Merge pull request #238 from codex-team/improvements

Improvements
This commit is contained in:
khaydarov 2017-12-23 23:00:14 +03:00 committed by GitHub
commit c84e4e6191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 174 additions and 157 deletions

View file

@ -95,7 +95,10 @@ var Module = function () {
*
* @param {EditorConfig} config
*/
function Module(config) {
function Module() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
config = _ref.config;
_classCallCheck(this, Module);
if (new.target === Module) {
@ -470,8 +473,10 @@ module.exports = exports['default'];
/**
* @typedef {Object} EditorConfig
* @property {String} holderId - Element to append Editor
* @property {Array} data - Blocks list in JSON-format
* ...
* @property {String} initialBlock - Tool name which will be initial
* @property {Object} tools - list of tools. The object value must be function (constructor) so that CodexEditor could make an instance
* @property {@link Tools#ToolsConfig} toolsConfig - tools configuration
* @property {Array} data - Blocks list in JSON-format
*/
@ -855,12 +860,13 @@ webpackContext.id = 4;
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(_) {
/* WEBPACK VAR INJECTION */(function(Module, _) {
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* @class BlockManager
* @classdesc Manage editor`s blocks storage and appearance
*/
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _block = __webpack_require__(6);
@ -870,28 +876,34 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var BlockManager = function () {
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @class BlockManager
* @classdesc Manage editor`s blocks storage and appearance
*
* @module BlockManager
*/
var BlockManager = function (_Module) {
_inherits(BlockManager, _Module);
/**
* @constructor
*
* @param {EditorConfig} config
*/
function BlockManager(_ref) {
var config = _ref.config;
function BlockManager(config) {
_classCallCheck(this, BlockManager);
this.config = config;
this.Editor = null;
/**
* Proxy for Blocks instance {@link Blocks}
*
* @type {Proxy}
* @private
*/
this._blocks = null;
var _this = _possibleConstructorReturn(this, (BlockManager.__proto__ || Object.getPrototypeOf(BlockManager)).call(this, config));
_this._blocks = null;
/**
* Index of current working block
@ -899,32 +911,27 @@ var BlockManager = function () {
* @type {number}
* @private
*/
this.currentBlockIndex = -1;
_this.currentBlockIndex = -1;
return _this;
}
/**
* Editor modules setting
* Should be called after Editor.UI preparation
* Define this._blocks property
*
* @param Editor
* @returns {Promise}
*/
_createClass(BlockManager, [{
key: 'prepare',
/**
* Should be called after Editor.UI preparation
* Define this._blocks property
*
* @returns {Promise}
*/
value: function prepare() {
var _this = this;
var _this2 = this;
return new Promise(function (resolve) {
var blocks = new Blocks(_this.Editor.UI.nodes.redactor);
var blocks = new Blocks(_this2.Editor.UI.nodes.redactor);
/**
* We need to use Proxy to overload set/get [] operator.
@ -940,7 +947,7 @@ var BlockManager = function () {
* @type {Proxy}
* @private
*/
_this._blocks = new Proxy(blocks, {
_this2._blocks = new Proxy(blocks, {
set: Blocks.set,
get: Blocks.get
});
@ -1011,12 +1018,6 @@ var BlockManager = function () {
* @return {Block}
*/
}, {
key: 'state',
set: function set(Editor) {
this.Editor = Editor;
}
}, {
key: 'currentBlock',
get: function get() {
@ -1067,7 +1068,7 @@ var BlockManager = function () {
}]);
return BlockManager;
}();
}(Module);
/**
* @class Blocks
@ -1081,6 +1082,7 @@ var BlockManager = function () {
BlockManager.displayName = 'BlockManager';
exports.default = BlockManager;
var Blocks = function () {
@ -1300,10 +1302,8 @@ var Blocks = function () {
}();
Blocks.displayName = 'Blocks';
module.exports = BlockManager;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
module.exports = exports['default'];
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0), __webpack_require__(1)))
/***/ }),
/* 6 */
@ -1430,10 +1430,10 @@ var Events = function (_Module) {
/**
* @constructor
*/
function Events() {
function Events(config) {
_classCallCheck(this, Events);
var _this = _possibleConstructorReturn(this, (Events.__proto__ || Object.getPrototypeOf(Events)).call(this));
var _this = _possibleConstructorReturn(this, (Events.__proto__ || Object.getPrototypeOf(Events)).call(this, config));
_this.subscribers = {};
@ -1478,13 +1478,13 @@ var Events = function (_Module) {
/**
* Destroyer
* clears subsribers list
*/
}, {
key: "destroy",
value: function destroy() {
this.Editor = null;
this.subscribers = null;
}
}]);
@ -1502,52 +1502,77 @@ module.exports = exports["default"];
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(_) {
/* WEBPACK VAR INJECTION */(function(Module, _) {
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**
* Codex Editor Renderer Module
*
* @author Codex Team
* @module Renderer
* @author CodeX Team
*
* @version 2.0.0
*/
var Renderer = function () {
var Renderer = function (_Module) {
_inherits(Renderer, _Module);
/**
* @constructor
*
* @param {EditorConfig} config
*/
function Renderer(config) {
_classCallCheck(this, Renderer);
this.config = config;
this.Editor = null;
return _possibleConstructorReturn(this, (Renderer.__proto__ || Object.getPrototypeOf(Renderer)).call(this, config));
}
/**
* Editor modules setter
* @typedef {Object} RendererItems
* @property {String} type - tool name
* @property {Object} data - tool data
*/
/**
* @example
*
* @param {Object} Editor
* items: [
* {
* type : 'paragraph',
* data : {
* text : 'Hello from Codex!'
* }
* },
* {
* type : 'paragraph',
* data : {
* text : 'Leave feedback if you like it!'
* }
* },
* ]
*
*/
/**
* Make plugin blocks from array of plugin`s data
* @param {RendererItems[]} items
*/
_createClass(Renderer, [{
key: "render",
/**
*
* Make plugin blocks from array of plugin`s data
*
* @param {Object[]} items
*/
value: function render(items) {
var _this = this;
var _this2 = this;
var chainData = [];
@ -1555,7 +1580,7 @@ var Renderer = function () {
chainData.push({
function: function _function() {
return _this.insertBlock(items[i]);
return _this2.insertBlock(items[i]);
}
});
};
@ -1588,21 +1613,10 @@ var Renderer = function () {
return Promise.resolve();
}
}, {
key: "state",
set: function set(Editor) {
this.Editor = Editor;
}
}]);
return Renderer;
}();
Renderer.displayName = "Renderer";
module.exports = Renderer;
}(Module);
// module.exports = (function (renderer) {
//
@ -1800,7 +1814,12 @@ module.exports = Renderer;
// return renderer;
//
// })({});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
Renderer.displayName = "Renderer";
exports.default = Renderer;
module.exports = exports["default"];
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0), __webpack_require__(1)))
/***/ }),
/* 9 */
@ -2421,21 +2440,13 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
* @property {String} iconClassname - this a icon in toolbar
* @property {Boolean} displayInToolbox - will be displayed in toolbox. Default value is TRUE
* @property {Boolean} enableLineBreaks - inserts new block or break lines. Default value is FALSE
* @property render @todo add description
* @property save @todo add description
* @property settings @todo add description
* @property validate - method that validates output data before saving
*/
/**
* @todo update according to current API
*
* @typedef {Object} Tool
* @property render
* @property save
* @property settings
* @property validate
*/
/**
* Class properties:
*
* @typedef {Tool} Tool
* @property {String} name - name of this module
* @property {Object[]} toolInstances - list of tool instances
@ -2497,9 +2508,7 @@ var Tools = function (_Module) {
}]);
function Tools(_ref) {
var config = _ref.config;
function Tools(config) {
_classCallCheck(this, Tools);
var _this = _possibleConstructorReturn(this, (Tools.__proto__ || Object.getPrototypeOf(Tools)).call(this, config));
@ -2637,6 +2646,11 @@ var Tools = function (_Module) {
var plugin = this.toolClasses[tool],
config = this.config.toolsConfig[tool];
if (!config) {
config = this.defaultConfig;
}
var instance = new plugin(data, config);
return instance;
@ -2735,9 +2749,7 @@ var UI = function (_Module) {
*
* @param {EditorConfig} config
*/
function UI(_ref) {
var config = _ref.config;
function UI(config) {
_classCallCheck(this, UI);
var _this = _possibleConstructorReturn(this, (UI.__proto__ || Object.getPrototypeOf(UI)).call(this, config));

File diff suppressed because one or more lines are too long

View file

@ -46,8 +46,10 @@
/**
* @typedef {Object} EditorConfig
* @property {String} holderId - Element to append Editor
* @property {Array} data - Blocks list in JSON-format
* ...
* @property {String} initialBlock - Tool name which will be initial
* @property {Object} tools - list of tools. The object value must be function (constructor) so that CodexEditor could make an instance
* @property {@link Tools#ToolsConfig} toolsConfig - tools configuration
* @property {Array} data - Blocks list in JSON-format
*/
'use strict';

View file

@ -14,7 +14,7 @@ export default class Module {
*
* @param {EditorConfig} config
*/
constructor(config) {
constructor({ config } = {}) {
if (new.target === Module) {

View file

@ -1,21 +1,21 @@
/**
* @class BlockManager
* @classdesc Manage editor`s blocks storage and appearance
*
* @module BlockManager
*/
import Block from '../block';
class BlockManager {
export default class BlockManager extends Module {
/**
* @constructor
*
* @param {EditorConfig} config
*/
constructor({ config }) {
constructor(config) {
this.config = config;
this.Editor = null;
super(config);
/**
* Proxy for Blocks instance {@link Blocks}
@ -35,17 +35,6 @@ class BlockManager {
}
/**
* Editor modules setting
*
* @param Editor
*/
set state(Editor) {
this.Editor = Editor;
}
/**
* Should be called after Editor.UI preparation
* Define this._blocks property
@ -392,6 +381,4 @@ class Blocks {
}
}
module.exports = BlockManager;
}

View file

@ -15,10 +15,9 @@ export default class Events extends Module {
/**
* @constructor
*/
constructor() {
super();
constructor(config) {
super(config);
this.subscribers = {};
}
@ -58,10 +57,10 @@ export default class Events extends Module {
/**
* Destroyer
* clears subsribers list
*/
destroy() {
this.Editor = null;
this.subscribers = null;
}

View file

@ -1,40 +1,52 @@
/**
* Codex Editor Renderer Module
*
* @author Codex Team
* @module Renderer
* @author CodeX Team
*
* @version 2.0.0
*/
class Renderer {
export default class Renderer extends Module {
/**
* @constructor
*
* @param {EditorConfig} config
*/
constructor(config) {
this.config = config;
this.Editor = null;
super(config);
}
/**
* Editor modules setter
*
* @param {Object} Editor
* @typedef {Object} RendererItems
* @property {String} type - tool name
* @property {Object} data - tool data
*/
set state(Editor) {
this.Editor = Editor;
}
/**
* @example
*
* items: [
* {
* type : 'paragraph',
* data : {
* text : 'Hello from Codex!'
* }
* },
* {
* type : 'paragraph',
* data : {
* text : 'Leave feedback if you like it!'
* }
* },
* ]
*
*/
/**
* Make plugin blocks from array of plugin`s data
*
* @param {Object[]} items
* @param {RendererItems[]} items
*/
render(items) {
@ -74,8 +86,6 @@ class Renderer {
}
module.exports = Renderer;
// module.exports = (function (renderer) {
//
// let editor = codex.editor;

View file

@ -104,12 +104,21 @@ export default class Sanitizer extends Module {
/**
* Cleans string from unwanted tags
* @param {String} taintString - HTML string
*
* @param {Object} customConfig - custom sanitizer configuration. Method uses default if param is empty
* @return {String} clean HTML
*/
clean(taintString) {
clean(taintString, customConfig = {}) {
if (_.isEmpty(customConfig)) {
return this._sanitizerInstance.clean(taintString);
} else {
return Sanitizer.clean(taintString, customConfig);
}
return this._sanitizerInstance.clean(taintString);
}

View file

@ -12,21 +12,13 @@
* @property {String} iconClassname - this a icon in toolbar
* @property {Boolean} displayInToolbox - will be displayed in toolbox. Default value is TRUE
* @property {Boolean} enableLineBreaks - inserts new block or break lines. Default value is FALSE
* @property render @todo add description
* @property save @todo add description
* @property settings @todo add description
* @property validate - method that validates output data before saving
*/
/**
* @todo update according to current API
*
* @typedef {Object} Tool
* @property render
* @property save
* @property settings
* @property validate
*/
/**
* Class properties:
*
* @typedef {Tool} Tool
* @property {String} name - name of this module
* @property {Object[]} toolInstances - list of tool instances
@ -77,7 +69,7 @@ export default class Tools extends Module {
*
* @param {ToolsConfig} config
*/
constructor({ config }) {
constructor(config) {
super(config);
@ -205,6 +197,12 @@ export default class Tools extends Module {
let plugin = this.toolClasses[tool],
config = this.config.toolsConfig[tool];
if (!config) {
config = this.defaultConfig;
}
let instance = new plugin(data, config);
return instance;

View file

@ -62,7 +62,7 @@ export default class UI extends Module {
*
* @param {EditorConfig} config
*/
constructor({ config }) {
constructor(config) {
super(config);