2020-03-27 09:02:11 +00:00
|
|
|
import React, { CSSProperties } from "react";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
|
|
|
|
import ContainerWidget, { ContainerWidgetProps } from "widgets/ContainerWidget";
|
|
|
|
|
import { WidgetTypes, GridDefaults } from "constants/WidgetConstants";
|
|
|
|
|
import DropTargetComponent from "components/editorComponents/DropTargetComponent";
|
|
|
|
|
import { getCanvasSnapRows } from "utils/WidgetPropsUtils";
|
|
|
|
|
import { getCanvasClassName } from "utils/generators";
|
2020-08-28 17:23:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2021-04-23 05:43:13 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
2020-03-27 09:02:11 +00:00
|
|
|
|
|
|
|
|
class CanvasWidget extends ContainerWidget {
|
2021-02-16 10:29:08 +00:00
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2020-03-27 09:02:11 +00:00
|
|
|
getWidgetType = () => {
|
|
|
|
|
return WidgetTypes.CANVAS_WIDGET;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getCanvasProps(): ContainerWidgetProps<WidgetProps> {
|
|
|
|
|
return {
|
|
|
|
|
...this.props,
|
|
|
|
|
parentRowSpace: 1,
|
|
|
|
|
parentColumnSpace: 1,
|
|
|
|
|
topRow: 0,
|
|
|
|
|
leftColumn: 0,
|
|
|
|
|
containerStyle: "none",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()}
|
|
|
|
|
minHeight={this.props.minHeight || 380}
|
|
|
|
|
>
|
2020-11-04 13:28:21 +00:00
|
|
|
{this.renderAsContainerComponent(canvasProps)}
|
2020-03-27 09:02:11 +00:00
|
|
|
</DropTargetComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-23 05:43:13 +00:00
|
|
|
renderChildWidget(childWidgetData: WidgetProps): React.ReactNode {
|
|
|
|
|
if (!childWidgetData) return null;
|
|
|
|
|
// For now, isVisible prop defines whether to render a detached widget
|
|
|
|
|
if (childWidgetData.detachFromLayout && !childWidgetData.isVisible) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const snapSpaces = this.getSnapSpaces();
|
|
|
|
|
|
|
|
|
|
childWidgetData.parentColumnSpace = snapSpaces.snapColumnSpace;
|
|
|
|
|
childWidgetData.parentRowSpace = snapSpaces.snapRowSpace;
|
|
|
|
|
if (this.props.noPad) childWidgetData.noContainerOffset = true;
|
|
|
|
|
childWidgetData.parentId = this.props.widgetId;
|
|
|
|
|
|
|
|
|
|
return WidgetFactory.createWidget(childWidgetData, this.props.renderMode);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
getPageView() {
|
2021-04-23 05:43:13 +00:00
|
|
|
let height = 0;
|
2020-03-27 09:02:11 +00:00
|
|
|
const snapRows = getCanvasSnapRows(
|
|
|
|
|
this.props.bottomRow,
|
|
|
|
|
this.props.canExtend,
|
|
|
|
|
);
|
2021-04-23 05:43:13 +00:00
|
|
|
height = snapRows * GridDefaults.DEFAULT_GRID_ROW_HEIGHT;
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
const style: CSSProperties = {
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: `${height}px`,
|
|
|
|
|
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-04-23 05:43:13 +00:00
|
|
|
if (this.props.dropDisabled) return this.getPageView();
|
2020-03-27 09:02:11 +00:00
|
|
|
return this.renderAsDropTarget();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default CanvasWidget;
|
2020-08-28 17:23:07 +00:00
|
|
|
export const ProfiledCanvasWidget = Sentry.withProfiler(CanvasWidget);
|