@ckeditor/ckeditor5-engine 30.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +30 -0
  3. package/package.json +70 -0
  4. package/src/controller/datacontroller.js +563 -0
  5. package/src/controller/editingcontroller.js +149 -0
  6. package/src/conversion/conversion.js +644 -0
  7. package/src/conversion/conversionhelpers.js +40 -0
  8. package/src/conversion/downcastdispatcher.js +914 -0
  9. package/src/conversion/downcasthelpers.js +1706 -0
  10. package/src/conversion/mapper.js +696 -0
  11. package/src/conversion/modelconsumable.js +329 -0
  12. package/src/conversion/upcastdispatcher.js +807 -0
  13. package/src/conversion/upcasthelpers.js +997 -0
  14. package/src/conversion/viewconsumable.js +623 -0
  15. package/src/dataprocessor/basichtmlwriter.js +32 -0
  16. package/src/dataprocessor/dataprocessor.jsdoc +64 -0
  17. package/src/dataprocessor/htmldataprocessor.js +159 -0
  18. package/src/dataprocessor/htmlwriter.js +22 -0
  19. package/src/dataprocessor/xmldataprocessor.js +161 -0
  20. package/src/dev-utils/model.js +482 -0
  21. package/src/dev-utils/operationreplayer.js +140 -0
  22. package/src/dev-utils/utils.js +103 -0
  23. package/src/dev-utils/view.js +1091 -0
  24. package/src/index.js +52 -0
  25. package/src/model/batch.js +82 -0
  26. package/src/model/differ.js +1282 -0
  27. package/src/model/document.js +483 -0
  28. package/src/model/documentfragment.js +390 -0
  29. package/src/model/documentselection.js +1261 -0
  30. package/src/model/element.js +438 -0
  31. package/src/model/history.js +138 -0
  32. package/src/model/item.jsdoc +14 -0
  33. package/src/model/liveposition.js +182 -0
  34. package/src/model/liverange.js +221 -0
  35. package/src/model/markercollection.js +553 -0
  36. package/src/model/model.js +934 -0
  37. package/src/model/node.js +507 -0
  38. package/src/model/nodelist.js +217 -0
  39. package/src/model/operation/attributeoperation.js +202 -0
  40. package/src/model/operation/detachoperation.js +103 -0
  41. package/src/model/operation/insertoperation.js +188 -0
  42. package/src/model/operation/markeroperation.js +154 -0
  43. package/src/model/operation/mergeoperation.js +216 -0
  44. package/src/model/operation/moveoperation.js +209 -0
  45. package/src/model/operation/nooperation.js +58 -0
  46. package/src/model/operation/operation.js +139 -0
  47. package/src/model/operation/operationfactory.js +49 -0
  48. package/src/model/operation/renameoperation.js +155 -0
  49. package/src/model/operation/rootattributeoperation.js +211 -0
  50. package/src/model/operation/splitoperation.js +254 -0
  51. package/src/model/operation/transform.js +2389 -0
  52. package/src/model/operation/utils.js +292 -0
  53. package/src/model/position.js +1164 -0
  54. package/src/model/range.js +1049 -0
  55. package/src/model/rootelement.js +111 -0
  56. package/src/model/schema.js +1851 -0
  57. package/src/model/selection.js +902 -0
  58. package/src/model/text.js +138 -0
  59. package/src/model/textproxy.js +279 -0
  60. package/src/model/treewalker.js +414 -0
  61. package/src/model/utils/autoparagraphing.js +77 -0
  62. package/src/model/utils/deletecontent.js +528 -0
  63. package/src/model/utils/getselectedcontent.js +150 -0
  64. package/src/model/utils/insertcontent.js +824 -0
  65. package/src/model/utils/modifyselection.js +229 -0
  66. package/src/model/utils/selection-post-fixer.js +297 -0
  67. package/src/model/writer.js +1574 -0
  68. package/src/view/attributeelement.js +274 -0
  69. package/src/view/containerelement.js +123 -0
  70. package/src/view/document.js +221 -0
  71. package/src/view/documentfragment.js +273 -0
  72. package/src/view/documentselection.js +387 -0
  73. package/src/view/domconverter.js +1437 -0
  74. package/src/view/downcastwriter.js +2121 -0
  75. package/src/view/editableelement.js +118 -0
  76. package/src/view/element.js +945 -0
  77. package/src/view/elementdefinition.jsdoc +59 -0
  78. package/src/view/emptyelement.js +119 -0
  79. package/src/view/filler.js +161 -0
  80. package/src/view/item.jsdoc +14 -0
  81. package/src/view/matcher.js +776 -0
  82. package/src/view/node.js +391 -0
  83. package/src/view/observer/arrowkeysobserver.js +58 -0
  84. package/src/view/observer/bubblingemittermixin.js +307 -0
  85. package/src/view/observer/bubblingeventinfo.js +71 -0
  86. package/src/view/observer/clickobserver.js +46 -0
  87. package/src/view/observer/compositionobserver.js +79 -0
  88. package/src/view/observer/domeventdata.js +82 -0
  89. package/src/view/observer/domeventobserver.js +99 -0
  90. package/src/view/observer/fakeselectionobserver.js +118 -0
  91. package/src/view/observer/focusobserver.js +106 -0
  92. package/src/view/observer/inputobserver.js +44 -0
  93. package/src/view/observer/keyobserver.js +83 -0
  94. package/src/view/observer/mouseobserver.js +56 -0
  95. package/src/view/observer/mutationobserver.js +345 -0
  96. package/src/view/observer/observer.js +118 -0
  97. package/src/view/observer/selectionobserver.js +242 -0
  98. package/src/view/placeholder.js +285 -0
  99. package/src/view/position.js +426 -0
  100. package/src/view/range.js +533 -0
  101. package/src/view/rawelement.js +148 -0
  102. package/src/view/renderer.js +1037 -0
  103. package/src/view/rooteditableelement.js +107 -0
  104. package/src/view/selection.js +718 -0
  105. package/src/view/styles/background.js +73 -0
  106. package/src/view/styles/border.js +362 -0
  107. package/src/view/styles/margin.js +41 -0
  108. package/src/view/styles/padding.js +40 -0
  109. package/src/view/styles/utils.js +277 -0
  110. package/src/view/stylesmap.js +938 -0
  111. package/src/view/text.js +147 -0
  112. package/src/view/textproxy.js +199 -0
  113. package/src/view/treewalker.js +496 -0
  114. package/src/view/uielement.js +238 -0
  115. package/src/view/upcastwriter.js +484 -0
  116. package/src/view/view.js +721 -0
  117. package/theme/placeholder.css +27 -0
