@ckeditor/ckeditor5-engine 35.4.0 → 36.0.1
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/LICENSE.md +1 -1
- package/package.json +22 -22
- package/src/controller/datacontroller.js +5 -1
- package/src/controller/editingcontroller.js +1 -1
- package/src/conversion/conversion.js +1 -1
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.js +1 -1
- package/src/conversion/downcasthelpers.js +1 -1
- package/src/conversion/mapper.js +1 -1
- package/src/conversion/modelconsumable.js +1 -1
- package/src/conversion/upcastdispatcher.js +1 -1
- package/src/conversion/upcasthelpers.js +8 -1
- package/src/conversion/viewconsumable.js +1 -1
- package/src/dataprocessor/basichtmlwriter.js +1 -1
- package/src/dataprocessor/dataprocessor.js +1 -1
- package/src/dataprocessor/htmldataprocessor.js +1 -2
- package/src/dataprocessor/htmlwriter.js +1 -1
- package/src/dataprocessor/xmldataprocessor.js +1 -1
- package/src/dev-utils/model.js +1 -1
- package/src/dev-utils/operationreplayer.js +1 -1
- package/src/dev-utils/utils.js +1 -1
- package/src/dev-utils/view.js +1 -1
- package/src/index.js +3 -2
- package/src/model/batch.js +9 -46
- package/src/model/differ.js +81 -174
- package/src/model/document.js +36 -92
- package/src/model/documentfragment.js +43 -96
- package/src/model/documentselection.js +151 -245
- package/src/model/element.js +47 -100
- package/src/model/history.js +15 -46
- package/src/model/item.js +1 -1
- package/src/model/liveposition.js +10 -36
- package/src/model/liverange.js +13 -36
- package/src/model/markercollection.js +40 -111
- package/src/model/model.js +212 -289
- package/src/model/node.js +35 -125
- package/src/model/nodelist.js +11 -39
- package/src/model/operation/attributeoperation.js +13 -44
- package/src/model/operation/detachoperation.js +3 -16
- package/src/model/operation/insertoperation.js +6 -34
- package/src/model/operation/markeroperation.js +9 -48
- package/src/model/operation/mergeoperation.js +8 -41
- package/src/model/operation/moveoperation.js +14 -37
- package/src/model/operation/nooperation.js +1 -7
- package/src/model/operation/operation.js +5 -63
- package/src/model/operation/operationfactory.js +3 -6
- package/src/model/operation/renameoperation.js +8 -28
- package/src/model/operation/rootattributeoperation.js +18 -47
- package/src/model/operation/splitoperation.js +9 -47
- package/src/model/operation/transform.js +109 -150
- package/src/model/operation/utils.js +36 -50
- package/src/model/position.js +117 -228
- package/src/model/range.js +145 -200
- package/src/model/rootelement.js +8 -47
- package/src/model/schema.js +236 -272
- package/src/model/selection.js +134 -192
- package/src/model/text.js +10 -37
- package/src/model/textproxy.js +15 -69
- package/src/model/treewalker.js +10 -101
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.js +11 -12
- package/src/model/utils/deletecontent.js +93 -62
- package/src/model/utils/findoptimalinsertionrange.js +24 -24
- package/src/model/utils/getselectedcontent.js +3 -6
- package/src/model/utils/insertcontent.js +36 -129
- package/src/model/utils/insertobject.js +19 -21
- package/src/model/utils/modifyselection.js +23 -33
- package/src/model/utils/selection-post-fixer.js +53 -59
- package/src/model/writer.js +208 -314
- package/src/view/attributeelement.js +1 -1
- package/src/view/containerelement.js +1 -1
- package/src/view/datatransfer.js +25 -28
- package/src/view/document.js +1 -17
- package/src/view/documentfragment.js +49 -1
- package/src/view/documentselection.js +1 -1
- package/src/view/domconverter.js +4 -3
- package/src/view/downcastwriter.js +1 -1
- package/src/view/editableelement.js +1 -1
- package/src/view/element.js +5 -5
- package/src/view/elementdefinition.js +1 -1
- package/src/view/emptyelement.js +1 -1
- package/src/view/filler.js +1 -1
- package/src/view/item.js +1 -1
- package/src/view/matcher.js +1 -1
- package/src/view/node.js +1 -1
- package/src/view/observer/arrowkeysobserver.js +1 -1
- package/src/view/observer/bubblingemittermixin.js +1 -1
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.js +1 -1
- package/src/view/observer/compositionobserver.js +1 -1
- package/src/view/observer/domeventdata.js +1 -1
- package/src/view/observer/domeventobserver.js +1 -1
- package/src/view/observer/fakeselectionobserver.js +1 -1
- package/src/view/observer/focusobserver.js +22 -4
- package/src/view/observer/inputobserver.js +1 -1
- package/src/view/observer/keyobserver.js +1 -1
- package/src/view/observer/mouseobserver.js +1 -1
- package/src/view/observer/mutationobserver.js +1 -1
- package/src/view/observer/observer.js +1 -1
- package/src/view/observer/selectionobserver.js +13 -2
- package/src/view/observer/tabobserver.js +1 -1
- package/src/view/placeholder.js +1 -1
- package/src/view/position.js +1 -1
- package/src/view/range.js +1 -1
- package/src/view/rawelement.js +1 -1
- package/src/view/renderer.js +1 -14
- package/src/view/rooteditableelement.js +1 -1
- package/src/view/selection.js +1 -1
- package/src/view/styles/background.js +1 -1
- package/src/view/styles/border.js +1 -1
- package/src/view/styles/margin.js +1 -1
- package/src/view/styles/padding.js +1 -1
- package/src/view/styles/utils.js +1 -1
- package/src/view/stylesmap.js +1 -1
- package/src/view/text.js +1 -1
- package/src/view/textproxy.js +1 -1
- package/src/view/treewalker.js +1 -1
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.js +1 -1
- package/src/view/upcastwriter.js +1 -1
- package/src/view/view.js +5 -5
- package/theme/placeholder.css +1 -1
- package/theme/renderer.css +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
/**
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
import DocumentSelection from '../documentselection';
|
|
9
9
|
import Element from '../element';
|
|
10
10
|
import LivePosition from '../liveposition';
|
|
11
|
+
import LiveRange from '../liverange';
|
|
11
12
|
import Position from '../position';
|
|
12
13
|
import Range from '../range';
|
|
13
14
|
import Selection from '../selection';
|
|
14
15
|
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
15
|
-
import { LiveRange } from '../../index';
|
|
16
16
|
/**
|
|
17
17
|
* Inserts content into the editor (specified selection) as one would expect the paste functionality to work.
|
|
18
18
|
*
|
|
@@ -20,11 +20,13 @@ import { LiveRange } from '../../index';
|
|
|
20
20
|
*
|
|
21
21
|
* Some examples:
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
23
|
+
* ```html
|
|
24
|
+
* <p>x^</p> + <p>y</p> => <p>x</p><p>y</p> => <p>xy[]</p>
|
|
25
|
+
* <p>x^y</p> + <p>z</p> => <p>x</p>^<p>y</p> + <p>z</p> => <p>x</p><p>z</p><p>y</p> => <p>xz[]y</p>
|
|
26
|
+
* <p>x^y</p> + <img /> => <p>x</p>^<p>y</p> + <img /> => <p>x</p><img /><p>y</p>
|
|
27
|
+
* <p>x</p><p>^</p><p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p> (no merging)
|
|
28
|
+
* <p>x</p>[<img />]<p>z</p> + <p>y</p> => <p>x</p>^<p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p>
|
|
29
|
+
* ```
|
|
28
30
|
*
|
|
29
31
|
* If an instance of {@link module:engine/model/selection~Selection} is passed as `selectable` it will be modified
|
|
30
32
|
* to the insertion selection (equal to a range to be selected after insertion).
|
|
@@ -35,13 +37,11 @@ import { LiveRange } from '../../index';
|
|
|
35
37
|
* This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertContent}
|
|
36
38
|
* method's behavior.
|
|
37
39
|
*
|
|
38
|
-
* @param
|
|
39
|
-
*
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
*
|
|
43
|
-
* @param {Number|'before'|'end'|'after'|'on'|'in'} [placeOrOffset] Sets place or offset of the selection.
|
|
44
|
-
* @returns {module:engine/model/range~Range} Range which contains all the performed changes. This is a range that, if removed,
|
|
40
|
+
* @param model The model in context of which the insertion should be performed.
|
|
41
|
+
* @param content The content to insert.
|
|
42
|
+
* @param selectable Selection into which the content should be inserted.
|
|
43
|
+
* @param placeOrOffset Sets place or offset of the selection.
|
|
44
|
+
* @returns Range which contains all the performed changes. This is a range that, if removed,
|
|
45
45
|
* would return the model to the state before the insertion. If no changes were preformed by `insertContent`, returns a range collapsed
|
|
46
46
|
* at the insertion position.
|
|
47
47
|
*/
|
|
@@ -194,108 +194,46 @@ export default function insertContent(model, content, selectable, placeOrOffset)
|
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
196
|
* Utility class for performing content insertion.
|
|
197
|
-
*
|
|
198
|
-
* @private
|
|
199
197
|
*/
|
|
200
198
|
class Insertion {
|
|
201
199
|
constructor(model, writer, position) {
|
|
202
|
-
/**
|
|
203
|
-
* The model in context of which the insertion should be performed.
|
|
204
|
-
*
|
|
205
|
-
* @member {module:engine/model~Model} #model
|
|
206
|
-
*/
|
|
207
|
-
this.model = model;
|
|
208
|
-
/**
|
|
209
|
-
* Batch to which operations will be added.
|
|
210
|
-
*
|
|
211
|
-
* @member {module:engine/controller/writer~Batch} #writer
|
|
212
|
-
*/
|
|
213
|
-
this.writer = writer;
|
|
214
|
-
/**
|
|
215
|
-
* The position at which (or near which) the next node will be inserted.
|
|
216
|
-
*
|
|
217
|
-
* @member {module:engine/model/position~Position} #position
|
|
218
|
-
*/
|
|
219
|
-
this.position = position;
|
|
220
|
-
/**
|
|
221
|
-
* Elements with which the inserted elements can be merged.
|
|
222
|
-
*
|
|
223
|
-
* <p>x^</p><p>y</p> + <p>z</p> (can merge to <p>x</p>)
|
|
224
|
-
* <p>x</p><p>^y</p> + <p>z</p> (can merge to <p>y</p>)
|
|
225
|
-
* <p>x^y</p> + <p>z</p> (can merge to <p>xy</p> which will be split during the action,
|
|
226
|
-
* so both its pieces will be added to this set)
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* @member {Set} #canMergeWith
|
|
230
|
-
*/
|
|
231
|
-
this.canMergeWith = new Set([this.position.parent]);
|
|
232
|
-
/**
|
|
233
|
-
* Schema of the model.
|
|
234
|
-
*
|
|
235
|
-
* @member {module:engine/model/schema~Schema} #schema
|
|
236
|
-
*/
|
|
237
|
-
this.schema = model.schema;
|
|
238
|
-
/**
|
|
239
|
-
* The temporary DocumentFragment used for grouping multiple nodes for single insert operation.
|
|
240
|
-
*
|
|
241
|
-
* @private
|
|
242
|
-
* @type {module:engine/model/documentfragment~DocumentFragment}
|
|
243
|
-
*/
|
|
244
|
-
this._documentFragment = writer.createDocumentFragment();
|
|
245
|
-
/**
|
|
246
|
-
* The current position in the temporary DocumentFragment.
|
|
247
|
-
*
|
|
248
|
-
* @private
|
|
249
|
-
* @type {module:engine/model/position~Position}
|
|
250
|
-
*/
|
|
251
|
-
this._documentFragmentPosition = writer.createPositionAt(this._documentFragment, 0);
|
|
252
200
|
/**
|
|
253
201
|
* The reference to the first inserted node.
|
|
254
|
-
*
|
|
255
|
-
* @private
|
|
256
|
-
* @type {module:engine/model/node~Node}
|
|
257
202
|
*/
|
|
258
203
|
this._firstNode = null;
|
|
259
204
|
/**
|
|
260
205
|
* The reference to the last inserted node.
|
|
261
|
-
*
|
|
262
|
-
* @private
|
|
263
|
-
* @type {module:engine/model/node~Node}
|
|
264
206
|
*/
|
|
265
207
|
this._lastNode = null;
|
|
266
208
|
/**
|
|
267
209
|
* The reference to the last auto paragraph node.
|
|
268
|
-
*
|
|
269
|
-
* @private
|
|
270
|
-
* @type {module:engine/model/node~Node}
|
|
271
210
|
*/
|
|
272
211
|
this._lastAutoParagraph = null;
|
|
273
212
|
/**
|
|
274
213
|
* The array of nodes that should be cleaned of not allowed attributes.
|
|
275
|
-
*
|
|
276
|
-
* @private
|
|
277
|
-
* @type {Array.<module:engine/model/node~Node>}
|
|
278
214
|
*/
|
|
279
215
|
this._filterAttributesOf = [];
|
|
280
216
|
/**
|
|
281
217
|
* Beginning of the affected range. See {@link module:engine/model/utils/insertcontent~Insertion#getAffectedRange}.
|
|
282
|
-
*
|
|
283
|
-
* @private
|
|
284
|
-
* @member {module:engine/model/liveposition~LivePosition|null} #_affectedStart
|
|
285
218
|
*/
|
|
286
219
|
this._affectedStart = null;
|
|
287
220
|
/**
|
|
288
221
|
* End of the affected range. See {@link module:engine/model/utils/insertcontent~Insertion#getAffectedRange}.
|
|
289
|
-
*
|
|
290
|
-
* @private
|
|
291
|
-
* @member {module:engine/model/liveposition~LivePosition|null} #_affectedEnd
|
|
292
222
|
*/
|
|
293
223
|
this._affectedEnd = null;
|
|
224
|
+
this._nodeToSelect = null;
|
|
225
|
+
this.model = model;
|
|
226
|
+
this.writer = writer;
|
|
227
|
+
this.position = position;
|
|
228
|
+
this.canMergeWith = new Set([this.position.parent]);
|
|
229
|
+
this.schema = model.schema;
|
|
230
|
+
this._documentFragment = writer.createDocumentFragment();
|
|
231
|
+
this._documentFragmentPosition = writer.createPositionAt(this._documentFragment, 0);
|
|
294
232
|
}
|
|
295
233
|
/**
|
|
296
234
|
* Handles insertion of a set of nodes.
|
|
297
235
|
*
|
|
298
|
-
* @param
|
|
236
|
+
* @param nodes Nodes to insert.
|
|
299
237
|
*/
|
|
300
238
|
handleNodes(nodes) {
|
|
301
239
|
for (const node of Array.from(nodes)) {
|
|
@@ -317,8 +255,7 @@ class Insertion {
|
|
|
317
255
|
/**
|
|
318
256
|
* Updates the last node after the auto paragraphing.
|
|
319
257
|
*
|
|
320
|
-
* @
|
|
321
|
-
* @param {module:engine/model/node~Node} node The last auto paragraphing node.
|
|
258
|
+
* @param node The last auto paragraphing node.
|
|
322
259
|
*/
|
|
323
260
|
_updateLastNodeFromAutoParagraph(node) {
|
|
324
261
|
const positionAfterLastNode = this.writer.createPositionAfter(this._lastNode);
|
|
@@ -340,8 +277,6 @@ class Insertion {
|
|
|
340
277
|
/**
|
|
341
278
|
* Returns range to be selected after insertion.
|
|
342
279
|
* Returns `null` if there is no valid range to select after insertion.
|
|
343
|
-
*
|
|
344
|
-
* @returns {module:engine/model/range~Range|null}
|
|
345
280
|
*/
|
|
346
281
|
getSelectionRange() {
|
|
347
282
|
if (this._nodeToSelect) {
|
|
@@ -352,8 +287,6 @@ class Insertion {
|
|
|
352
287
|
/**
|
|
353
288
|
* Returns a range which contains all the performed changes. This is a range that, if removed, would return the model to the state
|
|
354
289
|
* before the insertion. Returns `null` if no changes were done.
|
|
355
|
-
*
|
|
356
|
-
* @returns {module:engine/model/range~Range|null}
|
|
357
290
|
*/
|
|
358
291
|
getAffectedRange() {
|
|
359
292
|
if (!this._affectedStart) {
|
|
@@ -374,9 +307,6 @@ class Insertion {
|
|
|
374
307
|
}
|
|
375
308
|
/**
|
|
376
309
|
* Handles insertion of a single node.
|
|
377
|
-
*
|
|
378
|
-
* @private
|
|
379
|
-
* @param {module:engine/model/node~Node} node
|
|
380
310
|
*/
|
|
381
311
|
_handleNode(node) {
|
|
382
312
|
// Let's handle object in a special way.
|
|
@@ -409,8 +339,6 @@ class Insertion {
|
|
|
409
339
|
}
|
|
410
340
|
/**
|
|
411
341
|
* Inserts the temporary DocumentFragment into the model.
|
|
412
|
-
*
|
|
413
|
-
* @private
|
|
414
342
|
*/
|
|
415
343
|
_insertPartialFragment() {
|
|
416
344
|
if (this._documentFragment.isEmpty) {
|
|
@@ -437,8 +365,7 @@ class Insertion {
|
|
|
437
365
|
livePosition.detach();
|
|
438
366
|
}
|
|
439
367
|
/**
|
|
440
|
-
* @
|
|
441
|
-
* @param {module:engine/model/element~Element} node The object element.
|
|
368
|
+
* @param node The object element.
|
|
442
369
|
*/
|
|
443
370
|
_handleObject(node) {
|
|
444
371
|
// Try finding it a place in the tree.
|
|
@@ -451,8 +378,7 @@ class Insertion {
|
|
|
451
378
|
}
|
|
452
379
|
}
|
|
453
380
|
/**
|
|
454
|
-
* @
|
|
455
|
-
* @param {module:engine/model/node~Node} node The disallowed node which needs to be handled.
|
|
381
|
+
* @param node The disallowed node which needs to be handled.
|
|
456
382
|
*/
|
|
457
383
|
_handleDisallowedNode(node) {
|
|
458
384
|
// If the node is an element, try inserting its children (strip the parent).
|
|
@@ -467,8 +393,7 @@ class Insertion {
|
|
|
467
393
|
/**
|
|
468
394
|
* Append a node to the temporary DocumentFragment.
|
|
469
395
|
*
|
|
470
|
-
* @
|
|
471
|
-
* @param {module:engine/model/node~Node} node The node to insert.
|
|
396
|
+
* @param node The node to insert.
|
|
472
397
|
*/
|
|
473
398
|
_appendToFragment(node) {
|
|
474
399
|
/* istanbul ignore if */
|
|
@@ -479,8 +404,8 @@ class Insertion {
|
|
|
479
404
|
* Given node cannot be inserted on the given position.
|
|
480
405
|
*
|
|
481
406
|
* @error insertcontent-wrong-position
|
|
482
|
-
* @param
|
|
483
|
-
* @param
|
|
407
|
+
* @param node Node to insert.
|
|
408
|
+
* @param position Position to insert the node at.
|
|
484
409
|
*/
|
|
485
410
|
throw new CKEditorError('insertcontent-wrong-position', this, { node, position: this.position });
|
|
486
411
|
}
|
|
@@ -501,9 +426,6 @@ class Insertion {
|
|
|
501
426
|
*
|
|
502
427
|
* This method is used before inserting a node or splitting a parent node. `_affectedStart` and `_affectedEnd` are also changed
|
|
503
428
|
* during merging, but the logic there is more complicated so it is left out of this function.
|
|
504
|
-
*
|
|
505
|
-
* @private
|
|
506
|
-
* @param {module:engine/model/position~Position} position
|
|
507
429
|
*/
|
|
508
430
|
_setAffectedBoundaries(position) {
|
|
509
431
|
// Set affected boundaries stickiness so that those position will "expand" when something is inserted in between them:
|
|
@@ -528,8 +450,6 @@ class Insertion {
|
|
|
528
450
|
*
|
|
529
451
|
* After the content was inserted we may try to merge it with its siblings.
|
|
530
452
|
* This should happen only if the selection was in those elements initially.
|
|
531
|
-
*
|
|
532
|
-
* @private
|
|
533
453
|
*/
|
|
534
454
|
_mergeOnLeft() {
|
|
535
455
|
const node = this._firstNode;
|
|
@@ -596,8 +516,6 @@ class Insertion {
|
|
|
596
516
|
*
|
|
597
517
|
* After the content was inserted we may try to merge it with its siblings.
|
|
598
518
|
* This should happen only if the selection was in those elements initially.
|
|
599
|
-
*
|
|
600
|
-
* @private
|
|
601
519
|
*/
|
|
602
520
|
_mergeOnRight() {
|
|
603
521
|
const node = this._lastNode;
|
|
@@ -666,9 +584,7 @@ class Insertion {
|
|
|
666
584
|
/**
|
|
667
585
|
* Checks whether specified node can be merged with previous sibling element.
|
|
668
586
|
*
|
|
669
|
-
* @
|
|
670
|
-
* @param {module:engine/model/node~Node} node The node which could potentially be merged.
|
|
671
|
-
* @returns {Boolean}
|
|
587
|
+
* @param node The node which could potentially be merged.
|
|
672
588
|
*/
|
|
673
589
|
_canMergeLeft(node) {
|
|
674
590
|
const previousSibling = node.previousSibling;
|
|
@@ -679,9 +595,7 @@ class Insertion {
|
|
|
679
595
|
/**
|
|
680
596
|
* Checks whether specified node can be merged with next sibling element.
|
|
681
597
|
*
|
|
682
|
-
* @
|
|
683
|
-
* @param {module:engine/model/node~Node} node The node which could potentially be merged.
|
|
684
|
-
* @returns {Boolean}
|
|
598
|
+
* @param node The node which could potentially be merged.
|
|
685
599
|
*/
|
|
686
600
|
_canMergeRight(node) {
|
|
687
601
|
const nextSibling = node.nextSibling;
|
|
@@ -692,8 +606,7 @@ class Insertion {
|
|
|
692
606
|
/**
|
|
693
607
|
* Tries wrapping the node in a new paragraph and inserting it this way.
|
|
694
608
|
*
|
|
695
|
-
* @
|
|
696
|
-
* @param {module:engine/model/node~Node} node The node which needs to be autoparagraphed.
|
|
609
|
+
* @param node The node which needs to be autoparagraphed.
|
|
697
610
|
*/
|
|
698
611
|
_tryAutoparagraphing(node) {
|
|
699
612
|
const paragraph = this.writer.createElement('paragraph');
|
|
@@ -709,9 +622,7 @@ class Insertion {
|
|
|
709
622
|
* Checks if a node can be inserted in the given position or it would be accepted if a paragraph would be inserted.
|
|
710
623
|
* It also handles inserting the paragraph.
|
|
711
624
|
*
|
|
712
|
-
* @
|
|
713
|
-
* @param {module:engine/model/node~Node} node The node.
|
|
714
|
-
* @returns {Boolean} Whether an allowed position was found.
|
|
625
|
+
* @returns Whether an allowed position was found.
|
|
715
626
|
* `false` is returned if the node isn't allowed at the current position or in auto paragraph, `true` if was.
|
|
716
627
|
*/
|
|
717
628
|
_checkAndAutoParagraphToAllowedPosition(node) {
|
|
@@ -735,9 +646,7 @@ class Insertion {
|
|
|
735
646
|
return true;
|
|
736
647
|
}
|
|
737
648
|
/**
|
|
738
|
-
* @
|
|
739
|
-
* @param {module:engine/model/node~Node} node
|
|
740
|
-
* @returns {Boolean} Whether an allowed position was found.
|
|
649
|
+
* @returns Whether an allowed position was found.
|
|
741
650
|
* `false` is returned if the node isn't allowed at any position up in the tree, `true` if was.
|
|
742
651
|
*/
|
|
743
652
|
_checkAndSplitToAllowedPosition(node) {
|
|
@@ -786,10 +695,8 @@ class Insertion {
|
|
|
786
695
|
/**
|
|
787
696
|
* Gets the element in which the given node is allowed. It checks the passed element and all its ancestors.
|
|
788
697
|
*
|
|
789
|
-
* @
|
|
790
|
-
* @param
|
|
791
|
-
* @param {module:engine/model/node~Node} childNode The node to check.
|
|
792
|
-
* @returns {module:engine/model/element~Element|null}
|
|
698
|
+
* @param contextElement The element in which context the node should be checked.
|
|
699
|
+
* @param childNode The node to check.
|
|
793
700
|
*/
|
|
794
701
|
_getAllowedIn(contextElement, childNode) {
|
|
795
702
|
if (this.schema.checkChild(contextElement, childNode)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
/**
|
|
@@ -18,28 +18,25 @@ import { CKEditorError, first } from '@ckeditor/ckeditor5-utils';
|
|
|
18
18
|
*
|
|
19
19
|
* **Note**: For more documentation and examples, see {@link module:engine/model/model~Model#insertObject}.
|
|
20
20
|
*
|
|
21
|
-
* @param
|
|
22
|
-
*
|
|
23
|
-
* @param
|
|
24
|
-
* @param {module:engine/model/selection~Selectable} [selectable=model.document.selection]
|
|
25
|
-
* A selectable where the content should be inserted. If not specified, the current
|
|
21
|
+
* @param model The model in context of which the insertion should be performed.
|
|
22
|
+
* @param object An object to be inserted into the model document.
|
|
23
|
+
* @param selectable A selectable where the content should be inserted. If not specified, the current
|
|
26
24
|
* {@link module:engine/model/document~Document#selection document selection} will be used instead.
|
|
27
|
-
* @param
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param {'auto'|'before'|'after'} [options.findOptimalPosition] An option that, when set, adjusts the insertion position (relative to
|
|
25
|
+
* @param placeOrOffset Specifies the exact place or offset for the insertion to take place, relative to `selectable`.
|
|
26
|
+
* @param options Additional options.
|
|
27
|
+
* @param options.findOptimalPosition An option that, when set, adjusts the insertion position (relative to
|
|
31
28
|
* `selectable` and `placeOrOffset`) so that the content of `selectable` is not split upon insertion (a.k.a. non-destructive insertion).
|
|
32
29
|
* * When `'auto'`, the algorithm will decide whether to insert the object before or after `selectable` to avoid content splitting.
|
|
33
30
|
* * When `'before'`, the closest position before `selectable` will be used that will not result in content splitting.
|
|
34
31
|
* * When `'after'`, the closest position after `selectable` will be used that will not result in content splitting.
|
|
35
32
|
*
|
|
36
33
|
* Note that this option works only for block objects. Inline objects are inserted into text and do not split blocks.
|
|
37
|
-
* @param
|
|
34
|
+
* @param options.setSelection An option that, when set, moves the
|
|
38
35
|
* {@link module:engine/model/document~Document#selection document selection} after inserting the object.
|
|
39
36
|
* * When `'on'`, the document selection will be set on the inserted object.
|
|
40
37
|
* * When `'after'`, the document selection will move to the closest text node after the inserted object. If there is no
|
|
41
38
|
* such text node, a paragraph will be created and the document selection will be moved inside it.
|
|
42
|
-
* @returns
|
|
39
|
+
* @returns A range which contains all the performed changes. This is a range that, if removed,
|
|
43
40
|
* would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
|
|
44
41
|
* at the insertion position.
|
|
45
42
|
*/
|
|
@@ -106,15 +103,16 @@ export default function insertObject(model, object, selectable, placeOrOffset, o
|
|
|
106
103
|
return affectedRange;
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Updates document selection based on given `place` parameter in relation to `contextElement` element.
|
|
108
|
+
*
|
|
109
|
+
* @param writer An instance of the model writer.
|
|
110
|
+
* @param contextElement An element to set the attributes on.
|
|
111
|
+
* @param place The place where selection should be set in relation to the `contextElement` element.
|
|
112
|
+
* Value `on` will set selection on the passed `contextElement`. Value `after` will set selection after `contextElement`.
|
|
113
|
+
* @param attributes Attributes keys and values to set on a paragraph that this function can create when
|
|
114
|
+
* `place` parameter is equal to `after` but there is no element with `$text` node to set selection in.
|
|
115
|
+
*/
|
|
118
116
|
function updateSelection(writer, contextElement, place, paragraphAttributes) {
|
|
119
117
|
const model = writer.model;
|
|
120
118
|
if (place == 'on') {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
/**
|
|
@@ -38,14 +38,11 @@ const wordBoundaryCharacters = ' ,.?!:;"-()';
|
|
|
38
38
|
* which change the {@link module:engine/model/model~Model#modifySelection}
|
|
39
39
|
* method's behavior.
|
|
40
40
|
*
|
|
41
|
-
* @param
|
|
42
|
-
*
|
|
43
|
-
* @param
|
|
44
|
-
* The selection
|
|
45
|
-
* @param
|
|
46
|
-
* @param {'forward'|'backward'} [options.direction='forward'] The direction in which the selection should be modified.
|
|
47
|
-
* @param {'character'|'codePoint'|'word'} [options.unit='character'] The unit by which selection should be modified.
|
|
48
|
-
* @param {Boolean} [options.treatEmojiAsSingleUnit=false] Whether multi-characer emoji sequences should be handled as single unit.
|
|
41
|
+
* @param model The model in context of which the selection modification should be performed.
|
|
42
|
+
* @param selection The selection to modify.
|
|
43
|
+
* @param options.direction The direction in which the selection should be modified. Default 'forward'.
|
|
44
|
+
* @param options.unit The unit by which selection should be modified. Default 'character'.
|
|
45
|
+
* @param options.treatEmojiAsSingleUnit Whether multi-characer emoji sequences should be handled as single unit.
|
|
49
46
|
*/
|
|
50
47
|
export default function modifySelection(model, selection, options = {}) {
|
|
51
48
|
const schema = model.schema;
|
|
@@ -78,9 +75,9 @@ export default function modifySelection(model, selection, options = {}) {
|
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Checks whether the selection can be extended to the the walker's next value (next position).
|
|
80
|
+
*/
|
|
84
81
|
function tryExtendingTo(data, value) {
|
|
85
82
|
const { isForward, walker, unit, schema, treatEmojiAsSingleUnit } = data;
|
|
86
83
|
const { type, item, nextPosition } = value;
|
|
@@ -117,12 +114,10 @@ function tryExtendingTo(data, value) {
|
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// @param {String} unit The unit by which selection should be modified.
|
|
125
|
-
// @param {Boolean} treatEmojiAsSingleUnit
|
|
117
|
+
/**
|
|
118
|
+
* Finds a correct position by walking in a text node and checking whether selection can be extended to given position
|
|
119
|
+
* or should be extended further.
|
|
120
|
+
*/
|
|
126
121
|
function getCorrectPosition(walker, unit, treatEmojiAsSingleUnit) {
|
|
127
122
|
const textNode = walker.position.textNode;
|
|
128
123
|
if (textNode) {
|
|
@@ -137,11 +132,10 @@ function getCorrectPosition(walker, unit, treatEmojiAsSingleUnit) {
|
|
|
137
132
|
}
|
|
138
133
|
return walker.position;
|
|
139
134
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// @param {Boolean} isForward Is the direction in which the selection should be modified is forward.
|
|
135
|
+
/**
|
|
136
|
+
* Finds a correct position of a word break by walking in a text node and checking whether selection can be extended to given position
|
|
137
|
+
* or should be extended further.
|
|
138
|
+
*/
|
|
145
139
|
function getCorrectWordBreakPosition(walker, isForward) {
|
|
146
140
|
let textNode = walker.position.textNode;
|
|
147
141
|
if (!textNode) {
|
|
@@ -176,21 +170,17 @@ function getSearchRange(start, isForward) {
|
|
|
176
170
|
return new Range(searchEnd, start);
|
|
177
171
|
}
|
|
178
172
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// @param {Number} offset Position offset.
|
|
183
|
-
// @param {Boolean} isForward Is the direction in which the selection should be modified is forward.
|
|
173
|
+
/**
|
|
174
|
+
* Checks if selection is on word boundary.
|
|
175
|
+
*/
|
|
184
176
|
function isAtWordBoundary(data, offset, isForward) {
|
|
185
177
|
// The offset to check depends on direction.
|
|
186
178
|
const offsetToCheck = offset + (isForward ? 0 : -1);
|
|
187
179
|
return wordBoundaryCharacters.includes(data.charAt(offsetToCheck));
|
|
188
180
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
// @param {Number} offset Position offset.
|
|
193
|
-
// @param {Boolean} isForward Is the direction in which the selection should be modified is forward.
|
|
181
|
+
/**
|
|
182
|
+
* Checks if selection is on node boundary.
|
|
183
|
+
*/
|
|
194
184
|
function isAtNodeBoundary(textNode, offset, isForward) {
|
|
195
185
|
return offset === (isForward ? textNode.offsetSize : 0);
|
|
196
186
|
}
|