Browse Source

Adjust destroy in headless mode

pull/3671/head
Artur Arseniev 5 years ago
parent
commit
f38c3cc0e6
  1. 5
      src/commands/view/SelectComponent.js
  2. 13
      src/editor/model/Editor.js

5
src/commands/view/SelectComponent.js

@ -5,7 +5,8 @@ import {
off, off,
getUnitFromValue, getUnitFromValue,
isTaggableNode, isTaggableNode,
getViewEl getViewEl,
hasWin
} from 'utils/mixins'; } from 'utils/mixins';
import { isVisible, isDoc } from 'utils/dom'; import { isVisible, isDoc } from 'utils/dom';
import ToolbarView from 'dom_components/view/ToolbarView'; import ToolbarView from 'dom_components/view/ToolbarView';
@ -746,11 +747,13 @@ export default {
}, },
run(editor) { run(editor) {
if (!hasWin()) return;
this.editor = editor && editor.get('Editor'); this.editor = editor && editor.get('Editor');
this.enable(); this.enable();
}, },
stop(ed, sender, opts = {}) { stop(ed, sender, opts = {}) {
if (!hasWin()) return;
const { em, editor } = this; const { em, editor } = this;
this.onHovered(); // force to hide toolbar this.onHovered(); // force to hide toolbar
this.stopSelectComponent(); this.stopSelectComponent();

13
src/editor/model/Editor.js

@ -10,7 +10,7 @@ import {
import $ from 'cash-dom'; import $ from 'cash-dom';
import Backbone from 'backbone'; import Backbone from 'backbone';
import Extender from 'utils/extender'; import Extender from 'utils/extender';
import { getModel } from 'utils/mixins'; import { getModel, hasWin } from 'utils/mixins';
import Selected from './Selected'; import Selected from './Selected';
Backbone.$ = $; Backbone.$ = $;
@ -786,7 +786,7 @@ export default Backbone.Model.extend({
* Destroy editor * Destroy editor
*/ */
destroyAll() { destroyAll() {
const { config } = this; const { config, view } = this;
const editor = this.getEditor(); const editor = this.getEditor();
const { editors = [] } = config.grapesjs || {}; const { editors = [] } = config.grapesjs || {};
this.stopDefault(); this.stopDefault();
@ -794,7 +794,7 @@ export default Backbone.Model.extend({
.slice() .slice()
.reverse() .reverse()
.forEach(mod => mod.destroy()); .forEach(mod => mod.destroy());
this.view.remove(); view && view.remove();
this.stopListening(); this.stopListening();
this.clear({ silent: true }); this.clear({ silent: true });
this.destroyed = 1; this.destroyed = 1;
@ -802,9 +802,10 @@ export default Backbone.Model.extend({
i => (this[i] = {}) i => (this[i] = {})
); );
editors.splice(editors.indexOf(editor), 1); editors.splice(editors.indexOf(editor), 1);
$(config.el) hasWin() &&
.empty() $(config.el)
.attr(this.attrsOrig); .empty()
.attr(this.attrsOrig);
}, },
getEditing() { getEditing() {

Loading…
Cancel
Save