@@ -0,0 +1,138 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module engine/model/text
8
+ */
9
+
10
+ import Node from './node';
11
+
12
+ // @if CK_DEBUG_ENGINE // const { convertMapToStringifiedObject } = require( '../dev-utils/utils' );
13
+
14
+ /**
15
+ * Model text node. Type of {@link module:engine/model/node~Node node} that contains {@link module:engine/model/text~Text#data text data}.
16
+ *
17
+ * **Important:** see {@link module:engine/model/node~Node} to read about restrictions using `Text` and `Node` API.
18
+ *
19
+ * **Note:** keep in mind that `Text` instances might indirectly got removed from model tree when model is changed.
20
+ * This happens when {@link module:engine/model/writer~Writer model writer} is used to change model and the text node is merged with
21
+ * another text node. Then, both text nodes are removed and a new text node is inserted into the model. Because of
22
+ * this behavior, keeping references to `Text` is not recommended. Instead, consider creating
23
+ * {@link module:engine/model/liveposition~LivePosition live position} placed before the text node.
24
+ *
25
+ * @extends module:engine/model/node~Node
26
+ */
27
+ export default class Text extends Node {
28
+ /**
29
+ * Creates a text node.
30
+ *
31
+ * **Note:** Constructor of this class shouldn't be used directly in the code.
32
+ * Use the {@link module:engine/model/writer~Writer#createText} method instead.
33
+ *
34
+ * @protected
35
+ * @param {String} data Node's text.
36
+ * @param {Object} [attrs] Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
37
+ */
38
+ constructor( data, attrs ) {
39
+ super( attrs );
40
+
41
+ /**
42
+ * Text data contained in this text node.
43
+ *
44
+ * @protected
45
+ * @type {String}
46
+ */
47
+ this._data = data || '';
48
+ }
49
+
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ get offsetSize() {
54
+ return this.data.length;
55
+ }
56
+
57
+ /**
58
+ * Returns a text data contained in the node.
59
+ *
60
+ * @readonly
61
+ * @type {String}
62
+ */
63
+ get data() {
64
+ return this._data;
65
+ }
66
+
67
+ /**
68
+ * Checks whether this object is of the given.
69
+ *
70
+ * text.is( '$text' ); // -> true
71
+ * text.is( 'node' ); // -> true
72
+ * text.is( 'model:$text' ); // -> true
73
+ * text.is( 'model:node' ); // -> true
74
+ *
75
+ * text.is( 'view:$text' ); // -> false
76
+ * text.is( 'documentSelection' ); // -> false
77
+ *
78
+ * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
79
+ *
80
+ * **Note:** Until version 20.0.0 this method wasn't accepting `'$text'` type. The legacy `'text'` type is still
81
+ * accepted for backward compatibility.
82
+ *
83
+ * @param {String} type Type to check.
84
+ * @returns {Boolean}
85
+ */
86
+ is( type ) {
87
+ return type === '$text' || type === 'model:$text' ||
88
+ // This are legacy values kept for backward compatibility.
89
+ type === 'text' || type === 'model:text' ||
90
+ // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
91
+ type === 'node' || type === 'model:node';
92
+ }
93
+
94
+ /**
95
+ * Converts `Text` instance to plain object and returns it.
96
+ *
97
+ * @returns {Object} `Text` instance converted to plain object.
98
+ */
99
+ toJSON() {
100
+ const json = super.toJSON();
101
+
102
+ json.data = this.data;
103
+
104
+ return json;
105
+ }
106
+
107
+ /**
108
+ * Creates a copy of this text node and returns it. Created text node has same text data and attributes as original text node.
109
+ *
110
+ * @protected
111
+ * @returns {module:engine/model/text~Text} `Text` instance created using given plain object.
112
+ */
113
+ _clone() {
114
+ return new Text( this.data, this.getAttributes() );
115
+ }
116
+
117
+ /**
118
+ * Creates a `Text` instance from given plain object (i.e. parsed JSON string).
119
+ *
120
+ * @param {Object} json Plain object to be converted to `Text`.
121
+ * @returns {module:engine/model/text~Text} `Text` instance created using given plain object.
122
+ */
123
+ static fromJSON( json ) {
124
+ return new Text( json.data, json.attributes );
125
+ }
126
+
127
+ // @if CK_DEBUG_ENGINE // toString() {
128
+ // @if CK_DEBUG_ENGINE // return `#${ this.data }`;
129
+ // @if CK_DEBUG_ENGINE // }
130
+
131
+ // @if CK_DEBUG_ENGINE // logExtended() {
132
+ // @if CK_DEBUG_ENGINE // console.log( `ModelText: ${ this }, attrs: ${ convertMapToStringifiedObject( this.getAttributes() ) }` );
133
+ // @if CK_DEBUG_ENGINE // }
134
+
135
+ // @if CK_DEBUG_ENGINE // log() {
136
+ // @if CK_DEBUG_ENGINE // console.log( 'ModelText: ' + this );
137
+ // @if CK_DEBUG_ENGINE // }
138
+ }
@@ -0,0 +1,279 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module engine/model/textproxy
8
+ */
9
+
10
+ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
11
+
12
+ // @if CK_DEBUG_ENGINE // const { convertMapToStringifiedObject } = require( '../dev-utils/utils' );
13
+
14
+ /**
15
+ * `TextProxy` represents a part of {@link module:engine/model/text~Text text node}.
16
+ *
17
+ * Since {@link module:engine/model/position~Position positions} can be placed between characters of a text node,
18
+ * {@link module:engine/model/range~Range ranges} may contain only parts of text nodes. When {@link module:engine/model/range~Range#getItems
19
+ * getting items}
20
+ * contained in such range, we need to represent a part of that text node, since returning the whole text node would be incorrect.
21
+ * `TextProxy` solves this issue.
22
+ *
23
+ * `TextProxy` has an API similar to {@link module:engine/model/text~Text Text} and allows to do most of the common tasks performed
24
+ * on model nodes.
25
+ *
26
+ * **Note:** Some `TextProxy` instances may represent whole text node, not just a part of it.
27
+ * See {@link module:engine/model/textproxy~TextProxy#isPartial}.
28
+ *
29
+ * **Note:** `TextProxy` is not an instance of {@link module:engine/model/node~Node node}. Keep this in mind when using it as a
30
+ * parameter of methods.
31
+ *
32
+ * **Note:** `TextProxy` is a readonly interface. If you want to perform changes on model data represented by a `TextProxy`
33
+ * use {@link module:engine/model/writer~Writer model writer API}.
34
+ *
35
+ * **Note:** `TextProxy` instances are created on the fly, basing on the current state of model. Because of this, it is
36
+ * highly unrecommended to store references to `TextProxy` instances. `TextProxy` instances are not refreshed when
37
+ * model changes, so they might get invalidated. Instead, consider creating {@link module:engine/model/liveposition~LivePosition live
38
+ * position}.
39
+ *
40
+ * `TextProxy` instances are created by {@link module:engine/model/treewalker~TreeWalker model tree walker}. You should not need to create
41
+ * an instance of this class by your own.
42
+ */
43
+ export default class TextProxy {
44
+ /**
45
+ * Creates a text proxy.
46
+ *
47
+ * @protected
48
+ * @param {module:engine/model/text~Text} textNode Text node which part is represented by this text proxy.
49
+ * @param {Number} offsetInText Offset in {@link module:engine/model/textproxy~TextProxy#textNode text node} from which the text proxy
50
+ * starts.
51
+ * @param {Number} length Text proxy length, that is how many text node's characters, starting from `offsetInText` it represents.
52
+ * @constructor
53
+ */
54
+ constructor( textNode, offsetInText, length ) {
55
+ /**
56
+ * Text node which part is represented by this text proxy.
57
+ *
58
+ * @readonly
59
+ * @member {module:engine/model/text~Text}
60
+ */
61
+ this.textNode = textNode;
62
+
63
+ if ( offsetInText < 0 || offsetInText > textNode.offsetSize ) {
64
+ /**
65
+ * Given `offsetInText` value is incorrect.
66
+ *
67
+ * @error model-textproxy-wrong-offsetintext
68
+ */
69
+ throw new CKEditorError( 'model-textproxy-wrong-offsetintext', this );
70
+ }
71
+
72
+ if ( length < 0 || offsetInText + length > textNode.offsetSize ) {
73
+ /**
74
+ * Given `length` value is incorrect.
75
+ *
76
+ * @error model-textproxy-wrong-length
77
+ */
78
+ throw new CKEditorError( 'model-textproxy-wrong-length', this );
79
+ }
80
+
81
+ /**
82
+ * Text data represented by this text proxy.
83
+ *
84
+ * @readonly
85
+ * @member {String}
86
+ */
87
+ this.data = textNode.data.substring( offsetInText, offsetInText + length );
88
+
89
+ /**
90
+ * Offset in {@link module:engine/model/textproxy~TextProxy#textNode text node} from which the text proxy starts.
91
+ *
92
+ * @readonly
93
+ * @member {Number}
94
+ */
95
+ this.offsetInText = offsetInText;
96
+ }
97
+
98
+ /**
99
+ * Offset at which this text proxy starts in it's parent.
100
+ *
101
+ * @see module:engine/model/node~Node#startOffset
102
+ * @readonly
103
+ * @type {Number}
104
+ */
105
+ get startOffset() {
106
+ return this.textNode.startOffset !== null ? this.textNode.startOffset + this.offsetInText : null;
107
+ }
108
+
109
+ /**
110
+ * Offset size of this text proxy. Equal to the number of characters represented by the text proxy.
111
+ *
112
+ * @see module:engine/model/node~Node#offsetSize
113
+ * @readonly
114
+ * @type {Number}
115
+ */
116
+ get offsetSize() {
117
+ return this.data.length;
118
+ }
119
+
120
+ /**
121
+ * Offset at which this text proxy ends in it's parent.
122
+ *
123
+ * @see module:engine/model/node~Node#endOffset
124
+ * @readonly
125
+ * @type {Number}
126
+ */
127
+ get endOffset() {
128
+ return this.startOffset !== null ? this.startOffset + this.offsetSize : null;
129
+ }
130
+
131
+ /**
132
+ * Flag indicating whether `TextProxy` instance covers only part of the original {@link module:engine/model/text~Text text node}
133
+ * (`true`) or the whole text node (`false`).
134
+ *
135
+ * This is `false` when text proxy starts at the very beginning of {@link module:engine/model/textproxy~TextProxy#textNode textNode}
136
+ * ({@link module:engine/model/textproxy~TextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
137
+ * text node size.
138
+ *
139
+ * @readonly
140
+ * @type {Boolean}
141
+ */
142
+ get isPartial() {
143
+ return this.offsetSize !== this.textNode.offsetSize;
144
+ }
145
+
146
+ /**
147
+ * Parent of this text proxy, which is same as parent of text node represented by this text proxy.
148
+ *
149
+ * @readonly
150
+ * @type {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment|null}
151
+ */
152
+ get parent() {
153
+ return this.textNode.parent;
154
+ }
155
+
156
+ /**
157
+ * Root of this text proxy, which is same as root of text node represented by this text proxy.
158
+ *
159
+ * @readonly
160
+ * @type {module:engine/model/node~Node|module:engine/model/documentfragment~DocumentFragment}
161
+ */
162
+ get root() {
163
+ return this.textNode.root;
164
+ }
165
+
166
+ /**
167
+ * Checks whether this object is of the given.
168
+ *
169
+ * textProxy.is( '$textProxy' ); // -> true
170
+ * textProxy.is( 'model:$textProxy' ); // -> true
171
+ *
172
+ * textProxy.is( 'view:$textProxy' ); // -> false
173
+ * textProxy.is( 'range' ); // -> false
174
+ *
175
+ * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
176
+ *
177
+ * **Note:** Until version 20.0.0 this method wasn't accepting `'$textProxy'` type. The legacy `'textProxt'` type is still
178
+ * accepted for backward compatibility.
179
+ *
180
+ * @param {String} type Type to check.
181
+ * @returns {Boolean}
182
+ */
183
+ is( type ) {
184
+ return type === '$textProxy' || type === 'model:$textProxy' ||
185
+ // This are legacy values kept for backward compatibility.
186
+ type === 'textProxy' || type === 'model:textProxy';
187
+ }
188
+
189
+ /**
190
+ * Gets path to this text proxy.
191
+ *
192
+ * @see module:engine/model/node~Node#getPath
193
+ * @returns {Array.<Number>}
194
+ */
195
+ getPath() {
196
+ const path = this.textNode.getPath();
197
+
198
+ if ( path.length > 0 ) {
199
+ path[ path.length - 1 ] += this.offsetInText;
200
+ }
201
+
202
+ return path;
203
+ }
204
+
205
+ /**
206
+ * Returns ancestors array of this text proxy.
207
+ *
208
+ * @param {Object} options Options object.
209
+ * @param {Boolean} [options.includeSelf=false] When set to `true` this text proxy will be also included in parent's array.
210
+ * @param {Boolean} [options.parentFirst=false] When set to `true`, array will be sorted from text proxy parent to root element,
211
+ * otherwise root element will be the first item in the array.
212
+ * @returns {Array} Array with ancestors.
213
+ */
214
+ getAncestors( options = { includeSelf: false, parentFirst: false } ) {
215
+ const ancestors = [];
216
+ let parent = options.includeSelf ? this : this.parent;
217
+
218
+ while ( parent ) {
219
+ ancestors[ options.parentFirst ? 'push' : 'unshift' ]( parent );
220
+ parent = parent.parent;
221
+ }
222
+
223
+ return ancestors;
224
+ }
225
+
226
+ /**
227
+ * Checks if this text proxy has an attribute for given key.
228
+ *
229
+ * @param {String} key Key of attribute to check.
230
+ * @returns {Boolean} `true` if attribute with given key is set on text proxy, `false` otherwise.
231
+ */
232
+ hasAttribute( key ) {
233
+ return this.textNode.hasAttribute( key );
234
+ }
235
+
236
+ /**
237
+ * Gets an attribute value for given key or `undefined` if that attribute is not set on text proxy.
238
+ *
239
+ * @param {String} key Key of attribute to look for.
240
+ * @returns {*} Attribute value or `undefined`.
241
+ */
242
+ getAttribute( key ) {
243
+ return this.textNode.getAttribute( key );
244
+ }
245
+
246
+ /**
247
+ * Returns iterator that iterates over this node's attributes. Attributes are returned as arrays containing two
248
+ * items. First one is attribute key and second is attribute value.
249
+ *
250
+ * This format is accepted by native `Map` object and also can be passed in `Node` constructor.
251
+ *
252
+ * @returns {Iterable.<*>}
253
+ */
254
+ getAttributes() {
255
+ return this.textNode.getAttributes();
256
+ }
257
+
258
+ /**
259
+ * Returns iterator that iterates over this node's attribute keys.
260
+ *
261
+ * @returns {Iterable.<String>}
262
+ */
263
+ getAttributeKeys() {
264
+ return this.textNode.getAttributeKeys();
265
+ }
266
+
267
+ // @if CK_DEBUG_ENGINE // toString() {
268
+ // @if CK_DEBUG_ENGINE // return `#${ this.data }`;
269
+ // @if CK_DEBUG_ENGINE // }
270
+
271
+ // @if CK_DEBUG_ENGINE // log() {
272
+ // @if CK_DEBUG_ENGINE // console.log( 'ModelTextProxy: ' + this );
273
+ // @if CK_DEBUG_ENGINE // }
274
+
275
+ // @if CK_DEBUG_ENGINE // logExtended() {
276
+ // @if CK_DEBUG_ENGINE // console.log( `ModelTextProxy: ${ this }, ` +
277
+ // @if CK_DEBUG_ENGINE // `attrs: ${ convertMapToStringifiedObject( this.getAttributes() ) }` );
278
+ // @if CK_DEBUG_ENGINE // }
279
+ }