@ckeditor/ckeditor5-ui 47.6.1-alpha.1 → 48.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +3 -3
  3. package/{src → dist}/colorselector/documentcolorcollection.d.ts +4 -4
  4. package/{src → dist}/dialog/dialog.d.ts +1 -1
  5. package/dist/index-editor.css +2728 -587
  6. package/dist/index.css +2673 -850
  7. package/dist/index.css.map +1 -1
  8. package/dist/index.js +11 -1
  9. package/dist/index.js.map +1 -1
  10. package/{src → dist}/menubar/menubarmenuview.d.ts +4 -0
  11. package/{src → dist}/view.d.ts +1 -1
  12. package/package.json +25 -47
  13. package/lang/contexts.json +0 -51
  14. package/lang/translations/af.po +0 -208
  15. package/lang/translations/ar.po +0 -208
  16. package/lang/translations/ast.po +0 -208
  17. package/lang/translations/az.po +0 -208
  18. package/lang/translations/be.po +0 -208
  19. package/lang/translations/bg.po +0 -208
  20. package/lang/translations/bn.po +0 -208
  21. package/lang/translations/bs.po +0 -208
  22. package/lang/translations/ca.po +0 -208
  23. package/lang/translations/cs.po +0 -208
  24. package/lang/translations/da.po +0 -208
  25. package/lang/translations/de-ch.po +0 -208
  26. package/lang/translations/de.po +0 -208
  27. package/lang/translations/el.po +0 -208
  28. package/lang/translations/en-au.po +0 -208
  29. package/lang/translations/en-gb.po +0 -208
  30. package/lang/translations/en.po +0 -208
  31. package/lang/translations/eo.po +0 -208
  32. package/lang/translations/es-co.po +0 -208
  33. package/lang/translations/es.po +0 -208
  34. package/lang/translations/et.po +0 -208
  35. package/lang/translations/eu.po +0 -208
  36. package/lang/translations/fa.po +0 -208
  37. package/lang/translations/fi.po +0 -208
  38. package/lang/translations/fr.po +0 -208
  39. package/lang/translations/gl.po +0 -208
  40. package/lang/translations/gu.po +0 -208
  41. package/lang/translations/he.po +0 -208
  42. package/lang/translations/hi.po +0 -208
  43. package/lang/translations/hr.po +0 -208
  44. package/lang/translations/hu.po +0 -208
  45. package/lang/translations/hy.po +0 -208
  46. package/lang/translations/id.po +0 -208
  47. package/lang/translations/it.po +0 -208
  48. package/lang/translations/ja.po +0 -208
  49. package/lang/translations/jv.po +0 -208
  50. package/lang/translations/kk.po +0 -208
  51. package/lang/translations/km.po +0 -208
  52. package/lang/translations/kn.po +0 -208
  53. package/lang/translations/ko.po +0 -208
  54. package/lang/translations/ku.po +0 -208
  55. package/lang/translations/lt.po +0 -208
  56. package/lang/translations/lv.po +0 -208
  57. package/lang/translations/ms.po +0 -208
  58. package/lang/translations/nb.po +0 -208
  59. package/lang/translations/ne.po +0 -208
  60. package/lang/translations/nl.po +0 -208
  61. package/lang/translations/no.po +0 -208
  62. package/lang/translations/oc.po +0 -208
  63. package/lang/translations/pl.po +0 -208
  64. package/lang/translations/pt-br.po +0 -208
  65. package/lang/translations/pt.po +0 -208
  66. package/lang/translations/ro.po +0 -208
  67. package/lang/translations/ru.po +0 -208
  68. package/lang/translations/si.po +0 -208
  69. package/lang/translations/sk.po +0 -208
  70. package/lang/translations/sl.po +0 -208
  71. package/lang/translations/sq.po +0 -208
  72. package/lang/translations/sr-latn.po +0 -208
  73. package/lang/translations/sr.po +0 -208
  74. package/lang/translations/sv.po +0 -208
  75. package/lang/translations/th.po +0 -208
  76. package/lang/translations/ti.po +0 -208
  77. package/lang/translations/tk.po +0 -208
  78. package/lang/translations/tr.po +0 -208
  79. package/lang/translations/tt.po +0 -208
  80. package/lang/translations/ug.po +0 -208
  81. package/lang/translations/uk.po +0 -208
  82. package/lang/translations/ur.po +0 -208
  83. package/lang/translations/uz.po +0 -208
  84. package/lang/translations/vi.po +0 -208
  85. package/lang/translations/zh-cn.po +0 -208
  86. package/lang/translations/zh.po +0 -208
  87. package/src/arialiveannouncer.js +0 -189
  88. package/src/augmentation.js +0 -5
  89. package/src/autocomplete/autocompleteview.js +0 -157
  90. package/src/badge/badge.js +0 -226
  91. package/src/bindings/addkeyboardhandlingforgrid.js +0 -107
  92. package/src/bindings/clickoutsidehandler.js +0 -36
  93. package/src/bindings/csstransitiondisablermixin.js +0 -58
  94. package/src/bindings/draggableviewmixin.js +0 -144
  95. package/src/bindings/preventdefault.js +0 -35
  96. package/src/bindings/submithandler.js +0 -47
  97. package/src/button/button.js +0 -5
  98. package/src/button/buttonlabel.js +0 -5
  99. package/src/button/buttonlabelview.js +0 -42
  100. package/src/button/buttonview.js +0 -278
  101. package/src/button/filedialogbuttonview.js +0 -147
  102. package/src/button/listitembuttonview.js +0 -136
  103. package/src/button/switchbuttonview.js +0 -79
  104. package/src/collapsible/collapsibleview.js +0 -106
  105. package/src/colorgrid/colorgridview.js +0 -140
  106. package/src/colorgrid/colortileview.js +0 -42
  107. package/src/colorgrid/utils.js +0 -84
  108. package/src/colorpicker/colorpickerview.js +0 -356
  109. package/src/colorpicker/utils.js +0 -108
  110. package/src/colorselector/colorgridsfragmentview.js +0 -368
  111. package/src/colorselector/colorpickerfragmentview.js +0 -254
  112. package/src/colorselector/colorselectorview.js +0 -294
  113. package/src/colorselector/documentcolorcollection.js +0 -42
  114. package/src/componentfactory.js +0 -108
  115. package/src/dialog/dialog.js +0 -325
  116. package/src/dialog/dialogactionsview.js +0 -118
  117. package/src/dialog/dialogcontentview.js +0 -39
  118. package/src/dialog/dialogview.js +0 -507
  119. package/src/dropdown/button/dropdownbutton.js +0 -5
  120. package/src/dropdown/button/dropdownbuttonview.js +0 -70
  121. package/src/dropdown/button/splitbuttonview.js +0 -178
  122. package/src/dropdown/dropdownpanelfocusable.js +0 -5
  123. package/src/dropdown/dropdownpanelview.js +0 -106
  124. package/src/dropdown/dropdownview.js +0 -438
  125. package/src/dropdown/menu/dropdownmenubehaviors.js +0 -125
  126. package/src/dropdown/menu/dropdownmenubuttonview.js +0 -69
  127. package/src/dropdown/menu/dropdownmenulistitembuttonview.js +0 -30
  128. package/src/dropdown/menu/dropdownmenulistitemview.js +0 -38
  129. package/src/dropdown/menu/dropdownmenulistview.js +0 -29
  130. package/src/dropdown/menu/dropdownmenunestedmenupanelview.js +0 -63
  131. package/src/dropdown/menu/dropdownmenunestedmenuview.js +0 -214
  132. package/src/dropdown/menu/dropdownmenurootlistview.js +0 -168
  133. package/src/dropdown/menu/utils.js +0 -61
  134. package/src/dropdown/utils.js +0 -654
  135. package/src/editableui/editableuiview.js +0 -130
  136. package/src/editableui/inline/inlineeditableuiview.js +0 -75
  137. package/src/editorui/accessibilityhelp/accessibilityhelp.js +0 -142
  138. package/src/editorui/accessibilityhelp/accessibilityhelpcontentview.js +0 -112
  139. package/src/editorui/bodycollection.js +0 -128
  140. package/src/editorui/boxed/boxededitoruiview.js +0 -95
  141. package/src/editorui/editorui.js +0 -586
  142. package/src/editorui/editoruiview.js +0 -60
  143. package/src/editorui/evaluationbadge.js +0 -99
  144. package/src/editorui/poweredby.js +0 -120
  145. package/src/focuscycler.js +0 -383
  146. package/src/formheader/formheaderview.js +0 -77
  147. package/src/formrow/formrowview.js +0 -56
  148. package/src/highlightedtext/buttonlabelwithhighlightview.js +0 -31
  149. package/src/highlightedtext/highlightedtextview.js +0 -102
  150. package/src/highlightedtext/labelwithhighlightview.js +0 -37
  151. package/src/icon/iconview.js +0 -123
  152. package/src/iframe/iframeview.js +0 -63
  153. package/src/index.js +0 -132
  154. package/src/input/inputbase.js +0 -119
  155. package/src/input/inputview.js +0 -24
  156. package/src/inputnumber/inputnumberview.js +0 -40
  157. package/src/inputtext/inputtextview.js +0 -27
  158. package/src/label/labelview.js +0 -46
  159. package/src/labeledfield/labeledfieldview.js +0 -177
  160. package/src/labeledfield/utils.js +0 -176
  161. package/src/labeledinput/labeledinputview.js +0 -138
  162. package/src/legacyerrors.js +0 -20
  163. package/src/list/listitemgroupview.js +0 -82
  164. package/src/list/listitemview.js +0 -46
  165. package/src/list/listseparatorview.js +0 -28
  166. package/src/list/listview.js +0 -210
  167. package/src/menubar/menubarmenubuttonview.js +0 -68
  168. package/src/menubar/menubarmenulistitembuttonview.js +0 -30
  169. package/src/menubar/menubarmenulistitemfiledialogbuttonview.js +0 -32
  170. package/src/menubar/menubarmenulistitemview.js +0 -34
  171. package/src/menubar/menubarmenulistview.js +0 -72
  172. package/src/menubar/menubarmenupanelview.js +0 -64
  173. package/src/menubar/menubarmenuview.js +0 -198
  174. package/src/menubar/menubarview.js +0 -281
  175. package/src/menubar/utils.js +0 -1432
  176. package/src/model.js +0 -31
  177. package/src/notification/notification.js +0 -192
  178. package/src/panel/balloon/balloonpanelview.js +0 -1077
  179. package/src/panel/balloon/contextualballoon.js +0 -616
  180. package/src/panel/sticky/stickypanelview.js +0 -246
  181. package/src/search/filteredview.js +0 -5
  182. package/src/search/filtergroupanditemnames.js +0 -38
  183. package/src/search/searchinfoview.js +0 -59
  184. package/src/search/searchresultsview.js +0 -83
  185. package/src/search/text/searchtextqueryview.js +0 -87
  186. package/src/search/text/searchtextview.js +0 -242
  187. package/src/spinner/spinnerview.js +0 -38
  188. package/src/template.js +0 -1396
  189. package/src/textarea/textareaview.js +0 -189
  190. package/src/toolbar/balloon/balloontoolbar.js +0 -358
  191. package/src/toolbar/block/blockbuttonview.js +0 -41
  192. package/src/toolbar/block/blocktoolbar.js +0 -507
  193. package/src/toolbar/normalizetoolbarconfig.js +0 -52
  194. package/src/toolbar/toolbarlinebreakview.js +0 -28
  195. package/src/toolbar/toolbarseparatorview.js +0 -28
  196. package/src/toolbar/toolbarview.js +0 -873
  197. package/src/tooltipmanager.js +0 -454
  198. package/src/view.js +0 -471
  199. package/src/viewcollection.js +0 -210
  200. package/theme/components/arialiveannouncer/arialiveannouncer.css +0 -14
  201. package/theme/components/autocomplete/autocomplete.css +0 -22
  202. package/theme/components/button/button.css +0 -39
  203. package/theme/components/button/listitembutton.css +0 -48
  204. package/theme/components/button/switchbutton.css +0 -14
  205. package/theme/components/collapsible/collapsible.css +0 -10
  206. package/theme/components/colorgrid/colorgrid.css +0 -8
  207. package/theme/components/colorpicker/colorpicker.css +0 -34
  208. package/theme/components/colorselector/colorselector.css +0 -35
  209. package/theme/components/dialog/dialog.css +0 -42
  210. package/theme/components/dialog/dialogactions.css +0 -11
  211. package/theme/components/dropdown/dropdown.css +0 -95
  212. package/theme/components/dropdown/listdropdown.css +0 -10
  213. package/theme/components/dropdown/menu/dropdownmenu.css +0 -8
  214. package/theme/components/dropdown/menu/dropdownmenubutton.css +0 -9
  215. package/theme/components/dropdown/menu/dropdownmenulistitem.css +0 -10
  216. package/theme/components/dropdown/menu/dropdownmenulistitembutton.css +0 -10
  217. package/theme/components/dropdown/menu/dropdownmenupanel.css +0 -11
  218. package/theme/components/dropdown/splitbutton.css +0 -14
  219. package/theme/components/dropdown/toolbardropdown.css +0 -20
  220. package/theme/components/editorui/accessibilityhelp.css +0 -10
  221. package/theme/components/editorui/editorui.css +0 -10
  222. package/theme/components/form/form.css +0 -87
  223. package/theme/components/formheader/formheader.css +0 -18
  224. package/theme/components/formrow/formrow.css +0 -32
  225. package/theme/components/highlightedtext/highlightedtext.css +0 -12
  226. package/theme/components/icon/icon.css +0 -8
  227. package/theme/components/input/input.css +0 -10
  228. package/theme/components/label/label.css +0 -12
  229. package/theme/components/labeledfield/labeledfieldview.css +0 -16
  230. package/theme/components/labeledinput/labeledinput.css +0 -10
  231. package/theme/components/list/list.css +0 -26
  232. package/theme/components/menubar/menubar.css +0 -10
  233. package/theme/components/menubar/menubarmenu.css +0 -9
  234. package/theme/components/menubar/menubarmenubutton.css +0 -11
  235. package/theme/components/menubar/menubarmenulistitem.css +0 -10
  236. package/theme/components/menubar/menubarmenulistitembutton.css +0 -10
  237. package/theme/components/menubar/menubarmenupanel.css +0 -62
  238. package/theme/components/panel/balloonpanel.css +0 -56
  239. package/theme/components/panel/balloonrotator.css +0 -17
  240. package/theme/components/panel/fakepanel.css +0 -23
  241. package/theme/components/panel/stickypanel.css +0 -17
  242. package/theme/components/responsive-form/responsiveform.css +0 -42
  243. package/theme/components/search/search.css +0 -43
  244. package/theme/components/spinner/spinner.css +0 -23
  245. package/theme/components/textarea/textarea.css +0 -10
  246. package/theme/components/toolbar/blocktoolbar.css +0 -9
  247. package/theme/components/toolbar/toolbar.css +0 -58
  248. package/theme/components/tooltip/tooltip.css +0 -12
  249. package/theme/globals/_evaluationbadge.css +0 -54
  250. package/theme/globals/_hidden.css +0 -13
  251. package/theme/globals/_poweredby.css +0 -84
  252. package/theme/globals/_transition.css +0 -12
  253. package/theme/globals/_zindex.css +0 -10
  254. package/theme/globals/globals.css +0 -10
  255. package/theme/mixins/_dir.css +0 -10
  256. package/theme/mixins/_mediacolors.css +0 -20
  257. package/theme/mixins/_rwd.css +0 -10
  258. package/theme/mixins/_unselectable.css +0 -14
  259. /package/{src → dist}/arialiveannouncer.d.ts +0 -0
  260. /package/{src → dist}/augmentation.d.ts +0 -0
  261. /package/{src → dist}/autocomplete/autocompleteview.d.ts +0 -0
  262. /package/{src → dist}/badge/badge.d.ts +0 -0
  263. /package/{src → dist}/bindings/addkeyboardhandlingforgrid.d.ts +0 -0
  264. /package/{src → dist}/bindings/clickoutsidehandler.d.ts +0 -0
  265. /package/{src → dist}/bindings/csstransitiondisablermixin.d.ts +0 -0
  266. /package/{src → dist}/bindings/draggableviewmixin.d.ts +0 -0
  267. /package/{src → dist}/bindings/preventdefault.d.ts +0 -0
  268. /package/{src → dist}/bindings/submithandler.d.ts +0 -0
  269. /package/{src → dist}/button/button.d.ts +0 -0
  270. /package/{src → dist}/button/buttonlabel.d.ts +0 -0
  271. /package/{src → dist}/button/buttonlabelview.d.ts +0 -0
  272. /package/{src → dist}/button/buttonview.d.ts +0 -0
  273. /package/{src → dist}/button/filedialogbuttonview.d.ts +0 -0
  274. /package/{src → dist}/button/listitembuttonview.d.ts +0 -0
  275. /package/{src → dist}/button/switchbuttonview.d.ts +0 -0
  276. /package/{src → dist}/collapsible/collapsibleview.d.ts +0 -0
  277. /package/{src → dist}/colorgrid/colorgridview.d.ts +0 -0
  278. /package/{src → dist}/colorgrid/colortileview.d.ts +0 -0
  279. /package/{src → dist}/colorgrid/utils.d.ts +0 -0
  280. /package/{src → dist}/colorpicker/colorpickerview.d.ts +0 -0
  281. /package/{src → dist}/colorpicker/utils.d.ts +0 -0
  282. /package/{src → dist}/colorselector/colorgridsfragmentview.d.ts +0 -0
  283. /package/{src → dist}/colorselector/colorpickerfragmentview.d.ts +0 -0
  284. /package/{src → dist}/colorselector/colorselectorview.d.ts +0 -0
  285. /package/{src → dist}/componentfactory.d.ts +0 -0
  286. /package/{src → dist}/dialog/dialogactionsview.d.ts +0 -0
  287. /package/{src → dist}/dialog/dialogcontentview.d.ts +0 -0
  288. /package/{src → dist}/dialog/dialogview.d.ts +0 -0
  289. /package/{src → dist}/dropdown/button/dropdownbutton.d.ts +0 -0
  290. /package/{src → dist}/dropdown/button/dropdownbuttonview.d.ts +0 -0
  291. /package/{src → dist}/dropdown/button/splitbuttonview.d.ts +0 -0
  292. /package/{src → dist}/dropdown/dropdownpanelfocusable.d.ts +0 -0
  293. /package/{src → dist}/dropdown/dropdownpanelview.d.ts +0 -0
  294. /package/{src → dist}/dropdown/dropdownview.d.ts +0 -0
  295. /package/{src → dist}/dropdown/menu/dropdownmenubehaviors.d.ts +0 -0
  296. /package/{src → dist}/dropdown/menu/dropdownmenubuttonview.d.ts +0 -0
  297. /package/{src → dist}/dropdown/menu/dropdownmenulistitembuttonview.d.ts +0 -0
  298. /package/{src → dist}/dropdown/menu/dropdownmenulistitemview.d.ts +0 -0
  299. /package/{src → dist}/dropdown/menu/dropdownmenulistview.d.ts +0 -0
  300. /package/{src → dist}/dropdown/menu/dropdownmenunestedmenupanelview.d.ts +0 -0
  301. /package/{src → dist}/dropdown/menu/dropdownmenunestedmenuview.d.ts +0 -0
  302. /package/{src → dist}/dropdown/menu/dropdownmenurootlistview.d.ts +0 -0
  303. /package/{src → dist}/dropdown/menu/utils.d.ts +0 -0
  304. /package/{src → dist}/dropdown/utils.d.ts +0 -0
  305. /package/{src → dist}/editableui/editableuiview.d.ts +0 -0
  306. /package/{src → dist}/editableui/inline/inlineeditableuiview.d.ts +0 -0
  307. /package/{src → dist}/editorui/accessibilityhelp/accessibilityhelp.d.ts +0 -0
  308. /package/{src → dist}/editorui/accessibilityhelp/accessibilityhelpcontentview.d.ts +0 -0
  309. /package/{src → dist}/editorui/bodycollection.d.ts +0 -0
  310. /package/{src → dist}/editorui/boxed/boxededitoruiview.d.ts +0 -0
  311. /package/{src → dist}/editorui/editorui.d.ts +0 -0
  312. /package/{src → dist}/editorui/editoruiview.d.ts +0 -0
  313. /package/{src → dist}/editorui/evaluationbadge.d.ts +0 -0
  314. /package/{src → dist}/editorui/poweredby.d.ts +0 -0
  315. /package/{src → dist}/focuscycler.d.ts +0 -0
  316. /package/{src → dist}/formheader/formheaderview.d.ts +0 -0
  317. /package/{src → dist}/formrow/formrowview.d.ts +0 -0
  318. /package/{src → dist}/highlightedtext/buttonlabelwithhighlightview.d.ts +0 -0
  319. /package/{src → dist}/highlightedtext/highlightedtextview.d.ts +0 -0
  320. /package/{src → dist}/highlightedtext/labelwithhighlightview.d.ts +0 -0
  321. /package/{src → dist}/icon/iconview.d.ts +0 -0
  322. /package/{src → dist}/iframe/iframeview.d.ts +0 -0
  323. /package/{src → dist}/index.d.ts +0 -0
  324. /package/{src → dist}/input/inputbase.d.ts +0 -0
  325. /package/{src → dist}/input/inputview.d.ts +0 -0
  326. /package/{src → dist}/inputnumber/inputnumberview.d.ts +0 -0
  327. /package/{src → dist}/inputtext/inputtextview.d.ts +0 -0
  328. /package/{src → dist}/label/labelview.d.ts +0 -0
  329. /package/{src → dist}/labeledfield/labeledfieldview.d.ts +0 -0
  330. /package/{src → dist}/labeledfield/utils.d.ts +0 -0
  331. /package/{src → dist}/labeledinput/labeledinputview.d.ts +0 -0
  332. /package/{src → dist}/legacyerrors.d.ts +0 -0
  333. /package/{src → dist}/list/listitemgroupview.d.ts +0 -0
  334. /package/{src → dist}/list/listitemview.d.ts +0 -0
  335. /package/{src → dist}/list/listseparatorview.d.ts +0 -0
  336. /package/{src → dist}/list/listview.d.ts +0 -0
  337. /package/{src → dist}/menubar/menubarmenubuttonview.d.ts +0 -0
  338. /package/{src → dist}/menubar/menubarmenulistitembuttonview.d.ts +0 -0
  339. /package/{src → dist}/menubar/menubarmenulistitemfiledialogbuttonview.d.ts +0 -0
  340. /package/{src → dist}/menubar/menubarmenulistitemview.d.ts +0 -0
  341. /package/{src → dist}/menubar/menubarmenulistview.d.ts +0 -0
  342. /package/{src → dist}/menubar/menubarmenupanelview.d.ts +0 -0
  343. /package/{src → dist}/menubar/menubarview.d.ts +0 -0
  344. /package/{src → dist}/menubar/utils.d.ts +0 -0
  345. /package/{src → dist}/model.d.ts +0 -0
  346. /package/{src → dist}/notification/notification.d.ts +0 -0
  347. /package/{src → dist}/panel/balloon/balloonpanelview.d.ts +0 -0
  348. /package/{src → dist}/panel/balloon/contextualballoon.d.ts +0 -0
  349. /package/{src → dist}/panel/sticky/stickypanelview.d.ts +0 -0
  350. /package/{src → dist}/search/filteredview.d.ts +0 -0
  351. /package/{src → dist}/search/filtergroupanditemnames.d.ts +0 -0
  352. /package/{src → dist}/search/searchinfoview.d.ts +0 -0
  353. /package/{src → dist}/search/searchresultsview.d.ts +0 -0
  354. /package/{src → dist}/search/text/searchtextqueryview.d.ts +0 -0
  355. /package/{src → dist}/search/text/searchtextview.d.ts +0 -0
  356. /package/{src → dist}/spinner/spinnerview.d.ts +0 -0
  357. /package/{src → dist}/template.d.ts +0 -0
  358. /package/{src → dist}/textarea/textareaview.d.ts +0 -0
  359. /package/{src → dist}/toolbar/balloon/balloontoolbar.d.ts +0 -0
  360. /package/{src → dist}/toolbar/block/blockbuttonview.d.ts +0 -0
  361. /package/{src → dist}/toolbar/block/blocktoolbar.d.ts +0 -0
  362. /package/{src → dist}/toolbar/normalizetoolbarconfig.d.ts +0 -0
  363. /package/{src → dist}/toolbar/toolbarlinebreakview.d.ts +0 -0
  364. /package/{src → dist}/toolbar/toolbarseparatorview.d.ts +0 -0
  365. /package/{src → dist}/toolbar/toolbarview.d.ts +0 -0
  366. /package/{src → dist}/tooltipmanager.d.ts +0 -0
  367. /package/{src → dist}/viewcollection.d.ts +0 -0
