Skip to content

Commit 61e3963

Browse files
Theme: added debounce for style changes and update theme
1 parent 8529fec commit 61e3963

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

client/packages/lowcoder/src/api/commonSettingApi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Api from "./api";
22
import { AxiosPromise } from "axios";
33
import { ApiResponse, GenericApiResponse } from "./apiResponses";
44
import { trans } from "i18n";
5+
import { JSONObject } from "@lowcoder-ee/util/jsonTypes";
56

67
export type FetchCommonSettingPayload = {
78
orgId: string;
@@ -59,7 +60,7 @@ export interface ThemeDetail {
5960
boxShadow?: string;
6061
boxShadowColor?: string;
6162
animationIterationCount?: string;
62-
components?: Record<string, object>;
63+
components?: Record<string, JSONObject>;
6364
}
6465

6566
export function getThemeDetailName(key: keyof ThemeDetail) {

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
RightPanelContentWrapper,
1313
} from "pages/editor/right/styledComponent";
1414
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
15-
import React, { useEffect, useMemo, useState } from "react";
15+
import React, { Fragment, useEffect, useMemo, useState } from "react";
1616
import styled from "styled-components";
1717
import {
1818
BaseSection,
@@ -162,8 +162,8 @@ export const ThemeCompPanel = (props: any) => {
162162
setSelectedComp(compType);
163163
const compKey = genRandomKey();
164164
let { comp, defaultDataFn } = compInfo;
165-
166-
const compData = parseCompType(compType)
165+
let newComp: any;
166+
167167
if (compInfo.lazyLoad) {
168168
comp = (await import(`../../../comps/${compInfo.compPath!}`))[compInfo.compName!];
169169
const {
@@ -175,32 +175,32 @@ export const ThemeCompPanel = (props: any) => {
175175
const module = await import(`../../../comps/${defaultDataFnPath}.tsx`);
176176
defaultDataFn = module[defaultDataFnName];
177177
}
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);
178+
newComp = new comp!({});
186179
} else {
187180
comp = compInfo.comp;
188-
let newComp = new comp!({
181+
newComp = new comp!({
189182
dispatch: (action) => {
190183
if (newComp) {
191184
newComp = newComp.reduce(action);
192185
}
193186
},
194187
}) as any;
195188
await newComp.load();
189+
}
196190

197-
191+
if (newComp) {
198192
const compChildrens = newComp.children;
199-
const styleChildrenKeys = Object.keys(compChildrens).filter(child => child.toLowerCase().endsWith('style') || child.toLowerCase().endsWith('styles'));
193+
let styleChildrenKeys = Object.keys(compChildrens).filter(child => child.toLowerCase().endsWith('style'));
200194
let styleChildrens: Record<string, any> = {};
201195
styleChildrenKeys.forEach((childKey: string) => {
202196
styleChildrens[childKey] = compChildrens[childKey];
203197
})
198+
if (compChildrens.container) {
199+
styleChildrenKeys = Object.keys(compChildrens.container.children).filter(child => child.toLowerCase().endsWith('style'));
200+
styleChildrenKeys.forEach((childKey: string) => {
201+
styleChildrens[childKey] = compChildrens.container.children[childKey];
202+
})
203+
}
204204
setStyleChildrens(styleChildrens);
205205
}
206206

@@ -277,7 +277,7 @@ export const ThemeCompPanel = (props: any) => {
277277
<>
278278
{Object.keys(styleChildrens || {})?.map((styleKey: string) => {
279279
return (
280-
<>
280+
<Fragment key={styleKey}>
281281
<h4>
282282
{ sectionNames.hasOwnProperty(styleKey)
283283
? sectionNames[styleKey as keyof typeof sectionNames]
@@ -286,12 +286,12 @@ export const ThemeCompPanel = (props: any) => {
286286
</h4>
287287
<ThemeSettingsCompStyles
288288
styleOptions={Object.keys(styleChildrens?.[styleKey].children)}
289-
defaultStyle={theme.components?.[selectedComp] || {}}
289+
defaultStyle={{...theme.components?.[selectedComp]?.[styleKey] || {}}}
290290
configChange={(params) => {
291-
props.onCompStyleChange(selectedComp, params);
291+
props.onCompStyleChange(selectedComp, styleKey, params);
292292
}}
293293
/>
294-
</>
294+
</Fragment>
295295
)
296296
})}
297297
</>
@@ -304,7 +304,7 @@ export const ThemeCompPanel = (props: any) => {
304304
return (
305305
<PreviewApp
306306
style={{
307-
height: "500px",
307+
height: "600px",
308308
minWidth: "auto",
309309
width: "100%",
310310
}}
@@ -341,11 +341,9 @@ export const ThemeCompPanel = (props: any) => {
341341
{compList}
342342
</PropertySectionContext.Provider>
343343
</RightPanelContentWrapper>
344-
{/* <Divider type="vertical" style={{height: "510px"}}/> */}
345344
<div style={{flex: "1"}}>
346345
{appPreview}
347346
</div>
348-
{/* <Divider type="vertical" style={{height: "510px"}}/> */}
349347
<div style={{
350348
width: "280px",
351349
padding: "12px",

client/packages/lowcoder/src/pages/setting/theme/detail/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,20 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
522522
>
523523
<ThemeCompPanel
524524
theme={this.state.theme}
525-
onCompStyleChange={(compName: string, compStyle: Record<string, string>) => {
525+
onCompStyleChange={(
526+
compName: string,
527+
styleKey: string,
528+
compStyle: Record<string, string>
529+
) => {
526530
this.setState({
527531
theme: {
528532
...this.state.theme,
529533
components: {
530534
...this.state.theme.components,
531-
[compName]: compStyle,
535+
[compName]: {
536+
...this.state.theme.components?.[compName],
537+
[styleKey]: compStyle,
538+
}
532539
}
533540
},
534541
});

0 commit comments

Comments
 (0)