@zeyos/zx 5.5.0 → 5.7.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 (235) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/README.md +73 -7
  3. package/bin/zx-css.js +328 -0
  4. package/dist/types/components/account-menu/account-menu.d.ts +4 -2
  5. package/dist/types/components/activity-list/activity-list.d.ts +14 -8
  6. package/dist/types/components/agent-thread/ag-ui.d.ts +340 -0
  7. package/dist/types/components/agent-thread/agent-thread.d.ts +711 -0
  8. package/dist/types/components/agent-thread/ui-message-stream.d.ts +401 -0
  9. package/dist/types/components/app-sidebar/app-sidebar.d.ts +14 -8
  10. package/dist/types/components/approval-card/approval-card.d.ts +596 -0
  11. package/dist/types/components/avatar/avatar.d.ts +91 -4
  12. package/dist/types/components/block-view/block-view.d.ts +205 -0
  13. package/dist/types/components/breadcrumb/breadcrumb.d.ts +3 -3
  14. package/dist/types/components/calendar/calendar-model.d.ts +9 -2
  15. package/dist/types/components/calendar/calendar.d.ts +12 -4
  16. package/dist/types/components/chart/chart.d.ts +25 -13
  17. package/dist/types/components/code-editor/code-editor.d.ts +7 -2
  18. package/dist/types/components/composer/composer.d.ts +938 -0
  19. package/dist/types/components/composer/queue.d.ts +76 -0
  20. package/dist/types/components/copy/copy-button.d.ts +6 -4
  21. package/dist/types/components/copy/copy-input.d.ts +10 -6
  22. package/dist/types/components/datebox/date-range-box.d.ts +33 -0
  23. package/dist/types/components/datebox/placeholder.d.ts +7 -0
  24. package/dist/types/components/dock/dock.d.ts +12 -3
  25. package/dist/types/components/entity-ref/entity-ref.d.ts +5 -3
  26. package/dist/types/components/field-upload/field-upload.d.ts +3 -2
  27. package/dist/types/components/file-item/file-item.d.ts +3 -2
  28. package/dist/types/components/file-list/file-list.d.ts +14 -8
  29. package/dist/types/components/filter/filter-model.d.ts +31 -1
  30. package/dist/types/components/filter/filter.d.ts +20 -2
  31. package/dist/types/components/finder/finder.d.ts +14 -6
  32. package/dist/types/components/flag/flag.d.ts +99 -0
  33. package/dist/types/components/grid/grid.d.ts +1 -1
  34. package/dist/types/components/kanban-view/kanban-view.d.ts +8 -66
  35. package/dist/types/components/launcher/launcher.d.ts +2 -0
  36. package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +3 -2
  37. package/dist/types/components/number-field/number-field.d.ts +17 -6
  38. package/dist/types/components/prompt-starters/prompt-starters.d.ts +107 -0
  39. package/dist/types/components/prose/prose.d.ts +9 -6
  40. package/dist/types/components/questionnaire/conditions.d.ts +270 -0
  41. package/dist/types/components/questionnaire/items.d.ts +52 -30
  42. package/dist/types/components/questionnaire/questionnaire.d.ts +44 -4
  43. package/dist/types/components/rating/rating.d.ts +5 -3
  44. package/dist/types/components/run-status/run-status.d.ts +393 -0
  45. package/dist/types/components/run-trace/run-trace.d.ts +624 -0
  46. package/dist/types/components/select/country.d.ts +106 -0
  47. package/dist/types/components/select/field-adapter.d.ts +2 -1
  48. package/dist/types/components/select/locale.d.ts +102 -0
  49. package/dist/types/components/select/select.d.ts +41 -2
  50. package/dist/types/components/slider/slider.d.ts +1 -0
  51. package/dist/types/components/sort-control/sort-control.d.ts +7 -3
  52. package/dist/types/components/source-list/source-list.d.ts +179 -0
  53. package/dist/types/components/split-view/split-view.d.ts +5 -3
  54. package/dist/types/components/surface/catalog.d.ts +260 -0
  55. package/dist/types/components/surface/elicit.d.ts +81 -0
  56. package/dist/types/components/surface/mcp.d.ts +165 -0
  57. package/dist/types/components/surface/schema.d.ts +314 -0
  58. package/dist/types/components/surface/stream.d.ts +118 -0
  59. package/dist/types/components/surface/surface.d.ts +718 -0
  60. package/dist/types/components/surface/text.d.ts +277 -0
  61. package/dist/types/components/surface/validate.d.ts +339 -0
  62. package/dist/types/components/table/table.d.ts +55 -3
  63. package/dist/types/components/table/window.d.ts +203 -0
  64. package/dist/types/components/toolbar/toolbar.d.ts +10 -6
  65. package/dist/types/components/tooltip/tooltip.d.ts +2 -2
  66. package/dist/types/components/tree/tree.d.ts +20 -13
  67. package/dist/types/core/component.d.ts +10 -0
  68. package/dist/types/core/date.d.ts +8 -1
  69. package/dist/types/core/dom.d.ts +1 -0
  70. package/dist/types/core/http.d.ts +10 -0
  71. package/dist/types/core/i18n.d.ts +38 -0
  72. package/dist/types/core/messages.d.ts +479 -1
  73. package/dist/types/core/storage.d.ts +7 -2
  74. package/dist/types/elements/define.d.ts +21 -46
  75. package/dist/types/elements/definitions.d.ts +147 -0
  76. package/dist/types/elements/kit.d.ts +7 -0
  77. package/dist/types/elements/reflect.d.ts +6 -3
  78. package/dist/types/index.d.ts +18 -1
  79. package/dist/types/internal/agent-model.d.ts +587 -0
  80. package/dist/types/internal/date-locale.d.ts +7 -0
  81. package/dist/types/internal/highlight.d.ts +24 -0
  82. package/dist/types/internal/json-patch.d.ts +146 -0
  83. package/dist/types/internal/presence-loop.d.ts +148 -0
  84. package/dist/types/locales/de.d.ts +13 -0
  85. package/dist/types/locales/en.d.ts +2 -0
  86. package/dist/types/locales/index.d.ts +823 -0
  87. package/dist/types/zeyos/view.d.ts +8 -1
  88. package/dist/zx-zeyos.esm.js +20505 -18748
  89. package/dist/zx-zeyos.esm.min.js +5 -5
  90. package/dist/zx.core.css +1276 -0
  91. package/dist/zx.core.min.css +1 -0
  92. package/dist/zx.css +2424 -134
  93. package/dist/zx.esm.js +46167 -28468
  94. package/dist/zx.esm.min.js +40 -8
  95. package/dist/zx.global.js +46167 -28468
  96. package/dist/zx.global.min.js +40 -8
  97. package/dist/zx.layered.css +17302 -0
  98. package/dist/zx.layered.min.css +1 -0
  99. package/dist/zx.min.css +1 -1
  100. package/docs/agent-catalog.json +12501 -0
  101. package/docs/agent-surfaces.md +340 -0
  102. package/docs/api.json +2057 -166
  103. package/docs/llms.md +1458 -58
  104. package/docs/llms.txt +38 -8
  105. package/package.json +29 -6
  106. package/src/components/account-menu/account-menu.js +6 -3
  107. package/src/components/activity-item/activity-item.js +2 -1
  108. package/src/components/activity-list/activity-list.js +16 -10
  109. package/src/components/agent-thread/ag-ui.js +1439 -0
  110. package/src/components/agent-thread/agent-thread.css +417 -0
  111. package/src/components/agent-thread/agent-thread.js +1670 -0
  112. package/src/components/agent-thread/ui-message-stream.js +1281 -0
  113. package/src/components/app-sidebar/app-sidebar.js +18 -8
  114. package/src/components/approval-card/approval-card.css +289 -0
  115. package/src/components/approval-card/approval-card.js +1378 -0
  116. package/src/components/avatar/avatar.css +56 -1
  117. package/src/components/avatar/avatar.js +148 -26
  118. package/src/components/block-view/block-view.css +300 -0
  119. package/src/components/block-view/block-view.js +524 -0
  120. package/src/components/breadcrumb/breadcrumb.js +8 -5
  121. package/src/components/calendar/calendar-model.js +8 -2
  122. package/src/components/calendar/calendar.js +53 -18
  123. package/src/components/chart/chart.js +54 -23
  124. package/src/components/code-editor/code-editor.js +45 -8
  125. package/src/components/code-editor/field-adapter.js +1 -1
  126. package/src/components/composer/composer.css +482 -0
  127. package/src/components/composer/composer.js +1815 -0
  128. package/src/components/composer/queue.js +78 -0
  129. package/src/components/context-menu/context-menu.js +12 -1
  130. package/src/components/copy/copy-button.js +9 -7
  131. package/src/components/copy/copy-input.js +10 -6
  132. package/src/components/date-picker/date-picker.js +2 -1
  133. package/src/components/date-picker/date-range-picker.js +8 -7
  134. package/src/components/datebox/date-range-box.js +3 -9
  135. package/src/components/datebox/datebox.js +18 -21
  136. package/src/components/datebox/placeholder.js +18 -0
  137. package/src/components/dialog/dialog.js +1 -1
  138. package/src/components/dock/dock.js +34 -13
  139. package/src/components/entity-ref/entity-ref.js +16 -5
  140. package/src/components/field-upload/field-upload.js +81 -38
  141. package/src/components/file-item/file-item.js +70 -40
  142. package/src/components/file-list/file-list.js +15 -9
  143. package/src/components/filter/filter-model.js +46 -8
  144. package/src/components/filter/filter.css +3 -3
  145. package/src/components/filter/filter.js +29 -10
  146. package/src/components/filter-panel/filter-panel.js +13 -5
  147. package/src/components/finder/finder.js +50 -26
  148. package/src/components/flag/flag.css +40 -0
  149. package/src/components/flag/flag.js +177 -0
  150. package/src/components/form/form.js +1 -1
  151. package/src/components/grid/grid.js +22 -8
  152. package/src/components/kanban-view/kanban-view.js +51 -81
  153. package/src/components/launcher/launcher.js +17 -2
  154. package/src/components/list-toolbar/list-toolbar.js +2 -1
  155. package/src/components/master-panel/master-panel.js +1 -1
  156. package/src/components/menu-button/menu-button.js +4 -0
  157. package/src/components/message/message.js +3 -0
  158. package/src/components/multi-value-editor/multi-value-editor.js +10 -9
  159. package/src/components/navigation-bar/navigation-bar.js +3 -3
  160. package/src/components/number-field/number-field.js +29 -13
  161. package/src/components/prompt-starters/prompt-starters.css +91 -0
  162. package/src/components/prompt-starters/prompt-starters.js +206 -0
  163. package/src/components/prose/prose.js +14 -10
  164. package/src/components/questionnaire/conditions.js +666 -0
  165. package/src/components/questionnaire/items.js +150 -41
  166. package/src/components/questionnaire/questionnaire.js +126 -32
  167. package/src/components/rating/rating.js +5 -4
  168. package/src/components/run-status/run-status.css +208 -0
  169. package/src/components/run-status/run-status.js +782 -0
  170. package/src/components/run-trace/run-trace.css +443 -0
  171. package/src/components/run-trace/run-trace.js +1209 -0
  172. package/src/components/select/country.js +136 -0
  173. package/src/components/select/field-adapter.js +7 -2
  174. package/src/components/select/locale.js +219 -0
  175. package/src/components/select/select.css +20 -22
  176. package/src/components/select/select.js +94 -12
  177. package/src/components/sheet/sheet-stack.js +10 -1
  178. package/src/components/slider/slider.js +7 -2
  179. package/src/components/sort-control/sort-control.js +15 -5
  180. package/src/components/source-list/source-list.css +208 -0
  181. package/src/components/source-list/source-list.js +358 -0
  182. package/src/components/split-view/split-view.js +5 -3
  183. package/src/components/surface/catalog.js +1334 -0
  184. package/src/components/surface/elicit.js +107 -0
  185. package/src/components/surface/mcp.js +243 -0
  186. package/src/components/surface/schema.js +644 -0
  187. package/src/components/surface/stream.js +245 -0
  188. package/src/components/surface/surface.css +308 -0
  189. package/src/components/surface/surface.js +2291 -0
  190. package/src/components/surface/text.js +513 -0
  191. package/src/components/surface/validate.js +2218 -0
  192. package/src/components/tabbox/tabbox.js +9 -0
  193. package/src/components/table/table.css +63 -3
  194. package/src/components/table/table.js +167 -28
  195. package/src/components/table/window.js +317 -0
  196. package/src/components/toolbar/toolbar.js +12 -7
  197. package/src/components/tooltip/tooltip.css +2 -3
  198. package/src/components/tooltip/tooltip.js +32 -5
  199. package/src/components/tree/tree.js +53 -23
  200. package/src/core/component.js +25 -1
  201. package/src/core/date.js +62 -16
  202. package/src/core/dom.js +22 -2
  203. package/src/core/format.js +15 -13
  204. package/src/core/http.js +29 -20
  205. package/src/core/i18n.js +83 -10
  206. package/src/core/keyboard.js +79 -8
  207. package/src/core/messages.js +519 -2
  208. package/src/core/overlay-host.js +1 -0
  209. package/src/core/storage.js +59 -6
  210. package/src/elements/define.js +178 -130
  211. package/src/elements/definitions.js +229 -0
  212. package/src/elements/kit.js +444 -0
  213. package/src/elements/reflect.js +8 -3
  214. package/src/index.js +18 -1
  215. package/src/internal/agent-model.js +488 -0
  216. package/src/internal/date-locale.js +11 -0
  217. package/src/internal/highlight.js +104 -0
  218. package/src/internal/json-patch.js +405 -0
  219. package/src/internal/presence-loop.js +343 -0
  220. package/src/locales/de.js +911 -0
  221. package/src/locales/en.js +2 -0
  222. package/src/locales/index.js +7 -0
  223. package/src/zeyos/calendar.js +2 -1
  224. package/src/zeyos/form.js +2 -1
  225. package/src/zeyos/launcher.js +7 -6
  226. package/src/zeyos/module-bar.js +2 -1
  227. package/src/zeyos/schema.js +37 -23
  228. package/src/zeyos/select.js +4 -3
  229. package/src/zeyos/table.js +2 -13
  230. package/src/zeyos/view.js +57 -17
  231. package/styles/core.css +11 -0
  232. package/styles/tokens/semantic.css +1 -0
  233. package/styles/zeyos.css +2 -0
  234. package/styles/zx.css +11 -8
  235. package/styles/zx.layered.css +1 -0
