@zeyos/zx 5.7.0 → 5.8.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 (330) hide show
  1. package/CHANGELOG.md +330 -0
  2. package/README.md +47 -9
  3. package/dist/types/components/activity-item/activity-item.d.ts +14 -3
  4. package/dist/types/components/agent-avatar/agent-avatar.d.ts +165 -0
  5. package/dist/types/components/agent-avatar/agent-face.d.ts +93 -0
  6. package/dist/types/components/agent-thread/ag-ui.d.ts +21 -9
  7. package/dist/types/components/agent-thread/agent-thread.d.ts +26 -0
  8. package/dist/types/components/agent-thread/ui-message-stream.d.ts +3 -1
  9. package/dist/types/components/approval-card/approval-card.d.ts +31 -2
  10. package/dist/types/components/aurora/aurora.d.ts +31 -5
  11. package/dist/types/components/calendar/calendar.d.ts +39 -26
  12. package/dist/types/components/chart/chart.d.ts +250 -20
  13. package/dist/types/components/chart/color.d.ts +66 -0
  14. package/dist/types/components/chart/svg-adapter.d.ts +103 -0
  15. package/dist/types/components/chart/svg-geometry.d.ts +203 -0
  16. package/dist/types/components/check-button/check-button.d.ts +1 -4
  17. package/dist/types/components/checklist/checklist.d.ts +48 -5
  18. package/dist/types/components/code-editor/code-editor.d.ts +55 -1
  19. package/dist/types/components/composer/composer.d.ts +41 -6
  20. package/dist/types/components/context-menu/context-menu.d.ts +36 -8
  21. package/dist/types/components/copy/copy-button.d.ts +6 -0
  22. package/dist/types/components/copy/copy-input.d.ts +1 -0
  23. package/dist/types/components/date-picker/date-picker.d.ts +14 -0
  24. package/dist/types/components/date-picker/time-picker.d.ts +26 -17
  25. package/dist/types/components/datebox/datebox.d.ts +8 -4
  26. package/dist/types/components/dialog/dialog.d.ts +15 -4
  27. package/dist/types/components/empty-state/empty-state.d.ts +10 -1
  28. package/dist/types/components/field/field.d.ts +4 -2
  29. package/dist/types/components/form/form.d.ts +2 -1
  30. package/dist/types/components/kanban-view/kanban-card.d.ts +7 -0
  31. package/dist/types/components/kanban-view/kanban-view.d.ts +15 -3
  32. package/dist/types/components/launcher/launcher.d.ts +26 -0
  33. package/dist/types/components/master-panel/master-panel.d.ts +9 -4
  34. package/dist/types/components/menu-button/menu-button.d.ts +29 -5
  35. package/dist/types/components/message/message.d.ts +308 -5
  36. package/dist/types/components/modal/modal.d.ts +45 -8
  37. package/dist/types/components/modal/native-dialog.d.ts +40 -0
  38. package/dist/types/components/module-bar/module-bar.d.ts +9 -2
  39. package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +5 -4
  40. package/dist/types/components/number-field/number-field.d.ts +31 -1
  41. package/dist/types/components/pagination/pagination.d.ts +341 -19
  42. package/dist/types/components/run-status/run-status.d.ts +26 -0
  43. package/dist/types/components/run-trace/run-trace.d.ts +10 -6
  44. package/dist/types/components/search/search.d.ts +16 -4
  45. package/dist/types/components/select/select.d.ts +19 -1
  46. package/dist/types/components/sheet/sheet.d.ts +20 -6
  47. package/dist/types/components/slider/slider.d.ts +2 -1
  48. package/dist/types/components/stat-tile/stat-tile.d.ts +20 -3
  49. package/dist/types/components/stepper/stepper.d.ts +17 -4
  50. package/dist/types/components/surface/catalog.d.ts +61 -17
  51. package/dist/types/components/surface/surface.d.ts +6 -4
  52. package/dist/types/components/table/table.d.ts +207 -5
  53. package/dist/types/components/table/window.d.ts +25 -1
  54. package/dist/types/components/toggle/toggle.d.ts +38 -6
  55. package/dist/types/components/tooltip/tooltip.d.ts +5 -4
  56. package/dist/types/components/tree/tree.d.ts +43 -6
  57. package/dist/types/components/truncate/truncate.d.ts +4 -2
  58. package/dist/types/components/value-list/value-list.d.ts +9 -2
  59. package/dist/types/core/date.d.ts +2 -1
  60. package/dist/types/core/dom.d.ts +14 -0
  61. package/dist/types/core/drag-axis.d.ts +10 -5
  62. package/dist/types/core/export.d.ts +2 -2
  63. package/dist/types/core/format.d.ts +3 -1
  64. package/dist/types/core/icons.d.ts +36 -3
  65. package/dist/types/core/keyboard.d.ts +7 -3
  66. package/dist/types/core/messages.d.ts +3 -0
  67. package/dist/types/core/storage.d.ts +4 -3
  68. package/dist/types/core/util.d.ts +3 -1
  69. package/dist/types/elements/define.d.ts +5 -2
  70. package/dist/types/index.d.ts +6 -4
  71. package/dist/types/internal/agent-model.d.ts +99 -0
  72. package/dist/types/internal/app-rail.d.ts +37 -2
  73. package/dist/types/internal/collections.d.ts +18 -0
  74. package/dist/types/internal/menu-items.d.ts +27 -0
  75. package/dist/types/internal/overlay-content.d.ts +23 -0
  76. package/dist/types/internal/presence-loop.d.ts +5 -2
  77. package/dist/types/locales/index.d.ts +3 -0
  78. package/dist/types/zeyos/calendar.d.ts +43 -7
  79. package/dist/types/zeyos/connect.d.ts +4 -0
  80. package/dist/types/zeyos/form.d.ts +13 -5
  81. package/dist/types/zeyos/select.d.ts +5 -2
  82. package/dist/types/zeyos/table.d.ts +16 -8
  83. package/dist/types/zeyos/view.d.ts +2 -1
  84. package/dist/zx-zeyos.esm.js +3161 -515
  85. package/dist/zx-zeyos.esm.min.js +4 -4
  86. package/dist/zx.core.css +4 -0
  87. package/dist/zx.core.min.css +1 -1
  88. package/dist/zx.css +970 -57
  89. package/dist/zx.esm.js +6405 -2249
  90. package/dist/zx.esm.min.js +26 -26
  91. package/dist/zx.global.js +6405 -2249
  92. package/dist/zx.global.min.js +26 -26
  93. package/dist/zx.layered.css +972 -57
  94. package/dist/zx.layered.min.css +1 -1
  95. package/dist/zx.min.css +1 -1
  96. package/docs/agent-catalog.json +159 -1
  97. package/docs/agent-surfaces.md +21 -21
  98. package/docs/api.json +3154 -518
  99. package/docs/components/account-menu.md +24 -0
  100. package/docs/components/activity-item.md +23 -0
  101. package/docs/components/activity-list.md +28 -0
  102. package/docs/components/agent-avatar.md +59 -0
  103. package/docs/components/agent-thread.md +275 -0
  104. package/docs/components/app-icon.md +36 -0
  105. package/docs/components/app-sidebar.md +92 -0
  106. package/docs/components/approval-card.md +71 -0
  107. package/docs/components/aurora.md +34 -0
  108. package/docs/components/avatar.md +37 -0
  109. package/docs/components/badge.md +36 -0
  110. package/docs/components/block-view.md +34 -0
  111. package/docs/components/breadcrumb.md +20 -0
  112. package/docs/components/button.md +23 -0
  113. package/docs/components/calendar.md +68 -0
  114. package/docs/components/card-view.md +73 -0
  115. package/docs/components/card.md +25 -0
  116. package/docs/components/chart.md +109 -0
  117. package/docs/components/check-button.md +16 -0
  118. package/docs/components/checklist.md +19 -0
  119. package/docs/components/code-editor.md +38 -0
  120. package/docs/components/composer.md +107 -0
  121. package/docs/components/context-menu.md +32 -0
  122. package/docs/components/copy.md +37 -0
  123. package/docs/components/data-filter.md +16 -0
  124. package/docs/components/date-picker.md +31 -0
  125. package/docs/components/date-range.md +21 -0
  126. package/docs/components/datebox.md +31 -0
  127. package/docs/components/dialog.md +25 -0
  128. package/docs/components/dock.md +57 -0
  129. package/docs/components/dropdown.md +39 -0
  130. package/docs/components/elements.md +63 -0
  131. package/docs/components/empty-state.md +17 -0
  132. package/docs/components/entity-ref.md +26 -0
  133. package/docs/components/field-upload.md +18 -0
  134. package/docs/components/file-item.md +27 -0
  135. package/docs/components/file-list.md +23 -0
  136. package/docs/components/filter-panel.md +45 -0
  137. package/docs/components/filter.md +47 -0
  138. package/docs/components/finder.md +25 -0
  139. package/docs/components/form-widgets.md +42 -0
  140. package/docs/components/form.md +80 -0
  141. package/docs/components/grid.md +26 -0
  142. package/docs/components/groupbox.md +11 -0
  143. package/docs/components/helpers.md +359 -0
  144. package/docs/components/icons.md +87 -0
  145. package/docs/components/index.md +99 -0
  146. package/docs/components/kanban-view.md +42 -0
  147. package/docs/components/kbd.md +23 -0
  148. package/docs/components/kernel.md +41 -0
  149. package/docs/components/launcher.md +66 -0
  150. package/docs/components/layout.md +33 -0
  151. package/docs/components/list-toolbar.md +38 -0
  152. package/docs/components/loading.md +48 -0
  153. package/docs/components/menu-button.md +47 -0
  154. package/docs/components/message.md +76 -0
  155. package/docs/components/modal.md +27 -0
  156. package/docs/components/module-bar.md +71 -0
  157. package/docs/components/multi-value-editor.md +16 -0
  158. package/docs/components/navigation-bar.md +22 -0
  159. package/docs/components/number-field.md +34 -0
  160. package/docs/components/pagination.md +73 -0
  161. package/docs/components/panel.md +28 -0
  162. package/docs/components/prompt-starters.md +40 -0
  163. package/docs/components/prose.md +38 -0
  164. package/docs/components/questionnaire.md +115 -0
  165. package/docs/components/rating.md +19 -0
  166. package/docs/components/run-status.md +50 -0
  167. package/docs/components/run-trace.md +72 -0
  168. package/docs/components/search.md +11 -0
  169. package/docs/components/select.md +129 -0
  170. package/docs/components/sheet-stack.md +39 -0
  171. package/docs/components/sheet.md +77 -0
  172. package/docs/components/skeleton.md +27 -0
  173. package/docs/components/slider.md +29 -0
  174. package/docs/components/sort-control.md +21 -0
  175. package/docs/components/source-list.md +30 -0
  176. package/docs/components/split-view.md +12 -0
  177. package/docs/components/stat-tile.md +49 -0
  178. package/docs/components/stepper.md +27 -0
  179. package/docs/components/surface.md +152 -0
  180. package/docs/components/tabbox.md +33 -0
  181. package/docs/components/table-view.md +43 -0
  182. package/docs/components/table.md +232 -0
  183. package/docs/components/tag-picker.md +39 -0
  184. package/docs/components/timebox.md +16 -0
  185. package/docs/components/toggle.md +21 -0
  186. package/docs/components/tokens.md +82 -0
  187. package/docs/components/toolbar.md +26 -0
  188. package/docs/components/tooltip.md +16 -0
  189. package/docs/components/tree.md +48 -0
  190. package/docs/components/truncate.md +21 -0
  191. package/docs/components/value-list.md +14 -0
  192. package/docs/components/view-settings.md +56 -0
  193. package/docs/components/workspace-switcher.md +42 -0
  194. package/docs/components/zeyos.md +196 -0
  195. package/docs/llms-small.txt +299 -0
  196. package/docs/llms.md +725 -109
  197. package/docs/llms.txt +46 -19
  198. package/package.json +9 -4
  199. package/src/components/activity-item/activity-item.js +21 -2
  200. package/src/components/agent-avatar/agent-avatar.css +195 -0
  201. package/src/components/agent-avatar/agent-avatar.js +333 -0
  202. package/src/components/agent-avatar/agent-face.js +292 -0
  203. package/src/components/agent-thread/ag-ui.js +44 -11
  204. package/src/components/agent-thread/agent-thread.js +103 -11
  205. package/src/components/agent-thread/ui-message-stream.js +3 -1
  206. package/src/components/app-rail/app-rail.css +5 -0
  207. package/src/components/app-sidebar/app-sidebar.css +3 -0
  208. package/src/components/app-sidebar/app-sidebar.js +4 -3
  209. package/src/components/approval-card/approval-card.css +6 -0
  210. package/src/components/approval-card/approval-card.js +55 -7
  211. package/src/components/aurora/aurora.css +149 -14
  212. package/src/components/aurora/aurora.js +49 -6
  213. package/src/components/button/button.css +24 -11
  214. package/src/components/calendar/calendar.css +6 -2
  215. package/src/components/calendar/calendar.js +127 -47
  216. package/src/components/card-view/card-view.js +5 -6
  217. package/src/components/chart/chart.css +159 -1
  218. package/src/components/chart/chart.js +450 -62
  219. package/src/components/chart/color.js +297 -0
  220. package/src/components/chart/svg-adapter.js +576 -0
  221. package/src/components/chart/svg-geometry.js +323 -0
  222. package/src/components/check-button/check-button.js +3 -18
  223. package/src/components/checklist/checklist.css +9 -1
  224. package/src/components/checklist/checklist.js +105 -20
  225. package/src/components/checklist/field-adapter.js +6 -12
  226. package/src/components/code-editor/code-editor.css +33 -0
  227. package/src/components/code-editor/code-editor.js +97 -8
  228. package/src/components/code-editor/field-adapter.js +3 -0
  229. package/src/components/composer/composer.css +3 -0
  230. package/src/components/composer/composer.js +100 -22
  231. package/src/components/context-menu/context-menu.js +41 -5
  232. package/src/components/copy/copy-button.js +9 -1
  233. package/src/components/copy/copy-input.js +5 -0
  234. package/src/components/data-filter/filter-core.js +0 -1
  235. package/src/components/date-picker/date-picker.css +8 -0
  236. package/src/components/date-picker/date-picker.js +47 -8
  237. package/src/components/date-picker/date-range-picker.js +1 -1
  238. package/src/components/date-picker/month-picker.js +19 -3
  239. package/src/components/date-picker/time-picker.js +54 -19
  240. package/src/components/datebox/date-range-box.js +7 -3
  241. package/src/components/datebox/datebox.js +32 -6
  242. package/src/components/dialog/dialog.css +6 -0
  243. package/src/components/dialog/dialog.js +24 -33
  244. package/src/components/dropdown/dropdown.js +1 -18
  245. package/src/components/empty-state/empty-state.js +21 -2
  246. package/src/components/field/field.js +19 -3
  247. package/src/components/fieldset/fieldset.js +3 -1
  248. package/src/components/filter/filter.js +9 -0
  249. package/src/components/form/form.js +19 -2
  250. package/src/components/kanban-view/kanban-card.js +15 -2
  251. package/src/components/kanban-view/kanban-view.css +21 -0
  252. package/src/components/kanban-view/kanban-view.js +29 -16
  253. package/src/components/launcher/launcher.css +14 -0
  254. package/src/components/launcher/launcher.js +54 -9
  255. package/src/components/master-panel/master-panel.js +24 -22
  256. package/src/components/menu-button/menu-button.js +26 -4
  257. package/src/components/message/message.css +228 -29
  258. package/src/components/message/message.js +664 -30
  259. package/src/components/modal/modal.js +129 -30
  260. package/src/components/modal/native-dialog.js +91 -0
  261. package/src/components/module-bar/module-bar.css +3 -0
  262. package/src/components/module-bar/module-bar.js +17 -4
  263. package/src/components/multi-value-editor/multi-value-editor.css +7 -2
  264. package/src/components/multi-value-editor/multi-value-editor.js +3 -2
  265. package/src/components/navigation-bar/navigation-bar.js +13 -1
  266. package/src/components/number-field/field-adapter.js +3 -0
  267. package/src/components/number-field/number-field.js +70 -16
  268. package/src/components/pagination/pagination.css +26 -2
  269. package/src/components/pagination/pagination.js +551 -65
  270. package/src/components/prose/prose.js +7 -1
  271. package/src/components/rating/field-adapter.js +3 -0
  272. package/src/components/run-status/run-status.js +43 -3
  273. package/src/components/run-trace/run-trace.js +15 -7
  274. package/src/components/search/search.js +3 -18
  275. package/src/components/select/field-adapter.js +8 -1
  276. package/src/components/select/select.js +68 -13
  277. package/src/components/sheet/sheet.js +39 -13
  278. package/src/components/slider/field-adapter.js +3 -0
  279. package/src/components/slider/slider.js +4 -6
  280. package/src/components/stat-tile/stat-tile.js +24 -9
  281. package/src/components/stepper/stepper.css +15 -0
  282. package/src/components/stepper/stepper.js +34 -2
  283. package/src/components/surface/catalog.js +185 -28
  284. package/src/components/surface/surface.js +10 -5
  285. package/src/components/tabbox/tabbox.js +13 -1
  286. package/src/components/table/table.css +160 -2
  287. package/src/components/table/table.js +479 -52
  288. package/src/components/table/window.js +46 -4
  289. package/src/components/table-view/table-view.js +1 -10
  290. package/src/components/tag-picker/field-adapter.js +3 -0
  291. package/src/components/tag-picker/tag-picker.js +2 -0
  292. package/src/components/timebox/field-adapter.js +3 -0
  293. package/src/components/toggle/toggle.js +51 -27
  294. package/src/components/tooltip/tooltip.js +21 -14
  295. package/src/components/tree/tree.js +87 -14
  296. package/src/components/truncate/truncate.js +21 -5
  297. package/src/components/value-list/value-list.js +37 -9
  298. package/src/components/view-settings/view-settings.js +1 -5
  299. package/src/core/component.js +34 -2
  300. package/src/core/date.js +5 -4
  301. package/src/core/dom.js +45 -2
  302. package/src/core/drag-axis.js +24 -7
  303. package/src/core/export.js +4 -4
  304. package/src/core/fontawesome.js +34 -3
  305. package/src/core/format.js +3 -1
  306. package/src/core/http.js +23 -11
  307. package/src/core/icons.js +60 -8
  308. package/src/core/keyboard.js +83 -9
  309. package/src/core/messages.js +3 -0
  310. package/src/core/position.js +4 -3
  311. package/src/core/storage.js +80 -31
  312. package/src/core/util.js +16 -5
  313. package/src/elements/define.js +82 -47
  314. package/src/elements/kit.js +46 -35
  315. package/src/index.js +8 -4
  316. package/src/internal/agent-model.js +152 -0
  317. package/src/internal/app-rail.js +53 -2
  318. package/src/internal/collections.js +25 -0
  319. package/src/internal/menu-items.js +59 -0
  320. package/src/internal/overlay-content.js +35 -0
  321. package/src/internal/presence-loop.js +61 -14
  322. package/src/locales/de.js +3 -0
  323. package/src/zeyos/calendar.js +81 -19
  324. package/src/zeyos/connect.js +5 -1
  325. package/src/zeyos/form.js +29 -10
  326. package/src/zeyos/select.js +36 -12
  327. package/src/zeyos/table.js +43 -11
  328. package/src/zeyos/view.js +2 -1
  329. package/styles/tokens/semantic.css +7 -1
  330. package/styles/zx.css +1 -0
