@ckeditor/ckeditor5-engine 47.6.1 → 48.0.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/LICENSE.md +1 -1
- package/{src → dist}/engineconfig.d.ts +6 -15
- package/dist/index-editor.css +38 -15
- package/dist/index.css +37 -37
- package/dist/index.css.map +1 -1
- package/{src → dist}/index.d.ts +0 -1
- package/dist/index.js +588 -94
- package/dist/index.js.map +1 -1
- package/{src → dist}/model/model.d.ts +10 -4
- package/{src → dist}/model/selection.d.ts +1 -1
- package/{src → dist}/view/downcastwriter.d.ts +3 -2
- package/{src → dist}/view/element.d.ts +2 -2
- package/{src → dist}/view/matcher.d.ts +4 -2
- package/dist/view/styles/background.d.ts +18 -0
- package/{src → dist}/view/styles/border.d.ts +0 -12
- package/{src → dist}/view/styles/margin.d.ts +0 -13
- package/{src → dist}/view/styles/padding.d.ts +0 -13
- package/{src → dist}/view/styles/utils.d.ts +12 -0
- package/package.json +20 -39
- package/src/controller/datacontroller.js +0 -522
- package/src/controller/editingcontroller.js +0 -181
- package/src/conversion/conversion.js +0 -606
- package/src/conversion/conversionhelpers.js +0 -33
- package/src/conversion/downcastdispatcher.js +0 -563
- package/src/conversion/downcasthelpers.js +0 -2160
- package/src/conversion/mapper.js +0 -1050
- package/src/conversion/modelconsumable.js +0 -331
- package/src/conversion/upcastdispatcher.js +0 -470
- package/src/conversion/upcasthelpers.js +0 -952
- package/src/conversion/viewconsumable.js +0 -541
- package/src/dataprocessor/basichtmlwriter.js +0 -22
- package/src/dataprocessor/dataprocessor.js +0 -5
- package/src/dataprocessor/htmldataprocessor.js +0 -107
- package/src/dataprocessor/htmlwriter.js +0 -5
- package/src/dataprocessor/xmldataprocessor.js +0 -127
- package/src/dev-utils/model.js +0 -396
- package/src/dev-utils/operationreplayer.js +0 -116
- package/src/dev-utils/utils.js +0 -122
- package/src/dev-utils/view.js +0 -990
- package/src/engineconfig.js +0 -5
- package/src/index.js +0 -134
- package/src/legacyerrors.js +0 -17
- package/src/model/batch.js +0 -98
- package/src/model/differ.js +0 -1288
- package/src/model/document.js +0 -398
- package/src/model/documentfragment.js +0 -332
- package/src/model/documentselection.js +0 -1026
- package/src/model/element.js +0 -323
- package/src/model/history.js +0 -206
- package/src/model/item.js +0 -5
- package/src/model/liveposition.js +0 -93
- package/src/model/liverange.js +0 -121
- package/src/model/markercollection.js +0 -436
- package/src/model/model.js +0 -866
- package/src/model/node.js +0 -371
- package/src/model/nodelist.js +0 -244
- package/src/model/operation/attributeoperation.js +0 -172
- package/src/model/operation/detachoperation.js +0 -87
- package/src/model/operation/insertoperation.js +0 -153
- package/src/model/operation/markeroperation.js +0 -136
- package/src/model/operation/mergeoperation.js +0 -184
- package/src/model/operation/moveoperation.js +0 -179
- package/src/model/operation/nooperation.js +0 -48
- package/src/model/operation/operation.js +0 -78
- package/src/model/operation/operationfactory.js +0 -44
- package/src/model/operation/renameoperation.js +0 -128
- package/src/model/operation/rootattributeoperation.js +0 -173
- package/src/model/operation/rootoperation.js +0 -106
- package/src/model/operation/splitoperation.js +0 -214
- package/src/model/operation/transform.js +0 -2211
- package/src/model/operation/utils.js +0 -217
- package/src/model/position.js +0 -1041
- package/src/model/range.js +0 -880
- package/src/model/rootelement.js +0 -82
- package/src/model/schema.js +0 -1542
- package/src/model/selection.js +0 -814
- package/src/model/text.js +0 -92
- package/src/model/textproxy.js +0 -202
- package/src/model/treewalker.js +0 -313
- package/src/model/typecheckable.js +0 -16
- package/src/model/utils/autoparagraphing.js +0 -63
- package/src/model/utils/deletecontent.js +0 -509
- package/src/model/utils/getselectedcontent.js +0 -126
- package/src/model/utils/insertcontent.js +0 -750
- package/src/model/utils/insertobject.js +0 -135
- package/src/model/utils/modifyselection.js +0 -187
- package/src/model/utils/selection-post-fixer.js +0 -264
- package/src/model/writer.js +0 -1318
- package/src/view/attributeelement.js +0 -220
- package/src/view/containerelement.js +0 -91
- package/src/view/datatransfer.js +0 -106
- package/src/view/document.js +0 -139
- package/src/view/documentfragment.js +0 -251
- package/src/view/documentselection.js +0 -270
- package/src/view/domconverter.js +0 -1661
- package/src/view/downcastwriter.js +0 -1589
- package/src/view/editableelement.js +0 -74
- package/src/view/element.js +0 -1053
- package/src/view/elementdefinition.js +0 -5
- package/src/view/emptyelement.js +0 -83
- package/src/view/filler.js +0 -161
- package/src/view/item.js +0 -5
- package/src/view/matcher.js +0 -437
- package/src/view/node.js +0 -238
- package/src/view/observer/arrowkeysobserver.js +0 -40
- package/src/view/observer/bubblingemittermixin.js +0 -215
- package/src/view/observer/bubblingeventinfo.js +0 -49
- package/src/view/observer/clickobserver.js +0 -26
- package/src/view/observer/compositionobserver.js +0 -64
- package/src/view/observer/domeventdata.js +0 -63
- package/src/view/observer/domeventobserver.js +0 -81
- package/src/view/observer/fakeselectionobserver.js +0 -95
- package/src/view/observer/focusobserver.js +0 -166
- package/src/view/observer/inputobserver.js +0 -236
- package/src/view/observer/keyobserver.js +0 -36
- package/src/view/observer/mouseobserver.js +0 -26
- package/src/view/observer/mutationobserver.js +0 -219
- package/src/view/observer/observer.js +0 -92
- package/src/view/observer/pointerobserver.js +0 -26
- package/src/view/observer/selectionobserver.js +0 -318
- package/src/view/observer/tabobserver.js +0 -42
- package/src/view/observer/touchobserver.js +0 -26
- package/src/view/placeholder.js +0 -285
- package/src/view/position.js +0 -341
- package/src/view/range.js +0 -451
- package/src/view/rawelement.js +0 -115
- package/src/view/renderer.js +0 -1148
- package/src/view/rooteditableelement.js +0 -78
- package/src/view/selection.js +0 -594
- package/src/view/styles/background.d.ts +0 -33
- package/src/view/styles/background.js +0 -74
- package/src/view/styles/border.js +0 -316
- package/src/view/styles/margin.js +0 -34
- package/src/view/styles/padding.js +0 -34
- package/src/view/styles/utils.js +0 -219
- package/src/view/stylesmap.js +0 -941
- package/src/view/text.js +0 -110
- package/src/view/textproxy.js +0 -136
- package/src/view/tokenlist.js +0 -194
- package/src/view/treewalker.js +0 -389
- package/src/view/typecheckable.js +0 -19
- package/src/view/uielement.js +0 -194
- package/src/view/upcastwriter.js +0 -363
- package/src/view/view.js +0 -579
- package/theme/placeholder.css +0 -36
- package/theme/renderer.css +0 -9
- /package/{src → dist}/controller/datacontroller.d.ts +0 -0
- /package/{src → dist}/controller/editingcontroller.d.ts +0 -0
- /package/{src → dist}/conversion/conversion.d.ts +0 -0
- /package/{src → dist}/conversion/conversionhelpers.d.ts +0 -0
- /package/{src → dist}/conversion/downcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/downcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/mapper.d.ts +0 -0
- /package/{src → dist}/conversion/modelconsumable.d.ts +0 -0
- /package/{src → dist}/conversion/upcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/upcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/viewconsumable.d.ts +0 -0
- /package/{src → dist}/dataprocessor/basichtmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/dataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/xmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dev-utils/model.d.ts +0 -0
- /package/{src → dist}/dev-utils/operationreplayer.d.ts +0 -0
- /package/{src → dist}/dev-utils/utils.d.ts +0 -0
- /package/{src → dist}/dev-utils/view.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/model/batch.d.ts +0 -0
- /package/{src → dist}/model/differ.d.ts +0 -0
- /package/{src → dist}/model/document.d.ts +0 -0
- /package/{src → dist}/model/documentfragment.d.ts +0 -0
- /package/{src → dist}/model/documentselection.d.ts +0 -0
- /package/{src → dist}/model/element.d.ts +0 -0
- /package/{src → dist}/model/history.d.ts +0 -0
- /package/{src → dist}/model/item.d.ts +0 -0
- /package/{src → dist}/model/liveposition.d.ts +0 -0
- /package/{src → dist}/model/liverange.d.ts +0 -0
- /package/{src → dist}/model/markercollection.d.ts +0 -0
- /package/{src → dist}/model/node.d.ts +0 -0
- /package/{src → dist}/model/nodelist.d.ts +0 -0
- /package/{src → dist}/model/operation/attributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/detachoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/insertoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/markeroperation.d.ts +0 -0
- /package/{src → dist}/model/operation/mergeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/moveoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/nooperation.d.ts +0 -0
- /package/{src → dist}/model/operation/operation.d.ts +0 -0
- /package/{src → dist}/model/operation/operationfactory.d.ts +0 -0
- /package/{src → dist}/model/operation/renameoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootattributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/splitoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/transform.d.ts +0 -0
- /package/{src → dist}/model/operation/utils.d.ts +0 -0
- /package/{src → dist}/model/position.d.ts +0 -0
- /package/{src → dist}/model/range.d.ts +0 -0
- /package/{src → dist}/model/rootelement.d.ts +0 -0
- /package/{src → dist}/model/schema.d.ts +0 -0
- /package/{src → dist}/model/text.d.ts +0 -0
- /package/{src → dist}/model/textproxy.d.ts +0 -0
- /package/{src → dist}/model/treewalker.d.ts +0 -0
- /package/{src → dist}/model/typecheckable.d.ts +0 -0
- /package/{src → dist}/model/utils/autoparagraphing.d.ts +0 -0
- /package/{src → dist}/model/utils/deletecontent.d.ts +0 -0
- /package/{src → dist}/model/utils/getselectedcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertobject.d.ts +0 -0
- /package/{src → dist}/model/utils/modifyselection.d.ts +0 -0
- /package/{src → dist}/model/utils/selection-post-fixer.d.ts +0 -0
- /package/{src → dist}/model/writer.d.ts +0 -0
- /package/{src → dist}/view/attributeelement.d.ts +0 -0
- /package/{src → dist}/view/containerelement.d.ts +0 -0
- /package/{src → dist}/view/datatransfer.d.ts +0 -0
- /package/{src → dist}/view/document.d.ts +0 -0
- /package/{src → dist}/view/documentfragment.d.ts +0 -0
- /package/{src → dist}/view/documentselection.d.ts +0 -0
- /package/{src → dist}/view/domconverter.d.ts +0 -0
- /package/{src → dist}/view/editableelement.d.ts +0 -0
- /package/{src → dist}/view/elementdefinition.d.ts +0 -0
- /package/{src → dist}/view/emptyelement.d.ts +0 -0
- /package/{src → dist}/view/filler.d.ts +0 -0
- /package/{src → dist}/view/item.d.ts +0 -0
- /package/{src → dist}/view/node.d.ts +0 -0
- /package/{src → dist}/view/observer/arrowkeysobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingemittermixin.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingeventinfo.d.ts +0 -0
- /package/{src → dist}/view/observer/clickobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/compositionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventdata.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/fakeselectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/focusobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/inputobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/keyobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mouseobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mutationobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/observer.d.ts +0 -0
- /package/{src → dist}/view/observer/pointerobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/selectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/tabobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/touchobserver.d.ts +0 -0
- /package/{src → dist}/view/placeholder.d.ts +0 -0
- /package/{src → dist}/view/position.d.ts +0 -0
- /package/{src → dist}/view/range.d.ts +0 -0
- /package/{src → dist}/view/rawelement.d.ts +0 -0
- /package/{src → dist}/view/renderer.d.ts +0 -0
- /package/{src → dist}/view/rooteditableelement.d.ts +0 -0
- /package/{src → dist}/view/selection.d.ts +0 -0
- /package/{src → dist}/view/stylesmap.d.ts +0 -0
- /package/{src → dist}/view/text.d.ts +0 -0
- /package/{src → dist}/view/textproxy.d.ts +0 -0
- /package/{src → dist}/view/tokenlist.d.ts +0 -0
- /package/{src → dist}/view/treewalker.d.ts +0 -0
- /package/{src → dist}/view/typecheckable.d.ts +0 -0
- /package/{src → dist}/view/uielement.d.ts +0 -0
- /package/{src → dist}/view/upcastwriter.d.ts +0 -0
- /package/{src → dist}/view/view.d.ts +0 -0
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/model/operation/rootattributeoperation
|
|
7
|
-
*/
|
|
8
|
-
import { Operation } from './operation.js';
|
|
9
|
-
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
/**
|
|
11
|
-
* Operation to change root element's attribute. Using this class you can add, remove or change value of the attribute.
|
|
12
|
-
*
|
|
13
|
-
* This operation is needed, because root elements can't be changed through
|
|
14
|
-
* {@link module:engine/model/operation/attributeoperation~AttributeOperation}.
|
|
15
|
-
* It is because {@link module:engine/model/operation/attributeoperation~AttributeOperation}
|
|
16
|
-
* requires a range to change and root element can't
|
|
17
|
-
* be a part of range because every {@link module:engine/model/position~ModelPosition} has to be inside a root.
|
|
18
|
-
* {@link module:engine/model/position~ModelPosition} can't be created before a root element.
|
|
19
|
-
*/
|
|
20
|
-
export class RootAttributeOperation extends Operation {
|
|
21
|
-
/**
|
|
22
|
-
* Root element to change.
|
|
23
|
-
*/
|
|
24
|
-
root;
|
|
25
|
-
/**
|
|
26
|
-
* Key of an attribute to change or remove.
|
|
27
|
-
*/
|
|
28
|
-
key;
|
|
29
|
-
/**
|
|
30
|
-
* Old value of the attribute with given key or `null`, if attribute was not set before.
|
|
31
|
-
*
|
|
32
|
-
* @readonly
|
|
33
|
-
*/
|
|
34
|
-
oldValue;
|
|
35
|
-
/**
|
|
36
|
-
* New value of the attribute with given key or `null`, if operation should remove attribute.
|
|
37
|
-
*
|
|
38
|
-
* @readonly
|
|
39
|
-
*/
|
|
40
|
-
newValue;
|
|
41
|
-
/**
|
|
42
|
-
* Creates an operation that changes, removes or adds attributes on root element.
|
|
43
|
-
*
|
|
44
|
-
* @see module:engine/model/operation/attributeoperation~AttributeOperation
|
|
45
|
-
* @param root Root element to change.
|
|
46
|
-
* @param key Key of an attribute to change or remove.
|
|
47
|
-
* @param oldValue Old value of the attribute with given key or `null`, if attribute was not set before.
|
|
48
|
-
* @param newValue New value of the attribute with given key or `null`, if operation should remove attribute.
|
|
49
|
-
* @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
|
|
50
|
-
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
51
|
-
*/
|
|
52
|
-
constructor(root, key, oldValue, newValue, baseVersion) {
|
|
53
|
-
super(baseVersion);
|
|
54
|
-
this.root = root;
|
|
55
|
-
this.key = key;
|
|
56
|
-
this.oldValue = oldValue === undefined ? null : oldValue;
|
|
57
|
-
this.newValue = newValue === undefined ? null : newValue;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* @inheritDoc
|
|
61
|
-
*/
|
|
62
|
-
get type() {
|
|
63
|
-
if (this.oldValue === null) {
|
|
64
|
-
return 'addRootAttribute';
|
|
65
|
-
}
|
|
66
|
-
else if (this.newValue === null) {
|
|
67
|
-
return 'removeRootAttribute';
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return 'changeRootAttribute';
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @inheritDoc
|
|
75
|
-
*/
|
|
76
|
-
get affectedSelectable() {
|
|
77
|
-
return this.root;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Creates and returns an operation that has the same parameters as this operation.
|
|
81
|
-
*
|
|
82
|
-
* @returns Clone of this operation.
|
|
83
|
-
*/
|
|
84
|
-
clone() {
|
|
85
|
-
return new RootAttributeOperation(this.root, this.key, this.oldValue, this.newValue, this.baseVersion);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
89
|
-
*/
|
|
90
|
-
getReversed() {
|
|
91
|
-
return new RootAttributeOperation(this.root, this.key, this.newValue, this.oldValue, this.baseVersion + 1);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* @inheritDoc
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
_validate() {
|
|
98
|
-
if (this.root != this.root.root || this.root.is('documentFragment')) {
|
|
99
|
-
/**
|
|
100
|
-
* The element to change is not a root element.
|
|
101
|
-
*
|
|
102
|
-
* @error rootattribute-operation-not-a-root
|
|
103
|
-
* @param {module:engine/model/rootelement~ModelRootElement} root The root element.
|
|
104
|
-
* @param {string} key The key of the attribute.
|
|
105
|
-
*/
|
|
106
|
-
throw new CKEditorError('rootattribute-operation-not-a-root', this, { root: this.root, key: this.key });
|
|
107
|
-
}
|
|
108
|
-
if (this.oldValue !== null && this.root.getAttribute(this.key) !== this.oldValue) {
|
|
109
|
-
/**
|
|
110
|
-
* The attribute which should be removed does not exist for the given node.
|
|
111
|
-
*
|
|
112
|
-
* @error rootattribute-operation-wrong-old-value
|
|
113
|
-
* @param {module:engine/model/rootelement~ModelRootElement} root The root element.
|
|
114
|
-
* @param {string} key The key of the attribute.
|
|
115
|
-
*/
|
|
116
|
-
throw new CKEditorError('rootattribute-operation-wrong-old-value', this, { root: this.root, key: this.key });
|
|
117
|
-
}
|
|
118
|
-
if (this.oldValue === null && this.newValue !== null && this.root.hasAttribute(this.key)) {
|
|
119
|
-
/**
|
|
120
|
-
* The attribute with given key already exists for the given node.
|
|
121
|
-
*
|
|
122
|
-
* @error rootattribute-operation-attribute-exists
|
|
123
|
-
* @param {module:engine/model/rootelement~ModelRootElement} root The root element.
|
|
124
|
-
* @param {string} key The key of the attribute.
|
|
125
|
-
*/
|
|
126
|
-
throw new CKEditorError('rootattribute-operation-attribute-exists', this, { root: this.root, key: this.key });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* @inheritDoc
|
|
131
|
-
* @internal
|
|
132
|
-
*/
|
|
133
|
-
_execute() {
|
|
134
|
-
if (this.newValue !== null) {
|
|
135
|
-
this.root._setAttribute(this.key, this.newValue);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
this.root._removeAttribute(this.key);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* @inheritDoc
|
|
143
|
-
*/
|
|
144
|
-
toJSON() {
|
|
145
|
-
const json = super.toJSON();
|
|
146
|
-
json.root = this.root.toJSON();
|
|
147
|
-
return json;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @inheritDoc
|
|
151
|
-
*/
|
|
152
|
-
static get className() {
|
|
153
|
-
return 'RootAttributeOperation';
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Creates `RootAttributeOperation` object from deserialized object, i.e. from parsed JSON string.
|
|
157
|
-
*
|
|
158
|
-
* @param json Deserialized JSON object.
|
|
159
|
-
* @param document Document on which this operation will be applied.
|
|
160
|
-
*/
|
|
161
|
-
static fromJSON(json, document) {
|
|
162
|
-
if (!document.getRoot(json.root)) {
|
|
163
|
-
/**
|
|
164
|
-
* Cannot create RootAttributeOperation for document. Root with the specified name does not exist.
|
|
165
|
-
*
|
|
166
|
-
* @error rootattribute-operation-fromjson-no-root
|
|
167
|
-
* @param {string} rootName The root name.
|
|
168
|
-
*/
|
|
169
|
-
throw new CKEditorError('rootattribute-operation-fromjson-no-root', this, { rootName: json.root });
|
|
170
|
-
}
|
|
171
|
-
return new RootAttributeOperation(document.getRoot(json.root), json.key, json.oldValue, json.newValue, json.baseVersion);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/model/operation/rootoperation
|
|
7
|
-
*/
|
|
8
|
-
import { Operation } from './operation.js';
|
|
9
|
-
/**
|
|
10
|
-
* Operation that creates (or attaches) or detaches a root element.
|
|
11
|
-
*/
|
|
12
|
-
export class RootOperation extends Operation {
|
|
13
|
-
/**
|
|
14
|
-
* Root name to create or detach.
|
|
15
|
-
*/
|
|
16
|
-
rootName;
|
|
17
|
-
/**
|
|
18
|
-
* Root element name.
|
|
19
|
-
*/
|
|
20
|
-
elementName;
|
|
21
|
-
/**
|
|
22
|
-
* Specifies whether the operation adds (`true`) or detaches the root (`false`).
|
|
23
|
-
*/
|
|
24
|
-
isAdd;
|
|
25
|
-
/**
|
|
26
|
-
* Document which owns the root.
|
|
27
|
-
*/
|
|
28
|
-
_document;
|
|
29
|
-
/**
|
|
30
|
-
* Creates an operation that creates or removes a root element.
|
|
31
|
-
*
|
|
32
|
-
* @param rootName Root name to create or detach.
|
|
33
|
-
* @param elementName Root element name.
|
|
34
|
-
* @param isAdd Specifies whether the operation adds (`true`) or detaches the root (`false`).
|
|
35
|
-
* @param document Document which owns the root.
|
|
36
|
-
* @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation can be applied.
|
|
37
|
-
*/
|
|
38
|
-
constructor(rootName, elementName, isAdd, document, baseVersion) {
|
|
39
|
-
super(baseVersion);
|
|
40
|
-
this.rootName = rootName;
|
|
41
|
-
this.elementName = elementName;
|
|
42
|
-
this.isAdd = isAdd;
|
|
43
|
-
this._document = document;
|
|
44
|
-
// Make sure that the root exists ASAP, this is important for RTC.
|
|
45
|
-
// If the root was dynamically added, there will be more operations that operate on/in this root.
|
|
46
|
-
// These operations will require root element instance (in operation property or in position instance).
|
|
47
|
-
// If the root is not created ahead of time, instantiating such operations may fail.
|
|
48
|
-
if (!this._document.getRoot(this.rootName)) {
|
|
49
|
-
const root = this._document.createRoot(this.elementName, this.rootName);
|
|
50
|
-
root._isAttached = false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @inheritDoc
|
|
55
|
-
*/
|
|
56
|
-
get type() {
|
|
57
|
-
return this.isAdd ? 'addRoot' : 'detachRoot';
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* @inheritDoc
|
|
61
|
-
*/
|
|
62
|
-
get affectedSelectable() {
|
|
63
|
-
return this._document.getRoot(this.rootName);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @inheritDoc
|
|
67
|
-
*/
|
|
68
|
-
clone() {
|
|
69
|
-
return new RootOperation(this.rootName, this.elementName, this.isAdd, this._document, this.baseVersion);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* @inheritDoc
|
|
73
|
-
*/
|
|
74
|
-
getReversed() {
|
|
75
|
-
return new RootOperation(this.rootName, this.elementName, !this.isAdd, this._document, this.baseVersion + 1);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* @inheritDoc
|
|
79
|
-
*/
|
|
80
|
-
_execute() {
|
|
81
|
-
this._document.getRoot(this.rootName)._isAttached = this.isAdd;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @inheritDoc
|
|
85
|
-
*/
|
|
86
|
-
toJSON() {
|
|
87
|
-
const json = super.toJSON();
|
|
88
|
-
delete json._document;
|
|
89
|
-
return json;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @inheritDoc
|
|
93
|
-
*/
|
|
94
|
-
static get className() {
|
|
95
|
-
return 'RootOperation';
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Creates `RootOperation` object from deserialized object, i.e. from parsed JSON string.
|
|
99
|
-
*
|
|
100
|
-
* @param json Deserialized JSON object.
|
|
101
|
-
* @param document Document on which this operation will be applied.
|
|
102
|
-
*/
|
|
103
|
-
static fromJSON(json, document) {
|
|
104
|
-
return new RootOperation(json.rootName, json.elementName, json.isAdd, document, json.baseVersion);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/model/operation/splitoperation
|
|
7
|
-
*/
|
|
8
|
-
import { Operation } from './operation.js';
|
|
9
|
-
import { MergeOperation } from './mergeoperation.js';
|
|
10
|
-
import { ModelPosition } from '../position.js';
|
|
11
|
-
import { ModelRange } from '../range.js';
|
|
12
|
-
import { _insert, _move } from './utils.js';
|
|
13
|
-
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
14
|
-
/**
|
|
15
|
-
* Operation to split {@link module:engine/model/element~ModelElement an element} at given
|
|
16
|
-
* {@link module:engine/model/operation/splitoperation~SplitOperation#splitPosition split position} into two elements,
|
|
17
|
-
* both containing a part of the element's original content.
|
|
18
|
-
*/
|
|
19
|
-
export class SplitOperation extends Operation {
|
|
20
|
-
/**
|
|
21
|
-
* Position at which an element should be split.
|
|
22
|
-
*/
|
|
23
|
-
splitPosition;
|
|
24
|
-
/**
|
|
25
|
-
* Total offset size of elements that are in the split element after `position`.
|
|
26
|
-
*/
|
|
27
|
-
howMany;
|
|
28
|
-
/**
|
|
29
|
-
* Position at which the clone of split element (or element from graveyard) will be inserted.
|
|
30
|
-
*/
|
|
31
|
-
insertionPosition;
|
|
32
|
-
/**
|
|
33
|
-
* Position in the graveyard root before the element which should be used as a parent of the nodes after `position`.
|
|
34
|
-
* If it is not set, a copy of the the `position` parent will be used.
|
|
35
|
-
*
|
|
36
|
-
* The default behavior is to clone the split element. Element from graveyard is used during undo.
|
|
37
|
-
*/
|
|
38
|
-
graveyardPosition;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a split operation.
|
|
41
|
-
*
|
|
42
|
-
* @param splitPosition Position at which an element should be split.
|
|
43
|
-
* @param howMany Total offset size of elements that are in the split element after `position`.
|
|
44
|
-
* @param insertionPosition Position at which the clone of split element (or element from graveyard) will be inserted.
|
|
45
|
-
* @param graveyardPosition Position in the graveyard root before the element which
|
|
46
|
-
* should be used as a parent of the nodes after `position`. If it is not set, a copy of the the `position` parent will be used.
|
|
47
|
-
* @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
|
|
48
|
-
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
49
|
-
*/
|
|
50
|
-
constructor(splitPosition, howMany, insertionPosition, graveyardPosition, baseVersion) {
|
|
51
|
-
super(baseVersion);
|
|
52
|
-
this.splitPosition = splitPosition.clone();
|
|
53
|
-
// Keep position sticking to the next node. This way any new content added at the place where the element is split
|
|
54
|
-
// will be left in the original element.
|
|
55
|
-
this.splitPosition.stickiness = 'toNext';
|
|
56
|
-
this.howMany = howMany;
|
|
57
|
-
this.insertionPosition = insertionPosition;
|
|
58
|
-
this.graveyardPosition = graveyardPosition ? graveyardPosition.clone() : null;
|
|
59
|
-
if (this.graveyardPosition) {
|
|
60
|
-
this.graveyardPosition.stickiness = 'toNext';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @inheritDoc
|
|
65
|
-
*/
|
|
66
|
-
get type() {
|
|
67
|
-
return 'split';
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Position inside the new clone of a split element.
|
|
71
|
-
*
|
|
72
|
-
* This is a position where nodes that are after the split position will be moved to.
|
|
73
|
-
*/
|
|
74
|
-
get moveTargetPosition() {
|
|
75
|
-
const path = this.insertionPosition.path.slice();
|
|
76
|
-
path.push(0);
|
|
77
|
-
return new ModelPosition(this.insertionPosition.root, path);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Artificial range that contains all the nodes from the split element that will be moved to the new element.
|
|
81
|
-
* The range starts at {@link #splitPosition} and ends in the same parent, at `POSITIVE_INFINITY` offset.
|
|
82
|
-
*/
|
|
83
|
-
get movedRange() {
|
|
84
|
-
const end = this.splitPosition.getShiftedBy(Number.POSITIVE_INFINITY);
|
|
85
|
-
return new ModelRange(this.splitPosition, end);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @inheritDoc
|
|
89
|
-
*/
|
|
90
|
-
get affectedSelectable() {
|
|
91
|
-
// These could be positions but `Selectable` type only supports `Iterable<Range>`.
|
|
92
|
-
const ranges = [
|
|
93
|
-
ModelRange._createFromPositionAndShift(this.splitPosition, 0),
|
|
94
|
-
ModelRange._createFromPositionAndShift(this.insertionPosition, 0)
|
|
95
|
-
];
|
|
96
|
-
if (this.graveyardPosition) {
|
|
97
|
-
ranges.push(ModelRange._createFromPositionAndShift(this.graveyardPosition, 0));
|
|
98
|
-
}
|
|
99
|
-
return ranges;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Creates and returns an operation that has the same parameters as this operation.
|
|
103
|
-
*
|
|
104
|
-
* @returns Clone of this operation.
|
|
105
|
-
*/
|
|
106
|
-
clone() {
|
|
107
|
-
return new SplitOperation(this.splitPosition, this.howMany, this.insertionPosition, this.graveyardPosition, this.baseVersion);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
111
|
-
*/
|
|
112
|
-
getReversed() {
|
|
113
|
-
const graveyard = this.splitPosition.root.document.graveyard;
|
|
114
|
-
const graveyardPosition = new ModelPosition(graveyard, [0]);
|
|
115
|
-
return new MergeOperation(this.moveTargetPosition, this.howMany, this.splitPosition, graveyardPosition, this.baseVersion + 1);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @inheritDoc
|
|
119
|
-
* @internal
|
|
120
|
-
*/
|
|
121
|
-
_validate() {
|
|
122
|
-
const element = this.splitPosition.parent;
|
|
123
|
-
const offset = this.splitPosition.offset;
|
|
124
|
-
// Validate whether split operation has correct parameters.
|
|
125
|
-
if (!element || element.maxOffset < offset) {
|
|
126
|
-
/**
|
|
127
|
-
* Split position is invalid.
|
|
128
|
-
*
|
|
129
|
-
* @error split-operation-position-invalid
|
|
130
|
-
*/
|
|
131
|
-
throw new CKEditorError('split-operation-position-invalid', this);
|
|
132
|
-
}
|
|
133
|
-
else if (!element.parent) {
|
|
134
|
-
/**
|
|
135
|
-
* Cannot split root element.
|
|
136
|
-
*
|
|
137
|
-
* @error split-operation-split-in-root
|
|
138
|
-
*/
|
|
139
|
-
throw new CKEditorError('split-operation-split-in-root', this);
|
|
140
|
-
}
|
|
141
|
-
else if (this.howMany !== Number.NEGATIVE_INFINITY && this.howMany != element.maxOffset - this.splitPosition.offset) {
|
|
142
|
-
/**
|
|
143
|
-
* Split operation specifies wrong number of nodes to move.
|
|
144
|
-
*
|
|
145
|
-
* @error split-operation-how-many-invalid
|
|
146
|
-
*/
|
|
147
|
-
throw new CKEditorError('split-operation-how-many-invalid', this);
|
|
148
|
-
}
|
|
149
|
-
else if (this.graveyardPosition && !this.graveyardPosition.nodeAfter) {
|
|
150
|
-
/**
|
|
151
|
-
* Graveyard position invalid.
|
|
152
|
-
*
|
|
153
|
-
* @error split-operation-graveyard-position-invalid
|
|
154
|
-
*/
|
|
155
|
-
throw new CKEditorError('split-operation-graveyard-position-invalid', this);
|
|
156
|
-
}
|
|
157
|
-
this.howMany = this.splitPosition.parent.maxOffset - this.splitPosition.offset;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @inheritDoc
|
|
161
|
-
* @internal
|
|
162
|
-
*/
|
|
163
|
-
_execute() {
|
|
164
|
-
const splitElement = this.splitPosition.parent;
|
|
165
|
-
if (this.graveyardPosition) {
|
|
166
|
-
_move(ModelRange._createFromPositionAndShift(this.graveyardPosition, 1), this.insertionPosition);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const newElement = splitElement._clone();
|
|
170
|
-
_insert(this.insertionPosition, newElement);
|
|
171
|
-
}
|
|
172
|
-
const sourceRange = new ModelRange(ModelPosition._createAt(splitElement, this.splitPosition.offset), ModelPosition._createAt(splitElement, splitElement.maxOffset));
|
|
173
|
-
_move(sourceRange, this.moveTargetPosition);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* @inheritDoc
|
|
177
|
-
*/
|
|
178
|
-
toJSON() {
|
|
179
|
-
const json = super.toJSON();
|
|
180
|
-
json.splitPosition = this.splitPosition.toJSON();
|
|
181
|
-
json.insertionPosition = this.insertionPosition.toJSON();
|
|
182
|
-
if (this.graveyardPosition) {
|
|
183
|
-
json.graveyardPosition = this.graveyardPosition.toJSON();
|
|
184
|
-
}
|
|
185
|
-
return json;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* @inheritDoc
|
|
189
|
-
*/
|
|
190
|
-
static get className() {
|
|
191
|
-
return 'SplitOperation';
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Helper function that returns a default insertion position basing on given `splitPosition`. The default insertion
|
|
195
|
-
* position is after the split element.
|
|
196
|
-
*/
|
|
197
|
-
static getInsertionPosition(splitPosition) {
|
|
198
|
-
const path = splitPosition.path.slice(0, -1);
|
|
199
|
-
path[path.length - 1]++;
|
|
200
|
-
return new ModelPosition(splitPosition.root, path, 'toPrevious');
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Creates `SplitOperation` object from deserialized object, i.e. from parsed JSON string.
|
|
204
|
-
*
|
|
205
|
-
* @param json Deserialized JSON object.
|
|
206
|
-
* @param document Document on which this operation will be applied.
|
|
207
|
-
*/
|
|
208
|
-
static fromJSON(json, document) {
|
|
209
|
-
const splitPosition = ModelPosition.fromJSON(json.splitPosition, document);
|
|
210
|
-
const insertionPosition = ModelPosition.fromJSON(json.insertionPosition, document);
|
|
211
|
-
const graveyardPosition = json.graveyardPosition ? ModelPosition.fromJSON(json.graveyardPosition, document) : null;
|
|
212
|
-
return new this(splitPosition, json.howMany, insertionPosition, graveyardPosition, json.baseVersion);
|
|
213
|
-
}
|
|
214
|
-
}
|