feat: add importSchema event for documentModel

This commit is contained in:
LeoYuan 袁力皓 2022-09-26 14:47:41 +08:00 committed by 林熠
parent 6eefb4e96d
commit 4b8ec09e86

View File

@ -36,6 +36,10 @@ type PropChangeOptions = {
oldValue: any;
};
const Events = {
IMPORT_SCHEMA: 'shell.document.importSchema',
};
export default class DocumentModel {
private readonly [documentSymbol]: InnerDocumentModel;
private readonly [editorSymbol]: Editor;
@ -135,6 +139,7 @@ export default class DocumentModel {
*/
importSchema(schema: RootSchema) {
this[documentSymbol].import(schema);
this[editorSymbol].emit(Events.IMPORT_SCHEMA, schema);
}
/**
@ -290,4 +295,12 @@ export default class DocumentModel {
},
);
}
/**
* import schema event
* @param fn
*/
onImportSchema(fn: (schema: RootSchema) => void) {
this[editorSymbol].on(Events.IMPORT_SCHEMA, fn as any);
}
}