(readonly document: IDocumentModel, nodeSchema: Schema)
| 369 | }; |
| 370 | |
| 371 | constructor(readonly document: IDocumentModel, nodeSchema: Schema) { |
| 372 | makeObservable(this); |
| 373 | const { componentName, id, children, props, ...extras } = nodeSchema; |
| 374 | this.id = document.nextId(id); |
| 375 | this.componentName = componentName; |
| 376 | if (this.componentName === 'Leaf') { |
| 377 | this.props = new Props(this, { |
| 378 | children: isDOMText(children) || isJSExpression(children) ? children : '', |
| 379 | }); |
| 380 | } else { |
| 381 | this.props = new Props(this, props, extras); |
| 382 | this._children = new NodeChildren(this as INode, this.initialChildren(children)); |
| 383 | this._children.internalInitParent(); |
| 384 | this.props.merge( |
| 385 | this.upgradeProps(this.initProps(props || {})), |
| 386 | this.upgradeProps(extras), |
| 387 | ); |
| 388 | this.setupAutoruns(); |
| 389 | } |
| 390 | |
| 391 | this.initBuiltinProps(); |
| 392 | |
| 393 | this.isInited = true; |
| 394 | this.emitter = createModuleEventBus('Node'); |
| 395 | const { editor } = this.document.designer; |
| 396 | this.onVisibleChange((visible: boolean) => { |
| 397 | editor?.eventBus.emit(EDITOR_EVENT.NODE_VISIBLE_CHANGE, this, visible); |
| 398 | }); |
| 399 | this.onChildrenChange((info?: { type: string; node: INode }) => { |
| 400 | editor?.eventBus.emit(EDITOR_EVENT.NODE_CHILDREN_CHANGE, { |
| 401 | type: info?.type, |
| 402 | node: this, |
| 403 | }); |
| 404 | }); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * 节点初始化期间就把内置的一些 prop 初始化好,避免后续不断构造实例导致 reaction 执行多次 |
nothing calls this directly
no test coverage detected