implement getters instead of functions in block cursors

This commit is contained in:
Murod Khaydarov 2017-12-29 09:44:08 +03:00
commit 8adc54cc46
5 changed files with 88 additions and 88 deletions

View file

@ -1695,7 +1695,7 @@ var BlockManager = function (_Module) {
if (_Selection2.default.getSelectionAnchorOffset() === textNodeLength) {
var nextBlock = this.NextBlock();
var nextBlock = this.nextBlock;
if (!nextBlock) return;
@ -1721,7 +1721,7 @@ var BlockManager = function (_Module) {
if (_Selection2.default.getSelectionAnchorOffset() === 0) {
var previousBlock = this.PreviousBlock();
var previousBlock = this.previousBlock;
if (!previousBlock) return;
@ -1772,63 +1772,19 @@ var BlockManager = function (_Module) {
*/
}, {
key: 'LastBlock',
value: function LastBlock() {
key: 'getBlockByIndex',
return this._blocks[this._blocks.length - 1];
}
/**
* Returns Block by passed index
* @param {Number} index
* @return {Block}
*/
}, {
key: 'getBlockByIndex',
value: function getBlockByIndex(index) {
return this._blocks[index];
}
/**
* Returns next Block instance
* @return {Block|null}
*/
}, {
key: 'NextBlock',
value: function NextBlock() {
var isLastBlock = this.currentBlockIndex === this._blocks.length - 1;
if (isLastBlock) {
return null;
}
return this._blocks[this.currentBlockIndex + 1];
}
/**
* Returns previous Block instance
* @return {Block|null}
*/
}, {
key: 'PreviousBlock',
value: function PreviousBlock() {
var isFirstBlock = this.currentBlockIndex === 0;
if (isFirstBlock) {
return null;
}
return this._blocks[this.currentBlockIndex - 1];
}
/**
* Get Block instance by html element
*
@ -1888,6 +1844,12 @@ var BlockManager = function (_Module) {
throw new Error('Can not find a Block from this child Node');
}
}
}, {
key: 'lastBlock',
get: function get() {
return this._blocks[this._blocks.length - 1];
}
}, {
key: 'currentBlock',
get: function get() {
@ -1895,6 +1857,44 @@ var BlockManager = function (_Module) {
return this._blocks[this.currentBlockIndex];
}
/**
* Returns next Block instance
* @return {Block|null}
*/
}, {
key: 'nextBlock',
get: function get() {
var isLastBlock = this.currentBlockIndex === this._blocks.length - 1;
if (isLastBlock) {
return null;
}
return this._blocks[this.currentBlockIndex + 1];
}
/**
* Returns previous Block instance
* @return {Block|null}
*/
}, {
key: 'previousBlock',
get: function get() {
var isFirstBlock = this.currentBlockIndex === 0;
if (isFirstBlock) {
return null;
}
return this._blocks[this.currentBlockIndex - 1];
}
/**
* Get working html element
*
@ -2328,7 +2328,7 @@ var Caret = function (_Module) {
*/
value: function setToTheLastBlock() {
var lastBlock = this.Editor.BlockManager.LastBlock();
var lastBlock = this.Editor.BlockManager.lastBlock;
if (!lastBlock) return;
@ -4543,7 +4543,7 @@ var UI = function (_Module) {
key: 'clickedOnRedactorZone',
value: function clickedOnRedactorZone(event) {
var lastBlock = this.Editor.BlockManager.LastBlock(),
var lastBlock = this.Editor.BlockManager.lastBlock,
pluginsContent = lastBlock.pluginsContent;
/**

File diff suppressed because one or more lines are too long

View file

@ -158,7 +158,7 @@ export default class BlockManager extends Module {
if (Selection.getSelectionAnchorOffset() === textNodeLength) {
let nextBlock = this.NextBlock();
let nextBlock = this.nextBlock;
if (!nextBlock) return;
@ -184,7 +184,7 @@ export default class BlockManager extends Module {
if (Selection.getSelectionAnchorOffset() === 0) {
let previousBlock = this.PreviousBlock();
let previousBlock = this.previousBlock;
if (!previousBlock) return;
@ -228,7 +228,7 @@ export default class BlockManager extends Module {
* returns last Block
* @return {Block}
*/
LastBlock() {
get lastBlock() {
return this._blocks[this._blocks.length - 1];
@ -245,42 +245,6 @@ export default class BlockManager extends Module {
}
/**
* Returns next Block instance
* @return {Block|null}
*/
NextBlock() {
let isLastBlock = this.currentBlockIndex === (this._blocks.length - 1);
if (isLastBlock) {
return null;
}
return this._blocks[this.currentBlockIndex + 1];
}
/**
* Returns previous Block instance
* @return {Block|null}
*/
PreviousBlock() {
let isFirstBlock = this.currentBlockIndex === 0;
if (isFirstBlock) {
return null;
}
return this._blocks[this.currentBlockIndex - 1];
}
/**
* Get Block instance by html element
*
@ -313,6 +277,42 @@ export default class BlockManager extends Module {
}
/**
* Returns next Block instance
* @return {Block|null}
*/
get nextBlock() {
let isLastBlock = this.currentBlockIndex === (this._blocks.length - 1);
if (isLastBlock) {
return null;
}
return this._blocks[this.currentBlockIndex + 1];
}
/**
* Returns previous Block instance
* @return {Block|null}
*/
get previousBlock() {
let isFirstBlock = this.currentBlockIndex === 0;
if (isFirstBlock) {
return null;
}
return this._blocks[this.currentBlockIndex - 1];
}
/**
* Get working html element
*

View file

@ -94,7 +94,7 @@ export default class Caret extends Module {
*/
setToTheLastBlock() {
let lastBlock = this.Editor.BlockManager.LastBlock();
let lastBlock = this.Editor.BlockManager.lastBlock;
if (!lastBlock) return;

View file

@ -362,7 +362,7 @@ export default class UI extends Module {
clickedOnRedactorZone(event) {
let lastBlock = this.Editor.BlockManager.LastBlock(),
let lastBlock = this.Editor.BlockManager.lastBlock,
pluginsContent = lastBlock.pluginsContent;
/**