@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +25 -24
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +72 -116
- package/src/controller/editingcontroller.d.ts +98 -0
- package/src/controller/editingcontroller.js +22 -46
- package/src/conversion/conversion.d.ts +476 -0
- package/src/conversion/conversion.js +328 -347
- package/src/conversion/conversionhelpers.d.ts +26 -0
- package/src/conversion/conversionhelpers.js +1 -5
- package/src/conversion/downcastdispatcher.d.ts +547 -0
- package/src/conversion/downcastdispatcher.js +74 -152
- package/src/conversion/downcasthelpers.d.ts +1226 -0
- package/src/conversion/downcasthelpers.js +843 -762
- package/src/conversion/mapper.d.ts +503 -0
- package/src/conversion/mapper.js +84 -99
- package/src/conversion/modelconsumable.d.ts +201 -0
- package/src/conversion/modelconsumable.js +96 -99
- package/src/conversion/upcastdispatcher.d.ts +492 -0
- package/src/conversion/upcastdispatcher.js +73 -100
- package/src/conversion/upcasthelpers.d.ts +499 -0
- package/src/conversion/upcasthelpers.js +406 -373
- package/src/conversion/viewconsumable.d.ts +369 -0
- package/src/conversion/viewconsumable.js +139 -173
- package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/src/dataprocessor/basichtmlwriter.js +0 -9
- package/src/dataprocessor/dataprocessor.d.ts +61 -0
- package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/src/dataprocessor/htmldataprocessor.js +6 -28
- package/src/dataprocessor/htmlwriter.d.ts +16 -0
- package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/src/dataprocessor/xmldataprocessor.js +8 -40
- package/src/dev-utils/model.d.ts +124 -0
- package/src/dev-utils/model.js +41 -38
- package/src/dev-utils/operationreplayer.d.ts +51 -0
- package/src/dev-utils/operationreplayer.js +6 -14
- package/src/dev-utils/utils.d.ts +37 -0
- package/src/dev-utils/utils.js +5 -18
- package/src/dev-utils/view.d.ts +319 -0
- package/src/dev-utils/view.js +205 -226
- package/src/index.d.ts +108 -0
- package/src/index.js +4 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +246 -0
- package/src/model/document.js +1 -1
- package/src/model/documentfragment.d.ts +196 -0
- package/src/model/documentfragment.js +2 -2
- package/src/model/documentselection.d.ts +420 -0
- package/src/model/element.d.ts +165 -0
- package/src/model/history.d.ts +114 -0
- package/src/model/item.d.ts +14 -0
- package/src/model/liveposition.d.ts +77 -0
- package/src/model/liverange.d.ts +102 -0
- package/src/model/markercollection.d.ts +335 -0
- package/src/model/model.d.ts +885 -0
- package/src/model/model.js +59 -81
- package/src/model/node.d.ts +256 -0
- package/src/model/nodelist.d.ts +91 -0
- package/src/model/operation/attributeoperation.d.ts +98 -0
- package/src/model/operation/detachoperation.d.ts +55 -0
- package/src/model/operation/insertoperation.d.ts +85 -0
- package/src/model/operation/markeroperation.d.ts +86 -0
- package/src/model/operation/mergeoperation.d.ts +95 -0
- package/src/model/operation/mergeoperation.js +1 -1
- package/src/model/operation/moveoperation.d.ts +91 -0
- package/src/model/operation/nooperation.d.ts +33 -0
- package/src/model/operation/operation.d.ts +89 -0
- package/src/model/operation/operationfactory.d.ts +18 -0
- package/src/model/operation/renameoperation.d.ts +78 -0
- package/src/model/operation/rootattributeoperation.d.ts +97 -0
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.d.ts +104 -0
- package/src/model/operation/splitoperation.js +1 -1
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/operation/utils.js +1 -1
- package/src/model/position.d.ts +539 -0
- package/src/model/position.js +1 -1
- package/src/model/range.d.ts +458 -0
- package/src/model/range.js +1 -1
- package/src/model/rootelement.d.ts +40 -0
- package/src/model/schema.d.ts +1176 -0
- package/src/model/schema.js +19 -19
- package/src/model/selection.d.ts +472 -0
- package/src/model/text.d.ts +66 -0
- package/src/model/text.js +0 -2
- package/src/model/textproxy.d.ts +144 -0
- package/src/model/treewalker.d.ts +186 -0
- package/src/model/treewalker.js +19 -10
- package/src/model/typecheckable.d.ts +285 -0
- package/src/model/utils/autoparagraphing.d.ts +37 -0
- package/src/model/utils/deletecontent.d.ts +58 -0
- package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
- package/src/model/utils/getselectedcontent.d.ts +30 -0
- package/src/model/utils/insertcontent.d.ts +46 -0
- package/src/model/utils/insertcontent.js +2 -12
- package/src/model/utils/insertobject.d.ts +44 -0
- package/src/model/utils/insertobject.js +3 -14
- package/src/model/utils/modifyselection.d.ts +48 -0
- package/src/model/utils/selection-post-fixer.d.ts +65 -0
- package/src/model/writer.d.ts +823 -0
- package/src/model/writer.js +6 -61
- package/src/view/attributeelement.d.ts +108 -0
- package/src/view/attributeelement.js +25 -69
- package/src/view/containerelement.d.ts +49 -0
- package/src/view/containerelement.js +10 -43
- package/src/view/datatransfer.d.ts +75 -0
- package/src/view/document.d.ts +184 -0
- package/src/view/document.js +15 -84
- package/src/view/documentfragment.d.ts +149 -0
- package/src/view/documentfragment.js +39 -81
- package/src/view/documentselection.d.ts +306 -0
- package/src/view/documentselection.js +42 -143
- package/src/view/domconverter.d.ts +650 -0
- package/src/view/domconverter.js +157 -283
- package/src/view/downcastwriter.d.ts +996 -0
- package/src/view/downcastwriter.js +259 -426
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +468 -0
- package/src/view/element.js +150 -222
- package/src/view/elementdefinition.d.ts +87 -0
- package/src/view/emptyelement.d.ts +41 -0
- package/src/view/emptyelement.js +11 -44
- package/src/view/filler.d.ts +111 -0
- package/src/view/filler.js +24 -21
- package/src/view/item.d.ts +14 -0
- package/src/view/matcher.d.ts +486 -0
- package/src/view/matcher.js +247 -218
- package/src/view/node.d.ts +163 -0
- package/src/view/node.js +26 -100
- package/src/view/observer/arrowkeysobserver.d.ts +41 -0
- package/src/view/observer/arrowkeysobserver.js +0 -13
- package/src/view/observer/bubblingemittermixin.d.ts +166 -0
- package/src/view/observer/bubblingemittermixin.js +36 -25
- package/src/view/observer/bubblingeventinfo.d.ts +47 -0
- package/src/view/observer/bubblingeventinfo.js +3 -29
- package/src/view/observer/clickobserver.d.ts +43 -0
- package/src/view/observer/clickobserver.js +9 -19
- package/src/view/observer/compositionobserver.d.ts +82 -0
- package/src/view/observer/compositionobserver.js +13 -42
- package/src/view/observer/domeventdata.d.ts +50 -0
- package/src/view/observer/domeventdata.js +5 -30
- package/src/view/observer/domeventobserver.d.ts +69 -0
- package/src/view/observer/domeventobserver.js +19 -21
- package/src/view/observer/fakeselectionobserver.d.ts +43 -0
- package/src/view/observer/fakeselectionobserver.js +0 -16
- package/src/view/observer/focusobserver.d.ts +82 -0
- package/src/view/observer/focusobserver.js +14 -40
- package/src/view/observer/inputobserver.d.ts +86 -0
- package/src/view/observer/inputobserver.js +18 -64
- package/src/view/observer/keyobserver.d.ts +66 -0
- package/src/view/observer/keyobserver.js +8 -42
- package/src/view/observer/mouseobserver.d.ts +89 -0
- package/src/view/observer/mouseobserver.js +8 -28
- package/src/view/observer/mutationobserver.d.ts +82 -0
- package/src/view/observer/mutationobserver.js +7 -37
- package/src/view/observer/observer.d.ts +84 -0
- package/src/view/observer/observer.js +12 -25
- package/src/view/observer/selectionobserver.d.ts +144 -0
- package/src/view/observer/selectionobserver.js +17 -107
- package/src/view/observer/tabobserver.d.ts +42 -0
- package/src/view/observer/tabobserver.js +0 -14
- package/src/view/placeholder.d.ts +85 -0
- package/src/view/placeholder.js +26 -43
- package/src/view/position.d.ts +189 -0
- package/src/view/position.js +36 -83
- package/src/view/range.d.ts +279 -0
- package/src/view/range.js +79 -122
- package/src/view/rawelement.d.ts +73 -0
- package/src/view/rawelement.js +34 -48
- package/src/view/renderer.d.ts +265 -0
- package/src/view/renderer.js +105 -193
- package/src/view/rooteditableelement.d.ts +41 -0
- package/src/view/rooteditableelement.js +12 -40
- package/src/view/selection.d.ts +375 -0
- package/src/view/selection.js +79 -153
- package/src/view/styles/background.d.ts +33 -0
- package/src/view/styles/background.js +14 -12
- package/src/view/styles/border.d.ts +43 -0
- package/src/view/styles/border.js +58 -48
- package/src/view/styles/margin.d.ts +29 -0
- package/src/view/styles/margin.js +13 -11
- package/src/view/styles/padding.d.ts +29 -0
- package/src/view/styles/padding.js +13 -11
- package/src/view/styles/utils.d.ts +93 -0
- package/src/view/styles/utils.js +22 -48
- package/src/view/stylesmap.d.ts +675 -0
- package/src/view/stylesmap.js +249 -244
- package/src/view/text.d.ts +74 -0
- package/src/view/text.js +16 -46
- package/src/view/textproxy.d.ts +97 -0
- package/src/view/textproxy.js +10 -59
- package/src/view/treewalker.d.ts +195 -0
- package/src/view/treewalker.js +43 -106
- package/src/view/typecheckable.d.ts +448 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +29 -63
- package/src/view/upcastwriter.d.ts +417 -0
- package/src/view/upcastwriter.js +86 -157
- package/src/view/view.d.ts +417 -0
- package/src/view/view.js +47 -175
package/src/model/writer.js
CHANGED
|
@@ -29,16 +29,18 @@ import { CKEditorError, logWarning, toMap } from '@ckeditor/ckeditor5-utils';
|
|
|
29
29
|
* The instance of the writer is only available in the {@link module:engine/model/model~Model#change `change()`} or
|
|
30
30
|
* {@link module:engine/model/model~Model#enqueueChange `enqueueChange()`}.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* model.change( writer => {
|
|
34
|
+
* writer.insertText( 'foo', paragraph, 'end' );
|
|
35
|
+
* } );
|
|
36
|
+
* ```
|
|
35
37
|
*
|
|
36
38
|
* Note that the writer should never be stored and used outside of the `change()` and
|
|
37
39
|
* `enqueueChange()` blocks.
|
|
38
40
|
*
|
|
39
41
|
* Note that writer's methods do not check the {@link module:engine/model/schema~Schema}. It is possible
|
|
40
42
|
* to create incorrect model structures by using the writer. Read more about in
|
|
41
|
-
* {@glink framework/
|
|
43
|
+
* {@glink framework/deep-dive/schema#who-checks-the-schema "Who checks the schema?"}.
|
|
42
44
|
*
|
|
43
45
|
* @see module:engine/model/model~Model#change
|
|
44
46
|
* @see module:engine/model/model~Model#enqueueChange
|
|
@@ -519,9 +521,6 @@ export default class Writer {
|
|
|
519
521
|
createRangeOn(element) {
|
|
520
522
|
return this.model.createRangeOn(element);
|
|
521
523
|
}
|
|
522
|
-
/**
|
|
523
|
-
* Shortcut for {@link module:engine/model/model~Model#createSelection `Model#createSelection()`}.
|
|
524
|
-
*/
|
|
525
524
|
createSelection(...args) {
|
|
526
525
|
return this.model.createSelection(...args);
|
|
527
526
|
}
|
|
@@ -918,60 +917,6 @@ export default class Writer {
|
|
|
918
917
|
const oldRange = marker.getRange();
|
|
919
918
|
applyMarkerOperation(this, name, oldRange, null, marker.affectsData);
|
|
920
919
|
}
|
|
921
|
-
/**
|
|
922
|
-
* Sets the document's selection (ranges and direction) to the specified location based on the given
|
|
923
|
-
* {@link module:engine/model/selection~Selectable selectable} or creates an empty selection if no arguments were passed.
|
|
924
|
-
*
|
|
925
|
-
* ```ts
|
|
926
|
-
* // Sets selection to the given range.
|
|
927
|
-
* const range = writer.createRange( start, end );
|
|
928
|
-
* writer.setSelection( range );
|
|
929
|
-
*
|
|
930
|
-
* // Sets selection to given ranges.
|
|
931
|
-
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
|
|
932
|
-
* writer.setSelection( ranges );
|
|
933
|
-
*
|
|
934
|
-
* // Sets selection to other selection.
|
|
935
|
-
* const otherSelection = writer.createSelection();
|
|
936
|
-
* writer.setSelection( otherSelection );
|
|
937
|
-
*
|
|
938
|
-
* // Sets selection to the given document selection.
|
|
939
|
-
* const documentSelection = model.document.selection;
|
|
940
|
-
* writer.setSelection( documentSelection );
|
|
941
|
-
*
|
|
942
|
-
* // Sets collapsed selection at the given position.
|
|
943
|
-
* const position = writer.createPosition( root, path );
|
|
944
|
-
* writer.setSelection( position );
|
|
945
|
-
*
|
|
946
|
-
* // Sets collapsed selection at the position of the given node and an offset.
|
|
947
|
-
* writer.setSelection( paragraph, offset );
|
|
948
|
-
* ```
|
|
949
|
-
*
|
|
950
|
-
* Creates a range inside an {@link module:engine/model/element~Element element} which starts before the first child of
|
|
951
|
-
* that element and ends after the last child of that element.
|
|
952
|
-
*
|
|
953
|
-
* ```ts
|
|
954
|
-
* writer.setSelection( paragraph, 'in' );
|
|
955
|
-
* ```
|
|
956
|
-
*
|
|
957
|
-
* Creates a range on an {@link module:engine/model/item~Item item} which starts before the item and ends just after the item.
|
|
958
|
-
*
|
|
959
|
-
* ```ts
|
|
960
|
-
* writer.setSelection( paragraph, 'on' );
|
|
961
|
-
*
|
|
962
|
-
* // Removes all selection's ranges.
|
|
963
|
-
* writer.setSelection( null );
|
|
964
|
-
* ```
|
|
965
|
-
*
|
|
966
|
-
* `Writer#setSelection()` allow passing additional options (`backward`) as the last argument.
|
|
967
|
-
*
|
|
968
|
-
* ```ts
|
|
969
|
-
* // Sets selection as backward.
|
|
970
|
-
* writer.setSelection( range, { backward: true } );
|
|
971
|
-
* ```
|
|
972
|
-
*
|
|
973
|
-
* Throws `writer-incorrect-use` error when the writer is used outside the `change()` block.
|
|
974
|
-
*/
|
|
975
920
|
setSelection(...args) {
|
|
976
921
|
this._assertWriterUsedCorrectly();
|
|
977
922
|
this.model.document.selection._setTo(...args);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module engine/view/attributeelement
|
|
7
|
+
*/
|
|
8
|
+
import Element, { type ElementAttributes } from './element';
|
|
9
|
+
import type Document from './document';
|
|
10
|
+
import type Node from './node';
|
|
11
|
+
/**
|
|
12
|
+
* Attribute elements are used to represent formatting elements in the view (think – `<b>`, `<span style="font-size: 2em">`, etc.).
|
|
13
|
+
* Most often they are created when downcasting model text attributes.
|
|
14
|
+
*
|
|
15
|
+
* Editing engine does not define a fixed HTML DTD. This is why a feature developer needs to choose between various
|
|
16
|
+
* types (container element, {@link module:engine/view/attributeelement~AttributeElement attribute element},
|
|
17
|
+
* {@link module:engine/view/emptyelement~EmptyElement empty element}, etc) when developing a feature.
|
|
18
|
+
*
|
|
19
|
+
* To create a new attribute element instance use the
|
|
20
|
+
* {@link module:engine/view/downcastwriter~DowncastWriter#createAttributeElement `DowncastWriter#createAttributeElement()`} method.
|
|
21
|
+
*/
|
|
22
|
+
export default class AttributeElement extends Element {
|
|
23
|
+
static readonly DEFAULT_PRIORITY: number;
|
|
24
|
+
/**
|
|
25
|
+
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
* @readonly
|
|
29
|
+
*/
|
|
30
|
+
_priority: number;
|
|
31
|
+
/**
|
|
32
|
+
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
33
|
+
* and then two elements are considered similar if, and only if they have the same `_id`.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
* @readonly
|
|
37
|
+
*/
|
|
38
|
+
_id: string | number | null;
|
|
39
|
+
/**
|
|
40
|
+
* Keeps all the attribute elements that have the same {@link module:engine/view/attributeelement~AttributeElement#id ids}
|
|
41
|
+
* and still exist in the view tree.
|
|
42
|
+
*
|
|
43
|
+
* This property is managed by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
44
|
+
*/
|
|
45
|
+
private readonly _clonesGroup;
|
|
46
|
+
/**
|
|
47
|
+
* Creates an attribute element.
|
|
48
|
+
*
|
|
49
|
+
* @see module:engine/view/downcastwriter~DowncastWriter#createAttributeElement
|
|
50
|
+
* @see module:engine/view/element~Element
|
|
51
|
+
* @protected
|
|
52
|
+
* @param document The document instance to which this element belongs.
|
|
53
|
+
* @param name Node name.
|
|
54
|
+
* @param attrs Collection of attributes.
|
|
55
|
+
* @param children A list of nodes to be inserted into created element.
|
|
56
|
+
*/
|
|
57
|
+
constructor(document: Document, name: string, attrs?: ElementAttributes, children?: Node | Iterable<Node>);
|
|
58
|
+
/**
|
|
59
|
+
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
60
|
+
*/
|
|
61
|
+
get priority(): number;
|
|
62
|
+
/**
|
|
63
|
+
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
64
|
+
* and then two elements are considered similar if, and only if they have the same `id`.
|
|
65
|
+
*/
|
|
66
|
+
get id(): string | number | null;
|
|
67
|
+
/**
|
|
68
|
+
* Returns all {@link module:engine/view/attributeelement~AttributeElement attribute elements} that has the
|
|
69
|
+
* same {@link module:engine/view/attributeelement~AttributeElement#id id} and are in the view tree (were not removed).
|
|
70
|
+
*
|
|
71
|
+
* Note: If this element has been removed from the tree, returned set will not include it.
|
|
72
|
+
*
|
|
73
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError attribute-element-get-elements-with-same-id-no-id}
|
|
74
|
+
* if this element has no `id`.
|
|
75
|
+
*
|
|
76
|
+
* @returns Set containing all the attribute elements
|
|
77
|
+
* with the same `id` that were added and not removed from the view tree.
|
|
78
|
+
*/
|
|
79
|
+
getElementsWithSameId(): Set<AttributeElement>;
|
|
80
|
+
/**
|
|
81
|
+
* Checks if this element is similar to other element.
|
|
82
|
+
*
|
|
83
|
+
* If none of elements has set {@link module:engine/view/attributeelement~AttributeElement#id}, then both elements
|
|
84
|
+
* should have the same name, attributes and priority to be considered as similar. Two similar elements can contain
|
|
85
|
+
* different set of children nodes.
|
|
86
|
+
*
|
|
87
|
+
* If at least one element has {@link module:engine/view/attributeelement~AttributeElement#id} set, then both
|
|
88
|
+
* elements have to have the same {@link module:engine/view/attributeelement~AttributeElement#id} value to be
|
|
89
|
+
* considered similar.
|
|
90
|
+
*
|
|
91
|
+
* Similarity is important for {@link module:engine/view/downcastwriter~DowncastWriter}. For example:
|
|
92
|
+
*
|
|
93
|
+
* * two following similar elements can be merged together into one, longer element,
|
|
94
|
+
* * {@link module:engine/view/downcastwriter~DowncastWriter#unwrap} checks similarity of passed element and processed element to
|
|
95
|
+
* decide whether processed element should be unwrapped,
|
|
96
|
+
* * etc.
|
|
97
|
+
*/
|
|
98
|
+
isSimilar(otherElement: Element): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Clones provided element with priority.
|
|
101
|
+
*
|
|
102
|
+
* @internal
|
|
103
|
+
* @param deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
104
|
+
* element will be cloned without any children.
|
|
105
|
+
* @returns Clone of this element.
|
|
106
|
+
*/
|
|
107
|
+
_clone(deep?: boolean): this;
|
|
108
|
+
}
|
|
@@ -19,8 +19,6 @@ const DEFAULT_PRIORITY = 10;
|
|
|
19
19
|
*
|
|
20
20
|
* To create a new attribute element instance use the
|
|
21
21
|
* {@link module:engine/view/downcastwriter~DowncastWriter#createAttributeElement `DowncastWriter#createAttributeElement()`} method.
|
|
22
|
-
*
|
|
23
|
-
* @extends module:engine/view/element~Element
|
|
24
22
|
*/
|
|
25
23
|
export default class AttributeElement extends Element {
|
|
26
24
|
/**
|
|
@@ -29,34 +27,26 @@ export default class AttributeElement extends Element {
|
|
|
29
27
|
* @see module:engine/view/downcastwriter~DowncastWriter#createAttributeElement
|
|
30
28
|
* @see module:engine/view/element~Element
|
|
31
29
|
* @protected
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* A list of nodes to be inserted into created element.
|
|
30
|
+
* @param document The document instance to which this element belongs.
|
|
31
|
+
* @param name Node name.
|
|
32
|
+
* @param attrs Collection of attributes.
|
|
33
|
+
* @param children A list of nodes to be inserted into created element.
|
|
37
34
|
*/
|
|
38
|
-
constructor(
|
|
39
|
-
super(
|
|
40
|
-
/**
|
|
41
|
-
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
42
|
-
*
|
|
43
|
-
* @method #getFillerOffset
|
|
44
|
-
* @returns {Number|null} Block filler offset or `null` if block filler is not needed.
|
|
45
|
-
*/
|
|
46
|
-
this.getFillerOffset = getFillerOffset;
|
|
35
|
+
constructor(document, name, attrs, children) {
|
|
36
|
+
super(document, name, attrs, children);
|
|
47
37
|
/**
|
|
48
38
|
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
49
39
|
*
|
|
50
|
-
* @
|
|
51
|
-
* @
|
|
40
|
+
* @internal
|
|
41
|
+
* @readonly
|
|
52
42
|
*/
|
|
53
43
|
this._priority = DEFAULT_PRIORITY;
|
|
54
44
|
/**
|
|
55
45
|
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
56
46
|
* and then two elements are considered similar if, and only if they have the same `_id`.
|
|
57
47
|
*
|
|
58
|
-
* @
|
|
59
|
-
* @
|
|
48
|
+
* @internal
|
|
49
|
+
* @readonly
|
|
60
50
|
*/
|
|
61
51
|
this._id = null;
|
|
62
52
|
/**
|
|
@@ -64,17 +54,12 @@ export default class AttributeElement extends Element {
|
|
|
64
54
|
* and still exist in the view tree.
|
|
65
55
|
*
|
|
66
56
|
* This property is managed by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
67
|
-
*
|
|
68
|
-
* @protected
|
|
69
|
-
* @member {Set.<module:engine/view/attributeelement~AttributeElement>|null}
|
|
70
57
|
*/
|
|
71
58
|
this._clonesGroup = null;
|
|
59
|
+
this.getFillerOffset = getFillerOffset;
|
|
72
60
|
}
|
|
73
61
|
/**
|
|
74
62
|
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
-
* @type {Number}
|
|
78
63
|
*/
|
|
79
64
|
get priority() {
|
|
80
65
|
return this._priority;
|
|
@@ -82,9 +67,6 @@ export default class AttributeElement extends Element {
|
|
|
82
67
|
/**
|
|
83
68
|
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
84
69
|
* and then two elements are considered similar if, and only if they have the same `id`.
|
|
85
|
-
*
|
|
86
|
-
* @readonly
|
|
87
|
-
* @type {String|Number}
|
|
88
70
|
*/
|
|
89
71
|
get id() {
|
|
90
72
|
return this._id;
|
|
@@ -98,7 +80,7 @@ export default class AttributeElement extends Element {
|
|
|
98
80
|
* Throws {@link module:utils/ckeditorerror~CKEditorError attribute-element-get-elements-with-same-id-no-id}
|
|
99
81
|
* if this element has no `id`.
|
|
100
82
|
*
|
|
101
|
-
* @returns
|
|
83
|
+
* @returns Set containing all the attribute elements
|
|
102
84
|
* with the same `id` that were added and not removed from the view tree.
|
|
103
85
|
*/
|
|
104
86
|
getElementsWithSameId() {
|
|
@@ -129,9 +111,6 @@ export default class AttributeElement extends Element {
|
|
|
129
111
|
* * {@link module:engine/view/downcastwriter~DowncastWriter#unwrap} checks similarity of passed element and processed element to
|
|
130
112
|
* decide whether processed element should be unwrapped,
|
|
131
113
|
* * etc.
|
|
132
|
-
*
|
|
133
|
-
* @param {module:engine/view/element~Element} otherElement
|
|
134
|
-
* @returns {Boolean}
|
|
135
114
|
*/
|
|
136
115
|
isSimilar(otherElement) {
|
|
137
116
|
// If any element has an `id` set, just compare the ids.
|
|
@@ -143,10 +122,10 @@ export default class AttributeElement extends Element {
|
|
|
143
122
|
/**
|
|
144
123
|
* Clones provided element with priority.
|
|
145
124
|
*
|
|
146
|
-
* @
|
|
147
|
-
* @param
|
|
125
|
+
* @internal
|
|
126
|
+
* @param deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
148
127
|
* element will be cloned without any children.
|
|
149
|
-
* @returns
|
|
128
|
+
* @returns Clone of this element.
|
|
150
129
|
*/
|
|
151
130
|
_clone(deep = false) {
|
|
152
131
|
const cloned = super._clone(deep);
|
|
@@ -158,32 +137,8 @@ export default class AttributeElement extends Element {
|
|
|
158
137
|
}
|
|
159
138
|
}
|
|
160
139
|
AttributeElement.DEFAULT_PRIORITY = DEFAULT_PRIORITY;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*
|
|
164
|
-
* attributeElement.is( 'attributeElement' ); // -> true
|
|
165
|
-
* attributeElement.is( 'element' ); // -> true
|
|
166
|
-
* attributeElement.is( 'node' ); // -> true
|
|
167
|
-
* attributeElement.is( 'view:attributeElement' ); // -> true
|
|
168
|
-
* attributeElement.is( 'view:element' ); // -> true
|
|
169
|
-
* attributeElement.is( 'view:node' ); // -> true
|
|
170
|
-
*
|
|
171
|
-
* attributeElement.is( 'model:element' ); // -> false
|
|
172
|
-
* attributeElement.is( 'documentFragment' ); // -> false
|
|
173
|
-
*
|
|
174
|
-
* Assuming that the object being checked is an attribute element, you can also check its
|
|
175
|
-
* {@link module:engine/view/attributeelement~AttributeElement#name name}:
|
|
176
|
-
*
|
|
177
|
-
* attributeElement.is( 'element', 'b' ); // -> true if this is a bold element
|
|
178
|
-
* attributeElement.is( 'attributeElement', 'b' ); // -> same as above
|
|
179
|
-
* text.is( 'element', 'b' ); -> false
|
|
180
|
-
*
|
|
181
|
-
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
182
|
-
*
|
|
183
|
-
* @param {String} type Type to check.
|
|
184
|
-
* @param {String} [name] Element name.
|
|
185
|
-
* @returns {Boolean}
|
|
186
|
-
*/
|
|
140
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
141
|
+
// Proper overload would interfere with that.
|
|
187
142
|
AttributeElement.prototype.is = function (type, name) {
|
|
188
143
|
if (!name) {
|
|
189
144
|
return type === 'attributeElement' || type === 'view:attributeElement' ||
|
|
@@ -197,9 +152,11 @@ AttributeElement.prototype.is = function (type, name) {
|
|
|
197
152
|
type === 'element' || type === 'view:element');
|
|
198
153
|
}
|
|
199
154
|
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Returns block {@link module:engine/view/filler~Filler filler} offset or `null` if block filler is not needed.
|
|
157
|
+
*
|
|
158
|
+
* @returns Block filler offset or `null` if block filler is not needed.
|
|
159
|
+
*/
|
|
203
160
|
function getFillerOffset() {
|
|
204
161
|
// <b>foo</b> does not need filler.
|
|
205
162
|
if (nonUiChildrenCount(this)) {
|
|
@@ -219,10 +176,9 @@ function getFillerOffset() {
|
|
|
219
176
|
// Render block filler at the end of element (after all ui elements).
|
|
220
177
|
return this.childCount;
|
|
221
178
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
// @returns {Number}
|
|
179
|
+
/**
|
|
180
|
+
* Returns total count of children that are not {@link module:engine/view/uielement~UIElement UIElements}.
|
|
181
|
+
*/
|
|
226
182
|
function nonUiChildrenCount(element) {
|
|
227
183
|
return Array.from(element.getChildren()).filter(element => !element.is('uiElement')).length;
|
|
228
184
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module engine/view/containerelement
|
|
7
|
+
*/
|
|
8
|
+
import Element, { type ElementAttributes } from './element';
|
|
9
|
+
import type Document from './document';
|
|
10
|
+
import type Node from './node';
|
|
11
|
+
/**
|
|
12
|
+
* Containers are elements which define document structure. They define boundaries for
|
|
13
|
+
* {@link module:engine/view/attributeelement~AttributeElement attributes}. They are mostly used for block elements like `<p>` or `<div>`.
|
|
14
|
+
*
|
|
15
|
+
* Editing engine does not define a fixed HTML DTD. This is why a feature developer needs to choose between various
|
|
16
|
+
* types (container element, {@link module:engine/view/attributeelement~AttributeElement attribute element},
|
|
17
|
+
* {@link module:engine/view/emptyelement~EmptyElement empty element}, etc) when developing a feature.
|
|
18
|
+
*
|
|
19
|
+
* The container element should be your default choice when writing a converter, unless:
|
|
20
|
+
*
|
|
21
|
+
* * this element represents a model text attribute (then use {@link module:engine/view/attributeelement~AttributeElement}),
|
|
22
|
+
* * this is an empty element like `<img>` (then use {@link module:engine/view/emptyelement~EmptyElement}),
|
|
23
|
+
* * this is a root element,
|
|
24
|
+
* * this is a nested editable element (then use {@link module:engine/view/editableelement~EditableElement}).
|
|
25
|
+
*
|
|
26
|
+
* To create a new container element instance use the
|
|
27
|
+
* {@link module:engine/view/downcastwriter~DowncastWriter#createContainerElement `DowncastWriter#createContainerElement()`}
|
|
28
|
+
* method.
|
|
29
|
+
*/
|
|
30
|
+
export default class ContainerElement extends Element {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a container element.
|
|
33
|
+
*
|
|
34
|
+
* @see module:engine/view/downcastwriter~DowncastWriter#createContainerElement
|
|
35
|
+
* @see module:engine/view/element~Element
|
|
36
|
+
* @internal
|
|
37
|
+
* @param document The document instance to which this element belongs.
|
|
38
|
+
* @param name Node name.
|
|
39
|
+
* @param attrs Collection of attributes.
|
|
40
|
+
* @param children A list of nodes to be inserted into created element.
|
|
41
|
+
*/
|
|
42
|
+
constructor(document: Document, name: string, attrs?: ElementAttributes, children?: Node | Iterable<Node>);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
46
|
+
*
|
|
47
|
+
* @returns Block filler offset or `null` if block filler is not needed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getFillerOffset(this: ContainerElement): number | null;
|
|
@@ -24,8 +24,6 @@ import Element from './element';
|
|
|
24
24
|
* To create a new container element instance use the
|
|
25
25
|
* {@link module:engine/view/downcastwriter~DowncastWriter#createContainerElement `DowncastWriter#createContainerElement()`}
|
|
26
26
|
* method.
|
|
27
|
-
*
|
|
28
|
-
* @extends module:engine/view/element~Element
|
|
29
27
|
*/
|
|
30
28
|
export default class ContainerElement extends Element {
|
|
31
29
|
/**
|
|
@@ -33,50 +31,19 @@ export default class ContainerElement extends Element {
|
|
|
33
31
|
*
|
|
34
32
|
* @see module:engine/view/downcastwriter~DowncastWriter#createContainerElement
|
|
35
33
|
* @see module:engine/view/element~Element
|
|
36
|
-
* @
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* A list of nodes to be inserted into created element.
|
|
34
|
+
* @internal
|
|
35
|
+
* @param document The document instance to which this element belongs.
|
|
36
|
+
* @param name Node name.
|
|
37
|
+
* @param attrs Collection of attributes.
|
|
38
|
+
* @param children A list of nodes to be inserted into created element.
|
|
42
39
|
*/
|
|
43
|
-
constructor(
|
|
44
|
-
super(
|
|
45
|
-
/**
|
|
46
|
-
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
47
|
-
*
|
|
48
|
-
* @method #getFillerOffset
|
|
49
|
-
* @returns {Number|null} Block filler offset or `null` if block filler is not needed.
|
|
50
|
-
*/
|
|
40
|
+
constructor(document, name, attrs, children) {
|
|
41
|
+
super(document, name, attrs, children);
|
|
51
42
|
this.getFillerOffset = getFillerOffset;
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
* containerElement.is( 'containerElement' ); // -> true
|
|
58
|
-
* containerElement.is( 'element' ); // -> true
|
|
59
|
-
* containerElement.is( 'node' ); // -> true
|
|
60
|
-
* containerElement.is( 'view:containerElement' ); // -> true
|
|
61
|
-
* containerElement.is( 'view:element' ); // -> true
|
|
62
|
-
* containerElement.is( 'view:node' ); // -> true
|
|
63
|
-
*
|
|
64
|
-
* containerElement.is( 'model:element' ); // -> false
|
|
65
|
-
* containerElement.is( 'documentFragment' ); // -> false
|
|
66
|
-
*
|
|
67
|
-
* Assuming that the object being checked is a container element, you can also check its
|
|
68
|
-
* {@link module:engine/view/containerelement~ContainerElement#name name}:
|
|
69
|
-
*
|
|
70
|
-
* containerElement.is( 'element', 'div' ); // -> true if this is a div container element
|
|
71
|
-
* containerElement.is( 'contaienrElement', 'div' ); // -> same as above
|
|
72
|
-
* text.is( 'element', 'div' ); -> false
|
|
73
|
-
*
|
|
74
|
-
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
75
|
-
*
|
|
76
|
-
* @param {String} type Type to check.
|
|
77
|
-
* @param {String} [name] Element name.
|
|
78
|
-
* @returns {Boolean}
|
|
79
|
-
*/
|
|
45
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
46
|
+
// Proper overload would interfere with that.
|
|
80
47
|
ContainerElement.prototype.is = function (type, name) {
|
|
81
48
|
if (!name) {
|
|
82
49
|
return type === 'containerElement' || type === 'view:containerElement' ||
|
|
@@ -93,7 +60,7 @@ ContainerElement.prototype.is = function (type, name) {
|
|
|
93
60
|
/**
|
|
94
61
|
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
95
62
|
*
|
|
96
|
-
* @returns
|
|
63
|
+
* @returns Block filler offset or `null` if block filler is not needed.
|
|
97
64
|
*/
|
|
98
65
|
export function getFillerOffset() {
|
|
99
66
|
const children = [...this.getChildren()];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module engine/view/datatransfer
|
|
7
|
+
*/
|
|
8
|
+
type DomDataTransfer = globalThis.DataTransfer;
|
|
9
|
+
/**
|
|
10
|
+
* A facade over the native [`DataTransfer`](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) object.
|
|
11
|
+
*/
|
|
12
|
+
export default class DataTransfer {
|
|
13
|
+
/**
|
|
14
|
+
* The array of files created from the native `DataTransfer#files` or `DataTransfer#items`.
|
|
15
|
+
*/
|
|
16
|
+
private _files;
|
|
17
|
+
/**
|
|
18
|
+
* The native DataTransfer object.
|
|
19
|
+
*/
|
|
20
|
+
private _native;
|
|
21
|
+
/**
|
|
22
|
+
* @param nativeDataTransfer The native [`DataTransfer`](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) object.
|
|
23
|
+
* @param options.cacheFiles Whether `files` list should be initialized in the constructor.
|
|
24
|
+
*/
|
|
25
|
+
constructor(nativeDataTransfer: DomDataTransfer, options?: {
|
|
26
|
+
cacheFiles?: boolean;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* The array of files created from the native `DataTransfer#files` or `DataTransfer#items`.
|
|
30
|
+
*/
|
|
31
|
+
get files(): Array<File>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns an array of available native content types.
|
|
34
|
+
*/
|
|
35
|
+
get types(): ReadonlyArray<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the data from the data transfer by its MIME type.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* dataTransfer.getData( 'text/plain' );
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param type The MIME type. E.g. `text/html` or `text/plain`.
|
|
44
|
+
*/
|
|
45
|
+
getData(type: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Sets the data in the data transfer.
|
|
48
|
+
*
|
|
49
|
+
* @param type The MIME type. E.g. `text/html` or `text/plain`.
|
|
50
|
+
*/
|
|
51
|
+
setData(type: string, data: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* The effect that is allowed for a drag operation.
|
|
54
|
+
*/
|
|
55
|
+
set effectAllowed(value: EffectAllowed);
|
|
56
|
+
get effectAllowed(): EffectAllowed;
|
|
57
|
+
/**
|
|
58
|
+
* The actual drop effect.
|
|
59
|
+
*/
|
|
60
|
+
set dropEffect(value: DropEffect);
|
|
61
|
+
get dropEffect(): DropEffect;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the dragging operation was canceled.
|
|
64
|
+
*/
|
|
65
|
+
get isCanceled(): boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The effect that is allowed for a drag operation.
|
|
69
|
+
*/
|
|
70
|
+
export type EffectAllowed = DomDataTransfer['effectAllowed'];
|
|
71
|
+
/**
|
|
72
|
+
* The actual drop effect.
|
|
73
|
+
*/
|
|
74
|
+
export type DropEffect = DomDataTransfer['dropEffect'];
|
|
75
|
+
export {};
|