44 */
55
66/**
7- * @module engine/model/writer
7+ * @module engine/model/operation/utils
88 */
99
10- import Node from './node' ;
11- import Text from './text' ;
12- import TextProxy from './textproxy' ;
13- import Range from './range' ;
14- import DocumentFragment from './documentfragment' ;
15- import NodeList from './nodelist' ;
10+ import Node from '.. /node' ;
11+ import Text from '.. /text' ;
12+ import TextProxy from '.. /textproxy' ;
13+ import Range from '.. /range' ;
14+ import DocumentFragment from '.. /documentfragment' ;
15+ import NodeList from '.. /nodelist' ;
1616import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror' ;
1717
1818/**
19- * Contains functions used for composing model tree, grouped together under " model writer" name. Those functions
20- * are built on top of {@link module:engine/model/node~Node node}, and it's child classes', APIs.
19+ * Contains functions used for composing model tree by { @link module:engine/ model/operation~Operation operations}.
20+ * Those functions are built on top of {@link module:engine/model/node~Node node}, and it's child classes', APIs.
2121 *
22- * Model writer API has multiple advantages and it is highly recommended to use it when changing model tree and nodes:
23- * * model writer API {@link module:engine/model/writer~writer.normalizeNodes normalizes inserted nodes}, which means that you can insert
24- * not only {@link module:engine/model/node~Node nodes}, but also `String`s, {@link module:engine/model/textproxy~TextProxy text proxies}
25- * and
26- * {@link module:engine/model/documentfragment~DocumentFragment document fragments},
27- * * model writer API operates on {@link module:engine/model/position~Position positions}, which means that you have
28- * better control over manipulating model tree as positions operate on offsets rather than indexes,
29- * * model writer API automatically merges {@link module:engine/model/text~Text text nodes} with same attributes, which means
30- * lower memory usage and better efficiency.
31- *
32- * @namespace writer
22+ * @protected
23+ * @namespace utils
3324 */
34- const writer = {
35- insert,
36- remove,
37- move,
38- setAttribute,
39- removeAttribute,
40- normalizeNodes
41- } ;
42-
43- export default writer ;
4425
4526/**
4627 * Inserts given nodes at given position.
4728 *
48- * @function module:engine/model/writer~writer.insert
29+ * @protected
30+ * @function module:engine/model/operation/utils~utils.insert
4931 * @param {module:engine/model/position~Position } position Position at which nodes should be inserted.
5032 * @param {module:engine/model/node~NodeSet } nodes Nodes to insert.
5133 * @returns {module:engine/model/range~Range } Range spanning over inserted elements.
5234 */
53- export function insert ( position , nodes ) {
54- nodes = normalizeNodes ( nodes ) ;
35+ export function _insert ( position , nodes ) {
36+ nodes = _normalizeNodes ( nodes ) ;
5537
5638 // We have to count offset before inserting nodes because they can get merged and we would get wrong offsets.
5739 const offset = nodes . reduce ( ( sum , node ) => sum + node . offsetSize , 0 ) ;
@@ -75,18 +57,19 @@ export function insert( position, nodes ) {
7557/**
7658 * Removed nodes in given range. Only {@link module:engine/model/range~Range#isFlat flat} ranges are accepted.
7759 *
78- * @function module:engine/model/writer~writer.remove
60+ * @protected
61+ * @function module:engine/model/operation/utils~utils.remove
7962 * @param {module:engine/model/range~Range } range Range containing nodes to remove.
8063 * @returns {Array.<module:engine/model/node~Node> }
8164 */
82- export function remove ( range ) {
65+ export function _remove ( range ) {
8366 if ( ! range . isFlat ) {
8467 /**
8568 * Trying to remove a range which starts and ends in different element.
8669 *
87- * @error model-writer -remove-range-not-flat
70+ * @error operation-utils -remove-range-not-flat
8871 */
89- throw new CKEditorError ( 'model-writer -remove-range-not-flat: ' +
72+ throw new CKEditorError ( 'operation-utils -remove-range-not-flat: ' +
9073 'Trying to remove a range which starts and ends in different element.' ) ;
9174 }
9275
@@ -109,38 +92,42 @@ export function remove( range ) {
10992/**
11093 * Moves nodes in given range to given target position. Only {@link module:engine/model/range~Range#isFlat flat} ranges are accepted.
11194 *
95+ * @protected
96+ * @function module:engine/model/operation/utils~utils.move
11297 * @param {module:engine/model/range~Range } sourceRange Range containing nodes to move.
11398 * @param {module:engine/model/position~Position } targetPosition Position to which nodes should be moved.
11499 * @returns {module:engine/model/range~Range } Range containing moved nodes.
115100 */
116- export function move ( sourceRange , targetPosition ) {
101+ export function _move ( sourceRange , targetPosition ) {
117102 if ( ! sourceRange . isFlat ) {
118103 /**
119104 * Trying to move a range which starts and ends in different element.
120105 *
121- * @error model-writer -move-range-not-flat
106+ * @error operation-utils -move-range-not-flat
122107 */
123- throw new CKEditorError ( 'model-writer -move-range-not-flat: ' +
108+ throw new CKEditorError ( 'operation-utils -move-range-not-flat: ' +
124109 'Trying to move a range which starts and ends in different element.' ) ;
125110 }
126111
127- const nodes = this . remove ( sourceRange ) ;
112+ const nodes = _remove ( sourceRange ) ;
128113
129114 // We have to fix `targetPosition` because model changed after nodes from `sourceRange` got removed and
130115 // that change might have an impact on `targetPosition`.
131116 targetPosition = targetPosition . _getTransformedByDeletion ( sourceRange . start , sourceRange . end . offset - sourceRange . start . offset ) ;
132117
133- return this . insert ( targetPosition , nodes ) ;
118+ return _insert ( targetPosition , nodes ) ;
134119}
135120
136121/**
137122 * Sets given attribute on nodes in given range.
138123 *
124+ * @protected
125+ * @function module:engine/model/operation/utils~utils.setAttribute
139126 * @param {module:engine/model/range~Range } range Range containing nodes that should have the attribute set.
140127 * @param {String } key Key of attribute to set.
141128 * @param {* } value Attribute value.
142129 */
143- export function setAttribute ( range , key , value ) {
130+ export function _setAttribute ( range , key , value ) {
144131 // Range might start or end in text nodes, so we have to split them.
145132 _splitNodeAtPosition ( range . start ) ;
146133 _splitNodeAtPosition ( range . end ) ;
@@ -166,24 +153,16 @@ export function setAttribute( range, key, value ) {
166153 _mergeNodesAtIndex ( range . end . parent , range . end . index ) ;
167154}
168155
169- /**
170- * Removes given attribute from nodes in given range.
171- *
172- * @param {module:engine/model/range~Range } range Range containing nodes that should have the attribute removed.
173- * @param {String } key Key of attribute to remove.
174- */
175- export function removeAttribute ( range , key ) {
176- this . setAttribute ( range , key , null ) ;
177- }
178-
179156/**
180157 * Normalizes given object or an array of objects to an array of {@link module:engine/model/node~Node nodes}. See
181158 * {@link module:engine/model/node~NodeSet NodeSet} for details on how normalization is performed.
182159 *
160+ * @protected
161+ * @function module:engine/model/operation/utils~utils.normalizeNodes
183162 * @param {module:engine/model/node~NodeSet } nodes Objects to normalize.
184163 * @returns {Array.<module:engine/model/node~Node> } Normalized nodes.
185164 */
186- export function normalizeNodes ( nodes ) {
165+ export function _normalizeNodes ( nodes ) {
187166 const normalized = [ ] ;
188167
189168 if ( ! ( nodes instanceof Array ) ) {
0 commit comments