@vonage/vivid 5.19.0 → 5.20.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 (648) hide show
  1. package/accordion/definition.cjs +1 -1
  2. package/accordion/definition.js +1 -1
  3. package/accordion/index.cjs +2 -2
  4. package/accordion/index.js +2 -2
  5. package/accordion-item/definition.cjs +1 -1
  6. package/accordion-item/definition.js +1 -1
  7. package/action-group/definition.cjs +1 -1
  8. package/action-group/definition.js +1 -1
  9. package/action-group/index.cjs +2 -2
  10. package/action-group/index.js +2 -2
  11. package/alert/index.cjs +5 -5
  12. package/alert/index.js +8 -8
  13. package/audio-player/index.cjs +10 -10
  14. package/audio-player/index.js +28 -28
  15. package/avatar/index.cjs +7 -7
  16. package/avatar/index.js +14 -14
  17. package/banner/index.cjs +5 -5
  18. package/banner/index.js +9 -9
  19. package/breadcrumb/index.cjs +2 -2
  20. package/breadcrumb/index.js +3 -3
  21. package/breadcrumb-item/index.cjs +5 -5
  22. package/breadcrumb-item/index.js +1 -1
  23. package/bundled/affix.cjs +2 -2
  24. package/bundled/affix.js +11 -11
  25. package/bundled/anchored.cjs +1 -1
  26. package/bundled/anchored.js +6 -6
  27. package/bundled/aria-binding-directive.cjs +1 -1
  28. package/bundled/aria-binding-directive.js +88 -16
  29. package/bundled/base-color-picker.cjs +3 -3
  30. package/bundled/base-color-picker.js +5 -5
  31. package/bundled/base-progress.cjs +1 -1
  32. package/bundled/base-progress.js +3 -3
  33. package/bundled/breadcrumb-item.cjs +1 -1
  34. package/bundled/breadcrumb-item.js +3 -3
  35. package/bundled/button.cjs +1 -1
  36. package/bundled/button.js +3 -3
  37. package/bundled/calendar-event.cjs +1 -1
  38. package/bundled/calendar-event.js +4 -4
  39. package/bundled/calendar-picker.template.cjs +23 -24
  40. package/bundled/calendar-picker.template.js +35 -36
  41. package/bundled/char-count.cjs +2 -2
  42. package/bundled/char-count.js +8 -8
  43. package/bundled/children.cjs +1 -1
  44. package/bundled/children.js +11 -13
  45. package/bundled/definition.cjs +1 -1
  46. package/bundled/definition.js +2 -2
  47. package/bundled/definition10.cjs +3 -3
  48. package/bundled/definition10.js +5 -5
  49. package/bundled/definition11.cjs +2 -2
  50. package/bundled/definition11.js +7 -7
  51. package/bundled/definition12.cjs +15 -16
  52. package/bundled/definition12.js +22 -22
  53. package/bundled/definition13.cjs +3 -3
  54. package/bundled/definition13.js +5 -5
  55. package/bundled/definition14.cjs +2 -2
  56. package/bundled/definition14.js +2 -2
  57. package/bundled/definition15.cjs +7 -8
  58. package/bundled/definition15.js +14 -14
  59. package/bundled/definition16.cjs +3 -3
  60. package/bundled/definition16.js +8 -8
  61. package/bundled/definition17.cjs +7 -7
  62. package/bundled/definition17.js +13 -13
  63. package/bundled/definition18.cjs +18 -18
  64. package/bundled/definition18.js +36 -36
  65. package/bundled/definition19.cjs +2 -2
  66. package/bundled/definition19.js +1 -1
  67. package/bundled/definition2.cjs +10 -9
  68. package/bundled/definition2.js +24 -24
  69. package/bundled/definition20.cjs +19 -14
  70. package/bundled/definition20.js +51 -39
  71. package/bundled/definition21.cjs +6 -6
  72. package/bundled/definition21.js +18 -18
  73. package/bundled/definition22.cjs +3 -3
  74. package/bundled/definition22.js +7 -7
  75. package/bundled/definition23.cjs +4 -4
  76. package/bundled/definition23.js +8 -8
  77. package/bundled/definition24.cjs +8 -8
  78. package/bundled/definition24.js +17 -17
  79. package/bundled/definition3.cjs +1 -1
  80. package/bundled/definition3.js +5 -5
  81. package/bundled/definition4.cjs +9 -9
  82. package/bundled/definition4.js +16 -16
  83. package/bundled/definition5.cjs +4 -4
  84. package/bundled/definition5.js +5 -5
  85. package/bundled/definition6.cjs +6 -6
  86. package/bundled/definition6.js +21 -21
  87. package/bundled/definition7.cjs +2 -2
  88. package/bundled/definition7.js +4 -4
  89. package/bundled/definition8.cjs +4 -4
  90. package/bundled/definition8.js +7 -7
  91. package/bundled/definition9.cjs +10 -6
  92. package/bundled/definition9.js +48 -34
  93. package/bundled/delegates-aria.cjs +1 -1
  94. package/bundled/delegates-aria.js +20 -9
  95. package/bundled/divider.cjs +1 -1
  96. package/bundled/divider.js +3 -3
  97. package/bundled/form-associated.cjs +1 -1
  98. package/bundled/form-associated.js +6 -6
  99. package/bundled/form-element.cjs +1 -1
  100. package/bundled/form-element.js +1 -1
  101. package/bundled/host-semantics.cjs +1 -1
  102. package/bundled/host-semantics.js +2 -1
  103. package/bundled/kbd-shortcut.cjs +1 -0
  104. package/bundled/kbd-shortcut.js +14 -0
  105. package/bundled/linkable.cjs +2 -2
  106. package/bundled/linkable.js +5 -5
  107. package/bundled/listbox.cjs +1 -1
  108. package/bundled/listbox.js +4 -4
  109. package/bundled/localized.cjs +1 -1
  110. package/bundled/localized.js +3 -2
  111. package/bundled/mixins.cjs +16 -16
  112. package/bundled/mixins.js +39 -105
  113. package/bundled/picker-field.template.cjs +6 -6
  114. package/bundled/picker-field.template.js +15 -15
  115. package/bundled/platform.cjs +1 -0
  116. package/bundled/platform.js +9 -0
  117. package/bundled/ref.cjs +1 -1
  118. package/bundled/ref.js +2 -2
  119. package/bundled/render-in-light-dom.cjs +1 -0
  120. package/bundled/render-in-light-dom.js +57 -0
  121. package/bundled/repeat.cjs +1 -1
  122. package/bundled/repeat.js +117 -107
  123. package/bundled/slider.template.cjs +3 -3
  124. package/bundled/slider.template.js +1 -1
  125. package/bundled/slotted.cjs +1 -1
  126. package/bundled/slotted.js +2 -2
  127. package/bundled/time-selection-picker.template.cjs +4 -4
  128. package/bundled/time-selection-picker.template.js +18 -18
  129. package/bundled/vivid-element.cjs +3 -3
  130. package/bundled/vivid-element.js +626 -550
  131. package/bundled/when.cjs +1 -1
  132. package/bundled/when.js +2 -2
  133. package/bundled/with-contextual-help.cjs +1 -1
  134. package/bundled/with-contextual-help.js +1 -1
  135. package/bundled/with-error-text.cjs +1 -1
  136. package/bundled/with-error-text.js +1 -1
  137. package/bundled/with-success-text.cjs +1 -1
  138. package/bundled/with-success-text.js +1 -1
  139. package/calendar/index.cjs +8 -8
  140. package/calendar/index.js +9 -9
  141. package/calendar-event/index.cjs +4 -4
  142. package/calendar-event/index.js +1 -1
  143. package/card/index.cjs +24 -25
  144. package/card/index.js +29 -30
  145. package/color-picker/index.cjs +26 -26
  146. package/color-picker/index.js +90 -90
  147. package/combobox/index.cjs +13 -13
  148. package/combobox/index.js +22 -22
  149. package/country-group/index.cjs +4 -4
  150. package/country-group/index.js +3 -3
  151. package/custom-elements.json +940 -112
  152. package/data-grid/index.cjs +34 -34
  153. package/data-grid/index.js +37 -38
  154. package/date-picker/definition.cjs +1 -1
  155. package/date-picker/definition.js +1 -1
  156. package/date-picker/index.cjs +1 -1
  157. package/date-picker/index.js +2 -2
  158. package/date-range-picker/definition.cjs +1 -1
  159. package/date-range-picker/definition.js +1 -1
  160. package/date-range-picker/index.cjs +1 -1
  161. package/date-range-picker/index.js +4 -4
  162. package/date-time-picker/definition.cjs +1 -1
  163. package/date-time-picker/definition.js +1 -1
  164. package/date-time-picker/index.cjs +2 -2
  165. package/date-time-picker/index.js +6 -6
  166. package/dial-pad/definition.cjs +1 -1
  167. package/dial-pad/definition.js +1 -1
  168. package/dial-pad/index.cjs +8 -8
  169. package/dial-pad/index.js +15 -15
  170. package/dialog/definition.cjs +1 -1
  171. package/dialog/definition.js +1 -1
  172. package/dialog/index.cjs +16 -17
  173. package/dialog/index.js +29 -27
  174. package/divider/definition.cjs +1 -1
  175. package/divider/definition.js +1 -1
  176. package/empty-state/definition.cjs +1 -1
  177. package/empty-state/definition.js +1 -1
  178. package/empty-state/index.cjs +5 -5
  179. package/empty-state/index.js +9 -9
  180. package/fab/definition.cjs +1 -1
  181. package/fab/definition.js +1 -1
  182. package/fab/index.cjs +2 -2
  183. package/fab/index.js +6 -6
  184. package/file-picker/definition.cjs +1 -1
  185. package/file-picker/definition.js +1 -1
  186. package/file-picker/index.cjs +9 -10
  187. package/file-picker/index.js +21 -22
  188. package/flag/index.cjs +3 -3
  189. package/flag/index.js +7 -7
  190. package/header/definition.cjs +1 -1
  191. package/header/definition.js +1 -1
  192. package/header/index.cjs +2 -2
  193. package/header/index.js +8 -8
  194. package/icon/definition.cjs +1 -1
  195. package/icon/definition.js +1 -1
  196. package/index.cjs +184 -172
  197. package/index.js +52 -49
  198. package/kbd-key/definition.cjs +5 -0
  199. package/kbd-key/definition.js +2 -0
  200. package/kbd-key/index.cjs +5 -0
  201. package/kbd-key/index.js +65 -0
  202. package/kbd-shortcut/definition.cjs +5 -0
  203. package/kbd-shortcut/definition.js +2 -0
  204. package/kbd-shortcut/index.cjs +3 -0
  205. package/kbd-shortcut/index.js +27 -0
  206. package/layout/definition.cjs +1 -1
  207. package/layout/definition.js +1 -1
  208. package/layout/index.cjs +2 -2
  209. package/layout/index.js +2 -2
  210. package/lib/accordion-item/accordion-item.d.ts +18 -1
  211. package/lib/action-group/action-group.d.ts +18 -1
  212. package/lib/alert/alert.d.ts +36 -2
  213. package/lib/audio-player/audio-player.d.ts +18 -1
  214. package/lib/avatar/avatar.d.ts +18 -1
  215. package/lib/badge/badge.d.ts +18 -1
  216. package/lib/banner/banner.d.ts +54 -3
  217. package/lib/breadcrumb/breadcrumb.d.ts +18 -1
  218. package/lib/breadcrumb-item/breadcrumb-item.d.ts +18 -1
  219. package/lib/button/button.d.ts +54 -3
  220. package/lib/calendar-event/calendar-event.d.ts +18 -1
  221. package/lib/card/card.d.ts +18 -1
  222. package/lib/checkbox/checkbox.d.ts +107 -5
  223. package/lib/color-picker/color-picker.d.ts +126 -7
  224. package/lib/combobox/combobox.d.ts +124 -5
  225. package/lib/components.d.ts +4 -1
  226. package/lib/country-group/country-group.d.ts +36 -2
  227. package/lib/data-grid/data-grid-cell.d.ts +36 -2
  228. package/lib/data-grid/data-grid-row.d.ts +18 -1
  229. package/lib/date-picker/date-picker.d.ts +140 -4
  230. package/lib/date-range-picker/date-range-picker.d.ts +70 -2
  231. package/lib/date-time-picker/date-time-picker.d.ts +140 -4
  232. package/lib/dial-pad/dial-pad.d.ts +18 -1
  233. package/lib/dialog/dialog.d.ts +36 -2
  234. package/lib/divider/divider.d.ts +18 -1
  235. package/lib/fab/fab.d.ts +18 -1
  236. package/lib/file-picker/file-picker.d.ts +124 -5
  237. package/lib/header/header.d.ts +18 -1
  238. package/lib/icon/icon.template.d.ts +1 -2
  239. package/lib/kbd-key/definition.d.ts +4 -0
  240. package/lib/kbd-key/index.d.ts +1 -0
  241. package/lib/kbd-key/kbd-key.d.ts +18 -0
  242. package/lib/kbd-key/kbd-key.template.d.ts +4 -0
  243. package/lib/kbd-shortcut/definition.d.ts +3 -0
  244. package/lib/kbd-shortcut/index.d.ts +1 -0
  245. package/lib/kbd-shortcut/kbd-shortcut.d.ts +4 -0
  246. package/lib/kbd-shortcut/kbd-shortcut.template.d.ts +4 -0
  247. package/lib/menu/menu.d.ts +35 -1
  248. package/lib/menu-item/menu-item.d.ts +463 -2
  249. package/lib/nav/nav.d.ts +18 -1
  250. package/lib/nav-disclosure/nav-disclosure.d.ts +36 -2
  251. package/lib/nav-item/nav-item.d.ts +36 -2
  252. package/lib/note/note.d.ts +18 -1
  253. package/lib/number-field/number-field.d.ts +160 -7
  254. package/lib/option/option.d.ts +36 -2
  255. package/lib/pagination/pagination.d.ts +18 -1
  256. package/lib/platform-switch/definition.d.ts +3 -0
  257. package/lib/platform-switch/index.d.ts +1 -0
  258. package/lib/platform-switch/platform-switch.d.ts +4 -0
  259. package/lib/platform-switch/platform-switch.template.d.ts +4 -0
  260. package/lib/popover/popover.d.ts +36 -2
  261. package/lib/progress/progress.d.ts +18 -1
  262. package/lib/progress-ring/progress-ring.d.ts +18 -1
  263. package/lib/radio/radio.d.ts +53 -2
  264. package/lib/radio-group/radio-group.d.ts +18 -1
  265. package/lib/range-slider/range-slider.d.ts +52 -1
  266. package/lib/rich-text-editor/locale.d.ts +1 -0
  267. package/lib/rich-text-editor/popover.d.ts +1 -0
  268. package/lib/rich-text-editor/rich-text-editor.d.ts +17 -0
  269. package/lib/rich-text-editor/rte/utils/ui.d.ts +1 -0
  270. package/lib/searchable-select/option-tag.d.ts +18 -1
  271. package/lib/searchable-select/searchable-select.d.ts +160 -7
  272. package/lib/select/select.d.ts +160 -7
  273. package/lib/selectable-box/selectable-box.d.ts +18 -1
  274. package/lib/simple-color-picker/simple-color-picker.d.ts +35 -1
  275. package/lib/slider/slider.d.ts +53 -2
  276. package/lib/split-button/split-button.d.ts +54 -3
  277. package/lib/status/status.d.ts +18 -1
  278. package/lib/switch/switch.d.ts +36 -2
  279. package/lib/tab/tab.d.ts +54 -3
  280. package/lib/tab-panel/tab-panel.d.ts +18 -1
  281. package/lib/table/table-cell.d.ts +18 -1
  282. package/lib/table/table-header-cell.d.ts +18 -1
  283. package/lib/table/table-row.d.ts +18 -1
  284. package/lib/table/table-sorting-button.d.ts +18 -1
  285. package/lib/tag/tag.d.ts +54 -3
  286. package/lib/tag-group/tag-group.d.ts +18 -1
  287. package/lib/tag-name-map.d.ts +4 -1
  288. package/lib/text-area/text-area.d.ts +142 -6
  289. package/lib/text-field/text-field.d.ts +160 -7
  290. package/lib/time-picker/time-picker.d.ts +70 -2
  291. package/lib/toggletip/toggletip.d.ts +35 -1
  292. package/lib/tooltip/tooltip.d.ts +444 -0
  293. package/lib/tree-item/tree-item.d.ts +36 -2
  294. package/lib/tree-view/tree-view.d.ts +18 -1
  295. package/lib/video-player/video-player.d.ts +18 -1
  296. package/locales/de-DE.cjs +1 -0
  297. package/locales/de-DE.js +1 -0
  298. package/locales/en-GB.cjs +1 -0
  299. package/locales/en-GB.js +1 -0
  300. package/locales/en-US.cjs +1 -0
  301. package/locales/en-US.js +1 -0
  302. package/locales/ja-JP.cjs +1 -0
  303. package/locales/ja-JP.js +1 -0
  304. package/locales/zh-CN.cjs +1 -0
  305. package/locales/zh-CN.js +1 -0
  306. package/nav/definition.cjs +1 -1
  307. package/nav/definition.js +1 -1
  308. package/nav/index.cjs +2 -2
  309. package/nav/index.js +2 -2
  310. package/nav-disclosure/definition.cjs +1 -1
  311. package/nav-disclosure/definition.js +1 -1
  312. package/nav-disclosure/index.cjs +3 -4
  313. package/nav-disclosure/index.js +11 -11
  314. package/nav-item/definition.cjs +1 -1
  315. package/nav-item/definition.js +1 -1
  316. package/nav-item/index.cjs +2 -2
  317. package/nav-item/index.js +6 -6
  318. package/note/definition.cjs +1 -1
  319. package/note/definition.js +1 -1
  320. package/note/index.cjs +2 -2
  321. package/note/index.js +7 -7
  322. package/number-field/definition.cjs +1 -1
  323. package/number-field/definition.js +1 -1
  324. package/number-field/index.cjs +8 -9
  325. package/number-field/index.js +16 -17
  326. package/package.json +8 -8
  327. package/pagination/definition.cjs +1 -1
  328. package/pagination/definition.js +1 -1
  329. package/pagination/index.cjs +9 -9
  330. package/pagination/index.js +16 -16
  331. package/platform-switch/definition.cjs +5 -0
  332. package/platform-switch/definition.js +2 -0
  333. package/platform-switch/index.cjs +1 -0
  334. package/platform-switch/index.js +28 -0
  335. package/popover/definition.cjs +1 -1
  336. package/popover/definition.js +1 -1
  337. package/popover/index.cjs +6 -6
  338. package/popover/index.js +12 -12
  339. package/progress/definition.cjs +1 -1
  340. package/progress/definition.js +1 -1
  341. package/progress/index.cjs +4 -4
  342. package/progress/index.js +5 -5
  343. package/progress-ring/definition.cjs +1 -1
  344. package/progress-ring/definition.js +1 -1
  345. package/radio/definition.cjs +1 -1
  346. package/radio/definition.js +1 -1
  347. package/radio-group/definition.cjs +1 -1
  348. package/radio-group/definition.js +1 -1
  349. package/radio-group/index.cjs +5 -8
  350. package/radio-group/index.js +16 -16
  351. package/range-slider/definition.cjs +1 -1
  352. package/range-slider/definition.js +1 -1
  353. package/range-slider/index.cjs +5 -5
  354. package/range-slider/index.js +9 -9
  355. package/rich-text-editor/definition.cjs +1 -1
  356. package/rich-text-editor/definition.js +1 -1
  357. package/rich-text-editor/index.cjs +8 -6
  358. package/rich-text-editor/index.js +101 -78
  359. package/rich-text-view/definition.cjs +1 -1
  360. package/rich-text-view/definition.js +1 -1
  361. package/rich-text-view/index.cjs +1 -1
  362. package/rich-text-view/index.js +3 -3
  363. package/searchable-select/definition.cjs +1 -1
  364. package/searchable-select/definition.js +1 -1
  365. package/searchable-select/index.cjs +38 -40
  366. package/searchable-select/index.js +64 -64
  367. package/select/definition.cjs +1 -1
  368. package/select/definition.js +1 -1
  369. package/selectable-box/definition.cjs +1 -1
  370. package/selectable-box/definition.js +1 -1
  371. package/selectable-box/index.cjs +4 -4
  372. package/selectable-box/index.js +13 -13
  373. package/shared/aria/aria-binding-directive.d.ts +4 -4
  374. package/shared/aria/aria-mixin.d.ts +21 -3
  375. package/shared/aria/delegates-aria.d.ts +18 -1
  376. package/shared/aria/host-semantics.d.ts +18 -1
  377. package/shared/aria/idrefs-controller.d.ts +17 -0
  378. package/shared/color-picker/base-color-picker.d.ts +18 -1
  379. package/shared/feedback/feedback-message.d.ts +18 -1
  380. package/shared/feedback/mixins.d.ts +36 -2
  381. package/shared/foundation/button/button.d.ts +35 -1
  382. package/shared/foundation/form-associated/form-associated.d.ts +35 -1
  383. package/shared/foundation/vivid-element/vivid-element.d.ts +375 -0
  384. package/shared/framework/reactive-controller.d.ts +373 -0
  385. package/shared/patterns/affix.d.ts +36 -2
  386. package/shared/patterns/anchored.d.ts +34 -0
  387. package/shared/patterns/char-count/char-count.d.ts +18 -1
  388. package/shared/patterns/form-elements/form-element.d.ts +17 -0
  389. package/shared/patterns/form-elements/with-contextual-help.d.ts +18 -1
  390. package/shared/patterns/form-elements/with-error-text.d.ts +18 -1
  391. package/shared/patterns/form-elements/with-success-text.d.ts +18 -1
  392. package/shared/patterns/index.d.ts +1 -0
  393. package/shared/patterns/kbd-shortcut.d.ts +431 -0
  394. package/shared/patterns/linkable.d.ts +18 -1
  395. package/shared/patterns/localized.d.ts +35 -1
  396. package/shared/patterns/trapped-focus.d.ts +18 -1
  397. package/shared/picker-field/mixins/calendar-picker.d.ts +35 -1
  398. package/shared/picker-field/mixins/calendar-picker.template.d.ts +35 -1
  399. package/shared/picker-field/mixins/inline-time-picker/inline-time-picker.d.ts +18 -1
  400. package/shared/picker-field/mixins/min-max-calendar-picker.d.ts +35 -1
  401. package/shared/picker-field/mixins/single-date-picker.d.ts +35 -1
  402. package/shared/picker-field/mixins/single-value-picker.d.ts +35 -1
  403. package/shared/picker-field/mixins/time-selection-picker.d.ts +35 -1
  404. package/shared/picker-field/mixins/time-selection-picker.template.d.ts +70 -2
  405. package/shared/picker-field/picker-field.d.ts +124 -5
  406. package/shared/templating/render-in-light-dom.d.ts +7 -20
  407. package/shared/utils/platform.d.ts +1 -0
  408. package/side-drawer/definition.cjs +1 -1
  409. package/side-drawer/definition.js +1 -1
  410. package/side-drawer/index.cjs +3 -3
  411. package/side-drawer/index.js +3 -3
  412. package/simple-color-picker/definition.cjs +1 -1
  413. package/simple-color-picker/definition.js +1 -1
  414. package/simple-color-picker/index.cjs +2 -2
  415. package/simple-color-picker/index.js +6 -6
  416. package/split-button/definition.cjs +1 -1
  417. package/split-button/definition.js +1 -1
  418. package/split-button/index.cjs +5 -6
  419. package/split-button/index.js +8 -8
  420. package/status/definition.cjs +1 -1
  421. package/status/definition.js +1 -1
  422. package/status/index.cjs +4 -4
  423. package/status/index.js +9 -9
  424. package/styles/core/all.css +24 -2
  425. package/styles/core/typography.css +24 -2
  426. package/styles/fonts/spezia-variable.css +6 -0
  427. package/styles/tokens/theme-dark.css +2 -0
  428. package/styles/tokens/theme-light.css +2 -0
  429. package/switch/definition.cjs +1 -1
  430. package/switch/definition.js +1 -1
  431. package/switch/index.cjs +3 -3
  432. package/switch/index.js +4 -4
  433. package/tab/definition.cjs +1 -1
  434. package/tab/definition.js +1 -1
  435. package/tab-panel/definition.cjs +1 -1
  436. package/tab-panel/definition.js +1 -1
  437. package/table/definition.cjs +1 -1
  438. package/table/definition.js +1 -1
  439. package/table/index.cjs +9 -9
  440. package/table/index.js +19 -19
  441. package/tabs/definition.cjs +1 -1
  442. package/tabs/definition.js +1 -1
  443. package/tabs/index.cjs +8 -8
  444. package/tabs/index.js +14 -14
  445. package/tag/definition.cjs +1 -1
  446. package/tag/definition.js +1 -1
  447. package/tag/index.cjs +8 -8
  448. package/tag/index.js +11 -11
  449. package/tag-group/definition.cjs +1 -1
  450. package/tag-group/definition.js +1 -1
  451. package/tag-group/index.cjs +2 -2
  452. package/tag-group/index.js +2 -2
  453. package/text-area/definition.cjs +1 -1
  454. package/text-area/definition.js +1 -1
  455. package/text-area/index.cjs +8 -9
  456. package/text-area/index.js +25 -26
  457. package/time-picker/definition.cjs +1 -1
  458. package/time-picker/definition.js +1 -1
  459. package/time-picker/index.cjs +1 -1
  460. package/time-picker/index.js +1 -1
  461. package/tree-item/definition.cjs +1 -1
  462. package/tree-item/definition.js +1 -1
  463. package/tree-view/definition.cjs +1 -1
  464. package/tree-view/definition.js +1 -1
  465. package/tree-view/index.cjs +4 -4
  466. package/tree-view/index.js +7 -7
  467. package/unbundled/affix.cjs +1 -1
  468. package/unbundled/affix.js +1 -1
  469. package/unbundled/aria-binding-directive.cjs +112 -2
  470. package/unbundled/aria-binding-directive.js +108 -4
  471. package/unbundled/calendar-picker.template.cjs +8 -10
  472. package/unbundled/calendar-picker.template.js +8 -10
  473. package/unbundled/char-count.cjs +1 -1
  474. package/unbundled/char-count.js +1 -1
  475. package/unbundled/definition.cjs +91 -17
  476. package/unbundled/definition.js +88 -14
  477. package/unbundled/definition10.js +1 -1
  478. package/unbundled/definition11.js +1 -1
  479. package/unbundled/definition12.cjs +15 -2
  480. package/unbundled/definition12.js +17 -4
  481. package/unbundled/definition13.js +1 -1
  482. package/unbundled/definition14.js +1 -1
  483. package/unbundled/definition15.cjs +1 -1
  484. package/unbundled/definition15.js +2 -2
  485. package/unbundled/definition16.cjs +1 -1
  486. package/unbundled/definition16.js +2 -2
  487. package/unbundled/definition17.cjs +1 -1
  488. package/unbundled/definition17.js +2 -2
  489. package/unbundled/definition18.cjs +1 -1
  490. package/unbundled/definition18.js +2 -2
  491. package/unbundled/definition19.js +1 -1
  492. package/unbundled/definition2.cjs +96 -77
  493. package/unbundled/definition2.js +94 -75
  494. package/unbundled/definition20.js +1 -1
  495. package/unbundled/definition21.js +1 -1
  496. package/unbundled/definition22.cjs +2 -3
  497. package/unbundled/definition22.js +3 -4
  498. package/unbundled/definition23.cjs +3 -3
  499. package/unbundled/definition23.js +5 -5
  500. package/unbundled/definition24.js +1 -1
  501. package/unbundled/definition25.cjs +1 -1
  502. package/unbundled/definition25.js +2 -2
  503. package/unbundled/definition26.cjs +8 -8
  504. package/unbundled/definition26.js +6 -6
  505. package/unbundled/definition27.cjs +26 -12
  506. package/unbundled/definition27.js +28 -14
  507. package/unbundled/definition28.cjs +1 -1
  508. package/unbundled/definition28.js +3 -3
  509. package/unbundled/definition29.cjs +1 -1
  510. package/unbundled/definition29.js +2 -2
  511. package/unbundled/definition3.cjs +154 -95
  512. package/unbundled/definition3.js +146 -93
  513. package/unbundled/definition30.cjs +1 -1
  514. package/unbundled/definition30.js +3 -3
  515. package/unbundled/definition31.cjs +1 -1
  516. package/unbundled/definition31.js +2 -2
  517. package/unbundled/definition32.js +1 -1
  518. package/unbundled/definition33.cjs +1 -1
  519. package/unbundled/definition33.js +2 -2
  520. package/unbundled/definition34.cjs +103 -65
  521. package/unbundled/definition34.js +102 -64
  522. package/unbundled/definition35.cjs +26 -326
  523. package/unbundled/definition35.js +24 -247
  524. package/unbundled/definition36.cjs +131 -25
  525. package/unbundled/definition36.js +124 -23
  526. package/unbundled/definition37.cjs +326 -51
  527. package/unbundled/definition37.js +324 -49
  528. package/unbundled/definition38.cjs +137 -317
  529. package/unbundled/definition38.js +135 -315
  530. package/unbundled/definition39.cjs +337 -173
  531. package/unbundled/definition39.js +334 -170
  532. package/unbundled/definition4.cjs +34 -159
  533. package/unbundled/definition4.js +25 -151
  534. package/unbundled/definition40.cjs +234 -339
  535. package/unbundled/definition40.js +230 -335
  536. package/unbundled/definition41.cjs +48 -271
  537. package/unbundled/definition41.js +44 -267
  538. package/unbundled/definition42.cjs +68 -49
  539. package/unbundled/definition42.js +65 -46
  540. package/unbundled/definition43.cjs +424 -56
  541. package/unbundled/definition43.js +422 -54
  542. package/unbundled/definition44.cjs +45 -428
  543. package/unbundled/definition44.js +42 -425
  544. package/unbundled/definition45.cjs +45 -54
  545. package/unbundled/definition45.js +42 -51
  546. package/unbundled/definition46.cjs +178 -30
  547. package/unbundled/definition46.js +175 -26
  548. package/unbundled/definition47.cjs +29 -94
  549. package/unbundled/definition47.js +25 -91
  550. package/unbundled/definition48.cjs +76 -36
  551. package/unbundled/definition48.js +73 -33
  552. package/unbundled/definition49.cjs +56 -23
  553. package/unbundled/definition49.js +54 -18
  554. package/unbundled/definition5.cjs +56 -38
  555. package/unbundled/definition5.js +52 -28
  556. package/unbundled/definition50.cjs +23 -40
  557. package/unbundled/definition50.js +18 -38
  558. package/unbundled/definition51.cjs +30 -338
  559. package/unbundled/definition51.js +30 -338
  560. package/unbundled/definition52.cjs +317 -187
  561. package/unbundled/definition52.js +314 -184
  562. package/unbundled/definition53.cjs +194 -289
  563. package/unbundled/definition53.js +189 -284
  564. package/unbundled/definition54.cjs +47 -54
  565. package/unbundled/definition54.js +44 -50
  566. package/unbundled/definition55.cjs +279 -133
  567. package/unbundled/definition55.js +277 -130
  568. package/unbundled/definition56.cjs +50 -262
  569. package/unbundled/definition56.js +48 -261
  570. package/unbundled/definition57.cjs +128 -460
  571. package/unbundled/definition57.js +126 -459
  572. package/unbundled/definition58.cjs +235 -3604
  573. package/unbundled/definition58.js +231 -3437
  574. package/unbundled/definition59.cjs +419 -729
  575. package/unbundled/definition59.js +417 -727
  576. package/unbundled/definition6.cjs +18 -64
  577. package/unbundled/definition6.js +15 -60
  578. package/unbundled/definition60.cjs +3666 -106
  579. package/unbundled/definition60.js +3498 -101
  580. package/unbundled/definition61.cjs +625 -878
  581. package/unbundled/definition61.js +619 -872
  582. package/unbundled/definition62.cjs +106 -108
  583. package/unbundled/definition62.js +103 -105
  584. package/unbundled/definition63.cjs +1045 -71
  585. package/unbundled/definition63.js +1041 -66
  586. package/unbundled/definition64.cjs +105 -173
  587. package/unbundled/definition64.js +102 -170
  588. package/unbundled/definition65.cjs +70 -113
  589. package/unbundled/definition65.js +66 -110
  590. package/unbundled/definition66.cjs +185 -54
  591. package/unbundled/definition66.js +182 -51
  592. package/unbundled/definition67.cjs +110 -77
  593. package/unbundled/definition67.js +111 -77
  594. package/unbundled/definition68.cjs +58 -21
  595. package/unbundled/definition68.js +56 -16
  596. package/unbundled/definition69.cjs +82 -75
  597. package/unbundled/definition69.js +81 -75
  598. package/unbundled/definition7.cjs +2 -2
  599. package/unbundled/definition7.js +3 -3
  600. package/unbundled/definition70.cjs +19 -349
  601. package/unbundled/definition70.js +15 -341
  602. package/unbundled/definition71.cjs +88 -26
  603. package/unbundled/definition71.js +86 -23
  604. package/unbundled/definition72.cjs +309 -119
  605. package/unbundled/definition72.js +234 -116
  606. package/unbundled/definition73.cjs +293 -229
  607. package/unbundled/definition73.js +287 -230
  608. package/unbundled/definition74.cjs +39 -30
  609. package/unbundled/definition74.js +29 -28
  610. package/unbundled/definition75.cjs +106 -121
  611. package/unbundled/definition75.js +104 -113
  612. package/unbundled/definition76.cjs +260 -179
  613. package/unbundled/definition76.js +258 -176
  614. package/unbundled/definition77.cjs +29 -514
  615. package/unbundled/definition77.js +27 -503
  616. package/unbundled/definition78.cjs +171 -0
  617. package/unbundled/definition78.js +147 -0
  618. package/unbundled/definition79.cjs +233 -0
  619. package/unbundled/definition79.js +214 -0
  620. package/unbundled/definition8.js +1 -1
  621. package/unbundled/definition80.cjs +533 -0
  622. package/unbundled/definition80.js +513 -0
  623. package/unbundled/definition9.cjs +1 -1
  624. package/unbundled/definition9.js +2 -2
  625. package/unbundled/delegates-aria.cjs +15 -1
  626. package/unbundled/delegates-aria.js +17 -3
  627. package/unbundled/host-semantics.cjs +2 -1
  628. package/unbundled/host-semantics.js +2 -1
  629. package/unbundled/kbd-shortcut.cjs +26 -0
  630. package/unbundled/kbd-shortcut.js +20 -0
  631. package/unbundled/mixins.cjs +7 -77
  632. package/unbundled/mixins.js +6 -64
  633. package/unbundled/platform.cjs +17 -0
  634. package/unbundled/platform.js +12 -0
  635. package/unbundled/randomId.cjs +47 -0
  636. package/unbundled/randomId.js +35 -0
  637. package/unbundled/time-selection-picker.template.js +1 -1
  638. package/unbundled/vivid-element.cjs +82 -9
  639. package/unbundled/vivid-element.js +63 -8
  640. package/video-player/definition.cjs +1 -1
  641. package/video-player/definition.js +1 -1
  642. package/video-player/index.cjs +3 -3
  643. package/video-player/index.js +5 -5
  644. package/visually-hidden/definition.cjs +1 -1
  645. package/visually-hidden/definition.js +1 -1
  646. package/vivid.api.json +604 -6
  647. package/bundled/normalize.cjs +0 -1
  648. package/bundled/normalize.js +0 -7
