@inertiaui/modal-react 1.0.0-beta-5 → 2.0.2

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 (49) hide show
  1. package/dist/CloseButton.d.ts +5 -0
  2. package/dist/Deferred.d.ts +11 -0
  3. package/dist/HeadlessModal.d.ts +64 -0
  4. package/dist/Modal.d.ts +48 -0
  5. package/dist/ModalContent.d.ts +24 -0
  6. package/dist/ModalLink.d.ts +29 -0
  7. package/dist/ModalRenderer.d.ts +4 -0
  8. package/dist/ModalRoot.d.ts +22 -0
  9. package/dist/SlideoverContent.d.ts +24 -0
  10. package/dist/WhenVisible.d.ts +16 -0
  11. package/dist/config.d.ts +21 -0
  12. package/dist/constants.d.ts +7 -0
  13. package/dist/helpers.d.ts +3 -0
  14. package/dist/inertiaui-modal.d.ts +2 -0
  15. package/dist/inertiaui-modal.js +1680 -2167
  16. package/dist/inertiaui-modal.js.map +1 -0
  17. package/dist/inertiaui-modal.umd.cjs +1854 -21
  18. package/dist/inertiaui-modal.umd.cjs.map +1 -0
  19. package/dist/inertiauiModal.d.ts +21 -0
  20. package/dist/types.d.ts +111 -0
  21. package/dist/useModal.d.ts +2 -0
  22. package/package.json +37 -22
  23. package/src/{CloseButton.jsx → CloseButton.tsx} +5 -1
  24. package/src/{Deferred.jsx → Deferred.tsx} +10 -3
  25. package/src/HeadlessModal.tsx +238 -0
  26. package/src/Modal.tsx +292 -0
  27. package/src/ModalContent.tsx +311 -0
  28. package/src/ModalLink.tsx +224 -0
  29. package/src/ModalRenderer.tsx +33 -0
  30. package/src/ModalRoot.tsx +880 -0
  31. package/src/SlideoverContent.tsx +319 -0
  32. package/src/{WhenVisible.jsx → WhenVisible.tsx} +20 -9
  33. package/src/config.ts +99 -0
  34. package/src/constants.ts +22 -0
  35. package/src/helpers.ts +17 -0
  36. package/src/inertiauiModal.ts +65 -0
  37. package/src/types.ts +150 -0
  38. package/src/useModal.ts +7 -0
  39. package/src/HeadlessModal.jsx +0 -143
  40. package/src/Modal.jsx +0 -136
  41. package/src/ModalContent.jsx +0 -56
  42. package/src/ModalLink.jsx +0 -123
  43. package/src/ModalRenderer.jsx +0 -34
  44. package/src/ModalRoot.jsx +0 -623
  45. package/src/SlideoverContent.jsx +0 -55
  46. package/src/config.js +0 -3
  47. package/src/helpers.js +0 -2
  48. package/src/inertiauiModal.js +0 -34
  49. package/src/useModal.js +0 -6
