@vonage/vivid 5.23.1 → 5.25.0

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