@refraction-ui/react 0.19.1 → 0.20.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 (342) hide show
  1. package/dist/chunk-533MCMSU.js +2355 -0
  2. package/dist/chunk-533MCMSU.js.map +7 -0
  3. package/dist/chunk-AMK4VCBG.js +250 -0
  4. package/dist/chunk-AMK4VCBG.js.map +7 -0
  5. package/dist/chunk-BOLFYVI6.js +90 -0
  6. package/dist/chunk-BOLFYVI6.js.map +7 -0
  7. package/dist/chunk-F7B64KT3.js +187 -0
  8. package/dist/chunk-F7B64KT3.js.map +7 -0
  9. package/dist/chunk-FD37DFCC.js +77 -0
  10. package/dist/chunk-FD37DFCC.js.map +7 -0
  11. package/dist/chunk-H54FLNAF.js +132 -0
  12. package/dist/chunk-H54FLNAF.js.map +7 -0
  13. package/dist/chunk-INP46354.js +664 -0
  14. package/dist/chunk-INP46354.js.map +7 -0
  15. package/dist/chunk-ONACRMG4.js +116 -0
  16. package/dist/chunk-ONACRMG4.js.map +7 -0
  17. package/dist/chunk-SDZ3LROZ.js +7 -0
  18. package/dist/chunk-SDZ3LROZ.js.map +7 -0
  19. package/dist/chunk-TOZBR4GL.js +154 -0
  20. package/dist/chunk-TOZBR4GL.js.map +7 -0
  21. package/dist/chunk-UNEM2TRI.js +225 -0
  22. package/dist/chunk-UNEM2TRI.js.map +7 -0
  23. package/dist/chunk-VK3EQ34F.js +92 -0
  24. package/dist/chunk-VK3EQ34F.js.map +7 -0
  25. package/dist/chunk-WK2IIUFO.js +316 -0
  26. package/dist/chunk-WK2IIUFO.js.map +7 -0
  27. package/dist/chunk-WSPJTQAV.js +59 -0
  28. package/dist/chunk-WSPJTQAV.js.map +7 -0
  29. package/dist/chunk-XWP763SH.js +3 -2
  30. package/dist/chunk-XWP763SH.js.map +7 -1
  31. package/dist/chunk-Y2FNNAIL.js +80 -0
  32. package/dist/chunk-Y2FNNAIL.js.map +1 -0
  33. package/dist/{chunk-4A4BW3GR.js → chunk-ZF3OHCGV.js} +28 -5
  34. package/dist/chunk-ZF3OHCGV.js.map +7 -0
  35. package/dist/form.cjs +5 -11
  36. package/dist/form.cjs.map +1 -1
  37. package/dist/form.js +6 -12
  38. package/dist/form.js.map +1 -1
  39. package/dist/index.cjs +2879 -33936
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +1 -0
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.js +126 -28780
  44. package/dist/internal/react-app-shell/index.d.cts +2 -22
  45. package/dist/internal/react-app-shell/index.d.ts +2 -22
  46. package/dist/internal/react-badge/index.d.cts +5 -0
  47. package/dist/internal/react-badge/index.d.ts +5 -0
  48. package/dist/internal/react-callout/index.d.cts +4 -0
  49. package/dist/internal/react-callout/index.d.ts +4 -0
  50. package/dist/internal/react-card/index.d.cts +8 -1
  51. package/dist/internal/react-card/index.d.ts +8 -1
  52. package/dist/internal/react-collapsible/index.d.cts +0 -3
  53. package/dist/internal/react-collapsible/index.d.ts +0 -3
  54. package/dist/internal/react-combobox/index.d.cts +0 -3
  55. package/dist/internal/react-combobox/index.d.ts +0 -3
  56. package/dist/internal/react-command/index.d.cts +0 -3
  57. package/dist/internal/react-command/index.d.ts +0 -3
  58. package/dist/internal/react-data-table/index.d.cts +0 -3
  59. package/dist/internal/react-data-table/index.d.ts +0 -3
  60. package/dist/internal/react-dialog/index.d.cts +0 -3
  61. package/dist/internal/react-dialog/index.d.ts +0 -3
  62. package/dist/internal/react-dropdown-menu/index.d.cts +0 -3
  63. package/dist/internal/react-dropdown-menu/index.d.ts +0 -3
  64. package/dist/internal/react-feedback-dialog/index.d.cts +0 -3
  65. package/dist/internal/react-feedback-dialog/index.d.ts +0 -3
  66. package/dist/internal/react-form/index.d.cts +2 -21
  67. package/dist/internal/react-form/index.d.ts +2 -21
  68. package/dist/internal/react-keyboard-shortcut/index.d.cts +0 -6
  69. package/dist/internal/react-keyboard-shortcut/index.d.ts +0 -6
  70. package/dist/internal/react-link-card/index.d.cts +8 -2
  71. package/dist/internal/react-link-card/index.d.ts +8 -2
  72. package/dist/internal/react-popover/index.d.cts +0 -3
  73. package/dist/internal/react-popover/index.d.ts +0 -3
  74. package/dist/internal/react-sheet/index.d.cts +0 -3
  75. package/dist/internal/react-sheet/index.d.ts +0 -3
  76. package/dist/internal/react-slot/index.d.cts +23 -0
  77. package/dist/internal/react-slot/index.d.ts +23 -0
  78. package/dist/internal/react-toast/index.d.cts +0 -3
  79. package/dist/internal/react-toast/index.d.ts +0 -3
  80. package/dist/internal/react-tooltip/index.d.cts +0 -3
  81. package/dist/internal/react-tooltip/index.d.ts +0 -3
  82. package/dist/react-accordion.js +125 -0
  83. package/dist/react-accordion.js.map +7 -0
  84. package/dist/react-ai.js +257 -0
  85. package/dist/react-ai.js.map +7 -0
  86. package/dist/react-analytics.js +1698 -0
  87. package/dist/react-analytics.js.map +7 -0
  88. package/dist/react-animated-text.js +164 -0
  89. package/dist/react-animated-text.js.map +7 -0
  90. package/dist/react-app-shell.js +631 -0
  91. package/dist/react-app-shell.js.map +7 -0
  92. package/dist/react-audience-feature-card.js +53 -0
  93. package/dist/react-audience-feature-card.js.map +7 -0
  94. package/dist/react-audio-room.js +166 -0
  95. package/dist/react-audio-room.js.map +7 -0
  96. package/dist/react-auth.js +211 -0
  97. package/dist/react-auth.js.map +7 -0
  98. package/dist/react-avatar-group.js +154 -0
  99. package/dist/react-avatar-group.js.map +7 -0
  100. package/dist/react-avatar.js +168 -0
  101. package/dist/react-avatar.js.map +7 -0
  102. package/dist/react-badge.js +86 -0
  103. package/dist/react-badge.js.map +7 -0
  104. package/dist/react-bottom-nav.js +67 -0
  105. package/dist/react-bottom-nav.js.map +7 -0
  106. package/dist/react-brand-network-cell.js +92 -0
  107. package/dist/react-brand-network-cell.js.map +7 -0
  108. package/dist/react-breadcrumbs.js +104 -0
  109. package/dist/react-breadcrumbs.js.map +7 -0
  110. package/dist/react-browser-chrome-mock.js +89 -0
  111. package/dist/react-browser-chrome-mock.js.map +7 -0
  112. package/dist/react-button.js +13 -0
  113. package/dist/react-button.js.map +7 -0
  114. package/dist/react-calendar.js +301 -0
  115. package/dist/react-calendar.js.map +7 -0
  116. package/dist/react-call-controls.js +113 -0
  117. package/dist/react-call-controls.js.map +7 -0
  118. package/dist/react-callout.js +152 -0
  119. package/dist/react-callout.js.map +7 -0
  120. package/dist/react-card-grid.js +34 -0
  121. package/dist/react-card-grid.js.map +7 -0
  122. package/dist/react-card.js +200 -0
  123. package/dist/react-card.js.map +7 -0
  124. package/dist/react-carousel.js +132 -0
  125. package/dist/react-carousel.js.map +7 -0
  126. package/dist/react-charts.js +509 -0
  127. package/dist/react-charts.js.map +7 -0
  128. package/dist/react-checkbox.js +156 -0
  129. package/dist/react-checkbox.js.map +7 -0
  130. package/dist/react-checklist.js +168 -0
  131. package/dist/react-checklist.js.map +7 -0
  132. package/dist/react-code-block.js +78 -0
  133. package/dist/react-code-block.js.map +7 -0
  134. package/dist/react-code-editor.js +184 -0
  135. package/dist/react-code-editor.js.map +7 -0
  136. package/dist/react-collapsible.js +192 -0
  137. package/dist/react-collapsible.js.map +7 -0
  138. package/dist/react-combobox.js +609 -0
  139. package/dist/react-combobox.js.map +7 -0
  140. package/dist/react-command-input.js +202 -0
  141. package/dist/react-command-input.js.map +7 -0
  142. package/dist/react-command.js +364 -0
  143. package/dist/react-command.js.map +7 -0
  144. package/dist/react-composer.js +2036 -0
  145. package/dist/react-composer.js.map +7 -0
  146. package/dist/react-content-protection.js +133 -0
  147. package/dist/react-content-protection.js.map +7 -0
  148. package/dist/react-conversation.js +1226 -0
  149. package/dist/react-conversation.js.map +7 -0
  150. package/dist/react-cookie-consent.js +291 -0
  151. package/dist/react-cookie-consent.js.map +7 -0
  152. package/dist/react-data-table.js +310 -0
  153. package/dist/react-data-table.js.map +7 -0
  154. package/dist/react-date-picker.js +95 -0
  155. package/dist/react-date-picker.js.map +7 -0
  156. package/dist/react-device-frame.js +137 -0
  157. package/dist/react-device-frame.js.map +7 -0
  158. package/dist/react-dialog.js +218 -0
  159. package/dist/react-dialog.js.map +7 -0
  160. package/dist/react-diff-viewer.js +460 -0
  161. package/dist/react-diff-viewer.js.map +7 -0
  162. package/dist/react-dropdown-menu.js +292 -0
  163. package/dist/react-dropdown-menu.js.map +7 -0
  164. package/dist/react-editor-status-bar.js +148 -0
  165. package/dist/react-editor-status-bar.js.map +7 -0
  166. package/dist/react-editor-tabs.js +159 -0
  167. package/dist/react-editor-tabs.js.map +7 -0
  168. package/dist/react-emoji-picker.js +238 -0
  169. package/dist/react-emoji-picker.js.map +7 -0
  170. package/dist/react-empty-state.js +90 -0
  171. package/dist/react-empty-state.js.map +7 -0
  172. package/dist/react-feedback-dialog.js +275 -0
  173. package/dist/react-feedback-dialog.js.map +7 -0
  174. package/dist/react-file-tree.js +376 -0
  175. package/dist/react-file-tree.js.map +7 -0
  176. package/dist/react-file-upload.js +360 -0
  177. package/dist/react-file-upload.js.map +7 -0
  178. package/dist/react-floating-reactions.js +124 -0
  179. package/dist/react-floating-reactions.js.map +7 -0
  180. package/dist/react-flow-editor.js +198 -0
  181. package/dist/react-flow-editor.js.map +7 -0
  182. package/dist/react-footer.js +67 -0
  183. package/dist/react-footer.js.map +7 -0
  184. package/dist/react-graph-view.js +197 -0
  185. package/dist/react-graph-view.js.map +7 -0
  186. package/dist/react-icon-system.js +9 -0
  187. package/dist/react-icon-system.js.map +7 -0
  188. package/dist/react-infinite-canvas.js +8 -0
  189. package/dist/react-infinite-canvas.js.map +7 -0
  190. package/dist/react-inline-editor.js +216 -0
  191. package/dist/react-inline-editor.js.map +7 -0
  192. package/dist/react-input-group.js +150 -0
  193. package/dist/react-input-group.js.map +7 -0
  194. package/dist/react-input.js +10 -0
  195. package/dist/react-input.js.map +7 -0
  196. package/dist/react-install-prompt.js +132 -0
  197. package/dist/react-install-prompt.js.map +7 -0
  198. package/dist/react-kanban-board.js +198 -0
  199. package/dist/react-kanban-board.js.map +7 -0
  200. package/dist/react-keyboard-shortcut.js +36 -0
  201. package/dist/react-keyboard-shortcut.js.map +7 -0
  202. package/dist/react-language-selector.js +311 -0
  203. package/dist/react-language-selector.js.map +7 -0
  204. package/dist/react-link-card.js +48 -0
  205. package/dist/react-link-card.js.map +7 -0
  206. package/dist/react-live-captions.js +92 -0
  207. package/dist/react-live-captions.js.map +7 -0
  208. package/dist/react-live-cursors.js +145 -0
  209. package/dist/react-live-cursors.js.map +7 -0
  210. package/dist/react-live-transcript.js +117 -0
  211. package/dist/react-live-transcript.js.map +7 -0
  212. package/dist/react-location-selector.js +252 -0
  213. package/dist/react-location-selector.js.map +7 -0
  214. package/dist/react-logger.js +415 -0
  215. package/dist/react-logger.js.map +7 -0
  216. package/dist/react-markdown-renderer.js +12 -0
  217. package/dist/react-markdown-renderer.js.map +7 -0
  218. package/dist/react-marquee-strip.js +62 -0
  219. package/dist/react-marquee-strip.js.map +7 -0
  220. package/dist/react-mascot.js +367 -0
  221. package/dist/react-mascot.js.map +7 -0
  222. package/dist/react-mastery-bar.js +97 -0
  223. package/dist/react-mastery-bar.js.map +7 -0
  224. package/dist/react-mini-map.js +207 -0
  225. package/dist/react-mini-map.js.map +7 -0
  226. package/dist/react-mobile-nav.js +216 -0
  227. package/dist/react-mobile-nav.js.map +7 -0
  228. package/dist/react-navbar.js +96 -0
  229. package/dist/react-navbar.js.map +7 -0
  230. package/dist/react-numbered-steps.js +67 -0
  231. package/dist/react-numbered-steps.js.map +7 -0
  232. package/dist/react-otp-input.js +318 -0
  233. package/dist/react-otp-input.js.map +7 -0
  234. package/dist/react-pagination.js +199 -0
  235. package/dist/react-pagination.js.map +7 -0
  236. package/dist/react-password-input.js +104 -0
  237. package/dist/react-password-input.js.map +7 -0
  238. package/dist/react-payment.js +81 -0
  239. package/dist/react-payment.js.map +7 -0
  240. package/dist/react-popover.js +176 -0
  241. package/dist/react-popover.js.map +7 -0
  242. package/dist/react-pre-call-lobby.js +309 -0
  243. package/dist/react-pre-call-lobby.js.map +7 -0
  244. package/dist/react-presence-indicator.js +86 -0
  245. package/dist/react-presence-indicator.js.map +7 -0
  246. package/dist/react-pricing-card.js +142 -0
  247. package/dist/react-pricing-card.js.map +7 -0
  248. package/dist/react-progress-display.js +188 -0
  249. package/dist/react-progress-display.js.map +7 -0
  250. package/dist/react-radial-gauge.js +193 -0
  251. package/dist/react-radial-gauge.js.map +7 -0
  252. package/dist/react-radio.js +169 -0
  253. package/dist/react-radio.js.map +7 -0
  254. package/dist/react-rating-scale.js +171 -0
  255. package/dist/react-rating-scale.js.map +7 -0
  256. package/dist/react-reaction-bar.js +111 -0
  257. package/dist/react-reaction-bar.js.map +7 -0
  258. package/dist/react-resizable-layout.js +298 -0
  259. package/dist/react-resizable-layout.js.map +7 -0
  260. package/dist/react-rich-editor.js +1 -0
  261. package/dist/react-rich-editor.js.map +7 -0
  262. package/dist/react-search-bar.js +285 -0
  263. package/dist/react-search-bar.js.map +7 -0
  264. package/dist/react-section-head.js +65 -0
  265. package/dist/react-section-head.js.map +7 -0
  266. package/dist/react-segmented-control.js +215 -0
  267. package/dist/react-segmented-control.js.map +7 -0
  268. package/dist/react-select.js +389 -0
  269. package/dist/react-select.js.map +7 -0
  270. package/dist/react-separator.js +86 -0
  271. package/dist/react-separator.js.map +7 -0
  272. package/dist/react-sheet.js +310 -0
  273. package/dist/react-sheet.js.map +7 -0
  274. package/dist/react-sidebar.js +100 -0
  275. package/dist/react-sidebar.js.map +7 -0
  276. package/dist/react-skeleton.js +91 -0
  277. package/dist/react-skeleton.js.map +7 -0
  278. package/dist/react-skip-to-content.js +38 -0
  279. package/dist/react-skip-to-content.js.map +7 -0
  280. package/dist/react-slide-viewer.js +264 -0
  281. package/dist/react-slide-viewer.js.map +7 -0
  282. package/dist/react-slider.js +105 -0
  283. package/dist/react-slider.js.map +7 -0
  284. package/dist/react-slot-picker.js +184 -0
  285. package/dist/react-slot-picker.js.map +7 -0
  286. package/dist/react-slot.js +7 -0
  287. package/dist/react-slot.js.map +7 -0
  288. package/dist/react-social-auth-button.js +169 -0
  289. package/dist/react-social-auth-button.js.map +7 -0
  290. package/dist/react-sortable-list.js +204 -0
  291. package/dist/react-sortable-list.js.map +7 -0
  292. package/dist/react-stat-grid.js +69 -0
  293. package/dist/react-stat-grid.js.map +7 -0
  294. package/dist/react-status-indicator.js +117 -0
  295. package/dist/react-status-indicator.js.map +7 -0
  296. package/dist/react-steps.js +167 -0
  297. package/dist/react-steps.js.map +7 -0
  298. package/dist/react-sticky-note.js +131 -0
  299. package/dist/react-sticky-note.js.map +7 -0
  300. package/dist/react-switch.js +139 -0
  301. package/dist/react-switch.js.map +7 -0
  302. package/dist/react-table-of-contents.js +80 -0
  303. package/dist/react-table-of-contents.js.map +7 -0
  304. package/dist/react-tabs.js +230 -0
  305. package/dist/react-tabs.js.map +7 -0
  306. package/dist/react-terminal.js +101 -0
  307. package/dist/react-terminal.js.map +7 -0
  308. package/dist/react-test-results.js +158 -0
  309. package/dist/react-test-results.js.map +7 -0
  310. package/dist/react-textarea.js +89 -0
  311. package/dist/react-textarea.js.map +7 -0
  312. package/dist/react-thread-view.js +139 -0
  313. package/dist/react-thread-view.js.map +7 -0
  314. package/dist/react-timeline.js +153 -0
  315. package/dist/react-timeline.js.map +7 -0
  316. package/dist/react-toast.js +253 -0
  317. package/dist/react-toast.js.map +7 -0
  318. package/dist/react-tooltip.js +221 -0
  319. package/dist/react-tooltip.js.map +7 -0
  320. package/dist/react-version-selector.js +270 -0
  321. package/dist/react-version-selector.js.map +7 -0
  322. package/dist/react-video-grid.js +129 -0
  323. package/dist/react-video-grid.js.map +7 -0
  324. package/dist/react-video-player.js +206 -0
  325. package/dist/react-video-player.js.map +7 -0
  326. package/dist/react-video-tile.js +8 -0
  327. package/dist/react-video-tile.js.map +7 -0
  328. package/dist/react-voice-pill.js +314 -0
  329. package/dist/react-voice-pill.js.map +7 -0
  330. package/dist/react-waveform.js +558 -0
  331. package/dist/react-waveform.js.map +7 -0
  332. package/dist/react-wizard.js +337 -0
  333. package/dist/react-wizard.js.map +7 -0
  334. package/dist/styles.css +7 -0
  335. package/dist/theme.js +1 -1
  336. package/package.json +3 -2
  337. package/dist/applicationinsights-web-H7OBLIVJ.js +0 -23393
  338. package/dist/applicationinsights-web-H7OBLIVJ.js.map +0 -1
  339. package/dist/chunk-4A4BW3GR.js.map +0 -1
  340. package/dist/index.js.map +0 -1
  341. package/dist/module-X3HTTRQK.js +0 -6438
  342. package/dist/module-X3HTTRQK.js.map +0 -1
