@ckeditor/ckeditor5-engine 44.3.0 → 45.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/LICENSE.md +1 -1
- package/dist/index.js +305 -129
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/controller/datacontroller.js +40 -0
- package/src/controller/editingcontroller.js +16 -0
- package/src/conversion/conversion.js +6 -4
- package/src/conversion/conversionhelpers.js +1 -0
- package/src/conversion/downcastdispatcher.js +10 -0
- package/src/conversion/downcasthelpers.js +1 -1
- package/src/conversion/mapper.js +92 -95
- package/src/conversion/modelconsumable.js +13 -15
- package/src/conversion/upcastdispatcher.js +28 -24
- package/src/conversion/upcasthelpers.d.ts +1 -1
- package/src/conversion/upcasthelpers.js +2 -2
- package/src/conversion/viewconsumable.js +19 -20
- package/src/dataprocessor/htmldataprocessor.js +13 -1
- package/src/dataprocessor/xmldataprocessor.js +21 -1
- package/src/dev-utils/model.js +1 -1
- package/src/dev-utils/operationreplayer.js +3 -0
- package/src/dev-utils/utils.js +35 -1
- package/src/dev-utils/view.js +13 -0
- package/src/model/batch.js +20 -0
- package/src/model/differ.js +92 -88
- package/src/model/document.d.ts +1 -3
- package/src/model/document.js +38 -1
- package/src/model/documentfragment.js +10 -10
- package/src/model/documentselection.js +44 -32
- package/src/model/element.js +8 -4
- package/src/model/history.js +31 -33
- package/src/model/markercollection.js +25 -7
- package/src/model/model.js +21 -0
- package/src/model/node.js +22 -18
- package/src/model/nodelist.js +12 -12
- package/src/model/operation/attributeoperation.js +25 -1
- package/src/model/operation/detachoperation.js +8 -0
- package/src/model/operation/insertoperation.js +18 -0
- package/src/model/operation/markeroperation.js +29 -0
- package/src/model/operation/mergeoperation.js +16 -0
- package/src/model/operation/moveoperation.js +12 -0
- package/src/model/operation/operation.js +19 -0
- package/src/model/operation/renameoperation.js +12 -0
- package/src/model/operation/rootattributeoperation.js +20 -0
- package/src/model/operation/rootoperation.js +16 -0
- package/src/model/operation/splitoperation.js +19 -0
- package/src/model/operation/transform.js +5 -0
- package/src/model/position.js +40 -0
- package/src/model/range.js +8 -0
- package/src/model/rootelement.js +18 -10
- package/src/model/schema.js +25 -23
- package/src/model/selection.js +10 -10
- package/src/model/text.js +6 -0
- package/src/model/textproxy.js +12 -0
- package/src/model/treewalker.js +49 -0
- package/src/model/utils/insertcontent.js +60 -25
- package/src/model/writer.js +8 -0
- package/src/view/attributeelement.js +23 -23
- package/src/view/datatransfer.js +8 -0
- package/src/view/document.js +21 -4
- package/src/view/documentfragment.js +13 -9
- package/src/view/documentselection.js +4 -0
- package/src/view/domconverter.d.ts +6 -1
- package/src/view/domconverter.js +109 -48
- package/src/view/downcastwriter.js +14 -10
- package/src/view/element.js +29 -17
- package/src/view/matcher.js +1 -1
- package/src/view/node.js +9 -1
- package/src/view/observer/bubblingeventinfo.js +12 -0
- package/src/view/observer/clickobserver.js +4 -7
- package/src/view/observer/compositionobserver.js +14 -12
- package/src/view/observer/domeventdata.js +17 -1
- package/src/view/observer/domeventobserver.js +10 -13
- package/src/view/observer/fakeselectionobserver.d.ts +1 -1
- package/src/view/observer/fakeselectionobserver.js +5 -1
- package/src/view/observer/focusobserver.js +65 -14
- package/src/view/observer/inputobserver.js +33 -26
- package/src/view/observer/keyobserver.js +4 -7
- package/src/view/observer/mouseobserver.js +4 -7
- package/src/view/observer/mutationobserver.js +23 -6
- package/src/view/observer/observer.js +12 -4
- package/src/view/observer/selectionobserver.d.ts +6 -1
- package/src/view/observer/selectionobserver.js +94 -17
- package/src/view/observer/touchobserver.js +4 -7
- package/src/view/position.js +8 -0
- package/src/view/range.js +8 -0
- package/src/view/renderer.js +142 -70
- package/src/view/selection.js +16 -0
- package/src/view/stylesmap.js +26 -11
- package/src/view/text.js +6 -0
- package/src/view/textproxy.js +12 -0
- package/src/view/tokenlist.js +4 -6
- package/src/view/treewalker.js +42 -0
- package/src/view/upcastwriter.js +5 -1
- package/src/view/view.js +51 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "45.0.0-alpha.1",
|
|
4
4
|
"description": "The editing engine of CKEditor 5 – the best browser-based rich text editor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wysiwyg",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"type": "module",
|
|
25
25
|
"main": "src/index.js",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@ckeditor/ckeditor5-utils": "
|
|
28
|
-
"
|
|
27
|
+
"@ckeditor/ckeditor5-utils": "45.0.0-alpha.1",
|
|
28
|
+
"es-toolkit": "1.32.0"
|
|
29
29
|
},
|
|
30
30
|
"author": "CKSource (http://cksource.com/)",
|
|
31
31
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -35,6 +35,46 @@ import HtmlDataProcessor from '../dataprocessor/htmldataprocessor.js';
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export default 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;
|
|
38
78
|
/**
|
|
39
79
|
* Creates a data controller instance.
|
|
40
80
|
*
|
|
@@ -20,6 +20,22 @@ import { tryFixingRange } from '../model/utils/selection-post-fixer.js';
|
|
|
20
20
|
* browser-independent virtualization over the DOM elements. The editing controller also attaches default converters.
|
|
21
21
|
*/
|
|
22
22
|
export default class EditingController extends /* #__PURE__ */ ObservableMixin() {
|
|
23
|
+
/**
|
|
24
|
+
* Editor model.
|
|
25
|
+
*/
|
|
26
|
+
model;
|
|
27
|
+
/**
|
|
28
|
+
* Editing view controller.
|
|
29
|
+
*/
|
|
30
|
+
view;
|
|
31
|
+
/**
|
|
32
|
+
* A mapper that describes the model-view binding.
|
|
33
|
+
*/
|
|
34
|
+
mapper;
|
|
35
|
+
/**
|
|
36
|
+
* Downcast dispatcher that converts changes from the model to the {@link #view editing view}.
|
|
37
|
+
*/
|
|
38
|
+
downcastDispatcher;
|
|
23
39
|
/**
|
|
24
40
|
* Creates an editing controller instance.
|
|
25
41
|
*
|
|
@@ -55,14 +55,16 @@ import DowncastHelpers from './downcasthelpers.js';
|
|
|
55
55
|
* Model attribute to view attribute and vice versa.
|
|
56
56
|
*/
|
|
57
57
|
export default class Conversion {
|
|
58
|
+
/**
|
|
59
|
+
* Maps dispatchers group name to ConversionHelpers instances.
|
|
60
|
+
*/
|
|
61
|
+
_helpers = new Map();
|
|
62
|
+
_downcast;
|
|
63
|
+
_upcast;
|
|
58
64
|
/**
|
|
59
65
|
* Creates a new conversion instance.
|
|
60
66
|
*/
|
|
61
67
|
constructor(downcastDispatchers, upcastDispatchers) {
|
|
62
|
-
/**
|
|
63
|
-
* Maps dispatchers group name to ConversionHelpers instances.
|
|
64
|
-
*/
|
|
65
|
-
this._helpers = new Map();
|
|
66
68
|
// Define default 'downcast' & 'upcast' dispatchers groups. Those groups are always available as two-way converters needs them.
|
|
67
69
|
this._downcast = toArray(downcastDispatchers);
|
|
68
70
|
this._createConversionHelpers({ name: 'downcast', dispatchers: this._downcast, isDowncast: true });
|
|
@@ -100,6 +100,16 @@ import { EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
|
100
100
|
* ```
|
|
101
101
|
*/
|
|
102
102
|
export default class DowncastDispatcher extends /* #__PURE__ */ EmitterMixin() {
|
|
103
|
+
/**
|
|
104
|
+
* A template for an interface passed by the dispatcher to the event callbacks.
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
_conversionApi;
|
|
109
|
+
/**
|
|
110
|
+
* A map of already fired events for a given `ModelConsumable`.
|
|
111
|
+
*/
|
|
112
|
+
_firedEventsMap;
|
|
103
113
|
/**
|
|
104
114
|
* Creates a downcast dispatcher instance.
|
|
105
115
|
*
|
|
@@ -16,7 +16,7 @@ import ViewAttributeElement from '../view/attributeelement.js';
|
|
|
16
16
|
import ConversionHelpers from './conversionhelpers.js';
|
|
17
17
|
import StylesMap from '../view/stylesmap.js';
|
|
18
18
|
import { CKEditorError, toArray } from '@ckeditor/ckeditor5-utils';
|
|
19
|
-
import { cloneDeep } from '
|
|
19
|
+
import { cloneDeep } from 'es-toolkit/compat';
|
|
20
20
|
/**
|
|
21
21
|
* Downcast conversion helper functions.
|
|
22
22
|
*
|
package/src/conversion/mapper.js
CHANGED
|
@@ -30,50 +30,50 @@ import { CKEditorError, EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
|
30
30
|
* stop the event.
|
|
31
31
|
*/
|
|
32
32
|
export default class Mapper extends /* #__PURE__ */ EmitterMixin() {
|
|
33
|
+
/**
|
|
34
|
+
* Model element to view element mapping.
|
|
35
|
+
*/
|
|
36
|
+
_modelToViewMapping = new WeakMap();
|
|
37
|
+
/**
|
|
38
|
+
* View element to model element mapping.
|
|
39
|
+
*/
|
|
40
|
+
_viewToModelMapping = new WeakMap();
|
|
41
|
+
/**
|
|
42
|
+
* A map containing callbacks between view element names and functions evaluating length of view elements
|
|
43
|
+
* in model.
|
|
44
|
+
*/
|
|
45
|
+
_viewToModelLengthCallbacks = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* Model marker name to view elements mapping.
|
|
48
|
+
*
|
|
49
|
+
* Keys are `String`s while values are `Set`s with {@link module:engine/view/element~Element view elements}.
|
|
50
|
+
* One marker (name) can be mapped to multiple elements.
|
|
51
|
+
*/
|
|
52
|
+
_markerNameToElements = new Map();
|
|
53
|
+
/**
|
|
54
|
+
* View element to model marker names mapping.
|
|
55
|
+
*
|
|
56
|
+
* This is reverse to {@link ~Mapper#_markerNameToElements} map.
|
|
57
|
+
*/
|
|
58
|
+
_elementToMarkerNames = new Map();
|
|
59
|
+
/**
|
|
60
|
+
* The map of removed view elements with their current root (used for deferred unbinding).
|
|
61
|
+
*/
|
|
62
|
+
_deferredBindingRemovals = new Map();
|
|
63
|
+
/**
|
|
64
|
+
* Stores marker names of markers which have changed due to unbinding a view element (so it is assumed that the view element
|
|
65
|
+
* has been removed, moved or renamed).
|
|
66
|
+
*/
|
|
67
|
+
_unboundMarkerNames = new Set();
|
|
68
|
+
/**
|
|
69
|
+
* Manages dynamic cache for the `Mapper` to improve the performance.
|
|
70
|
+
*/
|
|
71
|
+
_cache = new MapperCache();
|
|
33
72
|
/**
|
|
34
73
|
* Creates an instance of the mapper.
|
|
35
74
|
*/
|
|
36
75
|
constructor() {
|
|
37
76
|
super();
|
|
38
|
-
/**
|
|
39
|
-
* Model element to view element mapping.
|
|
40
|
-
*/
|
|
41
|
-
this._modelToViewMapping = new WeakMap();
|
|
42
|
-
/**
|
|
43
|
-
* View element to model element mapping.
|
|
44
|
-
*/
|
|
45
|
-
this._viewToModelMapping = new WeakMap();
|
|
46
|
-
/**
|
|
47
|
-
* A map containing callbacks between view element names and functions evaluating length of view elements
|
|
48
|
-
* in model.
|
|
49
|
-
*/
|
|
50
|
-
this._viewToModelLengthCallbacks = new Map();
|
|
51
|
-
/**
|
|
52
|
-
* Model marker name to view elements mapping.
|
|
53
|
-
*
|
|
54
|
-
* Keys are `String`s while values are `Set`s with {@link module:engine/view/element~Element view elements}.
|
|
55
|
-
* One marker (name) can be mapped to multiple elements.
|
|
56
|
-
*/
|
|
57
|
-
this._markerNameToElements = new Map();
|
|
58
|
-
/**
|
|
59
|
-
* View element to model marker names mapping.
|
|
60
|
-
*
|
|
61
|
-
* This is reverse to {@link ~Mapper#_markerNameToElements} map.
|
|
62
|
-
*/
|
|
63
|
-
this._elementToMarkerNames = new Map();
|
|
64
|
-
/**
|
|
65
|
-
* The map of removed view elements with their current root (used for deferred unbinding).
|
|
66
|
-
*/
|
|
67
|
-
this._deferredBindingRemovals = new Map();
|
|
68
|
-
/**
|
|
69
|
-
* Stores marker names of markers which have changed due to unbinding a view element (so it is assumed that the view element
|
|
70
|
-
* has been removed, moved or renamed).
|
|
71
|
-
*/
|
|
72
|
-
this._unboundMarkerNames = new Set();
|
|
73
|
-
/**
|
|
74
|
-
* Manages dynamic cache for the `Mapper` to improve the performance.
|
|
75
|
-
*/
|
|
76
|
-
this._cache = new MapperCache();
|
|
77
77
|
// Default mapper algorithm for mapping model position to view position.
|
|
78
78
|
this.on('modelToViewPosition', (evt, data) => {
|
|
79
79
|
if (data.viewPosition) {
|
|
@@ -650,62 +650,59 @@ export default class Mapper extends /* #__PURE__ */ EmitterMixin() {
|
|
|
650
650
|
* @internal
|
|
651
651
|
*/
|
|
652
652
|
export class MapperCache extends /* #__PURE__ */ EmitterMixin() {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
this.
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
this.
|
|
705
|
-
|
|
706
|
-
this._clearCacheStartingBefore(viewNode);
|
|
707
|
-
};
|
|
708
|
-
}
|
|
653
|
+
/**
|
|
654
|
+
* For every view element or document fragment tracked by `MapperCache`, it holds currently cached data, or more precisely,
|
|
655
|
+
* model offset to view position mappings. See also `MappingCache` and `CacheItem`.
|
|
656
|
+
*
|
|
657
|
+
* If an item is tracked by `MapperCache` it has an entry in this structure, so this structure can be used to check which items
|
|
658
|
+
* are tracked by `MapperCache`. When an item is no longer tracked, it is removed from this structure.
|
|
659
|
+
*
|
|
660
|
+
* Although `MappingCache` and `CacheItem` structures allows for caching any model offsets and view positions, we only cache
|
|
661
|
+
* values for model offsets that are after a view node. So, in essence, positions inside text nodes are not cached. However, it takes
|
|
662
|
+
* from one to at most a few steps, to get from a cached position to a position that is inside a view text node.
|
|
663
|
+
*
|
|
664
|
+
* Additionally, only one item per `modelOffset` is cached. There can be several view nodes that "end" at the same `modelOffset`.
|
|
665
|
+
* In this case, we favour positions that are closer to the mapped item. For example
|
|
666
|
+
*
|
|
667
|
+
* * for model: `<paragraph>Some <$text bold=true italic=true>formatted</$text> text.</paragraph>`,
|
|
668
|
+
* * and view: `<p>Some <em><strong>formatted</strong></em> text.</p>`,
|
|
669
|
+
*
|
|
670
|
+
* for model offset `14` (after "d"), we store view position after `<em>` element (i.e. view position: at `<p>`, offset `2`).
|
|
671
|
+
*/
|
|
672
|
+
_cachedMapping = new WeakMap();
|
|
673
|
+
/**
|
|
674
|
+
* When `MapperCache` {@link ~MapperCache#save saves} view position -> model offset mapping, a `CacheItem` is inserted into certain
|
|
675
|
+
* `MappingCache#cacheList` at some index. Additionally, we store that index with the view node that is before the cached view position.
|
|
676
|
+
*
|
|
677
|
+
* This allows to quickly get a cache list item related to certain view node, and hence, for fast cache invalidation.
|
|
678
|
+
*
|
|
679
|
+
* For example, consider view: `<p>Some <strong>bold</strong> text.</p>`, where `<p>` is a view element tracked by `MapperCache`.
|
|
680
|
+
* If all `<p>` children were visited by `MapperCache`, then `<p>` cache list would have four items, related to following model offsets:
|
|
681
|
+
* `0`, `5`, `9`, `15`. Then, view node `"Some "` would have index `1`, `<strong>` index `2`, and `" text." index `3`.
|
|
682
|
+
*
|
|
683
|
+
* Note that the index related with a node is always greater than `0`. The first item in cache list is always for model offset `0`
|
|
684
|
+
* (and view offset `0`), and it is not related to any node.
|
|
685
|
+
*/
|
|
686
|
+
_nodeToCacheListIndex = new WeakMap();
|
|
687
|
+
/**
|
|
688
|
+
* Callback fired whenever there is a direct or indirect children change in tracked view element or tracked view document fragment.
|
|
689
|
+
*
|
|
690
|
+
* This is specified as a property to make it easier to set as an event callback and to later turn off that event.
|
|
691
|
+
*/
|
|
692
|
+
_invalidateOnChildrenChangeCallback = (evt, viewNode, data) => {
|
|
693
|
+
// View element or document fragment changed its children at `data.index`. Clear all cache starting from before that index.
|
|
694
|
+
this._clearCacheInsideParent(viewNode, data.index);
|
|
695
|
+
};
|
|
696
|
+
/**
|
|
697
|
+
* Callback fired whenever a view text node directly or indirectly inside a tracked view element or tracked view document fragment
|
|
698
|
+
* changes its text data.
|
|
699
|
+
*
|
|
700
|
+
* This is specified as a property to make it easier to set as an event callback and to later turn off that event.
|
|
701
|
+
*/
|
|
702
|
+
_invalidateOnTextChangeCallback = (evt, viewNode) => {
|
|
703
|
+
// Text node has changed. Clear all the cache starting from before this text node.
|
|
704
|
+
this._clearCacheStartingBefore(viewNode);
|
|
705
|
+
};
|
|
709
706
|
/**
|
|
710
707
|
* Saves cache for given view position mapping <-> model offset mapping. The view position should be after a node (i.e. it cannot
|
|
711
708
|
* be the first position inside its parent, or in other words, `viewOffset` must be greater than `0`).
|
|
@@ -88,21 +88,19 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
|
88
88
|
* ```
|
|
89
89
|
*/
|
|
90
90
|
export default class ModelConsumable {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this._textProxyRegistry = new Map();
|
|
105
|
-
}
|
|
91
|
+
/**
|
|
92
|
+
* Contains list of consumable values.
|
|
93
|
+
*/
|
|
94
|
+
_consumable = new Map();
|
|
95
|
+
/**
|
|
96
|
+
* For each {@link module:engine/model/textproxy~TextProxy} added to `ModelConsumable`, this registry holds a parent
|
|
97
|
+
* of that `TextProxy` and the start and end indices of that `TextProxy`. This allows identification of the `TextProxy`
|
|
98
|
+
* instances that point to the same part of the model but are different instances. Each distinct `TextProxy`
|
|
99
|
+
* is given a unique `Symbol` which is then registered as consumable. This process is transparent for the `ModelConsumable`
|
|
100
|
+
* API user because whenever `TextProxy` is added, tested, consumed or reverted, the internal mechanisms of
|
|
101
|
+
* `ModelConsumable` translate `TextProxy` to that unique `Symbol`.
|
|
102
|
+
*/
|
|
103
|
+
_textProxyRegistry = new Map();
|
|
106
104
|
/**
|
|
107
105
|
* Adds a consumable value to the consumables list and links it with a given model item.
|
|
108
106
|
*
|
|
@@ -108,6 +108,34 @@ import { CKEditorError, EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
|
108
108
|
* @fires documentFragment
|
|
109
109
|
*/
|
|
110
110
|
export default class UpcastDispatcher extends /* #__PURE__ */ EmitterMixin() {
|
|
111
|
+
/**
|
|
112
|
+
* An interface passed by the dispatcher to the event callbacks.
|
|
113
|
+
*/
|
|
114
|
+
conversionApi;
|
|
115
|
+
/**
|
|
116
|
+
* The list of elements that were created during splitting.
|
|
117
|
+
*
|
|
118
|
+
* After the conversion process, the list is cleared.
|
|
119
|
+
*/
|
|
120
|
+
_splitParts = new Map();
|
|
121
|
+
/**
|
|
122
|
+
* The list of cursor parent elements that were created during splitting.
|
|
123
|
+
*
|
|
124
|
+
* After the conversion process the list is cleared.
|
|
125
|
+
*/
|
|
126
|
+
_cursorParents = new Map();
|
|
127
|
+
/**
|
|
128
|
+
* The position in the temporary structure where the converted content is inserted. The structure reflects the context of
|
|
129
|
+
* the target position where the content will be inserted. This property is built based on the context parameter of the
|
|
130
|
+
* convert method.
|
|
131
|
+
*/
|
|
132
|
+
_modelCursor = null;
|
|
133
|
+
/**
|
|
134
|
+
* The list of elements that were created during the splitting but should not get removed on conversion end even if they are empty.
|
|
135
|
+
*
|
|
136
|
+
* The list is cleared after the conversion process.
|
|
137
|
+
*/
|
|
138
|
+
_emptyElementsToKeep = new Set();
|
|
111
139
|
/**
|
|
112
140
|
* Creates an upcast dispatcher that operates using the passed API.
|
|
113
141
|
*
|
|
@@ -117,30 +145,6 @@ export default class UpcastDispatcher extends /* #__PURE__ */ EmitterMixin() {
|
|
|
117
145
|
*/
|
|
118
146
|
constructor(conversionApi) {
|
|
119
147
|
super();
|
|
120
|
-
/**
|
|
121
|
-
* The list of elements that were created during splitting.
|
|
122
|
-
*
|
|
123
|
-
* After the conversion process, the list is cleared.
|
|
124
|
-
*/
|
|
125
|
-
this._splitParts = new Map();
|
|
126
|
-
/**
|
|
127
|
-
* The list of cursor parent elements that were created during splitting.
|
|
128
|
-
*
|
|
129
|
-
* After the conversion process the list is cleared.
|
|
130
|
-
*/
|
|
131
|
-
this._cursorParents = new Map();
|
|
132
|
-
/**
|
|
133
|
-
* The position in the temporary structure where the converted content is inserted. The structure reflects the context of
|
|
134
|
-
* the target position where the content will be inserted. This property is built based on the context parameter of the
|
|
135
|
-
* convert method.
|
|
136
|
-
*/
|
|
137
|
-
this._modelCursor = null;
|
|
138
|
-
/**
|
|
139
|
-
* The list of elements that were created during the splitting but should not get removed on conversion end even if they are empty.
|
|
140
|
-
*
|
|
141
|
-
* The list is cleared after the conversion process.
|
|
142
|
-
*/
|
|
143
|
-
this._emptyElementsToKeep = new Set();
|
|
144
148
|
this.conversionApi = {
|
|
145
149
|
...conversionApi,
|
|
146
150
|
consumable: null,
|
|
@@ -314,7 +314,7 @@ export default class UpcastHelpers extends ConversionHelpers<UpcastDispatcher> {
|
|
|
314
314
|
};
|
|
315
315
|
model: string | {
|
|
316
316
|
key: string;
|
|
317
|
-
value: unknown | ((viewElement: ViewElement, conversionApi: UpcastConversionApi) => unknown);
|
|
317
|
+
value: unknown | ((viewElement: ViewElement, conversionApi: UpcastConversionApi, data: UpcastConversionData<ViewElement>) => unknown);
|
|
318
318
|
name?: string;
|
|
319
319
|
};
|
|
320
320
|
converterPriority?: PriorityString;
|
|
@@ -6,7 +6,7 @@ import Matcher from '../view/matcher.js';
|
|
|
6
6
|
import ConversionHelpers from './conversionhelpers.js';
|
|
7
7
|
import { isParagraphable, wrapInParagraph } from '../model/utils/autoparagraphing.js';
|
|
8
8
|
import { priorities } from '@ckeditor/ckeditor5-utils';
|
|
9
|
-
import { cloneDeep } from '
|
|
9
|
+
import { cloneDeep } from 'es-toolkit/compat';
|
|
10
10
|
/**
|
|
11
11
|
* Contains the {@link module:engine/view/view view} to {@link module:engine/model/model model} converters for
|
|
12
12
|
* {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher}.
|
|
@@ -842,7 +842,7 @@ function prepareToAttributeConverter(config, shallow) {
|
|
|
842
842
|
}
|
|
843
843
|
const modelKey = config.model.key;
|
|
844
844
|
const modelValue = typeof config.model.value == 'function' ?
|
|
845
|
-
config.model.value(data.viewItem, conversionApi) : config.model.value;
|
|
845
|
+
config.model.value(data.viewItem, conversionApi, data) : config.model.value;
|
|
846
846
|
// Do not convert if attribute building function returned falsy value.
|
|
847
847
|
if (modelValue === null) {
|
|
848
848
|
return;
|
|
@@ -32,15 +32,13 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
export default class ViewConsumable {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this._consumables = new Map();
|
|
43
|
-
}
|
|
35
|
+
/**
|
|
36
|
+
* Map of consumable elements. If {@link module:engine/view/element~Element element} is used as a key,
|
|
37
|
+
* {@link module:engine/conversion/viewconsumable~ViewElementConsumables ViewElementConsumables} instance is stored as value.
|
|
38
|
+
* For {@link module:engine/view/text~Text text nodes} and
|
|
39
|
+
* {@link module:engine/view/documentfragment~DocumentFragment document fragments} boolean value is stored as value.
|
|
40
|
+
*/
|
|
41
|
+
_consumables = new Map();
|
|
44
42
|
/**
|
|
45
43
|
* Adds view {@link module:engine/view/element~Element element}, {@link module:engine/view/text~Text text node} or
|
|
46
44
|
* {@link module:engine/view/documentfragment~DocumentFragment document fragment} as ready to be consumed.
|
|
@@ -252,23 +250,24 @@ export default class ViewConsumable {
|
|
|
252
250
|
* It represents and manipulates consumable parts of a single {@link module:engine/view/element~Element}.
|
|
253
251
|
*/
|
|
254
252
|
export class ViewElementConsumables {
|
|
253
|
+
element;
|
|
254
|
+
/**
|
|
255
|
+
* Flag indicating if name of the element can be consumed.
|
|
256
|
+
*/
|
|
257
|
+
_canConsumeName = null;
|
|
258
|
+
/**
|
|
259
|
+
* A map of element's consumables.
|
|
260
|
+
* * For plain attributes the value is a boolean indicating whether the attribute is available to consume.
|
|
261
|
+
* * For token based attributes (like class list and style) the value is a map of tokens to booleans
|
|
262
|
+
* indicating whether the token is available to consume on the given attribute.
|
|
263
|
+
*/
|
|
264
|
+
_attributes = new Map();
|
|
255
265
|
/**
|
|
256
266
|
* Creates ViewElementConsumables instance.
|
|
257
267
|
*
|
|
258
268
|
* @param from View element from which `ViewElementConsumables` is being created.
|
|
259
269
|
*/
|
|
260
270
|
constructor(from) {
|
|
261
|
-
/**
|
|
262
|
-
* Flag indicating if name of the element can be consumed.
|
|
263
|
-
*/
|
|
264
|
-
this._canConsumeName = null;
|
|
265
|
-
/**
|
|
266
|
-
* A map of element's consumables.
|
|
267
|
-
* * For plain attributes the value is a boolean indicating whether the attribute is available to consume.
|
|
268
|
-
* * For token based attributes (like class list and style) the value is a map of tokens to booleans
|
|
269
|
-
* indicating whether the token is available to consume on the given attribute.
|
|
270
|
-
*/
|
|
271
|
-
this._attributes = new Map();
|
|
272
271
|
this.element = from;
|
|
273
272
|
}
|
|
274
273
|
/**
|
|
@@ -13,13 +13,25 @@ import DomConverter from '../view/domconverter.js';
|
|
|
13
13
|
* This data processor implementation uses HTML as input and output data.
|
|
14
14
|
*/
|
|
15
15
|
export default class HtmlDataProcessor {
|
|
16
|
+
/**
|
|
17
|
+
* A DOM parser instance used to parse an HTML string to an HTML document.
|
|
18
|
+
*/
|
|
19
|
+
domParser;
|
|
20
|
+
/**
|
|
21
|
+
* A DOM converter used to convert DOM elements to view elements.
|
|
22
|
+
*/
|
|
23
|
+
domConverter;
|
|
24
|
+
/**
|
|
25
|
+
* A basic HTML writer instance used to convert DOM elements to an HTML string.
|
|
26
|
+
*/
|
|
27
|
+
htmlWriter;
|
|
28
|
+
skipComments = true;
|
|
16
29
|
/**
|
|
17
30
|
* Creates a new instance of the HTML data processor class.
|
|
18
31
|
*
|
|
19
32
|
* @param document The view document instance.
|
|
20
33
|
*/
|
|
21
34
|
constructor(document) {
|
|
22
|
-
this.skipComments = true;
|
|
23
35
|
this.domParser = new DOMParser();
|
|
24
36
|
this.domConverter = new DomConverter(document, { renderingMode: 'data' });
|
|
25
37
|
this.htmlWriter = new BasicHtmlWriter();
|
|
@@ -15,6 +15,27 @@ import DomConverter from '../view/domconverter.js';
|
|
|
15
15
|
* For example, `<link>Text</link>` is a valid XML but invalid HTML.
|
|
16
16
|
*/
|
|
17
17
|
export default class XmlDataProcessor {
|
|
18
|
+
/**
|
|
19
|
+
* A list of namespaces allowed to use in the XML input.
|
|
20
|
+
*
|
|
21
|
+
* For example, registering namespaces [ 'attribute', 'container' ] allows to use `<attirbute:tagName></attribute:tagName>`
|
|
22
|
+
* and `<container:tagName></container:tagName>` input. It is mainly for debugging.
|
|
23
|
+
*/
|
|
24
|
+
namespaces;
|
|
25
|
+
/**
|
|
26
|
+
* DOM parser instance used to parse an XML string to an XML document.
|
|
27
|
+
*/
|
|
28
|
+
domParser;
|
|
29
|
+
/**
|
|
30
|
+
* DOM converter used to convert DOM elements to view elements.
|
|
31
|
+
*/
|
|
32
|
+
domConverter;
|
|
33
|
+
/**
|
|
34
|
+
* A basic HTML writer instance used to convert DOM elements to an XML string.
|
|
35
|
+
* There is no need to use a dedicated XML writer because the basic HTML writer works well in this case.
|
|
36
|
+
*/
|
|
37
|
+
htmlWriter;
|
|
38
|
+
skipComments = true;
|
|
18
39
|
/**
|
|
19
40
|
* Creates a new instance of the XML data processor class.
|
|
20
41
|
*
|
|
@@ -23,7 +44,6 @@ export default class XmlDataProcessor {
|
|
|
23
44
|
* @param options.namespaces A list of namespaces allowed to use in the XML input.
|
|
24
45
|
*/
|
|
25
46
|
constructor(document, options = {}) {
|
|
26
|
-
this.skipComments = true;
|
|
27
47
|
this.namespaces = options.namespaces || [];
|
|
28
48
|
this.domParser = new DOMParser();
|
|
29
49
|
this.domConverter = new DomConverter(document, { renderingMode: 'data' });
|
package/src/dev-utils/model.js
CHANGED
|
@@ -25,7 +25,7 @@ import { StylesProcessor } from '../view/stylesmap.js';
|
|
|
25
25
|
import DowncastDispatcher from '../conversion/downcastdispatcher.js';
|
|
26
26
|
import UpcastDispatcher from '../conversion/upcastdispatcher.js';
|
|
27
27
|
import { toMap } from '@ckeditor/ckeditor5-utils';
|
|
28
|
-
import { isPlainObject } from '
|
|
28
|
+
import { isPlainObject } from 'es-toolkit/compat';
|
|
29
29
|
/**
|
|
30
30
|
* Writes the content of a model {@link module:engine/model/document~Document document} to an HTML-like string.
|
|
31
31
|
*
|
|
@@ -11,6 +11,9 @@ import OperationFactory from '../model/operation/operationfactory.js';
|
|
|
11
11
|
* Operation replayer is a development tool created for easy replaying of operations on the document from stringified operations.
|
|
12
12
|
*/
|
|
13
13
|
export default class OperationReplayer {
|
|
14
|
+
_model;
|
|
15
|
+
_logSeparator;
|
|
16
|
+
_operationsToReplay;
|
|
14
17
|
/**
|
|
15
18
|
* @param model Data model.
|
|
16
19
|
* @param logSeparator Separator between operations.
|