diff --git a/src/config/require-config.js b/src/config/require-config.js index cd8687ad0..5d48af2cb 100644 --- a/src/config/require-config.js +++ b/src/config/require-config.js @@ -33,6 +33,8 @@ require.config({ }, packages : [ + { name: 'GrapesJS', location: 'grapesjs', }, + { name: 'Editor', location: 'editor', }, { name: 'AssetManager', location: 'asset_manager', }, { name: 'StyleManager', location: 'style_manager', }, { name: 'ClassManager', location: 'class_manager', }, diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index bed26f189..d986bf9d9 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -80,7 +80,8 @@ define([ * @private * */ initUtils: function() { - this.set('Utils', new Utils()); + this.Utils = new Utils(); + this.set('Utils', this.Utils); }, /** @@ -155,6 +156,7 @@ define([ cfg.stylePrefix = this.config.stylePrefix + pfx; cfg.target = this; this.clm = new ClassManager(cfg); + this.ClassManager = this.clm; this.set('ClassManager', this.clm); }, @@ -211,7 +213,7 @@ define([ if(this.cmp) this.cv.setWrapper(this.cmp); - + this.Canvas = this.cv; this.set('Canvas', this.cv); }, @@ -250,7 +252,8 @@ define([ if(this.stm) cfg.stm = this.stm; - this.am = new AssetManager(cfg); + this.am = new AssetManager(cfg); + this.AssetManager = this.am; this.set('AssetManager', this.am); }, @@ -264,6 +267,7 @@ define([ cfg.stylePrefix = this.config.stylePrefix + pfx; this.modal = new ModalDialog(cfg); this.modal.render().appendTo('body'); + this.Dialog = this.modal; this.set('Modal', this.modal); }, @@ -293,6 +297,7 @@ define([ cfg.canvasId = this.config.idCanvas; cfg.wrapperId = this.config.idWrapper; this.com = new Commands(cfg); + this.Commands = this.com; this.com.loadDefaultCommands(); this.set('Commands', this.com); }, @@ -308,6 +313,7 @@ define([ cfg.em = this; this.pn = new Panels(cfg); this.pn.addPanel({ id: 'views-container'}); + this.Panels = this.pn; this.set('Panels', this.pn); }, @@ -324,6 +330,7 @@ define([ register: [this.cmp.getComponent().get('components')], track: true }); + this.UndoManager = this.um; this.set('UndoManager', this.um); key('⌘+z, ctrl+z', function(){ that.um.undo(); diff --git a/src/grapesjs/main.js b/src/grapesjs/main.js index f57fce5bd..7ce04009d 100644 --- a/src/grapesjs/main.js +++ b/src/grapesjs/main.js @@ -1,9 +1,11 @@ -define(function(require) { +define(function (require) { return function(config) { var c = config || {}, - defaults = require('./config/config'); + defaults = require('./config/config'), + Editor = require('editor/main'), + PluginManager = require('PluginManager'); // Set default options for (var name in defaults) { @@ -11,13 +13,7 @@ define(function(require) { c[name] = defaults[name]; } - var plugins = []; - /* - .plugins will be PluginManager - grapesjs.plugins.add('sheeet', function(editor){ - editor.commands.add('openbar', function(){}); - }); - */ + var plugins = new PluginManager(); var editors = []; return { @@ -36,13 +32,13 @@ define(function(require) { * @return {grapesjs.Editor} GrapesJS Editor instance */ init: function(config) { - // var editor = new Editor(config); //- new EditorView({model: editor}).render(); //- inject and start plugins (plugins) // foreach config.plugins // pluginManager.get('plugin')(editor); // + return editor; }, diff --git a/src/plugin_manager/main.js b/src/plugin_manager/main.js index cc32983ab..cf70b86fd 100644 --- a/src/plugin_manager/main.js +++ b/src/plugin_manager/main.js @@ -19,6 +19,7 @@ define(function(require) { * Add new plugin. Plugins could not be overwritten * @param {string} id Plugin ID * @param {Function} plugin Function which contains all plugin logic + * @return {this} * @example * PluginManager.add('some-plugin', function(editor){ * editor.Commands.add('new-command', { @@ -29,6 +30,8 @@ define(function(require) { * }); */ add: function(id, plugin){ + if(plugins[id]) + return this; plugins[id] = plugin; return this; }, diff --git a/test/runner/main.js b/test/runner/main.js index 76d5a2464..b8b6ad713 100644 --- a/test/runner/main.js +++ b/test/runner/main.js @@ -2,6 +2,7 @@ require(['../src/config/require-config.js', 'config/config.js'], function() { require(['chai', 'sinon', + 'specs/grapesjs/main.js', 'specs/main.js', 'specs/asset_manager/main.js', 'specs/asset_manager/model/Asset.js', diff --git a/test/specs/grapesjs/main.js b/test/specs/grapesjs/main.js new file mode 100644 index 000000000..bd2d0f511 --- /dev/null +++ b/test/specs/grapesjs/main.js @@ -0,0 +1,31 @@ +define(['GrapesJS', 'PluginManager'], + function(GrapesJS, PluginManager) { + + describe('GrapesJS', function() { + + describe('Main', function() { + + var obj; + + beforeEach(function () { + obj = new GrapesJS(); + }); + + afterEach(function () { + delete obj; + }); + + it('main object should be loaded', function() { + obj.should.be.exist; + }); + + it('Init new editor', function() { + var editor = obj.init(); + editor.should.not.be.empty; + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/test/specs/plugin_manager/main.js b/test/specs/plugin_manager/main.js index 900930d82..8a1bebe57 100644 --- a/test/specs/plugin_manager/main.js +++ b/test/specs/plugin_manager/main.js @@ -33,6 +33,13 @@ define(['PluginManager'], function(PluginManager) { obj.get('test').should.not.be.empty; }); + it('Added plugin is working', function() { + obj.add('test', testPlugin); + var plugin = obj.get('test'); + plugin('tval'); + val.should.equal('tval'); + }); + }); });