@ckeditor/ckeditor5-engine 36.0.0 → 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/datatransfer.js +24 -27
- 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
|
@@ -16,7 +16,7 @@ import { cloneDeep } from 'lodash-es';
|
|
|
16
16
|
/**
|
|
17
17
|
* Upcast conversion helper functions.
|
|
18
18
|
*
|
|
19
|
-
* Learn more about {@glink framework/
|
|
19
|
+
* Learn more about {@glink framework/deep-dive/conversion/upcast upcast helpers}.
|
|
20
20
|
*
|
|
21
21
|
* @extends module:engine/conversion/conversionhelpers~ConversionHelpers
|
|
22
22
|
*/
|
|
@@ -30,49 +30,49 @@ export default class UpcastHelpers extends ConversionHelpers {
|
|
|
30
30
|
* Keep in mind that the element will be inserted only if it is allowed
|
|
31
31
|
* by {@link module:engine/model/schema~Schema schema} configuration.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* editor.conversion.for( 'upcast' ).elementToElement( {
|
|
35
|
+
* view: 'p',
|
|
36
|
+
* model: 'paragraph'
|
|
37
|
+
* } );
|
|
38
|
+
*
|
|
39
|
+
* editor.conversion.for( 'upcast' ).elementToElement( {
|
|
40
|
+
* view: 'p',
|
|
41
|
+
* model: 'paragraph',
|
|
42
|
+
* converterPriority: 'high'
|
|
43
|
+
* } );
|
|
44
|
+
*
|
|
45
|
+
* editor.conversion.for( 'upcast' ).elementToElement( {
|
|
46
|
+
* view: {
|
|
47
|
+
* name: 'p',
|
|
48
|
+
* classes: 'fancy'
|
|
49
|
+
* },
|
|
50
|
+
* model: 'fancyParagraph'
|
|
51
|
+
* } );
|
|
52
|
+
*
|
|
53
|
+
* editor.conversion.for( 'upcast' ).elementToElement( {
|
|
54
|
+
* view: {
|
|
55
|
+
* name: 'p',
|
|
56
|
+
* classes: 'heading'
|
|
57
|
+
* },
|
|
58
|
+
* model: ( viewElement, conversionApi ) => {
|
|
59
|
+
* const modelWriter = conversionApi.writer;
|
|
60
|
+
*
|
|
61
|
+
* return modelWriter.createElement( 'heading', { level: viewElement.getAttribute( 'data-level' ) } );
|
|
62
|
+
* }
|
|
63
|
+
* } );
|
|
64
|
+
* ```
|
|
63
65
|
*
|
|
64
66
|
* See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
|
|
65
67
|
* to the conversion process.
|
|
66
68
|
*
|
|
67
|
-
* @
|
|
68
|
-
* @param
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @
|
|
72
|
-
* function that takes a view element and {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API}
|
|
69
|
+
* @param config Conversion configuration.
|
|
70
|
+
* @param config.view Pattern matching all view elements which should be converted. If not set, the converter
|
|
71
|
+
* will fire for every view element.
|
|
72
|
+
* @param config.model Name of the model element, a model element instance or a function that takes a view element
|
|
73
|
+
* and {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API}
|
|
73
74
|
* and returns a model element. The model element will be inserted in the model.
|
|
74
|
-
* @param
|
|
75
|
-
* @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
|
|
75
|
+
* @param config.converterPriority Converter priority.
|
|
76
76
|
*/
|
|
77
77
|
elementToElement(config) {
|
|
78
78
|
return this.add(upcastElementToElement(config));
|
|
@@ -85,7 +85,9 @@ export default class UpcastHelpers extends ConversionHelpers {
|
|
|
85
85
|
*
|
|
86
86
|
* This helper is meant to set a model attribute on all the elements that are inside the converted element:
|
|
87
87
|
*
|
|
88
|
-
*
|
|
88
|
+
* ```
|
|
89
|
+
* <strong>Foo</strong> --> <strong><p>Foo</p></strong> --> <paragraph><$text bold="true">Foo</$text></paragraph>
|
|
90
|
+
* ```
|
|
89
91
|
*
|
|
90
92
|
* Above is a sample of HTML code, that goes through autoparagraphing (first step) and then is converted (second step).
|
|
91
93
|
* Even though `<strong>` is over `<p>` element, `bold="true"` was added to the text. See
|
|
@@ -93,72 +95,72 @@ export default class UpcastHelpers extends ConversionHelpers {
|
|
|
93
95
|
*
|
|
94
96
|
* Keep in mind that the attribute will be set only if it is allowed by {@link module:engine/model/schema~Schema schema} configuration.
|
|
95
97
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* editor.conversion.for( 'upcast' ).elementToAttribute( {
|
|
100
|
+
* view: 'strong',
|
|
101
|
+
* model: 'bold'
|
|
102
|
+
* } );
|
|
103
|
+
*
|
|
104
|
+
* editor.conversion.for( 'upcast' ).elementToAttribute( {
|
|
105
|
+
* view: 'strong',
|
|
106
|
+
* model: 'bold',
|
|
107
|
+
* converterPriority: 'high'
|
|
108
|
+
* } );
|
|
109
|
+
*
|
|
110
|
+
* editor.conversion.for( 'upcast' ).elementToAttribute( {
|
|
111
|
+
* view: {
|
|
112
|
+
* name: 'span',
|
|
113
|
+
* classes: 'bold'
|
|
114
|
+
* },
|
|
115
|
+
* model: 'bold'
|
|
116
|
+
* } );
|
|
117
|
+
*
|
|
118
|
+
* editor.conversion.for( 'upcast' ).elementToAttribute( {
|
|
119
|
+
* view: {
|
|
120
|
+
* name: 'span',
|
|
121
|
+
* classes: [ 'styled', 'styled-dark' ]
|
|
122
|
+
* },
|
|
123
|
+
* model: {
|
|
124
|
+
* key: 'styled',
|
|
125
|
+
* value: 'dark'
|
|
126
|
+
* }
|
|
127
|
+
* } );
|
|
128
|
+
*
|
|
129
|
+
* editor.conversion.for( 'upcast' ).elementToAttribute( {
|
|
130
|
+
* view: {
|
|
131
|
+
* name: 'span',
|
|
132
|
+
* styles: {
|
|
133
|
+
* 'font-size': /[\s\S]+/
|
|
134
|
+
* }
|
|
135
|
+
* },
|
|
136
|
+
* model: {
|
|
137
|
+
* key: 'fontSize',
|
|
138
|
+
* value: ( viewElement, conversionApi ) => {
|
|
139
|
+
* const fontSize = viewElement.getStyle( 'font-size' );
|
|
140
|
+
* const value = fontSize.substr( 0, fontSize.length - 2 );
|
|
141
|
+
*
|
|
142
|
+
* if ( value <= 10 ) {
|
|
143
|
+
* return 'small';
|
|
144
|
+
* } else if ( value > 12 ) {
|
|
145
|
+
* return 'big';
|
|
146
|
+
* }
|
|
147
|
+
*
|
|
148
|
+
* return null;
|
|
149
|
+
* }
|
|
150
|
+
* }
|
|
151
|
+
* } );
|
|
152
|
+
* ```
|
|
149
153
|
*
|
|
150
154
|
* See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
|
|
151
155
|
* to the conversion process.
|
|
152
156
|
*
|
|
153
|
-
* @
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
156
|
-
* @param {String|Object} config.model Model attribute key or an object with `key` and `value` properties, describing
|
|
157
|
+
* @param config Conversion configuration.
|
|
158
|
+
* @param config.view Pattern matching all view elements which should be converted.
|
|
159
|
+
* @param config.model Model attribute key or an object with `key` and `value` properties, describing
|
|
157
160
|
* the model attribute. `value` property may be set as a function that takes a view element and
|
|
158
161
|
* {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API} and returns the value.
|
|
159
162
|
* If `String` is given, the model attribute value will be set to `true`.
|
|
160
|
-
* @param
|
|
161
|
-
* @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
|
|
163
|
+
* @param config.converterPriority Converter priority. Defaults to `low`.
|
|
162
164
|
*/
|
|
163
165
|
elementToAttribute(config) {
|
|
164
166
|
return this.add(upcastElementToAttribute(config));
|
|
@@ -172,114 +174,120 @@ export default class UpcastHelpers extends ConversionHelpers {
|
|
|
172
174
|
* This helper is meant to convert view attributes from view elements which got converted to the model, so the view attribute
|
|
173
175
|
* is set only on the corresponding model node:
|
|
174
176
|
*
|
|
175
|
-
*
|
|
177
|
+
* ```
|
|
178
|
+
* <div class="dark"><div>foo</div></div> --> <div dark="true"><div>foo</div></div>
|
|
179
|
+
* ```
|
|
176
180
|
*
|
|
177
181
|
* Above, `class="dark"` attribute is added only to the `<div>` elements that has it. This is in contrary to
|
|
178
182
|
* {@link module:engine/conversion/upcasthelpers~UpcastHelpers#elementToAttribute} which sets attributes for
|
|
179
183
|
* all the children in the model:
|
|
180
184
|
*
|
|
181
|
-
*
|
|
185
|
+
* ```
|
|
186
|
+
* <strong>Foo</strong> --> <strong><p>Foo</p></strong> --> <paragraph><$text bold="true">Foo</$text></paragraph>
|
|
187
|
+
* ```
|
|
182
188
|
*
|
|
183
189
|
* Above is a sample of HTML code, that goes through autoparagraphing (first step) and then is converted (second step).
|
|
184
190
|
* Even though `<strong>` is over `<p>` element, `bold="true"` was added to the text.
|
|
185
191
|
*
|
|
186
192
|
* Keep in mind that the attribute will be set only if it is allowed by {@link module:engine/model/schema~Schema schema} configuration.
|
|
187
193
|
*
|
|
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
|
-
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
196
|
+
* view: 'src',
|
|
197
|
+
* model: 'source'
|
|
198
|
+
* } );
|
|
199
|
+
*
|
|
200
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
201
|
+
* view: { key: 'src' },
|
|
202
|
+
* model: 'source'
|
|
203
|
+
* } );
|
|
204
|
+
*
|
|
205
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
206
|
+
* view: { key: 'src' },
|
|
207
|
+
* model: 'source',
|
|
208
|
+
* converterPriority: 'normal'
|
|
209
|
+
* } );
|
|
210
|
+
*
|
|
211
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
212
|
+
* view: {
|
|
213
|
+
* key: 'data-style',
|
|
214
|
+
* value: /[\s\S]+/
|
|
215
|
+
* },
|
|
216
|
+
* model: 'styled'
|
|
217
|
+
* } );
|
|
218
|
+
*
|
|
219
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
220
|
+
* view: {
|
|
221
|
+
* name: 'img',
|
|
222
|
+
* key: 'class',
|
|
223
|
+
* value: 'styled-dark'
|
|
224
|
+
* },
|
|
225
|
+
* model: {
|
|
226
|
+
* key: 'styled',
|
|
227
|
+
* value: 'dark'
|
|
228
|
+
* }
|
|
229
|
+
* } );
|
|
230
|
+
*
|
|
231
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
232
|
+
* view: {
|
|
233
|
+
* key: 'class',
|
|
234
|
+
* value: /styled-[\S]+/
|
|
235
|
+
* },
|
|
236
|
+
* model: {
|
|
237
|
+
* key: 'styled'
|
|
238
|
+
* value: ( viewElement, conversionApi ) => {
|
|
239
|
+
* const regexp = /styled-([\S]+)/;
|
|
240
|
+
* const match = viewElement.getAttribute( 'class' ).match( regexp );
|
|
241
|
+
*
|
|
242
|
+
* return match[ 1 ];
|
|
243
|
+
* }
|
|
244
|
+
* }
|
|
245
|
+
* } );
|
|
246
|
+
* ```
|
|
239
247
|
*
|
|
240
248
|
* Converting styles works a bit differently as it requires `view.styles` to be an object and by default
|
|
241
249
|
* a model attribute will be set to `true` by such a converter. You can set the model attribute to any value by providing the `value`
|
|
242
250
|
* callback that returns the desired value.
|
|
243
251
|
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
252
|
+
* ```ts
|
|
253
|
+
* // Default conversion of font-weight style will result in setting bold attribute to true.
|
|
254
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
255
|
+
* view: {
|
|
256
|
+
* styles: {
|
|
257
|
+
* 'font-weight': 'bold'
|
|
258
|
+
* }
|
|
259
|
+
* },
|
|
260
|
+
* model: 'bold'
|
|
261
|
+
* } );
|
|
262
|
+
*
|
|
263
|
+
* // This converter will pass any style value to the `lineHeight` model attribute.
|
|
264
|
+
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
|
|
265
|
+
* view: {
|
|
266
|
+
* styles: {
|
|
267
|
+
* 'line-height': /[\s\S]+/
|
|
268
|
+
* }
|
|
269
|
+
* },
|
|
270
|
+
* model: {
|
|
271
|
+
* key: 'lineHeight',
|
|
272
|
+
* value: ( viewElement, conversionApi ) => viewElement.getStyle( 'line-height' )
|
|
273
|
+
* }
|
|
274
|
+
* } );
|
|
275
|
+
* ```
|
|
266
276
|
*
|
|
267
277
|
* See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
|
|
268
278
|
* to the conversion process.
|
|
269
279
|
*
|
|
270
|
-
* @
|
|
271
|
-
* @param
|
|
272
|
-
* @param {String|Object} config.view Specifies which view attribute will be converted. If a `String` is passed,
|
|
280
|
+
* @param config Conversion configuration.
|
|
281
|
+
* @param config.view Specifies which view attribute will be converted. If a `String` is passed,
|
|
273
282
|
* attributes with given key will be converted. If an `Object` is passed, it must have a required `key` property,
|
|
274
283
|
* specifying view attribute key, and may have an optional `value` property, specifying view attribute value and optional `name`
|
|
275
284
|
* property specifying a view element name from/on which the attribute should be converted. `value` can be given as a `String`,
|
|
276
285
|
* a `RegExp` or a function callback, that takes view attribute value as the only parameter and returns `Boolean`.
|
|
277
|
-
* @param
|
|
286
|
+
* @param config.model Model attribute key or an object with `key` and `value` properties, describing
|
|
278
287
|
* the model attribute. `value` property may be set as a function that takes a view element and
|
|
279
288
|
* {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API} and returns the value.
|
|
280
289
|
* If `String` is given, the model attribute value will be same as view attribute value.
|
|
281
|
-
* @param
|
|
282
|
-
* @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
|
|
290
|
+
* @param config.converterPriority Converter priority. Defaults to `low`.
|
|
283
291
|
*/
|
|
284
292
|
attributeToAttribute(config) {
|
|
285
293
|
return this.add(upcastAttributeToAttribute(config));
|
|
@@ -298,42 +306,42 @@ export default class UpcastHelpers extends ConversionHelpers {
|
|
|
298
306
|
*
|
|
299
307
|
* In most of the cases, the {@link #dataToMarker} should be used instead.
|
|
300
308
|
*
|
|
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
|
-
*
|
|
309
|
+
* ```ts
|
|
310
|
+
* editor.conversion.for( 'upcast' ).elementToMarker( {
|
|
311
|
+
* view: 'marker-search',
|
|
312
|
+
* model: 'search'
|
|
313
|
+
* } );
|
|
314
|
+
*
|
|
315
|
+
* editor.conversion.for( 'upcast' ).elementToMarker( {
|
|
316
|
+
* view: 'marker-search',
|
|
317
|
+
* model: 'search',
|
|
318
|
+
* converterPriority: 'high'
|
|
319
|
+
* } );
|
|
320
|
+
*
|
|
321
|
+
* editor.conversion.for( 'upcast' ).elementToMarker( {
|
|
322
|
+
* view: 'marker-search',
|
|
323
|
+
* model: ( viewElement, conversionApi ) => 'comment:' + viewElement.getAttribute( 'data-comment-id' )
|
|
324
|
+
* } );
|
|
325
|
+
*
|
|
326
|
+
* editor.conversion.for( 'upcast' ).elementToMarker( {
|
|
327
|
+
* view: {
|
|
328
|
+
* name: 'span',
|
|
329
|
+
* attributes: {
|
|
330
|
+
* 'data-marker': 'search'
|
|
331
|
+
* }
|
|
332
|
+
* },
|
|
333
|
+
* model: 'search'
|
|
334
|
+
* } );
|
|
335
|
+
* ```
|
|
326
336
|
*
|
|
327
337
|
* See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
|
|
328
338
|
* to the conversion process.
|
|
329
339
|
*
|
|
330
|
-
* @
|
|
331
|
-
* @param
|
|
332
|
-
* @param
|
|
333
|
-
* @param {String|Function} config.model Name of the model marker, or a function that takes a view element and returns
|
|
340
|
+
* @param config Conversion configuration.
|
|
341
|
+
* @param config.view Pattern matching all view elements which should be converted.
|
|
342
|
+
* @param config.model Name of the model marker, or a function that takes a view element and returns
|
|
334
343
|
* a model marker name.
|
|
335
|
-
* @param
|
|
336
|
-
* @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
|
|
344
|
+
* @param config.converterPriority Converter priority.
|
|
337
345
|
*/
|
|
338
346
|
elementToMarker(config) {
|
|
339
347
|
return this.add(upcastElementToMarker(config));
|
|
@@ -358,52 +366,56 @@ export default class UpcastHelpers extends ConversionHelpers {
|
|
|
358
366
|
*
|
|
359
367
|
* Basic usage:
|
|
360
368
|
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
+
* ```ts
|
|
370
|
+
* // Using the default conversion.
|
|
371
|
+
* // In this case, all markers from the `comment` group will be converted.
|
|
372
|
+
* // The conversion will look for `<comment-start>` and `<comment-end>` tags and
|
|
373
|
+
* // `data-comment-start-before`, `data-comment-start-after`,
|
|
374
|
+
* // `data-comment-end-before` and `data-comment-end-after` attributes.
|
|
375
|
+
* editor.conversion.for( 'upcast' ).dataToMarker( {
|
|
376
|
+
* view: 'comment'
|
|
377
|
+
* } );
|
|
378
|
+
* ```
|
|
369
379
|
*
|
|
370
380
|
* An example of a model that may be generated by this conversion:
|
|
371
381
|
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
382
|
+
* ```
|
|
383
|
+
* // View:
|
|
384
|
+
* <p>Foo<comment-start name="commentId:uid"></comment-start>bar</p>
|
|
385
|
+
* <figure data-comment-end-after="commentId:uid" class="image"><img src="abc.jpg" /></figure>
|
|
375
386
|
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
387
|
+
* // Model:
|
|
388
|
+
* <paragraph>Foo[bar</paragraph>
|
|
389
|
+
* <imageBlock src="abc.jpg"></imageBlock>]
|
|
390
|
+
* ```
|
|
379
391
|
*
|
|
380
392
|
* Where `[]` are boundaries of a marker that will receive the `comment:commentId:uid` name.
|
|
381
393
|
*
|
|
382
394
|
* Other examples of usage:
|
|
383
395
|
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
+
* ```ts
|
|
397
|
+
* // Using a custom function which is the same as the default conversion:
|
|
398
|
+
* editor.conversion.for( 'upcast' ).dataToMarker( {
|
|
399
|
+
* view: 'comment',
|
|
400
|
+
* model: ( name, conversionApi ) => 'comment:' + name,
|
|
401
|
+
* } );
|
|
402
|
+
*
|
|
403
|
+
* // Using the converter priority:
|
|
404
|
+
* editor.conversion.for( 'upcast' ).dataToMarker( {
|
|
405
|
+
* view: 'comment',
|
|
406
|
+
* model: ( name, conversionApi ) => 'comment:' + name,
|
|
407
|
+
* converterPriority: 'high'
|
|
408
|
+
* } );
|
|
409
|
+
* ```
|
|
396
410
|
*
|
|
397
411
|
* See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
|
|
398
412
|
* to the conversion process.
|
|
399
413
|
*
|
|
400
|
-
* @
|
|
401
|
-
* @param
|
|
402
|
-
* @param
|
|
403
|
-
* @param {Function} [config.model] A function that takes the `name` part from the view element or attribute and
|
|
414
|
+
* @param config Conversion configuration.
|
|
415
|
+
* @param config.view The marker group name to convert.
|
|
416
|
+
* @param config.model A function that takes the `name` part from the view element or attribute and
|
|
404
417
|
* {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API} and returns the marker name.
|
|
405
|
-
* @param
|
|
406
|
-
* @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
|
|
418
|
+
* @param config.converterPriority Converter priority.
|
|
407
419
|
*/
|
|
408
420
|
dataToMarker(config) {
|
|
409
421
|
return this.add(upcastDataToMarker(config));
|
|
@@ -420,7 +432,7 @@ export default class UpcastHelpers extends ConversionHelpers {
|
|
|
420
432
|
* When a view element is being converted to the model but it does not have converter specified, that view element
|
|
421
433
|
* will be converted to {@link module:engine/model/documentfragment~DocumentFragment model document fragment} and returned.
|
|
422
434
|
*
|
|
423
|
-
* @returns
|
|
435
|
+
* @returns Universal converter for view {@link module:engine/view/documentfragment~DocumentFragment fragments} and
|
|
424
436
|
* {@link module:engine/view/element~Element elements} that returns
|
|
425
437
|
* {@link module:engine/model/documentfragment~DocumentFragment model fragment} with children of converted view item.
|
|
426
438
|
*/
|
|
@@ -437,7 +449,7 @@ export function convertToModelFragment() {
|
|
|
437
449
|
/**
|
|
438
450
|
* Function factory, creates a converter that converts {@link module:engine/view/text~Text} to {@link module:engine/model/text~Text}.
|
|
439
451
|
*
|
|
440
|
-
* @returns {
|
|
452
|
+
* @returns {@link module:engine/view/text~Text View text} converter.
|
|
441
453
|
*/
|
|
442
454
|
export function convertText() {
|
|
443
455
|
return (evt, data, { schema, consumable, writer }) => {
|
|
@@ -478,11 +490,13 @@ export function convertText() {
|
|
|
478
490
|
* **Note**: because there is no view selection change dispatcher nor any other advanced view selection to model
|
|
479
491
|
* conversion mechanism, the callback should be set directly on view document.
|
|
480
492
|
*
|
|
481
|
-
*
|
|
493
|
+
* ```ts
|
|
494
|
+
* view.document.on( 'selectionChange', convertSelectionChange( modelDocument, mapper ) );
|
|
495
|
+
* ```
|
|
482
496
|
*
|
|
483
|
-
* @param
|
|
484
|
-
* @param
|
|
485
|
-
* @returns {
|
|
497
|
+
* @param model Data model.
|
|
498
|
+
* @param mapper Conversion mapper.
|
|
499
|
+
* @returns {@link module:engine/view/document~Document#event:selectionChange} callback function.
|
|
486
500
|
*/
|
|
487
501
|
export function convertSelectionChange(model, mapper) {
|
|
488
502
|
return (evt, data) => {
|
|
@@ -499,17 +513,19 @@ export function convertSelectionChange(model, mapper) {
|
|
|
499
513
|
}
|
|
500
514
|
};
|
|
501
515
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
516
|
+
/**
|
|
517
|
+
* View element to model element conversion helper.
|
|
518
|
+
*
|
|
519
|
+
* See {@link ~UpcastHelpers#elementToElement `.elementToElement()` upcast helper} for examples.
|
|
520
|
+
*
|
|
521
|
+
* @param config Conversion configuration.
|
|
522
|
+
* @param config.view Pattern matching all view elements which should be converted. If not
|
|
523
|
+
* set, the converter will fire for every view element.
|
|
524
|
+
* @param config.model Name of the model element, a model element
|
|
525
|
+
* instance or a function that takes a view element and returns a model element. The model element will be inserted in the model.
|
|
526
|
+
* @param config.converterPriority Converter priority.
|
|
527
|
+
* @returns Conversion helper.
|
|
528
|
+
*/
|
|
513
529
|
function upcastElementToElement(config) {
|
|
514
530
|
config = cloneDeep(config);
|
|
515
531
|
const converter = prepareToElementConverter(config);
|
|
@@ -519,17 +535,19 @@ function upcastElementToElement(config) {
|
|
|
519
535
|
dispatcher.on(eventName, converter, { priority: config.converterPriority || 'normal' });
|
|
520
536
|
};
|
|
521
537
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
538
|
+
/**
|
|
539
|
+
* View element to model attribute conversion helper.
|
|
540
|
+
*
|
|
541
|
+
* See {@link ~UpcastHelpers#elementToAttribute `.elementToAttribute()` upcast helper} for examples.
|
|
542
|
+
*
|
|
543
|
+
* @param config Conversion configuration.
|
|
544
|
+
* @param config.view Pattern matching all view elements which should be converted.
|
|
545
|
+
* @param config.model Model attribute key or an object with `key` and `value` properties, describing
|
|
546
|
+
* the model attribute. `value` property may be set as a function that takes a view element and returns the value.
|
|
547
|
+
* If `String` is given, the model attribute value will be set to `true`.
|
|
548
|
+
* @param config.converterPriority Converter priority. Defaults to `low`.
|
|
549
|
+
* @returns Conversion helper.
|
|
550
|
+
*/
|
|
533
551
|
function upcastElementToAttribute(config) {
|
|
534
552
|
config = cloneDeep(config);
|
|
535
553
|
normalizeModelAttributeConfig(config);
|
|
@@ -540,21 +558,23 @@ function upcastElementToAttribute(config) {
|
|
|
540
558
|
dispatcher.on(eventName, converter, { priority: config.converterPriority || 'low' });
|
|
541
559
|
};
|
|
542
560
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
561
|
+
/**
|
|
562
|
+
* View attribute to model attribute conversion helper.
|
|
563
|
+
*
|
|
564
|
+
* See {@link ~UpcastHelpers#attributeToAttribute `.attributeToAttribute()` upcast helper} for examples.
|
|
565
|
+
*
|
|
566
|
+
* @param config Conversion configuration.
|
|
567
|
+
* @param config.view Specifies which view attribute will be converted. If a `String` is passed,
|
|
568
|
+
* attributes with given key will be converted. If an `Object` is passed, it must have a required `key` property,
|
|
569
|
+
* specifying view attribute key, and may have an optional `value` property, specifying view attribute value and optional `name`
|
|
570
|
+
* property specifying a view element name from/on which the attribute should be converted. `value` can be given as a `String`,
|
|
571
|
+
* a `RegExp` or a function callback, that takes view attribute value as the only parameter and returns `Boolean`.
|
|
572
|
+
* @param config.model Model attribute key or an object with `key` and `value` properties, describing
|
|
573
|
+
* the model attribute. `value` property may be set as a function that takes a view element and returns the value.
|
|
574
|
+
* If `String` is given, the model attribute value will be same as view attribute value.
|
|
575
|
+
* @param config.converterPriority Converter priority. Defaults to `low`.
|
|
576
|
+
* @returns Conversion helper.
|
|
577
|
+
*/
|
|
558
578
|
function upcastAttributeToAttribute(config) {
|
|
559
579
|
config = cloneDeep(config);
|
|
560
580
|
let viewKey = null;
|
|
@@ -567,29 +587,29 @@ function upcastAttributeToAttribute(config) {
|
|
|
567
587
|
dispatcher.on('element', converter, { priority: config.converterPriority || 'low' });
|
|
568
588
|
};
|
|
569
589
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
590
|
+
/**
|
|
591
|
+
* View element to model marker conversion helper.
|
|
592
|
+
*
|
|
593
|
+
* See {@link ~UpcastHelpers#elementToMarker `.elementToMarker()` upcast helper} for examples.
|
|
594
|
+
*
|
|
595
|
+
* @param config Conversion configuration.
|
|
596
|
+
* @param config.view Pattern matching all view elements which should be converted.
|
|
597
|
+
* @param config.model Name of the model marker, or a function that takes a view element and returns
|
|
598
|
+
* a model marker name.
|
|
599
|
+
* @param config.converterPriority Converter priority.
|
|
600
|
+
* @returns Conversion helper.
|
|
601
|
+
*/
|
|
580
602
|
function upcastElementToMarker(config) {
|
|
581
603
|
const model = normalizeElementToMarkerModelConfig(config.model);
|
|
582
604
|
return upcastElementToElement({ ...config, model });
|
|
583
605
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
// @param {module:utils/priorities~PriorityString} [config.converterPriority='normal']
|
|
592
|
-
// @returns {Function} Conversion helper.
|
|
606
|
+
/**
|
|
607
|
+
* View data to model marker conversion helper.
|
|
608
|
+
*
|
|
609
|
+
* See {@link ~UpcastHelpers#dataToMarker} to learn more.
|
|
610
|
+
*
|
|
611
|
+
* @returns Conversion helper.
|
|
612
|
+
*/
|
|
593
613
|
function upcastDataToMarker(config) {
|
|
594
614
|
config = cloneDeep(config);
|
|
595
615
|
// Default conversion.
|
|
@@ -625,16 +645,15 @@ function upcastDataToMarker(config) {
|
|
|
625
645
|
dispatcher.on('element', upcastAttributeToMarker(normalizedConfig), { priority: basePriority + priorityFactor });
|
|
626
646
|
};
|
|
627
647
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
// @returns {Function} Marker converter.
|
|
648
|
+
/**
|
|
649
|
+
* Function factory, returns a callback function which converts view attributes to a model marker.
|
|
650
|
+
*
|
|
651
|
+
* The converter looks for elements with `data-group-start-before`, `data-group-start-after`, `data-group-end-before`
|
|
652
|
+
* and `data-group-end-after` attributes and inserts `$marker` model elements before/after those elements.
|
|
653
|
+
* `group` part is specified in `config.view`.
|
|
654
|
+
*
|
|
655
|
+
* @returns Marker converter.
|
|
656
|
+
*/
|
|
638
657
|
function upcastAttributeToMarker(config) {
|
|
639
658
|
return (evt, data, conversionApi) => {
|
|
640
659
|
const attrName = `data-${config.view}`;
|
|
@@ -681,11 +700,13 @@ function upcastAttributeToMarker(config) {
|
|
|
681
700
|
}
|
|
682
701
|
};
|
|
683
702
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
703
|
+
/**
|
|
704
|
+
* Helper function for from-view-element conversion. Checks if `config.view` directly specifies converted view element's name
|
|
705
|
+
* and if so, returns it.
|
|
706
|
+
*
|
|
707
|
+
* @param config Conversion view config.
|
|
708
|
+
* @returns View element name or `null` if name is not directly set.
|
|
709
|
+
*/
|
|
689
710
|
function getViewElementNameFromConfig(viewConfig) {
|
|
690
711
|
if (typeof viewConfig == 'string') {
|
|
691
712
|
return viewConfig;
|
|
@@ -695,10 +716,12 @@ function getViewElementNameFromConfig(viewConfig) {
|
|
|
695
716
|
}
|
|
696
717
|
return null;
|
|
697
718
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
719
|
+
/**
|
|
720
|
+
* Helper for to-model-element conversion. Takes a config object and returns a proper converter function.
|
|
721
|
+
*
|
|
722
|
+
* @param config Conversion configuration.
|
|
723
|
+
* @returns View to model converter.
|
|
724
|
+
*/
|
|
702
725
|
function prepareToElementConverter(config) {
|
|
703
726
|
const matcher = new Matcher(config.view);
|
|
704
727
|
return (evt, data, conversionApi) => {
|
|
@@ -724,12 +747,14 @@ function prepareToElementConverter(config) {
|
|
|
724
747
|
conversionApi.updateConversionResult(modelElement, data);
|
|
725
748
|
};
|
|
726
749
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
750
|
+
/**
|
|
751
|
+
* Helper function for upcasting-to-element converter. Takes the model configuration, the converted view element
|
|
752
|
+
* and a writer instance and returns a model element instance to be inserted in the model.
|
|
753
|
+
*
|
|
754
|
+
* @param model Model conversion configuration.
|
|
755
|
+
* @param input The converted view node.
|
|
756
|
+
* @param conversionApi The upcast conversion API.
|
|
757
|
+
*/
|
|
733
758
|
function getModelElement(model, input, conversionApi) {
|
|
734
759
|
if (model instanceof Function) {
|
|
735
760
|
return model(input, conversionApi);
|
|
@@ -738,12 +763,14 @@ function getModelElement(model, input, conversionApi) {
|
|
|
738
763
|
return conversionApi.writer.createElement(model);
|
|
739
764
|
}
|
|
740
765
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
766
|
+
/**
|
|
767
|
+
* Helper function view-attribute-to-model-attribute helper. Normalizes `config.view` which was set as `String` or
|
|
768
|
+
* as an `Object` with `key`, `value` and `name` properties. Normalized `config.view` has is compatible with
|
|
769
|
+
* {@link module:engine/view/matcher~MatcherPattern}.
|
|
770
|
+
*
|
|
771
|
+
* @param config Conversion config.
|
|
772
|
+
* @returns Key of the converted view attribute.
|
|
773
|
+
*/
|
|
747
774
|
function normalizeViewAttributeKeyValueConfig(config) {
|
|
748
775
|
if (typeof config.view == 'string') {
|
|
749
776
|
config.view = { key: config.view };
|
|
@@ -770,13 +797,15 @@ function normalizeViewAttributeKeyValueConfig(config) {
|
|
|
770
797
|
config.view = normalized;
|
|
771
798
|
return key;
|
|
772
799
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
800
|
+
/**
|
|
801
|
+
* Helper function that normalizes `config.model` in from-model-attribute conversion. `config.model` can be set
|
|
802
|
+
* as a `String`, an `Object` with only `key` property or an `Object` with `key` and `value` properties. Normalized
|
|
803
|
+
* `config.model` is an `Object` with `key` and `value` properties.
|
|
804
|
+
*
|
|
805
|
+
* @param config Conversion config.
|
|
806
|
+
* @param viewAttributeKeyToCopy Key of the converted view attribute. If it is set, model attribute value
|
|
807
|
+
* will be equal to view attribute value.
|
|
808
|
+
*/
|
|
780
809
|
function normalizeModelAttributeConfig(config, viewAttributeKeyToCopy = null) {
|
|
781
810
|
const defaultModelValue = viewAttributeKeyToCopy === null ? true :
|
|
782
811
|
(viewElement) => viewElement.getAttribute(viewAttributeKeyToCopy);
|
|
@@ -784,13 +813,14 @@ function normalizeModelAttributeConfig(config, viewAttributeKeyToCopy = null) {
|
|
|
784
813
|
const value = typeof config.model != 'object' || typeof config.model.value == 'undefined' ? defaultModelValue : config.model.value;
|
|
785
814
|
config.model = { key, value };
|
|
786
815
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
816
|
+
/**
|
|
817
|
+
* Helper for to-model-attribute conversion. Takes the model attribute name and conversion configuration and returns
|
|
818
|
+
* a proper converter function.
|
|
819
|
+
*
|
|
820
|
+
* @param config Conversion configuration. It is possible to provide multiple configurations in an array.
|
|
821
|
+
* @param shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
|
|
822
|
+
* on all elements in the range.
|
|
823
|
+
*/
|
|
794
824
|
function prepareToAttributeConverter(config, shallow) {
|
|
795
825
|
const matcher = new Matcher(config.view);
|
|
796
826
|
return (evt, data, conversionApi) => {
|
|
@@ -847,10 +877,11 @@ function prepareToAttributeConverter(config, shallow) {
|
|
|
847
877
|
}
|
|
848
878
|
};
|
|
849
879
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
880
|
+
/**
|
|
881
|
+
* Helper function that checks if element name should be consumed in attribute converters.
|
|
882
|
+
*
|
|
883
|
+
* @param viewConfig Conversion view config.
|
|
884
|
+
*/
|
|
854
885
|
function onlyViewNameIsDefined(viewConfig, viewItem) {
|
|
855
886
|
// https://github.com/ckeditor/ckeditor5-engine/issues/1786
|
|
856
887
|
const configToTest = typeof viewConfig == 'function' ? viewConfig(viewItem) : viewConfig;
|
|
@@ -859,17 +890,19 @@ function onlyViewNameIsDefined(viewConfig, viewItem) {
|
|
|
859
890
|
}
|
|
860
891
|
return !configToTest.classes && !configToTest.attributes && !configToTest.styles;
|
|
861
892
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
893
|
+
/**
|
|
894
|
+
* Helper function for to-model-attribute converter. Sets model attribute on given range. Checks {@link module:engine/model/schema~Schema}
|
|
895
|
+
* to ensure proper model structure.
|
|
896
|
+
*
|
|
897
|
+
* If any node on the given range has already defined an attribute with the same name, its value will not be updated.
|
|
898
|
+
*
|
|
899
|
+
* @param modelRange Model range on which attribute should be set.
|
|
900
|
+
* @param modelAttribute Model attribute to set.
|
|
901
|
+
* @param conversionApi Conversion API.
|
|
902
|
+
* @param shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
|
|
903
|
+
* on all elements in the range.
|
|
904
|
+
* @returns `true` if attribute was set on at least one node from given `modelRange`.
|
|
905
|
+
*/
|
|
873
906
|
function setAttributeOn(modelRange, modelAttribute, shallow, conversionApi) {
|
|
874
907
|
let result = false;
|
|
875
908
|
// Set attribute on each item in range according to Schema.
|
|
@@ -889,20 +922,20 @@ function setAttributeOn(modelRange, modelAttribute, shallow, conversionApi) {
|
|
|
889
922
|
}
|
|
890
923
|
return result;
|
|
891
924
|
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
925
|
+
/**
|
|
926
|
+
* Helper function for upcasting-to-marker conversion. Takes the config in a format requested by `upcastElementToMarker()`
|
|
927
|
+
* function and converts it to a format that is supported by `upcastElementToElement()` function.
|
|
928
|
+
*/
|
|
896
929
|
function normalizeElementToMarkerModelConfig(model) {
|
|
897
930
|
return (viewElement, conversionApi) => {
|
|
898
931
|
const markerName = typeof model == 'string' ? model : model(viewElement, conversionApi);
|
|
899
932
|
return conversionApi.writer.createElement('$marker', { 'data-name': markerName });
|
|
900
933
|
};
|
|
901
934
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
935
|
+
/**
|
|
936
|
+
* Helper function for upcasting-to-marker conversion. Takes the config in a format requested by `upcastDataToMarker()`
|
|
937
|
+
* function and converts it to a format that is supported by `upcastElementToElement()` function.
|
|
938
|
+
*/
|
|
906
939
|
function normalizeDataToMarkerConfig(config, type) {
|
|
907
940
|
const elementCreatorFunction = (viewElement, conversionApi) => {
|
|
908
941
|
const viewName = viewElement.getAttribute('name');
|