Parcourir la source

Cleanup: methods order in classes, let -> const.

Szymon Cofalik il y a 9 ans
Parent
commit
a72c93d0ea

+ 9 - 9
packages/ckeditor5-engine/src/treemodel/delta/attributedelta.js

@@ -20,15 +20,6 @@ import Element from '../element.js';
  * @extends core.treeModel.delta.Delta
  */
 export default class AttributeDelta extends Delta {
-	/**
-	 * @see core.treeModel.delta.Delta#_reverseDeltaClass
-	 * @private
-	 * @type {Object}
-	 */
-	get _reverseDeltaClass() {
-		return AttributeDelta;
-	}
-
 	/**
 	 * The attribute key that is changed by the delta or `null` if the delta has no operations.
 	 *
@@ -70,6 +61,15 @@ export default class AttributeDelta extends Delta {
 
 		return null;
 	}
+
+	/**
+	 * @see core.treeModel.delta.Delta#_reverseDeltaClass
+	 * @private
+	 * @type {Object}
+	 */
+	get _reverseDeltaClass() {
+		return AttributeDelta;
+	}
 }
 
 /**

+ 18 - 18
packages/ckeditor5-engine/src/treemodel/delta/insertdelta.js

@@ -18,6 +18,24 @@ import InsertOperation from '../operation/insertoperation.js';
  * @memberOf core.treeModel.delta
  */
 export default class InsertDelta extends Delta {
+	/**
+	 * Position where the delta inserts nodes or `null` if there are no operations in the delta.
+	 *
+	 * @type {core.treeModel.Position|null}
+	 */
+	get position() {
+		return this._insertOperation ? this._insertOperation.position : null;
+	}
+
+	/**
+	 * Node list containing all the nodes inserted by the delta or `null` if there are no operations in the delta.
+	 *
+	 * @type {core.treeModel.NodeList|null}
+	 */
+	get nodeList() {
+		return this._insertOperation ? this._insertOperation.nodeList : null;
+	}
+
 	/**
 	 * Insert operation that is saved in this delta or `null` if there are no operations in the delta.
 	 *
@@ -36,24 +54,6 @@ export default class InsertDelta extends Delta {
 	get _reverseDeltaClass() {
 		return RemoveDelta;
 	}
-
-	/**
-	 * Position where the delta inserts nodes or `null` if there are no operations in the delta.
-	 *
-	 * @type {core.treeModel.Position|null}
-	 */
-	get position() {
-		return this._insertOperation ? this._insertOperation.position : null;
-	}
-
-	/**
-	 * Node list containing all the nodes inserted by the delta or `null` if there are no operations in the delta.
-	 *
-	 * @type {core.treeModel.NodeList|null}
-	 */
-	get nodeList() {
-		return this._insertOperation ? this._insertOperation.nodeList : null;
-	}
 }
 
 /**

+ 9 - 9
packages/ckeditor5-engine/src/treemodel/delta/mergedelta.js

@@ -22,6 +22,15 @@ import CKEditorError from '../../ckeditorerror.js';
  * @memberOf core.treeModel.delta
  */
 export default class MergeDelta extends Delta {
+	/**
+	 * Position between to merged nodes or `null` if the delta has no operations.
+	 *
+	 * @type {core.treeModel.Position|null}
+	 */
+	get position() {
+		return this._removeOperation ? this._removeOperation.sourcePosition : null;
+	}
+
 	/**
 	 * Operation in this delta that removes the node after merge position (which will be empty at that point) or
 	 * `null` if the delta has no operations. Note, that after {@link core.treeModel.delta.transform transformation}
@@ -43,15 +52,6 @@ export default class MergeDelta extends Delta {
 	get _reverseDeltaClass() {
 		return SplitDelta;
 	}
-
-	/**
-	 * Position between to merged nodes or `null` if the delta has no operations.
-	 *
-	 * @type {core.treeModel.Position|null}
-	 */
-	get position() {
-		return this._removeOperation ? this._removeOperation.sourcePosition : null;
-	}
 }
 
 /**

+ 23 - 23
packages/ckeditor5-engine/src/treemodel/delta/movedelta.js

@@ -21,22 +21,12 @@ import CKEditorError from '../../ckeditorerror.js';
  */
 export default class MoveDelta extends Delta {
 	/**
-	 * Move operation that is saved in this delta or `null` if there are no operations in the delta.
+	 * How many nodes are moved by the delta or `null` if there are no operations in the delta.
 	 *
-	 * @protected
-	 * @type {core.treeModel.operation.MoveOperation|null}
-	 */
-	get _moveOperation() {
-		return this.operations[ 0 ] || null;
-	}
-
-	/**
-	 * @see core.treeModel.delta.Delta#_reverseDeltaClass
-	 * @private
-	 * @type {Object}
+	 * @type {Number|null}
 	 */
-	get _reverseDeltaClass() {
-		return MoveDelta;
+	get howMany() {
+		return this._moveOperation ? this._moveOperation.howMany : null;
 	}
 
 	/**
@@ -50,15 +40,6 @@ export default class MoveDelta extends Delta {
 		return this._moveOperation ? this._moveOperation.sourcePosition : null;
 	}
 
-	/**
-	 * How many nodes are moved by the delta or `null` if there are no operations in the delta.
-	 *
-	 * @type {Number|null}
-	 */
-	get howMany() {
-		return this._moveOperation ? this._moveOperation.howMany : null;
-	}
-
 	/**
 	 * {@link core.treeModel.delta.MoveDelta#_moveOperation Move operation}
 	 * {@link core.treeModel.operation.MoveOperation#targetPosition target position} or `null` if there are
@@ -69,6 +50,25 @@ export default class MoveDelta extends Delta {
 	get targetPosition() {
 		return this._moveOperation ? this._moveOperation.targetPosition : null;
 	}
+
+	/**
+	 * Move operation that is saved in this delta or `null` if there are no operations in the delta.
+	 *
+	 * @protected
+	 * @type {core.treeModel.operation.MoveOperation|null}
+	 */
+	get _moveOperation() {
+		return this.operations[ 0 ] || null;
+	}
+
+	/**
+	 * @see core.treeModel.delta.Delta#_reverseDeltaClass
+	 * @private
+	 * @type {Object}
+	 */
+	get _reverseDeltaClass() {
+		return MoveDelta;
+	}
 }
 
 function addMoveOperation( batch, delta, sourcePosition, howMany, targetPosition ) {

+ 9 - 9
packages/ckeditor5-engine/src/treemodel/delta/splitdelta.js

@@ -22,6 +22,15 @@ import MergeDelta from '../delta/mergedelta.js';
  * @memberOf core.treeModel.delta
  */
 export default class SplitDelta extends Delta {
+	/**
+	 * Position of split or `null` if there are no operations in the delta.
+	 *
+	 * @type {core.treeModel.Position|null}
+	 */
+	get position() {
+		return this._moveOperation ? this._moveOperation.sourcePosition : null;
+	}
+
 	/**
 	 * Operation in the delta that adds a node to the tree model where split elements will be moved to or `null` if
 	 * there are no operations in the delta.
@@ -56,15 +65,6 @@ export default class SplitDelta extends Delta {
 	get _reverseDeltaClass() {
 		return MergeDelta;
 	}
-
-	/**
-	 * Position of split or `null` if there are no operations in the delta.
-	 *
-	 * @type {core.treeModel.Position|null}
-	 */
-	get position() {
-		return this._moveOperation ? this._moveOperation.sourcePosition : null;
-	}
 }
 
 /**

+ 41 - 42
packages/ckeditor5-engine/src/treemodel/delta/transform.js

@@ -89,7 +89,7 @@ export default function transform( a, b, isAMoreImportantThanB ) {
 	let casesA = specialCases.get( a.constructor );
 
 	if ( !casesA ) {
-		let cases = specialCases.keys();
+		const cases = specialCases.keys();
 
 		for ( let caseClass of cases ) {
 			if ( a instanceof caseClass ) {
@@ -99,12 +99,11 @@ export default function transform( a, b, isAMoreImportantThanB ) {
 	}
 
 	if ( casesA ) {
-		let caseB = casesA.get( b.constructor );
-		transformAlgorithm = caseB || transformAlgorithm;
+		transformAlgorithm = casesA.get( b.constructor ) || transformAlgorithm;
 	}
 
-	let transformed = transformAlgorithm( a, b, isAMoreImportantThanB );
-	let baseVersion = arrayUtils.last( b.operations ).baseVersion;
+	const transformed = transformAlgorithm( a, b, isAMoreImportantThanB );
+	const baseVersion = arrayUtils.last( b.operations ).baseVersion;
 
 	return updateBaseVersion( baseVersion, transformed );
 }
@@ -143,14 +142,14 @@ export function defaultTransform( a, b, isAMoreImportantThanB ) {
 	for ( let opA of a.operations ) {
 		// We wrap the operation in the array. This is important, because operation transformation algorithm returns
 		// an array of operations so we need to make sure that our algorithm is ready to handle arrays.
-		let ops = [ opA ];
+		const ops = [ opA ];
 
 		// Now the real algorithm takes place.
 		for ( let opB of byOps ) {
 			// For each operation that we need transform by...
 			for ( let i = 0; i < ops.length; i++ ) {
 				// We take each operation to transform...
-				let op = ops[ i ];
+				const op = ops[ i ];
 
 				// And transform both of them by themselves.
 
@@ -171,7 +170,7 @@ export function defaultTransform( a, b, isAMoreImportantThanB ) {
 				Array.prototype.push.apply( newByOps, OT( opB, op, !isAMoreImportantThanB ) );
 
 				// Then, we transform operation from delta A by operation from delta B.
-				let results = OT( op, opB, isAMoreImportantThanB );
+				const results = OT( op, opB, isAMoreImportantThanB );
 
 				// We replace currently processed operation from `ops` array by the results of transformation.
 				// Note, that we process single operation but the OT result might be an array, so we might
@@ -232,7 +231,7 @@ export function addSpecialCase( A, B, resolver ) {
 addSpecialCase( AttributeDelta, WeakInsertDelta, ( a, b, isStrong ) => {
 	// If nodes are weak-inserted into attribute delta range, we need to apply changes from attribute delta on them.
 	// So first we do the normal transformation and if this special cases happens, we will add an extra delta.
-	let deltas = defaultTransform( a, b, isStrong );
+	const deltas = defaultTransform( a, b, isStrong );
 
 	if ( a.range.containsPosition( b.position ) ) {
 		deltas.push( _getComplementaryAttrDelta( b, a ) );
@@ -262,8 +261,8 @@ addSpecialCase( MoveDelta, MergeDelta, ( a, b, isStrong ) => {
 	// didn't happen) and then apply the original move operation. This is "mirrored" in MergeDelta x MoveDelta
 	// transformation below, where we simply do not apply MergeDelta.
 
-	let operateInSameParent = utils.compareArrays( a.sourcePosition.getParentPath(), b.position.getParentPath() ) === 'SAME';
-	let mergeInsideMoveRange = a.sourcePosition.offset <= b.position.offset && a.sourcePosition.offset + a.howMany > b.position.offset;
+	const operateInSameParent = utils.compareArrays( a.sourcePosition.getParentPath(), b.position.getParentPath() ) === 'SAME';
+	const mergeInsideMoveRange = a.sourcePosition.offset <= b.position.offset && a.sourcePosition.offset + a.howMany > b.position.offset;
 
 	if ( operateInSameParent && mergeInsideMoveRange ) {
 		return [
@@ -293,8 +292,8 @@ addSpecialCase( MergeDelta, MoveDelta, ( a, b, isStrong ) => {
 	// If merge is applied at the position between moved nodes we cancel the merge as it's results may be unexpected and
 	// very weird. Even if we do some "magic" we don't know what really are users' expectations.
 
-	let operateInSameParent = utils.compareArrays( a.position.getParentPath(), b.sourcePosition.getParentPath() ) === 'SAME';
-	let mergeInsideMoveRange = b.sourcePosition.offset <= a.position.offset && b.sourcePosition.offset + b.howMany > a.position.offset;
+	const operateInSameParent = utils.compareArrays( a.position.getParentPath(), b.sourcePosition.getParentPath() ) === 'SAME';
+	const mergeInsideMoveRange = b.sourcePosition.offset <= a.position.offset && b.sourcePosition.offset + b.howMany > a.position.offset;
 
 	if ( operateInSameParent && mergeInsideMoveRange ) {
 		// This is "no-op" delta, it has no type and no operations, it basically does nothing.
@@ -307,8 +306,8 @@ addSpecialCase( MergeDelta, MoveDelta, ( a, b, isStrong ) => {
 
 // Add special case for SplitDelta x SplitDelta transformation.
 addSpecialCase( SplitDelta, SplitDelta, ( a, b, isStrong ) => {
-	let pathA = a.position.getParentPath();
-	let pathB = b.position.getParentPath();
+	const pathA = a.position.getParentPath();
+	const pathB = b.position.getParentPath();
 
 	// The special case is for splits inside the same parent.
 	if ( utils.compareArrays( pathA, pathB ) == 'SAME' ) {
@@ -320,7 +319,7 @@ addSpecialCase( SplitDelta, SplitDelta, ( a, b, isStrong ) => {
 			// but since it was already split (at further offset) there are less child nodes in the split node.
 			// This means that we have to update `howMany` parameter of `MoveOperation` for that delta.
 
-			let delta = a.clone();
+			const delta = a.clone();
 			delta._moveOperation.howMany = b.position.offset - a.position.offset;
 
 			return [ delta ];
@@ -329,7 +328,7 @@ addSpecialCase( SplitDelta, SplitDelta, ( a, b, isStrong ) => {
 			// original split node but the node after it, which got created by the other split delta.
 			// To do so, we increment offsets so it looks like the split delta was created in the next node.
 
-			let delta = a.clone();
+			const delta = a.clone();
 
 			delta._cloneOperation.position.offset++;
 			delta._moveOperation.sourcePosition.path[ delta._moveOperation.sourcePosition.path.length - 2 ]++;
@@ -361,8 +360,8 @@ addSpecialCase( SplitDelta, WrapDelta, ( a, b, isStrong ) => {
 	// If split is applied at the position between wrapped nodes, we cancel the split as it's results may be unexpected and
 	// very weird. Even if we do some "magic" we don't know what really are users' expectations.
 
-	let operateInSameParent = utils.compareArrays( a.position.getParentPath(), b.range.start.getParentPath() ) === 'SAME';
-	let splitInsideWrapRange = b.range.start.offset < a.position.offset && b.range.end.offset >= a.position.offset;
+	const operateInSameParent = utils.compareArrays( a.position.getParentPath(), b.range.start.getParentPath() ) === 'SAME';
+	const splitInsideWrapRange = b.range.start.offset < a.position.offset && b.range.end.offset >= a.position.offset;
 
 	if ( operateInSameParent && splitInsideWrapRange ) {
 		// This is "no-op" delta, it has no type and no operations, it basically does nothing.
@@ -387,13 +386,26 @@ addSpecialCase( UnwrapDelta, SplitDelta, ( a, b, isStrong ) => {
 	return defaultTransform( a, b, isStrong );
 } );
 
+// Add special case for WeakInsertDelta x AttributeDelta transformation.
+addSpecialCase( WeakInsertDelta, AttributeDelta, ( a, b, isStrong ) => {
+	// If nodes are weak-inserted into attribute delta range, we need to apply changes from attribute delta on them.
+	// So first we do the normal transformation and if this special cases happens, we will add an extra delta.
+	const deltas = defaultTransform( a, b, isStrong );
+
+	if ( b.range.containsPosition( a.position ) ) {
+		deltas.push( _getComplementaryAttrDelta( a, b ) );
+	}
+
+	return deltas;
+} );
+
 // Add special case for WrapDelta x SplitDelta transformation.
 addSpecialCase( WrapDelta, SplitDelta, ( a, b, isStrong ) => {
 	// If incoming wrap delta tries to wrap range that contains split position, we have to cancel the split and apply
 	// the wrap. Since split was already applied, we have to revert it.
 
-	let operateInSameParent = utils.compareArrays( a.range.start.getParentPath(), b.position.getParentPath() ) === 'SAME';
-	let splitInsideWrapRange = a.range.start.offset < b.position.offset && a.range.end.offset >= b.position.offset;
+	const operateInSameParent = utils.compareArrays( a.range.start.getParentPath(), b.position.getParentPath() ) === 'SAME';
+	const splitInsideWrapRange = a.range.start.offset < b.position.offset && a.range.end.offset >= b.position.offset;
 
 	if ( operateInSameParent && splitInsideWrapRange ) {
 		return [
@@ -405,22 +417,9 @@ addSpecialCase( WrapDelta, SplitDelta, ( a, b, isStrong ) => {
 	return defaultTransform( a, b, isStrong );
 } );
 
-// Add special case for WeakInsertDelta x AttributeDelta transformation.
-addSpecialCase( WeakInsertDelta, AttributeDelta, ( a, b, isStrong ) => {
-	// If nodes are weak-inserted into attribute delta range, we need to apply changes from attribute delta on them.
-	// So first we do the normal transformation and if this special cases happens, we will add an extra delta.
-	let deltas = defaultTransform( a, b, isStrong );
-
-	if ( b.range.containsPosition( a.position ) ) {
-		deltas.push( _getComplementaryAttrDelta( a, b ) );
-	}
-
-	return deltas;
-} );
-
 // Creates an attribute delta that sets attribute from given `attributeDelta` on nodes from given `weakInsertDelta`.
 function _getComplementaryAttrDelta( weakInsertDelta, attributeDelta ) {
-	let complementaryAttrDelta = new AttributeDelta();
+	const complementaryAttrDelta = new AttributeDelta();
 
 	// At the beginning we store the attribute value from the first node on `weakInsertDelta` node list.
 	let val = weakInsertDelta.nodeList.get( 0 ).getAttribute( attributeDelta.key );
@@ -430,8 +429,8 @@ function _getComplementaryAttrDelta( weakInsertDelta, attributeDelta ) {
 	let lastIndex = 0;
 
 	for ( let i = 0; i < weakInsertDelta.nodeList.length; i++ ) {
-		let node = weakInsertDelta.nodeList.get( i );
-		let nodeAttrVal = node.getAttribute( attributeDelta.key );
+		const node = weakInsertDelta.nodeList.get( i );
+		const nodeAttrVal = node.getAttribute( attributeDelta.key );
 
 		// If previous node has different attribute value, we will create an operation to the point before current node.
 		// So all nodes with the same attributes up to this point will be included in one `AttributeOperation`.
@@ -439,10 +438,10 @@ function _getComplementaryAttrDelta( weakInsertDelta, attributeDelta ) {
 			// New operation is created only when it is needed. If given node already has proper value for this
 			// attribute we simply skip it without adding a new operation.
 			if ( val != attributeDelta.value ) {
-				let range = new Range( weakInsertDelta.position.getShiftedBy( lastIndex ), weakInsertDelta.position.getShiftedBy( i ) );
+				const range = new Range( weakInsertDelta.position.getShiftedBy( lastIndex ), weakInsertDelta.position.getShiftedBy( i ) );
 
 				// We don't care about base version because it will be updated after transformations anyway.
-				let attrOperation = new AttributeOperation( range, attributeDelta.key, val, attributeDelta.value, 0 );
+				const attrOperation = new AttributeOperation( range, attributeDelta.key, val, attributeDelta.value, 0 );
 				complementaryAttrDelta.addOperation( attrOperation );
 			}
 
@@ -453,7 +452,7 @@ function _getComplementaryAttrDelta( weakInsertDelta, attributeDelta ) {
 
 	// At the end we have to add additional `AttributeOperation` for the last part of node list. If all nodes on the
 	// node list had same attributes, this will be the only operation added to the delta.
-	let range = new Range(
+	const range = new Range(
 		weakInsertDelta.position.getShiftedBy( lastIndex ),
 		weakInsertDelta.position.getShiftedBy( weakInsertDelta.nodeList.length )
 	);
@@ -466,8 +465,8 @@ function _getComplementaryAttrDelta( weakInsertDelta, attributeDelta ) {
 // Checks priorities of passed constructors and decides which one is more important.
 // If both priorities are same, value passed in `isAMoreImportantThanB` parameter is used.
 function getPriority( A, B, isAMoreImportantThanB ) {
-	let aPriority = priorities.get( A );
-	let bPriority = priorities.get( B );
+	const aPriority = priorities.get( A );
+	const bPriority = priorities.get( B );
 
 	if ( aPriority > bPriority ) {
 		return true;

+ 9 - 9
packages/ckeditor5-engine/src/treemodel/delta/unwrapdelta.js

@@ -21,6 +21,15 @@ import CKEditorError from '../../ckeditorerror.js';
  * @memberOf core.treeModel.delta
  */
 export default class UnwrapDelta extends Delta {
+	/**
+	 * Position before unwrapped element or `null` if there are no operations in the delta.
+	 *
+	 * @type {core.treeModel.Position|null}
+	 */
+	get position() {
+		return this._moveOperation ? this._moveOperation.targetPosition : null;
+	}
+
 	/**
 	 * Operation in the delta that moves unwrapped nodes to their new parent or `null` if there are no operations in the delta.
 	 *
@@ -39,15 +48,6 @@ export default class UnwrapDelta extends Delta {
 	get _reverseDeltaClass() {
 		return WrapDelta;
 	}
-
-	/**
-	 * Position before unwrapped element or `null` if there are no operations in the delta.
-	 *
-	 * @type {core.treeModel.Position|null}
-	 */
-	get position() {
-		return this._moveOperation ? this._moveOperation.targetPosition : null;
-	}
 }
 
 /**

+ 11 - 11
packages/ckeditor5-engine/src/treemodel/delta/wrapdelta.js

@@ -23,6 +23,17 @@ import CKEditorError from '../../ckeditorerror.js';
  * @memberOf core.treeModel.delta
  */
 export default class WrapDelta extends Delta {
+	/**
+	 * Range to wrap or `null` if there are no operations in the delta.
+	 *
+	 * @type {core.treeModel.Range|null}
+	 */
+	get range() {
+		let moveOp = this._moveOperation;
+
+		return moveOp ? Range.createFromPositionAndShift( moveOp.sourcePosition, moveOp.howMany ) : null;
+	}
+
 	/**
 	 * Operation that moves wrapped nodes to their new parent or `null` if there are no operations in the delta.
 	 *
@@ -41,17 +52,6 @@ export default class WrapDelta extends Delta {
 	get _reverseDeltaClass() {
 		return UnwrapDelta;
 	}
-
-	/**
-	 * Range to wrap or `null` if there are no operations in the delta.
-	 *
-	 * @type {core.treeModel.Range|null}
-	 */
-	get range() {
-		let moveOp = this._moveOperation;
-
-		return moveOp ? Range.createFromPositionAndShift( moveOp.sourcePosition, moveOp.howMany ) : null;
-	}
 }
 
 /**