@ckeditor/ckeditor5-engine 46.0.2 → 46.1.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.
- package/dist/index.js +250 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.d.ts +4 -2
- package/src/index.js +3 -1
- package/src/model/documentselection.d.ts +6 -0
- package/src/model/documentselection.js +20 -0
- package/src/model/markercollection.d.ts +6 -0
- package/src/model/markercollection.js +13 -0
- package/src/model/range.d.ts +1 -1
- package/src/model/range.js +1 -1
- package/src/model/selection.d.ts +6 -0
- package/src/model/selection.js +18 -0
- package/src/view/attributeelement.d.ts +6 -0
- package/src/view/attributeelement.js +10 -0
- package/src/view/containerelement.d.ts +6 -0
- package/src/view/containerelement.js +10 -0
- package/src/view/documentfragment.d.ts +7 -0
- package/src/view/documentfragment.js +13 -0
- package/src/view/documentselection.d.ts +6 -0
- package/src/view/documentselection.js +8 -0
- package/src/view/domconverter.js +4 -2
- package/src/view/editableelement.d.ts +6 -0
- package/src/view/editableelement.js +12 -0
- package/src/view/element.d.ts +6 -0
- package/src/view/element.js +20 -0
- package/src/view/emptyelement.d.ts +6 -0
- package/src/view/emptyelement.js +10 -0
- package/src/view/node.d.ts +2 -2
- package/src/view/node.js +9 -6
- package/src/view/observer/pointerobserver.d.ts +76 -0
- package/src/view/observer/pointerobserver.js +26 -0
- package/src/view/observer/selectionobserver.d.ts +4 -4
- package/src/view/observer/selectionobserver.js +22 -1
- package/src/view/position.d.ts +6 -0
- package/src/view/position.js +11 -0
- package/src/view/range.d.ts +6 -0
- package/src/view/range.js +11 -0
- package/src/view/rawelement.d.ts +6 -0
- package/src/view/rawelement.js +10 -0
- package/src/view/rooteditableelement.d.ts +6 -0
- package/src/view/rooteditableelement.js +8 -0
- package/src/view/selection.d.ts +6 -0
- package/src/view/selection.js +17 -0
- package/src/view/text.d.ts +6 -0
- package/src/view/text.js +11 -0
- package/src/view/uielement.d.ts +6 -0
- package/src/view/uielement.js +10 -0
|
@@ -262,7 +262,15 @@ export class SelectionObserver extends Observer {
|
|
|
262
262
|
this._reportInfiniteLoop();
|
|
263
263
|
return;
|
|
264
264
|
}
|
|
265
|
-
if (
|
|
265
|
+
if (!isSelectionWithinRootElements(newViewSelection)) {
|
|
266
|
+
// Occasionally, such as when removing markers during a focus change, the selection may end up inside a view element
|
|
267
|
+
// whose parent has already been detached from the DOM. In most cases this is harmless, but if the selectionchange
|
|
268
|
+
// event fires before the view is fully synchronized with the DOM converter, some elements in the selection may become orphans.
|
|
269
|
+
// This can result in the view being out of sync with the actual DOM structure.
|
|
270
|
+
// See: https://github.com/ckeditor/ckeditor5/issues/18744
|
|
271
|
+
this.view.forceRender();
|
|
272
|
+
}
|
|
273
|
+
else if (this.selection.isSimilar(newViewSelection)) {
|
|
266
274
|
// If selection was equal and we are at this point of algorithm, it means that it was incorrect.
|
|
267
275
|
// Just re-render it, no need to fire any events, etc.
|
|
268
276
|
this.view.forceRender();
|
|
@@ -295,3 +303,16 @@ export class SelectionObserver extends Observer {
|
|
|
295
303
|
this._loopbackCounter = 0;
|
|
296
304
|
}
|
|
297
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Checks if all roots of the selection's range boundaries are root elements.
|
|
308
|
+
* Returns true if the selection is fully contained within root elements (not orphaned).
|
|
309
|
+
*
|
|
310
|
+
* @param selection The view selection to check.
|
|
311
|
+
* @returns True if all range boundaries are within root elements, false otherwise.
|
|
312
|
+
*/
|
|
313
|
+
function isSelectionWithinRootElements(selection) {
|
|
314
|
+
return Array
|
|
315
|
+
.from(selection.getRanges())
|
|
316
|
+
.flatMap(range => [range.start.root, range.end.root])
|
|
317
|
+
.every(root => root && root.is('rootElement'));
|
|
318
|
+
}
|
package/src/view/position.d.ts
CHANGED
|
@@ -145,6 +145,12 @@ export declare class ViewPosition extends ViewTypeCheckable {
|
|
|
145
145
|
* Clones this position.
|
|
146
146
|
*/
|
|
147
147
|
clone(): ViewPosition;
|
|
148
|
+
/**
|
|
149
|
+
* Converts `ViewPosition` instance to plain object and returns it.
|
|
150
|
+
*
|
|
151
|
+
* @returns `ViewPosition` instance converted to plain object.
|
|
152
|
+
*/
|
|
153
|
+
toJSON(): unknown;
|
|
148
154
|
/**
|
|
149
155
|
* Creates position at the given location. The location can be specified as:
|
|
150
156
|
*
|
package/src/view/position.js
CHANGED
|
@@ -235,6 +235,17 @@ export class ViewPosition extends ViewTypeCheckable {
|
|
|
235
235
|
clone() {
|
|
236
236
|
return new ViewPosition(this.parent, this.offset);
|
|
237
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Converts `ViewPosition` instance to plain object and returns it.
|
|
240
|
+
*
|
|
241
|
+
* @returns `ViewPosition` instance converted to plain object.
|
|
242
|
+
*/
|
|
243
|
+
toJSON() {
|
|
244
|
+
return {
|
|
245
|
+
parent: this.parent.toJSON(),
|
|
246
|
+
offset: this.offset
|
|
247
|
+
};
|
|
248
|
+
}
|
|
238
249
|
/**
|
|
239
250
|
* Creates position at the given location. The location can be specified as:
|
|
240
251
|
*
|
package/src/view/range.d.ts
CHANGED
|
@@ -244,6 +244,12 @@ export declare class ViewRange extends ViewTypeCheckable implements Iterable<Vie
|
|
|
244
244
|
* @returns True if ranges intersect.
|
|
245
245
|
*/
|
|
246
246
|
isIntersecting(otherRange: ViewRange): boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Converts `ViewRange` instance to plain object and returns it.
|
|
249
|
+
*
|
|
250
|
+
* @returns `ViewRange` instance converted to plain object.
|
|
251
|
+
*/
|
|
252
|
+
toJSON(): unknown;
|
|
247
253
|
/**
|
|
248
254
|
* Creates a range from the given parents and offsets.
|
|
249
255
|
*
|
package/src/view/range.js
CHANGED
|
@@ -378,6 +378,17 @@ export class ViewRange extends ViewTypeCheckable {
|
|
|
378
378
|
isIntersecting(otherRange) {
|
|
379
379
|
return this.start.isBefore(otherRange.end) && this.end.isAfter(otherRange.start);
|
|
380
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* Converts `ViewRange` instance to plain object and returns it.
|
|
383
|
+
*
|
|
384
|
+
* @returns `ViewRange` instance converted to plain object.
|
|
385
|
+
*/
|
|
386
|
+
toJSON() {
|
|
387
|
+
return {
|
|
388
|
+
start: this.start.toJSON(),
|
|
389
|
+
end: this.end.toJSON()
|
|
390
|
+
};
|
|
391
|
+
}
|
|
381
392
|
/**
|
|
382
393
|
* Creates a range from the given parents and offsets.
|
|
383
394
|
*
|
package/src/view/rawelement.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ export declare class ViewRawElement extends ViewElement {
|
|
|
42
42
|
* @param children A list of nodes to be inserted into created element.
|
|
43
43
|
*/
|
|
44
44
|
constructor(document: ViewDocument, name: string, attrs?: ViewElementAttributes, children?: ViewNode | Iterable<ViewNode>);
|
|
45
|
+
/**
|
|
46
|
+
* Converts `ViewRawElement` instance to plain object and returns it.
|
|
47
|
+
*
|
|
48
|
+
* @returns `ViewRawElement` instance converted to plain object.
|
|
49
|
+
*/
|
|
50
|
+
toJSON(): unknown;
|
|
45
51
|
/**
|
|
46
52
|
* Overrides the {@link module:engine/view/element~ViewElement#_insertChild} method.
|
|
47
53
|
* Throws the `view-rawelement-cannot-add` {@link module:utils/ckeditorerror~CKEditorError CKEditorError} to prevent
|
package/src/view/rawelement.js
CHANGED
|
@@ -44,6 +44,16 @@ export class ViewRawElement extends ViewElement {
|
|
|
44
44
|
// Returns `null` because filler is not needed for raw elements.
|
|
45
45
|
this.getFillerOffset = getFillerOffset;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts `ViewRawElement` instance to plain object and returns it.
|
|
49
|
+
*
|
|
50
|
+
* @returns `ViewRawElement` instance converted to plain object.
|
|
51
|
+
*/
|
|
52
|
+
toJSON() {
|
|
53
|
+
const json = super.toJSON();
|
|
54
|
+
json.type = 'RawElement';
|
|
55
|
+
return json;
|
|
56
|
+
}
|
|
47
57
|
/**
|
|
48
58
|
* Overrides the {@link module:engine/view/element~ViewElement#_insertChild} method.
|
|
49
59
|
* Throws the `view-rawelement-cannot-add` {@link module:utils/ckeditorerror~CKEditorError CKEditorError} to prevent
|
|
@@ -29,6 +29,12 @@ export declare class ViewRootEditableElement extends ViewEditableElement {
|
|
|
29
29
|
*/
|
|
30
30
|
get rootName(): string;
|
|
31
31
|
set rootName(rootName: string);
|
|
32
|
+
/**
|
|
33
|
+
* Converts `ViewRootEditableElement` instance to string and returns it.
|
|
34
|
+
*
|
|
35
|
+
* @returns `ViewRootEditableElement` instance converted to string.
|
|
36
|
+
*/
|
|
37
|
+
toJSON(): unknown;
|
|
32
38
|
/**
|
|
33
39
|
* Overrides old element name and sets new one.
|
|
34
40
|
* This is needed because view roots are created before they are attached to the DOM.
|
|
@@ -36,6 +36,14 @@ export class ViewRootEditableElement extends ViewEditableElement {
|
|
|
36
36
|
set rootName(rootName) {
|
|
37
37
|
this._setCustomProperty(rootNameSymbol, rootName);
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Converts `ViewRootEditableElement` instance to string and returns it.
|
|
41
|
+
*
|
|
42
|
+
* @returns `ViewRootEditableElement` instance converted to string.
|
|
43
|
+
*/
|
|
44
|
+
toJSON() {
|
|
45
|
+
return this.rootName;
|
|
46
|
+
}
|
|
39
47
|
/**
|
|
40
48
|
* Overrides old element name and sets new one.
|
|
41
49
|
* This is needed because view roots are created before they are attached to the DOM.
|
package/src/view/selection.d.ts
CHANGED
|
@@ -298,6 +298,12 @@ export declare class ViewSelection extends /* #__PURE__ */ ViewSelection_base {
|
|
|
298
298
|
* @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~ViewItem view item}.
|
|
299
299
|
*/
|
|
300
300
|
setFocus(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): void;
|
|
301
|
+
/**
|
|
302
|
+
* Converts `ViewSelection` instance to plain object and returns it.
|
|
303
|
+
*
|
|
304
|
+
* @returns `ViewSelection` instance converted to plain object.
|
|
305
|
+
*/
|
|
306
|
+
toJSON(): unknown;
|
|
301
307
|
/**
|
|
302
308
|
* Replaces all ranges that were added to the selection with given array of ranges. Last range of the array
|
|
303
309
|
* is treated like the last added range and is used to set {@link #anchor anchor} and {@link #focus focus}.
|
package/src/view/selection.js
CHANGED
|
@@ -493,6 +493,23 @@ export class ViewSelection extends /* #__PURE__ */ EmitterMixin(ViewTypeCheckabl
|
|
|
493
493
|
}
|
|
494
494
|
this.fire('change');
|
|
495
495
|
}
|
|
496
|
+
/**
|
|
497
|
+
* Converts `ViewSelection` instance to plain object and returns it.
|
|
498
|
+
*
|
|
499
|
+
* @returns `ViewSelection` instance converted to plain object.
|
|
500
|
+
*/
|
|
501
|
+
toJSON() {
|
|
502
|
+
const json = {
|
|
503
|
+
ranges: Array.from(this.getRanges()).map(range => range.toJSON())
|
|
504
|
+
};
|
|
505
|
+
if (this.isBackward) {
|
|
506
|
+
json.isBackward = true;
|
|
507
|
+
}
|
|
508
|
+
if (this.isFake) {
|
|
509
|
+
json.isFake = true;
|
|
510
|
+
}
|
|
511
|
+
return json;
|
|
512
|
+
}
|
|
496
513
|
/**
|
|
497
514
|
* Replaces all ranges that were added to the selection with given array of ranges. Last range of the array
|
|
498
515
|
* is treated like the last added range and is used to set {@link #anchor anchor} and {@link #focus focus}.
|
package/src/view/text.d.ts
CHANGED
|
@@ -64,6 +64,12 @@ export declare class ViewText extends ViewNode {
|
|
|
64
64
|
* @param otherNode Node to check if it is same as this node.
|
|
65
65
|
*/
|
|
66
66
|
isSimilar(otherNode: ViewNode): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Converts `ViewText` instance to plain object and returns it.
|
|
69
|
+
*
|
|
70
|
+
* @returns `ViewText` instance converted to plain object.
|
|
71
|
+
*/
|
|
72
|
+
toJSON(): unknown;
|
|
67
73
|
/**
|
|
68
74
|
* Clones this node.
|
|
69
75
|
*
|
package/src/view/text.js
CHANGED
|
@@ -78,6 +78,17 @@ export class ViewText extends ViewNode {
|
|
|
78
78
|
}
|
|
79
79
|
return this === otherNode || this.data === otherNode.data;
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Converts `ViewText` instance to plain object and returns it.
|
|
83
|
+
*
|
|
84
|
+
* @returns `ViewText` instance converted to plain object.
|
|
85
|
+
*/
|
|
86
|
+
toJSON() {
|
|
87
|
+
const json = super.toJSON();
|
|
88
|
+
json.type = 'Text';
|
|
89
|
+
json.data = this.data;
|
|
90
|
+
return json;
|
|
91
|
+
}
|
|
81
92
|
/**
|
|
82
93
|
* Clones this node.
|
|
83
94
|
*
|
package/src/view/uielement.d.ts
CHANGED
|
@@ -82,6 +82,12 @@ export declare class ViewUIElement extends ViewElement {
|
|
|
82
82
|
* Note that each time this method is called new DOM element is created.
|
|
83
83
|
*/
|
|
84
84
|
toDomElement(domDocument: DomDocument): DomElement;
|
|
85
|
+
/**
|
|
86
|
+
* Converts `ViewUIElement` instance to plain object and returns it.
|
|
87
|
+
*
|
|
88
|
+
* @returns `ViewUIElement` instance converted to plain object.
|
|
89
|
+
*/
|
|
90
|
+
toJSON(): unknown;
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
93
|
* This function injects UI element handling to the given {@link module:engine/view/document~ViewDocument document}.
|
package/src/view/uielement.js
CHANGED
|
@@ -100,6 +100,16 @@ export class ViewUIElement extends ViewElement {
|
|
|
100
100
|
}
|
|
101
101
|
return domElement;
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Converts `ViewUIElement` instance to plain object and returns it.
|
|
105
|
+
*
|
|
106
|
+
* @returns `ViewUIElement` instance converted to plain object.
|
|
107
|
+
*/
|
|
108
|
+
toJSON() {
|
|
109
|
+
const json = super.toJSON();
|
|
110
|
+
json.type = 'UIElement';
|
|
111
|
+
return json;
|
|
112
|
+
}
|
|
103
113
|
}
|
|
104
114
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
105
115
|
// Proper overload would interfere with that.
|