@ckeditor/ckeditor5-engine 36.0.1 → 37.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/README.md +1 -1
- package/package.json +24 -23
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +62 -109
- package/src/controller/editingcontroller.d.ts +98 -0
- package/src/controller/editingcontroller.js +22 -46
- package/src/conversion/conversion.d.ts +476 -0
- package/src/conversion/conversion.js +328 -347
- package/src/conversion/conversionhelpers.d.ts +26 -0
- package/src/conversion/conversionhelpers.js +1 -5
- package/src/conversion/downcastdispatcher.d.ts +547 -0
- package/src/conversion/downcastdispatcher.js +74 -152
- package/src/conversion/downcasthelpers.d.ts +1226 -0
- package/src/conversion/downcasthelpers.js +843 -762
- package/src/conversion/mapper.d.ts +499 -0
- package/src/conversion/mapper.js +84 -99
- package/src/conversion/modelconsumable.d.ts +201 -0
- package/src/conversion/modelconsumable.js +96 -99
- package/src/conversion/upcastdispatcher.d.ts +492 -0
- package/src/conversion/upcastdispatcher.js +73 -100
- package/src/conversion/upcasthelpers.d.ts +499 -0
- package/src/conversion/upcasthelpers.js +406 -373
- package/src/conversion/viewconsumable.d.ts +177 -0
- package/src/conversion/viewconsumable.js +157 -162
- package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/src/dataprocessor/basichtmlwriter.js +0 -9
- package/src/dataprocessor/dataprocessor.d.ts +61 -0
- package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/src/dataprocessor/htmldataprocessor.js +6 -28
- package/src/dataprocessor/htmlwriter.d.ts +16 -0
- package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/src/dataprocessor/xmldataprocessor.js +8 -40
- package/src/dev-utils/model.d.ts +124 -0
- package/src/dev-utils/model.js +41 -38
- package/src/dev-utils/operationreplayer.d.ts +51 -0
- package/src/dev-utils/operationreplayer.js +6 -14
- package/src/dev-utils/utils.d.ts +37 -0
- package/src/dev-utils/utils.js +5 -18
- package/src/dev-utils/view.d.ts +319 -0
- package/src/dev-utils/view.js +205 -226
- package/src/index.d.ts +105 -0
- package/src/index.js +1 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +245 -0
- package/src/model/document.js +1 -1
- package/src/model/documentfragment.d.ts +196 -0
- package/src/model/documentfragment.js +2 -2
- package/src/model/documentselection.d.ts +420 -0
- package/src/model/element.d.ts +165 -0
- package/src/model/history.d.ts +114 -0
- package/src/model/item.d.ts +14 -0
- package/src/model/liveposition.d.ts +77 -0
- package/src/model/liverange.d.ts +102 -0
- package/src/model/markercollection.d.ts +335 -0
- package/src/model/model.d.ts +812 -0
- package/src/model/model.js +59 -30
- package/src/model/node.d.ts +256 -0
- package/src/model/nodelist.d.ts +91 -0
- package/src/model/operation/attributeoperation.d.ts +98 -0
- package/src/model/operation/detachoperation.d.ts +55 -0
- package/src/model/operation/insertoperation.d.ts +85 -0
- package/src/model/operation/markeroperation.d.ts +86 -0
- package/src/model/operation/mergeoperation.d.ts +95 -0
- package/src/model/operation/moveoperation.d.ts +91 -0
- package/src/model/operation/nooperation.d.ts +33 -0
- package/src/model/operation/operation.d.ts +89 -0
- package/src/model/operation/operationfactory.d.ts +18 -0
- package/src/model/operation/renameoperation.d.ts +78 -0
- package/src/model/operation/rootattributeoperation.d.ts +97 -0
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.d.ts +104 -0
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/position.d.ts +539 -0
- package/src/model/position.js +1 -1
- package/src/model/range.d.ts +458 -0
- package/src/model/range.js +1 -1
- package/src/model/rootelement.d.ts +40 -0
- package/src/model/schema.d.ts +1176 -0
- package/src/model/schema.js +15 -15
- package/src/model/selection.d.ts +472 -0
- package/src/model/text.d.ts +66 -0
- package/src/model/text.js +0 -2
- package/src/model/textproxy.d.ts +144 -0
- package/src/model/treewalker.d.ts +186 -0
- package/src/model/treewalker.js +19 -10
- package/src/model/typecheckable.d.ts +255 -0
- package/src/model/utils/autoparagraphing.d.ts +37 -0
- package/src/model/utils/deletecontent.d.ts +58 -0
- package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
- package/src/model/utils/getselectedcontent.d.ts +30 -0
- package/src/model/utils/insertcontent.d.ts +46 -0
- package/src/model/utils/insertcontent.js +2 -12
- package/src/model/utils/insertobject.d.ts +44 -0
- package/src/model/utils/insertobject.js +3 -14
- package/src/model/utils/modifyselection.d.ts +48 -0
- package/src/model/utils/selection-post-fixer.d.ts +65 -0
- package/src/model/writer.d.ts +726 -0
- package/src/model/writer.js +6 -4
- package/src/view/attributeelement.d.ts +108 -0
- package/src/view/attributeelement.js +25 -69
- package/src/view/containerelement.d.ts +49 -0
- package/src/view/containerelement.js +10 -43
- package/src/view/datatransfer.d.ts +75 -0
- package/src/view/document.d.ts +184 -0
- package/src/view/document.js +15 -84
- package/src/view/documentfragment.d.ts +150 -0
- package/src/view/documentfragment.js +40 -81
- package/src/view/documentselection.d.ts +219 -0
- package/src/view/documentselection.js +75 -121
- package/src/view/domconverter.d.ts +620 -0
- package/src/view/domconverter.js +159 -276
- package/src/view/downcastwriter.d.ts +804 -0
- package/src/view/downcastwriter.js +336 -380
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +466 -0
- package/src/view/element.js +150 -222
- package/src/view/elementdefinition.d.ts +87 -0
- package/src/view/emptyelement.d.ts +41 -0
- package/src/view/emptyelement.js +11 -44
- package/src/view/filler.d.ts +111 -0
- package/src/view/filler.js +24 -21
- package/src/view/item.d.ts +14 -0
- package/src/view/matcher.d.ts +486 -0
- package/src/view/matcher.js +247 -218
- package/src/view/node.d.ts +160 -0
- package/src/view/node.js +26 -100
- package/src/view/observer/arrowkeysobserver.d.ts +41 -0
- package/src/view/observer/arrowkeysobserver.js +0 -13
- package/src/view/observer/bubblingemittermixin.d.ts +166 -0
- package/src/view/observer/bubblingemittermixin.js +36 -25
- package/src/view/observer/bubblingeventinfo.d.ts +47 -0
- package/src/view/observer/bubblingeventinfo.js +3 -29
- package/src/view/observer/clickobserver.d.ts +43 -0
- package/src/view/observer/clickobserver.js +9 -19
- package/src/view/observer/compositionobserver.d.ts +82 -0
- package/src/view/observer/compositionobserver.js +13 -42
- package/src/view/observer/domeventdata.d.ts +50 -0
- package/src/view/observer/domeventdata.js +5 -30
- package/src/view/observer/domeventobserver.d.ts +69 -0
- package/src/view/observer/domeventobserver.js +19 -21
- package/src/view/observer/fakeselectionobserver.d.ts +46 -0
- package/src/view/observer/fakeselectionobserver.js +2 -15
- package/src/view/observer/focusobserver.d.ts +82 -0
- package/src/view/observer/focusobserver.js +14 -40
- package/src/view/observer/inputobserver.d.ts +86 -0
- package/src/view/observer/inputobserver.js +18 -64
- package/src/view/observer/keyobserver.d.ts +67 -0
- package/src/view/observer/keyobserver.js +8 -42
- package/src/view/observer/mouseobserver.d.ts +89 -0
- package/src/view/observer/mouseobserver.js +8 -28
- package/src/view/observer/mutationobserver.d.ts +82 -0
- package/src/view/observer/mutationobserver.js +7 -37
- package/src/view/observer/observer.d.ts +84 -0
- package/src/view/observer/observer.js +12 -25
- package/src/view/observer/selectionobserver.d.ts +143 -0
- package/src/view/observer/selectionobserver.js +9 -99
- package/src/view/observer/tabobserver.d.ts +42 -0
- package/src/view/observer/tabobserver.js +0 -14
- package/src/view/placeholder.d.ts +85 -0
- package/src/view/placeholder.js +26 -43
- package/src/view/position.d.ts +189 -0
- package/src/view/position.js +36 -83
- package/src/view/range.d.ts +279 -0
- package/src/view/range.js +79 -122
- package/src/view/rawelement.d.ts +73 -0
- package/src/view/rawelement.js +34 -48
- package/src/view/renderer.d.ts +265 -0
- package/src/view/renderer.js +105 -193
- package/src/view/rooteditableelement.d.ts +41 -0
- package/src/view/rooteditableelement.js +12 -40
- package/src/view/selection.d.ts +375 -0
- package/src/view/selection.js +79 -153
- package/src/view/styles/background.d.ts +33 -0
- package/src/view/styles/background.js +14 -12
- package/src/view/styles/border.d.ts +43 -0
- package/src/view/styles/border.js +58 -48
- package/src/view/styles/margin.d.ts +29 -0
- package/src/view/styles/margin.js +13 -11
- package/src/view/styles/padding.d.ts +29 -0
- package/src/view/styles/padding.js +13 -11
- package/src/view/styles/utils.d.ts +93 -0
- package/src/view/styles/utils.js +22 -48
- package/src/view/stylesmap.d.ts +675 -0
- package/src/view/stylesmap.js +249 -244
- package/src/view/text.d.ts +74 -0
- package/src/view/text.js +16 -46
- package/src/view/textproxy.d.ts +97 -0
- package/src/view/textproxy.js +10 -59
- package/src/view/treewalker.d.ts +195 -0
- package/src/view/treewalker.js +43 -106
- package/src/view/typecheckable.d.ts +401 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +28 -62
- package/src/view/upcastwriter.d.ts +328 -0
- package/src/view/upcastwriter.js +124 -134
- package/src/view/view.d.ts +327 -0
- package/src/view/view.js +79 -150
package/src/view/stylesmap.js
CHANGED
|
@@ -14,32 +14,13 @@ import { get, isObject, merge, set, unset } from 'lodash-es';
|
|
|
14
14
|
export default class StylesMap {
|
|
15
15
|
/**
|
|
16
16
|
* Creates Styles instance.
|
|
17
|
-
*
|
|
18
|
-
* @param {module:engine/view/stylesmap~StylesProcessor} styleProcessor
|
|
19
17
|
*/
|
|
20
18
|
constructor(styleProcessor) {
|
|
21
|
-
/**
|
|
22
|
-
* Keeps an internal representation of styles map. Normalized styles are kept as object tree to allow unified modification and
|
|
23
|
-
* value access model using lodash's get, set, unset, etc methods.
|
|
24
|
-
*
|
|
25
|
-
* When no style processor rules are defined it acts as simple key-value storage.
|
|
26
|
-
*
|
|
27
|
-
* @private
|
|
28
|
-
* @type {Object}
|
|
29
|
-
*/
|
|
30
19
|
this._styles = {};
|
|
31
|
-
/**
|
|
32
|
-
* An instance of the {@link module:engine/view/stylesmap~StylesProcessor}.
|
|
33
|
-
*
|
|
34
|
-
* @private
|
|
35
|
-
* @member {module:engine/view/stylesmap~StylesProcessor}
|
|
36
|
-
*/
|
|
37
20
|
this._styleProcessor = styleProcessor;
|
|
38
21
|
}
|
|
39
22
|
/**
|
|
40
23
|
* Returns true if style map has no styles set.
|
|
41
|
-
*
|
|
42
|
-
* @type {Boolean}
|
|
43
24
|
*/
|
|
44
25
|
get isEmpty() {
|
|
45
26
|
const entries = Object.entries(this._styles);
|
|
@@ -48,8 +29,6 @@ export default class StylesMap {
|
|
|
48
29
|
}
|
|
49
30
|
/**
|
|
50
31
|
* Number of styles defined.
|
|
51
|
-
*
|
|
52
|
-
* @type {Number}
|
|
53
32
|
*/
|
|
54
33
|
get size() {
|
|
55
34
|
if (this.isEmpty) {
|
|
@@ -60,9 +39,9 @@ export default class StylesMap {
|
|
|
60
39
|
/**
|
|
61
40
|
* Set styles map to a new value.
|
|
62
41
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* styles.setTo( 'border:1px solid blue;margin-top:1px;' );
|
|
44
|
+
* ```
|
|
66
45
|
*/
|
|
67
46
|
setTo(inlineStyle) {
|
|
68
47
|
this.clear();
|
|
@@ -74,30 +53,33 @@ export default class StylesMap {
|
|
|
74
53
|
/**
|
|
75
54
|
* Checks if a given style is set.
|
|
76
55
|
*
|
|
77
|
-
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* styles.setTo( 'margin-left:1px;' );
|
|
78
58
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
59
|
+
* styles.has( 'margin-left' ); // -> true
|
|
60
|
+
* styles.has( 'padding' ); // -> false
|
|
61
|
+
* ```
|
|
81
62
|
*
|
|
82
63
|
* **Note**: This check supports normalized style names.
|
|
83
64
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* // Enable 'margin' shorthand processing:
|
|
67
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
86
68
|
*
|
|
87
|
-
*
|
|
69
|
+
* styles.setTo( 'margin:2px;' );
|
|
88
70
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
71
|
+
* styles.has( 'margin' ); // -> true
|
|
72
|
+
* styles.has( 'margin-top' ); // -> true
|
|
73
|
+
* styles.has( 'margin-left' ); // -> true
|
|
92
74
|
*
|
|
93
|
-
*
|
|
75
|
+
* styles.remove( 'margin-top' );
|
|
94
76
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
77
|
+
* styles.has( 'margin' ); // -> false
|
|
78
|
+
* styles.has( 'margin-top' ); // -> false
|
|
79
|
+
* styles.has( 'margin-left' ); // -> true
|
|
80
|
+
* ```
|
|
98
81
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @returns {Boolean}
|
|
82
|
+
* @param name Style name.
|
|
101
83
|
*/
|
|
102
84
|
has(name) {
|
|
103
85
|
if (this.isEmpty) {
|
|
@@ -121,26 +103,30 @@ export default class StylesMap {
|
|
|
121
103
|
/**
|
|
122
104
|
* Removes given style.
|
|
123
105
|
*
|
|
124
|
-
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* styles.setTo( 'background:#f00;margin-right:2px;' );
|
|
125
108
|
*
|
|
126
|
-
*
|
|
109
|
+
* styles.remove( 'background' );
|
|
127
110
|
*
|
|
128
|
-
*
|
|
111
|
+
* styles.toString(); // -> 'margin-right:2px;'
|
|
112
|
+
* ```
|
|
129
113
|
*
|
|
130
114
|
* ***Note**:* This method uses {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules
|
|
131
115
|
* enabled style processor rules} to normalize passed values.
|
|
132
116
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* // Enable 'margin' shorthand processing:
|
|
119
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
135
120
|
*
|
|
136
|
-
*
|
|
121
|
+
* styles.setTo( 'margin:1px' );
|
|
137
122
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
123
|
+
* styles.remove( 'margin-top' );
|
|
124
|
+
* styles.remove( 'margin-right' );
|
|
140
125
|
*
|
|
141
|
-
*
|
|
126
|
+
* styles.toString(); // -> 'margin-bottom:1px;margin-left:1px;'
|
|
127
|
+
* ```
|
|
142
128
|
*
|
|
143
|
-
* @param
|
|
129
|
+
* @param name Style name.
|
|
144
130
|
*/
|
|
145
131
|
remove(name) {
|
|
146
132
|
const path = toPath(name);
|
|
@@ -151,27 +137,28 @@ export default class StylesMap {
|
|
|
151
137
|
/**
|
|
152
138
|
* Returns a normalized style object or a single value.
|
|
153
139
|
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
140
|
+
* ```ts
|
|
141
|
+
* // Enable 'margin' shorthand processing:
|
|
142
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
156
143
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
144
|
+
* const styles = new Styles();
|
|
145
|
+
* styles.setTo( 'margin:1px 2px 3em;' );
|
|
159
146
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
147
|
+
* styles.getNormalized( 'margin' );
|
|
148
|
+
* // will log:
|
|
149
|
+
* // {
|
|
150
|
+
* // top: '1px',
|
|
151
|
+
* // right: '2px',
|
|
152
|
+
* // bottom: '3em',
|
|
153
|
+
* // left: '2px' // normalized value from margin shorthand
|
|
154
|
+
* // }
|
|
168
155
|
*
|
|
169
|
-
*
|
|
156
|
+
* styles.getNormalized( 'margin-left' ); // -> '2px'
|
|
157
|
+
* ```
|
|
170
158
|
*
|
|
171
159
|
* **Note**: This method will only return normalized styles if a style processor was defined.
|
|
172
160
|
*
|
|
173
|
-
* @param
|
|
174
|
-
* @returns {Object|String|undefined}
|
|
161
|
+
* @param name Style name.
|
|
175
162
|
*/
|
|
176
163
|
getNormalized(name) {
|
|
177
164
|
return this._styleProcessor.getNormalized(name, this._styles);
|
|
@@ -179,24 +166,26 @@ export default class StylesMap {
|
|
|
179
166
|
/**
|
|
180
167
|
* Returns a normalized style string. Styles are sorted by name.
|
|
181
168
|
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* styles.set( 'margin' , '1px' );
|
|
171
|
+
* styles.set( 'background', '#f00' );
|
|
184
172
|
*
|
|
185
|
-
*
|
|
173
|
+
* styles.toString(); // -> 'background:#f00;margin:1px;'
|
|
174
|
+
* ```
|
|
186
175
|
*
|
|
187
176
|
* **Note**: This method supports normalized styles if defined.
|
|
188
177
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* styles.set( 'margin' , '1px' );
|
|
193
|
-
* styles.set( 'background', '#f00' );
|
|
194
|
-
* styles.remove( 'margin-top' );
|
|
195
|
-
* styles.remove( 'margin-right' );
|
|
178
|
+
* ```ts
|
|
179
|
+
* // Enable 'margin' shorthand processing:
|
|
180
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
196
181
|
*
|
|
197
|
-
*
|
|
182
|
+
* styles.set( 'margin' , '1px' );
|
|
183
|
+
* styles.set( 'background', '#f00' );
|
|
184
|
+
* styles.remove( 'margin-top' );
|
|
185
|
+
* styles.remove( 'margin-right' );
|
|
198
186
|
*
|
|
199
|
-
*
|
|
187
|
+
* styles.toString(); // -> 'background:#f00;margin-bottom:1px;margin-left:1px;'
|
|
188
|
+
* ```
|
|
200
189
|
*/
|
|
201
190
|
toString() {
|
|
202
191
|
if (this.isEmpty) {
|
|
@@ -210,53 +199,58 @@ export default class StylesMap {
|
|
|
210
199
|
/**
|
|
211
200
|
* Returns property as a value string or undefined if property is not set.
|
|
212
201
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* // Enable 'margin' shorthand processing:
|
|
204
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
215
205
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
206
|
+
* const styles = new Styles();
|
|
207
|
+
* styles.setTo( 'margin:1px;' );
|
|
208
|
+
* styles.set( 'margin-bottom', '3em' );
|
|
219
209
|
*
|
|
220
|
-
*
|
|
210
|
+
* styles.getAsString( 'margin' ); // -> 'margin: 1px 1px 3em;'
|
|
211
|
+
* ```
|
|
221
212
|
*
|
|
222
213
|
* Note, however, that all sub-values must be set for the longhand property name to return a value:
|
|
223
214
|
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* const styles = new Styles();
|
|
217
|
+
* styles.setTo( 'margin:1px;' );
|
|
218
|
+
* styles.remove( 'margin-bottom' );
|
|
227
219
|
*
|
|
228
|
-
*
|
|
220
|
+
* styles.getAsString( 'margin' ); // -> undefined
|
|
221
|
+
* ```
|
|
229
222
|
*
|
|
230
223
|
* In the above scenario, it is not possible to return a `margin` value, so `undefined` is returned.
|
|
231
224
|
* Instead, you should use:
|
|
232
225
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
226
|
+
* ```ts
|
|
227
|
+
* const styles = new Styles();
|
|
228
|
+
* styles.setTo( 'margin:1px;' );
|
|
229
|
+
* styles.remove( 'margin-bottom' );
|
|
236
230
|
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
231
|
+
* for ( const styleName of styles.getStyleNames() ) {
|
|
232
|
+
* console.log( styleName, styles.getAsString( styleName ) );
|
|
233
|
+
* }
|
|
234
|
+
* // 'margin-top', '1px'
|
|
235
|
+
* // 'margin-right', '1px'
|
|
236
|
+
* // 'margin-left', '1px'
|
|
237
|
+
* ```
|
|
243
238
|
*
|
|
244
239
|
* In general, it is recommend to iterate over style names like in the example above. This way, you will always get all
|
|
245
240
|
* the currently set style values. So, if all the 4 margin values would be set
|
|
246
241
|
* the for-of loop above would yield only `'margin'`, `'1px'`:
|
|
247
242
|
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* const styles = new Styles();
|
|
245
|
+
* styles.setTo( 'margin:1px;' );
|
|
250
246
|
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
247
|
+
* for ( const styleName of styles.getStyleNames() ) {
|
|
248
|
+
* console.log( styleName, styles.getAsString( styleName ) );
|
|
249
|
+
* }
|
|
250
|
+
* // 'margin', '1px'
|
|
251
|
+
* ```
|
|
255
252
|
*
|
|
256
253
|
* **Note**: To get a normalized version of a longhand property use the {@link #getNormalized `#getNormalized()`} method.
|
|
257
|
-
*
|
|
258
|
-
* @param {String} propertyName
|
|
259
|
-
* @returns {String|undefined}
|
|
260
254
|
*/
|
|
261
255
|
getAsString(propertyName) {
|
|
262
256
|
if (this.isEmpty) {
|
|
@@ -278,14 +272,17 @@ export default class StylesMap {
|
|
|
278
272
|
*
|
|
279
273
|
* When `expand` is set to true and there's a shorthand style property set, it will also return all equivalent styles:
|
|
280
274
|
*
|
|
281
|
-
*
|
|
275
|
+
* ```ts
|
|
276
|
+
* stylesMap.setTo( 'margin: 1em' )
|
|
277
|
+
* ```
|
|
282
278
|
*
|
|
283
279
|
* will be expanded to:
|
|
284
280
|
*
|
|
285
|
-
*
|
|
281
|
+
* ```ts
|
|
282
|
+
* [ 'margin', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left' ]
|
|
283
|
+
* ```
|
|
286
284
|
*
|
|
287
|
-
* @param
|
|
288
|
-
* @returns {Array.<String>}
|
|
285
|
+
* @param expand Expand shorthand style properties and all return equivalent style representations.
|
|
289
286
|
*/
|
|
290
287
|
getStyleNames(expand = false) {
|
|
291
288
|
if (this.isEmpty) {
|
|
@@ -305,9 +302,6 @@ export default class StylesMap {
|
|
|
305
302
|
}
|
|
306
303
|
/**
|
|
307
304
|
* Returns normalized styles entries for further processing.
|
|
308
|
-
*
|
|
309
|
-
* @private
|
|
310
|
-
* @returns {Array.<module:engine/view/stylesmap~PropertyDescriptor>}
|
|
311
305
|
*/
|
|
312
306
|
_getStylesEntries() {
|
|
313
307
|
const parsed = [];
|
|
@@ -319,9 +313,6 @@ export default class StylesMap {
|
|
|
319
313
|
}
|
|
320
314
|
/**
|
|
321
315
|
* Removes empty objects upon removing an entry from internal object.
|
|
322
|
-
*
|
|
323
|
-
* @param {String} path
|
|
324
|
-
* @private
|
|
325
316
|
*/
|
|
326
317
|
_cleanEmptyObjectsOnPath(path) {
|
|
327
318
|
const pathParts = path.split('.');
|
|
@@ -347,7 +338,7 @@ export class StylesProcessor {
|
|
|
347
338
|
/**
|
|
348
339
|
* Creates StylesProcessor instance.
|
|
349
340
|
*
|
|
350
|
-
* @
|
|
341
|
+
* @internal
|
|
351
342
|
*/
|
|
352
343
|
constructor() {
|
|
353
344
|
this._normalizers = new Map();
|
|
@@ -358,17 +349,19 @@ export class StylesProcessor {
|
|
|
358
349
|
/**
|
|
359
350
|
* Parse style string value to a normalized object and appends it to styles object.
|
|
360
351
|
*
|
|
361
|
-
*
|
|
352
|
+
* ```ts
|
|
353
|
+
* const styles = {};
|
|
362
354
|
*
|
|
363
|
-
*
|
|
355
|
+
* stylesProcessor.toNormalizedForm( 'margin', '1px', styles );
|
|
364
356
|
*
|
|
365
|
-
*
|
|
357
|
+
* // styles will consist: { margin: { top: '1px', right: '1px', bottom: '1px', left: '1px; } }
|
|
358
|
+
* ```
|
|
366
359
|
*
|
|
367
360
|
* **Note**: To define normalizer callbacks use {@link #setNormalizer}.
|
|
368
361
|
*
|
|
369
|
-
* @param
|
|
370
|
-
* @param
|
|
371
|
-
* @param
|
|
362
|
+
* @param name Name of style property.
|
|
363
|
+
* @param propertyValue Value of style property.
|
|
364
|
+
* @param styles Object holding normalized styles.
|
|
372
365
|
*/
|
|
373
366
|
toNormalizedForm(name, propertyValue, styles) {
|
|
374
367
|
if (isObject(propertyValue)) {
|
|
@@ -386,22 +379,24 @@ export class StylesProcessor {
|
|
|
386
379
|
}
|
|
387
380
|
/**
|
|
388
381
|
* Returns a normalized version of a style property.
|
|
389
|
-
* const styles = {
|
|
390
|
-
* margin: { top: '1px', right: '1px', bottom: '1px', left: '1px; },
|
|
391
|
-
* background: { color: '#f00' }
|
|
392
|
-
* };
|
|
393
382
|
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
383
|
+
* ```ts
|
|
384
|
+
* const styles = {
|
|
385
|
+
* margin: { top: '1px', right: '1px', bottom: '1px', left: '1px; },
|
|
386
|
+
* background: { color: '#f00' }
|
|
387
|
+
* };
|
|
388
|
+
*
|
|
389
|
+
* stylesProcessor.getNormalized( 'background' );
|
|
390
|
+
* // will return: { color: '#f00' }
|
|
396
391
|
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
392
|
+
* stylesProcessor.getNormalized( 'margin-top' );
|
|
393
|
+
* // will return: '1px'
|
|
394
|
+
* ```
|
|
399
395
|
*
|
|
400
396
|
* **Note**: In some cases extracting single value requires defining an extractor callback {@link #setExtractor}.
|
|
401
397
|
*
|
|
402
|
-
* @param
|
|
403
|
-
* @param
|
|
404
|
-
* @returns {*}
|
|
398
|
+
* @param name Name of style property.
|
|
399
|
+
* @param styles Object holding normalized styles.
|
|
405
400
|
*/
|
|
406
401
|
getNormalized(name, styles) {
|
|
407
402
|
if (!name) {
|
|
@@ -428,30 +423,34 @@ export class StylesProcessor {
|
|
|
428
423
|
*
|
|
429
424
|
* For default margin reducer, the below code:
|
|
430
425
|
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
426
|
+
* ```ts
|
|
427
|
+
* stylesProcessor.getReducedForm( 'margin', {
|
|
428
|
+
* margin: { top: '1px', right: '1px', bottom: '2px', left: '1px; }
|
|
429
|
+
* } );
|
|
430
|
+
* ```
|
|
434
431
|
*
|
|
435
432
|
* will return:
|
|
436
433
|
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
434
|
+
* ```ts
|
|
435
|
+
* [
|
|
436
|
+
* [ 'margin', '1px 1px 2px' ]
|
|
437
|
+
* ]
|
|
438
|
+
* ```
|
|
440
439
|
*
|
|
441
440
|
* because it might be represented as a shorthand 'margin' value. However if one of margin long hand values is missing it should return:
|
|
442
441
|
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
442
|
+
* ```ts
|
|
443
|
+
* [
|
|
444
|
+
* [ 'margin-top', '1px' ],
|
|
445
|
+
* [ 'margin-right', '1px' ],
|
|
446
|
+
* [ 'margin-bottom', '2px' ]
|
|
447
|
+
* // the 'left' value is missing - cannot use 'margin' shorthand.
|
|
448
|
+
* ]
|
|
449
|
+
* ```
|
|
449
450
|
*
|
|
450
451
|
* **Note**: To define reducer callbacks use {@link #setReducer}.
|
|
451
452
|
*
|
|
452
|
-
* @param
|
|
453
|
-
* @param {Object} styles Object holding normalized styles.
|
|
454
|
-
* @returns {Array.<module:engine/view/stylesmap~PropertyDescriptor>}
|
|
453
|
+
* @param name Name of style property.
|
|
455
454
|
*/
|
|
456
455
|
getReducedForm(name, styles) {
|
|
457
456
|
const normalizedValue = this.getNormalized(name, styles);
|
|
@@ -468,8 +467,7 @@ export class StylesProcessor {
|
|
|
468
467
|
/**
|
|
469
468
|
* Return all style properties. Also expand shorthand properties (e.g. `margin`, `background`) if respective extractor is available.
|
|
470
469
|
*
|
|
471
|
-
* @param
|
|
472
|
-
* @returns {Array.<String>}
|
|
470
|
+
* @param styles Object holding normalized styles.
|
|
473
471
|
*/
|
|
474
472
|
getStyleNames(styles) {
|
|
475
473
|
// Find all extractable styles that have a value.
|
|
@@ -491,17 +489,16 @@ export class StylesProcessor {
|
|
|
491
489
|
/**
|
|
492
490
|
* Returns related style names.
|
|
493
491
|
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
492
|
+
* ```ts
|
|
493
|
+
* stylesProcessor.getRelatedStyles( 'margin' );
|
|
494
|
+
* // will return: [ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left' ];
|
|
496
495
|
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
496
|
+
* stylesProcessor.getRelatedStyles( 'margin-top' );
|
|
497
|
+
* // will return: [ 'margin' ];
|
|
498
|
+
* ```
|
|
499
499
|
*
|
|
500
500
|
* **Note**: To define new style relations load an existing style processor or use
|
|
501
501
|
* {@link module:engine/view/stylesmap~StylesProcessor#setStyleRelation `StylesProcessor.setStyleRelation()`}.
|
|
502
|
-
*
|
|
503
|
-
* @param {String} name
|
|
504
|
-
* @returns {Array.<String>}
|
|
505
502
|
*/
|
|
506
503
|
getRelatedStyles(name) {
|
|
507
504
|
return this._consumables.get(name) || [];
|
|
@@ -523,39 +520,42 @@ export class StylesProcessor {
|
|
|
523
520
|
*
|
|
524
521
|
* A normalizer should parse various margin notations as a single object:
|
|
525
522
|
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
523
|
+
* ```ts
|
|
524
|
+
* const styles = {
|
|
525
|
+
* margin: {
|
|
526
|
+
* top: '1px',
|
|
527
|
+
* right: '2em',
|
|
528
|
+
* bottom: '1px',
|
|
529
|
+
* left: '2em'
|
|
530
|
+
* }
|
|
531
|
+
* };
|
|
532
|
+
* ```
|
|
534
533
|
*
|
|
535
534
|
* Thus a normalizer for 'margin' style should return an object defining style path and value to store:
|
|
536
535
|
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
536
|
+
* ```ts
|
|
537
|
+
* const returnValue = {
|
|
538
|
+
* path: 'margin',
|
|
539
|
+
* value: {
|
|
540
|
+
* top: '1px',
|
|
541
|
+
* right: '2em',
|
|
542
|
+
* bottom: '1px',
|
|
543
|
+
* left: '2em'
|
|
544
|
+
* }
|
|
545
|
+
* };
|
|
546
|
+
* ```
|
|
546
547
|
*
|
|
547
548
|
* Additionally to fully support all margin notations there should be also defined 4 normalizers for longhand margin notations. Below
|
|
548
549
|
* is an example for 'margin-top' style property normalizer:
|
|
549
550
|
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
* @param {Function} callback
|
|
551
|
+
* ```ts
|
|
552
|
+
* stylesProcessor.setNormalizer( 'margin-top', valueString => {
|
|
553
|
+
* return {
|
|
554
|
+
* path: 'margin.top',
|
|
555
|
+
* value: valueString
|
|
556
|
+
* }
|
|
557
|
+
* } );
|
|
558
|
+
* ```
|
|
559
559
|
*/
|
|
560
560
|
setNormalizer(name, callback) {
|
|
561
561
|
this._normalizers.set(name, callback);
|
|
@@ -565,39 +565,44 @@ export class StylesProcessor {
|
|
|
565
565
|
*
|
|
566
566
|
* Most normalized style values are stored as one level objects. It is assumed that `'margin-top'` style will be stored as:
|
|
567
567
|
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
568
|
+
* ```ts
|
|
569
|
+
* const styles = {
|
|
570
|
+
* margin: {
|
|
571
|
+
* top: 'value'
|
|
572
|
+
* }
|
|
573
|
+
* }
|
|
574
|
+
* ```
|
|
573
575
|
*
|
|
574
576
|
* However, some styles can have conflicting notations and thus it might be harder to extract a style value from shorthand. For instance
|
|
575
577
|
* the 'border-top-style' can be defined using `'border-top:solid'`, `'border-style:solid none none none'` or by `'border:solid'`
|
|
576
578
|
* shorthands. The default border styles processors stores styles as:
|
|
577
579
|
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
580
|
+
* ```ts
|
|
581
|
+
* const styles = {
|
|
582
|
+
* border: {
|
|
583
|
+
* style: {
|
|
584
|
+
* top: 'solid'
|
|
585
|
+
* }
|
|
586
|
+
* }
|
|
587
|
+
* }
|
|
588
|
+
* ```
|
|
585
589
|
*
|
|
586
590
|
* as it is better to modify border style independently from other values. On the other part the output of the border might be
|
|
587
591
|
* desired as `border-top`, `border-left`, etc notation.
|
|
588
592
|
*
|
|
589
|
-
* In the above example
|
|
593
|
+
* In the above example an extractor should return a side border value that combines style, color and width:
|
|
590
594
|
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
595
|
+
* ```ts
|
|
596
|
+
* styleProcessor.setExtractor( 'border-top', styles => {
|
|
597
|
+
* return {
|
|
598
|
+
* color: styles.border.color.top,
|
|
599
|
+
* style: styles.border.style.top,
|
|
600
|
+
* width: styles.border.width.top
|
|
601
|
+
* }
|
|
602
|
+
* } );
|
|
603
|
+
* ```
|
|
598
604
|
*
|
|
599
|
-
* @param
|
|
600
|
-
* @param {Function|String} callbackOrPath Callback that return a requested value or path string for single values.
|
|
605
|
+
* @param callbackOrPath Callback that return a requested value or path string for single values.
|
|
601
606
|
*/
|
|
602
607
|
setExtractor(name, callbackOrPath) {
|
|
603
608
|
this._extractors.set(name, callbackOrPath);
|
|
@@ -611,29 +616,32 @@ export class StylesProcessor {
|
|
|
611
616
|
* For shorthand styles a reducer should return minimal style notation either by returning single name-value tuple or multiple tuples
|
|
612
617
|
* if a shorthand cannot be used. For instance for a margin shorthand a reducer might return:
|
|
613
618
|
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
619
|
+
* ```ts
|
|
620
|
+
* const marginShortHandTuple = [
|
|
621
|
+
* [ 'margin', '1px 1px 2px' ]
|
|
622
|
+
* ];
|
|
623
|
+
* ```
|
|
617
624
|
*
|
|
618
625
|
* or a longhand tuples for defined values:
|
|
619
626
|
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
627
|
+
* ```ts
|
|
628
|
+
* // Considering margin.bottom and margin.left are undefined.
|
|
629
|
+
* const marginLonghandsTuples = [
|
|
630
|
+
* [ 'margin-top', '1px' ],
|
|
631
|
+
* [ 'margin-right', '1px' ]
|
|
632
|
+
* ];
|
|
633
|
+
* ```
|
|
625
634
|
*
|
|
626
635
|
* A reducer obtains a normalized style value:
|
|
627
636
|
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
* @param {Function} callback
|
|
637
|
+
* ```ts
|
|
638
|
+
* // Simplified reducer that always outputs 4 values which are always present:
|
|
639
|
+
* stylesProcessor.setReducer( 'margin', margin => {
|
|
640
|
+
* return [
|
|
641
|
+
* [ 'margin', `${ margin.top } ${ margin.right } ${ margin.bottom } ${ margin.left }` ]
|
|
642
|
+
* ]
|
|
643
|
+
* } );
|
|
644
|
+
* ```
|
|
637
645
|
*/
|
|
638
646
|
setReducer(name, callback) {
|
|
639
647
|
this._reducers.set(name, callback);
|
|
@@ -641,12 +649,14 @@ export class StylesProcessor {
|
|
|
641
649
|
/**
|
|
642
650
|
* Defines a style shorthand relation to other style notations.
|
|
643
651
|
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
652
|
+
* ```ts
|
|
653
|
+
* stylesProcessor.setStyleRelation( 'margin', [
|
|
654
|
+
* 'margin-top',
|
|
655
|
+
* 'margin-right',
|
|
656
|
+
* 'margin-bottom',
|
|
657
|
+
* 'margin-left'
|
|
658
|
+
* ] );
|
|
659
|
+
* ```
|
|
650
660
|
*
|
|
651
661
|
* This enables expanding of style names for shorthands. For instance, if defined,
|
|
652
662
|
* {@link module:engine/conversion/viewconsumable~ViewConsumable view consumable} items are automatically created
|
|
@@ -656,9 +666,6 @@ export class StylesProcessor {
|
|
|
656
666
|
* fine since the view consumable will contain a consumable `margin-left` item (thanks to the relation) and
|
|
657
667
|
* `element.getStyle( 'margin-left' )` will work as well assuming that the style processor was correctly configured.
|
|
658
668
|
* However, once `margin-left` is consumed, `margin` will not be consumable anymore.
|
|
659
|
-
*
|
|
660
|
-
* @param {String} shorthandName
|
|
661
|
-
* @param {Array.<String>} styleNames
|
|
662
669
|
*/
|
|
663
670
|
setStyleRelation(shorthandName, styleNames) {
|
|
664
671
|
this._mapStyleNames(shorthandName, styleNames);
|
|
@@ -668,10 +675,6 @@ export class StylesProcessor {
|
|
|
668
675
|
}
|
|
669
676
|
/**
|
|
670
677
|
* Set two-way binding of style names.
|
|
671
|
-
*
|
|
672
|
-
* @param {String} name
|
|
673
|
-
* @param {Array.<String>} styleNames
|
|
674
|
-
* @private
|
|
675
678
|
*/
|
|
676
679
|
_mapStyleNames(name, styleNames) {
|
|
677
680
|
if (!this._consumables.has(name)) {
|
|
@@ -680,10 +683,12 @@ export class StylesProcessor {
|
|
|
680
683
|
this._consumables.get(name).push(...styleNames);
|
|
681
684
|
}
|
|
682
685
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
686
|
+
/**
|
|
687
|
+
* Parses inline styles and puts property - value pairs into styles map.
|
|
688
|
+
*
|
|
689
|
+
* @param stylesString Styles to parse.
|
|
690
|
+
* @returns Map of parsed properties and values.
|
|
691
|
+
*/
|
|
687
692
|
function parseInlineStyles(stylesString) {
|
|
688
693
|
// `null` if no quote was found in input string or last found quote was a closing quote. See below.
|
|
689
694
|
let quoteType = null;
|
|
@@ -743,15 +748,15 @@ function parseInlineStyles(stylesString) {
|
|
|
743
748
|
}
|
|
744
749
|
return stylesMap;
|
|
745
750
|
}
|
|
746
|
-
|
|
751
|
+
/**
|
|
752
|
+
* Return lodash compatible path from style name.
|
|
753
|
+
*/
|
|
747
754
|
function toPath(name) {
|
|
748
755
|
return name.replace('-', '.');
|
|
749
756
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
// @param {String|Object} valueOrObject
|
|
754
|
-
// @private
|
|
757
|
+
/**
|
|
758
|
+
* Appends style definition to the styles object.
|
|
759
|
+
*/
|
|
755
760
|
function appendStyleValue(stylesObject, nameOrPath, valueOrObject) {
|
|
756
761
|
let valueToSet = valueOrObject;
|
|
757
762
|
if (isObject(valueOrObject)) {
|