@@ -3,7 +3,11 @@ import { RootComp as RootCompTmp } from "comps/comps/rootComp";
3
3
import { PositionParams } from "layout" ;
4
4
import _ from "lodash" ;
5
5
import React , { ReactNode } from "react" ;
6
- import { BottomResComp , BottomResListComp , BottomResTypeEnum } from "types/bottomRes" ;
6
+ import {
7
+ BottomResComp ,
8
+ BottomResListComp ,
9
+ BottomResTypeEnum ,
10
+ } from "types/bottomRes" ;
7
11
import { setFields } from "util/objectUtils" ;
8
12
import { OptionalComp , renameAction } from "lowcoder-core" ;
9
13
import { GridItemComp } from "./comps/gridItemComp" ;
@@ -13,7 +17,7 @@ import { NameAndExposingInfo } from "./utils/exposingTypes";
13
17
import { checkName } from "./utils/rename" ;
14
18
import { trans } from "i18n" ;
15
19
import { UiLayoutType } from "./comps/uiComp" ;
16
- import { getEditorModeStatus } from "util/localStorageUtil" ;
20
+ import { getCollisionStatus , getEditorModeStatus } from "util/localStorageUtil" ;
17
21
18
22
type RootComp = InstanceType < typeof RootCompTmp > ;
19
23
@@ -43,6 +47,7 @@ export class EditorState {
43
47
readonly showPropertyPane : boolean = false ;
44
48
readonly selectedCompNames : Set < string > = new Set ( ) ;
45
49
readonly editorModeStatus : string = "" ;
50
+ readonly collisionStatus : string = "" ;
46
51
readonly isDragging : boolean = false ;
47
52
readonly draggingCompType : string = "button" ;
48
53
readonly forceShowGrid : boolean = false ; // show grid lines
@@ -52,16 +57,20 @@ export class EditorState {
52
57
readonly showResultCompName : string = "" ;
53
58
readonly selectSource ?: SelectSourceType ; // the source of select type
54
59
55
- private readonly setEditorState : ( fn : ( editorState : EditorState ) => EditorState ) => void ;
60
+ private readonly setEditorState : (
61
+ fn : ( editorState : EditorState ) => EditorState
62
+ ) => void ;
56
63
57
64
constructor (
58
65
rootComp : RootComp ,
59
66
setEditorState : ( fn : ( editorState : EditorState ) => EditorState ) => void ,
60
- initialEditorModeStatus : string = getEditorModeStatus ( )
67
+ initialEditorModeStatus : string = getEditorModeStatus ( ) ,
68
+ initialCollisionStatus : string = getCollisionStatus ( )
61
69
) {
62
70
this . rootComp = rootComp ;
63
71
this . setEditorState = setEditorState ;
64
72
this . editorModeStatus = initialEditorModeStatus ;
73
+ this . collisionStatus = initialCollisionStatus ;
65
74
}
66
75
67
76
/**
@@ -79,7 +88,10 @@ export class EditorState {
79
88
}
80
89
81
90
getAllCompMap ( ) {
82
- return { ...this . getAllHooksCompMap ( ) , ...this . getUIComp ( ) . getAllCompItems ( ) } ;
91
+ return {
92
+ ...this . getAllHooksCompMap ( ) ,
93
+ ...this . getUIComp ( ) . getAllCompItems ( ) ,
94
+ } ;
83
95
}
84
96
85
97
getAllUICompMap ( ) {
@@ -104,7 +116,9 @@ export class EditorState {
104
116
*/
105
117
getUICompByName ( name : string ) {
106
118
const compMap = this . getAllUICompMap ( ) ;
107
- return Object . values ( compMap ) . find ( ( item ) => item . children . name . getView ( ) === name ) ;
119
+ return Object . values ( compMap ) . find (
120
+ ( item ) => item . children . name . getView ( ) === name
121
+ ) ;
108
122
}
109
123
110
124
getNameGenerator ( ) {
@@ -120,17 +134,22 @@ export class EditorState {
120
134
121
135
uiCompInfoList ( ) : Array < CompInfo > {
122
136
const compMap = this . getAllUICompMap ( ) ;
123
- return Object . values ( compMap ) . map ( ( item ) => {
137
+ return Object . entries ( compMap ) . map ( ( [ key , item ] ) => {
124
138
return {
125
139
name : item . children . name . getView ( ) ,
126
140
type : item . children . compType . getView ( ) ,
127
141
data : item . children . comp . exposingValues ,
128
142
dataDesc : item . children . comp . exposingInfo ( ) . propertyDesc ,
143
+ key : key ,
129
144
} ;
130
145
} ) ;
131
146
}
132
147
133
- getCompInfo ( nameAndExposingInfo : NameAndExposingInfo , name : string , type : string ) : CompInfo {
148
+ getCompInfo (
149
+ nameAndExposingInfo : NameAndExposingInfo ,
150
+ name : string ,
151
+ type : string
152
+ ) : CompInfo {
134
153
return {
135
154
name,
136
155
type,
@@ -157,7 +176,11 @@ export class EditorState {
157
176
const exposingInfo = listComp . nameAndExposingInfo ( ) ;
158
177
return listComp . getView ( ) . map ( ( item ) => {
159
178
const name = item . children . name . getView ( ) ;
160
- return this . getCompInfo ( exposingInfo , name , BottomResTypeEnum . DateResponder ) ;
179
+ return this . getCompInfo (
180
+ exposingInfo ,
181
+ name ,
182
+ BottomResTypeEnum . DateResponder
183
+ ) ;
161
184
} ) ;
162
185
}
163
186
@@ -175,7 +198,11 @@ export class EditorState {
175
198
const exposingInfo = listComp . nameAndExposingInfo ( ) ;
176
199
return listComp . getView ( ) . map ( ( item ) => {
177
200
const name = item . children . name . getView ( ) ;
178
- return this . getCompInfo ( exposingInfo , name , BottomResTypeEnum . Transformer ) ;
201
+ return this . getCompInfo (
202
+ exposingInfo ,
203
+ name ,
204
+ BottomResTypeEnum . Transformer
205
+ ) ;
179
206
} ) ;
180
207
}
181
208
@@ -222,7 +249,10 @@ export class EditorState {
222
249
}
223
250
224
251
selectedQueryComp ( ) {
225
- if ( this . selectedBottomResType !== BottomResTypeEnum . Query || ! this . selectedBottomResName ) {
252
+ if (
253
+ this . selectedBottomResType !== BottomResTypeEnum . Query ||
254
+ ! this . selectedBottomResName
255
+ ) {
226
256
return undefined ;
227
257
}
228
258
return this . getQueriesComp ( )
@@ -233,7 +263,9 @@ export class EditorState {
233
263
}
234
264
235
265
showResultComp ( ) : BottomResComp | undefined {
236
- const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce < BottomResComp [ ] > ( ( a , b ) => {
266
+ const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce <
267
+ BottomResComp [ ]
268
+ > ( ( a , b ) => {
237
269
const items = this . getBottomResListComp ( b ) . items ( ) ;
238
270
return a . concat ( items ) ;
239
271
} , [ ] ) ;
@@ -279,7 +311,10 @@ export class EditorState {
279
311
return this . getUIComp ( ) . getComp ( ) ;
280
312
}
281
313
const [ key , comp ] = _ . toPairs ( selectedComps ) [ 0 ] ;
282
- if ( _ . size ( selectedComps ) === 1 && isContainer ( ( comp as GridItemComp ) ?. children ?. comp ) ) {
314
+ if (
315
+ _ . size ( selectedComps ) === 1 &&
316
+ isContainer ( ( comp as GridItemComp ) ?. children ?. comp )
317
+ ) {
283
318
return comp . children . comp ;
284
319
}
285
320
@@ -307,7 +342,9 @@ export class EditorState {
307
342
isCompSelected ( compName : string ) : OptionalComp {
308
343
const compMap = this . getAllCompMap ( ) ;
309
344
return Object . values ( compMap ) . find (
310
- ( item ) => item . children . name . getView ( ) === compName && this . selectedCompNames . has ( compName )
345
+ ( item ) =>
346
+ item . children . name . getView ( ) === compName &&
347
+ this . selectedCompNames . has ( compName )
311
348
) ;
312
349
}
313
350
@@ -319,6 +356,10 @@ export class EditorState {
319
356
this . changeState ( { editorModeStatus : newEditorModeStatus } ) ;
320
357
}
321
358
359
+ setCollisionStatus ( newCollisionStatus : string ) {
360
+ this . changeState ( { collisionStatus : newCollisionStatus } ) ;
361
+ }
362
+
322
363
setDragging ( dragging : boolean ) {
323
364
if ( this . isDragging === dragging ) {
324
365
return ;
@@ -356,7 +397,10 @@ export class EditorState {
356
397
} ) ;
357
398
}
358
399
359
- setSelectedCompNames ( selectedCompNames : Set < string > , selectSource ?: SelectSourceType ) {
400
+ setSelectedCompNames (
401
+ selectedCompNames : Set < string > ,
402
+ selectSource ?: SelectSourceType
403
+ ) {
360
404
if ( selectedCompNames . size === 0 && this . selectedCompNames . size === 0 ) {
361
405
return ;
362
406
}
@@ -406,7 +450,9 @@ export class EditorState {
406
450
}
407
451
408
452
getBottomResComp ( name : string ) : BottomResComp | undefined {
409
- const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce < BottomResComp [ ] > ( ( a , b ) => {
453
+ const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce <
454
+ BottomResComp [ ]
455
+ > ( ( a , b ) => {
410
456
const items = this . getBottomResListComp ( b ) . items ( ) ;
411
457
return a . concat ( items ) ;
412
458
} , [ ] ) ;
@@ -467,8 +513,11 @@ export class EditorState {
467
513
getAppType ( ) : UiLayoutType {
468
514
return this . getUIComp ( ) . children . compType . getView ( ) ;
469
515
}
516
+ getCollisionStatus ( ) : string {
517
+ return this . collisionStatus ;
518
+ }
519
+
470
520
}
471
-
472
521
export const EditorContext = React . createContext < EditorState > ( undefined as any ) ;
473
522
474
523
// current comp name
0 commit comments