@mortenbrudvik/waveui 0.11.0 → 0.12.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 (116) hide show
  1. package/README.md +97 -2
  2. package/dist/components/button/Link.cjs +1 -1
  3. package/dist/components/button/Link.cjs.map +1 -1
  4. package/dist/components/button/Link.mjs +4 -4
  5. package/dist/components/data-display/AvatarGroup.cjs +1 -1
  6. package/dist/components/data-display/AvatarGroup.cjs.map +1 -1
  7. package/dist/components/data-display/AvatarGroup.mjs +10 -10
  8. package/dist/components/data-display/InfoButton.cjs +1 -1
  9. package/dist/components/data-display/InfoButton.cjs.map +1 -1
  10. package/dist/components/data-display/InfoButton.mjs +12 -12
  11. package/dist/components/feedback/Toaster.cjs +1 -1
  12. package/dist/components/feedback/Toaster.cjs.map +1 -1
  13. package/dist/components/feedback/Toaster.mjs +235 -235
  14. package/dist/components/feedback/Toaster.mjs.map +1 -1
  15. package/dist/components/input/Combobox.cjs +1 -1
  16. package/dist/components/input/Combobox.cjs.map +1 -1
  17. package/dist/components/input/Combobox.mjs +176 -175
  18. package/dist/components/input/Combobox.mjs.map +1 -1
  19. package/dist/components/input/DatePicker.cjs +1 -1
  20. package/dist/components/input/DatePicker.cjs.map +1 -1
  21. package/dist/components/input/DatePicker.mjs +188 -187
  22. package/dist/components/input/DatePicker.mjs.map +1 -1
  23. package/dist/components/input/Dropdown.cjs +1 -1
  24. package/dist/components/input/Dropdown.cjs.map +1 -1
  25. package/dist/components/input/Dropdown.mjs +41 -40
  26. package/dist/components/input/Dropdown.mjs.map +1 -1
  27. package/dist/components/input/Option.cjs +1 -1
  28. package/dist/components/input/Option.cjs.map +1 -1
  29. package/dist/components/input/Option.mjs +89 -87
  30. package/dist/components/input/Option.mjs.map +1 -1
  31. package/dist/components/input/TagPicker.root.cjs +1 -1
  32. package/dist/components/input/TagPicker.root.cjs.map +1 -1
  33. package/dist/components/input/TagPicker.root.mjs +136 -135
  34. package/dist/components/input/TagPicker.root.mjs.map +1 -1
  35. package/dist/components/input/TimePicker.cjs +1 -1
  36. package/dist/components/input/TimePicker.cjs.map +1 -1
  37. package/dist/components/input/TimePicker.mjs +156 -154
  38. package/dist/components/input/TimePicker.mjs.map +1 -1
  39. package/dist/components/navigation/Menu.popover.cjs +1 -1
  40. package/dist/components/navigation/Menu.popover.cjs.map +1 -1
  41. package/dist/components/navigation/Menu.popover.mjs +137 -127
  42. package/dist/components/navigation/Menu.popover.mjs.map +1 -1
  43. package/dist/components/navigation/Menu.root.cjs +1 -1
  44. package/dist/components/navigation/Menu.root.cjs.map +1 -1
  45. package/dist/components/navigation/Menu.root.mjs +4 -4
  46. package/dist/components/overlays/Dialog.cjs +1 -1
  47. package/dist/components/overlays/Dialog.cjs.map +1 -1
  48. package/dist/components/overlays/Dialog.mjs +123 -123
  49. package/dist/components/overlays/Dialog.mjs.map +1 -1
  50. package/dist/components/overlays/Drawer.panel.cjs +1 -1
  51. package/dist/components/overlays/Drawer.panel.cjs.map +1 -1
  52. package/dist/components/overlays/Drawer.panel.mjs +12 -12
  53. package/dist/components/overlays/Drawer.panel.mjs.map +1 -1
  54. package/dist/components/overlays/Popover.cjs +1 -1
  55. package/dist/components/overlays/Popover.cjs.map +1 -1
  56. package/dist/components/overlays/Popover.mjs +173 -162
  57. package/dist/components/overlays/Popover.mjs.map +1 -1
  58. package/dist/components/overlays/TeachingPopover.cjs +1 -1
  59. package/dist/components/overlays/TeachingPopover.cjs.map +1 -1
  60. package/dist/components/overlays/TeachingPopover.mjs +96 -91
  61. package/dist/components/overlays/TeachingPopover.mjs.map +1 -1
  62. package/dist/components/overlays/Tooltip.cjs +1 -1
  63. package/dist/components/overlays/Tooltip.cjs.map +1 -1
  64. package/dist/components/overlays/Tooltip.mjs +47 -47
  65. package/dist/components/overlays/Tooltip.mjs.map +1 -1
  66. package/dist/components/portal/Portal.cjs +1 -1
  67. package/dist/components/portal/Portal.cjs.map +1 -1
  68. package/dist/components/portal/Portal.mjs +5 -5
  69. package/dist/components/table/DataGrid.cjs +1 -1
  70. package/dist/components/table/DataGrid.cjs.map +1 -1
  71. package/dist/components/table/DataGrid.mjs +1 -1
  72. package/dist/hooks/useDismiss.cjs.map +1 -1
  73. package/dist/hooks/useDismiss.mjs.map +1 -1
  74. package/dist/hooks/useFocusTrap.cjs.map +1 -1
  75. package/dist/hooks/useFocusTrap.mjs.map +1 -1
  76. package/dist/hooks/useFocusVisible.cjs +2 -0
  77. package/dist/hooks/useFocusVisible.cjs.map +1 -0
  78. package/dist/hooks/useFocusVisible.mjs +49 -0
  79. package/dist/hooks/useFocusVisible.mjs.map +1 -0
  80. package/dist/hooks/useFocusableGroup.cjs +2 -0
  81. package/dist/hooks/useFocusableGroup.cjs.map +1 -0
  82. package/dist/hooks/useFocusableGroup.mjs +70 -0
  83. package/dist/hooks/useFocusableGroup.mjs.map +1 -0
  84. package/dist/hooks/useModalLayer.cjs +1 -1
  85. package/dist/hooks/useModalLayer.cjs.map +1 -1
  86. package/dist/hooks/useModalLayer.mjs +4 -4
  87. package/dist/hooks/useModalOpen.cjs +2 -0
  88. package/dist/hooks/useModalOpen.cjs.map +1 -0
  89. package/dist/hooks/useModalOpen.mjs +14 -0
  90. package/dist/hooks/useModalOpen.mjs.map +1 -0
  91. package/dist/hooks/usePopupPosition.cjs +1 -1
  92. package/dist/hooks/usePopupPosition.cjs.map +1 -1
  93. package/dist/hooks/usePopupPosition.mjs +82 -53
  94. package/dist/hooks/usePopupPosition.mjs.map +1 -1
  95. package/dist/hooks/useResolvedTarget.cjs +2 -0
  96. package/dist/hooks/useResolvedTarget.cjs.map +1 -0
  97. package/dist/hooks/useResolvedTarget.mjs +37 -0
  98. package/dist/hooks/useResolvedTarget.mjs.map +1 -0
  99. package/dist/hooks/useRovingGrid.cjs +1 -1
  100. package/dist/hooks/useRovingGrid.cjs.map +1 -1
  101. package/dist/hooks/useRovingGrid.mjs +8 -57
  102. package/dist/hooks/useRovingGrid.mjs.map +1 -1
  103. package/dist/hooks/useRovingTabIndex.cjs +1 -1
  104. package/dist/hooks/useRovingTabIndex.cjs.map +1 -1
  105. package/dist/hooks/useRovingTabIndex.mjs +142 -107
  106. package/dist/hooks/useRovingTabIndex.mjs.map +1 -1
  107. package/dist/index.cjs +1 -1
  108. package/dist/index.d.cts +814 -18
  109. package/dist/index.d.ts +814 -18
  110. package/dist/index.mjs +120 -108
  111. package/dist/lib/layers.cjs +1 -1
  112. package/dist/lib/layers.cjs.map +1 -1
  113. package/dist/lib/layers.mjs +112 -109
  114. package/dist/lib/layers.mjs.map +1 -1
  115. package/dist/styles.css +1 -1
  116. package/package.json +1 -1
