@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,1014 +1,1014 @@
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/downcastwriter
7
- */
8
- import { ViewPosition, type ViewPositionOffset } from './position.js';
9
- import { ViewRange } from './range.js';
10
- import { ViewSelection, type ViewPlaceOrOffset, type ViewSelectable, type ViewSelectionOptions } from './selection.js';
11
- import { ViewContainerElement } from './containerelement.js';
12
- import { ViewAttributeElement } from './attributeelement.js';
13
- import { ViewEmptyElement } from './emptyelement.js';
14
- import { ViewUIElement } from './uielement.js';
15
- import { ViewRawElement } from './rawelement.js';
16
- import { type ArrayOrItem } from '@ckeditor/ckeditor5-utils';
17
- import { ViewDocumentFragment } from './documentfragment.js';
18
- import { ViewText } from './text.js';
19
- import { ViewEditableElement } from './editableelement.js';
20
- import { type ViewDocument } from './document.js';
21
- import { type ViewNode } from './node.js';
22
- import type { ViewElement, ViewElementAttributes } from './element.js';
23
- import { type ViewDomConverter } from './domconverter.js';
24
- import { type ViewItem } from './item.js';
25
- import type { DowncastSlotFilter } from '../conversion/downcasthelpers.js';
26
- import type { StyleValue } from './stylesmap.js';
6
+ * @module engine/view/downcastwriter
7
+ */
8
+ import { ViewPosition, type ViewPositionOffset } from "./position.js";
9
+ import { ViewRange } from "./range.js";
10
+ import { ViewSelection, type ViewPlaceOrOffset, type ViewSelectable, type ViewSelectionOptions } from "./selection.js";
11
+ import { ViewContainerElement } from "./containerelement.js";
12
+ import { ViewAttributeElement } from "./attributeelement.js";
13
+ import { ViewEmptyElement } from "./emptyelement.js";
14
+ import { ViewUIElement } from "./uielement.js";
15
+ import { ViewRawElement } from "./rawelement.js";
16
+ import { type ArrayOrItem } from "@ckeditor/ckeditor5-utils";
17
+ import { ViewDocumentFragment } from "./documentfragment.js";
18
+ import { ViewText } from "./text.js";
19
+ import { ViewEditableElement } from "./editableelement.js";
20
+ import { type ViewDocument } from "./document.js";
21
+ import { type ViewNode } from "./node.js";
22
+ import type { ViewElement, ViewElementAttributes } from "./element.js";
23
+ import { type ViewDomConverter } from "./domconverter.js";
24
+ import { type ViewItem } from "./item.js";
25
+ import type { DowncastSlotFilter } from "../conversion/downcasthelpers.js";
26
+ import type { StyleValue } from "./stylesmap.js";
27
27
  type DomDocument = globalThis.Document;
28
28
  type DomElement = globalThis.HTMLElement;
