@fusion.dev/helix-headless 0.151.0 → 0.153.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 (54) hide show
  1. package/custom-elements.json +1332 -37
  2. package/dist/app-header/root/app-header-root.d.ts +75 -0
  3. package/dist/app-header/root/app-header-root.js +140 -5
  4. package/dist/area-chart/root/area-chart-root.d.ts +16 -1
  5. package/dist/area-chart/root/area-chart-root.js +3 -3
  6. package/dist/bar-chart/root/bar-chart-root.d.ts +16 -1
  7. package/dist/bar-chart/root/bar-chart-root.js +3 -3
  8. package/dist/breadcrumbs/breadcrumb/breadcrumb.d.ts +11 -2
  9. package/dist/breadcrumbs/breadcrumb/breadcrumb.js +11 -2
  10. package/dist/breadcrumbs/root/breadcrumbs-root.d.ts +14 -2
  11. package/dist/breadcrumbs/root/breadcrumbs-root.js +16 -3
  12. package/dist/dialog/description.d.ts +10 -0
  13. package/dist/dialog/description.js +22 -8
  14. package/dist/dialog/root/dialog-root.d.ts +17 -1
  15. package/dist/dialog/root/dialog-root.js +2 -2
  16. package/dist/drawer/root/drawer-root.d.ts +38 -2
  17. package/dist/drawer/root/drawer-root.js +33 -6
  18. package/dist/heatmap/root/heatmap-root.d.ts +3 -0
  19. package/dist/heatmap/root/heatmap-root.js +2 -8
  20. package/dist/lightbox/root/lightbox-root.d.ts +44 -6
  21. package/dist/lightbox/root/lightbox-root.js +59 -11
  22. package/dist/lightbox/zoom-controller.d.ts +5 -0
  23. package/dist/lightbox/zoom-controller.js +8 -0
  24. package/dist/line-chart/root/line-chart-root.d.ts +16 -1
  25. package/dist/line-chart/root/line-chart-root.js +3 -3
  26. package/dist/loader/root/loader-root.d.ts +5 -0
  27. package/dist/menu/root/menu-root.js +2 -0
  28. package/dist/navigation/root/navigation-root.d.ts +11 -1
  29. package/dist/navigation/root/navigation-root.js +10 -5
  30. package/dist/notifications/root/notifications-root.d.ts +17 -0
  31. package/dist/notifications/root/notifications-root.js +21 -1
  32. package/dist/popover/root/popover-root.d.ts +18 -7
  33. package/dist/popover/root/popover-root.js +8 -1
  34. package/dist/progress/root/progress-root.d.ts +16 -1
  35. package/dist/progress/root/progress-root.js +12 -4
  36. package/dist/scatter-chart/root/scatter-chart-root.d.ts +16 -1
  37. package/dist/scatter-chart/root/scatter-chart-root.js +3 -3
  38. package/dist/splitter/root/splitter-root.d.ts +41 -0
  39. package/dist/splitter/root/splitter-root.js +77 -0
  40. package/dist/tabs/root/tabs-root.d.ts +25 -0
  41. package/dist/tabs/root/tabs-root.js +28 -1
  42. package/dist/tour/naming.d.ts +9 -3
  43. package/dist/tour/naming.js +9 -3
  44. package/dist/tour/root/tour-root.d.ts +29 -5
  45. package/dist/tour/root/tour-root.js +13 -1
  46. package/dist/tour/stop/tour-stop.d.ts +2 -1
  47. package/dist/tour/stop/tour-stop.js +4 -1
  48. package/dist/tree/root/tree-root.d.ts +13 -0
  49. package/dist/tree/root/tree-root.js +42 -2
  50. package/lint.json +1 -1
  51. package/package.json +5 -5
  52. package/types/jsx.d.ts +1456 -36
  53. package/types/vue.d.ts +277 -24
  54. package/types/words.d.ts +64 -0
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { AriaForwardController, customElement, HelixElement, IndicatorController, KeyboardNavigationController, MixinControllerActive, whenHydrated, words, } from '@fusion.dev/helix-core';
7
+ import { AriaForwardController, customElement, deepActiveElement, HelixActivateEvent, HelixElement, IndicatorController, KeyboardNavigationController, MixinControllerActive, whenHydrated, words, } from '@fusion.dev/helix-core';
8
8
  import { html, nothing } from 'lit';
9
9
  import { property } from 'lit/decorators.js';
