@zeyos/zx 5.8.1 → 5.9.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 (68) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/types/components/block-view/block-view.d.ts +3 -2
  3. package/dist/types/components/dock/dock.d.ts +2 -1
  4. package/dist/types/components/dropdown/dropdown.d.ts +2 -1
  5. package/dist/types/components/module-bar/module-bar.d.ts +53 -2
  6. package/dist/types/components/run-status/run-status.d.ts +1 -1
  7. package/dist/types/components/run-trace/run-trace.d.ts +8 -0
  8. package/dist/types/components/tabbox/tabbox.d.ts +7 -0
  9. package/dist/types/internal/focus-stops.d.ts +42 -0
  10. package/dist/zx-zeyos.esm.js +87 -25
  11. package/dist/zx-zeyos.esm.min.js +4 -4
  12. package/dist/zx.core.css +9 -2
  13. package/dist/zx.core.min.css +1 -1
  14. package/dist/zx.css +22 -84
  15. package/dist/zx.esm.js +258 -51
  16. package/dist/zx.esm.min.js +26 -26
  17. package/dist/zx.global.js +258 -51
  18. package/dist/zx.global.min.js +26 -26
  19. package/dist/zx.layered.css +22 -84
  20. package/dist/zx.layered.min.css +1 -1
  21. package/dist/zx.min.css +1 -1
  22. package/docs/components/approval-card.md +2 -2
  23. package/docs/components/block-view.md +2 -1
  24. package/docs/components/composer.md +4 -0
  25. package/docs/components/dock.md +4 -1
  26. package/docs/components/dropdown.md +3 -1
  27. package/docs/components/modal.md +3 -0
  28. package/docs/components/navigation-bar.md +5 -0
  29. package/docs/components/questionnaire.md +2 -2
  30. package/docs/components/run-status.md +2 -1
  31. package/docs/components/run-trace.md +2 -1
  32. package/docs/components/tabbox.md +6 -0
  33. package/docs/components/tokens.md +20 -0
  34. package/docs/llms.md +57 -9
  35. package/package.json +1 -1
  36. package/src/components/approval-card/approval-card.css +0 -5
  37. package/src/components/approval-card/approval-card.js +2 -0
  38. package/src/components/block-view/block-view.css +0 -10
  39. package/src/components/block-view/block-view.js +11 -6
  40. package/src/components/card/card.css +3 -0
  41. package/src/components/card-view/card-view.css +5 -5
  42. package/src/components/card-view/card-view.js +3 -1
  43. package/src/components/composer/composer.css +15 -26
  44. package/src/components/copy/copy-input.css +3 -1
  45. package/src/components/dialog/dialog.js +2 -1
  46. package/src/components/dock/dock.css +0 -6
  47. package/src/components/dock/dock.js +22 -7
  48. package/src/components/dropdown/dropdown.js +17 -2
  49. package/src/components/field/field.js +2 -1
  50. package/src/components/master-panel/master-panel.js +3 -1
  51. package/src/components/modal/modal.css +2 -11
  52. package/src/components/modal/modal.js +5 -2
  53. package/src/components/module-bar/module-bar.js +110 -26
  54. package/src/components/navigation-bar/navigation-bar.css +0 -4
  55. package/src/components/navigation-bar/navigation-bar.js +11 -2
  56. package/src/components/questionnaire/questionnaire.css +0 -14
  57. package/src/components/questionnaire/questionnaire.js +4 -2
  58. package/src/components/run-status/run-status.css +0 -7
  59. package/src/components/run-status/run-status.js +3 -1
  60. package/src/components/run-trace/run-trace.css +0 -5
  61. package/src/components/run-trace/run-trace.js +23 -2
  62. package/src/components/surface/surface.css +0 -6
  63. package/src/components/surface/surface.js +1 -1
  64. package/src/components/tabbox/tabbox.css +0 -6
  65. package/src/components/tabbox/tabbox.js +20 -2
  66. package/src/components/table/table.js +5 -0
  67. package/src/internal/focus-stops.js +108 -0
  68. package/styles/base.css +27 -3
@@ -6,6 +6,7 @@ import { ICON_SIZE, icon } from '../../core/icons.js';
6
6
  import { rovingTabindex } from '../../core/keyboard.js';
7
7
  import { storage } from '../../core/storage.js';
8
8
  import { clamp, uid } from '../../core/util.js';
9
+ import { syncPanelStop } from '../../internal/focus-stops.js';
9
10
 
10
11
  /** Storage namespace shared by every dock that opted into persistence. */
11
12
  const STORAGE_NAMESPACE = 'dock';
