2020-03-27 09:02:11 +00:00
|
|
|
import React, { CSSProperties } from "react";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
2021-09-09 15:10:22 +00:00
|
|
|
import ContainerWidget, {
|
|
|
|
|
ContainerWidgetProps,
|
|
|
|
|
} from "widgets/ContainerWidget/widget";
|
2022-08-19 10:10:36 +00:00
|
|
|
import { GridDefaults } from "constants/WidgetConstants";
|
2020-03-27 09:02:11 +00:00
|
|
|
import DropTargetComponent from "components/editorComponents/DropTargetComponent";
|
2022-02-24 12:54:37 +00:00
|
|
|
import { getCanvasSnapRows } from "utils/WidgetPropsUtils";
|
2020-03-27 09:02:11 +00:00
|
|
|
import { getCanvasClassName } from "utils/generators";
|
2021-09-09 15:10:22 +00:00
|
|
|
import WidgetFactory, { DerivedPropertiesMap } from "utils/WidgetFactory";
|
2022-08-19 10:10:36 +00:00
|
|
|
import { CanvasWidgetStructure } from "./constants";
|
2022-07-15 10:27:13 +00:00
|
|
|
import { CANVAS_DEFAULT_MIN_HEIGHT_PX } from "constants/AppConstants";
|
2020-03-27 09:02:11 +00:00
|
|
|
|
|
|
|
|
class CanvasWidget extends ContainerWidget {
|
2021-02-16 10:29:08 +00:00
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2021-09-09 15:10:22 +00:00
|
|
|
static getWidgetType() {
|
|
|
|
|
return "CANVAS_WIDGET";
|
|
|
|
|
}
|
2020-03-27 09:02:11 +00:00
|
|
|
|
|
|
|
|
getCanvasProps(): ContainerWidgetProps<WidgetProps> {
|
|
|
|
|
return {
|
|
|
|
|
...this.props,
|
|
|
|
|
parentRowSpace: 1,
|
|
|
|
|
parentColumnSpace: 1,
|
|
|
|
|
topRow: 0,
|
|
|
|
|
leftColumn: 0,
|
|
|
|
|
containerStyle: "none",
|
2021-09-09 15:10:22 +00:00
|
|
|
detachFromLayout: true,
|
2020-03-27 09:02:11 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderAsDropTarget() {
|
2020-11-04 13:28:21 +00:00
|
|
|
const canvasProps = this.getCanvasProps();
|
2020-03-27 09:02:11 +00:00
|
|
|
return (
|
|
|
|
|
<DropTargetComponent
|
2020-11-04 13:28:21 +00:00
|
|
|
{...canvasProps}
|
2020-03-27 09:02:11 +00:00
|
|
|
{...this.getSnapSpaces()}
|
2022-07-15 10:27:13 +00:00
|
|
|
minHeight={this.props.minHeight || CANVAS_DEFAULT_MIN_HEIGHT_PX}
|
2020-03-27 09:02:11 +00:00
|
|
|
>
|
2020-11-04 13:28:21 +00:00
|
|
|
{this.renderAsContainerComponent(canvasProps)}
|
2020-03-27 09:02:11 +00:00
|
|
|
</DropTargetComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
renderChildWidget(childWidgetData: CanvasWidgetStructure): React.ReactNode {
|
2021-04-23 05:43:13 +00:00
|
|
|
if (!childWidgetData) return null;
|
2022-03-30 13:22:01 +00:00
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
const childWidget = { ...childWidgetData };
|
2022-03-30 13:22:01 +00:00
|
|
|
|
2021-04-23 05:43:13 +00:00
|
|
|
const snapSpaces = this.getSnapSpaces();
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
childWidget.parentColumnSpace = snapSpaces.snapColumnSpace;
|
|
|
|
|
childWidget.parentRowSpace = snapSpaces.snapRowSpace;
|
|
|
|
|
if (this.props.noPad) childWidget.noContainerOffset = true;
|
|
|
|
|
childWidget.parentId = this.props.widgetId;
|
2021-04-23 05:43:13 +00:00
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
return WidgetFactory.createWidget(childWidget, this.props.renderMode);
|
2021-04-23 05:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
getPageView() {
|
2022-02-24 12:54:37 +00:00
|
|
|
let height = 0;
|
|
|
|
|
const snapRows = getCanvasSnapRows(
|
|
|
|
|
this.props.bottomRow,
|
|
|
|
|
this.props.canExtend,
|
|
|
|
|
);
|
|
|
|
|
height = snapRows * GridDefaults.DEFAULT_GRID_ROW_HEIGHT;
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
const style: CSSProperties = {
|
|
|
|
|
width: "100%",
|
2022-03-08 07:24:40 +00:00
|
|
|
height: `${height}px`,
|
2020-03-27 09:02:11 +00:00
|
|
|
background: "none",
|
|
|
|
|
position: "relative",
|
|
|
|
|
};
|
|
|
|
|
// This div is the DropTargetComponent alternative for the page view
|
|
|
|
|
// DropTargetComponent and this div are responsible for the canvas height
|
|
|
|
|
return (
|
|
|
|
|
<div className={getCanvasClassName()} style={style}>
|
|
|
|
|
{this.renderAsContainerComponent(this.getCanvasProps())}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getCanvasView() {
|
2021-09-09 15:10:22 +00:00
|
|
|
if (!this.props.dropDisabled) {
|
|
|
|
|
return this.renderAsDropTarget();
|
|
|
|
|
}
|
|
|
|
|
return this.getPageView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getDerivedPropertiesMap(): DerivedPropertiesMap {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getDefaultPropertiesMap(): Record<string, string> {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
// TODO Find a way to enforce this, (dont let it be set)
|
|
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
|
|
|
return {};
|
2020-03-27 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
export const CONFIG = {
|
|
|
|
|
type: CanvasWidget.getWidgetType(),
|
|
|
|
|
name: "Canvas",
|
|
|
|
|
hideCard: true,
|
|
|
|
|
defaults: {
|
|
|
|
|
rows: 0,
|
|
|
|
|
columns: 0,
|
|
|
|
|
widgetName: "Canvas",
|
|
|
|
|
version: 1,
|
|
|
|
|
detachFromLayout: true,
|
|
|
|
|
},
|
|
|
|
|
properties: {
|
|
|
|
|
derived: CanvasWidget.getDerivedPropertiesMap(),
|
|
|
|
|
default: CanvasWidget.getDefaultPropertiesMap(),
|
|
|
|
|
meta: CanvasWidget.getMetaPropertiesMap(),
|
|
|
|
|
config: CanvasWidget.getPropertyPaneConfig(),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
export default CanvasWidget;
|