@ckeditor/ckeditor5-engine 35.0.1 → 35.1.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.
- package/CHANGELOG.md +4 -4
- package/package.json +30 -24
- package/src/controller/datacontroller.js +467 -561
- package/src/controller/editingcontroller.js +168 -204
- package/src/conversion/conversion.js +541 -565
- package/src/conversion/conversionhelpers.js +24 -28
- package/src/conversion/downcastdispatcher.js +457 -686
- package/src/conversion/downcasthelpers.js +1583 -1965
- package/src/conversion/mapper.js +518 -707
- package/src/conversion/modelconsumable.js +240 -283
- package/src/conversion/upcastdispatcher.js +372 -718
- package/src/conversion/upcasthelpers.js +707 -818
- package/src/conversion/viewconsumable.js +524 -581
- package/src/dataprocessor/basichtmlwriter.js +12 -16
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.js +100 -116
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +116 -137
- package/src/dev-utils/model.js +260 -352
- package/src/dev-utils/operationreplayer.js +106 -126
- package/src/dev-utils/utils.js +34 -51
- package/src/dev-utils/view.js +632 -753
- package/src/index.js +0 -11
- package/src/model/batch.js +111 -127
- package/src/model/differ.js +988 -1233
- package/src/model/document.js +340 -449
- package/src/model/documentfragment.js +327 -364
- package/src/model/documentselection.js +996 -1189
- package/src/model/element.js +306 -410
- package/src/model/history.js +224 -262
- package/src/model/item.js +5 -0
- package/src/model/liveposition.js +84 -145
- package/src/model/liverange.js +108 -185
- package/src/model/markercollection.js +379 -480
- package/src/model/model.js +883 -1034
- package/src/model/node.js +419 -463
- package/src/model/nodelist.js +175 -201
- package/src/model/operation/attributeoperation.js +153 -182
- package/src/model/operation/detachoperation.js +64 -83
- package/src/model/operation/insertoperation.js +135 -166
- package/src/model/operation/markeroperation.js +114 -140
- package/src/model/operation/mergeoperation.js +163 -191
- package/src/model/operation/moveoperation.js +157 -187
- package/src/model/operation/nooperation.js +28 -38
- package/src/model/operation/operation.js +106 -125
- package/src/model/operation/operationfactory.js +30 -34
- package/src/model/operation/renameoperation.js +109 -135
- package/src/model/operation/rootattributeoperation.js +155 -188
- package/src/model/operation/splitoperation.js +196 -232
- package/src/model/operation/transform.js +1833 -2204
- package/src/model/operation/utils.js +140 -204
- package/src/model/position.js +899 -1053
- package/src/model/range.js +910 -1028
- package/src/model/rootelement.js +77 -97
- package/src/model/schema.js +1189 -1835
- package/src/model/selection.js +745 -862
- package/src/model/text.js +90 -114
- package/src/model/textproxy.js +204 -240
- package/src/model/treewalker.js +316 -397
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.js +32 -44
- package/src/model/utils/deletecontent.js +334 -418
- package/src/model/utils/findoptimalinsertionrange.js +25 -36
- package/src/model/utils/getselectedcontent.js +96 -118
- package/src/model/utils/insertcontent.js +654 -773
- package/src/model/utils/insertobject.js +96 -119
- package/src/model/utils/modifyselection.js +120 -158
- package/src/model/utils/selection-post-fixer.js +153 -201
- package/src/model/writer.js +1305 -1474
- package/src/view/attributeelement.js +189 -225
- package/src/view/containerelement.js +75 -85
- package/src/view/document.js +172 -215
- package/src/view/documentfragment.js +200 -249
- package/src/view/documentselection.js +338 -367
- package/src/view/domconverter.js +1370 -1617
- package/src/view/downcastwriter.js +1747 -2076
- package/src/view/editableelement.js +81 -97
- package/src/view/element.js +739 -890
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.js +82 -92
- package/src/view/filler.js +35 -50
- package/src/view/item.js +5 -0
- package/src/view/matcher.js +260 -559
- package/src/view/node.js +274 -360
- package/src/view/observer/arrowkeysobserver.js +19 -28
- package/src/view/observer/bubblingemittermixin.js +120 -263
- package/src/view/observer/bubblingeventinfo.js +47 -55
- package/src/view/observer/clickobserver.js +7 -13
- package/src/view/observer/compositionobserver.js +14 -24
- package/src/view/observer/domeventdata.js +57 -67
- package/src/view/observer/domeventobserver.js +40 -64
- package/src/view/observer/fakeselectionobserver.js +81 -96
- package/src/view/observer/focusobserver.js +45 -61
- package/src/view/observer/inputobserver.js +7 -13
- package/src/view/observer/keyobserver.js +17 -27
- package/src/view/observer/mouseobserver.js +7 -14
- package/src/view/observer/mutationobserver.js +220 -315
- package/src/view/observer/observer.js +81 -102
- package/src/view/observer/selectionobserver.js +191 -246
- package/src/view/observer/tabobserver.js +23 -36
- package/src/view/placeholder.js +128 -173
- package/src/view/position.js +350 -401
- package/src/view/range.js +453 -513
- package/src/view/rawelement.js +85 -112
- package/src/view/renderer.js +874 -1018
- package/src/view/rooteditableelement.js +80 -90
- package/src/view/selection.js +608 -689
- package/src/view/styles/background.js +43 -44
- package/src/view/styles/border.js +220 -276
- package/src/view/styles/margin.js +8 -17
- package/src/view/styles/padding.js +8 -16
- package/src/view/styles/utils.js +127 -160
- package/src/view/stylesmap.js +728 -905
- package/src/view/text.js +102 -126
- package/src/view/textproxy.js +144 -170
- package/src/view/treewalker.js +383 -479
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.js +166 -187
- package/src/view/upcastwriter.js +395 -449
- package/src/view/view.js +569 -664
- package/src/dataprocessor/dataprocessor.jsdoc +0 -64
- package/src/model/item.jsdoc +0 -14
- package/src/view/elementdefinition.jsdoc +0 -59
- package/src/view/item.jsdoc +0 -14
package/src/view/upcastwriter.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module module:engine/view/upcastwriter
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import DocumentFragment from './documentfragment';
|
|
11
9
|
import Element from './element';
|
|
12
10
|
import Text from './text';
|
|
@@ -14,7 +12,6 @@ import { isPlainObject } from 'lodash-es';
|
|
|
14
12
|
import Position from './position';
|
|
15
13
|
import Range from './range';
|
|
16
14
|
import Selection from './selection';
|
|
17
|
-
|
|
18
15
|
/**
|
|
19
16
|
* View upcast writer. It provides a set of methods used to manipulate non-semantic view trees.
|
|
20
17
|
*
|
|
@@ -35,450 +32,399 @@ import Selection from './selection';
|
|
|
35
32
|
* writer.appendChild( text, someViewElement );
|
|
36
33
|
*/
|
|
37
34
|
export default class UpcastWriter {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
* const selection = writer.createSelection( ranges );
|
|
434
|
-
*
|
|
435
|
-
* // Creates selection from the other selection.
|
|
436
|
-
* const otherSelection = writer.createSelection();
|
|
437
|
-
* const selection = writer.createSelection( otherSelection );
|
|
438
|
-
*
|
|
439
|
-
* // Creates selection from the document selection.
|
|
440
|
-
* const selection = writer.createSelection( editor.editing.view.document.selection );
|
|
441
|
-
*
|
|
442
|
-
* // Creates selection at the given position.
|
|
443
|
-
* const position = writer.createPositionFromPath( root, path );
|
|
444
|
-
* const selection = writer.createSelection( position );
|
|
445
|
-
*
|
|
446
|
-
* // Creates collapsed selection at the position of given item and offset.
|
|
447
|
-
* const paragraph = writer.createContainerElement( 'paragraph' );
|
|
448
|
-
* const selection = writer.createSelection( paragraph, offset );
|
|
449
|
-
*
|
|
450
|
-
* // Creates a range inside an {@link module:engine/view/element~Element element} which starts before the
|
|
451
|
-
* // first child of that element and ends after the last child of that element.
|
|
452
|
-
* const selection = writer.createSelection( paragraph, 'in' );
|
|
453
|
-
*
|
|
454
|
-
* // Creates a range on an {@link module:engine/view/item~Item item} which starts before the item and ends
|
|
455
|
-
* // just after the item.
|
|
456
|
-
* const selection = writer.createSelection( paragraph, 'on' );
|
|
457
|
-
*
|
|
458
|
-
* `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
459
|
-
*
|
|
460
|
-
* // Creates backward selection.
|
|
461
|
-
* const selection = writer.createSelection( range, { backward: true } );
|
|
462
|
-
*
|
|
463
|
-
* Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
464
|
-
* This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
465
|
-
* represented in other way, for example by applying proper CSS class.
|
|
466
|
-
*
|
|
467
|
-
* Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
468
|
-
* (and be properly handled by screen readers).
|
|
469
|
-
*
|
|
470
|
-
* // Creates fake selection with label.
|
|
471
|
-
* const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
|
|
472
|
-
*
|
|
473
|
-
* @param {module:engine/view/selection~Selectable} [selectable=null]
|
|
474
|
-
* @param {Number|'before'|'end'|'after'|'on'|'in'} [placeOrOffset] Offset or place when selectable is an `Item`.
|
|
475
|
-
* @param {Object} [options]
|
|
476
|
-
* @param {Boolean} [options.backward] Sets this selection instance to be backward.
|
|
477
|
-
* @param {Boolean} [options.fake] Sets this selection instance to be marked as `fake`.
|
|
478
|
-
* @param {String} [options.label] Label for the fake selection.
|
|
479
|
-
* @returns {module:engine/view/selection~Selection}
|
|
480
|
-
*/
|
|
481
|
-
createSelection( selectable, placeOrOffset, options ) {
|
|
482
|
-
return new Selection( selectable, placeOrOffset, options );
|
|
483
|
-
}
|
|
35
|
+
/**
|
|
36
|
+
* @param {module:engine/view/document~Document} document The view document instance in which this upcast writer operates.
|
|
37
|
+
*/
|
|
38
|
+
constructor(document) {
|
|
39
|
+
/**
|
|
40
|
+
* The view document instance in which this upcast writer operates.
|
|
41
|
+
*
|
|
42
|
+
* @readonly
|
|
43
|
+
* @type {module:engine/view/document~Document}
|
|
44
|
+
*/
|
|
45
|
+
this.document = document;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new {@link module:engine/view/documentfragment~DocumentFragment} instance.
|
|
49
|
+
*
|
|
50
|
+
* @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children]
|
|
51
|
+
* A list of nodes to be inserted into the created document fragment.
|
|
52
|
+
* @returns {module:engine/view/documentfragment~DocumentFragment} The created document fragment.
|
|
53
|
+
*/
|
|
54
|
+
createDocumentFragment(children) {
|
|
55
|
+
return new DocumentFragment(this.document, children);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new {@link module:engine/view/element~Element} instance.
|
|
59
|
+
*
|
|
60
|
+
* Attributes can be passed in various formats:
|
|
61
|
+
*
|
|
62
|
+
* upcastWriter.createElement( 'div', { class: 'editor', contentEditable: 'true' } ); // object
|
|
63
|
+
* upcastWriter.createElement( 'div', [ [ 'class', 'editor' ], [ 'contentEditable', 'true' ] ] ); // map-like iterator
|
|
64
|
+
* upcastWriter.createElement( 'div', mapOfAttributes ); // map
|
|
65
|
+
*
|
|
66
|
+
* @param {String} name Node name.
|
|
67
|
+
* @param {Object|Iterable} [attrs] Collection of attributes.
|
|
68
|
+
* @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children]
|
|
69
|
+
* A list of nodes to be inserted into created element.
|
|
70
|
+
* @returns {module:engine/view/element~Element} Created element.
|
|
71
|
+
*/
|
|
72
|
+
createElement(name, attrs, children) {
|
|
73
|
+
return new Element(this.document, name, attrs, children);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new {@link module:engine/view/text~Text} instance.
|
|
77
|
+
*
|
|
78
|
+
* @param {String} data The text's data.
|
|
79
|
+
* @returns {module:engine/view/text~Text} The created text node.
|
|
80
|
+
*/
|
|
81
|
+
createText(data) {
|
|
82
|
+
return new Text(this.document, data);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clones the provided element.
|
|
86
|
+
*
|
|
87
|
+
* @see module:engine/view/element~Element#_clone
|
|
88
|
+
* @param {module:engine/view/element~Element} element Element to be cloned.
|
|
89
|
+
* @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
|
|
90
|
+
* element will be cloned without any children.
|
|
91
|
+
* @returns {module:engine/view/element~Element} Clone of this element.
|
|
92
|
+
*/
|
|
93
|
+
clone(element, deep = false) {
|
|
94
|
+
return element._clone(deep);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Appends a child node or a list of child nodes at the end of this node
|
|
98
|
+
* and sets the parent of these nodes to this element.
|
|
99
|
+
*
|
|
100
|
+
* @see module:engine/view/element~Element#_appendChild
|
|
101
|
+
* @param {module:engine/view/item~Item|Iterable.<module:engine/view/item~Item>} items Items to be inserted.
|
|
102
|
+
* @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} element Element
|
|
103
|
+
* to which items will be appended.
|
|
104
|
+
* @fires module:engine/view/node~Node#event:change
|
|
105
|
+
* @returns {Number} Number of appended nodes.
|
|
106
|
+
*/
|
|
107
|
+
appendChild(items, element) {
|
|
108
|
+
return element._appendChild(items);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Inserts a child node or a list of child nodes on the given index and sets the parent of these nodes to
|
|
112
|
+
* this element.
|
|
113
|
+
*
|
|
114
|
+
* @see module:engine/view/element~Element#_insertChild
|
|
115
|
+
* @param {Number} index Offset at which nodes should be inserted.
|
|
116
|
+
* @param {module:engine/view/item~Item|Iterable.<module:engine/view/item~Item>} items Items to be inserted.
|
|
117
|
+
* @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} element Element
|
|
118
|
+
* to which items will be inserted.
|
|
119
|
+
* @fires module:engine/view/node~Node#event:change
|
|
120
|
+
* @returns {Number} Number of inserted nodes.
|
|
121
|
+
*/
|
|
122
|
+
insertChild(index, items, element) {
|
|
123
|
+
return element._insertChild(index, items);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Removes the given number of child nodes starting at the given index and set the parent of these nodes to `null`.
|
|
127
|
+
*
|
|
128
|
+
* @see module:engine/view/element~Element#_removeChildren
|
|
129
|
+
* @param {Number} index Offset from which nodes will be removed.
|
|
130
|
+
* @param {Number} howMany Number of nodes to remove.
|
|
131
|
+
* @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} element Element
|
|
132
|
+
* which children will be removed.
|
|
133
|
+
* @fires module:engine/view/node~Node#event:change
|
|
134
|
+
* @returns {Array.<module:engine/view/node~Node>} The array containing removed nodes.
|
|
135
|
+
*/
|
|
136
|
+
removeChildren(index, howMany, element) {
|
|
137
|
+
return element._removeChildren(index, howMany);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Removes given element from the view structure. Will not have effect on detached elements.
|
|
141
|
+
*
|
|
142
|
+
* @param {module:engine/view/element~Element} element Element which will be removed.
|
|
143
|
+
* @returns {Array.<module:engine/view/node~Node>} The array containing removed nodes.
|
|
144
|
+
*/
|
|
145
|
+
remove(element) {
|
|
146
|
+
const parent = element.parent;
|
|
147
|
+
if (parent) {
|
|
148
|
+
return this.removeChildren(parent.getChildIndex(element), 1, parent);
|
|
149
|
+
}
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Replaces given element with the new one in the view structure. Will not have effect on detached elements.
|
|
154
|
+
*
|
|
155
|
+
* @param {module:engine/view/element~Element} oldElement Element which will be replaced.
|
|
156
|
+
* @param {module:engine/view/element~Element} newElement Element which will be inserted in the place of the old element.
|
|
157
|
+
* @returns {Boolean} Whether old element was successfully replaced.
|
|
158
|
+
*/
|
|
159
|
+
replace(oldElement, newElement) {
|
|
160
|
+
const parent = oldElement.parent;
|
|
161
|
+
if (parent) {
|
|
162
|
+
const index = parent.getChildIndex(oldElement);
|
|
163
|
+
this.removeChildren(index, 1, parent);
|
|
164
|
+
this.insertChild(index, newElement, parent);
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Removes given element from view structure and places its children in its position.
|
|
171
|
+
* It does nothing if element has no parent.
|
|
172
|
+
*
|
|
173
|
+
* @param {module:engine/view/element~Element} element Element to unwrap.
|
|
174
|
+
*/
|
|
175
|
+
unwrapElement(element) {
|
|
176
|
+
const parent = element.parent;
|
|
177
|
+
if (parent) {
|
|
178
|
+
const index = parent.getChildIndex(element);
|
|
179
|
+
this.remove(element);
|
|
180
|
+
this.insertChild(index, element.getChildren(), parent);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Renames element by creating a copy of a given element but with its name changed and then moving contents of the
|
|
185
|
+
* old element to the new one.
|
|
186
|
+
*
|
|
187
|
+
* Since this function creates a new element and removes the given one, the new element is returned to keep reference.
|
|
188
|
+
*
|
|
189
|
+
* @param {String} newName New element name.
|
|
190
|
+
* @param {module:engine/view/element~Element} element Element to be renamed.
|
|
191
|
+
* @returns {module:engine/view/element~Element|null} New element or null if the old element
|
|
192
|
+
* was not replaced (happens for detached elements).
|
|
193
|
+
*/
|
|
194
|
+
rename(newName, element) {
|
|
195
|
+
const newElement = new Element(this.document, newName, element.getAttributes(), element.getChildren());
|
|
196
|
+
return this.replace(element, newElement) ? newElement : null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Adds or overwrites element's attribute with a specified key and value.
|
|
200
|
+
*
|
|
201
|
+
* writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
|
|
202
|
+
*
|
|
203
|
+
* @see module:engine/view/element~Element#_setAttribute
|
|
204
|
+
* @param {String} key Attribute key.
|
|
205
|
+
* @param {String} value Attribute value.
|
|
206
|
+
* @param {module:engine/view/element~Element} element Element for which attribute will be set.
|
|
207
|
+
*/
|
|
208
|
+
setAttribute(key, value, element) {
|
|
209
|
+
element._setAttribute(key, value);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Removes attribute from the element.
|
|
213
|
+
*
|
|
214
|
+
* writer.removeAttribute( 'href', linkElement );
|
|
215
|
+
*
|
|
216
|
+
* @see module:engine/view/element~Element#_removeAttribute
|
|
217
|
+
* @param {String} key Attribute key.
|
|
218
|
+
* @param {module:engine/view/element~Element} element Element from which attribute will be removed.
|
|
219
|
+
*/
|
|
220
|
+
removeAttribute(key, element) {
|
|
221
|
+
element._removeAttribute(key);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Adds specified class to the element.
|
|
225
|
+
*
|
|
226
|
+
* writer.addClass( 'foo', linkElement );
|
|
227
|
+
* writer.addClass( [ 'foo', 'bar' ], linkElement );
|
|
228
|
+
*
|
|
229
|
+
* @see module:engine/view/element~Element#_addClass
|
|
230
|
+
* @param {Array.<String>|String} className Single class name or array of class names which will be added.
|
|
231
|
+
* @param {module:engine/view/element~Element} element Element for which class will be added.
|
|
232
|
+
*/
|
|
233
|
+
addClass(className, element) {
|
|
234
|
+
element._addClass(className);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Removes specified class from the element.
|
|
238
|
+
*
|
|
239
|
+
* writer.removeClass( 'foo', linkElement );
|
|
240
|
+
* writer.removeClass( [ 'foo', 'bar' ], linkElement );
|
|
241
|
+
*
|
|
242
|
+
* @see module:engine/view/element~Element#_removeClass
|
|
243
|
+
* @param {Array.<String>|String} className Single class name or array of class names which will be removed.
|
|
244
|
+
* @param {module:engine/view/element~Element} element Element from which class will be removed.
|
|
245
|
+
*/
|
|
246
|
+
removeClass(className, element) {
|
|
247
|
+
element._removeClass(className);
|
|
248
|
+
}
|
|
249
|
+
setStyle(property, valueOrElement, element) {
|
|
250
|
+
if (isPlainObject(property) && element === undefined) {
|
|
251
|
+
valueOrElement._setStyle(property);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
element._setStyle(property, valueOrElement);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Removes specified style from the element.
|
|
259
|
+
*
|
|
260
|
+
* writer.removeStyle( 'color', element ); // Removes 'color' style.
|
|
261
|
+
* writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
|
|
262
|
+
*
|
|
263
|
+
* **Note**: This method can work with normalized style names if
|
|
264
|
+
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
265
|
+
* See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
|
|
266
|
+
*
|
|
267
|
+
* @see module:engine/view/element~Element#_removeStyle
|
|
268
|
+
* @param {Array.<String>|String} property Style property name or names to be removed.
|
|
269
|
+
* @param {module:engine/view/element~Element} element Element from which style will be removed.
|
|
270
|
+
*/
|
|
271
|
+
removeStyle(property, element) {
|
|
272
|
+
element._removeStyle(property);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Sets a custom property on element. Unlike attributes, custom properties are not rendered to the DOM,
|
|
276
|
+
* so they can be used to add special data to elements.
|
|
277
|
+
*
|
|
278
|
+
* @see module:engine/view/element~Element#_setCustomProperty
|
|
279
|
+
* @param {String|Symbol} key Custom property name/key.
|
|
280
|
+
* @param {*} value Custom property value to be stored.
|
|
281
|
+
* @param {module:engine/view/element~Element} element Element for which custom property will be set.
|
|
282
|
+
*/
|
|
283
|
+
setCustomProperty(key, value, element) {
|
|
284
|
+
element._setCustomProperty(key, value);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Removes a custom property stored under the given key.
|
|
288
|
+
*
|
|
289
|
+
* @see module:engine/view/element~Element#_removeCustomProperty
|
|
290
|
+
* @param {String|Symbol} key Name/key of the custom property to be removed.
|
|
291
|
+
* @param {module:engine/view/element~Element} element Element from which the custom property will be removed.
|
|
292
|
+
* @returns {Boolean} Returns true if property was removed.
|
|
293
|
+
*/
|
|
294
|
+
removeCustomProperty(key, element) {
|
|
295
|
+
return element._removeCustomProperty(key);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Creates position at the given location. The location can be specified as:
|
|
299
|
+
*
|
|
300
|
+
* * a {@link module:engine/view/position~Position position},
|
|
301
|
+
* * parent element and offset (offset defaults to `0`),
|
|
302
|
+
* * parent element and `'end'` (sets position at the end of that element),
|
|
303
|
+
* * {@link module:engine/view/item~Item view item} and `'before'` or `'after'` (sets position before or after given view item).
|
|
304
|
+
*
|
|
305
|
+
* This method is a shortcut to other constructors such as:
|
|
306
|
+
*
|
|
307
|
+
* * {@link #createPositionBefore},
|
|
308
|
+
* * {@link #createPositionAfter},
|
|
309
|
+
*
|
|
310
|
+
* @param {module:engine/view/item~Item|module:engine/model/position~Position} itemOrPosition
|
|
311
|
+
* @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when
|
|
312
|
+
* first parameter is a {@link module:engine/view/item~Item view item}.
|
|
313
|
+
* @returns {module:engine/view/position~Position}
|
|
314
|
+
*/
|
|
315
|
+
createPositionAt(itemOrPosition, offset) {
|
|
316
|
+
return Position._createAt(itemOrPosition, offset);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Creates a new position after given view item.
|
|
320
|
+
*
|
|
321
|
+
* @param {module:engine/view/item~Item} item View item after which the position should be located.
|
|
322
|
+
* @returns {module:engine/view/position~Position}
|
|
323
|
+
*/
|
|
324
|
+
createPositionAfter(item) {
|
|
325
|
+
return Position._createAfter(item);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Creates a new position before given view item.
|
|
329
|
+
*
|
|
330
|
+
* @param {module:engine/view/item~Item} item View item before which the position should be located.
|
|
331
|
+
* @returns {module:engine/view/position~Position}
|
|
332
|
+
*/
|
|
333
|
+
createPositionBefore(item) {
|
|
334
|
+
return Position._createBefore(item);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Creates a range spanning from `start` position to `end` position.
|
|
338
|
+
*
|
|
339
|
+
* **Note:** This factory method creates it's own {@link module:engine/view/position~Position} instances basing on passed values.
|
|
340
|
+
*
|
|
341
|
+
* @param {module:engine/view/position~Position} start Start position.
|
|
342
|
+
* @param {module:engine/view/position~Position} [end] End position. If not set, range will be collapsed at `start` position.
|
|
343
|
+
* @returns {module:engine/view/range~Range}
|
|
344
|
+
*/
|
|
345
|
+
createRange(start, end) {
|
|
346
|
+
return new Range(start, end);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Creates a range that starts before given {@link module:engine/view/item~Item view item} and ends after it.
|
|
350
|
+
*
|
|
351
|
+
* @param {module:engine/view/item~Item} item
|
|
352
|
+
* @returns {module:engine/view/range~Range}
|
|
353
|
+
*/
|
|
354
|
+
createRangeOn(item) {
|
|
355
|
+
return Range._createOn(item);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Creates a range inside an {@link module:engine/view/element~Element element} which starts before the first child of
|
|
359
|
+
* that element and ends after the last child of that element.
|
|
360
|
+
*
|
|
361
|
+
* @param {module:engine/view/element~Element} element Element which is a parent for the range.
|
|
362
|
+
* @returns {module:engine/view/range~Range}
|
|
363
|
+
*/
|
|
364
|
+
createRangeIn(element) {
|
|
365
|
+
return Range._createIn(element);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Creates a new {@link module:engine/view/selection~Selection} instance.
|
|
369
|
+
*
|
|
370
|
+
* // Creates empty selection without ranges.
|
|
371
|
+
* const selection = writer.createSelection();
|
|
372
|
+
*
|
|
373
|
+
* // Creates selection at the given range.
|
|
374
|
+
* const range = writer.createRange( start, end );
|
|
375
|
+
* const selection = writer.createSelection( range );
|
|
376
|
+
*
|
|
377
|
+
* // Creates selection at the given ranges
|
|
378
|
+
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
|
|
379
|
+
* const selection = writer.createSelection( ranges );
|
|
380
|
+
*
|
|
381
|
+
* // Creates selection from the other selection.
|
|
382
|
+
* const otherSelection = writer.createSelection();
|
|
383
|
+
* const selection = writer.createSelection( otherSelection );
|
|
384
|
+
*
|
|
385
|
+
* // Creates selection from the document selection.
|
|
386
|
+
* const selection = writer.createSelection( editor.editing.view.document.selection );
|
|
387
|
+
*
|
|
388
|
+
* // Creates selection at the given position.
|
|
389
|
+
* const position = writer.createPositionFromPath( root, path );
|
|
390
|
+
* const selection = writer.createSelection( position );
|
|
391
|
+
*
|
|
392
|
+
* // Creates collapsed selection at the position of given item and offset.
|
|
393
|
+
* const paragraph = writer.createContainerElement( 'paragraph' );
|
|
394
|
+
* const selection = writer.createSelection( paragraph, offset );
|
|
395
|
+
*
|
|
396
|
+
* // Creates a range inside an {@link module:engine/view/element~Element element} which starts before the
|
|
397
|
+
* // first child of that element and ends after the last child of that element.
|
|
398
|
+
* const selection = writer.createSelection( paragraph, 'in' );
|
|
399
|
+
*
|
|
400
|
+
* // Creates a range on an {@link module:engine/view/item~Item item} which starts before the item and ends
|
|
401
|
+
* // just after the item.
|
|
402
|
+
* const selection = writer.createSelection( paragraph, 'on' );
|
|
403
|
+
*
|
|
404
|
+
* `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
405
|
+
*
|
|
406
|
+
* // Creates backward selection.
|
|
407
|
+
* const selection = writer.createSelection( range, { backward: true } );
|
|
408
|
+
*
|
|
409
|
+
* Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
410
|
+
* This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
411
|
+
* represented in other way, for example by applying proper CSS class.
|
|
412
|
+
*
|
|
413
|
+
* Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
414
|
+
* (and be properly handled by screen readers).
|
|
415
|
+
*
|
|
416
|
+
* // Creates fake selection with label.
|
|
417
|
+
* const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
|
|
418
|
+
*
|
|
419
|
+
* @param {module:engine/view/selection~Selectable} [selectable=null]
|
|
420
|
+
* @param {Number|'before'|'end'|'after'|'on'|'in'} [placeOrOffset] Offset or place when selectable is an `Item`.
|
|
421
|
+
* @param {Object} [options]
|
|
422
|
+
* @param {Boolean} [options.backward] Sets this selection instance to be backward.
|
|
423
|
+
* @param {Boolean} [options.fake] Sets this selection instance to be marked as `fake`.
|
|
424
|
+
* @param {String} [options.label] Label for the fake selection.
|
|
425
|
+
* @returns {module:engine/view/selection~Selection}
|
|
426
|
+
*/
|
|
427
|
+
createSelection(...args) {
|
|
428
|
+
return new Selection(...args);
|
|
429
|
+
}
|
|
484
430
|
}
|