Browse Source

Support custom asset manager via custom.open/close

pull/3795/head
Artur Arseniev 4 years ago
parent
commit
acb33f48e5
  1. 6
      docs/modules/Assets.md
  2. 9
      src/asset_manager/index.js
  3. 9
      src/commands/view/OpenAssets.js

6
docs/modules/Assets.md

@ -362,6 +362,12 @@ const editor = grapesjs.init({
// `props` are the same used in `asset:custom` event // `props` are the same used in `asset:custom` event
// ... // ...
// Init and open your external Asset Manager // Init and open your external Asset Manager
// ...
// IMPORTANT:
// When the external library is closed you have to comunicate
// this state back to the editor, otherwise GrapesJS will think
// the Asset Manager is still open.
// example: myAssetManager.on('close', () => props.close())
}, },
close(props) { close(props) {
// Close the external Asset Manager // Close the external Asset Manager

9
src/asset_manager/index.js

@ -122,7 +122,12 @@ export default () => {
if (!bhv.container && !this.getConfig('custom').open) { if (!bhv.container && !this.getConfig('custom').open) {
return; return;
} }
this.em.trigger(this.events.custom, { this.em.trigger(this.events.custom, this.__customData());
},
__customData() {
const bhv = this.__getBehaviour();
return {
am: this, am: this,
open: this.isOpen(), open: this.isOpen(),
assets: this.getAll().models, assets: this.getAll().models,
@ -136,7 +141,7 @@ export default () => {
}, },
// extra // extra
options: bhv.options || {} options: bhv.options || {}
}); };
}, },
/** /**

9
src/commands/view/OpenAssets.js

@ -3,19 +3,19 @@ import { createEl } from '../../utils/dom';
export default { export default {
open(content) { open(content) {
const { editor, title, config } = this; const { editor, title, config, am } = this;
const { custom } = config; const { custom } = config;
if (isFunction(custom.open)) { if (isFunction(custom.open)) {
return custom.open(content); return custom.open(am.__customData());
} }
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(content) { close() {
const { custom } = this.config; const { custom } = this.config;
if (isFunction(custom.close)) { if (isFunction(custom.close)) {
return custom.close(content); return custom.close(this.am.__customData());
} }
const { Modal } = this.editor; const { Modal } = this.editor;
Modal && Modal.close(); Modal && Modal.close();
@ -28,6 +28,7 @@ export default {
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; this.config = config;
this.am = am;
am.setTarget(opts.target); am.setTarget(opts.target);
am.onClick(opts.onClick); am.onClick(opts.onClick);

Loading…
Cancel
Save