Browse Source

Update Plugin Manager

pull/36/head
Artur Arseniev 10 years ago
parent
commit
0f97c4fa01
  1. 2
      src/config/require-config.js
  2. 13
      src/editor/model/Editor.js
  3. 16
      src/grapesjs/main.js
  4. 3
      src/plugin_manager/main.js
  5. 1
      test/runner/main.js
  6. 31
      test/specs/grapesjs/main.js
  7. 7
      test/specs/plugin_manager/main.js

2
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', },

13
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();

16
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;
},

3
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;
},

1
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',

31
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;
});
});
});
});

7
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');
});
});
});

Loading…
Cancel
Save