Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit ebd9137

Browse files
committed
Marked operation utils names as protected.
1 parent 1d68fe6 commit ebd9137

File tree

6 files changed

+39
-48
lines changed

6 files changed

+39
-48
lines changed

src/model/operation/attributeoperation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Operation from './operation';
1111
import Range from '../range';
1212
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
13-
import { setAttribute } from './utils';
13+
import { _setAttribute } from './utils';
1414
import isEqual from '@ckeditor/ckeditor5-utils/src/lib/lodash/isEqual';
1515

1616
/**
@@ -151,7 +151,7 @@ export default class AttributeOperation extends Operation {
151151
// If value to set is same as old value, don't do anything.
152152
if ( !isEqual( this.oldValue, this.newValue ) ) {
153153
// Execution.
154-
setAttribute( this.range, this.key, this.newValue );
154+
_setAttribute( this.range, this.key, this.newValue );
155155
}
156156

157157
return { range: this.range, key: this.key, oldValue: this.oldValue, newValue: this.newValue };

src/model/operation/detachoperation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Operation from './operation';
1111
import Position from '../position';
1212
import Range from '../range';
13-
import { remove } from './utils';
13+
import { _remove } from './utils';
1414
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
1515

1616
/**
@@ -73,7 +73,7 @@ export default class DetachOperation extends Operation {
7373
throw new CKEditorError( 'detach-operation-on-document-node: Cannot detach document node.' );
7474
}
7575

76-
const nodes = remove( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ) );
76+
const nodes = _remove( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ) );
7777

7878
return { nodes };
7979
}

src/model/operation/insertoperation.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Operation from './operation';
1111
import Position from '../position';
1212
import NodeList from '../nodelist';
1313
import RemoveOperation from './removeoperation';
14-
import { insert, normalizeNodes } from './utils';
14+
import { _insert, _normalizeNodes } from './utils';
1515
import Text from '../text';
1616
import Element from '../element';
1717

@@ -45,7 +45,7 @@ export default class InsertOperation extends Operation {
4545
* @readonly
4646
* @member {module:engine/model/nodelist~NodeList} module:engine/model/operation/insertoperation~InsertOperation#nodeList
4747
*/
48-
this.nodes = new NodeList( normalizeNodes( nodes ) );
48+
this.nodes = new NodeList( _normalizeNodes( nodes ) );
4949

5050
/**
5151
* @inheritDoc
@@ -94,7 +94,7 @@ export default class InsertOperation extends Operation {
9494
const originalNodes = this.nodes;
9595
this.nodes = new NodeList( [ ...originalNodes ].map( node => node.clone( true ) ) );
9696

97-
const range = insert( this.position, originalNodes );
97+
const range = _insert( this.position, originalNodes );
9898

9999
return { range };
100100
}

src/model/operation/moveoperation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Position from '../position';
1212
import Range from '../range';
1313
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
1414
import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
15-
import { move } from './utils';
15+
import { _move } from './utils';
1616

1717
/**
1818
* Operation to move a range of {@link module:engine/model/item~Item model items}
@@ -184,7 +184,7 @@ export default class MoveOperation extends Operation {
184184
}
185185
}
186186

187-
const range = move( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ), this.targetPosition );
187+
const range = _move( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ), this.targetPosition );
188188

189189
return {
190190
sourcePosition: this.sourcePosition,

src/model/operation/utils.js

+8-17
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
2222
* @protected
2323
* @namespace utils
2424
*/
25-
const utils = {
26-
insert,
27-
remove,
28-
move,
29-
setAttribute,
30-
normalizeNodes
31-
};
32-
33-
export default utils;
3425

