@ckeditor/ckeditor5-engine 45.2.1 → 46.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/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 +94 -89
- 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
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/view/downcastwriter
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
8
|
+
import { ViewPosition } from './position.js';
|
|
9
|
+
import { ViewRange } from './range.js';
|
|
10
|
+
import { ViewSelection } from './selection.js';
|
|
11
|
+
import { ViewContainerElement } from './containerelement.js';
|
|
12
|
+
import { ViewAttributeElement } from './attributeelement.js';
|
|
13
|
+
import { ViewEmptyElement } from './emptyelement.js';
|
|
14
|
+
import { ViewUIElement } from './uielement.js';
|
|
15
|
+
import { ViewRawElement } from './rawelement.js';
|
|
16
16
|
import { CKEditorError, isIterable } from '@ckeditor/ckeditor5-utils';
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
17
|
+
import { ViewDocumentFragment } from './documentfragment.js';
|
|
18
|
+
import { ViewText } from './text.js';
|
|
19
|
+
import { ViewEditableElement } from './editableelement.js';
|
|
20
20
|
import { isPlainObject } from 'es-toolkit/compat';
|
|
21
21
|
/**
|
|
22
22
|
* View downcast writer.
|
|
@@ -24,23 +24,23 @@ import { isPlainObject } from 'es-toolkit/compat';
|
|
|
24
24
|
* It provides a set of methods used to manipulate view nodes.
|
|
25
25
|
*
|
|
26
26
|
* Do not create an instance of this writer manually. To modify a view structure, use
|
|
27
|
-
* the {@link module:engine/view/view~
|
|
27
|
+
* the {@link module:engine/view/view~EditingView#change `View#change()`} block.
|
|
28
28
|
*
|
|
29
|
-
* The `
|
|
29
|
+
* The `ViewDowncastWriter` is designed to work with semantic views which are the views that were/are being downcasted from the model.
|
|
30
30
|
* To work with ordinary views (e.g. parsed from a pasted content) use the
|
|
31
|
-
* {@link module:engine/view/upcastwriter~
|
|
31
|
+
* {@link module:engine/view/upcastwriter~ViewUpcastWriter upcast writer}.
|
|
32
32
|
*
|
|
33
33
|
* Read more about changing the view in the {@glink framework/architecture/editing-engine#changing-the-view Changing the view}
|
|
34
34
|
* section of the {@glink framework/architecture/editing-engine Editing engine architecture} guide.
|
|
35
35
|
*/
|
|
36
|
-
export
|
|
36
|
+
export class ViewDowncastWriter {
|
|
37
37
|
/**
|
|
38
38
|
* The view document instance in which this writer operates.
|
|
39
39
|
*/
|
|
40
40
|
document;
|
|
41
41
|
/**
|
|
42
|
-
* Holds references to the attribute groups that share the same {@link module:engine/view/attributeelement~
|
|
43
|
-
* The keys are `id`s, the values are `Set`s holding {@link module:engine/view/attributeelement~
|
|
42
|
+
* Holds references to the attribute groups that share the same {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
|
|
43
|
+
* The keys are `id`s, the values are `Set`s holding {@link module:engine/view/attributeelement~ViewAttributeElement}s.
|
|
44
44
|
*/
|
|
45
45
|
_cloneGroups = new Map();
|
|
46
46
|
/**
|
|
@@ -57,28 +57,29 @@ export default class DowncastWriter {
|
|
|
57
57
|
this.document.selection._setTo(...args);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Moves {@link module:engine/view/documentselection~
|
|
60
|
+
* Moves {@link module:engine/view/documentselection~ViewDocumentSelection#focus selection's focus} to the specified location.
|
|
61
61
|
*
|
|
62
|
-
* The location can be specified in the same form as
|
|
62
|
+
* The location can be specified in the same form as
|
|
63
|
+
* {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
|
|
63
64
|
* parameters.
|
|
64
65
|
*
|
|
65
66
|
* @param itemOrPosition
|
|
66
|
-
* @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~
|
|
67
|
+
* @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~ViewItem view item}.
|
|
67
68
|
*/
|
|
68
69
|
setSelectionFocus(itemOrPosition, offset) {
|
|
69
70
|
this.document.selection._setFocus(itemOrPosition, offset);
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
|
-
* Creates a new {@link module:engine/view/documentfragment~
|
|
73
|
+
* Creates a new {@link module:engine/view/documentfragment~ViewDocumentFragment} instance.
|
|
73
74
|
*
|
|
74
75
|
* @param children A list of nodes to be inserted into the created document fragment.
|
|
75
76
|
* @returns The created document fragment.
|
|
76
77
|
*/
|
|
77
78
|
createDocumentFragment(children) {
|
|
78
|
-
return new
|
|
79
|
+
return new ViewDocumentFragment(this.document, children);
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
|
-
* Creates a new {@link module:engine/view/text~
|
|
82
|
+
* Creates a new {@link module:engine/view/text~ViewText text node}.
|
|
82
83
|
*
|
|
83
84
|
* ```ts
|
|
84
85
|
* writer.createText( 'foo' );
|
|
@@ -88,10 +89,10 @@ export default class DowncastWriter {
|
|
|
88
89
|
* @returns The created text node.
|
|
89
90
|
*/
|
|
90
91
|
createText(data) {
|
|
91
|
-
return new
|
|
92
|
+
return new ViewText(this.document, data);
|
|
92
93
|
}
|
|
93
94
|
/**
|
|
94
|
-
* Creates a new {@link module:engine/view/attributeelement~
|
|
95
|
+
* Creates a new {@link module:engine/view/attributeelement~ViewAttributeElement}.
|
|
95
96
|
*
|
|
96
97
|
* ```ts
|
|
97
98
|
* writer.createAttributeElement( 'strong' );
|
|
@@ -107,14 +108,14 @@ export default class DowncastWriter {
|
|
|
107
108
|
* @param name Name of the element.
|
|
108
109
|
* @param attributes Element's attributes.
|
|
109
110
|
* @param options Element's options.
|
|
110
|
-
* @param options.priority Element's {@link module:engine/view/attributeelement~
|
|
111
|
-
* @param options.id Element's {@link module:engine/view/attributeelement~
|
|
111
|
+
* @param options.priority Element's {@link module:engine/view/attributeelement~ViewAttributeElement#priority priority}.
|
|
112
|
+
* @param options.id Element's {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
|
|
112
113
|
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
113
114
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
114
115
|
* @returns Created element.
|
|
115
116
|
*/
|
|
116
117
|
createAttributeElement(name, attributes, options = {}) {
|
|
117
|
-
const attributeElement = new
|
|
118
|
+
const attributeElement = new ViewAttributeElement(this.document, name, attributes);
|
|
118
119
|
if (typeof options.priority === 'number') {
|
|
119
120
|
attributeElement._priority = options.priority;
|
|
120
121
|
}
|
|
@@ -127,21 +128,21 @@ export default class DowncastWriter {
|
|
|
127
128
|
return attributeElement;
|
|
128
129
|
}
|
|
129
130
|
createContainerElement(name, attributes, childrenOrOptions = {}, options = {}) {
|
|
130
|
-
let children =
|
|
131
|
-
if (
|
|
131
|
+
let children = undefined;
|
|
132
|
+
if (isContainerOptions(childrenOrOptions)) {
|
|
132
133
|
options = childrenOrOptions;
|
|
133
134
|
}
|
|
134
135
|
else {
|
|
135
136
|
children = childrenOrOptions;
|
|
136
137
|
}
|
|
137
|
-
const containerElement = new
|
|
138
|
+
const containerElement = new ViewContainerElement(this.document, name, attributes, children);
|
|
138
139
|
if (options.renderUnsafeAttributes) {
|
|
139
140
|
containerElement._unsafeAttributesToRender.push(...options.renderUnsafeAttributes);
|
|
140
141
|
}
|
|
141
142
|
return containerElement;
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
144
|
-
* Creates a new {@link module:engine/view/editableelement~
|
|
145
|
+
* Creates a new {@link module:engine/view/editableelement~ViewEditableElement}.
|
|
145
146
|
*
|
|
146
147
|
* ```ts
|
|
147
148
|
* writer.createEditableElement( 'div' );
|
|
@@ -159,14 +160,14 @@ export default class DowncastWriter {
|
|
|
159
160
|
* @returns Created element.
|
|
160
161
|
*/
|
|
161
162
|
createEditableElement(name, attributes, options = {}) {
|
|
162
|
-
const editableElement = new
|
|
163
|
+
const editableElement = new ViewEditableElement(this.document, name, attributes);
|
|
163
164
|
if (options.renderUnsafeAttributes) {
|
|
164
165
|
editableElement._unsafeAttributesToRender.push(...options.renderUnsafeAttributes);
|
|
165
166
|
}
|
|
166
167
|
return editableElement;
|
|
167
168
|
}
|
|
168
169
|
/**
|
|
169
|
-
* Creates a new {@link module:engine/view/emptyelement~
|
|
170
|
+
* Creates a new {@link module:engine/view/emptyelement~ViewEmptyElement}.
|
|
170
171
|
*
|
|
171
172
|
* ```ts
|
|
172
173
|
* writer.createEmptyElement( 'img' );
|
|
@@ -181,14 +182,14 @@ export default class DowncastWriter {
|
|
|
181
182
|
* @returns Created element.
|
|
182
183
|
*/
|
|
183
184
|
createEmptyElement(name, attributes, options = {}) {
|
|
184
|
-
const emptyElement = new
|
|
185
|
+
const emptyElement = new ViewEmptyElement(this.document, name, attributes);
|
|
185
186
|
if (options.renderUnsafeAttributes) {
|
|
186
187
|
emptyElement._unsafeAttributesToRender.push(...options.renderUnsafeAttributes);
|
|
187
188
|
}
|
|
188
189
|
return emptyElement;
|
|
189
190
|
}
|
|
190
191
|
/**
|
|
191
|
-
* Creates a new {@link module:engine/view/uielement~
|
|
192
|
+
* Creates a new {@link module:engine/view/uielement~ViewUIElement}.
|
|
192
193
|
*
|
|
193
194
|
* ```ts
|
|
194
195
|
* writer.createUIElement( 'span' );
|
|
@@ -217,14 +218,14 @@ export default class DowncastWriter {
|
|
|
217
218
|
* @returns The created element.
|
|
218
219
|
*/
|
|
219
220
|
createUIElement(name, attributes, renderFunction) {
|
|
220
|
-
const uiElement = new
|
|
221
|
+
const uiElement = new ViewUIElement(this.document, name, attributes);
|
|
221
222
|
if (renderFunction) {
|
|
222
223
|
uiElement.render = renderFunction;
|
|
223
224
|
}
|
|
224
225
|
return uiElement;
|
|
225
226
|
}
|
|
226
227
|
/**
|
|
227
|
-
* Creates a new {@link module:engine/view/rawelement~
|
|
228
|
+
* Creates a new {@link module:engine/view/rawelement~ViewRawElement}.
|
|
228
229
|
*
|
|
229
230
|
* ```ts
|
|
230
231
|
* writer.createRawElement( 'span', { id: 'foo-1234' }, function( domElement ) {
|
|
@@ -238,7 +239,7 @@ export default class DowncastWriter {
|
|
|
238
239
|
* Raw elements are a perfect tool for integration with external frameworks and data sources.
|
|
239
240
|
*
|
|
240
241
|
* Unlike {@link #createUIElement UI elements}, raw elements act like "real" editor content (similar to
|
|
241
|
-
* {@link module:engine/view/containerelement~
|
|
242
|
+
* {@link module:engine/view/containerelement~ViewContainerElement} or {@link module:engine/view/emptyelement~ViewEmptyElement}),
|
|
242
243
|
* and they are considered by the editor selection.
|
|
243
244
|
*
|
|
244
245
|
* You should not use raw elements to render the UI in the editor content. Check out {@link #createUIElement `#createUIElement()`}
|
|
@@ -253,7 +254,7 @@ export default class DowncastWriter {
|
|
|
253
254
|
* @returns The created element.
|
|
254
255
|
*/
|
|
255
256
|
createRawElement(name, attributes, renderFunction, options = {}) {
|
|
256
|
-
const rawElement = new
|
|
257
|
+
const rawElement = new ViewRawElement(this.document, name, attributes);
|
|
257
258
|
if (renderFunction) {
|
|
258
259
|
rawElement.render = renderFunction;
|
|
259
260
|
}
|
|
@@ -351,32 +352,32 @@ export default class DowncastWriter {
|
|
|
351
352
|
* <p><b>fo{o</b><u>ba}r</u></p> -> <p><b>fo</b><b>o</b><u>ba</u><u>r</u></b></p>
|
|
352
353
|
* ```
|
|
353
354
|
*
|
|
354
|
-
* **Note:** {@link module:engine/view/documentfragment~
|
|
355
|
+
* **Note:** {@link module:engine/view/documentfragment~ViewDocumentFragment DocumentFragment} is treated like a container.
|
|
355
356
|
*
|
|
356
|
-
* **Note:** The difference between {@link module:engine/view/downcastwriter~
|
|
357
|
-
* {@link module:engine/view/downcastwriter~
|
|
358
|
-
* {@link module:engine/view/attributeelement~
|
|
359
|
-
* up to the first encountered {@link module:engine/view/containerelement~
|
|
357
|
+
* **Note:** The difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes breakAttributes()} and
|
|
358
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
|
|
359
|
+
* {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} that are ancestors of a given `position`,
|
|
360
|
+
* up to the first encountered {@link module:engine/view/containerelement~ViewContainerElement container element}.
|
|
360
361
|
* `breakContainer()` assumes that a given `position` is directly in the container element and breaks that container element.
|
|
361
362
|
*
|
|
362
363
|
* Throws the `view-writer-invalid-range-container` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
|
|
363
|
-
* when the {@link module:engine/view/range~
|
|
364
|
-
* and {@link module:engine/view/range~
|
|
364
|
+
* when the {@link module:engine/view/range~ViewRange#start start}
|
|
365
|
+
* and {@link module:engine/view/range~ViewRange#end end} positions of a passed range are not placed inside same parent container.
|
|
365
366
|
*
|
|
366
367
|
* Throws the `view-writer-cannot-break-empty-element` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
|
|
367
|
-
* when trying to break attributes inside an {@link module:engine/view/emptyelement~
|
|
368
|
+
* when trying to break attributes inside an {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElement}.
|
|
368
369
|
*
|
|
369
370
|
* Throws the `view-writer-cannot-break-ui-element` {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
|
|
370
|
-
* when trying to break attributes inside a {@link module:engine/view/uielement~
|
|
371
|
+
* when trying to break attributes inside a {@link module:engine/view/uielement~ViewUIElement UIElement}.
|
|
371
372
|
*
|
|
372
|
-
* @see module:engine/view/attributeelement~
|
|
373
|
-
* @see module:engine/view/containerelement~
|
|
374
|
-
* @see module:engine/view/downcastwriter~
|
|
373
|
+
* @see module:engine/view/attributeelement~ViewAttributeElement
|
|
374
|
+
* @see module:engine/view/containerelement~ViewContainerElement
|
|
375
|
+
* @see module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer
|
|
375
376
|
* @param positionOrRange The position where to break attribute elements.
|
|
376
377
|
* @returns The new position or range, after breaking the attribute elements.
|
|
377
378
|
*/
|
|
378
379
|
breakAttributes(positionOrRange) {
|
|
379
|
-
if (positionOrRange instanceof
|
|
380
|
+
if (positionOrRange instanceof ViewPosition) {
|
|
380
381
|
return this._breakAttributes(positionOrRange);
|
|
381
382
|
}
|
|
382
383
|
else {
|
|
@@ -384,7 +385,7 @@ export default class DowncastWriter {
|
|
|
384
385
|
}
|
|
385
386
|
}
|
|
386
387
|
/**
|
|
387
|
-
* Breaks a {@link module:engine/view/containerelement~
|
|
388
|
+
* Breaks a {@link module:engine/view/containerelement~ViewContainerElement container view element} into two, at the given position.
|
|
388
389
|
* The position has to be directly inside the container element and cannot be in the root. It does not break the conrainer view element
|
|
389
390
|
* if the position is at the beginning or at the end of its parent element.
|
|
390
391
|
*
|
|
@@ -395,15 +396,15 @@ export default class DowncastWriter {
|
|
|
395
396
|
* <p>foobar^</p> -> <p>foobar</p>^
|
|
396
397
|
* ```
|
|
397
398
|
*
|
|
398
|
-
* **Note:** The difference between {@link module:engine/view/downcastwriter~
|
|
399
|
-
* {@link module:engine/view/downcastwriter~
|
|
400
|
-
* {@link module:engine/view/attributeelement~
|
|
401
|
-
* up to the first encountered {@link module:engine/view/containerelement~
|
|
399
|
+
* **Note:** The difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes breakAttributes()} and
|
|
400
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
|
|
401
|
+
* {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} that are ancestors of a given `position`,
|
|
402
|
+
* up to the first encountered {@link module:engine/view/containerelement~ViewContainerElement container element}.
|
|
402
403
|
* `breakContainer()` assumes that the given `position` is directly in the container element and breaks that container element.
|
|
403
404
|
*
|
|
404
|
-
* @see module:engine/view/attributeelement~
|
|
405
|
-
* @see module:engine/view/containerelement~
|
|
406
|
-
* @see module:engine/view/downcastwriter~
|
|
405
|
+
* @see module:engine/view/attributeelement~ViewAttributeElement
|
|
406
|
+
* @see module:engine/view/containerelement~ViewContainerElement
|
|
407
|
+
* @see module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes
|
|
407
408
|
* @param position The position where to break the element.
|
|
408
409
|
* @returns The position between broken elements. If an element has not been broken,
|
|
409
410
|
* the returned position is placed either before or after it.
|
|
@@ -427,20 +428,20 @@ export default class DowncastWriter {
|
|
|
427
428
|
throw new CKEditorError('view-writer-break-root', this.document);
|
|
428
429
|
}
|
|
429
430
|
if (position.isAtStart) {
|
|
430
|
-
return
|
|
431
|
+
return ViewPosition._createBefore(element);
|
|
431
432
|
}
|
|
432
433
|
else if (!position.isAtEnd) {
|
|
433
434
|
const newElement = element._clone(false);
|
|
434
|
-
this.insert(
|
|
435
|
-
const sourceRange = new
|
|
436
|
-
const targetPosition = new
|
|
435
|
+
this.insert(ViewPosition._createAfter(element), newElement);
|
|
436
|
+
const sourceRange = new ViewRange(position, ViewPosition._createAt(element, 'end'));
|
|
437
|
+
const targetPosition = new ViewPosition(newElement, 0);
|
|
437
438
|
this.move(sourceRange, targetPosition);
|
|
438
439
|
}
|
|
439
|
-
return
|
|
440
|
+
return ViewPosition._createAfter(element);
|
|
440
441
|
}
|
|
441
442
|
/**
|
|
442
|
-
* Merges {@link module:engine/view/attributeelement~
|
|
443
|
-
* Only {@link module:engine/view/attributeelement~
|
|
443
|
+
* Merges {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements}. It also merges text nodes if needed.
|
|
444
|
+
* Only {@link module:engine/view/attributeelement~ViewAttributeElement#isSimilar similar} attribute elements can be merged.
|
|
444
445
|
*
|
|
445
446
|
* In following examples `<p>` is a container and `<b>` is an attribute element:
|
|
446
447
|
*
|
|
@@ -457,14 +458,15 @@ export default class DowncastWriter {
|
|
|
457
458
|
* <p><b>foo</b><i>[]</i><b>bar</b></p> -> <p><b>foo{}bar</b></p>
|
|
458
459
|
* ```
|
|
459
460
|
*
|
|
460
|
-
* **Note:** Difference between {@link module:engine/view/downcastwriter~
|
|
461
|
-
* {@link module:engine/view/downcastwriter~
|
|
462
|
-
* {@link module:engine/view/attributeelement~
|
|
463
|
-
*
|
|
461
|
+
* **Note:** Difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes mergeAttributes} and
|
|
462
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
|
|
463
|
+
* {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} or
|
|
464
|
+
* {@link module:engine/view/text~ViewText text nodes} while `mergeContainer` merges two
|
|
465
|
+
* {@link module:engine/view/containerelement~ViewContainerElement container elements}.
|
|
464
466
|
*
|
|
465
|
-
* @see module:engine/view/attributeelement~
|
|
466
|
-
* @see module:engine/view/containerelement~
|
|
467
|
-
* @see module:engine/view/downcastwriter~
|
|
467
|
+
* @see module:engine/view/attributeelement~ViewAttributeElement
|
|
468
|
+
* @see module:engine/view/containerelement~ViewContainerElement
|
|
469
|
+
* @see module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers
|
|
468
470
|
* @param position Merge position.
|
|
469
471
|
* @returns Position after merge.
|
|
470
472
|
*/
|
|
@@ -481,7 +483,7 @@ export default class DowncastWriter {
|
|
|
481
483
|
const offset = positionParent.index;
|
|
482
484
|
positionParent._remove();
|
|
483
485
|
this._removeFromClonedElementsGroup(positionParent);
|
|
484
|
-
return this.mergeAttributes(new
|
|
486
|
+
return this.mergeAttributes(new ViewPosition(parent, offset));
|
|
485
487
|
}
|
|
486
488
|
const nodeBefore = positionParent.getChild(positionOffset - 1);
|
|
487
489
|
const nodeAfter = positionParent.getChild(positionOffset);
|
|
@@ -502,27 +504,29 @@ export default class DowncastWriter {
|
|
|
502
504
|
this._removeFromClonedElementsGroup(nodeAfter);
|
|
503
505
|
// New position is located inside the first node, before new nodes.
|
|
504
506
|
// Call this method recursively to merge again if needed.
|
|
505
|
-
return this.mergeAttributes(new
|
|
507
|
+
return this.mergeAttributes(new ViewPosition(nodeBefore, count));
|
|
506
508
|
}
|
|
507
509
|
return position;
|
|
508
510
|
}
|
|
509
511
|
/**
|
|
510
|
-
* Merges two {@link module:engine/view/containerelement~
|
|
511
|
-
* Precisely, the element after the position is removed and it's contents are
|
|
512
|
+
* Merges two {@link module:engine/view/containerelement~ViewContainerElement container elements} that are
|
|
513
|
+
* before and after given position. Precisely, the element after the position is removed and it's contents are
|
|
514
|
+
* moved to element before the position.
|
|
512
515
|
*
|
|
513
516
|
* ```html
|
|
514
517
|
* <p>foo</p>^<p>bar</p> -> <p>foo^bar</p>
|
|
515
518
|
* <div>foo</div>^<p>bar</p> -> <div>foo^bar</div>
|
|
516
519
|
* ```
|
|
517
520
|
*
|
|
518
|
-
* **Note:** Difference between {@link module:engine/view/downcastwriter~
|
|
519
|
-
* {@link module:engine/view/downcastwriter~
|
|
520
|
-
* {@link module:engine/view/attributeelement~
|
|
521
|
-
*
|
|
521
|
+
* **Note:** Difference between {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes mergeAttributes} and
|
|
522
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
|
|
523
|
+
* {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements} or
|
|
524
|
+
* {@link module:engine/view/text~ViewText text nodes} while `mergeContainer` merges two
|
|
525
|
+
* {@link module:engine/view/containerelement~ViewContainerElement container elements}.
|
|
522
526
|
*
|
|
523
|
-
* @see module:engine/view/attributeelement~
|
|
524
|
-
* @see module:engine/view/containerelement~
|
|
525
|
-
* @see module:engine/view/downcastwriter~
|
|
527
|
+
* @see module:engine/view/attributeelement~ViewAttributeElement
|
|
528
|
+
* @see module:engine/view/containerelement~ViewContainerElement
|
|
529
|
+
* @see module:engine/view/downcastwriter~ViewDowncastWriter#mergeAttributes
|
|
526
530
|
* @param position Merge position.
|
|
527
531
|
* @returns Position after merge.
|
|
528
532
|
*/
|
|
@@ -538,9 +542,11 @@ export default class DowncastWriter {
|
|
|
538
542
|
throw new CKEditorError('view-writer-merge-containers-invalid-position', this.document);
|
|
539
543
|
}
|
|
540
544
|
const lastChild = prev.getChild(prev.childCount - 1);
|
|
541
|
-
const newPosition = lastChild instanceof
|
|
542
|
-
|
|
543
|
-
|
|
545
|
+
const newPosition = lastChild instanceof ViewText ?
|
|
546
|
+
ViewPosition._createAt(lastChild, 'end') :
|
|
547
|
+
ViewPosition._createAt(prev, 'end');
|
|
548
|
+
this.move(ViewRange._createIn(next), ViewPosition._createAt(prev, 'end'));
|
|
549
|
+
this.remove(ViewRange._createOn(next));
|
|
544
550
|
return newPosition;
|
|
545
551
|
}
|
|
546
552
|
/**
|
|
@@ -548,12 +554,12 @@ export default class DowncastWriter {
|
|
|
548
554
|
* and merging them afterwards.
|
|
549
555
|
*
|
|
550
556
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-insert-invalid-node` when nodes to insert
|
|
551
|
-
* contains instances that are not {@link module:engine/view/text~
|
|
552
|
-
* {@link module:engine/view/attributeelement~
|
|
553
|
-
* {@link module:engine/view/containerelement~
|
|
554
|
-
* {@link module:engine/view/emptyelement~
|
|
555
|
-
* {@link module:engine/view/rawelement~
|
|
556
|
-
* {@link module:engine/view/uielement~
|
|
557
|
+
* contains instances that are not {@link module:engine/view/text~ViewText Texts},
|
|
558
|
+
* {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElements},
|
|
559
|
+
* {@link module:engine/view/containerelement~ViewContainerElement ViewContainerElements},
|
|
560
|
+
* {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElements},
|
|
561
|
+
* {@link module:engine/view/rawelement~ViewRawElement RawElements} or
|
|
562
|
+
* {@link module:engine/view/uielement~ViewUIElement UIElements}.
|
|
557
563
|
*
|
|
558
564
|
* @param position Insertion position.
|
|
559
565
|
* @param nodes Node or nodes to insert.
|
|
@@ -561,13 +567,13 @@ export default class DowncastWriter {
|
|
|
561
567
|
*/
|
|
562
568
|
insert(position, nodes) {
|
|
563
569
|
nodes = isIterable(nodes) ? [...nodes] : [nodes];
|
|
564
|
-
// Check if nodes to insert are instances of
|
|
570
|
+
// Check if nodes to insert are instances of ViewAttributeElements, ViewContainerElements, ViewEmptyElements, UIElements or Text.
|
|
565
571
|
validateNodesToInsert(nodes, this.document);
|
|
566
|
-
// Group nodes in batches of nodes that require or do not require breaking an
|
|
572
|
+
// Group nodes in batches of nodes that require or do not require breaking an ViewAttributeElements.
|
|
567
573
|
const nodeGroups = nodes.reduce((groups, node) => {
|
|
568
574
|
const lastGroup = groups[groups.length - 1];
|
|
569
575
|
// Break attributes on nodes that do exist in the model tree so they can have attributes, other elements
|
|
570
|
-
// can't have an attribute in model and won't get wrapped with an
|
|
576
|
+
// can't have an attribute in model and won't get wrapped with an ViewAttributeElement while down-casted.
|
|
571
577
|
const breakAttributes = !node.is('uiElement');
|
|
572
578
|
if (!lastGroup || lastGroup.breakAttributes != breakAttributes) {
|
|
573
579
|
groups.push({
|
|
@@ -592,28 +598,28 @@ export default class DowncastWriter {
|
|
|
592
598
|
}
|
|
593
599
|
// When no nodes were inserted - return collapsed range.
|
|
594
600
|
if (!start) {
|
|
595
|
-
return new
|
|
601
|
+
return new ViewRange(position);
|
|
596
602
|
}
|
|
597
|
-
return new
|
|
603
|
+
return new ViewRange(start, end);
|
|
598
604
|
}
|
|
599
605
|
/**
|
|
600
606
|
* Removes provided range from the container.
|
|
601
607
|
*
|
|
602
608
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
|
|
603
|
-
* {@link module:engine/view/range~
|
|
604
|
-
* same parent container.
|
|
609
|
+
* {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
|
|
610
|
+
* positions are not placed inside same parent container.
|
|
605
611
|
*
|
|
606
612
|
* @param rangeOrItem Range to remove from container
|
|
607
|
-
* or an {@link module:engine/view/item~
|
|
613
|
+
* or an {@link module:engine/view/item~ViewItem item} to remove. If range is provided, after removing, it will be updated
|
|
608
614
|
* to a collapsed range showing the new position.
|
|
609
615
|
* @returns Document fragment containing removed nodes.
|
|
610
616
|
*/
|
|
611
617
|
remove(rangeOrItem) {
|
|
612
|
-
const range = rangeOrItem instanceof
|
|
618
|
+
const range = rangeOrItem instanceof ViewRange ? rangeOrItem : ViewRange._createOn(rangeOrItem);
|
|
613
619
|
validateRangeContainer(range, this.document);
|
|
614
620
|
// If range is collapsed - nothing to remove.
|
|
615
621
|
if (range.isCollapsed) {
|
|
616
|
-
return new
|
|
622
|
+
return new ViewDocumentFragment(this.document);
|
|
617
623
|
}
|
|
618
624
|
// Break attributes at range start and end.
|
|
619
625
|
const { start: breakStart, end: breakEnd } = this._breakAttributesRange(range, true);
|
|
@@ -629,14 +635,14 @@ export default class DowncastWriter {
|
|
|
629
635
|
range.start = mergePosition;
|
|
630
636
|
range.end = mergePosition.clone();
|
|
631
637
|
// Return removed nodes.
|
|
632
|
-
return new
|
|
638
|
+
return new ViewDocumentFragment(this.document, removed);
|
|
633
639
|
}
|
|
634
640
|
/**
|
|
635
641
|
* Removes matching elements from given range.
|
|
636
642
|
*
|
|
637
643
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
|
|
638
|
-
* {@link module:engine/view/range~
|
|
639
|
-
* same parent container.
|
|
644
|
+
* {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
|
|
645
|
+
* positions are not placed inside same parent container.
|
|
640
646
|
*
|
|
641
647
|
* @param range Range to clear.
|
|
642
648
|
* @param element Element to remove.
|
|
@@ -656,7 +662,7 @@ export default class DowncastWriter {
|
|
|
656
662
|
// When current item matches to the given element.
|
|
657
663
|
if (item.is('element') && element.isSimilar(item)) {
|
|
658
664
|
// Create range on this element.
|
|
659
|
-
rangeToRemove =
|
|
665
|
+
rangeToRemove = ViewRange._createOn(item);
|
|
660
666
|
// When range starts inside Text or TextProxy element.
|
|
661
667
|
}
|
|
662
668
|
else if (!current.nextPosition.isAfter(range.start) && item.is('$textProxy')) {
|
|
@@ -666,7 +672,7 @@ export default class DowncastWriter {
|
|
|
666
672
|
});
|
|
667
673
|
// If it is then create range inside this element.
|
|
668
674
|
if (parentElement) {
|
|
669
|
-
rangeToRemove =
|
|
675
|
+
rangeToRemove = ViewRange._createIn(parentElement);
|
|
670
676
|
}
|
|
671
677
|
}
|
|
672
678
|
// If we have found element to remove.
|
|
@@ -687,13 +693,13 @@ export default class DowncastWriter {
|
|
|
687
693
|
* Moves nodes from provided range to target position.
|
|
688
694
|
*
|
|
689
695
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
|
|
690
|
-
* {@link module:engine/view/range~
|
|
691
|
-
* same parent container.
|
|
696
|
+
* {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
|
|
697
|
+
* positions are not placed inside same parent container.
|
|
692
698
|
*
|
|
693
699
|
* @param sourceRange Range containing nodes to move.
|
|
694
700
|
* @param targetPosition Position to insert.
|
|
695
701
|
* @returns Range in target container. Inserted nodes are placed between
|
|
696
|
-
* {@link module:engine/view/range~
|
|
702
|
+
* {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end} positions.
|
|
697
703
|
*/
|
|
698
704
|
move(sourceRange, targetPosition) {
|
|
699
705
|
let nodes;
|
|
@@ -711,18 +717,18 @@ export default class DowncastWriter {
|
|
|
711
717
|
return this.insert(targetPosition, nodes);
|
|
712
718
|
}
|
|
713
719
|
/**
|
|
714
|
-
* Wraps elements within range with provided {@link module:engine/view/attributeelement~
|
|
720
|
+
* Wraps elements within range with provided {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
|
|
715
721
|
* If a collapsed range is provided, it will be wrapped only if it is equal to view selection.
|
|
716
722
|
*
|
|
717
723
|
* If a collapsed range was passed and is same as selection, the selection
|
|
718
724
|
* will be moved to the inside of the wrapped attribute element.
|
|
719
725
|
*
|
|
720
726
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-invalid-range-container`
|
|
721
|
-
* when {@link module:engine/view/range~
|
|
722
|
-
* and {@link module:engine/view/range~
|
|
727
|
+
* when {@link module:engine/view/range~ViewRange#start}
|
|
728
|
+
* and {@link module:engine/view/range~ViewRange#end} positions are not placed inside same parent container.
|
|
723
729
|
*
|
|
724
730
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
|
|
725
|
-
* an instance of {@link module:engine/view/attributeelement~
|
|
731
|
+
* an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
|
|
726
732
|
*
|
|
727
733
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-nonselection-collapsed-range` when passed range
|
|
728
734
|
* is collapsed and different than view selection.
|
|
@@ -732,7 +738,7 @@ export default class DowncastWriter {
|
|
|
732
738
|
* @returns range Range after wrapping, spanning over wrapping attribute element.
|
|
733
739
|
*/
|
|
734
740
|
wrap(range, attribute) {
|
|
735
|
-
if (!(attribute instanceof
|
|
741
|
+
if (!(attribute instanceof ViewAttributeElement)) {
|
|
736
742
|
throw new CKEditorError('view-writer-wrap-invalid-attribute', this.document);
|
|
737
743
|
}
|
|
738
744
|
validateRangeContainer(range, this.document);
|
|
@@ -752,21 +758,21 @@ export default class DowncastWriter {
|
|
|
752
758
|
if (viewSelection.isCollapsed && viewSelection.getFirstPosition().isEqual(range.start)) {
|
|
753
759
|
this.setSelection(position);
|
|
754
760
|
}
|
|
755
|
-
return new
|
|
761
|
+
return new ViewRange(position);
|
|
756
762
|
}
|
|
757
763
|
}
|
|
758
764
|
/**
|
|
759
765
|
* Unwraps nodes within provided range from attribute element.
|
|
760
766
|
*
|
|
761
767
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
|
|
762
|
-
* {@link module:engine/view/range~
|
|
763
|
-
* same parent container.
|
|
768
|
+
* {@link module:engine/view/range~ViewRange#start start} and {@link module:engine/view/range~ViewRange#end end}
|
|
769
|
+
* positions are not placed inside same parent container.
|
|
764
770
|
*/
|
|
765
771
|
unwrap(range, attribute) {
|
|
766
|
-
if (!(attribute instanceof
|
|
772
|
+
if (!(attribute instanceof ViewAttributeElement)) {
|
|
767
773
|
/**
|
|
768
|
-
* The `attribute` passed to {@link module:engine/view/downcastwriter~
|
|
769
|
-
* must be an instance of {@link module:engine/view/attributeelement~
|
|
774
|
+
* The `attribute` passed to {@link module:engine/view/downcastwriter~ViewDowncastWriter#unwrap `ViewDowncastWriter#unwrap()`}
|
|
775
|
+
* must be an instance of {@link module:engine/view/attributeelement~ViewAttributeElement `AttributeElement`}.
|
|
770
776
|
*
|
|
771
777
|
* @error view-writer-unwrap-invalid-attribute
|
|
772
778
|
*/
|
|
@@ -789,12 +795,12 @@ export default class DowncastWriter {
|
|
|
789
795
|
newRange.end.offset--;
|
|
790
796
|
}
|
|
791
797
|
const end = this.mergeAttributes(newRange.end);
|
|
792
|
-
return new
|
|
798
|
+
return new ViewRange(start, end);
|
|
793
799
|
}
|
|
794
800
|
/**
|
|
795
801
|
* Renames element by creating a copy of renamed element but with changed name and then moving contents of the
|
|
796
|
-
* old element to the new one. Keep in mind that this will invalidate all {@link module:engine/view/position~
|
|
797
|
-
* has renamed element as {@link module:engine/view/position~
|
|
802
|
+
* old element to the new one. Keep in mind that this will invalidate all {@link module:engine/view/position~ViewPosition positions}
|
|
803
|
+
* which has renamed element as {@link module:engine/view/position~ViewPosition#parent a parent}.
|
|
798
804
|
*
|
|
799
805
|
* New element has to be created because `Element#tagName` property in DOM is readonly.
|
|
800
806
|
*
|
|
@@ -805,17 +811,17 @@ export default class DowncastWriter {
|
|
|
805
811
|
* @returns Element created due to rename.
|
|
806
812
|
*/
|
|
807
813
|
rename(newName, viewElement) {
|
|
808
|
-
const newElement = new
|
|
809
|
-
this.insert(
|
|
810
|
-
this.move(
|
|
811
|
-
this.remove(
|
|
814
|
+
const newElement = new ViewContainerElement(this.document, newName, viewElement.getAttributes());
|
|
815
|
+
this.insert(ViewPosition._createAfter(viewElement), newElement);
|
|
816
|
+
this.move(ViewRange._createIn(viewElement), ViewPosition._createAt(newElement, 0));
|
|
817
|
+
this.remove(ViewRange._createOn(viewElement));
|
|
812
818
|
return newElement;
|
|
813
819
|
}
|
|
814
820
|
/**
|
|
815
821
|
* Cleans up memory by removing obsolete cloned elements group from the writer.
|
|
816
822
|
*
|
|
817
|
-
* Should be used whenever all {@link module:engine/view/attributeelement~
|
|
818
|
-
* with the same {@link module:engine/view/attributeelement~
|
|
823
|
+
* Should be used whenever all {@link module:engine/view/attributeelement~ViewAttributeElement attribute elements}
|
|
824
|
+
* with the same {@link module:engine/view/attributeelement~ViewAttributeElement#id id} are going to be removed from the view and
|
|
819
825
|
* the group will no longer be needed.
|
|
820
826
|
*
|
|
821
827
|
* Cloned elements group are not removed automatically in case if the group is still needed after all its elements
|
|
@@ -831,20 +837,20 @@ export default class DowncastWriter {
|
|
|
831
837
|
/**
|
|
832
838
|
* Creates position at the given location. The location can be specified as:
|
|
833
839
|
*
|
|
834
|
-
* * a {@link module:engine/view/position~
|
|
840
|
+
* * a {@link module:engine/view/position~ViewPosition position},
|
|
835
841
|
* * parent element and offset (offset defaults to `0`),
|
|
836
842
|
* * parent element and `'end'` (sets position at the end of that element),
|
|
837
|
-
* * {@link module:engine/view/item~
|
|
843
|
+
* * {@link module:engine/view/item~ViewItem view item} and `'before'` or `'after'` (sets position before or after given view item).
|
|
838
844
|
*
|
|
839
845
|
* This method is a shortcut to other constructors such as:
|
|
840
846
|
*
|
|
841
847
|
* * {@link #createPositionBefore},
|
|
842
848
|
* * {@link #createPositionAfter},
|
|
843
849
|
*
|
|
844
|
-
* @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~
|
|
850
|
+
* @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~ViewItem view item}.
|
|
845
851
|
*/
|
|
846
852
|
createPositionAt(itemOrPosition, offset) {
|
|
847
|
-
return
|
|
853
|
+
return ViewPosition._createAt(itemOrPosition, offset);
|
|
848
854
|
}
|
|
849
855
|
/**
|
|
850
856
|
* Creates a new position after given view item.
|
|
@@ -852,7 +858,7 @@ export default class DowncastWriter {
|
|
|
852
858
|
* @param item View item after which the position should be located.
|
|
853
859
|
*/
|
|
854
860
|
createPositionAfter(item) {
|
|
855
|
-
return
|
|
861
|
+
return ViewPosition._createAfter(item);
|
|
856
862
|
}
|
|
857
863
|
/**
|
|
858
864
|
* Creates a new position before given view item.
|
|
@@ -860,36 +866,36 @@ export default class DowncastWriter {
|
|
|
860
866
|
* @param item View item before which the position should be located.
|
|
861
867
|
*/
|
|
862
868
|
createPositionBefore(item) {
|
|
863
|
-
return
|
|
869
|
+
return ViewPosition._createBefore(item);
|
|
864
870
|
}
|
|
865
871
|
/**
|
|
866
872
|
* Creates a range spanning from `start` position to `end` position.
|
|
867
873
|
*
|
|
868
|
-
* **Note:** This factory method creates its own {@link module:engine/view/position~
|
|
874
|
+
* **Note:** This factory method creates its own {@link module:engine/view/position~ViewPosition} instances basing on passed values.
|
|
869
875
|
*
|
|
870
876
|
* @param start Start position.
|
|
871
877
|
* @param end End position. If not set, range will be collapsed at `start` position.
|
|
872
878
|
*/
|
|
873
879
|
createRange(start, end) {
|
|
874
|
-
return new
|
|
880
|
+
return new ViewRange(start, end);
|
|
875
881
|
}
|
|
876
882
|
/**
|
|
877
|
-
* Creates a range that starts before given {@link module:engine/view/item~
|
|
883
|
+
* Creates a range that starts before given {@link module:engine/view/item~ViewItem view item} and ends after it.
|
|
878
884
|
*/
|
|
879
885
|
createRangeOn(item) {
|
|
880
|
-
return
|
|
886
|
+
return ViewRange._createOn(item);
|
|
881
887
|
}
|
|
882
888
|
/**
|
|
883
|
-
* Creates a range inside an {@link module:engine/view/element~
|
|
889
|
+
* Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
|
|
884
890
|
* that element and ends after the last child of that element.
|
|
885
891
|
*
|
|
886
892
|
* @param element Element which is a parent for the range.
|
|
887
893
|
*/
|
|
888
894
|
createRangeIn(element) {
|
|
889
|
-
return
|
|
895
|
+
return ViewRange._createIn(element);
|
|
890
896
|
}
|
|
891
897
|
createSelection(...args) {
|
|
892
|
-
return new
|
|
898
|
+
return new ViewSelection(...args);
|
|
893
899
|
}
|
|
894
900
|
/**
|
|
895
901
|
* Creates placeholders for child elements of the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
|
|
@@ -960,7 +966,7 @@ export default class DowncastWriter {
|
|
|
960
966
|
_insertNodes(position, nodes, breakAttributes) {
|
|
961
967
|
let parentElement;
|
|
962
968
|
// Break attributes on nodes that do exist in the model tree so they can have attributes, other elements
|
|
963
|
-
// can't have an attribute in model and won't get wrapped with an
|
|
969
|
+
// can't have an attribute in model and won't get wrapped with an ViewAttributeElement while down-casted.
|
|
964
970
|
if (breakAttributes) {
|
|
965
971
|
parentElement = getParentContainer(position);
|
|
966
972
|
}
|
|
@@ -993,7 +999,7 @@ export default class DowncastWriter {
|
|
|
993
999
|
endPosition.offset--;
|
|
994
1000
|
}
|
|
995
1001
|
const end = this.mergeAttributes(endPosition);
|
|
996
|
-
return new
|
|
1002
|
+
return new ViewRange(start, end);
|
|
997
1003
|
}
|
|
998
1004
|
/**
|
|
999
1005
|
* Wraps children with provided `wrapElement`. Only children contained in `parent` element between
|
|
@@ -1016,7 +1022,7 @@ export default class DowncastWriter {
|
|
|
1016
1022
|
//
|
|
1017
1023
|
if (isAttribute && child._canMergeAttributesFrom(wrapElement)) {
|
|
1018
1024
|
child._mergeAttributesFrom(wrapElement);
|
|
1019
|
-
wrapPositions.push(new
|
|
1025
|
+
wrapPositions.push(new ViewPosition(parent, i));
|
|
1020
1026
|
}
|
|
1021
1027
|
//
|
|
1022
1028
|
// Wrap the child if it is not an attribute element or if it is an attribute element that should be inside
|
|
@@ -1032,7 +1038,7 @@ export default class DowncastWriter {
|
|
|
1032
1038
|
newAttribute._appendChild(child);
|
|
1033
1039
|
parent._insertChild(i, newAttribute);
|
|
1034
1040
|
this._addToClonedElementsGroup(newAttribute);
|
|
1035
|
-
wrapPositions.push(new
|
|
1041
|
+
wrapPositions.push(new ViewPosition(parent, i));
|
|
1036
1042
|
}
|
|
1037
1043
|
//
|
|
1038
1044
|
// If other nested attribute is found and it wasn't wrapped (see above), continue wrapping inside it.
|
|
@@ -1059,7 +1065,7 @@ export default class DowncastWriter {
|
|
|
1059
1065
|
endOffset--;
|
|
1060
1066
|
}
|
|
1061
1067
|
}
|
|
1062
|
-
return
|
|
1068
|
+
return ViewRange._createFromParentsAndOffsets(parent, startOffset, parent, endOffset);
|
|
1063
1069
|
}
|
|
1064
1070
|
/**
|
|
1065
1071
|
* Unwraps children from provided `unwrapElement`. Only children contained in `parent` element between
|
|
@@ -1093,7 +1099,7 @@ export default class DowncastWriter {
|
|
|
1093
1099
|
parent._insertChild(i, unwrapped);
|
|
1094
1100
|
this._removeFromClonedElementsGroup(child);
|
|
1095
1101
|
// Save start and end position of moved items.
|
|
1096
|
-
unwrapPositions.push(new
|
|
1102
|
+
unwrapPositions.push(new ViewPosition(parent, i), new ViewPosition(parent, i + count));
|
|
1097
1103
|
// Skip elements that were unwrapped. Assuming there won't be another element to unwrap in child elements.
|
|
1098
1104
|
i += count;
|
|
1099
1105
|
endOffset += count - 1;
|
|
@@ -1108,7 +1114,7 @@ export default class DowncastWriter {
|
|
|
1108
1114
|
//
|
|
1109
1115
|
if (child._canSubtractAttributesOf(unwrapElement)) {
|
|
1110
1116
|
child._subtractAttributesOf(unwrapElement);
|
|
1111
|
-
unwrapPositions.push(new
|
|
1117
|
+
unwrapPositions.push(new ViewPosition(parent, i), new ViewPosition(parent, i + 1));
|
|
1112
1118
|
i++;
|
|
1113
1119
|
continue;
|
|
1114
1120
|
}
|
|
@@ -1135,14 +1141,14 @@ export default class DowncastWriter {
|
|
|
1135
1141
|
endOffset--;
|
|
1136
1142
|
}
|
|
1137
1143
|
}
|
|
1138
|
-
return
|
|
1144
|
+
return ViewRange._createFromParentsAndOffsets(parent, startOffset, parent, endOffset);
|
|
1139
1145
|
}
|
|
1140
1146
|
/**
|
|
1141
1147
|
* Helper function for `view.writer.wrap`. Wraps range with provided attribute element.
|
|
1142
1148
|
* This method will also merge newly added attribute element with its siblings whenever possible.
|
|
1143
1149
|
*
|
|
1144
1150
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
|
|
1145
|
-
* an instance of {@link module:engine/view/attributeelement~
|
|
1151
|
+
* an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
|
|
1146
1152
|
*
|
|
1147
1153
|
* @returns New range after wrapping, spanning over wrapping attribute element.
|
|
1148
1154
|
*/
|
|
@@ -1159,14 +1165,14 @@ export default class DowncastWriter {
|
|
|
1159
1165
|
newRange.end.offset--;
|
|
1160
1166
|
}
|
|
1161
1167
|
const end = this.mergeAttributes(newRange.end);
|
|
1162
|
-
return new
|
|
1168
|
+
return new ViewRange(start, end);
|
|
1163
1169
|
}
|
|
1164
1170
|
/**
|
|
1165
1171
|
* Helper function for {@link #wrap}. Wraps position with provided attribute element.
|
|
1166
1172
|
* This method will also merge newly added attribute element with its siblings whenever possible.
|
|
1167
1173
|
*
|
|
1168
1174
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
|
|
1169
|
-
* an instance of {@link module:engine/view/attributeelement~
|
|
1175
|
+
* an instance of {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement}.
|
|
1170
1176
|
*
|
|
1171
1177
|
* @returns New position after wrapping.
|
|
1172
1178
|
*/
|
|
@@ -1186,11 +1192,11 @@ export default class DowncastWriter {
|
|
|
1186
1192
|
// Insert fake element in position location.
|
|
1187
1193
|
position.parent._insertChild(position.offset, fakeElement);
|
|
1188
1194
|
// Range around inserted fake attribute element.
|
|
1189
|
-
const wrapRange = new
|
|
1195
|
+
const wrapRange = new ViewRange(position, position.getShiftedBy(1));
|
|
1190
1196
|
// Wrap fake element with attribute (it will also merge if possible).
|
|
1191
1197
|
this.wrap(wrapRange, attribute);
|
|
1192
1198
|
// Remove fake element and place new position there.
|
|
1193
|
-
const newPosition = new
|
|
1199
|
+
const newPosition = new ViewPosition(fakeElement.parent, fakeElement.index);
|
|
1194
1200
|
fakeElement._remove();
|
|
1195
1201
|
// If position is placed between text nodes - merge them and return position inside.
|
|
1196
1202
|
const nodeBefore = newPosition.nodeBefore;
|
|
@@ -1202,7 +1208,7 @@ export default class DowncastWriter {
|
|
|
1202
1208
|
return movePositionToTextNode(newPosition);
|
|
1203
1209
|
}
|
|
1204
1210
|
/**
|
|
1205
|
-
* Helper function used by other `
|
|
1211
|
+
* Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at the boundaries of given range.
|
|
1206
1212
|
*
|
|
1207
1213
|
* @param range Range which `start` and `end` positions will be used to break attributes.
|
|
1208
1214
|
* @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
|
|
@@ -1216,23 +1222,23 @@ export default class DowncastWriter {
|
|
|
1216
1222
|
// Break at the collapsed position. Return new collapsed range.
|
|
1217
1223
|
if (range.isCollapsed) {
|
|
1218
1224
|
const position = this._breakAttributes(range.start, forceSplitText);
|
|
1219
|
-
return new
|
|
1225
|
+
return new ViewRange(position, position);
|
|
1220
1226
|
}
|
|
1221
1227
|
const breakEnd = this._breakAttributes(rangeEnd, forceSplitText);
|
|
1222
1228
|
const count = breakEnd.parent.childCount;
|
|
1223
1229
|
const breakStart = this._breakAttributes(rangeStart, forceSplitText);
|
|
1224
1230
|
// Calculate new break end offset.
|
|
1225
1231
|
breakEnd.offset += breakEnd.parent.childCount - count;
|
|
1226
|
-
return new
|
|
1232
|
+
return new ViewRange(breakStart, breakEnd);
|
|
1227
1233
|
}
|
|
1228
1234
|
/**
|
|
1229
|
-
* Helper function used by other `
|
|
1235
|
+
* Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at given position.
|
|
1230
1236
|
*
|
|
1231
1237
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-empty-element` when break position
|
|
1232
|
-
* is placed inside {@link module:engine/view/emptyelement~
|
|
1238
|
+
* is placed inside {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElement}.
|
|
1233
1239
|
*
|
|
1234
1240
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-ui-element` when break position
|
|
1235
|
-
* is placed inside {@link module:engine/view/uielement~
|
|
1241
|
+
* is placed inside {@link module:engine/view/uielement~ViewUIElement UIElement}.
|
|
1236
1242
|
*
|
|
1237
1243
|
* @param position Position where to break attributes.
|
|
1238
1244
|
* @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
|
|
@@ -1242,13 +1248,13 @@ export default class DowncastWriter {
|
|
|
1242
1248
|
_breakAttributes(position, forceSplitText = false) {
|
|
1243
1249
|
const positionOffset = position.offset;
|
|
1244
1250
|
const positionParent = position.parent;
|
|
1245
|
-
// If position is placed inside
|
|
1251
|
+
// If position is placed inside ViewEmptyElement - throw an exception as we cannot break inside.
|
|
1246
1252
|
if (position.parent.is('emptyElement')) {
|
|
1247
1253
|
/**
|
|
1248
1254
|
* Cannot break an `EmptyElement` instance.
|
|
1249
1255
|
*
|
|
1250
1256
|
* This error is thrown if
|
|
1251
|
-
* {@link module:engine/view/downcastwriter~
|
|
1257
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes `ViewDowncastWriter#breakAttributes()`}
|
|
1252
1258
|
* was executed in an incorrect position.
|
|
1253
1259
|
*
|
|
1254
1260
|
* @error view-writer-cannot-break-empty-element
|
|
@@ -1261,7 +1267,7 @@ export default class DowncastWriter {
|
|
|
1261
1267
|
* Cannot break a `UIElement` instance.
|
|
1262
1268
|
*
|
|
1263
1269
|
* This error is thrown if
|
|
1264
|
-
* {@link module:engine/view/downcastwriter~
|
|
1270
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes `ViewDowncastWriter#breakAttributes()`}
|
|
1265
1271
|
* was executed in an incorrect position.
|
|
1266
1272
|
*
|
|
1267
1273
|
* @error view-writer-cannot-break-ui-element
|
|
@@ -1274,7 +1280,7 @@ export default class DowncastWriter {
|
|
|
1274
1280
|
* Cannot break a `RawElement` instance.
|
|
1275
1281
|
*
|
|
1276
1282
|
* This error is thrown if
|
|
1277
|
-
* {@link module:engine/view/downcastwriter~
|
|
1283
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#breakAttributes `ViewDowncastWriter#breakAttributes()`}
|
|
1278
1284
|
* was executed in an incorrect position.
|
|
1279
1285
|
*
|
|
1280
1286
|
* @error view-writer-cannot-break-raw-element
|
|
@@ -1298,7 +1304,7 @@ export default class DowncastWriter {
|
|
|
1298
1304
|
// <p>foo<b><u>bar</u>[]</b></p>
|
|
1299
1305
|
// <p>foo<b><u>bar</u></b>[]</p>
|
|
1300
1306
|
if (positionOffset == length) {
|
|
1301
|
-
const newPosition = new
|
|
1307
|
+
const newPosition = new ViewPosition(positionParent.parent, positionParent.index + 1);
|
|
1302
1308
|
return this._breakAttributes(newPosition, forceSplitText);
|
|
1303
1309
|
}
|
|
1304
1310
|
else {
|
|
@@ -1306,7 +1312,7 @@ export default class DowncastWriter {
|
|
|
1306
1312
|
// <p>foo<b>[]<u>bar</u></b></p>
|
|
1307
1313
|
// <p>foo{}<b><u>bar</u></b></p>
|
|
1308
1314
|
if (positionOffset === 0) {
|
|
1309
|
-
const newPosition = new
|
|
1315
|
+
const newPosition = new ViewPosition(positionParent.parent, positionParent.index);
|
|
1310
1316
|
return this._breakAttributes(newPosition, forceSplitText);
|
|
1311
1317
|
}
|
|
1312
1318
|
// <p>foo<b><u>b{}ar</u></b></p>
|
|
@@ -1326,19 +1332,19 @@ export default class DowncastWriter {
|
|
|
1326
1332
|
// Move nodes to cloned node.
|
|
1327
1333
|
clonedNode._appendChild(nodesToMove);
|
|
1328
1334
|
// Create new position to work on.
|
|
1329
|
-
const newPosition = new
|
|
1335
|
+
const newPosition = new ViewPosition(positionParent.parent, offsetAfter);
|
|
1330
1336
|
return this._breakAttributes(newPosition, forceSplitText);
|
|
1331
1337
|
}
|
|
1332
1338
|
}
|
|
1333
1339
|
}
|
|
1334
1340
|
/**
|
|
1335
|
-
* Stores the information that an {@link module:engine/view/attributeelement~
|
|
1341
|
+
* Stores the information that an {@link module:engine/view/attributeelement~ViewAttributeElement attribute element} was
|
|
1336
1342
|
* added to the tree. Saves the reference to the group in the given element and updates the group, so other elements
|
|
1337
1343
|
* from the group now keep a reference to the given attribute element.
|
|
1338
1344
|
*
|
|
1339
|
-
* The clones group can be obtained using {@link module:engine/view/attributeelement~
|
|
1345
|
+
* The clones group can be obtained using {@link module:engine/view/attributeelement~ViewAttributeElement#getElementsWithSameId}.
|
|
1340
1346
|
*
|
|
1341
|
-
* Does nothing if added element has no {@link module:engine/view/attributeelement~
|
|
1347
|
+
* Does nothing if added element has no {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
|
|
1342
1348
|
*
|
|
1343
1349
|
* @param element Attribute element to save.
|
|
1344
1350
|
*/
|
|
@@ -1367,13 +1373,13 @@ export default class DowncastWriter {
|
|
|
1367
1373
|
element._clonesGroup = group;
|
|
1368
1374
|
}
|
|
1369
1375
|
/**
|
|
1370
|
-
* Removes all the information about the given {@link module:engine/view/attributeelement~
|
|
1376
|
+
* Removes all the information about the given {@link module:engine/view/attributeelement~ViewAttributeElement attribute element}
|
|
1371
1377
|
* from its clones group.
|
|
1372
1378
|
*
|
|
1373
1379
|
* Keep in mind, that the element will still keep a reference to the group (but the group will not keep a reference to it).
|
|
1374
1380
|
* This allows to reference the whole group even if the element was already removed from the tree.
|
|
1375
1381
|
*
|
|
1376
|
-
* Does nothing if the element has no {@link module:engine/view/attributeelement~
|
|
1382
|
+
* Does nothing if the element has no {@link module:engine/view/attributeelement~ViewAttributeElement#id id}.
|
|
1377
1383
|
*
|
|
1378
1384
|
* @param element Attribute element to remove.
|
|
1379
1385
|
*/
|
|
@@ -1403,15 +1409,15 @@ function _hasNonUiChildren(parent) {
|
|
|
1403
1409
|
return Array.from(parent.getChildren()).some(child => !child.is('uiElement'));
|
|
1404
1410
|
}
|
|
1405
1411
|
/**
|
|
1406
|
-
* The `attribute` passed to {@link module:engine/view/downcastwriter~
|
|
1407
|
-
* must be an instance of {@link module:engine/view/attributeelement~
|
|
1412
|
+
* The `attribute` passed to {@link module:engine/view/downcastwriter~ViewDowncastWriter#wrap `ViewDowncastWriter#wrap()`}
|
|
1413
|
+
* must be an instance of {@link module:engine/view/attributeelement~ViewAttributeElement `AttributeElement`}.
|
|
1408
1414
|
*
|
|
1409
1415
|
* @error view-writer-wrap-invalid-attribute
|
|
1410
1416
|
*/
|
|
1411
1417
|
/**
|
|
1412
|
-
* Returns first parent container of specified {@link module:engine/view/position~
|
|
1418
|
+
* Returns first parent container of specified {@link module:engine/view/position~ViewPosition Position}.
|
|
1413
1419
|
* Position's parent node is checked as first, then next parents are checked.
|
|
1414
|
-
* Note that {@link module:engine/view/documentfragment~
|
|
1420
|
+
* Note that {@link module:engine/view/documentfragment~ViewDocumentFragment DocumentFragment} is treated like a container.
|
|
1415
1421
|
*
|
|
1416
1422
|
* @param position Position used as a start point to locate parent container.
|
|
1417
1423
|
* @returns Parent container element or `undefined` if container is not found.
|
|
@@ -1427,10 +1433,10 @@ function getParentContainer(position) {
|
|
|
1427
1433
|
return parent;
|
|
1428
1434
|
}
|
|
1429
1435
|
/**
|
|
1430
|
-
* Checks if first {@link module:engine/view/attributeelement~
|
|
1436
|
+
* Checks if first {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement} provided to the function
|
|
1431
1437
|
* can be wrapped outside second element. It is done by comparing elements'
|
|
1432
|
-
* {@link module:engine/view/attributeelement~
|
|
1433
|
-
* {@link module:engine/view/element~
|
|
1438
|
+
* {@link module:engine/view/attributeelement~ViewAttributeElement#priority priorities}, if both have same priority
|
|
1439
|
+
* {@link module:engine/view/element~ViewElement#getIdentity identities} are compared.
|
|
1434
1440
|
*/
|
|
1435
1441
|
function shouldABeOutsideB(a, b) {
|
|
1436
1442
|
if (a.priority < b.priority) {
|
|
@@ -1457,11 +1463,11 @@ function shouldABeOutsideB(a, b) {
|
|
|
1457
1463
|
function movePositionToTextNode(position) {
|
|
1458
1464
|
const nodeBefore = position.nodeBefore;
|
|
1459
1465
|
if (nodeBefore && nodeBefore.is('$text')) {
|
|
1460
|
-
return new
|
|
1466
|
+
return new ViewPosition(nodeBefore, nodeBefore.data.length);
|
|
1461
1467
|
}
|
|
1462
1468
|
const nodeAfter = position.nodeAfter;
|
|
1463
1469
|
if (nodeAfter && nodeAfter.is('$text')) {
|
|
1464
|
-
return new
|
|
1470
|
+
return new ViewPosition(nodeAfter, 0);
|
|
1465
1471
|
}
|
|
1466
1472
|
return position;
|
|
1467
1473
|
}
|
|
@@ -1479,19 +1485,19 @@ function movePositionToTextNode(position) {
|
|
|
1479
1485
|
*/
|
|
1480
1486
|
function breakTextNode(position) {
|
|
1481
1487
|
if (position.offset == position.parent.data.length) {
|
|
1482
|
-
return new
|
|
1488
|
+
return new ViewPosition(position.parent.parent, position.parent.index + 1);
|
|
1483
1489
|
}
|
|
1484
1490
|
if (position.offset === 0) {
|
|
1485
|
-
return new
|
|
1491
|
+
return new ViewPosition(position.parent.parent, position.parent.index);
|
|
1486
1492
|
}
|
|
1487
1493
|
// Get part of the text that need to be moved.
|
|
1488
1494
|
const textToMove = position.parent.data.slice(position.offset);
|
|
1489
1495
|
// Leave rest of the text in position's parent.
|
|
1490
1496
|
position.parent._data = position.parent.data.slice(0, position.offset);
|
|
1491
1497
|
// Insert new text node after position's parent text node.
|
|
1492
|
-
position.parent.parent._insertChild(position.parent.index + 1, new
|
|
1498
|
+
position.parent.parent._insertChild(position.parent.index + 1, new ViewText(position.root.document, textToMove));
|
|
1493
1499
|
// Return new position between two newly created text nodes.
|
|
1494
|
-
return new
|
|
1500
|
+
return new ViewPosition(position.parent.parent, position.parent.index + 1);
|
|
1495
1501
|
}
|
|
1496
1502
|
/**
|
|
1497
1503
|
* Merges two text nodes into first node. Removes second node and returns merge position.
|
|
@@ -1505,9 +1511,9 @@ function mergeTextNodes(t1, t2) {
|
|
|
1505
1511
|
const nodeBeforeLength = t1.data.length;
|
|
1506
1512
|
t1._data += t2.data;
|
|
1507
1513
|
t2._remove();
|
|
1508
|
-
return new
|
|
1514
|
+
return new ViewPosition(t1, nodeBeforeLength);
|
|
1509
1515
|
}
|
|
1510
|
-
const validNodesToInsert = [
|
|
1516
|
+
const validNodesToInsert = [ViewText, ViewAttributeElement, ViewContainerElement, ViewEmptyElement, ViewRawElement, ViewUIElement];
|
|
1511
1517
|
/**
|
|
1512
1518
|
* Checks if provided nodes are valid to insert.
|
|
1513
1519
|
*
|
|
@@ -1520,15 +1526,15 @@ function validateNodesToInsert(nodes, errorContext) {
|
|
|
1520
1526
|
/**
|
|
1521
1527
|
* One of the nodes to be inserted is of an invalid type.
|
|
1522
1528
|
*
|
|
1523
|
-
* Nodes to be inserted with {@link module:engine/view/downcastwriter~
|
|
1524
|
-
* of the following types:
|
|
1529
|
+
* Nodes to be inserted with {@link module:engine/view/downcastwriter~ViewDowncastWriter#insert `ViewDowncastWriter#insert()`}
|
|
1530
|
+
* should be of the following types:
|
|
1525
1531
|
*
|
|
1526
|
-
* * {@link module:engine/view/attributeelement~
|
|
1527
|
-
* * {@link module:engine/view/containerelement~
|
|
1528
|
-
* * {@link module:engine/view/emptyelement~
|
|
1529
|
-
* * {@link module:engine/view/uielement~
|
|
1530
|
-
* * {@link module:engine/view/rawelement~
|
|
1531
|
-
* * {@link module:engine/view/text~
|
|
1532
|
+
* * {@link module:engine/view/attributeelement~ViewAttributeElement ViewAttributeElement},
|
|
1533
|
+
* * {@link module:engine/view/containerelement~ViewContainerElement ViewContainerElement},
|
|
1534
|
+
* * {@link module:engine/view/emptyelement~ViewEmptyElement ViewEmptyElement},
|
|
1535
|
+
* * {@link module:engine/view/uielement~ViewUIElement UIElement},
|
|
1536
|
+
* * {@link module:engine/view/rawelement~ViewRawElement RawElement},
|
|
1537
|
+
* * {@link module:engine/view/text~ViewText Text}.
|
|
1532
1538
|
*
|
|
1533
1539
|
* @error view-writer-insert-invalid-node-type
|
|
1534
1540
|
*/
|
|
@@ -1540,16 +1546,16 @@ function validateNodesToInsert(nodes, errorContext) {
|
|
|
1540
1546
|
}
|
|
1541
1547
|
}
|
|
1542
1548
|
/**
|
|
1543
|
-
* Checks if node is
|
|
1549
|
+
* Checks if node is ViewContainerElement or DocumentFragment, because in most cases they should be treated the same way.
|
|
1544
1550
|
*
|
|
1545
|
-
* @returns Returns `true` if node is instance of
|
|
1551
|
+
* @returns Returns `true` if node is instance of ViewContainerElement or DocumentFragment.
|
|
1546
1552
|
*/
|
|
1547
1553
|
function isContainerOrFragment(node) {
|
|
1548
1554
|
return node && (node.is('containerElement') || node.is('documentFragment'));
|
|
1549
1555
|
}
|
|
1550
1556
|
/**
|
|
1551
|
-
* Checks if {@link module:engine/view/range~
|
|
1552
|
-
* inside same {@link module:engine/view/containerelement~
|
|
1557
|
+
* Checks if {@link module:engine/view/range~ViewRange#start range start} and {@link module:engine/view/range~ViewRange#end range end}
|
|
1558
|
+
* are placed inside same {@link module:engine/view/containerelement~ViewContainerElement container element}.
|
|
1553
1559
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when validation fails.
|
|
1554
1560
|
*/
|
|
1555
1561
|
function validateRangeContainer(range, errorContext) {
|
|
@@ -1559,14 +1565,14 @@ function validateRangeContainer(range, errorContext) {
|
|
|
1559
1565
|
/**
|
|
1560
1566
|
* The container of the given range is invalid.
|
|
1561
1567
|
*
|
|
1562
|
-
* This may happen if {@link module:engine/view/range~
|
|
1563
|
-
* {@link module:engine/view/range~
|
|
1568
|
+
* This may happen if {@link module:engine/view/range~ViewRange#start range start} and
|
|
1569
|
+
* {@link module:engine/view/range~ViewRange#end range end} positions are not placed inside the same container element or
|
|
1564
1570
|
* a parent container for these positions cannot be found.
|
|
1565
1571
|
*
|
|
1566
|
-
* Methods like {@link module:engine/view/downcastwriter~
|
|
1567
|
-
* {@link module:engine/view/downcastwriter~
|
|
1568
|
-
* {@link module:engine/view/downcastwriter~
|
|
1569
|
-
* {@link module:engine/view/downcastwriter~
|
|
1572
|
+
* Methods like {@link module:engine/view/downcastwriter~ViewDowncastWriter#wrap `ViewDowncastWriter#remove()`},
|
|
1573
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#wrap `ViewDowncastWriter#clean()`},
|
|
1574
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#wrap `ViewDowncastWriter#wrap()`},
|
|
1575
|
+
* {@link module:engine/view/downcastwriter~ViewDowncastWriter#wrap `ViewDowncastWriter#unwrap()`} need to be called
|
|
1570
1576
|
* on a range that has its start and end positions located in the same container element. Both positions can be
|
|
1571
1577
|
* nested within other elements (e.g. an attribute element) but the closest container ancestor must be the same.
|
|
1572
1578
|
*
|
|
@@ -1575,3 +1581,9 @@ function validateRangeContainer(range, errorContext) {
|
|
|
1575
1581
|
throw new CKEditorError('view-writer-invalid-range-container', errorContext);
|
|
1576
1582
|
}
|
|
1577
1583
|
}
|
|
1584
|
+
/**
|
|
1585
|
+
* Checks if the provided argument is a plain object that can be used as options for container element.
|
|
1586
|
+
*/
|
|
1587
|
+
function isContainerOptions(childrenOrOptions) {
|
|
1588
|
+
return isPlainObject(childrenOrOptions);
|
|
1589
|
+
}
|