@@ -2,8 +2,12 @@ import { isContainer } from "comps/comps/containerBase";
2
2
import { RootComp as RootCompTmp } from "comps/comps/rootComp" ;
3
3
import { PositionParams } from "layout" ;
4
4
import _ from "lodash" ;
5
- import React , { ReactNode } from "react" ;
6
- import { BottomResComp , BottomResListComp , BottomResTypeEnum } from "types/bottomRes" ;
5
+ import React , { ReactNode , useContext } from "react" ;
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 { getCollissionStatus , 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 collissionStatus : 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
+ initialCollissionStatus : string = getCollissionStatus ( )
61
69
) {
62
70
this . rootComp = rootComp ;
63
71
this . setEditorState = setEditorState ;
64
72
this . editorModeStatus = initialEditorModeStatus ;
73
+ this . collissionStatus = initialCollissionStatus ;
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 ( ) {
@@ -130,7 +144,11 @@ export class EditorState {
130
144
} ) ;
131
145
}
132
146
133
- getCompInfo ( nameAndExposingInfo : NameAndExposingInfo , name : string , type : string ) : CompInfo {
147
+ getCompInfo (
148
+ nameAndExposingInfo : NameAndExposingInfo ,
149
+ name : string ,
150
+ type : string
151
+ ) : CompInfo {
134
152
return {
135
153
name,
136
154
type,
@@ -157,7 +175,11 @@ export class EditorState {
157
175
const exposingInfo = listComp . nameAndExposingInfo ( ) ;
158
176
return listComp . getView ( ) . map ( ( item ) => {
159
177
const name = item . children . name . getView ( ) ;
160
- return this . getCompInfo ( exposingInfo , name , BottomResTypeEnum . DateResponder ) ;
178
+ return this . getCompInfo (
179
+ exposingInfo ,
180
+ name ,
181
+ BottomResTypeEnum . DateResponder
182
+ ) ;
161
183
} ) ;
162
184
}
163
185
@@ -175,7 +197,11 @@ export class EditorState {
175
197
const exposingInfo = listComp . nameAndExposingInfo ( ) ;
176
198
return listComp . getView ( ) . map ( ( item ) => {
177
199
const name = item . children . name . getView ( ) ;
178
- return this . getCompInfo ( exposingInfo , name , BottomResTypeEnum . Transformer ) ;
200
+ return this . getCompInfo (
201
+ exposingInfo ,
202
+ name ,
203
+ BottomResTypeEnum . Transformer
204
+ ) ;
179
205
} ) ;
180
206
}
181
207
@@ -222,7 +248,10 @@ export class EditorState {
222
248
}
223
249
224
250
selectedQueryComp ( ) {
225
- if ( this . selectedBottomResType !== BottomResTypeEnum . Query || ! this . selectedBottomResName ) {
251
+ if (
252
+ this . selectedBottomResType !== BottomResTypeEnum . Query ||
253
+ ! this . selectedBottomResName
254
+ ) {
226
255
return undefined ;
227
256
}
228
257
return this . getQueriesComp ( )
@@ -233,7 +262,9 @@ export class EditorState {
233
262
}
234
263
235
264
showResultComp ( ) : BottomResComp | undefined {
236
- const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce < BottomResComp [ ] > ( ( a , b ) => {
265
+ const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce <
266
+ BottomResComp [ ]
267
+ > ( ( a , b ) => {
237
268
const items = this . getBottomResListComp ( b ) . items ( ) ;
238
269
return a . concat ( items ) ;
239
270
} , [ ] ) ;
@@ -279,7 +310,10 @@ export class EditorState {
279
310
return this . getUIComp ( ) . getComp ( ) ;
280
311
}
281
312
const [ key , comp ] = _ . toPairs ( selectedComps ) [ 0 ] ;
282
- if ( _ . size ( selectedComps ) === 1 && isContainer ( ( comp as GridItemComp ) ?. children ?. comp ) ) {
313
+ if (
314
+ _ . size ( selectedComps ) === 1 &&
315
+ isContainer ( ( comp as GridItemComp ) ?. children ?. comp )
316
+ ) {
283
317
return comp . children . comp ;
284
318
}
285
319
@@ -307,7 +341,9 @@ export class EditorState {
307
341
isCompSelected ( compName : string ) : OptionalComp {
308
342
const compMap = this . getAllCompMap ( ) ;
309
343
return Object . values ( compMap ) . find (
310
- ( item ) => item . children . name . getView ( ) === compName && this . selectedCompNames . has ( compName )
344
+ ( item ) =>
345
+ item . children . name . getView ( ) === compName &&
346
+ this . selectedCompNames . has ( compName )
311
347
) ;
312
348
}
313
349
@@ -319,6 +355,10 @@ export class EditorState {
319
355
this . changeState ( { editorModeStatus : newEditorModeStatus } ) ;
320
356
}
321
357
358
+ setCollissionStatus ( newCollissionStatus : string ) {
359
+ this . changeState ( { collissionStatus : newCollissionStatus } ) ;
360
+ }
361
+
322
362
setDragging ( dragging : boolean ) {
323
363
if ( this . isDragging === dragging ) {
324
364
return ;
@@ -356,7 +396,10 @@ export class EditorState {
356
396
} ) ;
357
397
}
358
398
359
- setSelectedCompNames ( selectedCompNames : Set < string > , selectSource ?: SelectSourceType ) {
399
+ setSelectedCompNames (
400
+ selectedCompNames : Set < string > ,
401
+ selectSource ?: SelectSourceType
402
+ ) {
360
403
if ( selectedCompNames . size === 0 && this . selectedCompNames . size === 0 ) {
361
404
return ;
362
405
}
@@ -406,7 +449,9 @@ export class EditorState {
406
449
}
407
450
408
451
getBottomResComp ( name : string ) : BottomResComp | undefined {
409
- const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce < BottomResComp [ ] > ( ( a , b ) => {
452
+ const bottomResComps = Object . values ( BottomResTypeEnum ) . reduce <
453
+ BottomResComp [ ]
454
+ > ( ( a , b ) => {
410
455
const items = this . getBottomResListComp ( b ) . items ( ) ;
411
456
return a . concat ( items ) ;
412
457
} , [ ] ) ;
@@ -467,8 +512,10 @@ export class EditorState {
467
512
getAppType ( ) : UiLayoutType {
468
513
return this . getUIComp ( ) . children . compType . getView ( ) ;
469
514
}
515
+ getCollissionStatus ( ) : string {
516
+ return this . collissionStatus ;
517
+ }
470
518
}
471
-
472
519
export const EditorContext = React . createContext < EditorState > ( undefined as any ) ;
473
520
474
521
// current comp name
0 commit comments