@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.1
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 +25 -24
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +72 -116
- 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 +503 -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 +369 -0
- package/src/conversion/viewconsumable.js +139 -173
- 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 +108 -0
- package/src/index.js +4 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +246 -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 +885 -0
- package/src/model/model.js +59 -81
- 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/mergeoperation.js +1 -1
- 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/splitoperation.js +1 -1
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/operation/utils.js +1 -1
- 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 +19 -19
- 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 +285 -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 +823 -0
- package/src/model/writer.js +6 -61
- 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 +149 -0
- package/src/view/documentfragment.js +39 -81
- package/src/view/documentselection.d.ts +306 -0
- package/src/view/documentselection.js +42 -143
- package/src/view/domconverter.d.ts +650 -0
- package/src/view/domconverter.js +157 -283
- package/src/view/downcastwriter.d.ts +996 -0
- package/src/view/downcastwriter.js +259 -426
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +468 -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 +163 -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 +43 -0
- package/src/view/observer/fakeselectionobserver.js +0 -16
- 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 +66 -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 +144 -0
- package/src/view/observer/selectionobserver.js +17 -107
- 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 +448 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +29 -63
- package/src/view/upcastwriter.d.ts +417 -0
- package/src/view/upcastwriter.js +86 -157
- package/src/view/view.d.ts +417 -0
- package/src/view/view.js +47 -175
|
@@ -17,61 +17,31 @@ import { isArray } from 'lodash-es';
|
|
|
17
17
|
* To consume items use {@link module:engine/conversion/viewconsumable~ViewConsumable#consume consume method}.
|
|
18
18
|
* To revert already consumed items use {@link module:engine/conversion/viewconsumable~ViewConsumable#revert revert method}.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* viewConsumable.add( element, { name: true } ); // Adds element's name as ready to be consumed.
|
|
22
|
+
* viewConsumable.add( textNode ); // Adds text node for consumption.
|
|
23
|
+
* viewConsumable.add( docFragment ); // Adds document fragment for consumption.
|
|
24
|
+
* viewConsumable.test( element, { name: true } ); // Tests if element's name can be consumed.
|
|
25
|
+
* viewConsumable.test( textNode ); // Tests if text node can be consumed.
|
|
26
|
+
* viewConsumable.test( docFragment ); // Tests if document fragment can be consumed.
|
|
27
|
+
* viewConsumable.consume( element, { name: true } ); // Consume element's name.
|
|
28
|
+
* viewConsumable.consume( textNode ); // Consume text node.
|
|
29
|
+
* viewConsumable.consume( docFragment ); // Consume document fragment.
|
|
30
|
+
* viewConsumable.revert( element, { name: true } ); // Revert already consumed element's name.
|
|
31
|
+
* viewConsumable.revert( textNode ); // Revert already consumed text node.
|
|
32
|
+
* viewConsumable.revert( docFragment ); // Revert already consumed document fragment.
|
|
33
|
+
* ```
|
|
32
34
|
*/
|
|
33
35
|
export default class ViewConsumable {
|
|
34
|
-
/**
|
|
35
|
-
* Creates new ViewConsumable.
|
|
36
|
-
*/
|
|
37
36
|
constructor() {
|
|
38
37
|
/**
|
|
39
38
|
* Map of consumable elements. If {@link module:engine/view/element~Element element} is used as a key,
|
|
40
39
|
* {@link module:engine/conversion/viewconsumable~ViewElementConsumables ViewElementConsumables} instance is stored as value.
|
|
41
40
|
* For {@link module:engine/view/text~Text text nodes} and
|
|
42
41
|
* {@link module:engine/view/documentfragment~DocumentFragment document fragments} boolean value is stored as value.
|
|
43
|
-
|
|
44
|
-
* @protected
|
|
45
|
-
* @member {Map.<module:engine/conversion/viewconsumable~ViewElementConsumables|Boolean>}
|
|
46
|
-
*/
|
|
42
|
+
*/
|
|
47
43
|
this._consumables = new Map();
|
|
48
44
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Adds {@link module:engine/view/element~Element view element}, {@link module:engine/view/text~Text text node} or
|
|
51
|
-
* {@link module:engine/view/documentfragment~DocumentFragment document fragment} as ready to be consumed.
|
|
52
|
-
*
|
|
53
|
-
* viewConsumable.add( p, { name: true } ); // Adds element's name to consume.
|
|
54
|
-
* viewConsumable.add( p, { attributes: 'name' } ); // Adds element's attribute.
|
|
55
|
-
* viewConsumable.add( p, { classes: 'foobar' } ); // Adds element's class.
|
|
56
|
-
* viewConsumable.add( p, { styles: 'color' } ); // Adds element's style
|
|
57
|
-
* viewConsumable.add( p, { attributes: 'name', styles: 'color' } ); // Adds attribute and style.
|
|
58
|
-
* viewConsumable.add( p, { classes: [ 'baz', 'bar' ] } ); // Multiple consumables can be provided.
|
|
59
|
-
* viewConsumable.add( textNode ); // Adds text node to consume.
|
|
60
|
-
* viewConsumable.add( docFragment ); // Adds document fragment to consume.
|
|
61
|
-
*
|
|
62
|
-
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `viewconsumable-invalid-attribute` when `class` or `style`
|
|
63
|
-
* attribute is provided - it should be handled separately by providing actual style/class.
|
|
64
|
-
*
|
|
65
|
-
* viewConsumable.add( p, { attributes: 'style' } ); // This call will throw an exception.
|
|
66
|
-
* viewConsumable.add( p, { styles: 'color' } ); // This is properly handled style.
|
|
67
|
-
*
|
|
68
|
-
* @param {module:engine/view/element~Element|module:engine/view/text~Text|module:engine/view/documentfragment~DocumentFragment} element
|
|
69
|
-
* @param {Object} [consumables] Used only if first parameter is {@link module:engine/view/element~Element view element} instance.
|
|
70
|
-
* @param {Boolean} consumables.name If set to true element's name will be included.
|
|
71
|
-
* @param {String|Array.<String>} consumables.attributes Attribute name or array of attribute names.
|
|
72
|
-
* @param {String|Array.<String>} consumables.classes Class name or array of class names.
|
|
73
|
-
* @param {String|Array.<String>} consumables.styles Style name or array of style names.
|
|
74
|
-
*/
|
|
75
45
|
add(element, consumables) {
|
|
76
46
|
let elementConsumables;
|
|
77
47
|
// For text nodes and document fragments just mark them as consumable.
|
|
@@ -95,27 +65,30 @@ export default class ViewConsumable {
|
|
|
95
65
|
* It returns `true` when all items included in method's call can be consumed. Returns `false` when
|
|
96
66
|
* first already consumed item is found and `null` when first non-consumable item is found.
|
|
97
67
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* viewConsumable.test( p, { name: true } ); // Tests element's name.
|
|
70
|
+
* viewConsumable.test( p, { attributes: 'name' } ); // Tests attribute.
|
|
71
|
+
* viewConsumable.test( p, { classes: 'foobar' } ); // Tests class.
|
|
72
|
+
* viewConsumable.test( p, { styles: 'color' } ); // Tests style.
|
|
73
|
+
* viewConsumable.test( p, { attributes: 'name', styles: 'color' } ); // Tests attribute and style.
|
|
74
|
+
* viewConsumable.test( p, { classes: [ 'baz', 'bar' ] } ); // Multiple consumables can be tested.
|
|
75
|
+
* viewConsumable.test( textNode ); // Tests text node.
|
|
76
|
+
* viewConsumable.test( docFragment ); // Tests document fragment.
|
|
77
|
+
* ```
|
|
106
78
|
*
|
|
107
79
|
* Testing classes and styles as attribute will test if all added classes/styles can be consumed.
|
|
108
80
|
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @
|
|
81
|
+
* ```ts
|
|
82
|
+
* viewConsumable.test( p, { attributes: 'class' } ); // Tests if all added classes can be consumed.
|
|
83
|
+
* viewConsumable.test( p, { attributes: 'style' } ); // Tests if all added styles can be consumed.
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param consumables Used only if first parameter is {@link module:engine/view/element~Element view element} instance.
|
|
87
|
+
* @param consumables.name If set to true element's name will be included.
|
|
88
|
+
* @param consumables.attributes Attribute name or array of attribute names.
|
|
89
|
+
* @param consumables.classes Class name or array of class names.
|
|
90
|
+
* @param consumables.styles Style name or array of style names.
|
|
91
|
+
* @returns Returns `true` when all items included in method's call can be consumed. Returns `false`
|
|
119
92
|
* when first already consumed item is found and `null` when first non-consumable item is found.
|
|
120
93
|
*/
|
|
121
94
|
test(element, consumables) {
|
|
@@ -135,27 +108,30 @@ export default class ViewConsumable {
|
|
|
135
108
|
* {@link module:engine/view/documentfragment~DocumentFragment document fragment}.
|
|
136
109
|
* It returns `true` when all items included in method's call can be consumed, otherwise returns `false`.
|
|
137
110
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* viewConsumable.consume( p, { name: true } ); // Consumes element's name.
|
|
113
|
+
* viewConsumable.consume( p, { attributes: 'name' } ); // Consumes element's attribute.
|
|
114
|
+
* viewConsumable.consume( p, { classes: 'foobar' } ); // Consumes element's class.
|
|
115
|
+
* viewConsumable.consume( p, { styles: 'color' } ); // Consumes element's style.
|
|
116
|
+
* viewConsumable.consume( p, { attributes: 'name', styles: 'color' } ); // Consumes attribute and style.
|
|
117
|
+
* viewConsumable.consume( p, { classes: [ 'baz', 'bar' ] } ); // Multiple consumables can be consumed.
|
|
118
|
+
* viewConsumable.consume( textNode ); // Consumes text node.
|
|
119
|
+
* viewConsumable.consume( docFragment ); // Consumes document fragment.
|
|
120
|
+
* ```
|
|
146
121
|
*
|
|
147
122
|
* Consuming classes and styles as attribute will test if all added classes/styles can be consumed.
|
|
148
123
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
156
|
-
* @param
|
|
157
|
-
* @param
|
|
158
|
-
* @
|
|
124
|
+
* ```ts
|
|
125
|
+
* viewConsumable.consume( p, { attributes: 'class' } ); // Consume only if all added classes can be consumed.
|
|
126
|
+
* viewConsumable.consume( p, { attributes: 'style' } ); // Consume only if all added styles can be consumed.
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @param consumables Used only if first parameter is {@link module:engine/view/element~Element view element} instance.
|
|
130
|
+
* @param consumables.name If set to true element's name will be included.
|
|
131
|
+
* @param consumables.attributes Attribute name or array of attribute names.
|
|
132
|
+
* @param consumables.classes Class name or array of class names.
|
|
133
|
+
* @param consumables.styles Style name or array of style names.
|
|
134
|
+
* @returns Returns `true` when all items included in method's call can be consumed,
|
|
159
135
|
* otherwise returns `false`.
|
|
160
136
|
*/
|
|
161
137
|
consume(element, consumables) {
|
|
@@ -178,27 +154,30 @@ export default class ViewConsumable {
|
|
|
178
154
|
* Method does not revert items that were never previously added for consumption, even if they are included in
|
|
179
155
|
* method's call.
|
|
180
156
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* viewConsumable.revert( p, { name: true } ); // Reverts element's name.
|
|
159
|
+
* viewConsumable.revert( p, { attributes: 'name' } ); // Reverts element's attribute.
|
|
160
|
+
* viewConsumable.revert( p, { classes: 'foobar' } ); // Reverts element's class.
|
|
161
|
+
* viewConsumable.revert( p, { styles: 'color' } ); // Reverts element's style.
|
|
162
|
+
* viewConsumable.revert( p, { attributes: 'name', styles: 'color' } ); // Reverts attribute and style.
|
|
163
|
+
* viewConsumable.revert( p, { classes: [ 'baz', 'bar' ] } ); // Multiple names can be reverted.
|
|
164
|
+
* viewConsumable.revert( textNode ); // Reverts text node.
|
|
165
|
+
* viewConsumable.revert( docFragment ); // Reverts document fragment.
|
|
166
|
+
* ```
|
|
189
167
|
*
|
|
190
168
|
* Reverting classes and styles as attribute will revert all classes/styles that were previously added for
|
|
191
169
|
* consumption.
|
|
192
170
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* viewConsumable.revert( p, { attributes: 'class' } ); // Reverts all classes added for consumption.
|
|
173
|
+
* viewConsumable.revert( p, { attributes: 'style' } ); // Reverts all styles added for consumption.
|
|
174
|
+
* ```
|
|
195
175
|
*
|
|
196
|
-
* @param {module:engine/view/element~Element
|
|
197
|
-
* @param
|
|
198
|
-
* @param
|
|
199
|
-
* @param
|
|
200
|
-
* @param
|
|
201
|
-
* @param {String|Array.<String>} consumables.styles Style name or array of style names.
|
|
176
|
+
* @param consumables Used only if first parameter is {@link module:engine/view/element~Element view element} instance.
|
|
177
|
+
* @param consumables.name If set to true element's name will be included.
|
|
178
|
+
* @param consumables.attributes Attribute name or array of attribute names.
|
|
179
|
+
* @param consumables.classes Class name or array of class names.
|
|
180
|
+
* @param consumables.styles Style name or array of style names.
|
|
202
181
|
*/
|
|
203
182
|
revert(element, consumables) {
|
|
204
183
|
const elementConsumables = this._consumables.get(element);
|
|
@@ -216,10 +195,6 @@ export default class ViewConsumable {
|
|
|
216
195
|
/**
|
|
217
196
|
* Creates consumable object from {@link module:engine/view/element~Element view element}. Consumable object will include
|
|
218
197
|
* element's name and all its attributes, classes and styles.
|
|
219
|
-
*
|
|
220
|
-
* @static
|
|
221
|
-
* @param {module:engine/view/element~Element} element
|
|
222
|
-
* @returns {Object} consumables
|
|
223
198
|
*/
|
|
224
199
|
static consumablesFromElement(element) {
|
|
225
200
|
const consumables = {
|
|
@@ -252,10 +227,8 @@ export default class ViewConsumable {
|
|
|
252
227
|
* {@link module:engine/view/node~Node node} or {@link module:engine/view/documentfragment~DocumentFragment document fragment}.
|
|
253
228
|
* Instance will contain all elements, child nodes, attributes, styles and classes added for consumption.
|
|
254
229
|
*
|
|
255
|
-
* @
|
|
256
|
-
* @param
|
|
257
|
-
* from which `ViewConsumable` will be created.
|
|
258
|
-
* @param {module:engine/conversion/viewconsumable~ViewConsumable} [instance] If provided, given `ViewConsumable` instance will be used
|
|
230
|
+
* @param from View node or document fragment from which `ViewConsumable` will be created.
|
|
231
|
+
* @param instance If provided, given `ViewConsumable` instance will be used
|
|
259
232
|
* to add all consumables. It will be returned instead of a new instance.
|
|
260
233
|
*/
|
|
261
234
|
static createFrom(from, instance) {
|
|
@@ -283,35 +256,16 @@ const CONSUMABLE_TYPES = ['attributes', 'classes', 'styles'];
|
|
|
283
256
|
/**
|
|
284
257
|
* This is a private helper-class for {@link module:engine/conversion/viewconsumable~ViewConsumable}.
|
|
285
258
|
* It represents and manipulates consumable parts of a single {@link module:engine/view/element~Element}.
|
|
286
|
-
*
|
|
287
|
-
* @private
|
|
288
259
|
*/
|
|
289
|
-
class ViewElementConsumables {
|
|
260
|
+
export class ViewElementConsumables {
|
|
290
261
|
/**
|
|
291
262
|
* Creates ViewElementConsumables instance.
|
|
292
263
|
*
|
|
293
|
-
* @param
|
|
294
|
-
* from which `ViewElementConsumables` is being created.
|
|
264
|
+
* @param from View node or document fragment from which `ViewElementConsumables` is being created.
|
|
295
265
|
*/
|
|
296
266
|
constructor(from) {
|
|
297
|
-
/**
|
|
298
|
-
* @readonly
|
|
299
|
-
* @member {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment}
|
|
300
|
-
*/
|
|
301
267
|
this.element = from;
|
|
302
|
-
/**
|
|
303
|
-
* Flag indicating if name of the element can be consumed.
|
|
304
|
-
*
|
|
305
|
-
* @private
|
|
306
|
-
* @member {Boolean}
|
|
307
|
-
*/
|
|
308
268
|
this._canConsumeName = null;
|
|
309
|
-
/**
|
|
310
|
-
* Contains maps of element's consumables: attributes, classes and styles.
|
|
311
|
-
*
|
|
312
|
-
* @private
|
|
313
|
-
* @member {Object}
|
|
314
|
-
*/
|
|
315
269
|
this._consumables = {
|
|
316
270
|
attributes: new Map(),
|
|
317
271
|
styles: new Map(),
|
|
@@ -323,21 +277,25 @@ class ViewElementConsumables {
|
|
|
323
277
|
* Element's name itself can be marked to be consumed (when element's name is consumed its attributes, classes and
|
|
324
278
|
* styles still could be consumed):
|
|
325
279
|
*
|
|
326
|
-
*
|
|
280
|
+
* ```ts
|
|
281
|
+
* consumables.add( { name: true } );
|
|
282
|
+
* ```
|
|
327
283
|
*
|
|
328
284
|
* Attributes classes and styles:
|
|
329
285
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
286
|
+
* ```ts
|
|
287
|
+
* consumables.add( { attributes: 'title', classes: 'foo', styles: 'color' } );
|
|
288
|
+
* consumables.add( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
|
|
289
|
+
* ```
|
|
332
290
|
*
|
|
333
291
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `viewconsumable-invalid-attribute` when `class` or `style`
|
|
334
292
|
* attribute is provided - it should be handled separately by providing `style` and `class` in consumables object.
|
|
335
293
|
*
|
|
336
|
-
* @param
|
|
337
|
-
* @param
|
|
338
|
-
* @param
|
|
339
|
-
* @param
|
|
340
|
-
* @param
|
|
294
|
+
* @param consumables Object describing which parts of the element can be consumed.
|
|
295
|
+
* @param consumables.name If set to `true` element's name will be added as consumable.
|
|
296
|
+
* @param consumables.attributes Attribute name or array of attribute names to add as consumable.
|
|
297
|
+
* @param consumables.classes Class name or array of class names to add as consumable.
|
|
298
|
+
* @param consumables.styles Style name or array of style names to add as consumable.
|
|
341
299
|
*/
|
|
342
300
|
add(consumables) {
|
|
343
301
|
if (consumables.name) {
|
|
@@ -354,19 +312,23 @@ class ViewElementConsumables {
|
|
|
354
312
|
*
|
|
355
313
|
* Element's name can be tested:
|
|
356
314
|
*
|
|
357
|
-
*
|
|
315
|
+
* ```ts
|
|
316
|
+
* consumables.test( { name: true } );
|
|
317
|
+
* ```
|
|
358
318
|
*
|
|
359
319
|
* Attributes classes and styles:
|
|
360
320
|
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* @param
|
|
367
|
-
* @param
|
|
368
|
-
* @param
|
|
369
|
-
* @
|
|
321
|
+
* ```ts
|
|
322
|
+
* consumables.test( { attributes: 'title', classes: 'foo', styles: 'color' } );
|
|
323
|
+
* consumables.test( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @param consumables Object describing which parts of the element should be tested.
|
|
327
|
+
* @param consumables.name If set to `true` element's name will be tested.
|
|
328
|
+
* @param consumables.attributes Attribute name or array of attribute names to test.
|
|
329
|
+
* @param consumables.classes Class name or array of class names to test.
|
|
330
|
+
* @param consumables.styles Style name or array of style names to test.
|
|
331
|
+
* @returns `true` when all tested items can be consumed, `null` when even one of the items
|
|
370
332
|
* was never marked for consumption and `false` when even one of the items was already consumed.
|
|
371
333
|
*/
|
|
372
334
|
test(consumables) {
|
|
@@ -390,18 +352,22 @@ class ViewElementConsumables {
|
|
|
390
352
|
* is already consumed - it consumes all consumable items provided.
|
|
391
353
|
* Element's name can be consumed:
|
|
392
354
|
*
|
|
393
|
-
*
|
|
355
|
+
* ```ts
|
|
356
|
+
* consumables.consume( { name: true } );
|
|
357
|
+
* ```
|
|
394
358
|
*
|
|
395
359
|
* Attributes classes and styles:
|
|
396
360
|
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
361
|
+
* ```ts
|
|
362
|
+
* consumables.consume( { attributes: 'title', classes: 'foo', styles: 'color' } );
|
|
363
|
+
* consumables.consume( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
|
|
364
|
+
* ```
|
|
399
365
|
*
|
|
400
|
-
* @param
|
|
401
|
-
* @param
|
|
402
|
-
* @param
|
|
403
|
-
* @param
|
|
404
|
-
* @param
|
|
366
|
+
* @param consumables Object describing which parts of the element should be consumed.
|
|
367
|
+
* @param consumables.name If set to `true` element's name will be consumed.
|
|
368
|
+
* @param consumables.attributes Attribute name or array of attribute names to consume.
|
|
369
|
+
* @param consumables.classes Class name or array of class names to consume.
|
|
370
|
+
* @param consumables.styles Style name or array of style names to consume.
|
|
405
371
|
*/
|
|
406
372
|
consume(consumables) {
|
|
407
373
|
if (consumables.name) {
|
|
@@ -417,18 +383,22 @@ class ViewElementConsumables {
|
|
|
417
383
|
* Revert already consumed parts of {@link module:engine/view/element~Element view Element}, so they can be consumed once again.
|
|
418
384
|
* Element's name can be reverted:
|
|
419
385
|
*
|
|
420
|
-
*
|
|
386
|
+
* ```ts
|
|
387
|
+
* consumables.revert( { name: true } );
|
|
388
|
+
* ```
|
|
421
389
|
*
|
|
422
390
|
* Attributes classes and styles:
|
|
423
391
|
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
392
|
+
* ```ts
|
|
393
|
+
* consumables.revert( { attributes: 'title', classes: 'foo', styles: 'color' } );
|
|
394
|
+
* consumables.revert( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
|
|
395
|
+
* ```
|
|
426
396
|
*
|
|
427
|
-
* @param
|
|
428
|
-
* @param
|
|
429
|
-
* @param
|
|
430
|
-
* @param
|
|
431
|
-
* @param
|
|
397
|
+
* @param consumables Object describing which parts of the element should be reverted.
|
|
398
|
+
* @param consumables.name If set to `true` element's name will be reverted.
|
|
399
|
+
* @param consumables.attributes Attribute name or array of attribute names to revert.
|
|
400
|
+
* @param consumables.classes Class name or array of class names to revert.
|
|
401
|
+
* @param consumables.styles Style name or array of style names to revert.
|
|
432
402
|
*/
|
|
433
403
|
revert(consumables) {
|
|
434
404
|
if (consumables.name) {
|
|
@@ -446,9 +416,8 @@ class ViewElementConsumables {
|
|
|
446
416
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `viewconsumable-invalid-attribute` when `class` or `style`
|
|
447
417
|
* type is provided - it should be handled separately by providing actual style/class type.
|
|
448
418
|
*
|
|
449
|
-
* @
|
|
450
|
-
* @param
|
|
451
|
-
* @param {String|Array.<String>} item Consumable item or array of items.
|
|
419
|
+
* @param type Type of the consumable item: `attributes`, `classes` or `styles`.
|
|
420
|
+
* @param item Consumable item or array of items.
|
|
452
421
|
*/
|
|
453
422
|
_add(type, item) {
|
|
454
423
|
const items = isArray(item) ? item : [item];
|
|
@@ -482,10 +451,9 @@ class ViewElementConsumables {
|
|
|
482
451
|
/**
|
|
483
452
|
* Helper method that tests consumables of a given type: attribute, class or style.
|
|
484
453
|
*
|
|
485
|
-
* @
|
|
486
|
-
* @param
|
|
487
|
-
* @
|
|
488
|
-
* @returns {Boolean|null} Returns `true` if all items can be consumed, `null` when one of the items cannot be
|
|
454
|
+
* @param type Type of the consumable item: `attributes`, `classes` or `styles`.
|
|
455
|
+
* @param item Consumable item or array of items.
|
|
456
|
+
* @returns Returns `true` if all items can be consumed, `null` when one of the items cannot be
|
|
489
457
|
* consumed and `false` when one of the items is already consumed.
|
|
490
458
|
*/
|
|
491
459
|
_test(type, item) {
|
|
@@ -516,9 +484,8 @@ class ViewElementConsumables {
|
|
|
516
484
|
/**
|
|
517
485
|
* Helper method that consumes items of a given type: attribute, class or style.
|
|
518
486
|
*
|
|
519
|
-
* @
|
|
520
|
-
* @param
|
|
521
|
-
* @param {String|Array.<String>} item Consumable item or array of items.
|
|
487
|
+
* @param type Type of the consumable item: `attributes`, `classes` or `styles`.
|
|
488
|
+
* @param item Consumable item or array of items.
|
|
522
489
|
*/
|
|
523
490
|
_consume(type, item) {
|
|
524
491
|
const items = isArray(item) ? item : [item];
|
|
@@ -542,9 +509,8 @@ class ViewElementConsumables {
|
|
|
542
509
|
/**
|
|
543
510
|
* Helper method that reverts items of a given type: attribute, class or style.
|
|
544
511
|
*
|
|
545
|
-
* @
|
|
546
|
-
* @param
|
|
547
|
-
* @param {String|Array.<String>} item Consumable item or array of items.
|
|
512
|
+
* @param type Type of the consumable item: `attributes`, `classes` or , `styles`.
|
|
513
|
+
* @param item Consumable item or array of items.
|
|
548
514
|
*/
|
|
549
515
|
_revert(type, item) {
|
|
550
516
|
const items = isArray(item) ? item : [item];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module engine/dataprocessor/basichtmlwriter
|
|
7
|
+
*/
|
|
8
|
+
import type HtmlWriter from './htmlwriter';
|
|
9
|
+
/**
|
|
10
|
+
* Basic HTML writer. It uses the native `innerHTML` property for basic conversion
|
|
11
|
+
* from a document fragment to an HTML string.
|
|
12
|
+
*/
|
|
13
|
+
export default class BasicHtmlWriter implements HtmlWriter {
|
|
14
|
+
/**
|
|
15
|
+
* Returns an HTML string created from the document fragment.
|
|
16
|
+
*/
|
|
17
|
+
getHtml(fragment: DocumentFragment): string;
|
|
18
|
+
}
|
|
@@ -2,22 +2,13 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/dataprocessor/basichtmlwriter
|
|
7
|
-
*/
|
|
8
|
-
/* globals document */
|
|
9
5
|
/**
|
|
10
6
|
* Basic HTML writer. It uses the native `innerHTML` property for basic conversion
|
|
11
7
|
* from a document fragment to an HTML string.
|
|
12
|
-
*
|
|
13
|
-
* @implements module:engine/dataprocessor/htmlwriter~HtmlWriter
|
|
14
8
|
*/
|
|
15
9
|
export default class BasicHtmlWriter {
|
|
16
10
|
/**
|
|
17
11
|
* Returns an HTML string created from the document fragment.
|
|
18
|
-
*
|
|
19
|
-
* @param {DocumentFragment} fragment
|
|
20
|
-
* @returns {String}
|
|
21
12
|
*/
|
|
22
13
|
getHtml(fragment) {
|
|
23
14
|
const doc = document.implementation.createHTMLDocument('');
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module engine/dataprocessor/dataprocessor
|
|
7
|
+
*/
|
|
8
|
+
import type ViewDocumentFragment from '../view/documentfragment';
|
|
9
|
+
import type { MatcherPattern } from '../view/matcher';
|
|
10
|
+
/**
|
|
11
|
+
* The data processor interface. It should be implemented by actual data processors.
|
|
12
|
+
*
|
|
13
|
+
* Each data processor implements a certain format of the data. For example, {@glink features/markdown Markdown data processor}
|
|
14
|
+
* will convert the data (a Markdown string) to a {@link module:engine/view/documentfragment~DocumentFragment document fragment} and back.
|
|
15
|
+
*
|
|
16
|
+
* **Note:** While the CKEditor 5 architecture supports changing the data format, in most scenarios we do recommend sticking to
|
|
17
|
+
* the default format which is HTML (supported by the {@link module:engine/dataprocessor/htmldataprocessor~HtmlDataProcessor}).
|
|
18
|
+
* HTML remains [the best standard for rich-text data](https://medium.com/content-uneditable/a-standard-for-rich-text-data-4b3a507af552).
|
|
19
|
+
*
|
|
20
|
+
* And please do remember – using Markdown [does not automatically make your
|
|
21
|
+
* application/website secure](https://github.com/ckeditor/ckeditor5-markdown-gfm/issues/16#issuecomment-375752994).
|
|
22
|
+
*/
|
|
23
|
+
export default interface DataProcessor {
|
|
24
|
+
/**
|
|
25
|
+
* Converts a {@link module:engine/view/documentfragment~DocumentFragment document fragment} to data.
|
|
26
|
+
*
|
|
27
|
+
* @param viewFragment The document fragment to be processed.
|
|
28
|
+
*/
|
|
29
|
+
toData(viewFragment: ViewDocumentFragment): string;
|
|
30
|
+
/**
|
|
31
|
+
* Converts the data to a {@link module:engine/view/documentfragment~DocumentFragment document fragment}.
|
|
32
|
+
*
|
|
33
|
+
* @param data The data to be processed.
|
|
34
|
+
*/
|
|
35
|
+
toView(data: string): ViewDocumentFragment;
|
|
36
|
+
/**
|
|
37
|
+
* Registers a {@link module:engine/view/matcher~MatcherPattern} for view elements whose content should be treated as raw data
|
|
38
|
+
* and its content should be converted to a
|
|
39
|
+
* {@link module:engine/view/element~Element#getCustomProperty custom property of a view element} called `"$rawContent"` while
|
|
40
|
+
* converting {@link #toView to view}.
|
|
41
|
+
*
|
|
42
|
+
* @param pattern Pattern matching all view elements whose content should be treated as plain text.
|
|
43
|
+
*/
|
|
44
|
+
registerRawContentMatcher(pattern: MatcherPattern): void;
|
|
45
|
+
/**
|
|
46
|
+
* If the processor is set to use marked fillers, it will insert ` ` fillers wrapped in `<span>` elements
|
|
47
|
+
* (`<span data-cke-filler="true"> </span>`) instead of regular ` ` characters.
|
|
48
|
+
*
|
|
49
|
+
* This mode allows for more precise handling of block fillers (so they do not leak into the editor content) but bloats the
|
|
50
|
+
* editor data with additional markup.
|
|
51
|
+
*
|
|
52
|
+
* This mode may be required by some features and will be turned on by them automatically.
|
|
53
|
+
*
|
|
54
|
+
* @param type Whether to use the default or marked ` ` block fillers.
|
|
55
|
+
*/
|
|
56
|
+
useFillerType(type: 'default' | 'marked'): void;
|
|
57
|
+
/**
|
|
58
|
+
* If `false`, comment nodes will be converted to `$comment`. Otherwise comment nodes are ignored.
|
|
59
|
+
*/
|
|
60
|
+
skipComments?: boolean;
|
|
61
|
+
}
|