@kakadu/components 2.2.1 → 2.3.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 (39) hide show
  1. package/build/components/button-tooltip.d.ts +2 -1
  2. package/build/components/button-tooltip.js +1 -1
  3. package/build/components/button-tooltip.mjs +7 -6
  4. package/build/components/button.js +1 -1
  5. package/build/components/button.mjs +44 -44
  6. package/build/components/collapsible.js +1 -1
  7. package/build/components/collapsible.mjs +12 -12
  8. package/build/components/icon-button.js +1 -1
  9. package/build/components/icon-button.mjs +29 -29
  10. package/build/components/modal.d.ts +3 -2
  11. package/build/components/modal.js +1 -9
  12. package/build/components/modal.mjs +105 -1226
  13. package/build/components/moving-gradients.js +1 -1
  14. package/build/components/moving-gradients.mjs +2 -2
  15. package/build/components/moving-stars.js +1 -1
  16. package/build/components/moving-stars.mjs +17 -17
  17. package/build/components/notification.js +1 -1
  18. package/build/components/notification.mjs +12 -12
  19. package/build/components/popover-menu.d.ts +19 -0
  20. package/build/components/popover-menu.js +1 -0
  21. package/build/components/popover-menu.mjs +68 -0
  22. package/build/components/popover.d.ts +26 -0
  23. package/build/components/popover.js +1 -0
  24. package/build/components/popover.mjs +95 -0
  25. package/build/components/skeleton.js +1 -1
  26. package/build/components/skeleton.mjs +23 -23
  27. package/build/components/spinner.js +1 -1
  28. package/build/components/spinner.mjs +1 -1
  29. package/build/components/text-button.js +1 -1
  30. package/build/components/text-button.mjs +14 -14
  31. package/build/components.css +1 -1
  32. package/build/focus-trap-react-CcpTuiJi.js +9 -0
  33. package/build/focus-trap-react-DYXrtbDH.mjs +1130 -0
  34. package/build/icons/icon.js +1 -1
  35. package/build/icons/icon.mjs +11 -11
  36. package/build/index.d.ts +4 -0
  37. package/build/index.js +1 -1
  38. package/build/index.mjs +161 -154
  39. package/package.json +1 -1
