@ckeditor/ckeditor5-engine 41.2.0 → 41.3.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/dist/content-index.css +4 -0
- package/dist/editor-index.css +23 -0
- package/dist/index.css +49 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +36728 -0
- package/dist/index.js.map +1 -0
- package/dist/types/controller/datacontroller.d.ts +335 -0
- package/dist/types/controller/editingcontroller.d.ts +98 -0
- package/dist/types/conversion/conversion.d.ts +478 -0
- package/dist/types/conversion/conversionhelpers.d.ts +26 -0
- package/dist/types/conversion/downcastdispatcher.d.ts +562 -0
- package/dist/types/conversion/downcasthelpers.d.ts +1190 -0
- package/dist/types/conversion/mapper.d.ts +503 -0
- package/dist/types/conversion/modelconsumable.d.ts +201 -0
- package/dist/types/conversion/upcastdispatcher.d.ts +492 -0
- package/dist/types/conversion/upcasthelpers.d.ts +499 -0
- package/dist/types/conversion/viewconsumable.d.ts +369 -0
- package/dist/types/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/dist/types/dataprocessor/dataprocessor.d.ts +61 -0
- package/dist/types/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/dist/types/dataprocessor/htmlwriter.d.ts +16 -0
- package/dist/types/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/dist/types/dev-utils/model.d.ts +124 -0
- package/dist/types/dev-utils/operationreplayer.d.ts +51 -0
- package/dist/types/dev-utils/utils.d.ts +37 -0
- package/dist/types/dev-utils/view.d.ts +319 -0
- package/dist/types/index.d.ts +113 -0
- package/dist/types/model/batch.d.ts +106 -0
- package/dist/types/model/differ.d.ts +415 -0
- package/dist/types/model/document.d.ts +274 -0
- package/dist/types/model/documentfragment.d.ts +200 -0
- package/dist/types/model/documentselection.d.ts +420 -0
- package/dist/types/model/element.d.ts +165 -0
- package/dist/types/model/history.d.ts +114 -0
- package/dist/types/model/item.d.ts +14 -0
- package/dist/types/model/liveposition.d.ts +77 -0
- package/dist/types/model/liverange.d.ts +102 -0
- package/dist/types/model/markercollection.d.ts +335 -0
- package/dist/types/model/model.d.ts +919 -0
- package/dist/types/model/node.d.ts +255 -0
- package/dist/types/model/nodelist.d.ts +91 -0
- package/dist/types/model/operation/attributeoperation.d.ts +103 -0
- package/dist/types/model/operation/detachoperation.d.ts +60 -0
- package/dist/types/model/operation/insertoperation.d.ts +90 -0
- package/dist/types/model/operation/markeroperation.d.ts +91 -0
- package/dist/types/model/operation/mergeoperation.d.ts +100 -0
- package/dist/types/model/operation/moveoperation.d.ts +96 -0
- package/dist/types/model/operation/nooperation.d.ts +38 -0
- package/dist/types/model/operation/operation.d.ts +96 -0
- package/dist/types/model/operation/operationfactory.d.ts +18 -0
- package/dist/types/model/operation/renameoperation.d.ts +83 -0
- package/dist/types/model/operation/rootattributeoperation.d.ts +98 -0
- package/dist/types/model/operation/rootoperation.d.ts +76 -0
- package/dist/types/model/operation/splitoperation.d.ts +109 -0
- package/dist/types/model/operation/transform.d.ts +100 -0
- package/dist/types/model/operation/utils.d.ts +71 -0
- package/dist/types/model/position.d.ts +538 -0
- package/dist/types/model/range.d.ts +458 -0
- package/dist/types/model/rootelement.d.ts +60 -0
- package/dist/types/model/schema.d.ts +1206 -0
- package/dist/types/model/selection.d.ts +482 -0
- package/dist/types/model/text.d.ts +66 -0
- package/dist/types/model/textproxy.d.ts +144 -0
- package/dist/types/model/treewalker.d.ts +186 -0
- package/dist/types/model/typecheckable.d.ts +285 -0
- package/dist/types/model/utils/autoparagraphing.d.ts +37 -0
- package/dist/types/model/utils/deletecontent.d.ts +58 -0
- package/dist/types/model/utils/getselectedcontent.d.ts +30 -0
- package/dist/types/model/utils/insertcontent.d.ts +46 -0
- package/dist/types/model/utils/insertobject.d.ts +47 -0
- package/dist/types/model/utils/modifyselection.d.ts +48 -0
- package/dist/types/model/utils/selection-post-fixer.d.ts +74 -0
- package/dist/types/model/writer.d.ts +851 -0
- package/dist/types/view/attributeelement.d.ts +108 -0
- package/dist/types/view/containerelement.d.ts +49 -0
- package/dist/types/view/datatransfer.d.ts +79 -0
- package/dist/types/view/document.d.ts +184 -0
- package/dist/types/view/documentfragment.d.ts +153 -0
- package/dist/types/view/documentselection.d.ts +306 -0
- package/dist/types/view/domconverter.d.ts +652 -0
- package/dist/types/view/downcastwriter.d.ts +996 -0
- package/dist/types/view/editableelement.d.ts +62 -0
- package/dist/types/view/element.d.ts +468 -0
- package/dist/types/view/elementdefinition.d.ts +87 -0
- package/dist/types/view/emptyelement.d.ts +41 -0
- package/dist/types/view/filler.d.ts +111 -0
- package/dist/types/view/item.d.ts +14 -0
- package/dist/types/view/matcher.d.ts +486 -0
- package/dist/types/view/node.d.ts +162 -0
- package/dist/types/view/observer/arrowkeysobserver.d.ts +45 -0
- package/dist/types/view/observer/bubblingemittermixin.d.ts +166 -0
- package/dist/types/view/observer/bubblingeventinfo.d.ts +47 -0
- package/dist/types/view/observer/clickobserver.d.ts +43 -0
- package/dist/types/view/observer/compositionobserver.d.ts +82 -0
- package/dist/types/view/observer/domeventdata.d.ts +50 -0
- package/dist/types/view/observer/domeventobserver.d.ts +73 -0
- package/dist/types/view/observer/fakeselectionobserver.d.ts +47 -0
- package/dist/types/view/observer/focusobserver.d.ts +82 -0
- package/dist/types/view/observer/inputobserver.d.ts +86 -0
- package/dist/types/view/observer/keyobserver.d.ts +66 -0
- package/dist/types/view/observer/mouseobserver.d.ts +89 -0
- package/dist/types/view/observer/mutationobserver.d.ts +86 -0
- package/dist/types/view/observer/observer.d.ts +89 -0
- package/dist/types/view/observer/selectionobserver.d.ts +148 -0
- package/dist/types/view/observer/tabobserver.d.ts +46 -0
- package/dist/types/view/placeholder.d.ts +96 -0
- package/dist/types/view/position.d.ts +188 -0
- package/dist/types/view/range.d.ts +279 -0
- package/dist/types/view/rawelement.d.ts +73 -0
- package/dist/types/view/renderer.d.ts +265 -0
- package/dist/types/view/rooteditableelement.d.ts +41 -0
- package/dist/types/view/selection.d.ts +375 -0
- package/dist/types/view/styles/background.d.ts +33 -0
- package/dist/types/view/styles/border.d.ts +43 -0
- package/dist/types/view/styles/margin.d.ts +29 -0
- package/dist/types/view/styles/padding.d.ts +29 -0
- package/dist/types/view/styles/utils.d.ts +93 -0
- package/dist/types/view/stylesmap.d.ts +673 -0
- package/dist/types/view/text.d.ts +74 -0
- package/dist/types/view/textproxy.d.ts +97 -0
- package/dist/types/view/treewalker.d.ts +195 -0
- package/dist/types/view/typecheckable.d.ts +448 -0
- package/dist/types/view/uielement.d.ts +96 -0
- package/dist/types/view/upcastwriter.d.ts +417 -0
- package/dist/types/view/view.d.ts +487 -0
- package/package.json +3 -2
- package/src/model/node.d.ts +0 -1
- package/src/model/node.js +0 -2
- package/src/model/position.d.ts +0 -1
- package/src/model/position.js +0 -2
- package/src/view/node.d.ts +0 -1
- package/src/view/node.js +0 -2
- package/src/view/position.d.ts +0 -1
- package/src/view/position.js +0 -2
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { default as Position } from './position.js';
|
|
6
|
+
import type Item from './item.js';
|
|
7
|
+
import type Range from './range.js';
|
|
8
|
+
/**
|
|
9
|
+
* Position iterator class. It allows to iterate forward and backward over the document.
|
|
10
|
+
*/
|
|
11
|
+
export default class TreeWalker implements Iterable<TreeWalkerValue> {
|
|
12
|
+
/**
|
|
13
|
+
* Walking direction. Defaults `'forward'`.
|
|
14
|
+
*/
|
|
15
|
+
readonly direction: TreeWalkerDirection;
|
|
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
|
+
readonly boundaries: Range | null;
|
|
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
|
+
readonly singleCharacters: boolean;
|
|
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
|
+
readonly shallow: boolean;
|
|
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
|
+
readonly ignoreElementEnd: boolean;
|
|
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
|
+
private _position;
|
|
49
|
+
/**
|
|
50
|
+
* Start boundary cached for optimization purposes.
|
|
51
|
+
*/
|
|
52
|
+
private _boundaryStartParent;
|
|
53
|
+
/**
|
|
54
|
+
* End boundary cached for optimization purposes.
|
|
55
|
+
*/
|
|
56
|
+
private _boundaryEndParent;
|
|
57
|
+
/**
|
|
58
|
+
* Parent of the most recently visited node. Cached for optimization purposes.
|
|
59
|
+
*/
|
|
60
|
+
private _visitedParent;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
|
|
63
|
+
*
|
|
64
|
+
* @param options Object with configuration.
|
|
65
|
+
*/
|
|
66
|
+
constructor(options: TreeWalkerOptions);
|
|
67
|
+
/**
|
|
68
|
+
* Iterable interface.
|
|
69
|
+
*
|
|
70
|
+
* @returns {Iterable.<module:engine/model/treewalker~TreeWalkerValue>}
|
|
71
|
+
*/
|
|
72
|
+
[Symbol.iterator](): IterableIterator<TreeWalkerValue>;
|
|
73
|
+
/**
|
|
74
|
+
* Iterator position. This is always static position, even if the initial position was a
|
|
75
|
+
* {@link module:engine/model/liveposition~LivePosition live position}. If start position is not defined then position depends
|
|
76
|
+
* on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
|
|
77
|
+
* is `'backward'` position starts from the end.
|
|
78
|
+
*/
|
|
79
|
+
get position(): Position;
|
|
80
|
+
/**
|
|
81
|
+
* Moves {@link #position} in the {@link #direction} skipping values as long as the callback function returns `true`.
|
|
82
|
+
*
|
|
83
|
+
* For example:
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* walker.skip( value => value.type == 'text' ); // <paragraph>[]foo</paragraph> -> <paragraph>foo[]</paragraph>
|
|
87
|
+
* walker.skip( () => true ); // Move the position to the end: <paragraph>[]foo</paragraph> -> <paragraph>foo</paragraph>[]
|
|
88
|
+
* walker.skip( () => false ); // Do not move the position.
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param skip Callback function. Gets {@link module:engine/model/treewalker~TreeWalkerValue} and should
|
|
92
|
+
* return `true` if the value should be skipped or `false` if not.
|
|
93
|
+
*/
|
|
94
|
+
skip(skip: (value: TreeWalkerValue) => boolean): void;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the next tree walker's value.
|
|
97
|
+
*/
|
|
98
|
+
next(): IteratorResult<TreeWalkerValue>;
|
|
99
|
+
/**
|
|
100
|
+
* Makes a step forward in model. Moves the {@link #position} to the next position and returns the encountered value.
|
|
101
|
+
*/
|
|
102
|
+
private _next;
|
|
103
|
+
/**
|
|
104
|
+
* Makes a step backward in model. Moves the {@link #position} to the previous position and returns the encountered value.
|
|
105
|
+
*/
|
|
106
|
+
private _previous;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Type of the step made by {@link module:engine/model/treewalker~TreeWalker}.
|
|
110
|
+
* Possible values: `'elementStart'` if walker is at the beginning of a node, `'elementEnd'` if walker is at the end of node,
|
|
111
|
+
* or `'text'` if walker traversed over text.
|
|
112
|
+
*/
|
|
113
|
+
export type TreeWalkerValueType = 'elementStart' | 'elementEnd' | 'text';
|
|
114
|
+
/**
|
|
115
|
+
* Object returned by {@link module:engine/model/treewalker~TreeWalker} when traversing tree model.
|
|
116
|
+
*/
|
|
117
|
+
export interface TreeWalkerValue {
|
|
118
|
+
type: TreeWalkerValueType;
|
|
119
|
+
/**
|
|
120
|
+
* Item between old and new positions of {@link module:engine/model/treewalker~TreeWalker}.
|
|
121
|
+
*/
|
|
122
|
+
item: Item;
|
|
123
|
+
/**
|
|
124
|
+
* Previous position of the iterator.
|
|
125
|
+
* * Forward iteration: For `'elementEnd'` it is the last position inside the element. For all other types it is the
|
|
126
|
+
* position before the item.
|
|
127
|
+
* * Backward iteration: For `'elementStart'` it is the first position inside the element. For all other types it is
|
|
128
|
+
* the position after item.
|
|
129
|
+
*/
|
|
130
|
+
previousPosition: Position;
|
|
131
|
+
/**
|
|
132
|
+
* Next position of the iterator.
|
|
133
|
+
* * Forward iteration: For `'elementStart'` it is the first position inside the element. For all other types it is
|
|
134
|
+
* the position after the item.
|
|
135
|
+
* * Backward iteration: For `'elementEnd'` it is last position inside element. For all other types it is the position
|
|
136
|
+
* before the item.
|
|
137
|
+
*/
|
|
138
|
+
nextPosition: Position;
|
|
139
|
+
/**
|
|
140
|
+
* Length of the item. For `'elementStart'` it is 1. For `'text'` it is the length of the text. For `'elementEnd'` it is `undefined`.
|
|
141
|
+
*/
|
|
142
|
+
length?: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Tree walking direction.
|
|
146
|
+
*/
|
|
147
|
+
export type TreeWalkerDirection = 'forward' | 'backward';
|
|
148
|
+
/**
|
|
149
|
+
* The configuration of TreeWalker.
|
|
150
|
+
*
|
|
151
|
+
* All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
|
|
152
|
+
*/
|
|
153
|
+
export interface TreeWalkerOptions {
|
|
154
|
+
/**
|
|
155
|
+
* Walking direction.
|
|
156
|
+
*
|
|
157
|
+
* @default 'forward'
|
|
158
|
+
*/
|
|
159
|
+
direction?: TreeWalkerDirection;
|
|
160
|
+
/**
|
|
161
|
+
* Range to define boundaries of the iterator.
|
|
162
|
+
*/
|
|
163
|
+
boundaries?: Range | null;
|
|
164
|
+
/**
|
|
165
|
+
* Starting position.
|
|
166
|
+
*/
|
|
167
|
+
startPosition?: Position;
|
|
168
|
+
/**
|
|
169
|
+
* Flag indicating whether all consecutive characters with the same attributes
|
|
170
|
+
* should be returned one by one as multiple {@link module:engine/model/textproxy~TextProxy} (`true`) objects or as one
|
|
171
|
+
* {@link module:engine/model/textproxy~TextProxy} (`false`).
|
|
172
|
+
*/
|
|
173
|
+
singleCharacters?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Flag indicating whether iterator should enter elements or not. If the
|
|
176
|
+
* iterator is shallow child nodes of any iterated node will not be returned along with `elementEnd` tag.
|
|
177
|
+
*/
|
|
178
|
+
shallow?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Flag indicating whether iterator should ignore `elementEnd` tags.
|
|
181
|
+
* If the option is true walker will not return a parent node of start position. If this option is `true`
|
|
182
|
+
* each {@link module:engine/model/element~Element} will be returned once, while if the option is `false` they might be returned
|
|
183
|
+
* twice: for `'elementStart'` and `'elementEnd'`.
|
|
184
|
+
*/
|
|
185
|
+
ignoreElementEnd?: boolean;
|
|
186
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/model/typecheckable
|
|
7
|
+
*/
|
|
8
|
+
import type { Marker } from './markercollection.js';
|
|
9
|
+
import type DocumentFragment from './documentfragment.js';
|
|
10
|
+
import type DocumentSelection from './documentselection.js';
|
|
11
|
+
import type Element from './element.js';
|
|
12
|
+
import type LivePosition from './liveposition.js';
|
|
13
|
+
import type LiveRange from './liverange.js';
|
|
14
|
+
import type Node from './node.js';
|
|
15
|
+
import type Position from './position.js';
|
|
16
|
+
import type Range from './range.js';
|
|
17
|
+
import type RootElement from './rootelement.js';
|
|
18
|
+
import type Selection from './selection.js';
|
|
19
|
+
import type Text from './text.js';
|
|
20
|
+
import type TextProxy from './textproxy.js';
|
|
21
|
+
export default abstract class TypeCheckable {
|
|
22
|
+
/**
|
|
23
|
+
* Checks whether the object is of type {@link module:engine/model/node~Node} or its subclass.
|
|
24
|
+
*
|
|
25
|
+
* This method is useful when processing model objects that are of unknown type. For example, a function
|
|
26
|
+
* may return a {@link module:engine/model/documentfragment~DocumentFragment} or a {@link module:engine/model/node~Node}
|
|
27
|
+
* that can be either a text node or an element. This method can be used to check what kind of object is returned.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* someObject.is( 'element' ); // -> true if this is an element
|
|
31
|
+
* someObject.is( 'node' ); // -> true if this is a node (a text node or an element)
|
|
32
|
+
* someObject.is( 'documentFragment' ); // -> true if this is a document fragment
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Since this method is also available on a range of view objects, you can prefix the type of the object with
|
|
36
|
+
* `model:` or `view:` to check, for example, if this is the model's or view's element:
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* modelElement.is( 'model:element' ); // -> true
|
|
40
|
+
* modelElement.is( 'view:element' ); // -> false
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* By using this method it is also possible to check a name of an element:
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* imageElement.is( 'element', 'imageBlock' ); // -> true
|
|
47
|
+
* imageElement.is( 'element', 'imageBlock' ); // -> same as above
|
|
48
|
+
* imageElement.is( 'model:element', 'imageBlock' ); // -> same as above, but more precise
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @label NODE
|
|
52
|
+
*/
|
|
53
|
+
is(type: 'node' | 'model:node'): this is Node | Element | Text | RootElement;
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether the object is of type {@link module:engine/model/element~Element} or its subclass.
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* element.is( 'element' ); // -> true
|
|
59
|
+
* element.is( 'node' ); // -> true
|
|
60
|
+
* element.is( 'model:element' ); // -> true
|
|
61
|
+
* element.is( 'model:node' ); // -> true
|
|
62
|
+
*
|
|
63
|
+
* element.is( 'view:element' ); // -> false
|
|
64
|
+
* element.is( 'documentSelection' ); // -> false
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Assuming that the object being checked is an element, you can also check its
|
|
68
|
+
* {@link module:engine/model/element~Element#name name}:
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element
|
|
72
|
+
* text.is( 'element', 'imageBlock' ); -> false
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @label ELEMENT
|
|
76
|
+
*/
|
|
77
|
+
is(type: 'element' | 'model:element'): this is Element | RootElement;
|
|
78
|
+
/**
|
|
79
|
+
* Checks whether the object is of type {@link module:engine/model/rootelement~RootElement}.
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* rootElement.is( 'rootElement' ); // -> true
|
|
83
|
+
* rootElement.is( 'element' ); // -> true
|
|
84
|
+
* rootElement.is( 'node' ); // -> true
|
|
85
|
+
* rootElement.is( 'model:rootElement' ); // -> true
|
|
86
|
+
* rootElement.is( 'model:element' ); // -> true
|
|
87
|
+
* rootElement.is( 'model:node' ); // -> true
|
|
88
|
+
*
|
|
89
|
+
* rootElement.is( 'view:element' ); // -> false
|
|
90
|
+
* rootElement.is( 'documentFragment' ); // -> false
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* Assuming that the object being checked is an element, you can also check its
|
|
94
|
+
* {@link module:engine/model/element~Element#name name}:
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* rootElement.is( 'rootElement', '$root' ); // -> same as above
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @label ROOT_ELEMENT
|
|
101
|
+
*/
|
|
102
|
+
is(type: 'rootElement' | 'model:rootElement'): this is RootElement;
|
|
103
|
+
/**
|
|
104
|
+
* Checks whether the object is of type {@link module:engine/model/text~Text}.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* text.is( '$text' ); // -> true
|
|
108
|
+
* text.is( 'node' ); // -> true
|
|
109
|
+
* text.is( 'model:$text' ); // -> true
|
|
110
|
+
* text.is( 'model:node' ); // -> true
|
|
111
|
+
*
|
|
112
|
+
* text.is( 'view:$text' ); // -> false
|
|
113
|
+
* text.is( 'documentSelection' ); // -> false
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* **Note:** Until version 20.0.0 this method wasn't accepting `'$text'` type. The legacy `'text'` type is still
|
|
117
|
+
* accepted for backward compatibility.
|
|
118
|
+
*
|
|
119
|
+
* @label TEXT
|
|
120
|
+
*/
|
|
121
|
+
is(type: '$text' | 'model:$text'): this is Text;
|
|
122
|
+
/**
|
|
123
|
+
* Checks whether the object is of type {@link module:engine/model/position~Position} or its subclass.
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* position.is( 'position' ); // -> true
|
|
127
|
+
* position.is( 'model:position' ); // -> true
|
|
128
|
+
*
|
|
129
|
+
* position.is( 'view:position' ); // -> false
|
|
130
|
+
* position.is( 'documentSelection' ); // -> false
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @label POSITION
|
|
134
|
+
*/
|
|
135
|
+
is(type: 'position' | 'model:position'): this is Position | LivePosition;
|
|
136
|
+
/**
|
|
137
|
+
* Checks whether the object is of type {@link module:engine/model/liveposition~LivePosition}.
|
|
138
|
+
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* livePosition.is( 'position' ); // -> true
|
|
141
|
+
* livePosition.is( 'model:position' ); // -> true
|
|
142
|
+
* livePosition.is( 'liveposition' ); // -> true
|
|
143
|
+
* livePosition.is( 'model:livePosition' ); // -> true
|
|
144
|
+
*
|
|
145
|
+
* livePosition.is( 'view:position' ); // -> false
|
|
146
|
+
* livePosition.is( 'documentSelection' ); // -> false
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @label LIVE_POSITION
|
|
150
|
+
*/
|
|
151
|
+
is(type: 'livePosition' | 'model:livePosition'): this is LivePosition;
|
|
152
|
+
/**
|
|
153
|
+
* Checks whether the object is of type {@link module:engine/model/range~Range} or its subclass.
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* range.is( 'range' ); // -> true
|
|
157
|
+
* range.is( 'model:range' ); // -> true
|
|
158
|
+
*
|
|
159
|
+
* range.is( 'view:range' ); // -> false
|
|
160
|
+
* range.is( 'documentSelection' ); // -> false
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @label RANGE
|
|
164
|
+
*/
|
|
165
|
+
is(type: 'range' | 'model:range'): this is Range | LiveRange;
|
|
166
|
+
/**
|
|
167
|
+
* Checks whether the object is of type {@link module:engine/model/liverange~LiveRange}.
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* liveRange.is( 'range' ); // -> true
|
|
171
|
+
* liveRange.is( 'model:range' ); // -> true
|
|
172
|
+
* liveRange.is( 'liveRange' ); // -> true
|
|
173
|
+
* liveRange.is( 'model:liveRange' ); // -> true
|
|
174
|
+
*
|
|
175
|
+
* liveRange.is( 'view:range' ); // -> false
|
|
176
|
+
* liveRange.is( 'documentSelection' ); // -> false
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @label LIVE_RANGE
|
|
180
|
+
*/
|
|
181
|
+
is(type: 'liveRange' | 'model:liveRange'): this is LiveRange;
|
|
182
|
+
/**
|
|
183
|
+
* Checks whether the object is of type {@link module:engine/model/documentfragment~DocumentFragment}.
|
|
184
|
+
*
|
|
185
|
+
* ```ts
|
|
186
|
+
* docFrag.is( 'documentFragment' ); // -> true
|
|
187
|
+
* docFrag.is( 'model:documentFragment' ); // -> true
|
|
188
|
+
*
|
|
189
|
+
* docFrag.is( 'view:documentFragment' ); // -> false
|
|
190
|
+
* docFrag.is( 'element' ); // -> false
|
|
191
|
+
* docFrag.is( 'node' ); // -> false
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* @label DOCUMENT_FRAGMENT
|
|
195
|
+
*/
|
|
196
|
+
is(type: 'documentFragment' | 'model:documentFragment'): this is DocumentFragment;
|
|
197
|
+
/**
|
|
198
|
+
* Checks whether the object is of type {@link module:engine/model/selection~Selection}
|
|
199
|
+
* or {@link module:engine/model/documentselection~DocumentSelection}.
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* selection.is( 'selection' ); // -> true
|
|
203
|
+
* selection.is( 'model:selection' ); // -> true
|
|
204
|
+
*
|
|
205
|
+
* selection.is( 'view:selection' ); // -> false
|
|
206
|
+
* selection.is( 'range' ); // -> false
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @label SELECTION
|
|
210
|
+
*/
|
|
211
|
+
is(type: 'selection' | 'model:selection'): this is Selection | DocumentSelection;
|
|
212
|
+
/**
|
|
213
|
+
* Checks whether the object is of type {@link module:engine/model/documentselection~DocumentSelection}.
|
|
214
|
+
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* selection.is( 'selection' ); // -> true
|
|
217
|
+
* selection.is( 'documentSelection' ); // -> true
|
|
218
|
+
* selection.is( 'model:selection' ); // -> true
|
|
219
|
+
* selection.is( 'model:documentSelection' ); // -> true
|
|
220
|
+
*
|
|
221
|
+
* selection.is( 'view:selection' ); // -> false
|
|
222
|
+
* selection.is( 'element' ); // -> false
|
|
223
|
+
* selection.is( 'node' ); // -> false
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @label DOCUMENT_SELECTION
|
|
227
|
+
*/
|
|
228
|
+
is(type: 'documentSelection' | 'model:documentSelection'): this is DocumentSelection;
|
|
229
|
+
/**
|
|
230
|
+
* Checks whether the object is of type {@link module:engine/model/markercollection~Marker}.
|
|
231
|
+
*
|
|
232
|
+
* ```ts
|
|
233
|
+
* marker.is( 'marker' ); // -> true
|
|
234
|
+
* marker.is( 'model:marker' ); // -> true
|
|
235
|
+
*
|
|
236
|
+
* marker.is( 'view:element' ); // -> false
|
|
237
|
+
* marker.is( 'documentSelection' ); // -> false
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @label MARKER
|
|
241
|
+
*/
|
|
242
|
+
is(type: 'marker' | 'model:marker'): this is Marker;
|
|
243
|
+
/**
|
|
244
|
+
* Checks whether the object is of type {@link module:engine/model/textproxy~TextProxy}.
|
|
245
|
+
*
|
|
246
|
+
* ```ts
|
|
247
|
+
* textProxy.is( '$textProxy' ); // -> true
|
|
248
|
+
* textProxy.is( 'model:$textProxy' ); // -> true
|
|
249
|
+
*
|
|
250
|
+
* textProxy.is( 'view:$textProxy' ); // -> false
|
|
251
|
+
* textProxy.is( 'range' ); // -> false
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* **Note:** Until version 20.0.0 this method wasn't accepting `'$textProxy'` type. The legacy `'textProxt'` type is still
|
|
255
|
+
* accepted for backward compatibility.
|
|
256
|
+
*
|
|
257
|
+
* @label TEXT_PROXY
|
|
258
|
+
*/
|
|
259
|
+
is(type: '$textProxy' | 'model:$textProxy'): this is TextProxy;
|
|
260
|
+
/**
|
|
261
|
+
* Checks whether the object is of type {@link module:engine/model/element~Element} or its subclass and has the specified `name`.
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element
|
|
265
|
+
* text.is( 'element', 'imageBlock' ); -> false
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @label ELEMENT_NAME
|
|
269
|
+
*/
|
|
270
|
+
is<N extends string>(type: 'element' | 'model:element', name: N): this is (Element | RootElement) & {
|
|
271
|
+
name: N;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Checks whether the object is of type {@link module:engine/model/rootelement~RootElement} and has the specified `name`.
|
|
275
|
+
*
|
|
276
|
+
* ```ts
|
|
277
|
+
* rootElement.is( 'rootElement', '$root' );
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @label ROOT_ELEMENT_NAME
|
|
281
|
+
*/
|
|
282
|
+
is<N extends string>(type: 'rootElement' | 'model:rootElement', name: N): this is RootElement & {
|
|
283
|
+
name: N;
|
|
284
|
+
};
|
|
285
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import type Node from '../node.js';
|
|
6
|
+
import type Position from '../position.js';
|
|
7
|
+
import type Schema from '../schema.js';
|
|
8
|
+
import type Writer from '../writer.js';
|
|
9
|
+
/**
|
|
10
|
+
* @module engine/model/utils/autoparagraphing
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Fixes all empty roots.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
* @param writer The model writer.
|
|
17
|
+
* @returns `true` if any change has been applied, `false` otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function autoParagraphEmptyRoots(writer: Writer): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the given node wrapped with a paragraph would be accepted by the schema in the given position.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
* @param position The position at which to check.
|
|
25
|
+
* @param nodeOrType The child node or child type to check.
|
|
26
|
+
* @param schema A schema instance used for element validation.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isParagraphable(position: Position, nodeOrType: Node | string, schema: Schema): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Inserts a new paragraph at the given position and returns a position inside that paragraph.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
* @param position The position where a paragraph should be inserted.
|
|
34
|
+
* @param writer The model writer.
|
|
35
|
+
* @returns Position inside the created paragraph.
|
|
36
|
+
*/
|
|
37
|
+
export declare function wrapInParagraph(position: Position, writer: Writer): Position;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/model/utils/deletecontent
|
|
7
|
+
*/
|
|
8
|
+
import DocumentSelection from '../documentselection.js';
|
|
9
|
+
import type Model from '../model.js';
|
|
10
|
+
import type Selection from '../selection.js';
|
|
11
|
+
/**
|
|
12
|
+
* Deletes content of the selection and merge siblings. The resulting selection is always collapsed.
|
|
13
|
+
*
|
|
14
|
+
* **Note:** Use {@link module:engine/model/model~Model#deleteContent} instead of this function.
|
|
15
|
+
* This function is only exposed to be reusable in algorithms
|
|
16
|
+
* which change the {@link module:engine/model/model~Model#deleteContent}
|
|
17
|
+
* method's behavior.
|
|
18
|
+
*
|
|
19
|
+
* @param model The model in context of which the insertion should be performed.
|
|
20
|
+
* @param selection Selection of which the content should be deleted.
|
|
21
|
+
* @param options.leaveUnmerged Whether to merge elements after removing the content of the selection.
|
|
22
|
+
*
|
|
23
|
+
* For example `<heading>x[x</heading><paragraph>y]y</paragraph>` will become:
|
|
24
|
+
*
|
|
25
|
+
* * `<heading>x^y</heading>` with the option disabled (`leaveUnmerged == false`)
|
|
26
|
+
* * `<heading>x^</heading><paragraph>y</paragraph>` with enabled (`leaveUnmerged == true`).
|
|
27
|
+
*
|
|
28
|
+
* Note: {@link module:engine/model/schema~Schema#isObject object} and {@link module:engine/model/schema~Schema#isLimit limit}
|
|
29
|
+
* elements will not be merged.
|
|
30
|
+
*
|
|
31
|
+
* @param options.doNotResetEntireContent Whether to skip replacing the entire content with a
|
|
32
|
+
* paragraph when the entire content was selected.
|
|
33
|
+
*
|
|
34
|
+
* For example `<heading>[x</heading><paragraph>y]</paragraph>` will become:
|
|
35
|
+
*
|
|
36
|
+
* * `<paragraph>^</paragraph>` with the option disabled (`doNotResetEntireContent == false`)
|
|
37
|
+
* * `<heading>^</heading>` with enabled (`doNotResetEntireContent == true`).
|
|
38
|
+
*
|
|
39
|
+
* @param options.doNotAutoparagraph Whether to create a paragraph if after content deletion selection is moved
|
|
40
|
+
* to a place where text cannot be inserted.
|
|
41
|
+
*
|
|
42
|
+
* For example `<paragraph>x</paragraph>[<imageBlock src="foo.jpg"></imageBlock>]` will become:
|
|
43
|
+
*
|
|
44
|
+
* * `<paragraph>x</paragraph><paragraph>[]</paragraph>` with the option disabled (`doNotAutoparagraph == false`)
|
|
45
|
+
* * `<paragraph>x</paragraph>[]` with the option enabled (`doNotAutoparagraph == true`).
|
|
46
|
+
*
|
|
47
|
+
* If you use this option you need to make sure to handle invalid selections yourself or leave
|
|
48
|
+
* them to the selection post-fixer (may not always work).
|
|
49
|
+
*
|
|
50
|
+
* **Note:** If there is no valid position for the selection, the paragraph will always be created:
|
|
51
|
+
*
|
|
52
|
+
* `[<imageBlock src="foo.jpg"></imageBlock>]` -> `<paragraph>[]</paragraph>`.
|
|
53
|
+
*/
|
|
54
|
+
export default function deleteContent(model: Model, selection: Selection | DocumentSelection, options?: {
|
|
55
|
+
leaveUnmerged?: boolean;
|
|
56
|
+
doNotResetEntireContent?: boolean;
|
|
57
|
+
doNotAutoparagraph?: boolean;
|
|
58
|
+
}): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import type DocumentFragment from '../documentfragment.js';
|
|
6
|
+
import type DocumentSelection from '../documentselection.js';
|
|
7
|
+
import type Model from '../model.js';
|
|
8
|
+
import type Selection from '../selection.js';
|
|
9
|
+
/**
|
|
10
|
+
* @module engine/model/utils/getselectedcontent
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Gets a clone of the selected content.
|
|
14
|
+
*
|
|
15
|
+
* For example, for the following selection:
|
|
16
|
+
*
|
|
17
|
+
* ```html
|
|
18
|
+
* <p>x</p><quote><p>y</p><h>fir[st</h></quote><p>se]cond</p><p>z</p>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* It will return a document fragment with such a content:
|
|
22
|
+
*
|
|
23
|
+
* ```html
|
|
24
|
+
* <quote><h>st</h></quote><p>se</p>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param model The model in context of which the selection modification should be performed.
|
|
28
|
+
* @param selection The selection of which content will be returned.
|
|
29
|
+
*/
|
|
30
|
+
export default function getSelectedContent(model: Model, selection: Selection | DocumentSelection): DocumentFragment;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/model/utils/insertcontent
|
|
7
|
+
*/
|
|
8
|
+
import DocumentSelection from '../documentselection.js';
|
|
9
|
+
import Range from '../range.js';
|
|
10
|
+
import type DocumentFragment from '../documentfragment.js';
|
|
11
|
+
import type Item from '../item.js';
|
|
12
|
+
import type Model from '../model.js';
|
|
13
|
+
import type Selection from '../selection.js';
|
|
14
|
+
/**
|
|
15
|
+
* Inserts content into the editor (specified selection) as one would expect the paste functionality to work.
|
|
16
|
+
*
|
|
17
|
+
* It takes care of removing the selected content, splitting elements (if needed), inserting elements and merging elements appropriately.
|
|
18
|
+
*
|
|
19
|
+
* Some examples:
|
|
20
|
+
*
|
|
21
|
+
* ```html
|
|
22
|
+
* <p>x^</p> + <p>y</p> => <p>x</p><p>y</p> => <p>xy[]</p>
|
|
23
|
+
* <p>x^y</p> + <p>z</p> => <p>x</p>^<p>y</p> + <p>z</p> => <p>x</p><p>z</p><p>y</p> => <p>xz[]y</p>
|
|
24
|
+
* <p>x^y</p> + <img /> => <p>x</p>^<p>y</p> + <img /> => <p>x</p><img /><p>y</p>
|
|
25
|
+
* <p>x</p><p>^</p><p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p> (no merging)
|
|
26
|
+
* <p>x</p>[<img />]<p>z</p> + <p>y</p> => <p>x</p>^<p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* If an instance of {@link module:engine/model/selection~Selection} is passed as `selectable` it will be modified
|
|
30
|
+
* to the insertion selection (equal to a range to be selected after insertion).
|
|
31
|
+
*
|
|
32
|
+
* If `selectable` is not passed, the content will be inserted using the current selection of the model document.
|
|
33
|
+
*
|
|
34
|
+
* **Note:** Use {@link module:engine/model/model~Model#insertContent} instead of this function.
|
|
35
|
+
* This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertContent}
|
|
36
|
+
* method's behavior.
|
|
37
|
+
*
|
|
38
|
+
* @param model The model in context of which the insertion should be performed.
|
|
39
|
+
* @param content The content to insert.
|
|
40
|
+
* @param selectable Selection into which the content should be inserted.
|
|
41
|
+
* @param placeOrOffset Sets place or offset of the selection.
|
|
42
|
+
* @returns Range which contains all the performed changes. This is a range that, if removed,
|
|
43
|
+
* would return the model to the state before the insertion. If no changes were preformed by `insertContent`, returns a range collapsed
|
|
44
|
+
* at the insertion position.
|
|
45
|
+
*/
|
|
46
|
+
export default function insertContent(model: Model, content: Item | DocumentFragment, selectable?: Selection | DocumentSelection): Range;
|