@@ -1,129 +1,3526 @@
1
- import { c as createRegisterFunction, s as defineVividComponent, t as VividElement } from "./vivid-element.js";
1
+ import { d as createRegisterFunction, t as VividElement, u as defineVividComponent } from "./vivid-element.js";
2
2
  import { t as __decorate } from "./decorate.js";
3
- import { c as impl, n as removeSymbol, s as sortedContributions, t as dispatchSlottableRequest } from "./slottable-request.js";
4
- import { ElementStyles, html, observable, ref } from "@microsoft/fast-element";
5
- import { DOMSerializer, Mark, Node } from "prosemirror-model";
6
- //#region src/lib/rich-text-view/rich-text-view.scss?inline
7
- var rich_text_view_default = ":host{display:contents}.content{overflow-wrap:break-word;white-space:break-spaces;display:contents}";
3
+ import { r as ProgressRing, t as progressRingDefinition } from "./definition5.js";
4
+ import { n as WithObservableLocale } from "./localized.js";
5
+ import { i as Button, t as buttonDefinition } from "./definition7.js";
6
+ import { i as Popup, r as PlacementStrategy, t as popupDefinition } from "./definition10.js";
7
+ import { i as MenuItem, t as menuItemDefinition } from "./definition12.js";
8
+ import { r as Menu, t as menuDefinition } from "./definition13.js";
9
+ import { t as Divider } from "./divider.js";
10
+ import { t as generateRandomId } from "./randomId.js";
11
+ import { n as textFieldDefinition, r as TextField } from "./definition26.js";
12
+ import { n as tooltipDefinition, r as Tooltip } from "./definition27.js";
13
+ import { r as ListboxOption, t as listboxOptionDefinition } from "./definition29.js";
14
+ import { t as dividerDefinition } from "./definition35.js";
15
+ import { a as featureFacade, c as impl, i as contributionPriority, n as removeSymbol, o as getFeatureImpl, r as RteFeatureImpl, s as sortedContributions, t as dispatchSlottableRequest } from "./slottable-request.js";
16
+ import { n as selectDefinition, r as Select } from "./definition61.js";
17
+ import { ElementStyles, html, observable, ref, volatile } from "@microsoft/fast-element";
18
+ import { DOMParser, DOMSerializer, Fragment, NodeRange, Schema, Slice } from "prosemirror-model";
19
+ import { AllSelection, EditorState, NodeSelection, Plugin, PluginKey, TextSelection } from "prosemirror-state";
20
+ import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
21
+ import { keymap } from "prosemirror-keymap";
22
+ import { autoJoin, baseKeymap, chainCommands, createParagraphNear, liftEmptyBlock, newlineInCode, splitBlockAs, toggleMark } from "prosemirror-commands";
23
+ import { dropCursor } from "prosemirror-dropcursor";
24
+ import { gapCursor } from "prosemirror-gapcursor";
25
+ import { closeHistory, history, redo, undo } from "prosemirror-history";
26
+ import DOMPurify from "dompurify";
27
+ import { InputRule, inputRules, undoInputRule } from "prosemirror-inputrules";
28
+ import { RemoveMarkStep, ReplaceAroundStep, dropPoint } from "prosemirror-transform";
29
+ import { marks } from "prosemirror-schema-basic";
30
+ //#region src/lib/rich-text-editor/rich-text-editor.scss?inline
31
+ var rich_text_editor_default = ":host{display:block}.rte{--editor-padding-inline:var(--rich-text-editor-padding-inline,16px);--editor-padding-block:var(--rich-text-editor-padding-block,8px);block-size:100%;max-block-size:inherit;min-block-size:inherit;flex-direction:column;display:flex}.editor{display:contents}.editor-viewport{contain:layout;flex-direction:column;flex:1;min-block-size:0;display:flex;position:relative;overflow:hidden}.editor-scroll-area{background-color:var(--vvd-color-canvas);color:var(--vvd-color-canvas-text);font:var(--vvd-typography-base);--scrollbar-track-color:transparent;--scrollbar-thumb-color:color-mix(in srgb, var(--vvd-color-neutral-950), transparent 70%);scrollbar-color:var(--scrollbar-thumb-color) var(--scrollbar-track-color);scrollbar-width:thin;flex-direction:column;flex:1;min-block-size:0;display:flex;overflow-y:auto}.editor-scroll-area ::-webkit-scrollbar{width:4px}.editor-scroll-area ::-webkit-scrollbar-track{background:var(--scrollbar-track-color)}.editor-scroll-area ::-webkit-scrollbar-thumb{background-color:var(--scrollbar-fallback-track-color,var(--scrollbar-thumb-color));border:0;border-radius:4px}.popovers--disabled>*{display:none!important}";
8
32
  //#endregion
9
- //#region src/lib/rich-text-view/rich-text-view.ts
33
+ //#region src/lib/rich-text-editor/rich-text-editor.ts
10
34
  /**
11
35
  * @public
12
- * @component rich-text-view
13
- * @dynamicSlot `@vonage/vivid#RteChildSlotProps` child - Used for custom rendered children.
36
+ * @component rich-text-editor
37
+ * @slot editor-before - Displayed before the scrollable editor area.
38
+ * @slot editor-start - Displayed at the start of the scrollable editor area.
39
+ * @slot editor-end - Displayed at the end of the scrollable editor area.
40
+ * @slot editor-after - Displayed after the scrollable editor area.
41
+ * @slot status - Displayed between the editor viewport and the toolbar.
42
+ * @slot text-color-picker - Color picker for the RteTextColorFeature.
43
+ * @dynamicSlot `{ url: string }` inline-image-placeholder - Placeholder content for inline images.
44
+ * @dynamicSlot `{ id: string }` suggestions-empty - Empty state if no suggestions are found.
14
45
  */
15
- var RichTextView = class extends VividElement {
16
- constructor(..._args) {
17
- super(..._args);
18
- this._slotCounter = 0;
19
- this._slottedChildren = /* @__PURE__ */ new Set();
20
- this._slotRequests = /* @__PURE__ */ new Set();
21
- this._contentElement = null;
22
- }
46
+ var RichTextEditor = class extends WithObservableLocale(VividElement) {
23
47
  /**
24
48
  * @internal
25
49
  */
26
- viewChanged(oldView, newView) {
27
- if (oldView) this._removeStyles();
28
- if (newView) this._addStyles(newView);
29
- this._updateView();
30
- }
31
- _addStyles(view) {
32
- const config = view[impl].config[impl];
33
- this._styles = new ElementStyles(sortedContributions(config.features.flatMap((f) => f.getStyles())));
34
- this._styles.addStylesTo(this.shadowRoot);
35
- }
36
- _removeStyles() {
37
- if (this._styles) {
38
- this._styles.removeStylesFrom(this.shadowRoot);
39
- this._styles = void 0;
40
- }
41
- }
42
- _cleanupLightDom() {
43
- for (const el of this._slottedChildren) this.removeChild(el);
44
- for (const slotName of this._slotRequests) dispatchSlottableRequest(this, "child", slotName, removeSymbol);
45
- this._slottedChildren.clear();
46
- this._slotRequests.clear();
47
- this._slotCounter = 0;
48
- }
49
- _updateView() {
50
- if (!this._contentElement) return;
51
- this._contentElement.innerHTML = "";
52
- this._cleanupLightDom();
53
- if (this.view) this._contentElement.appendChild(this._renderView(this.view));
54
- }
55
- _renderView(rteView) {
56
- const ctx = rteView[impl];
57
- if (rteView.type === "node" && rteView.node.type === "doc") rteView = rteView.children;
58
- if (rteView.type === "fragment") {
59
- const frag = document.createDocumentFragment();
60
- for (const child of rteView.content) frag.appendChild(this._renderView(child));
61
- return frag;
62
- }
63
- const customRenderedView = ctx.options.renderChildView?.(rteView) ?? false;
64
- if (customRenderedView) return this._handleCustomRender(rteView, customRenderedView);
65
- else return this._renderDefault(rteView);
66
- }
67
- _handleCustomRender(rteView, customResult) {
68
- const slotName = `child-view-${this._slotCounter++}`;
69
- const slot = document.createElement("slot");
70
- slot.setAttribute("name", slotName);
71
- if (customResult === true) {
72
- this._slotRequests.add(slotName);
73
- dispatchSlottableRequest(this, "child", slotName, { view: rteView });
74
- } else {
75
- const { dom, contentDom = dom } = customResult;
76
- const nestedView = document.createElement(this.tagName);
77
- nestedView.view = rteView.children;
78
- contentDom.appendChild(nestedView);
79
- dom.setAttribute("slot", slotName);
80
- this.appendChild(dom);
81
- this._slottedChildren.add(dom);
82
- }
83
- return slot;
84
- }
85
- _renderDefault(view) {
86
- const schema = view[impl].config[impl].schema;
87
- if (view.type === "node" && view.node.type === "text") return document.createTextNode(view.node.text);
88
- const item = view.type === "node" ? view.node : view.mark;
89
- const pmItem = view.type === "node" ? Node.fromJSON(schema, item) : Mark.fromJSON(schema, item);
90
- const spec = pmItem instanceof Node ? pmItem.type.spec.toDOM(pmItem) : pmItem.type.spec.toDOM(pmItem, true);
91
- const { dom, contentDOM = dom } = DOMSerializer.renderSpec(document, spec);
92
- const childrenRendered = this._renderView(view.children);
93
- contentDOM.appendChild(childrenRendered);
94
- return dom;
50
+ instanceChanged(prevInstance) {
51
+ prevInstance?.[impl].destroyViewIfNeeded();
52
+ this._initViewIfNeeded();
53
+ prevInstance?.[impl].styles.removeStylesFrom(this.shadowRoot);
54
+ this.instance?.[impl].styles.addStylesTo(this.shadowRoot);
55
+ }
56
+ _initViewIfNeeded() {
57
+ const instance = this.instance?.[impl];
58
+ if (instance && this.$fastController.isConnected && !instance.view) {
59
+ this._syncStateIfNeeded();
60
+ instance.createView(this._editorEl);
61
+ }
62
+ }
63
+ _destroyViewIfNeeded() {
64
+ this.instance?.[impl].destroyViewIfNeeded();
95
65
  }
96
- /**
97
- * @internal
98
- */
99
66
  connectedCallback() {
100
67
  super.connectedCallback();
101
- this._updateView();
68
+ this._initViewIfNeeded();
69
+ }
70
+ disconnectedCallback() {
71
+ super.disconnectedCallback();
72
+ this._destroyViewIfNeeded();
102
73
  }
103
74
  /**
104
75
  * @internal
105
76
  */
77
+ localeChanged() {
78
+ this._syncStateIfNeeded();
79
+ }
80
+ _syncStateIfNeeded() {
81
+ this.instance?.[impl].updateHostState({
82
+ locale: this.locale,
83
+ ctx: this._ctx
84
+ });
85
+ }
86
+ };
87
+ __decorate([observable], RichTextEditor.prototype, "instance", void 0);
88
+ //#endregion
89
+ //#region src/lib/rich-text-editor/rich-text-editor.template.ts
90
+ var RichTextEditorTemplate = (ctx) => {
91
+ return html`<template :_ctx="${() => ctx}">
92
+ <div class="rte">
93
+ <slot name="editor-before"></slot>
94
+ <div class="editor-viewport" ${ref("editorViewportElement")}>
95
+ <div class="editor-scroll-area" part="editor-scrollable-area">
96
+ <slot name="editor-start"></slot>
97
+ <div class="editor rich-text" ${ref("_editorEl")}></div>
98
+ <div class="popovers"></div>
99
+ <slot name="editor-end"></slot>
100
+ </div>
101
+ </div>
102
+ <slot name="editor-after"></slot>
103
+ <slot name="status"></slot>
104
+ <div class="toolbar"></div>
105
+ </div>
106
+ </template>`;
107
+ };
108
+ //#endregion
109
+ //#region src/lib/rich-text-editor/popover.ts
110
+ var Kind = {
111
+ default: {
112
+ placement: void 0,
113
+ placementStrategy: PlacementStrategy.AutoPlacementHorizontal,
114
+ strategy: "absolute"
115
+ },
116
+ autocomplete: {
117
+ placement: "bottom-start",
118
+ placementStrategy: PlacementStrategy.Flip,
119
+ strategy: "fixed"
120
+ }
121
+ };
122
+ var popoverTemplate = (context) => {
123
+ const popup = context.tagFor(Popup);
124
+ return html`<${popup}
125
+ :anchor="${(x) => x.anchorEl}"
126
+ :placement="${(x) => Kind[x.kind].placement}"
127
+ :placementStrategy="${(x) => Kind[x.kind].placementStrategy}"
128
+ :open="${(x) => x.open}"
129
+ :offset="${(x) => x.offset}"
130
+ :strategy="${(x) => Kind[x.kind].strategy}"
131
+ exportparts="vvd-theme-alternate"
132
+ >
133
+ <slot></slot>
134
+ </${popup}>`;
135
+ };
136
+ var Popover = class extends VividElement {
137
+ constructor(..._args) {
138
+ super(..._args);
139
+ this.kind = "default";
140
+ this.anchorBlocksPopover = false;
141
+ this.onAnchorBlockPopoverChanged = () => {
142
+ this.anchorBlocksPopover = this.anchorEl?.dataset.blockPopover === "true" || false;
143
+ };
144
+ this.requestedOpenState = false;
145
+ }
146
+ static setBlockPopover(onElement, block) {
147
+ onElement.dataset.blockPopover = block ? "true" : "false";
148
+ const event = new CustomEvent("block-popover-changed", {
149
+ bubbles: false,
150
+ composed: false
151
+ });
152
+ onElement.dispatchEvent(event);
153
+ }
154
+ /** Closes the popover. It reopens when anchorEl changes to a new element that does not block it. */
155
+ dismiss() {
156
+ this.anchorBlocksPopover = true;
157
+ }
158
+ anchorElChanged(prev, next) {
159
+ prev?.removeEventListener("block-popover-changed", this.onAnchorBlockPopoverChanged);
160
+ next?.addEventListener("block-popover-changed", this.onAnchorBlockPopoverChanged);
161
+ this.onAnchorBlockPopoverChanged();
162
+ }
163
+ anchorIdChanged() {
164
+ this.updateAnchor();
165
+ }
166
+ updateAnchor() {
167
+ if (this.anchorId && this.isConnected) this.anchorEl = this.getRootNode().getElementById(this.anchorId) || void 0;
168
+ else this.anchorEl = void 0;
169
+ }
170
+ requestOpenState(open) {
171
+ this.requestedOpenState = open;
172
+ }
173
+ get open() {
174
+ return this.requestedOpenState && !!this.anchorEl && !this.anchorBlocksPopover;
175
+ }
176
+ #observer;
177
+ connectedCallback() {
178
+ super.connectedCallback();
179
+ this.updateAnchor();
180
+ this.#observer = new MutationObserver((records) => {
181
+ if (records.some((r) => Array.from(r.addedNodes).some((n) => n instanceof HTMLElement && n.id === this.anchorId))) this.updateAnchor();
182
+ });
183
+ this.#observer.observe(this.getRootNode(), {
184
+ childList: true,
185
+ subtree: true
186
+ });
187
+ }
106
188
  disconnectedCallback() {
107
189
  super.disconnectedCallback();
108
- this._removeStyles();
109
- this._cleanupLightDom();
190
+ this.#observer.disconnect();
191
+ }
192
+ };
193
+ __decorate([observable], Popover.prototype, "kind", void 0);
194
+ __decorate([observable], Popover.prototype, "offset", void 0);
195
+ __decorate([observable], Popover.prototype, "anchorBlocksPopover", void 0);
196
+ __decorate([observable], Popover.prototype, "anchorEl", void 0);
197
+ __decorate([observable], Popover.prototype, "anchorId", void 0);
198
+ __decorate([observable], Popover.prototype, "requestedOpenState", void 0);
199
+ __decorate([volatile], Popover.prototype, "open", null);
200
+ var popoverDefinition = defineVividComponent("rich-text-editor-popover", Popover, popoverTemplate, [popupDefinition], {});
201
+ //#endregion
202
+ //#region ../../node_modules/.pnpm/prosemirror-view@1.41.8/node_modules/prosemirror-view/style/prosemirror.css?inline
203
+ var prosemirror_default = ".ProseMirror{word-wrap:break-word;white-space:pre-wrap;white-space:break-spaces;-webkit-font-variant-ligatures:none;font-variant-ligatures:none;font-feature-settings:\"liga\" 0;position:relative}.ProseMirror pre{white-space:pre-wrap}.ProseMirror li{position:relative}.ProseMirror-hideselection ::selection{background:0 0}.ProseMirror-hideselection ::selection{background:0 0}.ProseMirror-hideselection{caret-color:#0000}.ProseMirror [draggable][contenteditable=false]{user-select:text}.ProseMirror-selectednode{outline:2px solid #8cf}li.ProseMirror-selectednode{outline:none}li.ProseMirror-selectednode:after{content:\"\";pointer-events:none;border:2px solid #8cf;position:absolute;inset:-2px -2px -2px -32px}img.ProseMirror-separator{border:none!important;margin:0!important;display:inline!important}";
204
+ //#endregion
205
+ //#region src/lib/rich-text-editor/rte/utils/default-textblock.ts
206
+ function defaultTextblockForMatch(match) {
207
+ for (let i = 0; i < match.edgeCount; i++) {
208
+ const { type } = match.edge(i);
209
+ /* v8 ignore if -- @preserve It's currently not possible to exercise this code in our RTE */
210
+ if (type.isTextblock && !type.hasRequiredAttrs()) return type;
211
+ }
212
+ /* v8 ignore next 1 -- @preserve*/
213
+ throw new Error("No default textblock found.");
214
+ }
215
+ //#endregion
216
+ //#region src/lib/rich-text-editor/rte/utils/ui.style.scss?inline
217
+ var ui_style_default = "[data-class=ui-select]{min-inline-size:120px;margin-block:-4px}.ui-divider{block-size:20px}.ui-button-group{gap:4px;display:flex}.ui-tooltip,.ui-menu{--_popup-display:contents;display:contents}.ui-tooltip-wrapper{display:contents}";
218
+ //#endregion
219
+ //#region src/lib/rich-text-editor/rte/utils/feature-state.ts
220
+ var FeatureState = class {
221
+ constructor(initialValue) {
222
+ this.plugin = new Plugin({ state: {
223
+ init: () => initialValue,
224
+ apply: (tr, value) => {
225
+ const meta = tr.getMeta(this.plugin);
226
+ return meta !== void 0 ? meta : value;
227
+ }
228
+ } });
229
+ }
230
+ getValue(rte) {
231
+ return this.plugin.getState(rte.state);
232
+ }
233
+ setValue(rte, newValue) {
234
+ rte.dispatchTransaction(rte.tr.setMeta(this.plugin, newValue));
110
235
  }
111
236
  };