@@ -459,7 +460,8 @@ export class Dock extends Component {
459
460
  if (!collapsible) toggle.disabled = true;
460
461
 
461
462
  const header = h('div', { class: 'zx-dock__header' }, toggle);
462
- const body = h('div', { class: 'zx-dock__body', id: bodyId });
463
+ // A scroller the browser makes a Tab stop when nothing inside it is focusable: a region, not a control.
464
+ const body = h('div', { class: 'zx-dock__body', id: bodyId, dataset: { zxFocus: 'region' } });
463
465
  const element = h('section', {
464
466
  class: 'zx-dock__pane',
465
467
  dataset: { name, state: 'open' }
@@ -507,13 +509,14 @@ export class Dock extends Component {
507
509
  ariaSelected: 'false',
508
510
  tabindex: -1
509
511
  }, String(tabDefinition.title ?? tabName));
512
+ // A Tab stop only while it holds nothing that is one (see `_materialize()`).
510
513
  const panel = h('div', {
511
514
  class: 'zx-dock__panel',
512
515
  role: 'tabpanel',
513
516
  id: panelId,
514
517
  ariaLabelledby: tabId,
515
- tabindex: 0,
516
- hidden: true
518
+ hidden: true,
519
+ dataset: { zxFocus: 'region' }
517
520
  });
518
521
  list.append(tab);
519
522
  body.append(panel);
@@ -521,6 +524,13 @@ export class Dock extends Component {
521
524
  }
522
525
  header.append(list);
523
526
  record.roving = rovingTabindex(list, '.zx-dock__tab', { orientation: 'horizontal' });
527
+ this.listen(list, 'keydown', (event) => {
528
+ // The panel's content may have changed since it was shown; settle its stop before Tab moves.
529
+ const key = /** @type {KeyboardEvent} */ (event);
530
+ if (key.key !== 'Tab' || key.shiftKey) return;
531
+ const active = record.tabs.get(record.active);
532
+ if (active) syncPanelStop(active.panel);
533
+ });
524
534
  this.listen(list, 'click', (event) => {
525
535
  const button = /** @type {Element} */ (event.target).closest?.('.zx-dock__tab');
526
536
  if (!button || !list.contains(button)) return;
@@ -555,7 +565,8 @@ export class Dock extends Component {
555
565
  }
556
566
 
557
567
  /**
558
- * Runs any not-yet-run content factory for whatever the pane currently shows.
568
+ * Runs any not-yet-run content factory for whatever the pane currently shows, and settles
569
+ * whether a shown tab panel is a Tab stop itself.
559
570
  * @param {Record<string, any>} record Pane record.
560
571
  * @returns {void}
561
572
  */
@@ -563,9 +574,13 @@ export class Dock extends Component {
563
574
  if (record.collapsed) return;
564
575
  if (record.tabs) {
565
576
  const active = record.tabs.get(record.active);
566
- if (!active || active.built) return;
567
- active.built = true;
568
- appendContent(active.panel, active.content, true);
577
+ if (!active) return;
578
+ if (!active.built) {
579
+ active.built = true;
580
+ appendContent(active.panel, active.content, true);
581
+ }
582
+ // APG tabs: the panel is a Tab stop only while nothing inside it is one.
583
+ syncPanelStop(active.panel);
569
584
  return;
570
585
  }
571
586
  if (record.built) return;
@@ -35,7 +35,8 @@ const TABBABLE_SELECTOR = [
35
35
  * panel is hosted by that dialog, so `showModal()` does not make it inert.
36
36
  *
37
37
  * The panel follows its trigger in the Tab order: Tab on the anchor of an open panel moves into
38
- * the panel's first focusable control (or onto the panel itself when it carries a `tabindex`),
38
+ * the panel's first focusable control (or onto the panel itself when it carries a `tabindex`, where
39
+ * it shows focus with the ring inside its edge),
39
40
  * Tab past the panel's last control continues after the anchor, and Shift+Tab from the first goes
40
41
  * back to the anchor. Closing while focus is inside returns it to the anchor.
41
42
  * @fires Dropdown#open
@@ -107,12 +108,25 @@ export class Dropdown extends Component {
107
108
  render() {
108
109
  const panel = h('div', {
109
110
  id: uid('zx-dropdown'),
110
- popover: 'manual'
111
+ popover: 'manual',
112
+ // A surface, not a control: it draws no ring when a script focuses it (`#syncFocusMarker()`).
113
+ dataset: { zxFocus: 'container' }
111
114
  });
112
115
  panel.dataset.state = 'closed';
113
116
  return panel;
114
117
  }
115
118
 
119
+ /**
120
+ * A panel the application put in the Tab order (`tabindex` of 0 or more) is reached from its
121
+ * anchor's Tab, so it shows keyboard focus as a region, with the ring inside its edge; otherwise
122
+ * only a script focuses it and it draws no ring.
123
+ * @returns {void}
124
+ */
125
+ #syncFocusMarker() {
126
+ const reachable = this.el.hasAttribute('tabindex') && this.el.tabIndex >= 0;
127
+ this.el.dataset.zxFocus = reachable ? 'region' : 'container';
128
+ }
129
+
116
130
  /**
117
131
  * Opens and positions the panel.
118
132
  * @returns {this}
@@ -122,6 +136,7 @@ export class Dropdown extends Component {
122
136
  if (this.isOpen() || this.#destroyed) return this;
123
137
  const host = this.#host();
124
138
  if (this.el.parentElement !== host) host.append(this.el);
139
+ this.#syncFocusMarker();
125
140
  this.#position = position(this.#anchor, this.el, {
126
141
  placement: this.options.placement,
127
142
  offset: Number(this.options.offset),
@@ -439,7 +439,8 @@ function validateAdapter(adapter) {
439
439
 
440
440
  /** @param {string} message @param {string} id @returns {FieldAdapter} */
441
441
  function errorAdapter(message, id) {
442
- const el = h('div', { class: 'zx-field__error-control', id, role: 'alert', tabIndex: -1 }, message);
442
+ // Stands in for a control that could not be built; `focus()` reaches it, Tab does not.
443
+ const el = h('div', { class: 'zx-field__error-control', id, role: 'alert', tabIndex: -1, dataset: { zxFocus: 'container' } }, message);
443
444
  return {
444
445
  el,
445
446
  get: () => null,
@@ -78,9 +78,11 @@ export class MasterPanel extends Component {
78
78
  ariaLabel: this.msg('panel.actions')
79
79
  })
80
80
  );
81
+ // It scrolls, so with nothing focusable inside the browser makes it a Tab stop: a region.
81
82
  const content = h('div', {
82
83
  class: 'zx-master-panel__content',
83
- ref: 'content'
84
+ ref: 'content',
85
+ dataset: { zxFocus: 'region' }
84
86
  });
85
87
  const footer = h('footer', {
86
88
  class: 'zx-master-panel__footer',
@@ -34,18 +34,9 @@
34
34
 
35
35
  /*
36
36
  * The panel takes focus itself only as a fallback, when it holds nothing focusable at all. It is a
37
- * surface rather than a control, so that programmatic focus paints no ring; a reader the browser
38
- * reports as navigating by keyboard still gets one, because otherwise focus would be inside the
39
- * overlay with nothing on screen saying so.
37
+ * surface rather than a control and carries `data-zx-focus="container"`, so it draws no focus ring
38
+ * and keeps its own elevation while focused: the open dialog is what shows where focus is.
40
39
  */
41
- .zx-modal:focus {
42
- outline-color: transparent;
43
- }
44
-
45
- .zx-modal:focus-visible {
46
- outline: 2px solid var(--zx-color-ring);
47
- outline-offset: calc(-1 * var(--zx-space-1));
48
- }
49
40
 
50
41
  /*
51
42
  * `:modal` rather than `[open]`: only a dialog opened with `showModal()` blocks the page, and a
@@ -397,7 +397,8 @@ export class Modal extends Component {
397
397
  return;
398
398
  }
399
399
  // A panel holding nothing focusable has to take focus itself, and is made focusable only for
400
- // that: `tabindex="-1"` is programmatic focus, so it adds nothing to the Tab order.
400
+ // that: `tabindex="-1"` is programmatic focus, so it adds nothing to the Tab order, and
401
+ // `data-zx-focus="container"` (set in `render()`) keeps the focus ring off the surface.
401
402
  const panel = /** @type {HTMLElement} */ (this.el);
402
403
  if (!panel.hasAttribute('tabindex')) panel.setAttribute('tabindex', '-1');
403
404
  panel.focus();
@@ -409,7 +410,9 @@ export class Modal extends Component {
409
410
  */
410
411
  render() {
411
412
  const dialog = /** @type {HTMLDialogElement} */ (h('dialog', {
412
- class: 'zx-modal'
413
+ class: 'zx-modal',
414
+ // The panel is a surface, never a control: when it holds focus itself it draws no ring.
415
+ dataset: { zxFocus: 'container' }
413
416
  }, h('div', { class: 'zx-modal__content', ref: 'content' })));
414
417
  dialog.dataset.state = 'closed';
415
418
  this._mountInitial(dialog);
@@ -409,8 +409,10 @@ export class ModuleBar extends AppRailPresenter {
409
409
  }
410
410
 
411
411
  /**
412
- * Shows the tiles that fit, in bar order, and moves the rest behind "All modules". Everything is
413
- * shown first so a bar sized by its content measures as not overflowing and never shrinks itself.
412
+ * Shows the tiles that fit, in bar order, and moves the rest behind "All modules". Every module
413
+ * the bar could place is shown first, so a bar sized by its content measures as not overflowing
414
+ * and never shrinks itself; a module that can only ever be in the catalogue is not, so it takes
415
+ * no room.
414
416
  * @returns {void}
415
417
  */
416
418
  _layout() {
@@ -420,15 +422,17 @@ export class ModuleBar extends AppRailPresenter {
420
422
  const moreRow = list.querySelector(':scope > [data-module-bar-more]');
421
423
  const mode = this.el.dataset.allModules;
422
424
  const keep = [moduleOf(this._items, this._active)?.id, this._expandedId, this._promoted];
423
- let capacity = Infinity;
425
+ // An always-shown button takes its slot whether or not anything overflows.
426
+ const reserve = mode === 'always';
427
+ let partition = partitionModules(this._items, Infinity, keep, reserve);
424
428
  if (mode !== 'never' && list.isConnected) {
425
- for (const row of rows) row.hidden = false;
429
+ const placeable = new Set(partition.visible.map((item) => String(item.id)));
430
+ for (const row of rows) row.hidden = !placeable.has(row.dataset.moduleId);
426
431
  if (moreRow) moreRow.hidden = false;
427
432
  syncHeadings(list);
428
- capacity = measureCapacity(list, this.el.dataset.orientation === 'horizontal', rows.length + 1);
433
+ const space = measureSpace(list, this.el.dataset.orientation === 'horizontal');
434
+ if (space) partition = fitModules(this._items, space, keep, reserve);
429
435
  }
430
- // An always-shown button takes its slot whether or not anything overflows.
431
- const partition = partitionModules(this._items, capacity, keep, mode === 'always');
432
436
  const visible = new Set(partition.visible.map((item) => String(item.id)));
433
437
  for (const row of rows) row.hidden = !visible.has(row.dataset.moduleId);
434
438
  syncHeadings(list);
@@ -885,6 +889,77 @@ export function partitionModules(items, capacity = Infinity, keep = [], reserve
885
889
  return { visible, overflow, more: overflow.length > 0 };
886
890
  }
887
891
 
892
+ /**
893
+ * The bar's list as measured with every module it could place shown: its rows, section headings,
894
+ * and "All modules" button in document order, each with the length it takes along the bar, its
895
+ * margins included.
896
+ * @typedef {Object} ModuleBarSpace
897
+ * @property {number} room Length of the list's content box along the bar.
898
+ * @property {number} [gap=0] Gap between two shown entries.
899
+ * @property {Array<{id?: string, heading?: boolean, more?: boolean, size: number}>} entries Shown
900
+ * entries: a module row by its `id`, a heading, or the button. A heading takes its room only when
901
+ * a module after it, before the next heading, is on the bar.
902
+ */
903
+
904
+ /**
905
+ * Splits modules as `partitionModules()` does, giving it the most slots for which what it places
906
+ * fits the measured list: each row at its own length, a section heading only where one of its
907
+ * modules is on the bar, and the "All modules" button when it is shown. So one name that wraps to
908
+ * two lines costs its extra line, not a tile, and no row is ever cut in half. Kept modules stay
909
+ * on the bar even when nothing else fits, as with `partitionModules()`.
910
+ * @param {ModuleItem[]} items Modules.
911
+ * @param {ModuleBarSpace} space The measured list.
912
+ * @param {Array<string|number|null|undefined>|string|number|null} [keep=[]] Module ids that must stay visible.
913
+ * @param {boolean} [reserve=false] The button is shown even when every module fits.
914
+ * @returns {{visible: ModuleItem[], overflow: ModuleItem[], more: boolean}}
915
+ */
916
+ export function fitModules(items, space, keep = [], reserve = false) {
917
+ const fits = (partition) => barExtent(space, partition.visible, reserve || partition.more) <= space.room + 0.5;
918
+ const all = partitionModules(items, Infinity, keep, reserve);
919
+ if (fits(all)) return all;
920
+ // Less than everything needs the button, so every smaller count reserves its slot; without that,
921
+ // a count equal to the modules would place them all and leave the button out. A smaller count
922
+ // then never places a module a larger one leaves off, so the length grows with the count and the
923
+ // largest count that fits is found by bisection. One slot, the kept modules alone, is the floor.
924
+ let low = 1;
925
+ let high = all.visible.length;
926
+ while (low < high) {
927
+ const middle = Math.ceil((low + high) / 2);
928
+ if (fits(partitionModules(items, middle, keep, true))) low = middle;
929
+ else high = middle - 1;
930
+ }
931
+ return partitionModules(items, low, keep, true);
932
+ }
933
+
934
+ /**
935
+ * The length the list's entries take with these modules on the bar.
936
+ * @param {ModuleBarSpace} space The measured list.
937
+ * @param {ModuleItem[]} visible Modules on the bar.
938
+ * @param {boolean} more Whether the "All modules" button is shown.
939
+ * @returns {number}
940
+ */
941
+ function barExtent(space, visible, more) {
942
+ const shown = new Set(visible.map((item) => String(item.id)));
943
+ let total = 0;
944
+ let count = 0;
945
+ let heading = null;
946
+ for (const entry of space.entries ?? []) {
947
+ if (entry.heading) {
948
+ heading = entry;
949
+ continue;
950
+ }
951
+ if (entry.more ? !more : !shown.has(String(entry.id))) continue;
952
+ if (heading && !entry.more) {
953
+ total += heading.size;
954
+ count += 1;
955
+ }
956
+ heading = null;
957
+ total += entry.size;
958
+ count += 1;
959
+ }
960
+ return total + Math.max(0, count - 1) * (space.gap ?? 0);
961
+ }
962
+
888
963
  /**
889
964
  * Resolves a module's identity colour: a valid CSS `color` wins, then a known `tone`.
890
965
  * @param {{tone?: unknown, color?: unknown}} item Module.
@@ -970,31 +1045,40 @@ function barOrder(items) {
970
1045
  }
971
1046
 
972
1047
  /**
973
- * How many rows fit the list along its main axis, measured with every row shown.
1048
+ * Measures the list along its main axis for `fitModules()`, as it stands: with every module the
1049
+ * bar could place shown. Null when that already fits, or when the list has not been laid out.
974
1050
  * @param {HTMLElement} list Bar list.
975
1051
  * @param {boolean} horizontal Flow.
976
- * @param {number} count Rows, the button included.
977
- * @returns {number}
1052
+ * @returns {ModuleBarSpace|null}
978
1053
  */
979
- function measureCapacity(list, horizontal, count) {
1054
+ function measureSpace(list, horizontal) {
980
1055
  const overflowing = horizontal ? list.scrollWidth > list.clientWidth + 1 : list.scrollHeight > list.clientHeight + 1;
981
- if (!overflowing) return Infinity;
982
- // Names may wrap a row to two lines: the tallest row decides, so no row is ever cut in half.
983
- const rows = /** @type {HTMLElement[]} */ ([...list.querySelectorAll(':scope > li:not([hidden]):not(.zx-module-bar__heading)')]);
984
- if (!rows.length) return Infinity;
985
- const headings = /** @type {HTMLElement[]} */ ([...list.querySelectorAll(':scope > li.zx-module-bar__heading:not([hidden])')]);
1056
+ if (!overflowing) return null;
1057
+ const axis = horizontal ? 'Inline' : 'Block';
1058
+ /** @param {CSSStyleDeclaration} style @param {string} prefix @param {string} [suffix=''] @returns {number} */
1059
+ const edges = (style, prefix, suffix = '') => (Number.parseFloat(style[`${prefix}${axis}Start${suffix}`]) || 0)
1060
+ + (Number.parseFloat(style[`${prefix}${axis}End${suffix}`]) || 0);
1061
+ // Lengths are read from the drawn boxes for their fractions, and brought back to layout pixels,
1062
+ // which margins and gaps are in, for a bar drawn scaled (a thumbnail of a layout).
1063
+ const drawn = (element) => element.getBoundingClientRect()[horizontal ? 'width' : 'height'];
1064
+ const laid = horizontal ? list.offsetWidth : list.offsetHeight;
1065
+ const scale = laid > 0 && drawn(list) > 0 ? drawn(list) / laid : 1;
986
1066
  const style = getComputedStyle(list);
1067
+ const room = laid - edges(style, 'padding') - edges(style, 'border', 'Width');
987
1068
  const gap = Number.parseFloat(horizontal ? style.columnGap : style.rowGap) || 0;
988
- const padding = horizontal
989
- ? (Number.parseFloat(style.paddingInlineStart) || 0) + (Number.parseFloat(style.paddingInlineEnd) || 0)
990
- : (Number.parseFloat(style.paddingBlockStart) || 0) + (Number.parseFloat(style.paddingBlockEnd) || 0);
991
- const size = Math.max(...rows.map((row) => (horizontal ? row.offsetWidth : row.offsetHeight)));
992
- const headingSpace = headings.reduce((sum, heading) => sum + gap + (horizontal ? heading.offsetWidth : heading.offsetHeight)
993
- + (Number.parseFloat(horizontal ? getComputedStyle(heading).marginInlineStart : getComputedStyle(heading).marginBlockStart) || 0)
994
- + (Number.parseFloat(horizontal ? getComputedStyle(heading).marginInlineEnd : getComputedStyle(heading).marginBlockEnd) || 0), 0);
995
- const available = (horizontal ? list.clientWidth : list.clientHeight) - padding - headingSpace;
996
- if (size <= 0 || available <= 0) return count;
997
- return Math.max(1, Math.floor((available + gap) / (size + gap)));
1069
+ /** @type {ModuleBarSpace['entries']} */
1070
+ const entries = [];
1071
+ for (const child of /** @type {HTMLElement[]} */ ([...list.children])) {
1072
+ const childStyle = getComputedStyle(child);
1073
+ if (child.hidden || childStyle.display === 'none') continue;
1074
+ const size = drawn(child) / scale + edges(childStyle, 'margin');
1075
+ if (child.classList.contains('zx-module-bar__heading')) entries.push({ heading: true, size });
1076
+ else if (child.hasAttribute('data-module-bar-more')) entries.push({ more: true, size });
1077
+ else if (child.dataset.moduleId != null) entries.push({ id: child.dataset.moduleId, size });
1078
+ }
1079
+ // A list with no room, or rows without size, has not been laid out: nothing is moved off the bar.
1080
+ if (room <= 0 || !entries.some((entry) => entry.id != null && entry.size > 0)) return null;
1081
+ return { room, gap, entries };
998
1082
  }
999
1083
 
1000
1084
  /** @param {HTMLElement[]} entries @param {HTMLElement} current @param {1|-1} direction @returns {HTMLElement|null} */
@@ -144,10 +144,6 @@
144
144
  padding: var(--zx-space-4);
145
145
  }
146
146
 
147
- .zx-navigation-bar__panel:focus-visible {
148
- box-shadow: inset var(--zx-focus-ring);
149
- }
150
-
151
147
  /*
152
148
  * Overflow.
153
149
  *
@@ -2,6 +2,7 @@ import { Component } from '../../core/component.js';
2
2
  import { h } from '../../core/dom.js';
3
3
  import { rovingStep } from '../../core/keyboard.js';
4
4
  import { isElement, uid } from '../../core/util.js';
5
+ import { syncPanelStop } from '../../internal/focus-stops.js';
5
6
  import { button } from '../button/button.js';
6
7
  import { MenuButton } from '../menu-button/menu-button.js';
7
8
 
@@ -330,13 +331,14 @@ export class NavigationBar extends Component {
330
331
 
331
332
  let panel = null;
332
333
  if (this._tabMode) {
334
+ // A Tab stop only while it holds nothing that is one (see `_applyActive()`).
333
335
  panel = h('div', {
334
336
  class: 'zx-navigation-bar__panel',
335
337
  id: panelId,
336
338
  role: 'tabpanel',
337
- tabindex: '0',
338
339
  ariaLabelledby: tabId,
339
- hidden: true
340
+ hidden: true,
341
+ dataset: { zxFocus: 'region' }
340
342
  });
341
343
  this.refs.panels.append(panel);
342
344
  }
@@ -363,6 +365,7 @@ export class NavigationBar extends Component {
363
365
  item.item.setAttribute('aria-selected', String(active));
364
366
  item.item.tabIndex = active ? 0 : -1;
365
367
  if (item.panel) item.panel.hidden = !active;
368
+ if (active && item.panel) syncPanelStop(item.panel);
366
369
  } else if (active) {
367
370
  item.item.setAttribute('aria-current', 'page');
368
371
  } else {
@@ -392,6 +395,12 @@ export class NavigationBar extends Component {
392
395
  if (!item || !this.refs.items.contains(item)) return;
393
396
  const current = this._items.find((record) => record.item === item);
394
397
  if (!current) return;
398
+ if (event.key === 'Tab' && !event.shiftKey) {
399
+ // The panel's content may have changed since it was shown; settle its stop before Tab moves.
400
+ const active = this._activeName === null ? null : this._find(this._activeName);
401
+ if (active?.panel) syncPanelStop(active.panel);
402
+ return;
403
+ }
395
404
  const enabled = this._enabledItems();
396
405
  if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
397
406
  event.preventDefault();
@@ -50,16 +50,6 @@
50
50
  min-inline-size: 0;
51
51
  }
52
52
 
53
- .zx-questionnaire__item:focus {
54
- outline-color: transparent;
55
- }
56
-
57
- .zx-questionnaire__item:focus-visible {
58
- outline-color: transparent;
59
- box-shadow: var(--zx-focus-ring);
60
- border-radius: var(--zx-questionnaire-radius);
61
- }
62
-
63
53
  /* `<legend>` is laid out by the fieldset rather than by its own display, so it is taken out of
64
54
  that flow and placed as an ordinary block before the answers. */
65
55
  .zx-questionnaire__prompt {
@@ -290,10 +280,6 @@
290
280
  gap: var(--zx-space-3);
291
281
  }
292
282
 
293
- .zx-questionnaire__review:focus {
294
- outline-color: transparent;
295
- }
296
-
297
283
 
298
284
  .zx-questionnaire__review-title {
299
285
  margin: 0;
@@ -205,11 +205,13 @@ export class Questionnaire extends Component {
205
205
  this._form.setAttribute('novalidate', '');
206
206
 
207
207
  this._progressHost = h('div', { class: 'zx-questionnaire__progress', hidden: !this.options.progress });
208
+ // Both take focus only from a script, when a step changes under the reader; neither is a Tab stop.
208
209
  this._itemHost = h('fieldset', {
209
210
  class: 'zx-questionnaire__item',
210
- tabIndex: -1
211
+ tabIndex: -1,
212
+ dataset: { zxFocus: 'container' }
211
213
  });
212
- this._reviewHost = h('div', { class: 'zx-questionnaire__review', tabIndex: -1, hidden: true });
214
+ this._reviewHost = h('div', { class: 'zx-questionnaire__review', tabIndex: -1, hidden: true, dataset: { zxFocus: 'container' } });
213
215
  this._actionsHost = h('div', { class: 'zx-questionnaire__actions' });
214
216
  this.refs.item = this._itemHost;
215
217
  this.refs.review = this._reviewHost;
@@ -12,13 +12,6 @@
12
12
  font-size: var(--zx-text-sm);
13
13
  }
14
14
 
15
- /* The panel holds focus itself only when an update took away the control that had it. */
16
- .zx-run-status:focus-visible {
17
- border-radius: var(--zx-radius-md);
18
- outline-color: transparent;
19
- box-shadow: var(--zx-focus-ring);
20
- }
21
-
22
15
  /* ------------------------------------------------------------------ state -- */
23
16
 
24
17
  .zx-run-status__state {
@@ -221,7 +221,7 @@ export class RunStatus extends Component {
221
221
  /** @type {AgentAvatar|null} The agent's face, kept across draws while it asks for the same traits. */
222
222
  this._avatar = null;
223
223
  this._faceKey = '';
224
- /** Whether the root took `tabindex="-1"` to hold focus that had nowhere else to go. */
224
+ /** Whether the root took `tabindex="-1"` (and `data-zx-focus`) to hold focus that had nowhere else to go. */
225
225
  this._heldFocus = false;
226
226
  /** @type {ReturnType<typeof setInterval>|0} */
227
227
  this._interval = 0;
@@ -424,6 +424,7 @@ export class RunStatus extends Component {
424
424
  }
425
425
  if (!root.hasAttribute('tabindex')) {
426
426
  root.tabIndex = -1;
427
+ root.dataset.zxFocus = 'container';
427
428
  this._heldFocus = true;
428
429
  }
429
430
  root.focus({ preventScroll: true });
@@ -434,6 +435,7 @@ export class RunStatus extends Component {
434
435
  if (!this._heldFocus) return;
435
436
  this._heldFocus = false;
436
437
  this.el.removeAttribute('tabindex');
438
+ this.el.removeAttribute('data-zx-focus');
437
439
  }
438
440
 
439
441
  /**
@@ -398,11 +398,6 @@ button.zx-run-trace__row:hover {
398
398
  background: var(--zx-color-danger-bg);
399
399
  }
400
400
 
401
- .zx-run-trace__code:focus-visible {
402
- outline-color: transparent;
403
- box-shadow: var(--zx-focus-ring);
404
- }
405
-
406
401
  .zx-run-trace__more {
407
402
  justify-self: start;
408
403
  }
@@ -5,6 +5,7 @@ import { icon } from '../../core/icons.js';
5
5
  import { formatNumber } from '../../core/format.js';
6
6
  import { prefersReducedMotion } from '../../core/motion.js';
7
7
  import { uid } from '../../core/util.js';
8
+ import { syncScrollStop } from '../../internal/focus-stops.js';
8
9
  import {
9
10
  AGENT_MESSAGES, STATUS, agentAvatarOptions, authorFace, formatDuration, formatElapsed, initialsOf, normalizeRunState, traceSummary
10
11
  } from '../../internal/agent-model.js';
@@ -263,6 +264,9 @@ export class RunTrace extends Component {
263
264
  }
264
265
  });
265
266
  if (this.options.ticking) this.listen(root.ownerDocument, 'visibilitychange', () => this._syncClock());
267
+ // A width change rewraps the code blocks, which can start or stop them scrolling.
268
+ this._resize = typeof ResizeObserver === 'function' ? new ResizeObserver(() => this._syncCodeStops(root)) : null;
269
+ this._resize?.observe(root);
266
270
  this._build(this.options.steps);
267
271
  return root;
268
272
  }
@@ -391,6 +395,8 @@ export class RunTrace extends Component {
391
395
  this._revealTimer = null;
392
396
  if (this._clock) clearInterval(this._clock);
393
397
  this._clock = null;
398
+ this._resize?.disconnect();
399
+ this._resize = null;
394
400
  for (const entry of this._entries.values()) this._releaseAvatars(entry);
395
401
  this._entries.clear();
396
402
  super.destroy();
@@ -531,6 +537,7 @@ export class RunTrace extends Component {
531
537
  entry.row = row;
532
538
  entry.refs = refs;
533
539
  entry.body = body;
540
+ if (body) this._syncCodeStops(body);
534
541
  const again = focusedRef === null ? null
535
542
  : /** @type {HTMLElement|null} */ (refs?.querySelector(`[data-ref-index="${focusedRef}"]`) ?? null);
536
543
  if (again) again.focus({ preventScroll: true });
@@ -666,11 +673,11 @@ export class RunTrace extends Component {
666
673
  h('div', { class: 'zx-run-trace__section-head' },
667
674
  h('span', { class: 'zx-run-trace__section-title', id: titleId }, this.msg(keys.title)),
668
675
  copyButton({ text: full, title: this.msg(keys.copy), feedback: this.msg('runTrace.copied'), size: 'sm' })),
676
+ // A Tab stop only while its text scrolls (`_syncCodeStops()`).
669
677
  h('pre', {
670
678
  class: 'zx-run-trace__code',
671
- tabindex: '0',
672
679
  'aria-labelledby': titleId,
673
- dataset: { tone: kind === 'error' ? 'danger' : null }
680
+ dataset: { tone: kind === 'error' ? 'danger' : null, zxFocus: 'region' }
674
681
  }, shown.text),
675
682
  shown.cut ? h('button', {
676
683
  type: 'button', class: 'zx-btn zx-run-trace__more', dataset: { kind: 'ghost', size: 'sm', action: 'show-all' }
@@ -689,6 +696,7 @@ export class RunTrace extends Component {
689
696
  this._open = open;
690
697
  this._summary.setAttribute('aria-expanded', String(open));
691
698
  this._list.hidden = !open;
699
+ if (open) this._syncCodeStops(this._list);
692
700
  this._syncClock();
693
701
  this.emit('toggle', { id: null, open });
694
702
  }
@@ -706,9 +714,22 @@ export class RunTrace extends Component {
706
714
  else this._expanded.delete(id);
707
715
  entry.row.setAttribute('aria-expanded', String(open));
708
716
  entry.body.hidden = !open;
717
+ if (open) this._syncCodeStops(entry.body);
709
718
  this.emit('toggle', { id, open });
710
719
  }
711
720
 
721
+ /**
722
+ * Makes each code block a Tab stop while, and only while, its text scrolls inside it.
723
+ * @private
724
+ * @param {Element} scope Where to look for code blocks.
725
+ * @returns {void}
726
+ */
727
+ _syncCodeStops(scope) {
728
+ for (const code of /** @type {NodeListOf<HTMLElement>} */ (scope.querySelectorAll('.zx-run-trace__code'))) {
729
+ syncScrollStop(code);
730
+ }
731
+ }
732
+
712
733
  /**
713
734
  * Redraws the summary from the steps.
714
735
  * @private
@@ -291,12 +291,6 @@
291
291
  font-size: var(--zx-text-sm);
292
292
  }
293
293
 
294
- .zx-surface__verdict:focus-visible {
295
- border-radius: var(--zx-radius-sm);
296
- outline-color: transparent;
297
- box-shadow: var(--zx-focus-ring);
298
- }
299
-
300
294
  .zx-surface__verdict-icon {
301
295
  display: inline-flex;
302
296
  }
@@ -1829,7 +1829,7 @@ export class Surface extends Component {
1829
1829
  for (const [id, node] of this._model.nodes) if (this._entry(node.type)?.input) this._dirty.add(id);
1830
1830
  const time = formatTime(reply.at, this.options.locale);
1831
1831
  const verdict = verdictText(reply.action, this._model.actions ?? [], (key, ...args) => this.msg(key, ...args));
1832
- this._verdict = h('p', { class: 'zx-surface__verdict', tabIndex: -1, dataset: { action: reply.action } },
1832
+ this._verdict = h('p', { class: 'zx-surface__verdict', tabIndex: -1, dataset: { action: reply.action, zxFocus: 'container' } },
1833
1833
  h('span', { class: 'zx-surface__verdict-icon', 'aria-hidden': 'true' },
1834
1834
  icon(CLOSING_ACTIONS.includes(reply.action) || reply.action === 'reject' ? 'x' : 'check', { size: 14 })),
1835
1835
  h('span', {}, time ? this.msg('surface.verdictAt', verdict, time) : verdict));
@@ -292,9 +292,3 @@
292
292
  .zx-tabbox[data-variant="bracket"] .zx-tabbox__panel {
293
293
  padding: var(--zx-space-4);
294
294
  }
295
-
296
- .zx-tabbox__panel:focus-visible {
297
- outline-color: transparent;
298
- outline-offset: -2px;
299
- box-shadow: inset var(--zx-focus-ring);
300
- }