@ckeditor/ckeditor5-engine 44.1.0 → 44.2.0-alpha.1

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