|
| 1 | +import { CompParams } from "lowcoder-core"; |
| 2 | +import { ToDataType } from "comps/generators/multi"; |
| 3 | +import { NameConfigDisabled, NameConfigHidden, withExposingConfigs, NameConfig, CompDepsConfig } from "comps/generators/withExposing"; |
| 4 | +import { withMethodExposing } from "comps/generators/withMethodExposing"; |
| 5 | +import { NameGenerator } from "comps/utils/nameGenerator"; |
| 6 | +import { Section, sectionNames } from "lowcoder-design"; |
| 7 | +import { oldContainerParamsToNew } from "../containerBase"; |
| 8 | +import { toSimpleContainerData } from "../containerBase/simpleContainerComp"; |
| 9 | +import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils"; |
| 10 | +import { trans } from "i18n"; |
| 11 | +import { BoolCodeControl } from "comps/controls/codeControl"; |
| 12 | +import { DisabledContext } from "comps/generators/uiCompBuilder"; |
| 13 | +import React, { useContext, useEffect, useState } from "react"; |
| 14 | +import { EditorContext } from "comps/editorState"; |
| 15 | + |
| 16 | +import { |
| 17 | + ContainerChildren, |
| 18 | + ContainerCompBuilder, |
| 19 | +} from "../pageLayoutComp/pageLayoutCompBuilder"; |
| 20 | +import { PageLayout } from "../pageLayoutComp/pageLayout"; |
| 21 | + |
| 22 | + |
| 23 | +export const ContainerBaseComp = (function () { |
| 24 | + const childrenMap = { |
| 25 | + disabled: BoolCodeControl |
| 26 | + }; |
| 27 | + |
| 28 | + return new ContainerCompBuilder(childrenMap, (props, dispatch) => { |
| 29 | + |
| 30 | + const [siderCollapsed, setSiderCollapsed] = useState(false); |
| 31 | + |
| 32 | + return ( |
| 33 | + <DisabledContext.Provider value={props.disabled}> |
| 34 | + <PageLayout {...props} siderCollapsed={siderCollapsed} setSiderCollapsed={setSiderCollapsed} /> |
| 35 | + </DisabledContext.Provider> |
| 36 | + ); |
| 37 | + }) |
| 38 | + .setPropertyViewFn((children) => { |
| 39 | + return ( |
| 40 | + <> |
| 41 | + {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( |
| 42 | + <Section name={sectionNames.interaction}> |
| 43 | + {disabledPropertyView(children)} |
| 44 | + {hiddenPropertyView(children)} |
| 45 | + { children.container.appSelectorPropertyView()} |
| 46 | + </Section> |
| 47 | + )} |
| 48 | + |
| 49 | + {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( |
| 50 | + <><Section name={sectionNames.layout}> |
| 51 | + {children.container.getPropertyView()} |
| 52 | + </Section> |
| 53 | + <Section name={sectionNames.style}> |
| 54 | + { children.container.stylePropertyView() } |
| 55 | + </Section> |
| 56 | + {children.container.children.showHeader.getView() && ( |
| 57 | + <Section name={"Header Style"}> |
| 58 | + { children.container.headerStylePropertyView() } |
| 59 | + </Section> |
| 60 | + )} |
| 61 | + {children.container.children.showSider.getView() && ( |
| 62 | + <Section name={"Sider Style"}> |
| 63 | + { children.container.siderStylePropertyView() } |
| 64 | + </Section> |
| 65 | + )} |
| 66 | + <Section name={"Body Style"}> |
| 67 | + { children.container.bodyStylePropertyView() } |
| 68 | + </Section> |
| 69 | + {children.container.children.showFooter.getView() && ( |
| 70 | + <Section name={"Footer Style"}> |
| 71 | + { children.container.footerStylePropertyView() } |
| 72 | + </Section> |
| 73 | + )} |
| 74 | + </> |
| 75 | + )} |
| 76 | + </> |
| 77 | + ); |
| 78 | + }) |
| 79 | + .build(); |
| 80 | +})(); |
| 81 | + |
| 82 | +// Compatible with old data |
| 83 | +function convertOldContainerParams(params: CompParams<any>) { |
| 84 | + // convert older params to old params |
| 85 | + let tempParams = oldContainerParamsToNew(params); |
| 86 | + |
| 87 | + if (tempParams.value) { |
| 88 | + const container = tempParams.value.container; |
| 89 | + // old params |
| 90 | + if (container && (container.hasOwnProperty("layout") || container.hasOwnProperty("items"))) { |
| 91 | + const autoHeight = tempParams.value.autoHeight; |
| 92 | + const scrollbars = tempParams.value.scrollbars; |
| 93 | + return { |
| 94 | + ...tempParams, |
| 95 | + value: { |
| 96 | + container: { |
| 97 | + showHeader: true, |
| 98 | + body: { 0: { view: container } }, |
| 99 | + showFooter: false, |
| 100 | + showSider: true, |
| 101 | + autoHeight: autoHeight, |
| 102 | + contentScrollbars: scrollbars, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }; |
| 106 | + } |
| 107 | + } |
| 108 | + return tempParams; |
| 109 | +} |
| 110 | + |
| 111 | + |
| 112 | +class ContainerTmpComp extends ContainerBaseComp { |
| 113 | + constructor(params: CompParams<any>) { |
| 114 | + super(convertOldContainerParams(params)); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +const PageLayoutCompTmP = withExposingConfigs(ContainerTmpComp, [ |
| 119 | + NameConfigHidden, |
| 120 | + NameConfigDisabled, |
| 121 | + |
| 122 | + new NameConfig("container", trans("export.ratingValueDesc")), |
| 123 | + new CompDepsConfig( |
| 124 | + "siderCollapsed", |
| 125 | + (comp) => ({ data : comp.children.container.children.siderCollapsed.nodeWithoutCache()}), |
| 126 | + (input) => input.data.value, trans("listView.itemsDesc") |
| 127 | + ), |
| 128 | +]); |
| 129 | + |
| 130 | +export const PageLayoutComp = withMethodExposing(PageLayoutCompTmP, [ |
| 131 | + |
| 132 | + { |
| 133 | + method: { |
| 134 | + name: "setSiderCollapsed", |
| 135 | + description: "Set the Sider of the PageLayout to be collapsed or not", |
| 136 | + params: [{ name: "collapsed", type: "boolean" }], |
| 137 | + }, |
| 138 | + execute: (comp, values) => { |
| 139 | + const page = values[0] as number; |
| 140 | + if (page && page > 0) { |
| 141 | + // comp.children.pagination.children.pageNo.dispatchChangeValueAction(page); |
| 142 | + } |
| 143 | + }, |
| 144 | + } |
| 145 | +]); |
| 146 | + |
| 147 | +type ContainerDataType = ToDataType<ContainerChildren<{}>>; |
| 148 | + |
| 149 | +export function defaultPageLayoutData( |
| 150 | + compName: string, |
| 151 | + nameGenerator: NameGenerator |
| 152 | +): ContainerDataType { |
| 153 | + return { |
| 154 | + container: { |
| 155 | + header: toSimpleContainerData([ |
| 156 | + { |
| 157 | + item: { |
| 158 | + compType: "navigation", |
| 159 | + name: nameGenerator.genItemName("pageNavigation"), |
| 160 | + comp: { |
| 161 | + logoUrl: "", |
| 162 | + hidden: false, |
| 163 | + items: [ |
| 164 | + { |
| 165 | + label: "Home", |
| 166 | + hidden: false, |
| 167 | + active: false, |
| 168 | + }, |
| 169 | + { |
| 170 | + label: "Services", |
| 171 | + hidden: false, |
| 172 | + active: false, |
| 173 | + items: [ |
| 174 | + { |
| 175 | + label: "Lowcode Platform", |
| 176 | + hidden: false, |
| 177 | + active: false, |
| 178 | + }, |
| 179 | + { |
| 180 | + label: "App Development", |
| 181 | + hidden: false, |
| 182 | + active: false, |
| 183 | + }, |
| 184 | + ], |
| 185 | + }, |
| 186 | + { |
| 187 | + label: "About", |
| 188 | + hidden: false, |
| 189 | + active: false, |
| 190 | + }, |
| 191 | + ], |
| 192 | + }, |
| 193 | + }, |
| 194 | + layoutItem: { |
| 195 | + i: "", |
| 196 | + h: 6, |
| 197 | + w: 24, |
| 198 | + x: 0, |
| 199 | + y: 0, |
| 200 | + }, |
| 201 | + }, |
| 202 | + ]), |
| 203 | + }, |
| 204 | + }; |
| 205 | +} |
0 commit comments