2023-09-11 15:55:11 +00:00
|
|
|
import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
|
|
|
|
|
import { RenderModes } from "../../constants/WidgetConstants";
|
2023-10-04 11:53:29 +00:00
|
|
|
import { AutoLayoutEditorCanvas } from "./canvas/AutoLayoutEditorCanvas";
|
|
|
|
|
import { AutoLayoutViewerCanvas } from "./canvas/AutoLayoutViewerCanvas";
|
2023-09-11 15:55:11 +00:00
|
|
|
import { AutoLayoutEditorWrapper } from "./editor/AutoLayoutEditorWrapper";
|
|
|
|
|
import { AutoLayoutViewerWrapper } from "./viewer/AutoLayoutViewerWrapper";
|
2023-09-19 05:22:11 +00:00
|
|
|
import { getAutoLayoutComponentDimensions } from "layoutSystems/common/utils/ComponentSizeUtils";
|
2023-10-04 11:53:29 +00:00
|
|
|
import type { LayoutSystem } from "layoutSystems/types";
|
|
|
|
|
import { CANVAS_DEFAULT_MIN_HEIGHT_PX } from "constants/AppConstants";
|
|
|
|
|
import type { CanvasProps } from "layoutSystems/fixedlayout/canvas/FixedLayoutEditorCanvas";
|
2023-10-02 19:41:05 +00:00
|
|
|
import {
|
|
|
|
|
getAutoDimensionsConfig,
|
|
|
|
|
getAutoLayoutWidgetConfig,
|
|
|
|
|
} from "layoutSystems/common/utils/commonUtils";
|
|
|
|
|
import type { AutoDimensionOptions } from "WidgetProvider/constants";
|
2023-09-11 15:55:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getAutoLayoutDimensionsConfig
|
|
|
|
|
*
|
|
|
|
|
* utility function to fetch and process widget specific autoDimensionConfig(specific to Auto Layout Layout system)
|
|
|
|
|
* stored on the WidgetFactory.autoLayoutConfigMap.
|
|
|
|
|
*
|
|
|
|
|
* @returns AutoDimensionValues | undefined
|
|
|
|
|
*/
|
2023-10-02 19:41:05 +00:00
|
|
|
export const getAutoLayoutDimensionsConfig = (
|
|
|
|
|
props: BaseWidgetProps,
|
|
|
|
|
): AutoDimensionOptions | undefined => {
|
|
|
|
|
return getAutoDimensionsConfig(getAutoLayoutWidgetConfig(props), props);
|
2023-09-11 15:55:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-04 11:53:29 +00:00
|
|
|
* getAutoLayoutSystemWidgetPropsEnhancer
|
2023-09-11 15:55:11 +00:00
|
|
|
*
|
|
|
|
|
* utility function to enhance BaseWidgetProps with Auto Layout system specific props
|
|
|
|
|
*
|
|
|
|
|
* @returns EnhancedBaseWidgetProps
|
|
|
|
|
* @property {AutoDimensionValues | undefined} autoDimensionConfig The auto dimension configuration of a widget.
|
|
|
|
|
* @property {number} componentHeight The calculated height of a widget in pixels.
|
|
|
|
|
* @property {number} componentWidth The calculated width of a widget in pixels.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2023-10-04 11:53:29 +00:00
|
|
|
const getAutoLayoutSystemWidgetPropsEnhancer = (props: BaseWidgetProps) => {
|
2023-09-11 15:55:11 +00:00
|
|
|
const autoDimensionConfig = getAutoLayoutDimensionsConfig(props);
|
|
|
|
|
const { componentHeight, componentWidth } =
|
|
|
|
|
getAutoLayoutComponentDimensions(props);
|
|
|
|
|
return {
|
|
|
|
|
...props,
|
|
|
|
|
autoDimensionConfig,
|
|
|
|
|
componentHeight,
|
|
|
|
|
componentWidth,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-04 11:53:29 +00:00
|
|
|
const defaultAutoLayoutCanvasProps: Partial<CanvasProps> = {
|
|
|
|
|
parentRowSpace: 1,
|
|
|
|
|
parentColumnSpace: 1,
|
|
|
|
|
topRow: 0,
|
|
|
|
|
leftColumn: 0,
|
|
|
|
|
containerStyle: "none",
|
|
|
|
|
detachFromLayout: true,
|
|
|
|
|
shouldScrollContents: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getAutoLayoutSystemCanvasPropsEnhancer
|
|
|
|
|
*
|
|
|
|
|
* utility function to enhance BaseWidgetProps of canvas with Auto Layout system specific props
|
|
|
|
|
*
|
|
|
|
|
* @returns EnhancedBaseWidgetProps
|
|
|
|
|
* @property {AutoDimensionValues | undefined} autoDimensionConfig The auto dimension configuration of a widget.
|
|
|
|
|
* @property {number} componentHeight The calculated height of a widget in pixels.
|
|
|
|
|
* @property {number} componentWidth The calculated width of a widget in pixels.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const getAutoLayoutSystemCanvasPropsEnhancer = (props: BaseWidgetProps) => {
|
|
|
|
|
const enhancedProps = {
|
|
|
|
|
minHeight: CANVAS_DEFAULT_MIN_HEIGHT_PX,
|
|
|
|
|
...props,
|
|
|
|
|
...defaultAutoLayoutCanvasProps,
|
|
|
|
|
};
|
|
|
|
|
const autoDimensionConfig = getAutoLayoutDimensionsConfig(enhancedProps);
|
|
|
|
|
const { componentHeight, componentWidth } =
|
|
|
|
|
getAutoLayoutComponentDimensions(enhancedProps);
|
|
|
|
|
return {
|
|
|
|
|
...enhancedProps,
|
|
|
|
|
autoDimensionConfig,
|
|
|
|
|
componentHeight,
|
|
|
|
|
componentWidth,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-11 15:55:11 +00:00
|
|
|
/**
|
|
|
|
|
* getAutoLayoutSystemWrapper
|
|
|
|
|
*
|
|
|
|
|
* utility function to return the auto layout system wrapper based on render mode.
|
|
|
|
|
* wrapper is the component that wraps around a widget to provide layout-ing ability and enable editing experience.
|
|
|
|
|
*
|
|
|
|
|
* @returns current render mode specific wrapper.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const getAutoLayoutSystemWrapper = (renderMode: RenderModes) => {
|
|
|
|
|
if (renderMode === RenderModes.CANVAS) {
|
|
|
|
|
return AutoLayoutEditorWrapper;
|
|
|
|
|
} else {
|
|
|
|
|
return AutoLayoutViewerWrapper;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-04 11:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* getAutoLayoutSystemCanvasWrapper
|
|
|
|
|
*
|
|
|
|
|
* utility function to return the auto layout system canvas implementation based on render mode.
|
|
|
|
|
*
|
|
|
|
|
* @returns current render mode specific canvas component.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function getAutoLayoutSystemCanvasWrapper(renderMode: RenderModes) {
|
|
|
|
|
if (renderMode === RenderModes.CANVAS) {
|
|
|
|
|
return AutoLayoutEditorCanvas;
|
|
|
|
|
} else {
|
|
|
|
|
return AutoLayoutViewerCanvas;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 15:55:11 +00:00
|
|
|
/**
|
|
|
|
|
* getAutoLayoutSystem
|
|
|
|
|
*
|
|
|
|
|
* utility function to return the auto layout system config for
|
|
|
|
|
* wrapper based on render mode and property enhancer function
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
2023-10-04 11:53:29 +00:00
|
|
|
* @property widgetSystem - widget specific wrappers and enhancers of a layout system
|
|
|
|
|
* @property canvasSystem - canvas specific implementation and enhancers of a layout system
|
2023-09-11 15:55:11 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-10-04 11:53:29 +00:00
|
|
|
export function getAutoLayoutSystem(renderMode: RenderModes): LayoutSystem {
|
2023-09-11 15:55:11 +00:00
|
|
|
return {
|
2023-10-04 11:53:29 +00:00
|
|
|
widgetSystem: {
|
|
|
|
|
WidgetWrapper: getAutoLayoutSystemWrapper(renderMode),
|
|
|
|
|
propertyEnhancer: getAutoLayoutSystemWidgetPropsEnhancer,
|
|
|
|
|
},
|
|
|
|
|
canvasSystem: {
|
|
|
|
|
Canvas: getAutoLayoutSystemCanvasWrapper(renderMode),
|
|
|
|
|
propertyEnhancer: getAutoLayoutSystemCanvasPropsEnhancer,
|
|
|
|
|
},
|
2023-09-11 15:55:11 +00:00
|
|
|
};
|
|
|
|
|
}
|