@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,147 @@
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/view/text
8
+ */
9
+
10
+ import Node from './node';
11
+
12
+ /**
13
+ * Tree view text node.
14
+ *
15
+ * The constructor of this class should not be used directly. To create a new text node instance
16
+ * use the {@link module:engine/view/downcastwriter~DowncastWriter#createText `DowncastWriter#createText()`}
17
+ * method when working on data downcasted from the model or the
18
+ * {@link module:engine/view/upcastwriter~UpcastWriter#createText `UpcastWriter#createText()`}
19
+ * method when working on non-semantic views.
20
+ *
21
+ * @extends module:engine/view/node~Node
22
+ */
23
+ export default class Text extends Node {
24
+ /**
25
+ * Creates a tree view text node.
26
+ *
27
+ * @protected
28
+ * @param {module:engine/view/document~Document} document The document instance to which this text node belongs.
29
+ * @param {String} data The text's data.
30
+ */
31
+ constructor( document, data ) {
32
+ super( document );
33
+
34
+ /**
35
+ * The text content.
36
+ *
37
+ * Setting the data fires the {@link module:engine/view/node~Node#event:change:text change event}.
38
+ *
39
+ * @protected
40
+ * @member {String} module:engine/view/text~Text#_textData
41
+ */
42
+ this._textData = data;
43
+ }
44
+
45
+ /**
46
+ * Checks whether this object is of the given type.
47
+ *
48
+ * text.is( '$text' ); // -> true
49
+ * text.is( 'node' ); // -> true
50
+ * text.is( 'view:$text' ); // -> true
51
+ * text.is( 'view:node' ); // -> true
52
+ *
53
+ * text.is( 'model:$text' ); // -> false
54
+ * text.is( 'element' ); // -> false
55
+ * text.is( 'range' ); // -> false
56
+ *
57
+ * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
58
+ *
59
+ * **Note:** Until version 20.0.0 this method wasn't accepting `'$text'` type. The legacy `'text'` type is still
60
+ * accepted for backward compatibility.
61
+ *
62
+ * @param {String} type Type to check.
63
+ * @returns {Boolean}
64
+ */
65
+ is( type ) {
66
+ return type === '$text' || type === 'view:$text' ||
67
+ // This are legacy values kept for backward compatibility.
68
+ type === 'text' || type === 'view:text' ||
69
+ // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
70
+ type === 'node' || type === 'view:node';
71
+ }
72
+
73
+ /**
74
+ * The text content.
75
+ *
76
+ * @readonly
77
+ * @type {String}
78
+ */
79
+ get data() {
80
+ return this._textData;
81
+ }
82
+
83
+ /**
84
+ * The `_data` property is controlled by a getter and a setter.
85
+ *
86
+ * The getter is required when using the addition assignment operator on protected property:
87
+ *
88
+ * const foo = downcastWriter.createText( 'foo' );
89
+ * const bar = downcastWriter.createText( 'bar' );
90
+ *
91
+ * foo._data += bar.data; // executes: `foo._data = foo._data + bar.data`
92
+ * console.log( foo.data ); // prints: 'foobar'
93
+ *
94
+ * If the protected getter didn't exist, `foo._data` will return `undefined` and result of the merge will be invalid.
95
+ *
96
+ * The setter sets data and fires the {@link module:engine/view/node~Node#event:change:text change event}.
97
+ *
98
+ * @protected
99
+ * @type {String}
100
+ */
101
+ get _data() {
102
+ return this.data;
103
+ }
104
+
105
+ set _data( data ) {
106
+ this._fireChange( 'text', this );
107
+
108
+ this._textData = data;
109
+ }
110
+
111
+ /**
112
+ * Checks if this text node is similar to other text node.
113
+ * Both nodes should have the same data to be considered as similar.
114
+ *
115
+ * @param {module:engine/view/text~Text} otherNode Node to check if it is same as this node.
116
+ * @returns {Boolean}
117
+ */
118
+ isSimilar( otherNode ) {
119
+ if ( !( otherNode instanceof Text ) ) {
120
+ return false;
121
+ }
122
+
123
+ return this === otherNode || this.data === otherNode.data;
124
+ }
125
+
126
+ /**
127
+ * Clones this node.
128
+ *
129
+ * @protected
130
+ * @returns {module:engine/view/text~Text} Text node that is a clone of this node.
131
+ */
132
+ _clone() {
133
+ return new Text( this.document, this.data );
134
+ }
135
+
136
+ // @if CK_DEBUG_ENGINE // toString() {
137
+ // @if CK_DEBUG_ENGINE // return `#${ this.data }`;
138
+ // @if CK_DEBUG_ENGINE // }
139
+
140
+ // @if CK_DEBUG_ENGINE // log() {
141
+ // @if CK_DEBUG_ENGINE // console.log( 'ViewText: ' + this );
142
+ // @if CK_DEBUG_ENGINE // }
143
+
144
+ // @if CK_DEBUG_ENGINE // logExtended() {
145
+ // @if CK_DEBUG_ENGINE // console.log( 'ViewText: ' + this );
146
+ // @if CK_DEBUG_ENGINE // }
147
+ }
@@ -0,0 +1,199 @@
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/view/textproxy
8
+ */
9
+
10
+ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
11
+
12
+ /**
13
+ * TextProxy is a wrapper for substring of {@link module:engine/view/text~Text}. Instance of this class is created by
14
+ * {@link module:engine/view/treewalker~TreeWalker} when only a part of {@link module:engine/view/text~Text} needs to be returned.
15
+ *
16
+ * `TextProxy` has an API similar to {@link module:engine/view/text~Text Text} and allows to do most of the common tasks performed
17
+ * on view nodes.
18
+ *
19
+ * **Note:** Some `TextProxy` instances may represent whole text node, not just a part of it.
20
+ * See {@link module:engine/view/textproxy~TextProxy#isPartial}.
21
+ *
22
+ * **Note:** `TextProxy` is a readonly interface.
23
+ *
24
+ * **Note:** `TextProxy` instances are created on the fly basing on the current state of parent {@link module:engine/view/text~Text}.
25
+ * Because of this it is highly unrecommended to store references to `TextProxy instances because they might get
26
+ * invalidated due to operations on Document. Also TextProxy is not a {@link module:engine/view/node~Node} so it can not be
27
+ * inserted as a child of {@link module:engine/view/element~Element}.
28
+ *
29
+ * `TextProxy` instances are created by {@link module:engine/view/treewalker~TreeWalker view tree walker}. You should not need to create
30
+ * an instance of this class by your own.
31
+ */
32
+ export default class TextProxy {
33
+ /**
34
+ * Creates a text proxy.
35
+ *
36
+ * @protected
37
+ * @param {module:engine/view/text~Text} textNode Text node which part is represented by this text proxy.
38
+ * @param {Number} offsetInText Offset in {@link module:engine/view/textproxy~TextProxy#textNode text node}
39
+ * from which the text proxy starts.
40
+ * @param {Number} length Text proxy length, that is how many text node's characters, starting from `offsetInText` it represents.
41
+ * @constructor
42
+ */
43
+ constructor( textNode, offsetInText, length ) {
44
+ /**
45
+ * Reference to the {@link module:engine/view/text~Text} element which TextProxy is a substring.
46
+ *
47
+ * @readonly
48
+ * @member {module:engine/view/text~Text} module:engine/view/textproxy~TextProxy#textNode
49
+ */
50
+ this.textNode = textNode;
51
+
52
+ if ( offsetInText < 0 || offsetInText > textNode.data.length ) {
53
+ /**
54
+ * Given offsetInText value is incorrect.
55
+ *
56
+ * @error view-textproxy-wrong-offsetintext
57
+ */
58
+ throw new CKEditorError( 'view-textproxy-wrong-offsetintext', this );
59
+ }
60
+
61
+ if ( length < 0 || offsetInText + length > textNode.data.length ) {
62
+ /**
63
+ * Given length value is incorrect.
64
+ *
65
+ * @error view-textproxy-wrong-length
66
+ */
67
+ throw new CKEditorError( 'view-textproxy-wrong-length', this );
68
+ }
69
+
70
+ /**
71
+ * Text data represented by this text proxy.
72
+ *
73
+ * @readonly
74
+ * @member {String} module:engine/view/textproxy~TextProxy#data
75
+ */
76
+ this.data = textNode.data.substring( offsetInText, offsetInText + length );
77
+
78
+ /**
79
+ * Offset in the `textNode` where this `TextProxy` instance starts.
80
+ *
81
+ * @readonly
82
+ * @member {Number} module:engine/view/textproxy~TextProxy#offsetInText
83
+ */
84
+ this.offsetInText = offsetInText;
85
+ }
86
+
87
+ /**
88
+ * Offset size of this node.
89
+ *
90
+ * @readonly
91
+ * @type {Number}
92
+ */
93
+ get offsetSize() {
94
+ return this.data.length;
95
+ }
96
+
97
+ /**
98
+ * Flag indicating whether `TextProxy` instance covers only part of the original {@link module:engine/view/text~Text text node}
99
+ * (`true`) or the whole text node (`false`).
100
+ *
101
+ * This is `false` when text proxy starts at the very beginning of {@link module:engine/view/textproxy~TextProxy#textNode textNode}
102
+ * ({@link module:engine/view/textproxy~TextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
103
+ * text node size.
104
+ *
105
+ * @readonly
106
+ * @type {Boolean}
107
+ */
108
+ get isPartial() {
109
+ return this.data.length !== this.textNode.data.length;
110
+ }
111
+
112
+ /**
113
+ * Parent of this text proxy, which is same as parent of text node represented by this text proxy.
114
+ *
115
+ * @readonly
116
+ * @type {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment|null}
117
+ */
118
+ get parent() {
119
+ return this.textNode.parent;
120
+ }
121
+
122
+ /**
123
+ * Root of this text proxy, which is same as root of text node represented by this text proxy.
124
+ *
125
+ * @readonly
126
+ * @type {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment}
127
+ */
128
+ get root() {
129
+ return this.textNode.root;
130
+ }
131
+
132
+ /**
133
+ * {@link module:engine/view/document~Document View document} that owns this text proxy, or `null` if the text proxy is inside
134
+ * {@link module:engine/view/documentfragment~DocumentFragment document fragment}.
135
+ *
136
+ * @readonly
137
+ * @type {module:engine/view/document~Document|null}
138
+ */
139
+ get document() {
140
+ return this.textNode.document;
141
+ }
142
+
143
+ /**
144
+ * Checks whether this object is of the given type.
145
+ *
146
+ * textProxy.is( '$textProxy' ); // -> true
147
+ * textProxy.is( 'view:$textProxy' ); // -> true
148
+ *
149
+ * textProxy.is( 'model:$textProxy' ); // -> false
150
+ * textProxy.is( 'element' ); // -> false
151
+ * textProxy.is( 'range' ); // -> false
152
+ *
153
+ * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
154
+ *
155
+ * **Note:** Until version 20.0.0 this method wasn't accepting `'$textProxy'` type. The legacy `'textProxy'` type is still
156
+ * accepted for backward compatibility.
157
+ *
158
+ * @param {String} type Type to check.
159
+ * @returns {Boolean}
160
+ */
161
+ is( type ) {
162
+ return type === '$textProxy' || type === 'view:$textProxy' ||
163
+ // This are legacy values kept for backward compatibility.
164
+ type === 'textProxy' || type === 'view:textProxy';
165
+ }
166
+
167
+ /**
168
+ * Returns ancestors array of this text proxy.
169
+ *
170
+ * @param {Object} options Options object.
171
+ * @param {Boolean} [options.includeSelf=false] When set to `true` {#textNode} will be also included in parent's array.
172
+ * @param {Boolean} [options.parentFirst=false] When set to `true`, array will be sorted from text proxy parent to
173
+ * root element, otherwise root element will be the first item in the array.
174
+ * @returns {Array} Array with ancestors.
175
+ */
176
+ getAncestors( options = { includeSelf: false, parentFirst: false } ) {
177
+ const ancestors = [];
178
+ let parent = options.includeSelf ? this.textNode : this.parent;
179
+
180
+ while ( parent !== null ) {
181
+ ancestors[ options.parentFirst ? 'push' : 'unshift' ]( parent );
182
+ parent = parent.parent;
183
+ }
184
+
185
+ return ancestors;
186
+ }
187
+
188
+ // @if CK_DEBUG_ENGINE // toString() {
189
+ // @if CK_DEBUG_ENGINE // return `#${ this.data }`;
190
+ // @if CK_DEBUG_ENGINE // }
191
+
192
+ // @if CK_DEBUG_ENGINE // log() {
193
+ // @if CK_DEBUG_ENGINE // console.log( 'ViewTextProxy: ' + this );
194
+ // @if CK_DEBUG_ENGINE // }
195
+
196
+ // @if CK_DEBUG_ENGINE // logExtended() {
197
+ // @if CK_DEBUG_ENGINE // console.log( 'ViewTextProxy: ' + this );
198
+ // @if CK_DEBUG_ENGINE // }
199
+ }