Skip to content

Commit a5d099b

Browse files
initial
1 parent b106575 commit a5d099b

File tree

6 files changed

+305
-73
lines changed

6 files changed

+305
-73
lines changed

client/packages/lowcoder/src/comps/editorState.tsx

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { isContainer } from "comps/comps/containerBase";
22
import { RootComp as RootCompTmp } from "comps/comps/rootComp";
33
import { PositionParams } from "layout";
44
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";
711
import { setFields } from "util/objectUtils";
812
import { OptionalComp, renameAction } from "lowcoder-core";
913
import { GridItemComp } from "./comps/gridItemComp";
@@ -13,7 +17,7 @@ import { NameAndExposingInfo } from "./utils/exposingTypes";
1317
import { checkName } from "./utils/rename";
1418
import { trans } from "i18n";
1519
import { UiLayoutType } from "./comps/uiComp";
16-
import { getEditorModeStatus } from "util/localStorageUtil";
20+
import { getCollissionStatus, getEditorModeStatus } from "util/localStorageUtil";
1721

1822
type 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 collissionStatus: 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+
initialCollissionStatus: string = getCollissionStatus()
6169
) {
6270
this.rootComp = rootComp;
6371
this.setEditorState = setEditorState;
6472
this.editorModeStatus = initialEditorModeStatus;
73+
this.collissionStatus = initialCollissionStatus;
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() {
@@ -130,7 +144,11 @@ export class EditorState {
130144
});
131145
}
132146

133-
getCompInfo(nameAndExposingInfo: NameAndExposingInfo, name: string, type: string): CompInfo {
147+
getCompInfo(
148+
nameAndExposingInfo: NameAndExposingInfo,
149+
name: string,
150+
type: string
151+
): CompInfo {
134152
return {
135153
name,
136154
type,
@@ -157,7 +175,11 @@ export class EditorState {
157175
const exposingInfo = listComp.nameAndExposingInfo();
158176
return listComp.getView().map((item) => {
159177
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+
);
161183
});
162184
}
163185

@@ -175,7 +197,11 @@ export class EditorState {
175197
const exposingInfo = listComp.nameAndExposingInfo();
176198
return listComp.getView().map((item) => {
177199
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+
);
179205
});
180206
}
181207

@@ -222,7 +248,10 @@ export class EditorState {
222248
}
223249

224250
selectedQueryComp() {
225-
if (this.selectedBottomResType !== BottomResTypeEnum.Query || !this.selectedBottomResName) {
251+
if (
252+
this.selectedBottomResType !== BottomResTypeEnum.Query ||
253+
!this.selectedBottomResName
254+
) {
226255
return undefined;
227256
}
228257
return this.getQueriesComp()
@@ -233,7 +262,9 @@ export class EditorState {
233262
}
234263

235264
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) => {
237268
const items = this.getBottomResListComp(b).items();
238269
return a.concat(items);
239270
}, []);
@@ -279,7 +310,10 @@ export class EditorState {
279310
return this.getUIComp().getComp();
280311
}
281312
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+
) {
283317
return comp.children.comp;
284318
}
285319

@@ -307,7 +341,9 @@ export class EditorState {
307341
isCompSelected(compName: string): OptionalComp {
308342
const compMap = this.getAllCompMap();
309343
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)
311347
);
312348
}
313349

@@ -319,6 +355,10 @@ export class EditorState {
319355
this.changeState({ editorModeStatus: newEditorModeStatus });
320356
}
321357

358+
setCollissionStatus(newCollissionStatus: string) {
359+
this.changeState({ collissionStatus: newCollissionStatus });
360+
}
361+
322362
setDragging(dragging: boolean) {
323363
if (this.isDragging === dragging) {
324364
return;
@@ -356,7 +396,10 @@ export class EditorState {
356396
});
357397
}
358398

359-
setSelectedCompNames(selectedCompNames: Set<string>, selectSource?: SelectSourceType) {
399+
setSelectedCompNames(
400+
selectedCompNames: Set<string>,
401+
selectSource?: SelectSourceType
402+
) {
360403
if (selectedCompNames.size === 0 && this.selectedCompNames.size === 0) {
361404
return;
362405
}
@@ -406,7 +449,9 @@ export class EditorState {
406449
}
407450

408451
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) => {
410455
const items = this.getBottomResListComp(b).items();
411456
return a.concat(items);
412457
}, []);
@@ -467,8 +512,10 @@ export class EditorState {
467512
getAppType(): UiLayoutType {
468513
return this.getUIComp().children.compType.getView();
469514
}
515+
getCollissionStatus(): string {
516+
return this.collissionStatus;
517+
}
470518
}
471-
472519
export const EditorContext = React.createContext<EditorState>(undefined as any);
473520

474521
// current comp name

0 commit comments

Comments
 (0)