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