Browse Source

Allow defining a command with just a function

pull/561/head
Artur Arseniev 8 years ago
parent
commit
df282c10cf
  1. 23
      src/commands/index.js
  2. 26
      src/editor/index.js
  3. 16
      src/storage_manager/index.js

23
src/commands/index.js

@ -38,6 +38,7 @@
* },
* ...
*/
import { isFunction } from 'underscore';
module.exports = () => {
var c = {},
@ -48,6 +49,10 @@ module.exports = () => {
// Need it here as it would be used below
var add = function(id, obj){
if (isFunction(obj)) {
obj = { run: obj };
}
delete obj.initialize;
commands[id] = AbsCommands.extend(obj);
return this;
@ -193,6 +198,14 @@ module.exports = () => {
},
};
// Core commands
defaultCommands['core:undo'] = e => e.UndoManager.undo(1);
defaultCommands['core:redo'] = e => e.UndoManager.redo(1);
defaultCommands['core:canvas-clear'] = e => {
e.DomComponents.clear();
e.CssComposer.clear();
};
if(c.em)
c.model = c.em.get('Canvas');
@ -204,16 +217,20 @@ module.exports = () => {
/**
* Add new command to the collection
* @param {string} id Command's ID
* @param {Object} command Object representing you command. Methods `run` and `stop` are required
* @param {Object|Function} command Object representing your command,
* By passing just a function it's intended as a stateless command
* (just like passing an object with only `run` method).
* @return {this}
* @example
* commands.add('myCommand', {
* run: function(editor, sender){
* run(editor, sender) {
* alert('Hello world!');
* },
* stop: function(editor, sender){
* stop(editor, sender) {
* },
* });
* // As a function
* commands.add('myCommand2', editor => { ... });
* */
add,

26
src/editor/index.js

@ -1,29 +1,4 @@
/**
*
* * [getConfig](#getconfig)
* * [getHtml](#gethtml)
* * [getCss](#getcss)
* * [getJs](#getjs)
* * [getComponents](#getcomponents)
* * [setComponents](#setcomponents)
* * [addComponents](#addcomponents)
* * [getStyle](#getstyle)
* * [setStyle](#setstyle)
* * [getSelected](#getselected)
* * [getSelectedToStyle](#getselectedtostyle)
* * [setDevice](#setdevice)
* * [getDevice](#getdevice)
* * [runCommand](#runcommand)
* * [stopCommand](#stopcommand)
* * [store](#store)
* * [load](#load)
* * [getContainer](#getcontainer)
* * [refresh](#refresh)
* * [on](#on)
* * [off](#off)
* * [trigger](#trigger)
* * [render](#render)
*
* Editor class contains the top level API which you'll probably use to custom the editor or extend it with plugins.
* You get the Editor instance on init method
*
@ -75,7 +50,6 @@
* * `canvasScroll` - Triggered when the canvas is scrolle
* * `load` - When the editor is loaded
*
* @module Editor
* @param {Object} config Configurations
* @param {string} config.container='' Selector for the editor container, eg. '#myEditor'
* @param {string|Array<Object>} [config.components=''] HTML string or object of components

16
src/storage_manager/index.js

@ -1,24 +1,9 @@
/**
* - [isAutosave](#isautosave)
* - [setAutosave](#setautosave)
* - [getStepsBeforeSave](#getstepsbeforesave)
* - [setStepsBeforeSave](#setstepsbeforesave)
* - [getStorages](#getstorages)
* - [getCurrent](#getcurrent)
* - [setCurrent](#setcurrent)
* - [add](#add)
* - [get](#get)
* - [store](#store)
* - [load](#load)
*
*
* Before using methods you should get first the module from the editor instance, in this way:
*
* ```js
* var storageManager = editor.StorageManager;
* ```
*
* @module StorageManager
*/
module.exports = () => {
var c = {},
@ -47,6 +32,7 @@ module.exports = () => {
* @param {number} [config.stepsBeforeSave=1] If autosave enabled, indicates how many steps/changes are necessary
* before autosave is triggered
* @param {string} [config.type='local'] Default storage type. Available: 'local' | 'remote' | ''(do not store)
* @private
* @example
* ...
* {

Loading…
Cancel
Save