@@ -39,6 +39,10 @@ export interface IDocumentModel extends IPublicModelDocumentModel {
3939
4040 readonly designer : Designer ;
4141
42+ /**
43+ * 根据 id 获取节点
44+ */
45+ getNode ( id : string ) : INode | null ;
4246}
4347
4448export class DocumentModel implements IDocumentModel {
@@ -118,16 +122,85 @@ export class DocumentModel implements IDocumentModel {
118122
119123 @obx . ref private _drillDownNode : Node | null = null ;
120124
121- drillDown ( node : Node | null ) {
122- this . _drillDownNode = node ;
123- }
124-
125125 private _modalNode ?: INode ;
126126
127127 private _blank ?: boolean ;
128128
129129 private inited = false ;
130130
131+ @obx . shallow private willPurgeSpace : Node [ ] = [ ] ;
132+
133+ get modalNode ( ) {
134+ return this . _modalNode ;
135+ }
136+
137+ get currentRoot ( ) {
138+ return this . modalNode || this . focusNode ;
139+ }
140+
141+ @obx . shallow private activeNodes ?: Node [ ] ;
142+
143+ @obx . ref private _dropLocation : IDropLocation | null = null ;
144+
145+ set dropLocation ( loc : IPublicModelDropLocation | null ) {
146+ this . _dropLocation = loc ;
147+ // pub event
148+ this . designer . editor . eventBus . emit (
149+ 'document.dropLocation.changed' ,
150+ { document : this , location : loc } ,
151+ ) ;
152+ }
153+
154+ /**
155+ * 投放插入位置标记
156+ */
157+ get dropLocation ( ) {
158+ return this . _dropLocation ;
159+ }
160+
161+ /**
162+ * 导出 schema 数据
163+ */
164+ get schema ( ) : IPublicTypeRootSchema {
165+ return this . rootNode ?. schema as any ;
166+ }
167+
168+ @obx . ref private _opened = false ;
169+
170+ @obx . ref private _suspensed = false ;
171+
172+ /**
173+ * 是否为非激活状态
174+ */
175+ get suspensed ( ) : boolean {
176+ return this . _suspensed || ! this . _opened ;
177+ }
178+
179+ /**
180+ * 与 suspensed 相反,是否为激活状态,这个函数可能用的更多一点
181+ */
182+ get active ( ) : boolean {
183+ return ! this . _suspensed ;
184+ }
185+
186+ /**
187+ * @deprecated 兼容
188+ */
189+ get actived ( ) : boolean {
190+ return this . active ;
191+ }
192+
193+ /**
194+ * 是否打开
195+ */
196+ get opened ( ) {
197+ return this . _opened ;
198+ }
199+
200+ get root ( ) {
201+ return this . rootNode ;
202+ }
203+
131204 constructor ( project : Project , schema ?: IPublicTypeRootSchema ) {
132205 makeObservable ( this ) ;
133206 this . project = project ;
@@ -162,6 +235,10 @@ export class DocumentModel implements IDocumentModel {
162235 this . inited = true ;
163236 }
164237
238+ drillDown ( node : Node | null ) {
239+ this . _drillDownNode = node ;
240+ }
241+
165242 onChangeNodeVisible ( fn : ( node : IPublicModelNode , visible : boolean ) => void ) : ( ) => void {
166243 this . designer . editor ?. eventBus . on ( EDITOR_EVENT . NODE_CHILDREN_CHANGE , fn ) ;
167244
@@ -178,16 +255,6 @@ export class DocumentModel implements IDocumentModel {
178255 } ;
179256 }
180257
181- @obx . shallow private willPurgeSpace : Node [ ] = [ ] ;
182-
183- get modalNode ( ) {
184- return this . _modalNode ;
185- }
186-
187- get currentRoot ( ) {
188- return this . modalNode || this . focusNode ;
189- }
190-
191258 addWillPurge ( node : Node ) {
192259 this . willPurgeSpace . push ( node ) ;
193260 }
@@ -204,7 +271,7 @@ export class DocumentModel implements IDocumentModel {
204271 }
205272
206273 /**
207- * 生成唯一id
274+ * 生成唯一 id
208275 */
209276 nextId ( possibleId : string | undefined ) {
210277 let id = possibleId ;
@@ -218,7 +285,7 @@ export class DocumentModel implements IDocumentModel {
218285 /**
219286 * 根据 id 获取节点
220287 */
221- getNode ( id : string ) : Node | null {
288+ getNode ( id : string ) : INode | null {
222289 return this . _nodesMap . get ( id ) || null ;
223290 }
224291
@@ -237,8 +304,6 @@ export class DocumentModel implements IDocumentModel {
237304 return node ? ! node . isPurged : false ;
238305 }
239306
240- @obx . shallow private activeNodes ?: Node [ ] ;
241-
242307 /**
243308 * 根据 schema 创建一个节点
244309 */
@@ -338,24 +403,6 @@ export class DocumentModel implements IDocumentModel {
338403 this . _nodesMap . delete ( node . id ) ;
339404 }
340405
341- @obx . ref private _dropLocation : IDropLocation | null = null ;
342-
343- set dropLocation ( loc : IPublicModelDropLocation | null ) {
344- this . _dropLocation = loc ;
345- // pub event
346- this . designer . editor . eventBus . emit (
347- 'document.dropLocation.changed' ,
348- { document : this , location : loc } ,
349- ) ;
350- }
351-
352- /**
353- * 投放插入位置标记
354- */
355- get dropLocation ( ) {
356- return this . _dropLocation ;
357- }
358-
359406 /**
360407 * 包裹当前选区中的节点
361408 */
@@ -378,13 +425,6 @@ export class DocumentModel implements IDocumentModel {
378425 return null ;
379426 }
380427
381- /**
382- * 导出 schema 数据
383- */
384- get schema ( ) : IPublicTypeRootSchema {
385- return this . rootNode ?. schema as any ;
386- }
387-
388428 @action
389429 import ( schema : IPublicTypeRootSchema , checkId = false ) {
390430 const drillDownNodeId = this . _drillDownNode ?. id ;
@@ -449,37 +489,6 @@ export class DocumentModel implements IDocumentModel {
449489 ) ;
450490 }
451491
452- @obx . ref private _opened = false ;
453-
454- @obx . ref private _suspensed = false ;
455-
456- /**
457- * 是否为非激活状态
458- */
459- get suspensed ( ) : boolean {
460- return this . _suspensed || ! this . _opened ;
461- }
462-
463- /**
464- * 与 suspensed 相反,是否为激活状态,这个函数可能用的更多一点
465- */
466- get active ( ) : boolean {
467- return ! this . _suspensed ;
468- }
469-
470- /**
471- * @deprecated 兼容
472- */
473- get actived ( ) : boolean {
474- return this . active ;
475- }
476-
477- /**
478- * 是否打开
479- */
480- get opened ( ) {
481- return this . _opened ;
482- }
483492
484493 /**
485494 * 切换激活,只有打开的才能激活
@@ -617,10 +626,6 @@ export class DocumentModel implements IDocumentModel {
617626 return this . history ;
618627 }
619628
620- get root ( ) {
621- return this . rootNode ;
622- }
623-
624629 /**
625630 * @deprecated
626631 */
0 commit comments