@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.1

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 (203) hide show
  1. package/README.md +1 -1
  2. package/package.json +25 -24
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +72 -116
  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 +503 -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 +369 -0
  24. package/src/conversion/viewconsumable.js +139 -173
  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 +108 -0
  42. package/src/index.js +4 -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 +246 -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 +885 -0
  57. package/src/model/model.js +59 -81
  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/mergeoperation.js +1 -1
  66. package/src/model/operation/moveoperation.d.ts +91 -0
  67. package/src/model/operation/nooperation.d.ts +33 -0
  68. package/src/model/operation/operation.d.ts +89 -0
  69. package/src/model/operation/operationfactory.d.ts +18 -0
  70. package/src/model/operation/renameoperation.d.ts +78 -0
  71. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  72. package/src/model/operation/rootattributeoperation.js +1 -1
  73. package/src/model/operation/splitoperation.d.ts +104 -0
  74. package/src/model/operation/splitoperation.js +1 -1
  75. package/src/model/operation/transform.d.ts +100 -0
  76. package/src/model/operation/utils.d.ts +71 -0
  77. package/src/model/operation/utils.js +1 -1
  78. package/src/model/position.d.ts +539 -0
  79. package/src/model/position.js +1 -1
  80. package/src/model/range.d.ts +458 -0
  81. package/src/model/range.js +1 -1
  82. package/src/model/rootelement.d.ts +40 -0
  83. package/src/model/schema.d.ts +1176 -0
  84. package/src/model/schema.js +19 -19
  85. package/src/model/selection.d.ts +472 -0
  86. package/src/model/text.d.ts +66 -0
  87. package/src/model/text.js +0 -2
  88. package/src/model/textproxy.d.ts +144 -0
  89. package/src/model/treewalker.d.ts +186 -0
  90. package/src/model/treewalker.js +19 -10
  91. package/src/model/typecheckable.d.ts +285 -0
  92. package/src/model/utils/autoparagraphing.d.ts +37 -0
  93. package/src/model/utils/deletecontent.d.ts +58 -0
  94. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  95. package/src/model/utils/getselectedcontent.d.ts +30 -0
  96. package/src/model/utils/insertcontent.d.ts +46 -0
  97. package/src/model/utils/insertcontent.js +2 -12
  98. package/src/model/utils/insertobject.d.ts +44 -0
  99. package/src/model/utils/insertobject.js +3 -14
  100. package/src/model/utils/modifyselection.d.ts +48 -0
  101. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  102. package/src/model/writer.d.ts +823 -0
  103. package/src/model/writer.js +6 -61
  104. package/src/view/attributeelement.d.ts +108 -0
  105. package/src/view/attributeelement.js +25 -69
  106. package/src/view/containerelement.d.ts +49 -0
  107. package/src/view/containerelement.js +10 -43
  108. package/src/view/datatransfer.d.ts +75 -0
  109. package/src/view/document.d.ts +184 -0
  110. package/src/view/document.js +15 -84
  111. package/src/view/documentfragment.d.ts +149 -0
  112. package/src/view/documentfragment.js +39 -81
  113. package/src/view/documentselection.d.ts +306 -0
  114. package/src/view/documentselection.js +42 -143
  115. package/src/view/domconverter.d.ts +650 -0
  116. package/src/view/domconverter.js +157 -283
  117. package/src/view/downcastwriter.d.ts +996 -0
  118. package/src/view/downcastwriter.js +259 -426
  119. package/src/view/editableelement.d.ts +52 -0
  120. package/src/view/editableelement.js +9 -49
  121. package/src/view/element.d.ts +468 -0
  122. package/src/view/element.js +150 -222
  123. package/src/view/elementdefinition.d.ts +87 -0
  124. package/src/view/emptyelement.d.ts +41 -0
  125. package/src/view/emptyelement.js +11 -44
  126. package/src/view/filler.d.ts +111 -0
  127. package/src/view/filler.js +24 -21
  128. package/src/view/item.d.ts +14 -0
  129. package/src/view/matcher.d.ts +486 -0
  130. package/src/view/matcher.js +247 -218
  131. package/src/view/node.d.ts +163 -0
  132. package/src/view/node.js +26 -100
  133. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  134. package/src/view/observer/arrowkeysobserver.js +0 -13
  135. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  136. package/src/view/observer/bubblingemittermixin.js +36 -25
  137. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  138. package/src/view/observer/bubblingeventinfo.js +3 -29
  139. package/src/view/observer/clickobserver.d.ts +43 -0
  140. package/src/view/observer/clickobserver.js +9 -19
  141. package/src/view/observer/compositionobserver.d.ts +82 -0
  142. package/src/view/observer/compositionobserver.js +13 -42
  143. package/src/view/observer/domeventdata.d.ts +50 -0
  144. package/src/view/observer/domeventdata.js +5 -30
  145. package/src/view/observer/domeventobserver.d.ts +69 -0
  146. package/src/view/observer/domeventobserver.js +19 -21
  147. package/src/view/observer/fakeselectionobserver.d.ts +43 -0
  148. package/src/view/observer/fakeselectionobserver.js +0 -16
  149. package/src/view/observer/focusobserver.d.ts +82 -0
  150. package/src/view/observer/focusobserver.js +14 -40
  151. package/src/view/observer/inputobserver.d.ts +86 -0
  152. package/src/view/observer/inputobserver.js +18 -64
  153. package/src/view/observer/keyobserver.d.ts +66 -0
  154. package/src/view/observer/keyobserver.js +8 -42
  155. package/src/view/observer/mouseobserver.d.ts +89 -0
  156. package/src/view/observer/mouseobserver.js +8 -28
  157. package/src/view/observer/mutationobserver.d.ts +82 -0
  158. package/src/view/observer/mutationobserver.js +7 -37
  159. package/src/view/observer/observer.d.ts +84 -0
  160. package/src/view/observer/observer.js +12 -25
  161. package/src/view/observer/selectionobserver.d.ts +144 -0
  162. package/src/view/observer/selectionobserver.js +17 -107
  163. package/src/view/observer/tabobserver.d.ts +42 -0
  164. package/src/view/observer/tabobserver.js +0 -14
  165. package/src/view/placeholder.d.ts +85 -0
  166. package/src/view/placeholder.js +26 -43
  167. package/src/view/position.d.ts +189 -0
  168. package/src/view/position.js +36 -83
  169. package/src/view/range.d.ts +279 -0
  170. package/src/view/range.js +79 -122
  171. package/src/view/rawelement.d.ts +73 -0
  172. package/src/view/rawelement.js +34 -48
  173. package/src/view/renderer.d.ts +265 -0
  174. package/src/view/renderer.js +105 -193
  175. package/src/view/rooteditableelement.d.ts +41 -0
  176. package/src/view/rooteditableelement.js +12 -40
  177. package/src/view/selection.d.ts +375 -0
  178. package/src/view/selection.js +79 -153
  179. package/src/view/styles/background.d.ts +33 -0
  180. package/src/view/styles/background.js +14 -12
  181. package/src/view/styles/border.d.ts +43 -0
  182. package/src/view/styles/border.js +58 -48
  183. package/src/view/styles/margin.d.ts +29 -0
  184. package/src/view/styles/margin.js +13 -11
  185. package/src/view/styles/padding.d.ts +29 -0
  186. package/src/view/styles/padding.js +13 -11
  187. package/src/view/styles/utils.d.ts +93 -0
  188. package/src/view/styles/utils.js +22 -48
  189. package/src/view/stylesmap.d.ts +675 -0
  190. package/src/view/stylesmap.js +249 -244
  191. package/src/view/text.d.ts +74 -0
  192. package/src/view/text.js +16 -46
  193. package/src/view/textproxy.d.ts +97 -0
  194. package/src/view/textproxy.js +10 -59
  195. package/src/view/treewalker.d.ts +195 -0
  196. package/src/view/treewalker.js +43 -106
  197. package/src/view/typecheckable.d.ts +448 -0
  198. package/src/view/uielement.d.ts +96 -0
  199. package/src/view/uielement.js +29 -63
  200. package/src/view/upcastwriter.d.ts +417 -0
  201. package/src/view/upcastwriter.js +86 -157
  202. package/src/view/view.d.ts +417 -0
  203. package/src/view/view.js +47 -175
