@ckeditor/ckeditor5-engine 36.0.0 → 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 (201) 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/datatransfer.js +24 -27
  107. package/src/view/document.d.ts +184 -0
  108. package/src/view/document.js +15 -84
  109. package/src/view/documentfragment.d.ts +150 -0
  110. package/src/view/documentfragment.js +40 -81
  111. package/src/view/documentselection.d.ts +219 -0
  112. package/src/view/documentselection.js +75 -121
  113. package/src/view/domconverter.d.ts +620 -0
  114. package/src/view/domconverter.js +159 -276
  115. package/src/view/downcastwriter.d.ts +804 -0
  116. package/src/view/downcastwriter.js +336 -380
  117. package/src/view/editableelement.d.ts +52 -0
  118. package/src/view/editableelement.js +9 -49
  119. package/src/view/element.d.ts +466 -0
  120. package/src/view/element.js +150 -222
  121. package/src/view/elementdefinition.d.ts +87 -0
  122. package/src/view/emptyelement.d.ts +41 -0
  123. package/src/view/emptyelement.js +11 -44
  124. package/src/view/filler.d.ts +111 -0
  125. package/src/view/filler.js +24 -21
  126. package/src/view/item.d.ts +14 -0
  127. package/src/view/matcher.d.ts +486 -0
  128. package/src/view/matcher.js +247 -218
  129. package/src/view/node.d.ts +160 -0
  130. package/src/view/node.js +26 -100
  131. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  132. package/src/view/observer/arrowkeysobserver.js +0 -13
  133. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  134. package/src/view/observer/bubblingemittermixin.js +36 -25
  135. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  136. package/src/view/observer/bubblingeventinfo.js +3 -29
  137. package/src/view/observer/clickobserver.d.ts +43 -0
  138. package/src/view/observer/clickobserver.js +9 -19
  139. package/src/view/observer/compositionobserver.d.ts +82 -0
  140. package/src/view/observer/compositionobserver.js +13 -42
  141. package/src/view/observer/domeventdata.d.ts +50 -0
  142. package/src/view/observer/domeventdata.js +5 -30
  143. package/src/view/observer/domeventobserver.d.ts +69 -0
  144. package/src/view/observer/domeventobserver.js +19 -21
  145. package/src/view/observer/fakeselectionobserver.d.ts +46 -0
  146. package/src/view/observer/fakeselectionobserver.js +2 -15
  147. package/src/view/observer/focusobserver.d.ts +82 -0
  148. package/src/view/observer/focusobserver.js +14 -40
  149. package/src/view/observer/inputobserver.d.ts +86 -0
  150. package/src/view/observer/inputobserver.js +18 -64
  151. package/src/view/observer/keyobserver.d.ts +67 -0
  152. package/src/view/observer/keyobserver.js +8 -42
  153. package/src/view/observer/mouseobserver.d.ts +89 -0
  154. package/src/view/observer/mouseobserver.js +8 -28
  155. package/src/view/observer/mutationobserver.d.ts +82 -0
  156. package/src/view/observer/mutationobserver.js +7 -37
  157. package/src/view/observer/observer.d.ts +84 -0
  158. package/src/view/observer/observer.js +12 -25
  159. package/src/view/observer/selectionobserver.d.ts +143 -0
  160. package/src/view/observer/selectionobserver.js +9 -99
  161. package/src/view/observer/tabobserver.d.ts +42 -0
  162. package/src/view/observer/tabobserver.js +0 -14
  163. package/src/view/placeholder.d.ts +85 -0
  164. package/src/view/placeholder.js +26 -43
  165. package/src/view/position.d.ts +189 -0
  166. package/src/view/position.js +36 -83
  167. package/src/view/range.d.ts +279 -0
  168. package/src/view/range.js +79 -122
  169. package/src/view/rawelement.d.ts +73 -0
  170. package/src/view/rawelement.js +34 -48
  171. package/src/view/renderer.d.ts +265 -0
  172. package/src/view/renderer.js +105 -193
  173. package/src/view/rooteditableelement.d.ts +41 -0
  174. package/src/view/rooteditableelement.js +12 -40
  175. package/src/view/selection.d.ts +375 -0
  176. package/src/view/selection.js +79 -153
  177. package/src/view/styles/background.d.ts +33 -0
  178. package/src/view/styles/background.js +14 -12
  179. package/src/view/styles/border.d.ts +43 -0
  180. package/src/view/styles/border.js +58 -48
  181. package/src/view/styles/margin.d.ts +29 -0
  182. package/src/view/styles/margin.js +13 -11
  183. package/src/view/styles/padding.d.ts +29 -0
  184. package/src/view/styles/padding.js +13 -11
  185. package/src/view/styles/utils.d.ts +93 -0
  186. package/src/view/styles/utils.js +22 -48
  187. package/src/view/stylesmap.d.ts +675 -0
  188. package/src/view/stylesmap.js +249 -244
  189. package/src/view/text.d.ts +74 -0
  190. package/src/view/text.js +16 -46
  191. package/src/view/textproxy.d.ts +97 -0
  192. package/src/view/textproxy.js +10 -59
  193. package/src/view/treewalker.d.ts +195 -0
  194. package/src/view/treewalker.js +43 -106
  195. package/src/view/typecheckable.d.ts +401 -0
  196. package/src/view/uielement.d.ts +96 -0
  197. package/src/view/uielement.js +28 -62
  198. package/src/view/upcastwriter.d.ts +328 -0
  199. package/src/view/upcastwriter.js +124 -134
  200. package/src/view/view.d.ts +327 -0
  201. package/src/view/view.js +79 -150
