@@ -3,7 +3,11 @@ import { RootComp as RootCompTmp } from "comps/comps/rootComp";
33import { PositionParams } from "layout" ;
44import _ from "lodash" ;
55import React , { ReactNode } from "react" ;
6- import { BottomResComp , BottomResListComp , BottomResTypeEnum } from "types/bottomRes" ;
6+ import {
7+ BottomResComp ,
8+ BottomResListComp ,
9+ BottomResTypeEnum ,
10+ } from "types/bottomRes" ;
711import { setFields } from "util/objectUtils" ;
812import { OptionalComp , renameAction } from "lowcoder-core" ;
913import { GridItemComp } from "./comps/gridItemComp" ;
@@ -13,7 +17,7 @@ import { NameAndExposingInfo } from "./utils/exposingTypes";
1317import { checkName } from "./utils/rename" ;
1418import { trans } from "i18n" ;
1519import { UiLayoutType } from "./comps/uiComp" ;
16- import { getEditorModeStatus } from "util/localStorageUtil" ;
20+ import { getCollisionStatus , getEditorModeStatus } from "util/localStorageUtil" ;
1721
1822type RootComp = InstanceType < typeof RootCompTmp > ;
1923
@@ -43,6 +47,7 @@ export class EditorState {
4347 readonly showPropertyPane : boolean = false ;
4448 readonly selectedCompNames : Set < string > = new Set ( ) ;
4549 readonly editorModeStatus : string = "" ;
50+ readonly collisionStatus : string = "" ;
4651 readonly isDragging : boolean = false ;
4752 readonly draggingCompType : string = "button" ;
4853 readonly forceShowGrid : boolean = false ; // show grid lines
@@ -52,16 +57,20 @@ export class EditorState {
5257 readonly showResultCompName : string = "" ;
5358 readonly selectSource ?: SelectSourceType ; // the source of select type
5459
55- private readonly setEditorState : ( fn : ( editorState : EditorState ) => EditorState ) => void ;
60+ private readonly setEditorState : (
61+ fn : ( editorState : EditorState ) => EditorState
62+ ) => void ;
5663
5764 constructor (
5865 rootComp : RootComp ,
5966 setEditorState : ( fn : ( editorState : EditorState ) => EditorState ) => void ,
60- initialEditorModeStatus : string = getEditorModeStatus ( )
67+ initialEditorModeStatus : string = getEditorModeStatus ( ) ,
68+ initialCollisionStatus : string = getCollisionStatus ( )
6169 ) {
6270 this . rootComp = rootComp ;
6371 this . setEditorState = setEditorState ;
6472 this . editorModeStatus = initialEditorModeStatus ;
73+ this . collisionStatus = initialCollisionStatus ;
6574 }
6675
6776 /**
@@ -79,7 +88,10 @@ export class EditorState {
7988 }
8089
8190 getAllCompMap ( ) {
82- return { ...this . getAllHooksCompMap ( ) , ...this . getUIComp ( ) . getAllCompItems ( ) } ;
91+ return {
92+ ...this . getAllHooksCompMap ( ) ,
93+ ...this . getUIComp ( ) . getAllCompItems ( ) ,
94+ } ;
8395 }
8496
8597 getAllUICompMap ( ) {
@@ -104,7 +116,9 @@ export class EditorState {
104116 */
105117 getUICompByName ( name : string ) {
106118 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+ ) ;
108122 }
109123
110124 getNameGenerator ( ) {
@@ -120,17 +134,22 @@ export class EditorState {
120134
121135 uiCompInfoList ( ) : Array < CompInfo > {
122136 const compMap = this . getAllUICompMap ( ) ;
123- return Object . values ( compMap ) . map ( ( item ) => {
137+ return Object . entries ( compMap ) . map ( ( [ key , item ] ) => {
124138 return {
125139 name : item . children . name . getView ( ) ,
126140 type : item . children . compType . getView ( ) ,
127141 data : item . children . comp . exposingValues ,
128142 dataDesc : item . children . comp . exposingInfo ( ) . propertyDesc ,
143+ key : key ,
129144 } ;
130145 } ) ;
131146 }
132147
133- getCompInfo ( nameAndExposingInfo : NameAndExposingInfo , name : string , type : string ) : CompInfo {
148+ getCompInfo (
149+ nameAndExposingInfo : NameAndExposingInfo ,
150+ name : string ,
151+ type : string
152+ ) : CompInfo {
134153 return {
135154 name,
136155 type,
@@ -157,7 +176,11 @@ export class EditorState {
157176 const exposingInfo = listComp . nameAndExposingInfo ( ) ;
158177 return listComp . getView ( ) . map ( ( item ) => {
159178 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+ ) ;
161184 } ) ;
162185 }
163186
@@ -175,7 +198,11 @@ export class EditorState {
175198 const exposingInfo = listComp . nameAndExposingInfo ( ) ;
176199 return listComp . getView ( ) . map ( ( item ) => {
177200 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+ ) ;
179206 } ) ;
180207 }
181208
@@ -222,7 +249,10 @@ export class EditorState {
222249 }
223250
224251 selectedQueryComp ( ) {
225- if ( this . selectedBottomResType !== BottomResTypeEnum . Query || ! this . selectedBottomResName ) {
252+ if (
253+ this . selectedBottomResType !== BottomResTypeEnum . Query ||
254+ ! this . selectedBottomResName
255+ ) {
226256 return undefined ;
227257 }
228258 return this . getQueriesComp ( )
@@ -233,7 +263,9 @@ export class EditorState {
233263 }
234264
235265 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 ) => {
237269 const items = this . getBottomResListComp ( b ) . items ( ) ;
238270 return a . concat ( items ) ;
239271 } , [ ] ) ;
@@ -279,7 +311,10 @@ export class EditorState {
279311 return this . getUIComp ( ) . getComp ( ) ;
280312 }
281313 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+ ) {
283318 return comp . children . comp ;
284319 }
285320
@@ -307,7 +342,9 @@ export class EditorState {
307342 isCompSelected ( compName : string ) : OptionalComp {
308343 const compMap = this . getAllCompMap ( ) ;
309344 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 )
311348 ) ;
312349 }
313350
@@ -319,6 +356,10 @@ export class EditorState {
319356 this . changeState ( { editorModeStatus : newEditorModeStatus } ) ;
320357 }
321358
359+ setCollisionStatus ( newCollisionStatus : string ) {
360+ this . changeState ( { collisionStatus : newCollisionStatus } ) ;
361+ }
362+
322363 setDragging ( dragging : boolean ) {
323364 if ( this . isDragging === dragging ) {
324365 return ;
@@ -356,7 +397,10 @@ export class EditorState {
356397 } ) ;
357398 }
358399
359- setSelectedCompNames ( selectedCompNames : Set < string > , selectSource ?: SelectSourceType ) {
400+ setSelectedCompNames (
401+ selectedCompNames : Set < string > ,
402+ selectSource ?: SelectSourceType
403+ ) {
360404 if ( selectedCompNames . size === 0 && this . selectedCompNames . size === 0 ) {
361405 return ;
362406 }
@@ -406,7 +450,9 @@ export class EditorState {
406450 }
407451
408452 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 ) => {
410456 const items = this . getBottomResListComp ( b ) . items ( ) ;
411457 return a . concat ( items ) ;
412458 } , [ ] ) ;
@@ -467,8 +513,11 @@ export class EditorState {
467513 getAppType ( ) : UiLayoutType {
468514 return this . getUIComp ( ) . children . compType . getView ( ) ;
469515 }
516+ getCollisionStatus ( ) : string {
517+ return this . collisionStatus ;
518+ }
519+
470520}
471-
472521export const EditorContext = React . createContext < EditorState > ( undefined as any ) ;
473522
474523// current comp name
0 commit comments