@@ -0,0 +1,1815 @@
1
+ // @ts-check
2
+ import { Component } from '../../core/component.js';
3
+ import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
4
+ import { formatFileSize } from '../../core/format.js';
5
+ import { ICON_SIZE, icon } from '../../core/icons.js';
6
+ import { rovingTabindex } from '../../core/keyboard.js';
7
+ import { position } from '../../core/position.js';
8
+ import { storage } from '../../core/storage.js';
9
+ import { uid } from '../../core/util.js';
10
+ import { Dialog } from '../dialog/dialog.js';
11
+ import { keyLabels } from '../kbd/kbd.js';
12
+ import { Launcher } from '../launcher/launcher.js';
13
+ import {
14
+ addToQueue, emptyQueue, isQueueFull, queueLimit, removeFromQueue, takeNext
15
+ } from './queue.js';
16
+
17
+ /** @typedef {import('../launcher/launcher.js').LauncherItem} LauncherItem */
18
+
19
+ /**
20
+ * Something the `@` trigger can mention: an agent, a person, a record.
21
+ * @typedef {Object} MentionItem
22
+ * @property {string|number} id Stable identifier.
23
+ * @property {string} label Visible name; picking the item writes `@<label> ` into the text.
24
+ * @property {string} [description] Secondary line in the suggestion list.
25
+ * @property {string} [icon] Icon name drawn before the label.
26
+ */
27
+
28
+ /**
29
+ * Where mentions come from.
30
+ * @typedef {Object} MentionSource
31
+ * @property {string} [trigger='@'] Character that starts a mention.
32
+ * @property {MentionItem[]|((query: string) => MentionItem[]|Promise<MentionItem[]>)} items The
33
+ * items, filtered by the composer as the query changes, or a function that answers a query itself.
34
+ */
35
+
36
+ /**
37
+ * Something the message is about, shown as a removable chip above the text and sent with it.
38
+ * @typedef {Object} ContextChip
39
+ * @property {string} id Stable identifier.
40
+ * @property {string} label Visible label.
41
+ * @property {string} [icon] Icon name drawn before the label.
42
+ * @property {unknown} [ref] Application data handed back in `send`; the composer never reads it.
43
+ */
44
+
45
+ /**
46
+ * A further button in the composer's bar, after Attach and Commands: a search toggle, a model's
47
+ * parameters. The composer draws it and reports it; what it does is the application's.
48
+ * @typedef {Object} ComposerTool
49
+ * @property {string} id Stable identifier, handed back in `tool`.
50
+ * @property {string} label Accessible name and tooltip; the button shows only the icon.
51
+ * @property {string} icon Icon name: a built-in glyph or one the application registered.
52
+ * @property {boolean} [pressed] Makes the tool a toggle, drawn with `aria-pressed`. Leave it out for
53
+ * a plain button. The composer never changes it on its own: call `setToolPressed()`.
54
+ * @property {boolean} [disabled=false] Whether the tool takes no clicks.
55
+ * @property {boolean} [expanded] Makes the tool a disclosure, drawn with `aria-expanded`: a panel
56
+ * of settings it opens. Like `pressed`, the application sets it.
57
+ * @property {string} [controls] Id of what the tool opens, drawn as `aria-controls`.
58
+ */
59
+
60
+ /**
61
+ * @typedef {Object} ComposerToolDetail
62
+ * @property {string} id The tool's id.
63
+ * @property {ComposerTool} tool A copy of the tool as it stands, `pressed` included.
64
+ */
65
+
66
+ /**
67
+ * What `update()` changes in place. A key left out, or `undefined`, stays as it is.
68
+ * @typedef {Object} ComposerUpdate
69
+ * @property {string|null} [label] Accessible name; null resolves `composer.label` again.
70
+ * @property {string} [placeholder] Placeholder of the text; empty removes it.
71
+ * @property {string} [hint] Quiet text beside Send, as `setHint()`.
72
+ * @property {string} [note] Line under the composer, as `setNote()`.
73
+ * @property {'enter'|'mod+enter'} [submitKey] The key that sends.
74
+ * @property {string|null} [sendLabel] Visible text on Send; null or empty makes it icon-only.
75
+ * @property {boolean} [disabled] As `setDisabled()`.
76
+ * @property {boolean} [busy] As `setBusy()`.
77
+ */
78
+
79
+ /**
80
+ * @typedef {Object} ComposerSendDetail
81
+ * @property {string} text The message, trimmed.
82
+ * @property {File[]} files Attached files, in the order they were added.
83
+ * @property {MentionItem[]} mentions The picked mentions whose `@<label>` is still in the text.
84
+ * @property {ContextChip[]} context The context chips.
85
+ * @property {boolean} [queued] `true` on a message that waited in the queue. Absent otherwise.
86
+ */
87
+
88
+ /**
89
+ * A message waiting for the agent to finish. Everything it carries was taken when it was queued,
90
+ * so it is sent as it was written.
91
+ * @typedef {Object} QueuedMessage
92
+ * @property {string} id Stable identifier, for `removeQueued()`.
93
+ * @property {string} text The message, trimmed.
94
+ * @property {File[]} files Attached files, in the order they were added.
95
+ * @property {MentionItem[]} mentions The picked mentions whose `@<label>` is in the text.
96
+ * @property {ContextChip[]} context The context chips when it was queued.
97
+ */
98
+
99
+ /**
100
+ * @typedef {Object} ComposerQueueDetail
101
+ * @property {QueuedMessage} item The message added.
102
+ * @property {QueuedMessage[]} items The whole queue, in order, the message added included.
103
+ */
104
+
105
+ /**
106
+ * @typedef {Object} ComposerDequeueDetail
107
+ * @property {QueuedMessage} item The message that left the queue.
108
+ * @property {QueuedMessage[]} items What is left of the queue, in order.
109
+ * @property {'sent'|'removed'|'edited'|'cleared'} reason Why it left.
110
+ */
111
+
112
+ /**
113
+ * @typedef {Object} ComposerRemoveDetail
114
+ * @property {'file'|'context'} kind What was removed.
115
+ * @property {string} id The attachment's or chip's id.
116
+ * @property {File} [file] The removed file, for `kind: 'file'`.
117
+ * @property {ContextChip} [chip] The removed chip, for `kind: 'context'`.
118
+ */
119
+
120
+ /**
121
+ * @typedef {Object} ComposerOptions
122
+ * @property {string|null} [label=null] Accessible name of the text and of the group around it.
123
+ * Omitted resolves `composer.label`, English `Message`.
124
+ * @property {string} [placeholder=''] Placeholder of the text.
125
+ * @property {string} [value=''] Initial text. Without it, a saved draft is restored.
126
+ * @property {'enter'|'mod+enter'} [submitKey='enter'] `'enter'`: Enter sends and Shift+Enter breaks
127
+ * the line. `'mod+enter'`: Cmd+Enter (Ctrl+Enter elsewhere) sends and Enter breaks the line.
128
+ * @property {boolean} [busy=false] Whether an agent is working: Send becomes Stop.
129
+ * @property {boolean} [queue=false] Whether the send key holds a message back while the agent works.
130
+ * It is sent when the agent is no longer busy, one message each time busy ends, in order. The queue
131
+ * lives as long as the composer: it is not kept with the draft.
132
+ * @property {number} [queueLimit=10] Most messages that wait at once. At the limit the send key is
133
+ * refused, and the hint says why.
134
+ * @property {boolean} [disabled=false] Whether the composer takes no input.
135
+ * @property {boolean} [attachments=false] Whether files can be attached: an Attach button, paste,
136
+ * and drop.
137
+ * @property {string} [accept=''] File types accepted, in the `<input type="file">` syntax
138
+ * (`'image/*,.pdf'`). Empty accepts every file.
139
+ * @property {number} [maxFiles=10] Most files one message carries.
140
+ * @property {MentionSource|null} [mentions=null] Enables `@` mentions.
141
+ * @property {LauncherItem[]|null} [commands=null] Commands opened by `/` on an empty text, in a
142
+ * Launcher; an item with `items` opens a page of further commands.
143
+ * @property {ContextChip[]} [context=[]] Initial context chips.
144
+ * @property {string} [hint=''] Quiet text in the bar beside Send.
145
+ * @property {string} [note=''] Quiet line under the composer.
146
+ * @property {string|null} [draftKey=null] Key the unsent text is kept under (through `storage()`),
147
+ * restored on create and cleared on send.
148
+ * @property {number} [minRows=1] Rows the text never shrinks below, even when empty. Capped at
149
+ * `maxRows`.
150
+ * @property {number} [maxRows=10] Rows the text grows to before it scrolls.
151
+ * @property {{attach?: string, commands?: string}} [icons={}] Glyph names for the Attach and Commands
152
+ * buttons (a paperclip, a book) where the application registered its own.
153
+ * @property {ComposerTool[]} [tools=[]] Further icon buttons in the bar, after Attach and Commands.
154
+ * An entry without `id`, `label` or `icon` is left out, as is a repeated id.
155
+ * @property {string|null} [sendLabel=null] Visible text beside the Send glyph (`'Start task'`), which
156
+ * is then also its accessible name; while busy the button reads `composer.stop`. Null keeps Send
157
+ * icon-only. In a composer narrower than 24rem the text is visually hidden and stays the name.
158
+ * @property {Record<string, string>|Record<string, Record<string, string>>} [msg] Localized messages.
159
+ * @property {(event: CustomEvent<ComposerSendDetail>) => void} [onsend] Preventable send listener.
160
+ * @property {(event: CustomEvent<Record<string, never>>) => void} [onstop] Stop listener.
161
+ * @property {(event: CustomEvent<{text: string}>) => void} [oninput] Text listener.
162
+ * @property {(event: CustomEvent<{files: File[]}>) => void} [onattach] Preventable attach listener.
163
+ * @property {(event: CustomEvent<ComposerRemoveDetail>) => void} [onremove] Chip removal listener.
164
+ * @property {(event: CustomEvent<{item: MentionItem}>) => void} [onmention] Mention listener.
165
+ * @property {(event: CustomEvent<{item: LauncherItem}>) => void} [oncommand] Command listener.
166
+ * @property {(event: CustomEvent<ComposerToolDetail>) => void} [ontool] Tool listener.
167
+ * @property {(event: CustomEvent<ComposerQueueDetail>) => void} [onqueue] Listener for a message being
168
+ * queued.
169
+ * @property {(event: CustomEvent<ComposerDequeueDetail>) => void} [ondequeue] Listener for a message
170
+ * leaving the queue.
171
+ * @property {(event: CustomEvent<Record<string, never>>) => void} [onhistoryprevious] Listener for
172
+ * ArrowUp on an empty text.
173
+ */
174
+
175
+ const MESSAGES = Object.freeze({
176
+ 'composer.label': 'Message',
177
+ 'composer.send': 'Send',
178
+ 'composer.stop': 'Stop',
179
+ 'composer.attach': 'Attach files',
180
+ 'composer.remove': 'Remove %1',
181
+ 'composer.attachments': 'Attachments',
182
+ 'composer.context': 'Context',
183
+ 'composer.suggestions': 'Suggestions',
184
+ 'composer.match': '1 suggestion',
185
+ 'composer.matches': '%1 suggestions',
186
+ 'composer.commands': 'Commands',
187
+ 'composer.commandsPlaceholder': 'Search commands',
188
+ 'composer.drop': 'Drop files to attach',
189
+ 'composer.queue': 'Queued (%1)',
190
+ 'composer.queued': 'Queued; sends when the agent finishes',
191
+ 'composer.queueEdit': 'Edit',
192
+ 'composer.queueFile': '1 file',
193
+ 'composer.queueFiles': '%1 files',
194
+ 'composer.queueFull': 'Queue full (limit %1)',
195
+ 'composer.queueRemove': 'Remove',
196
+ 'composer.queueReplaceConfirm': 'Replace',
197
+ 'composer.queueReplaceMessage': 'The queued message takes its place in the message box.',
198
+ 'composer.queueReplaceTitle': 'Replace what you have written?'
199
+ });
200
+
201
+ /** Namespace the drafts are stored under. */
202
+ const DRAFT_NAMESPACE = 'composer';
203
+
204
+ /** Where a command copy given to the launcher keeps the application's own item. */
205
+ const COMMAND_SOURCE = Symbol('composer.command');
206
+
207
+ /**
208
+ * Where a mention starts and what has been typed of it: the text after the trigger up to the caret,
209
+ * when the trigger opens a word and the query holds no whitespace.
210
+ * @param {string} text The whole text.
211
+ * @param {number} caret Caret offset.
212
+ * @param {string} [trigger='@'] Character that starts a mention.
213
+ * @returns {{start: number, query: string}|null}
214
+ */
215
+ export function mentionQuery(text, caret, trigger = '@') {
216
+ const mark = String(trigger || '@');
217
+ const before = String(text ?? '').slice(0, Math.max(0, Number(caret) || 0));
218
+ const start = before.lastIndexOf(mark);
219
+ if (start < 0) return null;
220
+ if (start > 0 && !/\s/.test(before[start - 1])) return null;
221
+ const query = before.slice(start + mark.length);
222
+ if (/\s/.test(query)) return null;
223
+ return { start, query };
224
+ }
225
+
226
+ /**
227
+ * The items that match a mention query, best first: a label that starts with it, then a word in
228
+ * the label that does, then a label or description that contains it. Case and accents are ignored;
229
+ * items that rank the same keep their order. An empty query keeps every item.
230
+ * @param {MentionItem[]} items
231
+ * @param {string} query
232
+ * @returns {MentionItem[]}
233
+ */
234
+ export function filterMentions(items, query) {
235
+ const list = Array.isArray(items) ? items.filter(isMentionItem) : [];
236
+ const needle = fold(query);
237
+ if (!needle) return list;
238
+ return list
239
+ .map((item, order) => ({ item, order, rank: mentionRank(item, needle) }))
240
+ .filter((entry) => entry.rank < 4)
241
+ .sort((a, b) => a.rank - b.rank || a.order - b.order)
242
+ .map((entry) => entry.item);
243
+ }
244
+
245
+ /**
246
+ * The picked mentions whose `@<label>` is still in the text, each once.
247
+ * @param {string} text
248
+ * @param {MentionItem[]} mentions Mentions in the order they were picked.
249
+ * @param {string} [trigger='@']
250
+ * @returns {MentionItem[]}
251
+ */
252
+ export function mentionsInText(text, mentions, trigger = '@') {
253
+ const source = String(text ?? '');
254
+ const seen = new Set();
255
+ return (Array.isArray(mentions) ? mentions : []).filter((item) => {
256
+ if (!isMentionItem(item)) return false;
257
+ const key = String(item.id);
258
+ if (seen.has(key) || !source.includes(`${trigger}${item.label}`)) return false;
259
+ seen.add(key);
260
+ return true;
261
+ });
262
+ }
263
+
264
+ /**
265
+ * Whether a key press sends. A press during an IME composition never does.
266
+ * @param {{key: string, shiftKey?: boolean, metaKey?: boolean, ctrlKey?: boolean, altKey?: boolean,
267
+ * isComposing?: boolean, keyCode?: number}} event Key event, or its fields.
268
+ * @param {'enter'|'mod+enter'} [submitKey='enter']
269
+ * @param {{apple?: boolean}} [platform] `apple`: whether Mod is Cmd (otherwise Ctrl). Read from the
270
+ * browser when omitted.
271
+ * @returns {boolean}
272
+ */
273
+ export function isSubmitKey(event, submitKey = 'enter', { apple = isApplePlatform() } = {}) {
274
+ if (!event || event.key !== 'Enter') return false;
275
+ // 229 is the key code a browser reports for a key the input method is still processing.
276
+ if (event.isComposing || event.keyCode === 229) return false;
277
+ if (event.shiftKey || event.altKey) return false;
278
+ if (submitKey === 'mod+enter') {
279
+ return apple
280
+ ? Boolean(event.metaKey) && !event.ctrlKey
281
+ : Boolean(event.ctrlKey) && !event.metaKey;
282
+ }
283
+ return true;
284
+ }
285
+
286
+ /**
287
+ * Whether a file matches an `accept` list in the `<input type="file">` syntax: extensions
288
+ * (`.pdf`), whole MIME types (`application/json`), and MIME groups (`image/*`).
289
+ * @param {{name?: string, type?: string}} file
290
+ * @param {string} [accept='']
291
+ * @returns {boolean}
292
+ */
293
+ export function acceptsFile(file, accept = '') {
294
+ const tokens = String(accept ?? '').split(',').map((token) => token.trim().toLowerCase()).filter(Boolean);
295
+ if (!tokens.length) return true;
296
+ const name = String(file?.name ?? '').toLowerCase();
297
+ const type = String(file?.type ?? '').toLowerCase();
298
+ return tokens.some((token) => {
299
+ if (token.startsWith('.')) return name.endsWith(token);
300
+ if (token.endsWith('/*')) return type.startsWith(token.slice(0, -1));
301
+ return type === token;
302
+ });
303
+ }
304
+
305
+ /**
306
+ * The rows the text spans at least and at most: whole numbers of one or more, the least never above
307
+ * the most.
308
+ * @param {number} [minRows=1]
309
+ * @param {number} [maxRows=10]
310
+ * @returns {{min: number, max: number}}
311
+ */
312
+ export function rowRange(minRows = 1, maxRows = 10) {
313
+ const max = Math.max(1, Math.floor(Number(maxRows) || 1));
314
+ const min = Math.min(max, Math.max(1, Math.floor(Number(minRows) || 1)));
315
+ return { min, max };
316
+ }
317
+
318
+ /**
319
+ * The height an auto-growing text area takes for its content: at least `minRows` lines, at most
320
+ * `maxRows`, scrolling beyond that.
321
+ * @param {number} scrollHeight The content height, padding included (`textarea.scrollHeight`).
322
+ * @param {{lineHeight: number, padding?: number, border?: number, minRows?: number, maxRows?: number}} metrics
323
+ * Line height and the block padding and border, in pixels.
324
+ * @returns {{height: number, scrolls: boolean}} The border-box height, and whether the content
325
+ * overflows it.
326
+ */
327
+ export function autosizeHeight(scrollHeight, { lineHeight, padding = 0, border = 0, minRows = 1, maxRows = 10 }) {
328
+ const line = Number(lineHeight) > 0 ? Number(lineHeight) : 20;
329
+ const { min, max } = rowRange(minRows, maxRows);
330
+ const most = max * line + padding;
331
+ const content = Math.min(most, Math.max(min * line + padding, Number(scrollHeight) || 0));
332
+ return { height: Math.ceil(content + border), scrolls: Number(scrollHeight) > most + 1 };
333
+ }
334
+
335
+ /**
336
+ * The bar's extra tools as the composer draws them: entries without an `id`, a non-empty `label`
337
+ * or an `icon` are left out, a repeated id keeps its first entry, `id`, `label` and `icon` become
338
+ * strings, `disabled` a boolean, and `pressed` stays only when it is a boolean. Any other field the
339
+ * application put on a tool is kept, and handed back in `tool`.
340
+ * @param {unknown} tools
341
+ * @returns {ComposerTool[]}
342
+ */
343
+ export function normalizeTools(tools) {
344
+ /** @type {ComposerTool[]} */
345
+ const list = [];
346
+ const seen = new Set();
347
+ for (const entry of Array.isArray(tools) ? tools : []) {
348
+ if (!entry || typeof entry !== 'object') continue;
349
+ const tool = /** @type {Partial<ComposerTool> & Record<string, unknown>} */ (entry);
350
+ const id = tool.id == null ? '' : String(tool.id);
351
+ const label = tool.label == null ? '' : String(tool.label).trim();
352
+ const glyph = tool.icon == null ? '' : String(tool.icon);
353
+ if (!id || !label || !glyph || seen.has(id)) continue;
354
+ seen.add(id);
355
+ const { pressed, ...rest } = tool;
356
+ /** @type {ComposerTool} */
357
+ const normalized = { ...rest, id, label, icon: glyph, disabled: Boolean(tool.disabled) };
358
+ if (typeof pressed === 'boolean') normalized.pressed = pressed;
359
+ list.push(normalized);
360
+ }
361
+ return list;
362
+ }
363
+
364
+ /**
365
+ * A message box for talking to an agent: a text that grows with what is written, Send (Stop while
366
+ * the agent works), attachments, `@` mentions, `/` commands, and context chips. It keeps nothing
367
+ * but the unsent message: sending hands the text, files, mentions and context to the application,
368
+ * which owns the conversation. With `queue`, a message written while the agent works waits here
369
+ * until it is no longer busy.
370
+ *
371
+ * @fires Composer#send
372
+ * @fires Composer#stop
373
+ * @fires Composer#input
374
+ * @fires Composer#attach
375
+ * @fires Composer#remove
376
+ * @fires Composer#mention
377
+ * @fires Composer#command
378
+ * @fires Composer#tool
379
+ * @fires Composer#queue
380
+ * @fires Composer#dequeue
381
+ * @fires Composer#historyprevious
382
+ * @extends {Component<ComposerOptions>}
383
+ */
384
+ export class Composer extends Component {
385
+ static cssName = 'composer';
386
+
387
+ /** @type {Readonly<ComposerOptions>} */
388
+ static defaults = {
389
+ label: null,
390
+ placeholder: '',
391
+ value: '',
392
+ submitKey: 'enter',
393
+ busy: false,
394
+ queue: false,
395
+ queueLimit: 10,
396
+ disabled: false,
397
+ attachments: false,
398
+ accept: '',
399
+ maxFiles: 10,
400
+ mentions: null,
401
+ commands: null,
402
+ context: [],
403
+ hint: '',
404
+ note: '',
405
+ draftKey: null,
406
+ minRows: 1,
407
+ maxRows: 10,
408
+ icons: {},
409
+ tools: [],
410
+ sendLabel: null,
411
+ msg: MESSAGES
412
+ };
413
+
414
+ /** @returns {HTMLElement} */
415
+ render() {
416
+ const created = !this.el;
417
+ const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
418
+ this.el = root;
419
+ this._original = created ? null : snapshotTarget(root);
420
+ if (!created) root.replaceChildren();
421
+
422
+ const options = this.options;
423
+ /** @type {{id: string, file: File}[]} */
424
+ this._files = [];
425
+ /** @type {ContextChip[]} */
426
+ this._context = [];
427
+ /** @type {MentionItem[]} */
428
+ this._mentions = [];
429
+ /** @type {{start: number, end: number, items: MentionItem[], index: number}|null} */
430
+ this._mention = null;
431
+ this._mentionSequence = 0;
432
+ /** @type {import('../../core/position.js').PositionController|null} */
433
+ this._position = null;
434
+ /** @type {Launcher|null} */
435
+ this._launcher = null;
436
+ this._announced = '';
437
+ this._busy = Boolean(options.busy);
438
+ this._disabled = Boolean(options.disabled);
439
+ this._destroyed = false;
440
+ this._width = 0;
441
+ /** What the Send button last drew: mode, send key and label, so it redraws only on a change. */
442
+ this._sendDrawn = '';
443
+ /** @type {QueuedMessage[]} Session state: never saved with the draft. */
444
+ this._queue = [];
445
+ this._queueLimit = queueLimit(options.queueLimit);
446
+ /** Whether the send key was refused at the limit, which the hint then says. */
447
+ this._queueRefused = false;
448
+ /** @type {{destroy: () => void}[]} The keyboard of each queued row. */
449
+ this._queueRoving = [];
450
+ /** Whether a queued message is being sent, and whether busy ended again meanwhile. */
451
+ this._sendingQueued = false;
452
+ this._busyEndedAgain = false;
453
+ /** The application's hint, which `_syncHint()` shows unless the queue has something to say. */
454
+ this._hint = String(options.hint ?? '');
455
+ this._mentionSource = normalizeMentionSource(options.mentions);
456
+ this._commands = Array.isArray(options.commands) && options.commands.length ? options.commands : null;
457
+ this._draft = options.draftKey ? storage(DRAFT_NAMESPACE) : null;
458
+ if (this._draft) this._draft.migrateLegacy([String(options.draftKey)]);
459
+ this._tools = normalizeTools(options.tools);
460
+ this._sendLabel = sendLabelText(options.sendLabel);
461
+ this._rows = rowRange(options.minRows, Number(options.maxRows) || 10);
462
+
463
+ const label = this._labelText(options.label);
464
+ const listId = uid('zx-composer-suggestions');
465
+ const noteId = uid('zx-composer-note');
466
+ /** @type {'enter'|'mod+enter'} */
467
+ this._submitKey = submitKeyOf(options.submitKey);
468
+
469
+ const input = /** @type {HTMLTextAreaElement} */ (h('textarea', {
470
+ ref: 'input',
471
+ class: 'zx-composer__input',
472
+ rows: this._rows.min,
473
+ ariaLabel: label,
474
+ ariaDescribedby: options.note ? noteId : null,
475
+ placeholder: options.placeholder || null,
476
+ spellcheck: true
477
+ }));
478
+ this._input = input;
479
+ const context = h('ul', {
480
+ ref: 'context', class: 'zx-composer__chips', dataset: { kind: 'context' },
481
+ ariaLabel: this.msg('composer.context'), hidden: true
482
+ });
483
+ const files = h('ul', {
484
+ ref: 'files', class: 'zx-composer__chips', dataset: { kind: 'file' },
485
+ ariaLabel: this.msg('composer.attachments'), hidden: true
486
+ });
487
+ const fileInput = options.attachments ? /** @type {HTMLInputElement} */ (h('input', {
488
+ ref: 'fileInput', class: 'zx-composer__file-input', type: 'file', multiple: true,
489
+ accept: options.accept || null, hidden: true, tabindex: '-1'
490
+ })) : null;
491
+ const glyphs = { attach: 'plus', commands: 'list', ...(options.icons ?? {}) };
492
+ const attach = options.attachments ? iconButton(glyphs.attach, this.msg('composer.attach'), 'attach') : null;
493
+ const commands = this._commands ? iconButton(glyphs.commands, this.msg('composer.commands'), 'commands') : null;
494
+ commands?.setAttribute('aria-keyshortcuts', '/');
495
+ commands?.setAttribute('aria-haspopup', 'dialog');
496
+ const tools = h('span', { ref: 'tools', class: 'zx-composer__tools', hidden: true });
497
+ const send = /** @type {HTMLButtonElement} */ (h('button', {
498
+ ref: 'send', type: 'button', class: 'zx-icon-btn zx-composer__send'
499
+ }));
500
+ const hint = h('span', { ref: 'hint', class: 'zx-composer__hint', hidden: !options.hint }, String(options.hint ?? ''));
501
+ const queueLabelId = uid('zx-composer-queue');
502
+ const queue = options.queue ? h('div', { ref: 'queue', class: 'zx-composer__queue', hidden: true },
503
+ h('span', { ref: 'queueLabel', class: 'zx-composer__queue-label', id: queueLabelId }),
504
+ h('ol', { ref: 'queueList', class: 'zx-composer__queue-list', 'aria-labelledby': queueLabelId })) : null;
505
+ const frame = h('div', { ref: 'frame', class: 'zx-composer__frame' },
506
+ queue,
507
+ context,
508
+ files,
509
+ input,
510
+ h('div', { class: 'zx-composer__bar' },
511
+ attach, fileInput, commands, tools, hint,
512
+ h('span', { class: 'zx-composer__spacer' }),
513
+ send),
514
+ options.attachments
515
+ ? h('div', { class: 'zx-composer__drop', ariaHidden: 'true' }, icon('upload'), this.msg('composer.drop'))
516
+ : null);
517
+ const list = h('div', {
518
+ ref: 'list', class: 'zx-composer__suggestions', id: listId, role: 'listbox',
519
+ ariaLabel: this.msg('composer.suggestions'), hidden: true
520
+ });
521
+ const status = h('div', { ref: 'status', class: 'zx-composer__status', role: 'status', ariaLive: 'polite' });
522
+ const note = h('p', { ref: 'note', class: 'zx-composer__note', id: noteId, hidden: !options.note }, String(options.note ?? ''));
523
+
524
+ root.setAttribute('role', 'group');
525
+ root.setAttribute('aria-label', label);
526
+ root.append(...[frame, note, list, status].filter((node) => node !== null));
527
+
528
+ for (const chip of Array.isArray(options.context) ? options.context : []) this._putContext(chip);
529
+ const initial = typeof options.value === 'string' && options.value
530
+ ? options.value
531
+ : (this._draft ? String(this._draft.get(String(options.draftKey), '') ?? '') : '');
532
+ input.value = initial;
533
+ this._syncState();
534
+ this._syncSend();
535
+
536
+ this.listen(input, 'input', () => this._onInput());
537
+ this.listen(input, 'keydown', (event) => this._onKeydown(/** @type {KeyboardEvent} */ (event)));
538
+ this.listen(input, 'keyup', (event) => {
539
+ if (['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(/** @type {KeyboardEvent} */ (event).key)) this._updateMentions();
540
+ });
541
+ this.listen(input, 'click', () => this._updateMentions());
542
+ this.listen(input, 'blur', () => this._closeMentions());
543
+ this.listen(input, 'paste', (event) => this._onPaste(/** @type {ClipboardEvent} */ (event)));
544
+ this.listen(send, 'click', () => {
545
+ if (this._busy) this._stop();
546
+ else this._send();
547
+ });
548
+ if (attach && fileInput) {
549
+ this.listen(attach, 'click', () => fileInput.click());
550
+ this.listen(fileInput, 'change', () => {
551
+ const picked = Array.from(fileInput.files ?? []);
552
+ fileInput.value = '';
553
+ this._addFiles(picked, true);
554
+ input.focus();
555
+ });
556
+ }
557
+ if (commands) this.listen(commands, 'click', () => this._openCommands());
558
+ this.listen(tools, 'click', (event) => this._onToolClick(/** @type {MouseEvent} */ (event)));
559
+ this.listen(frame, 'click', (event) => this._onChipClick(/** @type {MouseEvent} */ (event)));
560
+ if (queue) {
561
+ this.listen(this.refs.queueList, 'click', (event) => this._onQueueClick(/** @type {MouseEvent} */ (event)));
562
+ this.listen(this.refs.queueList, 'keydown', (event) => this._onQueueKeydown(/** @type {KeyboardEvent} */ (event)));
563
+ }
564
+ // The suggestions keep the focus in the text: a press picks without blurring it.
565
+ this.listen(list, 'mousedown', (event) => event.preventDefault());
566
+ this.listen(list, 'click', (event) => {
567
+ const option = /** @type {Element|null} */ (event.target)?.closest?.('[role="option"]');
568
+ if (option && this._mention) this._pickMention(Number(/** @type {HTMLElement} */ (option).dataset.index));
569
+ });
570
+ this.listen(list, 'pointermove', (event) => {
571
+ const option = /** @type {Element|null} */ (event.target)?.closest?.('[role="option"]');
572
+ const index = Number(/** @type {HTMLElement|null} */ (option)?.dataset.index);
573
+ if (option && this._mention && index !== this._mention.index) this._highlight(index);
574
+ });
575
+ if (options.attachments) {
576
+ this.listen(root, 'dragenter', (event) => this._onDrag(/** @type {DragEvent} */ (event)));
577
+ this.listen(root, 'dragover', (event) => this._onDrag(/** @type {DragEvent} */ (event)));
578
+ this.listen(root, 'dragleave', (event) => {
579
+ const related = /** @type {Node|null} */ (/** @type {DragEvent} */ (event).relatedTarget);
580
+ if (!related || !root.contains(related)) this._setDropping(false);
581
+ });
582
+ this.listen(root, 'drop', (event) => this._onDrop(/** @type {DragEvent} */ (event)));
583
+ }
584
+
585
+ // The text re-wraps when its width changes, so its height is measured again.
586
+ this._observer = typeof ResizeObserver === 'function'
587
+ ? new ResizeObserver(() => {
588
+ const width = input.clientWidth;
589
+ if (width === this._width) return;
590
+ this._width = width;
591
+ this._autosize();
592
+ })
593
+ : null;
594
+ this._observer?.observe(input);
595
+ this._autosize();
596
+ return root;
597
+ }
598
+
599
+ /** Focuses the text. @returns {this} */
600
+ focus() {
601
+ this._input.focus();
602
+ return this;
603
+ }
604
+
605
+ /** @returns {string} The text as written. */
606
+ getValue() {
607
+ return this._input.value;
608
+ }
609
+
610
+ /**
611
+ * Replaces the text, keeps the draft in step, and puts the caret at the end. Emits nothing.
612
+ * @param {string} text
613
+ * @returns {this}
614
+ */
615
+ setValue(text) {
616
+ const input = this._input;
617
+ input.value = String(text ?? '');
618
+ input.setSelectionRange(input.value.length, input.value.length);
619
+ this._closeMentions();
620
+ this._afterTextChange();
621
+ return this;
622
+ }
623
+
624
+ /**
625
+ * Types text at the caret, replacing any selection, as if the person had typed it: the draft
626
+ * follows, and text ending in the mention trigger (`'@'`) opens the suggestions. Emits `input`.
627
+ * Use it for a button that starts a mention or inserts a snippet.
628
+ * @param {string} text
629
+ * @returns {this}
630
+ */
631
+ insertText(text) {
632
+ const input = this._input;
633
+ const value = String(text ?? '');
634
+ const start = input.selectionStart ?? input.value.length;
635
+ const end = input.selectionEnd ?? start;
636
+ input.setRangeText(value, start, end, 'end');
637
+ input.focus();
638
+ this._onInput();
639
+ return this;
640
+ }
641
+
642
+ /**
643
+ * Empties the text, the attachments and the draft. Context chips stay. Emits nothing.
644
+ * @returns {this}
645
+ */
646
+ clear() {
647
+ this._input.value = '';
648
+ this._mentions = [];
649
+ this._files = [];
650
+ this._renderFiles();
651
+ this._closeMentions();
652
+ this._afterTextChange();
653
+ return this;
654
+ }
655
+
656
+ /**
657
+ * Shows Stop in place of Send while an agent works; Escape in the text then emits `stop`. When
658
+ * busy ends, the first queued message is sent; the next waits for the next time it ends.
659
+ * @param {boolean} busy
660
+ * @returns {this}
661
+ * @fires Composer#send
662
+ * @fires Composer#dequeue
663
+ */
664
+ setBusy(busy) {
665
+ const ended = this._busy && !busy;
666
+ this._busy = Boolean(busy);
667
+ this._syncSend();
668
+ if (ended) this._sendNextQueued();
669
+ return this;
670
+ }
671
+
672
+ /** @returns {boolean} Whether Stop is showing. */
673
+ isBusy() {
674
+ return this._busy;
675
+ }
676
+
677
+ /**
678
+ * Changes the quiet text in the bar beside Send — what Enter does now, or why sending waits.
679
+ * An empty text hides it.
680
+ * @param {string} text
681
+ * @returns {this}
682
+ */
683
+ setHint(text) {
684
+ this._hint = String(text ?? '');
685
+ this._syncHint();
686
+ return this;
687
+ }
688
+
689
+ /**
690
+ * Changes the line under the composer, which also describes the text box. An empty text hides
691
+ * it.
692
+ * @param {string} text
693
+ * @returns {this}
694
+ */
695
+ setNote(text) {
696
+ const note = /** @type {HTMLElement} */ (this.refs.note);
697
+ note.textContent = String(text ?? '');
698
+ note.hidden = !note.textContent;
699
+ if (note.hidden) this._input.removeAttribute('aria-describedby');
700
+ else this._input.setAttribute('aria-describedby', note.id);
701
+ return this;
702
+ }
703
+
704
+ /**
705
+ * Turns input on or off.
706
+ * @param {boolean} disabled
707
+ * @returns {this}
708
+ */
709
+ setDisabled(disabled) {
710
+ this._disabled = Boolean(disabled);
711
+ if (this._disabled) {
712
+ this._closeMentions();
713
+ this._setDropping(false);
714
+ }
715
+ this._syncState();
716
+ this._syncSend();
717
+ return this;
718
+ }
719
+
720
+ /**
721
+ * Changes the composer in place: the text, its caret and selection, the focus, the attachments,
722
+ * the context chips and the draft all stay. This is how a placeholder follows the model picked
723
+ * beside the composer. Keys left out (or `undefined`) are kept; other keys are ignored. Emits
724
+ * nothing.
725
+ * @param {ComposerUpdate} [partial={}]
726
+ * @returns {this}
727
+ */
728
+ update(partial = {}) {
729
+ if (this._destroyed || !partial || typeof partial !== 'object') return this;
730
+ /** @param {keyof ComposerUpdate} key @returns {boolean} */
731
+ const has = (key) => Object.hasOwn(partial, key) && partial[key] !== undefined;
732
+ const input = this._input;
733
+ if (has('label')) {
734
+ const label = this._labelText(partial.label);
735
+ input.setAttribute('aria-label', label);
736
+ this.el.setAttribute('aria-label', label);
737
+ }
738
+ if (has('placeholder')) {
739
+ const placeholder = String(partial.placeholder ?? '');
740
+ if (placeholder) input.placeholder = placeholder;
741
+ else input.removeAttribute('placeholder');
742
+ }
743
+ if (has('hint')) this.setHint(String(partial.hint ?? ''));
744
+ if (has('note')) this.setNote(String(partial.note ?? ''));
745
+ if (has('submitKey')) this._submitKey = submitKeyOf(partial.submitKey);
746
+ if (has('sendLabel')) this._sendLabel = sendLabelText(partial.sendLabel);
747
+ if (has('disabled')) this.setDisabled(Boolean(partial.disabled));
748
+ if (has('busy')) this.setBusy(Boolean(partial.busy));
749
+ this._syncSend();
750
+ return this;
751
+ }
752
+
753
+ /**
754
+ * Replaces the bar's extra tools. A tool that held the focus keeps it when a tool with the same
755
+ * id is still there (and enabled); otherwise the focus moves to the text. Emits nothing.
756
+ * @param {ComposerTool[]} tools
757
+ * @returns {this}
758
+ */
759
+ setTools(tools) {
760
+ if (this._destroyed) return this;
761
+ this._tools = normalizeTools(tools);
762
+ this._renderTools();
763
+ return this;
764
+ }
765
+
766
+ /**
767
+ * Presses or releases a tool, which makes it a toggle if it was a plain button. Emits nothing.
768
+ * @param {string} id
769
+ * @param {boolean} pressed
770
+ * @returns {this}
771
+ */
772
+ setToolPressed(id, pressed) {
773
+ const tool = this._tools.find((entry) => entry.id === String(id));
774
+ if (!tool) return this;
775
+ tool.pressed = Boolean(pressed);
776
+ this._toolButton(tool.id)?.setAttribute('aria-pressed', String(tool.pressed));
777
+ return this;
778
+ }
779
+
780
+ /**
781
+ * Attaches files, as far as `accept` and `maxFiles` allow. Emits `attach` with the files taken.
782
+ * @param {FileList|File[]} files
783
+ * @returns {this}
784
+ */
785
+ addFiles(files) {
786
+ this._addFiles(Array.from(files ?? []), false);
787
+ return this;
788
+ }
789
+
790
+ /** @returns {File[]} The attached files. */
791
+ getFiles() {
792
+ return this._files.map((entry) => entry.file);
793
+ }
794
+
795
+ /**
796
+ * Adds a context chip, or replaces the chip with the same id. Emits nothing.
797
+ * @param {ContextChip} chip
798
+ * @returns {this}
799
+ */
800
+ addContext(chip) {
801
+ this._putContext(chip);
802
+ this._renderContext();
803
+ return this;
804
+ }
805
+
806
+ /**
807
+ * Removes a context chip. Emits nothing.
808
+ * @param {string} id
809
+ * @returns {this}
810
+ */
811
+ removeContext(id) {
812
+ this._context = this._context.filter((chip) => chip.id !== String(id));
813
+ this._renderContext();
814
+ return this;
815
+ }
816
+
817
+ /** @returns {ContextChip[]} The context chips. */
818
+ getContext() {
819
+ return this._context.map((chip) => ({ ...chip }));
820
+ }
821
+
822
+ /** @returns {QueuedMessage[]} Copies of the queued messages, the next to be sent first. */
823
+ getQueue() {
824
+ return this._queue.map(copyQueued);
825
+ }
826
+
827
+ /**
828
+ * Removes every queued message. Emits `dequeue` for each, with `reason: 'cleared'`. Stop does not
829
+ * do this: call it from a `stop` listener to drop what was waiting along with the run.
830
+ * @returns {this}
831
+ * @fires Composer#dequeue
832
+ */
833
+ clearQueue() {
834
+ const { queue, items } = emptyQueue(this._queue);
835
+ if (!items.length) return this;
836
+ this._queue = queue;
837
+ this._renderQueue();
838
+ for (const item of items) this._emitDequeue(item, 'cleared');
839
+ return this;
840
+ }
841
+
842
+ /**
843
+ * Removes one queued message. Emits `dequeue` with `reason: 'removed'`. An id that is not queued,
844
+ * because the message has been sent, say, changes nothing.
845
+ * @param {string} id
846
+ * @returns {this}
847
+ * @fires Composer#dequeue
848
+ */
849
+ removeQueued(id) {
850
+ const { queue, item } = removeFromQueue(this._queue, String(id));
851
+ if (!item) return this;
852
+ this._queue = queue;
853
+ this._renderQueue();
854
+ this._emitDequeue(item, 'removed');
855
+ return this;
856
+ }
857
+
858
+ /**
859
+ * Removes what the composer drew and the launcher it opened, drops the queue, and stops listening.
860
+ * @returns {void}
861
+ */
862
+ destroy() {
863
+ if (this._destroyed) return;
864
+ this._destroyed = true;
865
+ this._queue = [];
866
+ this._releaseQueueRoving();
867
+ this._mentionSequence += 1;
868
+ this._observer?.disconnect();
869
+ this._observer = null;
870
+ this._position?.destroy();
871
+ this._position = null;
872
+ this._launcher?.destroy();
873
+ this._launcher = null;
874
+ super.destroy();
875
+ if (this._original) restoreTarget(this.el, this._original);
876
+ }
877
+
878
+ /* ------------------------------------------------------------------ text -- */
879
+
880
+ /** @private @returns {void} */
881
+ _onInput() {
882
+ this._afterTextChange();
883
+ this._updateMentions();
884
+ this.emit('input', { text: this._input.value });
885
+ }
886
+
887
+ /** @private @returns {void} */
888
+ _afterTextChange() {
889
+ this._autosize();
890
+ this._syncSend();
891
+ this._saveDraft();
892
+ }
893
+
894
+ /** @private @returns {void} */
895
+ _saveDraft() {
896
+ if (!this._draft) return;
897
+ const key = String(this.options.draftKey);
898
+ if (this._input.value) this._draft.set(key, this._input.value);
899
+ else this._draft.remove(key);
900
+ }
901
+
902
+ /** Grows the text with its content, between `minRows` and `maxRows`. @private @returns {void} */
903
+ _autosize() {
904
+ const input = this._input;
905
+ if (!input.isConnected || typeof getComputedStyle !== 'function') return;
906
+ input.style.blockSize = 'auto';
907
+ const style = getComputedStyle(input);
908
+ const fontSize = parseFloat(style.fontSize) || 16;
909
+ const lineHeight = parseFloat(style.lineHeight) || fontSize * 1.5;
910
+ const padding = (parseFloat(style.paddingBlockStart) || 0) + (parseFloat(style.paddingBlockEnd) || 0);
911
+ const border = (parseFloat(style.borderBlockStartWidth) || 0) + (parseFloat(style.borderBlockEndWidth) || 0);
912
+ const { height, scrolls } = autosizeHeight(input.scrollHeight, {
913
+ lineHeight, padding, border, minRows: this._rows.min, maxRows: this._rows.max
914
+ });
915
+ input.style.blockSize = `${height}px`;
916
+ input.dataset.scrolls = String(scrolls);
917
+ }
918
+
919
+ /* ------------------------------------------------------------------ keys -- */
920
+
921
+ /**
922
+ * @private
923
+ * @param {KeyboardEvent} event
924
+ * @returns {void}
925
+ */
926
+ _onKeydown(event) {
927
+ if (event.isComposing || event.keyCode === 229) return;
928
+ const mention = this._mention;
929
+ if (mention) {
930
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
931
+ event.preventDefault();
932
+ const step = event.key === 'ArrowDown' ? 1 : -1;
933
+ this._highlight((mention.index + step + mention.items.length) % mention.items.length);
934
+ return;
935
+ }
936
+ if ((event.key === 'Enter' || event.key === 'Tab') && !event.shiftKey && !event.altKey
937
+ && !event.metaKey && !event.ctrlKey) {
938
+ event.preventDefault();
939
+ this._pickMention(mention.index);
940
+ return;
941
+ }
942
+ if (event.key === 'Escape') {
943
+ event.preventDefault();
944
+ event.stopPropagation();
945
+ this._closeMentions();
946
+ return;
947
+ }
948
+ }
949
+ const plain = !event.shiftKey && !event.altKey && !event.metaKey && !event.ctrlKey;
950
+ if (isSubmitKey(event, this._submitKey)) {
951
+ event.preventDefault();
952
+ this._send();
953
+ } else if (event.key === 'Escape' && this._busy) {
954
+ event.preventDefault();
955
+ this._stop();
956
+ } else if (event.key === 'ArrowUp' && plain && this._input.value === '') {
957
+ event.preventDefault();
958
+ this.emit('historyprevious', {});
959
+ } else if (event.key === '/' && plain && this._input.value === '' && this._commands) {
960
+ event.preventDefault();
961
+ this._openCommands();
962
+ }
963
+ }
964
+
965
+ /* ------------------------------------------------------------- send/stop -- */
966
+
967
+ /**
968
+ * The message as it stands in the composer, or null when there is nothing to send.
969
+ * @private
970
+ * @returns {ComposerSendDetail|null}
971
+ */
972
+ _message() {
973
+ const text = this._input.value.trim();
974
+ const files = this.getFiles();
975
+ if (!text && !files.length) return null;
976
+ const trigger = this._mentionSource?.trigger ?? '@';
977
+ return {
978
+ text,
979
+ files,
980
+ mentions: mentionsInText(text, this._mentions, trigger).map((item) => ({ ...item })),
981
+ context: this.getContext()
982
+ };
983
+ }
984
+
985
+ /** @private @returns {void} @fires Composer#send @fires Composer#queue */
986
+ _send() {
987
+ if (this._disabled) return;
988
+ if (this._busy) {
989
+ if (this.options.queue) this._enqueue();
990
+ return;
991
+ }
992
+ const detail = this._message();
993
+ if (!detail) return;
994
+ const event = this.emit('send', detail, { honorDomCancellation: true });
995
+ if (event.defaultPrevented || this._destroyed) return;
996
+ this.clear();
997
+ }
998
+
999
+ /** @private @returns {void} @fires Composer#stop */
1000
+ _stop() {
1001
+ if (!this._busy) return;
1002
+ this.emit('stop', {});
1003
+ }
1004
+
1005
+ /**
1006
+ * The Send button's glyph, text, name and readiness. With `sendLabel` the text is visible and is
1007
+ * the name; without it the button is a glyph named by `aria-label` alone.
1008
+ * @private
1009
+ * @returns {void}
1010
+ */
1011
+ _syncSend() {
1012
+ const button = /** @type {HTMLButtonElement} */ (this.refs.send);
1013
+ const busy = this._busy;
1014
+ const mode = busy ? 'stop' : 'send';
1015
+ const drawn = `${mode}\n${this._submitKey}\n${this._sendLabel}`;
1016
+ if (drawn !== this._sendDrawn) {
1017
+ this._sendDrawn = drawn;
1018
+ const chord = this._submitKey === 'mod+enter' ? 'Mod+Enter' : 'Enter';
1019
+ const apple = isApplePlatform();
1020
+ const name = busy ? this.msg('composer.stop') : (this._sendLabel || this.msg('composer.send'));
1021
+ const keys = busy ? 'Escape' : (chord === 'Enter' ? 'Enter' : `${apple ? 'Meta' : 'Control'}+Enter`);
1022
+ const shown = keyLabels(busy ? 'Escape' : chord, { apple }).join(apple ? '' : '+');
1023
+ button.dataset.mode = mode;
1024
+ const glyph = icon(busy ? 'square' : 'arrow-up', { size: ICON_SIZE.control });
1025
+ if (this._sendLabel) button.replaceChildren(glyph, h('span', { class: 'zx-composer__send-label' }, name));
1026
+ else button.replaceChildren(glyph);
1027
+ button.setAttribute('aria-label', name);
1028
+ button.setAttribute('aria-keyshortcuts', keys);
1029
+ button.title = `${name} (${shown})`;
1030
+ }
1031
+ // Never disabled while the composer is live: a disabled button drops the focus it holds.
1032
+ const empty = !this._input.value.trim() && !this._files.length;
1033
+ button.setAttribute('aria-disabled', String(!busy && empty));
1034
+ }
1035
+
1036
+ /** The quiet text beside Send: why the queue refused, else the application's. @private @returns {void} */
1037
+ _syncHint() {
1038
+ const hint = /** @type {HTMLElement} */ (this.refs.hint);
1039
+ hint.textContent = this._queueRefused ? this.msg('composer.queueFull', this._queueLimit) : this._hint;
1040
+ hint.hidden = !hint.textContent;
1041
+ }
1042
+
1043
+ /** Disabled state on the text and the buttons. @private @returns {void} */
1044
+ _syncState() {
1045
+ const disabled = this._disabled;
1046
+ this._input.disabled = disabled;
1047
+ if (disabled) this.el.setAttribute('aria-disabled', 'true');
1048
+ else this.el.removeAttribute('aria-disabled');
1049
+ for (const button of this.el.querySelectorAll('.zx-composer__frame button')) {
1050
+ /** @type {HTMLButtonElement} */ (button).disabled = disabled;
1051
+ }
1052
+ this._renderTools();
1053
+ this._renderFiles();
1054
+ this._renderContext();
1055
+ }
1056
+
1057
+ /**
1058
+ * The accessible name for a `label` option: the text given, or the `composer.label` message.
1059
+ * @private
1060
+ * @param {string|null|undefined} label
1061
+ * @returns {string}
1062
+ */
1063
+ _labelText(label) {
1064
+ return String(label ?? this.msg('composer.label'));
1065
+ }
1066
+
1067
+ /* ----------------------------------------------------------------- tools -- */
1068
+
1069
+ /**
1070
+ * Draws the extra tools, and puts the focus back on the tool that held it.
1071
+ * @private
1072
+ * @returns {void}
1073
+ */
1074
+ _renderTools() {
1075
+ const box = /** @type {HTMLElement} */ (this.refs.tools);
1076
+ const active = /** @type {HTMLElement|null} */ (box.ownerDocument.activeElement);
1077
+ const focused = active && box.contains(active) ? active.dataset.tool ?? null : null;
1078
+ box.hidden = this._tools.length === 0;
1079
+ box.replaceChildren(...this._tools.map((tool) => {
1080
+ const button = iconButton(tool.icon, tool.label, 'tool');
1081
+ button.dataset.tool = tool.id;
1082
+ if (typeof tool.pressed === 'boolean') button.setAttribute('aria-pressed', String(tool.pressed));
1083
+ if (typeof tool.expanded === 'boolean') button.setAttribute('aria-expanded', String(tool.expanded));
1084
+ if (tool.controls) button.setAttribute('aria-controls', String(tool.controls));
1085
+ button.disabled = this._disabled || Boolean(tool.disabled);
1086
+ return button;
1087
+ }));
1088
+ if (focused === null) return;
1089
+ const next = this._toolButton(focused);
1090
+ if (next && !next.disabled) next.focus();
1091
+ else if (!this._input.disabled) this._input.focus();
1092
+ }
1093
+
1094
+ /**
1095
+ * @private
1096
+ * @param {string} id
1097
+ * @returns {HTMLButtonElement|null}
1098
+ */
1099
+ _toolButton(id) {
1100
+ const buttons = /** @type {HTMLButtonElement[]} */ (Array.from(this.refs.tools.children));
1101
+ return buttons.find((button) => button.dataset.tool === id) ?? null;
1102
+ }
1103
+
1104
+ /**
1105
+ * @private
1106
+ * @param {MouseEvent} event
1107
+ * @returns {void}
1108
+ * @fires Composer#tool
1109
+ */
1110
+ _onToolClick(event) {
1111
+ const button = /** @type {HTMLButtonElement|null} */ (/** @type {Element|null} */ (event.target)?.closest?.('[data-tool]'));
1112
+ if (!button || button.disabled || this._disabled) return;
1113
+ const tool = this._tools.find((entry) => entry.id === button.dataset.tool);
1114
+ if (!tool) return;
1115
+ this.emit('tool', { id: tool.id, tool: { ...tool } });
1116
+ }
1117
+
1118
+ /* -------------------------------------------------------------- mentions -- */
1119
+
1120
+ /**
1121
+ * Opens, filters or closes the suggestions from the word the caret is in.
1122
+ * @private
1123
+ * @returns {void}
1124
+ */
1125
+ _updateMentions() {
1126
+ const source = this._mentionSource;
1127
+ const input = this._input;
1128
+ if (!source || this._disabled || input.selectionStart !== input.selectionEnd) {
1129
+ this._closeMentions();
1130
+ return;
1131
+ }
1132
+ const caret = input.selectionStart ?? input.value.length;
1133
+ const found = mentionQuery(input.value, caret, source.trigger);
1134
+ if (!found) {
1135
+ this._closeMentions();
1136
+ return;
1137
+ }
1138
+ this._mentionSequence += 1;
1139
+ const sequence = this._mentionSequence;
1140
+ /** @param {unknown} items */
1141
+ const apply = (items) => {
1142
+ if (sequence !== this._mentionSequence || this._destroyed) return;
1143
+ this._showMentions(found.start, caret, Array.isArray(items) ? items.filter(isMentionItem) : []);
1144
+ };
1145
+ if (typeof source.items !== 'function') {
1146
+ apply(filterMentions(source.items, found.query));
1147
+ return;
1148
+ }
1149
+ let result;
1150
+ try {
1151
+ result = source.items(found.query);
1152
+ } catch {
1153
+ this._closeMentions();
1154
+ return;
1155
+ }
1156
+ if (result && typeof (/** @type {Promise<unknown>} */ (result)).then === 'function') {
1157
+ /** @type {Promise<MentionItem[]>} */ (result).then(apply, () => {
1158
+ if (sequence === this._mentionSequence) this._closeMentions();
1159
+ });
1160
+ } else {
1161
+ apply(result);
1162
+ }
1163
+ }
1164
+
1165
+ /**
1166
+ * @private
1167
+ * @param {number} start Offset of the trigger.
1168
+ * @param {number} end Caret offset.
1169
+ * @param {MentionItem[]} items
1170
+ * @returns {void}
1171
+ */
1172
+ _showMentions(start, end, items) {
1173
+ if (!items.length) {
1174
+ this._closeMentions();
1175
+ return;
1176
+ }
1177
+ const list = /** @type {HTMLElement} */ (this.refs.list);
1178
+ const highlighted = this._mention?.items[this._mention.index];
1179
+ const kept = highlighted ? items.findIndex((item) => String(item.id) === String(highlighted.id)) : -1;
1180
+ this._mention = { start, end, items, index: Math.max(0, kept) };
1181
+ list.replaceChildren(...items.map((item, index) => h('div', {
1182
+ class: 'zx-composer__option', role: 'option', id: `${list.id}-${index}`,
1183
+ ariaSelected: 'false', dataset: { index: String(index) }
1184
+ },
1185
+ item.icon ? icon(item.icon, { size: ICON_SIZE.control }) : null,
1186
+ h('span', { class: 'zx-composer__option-text' },
1187
+ h('span', { class: 'zx-composer__option-label' }, String(item.label)),
1188
+ item.description ? h('span', { class: 'zx-composer__option-description' }, String(item.description)) : null))));
1189
+ if (list.hidden) {
1190
+ list.hidden = false;
1191
+ this._position = position(/** @type {HTMLElement} */ (this.refs.frame), list, {
1192
+ placement: 'top-start', offset: 6, flip: true
1193
+ });
1194
+ } else {
1195
+ this._position?.update();
1196
+ }
1197
+ this._input.setAttribute('aria-autocomplete', 'list');
1198
+ this._input.setAttribute('aria-controls', list.id);
1199
+ this._highlight(this._mention.index);
1200
+ this._announce(items.length === 1 ? this.msg('composer.match') : this.msg('composer.matches', items.length));
1201
+ }
1202
+
1203
+ /**
1204
+ * @private
1205
+ * @param {number} index
1206
+ * @returns {void}
1207
+ */
1208
+ _highlight(index) {
1209
+ const mention = this._mention;
1210
+ if (!mention || !Number.isInteger(index) || !mention.items[index]) return;
1211
+ mention.index = index;
1212
+ const options = /** @type {HTMLElement[]} */ (Array.from(this.refs.list.children));
1213
+ options.forEach((option, at) => option.setAttribute('aria-selected', String(at === index)));
1214
+ this._input.setAttribute('aria-activedescendant', options[index].id);
1215
+ options[index].scrollIntoView?.({ block: 'nearest' });
1216
+ }
1217
+
1218
+ /** @private @returns {void} */
1219
+ _closeMentions() {
1220
+ this._mentionSequence += 1;
1221
+ if (!this._mention && /** @type {HTMLElement} */ (this.refs.list).hidden) return;
1222
+ this._mention = null;
1223
+ this._position?.destroy();
1224
+ this._position = null;
1225
+ const list = /** @type {HTMLElement} */ (this.refs.list);
1226
+ list.hidden = true;
1227
+ list.replaceChildren();
1228
+ this._input.removeAttribute('aria-autocomplete');
1229
+ this._input.removeAttribute('aria-controls');
1230
+ this._input.removeAttribute('aria-activedescendant');
1231
+ this._announce('');
1232
+ }
1233
+
1234
+ /**
1235
+ * Writes `@<label> ` where the mention was typed and records the item.
1236
+ * @private
1237
+ * @param {number} index
1238
+ * @returns {void}
1239
+ * @fires Composer#mention
1240
+ */
1241
+ _pickMention(index) {
1242
+ const mention = this._mention;
1243
+ const item = mention?.items[index];
1244
+ if (!mention || !item) return;
1245
+ const input = this._input;
1246
+ const trigger = this._mentionSource?.trigger ?? '@';
1247
+ const text = `${trigger}${item.label} `;
1248
+ const rest = input.value.slice(mention.end).replace(/^ /, '');
1249
+ input.value = `${input.value.slice(0, mention.start)}${text}${rest}`;
1250
+ const caret = mention.start + text.length;
1251
+ input.setSelectionRange(caret, caret);
1252
+ this._closeMentions();
1253
+ this._mentions = [...this._mentions.filter((entry) => String(entry.id) !== String(item.id)), item];
1254
+ this._afterTextChange();
1255
+ this.emit('mention', { item: { ...item } });
1256
+ this.emit('input', { text: input.value });
1257
+ }
1258
+
1259
+ /**
1260
+ * Sets the polite status, once per change.
1261
+ * @private
1262
+ * @param {string} text
1263
+ * @param {boolean} [again=false] Whether the same text is news again: a no-break space then tells
1264
+ * it apart from the last time, because a live region says nothing about a text that did not change.
1265
+ * @returns {void}
1266
+ */
1267
+ _announce(text, again = false) {
1268
+ const spoken = again && text === this._announced ? `${text}\u00A0` : text;
1269
+ if (spoken === this._announced) return;
1270
+ this._announced = spoken;
1271
+ this.refs.status.textContent = spoken;
1272
+ }
1273
+
1274
+ /* ----------------------------------------------------------------- queue -- */
1275
+
1276
+ /**
1277
+ * Holds the message back until the agent is no longer busy, or refuses it at the limit: the
1278
+ * message then stays where it was written.
1279
+ * @private
1280
+ * @returns {void}
1281
+ * @fires Composer#queue
1282
+ */
1283
+ _enqueue() {
1284
+ const message = this._message();
1285
+ if (!message) return;
1286
+ const { queue, item } = addToQueue(this._queue, { id: uid('zx-composer-queued'), ...message }, this._queueLimit);
1287
+ if (!item) {
1288
+ this._queueRefused = true;
1289
+ this._syncHint();
1290
+ this._announce(this.msg('composer.queueFull', this._queueLimit), true);
1291
+ return;
1292
+ }
1293
+ this._queue = queue;
1294
+ this.clear();
1295
+ this._renderQueue();
1296
+ this._announce(this.msg('composer.queued'), true);
1297
+ this.emit('queue', { item: copyQueued(item), items: this.getQueue() });
1298
+ }
1299
+
1300
+ /**
1301
+ * Sends the first queued message for an end of busy. A `send` listener that ends busy again,
1302
+ * before it returns, does not send from inside this one: the next message goes when it is done.
1303
+ * @private
1304
+ * @returns {void}
1305
+ */
1306
+ _sendNextQueued() {
1307
+ if (this._sendingQueued) {
1308
+ this._busyEndedAgain = true;
1309
+ return;
1310
+ }
1311
+ this._sendingQueued = true;
1312
+ do {
1313
+ this._busyEndedAgain = false;
1314
+ this._sendQueued();
1315
+ } while (this._busyEndedAgain);
1316
+ this._sendingQueued = false;
1317
+ }
1318
+
1319
+ /**
1320
+ * Sends the first queued message, unless it must wait. What is being written stays: it is not the
1321
+ * message that goes. A prevented `send` was not sent, so the message stays first in line.
1322
+ * @private
1323
+ * @returns {void}
1324
+ * @fires Composer#send
1325
+ * @fires Composer#dequeue
1326
+ */
1327
+ _sendQueued() {
1328
+ if (this._busy || this._disabled || this._destroyed) return;
1329
+ const { queue, item } = takeNext(this._queue);
1330
+ if (!item) return;
1331
+ this._queue = queue;
1332
+ const { id, ...message } = copyQueued(item);
1333
+ const event = this.emit('send', { ...message, queued: true }, { honorDomCancellation: true });
1334
+ if (this._destroyed) return;
1335
+ if (event.defaultPrevented) this._queue = [item, ...this._queue];
1336
+ this._renderQueue();
1337
+ if (!event.defaultPrevented) this._emitDequeue(item, 'sent');
1338
+ }
1339
+
1340
+ /**
1341
+ * @private
1342
+ * @param {QueuedMessage} item
1343
+ * @param {ComposerDequeueDetail['reason']} reason
1344
+ * @returns {void}
1345
+ * @fires Composer#dequeue
1346
+ */
1347
+ _emitDequeue(item, reason) {
1348
+ this.emit('dequeue', { item: copyQueued(item), items: this.getQueue(), reason });
1349
+ }
1350
+
1351
+ /**
1352
+ * Takes a queued message back into the composer, asking first when that would replace what is
1353
+ * being written. The message may have been sent while the question was open; nothing happens then.
1354
+ * @private
1355
+ * @param {string} id
1356
+ * @returns {Promise<void>}
1357
+ * @fires Composer#dequeue
1358
+ * @fires Composer#input
1359
+ */
1360
+ async _editQueued(id) {
1361
+ if (this._input.value.trim() || this._files.length) {
1362
+ const replace = await Dialog.confirm({
1363
+ title: this.msg('composer.queueReplaceTitle'),
1364
+ message: this.msg('composer.queueReplaceMessage'),
1365
+ okLabel: this.msg('composer.queueReplaceConfirm'),
1366
+ danger: true
1367
+ });
1368
+ if (!replace || this._destroyed) return;
1369
+ }
1370
+ const { queue, item } = removeFromQueue(this._queue, id);
1371
+ if (!item) return;
1372
+ this._queue = queue;
1373
+ this._files = item.files.map((file) => ({ id: uid('zx-composer-file'), file }));
1374
+ this._renderFiles();
1375
+ this.setValue(item.text);
1376
+ this._mentions = item.mentions.map((mention) => ({ ...mention }));
1377
+ this._renderQueue();
1378
+ this._input.focus();
1379
+ this._emitDequeue(item, 'edited');
1380
+ this.emit('input', { text: this._input.value });
1381
+ }
1382
+
1383
+ /**
1384
+ * @private
1385
+ * @param {MouseEvent} event
1386
+ * @returns {void}
1387
+ */
1388
+ _onQueueClick(event) {
1389
+ const button = /** @type {HTMLElement|null} */ (/** @type {Element|null} */ (event.target)?.closest?.('[data-queue-action]'));
1390
+ const row = /** @type {HTMLElement|null} */ (button?.closest('[data-queued]') ?? null);
1391
+ if (!button || !row || this._disabled) return;
1392
+ if (button.dataset.queueAction === 'edit') this._editQueued(String(row.dataset.queued));
1393
+ else this.removeQueued(String(row.dataset.queued));
1394
+ }
1395
+
1396
+ /**
1397
+ * Delete on a focused row removes it. The arrow keys inside a row belong to its toolbar.
1398
+ * @private
1399
+ * @param {KeyboardEvent} event
1400
+ * @returns {void}
1401
+ */
1402
+ _onQueueKeydown(event) {
1403
+ if (event.key !== 'Delete' || event.shiftKey || event.altKey || event.metaKey || event.ctrlKey || this._disabled) return;
1404
+ const row = /** @type {HTMLElement|null} */ (/** @type {Element|null} */ (event.target)?.closest?.('[data-queued]'));
1405
+ if (!row) return;
1406
+ event.preventDefault();
1407
+ this.removeQueued(String(row.dataset.queued));
1408
+ }
1409
+
1410
+ /**
1411
+ * Draws the queue, and keeps the focus in it: on the same button of the same row, on the row now
1412
+ * in that place when the row has gone, and in the text when no row is left.
1413
+ * @private
1414
+ * @returns {void}
1415
+ */
1416
+ _renderQueue() {
1417
+ if (!this.options.queue) return;
1418
+ const list = /** @type {HTMLElement} */ (this.refs.queueList);
1419
+ const active = /** @type {HTMLElement|null} */ (list.ownerDocument.activeElement);
1420
+ const focused = active && list.contains(active) ? active : null;
1421
+ const focusedRow = /** @type {HTMLElement|null} */ (focused?.closest('[data-queued]') ?? null);
1422
+ const place = focusedRow ? Array.from(list.children).indexOf(focusedRow) : -1;
1423
+
1424
+ this._releaseQueueRoving();
1425
+ /** @type {HTMLElement} */ (this.refs.queue).hidden = this._queue.length === 0;
1426
+ this.refs.queueLabel.textContent = this.msg('composer.queue', this._queue.length);
1427
+ list.replaceChildren(...this._queue.map((item) => this._queueRow(item)));
1428
+ this._queueRoving = /** @type {HTMLElement[]} */ (Array.from(list.querySelectorAll('[role="toolbar"]')))
1429
+ .map((toolbar) => rovingTabindex(toolbar, '[data-queue-action]', { orientation: 'horizontal' }));
1430
+
1431
+ if (this._queueRefused && !isQueueFull(this._queue, this._queueLimit)) {
1432
+ this._queueRefused = false;
1433
+ this._syncHint();
1434
+ }
1435
+ if (!focused || !focusedRow) return;
1436
+ const rows = /** @type {HTMLElement[]} */ (Array.from(list.children));
1437
+ const row = rows.find((entry) => entry.dataset.queued === focusedRow.dataset.queued)
1438
+ ?? rows[Math.min(place, rows.length - 1)];
1439
+ const next = /** @type {HTMLElement|null} */ (row?.querySelector(`[data-queue-action="${focused.dataset.queueAction}"]`) ?? null);
1440
+ if (next) next.focus();
1441
+ else this._input.focus();
1442
+ }
1443
+
1444
+ /**
1445
+ * One queued message on one line: its text, or the names of its files when it has none, and a
1446
+ * toolbar named by that line.
1447
+ * @private
1448
+ * @param {QueuedMessage} item
1449
+ * @returns {HTMLElement}
1450
+ */
1451
+ _queueRow(item) {
1452
+ const textId = uid('zx-composer-queued-text');
1453
+ const count = item.files.length;
1454
+ return h('li', { class: 'zx-composer__queued', dataset: { queued: item.id } },
1455
+ h('span', { class: 'zx-composer__queued-text', id: textId },
1456
+ item.text || item.files.map((file) => file.name).join(', ')),
1457
+ item.text && count
1458
+ ? h('span', { class: 'zx-composer__queued-meta' },
1459
+ count === 1 ? this.msg('composer.queueFile') : this.msg('composer.queueFiles', count))
1460
+ : null,
1461
+ h('div', { class: 'zx-composer__queued-actions', role: 'toolbar', 'aria-labelledby': textId },
1462
+ this._queueButton('edit', this.msg('composer.queueEdit')),
1463
+ this._queueButton('remove', this.msg('composer.queueRemove'))));
1464
+ }
1465
+
1466
+ /**
1467
+ * @private
1468
+ * @param {'edit'|'remove'} action
1469
+ * @param {string} label
1470
+ * @returns {HTMLElement}
1471
+ */
1472
+ _queueButton(action, label) {
1473
+ return h('button', {
1474
+ type: 'button',
1475
+ class: 'zx-icon-btn zx-composer__queued-action',
1476
+ disabled: this._disabled,
1477
+ dataset: { queueAction: action }
1478
+ }, label);
1479
+ }
1480
+
1481
+ /** @private @returns {void} */
1482
+ _releaseQueueRoving() {
1483
+ for (const roving of this._queueRoving) roving.destroy();
1484
+ this._queueRoving = [];
1485
+ }
1486
+
1487
+ /* -------------------------------------------------------------- commands -- */
1488
+
1489
+ /**
1490
+ * Opens the commands in a launcher, created on first use.
1491
+ * @private
1492
+ * @returns {void}
1493
+ * @fires Composer#command
1494
+ */
1495
+ _openCommands() {
1496
+ if (!this._commands || this._disabled || this._destroyed) return;
1497
+ this._closeMentions();
1498
+ this._launcher ??= new Launcher(null, {
1499
+ items: orderedCommands(this._commands),
1500
+ shortcut: false,
1501
+ scope: this.el,
1502
+ label: this.msg('composer.commands'),
1503
+ placeholder: this.msg('composer.commandsPlaceholder'),
1504
+ onselect: (event) => {
1505
+ const item = event.detail.item;
1506
+ this.emit('command', { item: item[COMMAND_SOURCE] ?? item });
1507
+ }
1508
+ });
1509
+ this._launcher.open();
1510
+ }
1511
+
1512
+ /* ----------------------------------------------------------------- files -- */
1513
+
1514
+ /**
1515
+ * @private
1516
+ * @param {File[]} files
1517
+ * @param {boolean} fromPicker Whether the files came through the file input, which applied
1518
+ * `accept` already.
1519
+ * @returns {void}
1520
+ * @fires Composer#attach
1521
+ */
1522
+ _addFiles(files, fromPicker) {
1523
+ if (!this.options.attachments || this._disabled) return;
1524
+ const room = Math.max(0, (Number(this.options.maxFiles) || 0) - this._files.length);
1525
+ const taken = files
1526
+ .filter((file) => file && typeof file === 'object')
1527
+ .filter((file) => fromPicker || acceptsFile(file, this.options.accept))
1528
+ .slice(0, room);
1529
+ if (!taken.length) return;
1530
+ const event = this.emit('attach', { files: [...taken] });
1531
+ if (event.defaultPrevented || this._destroyed) return;
1532
+ for (const file of taken) this._files.push({ id: uid('zx-composer-file'), file });
1533
+ this._renderFiles();
1534
+ this._syncSend();
1535
+ }
1536
+
1537
+ /**
1538
+ * @private
1539
+ * @param {ClipboardEvent} event
1540
+ * @returns {void}
1541
+ */
1542
+ _onPaste(event) {
1543
+ const files = Array.from(event.clipboardData?.files ?? []);
1544
+ if (!files.length || !this.options.attachments || this._disabled) return;
1545
+ // A copied file also carries its name as text; a copied selection that includes an image
1546
+ // keeps its text.
1547
+ if (!Array.from(event.clipboardData?.types ?? []).includes('text/plain')) event.preventDefault();
1548
+ this._addFiles(files, false);
1549
+ }
1550
+
1551
+ /**
1552
+ * @private
1553
+ * @param {DragEvent} event
1554
+ * @returns {void}
1555
+ */
1556
+ _onDrag(event) {
1557
+ if (this._disabled || !Array.from(event.dataTransfer?.types ?? []).includes('Files')) return;
1558
+ event.preventDefault();
1559
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
1560
+ this._setDropping(true);
1561
+ }
1562
+
1563
+ /**
1564
+ * @private
1565
+ * @param {DragEvent} event
1566
+ * @returns {void}
1567
+ */
1568
+ _onDrop(event) {
1569
+ this._setDropping(false);
1570
+ const files = Array.from(event.dataTransfer?.files ?? []);
1571
+ if (this._disabled || !files.length) return;
1572
+ event.preventDefault();
1573
+ this._addFiles(files, false);
1574
+ this._input.focus();
1575
+ }
1576
+
1577
+ /**
1578
+ * @private
1579
+ * @param {boolean} dropping
1580
+ * @returns {void}
1581
+ */
1582
+ _setDropping(dropping) {
1583
+ if (dropping) this.el.setAttribute('data-state', 'dropping');
1584
+ else if (this.el.getAttribute('data-state') === 'dropping') this.el.removeAttribute('data-state');
1585
+ }
1586
+
1587
+ /* ----------------------------------------------------------------- chips -- */
1588
+
1589
+ /**
1590
+ * @private
1591
+ * @param {ContextChip} chip
1592
+ * @returns {void}
1593
+ */
1594
+ _putContext(chip) {
1595
+ if (!chip || typeof chip !== 'object' || chip.id == null || chip.label == null) return;
1596
+ const entry = { ...chip, id: String(chip.id), label: String(chip.label) };
1597
+ const index = this._context.findIndex((item) => item.id === entry.id);
1598
+ if (index >= 0) this._context[index] = entry;
1599
+ else this._context.push(entry);
1600
+ }
1601
+
1602
+ /** @private @returns {void} */
1603
+ _renderFiles() {
1604
+ const list = /** @type {HTMLElement} */ (this.refs.files);
1605
+ list.hidden = this._files.length === 0;
1606
+ list.replaceChildren(...this._files.map(({ id, file }) => this._chip({
1607
+ kind: 'file',
1608
+ id,
1609
+ label: String(file.name || ''),
1610
+ glyph: 'file',
1611
+ meta: Number.isFinite(file.size) ? formatFileSize(file.size, { decimals: 0, standard: 'si' }) : ''
1612
+ })));
1613
+ }
1614
+
1615
+ /** @private @returns {void} */
1616
+ _renderContext() {
1617
+ const list = /** @type {HTMLElement} */ (this.refs.context);
1618
+ list.hidden = this._context.length === 0;
1619
+ list.replaceChildren(...this._context.map((chip) => this._chip({
1620
+ kind: 'context', id: chip.id, label: chip.label, glyph: chip.icon ?? null, meta: ''
1621
+ })));
1622
+ }
1623
+
1624
+ /**
1625
+ * @private
1626
+ * @param {{kind: 'file'|'context', id: string, label: string, glyph: string|null, meta: string}} chip
1627
+ * @returns {HTMLElement}
1628
+ */
1629
+ _chip({ kind, id, label, glyph, meta }) {
1630
+ return h('li', { class: 'zx-composer__chip', dataset: { kind, id } },
1631
+ glyph ? icon(glyph, { size: ICON_SIZE.chip }) : null,
1632
+ h('span', { class: 'zx-composer__chip-label' }, label),
1633
+ meta ? h('span', { class: 'zx-composer__chip-meta' }, meta) : null,
1634
+ h('button', {
1635
+ type: 'button',
1636
+ class: 'zx-icon-btn zx-composer__remove',
1637
+ ariaLabel: this.msg('composer.remove', label),
1638
+ disabled: this._disabled,
1639
+ dataset: { remove: id, kind }
1640
+ }, icon('x', { size: ICON_SIZE.chip })));
1641
+ }
1642
+
1643
+ /**
1644
+ * Removes the chip whose button was pressed, and keeps the focus in the list.
1645
+ * @private
1646
+ * @param {MouseEvent} event
1647
+ * @returns {void}
1648
+ * @fires Composer#remove
1649
+ */
1650
+ _onChipClick(event) {
1651
+ const button = /** @type {HTMLElement|null} */ (/** @type {Element|null} */ (event.target)?.closest?.('[data-remove]'));
1652
+ if (!button || this._disabled) return;
1653
+ const id = String(button.dataset.remove);
1654
+ const kind = button.dataset.kind === 'context' ? 'context' : 'file';
1655
+ const list = /** @type {HTMLElement} */ (kind === 'file' ? this.refs.files : this.refs.context);
1656
+ const buttons = Array.from(list.querySelectorAll('[data-remove]'));
1657
+ const place = buttons.indexOf(button);
1658
+ /** @type {ComposerRemoveDetail} */
1659
+ let detail;
1660
+ if (kind === 'file') {
1661
+ const entry = this._files.find((item) => item.id === id);
1662
+ if (!entry) return;
1663
+ this._files = this._files.filter((item) => item !== entry);
1664
+ this._renderFiles();
1665
+ this._syncSend();
1666
+ detail = { kind, id, file: entry.file };
1667
+ } else {
1668
+ const chip = this._context.find((item) => item.id === id);
1669
+ if (!chip) return;
1670
+ this.removeContext(id);
1671
+ detail = { kind, id, chip: { ...chip } };
1672
+ }
1673
+ const rest = /** @type {HTMLElement[]} */ (Array.from(list.querySelectorAll('[data-remove]')));
1674
+ (rest[Math.min(place, rest.length - 1)] ?? this._input).focus();
1675
+ this.emit('remove', /** @type {Record<string, unknown>} */ (/** @type {unknown} */ (detail)));
1676
+ }
1677
+ }
1678
+
1679
+ /**
1680
+ * A quiet icon button in the composer's bar.
1681
+ * @param {string} name Icon name.
1682
+ * @param {string} label Accessible name.
1683
+ * @param {string} action What it does, for styling.
1684
+ * @returns {HTMLButtonElement}
1685
+ */
1686
+ function iconButton(name, label, action) {
1687
+ return /** @type {HTMLButtonElement} */ (h('button', {
1688
+ type: 'button',
1689
+ class: 'zx-icon-btn zx-composer__tool',
1690
+ ariaLabel: label,
1691
+ title: label,
1692
+ dataset: { action }
1693
+ }, icon(name, { size: ICON_SIZE.control })));
1694
+ }
1695
+
1696
+ /**
1697
+ * A copy of a queued message that shares nothing with the queue but its files.
1698
+ * @param {QueuedMessage} item
1699
+ * @returns {QueuedMessage}
1700
+ */
1701
+ function copyQueued(item) {
1702
+ return {
1703
+ ...item,
1704
+ files: [...item.files],
1705
+ mentions: item.mentions.map((mention) => ({ ...mention })),
1706
+ context: item.context.map((chip) => ({ ...chip }))
1707
+ };
1708
+ }
1709
+
1710
+ /**
1711
+ * The send key an option names; anything but `'mod+enter'` is `'enter'`.
1712
+ * @param {unknown} value
1713
+ * @returns {'enter'|'mod+enter'}
1714
+ */
1715
+ function submitKeyOf(value) {
1716
+ return value === 'mod+enter' ? 'mod+enter' : 'enter';
1717
+ }
1718
+
1719
+ /**
1720
+ * The visible Send text a `sendLabel` option asks for; empty keeps Send icon-only.
1721
+ * @param {unknown} value
1722
+ * @returns {string}
1723
+ */
1724
+ function sendLabelText(value) {
1725
+ return value == null ? '' : String(value).trim();
1726
+ }
1727
+
1728
+ /**
1729
+ * @param {ComposerOptions['mentions']} mentions
1730
+ * @returns {{trigger: string, items: MentionSource['items']}|null}
1731
+ */
1732
+ function normalizeMentionSource(mentions) {
1733
+ if (!mentions || typeof mentions !== 'object') return null;
1734
+ const items = mentions.items;
1735
+ if (!Array.isArray(items) && typeof items !== 'function') return null;
1736
+ const trigger = typeof mentions.trigger === 'string' && mentions.trigger ? mentions.trigger : '@';
1737
+ return { trigger, items };
1738
+ }
1739
+
1740
+ /**
1741
+ * @param {unknown} item
1742
+ * @returns {item is MentionItem}
1743
+ */
1744
+ function isMentionItem(item) {
1745
+ return Boolean(item) && typeof item === 'object'
1746
+ && /** @type {MentionItem} */ (item).id != null && /** @type {MentionItem} */ (item).label != null;
1747
+ }
1748
+
1749
+ /**
1750
+ * Lower case without accents, for matching.
1751
+ * @param {unknown} value
1752
+ * @returns {string}
1753
+ */
1754
+ function fold(value) {
1755
+ return String(value ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().trim();
1756
+ }
1757
+
1758
+ /**
1759
+ * @param {MentionItem} item
1760
+ * @param {string} needle Folded query.
1761
+ * @returns {number} 0 label prefix, 1 word prefix, 2 label substring, 3 id prefix or a word of the
1762
+ * description, 4 no match.
1763
+ */
1764
+ function mentionRank(item, needle) {
1765
+ const label = fold(item.label);
1766
+ if (label.startsWith(needle)) return 0;
1767
+ if (words(item.label).some((word) => word.startsWith(needle))) return 1;
1768
+ if (label.includes(needle)) return 2;
1769
+ if (fold(item.id).startsWith(needle) || words(item.description).some((word) => word.startsWith(needle))) return 3;
1770
+ return 4;
1771
+ }
1772
+
1773
+ /**
1774
+ * The folded words of a text.
1775
+ * @param {unknown} value
1776
+ * @returns {string[]}
1777
+ */
1778
+ function words(value) {
1779
+ return fold(value).split(/[^\p{L}\p{N}]+/u).filter(Boolean);
1780
+ }
1781
+
1782
+ /**
1783
+ * Copies of the commands that keep the application's order among equally ranked results (the
1784
+ * launcher otherwise sorts them by label), each remembering the item it was made from.
1785
+ * @param {LauncherItem[]} items
1786
+ * @returns {LauncherItem[]}
1787
+ */
1788
+ function orderedCommands(items) {
1789
+ return items.filter((item) => item && typeof item === 'object').map((item, index) => ({
1790
+ ...item,
1791
+ itemOrder: item.itemOrder ?? index,
1792
+ items: Array.isArray(item.items) ? orderedCommands(item.items) : item.items,
1793
+ [COMMAND_SOURCE]: item
1794
+ }));
1795
+ }
1796
+
1797
+ /** @returns {boolean} Whether the platform's command modifier is Cmd. */
1798
+ function isApplePlatform() {
1799
+ const nav = globalThis.navigator;
1800
+ if (!nav) return false;
1801
+ const platform = /** @type {{userAgentData?: {platform?: string}}} */ (nav).userAgentData?.platform || nav.platform || '';
1802
+ return /mac|iphone|ipad|ios/i.test(platform);
1803
+ }
1804
+
1805
+ /** Fired when the message is sent; preventable, which keeps the text and files. @event Composer#send @type {CustomEvent<ComposerSendDetail>} */
1806
+ /** Fired when Stop is pressed, or Escape in the text while busy. @event Composer#stop @type {CustomEvent<Record<string, never>>} */
1807
+ /** Fired when the reader changes the text. @event Composer#input @type {CustomEvent<{text: string}>} */
1808
+ /** Fired before files are attached; preventable. @event Composer#attach @type {CustomEvent<{files: File[]}>} */
1809
+ /** Fired after the reader removes an attachment or a context chip. @event Composer#remove @type {CustomEvent<ComposerRemoveDetail>} */
1810
+ /** Fired when a suggestion is picked. @event Composer#mention @type {CustomEvent<{item: MentionItem}>} */
1811
+ /** Fired when a command is chosen. @event Composer#command @type {CustomEvent<{item: LauncherItem}>} */
1812
+ /** Fired when one of the extra tools is pressed; the composer changes nothing itself. @event Composer#tool @type {CustomEvent<ComposerToolDetail>} */
1813
+ /** Fired when a message is added to the queue. @event Composer#queue @type {CustomEvent<ComposerQueueDetail>} */
1814
+ /** Fired when a message leaves the queue: sent, removed, taken back to edit, or cleared. @event Composer#dequeue @type {CustomEvent<ComposerDequeueDetail>} */
1815
+ /** Fired for ArrowUp on an empty text. @event Composer#historyprevious @type {CustomEvent<Record<string, never>>} */