@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
|
@@ -30,92 +30,34 @@ import HtmlDataProcessor from '../dataprocessor/htmldataprocessor';
|
|
|
30
30
|
* An instance of the data controller is always available in the {@link module:core/editor/editor~Editor#data `editor.data`}
|
|
31
31
|
* property:
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* editor.data.get( { rootName: 'customRoot' } ); // -> '<p>Hello!</p>'
|
|
35
|
+
* ```
|
|
36
36
|
*/
|
|
37
37
|
export default class DataController extends EmitterMixin() {
|
|
38
38
|
/**
|
|
39
39
|
* Creates a data controller instance.
|
|
40
40
|
*
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
41
|
+
* @param model Data model.
|
|
42
|
+
* @param stylesProcessor The styles processor instance.
|
|
43
43
|
*/
|
|
44
44
|
constructor(model, stylesProcessor) {
|
|
45
45
|
super();
|
|
46
|
-
/**
|
|
47
|
-
* Data model.
|
|
48
|
-
*
|
|
49
|
-
* @readonly
|
|
50
|
-
* @member {module:engine/model/model~Model}
|
|
51
|
-
*/
|
|
52
46
|
this.model = model;
|
|
53
|
-
/**
|
|
54
|
-
* Mapper used for the conversion. It has no permanent bindings, because these are created while getting data and
|
|
55
|
-
* ae cleared directly after the data are converted. However, the mapper is defined as a class property, because
|
|
56
|
-
* it needs to be passed to the `DowncastDispatcher` as a conversion API.
|
|
57
|
-
*
|
|
58
|
-
* @readonly
|
|
59
|
-
* @member {module:engine/conversion/mapper~Mapper}
|
|
60
|
-
*/
|
|
61
47
|
this.mapper = new Mapper();
|
|
62
|
-
/**
|
|
63
|
-
* Downcast dispatcher used by the {@link #get get method}. Downcast converters should be attached to it.
|
|
64
|
-
*
|
|
65
|
-
* @readonly
|
|
66
|
-
* @member {module:engine/conversion/downcastdispatcher~DowncastDispatcher}
|
|
67
|
-
*/
|
|
68
48
|
this.downcastDispatcher = new DowncastDispatcher({
|
|
69
49
|
mapper: this.mapper,
|
|
70
50
|
schema: model.schema
|
|
71
51
|
});
|
|
72
52
|
this.downcastDispatcher.on('insert:$text', insertText(), { priority: 'lowest' });
|
|
73
53
|
this.downcastDispatcher.on('insert', insertAttributesAndChildren(), { priority: 'lowest' });
|
|
74
|
-
/**
|
|
75
|
-
* Upcast dispatcher used by the {@link #set set method}. Upcast converters should be attached to it.
|
|
76
|
-
*
|
|
77
|
-
* @readonly
|
|
78
|
-
* @member {module:engine/conversion/upcastdispatcher~UpcastDispatcher}
|
|
79
|
-
*/
|
|
80
54
|
this.upcastDispatcher = new UpcastDispatcher({
|
|
81
55
|
schema: model.schema
|
|
82
56
|
});
|
|
83
|
-
/**
|
|
84
|
-
* The view document used by the data controller.
|
|
85
|
-
*
|
|
86
|
-
* @readonly
|
|
87
|
-
* @member {module:engine/view/document~Document}
|
|
88
|
-
*/
|
|
89
57
|
this.viewDocument = new ViewDocument(stylesProcessor);
|
|
90
|
-
/**
|
|
91
|
-
* Styles processor used during the conversion.
|
|
92
|
-
*
|
|
93
|
-
* @readonly
|
|
94
|
-
* @member {module:engine/view/stylesmap~StylesProcessor}
|
|
95
|
-
*/
|
|
96
58
|
this.stylesProcessor = stylesProcessor;
|
|
97
|
-
/**
|
|
98
|
-
* Data processor used specifically for HTML conversion.
|
|
99
|
-
*
|
|
100
|
-
* @readonly
|
|
101
|
-
* @member {module:engine/dataprocessor/htmldataprocessor~HtmlDataProcessor} #htmlProcessor
|
|
102
|
-
*/
|
|
103
59
|
this.htmlProcessor = new HtmlDataProcessor(this.viewDocument);
|
|
104
|
-
/**
|
|
105
|
-
* Data processor used during the conversion.
|
|
106
|
-
* Same instance as {@link #htmlProcessor} by default. Can be replaced at run time to handle different format, e.g. XML or Markdown.
|
|
107
|
-
*
|
|
108
|
-
* @member {module:engine/dataprocessor/dataprocessor~DataProcessor} #processor
|
|
109
|
-
*/
|
|
110
60
|
this.processor = this.htmlProcessor;
|
|
111
|
-
/**
|
|
112
|
-
* The view downcast writer just for data conversion purposes, i.e. to modify
|
|
113
|
-
* the {@link #viewDocument}.
|
|
114
|
-
*
|
|
115
|
-
* @private
|
|
116
|
-
* @readonly
|
|
117
|
-
* @member {module:engine/view/downcastwriter~DowncastWriter}
|
|
118
|
-
*/
|
|
119
61
|
this._viewWriter = new ViewDowncastWriter(this.viewDocument);
|
|
120
62
|
// Define default converters for text and elements.
|
|
121
63
|
//
|
|
@@ -146,13 +88,13 @@ export default class DataController extends EmitterMixin() {
|
|
|
146
88
|
* formatted by the {@link #processor data processor}.
|
|
147
89
|
*
|
|
148
90
|
* @fires get
|
|
149
|
-
* @param
|
|
91
|
+
* @param options Additional configuration for the retrieved data. `DataController` provides two optional
|
|
150
92
|
* properties: `rootName` and `trim`. Other properties of this object are specified by various editor features.
|
|
151
|
-
* @param
|
|
152
|
-
* @param
|
|
93
|
+
* @param options.rootName Root name. Default 'main'.
|
|
94
|
+
* @param options.trim Whether returned data should be trimmed. This option is set to `empty` by default,
|
|
153
95
|
* which means whenever editor content is considered empty, an empty string will be returned. To turn off trimming completely
|
|
154
96
|
* use `'none'`. In such cases the exact content will be returned (for example a `<p> </p>` for an empty editor).
|
|
155
|
-
* @returns
|
|
97
|
+
* @returns Output data.
|
|
156
98
|
*/
|
|
157
99
|
get(options = {}) {
|
|
158
100
|
const { rootName = 'main', trim = 'empty' } = options;
|
|
@@ -162,7 +104,9 @@ export default class DataController extends EmitterMixin() {
|
|
|
162
104
|
* is called with a non-existent root name. For example, if there is an editor instance with only `main` root,
|
|
163
105
|
* calling {@link #get} like:
|
|
164
106
|
*
|
|
165
|
-
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* data.get( { rootName: 'root2' } );
|
|
109
|
+
* ```
|
|
166
110
|
*
|
|
167
111
|
* will throw this error.
|
|
168
112
|
*
|
|
@@ -181,10 +125,9 @@ export default class DataController extends EmitterMixin() {
|
|
|
181
125
|
* {@link module:engine/model/documentfragment~DocumentFragment model document fragment} converted by the downcast converters
|
|
182
126
|
* attached to the {@link #downcastDispatcher} and formatted by the {@link #processor data processor}.
|
|
183
127
|
*
|
|
184
|
-
* @param
|
|
185
|
-
*
|
|
186
|
-
* @
|
|
187
|
-
* @returns {String} Output data.
|
|
128
|
+
* @param modelElementOrFragment The element whose content will be stringified.
|
|
129
|
+
* @param options Additional configuration passed to the conversion process.
|
|
130
|
+
* @returns Output data.
|
|
188
131
|
*/
|
|
189
132
|
stringify(modelElementOrFragment, options = {}) {
|
|
190
133
|
// Model -> view.
|
|
@@ -199,11 +142,10 @@ export default class DataController extends EmitterMixin() {
|
|
|
199
142
|
* {@link module:engine/view/documentfragment~DocumentFragment view document fragment}.
|
|
200
143
|
*
|
|
201
144
|
* @fires toView
|
|
202
|
-
* @param
|
|
203
|
-
*
|
|
204
|
-
* @param {Object} [options={}] Additional configuration that will be available through the
|
|
145
|
+
* @param modelElementOrFragment Element or document fragment whose content will be converted.
|
|
146
|
+
* @param options Additional configuration that will be available through the
|
|
205
147
|
* {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi#options} during the conversion process.
|
|
206
|
-
* @returns
|
|
148
|
+
* @returns Output view DocumentFragment.
|
|
207
149
|
*/
|
|
208
150
|
toView(modelElementOrFragment, options = {}) {
|
|
209
151
|
const viewDocument = this.viewDocument;
|
|
@@ -235,16 +177,20 @@ export default class DataController extends EmitterMixin() {
|
|
|
235
177
|
*
|
|
236
178
|
* When data is passed as a string, it is initialized on the default `main` root:
|
|
237
179
|
*
|
|
238
|
-
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* dataController.init( '<p>Foo</p>' ); // Initializes data on the `main` root only, as no other is specified.
|
|
182
|
+
* ```
|
|
239
183
|
*
|
|
240
184
|
* To initialize data on a different root or multiple roots at once, an object containing `rootName` - `data` pairs should be passed:
|
|
241
185
|
*
|
|
242
|
-
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* dataController.init( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Initializes data on both the `main` and `title` roots.
|
|
188
|
+
* ```
|
|
243
189
|
*
|
|
244
190
|
* @fires init
|
|
245
|
-
* @param
|
|
191
|
+
* @param data Input data as a string or an object containing the `rootName` - `data`
|
|
246
192
|
* pairs to initialize data on multiple roots at once.
|
|
247
|
-
* @returns
|
|
193
|
+
* @returns Promise that is resolved after the data is set on the editor.
|
|
248
194
|
*/
|
|
249
195
|
init(data) {
|
|
250
196
|
if (this.model.document.version) {
|
|
@@ -270,7 +216,9 @@ export default class DataController extends EmitterMixin() {
|
|
|
270
216
|
* is called with non-existent root name. For example, if there is an editor instance with only `main` root,
|
|
271
217
|
* calling {@link #init} like:
|
|
272
218
|
*
|
|
273
|
-
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* data.init( { main: '<p>Foo</p>', root2: '<p>Bar</p>' } );
|
|
221
|
+
* ```
|
|
274
222
|
*
|
|
275
223
|
* will throw this error.
|
|
276
224
|
*
|
|
@@ -297,21 +245,27 @@ export default class DataController extends EmitterMixin() {
|
|
|
297
245
|
*
|
|
298
246
|
* When data is passed as a string it is set on the default `main` root:
|
|
299
247
|
*
|
|
300
|
-
*
|
|
248
|
+
* ```ts
|
|
249
|
+
* dataController.set( '<p>Foo</p>' ); // Sets data on the `main` root, as no other is specified.
|
|
250
|
+
* ```
|
|
301
251
|
*
|
|
302
252
|
* To set data on a different root or multiple roots at once, an object containing `rootName` - `data` pairs should be passed:
|
|
303
253
|
*
|
|
304
|
-
*
|
|
254
|
+
* ```ts
|
|
255
|
+
* dataController.set( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Sets data on the `main` and `title` roots as specified.
|
|
256
|
+
* ```
|
|
305
257
|
*
|
|
306
258
|
* To set the data with a preserved undo stack and add the change to the undo stack, set `{ isUndoable: true }` as a `batchType` option.
|
|
307
259
|
*
|
|
308
|
-
*
|
|
260
|
+
* ```ts
|
|
261
|
+
* dataController.set( '<p>Foo</p>', { batchType: { isUndoable: true } } );
|
|
262
|
+
* ```
|
|
309
263
|
*
|
|
310
264
|
* @fires set
|
|
311
|
-
* @param
|
|
265
|
+
* @param data Input data as a string or an object containing the `rootName` - `data`
|
|
312
266
|
* pairs to set data on multiple roots at once.
|
|
313
|
-
* @param
|
|
314
|
-
* @param
|
|
267
|
+
* @param options Options for setting data.
|
|
268
|
+
* @param options.batchType The batch type that will be used to create a batch for the changes applied by this method.
|
|
315
269
|
* By default, the batch will be set as {@link module:engine/model/batch~Batch#isUndoable not undoable} and the undo stack will be
|
|
316
270
|
* cleared after the new data is applied (all undo steps will be removed). If the batch type `isUndoable` flag is be set to `true`,
|
|
317
271
|
* the undo stack will be preserved instead and not cleared when new data is applied.
|
|
@@ -330,7 +284,9 @@ export default class DataController extends EmitterMixin() {
|
|
|
330
284
|
* is called with non-existent root name. For example, if there is an editor instance with only the default `main` root,
|
|
331
285
|
* calling {@link #set} like:
|
|
332
286
|
*
|
|
333
|
-
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* data.set( { main: '<p>Foo</p>', root2: '<p>Bar</p>' } );
|
|
289
|
+
* ```
|
|
334
290
|
*
|
|
335
291
|
* will throw this error.
|
|
336
292
|
*
|
|
@@ -354,10 +310,10 @@ export default class DataController extends EmitterMixin() {
|
|
|
354
310
|
* attached to the {@link #upcastDispatcher}.
|
|
355
311
|
*
|
|
356
312
|
* @see #set
|
|
357
|
-
* @param
|
|
358
|
-
* @param
|
|
359
|
-
*
|
|
360
|
-
* @returns
|
|
313
|
+
* @param data Data to parse.
|
|
314
|
+
* @param context Base context in which the view will be converted to the model.
|
|
315
|
+
* See: {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert}.
|
|
316
|
+
* @returns Parsed data.
|
|
361
317
|
*/
|
|
362
318
|
parse(data, context = '$root') {
|
|
363
319
|
// data -> view
|
|
@@ -374,11 +330,10 @@ export default class DataController extends EmitterMixin() {
|
|
|
374
330
|
* {@link module:engine/model/documentfragment~DocumentFragment#markers static markers map}.
|
|
375
331
|
*
|
|
376
332
|
* @fires toModel
|
|
377
|
-
* @param
|
|
378
|
-
*
|
|
379
|
-
* @
|
|
380
|
-
*
|
|
381
|
-
* @returns {module:engine/model/documentfragment~DocumentFragment} Output document fragment.
|
|
333
|
+
* @param viewElementOrFragment The element or document fragment whose content will be converted.
|
|
334
|
+
* @param context Base context in which the view will be converted to the model.
|
|
335
|
+
* See: {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert}.
|
|
336
|
+
* @returns Output document fragment.
|
|
382
337
|
*/
|
|
383
338
|
toModel(viewElementOrFragment, context = '$root') {
|
|
384
339
|
return this.model.change(writer => {
|
|
@@ -394,8 +349,6 @@ export default class DataController extends EmitterMixin() {
|
|
|
394
349
|
* * border: {@link module:engine/view/styles/border~addBorderRules}
|
|
395
350
|
* * margin: {@link module:engine/view/styles/margin~addMarginRules}
|
|
396
351
|
* * padding: {@link module:engine/view/styles/padding~addPaddingRules}
|
|
397
|
-
*
|
|
398
|
-
* @param {Function} callback
|
|
399
352
|
*/
|
|
400
353
|
addStyleProcessorRules(callback) {
|
|
401
354
|
callback(this.stylesProcessor);
|
|
@@ -408,8 +361,7 @@ export default class DataController extends EmitterMixin() {
|
|
|
408
361
|
* The raw data can be later accessed by the {@link module:engine/view/element~Element#getCustomProperty view element custom property}
|
|
409
362
|
* `"$rawContent"`.
|
|
410
363
|
*
|
|
411
|
-
* @param
|
|
412
|
-
* be treated as a raw data.
|
|
364
|
+
* @param pattern Pattern matching all view elements whose content should be treated as a raw data.
|
|
413
365
|
*/
|
|
414
366
|
registerRawContentMatcher(pattern) {
|
|
415
367
|
// No need to register the pattern if both the `htmlProcessor` and `processor` are the same instances.
|
|
@@ -427,9 +379,8 @@ export default class DataController extends EmitterMixin() {
|
|
|
427
379
|
/**
|
|
428
380
|
* Checks whether all provided root names are actually existing editor roots.
|
|
429
381
|
*
|
|
430
|
-
* @
|
|
431
|
-
* @
|
|
432
|
-
* @returns {Boolean} Whether all provided root names are existing editor roots.
|
|
382
|
+
* @param rootNames Root names to check.
|
|
383
|
+
* @returns Whether all provided root names are existing editor roots.
|
|
433
384
|
*/
|
|
434
385
|
_checkIfRootsExists(rootNames) {
|
|
435
386
|
for (const rootName of rootNames) {
|
|
@@ -440,11 +391,13 @@ export default class DataController extends EmitterMixin() {
|
|
|
440
391
|
return true;
|
|
441
392
|
}
|
|
442
393
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
394
|
+
/**
|
|
395
|
+
* Helper function for downcast conversion.
|
|
396
|
+
*
|
|
397
|
+
* Takes a document element (element that is added to a model document) and checks which markers are inside it. If the marker is collapsed
|
|
398
|
+
* at element boundary, it is considered as contained inside the element and marker range is returned. Otherwise, if the marker is
|
|
399
|
+
* intersecting with the element, the intersection is returned.
|
|
400
|
+
*/
|
|
448
401
|
function _getMarkersRelativeToElement(element) {
|
|
449
402
|
const result = [];
|
|
450
403
|
const doc = element.root.document;
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
import View from '../view/view';
|
|
6
|
+
import Mapper from '../conversion/mapper';
|
|
7
|
+
import DowncastDispatcher from '../conversion/downcastdispatcher';
|
|
8
|
+
import type { default as Model } from '../model/model';
|
|
9
|
+
import type ModelItem from '../model/item';
|
|
10
|
+
import type { Marker } from '../model/markercollection';
|
|
11
|
+
import type { StylesProcessor } from '../view/stylesmap';
|
|
12
|
+
declare const EditingController_base: {
|
|
13
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
|
14
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A controller for the editing pipeline. The editing pipeline controls the {@link ~EditingController#model model} rendering,
|
|
18
|
+
* including selection handling. It also creates the {@link ~EditingController#view view} which builds a
|
|
19
|
+
* browser-independent virtualization over the DOM elements. The editing controller also attaches default converters.
|
|
20
|
+
*/
|
|
21
|
+
export default class EditingController extends EditingController_base {
|
|
22
|
+
/**
|
|
23
|
+
* Editor model.
|
|
24
|
+
*/
|
|
25
|
+
readonly model: Model;
|
|
26
|
+
/**
|
|
27
|
+
* Editing view controller.
|
|
28
|
+
*/
|
|
29
|
+
readonly view: View;
|
|
30
|
+
/**
|
|
31
|
+
* A mapper that describes the model-view binding.
|
|
32
|
+
*/
|
|
33
|
+
readonly mapper: Mapper;
|
|
34
|
+
/**
|
|
35
|
+
* Downcast dispatcher that converts changes from the model to the {@link #view editing view}.
|
|
36
|
+
*/
|
|
37
|
+
readonly downcastDispatcher: DowncastDispatcher;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an editing controller instance.
|
|
40
|
+
*
|
|
41
|
+
* @param model Editing model.
|
|
42
|
+
* @param stylesProcessor The styles processor instance.
|
|
43
|
+
*/
|
|
44
|
+
constructor(model: Model, stylesProcessor: StylesProcessor);
|
|
45
|
+
/**
|
|
46
|
+
* Removes all event listeners attached to the `EditingController`. Destroys all objects created
|
|
47
|
+
* by `EditingController` that need to be destroyed.
|
|
48
|
+
*/
|
|
49
|
+
destroy(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Calling this method will refresh the marker by triggering the downcast conversion for it.
|
|
52
|
+
*
|
|
53
|
+
* Reconverting the marker is useful when you want to change its {@link module:engine/view/element~Element view element}
|
|
54
|
+
* without changing any marker data. For instance:
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* let isCommentActive = false;
|
|
58
|
+
*
|
|
59
|
+
* model.conversion.markerToHighlight( {
|
|
60
|
+
* model: 'comment',
|
|
61
|
+
* view: data => {
|
|
62
|
+
* const classes = [ 'comment-marker' ];
|
|
63
|
+
*
|
|
64
|
+
* if ( isCommentActive ) {
|
|
65
|
+
* classes.push( 'comment-marker--active' );
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* return { classes };
|
|
69
|
+
* }
|
|
70
|
+
* } );
|
|
71
|
+
*
|
|
72
|
+
* // ...
|
|
73
|
+
*
|
|
74
|
+
* // Change the property that indicates if marker is displayed as active or not.
|
|
75
|
+
* isCommentActive = true;
|
|
76
|
+
*
|
|
77
|
+
* // Reconverting will downcast and synchronize the marker with the new isCommentActive state value.
|
|
78
|
+
* editor.editing.reconvertMarker( 'comment' );
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* **Note**: If you want to reconvert a model item, use {@link #reconvertItem} instead.
|
|
82
|
+
*
|
|
83
|
+
* @param markerOrName Name of a marker to update, or a marker instance.
|
|
84
|
+
*/
|
|
85
|
+
reconvertMarker(markerOrName: Marker | string): void;
|
|
86
|
+
/**
|
|
87
|
+
* Calling this method will downcast a model item on demand (by requesting a refresh in the {@link module:engine/model/differ~Differ}).
|
|
88
|
+
*
|
|
89
|
+
* You can use it if you want the view representation of a specific item updated as a response to external modifications. For instance,
|
|
90
|
+
* when the view structure depends not only on the associated model data but also on some external state.
|
|
91
|
+
*
|
|
92
|
+
* **Note**: If you want to reconvert a model marker, use {@link #reconvertMarker} instead.
|
|
93
|
+
*
|
|
94
|
+
* @param item Item to refresh.
|
|
95
|
+
*/
|
|
96
|
+
reconvertItem(item: ModelItem): void;
|
|
97
|
+
}
|
|
98
|
+
export {};
|
|
@@ -17,45 +17,19 @@ import { convertSelectionChange } from '../conversion/upcasthelpers';
|
|
|
17
17
|
* A controller for the editing pipeline. The editing pipeline controls the {@link ~EditingController#model model} rendering,
|
|
18
18
|
* including selection handling. It also creates the {@link ~EditingController#view view} which builds a
|
|
19
19
|
* browser-independent virtualization over the DOM elements. The editing controller also attaches default converters.
|
|
20
|
-
*
|
|
21
|
-
* @mixes module:utils/observablemixin~ObservableMixin
|
|
22
20
|
*/
|
|
23
21
|
export default class EditingController extends ObservableMixin() {
|
|
24
22
|
/**
|
|
25
23
|
* Creates an editing controller instance.
|
|
26
24
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
25
|
+
* @param model Editing model.
|
|
26
|
+
* @param stylesProcessor The styles processor instance.
|
|
29
27
|
*/
|
|
30
28
|
constructor(model, stylesProcessor) {
|
|
31
29
|
super();
|
|
32
|
-
/**
|
|
33
|
-
* Editor model.
|
|
34
|
-
*
|
|
35
|
-
* @readonly
|
|
36
|
-
* @member {module:engine/model/model~Model}
|
|
37
|
-
*/
|
|
38
30
|
this.model = model;
|
|
39
|
-
/**
|
|
40
|
-
* Editing view controller.
|
|
41
|
-
*
|
|
42
|
-
* @readonly
|
|
43
|
-
* @member {module:engine/view/view~View}
|
|
44
|
-
*/
|
|
45
31
|
this.view = new View(stylesProcessor);
|
|
46
|
-
/**
|
|
47
|
-
* A mapper that describes the model-view binding.
|
|
48
|
-
*
|
|
49
|
-
* @readonly
|
|
50
|
-
* @member {module:engine/conversion/mapper~Mapper}
|
|
51
|
-
*/
|
|
52
32
|
this.mapper = new Mapper();
|
|
53
|
-
/**
|
|
54
|
-
* Downcast dispatcher that converts changes from the model to the {@link #view editing view}.
|
|
55
|
-
*
|
|
56
|
-
* @readonly
|
|
57
|
-
* @member {module:engine/conversion/downcastdispatcher~DowncastDispatcher} #downcastDispatcher
|
|
58
|
-
*/
|
|
59
33
|
this.downcastDispatcher = new DowncastDispatcher({
|
|
60
34
|
mapper: this.mapper,
|
|
61
35
|
schema: model.schema
|
|
@@ -128,32 +102,34 @@ export default class EditingController extends ObservableMixin() {
|
|
|
128
102
|
* Reconverting the marker is useful when you want to change its {@link module:engine/view/element~Element view element}
|
|
129
103
|
* without changing any marker data. For instance:
|
|
130
104
|
*
|
|
131
|
-
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* let isCommentActive = false;
|
|
132
107
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
108
|
+
* model.conversion.markerToHighlight( {
|
|
109
|
+
* model: 'comment',
|
|
110
|
+
* view: data => {
|
|
111
|
+
* const classes = [ 'comment-marker' ];
|
|
137
112
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
113
|
+
* if ( isCommentActive ) {
|
|
114
|
+
* classes.push( 'comment-marker--active' );
|
|
115
|
+
* }
|
|
141
116
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
117
|
+
* return { classes };
|
|
118
|
+
* }
|
|
119
|
+
* } );
|
|
145
120
|
*
|
|
146
|
-
*
|
|
121
|
+
* // ...
|
|
147
122
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
123
|
+
* // Change the property that indicates if marker is displayed as active or not.
|
|
124
|
+
* isCommentActive = true;
|
|
150
125
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
126
|
+
* // Reconverting will downcast and synchronize the marker with the new isCommentActive state value.
|
|
127
|
+
* editor.editing.reconvertMarker( 'comment' );
|
|
128
|
+
* ```
|
|
153
129
|
*
|
|
154
130
|
* **Note**: If you want to reconvert a model item, use {@link #reconvertItem} instead.
|
|
155
131
|
*
|
|
156
|
-
* @param
|
|
132
|
+
* @param markerOrName Name of a marker to update, or a marker instance.
|
|
157
133
|
*/
|
|
158
134
|
reconvertMarker(markerOrName) {
|
|
159
135
|
const markerName = typeof markerOrName == 'string' ? markerOrName : markerOrName.name;
|
|
@@ -179,7 +155,7 @@ export default class EditingController extends ObservableMixin() {
|
|
|
179
155
|
*
|
|
180
156
|
* **Note**: If you want to reconvert a model marker, use {@link #reconvertMarker} instead.
|
|
181
157
|
*
|
|
182
|
-
* @param
|
|
158
|
+
* @param item Item to refresh.
|
|
183
159
|
*/
|
|
184
160
|
reconvertItem(item) {
|
|
185
161
|
this.model.change(() => {
|