mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 23:55:49 +01:00
Improve behaviour
This commit is contained in:
parent
dc9a20c62a
commit
e6bbe7f14f
6 changed files with 100 additions and 40 deletions
|
|
@ -224,6 +224,14 @@ module.exports = function () {
|
|||
|
||||
return el.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is DOM node
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'isNode',
|
||||
value: function isNode(node) {
|
||||
|
|
@ -747,6 +755,23 @@ var BlockManager = function () {
|
|||
this._blocks[++this._currentBlockIndex] = block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current working block
|
||||
*
|
||||
* @param {String} toolName — plugin name
|
||||
* @param {Object} data — plugin data
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'replace',
|
||||
value: function replace(toolName, data) {
|
||||
|
||||
var toolInstance = this.Editor.Tools.construct(toolName, data),
|
||||
block = new _block2.default(toolInstance);
|
||||
|
||||
this._blocks.insert(this._currentBlockIndex, block, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Block instance by html element
|
||||
*
|
||||
|
|
@ -831,13 +856,7 @@ var BlockManager = function () {
|
|||
}]);
|
||||
|
||||
return BlockManager;
|
||||
}(); /**
|
||||
* @class BlockManager
|
||||
* @classdesc Manage editor`s blocks storage and appearance
|
||||
*/
|
||||
|
||||
BlockManager.displayName = 'BlockManager';
|
||||
;
|
||||
}();
|
||||
|
||||
/**
|
||||
* @class Blocks
|
||||
|
|
@ -848,6 +867,12 @@ BlockManager.displayName = 'BlockManager';
|
|||
* @property {HTMLElement} workingArea — editor`s working node
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @class BlockManager
|
||||
* @classdesc Manage editor`s blocks storage and appearance
|
||||
*/
|
||||
|
||||
BlockManager.displayName = 'BlockManager';
|
||||
|
||||
var Blocks = function () {
|
||||
|
||||
|
|
@ -883,11 +908,14 @@ var Blocks = function () {
|
|||
*
|
||||
* @param {Number} index — index to insert Block
|
||||
* @param {Block} block — Block to insert
|
||||
* @param {Boolean} replace — it true, replace block on given index
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'insert',
|
||||
value: function insert(index, block) {
|
||||
var replace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
||||
|
||||
|
||||
if (!this.length) {
|
||||
|
||||
|
|
@ -897,11 +925,17 @@ var Blocks = function () {
|
|||
|
||||
if (index > this.length) {
|
||||
|
||||
// @todo decide how to handle this case
|
||||
return;
|
||||
index = this.length;
|
||||
}
|
||||
|
||||
this._blocks[index] = block;
|
||||
if (replace) {
|
||||
|
||||
this._blocks[index].html.remove();
|
||||
}
|
||||
|
||||
var deleteCount = replace ? 1 : 0;
|
||||
|
||||
this._blocks.splice(index, deleteCount, block);
|
||||
|
||||
if (index > 0) {
|
||||
|
||||
|
|
@ -1062,15 +1096,21 @@ module.exports = BlockManager;
|
|||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
/* WEBPACK VAR INJECTION */(function($) {
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _dom = __webpack_require__(1);
|
||||
|
||||
var _dom2 = __webpack_require__(0).interopRequireDefault(_dom);
|
||||
/**
|
||||
*
|
||||
* @class Block
|
||||
* @classdesc This class describes editor`s block, including block`s HTMLElement, data and tool
|
||||
*
|
||||
* @property {Tool} tool — current block tool (Paragraph, for example)
|
||||
* @property {Object} CSS — block`s css classes
|
||||
*
|
||||
*/
|
||||
|
||||
var Block = function () {
|
||||
|
||||
|
|
@ -1104,8 +1144,8 @@ var Block = function () {
|
|||
key: 'compose',
|
||||
value: function compose() {
|
||||
|
||||
var wrapper = _dom2.default.make('div', this.CSS.wrapper),
|
||||
content = _dom2.default.make('div', this.CSS.content);
|
||||
var wrapper = $.make('div', this.CSS.wrapper),
|
||||
content = $.make('div', this.CSS.content);
|
||||
|
||||
content.appendChild(this.tool.html);
|
||||
wrapper.appendChild(content);
|
||||
|
|
@ -1128,18 +1168,11 @@ var Block = function () {
|
|||
}]);
|
||||
|
||||
return Block;
|
||||
}(); /**
|
||||
*
|
||||
* @class Block
|
||||
* @classdesc This class describes editor`s block, including block`s HTMLElement, data and tool
|
||||
*
|
||||
* @property {Tool} tool — current block tool (Paragraph, for example)
|
||||
* @property {Object} CSS — block`s css classes
|
||||
*
|
||||
*/
|
||||
}();
|
||||
|
||||
Block.displayName = 'Block';
|
||||
exports.default = Block;
|
||||
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
|
||||
|
||||
/***/ }),
|
||||
/* 6 */
|
||||
|
|
@ -1255,7 +1288,7 @@ module.exports = Events;
|
|||
* Codex Editor Renderer Module
|
||||
*
|
||||
* @author Codex Team
|
||||
* @version 1.0
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
var Renderer = function () {
|
||||
|
|
@ -1298,7 +1331,7 @@ var Renderer = function () {
|
|||
|
||||
chainData.push({
|
||||
function: function _function() {
|
||||
return _this.makeBlock(items[i]);
|
||||
return _this.insertBlock(items[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -1321,8 +1354,8 @@ var Renderer = function () {
|
|||
*/
|
||||
|
||||
}, {
|
||||
key: "makeBlock",
|
||||
value: function makeBlock(item) {
|
||||
key: "insertBlock",
|
||||
value: function insertBlock(item) {
|
||||
|
||||
var tool = item.type,
|
||||
data = item.data;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -9,8 +9,6 @@
|
|||
*/
|
||||
|
||||
|
||||
import $ from './dom';
|
||||
|
||||
export default class Block {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -86,6 +86,12 @@ module.exports = class Dom {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is DOM node
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static isNode(node) {
|
||||
|
||||
return node && typeof node === 'object' && node.nodeType && node.nodeType === Node.ELEMENT_NODE;
|
||||
|
|
|
|||
|
|
@ -84,6 +84,21 @@ class BlockManager {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current working block
|
||||
*
|
||||
* @param {String} toolName — plugin name
|
||||
* @param {Object} data — plugin data
|
||||
*/
|
||||
replace(toolName, data) {
|
||||
|
||||
let toolInstance = this.Editor.Tools.construct(toolName, data),
|
||||
block = new Block(toolInstance);
|
||||
|
||||
this._blocks.insert(this._currentBlockIndex, block, true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Block instance by html element
|
||||
*
|
||||
|
|
@ -153,7 +168,7 @@ class BlockManager {
|
|||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @class Blocks
|
||||
|
|
@ -195,8 +210,9 @@ class Blocks {
|
|||
*
|
||||
* @param {Number} index — index to insert Block
|
||||
* @param {Block} block — Block to insert
|
||||
* @param {Boolean} replace — it true, replace block on given index
|
||||
*/
|
||||
insert(index, block) {
|
||||
insert(index, block, replace = false) {
|
||||
|
||||
if (!this.length) {
|
||||
|
||||
|
|
@ -207,12 +223,19 @@ class Blocks {
|
|||
|
||||
if (index > this.length) {
|
||||
|
||||
// @todo decide how to handle this case
|
||||
return;
|
||||
index = this.length;
|
||||
|
||||
}
|
||||
|
||||
this._blocks[index] = block;
|
||||
if (replace) {
|
||||
|
||||
this._blocks[index].html.remove();
|
||||
|
||||
}
|
||||
|
||||
let deleteCount = replace ? 1 : 0;
|
||||
|
||||
this._blocks.splice(index, deleteCount, block);
|
||||
|
||||
if (index > 0) {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* Codex Editor Renderer Module
|
||||
*
|
||||
* @author Codex Team
|
||||
* @version 1.0
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
class Renderer {
|
||||
|
|
@ -43,7 +43,7 @@ class Renderer {
|
|||
for (let i = 0; i < items.length; i++) {
|
||||
|
||||
chainData.push({
|
||||
function: () => this.makeBlock(items[i])
|
||||
function: () => this.insertBlock(items[i])
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ class Renderer {
|
|||
* @returns {Promise.<T>}
|
||||
* @private
|
||||
*/
|
||||
makeBlock(item) {
|
||||
insertBlock(item) {
|
||||
|
||||
let tool = item.type,
|
||||
data = item.data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue