@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
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Geometry for `SvgChartAdapter`: a value scale with round ticks, the bars of a category, how
3
+ * often a category label fits, a line with gaps, and the slices and rings of a pie.
4
+ *
5
+ * Plain numbers in, plain numbers and SVG path strings out — no DOM — so the arithmetic is tested
6
+ * on its own (`tests/unit/chart-svg.test.js`). Angles are radians clockwise from twelve o'clock,
7
+ * the way a pie is read; coordinates are SVG user units, y growing downwards. Path coordinates are
8
+ * rounded to two decimals, which is finer than any screen draws and keeps the markup short.
9
+ * @module zx/components/chart/svg-geometry
10
+ */
11
+
12
+ const TAU = Math.PI * 2;
13
+ /** Tolerance for a quotient that should be a whole number but is not, by float noise. */
14
+ const EPSILON = 1e-9;
15
+ /**
16
+ * The finest step a scale takes, relative to its largest value: sixteen units in the last place
17
+ * of a double, so that consecutive ticks stay distinct numbers (1e16 + 0.5 is 1e16) and rounding a
18
+ * tick to its step's digits cannot land on a neighbour.
19
+ */
20
+ const PRECISION = 2 ** -48;
21
+ /** The most intervals a scale is asked for; whatever the input, a scale has a handful of ticks. */
22
+ const MAX_INTERVALS = 50;
23
+ /** A bound on the tick loop, well above what `MAX_INTERVALS` produces: it can never run away. */
24
+ const MAX_TICKS = 200;
25
+ /** The largest round step a double holds: 2 × 10³⁰⁸ is beyond it. */
26
+ const LARGEST_STEP = 1e308;
27
+
28
+ /**
29
+ * @typedef {Object} NiceScale
30
+ * @property {number} min The lowest tick, at or below the lowest value.
31
+ * @property {number} max The highest tick, at or above the highest value.
32
+ * @property {number} step The distance between ticks: 1, 2 or 5 × 10ⁿ.
33
+ * @property {number[]} ticks Every tick from `min` to `max`, distinct and free of float noise
34
+ * (0.3, not 0.30000000000000004).
35
+ */
36
+
37
+ /**
38
+ * A linear scale over `[min, max]`, widened outwards to round ticks. A range of one value is
39
+ * widened to zero (or to one when the value is zero), so a flat series still sits on an axis;
40
+ * values that are not finite count as zero. Any finite bounds give a few distinct ticks: the step
41
+ * is never finer than the values can tell apart, and an outer tick a double cannot hold is the
42
+ * largest one it can.
43
+ * @param {number} min Lowest value.
44
+ * @param {number} max Highest value.
45
+ * @param {number} [count=5] About how many intervals the scale should have, 1 to 50.
46
+ * @returns {NiceScale}
47
+ */
48
+ export function niceScale(min, max, count = 5) {
49
+ let low = Number.isFinite(min) ? min : 0;
50
+ let high = Number.isFinite(max) ? max : 0;
51
+ if (low > high) [low, high] = [high, low];
52
+ if (low === high) {
53
+ if (low > 0) low = 0;
54
+ else if (low < 0) high = 0;
55
+ else high = 1;
56
+ }
57
+ const intervals = Math.min(MAX_INTERVALS, Math.max(1, Math.round(count) || 1));
58
+ // Halved, the span stays finite whatever the bounds: -1e308 to 1e308 is wider than a double.
59
+ // Neither can the step round away to nothing between two of the tiniest doubles.
60
+ const raw = Math.max(Number.MIN_VALUE, Math.min(Number.MAX_VALUE, ((high / 2 - low / 2) / intervals) * 2));
61
+ const finest = Math.max(Math.abs(low), Math.abs(high)) * PRECISION;
62
+ const step = niceStep(Math.max(raw, finest));
63
+ const exponent = Math.floor(Math.log10(step) + EPSILON);
64
+ /** @param {number} index @returns {number} */
65
+ const tickAt = (index) => tickValue(index * step, exponent);
66
+ let first = Math.floor(low / step + EPSILON);
67
+ let last = Math.ceil(high / step - EPSILON);
68
+ // The quotients of very large values are rounded: the outer ticks must still enclose the data.
69
+ if (tickAt(first) - low > step * EPSILON) first -= 1;
70
+ if (high - tickAt(last) > step * EPSILON) last += 1;
71
+ if (last <= first) last = first + 1;
72
+ const ticks = [];
73
+ // A small counter, not the tick index itself: at 2e16 adding one no longer changes a double.
74
+ for (let offset = 0; offset <= last - first && offset < MAX_TICKS; offset += 1) {
75
+ const tick = tickAt(first + offset);
76
+ if (tick !== ticks[ticks.length - 1]) ticks.push(tick);
77
+ }
78
+ return { min: ticks[0], max: ticks[ticks.length - 1], step, ticks };
79
+ }
80
+
81
+ /**
82
+ * The round step nearest `raw`: 1, 2 or 5 × 10ⁿ, choosing at the geometric midpoints between
83
+ * them, as most axis libraries do.
84
+ * @param {number} raw Unrounded step, positive.
85
+ * @returns {number}
86
+ */
87
+ export function niceStep(raw) {
88
+ if (!(raw > 0) || !Number.isFinite(raw)) return 1;
89
+ const power = 10 ** Math.floor(Math.log10(raw));
90
+ if (!(power > 0)) return Number.MIN_VALUE;
91
+ const fraction = raw / power;
92
+ const factor = fraction >= Math.SQRT2 * 5 ? 10 : fraction >= Math.sqrt(10) ? 5 : fraction >= Math.SQRT2 ? 2 : 1;
93
+ const step = clean(factor * power);
94
+ return Number.isFinite(step) ? step : LARGEST_STEP;
95
+ }
96
+
97
+ /**
98
+ * Maps a value of `[min, max]` to a position of `[from, to]`; the range may run backwards, as a
99
+ * vertical axis does.
100
+ * @param {number} min Domain start.
101
+ * @param {number} max Domain end.
102
+ * @param {number} from Position of `min`.
103
+ * @param {number} to Position of `max`.
104
+ * @returns {(value: number) => number}
105
+ */
106
+ export function linearScale(min, max, from, to) {
107
+ const span = max - min || 1;
108
+ if (Number.isFinite(span)) return (value) => from + ((value - min) / span) * (to - from);
109
+ // A domain wider than a double holds (-1e308 to 1e308) is measured in halves.
110
+ const half = max / 2 - min / 2;
111
+ return (value) => from + ((value / 2 - min / 2) / half) * (to - from);
112
+ }
113
+
114
+ /**
115
+ * @typedef {Object} BarSlot
116
+ * @property {number} x Left edge.
117
+ * @property {number} width Width, never more than its slot.
118
+ */
119
+
120
+ /**
121
+ * Where the bars of one category go: `count` series side by side across the middle 80% of the
122
+ * band, each bar 90% of its slot (at least one unit where the slot has room) and at most
123
+ * `maxWidth` wide, the group centred in the band. A bar never leaves its slot, so in a band too
124
+ * narrow for whole pixels the bars grow thin rather than paint over each other.
125
+ * @param {number} start Left edge of the band.
126
+ * @param {number} band Width of the band.
127
+ * @param {number} count Series in the group, at least 1.
128
+ * @param {number} [maxWidth=Infinity] Widest a bar may be.
129
+ * @returns {BarSlot[]}
130
+ */
131
+ export function barSlots(start, band, count, maxWidth = Infinity) {
132
+ const series = Math.max(1, Math.floor(count) || 1);
133
+ const slot = Math.min((band * 0.8) / series, maxWidth / 0.9);
134
+ const width = Math.max(0, Math.min(slot, Math.max(1, slot * 0.9)));
135
+ const left = start + (band - slot * series) / 2;
136
+ return Array.from({ length: series }, (_, index) => ({ x: left + index * slot + (slot - width) / 2, width }));
137
+ }
138
+
139
+ /**
140
+ * Every how many categories a label is written so that none overlaps the next: 1 when the
141
+ * widest label and a gap fit in one band, more as bands get narrow.
142
+ * @param {number} widest Width of the widest label.
143
+ * @param {number} band Width of one category.
144
+ * @param {number} [gap=0] Least space between two labels.
145
+ * @returns {number} A whole number, at least 1.
146
+ */
147
+ export function labelStep(widest, band, gap = 0) {
148
+ if (!(band > 0)) return 1;
149
+ return Math.max(1, Math.ceil((Math.max(0, widest) + Math.max(0, gap)) / band - EPSILON));
150
+ }
151
+
152
+ /**
153
+ * A polyline through the points, broken where a point is missing: each run of points starts a
154
+ * new subpath, so a gap in the data is a gap in the line.
155
+ * @param {Array<[number, number]|null>} points Positions in order; null where there is no value.
156
+ * @returns {string} SVG path data; empty for no points.
157
+ */
158
+ export function linePath(points) {
159
+ let path = '';
160
+ let open = false;
161
+ for (const point of points) {
162
+ if (!point) {
163
+ open = false;
164
+ continue;
165
+ }
166
+ path += `${open ? 'L' : 'M'}${num(point[0])} ${num(point[1])}`;
167
+ open = true;
168
+ }
169
+ return path;
170
+ }
171
+
172
+ /**
173
+ * @typedef {Object} ArcSlice
174
+ * @property {number} index Position of the value in the list.
175
+ * @property {number} value The value.
176
+ * @property {number} share The value's part of the whole, 0 to 1.
177
+ * @property {number} start Start angle.
178
+ * @property {number} end End angle.
179
+ */
180
+
181
+ /**
182
+ * The slices of a pie: one per positive value, in order clockwise from twelve o'clock, each
183
+ * sweeping its share of the circle. Zero, negative and non-finite values have no slice. With two
184
+ * slices or more, each gives up `padAngle` (half at either edge, never more than half its sweep)
185
+ * so neighbours stand apart whatever lies behind the chart. Shares are taken relative to the
186
+ * largest value, so values whose sum a double cannot hold (1e308 twice) still divide the circle.
187
+ * @param {unknown[]} values Values.
188
+ * @param {number} [padAngle=0] Gap between slices.
189
+ * @returns {ArcSlice[]} Empty when no value is positive.
190
+ */
191
+ export function arcSlices(values, padAngle = 0) {
192
+ const shown = values
193
+ .map((value, index) => ({ index, value: typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0 }))
194
+ .filter((entry) => entry.value > 0);
195
+ const largest = shown.reduce((most, entry) => Math.max(most, entry.value), 0);
196
+ if (!(largest > 0)) return [];
197
+ const total = shown.reduce((sum, entry) => sum + entry.value / largest, 0);
198
+ const pad = shown.length > 1 ? Math.max(0, padAngle) : 0;
199
+ let angle = 0;
200
+ return shown.map(({ index, value }) => {
201
+ const share = value / largest / total;
202
+ const sweep = share * TAU;
203
+ const start = angle;
204
+ angle += sweep;
205
+ const inset = Math.min(pad, sweep / 2) / 2;
206
+ return { index, value, share, start: start + inset, end: angle - inset };
207
+ });
208
+ }
209
+
210
+ /**
211
+ * @typedef {Object} Ring
212
+ * @property {number} outer Outer radius.
213
+ * @property {number} inner Inner radius; 0 for the centre of a pie.
214
+ */
215
+
216
+ /**
217
+ * The rings of a pie or doughnut with several datasets, outermost first: equal thickness between
218
+ * `radius` and the hole, `gap` apart. The gap gives up at most half a ring's share of the radius,
219
+ * so however many datasets there are, each keeps a ring of its own.
220
+ * @param {number} count Rings, at least 1.
221
+ * @param {number} radius Outer radius of the outermost ring.
222
+ * @param {number} [hole=0] Radius of the hole as a fraction of `radius`: 0 for a pie.
223
+ * @param {number} [gap=0] Space between neighbouring rings.
224
+ * @returns {Ring[]}
225
+ */
226
+ export function ringRadii(count, radius, hole = 0, gap = 0) {
227
+ const rings = Math.max(1, Math.floor(count) || 1);
228
+ const outermost = Math.max(0, radius);
229
+ const innermost = outermost * Math.min(1, Math.max(0, hole));
230
+ const thickness = (outermost - innermost) / rings;
231
+ const space = Math.min(Math.max(0, gap), thickness / 2);
232
+ return Array.from({ length: rings }, (_, index) => {
233
+ const outer = outermost - index * thickness;
234
+ const inner = index === rings - 1 ? innermost : outer - thickness + space;
235
+ return { outer, inner };
236
+ });
237
+ }
238
+
239
+ /**
240
+ * The outline of a slice: a wedge from the centre when `inner` is 0, a band of a ring otherwise.
241
+ * A sweep of the whole circle is drawn as two half circles (an arc command cannot close on its
242
+ * own start), the hole of a ring the other way round so the default fill rule leaves it empty.
243
+ * @param {number} cx Centre x.
244
+ * @param {number} cy Centre y.
245
+ * @param {number} outer Outer radius.
246
+ * @param {number} inner Inner radius.
247
+ * @param {number} start Start angle.
248
+ * @param {number} end End angle.
249
+ * @returns {string} SVG path data; empty when there is nothing to draw.
250
+ */
251
+ export function arcPath(cx, cy, outer, inner, start, end) {
252
+ const sweep = end - start;
253
+ if (!(sweep > 0) || !(outer > 0)) return '';
254
+ const hole = Math.max(0, Math.min(inner, outer));
255
+ if (sweep >= TAU - EPSILON) {
256
+ const circle = (radius, clockwise) => {
257
+ const r = num(radius);
258
+ return `M${num(cx)} ${num(cy - radius)}A${r} ${r} 0 1 ${clockwise} ${num(cx)} ${num(cy + radius)}`
259
+ + `A${r} ${r} 0 1 ${clockwise} ${num(cx)} ${num(cy - radius)}Z`;
260
+ };
261
+ return circle(outer, 1) + (hole > 0 ? circle(hole, 0) : '');
262
+ }
263
+ const large = sweep > Math.PI ? 1 : 0;
264
+ const [x0, y0] = polar(cx, cy, outer, start);
265
+ const [x1, y1] = polar(cx, cy, outer, end);
266
+ let path = `M${num(x0)} ${num(y0)}A${num(outer)} ${num(outer)} 0 ${large} 1 ${num(x1)} ${num(y1)}`;
267
+ if (hole > 0) {
268
+ const [x2, y2] = polar(cx, cy, hole, end);
269
+ const [x3, y3] = polar(cx, cy, hole, start);
270
+ path += `L${num(x2)} ${num(y2)}A${num(hole)} ${num(hole)} 0 ${large} 0 ${num(x3)} ${num(y3)}`;
271
+ } else {
272
+ path += `L${num(cx)} ${num(cy)}`;
273
+ }
274
+ return `${path}Z`;
275
+ }
276
+
277
+ /**
278
+ * The point at `radius` from the centre, `angle` clockwise from twelve o'clock.
279
+ * @param {number} cx @param {number} cy @param {number} radius @param {number} angle
280
+ * @returns {[number, number]}
281
+ */
282
+ export function polar(cx, cy, radius, angle) {
283
+ return [cx + radius * Math.sin(angle), cy - radius * Math.cos(angle)];
284
+ }
285
+
286
+ /**
287
+ * Significant digits a tick label needs so that no two ticks read alike: enough for the largest
288
+ * tick's magnitude down to the step's, whatever unit a compact number format abbreviates to.
289
+ * @param {number[]} ticks Ticks of a `niceScale()`.
290
+ * @param {number} step Its step.
291
+ * @returns {number} 1 to 21.
292
+ */
293
+ export function tickPrecision(ticks, step) {
294
+ const largest = ticks.reduce((most, tick) => Math.max(most, Math.abs(tick)), 0);
295
+ if (!(largest > 0) || !(step > 0)) return 1;
296
+ const digits = Math.floor(Math.log10(largest) + EPSILON) - Math.floor(Math.log10(step) + EPSILON) + 1;
297
+ return Math.min(21, Math.max(1, digits));
298
+ }
299
+
300
+ /** @param {number} value @returns {number} The value without float noise. */
301
+ function clean(value) {
302
+ return Number(value.toPrecision(12));
303
+ }
304
+
305
+ /**
306
+ * A tick rounded to the digits its step has, and no further: 1e12 + 0.2 keeps its fraction, 0.1 × 3
307
+ * loses its noise. A tick past the largest double is the largest double.
308
+ * @param {number} value The tick as multiplied out.
309
+ * @param {number} exponent The power of ten of the step's one significant digit.
310
+ * @returns {number}
311
+ */
312
+ function tickValue(value, exponent) {
313
+ if (value === 0) return 0;
314
+ if (!Number.isFinite(value)) return value > 0 ? Number.MAX_VALUE : -Number.MAX_VALUE;
315
+ const digits = Math.floor(Math.log10(Math.abs(value)) + EPSILON) - exponent + 1;
316
+ return Number(value.toPrecision(Math.min(100, Math.max(1, digits))));
317
+ }
318
+
319
+ /** @param {number} value @returns {string} The value to two decimals, as short as it goes. */
320
+ function num(value) {
321
+ const rounded = Math.round(value * 100) / 100;
322
+ return String(rounded === 0 ? 0 : rounded);
323
+ }
@@ -1,5 +1,5 @@
1
1
  import { Component } from '../../core/component.js';
