@vonage/vivid 5.24.0 → 5.25.0

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