10
10
  import { HelixHeadlessTabPanel } from '../panel/tab-panel.js';
@@ -35,9 +35,15 @@ let HelixHeadlessTabs = class HelixHeadlessTabs extends MixinControllerActive(He
35
35
  }
36
36
  this.requestActive(event.detail.value);
37
37
  };
38
+ this.held = [];
39
+ this.handleFocusIn = (event) => {
40
+ const path = event.composedPath();
41
+ this.focused = this.tabs.find((tab) => path.includes(tab));
42
+ };
38
43
  this.handleSlotChange = () => {
39
44
  this.sync();
40
45
  this.indicator.place();
46
+ this.refocus();
41
47
  };
42
48
  }
43
49
  static { this.words = 'helix-tabs'; }
@@ -54,6 +60,13 @@ let HelixHeadlessTabs = class HelixHeadlessTabs extends MixinControllerActive(He
54
60
  const tabs = this.tabs;
55
61
  const declared = this.active === '' ? tabs.find((tab) => tab.selected) : undefined;
56
62
  const value = (declared ?? this.resolveActive(tabs))?.value ?? '';
63
+ const previous = this.active;
64
+ const gone = this.held.includes(previous) && !tabs.some((tab) => tab.value === previous);
65
+ this.held = tabs.map((tab) => tab.value);
66
+ if (gone && value !== '') {
67
+ this.active = value;
68
+ this.dispatchEvent(new HelixActivateEvent({ previous, value }));
69
+ }
57
70
  for (const tab of tabs) {
58
71
  const selected = tab.value === value;
59
72
  whenHydrated(tab, () => {
@@ -77,13 +90,27 @@ let HelixHeadlessTabs = class HelixHeadlessTabs extends MixinControllerActive(He
77
90
  });
78
91
  }
79
92
  }
93
+ refocus() {
94
+ const gone = this.focused;
95
+ if (!gone || this.tabs.includes(gone)) {
96
+ return;
97
+ }
98
+ this.focused = undefined;
99
+ const active = deepActiveElement();
100
+ if (active !== null && active !== document.body) {
101
+ return;
102
+ }
103
+ void this.updateComplete.then(() => this.tabs.find((tab) => tab.selected)?.focus());
104
+ }
80
105
  connectedCallback() {
81
106
  super.connectedCallback();
82
107
  this.addEventListener('helix-select', this.handleSelection);
108
+ this.addEventListener('focusin', this.handleFocusIn);
83
109
  }
84
110
  disconnectedCallback() {
85
111
  super.disconnectedCallback();
86
112
  this.removeEventListener('helix-select', this.handleSelection);
113
+ this.removeEventListener('focusin', this.handleFocusIn);
87
114
  }
88
115
  firstUpdated(changed) {
89
116
  super.firstUpdated(changed);
@@ -15,6 +15,11 @@ export interface StopWords {
15
15
  heading: readonly Element[];
16
16
  /** Whether the stop has a `label` of its own. */
17
17
  labeled: boolean;
18
+ /**
19
+ * The region that holds the content, given where the content holds words
20
+ * with no element around them, which then describes the panel.
21
+ */
22
+ loose?: Element | null;
18
23
  /** The element that says the stop's place in the tour, such as "2 of 5". */
19
24
  progress: Element | null;
20
25
  }
@@ -24,7 +29,8 @@ export interface StopWords {
24
29
  * Named by the `heading` slot, then by the first heading in the content, then
25
30
  * by the stop's own `label`, and where there is none of those, by its place in
26
31
  * the tour, so no stop is an unnamed group. Described by the `description`
27
- * slot and by its place, which is how a screen reader hears where it is as
28
- * focus moves from one stop to the next.
32
+ * slot, or where it is empty by the words at the start of the content, as a
33
+ * `Dialog` is, and then by its place, which is how a screen reader hears where
34
+ * it is as focus moves from one stop to the next.
29
35
  */
30
- export declare const stopNaming: ({ content, description, heading, labeled, progress, }: StopWords) => StopNaming;
36
+ export declare const stopNaming: ({ content, description, heading, labeled, loose, progress, }: StopWords) => StopNaming;
@@ -1,10 +1,16 @@
1
1
  import { headingIn } from '@fusion.dev/helix-core';
2
- export const stopNaming = ({ content, description, heading, labeled, progress, }) => {
2
+ import { wordsAmong } from '../dialog/description.js';
3
+ export const stopNaming = ({ content, description, heading, labeled, loose = null, progress, }) => {
3
4
  const first = heading.length > 0 ? null : headingIn(content);
4
5
  const found = heading.length > 0 ? [...heading] : first ? [first] : [];
5
6
  const place = progress ? [progress] : [];
7
+ const said = description.length > 0
8
+ ? [...description]
9
+ : content.length === 0 && loose
10
+ ? [loose]
11
+ : wordsAmong(content, first);
6
12
  if (found.length === 0 && !labeled) {
7
- return { describedBy: [...description], labelledBy: place };
13
+ return { describedBy: said, labelledBy: place };
8
14
  }
9
- return { describedBy: [...description, ...place], labelledBy: found };
15
+ return { describedBy: [...said, ...place], labelledBy: found };
10
16
  };
@@ -40,11 +40,27 @@ declare const HelixHeadlessTour_base: (new (...args: any[]) => import("@fusion.d
40
40
  * you have moved it somewhere else on the page. A stop does not trap focus, so
41
41
  * you can still `Tab` out to the element it describes.
42
42
  *
43
- * **The arrow keys move between stops** while focus is in one: the arrow that
44
- * points the way the line runs goes on, and the other goes back, so on a
45
- * right-to-left page `ArrowLeft` goes on. Neither finishes the tour at the last
46
- * stop, and a text field in a stop keeps its own arrows. `Escape` skips the
47
- * tour.
43
+ * **The target is scrolled into view** before its stop is shown, by the
44
+ * least distance that brings it on screen, so the stop that points at it is
45
+ * on screen too.
46
+ *
47
+ * **Keyboard.** Focus is on the current stop's panel, which is not in the
48
+ * `Tab` order itself.
49
+ *
50
+ * | Key | What it does |
51
+ * |---|---|
52
+ * | Right | Goes to the next stop. On the last stop it does nothing, and Next finishes the tour. |
53
+ * | Left | Goes back to the previous stop. |
54
+ * | Escape | Skips the tour, and puts focus back where it was when the tour opened. |
55
+ * | Tab, Shift+Tab | Moves through the controls in the stop, and on out to the page. A stop does not trap focus. |
56
+ * | Enter, Space | On Back, Next, or Skip, presses it. |
57
+ *
58
+ * The arrow that points the way the line runs goes on, and the other goes
59
+ * back, so on a right-to-left page Left goes on and Right goes back. A text field in a stop keeps
60
+ * its own arrows.
61
+ *
62
+ * The tour is a region named by `label` while it runs. A development build
63
+ * warns when a tour opens with no `label`.
48
64
  *
49
65
  * @since 0.1.0
50
66
  * @status stable
@@ -186,6 +202,14 @@ export declare class HelixHeadlessTour extends HelixHeadlessTour_base {
186
202
  disconnectedCallback(): void;
187
203
  protected willUpdate(changed: PropertyValues): void;
188
204
  protected updated(changed: PropertyValues): void;
205
+ /** The target last scrolled into view, so a render that moved nothing scrolls nothing. */
206
+ private revealed;
207
+ /**
208
+ * Scrolls the current target into view, by the least distance that brings
209
+ * it on screen, before its stop is shown beside it. Zag's tour does the same.
210
+ * A target already on screen does not move.
211
+ */
212
+ private reveal;
189
213
  /** Where focus was when the tour opened, to give it back when it ends. */
190
214
  private returnFocus;
191
215
  /** Whether `follow` has seen the first update. */
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { controlsIn, customElement, deepActiveElement, deepContains, formatWords, HelixActivateEvent, HelixBeforeActivateEvent, HelixCompleteEvent, HelixElement, HelixTourStatusEvent, hostAria, inlineStep, keyClaimed, MixinControllerOpen, requestChange, whenHydrated, words, } from '@fusion.dev/helix-core';
7
+ import { auditName, controlsIn, customElement, deepActiveElement, deepContains, formatWords, HelixActivateEvent, HelixBeforeActivateEvent, HelixCompleteEvent, HelixElement, HelixTourStatusEvent, hostAria, inlineStep, keyClaimed, MixinControllerOpen, requestChange, whenHydrated, words, } from '@fusion.dev/helix-core';
8
8
  import { html } from 'lit';
9
9
  import { property, queryAssignedElements, state } from 'lit/decorators.js';
10
10
  import { stopBefore } from '../back.js';
@@ -151,11 +151,23 @@ let HelixHeadlessTour = class HelixHeadlessTour extends MixinControllerOpen(Heli
151
151
  }
152
152
  updated(changed) {
153
153
  super.updated(changed);
154
+ this.reveal();
154
155
  this.settle();
155
156
  this.light();
157
+ if (changed.has('open') && this.open) {
158
+ auditName(this, () => null, 'Give it a `label`, such as "Getting started".', () => this.label !== '');
159
+ }
156
160
  this.follow(changed);
157
161
  this.wait();
158
162
  }
163
+ reveal() {
164
+ const target = this.lit ?? undefined;
165
+ if (target === this.revealed) {
166
+ return;
167
+ }
168
+ this.revealed = target;
169
+ target?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
170
+ }
159
171
  follow(changed) {
160
172
  if (!this.followed) {
161
173
  this.followed = true;
@@ -37,7 +37,8 @@ import '../../button/index.js';
37
37
  * The panel is a `group`, and a `dialog` for a dialog stop, only while the
38
38
  * stop is shown. It is named by the `heading` slot, then by the first heading
39
39
  * in the content, then by `label`, and otherwise by its place in the tour. It
40
- * is described by the `description` slot and by its place, such as "2 of 5",
40
+ * is described by the `description` slot, or where that is empty by the words
41
+ * at the start of the content, and by its place, such as "2 of 5",
41
42
  * so a screen reader says where the reader is at every stop. `focus()` moves
42
43
  * focus to the panel, which is what the tour does when it opens or moves on.
43
44
  *
@@ -68,6 +68,9 @@ let HelixHeadlessTourStop = class HelixHeadlessTourStop extends HelixElement {
68
68
  description: slotted('description'),
69
69
  heading: slotted('heading'),
70
70
  labeled: this.label !== '',
71
+ loose: [...this.childNodes].some((one) => one.nodeType === Node.TEXT_NODE && (one.textContent ?? '').trim() !== '')
72
+ ? this.partNamed('content')
73
+ : null,
71
74
  progress: this.position === '' ? null : this.partNamed('progress'),
72
75
  });
73
76
  reflectElements(bubble, 'ariaLabelledByElements', labelledBy, true);
@@ -127,7 +130,7 @@ let HelixHeadlessTourStop = class HelixHeadlessTourStop extends HelixElement {
127
130
  ></div>
128
131
  <slot name="heading" part="heading" @slotchange=${this.nameByHeading}></slot>
129
132
  <slot name="description" part="description" @slotchange=${this.nameByHeading}></slot>
130
- <div part="content"><slot></slot></div>
133
+ <div part="content"><slot @slotchange=${this.nameByHeading}></slot></div>
131
134
  ${this.position === ''
132
135
  ? ''
133
136
  : html `<span part="progress" ?hidden=${!this.progress}>${this.position}</span>`}
@@ -36,6 +36,9 @@ declare const HelixHeadlessTree_base: (new (...args: any[]) => import("@fusion.d
36
36
  * tree of check marks, Control+A (Command+A on an Apple keyboard) checks every
37
37
  * item or clears them all, and Shift with Up or Down Arrow moves and checks.
38
38
  *
39
+ * Removing the item that has focus moves focus to the item after it among its
40
+ * siblings, or the one before, or its parent, so focus stays in the tree.
41
+ *
39
42
  * **`reorderable` lets you move items among their siblings.** Alt with Up or
40
43
  * Down moves the focused item a place, and Alt with Home or End to the first
41
44
  * or the last place among its siblings, as the APG's rearrangeable listbox
@@ -183,6 +186,16 @@ export declare class HelixHeadlessTree extends HelixHeadlessTree_base {
183
186
  /** Whether many items can be checked. */
184
187
  private get multiple();
185
188
  private watcher;
189
+ /** The item that last had focus, so its removal can hand focus on. */
190
+ private focused;
191
+ private readonly handleFocusIn;
192
+ /**
193
+ * Puts focus back in the tree where the item that had it was removed and
194
+ * focus fell to the page: on the item after it among its siblings, or the
195
+ * one before, or its parent. Read from the removal itself, which knows where
196
+ * the item stood.
197
+ */
198
+ private refocus;
186
199
  /**
187
200
  * Every item, in the order a reader moving down would meet them.
188
201
  *
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { AriaForwardController, closestInstance, commaList, customElement, HelixElement, inlineStep, keyClaimed, MixinCollection, MixinControllerActive, ReorderController, scrollItemIntoView, selectsAll, slottedWords, Typeahead, treeArrow, typesCharacter, whenHydrated, words, } from '@fusion.dev/helix-core';
7
+ import { AriaForwardController, closestInstance, commaList, customElement, deepActiveElement, HelixElement, inlineStep, keyClaimed, MixinCollection, MixinControllerActive, ReorderController, scrollItemIntoView, selectsAll, slottedWords, Typeahead, treeArrow, typesCharacter, whenHydrated, words, } from '@fusion.dev/helix-core';
8
8
  import { html, nothing } from 'lit';
9
9
  import { property } from 'lit/decorators.js';
10
10
  import { fromGrip } from '../grip.js';
@@ -52,6 +52,11 @@ let HelixHeadlessTree = class HelixHeadlessTree extends MixinCollection(MixinCon
52
52
  });
53
53
  this.pickedUpLabel = 'Picked up {name}';
54
54
  this.reorderable = false;
55
+ this.handleFocusIn = (event) => {
56
+ this.focused = event
57
+ .composedPath()
58
+ .find((node) => node instanceof HelixHeadlessTreeItem);
59
+ };
55
60
  this.handleSelection = (event) => {
56
61
  const origin = event.target;
57
62
  if (!(origin instanceof HelixHeadlessTreeItem) || !this.items.includes(origin)) {
@@ -162,6 +167,36 @@ let HelixHeadlessTree = class HelixHeadlessTree extends MixinCollection(MixinCon
162
167
  get multiple() {
163
168
  return this.selectionMode === 'multiple';
164
169
  }
170
+ refocus(records) {
171
+ const gone = this.focused;
172
+ if (!gone || this.items.includes(gone)) {
173
+ return;
174
+ }
175
+ this.focused = undefined;
176
+ const active = deepActiveElement();
177
+ if (active !== null && active !== document.body) {
178
+ return;
179
+ }
180
+ const record = records.find((one) => [...one.removedNodes].some((node) => node === gone || node.contains(gone)));
181
+ const near = (from, forward) => {
182
+ let node = from ?? null;
183
+ while (node) {
184
+ if (node instanceof HelixHeadlessTreeItem && !node.disabled && node.isConnected) {
185
+ return node;
186
+ }
187
+ node = forward ? node.nextSibling : node.previousSibling;
188
+ }
189
+ return undefined;
190
+ };
191
+ const parent = record ? closestInstance(record.target, HelixHeadlessTreeItem) : null;
192
+ const next = near(record?.nextSibling, true) ??
193
+ near(record?.previousSibling, false) ??
194
+ (parent instanceof HelixHeadlessTreeItem && this.items.includes(parent)
195
+ ? parent
196
+ : undefined) ??
197
+ this.visibleItems.find((item) => !item.disabled);
198
+ this.focusOn(next);
199
+ }
165
200
  get items() {
166
201
  return [...this.querySelectorAll('*')].filter((node) => node instanceof HelixHeadlessTreeItem);
167
202
  }
@@ -305,7 +340,11 @@ let HelixHeadlessTree = class HelixHeadlessTree extends MixinCollection(MixinCon
305
340
  this.addEventListener('helix-select', this.handleSelection);
306
341
  this.addEventListener('toggle', this.handleBranch, true);
307
342
  this.addEventListener('keydown', this.handleKeydown);
308
- this.watcher = new MutationObserver(() => this.syncItems());
343
+ this.addEventListener('focusin', this.handleFocusIn);
344
+ this.watcher = new MutationObserver((records) => {
345
+ this.syncItems();
346
+ this.refocus(records);
347
+ });
309
348
  this.watcher.observe(this, { childList: true, subtree: true });
310
349
  }
311
350
  disconnectedCallback() {
@@ -313,6 +352,7 @@ let HelixHeadlessTree = class HelixHeadlessTree extends MixinCollection(MixinCon
313
352
  this.removeEventListener('helix-select', this.handleSelection);
314
353
  this.removeEventListener('toggle', this.handleBranch, true);
315
354
  this.removeEventListener('keydown', this.handleKeydown);
355
+ this.removeEventListener('focusin', this.handleFocusIn);
316
356
  this.watcher?.disconnect();
317
357
  this.watcher = undefined;
318
358
  }