2
- import { h } from '../../core/dom.js';
2
+ import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
3
3
  import { ICON_SIZE, icon } from '../../core/icons.js';
4
4
 
5
5
  /**
@@ -37,7 +37,7 @@ export class CheckButton extends Component {
37
37
  }
38
38
 
39
39
  this._createdRoot = created;
40
- this._original = created ? null : snapshot(root);
40
+ this._original = created ? null : snapshotTarget(root);
41
41
  this._checked = Boolean(this.options.checked);
42
42
  this._disabled = Boolean(this.options.disabled);
43
43
  this._labels = normalizeLabels(this.options.label);
@@ -126,7 +126,7 @@ export class CheckButton extends Component {
126
126
  if (this._cleaned) return;
127
127
  this._cleaned = true;
128
128
  super.destroy();
129
- if (!this._createdRoot && this._original) restore(this.el, this._original);
129
+ if (!this._createdRoot && this._original) restoreTarget(this.el, this._original);
130
130
  }
131
131
 
132
132
  /** @returns {void} */
@@ -150,18 +150,3 @@ function normalizeLabels(label) {
150
150
  }
151
151
  return { on: String(label ?? ''), off: String(label ?? '') };
152
152
  }
153
-
154
- /** @param {Element} element @returns {{attributes: [string, string][], children: Node[]}} */
155
- function snapshot(element) {
156
- return {
157
- attributes: Array.from(element.attributes, (attribute) => [attribute.name, attribute.value]),
158
- children: Array.from(element.childNodes)
159
- };
160
- }
161
-
162
- /** @param {Element} element @param {{attributes: [string, string][], children: Node[]}} state */
163
- function restore(element, state) {
164
- for (const attribute of Array.from(element.attributes)) element.removeAttribute(attribute.name);
165
- for (const [name, value] of state.attributes) element.setAttribute(name, value);
166
- element.replaceChildren(...state.children);
167
- }
@@ -41,7 +41,7 @@
41
41
  line-height: 1.35;
