@@ -5,14 +5,14 @@ import {
5
5
uiCompRegistry ,
6
6
} from "comps/uiCompRegistry" ;
7
7
import { isEmpty } from "lodash" ;
8
- import { language , trans } from "i18n" ;
8
+ import { language } from "i18n" ;
9
9
import {
10
10
CompIconDiv ,
11
11
EmptyCompContent ,
12
12
RightPanelContentWrapper ,
13
13
} from "pages/editor/right/styledComponent" ;
14
14
import { tableDragClassName } from "pages/tutorials/tutorialsConstant" ;
15
- import React , { useContext , useEffect , useMemo , useState } from "react" ;
15
+ import React , { useEffect , useMemo , useState } from "react" ;
16
16
import styled from "styled-components" ;
17
17
import {
18
18
BaseSection ,
@@ -22,16 +22,14 @@ import {
22
22
labelCss ,
23
23
sectionNames ,
24
24
} 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" ;
27
27
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" ;
35
33
36
34
const CompDiv = styled . div `
37
35
display: flex;
@@ -109,7 +107,7 @@ export const ThemeCompPanel = (props: any) => {
109
107
const [ searchValue , setSearchValue ] = useState ( "" ) ;
110
108
const [ propertySectionState , setPropertySectionState ] = useState < PropertySectionState > ( initialState ) ;
111
109
const [ searchedPropertySectionState , setSearchedPropertySectionState ] = useState < PropertySectionState > ( { } ) ;
112
- const [ styleChildrens , setStyleChildrens ] = useState < Record < string , any > > ( { } ) ;
110
+ const [ styleChildrens , setStyleChildrens ] = useState < Record < string , any > > ( ) ;
113
111
const [ selectedComp , setSelectedComp ] = useState < string > ( '' ) ;
114
112
const [ appDsl , setAppDSL ] = useState < JSONObject > ( ) ;
115
113
@@ -156,57 +154,79 @@ export const ThemeCompPanel = (props: any) => {
156
154
157
155
const onCompSelect = async ( compMap : [ string , UICompManifest ] ) => {
158
156
setAppDSL ( undefined ) ;
159
- const [ compType , compInfo ] = compMap ;
160
- setSelectedComp ( compType ) ;
161
- const compKey = genRandomKey ( ) ;
162
- let { comp, defaultDataFn } = compInfo ;
157
+ setStyleChildrens ( undefined ) ;
163
158
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 ;
171
165
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 ] ;
196
177
}
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
+ }
206
226
}
207
227
}
208
- }
209
- setAppDSL ( { ... dsl as any , ui } ) ;
228
+ setAppDSL ( { ... dsl as any , ui } ) ;
229
+ } , 0 )
210
230
}
211
231
212
232
const compList = useMemo (
@@ -255,7 +275,7 @@ export const ThemeCompPanel = (props: any) => {
255
275
const stylePropertyView = useMemo ( ( ) => {
256
276
return (
257
277
< >
258
- { Object . keys ( styleChildrens ) ?. map ( ( styleKey : string ) => {
278
+ { Object . keys ( styleChildrens || { } ) ?. map ( ( styleKey : string ) => {
259
279
return (
260
280
< >
261
281
< h4 >
@@ -265,7 +285,7 @@ export const ThemeCompPanel = (props: any) => {
265
285
}
266
286
</ h4 >
267
287
< ThemeSettingsCompStyles
268
- styleOptions = { Object . keys ( styleChildrens [ styleKey ] . children ) }
288
+ styleOptions = { Object . keys ( styleChildrens ?. [ styleKey ] . children ) }
269
289
defaultStyle = { theme . components ?. [ selectedComp ] || { } }
270
290
configChange = { ( params ) => {
271
291
props . onCompStyleChange ( selectedComp , params ) ;
@@ -302,7 +322,7 @@ export const ThemeCompPanel = (props: any) => {
302
322
303
323
return (
304
324
< Flex style = { {
305
- height : "500px " ,
325
+ height : "600px " ,
306
326
overflow : "hidden" ,
307
327
} } >
308
328
< RightPanelContentWrapper style = { {
0 commit comments