@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
package/src/view/element.js
DELETED
|
@@ -1,1053 +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/view/element
|
|
7
|
-
*/
|
|
8
|
-
import { ViewNode } from './node.js';
|
|
9
|
-
import { ViewText } from './text.js';
|
|
10
|
-
import { ViewTextProxy } from './textproxy.js';
|
|
11
|
-
import { isIterable, toMap } from '@ckeditor/ckeditor5-utils';
|
|
12
|
-
import { Matcher, isPatternMatched } from './matcher.js';
|
|
13
|
-
import { StylesMap } from './stylesmap.js';
|
|
14
|
-
import { ViewTokenList } from './tokenlist.js';
|
|
15
|
-
// @if CK_DEBUG_ENGINE // const { convertMapToTags } = require( '../dev-utils/utils' );
|
|
16
|
-
/**
|
|
17
|
-
* View element.
|
|
18
|
-
*
|
|
19
|
-
* The editing engine does not define a fixed semantics of its elements (it is "DTD-free").
|
|
20
|
-
* This is why the type of the {@link module:engine/view/element~ViewElement} need to
|
|
21
|
-
* be defined by the feature developer. When creating an element you should use one of the following methods:
|
|
22
|
-
*
|
|
23
|
-
* * {@link module:engine/view/downcastwriter~ViewDowncastWriter#createContainerElement `downcastWriter#createContainerElement()`}
|
|
24
|
-
* in order to create a {@link module:engine/view/containerelement~ViewContainerElement},
|
|
25
|
-
* * {@link module:engine/view/downcastwriter~ViewDowncastWriter#createAttributeElement `downcastWriter#createAttributeElement()`}
|
|
26
|
-
* in order to create a {@link module:engine/view/attributeelement~ViewAttributeElement},
|
|
27
|
-
* * {@link module:engine/view/downcastwriter~ViewDowncastWriter#createEmptyElement `downcastWriter#createEmptyElement()`}
|
|
28
|
-
* in order to create a {@link module:engine/view/emptyelement~ViewEmptyElement}.
|
|
29
|
-
* * {@link module:engine/view/downcastwriter~ViewDowncastWriter#createUIElement `downcastWriter#createUIElement()`}
|
|
30
|
-
* in order to create a {@link module:engine/view/uielement~ViewUIElement}.
|
|
31
|
-
* * {@link module:engine/view/downcastwriter~ViewDowncastWriter#createEditableElement `downcastWriter#createEditableElement()`}
|
|
32
|
-
* in order to create a {@link module:engine/view/editableelement~ViewEditableElement}.
|
|
33
|
-
*
|
|
34
|
-
* Note that for view elements which are not created from the model, like elements from mutations, paste or
|
|
35
|
-
* {@link module:engine/controller/datacontroller~DataController#set data.set} it is not possible to define the type of the element.
|
|
36
|
-
* In such cases the {@link module:engine/view/upcastwriter~ViewUpcastWriter#createElement `UpcastWriter#createElement()`} method
|
|
37
|
-
* should be used to create generic view elements.
|
|
38
|
-
*/
|
|
39
|
-
export class ViewElement extends ViewNode {
|
|
40
|
-
/**
|
|
41
|
-
* Name of the element.
|
|
42
|
-
*/
|
|
43
|
-
name;
|
|
44
|
-
/**
|
|
45
|
-
* A list of attribute names that should be rendered in the editing pipeline even though filtering mechanisms
|
|
46
|
-
* implemented in the {@link module:engine/view/domconverter~ViewDomConverter} (for instance,
|
|
47
|
-
* {@link module:engine/view/domconverter~ViewDomConverter#shouldRenderAttribute}) would filter them out.
|
|
48
|
-
*
|
|
49
|
-
* These attributes can be specified as an option when the element is created by
|
|
50
|
-
* the {@link module:engine/view/downcastwriter~ViewDowncastWriter}. To check whether an unsafe an attribute should
|
|
51
|
-
* be permitted, use the {@link #shouldRenderUnsafeAttribute} method.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
_unsafeAttributesToRender = [];
|
|
56
|
-
/**
|
|
57
|
-
* Map of attributes, where attributes names are keys and attributes values are values.
|
|
58
|
-
*/
|
|
59
|
-
_attrs;
|
|
60
|
-
/**
|
|
61
|
-
* Array of child nodes.
|
|
62
|
-
*/
|
|
63
|
-
_children;
|
|
64
|
-
/**
|
|
65
|
-
* Map of custom properties.
|
|
66
|
-
* Custom properties can be added to element instance, will be cloned but not rendered into DOM.
|
|
67
|
-
*/
|
|
68
|
-
_customProperties = new Map();
|
|
69
|
-
/**
|
|
70
|
-
* Set of classes associated with element instance.
|
|
71
|
-
*
|
|
72
|
-
* Note that this is just an alias for `this._attrs.get( 'class' );`
|
|
73
|
-
*/
|
|
74
|
-
get _classes() {
|
|
75
|
-
return this._attrs.get('class');
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Normalized styles.
|
|
79
|
-
*
|
|
80
|
-
* Note that this is just an alias for `this._attrs.get( 'style' );`
|
|
81
|
-
*/
|
|
82
|
-
get _styles() {
|
|
83
|
-
return this._attrs.get('style');
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Creates a view element.
|
|
87
|
-
*
|
|
88
|
-
* Attributes can be passed in various formats:
|
|
89
|
-
*
|
|
90
|
-
* ```ts
|
|
91
|
-
* new Element( viewDocument, 'div', { class: 'editor', contentEditable: 'true' } ); // object
|
|
92
|
-
* new Element( viewDocument, 'div', [ [ 'class', 'editor' ], [ 'contentEditable', 'true' ] ] ); // map-like iterator
|
|
93
|
-
* new Element( viewDocument, 'div', mapOfAttributes ); // map
|
|
94
|
-
* ```
|
|
95
|
-
*
|
|
96
|
-
* @internal
|
|
97
|
-
* @param document The document instance to which this element belongs.
|
|
98
|
-
* @param name Node name.
|
|
99
|
-
* @param attrs Collection of attributes.
|
|
100
|
-
* @param children A list of nodes to be inserted into created element.
|
|
101
|
-
*/
|
|
102
|
-
constructor(document, name, attrs, children) {
|
|
103
|
-
super(document);
|
|
104
|
-
this.name = name;
|
|
105
|
-
this._attrs = this._parseAttributes(attrs);
|
|
106
|
-
this._children = [];
|
|
107
|
-
if (children) {
|
|
108
|
-
this._insertChild(0, children);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Number of element's children.
|
|
113
|
-
*/
|
|
114
|
-
get childCount() {
|
|
115
|
-
return this._children.length;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Is `true` if there are no nodes inside this element, `false` otherwise.
|
|
119
|
-
*/
|
|
120
|
-
get isEmpty() {
|
|
121
|
-
return this._children.length === 0;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Gets child at the given index.
|
|
125
|
-
*
|
|
126
|
-
* @param index Index of child.
|
|
127
|
-
* @returns Child node.
|
|
128
|
-
*/
|
|
129
|
-
getChild(index) {
|
|
130
|
-
return this._children[index];
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Gets index of the given child node. Returns `-1` if child node is not found.
|
|
134
|
-
*
|
|
135
|
-
* @param node Child node.
|
|
136
|
-
* @returns Index of the child node.
|
|
137
|
-
*/
|
|
138
|
-
getChildIndex(node) {
|
|
139
|
-
return this._children.indexOf(node);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Gets child nodes iterator.
|
|
143
|
-
*
|
|
144
|
-
* @returns Child nodes iterator.
|
|
145
|
-
*/
|
|
146
|
-
getChildren() {
|
|
147
|
-
return this._children[Symbol.iterator]();
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Returns an iterator that contains the keys for attributes. Order of inserting attributes is not preserved.
|
|
151
|
-
*
|
|
152
|
-
* @returns Keys for attributes.
|
|
153
|
-
*/
|
|
154
|
-
*getAttributeKeys() {
|
|
155
|
-
// This is yielded in this specific order to maintain backward compatibility of data.
|
|
156
|
-
// Otherwise, we could simply just have the `for` loop only inside this method.
|
|
157
|
-
if (this._classes) {
|
|
158
|
-
yield 'class';
|
|
159
|
-
}
|
|
160
|
-
if (this._styles) {
|
|
161
|
-
yield 'style';
|
|
162
|
-
}
|
|
163
|
-
for (const key of this._attrs.keys()) {
|
|
164
|
-
if (key != 'class' && key != 'style') {
|
|
165
|
-
yield key;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Returns iterator that iterates over this element's attributes.
|
|
171
|
-
*
|
|
172
|
-
* Attributes are returned as arrays containing two items. First one is attribute key and second is attribute value.
|
|
173
|
-
* This format is accepted by native `Map` object and also can be passed in `Node` constructor.
|
|
174
|
-
*/
|
|
175
|
-
*getAttributes() {
|
|
176
|
-
for (const [name, value] of this._attrs.entries()) {
|
|
177
|
-
yield [name, String(value)];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Gets attribute by key. If attribute is not present - returns undefined.
|
|
182
|
-
*
|
|
183
|
-
* @param key Attribute key.
|
|
184
|
-
* @returns Attribute value.
|
|
185
|
-
*/
|
|
186
|
-
getAttribute(key) {
|
|
187
|
-
return this._attrs.has(key) ? String(this._attrs.get(key)) : undefined;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Returns a boolean indicating whether an attribute with the specified key exists in the element.
|
|
191
|
-
*
|
|
192
|
-
* @param key Attribute key.
|
|
193
|
-
* @returns `true` if attribute with the specified key exists in the element, `false` otherwise.
|
|
194
|
-
*/
|
|
195
|
-
hasAttribute(key, token) {
|
|
196
|
-
if (!this._attrs.has(key)) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
if (token !== undefined) {
|
|
200
|
-
if (usesStylesMap(this.name, key) || usesTokenList(this.name, key)) {
|
|
201
|
-
return this._attrs.get(key).has(token);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
return this._attrs.get(key) === token;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Checks if this element is similar to other element.
|
|
211
|
-
* Both elements should have the same name and attributes to be considered as similar. Two similar elements
|
|
212
|
-
* can contain different set of children nodes.
|
|
213
|
-
*/
|
|
214
|
-
isSimilar(otherElement) {
|
|
215
|
-
if (!(otherElement instanceof ViewElement)) {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
// If exactly the same Element is provided - return true immediately.
|
|
219
|
-
if (this === otherElement) {
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
// Check element name.
|
|
223
|
-
if (this.name != otherElement.name) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
// Check number of attributes, classes and styles.
|
|
227
|
-
if (this._attrs.size !== otherElement._attrs.size) {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
// Check if attributes are the same.
|
|
231
|
-
for (const [key, value] of this._attrs) {
|
|
232
|
-
const otherValue = otherElement._attrs.get(key);
|
|
233
|
-
if (otherValue === undefined) {
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
if (typeof value == 'string' || typeof otherValue == 'string') {
|
|
237
|
-
if (otherValue !== value) {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else if (!value.isSimilar(otherValue)) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Returns true if class is present.
|
|
249
|
-
* If more then one class is provided - returns true only when all classes are present.
|
|
250
|
-
*
|
|
251
|
-
* ```ts
|
|
252
|
-
* element.hasClass( 'foo' ); // Returns true if 'foo' class is present.
|
|
253
|
-
* element.hasClass( 'foo', 'bar' ); // Returns true if 'foo' and 'bar' classes are both present.
|
|
254
|
-
* ```
|
|
255
|
-
*/
|
|
256
|
-
hasClass(...className) {
|
|
257
|
-
for (const name of className) {
|
|
258
|
-
if (!this._classes || !this._classes.has(name)) {
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return true;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Returns iterator that contains all class names.
|
|
266
|
-
*/
|
|
267
|
-
getClassNames() {
|
|
268
|
-
const array = this._classes ? this._classes.keys() : [];
|
|
269
|
-
// This is overcomplicated because we need to be backward compatible for use cases when iterator is expected.
|
|
270
|
-
const iterator = array[Symbol.iterator]();
|
|
271
|
-
return Object.assign(array, {
|
|
272
|
-
next: iterator.next.bind(iterator)
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Returns style value for the given property name.
|
|
277
|
-
* If the style does not exist `undefined` is returned.
|
|
278
|
-
*
|
|
279
|
-
* **Note**: This method can work with normalized style names if
|
|
280
|
-
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
281
|
-
* See {@link module:engine/view/stylesmap~StylesMap#getAsString `StylesMap#getAsString()`} for details.
|
|
282
|
-
*
|
|
283
|
-
* For an element with style set to `'margin:1px'`:
|
|
284
|
-
*
|
|
285
|
-
* ```ts
|
|
286
|
-
* // Enable 'margin' shorthand processing:
|
|
287
|
-
* editor.data.addStyleProcessorRules( addMarginStylesRules );
|
|
288
|
-
*
|
|
289
|
-
* const element = view.change( writer => {
|
|
290
|
-
* const element = writer.createElement();
|
|
291
|
-
* writer.setStyle( 'margin', '1px' );
|
|
292
|
-
* writer.setStyle( 'margin-bottom', '3em' );
|
|
293
|
-
*
|
|
294
|
-
* return element;
|
|
295
|
-
* } );
|
|
296
|
-
*
|
|
297
|
-
* element.getStyle( 'margin' ); // -> 'margin: 1px 1px 3em;'
|
|
298
|
-
* ```
|
|
299
|
-
*/
|
|
300
|
-
getStyle(property) {
|
|
301
|
-
return this._styles && this._styles.getAsString(property);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Returns a normalized style object or single style value.
|
|
305
|
-
*
|
|
306
|
-
* For an element with style set to: margin:1px 2px 3em;
|
|
307
|
-
*
|
|
308
|
-
* ```ts
|
|
309
|
-
* element.getNormalizedStyle( 'margin' ) );
|
|
310
|
-
* ```
|
|
311
|
-
*
|
|
312
|
-
* will return:
|
|
313
|
-
*
|
|
314
|
-
* ```ts
|
|
315
|
-
* {
|
|
316
|
-
* top: '1px',
|
|
317
|
-
* right: '2px',
|
|
318
|
-
* bottom: '3em',
|
|
319
|
-
* left: '2px' // a normalized value from margin shorthand
|
|
320
|
-
* }
|
|
321
|
-
* ```
|
|
322
|
-
*
|
|
323
|
-
* and reading for single style value:
|
|
324
|
-
*
|
|
325
|
-
* ```ts
|
|
326
|
-
* styles.getNormalizedStyle( 'margin-left' );
|
|
327
|
-
* ```
|
|
328
|
-
*
|
|
329
|
-
* Will return a `2px` string.
|
|
330
|
-
*
|
|
331
|
-
* **Note**: This method will return normalized values only if
|
|
332
|
-
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
333
|
-
* See {@link module:engine/view/stylesmap~StylesMap#getNormalized `StylesMap#getNormalized()`} for details.
|
|
334
|
-
*
|
|
335
|
-
* @param property Name of CSS property
|
|
336
|
-
*/
|
|
337
|
-
getNormalizedStyle(property) {
|
|
338
|
-
return this._styles && this._styles.getNormalized(property);
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Returns an array that contains all style names.
|
|
342
|
-
*
|
|
343
|
-
* @param expand Expand shorthand style properties and return all equivalent style representations.
|
|
344
|
-
*/
|
|
345
|
-
getStyleNames(expand) {
|
|
346
|
-
return this._styles ? this._styles.getStyleNames(expand) : [];
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Returns true if style keys are present.
|
|
350
|
-
* If more then one style property is provided - returns true only when all properties are present.
|
|
351
|
-
*
|
|
352
|
-
* ```ts
|
|
353
|
-
* element.hasStyle( 'color' ); // Returns true if 'border-top' style is present.
|
|
354
|
-
* element.hasStyle( 'color', 'border-top' ); // Returns true if 'color' and 'border-top' styles are both present.
|
|
355
|
-
* ```
|
|
356
|
-
*/
|
|
357
|
-
hasStyle(...property) {
|
|
358
|
-
for (const name of property) {
|
|
359
|
-
if (!this._styles || !this._styles.has(name)) {
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Returns ancestor element that match specified pattern.
|
|
367
|
-
* Provided patterns should be compatible with {@link module:engine/view/matcher~Matcher Matcher} as it is used internally.
|
|
368
|
-
*
|
|
369
|
-
* @see module:engine/view/matcher~Matcher
|
|
370
|
-
* @param patterns Patterns used to match correct ancestor. See {@link module:engine/view/matcher~Matcher}.
|
|
371
|
-
* @returns Found element or `null` if no matching ancestor was found.
|
|
372
|
-
*/
|
|
373
|
-
findAncestor(...patterns) {
|
|
374
|
-
const matcher = new Matcher(...patterns);
|
|
375
|
-
let parent = this.parent;
|
|
376
|
-
while (parent && !parent.is('documentFragment')) {
|
|
377
|
-
if (matcher.match(parent)) {
|
|
378
|
-
return parent;
|
|
379
|
-
}
|
|
380
|
-
parent = parent.parent;
|
|
381
|
-
}
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Returns the custom property value for the given key.
|
|
386
|
-
*/
|
|
387
|
-
getCustomProperty(key) {
|
|
388
|
-
return this._customProperties.get(key);
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Returns an iterator which iterates over this element's custom properties.
|
|
392
|
-
* Iterator provides `[ key, value ]` pairs for each stored property.
|
|
393
|
-
*/
|
|
394
|
-
*getCustomProperties() {
|
|
395
|
-
yield* this._customProperties.entries();
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Returns identity string based on element's name, styles, classes and other attributes.
|
|
399
|
-
* Two elements that {@link #isSimilar are similar} will have same identity string.
|
|
400
|
-
* It has the following format:
|
|
401
|
-
*
|
|
402
|
-
* ```ts
|
|
403
|
-
* 'name class="class1,class2" style="style1:value1;style2:value2" attr1="val1" attr2="val2"'
|
|
404
|
-
* ```
|
|
405
|
-
*
|
|
406
|
-
* For example:
|
|
407
|
-
*
|
|
408
|
-
* ```ts
|
|
409
|
-
* const element = writer.createContainerElement( 'foo', {
|
|
410
|
-
* banana: '10',
|
|
411
|
-
* apple: '20',
|
|
412
|
-
* style: 'color: red; border-color: white;',
|
|
413
|
-
* class: 'baz'
|
|
414
|
-
* } );
|
|
415
|
-
*
|
|
416
|
-
* // returns 'foo class="baz" style="border-color:white;color:red" apple="20" banana="10"'
|
|
417
|
-
* element.getIdentity();
|
|
418
|
-
* ```
|
|
419
|
-
*
|
|
420
|
-
* **Note**: Classes, styles and other attributes are sorted alphabetically.
|
|
421
|
-
*/
|
|
422
|
-
getIdentity() {
|
|
423
|
-
const classes = this._classes ? this._classes.keys().sort().join(',') : '';
|
|
424
|
-
const styles = this._styles && String(this._styles);
|
|
425
|
-
const attributes = Array.from(this._attrs)
|
|
426
|
-
.filter(([key]) => key != 'style' && key != 'class')
|
|
427
|
-
.map(i => `${i[0]}="${i[1]}"`)
|
|
428
|
-
.sort().join(' ');
|
|
429
|
-
return this.name +
|
|
430
|
-
(classes == '' ? '' : ` class="${classes}"`) +
|
|
431
|
-
(!styles ? '' : ` style="${styles}"`) +
|
|
432
|
-
(attributes == '' ? '' : ` ${attributes}`);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Decides whether an unsafe attribute is whitelisted and should be rendered in the editing pipeline even though filtering mechanisms
|
|
436
|
-
* like {@link module:engine/view/domconverter~ViewDomConverter#shouldRenderAttribute} say it should not.
|
|
437
|
-
*
|
|
438
|
-
* Unsafe attribute names can be specified when creating an element via {@link module:engine/view/downcastwriter~ViewDowncastWriter}.
|
|
439
|
-
*
|
|
440
|
-
* @param attributeName The name of the attribute to be checked.
|
|
441
|
-
*/
|
|
442
|
-
shouldRenderUnsafeAttribute(attributeName) {
|
|
443
|
-
return this._unsafeAttributesToRender.includes(attributeName);
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Converts `ViewElement` to plain object and returns it.
|
|
447
|
-
*
|
|
448
|
-
* @returns `ViewElement` converted to plain object.
|
|
449
|
-
*/
|
|
450
|
-
toJSON() {
|
|
451
|
-
const json = super.toJSON();
|
|
452
|
-
json.name = this.name;
|
|
453
|
-
json.type = 'Element';
|
|
454
|
-
if (this._attrs.size) {
|
|
455
|
-
json.attributes = Object.fromEntries(this.getAttributes());
|
|
456
|
-
}
|
|
457
|
-
if (this._children.length > 0) {
|
|
458
|
-
json.children = [];
|
|
459
|
-
for (const node of this._children) {
|
|
460
|
-
json.children.push(node.toJSON());
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return json;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Clones provided element.
|
|
467
|
-
*
|
|
468
|
-
* @internal
|
|
469
|
-
* @param deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
470
|
-
* element will be cloned without any children.
|
|
471
|
-
* @returns Clone of this element.
|
|
472
|
-
*/
|
|
473
|
-
_clone(deep = false) {
|
|
474
|
-
const childrenClone = [];
|
|
475
|
-
if (deep) {
|
|
476
|
-
for (const child of this.getChildren()) {
|
|
477
|
-
childrenClone.push(child._clone(deep));
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
// ViewContainerElement and ViewAttributeElement should be also cloned properly.
|
|
481
|
-
const cloned = new this.constructor(this.document, this.name, this._attrs, childrenClone);
|
|
482
|
-
// Clone custom properties.
|
|
483
|
-
cloned._customProperties = new Map(this._customProperties);
|
|
484
|
-
// Clone filler offset method.
|
|
485
|
-
// We can't define this method in a prototype because it's behavior which
|
|
486
|
-
// is changed by e.g. toWidget() function from ckeditor5-widget. Perhaps this should be one of custom props.
|
|
487
|
-
cloned.getFillerOffset = this.getFillerOffset;
|
|
488
|
-
// Clone unsafe attributes list.
|
|
489
|
-
cloned._unsafeAttributesToRender = this._unsafeAttributesToRender;
|
|
490
|
-
return cloned;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* {@link module:engine/view/element~ViewElement#_insertChild Insert} a child node or a list of child nodes at the end of this node
|
|
494
|
-
* and sets the parent of these nodes to this element.
|
|
495
|
-
*
|
|
496
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#insert
|
|
497
|
-
* @internal
|
|
498
|
-
* @param items Items to be inserted.
|
|
499
|
-
* @fires change
|
|
500
|
-
* @returns Number of appended nodes.
|
|
501
|
-
*/
|
|
502
|
-
_appendChild(items) {
|
|
503
|
-
return this._insertChild(this.childCount, items);
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Inserts a child node or a list of child nodes on the given index and sets the parent of these nodes to
|
|
507
|
-
* this element.
|
|
508
|
-
*
|
|
509
|
-
* @internal
|
|
510
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#insert
|
|
511
|
-
* @param index Position where nodes should be inserted.
|
|
512
|
-
* @param items Items to be inserted.
|
|
513
|
-
* @fires change
|
|
514
|
-
* @returns Number of inserted nodes.
|
|
515
|
-
*/
|
|
516
|
-
_insertChild(index, items) {
|
|
517
|
-
this._fireChange('children', this, { index });
|
|
518
|
-
let count = 0;
|
|
519
|
-
const nodes = normalize(this.document, items);
|
|
520
|
-
for (const node of nodes) {
|
|
521
|
-
// If node that is being added to this element is already inside another element, first remove it from the old parent.
|
|
522
|
-
if (node.parent !== null) {
|
|
523
|
-
node._remove();
|
|
524
|
-
}
|
|
525
|
-
node.parent = this;
|
|
526
|
-
node.document = this.document;
|
|
527
|
-
this._children.splice(index, 0, node);
|
|
528
|
-
index++;
|
|
529
|
-
count++;
|
|
530
|
-
}
|
|
531
|
-
return count;
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Removes number of child nodes starting at the given index and set the parent of these nodes to `null`.
|
|
535
|
-
*
|
|
536
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#remove
|
|
537
|
-
* @internal
|
|
538
|
-
* @param index Number of the first node to remove.
|
|
539
|
-
* @param howMany Number of nodes to remove.
|
|
540
|
-
* @fires change
|
|
541
|
-
* @returns The array of removed nodes.
|
|
542
|
-
*/
|
|
543
|
-
_removeChildren(index, howMany = 1) {
|
|
544
|
-
this._fireChange('children', this, { index });
|
|
545
|
-
for (let i = index; i < index + howMany; i++) {
|
|
546
|
-
this._children[i].parent = null;
|
|
547
|
-
}
|
|
548
|
-
return this._children.splice(index, howMany);
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Adds or overwrite attribute with a specified key and value.
|
|
552
|
-
*
|
|
553
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#setAttribute
|
|
554
|
-
* @internal
|
|
555
|
-
* @param key Attribute key.
|
|
556
|
-
* @param value Attribute value.
|
|
557
|
-
* @param overwrite Whether tokenized attribute should override the attribute value or just add a token.
|
|
558
|
-
* @fires change
|
|
559
|
-
*/
|
|
560
|
-
_setAttribute(key, value, overwrite = true) {
|
|
561
|
-
this._fireChange('attributes', this);
|
|
562
|
-
if (usesStylesMap(this.name, key) || usesTokenList(this.name, key)) {
|
|
563
|
-
let currentValue = this._attrs.get(key);
|
|
564
|
-
if (!currentValue) {
|
|
565
|
-
currentValue = usesStylesMap(this.name, key) ?
|
|
566
|
-
new StylesMap(this.document.stylesProcessor) :
|
|
567
|
-
new ViewTokenList();
|
|
568
|
-
this._attrs.set(key, currentValue);
|
|
569
|
-
}
|
|
570
|
-
if (overwrite) {
|
|
571
|
-
// If reset is set then value have to be a string to tokenize.
|
|
572
|
-
currentValue.setTo(String(value));
|
|
573
|
-
}
|
|
574
|
-
else if (usesStylesMap(this.name, key)) {
|
|
575
|
-
if (Array.isArray(value)) {
|
|
576
|
-
currentValue.set(value[0], value[1]);
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
currentValue.set(value);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
else { // TokenList.
|
|
583
|
-
currentValue.set(typeof value == 'string' ? value.split(/\s+/) : value);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
this._attrs.set(key, String(value));
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* Removes attribute from the element.
|
|
592
|
-
*
|
|
593
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#removeAttribute
|
|
594
|
-
* @internal
|
|
595
|
-
* @param key Attribute key.
|
|
596
|
-
* @param tokens Attribute value tokens to remove. The whole attribute is removed if not specified.
|
|
597
|
-
* @returns Returns true if an attribute existed and has been removed.
|
|
598
|
-
* @fires change
|
|
599
|
-
*/
|
|
600
|
-
_removeAttribute(key, tokens) {
|
|
601
|
-
this._fireChange('attributes', this);
|
|
602
|
-
if (tokens !== undefined && (usesStylesMap(this.name, key) || usesTokenList(this.name, key))) {
|
|
603
|
-
const currentValue = this._attrs.get(key);
|
|
604
|
-
if (!currentValue) {
|
|
605
|
-
return false;
|
|
606
|
-
}
|
|
607
|
-
if (usesTokenList(this.name, key) && typeof tokens == 'string') {
|
|
608
|
-
tokens = tokens.split(/\s+/);
|
|
609
|
-
}
|
|
610
|
-
currentValue.remove(tokens);
|
|
611
|
-
if (currentValue.isEmpty) {
|
|
612
|
-
return this._attrs.delete(key);
|
|
613
|
-
}
|
|
614
|
-
return false;
|
|
615
|
-
}
|
|
616
|
-
return this._attrs.delete(key);
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* Adds specified class.
|
|
620
|
-
*
|
|
621
|
-
* ```ts
|
|
622
|
-
* element._addClass( 'foo' ); // Adds 'foo' class.
|
|
623
|
-
* element._addClass( [ 'foo', 'bar' ] ); // Adds 'foo' and 'bar' classes.
|
|
624
|
-
* ```
|
|
625
|
-
*
|
|
626
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#addClass
|
|
627
|
-
* @internal
|
|
628
|
-
* @fires change
|
|
629
|
-
*/
|
|
630
|
-
_addClass(className) {
|
|
631
|
-
this._setAttribute('class', className, false);
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Removes specified class.
|
|
635
|
-
*
|
|
636
|
-
* ```ts
|
|
637
|
-
* element._removeClass( 'foo' ); // Removes 'foo' class.
|
|
638
|
-
* element._removeClass( [ 'foo', 'bar' ] ); // Removes both 'foo' and 'bar' classes.
|
|
639
|
-
* ```
|
|
640
|
-
*
|
|
641
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#removeClass
|
|
642
|
-
* @internal
|
|
643
|
-
* @fires change
|
|
644
|
-
*/
|
|
645
|
-
_removeClass(className) {
|
|
646
|
-
this._removeAttribute('class', className);
|
|
647
|
-
}
|
|
648
|
-
_setStyle(property, value) {
|
|
649
|
-
if (typeof property != 'string') {
|
|
650
|
-
this._setAttribute('style', property, false);
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
this._setAttribute('style', [property, value], false);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Removes specified style.
|
|
658
|
-
*
|
|
659
|
-
* ```ts
|
|
660
|
-
* element._removeStyle( 'color' ); // Removes 'color' style.
|
|
661
|
-
* element._removeStyle( [ 'color', 'border-top' ] ); // Removes both 'color' and 'border-top' styles.
|
|
662
|
-
* ```
|
|
663
|
-
*
|
|
664
|
-
* **Note**: This method can work with normalized style names if
|
|
665
|
-
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
666
|
-
* See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
|
|
667
|
-
*
|
|
668
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#removeStyle
|
|
669
|
-
* @internal
|
|
670
|
-
* @fires change
|
|
671
|
-
*/
|
|
672
|
-
_removeStyle(property) {
|
|
673
|
-
this._removeAttribute('style', property);
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Used by the {@link module:engine/view/matcher~Matcher Matcher} to collect matching attribute tuples
|
|
677
|
-
* (attribute name and optional token).
|
|
678
|
-
*
|
|
679
|
-
* Normalized patterns can be used in following ways:
|
|
680
|
-
* - to match any attribute name with any or no value:
|
|
681
|
-
*
|
|
682
|
-
* ```ts
|
|
683
|
-
* patterns: [
|
|
684
|
-
* [ true, true ]
|
|
685
|
-
* ]
|
|
686
|
-
* ```
|
|
687
|
-
*
|
|
688
|
-
* - to match a specific attribute with any value:
|
|
689
|
-
*
|
|
690
|
-
* ```ts
|
|
691
|
-
* patterns: [
|
|
692
|
-
* [ 'required', true ]
|
|
693
|
-
* ]
|
|
694
|
-
* ```
|
|
695
|
-
*
|
|
696
|
-
* - to match an attribute name with a RegExp with any value:
|
|
697
|
-
*
|
|
698
|
-
* ```ts
|
|
699
|
-
* patterns: [
|
|
700
|
-
* [ /h[1-6]/, true ]
|
|
701
|
-
* ]
|
|
702
|
-
* ```
|
|
703
|
-
*
|
|
704
|
-
* - to match a specific attribute with the exact value:
|
|
705
|
-
*
|
|
706
|
-
* ```ts
|
|
707
|
-
* patterns: [
|
|
708
|
-
* [ 'rel', 'nofollow' ]
|
|
709
|
-
* ]
|
|
710
|
-
* ```
|
|
711
|
-
*
|
|
712
|
-
* - to match a specific attribute with a value matching a RegExp:
|
|
713
|
-
*
|
|
714
|
-
* ```ts
|
|
715
|
-
* patterns: [
|
|
716
|
-
* [ 'src', /^https/ ]
|
|
717
|
-
* ]
|
|
718
|
-
* ```
|
|
719
|
-
*
|
|
720
|
-
* - to match an attribute name with a RegExp and the exact value:
|
|
721
|
-
*
|
|
722
|
-
* ```ts
|
|
723
|
-
* patterns: [
|
|
724
|
-
* [ /^data-property-/, 'foobar' ],
|
|
725
|
-
* ]
|
|
726
|
-
* ```
|
|
727
|
-
*
|
|
728
|
-
* - to match an attribute name with a RegExp and match a value with another RegExp:
|
|
729
|
-
*
|
|
730
|
-
* ```ts
|
|
731
|
-
* patterns: [
|
|
732
|
-
* [ /^data-property-/, /^foo/ ]
|
|
733
|
-
* ]
|
|
734
|
-
* ```
|
|
735
|
-
*
|
|
736
|
-
* - to match a specific style property with the value matching a RegExp:
|
|
737
|
-
*
|
|
738
|
-
* ```ts
|
|
739
|
-
* patterns: [
|
|
740
|
-
* [ 'style', 'font-size', /px$/ ]
|
|
741
|
-
* ]
|
|
742
|
-
* ```
|
|
743
|
-
*
|
|
744
|
-
* - to match a specific class (class attribute is tokenized so it matches tokens individually):
|
|
745
|
-
*
|
|
746
|
-
* ```ts
|
|
747
|
-
* patterns: [
|
|
748
|
-
* [ 'class', 'foo' ]
|
|
749
|
-
* ]
|
|
750
|
-
* ```
|
|
751
|
-
*
|
|
752
|
-
* @internal
|
|
753
|
-
* @param patterns An array of normalized patterns (tuples of 2 or 3 items depending on if tokenized attribute value match is needed).
|
|
754
|
-
* @param match An array to populate with matching tuples.
|
|
755
|
-
* @param exclude Array of attribute names to exclude from match.
|
|
756
|
-
* @returns `true` if element matches all patterns. The matching tuples are pushed to the `match` array.
|
|
757
|
-
*/
|
|
758
|
-
_collectAttributesMatch(patterns, match, exclude) {
|
|
759
|
-
for (const [keyPattern, tokenPattern, valuePattern] of patterns) {
|
|
760
|
-
let hasKey = false;
|
|
761
|
-
let hasValue = false;
|
|
762
|
-
for (const [key, value] of this._attrs) {
|
|
763
|
-
if (exclude && exclude.includes(key) || !isPatternMatched(keyPattern, key)) {
|
|
764
|
-
continue;
|
|
765
|
-
}
|
|
766
|
-
hasKey = true;
|
|
767
|
-
if (typeof value == 'string') {
|
|
768
|
-
if (isPatternMatched(tokenPattern, value)) {
|
|
769
|
-
match.push([key]);
|
|
770
|
-
hasValue = true;
|
|
771
|
-
}
|
|
772
|
-
else if (!(keyPattern instanceof RegExp)) {
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
const tokenMatch = value._getTokensMatch(tokenPattern, valuePattern || true);
|
|
778
|
-
if (tokenMatch) {
|
|
779
|
-
hasValue = true;
|
|
780
|
-
for (const tokenMatchItem of tokenMatch) {
|
|
781
|
-
match.push([key, tokenMatchItem]);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
else if (!(keyPattern instanceof RegExp)) {
|
|
785
|
-
return false;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
if (!hasKey || !hasValue) {
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
return true;
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* Used by the {@link module:engine/conversion/viewconsumable~ViewConsumable} to collect the
|
|
797
|
-
* {@link module:engine/view/element~ViewNormalizedConsumables} for the element.
|
|
798
|
-
*
|
|
799
|
-
* When `key` and `token` parameters are provided the output is filtered for the specified attribute and it's tokens and related tokens.
|
|
800
|
-
*
|
|
801
|
-
* @internal
|
|
802
|
-
* @param key Attribute name.
|
|
803
|
-
* @param token Reference token to collect all related tokens.
|
|
804
|
-
*/
|
|
805
|
-
_getConsumables(key, token) {
|
|
806
|
-
const attributes = [];
|
|
807
|
-
if (key) {
|
|
808
|
-
const value = this._attrs.get(key);
|
|
809
|
-
if (value !== undefined) {
|
|
810
|
-
if (typeof value == 'string') {
|
|
811
|
-
attributes.push([key]);
|
|
812
|
-
}
|
|
813
|
-
else {
|
|
814
|
-
for (const prop of value._getConsumables(token)) {
|
|
815
|
-
attributes.push([key, prop]);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
821
|
-
for (const [key, value] of this._attrs) {
|
|
822
|
-
if (typeof value == 'string') {
|
|
823
|
-
attributes.push([key]);
|
|
824
|
-
}
|
|
825
|
-
else {
|
|
826
|
-
for (const prop of value._getConsumables()) {
|
|
827
|
-
attributes.push([key, prop]);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
return {
|
|
833
|
-
name: !key,
|
|
834
|
-
attributes
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
/**
|
|
838
|
-
* Verify if the given element can be merged without conflicts into the element.
|
|
839
|
-
*
|
|
840
|
-
* Note that this method is extended by the {@link module:engine/view/attributeelement~ViewAttributeElement} implementation.
|
|
841
|
-
*
|
|
842
|
-
* This method is used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
|
|
843
|
-
* an {@link module:engine/view/attributeelement~ViewAttributeElement} to merge it with other ViewAttributeElement.
|
|
844
|
-
*
|
|
845
|
-
* @internal
|
|
846
|
-
* @returns Returns `true` if elements can be merged.
|
|
847
|
-
*/
|
|
848
|
-
_canMergeAttributesFrom(otherElement) {
|
|
849
|
-
if (this.name != otherElement.name) {
|
|
850
|
-
return false;
|
|
851
|
-
}
|
|
852
|
-
for (const [key, otherValue] of otherElement._attrs) {
|
|
853
|
-
const value = this._attrs.get(key);
|
|
854
|
-
if (value === undefined) {
|
|
855
|
-
continue;
|
|
856
|
-
}
|
|
857
|
-
if (typeof value == 'string' || typeof otherValue == 'string') {
|
|
858
|
-
if (value !== otherValue) {
|
|
859
|
-
return false;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
else if (!value._canMergeFrom(otherValue)) {
|
|
863
|
-
return false;
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
return true;
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* Merges attributes of a given element into the element.
|
|
870
|
-
* This includes also tokenized attributes like style and class.
|
|
871
|
-
*
|
|
872
|
-
* Note that you should make sure there are no conflicts before merging (see {@link #_canMergeAttributesFrom}).
|
|
873
|
-
*
|
|
874
|
-
* This method is used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
|
|
875
|
-
* an {@link module:engine/view/attributeelement~ViewAttributeElement} to merge it with other ViewAttributeElement.
|
|
876
|
-
*
|
|
877
|
-
* @internal
|
|
878
|
-
*/
|
|
879
|
-
_mergeAttributesFrom(otherElement) {
|
|
880
|
-
this._fireChange('attributes', this);
|
|
881
|
-
// Move all attributes/classes/styles from wrapper to wrapped ViewAttributeElement.
|
|
882
|
-
for (const [key, otherValue] of otherElement._attrs) {
|
|
883
|
-
const value = this._attrs.get(key);
|
|
884
|
-
if (value === undefined || typeof value == 'string' || typeof otherValue == 'string') {
|
|
885
|
-
this._setAttribute(key, otherValue);
|
|
886
|
-
}
|
|
887
|
-
else {
|
|
888
|
-
value._mergeFrom(otherValue);
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Verify if the given element attributes can be fully subtracted from the element.
|
|
894
|
-
*
|
|
895
|
-
* Note that this method is extended by the {@link module:engine/view/attributeelement~ViewAttributeElement} implementation.
|
|
896
|
-
*
|
|
897
|
-
* This method is used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
|
|
898
|
-
* an {@link module:engine/view/attributeelement~ViewAttributeElement} to unwrap the ViewAttributeElement.
|
|
899
|
-
*
|
|
900
|
-
* @internal
|
|
901
|
-
* @returns Returns `true` if elements attributes can be fully subtracted.
|
|
902
|
-
*/
|
|
903
|
-
_canSubtractAttributesOf(otherElement) {
|
|
904
|
-
if (this.name != otherElement.name) {
|
|
905
|
-
return false;
|
|
906
|
-
}
|
|
907
|
-
for (const [key, otherValue] of otherElement._attrs) {
|
|
908
|
-
const value = this._attrs.get(key);
|
|
909
|
-
if (value === undefined) {
|
|
910
|
-
return false;
|
|
911
|
-
}
|
|
912
|
-
if (typeof value == 'string' || typeof otherValue == 'string') {
|
|
913
|
-
if (value !== otherValue) {
|
|
914
|
-
return false;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
else if (!value._isMatching(otherValue)) {
|
|
918
|
-
return false;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
return true;
|
|
922
|
-
}
|
|
923
|
-
/**
|
|
924
|
-
* Removes (subtracts) corresponding attributes of the given element from the element.
|
|
925
|
-
* This includes also tokenized attributes like style and class.
|
|
926
|
-
* All attributes, classes and styles from given element should be present inside the element being unwrapped.
|
|
927
|
-
*
|
|
928
|
-
* Note that you should make sure all attributes could be subtracted before subtracting them (see {@link #_canSubtractAttributesOf}).
|
|
929
|
-
*
|
|
930
|
-
* This method is used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
|
|
931
|
-
* an {@link module:engine/view/attributeelement~ViewAttributeElement} to unwrap the ViewAttributeElement.
|
|
932
|
-
*
|
|
933
|
-
* @internal
|
|
934
|
-
*/
|
|
935
|
-
_subtractAttributesOf(otherElement) {
|
|
936
|
-
this._fireChange('attributes', this);
|
|
937
|
-
for (const [key, otherValue] of otherElement._attrs) {
|
|
938
|
-
const value = this._attrs.get(key);
|
|
939
|
-
if (typeof value == 'string' || typeof otherValue == 'string') {
|
|
940
|
-
this._attrs.delete(key);
|
|
941
|
-
}
|
|
942
|
-
else {
|
|
943
|
-
value.remove(otherValue.keys());
|
|
944
|
-
if (value.isEmpty) {
|
|
945
|
-
this._attrs.delete(key);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Sets a custom property. Unlike attributes, custom properties are not rendered to the DOM,
|
|
952
|
-
* so they can be used to add special data to elements.
|
|
953
|
-
*
|
|
954
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#setCustomProperty
|
|
955
|
-
* @internal
|
|
956
|
-
*/
|
|
957
|
-
_setCustomProperty(key, value) {
|
|
958
|
-
this._customProperties.set(key, value);
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Removes the custom property stored under the given key.
|
|
962
|
-
*
|
|
963
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#removeCustomProperty
|
|
964
|
-
* @internal
|
|
965
|
-
* @returns Returns true if property was removed.
|
|
966
|
-
*/
|
|
967
|
-
_removeCustomProperty(key) {
|
|
968
|
-
return this._customProperties.delete(key);
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Parses attributes provided to the element constructor before they are applied to an element. If attributes are passed
|
|
972
|
-
* as an object (instead of `Iterable`), the object is transformed to the map. Attributes with `null` value are removed.
|
|
973
|
-
* Attributes with non-`String` value are converted to `String`.
|
|
974
|
-
*
|
|
975
|
-
* @param attrs Attributes to parse.
|
|
976
|
-
* @returns Parsed attributes.
|
|
977
|
-
*/
|
|
978
|
-
_parseAttributes(attrs) {
|
|
979
|
-
const attrsMap = toMap(attrs);
|
|
980
|
-
for (const [key, value] of attrsMap) {
|
|
981
|
-
if (value === null) {
|
|
982
|
-
attrsMap.delete(key);
|
|
983
|
-
}
|
|
984
|
-
else if (usesStylesMap(this.name, key)) {
|
|
985
|
-
// This is either an element clone so we need to clone styles map, or a new instance which requires value to be parsed.
|
|
986
|
-
const newValue = value instanceof StylesMap ?
|
|
987
|
-
value._clone() :
|
|
988
|
-
new StylesMap(this.document.stylesProcessor).setTo(String(value));
|
|
989
|
-
attrsMap.set(key, newValue);
|
|
990
|
-
}
|
|
991
|
-
else if (usesTokenList(this.name, key)) {
|
|
992
|
-
// This is either an element clone so we need to clone token list, or a new instance which requires value to be parsed.
|
|
993
|
-
const newValue = value instanceof ViewTokenList ?
|
|
994
|
-
value._clone() :
|
|
995
|
-
new ViewTokenList().setTo(String(value));
|
|
996
|
-
attrsMap.set(key, newValue);
|
|
997
|
-
}
|
|
998
|
-
else if (typeof value != 'string') {
|
|
999
|
-
attrsMap.set(key, String(value));
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
return attrsMap;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
1006
|
-
// Proper overload would interfere with that.
|
|
1007
|
-
ViewElement.prototype.is = function (type, name) {
|
|
1008
|
-
if (!name) {
|
|
1009
|
-
return type === 'element' || type === 'view:element' ||
|
|
1010
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
1011
|
-
type === 'node' || type === 'view:node';
|
|
1012
|
-
}
|
|
1013
|
-
else {
|
|
1014
|
-
return name === this.name && (type === 'element' || type === 'view:element');
|
|
1015
|
-
}
|
|
1016
|
-
};
|
|
1017
|
-
/**
|
|
1018
|
-
* Converts strings to Text and non-iterables to arrays.
|
|
1019
|
-
*/
|
|
1020
|
-
function normalize(document, nodes) {
|
|
1021
|
-
// Separate condition because string is iterable.
|
|
1022
|
-
if (typeof nodes == 'string') {
|
|
1023
|
-
return [new ViewText(document, nodes)];
|
|
1024
|
-
}
|
|
1025
|
-
if (!isIterable(nodes)) {
|
|
1026
|
-
nodes = [nodes];
|
|
1027
|
-
}
|
|
1028
|
-
const normalizedNodes = [];
|
|
1029
|
-
for (const node of nodes) {
|
|
1030
|
-
if (typeof node == 'string') {
|
|
1031
|
-
normalizedNodes.push(new ViewText(document, node));
|
|
1032
|
-
}
|
|
1033
|
-
else if (node instanceof ViewTextProxy) {
|
|
1034
|
-
normalizedNodes.push(new ViewText(document, node.data));
|
|
1035
|
-
}
|
|
1036
|
-
else {
|
|
1037
|
-
normalizedNodes.push(node);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
return normalizedNodes;
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Returns `true` if an attribute on a given element should be handled as a TokenList.
|
|
1044
|
-
*/
|
|
1045
|
-
function usesTokenList(elementName, key) {
|
|
1046
|
-
return key == 'class' || elementName == 'a' && key == 'rel';
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Returns `true` if an attribute on a given element should be handled as a StylesMap.
|
|
1050
|
-
*/
|
|
1051
|
-
function usesStylesMap(elementName, key) {
|
|
1052
|
-
return key == 'style';
|
|
1053
|
-
}
|