@ckeditor/ckeditor5-engine 45.2.1 → 46.0.0-alpha.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/dist/index.js +2563 -2257
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/controller/datacontroller.d.ts +33 -32
- package/src/controller/datacontroller.js +29 -28
- package/src/controller/editingcontroller.d.ts +8 -8
- package/src/controller/editingcontroller.js +10 -10
- package/src/conversion/conversion.d.ts +18 -19
- package/src/conversion/conversion.js +4 -4
- package/src/conversion/conversionhelpers.d.ts +1 -1
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.d.ts +63 -69
- package/src/conversion/downcastdispatcher.js +16 -16
- package/src/conversion/downcasthelpers.d.ts +94 -83
- package/src/conversion/downcasthelpers.js +63 -53
- package/src/conversion/mapper.d.ts +27 -27
- package/src/conversion/mapper.js +15 -15
- package/src/conversion/modelconsumable.d.ts +26 -26
- package/src/conversion/modelconsumable.js +23 -23
- package/src/conversion/upcastdispatcher.d.ts +33 -32
- package/src/conversion/upcastdispatcher.js +19 -19
- package/src/conversion/upcasthelpers.d.ts +46 -38
- package/src/conversion/upcasthelpers.js +33 -24
- package/src/conversion/viewconsumable.d.ts +50 -45
- package/src/conversion/viewconsumable.js +32 -27
- package/src/dataprocessor/basichtmlwriter.d.ts +4 -2
- package/src/dataprocessor/basichtmlwriter.js +3 -1
- package/src/dataprocessor/dataprocessor.d.ts +7 -6
- package/src/dataprocessor/htmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/htmldataprocessor.js +6 -6
- package/src/dataprocessor/htmlwriter.d.ts +1 -1
- package/src/dataprocessor/xmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/xmldataprocessor.js +6 -6
- package/src/dev-utils/model.d.ts +25 -26
- package/src/dev-utils/model.js +35 -36
- package/src/dev-utils/operationreplayer.d.ts +5 -3
- package/src/dev-utils/operationreplayer.js +4 -2
- package/src/dev-utils/utils.d.ts +8 -0
- package/src/dev-utils/utils.js +8 -0
- package/src/dev-utils/view.d.ts +66 -63
- package/src/dev-utils/view.js +144 -134
- package/src/index.d.ts +135 -106
- package/src/index.js +120 -71
- package/src/legacyerrors.d.ts +5 -0
- package/src/legacyerrors.js +17 -0
- package/src/model/batch.d.ts +2 -15
- package/src/model/batch.js +1 -23
- package/src/model/differ.d.ts +54 -31
- package/src/model/differ.js +15 -15
- package/src/model/document.d.ts +31 -31
- package/src/model/document.js +13 -13
- package/src/model/documentfragment.d.ts +45 -45
- package/src/model/documentfragment.js +40 -40
- package/src/model/documentselection.d.ts +92 -92
- package/src/model/documentselection.js +71 -70
- package/src/model/element.d.ts +31 -31
- package/src/model/element.js +29 -29
- package/src/model/history.d.ts +3 -3
- package/src/model/history.js +2 -2
- package/src/model/item.d.ts +4 -5
- package/src/model/liveposition.d.ts +31 -31
- package/src/model/liveposition.js +18 -18
- package/src/model/liverange.d.ts +42 -38
- package/src/model/liverange.js +17 -16
- package/src/model/markercollection.d.ts +41 -40
- package/src/model/markercollection.js +22 -20
- package/src/model/model.d.ts +82 -81
- package/src/model/model.js +54 -54
- package/src/model/node.d.ts +48 -48
- package/src/model/node.js +31 -31
- package/src/model/nodelist.d.ts +17 -17
- package/src/model/nodelist.js +11 -11
- package/src/model/operation/attributeoperation.d.ts +10 -10
- package/src/model/operation/attributeoperation.js +7 -7
- package/src/model/operation/detachoperation.d.ts +11 -9
- package/src/model/operation/detachoperation.js +8 -6
- package/src/model/operation/insertoperation.d.ts +13 -13
- package/src/model/operation/insertoperation.js +15 -15
- package/src/model/operation/markeroperation.d.ts +12 -12
- package/src/model/operation/markeroperation.js +5 -5
- package/src/model/operation/mergeoperation.d.ts +16 -16
- package/src/model/operation/mergeoperation.js +18 -18
- package/src/model/operation/moveoperation.d.ts +16 -16
- package/src/model/operation/moveoperation.js +18 -15
- package/src/model/operation/nooperation.d.ts +4 -4
- package/src/model/operation/nooperation.js +2 -2
- package/src/model/operation/operation.d.ts +10 -10
- package/src/model/operation/operation.js +5 -5
- package/src/model/operation/operationfactory.d.ts +4 -4
- package/src/model/operation/operationfactory.js +12 -12
- package/src/model/operation/renameoperation.d.ts +10 -10
- package/src/model/operation/renameoperation.js +7 -7
- package/src/model/operation/rootattributeoperation.d.ts +12 -12
- package/src/model/operation/rootattributeoperation.js +8 -8
- package/src/model/operation/rootoperation.d.ts +8 -8
- package/src/model/operation/rootoperation.js +3 -3
- package/src/model/operation/splitoperation.d.ts +17 -17
- package/src/model/operation/splitoperation.js +19 -19
- package/src/model/operation/transform.d.ts +11 -8
- package/src/model/operation/transform.js +66 -49
- package/src/model/operation/utils.d.ts +24 -23
- package/src/model/operation/utils.js +20 -20
- package/src/model/position.d.ts +101 -97
- package/src/model/position.js +69 -64
- package/src/model/range.d.ts +90 -90
- package/src/model/range.js +87 -87
- package/src/model/rootelement.d.ts +11 -11
- package/src/model/rootelement.js +9 -9
- package/src/model/schema.d.ts +158 -154
- package/src/model/schema.js +93 -90
- package/src/model/selection.d.ts +73 -73
- package/src/model/selection.js +62 -62
- package/src/model/text.d.ts +11 -10
- package/src/model/text.js +11 -10
- package/src/model/textproxy.d.ts +39 -38
- package/src/model/textproxy.js +31 -30
- package/src/model/treewalker.d.ts +37 -37
- package/src/model/treewalker.js +14 -14
- package/src/model/typecheckable.d.ts +45 -45
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.d.ts +7 -7
- package/src/model/utils/deletecontent.d.ts +7 -5
- package/src/model/utils/deletecontent.js +13 -11
- package/src/model/utils/getselectedcontent.d.ts +6 -5
- package/src/model/utils/getselectedcontent.js +2 -1
- package/src/model/utils/insertcontent.d.ts +9 -8
- package/src/model/utils/insertcontent.js +41 -40
- package/src/model/utils/insertobject.d.ts +9 -9
- package/src/model/utils/insertobject.js +4 -4
- package/src/model/utils/modifyselection.d.ts +5 -4
- package/src/model/utils/modifyselection.js +12 -11
- package/src/model/utils/selection-post-fixer.d.ts +12 -8
- package/src/model/utils/selection-post-fixer.js +15 -11
- package/src/model/writer.d.ts +102 -101
- package/src/model/writer.js +99 -98
- package/src/view/attributeelement.d.ts +29 -29
- package/src/view/attributeelement.js +25 -25
- package/src/view/containerelement.d.ts +16 -15
- package/src/view/containerelement.js +15 -14
- package/src/view/datatransfer.d.ts +7 -7
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.d.ts +25 -25
- package/src/view/document.js +15 -15
- package/src/view/documentfragment.d.ts +21 -21
- package/src/view/documentfragment.js +14 -14
- package/src/view/documentselection.d.ts +65 -63
- package/src/view/documentselection.js +27 -25
- package/src/view/domconverter.d.ts +96 -91
- package/src/view/domconverter.js +78 -73
- package/src/view/downcastwriter.d.ts +185 -181
- package/src/view/downcastwriter.js +222 -210
- package/src/view/editableelement.d.ts +13 -13
- package/src/view/editableelement.js +8 -8
- package/src/view/element.d.ts +75 -74
- package/src/view/element.js +58 -58
- package/src/view/elementdefinition.d.ts +3 -4
- package/src/view/emptyelement.d.ts +13 -13
- package/src/view/emptyelement.js +13 -13
- package/src/view/filler.d.ts +14 -3
- package/src/view/filler.js +12 -1
- package/src/view/item.d.ts +4 -5
- package/src/view/matcher.d.ts +22 -19
- package/src/view/matcher.js +6 -6
- package/src/view/node.d.ts +33 -33
- package/src/view/node.js +9 -9
- package/src/view/observer/arrowkeysobserver.d.ts +10 -10
- package/src/view/observer/arrowkeysobserver.js +5 -5
- package/src/view/observer/bubblingemittermixin.d.ts +5 -5
- package/src/view/observer/bubblingemittermixin.js +2 -9
- package/src/view/observer/bubblingeventinfo.d.ts +9 -9
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.d.ts +8 -8
- package/src/view/observer/clickobserver.js +4 -4
- package/src/view/observer/compositionobserver.d.ts +19 -19
- package/src/view/observer/compositionobserver.js +6 -6
- package/src/view/observer/domeventdata.d.ts +9 -9
- package/src/view/observer/domeventdata.js +2 -2
- package/src/view/observer/domeventobserver.d.ts +3 -3
- package/src/view/observer/domeventobserver.js +5 -5
- package/src/view/observer/fakeselectionobserver.d.ts +9 -9
- package/src/view/observer/fakeselectionobserver.js +8 -8
- package/src/view/observer/focusobserver.d.ts +16 -16
- package/src/view/observer/focusobserver.js +7 -7
- package/src/view/observer/inputobserver.d.ts +18 -18
- package/src/view/observer/inputobserver.js +5 -5
- package/src/view/observer/keyobserver.d.ts +11 -11
- package/src/view/observer/keyobserver.js +3 -3
- package/src/view/observer/mouseobserver.d.ts +16 -16
- package/src/view/observer/mouseobserver.js +3 -3
- package/src/view/observer/mutationobserver.d.ts +21 -21
- package/src/view/observer/mutationobserver.js +7 -7
- package/src/view/observer/observer.d.ts +12 -12
- package/src/view/observer/observer.js +6 -6
- package/src/view/observer/selectionobserver.d.ts +33 -33
- package/src/view/observer/selectionobserver.js +14 -14
- package/src/view/observer/tabobserver.d.ts +10 -10
- package/src/view/observer/tabobserver.js +5 -5
- package/src/view/observer/touchobserver.d.ts +13 -13
- package/src/view/observer/touchobserver.js +3 -3
- package/src/view/placeholder.d.ts +21 -21
- package/src/view/placeholder.js +23 -23
- package/src/view/position.d.ts +49 -49
- package/src/view/position.js +42 -42
- package/src/view/range.d.ts +76 -74
- package/src/view/range.js +67 -65
- package/src/view/rawelement.d.ts +19 -19
- package/src/view/rawelement.js +16 -16
- package/src/view/renderer.d.ts +14 -14
- package/src/view/renderer.js +7 -7
- package/src/view/rooteditableelement.d.ts +8 -7
- package/src/view/rooteditableelement.js +7 -6
- package/src/view/selection.d.ts +66 -64
- package/src/view/selection.js +50 -48
- package/src/view/styles/background.d.ts +2 -2
- package/src/view/styles/background.js +9 -9
- package/src/view/styles/border.d.ts +2 -2
- package/src/view/styles/border.js +13 -13
- package/src/view/styles/margin.d.ts +2 -2
- package/src/view/styles/margin.js +5 -5
- package/src/view/styles/padding.d.ts +2 -2
- package/src/view/styles/padding.js +5 -5
- package/src/view/styles/utils.d.ts +24 -24
- package/src/view/styles/utils.js +25 -25
- package/src/view/stylesmap.d.ts +28 -32
- package/src/view/stylesmap.js +52 -39
- package/src/view/text.d.ts +11 -11
- package/src/view/text.js +10 -10
- package/src/view/textproxy.d.ts +33 -32
- package/src/view/textproxy.js +23 -22
- package/src/view/tokenlist.d.ts +14 -14
- package/src/view/tokenlist.js +10 -10
- package/src/view/treewalker.d.ts +42 -40
- package/src/view/treewalker.js +36 -35
- package/src/view/typecheckable.d.ts +76 -75
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.d.ts +22 -21
- package/src/view/uielement.js +17 -16
- package/src/view/upcastwriter.d.ts +70 -70
- package/src/view/upcastwriter.js +42 -42
- package/src/view/view.d.ts +70 -69
- package/src/view/view.js +56 -55
package/src/model/differ.d.ts
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/differ
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import type {
|
|
11
|
-
import type
|
|
12
|
-
import type
|
|
13
|
-
import type
|
|
14
|
-
import type Operation from './operation/operation.js';
|
|
8
|
+
import { ModelPosition } from './position.js';
|
|
9
|
+
import { ModelRange } from './range.js';
|
|
10
|
+
import type { MarkerCollection, MarkerData } from './markercollection.js';
|
|
11
|
+
import { type ModelItem } from './item.js';
|
|
12
|
+
import { type ModelNode } from './node.js';
|
|
13
|
+
import { type ModelRootElement } from './rootelement.js';
|
|
14
|
+
import { type Operation } from './operation/operation.js';
|
|
15
15
|
/**
|
|
16
16
|
* Calculates the difference between two model states.
|
|
17
17
|
*
|
|
@@ -20,7 +20,7 @@ import type Operation from './operation/operation.js';
|
|
|
20
20
|
* changed elements, after all changes are applied on the model document. Calculates the diff between saved
|
|
21
21
|
* elements and new ones and returns a change set.
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
23
|
+
export declare class Differ {
|
|
24
24
|
/**
|
|
25
25
|
* Priority of the {@link ~Differ#_elementState element states}. States on higher indexes of the array can overwrite states on the lower
|
|
26
26
|
* indexes.
|
|
@@ -144,7 +144,7 @@ export default class Differ {
|
|
|
144
144
|
*/
|
|
145
145
|
getMarkersToRemove(): Array<{
|
|
146
146
|
name: string;
|
|
147
|
-
range:
|
|
147
|
+
range: ModelRange;
|
|
148
148
|
}>;
|
|
149
149
|
/**
|
|
150
150
|
* Returns all markers which should be added as a result of buffered changes.
|
|
@@ -153,7 +153,7 @@ export default class Differ {
|
|
|
153
153
|
*/
|
|
154
154
|
getMarkersToAdd(): Array<{
|
|
155
155
|
name: string;
|
|
156
|
-
range:
|
|
156
|
+
range: ModelRange;
|
|
157
157
|
}>;
|
|
158
158
|
/**
|
|
159
159
|
* Returns all markers which changed.
|
|
@@ -161,8 +161,8 @@ export default class Differ {
|
|
|
161
161
|
getChangedMarkers(): Array<{
|
|
162
162
|
name: string;
|
|
163
163
|
data: {
|
|
164
|
-
oldRange:
|
|
165
|
-
newRange:
|
|
164
|
+
oldRange: ModelRange | null;
|
|
165
|
+
newRange: ModelRange | null;
|
|
166
166
|
};
|
|
167
167
|
}>;
|
|
168
168
|
/**
|
|
@@ -181,9 +181,9 @@ export default class Differ {
|
|
|
181
181
|
* Calculates the diff between the old model tree state (the state before the first buffered operations since the last {@link #reset}
|
|
182
182
|
* call) and the new model tree state (actual one). It should be called after all buffered operations are executed.
|
|
183
183
|
*
|
|
184
|
-
* The diff set is returned as an array of {@link module:engine/model/differ~
|
|
184
|
+
* The diff set is returned as an array of {@link module:engine/model/differ~DifferItem diff items}, each describing a change done
|
|
185
185
|
* on the model. The items are sorted by the position on which the change happened. If a position
|
|
186
|
-
* {@link module:engine/model/position~
|
|
186
|
+
* {@link module:engine/model/position~ModelPosition#isBefore is before} another one, it will be on an earlier index in the diff set.
|
|
187
187
|
*
|
|
188
188
|
* **Note**: Elements inside inserted element will not have a separate diff item, only the top most element change will be reported.
|
|
189
189
|
*
|
|
@@ -197,17 +197,17 @@ export default class Differ {
|
|
|
197
197
|
*/
|
|
198
198
|
getChanges(options?: {
|
|
199
199
|
includeChangesInGraveyard?: boolean;
|
|
200
|
-
}): Array<
|
|
200
|
+
}): Array<DifferItem>;
|
|
201
201
|
/**
|
|
202
202
|
* Returns all roots that have changed (either were attached, or detached, or their attributes changed).
|
|
203
203
|
*
|
|
204
204
|
* @returns Diff between the old and the new roots state.
|
|
205
205
|
*/
|
|
206
|
-
getChangedRoots(): Array<
|
|
206
|
+
getChangedRoots(): Array<DifferItemRoot>;
|
|
207
207
|
/**
|
|
208
208
|
* Returns a set of model items that were marked to get refreshed.
|
|
209
209
|
*/
|
|
210
|
-
getRefreshedItems(): Set<
|
|
210
|
+
getRefreshedItems(): Set<ModelItem>;
|
|
211
211
|
/**
|
|
212
212
|
* Resets `Differ`. Removes all buffered changes.
|
|
213
213
|
*/
|
|
@@ -219,7 +219,7 @@ export default class Differ {
|
|
|
219
219
|
* @internal
|
|
220
220
|
* @param item Item to refresh.
|
|
221
221
|
*/
|
|
222
|
-
_refreshItem(item:
|
|
222
|
+
_refreshItem(item: ModelItem): void;
|
|
223
223
|
/**
|
|
224
224
|
* Buffers all the data related to given root like it was all just added to the editor.
|
|
225
225
|
*
|
|
@@ -232,7 +232,7 @@ export default class Differ {
|
|
|
232
232
|
*
|
|
233
233
|
* @internal
|
|
234
234
|
*/
|
|
235
|
-
_bufferRootLoad(root:
|
|
235
|
+
_bufferRootLoad(root: ModelRootElement): void;
|
|
236
236
|
/**
|
|
237
237
|
* Buffers the root state change after the root was attached or detached
|
|
238
238
|
*/
|
|
@@ -344,12 +344,14 @@ export default class Differ {
|
|
|
344
344
|
export type DifferItemAction = 'insert' | 'remove' | 'rename' | 'refresh';
|
|
345
345
|
/**
|
|
346
346
|
* A snapshot is representing state of a given element before the first change was applied on that element.
|
|
347
|
+
*
|
|
348
|
+
* @internal
|
|
347
349
|
*/
|
|
348
350
|
export interface DifferSnapshot {
|
|
349
351
|
/**
|
|
350
352
|
* Node for which was snapshot was made.
|
|
351
353
|
*/
|
|
352
|
-
node:
|
|
354
|
+
node: ModelNode;
|
|
353
355
|
/**
|
|
354
356
|
* Name of the element at the time when the snapshot was made. For text node snapshots, it is set to `'$text'`.
|
|
355
357
|
*/
|
|
@@ -364,15 +366,15 @@ export interface DifferSnapshot {
|
|
|
364
366
|
*
|
|
365
367
|
* Could be one of:
|
|
366
368
|
*
|
|
367
|
-
* * {@link module:engine/model/differ~
|
|
368
|
-
* * {@link module:engine/model/differ~
|
|
369
|
-
* * {@link module:engine/model/differ~
|
|
369
|
+
* * {@link module:engine/model/differ~DifferItemInsert `DifferItemInsert`},
|
|
370
|
+
* * {@link module:engine/model/differ~DifferItemRemove `DifferItemRemove`},
|
|
371
|
+
* * {@link module:engine/model/differ~DifferItemAttribute `DifferItemAttribute`}.
|
|
370
372
|
*/
|
|
371
|
-
export type
|
|
373
|
+
export type DifferItem = DifferItemInsert | DifferItemRemove | DifferItemAttribute;
|
|
372
374
|
/**
|
|
373
375
|
* A single diff item for inserted nodes.
|
|
374
376
|
*/
|
|
375
|
-
export interface
|
|
377
|
+
export interface DifferItemInsert {
|
|
376
378
|
/**
|
|
377
379
|
* The type of diff item.
|
|
378
380
|
*/
|
|
@@ -396,7 +398,7 @@ export interface DiffItemInsert {
|
|
|
396
398
|
/**
|
|
397
399
|
* The position where the node was inserted.
|
|
398
400
|
*/
|
|
399
|
-
position:
|
|
401
|
+
position: ModelPosition;
|
|
400
402
|
/**
|
|
401
403
|
* The length of an inserted text node. For elements, it is always 1 as each inserted element is counted as a one.
|
|
402
404
|
*/
|
|
@@ -421,10 +423,31 @@ export interface DiffItemInsert {
|
|
|
421
423
|
attributes: Map<string, unknown>;
|
|
422
424
|
};
|
|
423
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* A single diff item for re-inserted nodes.
|
|
428
|
+
*/
|
|
429
|
+
export interface DifferItemReinsert {
|
|
430
|
+
/**
|
|
431
|
+
* The type of diff item.
|
|
432
|
+
*/
|
|
433
|
+
type: 'reinsert';
|
|
434
|
+
/**
|
|
435
|
+
* The name of the re-inserted elements or `'$text'` for a text node.
|
|
436
|
+
*/
|
|
437
|
+
name: string;
|
|
438
|
+
/**
|
|
439
|
+
* The position where the node was reinserted.
|
|
440
|
+
*/
|
|
441
|
+
position: ModelPosition;
|
|
442
|
+
/**
|
|
443
|
+
* The length of a re-inserted text node. For elements, it is always 1 as each re-inserted element is counted as a one.
|
|
444
|
+
*/
|
|
445
|
+
length: number;
|
|
446
|
+
}
|
|
424
447
|
/**
|
|
425
448
|
* A single diff item for removed nodes.
|
|
426
449
|
*/
|
|
427
|
-
export interface
|
|
450
|
+
export interface DifferItemRemove {
|
|
428
451
|
/**
|
|
429
452
|
* The type of diff item.
|
|
430
453
|
*/
|
|
@@ -448,7 +471,7 @@ export interface DiffItemRemove {
|
|
|
448
471
|
/**
|
|
449
472
|
* The position where the node was removed.
|
|
450
473
|
*/
|
|
451
|
-
position:
|
|
474
|
+
position: ModelPosition;
|
|
452
475
|
/**
|
|
453
476
|
* The length of a removed text node. For elements, it is always 1, as each removed element is counted as a one.
|
|
454
477
|
*/
|
|
@@ -457,7 +480,7 @@ export interface DiffItemRemove {
|
|
|
457
480
|
/**
|
|
458
481
|
* A single diff item for attribute change.
|
|
459
482
|
*/
|
|
460
|
-
export interface
|
|
483
|
+
export interface DifferItemAttribute {
|
|
461
484
|
/**
|
|
462
485
|
* The type of diff item.
|
|
463
486
|
*/
|
|
@@ -477,12 +500,12 @@ export interface DiffItemAttribute {
|
|
|
477
500
|
/**
|
|
478
501
|
* The range where the change happened.
|
|
479
502
|
*/
|
|
480
|
-
range:
|
|
503
|
+
range: ModelRange;
|
|
481
504
|
}
|
|
482
505
|
/**
|
|
483
506
|
* A single diff item for a changed root.
|
|
484
507
|
*/
|
|
485
|
-
export interface
|
|
508
|
+
export interface DifferItemRoot {
|
|
486
509
|
/**
|
|
487
510
|
* Name of the changed root.
|
|
488
511
|
*/
|
package/src/model/differ.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/differ
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import { ModelPosition } from './position.js';
|
|
9
|
+
import { ModelRange } from './range.js';
|
|
10
10
|
/**
|
|
11
11
|
* Calculates the difference between two model states.
|
|
12
12
|
*
|
|
@@ -173,7 +173,7 @@ class Differ {
|
|
|
173
173
|
this._markInsert(operation.targetPosition.parent, operation.getMovedRangeStart().offset, operation.howMany);
|
|
174
174
|
}
|
|
175
175
|
// Remember -- operation is buffered before it is executed. So, it was not executed yet.
|
|
176
|
-
const range =
|
|
176
|
+
const range = ModelRange._createFromPositionAndShift(operation.sourcePosition, operation.howMany);
|
|
177
177
|
for (const node of range.getItems({ shallow: true })) {
|
|
178
178
|
this._setElementState(node, 'move');
|
|
179
179
|
}
|
|
@@ -185,7 +185,7 @@ class Differ {
|
|
|
185
185
|
}
|
|
186
186
|
this._markRemove(operation.position.parent, operation.position.offset, 1);
|
|
187
187
|
this._markInsert(operation.position.parent, operation.position.offset, 1);
|
|
188
|
-
const range =
|
|
188
|
+
const range = ModelRange._createFromPositionAndShift(operation.position, 1);
|
|
189
189
|
for (const marker of this._markerCollection.getMarkersIntersectingRange(range)) {
|
|
190
190
|
const markerData = marker.getData();
|
|
191
191
|
this.bufferMarkerChange(marker.name, markerData, markerData);
|
|
@@ -199,7 +199,7 @@ class Differ {
|
|
|
199
199
|
if (!this._isInInsertedElement(splitElement)) {
|
|
200
200
|
this._markRemove(splitElement, operation.splitPosition.offset, operation.howMany);
|
|
201
201
|
// Remember -- operation is buffered before it is executed. So, it was not executed yet.
|
|
202
|
-
const range =
|
|
202
|
+
const range = ModelRange._createFromPositionAndShift(operation.splitPosition, operation.howMany);
|
|
203
203
|
for (const node of range.getItems({ shallow: true })) {
|
|
204
204
|
this._setElementState(node, 'move');
|
|
205
205
|
}
|
|
@@ -230,7 +230,7 @@ class Differ {
|
|
|
230
230
|
if (!this._isInInsertedElement(mergedIntoElement)) {
|
|
231
231
|
this._markInsert(mergedIntoElement, operation.targetPosition.offset, mergedElement.maxOffset);
|
|
232
232
|
// Remember -- operation is buffered before it is executed. So, it was not executed yet.
|
|
233
|
-
const range =
|
|
233
|
+
const range = ModelRange._createFromPositionAndShift(operation.sourcePosition, operation.howMany);
|
|
234
234
|
for (const node of range.getItems({ shallow: true })) {
|
|
235
235
|
this._setElementState(node, 'move');
|
|
236
236
|
}
|
|
@@ -369,9 +369,9 @@ class Differ {
|
|
|
369
369
|
* Calculates the diff between the old model tree state (the state before the first buffered operations since the last {@link #reset}
|
|
370
370
|
* call) and the new model tree state (actual one). It should be called after all buffered operations are executed.
|
|
371
371
|
*
|
|
372
|
-
* The diff set is returned as an array of {@link module:engine/model/differ~
|
|
372
|
+
* The diff set is returned as an array of {@link module:engine/model/differ~DifferItem diff items}, each describing a change done
|
|
373
373
|
* on the model. The items are sorted by the position on which the change happened. If a position
|
|
374
|
-
* {@link module:engine/model/position~
|
|
374
|
+
* {@link module:engine/model/position~ModelPosition#isBefore is before} another one, it will be on an earlier index in the diff set.
|
|
375
375
|
*
|
|
376
376
|
* **Note**: Elements inside inserted element will not have a separate diff item, only the top most element change will be reported.
|
|
377
377
|
*
|
|
@@ -439,11 +439,11 @@ class Differ {
|
|
|
439
439
|
const afterAttributes = childrenAfter[i].attributes;
|
|
440
440
|
let range;
|
|
441
441
|
if (childrenAfter[i].name == '$text') {
|
|
442
|
-
range = new
|
|
442
|
+
range = new ModelRange(ModelPosition._createAt(element, i), ModelPosition._createAt(element, i + 1));
|
|
443
443
|
}
|
|
444
444
|
else {
|
|
445
445
|
const index = element.offsetToIndex(i);
|
|
446
|
-
range = new
|
|
446
|
+
range = new ModelRange(ModelPosition._createAt(element, i), ModelPosition._createAt(element.getChild(index), 0));
|
|
447
447
|
}
|
|
448
448
|
// Generate diff items for this change (there might be multiple attributes changed and
|
|
449
449
|
// there is a single diff for each of them) and insert them into the diff set.
|
|
@@ -582,7 +582,7 @@ class Differ {
|
|
|
582
582
|
this._markInsert(item.parent, item.startOffset, item.offsetSize);
|
|
583
583
|
this._refreshedItems.add(item);
|
|
584
584
|
this._setElementState(item, 'refresh');
|
|
585
|
-
const range =
|
|
585
|
+
const range = ModelRange._createOn(item);
|
|
586
586
|
for (const marker of this._markerCollection.getMarkersIntersectingRange(range)) {
|
|
587
587
|
const markerData = marker.getData();
|
|
588
588
|
this.bufferMarkerChange(marker.name, markerData, markerData);
|
|
@@ -1026,7 +1026,7 @@ class Differ {
|
|
|
1026
1026
|
_getInsertDiff(parent, offset, action, elementSnapshot, elementSnapshotBefore) {
|
|
1027
1027
|
const diffItem = {
|
|
1028
1028
|
type: 'insert',
|
|
1029
|
-
position:
|
|
1029
|
+
position: ModelPosition._createAt(parent, offset),
|
|
1030
1030
|
name: elementSnapshot.name,
|
|
1031
1031
|
attributes: new Map(elementSnapshot.attributes),
|
|
1032
1032
|
length: 1,
|
|
@@ -1054,7 +1054,7 @@ class Differ {
|
|
|
1054
1054
|
return {
|
|
1055
1055
|
type: 'remove',
|
|
1056
1056
|
action,
|
|
1057
|
-
position:
|
|
1057
|
+
position: ModelPosition._createAt(parent, offset),
|
|
1058
1058
|
name: elementSnapshot.name,
|
|
1059
1059
|
attributes: new Map(elementSnapshot.attributes),
|
|
1060
1060
|
length: 1,
|
|
@@ -1135,7 +1135,7 @@ class Differ {
|
|
|
1135
1135
|
* and `howMany`.
|
|
1136
1136
|
*/
|
|
1137
1137
|
_removeAllNestedChanges(parent, offset, howMany) {
|
|
1138
|
-
const range = new
|
|
1138
|
+
const range = new ModelRange(ModelPosition._createAt(parent, offset), ModelPosition._createAt(parent, offset + howMany));
|
|
1139
1139
|
for (const item of range.getItems({ shallow: true })) {
|
|
1140
1140
|
if (item.is('element')) {
|
|
1141
1141
|
this._changesInElement.delete(item);
|
|
@@ -1144,7 +1144,7 @@ class Differ {
|
|
|
1144
1144
|
}
|
|
1145
1145
|
}
|
|
1146
1146
|
}
|
|
1147
|
-
export
|
|
1147
|
+
export { Differ };
|
|
1148
1148
|
/**
|
|
1149
1149
|
* Returns a snapshot for the specified child node. Text node snapshots have the `name` property set to `$text`.
|
|
1150
1150
|
*/
|
package/src/model/document.d.ts
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/document
|
|
7
7
|
*/
|
|
8
|
-
import Differ from './differ.js';
|
|
9
|
-
import
|
|
10
|
-
import History from './history.js';
|
|
11
|
-
import
|
|
12
|
-
import type {
|
|
13
|
-
import type Batch from './batch.js';
|
|
14
|
-
import type
|
|
15
|
-
import type
|
|
8
|
+
import { Differ } from './differ.js';
|
|
9
|
+
import { ModelDocumentSelection } from './documentselection.js';
|
|
10
|
+
import { History } from './history.js';
|
|
11
|
+
import { ModelRootElement } from './rootelement.js';
|
|
12
|
+
import type { Model } from './model.js';
|
|
13
|
+
import { type Batch } from './batch.js';
|
|
14
|
+
import { type ModelRange } from './range.js';
|
|
15
|
+
import { type ModelWriter } from './writer.js';
|
|
16
16
|
import { Collection } from '@ckeditor/ckeditor5-utils';
|
|
17
|
-
declare const
|
|
17
|
+
declare const ModelDocument_base: {
|
|
18
18
|
new (): import("@ckeditor/ckeditor5-utils").Emitter;
|
|
19
19
|
prototype: import("@ckeditor/ckeditor5-utils").Emitter;
|
|
20
20
|
};
|
|
@@ -24,8 +24,8 @@ declare const Document_base: {
|
|
|
24
24
|
* Read more about working with the model in
|
|
25
25
|
* {@glink framework/architecture/editing-engine#model introduction to the the editing engine's architecture}.
|
|
26
26
|
*
|
|
27
|
-
* Usually, the document contains just one {@link module:engine/model/document~
|
|
28
|
-
* you can retrieve it by just calling {@link module:engine/model/document~
|
|
27
|
+
* Usually, the document contains just one {@link module:engine/model/document~ModelDocument#roots root element}, so
|
|
28
|
+
* you can retrieve it by just calling {@link module:engine/model/document~ModelDocument#getRoot} without specifying its name:
|
|
29
29
|
*
|
|
30
30
|
* ```ts
|
|
31
31
|
* model.document.getRoot(); // -> returns the main root
|
|
@@ -34,7 +34,7 @@ declare const Document_base: {
|
|
|
34
34
|
* However, the document may contain multiple roots – e.g. when the editor has multiple editable areas
|
|
35
35
|
* (e.g. a title and a body of a message).
|
|
36
36
|
*/
|
|
37
|
-
export
|
|
37
|
+
export declare class ModelDocument extends /* #__PURE__ */ ModelDocument_base {
|
|
38
38
|
/**
|
|
39
39
|
* The {@link module:engine/model/model~Model model} that the document is a part of.
|
|
40
40
|
*/
|
|
@@ -46,12 +46,12 @@ export default class Document extends /* #__PURE__ */ Document_base {
|
|
|
46
46
|
/**
|
|
47
47
|
* The selection in this document.
|
|
48
48
|
*/
|
|
49
|
-
readonly selection:
|
|
49
|
+
readonly selection: ModelDocumentSelection;
|
|
50
50
|
/**
|
|
51
51
|
* A list of roots that are owned and managed by this document. Use {@link #createRoot}, {@link #getRoot} and
|
|
52
52
|
* {@link #getRootNames} to manipulate it.
|
|
53
53
|
*/
|
|
54
|
-
readonly roots: Collection<
|
|
54
|
+
readonly roots: Collection<ModelRootElement>;
|
|
55
55
|
/**
|
|
56
56
|
* The model differ object. Its role is to buffer changes done on the model document and then calculate a diff of those changes.
|
|
57
57
|
*/
|
|
@@ -91,19 +91,19 @@ export default class Document extends /* #__PURE__ */ Document_base {
|
|
|
91
91
|
/**
|
|
92
92
|
* The graveyard tree root. A document always has a graveyard root that stores removed nodes.
|
|
93
93
|
*/
|
|
94
|
-
get graveyard():
|
|
94
|
+
get graveyard(): ModelRootElement;
|
|
95
95
|
/**
|
|
96
96
|
* Creates a new root.
|
|
97
97
|
*
|
|
98
98
|
* **Note:** do not use this method after the editor has been initialized! If you want to dynamically add a root, use
|
|
99
|
-
* {@link module:engine/model/writer~
|
|
99
|
+
* {@link module:engine/model/writer~ModelWriter#addRoot `model.Writer#addRoot`} instead.
|
|
100
100
|
*
|
|
101
101
|
* @param elementName The element name. Defaults to `'$root'` which also has some basic schema defined
|
|
102
102
|
* (e.g. `$block` elements are allowed inside the `$root`). Make sure to define a proper schema if you use a different name.
|
|
103
103
|
* @param rootName A unique root name.
|
|
104
104
|
* @returns The created root.
|
|
105
105
|
*/
|
|
106
|
-
createRoot(elementName?: string, rootName?: string):
|
|
106
|
+
createRoot(elementName?: string, rootName?: string): ModelRootElement;
|
|
107
107
|
/**
|
|
108
108
|
* Removes all event listeners set by the document instance.
|
|
109
109
|
*/
|
|
@@ -117,7 +117,7 @@ export default class Document extends /* #__PURE__ */ Document_base {
|
|
|
117
117
|
* @param name The root name of the root to return.
|
|
118
118
|
* @returns The root registered under a given name or `null` when there is no root with the given name.
|
|
119
119
|
*/
|
|
120
|
-
getRoot(name?: string):
|
|
120
|
+
getRoot(name?: string): ModelRootElement | null;
|
|
121
121
|
/**
|
|
122
122
|
* Returns an array with names of all roots added to the document (except the {@link #graveyard graveyard root}).
|
|
123
123
|
*
|
|
@@ -135,18 +135,18 @@ export default class Document extends /* #__PURE__ */ Document_base {
|
|
|
135
135
|
*
|
|
136
136
|
* @param includeDetached Specified whether detached roots should be returned as well.
|
|
137
137
|
*/
|
|
138
|
-
getRoots(includeDetached?: boolean): Array<
|
|
138
|
+
getRoots(includeDetached?: boolean): Array<ModelRootElement>;
|
|
139
139
|
/**
|
|
140
140
|
* Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features
|
|
141
141
|
* will operate on a correct model state.
|
|
142
142
|
*
|
|
143
143
|
* An execution of a feature may lead to an incorrect document tree state. The callbacks are used to fix the document tree after
|
|
144
144
|
* it has changed. Post-fixers are fired just after all changes from the outermost change block were applied but
|
|
145
|
-
* before the {@link module:engine/model/document~
|
|
145
|
+
* before the {@link module:engine/model/document~ModelDocument#event:change change event} is fired. If a post-fixer callback made
|
|
146
146
|
* a change, it should return `true`. When this happens, all post-fixers are fired again to check if something else should
|
|
147
147
|
* not be fixed in the new document tree state.
|
|
148
148
|
*
|
|
149
|
-
* As a parameter, a post-fixer callback receives a {@link module:engine/model/writer~
|
|
149
|
+
* As a parameter, a post-fixer callback receives a {@link module:engine/model/writer~ModelWriter writer} instance connected with the
|
|
150
150
|
* executed changes block. Thanks to that, all changes done by the callback will be added to the same
|
|
151
151
|
* {@link module:engine/model/batch~Batch batch} (and undo step) as the original changes. This makes post-fixer changes transparent
|
|
152
152
|
* for the user.
|
|
@@ -190,7 +190,7 @@ export default class Document extends /* #__PURE__ */ Document_base {
|
|
|
190
190
|
* @fires change:data
|
|
191
191
|
* @param writer The writer on which post-fixers will be called.
|
|
192
192
|
*/
|
|
193
|
-
_handleChangeBlock(writer:
|
|
193
|
+
_handleChangeBlock(writer: ModelWriter): void;
|
|
194
194
|
/**
|
|
195
195
|
* Returns whether there is a buffered change or if the selection has changed from the last
|
|
196
196
|
* {@link module:engine/model/model~Model#enqueueChange `enqueueChange()` block}
|
|
@@ -205,23 +205,23 @@ export default class Document extends /* #__PURE__ */ Document_base {
|
|
|
205
205
|
*
|
|
206
206
|
* @returns The default root for this document.
|
|
207
207
|
*/
|
|
208
|
-
protected _getDefaultRoot():
|
|
208
|
+
protected _getDefaultRoot(): ModelRootElement;
|
|
209
209
|
/**
|
|
210
210
|
* Returns the default range for this selection. The default range is a collapsed range that starts and ends
|
|
211
211
|
* at the beginning of this selection's document {@link #_getDefaultRoot default root}.
|
|
212
212
|
*
|
|
213
213
|
* @internal
|
|
214
214
|
*/
|
|
215
|
-
_getDefaultRange():
|
|
215
|
+
_getDefaultRange(): ModelRange;
|
|
216
216
|
/**
|
|
217
|
-
* Checks whether a given {@link module:engine/model/range~
|
|
217
|
+
* Checks whether a given {@link module:engine/model/range~ModelRange range} is a valid range for
|
|
218
218
|
* the {@link #selection document's selection}.
|
|
219
219
|
*
|
|
220
220
|
* @internal
|
|
221
221
|
* @param range A range to check.
|
|
222
222
|
* @returns `true` if `range` is valid, `false` otherwise.
|
|
223
223
|
*/
|
|
224
|
-
_validateSelectionRange(range:
|
|
224
|
+
_validateSelectionRange(range: ModelRange): boolean;
|
|
225
225
|
/**
|
|
226
226
|
* Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
|
|
227
227
|
*
|
|
@@ -257,16 +257,16 @@ export default class Document extends /* #__PURE__ */ Document_base {
|
|
|
257
257
|
* } );
|
|
258
258
|
* ```
|
|
259
259
|
*
|
|
260
|
-
* @eventName ~
|
|
261
|
-
* @eventName ~
|
|
260
|
+
* @eventName ~ModelDocument#change
|
|
261
|
+
* @eventName ~ModelDocument#change:data
|
|
262
262
|
* @param batch The batch that was used in the executed changes block.
|
|
263
263
|
*/
|
|
264
|
-
export type
|
|
264
|
+
export type ModelDocumentChangeEvent = {
|
|
265
265
|
name: 'change' | 'change:data';
|
|
266
266
|
args: [batch: Batch];
|
|
267
267
|
};
|
|
268
268
|
/**
|
|
269
|
-
* Callback passed as an argument to the {@link module:engine/model/document~
|
|
269
|
+
* Callback passed as an argument to the {@link module:engine/model/document~ModelDocument#registerPostFixer} method.
|
|
270
270
|
*/
|
|
271
|
-
export type ModelPostFixer = (writer:
|
|
271
|
+
export type ModelPostFixer = (writer: ModelWriter) => boolean;
|
|
272
272
|
export {};
|
package/src/model/document.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/document
|
|
7
7
|
*/
|
|
8
|
-
import Differ from './differ.js';
|
|
9
|
-
import
|
|
10
|
-
import History from './history.js';
|
|
11
|
-
import
|
|
8
|
+
import { Differ } from './differ.js';
|
|
9
|
+
import { ModelDocumentSelection } from './documentselection.js';
|
|
10
|
+
import { History } from './history.js';
|
|
11
|
+
import { ModelRootElement } from './rootelement.js';
|
|
12
12
|
import { CKEditorError, Collection, EmitterMixin, isInsideSurrogatePair, isInsideCombinedSymbol } from '@ckeditor/ckeditor5-utils';
|
|
13
13
|
import { clone } from 'es-toolkit/compat';
|
|
14
14
|
// @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );
|
|
@@ -19,8 +19,8 @@ const graveyardName = '$graveyard';
|
|
|
19
19
|
* Read more about working with the model in
|
|
20
20
|
* {@glink framework/architecture/editing-engine#model introduction to the the editing engine's architecture}.
|
|
21
21
|
*
|
|
22
|
-
* Usually, the document contains just one {@link module:engine/model/document~
|
|
23
|
-
* you can retrieve it by just calling {@link module:engine/model/document~
|
|
22
|
+
* Usually, the document contains just one {@link module:engine/model/document~ModelDocument#roots root element}, so
|
|
23
|
+
* you can retrieve it by just calling {@link module:engine/model/document~ModelDocument#getRoot} without specifying its name:
|
|
24
24
|
*
|
|
25
25
|
* ```ts
|
|
26
26
|
* model.document.getRoot(); // -> returns the main root
|
|
@@ -29,7 +29,7 @@ const graveyardName = '$graveyard';
|
|
|
29
29
|
* However, the document may contain multiple roots – e.g. when the editor has multiple editable areas
|
|
30
30
|
* (e.g. a title and a body of a message).
|
|
31
31
|
*/
|
|
32
|
-
export
|
|
32
|
+
export class ModelDocument extends /* #__PURE__ */ EmitterMixin() {
|
|
33
33
|
/**
|
|
34
34
|
* The {@link module:engine/model/model~Model model} that the document is a part of.
|
|
35
35
|
*/
|
|
@@ -75,7 +75,7 @@ export default class Document extends /* #__PURE__ */ EmitterMixin() {
|
|
|
75
75
|
super();
|
|
76
76
|
this.model = model;
|
|
77
77
|
this.history = new History();
|
|
78
|
-
this.selection = new
|
|
78
|
+
this.selection = new ModelDocumentSelection(this);
|
|
79
79
|
this.roots = new Collection({ idProperty: 'rootName' });
|
|
80
80
|
this.differ = new Differ(model.markers);
|
|
81
81
|
this.isReadOnly = false;
|
|
@@ -170,7 +170,7 @@ export default class Document extends /* #__PURE__ */ EmitterMixin() {
|
|
|
170
170
|
* Creates a new root.
|
|
171
171
|
*
|
|
172
172
|
* **Note:** do not use this method after the editor has been initialized! If you want to dynamically add a root, use
|
|
173
|
-
* {@link module:engine/model/writer~
|
|
173
|
+
* {@link module:engine/model/writer~ModelWriter#addRoot `model.Writer#addRoot`} instead.
|
|
174
174
|
*
|
|
175
175
|
* @param elementName The element name. Defaults to `'$root'` which also has some basic schema defined
|
|
176
176
|
* (e.g. `$block` elements are allowed inside the `$root`). Make sure to define a proper schema if you use a different name.
|
|
@@ -186,7 +186,7 @@ export default class Document extends /* #__PURE__ */ EmitterMixin() {
|
|
|
186
186
|
*/
|
|
187
187
|
throw new CKEditorError('model-document-createroot-name-exists', this, { name: rootName });
|
|
188
188
|
}
|
|
189
|
-
const root = new
|
|
189
|
+
const root = new ModelRootElement(this, elementName, rootName);
|
|
190
190
|
this.roots.add(root);
|
|
191
191
|
return root;
|
|
192
192
|
}
|
|
@@ -237,11 +237,11 @@ export default class Document extends /* #__PURE__ */ EmitterMixin() {
|
|
|
237
237
|
*
|
|
238
238
|
* An execution of a feature may lead to an incorrect document tree state. The callbacks are used to fix the document tree after
|
|
239
239
|
* it has changed. Post-fixers are fired just after all changes from the outermost change block were applied but
|
|
240
|
-
* before the {@link module:engine/model/document~
|
|
240
|
+
* before the {@link module:engine/model/document~ModelDocument#event:change change event} is fired. If a post-fixer callback made
|
|
241
241
|
* a change, it should return `true`. When this happens, all post-fixers are fired again to check if something else should
|
|
242
242
|
* not be fixed in the new document tree state.
|
|
243
243
|
*
|
|
244
|
-
* As a parameter, a post-fixer callback receives a {@link module:engine/model/writer~
|
|
244
|
+
* As a parameter, a post-fixer callback receives a {@link module:engine/model/writer~ModelWriter writer} instance connected with the
|
|
245
245
|
* executed changes block. Thanks to that, all changes done by the callback will be added to the same
|
|
246
246
|
* {@link module:engine/model/batch~Batch batch} (and undo step) as the original changes. This makes post-fixer changes transparent
|
|
247
247
|
* for the user.
|
|
@@ -348,7 +348,7 @@ export default class Document extends /* #__PURE__ */ EmitterMixin() {
|
|
|
348
348
|
return nearestRange || model.createRange(position);
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
|
-
* Checks whether a given {@link module:engine/model/range~
|
|
351
|
+
* Checks whether a given {@link module:engine/model/range~ModelRange range} is a valid range for
|
|
352
352
|
* the {@link #selection document's selection}.
|
|
353
353
|
*
|
|
354
354
|
* @internal
|