@ckeditor/ckeditor5-engine 35.0.1 → 35.1.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 (124) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/package.json +30 -24
  3. package/src/controller/datacontroller.js +467 -561
  4. package/src/controller/editingcontroller.js +168 -204
  5. package/src/conversion/conversion.js +541 -565
  6. package/src/conversion/conversionhelpers.js +24 -28
  7. package/src/conversion/downcastdispatcher.js +457 -686
  8. package/src/conversion/downcasthelpers.js +1583 -1965
  9. package/src/conversion/mapper.js +518 -707
  10. package/src/conversion/modelconsumable.js +240 -283
  11. package/src/conversion/upcastdispatcher.js +372 -718
  12. package/src/conversion/upcasthelpers.js +707 -818
  13. package/src/conversion/viewconsumable.js +524 -581
  14. package/src/dataprocessor/basichtmlwriter.js +12 -16
  15. package/src/dataprocessor/dataprocessor.js +5 -0
  16. package/src/dataprocessor/htmldataprocessor.js +100 -116
  17. package/src/dataprocessor/htmlwriter.js +1 -18
  18. package/src/dataprocessor/xmldataprocessor.js +116 -137
  19. package/src/dev-utils/model.js +260 -352
  20. package/src/dev-utils/operationreplayer.js +106 -126
  21. package/src/dev-utils/utils.js +34 -51
  22. package/src/dev-utils/view.js +632 -753
  23. package/src/index.js +0 -11
  24. package/src/model/batch.js +111 -127
  25. package/src/model/differ.js +988 -1233
  26. package/src/model/document.js +340 -449
  27. package/src/model/documentfragment.js +327 -364
  28. package/src/model/documentselection.js +996 -1189
  29. package/src/model/element.js +306 -410
  30. package/src/model/history.js +224 -262
  31. package/src/model/item.js +5 -0
  32. package/src/model/liveposition.js +84 -145
  33. package/src/model/liverange.js +108 -185
  34. package/src/model/markercollection.js +379 -480
  35. package/src/model/model.js +883 -1034
  36. package/src/model/node.js +419 -463
  37. package/src/model/nodelist.js +175 -201
  38. package/src/model/operation/attributeoperation.js +153 -182
  39. package/src/model/operation/detachoperation.js +64 -83
  40. package/src/model/operation/insertoperation.js +135 -166
  41. package/src/model/operation/markeroperation.js +114 -140
  42. package/src/model/operation/mergeoperation.js +163 -191
  43. package/src/model/operation/moveoperation.js +157 -187
  44. package/src/model/operation/nooperation.js +28 -38
  45. package/src/model/operation/operation.js +106 -125
  46. package/src/model/operation/operationfactory.js +30 -34
  47. package/src/model/operation/renameoperation.js +109 -135
  48. package/src/model/operation/rootattributeoperation.js +155 -188
  49. package/src/model/operation/splitoperation.js +196 -232
  50. package/src/model/operation/transform.js +1833 -2204
  51. package/src/model/operation/utils.js +140 -204
  52. package/src/model/position.js +899 -1053
  53. package/src/model/range.js +910 -1028
  54. package/src/model/rootelement.js +77 -97
  55. package/src/model/schema.js +1189 -1835
  56. package/src/model/selection.js +745 -862
  57. package/src/model/text.js +90 -114
  58. package/src/model/textproxy.js +204 -240
  59. package/src/model/treewalker.js +316 -397
  60. package/src/model/typecheckable.js +16 -0
  61. package/src/model/utils/autoparagraphing.js +32 -44
  62. package/src/model/utils/deletecontent.js +334 -418
  63. package/src/model/utils/findoptimalinsertionrange.js +25 -36
  64. package/src/model/utils/getselectedcontent.js +96 -118
  65. package/src/model/utils/insertcontent.js +654 -773
  66. package/src/model/utils/insertobject.js +96 -119
  67. package/src/model/utils/modifyselection.js +120 -158
  68. package/src/model/utils/selection-post-fixer.js +153 -201
  69. package/src/model/writer.js +1305 -1474
  70. package/src/view/attributeelement.js +189 -225
  71. package/src/view/containerelement.js +75 -85
  72. package/src/view/document.js +172 -215
  73. package/src/view/documentfragment.js +200 -249
  74. package/src/view/documentselection.js +338 -367
  75. package/src/view/domconverter.js +1370 -1617
  76. package/src/view/downcastwriter.js +1747 -2076
  77. package/src/view/editableelement.js +81 -97
  78. package/src/view/element.js +739 -890
  79. package/src/view/elementdefinition.js +5 -0
  80. package/src/view/emptyelement.js +82 -92
  81. package/src/view/filler.js +35 -50
  82. package/src/view/item.js +5 -0
  83. package/src/view/matcher.js +260 -559
  84. package/src/view/node.js +274 -360
  85. package/src/view/observer/arrowkeysobserver.js +19 -28
  86. package/src/view/observer/bubblingemittermixin.js +120 -263
  87. package/src/view/observer/bubblingeventinfo.js +47 -55
  88. package/src/view/observer/clickobserver.js +7 -13
  89. package/src/view/observer/compositionobserver.js +14 -24
  90. package/src/view/observer/domeventdata.js +57 -67
  91. package/src/view/observer/domeventobserver.js +40 -64
  92. package/src/view/observer/fakeselectionobserver.js +81 -96
  93. package/src/view/observer/focusobserver.js +45 -61
  94. package/src/view/observer/inputobserver.js +7 -13
  95. package/src/view/observer/keyobserver.js +17 -27
  96. package/src/view/observer/mouseobserver.js +7 -14
  97. package/src/view/observer/mutationobserver.js +220 -315
  98. package/src/view/observer/observer.js +81 -102
  99. package/src/view/observer/selectionobserver.js +191 -246
  100. package/src/view/observer/tabobserver.js +23 -36
  101. package/src/view/placeholder.js +128 -173
  102. package/src/view/position.js +350 -401
  103. package/src/view/range.js +453 -513
  104. package/src/view/rawelement.js +85 -112
  105. package/src/view/renderer.js +874 -1018
  106. package/src/view/rooteditableelement.js +80 -90
  107. package/src/view/selection.js +608 -689
  108. package/src/view/styles/background.js +43 -44
  109. package/src/view/styles/border.js +220 -276
  110. package/src/view/styles/margin.js +8 -17
  111. package/src/view/styles/padding.js +8 -16
  112. package/src/view/styles/utils.js +127 -160
  113. package/src/view/stylesmap.js +728 -905
  114. package/src/view/text.js +102 -126
  115. package/src/view/textproxy.js +144 -170
  116. package/src/view/treewalker.js +383 -479
  117. package/src/view/typecheckable.js +19 -0
  118. package/src/view/uielement.js +166 -187
  119. package/src/view/upcastwriter.js +395 -449
  120. package/src/view/view.js +569 -664
  121. package/src/dataprocessor/dataprocessor.jsdoc +0 -64
  122. package/src/model/item.jsdoc +0 -14
  123. package/src/view/elementdefinition.jsdoc +0 -59
  124. package/src/view/item.jsdoc +0 -14
