@ckeditor/ckeditor5-engine 48.2.0 → 48.3.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.
Files changed (129) hide show
  1. package/dist/controller/datacontroller.d.ts +329 -328
  2. package/dist/controller/editingcontroller.d.ts +95 -94
  3. package/dist/conversion/comparemarkers.d.ts +45 -45
  4. package/dist/conversion/conversion.d.ts +474 -474
  5. package/dist/conversion/conversionhelpers.d.ts +21 -21
  6. package/dist/conversion/downcastdispatcher.d.ts +539 -538
  7. package/dist/conversion/downcasthelpers.d.ts +1129 -1129
  8. package/dist/conversion/mapper.d.ts +692 -697
  9. package/dist/conversion/modelconsumable.d.ts +196 -196
  10. package/dist/conversion/upcastdispatcher.d.ts +483 -482
  11. package/dist/conversion/upcasthelpers.d.ts +491 -491
  12. package/dist/conversion/viewconsumable.d.ts +330 -330
  13. package/dist/dataprocessor/basichtmlwriter.d.ts +15 -15
  14. package/dist/dataprocessor/dataprocessor.d.ts +57 -57
  15. package/dist/dataprocessor/htmldataprocessor.d.ts +72 -72
  16. package/dist/dataprocessor/htmlwriter.d.ts +11 -11
  17. package/dist/dataprocessor/xmldataprocessor.d.ts +86 -86
  18. package/dist/dev-utils/model.d.ts +128 -123
  19. package/dist/dev-utils/operationreplayer.d.ts +49 -49
  20. package/dist/dev-utils/utils.d.ts +33 -33
  21. package/dist/dev-utils/view.d.ts +314 -309
  22. package/dist/engineconfig.d.ts +39 -39
  23. package/dist/index.css.map +1 -1
  24. package/dist/index.d.ts +150 -150
  25. package/dist/index.js +34026 -40107
  26. package/dist/index.js.map +1 -1
  27. package/dist/legacyerrors.d.ts +0 -4
  28. package/dist/model/batch.d.ts +86 -86
  29. package/dist/model/differ.d.ts +504 -504
  30. package/dist/model/document.d.ts +265 -268
  31. package/dist/model/documentfragment.d.ts +214 -214
  32. package/dist/model/documentselection.d.ts +406 -410
  33. package/dist/model/element.d.ts +182 -182
  34. package/dist/model/history.d.ts +109 -109
  35. package/dist/model/item.d.ts +9 -9
  36. package/dist/model/liveposition.d.ts +70 -69
  37. package/dist/model/liverange.d.ts +93 -92
  38. package/dist/model/markercollection.d.ts +317 -324
  39. package/dist/model/model.d.ts +889 -909
  40. package/dist/model/node.d.ts +254 -254
  41. package/dist/model/nodelist.d.ts +110 -110
  42. package/dist/model/operation/attributeoperation.d.ts +98 -98
  43. package/dist/model/operation/detachoperation.d.ts +57 -57
  44. package/dist/model/operation/insertoperation.d.ts +85 -85
  45. package/dist/model/operation/markeroperation.d.ts +87 -87
  46. package/dist/model/operation/mergeoperation.d.ts +95 -95
  47. package/dist/model/operation/moveoperation.d.ts +97 -97
  48. package/dist/model/operation/nooperation.d.ts +33 -33
  49. package/dist/model/operation/operation.d.ts +94 -94
  50. package/dist/model/operation/operationfactory.d.ts +14 -14
  51. package/dist/model/operation/renameoperation.d.ts +78 -78
  52. package/dist/model/operation/rootattributeoperation.d.ts +93 -93
  53. package/dist/model/operation/rootoperation.d.ts +71 -71
  54. package/dist/model/operation/splitoperation.d.ts +104 -104
  55. package/dist/model/operation/transform.d.ts +91 -91
  56. package/dist/model/operation/utils.d.ts +58 -58
  57. package/dist/model/position.d.ts +535 -535
  58. package/dist/model/range.d.ts +458 -453
  59. package/dist/model/rootelement.d.ts +55 -55
  60. package/dist/model/schema.d.ts +1325 -1327
  61. package/dist/model/selection.d.ts +452 -471
  62. package/dist/model/text.d.ts +62 -62
  63. package/dist/model/textproxy.d.ts +140 -140
  64. package/dist/model/treewalker.d.ts +190 -190
  65. package/dist/model/typecheckable.d.ts +281 -281
  66. package/dist/model/utils/autoparagraphing.d.ts +29 -29
  67. package/dist/model/utils/deletecontent.d.ts +68 -68
  68. package/dist/model/utils/getselectedcontent.d.ts +27 -27
  69. package/dist/model/utils/insertcontent.d.ts +42 -42
  70. package/dist/model/utils/insertobject.d.ts +41 -41
  71. package/dist/model/utils/modifyselection.d.ts +44 -44
  72. package/dist/model/utils/selection-post-fixer.d.ts +71 -71
  73. package/dist/model/writer.d.ts +854 -854
  74. package/dist/view/attributeelement.d.ts +123 -123
  75. package/dist/view/containerelement.d.ts +49 -49
  76. package/dist/view/datatransfer.d.ts +70 -70
  77. package/dist/view/document.d.ts +175 -177
  78. package/dist/view/documentfragment.d.ts +158 -157
  79. package/dist/view/documentselection.d.ts +308 -307
  80. package/dist/view/domconverter.d.ts +612 -657
  81. package/dist/view/downcastwriter.d.ts +1006 -1006
  82. package/dist/view/editableelement.d.ts +64 -63
  83. package/dist/view/element.d.ts +754 -754
  84. package/dist/view/elementdefinition.d.ts +79 -79
  85. package/dist/view/emptyelement.d.ts +42 -42
  86. package/dist/view/filler.d.ts +75 -75
  87. package/dist/view/item.d.ts +9 -9
  88. package/dist/view/matcher.d.ts +412 -487
  89. package/dist/view/node.d.ts +164 -163
  90. package/dist/view/observer/arrowkeysobserver.d.ts +37 -37
  91. package/dist/view/observer/bubblingemittermixin.d.ts +163 -153
  92. package/dist/view/observer/bubblingeventinfo.d.ts +45 -42
  93. package/dist/view/observer/clickobserver.d.ts +36 -36
  94. package/dist/view/observer/compositionobserver.d.ts +67 -67
  95. package/dist/view/observer/domeventdata.d.ts +46 -46
  96. package/dist/view/observer/domeventobserver.d.ts +77 -74
  97. package/dist/view/observer/fakeselectionobserver.d.ts +42 -42
  98. package/dist/view/observer/focusobserver.d.ts +84 -84
  99. package/dist/view/observer/inputobserver.d.ts +76 -76
  100. package/dist/view/observer/keyobserver.d.ts +53 -53
  101. package/dist/view/observer/mouseobserver.d.ts +73 -73
  102. package/dist/view/observer/mutationobserver.d.ts +101 -101
  103. package/dist/view/observer/observer.d.ts +84 -83
  104. package/dist/view/observer/pointerobserver.d.ts +63 -63
  105. package/dist/view/observer/selectionobserver.d.ts +136 -136
  106. package/dist/view/observer/tabobserver.d.ts +38 -38
  107. package/dist/view/observer/touchobserver.d.ts +60 -60
  108. package/dist/view/placeholder.d.ts +80 -80
  109. package/dist/view/position.d.ts +187 -187
  110. package/dist/view/range.d.ts +282 -282
  111. package/dist/view/rawelement.d.ts +72 -72
  112. package/dist/view/renderer.d.ts +270 -272
  113. package/dist/view/rooteditableelement.d.ts +43 -43
  114. package/dist/view/selection.d.ts +356 -369
  115. package/dist/view/styles/background.d.ts +15 -15
  116. package/dist/view/styles/border.d.ts +27 -27
  117. package/dist/view/styles/margin.d.ts +12 -12
  118. package/dist/view/styles/padding.d.ts +12 -12
  119. package/dist/view/styles/utils.d.ts +72 -72
  120. package/dist/view/stylesmap.d.ts +715 -715
  121. package/dist/view/text.d.ts +75 -75
  122. package/dist/view/textproxy.d.ts +92 -92
  123. package/dist/view/tokenlist.d.ts +104 -104
  124. package/dist/view/treewalker.d.ts +201 -201
  125. package/dist/view/typecheckable.d.ts +445 -445
  126. package/dist/view/uielement.d.ts +93 -93
  127. package/dist/view/upcastwriter.d.ts +412 -412
  128. package/dist/view/view.d.ts +466 -469
  129. package/package.json +2 -2