@@ -1,1973 +1,838 @@
1
- var Ur = Object.defineProperty;
2
- var Hr = (e, t, r) => t in e ? Ur(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var K = (e, t, r) => Hr(e, typeof t != "symbol" ? t + "" : t, r);
4
- import * as Ce from "react";
5
- import $, { createContext as z, useContext as H, useEffect as L, useRef as S, useState as F, createElement as Re, useMemo as _, forwardRef as Pt, useImperativeHandle as tr, useLayoutEffect as Vr, useCallback as W, Fragment as ue, isValidElement as Br, cloneElement as Xr, useId as _e, useSyncExternalStore as zr, useReducer as Gr, createRef as Kr } from "react";
6
- import { jsxs as he, Fragment as Mt, jsx as P } from "react/jsx-runtime";
7
- import Ge from "axios";
8
- import * as _t from "@inertiajs/react";
9
- import { usePage as qr, router as Me } from "@inertiajs/react";
10
- import { mergeDataIntoQueryString as Yr } from "@inertiajs/core";
11
- import { createPortal as Zr } from "react-dom";
12
- const Te = {
1
+ import React, { createContext, useContext, useRef, useEffect, useReducer, useState, createElement, useMemo, forwardRef, useImperativeHandle, useCallback } from "react";
2
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
3
+ import Axios from "axios";
4
+ import { generateId as generateId$1, sameUrlPath, kebabCase, except, animate, createFocusTrap, onEscapeKey, cancelAnimations, lockScroll, markAriaHidden, isStandardDomEvent, rejectNullValues, only } from "@inertiaui/vanilla";
5
+ import * as vanilla from "@inertiaui/vanilla";
6
+ import { usePage, router, progress } from "@inertiajs/react";
7
+ import { mergeDataIntoQueryString } from "@inertiajs/core";
8
+ import { createPortal } from "react-dom";
9
+ const defaultConfig = {
13
10
  type: "modal",
14
- navigate: !1,
11
+ navigate: false,
12
+ useNativeDialog: true,
13
+ appElement: "#app",
15
14
  modal: {
16
- closeButton: !0,
17
- closeExplicitly: !1,
15
+ closeButton: true,
16
+ closeExplicitly: false,
17
+ closeOnClickOutside: true,
18
18
  maxWidth: "2xl",
19
19
  paddingClasses: "p-4 sm:p-6",
20
20
  panelClasses: "bg-white rounded",
21
21
  position: "center"
22
22
  },
23
23
  slideover: {
24
- closeButton: !0,
25
- closeExplicitly: !1,
24
+ closeButton: true,
25
+ closeExplicitly: false,
26
+ closeOnClickOutside: true,
26
27
  maxWidth: "md",
27
28
  paddingClasses: "p-4 sm:p-6",
28
29
  panelClasses: "bg-white min-h-screen",
29
30
  position: "right"
30
31
  }
31
32
  };
32
- class Jr {
33
+ class Config {
33
34
  constructor() {
34
- this.config = {}, this.reset();
35
+ this.config = {};
36
+ this.reset();
35
37
  }
36
38
  reset() {
37
- this.config = JSON.parse(JSON.stringify(Te));
39
+ this.config = JSON.parse(JSON.stringify(defaultConfig));
38
40
  }
39
- put(t, r) {
40
- if (typeof t == "object") {
41
+ put(key, value) {
42
+ if (typeof key === "object") {
41
43
  this.config = {
42
- type: t.type ?? Te.type,
43
- navigate: t.navigate ?? Te.navigate,
44
- modal: { ...Te.modal, ...t.modal ?? {} },
45
- slideover: { ...Te.slideover, ...t.slideover ?? {} }
44
+ type: key.type ?? defaultConfig.type,
45
+ navigate: key.navigate ?? defaultConfig.navigate,
46
+ useNativeDialog: key.useNativeDialog ?? defaultConfig.useNativeDialog,
47
+ appElement: key.appElement !== void 0 ? key.appElement : defaultConfig.appElement,
48
+ modal: { ...defaultConfig.modal, ...key.modal ?? {} },
49
+ slideover: { ...defaultConfig.slideover, ...key.slideover ?? {} }
46
50
  };
47
51
  return;
48
52
  }
49
- const n = t.split(".");
50
- let l = this.config;
51
- for (let i = 0; i < n.length - 1; i++)
52
- l = l[n[i]] = l[n[i]] || {};
53
- l[n[n.length - 1]] = r;
53
+ const keys = key.split(".");
54
+ let current = this.config;
55
+ for (let i = 0; i < keys.length - 1; i++) {
56
+ current = current[keys[i]] = current[keys[i]] || {};
57
+ }
58
+ current[keys[keys.length - 1]] = value;
54
59
  }
55
- get(t) {
56
- if (typeof t > "u")
60
+ get(key) {
61
+ if (typeof key === "undefined") {
57
62
  return this.config;
58
- const r = t.split(".");
59
- let n = this.config;
60
- for (const l of r) {
61
- if (n[l] === void 0)
63
+ }
64
+ const keys = key.split(".");
65
+ let current = this.config;
66
+ for (const k of keys) {
67
+ if (current === null || current === void 0 || typeof current !== "object") {
62
68
  return null;
63
- n = n[l];
69
+ }
70
+ current = current[k];
64
71
  }
65
- return n;
72
+ return current === void 0 ? null : current;
66
73
  }
67
74
  }
68
- const Je = new Jr(), Ti = () => Je.reset(), Pi = (e, t) => Je.put(e, t), Lt = (e) => Je.get(e), we = (e, t) => Je.get(e ? `slideover.${t}` : `modal.${t}`);
69
- function Qr(e, t) {
70
- const r = typeof window < "u" ? window.location.origin : "http://localhost";
71
- return e = typeof e == "string" ? new URL(e, r) : e, t = typeof t == "string" ? new URL(t, r) : t, `${e.origin}${e.pathname}` == `${t.origin}${t.pathname}`;
72
- }
73
- function ft(e = "inertiaui_modal_") {
74
- return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? `${e}${crypto.randomUUID()}` : `${e}${Date.now().toString(36)}_${Math.random().toString(36).substr(2, 9)}`;
75
- }
76
- function be(e) {
77
- return typeof e == "string" ? e.toLowerCase() : e;
78
- }
79
- function en(e, t, r = !1) {
80
- return r && (t = t.map(be)), Array.isArray(e) ? e.filter((n) => !t.includes(r ? be(n) : n)) : Object.keys(e).reduce((n, l) => (t.includes(r ? be(l) : l) || (n[l] = e[l]), n), {});
81
- }
82
- function tn(e, t, r = !1) {
83
- return r && (t = t.map(be)), Array.isArray(e) ? e.filter((n) => t.includes(r ? be(n) : n)) : Object.keys(e).reduce((n, l) => (t.includes(r ? be(l) : l) && (n[l] = e[l]), n), {});
84
- }
85
- function rn(e) {
86
- return Array.isArray(e) ? e.filter((t) => t !== null) : Object.keys(e).reduce((t, r) => (r in e && e[r] !== null && (t[r] = e[r]), t), {});
87
- }
88
- function Pe(e) {
89
- return e ? (e = e.replace(/_/g, "-"), e = e.replace(/-+/g, "-"), /[A-Z]/.test(e) ? (e = e.replace(/\s+/g, "").replace(/_/g, "").replace(/(?:^|\s|-)+([A-Za-z])/g, (t, r) => r.toUpperCase()), e = e.replace(/(.)(?=[A-Z])/g, "$1-"), e.toLowerCase()) : e) : "";
75
+ const configInstance = new Config();
76
+ const resetConfig = () => configInstance.reset();
77
+ const putConfig = (key, value) => configInstance.put(key, value);
78
+ const getConfig = (key) => configInstance.get(key);
79
+ const getConfigByType = (isSlideover, key) => configInstance.get(isSlideover ? `slideover.${key}` : `modal.${key}`);
80
+ function generateId(prefix = "inertiaui_") {
81
+ return generateId$1(prefix);
82
+ }
83
+ const ModalStackContext = createContext(null);
84
+ ModalStackContext.displayName = "ModalStackContext";
85
+ let pageVersion = null;
86
+ let resolveComponent = null;
87
+ let baseUrl = null;
88
+ let closingToBaseUrlTarget = null;
89
+ const prefetchCache = /* @__PURE__ */ new Map();
90
+ const prefetchInFlight = /* @__PURE__ */ new Map();
91
+ function getPrefetchCacheKey(url, method, data) {
92
+ return `${method}:${url}:${JSON.stringify(data)}`;
93
+ }
94
+ function getCachedResponse(url, method, data) {
95
+ const key = getPrefetchCacheKey(url, method, data);
96
+ const cached = prefetchCache.get(key);
97
+ if (!cached) {
98
+ return null;
99
+ }
100
+ if (Date.now() > cached.expiresAt) {
101
+ prefetchCache.delete(key);
102
+ return null;
103
+ }
104
+ return cached.response;
105
+ }
106
+ function setCachedResponse(url, method, data, response, cacheFor) {
107
+ const key = getPrefetchCacheKey(url, method, data);
108
+ prefetchCache.set(key, {
109
+ response,
110
+ timestamp: Date.now(),
111
+ expiresAt: Date.now() + cacheFor
112
+ });
90
113
  }
91
- function nn(e) {
92
- if (typeof window < "u")
93
- return e.toLowerCase() in window;
94
- if (typeof document < "u") {
95
- const n = document.createElement("div");
96
- return e.toLowerCase() in n;
114
+ function prefetch(href, options = {}) {
115
+ if (href.startsWith("#")) {
116
+ return Promise.resolve();
117
+ }
118
+ const method = (options.method ?? "get").toLowerCase();
119
+ const data = options.data ?? {};
120
+ const headers = options.headers ?? {};
121
+ const queryStringArrayFormat = options.queryStringArrayFormat ?? "brackets";
122
+ const cacheFor = options.cacheFor ?? 3e4;
123
+ const [url, mergedData] = mergeDataIntoQueryString(method, href || "", data, queryStringArrayFormat);
124
+ const cached = getCachedResponse(url, method, mergedData);
125
+ if (cached) {
126
+ return Promise.resolve();
127
+ }
128
+ const cacheKey = getPrefetchCacheKey(url, method, mergedData);
129
+ const inFlight = prefetchInFlight.get(cacheKey);
130
+ if (inFlight) {
131
+ return inFlight.then(() => {
132
+ });
97
133
  }
98
- const t = e.toLowerCase();
99
- return [
100
- /^on(click|dblclick|mousedown|mouseup|mouseover|mouseout|mousemove|mouseenter|mouseleave)$/,
101
- /^on(keydown|keyup|keypress)$/,
102
- /^on(focus|blur|change|input|submit|reset)$/,
103
- /^on(load|unload|error|resize|scroll)$/,
104
- /^on(touchstart|touchend|touchmove|touchcancel)$/,
105
- /^on(pointerdown|pointerup|pointermove|pointerenter|pointerleave|pointercancel)$/,
106
- /^on(drag|dragstart|dragend|dragenter|dragleave|dragover|drop)$/,
107
- /^on(animationstart|animationend|animationiteration)$/,
108
- /^on(transitionstart|transitionend|transitionrun|transitioncancel)$/
109
- ].some((n) => n.test(t));
134
+ options.onPrefetching?.();
135
+ const requestHeaders = {
136
+ ...headers,
137
+ Accept: "text/html, application/xhtml+xml",
138
+ "X-Requested-With": "XMLHttpRequest",
139
+ "X-Inertia": "true",
140
+ "X-Inertia-Version": pageVersion ?? "",
141
+ "X-InertiaUI-Modal": generateId(),
142
+ "X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
143
+ };
144
+ const request = Axios({
145
+ url,
146
+ method,
147
+ data: mergedData,
148
+ headers: requestHeaders
149
+ }).then((response) => {
150
+ setCachedResponse(url, method, mergedData, response, cacheFor);
151
+ options.onPrefetched?.();
152
+ return response;
153
+ }).finally(() => {
154
+ prefetchInFlight.delete(cacheKey);
155
+ });
156
+ prefetchInFlight.set(cacheKey, request);
157
+ return request.then(() => {
158
+ });
110
159
  }
111
- const Qe = z(null);
112
- Qe.displayName = "ModalStackContext";
113
- let rr = null, nr = null, xe = null, Ve = {}, pt = [], ye = {};
114
- const ln = ({ children: e }) => {
115
- const [t, r] = F([]), [n, l] = F({}), i = (h) => {
116
- r((c) => {
117
- const d = h([...c]), v = (w) => {
118
- var p;
119
- return d.length < 2 ? !0 : ((p = d.map((x) => ({ id: x.id, shouldRender: x.shouldRender })).reverse().find((x) => x.shouldRender)) == null ? void 0 : p.id) === w;
160
+ const ModalStackProvider = ({ children }) => {
161
+ const stackRef = useRef([]);
162
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
163
+ const [localModals, setLocalModals] = useState({});
164
+ const updateStack = (withStack) => {
165
+ const newStack = withStack([...stackRef.current]);
166
+ const isOnTopOfStack = (modalId) => {
167
+ if (newStack.length < 2) {
168
+ return true;
169
+ }
170
+ return newStack.map((modal) => ({ id: modal.id, shouldRender: modal.shouldRender })).reverse().find((modal) => modal.shouldRender)?.id === modalId;
171
+ };
172
+ newStack.forEach((modal, index) => {
173
+ newStack[index].onTopOfStack = isOnTopOfStack(modal.id);
174
+ newStack[index].getParentModal = () => {
175
+ if (index < 1) {
176
+ return null;
177
+ }
178
+ return stackRef.current.slice(0, index).reverse().find((m) => m.isOpen) ?? null;
179
+ };
180
+ newStack[index].getChildModal = () => {
181
+ if (index === stackRef.current.length - 1) {
182
+ return null;
183
+ }
184
+ return stackRef.current.slice(index + 1).find((m) => m.isOpen) ?? null;
120
185
  };
121
- return d.forEach((w, p) => {
122
- d[p].onTopOfStack = v(w.id), d[p].getParentModal = () => p < 1 ? null : d.slice(0, p).reverse().find((x) => x.isOpen), d[p].getChildModal = () => p === d.length - 1 ? null : d.slice(p + 1).find((x) => x.isOpen);
123
- }), d;
124
186
  });
187
+ stackRef.current = newStack;
188
+ forceUpdate();
125
189
  };
126
- L(() => {
127
- pt = t;
128
- }, [t]);
129
- class a {
130
- constructor(c, d, v, w, p) {
131
- K(this, "show", () => {
132
- i(
133
- (c) => c.map((d) => (d.id === this.id && !d.isOpen && (d.isOpen = !0, d.shouldRender = !0), d))
190
+ class ModalClass {
191
+ constructor(component, response, config, onClose, afterLeave) {
192
+ this.show = () => {
193
+ updateStack(
194
+ (prevStack) => prevStack.map((modal) => {
195
+ if (modal.id === this.id && !modal.isOpen) {
196
+ modal.isOpen = true;
197
+ modal.shouldRender = true;
198
+ }
199
+ return modal;
200
+ })
134
201
  );
135
- });
136
- K(this, "setOpen", (c) => {
137
- c ? this.show() : this.close();
138
- });
139
- K(this, "close", () => {
140
- i((c) => {
141
- let d = !1;
142
- const v = c.map((w) => {
143
- var p;
144
- return w.id === this.id && w.isOpen && (Object.keys(w.listeners).forEach((x) => {
145
- w.off(x);
146
- }), w.isOpen = !1, (p = w.onCloseCallback) == null || p.call(w), d = !0), w;
202
+ };
203
+ this.setOpen = (open) => {
204
+ if (open) {
205
+ this.show();
206
+ } else {
207
+ this.close();
208
+ }
209
+ };
210
+ this.close = () => {
211
+ updateStack((currentStack) => {
212
+ let modalClosed = false;
213
+ const newStack = currentStack.map((modal) => {
214
+ if (modal.id === this.id && modal.isOpen) {
215
+ Object.keys(modal.listeners).forEach((event) => {
216
+ modal.off(event);
217
+ });
218
+ modal.isOpen = false;
219
+ modal.onCloseCallback?.();
220
+ modalClosed = true;
221
+ }
222
+ return modal;
147
223
  });
148
- return d ? v : c;
224
+ return modalClosed ? newStack : currentStack;
149
225
  });
150
- });
151
- K(this, "afterLeave", () => {
152
- this.isOpen || i((c) => {
153
- const d = c.map((v) => {
154
- var w;
155
- return v.id === this.id && !v.isOpen && (v.shouldRender = !1, (w = v.afterLeaveCallback) == null || w.call(v), v.afterLeaveCallback = null), v;
226
+ };
227
+ this.afterLeave = () => {
228
+ if (this.isOpen) {
229
+ return;
230
+ }
231
+ updateStack((prevStack) => {
232
+ const updatedStack = prevStack.map((modal) => {
233
+ if (modal.id === this.id && !modal.isOpen) {
234
+ modal.shouldRender = false;
235
+ modal.afterLeaveCallback?.();
236
+ modal.afterLeaveCallback = null;
237
+ }
238
+ return modal;
156
239
  });
157
- return this.index === 0 ? [] : d;
240
+ if (this.index === 0) {
241
+ const savedBaseUrl = baseUrl;
242
+ baseUrl = null;
243
+ closingToBaseUrlTarget = savedBaseUrl;
244
+ if (savedBaseUrl && typeof window !== "undefined") {
245
+ router.push({
246
+ url: savedBaseUrl,
247
+ preserveScroll: true,
248
+ preserveState: true,
249
+ // Clear _inertiaui_modal prop to prevent modal from reopening
250
+ props: (currentProps) => {
251
+ const { _inertiaui_modal, ...rest } = currentProps;
252
+ return { ...rest, _inertiaui_modal: void 0 };
253
+ }
254
+ });
255
+ }
256
+ return [];
257
+ }
258
+ return updatedStack;
158
259
  });
159
- });
160
- K(this, "on", (c, d) => {
161
- c = Pe(c), this.listeners[c] = this.listeners[c] ?? [], this.listeners[c].push(d);
162
- });
163
- K(this, "off", (c, d) => {
164
- var v;
165
- c = Pe(c), d ? this.listeners[c] = ((v = this.listeners[c]) == null ? void 0 : v.filter((w) => w !== d)) ?? [] : delete this.listeners[c];
166
- });
167
- K(this, "emit", (c, ...d) => {
168
- var v;
169
- (v = this.listeners[Pe(c)]) == null || v.forEach((w) => w(...d));
170
- });
171
- K(this, "registerEventListenersFromProps", (c) => {
172
- const d = [];
173
- return Object.keys(c).filter((v) => v.startsWith("on")).forEach((v) => {
174
- const w = Pe(v).replace(/^on-/, "");
175
- this.on(w, c[v]), d.push(() => this.off(w, c[v]));
176
- }), () => d.forEach((v) => v());
177
- });
178
- K(this, "reload", (c = {}) => {
179
- var p, x;
180
- let d = Object.keys(this.response.props);
181
- if (c.only && (d = c.only), c.except && (d = en(d, c.except)), !((p = this.response) != null && p.url))
260
+ };
261
+ this.on = (event, callback) => {
262
+ event = kebabCase(event);
263
+ this.listeners[event] = this.listeners[event] ?? [];
264
+ this.listeners[event].push(callback);
265
+ };
266
+ this.off = (event, callback) => {
267
+ event = kebabCase(event);
268
+ if (callback) {
269
+ this.listeners[event] = this.listeners[event]?.filter((cb) => cb !== callback) ?? [];
270
+ } else {
271
+ delete this.listeners[event];
272
+ }
273
+ };
274
+ this.emit = (event, ...args) => {
275
+ this.listeners[kebabCase(event)]?.forEach((callback) => callback(...args));
276
+ };
277
+ this.registerEventListenersFromProps = (props) => {
278
+ const unsubscribers = [];
279
+ Object.keys(props).filter((key) => key.startsWith("on")).forEach((key) => {
280
+ const eventName = kebabCase(key).replace(/^on-/, "");
281
+ const callback = props[key];
282
+ this.on(eventName, callback);
283
+ unsubscribers.push(() => this.off(eventName, callback));
284
+ });
285
+ return () => unsubscribers.forEach((unsub) => unsub());
286
+ };
287
+ this.reload = (options = {}) => {
288
+ let keys = Object.keys(this.response.props);
289
+ if (options.only) {
290
+ keys = options.only;
291
+ }
292
+ if (options.except) {
293
+ keys = except(keys, options.except);
294
+ }
295
+ if (!this.response?.url) {
182
296
  return;
183
- const v = (c.method ?? "get").toLowerCase(), w = c.data ?? {};
184
- (x = c.onStart) == null || x.call(c), Ge({
297
+ }
298
+ const method = (options.method ?? "get").toLowerCase();
299
+ const data = options.data ?? {};
300
+ options.onStart?.();
301
+ Axios({
185
302
  url: this.response.url,
186
- method: v,
187
- data: v === "get" ? {} : w,
188
- params: v === "get" ? w : {},
303
+ method,
304
+ data: method === "get" ? {} : data,
305
+ params: method === "get" ? data : {},
189
306
  headers: {
190
- ...c.headers ?? {},
307
+ ...options.headers ?? {},
191
308
  Accept: "text/html, application/xhtml+xml",
192
- "X-Inertia": !0,
309
+ "X-Inertia": "true",
193
310
  "X-Inertia-Partial-Component": this.response.component,
194
- "X-Inertia-Version": this.response.version,
195
- "X-Inertia-Partial-Data": d.join(","),
196
- "X-InertiaUI-Modal": ft(),
197
- "X-InertiaUI-Modal-Use-Router": 0,
198
- "X-InertiaUI-Modal-Base-Url": xe
311
+ "X-Inertia-Version": this.response.version ?? "",
312
+ "X-Inertia-Partial-Data": keys.join(","),
313
+ "X-InertiaUI-Modal": generateId(),
314
+ "X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
199
315
  }
200
- }).then((O) => {
201
- var N;
202
- this.updateProps(O.data.props), (N = c.onSuccess) == null || N.call(c, O);
203
- }).catch((O) => {
204
- var N;
205
- (N = c.onError) == null || N.call(c, O);
316
+ }).then((response2) => {
317
+ this.updateProps(response2.data.props);
318
+ options.onSuccess?.(response2);
319
+ }).catch((error) => {
320
+ options.onError?.(error);
206
321
  }).finally(() => {
207
- var O;
208
- (O = c.onFinish) == null || O.call(c);
322
+ options.onFinish?.();
209
323
  });
210
- });
211
- K(this, "updateProps", (c) => {
212
- Object.assign(this.props, c), i((d) => d);
213
- });
214
- if (this.id = d.id ?? ft(), this.isOpen = !1, this.shouldRender = !1, this.listeners = {}, this.component = c, this.props = d.props, this.response = d, this.config = v ?? {}, this.onCloseCallback = w, this.afterLeaveCallback = p, ye[this.id]) {
215
- this.config = {
216
- ...this.config,
217
- ...ye[this.id].config ?? {}
218
- };
219
- const x = ye[this.id].onClose, O = ye[this.id].onAfterLeave;
220
- x && (this.onCloseCallback = w ? () => {
221
- w(), x();
222
- } : x), O && (this.afterLeaveCallback = p ? () => {
223
- p(), O();
224
- } : O), delete ye[this.id];
225
- }
226
- this.index = -1, this.getParentModal = () => null, this.getChildModal = () => null, this.onTopOfStack = !0;
227
- }
228
- static generateId() {
229
- return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? `inertiaui_modal_${crypto.randomUUID()}` : `inertiaui_modal_${Date.now().toString(36)}_${Math.random().toString(36).substr(2, 9)}`;
324
+ };
325
+ this.updateProps = (props) => {
326
+ Object.assign(this.props, props);
327
+ updateStack((prevStack) => prevStack);
328
+ };
329
+ this.id = response.id ?? generateId();
330
+ this.isOpen = false;
331
+ this.shouldRender = false;
332
+ this.listeners = {};
333
+ this.component = component;
334
+ this.props = response.props ?? {};
335
+ this.response = response;
336
+ this.config = config ?? {};
337
+ this.onCloseCallback = onClose ?? null;
338
+ this.afterLeaveCallback = afterLeave ?? null;
339
+ this.index = -1;
340
+ this.getParentModal = () => null;
341
+ this.getChildModal = () => null;
342
+ this.onTopOfStack = true;
230
343
  }
231
344
  }
232
- const s = (h, c = {}, d = null, v = null) => nr(h.component).then((w) => u(w, h, c, d, v)), o = (h) => {
233
- var d, v;
234
- const c = (v = (d = h.response) == null ? void 0 : d.meta) == null ? void 0 : v.deferredProps;
235
- c && Object.keys(c).forEach((w) => {
236
- h.reload({ only: c[w] });
345
+ const isValidModalResponse = (data) => {
346
+ return typeof data === "object" && data !== null && "component" in data && typeof data.component === "string";
347
+ };
348
+ const pushFromResponseData = (responseData, config = {}, onClose = null, onAfterLeave = null) => {
349
+ if (!resolveComponent) {
350
+ return Promise.reject(new Error("resolveComponent not set"));
351
+ }
352
+ if (!isValidModalResponse(responseData)) {
353
+ return Promise.reject(
354
+ new Error(
355
+ "Invalid modal response. This usually happens when the server returns a redirect (e.g., due to session expiration). Check if the user is still authenticated."
356
+ )
357
+ );
358
+ }
359
+ return resolveComponent(responseData.component).then(
360
+ (component) => push(component, responseData, config, onClose, onAfterLeave)
361
+ );
362
+ };
363
+ const loadDeferredProps = (modal) => {
364
+ const deferred = modal.response?.meta?.deferredProps;
365
+ if (!deferred) {
366
+ return;
367
+ }
368
+ Object.keys(deferred).forEach((key) => {
369
+ modal.reload({ only: deferred[key] });
237
370
  });
238
- }, u = (h, c, d, v, w) => {
239
- const p = new a(h, c, d, v, w);
240
- return p.index = t.length, i((x) => [...x, p]), o(p), p.show(), p;
241
371
  };
242
- function m(h, c, d, v) {
243
- if (!n[h])
244
- throw new Error(`The local modal "${h}" has not been registered.`);
245
- const w = u(null, {}, c, d, v);
246
- return w.name = h, n[h].callback(w), w;
372
+ const push = (component, response, config, onClose, afterLeave) => {
373
+ const newModal = new ModalClass(component, response, config, onClose, afterLeave);
374
+ newModal.index = stackRef.current.length;
375
+ updateStack((prevStack) => [...prevStack, newModal]);
376
+ loadDeferredProps(newModal);
377
+ newModal.show();
378
+ return newModal;
379
+ };
380
+ function pushLocalModal(name, config, onClose, afterLeave, props) {
381
+ if (!localModals[name]) {
382
+ throw new Error(`The local modal "${name}" has not been registered.`);
383
+ }
384
+ const responseData = { props: props ?? {} };
385
+ const modal = push(null, responseData, config, onClose, afterLeave);
386
+ modal.name = name;
387
+ localModals[name].callback(modal);
388
+ return modal;
247
389
  }
248
- const b = (h, c = {}) => g(
249
- h,
250
- c.method ?? "get",
251
- c.data ?? {},
252
- c.headers ?? {},
253
- c.config ?? {},
254
- c.onClose,
255
- c.onAfterLeave,
256
- c.queryStringArrayFormat ?? "brackets",
257
- c.navigate ?? Lt("navigate"),
258
- c.onStart,
259
- c.onSuccess,
260
- c.onError
261
- ).then((d) => {
262
- const v = c.listeners ?? {};
263
- return Object.keys(v).forEach((w) => {
264
- const p = Pe(w);
265
- d.on(p, v[w]);
266
- }), d;
267
- }), g = (h, c, d = {}, v = {}, w = {}, p = null, x = null, O = "brackets", N = !1, D = null, C = null, I = null) => {
268
- const B = ft();
269
- return new Promise((R, k) => {
270
- if (h.startsWith("#")) {
271
- R(m(h.substring(1), w, p, x));
390
+ const visitModal = (url, options = {}) => visit(
391
+ url,
392
+ options.method ?? "get",
393
+ options.data ?? {},
394
+ options.headers ?? {},
395
+ options.config ?? {},
396
+ options.onClose ?? null,
397
+ options.onAfterLeave ?? null,
398
+ options.queryStringArrayFormat ?? "brackets",
399
+ options.navigate ?? getConfig("navigate"),
400
+ options.onStart ?? null,
401
+ options.onSuccess ?? null,
402
+ options.onError ?? null,
403
+ options.props ?? null
404
+ ).then((modal) => {
405
+ const listeners = options.listeners ?? {};
406
+ Object.keys(listeners).forEach((event) => {
407
+ const eventName = kebabCase(event);
408
+ modal.on(eventName, listeners[event]);
409
+ });
410
+ return modal;
411
+ });
412
+ const updateBrowserUrl = (url, useBrowserHistory, modalData) => {
413
+ if (!url || !useBrowserHistory || typeof window === "undefined") {
414
+ return;
415
+ }
416
+ router.push({
417
+ url,
418
+ preserveScroll: true,
419
+ preserveState: true,
420
+ // Store modal data in page props for history navigation
421
+ props: modalData ? (currentProps) => ({
422
+ ...currentProps,
423
+ _inertiaui_modal: {
424
+ ...modalData,
425
+ baseUrl
426
+ }
427
+ }) : void 0
428
+ });
429
+ };
430
+ const visit = (href, method, payload = {}, headers = {}, config = {}, onClose = null, onAfterLeave = null, queryStringArrayFormat = "brackets", useBrowserHistory = false, onStart = null, onSuccess = null, onError = null, props = null) => {
431
+ const modalId = generateId();
432
+ return new Promise((resolve, reject) => {
433
+ if (href.startsWith("#")) {
434
+ resolve(pushLocalModal(href.substring(1), config, onClose, onAfterLeave, props));
272
435
  return;
273
436
  }
274
- const [j, ge] = Yr(c, h || "", d, O);
275
- let ce = N && t.length === 0;
276
- if (t.length === 0 && (xe = typeof window < "u" ? window.location.href : ""), v = {
277
- ...v,
437
+ const [url, data] = mergeDataIntoQueryString(method, href || "", payload, queryStringArrayFormat);
438
+ const cachedResponse = getCachedResponse(url, method, data);
439
+ if (cachedResponse) {
440
+ onSuccess?.(cachedResponse);
441
+ pushFromResponseData(cachedResponse.data, config, onClose, onAfterLeave).then((modal) => {
442
+ updateBrowserUrl(cachedResponse.data.url, useBrowserHistory, cachedResponse.data);
443
+ resolve(modal);
444
+ }).catch(reject);
445
+ return;
446
+ }
447
+ if (stackRef.current.length === 0) {
448
+ baseUrl = typeof window !== "undefined" ? window.location.href : "";
449
+ }
450
+ const requestHeaders = {
451
+ ...headers,
278
452
  Accept: "text/html, application/xhtml+xml",
279
453
  "X-Requested-With": "XMLHttpRequest",
280
- "X-Inertia": !0,
281
- "X-Inertia-Version": rr,
282
- "X-InertiaUI-Modal": B,
283
- "X-InertiaUI-Modal-Use-Router": ce ? 1 : 0,
284
- "X-InertiaUI-Modal-Base-Url": xe
285
- }, ce)
286
- return Ve = {}, ye[B] = {
287
- config: w,
288
- onClose: p,
289
- onAfterLeave: x
290
- }, Me.visit(j, {
291
- method: c,
292
- data: ge,
293
- headers: v,
294
- preserveScroll: !0,
295
- preserveState: !0,
296
- onError(...A) {
297
- I == null || I(...A), k(...A);
298
- },
299
- onStart(...A) {
300
- D == null || D(...A);
301
- },
302
- onSuccess(...A) {
303
- C == null || C(...A);
304
- },
305
- onBefore: () => {
306
- Ve[B] = R;
307
- }
308
- });
309
- D == null || D();
310
- const Q = (A) => {
311
- try {
312
- _t.progress && A(_t.progress);
313
- } catch {
314
- }
454
+ "X-Inertia": "true",
455
+ "X-Inertia-Version": pageVersion ?? "",
456
+ "X-InertiaUI-Modal": modalId,
457
+ "X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
315
458
  };
316
- Q((A) => A.start()), Ge({
317
- url: j,
318
- method: c,
319
- data: ge,
320
- headers: v
321
- }).then((A) => {
322
- C == null || C(A), R(s(A.data, w, p, x));
323
- }).catch((...A) => {
324
- I == null || I(...A), k(...A);
459
+ onStart?.();
460
+ progress?.start();
461
+ Axios({
462
+ url,
463
+ method,
464
+ data,
465
+ headers: requestHeaders
466
+ }).then((response) => {
467
+ onSuccess?.(response);
468
+ pushFromResponseData(response.data, config, onClose, onAfterLeave).then((modal) => {
469
+ updateBrowserUrl(response.data.url, useBrowserHistory, response.data);
470
+ resolve(modal);
471
+ }).catch(reject);
472
+ }).catch((...args) => {
473
+ onError?.(...args);
474
+ reject(args[0]);
325
475
  }).finally(() => {
326
- Q((A) => A.finish());
476
+ progress?.finish();
327
477
  });
328
478
  });
329
- }, E = {
330
- stack: t,
331
- localModals: n,
332
- push: u,
333
- pushFromResponseData: s,
334
- length: () => pt.length,
335
- closeAll: () => {
336
- pt.reverse().forEach((h) => h.close());
337
- },
338
- reset: () => i(() => []),
339
- visit: g,
340
- visitModal: b,
341
- registerLocalModal: (h, c) => {
342
- l((d) => ({
343
- ...d,
344
- [h]: { name: h, callback: c }
345
- }));
346
- },
347
- removeLocalModal: (h) => {
348
- l((c) => {
349
- const d = { ...c };
350
- return delete d[h], d;
351
- });
352
- },
353
- onModalOnBase: (h) => {
354
- const c = Ve[h.id];
355
- c && (c(h), delete Ve[h.id]);
356
- }
357
479
  };
358
- return /* @__PURE__ */ P(Qe.Provider, { value: E, children: e });
359
- }, et = () => {
360
- const e = H(Qe);
361
- if (e === null)
362
- throw new Error("useModalStack must be used within a ModalStackProvider");
363
- return e;
364
- }, Dt = ["closeButton", "closeExplicitly", "maxWidth", "paddingClasses", "panelClasses", "position", "slideover"], on = (e) => {
365
- e.initialPage && (rr = e.initialPage.version), e.resolveComponent && (nr = e.resolveComponent);
366
- }, Mi = (e, t) => (on(t), /* @__PURE__ */ P(ln, { children: /* @__PURE__ */ P(e, { ...t, children: ({ Component: n, props: l, key: i }) => /* @__PURE__ */ he(Mt, { children: [
367
- (() => {
368
- const s = Re(n, { key: i, ...l });
369
- return typeof n.layout == "function" ? n.layout(s) : Array.isArray(n.layout) ? n.layout.concat(s).reverse().reduce((u, m) => Re(m, l, u)) : s;
370
- })(),
371
- /* @__PURE__ */ P(an, {})
372
- ] }) }) })), an = ({ children: e }) => {
373
- var s, o;
374
- const t = H(Qe), r = qr();
375
- let n = !1, l = !!((s = r.props) != null && s._inertiaui_modal);
376
- L(() => Me.on("start", () => n = !0), []), L(() => Me.on("finish", () => n = !1), []), L(
377
- () => Me.on("navigate", function(u) {
378
- const m = u.detail.page.props._inertiaui_modal;
379
- if (!m) {
380
- t.closeAll(), xe = null, l = !1;
381
- return;
382
- }
383
- xe = m.baseUrl, t.pushFromResponseData(m, {}, () => {
384
- if (!m.baseUrl) {
385
- console.error("No base url in modal response data so cannot navigate back");
386
- return;
387
- }
388
- !n && typeof window < "u" && window.location.href !== m.baseUrl && Me.visit(m.baseUrl, {
389
- preserveScroll: !0,
390
- preserveState: !0
391
- });
392
- }).then(t.onModalOnBase);
393
- }),
394
- []
395
- );
396
- const i = (u) => {
397
- var m;
398
- return u.headers["X-InertiaUI-Modal-Base-Url"] = xe ?? (l ? (m = r.props._inertiaui_modal) == null ? void 0 : m.baseUrl : null), u;
480
+ const registerLocalModal = (name, callback) => {
481
+ setLocalModals((prevLocalModals) => ({
482
+ ...prevLocalModals,
483
+ [name]: { name, callback }
484
+ }));
399
485
  };
400
- L(() => (Ge.interceptors.request.use(i), () => Ge.interceptors.request.eject(i)), []);
401
- const a = S();
402
- return L(() => {
403
- var b, g;
404
- const u = (b = r.props) == null ? void 0 : b._inertiaui_modal, m = a.current;
405
- a.current = u, u && m && u.component === m.component && Qr(u.url, m.url) && ((g = t.stack[0]) == null || g.updateProps(u.props ?? {}));
406
- }, [(o = r.props) == null ? void 0 : o._inertiaui_modal]), /* @__PURE__ */ he(Mt, { children: [
407
- e,
408
- t.stack.length > 0 && /* @__PURE__ */ P(ir, { index: 0 })
409
- ] });
410
- }, kt = $.createContext(null);
411
- kt.displayName = "ModalIndexContext";
412
- const lr = () => {
413
- const e = $.useContext(kt);
414
- if (e === void 0)
415
- throw new Error("useModalIndex must be used within a ModalIndexProvider");
416
- return e;
417
- }, ir = ({ index: e }) => {
418
- const { stack: t } = et(), r = _(() => t[e], [t, e]);
419
- return (r == null ? void 0 : r.component) && /* @__PURE__ */ P(kt.Provider, { value: e, children: /* @__PURE__ */ P(
420
- r.component,
421
- {
422
- ...r.props,
423
- onModalEvent: (...n) => r.emit(...n)
424
- }
425
- ) });
426
- };
427
- function or() {
428
- return et().stack[lr()] ?? null;
429
- }
430
- const sn = ({ children: e, data: t, fallback: r }) => {
431
- if (!t)
432
- throw new Error("`<Deferred>` requires a `data` prop to be a string or array of strings");
433
- const [n, l] = F(!1), i = Array.isArray(t) ? t : [t], a = or().props;
434
- return L(() => {
435
- l(i.every((s) => a[s] !== void 0));
436
- }, [a, i]), n ? e : r;
437
- };
438
- sn.displayName = "InertiaModalDeferred";
439
- const ar = Pt(({ name: e, children: t, onFocus: r = null, onBlur: n = null, onClose: l = null, onSuccess: i = null, ...a }, s) => {
440
- const o = lr(), { stack: u, registerLocalModal: m, removeLocalModal: b } = et(), [g, y] = F(null), f = _(() => e ? g : u[o], [e, g, o, u]), E = _(() => {
441
- var p;
442
- return (p = u.find((x) => x.shouldRender && x.index > (f == null ? void 0 : f.index))) == null ? void 0 : p.index;
443
- }, [o, u]), h = _(() => (f == null ? void 0 : f.config.slideover) ?? a.slideover ?? Lt("type") === "slideover", [a.slideover]), c = _(
444
- () => ({
445
- slideover: h,
446
- closeButton: a.closeButton ?? we(h, "closeButton"),
447
- closeExplicitly: a.closeExplicitly ?? we(h, "closeExplicitly"),
448
- maxWidth: a.maxWidth ?? we(h, "maxWidth"),
449
- paddingClasses: a.paddingClasses ?? we(h, "paddingClasses"),
450
- panelClasses: a.panelClasses ?? we(h, "panelClasses"),
451
- position: a.position ?? we(h, "position"),
452
- ...f == null ? void 0 : f.config
453
- }),
454
- [a, f == null ? void 0 : f.config]
455
- );
456
- L(() => {
457
- if (e) {
458
- let p = null;
459
- return m(e, (x) => {
460
- p = x.registerEventListenersFromProps(a), y(x);
461
- }), () => {
462
- p == null || p(), p = null, b(e);
463
- };
464
- }
465
- return f.registerEventListenersFromProps(a);
466
- }, [e]);
467
- const d = S(f);
468
- L(() => {
469
- d.current = f;
470
- }, [f]), L(() => {
471
- f !== null && (f.isOpen ? i == null || i() : l == null || l());
472
- }, [f == null ? void 0 : f.isOpen]);
473
- const [v, w] = F(!1);
474
- return L(() => {
475
- v && f !== null && f.isOpen && (f.onTopOfStack ? r == null || r() : n == null || n()), w(!0);
476
- }, [f == null ? void 0 : f.onTopOfStack]), tr(
477
- s,
478
- () => ({
479
- afterLeave: () => {
480
- var p;
481
- return (p = d.current) == null ? void 0 : p.afterLeave();
482
- },
483
- close: () => {
484
- var p;
485
- return (p = d.current) == null ? void 0 : p.close();
486
- },
487
- emit: (...p) => {
488
- var x;
489
- return (x = d.current) == null ? void 0 : x.emit(...p);
490
- },
491
- getChildModal: () => {
492
- var p;
493
- return (p = d.current) == null ? void 0 : p.getChildModal();
494
- },
495
- getParentModal: () => {
496
- var p;
497
- return (p = d.current) == null ? void 0 : p.getParentModal();
498
- },
499
- reload: (...p) => {
500
- var x;
501
- return (x = d.current) == null ? void 0 : x.reload(...p);
502
- },
503
- setOpen: () => {
504
- var p;
505
- return (p = d.current) == null ? void 0 : p.setOpen();
506
- },
507
- get id() {
508
- var p;
509
- return (p = d.current) == null ? void 0 : p.id;
510
- },
511
- get index() {
512
- var p;
513
- return (p = d.current) == null ? void 0 : p.index;
514
- },
515
- get isOpen() {
516
- var p;
517
- return (p = d.current) == null ? void 0 : p.isOpen;
518
- },
519
- get config() {
520
- var p;
521
- return (p = d.current) == null ? void 0 : p.config;
522
- },
523
- get modalContext() {
524
- return d.current;
525
- },
526
- get onTopOfStack() {
527
- var p;
528
- return (p = d.current) == null ? void 0 : p.onTopOfStack;
529
- },
530
- get shouldRender() {
531
- var p;
532
- return (p = d.current) == null ? void 0 : p.shouldRender;
533
- }
534
- }),
535
- [f]
536
- ), (f == null ? void 0 : f.shouldRender) && /* @__PURE__ */ he(Mt, { children: [
537
- typeof t == "function" ? t({
538
- afterLeave: f.afterLeave,
539
- close: f.close,
540
- config: c,
541
- emit: f.emit,
542
- getChildModal: f.getChildModal,
543
- getParentModal: f.getParentModal,
544
- id: f.id,
545
- index: f.index,
546
- isOpen: f.isOpen,
547
- modalContext: f,
548
- onTopOfStack: f.onTopOfStack,
549
- reload: f.reload,
550
- setOpen: f.setOpen,
551
- shouldRender: f.shouldRender
552
- }) : t,
553
- E && /* @__PURE__ */ P(ir, { index: E })
554
- ] });
555
- });
556
- ar.displayName = "HeadlessModal";
557
- function sr(e) {
558
- var t, r, n = "";
559
- if (typeof e == "string" || typeof e == "number") n += e;
560
- else if (typeof e == "object") if (Array.isArray(e)) {
561
- var l = e.length;
562
- for (t = 0; t < l; t++) e[t] && (r = sr(e[t])) && (n && (n += " "), n += r);
563
- } else for (r in e) e[r] && (n && (n += " "), n += r);
564
- return n;
565
- }
566
- function Ke() {
567
- for (var e, t, r = 0, n = "", l = arguments.length; r < l; r++) (e = arguments[r]) && (t = sr(e)) && (n && (n += " "), n += t);
568
- return n;
569
- }
570
- var un = Object.defineProperty, cn = (e, t, r) => t in e ? un(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, mt = (e, t, r) => (cn(e, typeof t != "symbol" ? t + "" : t, r), r);
571
- let dn = class {
572
- constructor() {
573
- mt(this, "current", this.detect()), mt(this, "handoffState", "pending"), mt(this, "currentId", 0);
574
- }
575
- set(t) {
576
- this.current !== t && (this.handoffState = "pending", this.currentId = 0, this.current = t);
577
- }
578
- reset() {
579
- this.set(this.detect());
580
- }
581
- nextId() {
582
- return ++this.currentId;
583
- }
584
- get isServer() {
585
- return this.current === "server";
586
- }
587
- get isClient() {
588
- return this.current === "client";
589
- }
590
- detect() {
591
- return typeof window > "u" || typeof document > "u" ? "server" : "client";
592
- }
593
- handoff() {
594
- this.handoffState === "pending" && (this.handoffState = "complete");
595
- }
596
- get isHandoffComplete() {
597
- return this.handoffState === "complete";
598
- }
599
- }, Z = new dn();
600
- function De(e) {
601
- var t;
602
- return Z.isServer ? null : e == null ? document : (t = e == null ? void 0 : e.ownerDocument) != null ? t : document;
603
- }
604
- function bt(e) {
605
- var t, r;
606
- return Z.isServer ? null : e == null ? document : (r = (t = e == null ? void 0 : e.getRootNode) == null ? void 0 : t.call(e)) != null ? r : document;
607
- }
608
- function ur(e) {
609
- var t, r;
610
- return (r = (t = bt(e)) == null ? void 0 : t.activeElement) != null ? r : null;
611
- }
612
- function fn(e) {
613
- return ur(e) === e;
614
- }
615
- function tt(e) {
616
- typeof queueMicrotask == "function" ? queueMicrotask(e) : Promise.resolve().then(e).catch((t) => setTimeout(() => {
617
- throw t;
618
- }));
619
- }
620
- function ne() {
621
- let e = [], t = { addEventListener(r, n, l, i) {
622
- return r.addEventListener(n, l, i), t.add(() => r.removeEventListener(n, l, i));
623
- }, requestAnimationFrame(...r) {
624
- let n = requestAnimationFrame(...r);
625
- return t.add(() => cancelAnimationFrame(n));
626
- }, nextFrame(...r) {
627
- return t.requestAnimationFrame(() => t.requestAnimationFrame(...r));
628
- }, setTimeout(...r) {
629
- let n = setTimeout(...r);
630
- return t.add(() => clearTimeout(n));
631
- }, microTask(...r) {
632
- let n = { current: !0 };
633
- return tt(() => {
634
- n.current && r[0]();
635
- }), t.add(() => {
636
- n.current = !1;
637
- });
638
- }, style(r, n, l) {
639
- let i = r.style.getPropertyValue(n);
640
- return Object.assign(r.style, { [n]: l }), this.add(() => {
641
- Object.assign(r.style, { [n]: i });
486
+ const removeLocalModal = (name) => {
487
+ setLocalModals((prevLocalModals) => {
488
+ const newLocalModals = { ...prevLocalModals };
489
+ delete newLocalModals[name];
490
+ return newLocalModals;
642
491
  });
643
- }, group(r) {
644
- let n = ne();
645
- return r(n), this.add(() => n.dispose());
646
- }, add(r) {
647
- return e.includes(r) || e.push(r), () => {
648
- let n = e.indexOf(r);
649
- if (n >= 0) for (let l of e.splice(n, 1)) l();
650
- };
651
- }, dispose() {
652
- for (let r of e.splice(0)) r();
653
- } };
654
- return t;
655
- }
656
- function rt() {
657
- let [e] = F(ne);
658
- return L(() => () => e.dispose(), [e]), e;
659
- }
660
- let U = (e, t) => {
661
- Z.isServer ? L(e, t) : Vr(e, t);
662
- };
663
- function ve(e) {
664
- let t = S(e);
665
- return U(() => {
666
- t.current = e;
667
- }, [e]), t;
668
- }
669
- let M = function(e) {
670
- let t = ve(e);
671
- return $.useCallback((...r) => t.current(...r), [t]);
672
- };
673
- function je(e) {
674
- return _(() => e, Object.values(e));
675
- }
676
- let pn = z(void 0);
677
- function mn() {
678
- return H(pn);
679
- }
680
- function xt(...e) {
681
- return Array.from(new Set(e.flatMap((t) => typeof t == "string" ? t.split(" ") : []))).filter(Boolean).join(" ");
682
- }
683
- function re(e, t, ...r) {
684
- if (e in t) {
685
- let l = t[e];
686
- return typeof l == "function" ? l(...r) : l;
687
- }
688
- let n = new Error(`Tried to handle "${e}" but there is no handler defined. Only defined handlers are: ${Object.keys(t).map((l) => `"${l}"`).join(", ")}.`);
689
- throw Error.captureStackTrace && Error.captureStackTrace(n, re), n;
690
- }
691
- var qe = ((e) => (e[e.None = 0] = "None", e[e.RenderStrategy = 1] = "RenderStrategy", e[e.Static = 2] = "Static", e))(qe || {}), oe = ((e) => (e[e.Unmount = 0] = "Unmount", e[e.Hidden = 1] = "Hidden", e))(oe || {});
692
- function G() {
693
- let e = vn();
694
- return W((t) => hn({ mergeRefs: e, ...t }), [e]);
695
- }
696
- function hn({ ourProps: e, theirProps: t, slot: r, defaultTag: n, features: l, visible: i = !0, name: a, mergeRefs: s }) {
697
- s = s ?? gn;
698
- let o = cr(t, e);
699
- if (i) return Be(o, r, n, a, s);
700
- let u = l ?? 0;
701
- if (u & 2) {
702
- let { static: m = !1, ...b } = o;
703
- if (m) return Be(b, r, n, a, s);
704
- }
705
- if (u & 1) {
706
- let { unmount: m = !0, ...b } = o;
707
- return re(m ? 0 : 1, { 0() {
708
- return null;
709
- }, 1() {
710
- return Be({ ...b, hidden: !0, style: { display: "none" } }, r, n, a, s);
711
- } });
712
- }
713
- return Be(o, r, n, a, s);
714
- }
715
- function Be(e, t = {}, r, n, l) {
716
- let { as: i = r, children: a, refName: s = "ref", ...o } = ht(e, ["unmount", "static"]), u = e.ref !== void 0 ? { [s]: e.ref } : {}, m = typeof a == "function" ? a(t) : a;
717
- "className" in o && o.className && typeof o.className == "function" && (o.className = o.className(t)), o["aria-labelledby"] && o["aria-labelledby"] === o.id && (o["aria-labelledby"] = void 0);
718
- let b = {};
719
- if (t) {
720
- let g = !1, y = [];
721
- for (let [f, E] of Object.entries(t)) typeof E == "boolean" && (g = !0), E === !0 && y.push(f.replace(/([A-Z])/g, (h) => `-${h.toLowerCase()}`));
722
- if (g) {
723
- b["data-headlessui-state"] = y.join(" ");
724
- for (let f of y) b[`data-${f}`] = "";
725
- }
726
- }
727
- if (Fe(i) && (Object.keys(de(o)).length > 0 || Object.keys(de(b)).length > 0)) if (!Br(m) || Array.isArray(m) && m.length > 1 || yn(m)) {
728
- if (Object.keys(de(o)).length > 0) throw new Error(['Passing props on "Fragment"!', "", `The current component <${n} /> is rendering a "Fragment".`, "However we need to passthrough the following props:", Object.keys(de(o)).concat(Object.keys(de(b))).map((g) => ` - ${g}`).join(`
729
- `), "", "You can apply a few solutions:", ['Add an `as="..."` prop, to ensure that we render an actual element instead of a "Fragment".', "Render a single element as the child so that we can forward the props onto that element."].map((g) => ` - ${g}`).join(`
730
- `)].join(`
731
- `));
732
- } else {
733
- let g = m.props, y = g == null ? void 0 : g.className, f = typeof y == "function" ? (...c) => xt(y(...c), o.className) : xt(y, o.className), E = f ? { className: f } : {}, h = cr(m.props, de(ht(o, ["ref"])));
734
- for (let c in b) c in h && delete b[c];
735
- return Xr(m, Object.assign({}, h, b, u, { ref: l(wn(m), u.ref) }, E));
736
- }
737
- return Re(i, Object.assign({}, ht(o, ["ref"]), !Fe(i) && u, !Fe(i) && b), m);
738
- }
739
- function vn() {
740
- let e = S([]), t = W((r) => {
741
- for (let n of e.current) n != null && (typeof n == "function" ? n(r) : n.current = r);
742
- }, []);
743
- return (...r) => {
744
- if (!r.every((n) => n == null)) return e.current = r, t;
745
492
  };
746
- }
747
- function gn(...e) {
748
- return e.every((t) => t == null) ? void 0 : (t) => {
749
- for (let r of e) r != null && (typeof r == "function" ? r(t) : r.current = t);
493
+ const value = {
494
+ get stack() {
495
+ return stackRef.current;
496
+ },
497
+ localModals,
498
+ push,
499
+ pushFromResponseData,
500
+ length: () => stackRef.current.length,
501
+ closeAll: (force = false) => {
502
+ if (force) {
503
+ updateStack(() => []);
504
+ } else {
505
+ [...stackRef.current].reverse().forEach((modal) => modal.close());
506
+ }
507
+ },
508
+ reset: () => updateStack(() => []),
509
+ visit,
510
+ visitModal,
511
+ registerLocalModal,
512
+ removeLocalModal
750
513
  };
751
- }
752
- function cr(...e) {
753
- if (e.length === 0) return {};
754
- if (e.length === 1) return e[0];
755
- let t = {}, r = {};
756
- for (let n of e) for (let l in n) l.startsWith("on") && typeof n[l] == "function" ? (r[l] != null || (r[l] = []), r[l].push(n[l])) : t[l] = n[l];
757
- if (t.disabled || t["aria-disabled"]) for (let n in r) /^(on(?:Click|Pointer|Mouse|Key)(?:Down|Up|Press)?)$/.test(n) && (r[n] = [(l) => {
758
- var i;
759
- return (i = l == null ? void 0 : l.preventDefault) == null ? void 0 : i.call(l);
760
- }]);
761
- for (let n in r) Object.assign(t, { [n](l, ...i) {
762
- let a = r[n];
763
- for (let s of a) {
764
- if ((l instanceof Event || (l == null ? void 0 : l.nativeEvent) instanceof Event) && l.defaultPrevented) return;
765
- s(l, ...i);
766
- }
767
- } });
768
- return t;
769
- }
770
- function V(e) {
771
- var t;
772
- return Object.assign(Pt(e), { displayName: (t = e.displayName) != null ? t : e.name });
773
- }
774
- function de(e) {
775
- let t = Object.assign({}, e);
776
- for (let r in t) t[r] === void 0 && delete t[r];
777
- return t;
778
- }
779
- function ht(e, t = []) {
780
- let r = Object.assign({}, e);
781
- for (let n of t) n in r && delete r[n];
782
- return r;
783
- }
784
- function wn(e) {
785
- return $.version.split(".")[0] >= "19" ? e.props.ref : e.ref;
786
- }
787
- function Fe(e) {
788
- return e === ue || e === Symbol.for("react.fragment");
789
- }
790
- function yn(e) {
791
- return Fe(e.type);
792
- }
793
- let bn = "span";
794
- var Ye = ((e) => (e[e.None = 1] = "None", e[e.Focusable = 2] = "Focusable", e[e.Hidden = 4] = "Hidden", e))(Ye || {});
795
- function xn(e, t) {
796
- var r;
797
- let { features: n = 1, ...l } = e, i = { ref: t, "aria-hidden": (n & 2) === 2 ? !0 : (r = l["aria-hidden"]) != null ? r : void 0, hidden: (n & 4) === 4 ? !0 : void 0, style: { position: "fixed", top: 1, left: 1, width: 1, height: 0, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0, 0, 0, 0)", whiteSpace: "nowrap", borderWidth: "0", ...(n & 4) === 4 && (n & 2) !== 2 && { display: "none" } } };
798
- return G()({ ourProps: i, theirProps: l, slot: {}, defaultTag: bn, name: "Hidden" });
799
- }
800
- let Et = V(xn);
801
- function En(e) {
802
- return typeof e != "object" || e === null ? !1 : "nodeType" in e;
803
- }
804
- function se(e) {
805
- return En(e) && "tagName" in e;
806
- }
807
- function me(e) {
808
- return se(e) && "accessKey" in e;
809
- }
810
- function ae(e) {
811
- return se(e) && "tabIndex" in e;
812
- }
813
- function $n(e) {
814
- return se(e) && "style" in e;
815
- }
816
- function On(e) {
817
- return me(e) && e.nodeName === "IFRAME";
818
- }
819
- function Sn(e) {
820
- return me(e) && e.nodeName === "INPUT";
821
- }
822
- let dr = Symbol();
823
- function Tn(e, t = !0) {
824
- return Object.assign(e, { [dr]: t });
825
- }
826
- function J(...e) {
827
- let t = S(e);
828
- L(() => {
829
- t.current = e;
830
- }, [e]);
831
- let r = M((n) => {
832
- for (let l of t.current) l != null && (typeof l == "function" ? l(n) : l.current = n);
833
- });
834
- return e.every((n) => n == null || (n == null ? void 0 : n[dr])) ? void 0 : r;
835
- }
836
- let At = z(null);
837
- At.displayName = "DescriptionContext";
838
- function fr() {
839
- let e = H(At);
840
- if (e === null) {
841
- let t = new Error("You used a <Description /> component, but it is not inside a relevant parent.");
842
- throw Error.captureStackTrace && Error.captureStackTrace(t, fr), t;
843
- }
844
- return e;
845
- }
846
- function Pn() {
847
- let [e, t] = F([]);
848
- return [e.length > 0 ? e.join(" ") : void 0, _(() => function(r) {
849
- let n = M((i) => (t((a) => [...a, i]), () => t((a) => {
850
- let s = a.slice(), o = s.indexOf(i);
851
- return o !== -1 && s.splice(o, 1), s;
852
- }))), l = _(() => ({ register: n, slot: r.slot, name: r.name, props: r.props, value: r.value }), [n, r.slot, r.name, r.props, r.value]);
853
- return $.createElement(At.Provider, { value: l }, r.children);
854
- }, [t])];
855
- }
856
- let Mn = "p";
857
- function Ln(e, t) {
858
- let r = _e(), n = mn(), { id: l = `headlessui-description-${r}`, ...i } = e, a = fr(), s = J(t);
859
- U(() => a.register(l), [l, a.register]);
860
- let o = je({ ...a.slot, disabled: n || !1 }), u = { ref: s, ...a.props, id: l };
861
- return G()({ ourProps: u, theirProps: i, slot: o, defaultTag: Mn, name: a.name || "Description" });
862
- }
863
- let kn = V(Ln), An = Object.assign(kn, {});
864
- var pr = ((e) => (e.Space = " ", e.Enter = "Enter", e.Escape = "Escape", e.Backspace = "Backspace", e.Delete = "Delete", e.ArrowLeft = "ArrowLeft", e.ArrowUp = "ArrowUp", e.ArrowRight = "ArrowRight", e.ArrowDown = "ArrowDown", e.Home = "Home", e.End = "End", e.PageUp = "PageUp", e.PageDown = "PageDown", e.Tab = "Tab", e))(pr || {});
865
- let Cn = z(() => {
866
- });
867
- function Fn({ value: e, children: t }) {
868
- return $.createElement(Cn.Provider, { value: e }, t);
869
- }
870
- let mr = class extends Map {
871
- constructor(t) {
872
- super(), this.factory = t;
873
- }
874
- get(t) {
875
- let r = super.get(t);
876
- return r === void 0 && (r = this.factory(t), this.set(t, r)), r;
877
- }
514
+ return /* @__PURE__ */ jsx(ModalStackContext.Provider, { value, children });
878
515
  };
879
- var Nn = Object.defineProperty, In = (e, t, r) => t in e ? Nn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Rn = (e, t, r) => (In(e, t + "", r), r), hr = (e, t, r) => {
880
- if (!t.has(e)) throw TypeError("Cannot " + r);
881
- }, X = (e, t, r) => (hr(e, t, "read from private field"), r ? r.call(e) : t.get(e)), vt = (e, t, r) => {
882
- if (t.has(e)) throw TypeError("Cannot add the same private member more than once");
883
- t instanceof WeakSet ? t.add(e) : t.set(e, r);
884
- }, jt = (e, t, r, n) => (hr(e, t, "write to private field"), t.set(e, r), r), Y, Le, ke;
885
- let _n = class {
886
- constructor(t) {
887
- vt(this, Y, {}), vt(this, Le, new mr(() => /* @__PURE__ */ new Set())), vt(this, ke, /* @__PURE__ */ new Set()), Rn(this, "disposables", ne()), jt(this, Y, t), Z.isServer && this.disposables.microTask(() => {
888
- this.dispose();
889
- });
890
- }
891
- dispose() {
892
- this.disposables.dispose();
893
- }
894
- get state() {
895
- return X(this, Y);
896
- }
897
- subscribe(t, r) {
898
- if (Z.isServer) return () => {
899
- };
900
- let n = { selector: t, callback: r, current: t(X(this, Y)) };
901
- return X(this, ke).add(n), this.disposables.add(() => {
902
- X(this, ke).delete(n);
903
- });
904
- }
905
- on(t, r) {
906
- return Z.isServer ? () => {
907
- } : (X(this, Le).get(t).add(r), this.disposables.add(() => {
908
- X(this, Le).get(t).delete(r);
909
- }));
910
- }
911
- send(t) {
912
- let r = this.reduce(X(this, Y), t);
913
- if (r !== X(this, Y)) {
914
- jt(this, Y, r);
915
- for (let n of X(this, ke)) {
916
- let l = n.selector(X(this, Y));
917
- vr(n.current, l) || (n.current = l, n.callback(l));
918
- }
919
- for (let n of X(this, Le).get(t.type)) n(X(this, Y), t);
920
- }
516
+ const useModalStack = () => {
517
+ const context = useContext(ModalStackContext);
518
+ if (context === null) {
519
+ throw new Error("useModalStack must be used within a ModalStackProvider");
921
520
  }
521
+ return context;
922
522
  };
923
- Y = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap();
924
- function vr(e, t) {
925
- return Object.is(e, t) ? !0 : typeof e != "object" || e === null || typeof t != "object" || t === null ? !1 : Array.isArray(e) && Array.isArray(t) ? e.length !== t.length ? !1 : gt(e[Symbol.iterator](), t[Symbol.iterator]()) : e instanceof Map && t instanceof Map || e instanceof Set && t instanceof Set ? e.size !== t.size ? !1 : gt(e.entries(), t.entries()) : Wt(e) && Wt(t) ? gt(Object.entries(e)[Symbol.iterator](), Object.entries(t)[Symbol.iterator]()) : !1;
926
- }
927
- function gt(e, t) {
928
- do {
929
- let r = e.next(), n = t.next();
930
- if (r.done && n.done) return !0;
931
- if (r.done || n.done || !Object.is(r.value, n.value)) return !1;
932
- } while (!0);
933
- }
934
- function Wt(e) {
935
- if (Object.prototype.toString.call(e) !== "[object Object]") return !1;
936
- let t = Object.getPrototypeOf(e);
937
- return t === null || Object.getPrototypeOf(t) === null;
938
- }
939
- var Dn = Object.defineProperty, jn = (e, t, r) => t in e ? Dn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ut = (e, t, r) => (jn(e, typeof t != "symbol" ? t + "" : t, r), r), Wn = ((e) => (e[e.Push = 0] = "Push", e[e.Pop = 1] = "Pop", e))(Wn || {});
940
- let Un = { 0(e, t) {
941
- let r = t.id, n = e.stack, l = e.stack.indexOf(r);
942
- if (l !== -1) {
943
- let i = e.stack.slice();
944
- return i.splice(l, 1), i.push(r), n = i, { ...e, stack: n };
945
- }
946
- return { ...e, stack: [...e.stack, r] };
947
- }, 1(e, t) {
948
- let r = t.id, n = e.stack.indexOf(r);
949
- if (n === -1) return e;
950
- let l = e.stack.slice();
951
- return l.splice(n, 1), { ...e, stack: l };
952
- } }, Hn = class gr extends _n {
953
- constructor() {
954
- super(...arguments), Ut(this, "actions", { push: (t) => this.send({ type: 0, id: t }), pop: (t) => this.send({ type: 1, id: t }) }), Ut(this, "selectors", { isTop: (t, r) => t.stack[t.stack.length - 1] === r, inStack: (t, r) => t.stack.includes(r) });
523
+ const modalPropNames = ["closeButton", "closeExplicitly", "closeOnClickOutside", "maxWidth", "paddingClasses", "panelClasses", "position", "slideover"];
524
+ const initFromPageProps = (pageProps) => {
525
+ if (pageProps.initialPage) {
526
+ pageVersion = pageProps.initialPage.version ?? null;
955
527
  }
956
- static new() {
957
- return new gr({ stack: [] });
958
- }
959
- reduce(t, r) {
960
- return re(r.type, Un, t, r);
528
+ if (pageProps.resolveComponent) {
529
+ resolveComponent = pageProps.resolveComponent;
961
530
  }
962
531
  };
963
- const wr = new mr(() => Hn.new());
964
- var Xe = { exports: {} }, wt = {};
965
- /**
966
- * @license React
967
- * use-sync-external-store-with-selector.production.js
968
- *
969
- * Copyright (c) Meta Platforms, Inc. and affiliates.
970
- *
971
- * This source code is licensed under the MIT license found in the
972
- * LICENSE file in the root directory of this source tree.
973
- */
974
- var Ht;
975
- function Vn() {
976
- if (Ht) return wt;
977
- Ht = 1;
978
- var e = $;
979
- function t(o, u) {
980
- return o === u && (o !== 0 || 1 / o === 1 / u) || o !== o && u !== u;
981
- }
982
- var r = typeof Object.is == "function" ? Object.is : t, n = e.useSyncExternalStore, l = e.useRef, i = e.useEffect, a = e.useMemo, s = e.useDebugValue;
983
- return wt.useSyncExternalStoreWithSelector = function(o, u, m, b, g) {
984
- var y = l(null);
985
- if (y.current === null) {
986
- var f = { hasValue: !1, value: null };
987
- y.current = f;
988
- } else f = y.current;
989
- y = a(
990
- function() {
991
- function h(p) {
992
- if (!c) {
993
- if (c = !0, d = p, p = b(p), g !== void 0 && f.hasValue) {
994
- var x = f.value;
995
- if (g(x, p))
996
- return v = x;
997
- }
998
- return v = p;
999
- }
1000
- if (x = v, r(d, p)) return x;
1001
- var O = b(p);
1002
- return g !== void 0 && g(x, O) ? (d = p, x) : (d = p, v = O);
1003
- }
1004
- var c = !1, d, v, w = m === void 0 ? null : m;
1005
- return [
1006
- function() {
1007
- return h(u());
1008
- },
1009
- w === null ? void 0 : function() {
1010
- return h(w());
1011
- }
1012
- ];
1013
- },
1014
- [u, m, b, g]
1015
- );
1016
- var E = n(o, y[0], y[1]);
1017
- return i(
1018
- function() {
1019
- f.hasValue = !0, f.value = E;
1020
- },
1021
- [E]
1022
- ), s(E), E;
1023
- }, wt;
1024
- }
1025
- var yt = {};
1026
- /**
1027
- * @license React
1028
- * use-sync-external-store-with-selector.development.js
1029
- *
1030
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1031
- *
1032
- * This source code is licensed under the MIT license found in the
1033
- * LICENSE file in the root directory of this source tree.
1034
- */
1035
- var Vt;
1036
- function Bn() {
1037
- return Vt || (Vt = 1, process.env.NODE_ENV !== "production" && (function() {
1038
- function e(o, u) {
1039
- return o === u && (o !== 0 || 1 / o === 1 / u) || o !== o && u !== u;
1040
- }
1041
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
1042
- var t = $, r = typeof Object.is == "function" ? Object.is : e, n = t.useSyncExternalStore, l = t.useRef, i = t.useEffect, a = t.useMemo, s = t.useDebugValue;
1043
- yt.useSyncExternalStoreWithSelector = function(o, u, m, b, g) {
1044
- var y = l(null);
1045
- if (y.current === null) {
1046
- var f = { hasValue: !1, value: null };
1047
- y.current = f;
1048
- } else f = y.current;
1049
- y = a(
1050
- function() {
1051
- function h(p) {
1052
- if (!c) {
1053
- if (c = !0, d = p, p = b(p), g !== void 0 && f.hasValue) {
1054
- var x = f.value;
1055
- if (g(x, p))
1056
- return v = x;
1057
- }
1058
- return v = p;
1059
- }
1060
- if (x = v, r(d, p))
1061
- return x;
1062
- var O = b(p);
1063
- return g !== void 0 && g(x, O) ? (d = p, x) : (d = p, v = O);
1064
- }
1065
- var c = !1, d, v, w = m === void 0 ? null : m;
1066
- return [
1067
- function() {
1068
- return h(u());
1069
- },
1070
- w === null ? void 0 : function() {
1071
- return h(w());
1072
- }
1073
- ];
1074
- },
1075
- [u, m, b, g]
1076
- );
1077
- var E = n(o, y[0], y[1]);
1078
- return i(
1079
- function() {
1080
- f.hasValue = !0, f.value = E;
1081
- },
1082
- [E]
1083
- ), s(E), E;
1084
- }, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
1085
- })()), yt;
1086
- }
1087
- var Bt;
1088
- function Xn() {
1089
- return Bt || (Bt = 1, process.env.NODE_ENV === "production" ? Xe.exports = Vn() : Xe.exports = Bn()), Xe.exports;
1090
- }
1091
- var zn = Xn();
1092
- function yr(e, t, r = vr) {
1093
- return zn.useSyncExternalStoreWithSelector(M((n) => e.subscribe(Gn, n)), M(() => e.state), M(() => e.state), M(t), r);
1094
- }
1095
- function Gn(e) {
1096
- return e;
1097
- }
1098
- function We(e, t) {
1099
- let r = _e(), n = wr.get(t), [l, i] = yr(n, W((a) => [n.selectors.isTop(a, r), n.selectors.inStack(a, r)], [n, r]));
1100
- return U(() => {
1101
- if (e) return n.actions.push(r), () => n.actions.pop(r);
1102
- }, [n, e, r]), e ? i ? l : !0 : !1;
1103
- }
1104
- let $t = /* @__PURE__ */ new Map(), Ne = /* @__PURE__ */ new Map();
1105
- function Xt(e) {
1106
- var t;
1107
- let r = (t = Ne.get(e)) != null ? t : 0;
1108
- return Ne.set(e, r + 1), r !== 0 ? () => zt(e) : ($t.set(e, { "aria-hidden": e.getAttribute("aria-hidden"), inert: e.inert }), e.setAttribute("aria-hidden", "true"), e.inert = !0, () => zt(e));
1109
- }
1110
- function zt(e) {
1111
- var t;
1112
- let r = (t = Ne.get(e)) != null ? t : 1;
1113
- if (r === 1 ? Ne.delete(e) : Ne.set(e, r - 1), r !== 1) return;
1114
- let n = $t.get(e);
1115
- n && (n["aria-hidden"] === null ? e.removeAttribute("aria-hidden") : e.setAttribute("aria-hidden", n["aria-hidden"]), e.inert = n.inert, $t.delete(e));
1116
- }
1117
- function Kn(e, { allowed: t, disallowed: r } = {}) {
1118
- let n = We(e, "inert-others");
1119
- U(() => {
1120
- var l, i;
1121
- if (!n) return;
1122
- let a = ne();
1123
- for (let o of (l = r == null ? void 0 : r()) != null ? l : []) o && a.add(Xt(o));
1124
- let s = (i = t == null ? void 0 : t()) != null ? i : [];
1125
- for (let o of s) {
1126
- if (!o) continue;
1127
- let u = De(o);
1128
- if (!u) continue;
1129
- let m = o.parentElement;
1130
- for (; m && m !== u.body; ) {
1131
- for (let b of m.children) s.some((g) => b.contains(g)) || a.add(Xt(b));
1132
- m = m.parentElement;
1133
- }
1134
- }
1135
- return a.dispose;
1136
- }, [n, t, r]);
1137
- }
1138
- function qn(e, t, r) {
1139
- let n = ve((l) => {
1140
- let i = l.getBoundingClientRect();
1141
- i.x === 0 && i.y === 0 && i.width === 0 && i.height === 0 && r();
1142
- });
1143
- L(() => {
1144
- if (!e) return;
1145
- let l = t === null ? null : me(t) ? t : t.current;
1146
- if (!l) return;
1147
- let i = ne();
1148
- if (typeof ResizeObserver < "u") {
1149
- let a = new ResizeObserver(() => n.current(l));
1150
- a.observe(l), i.add(() => a.disconnect());
1151
- }
1152
- if (typeof IntersectionObserver < "u") {
1153
- let a = new IntersectionObserver(() => n.current(l));
1154
- a.observe(l), i.add(() => a.disconnect());
1155
- }
1156
- return () => i.dispose();
1157
- }, [t, n, e]);
1158
- }
1159
- let Ze = ["[contentEditable=true]", "[tabindex]", "a[href]", "area[href]", "button:not([disabled])", "iframe", "input:not([disabled])", "select:not([disabled])", "details>summary", "textarea:not([disabled])"].map((e) => `${e}:not([tabindex='-1'])`).join(","), Yn = ["[data-autofocus]"].map((e) => `${e}:not([tabindex='-1'])`).join(",");
1160
- var ee = ((e) => (e[e.First = 1] = "First", e[e.Previous = 2] = "Previous", e[e.Next = 4] = "Next", e[e.Last = 8] = "Last", e[e.WrapAround = 16] = "WrapAround", e[e.NoScroll = 32] = "NoScroll", e[e.AutoFocus = 64] = "AutoFocus", e))(ee || {}), Ot = ((e) => (e[e.Error = 0] = "Error", e[e.Overflow = 1] = "Overflow", e[e.Success = 2] = "Success", e[e.Underflow = 3] = "Underflow", e))(Ot || {}), Zn = ((e) => (e[e.Previous = -1] = "Previous", e[e.Next = 1] = "Next", e))(Zn || {});
1161
- function Jn(e = document.body) {
1162
- return e == null ? [] : Array.from(e.querySelectorAll(Ze)).sort((t, r) => Math.sign((t.tabIndex || Number.MAX_SAFE_INTEGER) - (r.tabIndex || Number.MAX_SAFE_INTEGER)));
1163
- }
1164
- function Qn(e = document.body) {
1165
- return e == null ? [] : Array.from(e.querySelectorAll(Yn)).sort((t, r) => Math.sign((t.tabIndex || Number.MAX_SAFE_INTEGER) - (r.tabIndex || Number.MAX_SAFE_INTEGER)));
1166
- }
1167
- var br = ((e) => (e[e.Strict = 0] = "Strict", e[e.Loose = 1] = "Loose", e))(br || {});
1168
- function el(e, t = 0) {
1169
- var r;
1170
- return e === ((r = De(e)) == null ? void 0 : r.body) ? !1 : re(t, { 0() {
1171
- return e.matches(Ze);
1172
- }, 1() {
1173
- let n = e;
1174
- for (; n !== null; ) {
1175
- if (n.matches(Ze)) return !0;
1176
- n = n.parentElement;
1177
- }
1178
- return !1;
1179
- } });
1180
- }
1181
- var tl = ((e) => (e[e.Keyboard = 0] = "Keyboard", e[e.Mouse = 1] = "Mouse", e))(tl || {});
1182
- typeof window < "u" && typeof document < "u" && (document.addEventListener("keydown", (e) => {
1183
- e.metaKey || e.altKey || e.ctrlKey || (document.documentElement.dataset.headlessuiFocusVisible = "");
1184
- }, !0), document.addEventListener("click", (e) => {
1185
- e.detail === 1 ? delete document.documentElement.dataset.headlessuiFocusVisible : e.detail === 0 && (document.documentElement.dataset.headlessuiFocusVisible = "");
1186
- }, !0));
1187
- function te(e) {
1188
- e == null || e.focus({ preventScroll: !0 });
1189
- }
1190
- let rl = ["textarea", "input"].join(",");
1191
- function nl(e) {
1192
- var t, r;
1193
- return (r = (t = e == null ? void 0 : e.matches) == null ? void 0 : t.call(e, rl)) != null ? r : !1;
1194
- }
1195
- function ll(e, t = (r) => r) {
1196
- return e.slice().sort((r, n) => {
1197
- let l = t(r), i = t(n);
1198
- if (l === null || i === null) return 0;
1199
- let a = l.compareDocumentPosition(i);
1200
- return a & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : a & Node.DOCUMENT_POSITION_PRECEDING ? 1 : 0;
1201
- });
1202
- }
1203
- function Ie(e, t, { sorted: r = !0, relativeTo: n = null, skipElements: l = [] } = {}) {
1204
- let i = Array.isArray(e) ? e.length > 0 ? bt(e[0]) : document : bt(e), a = Array.isArray(e) ? r ? ll(e) : e : t & 64 ? Qn(e) : Jn(e);
1205
- l.length > 0 && a.length > 1 && (a = a.filter((y) => !l.some((f) => f != null && "current" in f ? (f == null ? void 0 : f.current) === y : f === y))), n = n ?? (i == null ? void 0 : i.activeElement);
1206
- let s = (() => {
1207
- if (t & 5) return 1;
1208
- if (t & 10) return -1;
1209
- throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last");
1210
- })(), o = (() => {
1211
- if (t & 1) return 0;
1212
- if (t & 2) return Math.max(0, a.indexOf(n)) - 1;
1213
- if (t & 4) return Math.max(0, a.indexOf(n)) + 1;
1214
- if (t & 8) return a.length - 1;
1215
- throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last");
1216
- })(), u = t & 32 ? { preventScroll: !0 } : {}, m = 0, b = a.length, g;
1217
- do {
1218
- if (m >= b || m + b <= 0) return 0;
1219
- let y = o + m;
1220
- if (t & 16) y = (y + b) % b;
1221
- else {
1222
- if (y < 0) return 3;
1223
- if (y >= b) return 1;
1224
- }
1225
- g = a[y], g == null || g.focus(u), m += s;
1226
- } while (g !== ur(g));
1227
- return t & 6 && nl(g) && g.select(), 2;
1228
- }
1229
- function xr() {
1230
- return /iPhone/gi.test(window.navigator.platform) || /Mac/gi.test(window.navigator.platform) && window.navigator.maxTouchPoints > 0;
1231
- }
1232
- function il() {
1233
- return /Android/gi.test(window.navigator.userAgent);
1234
- }
1235
- function Gt() {
1236
- return xr() || il();
1237
- }
1238
- function ze(e, t, r, n) {
1239
- let l = ve(r);
1240
- L(() => {
1241
- if (!e) return;
1242
- function i(a) {
1243
- l.current(a);
1244
- }
1245
- return document.addEventListener(t, i, n), () => document.removeEventListener(t, i, n);
1246
- }, [e, t, n]);
1247
- }
1248
- function Er(e, t, r, n) {
1249
- let l = ve(r);
1250
- L(() => {
1251
- if (!e) return;
1252
- function i(a) {
1253
- l.current(a);
1254
- }
1255
- return window.addEventListener(t, i, n), () => window.removeEventListener(t, i, n);
1256
- }, [e, t, n]);
1257
- }
1258
- const Kt = 30;
1259
- function ol(e, t, r) {
1260
- let n = ve(r), l = W(function(s, o) {
1261
- if (s.defaultPrevented) return;
1262
- let u = o(s);
1263
- if (u === null || !u.getRootNode().contains(u) || !u.isConnected) return;
1264
- let m = (function b(g) {
1265
- return typeof g == "function" ? b(g()) : Array.isArray(g) || g instanceof Set ? g : [g];
1266
- })(t);
1267
- for (let b of m) if (b !== null && (b.contains(u) || s.composed && s.composedPath().includes(b))) return;
1268
- return !el(u, br.Loose) && u.tabIndex !== -1 && s.preventDefault(), n.current(s, u);
1269
- }, [n, t]), i = S(null);
1270
- ze(e, "pointerdown", (s) => {
1271
- var o, u;
1272
- Gt() || (i.current = ((u = (o = s.composedPath) == null ? void 0 : o.call(s)) == null ? void 0 : u[0]) || s.target);
1273
- }, !0), ze(e, "pointerup", (s) => {
1274
- if (Gt() || !i.current) return;
1275
- let o = i.current;
1276
- return i.current = null, l(s, () => o);
1277
- }, !0);
1278
- let a = S({ x: 0, y: 0 });
1279
- ze(e, "touchstart", (s) => {
1280
- a.current.x = s.touches[0].clientX, a.current.y = s.touches[0].clientY;
1281
- }, !0), ze(e, "touchend", (s) => {
1282
- let o = { x: s.changedTouches[0].clientX, y: s.changedTouches[0].clientY };
1283
- if (!(Math.abs(o.x - a.current.x) >= Kt || Math.abs(o.y - a.current.y) >= Kt)) return l(s, () => ae(s.target) ? s.target : null);
1284
- }, !0), Er(e, "blur", (s) => l(s, () => On(window.document.activeElement) ? window.document.activeElement : null), !0);
1285
- }
1286
- function Ct(...e) {
1287
- return _(() => De(...e), [...e]);
1288
- }
1289
- function $r(e, t, r, n) {
1290
- let l = ve(r);
1291
- L(() => {
1292
- e = e ?? window;
1293
- function i(a) {
1294
- l.current(a);
1295
- }
1296
- return e.addEventListener(t, i, n), () => e.removeEventListener(t, i, n);
1297
- }, [e, t, n]);
1298
- }
1299
- function al(e) {
1300
- return zr(e.subscribe, e.getSnapshot, e.getSnapshot);
1301
- }
1302
- function sl(e, t) {
1303
- let r = e(), n = /* @__PURE__ */ new Set();
1304
- return { getSnapshot() {
1305
- return r;
1306
- }, subscribe(l) {
1307
- return n.add(l), () => n.delete(l);
1308
- }, dispatch(l, ...i) {
1309
- let a = t[l].call(r, ...i);
1310
- a && (r = a, n.forEach((s) => s()));
1311
- } };
1312
- }
1313
- function ul() {
1314
- let e;
1315
- return { before({ doc: t }) {
1316
- var r;
1317
- let n = t.documentElement, l = (r = t.defaultView) != null ? r : window;
1318
- e = Math.max(0, l.innerWidth - n.clientWidth);
1319
- }, after({ doc: t, d: r }) {
1320
- let n = t.documentElement, l = Math.max(0, n.clientWidth - n.offsetWidth), i = Math.max(0, e - l);
1321
- r.style(n, "paddingRight", `${i}px`);
1322
- } };
1323
- }
1324
- function cl() {
1325
- return xr() ? { before({ doc: e, d: t, meta: r }) {
1326
- function n(l) {
1327
- for (let i of r().containers) for (let a of i()) if (a.contains(l)) return !0;
1328
- return !1;
1329
- }
1330
- t.microTask(() => {
1331
- var l;
1332
- if (window.getComputedStyle(e.documentElement).scrollBehavior !== "auto") {
1333
- let s = ne();
1334
- s.style(e.documentElement, "scrollBehavior", "auto"), t.add(() => t.microTask(() => s.dispose()));
532
+ const renderApp = (App, pageProps) => {
533
+ initFromPageProps(pageProps);
534
+ const renderInertiaApp = ({ Component, props, key }) => {
535
+ const renderComponent = () => {
536
+ const child = createElement(Component, { key, ...props });
537
+ if (typeof Component.layout === "function") {
538
+ return Component.layout(child);
1335
539
  }
1336
- let i = (l = window.scrollY) != null ? l : window.pageYOffset, a = null;
1337
- t.addEventListener(e, "click", (s) => {
1338
- if (ae(s.target)) try {
1339
- let o = s.target.closest("a");
1340
- if (!o) return;
1341
- let { hash: u } = new URL(o.href), m = e.querySelector(u);
1342
- ae(m) && !n(m) && (a = m);
1343
- } catch {
1344
- }
1345
- }, !0), t.group((s) => {
1346
- t.addEventListener(e, "touchstart", (o) => {
1347
- if (s.dispose(), ae(o.target) && $n(o.target)) if (n(o.target)) {
1348
- let u = o.target;
1349
- for (; u.parentElement && n(u.parentElement); ) u = u.parentElement;
1350
- s.style(u, "overscrollBehavior", "contain");
1351
- } else s.style(o.target, "touchAction", "none");
1352
- });
1353
- }), t.addEventListener(e, "touchmove", (s) => {
1354
- if (ae(s.target)) {
1355
- if (Sn(s.target)) return;
1356
- if (n(s.target)) {
1357
- let o = s.target;
1358
- for (; o.parentElement && o.dataset.headlessuiPortal !== "" && !(o.scrollHeight > o.clientHeight || o.scrollWidth > o.clientWidth); ) o = o.parentElement;
1359
- o.dataset.headlessuiPortal === "" && s.preventDefault();
1360
- } else s.preventDefault();
1361
- }
1362
- }, { passive: !1 }), t.add(() => {
1363
- var s;
1364
- let o = (s = window.scrollY) != null ? s : window.pageYOffset;
1365
- i !== o && window.scrollTo(0, i), a && a.isConnected && (a.scrollIntoView({ block: "nearest" }), a = null);
1366
- });
1367
- });
1368
- } } : {};
1369
- }
1370
- function dl() {
1371
- return { before({ doc: e, d: t }) {
1372
- t.style(e.documentElement, "overflow", "hidden");
1373
- } };
1374
- }
1375
- function qt(e) {
1376
- let t = {};
1377
- for (let r of e) Object.assign(t, r(t));
1378
- return t;
1379
- }
1380
- let pe = sl(() => /* @__PURE__ */ new Map(), { PUSH(e, t) {
1381
- var r;
1382
- let n = (r = this.get(e)) != null ? r : { doc: e, count: 0, d: ne(), meta: /* @__PURE__ */ new Set(), computedMeta: {} };
1383
- return n.count++, n.meta.add(t), n.computedMeta = qt(n.meta), this.set(e, n), this;
1384
- }, POP(e, t) {
1385
- let r = this.get(e);
1386
- return r && (r.count--, r.meta.delete(t), r.computedMeta = qt(r.meta)), this;
1387
- }, SCROLL_PREVENT(e) {
1388
- let t = { doc: e.doc, d: e.d, meta() {
1389
- return e.computedMeta;
1390
- } }, r = [cl(), ul(), dl()];
1391
- r.forEach(({ before: n }) => n == null ? void 0 : n(t)), r.forEach(({ after: n }) => n == null ? void 0 : n(t));
1392
- }, SCROLL_ALLOW({ d: e }) {
1393
- e.dispose();
1394
- }, TEARDOWN({ doc: e }) {
1395
- this.delete(e);
1396
- } });
1397
- pe.subscribe(() => {
1398
- let e = pe.getSnapshot(), t = /* @__PURE__ */ new Map();
1399
- for (let [r] of e) t.set(r, r.documentElement.style.overflow);
1400
- for (let r of e.values()) {
1401
- let n = t.get(r.doc) === "hidden", l = r.count !== 0;
1402
- (l && !n || !l && n) && pe.dispatch(r.count > 0 ? "SCROLL_PREVENT" : "SCROLL_ALLOW", r), r.count === 0 && pe.dispatch("TEARDOWN", r);
1403
- }
1404
- });
1405
- function fl(e, t, r = () => ({ containers: [] })) {
1406
- let n = al(pe), l = t ? n.get(t) : void 0, i = l ? l.count > 0 : !1;
1407
- return U(() => {
1408
- if (!(!t || !e)) return pe.dispatch("PUSH", t, r), () => pe.dispatch("POP", t, r);
1409
- }, [e, t]), i;
1410
- }
1411
- function pl(e, t, r = () => [document.body]) {
1412
- let n = We(e, "scroll-lock");
1413
- fl(n, t, (l) => {
1414
- var i;
1415
- return { containers: [...(i = l.containers) != null ? i : [], r] };
1416
- });
1417
- }
1418
- function ml(e = 0) {
1419
- let [t, r] = F(e), n = W((o) => r(o), []), l = W((o) => r((u) => u | o), []), i = W((o) => (t & o) === o, [t]), a = W((o) => r((u) => u & ~o), []), s = W((o) => r((u) => u ^ o), []);
1420
- return { flags: t, setFlag: n, addFlag: l, hasFlag: i, removeFlag: a, toggleFlag: s };
1421
- }
1422
- var Yt, Zt;
1423
- typeof process < "u" && typeof globalThis < "u" && typeof Element < "u" && ((Yt = process == null ? void 0 : process.env) == null ? void 0 : Yt.NODE_ENV) === "test" && typeof ((Zt = Element == null ? void 0 : Element.prototype) == null ? void 0 : Zt.getAnimations) > "u" && (Element.prototype.getAnimations = function() {
1424
- return console.warn(["Headless UI has polyfilled `Element.prototype.getAnimations` for your tests.", "Please install a proper polyfill e.g. `jsdom-testing-mocks`, to silence these warnings.", "", "Example usage:", "```js", "import { mockAnimationsApi } from 'jsdom-testing-mocks'", "mockAnimationsApi()", "```"].join(`
1425
- `)), [];
1426
- });
1427
- var hl = ((e) => (e[e.None = 0] = "None", e[e.Closed = 1] = "Closed", e[e.Enter = 2] = "Enter", e[e.Leave = 4] = "Leave", e))(hl || {});
1428
- function vl(e) {
1429
- let t = {};
1430
- for (let r in e) e[r] === !0 && (t[`data-${r}`] = "");
1431
- return t;
1432
- }
1433
- function gl(e, t, r, n) {
1434
- let [l, i] = F(r), { hasFlag: a, addFlag: s, removeFlag: o } = ml(e && l ? 3 : 0), u = S(!1), m = S(!1), b = rt();
1435
- return U(() => {
1436
- var g;
1437
- if (e) {
1438
- if (r && i(!0), !t) {
1439
- r && s(3);
1440
- return;
1441
- }
1442
- return (g = n == null ? void 0 : n.start) == null || g.call(n, r), wl(t, { inFlight: u, prepare() {
1443
- m.current ? m.current = !1 : m.current = u.current, u.current = !0, !m.current && (r ? (s(3), o(4)) : (s(4), o(2)));
1444
- }, run() {
1445
- m.current ? r ? (o(3), s(4)) : (o(4), s(3)) : r ? o(1) : s(1);
1446
- }, done() {
1447
- var y;
1448
- m.current && xl(t) || (u.current = !1, o(7), r || i(!1), (y = n == null ? void 0 : n.end) == null || y.call(n, r));
1449
- } });
1450
- }
1451
- }, [e, r, t, b]), e ? [l, { closed: a(1), enter: a(2), leave: a(4), transition: a(2) || a(4) }] : [r, { closed: void 0, enter: void 0, leave: void 0, transition: void 0 }];
1452
- }
1453
- function wl(e, { prepare: t, run: r, done: n, inFlight: l }) {
1454
- let i = ne();
1455
- return bl(e, { prepare: t, inFlight: l }), i.nextFrame(() => {
1456
- r(), i.requestAnimationFrame(() => {
1457
- i.add(yl(e, n));
1458
- });
1459
- }), i.dispose;
1460
- }
1461
- function yl(e, t) {
1462
- var r, n;
1463
- let l = ne();
1464
- if (!e) return l.dispose;
1465
- let i = !1;
1466
- l.add(() => {
1467
- i = !0;
1468
- });
1469
- let a = (n = (r = e.getAnimations) == null ? void 0 : r.call(e).filter((s) => s instanceof CSSTransition)) != null ? n : [];
1470
- return a.length === 0 ? (t(), l.dispose) : (Promise.allSettled(a.map((s) => s.finished)).then(() => {
1471
- i || t();
1472
- }), l.dispose);
1473
- }
1474
- function bl(e, { inFlight: t, prepare: r }) {
1475
- if (t != null && t.current) {
1476
- r();
1477
- return;
1478
- }
1479
- let n = e.style.transition;
1480
- e.style.transition = "none", r(), e.offsetHeight, e.style.transition = n;
1481
- }
1482
- function xl(e) {
1483
- var t, r;
1484
- return ((r = (t = e.getAnimations) == null ? void 0 : t.call(e)) != null ? r : []).some((n) => n instanceof CSSTransition && n.playState !== "finished");
1485
- }
1486
- function Ft(e, t) {
1487
- let r = S([]), n = M(e);
1488
- L(() => {
1489
- let l = [...r.current];
1490
- for (let [i, a] of t.entries()) if (r.current[i] !== a) {
1491
- let s = n(t, l);
1492
- return r.current = t, s;
1493
- }
1494
- }, [n, ...t]);
1495
- }
1496
- let nt = z(null);
1497
- nt.displayName = "OpenClosedContext";
1498
- var q = ((e) => (e[e.Open = 1] = "Open", e[e.Closed = 2] = "Closed", e[e.Closing = 4] = "Closing", e[e.Opening = 8] = "Opening", e))(q || {});
1499
- function lt() {
1500
- return H(nt);
1501
- }
1502
- function El({ value: e, children: t }) {
1503
- return $.createElement(nt.Provider, { value: e }, t);
1504
- }
1505
- function $l({ children: e }) {
1506
- return $.createElement(nt.Provider, { value: null }, e);
1507
- }
1508
- function Ol(e) {
1509
- function t() {
1510
- document.readyState !== "loading" && (e(), document.removeEventListener("DOMContentLoaded", t));
1511
- }
1512
- typeof window < "u" && typeof document < "u" && (document.addEventListener("DOMContentLoaded", t), t());
1513
- }
1514
- let ie = [];
1515
- Ol(() => {
1516
- function e(t) {
1517
- if (!ae(t.target) || t.target === document.body || ie[0] === t.target) return;
1518
- let r = t.target;
1519
- r = r.closest(Ze), ie.unshift(r ?? t.target), ie = ie.filter((n) => n != null && n.isConnected), ie.splice(10);
1520
- }
1521
- window.addEventListener("click", e, { capture: !0 }), window.addEventListener("mousedown", e, { capture: !0 }), window.addEventListener("focus", e, { capture: !0 }), document.body.addEventListener("click", e, { capture: !0 }), document.body.addEventListener("mousedown", e, { capture: !0 }), document.body.addEventListener("focus", e, { capture: !0 });
1522
- });
1523
- function Or(e) {
1524
- let t = M(e), r = S(!1);
1525
- L(() => (r.current = !1, () => {
1526
- r.current = !0, tt(() => {
1527
- r.current && t();
1528
- });
1529
- }), [t]);
1530
- }
1531
- let Sr = z(!1);
1532
- function Sl() {
1533
- return H(Sr);
1534
- }
1535
- function Jt(e) {
1536
- return $.createElement(Sr.Provider, { value: e.force }, e.children);
1537
- }
1538
- function Tl(e) {
1539
- let t = Sl(), r = H(Pr), [n, l] = F(() => {
1540
- var i;
1541
- if (!t && r !== null) return (i = r.current) != null ? i : null;
1542
- if (Z.isServer) return null;
1543
- let a = e == null ? void 0 : e.getElementById("headlessui-portal-root");
1544
- if (a) return a;
1545
- if (e === null) return null;
1546
- let s = e.createElement("div");
1547
- return s.setAttribute("id", "headlessui-portal-root"), e.body.appendChild(s);
1548
- });
1549
- return L(() => {
1550
- n !== null && (e != null && e.body.contains(n) || e == null || e.body.appendChild(n));
1551
- }, [n, e]), L(() => {
1552
- t || r !== null && l(r.current);
1553
- }, [r, l, t]), n;
1554
- }
1555
- let Tr = ue, Pl = V(function(e, t) {
1556
- let { ownerDocument: r = null, ...n } = e, l = S(null), i = J(Tn((g) => {
1557
- l.current = g;
1558
- }), t), a = Ct(l.current), s = r ?? a, o = Tl(s), u = H(St), m = rt(), b = G();
1559
- return Or(() => {
1560
- var g;
1561
- o && o.childNodes.length <= 0 && ((g = o.parentElement) == null || g.removeChild(o));
1562
- }), o ? Zr($.createElement("div", { "data-headlessui-portal": "", ref: (g) => {
1563
- m.dispose(), u && g && m.add(u.register(g));
1564
- } }, b({ ourProps: { ref: i }, theirProps: n, slot: {}, defaultTag: Tr, name: "Portal" })), o) : null;
1565
- });
1566
- function Ml(e, t) {
1567
- let r = J(t), { enabled: n = !0, ownerDocument: l, ...i } = e, a = G();
1568
- return n ? $.createElement(Pl, { ...i, ownerDocument: l, ref: r }) : a({ ourProps: { ref: r }, theirProps: i, slot: {}, defaultTag: Tr, name: "Portal" });
1569
- }
1570
- let Ll = ue, Pr = z(null);
1571
- function kl(e, t) {
1572
- let { target: r, ...n } = e, l = { ref: J(t) }, i = G();
1573
- return $.createElement(Pr.Provider, { value: r }, i({ ourProps: l, theirProps: n, defaultTag: Ll, name: "Popover.Group" }));
1574
- }
1575
- let St = z(null);
1576
- function Al() {
1577
- let e = H(St), t = S([]), r = M((i) => (t.current.push(i), e && e.register(i), () => n(i))), n = M((i) => {
1578
- let a = t.current.indexOf(i);
1579
- a !== -1 && t.current.splice(a, 1), e && e.unregister(i);
1580
- }), l = _(() => ({ register: r, unregister: n, portals: t }), [r, n, t]);
1581
- return [t, _(() => function({ children: i }) {
1582
- return $.createElement(St.Provider, { value: l }, i);
1583
- }, [l])];
1584
- }
1585
- let Cl = V(Ml), Mr = V(kl), Fl = Object.assign(Cl, { Group: Mr });
1586
- function Nl(e, t = typeof document < "u" ? document.defaultView : null, r) {
1587
- let n = We(e, "escape");
1588
- $r(t, "keydown", (l) => {
1589
- n && (l.defaultPrevented || l.key === pr.Escape && r(l));
1590
- });
1591
- }
1592
- function Il() {
1593
- var e;
1594
- let [t] = F(() => typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(pointer: coarse)") : null), [r, n] = F((e = t == null ? void 0 : t.matches) != null ? e : !1);
1595
- return U(() => {
1596
- if (!t) return;
1597
- function l(i) {
1598
- n(i.matches);
1599
- }
1600
- return t.addEventListener("change", l), () => t.removeEventListener("change", l);
1601
- }, [t]), r;
1602
- }
1603
- function Rl({ defaultContainers: e = [], portals: t, mainTreeNode: r } = {}) {
1604
- let n = M(() => {
1605
- var l, i;
1606
- let a = De(r), s = [];
1607
- for (let o of e) o !== null && (se(o) ? s.push(o) : "current" in o && se(o.current) && s.push(o.current));
1608
- if (t != null && t.current) for (let o of t.current) s.push(o);
1609
- for (let o of (l = a == null ? void 0 : a.querySelectorAll("html > *, body > *")) != null ? l : []) o !== document.body && o !== document.head && se(o) && o.id !== "headlessui-portal-root" && (r && (o.contains(r) || o.contains((i = r == null ? void 0 : r.getRootNode()) == null ? void 0 : i.host)) || s.some((u) => o.contains(u)) || s.push(o));
1610
- return s;
1611
- });
1612
- return { resolveContainers: n, contains: M((l) => n().some((i) => i.contains(l))) };
1613
- }
1614
- let Lr = z(null);
1615
- function Qt({ children: e, node: t }) {
1616
- let [r, n] = F(null), l = kr(t ?? r);
1617
- return $.createElement(Lr.Provider, { value: l }, e, l === null && $.createElement(Et, { features: Ye.Hidden, ref: (i) => {
1618
- var a, s;
1619
- if (i) {
1620
- for (let o of (s = (a = De(i)) == null ? void 0 : a.querySelectorAll("html > *, body > *")) != null ? s : []) if (o !== document.body && o !== document.head && se(o) && o != null && o.contains(i)) {
1621
- n(o);
1622
- break;
540
+ if (Array.isArray(Component.layout)) {
541
+ return Component.layout.slice().reverse().reduce(
542
+ (acc, Layout) => createElement(Layout, props, acc),
543
+ child
544
+ );
1623
545
  }
1624
- }
1625
- } }));
1626
- }
1627
- function kr(e = null) {
1628
- var t;
1629
- return (t = H(Lr)) != null ? t : e;
1630
- }
1631
- function _l() {
1632
- let e = typeof document > "u";
1633
- return "useSyncExternalStore" in Ce ? ((t) => t.useSyncExternalStore)(Ce)(() => () => {
1634
- }, () => !1, () => !e) : !1;
1635
- }
1636
- function it() {
1637
- let e = _l(), [t, r] = Ce.useState(Z.isHandoffComplete);
1638
- return t && Z.isHandoffComplete === !1 && r(!1), Ce.useEffect(() => {
1639
- t !== !0 && r(!0);
1640
- }, [t]), Ce.useEffect(() => Z.handoff(), []), e ? !1 : t;
1641
- }
1642
- function Nt() {
1643
- let e = S(!1);
1644
- return U(() => (e.current = !0, () => {
1645
- e.current = !1;
1646
- }), []), e;
1647
- }
1648
- var Ae = ((e) => (e[e.Forwards = 0] = "Forwards", e[e.Backwards = 1] = "Backwards", e))(Ae || {});
1649
- function Dl() {
1650
- let e = S(0);
1651
- return Er(!0, "keydown", (t) => {
1652
- t.key === "Tab" && (e.current = t.shiftKey ? 1 : 0);
1653
- }, !0), e;
1654
- }
1655
- function Ar(e) {
1656
- if (!e) return /* @__PURE__ */ new Set();
1657
- if (typeof e == "function") return new Set(e());
1658
- let t = /* @__PURE__ */ new Set();
1659
- for (let r of e.current) se(r.current) && t.add(r.current);
1660
- return t;
1661
- }
1662
- let jl = "div";
1663
- var fe = ((e) => (e[e.None = 0] = "None", e[e.InitialFocus = 1] = "InitialFocus", e[e.TabLock = 2] = "TabLock", e[e.FocusLock = 4] = "FocusLock", e[e.RestoreFocus = 8] = "RestoreFocus", e[e.AutoFocus = 16] = "AutoFocus", e))(fe || {});
1664
- function Wl(e, t) {
1665
- let r = S(null), n = J(r, t), { initialFocus: l, initialFocusFallback: i, containers: a, features: s = 15, ...o } = e;
1666
- it() || (s = 0);
1667
- let u = Ct(r.current);
1668
- Bl(s, { ownerDocument: u });
1669
- let m = Xl(s, { ownerDocument: u, container: r, initialFocus: l, initialFocusFallback: i });
1670
- zl(s, { ownerDocument: u, container: r, containers: a, previousActiveElement: m });
1671
- let b = Dl(), g = M((d) => {
1672
- if (!me(r.current)) return;
1673
- let v = r.current;
1674
- ((w) => w())(() => {
1675
- re(b.current, { [Ae.Forwards]: () => {
1676
- Ie(v, ee.First, { skipElements: [d.relatedTarget, i] });
1677
- }, [Ae.Backwards]: () => {
1678
- Ie(v, ee.Last, { skipElements: [d.relatedTarget, i] });
1679
- } });
1680
- });
1681
- }), y = We(!!(s & 2), "focus-trap#tab-lock"), f = rt(), E = S(!1), h = { ref: n, onKeyDown(d) {
1682
- d.key == "Tab" && (E.current = !0, f.requestAnimationFrame(() => {
1683
- E.current = !1;
1684
- }));
1685
- }, onBlur(d) {
1686
- if (!(s & 4)) return;
1687
- let v = Ar(a);
1688
- me(r.current) && v.add(r.current);
1689
- let w = d.relatedTarget;
1690
- ae(w) && w.dataset.headlessuiFocusGuard !== "true" && (Cr(v, w) || (E.current ? Ie(r.current, re(b.current, { [Ae.Forwards]: () => ee.Next, [Ae.Backwards]: () => ee.Previous }) | ee.WrapAround, { relativeTo: d.target }) : ae(d.target) && te(d.target)));
1691
- } }, c = G();
1692
- return $.createElement($.Fragment, null, y && $.createElement(Et, { as: "button", type: "button", "data-headlessui-focus-guard": !0, onFocus: g, features: Ye.Focusable }), c({ ourProps: h, theirProps: o, defaultTag: jl, name: "FocusTrap" }), y && $.createElement(Et, { as: "button", type: "button", "data-headlessui-focus-guard": !0, onFocus: g, features: Ye.Focusable }));
1693
- }
1694
- let Ul = V(Wl), Hl = Object.assign(Ul, { features: fe });
1695
- function Vl(e = !0) {
1696
- let t = S(ie.slice());
1697
- return Ft(([r], [n]) => {
1698
- n === !0 && r === !1 && tt(() => {
1699
- t.current.splice(0);
1700
- }), n === !1 && r === !0 && (t.current = ie.slice());
1701
- }, [e, ie, t]), M(() => {
1702
- var r;
1703
- return (r = t.current.find((n) => n != null && n.isConnected)) != null ? r : null;
1704
- });
1705
- }
1706
- function Bl(e, { ownerDocument: t }) {
1707
- let r = !!(e & 8), n = Vl(r);
1708
- Ft(() => {
1709
- r || fn(t == null ? void 0 : t.body) && te(n());
1710
- }, [r]), Or(() => {
1711
- r && te(n());
1712
- });
1713
- }
1714
- function Xl(e, { ownerDocument: t, container: r, initialFocus: n, initialFocusFallback: l }) {
1715
- let i = S(null), a = We(!!(e & 1), "focus-trap#initial-focus"), s = Nt();
1716
- return Ft(() => {
1717
- if (e === 0) return;
1718
- if (!a) {
1719
- l != null && l.current && te(l.current);
1720
- return;
1721
- }
1722
- let o = r.current;
1723
- o && tt(() => {
1724
- if (!s.current) return;
1725
- let u = t == null ? void 0 : t.activeElement;
1726
- if (n != null && n.current) {
1727
- if ((n == null ? void 0 : n.current) === u) {
1728
- i.current = u;
546
+ return child;
547
+ };
548
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
549
+ renderComponent(),
550
+ /* @__PURE__ */ jsx(ModalRoot, {})
551
+ ] });
552
+ };
553
+ return /* @__PURE__ */ jsx(ModalStackProvider, { children: /* @__PURE__ */ jsx(App, { ...pageProps, children: renderInertiaApp }) });
554
+ };
555
+ const ModalRoot = ({ children }) => {
556
+ const context = useContext(ModalStackContext);
557
+ const $page = usePage();
558
+ const pendingModalKeysRef = useRef(/* @__PURE__ */ new Set());
559
+ const getModalKey = (modalData) => modalData.id || `${modalData.component}:${modalData.url}`;
560
+ const isNavigatingRef = useRef(false);
561
+ const initialModalStillOpenedRef = useRef(!!$page.props?._inertiaui_modal);
562
+ useEffect(() => router.on("start", () => isNavigatingRef.current = true), []);
563
+ useEffect(() => router.on("finish", () => isNavigatingRef.current = false), []);
564
+ useEffect(
565
+ () => router.on("navigate", function($event) {
566
+ const modalOnBase = $event.detail.page.props._inertiaui_modal;
567
+ const pageUrl = $event.detail.page.url;
568
+ if (closingToBaseUrlTarget) {
569
+ const targetPath = new URL(closingToBaseUrlTarget, "http://x").pathname;
570
+ const pagePath = new URL(pageUrl, "http://x").pathname;
571
+ if (targetPath === pagePath) {
572
+ closingToBaseUrlTarget = null;
573
+ context?.closeAll(true);
574
+ baseUrl = null;
575
+ initialModalStillOpenedRef.current = false;
1729
576
  return;
1730
577
  }
1731
- } else if (o.contains(u)) {
1732
- i.current = u;
578
+ closingToBaseUrlTarget = null;
579
+ }
580
+ if (!modalOnBase) {
581
+ context?.closeAll(true);
582
+ baseUrl = null;
583
+ initialModalStillOpenedRef.current = false;
1733
584
  return;
1734
585
  }
1735
- if (n != null && n.current) te(n.current);
1736
- else {
1737
- if (e & 16) {
1738
- if (Ie(o, ee.First | ee.AutoFocus) !== Ot.Error) return;
1739
- } else if (Ie(o, ee.First) !== Ot.Error) return;
1740
- if (l != null && l.current && (te(l.current), (t == null ? void 0 : t.activeElement) === l.current)) return;
1741
- console.warn("There are no focusable elements inside the <FocusTrap />");
586
+ if (!sameUrlPath(pageUrl, modalOnBase.url)) {
587
+ context?.closeAll(true);
588
+ baseUrl = null;
589
+ initialModalStillOpenedRef.current = false;
590
+ return;
1742
591
  }
1743
- i.current = t == null ? void 0 : t.activeElement;
1744
- });
1745
- }, [l, a, e]), i;
1746
- }
1747
- function zl(e, { ownerDocument: t, container: r, containers: n, previousActiveElement: l }) {
1748
- let i = Nt(), a = !!(e & 4);
1749
- $r(t == null ? void 0 : t.defaultView, "focus", (s) => {
1750
- if (!a || !i.current) return;
1751
- let o = Ar(n);
1752
- me(r.current) && o.add(r.current);
1753
- let u = l.current;
1754
- if (!u) return;
1755
- let m = s.target;
1756
- me(m) ? Cr(o, m) ? (l.current = m, te(m)) : (s.preventDefault(), s.stopPropagation(), te(u)) : te(l.current);
1757
- }, !0);
1758
- }
1759
- function Cr(e, t) {
1760
- for (let r of e) if (r.contains(t)) return !0;
1761
- return !1;
1762
- }
1763
- function Fr(e) {
1764
- var t;
1765
- return !!(e.enter || e.enterFrom || e.enterTo || e.leave || e.leaveFrom || e.leaveTo) || !Fe((t = e.as) != null ? t : Ir) || $.Children.count(e.children) === 1;
1766
- }
1767
- let ot = z(null);
1768
- ot.displayName = "TransitionContext";
1769
- var Gl = ((e) => (e.Visible = "visible", e.Hidden = "hidden", e))(Gl || {});
1770
- function Kl() {
1771
- let e = H(ot);
1772
- if (e === null) throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");
1773
- return e;
1774
- }
1775
- function ql() {
1776
- let e = H(at);
1777
- if (e === null) throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");
1778
- return e;
1779
- }
1780
- let at = z(null);
1781
- at.displayName = "NestingContext";
1782
- function st(e) {
1783
- return "children" in e ? st(e.children) : e.current.filter(({ el: t }) => t.current !== null).filter(({ state: t }) => t === "visible").length > 0;
1784
- }
1785
- function Nr(e, t) {
1786
- let r = ve(e), n = S([]), l = Nt(), i = rt(), a = M((y, f = oe.Hidden) => {
1787
- let E = n.current.findIndex(({ el: h }) => h === y);
1788
- E !== -1 && (re(f, { [oe.Unmount]() {
1789
- n.current.splice(E, 1);
1790
- }, [oe.Hidden]() {
1791
- n.current[E].state = "hidden";
1792
- } }), i.microTask(() => {
1793
- var h;
1794
- !st(n) && l.current && ((h = r.current) == null || h.call(r));
1795
- }));
1796
- }), s = M((y) => {
1797
- let f = n.current.find(({ el: E }) => E === y);
1798
- return f ? f.state !== "visible" && (f.state = "visible") : n.current.push({ el: y, state: "visible" }), () => a(y, oe.Unmount);
1799
- }), o = S([]), u = S(Promise.resolve()), m = S({ enter: [], leave: [] }), b = M((y, f, E) => {
1800
- o.current.splice(0), t && (t.chains.current[f] = t.chains.current[f].filter(([h]) => h !== y)), t == null || t.chains.current[f].push([y, new Promise((h) => {
1801
- o.current.push(h);
1802
- })]), t == null || t.chains.current[f].push([y, new Promise((h) => {
1803
- Promise.all(m.current[f].map(([c, d]) => d)).then(() => h());
1804
- })]), f === "enter" ? u.current = u.current.then(() => t == null ? void 0 : t.wait.current).then(() => E(f)) : E(f);
1805
- }), g = M((y, f, E) => {
1806
- Promise.all(m.current[f].splice(0).map(([h, c]) => c)).then(() => {
1807
- var h;
1808
- (h = o.current.shift()) == null || h();
1809
- }).then(() => E(f));
1810
- });
1811
- return _(() => ({ children: n, register: s, unregister: a, onStart: b, onStop: g, wait: u, chains: m }), [s, a, n, b, g, m, u]);
1812
- }
1813
- let Ir = ue, Rr = qe.RenderStrategy;
1814
- function Yl(e, t) {
1815
- var r, n;
1816
- let { transition: l = !0, beforeEnter: i, afterEnter: a, beforeLeave: s, afterLeave: o, enter: u, enterFrom: m, enterTo: b, entered: g, leave: y, leaveFrom: f, leaveTo: E, ...h } = e, [c, d] = F(null), v = S(null), w = Fr(e), p = J(...w ? [v, t, d] : t === null ? [] : [t]), x = (r = h.unmount) == null || r ? oe.Unmount : oe.Hidden, { show: O, appear: N, initial: D } = Kl(), [C, I] = F(O ? "visible" : "hidden"), B = ql(), { register: R, unregister: k } = B;
1817
- U(() => R(v), [R, v]), U(() => {
1818
- if (x === oe.Hidden && v.current) {
1819
- if (O && C !== "visible") {
1820
- I("visible");
592
+ const modalKey = getModalKey(modalOnBase);
593
+ if (pendingModalKeysRef.current.has(modalKey)) {
594
+ return;
595
+ }
596
+ if (modalOnBase.id && context?.stack.some((m) => m.id === modalOnBase.id)) {
1821
597
  return;
1822
598
  }
1823
- return re(C, { hidden: () => k(v), visible: () => R(v) });
599
+ if (context?.stack.some((m) => m.response?.component === modalOnBase.component && sameUrlPath(m.response?.url, modalOnBase.url))) {
600
+ return;
601
+ }
602
+ baseUrl = modalOnBase.baseUrl;
603
+ pendingModalKeysRef.current.add(modalKey);
604
+ context?.pushFromResponseData(modalOnBase, {}, () => {
605
+ if (!modalOnBase.baseUrl) {
606
+ console.error("No base url in modal response data so cannot navigate back");
607
+ return;
608
+ }
609
+ if (!isNavigatingRef.current && typeof window !== "undefined" && window.location.href !== modalOnBase.baseUrl) {
610
+ router.visit(modalOnBase.baseUrl, {
611
+ preserveScroll: true,
612
+ preserveState: true
613
+ });
614
+ }
615
+ }).finally(() => {
616
+ pendingModalKeysRef.current.delete(modalKey);
617
+ });
618
+ }),
619
+ []
620
+ );
621
+ const axiosRequestInterceptor = (config) => {
622
+ const baseUrlValue = baseUrl ?? (initialModalStillOpenedRef.current ? $page.props._inertiaui_modal?.baseUrl : null);
623
+ if (baseUrlValue) {
624
+ config.headers["X-InertiaUI-Modal-Base-Url"] = baseUrlValue;
1824
625
  }
1825
- }, [C, v, R, k, O, x]);
1826
- let j = it();
1827
- U(() => {
1828
- if (w && j && C === "visible" && v.current === null) throw new Error("Did you forget to passthrough the `ref` to the actual DOM node?");
1829
- }, [v, C, j, w]);
1830
- let ge = D && !N, ce = N && O && D, Q = S(!1), A = Nr(() => {
1831
- Q.current || (I("hidden"), k(v));
1832
- }, B), $e = M((dt) => {
1833
- Q.current = !0;
1834
- let He = dt ? "enter" : "leave";
1835
- A.onStart(v, He, (Se) => {
1836
- Se === "enter" ? i == null || i() : Se === "leave" && (s == null || s());
1837
- });
1838
- }), le = M((dt) => {
1839
- let He = dt ? "enter" : "leave";
1840
- Q.current = !1, A.onStop(v, He, (Se) => {
1841
- Se === "enter" ? a == null || a() : Se === "leave" && (o == null || o());
1842
- }), He === "leave" && !st(A) && (I("hidden"), k(v));
1843
- });
1844
- L(() => {
1845
- w && l || ($e(O), le(O));
1846
- }, [O, w, l]);
1847
- let ct = !(!l || !w || !j || ge), [, T] = gl(ct, c, O, { start: $e, end: le }), Ue = de({ ref: p, className: ((n = xt(h.className, ce && u, ce && m, T.enter && u, T.enter && T.closed && m, T.enter && !T.closed && b, T.leave && y, T.leave && !T.closed && f, T.leave && T.closed && E, !T.transition && O && g)) == null ? void 0 : n.trim()) || void 0, ...vl(T) }), Oe = 0;
1848
- C === "visible" && (Oe |= q.Open), C === "hidden" && (Oe |= q.Closed), O && C === "hidden" && (Oe |= q.Opening), !O && C === "visible" && (Oe |= q.Closing);
1849
- let Wr = G();
1850
- return $.createElement(at.Provider, { value: A }, $.createElement(El, { value: Oe }, Wr({ ourProps: Ue, theirProps: h, defaultTag: Ir, features: Rr, visible: C === "visible", name: "Transition.Child" })));
1851
- }
1852
- function Zl(e, t) {
1853
- let { show: r, appear: n = !1, unmount: l = !0, ...i } = e, a = S(null), s = Fr(e), o = J(...s ? [a, t] : t === null ? [] : [t]);
1854
- it();
1855
- let u = lt();
1856
- if (r === void 0 && u !== null && (r = (u & q.Open) === q.Open), r === void 0) throw new Error("A <Transition /> is used but it is missing a `show={true | false}` prop.");
1857
- let [m, b] = F(r ? "visible" : "hidden"), g = Nr(() => {
1858
- r || b("hidden");
1859
- }), [y, f] = F(!0), E = S([r]);
1860
- U(() => {
1861
- y !== !1 && E.current[E.current.length - 1] !== r && (E.current.push(r), f(!1));
1862
- }, [E, r]);
1863
- let h = _(() => ({ show: r, appear: n, initial: y }), [r, n, y]);
1864
- U(() => {
1865
- r ? b("visible") : !st(g) && a.current !== null && b("hidden");
1866
- }, [r, g]);
1867
- let c = { unmount: l }, d = M(() => {
1868
- var p;
1869
- y && f(!1), (p = e.beforeEnter) == null || p.call(e);
1870
- }), v = M(() => {
1871
- var p;
1872
- y && f(!1), (p = e.beforeLeave) == null || p.call(e);
1873
- }), w = G();
1874
- return $.createElement(at.Provider, { value: g }, $.createElement(ot.Provider, { value: h }, w({ ourProps: { ...c, as: ue, children: $.createElement(_r, { ref: o, ...c, ...i, beforeEnter: d, beforeLeave: v }) }, theirProps: {}, defaultTag: ue, features: Rr, visible: m === "visible", name: "Transition" })));
1875
- }
1876
- function Jl(e, t) {
1877
- let r = H(ot) !== null, n = lt() !== null;
1878
- return $.createElement($.Fragment, null, !r && n ? $.createElement(Tt, { ref: t, ...e }) : $.createElement(_r, { ref: t, ...e }));
1879
- }
1880
- let Tt = V(Zl), _r = V(Yl), Ee = V(Jl), Dr = Object.assign(Tt, { Child: Ee, Root: Tt });
1881
- var Ql = ((e) => (e[e.Open = 0] = "Open", e[e.Closed = 1] = "Closed", e))(Ql || {}), ei = ((e) => (e[e.SetTitleId = 0] = "SetTitleId", e))(ei || {});
1882
- let ti = { 0(e, t) {
1883
- return e.titleId === t.id ? e : { ...e, titleId: t.id };
1884
- } }, It = z(null);
1885
- It.displayName = "DialogContext";
1886
- function ut(e) {
1887
- let t = H(It);
1888
- if (t === null) {
1889
- let r = new Error(`<${e} /> is missing a parent <Dialog /> component.`);
1890
- throw Error.captureStackTrace && Error.captureStackTrace(r, ut), r;
626
+ return config;
627
+ };
628
+ useEffect(() => {
629
+ const interceptorId = Axios.interceptors.request.use(axiosRequestInterceptor);
630
+ return () => Axios.interceptors.request.eject(interceptorId);
631
+ }, []);
632
+ const previousModalRef = useRef(void 0);
633
+ useEffect(() => {
634
+ const newModal = $page.props?._inertiaui_modal;
635
+ const previousModal = previousModalRef.current;
636
+ previousModalRef.current = newModal;
637
+ if (!newModal) {
638
+ return;
639
+ }
640
+ if (previousModal && newModal.component === previousModal.component && sameUrlPath(newModal.url, previousModal.url)) {
641
+ context?.stack[0]?.updateProps(newModal.props ?? {});
642
+ return;
643
+ }
644
+ if (!previousModal && context && context.stack.length > 0) {
645
+ const existingModal = context.stack.find(
646
+ (m) => m.response?.component === newModal.component && sameUrlPath(m.response?.url, newModal.url)
647
+ );
648
+ if (existingModal) {
649
+ existingModal.updateProps(newModal.props ?? {});
650
+ }
651
+ }
652
+ }, [$page.props?._inertiaui_modal]);
653
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
654
+ children,
655
+ context && context.stack.length > 0 && /* @__PURE__ */ jsx(ModalRenderer, { index: 0 })
656
+ ] });
657
+ };
658
+ const ModalIndexContext = React.createContext(null);
659
+ ModalIndexContext.displayName = "ModalIndexContext";
660
+ const useModalIndex = () => {
661
+ return React.useContext(ModalIndexContext);
662
+ };
663
+ const ModalRenderer = ({ index }) => {
664
+ const { stack } = useModalStack();
665
+ const modalContext = useMemo(() => {
666
+ return stack[index];
667
+ }, [stack, index]);
668
+ if (!modalContext?.component) {
669
+ return null;
1891
670
  }
1892
- return t;
1893
- }
1894
- function ri(e, t) {
1895
- return re(t.type, ti, e, t);
1896
- }
1897
- let er = V(function(e, t) {
1898
- let r = _e(), { id: n = `headlessui-dialog-${r}`, open: l, onClose: i, initialFocus: a, role: s = "dialog", autoFocus: o = !0, __demoMode: u = !1, unmount: m = !1, ...b } = e, g = S(!1);
1899
- s = (function() {
1900
- return s === "dialog" || s === "alertdialog" ? s : (g.current || (g.current = !0, console.warn(`Invalid role [${s}] passed to <Dialog />. Only \`dialog\` and and \`alertdialog\` are supported. Using \`dialog\` instead.`)), "dialog");
1901
- })();
1902
- let y = lt();
1903
- l === void 0 && y !== null && (l = (y & q.Open) === q.Open);
1904
- let f = S(null), E = J(f, t), h = Ct(f.current), c = l ? 0 : 1, [d, v] = Gr(ri, { titleId: null, descriptionId: null, panelRef: Kr() }), w = M(() => i(!1)), p = M((T) => v({ type: 0, id: T })), x = it() ? c === 0 : !1, [O, N] = Al(), D = { get current() {
1905
- var T;
1906
- return (T = d.panelRef.current) != null ? T : f.current;
1907
- } }, C = kr(), { resolveContainers: I } = Rl({ mainTreeNode: C, portals: O, defaultContainers: [D] }), B = y !== null ? (y & q.Closing) === q.Closing : !1;
1908
- Kn(u || B ? !1 : x, { allowed: M(() => {
1909
- var T, Ue;
1910
- return [(Ue = (T = f.current) == null ? void 0 : T.closest("[data-headlessui-portal]")) != null ? Ue : null];
1911
- }), disallowed: M(() => {
1912
- var T;
1913
- return [(T = C == null ? void 0 : C.closest("body > *:not(#headlessui-portal-root)")) != null ? T : null];
671
+ return /* @__PURE__ */ jsx(ModalIndexContext.Provider, { value: index, children: createElement(modalContext.component, {
672
+ ...modalContext.props,
673
+ onModalEvent: (...args) => modalContext.emit("modal-event", ...args)
1914
674
  }) });
1915
- let R = wr.get(null);
1916
- U(() => {
1917
- if (x) return R.actions.push(n), () => R.actions.pop(n);
1918
- }, [R, n, x]);
1919
- let k = yr(R, W((T) => R.selectors.isTop(T, n), [R, n]));
1920
- ol(k, I, (T) => {
1921
- T.preventDefault(), w();
1922
- }), Nl(k, h == null ? void 0 : h.defaultView, (T) => {
1923
- T.preventDefault(), T.stopPropagation(), document.activeElement && "blur" in document.activeElement && typeof document.activeElement.blur == "function" && document.activeElement.blur(), w();
1924
- }), pl(u || B ? !1 : x, h, I), qn(x, f, w);
1925
- let [j, ge] = Pn(), ce = _(() => [{ dialogState: c, close: w, setTitleId: p, unmount: m }, d], [c, w, p, m, d]), Q = je({ open: c === 0 }), A = { ref: E, id: n, role: s, tabIndex: -1, "aria-modal": u ? void 0 : c === 0 ? !0 : void 0, "aria-labelledby": d.titleId, "aria-describedby": j, unmount: m }, $e = !Il(), le = fe.None;
1926
- x && !u && (le |= fe.RestoreFocus, le |= fe.TabLock, o && (le |= fe.AutoFocus), $e && (le |= fe.InitialFocus));
1927
- let ct = G();
1928
- return $.createElement($l, null, $.createElement(Jt, { force: !0 }, $.createElement(Fl, null, $.createElement(It.Provider, { value: ce }, $.createElement(Mr, { target: f }, $.createElement(Jt, { force: !1 }, $.createElement(ge, { slot: Q }, $.createElement(N, null, $.createElement(Hl, { initialFocus: a, initialFocusFallback: f, containers: I, features: le }, $.createElement(Fn, { value: w }, ct({ ourProps: A, theirProps: b, slot: Q, defaultTag: ni, features: li, visible: c === 0, name: "Dialog" })))))))))));
1929
- }), ni = "div", li = qe.RenderStrategy | qe.Static;
1930
- function ii(e, t) {
1931
- let { transition: r = !1, open: n, ...l } = e, i = lt(), a = e.hasOwnProperty("open") || i !== null, s = e.hasOwnProperty("onClose");
1932
- if (!a && !s) throw new Error("You have to provide an `open` and an `onClose` prop to the `Dialog` component.");
1933
- if (!a) throw new Error("You provided an `onClose` prop to the `Dialog`, but forgot an `open` prop.");
1934
- if (!s) throw new Error("You provided an `open` prop to the `Dialog`, but forgot an `onClose` prop.");
1935
- if (!i && typeof e.open != "boolean") throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${e.open}`);
1936
- if (typeof e.onClose != "function") throw new Error(`You provided an \`onClose\` prop to the \`Dialog\`, but the value is not a function. Received: ${e.onClose}`);
1937
- return (n !== void 0 || r) && !l.static ? $.createElement(Qt, null, $.createElement(Dr, { show: n, transition: r, unmount: l.unmount }, $.createElement(er, { ref: t, ...l }))) : $.createElement(Qt, null, $.createElement(er, { ref: t, open: n, ...l }));
1938
- }
1939
- let oi = "div";
1940
- function ai(e, t) {
1941
- let r = _e(), { id: n = `headlessui-dialog-panel-${r}`, transition: l = !1, ...i } = e, [{ dialogState: a, unmount: s }, o] = ut("Dialog.Panel"), u = J(t, o.panelRef), m = je({ open: a === 0 }), b = M((h) => {
1942
- h.stopPropagation();
1943
- }), g = { ref: u, id: n, onClick: b }, y = l ? Ee : ue, f = l ? { unmount: s } : {}, E = G();
1944
- return $.createElement(y, { ...f }, E({ ourProps: g, theirProps: i, slot: m, defaultTag: oi, name: "Dialog.Panel" }));
1945
- }
1946
- let si = "div";
1947
- function ui(e, t) {
1948
- let { transition: r = !1, ...n } = e, [{ dialogState: l, unmount: i }] = ut("Dialog.Backdrop"), a = je({ open: l === 0 }), s = { ref: t, "aria-hidden": !0 }, o = r ? Ee : ue, u = r ? { unmount: i } : {}, m = G();
1949
- return $.createElement(o, { ...u }, m({ ourProps: s, theirProps: n, slot: a, defaultTag: si, name: "Dialog.Backdrop" }));
1950
- }
1951
- let ci = "h2";
1952
- function di(e, t) {
1953
- let r = _e(), { id: n = `headlessui-dialog-title-${r}`, ...l } = e, [{ dialogState: i, setTitleId: a }] = ut("Dialog.Title"), s = J(t);
1954
- L(() => (a(n), () => a(null)), [n, a]);
1955
- let o = je({ open: i === 0 }), u = { ref: s, id: n };
1956
- return G()({ ourProps: u, theirProps: l, slot: o, defaultTag: ci, name: "Dialog.Title" });
675
+ };
676
+ function useModal() {
677
+ return useModalStack().stack[useModalIndex()] ?? null;
1957
678
  }
1958
- let fi = V(ii), Rt = V(ai);
1959
- V(ui);
1960
- let pi = V(di), mi = Object.assign(fi, { Panel: Rt, Title: pi, Description: An });
1961
- function jr({ onClick: e }) {
1962
- return /* @__PURE__ */ he(
679
+ const Deferred = ({ children, data, fallback }) => {
680
+ if (!data) {
681
+ throw new Error("`<Deferred>` requires a `data` prop to be a string or array of strings");
682
+ }
683
+ const [loaded, setLoaded] = useState(false);
684
+ const keys = Array.isArray(data) ? data : [data];
685
+ const modal = useModal();
686
+ const modalProps = modal?.props ?? {};
687
+ useEffect(() => {
688
+ setLoaded(keys.every((key) => modalProps[key] !== void 0));
689
+ }, [modalProps, keys]);
690
+ return loaded ? children : fallback;
691
+ };
692
+ Deferred.displayName = "InertiaModalDeferred";
693
+ const HeadlessModal = forwardRef(
694
+ (allProps, ref) => {
695
+ const { name, children, onFocus, onBlur, onClose, onSuccess, ...props } = allProps;
696
+ const modalIndex = useModalIndex();
697
+ const { stack, registerLocalModal, removeLocalModal } = useModalStack();
698
+ const [localModalContext, setLocalModalContext] = useState(null);
699
+ const modalContext = useMemo(
700
+ () => name ? localModalContext : stack[modalIndex],
701
+ [name, localModalContext, modalIndex, stack]
702
+ );
703
+ const nextIndex = useMemo(() => {
704
+ return stack.find((m) => m.shouldRender && m.index > (modalContext?.index ?? -1))?.index;
705
+ }, [modalIndex, stack]);
706
+ const configSlideover = useMemo(
707
+ () => modalContext?.config.slideover ?? props.slideover ?? getConfig("type") === "slideover",
708
+ [props.slideover, modalContext?.config.slideover]
709
+ );
710
+ const config = useMemo(
711
+ () => ({
712
+ slideover: configSlideover,
713
+ closeButton: props.closeButton ?? getConfigByType(configSlideover, "closeButton"),
714
+ closeExplicitly: props.closeExplicitly ?? getConfigByType(configSlideover, "closeExplicitly"),
715
+ closeOnClickOutside: props.closeOnClickOutside ?? getConfigByType(configSlideover, "closeOnClickOutside"),
716
+ maxWidth: props.maxWidth ?? getConfigByType(configSlideover, "maxWidth"),
717
+ paddingClasses: props.paddingClasses ?? getConfigByType(configSlideover, "paddingClasses"),
718
+ panelClasses: props.panelClasses ?? getConfigByType(configSlideover, "panelClasses"),
719
+ position: props.position ?? getConfigByType(configSlideover, "position"),
720
+ ...modalContext?.config
721
+ }),
722
+ [props, modalContext?.config, configSlideover]
723
+ );
724
+ useEffect(() => {
725
+ if (name) {
726
+ let removeListeners = null;
727
+ registerLocalModal(name, (localContext) => {
728
+ removeListeners = localContext.registerEventListenersFromProps(props);
729
+ setLocalModalContext(localContext);
730
+ });
731
+ return () => {
732
+ removeListeners?.();
733
+ removeListeners = null;
734
+ removeLocalModal(name);
735
+ };
736
+ }
737
+ return modalContext?.registerEventListenersFromProps(props);
738
+ }, [name]);
739
+ const modalContextRef = useRef(modalContext);
740
+ useEffect(() => {
741
+ modalContextRef.current = modalContext;
742
+ }, [modalContext]);
743
+ const previousIsOpenRef = useRef(void 0);
744
+ useEffect(() => {
745
+ if (modalContext !== null) {
746
+ if (modalContext.isOpen) {
747
+ onSuccess?.();
748
+ } else if (previousIsOpenRef.current === true) {
749
+ onClose?.();
750
+ }
751
+ previousIsOpenRef.current = modalContext.isOpen;
752
+ }
753
+ }, [modalContext?.isOpen]);
754
+ const [rendered, setRendered] = useState(false);
755
+ useEffect(() => {
756
+ if (rendered && modalContext !== null && modalContext.isOpen) {
757
+ if (modalContext.onTopOfStack) {
758
+ onFocus?.();
759
+ } else {
760
+ onBlur?.();
761
+ }
762
+ }
763
+ setRendered(true);
764
+ }, [modalContext?.onTopOfStack]);
765
+ useImperativeHandle(
766
+ ref,
767
+ () => ({
768
+ afterLeave: () => modalContextRef.current?.afterLeave(),
769
+ close: () => modalContextRef.current?.close(),
770
+ emit: (...args) => modalContextRef.current?.emit(...args),
771
+ getChildModal: () => modalContextRef.current?.getChildModal(),
772
+ getParentModal: () => modalContextRef.current?.getParentModal(),
773
+ reload: (options) => modalContextRef.current?.reload(options),
774
+ setOpen: (open) => modalContextRef.current?.setOpen(open),
775
+ get id() {
776
+ return modalContextRef.current?.id;
777
+ },
778
+ get index() {
779
+ return modalContextRef.current?.index;
780
+ },
781
+ get isOpen() {
782
+ return modalContextRef.current?.isOpen;
783
+ },
784
+ get config() {
785
+ return modalContextRef.current?.config;
786
+ },
787
+ get modalContext() {
788
+ return modalContextRef.current;
789
+ },
790
+ get onTopOfStack() {
791
+ return modalContextRef.current?.onTopOfStack;
792
+ },
793
+ get shouldRender() {
794
+ return modalContextRef.current?.shouldRender;
795
+ }
796
+ }),
797
+ [modalContext]
798
+ );
799
+ if (!modalContext?.shouldRender) {
800
+ return null;
801
+ }
802
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
803
+ typeof children === "function" ? children({
804
+ // Spread props first so they can be overridden by built-in props
805
+ ...modalContext.props,
806
+ afterLeave: modalContext.afterLeave,
807
+ close: modalContext.close,
808
+ config,
809
+ emit: modalContext.emit,
810
+ getChildModal: modalContext.getChildModal,
811
+ getParentModal: modalContext.getParentModal,
812
+ id: modalContext.id,
813
+ index: modalContext.index,
814
+ isOpen: modalContext.isOpen,
815
+ modalContext,
816
+ onTopOfStack: modalContext.onTopOfStack,
817
+ reload: modalContext.reload,
818
+ setOpen: modalContext.setOpen,
819
+ shouldRender: modalContext.shouldRender
820
+ }) : children,
821
+ nextIndex !== void 0 && /* @__PURE__ */ jsx(ModalRenderer, { index: nextIndex })
822
+ ] });
823
+ }
824
+ );
825
+ HeadlessModal.displayName = "HeadlessModal";
826
+ function CloseButton({ onClick }) {
827
+ return /* @__PURE__ */ jsxs(
1963
828
  "button",
1964
829
  {
1965
830
  type: "button",
1966
831
  className: "im-close-button text-gray-400 hover:text-gray-500",
1967
- onClick: e,
832
+ onClick,
1968
833
  children: [
1969
- /* @__PURE__ */ P("span", { className: "sr-only", children: "Close" }),
1970
- /* @__PURE__ */ P(
834
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" }),
835
+ /* @__PURE__ */ jsx(
1971
836
  "svg",
1972
837
  {
1973
838
  className: "size-6",
@@ -1977,7 +842,7 @@ function jr({ onClick: e }) {
1977
842
  strokeWidth: "2",
1978
843
  stroke: "currentColor",
1979
844
  "aria-hidden": "true",
1980
- children: /* @__PURE__ */ P(
845
+ children: /* @__PURE__ */ jsx(
1981
846
  "path",
1982
847
  {
1983
848
  strokeLinecap: "round",
@@ -1991,338 +856,986 @@ function jr({ onClick: e }) {
1991
856
  }
1992
857
  );
1993
858
  }
1994
- const hi = ({ modalContext: e, config: t, children: r }) => {
1995
- const [n, l] = F(!1);
1996
- return /* @__PURE__ */ P("div", { className: "im-modal-container fixed inset-0 z-40 overflow-y-auto p-4", children: /* @__PURE__ */ P(
859
+ function r(e) {
860
+ var t, f, n = "";
861
+ if ("string" == typeof e || "number" == typeof e) n += e;
862
+ else if ("object" == typeof e) if (Array.isArray(e)) {
863
+ var o = e.length;
864
+ for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
865
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
866
+ return n;
867
+ }
868
+ function clsx() {
869
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
870
+ return n;
871
+ }
872
+ const maxWidthClasses = {
873
+ sm: "sm:max-w-sm",
874
+ md: "sm:max-w-md",
875
+ lg: "sm:max-w-md md:max-w-lg",
876
+ xl: "sm:max-w-md md:max-w-xl",
877
+ "2xl": "sm:max-w-md md:max-w-xl lg:max-w-2xl",
878
+ "3xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl",
879
+ "4xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-4xl",
880
+ "5xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl",
881
+ "6xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-6xl",
882
+ "7xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-7xl"
883
+ };
884
+ const defaultMaxWidth = "2xl";
885
+ function getMaxWidthClass(maxWidth) {
886
+ return maxWidthClasses[maxWidth] || maxWidthClasses[defaultMaxWidth];
887
+ }
888
+ const ModalContent = ({ modalContext, config, useNativeDialog, isFirstModal, onAfterLeave, children }) => {
889
+ const [isRendered, setIsRendered] = useState(false);
890
+ const [isVisible, setIsVisible] = useState(false);
891
+ const [entered, setEntered] = useState(false);
892
+ const wrapperRef = useRef(null);
893
+ const dialogRef = useRef(null);
894
+ const nativeWrapperRef = useRef(null);
895
+ const cleanupFocusTrapRef = useRef(null);
896
+ const cleanupEscapeKeyRef = useRef(null);
897
+ const maxWidthClass = useMemo(() => getMaxWidthClass(config.maxWidth), [config.maxWidth]);
898
+ const animateIn = useCallback(async (element) => {
899
+ if (!element) return;
900
+ setIsVisible(true);
901
+ await animate(element, [
902
+ { transform: "translate3d(0, 1rem, 0) scale(0.95)", opacity: 0 },
903
+ { transform: "translate3d(0, 0, 0) scale(1)", opacity: 1 }
904
+ ]);
905
+ setEntered(true);
906
+ }, []);
907
+ const animateOut = useCallback(
908
+ async (element) => {
909
+ if (!element) return;
910
+ setIsVisible(false);
911
+ await animate(element, [
912
+ { transform: "translate3d(0, 0, 0) scale(1)", opacity: 1 },
913
+ { transform: "translate3d(0, 1rem, 0) scale(0.95)", opacity: 0 }
914
+ ]);
915
+ setIsRendered(false);
916
+ if (useNativeDialog && dialogRef.current) {
917
+ dialogRef.current.close();
918
+ }
919
+ onAfterLeave?.();
920
+ modalContext.afterLeave();
921
+ },
922
+ [useNativeDialog, onAfterLeave, modalContext]
923
+ );
924
+ const setupFocusTrap = useCallback(() => {
925
+ if (useNativeDialog) return;
926
+ if (!wrapperRef.current || !modalContext.onTopOfStack) return;
927
+ if (cleanupFocusTrapRef.current) return;
928
+ cleanupFocusTrapRef.current = createFocusTrap(wrapperRef.current, {
929
+ initialFocus: true,
930
+ returnFocus: false
931
+ });
932
+ }, [modalContext.onTopOfStack, useNativeDialog]);
933
+ const cleanupFocusTrap = useCallback(() => {
934
+ if (cleanupFocusTrapRef.current) {
935
+ cleanupFocusTrapRef.current();
936
+ cleanupFocusTrapRef.current = null;
937
+ }
938
+ }, []);
939
+ const setupEscapeKey = useCallback(() => {
940
+ if (useNativeDialog) return;
941
+ if (cleanupEscapeKeyRef.current) return;
942
+ if (config?.closeExplicitly) return;
943
+ cleanupEscapeKeyRef.current = onEscapeKey(() => {
944
+ if (modalContext.onTopOfStack) {
945
+ modalContext.close();
946
+ }
947
+ });
948
+ }, [config?.closeExplicitly, modalContext, useNativeDialog]);
949
+ const cleanupEscapeKey = useCallback(() => {
950
+ if (cleanupEscapeKeyRef.current) {
951
+ cleanupEscapeKeyRef.current();
952
+ cleanupEscapeKeyRef.current = null;
953
+ }
954
+ }, []);
955
+ const handleClickOutside = useCallback(
956
+ (event) => {
957
+ if (useNativeDialog) return;
958
+ if (!modalContext.onTopOfStack) return;
959
+ if (config?.closeExplicitly) return;
960
+ if (config?.closeOnClickOutside === false) return;
961
+ if (!wrapperRef.current) return;
962
+ if (!wrapperRef.current.contains(event.target)) {
963
+ modalContext.close();
964
+ }
965
+ },
966
+ [modalContext, config?.closeExplicitly, config?.closeOnClickOutside, useNativeDialog]
967
+ );
968
+ const handleCancel = useCallback(
969
+ (event) => {
970
+ event.preventDefault();
971
+ if (modalContext.onTopOfStack && !config?.closeExplicitly) {
972
+ modalContext.close();
973
+ }
974
+ },
975
+ [modalContext, config?.closeExplicitly]
976
+ );
977
+ const handleDialogClick = useCallback(
978
+ (event) => {
979
+ if (event.target === dialogRef.current) {
980
+ if (modalContext.onTopOfStack && !config?.closeExplicitly && config?.closeOnClickOutside !== false) {
981
+ modalContext.close();
982
+ }
983
+ }
984
+ },
985
+ [modalContext, config?.closeExplicitly, config?.closeOnClickOutside]
986
+ );
987
+ const prevIsOpenRef = useRef(modalContext.isOpen);
988
+ useEffect(() => {
989
+ if (useNativeDialog) {
990
+ if (modalContext.isOpen && !dialogRef.current?.open) {
991
+ dialogRef.current?.showModal();
992
+ animateIn(nativeWrapperRef.current);
993
+ } else if (!modalContext.isOpen && prevIsOpenRef.current) {
994
+ setEntered(false);
995
+ animateOut(nativeWrapperRef.current);
996
+ }
997
+ } else {
998
+ if (modalContext.isOpen && !isRendered) {
999
+ setIsRendered(true);
1000
+ } else if (!modalContext.isOpen && prevIsOpenRef.current) {
1001
+ setEntered(false);
1002
+ animateOut(wrapperRef.current);
1003
+ }
1004
+ }
1005
+ prevIsOpenRef.current = modalContext.isOpen;
1006
+ }, [modalContext.isOpen, useNativeDialog, animateIn, animateOut, isRendered]);
1007
+ useEffect(() => {
1008
+ if (!useNativeDialog && isRendered && !entered && modalContext.isOpen) {
1009
+ animateIn(wrapperRef.current).then(() => {
1010
+ setupFocusTrap();
1011
+ });
1012
+ }
1013
+ }, [isRendered, useNativeDialog, entered, modalContext.isOpen, animateIn, setupFocusTrap]);
1014
+ useEffect(() => {
1015
+ if (!useNativeDialog) {
1016
+ setupEscapeKey();
1017
+ }
1018
+ return () => {
1019
+ cleanupEscapeKey();
1020
+ };
1021
+ }, [useNativeDialog, setupEscapeKey, cleanupEscapeKey]);
1022
+ useEffect(() => {
1023
+ if (useNativeDialog) return;
1024
+ if (modalContext.onTopOfStack) {
1025
+ setupEscapeKey();
1026
+ if (entered) {
1027
+ setupFocusTrap();
1028
+ }
1029
+ } else {
1030
+ cleanupFocusTrap();
1031
+ cleanupEscapeKey();
1032
+ }
1033
+ }, [modalContext.onTopOfStack, entered, setupEscapeKey, setupFocusTrap, cleanupFocusTrap, cleanupEscapeKey, useNativeDialog]);
1034
+ useEffect(() => {
1035
+ return () => {
1036
+ const wrapper = useNativeDialog ? nativeWrapperRef.current : wrapperRef.current;
1037
+ if (wrapper) {
1038
+ cancelAnimations(wrapper);
1039
+ }
1040
+ if (useNativeDialog) {
1041
+ if (dialogRef.current?.open) {
1042
+ dialogRef.current.close();
1043
+ }
1044
+ } else {
1045
+ cleanupFocusTrap();
1046
+ cleanupEscapeKey();
1047
+ }
1048
+ };
1049
+ }, [useNativeDialog, cleanupFocusTrap, cleanupEscapeKey]);
1050
+ const renderContent = () => /* @__PURE__ */ jsxs(
1997
1051
  "div",
1998
1052
  {
1999
- className: Ke("im-modal-positioner flex min-h-full justify-center", {
2000
- "items-start": t.position === "top",
2001
- "items-center": t.position === "center",
2002
- "items-end": t.position === "bottom"
2003
- }),
2004
- children: /* @__PURE__ */ P(
2005
- Ee,
1053
+ className: `im-modal-content relative ${config.paddingClasses} ${config.panelClasses}`,
1054
+ "data-inertiaui-modal-entered": entered,
1055
+ children: [
1056
+ config.closeButton && /* @__PURE__ */ jsx("div", { className: "absolute right-0 top-0 pr-3 pt-3", children: /* @__PURE__ */ jsx(CloseButton, { onClick: modalContext.close }) }),
1057
+ typeof children === "function" ? children({ modalContext, config }) : children
1058
+ ]
1059
+ }
1060
+ );
1061
+ if (useNativeDialog) {
1062
+ return /* @__PURE__ */ jsx(
1063
+ "dialog",
1064
+ {
1065
+ ref: dialogRef,
1066
+ className: clsx(
1067
+ "im-modal-dialog m-0 overflow-visible bg-transparent p-0",
1068
+ "size-full max-h-none max-w-none",
1069
+ "backdrop:bg-black/75 backdrop:transition-opacity backdrop:duration-300",
1070
+ isVisible ? "backdrop:opacity-100" : "backdrop:opacity-0",
1071
+ !isFirstModal && "backdrop:bg-transparent"
1072
+ ),
1073
+ onCancel: handleCancel,
1074
+ onClick: handleDialogClick,
1075
+ children: /* @__PURE__ */ jsx("div", { className: "im-modal-container fixed inset-0 overflow-y-auto p-4", children: /* @__PURE__ */ jsx(
1076
+ "div",
1077
+ {
1078
+ className: clsx("im-modal-positioner flex min-h-full justify-center", {
1079
+ "items-start": config.position === "top",
1080
+ "items-center": config.position === "center",
1081
+ "items-end": config.position === "bottom"
1082
+ }),
1083
+ children: /* @__PURE__ */ jsx(
1084
+ "div",
1085
+ {
1086
+ ref: nativeWrapperRef,
1087
+ className: clsx("im-modal-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
1088
+ children: renderContent()
1089
+ }
1090
+ )
1091
+ }
1092
+ ) })
1093
+ }
1094
+ );
1095
+ }
1096
+ if (!isRendered) return null;
1097
+ return /* @__PURE__ */ jsx(
1098
+ "div",
1099
+ {
1100
+ className: "im-modal-container fixed inset-0 z-40 overflow-y-auto p-4",
1101
+ onMouseDown: handleClickOutside,
1102
+ children: /* @__PURE__ */ jsx(
1103
+ "div",
2006
1104
  {
2007
- as: "div",
2008
- enterFrom: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
2009
- enterTo: "opacity-100 translate-y-0 sm:scale-100",
2010
- leaveFrom: "opacity-100 translate-y-0 sm:scale-100",
2011
- leaveTo: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
2012
- afterEnter: () => l(!0),
2013
- afterLeave: e.afterLeave,
2014
- className: Ke("im-modal-wrapper w-full transition duration-300 ease-in-out", e.onTopOfStack ? "" : "blur-sm", {
2015
- "sm:max-w-sm": t.maxWidth === "sm",
2016
- "sm:max-w-md": t.maxWidth === "md",
2017
- "sm:max-w-md md:max-w-lg": t.maxWidth === "lg",
2018
- "sm:max-w-md md:max-w-xl": t.maxWidth === "xl",
2019
- "sm:max-w-md md:max-w-xl lg:max-w-2xl": t.maxWidth === "2xl",
2020
- "sm:max-w-md md:max-w-xl lg:max-w-3xl": t.maxWidth === "3xl",
2021
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-4xl": t.maxWidth === "4xl",
2022
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl": t.maxWidth === "5xl",
2023
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-6xl": t.maxWidth === "6xl",
2024
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-7xl": t.maxWidth === "7xl"
1105
+ className: clsx("im-modal-positioner flex min-h-full justify-center", {
1106
+ "items-start": config.position === "top",
1107
+ "items-center": config.position === "center",
1108
+ "items-end": config.position === "bottom"
2025
1109
  }),
2026
- children: /* @__PURE__ */ he(
2027
- Rt,
1110
+ onMouseDown: handleClickOutside,
1111
+ children: /* @__PURE__ */ jsxs(
1112
+ "div",
2028
1113
  {
2029
- className: `im-modal-content relative ${t.paddingClasses} ${t.panelClasses}`,
2030
- "data-inertiaui-modal-entered": n,
1114
+ ref: wrapperRef,
1115
+ role: "dialog",
1116
+ "aria-modal": "true",
1117
+ className: clsx("im-modal-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
2031
1118
  children: [
2032
- t.closeButton && /* @__PURE__ */ P("div", { className: "absolute right-0 top-0 pr-3 pt-3", children: /* @__PURE__ */ P(jr, { onClick: e.close }) }),
2033
- typeof r == "function" ? r({ modalContext: e, config: t }) : r
1119
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Dialog" }),
1120
+ renderContent()
2034
1121
  ]
2035
1122
  }
2036
1123
  )
2037
1124
  }
2038
1125
  )
2039
1126
  }
2040
- ) });
2041
- }, vi = ({ modalContext: e, config: t, children: r }) => {
2042
- const [n, l] = F(!1);
2043
- return /* @__PURE__ */ P("div", { className: "im-slideover-container fixed inset-0 z-40 overflow-y-auto overflow-x-hidden", children: /* @__PURE__ */ P(
1127
+ );
1128
+ };
1129
+ const SlideoverContent = ({ modalContext, config, useNativeDialog, isFirstModal, onAfterLeave, children }) => {
1130
+ const [isRendered, setIsRendered] = useState(false);
1131
+ const [isVisible, setIsVisible] = useState(false);
1132
+ const [entered, setEntered] = useState(false);
1133
+ const wrapperRef = useRef(null);
1134
+ const dialogRef = useRef(null);
1135
+ const nativeWrapperRef = useRef(null);
1136
+ const cleanupFocusTrapRef = useRef(null);
1137
+ const cleanupEscapeKeyRef = useRef(null);
1138
+ const isLeft = config.position === "left";
1139
+ const maxWidthClass = useMemo(() => getMaxWidthClass(config.maxWidth), [config.maxWidth]);
1140
+ const getTranslateX = useCallback(() => isLeft ? "-100%" : "100%", [isLeft]);
1141
+ const animateIn = useCallback(
1142
+ async (element) => {
1143
+ if (!element) return;
1144
+ setIsVisible(true);
1145
+ const translateX = getTranslateX();
1146
+ await animate(element, [
1147
+ { transform: `translate3d(${translateX}, 0, 0)`, opacity: 0 },
1148
+ { transform: "translate3d(0, 0, 0)", opacity: 1 }
1149
+ ]);
1150
+ setEntered(true);
1151
+ },
1152
+ [getTranslateX]
1153
+ );
1154
+ const animateOut = useCallback(
1155
+ async (element) => {
1156
+ if (!element) return;
1157
+ setIsVisible(false);
1158
+ const translateX = getTranslateX();
1159
+ await animate(element, [
1160
+ { transform: "translate3d(0, 0, 0)", opacity: 1 },
1161
+ { transform: `translate3d(${translateX}, 0, 0)`, opacity: 0 }
1162
+ ]);
1163
+ setIsRendered(false);
1164
+ if (useNativeDialog && dialogRef.current) {
1165
+ dialogRef.current.close();
1166
+ }
1167
+ onAfterLeave?.();
1168
+ modalContext.afterLeave();
1169
+ },
1170
+ [getTranslateX, useNativeDialog, onAfterLeave, modalContext]
1171
+ );
1172
+ const setupFocusTrap = useCallback(() => {
1173
+ if (useNativeDialog) return;
1174
+ if (!wrapperRef.current || !modalContext.onTopOfStack) return;
1175
+ if (cleanupFocusTrapRef.current) return;
1176
+ cleanupFocusTrapRef.current = createFocusTrap(wrapperRef.current, {
1177
+ initialFocus: true,
1178
+ returnFocus: false
1179
+ });
1180
+ }, [modalContext.onTopOfStack, useNativeDialog]);
1181
+ const cleanupFocusTrap = useCallback(() => {
1182
+ if (cleanupFocusTrapRef.current) {
1183
+ cleanupFocusTrapRef.current();
1184
+ cleanupFocusTrapRef.current = null;
1185
+ }
1186
+ }, []);
1187
+ const setupEscapeKey = useCallback(() => {
1188
+ if (useNativeDialog) return;
1189
+ if (cleanupEscapeKeyRef.current) return;
1190
+ if (config?.closeExplicitly) return;
1191
+ cleanupEscapeKeyRef.current = onEscapeKey(() => {
1192
+ if (modalContext.onTopOfStack) {
1193
+ modalContext.close();
1194
+ }
1195
+ });
1196
+ }, [config?.closeExplicitly, modalContext, useNativeDialog]);
1197
+ const cleanupEscapeKey = useCallback(() => {
1198
+ if (cleanupEscapeKeyRef.current) {
1199
+ cleanupEscapeKeyRef.current();
1200
+ cleanupEscapeKeyRef.current = null;
1201
+ }
1202
+ }, []);
1203
+ const handleClickOutside = useCallback(
1204
+ (event) => {
1205
+ if (useNativeDialog) return;
1206
+ if (!modalContext.onTopOfStack) return;
1207
+ if (config?.closeExplicitly) return;
1208
+ if (config?.closeOnClickOutside === false) return;
1209
+ if (!wrapperRef.current) return;
1210
+ if (!wrapperRef.current.contains(event.target)) {
1211
+ modalContext.close();
1212
+ }
1213
+ },
1214
+ [modalContext, config?.closeExplicitly, config?.closeOnClickOutside, useNativeDialog]
1215
+ );
1216
+ const handleCancel = useCallback(
1217
+ (event) => {
1218
+ event.preventDefault();
1219
+ if (modalContext.onTopOfStack && !config?.closeExplicitly) {
1220
+ modalContext.close();
1221
+ }
1222
+ },
1223
+ [modalContext, config?.closeExplicitly]
1224
+ );
1225
+ const handleDialogClick = useCallback(
1226
+ (event) => {
1227
+ if (event.target === dialogRef.current) {
1228
+ if (modalContext.onTopOfStack && !config?.closeExplicitly && config?.closeOnClickOutside !== false) {
1229
+ modalContext.close();
1230
+ }
1231
+ }
1232
+ },
1233
+ [modalContext, config?.closeExplicitly, config?.closeOnClickOutside]
1234
+ );
1235
+ const prevIsOpenRef = useRef(modalContext.isOpen);
1236
+ useEffect(() => {
1237
+ if (useNativeDialog) {
1238
+ if (modalContext.isOpen && !dialogRef.current?.open) {
1239
+ dialogRef.current?.showModal();
1240
+ animateIn(nativeWrapperRef.current);
1241
+ } else if (!modalContext.isOpen && prevIsOpenRef.current) {
1242
+ setEntered(false);
1243
+ animateOut(nativeWrapperRef.current);
1244
+ }
1245
+ } else {
1246
+ if (modalContext.isOpen && !isRendered) {
1247
+ setIsRendered(true);
1248
+ } else if (!modalContext.isOpen && prevIsOpenRef.current) {
1249
+ setEntered(false);
1250
+ animateOut(wrapperRef.current);
1251
+ }
1252
+ }
1253
+ prevIsOpenRef.current = modalContext.isOpen;
1254
+ }, [modalContext.isOpen, useNativeDialog, animateIn, animateOut, isRendered]);
1255
+ useEffect(() => {
1256
+ if (!useNativeDialog && isRendered && !entered && modalContext.isOpen) {
1257
+ animateIn(wrapperRef.current).then(() => {
1258
+ setupFocusTrap();
1259
+ });
1260
+ }
1261
+ }, [isRendered, useNativeDialog, entered, modalContext.isOpen, animateIn, setupFocusTrap]);
1262
+ useEffect(() => {
1263
+ if (!useNativeDialog) {
1264
+ setupEscapeKey();
1265
+ }
1266
+ return () => {
1267
+ cleanupEscapeKey();
1268
+ };
1269
+ }, [useNativeDialog, setupEscapeKey, cleanupEscapeKey]);
1270
+ useEffect(() => {
1271
+ if (useNativeDialog) return;
1272
+ if (modalContext.onTopOfStack) {
1273
+ setupEscapeKey();
1274
+ if (entered) {
1275
+ setupFocusTrap();
1276
+ }
1277
+ } else {
1278
+ cleanupFocusTrap();
1279
+ cleanupEscapeKey();
1280
+ }
1281
+ }, [modalContext.onTopOfStack, entered, setupEscapeKey, setupFocusTrap, cleanupFocusTrap, cleanupEscapeKey, useNativeDialog]);
1282
+ useEffect(() => {
1283
+ return () => {
1284
+ const wrapper = useNativeDialog ? nativeWrapperRef.current : wrapperRef.current;
1285
+ if (wrapper) {
1286
+ cancelAnimations(wrapper);
1287
+ }
1288
+ if (useNativeDialog) {
1289
+ if (dialogRef.current?.open) {
1290
+ dialogRef.current.close();
1291
+ }
1292
+ } else {
1293
+ cleanupFocusTrap();
1294
+ cleanupEscapeKey();
1295
+ }
1296
+ };
1297
+ }, [useNativeDialog, cleanupFocusTrap, cleanupEscapeKey]);
1298
+ const renderContent = () => /* @__PURE__ */ jsxs(
2044
1299
  "div",
2045
1300
  {
2046
- className: Ke("im-slideover-positioner flex min-h-full items-center", {
2047
- "justify-start rtl:justify-end": (t == null ? void 0 : t.position) === "left",
2048
- "justify-end rtl:justify-start": (t == null ? void 0 : t.position) === "right"
2049
- }),
2050
- children: /* @__PURE__ */ P(
2051
- Ee,
1301
+ className: `im-slideover-content relative ${config.paddingClasses} ${config.panelClasses}`,
1302
+ "data-inertiaui-modal-entered": entered,
1303
+ children: [
1304
+ config.closeButton && /* @__PURE__ */ jsx("div", { className: "absolute right-0 top-0 pr-3 pt-3", children: /* @__PURE__ */ jsx(CloseButton, { onClick: modalContext.close }) }),
1305
+ typeof children === "function" ? children({ modalContext, config }) : children
1306
+ ]
1307
+ }
1308
+ );
1309
+ if (useNativeDialog) {
1310
+ return /* @__PURE__ */ jsx(
1311
+ "dialog",
1312
+ {
1313
+ ref: dialogRef,
1314
+ className: clsx(
1315
+ "im-slideover-dialog m-0 overflow-visible bg-transparent p-0",
1316
+ "size-full max-h-none max-w-none",
1317
+ "backdrop:bg-black/75 backdrop:transition-opacity backdrop:duration-300",
1318
+ isVisible ? "backdrop:opacity-100" : "backdrop:opacity-0",
1319
+ !isFirstModal && "backdrop:bg-transparent"
1320
+ ),
1321
+ onCancel: handleCancel,
1322
+ onClick: handleDialogClick,
1323
+ children: /* @__PURE__ */ jsx("div", { className: "im-slideover-container fixed inset-0 overflow-y-auto overflow-x-hidden", children: /* @__PURE__ */ jsx(
1324
+ "div",
1325
+ {
1326
+ className: clsx("im-slideover-positioner flex min-h-full items-center", {
1327
+ "justify-start rtl:justify-end": config?.position === "left",
1328
+ "justify-end rtl:justify-start": config?.position === "right"
1329
+ }),
1330
+ children: /* @__PURE__ */ jsx(
1331
+ "div",
1332
+ {
1333
+ ref: nativeWrapperRef,
1334
+ className: clsx("im-slideover-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
1335
+ children: renderContent()
1336
+ }
1337
+ )
1338
+ }
1339
+ ) })
1340
+ }
1341
+ );
1342
+ }
1343
+ if (!isRendered) return null;
1344
+ return /* @__PURE__ */ jsx(
1345
+ "div",
1346
+ {
1347
+ className: "im-slideover-container fixed inset-0 z-40 overflow-y-auto overflow-x-hidden",
1348
+ onMouseDown: handleClickOutside,
1349
+ children: /* @__PURE__ */ jsx(
1350
+ "div",
2052
1351
  {
2053
- as: "div",
2054
- enterFrom: `opacity-0 ${t.position === "left" ? "-translate-x-full" : "translate-x-full"}`,
2055
- enterTo: "opacity-100 translate-x-0",
2056
- leaveFrom: "opacity-100 translate-x-0",
2057
- leaveTo: `opacity-0 ${t.position === "left" ? "-translate-x-full" : "translate-x-full"}`,
2058
- afterEnter: () => l(!0),
2059
- afterLeave: e.afterLeave,
2060
- className: Ke("im-slideover-wrapper w-full transition duration-300 ease-in-out", e.onTopOfStack ? "" : "blur-sm", {
2061
- "sm:max-w-sm": t.maxWidth === "sm",
2062
- "sm:max-w-md": t.maxWidth === "md",
2063
- "sm:max-w-md md:max-w-lg": t.maxWidth === "lg",
2064
- "sm:max-w-md md:max-w-xl": t.maxWidth === "xl",
2065
- "sm:max-w-md md:max-w-xl lg:max-w-2xl": t.maxWidth === "2xl",
2066
- "sm:max-w-md md:max-w-xl lg:max-w-3xl": t.maxWidth === "3xl",
2067
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-4xl": t.maxWidth === "4xl",
2068
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl": t.maxWidth === "5xl",
2069
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-6xl": t.maxWidth === "6xl",
2070
- "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-7xl": t.maxWidth === "7xl"
1352
+ className: clsx("im-slideover-positioner flex min-h-full items-center", {
1353
+ "justify-start rtl:justify-end": config?.position === "left",
1354
+ "justify-end rtl:justify-start": config?.position === "right"
2071
1355
  }),
2072
- children: /* @__PURE__ */ he(
2073
- Rt,
1356
+ onMouseDown: handleClickOutside,
1357
+ children: /* @__PURE__ */ jsxs(
1358
+ "div",
2074
1359
  {
2075
- className: `im-slideover-content relative ${t.paddingClasses} ${t.panelClasses}`,
2076
- "data-inertiaui-modal-entered": n,
1360
+ ref: wrapperRef,
1361
+ role: "dialog",
1362
+ "aria-modal": "true",
1363
+ className: clsx("im-slideover-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
2077
1364
  children: [
2078
- t.closeButton && /* @__PURE__ */ P("div", { className: "absolute right-0 top-0 pr-3 pt-3", children: /* @__PURE__ */ P(jr, { onClick: e.close }) }),
2079
- typeof r == "function" ? r({ modalContext: e, config: t }) : r
1365
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Dialog" }),
1366
+ renderContent()
2080
1367
  ]
2081
1368
  }
2082
1369
  )
2083
1370
  }
2084
1371
  )
2085
1372
  }
2086
- ) });
2087
- }, gi = Pt(({ name: e, children: t, onFocus: r = null, onBlur: n = null, onClose: l = null, onSuccess: i = null, onAfterLeave: a = null, ...s }, o) => {
2088
- const u = (b) => typeof t == "function" ? t(b) : t, m = S(null);
2089
- return tr(o, () => m.current, [m]), /* @__PURE__ */ P(
2090
- ar,
1373
+ );
1374
+ };
1375
+ const Modal = forwardRef(
1376
+ (allProps, ref) => {
1377
+ const { name, children, onFocus, onBlur, onClose, onSuccess, onAfterLeave, ...props } = allProps;
1378
+ const renderChildren = (contentProps) => {
1379
+ if (typeof children === "function") {
1380
+ return children(contentProps);
1381
+ }
1382
+ return children;
1383
+ };
1384
+ const headlessModalRef = useRef(null);
1385
+ const cleanupScrollLockRef = useRef(null);
1386
+ const cleanupAriaHiddenRef = useRef(null);
1387
+ const [rendered, setRendered] = useState(false);
1388
+ const useNativeDialog = useMemo(() => getConfig("useNativeDialog"), []);
1389
+ useImperativeHandle(ref, () => headlessModalRef.current, [headlessModalRef]);
1390
+ useEffect(() => {
1391
+ return () => {
1392
+ cleanupScrollLockRef.current?.();
1393
+ cleanupAriaHiddenRef.current?.();
1394
+ };
1395
+ }, []);
1396
+ const handleSuccess = useCallback(() => {
1397
+ onSuccess?.();
1398
+ if (!cleanupScrollLockRef.current) {
1399
+ cleanupScrollLockRef.current = lockScroll();
1400
+ cleanupAriaHiddenRef.current = markAriaHidden(getConfig("appElement"));
1401
+ }
1402
+ }, [onSuccess]);
1403
+ const handleClose = useCallback(() => {
1404
+ onClose?.();
1405
+ cleanupScrollLockRef.current?.();
1406
+ cleanupAriaHiddenRef.current?.();
1407
+ cleanupScrollLockRef.current = null;
1408
+ cleanupAriaHiddenRef.current = null;
1409
+ }, [onClose]);
1410
+ const handleAfterLeave = useCallback(() => {
1411
+ onAfterLeave?.();
1412
+ }, [onAfterLeave]);
1413
+ return /* @__PURE__ */ jsx(
1414
+ HeadlessModal,
1415
+ {
1416
+ ref: headlessModalRef,
1417
+ name,
1418
+ onFocus: onFocus ?? void 0,
1419
+ onBlur: onBlur ?? void 0,
1420
+ onClose: handleClose,
1421
+ onSuccess: handleSuccess,
1422
+ ...props,
1423
+ children: ({
1424
+ afterLeave,
1425
+ close,
1426
+ config,
1427
+ emit,
1428
+ getChildModal,
1429
+ getParentModal,
1430
+ id,
1431
+ index,
1432
+ isOpen,
1433
+ modalContext,
1434
+ onTopOfStack,
1435
+ reload,
1436
+ setOpen,
1437
+ shouldRender,
1438
+ ...extraProps
1439
+ }) => /* @__PURE__ */ jsx(ModalPortal, { children: /* @__PURE__ */ jsxs(
1440
+ "div",
1441
+ {
1442
+ className: "im-dialog relative z-20",
1443
+ "data-inertiaui-modal-id": id,
1444
+ "data-inertiaui-modal-index": index,
1445
+ "aria-hidden": !onTopOfStack,
1446
+ children: [
1447
+ index === 0 && !useNativeDialog && /* @__PURE__ */ jsx(
1448
+ BackdropTransition,
1449
+ {
1450
+ show: isOpen,
1451
+ appear: !rendered,
1452
+ onAfterAppear: () => setRendered(true)
1453
+ }
1454
+ ),
1455
+ config.slideover ? /* @__PURE__ */ jsx(
1456
+ SlideoverContent,
1457
+ {
1458
+ modalContext,
1459
+ config,
1460
+ useNativeDialog,
1461
+ isFirstModal: index === 0,
1462
+ onAfterLeave: handleAfterLeave,
1463
+ children: renderChildren({
1464
+ ...extraProps,
1465
+ afterLeave,
1466
+ close,
1467
+ config,
1468
+ emit,
1469
+ getChildModal,
1470
+ getParentModal,
1471
+ id,
1472
+ index,
1473
+ isOpen,
1474
+ modalContext,
1475
+ onTopOfStack,
1476
+ reload,
1477
+ setOpen,
1478
+ shouldRender
1479
+ })
1480
+ }
1481
+ ) : /* @__PURE__ */ jsx(
1482
+ ModalContent,
1483
+ {
1484
+ modalContext,
1485
+ config,
1486
+ useNativeDialog,
1487
+ isFirstModal: index === 0,
1488
+ onAfterLeave: handleAfterLeave,
1489
+ children: renderChildren({
1490
+ ...extraProps,
1491
+ afterLeave,
1492
+ close,
1493
+ config,
1494
+ emit,
1495
+ getChildModal,
1496
+ getParentModal,
1497
+ id,
1498
+ index,
1499
+ isOpen,
1500
+ modalContext,
1501
+ onTopOfStack,
1502
+ reload,
1503
+ setOpen,
1504
+ shouldRender
1505
+ })
1506
+ }
1507
+ )
1508
+ ]
1509
+ }
1510
+ ) })
1511
+ }
1512
+ );
1513
+ }
1514
+ );
1515
+ function ModalPortal({ children }) {
1516
+ const [mounted, setMounted] = useState(false);
1517
+ useEffect(() => {
1518
+ setMounted(true);
1519
+ }, []);
1520
+ if (!mounted) return null;
1521
+ return createPortal(children, document.body);
1522
+ }
1523
+ function BackdropTransition({ show, appear, onAfterAppear }) {
1524
+ const [state, setState] = useState(() => {
1525
+ if (appear && show) return "entering";
1526
+ return show ? "entered" : "exited";
1527
+ });
1528
+ const initialRender = useRef(true);
1529
+ const backdropRef = useRef(null);
1530
+ useEffect(() => {
1531
+ if (initialRender.current) {
1532
+ initialRender.current = false;
1533
+ if (appear && show) {
1534
+ requestAnimationFrame(() => {
1535
+ setState("entered");
1536
+ const backdrop = backdropRef.current;
1537
+ if (backdrop) {
1538
+ const onTransitionEnd = (e) => {
1539
+ if (e.target !== backdrop) return;
1540
+ backdrop.removeEventListener("transitionend", onTransitionEnd);
1541
+ onAfterAppear?.();
1542
+ };
1543
+ backdrop.addEventListener("transitionend", onTransitionEnd);
1544
+ }
1545
+ });
1546
+ }
1547
+ return;
1548
+ }
1549
+ if (show) {
1550
+ setState("entering");
1551
+ requestAnimationFrame(() => {
1552
+ setState("entered");
1553
+ });
1554
+ } else {
1555
+ setState("leaving");
1556
+ const backdrop = backdropRef.current;
1557
+ if (backdrop) {
1558
+ const onTransitionEnd = (e) => {
1559
+ if (e.target !== backdrop) return;
1560
+ backdrop.removeEventListener("transitionend", onTransitionEnd);
1561
+ setState("exited");
1562
+ };
1563
+ backdrop.addEventListener("transitionend", onTransitionEnd);
1564
+ }
1565
+ }
1566
+ }, [show, appear, onAfterAppear]);
1567
+ if (state === "exited") return null;
1568
+ const isVisible = state === "entered";
1569
+ return /* @__PURE__ */ jsx(
1570
+ "div",
2091
1571
  {
2092
- ref: m,
2093
- name: e,
2094
- onFocus: r,
2095
- onBlur: n,
2096
- onClose: l,
2097
- onSuccess: i,
2098
- ...s,
2099
- children: ({
2100
- afterLeave: b,
2101
- close: g,
2102
- config: y,
2103
- emit: f,
2104
- getChildModal: E,
2105
- getParentModal: h,
2106
- id: c,
2107
- index: d,
2108
- isOpen: v,
2109
- modalContext: w,
2110
- onTopOfStack: p,
2111
- reload: x,
2112
- setOpen: O,
2113
- shouldRender: N
2114
- }) => /* @__PURE__ */ P(
2115
- Dr,
2116
- {
2117
- appear: !0,
2118
- show: v ?? !1,
2119
- afterLeave: a,
2120
- children: /* @__PURE__ */ he(
2121
- mi,
2122
- {
2123
- as: "div",
2124
- className: "im-dialog relative z-20",
2125
- onClose: () => y.closeExplicitly ? null : g(),
2126
- "data-inertiaui-modal-id": c,
2127
- "data-inertiaui-modal-index": d,
2128
- children: [
2129
- d === 0 ? /* @__PURE__ */ P(
2130
- Ee,
2131
- {
2132
- enter: "transition transform ease-in-out duration-300",
2133
- enterFrom: "opacity-0",
2134
- enterTo: "opacity-100",
2135
- leave: "transition transform ease-in-out duration-300",
2136
- leaveFrom: "opacity-100",
2137
- leaveTo: "opacity-0",
2138
- children: p ? /* @__PURE__ */ P(
2139
- "div",
2140
- {
2141
- className: "im-backdrop fixed inset-0 z-30 bg-black/75",
2142
- "aria-hidden": "true"
2143
- }
2144
- ) : /* @__PURE__ */ P("div", {})
2145
- }
2146
- ) : null,
2147
- d > 0 && p ? /* @__PURE__ */ P("div", { className: "im-backdrop fixed inset-0 z-30 bg-black/75" }) : null,
2148
- y.slideover ? /* @__PURE__ */ P(
2149
- vi,
2150
- {
2151
- modalContext: w,
2152
- config: y,
2153
- children: u({
2154
- afterLeave: b,
2155
- close: g,
2156
- config: y,
2157
- emit: f,
2158
- getChildModal: E,
2159
- getParentModal: h,
2160
- id: c,
2161
- index: d,
2162
- isOpen: v,
2163
- modalContext: w,
2164
- onTopOfStack: p,
2165
- reload: x,
2166
- setOpen: O,
2167
- shouldRender: N
2168
- })
2169
- }
2170
- ) : /* @__PURE__ */ P(
2171
- hi,
2172
- {
2173
- modalContext: w,
2174
- config: y,
2175
- children: u({
2176
- afterLeave: b,
2177
- close: g,
2178
- config: y,
2179
- emit: f,
2180
- getChildModal: E,
2181
- getParentModal: h,
2182
- id: c,
2183
- index: d,
2184
- isOpen: v,
2185
- modalContext: w,
2186
- onTopOfStack: p,
2187
- reload: x,
2188
- setOpen: O,
2189
- shouldRender: N
2190
- })
2191
- }
2192
- )
2193
- ]
2194
- }
2195
- )
2196
- }
2197
- )
1572
+ ref: backdropRef,
1573
+ className: `im-backdrop fixed inset-0 z-30 bg-black/75 transition-opacity duration-300 ease-in-out ${isVisible ? "opacity-100" : "opacity-0"}`,
1574
+ "aria-hidden": "true"
2198
1575
  }
2199
1576
  );
2200
- });
2201
- gi.displayName = "Modal";
2202
- const Ci = ({
2203
- href: e,
2204
- method: t = "get",
2205
- data: r = {},
2206
- as: n = "a",
2207
- headers: l = {},
2208
- queryStringArrayFormat: i = "brackets",
2209
- onAfterLeave: a = null,
2210
- onBlur: s = null,
2211
- onClose: o = null,
2212
- onError: u = null,
2213
- onFocus: m = null,
2214
- onStart: b = null,
2215
- onSuccess: g = null,
2216
- navigate: y = null,
2217
- children: f,
2218
- ...E
1577
+ }
1578
+ Modal.displayName = "Modal";
1579
+ const ModalLink = ({
1580
+ href,
1581
+ method = "get",
1582
+ data = {},
1583
+ as: Component = "a",
1584
+ headers = {},
1585
+ queryStringArrayFormat = "brackets",
1586
+ onAfterLeave,
1587
+ onBlur,
1588
+ onClose,
1589
+ onError,
1590
+ onFocus,
1591
+ onStart,
1592
+ onSuccess,
1593
+ onPrefetching,
1594
+ onPrefetched,
1595
+ navigate,
1596
+ prefetch: prefetch$1 = false,
1597
+ cacheFor = 3e4,
1598
+ children,
1599
+ ...props
2219
1600
  }) => {
2220
- const [h, c] = F(!1), [d, v] = F(null), { stack: w, visit: p } = et(), x = _(() => y ?? Lt("navigate"), [y]), O = {}, N = {};
2221
- Object.keys(E).forEach((k) => {
2222
- Dt.includes(k) || (k.startsWith("on") && typeof E[k] == "function" ? nn(k) ? O[k] = E[k] : N[k] = E[k] : O[k] = E[k]);
1601
+ const [loading, setLoading] = useState(false);
1602
+ const [modalContext, setModalContext] = useState(null);
1603
+ const { stack, visit } = useModalStack();
1604
+ const hoverTimeout = useRef(null);
1605
+ const shouldNavigate = useMemo(() => {
1606
+ return navigate ?? getConfig("navigate");
1607
+ }, [navigate]);
1608
+ const prefetchModes = useMemo(() => {
1609
+ if (prefetch$1 === true) {
1610
+ return ["hover"];
1611
+ }
1612
+ if (prefetch$1 === false) {
1613
+ return [];
1614
+ }
1615
+ if (Array.isArray(prefetch$1)) {
1616
+ return prefetch$1;
1617
+ }
1618
+ return [prefetch$1];
1619
+ }, [prefetch$1]);
1620
+ const doPrefetch = useCallback(() => {
1621
+ prefetch(href, {
1622
+ method,
1623
+ data,
1624
+ headers,
1625
+ queryStringArrayFormat,
1626
+ cacheFor,
1627
+ onPrefetching: onPrefetching ?? void 0,
1628
+ onPrefetched: onPrefetched ?? void 0
1629
+ });
1630
+ }, [href, method, data, headers, queryStringArrayFormat, cacheFor, onPrefetching, onPrefetched]);
1631
+ const handleMouseEnter = useCallback(() => {
1632
+ if (!prefetchModes.includes("hover")) return;
1633
+ hoverTimeout.current = setTimeout(() => {
1634
+ doPrefetch();
1635
+ }, 75);
1636
+ }, [prefetchModes, doPrefetch]);
1637
+ const handleMouseLeave = useCallback(() => {
1638
+ if (hoverTimeout.current) {
1639
+ clearTimeout(hoverTimeout.current);
1640
+ hoverTimeout.current = null;
1641
+ }
1642
+ }, []);
1643
+ const handleMouseDown = useCallback(
1644
+ (event) => {
1645
+ if (!prefetchModes.includes("click")) return;
1646
+ if (event.button !== 0) return;
1647
+ doPrefetch();
1648
+ },
1649
+ [prefetchModes, doPrefetch]
1650
+ );
1651
+ useEffect(() => {
1652
+ if (prefetchModes.includes("mount")) {
1653
+ doPrefetch();
1654
+ }
1655
+ }, []);
1656
+ useEffect(() => {
1657
+ return () => {
1658
+ if (hoverTimeout.current) {
1659
+ clearTimeout(hoverTimeout.current);
1660
+ }
1661
+ };
1662
+ }, []);
1663
+ const standardProps = {};
1664
+ const customEvents = {};
1665
+ Object.keys(props).forEach((key) => {
1666
+ if (modalPropNames.includes(key)) {
1667
+ return;
1668
+ }
1669
+ if (key.startsWith("on") && typeof props[key] === "function") {
1670
+ if (isStandardDomEvent(key)) {
1671
+ standardProps[key] = props[key];
1672
+ } else {
1673
+ customEvents[key] = props[key];
1674
+ }
1675
+ } else {
1676
+ standardProps[key] = props[key];
1677
+ }
2223
1678
  });
2224
- const [D, C] = F(!1);
2225
- L(() => {
2226
- d && (d.onTopOfStack && D ? m == null || m() : !d.onTopOfStack && !D && (s == null || s()), C(!d.onTopOfStack));
2227
- }, [w]);
2228
- const I = W(() => {
2229
- o == null || o();
2230
- }, [o]), B = W(() => {
2231
- v(null), a == null || a();
2232
- }, [a]), R = W(
2233
- (k) => {
2234
- k == null || k.preventDefault(), !h && (e.startsWith("#") || (c(!0), b == null || b()), p(
2235
- e,
2236
- t,
2237
- r,
2238
- l,
2239
- rn(tn(E, Dt)),
2240
- () => I(w.length),
2241
- B,
2242
- i,
2243
- x
2244
- ).then((j) => {
2245
- v(j), j.registerEventListenersFromProps(N), g == null || g();
2246
- }).catch((j) => {
2247
- console.error(j), u == null || u(j);
2248
- }).finally(() => c(!1)));
1679
+ const [isBlurred, setIsBlurred] = useState(false);
1680
+ useEffect(() => {
1681
+ if (!modalContext) {
1682
+ return;
1683
+ }
1684
+ if (modalContext.onTopOfStack && isBlurred) {
1685
+ onFocus?.();
1686
+ } else if (!modalContext.onTopOfStack && !isBlurred) {
1687
+ onBlur?.();
1688
+ }
1689
+ setIsBlurred(!modalContext.onTopOfStack);
1690
+ }, [stack]);
1691
+ const onCloseCallback = useCallback(() => {
1692
+ onClose?.();
1693
+ }, [onClose]);
1694
+ const onAfterLeaveCallback = useCallback(() => {
1695
+ setModalContext(null);
1696
+ onAfterLeave?.();
1697
+ }, [onAfterLeave]);
1698
+ const handle = useCallback(
1699
+ (e) => {
1700
+ e?.preventDefault();
1701
+ if (loading) return;
1702
+ if (!href.startsWith("#")) {
1703
+ setLoading(true);
1704
+ onStart?.();
1705
+ }
1706
+ visit(
1707
+ href,
1708
+ method,
1709
+ data,
1710
+ headers,
1711
+ rejectNullValues(only(props, modalPropNames)),
1712
+ () => onCloseCallback(),
1713
+ onAfterLeaveCallback,
1714
+ queryStringArrayFormat,
1715
+ shouldNavigate
1716
+ ).then((newModalContext) => {
1717
+ setModalContext(newModalContext);
1718
+ newModalContext.registerEventListenersFromProps(customEvents);
1719
+ onSuccess?.();
1720
+ }).catch((error) => {
1721
+ console.error(error);
1722
+ onError?.(error);
1723
+ }).finally(() => setLoading(false));
2249
1724
  },
2250
- [e, t, r, l, i, E, I, B]
1725
+ [href, method, data, headers, queryStringArrayFormat, props, onCloseCallback, onAfterLeaveCallback]
2251
1726
  );
2252
- return /* @__PURE__ */ P(
2253
- n,
1727
+ return /* @__PURE__ */ jsx(
1728
+ Component,
2254
1729
  {
2255
- ...O,
2256
- href: e,
2257
- onClick: R,
2258
- children: typeof f == "function" ? f({ loading: h }) : f
1730
+ ...standardProps,
1731
+ href,
1732
+ onClick: handle,
1733
+ onMouseEnter: handleMouseEnter,
1734
+ onMouseLeave: handleMouseLeave,
1735
+ onMouseDown: handleMouseDown,
1736
+ children: typeof children === "function" ? children({ loading }) : children
2259
1737
  }
2260
1738
  );
2261
- }, wi = ({ children: e, data: t, params: r, buffer: n, as: l, always: i, fallback: a }) => {
2262
- i = i ?? !1, l = l ?? "div", a = a ?? null;
2263
- const [s, o] = F(!1), u = S(!1), m = S(!1), b = S(null), g = or(), y = W(() => {
2264
- if (t)
1739
+ };
1740
+ const WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
1741
+ always = always ?? false;
1742
+ as = as ?? "div";
1743
+ fallback = fallback ?? null;
1744
+ const [loaded, setLoaded] = useState(false);
1745
+ const hasFetched = useRef(false);
1746
+ const fetching = useRef(false);
1747
+ const ref = useRef(null);
1748
+ const modal = useModal();
1749
+ const getReloadParams = useCallback(() => {
1750
+ if (data) {
2265
1751
  return {
2266
- only: Array.isArray(t) ? t : [t]
1752
+ only: Array.isArray(data) ? data : [data]
2267
1753
  };
2268
- if (!r)
1754
+ }
1755
+ if (!params) {
2269
1756
  throw new Error("You must provide either a `data` or `params` prop.");
2270
- return r;
2271
- }, [r, t]);
2272
- return L(() => {
2273
- if (!b.current)
1757
+ }
1758
+ return params;
1759
+ }, [params, data]);
1760
+ useEffect(() => {
1761
+ if (!ref.current) {
2274
1762
  return;
2275
- const f = new IntersectionObserver(
2276
- (E) => {
2277
- if (!E[0].isIntersecting || (!i && u.current && f.disconnect(), m.current))
1763
+ }
1764
+ const observer = new IntersectionObserver(
1765
+ (entries) => {
1766
+ if (!entries[0].isIntersecting) {
2278
1767
  return;
2279
- u.current = !0, m.current = !0;
2280
- const h = y();
2281
- g.reload({
2282
- ...h,
2283
- onStart: (c) => {
2284
- var d;
2285
- m.current = !0, (d = h.onStart) == null || d.call(h, c);
1768
+ }
1769
+ if (!always && hasFetched.current) {
1770
+ observer.disconnect();
1771
+ }
1772
+ if (fetching.current) {
1773
+ return;
1774
+ }
1775
+ hasFetched.current = true;
1776
+ fetching.current = true;
1777
+ const reloadParams = getReloadParams();
1778
+ modal?.reload({
1779
+ ...reloadParams,
1780
+ onStart: () => {
1781
+ fetching.current = true;
1782
+ reloadParams.onStart?.();
2286
1783
  },
2287
- onFinish: (c) => {
2288
- var d;
2289
- o(!0), m.current = !1, (d = h.onFinish) == null || d.call(h, c), i || f.disconnect();
1784
+ onFinish: () => {
1785
+ setLoaded(true);
1786
+ fetching.current = false;
1787
+ reloadParams.onFinish?.();
1788
+ if (!always) {
1789
+ observer.disconnect();
1790
+ }
2290
1791
  }
2291
1792
  });
2292
1793
  },
2293
1794
  {
2294
- rootMargin: `${n || 0}px`
1795
+ rootMargin: `${buffer || 0}px`
2295
1796
  }
2296
1797
  );
2297
- return f.observe(b.current), () => {
2298
- f.disconnect();
1798
+ observer.observe(ref.current);
1799
+ return () => {
1800
+ observer.disconnect();
2299
1801
  };
2300
- }, [b, y, n]), i || !s ? Re(
2301
- l,
2302
- {
2303
- props: null,
2304
- ref: b
2305
- },
2306
- s ? e : a
2307
- ) : s ? e : null;
1802
+ }, [ref, getReloadParams, buffer]);
1803
+ if (always || !loaded) {
1804
+ return createElement(
1805
+ as,
1806
+ {
1807
+ props: null,
1808
+ ref
1809
+ },
1810
+ loaded ? children : fallback
1811
+ );
1812
+ }
1813
+ return loaded ? children : null;
1814
+ };
1815
+ WhenVisible.displayName = "InertiaWhenVisible";
1816
+ const setPageLayout = (layout) => (module) => {
1817
+ module.default.layout = (page) => createElement(layout, { children: page });
1818
+ return module;
2308
1819
  };
2309
- wi.displayName = "InertiaWhenVisible";
2310
- const Fi = (e) => (t) => (t.default.layout = (r) => Re(e, {}, r), t);
2311
1820
  export {
2312
- sn as Deferred,
2313
- ar as HeadlessModal,
2314
- gi as Modal,
2315
- Ci as ModalLink,
2316
- an as ModalRoot,
2317
- ln as ModalStackProvider,
2318
- wi as WhenVisible,
2319
- Lt as getConfig,
2320
- on as initFromPageProps,
2321
- Pi as putConfig,
2322
- Mi as renderApp,
2323
- Ti as resetConfig,
2324
- Fi as setPageLayout,
2325
- or as useModal,
2326
- lr as useModalIndex,
2327
- et as useModalStack
1821
+ Deferred,
1822
+ HeadlessModal,
1823
+ Modal,
1824
+ ModalLink,
1825
+ ModalRoot,
1826
+ ModalStackProvider,
1827
+ WhenVisible,
1828
+ vanilla as dialogUtils,
1829
+ getConfig,
1830
+ initFromPageProps,
1831
+ modalPropNames,
1832
+ prefetch,
1833
+ putConfig,
1834
+ renderApp,
1835
+ resetConfig,
1836
+ setPageLayout,
1837
+ useModal,
1838
+ useModalIndex,
1839
+ useModalStack
2328
1840
  };
1841
+ //# sourceMappingURL=inertiaui-modal.js.map