package/src/template.js DELETED
@@ -1,1396 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module ui/template
7
- */
8
- import { View } from './view.js';
9
- import { ViewCollection } from './viewcollection.js';
10
- import { CKEditorError, EmitterMixin, isNode, toArray } from '@ckeditor/ckeditor5-utils';
11
- import { isObject, cloneDeepWith } from 'es-toolkit/compat';
12
- const xhtmlNs = 'http://www.w3.org/1999/xhtml';
13
- /**
14
- * A basic Template class. It renders a DOM HTML element or text from a
15
- * {@link module:ui/template~TemplateDefinition definition} and supports element attributes, children,
16
- * bindings to {@link module:utils/observablemixin~Observable observables} and DOM event propagation.
17
- *
18
- * A simple template can look like this:
19
- *
20
- * ```ts
21
- * const bind = Template.bind( observable, emitter );
22
- *
23
- * new Template( {
24
- * tag: 'p',
25
- * attributes: {
26
- * class: 'foo',
27
- * style: {
28
- * backgroundColor: 'yellow'
29
- * }
30
- * },
31
- * on: {
32
- * click: bind.to( 'clicked' )
33
- * },
34
- * children: [
35
- * 'A paragraph.'
36
- * ]
37
- * } ).render();
38
- * ```
39
- *
40
- * and it will render the following HTML element:
41
- *
42
- * ```html
43
- * <p class="foo" style="background-color: yellow;">A paragraph.</p>
44
- * ```
45
- *
46
- * Additionally, the `observable` will always fire `clicked` upon clicking `<p>` in the DOM.
47
- *
48
- * See {@link module:ui/template~TemplateDefinition} to know more about templates and complex
49
- * template definitions.
50
- */
51
- export class Template extends /* #__PURE__ */ EmitterMixin() {
52
- ns;
53
- /**
54
- * The tag (`tagName`) of this template, e.g. `div`. It also indicates that the template
55
- * renders to an HTML element.
56
- */
57
- tag;
58
- /**
59
- * The text of the template. It also indicates that the template renders to a DOM text node.
60
- */
61
- text;
62
- /**
63
- * The attributes of the template, e.g. `{ id: [ 'ck-id' ] }`, corresponding with
64
- * the attributes of an HTML element.
65
- *
66
- * **Note**: This property only makes sense when {@link #tag} is defined.
67
- */
68
- attributes;
69
- /**
70
- * The children of the template. They can be either:
71
- * * independent instances of {@link ~Template} (sub–templates),
72
- * * native DOM Nodes.
73
- *
74
- * **Note**: This property only makes sense when {@link #tag} is defined.
75
- */
76
- children;
77
- /**
78
- * The DOM event listeners of the template.
79
- */
80
- eventListeners;
81
- /**
82
- * Indicates whether this particular Template instance has been
83
- * {@link #render rendered}.
84
- */
85
- _isRendered;
86
- /**
87
- * The data used by the {@link #revert} method to restore a node to its original state.
88
- *
89
- * See: {@link #apply}.
90
- */
91
- _revertData;
92
- /**
93
- * Creates an instance of the {@link ~Template} class.
94
- *
95
- * @param def The definition of the template.
96
- */
97
- constructor(def) {
98
- super();
99
- Object.assign(this, normalize(clone(def)));
100
- this._isRendered = false;
101
- this._revertData = null;
102
- }
103
- /**
104
- * Renders a DOM Node (an HTML element or text) out of the template.
105
- *
106
- * ```ts
107
- * const domNode = new Template( { ... } ).render();
108
- * ```
109
- *
110
- * See: {@link #apply}.
111
- */
112
- render() {
113
- const node = this._renderNode({
114
- intoFragment: true
115
- });
116
- this._isRendered = true;
117
- return node;
118
- }
119
- /**
120
- * Applies the template to an existing DOM Node, either HTML element or text.
121
- *
122
- * **Note:** No new DOM nodes will be created. Applying extends:
123
- *
124
- * {@link module:ui/template~TemplateDefinition attributes},
125
- * {@link module:ui/template~TemplateDefinition event listeners}, and
126
- * `textContent` of {@link module:ui/template~TemplateDefinition children} only.
127
- *
128
- * **Note:** Existing `class` and `style` attributes are extended when a template
129
- * is applied to an HTML element, while other attributes and `textContent` are overridden.
130
- *
131
- * **Note:** The process of applying a template can be easily reverted using the
132
- * {@link module:ui/template~Template#revert} method.
133
- *
134
- * ```ts
135
- * const element = document.createElement( 'div' );
136
- * const observable = new Model( { divClass: 'my-div' } );
137
- * const emitter = Object.create( EmitterMixin );
138
- * const bind = Template.bind( observable, emitter );
139
- *
140
- * new Template( {
141
- * attributes: {
142
- * id: 'first-div',
143
- * class: bind.to( 'divClass' )
144
- * },
145
- * on: {
146
- * click: bind( 'elementClicked' ) // Will be fired by the observable.
147
- * },
148
- * children: [
149
- * 'Div text.'
150
- * ]
151
- * } ).apply( element );
152
- *
153
- * console.log( element.outerHTML ); // -> '<div id="first-div" class="my-div"></div>'
154
- * ```
155
- *
156
- * @see module:ui/template~Template#render
157
- * @see module:ui/template~Template#revert
158
- * @param node Root node for the template to apply.
159
- */
160
- apply(node) {
161
- this._revertData = getEmptyRevertData();
162
- this._renderNode({
163
- node,
164
- intoFragment: false,
165
- isApplying: true,
166
- revertData: this._revertData
167
- });
168
- return node;
169
- }
170
- /**
171
- * Reverts a template {@link module:ui/template~Template#apply applied} to a DOM node.
172
- *
173
- * @param node The root node for the template to revert. In most of the cases, it is the
174
- * same node used by {@link module:ui/template~Template#apply}.
175
- */
176
- revert(node) {
177
- if (!this._revertData) {
178
- /**
179
- * Attempting to revert a template which has not been applied yet.
180
- *
181
- * @error ui-template-revert-not-applied
182
- */
183
- throw new CKEditorError('ui-template-revert-not-applied', [this, node]);
184
- }
185
- this._revertTemplateFromNode(node, this._revertData);
186
- }
187
- /**
188
- * Returns an iterator which traverses the template in search of {@link module:ui/view~View}
189
- * instances and returns them one by one.
190
- *
191
- * ```ts
192
- * const viewFoo = new View();
193
- * const viewBar = new View();
194
- * const viewBaz = new View();
195
- * const template = new Template( {
196
- * tag: 'div',
197
- * children: [
198
- * viewFoo,
199
- * {
200
- * tag: 'div',
201
- * children: [
202
- * viewBar
203
- * ]
204
- * },
205
- * viewBaz
206
- * ]
207
- * } );
208
- *
209
- * // Logs: viewFoo, viewBar, viewBaz
210
- * for ( const view of template.getViews() ) {
211
- * console.log( view );
212
- * }
213
- * ```
214
- */
215
- *getViews() {
216
- function* search(def) {
217
- if (def.children) {
218
- for (const child of def.children) {
219
- if (isView(child)) {
220
- yield child;
221
- }
222
- else if (isTemplate(child)) {
223
- yield* search(child);
224
- }
225
- }
226
- }
227
- }
228
- yield* search(this);
229
- }
230
- /**
231
- * An entry point to the interface which binds DOM nodes to
232
- * {@link module:utils/observablemixin~Observable observables}.
233
- * There are two types of bindings:
234
- *
235
- * * HTML element attributes or text `textContent` synchronized with attributes of an
236
- * {@link module:utils/observablemixin~Observable}. Learn more about {@link module:ui/template~BindChain#to}
237
- * and {@link module:ui/template~BindChain#if}.
238
- *
239
- * ```ts
240
- * const bind = Template.bind( observable, emitter );
241
- *
242
- * new Template( {
243
- * attributes: {
244
- * // Binds the element "class" attribute to observable#classAttribute.
245
- * class: bind.to( 'classAttribute' )
246
- * }
247
- * } ).render();
248
- * ```
249
- *
250
- * * DOM events fired on HTML element propagated through
251
- * {@link module:utils/observablemixin~Observable}. Learn more about {@link module:ui/template~BindChain#to}.
252
- *
253
- * ```ts
254
- * const bind = Template.bind( observable, emitter );
255
- *
256
- * new Template( {
257
- * on: {
258
- * // Will be fired by the observable.
259
- * click: bind( 'elementClicked' )
260
- * }
261
- * } ).render();
262
- * ```
263
- *
264
- * Also see {@link module:ui/view~View#bindTemplate}.
265
- *
266
- * @param observable An observable which provides boundable attributes.
267
- * @param emitter An emitter that listens to observable attribute
268
- * changes or DOM Events (depending on the kind of the binding). Usually, a {@link module:ui/view~View} instance.
269
- */
270
- static bind(observable, emitter) {
271
- return {
272
- to(eventNameOrFunctionOrAttribute, callback) {
273
- return new TemplateToBinding({
274
- eventNameOrFunction: eventNameOrFunctionOrAttribute,
275
- attribute: eventNameOrFunctionOrAttribute,
276
- observable, emitter, callback
277
- });
278
- },
279
- if(attribute, valueIfTrue, callback) {
280
- return new TemplateIfBinding({
281
- observable, emitter, attribute, valueIfTrue, callback
282
- });
283
- }
284
- };
285
- }
286
- /**
287
- * Extends an existing {@link module:ui/template~Template} instance with some additional content
288
- * from another {@link module:ui/template~TemplateDefinition}.
289
- *
290
- * ```ts
291
- * const bind = Template.bind( observable, emitter );
292
- *
293
- * const template = new Template( {
294
- * tag: 'p',
295
- * attributes: {
296
- * class: 'a',
297
- * data-x: bind.to( 'foo' )
298
- * },
299
- * children: [
300
- * {
301
- * tag: 'span',
302
- * attributes: {
303
- * class: 'b'
304
- * },
305
- * children: [
306
- * 'Span'
307
- * ]
308
- * }
309
- * ]
310
- * } );
311
- *
312
- * // Instance-level extension.
313
- * Template.extend( template, {
314
- * attributes: {
315
- * class: 'b',
316
- * data-x: bind.to( 'bar' )
317
- * },
318
- * children: [
319
- * {
320
- * attributes: {
321
- * class: 'c'
322
- * }
323
- * }
324
- * ]
325
- * } );
326
- *
327
- * // Child extension.
328
- * Template.extend( template.children[ 0 ], {
329
- * attributes: {
330
- * class: 'd'
331
- * }
332
- * } );
333
- * ```
334
- *
335
- * the `outerHTML` of `template.render()` is:
336
- *
337
- * ```html
338
- * <p class="a b" data-x="{ observable.foo } { observable.bar }">
339
- * <span class="b c d">Span</span>
340
- * </p>
341
- * ```
342
- *
343
- * @param template An existing template instance to be extended.
344
- * @param def Additional definition to be applied to a template.
345
- */
346
- static extend(template, def) {
347
- if (template._isRendered) {
348
- /**
349
- * Extending a template after rendering may not work as expected. To make sure
350
- * the {@link module:ui/template~Template.extend extending} works for an element,
351
- * make sure it happens before {@link module:ui/template~Template#render} is called.
352
- *
353
- * @error template-extend-render
354
- */
355
- throw new CKEditorError('template-extend-render', [this, template]);
356
- }
357
- extendTemplate(template, normalize(clone(def)));
358
- }
359
- /**
360
- * Renders a DOM Node (either an HTML element or text) out of the template.
361
- *
362
- * @param data Rendering data.
363
- */
364
- _renderNode(data) {
365
- let isInvalid;
366
- if (data.node) {
367
- // When applying, a definition cannot have "tag" and "text" at the same time.
368
- isInvalid = this.tag && this.text;
369
- }
370
- else {
371
- // When rendering, a definition must have either "tag" or "text": XOR( this.tag, this.text ).
372
- isInvalid = this.tag ? this.text : !this.text;
373
- }
374
- if (isInvalid) {
375
- /**
376
- * Node definition cannot have the "tag" and "text" properties at the same time.
377
- * Node definition must have either "tag" or "text" when rendering a new Node.
378
- *
379
- * @error ui-template-wrong-syntax
380
- */
381
- throw new CKEditorError('ui-template-wrong-syntax', this);
382
- }
383
- if (this.text) {
384
- return this._renderText(data);
385
- }
386
- else {
387
- return this._renderElement(data);
388
- }
389
- }
390
- /**
391
- * Renders an HTML element out of the template.
392
- *
393
- * @param data Rendering data.
394
- */
395
- _renderElement(data) {
396
- let node = data.node;
397
- if (!node) {
398
- node = data.node = document.createElementNS(this.ns || xhtmlNs, this.tag);
399
- }
400
- this._renderAttributes(data);
401
- this._renderElementChildren(data);
402
- this._setUpListeners(data);
403
- return node;
404
- }
405
- /**
406
- * Renders a text node out of {@link module:ui/template~Template#text}.
407
- *
408
- * @param data Rendering data.
409
- */
410
- _renderText(data) {
411
- let node = data.node;
412
- // Save the original textContent to revert it in #revert().
413
- if (node) {
414
- data.revertData.text = node.textContent;
415
- }
416
- else {
417
- node = data.node = document.createTextNode('');
418
- }
419
- // Check if this Text Node is bound to Observable. Cases:
420
- //
421
- // text: [ Template.bind( ... ).to( ... ) ]
422
- //
423
- // text: [
424
- // 'foo',
425
- // Template.bind( ... ).to( ... ),
426
- // ...
427
- // ]
428
- //
429
- if (hasTemplateBinding(this.text)) {
430
- this._bindToObservable({
431
- schema: this.text,
432
- updater: getTextUpdater(node),
433
- data
434
- });
435
- }
436
- // Simply set text. Cases:
437
- //
438
- // text: [ 'all', 'are', 'static' ]
439
- //
440
- // text: [ 'foo' ]
441
- //
442
- else {
443
- node.textContent = this.text.join('');
444
- }
445
- return node;
446
- }
447
- /**
448
- * Renders HTML element attributes out of {@link module:ui/template~Template#attributes}.
449
- *
450
- * @param data Rendering data.
451
- */
452
- _renderAttributes(data) {
453
- if (!this.attributes) {
454
- return;
455
- }
456
- const node = data.node;
457
- const revertData = data.revertData;
458
- for (const attrName in this.attributes) {
459
- // Current attribute value in DOM.
460
- const domAttrValue = node.getAttribute(attrName);
461
- // The value to be set.
462
- const attrValue = this.attributes[attrName];
463
- // Save revert data.
464
- if (revertData) {
465
- revertData.attributes[attrName] = domAttrValue;
466
- }
467
- // Detect custom namespace:
468
- //
469
- // class: {
470
- // ns: 'abc',
471
- // value: Template.bind( ... ).to( ... )
472
- // }
473
- //
474
- const attrNs = isNamespaced(attrValue) ? attrValue[0].ns : null;
475
- // Activate binding if one is found. Cases:
476
- //
477
- // class: [
478
- // Template.bind( ... ).to( ... )
479
- // ]
480
- //
481
- // class: [
482
- // 'bar',
483
- // Template.bind( ... ).to( ... ),
484
- // 'baz'
485
- // ]
486
- //
487
- // class: {
488
- // ns: 'abc',
489
- // value: Template.bind( ... ).to( ... )
490
- // }
491
- //
492
- if (hasTemplateBinding(attrValue)) {
493
- // Normalize attributes with additional data like namespace:
494
- //
495
- // class: {
496
- // ns: 'abc',
497
- // value: [ ... ]
498
- // }
499
- //
500
- const valueToBind = isNamespaced(attrValue) ? attrValue[0].value : attrValue;
501
- // Extend the original value of attributes like "style" and "class",
502
- // don't override them.
503
- if (revertData && shouldExtend(attrName)) {
504
- valueToBind.unshift(domAttrValue);
505
- }
506
- this._bindToObservable({
507
- schema: valueToBind,
508
- updater: getAttributeUpdater(node, attrName, attrNs),
509
- data
510
- });
511
- }
512
- // Style attribute could be an Object so it needs to be parsed in a specific way.
513
- //
514
- // style: {
515
- // width: '100px',
516
- // height: Template.bind( ... ).to( ... )
517
- // }
518
- //
519
- else if (attrName == 'style' && typeof attrValue[0] !== 'string') {
520
- this._renderStyleAttribute(attrValue[0], data);
521
- }
522
- // Otherwise simply set the static attribute:
523
- //
524
- // class: [ 'foo' ]
525
- //
526
- // class: [ 'all', 'are', 'static' ]
527
- //
528
- // class: [
529
- // {
530
- // ns: 'abc',
531
- // value: [ 'foo' ]
532
- // }
533
- // ]
534
- //
535
- else {
536
- // Extend the original value of attributes like "style" and "class",
537
- // don't override them.
538
- if (revertData && domAttrValue && shouldExtend(attrName)) {
539
- attrValue.unshift(domAttrValue);
540
- }
541
- const value = attrValue
542
- // Retrieve "values" from:
543
- //
544
- // class: [
545
- // {
546
- // ns: 'abc',
547
- // value: [ ... ]
548
- // }
549
- // ]
550
- //
551
- .map((val) => val ? (val.value || val) : val)
552
- // Flatten the array.
553
- .reduce((prev, next) => prev.concat(next), [])
554
- // Convert into string.
555
- .reduce(arrayValueReducer, '');
556
- if (!isFalsy(value)) {
557
- node.setAttributeNS(attrNs, attrName, value);
558
- }
559
- }
560
- }
561
- }
562
- /**
563
- * Renders the `style` attribute of an HTML element based on
564
- * {@link module:ui/template~Template#attributes}.
565
- *
566
- * A style attribute is an object with static values:
567
- *
568
- * ```ts
569
- * attributes: {
570
- * style: {
571
- * color: 'red',
572
- * '--color': 'red'
573
- * }
574
- * }
575
- * ```
576
- *
577
- * or values bound to {@link module:ui/model~UIModel} properties:
578
- *
579
- * ```ts
580
- * attributes: {
581
- * style: {
582
- * color: bind.to( ... ),
583
- * '--color': bind.to( ... )
584
- * }
585
- * }
586
- * ```
587
- *
588
- * Note: The `style` attribute is rendered without setting the namespace. It does not seem to be
589
- * needed.
590
- *
591
- * @param styles Styles located in `attributes.style` of {@link module:ui/template~TemplateDefinition}.
592
- * @param data Rendering data.
593
- */
594
- _renderStyleAttribute(styles, data) {
595
- const node = data.node;
596
- for (const styleName in styles) {
597
- const styleValue = styles[styleName];
598
- // Cases:
599
- //
600
- // style: {
601
- // color: bind.to( 'attribute' )
602
- // }
603
- //
604
- if (hasTemplateBinding(styleValue)) {
605
- this._bindToObservable({
606
- schema: [styleValue],
607
- updater: getStyleUpdater(node, styleName),
608
- data
609
- });
610
- }
611
- // Cases:
612
- //
613
- // style: {
614
- // --color: 'red'
615
- // }
616
- //
617
- else if (isCssVariable(styleName)) {
618
- node.style.setProperty(styleName, styleValue);
619
- }
620
- // Cases:
621
- //
622
- // style: {
623
- // color: 'red'
624
- // }
625
- //
626
- else {
627
- node.style[styleName] = styleValue;
628
- }
629
- }
630
- }
631
- /**
632
- * Recursively renders HTML element's children from {@link module:ui/template~Template#children}.
633
- *
634
- * @param data Rendering data.
635
- */
636
- _renderElementChildren(data) {
637
- const node = data.node;
638
- const container = data.intoFragment ? document.createDocumentFragment() : node;
639
- const isApplying = data.isApplying;
640
- let childIndex = 0;
641
- for (const child of this.children) {
642
- if (isViewCollection(child)) {
643
- if (!isApplying) {
644
- child.setParent(node);
645
- // Note: ViewCollection renders its children.
646
- for (const view of child) {
647
- container.appendChild(view.element);
648
- }
649
- }
650
- }
651
- else if (isView(child)) {
652
- if (!isApplying) {
653
- if (!child.isRendered) {
654
- child.render();
655
- }
656
- container.appendChild(child.element);
657
- }
658
- }
659
- else if (isNode(child)) {
660
- container.appendChild(child);
661
- }
662
- else {
663
- if (isApplying) {
664
- const revertData = data.revertData;
665
- const childRevertData = getEmptyRevertData();
666
- revertData.children.push(childRevertData);
667
- child._renderNode({
668
- intoFragment: false,
669
- node: container.childNodes[childIndex++],
670
- isApplying: true,
671
- revertData: childRevertData
672
- });
673
- }
674
- else {
675
- container.appendChild(child.render());
676
- }
677
- }
678
- }
679
- if (data.intoFragment) {
680
- node.appendChild(container);
681
- }
682
- }
683
- /**
684
- * Activates `on` event listeners from the {@link module:ui/template~TemplateDefinition}
685
- * on an HTML element.
686
- *
687
- * @param data Rendering data.
688
- */
689
- _setUpListeners(data) {
690
- if (!this.eventListeners) {
691
- return;
692
- }
693
- for (const key in this.eventListeners) {
694
- const revertBindings = this.eventListeners[key].map(schemaItem => {
695
- const [domEvtName, domSelector] = key.split('@');
696
- return schemaItem.activateDomEventListener(domEvtName, domSelector, data);
697
- });
698
- if (data.revertData) {
699
- data.revertData.bindings.push(revertBindings);
700
- }
701
- }
702
- }
703
- /**
704
- * For a given {@link module:ui/template~TemplateValueSchema} containing {@link module:ui/template~TemplateBinding}
705
- * activates the binding and sets its initial value.
706
- *
707
- * Note: {@link module:ui/template~TemplateValueSchema} can be for HTML element attributes or
708
- * text node `textContent`.
709
- *
710
- * @param options Binding options.
711
- * @param options.updater A function which updates the DOM (like attribute or text).
712
- * @param options.data Rendering data.
713
- */
714
- _bindToObservable({ schema, updater, data }) {
715
- const revertData = data.revertData;
716
- // Set initial values.
717
- syncValueSchemaValue(schema, updater, data);
718
- const revertBindings = schema
719
- // Filter "falsy" (false, undefined, null, '') value schema components out.
720
- .filter(item => !isFalsy(item))
721
- // Filter inactive bindings from schema, like static strings ('foo'), numbers (42), etc.
722
- .filter((item) => item.observable)
723
- // Once only the actual binding are left, let the emitter listen to observable change:attribute event.
724
- // TODO: Reduce the number of listeners attached as many bindings may listen
725
- // to the same observable attribute.
726
- .map(templateBinding => templateBinding.activateAttributeListener(schema, updater, data));
727
- if (revertData) {
728
- revertData.bindings.push(revertBindings);
729
- }
730
- }
731
- /**
732
- * Reverts {@link module:ui/template~RenderData#revertData template data} from a node to
733
- * return it to the original state.
734
- *
735
- * @param node A node to be reverted.
736
- * @param revertData An object that stores information about what changes have been made by
737
- * {@link #apply} to the node. See {@link module:ui/template~RenderData#revertData} for more information.
738
- */
739
- _revertTemplateFromNode(node, revertData) {
740
- for (const binding of revertData.bindings) {
741
- // Each binding may consist of several observable+observable#attribute.
742
- // like the following has 2:
743
- //
744
- // class: [
745
- // 'x',
746
- // bind.to( 'foo' ),
747
- // 'y',
748
- // bind.to( 'bar' )
749
- // ]
750
- //
751
- for (const revertBinding of binding) {
752
- revertBinding();
753
- }
754
- }
755
- if (revertData.text) {
756
- node.textContent = revertData.text;
757
- return;
758
- }
759
- const element = node;
760
- for (const attrName in revertData.attributes) {
761
- const attrValue = revertData.attributes[attrName];
762
- // When the attribute has **not** been set before #apply().
763
- if (attrValue === null) {
764
- element.removeAttribute(attrName);
765
- }
766
- else {
767
- element.setAttribute(attrName, attrValue);
768
- }
769
- }
770
- for (let i = 0; i < revertData.children.length; ++i) {
771
- this._revertTemplateFromNode(element.childNodes[i], revertData.children[i]);
772
- }
773
- }
774
- }
775
- /**
776
- * Describes a binding created by the {@link module:ui/template~Template.bind} interface.
777
- *
778
- * @internal
779
- */
780
- export class TemplateBinding {
781
- /**
782
- * The name of the {@link module:ui/template~TemplateBinding#observable observed attribute}.
783
- */
784
- attribute;
785
- /**
786
- * An observable instance of the binding. It either:
787
- *
788
- * * provides the attribute with the value,
789
- * * or passes the event when a corresponding DOM event is fired.
790
- */
791
- observable;
792
- /**
793
- * An {@link module:utils/emittermixin~Emitter} used by the binding to:
794
- *
795
- * * listen to the attribute change in the {@link module:ui/template~TemplateBinding#observable},
796
- * * or listen to the event in the DOM.
797
- */
798
- emitter;
799
- /**
800
- * A custom function to process the value of the {@link module:ui/template~TemplateBinding#attribute}.
801
- */
802
- callback;
803
- /**
804
- * Creates an instance of the {@link module:ui/template~TemplateBinding} class.
805
- *
806
- * @param def The definition of the binding.
807
- */
808
- constructor(def) {
809
- this.attribute = def.attribute;
810
- this.observable = def.observable;
811
- this.emitter = def.emitter;
812
- this.callback = def.callback;
813
- }
814
- /**
815
- * Returns the value of the binding. It is the value of the {@link module:ui/template~TemplateBinding#attribute} in
816
- * {@link module:ui/template~TemplateBinding#observable}. The value may be processed by the
817
- * {@link module:ui/template~TemplateBinding#callback}, if such has been passed to the binding.
818
- *
819
- * @param node A native DOM node, passed to the custom {@link module:ui/template~TemplateBinding#callback}.
820
- * @returns The value of {@link module:ui/template~TemplateBinding#attribute} in
821
- * {@link module:ui/template~TemplateBinding#observable}.
822
- */
823
- getValue(node) {
824
- const value = this.observable[this.attribute];
825
- return this.callback ? this.callback(value, node) : value;
826
- }
827
- /**
828
- * Activates the listener which waits for changes of the {@link module:ui/template~TemplateBinding#attribute} in
829
- * {@link module:ui/template~TemplateBinding#observable}, then updates the DOM with the aggregated
830
- * value of {@link module:ui/template~TemplateValueSchema}.
831
- *
832
- * @param schema A full schema to generate an attribute or text in the DOM.
833
- * @param updater A DOM updater function used to update the native DOM attribute or text.
834
- * @param data Rendering data.
835
- * @returns A function to sever the listener binding.
836
- */
837
- activateAttributeListener(schema, updater, data) {
838
- const callback = () => syncValueSchemaValue(schema, updater, data);
839
- this.emitter.listenTo(this.observable, `change:${this.attribute}`, callback);
840
- // Allows revert of the listener.
841
- return () => {
842
- this.emitter.stopListening(this.observable, `change:${this.attribute}`, callback);
843
- };
844
- }
845
- }
846
- /**
847
- * Describes either:
848
- *
849
- * * a binding to an {@link module:utils/observablemixin~Observable},
850
- * * or a native DOM event binding.
851
- *
852
- * It is created by the {@link module:ui/template~BindChain#to} method.
853
- *
854
- * @internal
855
- */
856
- export class TemplateToBinding extends TemplateBinding {
857
- eventNameOrFunction;
858
- constructor(def) {
859
- super(def);
860
- this.eventNameOrFunction = def.eventNameOrFunction;
861
- }
862
- /**
863
- * Activates the listener for the native DOM event, which when fired, is propagated by
864
- * the {@link module:ui/template~TemplateBinding#emitter}.
865
- *
866
- * @param domEvtName The name of the native DOM event.
867
- * @param domSelector The selector in the DOM to filter delegated events.
868
- * @param data Rendering data.
869
- * @returns A function to sever the listener binding.
870
- */
871
- activateDomEventListener(domEvtName, domSelector, data) {
872
- const callback = (evt, domEvt) => {
873
- if (!domSelector || domEvt.target.matches(domSelector)) {
874
- if (typeof this.eventNameOrFunction == 'function') {
875
- this.eventNameOrFunction(domEvt);
876
- }
877
- else {
878
- this.observable.fire(this.eventNameOrFunction, domEvt);
879
- }
880
- }
881
- };
882
- this.emitter.listenTo(data.node, domEvtName, callback);
883
- // Allows revert of the listener.
884
- return () => {
885
- this.emitter.stopListening(data.node, domEvtName, callback);
886
- };
887
- }
888
- }
889
- /**
890
- * Describes a binding to {@link module:utils/observablemixin~Observable} created by the {@link module:ui/template~BindChain#if}
891
- * method.
892
- *
893
- * @internal
894
- */
895
- export class TemplateIfBinding extends TemplateBinding {
896
- /**
897
- * The value of the DOM attribute or text to be set if the {@link module:ui/template~TemplateBinding#attribute} in
898
- * {@link module:ui/template~TemplateBinding#observable} is `true`.
899
- */
900
- valueIfTrue;
901
- constructor(def) {
902
- super(def);
903
- this.valueIfTrue = def.valueIfTrue;
904
- }
905
- /**
906
- * @inheritDoc
907
- */
908
- getValue(node) {
909
- const value = super.getValue(node);
910
- return isFalsy(value) ? false : (this.valueIfTrue || true);
911
- }
912
- }
913
- /**
914
- * Checks whether given {@link module:ui/template~TemplateValueSchema} contains a
915
- * {@link module:ui/template~TemplateBinding}.
916
- */
917
- function hasTemplateBinding(schema) {
918
- if (!schema) {
919
- return false;
920
- }
921
- // Normalize attributes with additional data like namespace:
922
- //
923
- // class: {
924
- // ns: 'abc',
925
- // value: [ ... ]
926
- // }
927
- //
928
- if (schema.value) {
929
- schema = schema.value;
930
- }
931
- if (Array.isArray(schema)) {
932
- return schema.some(hasTemplateBinding);
933
- }
934
- else if (schema instanceof TemplateBinding) {
935
- return true;
936
- }
937
- return false;
938
- }
939
- /**
940
- * Checks whether the given name is a valid CSS variable name.
941
- *
942
- * A valid CSS variable name starts with two dashes (`--`), followed by a letter, underscore (`_`),
943
- * or dash (`-`), and can be followed by any combination of letters, digits, underscores, dashes,
944
- * or additional dashes.
945
- *
946
- * @param name The name to validate as a CSS variable.
947
- * @returns True if the name is a valid CSS variable, false otherwise.
948
- */
949
- function isCssVariable(name) {
950
- const regex = /^--[a-zA-Z_-][\w-]*$/;
951
- return regex.test(name);
952
- }
953
- /**
954
- * Assembles the value using {@link module:ui/template~TemplateValueSchema} and stores it in a form of
955
- * an Array. Each entry of the Array corresponds to one of {@link module:ui/template~TemplateValueSchema}
956
- * items.
957
- *
958
- * @param node DOM Node updated when {@link module:utils/observablemixin~Observable} changes.
959
- */
960
- function getValueSchemaValue(schema, node) {
961
- return schema.map(schemaItem => {
962
- // Process {@link module:ui/template~TemplateBinding} bindings.
963
- if (schemaItem instanceof TemplateBinding) {
964
- return schemaItem.getValue(node);
965
- }
966
- // All static values like strings, numbers, and "falsy" values (false, null, undefined, '', etc.) just pass.
967
- return schemaItem;
968
- });
969
- }
970
- /**
971
- * A function executed each time the bound Observable attribute changes, which updates the DOM with a value
972
- * constructed from {@link module:ui/template~TemplateValueSchema}.
973
- *
974
- * @param updater A function which updates the DOM (like attribute or text).
975
- * @param node DOM Node updated when {@link module:utils/observablemixin~Observable} changes.
976
- */
977
- function syncValueSchemaValue(schema, updater, { node }) {
978
- const values = getValueSchemaValue(schema, node);
979
- let value;
980
- // Check if schema is a single Template.bind.if, like:
981
- //
982
- // class: Template.bind.if( 'foo' )
983
- //
984
- if (schema.length == 1 && schema[0] instanceof TemplateIfBinding) {
985
- value = values[0];
986
- }
987
- else {
988
- value = values.reduce(arrayValueReducer, '');
989
- }
990
- if (isFalsy(value)) {
991
- updater.remove();
992
- }
993
- else {
994
- updater.set(value);
995
- }
996
- }
997
- /**
998
- * Returns an object consisting of `set` and `remove` functions, which
999
- * can be used in the context of DOM Node to set or reset `textContent`.
1000
- * @see module:ui/view~View#_bindToObservable
1001
- *
1002
- * @param node DOM Node to be modified.
1003
- */
1004
- function getTextUpdater(node) {
1005
- return {
1006
- set(value) {
1007
- node.textContent = value;
1008
- },
1009
- remove() {
1010
- node.textContent = '';
1011
- }
1012
- };
1013
- }
1014
- /**
1015
- * Returns an object consisting of `set` and `remove` functions, which
1016
- * can be used in the context of DOM Node to set or reset an attribute.
1017
- * @see module:ui/view~View#_bindToObservable
1018
- *
1019
- * @param el DOM Node to be modified.
1020
- * @param attrName Name of the attribute to be modified.
1021
- * @param ns Namespace to use.
1022
- */
1023
- function getAttributeUpdater(el, attrName, ns) {
1024
- return {
1025
- set(value) {
1026
- el.setAttributeNS(ns, attrName, value);
1027
- },
1028
- remove() {
1029
- el.removeAttributeNS(ns, attrName);
1030
- }
1031
- };
1032
- }
1033
- /**
1034
- * Returns an object consisting of `set` and `remove` functions, which
1035
- * can be used in the context of CSSStyleDeclaration to set or remove a style.
1036
- * @see module:ui/view~View#_bindToObservable
1037
- *
1038
- * @param el DOM Node to be modified.
1039
- * @param styleName Name of the style to be modified.
1040
- */
1041
- function getStyleUpdater(el, styleName) {
1042
- return {
1043
- set(value) {
1044
- if (isCssVariable(styleName)) {
1045
- el.style.setProperty(styleName, value);
1046
- }
1047
- else {
1048
- el.style[styleName] = value;
1049
- }
1050
- },
1051
- remove() {
1052
- if (isCssVariable(styleName)) {
1053
- el.style.removeProperty(styleName);
1054
- }
1055
- else {
1056
- el.style[styleName] = null;
1057
- }
1058
- }
1059
- };
1060
- }
1061
- /**
1062
- * Clones definition of the template.
1063
- */
1064
- function clone(def) {
1065
- const clone = cloneDeepWith(def, value => {
1066
- // Don't clone the `Template.bind`* bindings because of the references to Observable
1067
- // and DomEmitterMixin instances inside, which would also be traversed and cloned by greedy
1068
- // cloneDeepWith algorithm. There's no point in cloning Observable/DomEmitterMixins
1069
- // along with the definition.
1070
- //
1071
- // Don't clone Template instances if provided as a child. They're simply #render()ed
1072
- // and nothing should interfere.
1073
- //
1074
- // Also don't clone View instances if provided as a child of the Template. The template
1075
- // instance will be extracted from the View during the normalization and there's no need
1076
- // to clone it.
1077
- if (value && (value instanceof TemplateBinding || isTemplate(value) || isView(value) || isViewCollection(value))) {
1078
- return value;
1079
- }
1080
- });
1081
- return clone;
1082
- }
1083
- /**
1084
- * Normalizes given {@link module:ui/template~TemplateDefinition}.
1085
- *
1086
- * See:
1087
- * * {@link normalizeAttributes}
1088
- * * {@link normalizeListeners}
1089
- * * {@link normalizePlainTextDefinition}
1090
- * * {@link normalizeTextDefinition}
1091
- *
1092
- * @param def A template definition.
1093
- * @returns Normalized definition.
1094
- */
1095
- function normalize(def) {
1096
- if (typeof def == 'string') {
1097
- def = normalizePlainTextDefinition(def);
1098
- }
1099
- else if (def.text) {
1100
- normalizeTextDefinition(def);
1101
- }
1102
- if (def.on) {
1103
- def.eventListeners = normalizeListeners(def.on);
1104
- // Template mixes EmitterMixin, so delete #on to avoid collision.
1105
- delete def.on;
1106
- }
1107
- if (!def.text) {
1108
- if (def.attributes) {
1109
- normalizeAttributes(def.attributes);
1110
- }
1111
- const children = [];
1112
- if (def.children) {
1113
- if (isViewCollection(def.children)) {
1114
- children.push(def.children);
1115
- }
1116
- else {
1117
- for (const child of def.children) {
1118
- if (isTemplate(child) || isView(child) || isNode(child)) {
1119
- children.push(child);
1120
- }
1121
- else {
1122
- children.push(new Template(child));
1123
- }
1124
- }
1125
- }
1126
- }
1127
- def.children = children;
1128
- }
1129
- return def;
1130
- }
1131
- /**
1132
- * Normalizes "attributes" section of {@link module:ui/template~TemplateDefinition}.
1133
- *
1134
- * ```
1135
- * attributes: {
1136
- * a: 'bar',
1137
- * b: {@link module:ui/template~TemplateBinding},
1138
- * c: {
1139
- * value: 'bar'
1140
- * }
1141
- * }
1142
- * ```
1143
- *
1144
- * becomes
1145
- *
1146
- * ```
1147
- * attributes: {
1148
- * a: [ 'bar' ],
1149
- * b: [ {@link module:ui/template~TemplateBinding} ],
1150
- * c: {
1151
- * value: [ 'bar' ]
1152
- * }
1153
- * }
1154
- * ```
1155
- */
1156
- function normalizeAttributes(attributes) {
1157
- for (const a in attributes) {
1158
- if (attributes[a].value) {
1159
- attributes[a].value = toArray(attributes[a].value);
1160
- }
1161
- arrayify(attributes, a);
1162
- }
1163
- }
1164
- /**
1165
- * Normalizes "on" section of {@link module:ui/template~TemplateDefinition}.
1166
- *
1167
- * ```
1168
- * on: {
1169
- * a: 'bar',
1170
- * b: {@link module:ui/template~TemplateBinding},
1171
- * c: [ {@link module:ui/template~TemplateBinding}, () => { ... } ]
1172
- * }
1173
- * ```
1174
- *
1175
- * becomes
1176
- *
1177
- * ```
1178
- * on: {
1179
- * a: [ 'bar' ],
1180
- * b: [ {@link module:ui/template~TemplateBinding} ],
1181
- * c: [ {@link module:ui/template~TemplateBinding}, () => { ... } ]
1182
- * }
1183
- * ```
1184
- *
1185
- * @returns Object containing normalized listeners.
1186
- */
1187
- function normalizeListeners(listeners) {
1188
- for (const l in listeners) {
1189
- arrayify(listeners, l);
1190
- }
1191
- return listeners;
1192
- }
1193
- /**
1194
- * Normalizes "string" {@link module:ui/template~TemplateDefinition}.
1195
- *
1196
- * ```
1197
- * "foo"
1198
- * ```
1199
- *
1200
- * becomes
1201
- *
1202
- * ```
1203
- * { text: [ 'foo' ] },
1204
- * ```
1205
- *
1206
- * @returns Normalized template definition.
1207
- */
1208
- function normalizePlainTextDefinition(def) {
1209
- return {
1210
- text: [def]
1211
- };
1212
- }
1213
- /**
1214
- * Normalizes text {@link module:ui/template~TemplateDefinition}.
1215
- *
1216
- * ```
1217
- * children: [
1218
- * { text: 'def' },
1219
- * { text: {@link module:ui/template~TemplateBinding} }
1220
- * ]
1221
- * ```
1222
- *
1223
- * becomes
1224
- *
1225
- * ```
1226
- * children: [
1227
- * { text: [ 'def' ] },
1228
- * { text: [ {@link module:ui/template~TemplateBinding} ] }
1229
- * ]
1230
- * ```
1231
- */
1232
- function normalizeTextDefinition(def) {
1233
- def.text = toArray(def.text);
1234
- }
1235
- /**
1236
- * Wraps an entry in Object in an Array, if not already one.
1237
- *
1238
- * ```
1239
- * {
1240
- * x: 'y',
1241
- * a: [ 'b' ]
1242
- * }
1243
- * ```
1244
- *
1245
- * becomes
1246
- *
1247
- * ```
1248
- * {
1249
- * x: [ 'y' ],
1250
- * a: [ 'b' ]
1251
- * }
1252
- * ```
1253
- */
1254
- function arrayify(obj, key) {
1255
- obj[key] = toArray(obj[key]);
1256
- }
1257
- /**
1258
- * A helper which concatenates the value avoiding unwanted
1259
- * leading white spaces.
1260
- */
1261
- function arrayValueReducer(prev, cur) {
1262
- if (isFalsy(cur)) {
1263
- return prev;
1264
- }
1265
- else if (isFalsy(prev)) {
1266
- return cur;
1267
- }
1268
- else {
1269
- return `${prev} ${cur}`;
1270
- }
1271
- }
1272
- /**
1273
- * Extends one object defined in the following format:
1274
- *
1275
- * ```
1276
- * {
1277
- * key1: [Array1],
1278
- * key2: [Array2],
1279
- * ...
1280
- * keyN: [ArrayN]
1281
- * }
1282
- * ```
1283
- *
1284
- * with another object of the same data format.
1285
- *
1286
- * @param obj Base object.
1287
- * @param ext Object extending base.
1288
- */
1289
- function extendObjectValueArray(obj, ext) {
1290
- for (const a in ext) {
1291
- if (obj[a]) {
1292
- obj[a].push(...ext[a]);
1293
- }
1294
- else {
1295
- obj[a] = ext[a];
1296
- }
1297
- }
1298
- }
1299
- /**
1300
- * A helper for {@link module:ui/template~Template#extend}. Recursively extends {@link module:ui/template~Template} instance
1301
- * with content from {@link module:ui/template~TemplateDefinition}. See {@link module:ui/template~Template#extend} to learn more.
1302
- *
1303
- * @param def A template instance to be extended.
1304
- * @param def A definition which is to extend the template instance.
1305
- * @param Error context.
1306
- */
1307
- function extendTemplate(template, def) {
1308
- if (def.attributes) {
1309
- if (!template.attributes) {
1310
- template.attributes = {};
1311
- }
1312
- extendObjectValueArray(template.attributes, def.attributes);
1313
- }
1314
- if (def.eventListeners) {
1315
- if (!template.eventListeners) {
1316
- template.eventListeners = {};
1317
- }
1318
- extendObjectValueArray(template.eventListeners, def.eventListeners);
1319
- }
1320
- if (def.text) {
1321
- template.text.push(...def.text);
1322
- }
1323
- if (def.children && def.children.length) {
1324
- if (template.children.length != def.children.length) {
1325
- /**
1326
- * The number of children in extended definition does not match.
1327
- *
1328
- * @error ui-template-extend-children-mismatch
1329
- */
1330
- throw new CKEditorError('ui-template-extend-children-mismatch', template);
1331
- }
1332
- let childIndex = 0;
1333
- for (const childDef of def.children) {
1334
- extendTemplate(template.children[childIndex++], childDef);
1335
- }
1336
- }
1337
- }
1338
- /**
1339
- * Checks if value is "falsy".
1340
- * Note: 0 (Number) is not "falsy" in this context.
1341
- *
1342
- * @param value Value to be checked.
1343
- */
1344
- function isFalsy(value) {
1345
- return !value && value !== 0;
1346
- }
1347
- /**
1348
- * Checks if the item is an instance of {@link module:ui/view~View}
1349
- *
1350
- * @param value Value to be checked.
1351
- */
1352
- function isView(item) {
1353
- return item instanceof View;
1354
- }
1355
- /**
1356
- * Checks if the item is an instance of {@link module:ui/template~Template}
1357
- *
1358
- * @param value Value to be checked.
1359
- */
1360
- function isTemplate(item) {
1361
- return item instanceof Template;
1362
- }
1363
- /**
1364
- * Checks if the item is an instance of {@link module:ui/viewcollection~ViewCollection}
1365
- *
1366
- * @param value Value to be checked.
1367
- */
1368
- function isViewCollection(item) {
1369
- return item instanceof ViewCollection;
1370
- }
1371
- /**
1372
- * Checks if value array contains the one with namespace.
1373
- */
1374
- function isNamespaced(attrValue) {
1375
- return isObject(attrValue[0]) && attrValue[0].ns;
1376
- }
1377
- /**
1378
- * Creates an empty skeleton for {@link module:ui/template~Template#revert}
1379
- * data.
1380
- */
1381
- function getEmptyRevertData() {
1382
- return {
1383
- children: [],
1384
- bindings: [],
1385
- attributes: {}
1386
- };
1387
- }
1388
- /**
1389
- * Checks whether an attribute should be extended when
1390
- * {@link module:ui/template~Template#apply} is called.
1391
- *
1392
- * @param attrName Attribute name to check.
1393
- */
1394
- function shouldExtend(attrName) {
1395
- return attrName == 'class' || attrName == 'style';
1396
- }