42
42
  }
43
43
 
44
- .zx-checklist__item:hover {
44
+ .zx-checklist:not([aria-disabled="true"]) .zx-checklist__item:hover {
45
45
  background: var(--zx-color-bg-hover);
46
46
  }
47
47
 
@@ -70,3 +70,11 @@
70
70
  .zx-checklist[data-state="loading"] .zx-checklist__list {
71
71
  color: var(--zx-color-text-muted);
72
72
  }
73
+
74
+ .zx-checklist[aria-disabled="true"] {
75
+ opacity: var(--zx-control-disabled-opacity);
76
+ }
77
+
78
+ .zx-checklist[aria-disabled="true"] .zx-checklist__item {
79
+ cursor: default;
80
+ }
@@ -13,6 +13,9 @@ import { matchItems } from '../select/filter.js';
13
13
  * @property {boolean} [search=true] Whether the search field is shown.
14
14
  * @property {number} [height=280] Maximum list height in pixels.
15
15
  * @property {boolean} [defaultChecked=false] Fallback initial checked state.
16
+ * @property {string|null} [label=null] Heading text, which is also the group's accessible name;
17
+ * null uses the `checklist.label` message.
18
+ * @property {boolean} [disabled=false] Whether the search field and every checkbox are disabled.
16
19
  * @property {boolean} [hideLabel=false] Whether the heading is left out. The group keeps the
17
20
  * heading text as its accessible name (`aria-label`); a Field labelling the checklist names it
18
21
  * instead, which is why the `checklist` field type sets this.
@@ -43,6 +46,8 @@ export class Checklist extends Component {
43
46
  search: true,
44
47
  height: 280,
45
48
  defaultChecked: false,
49
+ label: null,
50
+ disabled: false,
46
51
  hideLabel: false,
47
52
  load: null
48
53
  };
@@ -52,18 +57,20 @@ export class Checklist extends Component {
52
57
  render() {
53
58
  // Instance state initialized here because render() runs inside the base
54
59
  // constructor, before class-field initializers would run (and clobber it).
55
- this._items = []; this._visibleItems = []; this._checked = new Set(); this._query = ''; this._loadSequence = 0; this._createdRoot = false; this._active = true; this._originalChildren = []; this._originalAttributes = new Map();
60
+ this._items = []; this._visibleItems = []; this._checked = new Set(); this._pending = null; this._query = ''; this._loadSequence = 0; this._createdRoot = false; this._active = true; this._originalChildren = []; this._originalAttributes = new Map();
56
61
  this._createdRoot = this.el === null;
57
62
  const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
58
63
  this.el = root;
59
64
  if (!this._createdRoot) this._originalChildren = Array.from(root.childNodes);
60
- for (const name of ['role', 'aria-label', 'aria-labelledby', 'data-state']) {
65
+ this._disabled = Boolean(this.options.disabled);
66
+ for (const name of ['role', 'aria-label', 'aria-labelledby', 'aria-disabled', 'data-state']) {
61
67
  this._originalAttributes.set(name, root.getAttribute(name));
62
68
  }
63
69
 
64
- const labelText = this._message('checklist.label', 'Checklist');
70
+ const labelText = this._labelText(this.options.label);
65
71
  const labelId = uid('zx-checklist-label');
66
72
  const title = this.options.hideLabel ? null : h('div', {
73
+ ref: 'label',
67
74
  class: 'zx-checklist__label',
68
75
  id: labelId
69
76
  }, labelText);
@@ -74,7 +81,8 @@ export class Checklist extends Component {
74
81
  autocomplete: 'off',
75
82
  placeholder: this._message('checklist.search', 'Search'),
76
83
  ariaLabel: this._message('checklist.search', 'Search checklist'),
77
- hidden: !this.options.search
84
+ hidden: !this.options.search,
85
+ disabled: this._disabled
78
86
  });
79
87
  const list = h('div', {
80
88
  ref: 'list',
@@ -99,6 +107,7 @@ export class Checklist extends Component {
99
107
  });
100
108
 
101
109
  this._replaceItems(this.options.items);
110
+ this._syncDisabled();
102
111
  if (typeof this.options.load === 'function') {
103
112
  queueMicrotask(() => {
104
113
  if (this._active) void this.reload().catch(() => {});
@@ -108,7 +117,9 @@ export class Checklist extends Component {
108
117
  }
109
118
 
110
119
  /**
111
- * Replaces items and derives checked state from `checkedKey` and `defaultChecked`.
120
+ * Replaces items and derives checked state from `checkedKey` and `defaultChecked` — unless
121
+ * `setValues()` asked for IDs the earlier items did not have yet, in which case the requested
122
+ * values are checked instead.
112
123
  * @param {ChecklistItem[]} items New items.
113
124
  * @returns {this}
114
125
  */
@@ -117,37 +128,77 @@ export class Checklist extends Component {
117
128
  return this;
118
129
  }
119
130
 
120
- /** Returns checked IDs in item order. @returns {unknown[]} */
131
+ /**
132
+ * Replaces the heading text, which is also the group's accessible name.
133
+ * @param {string|null} label New label; null restores the `checklist.label` message.
134
+ * @returns {this}
135
+ */
136
+ setLabel(label) {
137
+ const text = this._labelText(label);
138
+ if (this.refs.label) this.refs.label.textContent = text;
139
+ else this.el.setAttribute('aria-label', text);
140
+ return this;
141
+ }
142
+
143
+ /** Enables the search field and the checkboxes. @returns {this} */
144
+ enable() {
145
+ this._disabled = false;
146
+ this._syncDisabled();
147
+ return this;
148
+ }
149
+
150
+ /** Disables the search field and the checkboxes; values can still be set programmatically. @returns {this} */
151
+ disable() {
152
+ this._disabled = true;
153
+ this._syncDisabled();
154
+ return this;
155
+ }
156
+
157
+ /** Whether the checklist is disabled. @returns {boolean} */
158
+ isDisabled() {
159
+ return this._disabled;
160
+ }
161
+
162
+ /**
163
+ * Returns checked IDs in item order, followed by requested IDs whose items have not been loaded
164
+ * yet (see `setValues()`).
165
+ * @returns {unknown[]}
166
+ */
121
167
  getValues() {
122
- return this._items
168
+ const checked = this._items
123
169
  .map((item) => this._itemValue(item))
124
170
  .filter((value) => this._checked.has(value));
171
+ return this._pending ? [...checked, ...this._pending] : checked;
125
172
  }
126
173
 
127
174
  /**
128
- * Replaces the checked IDs.
175
+ * Replaces the checked IDs. IDs that none of the current items carries are kept as requested,
176
+ * and checked as soon as items carrying them arrive — through `setItems()` or the `load`
177
+ * loader — so a value set before the items load is not lost.
129
178
  * @param {Iterable<unknown>|unknown[]} ids Checked item IDs.
130
179
  * @returns {this}
131
180
  * @fires Checklist#change
132
181
  */
133
182
  setValues(ids) {
134
183
  const requested = new Set(ids == null ? [] : Array.from(ids));
135
- const next = new Set(this._items
136
- .map((item) => this._itemValue(item))
137
- .filter((value) => requested.has(value)));
138
- this._replaceChecked(next);
184
+ const known = new Set(this._items.map((item) => this._itemValue(item)));
185
+ const next = new Set([...known].filter((value) => requested.has(value)));
186
+ const missing = [...requested].filter((value) => !known.has(value));
187
+ // Before any item exists the request stands for the items still to come — an empty one too —
188
+ // in place of their own checked flags.
189
+ this._replaceChecked(next, missing.length || this._items.length === 0 ? missing : null);
139
190
  return this;
140
191
  }
141
192
 
142
193
  /** Checks every item. @returns {this} @fires Checklist#change */
143
194
  checkAll() {
144
- this._replaceChecked(new Set(this._items.map((item) => this._itemValue(item))));
195
+ this._replaceChecked(new Set(this._items.map((item) => this._itemValue(item))), null);
145
196
  return this;
146
197
  }
147
198
 
148
199
  /** Unchecks every item. @returns {this} @fires Checklist#change */
149
200
  uncheckAll() {
150
- this._replaceChecked(new Set());
201
+ this._replaceChecked(new Set(), null);
151
202
  return this;
152
203
  }
153
204
 
@@ -207,9 +258,18 @@ export class Checklist extends Component {
207
258
  /** @param {ChecklistItem[]} items @returns {void} */
208
259
  _replaceItems(items) {
209
260
  this._items = Array.isArray(items) ? items.slice() : [];
210
- this._checked = new Set(this._items
211
- .filter((item) => Boolean(this._initialChecked(item)))
212
- .map((item) => this._itemValue(item)));
261
+ if (this._pending !== null) {
262
+ // A value requested before its items existed: it decides what is checked, not checkedKey.
263
+ const wanted = new Set([...this._checked, ...this._pending]);
264
+ const known = new Set(this._items.map((item) => this._itemValue(item)));
265
+ this._checked = new Set([...known].filter((value) => wanted.has(value)));
266
+ const pending = this._pending.filter((value) => !known.has(value));
267
+ this._pending = pending.length ? pending : null;
268
+ } else {
269
+ this._checked = new Set(this._items
270
+ .filter((item) => Boolean(this._initialChecked(item)))
271
+ .map((item) => this._itemValue(item)));
272
+ }
213
273
  this._visibleItems = matchItems(this._items, this._query, [this.options.labelKey]);
214
274
  this._renderItems();
215
275
  }
@@ -223,6 +283,7 @@ export class Checklist extends Component {
223
283
  type: 'checkbox',
224
284
  id: checkboxId,
225
285
  checked: this._checked.has(this._itemValue(item)),
286
+ disabled: this._disabled,
226
287
  dataset: { index }
227
288
  });
228
289
  return h('label', {
@@ -239,9 +300,33 @@ export class Checklist extends Component {
239
300
  this.refs.list.replaceChildren(...rows);
240
301
  }
241
302
 
242
- /** @param {Set<unknown>} next @returns {void} */
243
- _replaceChecked(next) {
244
- if (setsEqual(this._checked, next)) return;
303
+ /** @returns {void} */
304
+ _syncDisabled() {
305
+ if (this._disabled) this.el.setAttribute('aria-disabled', 'true');
306
+ else this.el.removeAttribute('aria-disabled');
307
+ /** @type {HTMLInputElement} */ (this.refs.search).disabled = this._disabled;
308
+ for (const input of this.refs.list.querySelectorAll('input[type="checkbox"]')) {
309
+ /** @type {HTMLInputElement} */ (input).disabled = this._disabled;
310
+ }
311
+ }
312
+
313
+ /** @param {string|null|undefined} label @returns {string} */
314
+ _labelText(label) {
315
+ return label == null || label === '' ? this._message('checklist.label', 'Checklist') : String(label);
316
+ }
317
+
318
+ /**
319
+ * @param {Set<unknown>} next
320
+ * @param {unknown[]|null} pending Requested IDs no item carries yet, or null when no request waits
321
+ * for items; an empty array is a request made before any item existed.
322
+ * @returns {void}
323
+ */
324
+ _replaceChecked(next, pending) {
325
+ const nextPending = pending;
326
+ const pendingChanged = !setsEqual(new Set(this._pending ?? []), new Set(nextPending ?? []));
327
+ const unchanged = setsEqual(this._checked, next) && !pendingChanged;
328
+ this._pending = nextPending;
329
+ if (unchanged) return;
245
330
  this._checked = next;
246
331
  this._renderItems();
247
332
  this.emit('change', { values: this.getValues() });
@@ -10,38 +10,32 @@ export function registerChecklistFieldAdapter() {
10
10
  // The Field's label names the list (`aria-labelledby`), so the checklist draws no heading of
11
11
  // its own under it.
12
12
  const checklist = field.own(new Checklist(null, { hideLabel: true, ...(options.props ?? {}) }));
13
- let disabled = false;
14
13
  let setting = false;
15
- const syncDisabled = () => {
16
- checklist.el.setAttribute('aria-disabled', String(disabled));
17
- for (const control of checklist.el.querySelectorAll('input, button, select, textarea')) {
18
- control.disabled = disabled;
19
- }
20
- };
21
14
  field.listen(checklist.el, 'change', (event) => event.stopImmediatePropagation());
22
15
  checklist.on('change', (event) => {
23
16
  if (!setting) field.emit('change', { value: event.detail.values });
24
17
  });
25
- checklist.on('loaded', syncDisabled);
26
18
  return {
27
19
  el: checklist.el,
28
20
  get: () => checklist.getValues(),
29
21
  set: (value) => {
30
22
  setting = true;
31
23
  try {
32
- checklist.setValues(Array.isArray(value) ? value : []);
24
+ // An array is the value, an empty one included; anything else — the Field's '' when no
25
+ // value was given — clears what is shown and leaves items still to load their own flags.
26
+ if (Array.isArray(value)) checklist.setValues(value);
27
+ else checklist.uncheckAll();
33
28
  } finally {
34
29
  setting = false;
35
30
  }
36
- syncDisabled();
37
31
  },
38
32
  focus: () => {
39
33
  const search = checklist.el.querySelector('.zx-checklist__search:not([hidden]):not([disabled])');
40
34
  (search ?? checklist.el.querySelector('input[type="checkbox"]:not([disabled])'))?.focus();
41
35
  },
42
36
  setDisabled: (value) => {
43
- disabled = Boolean(value);
44
- syncDisabled();
37
+ if (value) checklist.disable();
38
+ else checklist.enable();
45
39
  }
46
40
  };
47
41
  });