Browse Source

Load blocks data on init

pull/3905/head
Artur Arseniev 5 years ago
parent
commit
dc3e91443a
  1. 6
      src/block_manager/index.js
  2. 21
      src/commands/view/OpenBlocks.js

6
src/block_manager/index.js

@ -104,6 +104,7 @@ export default () => {
blocksVisible = new Blocks([]); blocksVisible = new Blocks([]);
categories = new Categories(); categories = new Categories();
this.all = blocks; this.all = blocks;
blocks.add(c.blocks);
this.__initListen(); this.__initListen();
// Setup the sync between the global and public collections // Setup the sync between the global and public collections
@ -211,11 +212,6 @@ export default () => {
return c; return c;
}, },
onLoad() {
const blocks = this.getAll();
!blocks.length && blocks.reset(c.blocks);
},
postRender() { postRender() {
const collection = blocksVisible; const collection = blocksVisible;
blocksView = new BlocksView({ collection, categories }, c); blocksView = new BlocksView({ collection, categories }, c);

21
src/commands/view/OpenBlocks.js

@ -1,27 +1,40 @@
import { isFunction } from 'underscore';
import { createEl } from '../../utils/dom'; import { createEl } from '../../utils/dom';
export default { export default {
open() { 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) { if (this.firstRender) {
const id = 'views-container'; const id = 'views-container';
const pn = editor.Panels; const pn = editor.Panels;
const panels = pn.getPanel(id) || pn.addPanel({ id }); const panels = pn.getPanel(id) || pn.addPanel({ id });
panels.set('appendContent', container).trigger('change:appendContent'); 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'; if (container) container.style.display = 'block';
}, },
close() { 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'; if (container) container.style.display = 'none';
}, },
run(editor, sender) { run(editor, sender) {
const bm = editor.Blocks; const bm = editor.Blocks;
this.config = bm.getConfig();
this.firstRender = !this.container; this.firstRender = !this.container;
this.container = this.container || createEl('div'); this.container = this.container || createEl('div');
this.editor = editor; this.editor = editor;
@ -31,7 +44,7 @@ export default {
container container
}); });
if (bm.getConfig().custom) { if (this.config.custom) {
bm.__trgCustom(); bm.__trgCustom();
} }

Loading…
Cancel
Save