@@ -1,1359 +1,1357 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
5
  /**
6
- * @module engine/model/schema
7
- */
8
- import { ModelElement } from './element.js';
9
- import { ModelPosition } from './position.js';
10
- import { ModelRange } from './range.js';
11
- import { type ModelDocumentFragment } from './documentfragment.js';
12
- import { type ModelDocumentSelection } from './documentselection.js';
13
- import { type ModelItem } from './item.js';
14
- import { type ModelNode } from './node.js';
15
- import { type ModelSelection } from './selection.js';
16
- import { type ModelWriter } from './writer.js';
17
- declare const ModelSchema_base: {
18
- new (): import("@ckeditor/ckeditor5-utils").Observable;
19
- prototype: import("@ckeditor/ckeditor5-utils").Observable;
20
- };
6
+ * @module engine/model/schema
7
+ */
8
+ import { ModelElement } from "./element.js";
9
+ import { ModelPosition } from "./position.js";
10
+ import { ModelRange } from "./range.js";
11
+ import { type ModelDocumentFragment } from "./documentfragment.js";
12
+ import { type ModelDocumentSelection } from "./documentselection.js";
13
+ import { type ModelItem } from "./item.js";
14
+ import { type ModelNode } from "./node.js";
15
+ import { type ModelSelection } from "./selection.js";
16
+ import { type ModelWriter } from "./writer.js";
17
+ import { type ObservableMixinConstructor } from "@ckeditor/ckeditor5-utils";
18
+ declare const ModelSchemaBase: ObservableMixinConstructor;
21
19
  /**
22
- * The model's schema. It defines the allowed and disallowed structures of nodes as well as nodes' attributes.
23
- * The schema is usually defined by the features and based on them, the editing framework and features
24
- * make decisions on how to change and process the model.
25
- *
26
- * The instance of schema is available in {@link module:engine/model/model~Model#schema `editor.model.schema`}.
27
- *
28
- * Read more about the schema in:
29
- *
30
- * * The {@glink framework/architecture/editing-engine#schema schema section} of the
31
- * {@glink framework/architecture/editing-engine Introduction to the Editing engine architecture} guide.
32
- * * The {@glink framework/deep-dive/schema Schema deep-dive} guide.
33
- */
34
- export declare class ModelSchema extends /* #__PURE__ */ ModelSchema_base {
35
- private readonly _sourceDefinitions;
36
- /**
37
- * A dictionary containing attribute properties.
38
- */
39
- private readonly _attributeProperties;
40
- /**
41
- * Stores additional callbacks registered for schema items, which are evaluated when {@link ~ModelSchema#checkChild} is called.
42
- *
43
- * Keys are schema item names for which the callbacks are registered. Values are arrays with the callbacks.
44
- *
45
- * Some checks are added under {@link ~ModelSchema#_genericCheckSymbol} key, these are
46
- * evaluated for every {@link ~ModelSchema#checkChild} call.
47
- */
48
- private readonly _customChildChecks;
49
- /**
50
- * Stores additional callbacks registered for attribute names, which are evaluated when {@link ~ModelSchema#checkAttribute} is called.
51
- *
52
- * Keys are schema attribute names for which the callbacks are registered. Values are arrays with the callbacks.
53
- *
54
- * Some checks are added under {@link ~ModelSchema#_genericCheckSymbol} key, these are evaluated for every
55
- * {@link ~ModelSchema#checkAttribute} call.
56
- */
57
- private readonly _customAttributeChecks;
58
- private readonly _genericCheckSymbol;
59
- private _compiledDefinitions?;
60
- /**
61
- * Creates a schema instance.
62
- */
63
- constructor();
64
- /**
65
- * Registers a schema item. Can only be called once for every item name.
66
- *
67
- * ```ts
68
- * schema.register( 'paragraph', {
69
- * inheritAllFrom: '$block'
70
- * } );
71
- * ```
72
- */
73
- register(itemName: string, definition?: ModelSchemaItemDefinition): void;
74
- /**
75
- * Extends a {@link #register registered} item's definition.
76
- *
77
- * Extending properties such as `allowIn` will add more items to the existing properties,
78
- * while redefining properties such as `isBlock` will override the previously defined ones.
79
- *
80
- * ```ts
81
- * schema.register( 'foo', {
82
- * allowIn: '$root',
83
- * isBlock: true;
84
- * } );
85
- * schema.extend( 'foo', {
86
- * allowIn: 'blockQuote',
87
- * isBlock: false
88
- * } );
89
- *
90
- * schema.getDefinition( 'foo' );
91
- * // {
92
- * // allowIn: [ '$root', 'blockQuote' ],
93
- * // isBlock: false
94
- * // }
95
- * ```
96
- */
97
- extend(itemName: string, definition: ModelSchemaItemDefinition): void;
98
- /**
99
- * Returns data of all registered items.
100
- *
101
- * This method should normally be used for reflection purposes (e.g. defining a clone of a certain element,
102
- * checking a list of all block elements, etc).
103
- * Use specific methods (such as {@link #checkChild `checkChild()`} or {@link #isLimit `isLimit()`})
104
- * in other cases.
105
- */
106
- getDefinitions(): Record<string, ModelSchemaCompiledItemDefinition>;
107
- /**
108
- * Returns a definition of the given item or `undefined` if an item is not registered.
109
- *
110
- * This method should normally be used for reflection purposes (e.g. defining a clone of a certain element,
111
- * checking a list of all block elements, etc).
112
- * Use specific methods (such as {@link #checkChild `checkChild()`} or {@link #isLimit `isLimit()`})
113
- * in other cases.
114
- */
115
- getDefinition(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): ModelSchemaCompiledItemDefinition | undefined;
116
- /**
117
- * Returns `true` if the given item is registered in the schema.
118
- *
119
- * ```ts
120
- * schema.isRegistered( 'paragraph' ); // -> true
121
- * schema.isRegistered( editor.model.document.getRoot() ); // -> true
122
- * schema.isRegistered( 'foo' ); // -> false
123
- * ```
124
- */
125
- isRegistered(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
126
- /**
127
- * Returns `true` if the given item is defined to be
128
- * a block by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isBlock` property.
129
- *
130
- * ```ts
131
- * schema.isBlock( 'paragraph' ); // -> true
132
- * schema.isBlock( '$root' ); // -> false
133
- *
134
- * const paragraphElement = writer.createElement( 'paragraph' );
135
- * schema.isBlock( paragraphElement ); // -> true
136
- * ```
137
- *
138
- * See the {@glink framework/deep-dive/schema#block-elements Block elements} section of
139
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
140
- */
141
- isBlock(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
142
- /**
143
- * Returns `true` if the given item should be treated as a limit element.
144
- *
145
- * It considers an item to be a limit element if its
146
- * {@link module:engine/model/schema~ModelSchemaItemDefinition}'s
147
- * {@link module:engine/model/schema~ModelSchemaItemDefinition#isLimit `isLimit`} or
148
- * {@link module:engine/model/schema~ModelSchemaItemDefinition#isObject `isObject`} property
149
- * was set to `true`.
150
- *
151
- * ```ts
152
- * schema.isLimit( 'paragraph' ); // -> false
153
- * schema.isLimit( '$root' ); // -> true
154
- * schema.isLimit( editor.model.document.getRoot() ); // -> true
155
- * schema.isLimit( 'imageBlock' ); // -> true
156
- * ```
157
- *
158
- * See the {@glink framework/deep-dive/schema#limit-elements Limit elements} section of
159
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
160
- */
161
- isLimit(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
162
- /**
163
- * Returns `true` if the given item should be treated as an object element.
164
- *
165
- * It considers an item to be an object element if its
166
- * {@link module:engine/model/schema~ModelSchemaItemDefinition}'s
167
- * {@link module:engine/model/schema~ModelSchemaItemDefinition#isObject `isObject`} property
168
- * was set to `true`.
169
- *
170
- * ```ts
171
- * schema.isObject( 'paragraph' ); // -> false
172
- * schema.isObject( 'imageBlock' ); // -> true
173
- *
174
- * const imageElement = writer.createElement( 'imageBlock' );
175
- * schema.isObject( imageElement ); // -> true
176
- * ```
177
- *
178
- * See the {@glink framework/deep-dive/schema#object-elements Object elements} section of
179
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
180
- */
181
- isObject(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
182
- /**
183
- * Returns `true` if the given item is defined to be
184
- * an inline element by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isInline` property.
185
- *
186
- * ```ts
187
- * schema.isInline( 'paragraph' ); // -> false
188
- * schema.isInline( 'softBreak' ); // -> true
189
- *
190
- * const text = writer.createText( 'foo' );
191
- * schema.isInline( text ); // -> true
192
- * ```
193
- *
194
- * See the {@glink framework/deep-dive/schema#inline-elements Inline elements} section of
195
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
196
- */
197
- isInline(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
198
- /**
199
- * Returns `true` if the given item is defined to be
200
- * a selectable element by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isSelectable` property.
201
- *
202
- * ```ts
203
- * schema.isSelectable( 'paragraph' ); // -> false
204
- * schema.isSelectable( 'heading1' ); // -> false
205
- * schema.isSelectable( 'imageBlock' ); // -> true
206
- * schema.isSelectable( 'tableCell' ); // -> true
207
- *
208
- * const text = writer.createText( 'foo' );
209
- * schema.isSelectable( text ); // -> false
210
- * ```
211
- *
212
- * See the {@glink framework/deep-dive/schema#selectable-elements Selectable elements section} of
213
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
214
- */
215
- isSelectable(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
216
- /**
217
- * Returns `true` if the given item is defined to be
218
- * a content by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isContent` property.
219
- *
220
- * ```ts
221
- * schema.isContent( 'paragraph' ); // -> false
222
- * schema.isContent( 'heading1' ); // -> false
223
- * schema.isContent( 'imageBlock' ); // -> true
224
- * schema.isContent( 'horizontalLine' ); // -> true
225
- *
226
- * const text = writer.createText( 'foo' );
227
- * schema.isContent( text ); // -> true
228
- * ```
229
- *
230
- * See the {@glink framework/deep-dive/schema#content-elements Content elements section} of
231
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
232
- */
233
- isContent(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
234
- /**
235
- * Checks whether the given node can be a child of the given context.
236
- *
237
- * ```ts
238
- * schema.checkChild( model.document.getRoot(), paragraph ); // -> false
239
- *
240
- * schema.register( 'paragraph', {
241
- * allowIn: '$root'
242
- * } );
243
- *
244
- * schema.checkChild( model.document.getRoot(), paragraph ); // -> true
245
- * ```
246
- *
247
- * Both {@link module:engine/model/schema~ModelSchema#addChildCheck callback checks} and declarative rules (added when
248
- * {@link module:engine/model/schema~ModelSchema#register registering} and
249
- * {@link module:engine/model/schema~ModelSchema#extend extending} items)
250
- * are evaluated when this method is called.
251
- *
252
- * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
253
- *
254
- * Note that when verifying whether the given node can be a child of the given context, the schema also verifies the entire
255
- * context &ndash; from its root to its last element. Therefore, it is possible for `checkChild()` to return `false` even though
256
- * the `context` last element can contain the checked child. It happens if one of the `context` elements does not allow its child.
257
- * When `context` is verified, {@link module:engine/model/schema~ModelSchema#addChildCheck custom checks} are considered as well.
258
- *
259
- * @fires checkChild
260
- * @param context The context in which the child will be checked.
261
- * @param def The child to check.
262
- */
263
- checkChild(context: ModelSchemaContextDefinition, def: string | ModelNode | ModelDocumentFragment): boolean;
264
- /**
265
- * Checks whether the given attribute can be applied in the given context (on the last item of the context).
266
- *
267
- * ```ts
268
- * schema.checkAttribute( textNode, 'bold' ); // -> false
269
- *
270
- * schema.extend( '$text', {
271
- * allowAttributes: 'bold'
272
- * } );
273
- *
274
- * schema.checkAttribute( textNode, 'bold' ); // -> true
275
- * ```
276
- *
277
- * Both {@link module:engine/model/schema~ModelSchema#addAttributeCheck callback checks} and declarative rules (added when
278
- * {@link module:engine/model/schema~ModelSchema#register registering} and
279
- * {@link module:engine/model/schema~ModelSchema#extend extending} items)
280
- * are evaluated when this method is called.
281
- *
282
- * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
283
- *
284
- * @fires checkAttribute
285
- * @param context The context in which the attribute will be checked.
286
- * @param attributeName Name of attribute to check in the given context.
287
- */
288
- checkAttribute(context: ModelSchemaContextDefinition, attributeName: string): boolean;
289
- checkMerge(position: ModelPosition): boolean;
290
- checkMerge(baseElement: ModelElement, elementToMerge: ModelElement): boolean;
291
- /**
292
- * Allows registering a callback to the {@link #checkChild} method calls.
293
- *
294
- * Callbacks allow you to implement rules which are not otherwise possible to achieve
295
- * by using the declarative API of {@link module:engine/model/schema~ModelSchemaItemDefinition}.
296
- *
297
- * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
298
- *
299
- * For example, by using this method you can disallow elements in specific contexts:
300
- *
301
- * ```ts
302
- * // Disallow `heading1` inside a `blockQuote` that is inside a table.
303
- * schema.addChildCheck( ( context, childDefinition ) => {
304
- * if ( context.endsWith( 'tableCell blockQuote' ) ) {
305
- * return false;
306
- * }
307
- * }, 'heading1' );
308
- * ```
309
- *
310
- * You can skip the optional `itemName` parameter to evaluate the callback for every `checkChild()` call.
311
- *
312
- * ```ts
313
- * // Inside specific custom element, allow only children, which allows for a specific attribute.
314
- * schema.addChildCheck( ( context, childDefinition ) => {
315
- * if ( context.endsWith( 'myElement' ) ) {
316
- * return childDefinition.allowAttributes.includes( 'myAttribute' );
317
- * }
318
- * } );
319
- * ```
320
- *
321
- * Please note that the generic callbacks may affect the editor performance and should be avoided if possible.
322
- *
323
- * When one of the callbacks makes a decision (returns `true` or `false`) the processing is finished and other callbacks are not fired.
324
- * Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.
325
- *
326
- * You can also use `checkChild` event, if you need even better control. The result from the example above could also be
327
- * achieved with following event callback:
328
- *
329
- * ```ts
330
- * schema.on( 'checkChild', ( evt, args ) => {
331
- * const context = args[ 0 ];
332
- * const childDefinition = args[ 1 ];
333
- *
334
- * if ( context.endsWith( 'myElement' ) ) {
335
- * // Prevent next listeners from being called.
336
- * evt.stop();
337
- * // Set the `checkChild()` return value.
338
- * evt.return = childDefinition.allowAttributes.includes( 'myAttribute' );
339
- * }
340
- * }, { priority: 'high' } );
341
- * ```
342
- *
343
- * Note that the callback checks and declarative rules checks are processed on `normal` priority.
344
- *
345
- * Adding callbacks this way can also negatively impact editor performance.
346
- *
347
- * @param callback The callback to be called. It is called with two parameters:
348
- * {@link module:engine/model/schema~ModelSchemaContext} (context) instance and
349
- * {@link module:engine/model/schema~ModelSchemaCompiledItemDefinition} (definition). The callback may return `true/false` to
350
- * override `checkChild()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks) will define
351
- * `checkChild()`'s return value.
352
- * @param itemName Name of the schema item for which the callback is registered. If specified, the callback will be run only for
353
- * `checkChild()` calls which `def` parameter matches the `itemName`. Otherwise, the callback will run for every `checkChild` call.
354
- */
355
- addChildCheck(callback: ModelSchemaChildCheckCallback, itemName?: string): void;
356
- /**
357
- * Allows registering a callback to the {@link #checkAttribute} method calls.
358
- *
359
- * Callbacks allow you to implement rules which are not otherwise possible to achieve
360
- * by using the declarative API of {@link module:engine/model/schema~ModelSchemaItemDefinition}.
361
- *
362
- * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
363
- *
364
- * For example, by using this method you can disallow setting attributes on nodes in specific contexts:
365
- *
366
- * ```ts
367
- * // Disallow setting `bold` on text inside `heading1` element:
368
- * schema.addAttributeCheck( context => {
369
- * if ( context.endsWith( 'heading1 $text' ) ) {
370
- * return false;
371
- * }
372
- * }, 'bold' );
373
- * ```
374
- *
375
- * You can skip the optional `attributeName` parameter to evaluate the callback for every `checkAttribute()` call.
376
- *
377
- * ```ts
378
- * // Disallow formatting attributes on text inside custom `myTitle` element:
379
- * schema.addAttributeCheck( ( context, attributeName ) => {
380
- * if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
381
- * return false;
382
- * }
383
- * } );
384
- * ```
385
- *
386
- * Please note that the generic callbacks may affect the editor performance and should be avoided if possible.
387
- *
388
- * When one of the callbacks makes a decision (returns `true` or `false`) the processing is finished and other callbacks are not fired.
389
- * Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.
390
- *
391
- * You can also use {@link #event:checkAttribute} event, if you need even better control. The result from the example above could also
392
- * be achieved with following event callback:
393
- *
394
- * ```ts
395
- * schema.on( 'checkAttribute', ( evt, args ) => {
396
- * const context = args[ 0 ];
397
- * const attributeName = args[ 1 ];
398
- *
399
- * if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
400
- * // Prevent next listeners from being called.
401
- * evt.stop();
402
- * // Set the `checkAttribute()` return value.
403
- * evt.return = false;
404
- * }
405
- * }, { priority: 'high' } );
406
- * ```
407
- *
408
- * Note that the callback checks and declarative rules checks are processed on `normal` priority.
409
- *
410
- * Adding callbacks this way can also negatively impact editor performance.
411
- *
412
- * @param callback The callback to be called. It is called with two parameters:
413
- * {@link module:engine/model/schema~ModelSchemaContext `context`} and attribute name. The callback may return `true` or `false`, to
414
- * override `checkAttribute()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks)
415
- * will define `checkAttribute()`'s return value.
416
- * @param attributeName Name of the attribute for which the callback is registered. If specified, the callback will be run only for
417
- * `checkAttribute()` calls with matching `attributeName`. Otherwise, the callback will run for every `checkAttribute()` call.
418
- */
419
- addAttributeCheck(callback: ModelSchemaAttributeCheckCallback, attributeName?: string): void;
420
- /**
421
- * This method allows assigning additional metadata to the model attributes. For example,
422
- * {@link module:engine/model/schema~ModelAttributeProperties `AttributeProperties#isFormatting` property} is
423
- * used to mark formatting attributes (like `bold` or `italic`).
424
- *
425
- * ```ts
426
- * // Mark bold as a formatting attribute.
427
- * schema.setAttributeProperties( 'bold', {
428
- * isFormatting: true
429
- * } );
430
- *
431
- * // Override code not to be considered a formatting markup.
432
- * schema.setAttributeProperties( 'code', {
433
- * isFormatting: false
434
- * } );
435
- * ```
436
- *
437
- * Properties are not limited to members defined in the
438
- * {@link module:engine/model/schema~ModelAttributeProperties `AttributeProperties` type} and you can also use custom properties:
439
- *
440
- * ```ts
441
- * schema.setAttributeProperties( 'blockQuote', {
442
- * customProperty: 'value'
443
- * } );
444
- * ```
445
- *
446
- * Subsequent calls with the same attribute will extend its custom properties:
447
- *
448
- * ```ts
449
- * schema.setAttributeProperties( 'blockQuote', {
450
- * one: 1
451
- * } );
452
- *
453
- * schema.setAttributeProperties( 'blockQuote', {
454
- * two: 2
455
- * } );
456
- *
457
- * console.log( schema.getAttributeProperties( 'blockQuote' ) );
458
- * // Logs: { one: 1, two: 2 }
459
- * ```
460
- *
461
- * @param attributeName A name of the attribute to receive the properties.
462
- * @param properties A dictionary of properties.
463
- */
464
- setAttributeProperties(attributeName: string, properties: ModelAttributeProperties): void;
465
- /**
466
- * Returns properties associated with a given model attribute. See {@link #setAttributeProperties `setAttributeProperties()`}.
467
- *
468
- * @param attributeName A name of the attribute.
469
- */
470
- getAttributeProperties(attributeName: string): ModelAttributeProperties;
471
- /**
472
- * Returns the lowest {@link module:engine/model/schema~ModelSchema#isLimit limit element} containing the entire
473
- * selection/range/position or the root otherwise.
474
- *
475
- * @param selectionOrRangeOrPosition The selection/range/position to check.
476
- * @returns The lowest limit element containing the entire `selectionOrRangeOrPosition`.
477
- */
478
- getLimitElement(selectionOrRangeOrPosition: ModelSelection | ModelDocumentSelection | ModelRange | ModelPosition): ModelElement;
479
- /**
480
- * Checks whether the attribute is allowed in selection:
481
- *
482
- * * if the selection is not collapsed, then checks if the attribute is allowed on any of nodes in that range,
483
- * * if the selection is collapsed, then checks if on the selection position there's a text with the
484
- * specified attribute allowed.
485
- *
486
- * @param selection Selection which will be checked.
487
- * @param attribute The name of the attribute to check.
488
- */
489
- checkAttributeInSelection(selection: ModelSelection | ModelDocumentSelection, attribute: string): boolean;
490
- /**
491
- * Transforms the given set of ranges into a set of ranges where the given attribute is allowed (and can be applied).
492
- *
493
- * @param ranges Ranges to be validated.
494
- * @param attribute The name of the attribute to check.
495
- * @param options Optional configuration.
496
- * @param options.includeEmptyRanges When `true`, empty ranges that allow the attribute are also included
497
- * in the returned ranges.
498
- * @returns Ranges in which the attribute is allowed.
499
- */
500
- getValidRanges(ranges: Iterable<ModelRange>, attribute: string, options?: {
501
- includeEmptyRanges?: boolean;
502
- }): IterableIterator<ModelRange>;
503
- /**
504
- * Basing on given `position`, finds and returns a {@link module:engine/model/range~ModelRange range} which is
505
- * nearest to that `position` and is a correct range for selection.
506
- *
507
- * The correct selection range might be collapsed when it is located in a position where the text node can be placed.
508
- * Non-collapsed range is returned when selection can be placed around element marked as an "object" in
509
- * the {@link module:engine/model/schema~ModelSchema schema}.
510
- *
511
- * Direction of searching for the nearest correct selection range can be specified as:
512
- *
513
- * * `both` - searching will be performed in both ways,
514
- * * `forward` - searching will be performed only forward,
515
- * * `backward` - searching will be performed only backward.
516
- *
517
- * When valid selection range cannot be found, `null` is returned.
518
- *
519
- * @param position Reference position where new selection range should be looked for.
520
- * @param direction Search direction.
521
- * @returns Nearest selection range or `null` if one cannot be found.
522
- */
523
- getNearestSelectionRange(position: ModelPosition, direction?: 'both' | 'forward' | 'backward'): ModelRange | null;
524
- /**
525
- * Tries to find position ancestors that allow to insert a given node.
526
- * It starts searching from the given position and goes node by node to the top of the model tree
527
- * as long as a {@link module:engine/model/schema~ModelSchema#isLimit limit element}, an
528
- * {@link module:engine/model/schema~ModelSchema#isObject object element} or a topmost ancestor is not reached.
529
- *
530
- * @param position The position that the search will start from.
531
- * @param node The node for which an allowed parent should be found or its name.
532
- * @returns Allowed parent or null if nothing was found.
533
- */
534
- findAllowedParent(position: ModelPosition, node: ModelNode | string): ModelElement | null;
535
- /**
536
- * Sets attributes allowed by the schema on a given node.
537
- *
538
- * @param node A node to set attributes on.
539
- * @param attributes Attributes keys and values.
540
- * @param writer An instance of the model writer.
541
- */
542
- setAllowedAttributes(node: ModelNode, attributes: Record<string, unknown>, writer: ModelWriter): void;
543
- /**
544
- * Removes attributes disallowed by the schema.
545
- *
546
- * @param nodes Nodes that will be filtered.
547
- */
548
- removeDisallowedAttributes(nodes: Iterable<ModelNode>, writer: ModelWriter): void;
549
- /**
550
- * Gets attributes of a node that have a given property.
551
- *
552
- * @param node Node to get attributes from.
553
- * @param propertyName Name of the property that attribute must have to return it.
554
- * @param propertyValue Desired value of the property that we want to check.
555
- * When `undefined` attributes will be returned if they have set a given property no matter what the value is. If specified it will
556
- * return attributes which given property's value is equal to this parameter.
557
- * @returns Object with attributes' names as key and attributes' values as value.
558
- */
559
- getAttributesWithProperty(node: ModelNode, propertyName: string, propertyValue: unknown): Record<string, unknown>;
560
- /**
561
- * Creates an instance of the schema context.
562
- */
563
- createContext(context: ModelSchemaContextDefinition): ModelSchemaContext;
564
- private _clearCache;
565
- private _compile;
566
- private _checkContextMatch;
567
- /**
568
- * Calls child check callbacks to decide whether `def` is allowed in `context`. It uses both generic and specific (defined for `def`
569
- * item) callbacks. If neither callback makes a decision, `undefined` is returned.
570
- *
571
- * Note that the first callback that makes a decision "wins", i.e., if any callback returns `true` or `false`, then the processing
572
- * is over and that result is returned.
573
- */
574
- private _evaluateChildChecks;
575
- /**
576
- * Calls attribute check callbacks to decide whether `attributeName` can be set on the last element of `context`. It uses both
577
- * generic and specific (defined for `attributeName`) callbacks. If neither callback makes a decision, `undefined` is returned.
578
- *
579
- * Note that the first callback that makes a decision "wins", i.e., if any callback returns `true` or `false`, then the processing
580
- * is over and that result is returned.
581
- */
582
- private _evaluateAttributeChecks;
583
- /**
584
- * Takes a flat range and an attribute name. Traverses the range recursively and deeply to find and return all ranges
585
- * inside the given range on which the attribute can be applied.
586
- *
587
- * This is a helper function for {@link ~ModelSchema#getValidRanges}.
588
- *
589
- * @param range The range to process.
590
- * @param attribute The name of the attribute to check.
591
- * @returns Ranges in which the attribute is allowed.
592
- */
593
- private _getValidRangesForRange;
594
- /**
595
- * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
596
- *
597
- * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
598
- * will be returned so that it is not split. If the selection is at the end of a paragraph,
599
- * the collapsed range after this paragraph will be returned.
600
- *
601
- * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
602
- * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
603
- * by the inserted widget block.
604
- *
605
- * @internal
606
- * @param selection The selection based on which the insertion position should be calculated.
607
- * @param place The place where to look for optimal insertion range.
608
- * The `auto` value will determine itself the best position for insertion.
609
- * The `before` value will try to find a position before selection.
610
- * The `after` value will try to find a position after selection.
611
- * @returns The optimal range.
612
- */
613
- findOptimalInsertionRange(selection: ModelSelection | ModelDocumentSelection, place?: 'auto' | 'before' | 'after'): ModelRange;
20
+ * The model's schema. It defines the allowed and disallowed structures of nodes as well as nodes' attributes.
21
+ * The schema is usually defined by the features and based on them, the editing framework and features
22
+ * make decisions on how to change and process the model.
23
+ *
24
+ * The instance of schema is available in {@link module:engine/model/model~Model#schema `editor.model.schema`}.
25
+ *
26
+ * Read more about the schema in:
27
+ *
28
+ * * The {@glink framework/architecture/editing-engine#schema schema section} of the
29
+ * {@glink framework/architecture/editing-engine Introduction to the Editing engine architecture} guide.
30
+ * * The {@glink framework/deep-dive/schema Schema deep-dive} guide.
31
+ */
32
+ export declare class ModelSchema extends ModelSchemaBase {
33
+ private readonly _sourceDefinitions;
34
+ /**
35
+ * A dictionary containing attribute properties.
36
+ */
37
+ private readonly _attributeProperties;
38
+ /**
39
+ * Stores additional callbacks registered for schema items, which are evaluated when {@link ~ModelSchema#checkChild} is called.
40
+ *
41
+ * Keys are schema item names for which the callbacks are registered. Values are arrays with the callbacks.
42
+ *
43
+ * Some checks are added under {@link ~ModelSchema#_genericCheckSymbol} key, these are
44
+ * evaluated for every {@link ~ModelSchema#checkChild} call.
45
+ */
46
+ private readonly _customChildChecks;
47
+ /**
48
+ * Stores additional callbacks registered for attribute names, which are evaluated when {@link ~ModelSchema#checkAttribute} is called.
49
+ *
50
+ * Keys are schema attribute names for which the callbacks are registered. Values are arrays with the callbacks.
51
+ *
52
+ * Some checks are added under {@link ~ModelSchema#_genericCheckSymbol} key, these are evaluated for every
53
+ * {@link ~ModelSchema#checkAttribute} call.
54
+ */
55
+ private readonly _customAttributeChecks;
56
+ private readonly _genericCheckSymbol;
57
+ private _compiledDefinitions?;
58
+ /**
59
+ * Creates a schema instance.
60
+ */
61
+ constructor();
62
+ /**
63
+ * Registers a schema item. Can only be called once for every item name.
64
+ *
65
+ * ```ts
66
+ * schema.register( 'paragraph', {
67
+ * inheritAllFrom: '$block'
68
+ * } );
69
+ * ```
70
+ */
71
+ register(itemName: string, definition?: ModelSchemaItemDefinition): void;
72
+ /**
73
+ * Extends a {@link #register registered} item's definition.
74
+ *
75
+ * Extending properties such as `allowIn` will add more items to the existing properties,
76
+ * while redefining properties such as `isBlock` will override the previously defined ones.
77
+ *
78
+ * ```ts
79
+ * schema.register( 'foo', {
80
+ * allowIn: '$root',
81
+ * isBlock: true;
82
+ * } );
83
+ * schema.extend( 'foo', {
84
+ * allowIn: 'blockQuote',
85
+ * isBlock: false
86
+ * } );
87
+ *
88
+ * schema.getDefinition( 'foo' );
89
+ * // {
90
+ * // allowIn: [ '$root', 'blockQuote' ],
91
+ * // isBlock: false
92
+ * // }
93
+ * ```
94
+ */
95
+ extend(itemName: string, definition: ModelSchemaItemDefinition): void;
96
+ /**
97
+ * Returns data of all registered items.
98
+ *
99
+ * This method should normally be used for reflection purposes (e.g. defining a clone of a certain element,
100
+ * checking a list of all block elements, etc).
101
+ * Use specific methods (such as {@link #checkChild `checkChild()`} or {@link #isLimit `isLimit()`})
102
+ * in other cases.
103
+ */
104
+ getDefinitions(): Record<string, ModelSchemaCompiledItemDefinition>;
105
+ /**
106
+ * Returns a definition of the given item or `undefined` if an item is not registered.
107
+ *
108
+ * This method should normally be used for reflection purposes (e.g. defining a clone of a certain element,
109
+ * checking a list of all block elements, etc).
110
+ * Use specific methods (such as {@link #checkChild `checkChild()`} or {@link #isLimit `isLimit()`})
111
+ * in other cases.
112
+ */
113
+ getDefinition(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): ModelSchemaCompiledItemDefinition | undefined;
114
+ /**
115
+ * Returns `true` if the given item is registered in the schema.
116
+ *
117
+ * ```ts
118
+ * schema.isRegistered( 'paragraph' ); // -> true
119
+ * schema.isRegistered( editor.model.document.getRoot() ); // -> true
120
+ * schema.isRegistered( 'foo' ); // -> false
121
+ * ```
122
+ */
123
+ isRegistered(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
124
+ /**
125
+ * Returns `true` if the given item is defined to be
126
+ * a block by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isBlock` property.
127
+ *
128
+ * ```ts
129
+ * schema.isBlock( 'paragraph' ); // -> true
130
+ * schema.isBlock( '$root' ); // -> false
131
+ *
132
+ * const paragraphElement = writer.createElement( 'paragraph' );
133
+ * schema.isBlock( paragraphElement ); // -> true
134
+ * ```
135
+ *
136
+ * See the {@glink framework/deep-dive/schema#block-elements Block elements} section of
137
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
138
+ */
139
+ isBlock(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
140
+ /**
141
+ * Returns `true` if the given item should be treated as a limit element.
142
+ *
143
+ * It considers an item to be a limit element if its
144
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition}'s
145
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition#isLimit `isLimit`} or
146
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition#isObject `isObject`} property
147
+ * was set to `true`.
148
+ *
149
+ * ```ts
150
+ * schema.isLimit( 'paragraph' ); // -> false
151
+ * schema.isLimit( '$root' ); // -> true
152
+ * schema.isLimit( editor.model.document.getRoot() ); // -> true
153
+ * schema.isLimit( 'imageBlock' ); // -> true
154
+ * ```
155
+ *
156
+ * See the {@glink framework/deep-dive/schema#limit-elements Limit elements} section of
157
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
158
+ */
159
+ isLimit(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
160
+ /**
161
+ * Returns `true` if the given item should be treated as an object element.
162
+ *
163
+ * It considers an item to be an object element if its
164
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition}'s
165
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition#isObject `isObject`} property
166
+ * was set to `true`.
167
+ *
168
+ * ```ts
169
+ * schema.isObject( 'paragraph' ); // -> false
170
+ * schema.isObject( 'imageBlock' ); // -> true
171
+ *
172
+ * const imageElement = writer.createElement( 'imageBlock' );
173
+ * schema.isObject( imageElement ); // -> true
174
+ * ```
175
+ *
176
+ * See the {@glink framework/deep-dive/schema#object-elements Object elements} section of
177
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
178
+ */
179
+ isObject(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
180
+ /**
181
+ * Returns `true` if the given item is defined to be
182
+ * an inline element by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isInline` property.
183
+ *
184
+ * ```ts
185
+ * schema.isInline( 'paragraph' ); // -> false
186
+ * schema.isInline( 'softBreak' ); // -> true
187
+ *
188
+ * const text = writer.createText( 'foo' );
189
+ * schema.isInline( text ); // -> true
190
+ * ```
191
+ *
192
+ * See the {@glink framework/deep-dive/schema#inline-elements Inline elements} section of
193
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
194
+ */
195
+ isInline(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
196
+ /**
197
+ * Returns `true` if the given item is defined to be
198
+ * a selectable element by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isSelectable` property.
199
+ *
200
+ * ```ts
201
+ * schema.isSelectable( 'paragraph' ); // -> false
202
+ * schema.isSelectable( 'heading1' ); // -> false
203
+ * schema.isSelectable( 'imageBlock' ); // -> true
204
+ * schema.isSelectable( 'tableCell' ); // -> true
205
+ *
206
+ * const text = writer.createText( 'foo' );
207
+ * schema.isSelectable( text ); // -> false
208
+ * ```
209
+ *
210
+ * See the {@glink framework/deep-dive/schema#selectable-elements Selectable elements section} of
211
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
212
+ */
213
+ isSelectable(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
214
+ /**
215
+ * Returns `true` if the given item is defined to be
216
+ * a content by the {@link module:engine/model/schema~ModelSchemaItemDefinition}'s `isContent` property.
217
+ *
218
+ * ```ts
219
+ * schema.isContent( 'paragraph' ); // -> false
220
+ * schema.isContent( 'heading1' ); // -> false
221
+ * schema.isContent( 'imageBlock' ); // -> true
222
+ * schema.isContent( 'horizontalLine' ); // -> true
223
+ *
224
+ * const text = writer.createText( 'foo' );
225
+ * schema.isContent( text ); // -> true
226
+ * ```
227
+ *
228
+ * See the {@glink framework/deep-dive/schema#content-elements Content elements section} of
229
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
230
+ */
231
+ isContent(item: string | ModelItem | ModelDocumentFragment | ModelSchemaContextItem): boolean;
232
+ /**
233
+ * Checks whether the given node can be a child of the given context.
234
+ *
235
+ * ```ts
236
+ * schema.checkChild( model.document.getRoot(), paragraph ); // -> false
237
+ *
238
+ * schema.register( 'paragraph', {
239
+ * allowIn: '$root'
240
+ * } );
241
+ *
242
+ * schema.checkChild( model.document.getRoot(), paragraph ); // -> true
243
+ * ```
244
+ *
245
+ * Both {@link module:engine/model/schema~ModelSchema#addChildCheck callback checks} and declarative rules (added when
246
+ * {@link module:engine/model/schema~ModelSchema#register registering} and
247
+ * {@link module:engine/model/schema~ModelSchema#extend extending} items)
248
+ * are evaluated when this method is called.
249
+ *
250
+ * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
251
+ *
252
+ * Note that when verifying whether the given node can be a child of the given context, the schema also verifies the entire
253
+ * context &ndash; from its root to its last element. Therefore, it is possible for `checkChild()` to return `false` even though
254
+ * the `context` last element can contain the checked child. It happens if one of the `context` elements does not allow its child.
255
+ * When `context` is verified, {@link module:engine/model/schema~ModelSchema#addChildCheck custom checks} are considered as well.
256
+ *
257
+ * @fires checkChild
258
+ * @param context The context in which the child will be checked.
259
+ * @param def The child to check.
260
+ */
261
+ checkChild(context: ModelSchemaContextDefinition, def: string | ModelNode | ModelDocumentFragment): boolean;
262
+ /**
263
+ * Checks whether the given attribute can be applied in the given context (on the last item of the context).
264
+ *
265
+ * ```ts
266
+ * schema.checkAttribute( textNode, 'bold' ); // -> false
267
+ *
268
+ * schema.extend( '$text', {
269
+ * allowAttributes: 'bold'
270
+ * } );
271
+ *
272
+ * schema.checkAttribute( textNode, 'bold' ); // -> true
273
+ * ```
274
+ *
275
+ * Both {@link module:engine/model/schema~ModelSchema#addAttributeCheck callback checks} and declarative rules (added when
276
+ * {@link module:engine/model/schema~ModelSchema#register registering} and
277
+ * {@link module:engine/model/schema~ModelSchema#extend extending} items)
278
+ * are evaluated when this method is called.
279
+ *
280
+ * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
281
+ *
282
+ * @fires checkAttribute
283
+ * @param context The context in which the attribute will be checked.
284
+ * @param attributeName Name of attribute to check in the given context.
285
+ */
286
+ checkAttribute(context: ModelSchemaContextDefinition, attributeName: string): boolean;
287
+ checkMerge(position: ModelPosition): boolean;
288
+ checkMerge(baseElement: ModelElement, elementToMerge: ModelElement): boolean;
289
+ /**
290
+ * Allows registering a callback to the {@link #checkChild} method calls.
291
+ *
292
+ * Callbacks allow you to implement rules which are not otherwise possible to achieve
293
+ * by using the declarative API of {@link module:engine/model/schema~ModelSchemaItemDefinition}.
294
+ *
295
+ * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
296
+ *
297
+ * For example, by using this method you can disallow elements in specific contexts:
298
+ *
299
+ * ```ts
300
+ * // Disallow `heading1` inside a `blockQuote` that is inside a table.
301
+ * schema.addChildCheck( ( context, childDefinition ) => {
302
+ * if ( context.endsWith( 'tableCell blockQuote' ) ) {
303
+ * return false;
304
+ * }
305
+ * }, 'heading1' );
306
+ * ```
307
+ *
308
+ * You can skip the optional `itemName` parameter to evaluate the callback for every `checkChild()` call.
309
+ *
310
+ * ```ts
311
+ * // Inside specific custom element, allow only children, which allows for a specific attribute.
312
+ * schema.addChildCheck( ( context, childDefinition ) => {
313
+ * if ( context.endsWith( 'myElement' ) ) {
314
+ * return childDefinition.allowAttributes.includes( 'myAttribute' );
315
+ * }
316
+ * } );
317
+ * ```
318
+ *
319
+ * Please note that the generic callbacks may affect the editor performance and should be avoided if possible.
320
+ *
321
+ * When one of the callbacks makes a decision (returns `true` or `false`) the processing is finished and other callbacks are not fired.
322
+ * Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.
323
+ *
324
+ * You can also use `checkChild` event, if you need even better control. The result from the example above could also be
325
+ * achieved with following event callback:
326
+ *
327
+ * ```ts
328
+ * schema.on( 'checkChild', ( evt, args ) => {
329
+ * const context = args[ 0 ];
330
+ * const childDefinition = args[ 1 ];
331
+ *
332
+ * if ( context.endsWith( 'myElement' ) ) {
333
+ * // Prevent next listeners from being called.
334
+ * evt.stop();
335
+ * // Set the `checkChild()` return value.
336
+ * evt.return = childDefinition.allowAttributes.includes( 'myAttribute' );
337
+ * }
338
+ * }, { priority: 'high' } );
339
+ * ```
340
+ *
341
+ * Note that the callback checks and declarative rules checks are processed on `normal` priority.
342
+ *
343
+ * Adding callbacks this way can also negatively impact editor performance.
344
+ *
345
+ * @param callback The callback to be called. It is called with two parameters:
346
+ * {@link module:engine/model/schema~ModelSchemaContext} (context) instance and
347
+ * {@link module:engine/model/schema~ModelSchemaCompiledItemDefinition} (definition). The callback may return `true/false` to
348
+ * override `checkChild()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks) will define
349
+ * `checkChild()`'s return value.
350
+ * @param itemName Name of the schema item for which the callback is registered. If specified, the callback will be run only for
351
+ * `checkChild()` calls which `def` parameter matches the `itemName`. Otherwise, the callback will run for every `checkChild` call.
352
+ */
353
+ addChildCheck(callback: ModelSchemaChildCheckCallback, itemName?: string): void;
354
+ /**
355
+ * Allows registering a callback to the {@link #checkAttribute} method calls.
356
+ *
357
+ * Callbacks allow you to implement rules which are not otherwise possible to achieve
358
+ * by using the declarative API of {@link module:engine/model/schema~ModelSchemaItemDefinition}.
359
+ *
360
+ * Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
361
+ *
362
+ * For example, by using this method you can disallow setting attributes on nodes in specific contexts:
363
+ *
364
+ * ```ts
365
+ * // Disallow setting `bold` on text inside `heading1` element:
366
+ * schema.addAttributeCheck( context => {
367
+ * if ( context.endsWith( 'heading1 $text' ) ) {
368
+ * return false;
369
+ * }
370
+ * }, 'bold' );
371
+ * ```
372
+ *
373
+ * You can skip the optional `attributeName` parameter to evaluate the callback for every `checkAttribute()` call.
374
+ *
375
+ * ```ts
376
+ * // Disallow formatting attributes on text inside custom `myTitle` element:
377
+ * schema.addAttributeCheck( ( context, attributeName ) => {
378
+ * if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
379
+ * return false;
380
+ * }
381
+ * } );
382
+ * ```
383
+ *
384
+ * Please note that the generic callbacks may affect the editor performance and should be avoided if possible.
385
+ *
386
+ * When one of the callbacks makes a decision (returns `true` or `false`) the processing is finished and other callbacks are not fired.
387
+ * Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.
388
+ *
389
+ * You can also use {@link #event:checkAttribute} event, if you need even better control. The result from the example above could also
390
+ * be achieved with following event callback:
391
+ *
392
+ * ```ts
393
+ * schema.on( 'checkAttribute', ( evt, args ) => {
394
+ * const context = args[ 0 ];
395
+ * const attributeName = args[ 1 ];
396
+ *
397
+ * if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
398
+ * // Prevent next listeners from being called.
399
+ * evt.stop();
400
+ * // Set the `checkAttribute()` return value.
401
+ * evt.return = false;
402
+ * }
403
+ * }, { priority: 'high' } );
404
+ * ```
405
+ *
406
+ * Note that the callback checks and declarative rules checks are processed on `normal` priority.
407
+ *
408
+ * Adding callbacks this way can also negatively impact editor performance.
409
+ *
410
+ * @param callback The callback to be called. It is called with two parameters:
411
+ * {@link module:engine/model/schema~ModelSchemaContext `context`} and attribute name. The callback may return `true` or `false`, to
412
+ * override `checkAttribute()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks)
413
+ * will define `checkAttribute()`'s return value.
414
+ * @param attributeName Name of the attribute for which the callback is registered. If specified, the callback will be run only for
415
+ * `checkAttribute()` calls with matching `attributeName`. Otherwise, the callback will run for every `checkAttribute()` call.
416
+ */
417
+ addAttributeCheck(callback: ModelSchemaAttributeCheckCallback, attributeName?: string): void;
418
+ /**
419
+ * This method allows assigning additional metadata to the model attributes. For example,
420
+ * {@link module:engine/model/schema~ModelAttributeProperties `AttributeProperties#isFormatting` property} is
421
+ * used to mark formatting attributes (like `bold` or `italic`).
422
+ *
423
+ * ```ts
424
+ * // Mark bold as a formatting attribute.
425
+ * schema.setAttributeProperties( 'bold', {
426
+ * isFormatting: true
427
+ * } );
428
+ *
429
+ * // Override code not to be considered a formatting markup.
430
+ * schema.setAttributeProperties( 'code', {
431
+ * isFormatting: false
432
+ * } );
433
+ * ```
434
+ *
435
+ * Properties are not limited to members defined in the
436
+ * {@link module:engine/model/schema~ModelAttributeProperties `AttributeProperties` type} and you can also use custom properties:
437
+ *
438
+ * ```ts
439
+ * schema.setAttributeProperties( 'blockQuote', {
440
+ * customProperty: 'value'
441
+ * } );
442
+ * ```
443
+ *
444
+ * Subsequent calls with the same attribute will extend its custom properties:
445
+ *
446
+ * ```ts
447
+ * schema.setAttributeProperties( 'blockQuote', {
448
+ * one: 1
449
+ * } );
450
+ *
451
+ * schema.setAttributeProperties( 'blockQuote', {
452
+ * two: 2
453
+ * } );
454
+ *
455
+ * console.log( schema.getAttributeProperties( 'blockQuote' ) );
456
+ * // Logs: { one: 1, two: 2 }
457
+ * ```
458
+ *
459
+ * @param attributeName A name of the attribute to receive the properties.
460
+ * @param properties A dictionary of properties.
461
+ */
462
+ setAttributeProperties(attributeName: string, properties: ModelAttributeProperties): void;
463
+ /**
464
+ * Returns properties associated with a given model attribute. See {@link #setAttributeProperties `setAttributeProperties()`}.
465
+ *
466
+ * @param attributeName A name of the attribute.
467
+ */
468
+ getAttributeProperties(attributeName: string): ModelAttributeProperties;
469
+ /**
470
+ * Returns the lowest {@link module:engine/model/schema~ModelSchema#isLimit limit element} containing the entire
471
+ * selection/range/position or the root otherwise.
472
+ *
473
+ * @param selectionOrRangeOrPosition The selection/range/position to check.
474
+ * @returns The lowest limit element containing the entire `selectionOrRangeOrPosition`.
475
+ */
476
+ getLimitElement(selectionOrRangeOrPosition: ModelSelection | ModelDocumentSelection | ModelRange | ModelPosition): ModelElement;
477
+ /**
478
+ * Checks whether the attribute is allowed in selection:
479
+ *
480
+ * * if the selection is not collapsed, then checks if the attribute is allowed on any of nodes in that range,
481
+ * * if the selection is collapsed, then checks if on the selection position there's a text with the
482
+ * specified attribute allowed.
483
+ *
484
+ * @param selection Selection which will be checked.
485
+ * @param attribute The name of the attribute to check.
486
+ */
487
+ checkAttributeInSelection(selection: ModelSelection | ModelDocumentSelection, attribute: string): boolean;
488
+ /**
489
+ * Transforms the given set of ranges into a set of ranges where the given attribute is allowed (and can be applied).
490
+ *
491
+ * @param ranges Ranges to be validated.
492
+ * @param attribute The name of the attribute to check.
493
+ * @param options Optional configuration.
494
+ * @param options.includeEmptyRanges When `true`, empty ranges that allow the attribute are also included
495
+ * in the returned ranges.
496
+ * @returns Ranges in which the attribute is allowed.
497
+ */
498
+ getValidRanges(ranges: Iterable<ModelRange>, attribute: string, options?: {
499
+ includeEmptyRanges?: boolean;
500
+ }): IterableIterator<ModelRange>;
501
+ /**
502
+ * Basing on given `position`, finds and returns a {@link module:engine/model/range~ModelRange range} which is
503
+ * nearest to that `position` and is a correct range for selection.
504
+ *
505
+ * The correct selection range might be collapsed when it is located in a position where the text node can be placed.
506
+ * Non-collapsed range is returned when selection can be placed around element marked as an "object" in
507
+ * the {@link module:engine/model/schema~ModelSchema schema}.
508
+ *
509
+ * Direction of searching for the nearest correct selection range can be specified as:
510
+ *
511
+ * * `both` - searching will be performed in both ways,
512
+ * * `forward` - searching will be performed only forward,
513
+ * * `backward` - searching will be performed only backward.
514
+ *
515
+ * When valid selection range cannot be found, `null` is returned.
516
+ *
517
+ * @param position Reference position where new selection range should be looked for.
518
+ * @param direction Search direction.
519
+ * @returns Nearest selection range or `null` if one cannot be found.
520
+ */
521
+ getNearestSelectionRange(position: ModelPosition, direction?: "both" | "forward" | "backward"): ModelRange | null;
522
+ /**
523
+ * Tries to find position ancestors that allow to insert a given node.
524
+ * It starts searching from the given position and goes node by node to the top of the model tree
525
+ * as long as a {@link module:engine/model/schema~ModelSchema#isLimit limit element}, an
526
+ * {@link module:engine/model/schema~ModelSchema#isObject object element} or a topmost ancestor is not reached.
527
+ *
528
+ * @param position The position that the search will start from.
529
+ * @param node The node for which an allowed parent should be found or its name.
530
+ * @returns Allowed parent or null if nothing was found.
531
+ */
532
+ findAllowedParent(position: ModelPosition, node: ModelNode | string): ModelElement | null;
533
+ /**
534
+ * Sets attributes allowed by the schema on a given node.
535
+ *
536
+ * @param node A node to set attributes on.
537
+ * @param attributes Attributes keys and values.
538
+ * @param writer An instance of the model writer.
539
+ */
540
+ setAllowedAttributes(node: ModelNode, attributes: Record<string, unknown>, writer: ModelWriter): void;
541
+ /**
542
+ * Removes attributes disallowed by the schema.
543
+ *
544
+ * @param nodes Nodes that will be filtered.
545
+ */
546
+ removeDisallowedAttributes(nodes: Iterable<ModelNode>, writer: ModelWriter): void;
547
+ /**
548
+ * Gets attributes of a node that have a given property.
549
+ *
550
+ * @param node Node to get attributes from.
551
+ * @param propertyName Name of the property that attribute must have to return it.
552
+ * @param propertyValue Desired value of the property that we want to check.
553
+ * When `undefined` attributes will be returned if they have set a given property no matter what the value is. If specified it will
554
+ * return attributes which given property's value is equal to this parameter.
555
+ * @returns Object with attributes' names as key and attributes' values as value.
556
+ */
557
+ getAttributesWithProperty(node: ModelNode, propertyName: string, propertyValue: unknown): Record<string, unknown>;
558
+ /**
559
+ * Creates an instance of the schema context.
560
+ */
561
+ createContext(context: ModelSchemaContextDefinition): ModelSchemaContext;
562
+ private _clearCache;
563
+ private _compile;
564
+ private _checkContextMatch;
565
+ /**
566
+ * Calls child check callbacks to decide whether `def` is allowed in `context`. It uses both generic and specific (defined for `def`
567
+ * item) callbacks. If neither callback makes a decision, `undefined` is returned.
568
+ *
569
+ * Note that the first callback that makes a decision "wins", i.e., if any callback returns `true` or `false`, then the processing
570
+ * is over and that result is returned.
571
+ */
572
+ private _evaluateChildChecks;
573
+ /**
574
+ * Calls attribute check callbacks to decide whether `attributeName` can be set on the last element of `context`. It uses both
575
+ * generic and specific (defined for `attributeName`) callbacks. If neither callback makes a decision, `undefined` is returned.
576
+ *
577
+ * Note that the first callback that makes a decision "wins", i.e., if any callback returns `true` or `false`, then the processing
578
+ * is over and that result is returned.
579
+ */
580
+ private _evaluateAttributeChecks;
581
+ /**
582
+ * Takes a flat range and an attribute name. Traverses the range recursively and deeply to find and return all ranges
583
+ * inside the given range on which the attribute can be applied.
584
+ *
585
+ * This is a helper function for {@link ~ModelSchema#getValidRanges}.
586
+ *
587
+ * @param range The range to process.
588
+ * @param attribute The name of the attribute to check.
589
+ * @returns Ranges in which the attribute is allowed.
590
+ */
591
+ private _getValidRangesForRange;
592
+ /**
593
+ * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
594
+ *
595
+ * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
596
+ * will be returned so that it is not split. If the selection is at the end of a paragraph,
597
+ * the collapsed range after this paragraph will be returned.
598
+ *
599
+ * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
600
+ * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
601
+ * by the inserted widget block.
602
+ *
603
+ * @internal
604
+ * @param selection The selection based on which the insertion position should be calculated.
605
+ * @param place The place where to look for optimal insertion range.
606
+ * The `auto` value will determine itself the best position for insertion.
607
+ * The `before` value will try to find a position before selection.
608
+ * The `after` value will try to find a position after selection.
609
+ * @returns The optimal range.
610
+ */
611
+ findOptimalInsertionRange(selection: ModelSelection | ModelDocumentSelection, place?: "auto" | "before" | "after"): ModelRange;
614
612
  }
615
613
  /**
616
- * Event fired when the {@link ~ModelSchema#checkChild} method is called. It allows plugging in
617
- * additional behavior, for example implementing rules which cannot be defined using the declarative
618
- * {@link module:engine/model/schema~ModelSchemaItemDefinition} interface.
619
- *
620
- * **Note:** The {@link ~ModelSchema#addChildCheck} method is a more handy way to register callbacks. Internally,
621
- * it registers a listener to this event but comes with a simpler API and it is the recommended choice
622
- * in most of the cases.
623
- *
624
- * The {@link ~ModelSchema#checkChild} method fires an event because it is
625
- * {@link module:utils/observablemixin~Observable#decorate decorated} with it. Thanks to that you can
626
- * use this event in various ways, but the most important use case is overriding standard behavior of the
627
- * `checkChild()` method. Let's see a typical listener template:
628
- *
629
- * ```ts
630
- * schema.on( 'checkChild', ( evt, args ) => {
631
- * const context = args[ 0 ];
632
- * const childDefinition = args[ 1 ];
633
- * }, { priority: 'high' } );
634
- * ```
635
- *
636
- * The listener is added with a `high` priority to be executed before the default method is really called. The `args` callback
637
- * parameter contains arguments passed to `checkChild( context, child )`. However, the `context` parameter is already
638
- * normalized to a {@link module:engine/model/schema~ModelSchemaContext} instance and `child` to a
639
- * {@link module:engine/model/schema~ModelSchemaCompiledItemDefinition} instance, so you do not have to worry about
640
- * the various ways how `context` and `child` may be passed to `checkChild()`.
641
- *
642
- * **Note:** `childDefinition` may be `undefined` if `checkChild()` was called with a non-registered element.
643
- *
644
- * So, in order to implement a rule "disallow `heading1` in `blockQuote`", you can add such a listener:
645
- *
646
- * ```ts
647
- * schema.on( 'checkChild', ( evt, args ) => {
648
- * const context = args[ 0 ];
649
- * const childDefinition = args[ 1 ];
650
- *
651
- * if ( context.endsWith( 'blockQuote' ) && childDefinition && childDefinition.name == 'heading1' ) {
652
- * // Prevent next listeners from being called.
653
- * evt.stop();
654
- * // Set the checkChild()'s return value.
655
- * evt.return = false;
656
- * }
657
- * }, { priority: 'high' } );
658
- * ```
659
- *
660
- * Allowing elements in specific contexts will be a far less common use case, because it is normally handled by the
661
- * `allowIn` rule from {@link module:engine/model/schema~ModelSchemaItemDefinition}. But if you have a complex scenario
662
- * where `listItem` should be allowed only in element `foo` which must be in element `bar`, then this would be the way:
663
- *
664
- * ```ts
665
- * schema.on( 'checkChild', ( evt, args ) => {
666
- * const context = args[ 0 ];
667
- * const childDefinition = args[ 1 ];
668
- *
669
- * if ( context.endsWith( 'bar foo' ) && childDefinition.name == 'listItem' ) {
670
- * // Prevent next listeners from being called.
671
- * evt.stop();
672
- * // Set the checkChild()'s return value.
673
- * evt.return = true;
674
- * }
675
- * }, { priority: 'high' } );
676
- * ```
677
- *
678
- * @eventName ~ModelSchema#checkChild
679
- * @param args The `checkChild()`'s arguments.
680
- */
614
+ * Event fired when the {@link ~ModelSchema#checkChild} method is called. It allows plugging in
615
+ * additional behavior, for example implementing rules which cannot be defined using the declarative
616
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition} interface.
617
+ *
618
+ * **Note:** The {@link ~ModelSchema#addChildCheck} method is a more handy way to register callbacks. Internally,
619
+ * it registers a listener to this event but comes with a simpler API and it is the recommended choice
620
+ * in most of the cases.
621
+ *
622
+ * The {@link ~ModelSchema#checkChild} method fires an event because it is
623
+ * {@link module:utils/observablemixin~Observable#decorate decorated} with it. Thanks to that you can
624
+ * use this event in various ways, but the most important use case is overriding standard behavior of the
625
+ * `checkChild()` method. Let's see a typical listener template:
626
+ *
627
+ * ```ts
628
+ * schema.on( 'checkChild', ( evt, args ) => {
629
+ * const context = args[ 0 ];
630
+ * const childDefinition = args[ 1 ];
631
+ * }, { priority: 'high' } );
632
+ * ```
633
+ *
634
+ * The listener is added with a `high` priority to be executed before the default method is really called. The `args` callback
635
+ * parameter contains arguments passed to `checkChild( context, child )`. However, the `context` parameter is already
636
+ * normalized to a {@link module:engine/model/schema~ModelSchemaContext} instance and `child` to a
637
+ * {@link module:engine/model/schema~ModelSchemaCompiledItemDefinition} instance, so you do not have to worry about
638
+ * the various ways how `context` and `child` may be passed to `checkChild()`.
639
+ *
640
+ * **Note:** `childDefinition` may be `undefined` if `checkChild()` was called with a non-registered element.
641
+ *
642
+ * So, in order to implement a rule "disallow `heading1` in `blockQuote`", you can add such a listener:
643
+ *
644
+ * ```ts
645
+ * schema.on( 'checkChild', ( evt, args ) => {
646
+ * const context = args[ 0 ];
647
+ * const childDefinition = args[ 1 ];
648
+ *
649
+ * if ( context.endsWith( 'blockQuote' ) && childDefinition && childDefinition.name == 'heading1' ) {
650
+ * // Prevent next listeners from being called.
651
+ * evt.stop();
652
+ * // Set the checkChild()'s return value.
653
+ * evt.return = false;
654
+ * }
655
+ * }, { priority: 'high' } );
656
+ * ```
657
+ *
658
+ * Allowing elements in specific contexts will be a far less common use case, because it is normally handled by the
659
+ * `allowIn` rule from {@link module:engine/model/schema~ModelSchemaItemDefinition}. But if you have a complex scenario
660
+ * where `listItem` should be allowed only in element `foo` which must be in element `bar`, then this would be the way:
661
+ *
662
+ * ```ts
663
+ * schema.on( 'checkChild', ( evt, args ) => {
664
+ * const context = args[ 0 ];
665
+ * const childDefinition = args[ 1 ];
666
+ *
667
+ * if ( context.endsWith( 'bar foo' ) && childDefinition.name == 'listItem' ) {
668
+ * // Prevent next listeners from being called.
669
+ * evt.stop();
670
+ * // Set the checkChild()'s return value.
671
+ * evt.return = true;
672
+ * }
673
+ * }, { priority: 'high' } );
674
+ * ```
675
+ *
676
+ * @eventName ~ModelSchema#checkChild
677
+ * @param args The `checkChild()`'s arguments.
678
+ */
681
679
  export type ModelSchemaCheckChildEvent = {
682
- name: 'checkChild';
683
- args: [[context: ModelSchemaContext, def: ModelSchemaCompiledItemDefinition]];
680
+ name: "checkChild";
681
+ args: [[context: ModelSchemaContext, def: ModelSchemaCompiledItemDefinition]];
684
682
  };
685
683
  /**
686
- * Event fired when the {@link ~ModelSchema#checkAttribute} method is called. It allows plugging in
687
- * additional behavior, for example implementing rules which cannot be defined using the declarative
688
- * {@link module:engine/model/schema~ModelSchemaItemDefinition} interface.
689
- *
690
- * **Note:** The {@link ~ModelSchema#addAttributeCheck} method is a more handy way to register callbacks. Internally,
691
- * it registers a listener to this event but comes with a simpler API and it is the recommended choice
692
- * in most of the cases.
693
- *
694
- * The {@link ~ModelSchema#checkAttribute} method fires an event because it is
695
- * {@link module:utils/observablemixin~Observable#decorate decorated} with it. Thanks to that you can
696
- * use this event in various ways, but the most important use case is overriding the standard behavior of the
697
- * `checkAttribute()` method. Let's see a typical listener template:
698
- *
699
- * ```ts
700
- * schema.on( 'checkAttribute', ( evt, args ) => {
701
- * const context = args[ 0 ];
702
- * const attributeName = args[ 1 ];
703
- * }, { priority: 'high' } );
704
- * ```
705
- *
706
- * The listener is added with a `high` priority to be executed before the default method is really called. The `args` callback
707
- * parameter contains arguments passed to `checkAttribute( context, attributeName )`. However, the `context` parameter is already
708
- * normalized to a {@link module:engine/model/schema~ModelSchemaContext} instance, so you do not have to worry about
709
- * the various ways how `context` may be passed to `checkAttribute()`.
710
- *
711
- * So, in order to implement a rule "disallow `bold` in a text which is in a `heading1`, you can add such a listener:
712
- *
713
- * ```ts
714
- * schema.on( 'checkAttribute', ( evt, args ) => {
715
- * const context = args[ 0 ];
716
- * const attributeName = args[ 1 ];
717
- *
718
- * if ( context.endsWith( 'heading1 $text' ) && attributeName == 'bold' ) {
719
- * // Prevent next listeners from being called.
720
- * evt.stop();
721
- * // Set the checkAttribute()'s return value.
722
- * evt.return = false;
723
- * }
724
- * }, { priority: 'high' } );
725
- * ```
726
- *
727
- * Allowing attributes in specific contexts will be a far less common use case, because it is normally handled by the
728
- * `allowAttributes` rule from {@link module:engine/model/schema~ModelSchemaItemDefinition}. But if you have a complex scenario
729
- * where `bold` should be allowed only in element `foo` which must be in element `bar`, then this would be the way:
730
- *
731
- * ```ts
732
- * schema.on( 'checkAttribute', ( evt, args ) => {
733
- * const context = args[ 0 ];
734
- * const attributeName = args[ 1 ];
735
- *
736
- * if ( context.endsWith( 'bar foo $text' ) && attributeName == 'bold' ) {
737
- * // Prevent next listeners from being called.
738
- * evt.stop();
739
- * // Set the checkAttribute()'s return value.
740
- * evt.return = true;
741
- * }
742
- * }, { priority: 'high' } );
743
- * ```
744
- *
745
- * @eventName ~ModelSchema#checkAttribute
746
- * @param args The `checkAttribute()`'s arguments.
747
- */
684
+ * Event fired when the {@link ~ModelSchema#checkAttribute} method is called. It allows plugging in
685
+ * additional behavior, for example implementing rules which cannot be defined using the declarative
686
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition} interface.
687
+ *
688
+ * **Note:** The {@link ~ModelSchema#addAttributeCheck} method is a more handy way to register callbacks. Internally,
689
+ * it registers a listener to this event but comes with a simpler API and it is the recommended choice
690
+ * in most of the cases.
691
+ *
692
+ * The {@link ~ModelSchema#checkAttribute} method fires an event because it is
693
+ * {@link module:utils/observablemixin~Observable#decorate decorated} with it. Thanks to that you can
694
+ * use this event in various ways, but the most important use case is overriding the standard behavior of the
695
+ * `checkAttribute()` method. Let's see a typical listener template:
696
+ *
697
+ * ```ts
698
+ * schema.on( 'checkAttribute', ( evt, args ) => {
699
+ * const context = args[ 0 ];
700
+ * const attributeName = args[ 1 ];
701
+ * }, { priority: 'high' } );
702
+ * ```
703
+ *
704
+ * The listener is added with a `high` priority to be executed before the default method is really called. The `args` callback
705
+ * parameter contains arguments passed to `checkAttribute( context, attributeName )`. However, the `context` parameter is already
706
+ * normalized to a {@link module:engine/model/schema~ModelSchemaContext} instance, so you do not have to worry about
707
+ * the various ways how `context` may be passed to `checkAttribute()`.
708
+ *
709
+ * So, in order to implement a rule "disallow `bold` in a text which is in a `heading1`, you can add such a listener:
710
+ *
711
+ * ```ts
712
+ * schema.on( 'checkAttribute', ( evt, args ) => {
713
+ * const context = args[ 0 ];
714
+ * const attributeName = args[ 1 ];
715
+ *
716
+ * if ( context.endsWith( 'heading1 $text' ) && attributeName == 'bold' ) {
717
+ * // Prevent next listeners from being called.
718
+ * evt.stop();
719
+ * // Set the checkAttribute()'s return value.
720
+ * evt.return = false;
721
+ * }
722
+ * }, { priority: 'high' } );
723
+ * ```
724
+ *
725
+ * Allowing attributes in specific contexts will be a far less common use case, because it is normally handled by the
726
+ * `allowAttributes` rule from {@link module:engine/model/schema~ModelSchemaItemDefinition}. But if you have a complex scenario
727
+ * where `bold` should be allowed only in element `foo` which must be in element `bar`, then this would be the way:
728
+ *
729
+ * ```ts
730
+ * schema.on( 'checkAttribute', ( evt, args ) => {
731
+ * const context = args[ 0 ];
732
+ * const attributeName = args[ 1 ];
733
+ *
734
+ * if ( context.endsWith( 'bar foo $text' ) && attributeName == 'bold' ) {
735
+ * // Prevent next listeners from being called.
736
+ * evt.stop();
737
+ * // Set the checkAttribute()'s return value.
738
+ * evt.return = true;
739
+ * }
740
+ * }, { priority: 'high' } );
741
+ * ```
742
+ *
743
+ * @eventName ~ModelSchema#checkAttribute
744
+ * @param args The `checkAttribute()`'s arguments.
745
+ */
748
746
  export type ModelSchemaCheckAttributeEvent = {
749
- name: 'checkAttribute';
750
- args: [[context: ModelSchemaContext, attributeName: string]];
747
+ name: "checkAttribute";
748
+ args: [[context: ModelSchemaContext, attributeName: string]];
751
749
  };
752
750
  /**
753
- * A definition of a {@link module:engine/model/schema~ModelSchema schema} item.
754
- *
755
- * You can define the following rules:
756
- *
757
- * * {@link ~ModelSchemaItemDefinition#allowIn `allowIn`} &ndash; Defines in which other items this item will be allowed.
758
- * * {@link ~ModelSchemaItemDefinition#allowChildren `allowChildren`} &ndash; Defines which other items are allowed inside this item.
759
- * * {@link ~ModelSchemaItemDefinition#allowAttributes `allowAttributes`} &ndash; Defines allowed attributes of the given item.
760
- * * {@link ~ModelSchemaItemDefinition#disallowIn `disallowIn`} &ndash; Defines in which other items this item will be disallowed.
761
- * * {@link ~ModelSchemaItemDefinition#disallowChildren `disallowChildren`} &ndash; Defines which other items are
762
- * disallowed inside this item.
763
- * * {@link ~ModelSchemaItemDefinition#disallowAttributes `disallowAttributes`} &ndash; Defines disallowed attributes of the given item.
764
- * * {@link ~ModelSchemaItemDefinition#allowContentOf `allowContentOf`} &ndash; Makes this item allow children that are also allowed in the
765
- * specified items. This acknowledges disallow rules.
766
- * * {@link ~ModelSchemaItemDefinition#allowWhere `allowWhere`} &ndash; Makes this item allowed where the specified items are allowed. This
767
- * acknowledges disallow rules.
768
- * * {@link ~ModelSchemaItemDefinition#allowAttributesOf `allowAttributesOf`} &ndash; Inherits attributes from other items.
769
- * This acknowledges disallow rules.
770
- * * {@link ~ModelSchemaItemDefinition#inheritTypesFrom `inheritTypesFrom`} &ndash; Inherits `is*` properties of other items.
771
- * * {@link ~ModelSchemaItemDefinition#inheritAllFrom `inheritAllFrom`} &ndash;
772
- * A shorthand for `allowContentOf`, `allowWhere`, `allowAttributesOf`, `inheritTypesFrom`.
773
- *
774
- * # The `is*` properties
775
- *
776
- * There are a couple commonly used `is*` properties. Their role is to assign additional semantics to schema items.
777
- *
778
- * * {@link ~ModelSchemaItemDefinition#isBlock `isBlock`} &ndash; Whether this item is paragraph-like.
779
- * Generally speaking, content is usually made out of blocks like paragraphs, list items, images, headings, etc.
780
- * * {@link ~ModelSchemaItemDefinition#isInline `isInline`} &ndash; Whether an item is "text-like" and should be treated as an inline node.
781
- * Examples of inline elements: `$text`, `softBreak` (`<br>`), etc.
782
- * * {@link ~ModelSchemaItemDefinition#isLimit `isLimit`} &ndash; It can be understood as whether this element
783
- * should not be split by <kbd>Enter</kbd>. Examples of limit elements: `$root`, table cell, image caption, etc.
784
- * In other words, all actions that happen inside a limit element are limited to its content.
785
- * All objects are treated as limit elements, too.
786
- * * {@link ~ModelSchemaItemDefinition#isObject `isObject`} &ndash; Whether an item is "self-contained" and should be treated as a whole.
787
- * Examples of object elements: `imageBlock`, `table`, `video`, etc. An object is also a limit, so
788
- * {@link module:engine/model/schema~ModelSchema#isLimit `isLimit()`} returns `true` for object elements automatically.
789
- *
790
- * Read more about the meaning of these types in the
791
- * {@glink framework/deep-dive/schema#defining-additional-semantics dedicated section of the Schema deep-dive} guide.
792
- *
793
- * # Generic items
794
- *
795
- * There are several generic items (classes of elements) available: `$root`, `$container`, `$block`, `$blockObject`,
796
- * `$inlineObject`, and `$text`. They are defined as follows:
797
- *
798
- * ```ts
799
- * schema.register( '$root', {
800
- * isLimit: true
801
- * } );
802
- *
803
- * schema.register( '$container', {
804
- * allowIn: [ '$root', '$container' ]
805
- * } );
806
- *
807
- * schema.register( '$block', {
808
- * allowIn: [ '$root', '$container' ],
809
- * isBlock: true
810
- * } );
811
- *
812
- * schema.register( '$blockObject', {
813
- * allowWhere: '$block',
814
- * isBlock: true,
815
- * isObject: true
816
- * } );
817
- *
818
- * schema.register( '$inlineObject', {
819
- * allowWhere: '$text',
820
- * allowAttributesOf: '$text',
821
- * isInline: true,
822
- * isObject: true
823
- * } );
824
- *
825
- * schema.register( '$text', {
826
- * allowIn: '$block',
827
- * isInline: true,
828
- * isContent: true
829
- * } );
830
- * ```
831
- *
832
- * They reflect typical editor content that is contained within one root, consists of several blocks
833
- * (paragraphs, lists items, headings, images) which, in turn, may contain text inside.
834
- *
835
- * By inheriting from the generic items you can define new items which will get extended by other editor features.
836
- * Read more about generic types in the {@glink framework/deep-dive/schema Schema deep-dive} guide.
837
- *
838
- * # Example definitions
839
- *
840
- * Allow `paragraph` in roots and block quotes:
841
- *
842
- * ```ts
843
- * schema.register( 'paragraph', {
844
- * allowIn: [ '$root', 'blockQuote' ],
845
- * isBlock: true
846
- * } );
847
- * ```
848
- *
849
- * Allow `paragraph` everywhere where `$block` is allowed (i.e. in `$root`):
850
- *
851
- * ```ts
852
- * schema.register( 'paragraph', {
853
- * allowWhere: '$block',
854
- * isBlock: true
855
- * } );
856
- * ```
857
- *
858
- * Allow `paragraph` inside a `$root` and allow `$text` as a `paragraph` child:
859
- *
860
- * ```ts
861
- * schema.register( 'paragraph', {
862
- * allowIn: '$root',
863
- * allowChildren: '$text',
864
- * isBlock: true
865
- * } );
866
- * ```
867
- *
868
- * The previous rule can be written in a shorter form using inheritance:
869
- *
870
- * ```ts
871
- * schema.register( 'paragraph', {
872
- * inheritAllFrom: '$block'
873
- * } );
874
- * ```
875
- *
876
- * Make `imageBlock` a block object, which is allowed everywhere where `$block` is.
877
- * Also, allow `src` and `alt` attributes in it:
878
- *
879
- * ```ts
880
- * schema.register( 'imageBlock', {
881
- * inheritAllFrom: '$blockObject',
882
- * allowAttributes: [ 'src', 'alt' ],
883
- * } );
884
- * ```
885
- *
886
- * Make `caption` allowed in `imageBlock` and make it allow all the content of `$block`s (usually, `$text`).
887
- * Also, mark it as a limit element so it cannot be split:
888
- *
889
- * ```ts
890
- * schema.register( 'caption', {
891
- * allowIn: 'imageBlock',
892
- * allowContentOf: '$block',
893
- * isLimit: true
894
- * } );
895
- * ```
896
- *
897
- * Register `inlineImage` as a kind of an inline object but disallow it inside captions:
898
- *
899
- * ```ts
900
- * schema.register( 'imageInline', {
901
- * inheritAllFrom: '$inlineObject',
902
- * disallowIn: [ 'caption' ]
903
- * } );
904
- * ```
905
- *
906
- * Make `listItem` inherit all from `$block` but also allow additional attributes:
907
- *
908
- * ```ts
909
- * schema.register( 'listItem', {
910
- * inheritAllFrom: '$block',
911
- * allowAttributes: [ 'listType', 'listIndent' ]
912
- * } );
913
- * ```
914
- *
915
- * Which translates to:
916
- *
917
- * ```ts
918
- * schema.register( 'listItem', {
919
- * allowWhere: '$block',
920
- * allowContentOf: '$block',
921
- * allowAttributesOf: '$block',
922
- * inheritTypesFrom: '$block',
923
- * allowAttributes: [ 'listType', 'listIndent' ]
924
- * } );
925
- * ```
926
- *
927
- * # Tips
928
- *
929
- * * Check schema definitions of existing features to see how they are defined.
930
- * * If you want to publish your feature so other developers can use it, try to use
931
- * generic items as much as possible.
932
- * * Keep your model clean. Limit it to the actual data and store information in a normalized way.
933
- * * Remember about defining the `is*` properties. They do not affect the allowed structures, but they can
934
- * affect how the editor features treat your elements.
935
- */
751
+ * A definition of a {@link module:engine/model/schema~ModelSchema schema} item.
752
+ *
753
+ * You can define the following rules:
754
+ *
755
+ * * {@link ~ModelSchemaItemDefinition#allowIn `allowIn`} &ndash; Defines in which other items this item will be allowed.
756
+ * * {@link ~ModelSchemaItemDefinition#allowChildren `allowChildren`} &ndash; Defines which other items are allowed inside this item.
757
+ * * {@link ~ModelSchemaItemDefinition#allowAttributes `allowAttributes`} &ndash; Defines allowed attributes of the given item.
758
+ * * {@link ~ModelSchemaItemDefinition#disallowIn `disallowIn`} &ndash; Defines in which other items this item will be disallowed.
759
+ * * {@link ~ModelSchemaItemDefinition#disallowChildren `disallowChildren`} &ndash; Defines which other items are
760
+ * disallowed inside this item.
761
+ * * {@link ~ModelSchemaItemDefinition#disallowAttributes `disallowAttributes`} &ndash; Defines disallowed attributes of the given item.
762
+ * * {@link ~ModelSchemaItemDefinition#allowContentOf `allowContentOf`} &ndash; Makes this item allow children that are also allowed in the
763
+ * specified items. This acknowledges disallow rules.
764
+ * * {@link ~ModelSchemaItemDefinition#allowWhere `allowWhere`} &ndash; Makes this item allowed where the specified items are allowed. This
765
+ * acknowledges disallow rules.
766
+ * * {@link ~ModelSchemaItemDefinition#allowAttributesOf `allowAttributesOf`} &ndash; Inherits attributes from other items.
767
+ * This acknowledges disallow rules.
768
+ * * {@link ~ModelSchemaItemDefinition#inheritTypesFrom `inheritTypesFrom`} &ndash; Inherits `is*` properties of other items.
769
+ * * {@link ~ModelSchemaItemDefinition#inheritAllFrom `inheritAllFrom`} &ndash;
770
+ * A shorthand for `allowContentOf`, `allowWhere`, `allowAttributesOf`, `inheritTypesFrom`.
771
+ *
772
+ * # The `is*` properties
773
+ *
774
+ * There are a couple commonly used `is*` properties. Their role is to assign additional semantics to schema items.
775
+ *
776
+ * * {@link ~ModelSchemaItemDefinition#isBlock `isBlock`} &ndash; Whether this item is paragraph-like.
777
+ * Generally speaking, content is usually made out of blocks like paragraphs, list items, images, headings, etc.
778
+ * * {@link ~ModelSchemaItemDefinition#isInline `isInline`} &ndash; Whether an item is "text-like" and should be treated as an inline node.
779
+ * Examples of inline elements: `$text`, `softBreak` (`<br>`), etc.
780
+ * * {@link ~ModelSchemaItemDefinition#isLimit `isLimit`} &ndash; It can be understood as whether this element
781
+ * should not be split by <kbd>Enter</kbd>. Examples of limit elements: `$root`, table cell, image caption, etc.
782
+ * In other words, all actions that happen inside a limit element are limited to its content.
783
+ * All objects are treated as limit elements, too.
784
+ * * {@link ~ModelSchemaItemDefinition#isObject `isObject`} &ndash; Whether an item is "self-contained" and should be treated as a whole.
785
+ * Examples of object elements: `imageBlock`, `table`, `video`, etc. An object is also a limit, so
786
+ * {@link module:engine/model/schema~ModelSchema#isLimit `isLimit()`} returns `true` for object elements automatically.
787
+ *
788
+ * Read more about the meaning of these types in the
789
+ * {@glink framework/deep-dive/schema#defining-additional-semantics dedicated section of the Schema deep-dive} guide.
790
+ *
791
+ * # Generic items
792
+ *
793
+ * There are several generic items (classes of elements) available: `$root`, `$container`, `$block`, `$blockObject`,
794
+ * `$inlineObject`, and `$text`. They are defined as follows:
795
+ *
796
+ * ```ts
797
+ * schema.register( '$root', {
798
+ * isLimit: true
799
+ * } );
800
+ *
801
+ * schema.register( '$container', {
802
+ * allowIn: [ '$root', '$container' ]
803
+ * } );
804
+ *
805
+ * schema.register( '$block', {
806
+ * allowIn: [ '$root', '$container' ],
807
+ * isBlock: true
808
+ * } );
809
+ *
810
+ * schema.register( '$blockObject', {
811
+ * allowWhere: '$block',
812
+ * isBlock: true,
813
+ * isObject: true
814
+ * } );
815
+ *
816
+ * schema.register( '$inlineObject', {
817
+ * allowWhere: '$text',
818
+ * allowAttributesOf: '$text',
819
+ * isInline: true,
820
+ * isObject: true
821
+ * } );
822
+ *
823
+ * schema.register( '$text', {
824
+ * allowIn: '$block',
825
+ * isInline: true,
826
+ * isContent: true
827
+ * } );
828
+ * ```
829
+ *
830
+ * They reflect typical editor content that is contained within one root, consists of several blocks
831
+ * (paragraphs, lists items, headings, images) which, in turn, may contain text inside.
832
+ *
833
+ * By inheriting from the generic items you can define new items which will get extended by other editor features.
834
+ * Read more about generic types in the {@glink framework/deep-dive/schema Schema deep-dive} guide.
835
+ *
836
+ * # Example definitions
837
+ *
838
+ * Allow `paragraph` in roots and block quotes:
839
+ *
840
+ * ```ts
841
+ * schema.register( 'paragraph', {
842
+ * allowIn: [ '$root', 'blockQuote' ],
843
+ * isBlock: true
844
+ * } );
845
+ * ```
846
+ *
847
+ * Allow `paragraph` everywhere where `$block` is allowed (i.e. in `$root`):
848
+ *
849
+ * ```ts
850
+ * schema.register( 'paragraph', {
851
+ * allowWhere: '$block',
852
+ * isBlock: true
853
+ * } );
854
+ * ```
855
+ *
856
+ * Allow `paragraph` inside a `$root` and allow `$text` as a `paragraph` child:
857
+ *
858
+ * ```ts
859
+ * schema.register( 'paragraph', {
860
+ * allowIn: '$root',
861
+ * allowChildren: '$text',
862
+ * isBlock: true
863
+ * } );
864
+ * ```
865
+ *
866
+ * The previous rule can be written in a shorter form using inheritance:
867
+ *
868
+ * ```ts
869
+ * schema.register( 'paragraph', {
870
+ * inheritAllFrom: '$block'
871
+ * } );
872
+ * ```
873
+ *
874
+ * Make `imageBlock` a block object, which is allowed everywhere where `$block` is.
875
+ * Also, allow `src` and `alt` attributes in it:
876
+ *
877
+ * ```ts
878
+ * schema.register( 'imageBlock', {
879
+ * inheritAllFrom: '$blockObject',
880
+ * allowAttributes: [ 'src', 'alt' ],
881
+ * } );
882
+ * ```
883
+ *
884
+ * Make `caption` allowed in `imageBlock` and make it allow all the content of `$block`s (usually, `$text`).
885
+ * Also, mark it as a limit element so it cannot be split:
886
+ *
887
+ * ```ts
888
+ * schema.register( 'caption', {
889
+ * allowIn: 'imageBlock',
890
+ * allowContentOf: '$block',
891
+ * isLimit: true
892
+ * } );
893
+ * ```
894
+ *
895
+ * Register `inlineImage` as a kind of an inline object but disallow it inside captions:
896
+ *
897
+ * ```ts
898
+ * schema.register( 'imageInline', {
899
+ * inheritAllFrom: '$inlineObject',
900
+ * disallowIn: [ 'caption' ]
901
+ * } );
902
+ * ```
903
+ *
904
+ * Make `listItem` inherit all from `$block` but also allow additional attributes:
905
+ *
906
+ * ```ts
907
+ * schema.register( 'listItem', {
908
+ * inheritAllFrom: '$block',
909
+ * allowAttributes: [ 'listType', 'listIndent' ]
910
+ * } );
911
+ * ```
912
+ *
913
+ * Which translates to:
914
+ *
915
+ * ```ts
916
+ * schema.register( 'listItem', {
917
+ * allowWhere: '$block',
918
+ * allowContentOf: '$block',
919
+ * allowAttributesOf: '$block',
920
+ * inheritTypesFrom: '$block',
921
+ * allowAttributes: [ 'listType', 'listIndent' ]
922
+ * } );
923
+ * ```
924
+ *
925
+ * # Tips
926
+ *
927
+ * * Check schema definitions of existing features to see how they are defined.
928
+ * * If you want to publish your feature so other developers can use it, try to use
929
+ * generic items as much as possible.
930
+ * * Keep your model clean. Limit it to the actual data and store information in a normalized way.
931
+ * * Remember about defining the `is*` properties. They do not affect the allowed structures, but they can
932
+ * affect how the editor features treat your elements.
933
+ */
936
934
  export interface ModelSchemaItemDefinition {
937
- /**
938
- * Defines in which other items this item will be allowed.
939
- */
940
- allowIn?: string | Array<string>;
941
- /**
942
- * Defines which other items are allowed inside this item.
943
- */
944
- allowChildren?: string | Array<string>;
945
- /**
946
- * Defines allowed attributes of the given item.
947
- */
948
- allowAttributes?: string | Array<string>;
949
- /**
950
- * Defines in which other items this item will be disallowed. Takes precedence over allow rules.
951
- */
952
- disallowIn?: string | Array<string>;
953
- /**
954
- * Defines which other items are disallowed inside this item. Takes precedence over allow rules.
955
- */
956
- disallowChildren?: string | Array<string>;
957
- /**
958
- * Defines disallowed attributes for this item. Takes precedence over allow rules.
959
- */
960
- disallowAttributes?: string | Array<string>;
961
- /**
962
- * Inherits "allowed children" from other items.
963
- *
964
- * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
965
- */
966
- allowContentOf?: string | Array<string>;
967
- /**
968
- * Inherits "allowed in" from other items.
969
- *
970
- * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
971
- */
972
- allowWhere?: string | Array<string>;
973
- /**
974
- * Inherits "allowed attributes" from other items.
975
- *
976
- * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
977
- */
978
- allowAttributesOf?: string | Array<string>;
979
- /**
980
- * Inherits `is*` properties of other items.
981
- *
982
- * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
983
- */
984
- inheritTypesFrom?: string | Array<string>;
985
- /**
986
- * A shorthand for `allowContentOf`, `allowWhere`, `allowAttributesOf`, `inheritTypesFrom`.
987
- *
988
- * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
989
- */
990
- inheritAllFrom?: string;
991
- /**
992
- * Whether this item is paragraph-like. Generally speaking, content is usually made out of blocks
993
- * like paragraphs, list items, images, headings, etc. All these elements are marked as blocks. A block
994
- * should not allow another block inside. Note: There is also the `$block` generic item which has `isBlock` set to `true`.
995
- * Most block type items will inherit from `$block` (through `inheritAllFrom`).
996
- *
997
- * Read more about the block elements in the
998
- * {@glink framework/deep-dive/schema#block-elements Block elements section} of
999
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
1000
- */
1001
- isBlock?: boolean;
1002
- /**
1003
- * Whether an item is "text-like" and should be treated as an inline node. Examples of inline elements:
1004
- * `$text`, `softBreak` (`<br>`), etc.
1005
- *
1006
- * Read more about the inline elements in the
1007
- * {@glink framework/deep-dive/schema#inline-elements Inline elements section} of the Schema deep-dive guide.
1008
- */
1009
- isInline?: boolean;
1010
- /**
1011
- * It can be understood as whether this element should not be split by <kbd>Enter</kbd>.
1012
- * Examples of limit elements: `$root`, table cell, image caption, etc. In other words, all actions that happen inside
1013
- * a limit element are limited to its content.
1014
- *
1015
- * Read more about the limit elements in the
1016
- * {@glink framework/deep-dive/schema#limit-elements Limit elements section} of
1017
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
1018
- */
1019
- isLimit?: boolean;
1020
- /**
1021
- * Whether an item is "self-contained" and should be treated as a whole. Examples of object elements:
1022
- * `imageBlock`, `table`, `video`, etc.
1023
- *
1024
- * **Note:** An object is also a limit, so
1025
- * {@link module:engine/model/schema~ModelSchema#isLimit `isLimit()`} returns `true` for object elements automatically.
1026
- *
1027
- * Read more about the object elements in the
1028
- * {@glink framework/deep-dive/schema#object-elements Object elements section} of the Schema deep-dive guide.
1029
- */
1030
- isObject?: boolean;
1031
- /**
1032
- * `true` when an element should be selectable as a whole by the user.
1033
- * Examples of selectable elements: `imageBlock`, `table`, `tableCell`, etc.
1034
- *
1035
- * **Note:** An object is also a selectable element, so
1036
- * {@link module:engine/model/schema~ModelSchema#isSelectable `isSelectable()`} returns `true` for object elements automatically.
1037
- *
1038
- * Read more about selectable elements in the
1039
- * {@glink framework/deep-dive/schema#selectable-elements Selectable elements section} of
1040
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
1041
- */
1042
- isSelectable?: boolean;
1043
- /**
1044
- * An item is a content when it always finds its way to the editor data output regardless of the number and type of its descendants.
1045
- * Examples of content elements: `$text`, `imageBlock`, `table`, etc. (but not `paragraph`, `heading1` or `tableCell`).
1046
- *
1047
- * **Note:** An object is also a content element, so
1048
- * {@link module:engine/model/schema~ModelSchema#isContent `isContent()`} returns `true` for object elements automatically.
1049
- *
1050
- * Read more about content elements in the
1051
- * {@glink framework/deep-dive/schema#content-elements Content elements section} of
1052
- * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
1053
- */
1054
- isContent?: boolean;
935
+ /**
936
+ * Defines in which other items this item will be allowed.
937
+ */
938
+ allowIn?: string | Array<string>;
939
+ /**
940
+ * Defines which other items are allowed inside this item.
941
+ */
942
+ allowChildren?: string | Array<string>;
943
+ /**
944
+ * Defines allowed attributes of the given item.
945
+ */
946
+ allowAttributes?: string | Array<string>;
947
+ /**
948
+ * Defines in which other items this item will be disallowed. Takes precedence over allow rules.
949
+ */
950
+ disallowIn?: string | Array<string>;
951
+ /**
952
+ * Defines which other items are disallowed inside this item. Takes precedence over allow rules.
953
+ */
954
+ disallowChildren?: string | Array<string>;
955
+ /**
956
+ * Defines disallowed attributes for this item. Takes precedence over allow rules.
957
+ */
958
+ disallowAttributes?: string | Array<string>;
959
+ /**
960
+ * Inherits "allowed children" from other items.
961
+ *
962
+ * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
963
+ */
964
+ allowContentOf?: string | Array<string>;
965
+ /**
966
+ * Inherits "allowed in" from other items.
967
+ *
968
+ * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
969
+ */
970
+ allowWhere?: string | Array<string>;
971
+ /**
972
+ * Inherits "allowed attributes" from other items.
973
+ *
974
+ * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
975
+ */
976
+ allowAttributesOf?: string | Array<string>;
977
+ /**
978
+ * Inherits `is*` properties of other items.
979
+ *
980
+ * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
981
+ */
982
+ inheritTypesFrom?: string | Array<string>;
983
+ /**
984
+ * A shorthand for `allowContentOf`, `allowWhere`, `allowAttributesOf`, `inheritTypesFrom`.
985
+ *
986
+ * Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
987
+ */
988
+ inheritAllFrom?: string;
989
+ /**
990
+ * Whether this item is paragraph-like. Generally speaking, content is usually made out of blocks
991
+ * like paragraphs, list items, images, headings, etc. All these elements are marked as blocks. A block
992
+ * should not allow another block inside. Note: There is also the `$block` generic item which has `isBlock` set to `true`.
993
+ * Most block type items will inherit from `$block` (through `inheritAllFrom`).
994
+ *
995
+ * Read more about the block elements in the
996
+ * {@glink framework/deep-dive/schema#block-elements Block elements section} of
997
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
998
+ */
999
+ isBlock?: boolean;
1000
+ /**
1001
+ * Whether an item is "text-like" and should be treated as an inline node. Examples of inline elements:
1002
+ * `$text`, `softBreak` (`<br>`), etc.
1003
+ *
1004
+ * Read more about the inline elements in the
1005
+ * {@glink framework/deep-dive/schema#inline-elements Inline elements section} of the Schema deep-dive guide.
1006
+ */
1007
+ isInline?: boolean;
1008
+ /**
1009
+ * It can be understood as whether this element should not be split by <kbd>Enter</kbd>.
1010
+ * Examples of limit elements: `$root`, table cell, image caption, etc. In other words, all actions that happen inside
1011
+ * a limit element are limited to its content.
1012
+ *
1013
+ * Read more about the limit elements in the
1014
+ * {@glink framework/deep-dive/schema#limit-elements Limit elements section} of
1015
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
1016
+ */
1017
+ isLimit?: boolean;
1018
+ /**
1019
+ * Whether an item is "self-contained" and should be treated as a whole. Examples of object elements:
1020
+ * `imageBlock`, `table`, `video`, etc.
1021
+ *
1022
+ * **Note:** An object is also a limit, so
1023
+ * {@link module:engine/model/schema~ModelSchema#isLimit `isLimit()`} returns `true` for object elements automatically.
1024
+ *
1025
+ * Read more about the object elements in the
1026
+ * {@glink framework/deep-dive/schema#object-elements Object elements section} of the Schema deep-dive guide.
1027
+ */
1028
+ isObject?: boolean;
1029
+ /**
1030
+ * `true` when an element should be selectable as a whole by the user.
1031
+ * Examples of selectable elements: `imageBlock`, `table`, `tableCell`, etc.
1032
+ *
1033
+ * **Note:** An object is also a selectable element, so
1034
+ * {@link module:engine/model/schema~ModelSchema#isSelectable `isSelectable()`} returns `true` for object elements automatically.
1035
+ *
1036
+ * Read more about selectable elements in the
1037
+ * {@glink framework/deep-dive/schema#selectable-elements Selectable elements section} of
1038
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
1039
+ */
1040
+ isSelectable?: boolean;
1041
+ /**
1042
+ * An item is a content when it always finds its way to the editor data output regardless of the number and type of its descendants.
1043
+ * Examples of content elements: `$text`, `imageBlock`, `table`, etc. (but not `paragraph`, `heading1` or `tableCell`).
1044
+ *
1045
+ * **Note:** An object is also a content element, so
1046
+ * {@link module:engine/model/schema~ModelSchema#isContent `isContent()`} returns `true` for object elements automatically.
1047
+ *
1048
+ * Read more about content elements in the
1049
+ * {@glink framework/deep-dive/schema#content-elements Content elements section} of
1050
+ * the {@glink framework/deep-dive/schema Schema deep-dive} guide.
1051
+ */
1052
+ isContent?: boolean;
1055
1053
  }
1056
1054
  /**
1057
- * A simplified version of {@link module:engine/model/schema~ModelSchemaItemDefinition} after
1058
- * compilation by the {@link module:engine/model/schema~ModelSchema schema}.
1059
- * Rules fed to the schema by {@link module:engine/model/schema~ModelSchema#register}
1060
- * and {@link module:engine/model/schema~ModelSchema#extend} methods are defined in the
1061
- * {@link module:engine/model/schema~ModelSchemaItemDefinition} format.
1062
- * Later on, they are compiled to `ModelSchemaCompiledItemDefinition` so when you use e.g.
1063
- * the {@link module:engine/model/schema~ModelSchema#getDefinition} method you get the compiled version.
1064
- *
1065
- * The compiled version contains only the following properties:
1066
- *
1067
- * * The `name` property,
1068
- * * The `is*` properties,
1069
- * * The `allowIn` array,
1070
- * * The `allowChildren` array,
1071
- * * The `allowAttributes` array.
1072
- */
1055
+ * A simplified version of {@link module:engine/model/schema~ModelSchemaItemDefinition} after
1056
+ * compilation by the {@link module:engine/model/schema~ModelSchema schema}.
1057
+ * Rules fed to the schema by {@link module:engine/model/schema~ModelSchema#register}
1058
+ * and {@link module:engine/model/schema~ModelSchema#extend} methods are defined in the
1059
+ * {@link module:engine/model/schema~ModelSchemaItemDefinition} format.
1060
+ * Later on, they are compiled to `ModelSchemaCompiledItemDefinition` so when you use e.g.
1061
+ * the {@link module:engine/model/schema~ModelSchema#getDefinition} method you get the compiled version.
1062
+ *
1063
+ * The compiled version contains only the following properties:
1064
+ *
1065
+ * * The `name` property,
1066
+ * * The `is*` properties,
1067
+ * * The `allowIn` array,
1068
+ * * The `allowChildren` array,
1069
+ * * The `allowAttributes` array.
1070
+ */
1073
1071
  export interface ModelSchemaCompiledItemDefinition {
1074
- name: string;
1075
- isBlock: boolean;
1076
- isContent: boolean;
1077
- isInline: boolean;
1078
- isLimit: boolean;
1079
- isObject: boolean;
1080
- isSelectable: boolean;
1081
- allowIn: Array<string>;
1082
- allowChildren: Array<string>;
1083
- allowAttributes: Array<string>;
1072
+ name: string;
1073
+ isBlock: boolean;
1074
+ isContent: boolean;
1075
+ isInline: boolean;
1076
+ isLimit: boolean;
1077
+ isObject: boolean;
1078
+ isSelectable: boolean;
1079
+ allowIn: Array<string>;
1080
+ allowChildren: Array<string>;
1081
+ allowAttributes: Array<string>;
1084
1082
  }
1085
1083
  /**
1086
- * A schema context &ndash; a list of ancestors of a given position in the document.
1087
- *
1088
- * Considering such position:
1089
- *
1090
- * ```xml
1091
- * <$root>
1092
- * <blockQuote>
1093
- * <paragraph>
1094
- * ^
1095
- * </paragraph>
1096
- * </blockQuote>
1097
- * </$root>
1098
- * ```
1099
- *
1100
- * The context of this position is its {@link module:engine/model/position~ModelPosition#getAncestors lists of ancestors}:
1101
- *
1102
- * [ rootElement, blockQuoteElement, paragraphElement ]
1103
- *
1104
- * Contexts are used in the {@link module:engine/model/schema~ModelSchema#event:checkChild `Schema#checkChild`} and
1105
- * {@link module:engine/model/schema~ModelSchema#event:checkAttribute `Schema#checkAttribute`} events as a definition
1106
- * of a place in the document where the check occurs. The context instances are created based on the first arguments
1107
- * of the {@link module:engine/model/schema~ModelSchema#checkChild `Schema#checkChild()`} and
1108
- * {@link module:engine/model/schema~ModelSchema#checkAttribute `Schema#checkAttribute()`} methods so when
1109
- * using these methods you need to use {@link module:engine/model/schema~ModelSchemaContextDefinition}s.
1110
- */
1084
+ * A schema context &ndash; a list of ancestors of a given position in the document.
1085
+ *
1086
+ * Considering such position:
1087
+ *
1088
+ * ```xml
1089
+ * <$root>
1090
+ * <blockQuote>
1091
+ * <paragraph>
1092
+ * ^
1093
+ * </paragraph>
1094
+ * </blockQuote>
1095
+ * </$root>
1096
+ * ```
1097
+ *
1098
+ * The context of this position is its {@link module:engine/model/position~ModelPosition#getAncestors lists of ancestors}:
1099
+ *
1100
+ * [ rootElement, blockQuoteElement, paragraphElement ]
1101
+ *
1102
+ * Contexts are used in the {@link module:engine/model/schema~ModelSchema#event:checkChild `Schema#checkChild`} and
1103
+ * {@link module:engine/model/schema~ModelSchema#event:checkAttribute `Schema#checkAttribute`} events as a definition
1104
+ * of a place in the document where the check occurs. The context instances are created based on the first arguments
1105
+ * of the {@link module:engine/model/schema~ModelSchema#checkChild `Schema#checkChild()`} and
1106
+ * {@link module:engine/model/schema~ModelSchema#checkAttribute `Schema#checkAttribute()`} methods so when
1107
+ * using these methods you need to use {@link module:engine/model/schema~ModelSchemaContextDefinition}s.
1108
+ */
1111
1109
  export declare class ModelSchemaContext implements Iterable<ModelSchemaContextItem> {
1112
- private _items;
1113
- /**
1114
- * Creates an instance of the context.
1115
- */
1116
- constructor(context: ModelSchemaContextDefinition);
1117
- /**
1118
- * The number of items.
1119
- */
1120
- get length(): number;
1121
- /**
1122
- * The last item (the lowest node).
1123
- */
1124
- get last(): ModelSchemaContextItem;
1125
- /**
1126
- * Iterable interface.
1127
- *
1128
- * Iterates over all context items.
1129
- */
1130
- [Symbol.iterator](): IterableIterator<ModelSchemaContextItem>;
1131
- /**
1132
- * Returns a new schema context instance with an additional item.
1133
- *
1134
- * Item can be added as:
1135
- *
1136
- * ```ts
1137
- * const context = new ModelSchemaContext( [ '$root' ] );
1138
- *
1139
- * // An element.
1140
- * const fooElement = writer.createElement( 'fooElement' );
1141
- * const newContext = context.push( fooElement ); // [ '$root', 'fooElement' ]
1142
- *
1143
- * // A text node.
1144
- * const text = writer.createText( 'foobar' );
1145
- * const newContext = context.push( text ); // [ '$root', '$text' ]
1146
- *
1147
- * // A string (element name).
1148
- * const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]
1149
- * ```
1150
- *
1151
- * **Note** {@link module:engine/model/node~ModelNode} that is already in the model tree will be added as the only item
1152
- * (without ancestors).
1153
- *
1154
- * @param item An item that will be added to the current context.
1155
- * @returns A new schema context instance with an additional item.
1156
- */
1157
- push(item: string | ModelNode): ModelSchemaContext;
1158
- /**
1159
- * Returns a new schema context that is based on this context but has the last item removed.
1160
- *
1161
- * ```ts
1162
- * const ctxParagraph = new ModelSchemaContext( [ '$root', 'blockQuote', 'paragraph' ] );
1163
- * const ctxBlockQuote = ctxParagraph.trimLast(); // Items in `ctxBlockQuote` are: `$root` an `blockQuote`.
1164
- * const ctxRoot = ctxBlockQuote.trimLast(); // Items in `ctxRoot` are: `$root`.
1165
- * ```
1166
- *
1167
- * @returns A new reduced schema context instance.
1168
- */
1169
- trimLast(): ModelSchemaContext;
1170
- /**
1171
- * Gets an item on the given index.
1172
- */
1173
- getItem(index: number): ModelSchemaContextItem;
1174
- /**
1175
- * Returns the names of items.
1176
- */
1177
- getNames(): IterableIterator<string>;
1178
- /**
1179
- * Checks whether the context ends with the given nodes.
1180
- *
1181
- * ```ts
1182
- * const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] );
1183
- *
1184
- * ctx.endsWith( '$text' ); // -> true
1185
- * ctx.endsWith( 'paragraph $text' ); // -> true
1186
- * ctx.endsWith( '$root' ); // -> false
1187
- * ctx.endsWith( 'paragraph' ); // -> false
1188
- * ```
1189
- */
1190
- endsWith(query: string): boolean;
1191
- /**
1192
- * Checks whether the context starts with the given nodes.
1193
- *
1194
- * ```ts
1195
- * const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] );
1196
- *
1197
- * ctx.endsWith( '$root' ); // -> true
1198
- * ctx.endsWith( '$root paragraph' ); // -> true
1199
- * ctx.endsWith( '$text' ); // -> false
1200
- * ctx.endsWith( 'paragraph' ); // -> false
1201
- * ```
1202
- */
1203
- startsWith(query: string): boolean;
1110
+ private _items;
1111
+ /**
1112
+ * Creates an instance of the context.
1113
+ */
1114
+ constructor(context: ModelSchemaContextDefinition);
1115
+ /**
1116
+ * The number of items.
1117
+ */
1118
+ get length(): number;
1119
+ /**
1120
+ * The last item (the lowest node).
1121
+ */
1122
+ get last(): ModelSchemaContextItem;
1123
+ /**
1124
+ * Iterable interface.
1125
+ *
1126
+ * Iterates over all context items.
1127
+ */
1128
+ [Symbol.iterator](): IterableIterator<ModelSchemaContextItem>;
1129
+ /**
1130
+ * Returns a new schema context instance with an additional item.
1131
+ *
1132
+ * Item can be added as:
1133
+ *
1134
+ * ```ts
1135
+ * const context = new ModelSchemaContext( [ '$root' ] );
1136
+ *
1137
+ * // An element.
1138
+ * const fooElement = writer.createElement( 'fooElement' );
1139
+ * const newContext = context.push( fooElement ); // [ '$root', 'fooElement' ]
1140
+ *
1141
+ * // A text node.
1142
+ * const text = writer.createText( 'foobar' );
1143
+ * const newContext = context.push( text ); // [ '$root', '$text' ]
1144
+ *
1145
+ * // A string (element name).
1146
+ * const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]
1147
+ * ```
1148
+ *
1149
+ * **Note** {@link module:engine/model/node~ModelNode} that is already in the model tree will be added as the only item
1150
+ * (without ancestors).
1151
+ *
1152
+ * @param item An item that will be added to the current context.
1153
+ * @returns A new schema context instance with an additional item.
1154
+ */
1155
+ push(item: string | ModelNode): ModelSchemaContext;
1156
+ /**
1157
+ * Returns a new schema context that is based on this context but has the last item removed.
1158
+ *
1159
+ * ```ts
1160
+ * const ctxParagraph = new ModelSchemaContext( [ '$root', 'blockQuote', 'paragraph' ] );
1161
+ * const ctxBlockQuote = ctxParagraph.trimLast(); // Items in `ctxBlockQuote` are: `$root` an `blockQuote`.
1162
+ * const ctxRoot = ctxBlockQuote.trimLast(); // Items in `ctxRoot` are: `$root`.
1163
+ * ```
1164
+ *
1165
+ * @returns A new reduced schema context instance.
1166
+ */
1167
+ trimLast(): ModelSchemaContext;
1168
+ /**
1169
+ * Gets an item on the given index.
1170
+ */
1171
+ getItem(index: number): ModelSchemaContextItem;
1172
+ /**
1173
+ * Returns the names of items.
1174
+ */
1175
+ getNames(): IterableIterator<string>;
1176
+ /**
1177
+ * Checks whether the context ends with the given nodes.
1178
+ *
1179
+ * ```ts
1180
+ * const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] );
1181
+ *
1182
+ * ctx.endsWith( '$text' ); // -> true
1183
+ * ctx.endsWith( 'paragraph $text' ); // -> true
1184
+ * ctx.endsWith( '$root' ); // -> false
1185
+ * ctx.endsWith( 'paragraph' ); // -> false
1186
+ * ```
1187
+ */
1188
+ endsWith(query: string): boolean;
1189
+ /**
1190
+ * Checks whether the context starts with the given nodes.
1191
+ *
1192
+ * ```ts
1193
+ * const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] );
1194
+ *
1195
+ * ctx.endsWith( '$root' ); // -> true
1196
+ * ctx.endsWith( '$root paragraph' ); // -> true
1197
+ * ctx.endsWith( '$text' ); // -> false
1198
+ * ctx.endsWith( 'paragraph' ); // -> false
1199
+ * ```
1200
+ */
1201
+ startsWith(query: string): boolean;
1204
1202
  }
1205
1203
  /**
1206
- * The definition of a {@link module:engine/model/schema~ModelSchemaContext schema context}.
1207
- *
1208
- * Contexts can be created in multiple ways:
1209
- *
1210
- * * By defining a **node** – in this cases this node and all its ancestors will be used.
1211
- * * By defining a **position** in the document – in this case all its ancestors will be used.
1212
- * * By defining an **array of nodes** – in this case this array defines the entire context.
1213
- * * By defining a **name of node** - in this case node will be "mocked". It is not recommended because context
1214
- * will be unrealistic (e.g. attributes of these nodes are not specified). However, at times this may be the only
1215
- * way to define the context (e.g. when checking some hypothetical situation).
1216
- * * By defining an **array of node names** (potentially, mixed with real nodes) – The same as **name of node**
1217
- * but it is possible to create a path.
1218
- * * By defining a {@link module:engine/model/schema~ModelSchemaContext} instance - in this case the same instance as provided
1219
- * will be returned.
1220
- *
1221
- * Examples of context definitions passed to the {@link module:engine/model/schema~ModelSchema#checkChild `Schema#checkChild()`}
1222
- * method:
1223
- *
1224
- * ```ts
1225
- * // Assuming that we have a $root > blockQuote > paragraph structure, the following code
1226
- * // will check node 'foo' in the following context:
1227
- * // [ rootElement, blockQuoteElement, paragraphElement ]
1228
- * const contextDefinition = paragraphElement;
1229
- * const childToCheck = 'foo';
1230
- * schema.checkChild( contextDefinition, childToCheck );
1231
- *
1232
- * // Also check in [ rootElement, blockQuoteElement, paragraphElement ].
1233
- * schema.checkChild( model.createPositionAt( paragraphElement, 0 ), 'foo' );
1234
- *
1235
- * // Check in [ rootElement, paragraphElement ].
1236
- * schema.checkChild( [ rootElement, paragraphElement ], 'foo' );
1237
- *
1238
- * // Check only fakeParagraphElement.
1239
- * schema.checkChild( 'paragraph', 'foo' );
1240
- *
1241
- * // Check in [ fakeRootElement, fakeBarElement, paragraphElement ].
1242
- * schema.checkChild( [ '$root', 'bar', paragraphElement ], 'foo' );
1243
- * ```
1244
- *
1245
- * All these `checkChild()` calls will fire {@link module:engine/model/schema~ModelSchema#event:checkChild `Schema#checkChild`}
1246
- * events in which `args[ 0 ]` is an instance of the context. Therefore, you can write a listener like this:
1247
- *
1248
- * ```ts
1249
- * schema.on( 'checkChild', ( evt, args ) => {
1250
- * const ctx = args[ 0 ];
1251
- *
1252
- * console.log( Array.from( ctx.getNames() ) );
1253
- * } );
1254
- * ```
1255
- *
1256
- * Which will log the following:
1257
- *
1258
- * ```ts
1259
- * [ '$root', 'blockQuote', 'paragraph' ]
1260
- * [ '$root', 'paragraph' ]
1261
- * [ '$root', 'bar', 'paragraph' ]
1262
- * ```
1263
- *
1264
- * Note: When using the {@link module:engine/model/schema~ModelSchema#checkAttribute `Schema#checkAttribute()`} method
1265
- * you may want to check whether a text node may have an attribute. A {@link module:engine/model/text~ModelText} is a
1266
- * correct way to define a context so you can do this:
1267
- *
1268
- * ```ts
1269
- * schema.checkAttribute( textNode, 'bold' );
1270
- * ```
1271
- *
1272
- * But sometimes you want to check whether a text at a given position might've had some attribute,
1273
- * in which case you can create a context by mixing in an array of elements with a `'$text'` string:
1274
- *
1275
- * ```ts
1276
- * // Check in [ rootElement, paragraphElement, textNode ].
1277
- * schema.checkChild( [ ...positionInParagraph.getAncestors(), '$text' ], 'bold' );
1278
- * ```
1279
- */
1204
+ * The definition of a {@link module:engine/model/schema~ModelSchemaContext schema context}.
1205
+ *
1206
+ * Contexts can be created in multiple ways:
1207
+ *
1208
+ * * By defining a **node** – in this cases this node and all its ancestors will be used.
1209
+ * * By defining a **position** in the document – in this case all its ancestors will be used.
1210
+ * * By defining an **array of nodes** – in this case this array defines the entire context.
1211
+ * * By defining a **name of node** - in this case node will be "mocked". It is not recommended because context
1212
+ * will be unrealistic (e.g. attributes of these nodes are not specified). However, at times this may be the only
1213
+ * way to define the context (e.g. when checking some hypothetical situation).
1214
+ * * By defining an **array of node names** (potentially, mixed with real nodes) – The same as **name of node**
1215
+ * but it is possible to create a path.
1216
+ * * By defining a {@link module:engine/model/schema~ModelSchemaContext} instance - in this case the same instance as provided
1217
+ * will be returned.
1218
+ *
1219
+ * Examples of context definitions passed to the {@link module:engine/model/schema~ModelSchema#checkChild `Schema#checkChild()`}
1220
+ * method:
1221
+ *
1222
+ * ```ts
1223
+ * // Assuming that we have a $root > blockQuote > paragraph structure, the following code
1224
+ * // will check node 'foo' in the following context:
1225
+ * // [ rootElement, blockQuoteElement, paragraphElement ]
1226
+ * const contextDefinition = paragraphElement;
1227
+ * const childToCheck = 'foo';
1228
+ * schema.checkChild( contextDefinition, childToCheck );
1229
+ *
1230
+ * // Also check in [ rootElement, blockQuoteElement, paragraphElement ].
1231
+ * schema.checkChild( model.createPositionAt( paragraphElement, 0 ), 'foo' );
1232
+ *
1233
+ * // Check in [ rootElement, paragraphElement ].
1234
+ * schema.checkChild( [ rootElement, paragraphElement ], 'foo' );
1235
+ *
1236
+ * // Check only fakeParagraphElement.
1237
+ * schema.checkChild( 'paragraph', 'foo' );
1238
+ *
1239
+ * // Check in [ fakeRootElement, fakeBarElement, paragraphElement ].
1240
+ * schema.checkChild( [ '$root', 'bar', paragraphElement ], 'foo' );
1241
+ * ```
1242
+ *
1243
+ * All these `checkChild()` calls will fire {@link module:engine/model/schema~ModelSchema#event:checkChild `Schema#checkChild`}
1244
+ * events in which `args[ 0 ]` is an instance of the context. Therefore, you can write a listener like this:
1245
+ *
1246
+ * ```ts
1247
+ * schema.on( 'checkChild', ( evt, args ) => {
1248
+ * const ctx = args[ 0 ];
1249
+ *
1250
+ * console.log( Array.from( ctx.getNames() ) );
1251
+ * } );
1252
+ * ```
1253
+ *
1254
+ * Which will log the following:
1255
+ *
1256
+ * ```ts
1257
+ * [ '$root', 'blockQuote', 'paragraph' ]
1258
+ * [ '$root', 'paragraph' ]
1259
+ * [ '$root', 'bar', 'paragraph' ]
1260
+ * ```
1261
+ *
1262
+ * Note: When using the {@link module:engine/model/schema~ModelSchema#checkAttribute `Schema#checkAttribute()`} method
1263
+ * you may want to check whether a text node may have an attribute. A {@link module:engine/model/text~ModelText} is a
1264
+ * correct way to define a context so you can do this:
1265
+ *
1266
+ * ```ts
1267
+ * schema.checkAttribute( textNode, 'bold' );
1268
+ * ```
1269
+ *
1270
+ * But sometimes you want to check whether a text at a given position might've had some attribute,
1271
+ * in which case you can create a context by mixing in an array of elements with a `'$text'` string:
1272
+ *
1273
+ * ```ts
1274
+ * // Check in [ rootElement, paragraphElement, textNode ].
1275
+ * schema.checkChild( [ ...positionInParagraph.getAncestors(), '$text' ], 'bold' );
1276
+ * ```
1277
+ */
1280
1278
  export type ModelSchemaContextDefinition = ModelItem | ModelPosition | ModelSchemaContext | string | Array<string | ModelItem>;
1281
1279
  /**
1282
- * An item of the {@link module:engine/model/schema~ModelSchemaContext schema context}.
1283
- *
1284
- * It contains 3 properties:
1285
- *
1286
- * * `name` – the name of this item,
1287
- * * `* getAttributeKeys()` – a generator of keys of item attributes,
1288
- * * `getAttribute( keyName )` – a method to get attribute values.
1289
- *
1290
- * The context item interface is a highly simplified version of {@link module:engine/model/node~ModelNode} and its role
1291
- * is to expose only the information which schema checks are able to provide (which is the name of the node and
1292
- * node's attributes).
1293
- *
1294
- * ```ts
1295
- * schema.on( 'checkChild', ( evt, args ) => {
1296
- * const ctx = args[ 0 ];
1297
- * const firstItem = ctx.getItem( 0 );
1298
- *
1299
- * console.log( firstItem.name ); // -> '$root'
1300
- * console.log( firstItem.getAttribute( 'foo' ) ); // -> 'bar'
1301
- * console.log( Array.from( firstItem.getAttributeKeys() ) ); // -> [ 'foo', 'faa' ]
1302
- * } );
1303
- * ```
1304
- */
1280
+ * An item of the {@link module:engine/model/schema~ModelSchemaContext schema context}.
1281
+ *
1282
+ * It contains 3 properties:
1283
+ *
1284
+ * * `name` – the name of this item,
1285
+ * * `* getAttributeKeys()` – a generator of keys of item attributes,
1286
+ * * `getAttribute( keyName )` – a method to get attribute values.
1287
+ *
1288
+ * The context item interface is a highly simplified version of {@link module:engine/model/node~ModelNode} and its role
1289
+ * is to expose only the information which schema checks are able to provide (which is the name of the node and
1290
+ * node's attributes).
1291
+ *
1292
+ * ```ts
1293
+ * schema.on( 'checkChild', ( evt, args ) => {
1294
+ * const ctx = args[ 0 ];
1295
+ * const firstItem = ctx.getItem( 0 );
1296
+ *
1297
+ * console.log( firstItem.name ); // -> '$root'
1298
+ * console.log( firstItem.getAttribute( 'foo' ) ); // -> 'bar'
1299
+ * console.log( Array.from( firstItem.getAttributeKeys() ) ); // -> [ 'foo', 'faa' ]
1300
+ * } );
1301
+ * ```
1302
+ */
1305
1303
  export interface ModelSchemaContextItem {
1306
- name: string;
1307
- getAttributeKeys(): Generator<string>;
1308
- getAttribute(keyName: string): unknown;
1304
+ name: string;
1305
+ getAttributeKeys(): Generator<string>;
1306
+ getAttribute(keyName: string): unknown;
1309
1307
  }
1310
1308
  /**
1311
- * A structure containing additional metadata describing the attribute.
1312
- *
1313
- * See {@link module:engine/model/schema~ModelSchema#setAttributeProperties `Schema#setAttributeProperties()`} for usage examples.
1314
- */
1309
+ * A structure containing additional metadata describing the attribute.
1310
+ *
1311
+ * See {@link module:engine/model/schema~ModelSchema#setAttributeProperties `Schema#setAttributeProperties()`} for usage examples.
1312
+ */
1315
1313
  export interface ModelAttributeProperties {
1316
- /**
1317
- * Indicates that the attribute should be considered as a visual formatting, like `bold`, `italic` or
1318
- * `fontSize` rather than semantic attribute (such as `src`, `listType`, etc.). For example, it is used by the "Remove format" feature.
1319
- */
1320
- isFormatting?: boolean;
1321
- /**
1322
- * Indicates that given text attribute should be copied to the next block when enter is pressed.
1323
- */
1324
- copyOnEnter?: boolean;
1325
- /**
1326
- * Indicates that given attribute should be preserved while replacing the element.
1327
- */
1328
- copyOnReplace?: boolean;
1329
- /**
1330
- * Indicates that given text attribute should be copied from an inline object to the next inserted inline content.
1331
- *
1332
- * @default true
1333
- */
1334
- copyFromObject?: boolean;
1335
- /**
1336
- * Defines the mapping of all possible block alignments for a specific model element.
1337
- * It is used by features that need to determine whether an element can be aligned,
1338
- * and apply the alignment if possible.
1339
- */
1340
- blockAlignment?: ModelBlockAlignmentAttributesMapping | ((element: ModelElement) => ModelBlockAlignmentAttributesMapping);
1341
- [name: string]: unknown;
1314
+ /**
1315
+ * Indicates that the attribute should be considered as a visual formatting, like `bold`, `italic` or
1316
+ * `fontSize` rather than semantic attribute (such as `src`, `listType`, etc.). For example, it is used by the "Remove format" feature.
1317
+ */
1318
+ isFormatting?: boolean;
1319
+ /**
1320
+ * Indicates that given text attribute should be copied to the next block when enter is pressed.
1321
+ */
1322
+ copyOnEnter?: boolean;
1323
+ /**
1324
+ * Indicates that given attribute should be preserved while replacing the element.
1325
+ */
1326
+ copyOnReplace?: boolean;
1327
+ /**
1328
+ * Indicates that given text attribute should be copied from an inline object to the next inserted inline content.
1329
+ *
1330
+ * @default true
1331
+ */
1332
+ copyFromObject?: boolean;
1333
+ /**
1334
+ * Defines the mapping of all possible block alignments for a specific model element.
1335
+ * It is used by features that need to determine whether an element can be aligned,
1336
+ * and apply the alignment if possible.
1337
+ */
1338
+ blockAlignment?: ModelBlockAlignmentAttributesMapping | ((element: ModelElement) => ModelBlockAlignmentAttributesMapping);
1339
+ [name: string]: unknown;
1342
1340
  }
1343
1341
  /**
1344
- * Defines the mapping of block alignment options for a model element attribute.
1345
- *
1346
- * Each key represents a logical alignment name (e.g. `'left'`, `'center'`, `'right'`, `'justify'`),
1347
- * and the corresponding value describes how that alignment is represented in the model — including
1348
- * the actual attribute value and whether it should be treated as the default alignment for the element.
1349
- *
1350
- * Used by features that need to determine whether a model element supports block alignment
1351
- * and how to apply it. Can be provided as a static object or as a function receiving the element
1352
- * and returning the mapping dynamically, via {@link ~ModelAttributeProperties#blockAlignment}.
1353
- */
1342
+ * Defines the mapping of block alignment options for a model element attribute.
1343
+ *
1344
+ * Each key represents a logical alignment name (e.g. `'left'`, `'center'`, `'right'`, `'justify'`),
1345
+ * and the corresponding value describes how that alignment is represented in the model — including
1346
+ * the actual attribute value and whether it should be treated as the default alignment for the element.
1347
+ *
1348
+ * Used by features that need to determine whether a model element supports block alignment
1349
+ * and how to apply it. Can be provided as a static object or as a function receiving the element
1350
+ * and returning the mapping dynamically, via {@link ~ModelAttributeProperties#blockAlignment}.
1351
+ */
1354
1352
  export type ModelBlockAlignmentAttributesMapping = Record<string, {
1355
- isDefault?: boolean;
1356
- value: string;
1353
+ isDefault?: boolean;
1354
+ value: string;
1357
1355
  }>;
1358
1356
  export type ModelSchemaAttributeCheckCallback = (context: ModelSchemaContext, attributeName: string) => boolean | undefined;
1359
1357
  export type ModelSchemaChildCheckCallback = (context: ModelSchemaContext, definition: ModelSchemaCompiledItemDefinition) => boolean | undefined;