@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
|
@@ -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,23 +88,26 @@ 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;
|
|
159
101
|
if (!this._checkIfRootsExists([rootName])) {
|
|
160
102
|
/**
|
|
161
|
-
* Cannot get data from a non-existing root. This error is thrown when
|
|
103
|
+
* Cannot get data from a non-existing root. This error is thrown when
|
|
104
|
+
* {@link module:engine/controller/datacontroller~DataController#get `DataController#get()` method}
|
|
162
105
|
* is called with a non-existent root name. For example, if there is an editor instance with only `main` root,
|
|
163
|
-
* calling {@link #get} like:
|
|
106
|
+
* calling {@link module:engine/controller/datacontroller~DataController#get} like:
|
|
164
107
|
*
|
|
165
|
-
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* data.get( { rootName: 'root2' } );
|
|
110
|
+
* ```
|
|
166
111
|
*
|
|
167
112
|
* will throw this error.
|
|
168
113
|
*
|
|
@@ -181,10 +126,9 @@ export default class DataController extends EmitterMixin() {
|
|
|
181
126
|
* {@link module:engine/model/documentfragment~DocumentFragment model document fragment} converted by the downcast converters
|
|
182
127
|
* attached to the {@link #downcastDispatcher} and formatted by the {@link #processor data processor}.
|
|
183
128
|
*
|
|
184
|
-
* @param
|
|
185
|
-
*
|
|
186
|
-
* @
|
|
187
|
-
* @returns {String} Output data.
|
|
129
|
+
* @param modelElementOrFragment The element whose content will be stringified.
|
|
130
|
+
* @param options Additional configuration passed to the conversion process.
|
|
131
|
+
* @returns Output data.
|
|
188
132
|
*/
|
|
189
133
|
stringify(modelElementOrFragment, options = {}) {
|
|
190
134
|
// Model -> view.
|
|
@@ -199,11 +143,10 @@ export default class DataController extends EmitterMixin() {
|
|
|
199
143
|
* {@link module:engine/view/documentfragment~DocumentFragment view document fragment}.
|
|
200
144
|
*
|
|
201
145
|
* @fires toView
|
|
202
|
-
* @param
|
|
203
|
-
*
|
|
204
|
-
* @param {Object} [options={}] Additional configuration that will be available through the
|
|
146
|
+
* @param modelElementOrFragment Element or document fragment whose content will be converted.
|
|
147
|
+
* @param options Additional configuration that will be available through the
|
|
205
148
|
* {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi#options} during the conversion process.
|
|
206
|
-
* @returns
|
|
149
|
+
* @returns Output view DocumentFragment.
|
|
207
150
|
*/
|
|
208
151
|
toView(modelElementOrFragment, options = {}) {
|
|
209
152
|
const viewDocument = this.viewDocument;
|
|
@@ -230,21 +173,25 @@ export default class DataController extends EmitterMixin() {
|
|
|
230
173
|
* converted by the {@link #upcastDispatcher view-to-model converters}.
|
|
231
174
|
* Initial data can be only set to a document whose {@link module:engine/model/document~Document#version} is equal 0.
|
|
232
175
|
*
|
|
233
|
-
* **Note** This method is {@link module:utils/observablemixin~
|
|
176
|
+
* **Note** This method is {@link module:utils/observablemixin~Observable#decorate decorated} which is
|
|
234
177
|
* used by e.g. collaborative editing plugin that syncs remote data on init.
|
|
235
178
|
*
|
|
236
179
|
* When data is passed as a string, it is initialized on the default `main` root:
|
|
237
180
|
*
|
|
238
|
-
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* dataController.init( '<p>Foo</p>' ); // Initializes data on the `main` root only, as no other is specified.
|
|
183
|
+
* ```
|
|
239
184
|
*
|
|
240
185
|
* To initialize data on a different root or multiple roots at once, an object containing `rootName` - `data` pairs should be passed:
|
|
241
186
|
*
|
|
242
|
-
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* dataController.init( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Initializes data on both the `main` and `title` roots.
|
|
189
|
+
* ```
|
|
243
190
|
*
|
|
244
191
|
* @fires init
|
|
245
|
-
* @param
|
|
192
|
+
* @param data Input data as a string or an object containing the `rootName` - `data`
|
|
246
193
|
* pairs to initialize data on multiple roots at once.
|
|
247
|
-
* @returns
|
|
194
|
+
* @returns Promise that is resolved after the data is set on the editor.
|
|
248
195
|
*/
|
|
249
196
|
init(data) {
|
|
250
197
|
if (this.model.document.version) {
|
|
@@ -266,11 +213,14 @@ export default class DataController extends EmitterMixin() {
|
|
|
266
213
|
}
|
|
267
214
|
if (!this._checkIfRootsExists(Object.keys(initialData))) {
|
|
268
215
|
/**
|
|
269
|
-
* Cannot init data on a non-existent root. This error is thrown when
|
|
216
|
+
* Cannot init data on a non-existent root. This error is thrown when
|
|
217
|
+
* {@link module:engine/controller/datacontroller~DataController#init DataController#init() method}
|
|
270
218
|
* is called with non-existent root name. For example, if there is an editor instance with only `main` root,
|
|
271
|
-
* calling {@link #init} like:
|
|
219
|
+
* calling {@link module:engine/controller/datacontroller~DataController#init} like:
|
|
272
220
|
*
|
|
273
|
-
*
|
|
221
|
+
* ```ts
|
|
222
|
+
* data.init( { main: '<p>Foo</p>', root2: '<p>Bar</p>' } );
|
|
223
|
+
* ```
|
|
274
224
|
*
|
|
275
225
|
* will throw this error.
|
|
276
226
|
*
|
|
@@ -297,21 +247,27 @@ export default class DataController extends EmitterMixin() {
|
|
|
297
247
|
*
|
|
298
248
|
* When data is passed as a string it is set on the default `main` root:
|
|
299
249
|
*
|
|
300
|
-
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* dataController.set( '<p>Foo</p>' ); // Sets data on the `main` root, as no other is specified.
|
|
252
|
+
* ```
|
|
301
253
|
*
|
|
302
254
|
* To set data on a different root or multiple roots at once, an object containing `rootName` - `data` pairs should be passed:
|
|
303
255
|
*
|
|
304
|
-
*
|
|
256
|
+
* ```ts
|
|
257
|
+
* dataController.set( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Sets data on the `main` and `title` roots as specified.
|
|
258
|
+
* ```
|
|
305
259
|
*
|
|
306
260
|
* 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
261
|
*
|
|
308
|
-
*
|
|
262
|
+
* ```ts
|
|
263
|
+
* dataController.set( '<p>Foo</p>', { batchType: { isUndoable: true } } );
|
|
264
|
+
* ```
|
|
309
265
|
*
|
|
310
266
|
* @fires set
|
|
311
|
-
* @param
|
|
267
|
+
* @param data Input data as a string or an object containing the `rootName` - `data`
|
|
312
268
|
* pairs to set data on multiple roots at once.
|
|
313
|
-
* @param
|
|
314
|
-
* @param
|
|
269
|
+
* @param options Options for setting data.
|
|
270
|
+
* @param options.batchType The batch type that will be used to create a batch for the changes applied by this method.
|
|
315
271
|
* By default, the batch will be set as {@link module:engine/model/batch~Batch#isUndoable not undoable} and the undo stack will be
|
|
316
272
|
* 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
273
|
* the undo stack will be preserved instead and not cleared when new data is applied.
|
|
@@ -326,11 +282,14 @@ export default class DataController extends EmitterMixin() {
|
|
|
326
282
|
}
|
|
327
283
|
if (!this._checkIfRootsExists(Object.keys(newData))) {
|
|
328
284
|
/**
|
|
329
|
-
* Cannot set data on a non-existent root. This error is thrown when the
|
|
285
|
+
* Cannot set data on a non-existent root. This error is thrown when the
|
|
286
|
+
* {@link module:engine/controller/datacontroller~DataController#set DataController#set() method}
|
|
330
287
|
* is called with non-existent root name. For example, if there is an editor instance with only the default `main` root,
|
|
331
|
-
* calling {@link #set} like:
|
|
288
|
+
* calling {@link module:engine/controller/datacontroller~DataController#set} like:
|
|
332
289
|
*
|
|
333
|
-
*
|
|
290
|
+
* ```ts
|
|
291
|
+
* data.set( { main: '<p>Foo</p>', root2: '<p>Bar</p>' } );
|
|
292
|
+
* ```
|
|
334
293
|
*
|
|
335
294
|
* will throw this error.
|
|
336
295
|
*
|
|
@@ -354,10 +313,10 @@ export default class DataController extends EmitterMixin() {
|
|
|
354
313
|
* attached to the {@link #upcastDispatcher}.
|
|
355
314
|
*
|
|
356
315
|
* @see #set
|
|
357
|
-
* @param
|
|
358
|
-
* @param
|
|
359
|
-
*
|
|
360
|
-
* @returns
|
|
316
|
+
* @param data Data to parse.
|
|
317
|
+
* @param context Base context in which the view will be converted to the model.
|
|
318
|
+
* See: {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert}.
|
|
319
|
+
* @returns Parsed data.
|
|
361
320
|
*/
|
|
362
321
|
parse(data, context = '$root') {
|
|
363
322
|
// data -> view
|
|
@@ -374,11 +333,10 @@ export default class DataController extends EmitterMixin() {
|
|
|
374
333
|
* {@link module:engine/model/documentfragment~DocumentFragment#markers static markers map}.
|
|
375
334
|
*
|
|
376
335
|
* @fires toModel
|
|
377
|
-
* @param
|
|
378
|
-
*
|
|
379
|
-
* @
|
|
380
|
-
*
|
|
381
|
-
* @returns {module:engine/model/documentfragment~DocumentFragment} Output document fragment.
|
|
336
|
+
* @param viewElementOrFragment The element or document fragment whose content will be converted.
|
|
337
|
+
* @param context Base context in which the view will be converted to the model.
|
|
338
|
+
* See: {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert}.
|
|
339
|
+
* @returns Output document fragment.
|
|
382
340
|
*/
|
|
383
341
|
toModel(viewElementOrFragment, context = '$root') {
|
|
384
342
|
return this.model.change(writer => {
|
|
@@ -394,8 +352,6 @@ export default class DataController extends EmitterMixin() {
|
|
|
394
352
|
* * border: {@link module:engine/view/styles/border~addBorderRules}
|
|
395
353
|
* * margin: {@link module:engine/view/styles/margin~addMarginRules}
|
|
396
354
|
* * padding: {@link module:engine/view/styles/padding~addPaddingRules}
|
|
397
|
-
*
|
|
398
|
-
* @param {Function} callback
|
|
399
355
|
*/
|
|
400
356
|
addStyleProcessorRules(callback) {
|
|
401
357
|
callback(this.stylesProcessor);
|
|
@@ -408,8 +364,7 @@ export default class DataController extends EmitterMixin() {
|
|
|
408
364
|
* The raw data can be later accessed by the {@link module:engine/view/element~Element#getCustomProperty view element custom property}
|
|
409
365
|
* `"$rawContent"`.
|
|
410
366
|
*
|
|
411
|
-
* @param
|
|
412
|
-
* be treated as a raw data.
|
|
367
|
+
* @param pattern Pattern matching all view elements whose content should be treated as a raw data.
|
|
413
368
|
*/
|
|
414
369
|
registerRawContentMatcher(pattern) {
|
|
415
370
|
// No need to register the pattern if both the `htmlProcessor` and `processor` are the same instances.
|
|
@@ -427,9 +382,8 @@ export default class DataController extends EmitterMixin() {
|
|
|
427
382
|
/**
|
|
428
383
|
* Checks whether all provided root names are actually existing editor roots.
|
|
429
384
|
*
|
|
430
|
-
* @
|
|
431
|
-
* @
|
|
432
|
-
* @returns {Boolean} Whether all provided root names are existing editor roots.
|
|
385
|
+
* @param rootNames Root names to check.
|
|
386
|
+
* @returns Whether all provided root names are existing editor roots.
|
|
433
387
|
*/
|
|
434
388
|
_checkIfRootsExists(rootNames) {
|
|
435
389
|
for (const rootName of rootNames) {
|
|
@@ -440,11 +394,13 @@ export default class DataController extends EmitterMixin() {
|
|
|
440
394
|
return true;
|
|
441
395
|
}
|
|
442
396
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
397
|
+
/**
|
|
398
|
+
* Helper function for downcast conversion.
|
|
399
|
+
*
|
|
400
|
+
* Takes a document element (element that is added to a model document) and checks which markers are inside it. If the marker is collapsed
|
|
401
|
+
* at element boundary, it is considered as contained inside the element and marker range is returned. Otherwise, if the marker is
|
|
402
|
+
* intersecting with the element, the intersection is returned.
|
|
403
|
+
*/
|
|
448
404
|
function _getMarkersRelativeToElement(element) {
|
|
449
405
|
const result = [];
|
|
450
406
|
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(() => {
|