Browse Source

Remove init function from EditorModule

pull/4258/head
Alex Ritter 4 years ago
parent
commit
267901fdd9
  1. 1
      src/canvas/index.js
  2. 35
      src/editor/index.js
  3. 2
      src/index.js
  4. 8
      test/specs/block_manager/index.js
  5. 12
      test/specs/device_manager/index.js
  6. 8
      test/specs/editor/index.js
  7. 2
      test/specs/i18n/index.js
  8. 2
      test/specs/keymaps/index.js

1
src/canvas/index.js

@ -267,7 +267,6 @@ export default class CanvasModule {
model: this.canvas,
config: this.c,
});
console.log(this.canvas);
return this.canvasView.render().el;
}

35
src/editor/index.js

@ -62,31 +62,11 @@ import EditorView from './view/EditorView';
export default class EditorModule {
constructor(config = {}, opts = {}) {
this.$ = opts.$;
this.c = {
...defaults,
...config,
};
this.c = { ...defaults, ...config };
this.c.pStylePrefix = this.c.stylePrefix;
this.em = new EditorModel(this.c);
this.em.init(this);
this.editor = this.em;
}
editorView;
/**
* @property {EditorModel}
* @private
*/
//editor = em
modules = [];
/**
* Initialize editor model
* @return {this}
* @private
*/
init(opts = {}) {
this.em.init(this, { ...this.c, ...opts });
this.modules = [
'I18n',
@ -131,9 +111,16 @@ export default class EditorModule {
this[prop] = this.em.get(prop);
}
});
return this;
}
editorView;
/**
* @property {EditorModel}
* @private
*/
//editor = em
modules = [];
/**
* Returns configuration object

2
src/index.js

@ -52,7 +52,7 @@ export default {
if (!els && !headless) throw new Error("'container' is required");
config = { ...defaultConfig, ...config, grapesjs: this };
config.el = !headless && (isElement(els) ? els : document.querySelector(els));
const editor = new Editor(config, { $ }).init();
const editor = new Editor(config, { $ });
const em = editor.getModel();
// Load plugins

8
test/specs/block_manager/index.js

@ -10,14 +10,14 @@ describe('BlockManager', () => {
beforeEach(() => {
editor = new Editor({
blockManager: {
blocks: []
}
}).init();
blocks: [],
},
});
idTest = 'h1-block';
optsTest = {
label: 'Heading',
content: '<h1>Test</h1>'
content: '<h1>Test</h1>',
};
obj = editor.Blocks;

12
test/specs/device_manager/index.js

@ -13,9 +13,9 @@ describe('DeviceManager', () => {
testWidthDevice = '100px';
editor = new Editor({
deviceManager: {
devices: []
}
}).init();
devices: [],
},
});
em = editor.getModel();
obj = editor.Devices;
});
@ -64,7 +64,7 @@ describe('DeviceManager', () => {
test('Add device with props', () => {
const model = obj.add({
name: testNameDevice,
width: testWidthDevice
width: testWidthDevice,
});
expect(model.get('id')).toEqual(testNameDevice);
expect(model.get('name')).toEqual(testNameDevice);
@ -73,7 +73,7 @@ describe('DeviceManager', () => {
test('Add device without id and name', () => {
const model = obj.add({
width: testWidthDevice
width: testWidthDevice,
});
expect(model.get('name')).toEqual('');
expect(model.get('width')).toEqual(testWidthDevice);
@ -97,7 +97,7 @@ describe('DeviceManager', () => {
test('Get device by name with different id', () => {
const model = obj.add({
id: 'device',
name: testNameDevice
name: testNameDevice,
});
const model2 = obj.get(testNameDevice);
expect(model).toBe(model2);

8
test/specs/editor/index.js

@ -8,7 +8,6 @@ describe('Editor', () => {
beforeEach(() => {
editor = new Editor();
editor.init();
editor.getModel().loadOnStart();
});
@ -99,12 +98,7 @@ describe('Editor', () => {
</div>`);
expect(umStack.length).toBe(1); // UM counts first children
expect(keys(all).length).toBe(5 + initComps);
wrapper
.components()
.at(0)
.components()
.at(0)
.remove(); // Remove 1 component
wrapper.components().at(0).components().at(0).remove(); // Remove 1 component
expect(umStack.length).toBe(2);
expect(keys(all).length).toBe(3 + initComps);

2
test/specs/i18n/index.js

@ -4,7 +4,7 @@ import Editor from 'editor';
describe('I18n', () => {
describe('Main', () => {
let obj;
let editor = new Editor().init();
let editor = new Editor();
let em = editor.getModel();
beforeEach(() => {

2
test/specs/keymaps/index.js

@ -7,7 +7,7 @@ describe('Keymaps', () => {
let editor;
beforeEach(() => {
editor = new Editor({ keymaps: { defaults: [] } }).init();
editor = new Editor({ keymaps: { defaults: [] } });
em = editor.getModel();
em.loadOnStart();
obj = editor.Keymaps;

Loading…
Cancel
Save