@ckeditor/ckeditor5-engine 48.2.0-alpha.7 → 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,383 +1,370 @@
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/view/selection
7
- */
8
- import { ViewTypeCheckable } from './typecheckable.js';
9
- import { ViewRange } from './range.js';
10
- import { ViewPosition, type ViewPositionOffset } from './position.js';
11
- import { ViewNode } from './node.js';
12
- import { ViewDocumentSelection } from './documentselection.js';
13
- import { type ViewElement } from './element.js';
14
- import { type ViewItem } from './item.js';
15
- import { type ViewEditableElement } from './editableelement.js';
16
- declare const ViewSelection_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof ViewTypeCheckable, import("@ckeditor/ckeditor5-utils").Emitter>;
6
+ * @module engine/view/selection
7
+ */
8
+ import { ViewTypeCheckable } from "./typecheckable.js";
9
+ import { ViewRange } from "./range.js";
10
+ import { ViewPosition, type ViewPositionOffset } from "./position.js";
11
+ import { ViewNode } from "./node.js";
12
+ import { ViewDocumentSelection } from "./documentselection.js";
13
+ import { type EmitterMixinConstructor } from "@ckeditor/ckeditor5-utils";
14
+ import { type ViewElement } from "./element.js";
15
+ import { type ViewItem } from "./item.js";
16
+ import { type ViewEditableElement } from "./editableelement.js";
17
+ declare const ViewSelectionBase: EmitterMixinConstructor<typeof ViewTypeCheckable>;
17
18
  /**
18
- * Class representing an arbirtary selection in the view.
19
- * See also {@link module:engine/view/documentselection~ViewDocumentSelection}.
20
- *
21
- * New selection instances can be created via the constructor or one these methods:
22
- *
23
- * * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
24
- * * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
25
- *
26
- * A selection can consist of {@link module:engine/view/range~ViewRange ranges} that can be set by using
27
- * the {@link module:engine/view/selection~ViewSelection#setTo `Selection#setTo()`} method.
28
- */
29
- export declare class ViewSelection extends /* #__PURE__ */ ViewSelection_base {
30
- /**
31
- * Stores all ranges that are selected.
32
- */
33
- private _ranges;
34
- /**
35
- * Specifies whether the last added range was added as a backward or forward range.
36
- */
37
- private _lastRangeBackward;
38
- /**
39
- * Specifies whether selection instance is fake.
40
- */
41
- private _isFake;
42
- /**
43
- * Fake selection's label.
44
- */
45
- private _fakeSelectionLabel;
46
- /**
47
- * Creates new selection instance.
48
- *
49
- * **Note**: The selection constructor is available as a factory method:
50
- *
51
- * * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
52
- * * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
53
- *
54
- * ```ts
55
- * // Creates empty selection without ranges.
56
- * const selection = writer.createSelection();
57
- *
58
- * // Creates selection at the given range.
59
- * const range = writer.createRange( start, end );
60
- * const selection = writer.createSelection( range );
61
- *
62
- * // Creates selection at the given ranges
63
- * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
64
- * const selection = writer.createSelection( ranges );
65
- *
66
- * // Creates selection from the other selection.
67
- * const otherSelection = writer.createSelection();
68
- * const selection = writer.createSelection( otherSelection );
69
- *
70
- * // Creates selection from the document selection.
71
- * const selection = writer.createSelection( editor.editing.view.document.selection );
72
- *
73
- * // Creates selection at the given position.
74
- * const position = writer.createPositionFromPath( root, path );
75
- * const selection = writer.createSelection( position );
76
- *
77
- * // Creates collapsed selection at the position of given item and offset.
78
- * const paragraph = writer.createContainerElement( 'paragraph' );
79
- * const selection = writer.createSelection( paragraph, offset );
80
- *
81
- * // Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the
82
- * // first child of that element and ends after the last child of that element.
83
- * const selection = writer.createSelection( paragraph, 'in' );
84
- *
85
- * // Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends
86
- * // just after the item.
87
- * const selection = writer.createSelection( paragraph, 'on' );
88
- * ```
89
- *
90
- * `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
91
- *
92
- * ```ts
93
- * // Creates backward selection.
94
- * const selection = writer.createSelection( range, { backward: true } );
95
- * ```
96
- *
97
- * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
98
- * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
99
- * represented in other way, for example by applying proper CSS class.
100
- *
101
- * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
102
- * (and be properly handled by screen readers).
103
- *
104
- * ```ts
105
- * // Creates fake selection with label.
106
- * const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
107
- * ```
108
- *
109
- * @internal
110
- */
111
- constructor(...args: [] | [
112
- selectable: ViewNode,
113
- placeOrOffset: ViewPlaceOrOffset,
114
- options?: ViewSelectionOptions
115
- ] | [
116
- selectable?: Exclude<ViewSelectable, ViewNode>,
117
- options?: ViewSelectionOptions
118
- ]);
119
- /**
120
- * Returns true if selection instance is marked as `fake`.
121
- *
122
- * @see #setTo
123
- */
124
- get isFake(): boolean;
125
- /**
126
- * Returns fake selection label.
127
- *
128
- * @see #setTo
129
- */
130
- get fakeSelectionLabel(): string;
131
- /**
132
- * Selection anchor. Anchor may be described as a position where the selection starts. Together with
133
- * {@link #focus focus} they define the direction of selection, which is important
134
- * when expanding/shrinking selection. Anchor is always the start or end of the most recent added range.
135
- * It may be a bit unintuitive when there are multiple ranges in selection.
136
- *
137
- * @see #focus
138
- */
139
- get anchor(): ViewPosition | null;
140
- /**
141
- * Selection focus. Focus is a position where the selection ends.
142
- *
143
- * @see #anchor
144
- */
145
- get focus(): ViewPosition | null;
146
- /**
147
- * Returns whether the selection is collapsed. Selection is collapsed when there is exactly one range which is
148
- * collapsed.
149
- */
150
- get isCollapsed(): boolean;
151
- /**
152
- * Returns number of ranges in selection.
153
- */
154
- get rangeCount(): number;
155
- /**
156
- * Specifies whether the {@link #focus} precedes {@link #anchor}.
157
- */
158
- get isBackward(): boolean;
159
- /**
160
- * {@link module:engine/view/editableelement~ViewEditableElement ViewEditableElement} instance that contains this selection, or `null`
161
- * if the selection is not inside an editable element.
162
- */
163
- get editableElement(): ViewEditableElement | null;
164
- /**
165
- * Returns an iterable that contains copies of all ranges added to the selection.
166
- */
167
- getRanges(): IterableIterator<ViewRange>;
168
- /**
169
- * Returns copy of the first range in the selection. First range is the one which
170
- * {@link module:engine/view/range~ViewRange#start start} position
171
- * {@link module:engine/view/position~ViewPosition#isBefore is before} start
172
- * position of all other ranges (not to confuse with the first range added to the selection).
173
- * Returns `null` if no ranges are added to selection.
174
- */
175
- getFirstRange(): ViewRange | null;
176
- /**
177
- * Returns copy of the last range in the selection. Last range is the one which {@link module:engine/view/range~ViewRange#end end}
178
- * position {@link module:engine/view/position~ViewPosition#isAfter is after} end position of all other ranges (not to confuse
179
- * with the last range added to the selection). Returns `null` if no ranges are added to selection.
180
- */
181
- getLastRange(): ViewRange | null;
182
- /**
183
- * Returns copy of the first position in the selection. First position is the position that
184
- * {@link module:engine/view/position~ViewPosition#isBefore is before} any other position in the selection ranges.
185
- * Returns `null` if no ranges are added to selection.
186
- */
187
- getFirstPosition(): ViewPosition | null;
188
- /**
189
- * Returns copy of the last position in the selection. Last position is the position that
190
- * {@link module:engine/view/position~ViewPosition#isAfter is after} any other position in the selection ranges.
191
- * Returns `null` if no ranges are added to selection.
192
- */
193
- getLastPosition(): ViewPosition | null;
194
- /**
195
- * Checks whether, this selection is equal to given selection. Selections are equal if they have same directions,
196
- * same number of ranges and all ranges from one selection equal to a range from other selection.
197
- *
198
- * @param otherSelection Selection to compare with.
199
- * @returns `true` if selections are equal, `false` otherwise.
200
- */
201
- isEqual(otherSelection: ViewSelection | ViewDocumentSelection): boolean;
202
- /**
203
- * Checks whether this selection is similar to given selection. Selections are similar if they have same directions, same
204
- * number of ranges, and all {@link module:engine/view/range~ViewRange#getTrimmed trimmed} ranges from one selection are
205
- * equal to any trimmed range from other selection.
206
- *
207
- * @param otherSelection Selection to compare with.
208
- * @returns `true` if selections are similar, `false` otherwise.
209
- */
210
- isSimilar(otherSelection: ViewSelection | ViewDocumentSelection): boolean;
211
- /**
212
- * Returns the selected element. {@link module:engine/view/element~ViewElement Element} is considered as selected if there is only
213
- * one range in the selection, and that range contains exactly one element.
214
- * Returns `null` if there is no selected element.
215
- */
216
- getSelectedElement(): ViewElement | null;
217
- /**
218
- * Sets this selection's ranges and direction to the specified location based on the given
219
- * {@link module:engine/view/selection~ViewSelectable selectable}.
220
- *
221
- * ```ts
222
- * // Sets selection to the given range.
223
- * const range = writer.createRange( start, end );
224
- * selection.setTo( range );
225
- *
226
- * // Sets selection to given ranges.
227
- * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
228
- * selection.setTo( range );
229
- *
230
- * // Sets selection to the other selection.
231
- * const otherSelection = writer.createSelection();
232
- * selection.setTo( otherSelection );
233
- *
234
- * // Sets selection to contents of ViewDocumentSelection.
235
- * selection.setTo( editor.editing.view.document.selection );
236
- *
237
- * // Sets collapsed selection at the given position.
238
- * const position = writer.createPositionAt( root, path );
239
- * selection.setTo( position );
240
- *
241
- * // Sets collapsed selection at the position of given item and offset.
242
- * selection.setTo( paragraph, offset );
243
- * ```
244
- *
245
- * Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
246
- * that element and ends after the last child of that element.
247
- *
248
- * ```ts
249
- * selection.setTo( paragraph, 'in' );
250
- * ```
251
- *
252
- * Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
253
- *
254
- * ```ts
255
- * selection.setTo( paragraph, 'on' );
256
- *
257
- * // Clears selection. Removes all ranges.
258
- * selection.setTo( null );
259
- * ```
260
- *
261
- * `Selection#setTo()` method allow passing additional options (`backward`, `fake` and `label`) as the last argument.
262
- *
263
- * ```ts
264
- * // Sets selection as backward.
265
- * selection.setTo( range, { backward: true } );
266
- * ```
267
- *
268
- * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
269
- * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
270
- * represented in other way, for example by applying proper CSS class.
271
- *
272
- * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
273
- * (and be properly handled by screen readers).
274
- *
275
- * ```ts
276
- * // Creates fake selection with label.
277
- * selection.setTo( range, { fake: true, label: 'foo' } );
278
- * ```
279
- *
280
- * @fires change
281
- */
282
- setTo(...args: [
283
- selectable: ViewNode,
284
- placeOrOffset: ViewPlaceOrOffset,
285
- options?: ViewSelectionOptions
286
- ] | [
287
- selectable?: Exclude<ViewSelectable, ViewNode>,
288
- options?: ViewSelectionOptions
289
- ]): void;
290
- /**
291
- * Moves {@link #focus} to the specified location.
292
- *
293
- * The location can be specified in the same form as
294
- * {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
295
- * parameters.
296
- *
297
- * @fires change
298
- * @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~ViewItem view item}.
299
- */
300
- setFocus(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): void;
301
- /**
302
- * Converts `ViewSelection` instance to plain object and returns it.
303
- *
304
- * @returns `ViewSelection` instance converted to plain object.
305
- */
306
- toJSON(): unknown;
307
- /**
308
- * Replaces all ranges that were added to the selection with given array of ranges. Last range of the array
309
- * is treated like the last added range and is used to set {@link #anchor anchor} and {@link #focus focus}.
310
- * Accepts a flag describing in which way the selection is made.
311
- *
312
- * @param newRanges Iterable object of ranges to set.
313
- * @param isLastBackward Flag describing if last added range was selected forward - from start to end
314
- * (`false`) or backward - from end to start (`true`). Defaults to `false`.
315
- */
316
- private _setRanges;
317
- /**
318
- * Sets this selection instance to be marked as `fake`. A fake selection does not render as browser native selection
319
- * over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to
320
- * the user and selection over elements can be represented in other way, for example by applying proper CSS class.
321
- *
322
- * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be
323
- * properly handled by screen readers).
324
- */
325
- private _setFakeOptions;
326
- /**
327
- * Adds a range to the selection. Added range is copied. This means that passed range is not saved in the
328
- * selection instance and you can safely operate on it.
329
- *
330
- * Accepts a flag describing in which way the selection is made - passed range might be selected from
331
- * {@link module:engine/view/range~ViewRange#start start} to {@link module:engine/view/range~ViewRange#end end}
332
- * or from {@link module:engine/view/range~ViewRange#end end} to {@link module:engine/view/range~ViewRange#start start}.
333
- * The flag is used to set {@link #anchor anchor} and {@link #focus focus} properties.
334
- *
335
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
336
- * with ranges already stored in Selection instance.
337
- */
338
- private _addRange;
339
- /**
340
- * Adds range to selection - creates copy of given range so it can be safely used and modified.
341
- *
342
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
343
- * with ranges already stored in selection instance.
344
- */
345
- private _pushRange;
19
+ * Class representing an arbirtary selection in the view.
20
+ * See also {@link module:engine/view/documentselection~ViewDocumentSelection}.
21
+ *
22
+ * New selection instances can be created via the constructor or one these methods:
23
+ *
24
+ * * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
25
+ * * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
26
+ *
27
+ * A selection can consist of {@link module:engine/view/range~ViewRange ranges} that can be set by using
28
+ * the {@link module:engine/view/selection~ViewSelection#setTo `Selection#setTo()`} method.
29
+ */
30
+ export declare class ViewSelection extends ViewSelectionBase {
31
+ /**
32
+ * Stores all ranges that are selected.
33
+ */
34
+ private _ranges;
35
+ /**
36
+ * Specifies whether the last added range was added as a backward or forward range.
37
+ */
38
+ private _lastRangeBackward;
39
+ /**
40
+ * Specifies whether selection instance is fake.
41
+ */
42
+ private _isFake;
43
+ /**
44
+ * Fake selection's label.
45
+ */
46
+ private _fakeSelectionLabel;
47
+ /**
48
+ * Creates new selection instance.
49
+ *
50
+ * **Note**: The selection constructor is available as a factory method:
51
+ *
52
+ * * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
53
+ * * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
54
+ *
55
+ * ```ts
56
+ * // Creates empty selection without ranges.
57
+ * const selection = writer.createSelection();
58
+ *
59
+ * // Creates selection at the given range.
60
+ * const range = writer.createRange( start, end );
61
+ * const selection = writer.createSelection( range );
62
+ *
63
+ * // Creates selection at the given ranges
64
+ * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
65
+ * const selection = writer.createSelection( ranges );
66
+ *
67
+ * // Creates selection from the other selection.
68
+ * const otherSelection = writer.createSelection();
69
+ * const selection = writer.createSelection( otherSelection );
70
+ *
71
+ * // Creates selection from the document selection.
72
+ * const selection = writer.createSelection( editor.editing.view.document.selection );
73
+ *
74
+ * // Creates selection at the given position.
75
+ * const position = writer.createPositionFromPath( root, path );
76
+ * const selection = writer.createSelection( position );
77
+ *
78
+ * // Creates collapsed selection at the position of given item and offset.
79
+ * const paragraph = writer.createContainerElement( 'paragraph' );
80
+ * const selection = writer.createSelection( paragraph, offset );
81
+ *
82
+ * // Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the
83
+ * // first child of that element and ends after the last child of that element.
84
+ * const selection = writer.createSelection( paragraph, 'in' );
85
+ *
86
+ * // Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends
87
+ * // just after the item.
88
+ * const selection = writer.createSelection( paragraph, 'on' );
89
+ * ```
90
+ *
91
+ * `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
92
+ *
93
+ * ```ts
94
+ * // Creates backward selection.
95
+ * const selection = writer.createSelection( range, { backward: true } );
96
+ * ```
97
+ *
98
+ * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
99
+ * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
100
+ * represented in other way, for example by applying proper CSS class.
101
+ *
102
+ * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
103
+ * (and be properly handled by screen readers).
104
+ *
105
+ * ```ts
106
+ * // Creates fake selection with label.
107
+ * const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
108
+ * ```
109
+ *
110
+ * @internal
111
+ */
112
+ constructor(...args: [] | [selectable: ViewNode, placeOrOffset: ViewPlaceOrOffset, options?: ViewSelectionOptions] | [selectable?: Exclude<ViewSelectable, ViewNode>, options?: ViewSelectionOptions]);
113
+ /**
114
+ * Returns true if selection instance is marked as `fake`.
115
+ *
116
+ * @see #setTo
117
+ */
118
+ get isFake(): boolean;
119
+ /**
120
+ * Returns fake selection label.
121
+ *
122
+ * @see #setTo
123
+ */
124
+ get fakeSelectionLabel(): string;
125
+ /**
126
+ * Selection anchor. Anchor may be described as a position where the selection starts. Together with
127
+ * {@link #focus focus} they define the direction of selection, which is important
128
+ * when expanding/shrinking selection. Anchor is always the start or end of the most recent added range.
129
+ * It may be a bit unintuitive when there are multiple ranges in selection.
130
+ *
131
+ * @see #focus
132
+ */
133
+ get anchor(): ViewPosition | null;
134
+ /**
135
+ * Selection focus. Focus is a position where the selection ends.
136
+ *
137
+ * @see #anchor
138
+ */
139
+ get focus(): ViewPosition | null;
140
+ /**
141
+ * Returns whether the selection is collapsed. Selection is collapsed when there is exactly one range which is
142
+ * collapsed.
143
+ */
144
+ get isCollapsed(): boolean;
145
+ /**
146
+ * Returns number of ranges in selection.
147
+ */
148
+ get rangeCount(): number;
149
+ /**
150
+ * Specifies whether the {@link #focus} precedes {@link #anchor}.
151
+ */
152
+ get isBackward(): boolean;
153
+ /**
154
+ * {@link module:engine/view/editableelement~ViewEditableElement ViewEditableElement} instance that contains this selection, or `null`
155
+ * if the selection is not inside an editable element.
156
+ */
157
+ get editableElement(): ViewEditableElement | null;
158
+ /**
159
+ * Returns an iterable that contains copies of all ranges added to the selection.
160
+ */
161
+ getRanges(): IterableIterator<ViewRange>;
162
+ /**
163
+ * Returns copy of the first range in the selection. First range is the one which
164
+ * {@link module:engine/view/range~ViewRange#start start} position
165
+ * {@link module:engine/view/position~ViewPosition#isBefore is before} start
166
+ * position of all other ranges (not to confuse with the first range added to the selection).
167
+ * Returns `null` if no ranges are added to selection.
168
+ */
169
+ getFirstRange(): ViewRange | null;
170
+ /**
171
+ * Returns copy of the last range in the selection. Last range is the one which {@link module:engine/view/range~ViewRange#end end}
172
+ * position {@link module:engine/view/position~ViewPosition#isAfter is after} end position of all other ranges (not to confuse
173
+ * with the last range added to the selection). Returns `null` if no ranges are added to selection.
174
+ */
175
+ getLastRange(): ViewRange | null;
176
+ /**
177
+ * Returns copy of the first position in the selection. First position is the position that
178
+ * {@link module:engine/view/position~ViewPosition#isBefore is before} any other position in the selection ranges.
179
+ * Returns `null` if no ranges are added to selection.
180
+ */
181
+ getFirstPosition(): ViewPosition | null;
182
+ /**
183
+ * Returns copy of the last position in the selection. Last position is the position that
184
+ * {@link module:engine/view/position~ViewPosition#isAfter is after} any other position in the selection ranges.
185
+ * Returns `null` if no ranges are added to selection.
186
+ */
187
+ getLastPosition(): ViewPosition | null;
188
+ /**
189
+ * Checks whether, this selection is equal to given selection. Selections are equal if they have same directions,
190
+ * same number of ranges and all ranges from one selection equal to a range from other selection.
191
+ *
192
+ * @param otherSelection Selection to compare with.
193
+ * @returns `true` if selections are equal, `false` otherwise.
194
+ */
195
+ isEqual(otherSelection: ViewSelection | ViewDocumentSelection): boolean;
196
+ /**
197
+ * Checks whether this selection is similar to given selection. Selections are similar if they have same directions, same
198
+ * number of ranges, and all {@link module:engine/view/range~ViewRange#getTrimmed trimmed} ranges from one selection are
199
+ * equal to any trimmed range from other selection.
200
+ *
201
+ * @param otherSelection Selection to compare with.
202
+ * @returns `true` if selections are similar, `false` otherwise.
203
+ */
204
+ isSimilar(otherSelection: ViewSelection | ViewDocumentSelection): boolean;
205
+ /**
206
+ * Returns the selected element. {@link module:engine/view/element~ViewElement 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(): ViewElement | null;
211
+ /**
212
+ * Sets this selection's ranges and direction to the specified location based on the given
213
+ * {@link module:engine/view/selection~ViewSelectable selectable}.
214
+ *
215
+ * ```ts
216
+ * // Sets selection to the given range.
217
+ * const range = writer.createRange( start, end );
218
+ * selection.setTo( range );
219
+ *
220
+ * // Sets selection to given ranges.
221
+ * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
222
+ * selection.setTo( range );
223
+ *
224
+ * // Sets selection to the other selection.
225
+ * const otherSelection = writer.createSelection();
226
+ * selection.setTo( otherSelection );
227
+ *
228
+ * // Sets selection to contents of ViewDocumentSelection.
229
+ * selection.setTo( editor.editing.view.document.selection );
230
+ *
231
+ * // Sets collapsed selection at the given position.
232
+ * const position = writer.createPositionAt( root, path );
233
+ * selection.setTo( position );
234
+ *
235
+ * // Sets collapsed selection at the position of given item and offset.
236
+ * selection.setTo( paragraph, offset );
237
+ * ```
238
+ *
239
+ * Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
240
+ * that element and ends after the last child of that element.
241
+ *
242
+ * ```ts
243
+ * selection.setTo( paragraph, 'in' );
244
+ * ```
245
+ *
246
+ * Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
247
+ *
248
+ * ```ts
249
+ * selection.setTo( paragraph, 'on' );
250
+ *
251
+ * // Clears selection. Removes all ranges.
252
+ * selection.setTo( null );
253
+ * ```
254
+ *
255
+ * `Selection#setTo()` method allow passing additional options (`backward`, `fake` and `label`) as the last argument.
256
+ *
257
+ * ```ts
258
+ * // Sets selection as backward.
259
+ * selection.setTo( range, { backward: true } );
260
+ * ```
261
+ *
262
+ * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
263
+ * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
264
+ * represented in other way, for example by applying proper CSS class.
265
+ *
266
+ * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
267
+ * (and be properly handled by screen readers).
268
+ *
269
+ * ```ts
270
+ * // Creates fake selection with label.
271
+ * selection.setTo( range, { fake: true, label: 'foo' } );
272
+ * ```
273
+ *
274
+ * @fires change
275
+ */
276
+ setTo(...args: [selectable: ViewNode, placeOrOffset: ViewPlaceOrOffset, options?: ViewSelectionOptions] | [selectable?: Exclude<ViewSelectable, ViewNode>, options?: ViewSelectionOptions]): void;
277
+ /**
278
+ * Moves {@link #focus} to the specified location.
279
+ *
280
+ * The location can be specified in the same form as
281
+ * {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
282
+ * parameters.
283
+ *
284
+ * @fires change
285
+ * @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~ViewItem view item}.
286
+ */
287
+ setFocus(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): void;
288
+ /**
289
+ * Converts `ViewSelection` instance to plain object and returns it.
290
+ *
291
+ * @returns `ViewSelection` instance converted to plain object.
292
+ */
293
+ toJSON(): unknown;
294
+ /**
295
+ * Replaces all ranges that were added to the selection with given array of ranges. Last range of the array
296
+ * is treated like the last added range and is used to set {@link #anchor anchor} and {@link #focus focus}.
297
+ * Accepts a flag describing in which way the selection is made.
298
+ *
299
+ * @param newRanges Iterable object of ranges to set.
300
+ * @param isLastBackward Flag describing if last added range was selected forward - from start to end
301
+ * (`false`) or backward - from end to start (`true`). Defaults to `false`.
302
+ */
303
+ private _setRanges;
304
+ /**
305
+ * Sets this selection instance to be marked as `fake`. A fake selection does not render as browser native selection
306
+ * over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to
307
+ * the user and selection over elements can be represented in other way, for example by applying proper CSS class.
308
+ *
309
+ * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be
310
+ * properly handled by screen readers).
311
+ */
312
+ private _setFakeOptions;
313
+ /**
314
+ * Adds a range to the selection. Added range is copied. This means that passed range is not saved in the
315
+ * selection instance and you can safely operate on it.
316
+ *
317
+ * Accepts a flag describing in which way the selection is made - passed range might be selected from
318
+ * {@link module:engine/view/range~ViewRange#start start} to {@link module:engine/view/range~ViewRange#end end}
319
+ * or from {@link module:engine/view/range~ViewRange#end end} to {@link module:engine/view/range~ViewRange#start start}.
320
+ * The flag is used to set {@link #anchor anchor} and {@link #focus focus} properties.
321
+ *
322
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
323
+ * with ranges already stored in Selection instance.
324
+ */
325
+ private _addRange;
326
+ /**
327
+ * Adds range to selection - creates copy of given range so it can be safely used and modified.
328
+ *
329
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
330
+ * with ranges already stored in selection instance.
331
+ */
332
+ private _pushRange;
346
333
  }
347
334
  /**
348
- * Additional options for {@link ~ViewSelection}.
349
- */
335
+ * Additional options for {@link ~ViewSelection}.
336
+ */
350
337
  export interface ViewSelectionOptions {
351
- /**
352
- * Sets this selection instance to be backward.
353
- */
354
- backward?: boolean;
355
- /**
356
- * Sets this selection instance to be marked as `fake`.
357
- */
358
- fake?: boolean;
359
- /**
360
- * Label for the fake selection.
361
- */
362
- label?: string;
338
+ /**
339
+ * Sets this selection instance to be backward.
340
+ */
341
+ backward?: boolean;
342
+ /**
343
+ * Sets this selection instance to be marked as `fake`.
344
+ */
345
+ fake?: boolean;
346
+ /**
347
+ * Label for the fake selection.
348
+ */
349
+ label?: string;
363
350
  }
364
351
  /**
365
- * The place or offset of the selection.
366
- */
367
- export type ViewPlaceOrOffset = number | 'before' | 'end' | 'after' | 'on' | 'in';
352
+ * The place or offset of the selection.
353
+ */
354
+ export type ViewPlaceOrOffset = number | "before" | "end" | "after" | "on" | "in";
368
355
  /**
369
- * Fired whenever selection ranges are changed through {@link ~ViewSelection Selection API}.
370
- *
371
- * @eventName ~ViewSelection#change
372
- */
356
+ * Fired whenever selection ranges are changed through {@link ~ViewSelection Selection API}.
357
+ *
358
+ * @eventName ~ViewSelection#change
359
+ */
373
360
  export type ViewSelectionChangeEvent = {
374
- name: 'change';
375
- args: [];
361
+ name: "change";
362
+ args: [];
376
363
  };
377
364
  /**
378
- * An entity that is used to set selection.
379
- *
380
- * See also {@link module:engine/view/selection~ViewSelection#setTo}
381
- */
365
+ * An entity that is used to set selection.
366
+ *
367
+ * See also {@link module:engine/view/selection~ViewSelection#setTo}
368
+ */
382
369
  export type ViewSelectable = ViewSelection | ViewDocumentSelection | ViewPosition | Iterable<ViewRange> | ViewRange | ViewNode | null;
383
370
  export {};