@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.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 (200) hide show
  1. package/README.md +1 -1
  2. package/package.json +24 -23
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +62 -109
  5. package/src/controller/editingcontroller.d.ts +98 -0
  6. package/src/controller/editingcontroller.js +22 -46
  7. package/src/conversion/conversion.d.ts +476 -0
  8. package/src/conversion/conversion.js +328 -347
  9. package/src/conversion/conversionhelpers.d.ts +26 -0
  10. package/src/conversion/conversionhelpers.js +1 -5
  11. package/src/conversion/downcastdispatcher.d.ts +547 -0
  12. package/src/conversion/downcastdispatcher.js +74 -152
  13. package/src/conversion/downcasthelpers.d.ts +1226 -0
  14. package/src/conversion/downcasthelpers.js +843 -762
  15. package/src/conversion/mapper.d.ts +499 -0
  16. package/src/conversion/mapper.js +84 -99
  17. package/src/conversion/modelconsumable.d.ts +201 -0
  18. package/src/conversion/modelconsumable.js +96 -99
  19. package/src/conversion/upcastdispatcher.d.ts +492 -0
  20. package/src/conversion/upcastdispatcher.js +73 -100
  21. package/src/conversion/upcasthelpers.d.ts +499 -0
  22. package/src/conversion/upcasthelpers.js +406 -373
  23. package/src/conversion/viewconsumable.d.ts +177 -0
  24. package/src/conversion/viewconsumable.js +157 -162
  25. package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
  26. package/src/dataprocessor/basichtmlwriter.js +0 -9
  27. package/src/dataprocessor/dataprocessor.d.ts +61 -0
  28. package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
  29. package/src/dataprocessor/htmldataprocessor.js +6 -28
  30. package/src/dataprocessor/htmlwriter.d.ts +16 -0
  31. package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
  32. package/src/dataprocessor/xmldataprocessor.js +8 -40
  33. package/src/dev-utils/model.d.ts +124 -0
  34. package/src/dev-utils/model.js +41 -38
  35. package/src/dev-utils/operationreplayer.d.ts +51 -0
  36. package/src/dev-utils/operationreplayer.js +6 -14
  37. package/src/dev-utils/utils.d.ts +37 -0
  38. package/src/dev-utils/utils.js +5 -18
  39. package/src/dev-utils/view.d.ts +319 -0
  40. package/src/dev-utils/view.js +205 -226
  41. package/src/index.d.ts +105 -0
  42. package/src/index.js +1 -0
  43. package/src/model/batch.d.ts +106 -0
  44. package/src/model/differ.d.ts +329 -0
  45. package/src/model/document.d.ts +245 -0
  46. package/src/model/document.js +1 -1
  47. package/src/model/documentfragment.d.ts +196 -0
  48. package/src/model/documentfragment.js +2 -2
  49. package/src/model/documentselection.d.ts +420 -0
  50. package/src/model/element.d.ts +165 -0
  51. package/src/model/history.d.ts +114 -0
  52. package/src/model/item.d.ts +14 -0
  53. package/src/model/liveposition.d.ts +77 -0
  54. package/src/model/liverange.d.ts +102 -0
  55. package/src/model/markercollection.d.ts +335 -0
  56. package/src/model/model.d.ts +812 -0
  57. package/src/model/model.js +59 -30
  58. package/src/model/node.d.ts +256 -0
  59. package/src/model/nodelist.d.ts +91 -0
  60. package/src/model/operation/attributeoperation.d.ts +98 -0
  61. package/src/model/operation/detachoperation.d.ts +55 -0
  62. package/src/model/operation/insertoperation.d.ts +85 -0
  63. package/src/model/operation/markeroperation.d.ts +86 -0
  64. package/src/model/operation/mergeoperation.d.ts +95 -0
  65. package/src/model/operation/moveoperation.d.ts +91 -0
  66. package/src/model/operation/nooperation.d.ts +33 -0
  67. package/src/model/operation/operation.d.ts +89 -0
  68. package/src/model/operation/operationfactory.d.ts +18 -0
  69. package/src/model/operation/renameoperation.d.ts +78 -0
  70. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  71. package/src/model/operation/rootattributeoperation.js +1 -1
  72. package/src/model/operation/splitoperation.d.ts +104 -0
  73. package/src/model/operation/transform.d.ts +100 -0
  74. package/src/model/operation/utils.d.ts +71 -0
  75. package/src/model/position.d.ts +539 -0
  76. package/src/model/position.js +1 -1
  77. package/src/model/range.d.ts +458 -0
  78. package/src/model/range.js +1 -1
  79. package/src/model/rootelement.d.ts +40 -0
  80. package/src/model/schema.d.ts +1176 -0
  81. package/src/model/schema.js +15 -15
  82. package/src/model/selection.d.ts +472 -0
  83. package/src/model/text.d.ts +66 -0
  84. package/src/model/text.js +0 -2
  85. package/src/model/textproxy.d.ts +144 -0
  86. package/src/model/treewalker.d.ts +186 -0
  87. package/src/model/treewalker.js +19 -10
  88. package/src/model/typecheckable.d.ts +255 -0
  89. package/src/model/utils/autoparagraphing.d.ts +37 -0
  90. package/src/model/utils/deletecontent.d.ts +58 -0
  91. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  92. package/src/model/utils/getselectedcontent.d.ts +30 -0
  93. package/src/model/utils/insertcontent.d.ts +46 -0
  94. package/src/model/utils/insertcontent.js +2 -12
  95. package/src/model/utils/insertobject.d.ts +44 -0
  96. package/src/model/utils/insertobject.js +3 -14
  97. package/src/model/utils/modifyselection.d.ts +48 -0
  98. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  99. package/src/model/writer.d.ts +726 -0
  100. package/src/model/writer.js +6 -4
  101. package/src/view/attributeelement.d.ts +108 -0
  102. package/src/view/attributeelement.js +25 -69
  103. package/src/view/containerelement.d.ts +49 -0
  104. package/src/view/containerelement.js +10 -43
  105. package/src/view/datatransfer.d.ts +75 -0
  106. package/src/view/document.d.ts +184 -0
  107. package/src/view/document.js +15 -84
  108. package/src/view/documentfragment.d.ts +150 -0
  109. package/src/view/documentfragment.js +40 -81
  110. package/src/view/documentselection.d.ts +219 -0
  111. package/src/view/documentselection.js +75 -121
  112. package/src/view/domconverter.d.ts +620 -0
  113. package/src/view/domconverter.js +159 -276
  114. package/src/view/downcastwriter.d.ts +804 -0
  115. package/src/view/downcastwriter.js +336 -380
  116. package/src/view/editableelement.d.ts +52 -0
  117. package/src/view/editableelement.js +9 -49
  118. package/src/view/element.d.ts +466 -0
  119. package/src/view/element.js +150 -222
  120. package/src/view/elementdefinition.d.ts +87 -0
  121. package/src/view/emptyelement.d.ts +41 -0
  122. package/src/view/emptyelement.js +11 -44
  123. package/src/view/filler.d.ts +111 -0
  124. package/src/view/filler.js +24 -21
  125. package/src/view/item.d.ts +14 -0
  126. package/src/view/matcher.d.ts +486 -0
  127. package/src/view/matcher.js +247 -218
  128. package/src/view/node.d.ts +160 -0
  129. package/src/view/node.js +26 -100
  130. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  131. package/src/view/observer/arrowkeysobserver.js +0 -13
  132. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  133. package/src/view/observer/bubblingemittermixin.js +36 -25
  134. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  135. package/src/view/observer/bubblingeventinfo.js +3 -29
  136. package/src/view/observer/clickobserver.d.ts +43 -0
  137. package/src/view/observer/clickobserver.js +9 -19
  138. package/src/view/observer/compositionobserver.d.ts +82 -0
  139. package/src/view/observer/compositionobserver.js +13 -42
  140. package/src/view/observer/domeventdata.d.ts +50 -0
  141. package/src/view/observer/domeventdata.js +5 -30
  142. package/src/view/observer/domeventobserver.d.ts +69 -0
  143. package/src/view/observer/domeventobserver.js +19 -21
  144. package/src/view/observer/fakeselectionobserver.d.ts +46 -0
  145. package/src/view/observer/fakeselectionobserver.js +2 -15
  146. package/src/view/observer/focusobserver.d.ts +82 -0
  147. package/src/view/observer/focusobserver.js +14 -40
  148. package/src/view/observer/inputobserver.d.ts +86 -0
  149. package/src/view/observer/inputobserver.js +18 -64
  150. package/src/view/observer/keyobserver.d.ts +67 -0
  151. package/src/view/observer/keyobserver.js +8 -42
  152. package/src/view/observer/mouseobserver.d.ts +89 -0
  153. package/src/view/observer/mouseobserver.js +8 -28
  154. package/src/view/observer/mutationobserver.d.ts +82 -0
  155. package/src/view/observer/mutationobserver.js +7 -37
  156. package/src/view/observer/observer.d.ts +84 -0
  157. package/src/view/observer/observer.js +12 -25
  158. package/src/view/observer/selectionobserver.d.ts +143 -0
  159. package/src/view/observer/selectionobserver.js +9 -99
  160. package/src/view/observer/tabobserver.d.ts +42 -0
  161. package/src/view/observer/tabobserver.js +0 -14
  162. package/src/view/placeholder.d.ts +85 -0
  163. package/src/view/placeholder.js +26 -43
  164. package/src/view/position.d.ts +189 -0
  165. package/src/view/position.js +36 -83
  166. package/src/view/range.d.ts +279 -0
  167. package/src/view/range.js +79 -122
  168. package/src/view/rawelement.d.ts +73 -0
  169. package/src/view/rawelement.js +34 -48
  170. package/src/view/renderer.d.ts +265 -0
  171. package/src/view/renderer.js +105 -193
  172. package/src/view/rooteditableelement.d.ts +41 -0
  173. package/src/view/rooteditableelement.js +12 -40
  174. package/src/view/selection.d.ts +375 -0
  175. package/src/view/selection.js +79 -153
  176. package/src/view/styles/background.d.ts +33 -0
  177. package/src/view/styles/background.js +14 -12
  178. package/src/view/styles/border.d.ts +43 -0
  179. package/src/view/styles/border.js +58 -48
  180. package/src/view/styles/margin.d.ts +29 -0
  181. package/src/view/styles/margin.js +13 -11
  182. package/src/view/styles/padding.d.ts +29 -0
  183. package/src/view/styles/padding.js +13 -11
  184. package/src/view/styles/utils.d.ts +93 -0
  185. package/src/view/styles/utils.js +22 -48
  186. package/src/view/stylesmap.d.ts +675 -0
  187. package/src/view/stylesmap.js +249 -244
  188. package/src/view/text.d.ts +74 -0
  189. package/src/view/text.js +16 -46
  190. package/src/view/textproxy.d.ts +97 -0
  191. package/src/view/textproxy.js +10 -59
  192. package/src/view/treewalker.d.ts +195 -0
  193. package/src/view/treewalker.js +43 -106
  194. package/src/view/typecheckable.d.ts +401 -0
  195. package/src/view/uielement.d.ts +96 -0
  196. package/src/view/uielement.js +28 -62
  197. package/src/view/upcastwriter.d.ts +328 -0
  198. package/src/view/upcastwriter.js +124 -134
  199. package/src/view/view.d.ts +327 -0
  200. package/src/view/view.js +79 -150
