Browse Source

Update how custom asset event is triggered

pull/3795/head
Artur Arseniev 5 years ago
parent
commit
4fd99b091c
  1. 2
      docs/modules/Assets.md
  2. 12
      src/asset_manager/index.js
  3. 18
      src/commands/view/OpenAssets.js

2
docs/modules/Assets.md

@ -345,7 +345,7 @@ editor.on('asset:custom', props => {
Here an example of using custom Asset Manager with a Vue component. Here an example of using custom Asset Manager with a Vue component.
<demo-viewer value="x70amv3f" height="500" darkcode/> <demo-viewer value="wbj4tmqk" height="500" darkcode/>
<!-- <!--

12
src/asset_manager/index.js

@ -113,11 +113,11 @@ export default () => {
this.getAll().trigger(ev, ...data); this.getAll().trigger(ev, ...data);
}, },
__onAllEvent() { __onAllEvent: debounce(function() {
this.__trgCustom(); this.__trgCustom();
}, }),
__trgCustom: debounce(function() { __trgCustom() {
const bhv = this.__getBehaviour(); const bhv = this.__getBehaviour();
if (!bhv.container && !this.getConfig('custom').open) { if (!bhv.container && !this.getConfig('custom').open) {
return; return;
@ -133,9 +133,11 @@ export default () => {
select: (asset, complete) => { select: (asset, complete) => {
const res = this.add(asset); const res = this.add(asset);
isFunction(bhv.select) && bhv.select(res, complete); isFunction(bhv.select) && bhv.select(res, complete);
} },
// extra
options: bhv.options || {}
}); });
}), },
/** /**
* Open the asset manager. * Open the asset manager.

18
src/commands/view/OpenAssets.js

@ -1,13 +1,22 @@
import { isFunction } from 'underscore';
import { createEl } from '../../utils/dom'; import { createEl } from '../../utils/dom';
export default { export default {
open(content) { open(content) {
const { editor, title } = this; const { editor, title, config } = this;
const { custom } = config;
if (isFunction(custom.open)) {
return custom.open(content);
}
const { Modal } = editor; const { Modal } = editor;
Modal.open({ title, content }).onceClose(() => editor.stopCommand(this.id)); Modal.open({ title, content }).onceClose(() => editor.stopCommand(this.id));
}, },
close() { close(content) {
const { custom } = this.config;
if (isFunction(custom.close)) {
return custom.close(content);
}
const { Modal } = this.editor; const { Modal } = this.editor;
Modal && Modal.close(); Modal && Modal.close();
}, },
@ -18,6 +27,7 @@ export default {
const { types = [], accept, select } = opts; const { types = [], accept, select } = opts;
this.title = opts.modalTitle || editor.t('assetManager.modalTitle') || ''; this.title = opts.modalTitle || editor.t('assetManager.modalTitle') || '';
this.editor = editor; this.editor = editor;
this.config = config;
am.setTarget(opts.target); am.setTarget(opts.target);
am.onClick(opts.onClick); am.onClick(opts.onClick);
@ -25,11 +35,13 @@ export default {
am.onSelect(opts.onSelect); am.onSelect(opts.onSelect);
am.__behaviour({ am.__behaviour({
select, select,
types types,
options: opts
}); });
if (config.custom) { if (config.custom) {
this.rendered = this.rendered || createEl('div'); this.rendered = this.rendered || createEl('div');
this.rendered.className = `${config.stylePrefix}custom-wrp`;
am.__behaviour({ container: this.rendered }); am.__behaviour({ container: this.rendered });
am.__trgCustom(); am.__trgCustom();
} else { } else {

Loading…
Cancel
Save