2019-12-27 10:10:04 +00:00
|
|
|
import React, { useState } from "react";
|
2019-11-13 07:00:25 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
|
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
|
|
|
|
import { ContainerWidgetProps } from "widgets/ContainerWidget";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
2019-10-21 11:40:24 +00:00
|
|
|
import PropertyPane from "./PropertyPane";
|
2019-11-25 05:07:27 +00:00
|
|
|
import ArtBoard from "pages/common/ArtBoard";
|
2019-12-27 10:10:04 +00:00
|
|
|
import { ResizingContext, FocusContext } from "./CanvasContexts";
|
2019-03-21 17:42:23 +00:00
|
|
|
|
2019-08-26 12:41:21 +00:00
|
|
|
interface CanvasProps {
|
2019-09-19 22:25:37 +00:00
|
|
|
dsl: ContainerWidgetProps<WidgetProps>;
|
2019-10-21 11:40:24 +00:00
|
|
|
showPropertyPane: (
|
|
|
|
|
widgetId?: string,
|
|
|
|
|
node?: HTMLDivElement,
|
|
|
|
|
toggle?: boolean,
|
|
|
|
|
) => void;
|
2019-08-29 11:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-21 11:40:24 +00:00
|
|
|
/* eslint-disable react/display-name */
|
|
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
const Canvas = (props: CanvasProps) => {
|
2019-10-03 11:04:11 +00:00
|
|
|
const [isFocused, setFocus] = useState("");
|
2019-12-25 09:17:37 +00:00
|
|
|
const [isResizing, setIsResizing] = useState(false);
|
2019-11-26 10:45:46 +00:00
|
|
|
try {
|
|
|
|
|
return (
|
2019-12-25 09:17:37 +00:00
|
|
|
<ResizingContext.Provider value={{ isResizing, setIsResizing }}>
|
|
|
|
|
<FocusContext.Provider
|
|
|
|
|
value={{
|
|
|
|
|
isFocused,
|
|
|
|
|
setFocus,
|
|
|
|
|
showPropertyPane: props.showPropertyPane,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<PropertyPane />
|
|
|
|
|
<ArtBoard>
|
|
|
|
|
{props.dsl.widgetId &&
|
|
|
|
|
WidgetFactory.createWidget(props.dsl, RenderModes.CANVAS)}
|
|
|
|
|
</ArtBoard>
|
|
|
|
|
</FocusContext.Provider>
|
|
|
|
|
</ResizingContext.Provider>
|
2019-11-26 10:45:46 +00:00
|
|
|
);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log("Error rendering DSL", error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-09-09 10:30:22 +00:00
|
|
|
};
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2019-09-09 10:30:22 +00:00
|
|
|
export default Canvas;
|