@altinn/altinn-components 0.56.20 → 0.56.22

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 (77) hide show
  1. package/dist/assets/AccountSelector.css +1 -1
  2. package/dist/assets/AccountSelectorButton.css +1 -0
  3. package/dist/assets/DatepickerFilter.css +1 -1
  4. package/dist/assets/Dropdown.css +1 -1
  5. package/dist/assets/GlobalHeader.css +1 -1
  6. package/dist/assets/GlobalMenuButton2.css +1 -1
  7. package/dist/assets/HeaderLogo2.css +1 -1
  8. package/dist/assets/LayoutGrid.css +1 -1
  9. package/dist/assets/ModalBase.css +1 -1
  10. package/dist/assets/ModalFooter.css +1 -0
  11. package/dist/assets/SettingsSection.css +1 -1
  12. package/dist/components/Account/AccountMenu.js +20 -20
  13. package/dist/components/Bookmarks/BookmarkSettingsList.js +41 -11
  14. package/dist/components/Dropdown/Dropdown.js +10 -10
  15. package/dist/components/DsComponents/index.js +20 -21
  16. package/dist/components/GlobalHeader/AccountSelector.js +64 -124
  17. package/dist/components/GlobalHeader/AccountSelectorButton.js +127 -0
  18. package/dist/components/GlobalHeader/DigdirLogomark.js +23 -109
  19. package/dist/components/GlobalHeader/GlobalHeader.js +84 -117
  20. package/dist/components/GlobalHeader/GlobalMenuButton.js +64 -0
  21. package/dist/components/GlobalHeader/HeaderLogo.js +20 -13
  22. package/dist/components/GlobalHeader/index.js +2 -2
  23. package/dist/components/GlobalMenu/GlobalMenu.js +11 -10
  24. package/dist/components/GlobalMenu/index.js +2 -4
  25. package/dist/components/Layout/Layout.js +30 -30
  26. package/dist/components/Layout/LayoutGrid.js +3 -3
  27. package/dist/components/Modal/ModalBase.js +35 -33
  28. package/dist/components/Modal/ModalFooter.js +7 -10
  29. package/dist/components/Modal/index.js +8 -6
  30. package/dist/components/Settings/SettingsItem.js +53 -35
  31. package/dist/components/Settings/SettingsItemBase.js +19 -20
  32. package/dist/components/Settings/SettingsSection.js +10 -10
  33. package/dist/components/index.js +89 -88
  34. package/dist/functions/index.js +6 -4
  35. package/dist/functions/orgno/index.js +4 -0
  36. package/dist/functions/orgno/orgno.js +4 -0
  37. package/dist/hooks/useAccountSelector.js +77 -75
  38. package/dist/index.js +88 -85
  39. package/dist/textfield-CNXt-27J.js +3403 -0
  40. package/dist/types/lib/components/Bookmarks/BookmarkSettingsItem.d.ts +2 -0
  41. package/dist/types/lib/components/Bookmarks/BookmarkSettingsList.d.ts +7 -1
  42. package/dist/types/lib/components/Bookmarks/BookmarkSettingsList.stories.d.ts +4 -1
  43. package/dist/types/lib/components/Dropdown/Dropdown.d.ts +1 -1
  44. package/dist/types/lib/components/{Account/AccountMenuButton.d.ts → GlobalHeader/AccountSelectorButton.d.ts} +2 -2
  45. package/dist/types/lib/components/{Account/AccountMenuButton.stories.d.ts → GlobalHeader/AccountSelectorButton.stories.d.ts} +1 -1
  46. package/dist/types/lib/components/GlobalHeader/DigdirLogomark.d.ts +1 -2
  47. package/dist/types/lib/components/GlobalHeader/GlobalHeader.d.ts +1 -3
  48. package/dist/types/lib/components/GlobalHeader/GlobalHeader.stories.d.ts +1 -1
  49. package/dist/types/lib/components/{GlobalMenu → GlobalHeader}/GlobalMenuButton.d.ts +2 -2
  50. package/dist/types/lib/components/{GlobalMenu → GlobalHeader}/GlobalMenuButton.stories.d.ts +1 -1
  51. package/dist/types/lib/components/GlobalHeader/index.d.ts +1 -1
  52. package/dist/types/lib/components/GlobalMenu/index.d.ts +0 -1
  53. package/dist/types/lib/components/Modal/ModalBase.d.ts +2 -1
  54. package/dist/types/lib/components/Modal/ModalFooter.d.ts +3 -3
  55. package/dist/types/lib/components/Modal/index.d.ts +1 -0
  56. package/dist/types/lib/components/Settings/SettingsModal.stories.d.ts +2 -1
  57. package/dist/types/lib/functions/index.d.ts +1 -0
  58. package/dist/types/lib/functions/orgno/index.d.ts +1 -0
  59. package/dist/types/lib/functions/orgno/orgno.d.ts +1 -0
  60. package/package.json +1 -1
  61. package/dist/assets/AccountMenuButton.css +0 -1
  62. package/dist/assets/GlobalHeaderBase.css +0 -1
  63. package/dist/assets/HeaderGroup2.css +0 -1
  64. package/dist/assets/globalSearch.css +0 -1
  65. package/dist/components/Account/AccountMenuButton.js +0 -134
  66. package/dist/components/GlobalHeader/GlobalHeaderBase.js +0 -24
  67. package/dist/components/GlobalHeader/GlobalSearch.js +0 -62
  68. package/dist/components/GlobalHeader/GlobalSearchButton.js +0 -54
  69. package/dist/components/GlobalHeader/HeaderGroup.js +0 -8
  70. package/dist/components/GlobalMenu/GlobalMenuButton.js +0 -83
  71. package/dist/globalSearch.module-DziLSGZg.js +0 -9
  72. package/dist/index--jNxJmA8.js +0 -2000
  73. package/dist/textfield-Drdr9bio.js +0 -1439
  74. package/dist/types/lib/components/GlobalHeader/GlobalHeaderBase.d.ts +0 -9
  75. package/dist/types/lib/components/GlobalHeader/GlobalSearch.d.ts +0 -4
  76. package/dist/types/lib/components/GlobalHeader/GlobalSearchButton.d.ts +0 -6
  77. package/dist/types/lib/components/GlobalHeader/HeaderGroup.d.ts +0 -6