112
- __decorate([observable], RichTextView.prototype, "view", void 0);
113
237
  //#endregion
114
- //#region src/lib/rich-text-view/rich-text-view.template.ts
115
- var RichTextViewTemplate = () => html`<div class="content rich-text" ${ref("_contentElement")}></div>`;
238
+ //#region src/lib/rich-text-editor/rte/features/internal/core.style.scss?inline
239
+ var core_style_default = ".ProseMirror{box-sizing:border-box;padding:var(--editor-padding-block) var(--editor-padding-inline);outline:none;flex:1 0 0}.ProseMirror-selectednode{--focus-stroke-gap-color:transparent;--focus-border-radius:2px;outline:none;position:relative}.ProseMirror-selectednode:after{box-shadow:0 0 0 4px color-mix(in srgb, var(--focus-stroke-color,var(--vvd-color-cta-500)), transparent 85%), inset 0 0 0 3px var(--focus-stroke-gap-color,currentColor);outline:1px solid var(--focus-stroke-color,var(--vvd-color-cta-500));outline-offset:calc(-1px - var(--focus-inset,0px));border-radius:var(--focus-border-radius,inherit);block-size:calc(100% + var(--focus-block-size-addition,4px));content:\"\";inline-size:calc(100% + var(--focus-block-size-addition,4px));display:block;position:absolute;inset-block-start:50%;inset-inline-start:50%;transform:translate(-50%,-50%)}.editor--disabled .ProseMirror{color:var(--vvd-color-neutral-300);cursor:not-allowed}";
240
+ //#endregion
241
+ //#region src/lib/rich-text-editor/rte/utils/ui.ts
242
+ var isPropBinding = (prop) => typeof prop === "function";
243
+ var on = (event, prop, handler) => [
244
+ event,
245
+ prop,
246
+ handler
247
+ ];
248
+ var UiCtx = class {
249
+ constructor(view, rte, props) {
250
+ this.view = view;
251
+ this.rte = rte;
252
+ this.props = props;
253
+ this.bindings = [];
254
+ }
255
+ evalProp(prop) {
256
+ return isPropBinding(prop) ? prop(this) : prop;
257
+ }
258
+ bindProp(prop, bindFn) {
259
+ if (prop === void 0) return;
260
+ else if (isPropBinding(prop)) {
261
+ const binding = () => bindFn(prop(this));
262
+ this.bindings.push(binding);
263
+ binding();
264
+ } else bindFn(prop);
265
+ }
266
+ updateBindings() {
267
+ for (const binding of this.bindings) binding();
268
+ }
269
+ bindToEl(target, props = {}, events = [], children = []) {
270
+ for (const name in props) this.bindProp(props[name], (value) => {
271
+ target[name] = value;
272
+ });
273
+ for (const [name, value, bindFn] of events) if (value) target.addEventListener(name, bindFn(value));
274
+ for (const child of children) target.appendChild(child);
275
+ }
276
+ };
277
+ var createDiv = (ctx, props) => {
278
+ const div = document.createElement("div");
279
+ ctx.bindToEl(div, {
280
+ className: props.className,
281
+ slot: props.slot
282
+ }, [], props.children);
283
+ return div;
284
+ };
285
+ var createAnchor = (ctx, props) => {
286
+ const anchor = document.createElement("a");
287
+ ctx.bindToEl(anchor, {
288
+ href: props.href,
289
+ target: props.target,
290
+ rel: props.rel,
291
+ className: props.className
292
+ }, [], props.children);
293
+ return anchor;
294
+ };
295
+ var wrapperTargets = /* @__PURE__ */ new WeakMap();
296
+ var createOptionalTooltip = (ctx, props) => {
297
+ const tooltip = ctx.rte.createComponent(Tooltip);
298
+ tooltip.setAttribute("exportparts", "vvd-theme-alternate");
299
+ ctx.bindToEl(tooltip, {
300
+ className: "ui-tooltip",
301
+ text: props.label,
302
+ placement: ctx.props.popupPlacement
303
+ });
304
+ ctx.bindProp(props.enabled, (enabled) => {
305
+ if (!enabled) tooltip.open = false;
306
+ tooltip.anchor = enabled ? props.anchor : void 0;
307
+ });
308
+ const wrapper = createDiv(ctx, {
309
+ className: "ui-tooltip-wrapper",
310
+ slot: props.slot,
311
+ children: [props.anchor, tooltip]
312
+ });
313
+ wrapperTargets.set(wrapper, props.anchor);
314
+ return wrapper;
315
+ };
316
+ var createButton = (ctx, props) => {
317
+ const variant = () => ctx.evalProp(props.variant) ?? "toolbar";
318
+ const size = () => variant() === "toolbar" ? "super-condensed" : "condensed";
319
+ const appearanceInactive = () => variant() === "popover-primary" ? "outlined" : "ghost-light";
320
+ const appearanceActive = () => variant() === "toolbar-menu" || variant() === "popover" ? "filled" : appearanceInactive();
321
+ const appearance = () => ctx.evalProp(props.active) ? appearanceActive() : appearanceInactive();
322
+ const connotation = () => ctx.evalProp(props.connotation) ?? (variant() === "toolbar-menu" && ctx.evalProp(props.active) ? "cta" : void 0);
323
+ const disabled = () => Boolean(ctx.evalProp(ctx.props.disabled) || ctx.evalProp(props.disabled));
324
+ const button = ctx.rte.createComponent(Button);
325
+ ctx.bindToEl(button, {
326
+ size,
327
+ appearance,
328
+ disabled,
329
+ icon: props.icon,
330
+ autofocus: props.autofocus,
331
+ connotation,
332
+ [props.icon ? "ariaLabel" : "label"]: props.label,
333
+ pressed: () => Boolean(ctx.evalProp(props.active)),
334
+ ariaPressed: props.active !== void 0 ? () => ctx.evalProp(props.active) ? "true" : "false" : void 0
335
+ }, [on("click", props.onClick, (onClick) => () => {
336
+ if (!onClick()) ctx.view.focus();
337
+ })]);
338
+ return createOptionalTooltip(ctx, {
339
+ enabled: () => Boolean(ctx.evalProp(props.icon) && !ctx.evalProp(props.noTooltip) && !disabled()),
340
+ label: props.label,
341
+ anchor: button,
342
+ slot: props.slot
343
+ });
344
+ };
345
+ var createMenu = (ctx, props) => {
346
+ const menu = ctx.rte.createComponent(Menu);
347
+ ctx.bindToEl(menu, {
348
+ className: "ui-menu",
349
+ autoDismiss: true,
350
+ ariaLabel: props.label,
351
+ anchor: wrapperTargets.get(props.trigger) ?? props.trigger,
352
+ placement: ctx.props.popupPlacement,
353
+ offset: () => ctx.evalProp(ctx.props.menuOffset) ?? null
354
+ }, [], props.children);
355
+ const fragment = document.createDocumentFragment();
356
+ fragment.appendChild(props.trigger);
357
+ fragment.appendChild(menu);
358
+ return fragment;
359
+ };
360
+ var createMenuItem = (ctx, props) => {
361
+ const disabled = () => Boolean(ctx.evalProp(ctx.props.disabled) || ctx.evalProp(props.disabled));
362
+ const item = ctx.rte.createComponent(MenuItem);
363
+ ctx.bindToEl(item, {
364
+ text: props.text,
365
+ checked: props.checked,
366
+ disabled,
367
+ controlType: "radio",
368
+ checkedAppearance: "tick-only"
369
+ }, [on("change", props.onSelect, (onSelect) => () => {
370
+ if (item.checked && !item.disabled) {
371
+ if (ctx.evalProp(props.checked) !== item.checked) {
372
+ onSelect();
373
+ ctx.view.focus();
374
+ }
375
+ }
376
+ })]);
377
+ return item;
378
+ };
379
+ var createButtonGroup = (ctx, props) => createDiv(ctx, {
380
+ slot: props.slot,
381
+ className: "ui-button-group",
382
+ children: props.children
383
+ });
384
+ function markActive(state, type) {
385
+ const { from, $from, to, empty } = state.selection;
386
+ if (empty) return !!type.isInSet(state.storedMarks || $from.marks());
387
+ else return state.doc.rangeHasMark(from, to, type);
388
+ }
389
+ var createMarkToggle = (ctx, props) => createButton(ctx, {
390
+ label: props.label,
391
+ icon: props.icon,
392
+ active: () => markActive(ctx.view.state, props.markType),
393
+ disabled: () => !toggleMark(props.markType)(ctx.view.state),
394
+ onClick: () => {
395
+ toggleMark(props.markType)(ctx.view.state, ctx.view.dispatch);
396
+ }
397
+ });
398
+ var createOption = (ctx, props) => {
399
+ const disabled = () => Boolean(ctx.evalProp(ctx.props.disabled) || ctx.evalProp(props.disabled));
400
+ const option = ctx.rte.createComponent(ListboxOption);
401
+ ctx.bindToEl(option, {
402
+ value: props.value,
403
+ text: props.text,
404
+ disabled
405
+ });
406
+ return option;
407
+ };
408
+ var createSelect = (ctx, props) => {
409
+ const disabled = () => Boolean(ctx.evalProp(ctx.props.disabled));
410
+ const select = ctx.rte.createComponent(Select);
411
+ select.setAttribute("data-class", "ui-select");
412
+ ctx.bindToEl(select, {
413
+ placeholder: " ",
414
+ ariaLabel: props.label,
415
+ appearance: "ghost",
416
+ disabled
417
+ }, [on("change", props.onSelect, (onSelect) => () => {
418
+ const value = select.value;
419
+ if (value) {
420
+ onSelect(value);
421
+ ctx.view.focus();
422
+ }
423
+ })], props.children);
424
+ queueMicrotask(() => {
425
+ ctx.bindProp(props.value, (value) => select.value = value);
426
+ });
427
+ let hideTooltip = false;
428
+ select.addEventListener("vwc-popup:open", () => {
429
+ hideTooltip = true;
430
+ ctx.updateBindings();
431
+ });
432
+ select.addEventListener("vwc-popup:close", () => {
433
+ hideTooltip = false;
434
+ ctx.updateBindings();
435
+ });
436
+ return createOptionalTooltip(ctx, {
437
+ enabled: () => !hideTooltip && !disabled(),
438
+ label: props.label,
439
+ anchor: select
440
+ });
441
+ };
442
+ var createDivider = (ctx) => {
443
+ const divider = ctx.rte.createComponent(Divider);
444
+ ctx.bindToEl(divider, {
445
+ className: "ui-divider",
446
+ orientation: "vertical"
447
+ });
448
+ return divider;
449
+ };
450
+ var createTextField = (ctx, props) => {
451
+ const textField = ctx.rte.createComponent(TextField);
452
+ ctx.bindToEl(textField, {
453
+ label: props.label,
454
+ value: props.value,
455
+ placeholder: props.placeholder,
456
+ slot: props.slot,
457
+ autofocus: props.autofocus,
458
+ type: props.type,
459
+ helperText: props.helperText
460
+ }, [on("input", props.onInput, (onInput) => () => {
461
+ onInput(textField.value);
462
+ })]);
463
+ return textField;
464
+ };
465
+ var createText = (ctx, props) => {
466
+ const textNode = document.createTextNode("");
467
+ ctx.bindToEl(textNode, { textContent: props.text });
468
+ return textNode;
469
+ };
470
+ var createSingleSlot = (ctx, props) => {
471
+ const slot = document.createElement("slot");
472
+ slot.name = props.name;
473
+ let currentEl = null;
474
+ const listeners = [];
475
+ function cleanup() {
476
+ for (const { el, type, handler } of listeners) el.removeEventListener(type, handler);
477
+ listeners.length = 0;
478
+ currentEl = null;
479
+ }
480
+ for (const [key, prop] of Object.entries(props.assignedProps)) ctx.bindProp(prop, (value) => {
481
+ if (currentEl) currentEl[key] = value;
482
+ });
483
+ function applyPropsAndEvents(el) {
484
+ for (const [key, prop] of Object.entries(props.assignedProps)) el[key] = ctx.evalProp(prop);
485
+ for (const [type, handler] of Object.entries(props.assignedEvents)) {
486
+ const listener = (e) => {
487
+ handler(e);
488
+ ctx.view.focus();
489
+ };
490
+ el.addEventListener(type, listener);
491
+ listeners.push({
492
+ el,
493
+ type,
494
+ handler: listener
495
+ });
496
+ }
497
+ }
498
+ const processSlot = () => {
499
+ const first = slot.assignedElements({ flatten: true })[0];
500
+ if (first === currentEl) return;
501
+ cleanup();
502
+ if (first) {
503
+ currentEl = first;
504
+ applyPropsAndEvents(first);
505
+ }
506
+ };
507
+ slot.addEventListener("slotchange", processSlot);
508
+ queueMicrotask(processSlot);
509
+ return slot;
510
+ };
511
+ //#endregion
512
+ //#region src/lib/rich-text-editor/rte/features/internal/history.ts
513
+ var RteHistoryFeatureImpl = class extends RteFeatureImpl {
514
+ constructor(..._args) {
515
+ super(..._args);
516
+ this.name = "RteHistoryFeature";
517
+ }
518
+ getPlugins() {
519
+ return [this.contribution(history()), this.contribution(keymap({
520
+ "Mod-z": undo,
521
+ "Ctrl-y": redo,
522
+ "Cmd-Z": redo
523
+ }))];
524
+ }
525
+ getToolbarItems() {
526
+ return [this.contribution({
527
+ section: "history",
528
+ render: (ctx) => createButton(ctx, {
529
+ label: (ctx) => ctx.rte.getLocale().richTextEditor.undo,
530
+ icon: "undo-line",
531
+ disabled: (ctx) => !undo(ctx.view.state),
532
+ onClick: () => {
533
+ const { state, dispatch } = ctx.view;
534
+ undo(state, dispatch);
535
+ }
536
+ })
537
+ }, 1), this.contribution({
538
+ section: "history",
539
+ render: (ctx) => createButton(ctx, {
540
+ label: (ctx) => ctx.rte.getLocale().richTextEditor.redo,
541
+ icon: "redo-line",
542
+ disabled: (ctx) => !redo(ctx.view.state),
543
+ onClick: () => {
544
+ const { state, dispatch } = ctx.view;
545
+ redo(state, dispatch);
546
+ }
547
+ })
548
+ }, 2)];
549
+ }
550
+ };
551
+ //#endregion
552
+ //#region src/lib/rich-text-editor/rte/features/internal/foreign-html.ts
553
+ var RteForeignHtmlFeatureImpl = class extends RteFeatureImpl {
554
+ constructor(..._args) {
555
+ super(..._args);
556
+ this.name = "RteForeignHtmlFeature";
557
+ }
558
+ getPlugins(rte) {
559
+ return [this.contribution(new Plugin({ props: {
560
+ transformPastedHTML: (html) => rte.foreignHtmlParser[impl].transform(html),
561
+ clipboardParser: rte.foreignHtmlParser[impl].parser,
562
+ clipboardSerializer: rte.foreignHtmlSerializer[impl].serializer
563
+ } }))];
564
+ }
565
+ };
566
+ //#endregion
567
+ //#region src/lib/rich-text-editor/rte/features/internal/cursor-fix.ts
568
+ /**
569
+ * When the cursor is positioned after an inline atom node at the end of a line,
570
+ * browsers may display the cursor inside the atom.
571
+ */
572
+ var atomCursorFix = ($cursor) => {
573
+ if (!($cursor.parentOffset === $cursor.parent.content.size)) return null;
574
+ const nodeBefore = $cursor.nodeBefore;
575
+ if (nodeBefore && nodeBefore.isInline && nodeBefore.isAtom && !nodeBefore.isText) return {};
576
+ return null;
577
+ };
578
+ var RteCursorFixFeatureImpl = class extends RteFeatureImpl {
579
+ constructor(..._args) {
580
+ super(..._args);
581
+ this.name = "RteCursorFix";
582
+ }
583
+ getPlugins(rte) {
584
+ const cursorFixes = [atomCursorFix];
585
+ for (const markType of Object.values(rte.schema.marks)) {
586
+ const spec = markType.spec;
587
+ if (spec.cursorFix) cursorFixes.push(spec.cursorFix);
588
+ }
589
+ return [this.contribution(new Plugin({ props: { decorations: (state) => {
590
+ const { $cursor } = state.selection;
591
+ if (!$cursor) return null;
592
+ let cursorFix = null;
593
+ for (const fn of cursorFixes) {
594
+ const result = fn($cursor, state);
595
+ if (result) Object.assign(cursorFix ??= {}, result);
596
+ }
597
+ if (!cursorFix) return null;
598
+ return DecorationSet.create(state.doc, [Decoration.widget($cursor.pos, () => {
599
+ const span = document.createElement("span");
600
+ span.textContent = "​";
601
+ for (const [prop, value] of Object.entries(cursorFix)) span.style.setProperty(prop, value);
602
+ return span;
603
+ }, { side: -1 })]);
604
+ } } }))];
605
+ }
606
+ };
607
+ featureFacade(RteCursorFixFeatureImpl);
608
+ //#endregion
609
+ //#region src/lib/rich-text-editor/rte/features/internal/core.ts
610
+ /**
611
+ * Plugin to bring state from the host web component into ProseMirror.
612
+ */
613
+ var hostBridgePlugin = new Plugin({ state: {
614
+ init() {
615
+ return null;
616
+ },
617
+ apply(tr, value) {
618
+ const meta = tr.getMeta(hostBridgePlugin);
619
+ if (meta) return meta;
620
+ else return value;
621
+ }
622
+ } });
623
+ var RteCoreImpl = class extends RteFeatureImpl {
624
+ constructor(..._args) {
625
+ super(..._args);
626
+ this.name = "RteCore";
627
+ this.disabled = new FeatureState(false);
628
+ }
629
+ getStyles() {
630
+ return [
631
+ this.contribution(prosemirror_default),
632
+ this.contribution(core_style_default),
633
+ this.contribution(ui_style_default)
634
+ ];
635
+ }
636
+ getPlugins(rte) {
637
+ const enterKeyChainCommands = chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlockAs((node, atEnd, $from) => {
638
+ if (!atEnd) return {
639
+ type: node.type,
640
+ attrs: node.attrs
641
+ };
642
+ return {
643
+ type: defaultTextblockForMatch($from.node($from.depth - 1).contentMatchAt($from.indexAfter($from.depth - 1))),
644
+ attrs: rte.textblockAttrs.extractFromNode(node)
645
+ };
646
+ }));
647
+ return [
648
+ this.contribution(this.disabled.plugin),
649
+ this.contribution(new Plugin({
650
+ props: {
651
+ editable: () => !this.disabled.getValue(rte),
652
+ handleDOMEvents: { click: (_view, event) => {
653
+ if (this.disabled.getValue(rte)) {
654
+ event.preventDefault();
655
+ return true;
656
+ }
657
+ return false;
658
+ } }
659
+ },
660
+ view: (view) => {
661
+ const popovers = view.dom.getRootNode().querySelector(".popovers");
662
+ const updateDisabled = () => {
663
+ const disabled = this.disabled.getValue(rte);
664
+ popovers.classList.toggle("popovers--disabled", disabled);
665
+ view.dom.parentElement.classList.toggle("editor--disabled", disabled);
666
+ };
667
+ updateDisabled();
668
+ return { update: () => {
669
+ updateDisabled();
670
+ } };
671
+ }
672
+ })),
673
+ this.contribution(keymap({
674
+ ...baseKeymap,
675
+ Enter: enterKeyChainCommands,
676
+ "Shift-Enter": enterKeyChainCommands
677
+ })),
678
+ this.contribution(dropCursor()),
679
+ this.contribution(gapCursor()),
680
+ this.contribution(hostBridgePlugin)
681
+ ];
682
+ }
683
+ getFeatures() {
684
+ return [
685
+ this,
686
+ new RteHistoryFeatureImpl(),
687
+ new RteForeignHtmlFeatureImpl(),
688
+ new RteCursorFixFeatureImpl()
689
+ ];
690
+ }
691
+ };
692
+ featureFacade(RteCoreImpl);
693
+ //#endregion
694
+ //#region src/lib/rich-text-editor/rte/utils/sanitization.ts
695
+ var DEFAULT_ALLOWED_URI_REGEXP = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$))/i;
696
+ var ALLOWED_URI_REGEXP_WITH_BLOB = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|blob):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$))/i;
697
+ var ATTR_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
698
+ var domPurifyConfig = { ALLOWED_URI_REGEXP: ALLOWED_URI_REGEXP_WITH_BLOB };
699
+ /**
700
+ * Sanitize potentially dangerous URLs, like "javascript:", in anchor href attributes.
701
+ * Returns empty string if the URL is unsafe.
702
+ */
703
+ var sanitizeLinkHref = (url) => {
704
+ if (!DEFAULT_ALLOWED_URI_REGEXP.test(url.replace(ATTR_WHITESPACE, ""))) return "";
705
+ const anchor = document.createElement("a");
706
+ anchor.setAttribute("href", url);
707
+ /* v8 ignore next -- since href is already validated it's probably always present @preserve */
708
+ return DOMPurify.sanitize(anchor, {
709
+ RETURN_DOM: true,
710
+ ...domPurifyConfig
711
+ }).querySelector("a").getAttribute("href") ?? "";
712
+ };
713
+ /**
714
+ * Sanitize potentially dangerous URLs, like "javascript:", in image src attributes.
715
+ * Returns empty string if the URL is unsafe.
716
+ */
717
+ var sanitizeImageSrc = (url) => {
718
+ const img = document.createElement("img");
719
+ img.setAttribute("src", url);
720
+ return DOMPurify.sanitize(img, {
721
+ RETURN_DOM: true,
722
+ ...domPurifyConfig
723
+ }).querySelector("img").getAttribute("src") ?? "";
724
+ };
725
+ /**
726
+ * Escapes a CSS value for insertion into style attribute.
727
+ * E.g. "15px; background: red" => "15px"
728
+ */
729
+ var escapeCssProperty = (value) => value.replace(/[;!].*/, "");
730
+ //#endregion
731
+ //#region src/lib/rich-text-editor/rte/html-parser.ts
732
+ var copy = (obj) => ({ ...obj });
733
+ var parseRulesFromSchema = (schema) => ({
734
+ nodes: Object.fromEntries(Object.keys(schema.nodes).map((name) => [name, (schema.nodes[name].spec.parseDOM ?? []).map(copy)])),
735
+ marks: Object.fromEntries(Object.keys(schema.marks).map((name) => [name, (schema.marks[name].spec.parseDOM ?? []).map(copy)]))
736
+ });
737
+ var RteHtmlParser = class {
738
+ constructor(config, options) {
739
+ this[impl] = new RteHtmlParserImpl(config[impl], options);
740
+ }
741
+ /**
742
+ * Converts an HTML string to an RteDocument.
743
+ */
744
+ parseDocument(html, options) {
745
+ return this[impl].parser.parse(this.parseHtml(html, options), { preserveWhitespace: true }).toJSON();
746
+ }
747
+ /**
748
+ * Converts an HTML string to an RteFragment.
749
+ */
750
+ parseFragment(html, options) {
751
+ return this[impl].parser.parseSlice(this.parseHtml(html, options), { preserveWhitespace: true }).content.toJSON() ?? [];
752
+ }
753
+ parseHtml(html, options) {
754
+ const dom = DOMPurify.sanitize(html, {
755
+ RETURN_DOM: true,
756
+ ...domPurifyConfig
757
+ });
758
+ const container = document.createDocumentFragment();
759
+ container.appendChild(dom);
760
+ options?.modifyDom?.(container);
761
+ return container;
762
+ }
763
+ };
764
+ var RteHtmlParserImpl = class {
765
+ constructor(config, options) {
766
+ const rules = parseRulesFromSchema(config.schema);
767
+ options?.modifyParseRules?.(rules);
768
+ this.parser = buildDomParser(config.schema, rules);
769
+ }
770
+ transform(html) {
771
+ return DOMPurify.sanitize(html);
772
+ }
773
+ };
774
+ var buildDomParser = (schema, { marks, nodes }) => {
775
+ const parserRules = [];
776
+ const priority = (rule) => rule.priority ?? 50;
777
+ function insert(rule) {
778
+ let i = 0;
779
+ for (; i < parserRules.length; i++) {
780
+ const next = parserRules[i];
781
+ if (priority(next) < priority(rule)) break;
782
+ }
783
+ parserRules.splice(i, 0, rule);
784
+ }
785
+ for (const name in marks) marks[name]?.forEach((rule) => {
786
+ insert(rule = copy(rule));
787
+ if (!(rule.mark || rule.ignore || rule.clearMark)) rule.mark = name;
788
+ });
789
+ for (const name in nodes) nodes[name]?.forEach((rule) => {
790
+ insert(rule = copy(rule));
791
+ if (!(rule.node || rule.ignore || rule.mark)) rule.node = name;
792
+ });
793
+ parserRules.push({
794
+ tag: "br",
795
+ closeParent: true
796
+ });
797
+ return new DOMParser(schema, parserRules);
798
+ };
799
+ //#endregion
800
+ //#region src/lib/rich-text-editor/rte/html-serializer.ts
801
+ var RteHtmlSerializer = class {
802
+ constructor(config, options) {
803
+ this[impl] = new RteHtmlSerializerImpl(config[impl], options);
804
+ }
805
+ /**
806
+ * Converts an RteDocument to an HTML string.
807
+ */
808
+ serializeDocument(doc, options) {
809
+ return this[impl].serializeFragment(doc.content, options);
810
+ }
811
+ /**
812
+ * Converts an RteFragment to an HTML string.
813
+ */
814
+ serializeFragment(fragment, options) {
815
+ return this[impl].serializeFragment(fragment, options);
816
+ }
817
+ };
818
+ var RteHtmlSerializerImpl = class RteHtmlSerializerImpl {
819
+ constructor(config, options) {
820
+ this.config = config;
821
+ const serializers = RteHtmlSerializerImpl.domSerializersFromSchema(config.schema);
822
+ Object.assign(serializers.nodes, options?.serializers?.nodes ?? {});
823
+ Object.assign(serializers.marks, options?.serializers?.marks ?? {});
824
+ this.serializer = new DOMSerializer(serializers.nodes, serializers.marks);
825
+ }
826
+ static domSerializersFromSchema(schema) {
827
+ const result = {
828
+ nodes: {},
829
+ marks: {}
830
+ };
831
+ for (const name in schema.marks) {
832
+ const toDOM = schema.marks[name].spec.toDOM;
833
+ if (toDOM) result.marks[name] = toDOM;
834
+ }
835
+ for (const name in schema.nodes) {
836
+ const toDOM = schema.nodes[name].spec.serializeToDOM ?? schema.nodes[name].spec.toDOM;
837
+ if (toDOM) result.nodes[name] = toDOM;
838
+ }
839
+ result.nodes.text = (node) => document.createTextNode(node.text);
840
+ return result;
841
+ }
842
+ serializeFragment(fragment, options) {
843
+ const parsedFragment = Fragment.fromJSON(this.config.schema, fragment);
844
+ const serializedFragment = this.serializer.serializeFragment(parsedFragment);
845
+ const container = document.createDocumentFragment();
846
+ container.appendChild(serializedFragment);
847
+ options?.modifyDom?.(container);
848
+ const output = document.createElement("div");
849
+ output.appendChild(container);
850
+ return output.innerHTML;
851
+ }
852
+ };
853
+ //#endregion
854
+ //#region src/lib/rich-text-editor/rte/instance.ts
855
+ var parseDocument = (schema, doc) => {
856
+ const node = schema.topNodeType.createAndFill(null, doc ? Fragment.fromJSON(schema, doc.content) : null);
857
+ if (!node) throw new Error("Document could not be parsed");
858
+ node.check();
859
+ return node;
860
+ };
861
+ var RteInstance = class {
862
+ constructor(config, options) {
863
+ this.options = options;
864
+ this.feature = (Feature, featureId) => {
865
+ return this[impl].getPublicInterface(Feature, featureId);
866
+ };
867
+ this[impl] = new RteInstanceImpl(this, config, options);
868
+ }
869
+ /**
870
+ * Returns the current document state.
871
+ */
872
+ getDocument() {
873
+ return this[impl].state.doc.toJSON();
874
+ }
875
+ /**
876
+ * Reset the editor to its initial state. Optionally, an initial document can be provided.
877
+ */
878
+ reset(initialDocument) {
879
+ this[impl].reset(initialDocument);
880
+ }
881
+ /**
882
+ * Replaces the current selection with the given content.
883
+ * If no text is selected, this inserts the content at the cursor position.
884
+ */
885
+ replaceSelection(content, options) {
886
+ const { state, tr, schema, dispatchTransaction } = this[impl];
887
+ tr.replaceSelection(new Slice(Fragment.fromJSON(schema, content), 0, 0));
888
+ tr.doc.check();
889
+ const $from = tr.doc.resolve(tr.mapping.map(state.selection.from));
890
+ const $to = tr.doc.resolve(tr.selection.to);
891
+ const [$head, $anchor] = options?.cursorPlacement === "start" ? [$from, $to] : [$to, $from];
892
+ if (options?.selectContent) tr.setSelection(state.selection instanceof AllSelection ? new AllSelection(tr.doc) : TextSelection.between($anchor, $head));
893
+ else tr.setSelection(TextSelection.between($head, $head));
894
+ dispatchTransaction(tr);
895
+ }
896
+ /**
897
+ * Replaces the entire document with the given new document.
898
+ * Unlike reset, this preserves the rest of the editor state. The undo history is preserved, so the user can undo the replacement.
899
+ */
900
+ replaceDocument(newDocument, options) {
901
+ const { state, tr, schema, dispatchTransaction } = this[impl];
902
+ tr.replaceWith(0, state.doc.content.size, parseDocument(schema, newDocument));
903
+ if (options?.selectContent) tr.setSelection(new AllSelection(tr.doc));
904
+ else if (options?.cursorPlacement === "end") tr.setSelection(TextSelection.atEnd(tr.doc));
905
+ else tr.setSelection(TextSelection.atStart(tr.doc));
906
+ dispatchTransaction(tr);
907
+ }
908
+ };
909
+ var RteInstanceImpl = class {
910
+ getFeature(name) {
911
+ const f = this.config.featureMap.get(name);
912
+ if (!f) throw new Error(`Feature not found: ${name}`);
913
+ return f;
914
+ }
915
+ getPublicInterface(Feature, featureId) {
916
+ const instances = this.config.featureFacadesMap.get(Feature);
917
+ if (!instances || instances.length === 0) throw new Error(`Feature not found`);
918
+ if (instances[0].featureId !== void 0) {
919
+ if (featureId === void 0) throw new Error(`No featureId provided for multi-instance feature.`);
920
+ const instance = instances.find((f) => f.featureId === featureId);
921
+ if (!instance) throw new Error(`Feature with id "${featureId}" not found`);
922
+ return instance.getPublicInterface(this);
923
+ }
924
+ if (featureId !== void 0) throw new Error(`Feature does not support featureId`);
925
+ return instances[0].getPublicInterface(this);
926
+ }
927
+ constructor(instanceFacade, configFacade, options) {
928
+ this.options = options;
929
+ this.view = null;
930
+ this.dispatchTransaction = (tr) => {
931
+ const prevState = this.state;
932
+ this.state = this.state.apply(tr);
933
+ this.view?.updateState(this.state);
934
+ if (prevState.doc !== this.state.doc) this.options?.onChange?.();
935
+ return this.state;
936
+ };
937
+ this.facade = instanceFacade;
938
+ const config = configFacade[impl];
939
+ this.config = config;
940
+ this.schema = config.schema;
941
+ this.textblockAttrs = config.textblockAttrs;
942
+ this.features = config.features;
943
+ this.foreignHtmlParser = options?.foreignHtmlParser ?? new RteHtmlParser(configFacade);
944
+ this.foreignHtmlSerializer = options?.foreignHtmlSerializer ?? new RteHtmlSerializer(configFacade);
945
+ this.styles = new ElementStyles(sortedContributions(config.features.flatMap((f) => f.getStyles())));
946
+ this.initState(options?.initialDocument);
947
+ }
948
+ initState(initialDoc) {
949
+ this.state = EditorState.create({
950
+ doc: parseDocument(this.schema, initialDoc),
951
+ schema: this.config.schema,
952
+ plugins: sortedContributions(this.config.features.flatMap((feature) => feature.getPlugins(this)))
953
+ });
954
+ }
955
+ reset(initialDocument) {
956
+ const currentHostState = hostBridgePlugin.getState(this.state);
957
+ this.initState(initialDocument);
958
+ this.updateHostState(currentHostState);
959
+ this.view?.updateState(this.state);
960
+ }
961
+ createView(target) {
962
+ this.view = new EditorView((editor) => {
963
+ editor.part = "editor";
964
+ target.appendChild(editor);
965
+ }, {
966
+ state: this.state,
967
+ dispatchTransaction: this.dispatchTransaction
968
+ });
969
+ }
970
+ destroyViewIfNeeded() {
971
+ if (this.view) {
972
+ this.view.destroy();
973
+ this.view = null;
974
+ }
975
+ }
976
+ createComponent(type) {
977
+ return document.createElement(this.hostState().ctx.tagFor(type, true));
978
+ }
979
+ getLocale() {
980
+ return this.hostState().locale;
981
+ }
982
+ get tr() {
983
+ return this.state.tr;
984
+ }
985
+ hostState() {
986
+ const state = hostBridgePlugin.getState(this.state);
987
+ if (!state) throw new Error("No host state available");
988
+ return state;
989
+ }
990
+ updateHostState(hostState) {
991
+ this.dispatchTransaction(this.tr.setMeta(hostBridgePlugin, hostState));
992
+ }
993
+ };
994
+ //#endregion
995
+ //#region src/lib/rich-text-editor/rte/utils/textblock-attrs.ts
996
+ var TextblockAttrs = class {
997
+ constructor(specs) {
998
+ this.specs = specs;
999
+ this.attrs = {};
1000
+ for (const spec of specs) this.attrs[spec.name] = { default: spec.default };
1001
+ }
1002
+ fromDOM(dom) {
1003
+ return Object.assign({}, ...this.specs.map((s) => ({ [s.name]: s.fromDOM(dom) })));
1004
+ }
1005
+ getStyle(node) {
1006
+ return this.specs.flatMap((s) => s.toStyles(node)).join("; ");
1007
+ }
1008
+ getDOMAttrsProperties(node) {
1009
+ if (!this.specs.length) return {};
1010
+ return { style: this.getStyle(node) };
1011
+ }
1012
+ getDOMAttrs(node) {
1013
+ if (!this.specs.length) return [];
1014
+ return [this.getDOMAttrsProperties(node)];
1015
+ }
1016
+ extractFromNode(node) {
1017
+ return Object.assign({}, ...Object.keys(this.attrs).map((attr) => ({ [attr]: node.attrs[attr] })));
1018
+ }
1019
+ };
1020
+ //#endregion
1021
+ //#region src/lib/rich-text-editor/rte/utils/textblock-marks.ts
1022
+ var TextblockMarks = class {
1023
+ constructor(specs) {
1024
+ this.specs = specs;
1025
+ }
1026
+ getAllowedMarksForNode(nodeName) {
1027
+ return this.specs.filter((spec) => !spec.onNodeName || spec.onNodeName === nodeName).map((spec) => spec.markName);
1028
+ }
1029
+ getReferencedNodeNames() {
1030
+ return new Set(this.specs.map((spec) => spec.onNodeName).filter(Boolean));
1031
+ }
1032
+ };
1033
+ //#endregion
1034
+ //#region src/lib/rich-text-editor/rte/view.ts
1035
+ /**
1036
+ * Converts an RteDocument to an RteView tree for rendering outside the editor.
1037
+ * The logic is adapted from ProseMirror's DOM serialization to ensure the resulting structure
1038
+ * matches the editor's HTML structure.
1039
+ */
1040
+ var convertToView = (doc, ctx) => {
1041
+ const schema = ctx.config[impl].schema;
1042
+ const getMarkRank = (mark) => schema.marks[mark.type].rank;
1043
+ const marksEqual = (a, b) => {
1044
+ if (a.type !== b.type) return false;
1045
+ const attrsA = a.attrs;
1046
+ const attrsB = b.attrs;
1047
+ if (attrsA === attrsB) return true;
1048
+ /* v8 ignore next -- not currently reachable since all attrs are required @preserve */
1049
+ if (!attrsA || !attrsB) return false;
1050
+ const keysA = Object.keys(attrsA);
1051
+ const keysB = Object.keys(attrsB);
1052
+ /* v8 ignore next -- not currently reachable since all attrs are required @preserve */
1053
+ if (keysA.length !== keysB.length) return false;
1054
+ for (const key of keysA) if (attrsA[key] !== attrsB[key]) return false;
1055
+ return true;
1056
+ };
1057
+ const convertFragment = (nodes) => {
1058
+ const result = [];
1059
+ const active = [];
1060
+ const activeContents = [result];
1061
+ for (const node of nodes) {
1062
+ const nodeMarks = [...node.marks ?? []].sort((a, b) => getMarkRank(a) - getMarkRank(b));
1063
+ let keep = 0;
1064
+ let rendered = 0;
1065
+ while (keep < active.length && rendered < nodeMarks.length) {
1066
+ if (!marksEqual(active[keep], nodeMarks[rendered])) break;
1067
+ keep++;
1068
+ rendered++;
1069
+ }
1070
+ while (active.length > keep) {
1071
+ active.pop();
1072
+ activeContents.pop();
1073
+ }
1074
+ while (rendered < nodeMarks.length) {
1075
+ const mark = nodeMarks[rendered];
1076
+ const markContent = [];
1077
+ activeContents[activeContents.length - 1].push({
1078
+ type: "mark",
1079
+ mark,
1080
+ children: {
1081
+ type: "fragment",
1082
+ content: markContent,
1083
+ [impl]: ctx
1084
+ },
1085
+ [impl]: ctx
1086
+ });
1087
+ active.push(mark);
1088
+ activeContents.push(markContent);
1089
+ rendered++;
1090
+ }
1091
+ activeContents[activeContents.length - 1].push({
1092
+ type: "node",
1093
+ node,
1094
+ children: convertFragment(node.content ?? []),
1095
+ [impl]: ctx
1096
+ });
1097
+ }
1098
+ return {
1099
+ type: "fragment",
1100
+ content: result,
1101
+ [impl]: ctx
1102
+ };
1103
+ };
1104
+ return {
1105
+ type: "node",
1106
+ node: doc,
1107
+ children: convertFragment(doc.content),
1108
+ [impl]: ctx
1109
+ };
1110
+ };
1111
+ //#endregion
1112
+ //#region src/lib/rich-text-editor/rte/config.ts
1113
+ var RteConfig = class {
1114
+ constructor(features) {
1115
+ this[impl] = new RteConfigImpl(features);
1116
+ }
1117
+ instantiateEditor(options) {
1118
+ return new RteInstance(this, options);
1119
+ }
1120
+ instantiateView(document, options) {
1121
+ return convertToView(document, {
1122
+ config: this,
1123
+ options: { ...options }
1124
+ });
1125
+ }
1126
+ };
1127
+ var RteConfigImpl = class {
1128
+ constructor(featuresFacades) {
1129
+ const resolveFeatures = (features) => features.flatMap((f) => f.getFeatures().flatMap((subFeature) => subFeature === f ? f : resolveFeatures([subFeature])));
1130
+ this.features = resolveFeatures(featuresFacades.map(getFeatureImpl));
1131
+ this.featureMap = /* @__PURE__ */ new Map();
1132
+ for (const f of this.features) {
1133
+ if (this.featureMap.has(f.name)) throw new Error(`Duplicate feature: ${f.name}`);
1134
+ this.featureMap.set(f.name, f);
1135
+ }
1136
+ this.featureFacadesMap = /* @__PURE__ */ new Map();
1137
+ for (const facade of featuresFacades) {
1138
+ const FacadeClass = facade.constructor;
1139
+ const feature = getFeatureImpl(facade);
1140
+ const instances = this.featureFacadesMap.get(FacadeClass);
1141
+ if (instances) instances.push(feature);
1142
+ else this.featureFacadesMap.set(FacadeClass, [feature]);
1143
+ }
1144
+ if (!this.featureMap.has("RteBase")) throw new Error("RteBase feature is required");
1145
+ if (this.featureMap.has("RteLinkFeature") && !this.featureMap.has("RteToolbarFeature")) throw new Error("RteToolbarFeature is required for RteLinkFeature");
1146
+ this.textblockAttrs = new TextblockAttrs(sortedContributions(this.features.flatMap((f) => f.getTextblockAttrs())));
1147
+ this.textblockMarks = new TextblockMarks(sortedContributions(this.features.flatMap((f) => f.getTextblockMarks())));
1148
+ const schemaContributions = sortedContributions(this.features.flatMap((f) => f.getSchema(this.textblockAttrs, this.textblockMarks)));
1149
+ const schemaSpec = {
1150
+ nodes: {},
1151
+ marks: {}
1152
+ };
1153
+ for (const schema of schemaContributions) {
1154
+ Object.assign(schemaSpec.nodes, schema.nodes ?? {});
1155
+ Object.assign(schemaSpec.marks, schema.marks ?? {});
1156
+ }
1157
+ for (const referencedNodeName of this.textblockMarks.getReferencedNodeNames()) if (!(referencedNodeName in schemaSpec.nodes)) throw new Error(`Unknown node "${referencedNodeName}"`);
1158
+ this.schema = new Schema(schemaSpec);
1159
+ }
1160
+ };
1161
+ //#endregion
1162
+ //#region src/lib/rich-text-editor/rte/features/internal/basic-text-blocks.style.scss?inline
1163
+ var basic_text_blocks_style_default = "h1,h2,h3,p{all:unset;display:block}h1:first-child,h2:first-child,h3:first-child,p:first-child{margin-block-start:0}h1:last-child,h2:last-child,h3:last-child,p:last-child{margin-block-end:0}p{font:var(--vvd-typography-base);font-variant-ligatures:unset;font-feature-settings:unset;margin-block:16px;line-height:20px}.heading-step-1{font:var(--vvd-typography-heading-4);font-variant-ligatures:unset;font-feature-settings:unset;margin-block:24px 12px;line-height:28px}.heading-step-2{font:var(--vvd-typography-heading-3);font-variant-ligatures:unset;font-feature-settings:unset;margin-block:24px 12px;line-height:36px}.heading-step-3{font:var(--vvd-typography-heading-2);font-variant-ligatures:unset;font-feature-settings:unset;margin-block:32px 16px;line-height:42px}";
1164
+ //#endregion
1165
+ //#region src/lib/rich-text-editor/rte/features/internal/basic-text-blocks.ts
1166
+ var RteBasicTextBlocksImpl = class extends RteFeatureImpl {
1167
+ constructor(enabledBlocks) {
1168
+ super();
1169
+ this.enabledBlocks = enabledBlocks;
1170
+ this.name = "RteBasicTextBlocks";
1171
+ }
1172
+ getStyles() {
1173
+ return [this.contribution(basic_text_blocks_style_default)];
1174
+ }
1175
+ getSchema(textblockAttrs, textblockMarks) {
1176
+ const nodes = {};
1177
+ if (this.enabledBlocks.paragraph) nodes["paragraph"] = {
1178
+ group: "block",
1179
+ content: "inline*",
1180
+ attrs: { ...textblockAttrs.attrs },
1181
+ parseDOM: [{
1182
+ tag: "p",
1183
+ getAttrs: (dom) => textblockAttrs.fromDOM(dom)
1184
+ }],
1185
+ marks: textblockMarks.getAllowedMarksForNode("paragraph").join(" "),
1186
+ toDOM(node) {
1187
+ return [
1188
+ "p",
1189
+ {
1190
+ part: `node--paragraph`,
1191
+ ...textblockAttrs.getDOMAttrsProperties(node)
1192
+ },
1193
+ 0
1194
+ ];
1195
+ },
1196
+ serializeToDOM(node) {
1197
+ return [
1198
+ "p",
1199
+ ...textblockAttrs.getDOMAttrs(node),
1200
+ 0
1201
+ ];
1202
+ }
1203
+ };
1204
+ let headingCount = 0;
1205
+ for (const level of [
1206
+ 3,
1207
+ 2,
1208
+ 1
1209
+ ]) {
1210
+ const nodeName = `heading${level}`;
1211
+ const tag = `h${level}`;
1212
+ if (!this.enabledBlocks[nodeName]) continue;
1213
+ headingCount++;
1214
+ const visualLevel = headingCount;
1215
+ nodes[nodeName] = {
1216
+ group: "block",
1217
+ content: "inline*",
1218
+ attrs: { ...textblockAttrs.attrs },
1219
+ parseDOM: [{
1220
+ tag,
1221
+ getAttrs: (dom) => textblockAttrs.fromDOM(dom)
1222
+ }],
1223
+ marks: textblockMarks.getAllowedMarksForNode(nodeName).join(" "),
1224
+ defining: true,
1225
+ toDOM(node) {
1226
+ return [
1227
+ tag,
1228
+ {
1229
+ class: `heading-step-${visualLevel}`,
1230
+ part: `node--${nodeName}`,
1231
+ ...textblockAttrs.getDOMAttrsProperties(node)
1232
+ },
1233
+ 0
1234
+ ];
1235
+ },
1236
+ serializeToDOM(node) {
1237
+ return [
1238
+ tag,
1239
+ ...textblockAttrs.getDOMAttrs(node),
1240
+ 0
1241
+ ];
1242
+ }
1243
+ };
1244
+ }
1245
+ return [this.contribution({ nodes })];
1246
+ }
1247
+ getPlugins(rte) {
1248
+ const keyBindings = {};
1249
+ if (this.enabledBlocks.paragraph) keyBindings["Mod-Alt-0"] = this.setBlockType(rte, "paragraph");
1250
+ for (const level of [
1251
+ 1,
1252
+ 2,
1253
+ 3
1254
+ ]) {
1255
+ const nodeName = `heading${level}`;
1256
+ if (this.enabledBlocks[nodeName]) keyBindings[`Mod-Alt-${level}`] = this.setBlockType(rte, nodeName);
1257
+ }
1258
+ return [this.contribution(keymap(keyBindings))];
1259
+ }
1260
+ getCurrentBlockType(state) {
1261
+ const { $from, $to } = state.selection;
1262
+ const fromTopBlock = $from.depth === 0 ? state.doc.childAfter($from.pos).node : $from.node(1);
1263
+ if (fromTopBlock !== ($to.depth === 0 ? state.doc.childBefore($to.pos).node : $to.node(1))) return null;
1264
+ if (!(fromTopBlock.type.name in this.enabledBlocks)) return null;
1265
+ return fromTopBlock.type.name;
1266
+ }
1267
+ setBlockType(rte, name) {
1268
+ return (state, dispatch) => {
1269
+ const { from, to } = state.selection;
1270
+ const tr = state.tr;
1271
+ let supportedNodeFound = false;
1272
+ state.doc.nodesBetween(from, to, (node, pos) => {
1273
+ if (node.type.name in this.enabledBlocks) {
1274
+ supportedNodeFound = true;
1275
+ tr.setBlockType(pos, pos + node.nodeSize, state.schema.nodes[name], (oldNode) => rte.textblockAttrs.extractFromNode(oldNode));
1276
+ }
1277
+ return false;
1278
+ });
1279
+ if (!supportedNodeFound) return false;
1280
+ dispatch?.(tr);
1281
+ return true;
1282
+ };
1283
+ }
1284
+ };
1285
+ //#endregion
1286
+ //#region src/lib/rich-text-editor/rte/utils/text-before-cursor.ts
1287
+ /**
1288
+ * Get the text content before the cursor position in the current text block.
1289
+ */
1290
+ var textBeforeCursor = ($cursor) => $cursor.parent.textBetween(0, $cursor.parentOffset, void 0, "");
1291
+ //#endregion
1292
+ //#region src/lib/rich-text-editor/rte/features/internal/input-rules.ts
1293
+ /**
1294
+ * Aggregates all input rules from other features.
1295
+ */
1296
+ var RteInputRulesFeatureImpl = class extends RteFeatureImpl {
1297
+ constructor(..._args) {
1298
+ super(..._args);
1299
+ this.name = "RteInputRulesFeature";
1300
+ }
1301
+ getPlugins(rte) {
1302
+ const ruleSpecs = sortedContributions(rte.config.features.flatMap((f) => f.getInputRules(rte)));
1303
+ if (ruleSpecs.length === 0) return [];
1304
+ const plugins = [];
1305
+ const rules = ruleSpecs.map((spec) => spec.rule);
1306
+ plugins.push(this.contribution(inputRules({ rules })));
1307
+ plugins.push(this.contribution(keymap({ Backspace: undoInputRule }), contributionPriority.high));
1308
+ const enterHandlers = ruleSpecs.filter((spec) => spec.enterHandler).map((spec) => spec.enterHandler);
1309
+ if (enterHandlers.length > 0) plugins.push(this.contribution(keymap({ Enter: (state, dispatch) => {
1310
+ const { $cursor } = state.selection;
1311
+ if (!$cursor) return false;
1312
+ const textBefore = textBeforeCursor($cursor);
1313
+ for (const { regex, handler } of enterHandlers) {
1314
+ const match = regex.exec(textBefore);
1315
+ if (!match) continue;
1316
+ const matchStart = $cursor.pos - $cursor.parentOffset + match.index;
1317
+ const tr = handler(state, match, matchStart, matchStart + match[0].length);
1318
+ if (tr) dispatch?.(tr);
1319
+ break;
1320
+ }
1321
+ return false;
1322
+ } }), contributionPriority.highest));
1323
+ return plugins;
1324
+ }
1325
+ };
1326
+ //#endregion
1327
+ //#region src/lib/rich-text-editor/rte/features/base.ts
1328
+ var RteBaseImpl = class extends RteFeatureImpl {
1329
+ constructor(config) {
1330
+ super();
1331
+ this.config = config;
1332
+ this.name = "RteBase";
1333
+ }
1334
+ getSchema() {
1335
+ return [this.contribution({ nodes: {
1336
+ doc: { content: "block+" },
1337
+ text: { group: "inline" }
1338
+ } })];
1339
+ }
1340
+ getFeatures() {
1341
+ return [
1342
+ this,
1343
+ new RteCoreImpl(),
1344
+ new RteBasicTextBlocksImpl({
1345
+ heading1: this.config?.heading1 ?? false,
1346
+ heading2: this.config?.heading2 ?? false,
1347
+ heading3: this.config?.heading3 ?? false,
1348
+ paragraph: this.config?.paragraph ?? true
1349
+ }),
1350
+ new RteInputRulesFeatureImpl()
1351
+ ];
1352
+ }
1353
+ getPublicInterface(rte) {
1354
+ const core = rte.getFeature("RteCore");
1355
+ return {
1356
+ get disabled() {
1357
+ return core.disabled.getValue(rte);
1358
+ },
1359
+ set disabled(value) {
1360
+ core.disabled.setValue(rte, value);
1361
+ }
1362
+ };
1363
+ }
1364
+ };
1365
+ var RteBase = featureFacade(RteBaseImpl);
1366
+ //#endregion
1367
+ //#region src/lib/rich-text-editor/rte/features/text-block-picker.ts
1368
+ var RteTextBlockPickerFeatureImpl = class extends RteFeatureImpl {
1369
+ constructor(config) {
1370
+ super();
1371
+ this.config = config;
1372
+ this.name = "RteTextBlockPickerFeature";
1373
+ }
1374
+ getToolbarItems(rte) {
1375
+ const blocks = rte.getFeature("RteBasicTextBlocks");
1376
+ return [this.contribution({
1377
+ section: "font",
1378
+ render: (ctx) => {
1379
+ return createSelect(ctx, {
1380
+ label: () => ctx.rte.getLocale().richTextEditor.paragraphStyles,
1381
+ value: (ctx) => blocks.getCurrentBlockType(ctx.view.state) ?? "",
1382
+ onSelect: (value) => {
1383
+ const { state, dispatch } = ctx.view;
1384
+ blocks.setBlockType(rte, value)(state, dispatch);
1385
+ },
1386
+ children: this.config.options.map((opt) => createOption(ctx, {
1387
+ text: opt.label,
1388
+ value: opt.node,
1389
+ disabled: () => !blocks.setBlockType(rte, opt.node)(ctx.view.state)
1390
+ }))
1391
+ });
1392
+ }
1393
+ }, 1)];
1394
+ }
1395
+ };
1396
+ var RteTextBlockPickerFeature = featureFacade(RteTextBlockPickerFeatureImpl);
1397
+ //#endregion
1398
+ //#region src/lib/rich-text-editor/rte/features/toolbar.style.scss?inline
1399
+ var toolbar_style_default = ".toolbar{background-color:var(--vvd-color-neutral-50);flex-wrap:wrap;align-items:center;gap:8px;padding:4px;display:flex}.toolbar--hidden{display:none}";
1400
+ //#endregion
1401
+ //#region src/lib/rich-text-editor/rte/features/toolbar.ts
1402
+ var RteToolbarFeatureImpl = class extends RteFeatureImpl {
1403
+ constructor(config) {
1404
+ super();
1405
+ this.config = config;
1406
+ this.name = "RteToolbarFeature";
1407
+ this.hidden = new FeatureState(false);
1408
+ }
1409
+ getStyles() {
1410
+ return [this.contribution(toolbar_style_default)];
1411
+ }
1412
+ getPlugins(rte) {
1413
+ const sections = [
1414
+ "history",
1415
+ "font",
1416
+ "text-style",
1417
+ "textblock",
1418
+ "insert"
1419
+ ];
1420
+ const itemsBySection = new Map(sections.map((section) => [section, []]));
1421
+ for (const toolbarItem of sortedContributions(rte.features.flatMap((f) => f.getToolbarItems(rte)))) itemsBySection.get(toolbarItem.section).push(toolbarItem);
1422
+ const core = rte.getFeature("RteCore");
1423
+ return [this.contribution(this.hidden.plugin), this.contribution(new Plugin({ view: (view) => {
1424
+ const ctx = new UiCtx(view, rte, {
1425
+ popupPlacement: this.config?.popupDirection === "outward" ? "bottom" : "top",
1426
+ menuOffset: 8,
1427
+ disabled: () => core.disabled.getValue(rte)
1428
+ });
1429
+ const toolbar = view.dom.getRootNode().querySelector(".toolbar");
1430
+ ctx.bindProp(() => this.hidden.getValue(rte), (hidden) => {
1431
+ toolbar.classList.toggle("toolbar--hidden", hidden);
1432
+ });
1433
+ let openSection = false;
1434
+ for (const section of sections) {
1435
+ const items = itemsBySection.get(section);
1436
+ if (items.length && openSection) {
1437
+ toolbar.appendChild(createDivider(ctx));
1438
+ openSection = false;
1439
+ }
1440
+ for (const toolbarItemSpec of items) {
1441
+ toolbar.appendChild(toolbarItemSpec.render(ctx));
1442
+ openSection = true;
1443
+ }
1444
+ }
1445
+ return {
1446
+ update() {
1447
+ ctx.updateBindings();
1448
+ },
1449
+ destroy() {
1450
+ toolbar.innerHTML = "";
1451
+ }
1452
+ };
1453
+ } }))];
1454
+ }
1455
+ getPublicInterface(rte) {
1456
+ const hidden = this.hidden;
1457
+ return {
1458
+ get hidden() {
1459
+ return hidden.getValue(rte);
1460
+ },
1461
+ set hidden(value) {
1462
+ hidden.setValue(rte, value);
1463
+ }
1464
+ };
1465
+ }
1466
+ };
1467
+ var RteToolbarFeature = featureFacade(RteToolbarFeatureImpl);
1468
+ //#endregion
1469
+ //#region src/lib/rich-text-editor/rte/features/placeholder.style.scss?inline
1470
+ var placeholder_style_default = ".placeholder{display:contents}.placeholder:before{color:var(--vvd-color-neutral-600);content:attr(data-placeholder);font-size:var(--placeholder-font-size,inherit);inset-inline:var(--editor-padding-inline);line-height:inherit;pointer-events:none;position:absolute}.editor--disabled .placeholder:before{color:var(--vvd-color-neutral-300)}";
1471
+ //#endregion
1472
+ //#region src/lib/rich-text-editor/rte/features/placeholder.ts
1473
+ var RtePlaceholderFeatureImpl = class extends RteFeatureImpl {
1474
+ constructor(config) {
1475
+ super();
1476
+ this.config = config;
1477
+ this.name = "RtePlaceholderFeature";
1478
+ }
1479
+ getStyles() {
1480
+ return [this.contribution(placeholder_style_default)];
1481
+ }
1482
+ getPlugins() {
1483
+ const placeholderPlugin = new Plugin({ props: { decorations: (state) => {
1484
+ if (state.doc.nodeSize === 4) {
1485
+ const storedSize = state.schema.marks.fontSize?.isInSet(state.storedMarks ?? [])?.attrs.size;
1486
+ return DecorationSet.create(state.doc, [Decoration.widget(1, () => {
1487
+ const placeholder = document.createElement("span");
1488
+ placeholder.className = "placeholder";
1489
+ placeholder.dataset.placeholder = this.config.text;
1490
+ if (storedSize) placeholder.style.setProperty("--placeholder-font-size", storedSize);
1491
+ return placeholder;
1492
+ })]);
1493
+ }
1494
+ return null;
1495
+ } } });
1496
+ return [this.contribution(placeholderPlugin)];
1497
+ }
1498
+ };
1499
+ var RtePlaceholderFeature = featureFacade(RtePlaceholderFeatureImpl);
1500
+ //#endregion
1501
+ //#region src/lib/rich-text-editor/rte/features/hard-break.ts
1502
+ var RteHardBreakFeatureImpl = class extends RteFeatureImpl {
1503
+ constructor(..._args) {
1504
+ super(..._args);
1505
+ this.name = "RteHardBreakFeature";
1506
+ }
1507
+ getSchema() {
1508
+ return [this.contribution({ nodes: { hardBreak: {
1509
+ inline: true,
1510
+ group: "inline",
1511
+ selectable: false,
1512
+ parseDOM: [{ tag: "br" }],
1513
+ toDOM() {
1514
+ return ["br"];
1515
+ }
1516
+ } } })];
1517
+ }
1518
+ getPlugins(_rte) {
1519
+ const forceBreak = (state, dispatch) => {
1520
+ dispatch?.(state.tr.replaceSelectionWith(state.schema.nodes.hardBreak.create(), true).scrollIntoView());
1521
+ return true;
1522
+ };
1523
+ const keyBindings = { "Shift-Enter": forceBreak };
1524
+ return [this.contribution(keymap(keyBindings), contributionPriority.high)];
1525
+ }
1526
+ };
1527
+ var RteHardBreakFeature = featureFacade(RteHardBreakFeatureImpl);
1528
+ //#endregion
1529
+ //#region src/lib/rich-text-editor/rte/features/font-size-picker.ts
1530
+ var mixedFontSize = Symbol("mixedFontSize");
1531
+ var RteFontSizePickerFeatureImpl = class extends RteFeatureImpl {
1532
+ constructor(config) {
1533
+ super();
1534
+ this.config = config;
1535
+ this.name = "RteFontSizePickerFeature";
1536
+ this.fontSizes = config.options;
1537
+ if (config.onBlocks) {
1538
+ this.defaultFontSizeForNode = {};
1539
+ for (const block of config.onBlocks) this.defaultFontSizeForNode[block.node] = block.defaultSize ?? null;
1540
+ }
1541
+ }
1542
+ getTextblockMarks() {
1543
+ if (this.config?.onBlocks) return this.config.onBlocks.map((block) => this.contribution({
1544
+ markName: "fontSize",
1545
+ onNodeName: block.node
1546
+ }));
1547
+ return [this.contribution({ markName: "fontSize" })];
1548
+ }
1549
+ getSchema() {
1550
+ return [this.contribution({ marks: { fontSize: {
1551
+ attrs: { size: { validate: "string" } },
1552
+ parseDOM: [{
1553
+ tag: "span[style*='font-size']",
1554
+ getAttrs: (node) => {
1555
+ const size = node.getAttribute("style").match(/font-size:\s*([^;]+)/)?.[1]?.trim();
1556
+ if (size) return { size };
1557
+ return false;
1558
+ }
1559
+ }],
1560
+ toDOM: (mark) => {
1561
+ return [
1562
+ "span",
1563
+ { style: `font-size: ${escapeCssProperty(mark.attrs.size)};` },
1564
+ 0
1565
+ ];
1566
+ },
1567
+ cursorFix: ($cursor, state) => {
1568
+ const storedMarks = state.storedMarks;
1569
+ if (!storedMarks) return null;
1570
+ const fontSizeMark = storedMarks.find((m) => m.type.name === "fontSize");
1571
+ if (fontSizeMark) return { "font-size": fontSizeMark.attrs.size };
1572
+ if (storedMarks.length === 0) {
1573
+ const defaultSize = this.defaultFontSizeForNode?.[$cursor.parent.type.name];
1574
+ if (defaultSize) return { "font-size": defaultSize };
1575
+ }
1576
+ return null;
1577
+ }
1578
+ } } })];
1579
+ }
1580
+ getPlugins() {
1581
+ return [this.contribution(keymap({
1582
+ "Mod-Shift-.": this.adjustFontSize(-1),
1583
+ "Mod-Shift-,": this.adjustFontSize(1)
1584
+ }))];
1585
+ }
1586
+ getToolbarItems(rte) {
1587
+ return [this.contribution({
1588
+ section: "font",
1589
+ render: (ctx) => createMenu(ctx, {
1590
+ label: () => rte.getLocale().richTextEditor.textSize,
1591
+ trigger: createButton(ctx, {
1592
+ label: () => rte.getLocale().richTextEditor.textSize,
1593
+ icon: "text-size-line"
1594
+ }),
1595
+ children: this.fontSizes.map((fs) => createMenuItem(ctx, {
1596
+ text: fs.label,
1597
+ checked: () => this.getFontSizeFromSelection(ctx.view.state) === fs.size,
1598
+ disabled: () => !this.setFontSize(fs.size)(ctx.view.state),
1599
+ onSelect: () => {
1600
+ const { state, dispatch } = ctx.view;
1601
+ this.setFontSize(fs.size)(state, dispatch);
1602
+ }
1603
+ }))
1604
+ })
1605
+ }, 2)];
1606
+ }
1607
+ getFontSizeFromSelection(state) {
1608
+ const { from, to, $from, empty } = state.selection;
1609
+ const { fontSize } = state.schema.marks;
1610
+ if (empty) {
1611
+ const defaultSize = this.defaultFontSizeForNode?.[$from.parent.type.name] ?? null;
1612
+ return fontSize.isInSet(state.storedMarks || $from.marks())?.attrs.size ?? defaultSize;
1613
+ }
1614
+ let size = null;
1615
+ const observeSize = (observedSize) => {
1616
+ if (size === null) size = observedSize ?? null;
1617
+ else if (observedSize !== size) size = mixedFontSize;
1618
+ };
1619
+ state.doc.nodesBetween(from, to, (node, _, parent) => {
1620
+ if (size === mixedFontSize) return false;
1621
+ if (!node.isLeaf) {
1622
+ if (node.type.allowsMarkType(fontSize) && node.childCount === 0) observeSize(this.defaultFontSizeForNode?.[node.type.name]);
1623
+ return true;
1624
+ }
1625
+ observeSize(fontSize.isInSet(node.marks)?.attrs.size ?? (parent && this.defaultFontSizeForNode?.[parent.type.name]));
1626
+ return true;
1627
+ });
1628
+ return size;
1629
+ }
1630
+ setFontSize(size) {
1631
+ return (state, dispatch) => {
1632
+ const { from, to, empty, $from } = state.selection;
1633
+ const { fontSize } = state.schema.marks;
1634
+ if (!toggleMark(fontSize, { size })(state)) return false;
1635
+ const tr = state.tr;
1636
+ if (empty) {
1637
+ const newStoredMarks = (state.storedMarks || []).filter((m) => m.type !== fontSize);
1638
+ if (size !== this.defaultFontSizeForNode?.[$from.parent.type.name]) newStoredMarks.push(fontSize.create({ size }));
1639
+ tr.setStoredMarks(newStoredMarks);
1640
+ } else {
1641
+ tr.addMark(from, to, fontSize.create({ size }));
1642
+ tr.doc.nodesBetween(from, to, (node, pos, parent) => {
1643
+ if (!node.isInline) return;
1644
+ const mark = fontSize.isInSet(node.marks);
1645
+ const defaultSize = this.defaultFontSizeForNode?.[parent.type.name];
1646
+ if (mark && mark.attrs.size === defaultSize) tr.step(new RemoveMarkStep(pos, pos + node.nodeSize, mark));
1647
+ });
1648
+ }
1649
+ dispatch?.(tr.scrollIntoView());
1650
+ return true;
1651
+ };
1652
+ }
1653
+ adjustFontSize(adjustment) {
1654
+ return (state, dispatch) => {
1655
+ const currentSize = this.getFontSizeFromSelection(state);
1656
+ if (currentSize === null || currentSize === mixedFontSize) return false;
1657
+ const nextIndex = this.fontSizes.findIndex((fs) => fs.size === currentSize) + adjustment;
1658
+ if (nextIndex < 0 || nextIndex >= this.fontSizes.length) return false;
1659
+ return this.setFontSize(this.fontSizes[nextIndex].size)(state, dispatch);
1660
+ };
1661
+ }
1662
+ };
1663
+ var RteFontSizePickerFeature = featureFacade(RteFontSizePickerFeatureImpl);
1664
+ //#endregion
1665
+ //#region src/lib/rich-text-editor/rte/features/internal/text-style.ts
1666
+ var RteTextStyleFeatureImpl = class extends RteFeatureImpl {
1667
+ constructor(config) {
1668
+ super();
1669
+ this.config = config;
1670
+ }
1671
+ getTextblockMarks() {
1672
+ if (this.config?.onBlocks) return this.config.onBlocks.map((block) => this.contribution({
1673
+ markName: this.markName,
1674
+ onNodeName: block.node
1675
+ }));
1676
+ return [this.contribution({ markName: this.markName })];
1677
+ }
1678
+ };
1679
+ //#endregion
1680
+ //#region src/lib/rich-text-editor/rte/features/bold.ts
1681
+ var RteBoldFeatureImpl = class extends RteTextStyleFeatureImpl {
1682
+ constructor(..._args) {
1683
+ super(..._args);
1684
+ this.name = "RteBoldFeature";
1685
+ this.markName = "bold";
1686
+ }
1687
+ getSchema() {
1688
+ return [this.contribution({ marks: { bold: marks.strong } })];
1689
+ }
1690
+ getPlugins(rte) {
1691
+ return [this.contribution(keymap({ "Mod-b": toggleMark(rte.schema.marks.bold) }))];
1692
+ }
1693
+ getToolbarItems(rte) {
1694
+ return [this.contribution({
1695
+ section: "text-style",
1696
+ render: (ctx) => createMarkToggle(ctx, {
1697
+ label: () => ctx.rte.getLocale().richTextEditor.bold,
1698
+ icon: "bold-line",
1699
+ markType: rte.schema.marks.bold
1700
+ })
1701
+ }, 1)];
1702
+ }
1703
+ };
1704
+ var RteBoldFeature = featureFacade(RteBoldFeatureImpl);
1705
+ //#endregion
1706
+ //#region src/lib/rich-text-editor/rte/features/italic.ts
1707
+ var RteItalicFeatureImpl = class extends RteTextStyleFeatureImpl {
1708
+ constructor(..._args) {
1709
+ super(..._args);
1710
+ this.name = "RteItalicFeature";
1711
+ this.markName = "italic";
1712
+ }
1713
+ getSchema() {
1714
+ return [this.contribution({ marks: { italic: marks.em } })];
1715
+ }
1716
+ getPlugins(rte) {
1717
+ return [this.contribution(keymap({ "Mod-i": toggleMark(rte.schema.marks.italic) }))];
1718
+ }
1719
+ getToolbarItems(rte) {
1720
+ return [this.contribution({
1721
+ section: "text-style",
1722
+ render: (ctx) => createMarkToggle(ctx, {
1723
+ label: () => ctx.rte.getLocale().richTextEditor.italic,
1724
+ icon: "italic-line",
1725
+ markType: rte.schema.marks.italic
1726
+ })
1727
+ }, 2)];
1728
+ }
1729
+ };
1730
+ var RteItalicFeature = featureFacade(RteItalicFeatureImpl);
1731
+ //#endregion
1732
+ //#region src/lib/rich-text-editor/rte/features/underline.ts
1733
+ var RteUnderlineFeatureImpl = class extends RteTextStyleFeatureImpl {
1734
+ constructor(..._args) {
1735
+ super(..._args);
1736
+ this.name = "RteUnderlineFeature";
1737
+ this.markName = "underline";
1738
+ }
1739
+ getSchema() {
1740
+ return [this.contribution({ marks: { underline: {
1741
+ parseDOM: [{ tag: "u" }],
1742
+ toDOM() {
1743
+ return ["u", 0];
1744
+ }
1745
+ } } })];
1746
+ }
1747
+ getPlugins(rte) {
1748
+ return [this.contribution(keymap({ "Mod-u": toggleMark(rte.schema.marks.underline) }))];
1749
+ }
1750
+ getToolbarItems(rte) {
1751
+ return [this.contribution({
1752
+ section: "text-style",
1753
+ render: (ctx) => createMarkToggle(ctx, {
1754
+ label: () => ctx.rte.getLocale().richTextEditor.underline,
1755
+ icon: "underline-line",
1756
+ markType: rte.schema.marks.underline
1757
+ })
1758
+ }, 3)];
1759
+ }
1760
+ };
1761
+ var RteUnderlineFeature = featureFacade(RteUnderlineFeatureImpl);
1762
+ //#endregion
1763
+ //#region src/lib/rich-text-editor/rte/features/strikethrough.ts
1764
+ var RteStrikethroughFeatureImpl = class extends RteTextStyleFeatureImpl {
1765
+ constructor(..._args) {
1766
+ super(..._args);
1767
+ this.name = "RteStrikethroughFeature";
1768
+ this.markName = "strikethrough";
1769
+ }
1770
+ getSchema() {
1771
+ return [this.contribution({ marks: { strikethrough: {
1772
+ parseDOM: [{ tag: "s" }, { tag: "del" }],
1773
+ toDOM() {
1774
+ return ["s", 0];
1775
+ }
1776
+ } } })];
1777
+ }
1778
+ getPlugins(rte) {
1779
+ return [this.contribution(keymap({
1780
+ "Alt-Shift-5": toggleMark(rte.schema.marks.strikethrough),
1781
+ "Cmd-Shift-X": toggleMark(rte.schema.marks.strikethrough)
1782
+ }))];
1783
+ }
1784
+ getToolbarItems(rte) {
1785
+ return [this.contribution({
1786
+ section: "text-style",
1787
+ render: (ctx) => createMarkToggle(ctx, {
1788
+ label: () => ctx.rte.getLocale().richTextEditor.strikethrough,
1789
+ icon: "strikethrough-line",
1790
+ markType: rte.schema.marks.strikethrough
1791
+ })
1792
+ }, 4)];
1793
+ }
1794
+ };
1795
+ var RteStrikethroughFeature = featureFacade(RteStrikethroughFeatureImpl);
1796
+ //#endregion
1797
+ //#region src/lib/rich-text-editor/rte/features/monospace.style.scss?inline
1798
+ var monospace_style_default = "tt{font:var(--vvd-typography-base-code);font-variant-ligatures:unset;font-feature-settings:unset;font-size:unset;font-weight:unset;line-height:unset}";
1799
+ //#endregion
1800
+ //#region src/lib/rich-text-editor/rte/features/monospace.ts
1801
+ var RteMonospaceFeatureImpl = class extends RteTextStyleFeatureImpl {
1802
+ constructor(..._args) {
1803
+ super(..._args);
1804
+ this.name = "RteMonospaceFeature";
1805
+ this.markName = "monospace";
1806
+ }
1807
+ getStyles() {
1808
+ return [this.contribution(monospace_style_default)];
1809
+ }
1810
+ getSchema() {
1811
+ return [this.contribution({ marks: { monospace: {
1812
+ parseDOM: [{ tag: "tt" }, { tag: "code" }],
1813
+ toDOM() {
1814
+ return ["tt", 0];
1815
+ }
1816
+ } } })];
1817
+ }
1818
+ getPlugins(rte) {
1819
+ return [this.contribution(keymap({ "Mod-M": toggleMark(rte.schema.marks.monospace) }))];
1820
+ }
1821
+ getToolbarItems(rte) {
1822
+ return [this.contribution({
1823
+ section: "text-style",
1824
+ render: (ctx) => createMarkToggle(ctx, {
1825
+ label: () => ctx.rte.getLocale().richTextEditor.monospace,
1826
+ icon: "monospace-line",
1827
+ markType: rte.schema.marks.monospace
1828
+ })
1829
+ }, 5)];
1830
+ }
1831
+ };
1832
+ var RteMonospaceFeature = featureFacade(RteMonospaceFeatureImpl);
1833
+ //#endregion
1834
+ //#region src/lib/rich-text-editor/rte/features/text-color-picker.ts
1835
+ function markApplies(doc, ranges, type) {
1836
+ for (let i = 0; i < ranges.length; i++) {
1837
+ const { $from, $to } = ranges[i];
1838
+ let can = $from.depth == 0 ? doc.type.allowsMarkType(type) : false;
1839
+ doc.nodesBetween($from.pos, $to.pos, (node) => {
1840
+ if (can) return false;
1841
+ can = node.inlineContent && node.type.allowsMarkType(type);
1842
+ return true;
1843
+ });
1844
+ if (can) return true;
1845
+ }
1846
+ return false;
1847
+ }
1848
+ var mixedColor = Symbol("mixedColor");
1849
+ var RteTextColorPickerFeatureImpl = class extends RteFeatureImpl {
1850
+ constructor(config) {
1851
+ super();
1852
+ this.config = config;
1853
+ this.name = "RteTextColorPicker";
1854
+ if (config?.onBlocks) {
1855
+ this.defaultColorForNode = {};
1856
+ for (const block of config.onBlocks) this.defaultColorForNode[block.node] = block.defaultColor ?? null;
1857
+ }
1858
+ }
1859
+ getTextblockMarks() {
1860
+ if (this.config?.onBlocks) return this.config.onBlocks.map((block) => this.contribution({
1861
+ markName: "textColor",
1862
+ onNodeName: block.node
1863
+ }));
1864
+ return [this.contribution({ markName: "textColor" })];
1865
+ }
1866
+ getSchema() {
1867
+ return [this.contribution({ marks: { textColor: {
1868
+ attrs: { color: { validate: "string" } },
1869
+ parseDOM: [{
1870
+ tag: "span[data-text-color]",
1871
+ getAttrs: (dom) => {
1872
+ return { color: dom.getAttribute("data-text-color") };
1873
+ }
1874
+ }, {
1875
+ style: "color",
1876
+ getAttrs: (value) => {
1877
+ return { color: value };
1878
+ }
1879
+ }],
1880
+ toDOM(node) {
1881
+ const { color } = node.attrs;
1882
+ return [
1883
+ "span",
1884
+ {
1885
+ style: `color: ${escapeCssProperty(color)};`,
1886
+ "data-text-color": color
1887
+ },
1888
+ 0
1889
+ ];
1890
+ },
1891
+ inclusive: true
1892
+ } } })];
1893
+ }
1894
+ getToolbarItems() {
1895
+ return [this.contribution({
1896
+ section: "text-style",
1897
+ render: (ctx) => {
1898
+ const tooltipButton = createButton(ctx, {
1899
+ label: () => ctx.rte.getLocale().richTextEditor.textColor,
1900
+ disabled: () => !this.setColor("any")(ctx.view.state),
1901
+ icon: "textcolor-line"
1902
+ });
1903
+ const button = tooltipButton.firstElementChild;
1904
+ return createDiv(ctx, { children: [tooltipButton, createSingleSlot(ctx, {
1905
+ name: "text-color-picker",
1906
+ assignedProps: {
1907
+ anchor: button,
1908
+ value: () => this.getSelectionColor(ctx.view.state) || ""
1909
+ },
1910
+ assignedEvents: { change: (e) => {
1911
+ const value = e.currentTarget.value;
1912
+ this.setColor(value)(ctx.view.state, ctx.view.dispatch);
1913
+ } }
1914
+ })] });
1915
+ }
1916
+ }, 6)];
1917
+ }
1918
+ getSelectionColor(state) {
1919
+ const { selection } = state;
1920
+ const { textColor } = state.schema.marks;
1921
+ const { from, to, $from, empty } = selection;
1922
+ if (empty) {
1923
+ const defaultColor = this.defaultColorForNode?.[$from.parent.type.name] ?? null;
1924
+ return textColor.isInSet(state.storedMarks || $from.marks())?.attrs.color ?? defaultColor;
1925
+ }
1926
+ let selectionColor = null;
1927
+ const observeColor = (observedColor) => {
1928
+ if (selectionColor === null) selectionColor = observedColor ?? null;
1929
+ else if (observedColor !== selectionColor) selectionColor = mixedColor;
1930
+ };
1931
+ state.doc.nodesBetween(from, to, (node, pos, parent) => {
1932
+ if (selectionColor === mixedColor) return false;
1933
+ if (!node.isLeaf) {
1934
+ if (node.type.allowsMarkType(textColor) && node.childCount === 0) observeColor(this.defaultColorForNode?.[node.type.name]);
1935
+ return true;
1936
+ }
1937
+ observeColor(textColor.isInSet(node.marks)?.attrs.color ?? (parent && this.defaultColorForNode?.[parent.type.name]));
1938
+ return true;
1939
+ });
1940
+ return selectionColor === mixedColor ? null : selectionColor;
1941
+ }
1942
+ setColor(color) {
1943
+ return (state, dispatch) => {
1944
+ const { textColor } = state.schema.marks;
1945
+ const { from, to, empty, $from } = state.selection;
1946
+ if (!markApplies(state.doc, state.selection.ranges, textColor)) return false;
1947
+ const tr = state.tr;
1948
+ if (empty) {
1949
+ const newStoredMarks = (state.storedMarks || []).filter((m) => m.type !== textColor);
1950
+ if (color !== this.defaultColorForNode?.[$from.parent.type.name]) newStoredMarks.push(textColor.create({ color }));
1951
+ tr.setStoredMarks(newStoredMarks);
1952
+ } else {
1953
+ tr.addMark(from, to, textColor.create({ color }));
1954
+ tr.doc.nodesBetween(from, to, (node, pos, parent) => {
1955
+ if (!node.isInline) return;
1956
+ const mark = textColor.isInSet(node.marks);
1957
+ const defaultColor = this.defaultColorForNode?.[parent.type.name];
1958
+ if (mark && mark.attrs.color === defaultColor) tr.step(new RemoveMarkStep(pos, pos + node.nodeSize, mark));
1959
+ });
1960
+ }
1961
+ dispatch?.(tr.scrollIntoView());
1962
+ return true;
1963
+ };
1964
+ }
1965
+ };
1966
+ var RteTextColorPickerFeature = featureFacade(RteTextColorPickerFeatureImpl);
1967
+ //#endregion
1968
+ //#region src/lib/rich-text-editor/rte/features/list.style.scss?inline
1969
+ var list_style_default = ".rich-text ul,.rich-text ol{padding-inline-start:1.5em}.rich-text li{list-style-position:inside}";
1970
+ //#endregion
1971
+ //#region src/lib/rich-text-editor/rte/features/list.ts
1972
+ var atStartOfNode = ($cursor) => $cursor.parentOffset === 0;
1973
+ var isEmpty = (node) => node.nodeSize === 2;
1974
+ var listDepth = ($li) => $li.depth - 1;
1975
+ var outOfListDepth = ($li) => $li.depth - 2;
1976
+ var getLi = ($li) => $li.parent;
1977
+ var getList = ($li) => $li.node(listDepth($li));
1978
+ var isNested = ($li) => $li.depth > 2;
1979
+ var isFirstChild = ($pos, depth) => $pos.index(depth) === 0;
1980
+ var isLastChild = ($pos, depth) => $pos.index(depth) === $pos.node(depth).childCount - 1;
1981
+ var prevSibling = ($pos, depth) => {
1982
+ const parent = $pos.node(depth);
1983
+ const index = $pos.index(depth);
1984
+ return parent.maybeChild(index - 1);
1985
+ };
1986
+ var nextSibling = ($pos, depth) => {
1987
+ const parent = $pos.node(depth);
1988
+ const index = $pos.index(depth);
1989
+ return parent.maybeChild(index + 1);
1990
+ };
1991
+ var asTextSelection = (selection) => {
1992
+ let { $from, $to } = selection;
1993
+ if (selection instanceof AllSelection) {
1994
+ const textSelection = TextSelection.between(selection.$from, selection.$to);
1995
+ $from = textSelection.$from;
1996
+ $to = textSelection.$to;
1997
+ }
1998
+ return {
1999
+ $from,
2000
+ $to
2001
+ };
2002
+ };
2003
+ var getSharedAncestor = ($from, $to) => $from.sameParent($to) ? $from.node(-1) : $from.node($from.sharedDepth($to.pos));
2004
+ var cursorInListItem = (state) => {
2005
+ const { $cursor } = state.selection;
2006
+ if ($cursor?.parent.type === state.schema.nodes.listItem) return $cursor;
2007
+ return null;
2008
+ };
2009
+ var allListItemsAreOfType = (state, $from, $to, type) => {
2010
+ let currentListType;
2011
+ let allLisAreOurType = true;
2012
+ state.doc.nodesBetween($from.pos, $to.pos, (node) => {
2013
+ if (node.type.isInGroup("list")) currentListType = node.type;
2014
+ if (node.type === state.schema.nodes.listItem && currentListType !== type) allLisAreOurType = false;
2015
+ });
2016
+ return allLisAreOurType;
2017
+ };
2018
+ var lift = (rte, $li, tr) => {
2019
+ if (isNested($li)) liftToOuterList($li, tr);
2020
+ else liftOutOfList(rte, $li, tr);
2021
+ };
2022
+ var liftToOuterList = ($li, tr) => {
2023
+ const liRange = new NodeRange($li.doc.resolve($li.before()), $li.doc.resolve($li.after()), $li.depth - 1);
2024
+ tr.lift(liRange, $li.depth - 2);
2025
+ };
2026
+ var liftOutOfList = (rte, $li, tr) => {
2027
+ const list = getList($li);
2028
+ const listIndex = $li.index(outOfListDepth($li));
2029
+ const defaultTextblock = defaultTextblockForMatch($li.node(outOfListDepth($li)).contentMatchAt(listIndex + 1));
2030
+ const atStart = isFirstChild($li, listDepth($li));
2031
+ const atEnd = isLastChild($li, listDepth($li));
2032
+ tr.step(new ReplaceAroundStep($li.before() - (atStart ? 1 : 0), $li.after() + (atEnd ? 1 : 0), $li.start(), $li.end(), new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))).append(Fragment.from(defaultTextblock.create(rte.textblockAttrs.extractFromNode(getLi($li))))).append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), (atStart ? 0 : 1) + 1));
2033
+ };
2034
+ var sink = (rte, listType, $node, tr) => {
2035
+ if ($node.parent.type === rte.schema.nodes.listItem) sinkLi(listType, $node, tr);
2036
+ else sinkNode(rte, listType, $node, tr);
2037
+ };
2038
+ var sinkLi = (listType, $li, tr) => {
2039
+ const canJoinWithPrev = prevSibling($li, listDepth($li))?.type === listType;
2040
+ const canJoinWithNext = nextSibling($li, listDepth($li))?.type === listType;
2041
+ const openStart = canJoinWithPrev ? 1 : 0;
2042
+ const openEnd = canJoinWithNext ? 1 : 0;
2043
+ tr.step(new ReplaceAroundStep($li.before() - (canJoinWithPrev ? 1 : 0), $li.after() + (canJoinWithNext ? 1 : 0), $li.before(), $li.after(), new Slice(Fragment.from(listType.create(null, [])), openStart, openEnd), 1 - openStart));
2044
+ };
2045
+ var sinkNode = (rte, listType, $node, tr) => {
2046
+ tr.step(new ReplaceAroundStep($node.before(), $node.after(), $node.start(), $node.end(), new Slice(Fragment.from(listType.create(null, [rte.schema.nodes.listItem.create(rte.textblockAttrs.extractFromNode($node.parent))])), 0, 0), 2));
2047
+ };
2048
+ var RteListFeatureImpl = class extends RteFeatureImpl {
2049
+ constructor(config) {
2050
+ super();
2051
+ this.config = config;
2052
+ this.name = "RteListFeature";
2053
+ if (!config.bulletList && !config.numberedList) throw new Error("RteListFeature requires at least one of bulletList or numberedList to be enabled");
2054
+ }
2055
+ getStyles() {
2056
+ return [this.contribution(list_style_default)];
2057
+ }
2058
+ getSchema(textblockAttrs) {
2059
+ return [this.contribution({ nodes: {
2060
+ listItem: {
2061
+ content: "inline*",
2062
+ attrs: textblockAttrs.attrs,
2063
+ defining: true,
2064
+ parseDOM: [{
2065
+ tag: "li",
2066
+ getAttrs: (dom) => textblockAttrs.fromDOM(dom)
2067
+ }],
2068
+ toDOM(node) {
2069
+ return [
2070
+ "li",
2071
+ ...textblockAttrs.getDOMAttrs(node),
2072
+ 0
2073
+ ];
2074
+ }
2075
+ },
2076
+ ...this.config.bulletList ? { bulletList: {
2077
+ group: "block list",
2078
+ content: "(listItem | list)+",
2079
+ parseDOM: [{ tag: "ul" }],
2080
+ toDOM() {
2081
+ return ["ul", 0];
2082
+ }
2083
+ } } : {},
2084
+ ...this.config.numberedList ? { numberedList: {
2085
+ group: "block list",
2086
+ content: "(listItem | list)+",
2087
+ parseDOM: [{ tag: "ol" }],
2088
+ toDOM() {
2089
+ return ["ol", 0];
2090
+ }
2091
+ } } : {}
2092
+ } })];
2093
+ }
2094
+ getPlugins(rte) {
2095
+ this.rte = rte;
2096
+ const tabCommand = (state, dispatch) => {
2097
+ const $liCursor = cursorInListItem(state);
2098
+ if ($liCursor && atStartOfNode($liCursor)) {
2099
+ const tr = state.tr;
2100
+ sinkLi(getList($liCursor).type, $liCursor, tr);
2101
+ dispatch?.(tr.scrollIntoView());
2102
+ return true;
2103
+ }
2104
+ return false;
2105
+ };
2106
+ const shiftTabCommand = (state, dispatch) => {
2107
+ const $liCursor = cursorInListItem(state);
2108
+ if ($liCursor && atStartOfNode($liCursor) && isNested($liCursor)) {
2109
+ const tr = state.tr;
2110
+ liftToOuterList($liCursor, tr);
2111
+ dispatch?.(tr.scrollIntoView());
2112
+ return true;
2113
+ }
2114
+ return false;
2115
+ };
2116
+ const enterCommand = (state, dispatch) => {
2117
+ const $liCursor = cursorInListItem(state);
2118
+ if ($liCursor && isEmpty(getLi($liCursor))) {
2119
+ const tr = state.tr;
2120
+ lift(this.rte, $liCursor, tr);
2121
+ dispatch?.(tr.scrollIntoView());
2122
+ return true;
2123
+ }
2124
+ return false;
2125
+ };
2126
+ const backspaceCommand = (state, dispatch) => {
2127
+ const $liCursor = cursorInListItem(state);
2128
+ if ($liCursor && atStartOfNode($liCursor)) {
2129
+ if (isFirstChild($liCursor, listDepth($liCursor)) && prevSibling($liCursor, outOfListDepth($liCursor))?.type === getList($liCursor).type) return false;
2130
+ const tr = state.tr;
2131
+ lift(this.rte, $liCursor, tr);
2132
+ dispatch?.(tr.scrollIntoView());
2133
+ return true;
2134
+ }
2135
+ return false;
2136
+ };
2137
+ return [this.contribution(keymap({
2138
+ Enter: enterCommand,
2139
+ Backspace: backspaceCommand,
2140
+ Tab: tabCommand,
2141
+ "Shift-Tab": shiftTabCommand,
2142
+ ...this.config.bulletList ? { "Mod-Shift-8": this.toggleList(rte.schema.nodes.bulletList) } : {},
2143
+ ...this.config.numberedList ? { "Mod-Shift-7": this.toggleList(rte.schema.nodes.numberedList) } : {}
2144
+ }), contributionPriority.high)];
2145
+ }
2146
+ getToolbarItems(rte) {
2147
+ const toolbarItems = [];
2148
+ if (this.config.bulletList) toolbarItems.push(this.contribution({
2149
+ section: "textblock",
2150
+ render: (ctx) => createButton(ctx, {
2151
+ label: () => ctx.rte.getLocale().richTextEditor.bulletList,
2152
+ icon: "bullet-list-2-line",
2153
+ active: () => this.isSelectionInList(rte.schema.nodes.bulletList, ctx.rte.state),
2154
+ onClick: () => {
2155
+ const { state, dispatch } = ctx.view;
2156
+ this.toggleList(rte.schema.nodes.bulletList)(state, dispatch);
2157
+ }
2158
+ })
2159
+ }, 1));
2160
+ if (this.config.numberedList) toolbarItems.push(this.contribution({
2161
+ section: "textblock",
2162
+ render: (ctx) => createButton(ctx, {
2163
+ label: () => ctx.rte.getLocale().richTextEditor.numberedList,
2164
+ icon: "list-numbered-line",
2165
+ active: () => this.isSelectionInList(rte.schema.nodes.numberedList, ctx.rte.state),
2166
+ onClick: () => {
2167
+ const { state, dispatch } = ctx.view;
2168
+ this.toggleList(rte.schema.nodes.numberedList)(state, dispatch);
2169
+ }
2170
+ })
2171
+ }, 2));
2172
+ return toolbarItems;
2173
+ }
2174
+ toggleList(type) {
2175
+ return autoJoin((state, dispatch) => {
2176
+ const { $from, $to } = asTextSelection(state.selection);
2177
+ if (getSharedAncestor($from, $to).type.isInGroup("list")) if (allListItemsAreOfType(state, $from, $to, type)) {
2178
+ const tr = state.tr;
2179
+ state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
2180
+ if (node.type === state.schema.nodes.listItem) {
2181
+ const $li = tr.doc.resolve(tr.mapping.map(pos + 1));
2182
+ lift(this.rte, $li, tr);
2183
+ }
2184
+ });
2185
+ dispatch?.(tr.scrollIntoView());
2186
+ return true;
2187
+ } else {
2188
+ const tr = state.tr;
2189
+ state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
2190
+ if (node.type.isInGroup("list") && node.type !== type) tr.setNodeMarkup(pos, type, node.attrs);
2191
+ });
2192
+ dispatch?.(tr.scrollIntoView());
2193
+ return true;
2194
+ }
2195
+ else {
2196
+ const tr = state.tr;
2197
+ state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
2198
+ if (!node.isTextblock) return;
2199
+ const $node = tr.doc.resolve(tr.mapping.map(pos + 1));
2200
+ sink(this.rte, type, $node, tr);
2201
+ });
2202
+ dispatch?.(tr.scrollIntoView());
2203
+ return true;
2204
+ }
2205
+ }, (before, after) => before.type === type && after.type === type);
2206
+ }
2207
+ isSelectionInList(type, state) {
2208
+ const { $from, $to } = asTextSelection(state.selection);
2209
+ if (getSharedAncestor($from, $to).type.isInGroup("list")) return allListItemsAreOfType(state, $from, $to, type);
2210
+ else return false;
2211
+ }
2212
+ };
2213
+ var RteListFeature = featureFacade(RteListFeatureImpl);
2214
+ //#endregion
2215
+ //#region src/lib/rich-text-editor/rte/features/alignment.ts
2216
+ var alignments = [
2217
+ {
2218
+ value: "left",
2219
+ icon: "align-left-line",
2220
+ label: "left"
2221
+ },
2222
+ {
2223
+ value: "center",
2224
+ icon: "align-center-line",
2225
+ label: "center"
2226
+ },
2227
+ {
2228
+ value: "right",
2229
+ icon: "align-right-line",
2230
+ label: "right"
2231
+ }
2232
+ ];
2233
+ var validTextAlign = (value) => alignments.find((a) => a.value === value)?.value ?? "left";
2234
+ var RteAlignmentFeatureImpl = class extends RteFeatureImpl {
2235
+ constructor(..._args) {
2236
+ super(..._args);
2237
+ this.name = "RteAlignmentFeature";
2238
+ }
2239
+ getTextblockAttrs() {
2240
+ return [this.contribution({
2241
+ name: "textAlign",
2242
+ default: "left",
2243
+ fromDOM(dom) {
2244
+ return validTextAlign(dom.style.textAlign);
2245
+ },
2246
+ toStyles(node) {
2247
+ return [`text-align: ${validTextAlign(node.attrs.textAlign)}`];
2248
+ }
2249
+ })];
2250
+ }
2251
+ getPlugins() {
2252
+ return [this.contribution(keymap({
2253
+ "Mod-L": this.setAlignment("left"),
2254
+ "Mod-E": this.setAlignment("center"),
2255
+ "Mod-R": this.setAlignment("right")
2256
+ }))];
2257
+ }
2258
+ getToolbarItems() {
2259
+ return [this.contribution({
2260
+ section: "textblock",
2261
+ render: (ctx) => createMenu(ctx, {
2262
+ label: () => ctx.rte.getLocale().richTextEditor.alignment,
2263
+ trigger: createButton(ctx, {
2264
+ label: () => ctx.rte.getLocale().richTextEditor.alignment,
2265
+ icon: () => {
2266
+ const currentAlign = this.getAlignmentFromSelection(ctx.view.state);
2267
+ return alignments.find((a) => a.value === currentAlign)?.icon ?? "align-left-line";
2268
+ }
2269
+ }),
2270
+ children: [createButtonGroup(ctx, {
2271
+ slot: "header",
2272
+ children: alignments.map((align, index) => createButton(ctx, {
2273
+ icon: align.icon,
2274
+ label: () => ctx.rte.getLocale().richTextEditor.alignments[align.label],
2275
+ noTooltip: true,
2276
+ variant: "toolbar-menu",
2277
+ autofocus: () => {
2278
+ const currentAlign = this.getAlignmentFromSelection(ctx.view.state);
2279
+ if ((currentAlign === "mixed" || currentAlign === null) && index === 0) return true;
2280
+ return align.value === currentAlign;
2281
+ },
2282
+ active: () => this.getAlignmentFromSelection(ctx.view.state) === align.value,
2283
+ disabled: () => this.getAlignmentFromSelection(ctx.view.state) === null,
2284
+ onClick: () => {
2285
+ const { state, dispatch } = ctx.view;
2286
+ this.setAlignment(align.value)(state, dispatch);
2287
+ }
2288
+ }))
2289
+ })]
2290
+ })
2291
+ }, 3)];
2292
+ }
2293
+ getAlignmentFromSelection(state) {
2294
+ const { selection } = state;
2295
+ const { from, to } = selection;
2296
+ let align = null;
2297
+ state.doc.nodesBetween(from, to, (node) => {
2298
+ if (align === "mixed") return;
2299
+ if (node.type.isTextblock) {
2300
+ if (!align) align = node.attrs.textAlign;
2301
+ else if (align !== node.attrs.textAlign) align = "mixed";
2302
+ }
2303
+ });
2304
+ return align;
2305
+ }
2306
+ setAlignment(align) {
2307
+ return (state, dispatch) => {
2308
+ const { tr, selection } = state;
2309
+ const { from, to } = selection;
2310
+ state.doc.nodesBetween(from, to, (node, pos) => {
2311
+ if (node.type.isTextblock) tr.setNodeMarkup(pos, node.type, {
2312
+ ...node.attrs,
2313
+ textAlign: align
2314
+ });
2315
+ });
2316
+ dispatch?.(tr.scrollIntoView());
2317
+ return true;
2318
+ };
2319
+ }
2320
+ };
2321
+ var RteAlignmentFeature = featureFacade(RteAlignmentFeatureImpl);
2322
+ //#endregion
2323
+ //#region src/lib/rich-text-editor/rte/features/link.style.scss?inline
2324
+ var link_style_default = ".link-popover{flex-direction:column;gap:8px;inline-size:450px;padding:16px;display:flex}.link-popover-header{justify-content:space-between;align-items:center;display:flex}.link-popover-label{color:var(--vvd-color-neutral-600);font:var(--vvd-typography-base-condensed)}.link-popover-content{flex-direction:column;gap:16px;display:flex}.link,.rich-text a[href],.link:visited,.rich-text a[href]:visited{color:var(--vvd-color-cta-600)}.link:hover,.rich-text a[href]:hover{color:var(--vvd-color-cta-500)}.link:active,.rich-text a[href]:active{color:var(--vvd-color-cta-400)}.link-action-bar{justify-content:end;gap:8px;display:flex}.link-toolbar-menu{flex-direction:column;gap:16px;inline-size:368px;padding:8px;display:flex}";
2325
+ //#endregion
2326
+ //#region src/lib/rich-text-editor/rte/features/link.ts
2327
+ var linkPattern = "(?:https?://|www\\.)[^\\s<]+";
2328
+ function convertToLink(state, matchedText, start, end) {
2329
+ if (state.doc.rangeHasMark(start, start + 1, state.schema.marks.link)) return null;
2330
+ const link = matchedText.replace(/[.,;:!?) ]+$/, "");
2331
+ const href = link.startsWith("www.") ? `https://${link}` : link;
2332
+ const linkMark = state.schema.marks.link.create({ href });
2333
+ const linkEnd = start + link.length;
2334
+ const trailingChars = matchedText.slice(link.length);
2335
+ const tr = state.tr.addMark(start, linkEnd, linkMark);
2336
+ if (trailingChars) tr.replaceWith(linkEnd, end, state.schema.text(trailingChars));
2337
+ return tr;
2338
+ }
2339
+ var RteLinkFeatureImpl = class extends RteFeatureImpl {
2340
+ constructor(..._args) {
2341
+ super(..._args);
2342
+ this.name = "RteLinkFeature";
2343
+ this.removeLink = (state, dispatch) => {
2344
+ const tr = state.tr;
2345
+ const existingLink = this.getCurrentLink(state);
2346
+ tr.removeMark(existingLink.start, existingLink.end, state.schema.marks.link);
2347
+ dispatch?.(tr.scrollIntoView());
2348
+ return true;
2349
+ };
2350
+ }
2351
+ getStyles() {
2352
+ return [this.contribution(link_style_default)];
2353
+ }
2354
+ getSchema() {
2355
+ return [this.contribution({ marks: { link: {
2356
+ attrs: { href: { validate: "string" } },
2357
+ inclusive: false,
2358
+ parseDOM: [{
2359
+ tag: "a[href]",
2360
+ getAttrs(dom) {
2361
+ return { href: dom.getAttribute("href") };
2362
+ }
2363
+ }],
2364
+ toDOM(node) {
2365
+ const { href } = node.attrs;
2366
+ return [
2367
+ "a",
2368
+ { href: sanitizeLinkHref(href) },
2369
+ 0
2370
+ ];
2371
+ }
2372
+ } } }, contributionPriority.high)];
2373
+ }
2374
+ getTextblockMarks() {
2375
+ return [this.contribution({ markName: "link" })];
2376
+ }
2377
+ getInputRules() {
2378
+ const linkRegex = new RegExp(`${linkPattern}$`);
2379
+ return [this.contribution({
2380
+ rule: new InputRule(new RegExp(`${linkPattern} $`), (state, match, start, end) => convertToLink(state, match[0], start, end)),
2381
+ enterHandler: {
2382
+ regex: linkRegex,
2383
+ handler: (state, match, start, end) => convertToLink(state, match[0], start, end)
2384
+ }
2385
+ })];
2386
+ }
2387
+ getPlugins(rte) {
2388
+ const insertLinkCommand = () => {
2389
+ this.toolbarMenu.open = true;
2390
+ return true;
2391
+ };
2392
+ let popup;
2393
+ return [this.contribution(new Plugin({
2394
+ props: { decorations: (state) => {
2395
+ const link = this.getCurrentLink(state);
2396
+ if (link) {
2397
+ const deco = Decoration.inline(link.start, link.end, { id: "current-link" });
2398
+ return DecorationSet.create(state.doc, [deco]);
2399
+ }
2400
+ return null;
2401
+ } },
2402
+ view: (view) => {
2403
+ const ctx = new UiCtx(view, rte, { popupPlacement: "bottom" });
2404
+ popup = rte.createComponent(Popover);
2405
+ popup.anchorId = "current-link";
2406
+ const content = createDiv(ctx, {
2407
+ className: "link-popover",
2408
+ children: [createDiv(ctx, {
2409
+ className: "link-popover-header",
2410
+ children: [createDiv(ctx, {
2411
+ className: "link-popover-label",
2412
+ children: [createText(ctx, { text: () => this.getCurrentLink(ctx.view.state)?.text || "" })]
2413
+ }), createButton(ctx, {
2414
+ icon: "close-line",
2415
+ label: () => ctx.rte.getLocale().richTextEditor.close,
2416
+ noTooltip: true,
2417
+ onClick: () => {
2418
+ popup.dismiss();
2419
+ }
2420
+ })]
2421
+ }), createDiv(ctx, {
2422
+ className: "link-popover-content",
2423
+ children: [createAnchor(ctx, {
2424
+ className: "link",
2425
+ href: () => this.getCurrentLink(ctx.view.state)?.href || "",
2426
+ target: "_blank",
2427
+ rel: "noopener",
2428
+ children: [createText(ctx, { text: () => this.getCurrentLink(ctx.view.state)?.href || "" })]
2429
+ }), createDiv(ctx, {
2430
+ className: "link-action-bar",
2431
+ children: [createButton(ctx, {
2432
+ icon: "delete-line",
2433
+ label: () => ctx.rte.getLocale().richTextEditor.delete,
2434
+ connotation: "alert",
2435
+ variant: "popover",
2436
+ noTooltip: true,
2437
+ onClick: () => {
2438
+ const { state, dispatch } = ctx.view;
2439
+ this.removeLink(state, dispatch);
2440
+ }
2441
+ }), createButton(ctx, {
2442
+ icon: "edit-line",
2443
+ label: () => ctx.rte.getLocale().richTextEditor.edit,
2444
+ variant: "popover",
2445
+ noTooltip: true,
2446
+ onClick: () => {
2447
+ this.toolbarMenu.open = true;
2448
+ popup.requestOpenState(false);
2449
+ return true;
2450
+ }
2451
+ })]
2452
+ })]
2453
+ })]
2454
+ });
2455
+ popup.appendChild(content);
2456
+ view.dom.getRootNode().querySelector(".popovers").appendChild(popup);
2457
+ return {
2458
+ update: (view) => {
2459
+ const state = view.state;
2460
+ ctx.updateBindings();
2461
+ const link = this.getCurrentLink(state);
2462
+ popup.requestOpenState(Boolean(link));
2463
+ },
2464
+ destroy: () => {
2465
+ popup.remove();
2466
+ }
2467
+ };
2468
+ }
2469
+ })), this.contribution(keymap({
2470
+ Escape: (state) => {
2471
+ if (this.getCurrentLink(state)) {
2472
+ popup?.dismiss();
2473
+ return true;
2474
+ }
2475
+ return false;
2476
+ },
2477
+ "Mod-k": insertLinkCommand
2478
+ }))];
2479
+ }
2480
+ getToolbarItems(rte) {
2481
+ const getSelectionText = (state) => {
2482
+ const { from, to } = state.selection;
2483
+ if (from === to) return "";
2484
+ return state.doc.textBetween(from, to, " ");
2485
+ };
2486
+ const isValidUrl = (url) => {
2487
+ try {
2488
+ new URL(url);
2489
+ return true;
2490
+ } catch {
2491
+ return false;
2492
+ }
2493
+ };
2494
+ return [this.contribution({
2495
+ section: "insert",
2496
+ render: (ctx) => {
2497
+ const textField = createTextField(ctx, {
2498
+ label: () => ctx.rte.getLocale().richTextEditor.linkText,
2499
+ placeholder: () => ctx.rte.getLocale().richTextEditor.linkTextPlaceholder,
2500
+ slot: "header",
2501
+ autofocus: true,
2502
+ value: () => this.getCurrentLink(ctx.view.state)?.text || getSelectionText(ctx.view.state) || "",
2503
+ onInput: () => {
2504
+ updateValidation();
2505
+ }
2506
+ });
2507
+ const urlField = createTextField(ctx, {
2508
+ label: () => ctx.rte.getLocale().richTextEditor.linkUrl,
2509
+ type: "url",
2510
+ placeholder: () => ctx.rte.getLocale().richTextEditor.linkUrlPlaceholder,
2511
+ helperText: () => ctx.rte.getLocale().richTextEditor.linkUrlHelperText,
2512
+ slot: "header",
2513
+ value: () => this.getCurrentLink(ctx.view.state)?.href || "",
2514
+ onInput: () => {
2515
+ updateValidation();
2516
+ }
2517
+ });
2518
+ const applyButton = createButton(ctx, {
2519
+ label: () => ctx.rte.getLocale().richTextEditor.apply,
2520
+ variant: "popover-primary",
2521
+ disabled: () => {
2522
+ const link = this.getCurrentLink(ctx.view.state);
2523
+ return !(link && link.text.length && isValidUrl(link.href));
2524
+ },
2525
+ onClick: () => {
2526
+ const { state, dispatch } = ctx.view;
2527
+ this.insertLink(rte, urlField.value, textField.value)(state, dispatch);
2528
+ }
2529
+ });
2530
+ const updateValidation = () => {
2531
+ applyButton.querySelector("[data-vvd-component=\"button\"]").disabled = !(textField.value.length && isValidUrl(urlField.value));
2532
+ };
2533
+ const menu = createMenu(ctx, {
2534
+ label: () => ctx.rte.getLocale().richTextEditor.hyperlink,
2535
+ trigger: createButton(ctx, {
2536
+ label: () => ctx.rte.getLocale().richTextEditor.hyperlink,
2537
+ icon: "link-line"
2538
+ }),
2539
+ children: [createDiv(ctx, {
2540
+ className: "link-toolbar-menu",
2541
+ slot: "header",
2542
+ children: [
2543
+ textField,
2544
+ urlField,
2545
+ createDiv(ctx, {
2546
+ className: "link-action-bar",
2547
+ slot: "header",
2548
+ children: [createButton(ctx, {
2549
+ label: () => ctx.rte.getLocale().richTextEditor.cancel,
2550
+ variant: "popover",
2551
+ onClick: () => {
2552
+ this.toolbarMenu.open = false;
2553
+ }
2554
+ }), applyButton]
2555
+ })
2556
+ ]
2557
+ })]
2558
+ });
2559
+ this.toolbarMenu = menu.lastElementChild;
2560
+ return menu;
2561
+ }
2562
+ }, 1)];
2563
+ }
2564
+ getCurrentLink(state) {
2565
+ const selection = state.selection;
2566
+ if (!(selection instanceof TextSelection)) return null;
2567
+ const linkMark = state.schema.marks.link;
2568
+ const { $from, $to } = selection;
2569
+ const selectionStartMarks = state.selection.empty ? $from.marks() : $from.nodeAfter?.marks ?? [];
2570
+ const targetHref = linkMark.isInSet(selectionStartMarks)?.attrs.href;
2571
+ if (!targetHref) return null;
2572
+ const isTargetLink = (node) => linkMark.isInSet(node.marks)?.attrs.href === targetHref;
2573
+ let currentRun = null;
2574
+ const runs = [];
2575
+ state.doc.nodesBetween($from.start(), $to.end(), (node, pos) => {
2576
+ if (!node.isText) return true;
2577
+ const nodeEnd = pos + node.nodeSize;
2578
+ if (isTargetLink(node)) if (!currentRun) {
2579
+ currentRun = {
2580
+ start: pos,
2581
+ end: nodeEnd
2582
+ };
2583
+ runs.push(currentRun);
2584
+ } else currentRun.end = nodeEnd;
2585
+ else currentRun = null;
2586
+ return false;
2587
+ });
2588
+ const selectionRun = runs.find((run) => run.start <= selection.from && run.end >= selection.to);
2589
+ if (!selectionRun) return null;
2590
+ return {
2591
+ text: state.doc.textBetween(selectionRun.start, selectionRun.end, " "),
2592
+ href: targetHref,
2593
+ start: selectionRun.start,
2594
+ end: selectionRun.end
2595
+ };
2596
+ }
2597
+ insertLink(rte, href, text) {
2598
+ return (state, dispatch) => {
2599
+ let { from, to } = state.selection;
2600
+ const tr = state.tr;
2601
+ const existingLink = this.getCurrentLink(state);
2602
+ if (existingLink) {
2603
+ from = existingLink.start;
2604
+ to = existingLink.end;
2605
+ }
2606
+ tr.insertText(text, from, to);
2607
+ tr.addMark(from, from + text.length, rte.schema.marks.link.create({ href }));
2608
+ dispatch?.(tr.scrollIntoView());
2609
+ return true;
2610
+ };
2611
+ }
2612
+ };
2613
+ var RteLinkFeature = featureFacade(RteLinkFeatureImpl);
2614
+ //#endregion
2615
+ //#region src/lib/rich-text-editor/rte/features/inline-image.style.scss?inline
2616
+ var inline_image_style_default = ".inline-image-wrapper{vertical-align:text-bottom;display:inline-block}.inline-image{block-size:auto;display:block}.inline-image-popover{align-items:center;gap:4px;padding:8px;display:flex}.inline-image-placeholder{color:var(--vvd-color-canvas-text);font:var(--vvd-typography-base);font-feature-settings:normal;font-variant-ligatures:normal;overflow-wrap:normal;pointer-events:none;white-space:normal}";
2617
+ //#endregion
2618
+ //#region src/lib/rich-text-editor/rte/features/inline-image.ts
2619
+ var isGenerator$1 = (value) => value !== null && Boolean(value["next"]);
2620
+ var uniqueId = 1;
2621
+ var generateUniqueId = () => uniqueId++;
2622
+ var InlineImageView = class {
2623
+ constructor(node, view, getPos, config) {
2624
+ this.view = view;
2625
+ this.getPos = getPos;
2626
+ this.config = config;
2627
+ this.content = null;
2628
+ this.dom = document.createElement("div");
2629
+ this.dom.className = "inline-image-wrapper";
2630
+ this.imageUrl = node.attrs.imageUrl;
2631
+ this.img = document.createElement("img");
2632
+ this.initializeImg(node);
2633
+ const resolveResult = this.config.resolveUrl ? this.config.resolveUrl(this.imageUrl) : this.imageUrl;
2634
+ const initialResolvedUrl = isGenerator$1(resolveResult) ? null : resolveResult;
2635
+ this.handleResolvedUrl(initialResolvedUrl);
2636
+ if (isGenerator$1(resolveResult)) this.handleResolvedUrlGenerator(resolveResult);
2637
+ }
2638
+ setContent(content, { onDestroy, allowPopover } = {}) {
2639
+ this.content?.remove();
2640
+ this.onContentDestroy?.();
2641
+ this.content = content;
2642
+ if (content) {
2643
+ this.onContentDestroy = onDestroy;
2644
+ this.dom.appendChild(content);
2645
+ }
2646
+ Popover.setBlockPopover(this.dom, !allowPopover);
2647
+ }
2648
+ async handleResolvedUrlGenerator(generator) {
2649
+ const iterator = generator[Symbol.asyncIterator]();
2650
+ let result;
2651
+ do {
2652
+ result = await iterator.next();
2653
+ this.handleResolvedUrl(result.value);
2654
+ } while (!result.done);
2655
+ }
2656
+ handleResolvedUrl(result) {
2657
+ if (typeof result === "string") this.renderImg(result);
2658
+ else if (result?.type === "placeholder") {
2659
+ const slotName = `inline-image-placeholder-${generateUniqueId()}`;
2660
+ const slot = document.createElement("slot");
2661
+ slot.className = "inline-image-placeholder";
2662
+ slot.name = slotName;
2663
+ const onDestroy = result.create?.(slotName);
2664
+ const host = this.view.dom.getRootNode().host;
2665
+ dispatchSlottableRequest(host, "inline-image-placeholder", slotName, { url: this.imageUrl });
2666
+ this.setContent(slot, { onDestroy: () => {
2667
+ dispatchSlottableRequest(host, "inline-image-placeholder", slotName, removeSymbol);
2668
+ onDestroy?.();
2669
+ } });
2670
+ } else this.setContent(null);
2671
+ }
2672
+ initializeImg(node) {
2673
+ this.img.className = "inline-image";
2674
+ this.update(node);
2675
+ this.img.addEventListener("load", () => {
2676
+ const pos = this.getPos?.();
2677
+ if (pos) {
2678
+ const { state, dispatch } = this.view;
2679
+ const currentNode = state.doc.nodeAt(pos);
2680
+ if (!currentNode || currentNode.attrs.naturalWidth === this.img.naturalWidth && currentNode.attrs.naturalHeight === this.img.naturalHeight) return;
2681
+ const tr = state.tr;
2682
+ tr.setNodeAttribute(pos, "naturalWidth", this.img.naturalWidth);
2683
+ tr.setNodeAttribute(pos, "naturalHeight", this.img.naturalHeight);
2684
+ tr.setMeta("addToHistory", false);
2685
+ dispatch(tr);
2686
+ }
2687
+ });
2688
+ }
2689
+ renderImg(src) {
2690
+ this.img.src = sanitizeImageSrc(src);
2691
+ this.setContent(this.img, { allowPopover: true });
2692
+ }
2693
+ update(node) {
2694
+ this.img.alt = node.attrs.alt;
2695
+ this.img.width = node.attrs.naturalWidth;
2696
+ this.img.height = node.attrs.naturalHeight;
2697
+ this.img.style.maxWidth = node.attrs.size;
2698
+ return true;
2699
+ }
2700
+ destroy() {
2701
+ this.setContent(null);
2702
+ }
2703
+ };
2704
+ var RteInlineImageFeatureImpl = class extends RteFeatureImpl {
2705
+ constructor(config = {}) {
2706
+ super();
2707
+ this.config = config;
2708
+ this.name = "RteInlineImageFeature";
2709
+ }
2710
+ getStyles() {
2711
+ return [this.contribution(inline_image_style_default)];
2712
+ }
2713
+ getSchema() {
2714
+ return [this.contribution({ nodes: { inlineImage: {
2715
+ inline: true,
2716
+ group: "inline",
2717
+ selectable: true,
2718
+ atom: true,
2719
+ attrs: {
2720
+ imageUrl: { validate: "string" },
2721
+ alt: {
2722
+ validate: "string",
2723
+ default: ""
2724
+ },
2725
+ size: {
2726
+ validate: "string|null",
2727
+ default: null
2728
+ },
2729
+ naturalWidth: {
2730
+ validate: "number|null",
2731
+ default: null
2732
+ },
2733
+ naturalHeight: {
2734
+ validate: "number|null",
2735
+ default: null
2736
+ }
2737
+ },
2738
+ parseDOM: [{
2739
+ tag: "img[src],img[data-src]",
2740
+ getAttrs: (dom) => {
2741
+ const parseDimension = (dim) => {
2742
+ const value = parseInt(dim ?? "", 10);
2743
+ return isNaN(value) ? null : value;
2744
+ };
2745
+ const srcAttr = dom.getAttribute("data-src") ?? dom.getAttribute("src");
2746
+ const imageUrl = this.config.parseUrlFromHtml ? this.config.parseUrlFromHtml(srcAttr) : srcAttr;
2747
+ if (imageUrl === null) return false;
2748
+ return {
2749
+ imageUrl,
2750
+ alt: dom.getAttribute("alt") || "",
2751
+ size: dom.style.maxWidth || null,
2752
+ naturalWidth: parseDimension(dom.getAttribute("width")),
2753
+ naturalHeight: parseDimension(dom.getAttribute("height"))
2754
+ };
2755
+ }
2756
+ }],
2757
+ toDOM: (node) => {
2758
+ const { imageUrl, alt, size, naturalWidth, naturalHeight } = node.attrs;
2759
+ const resolvedUrl = this.config.serializeUrlToHtml ? this.config.serializeUrlToHtml(imageUrl) : imageUrl;
2760
+ if (resolvedUrl === null) return document.createTextNode("");
2761
+ const attrs = {
2762
+ src: sanitizeImageSrc(resolvedUrl),
2763
+ "data-src": resolvedUrl,
2764
+ alt
2765
+ };
2766
+ if (size) attrs.style = `max-width: ${escapeCssProperty(size)}; height: auto;`;
2767
+ if (naturalWidth) attrs.width = naturalWidth;
2768
+ if (naturalHeight) attrs.height = naturalHeight;
2769
+ return ["img", attrs];
2770
+ }
2771
+ } } })];
2772
+ }
2773
+ getPlugins(rte) {
2774
+ let popover;
2775
+ return [this.contribution(new Plugin({
2776
+ props: { nodeViews: { inlineImage: (node, view, getPos) => new InlineImageView(node, view, getPos, this.config) } },
2777
+ view: (view) => {
2778
+ const ctx = new UiCtx(view, rte, { popupPlacement: "bottom" });
2779
+ popover = rte.createComponent(Popover);
2780
+ popover.offset = 4;
2781
+ const content = createDiv(ctx, {
2782
+ className: "inline-image-popover",
2783
+ children: [
2784
+ createButton(ctx, {
2785
+ label: () => ctx.rte.getLocale().richTextEditor.imageSizes.small,
2786
+ variant: "popover",
2787
+ active: () => this.getSelectedImageSize(ctx.view.state) === "small",
2788
+ onClick: () => {
2789
+ this.setSelectedImageSize("small")(ctx.view.state, ctx.view.dispatch);
2790
+ }
2791
+ }),
2792
+ createDivider(ctx),
2793
+ createButton(ctx, {
2794
+ label: () => ctx.rte.getLocale().richTextEditor.imageSizes.fit,
2795
+ variant: "popover",
2796
+ active: () => this.getSelectedImageSize(ctx.view.state) === "fit",
2797
+ onClick: () => {
2798
+ this.setSelectedImageSize("fit")(ctx.view.state, ctx.view.dispatch);
2799
+ }
2800
+ }),
2801
+ createDivider(ctx),
2802
+ createButton(ctx, {
2803
+ label: () => ctx.rte.getLocale().richTextEditor.imageSizes.original,
2804
+ variant: "popover",
2805
+ active: () => this.getSelectedImageSize(ctx.view.state) === "original",
2806
+ onClick: () => {
2807
+ this.setSelectedImageSize("original")(ctx.view.state, ctx.view.dispatch);
2808
+ }
2809
+ })
2810
+ ]
2811
+ });
2812
+ popover.appendChild(content);
2813
+ view.dom.getRootNode().querySelector(".popovers").appendChild(popover);
2814
+ return {
2815
+ update: (view) => {
2816
+ ctx.updateBindings();
2817
+ const selectedImage = this.getSelectedInlineImage(view.state);
2818
+ if (selectedImage) {
2819
+ popover.anchorEl = view.nodeDOM(selectedImage.pos);
2820
+ popover.requestOpenState(true);
2821
+ } else {
2822
+ popover.anchorEl = void 0;
2823
+ popover.requestOpenState(false);
2824
+ }
2825
+ },
2826
+ destroy: () => {
2827
+ popover.remove();
2828
+ }
2829
+ };
2830
+ }
2831
+ })), this.contribution(keymap({ Escape: (state) => {
2832
+ if (this.getSelectedInlineImage(state)) {
2833
+ popover?.dismiss();
2834
+ return true;
2835
+ }
2836
+ return false;
2837
+ } }))];
2838
+ }
2839
+ calculateSmallWidth(naturalWidth) {
2840
+ return Math.min(300, naturalWidth / 2) + "px";
2841
+ }
2842
+ getSelectedInlineImage(state) {
2843
+ const sel = state.selection;
2844
+ if (sel instanceof NodeSelection && sel.node.type === state.schema.nodes.inlineImage) return {
2845
+ pos: sel.from,
2846
+ node: sel.node
2847
+ };
2848
+ return null;
2849
+ }
2850
+ setSelectedImageSize(size) {
2851
+ return (state, dispatch) => {
2852
+ const selectedImage = this.getSelectedInlineImage(state);
2853
+ if (!selectedImage) return false;
2854
+ const { naturalWidth } = selectedImage.node.attrs;
2855
+ if (size === "small" && naturalWidth === null) return false;
2856
+ const tr = state.tr;
2857
+ tr.setNodeAttribute(selectedImage.pos, "size", size === "small" ? this.calculateSmallWidth(naturalWidth) : size === "fit" ? "100%" : null);
2858
+ dispatch?.(tr.scrollIntoView());
2859
+ return true;
2860
+ };
2861
+ }
2862
+ getSelectedImageSize(state) {
2863
+ const selectedImage = this.getSelectedInlineImage(state);
2864
+ if (!selectedImage) return null;
2865
+ const { size, naturalWidth } = selectedImage.node.attrs;
2866
+ if (naturalWidth !== null && size === this.calculateSmallWidth(naturalWidth)) return "small";
2867
+ if (size === "100%") return "fit";
2868
+ if (size === null) return "original";
2869
+ return null;
2870
+ }
2871
+ };
2872
+ var RteInlineImageFeature = featureFacade(RteInlineImageFeatureImpl);
2873
+ //#endregion
2874
+ //#region src/shared/utils/promise.ts
2875
+ var resolvePromise = async (promise) => {
2876
+ try {
2877
+ return {
2878
+ type: "ok",
2879
+ result: await promise
2880
+ };
2881
+ } catch (e) {
2882
+ return {
2883
+ type: "error",
2884
+ error: e
2885
+ };
2886
+ }
2887
+ };
2888
+ //#endregion
2889
+ //#region src/lib/rich-text-editor/rte/features/file-handler.ts
2890
+ var RteFileHandlerFeatureImpl = class extends RteFeatureImpl {
2891
+ constructor(config) {
2892
+ super();
2893
+ this.config = config;
2894
+ this.name = "RteFileHandlerFeature";
2895
+ }
2896
+ getPlugins(rte) {
2897
+ const insertPointPlaceholderPlugin = new Plugin({
2898
+ state: {
2899
+ init() {
2900
+ return DecorationSet.empty;
2901
+ },
2902
+ apply(tr, set) {
2903
+ set = set.map(tr.mapping, tr.doc);
2904
+ const action = tr.getMeta(insertPointPlaceholderPlugin);
2905
+ if (action && action.add) {
2906
+ const placeholder = document.createElement("placeholder");
2907
+ const deco = Decoration.widget(action.add.pos, placeholder, {
2908
+ id: action.add.id,
2909
+ relaxedSide: true
2910
+ });
2911
+ set = set.add(tr.doc, [deco]);
2912
+ } else if (action && action.remove) set = set.remove(set.find(void 0, void 0, (spec) => spec.id == action.remove.id));
2913
+ return set;
2914
+ }
2915
+ },
2916
+ props: { decorations(state) {
2917
+ return this.getState(state);
2918
+ } }
2919
+ });
2920
+ const createInsertPointPlaceholder = (tr, pos) => {
2921
+ const id = generateRandomId();
2922
+ tr.setMeta(insertPointPlaceholderPlugin, { add: {
2923
+ id,
2924
+ pos
2925
+ } });
2926
+ return {
2927
+ getPos: (state) => {
2928
+ const found = insertPointPlaceholderPlugin.getState(state).find(void 0, void 0, (spec) => spec.id == id);
2929
+ return found.length ? found[0].from : null;
2930
+ },
2931
+ remove: (tr) => {
2932
+ tr.setMeta(insertPointPlaceholderPlugin, { remove: { id } });
2933
+ }
2934
+ };
2935
+ };
2936
+ const insertFragment = (tr, fragment, insertPoint) => {
2937
+ if (insertPoint.type === "selection") {
2938
+ const parsed = Slice.fromJSON(rte.schema, { content: fragment });
2939
+ tr.replaceSelection(parsed);
2940
+ } else {
2941
+ const parsed = Fragment.fromJSON(rte.schema, fragment);
2942
+ tr.insert(insertPoint.pos, parsed);
2943
+ }
2944
+ };
2945
+ const handleFiles = (files, insertPoint) => {
2946
+ const result = this.config.handleFiles(files);
2947
+ if (result === null) return;
2948
+ else if (result instanceof Promise) handleAsyncResult(result, insertPoint);
2949
+ else handleSyncResult(result, insertPoint);
2950
+ };
2951
+ const handleSyncResult = (result, insertPoint) => {
2952
+ const tr = rte.state.tr;
2953
+ insertFragment(tr, result, insertPoint);
2954
+ rte.dispatchTransaction(tr);
2955
+ };
2956
+ const handleAsyncResult = async (promise, insertPoint) => {
2957
+ const tr = rte.state.tr;
2958
+ if (insertPoint.type === "selection" && !tr.selection.empty) tr.deleteSelection();
2959
+ const placeholder = createInsertPointPlaceholder(tr, insertPoint.type === "selection" ? tr.selection.from : insertPoint.pos);
2960
+ rte.dispatchTransaction(tr);
2961
+ const resolved = await resolvePromise(promise);
2962
+ const updatedPos = placeholder.getPos(rte.state);
2963
+ const insertTr = rte.state.tr;
2964
+ placeholder.remove(insertTr);
2965
+ if (updatedPos !== null && resolved.type === "ok") insertFragment(insertTr, resolved.result, {
2966
+ type: "pos",
2967
+ pos: updatedPos
2968
+ });
2969
+ rte.dispatchTransaction(insertTr);
2970
+ if (resolved.type === "error") console.error("Error in handleFiles handler:", resolved.error);
2971
+ };
2972
+ return [this.contribution(insertPointPlaceholderPlugin), this.contribution(new Plugin({ props: {
2973
+ handlePaste: (view, event) => {
2974
+ const files = Array.from(event.clipboardData.files);
2975
+ if (!files.length) return false;
2976
+ handleFiles(files, { type: "selection" });
2977
+ return true;
2978
+ },
2979
+ handleDrop: (view, event, slice, moved) => {
2980
+ const files = Array.from(event.dataTransfer.files);
2981
+ if (!files.length) return false;
2982
+ let target = view.posAtCoords({
2983
+ left: event.clientX,
2984
+ top: event.clientY
2985
+ }).pos;
2986
+ if (view.dragging && view.dragging.slice) {
2987
+ const point = dropPoint(view.state.doc, target, view.dragging.slice);
2988
+ if (point != null) target = point;
2989
+ }
2990
+ handleFiles(files, {
2991
+ type: "pos",
2992
+ pos: target
2993
+ });
2994
+ return true;
2995
+ }
2996
+ } }))];
2997
+ }
2998
+ };
2999
+ var RteFileHandlerFeature = featureFacade(RteFileHandlerFeatureImpl);
3000
+ //#endregion
3001
+ //#region src/lib/rich-text-editor/rte/features/drop-handler.ts
3002
+ var RteDropHandlerFeatureImpl = class extends RteFeatureImpl {
3003
+ constructor(config) {
3004
+ super();
3005
+ this.config = config;
3006
+ this.name = "RteDebugFeature";
3007
+ }
3008
+ getPlugins(rte) {
3009
+ const dragOverResults = /* @__PURE__ */ new WeakMap();
3010
+ let lastResult = false;
3011
+ const onDragOver = (event) => {
3012
+ if (dragOverResults.get(event) !== void 0) return;
3013
+ lastResult = this.config.onViewportDragOver?.(event) ?? false;
3014
+ };
3015
+ const onDrop = (event) => {
3016
+ this.config.onViewportDrop?.(event);
3017
+ this.config.onViewportDragFinish?.();
3018
+ };
3019
+ const onDragEnd = () => {
3020
+ this.config.onViewportDragFinish?.();
3021
+ };
3022
+ let isEntering = false;
3023
+ const onDragEnter = () => {
3024
+ isEntering = true;
3025
+ window.setTimeout(() => isEntering = false, 0);
3026
+ };
3027
+ const onDragLeave = () => {
3028
+ if (isEntering) return;
3029
+ this.config.onViewportDragFinish?.();
3030
+ };
3031
+ return [this.contribution(new Plugin({ view: (view) => {
3032
+ const viewport = view.root.host.editorViewportElement;
3033
+ viewport.addEventListener("dragover", onDragOver);
3034
+ viewport.addEventListener("drop", onDrop);
3035
+ viewport.addEventListener("dragend", onDragEnd);
3036
+ viewport.addEventListener("dragenter", onDragEnter);
3037
+ viewport.addEventListener("dragleave", onDragLeave);
3038
+ return { destroy() {
3039
+ viewport.removeEventListener("dragover", onDragOver);
3040
+ viewport.removeEventListener("drop", onDrop);
3041
+ viewport.removeEventListener("dragend", onDragEnd);
3042
+ viewport.removeEventListener("dragenter", onDragEnter);
3043
+ viewport.removeEventListener("dragleave", onDragLeave);
3044
+ } };
3045
+ } })), this.contribution(new Plugin({ props: { handleDOMEvents: {
3046
+ dragover: (view, event) => {
3047
+ const result = this.config.onViewportDragOver?.(event) ?? false;
3048
+ dragOverResults.set(event, result);
3049
+ lastResult = result;
3050
+ if (result) {
3051
+ event.stopImmediatePropagation();
3052
+ event.preventDefault();
3053
+ return true;
3054
+ }
3055
+ return false;
3056
+ },
3057
+ drop: (view, event) => {
3058
+ return lastResult;
3059
+ }
3060
+ } } }), contributionPriority.high)];
3061
+ }
3062
+ };
3063
+ var RteDropHandlerFeature = featureFacade(RteDropHandlerFeatureImpl);
3064
+ //#endregion
3065
+ //#region src/lib/rich-text-editor/rte/features/toolbar-button.ts
3066
+ var RteToolbarButtonFeatureImpl = class extends RteFeatureImpl {
3067
+ constructor(featureId, options) {
3068
+ super();
3069
+ this.featureId = featureId;
3070
+ this.options = options;
3071
+ this.name = `RteToolbarButtonFeature[${featureId}]`;
3072
+ }
3073
+ getToolbarItems() {
3074
+ return [this.contribution({
3075
+ section: "insert",
3076
+ render: (ctx) => createButton(ctx, {
3077
+ label: this.options.label,
3078
+ icon: this.options.icon,
3079
+ onClick: () => {
3080
+ this.executeAction(ctx);
3081
+ }
3082
+ })
3083
+ }, 2 + (this.options.order ?? 0) / Number.MAX_SAFE_INTEGER)];
3084
+ }
3085
+ executeAction(ctx) {
3086
+ const { action } = this.options;
3087
+ switch (action.type) {
3088
+ case "insert-text": {
3089
+ const { state, dispatch } = ctx.view;
3090
+ const { from, to } = state.selection;
3091
+ dispatch(state.tr.insertText(action.text, from, to));
3092
+ break;
3093
+ }
3094
+ }
3095
+ }
3096
+ };
3097
+ var RteToolbarButtonFeature = featureFacade(RteToolbarButtonFeatureImpl);
3098
+ //#endregion
3099
+ //#region src/lib/rich-text-editor/rte/features/atom.ts
3100
+ var isGenerator = (value) => value !== null && typeof value === "object" && "next" in value;
3101
+ var AtomView = class {
3102
+ constructor(node, config, atomName) {
3103
+ this.dom = document.createElement("span");
3104
+ this.dom.className = "atom-wrapper";
3105
+ this.dom.setAttribute("part", `node--${atomName}`);
3106
+ const result = config.resolveValue ? config.resolveValue(node.attrs.value) : node.attrs.value;
3107
+ if (isGenerator(result)) {
3108
+ this.dom.textContent = "";
3109
+ this.handleResolvedGenerator(result);
3110
+ } else this.dom.textContent = result ?? "";
3111
+ }
3112
+ async handleResolvedGenerator(generator) {
3113
+ const iterator = generator[Symbol.asyncIterator]();
3114
+ let result;
3115
+ do {
3116
+ result = await iterator.next();
3117
+ this.dom.textContent = result.value ?? "";
3118
+ } while (!result.done);
3119
+ }
3120
+ };
3121
+ var RteAtomFeatureImpl = class extends RteFeatureImpl {
3122
+ constructor(atomName, config = {}) {
3123
+ super();
3124
+ this.atomName = atomName;
3125
+ this.config = config;
3126
+ this.name = `RteAtomFeature[${atomName}]`;
3127
+ }
3128
+ getSchema() {
3129
+ const atomSpec = {
3130
+ inline: true,
3131
+ group: "inline",
3132
+ selectable: true,
3133
+ atom: true,
3134
+ attrs: { value: { validate: "string" } },
3135
+ parseDOM: [{
3136
+ tag: `span[data-atom-type="${this.atomName}"][data-value]`,
3137
+ getAttrs: (dom) => ({ value: dom.getAttribute("data-value") })
3138
+ }],
3139
+ toDOM: (node) => {
3140
+ const serializedValue = this.config.serializeValueToHtml ? this.config.serializeValueToHtml(node.attrs.value) : node.attrs.value;
3141
+ if (serializedValue === null) return document.createDocumentFragment();
3142
+ return [
3143
+ "span",
3144
+ { part: `node--${this.atomName}` },
3145
+ serializedValue
3146
+ ];
3147
+ },
3148
+ serializeToDOM: (node) => {
3149
+ const serializedValue = this.config.serializeValueToHtml ? this.config.serializeValueToHtml(node.attrs.value) : node.attrs.value;
3150
+ if (serializedValue === null) return document.createTextNode("");
3151
+ return [
3152
+ "span",
3153
+ {
3154
+ "data-atom-type": this.atomName,
3155
+ "data-value": node.attrs.value
3156
+ },
3157
+ serializedValue
3158
+ ];
3159
+ }
3160
+ };
3161
+ return [this.contribution({ nodes: { [this.atomName]: atomSpec } })];
3162
+ }
3163
+ getPlugins(_rte) {
3164
+ return [this.contribution(new Plugin({ props: { nodeViews: { [this.atomName]: (node) => new AtomView(node, this.config, this.atomName) } } }))];
3165
+ }
3166
+ };
3167
+ var RteAtomFeature = featureFacade(RteAtomFeatureImpl);
3168
+ //#endregion
3169
+ //#region src/lib/rich-text-editor/rte/features/input-rule.ts
3170
+ var RteInputRuleFeatureImpl = class extends RteFeatureImpl {
3171
+ constructor(featureId, options) {
3172
+ super();
3173
+ this.featureId = featureId;
3174
+ this.options = options;
3175
+ this.name = `RteInputRuleFeature[${featureId}]`;
3176
+ }
3177
+ getInputRules(rte) {
3178
+ const basePattern = `(?:${this.options.pattern.source})`;
3179
+ const handler = (state, match, start, end) => {
3180
+ const fragment = this.options.handler(match);
3181
+ if (!fragment) return null;
3182
+ return state.tr.replaceWith(start, end, Fragment.fromJSON(rte.schema, fragment));
3183
+ };
3184
+ const spec = { rule: new InputRule(this.options.matchAfterWhitespace ? new RegExp(`${basePattern} $`) : new RegExp(`${basePattern}$`), handler) };
3185
+ if (this.options.matchAfterWhitespace) spec.enterHandler = {
3186
+ regex: new RegExp(`${basePattern}$`),
3187
+ handler
3188
+ };
3189
+ return [this.contribution(spec)];
3190
+ }
3191
+ };
3192
+ var RteInputRuleFeature = featureFacade(RteInputRuleFeatureImpl);
3193
+ //#endregion
3194
+ //#region src/lib/rich-text-editor/rte/features/keyboard-shortcuts.ts
3195
+ function toCommand(handler, rteInstance) {
3196
+ if (handler.length === 0) return (_state, _dispatch) => handler();
3197
+ return (_state, _dispatch) => handler(rteInstance);
3198
+ }
3199
+ var RteKeyboardShortcutsFeatureImpl = class extends RteFeatureImpl {
3200
+ constructor(featureId, options) {
3201
+ super();
3202
+ this.featureId = featureId;
3203
+ this.options = options;
3204
+ this.name = `RteKeyboardShortcutsFeature[${featureId}]`;
3205
+ }
3206
+ getPlugins(rte) {
3207
+ const bindings = {};
3208
+ for (const [key, handler] of Object.entries(this.options.shortcuts)) bindings[key] = toCommand(handler, rte.facade);
3209
+ return [this.contribution(keymap(bindings), contributionPriority.high)];
3210
+ }
3211
+ };
3212
+ var RteKeyboardShortcutsFeature = featureFacade(RteKeyboardShortcutsFeatureImpl);
3213
+ //#endregion
3214
+ //#region src/lib/rich-text-editor/rte/features/suggest.style.scss?inline
3215
+ var suggest_style_default = ".suggest-popover{flex-direction:column;gap:2px;max-block-size:408px;min-inline-size:128px;max-inline-size:248px;padding:4px;display:flex}.suggest-loading-widget{vertical-align:middle;white-space:normal;align-items:center;margin-inline-start:2px;display:inline-flex}.suggest-empty-message{color:var(--vvd-color-neutral-300);font:var(--vvd-typography-base);text-align:center;justify-content:center;align-items:center;min-block-size:40px;display:flex}.suggest-item--visible-focus{box-shadow:0 0 0 4px color-mix(in srgb, var(--focus-stroke-color,var(--vvd-color-cta-500)), transparent 85%), inset 0 0 0 3px var(--focus-stroke-gap-color,currentColor);outline:1px solid var(--focus-stroke-color,var(--vvd-color-cta-500));outline-offset:calc(-1px - var(--focus-inset,0px));--focus-stroke-gap-color:transparent}";
3216
+ //#endregion
3217
+ //#region src/lib/rich-text-editor/rte/features/suggest.ts
3218
+ var isPopoverOpen = (state) => Boolean(state?.suggestions && !state.dismissed);
3219
+ var popoverShowsResults = (state) => isPopoverOpen(state) && state.suggestions.items.length > 0;
3220
+ function findMatch(state, regex) {
3221
+ const { $cursor } = state.selection;
3222
+ if (!$cursor) return null;
3223
+ const textBefore = textBeforeCursor($cursor);
3224
+ const match = regex.exec(textBefore);
3225
+ if (!match) return null;
3226
+ const blockStart = $cursor.pos - $cursor.parentOffset;
3227
+ return {
3228
+ text: match[0],
3229
+ groups: [...match],
3230
+ start: blockStart + match.index,
3231
+ end: blockStart + match.index + match[0].length
3232
+ };
3233
+ }
3234
+ var replaceMatch = (view, match, fragment) => {
3235
+ const { state } = view;
3236
+ view.dispatch(closeHistory(state.tr));
3237
+ const tr = view.state.tr;
3238
+ tr.replaceWith(match.start, match.end, Fragment.fromJSON(view.state.schema, fragment));
3239
+ const newPos = tr.mapping.map(match.end);
3240
+ tr.setSelection(TextSelection.create(tr.doc, newPos));
3241
+ view.dispatch(tr.scrollIntoView());
3242
+ };
3243
+ var RteSuggestFeatureImpl = class extends RteFeatureImpl {
3244
+ selectSuggestion(view, suggestState, suggestion) {
3245
+ const fragment = this.options.select(suggestion);
3246
+ replaceMatch(view, suggestState.match, fragment);
3247
+ view.focus();
3248
+ }
3249
+ async startLoadingSuggestions(match, dispatch) {
3250
+ const gen = ++this.loadGeneration;
3251
+ const suggestions = await this.options.load(match);
3252
+ if (gen !== this.loadGeneration) return;
3253
+ dispatch({
3254
+ type: "load",
3255
+ generation: gen,
3256
+ suggestions
3257
+ });
3258
+ }
3259
+ constructor(featureId, options) {
3260
+ super();
3261
+ this.featureId = featureId;
3262
+ this.options = options;
3263
+ this.pluginKey = new PluginKey("suggest");
3264
+ this.loadGeneration = 0;
3265
+ this.name = `RteSuggestFeature[${featureId}]`;
3266
+ }
3267
+ getStyles() {
3268
+ return [this.contribution(suggest_style_default)];
3269
+ }
3270
+ getPlugins(rte) {
3271
+ const createSuggestActionTr = (action) => rte.state.tr.setMeta(this.pluginKey, action);
3272
+ const dispatchSuggestAction = (action) => rte.dispatchTransaction(createSuggestActionTr(action));
3273
+ const suggestPlugin = new Plugin({
3274
+ key: this.pluginKey,
3275
+ state: {
3276
+ init: () => null,
3277
+ apply: (tr, prevState, _prevEditor, newEditor) => {
3278
+ const match = findMatch(newEditor, this.options.pattern);
3279
+ if (!match) return null;
3280
+ if (!prevState && !tr.docChanged) return null;
3281
+ if (prevState?.dismissed) return prevState;
3282
+ const loadingDecoration = (isLoading) => {
3283
+ if (!isLoading) return DecorationSet.empty;
3284
+ return Boolean(prevState?.loadingDecoration.find().length ?? 0) ? prevState.loadingDecoration.map(tr.mapping, tr.doc) : DecorationSet.create(tr.doc, [Decoration.widget(match.end, () => {
3285
+ const wrapper = document.createElement("span");
3286
+ wrapper.className = "suggest-loading-widget";
3287
+ const spinner = rte.createComponent(ProgressRing);
3288
+ spinner.size = -6;
3289
+ wrapper.appendChild(spinner);
3290
+ return wrapper;
3291
+ }, {
3292
+ ignoreSelection: true,
3293
+ side: 1
3294
+ })]);
3295
+ };
3296
+ const action = tr.getMeta(this.pluginKey);
3297
+ if (prevState && action) switch (action.type) {
3298
+ case "load": return {
3299
+ ...prevState,
3300
+ suggestions: {
3301
+ generation: action.generation,
3302
+ items: action.suggestions,
3303
+ selectedIndex: 0,
3304
+ visibleFocus: false
3305
+ },
3306
+ loadingDecoration: loadingDecoration(false)
3307
+ };
3308
+ case "navigate": {
3309
+ /* v8 ignore next 3 -- defensive: navigate is only dispatched after results are loaded @preserve */
3310
+ if (!prevState.suggestions?.items.length) return prevState;
3311
+ if (!prevState.suggestions.visibleFocus) return {
3312
+ ...prevState,
3313
+ suggestions: {
3314
+ ...prevState.suggestions,
3315
+ visibleFocus: true
3316
+ }
3317
+ };
3318
+ const newIndex = Math.max(0, Math.min(prevState.suggestions.items.length - 1, prevState.suggestions.selectedIndex + (action.action === "up" ? -1 : 1)));
3319
+ return {
3320
+ ...prevState,
3321
+ suggestions: {
3322
+ ...prevState.suggestions,
3323
+ selectedIndex: newIndex
3324
+ }
3325
+ };
3326
+ }
3327
+ case "dismiss": return {
3328
+ ...prevState,
3329
+ dismissed: true,
3330
+ loadingDecoration: DecorationSet.empty
3331
+ };
3332
+ }
3333
+ if (!prevState) {
3334
+ this.startLoadingSuggestions(match.groups, dispatchSuggestAction);
3335
+ return {
3336
+ match,
3337
+ loadingDecoration: loadingDecoration(true)
3338
+ };
3339
+ }
3340
+ const matchChanged = match.groups[0] !== prevState.match.groups[0];
3341
+ if (matchChanged) this.startLoadingSuggestions(match.groups, dispatchSuggestAction);
3342
+ return {
3343
+ ...prevState,
3344
+ match,
3345
+ suggestions: prevState.suggestions ? {
3346
+ ...prevState.suggestions,
3347
+ visibleFocus: false
3348
+ } : void 0,
3349
+ loadingDecoration: loadingDecoration(matchChanged)
3350
+ };
3351
+ }
3352
+ },
3353
+ props: { decorations: (state) => {
3354
+ const suggestState = this.pluginKey.getState(state);
3355
+ if (!suggestState) return null;
3356
+ return suggestState.loadingDecoration.add(state.doc, [Decoration.inline(suggestState.match.start, suggestState.match.end, { id: `suggest-anchor-${this.featureId}` })]);
3357
+ } },
3358
+ view: (view) => {
3359
+ const ctx = new UiCtx(view, rte, { popupPlacement: "bottom" });
3360
+ const popover = rte.createComponent(Popover);
3361
+ popover.anchorId = `suggest-anchor-${this.featureId}`;
3362
+ popover.kind = "autocomplete";
3363
+ popover.offset = 4;
3364
+ const content = createDiv(ctx, {
3365
+ className: "suggest-popover",
3366
+ children: []
3367
+ });
3368
+ popover.appendChild(content);
3369
+ view.dom.getRootNode().querySelector(".popovers").appendChild(popover);
3370
+ const emptySlotName = `${this.featureId}-suggestions-empty`;
3371
+ const host = view.dom.getRootNode().host;
3372
+ let emptySlotShowing = false;
3373
+ const updateEmptySlotShowing = (showing) => {
3374
+ if (!emptySlotShowing && showing) dispatchSlottableRequest(host, "suggestions-empty-state", emptySlotName, { id: this.featureId });
3375
+ if (emptySlotShowing && !showing) dispatchSlottableRequest(host, "suggestions-empty-state", emptySlotName, removeSymbol);
3376
+ emptySlotShowing = showing;
3377
+ };
3378
+ const updatePopoverContent = (suggestState) => {
3379
+ content.innerHTML = "";
3380
+ const suggestions = suggestState.suggestions;
3381
+ const showEmptyState = suggestions.items.length === 0;
3382
+ updateEmptySlotShowing(showEmptyState);
3383
+ if (showEmptyState) {
3384
+ const emptySlot = document.createElement("slot");
3385
+ emptySlot.name = emptySlotName;
3386
+ emptySlot.textContent = rte.getLocale().richTextEditor.suggestNoResults;
3387
+ content.appendChild(createDiv(ctx, {
3388
+ className: "suggest-empty-message",
3389
+ children: [emptySlot]
3390
+ }));
3391
+ return;
3392
+ }
3393
+ for (const [index, suggestion] of suggestions.items.entries()) {
3394
+ const item = rte.createComponent(ListboxOption);
3395
+ item.text = suggestion.text;
3396
+ item.textSecondary = suggestion.textSecondary;
3397
+ if (index === suggestions.selectedIndex) {
3398
+ item._highlighted = true;
3399
+ item.dataset.highlighted = "true";
3400
+ if (suggestions.visibleFocus) item.classList.add("suggest-item--visible-focus");
3401
+ queueMicrotask(() => {
3402
+ item.scrollIntoView({ block: "nearest" });
3403
+ });
3404
+ }
3405
+ item.addEventListener("click", (e) => {
3406
+ e.preventDefault();
3407
+ e.stopPropagation();
3408
+ this.selectSuggestion(view, suggestState, suggestion);
3409
+ });
3410
+ content.appendChild(item);
3411
+ }
3412
+ };
3413
+ return {
3414
+ update: (view) => {
3415
+ ctx.updateBindings();
3416
+ const suggestState = this.pluginKey.getState(view.state);
3417
+ const showPopover = isPopoverOpen(suggestState);
3418
+ popover.requestOpenState(showPopover);
3419
+ if (showPopover) updatePopoverContent(suggestState);
3420
+ else updateEmptySlotShowing(false);
3421
+ },
3422
+ destroy: () => {
3423
+ updateEmptySlotShowing(false);
3424
+ popover.remove();
3425
+ }
3426
+ };
3427
+ }
3428
+ });
3429
+ return [this.contribution(suggestPlugin), this.contribution(keymap({
3430
+ ArrowUp: (state, dispatch) => {
3431
+ if (!popoverShowsResults(this.pluginKey.getState(state))) return false;
3432
+ dispatch?.(createSuggestActionTr({
3433
+ type: "navigate",
3434
+ action: "up"
3435
+ }));
3436
+ return true;
3437
+ },
3438
+ ArrowDown: (state, dispatch) => {
3439
+ if (!popoverShowsResults(this.pluginKey.getState(state))) return false;
3440
+ dispatch?.(createSuggestActionTr({
3441
+ type: "navigate",
3442
+ action: "down"
3443
+ }));
3444
+ return true;
3445
+ },
3446
+ Enter: (state, _dispatch, view) => {
3447
+ const suggestState = this.pluginKey.getState(state);
3448
+ if (!popoverShowsResults(suggestState)) return false;
3449
+ const suggestion = suggestState.suggestions.items[suggestState.suggestions.selectedIndex];
3450
+ /* v8 ignore next 3 -- defensive: view is always passed by keymap @preserve */
3451
+ if (view) this.selectSuggestion(view, suggestState, suggestion);
3452
+ return true;
3453
+ },
3454
+ Escape: (state, dispatch) => {
3455
+ if (!isPopoverOpen(this.pluginKey.getState(state))) return false;
3456
+ dispatch?.(createSuggestActionTr({ type: "dismiss" }));
3457
+ return true;
3458
+ }
3459
+ }), contributionPriority.high)];
3460
+ }
3461
+ };
3462
+ var RteSuggestFeature = featureFacade(RteSuggestFeatureImpl);
3463
+ //#endregion
3464
+ //#region src/lib/rich-text-editor/rte/features/character-count.ts
3465
+ var countCharacters = (doc) => doc.textBetween(0, doc.content.size, void 0, " ").length;
3466
+ var RteCharacterCountFeatureImpl = class extends RteFeatureImpl {
3467
+ constructor(config) {
3468
+ super();
3469
+ this.config = config;
3470
+ this.name = "RteCharacterCountFeature";
3471
+ }
3472
+ getPlugins() {
3473
+ const limit = this.config?.limit;
3474
+ if (limit === void 0) return [];
3475
+ return [this.contribution(new Plugin({ filterTransaction: (transaction, state) => {
3476
+ if (!transaction.docChanged) return true;
3477
+ const oldSize = countCharacters(state.doc);
3478
+ const newSize = countCharacters(transaction.doc);
3479
+ if (newSize <= limit) return true;
3480
+ if (oldSize > limit) return newSize <= oldSize;
3481
+ if (!transaction.getMeta("paste")) return false;
3482
+ const pos = transaction.selection.$head.pos;
3483
+ const from = pos - (newSize - limit);
3484
+ const to = pos;
3485
+ transaction.deleteRange(from, to);
3486
+ return countCharacters(transaction.doc) <= limit;
3487
+ } }))];
3488
+ }
3489
+ getPublicInterface(rte) {
3490
+ const limit = this.config?.limit;
3491
+ return {
3492
+ get characters() {
3493
+ return countCharacters(rte.state.doc);
3494
+ },
3495
+ get limit() {
3496
+ return limit;
3497
+ }
3498
+ };
3499
+ }
3500
+ };
3501
+ var RteCharacterCountFeature = featureFacade(RteCharacterCountFeatureImpl);
116
3502
  //#endregion
