Skip to content

Commit 8529fec

Browse files
theme: fix lc-comps loading in comp styling
1 parent b2d5862 commit 8529fec

File tree

2 files changed

+81
-62
lines changed

2 files changed

+81
-62
lines changed

client/packages/lowcoder/src/comps/comps/gridItemComp.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const TmpComp = withTypeAndChildren<
3939
>(
4040
(type) => {
4141
const compInfo = parseCompType(type);
42-
4342
if (compInfo.isRemote) {
4443
return remoteComp(compInfo);
4544
}

client/packages/lowcoder/src/pages/setting/theme/ThemeCompPanel.tsx

Lines changed: 81 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
uiCompRegistry,
66
} from "comps/uiCompRegistry";
77
import { isEmpty } from "lodash";
8-
import { language, trans } from "i18n";
8+
import { language } from "i18n";
99
import {
1010
CompIconDiv,
1111
EmptyCompContent,
1212
RightPanelContentWrapper,
1313
} from "pages/editor/right/styledComponent";
1414
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
15-
import React, { useContext, useEffect, useMemo, useState } from "react";
15+
import React, { useEffect, useMemo, useState } from "react";
1616
import styled from "styled-components";
1717
import {
1818
BaseSection,
@@ -22,16 +22,14 @@ import {
2222
labelCss,
2323
sectionNames,
2424
} from "lowcoder-design";
25-
import { Divider, Flex, Input } from "antd";
26-
import { genRandomKey } from "@lowcoder-ee/comps/utils/idGenerator";
25+
import { Flex, Input } from "antd";
26+
import { genRandomKey } from "comps/utils/idGenerator";
2727
import dsl from "./detail/previewDsl";
28-
import { RootComp } from "@lowcoder-ee/comps/comps/rootComp";
29-
import { NameGenerator, evalAndReduceWithExposing } from "@lowcoder-ee/comps/utils";
30-
import ThemeSettingsSelector from "@lowcoder-ee/components/ThemeSettingsSelector";
31-
import ThemeSettingsCompStyles from "@lowcoder-ee/components/ThemeSettingsCompStyles";
32-
import { JSONObject } from "@lowcoder-ee/util/jsonTypes";
33-
import PreviewApp from "@lowcoder-ee/components/PreviewApp";
34-
import { parseCompType } from "@lowcoder-ee/comps/utils/remote";
28+
import { NameGenerator } from "comps/utils";
29+
import ThemeSettingsCompStyles from "components/ThemeSettingsCompStyles";
30+
import { JSONObject } from "util/jsonTypes";
31+
import PreviewApp from "components/PreviewApp";
32+
import { parseCompType } from "comps/utils/remote";
3533

3634
const CompDiv = styled.div`
3735
display: flex;
@@ -109,7 +107,7 @@ export const ThemeCompPanel = (props: any) => {
109107
const [searchValue, setSearchValue] = useState("");
110108
const [propertySectionState, setPropertySectionState] = useState<PropertySectionState>(initialState);
111109
const [searchedPropertySectionState, setSearchedPropertySectionState] = useState<PropertySectionState>({});
112-
const [styleChildrens, setStyleChildrens] = useState<Record<string, any>>({});
110+
const [styleChildrens, setStyleChildrens] = useState<Record<string, any>>();
113111
const [selectedComp, setSelectedComp] = useState<string>('');
114112
const [appDsl, setAppDSL] = useState<JSONObject>();
115113

@@ -156,57 +154,79 @@ export const ThemeCompPanel = (props: any) => {
156154

157155
const onCompSelect = async (compMap: [string, UICompManifest]) => {
158156
setAppDSL(undefined);
159-
const [compType, compInfo] = compMap;
160-
setSelectedComp(compType);
161-
const compKey = genRandomKey();
162-
let { comp, defaultDataFn } = compInfo;
157+
setStyleChildrens(undefined);
163158

164-
const compData = parseCompType(compType)
165-
if (compInfo.lazyLoad) {
166-
comp = (await import(`../../../comps/${compInfo.compPath!}`))[compInfo.compName!];
167-
const {
168-
defaultDataFnName,
169-
defaultDataFnPath,
170-
} = compInfo;
159+
setTimeout(async () => {
160+
161+
const [compType, compInfo] = compMap;
162+
setSelectedComp(compType);
163+
const compKey = genRandomKey();
164+
let { comp, defaultDataFn } = compInfo;
171165

172-
if(defaultDataFnName && defaultDataFnPath) {
173-
const module = await import(`../../../comps/${defaultDataFnPath}.tsx`);
174-
defaultDataFn = module[defaultDataFnName];
175-
}
176-
const newComp = new comp!({});
177-
const compChildrens = newComp.children;
178-
const styleChildrenKeys = Object.keys(compChildrens).filter(child => child.toLowerCase().endsWith('style'));
179-
let styleChildrens: Record<string, any> = {};
180-
styleChildrenKeys.forEach((childKey: string) => {
181-
styleChildrens[childKey] = compChildrens[childKey];
182-
})
183-
setStyleChildrens(styleChildrens);
184-
} else {
185-
comp = compInfo.comp;
186-
}
187-
188-
const ui = {
189-
items: {
190-
[compKey]: {
191-
compType: compType,
192-
name: `${compType}1`,
193-
comp: defaultDataFn
194-
? defaultDataFn("comp", new NameGenerator())
195-
: new comp!({}),
166+
const compData = parseCompType(compType)
167+
if (compInfo.lazyLoad) {
168+
comp = (await import(`../../../comps/${compInfo.compPath!}`))[compInfo.compName!];
169+
const {
170+
defaultDataFnName,
171+
defaultDataFnPath,
172+
} = compInfo;
173+
174+
if(defaultDataFnName && defaultDataFnPath) {
175+
const module = await import(`../../../comps/${defaultDataFnPath}.tsx`);
176+
defaultDataFn = module[defaultDataFnName];
196177
}
197-
},
198-
layout: {
199-
[compKey]: {
200-
...compInfo.layoutInfo,
201-
w: (compInfo?.layoutInfo?.w || 5) * 1.5,
202-
h: (compInfo?.layoutInfo?.h || 5),
203-
i: compKey,
204-
x: 2,
205-
y: 2,
178+
const newComp = new comp!({});
179+
const compChildrens = newComp.children;
180+
const styleChildrenKeys = Object.keys(compChildrens).filter(child => child.toLowerCase().endsWith('style'));
181+
let styleChildrens: Record<string, any> = {};
182+
styleChildrenKeys.forEach((childKey: string) => {
183+
styleChildrens[childKey] = compChildrens[childKey];
184+
})
185+
setStyleChildrens(styleChildrens);
186+
} else {
187+
comp = compInfo.comp;
188+
let newComp = new comp!({
189+
dispatch: (action) => {
190+
if (newComp) {
191+
newComp = newComp.reduce(action);
192+
}
193+
},
194+
}) as any;
195+
await newComp.load();
196+
197+
198+
const compChildrens = newComp.children;
199+
const styleChildrenKeys = Object.keys(compChildrens).filter(child => child.toLowerCase().endsWith('style') || child.toLowerCase().endsWith('styles'));
200+
let styleChildrens: Record<string, any> = {};
201+
styleChildrenKeys.forEach((childKey: string) => {
202+
styleChildrens[childKey] = compChildrens[childKey];
203+
})
204+
setStyleChildrens(styleChildrens);
205+
}
206+
207+
const ui = {
208+
items: {
209+
[compKey]: {
210+
compType: compType,
211+
name: `${compType}1`,
212+
comp: defaultDataFn
213+
? defaultDataFn("comp", new NameGenerator())
214+
: new comp!({}),
215+
}
216+
},
217+
layout: {
218+
[compKey]: {
219+
...compInfo.layoutInfo,
220+
w: (compInfo?.layoutInfo?.w || 5) * 1.5,
221+
h: (compInfo?.layoutInfo?.h || 5),
222+
i: compKey,
223+
x: 2,
224+
y: 2,
225+
}
206226
}
207227
}
208-
}
209-
setAppDSL({...dsl as any, ui});
228+
setAppDSL({...dsl as any, ui});
229+
}, 0)
210230
}
211231

212232
const compList = useMemo(
@@ -255,7 +275,7 @@ export const ThemeCompPanel = (props: any) => {
255275
const stylePropertyView = useMemo(() => {
256276
return (
257277
<>
258-
{Object.keys(styleChildrens)?.map((styleKey: string) => {
278+
{Object.keys(styleChildrens || {})?.map((styleKey: string) => {
259279
return (
260280
<>
261281
<h4>
@@ -265,7 +285,7 @@ export const ThemeCompPanel = (props: any) => {
265285
}
266286
</h4>
267287
<ThemeSettingsCompStyles
268-
styleOptions={Object.keys(styleChildrens[styleKey].children)}
288+
styleOptions={Object.keys(styleChildrens?.[styleKey].children)}
269289
defaultStyle={theme.components?.[selectedComp] || {}}
270290
configChange={(params) => {
271291
props.onCompStyleChange(selectedComp, params);
@@ -302,7 +322,7 @@ export const ThemeCompPanel = (props: any) => {
302322

303323
return (
304324
<Flex style={{
305-
height: "500px",
325+
height: "600px",
306326
overflow: "hidden",
307327
}}>
308328
<RightPanelContentWrapper style={{

0 commit comments

Comments
 (0)