11import { IPublicTypeCustomView , IPublicModelEditor , IPublicModelSettingTopEntry , IPublicApiSetters } from '@alilc/lowcode-types' ;
22import { 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' ;
44import { ISettingEntry } from './setting-entry-type' ;
55import { ISettingField , SettingField } from './setting-field' ;
66import { INode } from '../../document' ;
@@ -14,33 +14,17 @@ function generateSessionId(nodes: INode[]) {
1414 . join ( ',' ) ;
1515}
1616
17- export interface ISettingTopEntry extends ISettingEntry , IPublicModelSettingTopEntry <
17+ export interface ISettingTopEntry extends SettingTopEntry { }
18+
19+ export class SettingTopEntry implements ISettingEntry , IPublicModelSettingTopEntry <
1820 INode ,
1921 ISettingField
2022> {
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 {
3923 private emitter : IEventBus = createModuleEventBus ( 'SettingTopEntry' ) ;
4024
41- private _items : Array < SettingField | IPublicTypeCustomView > = [ ] ;
25+ private _items : Array < ISettingField | IPublicTypeCustomView > = [ ] ;
4226
43- private _componentMeta : IComponentMeta | null = null ;
27+ private _componentMeta : IComponentMeta | null | undefined = null ;
4428
4529 private _isSame = true ;
4630
@@ -75,7 +59,7 @@ export class SettingTopEntry implements ISettingTopEntry {
7559 }
7660
7761 get isLocked ( ) : boolean {
78- return this . first . isLocked ;
62+ return this . first ? .isLocked ?? false ;
7963 }
8064
8165 /**
@@ -87,7 +71,11 @@ export class SettingTopEntry implements ISettingTopEntry {
8771
8872 readonly id : string ;
8973
90- readonly first : INode ;
74+ @computed get first ( ) : INode | null {
75+ return this . _first ;
76+ }
77+
78+ @obx . ref _first : INode | null ;
9179
9280 readonly designer : IDesigner | undefined ;
9381
@@ -96,12 +84,14 @@ export class SettingTopEntry implements ISettingTopEntry {
9684 disposeFunctions : any [ ] = [ ] ;
9785
9886 constructor ( readonly editor : IPublicModelEditor , readonly nodes : INode [ ] ) {
87+ makeObservable ( this ) ;
88+
9989 if ( ! Array . isArray ( nodes ) || nodes . length < 1 ) {
10090 throw new ReferenceError ( 'nodes should not be empty' ) ;
10191 }
10292 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 ;
10595 this . setters = editor . get ( 'setters' ) as IPublicApiSetters ;
10696
10797 // setups
@@ -116,7 +106,7 @@ export class SettingTopEntry implements ISettingTopEntry {
116106 private setupComponentMeta ( ) {
117107 // todo: enhance compile a temp configure.compiled
118108 const { first } = this ;
119- const meta = first . componentMeta ;
109+ const meta = first ? .componentMeta ;
120110 const l = this . nodes . length ;
121111 let theSame = true ;
122112 for ( let i = 1 ; i < l ; i ++ ) {
@@ -160,7 +150,7 @@ export class SettingTopEntry implements ISettingTopEntry {
160150 /**
161151 * 获取当前属性值
162152 */
163- @ computed getValue ( ) : any {
153+ getValue ( ) : any {
164154 return this . first ?. propsData ;
165155 }
166156
@@ -202,14 +192,14 @@ export class SettingTopEntry implements ISettingTopEntry {
202192 * 获取子级属性值
203193 */
204194 getPropValue ( propName : string | number ) : any {
205- return this . first . getProp ( propName . toString ( ) , true ) ?. getValue ( ) ;
195+ return this . first ? .getProp ( propName . toString ( ) , true ) ?. getValue ( ) ;
206196 }
207197
208198 /**
209199 * 获取顶层附属属性值
210200 */
211201 getExtraPropValue ( propName : string ) {
212- return this . first . getExtraProp ( propName , false ) ?. getValue ( ) ;
202+ return this . first ? .getExtraProp ( propName , false ) ?. getValue ( ) ;
213203 }
214204
215205 /**
@@ -244,8 +234,9 @@ export class SettingTopEntry implements ISettingTopEntry {
244234 this . disposeItems ( ) ;
245235 this . _settingFieldMap = { } ;
246236 this . emitter . removeAllListeners ( ) ;
247- this . disposeFunctions . forEach ( f => f ( ) ) ;
237+ this . disposeFunctions . forEach ( f => f ?. ( ) ) ;
248238 this . disposeFunctions = [ ] ;
239+ this . _first = null ;
249240 }
250241
251242 getProp ( propName : string | number ) {
@@ -274,7 +265,7 @@ export class SettingTopEntry implements ISettingTopEntry {
274265 }
275266
276267 getPage ( ) {
277- return this . first . document ;
268+ return this . first ? .document ;
278269 }
279270
280271 /**
@@ -292,6 +283,7 @@ export class SettingTopEntry implements ISettingTopEntry {
292283interface Purgeable {
293284 purge ( ) : void ;
294285}
286+
295287function isPurgeable ( obj : any ) : obj is Purgeable {
296288 return obj && obj . purge ;
297289}
0 commit comments