2024-08-06 14:52:22 +00:00
|
|
|
import { getCanvasWidgets } from "ee/selectors/entitiesSelector";
|
2023-09-19 05:22:11 +00:00
|
|
|
import { GridDefaults, type RenderModes } from "constants/WidgetConstants";
|
2023-10-04 11:53:29 +00:00
|
|
|
import { getLayoutSystem } from "layoutSystems/withLayoutSystemWidgetHOC";
|
2023-09-19 05:22:11 +00:00
|
|
|
import type {
|
|
|
|
|
CanvasWidgetsReduxState,
|
|
|
|
|
FlattenedWidgetProps,
|
|
|
|
|
} from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import { createSelector } from "reselect";
|
2023-10-04 08:54:16 +00:00
|
|
|
import { getRenderMode } from "./editorSelectors";
|
2023-09-19 05:22:11 +00:00
|
|
|
import { getIsMobileBreakPoint } from "sagas/selectors";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { AppState } from "ee/reducers";
|
2023-10-04 08:54:16 +00:00
|
|
|
import type { LayoutSystemTypes } from "layoutSystems/types";
|
|
|
|
|
import { getLayoutSystemType } from "./layoutSystemSelectors";
|
2023-09-19 05:22:11 +00:00
|
|
|
|
|
|
|
|
function buildFlattenedChildCanvasWidgets(
|
|
|
|
|
canvasWidgets: CanvasWidgetsReduxState,
|
|
|
|
|
renderMode: RenderModes,
|
2023-10-04 08:54:16 +00:00
|
|
|
layoutSystemType: LayoutSystemTypes,
|
2023-09-19 05:22:11 +00:00
|
|
|
isMobile: boolean,
|
|
|
|
|
parentWidgetId: string,
|
|
|
|
|
flattenedChildCanvasWidgets: Record<string, FlattenedWidgetProps> = {},
|
|
|
|
|
) {
|
|
|
|
|
const parentWidget = canvasWidgets[parentWidgetId];
|
2023-10-04 11:53:29 +00:00
|
|
|
const {
|
|
|
|
|
widgetSystem: { propertyEnhancer },
|
|
|
|
|
} = getLayoutSystem(renderMode, layoutSystemType);
|
2023-09-19 05:22:11 +00:00
|
|
|
parentWidget?.children?.forEach((childId) => {
|
|
|
|
|
const childWidget = canvasWidgets[childId];
|
|
|
|
|
let parentRowSpace =
|
|
|
|
|
childWidget.parentRowSpace ?? GridDefaults.DEFAULT_GRID_ROW_HEIGHT;
|
|
|
|
|
if (childWidget.type === "CANVAS_WIDGET") {
|
|
|
|
|
parentRowSpace = 1;
|
|
|
|
|
}
|
|
|
|
|
flattenedChildCanvasWidgets[childId] = propertyEnhancer({
|
|
|
|
|
...childWidget,
|
|
|
|
|
isMobile,
|
|
|
|
|
parentRowSpace,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buildFlattenedChildCanvasWidgets(
|
|
|
|
|
canvasWidgets,
|
|
|
|
|
renderMode,
|
2023-10-04 08:54:16 +00:00
|
|
|
layoutSystemType,
|
2023-09-19 05:22:11 +00:00
|
|
|
isMobile,
|
|
|
|
|
childId,
|
|
|
|
|
flattenedChildCanvasWidgets,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return flattenedChildCanvasWidgets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getFlattenedChildCanvasWidgets = createSelector(
|
|
|
|
|
[
|
|
|
|
|
getCanvasWidgets,
|
|
|
|
|
getRenderMode,
|
2023-10-04 08:54:16 +00:00
|
|
|
getLayoutSystemType,
|
2023-09-19 05:22:11 +00:00
|
|
|
getIsMobileBreakPoint,
|
|
|
|
|
(_state: AppState, parentWidgetId: string) => parentWidgetId,
|
|
|
|
|
],
|
|
|
|
|
buildFlattenedChildCanvasWidgets,
|
|
|
|
|
);
|