3526
/**
3627
* Inserts given nodes at given position.
@@ -41,8 +32,8 @@ export default utils;
4132
* @param {module:engine/model/node~NodeSet} nodes Nodes to insert.
4233
* @returns {module:engine/model/range~Range} Range spanning over inserted elements.
4334
*/
44-
export function insert( position, nodes ) {
45-
nodes = normalizeNodes( nodes );
35+
export function _insert( position, nodes ) {
36+
nodes = _normalizeNodes( nodes );
4637

4738
// We have to count offset before inserting nodes because they can get merged and we would get wrong offsets.
4839
const offset = nodes.reduce( ( sum, node ) => sum + node.offsetSize, 0 );
@@ -71,7 +62,7 @@ export function insert( position, nodes ) {
7162
* @param {module:engine/model/range~Range} range Range containing nodes to remove.
7263
* @returns {Array.<module:engine/model/node~Node>}
7364
*/
74-
export function remove( range ) {
65+
export function _remove( range ) {
7566
if ( !range.isFlat ) {
7667
/**
7768
* Trying to remove a range which starts and ends in different element.
@@ -107,7 +98,7 @@ export function remove( range ) {
10798
* @param {module:engine/model/position~Position} targetPosition Position to which nodes should be moved.
10899
* @returns {module:engine/model/range~Range} Range containing moved nodes.
109100
*/
110-
export function move( sourceRange, targetPosition ) {
101+
export function _move( sourceRange, targetPosition ) {
111102
if ( !sourceRange.isFlat ) {
112103
/**
113104
* Trying to move a range which starts and ends in different element.
@@ -118,13 +109,13 @@ export function move( sourceRange, targetPosition ) {
118109
'Trying to move a range which starts and ends in different element.' );
119110
}
120111

121-
const nodes = remove( sourceRange );
112+
const nodes = _remove( sourceRange );
122113

123114
// We have to fix `targetPosition` because model changed after nodes from `sourceRange` got removed and
124115
// that change might have an impact on `targetPosition`.
125116
targetPosition = targetPosition._getTransformedByDeletion( sourceRange.start, sourceRange.end.offset - sourceRange.start.offset );
126117

127-
return insert( targetPosition, nodes );
118+
return _insert( targetPosition, nodes );
128119
}
129120

130121
/**
@@ -136,7 +127,7 @@ export function move( sourceRange, targetPosition ) {
136127
* @param {String} key Key of attribute to set.
137128
* @param {*} value Attribute value.
138129
*/
139-
export function setAttribute( range, key, value ) {
130+
export function _setAttribute( range, key, value ) {
140131
// Range might start or end in text nodes, so we have to split them.
141132
_splitNodeAtPosition( range.start );
142133
_splitNodeAtPosition( range.end );
@@ -171,7 +162,7 @@ export function setAttribute( range, key, value ) {
171162
* @param {module:engine/model/node~NodeSet} nodes Objects to normalize.
172163
* @returns {Array.<module:engine/model/node~Node>} Normalized nodes.
173164
*/
174-
export function normalizeNodes( nodes ) {
165+
export function _normalizeNodes( nodes ) {
175166
const normalized = [];
176167

177168
if ( !( nodes instanceof Array ) ) {

tests/model/operation/utils.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Text from '../../../src/model/text';
1010
import TextProxy from '../../../src/model/textproxy';
1111
import Position from '../../../src/model/position';
1212
import Range from '../../../src/model/range';
13-
import utils from '../../../src/model/operation/utils';
13+
import * as utils from '../../../src/model/operation/utils';
1414
import { getData } from '../../../src/dev-utils/model';
1515

1616
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
@@ -38,19 +38,19 @@ describe( 'writer utils', () => {
3838

3939
describe( 'insert', () => {
4040
it( 'should insert nodes between nodes', () => {
41-
utils.insert( Position.createAt( root, 3 ), [ 'xxx', new Element( 'p' ) ] );
41+
utils._insert( Position.createAt( root, 3 ), [ 'xxx', new Element( 'p' ) ] );
4242

4343
expectData( 'fooxxx<p></p><$text bold="true">bar</$text><image src="img.jpg"></image>xyz' );
4444
} );
4545

4646
it( 'should split text node if nodes at inserted at offset inside text node', () => {
47-
utils.insert( Position.createAt( root, 5 ), new Element( 'p' ) );
47+
utils._insert( Position.createAt( root, 5 ), new Element( 'p' ) );
4848

4949
expectData( 'foo<$text bold="true">ba</$text><p></p><$text bold="true">r</$text><image src="img.jpg"></image>xyz' );
5050
} );
5151

5252
it( 'should merge text nodes if possible', () => {
53-
utils.insert( Position.createAt( root, 3 ), new Text( 'xxx', { bold: true } ) );
53+
utils._insert( Position.createAt( root, 3 ), new Text( 'xxx', { bold: true } ) );
5454

5555
expectData( 'foo<$text bold="true">xxxbar</$text><image src="img.jpg"></image>xyz' );
5656
} );
@@ -59,73 +59,73 @@ describe( 'writer utils', () => {
5959
describe( 'remove', () => {
6060
it( 'should remove nodes in given range', () => {
6161
const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
62-
utils.remove( range );
62+
utils._remove( range );
6363

6464
expectData( 'foo<image src="img.jpg"></image>xyz' );
6565
} );
6666

6767
it( 'should split text node if range starts or ends inside text node', () => {
6868
const range = Range.createFromParentsAndOffsets( root, 1, root, 5 );
69-
utils.remove( range );
69+
utils._remove( range );
7070

7171
expectData( 'f<$text bold="true">r</$text><image src="img.jpg"></image>xyz' );
7272
} );
7373

7474
it( 'should merge text nodes if possible', () => {
7575
const range = Range.createFromParentsAndOffsets( root, 3, root, 7 );
76-
utils.remove( range );
76+
utils._remove( range );
7777

7878
expectData( 'fooxyz' );
7979
expect( root.childCount ).to.equal( 1 );
8080
} );
8181

8282
it( 'should throw if given range is not flat', () => {
8383
expect( () => {
84-
utils.remove( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ) );
84+
utils._remove( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ) );
8585
} ).to.throw( CKEditorError, /operation-utils-remove-range-not-flat/ );
8686
} );
8787
} );
8888

8989
describe( 'move', () => {
9090
it( 'should move a range of nodes', () => {
9191
const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
92-
utils.move( range, Position.createAt( root, 0 ) );
92+
utils._move( range, Position.createAt( root, 0 ) );
9393

9494
expectData( '<$text bold="true">bar</$text>foo<image src="img.jpg"></image>xyz' );
9595
} );
9696

9797
it( 'should correctly move if target position is in same element as moved range, but after range', () => {
9898
const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
99-
utils.move( range, Position.createAt( root, 10 ) );
99+
utils._move( range, Position.createAt( root, 10 ) );
100100

101101
expectData( 'foo<image src="img.jpg"></image>xyz<$text bold="true">bar</$text>' );
102102
} );
103103

104104
it( 'should throw if given range is not flat', () => {
105105
expect( () => {
106-
utils.move( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ), null );
106+
utils._move( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ), null );
107107
} ).to.throw( CKEditorError, /operation-utils-move-range-not-flat/ );
108108
} );
109109
} );
110110

111111
describe( 'setAttribute', () => {
112112
it( 'should set attribute on given range of nodes', () => {
113113
const range = Range.createFromParentsAndOffsets( root, 6, root, 8 );
114-
utils.setAttribute( range, 'newAttr', true );
114+
utils._setAttribute( range, 'newAttr', true );
115115

116116
expectData( 'foo<$text bold="true">bar</$text><image newAttr="true" src="img.jpg"></image><$text newAttr="true">x</$text>yz' );
117117
} );
118118

119119
it( 'should remove attribute if null was passed as a value', () => {
120120
const range = Range.createFromParentsAndOffsets( root, 6, root, 7 );
121-
utils.setAttribute( range, 'src', null );
121+
utils._setAttribute( range, 'src', null );
122122

123123
expectData( 'foo<$text bold="true">bar</$text><image></image>xyz' );
124124
} );
125125

126126
it( 'should merge nodes if possible', () => {
127127
const range = Range.createFromParentsAndOffsets( root, 0, root, 3 );
128-
utils.setAttribute( range, 'bold', true );
128+
utils._setAttribute( range, 'bold', true );
129129

130130
expectData( '<$text bold="true">foobar</$text><image src="img.jpg"></image>xyz' );
131131
} );
@@ -136,11 +136,11 @@ describe( 'normalizeNodes', () => {
136136
it( 'should change single object into an array', () => {
137137
const p = new Element( 'p' );
138138

139-
expect( utils.normalizeNodes( p ) ).to.deep.equal( [ p ] );
139+
expect( utils._normalizeNodes( p ) ).to.deep.equal( [ p ] );
140140
} );
141141

142142
it( 'should change strings to text nodes', () => {
143-
const text = utils.normalizeNodes( 'abc' )[ 0 ];
143+
const text = utils._normalizeNodes( 'abc' )[ 0 ];
144144

145145
expect( text ).to.be.instanceof( Text );
146146
expect( text.data ).to.equal( 'abc' );
@@ -150,7 +150,7 @@ describe( 'normalizeNodes', () => {
150150
const textNode = new Text( 'abc' );
151151
const textProxy = new TextProxy( textNode, 1, 1 );
152152

153-
const text = utils.normalizeNodes( textProxy )[ 0 ];
153+
const text = utils._normalizeNodes( textProxy )[ 0 ];
154154

155155
expect( text ).to.be.instanceof( Text );
156156
expect( text.data ).to.equal( 'b' );
@@ -159,19 +159,19 @@ describe( 'normalizeNodes', () => {
159159
it( 'should not change elements', () => {
160160
const p = new Element( 'p' );
161161

162-
expect( utils.normalizeNodes( p )[ 0 ] ).to.equal( p );
162+
expect( utils._normalizeNodes( p )[ 0 ] ).to.equal( p );
163163
} );
164164

165165
it( 'should omit unrecognized objects', () => {
166-
expect( utils.normalizeNodes( 1 ) ).to.deep.equal( [] );
166+
expect( utils._normalizeNodes( 1 ) ).to.deep.equal( [] );
167167
} );
168168

169169
it( 'should accept arrays', () => {
170170
const text = new Text( 'foo', { bold: true } );
171171
const image = new Element( 'image' );
172172
const nodes = [ 'abc', text, image, 1, 'xyz' ];
173173

174-
const normalized = utils.normalizeNodes( nodes );
174+
const normalized = utils._normalizeNodes( nodes );
175175

176176
expect( normalized[ 0 ] ).to.be.instanceof( Text );
177177
expect( normalized[ 1 ] ).to.equal( text );
@@ -180,7 +180,7 @@ describe( 'normalizeNodes', () => {
180180
} );
181181

182182
it( 'should merge text nodes if mergeTextNodes flag is set to true', () => {
183-
const normalized = utils.normalizeNodes( [ 'foo', 'bar' ], true );
183+
const normalized = utils._normalizeNodes( [ 'foo', 'bar' ], true );
184184

185185
expect( normalized.length ).to.equal( 1 );
186186
expect( normalized[ 0 ].data ).to.equal( 'foobar' );
@@ -193,7 +193,7 @@ describe( 'normalizeNodes', () => {
193193
'xyz'
194194
];
195195

196-
const normalized = utils.normalizeNodes( nodes, true );
196+
const normalized = utils._normalizeNodes( nodes, true );
197197

198198
expect( normalized[ 0 ] ).to.be.instanceof( Text );
199199
expect( normalized[ 0 ].getAttribute( 'bold' ) ).to.be.true;

0 commit comments

Comments
 (0)