1
1
import { IPublicTypeCustomView , IPublicModelEditor , IPublicModelSettingTopEntry , IPublicApiSetters } from '@alilc/lowcode-types' ;
2
2
import { isCustomView } from '@alilc/lowcode-utils' ;
3
- import { computed , IEventBus , createModuleEventBus } from '@alilc/lowcode-editor-core' ;
3
+ import { computed , IEventBus , createModuleEventBus , obx , makeObservable } from '@alilc/lowcode-editor-core' ;
4
4
import { ISettingEntry } from './setting-entry-type' ;
5
5
import { ISettingField , SettingField } from './setting-field' ;
6
6
import { INode } from '../../document' ;
@@ -14,33 +14,17 @@ function generateSessionId(nodes: INode[]) {
14
14
. join ( ',' ) ;
15
15
}
16
16
17
- export interface ISettingTopEntry extends ISettingEntry , IPublicModelSettingTopEntry <
17
+ export interface ISettingTopEntry extends SettingTopEntry { }
18
+
19
+ export class SettingTopEntry implements ISettingEntry , IPublicModelSettingTopEntry <
18
20
INode ,
19
21
ISettingField
20
22
> {
21
- readonly top : ISettingTopEntry ;
22
-
23
- readonly parent : ISettingTopEntry ;
24
-
25
- readonly path : never [ ] ;
26
-
27
- items : Array < ISettingField | IPublicTypeCustomView > ;
28
-
29
- componentMeta : IComponentMeta | null ;
30
-
31
- purge ( ) : void ;
32
-
33
- getExtraPropValue ( propName : string ) : void ;
34
-
35
- setExtraPropValue ( propName : string , value : any ) : void ;
36
- }
37
-
38
- export class SettingTopEntry implements ISettingTopEntry {
39
23
private emitter : IEventBus = createModuleEventBus ( 'SettingTopEntry' ) ;
40
24
41
- private _items : Array < SettingField | IPublicTypeCustomView > = [ ] ;
25
+ private _items : Array < ISettingField | IPublicTypeCustomView > = [ ] ;
42
26
43
- private _componentMeta : IComponentMeta | null = null ;
27
+ private _componentMeta : IComponentMeta | null | undefined = null ;
44
28
45
29
private _isSame = true ;
46
30
@@ -75,7 +59,7 @@ export class SettingTopEntry implements ISettingTopEntry {
75
59
}
76
60
77
61
get isLocked ( ) : boolean {
78
- return this . first . isLocked ;
62
+ return this . first ? .isLocked ?? false ;
79
63
}
80
64
81
65
/**
@@ -87,7 +71,11 @@ export class SettingTopEntry implements ISettingTopEntry {
87
71
88
72
readonly id : string ;
89
73
90
- readonly first : INode ;
74
+ @computed get first ( ) : INode | null {
75
+ return this . _first ;
76
+ }
77
+
78
+ @obx . ref _first : INode | null ;
91
79
92
80
readonly designer : IDesigner | undefined ;
93
81
@@ -96,12 +84,14 @@ export class SettingTopEntry implements ISettingTopEntry {
96
84
disposeFunctions : any [ ] = [ ] ;
97
85
98
86
constructor ( readonly editor : IPublicModelEditor , readonly nodes : INode [ ] ) {
87
+ makeObservable ( this ) ;
88
+
99
89
if ( ! Array . isArray ( nodes ) || nodes . length < 1 ) {
100
90
throw new ReferenceError ( 'nodes should not be empty' ) ;
101
91
}
102
92
this . id = generateSessionId ( nodes ) ;
103
- this . first = nodes [ 0 ] ;
104
- this . designer = this . first . document ?. designer ;
93
+ this . _first = nodes [ 0 ] ;
94
+ this . designer = this . _first . document ?. designer ;
105
95
this . setters = editor . get ( 'setters' ) as IPublicApiSetters ;
106
96
107
97
// setups
@@ -116,7 +106,7 @@ export class SettingTopEntry implements ISettingTopEntry {
116
106
private setupComponentMeta ( ) {
117
107
// todo: enhance compile a temp configure.compiled
118
108
const { first } = this ;
119
- const meta = first . componentMeta ;
109
+ const meta = first ? .componentMeta ;
120
110
const l = this . nodes . length ;
121
111
let theSame = true ;
122
112
for ( let i = 1 ; i < l ; i ++ ) {
@@ -160,7 +150,7 @@ export class SettingTopEntry implements ISettingTopEntry {
160
150
/**
161
151
* 获取当前属性值
162
152
*/
163
- @ computed getValue ( ) : any {
153
+ getValue ( ) : any {
164
154
return this . first ?. propsData ;
165
155
}
166
156
@@ -202,14 +192,14 @@ export class SettingTopEntry implements ISettingTopEntry {
202
192
* 获取子级属性值
203
193
*/
204
194
getPropValue ( propName : string | number ) : any {
205
- return this . first . getProp ( propName . toString ( ) , true ) ?. getValue ( ) ;
195
+ return this . first ? .getProp ( propName . toString ( ) , true ) ?. getValue ( ) ;
206
196
}
207
197
208
198
/**
209
199
* 获取顶层附属属性值
210
200
*/
211
201
getExtraPropValue ( propName : string ) {
212
- return this . first . getExtraProp ( propName , false ) ?. getValue ( ) ;
202
+ return this . first ? .getExtraProp ( propName , false ) ?. getValue ( ) ;
213
203
}
214
204
215
205
/**
@@ -244,8 +234,9 @@ export class SettingTopEntry implements ISettingTopEntry {
244
234
this . disposeItems ( ) ;
245
235
this . _settingFieldMap = { } ;
246
236
this . emitter . removeAllListeners ( ) ;
247
- this . disposeFunctions . forEach ( f => f ( ) ) ;
237
+ this . disposeFunctions . forEach ( f => f ?. ( ) ) ;
248
238
this . disposeFunctions = [ ] ;
239
+ this . _first = null ;
249
240
}
250
241
251
242
getProp ( propName : string | number ) {
@@ -274,7 +265,7 @@ export class SettingTopEntry implements ISettingTopEntry {
274
265
}
275
266
276
267
getPage ( ) {
277
- return this . first . document ;
268
+ return this . first ? .document ;
278
269
}
279
270
280
271
/**
@@ -292,6 +283,7 @@ export class SettingTopEntry implements ISettingTopEntry {
292
283
interface Purgeable {
293
284
purge ( ) : void ;
294
285
}
286
+
295
287
function isPurgeable ( obj : any ) : obj is Purgeable {
296
288
return obj && obj . purge ;
297
289
}
0 commit comments