diff --git a/src/asset_manager/index.js b/src/asset_manager/index.js index b2ac562d8..c72d413ab 100644 --- a/src/asset_manager/index.js +++ b/src/asset_manager/index.js @@ -56,6 +56,7 @@ export const evUpdate = `${evPfx}update`; export const evAdd = `${evPfx}add`; export const evRemove = `${evPfx}remove`; export const evRemoveBefore = `${evRemove}:before`; +export const evCustom = `${evRemove}:custom`; export default () => { let c = {}; @@ -79,7 +80,8 @@ export default () => { update: evUpdate, add: evAdd, remove: evRemove, - removeBefore: evRemoveBefore + removeBefore: evRemoveBefore, + custom: evCustom }, init(config = {}) { diff --git a/src/commands/view/OpenAssets.js b/src/commands/view/OpenAssets.js index cf1400f40..16c24efcb 100644 --- a/src/commands/view/OpenAssets.js +++ b/src/commands/view/OpenAssets.js @@ -1,11 +1,23 @@ export default { + open(content) { + const { editor, title } = this; + const { Modal } = editor; + Modal.open({ title, content }).onceClose(() => editor.stopCommand(this.id)); + }, + + close() { + const { Modal } = this.editor; + Modal && Modal.close(); + }, + run(editor, sender, opts = {}) { + this.editor = editor; const modal = editor.Modal; const am = editor.AssetManager; const config = am.getConfig(); - const title = opts.modalTitle || editor.t('assetManager.modalTitle') || ''; const types = opts.types; const accept = opts.accept; + this.title = opts.modalTitle || editor.t('assetManager.modalTitle') || ''; am.setTarget(opts.target); am.onClick(opts.onClick); @@ -33,14 +45,12 @@ export default { uploadEl && uploadEl.setAttribute('accept', accept); } - modal - .open({ title, content: this.rendered }) - .onceClose(() => editor.stopCommand(this.id)); + this.open(this.rendered); return this; }, stop(editor) { - const { Modal } = editor; - Modal && Modal.close(); + this.editor = editor; + this.close(this.rendered); } };