@@ -1,2000 +0,0 @@
1
- "use client";
2
- import { jsx as Ee } from "react/jsx-runtime";
3
- import { c as zt } from "./lite-1fxw3LjI.js";
4
- import * as c from "react";
5
- import { useLayoutEffect as Gt, useEffect as Yt, useRef as In, createContext as vt, useReducer as wn, useContext as ht, forwardRef as Ve, useId as Cn, useMemo as Sn, isValidElement as Tn } from "react";
6
- import { B as Xt } from "./button-BB5sYVKY.js";
7
- import * as Zt from "react-dom";
8
- import { f as On, b as Mn, o as An, c as Pn, g as ot } from "./floating-ui.dom-bEgaHJCq.js";
9
- import { S as Nn } from "./index-D7FJjvrv.js";
10
- import { L as Dn } from "./label-xTmTyPhk.js";
11
- import { I as Fn } from "./input-wBv_FkEV.js";
12
- const St = (e, t) => {
13
- const n = {}, r = {};
14
- let o = 0;
15
- const i = e.length;
16
- for (; o < i; )
17
- r[e[o]] = 1, o += 1;
18
- for (const s in t)
19
- Object.hasOwn(r, s) || (n[s] = t[s]);
20
- return n;
21
- };
22
- function et() {
23
- return typeof window < "u";
24
- }
25
- function tt(e) {
26
- return Jt(e) ? (e.nodeName || "").toLowerCase() : "#document";
27
- }
28
- function _e(e) {
29
- var t;
30
- return (e == null || (t = e.ownerDocument) == null ? void 0 : t.defaultView) || window;
31
- }
32
- function kn(e) {
33
- var t;
34
- return (t = (Jt(e) ? e.ownerDocument : e.document) || window.document) == null ? void 0 : t.documentElement;
35
- }
36
- function Jt(e) {
37
- return et() ? e instanceof Node || e instanceof _e(e).Node : !1;
38
- }
39
- function oe(e) {
40
- return et() ? e instanceof Element || e instanceof _e(e).Element : !1;
41
- }
42
- function de(e) {
43
- return et() ? e instanceof HTMLElement || e instanceof _e(e).HTMLElement : !1;
44
- }
45
- function mt(e) {
46
- return !et() || typeof ShadowRoot > "u" ? !1 : e instanceof ShadowRoot || e instanceof _e(e).ShadowRoot;
47
- }
48
- function Tt(e) {
49
- return ["html", "body", "#document"].includes(tt(e));
50
- }
51
- function Ln(e) {
52
- return _e(e).getComputedStyle(e);
53
- }
54
- function Vn(e) {
55
- if (tt(e) === "html")
56
- return e;
57
- const t = (
58
- // Step into the shadow DOM of the parent of a slotted node.
59
- e.assignedSlot || // DOM Element detected.
60
- e.parentNode || // ShadowRoot detected.
61
- mt(e) && e.host || // Fallback.
62
- kn(e)
63
- );
64
- return mt(t) ? t.host : t;
65
- }
66
- function me(e) {
67
- let t = e.activeElement;
68
- for (; ((n = t) == null || (n = n.shadowRoot) == null ? void 0 : n.activeElement) != null; ) {
69
- var n;
70
- t = t.shadowRoot.activeElement;
71
- }
72
- return t;
73
- }
74
- function Q(e, t) {
75
- if (!e || !t)
76
- return !1;
77
- const n = t.getRootNode == null ? void 0 : t.getRootNode();
78
- if (e.contains(t))
79
- return !0;
80
- if (n && mt(n)) {
81
- let r = t;
82
- for (; r; ) {
83
- if (e === r)
84
- return !0;
85
- r = r.parentNode || r.host;
86
- }
87
- }
88
- return !1;
89
- }
90
- function Qt() {
91
- const e = navigator.userAgentData;
92
- return e != null && e.platform ? e.platform : navigator.platform;
93
- }
94
- function en() {
95
- const e = navigator.userAgentData;
96
- return e && Array.isArray(e.brands) ? e.brands.map((t) => {
97
- let {
98
- brand: n,
99
- version: r
100
- } = t;
101
- return n + "/" + r;
102
- }).join(" ") : navigator.userAgent;
103
- }
104
- function tn(e) {
105
- return e.mozInputSource === 0 && e.isTrusted ? !0 : pt() && e.pointerType ? e.type === "click" && e.buttons === 1 : e.detail === 0 && !e.pointerType;
106
- }
107
- function nn(e) {
108
- return Kn() ? !1 : !pt() && e.width === 0 && e.height === 0 || pt() && e.width === 1 && e.height === 1 && e.pressure === 0 && e.detail === 0 && e.pointerType === "mouse" || // iOS VoiceOver returns 0.333• for width/height.
109
- e.width < 1 && e.height < 1 && e.pressure === 0 && e.detail === 0 && e.pointerType === "touch";
110
- }
111
- function rn() {
112
- return /apple/i.test(navigator.vendor);
113
- }
114
- function pt() {
115
- const e = /android/i;
116
- return e.test(Qt()) || e.test(en());
117
- }
118
- function _n() {
119
- return Qt().toLowerCase().startsWith("mac") && !navigator.maxTouchPoints;
120
- }
121
- function Kn() {
122
- return en().includes("jsdom/");
123
- }
124
- function Bn(e) {
125
- return "nativeEvent" in e;
126
- }
127
- function $n(e) {
128
- return e.matches("html,body");
129
- }
130
- function re(e) {
131
- return e?.ownerDocument || document;
132
- }
133
- function it(e, t) {
134
- if (t == null)
135
- return !1;
136
- if ("composedPath" in e)
137
- return e.composedPath().includes(t);
138
- const n = e;
139
- return n.target != null && t.contains(n.target);
140
- }
141
- function Ie(e) {
142
- return "composedPath" in e ? e.composedPath()[0] : e.target;
143
- }
144
- const Wn = "input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
145
- function qn(e) {
146
- return de(e) && e.matches(Wn);
147
- }
148
- function ee(e) {
149
- e.preventDefault(), e.stopPropagation();
150
- }
151
- function on(e) {
152
- return e ? e.getAttribute("role") === "combobox" && qn(e) : !1;
153
- }
154
- const Ot = Math.floor;
155
- var Hn = ["input:not([inert])", "select:not([inert])", "textarea:not([inert])", "a[href]:not([inert])", "button:not([inert])", "[tabindex]:not(slot):not([inert])", "audio[controls]:not([inert])", "video[controls]:not([inert])", '[contenteditable]:not([contenteditable="false"]):not([inert])', "details>summary:first-of-type:not([inert])", "details:not([inert])"], Ge = /* @__PURE__ */ Hn.join(","), sn = typeof Element > "u", Se = sn ? function() {
156
- } : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector, Ye = !sn && Element.prototype.getRootNode ? function(e) {
157
- var t;
158
- return e == null || (t = e.getRootNode) === null || t === void 0 ? void 0 : t.call(e);
159
- } : function(e) {
160
- return e?.ownerDocument;
161
- }, Xe = function e(t, n) {
162
- var r;
163
- n === void 0 && (n = !0);
164
- var o = t == null || (r = t.getAttribute) === null || r === void 0 ? void 0 : r.call(t, "inert"), i = o === "" || o === "true", s = i || n && t && e(t.parentNode);
165
- return s;
166
- }, jn = function(t) {
167
- var n, r = t == null || (n = t.getAttribute) === null || n === void 0 ? void 0 : n.call(t, "contenteditable");
168
- return r === "" || r === "true";
169
- }, Un = function(t, n, r) {
170
- if (Xe(t))
171
- return [];
172
- var o = Array.prototype.slice.apply(t.querySelectorAll(Ge));
173
- return n && Se.call(t, Ge) && o.unshift(t), o = o.filter(r), o;
174
- }, zn = function e(t, n, r) {
175
- for (var o = [], i = Array.from(t); i.length; ) {
176
- var s = i.shift();
177
- if (!Xe(s, !1))
178
- if (s.tagName === "SLOT") {
179
- var a = s.assignedElements(), l = a.length ? a : s.children, u = e(l, !0, r);
180
- r.flatten ? o.push.apply(o, u) : o.push({
181
- scopeParent: s,
182
- candidates: u
183
- });
184
- } else {
185
- var p = Se.call(s, Ge);
186
- p && r.filter(s) && (n || !t.includes(s)) && o.push(s);
187
- var f = s.shadowRoot || // check for an undisclosed shadow
188
- typeof r.getShadowRoot == "function" && r.getShadowRoot(s), v = !Xe(f, !1) && (!r.shadowRootFilter || r.shadowRootFilter(s));
189
- if (f && v) {
190
- var d = e(f === !0 ? s.children : f.children, !0, r);
191
- r.flatten ? o.push.apply(o, d) : o.push({
192
- scopeParent: s,
193
- candidates: d
194
- });
195
- } else
196
- i.unshift.apply(i, s.children);
197
- }
198
- }
199
- return o;
200
- }, un = function(t) {
201
- return !isNaN(parseInt(t.getAttribute("tabindex"), 10));
202
- }, cn = function(t) {
203
- if (!t)
204
- throw new Error("No node provided");
205
- return t.tabIndex < 0 && (/^(AUDIO|VIDEO|DETAILS)$/.test(t.tagName) || jn(t)) && !un(t) ? 0 : t.tabIndex;
206
- }, Gn = function(t, n) {
207
- var r = cn(t);
208
- return r < 0 && n && !un(t) ? 0 : r;
209
- }, Yn = function(t, n) {
210
- return t.tabIndex === n.tabIndex ? t.documentOrder - n.documentOrder : t.tabIndex - n.tabIndex;
211
- }, an = function(t) {
212
- return t.tagName === "INPUT";
213
- }, Xn = function(t) {
214
- return an(t) && t.type === "hidden";
215
- }, Zn = function(t) {
216
- var n = t.tagName === "DETAILS" && Array.prototype.slice.apply(t.children).some(function(r) {
217
- return r.tagName === "SUMMARY";
218
- });
219
- return n;
220
- }, Jn = function(t, n) {
221
- for (var r = 0; r < t.length; r++)
222
- if (t[r].checked && t[r].form === n)
223
- return t[r];
224
- }, Qn = function(t) {
225
- if (!t.name)
226
- return !0;
227
- var n = t.form || Ye(t), r = function(a) {
228
- return n.querySelectorAll('input[type="radio"][name="' + a + '"]');
229
- }, o;
230
- if (typeof window < "u" && typeof window.CSS < "u" && typeof window.CSS.escape == "function")
231
- o = r(window.CSS.escape(t.name));
232
- else
233
- try {
234
- o = r(t.name);
235
- } catch (s) {
236
- return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s", s.message), !1;
237
- }
238
- var i = Jn(o, t.form);
239
- return !i || i === t;
240
- }, er = function(t) {
241
- return an(t) && t.type === "radio";
242
- }, tr = function(t) {
243
- return er(t) && !Qn(t);
244
- }, nr = function(t) {
245
- var n, r = t && Ye(t), o = (n = r) === null || n === void 0 ? void 0 : n.host, i = !1;
246
- if (r && r !== t) {
247
- var s, a, l;
248
- for (i = !!((s = o) !== null && s !== void 0 && (a = s.ownerDocument) !== null && a !== void 0 && a.contains(o) || t != null && (l = t.ownerDocument) !== null && l !== void 0 && l.contains(t)); !i && o; ) {
249
- var u, p, f;
250
- r = Ye(o), o = (u = r) === null || u === void 0 ? void 0 : u.host, i = !!((p = o) !== null && p !== void 0 && (f = p.ownerDocument) !== null && f !== void 0 && f.contains(o));
251
- }
252
- }
253
- return i;
254
- }, Mt = function(t) {
255
- var n = t.getBoundingClientRect(), r = n.width, o = n.height;
256
- return r === 0 && o === 0;
257
- }, rr = function(t, n) {
258
- var r = n.displayCheck, o = n.getShadowRoot;
259
- if (getComputedStyle(t).visibility === "hidden")
260
- return !0;
261
- var i = Se.call(t, "details>summary:first-of-type"), s = i ? t.parentElement : t;
262
- if (Se.call(s, "details:not([open]) *"))
263
- return !0;
264
- if (!r || r === "full" || r === "legacy-full") {
265
- if (typeof o == "function") {
266
- for (var a = t; t; ) {
267
- var l = t.parentElement, u = Ye(t);
268
- if (l && !l.shadowRoot && o(l) === !0)
269
- return Mt(t);
270
- t.assignedSlot ? t = t.assignedSlot : !l && u !== t.ownerDocument ? t = u.host : t = l;
271
- }
272
- t = a;
273
- }
274
- if (nr(t))
275
- return !t.getClientRects().length;
276
- if (r !== "legacy-full")
277
- return !0;
278
- } else if (r === "non-zero-area")
279
- return Mt(t);
280
- return !1;
281
- }, or = function(t) {
282
- if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(t.tagName))
283
- for (var n = t.parentElement; n; ) {
284
- if (n.tagName === "FIELDSET" && n.disabled) {
285
- for (var r = 0; r < n.children.length; r++) {
286
- var o = n.children.item(r);
287
- if (o.tagName === "LEGEND")
288
- return Se.call(n, "fieldset[disabled] *") ? !0 : !o.contains(t);
289
- }
290
- return !0;
291
- }
292
- n = n.parentElement;
293
- }
294
- return !1;
295
- }, ir = function(t, n) {
296
- return !(n.disabled || // we must do an inert look up to filter out any elements inside an inert ancestor
297
- // because we're limited in the type of selectors we can use in JSDom (see related
298
- // note related to `candidateSelectors`)
299
- Xe(n) || Xn(n) || rr(n, t) || // For a details element with a summary, the summary element gets the focus
300
- Zn(n) || or(n));
301
- }, bt = function(t, n) {
302
- return !(tr(n) || cn(n) < 0 || !ir(t, n));
303
- }, sr = function(t) {
304
- var n = parseInt(t.getAttribute("tabindex"), 10);
305
- return !!(isNaN(n) || n >= 0);
306
- }, ur = function e(t) {
307
- var n = [], r = [];
308
- return t.forEach(function(o, i) {
309
- var s = !!o.scopeParent, a = s ? o.scopeParent : o, l = Gn(a, s), u = s ? e(o.candidates) : a;
310
- l === 0 ? s ? n.push.apply(n, u) : n.push(a) : r.push({
311
- documentOrder: i,
312
- tabIndex: l,
313
- item: o,
314
- isScope: s,
315
- content: u
316
- });
317
- }), r.sort(Yn).reduce(function(o, i) {
318
- return i.isScope ? o.push.apply(o, i.content) : o.push(i.content), o;
319
- }, []).concat(n);
320
- }, ke = function(t, n) {
321
- n = n || {};
322
- var r;
323
- return n.getShadowRoot ? r = zn([t], n.includeContainer, {
324
- filter: bt.bind(null, n),
325
- flatten: !1,
326
- getShadowRoot: n.getShadowRoot,
327
- shadowRootFilter: sr
328
- }) : r = Un(t, n.includeContainer, bt.bind(null, n)), ur(r);
329
- }, cr = function(t, n) {
330
- if (n = n || {}, !t)
331
- throw new Error("No node provided");
332
- return Se.call(t, Ge) === !1 ? !1 : bt(n, t);
333
- }, Ue = typeof document < "u" ? Gt : Yt;
334
- function Ze(e, t) {
335
- if (e === t)
336
- return !0;
337
- if (typeof e != typeof t)
338
- return !1;
339
- if (typeof e == "function" && e.toString() === t.toString())
340
- return !0;
341
- let n, r, o;
342
- if (e && t && typeof e == "object") {
343
- if (Array.isArray(e)) {
344
- if (n = e.length, n !== t.length) return !1;
345
- for (r = n; r-- !== 0; )
346
- if (!Ze(e[r], t[r]))
347
- return !1;
348
- return !0;
349
- }
350
- if (o = Object.keys(e), n = o.length, n !== Object.keys(t).length)
351
- return !1;
352
- for (r = n; r-- !== 0; )
353
- if (!{}.hasOwnProperty.call(t, o[r]))
354
- return !1;
355
- for (r = n; r-- !== 0; ) {
356
- const i = o[r];
357
- if (!(i === "_owner" && e.$$typeof) && !Ze(e[i], t[i]))
358
- return !1;
359
- }
360
- return !0;
361
- }
362
- return e !== e && t !== t;
363
- }
364
- function ln(e) {
365
- return typeof window > "u" ? 1 : (e.ownerDocument.defaultView || window).devicePixelRatio || 1;
366
- }
367
- function At(e, t) {
368
- const n = ln(e);
369
- return Math.round(t * n) / n;
370
- }
371
- function st(e) {
372
- const t = c.useRef(e);
373
- return Ue(() => {
374
- t.current = e;
375
- }), t;
376
- }
377
- function ar(e) {
378
- e === void 0 && (e = {});
379
- const {
380
- placement: t = "bottom",
381
- strategy: n = "absolute",
382
- middleware: r = [],
383
- platform: o,
384
- elements: {
385
- reference: i,
386
- floating: s
387
- } = {},
388
- transform: a = !0,
389
- whileElementsMounted: l,
390
- open: u
391
- } = e, [p, f] = c.useState({
392
- x: 0,
393
- y: 0,
394
- strategy: n,
395
- placement: t,
396
- middlewareData: {},
397
- isPositioned: !1
398
- }), [v, d] = c.useState(r);
399
- Ze(v, r) || d(r);
400
- const [m, h] = c.useState(null), [P, N] = c.useState(null), L = c.useCallback((w) => {
401
- w !== k.current && (k.current = w, h(w));
402
- }, []), g = c.useCallback((w) => {
403
- w !== U.current && (U.current = w, N(w));
404
- }, []), C = i || m, z = s || P, k = c.useRef(null), U = c.useRef(null), K = c.useRef(p), ue = l != null, Z = st(l), H = st(o), y = st(u), D = c.useCallback(() => {
405
- if (!k.current || !U.current)
406
- return;
407
- const w = {
408
- placement: t,
409
- strategy: n,
410
- middleware: v
411
- };
412
- H.current && (w.platform = H.current), Pn(k.current, U.current, w).then((R) => {
413
- const V = {
414
- ...R,
415
- // The floating element's position may be recomputed while it's closed
416
- // but still mounted (such as when transitioning out). To ensure
417
- // `isPositioned` will be `false` initially on the next open, avoid
418
- // setting it to `true` when `open === false` (must be specified).
419
- isPositioned: y.current !== !1
420
- };
421
- S.current && !Ze(K.current, V) && (K.current = V, Zt.flushSync(() => {
422
- f(V);
423
- }));
424
- });
425
- }, [v, t, n, H, y]);
426
- Ue(() => {
427
- u === !1 && K.current.isPositioned && (K.current.isPositioned = !1, f((w) => ({
428
- ...w,
429
- isPositioned: !1
430
- })));
431
- }, [u]);
432
- const S = c.useRef(!1);
433
- Ue(() => (S.current = !0, () => {
434
- S.current = !1;
435
- }), []), Ue(() => {
436
- if (C && (k.current = C), z && (U.current = z), C && z) {
437
- if (Z.current)
438
- return Z.current(C, z, D);
439
- D();
440
- }
441
- }, [C, z, D, Z, ue]);
442
- const b = c.useMemo(() => ({
443
- reference: k,
444
- floating: U,
445
- setReference: L,
446
- setFloating: g
447
- }), [L, g]), T = c.useMemo(() => ({
448
- reference: C,
449
- floating: z
450
- }), [C, z]), F = c.useMemo(() => {
451
- const w = {
452
- position: n,
453
- left: 0,
454
- top: 0
455
- };
456
- if (!T.floating)
457
- return w;
458
- const R = At(T.floating, p.x), V = At(T.floating, p.y);
459
- return a ? {
460
- ...w,
461
- transform: "translate(" + R + "px, " + V + "px)",
462
- ...ln(T.floating) >= 1.5 && {
463
- willChange: "transform"
464
- }
465
- } : {
466
- position: n,
467
- left: R,
468
- top: V
469
- };
470
- }, [n, a, T.floating, p.x, p.y]);
471
- return c.useMemo(() => ({
472
- ...p,
473
- update: D,
474
- refs: b,
475
- elements: T,
476
- floatingStyles: F
477
- }), [p, D, b, T, F]);
478
- }
479
- const ro = (e, t) => ({
480
- ...An(e),
481
- options: [e, t]
482
- }), oo = (e, t) => ({
483
- ...On(e),
484
- options: [e, t]
485
- }), io = (e, t) => ({
486
- ...Mn(e),
487
- options: [e, t]
488
- });
489
- function lr(e) {
490
- return c.useMemo(() => e.every((t) => t == null) ? null : (t) => {
491
- e.forEach((n) => {
492
- typeof n == "function" ? n(t) : n != null && (n.current = t);
493
- });
494
- }, e);
495
- }
496
- const fn = {
497
- ...c
498
- }, fr = fn.useInsertionEffect, dr = fr || ((e) => e());
499
- function se(e) {
500
- const t = c.useRef(() => {
501
- if (process.env.NODE_ENV !== "production")
502
- throw new Error("Cannot call an event handler while rendering.");
503
- });
504
- return dr(() => {
505
- t.current = e;
506
- }), c.useCallback(function() {
507
- for (var n = arguments.length, r = new Array(n), o = 0; o < n; o++)
508
- r[o] = arguments[o];
509
- return t.current == null ? void 0 : t.current(...r);
510
- }, []);
511
- }
512
- const xt = "ArrowUp", Ke = "ArrowDown", Te = "ArrowLeft", Ae = "ArrowRight";
513
- function qe(e, t, n) {
514
- return Math.floor(e / t) !== n;
515
- }
516
- function De(e, t) {
517
- return t < 0 || t >= e.current.length;
518
- }
519
- function ut(e, t) {
520
- return X(e, {
521
- disabledIndices: t
522
- });
523
- }
524
- function Pt(e, t) {
525
- return X(e, {
526
- decrement: !0,
527
- startingIndex: e.current.length,
528
- disabledIndices: t
529
- });
530
- }
531
- function X(e, t) {
532
- let {
533
- startingIndex: n = -1,
534
- decrement: r = !1,
535
- disabledIndices: o,
536
- amount: i = 1
537
- } = t === void 0 ? {} : t;
538
- const s = e.current;
539
- let a = n;
540
- do
541
- a += r ? -i : i;
542
- while (a >= 0 && a <= s.length - 1 && ze(s, a, o));
543
- return a;
544
- }
545
- function mr(e, t) {
546
- let {
547
- event: n,
548
- orientation: r,
549
- loop: o,
550
- cols: i,
551
- disabledIndices: s,
552
- minIndex: a,
553
- maxIndex: l,
554
- prevIndex: u,
555
- stopEvent: p = !1
556
- } = t, f = u;
557
- if (n.key === xt) {
558
- if (p && ee(n), u === -1)
559
- f = l;
560
- else if (f = X(e, {
561
- startingIndex: f,
562
- amount: i,
563
- decrement: !0,
564
- disabledIndices: s
565
- }), o && (u - i < a || f < 0)) {
566
- const v = u % i, d = l % i, m = l - (d - v);
567
- d === v ? f = l : f = d > v ? m : m - i;
568
- }
569
- De(e, f) && (f = u);
570
- }
571
- if (n.key === Ke && (p && ee(n), u === -1 ? f = a : (f = X(e, {
572
- startingIndex: u,
573
- amount: i,
574
- disabledIndices: s
575
- }), o && u + i > l && (f = X(e, {
576
- startingIndex: u % i - i,
577
- amount: i,
578
- disabledIndices: s
579
- }))), De(e, f) && (f = u)), r === "both") {
580
- const v = Ot(u / i);
581
- n.key === Ae && (p && ee(n), u % i !== i - 1 ? (f = X(e, {
582
- startingIndex: u,
583
- disabledIndices: s
584
- }), o && qe(f, i, v) && (f = X(e, {
585
- startingIndex: u - u % i - 1,
586
- disabledIndices: s
587
- }))) : o && (f = X(e, {
588
- startingIndex: u - u % i - 1,
589
- disabledIndices: s
590
- })), qe(f, i, v) && (f = u)), n.key === Te && (p && ee(n), u % i !== 0 ? (f = X(e, {
591
- startingIndex: u,
592
- decrement: !0,
593
- disabledIndices: s
594
- }), o && qe(f, i, v) && (f = X(e, {
595
- startingIndex: u + (i - u % i),
596
- decrement: !0,
597
- disabledIndices: s
598
- }))) : o && (f = X(e, {
599
- startingIndex: u + (i - u % i),
600
- decrement: !0,
601
- disabledIndices: s
602
- })), qe(f, i, v) && (f = u));
603
- const d = Ot(l / i) === v;
604
- De(e, f) && (o && d ? f = n.key === Te ? l : X(e, {
605
- startingIndex: u - u % i - 1,
606
- disabledIndices: s
607
- }) : f = u);
608
- }
609
- return f;
610
- }
611
- function pr(e, t, n) {
612
- const r = [];
613
- let o = 0;
614
- return e.forEach((i, s) => {
615
- let {
616
- width: a,
617
- height: l
618
- } = i;
619
- if (a > t && process.env.NODE_ENV !== "production")
620
- throw new Error("[Floating UI]: Invalid grid - item width at index " + s + " is greater than grid columns");
621
- let u = !1;
622
- for (n && (o = 0); !u; ) {
623
- const p = [];
624
- for (let f = 0; f < a; f++)
625
- for (let v = 0; v < l; v++)
626
- p.push(o + f + v * t);
627
- o % t + a <= t && p.every((f) => r[f] == null) ? (p.forEach((f) => {
628
- r[f] = s;
629
- }), u = !0) : o++;
630
- }
631
- }), [...r];
632
- }
633
- function br(e, t, n, r, o) {
634
- if (e === -1) return -1;
635
- const i = n.indexOf(e), s = t[e];
636
- switch (o) {
637
- case "tl":
638
- return i;
639
- case "tr":
640
- return s ? i + s.width - 1 : i;
641
- case "bl":
642
- return s ? i + (s.height - 1) * r : i;
643
- case "br":
644
- return n.lastIndexOf(e);
645
- }
646
- }
647
- function gr(e, t) {
648
- return t.flatMap((n, r) => e.includes(n) ? [r] : []);
649
- }
650
- function ze(e, t, n) {
651
- if (n)
652
- return n.includes(t);
653
- const r = e[t];
654
- return r == null || r.hasAttribute("disabled") || r.getAttribute("aria-disabled") === "true";
655
- }
656
- let Nt = 0;
657
- function he(e, t) {
658
- t === void 0 && (t = {});
659
- const {
660
- preventScroll: n = !1,
661
- cancelPrevious: r = !0,
662
- sync: o = !1
663
- } = t;
664
- r && cancelAnimationFrame(Nt);
665
- const i = () => e?.focus({
666
- preventScroll: n
667
- });
668
- o ? i() : Nt = requestAnimationFrame(i);
669
- }
670
- var j = typeof document < "u" ? Gt : Yt;
671
- function Je() {
672
- return Je = Object.assign ? Object.assign.bind() : function(e) {
673
- for (var t = 1; t < arguments.length; t++) {
674
- var n = arguments[t];
675
- for (var r in n)
676
- Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
677
- }
678
- return e;
679
- }, Je.apply(this, arguments);
680
- }
681
- let Dt = !1, vr = 0;
682
- const Ft = () => (
683
- // Ensure the id is unique with multiple independent versions of Floating UI
684
- // on <React 18
685
- "floating-ui-" + Math.random().toString(36).slice(2, 6) + vr++
686
- );
687
- function hr() {
688
- const [e, t] = c.useState(() => Dt ? Ft() : void 0);
689
- return j(() => {
690
- e == null && t(Ft());
691
- }, []), c.useEffect(() => {
692
- Dt = !0;
693
- }, []), e;
694
- }
695
- const xr = fn.useId, Et = xr || hr;
696
- let Le;
697
- process.env.NODE_ENV !== "production" && (Le = /* @__PURE__ */ new Set());
698
- function ct() {
699
- for (var e, t = arguments.length, n = new Array(t), r = 0; r < t; r++)
700
- n[r] = arguments[r];
701
- const o = "Floating UI: " + n.join(" ");
702
- if (!((e = Le) != null && e.has(o))) {
703
- var i;
704
- (i = Le) == null || i.add(o), console.warn(o);
705
- }
706
- }
707
- function Er() {
708
- for (var e, t = arguments.length, n = new Array(t), r = 0; r < t; r++)
709
- n[r] = arguments[r];
710
- const o = "Floating UI: " + n.join(" ");
711
- if (!((e = Le) != null && e.has(o))) {
712
- var i;
713
- (i = Le) == null || i.add(o), console.error(o);
714
- }
715
- }
716
- function yr() {
717
- const e = /* @__PURE__ */ new Map();
718
- return {
719
- emit(t, n) {
720
- var r;
721
- (r = e.get(t)) == null || r.forEach((o) => o(n));
722
- },
723
- on(t, n) {
724
- e.set(t, [...e.get(t) || [], n]);
725
- },
726
- off(t, n) {
727
- var r;
728
- e.set(t, ((r = e.get(t)) == null ? void 0 : r.filter((o) => o !== n)) || []);
729
- }
730
- };
731
- }
732
- const Rr = /* @__PURE__ */ c.createContext(null), Ir = /* @__PURE__ */ c.createContext(null), yt = () => {
733
- var e;
734
- return ((e = c.useContext(Rr)) == null ? void 0 : e.id) || null;
735
- }, nt = () => c.useContext(Ir);
736
- function Oe(e) {
737
- return "data-floating-ui-" + e;
738
- }
739
- function xe(e) {
740
- const t = In(e);
741
- return j(() => {
742
- t.current = e;
743
- }), t;
744
- }
745
- function wr(e, t) {
746
- var n;
747
- let r = [], o = (n = e.find((i) => i.id === t)) == null ? void 0 : n.parentId;
748
- for (; o; ) {
749
- const i = e.find((s) => s.id === o);
750
- o = i?.parentId, i && (r = r.concat(i));
751
- }
752
- return r;
753
- }
754
- function Ce(e, t) {
755
- let n = e.filter((o) => {
756
- var i;
757
- return o.parentId === t && ((i = o.context) == null ? void 0 : i.open);
758
- }), r = n;
759
- for (; r.length; )
760
- r = e.filter((o) => {
761
- var i;
762
- return (i = r) == null ? void 0 : i.some((s) => {
763
- var a;
764
- return o.parentId === s.id && ((a = o.context) == null ? void 0 : a.open);
765
- });
766
- }), n = n.concat(r);
767
- return n;
768
- }
769
- function Cr(e, t) {
770
- let n, r = -1;
771
- function o(i, s) {
772
- s > r && (n = i, r = s), Ce(e, i).forEach((l) => {
773
- o(l.id, s + 1);
774
- });
775
- }
776
- return o(t, 0), e.find((i) => i.id === n);
777
- }
778
- let we = /* @__PURE__ */ new WeakMap(), He = /* @__PURE__ */ new WeakSet(), je = {}, at = 0;
779
- const Sr = () => typeof HTMLElement < "u" && "inert" in HTMLElement.prototype, dn = (e) => e && (e.host || dn(e.parentNode)), Tr = (e, t) => t.map((n) => {
780
- if (e.contains(n))
781
- return n;
782
- const r = dn(n);
783
- return e.contains(r) ? r : null;
784
- }).filter((n) => n != null);
785
- function Or(e, t, n, r) {
786
- const o = "data-floating-ui-inert", i = r ? "inert" : n ? "aria-hidden" : null, s = Tr(t, e), a = /* @__PURE__ */ new Set(), l = new Set(s), u = [];
787
- je[o] || (je[o] = /* @__PURE__ */ new WeakMap());
788
- const p = je[o];
789
- s.forEach(f), v(t), a.clear();
790
- function f(d) {
791
- !d || a.has(d) || (a.add(d), d.parentNode && f(d.parentNode));
792
- }
793
- function v(d) {
794
- !d || l.has(d) || [].forEach.call(d.children, (m) => {
795
- if (tt(m) !== "script")
796
- if (a.has(m))
797
- v(m);
798
- else {
799
- const h = i ? m.getAttribute(i) : null, P = h !== null && h !== "false", N = (we.get(m) || 0) + 1, L = (p.get(m) || 0) + 1;
800
- we.set(m, N), p.set(m, L), u.push(m), N === 1 && P && He.add(m), L === 1 && m.setAttribute(o, ""), !P && i && m.setAttribute(i, "true");
801
- }
802
- });
803
- }
804
- return at++, () => {
805
- u.forEach((d) => {
806
- const m = (we.get(d) || 0) - 1, h = (p.get(d) || 0) - 1;
807
- we.set(d, m), p.set(d, h), m || (!He.has(d) && i && d.removeAttribute(i), He.delete(d)), h || d.removeAttribute(o);
808
- }), at--, at || (we = /* @__PURE__ */ new WeakMap(), we = /* @__PURE__ */ new WeakMap(), He = /* @__PURE__ */ new WeakSet(), je = {});
809
- };
810
- }
811
- function kt(e, t, n) {
812
- t === void 0 && (t = !1), n === void 0 && (n = !1);
813
- const r = re(e[0]).body;
814
- return Or(e.concat(Array.from(r.querySelectorAll("[aria-live]"))), r, t, n);
815
- }
816
- const Me = () => ({
817
- getShadowRoot: !0,
818
- displayCheck: (
819
- // JSDOM does not support the `tabbable` library. To solve this we can
820
- // check if `ResizeObserver` is a real function (not polyfilled), which
821
- // determines if the current environment is JSDOM-like.
822
- typeof ResizeObserver == "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
823
- )
824
- });
825
- function mn(e, t) {
826
- const n = ke(e, Me());
827
- t === "prev" && n.reverse();
828
- const r = n.indexOf(me(re(e)));
829
- return n.slice(r + 1)[0];
830
- }
831
- function pn() {
832
- return mn(document.body, "next");
833
- }
834
- function bn() {
835
- return mn(document.body, "prev");
836
- }
837
- function Fe(e, t) {
838
- const n = t || e.currentTarget, r = e.relatedTarget;
839
- return !r || !Q(n, r);
840
- }
841
- function Mr(e) {
842
- ke(e, Me()).forEach((n) => {
843
- n.dataset.tabindex = n.getAttribute("tabindex") || "", n.setAttribute("tabindex", "-1");
844
- });
845
- }
846
- function Lt(e) {
847
- e.querySelectorAll("[data-tabindex]").forEach((n) => {
848
- const r = n.dataset.tabindex;
849
- delete n.dataset.tabindex, r ? n.setAttribute("tabindex", r) : n.removeAttribute("tabindex");
850
- });
851
- }
852
- function Ar(e, t, n) {
853
- const r = e.indexOf(t);
854
- function o(s) {
855
- const a = Oe("focus-guard");
856
- let l = r + (s ? 1 : 0), u = e[l];
857
- for (; u && (!u.isConnected || u.hasAttribute(a) || Q(n, u)); )
858
- s ? l++ : l--, u = e[l];
859
- return u;
860
- }
861
- const i = o(!0);
862
- return i || o(!1);
863
- }
864
- const Rt = {
865
- border: 0,
866
- clip: "rect(0 0 0 0)",
867
- height: "1px",
868
- margin: "-1px",
869
- overflow: "hidden",
870
- padding: 0,
871
- position: "fixed",
872
- whiteSpace: "nowrap",
873
- width: "1px",
874
- top: 0,
875
- left: 0
876
- };
877
- let Pr;
878
- function Vt(e) {
879
- e.key === "Tab" && (e.target, clearTimeout(Pr));
880
- }
881
- const Qe = /* @__PURE__ */ c.forwardRef(function(t, n) {
882
- const [r, o] = c.useState();
883
- j(() => (rn() && o("button"), document.addEventListener("keydown", Vt), () => {
884
- document.removeEventListener("keydown", Vt);
885
- }), []);
886
- const i = {
887
- ref: n,
888
- tabIndex: 0,
889
- // Role is only for VoiceOver
890
- role: r,
891
- "aria-hidden": r ? void 0 : !0,
892
- [Oe("focus-guard")]: "",
893
- style: Rt
894
- };
895
- return /* @__PURE__ */ c.createElement("span", Je({}, t, i));
896
- }), gn = /* @__PURE__ */ c.createContext(null), _t = /* @__PURE__ */ Oe("portal");
897
- function Nr(e) {
898
- e === void 0 && (e = {});
899
- const {
900
- id: t,
901
- root: n
902
- } = e, r = Et(), o = vn(), [i, s] = c.useState(null), a = c.useRef(null);
903
- return j(() => () => {
904
- i?.remove(), queueMicrotask(() => {
905
- a.current = null;
906
- });
907
- }, [i]), j(() => {
908
- if (!r || a.current) return;
909
- const l = t ? document.getElementById(t) : null;
910
- if (!l) return;
911
- const u = document.createElement("div");
912
- u.id = r, u.setAttribute(_t, ""), l.appendChild(u), a.current = u, s(u);
913
- }, [t, r]), j(() => {
914
- if (!r || a.current) return;
915
- let l = n || o?.portalNode;
916
- l && !oe(l) && (l = l.current), l = l || document.body;
917
- let u = null;
918
- t && (u = document.createElement("div"), u.id = t, l.appendChild(u));
919
- const p = document.createElement("div");
920
- p.id = r, p.setAttribute(_t, ""), l = u || l, l.appendChild(p), a.current = p, s(p);
921
- }, [t, n, r, o]), i;
922
- }
923
- function so(e) {
924
- const {
925
- children: t,
926
- id: n,
927
- root: r = null,
928
- preserveTabOrder: o = !0
929
- } = e, i = Nr({
930
- id: n,
931
- root: r
932
- }), [s, a] = c.useState(null), l = c.useRef(null), u = c.useRef(null), p = c.useRef(null), f = c.useRef(null), v = s?.modal, d = s?.open, m = (
933
- // The FocusManager and therefore floating element are currently open/
934
- // rendered.
935
- !!s && // Guards are only for non-modal focus management.
936
- !s.modal && // Don't render if unmount is transitioning.
937
- s.open && o && !!(r || i)
938
- );
939
- return c.useEffect(() => {
940
- if (!i || !o || v)
941
- return;
942
- function h(P) {
943
- i && Fe(P) && (P.type === "focusin" ? Lt : Mr)(i);
944
- }
945
- return i.addEventListener("focusin", h, !0), i.addEventListener("focusout", h, !0), () => {
946
- i.removeEventListener("focusin", h, !0), i.removeEventListener("focusout", h, !0);
947
- };
948
- }, [i, o, v]), c.useEffect(() => {
949
- i && (d || Lt(i));
950
- }, [d, i]), /* @__PURE__ */ c.createElement(gn.Provider, {
951
- value: c.useMemo(() => ({
952
- preserveTabOrder: o,
953
- beforeOutsideRef: l,
954
- afterOutsideRef: u,
955
- beforeInsideRef: p,
956
- afterInsideRef: f,
957
- portalNode: i,
958
- setFocusManagerState: a
959
- }), [o, i])
960
- }, m && i && /* @__PURE__ */ c.createElement(Qe, {
961
- "data-type": "outside",
962
- ref: l,
963
- onFocus: (h) => {
964
- if (Fe(h, i)) {
965
- var P;
966
- (P = p.current) == null || P.focus();
967
- } else {
968
- const N = bn() || s?.refs.domReference.current;
969
- N?.focus();
970
- }
971
- }
972
- }), m && i && /* @__PURE__ */ c.createElement("span", {
973
- "aria-owns": i.id,
974
- style: Rt
975
- }), i && /* @__PURE__ */ Zt.createPortal(t, i), m && i && /* @__PURE__ */ c.createElement(Qe, {
976
- "data-type": "outside",
977
- ref: u,
978
- onFocus: (h) => {
979
- if (Fe(h, i)) {
980
- var P;
981
- (P = f.current) == null || P.focus();
982
- } else {
983
- const N = pn() || s?.refs.domReference.current;
984
- N?.focus(), s?.closeOnFocusOut && s?.onOpenChange(!1, h.nativeEvent, "focus-out");
985
- }
986
- }
987
- }));
988
- }
989
- const vn = () => c.useContext(gn), gt = "data-floating-ui-focusable";
990
- function hn(e) {
991
- return e ? e.hasAttribute(gt) ? e : e.querySelector("[" + gt + "]") || e : null;
992
- }
993
- const Kt = 20;
994
- let Re = [];
995
- function lt(e) {
996
- Re = Re.filter((n) => n.isConnected);
997
- let t = e;
998
- if (!(!t || tt(t) === "body")) {
999
- if (!cr(t, Me())) {
1000
- const n = ke(t, Me())[0];
1001
- n && (t = n);
1002
- }
1003
- Re.push(t), Re.length > Kt && (Re = Re.slice(-Kt));
1004
- }
1005
- }
1006
- function Bt() {
1007
- return Re.slice().reverse().find((e) => e.isConnected);
1008
- }
1009
- const Dr = /* @__PURE__ */ c.forwardRef(function(t, n) {
1010
- return /* @__PURE__ */ c.createElement("button", Je({}, t, {
1011
- type: "button",
1012
- ref: n,
1013
- tabIndex: -1,
1014
- style: Rt
1015
- }));
1016
- });
1017
- function uo(e) {
1018
- const {
1019
- context: t,
1020
- children: n,
1021
- disabled: r = !1,
1022
- order: o = ["content"],
1023
- guards: i = !0,
1024
- initialFocus: s = 0,
1025
- returnFocus: a = !0,
1026
- restoreFocus: l = !1,
1027
- modal: u = !0,
1028
- visuallyHiddenDismiss: p = !1,
1029
- closeOnFocusOut: f = !0
1030
- } = e, {
1031
- open: v,
1032
- refs: d,
1033
- nodeId: m,
1034
- onOpenChange: h,
1035
- events: P,
1036
- dataRef: N,
1037
- floatingId: L,
1038
- elements: {
1039
- domReference: g,
1040
- floating: C
1041
- }
1042
- } = t, z = typeof s == "number" && s < 0, k = on(g) && z, U = Sr() ? i : !0, K = xe(o), ue = xe(s), Z = xe(a), H = nt(), y = vn(), D = c.useRef(null), S = c.useRef(null), b = c.useRef(!1), T = c.useRef(!1), F = c.useRef(-1), w = y != null, R = hn(C), V = se(function(A) {
1043
- return A === void 0 && (A = R), A ? ke(A, Me()) : [];
1044
- }), Y = se((A) => {
1045
- const I = V(A);
1046
- return K.current.map((x) => g && x === "reference" ? g : R && x === "floating" ? R : I).filter(Boolean).flat();
1047
- });
1048
- c.useEffect(() => {
1049
- b.current = !1;
1050
- }, [r]), c.useEffect(() => {
1051
- if (r || !u) return;
1052
- function A(x) {
1053
- if (x.key === "Tab") {
1054
- Q(R, me(re(R))) && V().length === 0 && !k && ee(x);
1055
- const O = Y(), $ = Ie(x);
1056
- K.current[0] === "reference" && $ === g && (ee(x), x.shiftKey ? he(O[O.length - 1]) : he(O[1])), K.current[1] === "floating" && $ === R && x.shiftKey && (ee(x), he(O[0]));
1057
- }
1058
- }
1059
- const I = re(R);
1060
- return I.addEventListener("keydown", A), () => {
1061
- I.removeEventListener("keydown", A);
1062
- };
1063
- }, [r, g, R, u, K, k, V, Y]), c.useEffect(() => {
1064
- if (r || !C) return;
1065
- function A(I) {
1066
- const x = Ie(I), $ = V().indexOf(x);
1067
- $ !== -1 && (F.current = $);
1068
- }
1069
- return C.addEventListener("focusin", A), () => {
1070
- C.removeEventListener("focusin", A);
1071
- };
1072
- }, [r, C, V]), c.useEffect(() => {
1073
- if (r || !f) return;
1074
- function A() {
1075
- T.current = !0, setTimeout(() => {
1076
- T.current = !1;
1077
- });
1078
- }
1079
- function I(x) {
1080
- const O = x.relatedTarget;
1081
- queueMicrotask(() => {
1082
- const $ = !(Q(g, O) || Q(C, O) || Q(O, C) || Q(y?.portalNode, O) || O != null && O.hasAttribute(Oe("focus-guard")) || H && (Ce(H.nodesRef.current, m).find((G) => {
1083
- var J, q;
1084
- return Q((J = G.context) == null ? void 0 : J.elements.floating, O) || Q((q = G.context) == null ? void 0 : q.elements.domReference, O);
1085
- }) || wr(H.nodesRef.current, m).find((G) => {
1086
- var J, q;
1087
- return ((J = G.context) == null ? void 0 : J.elements.floating) === O || ((q = G.context) == null ? void 0 : q.elements.domReference) === O;
1088
- })));
1089
- if (l && $ && me(re(R)) === re(R).body) {
1090
- de(R) && R.focus();
1091
- const G = F.current, J = V(), q = J[G] || J[J.length - 1] || R;
1092
- de(q) && q.focus();
1093
- }
1094
- (k || !u) && O && $ && !T.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
1095
- O !== Bt() && (b.current = !0, h(!1, x, "focus-out"));
1096
- });
1097
- }
1098
- if (C && de(g))
1099
- return g.addEventListener("focusout", I), g.addEventListener("pointerdown", A), C.addEventListener("focusout", I), () => {
1100
- g.removeEventListener("focusout", I), g.removeEventListener("pointerdown", A), C.removeEventListener("focusout", I);
1101
- };
1102
- }, [r, g, C, R, u, m, H, y, h, f, l, V, k]), c.useEffect(() => {
1103
- var A;
1104
- if (r) return;
1105
- const I = Array.from((y == null || (A = y.portalNode) == null ? void 0 : A.querySelectorAll("[" + Oe("portal") + "]")) || []);
1106
- if (C) {
1107
- const x = [C, ...I, D.current, S.current, K.current.includes("reference") || k ? g : null].filter(($) => $ != null), O = u || k ? kt(x, U, !U) : kt(x);
1108
- return () => {
1109
- O();
1110
- };
1111
- }
1112
- }, [r, g, C, u, K, y, k, U]), j(() => {
1113
- if (r || !de(R)) return;
1114
- const A = re(R), I = me(A);
1115
- queueMicrotask(() => {
1116
- const x = Y(R), O = ue.current, $ = (typeof O == "number" ? x[O] : O.current) || R, G = Q(R, I);
1117
- !z && !G && v && he($, {
1118
- preventScroll: $ === R
1119
- });
1120
- });
1121
- }, [r, v, R, z, Y, ue]), j(() => {
1122
- if (r || !R) return;
1123
- let A = !1;
1124
- const I = re(R), x = me(I);
1125
- let $ = N.current.openEvent;
1126
- const G = d.domReference.current;
1127
- lt(x);
1128
- function J(q) {
1129
- let {
1130
- open: ye,
1131
- reason: pe,
1132
- event: te,
1133
- nested: be
1134
- } = q;
1135
- ye && ($ = te), pe === "escape-key" && d.domReference.current && lt(d.domReference.current), pe === "hover" && te.type === "mouseleave" && (b.current = !0), pe === "outside-press" && (be ? (b.current = !1, A = !0) : b.current = !(tn(te) || nn(te)));
1136
- }
1137
- return P.on("openchange", J), () => {
1138
- P.off("openchange", J);
1139
- const q = me(I), ye = Q(C, q) || H && Ce(H.nodesRef.current, m).some((ae) => {
1140
- var Pe;
1141
- return Q((Pe = ae.context) == null ? void 0 : Pe.elements.floating, q);
1142
- });
1143
- (ye || $ && ["click", "mousedown"].includes($.type)) && d.domReference.current && lt(d.domReference.current);
1144
- const te = G || x, be = ke(re(te).body, Me());
1145
- queueMicrotask(() => {
1146
- let ae = Bt();
1147
- !ae && de(te) && C && (ae = Ar(be, te, C)), // eslint-disable-next-line react-hooks/exhaustive-deps
1148
- Z.current && !b.current && de(ae) && // If the focus moved somewhere else after mount, avoid returning focus
1149
- // since it likely entered a different element which should be
1150
- // respected: https://github.com/floating-ui/floating-ui/issues/2607
1151
- (!(ae !== q && q !== I.body) || ye) && ae.focus({
1152
- preventScroll: A
1153
- });
1154
- });
1155
- };
1156
- }, [r, C, R, Z, N, d, P, H, m]), j(() => {
1157
- if (!r && y)
1158
- return y.setFocusManagerState({
1159
- modal: u,
1160
- closeOnFocusOut: f,
1161
- open: v,
1162
- onOpenChange: h,
1163
- refs: d
1164
- }), () => {
1165
- y.setFocusManagerState(null);
1166
- };
1167
- }, [r, y, u, v, h, d, f]), j(() => {
1168
- if (r || !R || typeof MutationObserver != "function" || z) return;
1169
- const A = () => {
1170
- const x = R.getAttribute("tabindex"), O = V(), $ = me(re(C)), G = O.indexOf($);
1171
- G !== -1 && (F.current = G), K.current.includes("floating") || $ !== d.domReference.current && O.length === 0 ? x !== "0" && R.setAttribute("tabindex", "0") : x !== "-1" && R.setAttribute("tabindex", "-1");
1172
- };
1173
- A();
1174
- const I = new MutationObserver(A);
1175
- return I.observe(R, {
1176
- childList: !0,
1177
- subtree: !0,
1178
- attributes: !0
1179
- }), () => {
1180
- I.disconnect();
1181
- };
1182
- }, [r, C, R, d, K, V, z]);
1183
- function fe(A) {
1184
- return r || !p || !u ? null : /* @__PURE__ */ c.createElement(Dr, {
1185
- ref: A === "start" ? D : S,
1186
- onClick: (I) => h(!1, I.nativeEvent)
1187
- }, typeof p == "string" ? p : "Dismiss");
1188
- }
1189
- const ce = !r && U && (u ? !k : !0) && (w || u);
1190
- return /* @__PURE__ */ c.createElement(c.Fragment, null, ce && /* @__PURE__ */ c.createElement(Qe, {
1191
- "data-type": "inside",
1192
- ref: y?.beforeInsideRef,
1193
- onFocus: (A) => {
1194
- if (u) {
1195
- const x = Y();
1196
- he(o[0] === "reference" ? x[0] : x[x.length - 1]);
1197
- } else if (y != null && y.preserveTabOrder && y.portalNode)
1198
- if (b.current = !1, Fe(A, y.portalNode)) {
1199
- const x = pn() || g;
1200
- x?.focus();
1201
- } else {
1202
- var I;
1203
- (I = y.beforeOutsideRef.current) == null || I.focus();
1204
- }
1205
- }
1206
- }), !k && fe("start"), n, fe("end"), ce && /* @__PURE__ */ c.createElement(Qe, {
1207
- "data-type": "inside",
1208
- ref: y?.afterInsideRef,
1209
- onFocus: (A) => {
1210
- if (u)
1211
- he(Y()[0]);
1212
- else if (y != null && y.preserveTabOrder && y.portalNode)
1213
- if (f && (b.current = !0), Fe(A, y.portalNode)) {
1214
- const x = bn() || g;
1215
- x?.focus();
1216
- } else {
1217
- var I;
1218
- (I = y.afterOutsideRef.current) == null || I.focus();
1219
- }
1220
- }
1221
- }));
1222
- }
1223
- const Fr = {
1224
- pointerdown: "onPointerDown",
1225
- mousedown: "onMouseDown",
1226
- click: "onClick"
1227
- }, kr = {
1228
- pointerdown: "onPointerDownCapture",
1229
- mousedown: "onMouseDownCapture",
1230
- click: "onClickCapture"
1231
- }, $t = (e) => {
1232
- var t, n;
1233
- return {
1234
- escapeKey: typeof e == "boolean" ? e : (t = e?.escapeKey) != null ? t : !1,
1235
- outsidePress: typeof e == "boolean" ? e : (n = e?.outsidePress) != null ? n : !0
1236
- };
1237
- };
1238
- function co(e, t) {
1239
- t === void 0 && (t = {});
1240
- const {
1241
- open: n,
1242
- onOpenChange: r,
1243
- elements: o,
1244
- dataRef: i
1245
- } = e, {
1246
- enabled: s = !0,
1247
- escapeKey: a = !0,
1248
- outsidePress: l = !0,
1249
- outsidePressEvent: u = "pointerdown",
1250
- referencePress: p = !1,
1251
- referencePressEvent: f = "pointerdown",
1252
- ancestorScroll: v = !1,
1253
- bubbles: d,
1254
- capture: m
1255
- } = t, h = nt(), P = se(typeof l == "function" ? l : () => !1), N = typeof l == "function" ? P : l, L = c.useRef(!1), g = c.useRef(!1), {
1256
- escapeKey: C,
1257
- outsidePress: z
1258
- } = $t(d), {
1259
- escapeKey: k,
1260
- outsidePress: U
1261
- } = $t(m), K = se((S) => {
1262
- var b;
1263
- if (!n || !s || !a || S.key !== "Escape")
1264
- return;
1265
- const T = (b = i.current.floatingContext) == null ? void 0 : b.nodeId, F = h ? Ce(h.nodesRef.current, T) : [];
1266
- if (!C && (S.stopPropagation(), F.length > 0)) {
1267
- let w = !0;
1268
- if (F.forEach((R) => {
1269
- var V;
1270
- if ((V = R.context) != null && V.open && !R.context.dataRef.current.__escapeKeyBubbles) {
1271
- w = !1;
1272
- return;
1273
- }
1274
- }), !w)
1275
- return;
1276
- }
1277
- r(!1, Bn(S) ? S.nativeEvent : S, "escape-key");
1278
- }), ue = se((S) => {
1279
- var b;
1280
- const T = () => {
1281
- var F;
1282
- K(S), (F = Ie(S)) == null || F.removeEventListener("keydown", T);
1283
- };
1284
- (b = Ie(S)) == null || b.addEventListener("keydown", T);
1285
- }), Z = se((S) => {
1286
- var b;
1287
- const T = L.current;
1288
- L.current = !1;
1289
- const F = g.current;
1290
- if (g.current = !1, u === "click" && F || T || typeof N == "function" && !N(S))
1291
- return;
1292
- const w = Ie(S), R = "[" + Oe("inert") + "]", V = re(o.floating).querySelectorAll(R);
1293
- let Y = oe(w) ? w : null;
1294
- for (; Y && !Tt(Y); ) {
1295
- const I = Vn(Y);
1296
- if (Tt(I) || !oe(I))
1297
- break;
1298
- Y = I;
1299
- }
1300
- if (V.length && oe(w) && !$n(w) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
1301
- !Q(w, o.floating) && // If the target root element contains none of the markers, then the
1302
- // element was injected after the floating element rendered.
1303
- Array.from(V).every((I) => !Q(Y, I)))
1304
- return;
1305
- if (de(w) && D) {
1306
- const I = w.clientWidth > 0 && w.scrollWidth > w.clientWidth, x = w.clientHeight > 0 && w.scrollHeight > w.clientHeight;
1307
- let O = x && S.offsetX > w.clientWidth;
1308
- if (x && Ln(w).direction === "rtl" && (O = S.offsetX <= w.offsetWidth - w.clientWidth), O || I && S.offsetY > w.clientHeight)
1309
- return;
1310
- }
1311
- const fe = (b = i.current.floatingContext) == null ? void 0 : b.nodeId, ce = h && Ce(h.nodesRef.current, fe).some((I) => {
1312
- var x;
1313
- return it(S, (x = I.context) == null ? void 0 : x.elements.floating);
1314
- });
1315
- if (it(S, o.floating) || it(S, o.domReference) || ce)
1316
- return;
1317
- const A = h ? Ce(h.nodesRef.current, fe) : [];
1318
- if (A.length > 0) {
1319
- let I = !0;
1320
- if (A.forEach((x) => {
1321
- var O;
1322
- if ((O = x.context) != null && O.open && !x.context.dataRef.current.__outsidePressBubbles) {
1323
- I = !1;
1324
- return;
1325
- }
1326
- }), !I)
1327
- return;
1328
- }
1329
- r(!1, S, "outside-press");
1330
- }), H = se((S) => {
1331
- var b;
1332
- const T = () => {
1333
- var F;
1334
- Z(S), (F = Ie(S)) == null || F.removeEventListener(u, T);
1335
- };
1336
- (b = Ie(S)) == null || b.addEventListener(u, T);
1337
- });
1338
- c.useEffect(() => {
1339
- if (!n || !s)
1340
- return;
1341
- i.current.__escapeKeyBubbles = C, i.current.__outsidePressBubbles = z;
1342
- function S(F) {
1343
- r(!1, F, "ancestor-scroll");
1344
- }
1345
- const b = re(o.floating);
1346
- a && b.addEventListener("keydown", k ? ue : K, k), N && b.addEventListener(u, U ? H : Z, U);
1347
- let T = [];
1348
- return v && (oe(o.domReference) && (T = ot(o.domReference)), oe(o.floating) && (T = T.concat(ot(o.floating))), !oe(o.reference) && o.reference && o.reference.contextElement && (T = T.concat(ot(o.reference.contextElement)))), T = T.filter((F) => {
1349
- var w;
1350
- return F !== ((w = b.defaultView) == null ? void 0 : w.visualViewport);
1351
- }), T.forEach((F) => {
1352
- F.addEventListener("scroll", S, {
1353
- passive: !0
1354
- });
1355
- }), () => {
1356
- a && b.removeEventListener("keydown", k ? ue : K, k), N && b.removeEventListener(u, U ? H : Z, U), T.forEach((F) => {
1357
- F.removeEventListener("scroll", S);
1358
- });
1359
- };
1360
- }, [i, o, a, N, u, n, r, v, s, C, z, K, k, ue, Z, U, H]), c.useEffect(() => {
1361
- L.current = !1;
1362
- }, [N, u]);
1363
- const y = c.useMemo(() => ({
1364
- onKeyDown: K,
1365
- [Fr[f]]: (S) => {
1366
- p && r(!1, S.nativeEvent, "reference-press");
1367
- }
1368
- }), [K, r, p, f]), D = c.useMemo(() => ({
1369
- onKeyDown: K,
1370
- onMouseDown() {
1371
- g.current = !0;
1372
- },
1373
- onMouseUp() {
1374
- g.current = !0;
1375
- },
1376
- [kr[u]]: () => {
1377
- L.current = !0;
1378
- }
1379
- }), [K, u]);
1380
- return c.useMemo(() => s ? {
1381
- reference: y,
1382
- floating: D
1383
- } : {}, [s, y, D]);
1384
- }
1385
- function Lr(e) {
1386
- const {
1387
- open: t = !1,
1388
- onOpenChange: n,
1389
- elements: r
1390
- } = e, o = Et(), i = c.useRef({}), [s] = c.useState(() => yr()), a = yt() != null;
1391
- if (process.env.NODE_ENV !== "production") {
1392
- const d = r.reference;
1393
- d && !oe(d) && Er("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
1394
- }
1395
- const [l, u] = c.useState(r.reference), p = se((d, m, h) => {
1396
- i.current.openEvent = d ? m : void 0, s.emit("openchange", {
1397
- open: d,
1398
- event: m,
1399
- reason: h,
1400
- nested: a
1401
- }), n?.(d, m, h);
1402
- }), f = c.useMemo(() => ({
1403
- setPositionReference: u
1404
- }), []), v = c.useMemo(() => ({
1405
- reference: l || r.reference || null,
1406
- floating: r.floating || null,
1407
- domReference: r.reference
1408
- }), [l, r.reference, r.floating]);
1409
- return c.useMemo(() => ({
1410
- dataRef: i,
1411
- open: t,
1412
- onOpenChange: p,
1413
- elements: v,
1414
- events: s,
1415
- floatingId: o,
1416
- refs: f
1417
- }), [t, p, v, s, o, f]);
1418
- }
1419
- function ao(e) {
1420
- e === void 0 && (e = {});
1421
- const {
1422
- nodeId: t
1423
- } = e, n = Lr({
1424
- ...e,
1425
- elements: {
1426
- reference: null,
1427
- floating: null,
1428
- ...e.elements
1429
- }
1430
- }), r = e.rootContext || n, o = r.elements, [i, s] = c.useState(null), [a, l] = c.useState(null), p = o?.reference || i, f = c.useRef(null), v = nt();
1431
- j(() => {
1432
- p && (f.current = p);
1433
- }, [p]);
1434
- const d = ar({
1435
- ...e,
1436
- elements: {
1437
- ...o,
1438
- ...a && {
1439
- reference: a
1440
- }
1441
- }
1442
- }), m = c.useCallback((g) => {
1443
- const C = oe(g) ? {
1444
- getBoundingClientRect: () => g.getBoundingClientRect(),
1445
- contextElement: g
1446
- } : g;
1447
- l(C), d.refs.setReference(C);
1448
- }, [d.refs]), h = c.useCallback((g) => {
1449
- (oe(g) || g === null) && (f.current = g, s(g)), (oe(d.refs.reference.current) || d.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
1450
- // `null` to support `positionReference` + an unstable `reference`
1451
- // callback ref.
1452
- g !== null && !oe(g)) && d.refs.setReference(g);
1453
- }, [d.refs]), P = c.useMemo(() => ({
1454
- ...d.refs,
1455
- setReference: h,
1456
- setPositionReference: m,
1457
- domReference: f
1458
- }), [d.refs, h, m]), N = c.useMemo(() => ({
1459
- ...d.elements,
1460
- domReference: p
1461
- }), [d.elements, p]), L = c.useMemo(() => ({
1462
- ...d,
1463
- ...r,
1464
- refs: P,
1465
- elements: N,
1466
- nodeId: t
1467
- }), [d, P, N, t, r]);
1468
- return j(() => {
1469
- r.dataRef.current.floatingContext = L;
1470
- const g = v?.nodesRef.current.find((C) => C.id === t);
1471
- g && (g.context = L);
1472
- }), c.useMemo(() => ({
1473
- ...d,
1474
- context: L,
1475
- refs: P,
1476
- elements: N
1477
- }), [d, P, N, L]);
1478
- }
1479
- const Wt = "active", qt = "selected";
1480
- function ft(e, t, n) {
1481
- const r = /* @__PURE__ */ new Map(), o = n === "item";
1482
- let i = e;
1483
- if (o && e) {
1484
- const {
1485
- [Wt]: s,
1486
- [qt]: a,
1487
- ...l
1488
- } = e;
1489
- i = l;
1490
- }
1491
- return {
1492
- ...n === "floating" && {
1493
- tabIndex: -1,
1494
- [gt]: ""
1495
- },
1496
- ...i,
1497
- ...t.map((s) => {
1498
- const a = s ? s[n] : null;
1499
- return typeof a == "function" ? e ? a(e) : null : a;
1500
- }).concat(e).reduce((s, a) => (a && Object.entries(a).forEach((l) => {
1501
- let [u, p] = l;
1502
- if (!(o && [Wt, qt].includes(u)))
1503
- if (u.indexOf("on") === 0) {
1504
- if (r.has(u) || r.set(u, []), typeof p == "function") {
1505
- var f;
1506
- (f = r.get(u)) == null || f.push(p), s[u] = function() {
1507
- for (var v, d = arguments.length, m = new Array(d), h = 0; h < d; h++)
1508
- m[h] = arguments[h];
1509
- return (v = r.get(u)) == null ? void 0 : v.map((P) => P(...m)).find((P) => P !== void 0);
1510
- };
1511
- }
1512
- } else
1513
- s[u] = p;
1514
- }), s), {})
1515
- };
1516
- }
1517
- function lo(e) {
1518
- e === void 0 && (e = []);
1519
- const t = e.map((a) => a?.reference), n = e.map((a) => a?.floating), r = e.map((a) => a?.item), o = c.useCallback(
1520
- (a) => ft(a, e, "reference"),
1521
- // eslint-disable-next-line react-hooks/exhaustive-deps
1522
- t
1523
- ), i = c.useCallback(
1524
- (a) => ft(a, e, "floating"),
1525
- // eslint-disable-next-line react-hooks/exhaustive-deps
1526
- n
1527
- ), s = c.useCallback(
1528
- (a) => ft(a, e, "item"),
1529
- // eslint-disable-next-line react-hooks/exhaustive-deps
1530
- r
1531
- );
1532
- return c.useMemo(() => ({
1533
- getReferenceProps: o,
1534
- getFloatingProps: i,
1535
- getItemProps: s
1536
- }), [o, i, s]);
1537
- }
1538
- let Ht = !1;
1539
- function rt(e, t, n) {
1540
- switch (e) {
1541
- case "vertical":
1542
- return t;
1543
- case "horizontal":
1544
- return n;
1545
- default:
1546
- return t || n;
1547
- }
1548
- }
1549
- function jt(e, t) {
1550
- return rt(t, e === xt || e === Ke, e === Te || e === Ae);
1551
- }
1552
- function dt(e, t, n) {
1553
- return rt(t, e === Ke, n ? e === Te : e === Ae) || e === "Enter" || e === " " || e === "";
1554
- }
1555
- function Vr(e, t, n) {
1556
- return rt(t, n ? e === Te : e === Ae, e === Ke);
1557
- }
1558
- function Ut(e, t, n) {
1559
- return rt(t, n ? e === Ae : e === Te, e === xt);
1560
- }
1561
- function fo(e, t) {
1562
- const {
1563
- open: n,
1564
- onOpenChange: r,
1565
- elements: o
1566
- } = e, {
1567
- listRef: i,
1568
- activeIndex: s,
1569
- onNavigate: a = () => {
1570
- },
1571
- enabled: l = !0,
1572
- selectedIndex: u = null,
1573
- allowEscape: p = !1,
1574
- loop: f = !1,
1575
- nested: v = !1,
1576
- rtl: d = !1,
1577
- virtual: m = !1,
1578
- focusItemOnOpen: h = "auto",
1579
- focusItemOnHover: P = !0,
1580
- openOnArrowKeyDown: N = !0,
1581
- disabledIndices: L = void 0,
1582
- orientation: g = "vertical",
1583
- cols: C = 1,
1584
- scrollItemIntoView: z = !0,
1585
- virtualItemRef: k,
1586
- itemSizes: U,
1587
- dense: K = !1
1588
- } = t;
1589
- process.env.NODE_ENV !== "production" && (p && (f || ct("`useListNavigation` looping must be enabled to allow escaping."), m || ct("`useListNavigation` must be virtual to allow escaping.")), g === "vertical" && C > 1 && ct("In grid list navigation mode (`cols` > 1), the `orientation` should", 'be either "horizontal" or "both".'));
1590
- const ue = hn(o.floating), Z = xe(ue), H = yt(), y = nt(), D = se(a), S = c.useRef(h), b = c.useRef(u ?? -1), T = c.useRef(null), F = c.useRef(!0), w = c.useRef(D), R = c.useRef(!!o.floating), V = c.useRef(n), Y = c.useRef(!1), fe = c.useRef(!1), ce = xe(L), A = xe(n), I = xe(z), x = xe(u), [O, $] = c.useState(), [G, J] = c.useState(), q = se(function(M, W, E) {
1591
- E === void 0 && (E = !1);
1592
- function _(B) {
1593
- m ? ($(B.id), y?.events.emit("virtualfocus", B), k && (k.current = B)) : he(B, {
1594
- preventScroll: !0,
1595
- // Mac Safari does not move the virtual cursor unless the focus call
1596
- // is sync. However, for the very first focus call, we need to wait
1597
- // for the position to be ready in order to prevent unwanted
1598
- // scrolling. This means the virtual cursor will not move to the first
1599
- // item when first opening the floating element, but will on
1600
- // subsequent calls. `preventScroll` is supported in modern Safari,
1601
- // so we can use that instead.
1602
- // iOS Safari must be async or the first item will not be focused.
1603
- sync: _n() && rn() ? Ht || Y.current : !1
1604
- });
1605
- }
1606
- const ne = M.current[W.current];
1607
- ne && _(ne), requestAnimationFrame(() => {
1608
- const B = M.current[W.current] || ne;
1609
- if (!B) return;
1610
- ne || _(B);
1611
- const le = I.current;
1612
- le && pe && (E || !F.current) && (B.scrollIntoView == null || B.scrollIntoView(typeof le == "boolean" ? {
1613
- block: "nearest",
1614
- inline: "nearest"
1615
- } : le));
1616
- });
1617
- });
1618
- j(() => {
1619
- document.createElement("div").focus({
1620
- get preventScroll() {
1621
- return Ht = !0, !1;
1622
- }
1623
- });
1624
- }, []), j(() => {
1625
- l && (n && o.floating ? S.current && u != null && (fe.current = !0, b.current = u, D(u)) : R.current && (b.current = -1, w.current(null)));
1626
- }, [l, n, o.floating, u, D]), j(() => {
1627
- if (l && n && o.floating)
1628
- if (s == null) {
1629
- if (Y.current = !1, x.current != null)
1630
- return;
1631
- if (R.current && (b.current = -1, q(i, b)), (!V.current || !R.current) && S.current && (T.current != null || S.current === !0 && T.current == null)) {
1632
- let M = 0;
1633
- const W = () => {
1634
- i.current[0] == null ? (M < 2 && (M ? requestAnimationFrame : queueMicrotask)(W), M++) : (b.current = T.current == null || dt(T.current, g, d) || v ? ut(i, ce.current) : Pt(i, ce.current), T.current = null, D(b.current));
1635
- };
1636
- W();
1637
- }
1638
- } else De(i, s) || (b.current = s, q(i, b, fe.current), fe.current = !1);
1639
- }, [l, n, o.floating, s, x, v, i, g, d, D, q, ce]), j(() => {
1640
- var M;
1641
- if (!l || o.floating || !y || m || !R.current)
1642
- return;
1643
- const W = y.nodesRef.current, E = (M = W.find((B) => B.id === H)) == null || (M = M.context) == null ? void 0 : M.elements.floating, _ = me(re(o.floating)), ne = W.some((B) => B.context && Q(B.context.elements.floating, _));
1644
- E && !ne && F.current && E.focus({
1645
- preventScroll: !0
1646
- });
1647
- }, [l, o.floating, y, H, m]), j(() => {
1648
- if (!l || !y || !m || H) return;
1649
- function M(W) {
1650
- J(W.id), k && (k.current = W);
1651
- }
1652
- return y.events.on("virtualfocus", M), () => {
1653
- y.events.off("virtualfocus", M);
1654
- };
1655
- }, [l, y, m, H, k]), j(() => {
1656
- w.current = D, R.current = !!o.floating;
1657
- }), j(() => {
1658
- n || (T.current = null);
1659
- }, [n]), j(() => {
1660
- V.current = n;
1661
- }, [n]);
1662
- const ye = s != null, pe = c.useMemo(() => {
1663
- function M(E) {
1664
- if (!n) return;
1665
- const _ = i.current.indexOf(E);
1666
- _ !== -1 && D(_);
1667
- }
1668
- return {
1669
- onFocus(E) {
1670
- let {
1671
- currentTarget: _
1672
- } = E;
1673
- M(_);
1674
- },
1675
- onClick: (E) => {
1676
- let {
1677
- currentTarget: _
1678
- } = E;
1679
- return _.focus({
1680
- preventScroll: !0
1681
- });
1682
- },
1683
- // Safari
1684
- ...P && {
1685
- onMouseMove(E) {
1686
- let {
1687
- currentTarget: _
1688
- } = E;
1689
- M(_);
1690
- },
1691
- onPointerLeave(E) {
1692
- let {
1693
- pointerType: _
1694
- } = E;
1695
- !F.current || _ === "touch" || (b.current = -1, q(i, b), D(null), m || he(Z.current, {
1696
- preventScroll: !0
1697
- }));
1698
- }
1699
- }
1700
- };
1701
- }, [n, Z, q, P, i, D, m]), te = se((M) => {
1702
- if (F.current = !1, Y.current = !0, !A.current && M.currentTarget === Z.current)
1703
- return;
1704
- if (v && Ut(M.key, g, d)) {
1705
- ee(M), r(!1, M.nativeEvent, "list-navigation"), de(o.domReference) && !m && o.domReference.focus();
1706
- return;
1707
- }
1708
- const W = b.current, E = ut(i, L), _ = Pt(i, L);
1709
- if (M.key === "Home" && (ee(M), b.current = E, D(b.current)), M.key === "End" && (ee(M), b.current = _, D(b.current)), C > 1) {
1710
- const ne = U || Array.from({
1711
- length: i.current.length
1712
- }, () => ({
1713
- width: 1,
1714
- height: 1
1715
- })), B = pr(ne, C, K), le = B.findIndex((ie) => ie != null && !ze(i.current, ie, L)), Be = B.reduce((ie, ge, $e) => ge != null && !ze(i.current, ge, L) ? $e : ie, -1), Ne = B[mr({
1716
- current: B.map((ie) => ie != null ? i.current[ie] : null)
1717
- }, {
1718
- event: M,
1719
- orientation: g,
1720
- loop: f,
1721
- cols: C,
1722
- // treat undefined (empty grid spaces) as disabled indices so we
1723
- // don't end up in them
1724
- disabledIndices: gr([...L || i.current.map((ie, ge) => ze(i.current, ge) ? ge : void 0), void 0], B),
1725
- minIndex: le,
1726
- maxIndex: Be,
1727
- prevIndex: br(
1728
- b.current > _ ? E : b.current,
1729
- ne,
1730
- B,
1731
- C,
1732
- // use a corner matching the edge closest to the direction
1733
- // we're moving in so we don't end up in the same item. Prefer
1734
- // top/left over bottom/right.
1735
- M.key === Ke ? "bl" : M.key === Ae ? "tr" : "tl"
1736
- ),
1737
- stopEvent: !0
1738
- })];
1739
- if (Ne != null && (b.current = Ne, D(b.current)), g === "both")
1740
- return;
1741
- }
1742
- if (jt(M.key, g)) {
1743
- if (ee(M), n && !m && me(M.currentTarget.ownerDocument) === M.currentTarget) {
1744
- b.current = dt(M.key, g, d) ? E : _, D(b.current);
1745
- return;
1746
- }
1747
- dt(M.key, g, d) ? f ? b.current = W >= _ ? p && W !== i.current.length ? -1 : E : X(i, {
1748
- startingIndex: W,
1749
- disabledIndices: L
1750
- }) : b.current = Math.min(_, X(i, {
1751
- startingIndex: W,
1752
- disabledIndices: L
1753
- })) : f ? b.current = W <= E ? p && W !== -1 ? i.current.length : _ : X(i, {
1754
- startingIndex: W,
1755
- decrement: !0,
1756
- disabledIndices: L
1757
- }) : b.current = Math.max(E, X(i, {
1758
- startingIndex: W,
1759
- decrement: !0,
1760
- disabledIndices: L
1761
- })), De(i, b.current) ? D(null) : D(b.current);
1762
- }
1763
- }), be = c.useMemo(() => m && n && ye && {
1764
- "aria-activedescendant": G || O
1765
- }, [m, n, ye, G, O]), ae = c.useMemo(() => ({
1766
- "aria-orientation": g === "both" ? void 0 : g,
1767
- ...!on(o.domReference) && be,
1768
- onKeyDown: te,
1769
- onPointerMove() {
1770
- F.current = !0;
1771
- }
1772
- }), [be, te, o.domReference, g]), Pe = c.useMemo(() => {
1773
- function M(E) {
1774
- h === "auto" && tn(E.nativeEvent) && (S.current = !0);
1775
- }
1776
- function W(E) {
1777
- S.current = h, h === "auto" && nn(E.nativeEvent) && (S.current = !0);
1778
- }
1779
- return {
1780
- ...be,
1781
- onKeyDown(E) {
1782
- F.current = !1;
1783
- const _ = E.key.indexOf("Arrow") === 0, ne = Vr(E.key, g, d), B = Ut(E.key, g, d), le = jt(E.key, g), Be = (v ? ne : le) || E.key === "Enter" || E.key.trim() === "";
1784
- if (m && n) {
1785
- const $e = y?.nodesRef.current.find((We) => We.parentId == null), ve = y && $e ? Cr(y.nodesRef.current, $e.id) : null;
1786
- if (_ && ve && k) {
1787
- const We = new KeyboardEvent("keydown", {
1788
- key: E.key,
1789
- bubbles: !0
1790
- });
1791
- if (ne || B) {
1792
- var Ne, ie;
1793
- const Rn = ((Ne = ve.context) == null ? void 0 : Ne.elements.domReference) === E.currentTarget, wt = B && !Rn ? (ie = ve.context) == null ? void 0 : ie.elements.domReference : ne ? i.current.find((Ct) => Ct?.id === O) : null;
1794
- wt && (ee(E), wt.dispatchEvent(We), J(void 0));
1795
- }
1796
- if (le && ve.context && ve.context.open && ve.parentId && E.currentTarget !== ve.context.elements.domReference) {
1797
- var ge;
1798
- ee(E), (ge = ve.context.elements.domReference) == null || ge.dispatchEvent(We);
1799
- return;
1800
- }
1801
- }
1802
- return te(E);
1803
- }
1804
- if (!(!n && !N && _)) {
1805
- if (Be && (T.current = v && le ? null : E.key), v) {
1806
- ne && (ee(E), n ? (b.current = ut(i, ce.current), D(b.current)) : r(!0, E.nativeEvent, "list-navigation"));
1807
- return;
1808
- }
1809
- le && (u != null && (b.current = u), ee(E), !n && N ? r(!0, E.nativeEvent, "list-navigation") : te(E), n && D(b.current));
1810
- }
1811
- },
1812
- onFocus() {
1813
- n && !m && D(null);
1814
- },
1815
- onPointerDown: W,
1816
- onMouseDown: M,
1817
- onClick: M
1818
- };
1819
- }, [O, be, te, ce, h, i, v, D, r, n, N, g, d, u, y, m, k]);
1820
- return c.useMemo(() => l ? {
1821
- reference: Pe,
1822
- floating: ae,
1823
- item: pe
1824
- } : {}, [l, Pe, ae, pe]);
1825
- }
1826
- const _r = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", !1]]);
1827
- function mo(e, t) {
1828
- var n;
1829
- t === void 0 && (t = {});
1830
- const {
1831
- open: r,
1832
- floatingId: o
1833
- } = e, {
1834
- enabled: i = !0,
1835
- role: s = "dialog"
1836
- } = t, a = (n = _r.get(s)) != null ? n : s, l = Et(), p = yt() != null, f = c.useMemo(() => a === "tooltip" || s === "label" ? {
1837
- ["aria-" + (s === "label" ? "labelledby" : "describedby")]: r ? o : void 0
1838
- } : {
1839
- "aria-expanded": r ? "true" : "false",
1840
- "aria-haspopup": a === "alertdialog" ? "dialog" : a,
1841
- "aria-controls": r ? o : void 0,
1842
- ...a === "listbox" && {
1843
- role: "combobox"
1844
- },
1845
- ...a === "menu" && {
1846
- id: l
1847
- },
1848
- ...a === "menu" && p && {
1849
- role: "menuitem"
1850
- },
1851
- ...s === "select" && {
1852
- "aria-autocomplete": "none"
1853
- },
1854
- ...s === "combobox" && {
1855
- "aria-autocomplete": "list"
1856
- }
1857
- }, [a, o, p, r, l, s]), v = c.useMemo(() => {
1858
- const m = {
1859
- id: o,
1860
- ...a && {
1861
- role: a
1862
- }
1863
- };
1864
- return a === "tooltip" || s === "label" ? m : {
1865
- ...m,
1866
- ...a === "menu" && {
1867
- "aria-labelledby": l
1868
- }
1869
- };
1870
- }, [a, o, l, s]), d = c.useCallback((m) => {
1871
- let {
1872
- active: h,
1873
- selected: P
1874
- } = m;
1875
- const N = {
1876
- role: "option",
1877
- ...h && {
1878
- id: o + "-option"
1879
- }
1880
- };
1881
- switch (s) {
1882
- case "select":
1883
- return {
1884
- ...N,
1885
- "aria-selected": h && P
1886
- };
1887
- case "combobox":
1888
- return {
1889
- ...N,
1890
- ...h && {
1891
- "aria-selected": !0
1892
- }
1893
- };
1894
- }
1895
- return {};
1896
- }, [o, s]);
1897
- return c.useMemo(() => i ? {
1898
- reference: f,
1899
- floating: v,
1900
- item: d
1901
- } : {}, [i, f, v, d]);
1902
- }
1903
- const Kr = vt(void 0), xn = vt({
1904
- activeIndex: 0
1905
- }), Br = (e, t) => t.type === "SET_ACTIVE_INDEX" ? {
1906
- ...e,
1907
- activeIndex: t.payload
1908
- } : e, En = vt(() => {
1909
- throw new Error("ComboboxIdDispatch must be used within a provider");
1910
- }), po = ({ children: e }) => {
1911
- const [t, n] = wn(Br, {
1912
- activeIndex: 0
1913
- });
1914
- return Ee(xn.Provider, { value: t, children: Ee(En.Provider, { value: n, children: e }) });
1915
- };
1916
- function bo() {
1917
- return ht(En);
1918
- }
1919
- function $r() {
1920
- return ht(xn);
1921
- }
1922
- const Wr = Ve(({ asChild: e, interactive: t, id: n, className: r, ...o }, i) => {
1923
- if (t && !n)
1924
- throw new Error("If ComboboxCustom is interactive, it must have an id");
1925
- const s = e ? Nn : "div", a = Cn(), { activeIndex: l } = $r(), u = ht(Kr);
1926
- if (!u)
1927
- throw new Error("ComboboxCustom must be used within a Combobox");
1928
- const { customIds: p, setListRef: f, getItemProps: v, size: d } = u, m = Sn(() => n && p.indexOf(n) || 0, [n, p]), h = lr([
1929
- (P) => {
1930
- f(m, P);
1931
- },
1932
- i
1933
- ]);
1934
- return Ee(Dn, { "data-size": d, asChild: !0, children: Ee(s, { ref: h, tabIndex: -1, className: zt("ds-combobox__custom", r), id: n || a, role: "option", "aria-selected": l === m, "data-active": l === m, ...St(["interactive"], o), ...St(["onClick", "onPointerLeave"], v()) }) });
1935
- });
1936
- function qr(e) {
1937
- return Tn(e) && e.type === Wr;
1938
- }
1939
- function go(e) {
1940
- return qr(e) && e.props.interactive === !0;
1941
- }
1942
- const yn = "internal-option-", vo = (e) => yn + e, ho = (e) => e.slice(yn.length), Hr = (e, t) => {
1943
- const n = e.value;
1944
- e.value = t;
1945
- const r = e._valueTracker;
1946
- typeof r < "u" && r.setValue(n), e.dispatchEvent(new Event("change", { bubbles: !0 }));
1947
- }, jr = Ve(function({ className: t, ...n }, r) {
1948
- return Ee("div", { ref: r, className: zt("ds-search", t), ...n });
1949
- }), Ur = Ve(function({ children: t = "Søk", ...n }, r) {
1950
- return Ee(Xt, { ref: r, type: "submit", ...n, children: t });
1951
- }), zr = Ve(function({ "aria-label": t = "Tøm", onClick: n, ...r }, o) {
1952
- return Ee(Xt, { ref: o, variant: "tertiary", type: "reset", "aria-label": t, onClick: (s) => {
1953
- const a = s.target;
1954
- let l = null;
1955
- if (a instanceof HTMLElement && (l = a.closest(".ds-search")?.querySelector("input")), !l)
1956
- throw new Error("Input is missing");
1957
- if (!(l instanceof HTMLInputElement))
1958
- throw new Error("Input is not an input element");
1959
- s.preventDefault(), Hr(l, ""), l.focus(), n?.(s);
1960
- }, icon: !0, ...r });
1961
- }), Gr = Ve(function({ ...t }, n) {
1962
- return Ee(Fn, {
1963
- ref: n,
1964
- type: "search",
1965
- /* We need an empty placeholder for the clear button to be able to show/hide */
1966
- placeholder: "",
1967
- ...t
1968
- });
1969
- }), It = Object.assign(jr, {
1970
- Clear: zr,
1971
- Button: Ur,
1972
- Input: Gr
1973
- });
1974
- It.Clear.displayName = "Search.Clear";
1975
- It.Button.displayName = "Search.Button";
1976
- It.Input.displayName = "Search.Input";
1977
- export {
1978
- Kr as C,
1979
- so as F,
1980
- It as S,
1981
- lr as a,
1982
- $r as b,
1983
- ao as c,
1984
- ro as d,
1985
- mo as e,
1986
- oo as f,
1987
- co as g,
1988
- fo as h,
1989
- go as i,
1990
- lo as j,
1991
- po as k,
1992
- Hr as l,
1993
- uo as m,
1994
- Wr as n,
1995
- St as o,
1996
- vo as p,
1997
- ho as r,
1998
- io as s,
1999
- bo as u
2000
- };