@@ -2,14 +2,11 @@
2
2
  * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module engine/model/operation/rootattributeoperation
8
7
  */
9
-
10
8
  import Operation from './operation';
11
9
  import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
12
-
13
10
  /**
14
11
  * Operation to change root element's attribute. Using this class you can add, remove or change value of the attribute.
15
12
  *
@@ -23,189 +20,159 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
23
20
  * @extends module:engine/model/operation/operation~Operation
24
21
  */
25
22
  export default class RootAttributeOperation extends Operation {
26
- /**
27
- * Creates an operation that changes, removes or adds attributes on root element.
28
- *
29
- * @see module:engine/model/operation/attributeoperation~AttributeOperation
30
- * @param {module:engine/model/rootelement~RootElement} root Root element to change.
31
- * @param {String} key Key of an attribute to change or remove.
32
- * @param {*} oldValue Old value of the attribute with given key or `null` if adding a new attribute.
33
- * @param {*} newValue New value to set for the attribute. If `null`, then the operation just removes the attribute.
34
- * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
35
- * can be applied or `null` if the operation operates on detached (non-document) tree.
36
- */
37
- constructor( root, key, oldValue, newValue, baseVersion ) {
38
- super( baseVersion );
39
-
40
- /**
41
- * Root element to change.
42
- *
43
- * @readonly
44
- * @member {module:engine/model/rootelement~RootElement}
45
- */
46
- this.root = root;
47
-
48
- /**
49
- * Key of an attribute to change or remove.
50
- *
51
- * @readonly
52
- * @member {String}
53
- */
54
- this.key = key;
55
-
56
- /**
57
- * Old value of the attribute with given key or `null` if adding a new attribute.
58
- *
59
- * @readonly
60
- * @member {*}
61
- */
62
- this.oldValue = oldValue;
63
-
64
- /**
65
- * New value to set for the attribute. If `null`, then the operation just removes the attribute.
66
- *
67
- * @readonly
68
- * @member {*}
69
- */
70
- this.newValue = newValue;
71
- }
72
-
73
- /**
74
- * @inheritDoc
75
- */
76
- get type() {
77
- if ( this.oldValue === null ) {
78
- return 'addRootAttribute';
79
- } else if ( this.newValue === null ) {
80
- return 'removeRootAttribute';
81
- } else {
82
- return 'changeRootAttribute';
83
- }
84
- }
85
-
86
- /**
87
- * Creates and returns an operation that has the same parameters as this operation.
88
- *
89
- * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation} Clone of this operation.
90
- */
91
- clone() {
92
- return new RootAttributeOperation( this.root, this.key, this.oldValue, this.newValue, this.baseVersion );
93
- }
94
-
95
- /**
96
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
97
- *
98
- * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation}
99
- */
100
- getReversed() {
101
- return new RootAttributeOperation( this.root, this.key, this.newValue, this.oldValue, this.baseVersion + 1 );
102
- }
103
-
104
- /**
105
- * @inheritDoc
106
- */
107
- _validate() {
108
- if ( this.root != this.root.root || this.root.is( 'documentFragment' ) ) {
109
- /**
110
- * The element to change is not a root element.
111
- *
112
- * @error rootattribute-operation-not-a-root
113
- * @param {module:engine/model/rootelement~RootElement} root
114
- * @param {String} key
115
- * @param {*} value
116
- */
117
- throw new CKEditorError(
118
- 'rootattribute-operation-not-a-root',
119
- this,
120
- { root: this.root, key: this.key }
121
- );
122
- }
123
-
124
- if ( this.oldValue !== null && this.root.getAttribute( this.key ) !== this.oldValue ) {
125
- /**
126
- * The attribute which should be removed does not exists for the given node.
127
- *
128
- * @error rootattribute-operation-wrong-old-value
129
- * @param {module:engine/model/rootelement~RootElement} root
130
- * @param {String} key
131
- * @param {*} value
132
- */
133
- throw new CKEditorError(
134
- 'rootattribute-operation-wrong-old-value',
135
- this,
136
- { root: this.root, key: this.key }
137
- );
138
- }
139
-
140
- if ( this.oldValue === null && this.newValue !== null && this.root.hasAttribute( this.key ) ) {
141
- /**
142
- * The attribute with given key already exists for the given node.
143
- *
144
- * @error rootattribute-operation-attribute-exists
145
- * @param {module:engine/model/rootelement~RootElement} root
146
- * @param {String} key
147
- */
148
- throw new CKEditorError(
149
- 'rootattribute-operation-attribute-exists',
150
- this,
151
- { root: this.root, key: this.key }
152
- );
153
- }
154
- }
155
-
156
- /**
157
- * @inheritDoc
158
- */
159
- _execute() {
160
- if ( this.newValue !== null ) {
161
- this.root._setAttribute( this.key, this.newValue );
162
- } else {
163
- this.root._removeAttribute( this.key );
164
- }
165
- }
166
-
167
- /**
168
- * @inheritDoc
169
- */
170
- toJSON() {
171
- const json = super.toJSON();
172
-
173
- json.root = this.root.toJSON();
174
-
175
- return json;
176
- }
177
-
178
- /**
179
- * @inheritDoc
180
- */
181
- static get className() {
182
- return 'RootAttributeOperation';
183
- }
184
-
185
- /**
186
- * Creates RootAttributeOperation object from deserilized object, i.e. from parsed JSON string.
187
- *
188
- * @param {Object} json Deserialized JSON object.
189
- * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
190
- * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation}
191
- */
192
- static fromJSON( json, document ) {
193
- if ( !document.getRoot( json.root ) ) {
194
- /**
195
- * Cannot create RootAttributeOperation for document. Root with specified name does not exist.
196
- *
197
- * @error rootattribute-operation-fromjson-no-root
198
- * @param {String} rootName
199
- */
200
- throw new CKEditorError( 'rootattribute-operation-fromjson-no-root', this, { rootName: json.root } );
201
- }
202
-
203
- return new RootAttributeOperation( document.getRoot( json.root ), json.key, json.oldValue, json.newValue, json.baseVersion );
204
- }
205
-
206
- // @if CK_DEBUG_ENGINE // toString() {
207
- // @if CK_DEBUG_ENGINE // return `RootAttributeOperation( ${ this.baseVersion } ): ` +
208
- // @if CK_DEBUG_ENGINE // `"${ this.key }": ${ JSON.stringify( this.oldValue ) }` +
209
- // @if CK_DEBUG_ENGINE // ` -> ${ JSON.stringify( this.newValue ) }, ${ this.root.rootName }`;
210
- // @if CK_DEBUG_ENGINE // }
23
+ /**
24
+ * Creates an operation that changes, removes or adds attributes on root element.
25
+ *
26
+ * @see module:engine/model/operation/attributeoperation~AttributeOperation
27
+ * @param {module:engine/model/rootelement~RootElement} root Root element to change.
28
+ * @param {String} key Key of an attribute to change or remove.
29
+ * @param {*} oldValue Old value of the attribute with given key or `null` if adding a new attribute.
30
+ * @param {*} newValue New value to set for the attribute. If `null`, then the operation just removes the attribute.
31
+ * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
32
+ * can be applied or `null` if the operation operates on detached (non-document) tree.
33
+ */
34
+ constructor(root, key, oldValue, newValue, baseVersion) {
35
+ super(baseVersion);
36
+ /**
37
+ * Root element to change.
38
+ *
39
+ * @readonly
40
+ * @member {module:engine/model/rootelement~RootElement}
41
+ */
42
+ this.root = root;
43
+ /**
44
+ * Key of an attribute to change or remove.
45
+ *
46
+ * @readonly
47
+ * @member {String}
48
+ */
49
+ this.key = key;
50
+ /**
51
+ * Old value of the attribute with given key or `null` if adding a new attribute.
52
+ *
53
+ * @readonly
54
+ * @member {*}
55
+ */
56
+ this.oldValue = oldValue;
57
+ /**
58
+ * New value to set for the attribute. If `null`, then the operation just removes the attribute.
59
+ *
60
+ * @readonly
61
+ * @member {*}
62
+ */
63
+ this.newValue = newValue;
64
+ }
65
+ /**
66
+ * @inheritDoc
67
+ */
68
+ get type() {
69
+ if (this.oldValue === null) {
70
+ return 'addRootAttribute';
71
+ }
72
+ else if (this.newValue === null) {
73
+ return 'removeRootAttribute';
74
+ }
75
+ else {
76
+ return 'changeRootAttribute';
77
+ }
78
+ }
79
+ /**
80
+ * Creates and returns an operation that has the same parameters as this operation.
81
+ *
82
+ * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation} Clone of this operation.
83
+ */
84
+ clone() {
85
+ return new RootAttributeOperation(this.root, this.key, this.oldValue, this.newValue, this.baseVersion);
86
+ }
87
+ /**
88
+ * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
89
+ *
90
+ * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation}
91
+ */
92
+ getReversed() {
93
+ return new RootAttributeOperation(this.root, this.key, this.newValue, this.oldValue, this.baseVersion + 1);
94
+ }
95
+ /**
96
+ * @inheritDoc
97
+ * @internal
98
+ */
99
+ _validate() {
100
+ if (this.root != this.root.root || this.root.is('documentFragment')) {
101
+ /**
102
+ * The element to change is not a root element.
103
+ *
104
+ * @error rootattribute-operation-not-a-root
105
+ * @param {module:engine/model/rootelement~RootElement} root
106
+ * @param {String} key
107
+ * @param {*} value
108
+ */
109
+ throw new CKEditorError('rootattribute-operation-not-a-root', this, { root: this.root, key: this.key });
110
+ }
111
+ if (this.oldValue !== null && this.root.getAttribute(this.key) !== this.oldValue) {
112
+ /**
113
+ * The attribute which should be removed does not exists for the given node.
114
+ *
115
+ * @error rootattribute-operation-wrong-old-value
116
+ * @param {module:engine/model/rootelement~RootElement} root
117
+ * @param {String} key
118
+ * @param {*} value
119
+ */
120
+ throw new CKEditorError('rootattribute-operation-wrong-old-value', this, { root: this.root, key: this.key });
121
+ }
122
+ if (this.oldValue === null && this.newValue !== null && this.root.hasAttribute(this.key)) {
123
+ /**
124
+ * The attribute with given key already exists for the given node.
125
+ *
126
+ * @error rootattribute-operation-attribute-exists
127
+ * @param {module:engine/model/rootelement~RootElement} root
128
+ * @param {String} key
129
+ */
130
+ throw new CKEditorError('rootattribute-operation-attribute-exists', this, { root: this.root, key: this.key });
131
+ }
132
+ }
133
+ /**
134
+ * @inheritDoc
135
+ * @internal
136
+ */
137
+ _execute() {
138
+ if (this.newValue !== null) {
139
+ this.root._setAttribute(this.key, this.newValue);
140
+ }
141
+ else {
142
+ this.root._removeAttribute(this.key);
143
+ }
144
+ }
145
+ /**
146
+ * @inheritDoc
147
+ */
148
+ toJSON() {
149
+ const json = super.toJSON();
150
+ json.root = this.root.toJSON();
151
+ return json;
152
+ }
153
+ /**
154
+ * @inheritDoc
155
+ */
156
+ static get className() {
157
+ return 'RootAttributeOperation';
158
+ }
159
+ /**
160
+ * Creates RootAttributeOperation object from deserilized object, i.e. from parsed JSON string.
161
+ *
162
+ * @param {Object} json Deserialized JSON object.
163
+ * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
164
+ * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation}
165
+ */
166
+ static fromJSON(json, document) {
167
+ if (!document.getRoot(json.root)) {
168
+ /**
169
+ * Cannot create RootAttributeOperation for document. Root with specified name does not exist.
170
+ *
171
+ * @error rootattribute-operation-fromjson-no-root
172
+ * @param {String} rootName
173
+ */
174
+ throw new CKEditorError('rootattribute-operation-fromjson-no-root', this, { rootName: json.root });
175
+ }
176
+ return new RootAttributeOperation(document.getRoot(json.root), json.key, json.oldValue, json.newValue, json.baseVersion);
177
+ }
211
178
  }