@@ -66,3 +66,36 @@
66
66
  .zx-code-editor[data-disabled="true"] {
67
67
  opacity: 0.6;
68
68
  }
69
+
70
+ /* The error state, whoever declares it: a standalone editor through setHighlight(), or a Field
71
+ marking the textarea it labels. Either way the frame says so, as a field's control does. */
72
+ .zx-code-editor[data-state="danger"],
73
+ .zx-code-editor:has(.zx-code-editor__input[aria-invalid="true"]) {
74
+ border-color: var(--zx-color-danger);
75
+ }
76
+
77
+ /* The message of a standalone editor: a Field's highlight text, set under the source. */
78
+ .zx-code-editor__highlight {
79
+ padding: var(--zx-space-2) var(--zx-space-3);
80
+ border-block-start: 1px solid var(--zx-color-border);
81
+ color: var(--zx-color-text-muted);
82
+ font-size: var(--zx-text-sm);
83
+ overflow-wrap: anywhere;
84
+ }
85
+
86
+ .zx-code-editor__highlight[hidden] {
87
+ display: none;
88
+ }
89
+
90
+ .zx-code-editor[data-state="danger"] .zx-code-editor__highlight {
91
+ border-block-start-color: var(--zx-color-danger);
92
+ color: var(--zx-color-danger);
93
+ }
94
+
95
+ .zx-code-editor[data-state="warning"] .zx-code-editor__highlight {
96
+ color: var(--zx-color-warning);
97
+ }
98
+
99
+ .zx-code-editor[data-state="success"] .zx-code-editor__highlight {
100
+ color: var(--zx-color-success);
101
+ }
@@ -1,5 +1,6 @@
1
1
  import { Component } from '../../core/component.js';
