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