@ckeditor/ckeditor5-engine 47.6.1 → 48.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/LICENSE.md +1 -1
- package/{src → dist}/engineconfig.d.ts +6 -15
- package/dist/index-editor.css +38 -15
- package/dist/index.css +37 -37
- package/dist/index.css.map +1 -1
- package/{src → dist}/index.d.ts +0 -1
- package/dist/index.js +588 -94
- package/dist/index.js.map +1 -1
- package/{src → dist}/model/model.d.ts +10 -4
- package/{src → dist}/model/selection.d.ts +1 -1
- package/{src → dist}/view/downcastwriter.d.ts +3 -2
- package/{src → dist}/view/element.d.ts +2 -2
- package/{src → dist}/view/matcher.d.ts +4 -2
- package/dist/view/styles/background.d.ts +18 -0
- package/{src → dist}/view/styles/border.d.ts +0 -12
- package/{src → dist}/view/styles/margin.d.ts +0 -13
- package/{src → dist}/view/styles/padding.d.ts +0 -13
- package/{src → dist}/view/styles/utils.d.ts +12 -0
- package/package.json +20 -39
- package/src/controller/datacontroller.js +0 -522
- package/src/controller/editingcontroller.js +0 -181
- package/src/conversion/conversion.js +0 -606
- package/src/conversion/conversionhelpers.js +0 -33
- package/src/conversion/downcastdispatcher.js +0 -563
- package/src/conversion/downcasthelpers.js +0 -2160
- package/src/conversion/mapper.js +0 -1050
- package/src/conversion/modelconsumable.js +0 -331
- package/src/conversion/upcastdispatcher.js +0 -470
- package/src/conversion/upcasthelpers.js +0 -952
- package/src/conversion/viewconsumable.js +0 -541
- package/src/dataprocessor/basichtmlwriter.js +0 -22
- package/src/dataprocessor/dataprocessor.js +0 -5
- package/src/dataprocessor/htmldataprocessor.js +0 -107
- package/src/dataprocessor/htmlwriter.js +0 -5
- package/src/dataprocessor/xmldataprocessor.js +0 -127
- package/src/dev-utils/model.js +0 -396
- package/src/dev-utils/operationreplayer.js +0 -116
- package/src/dev-utils/utils.js +0 -122
- package/src/dev-utils/view.js +0 -990
- package/src/engineconfig.js +0 -5
- package/src/index.js +0 -134
- package/src/legacyerrors.js +0 -17
- package/src/model/batch.js +0 -98
- package/src/model/differ.js +0 -1288
- package/src/model/document.js +0 -398
- package/src/model/documentfragment.js +0 -332
- package/src/model/documentselection.js +0 -1026
- package/src/model/element.js +0 -323
- package/src/model/history.js +0 -206
- package/src/model/item.js +0 -5
- package/src/model/liveposition.js +0 -93
- package/src/model/liverange.js +0 -121
- package/src/model/markercollection.js +0 -436
- package/src/model/model.js +0 -866
- package/src/model/node.js +0 -371
- package/src/model/nodelist.js +0 -244
- package/src/model/operation/attributeoperation.js +0 -172
- package/src/model/operation/detachoperation.js +0 -87
- package/src/model/operation/insertoperation.js +0 -153
- package/src/model/operation/markeroperation.js +0 -136
- package/src/model/operation/mergeoperation.js +0 -184
- package/src/model/operation/moveoperation.js +0 -179
- package/src/model/operation/nooperation.js +0 -48
- package/src/model/operation/operation.js +0 -78
- package/src/model/operation/operationfactory.js +0 -44
- package/src/model/operation/renameoperation.js +0 -128
- package/src/model/operation/rootattributeoperation.js +0 -173
- package/src/model/operation/rootoperation.js +0 -106
- package/src/model/operation/splitoperation.js +0 -214
- package/src/model/operation/transform.js +0 -2211
- package/src/model/operation/utils.js +0 -217
- package/src/model/position.js +0 -1041
- package/src/model/range.js +0 -880
- package/src/model/rootelement.js +0 -82
- package/src/model/schema.js +0 -1542
- package/src/model/selection.js +0 -814
- package/src/model/text.js +0 -92
- package/src/model/textproxy.js +0 -202
- package/src/model/treewalker.js +0 -313
- package/src/model/typecheckable.js +0 -16
- package/src/model/utils/autoparagraphing.js +0 -63
- package/src/model/utils/deletecontent.js +0 -509
- package/src/model/utils/getselectedcontent.js +0 -126
- package/src/model/utils/insertcontent.js +0 -750
- package/src/model/utils/insertobject.js +0 -135
- package/src/model/utils/modifyselection.js +0 -187
- package/src/model/utils/selection-post-fixer.js +0 -264
- package/src/model/writer.js +0 -1318
- package/src/view/attributeelement.js +0 -220
- package/src/view/containerelement.js +0 -91
- package/src/view/datatransfer.js +0 -106
- package/src/view/document.js +0 -139
- package/src/view/documentfragment.js +0 -251
- package/src/view/documentselection.js +0 -270
- package/src/view/domconverter.js +0 -1661
- package/src/view/downcastwriter.js +0 -1589
- package/src/view/editableelement.js +0 -74
- package/src/view/element.js +0 -1053
- package/src/view/elementdefinition.js +0 -5
- package/src/view/emptyelement.js +0 -83
- package/src/view/filler.js +0 -161
- package/src/view/item.js +0 -5
- package/src/view/matcher.js +0 -437
- package/src/view/node.js +0 -238
- package/src/view/observer/arrowkeysobserver.js +0 -40
- package/src/view/observer/bubblingemittermixin.js +0 -215
- package/src/view/observer/bubblingeventinfo.js +0 -49
- package/src/view/observer/clickobserver.js +0 -26
- package/src/view/observer/compositionobserver.js +0 -64
- package/src/view/observer/domeventdata.js +0 -63
- package/src/view/observer/domeventobserver.js +0 -81
- package/src/view/observer/fakeselectionobserver.js +0 -95
- package/src/view/observer/focusobserver.js +0 -166
- package/src/view/observer/inputobserver.js +0 -236
- package/src/view/observer/keyobserver.js +0 -36
- package/src/view/observer/mouseobserver.js +0 -26
- package/src/view/observer/mutationobserver.js +0 -219
- package/src/view/observer/observer.js +0 -92
- package/src/view/observer/pointerobserver.js +0 -26
- package/src/view/observer/selectionobserver.js +0 -318
- package/src/view/observer/tabobserver.js +0 -42
- package/src/view/observer/touchobserver.js +0 -26
- package/src/view/placeholder.js +0 -285
- package/src/view/position.js +0 -341
- package/src/view/range.js +0 -451
- package/src/view/rawelement.js +0 -115
- package/src/view/renderer.js +0 -1148
- package/src/view/rooteditableelement.js +0 -78
- package/src/view/selection.js +0 -594
- package/src/view/styles/background.d.ts +0 -33
- package/src/view/styles/background.js +0 -74
- package/src/view/styles/border.js +0 -316
- package/src/view/styles/margin.js +0 -34
- package/src/view/styles/padding.js +0 -34
- package/src/view/styles/utils.js +0 -219
- package/src/view/stylesmap.js +0 -941
- package/src/view/text.js +0 -110
- package/src/view/textproxy.js +0 -136
- package/src/view/tokenlist.js +0 -194
- package/src/view/treewalker.js +0 -389
- package/src/view/typecheckable.js +0 -19
- package/src/view/uielement.js +0 -194
- package/src/view/upcastwriter.js +0 -363
- package/src/view/view.js +0 -579
- package/theme/placeholder.css +0 -36
- package/theme/renderer.css +0 -9
- /package/{src → dist}/controller/datacontroller.d.ts +0 -0
- /package/{src → dist}/controller/editingcontroller.d.ts +0 -0
- /package/{src → dist}/conversion/conversion.d.ts +0 -0
- /package/{src → dist}/conversion/conversionhelpers.d.ts +0 -0
- /package/{src → dist}/conversion/downcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/downcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/mapper.d.ts +0 -0
- /package/{src → dist}/conversion/modelconsumable.d.ts +0 -0
- /package/{src → dist}/conversion/upcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/upcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/viewconsumable.d.ts +0 -0
- /package/{src → dist}/dataprocessor/basichtmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/dataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/xmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dev-utils/model.d.ts +0 -0
- /package/{src → dist}/dev-utils/operationreplayer.d.ts +0 -0
- /package/{src → dist}/dev-utils/utils.d.ts +0 -0
- /package/{src → dist}/dev-utils/view.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/model/batch.d.ts +0 -0
- /package/{src → dist}/model/differ.d.ts +0 -0
- /package/{src → dist}/model/document.d.ts +0 -0
- /package/{src → dist}/model/documentfragment.d.ts +0 -0
- /package/{src → dist}/model/documentselection.d.ts +0 -0
- /package/{src → dist}/model/element.d.ts +0 -0
- /package/{src → dist}/model/history.d.ts +0 -0
- /package/{src → dist}/model/item.d.ts +0 -0
- /package/{src → dist}/model/liveposition.d.ts +0 -0
- /package/{src → dist}/model/liverange.d.ts +0 -0
- /package/{src → dist}/model/markercollection.d.ts +0 -0
- /package/{src → dist}/model/node.d.ts +0 -0
- /package/{src → dist}/model/nodelist.d.ts +0 -0
- /package/{src → dist}/model/operation/attributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/detachoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/insertoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/markeroperation.d.ts +0 -0
- /package/{src → dist}/model/operation/mergeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/moveoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/nooperation.d.ts +0 -0
- /package/{src → dist}/model/operation/operation.d.ts +0 -0
- /package/{src → dist}/model/operation/operationfactory.d.ts +0 -0
- /package/{src → dist}/model/operation/renameoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootattributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/splitoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/transform.d.ts +0 -0
- /package/{src → dist}/model/operation/utils.d.ts +0 -0
- /package/{src → dist}/model/position.d.ts +0 -0
- /package/{src → dist}/model/range.d.ts +0 -0
- /package/{src → dist}/model/rootelement.d.ts +0 -0
- /package/{src → dist}/model/schema.d.ts +0 -0
- /package/{src → dist}/model/text.d.ts +0 -0
- /package/{src → dist}/model/textproxy.d.ts +0 -0
- /package/{src → dist}/model/treewalker.d.ts +0 -0
- /package/{src → dist}/model/typecheckable.d.ts +0 -0
- /package/{src → dist}/model/utils/autoparagraphing.d.ts +0 -0
- /package/{src → dist}/model/utils/deletecontent.d.ts +0 -0
- /package/{src → dist}/model/utils/getselectedcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertobject.d.ts +0 -0
- /package/{src → dist}/model/utils/modifyselection.d.ts +0 -0
- /package/{src → dist}/model/utils/selection-post-fixer.d.ts +0 -0
- /package/{src → dist}/model/writer.d.ts +0 -0
- /package/{src → dist}/view/attributeelement.d.ts +0 -0
- /package/{src → dist}/view/containerelement.d.ts +0 -0
- /package/{src → dist}/view/datatransfer.d.ts +0 -0
- /package/{src → dist}/view/document.d.ts +0 -0
- /package/{src → dist}/view/documentfragment.d.ts +0 -0
- /package/{src → dist}/view/documentselection.d.ts +0 -0
- /package/{src → dist}/view/domconverter.d.ts +0 -0
- /package/{src → dist}/view/editableelement.d.ts +0 -0
- /package/{src → dist}/view/elementdefinition.d.ts +0 -0
- /package/{src → dist}/view/emptyelement.d.ts +0 -0
- /package/{src → dist}/view/filler.d.ts +0 -0
- /package/{src → dist}/view/item.d.ts +0 -0
- /package/{src → dist}/view/node.d.ts +0 -0
- /package/{src → dist}/view/observer/arrowkeysobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingemittermixin.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingeventinfo.d.ts +0 -0
- /package/{src → dist}/view/observer/clickobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/compositionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventdata.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/fakeselectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/focusobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/inputobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/keyobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mouseobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mutationobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/observer.d.ts +0 -0
- /package/{src → dist}/view/observer/pointerobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/selectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/tabobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/touchobserver.d.ts +0 -0
- /package/{src → dist}/view/placeholder.d.ts +0 -0
- /package/{src → dist}/view/position.d.ts +0 -0
- /package/{src → dist}/view/range.d.ts +0 -0
- /package/{src → dist}/view/rawelement.d.ts +0 -0
- /package/{src → dist}/view/renderer.d.ts +0 -0
- /package/{src → dist}/view/rooteditableelement.d.ts +0 -0
- /package/{src → dist}/view/selection.d.ts +0 -0
- /package/{src → dist}/view/stylesmap.d.ts +0 -0
- /package/{src → dist}/view/text.d.ts +0 -0
- /package/{src → dist}/view/textproxy.d.ts +0 -0
- /package/{src → dist}/view/tokenlist.d.ts +0 -0
- /package/{src → dist}/view/treewalker.d.ts +0 -0
- /package/{src → dist}/view/typecheckable.d.ts +0 -0
- /package/{src → dist}/view/uielement.d.ts +0 -0
- /package/{src → dist}/view/upcastwriter.d.ts +0 -0
- /package/{src → dist}/view/view.d.ts +0 -0
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/controller/datacontroller
|
|
7
|
-
*/
|
|
8
|
-
import { CKEditorError, EmitterMixin, ObservableMixin, logWarning } from '@ckeditor/ckeditor5-utils';
|
|
9
|
-
import { Mapper } from '../conversion/mapper.js';
|
|
10
|
-
import { DowncastDispatcher } from '../conversion/downcastdispatcher.js';
|
|
11
|
-
import { insertAttributesAndChildren, insertText } from '../conversion/downcasthelpers.js';
|
|
12
|
-
import { UpcastDispatcher } from '../conversion/upcastdispatcher.js';
|
|
13
|
-
import { convertText, convertToModelFragment } from '../conversion/upcasthelpers.js';
|
|
14
|
-
import { ViewDocumentFragment } from '../view/documentfragment.js';
|
|
15
|
-
import { ViewDocument } from '../view/document.js';
|
|
16
|
-
import { ViewDowncastWriter } from '../view/downcastwriter.js';
|
|
17
|
-
import { ModelRange } from '../model/range.js';
|
|
18
|
-
import { autoParagraphEmptyRoots } from '../model/utils/autoparagraphing.js';
|
|
19
|
-
import { HtmlDataProcessor } from '../dataprocessor/htmldataprocessor.js';
|
|
20
|
-
/**
|
|
21
|
-
* Controller for the data pipeline. The data pipeline controls how data is retrieved from the document
|
|
22
|
-
* and set inside it. Hence, the controller features two methods which allow to {@link ~DataController#get get}
|
|
23
|
-
* and {@link ~DataController#set set} data of the {@link ~DataController#model model}
|
|
24
|
-
* using the given:
|
|
25
|
-
*
|
|
26
|
-
* * {@link module:engine/dataprocessor/dataprocessor~DataProcessor data processor},
|
|
27
|
-
* * downcast converters,
|
|
28
|
-
* * upcast converters.
|
|
29
|
-
*
|
|
30
|
-
* An instance of the data controller is always available in the {@link module:core/editor/editor~Editor#data `editor.data`}
|
|
31
|
-
* property:
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* editor.data.get( { rootName: 'customRoot' } ); // -> '<p>Hello!</p>'
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export class DataController extends /* #__PURE__ */ EmitterMixin() {
|
|
38
|
-
/**
|
|
39
|
-
* Data model.
|
|
40
|
-
*/
|
|
41
|
-
model;
|
|
42
|
-
/**
|
|
43
|
-
* Mapper used for the conversion. It has no permanent bindings, because these are created while getting data and
|
|
44
|
-
* are cleared directly after the data are converted. However, the mapper is defined as a class property, because
|
|
45
|
-
* it needs to be passed to the `DowncastDispatcher` as a conversion API.
|
|
46
|
-
*/
|
|
47
|
-
mapper;
|
|
48
|
-
/**
|
|
49
|
-
* Downcast dispatcher used by the {@link #get get method}. Downcast converters should be attached to it.
|
|
50
|
-
*/
|
|
51
|
-
downcastDispatcher;
|
|
52
|
-
/**
|
|
53
|
-
* Upcast dispatcher used by the {@link #set set method}. Upcast converters should be attached to it.
|
|
54
|
-
*/
|
|
55
|
-
upcastDispatcher;
|
|
56
|
-
/**
|
|
57
|
-
* The view document used by the data controller.
|
|
58
|
-
*/
|
|
59
|
-
viewDocument;
|
|
60
|
-
/**
|
|
61
|
-
* Styles processor used during the conversion.
|
|
62
|
-
*/
|
|
63
|
-
stylesProcessor;
|
|
64
|
-
/**
|
|
65
|
-
* Data processor used specifically for HTML conversion.
|
|
66
|
-
*/
|
|
67
|
-
htmlProcessor;
|
|
68
|
-
/**
|
|
69
|
-
* Data processor used during the conversion.
|
|
70
|
-
* Same instance as {@link #htmlProcessor} by default. Can be replaced at run time to handle different format, e.g. XML or Markdown.
|
|
71
|
-
*/
|
|
72
|
-
processor;
|
|
73
|
-
/**
|
|
74
|
-
* The view downcast writer just for data conversion purposes, i.e. to modify
|
|
75
|
-
* the {@link #viewDocument}.
|
|
76
|
-
*/
|
|
77
|
-
_viewWriter;
|
|
78
|
-
/**
|
|
79
|
-
* Creates a data controller instance.
|
|
80
|
-
*
|
|
81
|
-
* @param model Data model.
|
|
82
|
-
* @param stylesProcessor The styles processor instance.
|
|
83
|
-
*/
|
|
84
|
-
constructor(model, stylesProcessor) {
|
|
85
|
-
super();
|
|
86
|
-
this.model = model;
|
|
87
|
-
this.mapper = new Mapper();
|
|
88
|
-
this.downcastDispatcher = new DowncastDispatcher({
|
|
89
|
-
mapper: this.mapper,
|
|
90
|
-
schema: model.schema
|
|
91
|
-
});
|
|
92
|
-
this.downcastDispatcher.on('insert:$text', insertText(), { priority: 'lowest' });
|
|
93
|
-
this.downcastDispatcher.on('insert', insertAttributesAndChildren(), { priority: 'lowest' });
|
|
94
|
-
this.upcastDispatcher = new UpcastDispatcher({
|
|
95
|
-
schema: model.schema
|
|
96
|
-
});
|
|
97
|
-
this.viewDocument = new ViewDocument(stylesProcessor);
|
|
98
|
-
this.stylesProcessor = stylesProcessor;
|
|
99
|
-
this.htmlProcessor = new HtmlDataProcessor(this.viewDocument);
|
|
100
|
-
this.processor = this.htmlProcessor;
|
|
101
|
-
this._viewWriter = new ViewDowncastWriter(this.viewDocument);
|
|
102
|
-
// Define default converters for text and elements.
|
|
103
|
-
//
|
|
104
|
-
// Note that if there is no default converter for the element it will be skipped, for instance `<b>foo</b>` will be
|
|
105
|
-
// converted to nothing. We therefore add `convertToModelFragment` as a last converter so it converts children of that
|
|
106
|
-
// element to the document fragment so `<b>foo</b>` will still be converted to `foo` even if there is no converter for `<b>`.
|
|
107
|
-
this.upcastDispatcher.on('text', convertText(), { priority: 'lowest' });
|
|
108
|
-
this.upcastDispatcher.on('element', convertToModelFragment(), { priority: 'lowest' });
|
|
109
|
-
this.upcastDispatcher.on('documentFragment', convertToModelFragment(), { priority: 'lowest' });
|
|
110
|
-
ObservableMixin().prototype.decorate.call(this, 'init');
|
|
111
|
-
ObservableMixin().prototype.decorate.call(this, 'set');
|
|
112
|
-
ObservableMixin().prototype.decorate.call(this, 'get');
|
|
113
|
-
ObservableMixin().prototype.decorate.call(this, 'toView');
|
|
114
|
-
ObservableMixin().prototype.decorate.call(this, 'toModel');
|
|
115
|
-
// Fire the `ready` event when the initialization has completed. Such low-level listener offers the possibility
|
|
116
|
-
// to plug into the initialization pipeline without interrupting the initialization flow.
|
|
117
|
-
this.on('init', () => {
|
|
118
|
-
this.fire('ready');
|
|
119
|
-
}, { priority: 'lowest' });
|
|
120
|
-
// Fix empty roots after DataController is 'ready' (note that the init method could be decorated and stopped).
|
|
121
|
-
// We need to handle this event because initial data could be empty and the post-fixer would not get triggered.
|
|
122
|
-
this.on('ready', () => {
|
|
123
|
-
this.model.enqueueChange({ isUndoable: false }, autoParagraphEmptyRoots);
|
|
124
|
-
}, { priority: 'lowest' });
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Returns the model's data converted by downcast dispatchers attached to {@link #downcastDispatcher} and
|
|
128
|
-
* formatted by the {@link #processor data processor}.
|
|
129
|
-
*
|
|
130
|
-
* A warning is logged when you try to retrieve data for a detached root, as most probably this is a mistake. A detached root should
|
|
131
|
-
* be treated like it is removed, and you should not save its data. Note, that the detached root data is always an empty string.
|
|
132
|
-
*
|
|
133
|
-
* @fires get
|
|
134
|
-
* @param options Additional configuration for the retrieved data. `DataController` provides two optional
|
|
135
|
-
* properties: `rootName` and `trim`. Other properties of this object are specified by various editor features.
|
|
136
|
-
* @param options.rootName Root name. Default 'main'.
|
|
137
|
-
* @param options.trim Whether returned data should be trimmed. This option is set to `empty` by default,
|
|
138
|
-
* which means whenever editor content is considered empty, an empty string will be returned. To turn off trimming completely
|
|
139
|
-
* use `'none'`. In such cases the exact content will be returned (for example a `<p> </p>` for an empty editor).
|
|
140
|
-
* @returns Output data.
|
|
141
|
-
*/
|
|
142
|
-
get(options = {}) {
|
|
143
|
-
const { rootName = 'main', trim = 'empty' } = options;
|
|
144
|
-
if (!this._checkIfRootsExists([rootName])) {
|
|
145
|
-
/**
|
|
146
|
-
* Cannot get data from a non-existing root. This error is thrown when
|
|
147
|
-
* {@link module:engine/controller/datacontroller~DataController#get `DataController#get()` method}
|
|
148
|
-
* is called with a non-existent root name. For example, if there is an editor instance with only `main` root,
|
|
149
|
-
* calling {@link module:engine/controller/datacontroller~DataController#get} like:
|
|
150
|
-
*
|
|
151
|
-
* ```ts
|
|
152
|
-
* data.get( { rootName: 'root2' } );
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* will throw this error.
|
|
156
|
-
*
|
|
157
|
-
* @error datacontroller-get-non-existent-root
|
|
158
|
-
*/
|
|
159
|
-
throw new CKEditorError('datacontroller-get-non-existent-root', this);
|
|
160
|
-
}
|
|
161
|
-
const root = this.model.document.getRoot(rootName);
|
|
162
|
-
if (!root.isAttached()) {
|
|
163
|
-
/**
|
|
164
|
-
* Retrieving document data for a detached root.
|
|
165
|
-
*
|
|
166
|
-
* This usually indicates an error as a detached root should be considered "removed" and should not be included in the
|
|
167
|
-
* document data.
|
|
168
|
-
*
|
|
169
|
-
* @error datacontroller-get-detached-root
|
|
170
|
-
*/
|
|
171
|
-
logWarning('datacontroller-get-detached-root', this);
|
|
172
|
-
}
|
|
173
|
-
if (trim === 'empty' && !this.model.hasContent(root, { ignoreWhitespaces: true })) {
|
|
174
|
-
return '';
|
|
175
|
-
}
|
|
176
|
-
return this.stringify(root, options);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Returns the content of the given {@link module:engine/model/element~ModelElement model's element} or
|
|
180
|
-
* {@link module:engine/model/documentfragment~ModelDocumentFragment model document fragment} converted by the downcast converters
|
|
181
|
-
* attached to the {@link #downcastDispatcher} and formatted by the {@link #processor data processor}.
|
|
182
|
-
*
|
|
183
|
-
* @param modelElementOrFragment The element whose content will be stringified.
|
|
184
|
-
* @param options Additional configuration passed to the conversion process.
|
|
185
|
-
* @returns Output data.
|
|
186
|
-
*/
|
|
187
|
-
stringify(modelElementOrFragment, options = {}) {
|
|
188
|
-
// Model -> view.
|
|
189
|
-
const viewDocumentFragment = this.toView(modelElementOrFragment, options);
|
|
190
|
-
// View -> data.
|
|
191
|
-
return this.processor.toData(viewDocumentFragment);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Returns the content of the given {@link module:engine/model/element~ModelElement model element} or
|
|
195
|
-
* {@link module:engine/model/documentfragment~ModelDocumentFragment model document fragment} converted by the downcast
|
|
196
|
-
* converters attached to {@link #downcastDispatcher} into a
|
|
197
|
-
* {@link module:engine/view/documentfragment~ViewDocumentFragment view document fragment}.
|
|
198
|
-
*
|
|
199
|
-
* @fires toView
|
|
200
|
-
* @param modelElementOrFragment Element or document fragment whose content will be converted.
|
|
201
|
-
* @param options Additional configuration that will be available through the
|
|
202
|
-
* {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi#options} during the conversion process.
|
|
203
|
-
* @returns Output view ModelDocumentFragment.
|
|
204
|
-
*/
|
|
205
|
-
toView(modelElementOrFragment, options = {}) {
|
|
206
|
-
const viewDocument = this.viewDocument;
|
|
207
|
-
const viewWriter = this._viewWriter;
|
|
208
|
-
// Clear bindings so the call to this method returns correct results.
|
|
209
|
-
this.mapper.clearBindings();
|
|
210
|
-
// First, convert elements.
|
|
211
|
-
const modelRange = ModelRange._createIn(modelElementOrFragment);
|
|
212
|
-
const viewDocumentFragment = new ViewDocumentFragment(viewDocument);
|
|
213
|
-
this.mapper.bindElements(modelElementOrFragment, viewDocumentFragment);
|
|
214
|
-
// Prepare list of markers.
|
|
215
|
-
// For document fragment, simply take the markers assigned to this document fragment.
|
|
216
|
-
// For model root, all markers in that root will be taken.
|
|
217
|
-
// For model element, we need to check which markers are intersecting with this element and relatively modify the markers' ranges.
|
|
218
|
-
// Collapsed markers at element boundary, although considered as not intersecting with the element, will also be returned.
|
|
219
|
-
const markers = modelElementOrFragment.is('documentFragment') ?
|
|
220
|
-
modelElementOrFragment.markers :
|
|
221
|
-
_getMarkersRelativeToElement(modelElementOrFragment);
|
|
222
|
-
this.downcastDispatcher.convert(modelRange, markers, viewWriter, options);
|
|
223
|
-
return viewDocumentFragment;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Sets the initial input data parsed by the {@link #processor data processor} and
|
|
227
|
-
* converted by the {@link #upcastDispatcher view-to-model converters}.
|
|
228
|
-
* Initial data can be only set to a document whose {@link module:engine/model/document~ModelDocument#version} is equal 0.
|
|
229
|
-
*
|
|
230
|
-
* **Note** This method is {@link module:utils/observablemixin~Observable#decorate decorated} which is
|
|
231
|
-
* used by e.g. collaborative editing plugin that syncs remote data on init.
|
|
232
|
-
*
|
|
233
|
-
* When data is passed as a string, it is initialized on the default `main` root:
|
|
234
|
-
*
|
|
235
|
-
* ```ts
|
|
236
|
-
* dataController.init( '<p>Foo</p>' ); // Initializes data on the `main` root only, as no other is specified.
|
|
237
|
-
* ```
|
|
238
|
-
*
|
|
239
|
-
* To initialize data on a different root or multiple roots at once, an object containing `rootName` - `data` pairs should be passed:
|
|
240
|
-
*
|
|
241
|
-
* ```ts
|
|
242
|
-
* dataController.init( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Initializes data on both the `main` and `title` roots.
|
|
243
|
-
* ```
|
|
244
|
-
*
|
|
245
|
-
* @fires init
|
|
246
|
-
* @param data Input data as a string or an object containing the `rootName` - `data`
|
|
247
|
-
* pairs to initialize data on multiple roots at once.
|
|
248
|
-
* @returns Promise that is resolved after the data is set on the editor.
|
|
249
|
-
*/
|
|
250
|
-
init(data) {
|
|
251
|
-
if (this.model.document.version) {
|
|
252
|
-
/**
|
|
253
|
-
* Cannot set initial data to a non-empty {@link module:engine/model/document~ModelDocument}.
|
|
254
|
-
* Initial data should be set once, during the {@link module:core/editor/editor~Editor} initialization,
|
|
255
|
-
* when the {@link module:engine/model/document~ModelDocument#version} is equal 0.
|
|
256
|
-
*
|
|
257
|
-
* @error datacontroller-init-document-not-empty
|
|
258
|
-
*/
|
|
259
|
-
throw new CKEditorError('datacontroller-init-document-not-empty', this);
|
|
260
|
-
}
|
|
261
|
-
let initialData = {};
|
|
262
|
-
if (typeof data === 'string') {
|
|
263
|
-
initialData.main = data; // Default root is 'main'. To initiate data on a different root, object should be passed.
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
initialData = data;
|
|
267
|
-
}
|
|
268
|
-
if (!this._checkIfRootsExists(Object.keys(initialData))) {
|
|
269
|
-
/**
|
|
270
|
-
* Cannot init data on a non-existent root. This error is thrown when
|
|
271
|
-
* {@link module:engine/controller/datacontroller~DataController#init DataController#init() method}
|
|
272
|
-
* is called with non-existent root name. For example, if there is an editor instance with only `main` root,
|
|
273
|
-
* calling {@link module:engine/controller/datacontroller~DataController#init} like:
|
|
274
|
-
*
|
|
275
|
-
* ```ts
|
|
276
|
-
* data.init( { main: '<p>Foo</p>', root2: '<p>Bar</p>' } );
|
|
277
|
-
* ```
|
|
278
|
-
*
|
|
279
|
-
* will throw this error.
|
|
280
|
-
*
|
|
281
|
-
* @error datacontroller-init-non-existent-root
|
|
282
|
-
*/
|
|
283
|
-
throw new CKEditorError('datacontroller-init-non-existent-root', this);
|
|
284
|
-
}
|
|
285
|
-
this.model.enqueueChange({ isUndoable: false }, writer => {
|
|
286
|
-
for (const rootName of Object.keys(initialData)) {
|
|
287
|
-
const modelRoot = this.model.document.getRoot(rootName);
|
|
288
|
-
writer.insert(this.parse(initialData[rootName], modelRoot), modelRoot, 0);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
return Promise.resolve();
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Sets the input data parsed by the {@link #processor data processor} and
|
|
295
|
-
* converted by the {@link #upcastDispatcher view-to-model converters}.
|
|
296
|
-
* This method can be used any time to replace existing editor data with the new one without clearing the
|
|
297
|
-
* {@link module:engine/model/document~ModelDocument#history document history}.
|
|
298
|
-
*
|
|
299
|
-
* This method also creates a batch with all the changes applied. If all you need is to parse data, use
|
|
300
|
-
* the {@link #parse} method.
|
|
301
|
-
*
|
|
302
|
-
* When data is passed as a string it is set on the default `main` root:
|
|
303
|
-
*
|
|
304
|
-
* ```ts
|
|
305
|
-
* dataController.set( '<p>Foo</p>' ); // Sets data on the `main` root, as no other is specified.
|
|
306
|
-
* ```
|
|
307
|
-
*
|
|
308
|
-
* To set data on a different root or multiple roots at once, an object containing `rootName` - `data` pairs should be passed:
|
|
309
|
-
*
|
|
310
|
-
* ```ts
|
|
311
|
-
* dataController.set( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Sets data on the `main` and `title` roots as specified.
|
|
312
|
-
* ```
|
|
313
|
-
*
|
|
314
|
-
* To set the data with a preserved undo stack and add the change to the undo stack, set `{ isUndoable: true }` as a `batchType` option.
|
|
315
|
-
*
|
|
316
|
-
* ```ts
|
|
317
|
-
* dataController.set( '<p>Foo</p>', { batchType: { isUndoable: true } } );
|
|
318
|
-
* ```
|
|
319
|
-
*
|
|
320
|
-
* @fires set
|
|
321
|
-
* @param data Input data as a string or an object containing the `rootName` - `data`
|
|
322
|
-
* pairs to set data on multiple roots at once.
|
|
323
|
-
* @param options Options for setting data.
|
|
324
|
-
* @param options.batchType The batch type that will be used to create a batch for the changes applied by this method.
|
|
325
|
-
* By default, the batch will be set as {@link module:engine/model/batch~Batch#isUndoable not undoable} and the undo stack will be
|
|
326
|
-
* cleared after the new data is applied (all undo steps will be removed). If the batch type `isUndoable` flag is be set to `true`,
|
|
327
|
-
* the undo stack will be preserved instead and not cleared when new data is applied.
|
|
328
|
-
*/
|
|
329
|
-
set(data, options = {}) {
|
|
330
|
-
let newData = {};
|
|
331
|
-
if (typeof data === 'string') {
|
|
332
|
-
newData.main = data; // The default root is 'main'. To set data on a different root, an object should be passed.
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
newData = data;
|
|
336
|
-
}
|
|
337
|
-
if (!this._checkIfRootsExists(Object.keys(newData))) {
|
|
338
|
-
/**
|
|
339
|
-
* Cannot set data on a non-existent root. This error is thrown when the
|
|
340
|
-
* {@link module:engine/controller/datacontroller~DataController#set DataController#set() method}
|
|
341
|
-
* is called with non-existent root name. For example, if there is an editor instance with only the default `main` root,
|
|
342
|
-
* calling {@link module:engine/controller/datacontroller~DataController#set} like:
|
|
343
|
-
*
|
|
344
|
-
* ```ts
|
|
345
|
-
* data.set( { main: '<p>Foo</p>', root2: '<p>Bar</p>' } );
|
|
346
|
-
* ```
|
|
347
|
-
*
|
|
348
|
-
* will throw this error.
|
|
349
|
-
*
|
|
350
|
-
* @error datacontroller-set-non-existent-root
|
|
351
|
-
*/
|
|
352
|
-
throw new CKEditorError('datacontroller-set-non-existent-root', this);
|
|
353
|
-
}
|
|
354
|
-
this.model.enqueueChange(options.batchType || {}, writer => {
|
|
355
|
-
writer.setSelection(null);
|
|
356
|
-
writer.removeSelectionAttribute(this.model.document.selection.getAttributeKeys());
|
|
357
|
-
for (const rootName of Object.keys(newData)) {
|
|
358
|
-
// Save to model.
|
|
359
|
-
const modelRoot = this.model.document.getRoot(rootName);
|
|
360
|
-
writer.remove(writer.createRangeIn(modelRoot));
|
|
361
|
-
writer.insert(this.parse(newData[rootName], modelRoot), modelRoot, 0);
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Returns the data parsed by the {@link #processor data processor} and then converted by upcast converters
|
|
367
|
-
* attached to the {@link #upcastDispatcher}.
|
|
368
|
-
*
|
|
369
|
-
* @see #set
|
|
370
|
-
* @param data Data to parse.
|
|
371
|
-
* @param context Base context in which the view will be converted to the model.
|
|
372
|
-
* See: {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert}.
|
|
373
|
-
* @returns Parsed data.
|
|
374
|
-
*/
|
|
375
|
-
parse(data, context = '$root') {
|
|
376
|
-
// data -> view
|
|
377
|
-
const viewDocumentFragment = this.processor.toView(data);
|
|
378
|
-
// view -> model
|
|
379
|
-
return this.toModel(viewDocumentFragment, context);
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Returns the result of the given {@link module:engine/view/element~ViewElement view element} or
|
|
383
|
-
* {@link module:engine/view/documentfragment~ViewDocumentFragment view document fragment} converted by the
|
|
384
|
-
* {@link #upcastDispatcher view-to-model converters}, wrapped by {@link module:engine/model/documentfragment~ModelDocumentFragment}.
|
|
385
|
-
*
|
|
386
|
-
* When marker elements were converted during the conversion process, it will be set as a document fragment's
|
|
387
|
-
* {@link module:engine/model/documentfragment~ModelDocumentFragment#markers static markers map}.
|
|
388
|
-
*
|
|
389
|
-
* @fires toModel
|
|
390
|
-
* @param viewElementOrFragment The element or document fragment whose content will be converted.
|
|
391
|
-
* @param context Base context in which the view will be converted to the model.
|
|
392
|
-
* See: {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert}.
|
|
393
|
-
* @returns Output document fragment.
|
|
394
|
-
*/
|
|
395
|
-
toModel(viewElementOrFragment, context = '$root') {
|
|
396
|
-
return this.model.change(writer => {
|
|
397
|
-
return this.upcastDispatcher.convert(viewElementOrFragment, writer, context);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Adds the style processor normalization rules.
|
|
402
|
-
*
|
|
403
|
-
* You can implement your own rules as well as use one of the available processor rules:
|
|
404
|
-
*
|
|
405
|
-
* * background: {@link module:engine/view/styles/background~addBackgroundStylesRules}
|
|
406
|
-
* * border: {@link module:engine/view/styles/border~addBorderStylesRules}
|
|
407
|
-
* * margin: {@link module:engine/view/styles/margin~addMarginStylesRules}
|
|
408
|
-
* * padding: {@link module:engine/view/styles/padding~addPaddingStylesRules}
|
|
409
|
-
*/
|
|
410
|
-
addStyleProcessorRules(callback) {
|
|
411
|
-
callback(this.stylesProcessor);
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Registers a {@link module:engine/view/matcher~MatcherPattern} on an {@link #htmlProcessor htmlProcessor}
|
|
415
|
-
* and a {@link #processor processor} for view elements whose content should be treated as raw data
|
|
416
|
-
* and not processed during the conversion from DOM to view elements.
|
|
417
|
-
*
|
|
418
|
-
* The raw data can be later accessed by the
|
|
419
|
-
* {@link module:engine/view/element~ViewElement#getCustomProperty view element custom property}
|
|
420
|
-
* `"$rawContent"`.
|
|
421
|
-
*
|
|
422
|
-
* @param pattern Pattern matching all view elements whose content should be treated as a raw data.
|
|
423
|
-
*/
|
|
424
|
-
registerRawContentMatcher(pattern) {
|
|
425
|
-
// No need to register the pattern if both the `htmlProcessor` and `processor` are the same instances.
|
|
426
|
-
if (this.processor && this.processor !== this.htmlProcessor) {
|
|
427
|
-
this.processor.registerRawContentMatcher(pattern);
|
|
428
|
-
}
|
|
429
|
-
this.htmlProcessor.registerRawContentMatcher(pattern);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Removes all event listeners set by the DataController.
|
|
433
|
-
*/
|
|
434
|
-
destroy() {
|
|
435
|
-
this.stopListening();
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Checks whether all provided root names are actually existing editor roots.
|
|
439
|
-
*
|
|
440
|
-
* @param rootNames Root names to check.
|
|
441
|
-
* @returns Whether all provided root names are existing editor roots.
|
|
442
|
-
*/
|
|
443
|
-
_checkIfRootsExists(rootNames) {
|
|
444
|
-
for (const rootName of rootNames) {
|
|
445
|
-
if (!this.model.document.getRoot(rootName)) {
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Helper function for downcast conversion.
|
|
454
|
-
*
|
|
455
|
-
* Takes a document element (element that is added to a model document) and checks which markers are inside it. If the marker is collapsed
|
|
456
|
-
* at element boundary, it is considered as contained inside the element and marker range is returned. Otherwise, if the marker is
|
|
457
|
-
* intersecting with the element, the intersection is returned.
|
|
458
|
-
*/
|
|
459
|
-
function _getMarkersRelativeToElement(element) {
|
|
460
|
-
const result = [];
|
|
461
|
-
const doc = element.root.document;
|
|
462
|
-
if (!doc) {
|
|
463
|
-
return new Map();
|
|
464
|
-
}
|
|
465
|
-
const elementRange = ModelRange._createIn(element);
|
|
466
|
-
for (const marker of doc.model.markers) {
|
|
467
|
-
const markerRange = marker.getRange();
|
|
468
|
-
const isMarkerCollapsed = markerRange.isCollapsed;
|
|
469
|
-
const isMarkerAtElementBoundary = markerRange.start.isEqual(elementRange.start) || markerRange.end.isEqual(elementRange.end);
|
|
470
|
-
if (isMarkerCollapsed && isMarkerAtElementBoundary) {
|
|
471
|
-
result.push([marker.name, markerRange]);
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
const updatedMarkerRange = elementRange.getIntersection(markerRange);
|
|
475
|
-
if (updatedMarkerRange) {
|
|
476
|
-
result.push([marker.name, updatedMarkerRange]);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
// Sort the markers in a stable fashion to ensure that the order in which they are
|
|
481
|
-
// added to the model's marker collection does not affect how they are
|
|
482
|
-
// downcast. One particular use case that we are targeting here, is one where
|
|
483
|
-
// two markers are adjacent but not overlapping, such as an insertion/deletion
|
|
484
|
-
// suggestion pair representing the replacement of a range of text. In this
|
|
485
|
-
// case, putting the markers in DOM order causes the first marker's end to be
|
|
486
|
-
// serialized right after the second marker's start, while putting the markers
|
|
487
|
-
// in reverse DOM order causes it to be right before the second marker's
|
|
488
|
-
// start. So, we sort these in a way that ensures non-intersecting ranges are in
|
|
489
|
-
// reverse DOM order, and intersecting ranges are in something approximating
|
|
490
|
-
// reverse DOM order (since reverse DOM order doesn't have a precise meaning
|
|
491
|
-
// when working with intersecting ranges).
|
|
492
|
-
result.sort(([n1, r1], [n2, r2]) => {
|
|
493
|
-
if (r1.end.compareWith(r2.start) !== 'after') {
|
|
494
|
-
// m1.end <= m2.start -- m1 is entirely <= m2
|
|
495
|
-
return 1;
|
|
496
|
-
}
|
|
497
|
-
else if (r1.start.compareWith(r2.end) !== 'before') {
|
|
498
|
-
// m1.start >= m2.end -- m1 is entirely >= m2
|
|
499
|
-
return -1;
|
|
500
|
-
}
|
|
501
|
-
else {
|
|
502
|
-
// they overlap, so use their start positions as the primary sort key and
|
|
503
|
-
// end positions as the secondary sort key
|
|
504
|
-
switch (r1.start.compareWith(r2.start)) {
|
|
505
|
-
case 'before':
|
|
506
|
-
return 1;
|
|
507
|
-
case 'after':
|
|
508
|
-
return -1;
|
|
509
|
-
default:
|
|
510
|
-
switch (r1.end.compareWith(r2.end)) {
|
|
511
|
-
case 'before':
|
|
512
|
-
return 1;
|
|
513
|
-
case 'after':
|
|
514
|
-
return -1;
|
|
515
|
-
default:
|
|
516
|
-
return n2.localeCompare(n1);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
return new Map(result);
|
|
522
|
-
}
|