@vonage/vivid 5.19.0 → 5.20.1

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