@@ -0,0 +1,285 @@
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/model/typecheckable
7
+ */
8
+ import type { Marker } from './markercollection';
9
+ import type DocumentFragment from './documentfragment';
10
+ import type DocumentSelection from './documentselection';
11
+ import type Element from './element';
12
+ import type LivePosition from './liveposition';
13
+ import type LiveRange from './liverange';
14
+ import type Node from './node';
15
+ import type Position from './position';
16
+ import type Range from './range';
17
+ import type RootElement from './rootelement';
18
+ import type Selection from './selection';
19
+ import type Text from './text';
20
+ import type TextProxy from './textproxy';
21
+ export default abstract class TypeCheckable {
22
+ /**
23
+ * Checks whether the object is of type {@link module:engine/model/node~Node} or its subclass.
24
+ *
25
+ * This method is useful when processing model objects that are of unknown type. For example, a function
26
+ * may return a {@link module:engine/model/documentfragment~DocumentFragment} or a {@link module:engine/model/node~Node}
27
+ * that can be either a text node or an element. This method can be used to check what kind of object is returned.
28
+ *
29
+ * ```ts
30
+ * someObject.is( 'element' ); // -> true if this is an element
31
+ * someObject.is( 'node' ); // -> true if this is a node (a text node or an element)
32
+ * someObject.is( 'documentFragment' ); // -> true if this is a document fragment
33
+ * ```
34
+ *
35
+ * Since this method is also available on a range of view objects, you can prefix the type of the object with
36
+ * `model:` or `view:` to check, for example, if this is the model's or view's element:
37
+ *
38
+ * ```ts
39
+ * modelElement.is( 'model:element' ); // -> true
40
+ * modelElement.is( 'view:element' ); // -> false
41
+ * ```
42
+ *
43
+ * By using this method it is also possible to check a name of an element:
44
+ *
45
+ * ```ts
46
+ * imageElement.is( 'element', 'imageBlock' ); // -> true
47
+ * imageElement.is( 'element', 'imageBlock' ); // -> same as above
48
+ * imageElement.is( 'model:element', 'imageBlock' ); // -> same as above, but more precise
49
+ * ```
50
+ *
51
+ * @label NODE
52
+ */
53
+ is(type: 'node' | 'model:node'): this is Node | Element | Text | RootElement;
54
+ /**
55
+ * Checks whether the object is of type {@link module:engine/model/element~Element} or its subclass.
56
+ *
57
+ * ```ts
58
+ * element.is( 'element' ); // -> true
59
+ * element.is( 'node' ); // -> true
60
+ * element.is( 'model:element' ); // -> true
61
+ * element.is( 'model:node' ); // -> true
62
+ *
63
+ * element.is( 'view:element' ); // -> false
64
+ * element.is( 'documentSelection' ); // -> false
65
+ * ```
66
+ *
67
+ * Assuming that the object being checked is an element, you can also check its
68
+ * {@link module:engine/model/element~Element#name name}:
69
+ *
70
+ * ```ts
71
+ * element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element
72
+ * text.is( 'element', 'imageBlock' ); -> false
73
+ * ```
74
+ *
75
+ * @label ELEMENT
76
+ */
77
+ is(type: 'element' | 'model:element'): this is Element | RootElement;
78
+ /**
79
+ * Checks whether the object is of type {@link module:engine/model/rootelement~RootElement}.
80
+ *
81
+ * ```ts
82
+ * rootElement.is( 'rootElement' ); // -> true
83
+ * rootElement.is( 'element' ); // -> true
84
+ * rootElement.is( 'node' ); // -> true
85
+ * rootElement.is( 'model:rootElement' ); // -> true
86
+ * rootElement.is( 'model:element' ); // -> true
87
+ * rootElement.is( 'model:node' ); // -> true
88
+ *
89
+ * rootElement.is( 'view:element' ); // -> false
90
+ * rootElement.is( 'documentFragment' ); // -> false
91
+ * ```
92
+ *
93
+ * Assuming that the object being checked is an element, you can also check its
94
+ * {@link module:engine/model/element~Element#name name}:
95
+ *
96
+ * ```ts
97
+ * rootElement.is( 'rootElement', '$root' ); // -> same as above
98
+ * ```
99
+ *
100
+ * @label ROOT_ELEMENT
101
+ */
102
+ is(type: 'rootElement' | 'model:rootElement'): this is RootElement;
103
+ /**
104
+ * Checks whether the object is of type {@link module:engine/model/text~Text}.
105
+ *
106
+ * ```ts
107
+ * text.is( '$text' ); // -> true
108
+ * text.is( 'node' ); // -> true
109
+ * text.is( 'model:$text' ); // -> true
110
+ * text.is( 'model:node' ); // -> true
111
+ *
112
+ * text.is( 'view:$text' ); // -> false
113
+ * text.is( 'documentSelection' ); // -> false
114
+ * ```
115
+ *
116
+ * **Note:** Until version 20.0.0 this method wasn't accepting `'$text'` type. The legacy `'text'` type is still
117
+ * accepted for backward compatibility.
118
+ *
119
+ * @label TEXT
120
+ */
121
+ is(type: '$text' | 'model:$text'): this is Text;
122
+ /**
123
+ * Checks whether the object is of type {@link module:engine/model/position~Position} or its subclass.
124
+ *
125
+ * ```ts
126
+ * position.is( 'position' ); // -> true
127
+ * position.is( 'model:position' ); // -> true
128
+ *
129
+ * position.is( 'view:position' ); // -> false
130
+ * position.is( 'documentSelection' ); // -> false
131
+ * ```
132
+ *
133
+ * @label POSITION
134
+ */
135
+ is(type: 'position' | 'model:position'): this is Position | LivePosition;
136
+ /**
137
+ * Checks whether the object is of type {@link module:engine/model/liveposition~LivePosition}.
138
+ *
139
+ * ```ts
140
+ * livePosition.is( 'position' ); // -> true
141
+ * livePosition.is( 'model:position' ); // -> true
142
+ * livePosition.is( 'liveposition' ); // -> true
143
+ * livePosition.is( 'model:livePosition' ); // -> true
144
+ *
145
+ * livePosition.is( 'view:position' ); // -> false
146
+ * livePosition.is( 'documentSelection' ); // -> false
147
+ * ```
148
+ *
149
+ * @label LIVE_POSITION
150
+ */
151
+ is(type: 'livePosition' | 'model:livePosition'): this is LivePosition;
152
+ /**
153
+ * Checks whether the object is of type {@link module:engine/model/range~Range} or its subclass.
154
+ *
155
+ * ```ts
156
+ * range.is( 'range' ); // -> true
157
+ * range.is( 'model:range' ); // -> true
158
+ *
159
+ * range.is( 'view:range' ); // -> false
160
+ * range.is( 'documentSelection' ); // -> false
161
+ * ```
162
+ *
163
+ * @label RANGE
164
+ */
165
+ is(type: 'range' | 'model:range'): this is Range | LiveRange;
166
+ /**
167
+ * Checks whether the object is of type {@link module:engine/model/liverange~LiveRange}.
168
+ *
169
+ * ```ts
170
+ * liveRange.is( 'range' ); // -> true
171
+ * liveRange.is( 'model:range' ); // -> true
172
+ * liveRange.is( 'liveRange' ); // -> true
173
+ * liveRange.is( 'model:liveRange' ); // -> true
174
+ *
175
+ * liveRange.is( 'view:range' ); // -> false
176
+ * liveRange.is( 'documentSelection' ); // -> false
177
+ * ```
178
+ *
179
+ * @label LIVE_RANGE
180
+ */
181
+ is(type: 'liveRange' | 'model:liveRange'): this is LiveRange;
182
+ /**
183
+ * Checks whether the object is of type {@link module:engine/model/documentfragment~DocumentFragment}.
184
+ *
185
+ * ```ts
186
+ * docFrag.is( 'documentFragment' ); // -> true
187
+ * docFrag.is( 'model:documentFragment' ); // -> true
188
+ *
189
+ * docFrag.is( 'view:documentFragment' ); // -> false
190
+ * docFrag.is( 'element' ); // -> false
191
+ * docFrag.is( 'node' ); // -> false
192
+ * ```
193
+ *
194
+ * @label DOCUMENT_FRAGMENT
195
+ */
196
+ is(type: 'documentFragment' | 'model:documentFragment'): this is DocumentFragment;
197
+ /**
198
+ * Checks whether the object is of type {@link module:engine/model/selection~Selection}
199
+ * or {@link module:engine/model/documentselection~DocumentSelection}.
200
+ *
201
+ * ```ts
202
+ * selection.is( 'selection' ); // -> true
203
+ * selection.is( 'model:selection' ); // -> true
204
+ *
205
+ * selection.is( 'view:selection' ); // -> false
206
+ * selection.is( 'range' ); // -> false
207
+ * ```
208
+ *
209
+ * @label SELECTION
210
+ */
211
+ is(type: 'selection' | 'model:selection'): this is Selection | DocumentSelection;
212
+ /**
213
+ * Checks whether the object is of type {@link module:engine/model/documentselection~DocumentSelection}.
214
+ *
215
+ * ```ts
216
+ * selection.is( 'selection' ); // -> true
217
+ * selection.is( 'documentSelection' ); // -> true
218
+ * selection.is( 'model:selection' ); // -> true
219
+ * selection.is( 'model:documentSelection' ); // -> true
220
+ *
221
+ * selection.is( 'view:selection' ); // -> false
222
+ * selection.is( 'element' ); // -> false
223
+ * selection.is( 'node' ); // -> false
224
+ * ```
225
+ *
226
+ * @label DOCUMENT_SELECTION
227
+ */
228
+ is(type: 'documentSelection' | 'model:documentSelection'): this is DocumentSelection;
229
+ /**
230
+ * Checks whether the object is of type {@link module:engine/model/markercollection~Marker}.
231
+ *
232
+ * ```ts
233
+ * marker.is( 'marker' ); // -> true
234
+ * marker.is( 'model:marker' ); // -> true
235
+ *
236
+ * marker.is( 'view:element' ); // -> false
237
+ * marker.is( 'documentSelection' ); // -> false
238
+ * ```
239
+ *
240
+ * @label MARKER
241
+ */
242
+ is(type: 'marker' | 'model:marker'): this is Marker;
243
+ /**
244
+ * Checks whether the object is of type {@link module:engine/model/textproxy~TextProxy}.
245
+ *
246
+ * ```ts
247
+ * textProxy.is( '$textProxy' ); // -> true
248
+ * textProxy.is( 'model:$textProxy' ); // -> true
249
+ *
250
+ * textProxy.is( 'view:$textProxy' ); // -> false
251
+ * textProxy.is( 'range' ); // -> false
252
+ * ```
253
+ *
254
+ * **Note:** Until version 20.0.0 this method wasn't accepting `'$textProxy'` type. The legacy `'textProxt'` type is still
255
+ * accepted for backward compatibility.
256
+ *
257
+ * @label TEXT_PROXY
258
+ */
259
+ is(type: '$textProxy' | 'model:$textProxy'): this is TextProxy;
260
+ /**
261
+ * Checks whether the object is of type {@link module:engine/model/element~Element} or its subclass and has the specified `name`.
262
+ *
263
+ * ```ts
264
+ * element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element
265
+ * text.is( 'element', 'imageBlock' ); -> false
266
+ * ```
267
+ *
268
+ * @label ELEMENT_NAME
269
+ */
270
+ is<N extends string>(type: 'element' | 'model:element', name: N): this is (Element | RootElement) & {
271
+ name: N;
272
+ };
273
+ /**
274
+ * Checks whether the object is of type {@link module:engine/model/rootelement~RootElement} and has the specified `name`.
275
+ *
276
+ * ```ts
277
+ * rootElement.is( 'rootElement', '$root' );
278
+ * ```
279
+ *
280
+ * @label ROOT_ELEMENT_NAME
281
+ */
282
+ is<N extends string>(type: 'rootElement' | 'model:rootElement', name: N): this is RootElement & {
283
+ name: N;
284
+ };
285
+ }
@@ -0,0 +1,37 @@
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
+ import type Node from '../node';
6
+ import type Position from '../position';
7
+ import type Schema from '../schema';
8
+ import type Writer from '../writer';
9
+ /**
10
+ * @module engine/model/utils/autoparagraphing
11
+ */
12
+ /**
13
+ * Fixes all empty roots.
14
+ *
15
+ * @internal
16
+ * @param writer The model writer.
17
+ * @returns `true` if any change has been applied, `false` otherwise.
18
+ */
19
+ export declare function autoParagraphEmptyRoots(writer: Writer): boolean;
20
+ /**
21
+ * Checks if the given node wrapped with a paragraph would be accepted by the schema in the given position.
22
+ *
23
+ * @internal
24
+ * @param position The position at which to check.
25
+ * @param nodeOrType The child node or child type to check.
26
+ * @param schema A schema instance used for element validation.
27
+ */
28
+ export declare function isParagraphable(position: Position, nodeOrType: Node | string, schema: Schema): boolean;
29
+ /**
30
+ * Inserts a new paragraph at the given position and returns a position inside that paragraph.
31
+ *
32
+ * @internal
33
+ * @param position The position where a paragraph should be inserted.
34
+ * @param writer The model writer.
35
+ * @returns Position inside the created paragraph.
36
+ */
37
+ export declare function wrapInParagraph(position: Position, writer: Writer): Position;
@@ -0,0 +1,58 @@
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/model/utils/deletecontent
7
+ */
8
+ import DocumentSelection from '../documentselection';
9
+ import type Model from '../model';
10
+ import type Selection from '../selection';
11
+ /**
12
+ * Deletes content of the selection and merge siblings. The resulting selection is always collapsed.
13
+ *
14
+ * **Note:** Use {@link module:engine/model/model~Model#deleteContent} instead of this function.
15
+ * This function is only exposed to be reusable in algorithms
16
+ * which change the {@link module:engine/model/model~Model#deleteContent}
17
+ * method's behavior.
18
+ *
19
+ * @param model The model in context of which the insertion should be performed.
20
+ * @param selection Selection of which the content should be deleted.
21
+ * @param options.leaveUnmerged Whether to merge elements after removing the content of the selection.
22
+ *
23
+ * For example `<heading>x[x</heading><paragraph>y]y</paragraph>` will become:
24
+ *
25
+ * * `<heading>x^y</heading>` with the option disabled (`leaveUnmerged == false`)
26
+ * * `<heading>x^</heading><paragraph>y</paragraph>` with enabled (`leaveUnmerged == true`).
27
+ *
28
+ * Note: {@link module:engine/model/schema~Schema#isObject object} and {@link module:engine/model/schema~Schema#isLimit limit}
29
+ * elements will not be merged.
30
+ *
31
+ * @param options.doNotResetEntireContent Whether to skip replacing the entire content with a
32
+ * paragraph when the entire content was selected.
33
+ *
34
+ * For example `<heading>[x</heading><paragraph>y]</paragraph>` will become:
35
+ *
36
+ * * `<paragraph>^</paragraph>` with the option disabled (`doNotResetEntireContent == false`)
37
+ * * `<heading>^</heading>` with enabled (`doNotResetEntireContent == true`).
38
+ *
39
+ * @param options.doNotAutoparagraph Whether to create a paragraph if after content deletion selection is moved
40
+ * to a place where text cannot be inserted.
41
+ *
42
+ * For example `<paragraph>x</paragraph>[<imageBlock src="foo.jpg"></imageBlock>]` will become:
43
+ *
44
+ * * `<paragraph>x</paragraph><paragraph>[]</paragraph>` with the option disabled (`doNotAutoparagraph == false`)
45
+ * * `<paragraph>x</paragraph>[]` with the option enabled (`doNotAutoparagraph == true`).
46
+ *
47
+ * If you use this option you need to make sure to handle invalid selections yourself or leave
48
+ * them to the selection post-fixer (may not always work).
49
+ *
50
+ * **Note:** If there is no valid position for the selection, the paragraph will always be created:
51
+ *
52
+ * `[<imageBlock src="foo.jpg"></imageBlock>]` -> `<paragraph>[]</paragraph>`.
53
+ */
54
+ export default function deleteContent(model: Model, selection: Selection | DocumentSelection, options?: {
55
+ leaveUnmerged?: boolean;
56
+ doNotResetEntireContent?: boolean;
57
+ doNotAutoparagraph?: boolean;
58
+ }): void;
@@ -0,0 +1,32 @@
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
+ import type DocumentSelection from '../documentselection';
6
+ import type Model from '../model';
7
+ import type Range from '../range';
8
+ import type Selection from '../selection';
9
+ /**
10
+ * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
11
+ *
12
+ * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
13
+ * will be returned so that it is not split. If the selection is at the end of a paragraph,
14
+ * the collapsed range after this paragraph will be returned.
15
+ *
16
+ * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
17
+ * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
18
+ * by the inserted widget block.
19
+ *
20
+ * **Note:** Use {@link module:widget/utils#findOptimalInsertionRange} instead of this function outside engine.
21
+ * This function is only exposed to be used by {@link module:widget/utils#findOptimalInsertionRange findOptimalInsertionRange()}
22
+ * in the `widget` package and inside the `engine` package.
23
+ *
24
+ * @param selection The selection based on which the insertion position should be calculated.
25
+ * @param model Model instance.
26
+ * @param place The place where to look for optimal insertion range.
27
+ * The default `auto` value will determine itself the best position for insertion.
28
+ * The `before` value will try to find a position before selection.
29
+ * The `after` value will try to find a position after selection.
30
+ * @returns The optimal range.
31
+ */
32
+ export declare function findOptimalInsertionRange(selection: Selection | DocumentSelection, model: Model, place?: 'auto' | 'before' | 'after'): Range;
@@ -0,0 +1,30 @@
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
+ import type DocumentFragment from '../documentfragment';
6
+ import type DocumentSelection from '../documentselection';
7
+ import type Model from '../model';
8
+ import type Selection from '../selection';
9
+ /**
10
+ * @module engine/model/utils/getselectedcontent
11
+ */
12
+ /**
13
+ * Gets a clone of the selected content.
14
+ *
15
+ * For example, for the following selection:
16
+ *
17
+ * ```html
18
+ * <p>x</p><quote><p>y</p><h>fir[st</h></quote><p>se]cond</p><p>z</p>
19
+ * ```
20
+ *
21
+ * It will return a document fragment with such a content:
22
+ *
23
+ * ```html
24
+ * <quote><h>st</h></quote><p>se</p>
25
+ * ```
26
+ *
27
+ * @param model The model in context of which the selection modification should be performed.
28
+ * @param selection The selection of which content will be returned.
29
+ */
30
+ export default function getSelectedContent(model: Model, selection: Selection | DocumentSelection): DocumentFragment;
@@ -0,0 +1,46 @@
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/model/utils/insertcontent
7
+ */
8
+ import DocumentSelection from '../documentselection';
9
+ import Range from '../range';
10
+ import type DocumentFragment from '../documentfragment';
11
+ import type Item from '../item';
12
+ import type Model from '../model';
13
+ import type Selection from '../selection';
14
+ /**
15
+ * Inserts content into the editor (specified selection) as one would expect the paste functionality to work.
16
+ *
17
+ * It takes care of removing the selected content, splitting elements (if needed), inserting elements and merging elements appropriately.
18
+ *
19
+ * Some examples:
20
+ *
21
+ * ```html
22
+ * <p>x^</p> + <p>y</p> => <p>x</p><p>y</p> => <p>xy[]</p>
23
+ * <p>x^y</p> + <p>z</p> => <p>x</p>^<p>y</p> + <p>z</p> => <p>x</p><p>z</p><p>y</p> => <p>xz[]y</p>
24
+ * <p>x^y</p> + <img /> => <p>x</p>^<p>y</p> + <img /> => <p>x</p><img /><p>y</p>
25
+ * <p>x</p><p>^</p><p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p> (no merging)
26
+ * <p>x</p>[<img />]<p>z</p> + <p>y</p> => <p>x</p>^<p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p>
27
+ * ```
28
+ *
29
+ * If an instance of {@link module:engine/model/selection~Selection} is passed as `selectable` it will be modified
30
+ * to the insertion selection (equal to a range to be selected after insertion).
31
+ *
32
+ * If `selectable` is not passed, the content will be inserted using the current selection of the model document.
33
+ *
34
+ * **Note:** Use {@link module:engine/model/model~Model#insertContent} instead of this function.
35
+ * This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertContent}
36
+ * method's behavior.
37
+ *
38
+ * @param model The model in context of which the insertion should be performed.
39
+ * @param content The content to insert.
40
+ * @param selectable Selection into which the content should be inserted.
41
+ * @param placeOrOffset Sets place or offset of the selection.
42
+ * @returns Range which contains all the performed changes. This is a range that, if removed,
43
+ * would return the model to the state before the insertion. If no changes were preformed by `insertContent`, returns a range collapsed
44
+ * at the insertion position.
45
+ */
46
+ export default function insertContent(model: Model, content: Item | DocumentFragment, selectable?: Selection | DocumentSelection): Range;
@@ -11,7 +11,6 @@ import LivePosition from '../liveposition';
11
11
  import LiveRange from '../liverange';