@@ -0,0 +1,245 @@
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/document
7
+ */
8
+ import Differ from './differ';
9
+ import DocumentSelection from './documentselection';
10
+ import History from './history';
11
+ import RootElement from './rootelement';
12
+ import type { default as Model } from './model';
13
+ import type Batch from './batch';
14
+ import type Range from './range';
15
+ import type Writer from './writer';
16
+ import { Collection } from '@ckeditor/ckeditor5-utils';
17
+ declare const Document_base: {
18
+ new (): import("@ckeditor/ckeditor5-utils").Emitter;
19
+ prototype: import("@ckeditor/ckeditor5-utils").Emitter;
20
+ };
21
+ /**
22
+ * Data model's document. It contains the model's structure, its selection and the history of changes.
23
+ *
24
+ * Read more about working with the model in
25
+ * {@glink framework/architecture/editing-engine#model introduction to the the editing engine's architecture}.
26
+ *
27
+ * Usually, the document contains just one {@link module:engine/model/document~Document#roots root element}, so
28
+ * you can retrieve it by just calling {@link module:engine/model/document~Document#getRoot} without specifying its name:
29
+ *
30
+ * ```ts
31
+ * model.document.getRoot(); // -> returns the main root
32
+ * ```
33
+ *
34
+ * However, the document may contain multiple roots – e.g. when the editor has multiple editable areas
35
+ * (e.g. a title and a body of a message).
36
+ */
37
+ export default class Document extends Document_base {
38
+ /**
39
+ * The {@link module:engine/model/model~Model model} that the document is a part of.
40
+ */
41
+ readonly model: Model;
42
+ /**
43
+ * The document's history.
44
+ */
45
+ readonly history: History;
46
+ /**
47
+ * The selection in this document.
48
+ */
49
+ readonly selection: DocumentSelection;
50
+ /**
51
+ * A list of roots that are owned and managed by this document. Use {@link #createRoot} and
52
+ * {@link #getRoot} to manipulate it.
53
+ */
54
+ readonly roots: Collection<RootElement>;
55
+ /**
56
+ * The model differ object. Its role is to buffer changes done on the model document and then calculate a diff of those changes.
57
+ */
58
+ readonly differ: Differ;
59
+ /**
60
+ * Post-fixer callbacks registered to the model document.
61
+ */
62
+ private readonly _postFixers;
63
+ /**
64
+ * A boolean indicates whether the selection has changed until
65
+ */
66
+ private _hasSelectionChangedFromTheLastChangeBlock;
67
+ /**
68
+ * Creates an empty document instance with no {@link #roots} (other than
69
+ * the {@link #graveyard graveyard root}).
70
+ */
71
+ constructor(model: Model);
72
+ /**
73
+ * The document version. Every applied operation increases the version number. It is used to
74
+ * ensure that operations are applied on a proper document version.
75
+ *
76
+ * This property is equal to {@link module:engine/model/history~History#version `model.Document#history#version`}.
77
+ *
78
+ * If the {@link module:engine/model/operation/operation~Operation#baseVersion base version} does not match the document version,
79
+ * a {@link module:utils/ckeditorerror~CKEditorError model-document-applyoperation-wrong-version} error is thrown.
80
+ */
81
+ get version(): number;
82
+ set version(version: number);
83
+ /**
84
+ * The graveyard tree root. A document always has a graveyard root that stores removed nodes.
85
+ */
86
+ get graveyard(): RootElement;
87
+ /**
88
+ * Creates a new root.
89
+ *
90
+ * @param elementName The element name. Defaults to `'$root'` which also has some basic schema defined
91
+ * (`$block`s are allowed inside the `$root`). Make sure to define a proper schema if you use a different name.
92
+ * @param rootName A unique root name.
93
+ * @returns The created root.
94
+ */
95
+ createRoot(elementName?: string, rootName?: string): RootElement;
96
+ /**
97
+ * Removes all event listeners set by the document instance.
98
+ */
99
+ destroy(): void;
100
+ /**
101
+ * Returns a root by its name.
102
+ *
103
+ * @param name A unique root name.
104
+ * @returns The root registered under a given name or `null` when there is no root with the given name.
105
+ */
106
+ getRoot(name?: string): RootElement | null;
107
+ /**
108
+ * Returns an array with names of all roots (without the {@link #graveyard}) added to the document.
109
+ *
110
+ * @returns Roots names.
111
+ */
112
+ getRootNames(): Array<string>;
113
+ /**
114
+ * Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features
115
+ * will operate on a correct model state.
116
+ *
117
+ * An execution of a feature may lead to an incorrect document tree state. The callbacks are used to fix the document tree after
118
+ * it has changed. Post-fixers are fired just after all changes from the outermost change block were applied but
119
+ * before the {@link module:engine/model/document~Document#event:change change event} is fired. If a post-fixer callback made
120
+ * a change, it should return `true`. When this happens, all post-fixers are fired again to check if something else should
121
+ * not be fixed in the new document tree state.
122
+ *
123
+ * As a parameter, a post-fixer callback receives a {@link module:engine/model/writer~Writer writer} instance connected with the
124
+ * executed changes block. Thanks to that, all changes done by the callback will be added to the same
125
+ * {@link module:engine/model/batch~Batch batch} (and undo step) as the original changes. This makes post-fixer changes transparent
126
+ * for the user.
127
+ *
128
+ * An example of a post-fixer is a callback that checks if all the data were removed from the editor. If so, the
129
+ * callback should add an empty paragraph so that the editor is never empty:
130
+ *
131
+ * ```ts
132
+ * document.registerPostFixer( writer => {
133
+ * const changes = document.differ.getChanges();
134
+ *
135
+ * // Check if the changes lead to an empty root in the editor.
136
+ * for ( const entry of changes ) {
137
+ * if ( entry.type == 'remove' && entry.position.root.isEmpty ) {
138
+ * writer.insertElement( 'paragraph', entry.position.root, 0 );
139
+ *
140
+ * // It is fine to return early, even if multiple roots would need to be fixed.
141
+ * // All post-fixers will be fired again, so if there are more empty roots, those will be fixed, too.
142
+ * return true;
143
+ * }
144
+ * }
145
+ *
146
+ * return false;
147
+ * } );
148
+ * ```
149
+ */
150
+ registerPostFixer(postFixer: ModelPostFixer): void;
151
+ /**
152
+ * A custom `toJSON()` method to solve child-parent circular dependencies.
153
+ *
154
+ * @returns A clone of this object with the document property changed to a string.
155
+ */
156
+ toJSON(): unknown;
157
+ /**
158
+ * Check if there were any changes done on document, and if so, call post-fixers,
159
+ * fire `change` event for features and conversion and then reset the differ.
160
+ * Fire `change:data` event when at least one operation or buffered marker changes the data.
161
+ *
162
+ * @internal
163
+ * @fires change
164
+ * @fires change:data
165
+ * @param writer The writer on which post-fixers will be called.
166
+ */
167
+ _handleChangeBlock(writer: Writer): void;
168
+ /**
169
+ * Returns whether there is a buffered change or if the selection has changed from the last
170
+ * {@link module:engine/model/model~Model#enqueueChange `enqueueChange()` block}
171
+ * or {@link module:engine/model/model~Model#change `change()` block}.
172
+ *
173
+ * @returns Returns `true` if document has changed from the last `change()` or `enqueueChange()` block.
174
+ */
175
+ protected _hasDocumentChangedFromTheLastChangeBlock(): boolean;
176
+ /**
177
+ * Returns the default root for this document which is either the first root that was added to the document using
178
+ * {@link #createRoot} or the {@link #graveyard graveyard root} if no other roots were created.
179
+ *
180
+ * @returns The default root for this document.
181
+ */
182
+ protected _getDefaultRoot(): RootElement;
183
+ /**
184
+ * Returns the default range for this selection. The default range is a collapsed range that starts and ends
185
+ * at the beginning of this selection's document {@link #_getDefaultRoot default root}.
186
+ *
187
+ * @internal
188
+ */
189
+ _getDefaultRange(): Range;
190
+ /**
191
+ * Checks whether a given {@link module:engine/model/range~Range range} is a valid range for
192
+ * the {@link #selection document's selection}.
193
+ *
194
+ * @internal
195
+ * @param range A range to check.
196
+ * @returns `true` if `range` is valid, `false` otherwise.
197
+ */
198
+ _validateSelectionRange(range: Range): boolean;
199
+ /**
200
+ * Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
201
+ *
202
+ * @param writer The writer on which post-fixer callbacks will be called.
203
+ */
204
+ private _callPostFixers;
205
+ }
206
+ /**
207
+ * Fired after each {@link module:engine/model/model~Model#enqueueChange `enqueueChange()` block} or the outermost
208
+ * {@link module:engine/model/model~Model#change `change()` block} was executed and the document was changed
209
+ * during that block's execution.
210
+ *
211
+ * The changes which this event will cover include:
212
+ *
213
+ * * document structure changes,
214
+ * * selection changes,
215
+ * * marker changes.
216
+ *
217
+ * If you want to be notified about all these changes, then simply listen to this event like this:
218
+ *
219
+ * ```ts
220
+ * model.document.on( 'change', () => {
221
+ * console.log( 'The document has changed!' );
222
+ * } );
223
+ * ```
224
+ *
225
+ * If, however, you only want to be notified about the data changes, then use `change:data` event,
226
+ * which is fired for document structure changes and marker changes (which affects the data).
227
+ *
228
+ * ```ts
229
+ * model.document.on( 'change:data', () => {
230
+ * console.log( 'The data has changed!' );
231
+ * } );
232
+ * ```
233
+ *
234
+ * @eventName change
235
+ * @param batch The batch that was used in the executed changes block.
236
+ */
237
+ export type DocumentChangeEvent = {
238
+ name: 'change' | 'change:data';
239
+ args: [batch: Batch];
240
+ };
241
+ /**
242
+ * Callback passed as an argument to the {@link module:engine/model/document~Document#registerPostFixer} method.
243
+ */
244
+ export type ModelPostFixer = (writer: Writer) => boolean;
245
+ export {};
@@ -17,7 +17,7 @@ const graveyardName = '$graveyard';
17
17
  * Data model's document. It contains the model's structure, its selection and the history of changes.
