@vonage/vivid 5.19.0 → 5.20.1

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