@@ -7,7 +7,37 @@ import { getFirstTabbable as o, isHiddenInput as s } from "../lib/focus.mjs";
7
7
  import { isAltGraphCharacter as c, useTypeahead as l } from "./useTypeahead.mjs";
8
8
  import * as u from "react";
9
9
  //#region src/hooks/useRovingTabIndex.ts
10
- var d = "[data-roving-value]", f = /* @__PURE__ */ new Set([
10
+ function d(e, t, n) {
11
+ let r = t.querySelectorAll("[role=\"row\"]");
12
+ if (r.length > 0) return Array.from(r).map((t) => e.filter((e) => t.contains(e.element)));
13
+ if (n !== void 0 && n > 0) {
14
+ let t = [];
15
+ for (let r = 0; r < e.length; r += n) t.push(e.slice(r, r + n));
16
+ return t;
17
+ }
18
+ return null;
19
+ }
20
+ function f(e, t, n) {
21
+ let r = e.key === "ArrowUp" || e.key === "ArrowDown", i = e.key === "Home" || e.key === "End";
22
+ if (!n || !r && !i) return;
23
+ let a = t.findIndex((e) => e.includes(n));
24
+ if (a < 0) return;
25
+ if (i) {
26
+ let r = (e.ctrlKey ? t.flat() : t[a]).filter((e) => !e.disabled), i = e.key === "Home" ? r[0] : r[r.length - 1];
27
+ return i && i !== n ? [i] : "stay";
28
+ }
29
+ let o = t[a].indexOf(n), s = e.key === "ArrowDown" ? 1 : -1;
30
+ for (let e = a + s; e >= 0 && e < t.length; e += s) {
31
+ let n, r = Infinity;
32
+ if (t[e].forEach((e, t) => {
33
+ if (e.disabled) return;
34
+ let i = Math.abs(t - o);
35
+ i < r && (n = e, r = i);
36
+ }), n) return [n];
37
+ }
38
+ return "stay";
39
+ }
40
+ var p = "[data-roving-value]", m = /* @__PURE__ */ new Set([
11
41
  "radiogroup",
12
42
  "listbox",
13
43
  "grid",
@@ -17,12 +47,12 @@ var d = "[data-roving-value]", f = /* @__PURE__ */ new Set([
17
47
  "menubar",
18
48
  "tree",
19
49
  "spinbutton"
20
- ]), p = /* @__PURE__ */ new Set([
50
+ ]), h = /* @__PURE__ */ new Set([
21
51
  "slider",
22
52
  "spinbutton",
23
53
  "textbox",
24
54
  "searchbox"
25
- ]), m = /* @__PURE__ */ new Set([
55
+ ]), g = /* @__PURE__ */ new Set([
26
56
  "button",
27
57
  "checkbox",
28
58
  "color",
@@ -32,7 +62,7 @@ var d = "[data-roving-value]", f = /* @__PURE__ */ new Set([
32
62
  "radio",
33
63
  "reset",
34
64
  "submit"
35
- ]), h = [
65
+ ]), _ = [
36
66
  "disabled",
37
67
  "aria-disabled",
38
68
  "data-disabled-focusable",
@@ -47,47 +77,47 @@ var d = "[data-roving-value]", f = /* @__PURE__ */ new Set([
47
77
  "type",
48
78
  "contenteditable"
49
79
  ];
50
- function g(e, t) {
80
+ function v(e, t) {
51
81
  if (e.hasAttribute("data-roving-container")) return !0;
52
82
  if (!t || e.hasAttribute("data-roving-transparent")) return !1;
53
83
  let n = e.getAttribute("role");
54
- return n !== null && f.has(n);
84
+ return n !== null && m.has(n);
55
85
  }
56
- function _(e, t, n) {
57
- for (let r = e; r && r !== t; r = r.parentElement) if (g(r, n)) return !0;
86
+ function y(e, t, n) {
87
+ for (let r = e; r && r !== t; r = r.parentElement) if (v(r, n)) return !0;
58
88
  return !1;
59
89
  }
60
- var v = "[tabindex], [data-roving-value]";
61
- function y(e, t) {
90
+ var b = "[tabindex], [data-roving-value]";
91
+ function x(e, t) {
62
92
  try {
63
93
  return e.matches(t);
64
94
  } catch {
65
95
  return !1;
66
96
  }
67
97
  }
68
- function b(e) {
98
+ function S(e) {
69
99
  let t = /* @__PURE__ */ new Map();
70
100
  for (let n of e) n.type === "attributes" && n.attributeName === "tabindex" && t.set(n.target, n);
71
101
  let n = /* @__PURE__ */ new Set();
72
102
  for (let [e, r] of t) r.oldValue === e.getAttribute("tabindex") && n.add(e);
73
103
  return n;
74
104
  }
75
- function x(e) {
105
+ function C(e) {
76
106
  return e.tabIndex >= 0 && !e.hasAttribute("disabled");
77
107
  }
78
- function S(e) {
108
+ function w(e) {
79
109
  let { element: t } = e;
80
- if (!e.nested || x(t)) return t;
110
+ if (!e.nested || C(t)) return t;
81
111
  let n = t.querySelector("[tabindex=\"0\"]");
82
112
  if (n) return n;
83
113
  let r = o(t);
84
114
  return r instanceof HTMLElement ? r : null;
85
115
  }
86
- function C(e) {
116
+ function T(e) {
87
117
  let t = e.getAttribute("data-roving-disabled");
88
- return t !== null && t !== "false" || w(e) ? !0 : !e.hasAttribute("data-disabled-focusable") && e.getAttribute("aria-disabled") === "true";
118
+ return t !== null && t !== "false" || E(e) ? !0 : !e.hasAttribute("data-disabled-focusable") && e.getAttribute("aria-disabled") === "true";
89
119
  }
90
- function w(e) {
120
+ function E(e) {
91
121
  if (e.disabled === !0) return !0;
92
122
  try {
93
123
  return e.matches(":disabled");
@@ -95,20 +125,20 @@ function w(e) {
95
125
  return !1;
96
126
  }
97
127
  }
98
- function T(e) {
128
+ function D(e) {
99
129
  if (!e || e.nodeType !== 1) return !1;
100
130
  let t = e, n = t.getAttribute("role");
101
- if (n !== null && p.has(n)) return !0;
131
+ if (n !== null && h.has(n)) return !0;
102
132
  let r = t.localName;
103
133
  if (r === "textarea" || r === "select") return !0;
104
- if (r === "input") return !m.has(t.type);
134
+ if (r === "input") return !g.has(t.type);
105
135
  let i = t.closest("[contenteditable]");
106
136
  return i !== null && i.getAttribute("contenteditable") !== "false";
107
137
  }
108
- function E(e) {
109
- return !e.nested && !T(e.element);
138
+ function O(e) {
139
+ return !e.nested && !D(e.element);
110
140
  }
111
- function D(e, t, n) {
141
+ function k(e, t, n) {
112
142
  let r = e.ownerDocument.defaultView;
113
143
  if (!r) return !1;
114
144
  for (let i = e; i && i !== t; i = i.parentElement) {
@@ -133,14 +163,14 @@ function te(e) {
133
163
  return !1;
134
164
  }
135
165
  }
136
- function O(e) {
137
- return [e.value, e.disabled ? 0 : E(e) ? 1 : 2];
166
+ function A(e) {
167
+ return [e.value, e.disabled ? 0 : O(e) ? 1 : 2];
138
168
  }
139
- function k(e, t, n, r) {
169
+ function j(e, t, n, r) {
140
170
  let i = e.some(([, e]) => e === 1) ? 1 : 2, a = e.filter(([, e]) => e === i).map(([e]) => e);
141
171
  return n === "last-focused" && r !== null && a.includes(r) ? r : t !== null && t !== "" && a.includes(t) ? t : a[0] ?? null;
142
172
  }
143
- function A(e, t) {
173
+ function M(e, t) {
144
174
  if (!t) return e;
145
175
  let n = new Map(e.map((e) => [e.value, e])), r = [];
146
176
  for (let e of t) {
@@ -149,11 +179,11 @@ function A(e, t) {
149
179
  }
150
180
  return r;
151
181
  }
152
- var j = class {
182
+ var N = class {
153
183
  container = null;
154
184
  lastFocused = null;
155
185
  options = {
156
- itemSelector: d,
186
+ itemSelector: p,
157
187
  manageTabIndex: !1,
158
188
  items: void 0,
159
189
  activeValue: null,
@@ -170,7 +200,7 @@ var j = class {
170
200
  subscribe = (e) => (this.notify = e, this.observe(), () => {
171
201
  this.notify = null, this.disconnect();
172
202
  });
173
- getSnapshot = () => this.container ? (this.dirty && (this.dirty = !1, this.snapshot = JSON.stringify(this.resolveOwn().map(O))), this.snapshot) : "";
203
+ getSnapshot = () => this.container ? (this.dirty && (this.dirty = !1, this.snapshot = JSON.stringify(this.resolveOwn().map(A))), this.snapshot) : "";
174
204
  getServerSnapshot = () => "";
175
205
  setContainer(e) {
176
206
  if (e === this.container) return;
@@ -178,14 +208,14 @@ var j = class {
178
208
  this.disconnect(), this.container && this.options.manageTabIndex && this.release(this.container, "all", t), this.container = e, this.dirty = !0, this.notify && (this.observe(), this.notify());
179
209
  }
180
210
  recordFocus(e) {
181
- E(e) && (this.lastFocused = e.value);
211
+ O(e) && (this.lastFocused = e.value);
182
212
  }
183
213
  setOptions(e) {
184
214
  let t = this.options;
185
215
  this.options = e, t.manageTabIndex && !e.manageTabIndex && this.container && this.release(this.container, "all", this.takeRecords()), (t.itemSelector !== e.itemSelector || t.manageTabIndex !== e.manageTabIndex || t.roleComposites !== e.roleComposites) && (this.dirty = !0, this.notify?.());
186
216
  }
187
217
  resolve(e = this.container) {
188
- return A(this.resolveOwn(e), this.options.items);
218
+ return M(this.resolveOwn(e), this.options.items);
189
219
  }
190
220
  resolveOwn(e = this.container) {
191
221
  if (!e) return [];
@@ -198,7 +228,7 @@ var j = class {
198
228
  let a = [], o = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Map();
199
229
  for (let t of i) {
200
230
  let i = null, l = !1;
201
- for (let n = t; n && n !== e; n = n.parentElement) g(n, r) && (i = n), (n.hidden || n.hasAttribute("inert")) && (l = !0);
231
+ for (let n = t; n && n !== e; n = n.parentElement) v(n, r) && (i = n), (n.hidden || n.hasAttribute("inert")) && (l = !0);
202
232
  if (l) continue;
203
233
  let u = i ?? t;
204
234
  if (o.has(u)) continue;
@@ -209,16 +239,16 @@ var j = class {
209
239
  value: this.valueOf(u, d),
210
240
  element: u,
211
241
  nested: d,
212
- disabled: C(u)
242
+ disabled: T(u)
213
243
  };
214
- d && !f.disabled && !S(f) && (f.disabled = !0), n && !f.disabled && D(u, e, c) && (f.disabled = !0), a.push(f);
244
+ d && !f.disabled && !w(f) && (f.disabled = !0), n && !f.disabled && k(u, e, c) && (f.disabled = !0), a.push(f);
215
245
  }
216
246
  return a;
217
247
  }
218
248
  stamp() {
219
249
  if (!this.options.manageTabIndex || !this.container) return;
220
250
  this.release(this.container, "stale");
221
- let e = this.resolve(), t = this.options.tabStop === "none" ? null : k(e.map(O), this.options.activeValue, this.options.tabStop, this.lastFocused);
251
+ let e = this.resolve(), t = this.options.tabStop === "none" ? null : j(e.map(A), this.options.activeValue, this.options.tabStop, this.lastFocused);
222
252
  for (let n of e) {
223
253
  if (n.nested) continue;
224
254
  let { element: e } = n, r = n.value === t ? "0" : "-1", i = e.getAttribute("tabindex"), a = this.stamped.get(e);
@@ -230,17 +260,17 @@ var j = class {
230
260
  }
231
261
  }
232
262
  release(e, t, n = []) {
233
- let r = b(n), { itemSelector: i, roleComposites: a } = this.options;
234
- for (let n of Array.from(e.querySelectorAll(v))) {
263
+ let r = S(n), { itemSelector: i, roleComposites: a } = this.options;
264
+ for (let n of Array.from(e.querySelectorAll(b))) {
235
265
  let o = this.stamped.get(n);
236
- if (!o || t === "stale" && y(n, i) && !_(n, e, a)) continue;
266
+ if (!o || t === "stale" && x(n, i) && !y(n, e, a)) continue;
237
267
  this.stamped.delete(n);
238
268
  let s = n.getAttribute("tabindex");
239
269
  !(s !== o.stamped || r.has(n)) && s !== o.tabIndex && (o.tabIndex === null ? n.removeAttribute("tabindex") : n.setAttribute("tabindex", o.tabIndex)), o.addedValue !== null && n.getAttribute("data-roving-value") === o.addedValue && n.removeAttribute("data-roving-value");
240
270
  }
241
271
  }
242
272
  adopt(e) {
243
- for (let t of b(e)) {
273
+ for (let t of S(e)) {
244
274
  let e = this.stamped.get(t);
245
275
  e && (e.tabIndex = t.getAttribute("tabindex"));
246
276
  }
@@ -262,14 +292,14 @@ var j = class {
262
292
  childList: !0,
263
293
  attributes: !0,
264
294
  attributeOldValue: !0,
265
- attributeFilter: h
295
+ attributeFilter: _
266
296
  }), this.dirty = !0);
267
297
  }
268
298
  disconnect() {
269
299
  this.observer?.disconnect(), this.observer = null;
270
300
  }
271
301
  };
272
- function M(e) {
302
+ function P(e) {
273
303
  if (e === "") return null;
274
304
  try {
275
305
  return JSON.parse(e);
@@ -277,13 +307,13 @@ function M(e) {
277
307
  return null;
278
308
  }
279
309
  }
280
- function N(e) {
310
+ function F(e) {
281
311
  return e.getAttribute("data-roving-text") ?? e.textContent ?? "";
282
312
  }
283
- function P(e, t) {
313
+ function I(e, t) {
284
314
  return !t || typeof t.nodeType != "number" ? !1 : t === e || e.contains(t);
285
315
  }
286
- function F(e, t, n) {
316
+ function L(e, t, n) {
287
317
  if (e.length === 0 || !t || typeof t.nodeType != "number") return null;
288
318
  let r = new Map(e.map((e) => [e.element, e]));
289
319
  for (let e = t; e && e !== n; e = e.parentNode) {
@@ -292,97 +322,102 @@ function F(e, t, n) {
292
322
  }
293
323
  return null;
294
324
  }
295
- function I(e, t, n) {
296
- return e ? t === S(e) : t === n;
325
+ function R(e, t, n) {
326
+ return e ? t === w(e) : t === n;
297
327
  }
298
- function L(o, s) {
299
- let f = s === void 0 ? void 0 : o, { activeValue: p = null, items: m, orientation: h = "horizontal", loop: g = !0, dir: _, itemSelector: v = d, typeahead: y = !1, homeEndKeys: b = !0, tabStop: x = "active", manageTabIndex: C = !1, onFocusMove: w } = s ?? o, [D] = u.useState(() => new j()), O = u.useSyncExternalStore(D.subscribe, D.getSnapshot, D.getServerSnapshot), [A, L] = u.useState(null), [R, z] = u.useState(null), B = f === void 0 && m === void 0;
328
+ function z(o, s) {
329
+ let m = s === void 0 ? void 0 : o, { activeValue: h = null, items: g, orientation: _ = "horizontal", columns: v, loop: y = !0, dir: b, itemSelector: x = p, typeahead: S = !1, homeEndKeys: C = !0, tabStop: T = "active", manageTabIndex: E = !1, onFocusMove: k } = s ?? o, [A] = u.useState(() => new N()), M = u.useSyncExternalStore(A.subscribe, A.getSnapshot, A.getServerSnapshot), [z, B] = u.useState(null), [V, ne] = u.useState(null), re = m === void 0 && g === void 0;
300
330
  u.useLayoutEffect(() => {
301
- D.setOptions({
302
- itemSelector: v,
303
- manageTabIndex: C,
304
- items: m,
305
- activeValue: p,
306
- tabStop: x,
307
- roleComposites: B
308
- }), f && D.setContainer(f.current), D.stamp();
331
+ A.setOptions({
332
+ itemSelector: x,
333
+ manageTabIndex: E,
334
+ items: g,
335
+ activeValue: h,
336
+ tabStop: T,
337
+ roleComposites: re
338
+ }), m && A.setContainer(m.current), A.stamp();
309
339
  }), u.useEffect(() => {
310
- e && !te(v) && t(`useRovingTabIndex:itemSelector:${v}`, `useRovingTabIndex: itemSelector "${v}" is not a valid CSS selector in this browser; no item is navigable or tabbable.`);
311
- }, [v]);
312
- let V = u.useMemo(() => M(O), [O]), H = u.useMemo(() => {
313
- if (!m) return V;
314
- if (V) {
315
- let e = new Map(V), t = m.flatMap((t) => {
340
+ e && !te(x) && t(`useRovingTabIndex:itemSelector:${x}`, `useRovingTabIndex: itemSelector "${x}" is not a valid CSS selector in this browser; no item is navigable or tabbable.`);
341
+ }, [x]), u.useEffect(() => {
342
+ if (!e || _ !== "grid" || v) return;
343
+ let n = A.container;
344
+ n && n.querySelector("[role=\"row\"]") === null && t("useRovingTabIndex:grid-rows", "useRovingTabIndex: orientation \"grid\" needs role=\"row\" elements around the items or a `columns` count; without either it acts as \"both\".");
345
+ });
346
+ let H = u.useMemo(() => P(M), [M]), U = u.useMemo(() => {
347
+ if (!g) return H;
348
+ if (H) {
349
+ let e = new Map(H), t = g.flatMap((t) => {
316
350
  let n = e.get(t);
317
351
  return n === void 0 ? [] : [[t, n]];
318
352
  });
319
353
  if (t.length > 0) return t;
320
354
  }
321
- return m.map((e) => [e, 1]);
322
- }, [m, V]), U = x === "none" ? null : H ? k(H, p, x, R) : p || null, W = u.useCallback((e) => e === U ? 0 : -1, [U]), G = u.useCallback((e) => {
323
- D.setContainer(e), f && n(f, e);
324
- }, [D, f]), K = u.useRef([]), q = u.useRef([]), { onTypeahead: ne, isSearching: re } = l({
355
+ return g.map((e) => [e, 1]);
356
+ }, [g, H]), W = T === "none" ? null : U ? j(U, h, T, V) : h || null, ie = u.useCallback((e) => e === W ? 0 : -1, [W]), G = u.useCallback((e) => {
357
+ A.setContainer(e), m && n(m, e);
358
+ }, [A, m]), K = u.useRef([]), q = u.useRef([]), { onTypeahead: ae, isSearching: oe } = l({
325
359
  getItems: () => K.current,
326
360
  onMatch: (e, t) => {
327
361
  q.current = t;
328
362
  }
329
363
  }), J = (e) => {
330
364
  if (!e || e.disabled) return !1;
331
- let t = S(e);
332
- return !t || (t.focus(), !ee(t)) ? !1 : (D.recordFocus(e), !0);
365
+ let t = w(e);
366
+ return !t || (t.focus(), !ee(t)) ? !1 : (A.recordFocus(e), !0);
333
367
  }, Y = (e) => {
334
368
  for (let t of e) if (J(t)) return;
335
369
  }, X = r((e, t) => {
336
- let n = e.metaKey || (e.altKey || e.ctrlKey) && !c(e);
337
- if (e.defaultPrevented || n || T(e.target)) return;
338
- let r = D.container ?? e.currentTarget;
339
- if (!P(r, e.target)) return;
340
- let o = D.resolve(r), s = o.filter((e) => !e.disabled);
341
- if (s.length === 0) return;
342
- let l = F(o, e.target, r), u = !1, d = [], f = t ? null : i(e.key, {
343
- orientation: h,
344
- dir: _ ?? a(e.currentTarget)
370
+ let n = _ === "grid" && e.ctrlKey && !e.altKey && (e.key === "Home" || e.key === "End"), r = e.metaKey || (e.altKey || e.ctrlKey) && !c(e) && !n;
371
+ if (e.defaultPrevented || r || D(e.target)) return;
372
+ let o = A.container ?? e.currentTarget;
373
+ if (!I(o, e.target)) return;
374
+ let s = A.resolve(o), l = s.filter((e) => !e.disabled);
375
+ if (l.length === 0) return;
376
+ let u = L(s, e.target, o), p = !1, m = [], h = _ === "grid" && !t ? d(s, o, v) : null, g = h ? f(e, h, u) : void 0, x = t || g ? null : i(e.key, {
377
+ orientation: _ === "grid" ? h ? "horizontal" : "both" : _,
378
+ dir: b ?? a(e.currentTarget)
345
379
  });
346
- if (f) {
347
- if (u = !0, !l) d = f === "next" ? s : [...s].reverse();
380
+ if (g) p = !0, m = g === "stay" ? [] : g;
381
+ else if (x) {
382
+ if (p = !0, !u) m = x === "next" ? l : [...l].reverse();
348
383
  else {
349
- let e = f === "next" ? 1 : -1, t = o.length, n = o.indexOf(l);
384
+ let e = x === "next" ? 1 : -1, t = s.length, n = s.indexOf(u);
350
385
  for (let r = 1; r < t; r++) {
351
386
  if (n += e, n < 0 || n >= t) {
352
- if (!g) break;
387
+ if (!y) break;
353
388
  n = (n + t) % t;
354
389
  }
355
- o[n].disabled || d.push(o[n]);
390
+ s[n].disabled || m.push(s[n]);
356
391
  }
357
392
  }
358
- } else !t && b && (e.key === "Home" || e.key === "End") ? (u = !0, d = e.key === "Home" ? s : [...s].reverse()) : y && I(l, e.target, r) && (K.current = o.map((e) => ({
393
+ } else !t && C && (e.key === "Home" || e.key === "End") ? (p = !0, m = e.key === "Home" ? l : [...l].reverse()) : S && R(u, e.target, o) && (K.current = s.map((e) => ({
359
394
  value: e.value,
360
- text: N(e.element),
395
+ text: F(e.element),
361
396
  disabled: e.disabled
362
- })), q.current = [], ne(e, l?.value ?? null) && (u = !0, d = q.current.flatMap((e) => s.filter((t) => t.value === e))));
363
- if (u) {
397
+ })), q.current = [], ae(e, u?.value ?? null) && (p = !0, m = q.current.flatMap((e) => l.filter((t) => t.value === e))));
398
+ if (p) {
364
399
  e.preventDefault();
365
- for (let t of d) {
366
- if (t === l) return;
400
+ for (let t of m) {
401
+ if (t === u) return;
367
402
  if (J(t)) {
368
- w?.(t.value, e);
403
+ k?.(t.value, e);
369
404
  return;
370
405
  }
371
406
  }
372
407
  }
373
408
  }), Z = r((e) => X(e, !1)), Q = r((e) => {
374
- y && e.key === " " && re() && X(e, !0);
409
+ S && e.key === " " && oe() && X(e, !0);
375
410
  }), $ = r((e) => {
376
- let t = D.container ?? e.currentTarget;
377
- if (!P(t, e.target)) return;
378
- let n = F(D.resolve(t), e.target, t);
379
- n && (D.recordFocus(n), L(n.value), E(n) && z(n.value), D.stamp());
380
- }), ie = r((e) => {
381
- J(D.resolve().find((t) => t.value === e));
382
- }), ae = r(() => {
383
- Y(D.resolve().filter((e) => !e.disabled));
384
- }), oe = r(() => {
385
- Y(D.resolve().filter((e) => !e.disabled).reverse());
411
+ let t = A.container ?? e.currentTarget;
412
+ if (!I(t, e.target)) return;
413
+ let n = L(A.resolve(t), e.target, t);
414
+ n && (A.recordFocus(n), B(n.value), O(n) && ne(n.value), A.stamp());
415
+ }), se = r((e) => {
416
+ J(A.resolve().find((t) => t.value === e));
417
+ }), ce = r(() => {
418
+ Y(A.resolve().filter((e) => !e.disabled));
419
+ }), le = r(() => {
420
+ Y(A.resolve().filter((e) => !e.disabled).reverse());
386
421
  });
387
422
  return {
388
423
  containerProps: u.useMemo(() => ({
@@ -400,14 +435,14 @@ function L(o, s) {
400
435
  handleKeyDown: Z,
401
436
  handleKeyDownCapture: Q,
402
437
  handleFocus: $,
403
- getTabIndex: W,
404
- focusedValue: A,
405
- focusValue: ie,
406
- focusFirst: ae,
407
- focusLast: oe
438
+ getTabIndex: ie,
439
+ focusedValue: z,
440
+ focusValue: se,
441
+ focusFirst: ce,
442
+ focusLast: le
408
443
  };
409
444
  }
410
445
  //#endregion
411
- export { D as isHiddenByCss, L as useRovingTabIndex };
446
+ export { k as isHiddenByCss, z as useRovingTabIndex };
412
447
 
413
448
  //# sourceMappingURL=useRovingTabIndex.mjs.map