package/src/view/range.js CHANGED
@@ -23,24 +23,12 @@ export default class Range extends TypeCheckable {
23
23
  *
24
24
  * **Note:** Constructor creates it's own {@link module:engine/view/position~Position} instances basing on passed values.
25
25
  *
26
- * @param {module:engine/view/position~Position} start Start position.
27
- * @param {module:engine/view/position~Position} [end] End position. If not set, range will be collapsed at the `start` position.
26
+ * @param start Start position.
27
+ * @param end End position. If not set, range will be collapsed at the `start` position.
28
28
  */
29
29
  constructor(start, end = null) {
30
30
  super();
31
- /**
32
- * Start position.
33
- *
34
- * @readonly
35
- * @member {module:engine/view/position~Position}
36
- */
37
31
  this.start = start.clone();
38
- /**
39
- * End position.
40
- *
41
- * @readonly
42
- * @member {module:engine/view/position~Position}
43
- */
44
32
  this.end = end ? end.clone() : start.clone();
45
33
  }
46
34
  /**
@@ -53,16 +41,12 @@ export default class Range extends TypeCheckable {
53
41
  * This iterator uses {@link module:engine/view/treewalker~TreeWalker TreeWalker} with `boundaries` set to this range and
54
42
  * `ignoreElementEnd` option
55
43
  * set to `true`.
56
- *
57
- * @returns {Iterable.<module:engine/view/treewalker~TreeWalkerValue>}
58
44
  */
59
45
  *[Symbol.iterator]() {
60
46
  yield* new TreeWalker({ boundaries: this, ignoreElementEnd: true });
61
47
  }
62
48
  /**
63
49
  * Returns whether the range is collapsed, that is it start and end positions are equal.
64
- *
65
- * @type {Boolean}
66
50
  */
67
51
  get isCollapsed() {
68
52
  return this.start.isEqual(this.end);
@@ -70,16 +54,12 @@ export default class Range extends TypeCheckable {
70
54
  /**
71
55
  * Returns whether this range is flat, that is if {@link module:engine/view/range~Range#start start} position and
72
56
  * {@link module:engine/view/range~Range#end end} position are in the same {@link module:engine/view/position~Position#parent parent}.
73
- *
74
- * @type {Boolean}
75
57
  */
76
58
  get isFlat() {
77
59
  return this.start.parent === this.end.parent;
78
60
  }
79
61
  /**
80
62
  * Range root element.
81
- *
82
- * @type {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment}
83
63
  */
84
64
  get root() {
85
65
  return this.start.root;
@@ -90,8 +70,10 @@ export default class Range extends TypeCheckable {
90
70
  *
91
71
  * For example:
92
72
  *
93
- * <p>Foo</p><p><b>{Bar}</b></p> -> <p>Foo</p>[<p><b>Bar</b>]</p>
94
- * <p><b>foo</b>{bar}<span></span></p> -> <p><b>foo[</b>bar<span></span>]</p>
73
+ * ```html
74
+ * <p>Foo</p><p><b>{Bar}</b></p> -> <p>Foo</p>[<p><b>Bar</b>]</p>
75
+ * <p><b>foo</b>{bar}<span></span></p> -> <p><b>foo[</b>bar<span></span>]</p>
76
+ * ```
95
77
  *
96
78
  * Note that in the sample above:
97
79
  *
@@ -99,7 +81,7 @@ export default class Range extends TypeCheckable {
99
81
  * - `<b>` have type of {@link module:engine/view/attributeelement~AttributeElement},
100
82
  * - `<span>` have type of {@link module:engine/view/uielement~UIElement}.
101
83
  *
102
- * @returns {module:engine/view/range~Range} Enlarged range.
84
+ * @returns Enlarged range.
103
85
  */
104
86
  getEnlarged() {
105
87
  let start = this.start.getLastMatchingPosition(enlargeTrimSkip, { direction: 'backward' });
@@ -119,8 +101,10 @@ export default class Range extends TypeCheckable {
119
101
  *
120
102
  * For example:
121
103
  *
122
- * <p>Foo</p>[<p><b>Bar</b>]</p> -> <p>Foo</p><p><b>{Bar}</b></p>
123
- * <p><b>foo[</b>bar<span></span>]</p> -> <p><b>foo</b>{bar}<span></span></p>
104
+ * ```html
105
+ * <p>Foo</p>[<p><b>Bar</b>]</p> -> <p>Foo</p><p><b>{Bar}</b></p>
106
+ * <p><b>foo[</b>bar<span></span>]</p> -> <p><b>foo</b>{bar}<span></span></p>
107
+ * ```
124
108
  *
125
109
  * Note that in the sample above:
126
110
  *
@@ -128,7 +112,7 @@ export default class Range extends TypeCheckable {
128
112
  * - `<b>` have type of {@link module:engine/view/attributeelement~AttributeElement},
129
113
  * - `<span>` have type of {@link module:engine/view/uielement~UIElement}.
130
114
  *
131
- * @returns {module:engine/view/range~Range} Shrink range.
115
+ * @returns Shrunk range.
132
116
  */
133
117
  getTrimmed() {
134
118
  let start = this.start.getLastMatchingPosition(enlargeTrimSkip);
@@ -150,8 +134,8 @@ export default class Range extends TypeCheckable {
150
134
  /**
151
135
  * Two ranges are equal if their start and end positions are equal.
152
136
  *
153
- * @param {module:engine/view/range~Range} otherRange Range to compare with.
154
- * @returns {Boolean} `true` if ranges are equal, `false` otherwise
137
+ * @param otherRange Range to compare with.
138
+ * @returns `true` if ranges are equal, `false` otherwise
155
139
  */
156
140
  isEqual(otherRange) {
157
141
  return this == otherRange || (this.start.isEqual(otherRange.start) && this.end.isEqual(otherRange.end));
@@ -159,9 +143,8 @@ export default class Range extends TypeCheckable {
159
143
  /**
160
144
  * Checks whether this range contains given {@link module:engine/view/position~Position position}.
161
145
  *
162
- * @param {module:engine/view/position~Position} position Position to check.
163
- * @returns {Boolean} `true` if given {@link module:engine/view/position~Position position} is contained in this range,
164
- * `false` otherwise.
146
+ * @param position Position to check.
147
+ * @returns `true` if given {@link module:engine/view/position~Position position} is contained in this range, `false` otherwise.
165
148
  */
166
149
  containsPosition(position) {
167
150
  return position.isAfter(this.start) && position.isBefore(this.end);
@@ -169,11 +152,11 @@ export default class Range extends TypeCheckable {
169
152
  /**
170
153
  * Checks whether this range contains given {@link module:engine/view/range~Range range}.
171
154
  *
172
- * @param {module:engine/view/range~Range} otherRange Range to check.
173
- * @param {Boolean} [loose=false] Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
155
+ * @param otherRange Range to check.
156
+ * @param loose Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
174
157
  * start or end at the same position as this range boundaries. If the check is loose (`true`), compared range can start, end or
175
158
  * even be equal to this range. Note that collapsed ranges are always compared in strict mode.
176
- * @returns {Boolean} `true` if given {@link module:engine/view/range~Range range} boundaries are contained by this range, `false`
159
+ * @returns `true` if given {@link module:engine/view/range~Range range} boundaries are contained by this range, `false`
177
160
  * otherwise.
178
161
  */
179
162
  containsRange(otherRange, loose = false) {
@@ -191,29 +174,31 @@ export default class Range extends TypeCheckable {
191
174
  *
192
175
  * Examples:
193
176
  *
194
- * let foo = downcastWriter.createText( 'foo' );
195
- * let img = downcastWriter.createContainerElement( 'img' );
196
- * let bar = downcastWriter.createText( 'bar' );
197
- * let p = downcastWriter.createContainerElement( 'p', null, [ foo, img, bar ] );
198
- *
199
- * let range = view.createRange( view.createPositionAt( foo, 2 ), view.createPositionAt( bar, 1 ); // "o", img, "b" are in range.
200
- * let otherRange = view.createRange( // "oo", img, "ba" are in range.
201
- * view.createPositionAt( foo, 1 ),
202
- * view.createPositionAt( bar, 2 )
203
- * );
204
- * let transformed = range.getDifference( otherRange );
205
- * // transformed array has no ranges because `otherRange` contains `range`
206
- *
207
- * otherRange = view.createRange( view.createPositionAt( foo, 1 ), view.createPositionAt( p, 2 ); // "oo", img are in range.
208
- * transformed = range.getDifference( otherRange );
209
- * // transformed array has one range: from ( p, 2 ) to ( bar, 1 )
210
- *
211
- * otherRange = view.createRange( view.createPositionAt( p, 1 ), view.createPositionAt( p, 2 ) ); // img is in range.
212
- * transformed = range.getDifference( otherRange );
213
- * // transformed array has two ranges: from ( foo, 1 ) to ( p, 1 ) and from ( p, 2 ) to ( bar, 1 )
214
- *
215
- * @param {module:engine/view/range~Range} otherRange Range to differentiate against.
216
- * @returns {Array.<module:engine/view/range~Range>} The difference between ranges.
177
+ * ```ts
178
+ * let foo = downcastWriter.createText( 'foo' );
179
+ * let img = downcastWriter.createContainerElement( 'img' );
180
+ * let bar = downcastWriter.createText( 'bar' );
181
+ * let p = downcastWriter.createContainerElement( 'p', null, [ foo, img, bar ] );
182
+ *
183
+ * let range = view.createRange( view.createPositionAt( foo, 2 ), view.createPositionAt( bar, 1 ); // "o", img, "b" are in range.
184
+ * let otherRange = view.createRange( // "oo", img, "ba" are in range.
185
+ * view.createPositionAt( foo, 1 ),
186
+ * view.createPositionAt( bar, 2 )
187
+ * );
188
+ * let transformed = range.getDifference( otherRange );
189
+ * // transformed array has no ranges because `otherRange` contains `range`
190
+ *
191
+ * otherRange = view.createRange( view.createPositionAt( foo, 1 ), view.createPositionAt( p, 2 ); // "oo", img are in range.
192
+ * transformed = range.getDifference( otherRange );
193
+ * // transformed array has one range: from ( p, 2 ) to ( bar, 1 )
194
+ *
195
+ * otherRange = view.createRange( view.createPositionAt( p, 1 ), view.createPositionAt( p, 2 ) ); // img is in range.
196
+ * transformed = range.getDifference( otherRange );
197
+ * // transformed array has two ranges: from ( foo, 1 ) to ( p, 1 ) and from ( p, 2 ) to ( bar, 1 )
198
+ * ```
199
+ *
200
+ * @param otherRange Range to differentiate against.
201
+ * @returns The difference between ranges.
217
202
  */
218
203
  getDifference(otherRange) {
219
204
  const ranges = [];
@@ -242,20 +227,22 @@ export default class Range extends TypeCheckable {
242
227
  *
243
228
  * Examples:
244
229
  *
245
- * let foo = downcastWriter.createText( 'foo' );
246
- * let img = downcastWriter.createContainerElement( 'img' );
247
- * let bar = downcastWriter.createText( 'bar' );
248
- * let p = downcastWriter.createContainerElement( 'p', null, [ foo, img, bar ] );
230
+ * ```ts
231
+ * let foo = downcastWriter.createText( 'foo' );
232
+ * let img = downcastWriter.createContainerElement( 'img' );
233
+ * let bar = downcastWriter.createText( 'bar' );
234
+ * let p = downcastWriter.createContainerElement( 'p', null, [ foo, img, bar ] );
249
235
  *
250
- * let range = view.createRange( view.createPositionAt( foo, 2 ), view.createPositionAt( bar, 1 ); // "o", img, "b" are in range.
251
- * let otherRange = view.createRange( view.createPositionAt( foo, 1 ), view.createPositionAt( p, 2 ); // "oo", img are in range.
252
- * let transformed = range.getIntersection( otherRange ); // range from ( foo, 1 ) to ( p, 2 ).
236
+ * let range = view.createRange( view.createPositionAt( foo, 2 ), view.createPositionAt( bar, 1 ); // "o", img, "b" are in range.
237
+ * let otherRange = view.createRange( view.createPositionAt( foo, 1 ), view.createPositionAt( p, 2 ); // "oo", img are in range.
238
+ * let transformed = range.getIntersection( otherRange ); // range from ( foo, 1 ) to ( p, 2 ).
253
239
  *
254
- * otherRange = view.createRange( view.createPositionAt( bar, 1 ), view.createPositionAt( bar, 3 ); "ar" is in range.
255
- * transformed = range.getIntersection( otherRange ); // null - no common part.
240
+ * otherRange = view.createRange( view.createPositionAt( bar, 1 ), view.createPositionAt( bar, 3 ); "ar" is in range.
241
+ * transformed = range.getIntersection( otherRange ); // null - no common part.
242
+ * ```
256
243
  *
257
- * @param {module:engine/view/range~Range} otherRange Range to check for intersection.
258
- * @returns {module:engine/view/range~Range|null} A common part of given ranges or `null` if ranges have no common part.
244
+ * @param otherRange Range to check for intersection.
245
+ * @returns A common part of given ranges or `null` if ranges have no common part.
259
246
  */
260
247
  getIntersection(otherRange) {
261
248
  if (this.isIntersecting(otherRange)) {
@@ -281,12 +268,7 @@ export default class Range extends TypeCheckable {
281
268
  /**
282
269
  * Creates a {@link module:engine/view/treewalker~TreeWalker TreeWalker} instance with this range as a boundary.
283
270
  *
284
- * @param {Object} options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
285
- * @param {module:engine/view/position~Position} [options.startPosition]
286
- * @param {Boolean} [options.singleCharacters=false]
287
- * @param {Boolean} [options.shallow=false]
288
- * @param {Boolean} [options.ignoreElementEnd=false]
289
- * @returns {module:engine/view/treewalker~TreeWalker}
271
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
290
272
  */
291
273
  getWalker(options = {}) {
292
274
  options.boundaries = this;
@@ -295,8 +277,6 @@ export default class Range extends TypeCheckable {
295
277
  /**
296
278
  * Returns a {@link module:engine/view/node~Node} or {@link module:engine/view/documentfragment~DocumentFragment}
297
279
  * which is a common ancestor of range's both ends (in which the entire range is contained).
298
- *
299
- * @returns {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment|null}
300
280
  */
301
281
  getCommonAncestor() {
302
282
  return this.start.getCommonAncestor(this.end);
@@ -305,8 +285,6 @@ export default class Range extends TypeCheckable {
305
285
  * Returns an {@link module:engine/view/element~Element Element} contained by the range.
306
286
  * The element will be returned when it is the **only** node within the range and **fully–contained**
307
287
  * at the same time.
308
- *
309
- * @returns {module:engine/view/element~Element|null}
310
288
  */
311
289
  getContainedElement() {
312
290
  if (this.isCollapsed) {
@@ -336,8 +314,6 @@ export default class Range extends TypeCheckable {
336
314
  }
337
315
  /**
338
316
  * Clones this range.
339
- *
340
- * @returns {module:engine/view/range~Range}
341
317
  */
342
318
  clone() {
343
319
  return new Range(this.start, this.end);
@@ -353,8 +329,7 @@ export default class Range extends TypeCheckable {
353
329
  * You may specify additional options for the tree walker. See {@link module:engine/view/treewalker~TreeWalker} for
354
330
  * a full list of available options.
355
331
  *
356
- * @param {Object} options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
357
- * @returns {Iterable.<module:engine/view/item~Item>}
332
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
358
333
  */
359
334
  *getItems(options = {}) {
360
335
  options.boundaries = this;
@@ -374,8 +349,7 @@ export default class Range extends TypeCheckable {
374
349
  * You may specify additional options for the tree walker. See {@link module:engine/view/treewalker~TreeWalker} for
375
350
  * a full list of available options.
376
351
  *
377
- * @param {Object} options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
378
- * @returns {Iterable.<module:engine/view/position~Position>}
352
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
379
353
  */
380
354
  *getPositions(options = {}) {
381
355
  options.boundaries = this;
@@ -388,8 +362,8 @@ export default class Range extends TypeCheckable {
388
362
  /**
389
363
  * Checks and returns whether this range intersects with the given range.
390
364
  *
391
- * @param {module:engine/view/range~Range} otherRange Range to compare with.
392
- * @returns {Boolean} True if ranges intersect.
365
+ * @param otherRange Range to compare with.
366
+ * @returns True if ranges intersect.
393
367
  */
394
368
  isIntersecting(otherRange) {
395
369
  return this.start.isBefore(otherRange.end) && this.end.isAfter(otherRange.start);
@@ -397,14 +371,12 @@ export default class Range extends TypeCheckable {
397
371
  /**
398
372
  * Creates a range from the given parents and offsets.
399
373
  *
400
- * @protected
401
- * @param {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment} startElement Start position
402
- * parent element.
403
- * @param {Number} startOffset Start position offset.
404
- * @param {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment} endElement End position
405
- * parent element.
406
- * @param {Number} endOffset End position offset.
407
- * @returns {module:engine/view/range~Range} Created range.
374
+ * @internal
375
+ * @param startElement Start position parent element.
376
+ * @param startOffset Start position offset.
377
+ * @param endElement End position parent element.
378
+ * @param endOffset End position offset.
379
+ * @returns Created range.
408
380
  */
409
381
  static _createFromParentsAndOffsets(startElement, startOffset, endElement, endOffset) {
410
382
  return new this(new Position(startElement, startOffset), new Position(endElement, endOffset));
@@ -413,10 +385,9 @@ export default class Range extends TypeCheckable {
413
385
  * Creates a new range, spreading from specified {@link module:engine/view/position~Position position} to a position moved by
414
386
  * given `shift`. If `shift` is a negative value, shifted position is treated as the beginning of the range.
415
387
  *
416
- * @protected
417
- * @param {module:engine/view/position~Position} position Beginning of the range.
418
- * @param {Number} shift How long the range should be.
419
- * @returns {module:engine/view/range~Range}
388
+ * @internal
389
+ * @param position Beginning of the range.
390
+ * @param shift How long the range should be.
420
391
  */
421
392
  static _createFromPositionAndShift(position, shift) {
422
393
  const start = position;
@@ -427,9 +398,8 @@ export default class Range extends TypeCheckable {
427
398
  * Creates a range inside an {@link module:engine/view/element~Element element} which starts before the first child of
428
399
  * that element and ends after the last child of that element.
429
400
  *
430
- * @protected
431
- * @param {module:engine/view/element~Element} element Element which is a parent for the range.
432
- * @returns {module:engine/view/range~Range}
401
+ * @internal
402
+ * @param element Element which is a parent for the range.
433
403
  */
434
404
  static _createIn(element) {
435
405
  return this._createFromParentsAndOffsets(element, 0, element, element.childCount);
@@ -437,34 +407,21 @@ export default class Range extends TypeCheckable {
437
407
  /**
438
408
  * Creates a range that starts before given {@link module:engine/view/item~Item view item} and ends after it.
439
409
  *
440
- * @protected
441
- * @param {module:engine/view/item~Item} item
442
- * @returns {module:engine/view/range~Range}
410
+ * @internal
443
411
  */
444
412
  static _createOn(item) {
445
413
  const size = item.is('$textProxy') ? item.offsetSize : 1;
446
414
  return this._createFromPositionAndShift(Position._createBefore(item), size);
447
415
  }
448
416
  }
449
- /**
450
- * Checks whether this object is of the given type.
451
- *
452
- * range.is( 'range' ); // -> true
453
- * range.is( 'view:range' ); // -> true
454
- *
455
- * range.is( 'model:range' ); // -> false
456
- * range.is( 'element' ); // -> false
457
- * range.is( 'selection' ); // -> false
458
- *
459
- * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
460
- *
461
- * @param {String} type
462
- * @returns {Boolean}
463
- */
417
+ // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
418
+ // Proper overload would interfere with that.
464
419
  Range.prototype.is = function (type) {
465
420
  return type === 'range' || type === 'view:range';
466
421
  };
467
- // Function used by getEnlarged and getTrimmed methods.
422
+ /**
423
+ * Function used by getEnlarged and getTrimmed methods.
424
+ */
468
425
  function enlargeTrimSkip(value) {
469
426
  if (value.item.is('attributeElement') || value.item.is('uiElement')) {
470
427
  return true;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module engine/view/rawelement
7
+ */
8
+ import Element, { type ElementAttributes } from './element';
9
+ import Node from './node';
10
+ import type Document from './document';
11
+ import type DomConverter from './domconverter';
12
+ import type Item from './item';
13
+ type DomElement = globalThis.HTMLElement;
14
+ /**
15
+ * The raw element class.
16
+ *
17
+ * The raw elements work as data containers ("wrappers", "sandboxes") but their children are not managed or
18
+ * even recognized by the editor. This encapsulation allows integrations to maintain custom DOM structures
19
+ * in the editor content without, for instance, worrying about compatibility with other editor features.
20
+ * Raw elements are a perfect tool for integration with external frameworks and data sources.
21
+ *
22
+ * Unlike {@link module:engine/view/uielement~UIElement UI elements}, raw elements act like real editor
23
+ * content (similar to {@link module:engine/view/containerelement~ContainerElement} or
24
+ * {@link module:engine/view/emptyelement~EmptyElement}), they are considered by the editor selection and
25
+ * {@link module:widget/utils~toWidget they can work as widgets}.
26
+ *
27
+ * To create a new raw element, use the
28
+ * {@link module:engine/view/downcastwriter~DowncastWriter#createRawElement `downcastWriter#createRawElement()`} method.
29
+ */
30
+ export default class RawElement extends Element {
31
+ /**
32
+ * Creates a new instance of a raw element.
33
+ *
34
+ * Throws the `view-rawelement-cannot-add` {@link module:utils/ckeditorerror~CKEditorError CKEditorError} when the `children`
35
+ * parameter is passed to inform that the usage of `RawElement` is incorrect (adding child nodes to `RawElement` is forbidden).
36
+ *
37
+ * @see module:engine/view/downcastwriter~DowncastWriter#createRawElement
38
+ * @internal
39
+ * @param document The document instance to which this element belongs.
40
+ * @param name Node name.
41
+ * @param attrs Collection of attributes.
42
+ * @param children A list of nodes to be inserted into created element.
43
+ */
44
+ constructor(document: Document, name: string, attrs?: ElementAttributes, children?: Node | Iterable<Node>);
45
+ /**
46
+ * Overrides the {@link module:engine/view/element~Element#_insertChild} method.
47
+ * Throws the `view-rawelement-cannot-add` {@link module:utils/ckeditorerror~CKEditorError CKEditorError} to prevent
48
+ * adding any child nodes to a raw element.
49
+ *
50
+ * @internal
51
+ */
52
+ _insertChild(index: number, items: Item | Iterable<Item>): number;
53
+ /**
54
+ * This allows rendering the children of a {@link module:engine/view/rawelement~RawElement} on the DOM level.
55
+ * This method is called by the {@link module:engine/view/domconverter~DomConverter} with the raw DOM element
56
+ * passed as an argument, leaving the number and shape of the children up to the integrator.
57
+ *
58
+ * This method **must be defined** for the raw element to work:
59
+ *
60
+ * ```ts
61
+ * const myRawElement = downcastWriter.createRawElement( 'div' );
62
+ *
63
+ * myRawElement.render = function( domElement, domConverter ) {
64
+ * domConverter.setContentOf( domElement, '<b>This is the raw content of myRawElement.</b>' );
65
+ * };
66
+ * ```
67
+ *
68
+ * @param domElement The native DOM element representing the raw view element.
69
+ * @param domConverter Instance of the DomConverter used to optimize the output.
70
+ */
71
+ render(domElement: DomElement, domConverter: DomConverter): void;
72
+ }
73
+ export {};
@@ -2,6 +2,7 @@
2
2
  * @license Copyright (c) 2003-2023, 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
+ /* eslint-disable @typescript-eslint/no-unused-vars */
5
6
  /**
6
7
  * @module engine/view/rawelement
7
8
  */
@@ -23,8 +24,6 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
23
24
  *
24
25
  * To create a new raw element, use the
25
26
  * {@link module:engine/view/downcastwriter~DowncastWriter#createRawElement `downcastWriter#createRawElement()`} method.
26
- *
27
- * @extends module:engine/view/element~Element
28
27
  */
29
28
  export default class RawElement extends Element {
30
29
  /**
@@ -34,21 +33,15 @@ export default class RawElement extends Element {
34
33
  * parameter is passed to inform that the usage of `RawElement` is incorrect (adding child nodes to `RawElement` is forbidden).
35
34
  *
36
35
  * @see module:engine/view/downcastwriter~DowncastWriter#createRawElement
37
- * @protected
38
- * @param {module:engine/view/document~Document} document The document instance to which this element belongs.
39
- * @param {String} name A node name.
40
- * @param {Object|Iterable} [attrs] The collection of attributes.
41
- * @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children]
42
- * A list of nodes to be inserted into the created element.
36
+ * @internal
37
+ * @param document The document instance to which this element belongs.
38
+ * @param name Node name.
39
+ * @param attrs Collection of attributes.
40
+ * @param children A list of nodes to be inserted into created element.
43
41
  */
44
- constructor(...args) {
45
- super(...args);
46
- /**
47
- * Returns `null` because filler is not needed for raw elements.
48
- *
49
- * @method #getFillerOffset
50
- * @returns {null} Always returns null.
51
- */
42
+ constructor(document, name, attrs, children) {
43
+ super(document, name, attrs, children);
44
+ // Returns `null` because filler is not needed for raw elements.
52
45
  this.getFillerOffset = getFillerOffset;
53
46
  }
54
47
  /**
@@ -56,7 +49,7 @@ export default class RawElement extends Element {
56
49
  * Throws the `view-rawelement-cannot-add` {@link module:utils/ckeditorerror~CKEditorError CKEditorError} to prevent
57
50
  * adding any child nodes to a raw element.
58
51
  *
59
- * @protected
52
+ * @internal
60
53
  */
61
54
  _insertChild(index, items) {
62
55
  if (items && (items instanceof Node || Array.from(items).length > 0)) {
@@ -69,35 +62,28 @@ export default class RawElement extends Element {
69
62
  }
70
63
  return 0;
71
64
  }
72
- render() { }
65
+ /**
66
+ * This allows rendering the children of a {@link module:engine/view/rawelement~RawElement} on the DOM level.
67
+ * This method is called by the {@link module:engine/view/domconverter~DomConverter} with the raw DOM element
68
+ * passed as an argument, leaving the number and shape of the children up to the integrator.
69
+ *
70
+ * This method **must be defined** for the raw element to work:
71
+ *
72
+ * ```ts
73
+ * const myRawElement = downcastWriter.createRawElement( 'div' );
74
+ *
75
+ * myRawElement.render = function( domElement, domConverter ) {
76
+ * domConverter.setContentOf( domElement, '<b>This is the raw content of myRawElement.</b>' );
77
+ * };
78
+ * ```
79
+ *
80
+ * @param domElement The native DOM element representing the raw view element.
81
+ * @param domConverter Instance of the DomConverter used to optimize the output.
82
+ */
83
+ render(domElement, domConverter) { }
73
84
  }
74
- /**
75
- * Checks whether this object is of the given type or name.
76
- *
77
- * rawElement.is( 'rawElement' ); // -> true
78
- * rawElement.is( 'element' ); // -> true
79
- * rawElement.is( 'node' ); // -> true
80
- * rawElement.is( 'view:rawElement' ); // -> true
81
- * rawElement.is( 'view:element' ); // -> true
82
- * rawElement.is( 'view:node' ); // -> true
83
- *
84
- * rawElement.is( 'model:element' ); // -> false
85
- * rawElement.is( 'documentFragment' ); // -> false
86
- *
87
- * Assuming that the object being checked is a raw element, you can also check its
88
- * {@link module:engine/view/rawelement~RawElement#name name}:
89
- *
90
- * rawElement.is( 'img' ); // -> true if this is an img element
91
- * rawElement.is( 'rawElement', 'img' ); // -> same as above
92
- * text.is( 'img' ); -> false
93
- *
94
- * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
95
- *
96
- * @param {String} type The type to check when the `name` parameter is present.
97
- * Otherwise, it acts like the `name` parameter.
98
- * @param {String} [name] The element name.
99
- * @returns {Boolean}
100
- */
85
+ // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
86
+ // Proper overload would interfere with that.
101
87
  RawElement.prototype.is = function (type, name) {
102
88
  if (!name) {
103
89
  return type === 'rawElement' || type === 'view:rawElement' ||
@@ -111,9 +97,9 @@ RawElement.prototype.is = function (type, name) {
111
97
  type === 'element' || type === 'view:element');
112
98
  }
113
99
  };
114
- // Returns `null` because block filler is not needed for raw elements.
115
- //
116
- // @returns {null}
100
+ /**
101
+ * Returns `null` because block filler is not needed for raw elements.
102
+ */
117
103
  function getFillerOffset() {
118
104
  return null;
119
105
  }