117
- //#region src/lib/rich-text-view/definition.ts
118
- var richTextViewDefinition = defineVividComponent("rich-text-view", RichTextView, RichTextViewTemplate, [], {
119
- styles: rich_text_view_default,
3503
+ //#region src/lib/rich-text-editor/definition.ts
3504
+ var richTextEditorDefinition = defineVividComponent("rich-text-editor", RichTextEditor, RichTextEditorTemplate, [
3505
+ dividerDefinition,
3506
+ selectDefinition,
3507
+ listboxOptionDefinition,
3508
+ buttonDefinition,
3509
+ tooltipDefinition,
3510
+ menuDefinition,
3511
+ menuItemDefinition,
3512
+ textFieldDefinition,
3513
+ popoverDefinition,
3514
+ progressRingDefinition
3515
+ ], {
3516
+ styles: rich_text_editor_default,
120
3517
  shadowOptions: { delegatesFocus: true }
121
3518
  });
122
3519
  /**
123
- * Registers the rich-text-view element with the design system.
3520
+ * Registers the rich-text-editor element with the design system.
124
3521
  *
125
3522
  * @param prefix - the prefix to use for the component name
126
3523
  */
127
- var registerRichTextView = createRegisterFunction(richTextViewDefinition);
3524
+ var registerRichTextEditor = createRegisterFunction(richTextEditorDefinition);
128
3525
  //#endregion
129
- export { richTextViewDefinition as n, RichTextView as r, registerRichTextView as t };
3526
+ export { RichTextEditor as A, RtePlaceholderFeature as C, RteConfig as D, RteBase as E, RteHtmlSerializer as O, RteHardBreakFeature as S, RteTextBlockPickerFeature as T, RteStrikethroughFeature as _, RteKeyboardShortcutsFeature as a, RteBoldFeature as b, RteToolbarButtonFeature as c, RteInlineImageFeature as d, RteLinkFeature as f, RteMonospaceFeature as g, RteTextColorPickerFeature as h, RteSuggestFeature as i, RteHtmlParser as k, RteDropHandlerFeature as l, RteListFeature as m, richTextEditorDefinition as n, RteInputRuleFeature as o, RteAlignmentFeature as p, RteCharacterCountFeature as r, RteAtomFeature as s, registerRichTextEditor as t, RteFileHandlerFeature as u, RteUnderlineFeature as v, RteToolbarFeature as w, RteFontSizePickerFeature as x, RteItalicFeature as y };