18
18
  *
19
19
  * Read more about working with the model in
20
- * {@glink framework/guides/architecture/editing-engine#model introduction to the the editing engine's architecture}.
20
+ * {@glink framework/architecture/editing-engine#model introduction to the the editing engine's architecture}.
21
21
  *
22
22
  * Usually, the document contains just one {@link module:engine/model/document~Document#roots root element}, so
23
23
  * you can retrieve it by just calling {@link module:engine/model/document~Document#getRoot} without specifying its name:
@@ -0,0 +1,196 @@
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/documentfragment
7
+ */
8
+ import TypeCheckable from './typecheckable';
9
+ import type Item from './item';
10
+ import type Node from './node';
11
+ import type Range from './range';
12
+ /**
13
+ * DocumentFragment represents a part of model which does not have a common root but its top-level nodes
14
+ * can be seen as siblings. In other words, it is a detached part of model tree, without a root.
15
+ *
16
+ * DocumentFragment has own {@link module:engine/model/markercollection~MarkerCollection}. Markers from this collection
17
+ * will be set to the {@link module:engine/model/model~Model#markers model markers} by a
18
+ * {@link module:engine/model/writer~Writer#insert} function.
19
+ */
20
+ export default class DocumentFragment extends TypeCheckable implements Iterable<Node> {
21
+ /**
22
+ * DocumentFragment static markers map. This is a list of names and {@link module:engine/model/range~Range ranges}
23
+ * which will be set as Markers to {@link module:engine/model/model~Model#markers model markers collection}
24
+ * when DocumentFragment will be inserted to the document.
25
+ */
26
+ readonly markers: Map<string, Range>;
27
+ /**
28
+ * Artificial element name. Returns `undefined`. Added for compatibility reasons.
29
+ */
30
+ name?: undefined;
31
+ /**
32
+ * Artificial root name. Returns `undefined`. Added for compatibility reasons.
33
+ */
34
+ rootName?: undefined;
35
+ /**
36
+ * List of nodes contained inside the document fragment.
37
+ */
38
+ private readonly _children;
39
+ /**
40
+ * Creates an empty `DocumentFragment`.
41
+ *
42
+ * **Note:** Constructor of this class shouldn't be used directly in the code.
43
+ * Use the {@link module:engine/model/writer~Writer#createDocumentFragment} method instead.
44
+ *
45
+ * @internal
46
+ * @param children Nodes to be contained inside the `DocumentFragment`.
47
+ */
48
+ constructor(children?: Node | Iterable<Node>);
49
+ /**
50
+ * Returns an iterator that iterates over all nodes contained inside this document fragment.
51
+ */
52
+ [Symbol.iterator](): IterableIterator<Node>;
53
+ /**
54
+ * Number of this document fragment's children.
55
+ */
56
+ get childCount(): number;
57
+ /**
58
+ * Sum of {@link module:engine/model/node~Node#offsetSize offset sizes} of all of this document fragment's children.
59
+ */
60
+ get maxOffset(): number;
61
+ /**
62
+ * Is `true` if there are no nodes inside this document fragment, `false` otherwise.
63
+ */
64
+ get isEmpty(): boolean;
65
+ /**
66
+ * Artificial next sibling. Returns `null`. Added for compatibility reasons.
67
+ */
68
+ get nextSibling(): null;
69
+ /**
70
+ * Artificial previous sibling. Returns `null`. Added for compatibility reasons.
71
+ */
72
+ get previousSibling(): null;
73
+ /**
74
+ * Artificial root of `DocumentFragment`. Returns itself. Added for compatibility reasons.
75
+ */
76
+ get root(): DocumentFragment;
77
+ /**
78
+ * Artificial parent of `DocumentFragment`. Returns `null`. Added for compatibility reasons.
79
+ */
80
+ get parent(): null;
81
+ /**
82
+ * Artificial owner of `DocumentFragment`. Returns `null`. Added for compatibility reasons.
83
+ */
84
+ get document(): null;
85
+ /**
86
+ * Returns empty array. Added for compatibility reasons.
87
+ */
88
+ getAncestors(): Array<never>;
89
+ /**
90
+ * Gets the child at the given index. Returns `null` if incorrect index was passed.
91
+ *
92
+ * @param index Index of child.
93
+ * @returns Child node.
94
+ */
95
+ getChild(index: number): Node | null;
96
+ /**
97
+ * Returns an iterator that iterates over all of this document fragment's children.
98
+ */
99
+ getChildren(): IterableIterator<Node>;
100
+ /**
101
+ * Returns an index of the given child node. Returns `null` if given node is not a child of this document fragment.
102
+ *
103
+ * @param node Child node to look for.
104
+ * @returns Child node's index.
105
+ */
106
+ getChildIndex(node: Node): number | null;
107
+ /**
108
+ * Returns the starting offset of given child. Starting offset is equal to the sum of
109
+ * {@link module:engine/model/node~Node#offsetSize offset sizes} of all node's siblings that are before it. Returns `null` if
110
+ * given node is not a child of this document fragment.
111
+ *
112
+ * @param node Child node to look for.
113
+ * @returns Child node's starting offset.
114
+ */
115
+ getChildStartOffset(node: Node): number | null;
116
+ /**
117
+ * Returns path to a `DocumentFragment`, which is an empty array. Added for compatibility reasons.
118
+ */
119
+ getPath(): Array<number>;
120
+ /**
121
+ * Returns a descendant node by its path relative to this element.
122
+ *
123
+ * ```ts
124
+ * // <this>a<b>c</b></this>
125
+ * this.getNodeByPath( [ 0 ] ); // -> "a"
126
+ * this.getNodeByPath( [ 1 ] ); // -> <b>
127
+ * this.getNodeByPath( [ 1, 0 ] ); // -> "c"
128
+ * ```
129
+ *
130
+ * @param relativePath Path of the node to find, relative to this element.
131
+ */
132
+ getNodeByPath(relativePath: Array<number>): Node | DocumentFragment;
133
+ /**
134
+ * Converts offset "position" to index "position".
135
+ *
136
+ * Returns index of a node that occupies given offset. If given offset is too low, returns `0`. If given offset is
137
+ * too high, returns index after last child.
138
+ *
139
+ * ```ts
140
+ * const textNode = new Text( 'foo' );
141
+ * const pElement = new Element( 'p' );
142
+ * const docFrag = new DocumentFragment( [ textNode, pElement ] );
143
+ * docFrag.offsetToIndex( -1 ); // Returns 0, because offset is too low.
144
+ * docFrag.offsetToIndex( 0 ); // Returns 0, because offset 0 is taken by `textNode` which is at index 0.
145
+ * docFrag.offsetToIndex( 1 ); // Returns 0, because `textNode` has `offsetSize` equal to 3, so it occupies offset 1 too.
146
+ * docFrag.offsetToIndex( 2 ); // Returns 0.
147
+ * docFrag.offsetToIndex( 3 ); // Returns 1.
148
+ * docFrag.offsetToIndex( 4 ); // Returns 2. There are no nodes at offset 4, so last available index is returned.
149
+ * ```
150
+ *
151
+ * @param offset Offset to look for.
152
+ * @returns Index of a node that occupies given offset.
153
+ */
154
+ offsetToIndex(offset: number): number;
155
+ /**
156
+ * Converts `DocumentFragment` instance to plain object and returns it.
157
+ * Takes care of converting all of this document fragment's children.
158
+ *
159
+ * @returns `DocumentFragment` instance converted to plain object.
160
+ */
161
+ toJSON(): unknown;
162
+ /**
163
+ * Creates a `DocumentFragment` instance from given plain object (i.e. parsed JSON string).
164
+ * Converts `DocumentFragment` children to proper nodes.
165
+ *
166
+ * @param json Plain object to be converted to `DocumentFragment`.
167
+ * @returns `DocumentFragment` instance created using given plain object.
168
+ */
169
+ static fromJSON(json: any): DocumentFragment;
170
+ /**
171
+ * {@link #_insertChild Inserts} one or more nodes at the end of this document fragment.
172
+ *
173
+ * @internal
174
+ * @param items Items to be inserted.
175
+ */
176
+ _appendChild(items: string | Item | Iterable<string | Item>): void;
177
+ /**
178
+ * Inserts one or more nodes at the given index and sets {@link module:engine/model/node~Node#parent parent} of these nodes
179
+ * to this document fragment.
180
+ *
181
+ * @internal
182
+ * @param index Index at which nodes should be inserted.
183
+ * @param items Items to be inserted.
184
+ */
185
+ _insertChild(index: number, items: string | Item | Iterable<string | Item>): void;
186
+ /**
187
+ * Removes one or more nodes starting at the given index
188
+ * and sets {@link module:engine/model/node~Node#parent parent} of these nodes to `null`.
189
+ *
190
+ * @internal
191
+ * @param index Index of the first node to remove.
192
+ * @param howMany Number of nodes to remove.
193
+ * @returns Array containing removed nodes.
194
+ */
195
+ _removeChildren(index: number, howMany?: number): Array<Node>;
196
+ }
@@ -3,7 +3,7 @@
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
- * @module module:engine/model/documentfragment
6
+ * @module engine/model/documentfragment
7
7
  */
8
8
  import TypeCheckable from './typecheckable';
9
9
  import Element from './element';
@@ -171,7 +171,7 @@ export default class DocumentFragment extends TypeCheckable {
171
171
  * Converts offset "position" to index "position".
172
172
  *
173
173
  * Returns index of a node that occupies given offset. If given offset is too low, returns `0`. If given offset is
174
- * too high, returns index after last child}.
174
+ * too high, returns index after last child.
175
175
  *
176
176
  * ```ts
177
177
  * const textNode = new Text( 'foo' );