@vonage/vivid 5.17.0 → 5.19.0

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