@@ -1,1253 +1,132 @@
1
- import { j as N } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import Ie, { createContext as Ae, useRef as te, useState as re, useCallback as J, useMemo as ne, useEffect as H, useContext as xe } from "react";
3
- import { cx as de } from "@kuma-ui/core";
4
- import { createPortal as _e } from "react-dom";
5
- import { IconType as Le } from "../icons/icon.mjs";
6
- import Be from "./text-button.mjs";
7
- function ke(r) {
8
- if (Object.prototype.hasOwnProperty.call(r, "__esModule")) return r;
9
- var e = r.default;
10
- if (typeof e == "function") {
11
- var t = function a() {
12
- return this instanceof a ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
13
- };
14
- t.prototype = e.prototype;
15
- } else t = {};
16
- return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(r).forEach(function(a) {
17
- var s = Object.getOwnPropertyDescriptor(r, a);
18
- Object.defineProperty(t, a, s.get ? s : {
19
- enumerable: !0,
20
- get: function() {
21
- return r[a];
22
- }
23
- });
24
- }), t;
25
- }
26
- var Q = { exports: {} };
27
- /*!
28
- * tabbable 6.4.0
29
- * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
30
- */
31
- var Ee = ["input:not([inert]):not([inert] *)", "select:not([inert]):not([inert] *)", "textarea:not([inert]):not([inert] *)", "a[href]:not([inert]):not([inert] *)", "button:not([inert]):not([inert] *)", "[tabindex]:not(slot):not([inert]):not([inert] *)", "audio[controls]:not([inert]):not([inert] *)", "video[controls]:not([inert]):not([inert] *)", '[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)', "details>summary:first-of-type:not([inert]):not([inert] *)", "details:not([inert]):not([inert] *)"], ie = /* @__PURE__ */ Ee.join(","), Fe = typeof Element > "u", W = Fe ? function() {
32
- } : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector, oe = !Fe && Element.prototype.getRootNode ? function(r) {
33
- var e;
34
- return r == null || (e = r.getRootNode) === null || e === void 0 ? void 0 : e.call(r);
35
- } : function(r) {
36
- return r == null ? void 0 : r.ownerDocument;
37
- }, ue = function(e, t) {
38
- var a;
39
- t === void 0 && (t = !0);
40
- var s = e == null || (a = e.getAttribute) === null || a === void 0 ? void 0 : a.call(e, "inert"), c = s === "" || s === "true", n = c || t && e && // closest does not exist on shadow roots, so we fall back to a manual
41
- // lookup upward, in case it is not defined.
42
- (typeof e.closest == "function" ? e.closest("[inert]") : ue(e.parentNode));
43
- return n;
44
- }, Me = function(e) {
45
- var t, a = e == null || (t = e.getAttribute) === null || t === void 0 ? void 0 : t.call(e, "contenteditable");
46
- return a === "" || a === "true";
47
- }, Se = function(e, t, a) {
48
- if (ue(e))
49
- return [];
50
- var s = Array.prototype.slice.apply(e.querySelectorAll(ie));
51
- return t && W.call(e, ie) && s.unshift(e), s = s.filter(a), s;
52
- }, se = function(e, t, a) {
53
- for (var s = [], c = Array.from(e); c.length; ) {
54
- var n = c.shift();
55
- if (!ue(n, !1))
56
- if (n.tagName === "SLOT") {
57
- var p = n.assignedElements(), y = p.length ? p : n.children, k = se(y, !0, a);
58
- a.flatten ? s.push.apply(s, k) : s.push({
59
- scopeParent: n,
60
- candidates: k
61
- });
62
- } else {
63
- var S = W.call(n, ie);
64
- S && a.filter(n) && (t || !e.includes(n)) && s.push(n);
65
- var D = n.shadowRoot || // check for an undisclosed shadow
66
- typeof a.getShadowRoot == "function" && a.getShadowRoot(n), R = !ue(D, !1) && (!a.shadowRootFilter || a.shadowRootFilter(n));
67
- if (D && R) {
68
- var A = se(D === !0 ? n.children : D.children, !0, a);
69
- a.flatten ? s.push.apply(s, A) : s.push({
70
- scopeParent: n,
71
- candidates: A
72
- });
73
- } else
74
- c.unshift.apply(c, n.children);
75
- }
76
- }
77
- return s;
78
- }, Oe = function(e) {
79
- return !isNaN(parseInt(e.getAttribute("tabindex"), 10));
80
- }, K = function(e) {
81
- if (!e)
82
- throw new Error("No node provided");
83
- return e.tabIndex < 0 && (/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName) || Me(e)) && !Oe(e) ? 0 : e.tabIndex;
84
- }, Ke = function(e, t) {
85
- var a = K(e);
86
- return a < 0 && t && !Oe(e) ? 0 : a;
87
- }, qe = function(e, t) {
88
- return e.tabIndex === t.tabIndex ? e.documentOrder - t.documentOrder : e.tabIndex - t.tabIndex;
89
- }, De = function(e) {
90
- return e.tagName === "INPUT";
91
- }, Ve = function(e) {
92
- return De(e) && e.type === "hidden";
93
- }, $e = function(e) {
94
- var t = e.tagName === "DETAILS" && Array.prototype.slice.apply(e.children).some(function(a) {
95
- return a.tagName === "SUMMARY";
96
- });
97
- return t;
98
- }, Ge = function(e, t) {
99
- for (var a = 0; a < e.length; a++)
100
- if (e[a].checked && e[a].form === t)
101
- return e[a];
102
- }, Ue = function(e) {
103
- if (!e.name)
104
- return !0;
105
- var t = e.form || oe(e), a = function(p) {
106
- return t.querySelectorAll('input[type="radio"][name="' + p + '"]');
107
- }, s;
108
- if (typeof window < "u" && typeof window.CSS < "u" && typeof window.CSS.escape == "function")
109
- s = a(window.CSS.escape(e.name));
110
- else
111
- try {
112
- s = a(e.name);
113
- } catch (n) {
114
- 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", n.message), !1;
115
- }
116
- var c = Ge(s, e.form);
117
- return !c || c === e;
118
- }, ze = function(e) {
119
- return De(e) && e.type === "radio";
120
- }, We = function(e) {
121
- return ze(e) && !Ue(e);
122
- }, Ye = function(e) {
123
- var t, a = e && oe(e), s = (t = a) === null || t === void 0 ? void 0 : t.host, c = !1;
124
- if (a && a !== e) {
125
- var n, p, y;
126
- for (c = !!((n = s) !== null && n !== void 0 && (p = n.ownerDocument) !== null && p !== void 0 && p.contains(s) || e != null && (y = e.ownerDocument) !== null && y !== void 0 && y.contains(e)); !c && s; ) {
127
- var k, S, D;
128
- a = oe(s), s = (k = a) === null || k === void 0 ? void 0 : k.host, c = !!((S = s) !== null && S !== void 0 && (D = S.ownerDocument) !== null && D !== void 0 && D.contains(s));
129
- }
130
- }
131
- return c;
132
- }, be = function(e) {
133
- var t = e.getBoundingClientRect(), a = t.width, s = t.height;
134
- return a === 0 && s === 0;
135
- }, He = function(e, t) {
136
- var a = t.displayCheck, s = t.getShadowRoot;
137
- if (a === "full-native" && "checkVisibility" in e) {
138
- var c = e.checkVisibility({
139
- // Checking opacity might be desirable for some use cases, but natively,
140
- // opacity zero elements _are_ focusable and tabbable.
141
- checkOpacity: !1,
142
- opacityProperty: !1,
143
- contentVisibilityAuto: !0,
144
- visibilityProperty: !0,
145
- // This is an alias for `visibilityProperty`. Contemporary browsers
146
- // support both. However, this alias has wider browser support (Chrome
147
- // >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
148
- // we include it anyway.
149
- checkVisibilityCSS: !0
150
- });
151
- return !c;
152
- }
153
- if (getComputedStyle(e).visibility === "hidden")
154
- return !0;
155
- var n = W.call(e, "details>summary:first-of-type"), p = n ? e.parentElement : e;
156
- if (W.call(p, "details:not([open]) *"))
157
- return !0;
158
- if (!a || a === "full" || // full-native can run this branch when it falls through in case
159
- // Element#checkVisibility is unsupported
160
- a === "full-native" || a === "legacy-full") {
161
- if (typeof s == "function") {
162
- for (var y = e; e; ) {
163
- var k = e.parentElement, S = oe(e);
164
- if (k && !k.shadowRoot && s(k) === !0)
165
- return be(e);
166
- e.assignedSlot ? e = e.assignedSlot : !k && S !== e.ownerDocument ? e = S.host : e = k;
167
- }
168
- e = y;
169
- }
170
- if (Ye(e))
171
- return !e.getClientRects().length;
172
- if (a !== "legacy-full")
173
- return !0;
174
- } else if (a === "non-zero-area")
175
- return be(e);
176
- return !1;
177
- }, Ze = function(e) {
178
- if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))
179
- for (var t = e.parentElement; t; ) {
180
- if (t.tagName === "FIELDSET" && t.disabled) {
181
- for (var a = 0; a < t.children.length; a++) {
182
- var s = t.children.item(a);
183
- if (s.tagName === "LEGEND")
184
- return W.call(t, "fieldset[disabled] *") ? !0 : !s.contains(e);
185
- }
186
- return !0;
187
- }
188
- t = t.parentElement;
189
- }
190
- return !1;
191
- }, ce = function(e, t) {
192
- return !(t.disabled || Ve(t) || He(t, e) || // For a details element with a summary, the summary element gets the focus
193
- $e(t) || Ze(t));
194
- }, ve = function(e, t) {
195
- return !(We(t) || K(t) < 0 || !ce(e, t));
196
- }, Xe = function(e) {
197
- var t = parseInt(e.getAttribute("tabindex"), 10);
198
- return !!(isNaN(t) || t >= 0);
199
- }, Ne = function(e) {
200
- var t = [], a = [];
201
- return e.forEach(function(s, c) {
202
- var n = !!s.scopeParent, p = n ? s.scopeParent : s, y = Ke(p, n), k = n ? Ne(s.candidates) : p;
203
- y === 0 ? n ? t.push.apply(t, k) : t.push(p) : a.push({
204
- documentOrder: c,
205
- tabIndex: y,
206
- item: s,
207
- isScope: n,
208
- content: k
209
- });
210
- }), a.sort(qe).reduce(function(s, c) {
211
- return c.isScope ? s.push.apply(s, c.content) : s.push(c.content), s;
212
- }, []).concat(t);
213
- }, Re = function(e, t) {
214
- t = t || {};
215
- var a;
216
- return t.getShadowRoot ? a = se([e], t.includeContainer, {
217
- filter: ve.bind(null, t),
218
- flatten: !1,
219
- getShadowRoot: t.getShadowRoot,
220
- shadowRootFilter: Xe
221
- }) : a = Se(e, t.includeContainer, ve.bind(null, t)), Ne(a);
222
- }, Pe = function(e, t) {
223
- t = t || {};
224
- var a;
225
- return t.getShadowRoot ? a = se([e], t.includeContainer, {
226
- filter: ce.bind(null, t),
227
- flatten: !0,
228
- getShadowRoot: t.getShadowRoot
229
- }) : a = Se(e, t.includeContainer, ce.bind(null, t)), a;
230
- }, z = function(e, t) {
231
- if (t = t || {}, !e)
232
- throw new Error("No node provided");
233
- return W.call(e, ie) === !1 ? !1 : ve(t, e);
234
- }, Je = /* @__PURE__ */ Ee.concat("iframe:not([inert]):not([inert] *)").join(","), ae = function(e, t) {
235
- if (t = t || {}, !e)
236
- throw new Error("No node provided");
237
- return W.call(e, Je) === !1 ? !1 : ce(t, e);
238
- };
239
- const Qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
240
- __proto__: null,
241
- focusable: Pe,
242
- getTabIndex: K,
243
- isFocusable: ae,
244
- isTabbable: z,
245
- tabbable: Re
246
- }, Symbol.toStringTag, { value: "Module" }));
247
- /*!
248
- * focus-trap 7.8.0
249
- * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
250
- */
251
- function pe(r, e) {
252
- (e == null || e > r.length) && (e = r.length);
253
- for (var t = 0, a = Array(e); t < e; t++) a[t] = r[t];
254
- return a;
255
- }
256
- function et(r) {
257
- if (Array.isArray(r)) return pe(r);
258
- }
259
- function he(r, e) {
260
- var t = typeof Symbol < "u" && r[Symbol.iterator] || r["@@iterator"];
261
- if (!t) {
262
- if (Array.isArray(r) || (t = Ce(r)) || e) {
263
- t && (r = t);
264
- var a = 0, s = function() {
265
- };
266
- return {
267
- s,
268
- n: function() {
269
- return a >= r.length ? {
270
- done: !0
271
- } : {
272
- done: !1,
273
- value: r[a++]
274
- };
275
- },
276
- e: function(y) {
277
- throw y;
278
- },
279
- f: s
280
- };
281
- }
282
- throw new TypeError(`Invalid attempt to iterate non-iterable instance.
283
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
284
- }
285
- var c, n = !0, p = !1;
286
- return {
287
- s: function() {
288
- t = t.call(r);
289
- },
290
- n: function() {
291
- var y = t.next();
292
- return n = y.done, y;
293
- },
294
- e: function(y) {
295
- p = !0, c = y;
296
- },
297
- f: function() {
298
- try {
299
- n || t.return == null || t.return();
300
- } finally {
301
- if (p) throw c;
302
- }
303
- }
304
- };
305
- }
306
- function tt(r, e, t) {
307
- return (e = ot(e)) in r ? Object.defineProperty(r, e, {
308
- value: t,
309
- enumerable: !0,
310
- configurable: !0,
311
- writable: !0
312
- }) : r[e] = t, r;
313
- }
314
- function rt(r) {
315
- if (typeof Symbol < "u" && r[Symbol.iterator] != null || r["@@iterator"] != null) return Array.from(r);
316
- }
317
- function at() {
318
- throw new TypeError(`Invalid attempt to spread non-iterable instance.
319
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
320
- }
321
- function ye(r, e) {
322
- var t = Object.keys(r);
323
- if (Object.getOwnPropertySymbols) {
324
- var a = Object.getOwnPropertySymbols(r);
325
- e && (a = a.filter(function(s) {
326
- return Object.getOwnPropertyDescriptor(r, s).enumerable;
327
- })), t.push.apply(t, a);
328
- }
329
- return t;
330
- }
331
- function me(r) {
332
- for (var e = 1; e < arguments.length; e++) {
333
- var t = arguments[e] != null ? arguments[e] : {};
334
- e % 2 ? ye(Object(t), !0).forEach(function(a) {
335
- tt(r, a, t[a]);
336
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(t)) : ye(Object(t)).forEach(function(a) {
337
- Object.defineProperty(r, a, Object.getOwnPropertyDescriptor(t, a));
338
- });
339
- }
340
- return r;
341
- }
342
- function nt(r) {
343
- return et(r) || rt(r) || Ce(r) || at();
344
- }
345
- function it(r, e) {
346
- if (typeof r != "object" || !r) return r;
347
- var t = r[Symbol.toPrimitive];
348
- if (t !== void 0) {
349
- var a = t.call(r, e);
350
- if (typeof a != "object") return a;
351
- throw new TypeError("@@toPrimitive must return a primitive value.");
352
- }
353
- return (e === "string" ? String : Number)(r);
354
- }
355
- function ot(r) {
356
- var e = it(r, "string");
357
- return typeof e == "symbol" ? e : e + "";
358
- }
359
- function Ce(r, e) {
360
- if (r) {
361
- if (typeof r == "string") return pe(r, e);
362
- var t = {}.toString.call(r).slice(8, -1);
363
- return t === "Object" && r.constructor && (t = r.constructor.name), t === "Map" || t === "Set" ? Array.from(r) : t === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? pe(r, e) : void 0;
364
- }
365
- }
366
- var B = {
367
- // Returns the trap from the top of the stack.
368
- getActiveTrap: function(e) {
369
- return (e == null ? void 0 : e.length) > 0 ? e[e.length - 1] : null;
370
- },
371
- // Pauses the currently active trap, then adds a new trap to the stack.
372
- activateTrap: function(e, t) {
373
- var a = B.getActiveTrap(e);
374
- t !== a && B.pauseTrap(e);
375
- var s = e.indexOf(t);
376
- s === -1 || e.splice(s, 1), e.push(t);
377
- },
378
- // Removes the trap from the top of the stack, then unpauses the next trap down.
379
- deactivateTrap: function(e, t) {
380
- var a = e.indexOf(t);
381
- a !== -1 && e.splice(a, 1), B.unpauseTrap(e);
382
- },
383
- // Pauses the trap at the top of the stack.
384
- pauseTrap: function(e) {
385
- var t = B.getActiveTrap(e);
386
- t == null || t._setPausedState(!0);
387
- },
388
- // Unpauses the trap at the top of the stack.
389
- unpauseTrap: function(e) {
390
- var t = B.getActiveTrap(e);
391
- t && !t._isManuallyPaused() && t._setPausedState(!1);
392
- }
393
- }, ut = function(e) {
394
- return e.tagName && e.tagName.toLowerCase() === "input" && typeof e.select == "function";
395
- }, st = function(e) {
396
- return (e == null ? void 0 : e.key) === "Escape" || (e == null ? void 0 : e.key) === "Esc" || (e == null ? void 0 : e.keyCode) === 27;
397
- }, X = function(e) {
398
- return (e == null ? void 0 : e.key) === "Tab" || (e == null ? void 0 : e.keyCode) === 9;
399
- }, ct = function(e) {
400
- return X(e) && !e.shiftKey;
401
- }, lt = function(e) {
402
- return X(e) && e.shiftKey;
403
- }, ge = function(e) {
404
- return setTimeout(e, 0);
405
- }, Z = function(e) {
406
- for (var t = arguments.length, a = new Array(t > 1 ? t - 1 : 0), s = 1; s < t; s++)
407
- a[s - 1] = arguments[s];
408
- return typeof e == "function" ? e.apply(void 0, a) : e;
409
- }, ee = function(e) {
410
- return e.target.shadowRoot && typeof e.composedPath == "function" ? e.composedPath()[0] : e.target;
411
- }, ft = [], dt = function(e, t) {
412
- var a = (t == null ? void 0 : t.document) || document, s = (t == null ? void 0 : t.trapStack) || ft, c = me({
413
- returnFocusOnDeactivate: !0,
414
- escapeDeactivates: !0,
415
- delayInitialFocus: !0,
416
- isolateSubtrees: !1,
417
- isKeyForward: ct,
418
- isKeyBackward: lt
419
- }, t), n = {
420
- // containers given to createFocusTrap()
421
- /** @type {Array<HTMLElement>} */
422
- containers: [],
423
- // list of objects identifying tabbable nodes in `containers` in the trap
424
- // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
425
- // is active, but the trap should never get to a state where there isn't at least one group
426
- // with at least one tabbable node in it (that would lead to an error condition that would
427
- // result in an error being thrown)
428
- /** @type {Array<{
429
- * container: HTMLElement,
430
- * tabbableNodes: Array<HTMLElement>, // empty if none
431
- * focusableNodes: Array<HTMLElement>, // empty if none
432
- * posTabIndexesFound: boolean,
433
- * firstTabbableNode: HTMLElement|undefined,
434
- * lastTabbableNode: HTMLElement|undefined,
435
- * firstDomTabbableNode: HTMLElement|undefined,
436
- * lastDomTabbableNode: HTMLElement|undefined,
437
- * nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
438
- * }>}
439
- */
440
- containerGroups: [],
441
- // same order/length as `containers` list
442
- // references to objects in `containerGroups`, but only those that actually have
443
- // tabbable nodes in them
444
- // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
445
- // the same length
446
- tabbableGroups: [],
447
- // references to nodes that are siblings to the ancestors of this trap's containers.
448
- /** @type {Set<HTMLElement>} */
449
- adjacentElements: /* @__PURE__ */ new Set(),
450
- // references to nodes that were inert or aria-hidden before the trap was activated.
451
- /** @type {Set<HTMLElement>} */
452
- alreadySilent: /* @__PURE__ */ new Set(),
453
- nodeFocusedBeforeActivation: null,
454
- mostRecentlyFocusedNode: null,
455
- active: !1,
456
- paused: !1,
457
- manuallyPaused: !1,
458
- // timer ID for when delayInitialFocus is true and initial focus in this trap
459
- // has been delayed during activation
460
- delayInitialFocusTimer: void 0,
461
- // the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any
462
- recentNavEvent: void 0
463
- }, p, y = function(o, i, l) {
464
- return o && o[i] !== void 0 ? o[i] : c[l || i];
465
- }, k = function(o, i) {
466
- var l = typeof (i == null ? void 0 : i.composedPath) == "function" ? i.composedPath() : void 0;
467
- return n.containerGroups.findIndex(function(g) {
468
- var h = g.container, w = g.tabbableNodes;
469
- return h.contains(o) || // fall back to explicit tabbable search which will take into consideration any
470
- // web components if the `tabbableOptions.getShadowRoot` option was used for
471
- // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
472
- // look inside web components even if open)
473
- (l == null ? void 0 : l.includes(h)) || w.find(function(v) {
474
- return v === o;
475
- });
476
- });
477
- }, S = function(o) {
478
- var i = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, l = i.hasFallback, g = l === void 0 ? !1 : l, h = i.params, w = h === void 0 ? [] : h, v = c[o];
479
- if (typeof v == "function" && (v = v.apply(void 0, nt(w))), v === !0 && (v = void 0), !v) {
480
- if (v === void 0 || v === !1)
481
- return v;
482
- throw new Error("`".concat(o, "` was specified but was not a node, or did not return a node"));
483
- }
484
- var E = v;
485
- if (typeof v == "string") {
486
- try {
487
- E = a.querySelector(v);
488
- } catch (F) {
489
- throw new Error("`".concat(o, '` appears to be an invalid selector; error="').concat(F.message, '"'));
490
- }
491
- if (!E && !g)
492
- throw new Error("`".concat(o, "` as selector refers to no known node"));
493
- }
494
- return E;
495
- }, D = function() {
496
- var o = S("initialFocus", {
497
- hasFallback: !0
498
- });
499
- if (o === !1)
500
- return !1;
501
- if (o === void 0 || o && !ae(o, c.tabbableOptions))
502
- if (k(a.activeElement) >= 0)
503
- o = a.activeElement;
504
- else {
505
- var i = n.tabbableGroups[0], l = i && i.firstTabbableNode;
506
- o = l || S("fallbackFocus");
507
- }
508
- else o === null && (o = S("fallbackFocus"));
509
- if (!o)
510
- throw new Error("Your focus-trap needs to have at least one focusable element");
511
- return o;
512
- }, R = function() {
513
- if (n.containerGroups = n.containers.map(function(o) {
514
- var i = Re(o, c.tabbableOptions), l = Pe(o, c.tabbableOptions), g = i.length > 0 ? i[0] : void 0, h = i.length > 0 ? i[i.length - 1] : void 0, w = l.find(function(F) {
515
- return z(F);
516
- }), v = l.slice().reverse().find(function(F) {
517
- return z(F);
518
- }), E = !!i.find(function(F) {
519
- return K(F) > 0;
520
- });
521
- return {
522
- container: o,
523
- tabbableNodes: i,
524
- focusableNodes: l,
525
- /** True if at least one node with positive `tabindex` was found in this container. */
526
- posTabIndexesFound: E,
527
- /** First tabbable node in container, __tabindex__ order; `undefined` if none. */
528
- firstTabbableNode: g,
529
- /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */
530
- lastTabbableNode: h,
531
- // NOTE: DOM order is NOT NECESSARILY "document position" order, but figuring that out
532
- // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
533
- // because that API doesn't work with Shadow DOM as well as it should (@see
534
- // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,
535
- // to address an edge case related to positive tabindex support, this seems like a much easier,
536
- // "close enough most of the time" alternative for positive tabindexes which should generally
537
- // be avoided anyway...
538
- /** First tabbable node in container, __DOM__ order; `undefined` if none. */
539
- firstDomTabbableNode: w,
540
- /** Last tabbable node in container, __DOM__ order; `undefined` if none. */
541
- lastDomTabbableNode: v,
542
- /**
543
- * Finds the __tabbable__ node that follows the given node in the specified direction,
544
- * in this container, if any.
545
- * @param {HTMLElement} node
546
- * @param {boolean} [forward] True if going in forward tab order; false if going
547
- * in reverse.
548
- * @returns {HTMLElement|undefined} The next tabbable node, if any.
549
- */
550
- nextTabbableNode: function(j) {
551
- var _ = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0, x = i.indexOf(j);
552
- return x < 0 ? _ ? l.slice(l.indexOf(j) + 1).find(function(U) {
553
- return z(U);
554
- }) : l.slice(0, l.indexOf(j)).reverse().find(function(U) {
555
- return z(U);
556
- }) : i[x + (_ ? 1 : -1)];
557
- }
558
- };
559
- }), n.tabbableGroups = n.containerGroups.filter(function(o) {
560
- return o.tabbableNodes.length > 0;
561
- }), n.tabbableGroups.length <= 0 && !S("fallbackFocus"))
562
- throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");
563
- if (n.containerGroups.find(function(o) {
564
- return o.posTabIndexesFound;
565
- }) && n.containerGroups.length > 1)
566
- throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.");
567
- }, A = function(o) {
568
- var i = o.activeElement;
569
- if (i)
570
- return i.shadowRoot && i.shadowRoot.activeElement !== null ? A(i.shadowRoot) : i;
571
- }, P = function(o) {
572
- if (o !== !1 && o !== A(document)) {
573
- if (!o || !o.focus) {
574
- P(D());
575
- return;
576
- }
577
- o.focus({
578
- preventScroll: !!c.preventScroll
579
- }), n.mostRecentlyFocusedNode = o, ut(o) && o.select();
580
- }
581
- }, Y = function(o) {
582
- var i = S("setReturnFocus", {
583
- params: [o]
584
- });
585
- return i || (i === !1 ? !1 : o);
586
- }, C = function(o) {
587
- var i = o.target, l = o.event, g = o.isBackward, h = g === void 0 ? !1 : g;
588
- i = i || ee(l), R();
589
- var w = null;
590
- if (n.tabbableGroups.length > 0) {
591
- var v = k(i, l), E = v >= 0 ? n.containerGroups[v] : void 0;
592
- if (v < 0)
593
- h ? w = n.tabbableGroups[n.tabbableGroups.length - 1].lastTabbableNode : w = n.tabbableGroups[0].firstTabbableNode;
594
- else if (h) {
595
- var F = n.tabbableGroups.findIndex(function(le) {
596
- var fe = le.firstTabbableNode;
597
- return i === fe;
598
- });
599
- if (F < 0 && (E.container === i || ae(i, c.tabbableOptions) && !z(i, c.tabbableOptions) && !E.nextTabbableNode(i, !1)) && (F = v), F >= 0) {
600
- var j = F === 0 ? n.tabbableGroups.length - 1 : F - 1, _ = n.tabbableGroups[j];
601
- w = K(i) >= 0 ? _.lastTabbableNode : _.lastDomTabbableNode;
602
- } else X(l) || (w = E.nextTabbableNode(i, !1));
603
- } else {
604
- var x = n.tabbableGroups.findIndex(function(le) {
605
- var fe = le.lastTabbableNode;
606
- return i === fe;
607
- });
608
- if (x < 0 && (E.container === i || ae(i, c.tabbableOptions) && !z(i, c.tabbableOptions) && !E.nextTabbableNode(i)) && (x = v), x >= 0) {
609
- var U = x === n.tabbableGroups.length - 1 ? 0 : x + 1, M = n.tabbableGroups[U];
610
- w = K(i) >= 0 ? M.firstTabbableNode : M.firstDomTabbableNode;
611
- } else X(l) || (w = E.nextTabbableNode(i));
612
- }
613
- } else
614
- w = S("fallbackFocus");
615
- return w;
616
- }, I = function(o) {
617
- var i = ee(o);
618
- if (!(k(i, o) >= 0)) {
619
- if (Z(c.clickOutsideDeactivates, o)) {
620
- p.deactivate({
621
- // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
622
- // which will result in the outside click setting focus to the node
623
- // that was clicked (and if not focusable, to "nothing"); by setting
624
- // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
625
- // on activation (or the configured `setReturnFocus` node), whether the
626
- // outside click was on a focusable node or not
627
- returnFocus: c.returnFocusOnDeactivate
628
- });
629
- return;
630
- }
631
- Z(c.allowOutsideClick, o) || o.preventDefault();
632
- }
633
- }, q = function(o) {
634
- var i = ee(o), l = k(i, o) >= 0;
635
- if (l || i instanceof Document)
636
- l && (n.mostRecentlyFocusedNode = i);
637
- else {
638
- o.stopImmediatePropagation();
639
- var g, h = !0;
640
- if (n.mostRecentlyFocusedNode)
641
- if (K(n.mostRecentlyFocusedNode) > 0) {
642
- var w = k(n.mostRecentlyFocusedNode), v = n.containerGroups[w].tabbableNodes;
643
- if (v.length > 0) {
644
- var E = v.findIndex(function(F) {
645
- return F === n.mostRecentlyFocusedNode;
646
- });
647
- E >= 0 && (c.isKeyForward(n.recentNavEvent) ? E + 1 < v.length && (g = v[E + 1], h = !1) : E - 1 >= 0 && (g = v[E - 1], h = !1));
648
- }
649
- } else
650
- n.containerGroups.some(function(F) {
651
- return F.tabbableNodes.some(function(j) {
652
- return K(j) > 0;
653
- });
654
- }) || (h = !1);
655
- else
656
- h = !1;
657
- h && (g = C({
658
- // move FROM the MRU node, not event-related node (which will be the node that is
659
- // outside the trap causing the focus escape we're trying to fix)
660
- target: n.mostRecentlyFocusedNode,
661
- isBackward: c.isKeyBackward(n.recentNavEvent)
662
- })), P(g || n.mostRecentlyFocusedNode || D());
663
- }
664
- n.recentNavEvent = void 0;
665
- }, V = function(o) {
666
- var i = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1;
667
- n.recentNavEvent = o;
668
- var l = C({
669
- event: o,
670
- isBackward: i
671
- });
672
- l && (X(o) && o.preventDefault(), P(l));
673
- }, $ = function(o) {
674
- (c.isKeyForward(o) || c.isKeyBackward(o)) && V(o, c.isKeyBackward(o));
675
- }, G = function(o) {
676
- st(o) && Z(c.escapeDeactivates, o) !== !1 && (o.preventDefault(), p.deactivate());
677
- }, L = function(o) {
678
- var i = ee(o);
679
- k(i, o) >= 0 || Z(c.clickOutsideDeactivates, o) || Z(c.allowOutsideClick, o) || (o.preventDefault(), o.stopImmediatePropagation());
680
- }, d = function() {
681
- if (n.active)
682
- return B.activateTrap(s, p), n.delayInitialFocusTimer = c.delayInitialFocus ? ge(function() {
683
- P(D());
684
- }) : P(D()), a.addEventListener("focusin", q, !0), a.addEventListener("mousedown", I, {
685
- capture: !0,
686
- passive: !1
687
- }), a.addEventListener("touchstart", I, {
688
- capture: !0,
689
- passive: !1
690
- }), a.addEventListener("click", L, {
691
- capture: !0,
692
- passive: !1
693
- }), a.addEventListener("keydown", $, {
694
- capture: !0,
695
- passive: !1
696
- }), a.addEventListener("keydown", G), p;
697
- }, f = function(o) {
698
- n.active && !n.paused && p._setSubtreeIsolation(!1), n.adjacentElements.clear(), n.alreadySilent.clear();
699
- var i = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), g = he(o), h;
700
- try {
701
- for (g.s(); !(h = g.n()).done; ) {
702
- var w = h.value;
703
- i.add(w);
704
- for (var v = typeof ShadowRoot < "u" && w.getRootNode() instanceof ShadowRoot, E = w; E; ) {
705
- i.add(E);
706
- var F = E.parentElement, j = [];
707
- F ? j = F.children : !F && v && (j = E.getRootNode().children, F = E.getRootNode().host, v = typeof ShadowRoot < "u" && F.getRootNode() instanceof ShadowRoot);
708
- var _ = he(j), x;
709
- try {
710
- for (_.s(); !(x = _.n()).done; ) {
711
- var U = x.value;
712
- l.add(U);
713
- }
714
- } catch (M) {
715
- _.e(M);
716
- } finally {
717
- _.f();
718
- }
719
- E = F;
720
- }
721
- }
722
- } catch (M) {
723
- g.e(M);
724
- } finally {
725
- g.f();
726
- }
727
- i.forEach(function(M) {
728
- l.delete(M);
729
- }), n.adjacentElements = l;
730
- }, m = function() {
731
- if (n.active)
732
- return a.removeEventListener("focusin", q, !0), a.removeEventListener("mousedown", I, !0), a.removeEventListener("touchstart", I, !0), a.removeEventListener("click", L, !0), a.removeEventListener("keydown", $, !0), a.removeEventListener("keydown", G), p;
733
- }, u = function(o) {
734
- var i = o.some(function(l) {
735
- var g = Array.from(l.removedNodes);
736
- return g.some(function(h) {
737
- return h === n.mostRecentlyFocusedNode;
738
- });
739
- });
740
- i && P(D());
741
- }, T = typeof window < "u" && "MutationObserver" in window ? new MutationObserver(u) : void 0, O = function() {
742
- T && (T.disconnect(), n.active && !n.paused && n.containers.map(function(o) {
743
- T.observe(o, {
744
- subtree: !0,
745
- childList: !0
746
- });
747
- }));
748
- };
749
- return p = {
750
- get active() {
751
- return n.active;
752
- },
753
- get paused() {
754
- return n.paused;
755
- },
756
- activate: function(o) {
757
- if (n.active)
758
- return this;
759
- var i = y(o, "onActivate"), l = y(o, "onPostActivate"), g = y(o, "checkCanFocusTrap"), h = B.getActiveTrap(s), w = !1;
760
- if (h && !h.paused) {
761
- var v;
762
- (v = h._setSubtreeIsolation) === null || v === void 0 || v.call(h, !1), w = !0;
763
- }
764
- try {
765
- g || R(), n.active = !0, n.paused = !1, n.nodeFocusedBeforeActivation = A(a), i == null || i();
766
- var E = function() {
767
- g && R(), d(), O(), c.isolateSubtrees && p._setSubtreeIsolation(!0), l == null || l();
768
- };
769
- if (g)
770
- return g(n.containers.concat()).then(E, E), this;
771
- E();
772
- } catch (j) {
773
- if (h === B.getActiveTrap(s) && w) {
774
- var F;
775
- (F = h._setSubtreeIsolation) === null || F === void 0 || F.call(h, !0);
776
- }
777
- throw j;
778
- }
779
- return this;
780
- },
781
- deactivate: function(o) {
782
- if (!n.active)
783
- return this;
784
- var i = me({
785
- onDeactivate: c.onDeactivate,
786
- onPostDeactivate: c.onPostDeactivate,
787
- checkCanReturnFocus: c.checkCanReturnFocus
788
- }, o);
789
- clearTimeout(n.delayInitialFocusTimer), n.delayInitialFocusTimer = void 0, n.paused || p._setSubtreeIsolation(!1), n.alreadySilent.clear(), m(), n.active = !1, n.paused = !1, O(), B.deactivateTrap(s, p);
790
- var l = y(i, "onDeactivate"), g = y(i, "onPostDeactivate"), h = y(i, "checkCanReturnFocus"), w = y(i, "returnFocus", "returnFocusOnDeactivate");
791
- l == null || l();
792
- var v = function() {
793
- ge(function() {
794
- w && P(Y(n.nodeFocusedBeforeActivation)), g == null || g();
795
- });
796
- };
797
- return w && h ? (h(Y(n.nodeFocusedBeforeActivation)).then(v, v), this) : (v(), this);
798
- },
799
- pause: function(o) {
800
- return n.active ? (n.manuallyPaused = !0, this._setPausedState(!0, o)) : this;
801
- },
802
- unpause: function(o) {
803
- return n.active ? (n.manuallyPaused = !1, s[s.length - 1] !== this ? this : this._setPausedState(!1, o)) : this;
804
- },
805
- updateContainerElements: function(o) {
806
- var i = [].concat(o).filter(Boolean);
807
- return n.containers = i.map(function(l) {
808
- return typeof l == "string" ? a.querySelector(l) : l;
809
- }), c.isolateSubtrees && f(n.containers), n.active && (R(), c.isolateSubtrees && !n.paused && p._setSubtreeIsolation(!0)), O(), this;
810
- }
811
- }, Object.defineProperties(p, {
812
- _isManuallyPaused: {
813
- value: function() {
814
- return n.manuallyPaused;
815
- }
816
- },
817
- _setPausedState: {
818
- value: function(o, i) {
819
- if (n.paused === o)
820
- return this;
821
- if (n.paused = o, o) {
822
- var l = y(i, "onPause"), g = y(i, "onPostPause");
823
- l == null || l(), m(), O(), p._setSubtreeIsolation(!1), g == null || g();
824
- } else {
825
- var h = y(i, "onUnpause"), w = y(i, "onPostUnpause");
826
- h == null || h(), p._setSubtreeIsolation(!0), R(), d(), O(), w == null || w();
827
- }
828
- return this;
829
- }
830
- },
831
- _setSubtreeIsolation: {
832
- value: function(o) {
833
- c.isolateSubtrees && n.adjacentElements.forEach(function(i) {
834
- var l;
835
- if (o)
836
- switch (c.isolateSubtrees) {
837
- case "aria-hidden":
838
- (i.ariaHidden === "true" || ((l = i.getAttribute("aria-hidden")) === null || l === void 0 ? void 0 : l.toLowerCase()) === "true") && n.alreadySilent.add(i), i.setAttribute("aria-hidden", "true");
839
- break;
840
- default:
841
- (i.inert || i.hasAttribute("inert")) && n.alreadySilent.add(i), i.setAttribute("inert", !0);
842
- break;
843
- }
844
- else if (!n.alreadySilent.has(i)) switch (c.isolateSubtrees) {
845
- case "aria-hidden":
846
- i.removeAttribute("aria-hidden");
847
- break;
848
- default:
849
- i.removeAttribute("inert");
850
- break;
851
- }
852
- });
853
- }
854
- }
855
- }), p.updateContainerElements(e), p;
856
- };
857
- const vt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
858
- __proto__: null,
859
- createFocusTrap: dt
860
- }, Symbol.toStringTag, { value: "Module" })), pt = /* @__PURE__ */ ke(vt), bt = /* @__PURE__ */ ke(Qe);
861
- var Te;
862
- function ht() {
863
- if (Te) return Q.exports;
864
- Te = 1;
865
- function r(d) {
866
- "@babel/helpers - typeof";
867
- return r = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(f) {
868
- return typeof f;
869
- } : function(f) {
870
- return f && typeof Symbol == "function" && f.constructor === Symbol && f !== Symbol.prototype ? "symbol" : typeof f;
871
- }, r(d);
872
- }
873
- var e, t;
874
- function a(d, f) {
875
- if (!(d instanceof f)) throw new TypeError("Cannot call a class as a function");
876
- }
877
- function s(d, f) {
878
- for (var m = 0; m < f.length; m++) {
879
- var u = f[m];
880
- u.enumerable = u.enumerable || !1, u.configurable = !0, "value" in u && (u.writable = !0), Object.defineProperty(d, P(u.key), u);
881
- }
882
- }
883
- function c(d, f, m) {
884
- return f && s(d.prototype, f), Object.defineProperty(d, "prototype", { writable: !1 }), d;
885
- }
886
- function n(d, f, m) {
887
- return f = S(f), p(d, k() ? Reflect.construct(f, m || [], S(d).constructor) : f.apply(d, m));
888
- }
889
- function p(d, f) {
890
- if (f && (r(f) == "object" || typeof f == "function")) return f;
891
- if (f !== void 0) throw new TypeError("Derived constructors may only return object or undefined");
892
- return y(d);
893
- }
894
- function y(d) {
895
- if (d === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
896
- return d;
897
- }
898
- function k() {
899
- try {
900
- var d = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
901
- }));
902
- } catch {
903
- }
904
- return (k = function() {
905
- return !!d;
906
- })();
907
- }
908
- function S(d) {
909
- return S = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(f) {
910
- return f.__proto__ || Object.getPrototypeOf(f);
911
- }, S(d);
912
- }
913
- function D(d, f) {
914
- if (typeof f != "function" && f !== null) throw new TypeError("Super expression must either be null or a function");
915
- d.prototype = Object.create(f && f.prototype, { constructor: { value: d, writable: !0, configurable: !0 } }), Object.defineProperty(d, "prototype", { writable: !1 }), f && R(d, f);
916
- }
917
- function R(d, f) {
918
- return R = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(m, u) {
919
- return m.__proto__ = u, m;
920
- }, R(d, f);
921
- }
922
- function A(d, f, m) {
923
- return (f = P(f)) in d ? Object.defineProperty(d, f, { value: m, enumerable: !0, configurable: !0, writable: !0 }) : d[f] = m, d;
924
- }
925
- function P(d) {
926
- var f = Y(d, "string");
927
- return r(f) == "symbol" ? f : f + "";
928
- }
929
- function Y(d, f) {
930
- if (r(d) != "object" || !d) return d;
931
- var m = d[Symbol.toPrimitive];
932
- if (m !== void 0) {
933
- var u = m.call(d, f);
934
- if (r(u) != "object") return u;
935
- throw new TypeError("@@toPrimitive must return a primitive value.");
936
- }
937
- return (f === "string" ? String : Number)(d);
938
- }
939
- var C = Ie, I = pt, q = I.createFocusTrap, V = bt, $ = V.isFocusable, G = parseInt((e = (t = /^(\d+)\./.exec(C.version)) === null || t === void 0 ? void 0 : t[1]) !== null && e !== void 0 ? e : 0, 10), L = /* @__PURE__ */ (function(d) {
940
- function f(m) {
941
- var u;
942
- a(this, f), u = n(this, f, [m]), A(u, "getNodeForOption", function(b) {
943
- var o, i = (o = this.internalOptions[b]) !== null && o !== void 0 ? o : this.originalOptions[b];
944
- if (typeof i == "function") {
945
- for (var l = arguments.length, g = new Array(l > 1 ? l - 1 : 0), h = 1; h < l; h++)
946
- g[h - 1] = arguments[h];
947
- i = i.apply(void 0, g);
948
- }
949
- if (i === !0 && (i = void 0), !i) {
950
- if (i === void 0 || i === !1)
951
- return i;
952
- throw new Error("`".concat(b, "` was specified but was not a node, or did not return a node"));
953
- }
954
- var w = i;
955
- if (typeof i == "string") {
956
- var v;
957
- if (w = (v = this.getDocument()) === null || v === void 0 ? void 0 : v.querySelector(i), !w)
958
- throw new Error("`".concat(b, "` as selector refers to no known node"));
959
- }
960
- return w;
961
- }), u.handleDeactivate = u.handleDeactivate.bind(u), u.handlePostDeactivate = u.handlePostDeactivate.bind(u), u.handleClickOutsideDeactivates = u.handleClickOutsideDeactivates.bind(u), u.internalOptions = {
962
- // We need to hijack the returnFocusOnDeactivate option,
963
- // because React can move focus into the element before we arrived at
964
- // this lifecycle hook (e.g. with autoFocus inputs). So the component
965
- // captures the previouslyFocusedElement in componentWillMount,
966
- // then (optionally) returns focus to it in componentWillUnmount.
967
- returnFocusOnDeactivate: !1,
968
- // the rest of these are also related to deactivation of the trap, and we
969
- // need to use them and control them as well
970
- checkCanReturnFocus: null,
971
- onDeactivate: u.handleDeactivate,
972
- onPostDeactivate: u.handlePostDeactivate,
973
- // we need to special-case this setting as well so that we can know if we should
974
- // NOT return focus if the trap gets auto-deactivated as the result of an
975
- // outside click (otherwise, we'll always think we should return focus because
976
- // of how we manage that flag internally here)
977
- clickOutsideDeactivates: u.handleClickOutsideDeactivates
978
- }, u.originalOptions = {
979
- // because of the above `internalOptions`, we maintain our own flag for
980
- // this option, and default it to `true` because that's focus-trap's default
981
- returnFocusOnDeactivate: !0,
982
- // because of the above `internalOptions`, we keep these separate since
983
- // they're part of the deactivation process which we configure (internally) to
984
- // be shared between focus-trap and focus-trap-react
985
- onDeactivate: null,
986
- onPostDeactivate: null,
987
- checkCanReturnFocus: null,
988
- // the user's setting, defaulted to false since focus-trap defaults this to false
989
- clickOutsideDeactivates: !1
990
- };
991
- var T = m.focusTrapOptions;
992
- for (var O in T)
993
- if (Object.prototype.hasOwnProperty.call(T, O)) {
994
- if (O === "returnFocusOnDeactivate" || O === "onDeactivate" || O === "onPostDeactivate" || O === "checkCanReturnFocus" || O === "clickOutsideDeactivates") {
995
- u.originalOptions[O] = T[O];
996
- continue;
997
- }
998
- u.internalOptions[O] = T[O];
999
- }
1000
- return u.outsideClick = null, u.focusTrapElements = m.containerElements || [], u.updatePreviousElement(), u;
1001
- }
1002
- return D(f, d), c(f, [{
1003
- key: "getDocument",
1004
- value: function() {
1005
- return this.props.focusTrapOptions.document || (typeof document < "u" ? document : void 0);
1006
- }
1007
- }, {
1008
- key: "getReturnFocusNode",
1009
- value: function() {
1010
- var u = this.getNodeForOption("setReturnFocus", this.previouslyFocusedElement);
1011
- return u || (u === !1 ? !1 : this.previouslyFocusedElement);
1012
- }
1013
- /** Update the previously focused element with the currently focused element. */
1014
- }, {
1015
- key: "updatePreviousElement",
1016
- value: function() {
1017
- var u = this.getDocument();
1018
- u && (this.previouslyFocusedElement = u.activeElement);
1019
- }
1020
- }, {
1021
- key: "deactivateTrap",
1022
- value: function() {
1023
- !this.focusTrap || !this.focusTrap.active || this.focusTrap.deactivate({
1024
- // NOTE: we never let the trap return the focus since we do that ourselves
1025
- returnFocus: !1,
1026
- // we'll call this in our own post deactivate handler so make sure the trap doesn't
1027
- // do it prematurely
1028
- checkCanReturnFocus: null,
1029
- // let it call the user's original deactivate handler, if any, instead of
1030
- // our own which calls back into this function
1031
- onDeactivate: this.originalOptions.onDeactivate
1032
- // NOTE: for post deactivate, don't specify anything so that it calls the
1033
- // onPostDeactivate handler specified on `this.internalOptions`
1034
- // which will always be our own `handlePostDeactivate()` handler, which
1035
- // will finish things off by calling the user's provided onPostDeactivate
1036
- // handler, if any, at the right time
1037
- // onPostDeactivate: NOTHING
1038
- });
1039
- }
1040
- }, {
1041
- key: "handleClickOutsideDeactivates",
1042
- value: function(u) {
1043
- var T = typeof this.originalOptions.clickOutsideDeactivates == "function" ? this.originalOptions.clickOutsideDeactivates.call(null, u) : this.originalOptions.clickOutsideDeactivates;
1044
- return T && (this.outsideClick = {
1045
- target: u.target,
1046
- allowDeactivation: T
1047
- }), T;
1048
- }
1049
- }, {
1050
- key: "handleDeactivate",
1051
- value: function() {
1052
- this.originalOptions.onDeactivate && this.originalOptions.onDeactivate.call(null), this.deactivateTrap();
1053
- }
1054
- }, {
1055
- key: "handlePostDeactivate",
1056
- value: function() {
1057
- var u = this, T = function() {
1058
- var b = u.getReturnFocusNode(), o = !!// did the consumer allow it?
1059
- (u.originalOptions.returnFocusOnDeactivate && // can we actually focus the node?
1060
- b !== null && b !== void 0 && b.focus && // was there an outside click that allowed deactivation?
1061
- (!u.outsideClick || // did the consumer allow deactivation when the outside node was clicked?
1062
- u.outsideClick.allowDeactivation && // is the outside node NOT focusable (implying that it did NOT receive focus
1063
- // as a result of the click-through) -- in which case do NOT restore focus
1064
- // to `returnFocusNode` because focus should remain on the outside node
1065
- !$(u.outsideClick.target, u.internalOptions.tabbableOptions))), i = u.internalOptions.preventScroll, l = i === void 0 ? !1 : i;
1066
- o && b.focus({
1067
- preventScroll: l
1068
- }), u.originalOptions.onPostDeactivate && u.originalOptions.onPostDeactivate.call(null), u.outsideClick = null;
1069
- };
1070
- this.originalOptions.checkCanReturnFocus ? this.originalOptions.checkCanReturnFocus.call(null, this.getReturnFocusNode()).then(T, T) : T();
1071
- }
1072
- }, {
1073
- key: "setupFocusTrap",
1074
- value: function() {
1075
- if (this.focusTrap)
1076
- this.props.active && !this.focusTrap.active && (this.focusTrap.activate(), this.props.paused && this.focusTrap.pause());
1077
- else {
1078
- var u = this.focusTrapElements.some(Boolean);
1079
- u && (this.focusTrap = this.props._createFocusTrap(this.focusTrapElements, this.internalOptions), this.props.active && this.focusTrap.activate(), this.props.paused && this.focusTrap.pause());
1080
- }
1081
- }
1082
- }, {
1083
- key: "componentDidMount",
1084
- value: function() {
1085
- this.props.active && this.setupFocusTrap();
1086
- }
1087
- }, {
1088
- key: "componentDidUpdate",
1089
- value: function(u) {
1090
- if (this.focusTrap) {
1091
- u.containerElements !== this.props.containerElements && this.focusTrap.updateContainerElements(this.props.containerElements);
1092
- var T = !u.active && this.props.active, O = u.active && !this.props.active, b = !u.paused && this.props.paused, o = u.paused && !this.props.paused;
1093
- if (T && (this.updatePreviousElement(), this.focusTrap.activate()), O) {
1094
- this.deactivateTrap();
1095
- return;
1096
- }
1097
- b && this.focusTrap.pause(), o && this.focusTrap.unpause();
1098
- } else
1099
- u.containerElements !== this.props.containerElements && (this.focusTrapElements = this.props.containerElements), this.props.active && (this.updatePreviousElement(), this.setupFocusTrap());
1100
- }
1101
- }, {
1102
- key: "componentWillUnmount",
1103
- value: function() {
1104
- this.deactivateTrap();
1105
- }
1106
- }, {
1107
- key: "render",
1108
- value: function() {
1109
- var u = this, T = this.props.children ? C.Children.only(this.props.children) : void 0;
1110
- if (T) {
1111
- if (T.type && T.type === C.Fragment)
1112
- throw new Error("A focus-trap cannot use a Fragment as its child container. Try replacing it with a <div> element.");
1113
- var O = function(i) {
1114
- var l = u.props.containerElements;
1115
- T && (G >= 19 ? typeof T.props.ref == "function" ? T.props.ref(i) : T.props.ref && (T.props.ref.current = i) : typeof T.ref == "function" ? T.ref(i) : T.ref && (T.ref.current = i)), u.focusTrapElements = l || [i];
1116
- }, b = C.cloneElement(T, {
1117
- ref: O
1118
- });
1119
- return b;
1120
- }
1121
- return null;
1122
- }
1123
- }]);
1124
- })(C.Component);
1125
- return L.defaultProps = {
1126
- active: !0,
1127
- paused: !1,
1128
- focusTrapOptions: {},
1129
- _createFocusTrap: q
1130
- }, Q.exports = L, Q.exports.FocusTrap = L, Q.exports;
1131
- }
1132
- var yt = ht();
1133
- const je = Ae({
1
+ import { j as t } from "../jsx-runtime-B4hRZ52C.mjs";
2
+ import { createContext as q, useRef as v, useState as w, useCallback as j, useMemo as T, useEffect as p, useContext as z } from "react";
3
+ import { cx as I } from "@kuma-ui/core";
4
+ import { createPortal as G } from "react-dom";
5
+ import { f as H } from "../focus-trap-react-DYXrtbDH.mjs";
6
+ import { IconType as J } from "../icons/icon.mjs";
7
+ import K from "./text-button.mjs";
8
+ const B = q({
1134
9
  isVisible: !1
1135
10
  }), {
1136
- Provider: mt
1137
- } = je;
1138
- function gt() {
1139
- return xe(je);
11
+ Provider: Q
12
+ } = B;
13
+ function U() {
14
+ return z(B);
1140
15
  }
1141
- function Tt() {
16
+ function V() {
1142
17
  const {
1143
- close: r
1144
- } = gt(), e = J(() => {
1145
- r == null || r();
1146
- }, [r]);
1147
- return /* @__PURE__ */ N.jsxs(N.Fragment, { children: [
1148
- /* @__PURE__ */ N.jsx("div", { className: "kakadu-components-2543813221" }),
1149
- /* @__PURE__ */ N.jsx("div", { className: "kakadu-components-840864829", children: /* @__PURE__ */ N.jsx(Be, { iconLeft: Le.times, label: "Close", className: "kakadu-components-3855719072", onClick: e }) })
18
+ close: n
19
+ } = U(), o = j(() => {
20
+ n == null || n();
21
+ }, [n]);
22
+ return /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
23
+ /* @__PURE__ */ t.jsx("div", { className: "kakadu-components-2543813221" }),
24
+ /* @__PURE__ */ t.jsx("div", { className: "kakadu-components-840864829", children: /* @__PURE__ */ t.jsx(K, { iconLeft: J.times, label: "Close", className: "kakadu-components-3855719072", onClick: o }) })
1150
25
  ] });
1151
26
  }
1152
- function we({
1153
- decorators: r,
1154
- children: e
27
+ function C({
28
+ decorators: n,
29
+ children: o
1155
30
  }) {
1156
- return r.length === 0 ? e : r.reduceRight((t, a) => /* @__PURE__ */ N.jsx(a, { children: t }), e);
1157
- }
1158
- function Dt({
1159
- root: r,
1160
- outerDecorators: e = [],
1161
- innerDecorators: t = [],
1162
- maxWidth: a,
1163
- className: s,
1164
- isVisible: c,
1165
- isFullWidth: n = !1,
1166
- shouldCloseOnOutsideClick: p = !0,
1167
- shouldCloseOnEscapePress: y = !0,
1168
- showCloseButton: k = !0,
1169
- onClose: S,
1170
- children: D
31
+ return n.length === 0 ? o : n.reduceRight((r, u) => /* @__PURE__ */ t.jsx(u, { children: r }), o);
32
+ }
33
+ function te({
34
+ root: n,
35
+ outerDecorators: o = [],
36
+ innerDecorators: r = [],
37
+ label: u,
38
+ maxWidth: c,
39
+ className: i,
40
+ isVisible: s,
41
+ isFullWidth: f = !1,
42
+ shouldCloseOnOutsideClick: k = !0,
43
+ shouldCloseOnEscapePress: l = !0,
44
+ showCloseButton: d = !0,
45
+ onClose: a,
46
+ children: P
1171
47
  }) {
1172
- const R = te(null), A = te(null), [P, Y] = re(!1), [C, I] = re(!1), q = J((u) => {
1173
- R.current = u, I(!1);
1174
- }, []), V = te(null), $ = J((u) => {
1175
- u && (V.current = u);
1176
- }, []), [G, L] = re(c ?? !1), d = ne(() => ({
1177
- isVisible: G,
1178
- setInitialFocus: $,
1179
- close: q
1180
- }), [G, $, q]);
1181
- H(() => {
1182
- c && (Y(!0), L(!0));
1183
- }, [c]), H(() => {
1184
- if (c) {
1185
- const u = setTimeout(() => {
1186
- I(!0);
48
+ const R = v(null), N = v(null), [g, A] = w(!1), [m, x] = w(!1), y = j((e) => {
49
+ R.current = e, x(!1);
50
+ }, []), E = v(null), L = j((e) => {
51
+ e && (E.current = e);
52
+ }, []), [M, F] = w(s ?? !1), D = T(() => ({
53
+ isVisible: M,
54
+ setInitialFocus: L,
55
+ close: y
56
+ }), [M, L, y]);
57
+ p(() => {
58
+ s && (A(!0), F(!0));
59
+ }, [s]), p(() => {
60
+ if (s) {
61
+ const e = setTimeout(() => {
62
+ x(!0);
1187
63
  }, 100);
1188
64
  return () => {
1189
- clearTimeout(u);
65
+ clearTimeout(e);
1190
66
  };
1191
67
  }
1192
- I(!1);
1193
- }, [c]), H(() => {
1194
- if (P && !C) {
1195
- const u = setTimeout(() => {
1196
- S == null || S(R.current ?? void 0), L(!1);
68
+ x(!1);
69
+ }, [s]), p(() => {
70
+ if (g && !m) {
71
+ const e = setTimeout(() => {
72
+ a == null || a(R.current ?? void 0), F(!1);
1197
73
  }, 370);
1198
74
  return () => {
1199
- clearTimeout(u);
75
+ clearTimeout(e);
1200
76
  };
1201
77
  }
1202
- }, [P, C, S]), H(() => {
1203
- const u = A.current;
1204
- if (c && p && u) {
1205
- const T = (O) => {
1206
- u === O.target && I(!1);
78
+ }, [g, m, a]), p(() => {
79
+ const e = N.current;
80
+ if (s && k && e) {
81
+ const h = ($) => {
82
+ e === $.target && x(!1);
1207
83
  };
1208
- return u.addEventListener("click", T), () => {
1209
- u.removeEventListener("click", T);
84
+ return e.addEventListener("click", h), () => {
85
+ e.removeEventListener("click", h);
1210
86
  };
1211
87
  }
1212
- }, [c, p]), H(() => {
1213
- if (!c || !y)
88
+ }, [s, k]), p(() => {
89
+ if (!s || !l)
1214
90
  return;
1215
- const u = (T) => {
1216
- T.key === "Escape" && I(!1);
91
+ const e = (h) => {
92
+ h.key === "Escape" && x(!1);
1217
93
  };
1218
- return window.addEventListener("keydown", u), () => {
1219
- window.removeEventListener("keydown", u);
94
+ return window.addEventListener("keydown", e), () => {
95
+ window.removeEventListener("keydown", e);
1220
96
  };
1221
- }, [c, y]);
1222
- const f = ne(() => ({
1223
- initialFocus: () => V.current ?? void 0,
97
+ }, [s, l]);
98
+ const S = T(() => ({
99
+ initialFocus: () => E.current ?? void 0,
1224
100
  onActivate: () => {
1225
- var u;
1226
- return (u = V.current) == null ? void 0 : u.focus();
1227
- }
1228
- }), []), m = /* @__PURE__ */ N.jsx(we, { decorators: e, children: /* @__PURE__ */ N.jsx("div", { style: {
1229
- "--max-width": a ? `${a}px` : void 0
1230
- }, className: de("kakadu-components-4119461136", C && "kakadu-components-2522346797", s), children: /* @__PURE__ */ N.jsx(we, { decorators: t, children: /* @__PURE__ */ N.jsx(yt.FocusTrap, { active: C, focusTrapOptions: f, children: /* @__PURE__ */ N.jsx("div", { ref: A, className: "kakadu-components-4011815997", children: /* @__PURE__ */ N.jsx("div", { className: de("kakadu-components-3324483532", n && "kakadu-components-3799971070", C && "kakadu-components-968755580"), children: /* @__PURE__ */ N.jsxs(mt, { value: d, children: [
1231
- k ? /* @__PURE__ */ N.jsx(Tt, {}) : null,
1232
- /* @__PURE__ */ N.jsx("div", { className: de("kakadu-components-633990035", n && "kakadu-components-171969824"), children: D })
101
+ var e;
102
+ return (e = E.current) == null ? void 0 : e.focus();
103
+ }
104
+ }), []), b = /* @__PURE__ */ t.jsx(C, { decorators: o, children: /* @__PURE__ */ t.jsx("div", { "aria-hidden": !m, style: {
105
+ "--max-width": c ? `${c}px` : void 0
106
+ }, className: I("kakadu-components-4119461136", m && "kakadu-components-2522346797", i), children: /* @__PURE__ */ t.jsx(C, { decorators: r, children: /* @__PURE__ */ t.jsx(H.FocusTrap, { active: m, focusTrapOptions: S, children: /* @__PURE__ */ t.jsx("div", { ref: N, className: "kakadu-components-4011815997", children: /* @__PURE__ */ t.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": u ?? "Modal", className: I("kakadu-components-3324483532", f && "kakadu-components-3799971070", m && "kakadu-components-968755580"), children: /* @__PURE__ */ t.jsxs(Q, { value: D, children: [
107
+ d ? /* @__PURE__ */ t.jsx(V, {}) : null,
108
+ /* @__PURE__ */ t.jsx("div", { className: I("kakadu-components-633990035", f && "kakadu-components-171969824"), children: P })
1233
109
  ] }) }) }) }) }) }) });
1234
- return r ? _e(m, r) : m;
1235
- }
1236
- function Nt(r, e) {
1237
- const [t, a] = re(!1), s = te(void 0), c = J(async () => (a(!0), new Promise((y) => {
1238
- s.current = y;
1239
- })), []), n = J((y) => {
1240
- var k;
1241
- a(!1), (k = s.current) == null || k.call(s, y), s.current = void 0;
1242
- }, []), p = ne(() => /* @__PURE__ */ N.jsx(r, { ...e, isVisible: t, onClose: n }), [r, e, t, n]);
1243
- return ne(() => ({
1244
- isVisible: t,
1245
- show: c,
1246
- modal: p
1247
- }), [t, c, p]);
110
+ return n ? G(b, n) : b;
111
+ }
112
+ function ne(n, o) {
113
+ const [r, u] = w(!1), c = v(void 0), i = v(null), s = j(async (l) => (u(!0), i.current = l ?? document.activeElement, new Promise((d) => {
114
+ c.current = d;
115
+ })), []), f = j((l) => {
116
+ var d;
117
+ if (u(!1), (d = c.current) == null || d.call(c, l), c.current = void 0, i.current) {
118
+ const a = i.current;
119
+ a.isConnected && a.focus(), i.current = null;
120
+ }
121
+ }, []), k = T(() => /* @__PURE__ */ t.jsx(n, { ...o, isVisible: r, onClose: f }), [n, o, r, f]);
122
+ return T(() => ({
123
+ isVisible: r,
124
+ show: s,
125
+ modal: k
126
+ }), [r, s, k]);
1248
127
  }
1249
128
  export {
1250
- Dt as default,
1251
- Nt as useModal,
1252
- gt as useModalContext
129
+ te as default,
130
+ ne as useModal,
131
+ U as useModalContext
1253
132
  };