From dc3e91443a02ff557a49e0e0b0cea296a8f7181a Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 4 Oct 2021 15:26:59 +0200 Subject: [PATCH] Load blocks data on init --- src/block_manager/index.js | 6 +----- src/commands/view/OpenBlocks.js | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/block_manager/index.js b/src/block_manager/index.js index c8581c0ec..bdc396d66 100644 --- a/src/block_manager/index.js +++ b/src/block_manager/index.js @@ -104,6 +104,7 @@ export default () => { blocksVisible = new Blocks([]); categories = new Categories(); this.all = blocks; + blocks.add(c.blocks); this.__initListen(); // Setup the sync between the global and public collections @@ -211,11 +212,6 @@ export default () => { return c; }, - onLoad() { - const blocks = this.getAll(); - !blocks.length && blocks.reset(c.blocks); - }, - postRender() { const collection = blocksVisible; blocksView = new BlocksView({ collection, categories }, c); diff --git a/src/commands/view/OpenBlocks.js b/src/commands/view/OpenBlocks.js index f1a049030..26fd1a1ba 100644 --- a/src/commands/view/OpenBlocks.js +++ b/src/commands/view/OpenBlocks.js @@ -1,27 +1,40 @@ +import { isFunction } from 'underscore'; import { createEl } from '../../utils/dom'; export default { open() { - const { container, editor, bm } = this; + const { container, editor, bm, config } = this; + const { custom } = config; + + if (isFunction(custom.open)) { + return custom.open(bm.__customData()); + } if (this.firstRender) { const id = 'views-container'; const pn = editor.Panels; const panels = pn.getPanel(id) || pn.addPanel({ id }); panels.set('appendContent', container).trigger('change:appendContent'); - if (!bm.getConfig().custom) container.appendChild(bm.render()); + if (!custom) container.appendChild(bm.render()); } if (container) container.style.display = 'block'; }, close() { - const { container } = this; + const { container, config } = this; + const { custom } = config; + + if (isFunction(custom.close)) { + return custom.close(this.bm.__customData()); + } + if (container) container.style.display = 'none'; }, run(editor, sender) { const bm = editor.Blocks; + this.config = bm.getConfig(); this.firstRender = !this.container; this.container = this.container || createEl('div'); this.editor = editor; @@ -31,7 +44,7 @@ export default { container }); - if (bm.getConfig().custom) { + if (this.config.custom) { bm.__trgCustom(); }