Skip to content

Commit

Permalink
fix: fix document.onMountNode parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Oct 26, 2023
1 parent 11ee97c commit 055ab68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/designer/src/document/document-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export interface IDocumentModel extends Omit<IPublicModelDocumentModel<
'onRemoveNode' |
'onChangeDetecting' |
'onChangeSelection' |
'onMountNode' |
'onChangeNodeProp' |
'onImportSchema' |
'isDetectingNode' |
Expand Down Expand Up @@ -414,6 +413,14 @@ export class DocumentModel implements IDocumentModel {
return node ? !node.isPurged : false;
}

onMountNode(fn: (payload: { node: INode }) => void) {
this.designer.editor.eventBus.on('node.add', fn as any);

return () => {
this.designer.editor.eventBus.off('node.add', fn as any);
};
}

/**
* 根据 schema 创建一个节点
*/
Expand Down
9 changes: 5 additions & 4 deletions packages/shell/src/model/document-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ export class DocumentModel implements IPublicModelDocumentModel {
* 当前 document 新增节点事件,此时节点已经挂载到 document 上
*/
onMountNode(fn: (payload: { node: IPublicModelNode }) => void): IPublicTypeDisposable {
this[editorSymbol].eventBus.on('node.add', fn as any);
return () => {
this[editorSymbol].eventBus.off('node.add', fn as any);
};
return this[documentSymbol].onMountNode(({
node,
}) => {
fn({ node: ShellNode.create(node)! });
});
}

/**
Expand Down

0 comments on commit 055ab68

Please sign in to comment.