|
| 1 | +import { CompParams } from "lowcoder-core"; |
| 2 | +import { ToDataType } from "comps/generators/multi"; |
| 3 | +import { NameConfigHidden, withExposingConfigs } from "comps/generators/withExposing"; |
| 4 | +import { NameGenerator } from "comps/utils/nameGenerator"; |
| 5 | +import { Section, sectionNames } from "lowcoder-design"; |
| 6 | +import { oldContainerParamsToNew } from "../containerBase"; |
| 7 | +import { toSimpleContainerData } from "../containerBase/simpleContainerComp"; |
| 8 | +import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils"; |
| 9 | +import { trans } from "i18n"; |
| 10 | +import { BoolCodeControl } from "comps/controls/codeControl"; |
| 11 | +import { DisabledContext } from "comps/generators/uiCompBuilder"; |
| 12 | +import React, { useContext } from "react"; |
| 13 | +import { EditorContext } from "comps/editorState"; |
| 14 | + |
| 15 | +import { |
| 16 | + ContainerChildren, |
| 17 | + ContainerCompBuilder, |
| 18 | +} from "../pageLayoutComp/pageLayoutCompBuilder"; |
| 19 | +import { PageLayout } from "../pageLayoutComp/pageLayout"; |
| 20 | + |
| 21 | +export const ContainerBaseComp = (function () { |
| 22 | + const childrenMap = { |
| 23 | + disabled: BoolCodeControl, |
| 24 | + }; |
| 25 | + return new ContainerCompBuilder(childrenMap, (props, dispatch) => { |
| 26 | + return ( |
| 27 | + <DisabledContext.Provider value={props.disabled}> |
| 28 | + <PageLayout {...props} /> |
| 29 | + </DisabledContext.Provider> |
| 30 | + ); |
| 31 | + }) |
| 32 | + .setPropertyViewFn((children) => { |
| 33 | + return ( |
| 34 | + <> |
| 35 | + {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( |
| 36 | + <Section name={sectionNames.interaction}> |
| 37 | + {disabledPropertyView(children)} |
| 38 | + {hiddenPropertyView(children)} |
| 39 | + { children.container.appSelectorPropertyView()} |
| 40 | + </Section> |
| 41 | + )} |
| 42 | + |
| 43 | + {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( |
| 44 | + <><Section name={sectionNames.layout}> |
| 45 | + {children.container.getPropertyView()} |
| 46 | + </Section> |
| 47 | + <Section name={sectionNames.style}> |
| 48 | + { children.container.stylePropertyView() } |
| 49 | + </Section> |
| 50 | + {children.container.children.showHeader.getView() && ( |
| 51 | + <Section name={"Header Style"}> |
| 52 | + { children.container.headerStylePropertyView() } |
| 53 | + </Section> |
| 54 | + )} |
| 55 | + {children.container.children.showSider.getView() && ( |
| 56 | + <Section name={"Sider Style"}> |
| 57 | + { children.container.siderStylePropertyView() } |
| 58 | + </Section> |
| 59 | + )} |
| 60 | + <Section name={"Body Style"}> |
| 61 | + { children.container.bodyStylePropertyView() } |
| 62 | + </Section> |
| 63 | + {children.container.children.showFooter.getView() && ( |
| 64 | + <Section name={"Footer Style"}> |
| 65 | + { children.container.footerStylePropertyView() } |
| 66 | + </Section> |
| 67 | + )} |
| 68 | + </> |
| 69 | + )} |
| 70 | + </> |
| 71 | + ); |
| 72 | + }) |
| 73 | + .build(); |
| 74 | +})(); |
| 75 | + |
| 76 | +// Compatible with old data |
| 77 | +function convertOldContainerParams(params: CompParams<any>) { |
| 78 | + // convert older params to old params |
| 79 | + let tempParams = oldContainerParamsToNew(params); |
| 80 | + |
| 81 | + if (tempParams.value) { |
| 82 | + const container = tempParams.value.container; |
| 83 | + // old params |
| 84 | + if (container && (container.hasOwnProperty("layout") || container.hasOwnProperty("items"))) { |
| 85 | + const autoHeight = tempParams.value.autoHeight; |
| 86 | + const scrollbars = tempParams.value.scrollbars; |
| 87 | + return { |
| 88 | + ...tempParams, |
| 89 | + value: { |
| 90 | + container: { |
| 91 | + showHeader: true, |
| 92 | + body: { 0: { view: container } }, |
| 93 | + showFooter: false, |
| 94 | + showSider: true, |
| 95 | + autoHeight: autoHeight, |
| 96 | + contentScrollbars: scrollbars, |
| 97 | + }, |
| 98 | + }, |
| 99 | + }; |
| 100 | + } |
| 101 | + } |
| 102 | + return tempParams; |
| 103 | +} |
| 104 | + |
| 105 | +class ContainerTmpComp extends ContainerBaseComp { |
| 106 | + constructor(params: CompParams<any>) { |
| 107 | + super(convertOldContainerParams(params)); |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +export const PageLayoutComp = withExposingConfigs(ContainerTmpComp, [NameConfigHidden]); |
| 112 | + |
| 113 | +type ContainerDataType = ToDataType<ContainerChildren<{}>>; |
| 114 | + |
| 115 | +export function defaultPageLayoutData( |
| 116 | + compName: string, |
| 117 | + nameGenerator: NameGenerator |
| 118 | +): ContainerDataType { |
| 119 | + return { |
| 120 | + container: { |
| 121 | + header: toSimpleContainerData([ |
| 122 | + { |
| 123 | + item: { |
| 124 | + compType: "text", |
| 125 | + name: nameGenerator.genItemName("containerTitle"), |
| 126 | + comp: { |
| 127 | + text: "## " + trans("container.title"), |
| 128 | + }, |
| 129 | + }, |
| 130 | + layoutItem: { |
| 131 | + i: "", |
| 132 | + h: 6, |
| 133 | + w: 24, |
| 134 | + x: 0, |
| 135 | + y: 0, |
| 136 | + }, |
| 137 | + }, |
| 138 | + ]), |
| 139 | + }, |
| 140 | + }; |
| 141 | +} |
0 commit comments