@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/src/model/treewalker.js
CHANGED
|
@@ -9,6 +9,55 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
|
9
9
|
* Position iterator class. It allows to iterate forward and backward over the document.
|
|
10
10
|
*/
|
|
11
11
|
export default class TreeWalker {
|
|
12
|
+
/**
|
|
13
|
+
* Walking direction. Defaults `'forward'`.
|
|
14
|
+
*/
|
|
15
|
+
direction;
|
|
16
|
+
/**
|
|
17
|
+
* Iterator boundaries.
|
|
18
|
+
*
|
|
19
|
+
* When the iterator is walking `'forward'` on the end of boundary or is walking `'backward'`
|
|
20
|
+
* on the start of boundary, then `{ done: true }` is returned.
|
|
21
|
+
*
|
|
22
|
+
* If boundaries are not defined they are set before first and after last child of the root node.
|
|
23
|
+
*/
|
|
24
|
+
boundaries;
|
|
25
|
+
/**
|
|
26
|
+
* Flag indicating whether all consecutive characters with the same attributes should be
|
|
27
|
+
* returned as one {@link module:engine/model/textproxy~TextProxy} (`true`) or one by one (`false`).
|
|
28
|
+
*/
|
|
29
|
+
singleCharacters;
|
|
30
|
+
/**
|
|
31
|
+
* Flag indicating whether iterator should enter elements or not. If the iterator is shallow child nodes of any
|
|
32
|
+
* iterated node will not be returned along with `elementEnd` tag.
|
|
33
|
+
*/
|
|
34
|
+
shallow;
|
|
35
|
+
/**
|
|
36
|
+
* Flag indicating whether iterator should ignore `elementEnd` tags. If the option is true walker will not
|
|
37
|
+
* return a parent node of the start position. If this option is `true` each {@link module:engine/model/element~Element} will
|
|
38
|
+
* be returned once, while if the option is `false` they might be returned twice:
|
|
39
|
+
* for `'elementStart'` and `'elementEnd'`.
|
|
40
|
+
*/
|
|
41
|
+
ignoreElementEnd;
|
|
42
|
+
/**
|
|
43
|
+
* Iterator position. This is always static position, even if the initial position was a
|
|
44
|
+
* {@link module:engine/model/liveposition~LivePosition live position}. If start position is not defined then position depends
|
|
45
|
+
* on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
|
|
46
|
+
* is `'backward'` position starts from the end.
|
|
47
|
+
*/
|
|
48
|
+
_position;
|
|
49
|
+
/**
|
|
50
|
+
* Start boundary cached for optimization purposes.
|
|
51
|
+
*/
|
|
52
|
+
_boundaryStartParent;
|
|
53
|
+
/**
|
|
54
|
+
* End boundary cached for optimization purposes.
|
|
55
|
+
*/
|
|
56
|
+
_boundaryEndParent;
|
|
57
|
+
/**
|
|
58
|
+
* Parent of the most recently visited node. Cached for optimization purposes.
|
|
59
|
+
*/
|
|
60
|
+
_visitedParent;
|
|
12
61
|
/**
|
|
13
62
|
* Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
|
|
14
63
|
*
|
|
@@ -186,32 +186,67 @@ export default function insertContent(model, content, selectable) {
|
|
|
186
186
|
* Utility class for performing content insertion.
|
|
187
187
|
*/
|
|
188
188
|
class Insertion {
|
|
189
|
+
/**
|
|
190
|
+
* The model in context of which the insertion should be performed.
|
|
191
|
+
*/
|
|
192
|
+
model;
|
|
193
|
+
/**
|
|
194
|
+
* Batch to which operations will be added.
|
|
195
|
+
*/
|
|
196
|
+
writer;
|
|
197
|
+
/**
|
|
198
|
+
* The position at which (or near which) the next node will be inserted.
|
|
199
|
+
*/
|
|
200
|
+
position;
|
|
201
|
+
/**
|
|
202
|
+
* Elements with which the inserted elements can be merged.
|
|
203
|
+
*
|
|
204
|
+
* ```html
|
|
205
|
+
* <p>x^</p><p>y</p> + <p>z</p> (can merge to <p>x</p>)
|
|
206
|
+
* <p>x</p><p>^y</p> + <p>z</p> (can merge to <p>y</p>)
|
|
207
|
+
* <p>x^y</p> + <p>z</p> (can merge to <p>xy</p> which will be split during the action,
|
|
208
|
+
* so both its pieces will be added to this set)
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
canMergeWith;
|
|
212
|
+
/**
|
|
213
|
+
* Schema of the model.
|
|
214
|
+
*/
|
|
215
|
+
schema;
|
|
216
|
+
/**
|
|
217
|
+
* The temporary DocumentFragment used for grouping multiple nodes for single insert operation.
|
|
218
|
+
*/
|
|
219
|
+
_documentFragment;
|
|
220
|
+
/**
|
|
221
|
+
* The current position in the temporary DocumentFragment.
|
|
222
|
+
*/
|
|
223
|
+
_documentFragmentPosition;
|
|
224
|
+
/**
|
|
225
|
+
* The reference to the first inserted node.
|
|
226
|
+
*/
|
|
227
|
+
_firstNode = null;
|
|
228
|
+
/**
|
|
229
|
+
* The reference to the last inserted node.
|
|
230
|
+
*/
|
|
231
|
+
_lastNode = null;
|
|
232
|
+
/**
|
|
233
|
+
* The reference to the last auto paragraph node.
|
|
234
|
+
*/
|
|
235
|
+
_lastAutoParagraph = null;
|
|
236
|
+
/**
|
|
237
|
+
* The array of nodes that should be cleaned of not allowed attributes.
|
|
238
|
+
*/
|
|
239
|
+
_filterAttributesOf = [];
|
|
240
|
+
/**
|
|
241
|
+
* Beginning of the affected range. See {@link module:engine/model/utils/insertcontent~Insertion#getAffectedRange}.
|
|
242
|
+
*/
|
|
243
|
+
_affectedStart = null;
|
|
244
|
+
/**
|
|
245
|
+
* End of the affected range. See {@link module:engine/model/utils/insertcontent~Insertion#getAffectedRange}.
|
|
246
|
+
*/
|
|
247
|
+
_affectedEnd = null;
|
|
248
|
+
_nodeToSelect = null;
|
|
189
249
|
constructor(model, writer, position) {
|
|
190
|
-
/**
|
|
191
|
-
* The reference to the first inserted node.
|
|
192
|
-
*/
|
|
193
|
-
this._firstNode = null;
|
|
194
|
-
/**
|
|
195
|
-
* The reference to the last inserted node.
|
|
196
|
-
*/
|
|
197
|
-
this._lastNode = null;
|
|
198
|
-
/**
|
|
199
|
-
* The reference to the last auto paragraph node.
|
|
200
|
-
*/
|
|
201
|
-
this._lastAutoParagraph = null;
|
|
202
|
-
/**
|
|
203
|
-
* The array of nodes that should be cleaned of not allowed attributes.
|
|
204
|
-
*/
|
|
205
|
-
this._filterAttributesOf = [];
|
|
206
|
-
/**
|
|
207
|
-
* Beginning of the affected range. See {@link module:engine/model/utils/insertcontent~Insertion#getAffectedRange}.
|
|
208
|
-
*/
|
|
209
|
-
this._affectedStart = null;
|
|
210
|
-
/**
|
|
211
|
-
* End of the affected range. See {@link module:engine/model/utils/insertcontent~Insertion#getAffectedRange}.
|
|
212
|
-
*/
|
|
213
|
-
this._affectedEnd = null;
|
|
214
|
-
this._nodeToSelect = null;
|
|
215
250
|
this.model = model;
|
|
216
251
|
this.writer = writer;
|
|
217
252
|
this.position = position;
|
package/src/model/writer.js
CHANGED
|
@@ -47,6 +47,14 @@ import { CKEditorError, logWarning, toMap } from '@ckeditor/ckeditor5-utils';
|
|
|
47
47
|
* @see module:engine/model/model~Model#enqueueChange
|
|
48
48
|
*/
|
|
49
49
|
export default class Writer {
|
|
50
|
+
/**
|
|
51
|
+
* Instance of the model on which this writer operates.
|
|
52
|
+
*/
|
|
53
|
+
model;
|
|
54
|
+
/**
|
|
55
|
+
* The batch to which this writer will add changes.
|
|
56
|
+
*/
|
|
57
|
+
batch;
|
|
50
58
|
/**
|
|
51
59
|
* Creates a writer instance.
|
|
52
60
|
*
|
|
@@ -21,6 +21,29 @@ const DEFAULT_PRIORITY = 10;
|
|
|
21
21
|
* {@link module:engine/view/downcastwriter~DowncastWriter#createAttributeElement `DowncastWriter#createAttributeElement()`} method.
|
|
22
22
|
*/
|
|
23
23
|
class AttributeElement extends Element {
|
|
24
|
+
static DEFAULT_PRIORITY = DEFAULT_PRIORITY;
|
|
25
|
+
/**
|
|
26
|
+
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
* @readonly
|
|
30
|
+
*/
|
|
31
|
+
_priority = DEFAULT_PRIORITY;
|
|
32
|
+
/**
|
|
33
|
+
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
34
|
+
* and then two elements are considered similar if, and only if they have the same `_id`.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
* @readonly
|
|
38
|
+
*/
|
|
39
|
+
_id = null;
|
|
40
|
+
/**
|
|
41
|
+
* Keeps all the attribute elements that have the same {@link module:engine/view/attributeelement~AttributeElement#id ids}
|
|
42
|
+
* and still exist in the view tree.
|
|
43
|
+
*
|
|
44
|
+
* This property is managed by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
45
|
+
*/
|
|
46
|
+
_clonesGroup = null;
|
|
24
47
|
/**
|
|
25
48
|
* Creates an attribute element.
|
|
26
49
|
*
|
|
@@ -34,28 +57,6 @@ class AttributeElement extends Element {
|
|
|
34
57
|
*/
|
|
35
58
|
constructor(document, name, attrs, children) {
|
|
36
59
|
super(document, name, attrs, children);
|
|
37
|
-
/**
|
|
38
|
-
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
39
|
-
*
|
|
40
|
-
* @internal
|
|
41
|
-
* @readonly
|
|
42
|
-
*/
|
|
43
|
-
this._priority = DEFAULT_PRIORITY;
|
|
44
|
-
/**
|
|
45
|
-
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
46
|
-
* and then two elements are considered similar if, and only if they have the same `_id`.
|
|
47
|
-
*
|
|
48
|
-
* @internal
|
|
49
|
-
* @readonly
|
|
50
|
-
*/
|
|
51
|
-
this._id = null;
|
|
52
|
-
/**
|
|
53
|
-
* Keeps all the attribute elements that have the same {@link module:engine/view/attributeelement~AttributeElement#id ids}
|
|
54
|
-
* and still exist in the view tree.
|
|
55
|
-
*
|
|
56
|
-
* This property is managed by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
57
|
-
*/
|
|
58
|
-
this._clonesGroup = null;
|
|
59
60
|
this.getFillerOffset = getFillerOffset;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
@@ -162,7 +163,6 @@ class AttributeElement extends Element {
|
|
|
162
163
|
return super._canSubtractAttributesOf(otherElement);
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
|
-
AttributeElement.DEFAULT_PRIORITY = DEFAULT_PRIORITY;
|
|
166
166
|
export default AttributeElement;
|
|
167
167
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
168
168
|
// Proper overload would interfere with that.
|
package/src/view/datatransfer.js
CHANGED
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
* A facade over the native [`DataTransfer`](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) object.
|
|
7
7
|
*/
|
|
8
8
|
export default class DataTransfer {
|
|
9
|
+
/**
|
|
10
|
+
* The array of files created from the native `DataTransfer#files` or `DataTransfer#items`.
|
|
11
|
+
*/
|
|
12
|
+
_files;
|
|
13
|
+
/**
|
|
14
|
+
* The native DataTransfer object.
|
|
15
|
+
*/
|
|
16
|
+
_native;
|
|
9
17
|
/**
|
|
10
18
|
* @param nativeDataTransfer The native [`DataTransfer`](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) object.
|
|
11
19
|
* @param options.cacheFiles Whether `files` list should be initialized in the constructor.
|
package/src/view/document.js
CHANGED
|
@@ -14,6 +14,27 @@ import { Collection, ObservableMixin } from '@ckeditor/ckeditor5-utils';
|
|
|
14
14
|
* {@link module:engine/view/documentselection~DocumentSelection view selection} associated with this document.
|
|
15
15
|
*/
|
|
16
16
|
export default class Document extends /* #__PURE__ */ BubblingEmitterMixin(/* #__PURE__ */ ObservableMixin()) {
|
|
17
|
+
/**
|
|
18
|
+
* Selection done on this document.
|
|
19
|
+
*/
|
|
20
|
+
selection;
|
|
21
|
+
/**
|
|
22
|
+
* Roots of the view tree. Collection of the {@link module:engine/view/element~Element view elements}.
|
|
23
|
+
*
|
|
24
|
+
* View roots are created as a result of binding between {@link module:engine/view/document~Document#roots} and
|
|
25
|
+
* {@link module:engine/model/document~Document#roots} and this is handled by
|
|
26
|
+
* {@link module:engine/controller/editingcontroller~EditingController}, so to create view root we need to create
|
|
27
|
+
* model root using {@link module:engine/model/document~Document#createRoot}.
|
|
28
|
+
*/
|
|
29
|
+
roots;
|
|
30
|
+
/**
|
|
31
|
+
* The styles processor instance used by this document when normalizing styles.
|
|
32
|
+
*/
|
|
33
|
+
stylesProcessor;
|
|
34
|
+
/**
|
|
35
|
+
* Post-fixer callbacks registered to the view document.
|
|
36
|
+
*/
|
|
37
|
+
_postFixers = new Set();
|
|
17
38
|
/**
|
|
18
39
|
* Creates a Document instance.
|
|
19
40
|
*
|
|
@@ -21,10 +42,6 @@ export default class Document extends /* #__PURE__ */ BubblingEmitterMixin(/* #_
|
|
|
21
42
|
*/
|
|
22
43
|
constructor(stylesProcessor) {
|
|
23
44
|
super();
|
|
24
|
-
/**
|
|
25
|
-
* Post-fixer callbacks registered to the view document.
|
|
26
|
-
*/
|
|
27
|
-
this._postFixers = new Set();
|
|
28
45
|
this.selection = new DocumentSelection();
|
|
29
46
|
this.roots = new Collection({ idProperty: 'rootName' });
|
|
30
47
|
this.stylesProcessor = stylesProcessor;
|
|
@@ -17,6 +17,19 @@ import { EmitterMixin, isIterable } from '@ckeditor/ckeditor5-utils';
|
|
|
17
17
|
* method.
|
|
18
18
|
*/
|
|
19
19
|
export default class DocumentFragment extends /* #__PURE__ */ EmitterMixin(TypeCheckable) {
|
|
20
|
+
/**
|
|
21
|
+
* The document to which this document fragment belongs.
|
|
22
|
+
*/
|
|
23
|
+
document;
|
|
24
|
+
/**
|
|
25
|
+
* Array of child nodes.
|
|
26
|
+
*/
|
|
27
|
+
_children = [];
|
|
28
|
+
/**
|
|
29
|
+
* Map of custom properties.
|
|
30
|
+
* Custom properties can be added to document fragment instance.
|
|
31
|
+
*/
|
|
32
|
+
_customProperties = new Map();
|
|
20
33
|
/**
|
|
21
34
|
* Creates new DocumentFragment instance.
|
|
22
35
|
*
|
|
@@ -26,15 +39,6 @@ export default class DocumentFragment extends /* #__PURE__ */ EmitterMixin(TypeC
|
|
|
26
39
|
*/
|
|
27
40
|
constructor(document, children) {
|
|
28
41
|
super();
|
|
29
|
-
/**
|
|
30
|
-
* Array of child nodes.
|
|
31
|
-
*/
|
|
32
|
-
this._children = [];
|
|
33
|
-
/**
|
|
34
|
-
* Map of custom properties.
|
|
35
|
-
* Custom properties can be added to document fragment instance.
|
|
36
|
-
*/
|
|
37
|
-
this._customProperties = new Map();
|
|
38
42
|
this.document = document;
|
|
39
43
|
if (children) {
|
|
40
44
|
this._insertChild(0, children);
|
|
@@ -19,6 +19,10 @@ import { EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
|
19
19
|
* (so via {@link module:engine/view/downcastwriter~DowncastWriter#setSelection `DowncastWriter#setSelection()`}).
|
|
20
20
|
*/
|
|
21
21
|
export default class DocumentSelection extends /* #__PURE__ */ EmitterMixin(TypeCheckable) {
|
|
22
|
+
/**
|
|
23
|
+
* Selection is used internally (`DocumentSelection` is a proxy to that selection).
|
|
24
|
+
*/
|
|
25
|
+
_selection;
|
|
22
26
|
constructor(...args) {
|
|
23
27
|
super();
|
|
24
28
|
this._selection = new Selection();
|
|
@@ -20,6 +20,7 @@ import type EditableElement from './editableelement.js';
|
|
|
20
20
|
import type ViewRawElement from './rawelement.js';
|
|
21
21
|
type DomNode = globalThis.Node;
|
|
22
22
|
type DomElement = globalThis.HTMLElement;
|
|
23
|
+
type DomDocument = globalThis.Document;
|
|
23
24
|
type DomDocumentFragment = globalThis.DocumentFragment;
|
|
24
25
|
type DomRange = globalThis.Range;
|
|
25
26
|
type DomText = globalThis.Text;
|
|
@@ -77,7 +78,7 @@ export default class DomConverter {
|
|
|
77
78
|
*/
|
|
78
79
|
readonly unsafeElements: Array<string>;
|
|
79
80
|
/**
|
|
80
|
-
* The DOM Document used to create DOM nodes.
|
|
81
|
+
* The DOM Document used by `DomConverter` to create DOM nodes.
|
|
81
82
|
*/
|
|
82
83
|
private readonly _domDocument;
|
|
83
84
|
/**
|
|
@@ -121,6 +122,10 @@ export default class DomConverter {
|
|
|
121
122
|
blockFillerMode?: BlockFillerMode;
|
|
122
123
|
renderingMode?: 'data' | 'editing';
|
|
123
124
|
});
|
|
125
|
+
/**
|
|
126
|
+
* The DOM Document used by `DomConverter` to create DOM nodes.
|
|
127
|
+
*/
|
|
128
|
+
get domDocument(): DomDocument;
|
|
124
129
|
/**
|
|
125
130
|
* Binds a given DOM element that represents fake selection to a **position** of a
|
|
126
131
|
* {@link module:engine/view/documentselection~DocumentSelection document selection}.
|
package/src/view/domconverter.js
CHANGED
|
@@ -36,6 +36,73 @@ const UNSAFE_ELEMENT_REPLACEMENT_ATTRIBUTE = 'data-ck-unsafe-element';
|
|
|
36
36
|
* Two converters will keep separate binding maps, so one tree view can be bound with two DOM trees.
|
|
37
37
|
*/
|
|
38
38
|
export default class DomConverter {
|
|
39
|
+
document;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to leave the View-to-DOM conversion result unchanged or improve editing experience by filtering out interactive data.
|
|
42
|
+
*/
|
|
43
|
+
renderingMode;
|
|
44
|
+
/**
|
|
45
|
+
* The mode of a block filler used by the DOM converter.
|
|
46
|
+
*/
|
|
47
|
+
blockFillerMode;
|
|
48
|
+
/**
|
|
49
|
+
* Elements which are considered pre-formatted elements.
|
|
50
|
+
*/
|
|
51
|
+
preElements;
|
|
52
|
+
/**
|
|
53
|
+
* Elements which are considered block elements (and hence should be filled with a
|
|
54
|
+
* {@link #isBlockFiller block filler}).
|
|
55
|
+
*
|
|
56
|
+
* Whether an element is considered a block element also affects handling of trailing whitespaces.
|
|
57
|
+
*
|
|
58
|
+
* You can extend this array if you introduce support for block elements which are not yet recognized here.
|
|
59
|
+
*/
|
|
60
|
+
blockElements;
|
|
61
|
+
/**
|
|
62
|
+
* A list of elements that exist inline (in text) but their inner structure cannot be edited because
|
|
63
|
+
* of the way they are rendered by the browser. They are mostly HTML form elements but there are other
|
|
64
|
+
* elements such as `<img>` or `<iframe>` that also have non-editable children or no children whatsoever.
|
|
65
|
+
*
|
|
66
|
+
* Whether an element is considered an inline object has an impact on white space rendering (trimming)
|
|
67
|
+
* around (and inside of it). In short, white spaces in text nodes next to inline objects are not trimmed.
|
|
68
|
+
*
|
|
69
|
+
* You can extend this array if you introduce support for inline object elements which are not yet recognized here.
|
|
70
|
+
*/
|
|
71
|
+
inlineObjectElements;
|
|
72
|
+
/**
|
|
73
|
+
* A list of elements which may affect the editing experience. To avoid this, those elements are replaced with
|
|
74
|
+
* `<span data-ck-unsafe-element="[element name]"></span>` while rendering in the editing mode.
|
|
75
|
+
*/
|
|
76
|
+
unsafeElements;
|
|
77
|
+
/**
|
|
78
|
+
* The DOM Document used by `DomConverter` to create DOM nodes.
|
|
79
|
+
*/
|
|
80
|
+
_domDocument;
|
|
81
|
+
/**
|
|
82
|
+
* The DOM-to-view mapping.
|
|
83
|
+
*/
|
|
84
|
+
_domToViewMapping = new WeakMap();
|
|
85
|
+
/**
|
|
86
|
+
* The view-to-DOM mapping.
|
|
87
|
+
*/
|
|
88
|
+
_viewToDomMapping = new WeakMap();
|
|
89
|
+
/**
|
|
90
|
+
* Holds the mapping between fake selection containers and corresponding view selections.
|
|
91
|
+
*/
|
|
92
|
+
_fakeSelectionMapping = new WeakMap();
|
|
93
|
+
/**
|
|
94
|
+
* Matcher for view elements whose content should be treated as raw data
|
|
95
|
+
* and not processed during the conversion from DOM nodes to view elements.
|
|
96
|
+
*/
|
|
97
|
+
_rawContentElementMatcher = new Matcher();
|
|
98
|
+
/**
|
|
99
|
+
* Matcher for inline object view elements. This is an extension of a simple {@link #inlineObjectElements} array of element names.
|
|
100
|
+
*/
|
|
101
|
+
_inlineObjectElementMatcher = new Matcher();
|
|
102
|
+
/**
|
|
103
|
+
* Set of elements with temporary custom properties that require clearing after render.
|
|
104
|
+
*/
|
|
105
|
+
_elementsWithTemporaryCustomProperties = new Set();
|
|
39
106
|
/**
|
|
40
107
|
* Creates a DOM converter.
|
|
41
108
|
*
|
|
@@ -49,31 +116,6 @@ export default class DomConverter {
|
|
|
49
116
|
* or improve editing experience by filtering out interactive data.
|
|
50
117
|
*/
|
|
51
118
|
constructor(document, { blockFillerMode, renderingMode = 'editing' } = {}) {
|
|
52
|
-
/**
|
|
53
|
-
* The DOM-to-view mapping.
|
|
54
|
-
*/
|
|
55
|
-
this._domToViewMapping = new WeakMap();
|
|
56
|
-
/**
|
|
57
|
-
* The view-to-DOM mapping.
|
|
58
|
-
*/
|
|
59
|
-
this._viewToDomMapping = new WeakMap();
|
|
60
|
-
/**
|
|
61
|
-
* Holds the mapping between fake selection containers and corresponding view selections.
|
|
62
|
-
*/
|
|
63
|
-
this._fakeSelectionMapping = new WeakMap();
|
|
64
|
-
/**
|
|
65
|
-
* Matcher for view elements whose content should be treated as raw data
|
|
66
|
-
* and not processed during the conversion from DOM nodes to view elements.
|
|
67
|
-
*/
|
|
68
|
-
this._rawContentElementMatcher = new Matcher();
|
|
69
|
-
/**
|
|
70
|
-
* Matcher for inline object view elements. This is an extension of a simple {@link #inlineObjectElements} array of element names.
|
|
71
|
-
*/
|
|
72
|
-
this._inlineObjectElementMatcher = new Matcher();
|
|
73
|
-
/**
|
|
74
|
-
* Set of elements with temporary custom properties that require clearing after render.
|
|
75
|
-
*/
|
|
76
|
-
this._elementsWithTemporaryCustomProperties = new Set();
|
|
77
119
|
this.document = document;
|
|
78
120
|
this.renderingMode = renderingMode;
|
|
79
121
|
this.blockFillerMode = blockFillerMode || (renderingMode === 'editing' ? 'br' : 'nbsp');
|
|
@@ -90,6 +132,12 @@ export default class DomConverter {
|
|
|
90
132
|
this.unsafeElements = ['script', 'style'];
|
|
91
133
|
this._domDocument = this.renderingMode === 'editing' ? global.document : global.document.implementation.createHTMLDocument('');
|
|
92
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* The DOM Document used by `DomConverter` to create DOM nodes.
|
|
137
|
+
*/
|
|
138
|
+
get domDocument() {
|
|
139
|
+
return this._domDocument;
|
|
140
|
+
}
|
|
93
141
|
/**
|
|
94
142
|
* Binds a given DOM element that represents fake selection to a **position** of a
|
|
95
143
|
* {@link module:engine/view/documentselection~DocumentSelection document selection}.
|
|
@@ -790,30 +838,43 @@ export default class DomConverter {
|
|
|
790
838
|
*/
|
|
791
839
|
focus(viewEditable) {
|
|
792
840
|
const domEditable = this.mapViewToDom(viewEditable);
|
|
793
|
-
if (domEditable
|
|
794
|
-
//
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
//
|
|
798
|
-
//
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
scrollPositions.push([scrollLeft, scrollTop]);
|
|
802
|
-
});
|
|
803
|
-
domEditable.focus();
|
|
804
|
-
// Restore scrollLeft and scrollTop values starting from domEditable up to
|
|
805
|
-
// document#documentElement.
|
|
806
|
-
// https://github.com/ckeditor/ckeditor5-engine/issues/951
|
|
807
|
-
// https://github.com/ckeditor/ckeditor5-engine/issues/957
|
|
808
|
-
forEachDomElementAncestor(domEditable, node => {
|
|
809
|
-
const [scrollLeft, scrollTop] = scrollPositions.shift();
|
|
810
|
-
node.scrollLeft = scrollLeft;
|
|
811
|
-
node.scrollTop = scrollTop;
|
|
812
|
-
});
|
|
813
|
-
// Restore the scrollX and scrollY positions after the focus.
|
|
814
|
-
// https://github.com/ckeditor/ckeditor5-engine/issues/951
|
|
815
|
-
global.window.scrollTo(scrollX, scrollY);
|
|
841
|
+
if (!domEditable || domEditable.ownerDocument.activeElement === domEditable) {
|
|
842
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
843
|
+
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'DomConverter',
|
|
844
|
+
// @if CK_DEBUG_TYPING // '%cDOM editable is already active or does not exist',
|
|
845
|
+
// @if CK_DEBUG_TYPING // 'font-style: italic'
|
|
846
|
+
// @if CK_DEBUG_TYPING // ) );
|
|
847
|
+
// @if CK_DEBUG_TYPING // }
|
|
848
|
+
return;
|
|
816
849
|
}
|
|
850
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
851
|
+
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'DomConverter',
|
|
852
|
+
// @if CK_DEBUG_TYPING // 'Focus DOM editable:',
|
|
853
|
+
// @if CK_DEBUG_TYPING // { domEditable }
|
|
854
|
+
// @if CK_DEBUG_TYPING // ) );
|
|
855
|
+
// @if CK_DEBUG_TYPING // }
|
|
856
|
+
// Save the scrollX and scrollY positions before the focus.
|
|
857
|
+
const { scrollX, scrollY } = global.window;
|
|
858
|
+
const scrollPositions = [];
|
|
859
|
+
// Save all scrollLeft and scrollTop values starting from domEditable up to
|
|
860
|
+
// document#documentElement.
|
|
861
|
+
forEachDomElementAncestor(domEditable, node => {
|
|
862
|
+
const { scrollLeft, scrollTop } = node;
|
|
863
|
+
scrollPositions.push([scrollLeft, scrollTop]);
|
|
864
|
+
});
|
|
865
|
+
domEditable.focus();
|
|
866
|
+
// Restore scrollLeft and scrollTop values starting from domEditable up to
|
|
867
|
+
// document#documentElement.
|
|
868
|
+
// https://github.com/ckeditor/ckeditor5-engine/issues/951
|
|
869
|
+
// https://github.com/ckeditor/ckeditor5-engine/issues/957
|
|
870
|
+
forEachDomElementAncestor(domEditable, node => {
|
|
871
|
+
const [scrollLeft, scrollTop] = scrollPositions.shift();
|
|
872
|
+
node.scrollLeft = scrollLeft;
|
|
873
|
+
node.scrollTop = scrollTop;
|
|
874
|
+
});
|
|
875
|
+
// Restore the scrollX and scrollY positions after the focus.
|
|
876
|
+
// https://github.com/ckeditor/ckeditor5-engine/issues/951
|
|
877
|
+
global.window.scrollTo(scrollX, scrollY);
|
|
817
878
|
}
|
|
818
879
|
/**
|
|
819
880
|
* Remove DOM selection from blurred editable, so it won't interfere with clicking on dropdowns (especially on iOS).
|
|
@@ -17,7 +17,7 @@ import { CKEditorError, isIterable } from '@ckeditor/ckeditor5-utils';
|
|
|
17
17
|
import DocumentFragment from './documentfragment.js';
|
|
18
18
|
import Text from './text.js';
|
|
19
19
|
import EditableElement from './editableelement.js';
|
|
20
|
-
import { isPlainObject } from '
|
|
20
|
+
import { isPlainObject } from 'es-toolkit/compat';
|
|
21
21
|
/**
|
|
22
22
|
* View downcast writer.
|
|
23
23
|
*
|
|
@@ -34,19 +34,23 @@ import { isPlainObject } from 'lodash-es';
|
|
|
34
34
|
* section of the {@glink framework/architecture/editing-engine Editing engine architecture} guide.
|
|
35
35
|
*/
|
|
36
36
|
export default class DowncastWriter {
|
|
37
|
+
/**
|
|
38
|
+
* The view document instance in which this writer operates.
|
|
39
|
+
*/
|
|
40
|
+
document;
|
|
41
|
+
/**
|
|
42
|
+
* Holds references to the attribute groups that share the same {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
43
|
+
* The keys are `id`s, the values are `Set`s holding {@link module:engine/view/attributeelement~AttributeElement}s.
|
|
44
|
+
*/
|
|
45
|
+
_cloneGroups = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* The slot factory used by the `elementToStructure` downcast helper.
|
|
48
|
+
*/
|
|
49
|
+
_slotFactory = null;
|
|
37
50
|
/**
|
|
38
51
|
* @param document The view document instance.
|
|
39
52
|
*/
|
|
40
53
|
constructor(document) {
|
|
41
|
-
/**
|
|
42
|
-
* Holds references to the attribute groups that share the same {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
43
|
-
* The keys are `id`s, the values are `Set`s holding {@link module:engine/view/attributeelement~AttributeElement}s.
|
|
44
|
-
*/
|
|
45
|
-
this._cloneGroups = new Map();
|
|
46
|
-
/**
|
|
47
|
-
* The slot factory used by the `elementToStructure` downcast helper.
|
|
48
|
-
*/
|
|
49
|
-
this._slotFactory = null;
|
|
50
54
|
this.document = document;
|
|
51
55
|
}
|
|
52
56
|
setSelection(...args) {
|
package/src/view/element.js
CHANGED
|
@@ -37,6 +37,35 @@ import TokenList from './tokenlist.js';
|
|
|
37
37
|
* should be used to create generic view elements.
|
|
38
38
|
*/
|
|
39
39
|
export default class Element extends Node {
|
|
40
|
+
/**
|
|
41
|
+
* Name of the element.
|
|
42
|
+
*/
|
|
43
|
+
name;
|
|
44
|
+
/**
|
|
45
|
+
* A list of attribute names that should be rendered in the editing pipeline even though filtering mechanisms
|
|
46
|
+
* implemented in the {@link module:engine/view/domconverter~DomConverter} (for instance,
|
|
47
|
+
* {@link module:engine/view/domconverter~DomConverter#shouldRenderAttribute}) would filter them out.
|
|
48
|
+
*
|
|
49
|
+
* These attributes can be specified as an option when the element is created by
|
|
50
|
+
* the {@link module:engine/view/downcastwriter~DowncastWriter}. To check whether an unsafe an attribute should
|
|
51
|
+
* be permitted, use the {@link #shouldRenderUnsafeAttribute} method.
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
_unsafeAttributesToRender = [];
|
|
56
|
+
/**
|
|
57
|
+
* Map of attributes, where attributes names are keys and attributes values are values.
|
|
58
|
+
*/
|
|
59
|
+
_attrs;
|
|
60
|
+
/**
|
|
61
|
+
* Array of child nodes.
|
|
62
|
+
*/
|
|
63
|
+
_children;
|
|
64
|
+
/**
|
|
65
|
+
* Map of custom properties.
|
|
66
|
+
* Custom properties can be added to element instance, will be cloned but not rendered into DOM.
|
|
67
|
+
*/
|
|
68
|
+
_customProperties = new Map();
|
|
40
69
|
/**
|
|
41
70
|
* Set of classes associated with element instance.
|
|
42
71
|
*
|
|
@@ -72,23 +101,6 @@ export default class Element extends Node {
|
|
|
72
101
|
*/
|
|
73
102
|
constructor(document, name, attrs, children) {
|
|
74
103
|
super(document);
|
|
75
|
-
/**
|
|
76
|
-
* A list of attribute names that should be rendered in the editing pipeline even though filtering mechanisms
|
|
77
|
-
* implemented in the {@link module:engine/view/domconverter~DomConverter} (for instance,
|
|
78
|
-
* {@link module:engine/view/domconverter~DomConverter#shouldRenderAttribute}) would filter them out.
|
|
79
|
-
*
|
|
80
|
-
* These attributes can be specified as an option when the element is created by
|
|
81
|
-
* the {@link module:engine/view/downcastwriter~DowncastWriter}. To check whether an unsafe an attribute should
|
|
82
|
-
* be permitted, use the {@link #shouldRenderUnsafeAttribute} method.
|
|
83
|
-
*
|
|
84
|
-
* @internal
|
|
85
|
-
*/
|
|
86
|
-
this._unsafeAttributesToRender = [];
|
|
87
|
-
/**
|
|
88
|
-
* Map of custom properties.
|
|
89
|
-
* Custom properties can be added to element instance, will be cloned but not rendered into DOM.
|
|
90
|
-
*/
|
|
91
|
-
this._customProperties = new Map();
|
|
92
104
|
this.name = name;
|
|
93
105
|
this._attrs = this._parseAttributes(attrs);
|
|
94
106
|
this._children = [];
|
package/src/view/matcher.js
CHANGED
|
@@ -9,13 +9,13 @@ import { normalizeConsumables } from '../conversion/viewconsumable.js';
|
|
|
9
9
|
* Instance of this class can be used to find {@link module:engine/view/element~Element elements} that match given pattern.
|
|
10
10
|
*/
|
|
11
11
|
export default class Matcher {
|
|
12
|
+
_patterns = [];
|
|
12
13
|
/**
|
|
13
14
|
* Creates new instance of Matcher.
|
|
14
15
|
*
|
|
15
16
|
* @param pattern Match patterns. See {@link module:engine/view/matcher~Matcher#add add method} for more information.
|
|
16
17
|
*/
|
|
17
18
|
constructor(...pattern) {
|
|
18
|
-
this._patterns = [];
|
|
19
19
|
this.add(...pattern);
|
|
20
20
|
}
|
|
21
21
|
/**
|