@ckeditor/ckeditor5-engine 48.2.0 → 48.3.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 (129) hide show
  1. package/dist/controller/datacontroller.d.ts +329 -328
  2. package/dist/controller/editingcontroller.d.ts +95 -94
  3. package/dist/conversion/comparemarkers.d.ts +45 -45
  4. package/dist/conversion/conversion.d.ts +474 -474
  5. package/dist/conversion/conversionhelpers.d.ts +21 -21
  6. package/dist/conversion/downcastdispatcher.d.ts +539 -538
  7. package/dist/conversion/downcasthelpers.d.ts +1129 -1129
  8. package/dist/conversion/mapper.d.ts +692 -697
  9. package/dist/conversion/modelconsumable.d.ts +196 -196
  10. package/dist/conversion/upcastdispatcher.d.ts +483 -482
  11. package/dist/conversion/upcasthelpers.d.ts +491 -491
  12. package/dist/conversion/viewconsumable.d.ts +330 -330
  13. package/dist/dataprocessor/basichtmlwriter.d.ts +15 -15
  14. package/dist/dataprocessor/dataprocessor.d.ts +57 -57
  15. package/dist/dataprocessor/htmldataprocessor.d.ts +72 -72
  16. package/dist/dataprocessor/htmlwriter.d.ts +11 -11
  17. package/dist/dataprocessor/xmldataprocessor.d.ts +86 -86
  18. package/dist/dev-utils/model.d.ts +128 -123
  19. package/dist/dev-utils/operationreplayer.d.ts +49 -49
  20. package/dist/dev-utils/utils.d.ts +33 -33
  21. package/dist/dev-utils/view.d.ts +314 -309
  22. package/dist/engineconfig.d.ts +39 -39
  23. package/dist/index.css.map +1 -1
  24. package/dist/index.d.ts +150 -150
  25. package/dist/index.js +34026 -40107
  26. package/dist/index.js.map +1 -1
  27. package/dist/legacyerrors.d.ts +0 -4
  28. package/dist/model/batch.d.ts +86 -86
  29. package/dist/model/differ.d.ts +504 -504
  30. package/dist/model/document.d.ts +265 -268
  31. package/dist/model/documentfragment.d.ts +214 -214
  32. package/dist/model/documentselection.d.ts +406 -410
  33. package/dist/model/element.d.ts +182 -182
  34. package/dist/model/history.d.ts +109 -109
  35. package/dist/model/item.d.ts +9 -9
  36. package/dist/model/liveposition.d.ts +70 -69
  37. package/dist/model/liverange.d.ts +93 -92
  38. package/dist/model/markercollection.d.ts +317 -324
  39. package/dist/model/model.d.ts +889 -909
  40. package/dist/model/node.d.ts +254 -254
  41. package/dist/model/nodelist.d.ts +110 -110
  42. package/dist/model/operation/attributeoperation.d.ts +98 -98
  43. package/dist/model/operation/detachoperation.d.ts +57 -57
  44. package/dist/model/operation/insertoperation.d.ts +85 -85
  45. package/dist/model/operation/markeroperation.d.ts +87 -87
  46. package/dist/model/operation/mergeoperation.d.ts +95 -95
  47. package/dist/model/operation/moveoperation.d.ts +97 -97
  48. package/dist/model/operation/nooperation.d.ts +33 -33
  49. package/dist/model/operation/operation.d.ts +94 -94
  50. package/dist/model/operation/operationfactory.d.ts +14 -14
  51. package/dist/model/operation/renameoperation.d.ts +78 -78
  52. package/dist/model/operation/rootattributeoperation.d.ts +93 -93
  53. package/dist/model/operation/rootoperation.d.ts +71 -71
  54. package/dist/model/operation/splitoperation.d.ts +104 -104
  55. package/dist/model/operation/transform.d.ts +91 -91
  56. package/dist/model/operation/utils.d.ts +58 -58
  57. package/dist/model/position.d.ts +535 -535
  58. package/dist/model/range.d.ts +458 -453
  59. package/dist/model/rootelement.d.ts +55 -55
  60. package/dist/model/schema.d.ts +1325 -1327
  61. package/dist/model/selection.d.ts +452 -471
  62. package/dist/model/text.d.ts +62 -62
  63. package/dist/model/textproxy.d.ts +140 -140
  64. package/dist/model/treewalker.d.ts +190 -190
  65. package/dist/model/typecheckable.d.ts +281 -281
  66. package/dist/model/utils/autoparagraphing.d.ts +29 -29
  67. package/dist/model/utils/deletecontent.d.ts +68 -68
  68. package/dist/model/utils/getselectedcontent.d.ts +27 -27
  69. package/dist/model/utils/insertcontent.d.ts +42 -42
  70. package/dist/model/utils/insertobject.d.ts +41 -41
  71. package/dist/model/utils/modifyselection.d.ts +44 -44
  72. package/dist/model/utils/selection-post-fixer.d.ts +71 -71
  73. package/dist/model/writer.d.ts +854 -854
  74. package/dist/view/attributeelement.d.ts +123 -123
  75. package/dist/view/containerelement.d.ts +49 -49
  76. package/dist/view/datatransfer.d.ts +70 -70
  77. package/dist/view/document.d.ts +175 -177
  78. package/dist/view/documentfragment.d.ts +158 -157
  79. package/dist/view/documentselection.d.ts +308 -307
  80. package/dist/view/domconverter.d.ts +612 -657
  81. package/dist/view/downcastwriter.d.ts +1006 -1006
  82. package/dist/view/editableelement.d.ts +64 -63
  83. package/dist/view/element.d.ts +754 -754
  84. package/dist/view/elementdefinition.d.ts +79 -79
  85. package/dist/view/emptyelement.d.ts +42 -42
  86. package/dist/view/filler.d.ts +75 -75
  87. package/dist/view/item.d.ts +9 -9
  88. package/dist/view/matcher.d.ts +412 -487
  89. package/dist/view/node.d.ts +164 -163
  90. package/dist/view/observer/arrowkeysobserver.d.ts +37 -37
  91. package/dist/view/observer/bubblingemittermixin.d.ts +163 -153
  92. package/dist/view/observer/bubblingeventinfo.d.ts +45 -42
  93. package/dist/view/observer/clickobserver.d.ts +36 -36
  94. package/dist/view/observer/compositionobserver.d.ts +67 -67
  95. package/dist/view/observer/domeventdata.d.ts +46 -46
  96. package/dist/view/observer/domeventobserver.d.ts +77 -74
  97. package/dist/view/observer/fakeselectionobserver.d.ts +42 -42
  98. package/dist/view/observer/focusobserver.d.ts +84 -84
  99. package/dist/view/observer/inputobserver.d.ts +76 -76
  100. package/dist/view/observer/keyobserver.d.ts +53 -53
  101. package/dist/view/observer/mouseobserver.d.ts +73 -73
  102. package/dist/view/observer/mutationobserver.d.ts +101 -101
  103. package/dist/view/observer/observer.d.ts +84 -83
  104. package/dist/view/observer/pointerobserver.d.ts +63 -63
  105. package/dist/view/observer/selectionobserver.d.ts +136 -136
  106. package/dist/view/observer/tabobserver.d.ts +38 -38
  107. package/dist/view/observer/touchobserver.d.ts +60 -60
  108. package/dist/view/placeholder.d.ts +80 -80
  109. package/dist/view/position.d.ts +187 -187
  110. package/dist/view/range.d.ts +282 -282
  111. package/dist/view/rawelement.d.ts +72 -72
  112. package/dist/view/renderer.d.ts +270 -272
  113. package/dist/view/rooteditableelement.d.ts +43 -43
  114. package/dist/view/selection.d.ts +356 -369
  115. package/dist/view/styles/background.d.ts +15 -15
  116. package/dist/view/styles/border.d.ts +27 -27
  117. package/dist/view/styles/margin.d.ts +12 -12
  118. package/dist/view/styles/padding.d.ts +12 -12
  119. package/dist/view/styles/utils.d.ts +72 -72
  120. package/dist/view/stylesmap.d.ts +715 -715
  121. package/dist/view/text.d.ts +75 -75
  122. package/dist/view/textproxy.d.ts +92 -92
  123. package/dist/view/tokenlist.d.ts +104 -104
  124. package/dist/view/treewalker.d.ts +201 -201
  125. package/dist/view/typecheckable.d.ts +445 -445
  126. package/dist/view/uielement.d.ts +93 -93
  127. package/dist/view/upcastwriter.d.ts +412 -412
  128. package/dist/view/view.d.ts +466 -469
  129. package/package.json +2 -2
