@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
|
@@ -11,7 +11,7 @@ import DowncastHelpers from './downcasthelpers';
|
|
|
11
11
|
/**
|
|
12
12
|
* A utility class that helps add converters to upcast and downcast dispatchers.
|
|
13
13
|
*
|
|
14
|
-
* We recommend reading the {@glink framework/
|
|
14
|
+
* We recommend reading the {@glink framework/deep-dive/conversion/intro editor conversion} guide first to
|
|
15
15
|
* understand the core concepts of the conversion mechanisms.
|
|
16
16
|
*
|
|
17
17
|
* An instance of the conversion manager is available in the
|
|
@@ -28,14 +28,16 @@ import DowncastHelpers from './downcasthelpers';
|
|
|
28
28
|
* To add a converter to a specific group, use the {@link module:engine/conversion/conversion~Conversion#for `for()`}
|
|
29
29
|
* method:
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* // Add a converter to editing downcast and data downcast.
|
|
33
|
+
* editor.conversion.for( 'downcast' ).elementToElement( config ) );
|
|
33
34
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
35
|
+
* // Add a converter to the data pipepline only:
|
|
36
|
+
* editor.conversion.for( 'dataDowncast' ).elementToElement( dataConversionConfig ) );
|
|
36
37
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* // And a slightly different one for the editing pipeline:
|
|
39
|
+
* editor.conversion.for( 'editingDowncast' ).elementToElement( editingConversionConfig ) );
|
|
40
|
+
* ```
|
|
39
41
|
*
|
|
40
42
|
* See {@link module:engine/conversion/conversion~Conversion#for `for()`} method documentation to learn more about
|
|
41
43
|
* available conversion helpers and how to use your custom ones.
|
|
@@ -55,18 +57,10 @@ import DowncastHelpers from './downcasthelpers';
|
|
|
55
57
|
export default class Conversion {
|
|
56
58
|
/**
|
|
57
59
|
* Creates a new conversion instance.
|
|
58
|
-
*
|
|
59
|
-
* @param {module:engine/conversion/downcastdispatcher~DowncastDispatcher|
|
|
60
|
-
* Array.<module:engine/conversion/downcastdispatcher~DowncastDispatcher>} downcastDispatchers
|
|
61
|
-
* @param {module:engine/conversion/upcastdispatcher~UpcastDispatcher|
|
|
62
|
-
* Array.<module:engine/conversion/upcastdispatcher~UpcastDispatcher>} upcastDispatchers
|
|
63
60
|
*/
|
|
64
61
|
constructor(downcastDispatchers, upcastDispatchers) {
|
|
65
62
|
/**
|
|
66
63
|
* Maps dispatchers group name to ConversionHelpers instances.
|
|
67
|
-
*
|
|
68
|
-
* @private
|
|
69
|
-
* @member {Map.<String,module:engine/conversion/conversionhelpers~ConversionHelpers>}
|
|
70
64
|
*/
|
|
71
65
|
this._helpers = new Map();
|
|
72
66
|
// Define default 'downcast' & 'upcast' dispatchers groups. Those groups are always available as two-way converters needs them.
|
|
@@ -78,16 +72,17 @@ export default class Conversion {
|
|
|
78
72
|
/**
|
|
79
73
|
* Define an alias for registered dispatcher.
|
|
80
74
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const conversion = new Conversion(
|
|
77
|
+
* [ dataDowncastDispatcher, editingDowncastDispatcher ],
|
|
78
|
+
* upcastDispatcher
|
|
79
|
+
* );
|
|
85
80
|
*
|
|
86
|
-
*
|
|
81
|
+
* conversion.addAlias( 'dataDowncast', dataDowncastDispatcher );
|
|
82
|
+
* ```
|
|
87
83
|
*
|
|
88
|
-
* @param
|
|
89
|
-
* @param
|
|
90
|
-
* module:engine/conversion/upcastdispatcher~UpcastDispatcher} dispatcher Dispatcher which should have an alias.
|
|
84
|
+
* @param alias An alias of a dispatcher.
|
|
85
|
+
* @param dispatcher Dispatcher which should have an alias.
|
|
91
86
|
*/
|
|
92
87
|
addAlias(alias, dispatcher) {
|
|
93
88
|
const isDowncast = this._downcast.includes(dispatcher);
|
|
@@ -115,12 +110,14 @@ export default class Conversion {
|
|
|
115
110
|
*
|
|
116
111
|
* The `for()` chain comes with a set of conversion helpers which you can use like this:
|
|
117
112
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* editor.conversion.for( 'downcast' )
|
|
115
|
+
* .elementToElement( config1 ) // Adds an element-to-element downcast converter.
|
|
116
|
+
* .attributeToElement( config2 ); // Adds an attribute-to-element downcast converter.
|
|
121
117
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
118
|
+
* editor.conversion.for( 'upcast' )
|
|
119
|
+
* .elementToAttribute( config3 ); // Adds an element-to-attribute upcast converter.
|
|
120
|
+
* ```
|
|
124
121
|
*
|
|
125
122
|
* Refer to the documentation of built-in conversion helpers to learn about their configuration options.
|
|
126
123
|
*
|
|
@@ -143,25 +140,28 @@ export default class Conversion {
|
|
|
143
140
|
*
|
|
144
141
|
* If you need to implement an atypical converter, you can do so by calling:
|
|
145
142
|
*
|
|
146
|
-
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* editor.conversion.for( direction ).add( customHelper );
|
|
145
|
+
* ```
|
|
147
146
|
*
|
|
148
147
|
* The `.add()` method takes exactly one parameter, which is a function. This function should accept one parameter that
|
|
149
148
|
* is a dispatcher instance. The function should add an actual converter to the passed dispatcher instance.
|
|
150
149
|
*
|
|
151
150
|
* Example:
|
|
152
151
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
152
|
+
* ```ts
|
|
153
|
+
* editor.conversion.for( 'upcast' ).add( dispatcher => {
|
|
154
|
+
* dispatcher.on( 'element:a', ( evt, data, conversionApi ) => {
|
|
155
|
+
* // Do something with a view <a> element.
|
|
156
|
+
* } );
|
|
157
|
+
* } );
|
|
158
|
+
* ```
|
|
158
159
|
*
|
|
159
160
|
* Refer to the documentation of {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher}
|
|
160
161
|
* and {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher} to learn how to write
|
|
161
162
|
* custom converters.
|
|
162
163
|
*
|
|
163
|
-
* @param
|
|
164
|
-
* @returns {module:engine/conversion/downcasthelpers~DowncastHelpers|module:engine/conversion/upcasthelpers~UpcastHelpers}
|
|
164
|
+
* @param groupName The name of dispatchers group to add the converters to.
|
|
165
165
|
*/
|
|
166
166
|
for(groupName) {
|
|
167
167
|
if (!this._helpers.has(groupName)) {
|
|
@@ -178,72 +178,73 @@ export default class Conversion {
|
|
|
178
178
|
* Sets up converters between the model and the view that convert a model element to a view element (and vice versa).
|
|
179
179
|
* For example, the model `<paragraph>Foo</paragraph>` is turned into `<p>Foo</p>` in the view.
|
|
180
180
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* // A simple conversion from the `paragraph` model element to the `<p>` view element (and vice versa).
|
|
183
|
+
* editor.conversion.elementToElement( { model: 'paragraph', view: 'p' } );
|
|
184
|
+
*
|
|
185
|
+
* // Override other converters by specifying a converter definition with a higher priority.
|
|
186
|
+
* editor.conversion.elementToElement( { model: 'paragraph', view: 'div', converterPriority: 'high' } );
|
|
187
|
+
*
|
|
188
|
+
* // View specified as an object instead of a string.
|
|
189
|
+
* editor.conversion.elementToElement( {
|
|
190
|
+
* model: 'fancyParagraph',
|
|
191
|
+
* view: {
|
|
192
|
+
* name: 'p',
|
|
193
|
+
* classes: 'fancy'
|
|
194
|
+
* }
|
|
195
|
+
* } );
|
|
196
|
+
*
|
|
197
|
+
* // Use `upcastAlso` to define other view elements that should also be converted to a `paragraph` element.
|
|
198
|
+
* editor.conversion.elementToElement( {
|
|
199
|
+
* model: 'paragraph',
|
|
200
|
+
* view: 'p',
|
|
201
|
+
* upcastAlso: [
|
|
202
|
+
* 'div',
|
|
203
|
+
* {
|
|
204
|
+
* // Any element with the `display: block` style.
|
|
205
|
+
* styles: {
|
|
206
|
+
* display: 'block'
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* ]
|
|
210
|
+
* } );
|
|
211
|
+
*
|
|
212
|
+
* // `upcastAlso` set as callback enables a conversion of a wide range of different view elements.
|
|
213
|
+
* editor.conversion.elementToElement( {
|
|
214
|
+
* model: 'heading',
|
|
215
|
+
* view: 'h2',
|
|
216
|
+
* // Convert "heading-like" paragraphs to headings.
|
|
217
|
+
* upcastAlso: viewElement => {
|
|
218
|
+
* const fontSize = viewElement.getStyle( 'font-size' );
|
|
219
|
+
*
|
|
220
|
+
* if ( !fontSize ) {
|
|
221
|
+
* return null;
|
|
222
|
+
* }
|
|
223
|
+
*
|
|
224
|
+
* const match = fontSize.match( /(\d+)\s*px/ );
|
|
225
|
+
*
|
|
226
|
+
* if ( !match ) {
|
|
227
|
+
* return null;
|
|
228
|
+
* }
|
|
229
|
+
*
|
|
230
|
+
* const size = Number( match[ 1 ] );
|
|
231
|
+
*
|
|
232
|
+
* if ( size > 26 ) {
|
|
233
|
+
* // Returned value can be an object with the matched properties.
|
|
234
|
+
* // These properties will be "consumed" during the conversion.
|
|
235
|
+
* // See `engine.view.Matcher~MatcherPattern` and `engine.view.Matcher#match` for more details.
|
|
236
|
+
*
|
|
237
|
+
* return { name: true, styles: [ 'font-size' ] };
|
|
238
|
+
* }
|
|
239
|
+
*
|
|
240
|
+
* return null;
|
|
241
|
+
* }
|
|
242
|
+
* } );
|
|
243
|
+
* ```
|
|
242
244
|
*
|
|
243
245
|
* `definition.model` is a `String` with a model element name to convert from or to.
|
|
244
|
-
* See {@link module:engine/conversion/conversion~ConverterDefinition} to learn about other parameters.
|
|
245
246
|
*
|
|
246
|
-
* @param
|
|
247
|
+
* @param definition The converter definition.
|
|
247
248
|
*/
|
|
248
249
|
elementToElement(definition) {
|
|
249
250
|
// Set up downcast converter.
|
|
@@ -262,159 +263,160 @@ export default class Conversion {
|
|
|
262
263
|
* Sets up converters between the model and the view that convert a model attribute to a view element (and vice versa).
|
|
263
264
|
* For example, a model text node with `"Foo"` as data and the `bold` attribute will be turned to `<strong>Foo</strong>` in the view.
|
|
264
265
|
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
266
|
+
* ```ts
|
|
267
|
+
* // A simple conversion from the `bold=true` attribute to the `<strong>` view element (and vice versa).
|
|
268
|
+
* editor.conversion.attributeToElement( { model: 'bold', view: 'strong' } );
|
|
269
|
+
*
|
|
270
|
+
* // Override other converters by specifying a converter definition with a higher priority.
|
|
271
|
+
* editor.conversion.attributeToElement( { model: 'bold', view: 'b', converterPriority: 'high' } );
|
|
272
|
+
*
|
|
273
|
+
* // View specified as an object instead of a string.
|
|
274
|
+
* editor.conversion.attributeToElement( {
|
|
275
|
+
* model: 'bold',
|
|
276
|
+
* view: {
|
|
277
|
+
* name: 'span',
|
|
278
|
+
* classes: 'bold'
|
|
279
|
+
* }
|
|
280
|
+
* } );
|
|
281
|
+
*
|
|
282
|
+
* // Use `config.model.name` to define the conversion only from a given node type, `$text` in this case.
|
|
283
|
+
* // The same attribute on different elements may then be handled by a different converter.
|
|
284
|
+
* editor.conversion.attributeToElement( {
|
|
285
|
+
* model: {
|
|
286
|
+
* key: 'textDecoration',
|
|
287
|
+
* values: [ 'underline', 'lineThrough' ],
|
|
288
|
+
* name: '$text'
|
|
289
|
+
* },
|
|
290
|
+
* view: {
|
|
291
|
+
* underline: {
|
|
292
|
+
* name: 'span',
|
|
293
|
+
* styles: {
|
|
294
|
+
* 'text-decoration': 'underline'
|
|
295
|
+
* }
|
|
296
|
+
* },
|
|
297
|
+
* lineThrough: {
|
|
298
|
+
* name: 'span',
|
|
299
|
+
* styles: {
|
|
300
|
+
* 'text-decoration': 'line-through'
|
|
301
|
+
* }
|
|
302
|
+
* }
|
|
303
|
+
* }
|
|
304
|
+
* } );
|
|
305
|
+
*
|
|
306
|
+
* // Use `upcastAlso` to define other view elements that should also be converted to the `bold` attribute.
|
|
307
|
+
* editor.conversion.attributeToElement( {
|
|
308
|
+
* model: 'bold',
|
|
309
|
+
* view: 'strong',
|
|
310
|
+
* upcastAlso: [
|
|
311
|
+
* 'b',
|
|
312
|
+
* {
|
|
313
|
+
* name: 'span',
|
|
314
|
+
* classes: 'bold'
|
|
315
|
+
* },
|
|
316
|
+
* {
|
|
317
|
+
* name: 'span',
|
|
318
|
+
* styles: {
|
|
319
|
+
* 'font-weight': 'bold'
|
|
320
|
+
* }
|
|
321
|
+
* },
|
|
322
|
+
* viewElement => {
|
|
323
|
+
* const fontWeight = viewElement.getStyle( 'font-weight' );
|
|
324
|
+
*
|
|
325
|
+
* if ( viewElement.is( 'element', 'span' ) && fontWeight && /\d+/.test() && Number( fontWeight ) > 500 ) {
|
|
326
|
+
* // Returned value can be an object with the matched properties.
|
|
327
|
+
* // These properties will be "consumed" during the conversion.
|
|
328
|
+
* // See `engine.view.Matcher~MatcherPattern` and `engine.view.Matcher#match` for more details.
|
|
329
|
+
*
|
|
330
|
+
* return {
|
|
331
|
+
* name: true,
|
|
332
|
+
* styles: [ 'font-weight' ]
|
|
333
|
+
* };
|
|
334
|
+
* }
|
|
335
|
+
* }
|
|
336
|
+
* ]
|
|
337
|
+
* } );
|
|
338
|
+
*
|
|
339
|
+
* // Conversion from and to a model attribute key whose value is an enum (`fontSize=big|small`).
|
|
340
|
+
* // `upcastAlso` set as callback enables a conversion of a wide range of different view elements.
|
|
341
|
+
* editor.conversion.attributeToElement( {
|
|
342
|
+
* model: {
|
|
343
|
+
* key: 'fontSize',
|
|
344
|
+
* values: [ 'big', 'small' ]
|
|
345
|
+
* },
|
|
346
|
+
* view: {
|
|
347
|
+
* big: {
|
|
348
|
+
* name: 'span',
|
|
349
|
+
* styles: {
|
|
350
|
+
* 'font-size': '1.2em'
|
|
351
|
+
* }
|
|
352
|
+
* },
|
|
353
|
+
* small: {
|
|
354
|
+
* name: 'span',
|
|
355
|
+
* styles: {
|
|
356
|
+
* 'font-size': '0.8em'
|
|
357
|
+
* }
|
|
358
|
+
* }
|
|
359
|
+
* },
|
|
360
|
+
* upcastAlso: {
|
|
361
|
+
* big: viewElement => {
|
|
362
|
+
* const fontSize = viewElement.getStyle( 'font-size' );
|
|
363
|
+
*
|
|
364
|
+
* if ( !fontSize ) {
|
|
365
|
+
* return null;
|
|
366
|
+
* }
|
|
367
|
+
*
|
|
368
|
+
* const match = fontSize.match( /(\d+)\s*px/ );
|
|
369
|
+
*
|
|
370
|
+
* if ( !match ) {
|
|
371
|
+
* return null;
|
|
372
|
+
* }
|
|
373
|
+
*
|
|
374
|
+
* const size = Number( match[ 1 ] );
|
|
375
|
+
*
|
|
376
|
+
* if ( viewElement.is( 'element', 'span' ) && size > 10 ) {
|
|
377
|
+
* // Returned value can be an object with the matched properties.
|
|
378
|
+
* // These properties will be "consumed" during the conversion.
|
|
379
|
+
* // See `engine.view.Matcher~MatcherPattern` and `engine.view.Matcher#match` for more details.
|
|
380
|
+
*
|
|
381
|
+
* return { name: true, styles: [ 'font-size' ] };
|
|
382
|
+
* }
|
|
383
|
+
*
|
|
384
|
+
* return null;
|
|
385
|
+
* },
|
|
386
|
+
* small: viewElement => {
|
|
387
|
+
* const fontSize = viewElement.getStyle( 'font-size' );
|
|
388
|
+
*
|
|
389
|
+
* if ( !fontSize ) {
|
|
390
|
+
* return null;
|
|
391
|
+
* }
|
|
392
|
+
*
|
|
393
|
+
* const match = fontSize.match( /(\d+)\s*px/ );
|
|
394
|
+
*
|
|
395
|
+
* if ( !match ) {
|
|
396
|
+
* return null;
|
|
397
|
+
* }
|
|
398
|
+
*
|
|
399
|
+
* const size = Number( match[ 1 ] );
|
|
400
|
+
*
|
|
401
|
+
* if ( viewElement.is( 'element', 'span' ) && size < 10 ) {
|
|
402
|
+
* // Returned value can be an object with the matched properties.
|
|
403
|
+
* // These properties will be "consumed" during the conversion.
|
|
404
|
+
* // See `engine.view.Matcher~MatcherPattern` and `engine.view.Matcher#match` for more details.
|
|
405
|
+
*
|
|
406
|
+
* return { name: true, styles: [ 'font-size' ] };
|
|
407
|
+
* }
|
|
408
|
+
*
|
|
409
|
+
* return null;
|
|
410
|
+
* }
|
|
411
|
+
* }
|
|
412
|
+
* } );
|
|
413
|
+
* ```
|
|
411
414
|
*
|
|
412
415
|
* The `definition.model` parameter specifies which model attribute should be converted from or to. It can be a `{ key, value }` object
|
|
413
416
|
* describing the attribute key and value to convert or a `String` specifying just the attribute key (in such a case
|
|
414
417
|
* `value` is set to `true`).
|
|
415
|
-
* See {@link module:engine/conversion/conversion~ConverterDefinition} to learn about other parameters.
|
|
416
418
|
*
|
|
417
|
-
* @param
|
|
419
|
+
* @param definition The converter definition.
|
|
418
420
|
*/
|
|
419
421
|
attributeToElement(definition) {
|
|
420
422
|
// Set up downcast converter.
|
|
@@ -436,75 +438,77 @@ export default class Conversion {
|
|
|
436
438
|
* To convert the text attributes,
|
|
437
439
|
* the {@link module:engine/conversion/conversion~Conversion#attributeToElement `attributeToElement converter`}should be set up.
|
|
438
440
|
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
441
|
+
* ```ts
|
|
442
|
+
* // A simple conversion from the `source` model attribute to the `src` view attribute (and vice versa).
|
|
443
|
+
* editor.conversion.attributeToAttribute( { model: 'source', view: 'src' } );
|
|
444
|
+
*
|
|
445
|
+
* // Attribute values are strictly specified.
|
|
446
|
+
* editor.conversion.attributeToAttribute( {
|
|
447
|
+
* model: {
|
|
448
|
+
* name: 'imageInline',
|
|
449
|
+
* key: 'aside',
|
|
450
|
+
* values: [ 'aside' ]
|
|
451
|
+
* },
|
|
452
|
+
* view: {
|
|
453
|
+
* aside: {
|
|
454
|
+
* name: 'img',
|
|
455
|
+
* key: 'class',
|
|
456
|
+
* value: [ 'aside', 'half-size' ]
|
|
457
|
+
* }
|
|
458
|
+
* }
|
|
459
|
+
* } );
|
|
460
|
+
*
|
|
461
|
+
* // Set the style attribute.
|
|
462
|
+
* editor.conversion.attributeToAttribute( {
|
|
463
|
+
* model: {
|
|
464
|
+
* name: 'imageInline',
|
|
465
|
+
* key: 'aside',
|
|
466
|
+
* values: [ 'aside' ]
|
|
467
|
+
* },
|
|
468
|
+
* view: {
|
|
469
|
+
* aside: {
|
|
470
|
+
* name: 'img',
|
|
471
|
+
* key: 'style',
|
|
472
|
+
* value: {
|
|
473
|
+
* float: 'right',
|
|
474
|
+
* width: '50%',
|
|
475
|
+
* margin: '5px'
|
|
476
|
+
* }
|
|
477
|
+
* }
|
|
478
|
+
* }
|
|
479
|
+
* } );
|
|
480
|
+
*
|
|
481
|
+
* // Conversion from and to a model attribute key whose value is an enum (`align=right|center`).
|
|
482
|
+
* // Use `upcastAlso` to define other view elements that should also be converted to the `align=right` attribute.
|
|
483
|
+
* editor.conversion.attributeToAttribute( {
|
|
484
|
+
* model: {
|
|
485
|
+
* key: 'align',
|
|
486
|
+
* values: [ 'right', 'center' ]
|
|
487
|
+
* },
|
|
488
|
+
* view: {
|
|
489
|
+
* right: {
|
|
490
|
+
* key: 'class',
|
|
491
|
+
* value: 'align-right'
|
|
492
|
+
* },
|
|
493
|
+
* center: {
|
|
494
|
+
* key: 'class',
|
|
495
|
+
* value: 'align-center'
|
|
496
|
+
* }
|
|
497
|
+
* },
|
|
498
|
+
* upcastAlso: {
|
|
499
|
+
* right: {
|
|
500
|
+
* styles: {
|
|
501
|
+
* 'text-align': 'right'
|
|
502
|
+
* }
|
|
503
|
+
* },
|
|
504
|
+
* center: {
|
|
505
|
+
* styles: {
|
|
506
|
+
* 'text-align': 'center'
|
|
507
|
+
* }
|
|
508
|
+
* }
|
|
509
|
+
* }
|
|
510
|
+
* } );
|
|
511
|
+
* ```
|
|
508
512
|
*
|
|
509
513
|
* The `definition.model` parameter specifies which model attribute should be converted from and to.
|
|
510
514
|
* It can be a `{ key, [ values ], [ name ] }` object or a `String`, which will be treated like `{ key: definition.model }`.
|
|
@@ -532,12 +536,11 @@ export default class Conversion {
|
|
|
532
536
|
* **Note:** `definition.model` and `definition.view` form should be mirrored, so the same types of parameters should
|
|
533
537
|
* be given in both parameters.
|
|
534
538
|
*
|
|
535
|
-
* @param
|
|
536
|
-
* @param
|
|
537
|
-
* @param
|
|
538
|
-
* @param
|
|
539
|
-
*
|
|
540
|
-
* is used only if `config.model.values` is specified.
|
|
539
|
+
* @param definition The converter definition.
|
|
540
|
+
* @param definition.model The model attribute to convert from and to.
|
|
541
|
+
* @param definition.view The view attribute to convert from and to.
|
|
542
|
+
* @param definition.upcastAlso Any view element matching `definition.upcastAlso` will also be converted to the given model attribute.
|
|
543
|
+
* `definition.upcastAlso` is used only if `config.model.values` is specified.
|
|
541
544
|
*/
|
|
542
545
|
attributeToAttribute(definition) {
|
|
543
546
|
// Set up downcast converter.
|
|
@@ -554,12 +557,7 @@ export default class Conversion {
|
|
|
554
557
|
/**
|
|
555
558
|
* Creates and caches conversion helpers for given dispatchers group.
|
|
556
559
|
*
|
|
557
|
-
* @
|
|
558
|
-
* @param {Object} options
|
|
559
|
-
* @param {String} options.name Group name.
|
|
560
|
-
* @param {Array.<module:engine/conversion/downcastdispatcher~DowncastDispatcher|
|
|
561
|
-
* module:engine/conversion/upcastdispatcher~UpcastDispatcher>} options.dispatchers
|
|
562
|
-
* @param {Boolean} options.isDowncast
|
|
560
|
+
* @param options.name Group name.
|
|
563
561
|
*/
|
|
564
562
|
_createConversionHelpers({ name, dispatchers, isDowncast }) {
|
|
565
563
|
if (this._helpers.has(name)) {
|
|
@@ -577,26 +575,9 @@ export default class Conversion {
|
|
|
577
575
|
}
|
|
578
576
|
}
|
|
579
577
|
/**
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
* @typedef {Object} module:engine/conversion/conversion~ConverterDefinition
|
|
583
|
-
*
|
|
584
|
-
* @property {*} [model] The model conversion definition. Describes the model element or model attribute to convert. This parameter differs
|
|
585
|
-
* for different functions that accept `ConverterDefinition`. See the description of the function to learn how to set it.
|
|
586
|
-
* @property {module:engine/view/elementdefinition~ElementDefinition|Object} view The definition of the view element to convert from and
|
|
587
|
-
* to. If `model` describes multiple values, `view` is an object that assigns these values (`view` object keys) to view element definitions
|
|
588
|
-
* (`view` object values).
|
|
589
|
-
* @property {module:engine/view/matcher~MatcherPattern|Array.<module:engine/view/matcher~MatcherPattern>} [upcastAlso]
|
|
590
|
-
* Any view element matching `upcastAlso` will also be converted to the model. If `model` describes multiple values, `upcastAlso`
|
|
591
|
-
* is an object that assigns these values (`upcastAlso` object keys) to {@link module:engine/view/matcher~MatcherPattern}s
|
|
592
|
-
* (`upcastAlso` object values).
|
|
593
|
-
* @property {module:utils/priorities~PriorityString} [converterPriority] The converter priority.
|
|
578
|
+
* Helper function that creates a joint array out of an item passed in `definition.view` and items passed in
|
|
579
|
+
* `definition.upcastAlso`.
|
|
594
580
|
*/
|
|
595
|
-
// Helper function that creates a joint array out of an item passed in `definition.view` and items passed in
|
|
596
|
-
// `definition.upcastAlso`.
|
|
597
|
-
//
|
|
598
|
-
// @param {module:engine/conversion/conversion~ConverterDefinition} definition
|
|
599
|
-
// @returns {Array} Array containing view definitions.
|
|
600
581
|
function* _getAllUpcastDefinitions(definition) {
|
|
601
582
|
if (definition.model.values) {
|
|
602
583
|
for (const value of definition.model.values) {
|