2
2
  import { h } from '../../core/dom.js';
3
+ import { uid } from '../../core/util.js';
3
4
 
4
5
  /**
5
6
  * @typedef {Object} CodeEditorOptions
@@ -10,7 +11,13 @@ import { h } from '../../core/dom.js';
10
11
  * message ("Code editor").
11
12
  * @property {string} [placeholder=''] Placeholder text.
12
13
  * @property {number} [rows=12] Visible textarea rows.
13
- * @property {string} [indent='\t'] Text inserted by Tab and removed by Shift+Tab.
14
+ * @property {string} [indent='\t'] Text inserted by Tab and removed by Shift+Tab — a tab by
15
+ * default, `' '` for two spaces. While it is non-empty the editor captures Tab: Tab inserts it at
16
+ * the caret or indents every selected line, Shift+Tab outdents them, and focus stays in the
17
+ * editor. Escape releases the capture for the next keystroke, so Escape then Tab (or Shift+Tab)
18
+ * moves focus on. `indent: ''` switches the capture off: Tab and Shift+Tab move focus as in any
19
+ * other field and nothing is indented. Tab with Ctrl, Alt or Meta, and Tab in a read-only or
20
+ * disabled editor, are never captured.
14
21
  * @property {'off'|'soft'|'hard'} [wrap='off'] Textarea wrapping behavior.
15
22
  * @property {boolean} [spellcheck=false] Whether browser spellcheck is enabled.
16
23
  * @property {boolean} [readOnly=false] Whether content can be selected but not changed.
@@ -18,6 +25,8 @@ import { h } from '../../core/dom.js';
18
25
  * @property {boolean} [status=true] Whether the line/column status is visible.
19
26
  * @property {(event: CustomEvent<{value:string}>) => void} [oninput] Input listener.
20
27
  * @property {(event: CustomEvent<{value:string}>) => void} [onchange] Change listener.
28
+ * @property {(event: CustomEvent<{message:string}>) => void} [oninvalid] Listener called when
29
+ * `setHighlight()` puts the editor in its error state.
21
30
  */