@@ -0,0 +1,2036 @@
1
+ import {
2
+ detectEmojiShortcode,
3
+ detectTriggerInText
4
+ } from "./chunk-BOLFYVI6.js";
5
+ import {
6
+ searchEmojis
7
+ } from "./chunk-533MCMSU.js";
8
+ import {
9
+ cn,
10
+ cva,
11
+ generateId,
12
+ prefersReducedMotion
13
+ } from "./chunk-ZF3OHCGV.js";
14
+
15
+ // ../react-composer/dist/index.js
16
+ import * as React2 from "react";
17
+
18
+ // ../composer/dist/index.js
19
+ function toMessageAttachment(attachment) {
20
+ return {
21
+ id: attachment.id,
22
+ name: attachment.name,
23
+ url: attachment.previewUrl ?? "",
24
+ type: attachment.mimeType ?? attachment.kind,
25
+ size: attachment.sizeBytes
26
+ };
27
+ }
28
+ var cachedSegmenter;
29
+ function getSegmenter() {
30
+ if (cachedSegmenter === void 0) {
31
+ const IntlAny = typeof Intl !== "undefined" ? Intl : void 0;
32
+ const Segmenter = IntlAny?.Segmenter;
33
+ cachedSegmenter = Segmenter ? new Segmenter(void 0, { granularity: "grapheme" }) : null;
34
+ }
35
+ return cachedSegmenter;
36
+ }
37
+ function isHighSurrogate(code) {
38
+ return code >= 55296 && code <= 56319;
39
+ }
40
+ function isLowSurrogate(code) {
41
+ return code >= 56320 && code <= 57343;
42
+ }
43
+ function graphemeLength(text) {
44
+ if (text === "") return 0;
45
+ const segmenter = getSegmenter();
46
+ if (segmenter) {
47
+ let count2 = 0;
48
+ for (const _ of segmenter.segment(text)) count2++;
49
+ return count2;
50
+ }
51
+ let count = 0;
52
+ for (const _ of text) count++;
53
+ return count;
54
+ }
55
+ function clampGraphemes(text, max) {
56
+ if (max <= 0) return "";
57
+ const segmenter = getSegmenter();
58
+ if (segmenter) {
59
+ let count2 = 0;
60
+ let endIndex = text.length;
61
+ for (const part of segmenter.segment(text)) {
62
+ count2++;
63
+ if (count2 > max) {
64
+ endIndex = part.index;
65
+ break;
66
+ }
67
+ }
68
+ return text.slice(0, endIndex);
69
+ }
70
+ let count = 0;
71
+ let i = 0;
72
+ while (i < text.length && count < max) {
73
+ const code = text.charCodeAt(i);
74
+ i += isHighSurrogate(code) && i + 1 < text.length && isLowSurrogate(text.charCodeAt(i + 1)) ? 2 : 1;
75
+ count++;
76
+ }
77
+ return text.slice(0, i);
78
+ }
79
+ function payloadFor(raw) {
80
+ return raw.trim();
81
+ }
82
+ function canSend({ text, attachments = [], disabled = false, readOnly = false, busy = false }) {
83
+ if (disabled || readOnly || busy) return false;
84
+ return payloadFor(text).length > 0 || attachments.length > 0;
85
+ }
86
+ function shouldSubmitOnEnter({
87
+ shiftPressed,
88
+ isComposing
89
+ }) {
90
+ return !shiftPressed && !isComposing;
91
+ }
92
+ var COUNTER_VISIBLE_FRACTION = 0.2;
93
+ function computeCounter(text, maxLength) {
94
+ if (maxLength === void 0) {
95
+ return { visible: false, remaining: null, overLimit: false };
96
+ }
97
+ const remaining = maxLength - graphemeLength(text);
98
+ return {
99
+ visible: remaining <= maxLength * COUNTER_VISIBLE_FRACTION,
100
+ remaining,
101
+ overLimit: remaining <= 0
102
+ };
103
+ }
104
+ var DEFAULT_MAX_QUERY_LENGTH = 40;
105
+ var DEFAULT_MAX_VISIBLE_RESULTS = 6;
106
+ var SCAN_UNITS_PER_GRAPHEME = 16;
107
+ function resolveTriggerConfig(trigger) {
108
+ const symbol = trigger.symbol;
109
+ return {
110
+ id: trigger.id,
111
+ symbol,
112
+ scope: trigger.scope ?? "anywhere",
113
+ queryPattern: trigger.queryPattern ?? null,
114
+ maxQueryLength: trigger.maxQueryLength ?? DEFAULT_MAX_QUERY_LENGTH,
115
+ closeOnSpace: trigger.closeOnSpace ?? true,
116
+ allowMidWord: trigger.allowMidWord ?? false,
117
+ extraBoundaryChars: trigger.extraBoundaryChars ?? [],
118
+ debounceMs: trigger.debounceMs ?? 0,
119
+ maxVisibleResults: trigger.maxVisibleResults ?? DEFAULT_MAX_VISIBLE_RESULTS,
120
+ wrapNavigation: trigger.wrapNavigation ?? true,
121
+ toDisplay: trigger.toDisplay ?? ((candidate) => `${symbol}${candidate.display}`),
122
+ resolve: trigger.resolve
123
+ };
124
+ }
125
+ function scanWindowFor(trigger) {
126
+ return trigger.maxQueryLength * SCAN_UNITS_PER_GRAPHEME + trigger.symbol.length;
127
+ }
128
+ function isWhitespace(ch) {
129
+ return /\s/.test(ch);
130
+ }
131
+ function boundaryOk(text, symbolStart, trigger) {
132
+ if (trigger.allowMidWord) return true;
133
+ if (symbolStart === 0) return true;
134
+ const prev = text[symbolStart - 1];
135
+ return isWhitespace(prev) || trigger.extraBoundaryChars.includes(prev);
136
+ }
137
+ function scopeOk(text, symbolStart, scope) {
138
+ if (scope === "anywhere") return true;
139
+ if (scope === "startOfMessage") return symbolStart === 0;
140
+ return symbolStart === 0 || text[symbolStart - 1] === "\n";
141
+ }
142
+ function findCandidate(text, caret, trigger) {
143
+ const window2 = scanWindowFor(trigger);
144
+ const isSimple = trigger.symbol.length === 1 && trigger.scope === "anywhere" && trigger.closeOnSpace && !trigger.allowMidWord && trigger.extraBoundaryChars.length === 0;
145
+ if (isSimple) {
146
+ const sliceStart2 = Math.max(0, caret - window2 - 1);
147
+ const slice = text.slice(sliceStart2, caret);
148
+ const hit = detectTriggerInText(slice, slice.length, trigger.symbol);
149
+ if (!hit) return null;
150
+ return { symbolStart: sliceStart2 + hit.start, query: hit.query };
151
+ }
152
+ const sliceStart = Math.max(0, caret - window2);
153
+ const rel = text.slice(sliceStart, caret).lastIndexOf(trigger.symbol);
154
+ if (rel === -1) return null;
155
+ const symbolStart = sliceStart + rel;
156
+ if (symbolStart + trigger.symbol.length > caret) return null;
157
+ return { symbolStart, query: text.slice(symbolStart + trigger.symbol.length, caret) };
158
+ }
159
+ function validateCandidate(text, caret, trigger, candidate, dismissed, tokenRanges) {
160
+ const { symbolStart, query } = candidate;
161
+ if (!boundaryOk(text, symbolStart, trigger)) return null;
162
+ if (!scopeOk(text, symbolStart, trigger.scope)) return null;
163
+ for (const range of tokenRanges) {
164
+ if (symbolStart >= range.start && symbolStart < range.end) return null;
165
+ }
166
+ if (dismissed.some((d) => d.triggerId === trigger.id && d.symbolStart === symbolStart)) return null;
167
+ if (trigger.closeOnSpace && /\s/.test(query)) return null;
168
+ if (!trigger.closeOnSpace && query.includes("\n")) return null;
169
+ if (graphemeLength(query) > trigger.maxQueryLength) return null;
170
+ if (trigger.queryPattern && !trigger.queryPattern.test(query)) return null;
171
+ return { trigger, symbolStart, caret, query };
172
+ }
173
+ function detectActiveTrigger({
174
+ text,
175
+ caret,
176
+ triggers,
177
+ isComposing = false,
178
+ dismissed = [],
179
+ tokenRanges = []
180
+ }) {
181
+ if (isComposing) return null;
182
+ let best = null;
183
+ for (const trigger of triggers) {
184
+ const candidate = findCandidate(text, caret, trigger);
185
+ if (!candidate) continue;
186
+ const match = validateCandidate(text, caret, trigger, candidate, dismissed, tokenRanges);
187
+ if (!match) continue;
188
+ if (!best || match.symbolStart > best.symbolStart || match.symbolStart === best.symbolStart && match.trigger.symbol.length > best.trigger.symbol.length) {
189
+ best = match;
190
+ }
191
+ }
192
+ return best;
193
+ }
194
+ var LOADING_DELAY_MS = 120;
195
+ var DISMISS_GRACE_MS = 120;
196
+ var CIRCUIT_BREAKER_THRESHOLD = 2;
197
+ var CLOSED_SUGGESTION_STATE = {
198
+ isOpen: false,
199
+ items: [],
200
+ visibleItems: [],
201
+ activeIndex: 0,
202
+ loading: false,
203
+ error: null,
204
+ requestToken: 0
205
+ };
206
+ function createSuggestionController({ emit }) {
207
+ let state = CLOSED_SUGGESTION_STATE;
208
+ let match = null;
209
+ let requestCounter = 0;
210
+ let debounceTimer = null;
211
+ let loadingTimer = null;
212
+ let dismissTimer = null;
213
+ const consecutiveFailures = /* @__PURE__ */ new Map();
214
+ const tripped = /* @__PURE__ */ new Set();
215
+ function clearTimer(timer) {
216
+ if (timer !== null) clearTimeout(timer);
217
+ return null;
218
+ }
219
+ function setState(patch) {
220
+ state = { ...state, ...patch };
221
+ }
222
+ function sameOccurrence(a, b) {
223
+ return a !== null && b !== null && a.trigger.id === b.trigger.id && a.symbolStart === b.symbolStart;
224
+ }
225
+ function closeInternal() {
226
+ debounceTimer = clearTimer(debounceTimer);
227
+ loadingTimer = clearTimer(loadingTimer);
228
+ requestCounter++;
229
+ match = null;
230
+ state = CLOSED_SUGGESTION_STATE;
231
+ }
232
+ function applyResults(forMatch, items) {
233
+ loadingTimer = clearTimer(loadingTimer);
234
+ consecutiveFailures.set(forMatch.trigger.id, 0);
235
+ setState({
236
+ isOpen: true,
237
+ items,
238
+ visibleItems: items.slice(0, forMatch.trigger.maxVisibleResults),
239
+ activeIndex: 0,
240
+ loading: false,
241
+ error: null
242
+ });
243
+ }
244
+ function applyFailure(forMatch, error) {
245
+ loadingTimer = clearTimer(loadingTimer);
246
+ const triggerId = forMatch.trigger.id;
247
+ const failures = (consecutiveFailures.get(triggerId) ?? 0) + 1;
248
+ consecutiveFailures.set(triggerId, failures);
249
+ if (failures >= CIRCUIT_BREAKER_THRESHOLD) {
250
+ tripped.add(triggerId);
251
+ closeInternal();
252
+ return;
253
+ }
254
+ setState({
255
+ isOpen: true,
256
+ items: [],
257
+ visibleItems: [],
258
+ loading: false,
259
+ error: error instanceof Error ? error.message : "Failed to load suggestions"
260
+ });
261
+ }
262
+ function dispatch(forMatch, notifySync) {
263
+ const token = ++requestCounter;
264
+ setState({ requestToken: token });
265
+ let result;
266
+ try {
267
+ result = forMatch.trigger.resolve(forMatch.query);
268
+ } catch (error) {
269
+ applyFailure(forMatch, error);
270
+ if (notifySync) emit();
271
+ return;
272
+ }
273
+ if (Array.isArray(result)) {
274
+ applyResults(forMatch, result);
275
+ if (notifySync) emit();
276
+ return;
277
+ }
278
+ loadingTimer = clearTimer(loadingTimer);
279
+ loadingTimer = setTimeout(() => {
280
+ if (token !== requestCounter) return;
281
+ setState({ isOpen: true, loading: true });
282
+ emit();
283
+ }, LOADING_DELAY_MS);
284
+ result.then(
285
+ (items) => {
286
+ if (token !== requestCounter || !sameOccurrence(match, forMatch)) return;
287
+ applyResults(forMatch, items);
288
+ emit();
289
+ },
290
+ (error) => {
291
+ if (token !== requestCounter || !sameOccurrence(match, forMatch)) return;
292
+ applyFailure(forMatch, error);
293
+ emit();
294
+ }
295
+ );
296
+ }
297
+ function schedule(forMatch) {
298
+ debounceTimer = clearTimer(debounceTimer);
299
+ if (forMatch.trigger.debounceMs <= 0) {
300
+ dispatch(forMatch, false);
301
+ return;
302
+ }
303
+ debounceTimer = setTimeout(() => {
304
+ debounceTimer = null;
305
+ if (sameOccurrence(match, forMatch) && match?.query === forMatch.query) {
306
+ dispatch(forMatch, true);
307
+ }
308
+ }, forMatch.trigger.debounceMs);
309
+ }
310
+ return {
311
+ get state() {
312
+ return state;
313
+ },
314
+ sync(next) {
315
+ if (next === null) {
316
+ if (match !== null || state.isOpen) closeInternal();
317
+ return;
318
+ }
319
+ if (tripped.has(next.trigger.id)) {
320
+ if (match !== null || state.isOpen) closeInternal();
321
+ return;
322
+ }
323
+ const isSame = sameOccurrence(match, next);
324
+ const queryChanged = !isSame || match?.query !== next.query;
325
+ match = next;
326
+ if (!isSame) {
327
+ state = { ...CLOSED_SUGGESTION_STATE, isOpen: true, requestToken: state.requestToken };
328
+ }
329
+ if (queryChanged) schedule(next);
330
+ },
331
+ moveNext() {
332
+ const count = state.items.length;
333
+ if (!state.isOpen || count === 0) return;
334
+ const wrap = match?.trigger.wrapNavigation ?? true;
335
+ const next = wrap ? (state.activeIndex + 1) % count : Math.min(state.activeIndex + 1, count - 1);
336
+ setState({ activeIndex: next });
337
+ },
338
+ movePrevious() {
339
+ const count = state.items.length;
340
+ if (!state.isOpen || count === 0) return;
341
+ const wrap = match?.trigger.wrapNavigation ?? true;
342
+ const previous = wrap ? (state.activeIndex - 1 + count) % count : Math.max(state.activeIndex - 1, 0);
343
+ setState({ activeIndex: previous });
344
+ },
345
+ setActiveIndex(index) {
346
+ if (!state.isOpen || state.items.length === 0) return;
347
+ setState({ activeIndex: Math.max(0, Math.min(index, state.items.length - 1)) });
348
+ },
349
+ retry() {
350
+ if (match === null) return;
351
+ if (tripped.has(match.trigger.id)) return;
352
+ setState({ error: null });
353
+ dispatch(match, false);
354
+ },
355
+ dismissDeferred(onClosed) {
356
+ dismissTimer = clearTimer(dismissTimer);
357
+ dismissTimer = setTimeout(() => {
358
+ dismissTimer = null;
359
+ closeInternal();
360
+ onClosed();
361
+ }, DISMISS_GRACE_MS);
362
+ },
363
+ cancelDeferredDismiss() {
364
+ dismissTimer = clearTimer(dismissTimer);
365
+ },
366
+ close() {
367
+ dismissTimer = clearTimer(dismissTimer);
368
+ closeInternal();
369
+ },
370
+ isTripped(triggerId) {
371
+ return tripped.has(triggerId);
372
+ },
373
+ destroy() {
374
+ debounceTimer = clearTimer(debounceTimer);
375
+ loadingTimer = clearTimer(loadingTimer);
376
+ dismissTimer = clearTimer(dismissTimer);
377
+ match = null;
378
+ state = CLOSED_SUGGESTION_STATE;
379
+ }
380
+ };
381
+ }
382
+ function diffEdit(oldText, newText) {
383
+ if (oldText === newText) return null;
384
+ const minLen = Math.min(oldText.length, newText.length);
385
+ let prefix = 0;
386
+ while (prefix < minLen && oldText[prefix] === newText[prefix]) prefix++;
387
+ let suffix = 0;
388
+ while (suffix < minLen - prefix && oldText[oldText.length - 1 - suffix] === newText[newText.length - 1 - suffix]) {
389
+ suffix++;
390
+ }
391
+ return { start: prefix, oldEnd: oldText.length - suffix, newEnd: newText.length - suffix };
392
+ }
393
+ function nearestBoundary(offset, token) {
394
+ return offset - token.start <= token.end - offset ? token.start : token.end;
395
+ }
396
+ function applyValueEdit({
397
+ oldValue,
398
+ newValue,
399
+ tokens,
400
+ newSelection,
401
+ maxLength
402
+ }) {
403
+ const noChange = {
404
+ value: oldValue,
405
+ tokens: [...tokens],
406
+ selection: newSelection,
407
+ rejected: false,
408
+ trimmed: false,
409
+ removedTokens: [],
410
+ edit: null
411
+ };
412
+ const diff = diffEdit(oldValue, newValue);
413
+ if (!diff) return noChange;
414
+ const insertedRaw = newValue.slice(diff.start, diff.newEnd);
415
+ if (diff.oldEnd === diff.start) {
416
+ const host = tokens.find((t) => t.start < diff.start && diff.start < t.end);
417
+ if (host) {
418
+ const caret2 = nearestBoundary(diff.start, host);
419
+ return { ...noChange, rejected: true, selection: { start: caret2, end: caret2 } };
420
+ }
421
+ }
422
+ let expStart = diff.start;
423
+ let expOldEnd = diff.oldEnd;
424
+ const removedTokens = [];
425
+ for (const token of tokens) {
426
+ const overlaps = token.start < expOldEnd && token.end > expStart;
427
+ if (!overlaps) continue;
428
+ removedTokens.push(token);
429
+ expStart = Math.min(expStart, token.start);
430
+ expOldEnd = Math.max(expOldEnd, token.end);
431
+ }
432
+ let inserted = insertedRaw;
433
+ let trimmed = false;
434
+ if (maxLength !== void 0 && inserted.length > 0) {
435
+ const baseLength = graphemeLength(oldValue.slice(0, expStart)) + graphemeLength(oldValue.slice(expOldEnd));
436
+ const budget = Math.max(0, maxLength - baseLength);
437
+ if (graphemeLength(inserted) > budget) {
438
+ inserted = clampGraphemes(inserted, budget);
439
+ trimmed = true;
440
+ }
441
+ }
442
+ const value = oldValue.slice(0, expStart) + inserted + oldValue.slice(expOldEnd);
443
+ const delta = expStart + inserted.length - expOldEnd;
444
+ const nextTokens = tokens.filter((t) => !removedTokens.includes(t)).map((t) => t.start >= expOldEnd ? { ...t, start: t.start + delta, end: t.end + delta } : t);
445
+ const appliedMatchesRaw = expStart === diff.start && expOldEnd === diff.oldEnd && !trimmed;
446
+ const caret = expStart + inserted.length;
447
+ const selection = appliedMatchesRaw ? newSelection : { start: caret, end: caret };
448
+ return {
449
+ value,
450
+ tokens: nextTokens,
451
+ selection: clampSelectionToValue(selection, value),
452
+ rejected: false,
453
+ trimmed,
454
+ removedTokens,
455
+ edit: { start: expStart, oldEnd: expOldEnd, newEnd: expStart + inserted.length }
456
+ };
457
+ }
458
+ function clampSelectionToValue(selection, value) {
459
+ const clamp = (n) => Math.max(0, Math.min(n, value.length));
460
+ return { start: clamp(selection.start), end: clamp(selection.end) };
461
+ }
462
+ function snapSelectionToTokens(tokens, selection, previous) {
463
+ const inside = (offset) => tokens.find((t) => t.start < offset && offset < t.end);
464
+ if (selection.start === selection.end) {
465
+ const host = inside(selection.start);
466
+ if (!host) return selection;
467
+ let caret;
468
+ if (previous && previous.start === previous.end && previous.start !== selection.start) {
469
+ caret = selection.start > previous.start ? host.end : host.start;
470
+ } else {
471
+ caret = nearestBoundary(selection.start, host);
472
+ }
473
+ return { start: caret, end: caret };
474
+ }
475
+ const startHost = inside(selection.start);
476
+ const endHost = inside(selection.end);
477
+ return {
478
+ start: startHost ? startHost.start : selection.start,
479
+ end: endHost ? endHost.end : selection.end
480
+ };
481
+ }
482
+ function expandRangeOverTokens(tokens, range) {
483
+ let { start, end } = range;
484
+ for (const token of tokens) {
485
+ if (token.start < end && token.end > start) {
486
+ start = Math.min(start, token.start);
487
+ end = Math.max(end, token.end);
488
+ }
489
+ }
490
+ return { start, end };
491
+ }
492
+ function commitTokenAt({ value, tokens, start, end, token }) {
493
+ const display = token.display;
494
+ const nextValue = value.slice(0, start) + display + value.slice(end);
495
+ const delta = display.length - (end - start);
496
+ const placed = { ...token, start, end: start + display.length };
497
+ const shifted = tokens.map(
498
+ (t) => t.start >= end ? { ...t, start: t.start + delta, end: t.end + delta } : t
499
+ );
500
+ const nextTokens = [...shifted, placed].sort((a, b) => a.start - b.start);
501
+ const caret = placed.end;
502
+ return { value: nextValue, tokens: nextTokens, selection: { start: caret, end: caret } };
503
+ }
504
+ function serializeTokens(value, tokens) {
505
+ const resolved = tokens.map((t) => ({
506
+ type: t.triggerId,
507
+ id: t.id,
508
+ display: t.display,
509
+ start: t.start,
510
+ end: t.end
511
+ }));
512
+ return { plainText: value, tokens: resolved };
513
+ }
514
+ function detectTypedEmoji(value, caret) {
515
+ const hit = detectEmojiShortcode(value.slice(0, caret));
516
+ if (!hit) return null;
517
+ return { shortcode: hit.shortcode, unicode: hit.unicode, start: caret - hit.shortcode.length };
518
+ }
519
+ var DEFAULT_DRAFT_DEBOUNCE_MS = 400;
520
+ var DEFAULT_TYPING_SIGNAL_INTERVAL_MS = 3e3;
521
+ function validateDraft(raw) {
522
+ if (typeof raw !== "object" || raw === null) return null;
523
+ const draft = raw;
524
+ if (typeof draft.value !== "string") return null;
525
+ if (!Array.isArray(draft.tokens)) return null;
526
+ if (!Array.isArray(draft.attachmentIds)) return null;
527
+ for (const token of draft.tokens) {
528
+ if (typeof token !== "object" || token === null || typeof token.start !== "number" || typeof token.end !== "number" || typeof token.display !== "string" || // The one invariant that matters: ranges must project the display.
529
+ draft.value.substring(token.start, token.end) !== token.display) {
530
+ return null;
531
+ }
532
+ }
533
+ return {
534
+ value: draft.value,
535
+ tokens: draft.tokens,
536
+ attachmentIds: draft.attachmentIds,
537
+ updatedAt: typeof draft.updatedAt === "number" ? draft.updatedAt : 0
538
+ };
539
+ }
540
+ function createComposer(config = {}) {
541
+ const now = config.now ?? (() => Date.now());
542
+ const generateId$1 = config.generateId ?? generateId;
543
+ const onEvent = config.onEvent ?? (() => void 0);
544
+ const triggers = (config.triggers ?? []).map(resolveTriggerConfig);
545
+ const draftDebounceMs = config.draftDebounceMs ?? DEFAULT_DRAFT_DEBOUNCE_MS;
546
+ const typingSignalIntervalMs = config.typingSignalIntervalMs ?? DEFAULT_TYPING_SIGNAL_INTERVAL_MS;
547
+ const emojiTrigger = triggers.find((t) => t.symbol === ":") ?? null;
548
+ let value = config.initialValue ?? "";
549
+ let tokens = [...config.initialTokens ?? []];
550
+ let selection = { start: value.length, end: value.length };
551
+ let isComposing = false;
552
+ let isBusy = false;
553
+ let disabled = false;
554
+ let readOnly = false;
555
+ let error = null;
556
+ let attachments = [];
557
+ let mode = "compose";
558
+ let editingMessageId;
559
+ let preEditSnapshot = null;
560
+ let activeMatch = null;
561
+ let dismissed = [];
562
+ let clipShadow = null;
563
+ let lastTypingAt = Number.NEGATIVE_INFINITY;
564
+ let draftTimer = null;
565
+ let destroyed = false;
566
+ const listeners = /* @__PURE__ */ new Set();
567
+ if (config.draftStore && config.draftKey) {
568
+ try {
569
+ const draft = validateDraft(config.draftStore.read(config.draftKey));
570
+ if (draft) {
571
+ value = draft.value;
572
+ tokens = draft.tokens;
573
+ selection = { start: value.length, end: value.length };
574
+ }
575
+ } catch {
576
+ }
577
+ }
578
+ const suggestions = createSuggestionController({ emit: () => emit() });
579
+ function toActiveTriggerState(match) {
580
+ if (!match) return null;
581
+ return {
582
+ triggerId: match.trigger.id,
583
+ symbol: match.trigger.symbol,
584
+ symbolStart: match.symbolStart,
585
+ caret: match.caret,
586
+ query: match.query
587
+ };
588
+ }
589
+ function buildState() {
590
+ const counter = computeCounter(value, config.maxLength);
591
+ const overBudget = counter.remaining !== null && counter.remaining < 0;
592
+ return {
593
+ value,
594
+ selection,
595
+ isComposing,
596
+ isBusy,
597
+ disabled,
598
+ readOnly,
599
+ isEmpty: payloadFor(value).length === 0 && attachments.length === 0,
600
+ canSend: canSend({ text: value, attachments, disabled, readOnly, busy: isBusy }) && !overBudget,
601
+ error,
602
+ attachments: [...attachments],
603
+ tokens: [...tokens],
604
+ activeTrigger: toActiveTriggerState(activeMatch),
605
+ suggestion: destroyed ? CLOSED_SUGGESTION_STATE : suggestions.state,
606
+ counter,
607
+ mode,
608
+ editingMessageId
609
+ };
610
+ }
611
+ function emit() {
612
+ if (destroyed) return;
613
+ const snapshot = buildState();
614
+ for (const listener of listeners) listener(snapshot);
615
+ }
616
+ function shiftDismissedForEdit(editStart, editOldEnd, delta) {
617
+ dismissed = dismissed.map((d) => d.symbolStart >= editOldEnd ? { ...d, symbolStart: d.symbolStart + delta } : d).filter((d) => {
618
+ if (d.symbolStart >= editStart && d.symbolStart < editOldEnd) return false;
619
+ const trigger = triggers.find((t) => t.id === d.triggerId);
620
+ return trigger !== void 0 && value.startsWith(trigger.symbol, d.symbolStart);
621
+ });
622
+ }
623
+ function recomputeTriggers() {
624
+ const collapsed = selection.start === selection.end;
625
+ activeMatch = collapsed && !isComposing && !disabled && !readOnly ? detectActiveTrigger({
626
+ text: value,
627
+ caret: selection.start,
628
+ triggers,
629
+ isComposing,
630
+ dismissed,
631
+ tokenRanges: tokens
632
+ }) : null;
633
+ suggestions.sync(activeMatch);
634
+ }
635
+ function fireTypingSignal() {
636
+ const at = now();
637
+ if (at - lastTypingAt >= typingSignalIntervalMs) {
638
+ lastTypingAt = at;
639
+ onEvent({ type: "typing" });
640
+ }
641
+ }
642
+ function scheduleDraftWrite() {
643
+ if (!config.draftStore || !config.draftKey) return;
644
+ if (draftTimer !== null) clearTimeout(draftTimer);
645
+ draftTimer = setTimeout(() => {
646
+ draftTimer = null;
647
+ if (isComposing || destroyed) return;
648
+ config.draftStore?.write(config.draftKey, {
649
+ value,
650
+ tokens: [...tokens],
651
+ attachmentIds: attachments.map((a) => a.id),
652
+ updatedAt: now()
653
+ });
654
+ }, draftDebounceMs);
655
+ }
656
+ function cancelDraftWrite() {
657
+ if (draftTimer !== null) {
658
+ clearTimeout(draftTimer);
659
+ draftTimer = null;
660
+ }
661
+ }
662
+ function clearPersistedDraft() {
663
+ cancelDraftWrite();
664
+ if (config.draftStore && config.draftKey) config.draftStore.clear(config.draftKey);
665
+ }
666
+ function maybeCommitTypedEmoji() {
667
+ if (!emojiTrigger || selection.start !== selection.end) return;
668
+ const caretBefore = selection.start;
669
+ const hit = detectTypedEmoji(value, caretBefore);
670
+ if (!hit) return;
671
+ if (tokens.some((t) => t.start < caretBefore && hit.start < t.end)) return;
672
+ const token = {
673
+ triggerId: emojiTrigger.id,
674
+ symbol: emojiTrigger.symbol,
675
+ id: hit.shortcode,
676
+ label: hit.shortcode.slice(1, -1),
677
+ display: hit.unicode
678
+ };
679
+ const committed = commitTokenAt({
680
+ value,
681
+ tokens,
682
+ start: hit.start,
683
+ end: caretBefore,
684
+ token
685
+ });
686
+ const delta = committed.value.length - value.length;
687
+ value = committed.value;
688
+ tokens = committed.tokens;
689
+ selection = committed.selection;
690
+ shiftDismissedForEdit(hit.start, caretBefore, delta);
691
+ }
692
+ function mutateValue(newText, newSelection, opts = {}) {
693
+ const previousSelection = selection;
694
+ if (isComposing) {
695
+ const result2 = applyValueEdit({ oldValue: value, newValue: newText, tokens, newSelection });
696
+ value = result2.value;
697
+ tokens = result2.tokens;
698
+ selection = result2.selection;
699
+ emit();
700
+ return { applied: true, editStart: result2.edit?.start ?? newSelection.start };
701
+ }
702
+ const result = applyValueEdit({
703
+ oldValue: value,
704
+ newValue: newText,
705
+ tokens,
706
+ newSelection,
707
+ maxLength: config.maxLength
708
+ });
709
+ if (result.rejected) {
710
+ onEvent({ type: "edit-rejected", reason: "inside-token" });
711
+ selection = result.selection;
712
+ recomputeTriggers();
713
+ emit();
714
+ return { applied: false, editStart: 0 };
715
+ }
716
+ if (result.trimmed && opts.trimEventOnClamp !== false) {
717
+ onEvent({ type: "paste-trimmed" });
718
+ }
719
+ const editStart = result.edit?.start ?? newSelection.start;
720
+ value = result.value;
721
+ tokens = result.tokens;
722
+ selection = snapSelectionToTokens(tokens, result.selection, previousSelection);
723
+ if (result.edit) {
724
+ shiftDismissedForEdit(
725
+ result.edit.start,
726
+ result.edit.oldEnd,
727
+ result.edit.newEnd - result.edit.oldEnd
728
+ );
729
+ }
730
+ maybeCommitTypedEmoji();
731
+ recomputeTriggers();
732
+ if (!opts.programmatic) fireTypingSignal();
733
+ scheduleDraftWrite();
734
+ emit();
735
+ return { applied: true, editStart };
736
+ }
737
+ function buildSubmissionTokens() {
738
+ const plainText = payloadFor(value);
739
+ const leading = value.length - value.trimStart().length;
740
+ const serialized = serializeTokens(value, tokens);
741
+ return {
742
+ plainText,
743
+ tokens: serialized.tokens.map((t) => ({ ...t, start: t.start - leading, end: t.end - leading }))
744
+ };
745
+ }
746
+ function commitSuggestion(index) {
747
+ const match = activeMatch;
748
+ const menu = suggestions.state;
749
+ if (!match || !menu.isOpen) return false;
750
+ const item = menu.items[index ?? menu.activeIndex];
751
+ if (!item) return false;
752
+ const display = match.trigger.toDisplay(item);
753
+ if (config.maxLength !== void 0) {
754
+ const replacedSpan = value.slice(match.symbolStart, match.caret);
755
+ const nextLength = graphemeLength(value) - graphemeLength(replacedSpan) + graphemeLength(display);
756
+ if (nextLength > config.maxLength) {
757
+ onEvent({ type: "insert-rejected", reason: "max-length" });
758
+ emit();
759
+ return false;
760
+ }
761
+ }
762
+ const token = {
763
+ triggerId: match.trigger.id,
764
+ symbol: match.trigger.symbol,
765
+ id: item.id,
766
+ label: item.display,
767
+ display,
768
+ metadata: item.metadata
769
+ };
770
+ const committed = commitTokenAt({
771
+ value,
772
+ tokens,
773
+ start: match.symbolStart,
774
+ end: match.caret,
775
+ token
776
+ });
777
+ const delta = committed.value.length - value.length;
778
+ value = committed.value;
779
+ tokens = committed.tokens;
780
+ selection = committed.selection;
781
+ shiftDismissedForEdit(match.symbolStart, match.caret, delta);
782
+ suggestions.cancelDeferredDismiss();
783
+ activeMatch = null;
784
+ suggestions.sync(null);
785
+ scheduleDraftWrite();
786
+ emit();
787
+ return true;
788
+ }
789
+ function performSubmit() {
790
+ const counter = computeCounter(value, config.maxLength);
791
+ const overBudget = counter.remaining !== null && counter.remaining < 0;
792
+ if (!canSend({ text: value, attachments, disabled, readOnly, busy: isBusy }) || overBudget) {
793
+ return null;
794
+ }
795
+ const { plainText, tokens: submissionTokens } = buildSubmissionTokens();
796
+ if (config.validator) {
797
+ const verdict = config.validator(plainText, submissionTokens);
798
+ if (!verdict.isValid) {
799
+ error = verdict.reason ?? "Message failed validation";
800
+ emit();
801
+ return null;
802
+ }
803
+ }
804
+ const submission = {
805
+ plainText,
806
+ tokens: submissionTokens,
807
+ attachments: [...attachments],
808
+ replyToMessageId: config.replyToMessageId,
809
+ ...mode === "edit" ? { editingMessageId } : {}
810
+ };
811
+ value = "";
812
+ tokens = [];
813
+ attachments = [];
814
+ selection = { start: 0, end: 0 };
815
+ error = null;
816
+ activeMatch = null;
817
+ dismissed = [];
818
+ clipShadow = null;
819
+ mode = "compose";
820
+ editingMessageId = void 0;
821
+ preEditSnapshot = null;
822
+ suggestions.close();
823
+ clearPersistedDraft();
824
+ emit();
825
+ return submission;
826
+ }
827
+ const api = {
828
+ getState() {
829
+ return buildState();
830
+ },
831
+ subscribe(listener) {
832
+ listeners.add(listener);
833
+ return () => listeners.delete(listener);
834
+ },
835
+ setValue(text, sel, opts) {
836
+ if (destroyed || disabled) return;
837
+ if (readOnly) {
838
+ if (text === value && sel) api.setSelection(sel);
839
+ return;
840
+ }
841
+ const nextSelection = sel ?? { start: text.length, end: text.length };
842
+ mutateValue(text, nextSelection, { programmatic: opts?.programmatic });
843
+ },
844
+ setSelection(sel) {
845
+ if (destroyed || disabled) return;
846
+ const previous = selection;
847
+ selection = snapSelectionToTokens(tokens, {
848
+ start: Math.max(0, Math.min(sel.start, value.length)),
849
+ end: Math.max(0, Math.min(sel.end, value.length))
850
+ }, previous);
851
+ recomputeTriggers();
852
+ emit();
853
+ },
854
+ insertTextAtCursor(text) {
855
+ if (destroyed) return;
856
+ if (disabled) {
857
+ onEvent({ type: "insert-rejected", reason: "disabled" });
858
+ return;
859
+ }
860
+ if (readOnly) {
861
+ onEvent({ type: "insert-rejected", reason: "read-only" });
862
+ return;
863
+ }
864
+ if (isComposing) {
865
+ onEvent({ type: "insert-rejected", reason: "composing" });
866
+ return;
867
+ }
868
+ if (config.maxLength !== void 0) {
869
+ const range = expandRangeOverTokens(tokens, selection);
870
+ const base = graphemeLength(value.slice(0, range.start)) + graphemeLength(value.slice(range.end));
871
+ if (base + graphemeLength(text) > config.maxLength) {
872
+ onEvent({ type: "insert-rejected", reason: "max-length" });
873
+ return;
874
+ }
875
+ }
876
+ const nextText = value.slice(0, selection.start) + text + value.slice(selection.end);
877
+ const caret = selection.start + text.length;
878
+ mutateValue(nextText, { start: caret, end: caret });
879
+ },
880
+ setComposing(composing) {
881
+ if (destroyed || isComposing === composing) return;
882
+ isComposing = composing;
883
+ if (!composing) {
884
+ if (config.maxLength !== void 0 && graphemeLength(value) > config.maxLength) {
885
+ value = clampGraphemes(value, config.maxLength);
886
+ tokens = tokens.filter((t) => t.end <= value.length);
887
+ selection = {
888
+ start: Math.min(selection.start, value.length),
889
+ end: Math.min(selection.end, value.length)
890
+ };
891
+ }
892
+ maybeCommitTypedEmoji();
893
+ recomputeTriggers();
894
+ scheduleDraftWrite();
895
+ } else {
896
+ activeMatch = null;
897
+ suggestions.sync(null);
898
+ }
899
+ emit();
900
+ },
901
+ applyEnter({ shiftPressed }) {
902
+ if (destroyed || disabled || readOnly) return "noop";
903
+ const menu = suggestions.state;
904
+ if (menu.isOpen && !isComposing) {
905
+ if (menu.items.length > 0) {
906
+ return commitSuggestion() ? "committed-suggestion" : "noop";
907
+ }
908
+ return "noop";
909
+ }
910
+ if (!shouldSubmitOnEnter({ shiftPressed, isComposing })) {
911
+ return isComposing ? "noop" : "newline";
912
+ }
913
+ return performSubmit() ? "submitted" : "noop";
914
+ },
915
+ moveSuggestionNext() {
916
+ suggestions.moveNext();
917
+ emit();
918
+ },
919
+ moveSuggestionPrevious() {
920
+ suggestions.movePrevious();
921
+ emit();
922
+ },
923
+ setSuggestionActiveIndex(index) {
924
+ suggestions.setActiveIndex(index);
925
+ emit();
926
+ },
927
+ applySuggestion(index) {
928
+ commitSuggestion(index);
929
+ },
930
+ dismissSuggestion() {
931
+ if (activeMatch) {
932
+ dismissed.push({ triggerId: activeMatch.trigger.id, symbolStart: activeMatch.symbolStart });
933
+ activeMatch = null;
934
+ }
935
+ suggestions.close();
936
+ emit();
937
+ },
938
+ dismissSuggestionDeferred() {
939
+ suggestions.dismissDeferred(() => {
940
+ activeMatch = null;
941
+ emit();
942
+ });
943
+ },
944
+ retrySuggestions() {
945
+ suggestions.retry();
946
+ emit();
947
+ },
948
+ addAttachment(draft) {
949
+ if (destroyed) return null;
950
+ if (config.maxAttachments !== void 0 && attachments.length >= config.maxAttachments) {
951
+ onEvent({ type: "attachment-rejected", reason: "max-attachments", name: draft.name });
952
+ return null;
953
+ }
954
+ if (config.maxAttachmentSizeBytes !== void 0 && draft.sizeBytes !== void 0 && draft.sizeBytes > config.maxAttachmentSizeBytes) {
955
+ onEvent({ type: "attachment-rejected", reason: "max-size", name: draft.name });
956
+ return null;
957
+ }
958
+ if (config.acceptAttachment) {
959
+ const verdict = config.acceptAttachment(draft);
960
+ if (verdict !== true) {
961
+ onEvent({
962
+ type: "attachment-rejected",
963
+ reason: "not-accepted",
964
+ name: draft.name,
965
+ ...typeof verdict === "string" ? { detail: verdict } : {}
966
+ });
967
+ return null;
968
+ }
969
+ }
970
+ const id = draft.id ?? generateId$1("rfr-attachment");
971
+ attachments = [...attachments, { ...draft, id, status: draft.status ?? "pending" }];
972
+ scheduleDraftWrite();
973
+ emit();
974
+ return id;
975
+ },
976
+ updateAttachment(id, patch) {
977
+ if (destroyed) return;
978
+ attachments = attachments.map((a) => a.id === id ? { ...a, ...patch, id } : a);
979
+ emit();
980
+ },
981
+ removeAttachment(id) {
982
+ if (destroyed) return;
983
+ attachments = attachments.filter((a) => a.id !== id);
984
+ scheduleDraftWrite();
985
+ emit();
986
+ },
987
+ setBusy(busy) {
988
+ if (destroyed || isBusy === busy) return;
989
+ isBusy = busy;
990
+ emit();
991
+ },
992
+ setError(nextError) {
993
+ if (destroyed) return;
994
+ error = nextError;
995
+ emit();
996
+ },
997
+ setDisabled(nextDisabled) {
998
+ if (destroyed || disabled === nextDisabled) return;
999
+ disabled = nextDisabled;
1000
+ if (disabled) {
1001
+ activeMatch = null;
1002
+ suggestions.close();
1003
+ }
1004
+ emit();
1005
+ },
1006
+ setReadOnly(nextReadOnly) {
1007
+ if (destroyed || readOnly === nextReadOnly) return;
1008
+ readOnly = nextReadOnly;
1009
+ if (readOnly) {
1010
+ activeMatch = null;
1011
+ suggestions.close();
1012
+ }
1013
+ emit();
1014
+ },
1015
+ beginEdit({ value: editValue, tokens: editTokens, messageId }) {
1016
+ if (destroyed || disabled) return;
1017
+ preEditSnapshot = { value, tokens: [...tokens], selection, attachments: [...attachments] };
1018
+ mode = "edit";
1019
+ editingMessageId = messageId;
1020
+ value = editValue;
1021
+ tokens = [...editTokens ?? []];
1022
+ selection = { start: value.length, end: value.length };
1023
+ activeMatch = null;
1024
+ dismissed = [];
1025
+ suggestions.close();
1026
+ emit();
1027
+ },
1028
+ cancelEdit() {
1029
+ if (destroyed || mode !== "edit") return;
1030
+ const snapshot = preEditSnapshot;
1031
+ mode = "compose";
1032
+ editingMessageId = void 0;
1033
+ preEditSnapshot = null;
1034
+ if (snapshot) {
1035
+ value = snapshot.value;
1036
+ tokens = snapshot.tokens;
1037
+ selection = snapshot.selection;
1038
+ attachments = snapshot.attachments;
1039
+ }
1040
+ activeMatch = null;
1041
+ suggestions.close();
1042
+ emit();
1043
+ },
1044
+ copySelection() {
1045
+ return value.slice(selection.start, selection.end);
1046
+ },
1047
+ cutSelection() {
1048
+ if (destroyed || disabled || readOnly) return "";
1049
+ if (selection.start === selection.end) return "";
1050
+ const range = expandRangeOverTokens(tokens, selection);
1051
+ const text = value.slice(range.start, range.end);
1052
+ clipShadow = {
1053
+ text,
1054
+ tokens: tokens.filter((t) => t.start >= range.start && t.end <= range.end).map((t) => ({ ...t, start: t.start - range.start, end: t.end - range.start }))
1055
+ };
1056
+ const nextText = value.slice(0, range.start) + value.slice(range.end);
1057
+ mutateValue(nextText, { start: range.start, end: range.start });
1058
+ return text;
1059
+ },
1060
+ pasteText(text) {
1061
+ if (destroyed || disabled || readOnly) return;
1062
+ const shadow = clipShadow;
1063
+ const range = expandRangeOverTokens(tokens, selection);
1064
+ const nextText = value.slice(0, range.start) + text + value.slice(range.end);
1065
+ const caret = range.start + text.length;
1066
+ const before = value;
1067
+ mutateValue(nextText, { start: caret, end: caret }, { trimEventOnClamp: true });
1068
+ if (shadow && text === shadow.text && value === before.slice(0, range.start) + text + before.slice(range.end)) {
1069
+ const restored = shadow.tokens.map((t) => ({
1070
+ ...t,
1071
+ start: t.start + range.start,
1072
+ end: t.end + range.start
1073
+ }));
1074
+ tokens = [...tokens, ...restored].sort((a, b) => a.start - b.start);
1075
+ emit();
1076
+ }
1077
+ },
1078
+ submit() {
1079
+ if (destroyed) return null;
1080
+ return performSubmit();
1081
+ },
1082
+ reset() {
1083
+ if (destroyed) return;
1084
+ cancelDraftWrite();
1085
+ suggestions.close();
1086
+ value = config.initialValue ?? "";
1087
+ tokens = [...config.initialTokens ?? []];
1088
+ selection = { start: value.length, end: value.length };
1089
+ isComposing = false;
1090
+ isBusy = false;
1091
+ error = null;
1092
+ attachments = [];
1093
+ mode = "compose";
1094
+ editingMessageId = void 0;
1095
+ preEditSnapshot = null;
1096
+ activeMatch = null;
1097
+ dismissed = [];
1098
+ clipShadow = null;
1099
+ lastTypingAt = Number.NEGATIVE_INFINITY;
1100
+ recomputeTriggers();
1101
+ emit();
1102
+ },
1103
+ serialize() {
1104
+ return serializeTokens(value, tokens);
1105
+ },
1106
+ destroy() {
1107
+ if (destroyed) return;
1108
+ cancelDraftWrite();
1109
+ suggestions.destroy();
1110
+ listeners.clear();
1111
+ destroyed = true;
1112
+ }
1113
+ };
1114
+ return api;
1115
+ }
1116
+ var composerSurfaceVariants = cva({
1117
+ base: [
1118
+ "overflow-hidden rounded-2xl border shadow-sm",
1119
+ "transition-[box-shadow,border-color,background-color] duration-150 ease-out",
1120
+ "focus-within:ring-1 focus-within:ring-ring focus-within:shadow-md",
1121
+ "motion-reduce:transition-none"
1122
+ ].join(" "),
1123
+ variants: {
1124
+ surface: {
1125
+ outlined: "border-border bg-background focus-within:border-ring",
1126
+ filled: "border-border/50 bg-muted/50 focus-within:border-ring/70 focus-within:bg-background"
1127
+ },
1128
+ disabled: {
1129
+ true: "pointer-events-none opacity-60",
1130
+ false: ""
1131
+ },
1132
+ error: {
1133
+ true: "border-destructive/50",
1134
+ false: ""
1135
+ }
1136
+ },
1137
+ defaultVariants: {
1138
+ surface: "outlined",
1139
+ disabled: "false",
1140
+ error: "false"
1141
+ }
1142
+ });
1143
+ var composerFieldClass = "block w-full resize-none bg-transparent px-3.5 py-3 text-sm placeholder:text-muted-foreground focus:outline-none";
1144
+ var composerTrayClass = "flex flex-wrap gap-2 px-3 pt-3";
1145
+ var composerAttachmentChipVariants = cva({
1146
+ base: [
1147
+ "inline-flex items-center gap-1 rounded-md bg-muted px-2 py-0.5 text-xs",
1148
+ "origin-left transition-all duration-150 ease-out motion-reduce:transition-none"
1149
+ ].join(" "),
1150
+ variants: {
1151
+ status: {
1152
+ pending: "opacity-70",
1153
+ uploading: "opacity-70",
1154
+ ready: "",
1155
+ error: "text-destructive"
1156
+ },
1157
+ exiting: {
1158
+ true: "scale-90 opacity-0 motion-reduce:scale-100",
1159
+ false: "motion-safe:animate-fade-in-scale"
1160
+ }
1161
+ },
1162
+ defaultVariants: {
1163
+ status: "pending",
1164
+ exiting: "false"
1165
+ }
1166
+ });
1167
+ var composerTokenPillClass = "rounded bg-accent/40 px-0.5 text-accent-foreground";
1168
+ var composerMenuClass = "z-20 w-72 overflow-hidden rounded-xl border border-border bg-popover shadow-lg origin-bottom motion-safe:animate-fade-in-scale";
1169
+ var composerAccessoryPanelClass = "border-t border-border motion-safe:animate-fade-in";
1170
+ var composerAccessoryToggleVariants = cva({
1171
+ base: "flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
1172
+ variants: {
1173
+ active: {
1174
+ true: "bg-accent text-foreground",
1175
+ false: "text-muted-foreground"
1176
+ }
1177
+ },
1178
+ defaultVariants: {
1179
+ active: "false"
1180
+ }
1181
+ });
1182
+ var composerMenuItemVariants = cva({
1183
+ base: "flex w-full items-center gap-2 px-3 py-2 text-left text-sm",
1184
+ variants: {
1185
+ active: {
1186
+ true: "bg-accent",
1187
+ false: "hover:bg-accent/50"
1188
+ }
1189
+ },
1190
+ defaultVariants: {
1191
+ active: "false"
1192
+ }
1193
+ });
1194
+ var composerCounterVariants = cva({
1195
+ base: "text-xs tabular-nums",
1196
+ variants: {
1197
+ overLimit: {
1198
+ true: "font-medium text-destructive",
1199
+ false: "text-muted-foreground"
1200
+ }
1201
+ },
1202
+ defaultVariants: {
1203
+ overLimit: "false"
1204
+ }
1205
+ });
1206
+ var composerPrimaryActionVariants = cva({
1207
+ base: "flex h-9 w-9 items-center justify-center rounded-full transition-all duration-150 ease-out active:scale-95 motion-reduce:transition-none motion-reduce:active:scale-100 motion-safe:animate-scale-in",
1208
+ variants: {
1209
+ enabled: {
1210
+ true: "bg-primary text-primary-foreground hover:opacity-90",
1211
+ false: "bg-muted text-muted-foreground"
1212
+ }
1213
+ },
1214
+ defaultVariants: {
1215
+ enabled: "false"
1216
+ }
1217
+ });
1218
+ function createEmojiTrigger(options = {}) {
1219
+ const { id = "emoji", symbol = ":", maxResults = 8, minQueryLength = 1 } = options;
1220
+ return {
1221
+ id,
1222
+ symbol,
1223
+ // The committed token is the glyph itself, not `:name:`.
1224
+ toDisplay: (candidate) => candidate.metadata?.emoji ?? candidate.display,
1225
+ resolve: (query) => {
1226
+ if (query.length < minQueryLength) return [];
1227
+ return searchEmojis(query, maxResults).map((entry) => ({
1228
+ id: `${entry.shortcode}`,
1229
+ display: `${entry.emoji} :${entry.shortcode}:`,
1230
+ subtitle: entry.name,
1231
+ metadata: { emoji: entry.emoji, shortcode: entry.shortcode }
1232
+ }));
1233
+ }
1234
+ };
1235
+ }
1236
+
1237
+ // ../react-composer/dist/index.js
1238
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
1239
+ function useComposer(config = {}, init) {
1240
+ const configRef = React2.useRef(config);
1241
+ const initRef = React2.useRef(init);
1242
+ const coreRef = React2.useRef(null);
1243
+ const getCore = React2.useCallback(() => {
1244
+ if (coreRef.current === null) {
1245
+ const api = createComposer(configRef.current);
1246
+ initRef.current?.(api);
1247
+ coreRef.current = { api, snapshot: api.getState() };
1248
+ }
1249
+ return coreRef.current;
1250
+ }, []);
1251
+ const subscribe = React2.useCallback(
1252
+ (onStoreChange) => {
1253
+ const core = getCore();
1254
+ return core.api.subscribe((next) => {
1255
+ core.snapshot = next;
1256
+ onStoreChange();
1257
+ });
1258
+ },
1259
+ [getCore]
1260
+ );
1261
+ const getSnapshot = React2.useCallback(() => getCore().snapshot, [getCore]);
1262
+ const state = React2.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1263
+ React2.useEffect(
1264
+ () => () => {
1265
+ coreRef.current?.api.destroy();
1266
+ coreRef.current = null;
1267
+ },
1268
+ []
1269
+ );
1270
+ return { state, api: getCore().api };
1271
+ }
1272
+ var FIELD_LINE_HEIGHT = 1.5;
1273
+ var FIELD_VERTICAL_PADDING_REM = 1.5;
1274
+ var TRIMMED_NOTICE_HIDE_MS = 4e3;
1275
+ var CHIP_EXIT_MS = 150;
1276
+ function fieldHeightFor(lines) {
1277
+ return `calc(${lines * FIELD_LINE_HEIGHT}em + ${FIELD_VERTICAL_PADDING_REM}rem)`;
1278
+ }
1279
+ var DEFAULT_COMPOSER_STRINGS = {
1280
+ composerLabel: "Message composer",
1281
+ messageLabel: "Message",
1282
+ sendLabel: "Send",
1283
+ stopLabel: "Stop",
1284
+ attachLabel: "Attach a file",
1285
+ removeAttachmentLabel: (name) => `Remove attachment ${name}`,
1286
+ suggestionsLabel: "Suggestions",
1287
+ noMatchesLabel: (query) => `No matches for "${query}"`,
1288
+ loadingLabel: "Loading suggestions\u2026",
1289
+ retryLabel: "Retry",
1290
+ trimmedNotice: "Pasted text was trimmed to fit the length limit",
1291
+ counterLabel: (remaining) => `${remaining} characters remaining`,
1292
+ editingLabel: "Editing message",
1293
+ cancelEditLabel: "Cancel edit",
1294
+ accessoryPanelLabel: "Emoji and stickers",
1295
+ resultsAnnouncement: (count) => `${count} suggestions available`
1296
+ };
1297
+ function useLatestRef(value) {
1298
+ const ref = React2.useRef(value);
1299
+ ref.current = value;
1300
+ return ref;
1301
+ }
1302
+ function kindFromMime(mimeType) {
1303
+ if (mimeType.startsWith("image/")) return "image";
1304
+ if (mimeType.startsWith("video/")) return "video";
1305
+ if (mimeType.startsWith("audio/")) return "audio";
1306
+ return "file";
1307
+ }
1308
+ function segmentValue(value, tokens) {
1309
+ const segments = [];
1310
+ let cursor = 0;
1311
+ for (const token of tokens) {
1312
+ if (token.start > cursor) {
1313
+ segments.push({ key: `p${cursor}`, text: value.slice(cursor, token.start), isToken: false });
1314
+ }
1315
+ segments.push({ key: `t${token.start}`, text: value.slice(token.start, token.end), isToken: true });
1316
+ cursor = token.end;
1317
+ }
1318
+ if (cursor < value.length) {
1319
+ segments.push({ key: `p${cursor}`, text: value.slice(cursor), isToken: false });
1320
+ }
1321
+ return segments;
1322
+ }
1323
+ var iconSvgProps = {
1324
+ xmlns: "http://www.w3.org/2000/svg",
1325
+ viewBox: "0 0 24 24",
1326
+ width: 16,
1327
+ height: 16,
1328
+ fill: "none",
1329
+ stroke: "currentColor",
1330
+ strokeWidth: 2,
1331
+ strokeLinecap: "round",
1332
+ strokeLinejoin: "round",
1333
+ "aria-hidden": true
1334
+ };
1335
+ function IconArrowUp() {
1336
+ return /* @__PURE__ */ jsxs("svg", { ...iconSvgProps, children: [
1337
+ /* @__PURE__ */ jsx("path", { d: "M12 19V5" }),
1338
+ /* @__PURE__ */ jsx("path", { d: "m5 12 7-7 7 7" })
1339
+ ] });
1340
+ }
1341
+ function IconStop() {
1342
+ return /* @__PURE__ */ jsx("svg", { ...iconSvgProps, children: /* @__PURE__ */ jsx("rect", { x: 7, y: 7, width: 10, height: 10, rx: 1.5 }) });
1343
+ }
1344
+ function IconSmiley() {
1345
+ return /* @__PURE__ */ jsxs("svg", { ...iconSvgProps, children: [
1346
+ /* @__PURE__ */ jsx("circle", { cx: 12, cy: 12, r: 9 }),
1347
+ /* @__PURE__ */ jsx("path", { d: "M8 14s1.5 2 4 2 4-2 4-2" }),
1348
+ /* @__PURE__ */ jsx("path", { d: "M9 9h.01M15 9h.01" })
1349
+ ] });
1350
+ }
1351
+ var RefractionComposer = React2.forwardRef(
1352
+ function RefractionComposer2({
1353
+ value: valueProp,
1354
+ defaultValue,
1355
+ onChange,
1356
+ placeholder,
1357
+ disabledPlaceholder,
1358
+ minLines = 1,
1359
+ maxLines = 6,
1360
+ maxLength,
1361
+ maxAttachments,
1362
+ disabled = false,
1363
+ readOnly = false,
1364
+ busy = false,
1365
+ onStop,
1366
+ surface = "outlined",
1367
+ accessoryPanel,
1368
+ accessoryPanelOpen,
1369
+ defaultAccessoryPanelOpen = false,
1370
+ onAccessoryPanelToggle,
1371
+ autoFocus,
1372
+ dir,
1373
+ triggers,
1374
+ submitOnEnter,
1375
+ strings: stringsProp,
1376
+ leading,
1377
+ trailing,
1378
+ primaryAction,
1379
+ renderSuggestion,
1380
+ initialAttachments,
1381
+ draftStore,
1382
+ draftKey,
1383
+ validator,
1384
+ replyToMessageId,
1385
+ onSubmit,
1386
+ onEditLastRequested,
1387
+ onEditCancel,
1388
+ onTypingActivity,
1389
+ onAttachmentAdd,
1390
+ onAttachmentRejected,
1391
+ onEvent,
1392
+ apiRef,
1393
+ id,
1394
+ className,
1395
+ ...rest
1396
+ }, forwardedRef) {
1397
+ const strings = React2.useMemo(
1398
+ () => ({ ...DEFAULT_COMPOSER_STRINGS, ...stringsProp }),
1399
+ [stringsProp]
1400
+ );
1401
+ const onSubmitRef = useLatestRef(onSubmit);
1402
+ const onChangeRef = useLatestRef(onChange);
1403
+ const onStopRef = useLatestRef(onStop);
1404
+ const onEventRef = useLatestRef(onEvent);
1405
+ const onTypingActivityRef = useLatestRef(onTypingActivity);
1406
+ const onAttachmentAddRef = useLatestRef(onAttachmentAdd);
1407
+ const onAttachmentRejectedRef = useLatestRef(onAttachmentRejected);
1408
+ const onEditLastRequestedRef = useLatestRef(onEditLastRequested);
1409
+ const onEditCancelRef = useLatestRef(onEditCancel);
1410
+ const onAccessoryPanelToggleRef = useLatestRef(onAccessoryPanelToggle);
1411
+ const [trimmedNoticeVisible, setTrimmedNoticeVisible] = React2.useState(false);
1412
+ const trimmedTimerRef = React2.useRef(null);
1413
+ const [panelOpenInternal, setPanelOpenInternal] = React2.useState(defaultAccessoryPanelOpen);
1414
+ const panelControlled = accessoryPanelOpen !== void 0;
1415
+ const panelOpen = panelControlled ? accessoryPanelOpen : panelOpenInternal;
1416
+ const togglePanel = React2.useCallback(() => {
1417
+ const next = !(panelControlled ? accessoryPanelOpen : panelOpenInternal);
1418
+ if (!panelControlled) setPanelOpenInternal(next);
1419
+ onAccessoryPanelToggleRef.current?.(next);
1420
+ }, [panelControlled, accessoryPanelOpen, panelOpenInternal, onAccessoryPanelToggleRef]);
1421
+ const [exitingAttachments, setExitingAttachments] = React2.useState(
1422
+ () => /* @__PURE__ */ new Set()
1423
+ );
1424
+ const exitTimersRef = React2.useRef(/* @__PURE__ */ new Map());
1425
+ const configRef = React2.useRef(null);
1426
+ if (configRef.current === null) {
1427
+ configRef.current = {
1428
+ initialValue: valueProp ?? defaultValue ?? "",
1429
+ minLines,
1430
+ maxLines,
1431
+ triggers,
1432
+ onEvent: (event) => {
1433
+ if (event.type === "typing") onTypingActivityRef.current?.();
1434
+ if (event.type === "attachment-rejected") onAttachmentRejectedRef.current?.(event);
1435
+ if (event.type === "paste-trimmed") {
1436
+ setTrimmedNoticeVisible(true);
1437
+ if (trimmedTimerRef.current !== null) clearTimeout(trimmedTimerRef.current);
1438
+ trimmedTimerRef.current = setTimeout(() => {
1439
+ trimmedTimerRef.current = null;
1440
+ setTrimmedNoticeVisible(false);
1441
+ }, TRIMMED_NOTICE_HIDE_MS);
1442
+ }
1443
+ onEventRef.current?.(event);
1444
+ }
1445
+ };
1446
+ }
1447
+ configRef.current.maxLength = maxLength;
1448
+ configRef.current.maxAttachments = maxAttachments;
1449
+ configRef.current.validator = validator;
1450
+ configRef.current.replyToMessageId = replyToMessageId;
1451
+ configRef.current.draftStore = draftStore;
1452
+ configRef.current.draftKey = draftKey;
1453
+ const { state, api } = useComposer(configRef.current, (core) => {
1454
+ for (const draft of initialAttachments ?? []) core.addAttachment(draft);
1455
+ if (disabled) core.setDisabled(true);
1456
+ if (readOnly) core.setReadOnly(true);
1457
+ if (busy) core.setBusy(true);
1458
+ });
1459
+ React2.useEffect(() => {
1460
+ const exitTimers = exitTimersRef.current;
1461
+ return () => {
1462
+ if (trimmedTimerRef.current !== null) clearTimeout(trimmedTimerRef.current);
1463
+ for (const timer of exitTimers.values()) clearTimeout(timer);
1464
+ exitTimers.clear();
1465
+ };
1466
+ }, []);
1467
+ const textareaRef = React2.useRef(null);
1468
+ const highlightRef = React2.useRef(null);
1469
+ const rootRef = React2.useRef(null);
1470
+ const mergedTextareaRef = React2.useCallback(
1471
+ (node) => {
1472
+ textareaRef.current = node;
1473
+ if (typeof forwardedRef === "function") forwardedRef(node);
1474
+ else if (forwardedRef) forwardedRef.current = node;
1475
+ },
1476
+ [forwardedRef]
1477
+ );
1478
+ const idBase = React2.useRef(id ?? generateId("composer")).current;
1479
+ const listId = `${idBase}-listbox`;
1480
+ const optionId = (index) => `${idBase}-option-${index}`;
1481
+ React2.useEffect(() => {
1482
+ if (!apiRef) return;
1483
+ if (typeof apiRef === "function") {
1484
+ apiRef(api);
1485
+ return () => {
1486
+ apiRef(null);
1487
+ };
1488
+ }
1489
+ const mutableRef = apiRef;
1490
+ mutableRef.current = api;
1491
+ return () => {
1492
+ mutableRef.current = null;
1493
+ };
1494
+ }, [apiRef, api]);
1495
+ React2.useEffect(() => {
1496
+ api.setDisabled(disabled);
1497
+ }, [api, disabled]);
1498
+ React2.useEffect(() => {
1499
+ api.setReadOnly(readOnly);
1500
+ }, [api, readOnly]);
1501
+ React2.useEffect(() => {
1502
+ api.setBusy(busy);
1503
+ }, [api, busy]);
1504
+ React2.useEffect(() => {
1505
+ if (valueProp === void 0) return;
1506
+ const current = api.getState();
1507
+ if (current.disabled || current.readOnly || current.value === valueProp) return;
1508
+ api.setValue(
1509
+ valueProp,
1510
+ { start: valueProp.length, end: valueProp.length },
1511
+ { programmatic: true }
1512
+ );
1513
+ }, [api, valueProp, state.value]);
1514
+ const withValueChange = React2.useCallback(
1515
+ (mutate) => {
1516
+ const before = api.getState().value;
1517
+ const result = mutate();
1518
+ const after = api.getState().value;
1519
+ if (after !== before) onChangeRef.current?.(after);
1520
+ return result;
1521
+ },
1522
+ [api, onChangeRef]
1523
+ );
1524
+ const [coarsePointer, setCoarsePointer] = React2.useState(false);
1525
+ React2.useEffect(() => {
1526
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
1527
+ const query = window.matchMedia("(pointer: coarse)");
1528
+ const update = () => setCoarsePointer(query.matches);
1529
+ update();
1530
+ query.addEventListener?.("change", update);
1531
+ return () => query.removeEventListener?.("change", update);
1532
+ }, []);
1533
+ const submitEnabled = submitOnEnter ?? !coarsePointer;
1534
+ React2.useEffect(() => {
1535
+ const el = textareaRef.current;
1536
+ if (!el) return;
1537
+ if (el.value !== state.value) el.value = state.value;
1538
+ if (document.activeElement === el && (el.selectionStart !== state.selection.start || el.selectionEnd !== state.selection.end)) {
1539
+ el.setSelectionRange(state.selection.start, state.selection.end);
1540
+ }
1541
+ }, [state.value, state.selection.start, state.selection.end]);
1542
+ const readSelection = (el) => ({
1543
+ start: el.selectionStart ?? el.value.length,
1544
+ end: el.selectionEnd ?? el.value.length
1545
+ });
1546
+ const handleChange = (event) => {
1547
+ const el = event.currentTarget;
1548
+ withValueChange(() => api.setValue(el.value, readSelection(el)));
1549
+ };
1550
+ const handleSelect = (event) => {
1551
+ const el = event.currentTarget;
1552
+ const next = readSelection(el);
1553
+ const current = api.getState().selection;
1554
+ if (next.start !== current.start || next.end !== current.end) {
1555
+ api.setSelection(next);
1556
+ }
1557
+ };
1558
+ const submitNow = React2.useCallback(() => {
1559
+ const submission = withValueChange(() => api.submit());
1560
+ if (submission) onSubmitRef.current?.(submission);
1561
+ return submission !== null;
1562
+ }, [api, onSubmitRef, withValueChange]);
1563
+ const handleKeyDown = (event) => {
1564
+ const snapshot = api.getState();
1565
+ const menuOpen2 = snapshot.suggestion.isOpen && !snapshot.isComposing;
1566
+ const hasMenuItems = snapshot.suggestion.items.length > 0;
1567
+ if (menuOpen2) {
1568
+ if (event.key === "ArrowDown" && hasMenuItems) {
1569
+ event.preventDefault();
1570
+ api.moveSuggestionNext();
1571
+ return;
1572
+ }
1573
+ if (event.key === "ArrowUp" && hasMenuItems) {
1574
+ event.preventDefault();
1575
+ api.moveSuggestionPrevious();
1576
+ return;
1577
+ }
1578
+ if (event.key === "Tab" && hasMenuItems) {
1579
+ event.preventDefault();
1580
+ withValueChange(() => api.applySuggestion());
1581
+ return;
1582
+ }
1583
+ if (event.key === "Escape") {
1584
+ event.preventDefault();
1585
+ api.dismissSuggestion();
1586
+ return;
1587
+ }
1588
+ }
1589
+ if (event.key === "Escape" && !menuOpen2 && snapshot.mode === "edit") {
1590
+ event.preventDefault();
1591
+ withValueChange(() => api.cancelEdit());
1592
+ onEditCancelRef.current?.();
1593
+ return;
1594
+ }
1595
+ if (event.key === "ArrowUp" && !menuOpen2 && !snapshot.isComposing && snapshot.value === "" && onEditLastRequestedRef.current) {
1596
+ event.preventDefault();
1597
+ onEditLastRequestedRef.current();
1598
+ return;
1599
+ }
1600
+ if (event.key === "Enter") {
1601
+ if (menuOpen2) {
1602
+ event.preventDefault();
1603
+ withValueChange(() => api.applyEnter({ shiftPressed: event.shiftKey }));
1604
+ return;
1605
+ }
1606
+ if (snapshot.isComposing) return;
1607
+ if (event.shiftKey || !submitEnabled) return;
1608
+ event.preventDefault();
1609
+ if (snapshot.disabled || snapshot.readOnly) return;
1610
+ submitNow();
1611
+ }
1612
+ };
1613
+ const handleCompositionStart = () => api.setComposing(true);
1614
+ const handleCompositionEnd = () => withValueChange(() => api.setComposing(false));
1615
+ const handleCopy = (event) => {
1616
+ const text = api.copySelection();
1617
+ if (text === "") return;
1618
+ event.preventDefault();
1619
+ event.clipboardData.setData("text/plain", text);
1620
+ };
1621
+ const handleCut = (event) => {
1622
+ event.preventDefault();
1623
+ const text = withValueChange(() => api.cutSelection());
1624
+ if (text !== "") event.clipboardData.setData("text/plain", text);
1625
+ };
1626
+ const addFiles = React2.useCallback(
1627
+ (files) => {
1628
+ for (const file of Array.from(files)) {
1629
+ const previewUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function" ? URL.createObjectURL(file) : void 0;
1630
+ const attachmentId = api.addAttachment({
1631
+ kind: kindFromMime(file.type),
1632
+ name: file.name,
1633
+ mimeType: file.type || void 0,
1634
+ sizeBytes: file.size,
1635
+ previewUrl
1636
+ });
1637
+ if (attachmentId === null) {
1638
+ if (previewUrl !== void 0) URL.revokeObjectURL(previewUrl);
1639
+ continue;
1640
+ }
1641
+ const added = api.getState().attachments.find((a) => a.id === attachmentId);
1642
+ if (added) onAttachmentAddRef.current?.(added);
1643
+ }
1644
+ },
1645
+ [api, onAttachmentAddRef]
1646
+ );
1647
+ const releasePreview = (previewUrl) => {
1648
+ if (previewUrl !== void 0 && typeof URL !== "undefined" && typeof URL.revokeObjectURL === "function") {
1649
+ URL.revokeObjectURL(previewUrl);
1650
+ }
1651
+ };
1652
+ const removeAttachment = React2.useCallback(
1653
+ (id2, previewUrl) => {
1654
+ const finish = () => {
1655
+ api.removeAttachment(id2);
1656
+ releasePreview(previewUrl);
1657
+ exitTimersRef.current.delete(id2);
1658
+ setExitingAttachments((prev) => {
1659
+ if (!prev.has(id2)) return prev;
1660
+ const next = new Set(prev);
1661
+ next.delete(id2);
1662
+ return next;
1663
+ });
1664
+ };
1665
+ if (prefersReducedMotion() || exitTimersRef.current.has(id2)) {
1666
+ if (!exitTimersRef.current.has(id2)) finish();
1667
+ return;
1668
+ }
1669
+ setExitingAttachments((prev) => new Set(prev).add(id2));
1670
+ exitTimersRef.current.set(id2, setTimeout(finish, CHIP_EXIT_MS));
1671
+ },
1672
+ [api]
1673
+ );
1674
+ const handlePaste = (event) => {
1675
+ const files = event.clipboardData?.files;
1676
+ if (files && files.length > 0) {
1677
+ event.preventDefault();
1678
+ addFiles(files);
1679
+ return;
1680
+ }
1681
+ event.preventDefault();
1682
+ withValueChange(() => api.pasteText(event.clipboardData?.getData("text/plain") ?? ""));
1683
+ };
1684
+ const [dragActive, setDragActive] = React2.useState(false);
1685
+ const dragHasPayload = (event) => {
1686
+ const types = event.dataTransfer ? Array.from(event.dataTransfer.types ?? []) : [];
1687
+ return types.includes("Files") || types.includes("text/plain");
1688
+ };
1689
+ const handleDragOver = (event) => {
1690
+ if (!dragHasPayload(event)) return;
1691
+ event.preventDefault();
1692
+ setDragActive(true);
1693
+ };
1694
+ const handleDragLeave = () => setDragActive(false);
1695
+ const handleDrop = (event) => {
1696
+ event.preventDefault();
1697
+ setDragActive(false);
1698
+ const transfer = event.dataTransfer;
1699
+ if (!transfer) return;
1700
+ if (transfer.files && transfer.files.length > 0) {
1701
+ addFiles(transfer.files);
1702
+ return;
1703
+ }
1704
+ const text = transfer.getData("text/plain");
1705
+ if (text) withValueChange(() => api.pasteText(text));
1706
+ };
1707
+ const handleBlur = () => api.dismissSuggestionDeferred();
1708
+ const handleScroll = (event) => {
1709
+ if (highlightRef.current) {
1710
+ highlightRef.current.scrollTop = event.currentTarget.scrollTop;
1711
+ }
1712
+ };
1713
+ const hasTriggers = (triggers?.length ?? 0) > 0;
1714
+ const menuOpen = state.suggestion.isOpen;
1715
+ const visibleItems = state.suggestion.visibleItems;
1716
+ const activeIndex = state.suggestion.activeIndex;
1717
+ const [menuSide, setMenuSide] = React2.useState("above");
1718
+ const [menuMaxHeight, setMenuMaxHeight] = React2.useState(void 0);
1719
+ React2.useLayoutEffect(() => {
1720
+ if (!menuOpen) return;
1721
+ const measure = () => {
1722
+ const el = rootRef.current;
1723
+ if (el === null) return;
1724
+ const rect = el.getBoundingClientRect();
1725
+ const spaceAbove = rect.top;
1726
+ const spaceBelow = window.innerHeight - rect.bottom;
1727
+ const side = spaceAbove >= spaceBelow ? "above" : "below";
1728
+ setMenuSide(side);
1729
+ setMenuMaxHeight(Math.max(96, (side === "above" ? spaceAbove : spaceBelow) - 16));
1730
+ };
1731
+ measure();
1732
+ window.addEventListener("resize", measure);
1733
+ window.addEventListener("scroll", measure, true);
1734
+ return () => {
1735
+ window.removeEventListener("resize", measure);
1736
+ window.removeEventListener("scroll", measure, true);
1737
+ };
1738
+ }, [menuOpen]);
1739
+ const hasText = state.value.trim().length > 0;
1740
+ const effectivePlaceholder = state.disabled && disabledPlaceholder !== void 0 ? disabledPlaceholder : placeholder;
1741
+ const segments = React2.useMemo(
1742
+ () => segmentValue(state.value, state.tokens),
1743
+ [state.value, state.tokens]
1744
+ );
1745
+ const primaryContext = {
1746
+ hasText,
1747
+ canSend: state.canSend,
1748
+ busy: state.isBusy
1749
+ };
1750
+ const defaultPrimaryAction = state.isBusy ? /* @__PURE__ */ jsx(
1751
+ "button",
1752
+ {
1753
+ type: "button",
1754
+ "aria-label": strings.stopLabel,
1755
+ className: composerPrimaryActionVariants({ enabled: "true" }),
1756
+ onMouseDown: (event) => event.preventDefault(),
1757
+ onClick: () => onStopRef.current?.(),
1758
+ children: /* @__PURE__ */ jsx(IconStop, {})
1759
+ },
1760
+ "stop"
1761
+ ) : /* @__PURE__ */ jsx(
1762
+ "button",
1763
+ {
1764
+ type: "button",
1765
+ "aria-label": strings.sendLabel,
1766
+ disabled: !state.canSend,
1767
+ className: composerPrimaryActionVariants({ enabled: state.canSend ? "true" : "false" }),
1768
+ onMouseDown: (event) => event.preventDefault(),
1769
+ onClick: submitNow,
1770
+ children: /* @__PURE__ */ jsx(IconArrowUp, {})
1771
+ },
1772
+ "send"
1773
+ );
1774
+ const menuBody = () => {
1775
+ if (state.suggestion.loading) {
1776
+ return /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-sm text-muted-foreground", children: strings.loadingLabel });
1777
+ }
1778
+ if (state.suggestion.error !== null) {
1779
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2 text-sm text-destructive", children: [
1780
+ /* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: state.suggestion.error }),
1781
+ /* @__PURE__ */ jsx(
1782
+ "button",
1783
+ {
1784
+ type: "button",
1785
+ className: "font-medium underline",
1786
+ onMouseDown: (event) => event.preventDefault(),
1787
+ onClick: () => api.retrySuggestions(),
1788
+ children: strings.retryLabel
1789
+ }
1790
+ )
1791
+ ] });
1792
+ }
1793
+ if (visibleItems.length === 0) {
1794
+ return /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-sm text-muted-foreground", children: strings.noMatchesLabel(state.activeTrigger?.query ?? "") });
1795
+ }
1796
+ return visibleItems.map((candidate, index) => {
1797
+ const active = index === activeIndex;
1798
+ return /* @__PURE__ */ jsx(
1799
+ "button",
1800
+ {
1801
+ type: "button",
1802
+ role: "option",
1803
+ id: optionId(index),
1804
+ "aria-selected": active,
1805
+ className: composerMenuItemVariants({ active: active ? "true" : "false" }),
1806
+ onMouseEnter: () => api.setSuggestionActiveIndex(index),
1807
+ onMouseDown: (event) => event.preventDefault(),
1808
+ onClick: () => withValueChange(() => api.applySuggestion(index)),
1809
+ children: renderSuggestion ? renderSuggestion(candidate, { active, index }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1810
+ /* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: candidate.display }),
1811
+ candidate.subtitle !== void 0 && /* @__PURE__ */ jsx("span", { className: "truncate text-xs text-muted-foreground", children: candidate.subtitle })
1812
+ ] })
1813
+ },
1814
+ candidate.id
1815
+ );
1816
+ });
1817
+ };
1818
+ return /* @__PURE__ */ jsxs(
1819
+ "div",
1820
+ {
1821
+ ...rest,
1822
+ ref: rootRef,
1823
+ id: idBase,
1824
+ dir,
1825
+ role: "form",
1826
+ "aria-label": strings.composerLabel,
1827
+ className: cn("relative", className),
1828
+ onDragOver: handleDragOver,
1829
+ onDragLeave: handleDragLeave,
1830
+ onDrop: handleDrop,
1831
+ children: [
1832
+ menuOpen && /* @__PURE__ */ jsx(
1833
+ "div",
1834
+ {
1835
+ id: listId,
1836
+ role: "listbox",
1837
+ "aria-label": strings.suggestionsLabel,
1838
+ className: cn(
1839
+ composerMenuClass,
1840
+ "absolute start-0",
1841
+ menuSide === "above" ? "bottom-full mb-2" : "top-full mt-2 origin-top"
1842
+ ),
1843
+ style: menuMaxHeight !== void 0 ? { maxHeight: menuMaxHeight, overflowY: "auto" } : void 0,
1844
+ children: menuBody()
1845
+ }
1846
+ ),
1847
+ /* @__PURE__ */ jsxs(
1848
+ "div",
1849
+ {
1850
+ "data-dragover": dragActive ? "" : void 0,
1851
+ className: cn(
1852
+ composerSurfaceVariants({
1853
+ surface,
1854
+ disabled: state.disabled ? "true" : "false",
1855
+ error: state.error !== null ? "true" : "false"
1856
+ }),
1857
+ dragActive && "border-primary/60 shadow-md"
1858
+ ),
1859
+ children: [
1860
+ state.error !== null && /* @__PURE__ */ jsx(
1861
+ "div",
1862
+ {
1863
+ role: "alert",
1864
+ className: "flex items-center gap-2 border-b border-border bg-destructive/5 px-3 py-2 text-xs text-destructive",
1865
+ children: /* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: state.error })
1866
+ }
1867
+ ),
1868
+ state.mode === "edit" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 border-b border-border px-3 py-2 text-xs text-muted-foreground", children: [
1869
+ /* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: strings.editingLabel }),
1870
+ /* @__PURE__ */ jsx(
1871
+ "button",
1872
+ {
1873
+ type: "button",
1874
+ className: "font-medium underline",
1875
+ onClick: () => {
1876
+ withValueChange(() => api.cancelEdit());
1877
+ onEditCancelRef.current?.();
1878
+ },
1879
+ children: strings.cancelEditLabel
1880
+ }
1881
+ )
1882
+ ] }),
1883
+ trimmedNoticeVisible && /* @__PURE__ */ jsx("div", { role: "status", className: "px-3 pt-2 text-xs text-muted-foreground", children: strings.trimmedNotice }),
1884
+ state.attachments.length > 0 && /* @__PURE__ */ jsx("div", { className: composerTrayClass, children: state.attachments.map((attachment) => /* @__PURE__ */ jsxs(
1885
+ "span",
1886
+ {
1887
+ className: composerAttachmentChipVariants({
1888
+ status: attachment.status,
1889
+ exiting: exitingAttachments.has(attachment.id) ? "true" : "false"
1890
+ }),
1891
+ children: [
1892
+ attachment.name,
1893
+ /* @__PURE__ */ jsx(
1894
+ "button",
1895
+ {
1896
+ type: "button",
1897
+ "aria-label": strings.removeAttachmentLabel(attachment.name),
1898
+ className: "text-muted-foreground hover:text-destructive",
1899
+ onClick: () => removeAttachment(attachment.id, attachment.previewUrl),
1900
+ children: "\u2715"
1901
+ }
1902
+ )
1903
+ ]
1904
+ },
1905
+ attachment.id
1906
+ )) }),
1907
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
1908
+ /* @__PURE__ */ jsxs(
1909
+ "div",
1910
+ {
1911
+ ref: highlightRef,
1912
+ "aria-hidden": "true",
1913
+ className: cn(
1914
+ composerFieldClass,
1915
+ "pointer-events-none overflow-hidden whitespace-pre-wrap break-words text-transparent"
1916
+ ),
1917
+ style: {
1918
+ lineHeight: FIELD_LINE_HEIGHT,
1919
+ minHeight: fieldHeightFor(minLines),
1920
+ maxHeight: fieldHeightFor(maxLines)
1921
+ },
1922
+ children: [
1923
+ segments.map(
1924
+ (segment) => segment.isToken ? /* @__PURE__ */ jsx(
1925
+ "span",
1926
+ {
1927
+ "data-token": "",
1928
+ className: cn(composerTokenPillClass, "px-0 text-transparent"),
1929
+ children: /* @__PURE__ */ jsx("bdi", { children: segment.text })
1930
+ },
1931
+ segment.key
1932
+ ) : /* @__PURE__ */ jsx("span", { children: segment.text }, segment.key)
1933
+ ),
1934
+ "\u200B"
1935
+ ]
1936
+ }
1937
+ ),
1938
+ /* @__PURE__ */ jsx(
1939
+ "textarea",
1940
+ {
1941
+ ref: mergedTextareaRef,
1942
+ id: `${idBase}-input`,
1943
+ rows: minLines,
1944
+ value: state.value,
1945
+ placeholder: effectivePlaceholder,
1946
+ disabled: state.disabled,
1947
+ readOnly: state.readOnly,
1948
+ autoFocus,
1949
+ "aria-multiline": "true",
1950
+ "aria-label": strings.messageLabel,
1951
+ ...hasTriggers ? {
1952
+ "aria-autocomplete": "list",
1953
+ "aria-expanded": menuOpen,
1954
+ "aria-controls": listId,
1955
+ "aria-activedescendant": menuOpen && visibleItems.length > 0 ? optionId(activeIndex) : void 0
1956
+ } : {},
1957
+ className: cn(
1958
+ composerFieldClass,
1959
+ "absolute inset-0 h-full overflow-y-auto focus-visible:outline-none"
1960
+ ),
1961
+ style: { lineHeight: FIELD_LINE_HEIGHT, maxHeight: fieldHeightFor(maxLines) },
1962
+ onChange: handleChange,
1963
+ onSelect: handleSelect,
1964
+ onKeyDown: handleKeyDown,
1965
+ onCompositionStart: handleCompositionStart,
1966
+ onCompositionEnd: handleCompositionEnd,
1967
+ onCopy: handleCopy,
1968
+ onCut: handleCut,
1969
+ onPaste: handlePaste,
1970
+ onBlur: handleBlur,
1971
+ onScroll: handleScroll
1972
+ }
1973
+ )
1974
+ ] }),
1975
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5 px-2 pb-2", children: [
1976
+ accessoryPanel !== void 0 && /* @__PURE__ */ jsx(
1977
+ "button",
1978
+ {
1979
+ type: "button",
1980
+ "aria-label": strings.accessoryPanelLabel,
1981
+ "aria-expanded": panelOpen,
1982
+ "aria-controls": `${idBase}-accessory`,
1983
+ className: composerAccessoryToggleVariants({ active: panelOpen ? "true" : "false" }),
1984
+ onMouseDown: (event) => event.preventDefault(),
1985
+ onClick: togglePanel,
1986
+ children: /* @__PURE__ */ jsx(IconSmiley, {})
1987
+ }
1988
+ ),
1989
+ leading,
1990
+ /* @__PURE__ */ jsx("div", { className: "flex-1" }),
1991
+ state.counter.visible && state.counter.remaining !== null && /* @__PURE__ */ jsx(
1992
+ "div",
1993
+ {
1994
+ "aria-live": state.counter.overLimit ? "polite" : void 0,
1995
+ className: cn(
1996
+ composerCounterVariants({
1997
+ overLimit: state.counter.overLimit ? "true" : "false"
1998
+ }),
1999
+ "me-2"
2000
+ ),
2001
+ children: strings.counterLabel(state.counter.remaining)
2002
+ }
2003
+ ),
2004
+ trailing,
2005
+ primaryAction ? primaryAction(primaryContext) : defaultPrimaryAction
2006
+ ] }),
2007
+ accessoryPanel !== void 0 && panelOpen && /* @__PURE__ */ jsx("div", { id: `${idBase}-accessory`, className: composerAccessoryPanelClass, children: accessoryPanel })
2008
+ ]
2009
+ }
2010
+ ),
2011
+ /* @__PURE__ */ jsx("div", { "aria-live": "polite", className: "sr-only", children: menuOpen && !state.suggestion.loading && state.suggestion.error === null ? visibleItems.length === 0 ? strings.noMatchesLabel(state.activeTrigger?.query ?? "") : strings.resultsAnnouncement(visibleItems.length) : "" })
2012
+ ]
2013
+ }
2014
+ );
2015
+ }
2016
+ );
2017
+ export {
2018
+ DEFAULT_COMPOSER_STRINGS,
2019
+ RefractionComposer,
2020
+ composerAccessoryPanelClass,
2021
+ composerAccessoryToggleVariants,
2022
+ composerAttachmentChipVariants,
2023
+ composerCounterVariants,
2024
+ composerFieldClass,
2025
+ composerMenuClass,
2026
+ composerMenuItemVariants,
2027
+ composerPrimaryActionVariants,
2028
+ composerSurfaceVariants,
2029
+ composerTokenPillClass,
2030
+ composerTrayClass,
2031
+ createComposer,
2032
+ createEmojiTrigger,
2033
+ toMessageAttachment,
2034
+ useComposer
2035
+ };
2036
+ //# sourceMappingURL=react-composer.js.map