@ckeditor/ckeditor5-engine 45.2.1 → 46.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2563 -2257
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/controller/datacontroller.d.ts +33 -32
- package/src/controller/datacontroller.js +29 -28
- package/src/controller/editingcontroller.d.ts +8 -8
- package/src/controller/editingcontroller.js +10 -10
- package/src/conversion/conversion.d.ts +18 -19
- package/src/conversion/conversion.js +4 -4
- package/src/conversion/conversionhelpers.d.ts +1 -1
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.d.ts +63 -69
- package/src/conversion/downcastdispatcher.js +16 -16
- package/src/conversion/downcasthelpers.d.ts +94 -83
- package/src/conversion/downcasthelpers.js +63 -53
- package/src/conversion/mapper.d.ts +27 -27
- package/src/conversion/mapper.js +15 -15
- package/src/conversion/modelconsumable.d.ts +26 -26
- package/src/conversion/modelconsumable.js +23 -23
- package/src/conversion/upcastdispatcher.d.ts +33 -32
- package/src/conversion/upcastdispatcher.js +19 -19
- package/src/conversion/upcasthelpers.d.ts +46 -38
- package/src/conversion/upcasthelpers.js +33 -24
- package/src/conversion/viewconsumable.d.ts +50 -45
- package/src/conversion/viewconsumable.js +32 -27
- package/src/dataprocessor/basichtmlwriter.d.ts +4 -2
- package/src/dataprocessor/basichtmlwriter.js +3 -1
- package/src/dataprocessor/dataprocessor.d.ts +7 -6
- package/src/dataprocessor/htmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/htmldataprocessor.js +6 -6
- package/src/dataprocessor/htmlwriter.d.ts +1 -1
- package/src/dataprocessor/xmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/xmldataprocessor.js +6 -6
- package/src/dev-utils/model.d.ts +25 -26
- package/src/dev-utils/model.js +35 -36
- package/src/dev-utils/operationreplayer.d.ts +5 -3
- package/src/dev-utils/operationreplayer.js +4 -2
- package/src/dev-utils/utils.d.ts +8 -0
- package/src/dev-utils/utils.js +8 -0
- package/src/dev-utils/view.d.ts +66 -63
- package/src/dev-utils/view.js +144 -134
- package/src/index.d.ts +135 -106
- package/src/index.js +120 -71
- package/src/legacyerrors.d.ts +5 -0
- package/src/legacyerrors.js +17 -0
- package/src/model/batch.d.ts +2 -15
- package/src/model/batch.js +1 -23
- package/src/model/differ.d.ts +54 -31
- package/src/model/differ.js +15 -15
- package/src/model/document.d.ts +31 -31
- package/src/model/document.js +13 -13
- package/src/model/documentfragment.d.ts +45 -45
- package/src/model/documentfragment.js +40 -40
- package/src/model/documentselection.d.ts +92 -92
- package/src/model/documentselection.js +71 -70
- package/src/model/element.d.ts +31 -31
- package/src/model/element.js +29 -29
- package/src/model/history.d.ts +3 -3
- package/src/model/history.js +2 -2
- package/src/model/item.d.ts +4 -5
- package/src/model/liveposition.d.ts +31 -31
- package/src/model/liveposition.js +18 -18
- package/src/model/liverange.d.ts +42 -38
- package/src/model/liverange.js +17 -16
- package/src/model/markercollection.d.ts +41 -40
- package/src/model/markercollection.js +22 -20
- package/src/model/model.d.ts +82 -81
- package/src/model/model.js +54 -54
- package/src/model/node.d.ts +48 -48
- package/src/model/node.js +31 -31
- package/src/model/nodelist.d.ts +17 -17
- package/src/model/nodelist.js +11 -11
- package/src/model/operation/attributeoperation.d.ts +10 -10
- package/src/model/operation/attributeoperation.js +7 -7
- package/src/model/operation/detachoperation.d.ts +11 -9
- package/src/model/operation/detachoperation.js +8 -6
- package/src/model/operation/insertoperation.d.ts +13 -13
- package/src/model/operation/insertoperation.js +15 -15
- package/src/model/operation/markeroperation.d.ts +12 -12
- package/src/model/operation/markeroperation.js +5 -5
- package/src/model/operation/mergeoperation.d.ts +16 -16
- package/src/model/operation/mergeoperation.js +18 -18
- package/src/model/operation/moveoperation.d.ts +16 -16
- package/src/model/operation/moveoperation.js +18 -15
- package/src/model/operation/nooperation.d.ts +4 -4
- package/src/model/operation/nooperation.js +2 -2
- package/src/model/operation/operation.d.ts +10 -10
- package/src/model/operation/operation.js +5 -5
- package/src/model/operation/operationfactory.d.ts +4 -4
- package/src/model/operation/operationfactory.js +12 -12
- package/src/model/operation/renameoperation.d.ts +10 -10
- package/src/model/operation/renameoperation.js +7 -7
- package/src/model/operation/rootattributeoperation.d.ts +12 -12
- package/src/model/operation/rootattributeoperation.js +8 -8
- package/src/model/operation/rootoperation.d.ts +8 -8
- package/src/model/operation/rootoperation.js +3 -3
- package/src/model/operation/splitoperation.d.ts +17 -17
- package/src/model/operation/splitoperation.js +19 -19
- package/src/model/operation/transform.d.ts +11 -8
- package/src/model/operation/transform.js +66 -49
- package/src/model/operation/utils.d.ts +24 -23
- package/src/model/operation/utils.js +20 -20
- package/src/model/position.d.ts +101 -97
- package/src/model/position.js +69 -64
- package/src/model/range.d.ts +90 -90
- package/src/model/range.js +87 -87
- package/src/model/rootelement.d.ts +11 -11
- package/src/model/rootelement.js +9 -9
- package/src/model/schema.d.ts +158 -154
- package/src/model/schema.js +93 -90
- package/src/model/selection.d.ts +73 -73
- package/src/model/selection.js +62 -62
- package/src/model/text.d.ts +11 -10
- package/src/model/text.js +11 -10
- package/src/model/textproxy.d.ts +39 -38
- package/src/model/textproxy.js +31 -30
- package/src/model/treewalker.d.ts +37 -37
- package/src/model/treewalker.js +14 -14
- package/src/model/typecheckable.d.ts +45 -45
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.d.ts +7 -7
- package/src/model/utils/deletecontent.d.ts +7 -5
- package/src/model/utils/deletecontent.js +13 -11
- package/src/model/utils/getselectedcontent.d.ts +6 -5
- package/src/model/utils/getselectedcontent.js +2 -1
- package/src/model/utils/insertcontent.d.ts +9 -8
- package/src/model/utils/insertcontent.js +41 -40
- package/src/model/utils/insertobject.d.ts +9 -9
- package/src/model/utils/insertobject.js +4 -4
- package/src/model/utils/modifyselection.d.ts +5 -4
- package/src/model/utils/modifyselection.js +12 -11
- package/src/model/utils/selection-post-fixer.d.ts +12 -8
- package/src/model/utils/selection-post-fixer.js +15 -11
- package/src/model/writer.d.ts +102 -101
- package/src/model/writer.js +99 -98
- package/src/view/attributeelement.d.ts +29 -29
- package/src/view/attributeelement.js +25 -25
- package/src/view/containerelement.d.ts +16 -15
- package/src/view/containerelement.js +15 -14
- package/src/view/datatransfer.d.ts +7 -7
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.d.ts +25 -25
- package/src/view/document.js +15 -15
- package/src/view/documentfragment.d.ts +21 -21
- package/src/view/documentfragment.js +14 -14
- package/src/view/documentselection.d.ts +65 -63
- package/src/view/documentselection.js +27 -25
- package/src/view/domconverter.d.ts +94 -89
- package/src/view/domconverter.js +78 -73
- package/src/view/downcastwriter.d.ts +185 -181
- package/src/view/downcastwriter.js +222 -210
- package/src/view/editableelement.d.ts +13 -13
- package/src/view/editableelement.js +8 -8
- package/src/view/element.d.ts +75 -74
- package/src/view/element.js +58 -58
- package/src/view/elementdefinition.d.ts +3 -4
- package/src/view/emptyelement.d.ts +13 -13
- package/src/view/emptyelement.js +13 -13
- package/src/view/filler.d.ts +14 -3
- package/src/view/filler.js +12 -1
- package/src/view/item.d.ts +4 -5
- package/src/view/matcher.d.ts +22 -19
- package/src/view/matcher.js +6 -6
- package/src/view/node.d.ts +33 -33
- package/src/view/node.js +9 -9
- package/src/view/observer/arrowkeysobserver.d.ts +10 -10
- package/src/view/observer/arrowkeysobserver.js +5 -5
- package/src/view/observer/bubblingemittermixin.d.ts +5 -5
- package/src/view/observer/bubblingemittermixin.js +2 -9
- package/src/view/observer/bubblingeventinfo.d.ts +9 -9
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.d.ts +8 -8
- package/src/view/observer/clickobserver.js +4 -4
- package/src/view/observer/compositionobserver.d.ts +19 -19
- package/src/view/observer/compositionobserver.js +6 -6
- package/src/view/observer/domeventdata.d.ts +9 -9
- package/src/view/observer/domeventdata.js +2 -2
- package/src/view/observer/domeventobserver.d.ts +3 -3
- package/src/view/observer/domeventobserver.js +5 -5
- package/src/view/observer/fakeselectionobserver.d.ts +9 -9
- package/src/view/observer/fakeselectionobserver.js +8 -8
- package/src/view/observer/focusobserver.d.ts +16 -16
- package/src/view/observer/focusobserver.js +7 -7
- package/src/view/observer/inputobserver.d.ts +18 -18
- package/src/view/observer/inputobserver.js +5 -5
- package/src/view/observer/keyobserver.d.ts +11 -11
- package/src/view/observer/keyobserver.js +3 -3
- package/src/view/observer/mouseobserver.d.ts +16 -16
- package/src/view/observer/mouseobserver.js +3 -3
- package/src/view/observer/mutationobserver.d.ts +21 -21
- package/src/view/observer/mutationobserver.js +7 -7
- package/src/view/observer/observer.d.ts +12 -12
- package/src/view/observer/observer.js +6 -6
- package/src/view/observer/selectionobserver.d.ts +33 -33
- package/src/view/observer/selectionobserver.js +14 -14
- package/src/view/observer/tabobserver.d.ts +10 -10
- package/src/view/observer/tabobserver.js +5 -5
- package/src/view/observer/touchobserver.d.ts +13 -13
- package/src/view/observer/touchobserver.js +3 -3
- package/src/view/placeholder.d.ts +21 -21
- package/src/view/placeholder.js +23 -23
- package/src/view/position.d.ts +49 -49
- package/src/view/position.js +42 -42
- package/src/view/range.d.ts +76 -74
- package/src/view/range.js +67 -65
- package/src/view/rawelement.d.ts +19 -19
- package/src/view/rawelement.js +16 -16
- package/src/view/renderer.d.ts +14 -14
- package/src/view/renderer.js +7 -7
- package/src/view/rooteditableelement.d.ts +8 -7
- package/src/view/rooteditableelement.js +7 -6
- package/src/view/selection.d.ts +66 -64
- package/src/view/selection.js +50 -48
- package/src/view/styles/background.d.ts +2 -2
- package/src/view/styles/background.js +9 -9
- package/src/view/styles/border.d.ts +2 -2
- package/src/view/styles/border.js +13 -13
- package/src/view/styles/margin.d.ts +2 -2
- package/src/view/styles/margin.js +5 -5
- package/src/view/styles/padding.d.ts +2 -2
- package/src/view/styles/padding.js +5 -5
- package/src/view/styles/utils.d.ts +24 -24
- package/src/view/styles/utils.js +25 -25
- package/src/view/stylesmap.d.ts +28 -32
- package/src/view/stylesmap.js +52 -39
- package/src/view/text.d.ts +11 -11
- package/src/view/text.js +10 -10
- package/src/view/textproxy.d.ts +33 -32
- package/src/view/textproxy.js +23 -22
- package/src/view/tokenlist.d.ts +14 -14
- package/src/view/tokenlist.js +10 -10
- package/src/view/treewalker.d.ts +42 -40
- package/src/view/treewalker.js +36 -35
- package/src/view/typecheckable.d.ts +76 -75
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.d.ts +22 -21
- package/src/view/uielement.js +17 -16
- package/src/view/upcastwriter.d.ts +70 -70
- package/src/view/upcastwriter.js +42 -42
- package/src/view/view.d.ts +70 -69
- package/src/view/view.js +56 -55
package/src/model/schema.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/schema
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
8
|
+
import { ModelElement } from './element.js';
|
|
9
|
+
import { ModelPosition } from './position.js';
|
|
10
|
+
import { ModelRange } from './range.js';
|
|
11
|
+
import { ModelText } from './text.js';
|
|
12
|
+
import { ModelTreeWalker } from './treewalker.js';
|
|
13
13
|
import { CKEditorError, first, ObservableMixin } from '@ckeditor/ckeditor5-utils';
|
|
14
14
|
/**
|
|
15
15
|
* The model's schema. It defines the allowed and disallowed structures of nodes as well as nodes' attributes.
|
|
@@ -24,27 +24,28 @@ import { CKEditorError, first, ObservableMixin } from '@ckeditor/ckeditor5-utils
|
|
|
24
24
|
* {@glink framework/architecture/editing-engine Introduction to the Editing engine architecture} guide.
|
|
25
25
|
* * The {@glink framework/deep-dive/schema Schema deep-dive} guide.
|
|
26
26
|
*/
|
|
27
|
-
export
|
|
27
|
+
export class ModelSchema extends /* #__PURE__ */ ObservableMixin() {
|
|
28
28
|
_sourceDefinitions = {};
|
|
29
29
|
/**
|
|
30
30
|
* A dictionary containing attribute properties.
|
|
31
31
|
*/
|
|
32
32
|
_attributeProperties = Object.create(null);
|
|
33
33
|
/**
|
|
34
|
-
* Stores additional callbacks registered for schema items, which are evaluated when {@link ~
|
|
34
|
+
* Stores additional callbacks registered for schema items, which are evaluated when {@link ~ModelSchema#checkChild} is called.
|
|
35
35
|
*
|
|
36
36
|
* Keys are schema item names for which the callbacks are registered. Values are arrays with the callbacks.
|
|
37
37
|
*
|
|
38
|
-
* Some checks are added under {@link ~
|
|
38
|
+
* Some checks are added under {@link ~ModelSchema#_genericCheckSymbol} key, these are
|
|
39
|
+
* evaluated for every {@link ~ModelSchema#checkChild} call.
|
|
39
40
|
*/
|
|
40
41
|
_customChildChecks = new Map();
|
|
41
42
|
/**
|
|
42
|
-
* Stores additional callbacks registered for attribute names, which are evaluated when {@link ~
|
|
43
|
+
* Stores additional callbacks registered for attribute names, which are evaluated when {@link ~ModelSchema#checkAttribute} is called.
|
|
43
44
|
*
|
|
44
45
|
* Keys are schema attribute names for which the callbacks are registered. Values are arrays with the callbacks.
|
|
45
46
|
*
|
|
46
|
-
* Some checks are added under {@link ~
|
|
47
|
-
* {@link ~
|
|
47
|
+
* Some checks are added under {@link ~ModelSchema#_genericCheckSymbol} key, these are evaluated for every
|
|
48
|
+
* {@link ~ModelSchema#checkAttribute} call.
|
|
48
49
|
*/
|
|
49
50
|
_customAttributeChecks = new Map();
|
|
50
51
|
_genericCheckSymbol = Symbol('$generic');
|
|
@@ -57,10 +58,10 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
57
58
|
this.decorate('checkChild');
|
|
58
59
|
this.decorate('checkAttribute');
|
|
59
60
|
this.on('checkAttribute', (evt, args) => {
|
|
60
|
-
args[0] = new
|
|
61
|
+
args[0] = new ModelSchemaContext(args[0]);
|
|
61
62
|
}, { priority: 'highest' });
|
|
62
63
|
this.on('checkChild', (evt, args) => {
|
|
63
|
-
args[0] = new
|
|
64
|
+
args[0] = new ModelSchemaContext(args[0]);
|
|
64
65
|
args[1] = this.getDefinition(args[1]);
|
|
65
66
|
}, { priority: 'highest' });
|
|
66
67
|
}
|
|
@@ -80,7 +81,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
80
81
|
*
|
|
81
82
|
* This situation may happen when:
|
|
82
83
|
*
|
|
83
|
-
* * Two or more plugins called {@link module:engine/model/schema~
|
|
84
|
+
* * Two or more plugins called {@link module:engine/model/schema~ModelSchema#register `register()`} with the same name.
|
|
84
85
|
* This will usually mean that there is a collision between plugins which try to use the same element in the model.
|
|
85
86
|
* Unfortunately, the only way to solve this is by modifying one of these plugins to use a unique model element name.
|
|
86
87
|
* * A single plugin was loaded twice. This happens when it is installed by npm/yarn in two versions
|
|
@@ -132,7 +133,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
132
133
|
* Cannot extend an item which was not registered yet.
|
|
133
134
|
*
|
|
134
135
|
* This error happens when a plugin tries to extend the schema definition of an item which was not
|
|
135
|
-
* {@link module:engine/model/schema~
|
|
136
|
+
* {@link module:engine/model/schema~ModelSchema#register registered} yet.
|
|
136
137
|
*
|
|
137
138
|
* @param itemName The name of the model element which is being extended.
|
|
138
139
|
* @error schema-cannot-extend-missing-item
|
|
@@ -174,7 +175,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
174
175
|
else if ('is' in item && (item.is('$text') || item.is('$textProxy'))) {
|
|
175
176
|
itemName = '$text';
|
|
176
177
|
}
|
|
177
|
-
// Element or module:engine/model/schema~
|
|
178
|
+
// Element or module:engine/model/schema~ModelSchemaContextItem.
|
|
178
179
|
else {
|
|
179
180
|
itemName = item.name;
|
|
180
181
|
}
|
|
@@ -194,7 +195,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
194
195
|
}
|
|
195
196
|
/**
|
|
196
197
|
* Returns `true` if the given item is defined to be
|
|
197
|
-
* a block by the {@link module:engine/model/schema~
|
|
198
|
+
* a block by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isBlock` property.
|
|
198
199
|
*
|
|
199
200
|
* ```ts
|
|
200
201
|
* schema.isBlock( 'paragraph' ); // -> true
|
|
@@ -215,9 +216,9 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
215
216
|
* Returns `true` if the given item should be treated as a limit element.
|
|
216
217
|
*
|
|
217
218
|
* It considers an item to be a limit element if its
|
|
218
|
-
* {@link module:engine/model/schema~
|
|
219
|
-
* {@link module:engine/model/schema~
|
|
220
|
-
* {@link module:engine/model/schema~
|
|
219
|
+
* {@link module:engine/model/schema~ModelSchemaItemDefinition}'s
|
|
220
|
+
* {@link module:engine/model/schema~ModelSchemaItemDefinition#isLimit `isLimit`} or
|
|
221
|
+
* {@link module:engine/model/schema~ModelSchemaItemDefinition#isObject `isObject`} property
|
|
221
222
|
* was set to `true`.
|
|
222
223
|
*
|
|
223
224
|
* ```ts
|
|
@@ -241,8 +242,8 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
241
242
|
* Returns `true` if the given item should be treated as an object element.
|
|
242
243
|
*
|
|
243
244
|
* It considers an item to be an object element if its
|
|
244
|
-
* {@link module:engine/model/schema~
|
|
245
|
-
* {@link module:engine/model/schema~
|
|
245
|
+
* {@link module:engine/model/schema~ModelSchemaItemDefinition}'s
|
|
246
|
+
* {@link module:engine/model/schema~ModelSchemaItemDefinition#isObject `isObject`} property
|
|
246
247
|
* was set to `true`.
|
|
247
248
|
*
|
|
248
249
|
* ```ts
|
|
@@ -267,7 +268,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
267
268
|
}
|
|
268
269
|
/**
|
|
269
270
|
* Returns `true` if the given item is defined to be
|
|
270
|
-
* an inline element by the {@link module:engine/model/schema~
|
|
271
|
+
* an inline element by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isInline` property.
|
|
271
272
|
*
|
|
272
273
|
* ```ts
|
|
273
274
|
* schema.isInline( 'paragraph' ); // -> false
|
|
@@ -286,7 +287,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
286
287
|
}
|
|
287
288
|
/**
|
|
288
289
|
* Returns `true` if the given item is defined to be
|
|
289
|
-
* a selectable element by the {@link module:engine/model/schema~
|
|
290
|
+
* a selectable element by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isSelectable` property.
|
|
290
291
|
*
|
|
291
292
|
* ```ts
|
|
292
293
|
* schema.isSelectable( 'paragraph' ); // -> false
|
|
@@ -310,7 +311,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
310
311
|
}
|
|
311
312
|
/**
|
|
312
313
|
* Returns `true` if the given item is defined to be
|
|
313
|
-
* a content by the {@link module:engine/model/schema~
|
|
314
|
+
* a content by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isContent` property.
|
|
314
315
|
*
|
|
315
316
|
* ```ts
|
|
316
317
|
* schema.isContent( 'paragraph' ); // -> false
|
|
@@ -345,8 +346,9 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
345
346
|
* schema.checkChild( model.document.getRoot(), paragraph ); // -> true
|
|
346
347
|
* ```
|
|
347
348
|
*
|
|
348
|
-
* Both {@link module:engine/model/schema~
|
|
349
|
-
* {@link module:engine/model/schema~
|
|
349
|
+
* Both {@link module:engine/model/schema~ModelSchema#addChildCheck callback checks} and declarative rules (added when
|
|
350
|
+
* {@link module:engine/model/schema~ModelSchema#register registering} and
|
|
351
|
+
* {@link module:engine/model/schema~ModelSchema#extend extending} items)
|
|
350
352
|
* are evaluated when this method is called.
|
|
351
353
|
*
|
|
352
354
|
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
@@ -354,14 +356,14 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
354
356
|
* Note that when verifying whether the given node can be a child of the given context, the schema also verifies the entire
|
|
355
357
|
* context – from its root to its last element. Therefore, it is possible for `checkChild()` to return `false` even though
|
|
356
358
|
* the `context` last element can contain the checked child. It happens if one of the `context` elements does not allow its child.
|
|
357
|
-
* When `context` is verified, {@link module:engine/model/schema~
|
|
359
|
+
* When `context` is verified, {@link module:engine/model/schema~ModelSchema#addChildCheck custom checks} are considered as well.
|
|
358
360
|
*
|
|
359
361
|
* @fires checkChild
|
|
360
362
|
* @param context The context in which the child will be checked.
|
|
361
363
|
* @param def The child to check.
|
|
362
364
|
*/
|
|
363
365
|
checkChild(context, def) {
|
|
364
|
-
// Note: `context` and `def` are already normalized here to `
|
|
366
|
+
// Note: `context` and `def` are already normalized here to `ModelSchemaContext` and `ModelSchemaCompiledItemDefinition`.
|
|
365
367
|
if (!def) {
|
|
366
368
|
return false;
|
|
367
369
|
}
|
|
@@ -380,8 +382,9 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
380
382
|
* schema.checkAttribute( textNode, 'bold' ); // -> true
|
|
381
383
|
* ```
|
|
382
384
|
*
|
|
383
|
-
* Both {@link module:engine/model/schema~
|
|
384
|
-
* {@link module:engine/model/schema~
|
|
385
|
+
* Both {@link module:engine/model/schema~ModelSchema#addAttributeCheck callback checks} and declarative rules (added when
|
|
386
|
+
* {@link module:engine/model/schema~ModelSchema#register registering} and
|
|
387
|
+
* {@link module:engine/model/schema~ModelSchema#extend extending} items)
|
|
385
388
|
* are evaluated when this method is called.
|
|
386
389
|
*
|
|
387
390
|
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
@@ -391,7 +394,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
391
394
|
* @param attributeName Name of attribute to check in the given context.
|
|
392
395
|
*/
|
|
393
396
|
checkAttribute(context, attributeName) {
|
|
394
|
-
// Note: `context` is already normalized here to `
|
|
397
|
+
// Note: `context` is already normalized here to `ModelSchemaContext`.
|
|
395
398
|
const def = this.getDefinition(context.last);
|
|
396
399
|
if (!def) {
|
|
397
400
|
return false;
|
|
@@ -408,20 +411,20 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
408
411
|
* In other words – both elements are not a limit elements and whether `elementToMerge`'s children
|
|
409
412
|
* {@link #checkChild are allowed} in the `positionOrBaseElement`.
|
|
410
413
|
*
|
|
411
|
-
* This check ensures that elements merged with {@link module:engine/model/writer~
|
|
414
|
+
* This check ensures that elements merged with {@link module:engine/model/writer~ModelWriter#merge `Writer#merge()`}
|
|
412
415
|
* will be valid.
|
|
413
416
|
*
|
|
414
|
-
* Instead of elements, you can pass the instance of the {@link module:engine/model/position~
|
|
417
|
+
* Instead of elements, you can pass the instance of the {@link module:engine/model/position~ModelPosition} class as the
|
|
415
418
|
* `positionOrBaseElement`. It means that the elements before and after the position will be checked whether they can be merged.
|
|
416
419
|
*
|
|
417
420
|
* @param positionOrBaseElement The position or base element to which the `elementToMerge` will be merged.
|
|
418
421
|
* @param elementToMerge The element to merge. Required if `positionOrBaseElement` is an element.
|
|
419
422
|
*/
|
|
420
423
|
checkMerge(positionOrBaseElement, elementToMerge) {
|
|
421
|
-
if (positionOrBaseElement instanceof
|
|
424
|
+
if (positionOrBaseElement instanceof ModelPosition) {
|
|
422
425
|
const nodeBefore = positionOrBaseElement.nodeBefore;
|
|
423
426
|
const nodeAfter = positionOrBaseElement.nodeAfter;
|
|
424
|
-
if (!(nodeBefore instanceof
|
|
427
|
+
if (!(nodeBefore instanceof ModelElement)) {
|
|
425
428
|
/**
|
|
426
429
|
* The node before the merge position must be an element.
|
|
427
430
|
*
|
|
@@ -429,7 +432,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
429
432
|
*/
|
|
430
433
|
throw new CKEditorError('schema-check-merge-no-element-before', this);
|
|
431
434
|
}
|
|
432
|
-
if (!(nodeAfter instanceof
|
|
435
|
+
if (!(nodeAfter instanceof ModelElement)) {
|
|
433
436
|
/**
|
|
434
437
|
* The node after the merge position must be an element.
|
|
435
438
|
*
|
|
@@ -453,7 +456,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
453
456
|
* Allows registering a callback to the {@link #checkChild} method calls.
|
|
454
457
|
*
|
|
455
458
|
* Callbacks allow you to implement rules which are not otherwise possible to achieve
|
|
456
|
-
* by using the declarative API of {@link module:engine/model/schema~
|
|
459
|
+
* by using the declarative API of {@link module:engine/model/schema~ModelSchemaItemDefinition}.
|
|
457
460
|
*
|
|
458
461
|
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
459
462
|
*
|
|
@@ -506,9 +509,9 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
506
509
|
* Adding callbacks this way can also negatively impact editor performance.
|
|
507
510
|
*
|
|
508
511
|
* @param callback The callback to be called. It is called with two parameters:
|
|
509
|
-
* {@link module:engine/model/schema~
|
|
510
|
-
* {@link module:engine/model/schema~
|
|
511
|
-
* `checkChild()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks) will define
|
|
512
|
+
* {@link module:engine/model/schema~ModelSchemaContext} (context) instance and
|
|
513
|
+
* {@link module:engine/model/schema~ModelSchemaCompiledItemDefinition} (definition). The callback may return `true/false` to
|
|
514
|
+
* override `checkChild()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks) will define
|
|
512
515
|
* `checkChild()`'s return value.
|
|
513
516
|
* @param itemName Name of the schema item for which the callback is registered. If specified, the callback will be run only for
|
|
514
517
|
* `checkChild()` calls which `def` parameter matches the `itemName`. Otherwise, the callback will run for every `checkChild` call.
|
|
@@ -523,7 +526,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
523
526
|
* Allows registering a callback to the {@link #checkAttribute} method calls.
|
|
524
527
|
*
|
|
525
528
|
* Callbacks allow you to implement rules which are not otherwise possible to achieve
|
|
526
|
-
* by using the declarative API of {@link module:engine/model/schema~
|
|
529
|
+
* by using the declarative API of {@link module:engine/model/schema~ModelSchemaItemDefinition}.
|
|
527
530
|
*
|
|
528
531
|
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
529
532
|
*
|
|
@@ -576,7 +579,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
576
579
|
* Adding callbacks this way can also negatively impact editor performance.
|
|
577
580
|
*
|
|
578
581
|
* @param callback The callback to be called. It is called with two parameters:
|
|
579
|
-
* {@link module:engine/model/schema~
|
|
582
|
+
* {@link module:engine/model/schema~ModelSchemaContext `context`} and attribute name. The callback may return `true` or `false`, to
|
|
580
583
|
* override `checkAttribute()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks)
|
|
581
584
|
* will define `checkAttribute()`'s return value.
|
|
582
585
|
* @param attributeName Name of the attribute for which the callback is registered. If specified, the callback will be run only for
|
|
@@ -590,7 +593,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
590
593
|
}
|
|
591
594
|
/**
|
|
592
595
|
* This method allows assigning additional metadata to the model attributes. For example,
|
|
593
|
-
* {@link module:engine/model/schema~
|
|
596
|
+
* {@link module:engine/model/schema~ModelAttributeProperties `AttributeProperties#isFormatting` property} is
|
|
594
597
|
* used to mark formatting attributes (like `bold` or `italic`).
|
|
595
598
|
*
|
|
596
599
|
* ```ts
|
|
@@ -606,7 +609,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
606
609
|
* ```
|
|
607
610
|
*
|
|
608
611
|
* Properties are not limited to members defined in the
|
|
609
|
-
* {@link module:engine/model/schema~
|
|
612
|
+
* {@link module:engine/model/schema~ModelAttributeProperties `AttributeProperties` type} and you can also use custom properties:
|
|
610
613
|
*
|
|
611
614
|
* ```ts
|
|
612
615
|
* schema.setAttributeProperties( 'blockQuote', {
|
|
@@ -644,7 +647,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
644
647
|
return this._attributeProperties[attributeName] || Object.create(null);
|
|
645
648
|
}
|
|
646
649
|
/**
|
|
647
|
-
* Returns the lowest {@link module:engine/model/schema~
|
|
650
|
+
* Returns the lowest {@link module:engine/model/schema~ModelSchema#isLimit limit element} containing the entire
|
|
648
651
|
* selection/range/position or the root otherwise.
|
|
649
652
|
*
|
|
650
653
|
* @param selectionOrRangeOrPosition The selection/range/position to check.
|
|
@@ -652,11 +655,11 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
652
655
|
*/
|
|
653
656
|
getLimitElement(selectionOrRangeOrPosition) {
|
|
654
657
|
let element;
|
|
655
|
-
if (selectionOrRangeOrPosition instanceof
|
|
658
|
+
if (selectionOrRangeOrPosition instanceof ModelPosition) {
|
|
656
659
|
element = selectionOrRangeOrPosition.parent;
|
|
657
660
|
}
|
|
658
661
|
else {
|
|
659
|
-
const ranges = selectionOrRangeOrPosition instanceof
|
|
662
|
+
const ranges = selectionOrRangeOrPosition instanceof ModelRange ?
|
|
660
663
|
[selectionOrRangeOrPosition] :
|
|
661
664
|
Array.from(selectionOrRangeOrPosition.getRanges());
|
|
662
665
|
// Find the common ancestor for all selection's ranges.
|
|
@@ -694,7 +697,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
694
697
|
const firstPosition = selection.getFirstPosition();
|
|
695
698
|
const context = [
|
|
696
699
|
...firstPosition.getAncestors(),
|
|
697
|
-
new
|
|
700
|
+
new ModelText('', selection.getAttributes())
|
|
698
701
|
];
|
|
699
702
|
// Check whether schema allows for a text with the attribute in the selection.
|
|
700
703
|
return this.checkAttribute(context, attribute);
|
|
@@ -728,12 +731,12 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
728
731
|
}
|
|
729
732
|
}
|
|
730
733
|
/**
|
|
731
|
-
* Basing on given `position`, finds and returns a {@link module:engine/model/range~
|
|
734
|
+
* Basing on given `position`, finds and returns a {@link module:engine/model/range~ModelRange range} which is
|
|
732
735
|
* nearest to that `position` and is a correct range for selection.
|
|
733
736
|
*
|
|
734
737
|
* The correct selection range might be collapsed when it is located in a position where the text node can be placed.
|
|
735
738
|
* Non-collapsed range is returned when selection can be placed around element marked as an "object" in
|
|
736
|
-
* the {@link module:engine/model/schema~
|
|
739
|
+
* the {@link module:engine/model/schema~ModelSchema schema}.
|
|
737
740
|
*
|
|
738
741
|
* Direction of searching for the nearest correct selection range can be specified as:
|
|
739
742
|
*
|
|
@@ -755,22 +758,22 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
755
758
|
}
|
|
756
759
|
// Return collapsed range if provided position is valid.
|
|
757
760
|
if (this.checkChild(position, '$text')) {
|
|
758
|
-
return new
|
|
761
|
+
return new ModelRange(position);
|
|
759
762
|
}
|
|
760
763
|
let backwardWalker, forwardWalker;
|
|
761
764
|
// Never leave a limit element.
|
|
762
765
|
const limitElement = position.getAncestors().reverse().find(item => this.isLimit(item)) ||
|
|
763
766
|
position.root;
|
|
764
767
|
if (direction == 'both' || direction == 'backward') {
|
|
765
|
-
backwardWalker = new
|
|
766
|
-
boundaries:
|
|
768
|
+
backwardWalker = new ModelTreeWalker({
|
|
769
|
+
boundaries: ModelRange._createIn(limitElement),
|
|
767
770
|
startPosition: position,
|
|
768
771
|
direction: 'backward'
|
|
769
772
|
});
|
|
770
773
|
}
|
|
771
774
|
if (direction == 'both' || direction == 'forward') {
|
|
772
|
-
forwardWalker = new
|
|
773
|
-
boundaries:
|
|
775
|
+
forwardWalker = new ModelTreeWalker({
|
|
776
|
+
boundaries: ModelRange._createIn(limitElement),
|
|
774
777
|
startPosition: position
|
|
775
778
|
});
|
|
776
779
|
}
|
|
@@ -778,10 +781,10 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
778
781
|
const type = (data.walker == backwardWalker ? 'elementEnd' : 'elementStart');
|
|
779
782
|
const value = data.value;
|
|
780
783
|
if (value.type == type && this.isObject(value.item)) {
|
|
781
|
-
return
|
|
784
|
+
return ModelRange._createOn(value.item);
|
|
782
785
|
}
|
|
783
786
|
if (this.checkChild(value.nextPosition, '$text')) {
|
|
784
|
-
return new
|
|
787
|
+
return new ModelRange(value.nextPosition);
|
|
785
788
|
}
|
|
786
789
|
}
|
|
787
790
|
return null;
|
|
@@ -789,8 +792,8 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
789
792
|
/**
|
|
790
793
|
* Tries to find position ancestors that allow to insert a given node.
|
|
791
794
|
* It starts searching from the given position and goes node by node to the top of the model tree
|
|
792
|
-
* as long as a {@link module:engine/model/schema~
|
|
793
|
-
* {@link module:engine/model/schema~
|
|
795
|
+
* as long as a {@link module:engine/model/schema~ModelSchema#isLimit limit element}, an
|
|
796
|
+
* {@link module:engine/model/schema~ModelSchema#isObject object element} or a topmost ancestor is not reached.
|
|
794
797
|
*
|
|
795
798
|
* @param position The position that the search will start from.
|
|
796
799
|
* @param node The node for which an allowed parent should be found or its name.
|
|
@@ -841,7 +844,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
841
844
|
// is at start of an element. Using positions prevent from omitting merged nodes
|
|
842
845
|
// see https://github.com/ckeditor/ckeditor5-engine/issues/1789.
|
|
843
846
|
else {
|
|
844
|
-
const rangeInNode =
|
|
847
|
+
const rangeInNode = ModelRange._createIn(node);
|
|
845
848
|
const positionsInRange = rangeInNode.getPositions();
|
|
846
849
|
for (const position of positionsInRange) {
|
|
847
850
|
const item = position.nodeBefore || position.parent;
|
|
@@ -877,7 +880,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
877
880
|
* Creates an instance of the schema context.
|
|
878
881
|
*/
|
|
879
882
|
createContext(context) {
|
|
880
|
-
return new
|
|
883
|
+
return new ModelSchemaContext(context);
|
|
881
884
|
}
|
|
882
885
|
_clearCache() {
|
|
883
886
|
this._compiledDefinitions = null;
|
|
@@ -995,7 +998,7 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
995
998
|
* Takes a flat range and an attribute name. Traverses the range recursively and deeply to find and return all ranges
|
|
996
999
|
* inside the given range on which the attribute can be applied.
|
|
997
1000
|
*
|
|
998
|
-
* This is a helper function for {@link ~
|
|
1001
|
+
* This is a helper function for {@link ~ModelSchema#getValidRanges}.
|
|
999
1002
|
*
|
|
1000
1003
|
* @param range The range to process.
|
|
1001
1004
|
* @param attribute The name of the attribute to check.
|
|
@@ -1006,18 +1009,18 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
1006
1009
|
let end = range.start;
|
|
1007
1010
|
for (const item of range.getItems({ shallow: true })) {
|
|
1008
1011
|
if (item.is('element')) {
|
|
1009
|
-
yield* this._getValidRangesForRange(
|
|
1012
|
+
yield* this._getValidRangesForRange(ModelRange._createIn(item), attribute);
|
|
1010
1013
|
}
|
|
1011
1014
|
if (!this.checkAttribute(item, attribute)) {
|
|
1012
1015
|
if (!start.isEqual(end)) {
|
|
1013
|
-
yield new
|
|
1016
|
+
yield new ModelRange(start, end);
|
|
1014
1017
|
}
|
|
1015
|
-
start =
|
|
1018
|
+
start = ModelPosition._createAfter(item);
|
|
1016
1019
|
}
|
|
1017
|
-
end =
|
|
1020
|
+
end = ModelPosition._createAfter(item);
|
|
1018
1021
|
}
|
|
1019
1022
|
if (!start.isEqual(end)) {
|
|
1020
|
-
yield new
|
|
1023
|
+
yield new ModelRange(start, end);
|
|
1021
1024
|
}
|
|
1022
1025
|
}
|
|
1023
1026
|
/**
|
|
@@ -1043,27 +1046,27 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
1043
1046
|
const selectedElement = selection.getSelectedElement();
|
|
1044
1047
|
if (selectedElement && this.isObject(selectedElement) && !this.isInline(selectedElement)) {
|
|
1045
1048
|
if (place == 'before' || place == 'after') {
|
|
1046
|
-
return new
|
|
1049
|
+
return new ModelRange(ModelPosition._createAt(selectedElement, place));
|
|
1047
1050
|
}
|
|
1048
|
-
return
|
|
1051
|
+
return ModelRange._createOn(selectedElement);
|
|
1049
1052
|
}
|
|
1050
1053
|
const firstBlock = first(selection.getSelectedBlocks());
|
|
1051
1054
|
// There are no block elements within ancestors (in the current limit element).
|
|
1052
1055
|
if (!firstBlock) {
|
|
1053
|
-
return new
|
|
1056
|
+
return new ModelRange(selection.focus);
|
|
1054
1057
|
}
|
|
1055
1058
|
// If inserting into an empty block – return position in that block. It will get
|
|
1056
1059
|
// replaced with the image by insertContent(). #42.
|
|
1057
1060
|
if (firstBlock.isEmpty) {
|
|
1058
|
-
return new
|
|
1061
|
+
return new ModelRange(ModelPosition._createAt(firstBlock, 0));
|
|
1059
1062
|
}
|
|
1060
|
-
const positionAfter =
|
|
1063
|
+
const positionAfter = ModelPosition._createAfter(firstBlock);
|
|
1061
1064
|
// If selection is at the end of the block - return position after the block.
|
|
1062
1065
|
if (selection.focus.isTouching(positionAfter)) {
|
|
1063
|
-
return new
|
|
1066
|
+
return new ModelRange(positionAfter);
|
|
1064
1067
|
}
|
|
1065
1068
|
// Otherwise, return position before the block.
|
|
1066
|
-
return new
|
|
1069
|
+
return new ModelRange(ModelPosition._createBefore(firstBlock));
|
|
1067
1070
|
}
|
|
1068
1071
|
}
|
|
1069
1072
|
/**
|
|
@@ -1081,24 +1084,24 @@ export default class Schema extends /* #__PURE__ */ ObservableMixin() {
|
|
|
1081
1084
|
* </$root>
|
|
1082
1085
|
* ```
|
|
1083
1086
|
*
|
|
1084
|
-
* The context of this position is its {@link module:engine/model/position~
|
|
1087
|
+
* The context of this position is its {@link module:engine/model/position~ModelPosition#getAncestors lists of ancestors}:
|
|
1085
1088
|
*
|
|
1086
1089
|
* [ rootElement, blockQuoteElement, paragraphElement ]
|
|
1087
1090
|
*
|
|
1088
|
-
* Contexts are used in the {@link module:engine/model/schema~
|
|
1089
|
-
* {@link module:engine/model/schema~
|
|
1091
|
+
* Contexts are used in the {@link module:engine/model/schema~ModelSchema#event:checkChild `Schema#checkChild`} and
|
|
1092
|
+
* {@link module:engine/model/schema~ModelSchema#event:checkAttribute `Schema#checkAttribute`} events as a definition
|
|
1090
1093
|
* of a place in the document where the check occurs. The context instances are created based on the first arguments
|
|
1091
|
-
* of the {@link module:engine/model/schema~
|
|
1092
|
-
* {@link module:engine/model/schema~
|
|
1093
|
-
* using these methods you need to use {@link module:engine/model/schema~
|
|
1094
|
+
* of the {@link module:engine/model/schema~ModelSchema#checkChild `Schema#checkChild()`} and
|
|
1095
|
+
* {@link module:engine/model/schema~ModelSchema#checkAttribute `Schema#checkAttribute()`} methods so when
|
|
1096
|
+
* using these methods you need to use {@link module:engine/model/schema~ModelSchemaContextDefinition}s.
|
|
1094
1097
|
*/
|
|
1095
|
-
export class
|
|
1098
|
+
export class ModelSchemaContext {
|
|
1096
1099
|
_items;
|
|
1097
1100
|
/**
|
|
1098
1101
|
* Creates an instance of the context.
|
|
1099
1102
|
*/
|
|
1100
1103
|
constructor(context) {
|
|
1101
|
-
if (context instanceof
|
|
1104
|
+
if (context instanceof ModelSchemaContext) {
|
|
1102
1105
|
return context;
|
|
1103
1106
|
}
|
|
1104
1107
|
let items;
|
|
@@ -1141,7 +1144,7 @@ export class SchemaContext {
|
|
|
1141
1144
|
* Item can be added as:
|
|
1142
1145
|
*
|
|
1143
1146
|
* ```ts
|
|
1144
|
-
* const context = new
|
|
1147
|
+
* const context = new ModelSchemaContext( [ '$root' ] );
|
|
1145
1148
|
*
|
|
1146
1149
|
* // An element.
|
|
1147
1150
|
* const fooElement = writer.createElement( 'fooElement' );
|
|
@@ -1155,14 +1158,14 @@ export class SchemaContext {
|
|
|
1155
1158
|
* const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]
|
|
1156
1159
|
* ```
|
|
1157
1160
|
*
|
|
1158
|
-
* **Note** {@link module:engine/model/node~
|
|
1161
|
+
* **Note** {@link module:engine/model/node~ModelNode} that is already in the model tree will be added as the only item
|
|
1159
1162
|
* (without ancestors).
|
|
1160
1163
|
*
|
|
1161
1164
|
* @param item An item that will be added to the current context.
|
|
1162
1165
|
* @returns A new schema context instance with an additional item.
|
|
1163
1166
|
*/
|
|
1164
1167
|
push(item) {
|
|
1165
|
-
const ctx = new
|
|
1168
|
+
const ctx = new ModelSchemaContext([item]);
|
|
1166
1169
|
ctx._items = [...this._items, ...ctx._items];
|
|
1167
1170
|
return ctx;
|
|
1168
1171
|
}
|
|
@@ -1170,7 +1173,7 @@ export class SchemaContext {
|
|
|
1170
1173
|
* Returns a new schema context that is based on this context but has the last item removed.
|
|
1171
1174
|
*
|
|
1172
1175
|
* ```ts
|
|
1173
|
-
* const ctxParagraph = new
|
|
1176
|
+
* const ctxParagraph = new ModelSchemaContext( [ '$root', 'blockQuote', 'paragraph' ] );
|
|
1174
1177
|
* const ctxBlockQuote = ctxParagraph.trimLast(); // Items in `ctxBlockQuote` are: `$root` an `blockQuote`.
|
|
1175
1178
|
* const ctxRoot = ctxBlockQuote.trimLast(); // Items in `ctxRoot` are: `$root`.
|
|
1176
1179
|
* ```
|
|
@@ -1178,7 +1181,7 @@ export class SchemaContext {
|
|
|
1178
1181
|
* @returns A new reduced schema context instance.
|
|
1179
1182
|
*/
|
|
1180
1183
|
trimLast() {
|
|
1181
|
-
const ctx = new
|
|
1184
|
+
const ctx = new ModelSchemaContext([]);
|
|
1182
1185
|
ctx._items = this._items.slice(0, -1);
|
|
1183
1186
|
return ctx;
|
|
1184
1187
|
}
|
|
@@ -1198,7 +1201,7 @@ export class SchemaContext {
|
|
|
1198
1201
|
* Checks whether the context ends with the given nodes.
|
|
1199
1202
|
*
|
|
1200
1203
|
* ```ts
|
|
1201
|
-
* const ctx = new
|
|
1204
|
+
* const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] );
|
|
1202
1205
|
*
|
|
1203
1206
|
* ctx.endsWith( '$text' ); // -> true
|
|
1204
1207
|
* ctx.endsWith( 'paragraph $text' ); // -> true
|
|
@@ -1213,7 +1216,7 @@ export class SchemaContext {
|
|
|
1213
1216
|
* Checks whether the context starts with the given nodes.
|
|
1214
1217
|
*
|
|
1215
1218
|
* ```ts
|
|
1216
|
-
* const ctx = new
|
|
1219
|
+
* const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] );
|
|
1217
1220
|
*
|
|
1218
1221
|
* ctx.endsWith( '$root' ); // -> true
|
|
1219
1222
|
* ctx.endsWith( '$root paragraph' ); // -> true
|