@@ -1,426 +1,422 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
5
  /**
6
- * @module engine/model/documentselection
7
- */
8
- import { ModelTypeCheckable } from './typecheckable.js';
9
- import { ModelSelection, type ModelSelectionChangeAttributeEvent, type ModelSelectionChangeRangeEvent } from './selection.js';
10
- import type { ModelDocument } from './document.js';
11
- import type { Marker } from './markercollection.js';
12
- import { type ModelElement } from './element.js';
13
- import { type ModelItem } from './item.js';
14
- import type { ModelPosition, ModelPositionOffset } from './position.js';
15
- import { type ModelRange } from './range.js';
16
- import { Collection } from '@ckeditor/ckeditor5-utils';
17
- declare const ModelDocumentSelection_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof ModelTypeCheckable, import("@ckeditor/ckeditor5-utils").Emitter>;
6
+ * @module engine/model/documentselection
7
+ */
8
+ import { ModelTypeCheckable } from "./typecheckable.js";
9
+ import { ModelSelection, type ModelSelectionChangeAttributeEvent, type ModelSelectionChangeRangeEvent } from "./selection.js";
10
+ import type { ModelDocument } from "./document.js";
11
+ import type { Marker } from "./markercollection.js";
12
+ import { type ModelElement } from "./element.js";
13
+ import { type ModelItem } from "./item.js";
14
+ import type { ModelPosition, ModelPositionOffset } from "./position.js";
15
+ import { type ModelRange } from "./range.js";
16
+ import { Collection, type EmitterMixinConstructor } from "@ckeditor/ckeditor5-utils";
17
+ declare const ModelDocumentSelectionBase: EmitterMixinConstructor<typeof ModelTypeCheckable>;
18
18
  /**
19
- * `ModelDocumentSelection` is a special selection which is used as the
20
- * {@link module:engine/model/document~ModelDocument#selection document's selection}.
21
- * There can be only one instance of `ModelDocumentSelection` per document.
22
- *
23
- * Document selection can only be changed by using the {@link module:engine/model/writer~ModelWriter} instance
24
- * inside the {@link module:engine/model/model~Model#change `change()`} block, as it provides a secure way to modify model.
25
- *
26
- * `ModelDocumentSelection` is automatically updated upon changes in the {@link module:engine/model/document~ModelDocument document}
27
- * to always contain valid ranges. Its attributes are inherited from the text unless set explicitly.
28
- *
29
- * Differences between {@link module:engine/model/selection~ModelSelection} and `ModelDocumentSelection` are:
30
- * * there is always a range in `ModelDocumentSelection` - even if no ranges were added there is a "default range"
31
- * present in the selection,
32
- * * ranges added to this selection updates automatically when the document changes,
33
- * * attributes of `ModelDocumentSelection` are updated automatically according to selection ranges.
34
- *
35
- * Since `ModelDocumentSelection` uses {@link module:engine/model/liverange~ModelLiveRange live ranges}
36
- * and is updated when {@link module:engine/model/document~ModelDocument document}
37
- * changes, it cannot be set on {@link module:engine/model/node~ModelNode nodes}
38
- * that are inside {@link module:engine/model/documentfragment~ModelDocumentFragment document fragment}.
39
- * If you need to represent a selection in document fragment,
40
- * use {@link module:engine/model/selection~ModelSelection Selection class} instead.
41
- */
42
- export declare class ModelDocumentSelection extends /* #__PURE__ */ ModelDocumentSelection_base {
43
- /**
44
- * Selection used internally by that class (`ModelDocumentSelection` is a proxy to that selection).
45
- */
46
- private _selection;
47
- /**
48
- * Creates an empty live selection for given {@link module:engine/model/document~ModelDocument}.
49
- *
50
- * @param doc Document which owns this selection.
51
- */
52
- constructor(doc: ModelDocument);
53
- /**
54
- * Describes whether the selection is collapsed. Selection is collapsed when there is exactly one range which is
55
- * collapsed.
56
- */
57
- get isCollapsed(): boolean;
58
- /**
59
- * Selection anchor. Anchor may be described as a position where the most recent part of the selection starts.
60
- * Together with {@link #focus} they define the direction of selection, which is important
61
- * when expanding/shrinking selection. Anchor is always {@link module:engine/model/range~ModelRange#start start} or
62
- * {@link module:engine/model/range~ModelRange#end end} position of the most recently added range.
63
- *
64
- * Is set to `null` if there are no ranges in selection.
65
- *
66
- * @see #focus
67
- */
68
- get anchor(): ModelPosition | null;
69
- /**
70
- * Selection focus. Focus is a position where the selection ends.
71
- *
72
- * Is set to `null` if there are no ranges in selection.
73
- *
74
- * @see #anchor
75
- */
76
- get focus(): ModelPosition | null;
77
- /**
78
- * Number of ranges in selection.
79
- */
80
- get rangeCount(): number;
81
- /**
82
- * Describes whether `Documentselection` has own range(s) set, or if it is defaulted to
83
- * {@link module:engine/model/document~ModelDocument#_getDefaultRange document's default range}.
84
- */
85
- get hasOwnRange(): boolean;
86
- /**
87
- * Specifies whether the {@link #focus}
88
- * precedes {@link #anchor}.
89
- *
90
- * @readonly
91
- * @type {Boolean}
92
- */
93
- get isBackward(): boolean;
94
- /**
95
- * Describes whether the gravity is overridden (using {@link module:engine/model/writer~ModelWriter#overrideSelectionGravity}) or not.
96
- *
97
- * Note that the gravity remains overridden as long as will not be restored the same number of times as it was overridden.
98
- */
99
- get isGravityOverridden(): boolean;
100
- /**
101
- * A collection of selection {@link module:engine/model/markercollection~Marker markers}.
102
- * Marker is a selection marker when selection range is inside the marker range.
103
- *
104
- * **Note**: Only markers from {@link ~ModelDocumentSelection#observeMarkers observed markers groups} are collected.
105
- */
106
- get markers(): Collection<Marker>;
107
- /**
108
- * Used for the compatibility with the {@link module:engine/model/selection~ModelSelection#isEqual} method.
109
- *
110
- * @internal
111
- */
112
- get _ranges(): Array<ModelRange>;
113
- /**
114
- * Returns an iterable that iterates over copies of selection ranges.
115
- */
116
- getRanges(): IterableIterator<ModelRange>;
117
- /**
118
- * Returns the first position in the selection.
119
- * First position is the position that {@link module:engine/model/position~ModelPosition#isBefore is before}
120
- * any other position in the selection.
121
- *
122
- * Returns `null` if there are no ranges in selection.
123
- */
124
- getFirstPosition(): ModelPosition | null;
125
- /**
126
- * Returns the last position in the selection.
127
- * Last position is the position that {@link module:engine/model/position~ModelPosition#isAfter is after}
128
- * any other position in the selection.
129
- *
130
- * Returns `null` if there are no ranges in selection.
131
- */
132
- getLastPosition(): ModelPosition | null;
133
- /**
134
- * Returns a copy of the first range in the selection.
135
- * First range is the one which {@link module:engine/model/range~ModelRange#start start} position
136
- * {@link module:engine/model/position~ModelPosition#isBefore is before} start position of all other ranges
137
- * (not to confuse with the first range added to the selection).
138
- *
139
- * Returns `null` if there are no ranges in selection.
140
- */
141
- getFirstRange(): ModelRange | null;
142
- /**
143
- * Returns a copy of the last range in the selection.
144
- * Last range is the one which {@link module:engine/model/range~ModelRange#end end} position
145
- * {@link module:engine/model/position~ModelPosition#isAfter is after} end position of all
146
- * other ranges (not to confuse with the range most recently added to the selection).
147
- *
148
- * Returns `null` if there are no ranges in selection.
149
- */
150
- getLastRange(): ModelRange | null;
151
- /**
152
- * Gets elements of type {@link module:engine/model/schema~ModelSchema#isBlock "block"} touched by the selection.
153
- *
154
- * This method's result can be used for example to apply block styling to all blocks covered by this selection.
155
- *
156
- * **Note:** `getSelectedBlocks()` returns blocks that are nested in other non-block elements
157
- * but will not return blocks nested in other blocks.
158
- *
159
- * In this case the function will return exactly all 3 paragraphs (note: `<blockQuote>` is not a block itself):
160
- *
161
- * ```
162
- * <paragraph>[a</paragraph>
163
- * <blockQuote>
164
- * <paragraph>b</paragraph>
165
- * </blockQuote>
166
- * <paragraph>c]d</paragraph>
167
- * ```
168
- *
169
- * In this case the paragraph will also be returned, despite the collapsed selection:
170
- *
171
- * ```
172
- * <paragraph>[]a</paragraph>
173
- * ```
174
- *
175
- * In such a scenario, however, only blocks A, B & E will be returned as blocks C & D are nested in block B:
176
- *
177
- * ```
178
- * [<blockA></blockA>
179
- * <blockB>
180
- * <blockC></blockC>
181
- * <blockD></blockD>
182
- * </blockB>
183
- * <blockE></blockE>]
184
- * ```
185
- *
186
- * If the selection is inside a block all the inner blocks (A & B) are returned:
187
- *
188
- * ```
189
- * <block>
190
- * <blockA>[a</blockA>
191
- * <blockB>b]</blockB>
192
- * </block>
193
- * ```
194
- *
195
- * **Special case**: If a selection ends at the beginning of a block, that block is not returned as from user perspective
196
- * this block wasn't selected. See [#984](https://github.com/ckeditor/ckeditor5-engine/issues/984) for more details.
197
- *
198
- * ```
199
- * <paragraph>[a</paragraph>
200
- * <paragraph>b</paragraph>
201
- * <paragraph>]c</paragraph> // this block will not be returned
202
- * ```
203
- */
204
- getSelectedBlocks(): IterableIterator<ModelElement>;
205
- /**
206
- * Returns the selected element. {@link module:engine/model/element~ModelElement Element} is considered as selected if there is only
207
- * one range in the selection, and that range contains exactly one element.
208
- * Returns `null` if there is no selected element.
209
- */
210
- getSelectedElement(): ModelElement | null;
211
- /**
212
- * Checks whether the selection contains the entire content of the given element. This means that selection must start
213
- * at a position {@link module:engine/model/position~ModelPosition#isTouching touching} the element's start and ends at position
214
- * touching the element's end.
215
- *
216
- * By default, this method will check whether the entire content of the selection's current root is selected.
217
- * Useful to check if e.g. the user has just pressed <kbd>Ctrl</kbd> + <kbd>A</kbd>.
218
- */
219
- containsEntireContent(element: ModelElement): boolean;
220
- /**
221
- * Unbinds all events previously bound by document selection.
222
- */
223
- destroy(): void;
224
- /**
225
- * Returns iterable that iterates over this selection's attribute keys.
226
- */
227
- getAttributeKeys(): IterableIterator<string>;
228
- /**
229
- * Returns iterable that iterates over this selection's attributes.
230
- *
231
- * Attributes are returned as arrays containing two items. First one is attribute key and second is attribute value.
232
- * This format is accepted by native `Map` object and also can be passed in `Node` constructor.
233
- */
234
- getAttributes(): IterableIterator<[string, unknown]>;
235
- /**
236
- * Gets an attribute value for given key or `undefined` if that attribute is not set on the selection.
237
- *
238
- * @param key Key of attribute to look for.
239
- * @returns Attribute value or `undefined`.
240
- */
241
- getAttribute(key: string): unknown;
242
- /**
243
- * Checks if the selection has an attribute for given key.
244
- *
245
- * @param key Key of attribute to check.
246
- * @returns `true` if attribute with given key is set on selection, `false` otherwise.
247
- */
248
- hasAttribute(key: string): boolean;
249
- /**
250
- * Refreshes selection attributes and markers according to the current position in the model.
251
- */
252
- refresh(): void;
253
- /**
254
- * Registers a marker group prefix or a marker name to be collected in the
255
- * {@link ~ModelDocumentSelection#markers selection markers collection}.
256
- *
257
- * See also {@link module:engine/model/markercollection~MarkerCollection#getMarkersGroup `MarkerCollection#getMarkersGroup()`}.
258
- *
259
- * @param prefixOrName The marker group prefix or marker name.
260
- */
261
- observeMarkers(prefixOrName: string): void;
262
- /**
263
- * Converts `DocumentSelection` to plain object and returns it.
264
- *
265
- * @returns `DocumentSelection` converted to plain object.
266
- */
267
- toJSON(): unknown;
268
- /**
269
- * Moves {@link module:engine/model/documentselection~ModelDocumentSelection#focus} to the specified location.
270
- * Should be used only within the {@link module:engine/model/writer~ModelWriter#setSelectionFocus} method.
271
- *
272
- * The location can be specified in the same form as
273
- * {@link module:engine/model/writer~ModelWriter#createPositionAt writer.createPositionAt()} parameters.
274
- *
275
- * @see module:engine/model/writer~ModelWriter#setSelectionFocus
276
- * @internal
277
- * @param offset Offset or one of the flags. Used only when
278
- * first parameter is a {@link module:engine/model/item~ModelItem model item}.
279
- */
280
- _setFocus(itemOrPosition: ModelItem | ModelPosition, offset?: ModelPositionOffset): void;
281
- /**
282
- * Sets this selection's ranges and direction to the specified location based on the given
283
- * {@link module:engine/model/selection~ModelSelectable selectable}.
284
- * Should be used only within the {@link module:engine/model/writer~ModelWriter#setSelection} method.
285
- *
286
- * @see module:engine/model/writer~ModelWriter#setSelection
287
- * @internal
288
- */
289
- _setTo(...args: Parameters<ModelSelection['setTo']>): void;
290
- /**
291
- * Sets attribute on the selection. If attribute with the same key already is set, it's value is overwritten.
292
- * Should be used only within the {@link module:engine/model/writer~ModelWriter#setSelectionAttribute} method.
293
- *
294
- * @see module:engine/model/writer~ModelWriter#setSelectionAttribute
295
- * @internal
296
- * @param key Key of the attribute to set.
297
- * @param value Attribute value.
298
- */
299
- _setAttribute(key: string, value: unknown): void;
300
- /**
301
- * Removes an attribute with given key from the selection.
302
- * If the given attribute was set on the selection, fires the {@link module:engine/model/selection~ModelSelection#event:change:range}
303
- * event with removed attribute key.
304
- * Should be used only within the {@link module:engine/model/writer~ModelWriter#removeSelectionAttribute} method.
305
- *
306
- * @see module:engine/model/writer~ModelWriter#removeSelectionAttribute
307
- * @internal
308
- * @param key Key of the attribute to remove.
309
- */
310
- _removeAttribute(key: string): void;
311
- /**
312
- * Returns an iterable that iterates through all selection attributes stored in current selection's parent.
313
- *
314
- * @internal
315
- */
316
- _getStoredAttributes(): Iterable<[string, unknown]>;
317
- /**
318
- * Temporarily changes the gravity of the selection from the left to the right.
319
- *
320
- * The gravity defines from which direction the selection inherits its attributes. If it's the default left
321
- * gravity, the selection (after being moved by the the user) inherits attributes from its left hand side.
322
- * This method allows to temporarily override this behavior by forcing the gravity to the right.
323
- *
324
- * It returns an unique identifier which is required to restore the gravity. It guarantees the symmetry
325
- * of the process.
326
- *
327
- * @see module:engine/model/writer~ModelWriter#overrideSelectionGravity
328
- * @internal
329
- * @returns The unique id which allows restoring the gravity.
330
- */
331
- _overrideGravity(): string;
332
- /**
333
- * Restores the {@link ~ModelDocumentSelection#_overrideGravity overridden gravity}.
334
- *
335
- * Restoring the gravity is only possible using the unique identifier returned by
336
- * {@link ~ModelDocumentSelection#_overrideGravity}. Note that the gravity remains overridden as long as won't be restored
337
- * the same number of times it was overridden.
338
- *
339
- * @see module:engine/model/writer~ModelWriter#restoreSelectionGravity
340
- * @internal
341
- * @param uid The unique id returned by {@link #_overrideGravity}.
342
- */
343
- _restoreGravity(uid: string): void;
344
- /**
345
- * Generates and returns an attribute key for selection attributes store, basing on original attribute key.
346
- *
347
- * @internal
348
- * @param key Attribute key to convert.
349
- * @returns Converted attribute key, applicable for selection store.
350
- */
351
- static _getStoreAttributeKey(key: string): string;
352
- /**
353
- * Checks whether the given attribute key is an attribute stored on an element.
354
- *
355
- * @internal
356
- */
357
- static _isStoreAttributeKey(key: string): boolean;
19
+ * `ModelDocumentSelection` is a special selection which is used as the
20
+ * {@link module:engine/model/document~ModelDocument#selection document's selection}.
21
+ * There can be only one instance of `ModelDocumentSelection` per document.
22
+ *
23
+ * Document selection can only be changed by using the {@link module:engine/model/writer~ModelWriter} instance
24
+ * inside the {@link module:engine/model/model~Model#change `change()`} block, as it provides a secure way to modify model.
25
+ *
26
+ * `ModelDocumentSelection` is automatically updated upon changes in the {@link module:engine/model/document~ModelDocument document}
27
+ * to always contain valid ranges. Its attributes are inherited from the text unless set explicitly.
28
+ *
29
+ * Differences between {@link module:engine/model/selection~ModelSelection} and `ModelDocumentSelection` are:
30
+ * * there is always a range in `ModelDocumentSelection` - even if no ranges were added there is a "default range"
31
+ * present in the selection,
32
+ * * ranges added to this selection updates automatically when the document changes,
33
+ * * attributes of `ModelDocumentSelection` are updated automatically according to selection ranges.
34
+ *
35
+ * Since `ModelDocumentSelection` uses {@link module:engine/model/liverange~ModelLiveRange live ranges}
36
+ * and is updated when {@link module:engine/model/document~ModelDocument document}
37
+ * changes, it cannot be set on {@link module:engine/model/node~ModelNode nodes}
38
+ * that are inside {@link module:engine/model/documentfragment~ModelDocumentFragment document fragment}.
39
+ * If you need to represent a selection in document fragment,
40
+ * use {@link module:engine/model/selection~ModelSelection Selection class} instead.
41
+ */
42
+ export declare class ModelDocumentSelection extends ModelDocumentSelectionBase {
43
+ /**
44
+ * Selection used internally by that class (`ModelDocumentSelection` is a proxy to that selection).
45
+ */
46
+ private _selection;
47
+ /**
48
+ * Creates an empty live selection for given {@link module:engine/model/document~ModelDocument}.
49
+ *
50
+ * @param doc Document which owns this selection.
51
+ */
52
+ constructor(doc: ModelDocument);
53
+ /**
54
+ * Describes whether the selection is collapsed. Selection is collapsed when there is exactly one range which is
55
+ * collapsed.
56
+ */
57
+ get isCollapsed(): boolean;
58
+ /**
59
+ * Selection anchor. Anchor may be described as a position where the most recent part of the selection starts.
60
+ * Together with {@link #focus} they define the direction of selection, which is important
61
+ * when expanding/shrinking selection. Anchor is always {@link module:engine/model/range~ModelRange#start start} or
62
+ * {@link module:engine/model/range~ModelRange#end end} position of the most recently added range.
63
+ *
64
+ * Is set to `null` if there are no ranges in selection.
65
+ *
66
+ * @see #focus
67
+ */
68
+ get anchor(): ModelPosition | null;
69
+ /**
70
+ * Selection focus. Focus is a position where the selection ends.
71
+ *
72
+ * Is set to `null` if there are no ranges in selection.
73
+ *
74
+ * @see #anchor
75
+ */
76
+ get focus(): ModelPosition | null;
77
+ /**
78
+ * Number of ranges in selection.
79
+ */
80
+ get rangeCount(): number;
81
+ /**
82
+ * Describes whether `Documentselection` has own range(s) set, or if it is defaulted to
83
+ * {@link module:engine/model/document~ModelDocument#_getDefaultRange document's default range}.
84
+ */
85
+ get hasOwnRange(): boolean;
86
+ /**
87
+ * Specifies whether the {@link #focus}
88
+ * precedes {@link #anchor}.
89
+ *
90
+ * @readonly
91
+ * @type {Boolean}
92
+ */
93
+ get isBackward(): boolean;
94
+ /**
95
+ * Describes whether the gravity is overridden (using {@link module:engine/model/writer~ModelWriter#overrideSelectionGravity}) or not.
96
+ *
97
+ * Note that the gravity remains overridden as long as will not be restored the same number of times as it was overridden.
98
+ */
99
+ get isGravityOverridden(): boolean;
100
+ /**
101
+ * A collection of selection {@link module:engine/model/markercollection~Marker markers}.
102
+ * Marker is a selection marker when selection range is inside the marker range.
103
+ *
104
+ * **Note**: Only markers from {@link ~ModelDocumentSelection#observeMarkers observed markers groups} are collected.
105
+ */
106
+ get markers(): Collection<Marker>;
107
+ /**
108
+ * Used for the compatibility with the {@link module:engine/model/selection~ModelSelection#isEqual} method.
109
+ *
110
+ * @internal
111
+ */
112
+ get _ranges(): Array<ModelRange>;
113
+ /**
114
+ * Returns an iterable that iterates over copies of selection ranges.
115
+ */
116
+ getRanges(): IterableIterator<ModelRange>;
117
+ /**
118
+ * Returns the first position in the selection.
119
+ * First position is the position that {@link module:engine/model/position~ModelPosition#isBefore is before}
120
+ * any other position in the selection.
121
+ *
122
+ * Returns `null` if there are no ranges in selection.
123
+ */
124
+ getFirstPosition(): ModelPosition | null;
125
+ /**
126
+ * Returns the last position in the selection.
127
+ * Last position is the position that {@link module:engine/model/position~ModelPosition#isAfter is after}
128
+ * any other position in the selection.
129
+ *
130
+ * Returns `null` if there are no ranges in selection.
131
+ */
132
+ getLastPosition(): ModelPosition | null;
133
+ /**
134
+ * Returns a copy of the first range in the selection.
135
+ * First range is the one which {@link module:engine/model/range~ModelRange#start start} position
136
+ * {@link module:engine/model/position~ModelPosition#isBefore is before} start position of all other ranges
137
+ * (not to confuse with the first range added to the selection).
138
+ *
139
+ * Returns `null` if there are no ranges in selection.
140
+ */
141
+ getFirstRange(): ModelRange | null;
142
+ /**
143
+ * Returns a copy of the last range in the selection.
144
+ * Last range is the one which {@link module:engine/model/range~ModelRange#end end} position
145
+ * {@link module:engine/model/position~ModelPosition#isAfter is after} end position of all
146
+ * other ranges (not to confuse with the range most recently added to the selection).
147
+ *
148
+ * Returns `null` if there are no ranges in selection.
149
+ */
150
+ getLastRange(): ModelRange | null;
151
+ /**
152
+ * Gets elements of type {@link module:engine/model/schema~ModelSchema#isBlock "block"} touched by the selection.
153
+ *
154
+ * This method's result can be used for example to apply block styling to all blocks covered by this selection.
155
+ *
156
+ * **Note:** `getSelectedBlocks()` returns blocks that are nested in other non-block elements
157
+ * but will not return blocks nested in other blocks.
158
+ *
159
+ * In this case the function will return exactly all 3 paragraphs (note: `<blockQuote>` is not a block itself):
160
+ *
161
+ * ```
162
+ * <paragraph>[a</paragraph>
163
+ * <blockQuote>
164
+ * <paragraph>b</paragraph>
165
+ * </blockQuote>
166
+ * <paragraph>c]d</paragraph>
167
+ * ```
168
+ *
169
+ * In this case the paragraph will also be returned, despite the collapsed selection:
170
+ *
171
+ * ```
172
+ * <paragraph>[]a</paragraph>
173
+ * ```
174
+ *
175
+ * In such a scenario, however, only blocks A, B & E will be returned as blocks C & D are nested in block B:
176
+ *
177
+ * ```
178
+ * [<blockA></blockA>
179
+ * <blockB>
180
+ * <blockC></blockC>
181
+ * <blockD></blockD>
182
+ * </blockB>
183
+ * <blockE></blockE>]
184
+ * ```
185
+ *
186
+ * If the selection is inside a block all the inner blocks (A & B) are returned:
187
+ *
188
+ * ```
189
+ * <block>
190
+ * <blockA>[a</blockA>
191
+ * <blockB>b]</blockB>
192
+ * </block>
193
+ * ```
194
+ *
195
+ * **Special case**: If a selection ends at the beginning of a block, that block is not returned as from user perspective
196
+ * this block wasn't selected. See [#984](https://github.com/ckeditor/ckeditor5-engine/issues/984) for more details.
197
+ *
198
+ * ```
199
+ * <paragraph>[a</paragraph>
200
+ * <paragraph>b</paragraph>
201
+ * <paragraph>]c</paragraph> // this block will not be returned
202
+ * ```
203
+ */
204
+ getSelectedBlocks(): IterableIterator<ModelElement>;
205
+ /**
206
+ * Returns the selected element. {@link module:engine/model/element~ModelElement Element} is considered as selected if there is only
207
+ * one range in the selection, and that range contains exactly one element.
208
+ * Returns `null` if there is no selected element.
209
+ */
210
+ getSelectedElement(): ModelElement | null;
211
+ /**
212
+ * Checks whether the selection contains the entire content of the given element. This means that selection must start
213
+ * at a position {@link module:engine/model/position~ModelPosition#isTouching touching} the element's start and ends at position
214
+ * touching the element's end.
215
+ *
216
+ * By default, this method will check whether the entire content of the selection's current root is selected.
217
+ * Useful to check if e.g. the user has just pressed <kbd>Ctrl</kbd> + <kbd>A</kbd>.
218
+ */
219
+ containsEntireContent(element: ModelElement): boolean;
220
+ /**
221
+ * Unbinds all events previously bound by document selection.
222
+ */
223
+ destroy(): void;
224
+ /**
225
+ * Returns iterable that iterates over this selection's attribute keys.
226
+ */
227
+ getAttributeKeys(): IterableIterator<string>;
228
+ /**
229
+ * Returns iterable that iterates over this selection's attributes.
230
+ *
231
+ * Attributes are returned as arrays containing two items. First one is attribute key and second is attribute value.
232
+ * This format is accepted by native `Map` object and also can be passed in `Node` constructor.
233
+ */
234
+ getAttributes(): IterableIterator<[string, unknown]>;
235
+ /**
236
+ * Gets an attribute value for given key or `undefined` if that attribute is not set on the selection.
237
+ *
238
+ * @param key Key of attribute to look for.
239
+ * @returns Attribute value or `undefined`.
240
+ */
241
+ getAttribute(key: string): unknown;
242
+ /**
243
+ * Checks if the selection has an attribute for given key.
244
+ *
245
+ * @param key Key of attribute to check.
246
+ * @returns `true` if attribute with given key is set on selection, `false` otherwise.
247
+ */
248
+ hasAttribute(key: string): boolean;
249
+ /**
250
+ * Refreshes selection attributes and markers according to the current position in the model.
251
+ */
252
+ refresh(): void;
253
+ /**
254
+ * Registers a marker group prefix or a marker name to be collected in the
255
+ * {@link ~ModelDocumentSelection#markers selection markers collection}.
256
+ *
257
+ * See also {@link module:engine/model/markercollection~MarkerCollection#getMarkersGroup `MarkerCollection#getMarkersGroup()`}.
258
+ *
259
+ * @param prefixOrName The marker group prefix or marker name.
260
+ */
261
+ observeMarkers(prefixOrName: string): void;
262
+ /**
263
+ * Converts `DocumentSelection` to plain object and returns it.
264
+ *
265
+ * @returns `DocumentSelection` converted to plain object.
266
+ */
267
+ toJSON(): unknown;
268
+ /**
269
+ * Moves {@link module:engine/model/documentselection~ModelDocumentSelection#focus} to the specified location.
270
+ * Should be used only within the {@link module:engine/model/writer~ModelWriter#setSelectionFocus} method.
271
+ *
272
+ * The location can be specified in the same form as
273
+ * {@link module:engine/model/writer~ModelWriter#createPositionAt writer.createPositionAt()} parameters.
274
+ *
275
+ * @see module:engine/model/writer~ModelWriter#setSelectionFocus
276
+ * @internal
277
+ * @param offset Offset or one of the flags. Used only when
278
+ * first parameter is a {@link module:engine/model/item~ModelItem model item}.
279
+ */
280
+ _setFocus(itemOrPosition: ModelItem | ModelPosition, offset?: ModelPositionOffset): void;
281
+ /**
282
+ * Sets this selection's ranges and direction to the specified location based on the given
283
+ * {@link module:engine/model/selection~ModelSelectable selectable}.
284
+ * Should be used only within the {@link module:engine/model/writer~ModelWriter#setSelection} method.
285
+ *
286
+ * @see module:engine/model/writer~ModelWriter#setSelection
287
+ * @internal
288
+ */
289
+ _setTo(...args: Parameters<ModelSelection["setTo"]>): void;
290
+ /**
291
+ * Sets attribute on the selection. If attribute with the same key already is set, it's value is overwritten.
292
+ * Should be used only within the {@link module:engine/model/writer~ModelWriter#setSelectionAttribute} method.
293
+ *
294
+ * @see module:engine/model/writer~ModelWriter#setSelectionAttribute
295
+ * @internal
296
+ * @param key Key of the attribute to set.
297
+ * @param value Attribute value.
298
+ */
299
+ _setAttribute(key: string, value: unknown): void;
300
+ /**
301
+ * Removes an attribute with given key from the selection.
302
+ * If the given attribute was set on the selection, fires the {@link module:engine/model/selection~ModelSelection#event:change:range}
303
+ * event with removed attribute key.
304
+ * Should be used only within the {@link module:engine/model/writer~ModelWriter#removeSelectionAttribute} method.
305
+ *
306
+ * @see module:engine/model/writer~ModelWriter#removeSelectionAttribute
307
+ * @internal
308
+ * @param key Key of the attribute to remove.
309
+ */
310
+ _removeAttribute(key: string): void;
311
+ /**
312
+ * Returns an iterable that iterates through all selection attributes stored in current selection's parent.
313
+ *
314
+ * @internal
315
+ */
316
+ _getStoredAttributes(): Iterable<[string, unknown]>;
317
+ /**
318
+ * Temporarily changes the gravity of the selection from the left to the right.
319
+ *
320
+ * The gravity defines from which direction the selection inherits its attributes. If it's the default left
321
+ * gravity, the selection (after being moved by the the user) inherits attributes from its left hand side.
322
+ * This method allows to temporarily override this behavior by forcing the gravity to the right.
323
+ *
324
+ * It returns an unique identifier which is required to restore the gravity. It guarantees the symmetry
325
+ * of the process.
326
+ *
327
+ * @see module:engine/model/writer~ModelWriter#overrideSelectionGravity
328
+ * @internal
329
+ * @returns The unique id which allows restoring the gravity.
330
+ */
331
+ _overrideGravity(): string;
332
+ /**
333
+ * Restores the {@link ~ModelDocumentSelection#_overrideGravity overridden gravity}.
334
+ *
335
+ * Restoring the gravity is only possible using the unique identifier returned by
336
+ * {@link ~ModelDocumentSelection#_overrideGravity}. Note that the gravity remains overridden as long as won't be restored
337
+ * the same number of times it was overridden.
338
+ *
339
+ * @see module:engine/model/writer~ModelWriter#restoreSelectionGravity
340
+ * @internal
341
+ * @param uid The unique id returned by {@link #_overrideGravity}.
342
+ */
343
+ _restoreGravity(uid: string): void;
344
+ /**
345
+ * Generates and returns an attribute key for selection attributes store, basing on original attribute key.
346
+ *
347
+ * @internal
348
+ * @param key Attribute key to convert.
349
+ * @returns Converted attribute key, applicable for selection store.
350
+ */
351
+ static _getStoreAttributeKey(key: string): string;
352
+ /**
353
+ * Checks whether the given attribute key is an attribute stored on an element.
354
+ *
355
+ * @internal
356
+ */
357
+ static _isStoreAttributeKey(key: string): boolean;
358
358
  }
359
359
  /**
360
- * Fired when selection range(s) changed.
361
- *
362
- * @eventName ~ModelDocumentSelection#change:range
363
- * @param directChange In case of {@link module:engine/model/selection~ModelSelection} class it is always set
364
- * to `true` which indicates that the selection change was caused by a direct use of selection's API.
365
- * The {@link module:engine/model/documentselection~ModelDocumentSelection}, however, may change because its position
366
- * was directly changed through the {@link module:engine/model/writer~ModelWriter writer} or because its position was
367
- * changed because the structure of the model has been changed (which means an indirect change).
368
- * The indirect change does not occur in case of normal (detached) selections because they are "static" (as "not live")
369
- * which mean that they are not updated once the document changes.
370
- */
360
+ * Fired when selection range(s) changed.
361
+ *
362
+ * @eventName ~ModelDocumentSelection#change:range
363
+ * @param directChange In case of {@link module:engine/model/selection~ModelSelection} class it is always set
364
+ * to `true` which indicates that the selection change was caused by a direct use of selection's API.
365
+ * The {@link module:engine/model/documentselection~ModelDocumentSelection}, however, may change because its position
366
+ * was directly changed through the {@link module:engine/model/writer~ModelWriter writer} or because its position was
367
+ * changed because the structure of the model has been changed (which means an indirect change).
368
+ * The indirect change does not occur in case of normal (detached) selections because they are "static" (as "not live")
369
+ * which mean that they are not updated once the document changes.
370
+ */
371
371
  export type ModelDocumentSelectionChangeRangeEvent = ModelSelectionChangeRangeEvent;
372
372
  /**
373
- * Fired when selection attribute changed.
374
- *
375
- * @eventName ~ModelDocumentSelection#change:attribute
376
- * @param directChange In case of {@link module:engine/model/selection~ModelSelection} class it is always set
377
- * to `true` which indicates that the selection change was caused by a direct use of selection's API.
378
- * The {@link module:engine/model/documentselection~ModelDocumentSelection}, however, may change because its attributes
379
- * were directly changed through the {@link module:engine/model/writer~ModelWriter writer} or because its position was
380
- * changed in the model and its attributes were refreshed (which means an indirect change).
381
- * The indirect change does not occur in case of normal (detached) selections because they are "static" (as "not live")
382
- * which mean that they are not updated once the document changes.
383
- * @param attributeKeys Array containing keys of attributes that changed.
373
+ * Fired when selection attribute changed.
374
+ *
375
+ * @eventName ~ModelDocumentSelection#change:attribute
376
+ * @param directChange In case of {@link module:engine/model/selection~ModelSelection} class it is always set
377
+ * to `true` which indicates that the selection change was caused by a direct use of selection's API.
378
+ * The {@link module:engine/model/documentselection~ModelDocumentSelection}, however, may change because its attributes
379
+ * were directly changed through the {@link module:engine/model/writer~ModelWriter writer} or because its position was
380
+ * changed in the model and its attributes were refreshed (which means an indirect change).
381
+ * The indirect change does not occur in case of normal (detached) selections because they are "static" (as "not live")
382
+ * which mean that they are not updated once the document changes.
383
+ * @param attributeKeys Array containing keys of attributes that changed.
384
384
  */
385
385
  export type ModelDocumentSelectionChangeAttributeEvent = ModelSelectionChangeAttributeEvent;
386
386
  /**
387
- * Fired when selection marker(s) changed.
388
- *
389
- * @eventName ~ModelDocumentSelection#change:marker
390
- * @param directChange This is always set to `false` in case of `change:marker` event as there is no possibility
391
- * to change markers directly through {@link module:engine/model/documentselection~ModelDocumentSelection} API.
392
- * See also {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:range} and
393
- * {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:attribute}.
394
- * @param oldMarkers Markers in which the selection was before the change.
395
- */
387
+ * Fired when selection marker(s) changed.
388
+ *
389
+ * @eventName ~ModelDocumentSelection#change:marker
390
+ * @param directChange This is always set to `false` in case of `change:marker` event as there is no possibility
391
+ * to change markers directly through {@link module:engine/model/documentselection~ModelDocumentSelection} API.
392
+ * See also {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:range} and
393
+ * {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:attribute}.
394
+ * @param oldMarkers Markers in which the selection was before the change.
395
+ */
396
396
  export type ModelDocumentSelectionChangeMarkerEvent = {
397
- name: 'change:marker';
398
- args: [
399
- {
400
- directChange: boolean;
401
- oldMarkers: Array<Marker>;
402
- }
403
- ];
397
+ name: "change:marker";
398
+ args: [{
399
+ directChange: boolean;
400
+ oldMarkers: Array<Marker>;
401
+ }];
404
402
  };
405
403
  /**
406
- * Fired when selection range(s), attribute(s) or marker(s) changed.
407
- *
408
- * @eventName ~ModelDocumentSelection#change
409
- * @param directChange This is always set to `false` in case of `change:marker` event as there is no possibility
410
- * to change markers directly through {@link module:engine/model/documentselection~ModelDocumentSelection} API.
411
- * See also {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:range} and
412
- * {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:attribute}.
413
- * @param attributeKeys Array containing keys of attributes that changed.
414
- * @param oldMarkers Markers in which the selection was before the change.
415
- */
404
+ * Fired when selection range(s), attribute(s) or marker(s) changed.
405
+ *
406
+ * @eventName ~ModelDocumentSelection#change
407
+ * @param directChange This is always set to `false` in case of `change:marker` event as there is no possibility
408
+ * to change markers directly through {@link module:engine/model/documentselection~ModelDocumentSelection} API.
409
+ * See also {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:range} and
410
+ * {@link module:engine/model/documentselection~ModelDocumentSelection#event:change:attribute}.
411
+ * @param attributeKeys Array containing keys of attributes that changed.
412
+ * @param oldMarkers Markers in which the selection was before the change.
413
+ */
416
414
  export type ModelDocumentSelectionChangeEvent = {
417
- name: 'change' | 'change:attribute' | 'change:marker' | 'change:range';
418
- args: [
419
- {
420
- directChange: boolean;
421
- attributeKeys?: Array<string>;
422
- oldMarkers?: Array<Marker>;
423
- }
424
- ];
415
+ name: "change" | "change:attribute" | "change:marker" | "change:range";
416
+ args: [{
417
+ directChange: boolean;
418
+ attributeKeys?: Array<string>;
419
+ oldMarkers?: Array<Marker>;
420
+ }];
425
421
  };
426
422
  export {};