@inertiaui/modal-react 1.0.0-beta-4 → 2.0.0-beta.1

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