29
29
  /**
30
- * View downcast writer.
31
- *
32
- * It provides a set of methods used to manipulate view nodes.
33
- *
34
- * Do not create an instance of this writer manually. To modify a view structure, use
35
- * the {@link module:engine/view/view~EditingView#change `View#change()`} block.
36
- *
37
- * The `ViewDowncastWriter` is designed to work with semantic views which are the views that were/are being downcasted from the model.
38
- * To work with ordinary views (e.g. parsed from a pasted content) use the
39
- * {@link module:engine/view/upcastwriter~ViewUpcastWriter upcast writer}.
40
- *
41
- * Read more about changing the view in the {@glink framework/architecture/editing-engine#changing-the-view Changing the view}
42
- * section of the {@glink framework/architecture/editing-engine Editing engine architecture} guide.
43
- */
30
+ * View downcast writer.
31
+ *
32
+ * It provides a set of methods used to manipulate view nodes.
33
+ *
34
+ * Do not create an instance of this writer manually. To modify a view structure, use
35
+ * the {@link module:engine/view/view~EditingView#change `View#change()`} block.
36
+ *
37
+ * The `ViewDowncastWriter` is designed to work with semantic views which are the views that were/are being downcasted from the model.
38
+ * To work with ordinary views (e.g. parsed from a pasted content) use the
39
+ * {@link module:engine/view/upcastwriter~ViewUpcastWriter upcast writer}.
40
+ *
41
+ * Read more about changing the view in the {@glink framework/architecture/editing-engine#changing-the-view Changing the view}
42
+ * section of the {@glink framework/architecture/editing-engine Editing engine architecture} guide.
43
+ */
44
44
  export declare class ViewDowncastWriter {
45
- /**
46
- * The view document instance in which this writer operates.
47
- */
48
- readonly document: ViewDocument;
49
- /**
50
- * Holds references to the attribute groups that share the same {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
51
- * The keys are `id`s, the values are `Set`s holding {@link module:engine/view/attributeelement~ViewAttributeElement}s.
52
- */
53
- private readonly _cloneGroups;
54
- /**
55
- * The slot factory used by the `elementToStructure` downcast helper.
56
- */
57
- private _slotFactory;
58
- /**
59
- * @param document The view document instance.
60
- */
61
- constructor(document: ViewDocument);
62
- /**
63
- * Sets {@link module:engine/view/documentselection~ViewDocumentSelection selection's} ranges and direction to the
64
- * specified location based on the given {@link module:engine/view/selection~ViewSelectable selectable}.
65
- *
66
- * Usage:
67
- *
68
- * ```ts
69
- * // Sets collapsed selection at the position of given item and offset.
70
- * const paragraph = writer.createContainerElement( 'p' );
71
- * writer.setSelection( paragraph, offset );
72
- * ```
73
- *
74
- * Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
75
- * that element and ends after the last child of that element.
76
- *
77
- * ```ts
78
- * writer.setSelection( paragraph, 'in' );
79
- * ```
80
- *
81
- * Creates a range on the {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
82
- *
83
- * ```ts
84
- * writer.setSelection( paragraph, 'on' );
85
- * ```
86
- *
87
- * `ViewDowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.
88
- *
89
- * ```ts
90
- * // Sets selection as backward.
91
- * writer.setSelection( element, 'in', { backward: true } );
92
- *
93
- * // Sets selection as fake.
94
- * // Fake selection does not render as browser native selection over selected elements and is hidden to the user.
95
- * // This way, no native selection UI artifacts are displayed to the user and selection over elements can be
96
- * // represented in other way, for example by applying proper CSS class.
97
- * writer.setSelection( element, 'in', { fake: true } );
98
- *
99
- * // Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
100
- * // (and be properly handled by screen readers).
101
- * writer.setSelection( element, 'in', { fake: true, label: 'foo' } );
102
- * ```
103
- *
104
- * See also: {@link #setSelection:SELECTABLE `setSelection( selectable, options )`}.
105
- *
106
- * @label NODE_OFFSET
107
- */
108
- setSelection(selectable: ViewNode, placeOrOffset: ViewPlaceOrOffset, options?: ViewSelectionOptions): void;
109
- /**
110
- * Sets {@link module:engine/view/documentselection~ViewDocumentSelection selection's} ranges and direction to the
111
- * specified location based on the given {@link module:engine/view/selection~ViewSelectable selectable}.
112
- *
113
- * Usage:
114
- *
115
- * ```ts
116
- * // Sets selection to the given range.
117
- * const range = writer.createRange( start, end );
118
- * writer.setSelection( range );
119
- *
120
- * // Sets backward selection to the given range.
121
- * const range = writer.createRange( start, end );
122
- * writer.setSelection( range );
123
- *
124
- * // Sets selection to given ranges.
125
- * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( start2, end2 ) ];
126
- * writer.setSelection( range );
127
- *
128
- * // Sets selection to the other selection.
129
- * const otherSelection = writer.createSelection();
130
- * writer.setSelection( otherSelection );
131
- *
132
- * // Sets collapsed selection at the given position.
133
- * const position = writer.createPositionFromPath( root, path );
134
- * writer.setSelection( position );
135
- *
136
- * // Removes all ranges.
137
- * writer.setSelection( null );
138
- * ```
139
- *
140
- * `ViewDowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.
141
- *
142
- * ```ts
143
- * // Sets selection as backward.
144
- * writer.setSelection( range, { backward: true } );
145
- *
146
- * // Sets selection as fake.
147
- * // Fake selection does not render as browser native selection over selected elements and is hidden to the user.
148
- * // This way, no native selection UI artifacts are displayed to the user and selection over elements can be
149
- * // represented in other way, for example by applying proper CSS class.
150
- * writer.setSelection( range, { fake: true } );
151
- *
152
- * // Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
153
- * // (and be properly handled by screen readers).
154
- * writer.setSelection( range, { fake: true, label: 'foo' } );
155
- * ```
156
- *
157
- * See also: {@link #setSelection:NODE_OFFSET `setSelection( node, placeOrOffset, options )`}.
158
- *
159
- * @label SELECTABLE
160
- */
161
- setSelection(selectable: Exclude<ViewSelectable, ViewNode>, options?: ViewSelectionOptions): void;
162
- /**
163
- * Moves {@link module:engine/view/documentselection~ViewDocumentSelection#focus selection's focus} to the specified location.
164
- *
165
- * The location can be specified in the same form as
166
- * {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
167
- * parameters.
168
- *
169
- * @param itemOrPosition
170
- * @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~ViewItem view item}.
171
- */
172
- setSelectionFocus(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): void;
173
- /**
174
- * Creates a new {@link module:engine/view/documentfragment~ViewDocumentFragment} instance.
175
- *
176
- * @param children A list of nodes to be inserted into the created document fragment.
177
- * @returns The created document fragment.
178
- */
179
- createDocumentFragment(children?: ViewNode | Iterable<ViewNode>): ViewDocumentFragment;
180
- /**
181
- * Creates a new {@link module:engine/view/text~ViewText text node}.
182
- *
183
- * ```ts
184
- * writer.createText( 'foo' );
185
- * ```
186
- *
187
- * @param data The text's data.
188
- * @returns The created text node.
189
- */
190
- createText(data: string): ViewText;
191
- /**
192
- * Creates a new {@link module:engine/view/attributeelement~ViewAttributeElement}.
193
- *
194
- * ```ts
195
- * writer.createAttributeElement( 'strong' );
196
- * writer.createAttributeElement( 'a', { href: 'foo.bar' } );
197
- *
198
- * // Make `<a>` element contain other attributes element so the `<a>` element is not broken.
199
- * writer.createAttributeElement( 'a', { href: 'foo.bar' }, { priority: 5 } );
200
- *
201
- * // Set `id` of a marker element so it is not joined or merged with "normal" elements.
202
- * writer.createAttributeElement( 'span', { class: 'my-marker' }, { id: 'marker:my' } );
203
- * ```
204
- *
205
- * @param name Name of the element.
206
- * @param attributes Element's attributes.
207
- * @param options Element's options.
208
- * @param options.priority Element's {@link module:engine/view/attributeelement~ViewAttributeElement#priority priority}.
209
- * @param options.id Element's {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
210
- * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
211
- * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
212
- * @returns Created element.
213
- */
214
- createAttributeElement(name: string, attributes?: ViewElementAttributes, options?: {
215
- priority?: number;
216
- id?: number | string;
217
- renderUnsafeAttributes?: Array<string>;
218
- }): ViewAttributeElement;
219
- /**
220
- * Creates a new {@link module:engine/view/containerelement~ViewContainerElement}.
221
- *
222
- * ```ts
223
- * writer.createContainerElement( 'p' );
224
- *
225
- * // Create element with custom attributes.
226
- * writer.createContainerElement( 'div', { id: 'foo-bar', 'data-baz': '123' } );
227
- *
228
- * // Create element with custom styles.
229
- * writer.createContainerElement( 'p', { style: 'font-weight: bold; padding-bottom: 10px' } );
230
- *
231
- * // Create element with custom classes.
232
- * writer.createContainerElement( 'p', { class: 'foo bar baz' } );
233
- *
234
- * // Create element with specific options.
235
- * writer.createContainerElement( 'span', { class: 'placeholder' }, { renderUnsafeAttributes: [ 'foo' ] } );
236
- * ```
237
- *
238
- * @label WITHOUT_CHILDREN
239
- * @param name Name of the element.
240
- * @param attributes Elements attributes.
241
- * @param options Element's options.
242
- * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
243
- * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
244
- * @returns Created element.
245
- */
246
- createContainerElement(name: string, attributes?: ViewElementAttributes, options?: {
247
- renderUnsafeAttributes?: Array<string>;
248
- }): ViewContainerElement;
249
- /**
250
- * Creates a new {@link module:engine/view/containerelement~ViewContainerElement} with children.
251
- *
252
- * ```ts
253
- * // Create element with children.
254
- * writer.createContainerElement( 'figure', { class: 'image' }, [
255
- * writer.createEmptyElement( 'img' ),
256
- * writer.createContainerElement( 'figcaption' )
257
- * ] );
258
- *
259
- * // Create element with specific options.
260
- * writer.createContainerElement( 'figure', { class: 'image' }, [
261
- * writer.createEmptyElement( 'img' ),
262
- * writer.createContainerElement( 'figcaption' )
263
- * ], { renderUnsafeAttributes: [ 'foo' ] } );
264
- * ```
265
- *
266
- * @label WITH_CHILDREN
267
- * @param name Name of the element.
268
- * @param attributes Elements attributes.
269
- * @param children A node or a list of nodes to be inserted into the created element.
270
- * If no children were specified, element's `options` can be passed in this argument.
271
- * @param options Element's options.
272
- * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
273
- * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
274
- * @returns Created element.
275
- */
276
- createContainerElement(name: string, attributes: ViewElementAttributes, children: ViewNode | Iterable<ViewNode>, options?: {
277
- renderUnsafeAttributes?: Array<string>;
278
- }): ViewContainerElement;
279
- /**
280
- * Creates a new {@link module:engine/view/editableelement~ViewEditableElement}.
281
- *
282
- * ```ts
283
- * writer.createEditableElement( 'div' );
284
- * writer.createEditableElement( 'div', { id: 'foo-1234' } );
285
- * ```
286
- *
287
- * Note: The editable element is to be used in the editing pipeline. Usually, together with
288
- * {@link module:widget/utils~toWidgetEditable `toWidgetEditable()`}.
289
- *
290
- * @param name Name of the element.
291
- * @param attributes Elements attributes.
292
- * @param options Element's options.
293
- * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
294
- * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
295
- * @returns Created element.
296
- */
297
- createEditableElement(name: string, attributes?: ViewElementAttributes, options?: {
298
- renderUnsafeAttributes?: Array<string>;
299
- }): ViewEditableElement;
300
- /**
301
- * Creates a new {@link module:engine/view/emptyelement~ViewEmptyElement}.
302
- *
303
- * ```ts
304
- * writer.createEmptyElement( 'img' );
305
- * writer.createEmptyElement( 'img', { id: 'foo-1234' } );
306
- * ```
307
- *
308
- * @param name Name of the element.
309
- * @param attributes Elements attributes.
310
- * @param options Element's options.
311
- * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
312
- * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
313
- * @returns Created element.
314
- */
315
- createEmptyElement(name: string, attributes?: ViewElementAttributes, options?: {
316
- renderUnsafeAttributes?: Array<string>;
317
- }): ViewEmptyElement;
318
- /**
319
- * Creates a new {@link module:engine/view/uielement~ViewUIElement}.
320
- *
321
- * ```ts
322
- * writer.createUIElement( 'span' );
323
- * writer.createUIElement( 'span', { id: 'foo-1234' } );
324
- * ```
325
- *
326
- * A custom render function can be provided as the third parameter:
327
- *
328
- * ```ts
329
- * writer.createUIElement( 'span', null, function( domDocument ) {
330
- * const domElement = this.toDomElement( domDocument );
331
- * domElement.innerHTML = '<b>this is ui element</b>';
332
- *
333
- * return domElement;
334
- * } );
335
- * ```
336
- *
337
- * Unlike {@link #createRawElement raw elements}, UI elements are by no means editor content, for instance,
338
- * they are ignored by the editor selection system.
339
- *
340
- * You should not use UI elements as data containers. Check out {@link #createRawElement} instead.
341
- *
342
- * @param name The name of the element.
343
- * @param attributes Element attributes.
344
- * @param renderFunction A custom render function.
345
- * @returns The created element.
346
- */
347
- createUIElement(name: string, attributes?: ViewElementAttributes, renderFunction?: (this: ViewUIElement, domDocument: DomDocument, domConverter: ViewDomConverter) => DomElement): ViewUIElement;
348
- /**
349
- * Creates a new {@link module:engine/view/rawelement~ViewRawElement}.
350
- *
351
- * ```ts
352
- * writer.createRawElement( 'span', { id: 'foo-1234' }, function( domElement ) {
353
- * domElement.innerHTML = '<b>This is the raw content of the raw element.</b>';
354
- * } );
355
- * ```
356
- *
357
- * Raw elements work as data containers ("wrappers", "sandboxes") but their children are not managed or
358
- * even recognized by the editor. This encapsulation allows integrations to maintain custom DOM structures
359
- * in the editor content without, for instance, worrying about compatibility with other editor features.
360
- * Raw elements are a perfect tool for integration with external frameworks and data sources.
361
- *
362
- * Unlike {@link #createUIElement UI elements}, raw elements act like "real" editor content (similar to
363
- * {@link module:engine/view/containerelement~ViewContainerElement} or {@link module:engine/view/emptyelement~ViewEmptyElement}),
364
- * and they are considered by the editor selection.
365
- *
366
- * You should not use raw elements to render the UI in the editor content. Check out {@link #createUIElement `#createUIElement()`}
367
- * instead.
368
- *
369
- * @param name The name of the element.
370
- * @param attributes Element attributes.
371
- * @param renderFunction A custom render function.
372
- * @param options Element's options.
373
- * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
374
- * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
375
- * @returns The created element.
376
- */
377
- createRawElement(name: string, attributes?: ViewElementAttributes, renderFunction?: (domElement: DomElement, domConverter: ViewDomConverter) => void, options?: {
378
- renderUnsafeAttributes?: Array<string>;
379
- }): ViewRawElement;
380
- /**
381
- * Adds or overwrites the element's attribute with a specified key and value.
382
- *
383
- * ```ts
384
- * writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
385
- * ```
386
- *
387
- * @param key The attribute key.
388
- * @param value The attribute value.
389
- * @param element The element to set an attribute on.
390
- */
391
- setAttribute(key: string, value: unknown, element: ViewElement): void;
392
- /**
393
- * Adds or overwrites the element's attribute with a specified key and value.
394
- * Note that for tokenized attributes it allows the `reset` parameter to specify if the previous
395
- * attribute value should be overwritten or a new token (class name, style property) should be added.
396
- *
397
- * ```ts
398
- * writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
399
- * writer.setAttribute( 'class', 'foo', false, element );
400
- * ```
401
- *
402
- * @param key The attribute key.
403
- * @param value The attribute value.
404
- * @param overwrite Whether tokenized attribute should overwrite the attribute value or just add a token.
405
- * @param element The element to set an attribute on.
406
- */
407
- setAttribute(key: string, value: unknown, overwrite: boolean, element: ViewElement): void;
408
- /**
409
- * Removes attribute from the element.
410
- *
411
- * ```ts
412
- * writer.removeAttribute( 'href', linkElement );
413
- * ```
414
- *
415
- * @param key Attribute key.
416
- * @param element The element to remove an attribute of.
417
- */
418
- removeAttribute(key: string, element: ViewElement): void;
419
- /**
420
- * Removes specified tokens from an attribute value (for example class names, style properties).
421
- * If resulting attribute become empty, the whole attribute is removed.
422
- *
423
- * ```ts
424
- * writer.removeAttribute( 'class', 'foo', linkElement );
425
- * ```
426
- *
427
- * @param key Attribute key.
428
- * @param tokens Tokens to partly remove from attribute value. For example class names or style property names.
429
- * @param element The element to remove an attribute of.
430
- */
431
- removeAttribute(key: string, tokens: ArrayOrItem<string>, element: ViewElement): void;
432
- /**
433
- * Adds specified class to the element.
434
- *
435
- * ```ts
436
- * writer.addClass( 'foo', linkElement );
437
- * writer.addClass( [ 'foo', 'bar' ], linkElement );
438
- * ```
439
- */
440
- addClass(className: string | Array<string>, element: ViewElement): void;
441
- /**
442
- * Removes specified class from the element.
443
- *
444
- * ```ts
445
- * writer.removeClass( 'foo', linkElement );
446
- * writer.removeClass( [ 'foo', 'bar' ], linkElement );
447
- * ```
448
- */
449
- removeClass(className: string | Array<string>, element: ViewElement): void;
450
- /**
451
- * Adds style to the element.
452
- *
453
- * ```ts
454
- * writer.setStyle( 'color', 'red', element );
455
- * ```
456
- *
457
- * **Note**: The passed style can be normalized if
458
- * {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
459
- * See {@link module:engine/view/stylesmap~StylesMap#set `StylesMap#set()`} for details.
460
- *
461
- * @label KEY_VALUE
462
- * @param property Property name.
463
- * @param value Value to set.
464
- * @param element Element to set styles on.
465
- */
466
- setStyle(property: string, value: StyleValue, element: ViewElement): void;
467
- /**
468
- * Adds many styles to the element.
469
- *
470
- * ```ts
471
- * writer.setStyle( {
472
- * color: 'red',
473
- * position: 'fixed'
474
- * }, element );
475
- * ```
476
- *
477
- * **Note**: The passed style can be normalized if
478
- * {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
479
- * See {@link module:engine/view/stylesmap~StylesMap#set `StylesMap#set()`} for details.
480
- *
481
- * @label OBJECT
482
- * @param property Object with key - value pairs.
483
- * @param element Element to set styles on.
484
- */
485
- setStyle(property: Record<string, StyleValue>, element: ViewElement): void;
486
- /**
487
- * Removes specified style from the element.
488
- *
489
- * ```ts
490
- * writer.removeStyle( 'color', element ); // Removes 'color' style.
491
- * writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
492
- * ```
493
- *
494
- * **Note**: This method can work with normalized style names if
495
- * {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
496
- * See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
497
- */
498
- removeStyle(property: string | Array<string>, element: ViewElement): void;
499
- /**
500
- * Sets a custom property on element. Unlike attributes, custom properties are not rendered to the DOM,
501
- * so they can be used to add special data to elements.
502
- */
503
- setCustomProperty(key: string | symbol, value: unknown, element: ViewElement | ViewDocumentFragment): void;
504
- /**
505
- * Removes a custom property stored under the given key.
506
- *
507
- * @returns Returns true if property was removed.
508
- */
509
- removeCustomProperty(key: string | symbol, element: ViewElement | ViewDocumentFragment): boolean;
510
- /**
511
- * Breaks attribute elements at the provided position or at the boundaries of a provided range. It breaks attribute elements
512
- * up to their first ancestor that is a container element.
513
- *
514
- * In following examples `<p>` is a container, `<b>` and `<u>` are attribute elements:
515
- *
516
- * ```html
517
- * <p>foo<b><u>bar{}</u></b></p> -> <p>foo<b><u>bar</u></b>[]</p>
518
- * <p>foo<b><u>{}bar</u></b></p> -> <p>foo{}<b><u>bar</u></b></p>
519
- * <p>foo<b><u>b{}ar</u></b></p> -> <p>foo<b><u>b</u></b>[]<b><u>ar</u></b></p>
520
- * <p><b>fo{o</b><u>ba}r</u></p> -> <p><b>fo</b><b>o</b><u>ba</u><u>r</u></b></p>
521
- * ```
522
- *
523
- * **Note:** {@link module:engine/view/documentfragment~ViewDocumentFragment DocumentFragment} is treated like a container.
524
- *
525
- * **Note:** The difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes breakAttributes()} and
526
- * {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
527
- * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} that are ancestors of a given `position`,
528
- * up to the first encountered {@link module:engine/view/containerelement~ViewContainerElement container element}.
529
- * `breakContainer()` assumes that a given `position` is directly in the container element and breaks that container element.
530
- *
531
- * Throws the `view-writer-invalid-range-container` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
532
- * when the {@link module:engine/view/range~ViewRange#start start}
533
- * and {@link module:engine/view/range~ViewRange#end end} positions of a passed range are not placed inside same parent container.
534
- *
535
- * Throws the `view-writer-cannot-break-empty-element` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
536
- * when trying to break attributes inside an {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElement}.
537
- *
538
- * Throws the `view-writer-cannot-break-ui-element` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
539
- * when trying to break attributes inside a {@link module:engine/view/uielement~ViewUIElement UIElement}.
540
- *
541
- * @see module:engine/view/attributeelement~ViewAttributeElement
542
- * @see module:engine/view/containerelement~ViewContainerElement
543
- * @see module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer
544
- * @param positionOrRange The position where to break attribute elements.
545
- * @returns The new position or range, after breaking the attribute elements.
546
- */
547
- breakAttributes(positionOrRange: ViewPosition | ViewRange): ViewPosition | ViewRange;
548
- /**
549
- * Breaks a {@link module:engine/view/containerelement~ViewContainerElement container view element} into two, at the given position.
550
- * The position has to be directly inside the container element and cannot be in the root. It does not break the conrainer view element
551
- * if the position is at the beginning or at the end of its parent element.
552
- *
553
- * ```html
554
- * <p>foo^bar</p> -> <p>foo</p><p>bar</p>
555
- * <div><p>foo</p>^<p>bar</p></div> -> <div><p>foo</p></div><div><p>bar</p></div>
556
- * <p>^foobar</p> -> ^<p>foobar</p>
557
- * <p>foobar^</p> -> <p>foobar</p>^
558
- * ```
559
- *
560
- * **Note:** The difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes breakAttributes()} and
561
- * {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
562
- * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} that are ancestors of a given `position`,
563
- * up to the first encountered {@link module:engine/view/containerelement~ViewContainerElement container element}.
564
- * `breakContainer()` assumes that the given `position` is directly in the container element and breaks that container element.
565
- *
566
- * @see module:engine/view/attributeelement~ViewAttributeElement
567
- * @see module:engine/view/containerelement~ViewContainerElement
568
- * @see module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes
569
- * @param position The position where to break the element.
570
- * @returns The position between broken elements. If an element has not been broken,
571
- * the returned position is placed either before or after it.
572
- */
573
- breakContainer(position: ViewPosition): ViewPosition;
574
- /**
575
- * Merges {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements}. It also merges text nodes if needed.
576
- * Only {@link module:engine/view/attributeelement~ViewAttributeElement#isSimilar similar} attribute elements can be merged.
577
- *
578
- * In following examples `<p>` is a container and `<b>` is an attribute element:
579
- *
580
- * ```html
581
- * <p>foo[]bar</p> -> <p>foo{}bar</p>
582
- * <p><b>foo</b>[]<b>bar</b></p> -> <p><b>foo{}bar</b></p>
583
- * <p><b foo="bar">a</b>[]<b foo="baz">b</b></p> -> <p><b foo="bar">a</b>[]<b foo="baz">b</b></p>
584
- * ```
585
- *
586
- * It will also take care about empty attributes when merging:
587
- *
588
- * ```html
589
- * <p><b>[]</b></p> -> <p>[]</p>
590
- * <p><b>foo</b><i>[]</i><b>bar</b></p> -> <p><b>foo{}bar</b></p>
591
- * ```
592
- *
593
- * **Note:** Difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes mergeAttributes} and
594
- * {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
595
- * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} or
596
- * {@link module:engine/view/text~ViewText text nodes} while `mergeContainer` merges two
597
- * {@link module:engine/view/containerelement~ViewContainerElement container elements}.
598
- *
599
- * @see module:engine/view/attributeelement~ViewAttributeElement
600
- * @see module:engine/view/containerelement~ViewContainerElement
601
- * @see module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers
602
- * @param position Merge position.
603
- * @returns Position after merge.
604
- */
605
- mergeAttributes(position: ViewPosition): ViewPosition;
606
- /**
607
- * Merges two {@link module:engine/view/containerelement~ViewContainerElement container elements} that are
608
- * before and after given position. Precisely, the element after the position is removed and it's contents are
609
- * moved to element before the position.
610
- *
611
- * ```html
612
- * <p>foo</p>^<p>bar</p> -> <p>foo^bar</p>
613
- * <div>foo</div>^<p>bar</p> -> <div>foo^bar</div>
614
- * ```
615
- *
616
- * **Note:** Difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes mergeAttributes} and
617
- * {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
618
- * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} or
619
- * {@link module:engine/view/text~ViewText text nodes} while `mergeContainer` merges two
620
- * {@link module:engine/view/containerelement~ViewContainerElement container elements}.
621
- *
622
- * @see module:engine/view/attributeelement~ViewAttributeElement
623
- * @see module:engine/view/containerelement~ViewContainerElement
624
- * @see module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes
625
- * @param position Merge position.
626
- * @returns Position after merge.
627
- */
628
- mergeContainers(position: ViewPosition): ViewPosition;
629
- /**
630
- * Inserts a node or nodes at specified position. Takes care about breaking attributes before insertion
631
- * and merging them afterwards.
632
- *
633
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-insert-invalid-node` when nodes to insert
634
- * contains instances that are not {@link module:engine/view/text~ViewText Texts},
635
- * {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElements},
636
- * {@link module:engine/view/containerelement~ViewContainerElement ViewContainerElements},
637
- * {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElements},
638
- * {@link module:engine/view/rawelement~ViewRawElement RawElements} or
639
- * {@link module:engine/view/uielement~ViewUIElement UIElements}.
640
- *
641
- * @param position Insertion position.
642
- * @param nodes Node or nodes to insert.
643
- * @returns Range around inserted nodes.
644
- */
645
- insert(position: ViewPosition, nodes: ViewNode | Iterable<ViewNode>): ViewRange;
646
- /**
647
- * Removes provided range from the container.
648
- *
649
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
650
- * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
651
- * positions are not placed inside same parent container.
652
- *
653
- * @param rangeOrItem Range to remove from container
654
- * or an {@link module:engine/view/item~ViewItem item} to remove. If range is provided, after removing, it will be updated
655
- * to a collapsed range showing the new position.
656
- * @returns Document fragment containing removed nodes.
657
- */
658
- remove(rangeOrItem: ViewRange | ViewItem): ViewDocumentFragment;
659
- /**
660
- * Removes matching elements from given range.
661
- *
662
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
663
- * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
664
- * positions are not placed inside same parent container.
665
- *
666
- * @param range Range to clear.
667
- * @param element Element to remove.
668
- */
669
- clear(range: ViewRange, element: ViewElement): void;
670
- /**
671
- * Moves nodes from provided range to target position.
672
- *
673
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
674
- * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
675
- * positions are not placed inside same parent container.
676
- *
677
- * @param sourceRange Range containing nodes to move.
678
- * @param targetPosition Position to insert.
679
- * @returns Range in target container. Inserted nodes are placed between
680
- * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end} positions.
681
- */
682
- move(sourceRange: ViewRange, targetPosition: ViewPosition): ViewRange;
683
- /**
684
- * Wraps elements within range with provided {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
685
- * If a collapsed range is provided, it will be wrapped only if it is equal to view selection.
686
- *
687
- * If a collapsed range was passed and is same as selection, the selection
688
- * will be moved to the inside of the wrapped attribute element.
689
- *
690
- * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-invalid-range-container`
691
- * when {@link module:engine/view/range~ViewRange#start}
692
- * and {@link module:engine/view/range~ViewRange#end} positions are not placed inside same parent container.
693
- *
694
- * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
695
- * an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
696
- *
697
- * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-nonselection-collapsed-range` when passed range
698
- * is collapsed and different than view selection.
699
- *
700
- * @param range Range to wrap.
701
- * @param attribute Attribute element to use as wrapper.
702
- * @returns range Range after wrapping, spanning over wrapping attribute element.
703
- */
704
- wrap(range: ViewRange, attribute: ViewAttributeElement): ViewRange;
705
- /**
706
- * Unwraps nodes within provided range from attribute element.
707
- *
708
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
709
- * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
710
- * positions are not placed inside same parent container.
711
- */
712
- unwrap(range: ViewRange, attribute: ViewAttributeElement): ViewRange;
713
- /**
714
- * Renames element by creating a copy of renamed element but with changed name and then moving contents of the
715
- * old element to the new one. Keep in mind that this will invalidate all {@link module:engine/view/position~ViewPosition positions}
716
- * which has renamed element as {@link module:engine/view/position~ViewPosition#parent a parent}.
717
- *
718
- * New element has to be created because `Element#tagName` property in DOM is readonly.
719
- *
720
- * Since this function creates a new element and removes the given one, the new element is returned to keep reference.
721
- *
722
- * @param newName New name for element.
723
- * @param viewElement Element to be renamed.
724
- * @returns Element created due to rename.
725
- */
726
- rename(newName: string, viewElement: ViewContainerElement): ViewContainerElement;
727
- /**
728
- * Cleans up memory by removing obsolete cloned elements group from the writer.
729
- *
730
- * Should be used whenever all {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements}
731
- * with the same {@link module:engine/view/attributeelement~ViewAttributeElement#id id} are going to be removed from the view and
732
- * the group will no longer be needed.
733
- *
734
- * Cloned elements group are not removed automatically in case if the group is still needed after all its elements
735
- * were removed from the view.
736
- *
737
- * Keep in mind that group names are equal to the `id` property of the attribute element.
738
- *
739
- * @param groupName Name of the group to clear.
740
- */
741
- clearClonedElementsGroup(groupName: string): void;
742
- /**
743
- * Creates position at the given location. The location can be specified as:
744
- *
745
- * * a {@link module:engine/view/position~ViewPosition position},
746
- * * parent element and offset (offset defaults to `0`),
747
- * * parent element and `'end'` (sets position at the end of that element),
748
- * * {@link module:engine/view/item~ViewItem view item} and `'before'` or `'after'` (sets position before or after given view item).
749
- *
750
- * This method is a shortcut to other constructors such as:
751
- *
752
- * * {@link #createPositionBefore},
753
- * * {@link #createPositionAfter},
754
- *
755
- * @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~ViewItem view item}.
756
- */
757
- createPositionAt(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): ViewPosition;
758
- /**
759
- * Creates a new position after given view item.
760
- *
761
- * @param item View item after which the position should be located.
762
- */
763
- createPositionAfter(item: ViewItem): ViewPosition;
764
- /**
765
- * Creates a new position before given view item.
766
- *
767
- * @param item View item before which the position should be located.
768
- */
769
- createPositionBefore(item: ViewItem): ViewPosition;
770
- /**
771
- * Creates a range spanning from `start` position to `end` position.
772
- *
773
- * **Note:** This factory method creates its own {@link module:engine/view/position~ViewPosition} instances basing on passed values.
774
- *
775
- * @param start Start position.
776
- * @param end End position. If not set, range will be collapsed at `start` position.
777
- */
778
- createRange(start: ViewPosition, end?: ViewPosition | null): ViewRange;
779
- /**
780
- * Creates a range that starts before given {@link module:engine/view/item~ViewItem view item} and ends after it.
781
- */
782
- createRangeOn(item: ViewItem): ViewRange;
783
- /**
784
- * Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
785
- * that element and ends after the last child of that element.
786
- *
787
- * @param element Element which is a parent for the range.
788
- */
789
- createRangeIn(element: ViewElement | ViewDocumentFragment): ViewRange;
790
- /**
791
- * Creates new {@link module:engine/view/selection~ViewSelection} instance.
792
- *
793
- * ```ts
794
- * // Creates collapsed selection at the position of given item and offset.
795
- * const paragraph = writer.createContainerElement( 'p' );
796
- * const selection = writer.createSelection( paragraph, offset );
797
- *
798
- * // Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the
799
- * // first child of that element and ends after the last child of that element.
800
- * const selection = writer.createSelection( paragraph, 'in' );
801
- *
802
- * // Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends
803
- * // just after the item.
804
- * const selection = writer.createSelection( paragraph, 'on' );
805
- * ```
806
- *
807
- * `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
808
- *
809
- * ```ts
810
- * // Creates backward selection.
811
- * const selection = writer.createSelection( element, 'in', { backward: true } );
812
- * ```
813
- *
814
- * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
815
- * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
816
- * represented in other way, for example by applying proper CSS class.
817
- *
818
- * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
819
- * (and be properly handled by screen readers).
820
- *
821
- * ```ts
822
- * // Creates fake selection with label.
823
- * const selection = writer.createSelection( element, 'in', { fake: true, label: 'foo' } );
824
- * ```
825
- *
826
- * See also: {@link #createSelection:SELECTABLE `createSelection( selectable, options )`}.
827
- *
828
- * @label NODE_OFFSET
829
- */
830
- createSelection(selectable: ViewNode, placeOrOffset: ViewPlaceOrOffset, options?: ViewSelectionOptions): ViewSelection;
831
- /**
832
- * Creates new {@link module:engine/view/selection~ViewSelection} instance.
833
- *
834
- * ```ts
835
- * // Creates empty selection without ranges.
836
- * const selection = writer.createSelection();
837
- *
838
- * // Creates selection at the given range.
839
- * const range = writer.createRange( start, end );
840
- * const selection = writer.createSelection( range );
841
- *
842
- * // Creates selection at the given ranges
843
- * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
844
- * const selection = writer.createSelection( ranges );
845
- *
846
- * // Creates selection from the other selection.
847
- * const otherSelection = writer.createSelection();
848
- * const selection = writer.createSelection( otherSelection );
849
- *
850
- * // Creates selection from the document selection.
851
- * const selection = writer.createSelection( editor.editing.view.document.selection );
852
- *
853
- * // Creates selection at the given position.
854
- * const position = writer.createPositionFromPath( root, path );
855
- * const selection = writer.createSelection( position );
856
- * ```
857
- *
858
- * `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
859
- *
860
- * ```ts
861
- * // Creates backward selection.
862
- * const selection = writer.createSelection( range, { backward: true } );
863
- * ```
864
- *
865
- * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
866
- * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
867
- * represented in other way, for example by applying proper CSS class.
868
- *
869
- * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
870
- * (and be properly handled by screen readers).
871
- *
872
- * ```ts
873
- * // Creates fake selection with label.
874
- * const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
875
- * ```
876
- *
877
- * See also: {@link #createSelection:NODE_OFFSET `createSelection( node, placeOrOffset, options )`}.
878
- *
879
- * @label SELECTABLE
880
- */
881
- createSelection(selectable?: Exclude<ViewSelectable, ViewNode>, option?: ViewSelectionOptions): ViewSelection;
882
- /**
883
- * Creates placeholders for child elements of the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
884
- * `elementToStructure()`} conversion helper.
885
- *
886
- * ```ts
887
- * const viewSlot = conversionApi.writer.createSlot();
888
- * const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
889
- *
890
- * conversionApi.writer.insert( viewPosition, viewSlot );
891
- * ```
892
- *
893
- * It could be filtered down to a specific subset of children (only `<foo>` model elements in this case):
894
- *
895
- * ```ts
896
- * const viewSlot = conversionApi.writer.createSlot( node => node.is( 'element', 'foo' ) );
897
- * const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
898
- *
899
- * conversionApi.writer.insert( viewPosition, viewSlot );
900
- * ```
901
- *
902
- * While providing a filtered slot, make sure to provide slots for all child nodes. A single node cannot be downcasted into
903
- * multiple slots.
904
- *
905
- * **Note**: You should not change the order of nodes. View elements should be in the same order as model nodes.
906
- *
907
- * @param modeOrFilter The filter for child nodes.
908
- * @returns The slot element to be placed in to the view structure while processing
909
- * {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure `elementToStructure()`}.
910
- */
911
- createSlot(modeOrFilter?: 'children' | DowncastSlotFilter): ViewElement;
912
- /**
913
- * Registers a slot factory.
914
- *
915
- * @internal
916
- * @param slotFactory The slot factory.
917
- */
918
- _registerSlotFactory(slotFactory: (writer: ViewDowncastWriter, modeOrFilter: 'children' | DowncastSlotFilter) => ViewElement): void;
919
- /**
920
- * Clears the registered slot factory.
921
- *
922
- * @internal
923
- */
924
- _clearSlotFactory(): void;
925
- /**
926
- * Inserts a node or nodes at the specified position. Takes care of breaking attributes before insertion
927
- * and merging them afterwards if requested by the breakAttributes param.
928
- *
929
- * @param position Insertion position.
930
- * @param nodes Node or nodes to insert.
931
- * @param breakAttributes Whether attributes should be broken.
932
- * @returns Range around inserted nodes.
933
- */
934
- private _insertNodes;
935
- /**
936
- * Wraps children with provided `wrapElement`. Only children contained in `parent` element between
937
- * `startOffset` and `endOffset` will be wrapped.
938
- */
939
- private _wrapChildren;
940
- /**
941
- * Unwraps children from provided `unwrapElement`. Only children contained in `parent` element between
942
- * `startOffset` and `endOffset` will be unwrapped.
943
- */
944
- private _unwrapChildren;
945
- /**
946
- * Helper function for `view.writer.wrap`. Wraps range with provided attribute element.
947
- * This method will also merge newly added attribute element with its siblings whenever possible.
948
- *
949
- * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
950
- * an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
951
- *
952
- * @returns New range after wrapping, spanning over wrapping attribute element.
953
- */
954
- private _wrapRange;
955
- /**
956
- * Helper function for {@link #wrap}. Wraps position with provided attribute element.
957
- * This method will also merge newly added attribute element with its siblings whenever possible.
958
- *
959
- * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
960
- * an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
961
- *
962
- * @returns New position after wrapping.
963
- */
964
- private _wrapPosition;
965
- /**
966
- * Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at the boundaries of given range.
967
- *
968
- * @param range Range which `start` and `end` positions will be used to break attributes.
969
- * @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
970
- * This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
971
- * @returns New range with located at break positions.
972
- */
973
- private _breakAttributesRange;
974
- /**
975
- * Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at given position.
976
- *
977
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-empty-element` when break position
978
- * is placed inside {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElement}.
979
- *
980
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-ui-element` when break position
981
- * is placed inside {@link module:engine/view/uielement~ViewUIElement UIElement}.
982
- *
983
- * @param position Position where to break attributes.
984
- * @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
985
- * This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
986
- * @returns New position after breaking the attributes.
987
- */
988
- private _breakAttributes;
989
- /**
990
- * Stores the information that an {@link module:engine/view/attributeelement~ViewAttributeElement attribute element} was
991
- * added to the tree. Saves the reference to the group in the given element and updates the group, so other elements
992
- * from the group now keep a reference to the given attribute element.
993
- *
994
- * The clones group can be obtained using {@link module:engine/view/attributeelement~ViewAttributeElement#getElementsWithSameId}.
995
- *
996
- * Does nothing if added element has no {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
997
- *
998
- * @param element Attribute element to save.
999
- */
1000
- private _addToClonedElementsGroup;
1001
- /**
1002
- * Removes all the information about the given {@link module:engine/view/attributeelement~ViewAttributeElement attribute element}
1003
- * from its clones group.
1004
- *
1005
- * Keep in mind, that the element will still keep a reference to the group (but the group will not keep a reference to it).
1006
- * This allows to reference the whole group even if the element was already removed from the tree.
1007
- *
1008
- * Does nothing if the element has no {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
1009
- *
1010
- * @param element Attribute element to remove.
1011
- */
1012
- private _removeFromClonedElementsGroup;
45
+ /**
46
+ * The view document instance in which this writer operates.
47
+ */
48
+ readonly document: ViewDocument;
49
+ /**
50
+ * Holds references to the attribute groups that share the same {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
51
+ * The keys are `id`s, the values are `Set`s holding {@link module:engine/view/attributeelement~ViewAttributeElement}s.
52
+ */
53
+ private readonly _cloneGroups;
54
+ /**
55
+ * The slot factory used by the `elementToStructure` downcast helper.
56
+ */
57
+ private _slotFactory;
58
+ /**
59
+ * @param document The view document instance.
60
+ */
61
+ constructor(document: ViewDocument);
62
+ /**
63
+ * Sets {@link module:engine/view/documentselection~ViewDocumentSelection selection's} ranges and direction to the
64
+ * specified location based on the given {@link module:engine/view/selection~ViewSelectable selectable}.
65
+ *
66
+ * Usage:
67
+ *
68
+ * ```ts
69
+ * // Sets collapsed selection at the position of given item and offset.
70
+ * const paragraph = writer.createContainerElement( 'p' );
71
+ * writer.setSelection( paragraph, offset );
72
+ * ```
73
+ *
74
+ * Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
75
+ * that element and ends after the last child of that element.
76
+ *
77
+ * ```ts
78
+ * writer.setSelection( paragraph, 'in' );
79
+ * ```
80
+ *
81
+ * Creates a range on the {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
82
+ *
83
+ * ```ts
84
+ * writer.setSelection( paragraph, 'on' );
85
+ * ```
86
+ *
87
+ * `ViewDowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.
88
+ *
89
+ * ```ts
90
+ * // Sets selection as backward.
91
+ * writer.setSelection( element, 'in', { backward: true } );
92
+ *
93
+ * // Sets selection as fake.
94
+ * // Fake selection does not render as browser native selection over selected elements and is hidden to the user.
95
+ * // This way, no native selection UI artifacts are displayed to the user and selection over elements can be
96
+ * // represented in other way, for example by applying proper CSS class.
97
+ * writer.setSelection( element, 'in', { fake: true } );
98
+ *
99
+ * // Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
100
+ * // (and be properly handled by screen readers).
101
+ * writer.setSelection( element, 'in', { fake: true, label: 'foo' } );
102
+ * ```
103
+ *
104
+ * See also: {@link #setSelection:SELECTABLE `setSelection( selectable, options )`}.
105
+ *
106
+ * @label NODE_OFFSET
107
+ */
108
+ setSelection(selectable: ViewNode, placeOrOffset: ViewPlaceOrOffset, options?: ViewSelectionOptions): void;
109
+ /**
110
+ * Sets {@link module:engine/view/documentselection~ViewDocumentSelection selection's} ranges and direction to the
111
+ * specified location based on the given {@link module:engine/view/selection~ViewSelectable selectable}.
112
+ *
113
+ * Usage:
114
+ *
115
+ * ```ts
116
+ * // Sets selection to the given range.
117
+ * const range = writer.createRange( start, end );
118
+ * writer.setSelection( range );
119
+ *
120
+ * // Sets backward selection to the given range.
121
+ * const range = writer.createRange( start, end );
122
+ * writer.setSelection( range );
123
+ *
124
+ * // Sets selection to given ranges.
125
+ * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( start2, end2 ) ];
126
+ * writer.setSelection( range );
127
+ *
128
+ * // Sets selection to the other selection.
129
+ * const otherSelection = writer.createSelection();
130
+ * writer.setSelection( otherSelection );
131
+ *
132
+ * // Sets collapsed selection at the given position.
133
+ * const position = writer.createPositionFromPath( root, path );
134
+ * writer.setSelection( position );
135
+ *
136
+ * // Removes all ranges.
137
+ * writer.setSelection( null );
138
+ * ```
139
+ *
140
+ * `ViewDowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.
141
+ *
142
+ * ```ts
143
+ * // Sets selection as backward.
144
+ * writer.setSelection( range, { backward: true } );
145
+ *
146
+ * // Sets selection as fake.
147
+ * // Fake selection does not render as browser native selection over selected elements and is hidden to the user.
148
+ * // This way, no native selection UI artifacts are displayed to the user and selection over elements can be
149
+ * // represented in other way, for example by applying proper CSS class.
150
+ * writer.setSelection( range, { fake: true } );
151
+ *
152
+ * // Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
153
+ * // (and be properly handled by screen readers).
154
+ * writer.setSelection( range, { fake: true, label: 'foo' } );
155
+ * ```
156
+ *
157
+ * See also: {@link #setSelection:NODE_OFFSET `setSelection( node, placeOrOffset, options )`}.
158
+ *
159
+ * @label SELECTABLE
160
+ */
161
+ setSelection(selectable: Exclude<ViewSelectable, ViewNode>, options?: ViewSelectionOptions): void;
162
+ /**
163
+ * Moves {@link module:engine/view/documentselection~ViewDocumentSelection#focus selection's focus} to the specified location.
164
+ *
165
+ * The location can be specified in the same form as
166
+ * {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
167
+ * parameters.
168
+ *
169
+ * @param itemOrPosition
170
+ * @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~ViewItem view item}.
171
+ */
172
+ setSelectionFocus(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): void;
173
+ /**
174
+ * Creates a new {@link module:engine/view/documentfragment~ViewDocumentFragment} instance.
175
+ *
176
+ * @param children A list of nodes to be inserted into the created document fragment.
177
+ * @returns The created document fragment.
178
+ */
179
+ createDocumentFragment(children?: ViewNode | Iterable<ViewNode>): ViewDocumentFragment;
180
+ /**
181
+ * Creates a new {@link module:engine/view/text~ViewText text node}.
182
+ *
183
+ * ```ts
184
+ * writer.createText( 'foo' );
185
+ * ```
186
+ *
187
+ * @param data The text's data.
188
+ * @returns The created text node.
189
+ */
190
+ createText(data: string): ViewText;
191
+ /**
192
+ * Creates a new {@link module:engine/view/attributeelement~ViewAttributeElement}.
193
+ *
194
+ * ```ts
195
+ * writer.createAttributeElement( 'strong' );
196
+ * writer.createAttributeElement( 'a', { href: 'foo.bar' } );
197
+ *
198
+ * // Make `<a>` element contain other attributes element so the `<a>` element is not broken.
199
+ * writer.createAttributeElement( 'a', { href: 'foo.bar' }, { priority: 5 } );
200
+ *
201
+ * // Set `id` of a marker element so it is not joined or merged with "normal" elements.
202
+ * writer.createAttributeElement( 'span', { class: 'my-marker' }, { id: 'marker:my' } );
203
+ * ```
204
+ *
205
+ * @param name Name of the element.
206
+ * @param attributes Element's attributes.
207
+ * @param options Element's options.
208
+ * @param options.priority Element's {@link module:engine/view/attributeelement~ViewAttributeElement#priority priority}.
209
+ * @param options.id Element's {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
210
+ * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
211
+ * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
212
+ * @returns Created element.
213
+ */
214
+ createAttributeElement(name: string, attributes?: ViewElementAttributes, options?: {
215
+ priority?: number;
216
+ id?: number | string;
217
+ renderUnsafeAttributes?: Array<string>;
218
+ }): ViewAttributeElement;
219
+ /**
220
+ * Creates a new {@link module:engine/view/containerelement~ViewContainerElement}.
221
+ *
222
+ * ```ts
223
+ * writer.createContainerElement( 'p' );
224
+ *
225
+ * // Create element with custom attributes.
226
+ * writer.createContainerElement( 'div', { id: 'foo-bar', 'data-baz': '123' } );
227
+ *
228
+ * // Create element with custom styles.
229
+ * writer.createContainerElement( 'p', { style: 'font-weight: bold; padding-bottom: 10px' } );
230
+ *
231
+ * // Create element with custom classes.
232
+ * writer.createContainerElement( 'p', { class: 'foo bar baz' } );
233
+ *
234
+ * // Create element with specific options.
235
+ * writer.createContainerElement( 'span', { class: 'placeholder' }, { renderUnsafeAttributes: [ 'foo' ] } );
236
+ * ```
237
+ *
238
+ * @label WITHOUT_CHILDREN
239
+ * @param name Name of the element.
240
+ * @param attributes Elements attributes.
241
+ * @param options Element's options.
242
+ * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
243
+ * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
244
+ * @returns Created element.
245
+ */
246
+ createContainerElement(name: string, attributes?: ViewElementAttributes, options?: {
247
+ renderUnsafeAttributes?: Array<string>;
248
+ }): ViewContainerElement;
249
+ /**
250
+ * Creates a new {@link module:engine/view/containerelement~ViewContainerElement} with children.
251
+ *
252
+ * ```ts
253
+ * // Create element with children.
254
+ * writer.createContainerElement( 'figure', { class: 'image' }, [
255
+ * writer.createEmptyElement( 'img' ),
256
+ * writer.createContainerElement( 'figcaption' )
257
+ * ] );
258
+ *
259
+ * // Create element with specific options.
260
+ * writer.createContainerElement( 'figure', { class: 'image' }, [
261
+ * writer.createEmptyElement( 'img' ),
262
+ * writer.createContainerElement( 'figcaption' )
263
+ * ], { renderUnsafeAttributes: [ 'foo' ] } );
264
+ * ```
265
+ *
266
+ * @label WITH_CHILDREN
267
+ * @param name Name of the element.
268
+ * @param attributes Elements attributes.
269
+ * @param children A node or a list of nodes to be inserted into the created element.
270
+ * If no children were specified, element's `options` can be passed in this argument.
271
+ * @param options Element's options.
272
+ * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
273
+ * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
274
+ * @returns Created element.
275
+ */
276
+ createContainerElement(name: string, attributes: ViewElementAttributes, children: ViewNode | Iterable<ViewNode>, options?: {
277
+ renderUnsafeAttributes?: Array<string>;
278
+ }): ViewContainerElement;
279
+ /**
280
+ * Creates a new {@link module:engine/view/editableelement~ViewEditableElement}.
281
+ *
282
+ * ```ts
283
+ * writer.createEditableElement( 'div' );
284
+ * writer.createEditableElement( 'div', { id: 'foo-1234' } );
285
+ * ```
286
+ *
287
+ * Note: The editable element is to be used in the editing pipeline. Usually, together with
288
+ * {@link module:widget/utils~toWidgetEditable `toWidgetEditable()`}.
289
+ *
290
+ * @param name Name of the element.
291
+ * @param attributes Elements attributes.
292
+ * @param options Element's options.
293
+ * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
294
+ * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
295
+ * @returns Created element.
296
+ */
297
+ createEditableElement(name: string, attributes?: ViewElementAttributes, options?: {
298
+ renderUnsafeAttributes?: Array<string>;
299
+ }): ViewEditableElement;
300
+ /**
301
+ * Creates a new {@link module:engine/view/emptyelement~ViewEmptyElement}.
302
+ *
303
+ * ```ts
304
+ * writer.createEmptyElement( 'img' );
305
+ * writer.createEmptyElement( 'img', { id: 'foo-1234' } );
306
+ * ```
307
+ *
308
+ * @param name Name of the element.
309
+ * @param attributes Elements attributes.
310
+ * @param options Element's options.
311
+ * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
312
+ * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
313
+ * @returns Created element.
314
+ */
315
+ createEmptyElement(name: string, attributes?: ViewElementAttributes, options?: {
316
+ renderUnsafeAttributes?: Array<string>;
317
+ }): ViewEmptyElement;
318
+ /**
319
+ * Creates a new {@link module:engine/view/uielement~ViewUIElement}.
320
+ *
321
+ * ```ts
322
+ * writer.createUIElement( 'span' );
323
+ * writer.createUIElement( 'span', { id: 'foo-1234' } );
324
+ * ```
325
+ *
326
+ * A custom render function can be provided as the third parameter:
327
+ *
328
+ * ```ts
329
+ * writer.createUIElement( 'span', null, function( domDocument ) {
330
+ * const domElement = this.toDomElement( domDocument );
331
+ * domElement.innerHTML = '<b>this is ui element</b>';
332
+ *
333
+ * return domElement;
334
+ * } );
335
+ * ```
336
+ *
337
+ * Unlike {@link #createRawElement raw elements}, UI elements are by no means editor content, for instance,
338
+ * they are ignored by the editor selection system.
339
+ *
340
+ * You should not use UI elements as data containers. Check out {@link #createRawElement} instead.
341
+ *
342
+ * @param name The name of the element.
343
+ * @param attributes Element attributes.
344
+ * @param renderFunction A custom render function.
345
+ * @returns The created element.
346
+ */
347
+ createUIElement(name: string, attributes?: ViewElementAttributes, renderFunction?: (this: ViewUIElement, domDocument: DomDocument, domConverter: ViewDomConverter) => DomElement): ViewUIElement;
348
+ /**
349
+ * Creates a new {@link module:engine/view/rawelement~ViewRawElement}.
350
+ *
351
+ * ```ts
352
+ * writer.createRawElement( 'span', { id: 'foo-1234' }, function( domElement ) {
353
+ * domElement.innerHTML = '<b>This is the raw content of the raw element.</b>';
354
+ * } );
355
+ * ```
356
+ *
357
+ * Raw elements work as data containers ("wrappers", "sandboxes") but their children are not managed or
358
+ * even recognized by the editor. This encapsulation allows integrations to maintain custom DOM structures
359
+ * in the editor content without, for instance, worrying about compatibility with other editor features.
360
+ * Raw elements are a perfect tool for integration with external frameworks and data sources.
361
+ *
362
+ * Unlike {@link #createUIElement UI elements}, raw elements act like "real" editor content (similar to
363
+ * {@link module:engine/view/containerelement~ViewContainerElement} or {@link module:engine/view/emptyelement~ViewEmptyElement}),
364
+ * and they are considered by the editor selection.
365
+ *
366
+ * You should not use raw elements to render the UI in the editor content. Check out {@link #createUIElement `#createUIElement()`}
367
+ * instead.
368
+ *
369
+ * @param name The name of the element.
370
+ * @param attributes Element attributes.
371
+ * @param renderFunction A custom render function.
372
+ * @param options Element's options.
373
+ * @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
374
+ * pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
375
+ * @returns The created element.
376
+ */
377
+ createRawElement(name: string, attributes?: ViewElementAttributes, renderFunction?: (domElement: DomElement, domConverter: ViewDomConverter) => void, options?: {
378
+ renderUnsafeAttributes?: Array<string>;
379
+ }): ViewRawElement;
380
+ /**
381
+ * Adds or overwrites the element's attribute with a specified key and value.
382
+ *
383
+ * ```ts
384
+ * writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
385
+ * ```
386
+ *
387
+ * @param key The attribute key.
388
+ * @param value The attribute value.
389
+ * @param element The element to set an attribute on.
390
+ */
391
+ setAttribute(key: string, value: unknown, element: ViewElement): void;
392
+ /**
393
+ * Adds or overwrites the element's attribute with a specified key and value.
394
+ * Note that for tokenized attributes it allows the `reset` parameter to specify if the previous
395
+ * attribute value should be overwritten or a new token (class name, style property) should be added.
396
+ *
397
+ * ```ts
398
+ * writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
399
+ * writer.setAttribute( 'class', 'foo', false, element );
400
+ * ```
401
+ *
402
+ * @param key The attribute key.
403
+ * @param value The attribute value.
404
+ * @param overwrite Whether tokenized attribute should overwrite the attribute value or just add a token.
405
+ * @param element The element to set an attribute on.
406
+ */
407
+ setAttribute(key: string, value: unknown, overwrite: boolean, element: ViewElement): void;
408
+ /**
409
+ * Removes attribute from the element.
410
+ *
411
+ * ```ts
412
+ * writer.removeAttribute( 'href', linkElement );
413
+ * ```
414
+ *
415
+ * @param key Attribute key.
416
+ * @param element The element to remove an attribute of.
417
+ */
418
+ removeAttribute(key: string, element: ViewElement): void;
419
+ /**
420
+ * Removes specified tokens from an attribute value (for example class names, style properties).
421
+ * If resulting attribute become empty, the whole attribute is removed.
422
+ *
423
+ * ```ts
424
+ * writer.removeAttribute( 'class', 'foo', linkElement );
425
+ * ```
426
+ *
427
+ * @param key Attribute key.
428
+ * @param tokens Tokens to partly remove from attribute value. For example class names or style property names.
429
+ * @param element The element to remove an attribute of.
430
+ */
431
+ removeAttribute(key: string, tokens: ArrayOrItem<string>, element: ViewElement): void;
432
+ /**
433
+ * Adds specified class to the element.
434
+ *
435
+ * ```ts
436
+ * writer.addClass( 'foo', linkElement );
437
+ * writer.addClass( [ 'foo', 'bar' ], linkElement );
438
+ * ```
439
+ */
440
+ addClass(className: string | Array<string>, element: ViewElement): void;
441
+ /**
442
+ * Removes specified class from the element.
443
+ *
444
+ * ```ts
445
+ * writer.removeClass( 'foo', linkElement );
446
+ * writer.removeClass( [ 'foo', 'bar' ], linkElement );
447
+ * ```
448
+ */
449
+ removeClass(className: string | Array<string>, element: ViewElement): void;
450
+ /**
451
+ * Adds style to the element.
452
+ *
453
+ * ```ts
454
+ * writer.setStyle( 'color', 'red', element );
455
+ * ```
456
+ *
457
+ * **Note**: The passed style can be normalized if
458
+ * {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
459
+ * See {@link module:engine/view/stylesmap~StylesMap#set `StylesMap#set()`} for details.
460
+ *
461
+ * @label KEY_VALUE
462
+ * @param property Property name.
463
+ * @param value Value to set.
464
+ * @param element Element to set styles on.
465
+ */
466
+ setStyle(property: string, value: StyleValue, element: ViewElement): void;
467
+ /**
468
+ * Adds many styles to the element.
469
+ *
470
+ * ```ts
471
+ * writer.setStyle( {
472
+ * color: 'red',
473
+ * position: 'fixed'
474
+ * }, element );
475
+ * ```
476
+ *
477
+ * **Note**: The passed style can be normalized if
478
+ * {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
479
+ * See {@link module:engine/view/stylesmap~StylesMap#set `StylesMap#set()`} for details.
480
+ *
481
+ * @label OBJECT
482
+ * @param property Object with key - value pairs.
483
+ * @param element Element to set styles on.
484
+ */
485
+ setStyle(property: Record<string, StyleValue>, element: ViewElement): void;
486
+ /**
487
+ * Removes specified style from the element.
488
+ *
489
+ * ```ts
490
+ * writer.removeStyle( 'color', element ); // Removes 'color' style.
491
+ * writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
492
+ * ```
493
+ *
494
+ * **Note**: This method can work with normalized style names if
495
+ * {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
496
+ * See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
497
+ */
498
+ removeStyle(property: string | Array<string>, element: ViewElement): void;
499
+ /**
500
+ * Sets a custom property on element. Unlike attributes, custom properties are not rendered to the DOM,
501
+ * so they can be used to add special data to elements.
502
+ */
503
+ setCustomProperty(key: string | symbol, value: unknown, element: ViewElement | ViewDocumentFragment): void;
504
+ /**
505
+ * Removes a custom property stored under the given key.
506
+ *
507
+ * @returns Returns true if property was removed.
508
+ */
509
+ removeCustomProperty(key: string | symbol, element: ViewElement | ViewDocumentFragment): boolean;
510
+ /**
511
+ * Breaks attribute elements at the provided position or at the boundaries of a provided range. It breaks attribute elements
512
+ * up to their first ancestor that is a container element.
513
+ *
514
+ * In following examples `<p>` is a container, `<b>` and `<u>` are attribute elements:
515
+ *
516
+ * ```html
517
+ * <p>foo<b><u>bar{}</u></b></p> -> <p>foo<b><u>bar</u></b>[]</p>
518
+ * <p>foo<b><u>{}bar</u></b></p> -> <p>foo{}<b><u>bar</u></b></p>
519
+ * <p>foo<b><u>b{}ar</u></b></p> -> <p>foo<b><u>b</u></b>[]<b><u>ar</u></b></p>
520
+ * <p><b>fo{o</b><u>ba}r</u></p> -> <p><b>fo</b><b>o</b><u>ba</u><u>r</u></b></p>
521
+ * ```
522
+ *
523
+ * **Note:** {@link module:engine/view/documentfragment~ViewDocumentFragment DocumentFragment} is treated like a container.
524
+ *
525
+ * **Note:** The difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes breakAttributes()} and
526
+ * {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
527
+ * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} that are ancestors of a given `position`,
528
+ * up to the first encountered {@link module:engine/view/containerelement~ViewContainerElement container element}.
529
+ * `breakContainer()` assumes that a given `position` is directly in the container element and breaks that container element.
530
+ *
531
+ * Throws the `view-writer-invalid-range-container` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
532
+ * when the {@link module:engine/view/range~ViewRange#start start}
533
+ * and {@link module:engine/view/range~ViewRange#end end} positions of a passed range are not placed inside same parent container.
534
+ *
535
+ * Throws the `view-writer-cannot-break-empty-element` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
536
+ * when trying to break attributes inside an {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElement}.
537
+ *
538
+ * Throws the `view-writer-cannot-break-ui-element` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
539
+ * when trying to break attributes inside a {@link module:engine/view/uielement~ViewUIElement UIElement}.
540
+ *
541
+ * @see module:engine/view/attributeelement~ViewAttributeElement
542
+ * @see module:engine/view/containerelement~ViewContainerElement
543
+ * @see module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer
544
+ * @param positionOrRange The position where to break attribute elements.
545
+ * @returns The new position or range, after breaking the attribute elements.
546
+ */
547
+ breakAttributes(positionOrRange: ViewPosition | ViewRange): ViewPosition | ViewRange;
548
+ /**
549
+ * Breaks a {@link module:engine/view/containerelement~ViewContainerElement container view element} into two, at the given position.
550
+ * The position has to be directly inside the container element and cannot be in the root. It does not break the conrainer view element
551
+ * if the position is at the beginning or at the end of its parent element.
552
+ *
553
+ * ```html
554
+ * <p>foo^bar</p> -> <p>foo</p><p>bar</p>
555
+ * <div><p>foo</p>^<p>bar</p></div> -> <div><p>foo</p></div><div><p>bar</p></div>
556
+ * <p>^foobar</p> -> ^<p>foobar</p>
557
+ * <p>foobar^</p> -> <p>foobar</p>^
558
+ * ```
559
+ *
560
+ * **Note:** The difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes breakAttributes()} and
561
+ * {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
562
+ * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} that are ancestors of a given `position`,
563
+ * up to the first encountered {@link module:engine/view/containerelement~ViewContainerElement container element}.
564
+ * `breakContainer()` assumes that the given `position` is directly in the container element and breaks that container element.
565
+ *
566
+ * @see module:engine/view/attributeelement~ViewAttributeElement
567
+ * @see module:engine/view/containerelement~ViewContainerElement
568
+ * @see module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes
569
+ * @param position The position where to break the element.
570
+ * @returns The position between broken elements. If an element has not been broken,
571
+ * the returned position is placed either before or after it.
572
+ */
573
+ breakContainer(position: ViewPosition): ViewPosition;
574
+ /**
575
+ * Merges {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements}. It also merges text nodes if needed.
576
+ * Only {@link module:engine/view/attributeelement~ViewAttributeElement#isSimilar similar} attribute elements can be merged.
577
+ *
578
+ * In following examples `<p>` is a container and `<b>` is an attribute element:
579
+ *
580
+ * ```html
581
+ * <p>foo[]bar</p> -> <p>foo{}bar</p>
582
+ * <p><b>foo</b>[]<b>bar</b></p> -> <p><b>foo{}bar</b></p>
583
+ * <p><b foo="bar">a</b>[]<b foo="baz">b</b></p> -> <p><b foo="bar">a</b>[]<b foo="baz">b</b></p>
584
+ * ```
585
+ *
586
+ * It will also take care about empty attributes when merging:
587
+ *
588
+ * ```html
589
+ * <p><b>[]</b></p> -> <p>[]</p>
590
+ * <p><b>foo</b><i>[]</i><b>bar</b></p> -> <p><b>foo{}bar</b></p>
591
+ * ```
592
+ *
593
+ * **Note:** Difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes mergeAttributes} and
594
+ * {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
595
+ * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} or
596
+ * {@link module:engine/view/text~ViewText text nodes} while `mergeContainer` merges two
597
+ * {@link module:engine/view/containerelement~ViewContainerElement container elements}.
598
+ *
599
+ * @see module:engine/view/attributeelement~ViewAttributeElement
600
+ * @see module:engine/view/containerelement~ViewContainerElement
601
+ * @see module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers
602
+ * @param position Merge position.
603
+ * @returns Position after merge.
604
+ */
605
+ mergeAttributes(position: ViewPosition): ViewPosition;
606
+ /**
607
+ * Merges two {@link module:engine/view/containerelement~ViewContainerElement container elements} that are
608
+ * before and after given position. Precisely, the element after the position is removed and it's contents are
609
+ * moved to element before the position.
610
+ *
611
+ * ```html
612
+ * <p>foo</p>^<p>bar</p> -> <p>foo^bar</p>
613
+ * <div>foo</div>^<p>bar</p> -> <div>foo^bar</div>
614
+ * ```
615
+ *
616
+ * **Note:** Difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes mergeAttributes} and
617
+ * {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
618
+ * {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} or
619
+ * {@link module:engine/view/text~ViewText text nodes} while `mergeContainer` merges two
620
+ * {@link module:engine/view/containerelement~ViewContainerElement container elements}.
621
+ *
622
+ * @see module:engine/view/attributeelement~ViewAttributeElement
623
+ * @see module:engine/view/containerelement~ViewContainerElement
624
+ * @see module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes
625
+ * @param position Merge position.
626
+ * @returns Position after merge.
627
+ */
628
+ mergeContainers(position: ViewPosition): ViewPosition;
629
+ /**
630
+ * Inserts a node or nodes at specified position. Takes care about breaking attributes before insertion
631
+ * and merging them afterwards.
632
+ *
633
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-insert-invalid-node` when nodes to insert
634
+ * contains instances that are not {@link module:engine/view/text~ViewText Texts},
635
+ * {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElements},
636
+ * {@link module:engine/view/containerelement~ViewContainerElement ViewContainerElements},
637
+ * {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElements},
638
+ * {@link module:engine/view/rawelement~ViewRawElement RawElements} or
639
+ * {@link module:engine/view/uielement~ViewUIElement UIElements}.
640
+ *
641
+ * @param position Insertion position.
642
+ * @param nodes Node or nodes to insert.
643
+ * @returns Range around inserted nodes.
644
+ */
645
+ insert(position: ViewPosition, nodes: ViewNode | Iterable<ViewNode>): ViewRange;
646
+ /**
647
+ * Removes provided range from the container.
648
+ *
649
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
650
+ * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
651
+ * positions are not placed inside same parent container.
652
+ *
653
+ * @param rangeOrItem Range to remove from container
654
+ * or an {@link module:engine/view/item~ViewItem item} to remove. If range is provided, after removing, it will be updated
655
+ * to a collapsed range showing the new position.
656
+ * @returns Document fragment containing removed nodes.
657
+ */
658
+ remove(rangeOrItem: ViewRange | ViewItem): ViewDocumentFragment;
659
+ /**
660
+ * Removes matching elements from given range.
661
+ *
662
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
663
+ * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
664
+ * positions are not placed inside same parent container.
665
+ *
666
+ * @param range Range to clear.
667
+ * @param element Element to remove.
668
+ */
669
+ clear(range: ViewRange, element: ViewElement): void;
670
+ /**
671
+ * Moves nodes from provided range to target position.
672
+ *
673
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
674
+ * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
675
+ * positions are not placed inside same parent container.
676
+ *
677
+ * @param sourceRange Range containing nodes to move.
678
+ * @param targetPosition Position to insert.
679
+ * @returns Range in target container. Inserted nodes are placed between
680
+ * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end} positions.
681
+ */
682
+ move(sourceRange: ViewRange, targetPosition: ViewPosition): ViewRange;
683
+ /**
684
+ * Wraps elements within range with provided {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
685
+ * If a collapsed range is provided, it will be wrapped only if it is equal to view selection.
686
+ *
687
+ * If a collapsed range was passed and is same as selection, the selection
688
+ * will be moved to the inside of the wrapped attribute element.
689
+ *
690
+ * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-invalid-range-container`
691
+ * when {@link module:engine/view/range~ViewRange#start}
692
+ * and {@link module:engine/view/range~ViewRange#end} positions are not placed inside same parent container.
693
+ *
694
+ * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
695
+ * an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
696
+ *
697
+ * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-nonselection-collapsed-range` when passed range
698
+ * is collapsed and different than view selection.
699
+ *
700
+ * @param range Range to wrap.
701
+ * @param attribute Attribute element to use as wrapper.
702
+ * @returns range Range after wrapping, spanning over wrapping attribute element.
703
+ */
704
+ wrap(range: ViewRange, attribute: ViewAttributeElement): ViewRange;
705
+ /**
706
+ * Unwraps nodes within provided range from attribute element.
707
+ *
708
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
709
+ * {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
710
+ * positions are not placed inside same parent container.
711
+ */
712
+ unwrap(range: ViewRange, attribute: ViewAttributeElement): ViewRange;
713
+ /**
714
+ * Renames element by creating a copy of renamed element but with changed name and then moving contents of the
715
+ * old element to the new one. Keep in mind that this will invalidate all {@link module:engine/view/position~ViewPosition positions}
716
+ * which has renamed element as {@link module:engine/view/position~ViewPosition#parent a parent}.
717
+ *
718
+ * New element has to be created because `Element#tagName` property in DOM is readonly.
719
+ *
720
+ * Since this function creates a new element and removes the given one, the new element is returned to keep reference.
721
+ *
722
+ * @param newName New name for element.
723
+ * @param viewElement Element to be renamed.
724
+ * @returns Element created due to rename.
725
+ */
726
+ rename(newName: string, viewElement: ViewContainerElement): ViewContainerElement;
727
+ /**
728
+ * Cleans up memory by removing obsolete cloned elements group from the writer.
729
+ *
730
+ * Should be used whenever all {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements}
731
+ * with the same {@link module:engine/view/attributeelement~ViewAttributeElement#id id} are going to be removed from the view and
732
+ * the group will no longer be needed.
733
+ *
734
+ * Cloned elements group are not removed automatically in case if the group is still needed after all its elements
735
+ * were removed from the view.
736
+ *
737
+ * Keep in mind that group names are equal to the `id` property of the attribute element.
738
+ *
739
+ * @param groupName Name of the group to clear.
740
+ */
741
+ clearClonedElementsGroup(groupName: string): void;
742
+ /**
743
+ * Creates position at the given location. The location can be specified as:
744
+ *
745
+ * * a {@link module:engine/view/position~ViewPosition position},
746
+ * * parent element and offset (offset defaults to `0`),
747
+ * * parent element and `'end'` (sets position at the end of that element),
748
+ * * {@link module:engine/view/item~ViewItem view item} and `'before'` or `'after'` (sets position before or after given view item).
749
+ *
750
+ * This method is a shortcut to other constructors such as:
751
+ *
752
+ * * {@link #createPositionBefore},
753
+ * * {@link #createPositionAfter},
754
+ *
755
+ * @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~ViewItem view item}.
756
+ */
757
+ createPositionAt(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): ViewPosition;
758
+ /**
759
+ * Creates a new position after given view item.
760
+ *
761
+ * @param item View item after which the position should be located.
762
+ */
763
+ createPositionAfter(item: ViewItem): ViewPosition;
764
+ /**
765
+ * Creates a new position before given view item.
766
+ *
767
+ * @param item View item before which the position should be located.
768
+ */
769
+ createPositionBefore(item: ViewItem): ViewPosition;
770
+ /**
771
+ * Creates a range spanning from `start` position to `end` position.
772
+ *
773
+ * **Note:** This factory method creates its own {@link module:engine/view/position~ViewPosition} instances basing on passed values.
774
+ *
775
+ * @param start Start position.
776
+ * @param end End position. If not set, range will be collapsed at `start` position.
777
+ */
778
+ createRange(start: ViewPosition, end?: ViewPosition | null): ViewRange;
779
+ /**
780
+ * Creates a range that starts before given {@link module:engine/view/item~ViewItem view item} and ends after it.
781
+ */
782
+ createRangeOn(item: ViewItem): ViewRange;
783
+ /**
784
+ * Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
785
+ * that element and ends after the last child of that element.
786
+ *
787
+ * @param element Element which is a parent for the range.
788
+ */
789
+ createRangeIn(element: ViewElement | ViewDocumentFragment): ViewRange;
790
+ /**
791
+ * Creates new {@link module:engine/view/selection~ViewSelection} instance.
792
+ *
793
+ * ```ts
794
+ * // Creates collapsed selection at the position of given item and offset.
795
+ * const paragraph = writer.createContainerElement( 'p' );
796
+ * const selection = writer.createSelection( paragraph, offset );
797
+ *
798
+ * // Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the
799
+ * // first child of that element and ends after the last child of that element.
800
+ * const selection = writer.createSelection( paragraph, 'in' );
801
+ *
802
+ * // Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends
803
+ * // just after the item.
804
+ * const selection = writer.createSelection( paragraph, 'on' );
805
+ * ```
806
+ *
807
+ * `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
808
+ *
809
+ * ```ts
810
+ * // Creates backward selection.
811
+ * const selection = writer.createSelection( element, 'in', { backward: true } );
812
+ * ```
813
+ *
814
+ * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
815
+ * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
816
+ * represented in other way, for example by applying proper CSS class.
817
+ *
818
+ * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
819
+ * (and be properly handled by screen readers).
820
+ *
821
+ * ```ts
822
+ * // Creates fake selection with label.
823
+ * const selection = writer.createSelection( element, 'in', { fake: true, label: 'foo' } );
824
+ * ```
825
+ *
826
+ * See also: {@link #createSelection:SELECTABLE `createSelection( selectable, options )`}.
827
+ *
828
+ * @label NODE_OFFSET
829
+ */
830
+ createSelection(selectable: ViewNode, placeOrOffset: ViewPlaceOrOffset, options?: ViewSelectionOptions): ViewSelection;
831
+ /**
832
+ * Creates new {@link module:engine/view/selection~ViewSelection} instance.
833
+ *
834
+ * ```ts
835
+ * // Creates empty selection without ranges.
836
+ * const selection = writer.createSelection();
837
+ *
838
+ * // Creates selection at the given range.
839
+ * const range = writer.createRange( start, end );
840
+ * const selection = writer.createSelection( range );
841
+ *
842
+ * // Creates selection at the given ranges
843
+ * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
844
+ * const selection = writer.createSelection( ranges );
845
+ *
846
+ * // Creates selection from the other selection.
847
+ * const otherSelection = writer.createSelection();
848
+ * const selection = writer.createSelection( otherSelection );
849
+ *
850
+ * // Creates selection from the document selection.
851
+ * const selection = writer.createSelection( editor.editing.view.document.selection );
852
+ *
853
+ * // Creates selection at the given position.
854
+ * const position = writer.createPositionFromPath( root, path );
855
+ * const selection = writer.createSelection( position );
856
+ * ```
857
+ *
858
+ * `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
859
+ *
860
+ * ```ts
861
+ * // Creates backward selection.
862
+ * const selection = writer.createSelection( range, { backward: true } );
863
+ * ```
864
+ *
865
+ * Fake selection does not render as browser native selection over selected elements and is hidden to the user.
866
+ * This way, no native selection UI artifacts are displayed to the user and selection over elements can be
867
+ * represented in other way, for example by applying proper CSS class.
868
+ *
869
+ * Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
870
+ * (and be properly handled by screen readers).
871
+ *
872
+ * ```ts
873
+ * // Creates fake selection with label.
874
+ * const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
875
+ * ```
876
+ *
877
+ * See also: {@link #createSelection:NODE_OFFSET `createSelection( node, placeOrOffset, options )`}.
878
+ *
879
+ * @label SELECTABLE
880
+ */
881
+ createSelection(selectable?: Exclude<ViewSelectable, ViewNode>, option?: ViewSelectionOptions): ViewSelection;
882
+ /**
883
+ * Creates placeholders for child elements of the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
884
+ * `elementToStructure()`} conversion helper.
885
+ *
886
+ * ```ts
887
+ * const viewSlot = conversionApi.writer.createSlot();
888
+ * const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
889
+ *
890
+ * conversionApi.writer.insert( viewPosition, viewSlot );
891
+ * ```
892
+ *
893
+ * It could be filtered down to a specific subset of children (only `<foo>` model elements in this case):
894
+ *
895
+ * ```ts
896
+ * const viewSlot = conversionApi.writer.createSlot( node => node.is( 'element', 'foo' ) );
897
+ * const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
898
+ *
899
+ * conversionApi.writer.insert( viewPosition, viewSlot );
900
+ * ```
901
+ *
902
+ * While providing a filtered slot, make sure to provide slots for all child nodes. A single node cannot be downcasted into
903
+ * multiple slots.
904
+ *
905
+ * **Note**: You should not change the order of nodes. View elements should be in the same order as model nodes.
906
+ *
907
+ * @param modeOrFilter The filter for child nodes.
908
+ * @returns The slot element to be placed in to the view structure while processing
909
+ * {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure `elementToStructure()`}.
910
+ */
911
+ createSlot(modeOrFilter?: "children" | DowncastSlotFilter): ViewElement;
912
+ /**
913
+ * Registers a slot factory.
914
+ *
915
+ * @internal
916
+ * @param slotFactory The slot factory.
917
+ */
918
+ _registerSlotFactory(slotFactory: (writer: ViewDowncastWriter, modeOrFilter: "children" | DowncastSlotFilter) => ViewElement): void;
919
+ /**
920
+ * Clears the registered slot factory.
921
+ *
922
+ * @internal
923
+ */
924
+ _clearSlotFactory(): void;
925
+ /**
926
+ * Inserts a node or nodes at the specified position. Takes care of breaking attributes before insertion
927
+ * and merging them afterwards if requested by the breakAttributes param.
928
+ *
929
+ * @param position Insertion position.
930
+ * @param nodes Node or nodes to insert.
931
+ * @param breakAttributes Whether attributes should be broken.
932
+ * @returns Range around inserted nodes.
933
+ */
934
+ private _insertNodes;
935
+ /**
936
+ * Wraps children with provided `wrapElement`. Only children contained in `parent` element between
937
+ * `startOffset` and `endOffset` will be wrapped.
938
+ */
939
+ private _wrapChildren;
940
+ /**
941
+ * Unwraps children from provided `unwrapElement`. Only children contained in `parent` element between
942
+ * `startOffset` and `endOffset` will be unwrapped.
943
+ */
944
+ private _unwrapChildren;
945
+ /**
946
+ * Helper function for `view.writer.wrap`. Wraps range with provided attribute element.
947
+ * This method will also merge newly added attribute element with its siblings whenever possible.
948
+ *
949
+ * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
950
+ * an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
951
+ *
952
+ * @returns New range after wrapping, spanning over wrapping attribute element.
953
+ */
954
+ private _wrapRange;
955
+ /**
956
+ * Helper function for {@link #wrap}. Wraps position with provided attribute element.
957
+ * This method will also merge newly added attribute element with its siblings whenever possible.
958
+ *
959
+ * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
960
+ * an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
961
+ *
962
+ * @returns New position after wrapping.
963
+ */
964
+ private _wrapPosition;
965
+ /**
966
+ * Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at the boundaries of given range.
967
+ *
968
+ * @param range Range which `start` and `end` positions will be used to break attributes.
969
+ * @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
970
+ * This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
971
+ * @returns New range with located at break positions.
972
+ */
973
+ private _breakAttributesRange;
974
+ /**
975
+ * Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at given position.
976
+ *
977
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-empty-element` when break position
978
+ * is placed inside {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElement}.
979
+ *
980
+ * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-ui-element` when break position
981
+ * is placed inside {@link module:engine/view/uielement~ViewUIElement UIElement}.
982
+ *
983
+ * @param position Position where to break attributes.
984
+ * @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
985
+ * This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
986
+ * @returns New position after breaking the attributes.
987
+ */
988
+ private _breakAttributes;
989
+ /**
990
+ * Stores the information that an {@link module:engine/view/attributeelement~ViewAttributeElement attribute element} was
991
+ * added to the tree. Saves the reference to the group in the given element and updates the group, so other elements
992
+ * from the group now keep a reference to the given attribute element.
993
+ *
994
+ * The clones group can be obtained using {@link module:engine/view/attributeelement~ViewAttributeElement#getElementsWithSameId}.
995
+ *
996
+ * Does nothing if added element has no {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
997
+ *
998
+ * @param element Attribute element to save.
999
+ */
1000
+ private _addToClonedElementsGroup;
1001
+ /**
1002
+ * Removes all the information about the given {@link module:engine/view/attributeelement~ViewAttributeElement attribute element}
1003
+ * from its clones group.
1004
+ *
1005
+ * Keep in mind, that the element will still keep a reference to the group (but the group will not keep a reference to it).
1006
+ * This allows to reference the whole group even if the element was already removed from the tree.
1007
+ *
1008
+ * Does nothing if the element has no {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
1009
+ *
1010
+ * @param element Attribute element to remove.
1011
+ */
1012
+ private _removeFromClonedElementsGroup;
1013
1013
  }
1014
1014
  export {};