22
31
 
23
32
  /** Keys that only modify the next one: pressing them is not the keystroke that ends a Tab release. */
@@ -31,8 +40,13 @@ const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta', 'AltGraph', 'C
31
40
  * Capturing Tab is what a code surface has to do, and it would be a keyboard trap if nothing undid
32
41
  * it: Escape releases the capture until the next keystroke in the editor, so Escape then Tab (or
33
42
  * Shift+Tab) moves focus out of the editor as it would leave any other field.
43
+ *
44
+ * A standalone editor reports a validation or status message the way a Field does, with
45
+ * `setHighlight()` and `clearHighlight()`. Inside a Field (the `code` field type) the Field's own
46
+ * message is the one to set; it marks the editor's textarea invalid and the frame follows.
34
47
  * @fires CodeEditor#input
35
48
  * @fires CodeEditor#change
49
+ * @fires CodeEditor#invalid
36
50
  * @extends {Component<CodeEditorOptions>}
37
51
  */
38
52
  export class CodeEditor extends Component {
@@ -60,15 +74,13 @@ export class CodeEditor extends Component {
60
74
  const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
61
75
  this.el = root;
62
76
  this._initialChildren = this._createdRoot ? [] : [...root.childNodes];
63
- this._initialAttributes = new Map(['data-language', 'data-readonly', 'data-disabled']
77
+ this._initialAttributes = new Map(['data-language', 'data-readonly', 'data-disabled', 'data-state']
64
78
  .map((name) => [name, root.getAttribute(name)]));
65
79
  this._language = normalizeLanguage(this.options.language);
66
80
  this._languageLabel = h('span', { class: 'zx-code-editor__language' }, this._language);
67
- this._position = h('span', {
68
- class: 'zx-code-editor__position',
69
- role: 'status',
70
- ariaLive: 'polite'
71
- });
81
+ // A visible readout, not a live region: announced on every caret move it would talk over
82
+ // each keystroke.
83
+ this._position = h('span', { class: 'zx-code-editor__position' });
72
84
  this._header = h('div', { class: 'zx-code-editor__header' }, this._languageLabel,
73
85
  this.options.status ? this._position : null);
74
86
  this._input = /** @type {HTMLTextAreaElement} */ (h('textarea', {
@@ -84,13 +96,19 @@ export class CodeEditor extends Component {
84
96
  autocomplete: 'off',
85
97
  autocapitalize: 'off'
86
98
  }));
99
+ this._highlight = h('div', {
100
+ class: 'zx-code-editor__highlight',
101
+ id: uid('zx-code-editor-highlight'),
102
+ ariaLive: 'polite',
103
+ hidden: true
104
+ });
87
105
  this._input.value = String(this.options.value ?? '');
88
106
  this._committedValue = this._input.value;
89
107
  this._indentEditing = false;
90
108
  root.dataset.language = this._language;
91
109
  root.dataset.readonly = String(Boolean(this.options.readOnly));
92
110
  root.dataset.disabled = String(Boolean(this.options.disabled));
93
- root.replaceChildren(this._header, this._input);
111
+ root.replaceChildren(this._header, this._input, this._highlight);
94
112
  /** Set by Escape: the next Tab moves focus instead of indenting. */
95
113
  this._tabReleased = false;
96
114
 
@@ -139,6 +157,56 @@ export class CodeEditor extends Component {
139
157
  return this;
140
158
  }
141
159
 
160
+ /**
161
+ * Returns the native textarea — the element that carries the editor's name, validity and
162
+ * description, and the one a `<label for>` or a Field labels.
163
+ * @returns {HTMLTextAreaElement}
164
+ */
165
+ getInput() { return this._input; }
166
+
167
+ /**
168
+ * Displays a validation or status message under the text, as `Field#setHighlight()` does for a
169
+ * field: the kind is reflected as `data-state` on the root, and `'danger'` is the error state —
170
+ * the textarea gets `aria-invalid="true"`, the message is announced as an alert, the frame takes
171
+ * the danger colour, and `invalid` is emitted. The message is the textarea's description
172
+ * (`aria-describedby`) for as long as it is shown. An empty message clears it.
173
+ * @param {string} message Message text.
174
+ * @param {'danger'|'warning'|'success'} [kind='danger'] Message kind.
175
+ * @returns {this}
176
+ * @fires CodeEditor#invalid
177
+ */
178
+ setHighlight(message, kind = 'danger') {
179
+ if (!message) return this.clearHighlight();
180
+ const normalizedKind = ['danger', 'warning', 'success'].includes(kind) ? kind : 'danger';
181
+ this.el.dataset.state = normalizedKind;
182
+ this._highlight.textContent = String(message);
183
+ this._highlight.hidden = false;
184
+ this._describe(true);
185
+ if (normalizedKind === 'danger') {
186
+ this._highlight.setAttribute('role', 'alert');
187
+ this._input.setAttribute('aria-invalid', 'true');
188
+ this.emit('invalid', { message: String(message) });
189
+ } else {
190
+ this._highlight.removeAttribute('role');
191
+ this._input.removeAttribute('aria-invalid');
192
+ }
193
+ return this;
194
+ }
195
+
196
+ /**
197
+ * Clears the current validation or status message.
198
+ * @returns {this}
199
+ */
200
+ clearHighlight() {
201
+ delete this.el.dataset.state;
202
+ this._highlight.textContent = '';
203
+ this._highlight.hidden = true;
204
+ this._highlight.removeAttribute('role');
205
+ this._input.removeAttribute('aria-invalid');
206
+ this._describe(false);
207
+ return this;
208
+ }
209
+
142
210
  /** @returns {this} */
143
211
  focus() { this._input.focus(); return this; }
144
212
 
@@ -205,6 +273,21 @@ export class CodeEditor extends Component {
205
273
  this.emit('input', { value: this.getValue() });
206
274
  }
207
275
 
276
+ /**
277
+ * Adds the message to, or takes it out of, the textarea's `aria-describedby`, leaving any id
278
+ * something else put there (a Field's description) in place.
279
+ * @param {boolean} described Whether the message describes the textarea.
280
+ * @returns {void}
281
+ */
282
+ _describe(described) {
283
+ const id = this._highlight.id;
284
+ const ids = (this._input.getAttribute('aria-describedby') ?? '').split(/\s+/)
285
+ .filter((value) => value && value !== id);
286
+ if (described) ids.push(id);
287
+ if (ids.length) this._input.setAttribute('aria-describedby', ids.join(' '));
288
+ else this._input.removeAttribute('aria-describedby');
289
+ }
290
+
208
291
  /** Commits once, whether the browser emits change before blur or the fallback edited text. @returns {void} */
209
292
  _commitValue() {
210
293
  const value = this.getValue();
@@ -341,3 +424,9 @@ function clampIndex(value, length) {
341
424
  * @event CodeEditor#change
342
425
  * @type {CustomEvent<{value:string}>}
343
426
  */
427
+
428
+ /**
429
+ * Emitted when `setHighlight()` puts the editor in its error state (`kind: 'danger'`).
430
+ * @event CodeEditor#invalid
431
+ * @type {CustomEvent<{message:string}>}
432
+ */
@@ -27,6 +27,9 @@ export function registerCodeEditorFieldAdapter() {
27
27
  editor.on('input', (event) => field.emit('input', { value: event.detail.value }));
28
28
  return {
29
29
  el: editor.el,
30
+ // The textarea, not the frame, is what the label names and what is invalid: the Field's
31
+ // message then describes it, and the editor draws its error frame from `aria-invalid`.
32
+ labelTarget: editor.getInput(),
30
33
  get: () => editor.getValue(),
31
34
  set: (value) => {
32
35
  setting = true;
@@ -436,6 +436,9 @@
436
436
  color: var(--zx-color-text-subtle);
437
437
  }
438
438
 
439
+ /* An agent mention draws its face, a little larger than a glyph. */
440
+ .zx-composer__option > .zx-agent-avatar { --zx-agent-avatar-size: var(--zx-space-5); }
441
+
439
442
  .zx-composer__option-text {
440
443
  display: grid;
441
444
  min-inline-size: 0;
@@ -7,6 +7,8 @@ import { rovingTabindex } from '../../core/keyboard.js';
7
7
  import { position } from '../../core/position.js';
8
8
  import { storage } from '../../core/storage.js';
9
9
  import { uid } from '../../core/util.js';
10
+ import { AGENT_ITEM_KEYS, agentAvatarOptions, mentionPattern } from '../../internal/agent-model.js';
11
+ import { AgentAvatar } from '../agent-avatar/agent-avatar.js';
10
12
  import { Dialog } from '../dialog/dialog.js';
11
13
  import { keyLabels } from '../kbd/kbd.js';
12
14
  import { Launcher } from '../launcher/launcher.js';
@@ -23,6 +25,9 @@ import {
23
25
  * @property {string} label Visible name; picking the item writes `@<label> ` into the text.
24
26
  * @property {string} [description] Secondary line in the suggestion list.
25
27
  * @property {string} [icon] Icon name drawn before the label.
28
+ * @property {import('../../internal/app-rail.js').AppNavAgent|true} [agent] Draws the item as an
29
+ * agent: its AgentAvatar, still, in place of `icon` — these options, or `true` to derive it from
30
+ * the label. An activity's word joins the option's accessible name.
26
31
  */
27
32
 
28
33
  /**
@@ -127,8 +132,9 @@ import {
127
132
  * the line. `'mod+enter'`: Cmd+Enter (Ctrl+Enter elsewhere) sends and Enter breaks the line.
128
133
  * @property {boolean} [busy=false] Whether an agent is working: Send becomes Stop.
129
134
  * @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.
135
+ * It is sent when the agent is no longer busy, one message each time busy ends, in order; busy that
136
+ * ends while the composer is disabled sends when it is enabled again. The queue lives as long as
137
+ * the composer: it is not kept with the draft.
132
138
  * @property {number} [queueLimit=10] Most messages that wait at once. At the limit the send key is
133
139
  * refused, and the hint says why.
134
140
  * @property {boolean} [disabled=false] Whether the composer takes no input.
@@ -243,7 +249,9 @@ export function filterMentions(items, query) {
243
249
  }
244
250
 
245
251
  /**
246
- * The picked mentions whose `@<label>` is still in the text, each once.
252
+ * The picked mentions whose `@<label>` is still in the text as a whole mention, each once: not
253
+ * right after a letter or digit (`ann@ledger.example` mentions nobody) and not right before one
254
+ * (`@Annabel` does not mention Ann), in any script — the rule AgentThread marks mentions by.
247
255
  * @param {string} text
248
256
  * @param {MentionItem[]} mentions Mentions in the order they were picked.
249
257
  * @param {string} [trigger='@']
@@ -255,7 +263,7 @@ export function mentionsInText(text, mentions, trigger = '@') {
255
263
  return (Array.isArray(mentions) ? mentions : []).filter((item) => {
256
264
  if (!isMentionItem(item)) return false;
257
265
  const key = String(item.id);
258
- if (seen.has(key) || !source.includes(`${trigger}${item.label}`)) return false;
266
+ if (seen.has(key) || !mentionPattern([item.label], trigger)?.test(source)) return false;
259
267
  seen.add(key);
260
268
  return true;
261
269
  });
@@ -417,6 +425,12 @@ export class Composer extends Component {
417
425
  const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
418
426
  this.el = root;
419
427
  this._original = created ? null : snapshotTarget(root);
428
+ /**
429
+ * The faces of agent mentions, one per item id, reused while the list redraws on every
430
+ * keystroke and destroyed with the composer.
431
+ * @type {Map<string, {signature: string, avatar: AgentAvatar}>}
432
+ */
433
+ this._mentionFaces = new Map();
420
434
  if (!created) root.replaceChildren();
421
435
 
422
436
  const options = this.options;
@@ -450,6 +464,10 @@ export class Composer extends Component {
450
464
  /** Whether a queued message is being sent, and whether busy ended again meanwhile. */
451
465
  this._sendingQueued = false;
452
466
  this._busyEndedAgain = false;
467
+ /** Whether busy ended while input was off, so a queued message goes when it is back on. */
468
+ this._sendOwed = false;
469
+ /** @type {Dialog|null} The question before a queued message replaces the text, while it is open. */
470
+ this._confirm = null;
453
471
  /** The application's hint, which `_syncHint()` shows unless the queue has something to say. */
454
472
  this._hint = String(options.hint ?? '');
455
473
  this._mentionSource = normalizeMentionSource(options.mentions);
@@ -655,7 +673,8 @@ export class Composer extends Component {
655
673
 
656
674
  /**
657
675
  * 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.
676
+ * busy ends, the first queued message is sent; the next waits for the next time it ends. Busy
677
+ * that ends while the composer is disabled sends when it is enabled again.
659
678
  * @param {boolean} busy
660
679
  * @returns {this}
661
680
  * @fires Composer#send
@@ -664,6 +683,8 @@ export class Composer extends Component {
664
683
  setBusy(busy) {
665
684
  const ended = this._busy && !busy;
666
685
  this._busy = Boolean(busy);
686
+ // Working again takes the place of a send still owed: the next end of busy sends.
687
+ if (this._busy) this._sendOwed = false;
667
688
  this._syncSend();
668
689
  if (ended) this._sendNextQueued();
669
690
  return this;
@@ -702,9 +723,12 @@ export class Composer extends Component {
702
723
  }
703
724
 
704
725
  /**
705
- * Turns input on or off.
726
+ * Turns input on or off. Turned back on, it sends the queued message that an end of busy owed
727
+ * while it was off.
706
728
  * @param {boolean} disabled
707
729
  * @returns {this}
730
+ * @fires Composer#send
731
+ * @fires Composer#dequeue
708
732
  */
709
733
  setDisabled(disabled) {
710
734
  this._disabled = Boolean(disabled);
@@ -714,6 +738,10 @@ export class Composer extends Component {
714
738
  }
715
739
  this._syncState();
716
740
  this._syncSend();
741
+ if (!this._disabled && this._sendOwed && !this._busy) {
742
+ this._sendOwed = false;
743
+ this._sendNextQueued();
744
+ }
717
745
  return this;
718
746
  }
719
747
 
@@ -744,8 +772,11 @@ export class Composer extends Component {
744
772
  if (has('note')) this.setNote(String(partial.note ?? ''));
745
773
  if (has('submitKey')) this._submitKey = submitKeyOf(partial.submitKey);
746
774
  if (has('sendLabel')) this._sendLabel = sendLabelText(partial.sendLabel);
775
+ // Busy starting goes first and busy ending last, so a queued message waits for both changes.
776
+ const busy = has('busy') ? Boolean(partial.busy) : null;
777
+ if (busy === true) this.setBusy(true);
747
778
  if (has('disabled')) this.setDisabled(Boolean(partial.disabled));
748
- if (has('busy')) this.setBusy(Boolean(partial.busy));
779
+ if (busy === false) this.setBusy(false);
749
780
  this._syncSend();
750
781
  return this;
751
782
  }
@@ -871,6 +902,10 @@ export class Composer extends Component {
871
902
  this._position = null;
872
903
  this._launcher?.destroy();
873
904
  this._launcher = null;
905
+ this._confirm?.destroy();
906
+ this._confirm = null;
907
+ for (const { avatar } of this._mentionFaces.values()) avatar.destroy();
908
+ this._mentionFaces.clear();
874
909
  super.destroy();
875
910
  if (this._original) restoreTarget(this.el, this._original);
876
911
  }
@@ -1178,14 +1213,20 @@ export class Composer extends Component {
1178
1213
  const highlighted = this._mention?.items[this._mention.index];
1179
1214
  const kept = highlighted ? items.findIndex((item) => String(item.id) === String(highlighted.id)) : -1;
1180
1215
  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))));
1216
+ list.replaceChildren(...items.map((item, index) => {
1217
+ const face = this._mentionFace(item);
1218
+ const word = face?.getActivityWord() ?? null;
1219
+ return h('div', {
1220
+ class: 'zx-composer__option', role: 'option', id: `${list.id}-${index}`,
1221
+ ariaSelected: 'false', dataset: { index: String(index) },
1222
+ // An agent's activity is in its face and dot; the name says it too, after the label.
1223
+ ariaLabel: word ? [String(item.label), word, item.description ? String(item.description) : null].filter(Boolean).join(', ') : null
1224
+ },
1225
+ face ? face.toElement() : item.icon ? icon(item.icon, { size: ICON_SIZE.control }) : null,
1226
+ h('span', { class: 'zx-composer__option-text' },
1227
+ h('span', { class: 'zx-composer__option-label' }, String(item.label)),
1228
+ item.description ? h('span', { class: 'zx-composer__option-description' }, String(item.description)) : null));
1229
+ }));
1189
1230
  if (list.hidden) {
1190
1231
  list.hidden = false;
1191
1232
  this._position = position(/** @type {HTMLElement} */ (this.refs.frame), list, {
@@ -1216,6 +1257,27 @@ export class Composer extends Component {
1216
1257
  }
1217
1258
 
1218
1259
  /** @private @returns {void} */
1260
+ /**
1261
+ * The AgentAvatar an agent mention draws, kept per item id and rebuilt only when the item changes.
1262
+ * @private
1263
+ * @param {MentionItem} item
1264
+ * @returns {AgentAvatar|null}
1265
+ */
1266
+ _mentionFace(item) {
1267
+ const options = agentAvatarOptions(item.agent || null, { size: 'sm', label: null, animate: false },
1268
+ { fallback: { name: String(item.label) }, carry: AGENT_ITEM_KEYS });
1269
+ if (!options) return null;
1270
+ const key = String(item.id);
1271
+ const signature = JSON.stringify(options);
1272
+ let entry = this._mentionFaces.get(key);
1273
+ if (!entry || entry.signature !== signature) {
1274
+ entry?.avatar.destroy();
1275
+ entry = { signature, avatar: new AgentAvatar(null, options) };
1276
+ this._mentionFaces.set(key, entry);
1277
+ }
1278
+ return entry.avatar;
1279
+ }
1280
+
1219
1281
  _closeMentions() {
1220
1282
  this._mentionSequence += 1;
1221
1283
  if (!this._mention && /** @type {HTMLElement} */ (this.refs.list).hidden) return;
@@ -1325,7 +1387,11 @@ export class Composer extends Component {
1325
1387
  * @fires Composer#dequeue
1326
1388
  */
1327
1389
  _sendQueued() {
1328
- if (this._busy || this._disabled || this._destroyed) return;
1390
+ if (this._busy || this._destroyed) return;
1391
+ if (this._disabled) {
1392
+ this._sendOwed = true;
1393
+ return;
1394
+ }
1329
1395
  const { queue, item } = takeNext(this._queue);
1330
1396
  if (!item) return;
1331
1397
  this._queue = queue;
@@ -1359,12 +1425,24 @@ export class Composer extends Component {
1359
1425
  */
1360
1426
  async _editQueued(id) {
1361
1427
  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
- });
1428
+ if (this._confirm) return;
1429
+ const doc = this.el.ownerDocument;
1430
+ const before = new Set(doc.querySelectorAll('dialog'));
1431
+ let replace = false;
1432
+ try {
1433
+ const answer = Dialog.confirm({
1434
+ title: this.msg('composer.queueReplaceTitle'),
1435
+ message: this.msg('composer.queueReplaceMessage'),
1436
+ okLabel: this.msg('composer.queueReplaceConfirm'),
1437
+ danger: true
1438
+ });
1439
+ // The question is created and opened synchronously; keep it so destroy() can close it.
1440
+ const opened = [...doc.querySelectorAll('dialog')].find((element) => !before.has(element));
1441
+ this._confirm = opened ? /** @type {Dialog|null} */ (Dialog.from(opened)) : null;
1442
+ replace = await answer;
1443
+ } finally {
1444
+ this._confirm = null;
1445
+ }
1368
1446
  if (!replace || this._destroyed) return;
1369
1447
  }
1370
1448
  const { queue, item } = removeFromQueue(this._queue, id);
@@ -2,8 +2,10 @@ import { Component } from '../../core/component.js';
2
2
  import { h, resolveElement } from '../../core/dom.js';
3
3
  import { rovingTabindex, typeahead } from '../../core/keyboard.js';
4
4
  import {
5
+ applyCheckedState,
5
6
  isMenuItem,
6
7
  MENU_ITEM_SELECTOR,
8
+ nextCheckedState,
7
9
  renderMenuEntries
8
10
  } from '../../internal/menu-items.js';
9
11
  import { Dropdown } from '../dropdown/dropdown.js';
@@ -24,12 +26,20 @@ import { Dropdown } from '../dropdown/dropdown.js';
24
26
  * @property {string|null} [selector=null] Restricts the menu to descendants matching this
25
27
  * selector, and reports the matched element as the context of the selection. A table passes
26
28
  * `'tbody tr'` here to get a per-row menu from one listener.
27
- * @property {(event: CustomEvent<{value: unknown, item: MenuItem, context: Element|null}>) => void} [onselect]
28
- * Selection listener.
29
+ * @property {(event: CustomEvent<ContextMenuSelectDetail>) => void} [onselect] Selection listener.
29
30
  * @property {(event: CustomEvent<{context: Element|null}>) => void} [onopen] Open listener.
30
31
  * @property {(event: CustomEvent<Record<string, never>>) => void} [onclose] Close listener.
31
32
  */
32
33
 
34
+ /**
35
+ * @typedef {Object} ContextMenuSelectDetail
36
+ * @property {unknown} value The chosen item's value.
37
+ * @property {MenuItem} item The chosen item, as the application gave it.
38
+ * @property {Element|null} context The element the menu was opened on.
39
+ * @property {boolean} [checked] For a `menuitemcheckbox` or `menuitemradio`, the state choosing it
40
+ * gives the item: a checkbox toggles, a radio is checked. Absent for a plain item.
41
+ */
42
+
33
43
  /**
34
44
  * Right-click menu for a region, implementing the APG menu pattern.
35
45
  *
@@ -43,6 +53,11 @@ import { Dropdown } from '../dropdown/dropdown.js';
43
53
  * menus are a common accessibility failure, so both routes are wired here rather than left to the
44
54
  * application.
45
55
  *
56
+ * Choosing a `menuitemcheckbox` toggles its `aria-checked`, and choosing a `menuitemradio` checks
57
+ * it and unchecks the other radio items of its section (between separators or headings); the new
58
+ * state arrives as `detail.checked`. A prevented `select` keeps the state as it was. Items given as
59
+ * a function are resolved again on every opening, so there the function's answer is the state.
60
+ *
46
61
  * Note that the component's root is the anchor, which lives on `<body>` — so the bubbling `zx-*`
47
62
  * DOM events land there, not in the target's tree. Listen with `on('select')` or `onselect`.
48
63
  *
@@ -232,7 +247,8 @@ export class ContextMenu extends Component {
232
247
  root.style.left = `${x}px`;
233
248
  root.style.top = `${y}px`;
234
249
  this.#context = context;
235
- this.#returnFocus = document.activeElement;
250
+ // Reopened while open, focus is already in the menu: it still returns where it came from.
251
+ if (!this.isOpen()) this.#returnFocus = document.activeElement;
236
252
  this.#dropdown.open();
237
253
  this.#roving.focusFirst();
238
254
  this.emit('open', { context });
@@ -240,6 +256,7 @@ export class ContextMenu extends Component {
240
256
 
241
257
  /** @param {Event} event @returns {void} */
242
258
  #onContextMenu(event) {
259
+ if (this.#fromPanel(event)) return;
243
260
  const pointer = /** @type {PointerEvent & {target: Element}} */ (event);
244
261
  const context = this.#contextFor(pointer.target);
245
262
  // Only take over the platform menu once there is something of our own to show — and resolve
@@ -253,6 +270,7 @@ export class ContextMenu extends Component {
253
270
  #onTargetKeydown(event) {
254
271
  const key = /** @type {KeyboardEvent} */ (event);
255
272
  if (key.key !== 'ContextMenu' && !(key.key === 'F10' && key.shiftKey)) return;
273
+ if (this.#fromPanel(event)) return;
256
274
  const context = this.#contextFor(/** @type {Element} */ (key.target));
257
275
  if (!context || !this.#prepare(context)) return;
258
276
  event.preventDefault();
@@ -260,6 +278,17 @@ export class ContextMenu extends Component {
260
278
  this.#openResolved(box.left, box.bottom, context);
261
279
  }
262
280
 
281
+ /**
282
+ * Whether an event on the target began inside the menu's own panel. A target that is itself a
283
+ * theme scope hosts the panel, so a right-click or Shift+F10 inside the open menu bubbles to the
284
+ * target, and is not a request for a menu on it.
285
+ * @param {Event} event Event heard on the target.
286
+ * @returns {boolean}
287
+ */
288
+ #fromPanel(event) {
289
+ return this.#panel.contains(/** @type {Node|null} */ (event.target));
290
+ }
291
+
263
292
  /**
264
293
  * The element a pointer or key event applies to, honoring `selector`.
265
294
  * @param {Element|null} from Event target.
@@ -303,12 +332,18 @@ export class ContextMenu extends Component {
303
332
  const reclaim = restore instanceof HTMLElement && restore.isConnected && this.#ownsFocus();
304
333
  // A dialog opened by a callback records the invoking control as its opener.
305
334
  if (reclaim) restore.focus();
306
- const selected = this.emit('select', { value: item.value, item, context });
335
+ const entries = this.#items;
336
+ const checked = nextCheckedState(item, element.getAttribute('aria-checked') === 'true');
337
+ const selected = this.emit('select', checked === undefined
338
+ ? { value: item.value, item, context }
339
+ : { value: item.value, item, context, checked });
307
340
  if (selected.defaultPrevented) {
308
341
  event?.preventDefault();
309
342
  if (reclaim && document.activeElement === restore && element instanceof HTMLElement) element.focus();
310
343
  return;
311
344
  }
345
+ // A listener that replaced the items has rendered the state it wants already.
346
+ if (checked !== undefined && this.#items === entries) applyCheckedState(this.#panel, entries, index, checked);
312
347
  try {
313
348
  item.onselect?.(item.value, item, this);
314
349
  } finally {
@@ -330,8 +365,9 @@ export class ContextMenu extends Component {
330
365
 
331
366
  /**
332
367
  * Fired when an enabled item is activated. `context` is the element the menu was opened on.
368
+ * Preventing it keeps the menu open and a checkbox or radio item's state unchanged.
333
369
  * @event ContextMenu#select
334
- * @type {CustomEvent<{value: unknown, item: MenuItem, context: Element|null}>}
370
+ * @type {CustomEvent<ContextMenuSelectDetail>}
335
371
  */
336
372
 
337
373
  /**
@@ -17,6 +17,9 @@ import { icon as createIcon } from '../../core/icons.js';
17
17
  * @property {'default'|'primary'|'ghost'} [kind='ghost'] Visual intent.
18
18
  * @property {(text: string, copied: boolean) => void} [oncopy] Called with the text and whether
19
19
  * the clipboard accepted it.
20
+ * @property {AbortSignal} [signal] Ends the button's life: aborting removes its click listener,
21
+ * stops a pending confirmation, and makes a copy still waiting on the clipboard report nothing.
22
+ * For a button owned by something that is destroyed before the page is.
20
23
  */
21
24
 
22
25
  /** @type {Readonly<CopyButtonOptions>} */
@@ -58,10 +61,15 @@ export function copyButton(opts = {}) {
58
61
  if (!iconOnly) element.append(h('span', { class: 'zx-copy-button__label' }, String(options.label)));
59
62
  element.append(status);
60
63
 
64
+ const signal = options.signal ?? null;
65
+ if (signal?.aborted) return element;
61
66
  let timer = 0;
67
+ signal?.addEventListener('abort', () => clearTimeout(timer), { once: true });
62
68
  element.addEventListener('click', async () => {
63
69
  const text = typeof options.text === 'function' ? String(options.text()) : String(options.text ?? '');
64
70
  const copied = await copyToClipboard(text);
71
+ // The owner went away while the clipboard was answering: nobody is left to tell.
72
+ if (signal?.aborted) return;
65
73
  options.oncopy?.(text, copied);
66
74
  if (!copied) return;
67
75
 
@@ -75,6 +83,6 @@ export function copyButton(opts = {}) {
75
83
  glyph.replaceChildren(createIcon('copy', { size: options.size === 'sm' ? 12 : 14 }));
76
84
  status.textContent = '';
77
85
  }, Math.max(0, Number(options.feedbackDuration) || 0));
78
- });
86
+ }, signal ? { signal } : undefined);
79
87
  return element;
80
88
  }
@@ -60,11 +60,15 @@ export class CopyInput extends Component {
60
60
  value: String(this.options.value ?? '')
61
61
  }));
62
62
  const { buttonTitle = this.msg('copy.copy'), feedback = this.msg('copy.copied') } = this.options;
63
+ // The button's listener, its confirmation timer, and a copy still awaiting the clipboard all
64
+ // end with this component: `destroy()` aborts it.
65
+ this._buttonLife = new AbortController();
63
66
  const button = copyButton({
64
67
  text: () => this.get(),
65
68
  title: buttonTitle,
66
69
  feedback,
67
70
  size: this.options.size === 'sm' ? 'sm' : 'md',
71
+ signal: this._buttonLife.signal,
68
72
  oncopy: (value, copied) => this.emit('copy', { value, copied })
69
73
  });
70
74
 
@@ -115,6 +119,7 @@ export class CopyInput extends Component {
115
119
  /** Restores an enhanced target to the markup it had before the takeover. @returns {void} */
116
120
  destroy() {
117
121
  const root = this.el;
122
+ this._buttonLife?.abort();
118
123
  super.destroy();
119
124
  if (!this._createdRoot && root) restoreTarget(root, this._snapshot);
120
125
  }
@@ -20,7 +20,6 @@ export function normalizeText(value) {
20
20
  * @returns {boolean} Whether every query term occurs in the combined fields.
21
21
  */
22
22
  export function matchesText(values, query) {
23
- // TODO(unify): share this tiny matcher with WP4's select filter once both branches merge.
24
23
  const terms = normalizeText(query).trim().split(/\s+/).filter(Boolean);
25
24
  if (terms.length === 0) return true;
26
25
  const corpus = normalizeText(values.flat(Infinity).join(' '));