12
12
  import Position from '../position';
13
13
  import Range from '../range';
14
- import Selection from '../selection';
15
14
  import { CKEditorError } from '@ckeditor/ckeditor5-utils';
16
15
  /**
17
16
  * Inserts content into the editor (specified selection) as one would expect the paste functionality to work.
@@ -45,18 +44,9 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
45
44
  * would return the model to the state before the insertion. If no changes were preformed by `insertContent`, returns a range collapsed
46
45
  * at the insertion position.
47
46
  */
48
- export default function insertContent(model, content, selectable, placeOrOffset) {
47
+ export default function insertContent(model, content, selectable) {
49
48
  return model.change(writer => {
50
- let selection;
51
- if (!selectable) {
52
- selection = model.document.selection;
53
- }
54
- else if (selectable instanceof Selection || selectable instanceof DocumentSelection) {
55
- selection = selectable;
56
- }
57
- else {
58
- selection = writer.createSelection(selectable, placeOrOffset);
59
- }
49
+ const selection = selectable ? selectable : model.document.selection;
60
50
  if (!selection.isCollapsed) {
61
51
  model.deleteContent(selection, { doNotAutoparagraph: true });
62
52
  }
@@ -0,0 +1,44 @@
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
+ import type DocumentSelection from '../documentselection';
6
+ import type Selection from '../selection';
7
+ import type Element from '../element';
8
+ import type Model from '../model';
9
+ import type Range from '../range';
10
+ /**
11
+ * Inserts an {@glink framework/deep-dive/schema#object-elements object element} at a specific position in the editor content.
12
+ *
13
+ * **Note:** Use {@link module:engine/model/model~Model#insertObject} instead of this function.
14
+ * This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertObject}
15
+ * method's behavior.
16
+ *
17
+ * **Note**: For more documentation and examples, see {@link module:engine/model/model~Model#insertObject}.
18
+ *
19
+ * @param model The model in context of which the insertion should be performed.
20
+ * @param object An object to be inserted into the model document.
21
+ * @param selectable A selectable where the content should be inserted. If not specified, the current
22
+ * {@link module:engine/model/document~Document#selection document selection} will be used instead.
23
+ * @param placeOrOffset Specifies the exact place or offset for the insertion to take place, relative to `selectable`.
24
+ * @param options Additional options.
25
+ * @param options.findOptimalPosition An option that, when set, adjusts the insertion position (relative to
26
+ * `selectable` and `placeOrOffset`) so that the content of `selectable` is not split upon insertion (a.k.a. non-destructive insertion).
27
+ * * When `'auto'`, the algorithm will decide whether to insert the object before or after `selectable` to avoid content splitting.
28
+ * * When `'before'`, the closest position before `selectable` will be used that will not result in content splitting.
29
+ * * When `'after'`, the closest position after `selectable` will be used that will not result in content splitting.
30
+ *
31
+ * Note that this option works only for block objects. Inline objects are inserted into text and do not split blocks.
32
+ * @param options.setSelection An option that, when set, moves the
33
+ * {@link module:engine/model/document~Document#selection document selection} after inserting the object.
34
+ * * When `'on'`, the document selection will be set on the inserted object.
35
+ * * When `'after'`, the document selection will move to the closest text node after the inserted object. If there is no
36
+ * such text node, a paragraph will be created and the document selection will be moved inside it.
37
+ * @returns A range which contains all the performed changes. This is a range that, if removed,
38
+ * would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
39
+ * at the insertion position.
40
+ */
41
+ export default function insertObject(model: Model, object: Element, selectable?: Selection | DocumentSelection | null, options?: {
42
+ findOptimalPosition?: 'auto' | 'before' | 'after';
43
+ setSelection?: 'on' | 'after';
44
+ }): Range;
@@ -6,11 +6,9 @@
6
6
  * @module engine/model/utils/insertobject
7
7
  */
8
8
  import { findOptimalInsertionRange } from './findoptimalinsertionrange';
9
- import DocumentSelection from '../documentselection';
10
- import Selection from '../selection';
11
9
  import { CKEditorError, first } from '@ckeditor/ckeditor5-utils';
12
10
  /**
13
- * Inserts an {@glink framework/guides/deep-dive/schema#object-elements object element} at a specific position in the editor content.
11
+ * Inserts an {@glink framework/deep-dive/schema#object-elements object element} at a specific position in the editor content.
14
12
  *
15
13
  * **Note:** Use {@link module:engine/model/model~Model#insertObject} instead of this function.
16
14
  * This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertObject}
@@ -40,7 +38,7 @@ import { CKEditorError, first } from '@ckeditor/ckeditor5-utils';
40
38
  * would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
41
39
  * at the insertion position.
42
40
  */
43
- export default function insertObject(model, object, selectable, placeOrOffset, options = {}) {
41
+ export default function insertObject(model, object, selectable, options = {}) {
44
42
  if (!model.schema.isObject(object)) {
45
43
  /**
46
44
  * Tried to insert an element with {@link module:engine/model/utils/insertobject insertObject()} function
@@ -53,16 +51,7 @@ export default function insertObject(model, object, selectable, placeOrOffset, o
53
51
  throw new CKEditorError('insertobject-element-not-an-object', model, { object });
54
52
  }
55
53
  // Normalize selectable to a selection instance.
56
- let originalSelection;
57
- if (!selectable) {
58
- originalSelection = model.document.selection;
59
- }
60
- else if (selectable instanceof Selection || selectable instanceof DocumentSelection) {
61
- originalSelection = selectable;
62
- }
63
- else {
64
- originalSelection = model.createSelection(selectable, placeOrOffset);
65
- }
54
+ const originalSelection = selectable ? selectable : model.document.selection;
66
55
  // Adjust the insertion selection.
67
56
  let insertionSelection = originalSelection;
68
57
  if (options.findOptimalPosition && model.schema.isBlock(object)) {
@@ -0,0 +1,48 @@
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/model/utils/modifyselection
7
+ */
8
+ import DocumentSelection from '../documentselection';
9
+ import type Model from '../model';
10
+ import type Selection from '../selection';
11
+ /**
12
+ * Modifies the selection. Currently, the supported modifications are:
13
+ *
14
+ * * Extending. The selection focus is moved in the specified `options.direction` with a step specified in `options.unit`.
15
+ * Possible values for `unit` are:
16
+ * * `'character'` (default) - moves selection by one user-perceived character. In most cases this means moving by one
17
+ * character in `String` sense. However, unicode also defines "combing marks". These are special symbols, that combines
18
+ * with a symbol before it ("base character") to create one user-perceived character. For example, `q̣̇` is a normal
19
+ * letter `q` with two "combining marks": upper dot (`Ux0307`) and lower dot (`Ux0323`). For most actions, i.e. extending
20
+ * selection by one position, it is correct to include both "base character" and all of it's "combining marks". That is
21
+ * why `'character'` value is most natural and common method of modifying selection.
22
+ * * `'codePoint'` - moves selection by one unicode code point. In contrary to, `'character'` unit, this will insert
23
+ * selection between "base character" and "combining mark", because "combining marks" have their own unicode code points.
24
+ * However, for technical reasons, unicode code points with values above `UxFFFF` are represented in native `String` by
25
+ * two characters, called "surrogate pairs". Halves of "surrogate pairs" have a meaning only when placed next to each other.
26
+ * For example `𨭎` is represented in `String` by `\uD862\uDF4E`. Both `\uD862` and `\uDF4E` do not have any meaning
27
+ * outside the pair (are rendered as ? when alone). Position between them would be incorrect. In this case, selection
28
+ * extension will include whole "surrogate pair".
29
+ * * `'word'` - moves selection by a whole word.
30
+ *
31
+ * **Note:** if you extend a forward selection in a backward direction you will in fact shrink it.
32
+ *
33
+ * **Note:** Use {@link module:engine/model/model~Model#modifySelection} instead of this function.
34
+ * This function is only exposed to be reusable in algorithms
35
+ * which change the {@link module:engine/model/model~Model#modifySelection}
36
+ * method's behavior.
37
+ *
38
+ * @param model The model in context of which the selection modification should be performed.
39
+ * @param selection The selection to modify.
40
+ * @param options.direction The direction in which the selection should be modified. Default 'forward'.
41
+ * @param options.unit The unit by which selection should be modified. Default 'character'.
42
+ * @param options.treatEmojiAsSingleUnit Whether multi-characer emoji sequences should be handled as single unit.
43
+ */
44
+ export default function modifySelection(model: Model, selection: Selection | DocumentSelection, options?: {
45
+ direction?: 'forward' | 'backward';
46
+ unit?: 'character' | 'codePoint' | 'word';
47
+ treatEmojiAsSingleUnit?: boolean;
48
+ }): void;