@inertiaui/modal-react 3.0.1 → 3.1.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.
- package/LICENSE.md +21 -0
- package/dist/ModalLink.d.ts +1 -1
- package/dist/inertiaui-modal.js +1602 -1818
- package/dist/inertiaui-modal.js.map +1 -1
- package/dist/inertiaui-modal.umd.cjs +1694 -1871
- package/dist/inertiaui-modal.umd.cjs.map +1 -1
- package/dist/inertiauiModal.d.ts +3 -3
- package/dist/types.d.ts +1 -1
- package/package.json +39 -65
- package/src/CloseButton.tsx +3 -19
- package/src/Deferred.tsx +1 -0
- package/src/HeadlessModal.tsx +151 -155
- package/src/Modal.tsx +132 -144
- package/src/ModalContent.tsx +13 -14
- package/src/ModalLink.tsx +4 -3
- package/src/ModalRenderer.tsx +1 -0
- package/src/ModalRoot.tsx +25 -31
- package/src/SlideoverContent.tsx +14 -15
- package/src/WhenVisible.tsx +2 -1
- package/src/cache.ts +4 -1
- package/src/config.ts +3 -4
- package/src/inertiauiModal.ts +11 -10
- package/src/types.ts +1 -1
package/dist/inertiaui-modal.js
CHANGED
|
@@ -1,1858 +1,1642 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import * as vanilla from "@inertiaui/vanilla";
|
|
5
|
-
import { usePage, http, router, progress } from "@inertiajs/react";
|
|
1
|
+
import * as dialogUtils from "@inertiaui/vanilla";
|
|
2
|
+
import { animate, cancelAnimations, createFocusTrap, except, generateId, isStandardDomEvent, kebabCase, lockScroll, markAriaHidden, onEscapeKey, only, rejectNullValues, sameUrlPath } from "@inertiaui/vanilla";
|
|
3
|
+
import React, { createContext, createElement, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
6
4
|
import { mergeDataIntoQueryString } from "@inertiajs/core";
|
|
5
|
+
import { http, progress, router, usePage } from "@inertiajs/react";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { createPortal } from "react-dom";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
//#region src/config.ts
|
|
9
|
+
var defaultConfig = {
|
|
10
|
+
type: "modal",
|
|
11
|
+
navigate: false,
|
|
12
|
+
useNativeDialog: true,
|
|
13
|
+
appElement: "#app",
|
|
14
|
+
modal: {
|
|
15
|
+
closeButton: true,
|
|
16
|
+
closeExplicitly: false,
|
|
17
|
+
closeOnClickOutside: true,
|
|
18
|
+
maxWidth: "2xl",
|
|
19
|
+
paddingClasses: "p-4 sm:p-6",
|
|
20
|
+
panelClasses: "bg-white rounded",
|
|
21
|
+
position: "center"
|
|
22
|
+
},
|
|
23
|
+
slideover: {
|
|
24
|
+
closeButton: true,
|
|
25
|
+
closeExplicitly: false,
|
|
26
|
+
closeOnClickOutside: true,
|
|
27
|
+
maxWidth: "md",
|
|
28
|
+
paddingClasses: "p-4 sm:p-6",
|
|
29
|
+
panelClasses: "bg-white min-h-screen",
|
|
30
|
+
position: "right"
|
|
31
|
+
}
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
33
|
+
var Config = class {
|
|
34
|
+
constructor() {
|
|
35
|
+
this.config = {};
|
|
36
|
+
this.reset();
|
|
37
|
+
}
|
|
38
|
+
reset() {
|
|
39
|
+
this.config = JSON.parse(JSON.stringify(defaultConfig));
|
|
40
|
+
}
|
|
41
|
+
put(key, value) {
|
|
42
|
+
if (typeof key === "object") {
|
|
43
|
+
this.config = {
|
|
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: {
|
|
49
|
+
...defaultConfig.modal,
|
|
50
|
+
...key.modal
|
|
51
|
+
},
|
|
52
|
+
slideover: {
|
|
53
|
+
...defaultConfig.slideover,
|
|
54
|
+
...key.slideover
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const keys = key.split(".");
|
|
60
|
+
let current = this.config;
|
|
61
|
+
for (let i = 0; i < keys.length - 1; i++) current = current[keys[i]] = current[keys[i]] || {};
|
|
62
|
+
current[keys[keys.length - 1]] = value;
|
|
63
|
+
}
|
|
64
|
+
get(key) {
|
|
65
|
+
if (typeof key === "undefined") return this.config;
|
|
66
|
+
const keys = key.split(".");
|
|
67
|
+
let current = this.config;
|
|
68
|
+
for (const k of keys) {
|
|
69
|
+
if (current === null || current === void 0 || typeof current !== "object") return null;
|
|
70
|
+
current = current[k];
|
|
71
|
+
}
|
|
72
|
+
return current === void 0 ? null : current;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var configInstance = new Config();
|
|
76
|
+
var resetConfig = () => configInstance.reset();
|
|
77
|
+
var putConfig = (key, value) => configInstance.put(key, value);
|
|
78
|
+
var getConfig = (key) => configInstance.get(key);
|
|
79
|
+
var getConfigByType = (isSlideover, key) => configInstance.get(isSlideover ? `slideover.${key}` : `modal.${key}`);
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/cache.ts
|
|
82
|
+
var ResponseCache = class {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
85
|
+
this.timers = /* @__PURE__ */ new Map();
|
|
86
|
+
this.inFlight = /* @__PURE__ */ new Map();
|
|
87
|
+
}
|
|
88
|
+
static key(method, url, data) {
|
|
89
|
+
return `${method}:${url}:${JSON.stringify(data)}`;
|
|
90
|
+
}
|
|
91
|
+
get(key) {
|
|
92
|
+
const cached = this.cache.get(key);
|
|
93
|
+
if (!cached) return null;
|
|
94
|
+
if (Date.now() > cached.expiresAt) {
|
|
95
|
+
this.delete(key);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return cached.response;
|
|
99
|
+
}
|
|
100
|
+
set(key, response, cacheFor) {
|
|
101
|
+
this.delete(key);
|
|
102
|
+
this.cache.set(key, {
|
|
103
|
+
response,
|
|
104
|
+
expiresAt: Date.now() + cacheFor
|
|
105
|
+
});
|
|
106
|
+
if (cacheFor > 0) this.timers.set(key, setTimeout(() => this.delete(key), cacheFor));
|
|
107
|
+
}
|
|
108
|
+
delete(key) {
|
|
109
|
+
this.cache.delete(key);
|
|
110
|
+
const timer = this.timers.get(key);
|
|
111
|
+
if (timer) {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
this.timers.delete(key);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
getInFlight(key) {
|
|
117
|
+
return this.inFlight.get(key);
|
|
118
|
+
}
|
|
119
|
+
setInFlight(key, promise) {
|
|
120
|
+
this.inFlight.set(key, promise);
|
|
121
|
+
}
|
|
122
|
+
deleteInFlight(key) {
|
|
123
|
+
this.inFlight.delete(key);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/helpers.ts
|
|
79
128
|
function parseResponseData(data) {
|
|
80
|
-
|
|
129
|
+
return typeof data === "string" ? JSON.parse(data) : data;
|
|
81
130
|
}
|
|
82
|
-
|
|
83
|
-
|
|
131
|
+
var generateIdUsingCallback = null;
|
|
132
|
+
function generateId$1(prefix = "inertiaui_") {
|
|
133
|
+
if (generateIdUsingCallback) return generateIdUsingCallback();
|
|
134
|
+
return generateId(prefix);
|
|
84
135
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.timers = /* @__PURE__ */ new Map();
|
|
89
|
-
this.inFlight = /* @__PURE__ */ new Map();
|
|
90
|
-
}
|
|
91
|
-
static key(method, url, data) {
|
|
92
|
-
return `${method}:${url}:${JSON.stringify(data)}`;
|
|
93
|
-
}
|
|
94
|
-
get(key) {
|
|
95
|
-
const cached = this.cache.get(key);
|
|
96
|
-
if (!cached) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
if (Date.now() > cached.expiresAt) {
|
|
100
|
-
this.delete(key);
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
return cached.response;
|
|
104
|
-
}
|
|
105
|
-
set(key, response, cacheFor) {
|
|
106
|
-
this.delete(key);
|
|
107
|
-
this.cache.set(key, {
|
|
108
|
-
response,
|
|
109
|
-
expiresAt: Date.now() + cacheFor
|
|
110
|
-
});
|
|
111
|
-
if (cacheFor > 0) {
|
|
112
|
-
this.timers.set(key, setTimeout(() => this.delete(key), cacheFor));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
delete(key) {
|
|
116
|
-
this.cache.delete(key);
|
|
117
|
-
const timer = this.timers.get(key);
|
|
118
|
-
if (timer) {
|
|
119
|
-
clearTimeout(timer);
|
|
120
|
-
this.timers.delete(key);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
getInFlight(key) {
|
|
124
|
-
return this.inFlight.get(key);
|
|
125
|
-
}
|
|
126
|
-
setInFlight(key, promise) {
|
|
127
|
-
this.inFlight.set(key, promise);
|
|
128
|
-
}
|
|
129
|
-
deleteInFlight(key) {
|
|
130
|
-
this.inFlight.delete(key);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const ModalStackContext = createContext(null);
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/ModalRoot.tsx
|
|
138
|
+
var ModalStackContext = createContext(null);
|
|
134
139
|
ModalStackContext.displayName = "ModalStackContext";
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
var baseUrl = null;
|
|
141
|
+
var currentPageVersion = null;
|
|
142
|
+
var closingToBaseUrlTarget = null;
|
|
143
|
+
var prefetchCache = new ResponseCache();
|
|
139
144
|
function prefetch(href, options = {}) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
options.onPrefetched?.();
|
|
176
|
-
return response;
|
|
177
|
-
}).finally(() => {
|
|
178
|
-
prefetchCache.deleteInFlight(cacheKey);
|
|
179
|
-
});
|
|
180
|
-
prefetchCache.setInFlight(cacheKey, request);
|
|
181
|
-
return request.then(() => {
|
|
182
|
-
});
|
|
145
|
+
if (href.startsWith("#")) return Promise.resolve();
|
|
146
|
+
const method = options.method ?? "get";
|
|
147
|
+
const data = options.data ?? {};
|
|
148
|
+
const headers = options.headers ?? {};
|
|
149
|
+
const queryStringArrayFormat = options.queryStringArrayFormat ?? "brackets";
|
|
150
|
+
const cacheFor = options.cacheFor ?? 3e4;
|
|
151
|
+
const [url, mergedData] = mergeDataIntoQueryString(method, href || "", data, queryStringArrayFormat);
|
|
152
|
+
const cacheKey = ResponseCache.key(method, url, mergedData);
|
|
153
|
+
if (prefetchCache.get(cacheKey)) return Promise.resolve();
|
|
154
|
+
const inFlight = prefetchCache.getInFlight(cacheKey);
|
|
155
|
+
if (inFlight) return inFlight.then(() => {});
|
|
156
|
+
options.onPrefetching?.();
|
|
157
|
+
const requestHeaders = {
|
|
158
|
+
...headers,
|
|
159
|
+
Accept: "text/html, application/xhtml+xml",
|
|
160
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
161
|
+
"X-Inertia": "true",
|
|
162
|
+
"X-Inertia-Version": currentPageVersion ?? "",
|
|
163
|
+
"X-InertiaUI-Modal": generateId$1(),
|
|
164
|
+
"X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
|
|
165
|
+
};
|
|
166
|
+
const request = http.getClient().request({
|
|
167
|
+
url,
|
|
168
|
+
method,
|
|
169
|
+
data: mergedData,
|
|
170
|
+
headers: requestHeaders
|
|
171
|
+
}).then((response) => {
|
|
172
|
+
prefetchCache.set(cacheKey, response, cacheFor);
|
|
173
|
+
options.onPrefetched?.();
|
|
174
|
+
return response;
|
|
175
|
+
}).finally(() => {
|
|
176
|
+
prefetchCache.deleteInFlight(cacheKey);
|
|
177
|
+
});
|
|
178
|
+
prefetchCache.setInFlight(cacheKey, request);
|
|
179
|
+
return request.then(() => {});
|
|
183
180
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
onSuccess?.(response);
|
|
491
|
-
pushFromResponseData(responseData, config, onClose, onAfterLeave).then((modal) => {
|
|
492
|
-
updateBrowserUrl(responseData.url, useBrowserHistory, responseData);
|
|
493
|
-
resolve(modal);
|
|
494
|
-
}).catch(reject);
|
|
495
|
-
}).catch((...args) => {
|
|
496
|
-
onError?.(...args);
|
|
497
|
-
reject(args[0]);
|
|
498
|
-
}).finally(() => {
|
|
499
|
-
progress?.finish();
|
|
500
|
-
});
|
|
501
|
-
});
|
|
502
|
-
};
|
|
503
|
-
const registerLocalModal = (name, callback) => {
|
|
504
|
-
setLocalModals((prevLocalModals) => ({
|
|
505
|
-
...prevLocalModals,
|
|
506
|
-
[name]: { name, callback }
|
|
507
|
-
}));
|
|
508
|
-
};
|
|
509
|
-
const removeLocalModal = (name) => {
|
|
510
|
-
setLocalModals((prevLocalModals) => {
|
|
511
|
-
const newLocalModals = { ...prevLocalModals };
|
|
512
|
-
delete newLocalModals[name];
|
|
513
|
-
return newLocalModals;
|
|
514
|
-
});
|
|
515
|
-
};
|
|
516
|
-
const value = {
|
|
517
|
-
get stack() {
|
|
518
|
-
return stackRef.current;
|
|
519
|
-
},
|
|
520
|
-
localModals,
|
|
521
|
-
push,
|
|
522
|
-
pushFromResponseData,
|
|
523
|
-
length: () => stackRef.current.length,
|
|
524
|
-
closeAll: (force = false) => {
|
|
525
|
-
if (force) {
|
|
526
|
-
updateStack(() => []);
|
|
527
|
-
} else {
|
|
528
|
-
[...stackRef.current].reverse().forEach((modal) => modal.close());
|
|
529
|
-
}
|
|
530
|
-
},
|
|
531
|
-
reset: () => updateStack(() => []),
|
|
532
|
-
visit,
|
|
533
|
-
visitModal,
|
|
534
|
-
registerLocalModal,
|
|
535
|
-
removeLocalModal
|
|
536
|
-
};
|
|
537
|
-
return /* @__PURE__ */ jsx(ModalStackContext.Provider, { value, children });
|
|
181
|
+
var ModalStackProvider = ({ children }) => {
|
|
182
|
+
const stackRef = useRef([]);
|
|
183
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
184
|
+
const [localModals, setLocalModals] = useState({});
|
|
185
|
+
const updateStack = (withStack) => {
|
|
186
|
+
const newStack = withStack([...stackRef.current]);
|
|
187
|
+
const isOnTopOfStack = (modalId) => {
|
|
188
|
+
if (newStack.length < 2) return true;
|
|
189
|
+
return newStack.map((modal) => ({
|
|
190
|
+
id: modal.id,
|
|
191
|
+
shouldRender: modal.shouldRender
|
|
192
|
+
})).reverse().find((modal) => modal.shouldRender)?.id === modalId;
|
|
193
|
+
};
|
|
194
|
+
newStack.forEach((modal, index) => {
|
|
195
|
+
newStack[index].onTopOfStack = isOnTopOfStack(modal.id);
|
|
196
|
+
newStack[index].getParentModal = () => {
|
|
197
|
+
if (index < 1) return null;
|
|
198
|
+
return stackRef.current.slice(0, index).reverse().find((m) => m.isOpen) ?? null;
|
|
199
|
+
};
|
|
200
|
+
newStack[index].getChildModal = () => {
|
|
201
|
+
if (index === stackRef.current.length - 1) return null;
|
|
202
|
+
return stackRef.current.slice(index + 1).find((m) => m.isOpen) ?? null;
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
stackRef.current = newStack;
|
|
206
|
+
forceUpdate();
|
|
207
|
+
};
|
|
208
|
+
class ModalClass {
|
|
209
|
+
constructor(component, response, config, onClose, afterLeave) {
|
|
210
|
+
this.show = () => {
|
|
211
|
+
updateStack((prevStack) => prevStack.map((modal) => {
|
|
212
|
+
if (modal.id === this.id && !modal.isOpen) {
|
|
213
|
+
modal.isOpen = true;
|
|
214
|
+
modal.shouldRender = true;
|
|
215
|
+
}
|
|
216
|
+
return modal;
|
|
217
|
+
}));
|
|
218
|
+
};
|
|
219
|
+
this.setOpen = (open) => {
|
|
220
|
+
if (open) this.show();
|
|
221
|
+
else this.close();
|
|
222
|
+
};
|
|
223
|
+
this.close = () => {
|
|
224
|
+
updateStack((currentStack) => {
|
|
225
|
+
let modalClosed = false;
|
|
226
|
+
const newStack = currentStack.map((modal) => {
|
|
227
|
+
if (modal.id === this.id && modal.isOpen) {
|
|
228
|
+
Object.keys(modal.listeners).forEach((event) => {
|
|
229
|
+
modal.off(event);
|
|
230
|
+
});
|
|
231
|
+
modal.isOpen = false;
|
|
232
|
+
modal.onCloseCallback?.();
|
|
233
|
+
modalClosed = true;
|
|
234
|
+
}
|
|
235
|
+
return modal;
|
|
236
|
+
});
|
|
237
|
+
return modalClosed ? newStack : currentStack;
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
this.afterLeave = () => {
|
|
241
|
+
if (this.isOpen) return;
|
|
242
|
+
updateStack((prevStack) => {
|
|
243
|
+
const updatedStack = prevStack.map((modal) => {
|
|
244
|
+
if (modal.id === this.id && !modal.isOpen) {
|
|
245
|
+
modal.shouldRender = false;
|
|
246
|
+
modal.afterLeaveCallback?.();
|
|
247
|
+
modal.afterLeaveCallback = null;
|
|
248
|
+
}
|
|
249
|
+
return modal;
|
|
250
|
+
});
|
|
251
|
+
if (this.index === 0) {
|
|
252
|
+
const savedBaseUrl = baseUrl;
|
|
253
|
+
baseUrl = null;
|
|
254
|
+
closingToBaseUrlTarget = savedBaseUrl;
|
|
255
|
+
if (savedBaseUrl && typeof window !== "undefined" && !sameUrlPath(savedBaseUrl, window.location.href)) router.push({
|
|
256
|
+
url: savedBaseUrl,
|
|
257
|
+
preserveScroll: true,
|
|
258
|
+
preserveState: true,
|
|
259
|
+
props: (currentProps) => {
|
|
260
|
+
const { _inertiaui_modal, ...rest } = currentProps;
|
|
261
|
+
return {
|
|
262
|
+
...rest,
|
|
263
|
+
_inertiaui_modal: void 0
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
return updatedStack;
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
this.on = (event, callback) => {
|
|
273
|
+
event = kebabCase(event);
|
|
274
|
+
this.listeners[event] = this.listeners[event] ?? [];
|
|
275
|
+
this.listeners[event].push(callback);
|
|
276
|
+
};
|
|
277
|
+
this.off = (event, callback) => {
|
|
278
|
+
event = kebabCase(event);
|
|
279
|
+
if (callback) this.listeners[event] = this.listeners[event]?.filter((cb) => cb !== callback) ?? [];
|
|
280
|
+
else delete this.listeners[event];
|
|
281
|
+
};
|
|
282
|
+
this.emit = (event, ...args) => {
|
|
283
|
+
this.listeners[kebabCase(event)]?.forEach((callback) => callback(...args));
|
|
284
|
+
};
|
|
285
|
+
this.registerEventListenersFromProps = (props) => {
|
|
286
|
+
const unsubscribers = [];
|
|
287
|
+
Object.keys(props).filter((key) => key.startsWith("on")).forEach((key) => {
|
|
288
|
+
const eventName = kebabCase(key).replace(/^on-/, "");
|
|
289
|
+
const callback = props[key];
|
|
290
|
+
this.on(eventName, callback);
|
|
291
|
+
unsubscribers.push(() => this.off(eventName, callback));
|
|
292
|
+
});
|
|
293
|
+
return () => unsubscribers.forEach((unsub) => unsub());
|
|
294
|
+
};
|
|
295
|
+
this.reload = (options = {}) => {
|
|
296
|
+
let keys = Object.keys(this.response.props);
|
|
297
|
+
if (options.only) keys = options.only;
|
|
298
|
+
if (options.except) keys = except(keys, options.except);
|
|
299
|
+
if (!this.response?.url) return;
|
|
300
|
+
const method = options.method ?? "get";
|
|
301
|
+
const data = options.data ?? {};
|
|
302
|
+
options.onStart?.();
|
|
303
|
+
http.getClient().request({
|
|
304
|
+
url: this.response.url,
|
|
305
|
+
method,
|
|
306
|
+
data: method === "get" ? void 0 : data,
|
|
307
|
+
params: method === "get" ? data : void 0,
|
|
308
|
+
headers: {
|
|
309
|
+
...options.headers,
|
|
310
|
+
Accept: "text/html, application/xhtml+xml",
|
|
311
|
+
"X-Inertia": "true",
|
|
312
|
+
"X-Inertia-Partial-Component": this.response.component,
|
|
313
|
+
"X-Inertia-Version": this.response.version ?? "",
|
|
314
|
+
"X-Inertia-Partial-Data": keys.join(","),
|
|
315
|
+
"X-InertiaUI-Modal": generateId$1(),
|
|
316
|
+
"X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
|
|
317
|
+
}
|
|
318
|
+
}).then((response) => {
|
|
319
|
+
this.updateProps(parseResponseData(response.data).props);
|
|
320
|
+
options.onSuccess?.(response);
|
|
321
|
+
}).catch((error) => {
|
|
322
|
+
options.onError?.(error);
|
|
323
|
+
}).finally(() => {
|
|
324
|
+
options.onFinish?.();
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
this.updateProps = (props) => {
|
|
328
|
+
Object.assign(this.props, props);
|
|
329
|
+
updateStack((prevStack) => prevStack);
|
|
330
|
+
};
|
|
331
|
+
this.id = response.id ?? generateId$1();
|
|
332
|
+
this.isOpen = false;
|
|
333
|
+
this.shouldRender = false;
|
|
334
|
+
this.listeners = {};
|
|
335
|
+
this.component = component;
|
|
336
|
+
this.props = response.props ?? {};
|
|
337
|
+
this.response = response;
|
|
338
|
+
this.config = config ?? {};
|
|
339
|
+
this.onCloseCallback = onClose ?? null;
|
|
340
|
+
this.afterLeaveCallback = afterLeave ?? null;
|
|
341
|
+
this.index = -1;
|
|
342
|
+
this.getParentModal = () => null;
|
|
343
|
+
this.getChildModal = () => null;
|
|
344
|
+
this.onTopOfStack = true;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const isValidModalResponse = (data) => {
|
|
348
|
+
return typeof data === "object" && data !== null && "component" in data && typeof data.component === "string";
|
|
349
|
+
};
|
|
350
|
+
const pushFromResponseData = (responseData, config = {}, onClose = null, onAfterLeave = null) => {
|
|
351
|
+
if (!isValidModalResponse(responseData)) return Promise.reject(/* @__PURE__ */ new Error("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."));
|
|
352
|
+
return router.resolveComponent(responseData.component).then((component) => push(component, responseData, config, onClose, onAfterLeave));
|
|
353
|
+
};
|
|
354
|
+
const loadDeferredProps = (modal) => {
|
|
355
|
+
const deferred = modal.response?.meta?.deferredProps;
|
|
356
|
+
if (!deferred) return;
|
|
357
|
+
Object.keys(deferred).forEach((key) => {
|
|
358
|
+
modal.reload({ only: deferred[key] });
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
const push = (component, response, config, onClose, afterLeave) => {
|
|
362
|
+
const newModal = new ModalClass(component, response, config, onClose, afterLeave);
|
|
363
|
+
newModal.index = stackRef.current.length;
|
|
364
|
+
updateStack((prevStack) => [...prevStack, newModal]);
|
|
365
|
+
loadDeferredProps(newModal);
|
|
366
|
+
newModal.show();
|
|
367
|
+
return newModal;
|
|
368
|
+
};
|
|
369
|
+
function pushLocalModal(name, config, onClose, afterLeave, props) {
|
|
370
|
+
if (!localModals[name]) throw new Error(`The local modal "${name}" has not been registered.`);
|
|
371
|
+
const modal = push(null, { props: props ?? {} }, config, onClose, afterLeave);
|
|
372
|
+
modal.name = name;
|
|
373
|
+
localModals[name].callback(modal);
|
|
374
|
+
return modal;
|
|
375
|
+
}
|
|
376
|
+
const visitModal = (url, options = {}) => visit(url, options.method ?? "get", options.data ?? {}, options.headers ?? {}, options.config ?? {}, options.onClose ?? null, options.onAfterLeave ?? null, options.queryStringArrayFormat ?? "brackets", options.navigate ?? getConfig("navigate"), options.onStart ?? null, options.onSuccess ?? null, options.onError ?? null, options.props ?? null).then((modal) => {
|
|
377
|
+
const listeners = options.listeners ?? {};
|
|
378
|
+
Object.keys(listeners).forEach((event) => {
|
|
379
|
+
const eventName = kebabCase(event);
|
|
380
|
+
modal.on(eventName, listeners[event]);
|
|
381
|
+
});
|
|
382
|
+
return modal;
|
|
383
|
+
});
|
|
384
|
+
const updateBrowserUrl = (url, useBrowserHistory, modalData) => {
|
|
385
|
+
if (!url || !useBrowserHistory || typeof window === "undefined") return;
|
|
386
|
+
router.push({
|
|
387
|
+
url,
|
|
388
|
+
preserveScroll: true,
|
|
389
|
+
preserveState: true,
|
|
390
|
+
props: modalData ? (currentProps) => ({
|
|
391
|
+
...currentProps,
|
|
392
|
+
_inertiaui_modal: {
|
|
393
|
+
...modalData,
|
|
394
|
+
baseUrl
|
|
395
|
+
}
|
|
396
|
+
}) : void 0
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
const visit = (href, method, payload = {}, headers = {}, config = {}, onClose = null, onAfterLeave = null, queryStringArrayFormat = "brackets", useBrowserHistory = false, onStart = null, onSuccess = null, onError = null, props = null) => {
|
|
400
|
+
const modalId = generateId$1();
|
|
401
|
+
return new Promise((resolve, reject) => {
|
|
402
|
+
if (href.startsWith("#")) {
|
|
403
|
+
resolve(pushLocalModal(href.substring(1), config, onClose, onAfterLeave, props));
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const [url, data] = mergeDataIntoQueryString(method, href || "", payload, queryStringArrayFormat);
|
|
407
|
+
const cachedResponse = prefetchCache.get(ResponseCache.key(method, url, data));
|
|
408
|
+
if (cachedResponse) {
|
|
409
|
+
const cachedData = parseResponseData(cachedResponse.data);
|
|
410
|
+
onSuccess?.(cachedResponse);
|
|
411
|
+
pushFromResponseData(cachedData, config, onClose, onAfterLeave).then((modal) => {
|
|
412
|
+
updateBrowserUrl(cachedData.url, useBrowserHistory, cachedData);
|
|
413
|
+
resolve(modal);
|
|
414
|
+
}).catch(reject);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (stackRef.current.length === 0) baseUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
418
|
+
const requestHeaders = {
|
|
419
|
+
...headers,
|
|
420
|
+
Accept: "text/html, application/xhtml+xml",
|
|
421
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
422
|
+
"X-Inertia": "true",
|
|
423
|
+
"X-Inertia-Version": currentPageVersion ?? "",
|
|
424
|
+
"X-InertiaUI-Modal": modalId,
|
|
425
|
+
"X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
|
|
426
|
+
};
|
|
427
|
+
onStart?.();
|
|
428
|
+
progress?.start();
|
|
429
|
+
http.getClient().request({
|
|
430
|
+
url,
|
|
431
|
+
method,
|
|
432
|
+
data,
|
|
433
|
+
headers: requestHeaders
|
|
434
|
+
}).then((response) => {
|
|
435
|
+
const responseData = parseResponseData(response.data);
|
|
436
|
+
onSuccess?.(response);
|
|
437
|
+
pushFromResponseData(responseData, config, onClose, onAfterLeave).then((modal) => {
|
|
438
|
+
updateBrowserUrl(responseData.url, useBrowserHistory, responseData);
|
|
439
|
+
resolve(modal);
|
|
440
|
+
}).catch(reject);
|
|
441
|
+
}).catch((...args) => {
|
|
442
|
+
onError?.(...args);
|
|
443
|
+
reject(args[0]);
|
|
444
|
+
}).finally(() => {
|
|
445
|
+
progress?.finish();
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
const registerLocalModal = (name, callback) => {
|
|
450
|
+
setLocalModals((prevLocalModals) => ({
|
|
451
|
+
...prevLocalModals,
|
|
452
|
+
[name]: {
|
|
453
|
+
name,
|
|
454
|
+
callback
|
|
455
|
+
}
|
|
456
|
+
}));
|
|
457
|
+
};
|
|
458
|
+
const removeLocalModal = (name) => {
|
|
459
|
+
setLocalModals((prevLocalModals) => {
|
|
460
|
+
const newLocalModals = { ...prevLocalModals };
|
|
461
|
+
delete newLocalModals[name];
|
|
462
|
+
return newLocalModals;
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
const value = {
|
|
466
|
+
get stack() {
|
|
467
|
+
return stackRef.current;
|
|
468
|
+
},
|
|
469
|
+
localModals,
|
|
470
|
+
push,
|
|
471
|
+
pushFromResponseData,
|
|
472
|
+
length: () => stackRef.current.length,
|
|
473
|
+
closeAll: (force = false) => {
|
|
474
|
+
if (force) updateStack(() => []);
|
|
475
|
+
else [...stackRef.current].reverse().forEach((modal) => modal.close());
|
|
476
|
+
},
|
|
477
|
+
reset: () => updateStack(() => []),
|
|
478
|
+
visit,
|
|
479
|
+
visitModal,
|
|
480
|
+
registerLocalModal,
|
|
481
|
+
removeLocalModal
|
|
482
|
+
};
|
|
483
|
+
return /* @__PURE__ */ jsx(ModalStackContext.Provider, {
|
|
484
|
+
value,
|
|
485
|
+
children
|
|
486
|
+
});
|
|
538
487
|
};
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
return context;
|
|
488
|
+
var useModalStack = () => {
|
|
489
|
+
const context = useContext(ModalStackContext);
|
|
490
|
+
if (context === null) throw new Error("useModalStack must be used within a ModalStackProvider");
|
|
491
|
+
return context;
|
|
545
492
|
};
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
493
|
+
var modalPropNames = [
|
|
494
|
+
"closeButton",
|
|
495
|
+
"closeExplicitly",
|
|
496
|
+
"closeOnClickOutside",
|
|
497
|
+
"maxWidth",
|
|
498
|
+
"paddingClasses",
|
|
499
|
+
"panelClasses",
|
|
500
|
+
"position",
|
|
501
|
+
"slideover"
|
|
502
|
+
];
|
|
503
|
+
var initFromPageProps = (pageProps) => {
|
|
504
|
+
if (pageProps.initialPage) currentPageVersion = pageProps.initialPage.version ?? null;
|
|
551
505
|
};
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
/* @__PURE__ */ jsx(ModalRoot, {})
|
|
571
|
-
] });
|
|
572
|
-
};
|
|
573
|
-
return /* @__PURE__ */ jsx(ModalStackProvider, { children: /* @__PURE__ */ jsx(App, { ...pageProps, children: renderInertiaApp }) });
|
|
506
|
+
var renderApp = (App, pageProps) => {
|
|
507
|
+
initFromPageProps(pageProps);
|
|
508
|
+
const renderInertiaApp = ({ Component, props, key }) => {
|
|
509
|
+
const renderComponent = () => {
|
|
510
|
+
const child = createElement(Component, {
|
|
511
|
+
key,
|
|
512
|
+
...props
|
|
513
|
+
});
|
|
514
|
+
if (typeof Component.layout === "function") return Component.layout(child);
|
|
515
|
+
if (Array.isArray(Component.layout)) return Component.layout.slice().reverse().reduce((acc, Layout) => createElement(Layout, props, acc), child);
|
|
516
|
+
return child;
|
|
517
|
+
};
|
|
518
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [renderComponent(), /* @__PURE__ */ jsx(ModalRoot, {})] });
|
|
519
|
+
};
|
|
520
|
+
return /* @__PURE__ */ jsx(ModalStackProvider, { children: /* @__PURE__ */ jsx(App, {
|
|
521
|
+
...pageProps,
|
|
522
|
+
children: renderInertiaApp
|
|
523
|
+
}) });
|
|
574
524
|
};
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
const previousModal = previousModalRef.current;
|
|
653
|
-
previousModalRef.current = newModal;
|
|
654
|
-
if (!newModal) {
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
if (previousModal && newModal.component === previousModal.component && sameUrlPath(newModal.url, previousModal.url)) {
|
|
658
|
-
context?.stack[0]?.updateProps(newModal.props ?? {});
|
|
659
|
-
return;
|
|
660
|
-
}
|
|
661
|
-
if (!previousModal && context && context.stack.length > 0) {
|
|
662
|
-
const existingModal = context.stack.find(
|
|
663
|
-
(m) => m.response?.component === newModal.component && sameUrlPath(m.response?.url, newModal.url)
|
|
664
|
-
);
|
|
665
|
-
if (existingModal) {
|
|
666
|
-
existingModal.updateProps(newModal.props ?? {});
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}, [$page.props?._inertiaui_modal]);
|
|
670
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
671
|
-
children,
|
|
672
|
-
context && context.stack.length > 0 && /* @__PURE__ */ jsx(ModalRenderer, { index: 0 })
|
|
673
|
-
] });
|
|
525
|
+
var ModalRoot = ({ children }) => {
|
|
526
|
+
const context = useContext(ModalStackContext);
|
|
527
|
+
const $page = usePage();
|
|
528
|
+
const pendingModalKeysRef = useRef(/* @__PURE__ */ new Set());
|
|
529
|
+
currentPageVersion = $page.version ?? null;
|
|
530
|
+
const getModalKey = (modalData) => modalData.id || `${modalData.component}:${modalData.url}`;
|
|
531
|
+
const isNavigatingRef = useRef(false);
|
|
532
|
+
const pageRef = useRef($page);
|
|
533
|
+
pageRef.current = $page;
|
|
534
|
+
useLayoutEffect(() => http.onRequest((config) => {
|
|
535
|
+
const baseUrlValue = baseUrl ?? pageRef.current.props._inertiaui_modal?.baseUrl ?? null;
|
|
536
|
+
if (baseUrlValue) {
|
|
537
|
+
config.headers = config.headers ?? {};
|
|
538
|
+
config.headers["X-InertiaUI-Modal-Base-Url"] = baseUrlValue;
|
|
539
|
+
}
|
|
540
|
+
return config;
|
|
541
|
+
}), []);
|
|
542
|
+
useEffect(() => router.on("start", () => isNavigatingRef.current = true), []);
|
|
543
|
+
useEffect(() => router.on("finish", () => isNavigatingRef.current = false), []);
|
|
544
|
+
useEffect(() => router.on("navigate", function($event) {
|
|
545
|
+
const modalOnBase = $event.detail.page.props._inertiaui_modal;
|
|
546
|
+
const pageUrl = $event.detail.page.url;
|
|
547
|
+
if (closingToBaseUrlTarget) {
|
|
548
|
+
if (new URL(closingToBaseUrlTarget, "http://x").pathname === new URL(pageUrl, "http://x").pathname) {
|
|
549
|
+
closingToBaseUrlTarget = null;
|
|
550
|
+
context?.closeAll(true);
|
|
551
|
+
baseUrl = null;
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
closingToBaseUrlTarget = null;
|
|
555
|
+
}
|
|
556
|
+
if (!modalOnBase) {
|
|
557
|
+
context?.closeAll(true);
|
|
558
|
+
baseUrl = null;
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
if (!sameUrlPath(pageUrl, modalOnBase.url)) {
|
|
562
|
+
context?.closeAll(true);
|
|
563
|
+
baseUrl = null;
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const modalKey = getModalKey(modalOnBase);
|
|
567
|
+
if (pendingModalKeysRef.current.has(modalKey)) return;
|
|
568
|
+
if (modalOnBase.id && context?.stack.some((m) => m.id === modalOnBase.id)) return;
|
|
569
|
+
if (context?.stack.some((m) => m.response?.component === modalOnBase.component && sameUrlPath(m.response?.url, modalOnBase.url))) return;
|
|
570
|
+
baseUrl = modalOnBase.baseUrl;
|
|
571
|
+
pendingModalKeysRef.current.add(modalKey);
|
|
572
|
+
context?.pushFromResponseData(modalOnBase, {}, () => {
|
|
573
|
+
if (!modalOnBase.baseUrl) {
|
|
574
|
+
console.error("No base url in modal response data so cannot navigate back");
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
baseUrl = null;
|
|
578
|
+
if (!isNavigatingRef.current && typeof window !== "undefined" && window.location.href !== modalOnBase.baseUrl) router.visit(modalOnBase.baseUrl, {
|
|
579
|
+
preserveScroll: true,
|
|
580
|
+
preserveState: true
|
|
581
|
+
});
|
|
582
|
+
}).finally(() => {
|
|
583
|
+
pendingModalKeysRef.current.delete(modalKey);
|
|
584
|
+
});
|
|
585
|
+
}), []);
|
|
586
|
+
const previousModalRef = useRef(void 0);
|
|
587
|
+
useEffect(() => {
|
|
588
|
+
const newModal = $page.props?._inertiaui_modal;
|
|
589
|
+
const previousModal = previousModalRef.current;
|
|
590
|
+
previousModalRef.current = newModal;
|
|
591
|
+
if (!newModal) return;
|
|
592
|
+
if (previousModal && newModal.component === previousModal.component && sameUrlPath(newModal.url, previousModal.url)) {
|
|
593
|
+
context?.stack[0]?.updateProps(newModal.props ?? {});
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (!previousModal && context && context.stack.length > 0) {
|
|
597
|
+
const existingModal = context.stack.find((m) => m.response?.component === newModal.component && sameUrlPath(m.response?.url, newModal.url));
|
|
598
|
+
if (existingModal) existingModal.updateProps(newModal.props ?? {});
|
|
599
|
+
}
|
|
600
|
+
}, [$page.props?._inertiaui_modal]);
|
|
601
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [children, context && context.stack.length > 0 && /* @__PURE__ */ jsx(ModalRenderer, { index: 0 })] });
|
|
674
602
|
};
|
|
675
|
-
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/ModalRenderer.tsx
|
|
605
|
+
var ModalIndexContext = React.createContext(null);
|
|
676
606
|
ModalIndexContext.displayName = "ModalIndexContext";
|
|
677
|
-
|
|
678
|
-
|
|
607
|
+
var useModalIndex = () => {
|
|
608
|
+
return React.useContext(ModalIndexContext);
|
|
679
609
|
};
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
610
|
+
var ModalRenderer = ({ index }) => {
|
|
611
|
+
const { stack } = useModalStack();
|
|
612
|
+
const modalContext = useMemo(() => {
|
|
613
|
+
return stack[index];
|
|
614
|
+
}, [stack, index]);
|
|
615
|
+
if (!modalContext?.component) return null;
|
|
616
|
+
return /* @__PURE__ */ jsx(ModalIndexContext.Provider, {
|
|
617
|
+
value: index,
|
|
618
|
+
children: createElement(modalContext.component, {
|
|
619
|
+
...modalContext.props,
|
|
620
|
+
onModalEvent: (...args) => modalContext.emit("modal-event", ...args)
|
|
621
|
+
})
|
|
622
|
+
});
|
|
692
623
|
};
|
|
624
|
+
//#endregion
|
|
625
|
+
//#region src/useModal.ts
|
|
693
626
|
function useModal() {
|
|
694
|
-
|
|
627
|
+
return useModalStack().stack[useModalIndex()] ?? null;
|
|
695
628
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
return loaded ? children : fallback;
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/Deferred.tsx
|
|
631
|
+
var Deferred = ({ children, data, fallback }) => {
|
|
632
|
+
if (!data) throw new Error("`<Deferred>` requires a `data` prop to be a string or array of strings");
|
|
633
|
+
const [loaded, setLoaded] = useState(false);
|
|
634
|
+
const keys = Array.isArray(data) ? data : [data];
|
|
635
|
+
const modalProps = useModal()?.props ?? {};
|
|
636
|
+
useEffect(() => {
|
|
637
|
+
setLoaded(keys.every((key) => modalProps[key] !== void 0));
|
|
638
|
+
}, [modalProps, keys]);
|
|
639
|
+
return loaded ? children : fallback;
|
|
708
640
|
};
|
|
709
641
|
Deferred.displayName = "InertiaModalDeferred";
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
close: modalContext.close,
|
|
825
|
-
config,
|
|
826
|
-
emit: modalContext.emit,
|
|
827
|
-
getChildModal: modalContext.getChildModal,
|
|
828
|
-
getParentModal: modalContext.getParentModal,
|
|
829
|
-
id: modalContext.id,
|
|
830
|
-
index: modalContext.index,
|
|
831
|
-
isOpen: modalContext.isOpen,
|
|
832
|
-
modalContext,
|
|
833
|
-
onTopOfStack: modalContext.onTopOfStack,
|
|
834
|
-
reload: modalContext.reload,
|
|
835
|
-
setOpen: modalContext.setOpen,
|
|
836
|
-
shouldRender: modalContext.shouldRender
|
|
837
|
-
}) : children,
|
|
838
|
-
nextIndex !== void 0 && /* @__PURE__ */ jsx(ModalRenderer, { index: nextIndex })
|
|
839
|
-
] });
|
|
840
|
-
}
|
|
841
|
-
);
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/HeadlessModal.tsx
|
|
644
|
+
var HeadlessModal = forwardRef((allProps, ref) => {
|
|
645
|
+
const { name, children, onFocus, onBlur, onClose, onSuccess, ...props } = allProps;
|
|
646
|
+
const modalIndex = useModalIndex();
|
|
647
|
+
const { stack, registerLocalModal, removeLocalModal } = useModalStack();
|
|
648
|
+
const [localModalContext, setLocalModalContext] = useState(null);
|
|
649
|
+
const modalContext = useMemo(() => name ? localModalContext : stack[modalIndex], [
|
|
650
|
+
name,
|
|
651
|
+
localModalContext,
|
|
652
|
+
modalIndex,
|
|
653
|
+
stack
|
|
654
|
+
]);
|
|
655
|
+
const nextIndex = useMemo(() => {
|
|
656
|
+
return stack.find((m) => m.shouldRender && m.index > (modalContext?.index ?? -1))?.index;
|
|
657
|
+
}, [modalIndex, stack]);
|
|
658
|
+
const configSlideover = useMemo(() => modalContext?.config.slideover ?? props.slideover ?? getConfig("type") === "slideover", [props.slideover, modalContext?.config.slideover]);
|
|
659
|
+
const config = useMemo(() => ({
|
|
660
|
+
slideover: configSlideover,
|
|
661
|
+
closeButton: props.closeButton ?? getConfigByType(configSlideover, "closeButton"),
|
|
662
|
+
closeExplicitly: props.closeExplicitly ?? getConfigByType(configSlideover, "closeExplicitly"),
|
|
663
|
+
closeOnClickOutside: props.closeOnClickOutside ?? getConfigByType(configSlideover, "closeOnClickOutside"),
|
|
664
|
+
maxWidth: props.maxWidth ?? getConfigByType(configSlideover, "maxWidth"),
|
|
665
|
+
paddingClasses: props.paddingClasses ?? getConfigByType(configSlideover, "paddingClasses"),
|
|
666
|
+
panelClasses: props.panelClasses ?? getConfigByType(configSlideover, "panelClasses"),
|
|
667
|
+
position: props.position ?? getConfigByType(configSlideover, "position"),
|
|
668
|
+
...modalContext?.config
|
|
669
|
+
}), [
|
|
670
|
+
props,
|
|
671
|
+
modalContext?.config,
|
|
672
|
+
configSlideover
|
|
673
|
+
]);
|
|
674
|
+
useEffect(() => {
|
|
675
|
+
if (name) {
|
|
676
|
+
let removeListeners = null;
|
|
677
|
+
registerLocalModal(name, (localContext) => {
|
|
678
|
+
removeListeners = localContext.registerEventListenersFromProps(props);
|
|
679
|
+
setLocalModalContext(localContext);
|
|
680
|
+
});
|
|
681
|
+
return () => {
|
|
682
|
+
removeListeners?.();
|
|
683
|
+
removeListeners = null;
|
|
684
|
+
removeLocalModal(name);
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
return modalContext?.registerEventListenersFromProps(props);
|
|
688
|
+
}, [name]);
|
|
689
|
+
const modalContextRef = useRef(modalContext);
|
|
690
|
+
useEffect(() => {
|
|
691
|
+
modalContextRef.current = modalContext;
|
|
692
|
+
}, [modalContext]);
|
|
693
|
+
const previousIsOpenRef = useRef(void 0);
|
|
694
|
+
useEffect(() => {
|
|
695
|
+
if (modalContext != null) {
|
|
696
|
+
if (modalContext.isOpen) onSuccess?.();
|
|
697
|
+
else if (previousIsOpenRef.current === true) onClose?.();
|
|
698
|
+
previousIsOpenRef.current = modalContext.isOpen;
|
|
699
|
+
}
|
|
700
|
+
}, [modalContext?.isOpen]);
|
|
701
|
+
const [rendered, setRendered] = useState(false);
|
|
702
|
+
useEffect(() => {
|
|
703
|
+
if (rendered && modalContext != null && modalContext.isOpen) if (modalContext.onTopOfStack) onFocus?.();
|
|
704
|
+
else onBlur?.();
|
|
705
|
+
setRendered(true);
|
|
706
|
+
}, [modalContext?.onTopOfStack]);
|
|
707
|
+
useImperativeHandle(ref, () => ({
|
|
708
|
+
afterLeave: () => modalContextRef.current?.afterLeave(),
|
|
709
|
+
close: () => modalContextRef.current?.close(),
|
|
710
|
+
emit: (...args) => modalContextRef.current?.emit(...args),
|
|
711
|
+
getChildModal: () => modalContextRef.current?.getChildModal(),
|
|
712
|
+
getParentModal: () => modalContextRef.current?.getParentModal(),
|
|
713
|
+
reload: (options) => modalContextRef.current?.reload(options),
|
|
714
|
+
setOpen: (open) => modalContextRef.current?.setOpen(open),
|
|
715
|
+
get id() {
|
|
716
|
+
return modalContextRef.current?.id;
|
|
717
|
+
},
|
|
718
|
+
get index() {
|
|
719
|
+
return modalContextRef.current?.index;
|
|
720
|
+
},
|
|
721
|
+
get isOpen() {
|
|
722
|
+
return modalContextRef.current?.isOpen;
|
|
723
|
+
},
|
|
724
|
+
get config() {
|
|
725
|
+
return modalContextRef.current?.config;
|
|
726
|
+
},
|
|
727
|
+
get modalContext() {
|
|
728
|
+
return modalContextRef.current;
|
|
729
|
+
},
|
|
730
|
+
get onTopOfStack() {
|
|
731
|
+
return modalContextRef.current?.onTopOfStack;
|
|
732
|
+
},
|
|
733
|
+
get shouldRender() {
|
|
734
|
+
return modalContextRef.current?.shouldRender;
|
|
735
|
+
}
|
|
736
|
+
}), [modalContext]);
|
|
737
|
+
if (!modalContext?.shouldRender) return null;
|
|
738
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [typeof children === "function" ? children({
|
|
739
|
+
...modalContext.props,
|
|
740
|
+
afterLeave: modalContext.afterLeave,
|
|
741
|
+
close: modalContext.close,
|
|
742
|
+
config,
|
|
743
|
+
emit: modalContext.emit,
|
|
744
|
+
getChildModal: modalContext.getChildModal,
|
|
745
|
+
getParentModal: modalContext.getParentModal,
|
|
746
|
+
id: modalContext.id,
|
|
747
|
+
index: modalContext.index,
|
|
748
|
+
isOpen: modalContext.isOpen,
|
|
749
|
+
modalContext,
|
|
750
|
+
onTopOfStack: modalContext.onTopOfStack,
|
|
751
|
+
reload: modalContext.reload,
|
|
752
|
+
setOpen: modalContext.setOpen,
|
|
753
|
+
shouldRender: modalContext.shouldRender
|
|
754
|
+
}) : children, nextIndex !== void 0 && /* @__PURE__ */ jsx(ModalRenderer, { index: nextIndex })] });
|
|
755
|
+
});
|
|
842
756
|
HeadlessModal.displayName = "HeadlessModal";
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
"button",
|
|
846
|
-
{
|
|
847
|
-
type: "button",
|
|
848
|
-
className: "im-close-button text-gray-400 hover:text-gray-500",
|
|
849
|
-
onClick,
|
|
850
|
-
children: [
|
|
851
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" }),
|
|
852
|
-
/* @__PURE__ */ jsx(
|
|
853
|
-
"svg",
|
|
854
|
-
{
|
|
855
|
-
className: "size-6",
|
|
856
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
857
|
-
fill: "none",
|
|
858
|
-
viewBox: "0 0 24 24",
|
|
859
|
-
strokeWidth: "2",
|
|
860
|
-
stroke: "currentColor",
|
|
861
|
-
"aria-hidden": "true",
|
|
862
|
-
children: /* @__PURE__ */ jsx(
|
|
863
|
-
"path",
|
|
864
|
-
{
|
|
865
|
-
strokeLinecap: "round",
|
|
866
|
-
strokeLinejoin: "round",
|
|
867
|
-
d: "M6 18L18 6M6 6l12 12"
|
|
868
|
-
}
|
|
869
|
-
)
|
|
870
|
-
}
|
|
871
|
-
)
|
|
872
|
-
]
|
|
873
|
-
}
|
|
874
|
-
);
|
|
875
|
-
}
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region ../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
876
759
|
function r(e) {
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
760
|
+
var t, f, n = "";
|
|
761
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
762
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
763
|
+
var o = e.length;
|
|
764
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
765
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
766
|
+
return n;
|
|
884
767
|
}
|
|
885
768
|
function clsx() {
|
|
886
|
-
|
|
887
|
-
|
|
769
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
770
|
+
return n;
|
|
771
|
+
}
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/CloseButton.tsx
|
|
774
|
+
function CloseButton({ onClick }) {
|
|
775
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
776
|
+
type: "button",
|
|
777
|
+
className: "im-close-button text-gray-400 hover:text-gray-500",
|
|
778
|
+
onClick,
|
|
779
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
780
|
+
className: "sr-only",
|
|
781
|
+
children: "Close"
|
|
782
|
+
}), /* @__PURE__ */ jsx("svg", {
|
|
783
|
+
className: "size-6",
|
|
784
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
785
|
+
fill: "none",
|
|
786
|
+
viewBox: "0 0 24 24",
|
|
787
|
+
strokeWidth: "2",
|
|
788
|
+
stroke: "currentColor",
|
|
789
|
+
"aria-hidden": "true",
|
|
790
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
791
|
+
strokeLinecap: "round",
|
|
792
|
+
strokeLinejoin: "round",
|
|
793
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
794
|
+
})
|
|
795
|
+
})]
|
|
796
|
+
});
|
|
888
797
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/constants.ts
|
|
800
|
+
/**
|
|
801
|
+
* Max width classes for modals and slideovers.
|
|
802
|
+
* Uses a map lookup for Tailwind 4 compatibility (scanner picks up full class strings).
|
|
803
|
+
*/
|
|
804
|
+
var maxWidthClasses = {
|
|
805
|
+
sm: "sm:max-w-sm",
|
|
806
|
+
md: "sm:max-w-md",
|
|
807
|
+
lg: "sm:max-w-md md:max-w-lg",
|
|
808
|
+
xl: "sm:max-w-md md:max-w-xl",
|
|
809
|
+
"2xl": "sm:max-w-md md:max-w-xl lg:max-w-2xl",
|
|
810
|
+
"3xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl",
|
|
811
|
+
"4xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-4xl",
|
|
812
|
+
"5xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl",
|
|
813
|
+
"6xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-6xl",
|
|
814
|
+
"7xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-7xl"
|
|
900
815
|
};
|
|
901
|
-
const defaultMaxWidth = "2xl";
|
|
902
816
|
function getMaxWidthClass(maxWidth) {
|
|
903
|
-
|
|
817
|
+
return maxWidthClasses[maxWidth] || maxWidthClasses["2xl"];
|
|
904
818
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
}
|
|
1142
|
-
)
|
|
1143
|
-
}
|
|
1144
|
-
);
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region src/ModalContent.tsx
|
|
821
|
+
var ModalContent = ({ modalContext, config, useNativeDialog, isFirstModal, onAfterLeave, children }) => {
|
|
822
|
+
const [isRendered, setIsRendered] = useState(false);
|
|
823
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
824
|
+
const [entered, setEntered] = useState(false);
|
|
825
|
+
const wrapperRef = useRef(null);
|
|
826
|
+
const dialogRef = useRef(null);
|
|
827
|
+
const nativeWrapperRef = useRef(null);
|
|
828
|
+
const cleanupFocusTrapRef = useRef(null);
|
|
829
|
+
const cleanupEscapeKeyRef = useRef(null);
|
|
830
|
+
const maxWidthClass = useMemo(() => getMaxWidthClass(config.maxWidth), [config.maxWidth]);
|
|
831
|
+
const animateIn = useCallback(async (element) => {
|
|
832
|
+
if (!element) return;
|
|
833
|
+
setIsVisible(true);
|
|
834
|
+
await animate(element, [{
|
|
835
|
+
transform: "translate3d(0, 1rem, 0) scale(0.95)",
|
|
836
|
+
opacity: 0
|
|
837
|
+
}, {
|
|
838
|
+
transform: "translate3d(0, 0, 0) scale(1)",
|
|
839
|
+
opacity: 1
|
|
840
|
+
}]);
|
|
841
|
+
setEntered(true);
|
|
842
|
+
}, []);
|
|
843
|
+
const animateOut = useCallback(async (element) => {
|
|
844
|
+
if (!element) return;
|
|
845
|
+
setIsVisible(false);
|
|
846
|
+
await animate(element, [{
|
|
847
|
+
transform: "translate3d(0, 0, 0) scale(1)",
|
|
848
|
+
opacity: 1
|
|
849
|
+
}, {
|
|
850
|
+
transform: "translate3d(0, 1rem, 0) scale(0.95)",
|
|
851
|
+
opacity: 0
|
|
852
|
+
}]);
|
|
853
|
+
setIsRendered(false);
|
|
854
|
+
if (useNativeDialog && dialogRef.current) dialogRef.current.close();
|
|
855
|
+
onAfterLeave?.();
|
|
856
|
+
modalContext.afterLeave();
|
|
857
|
+
}, [
|
|
858
|
+
useNativeDialog,
|
|
859
|
+
onAfterLeave,
|
|
860
|
+
modalContext
|
|
861
|
+
]);
|
|
862
|
+
const setupFocusTrap = useCallback(() => {
|
|
863
|
+
if (useNativeDialog) return;
|
|
864
|
+
if (!wrapperRef.current || !modalContext.onTopOfStack) return;
|
|
865
|
+
if (cleanupFocusTrapRef.current) return;
|
|
866
|
+
cleanupFocusTrapRef.current = createFocusTrap(wrapperRef.current, {
|
|
867
|
+
initialFocus: true,
|
|
868
|
+
returnFocus: false
|
|
869
|
+
});
|
|
870
|
+
}, [modalContext.onTopOfStack, useNativeDialog]);
|
|
871
|
+
const cleanupFocusTrap = useCallback(() => {
|
|
872
|
+
if (cleanupFocusTrapRef.current) {
|
|
873
|
+
cleanupFocusTrapRef.current();
|
|
874
|
+
cleanupFocusTrapRef.current = null;
|
|
875
|
+
}
|
|
876
|
+
}, []);
|
|
877
|
+
const setupEscapeKey = useCallback(() => {
|
|
878
|
+
if (useNativeDialog) return;
|
|
879
|
+
if (cleanupEscapeKeyRef.current) return;
|
|
880
|
+
if (config?.closeExplicitly) return;
|
|
881
|
+
cleanupEscapeKeyRef.current = onEscapeKey(() => {
|
|
882
|
+
if (modalContext.onTopOfStack) modalContext.close();
|
|
883
|
+
});
|
|
884
|
+
}, [
|
|
885
|
+
config?.closeExplicitly,
|
|
886
|
+
modalContext,
|
|
887
|
+
useNativeDialog
|
|
888
|
+
]);
|
|
889
|
+
const cleanupEscapeKey = useCallback(() => {
|
|
890
|
+
if (cleanupEscapeKeyRef.current) {
|
|
891
|
+
cleanupEscapeKeyRef.current();
|
|
892
|
+
cleanupEscapeKeyRef.current = null;
|
|
893
|
+
}
|
|
894
|
+
}, []);
|
|
895
|
+
const handleClickOutside = useCallback((event) => {
|
|
896
|
+
if (useNativeDialog) return;
|
|
897
|
+
if (!modalContext.onTopOfStack) return;
|
|
898
|
+
if (config?.closeExplicitly) return;
|
|
899
|
+
if (config?.closeOnClickOutside === false) return;
|
|
900
|
+
if (!wrapperRef.current) return;
|
|
901
|
+
if (!wrapperRef.current.contains(event.target)) modalContext.close();
|
|
902
|
+
}, [
|
|
903
|
+
modalContext,
|
|
904
|
+
config?.closeExplicitly,
|
|
905
|
+
config?.closeOnClickOutside,
|
|
906
|
+
useNativeDialog
|
|
907
|
+
]);
|
|
908
|
+
const handleCancel = useCallback((event) => {
|
|
909
|
+
event.preventDefault();
|
|
910
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly) modalContext.close();
|
|
911
|
+
}, [modalContext, config?.closeExplicitly]);
|
|
912
|
+
const handleDialogClick = useCallback((event) => {
|
|
913
|
+
if (event.target === dialogRef.current) {
|
|
914
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly && config?.closeOnClickOutside !== false) modalContext.close();
|
|
915
|
+
}
|
|
916
|
+
}, [
|
|
917
|
+
modalContext,
|
|
918
|
+
config?.closeExplicitly,
|
|
919
|
+
config?.closeOnClickOutside
|
|
920
|
+
]);
|
|
921
|
+
const prevIsOpenRef = useRef(modalContext.isOpen);
|
|
922
|
+
useEffect(() => {
|
|
923
|
+
if (useNativeDialog) {
|
|
924
|
+
if (modalContext.isOpen && !dialogRef.current?.open) {
|
|
925
|
+
dialogRef.current?.showModal();
|
|
926
|
+
animateIn(nativeWrapperRef.current);
|
|
927
|
+
} else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
928
|
+
setEntered(false);
|
|
929
|
+
animateOut(nativeWrapperRef.current);
|
|
930
|
+
}
|
|
931
|
+
} else if (modalContext.isOpen && !isRendered) setIsRendered(true);
|
|
932
|
+
else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
933
|
+
setEntered(false);
|
|
934
|
+
animateOut(wrapperRef.current);
|
|
935
|
+
}
|
|
936
|
+
prevIsOpenRef.current = modalContext.isOpen;
|
|
937
|
+
}, [
|
|
938
|
+
modalContext.isOpen,
|
|
939
|
+
useNativeDialog,
|
|
940
|
+
animateIn,
|
|
941
|
+
animateOut,
|
|
942
|
+
isRendered
|
|
943
|
+
]);
|
|
944
|
+
useEffect(() => {
|
|
945
|
+
if (!useNativeDialog && isRendered && !entered && modalContext.isOpen) animateIn(wrapperRef.current).then(() => {
|
|
946
|
+
setupFocusTrap();
|
|
947
|
+
});
|
|
948
|
+
}, [
|
|
949
|
+
isRendered,
|
|
950
|
+
useNativeDialog,
|
|
951
|
+
entered,
|
|
952
|
+
modalContext.isOpen,
|
|
953
|
+
animateIn,
|
|
954
|
+
setupFocusTrap
|
|
955
|
+
]);
|
|
956
|
+
useEffect(() => {
|
|
957
|
+
if (!useNativeDialog) setupEscapeKey();
|
|
958
|
+
return () => {
|
|
959
|
+
cleanupEscapeKey();
|
|
960
|
+
};
|
|
961
|
+
}, [
|
|
962
|
+
useNativeDialog,
|
|
963
|
+
setupEscapeKey,
|
|
964
|
+
cleanupEscapeKey
|
|
965
|
+
]);
|
|
966
|
+
useEffect(() => {
|
|
967
|
+
if (useNativeDialog) return;
|
|
968
|
+
if (modalContext.onTopOfStack) {
|
|
969
|
+
setupEscapeKey();
|
|
970
|
+
if (entered) setupFocusTrap();
|
|
971
|
+
} else {
|
|
972
|
+
cleanupFocusTrap();
|
|
973
|
+
cleanupEscapeKey();
|
|
974
|
+
}
|
|
975
|
+
}, [
|
|
976
|
+
modalContext.onTopOfStack,
|
|
977
|
+
entered,
|
|
978
|
+
setupEscapeKey,
|
|
979
|
+
setupFocusTrap,
|
|
980
|
+
cleanupFocusTrap,
|
|
981
|
+
cleanupEscapeKey,
|
|
982
|
+
useNativeDialog
|
|
983
|
+
]);
|
|
984
|
+
useEffect(() => {
|
|
985
|
+
return () => {
|
|
986
|
+
const wrapper = useNativeDialog ? nativeWrapperRef.current : wrapperRef.current;
|
|
987
|
+
if (wrapper) cancelAnimations(wrapper);
|
|
988
|
+
if (useNativeDialog) {
|
|
989
|
+
if (dialogRef.current?.open) dialogRef.current.close();
|
|
990
|
+
} else {
|
|
991
|
+
cleanupFocusTrap();
|
|
992
|
+
cleanupEscapeKey();
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
}, [
|
|
996
|
+
useNativeDialog,
|
|
997
|
+
cleanupFocusTrap,
|
|
998
|
+
cleanupEscapeKey
|
|
999
|
+
]);
|
|
1000
|
+
const renderContent = () => /* @__PURE__ */ jsxs("div", {
|
|
1001
|
+
className: `im-modal-content relative ${config.paddingClasses} ${config.panelClasses}`,
|
|
1002
|
+
"data-inertiaui-modal-entered": entered,
|
|
1003
|
+
children: [config.closeButton && /* @__PURE__ */ jsx("div", {
|
|
1004
|
+
className: "absolute top-0 right-0 pt-3 pr-3",
|
|
1005
|
+
children: /* @__PURE__ */ jsx(CloseButton, { onClick: modalContext.close })
|
|
1006
|
+
}), typeof children === "function" ? children({
|
|
1007
|
+
modalContext,
|
|
1008
|
+
config
|
|
1009
|
+
}) : children]
|
|
1010
|
+
});
|
|
1011
|
+
if (useNativeDialog) return /* @__PURE__ */ jsx("dialog", {
|
|
1012
|
+
ref: dialogRef,
|
|
1013
|
+
className: clsx("im-modal-dialog m-0 overflow-visible bg-transparent p-0", "size-full max-h-none max-w-none", "backdrop:bg-black/75 backdrop:transition-opacity backdrop:duration-300", isVisible ? "backdrop:opacity-100" : "backdrop:opacity-0", !isFirstModal && "backdrop:bg-transparent"),
|
|
1014
|
+
onCancel: handleCancel,
|
|
1015
|
+
onClick: handleDialogClick,
|
|
1016
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1017
|
+
className: "im-modal-container fixed inset-0 overflow-y-auto p-4",
|
|
1018
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1019
|
+
className: clsx("im-modal-positioner flex min-h-full justify-center", {
|
|
1020
|
+
"items-start": config.position === "top",
|
|
1021
|
+
"items-center": config.position === "center",
|
|
1022
|
+
"items-end": config.position === "bottom"
|
|
1023
|
+
}),
|
|
1024
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1025
|
+
ref: nativeWrapperRef,
|
|
1026
|
+
className: clsx("im-modal-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1027
|
+
children: renderContent()
|
|
1028
|
+
})
|
|
1029
|
+
})
|
|
1030
|
+
})
|
|
1031
|
+
});
|
|
1032
|
+
if (!isRendered) return null;
|
|
1033
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1034
|
+
className: "im-modal-container fixed inset-0 z-40 overflow-y-auto p-4",
|
|
1035
|
+
onMouseDown: handleClickOutside,
|
|
1036
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1037
|
+
className: clsx("im-modal-positioner flex min-h-full justify-center", {
|
|
1038
|
+
"items-start": config.position === "top",
|
|
1039
|
+
"items-center": config.position === "center",
|
|
1040
|
+
"items-end": config.position === "bottom"
|
|
1041
|
+
}),
|
|
1042
|
+
onMouseDown: handleClickOutside,
|
|
1043
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1044
|
+
ref: wrapperRef,
|
|
1045
|
+
role: "dialog",
|
|
1046
|
+
"aria-modal": "true",
|
|
1047
|
+
className: clsx("im-modal-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1048
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1049
|
+
className: "sr-only",
|
|
1050
|
+
children: "Dialog"
|
|
1051
|
+
}), renderContent()]
|
|
1052
|
+
})
|
|
1053
|
+
})
|
|
1054
|
+
});
|
|
1145
1055
|
};
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
renderContent()
|
|
1384
|
-
]
|
|
1385
|
-
}
|
|
1386
|
-
)
|
|
1387
|
-
}
|
|
1388
|
-
)
|
|
1389
|
-
}
|
|
1390
|
-
);
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region src/SlideoverContent.tsx
|
|
1058
|
+
var SlideoverContent = ({ modalContext, config, useNativeDialog, isFirstModal, onAfterLeave, children }) => {
|
|
1059
|
+
const [isRendered, setIsRendered] = useState(false);
|
|
1060
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
1061
|
+
const [entered, setEntered] = useState(false);
|
|
1062
|
+
const wrapperRef = useRef(null);
|
|
1063
|
+
const dialogRef = useRef(null);
|
|
1064
|
+
const nativeWrapperRef = useRef(null);
|
|
1065
|
+
const cleanupFocusTrapRef = useRef(null);
|
|
1066
|
+
const cleanupEscapeKeyRef = useRef(null);
|
|
1067
|
+
const isLeft = config.position === "left";
|
|
1068
|
+
const maxWidthClass = useMemo(() => getMaxWidthClass(config.maxWidth), [config.maxWidth]);
|
|
1069
|
+
const getTranslateX = useCallback(() => isLeft ? "-100%" : "100%", [isLeft]);
|
|
1070
|
+
const animateIn = useCallback(async (element) => {
|
|
1071
|
+
if (!element) return;
|
|
1072
|
+
setIsVisible(true);
|
|
1073
|
+
await animate(element, [{
|
|
1074
|
+
transform: `translate3d(${getTranslateX()}, 0, 0)`,
|
|
1075
|
+
opacity: 0
|
|
1076
|
+
}, {
|
|
1077
|
+
transform: "translate3d(0, 0, 0)",
|
|
1078
|
+
opacity: 1
|
|
1079
|
+
}]);
|
|
1080
|
+
setEntered(true);
|
|
1081
|
+
}, [getTranslateX]);
|
|
1082
|
+
const animateOut = useCallback(async (element) => {
|
|
1083
|
+
if (!element) return;
|
|
1084
|
+
setIsVisible(false);
|
|
1085
|
+
await animate(element, [{
|
|
1086
|
+
transform: "translate3d(0, 0, 0)",
|
|
1087
|
+
opacity: 1
|
|
1088
|
+
}, {
|
|
1089
|
+
transform: `translate3d(${getTranslateX()}, 0, 0)`,
|
|
1090
|
+
opacity: 0
|
|
1091
|
+
}]);
|
|
1092
|
+
setIsRendered(false);
|
|
1093
|
+
if (useNativeDialog && dialogRef.current) dialogRef.current.close();
|
|
1094
|
+
onAfterLeave?.();
|
|
1095
|
+
modalContext.afterLeave();
|
|
1096
|
+
}, [
|
|
1097
|
+
getTranslateX,
|
|
1098
|
+
useNativeDialog,
|
|
1099
|
+
onAfterLeave,
|
|
1100
|
+
modalContext
|
|
1101
|
+
]);
|
|
1102
|
+
const setupFocusTrap = useCallback(() => {
|
|
1103
|
+
if (useNativeDialog) return;
|
|
1104
|
+
if (!wrapperRef.current || !modalContext.onTopOfStack) return;
|
|
1105
|
+
if (cleanupFocusTrapRef.current) return;
|
|
1106
|
+
cleanupFocusTrapRef.current = createFocusTrap(wrapperRef.current, {
|
|
1107
|
+
initialFocus: true,
|
|
1108
|
+
returnFocus: false
|
|
1109
|
+
});
|
|
1110
|
+
}, [modalContext.onTopOfStack, useNativeDialog]);
|
|
1111
|
+
const cleanupFocusTrap = useCallback(() => {
|
|
1112
|
+
if (cleanupFocusTrapRef.current) {
|
|
1113
|
+
cleanupFocusTrapRef.current();
|
|
1114
|
+
cleanupFocusTrapRef.current = null;
|
|
1115
|
+
}
|
|
1116
|
+
}, []);
|
|
1117
|
+
const setupEscapeKey = useCallback(() => {
|
|
1118
|
+
if (useNativeDialog) return;
|
|
1119
|
+
if (cleanupEscapeKeyRef.current) return;
|
|
1120
|
+
if (config?.closeExplicitly) return;
|
|
1121
|
+
cleanupEscapeKeyRef.current = onEscapeKey(() => {
|
|
1122
|
+
if (modalContext.onTopOfStack) modalContext.close();
|
|
1123
|
+
});
|
|
1124
|
+
}, [
|
|
1125
|
+
config?.closeExplicitly,
|
|
1126
|
+
modalContext,
|
|
1127
|
+
useNativeDialog
|
|
1128
|
+
]);
|
|
1129
|
+
const cleanupEscapeKey = useCallback(() => {
|
|
1130
|
+
if (cleanupEscapeKeyRef.current) {
|
|
1131
|
+
cleanupEscapeKeyRef.current();
|
|
1132
|
+
cleanupEscapeKeyRef.current = null;
|
|
1133
|
+
}
|
|
1134
|
+
}, []);
|
|
1135
|
+
const handleClickOutside = useCallback((event) => {
|
|
1136
|
+
if (useNativeDialog) return;
|
|
1137
|
+
if (!modalContext.onTopOfStack) return;
|
|
1138
|
+
if (config?.closeExplicitly) return;
|
|
1139
|
+
if (config?.closeOnClickOutside === false) return;
|
|
1140
|
+
if (!wrapperRef.current) return;
|
|
1141
|
+
if (!wrapperRef.current.contains(event.target)) modalContext.close();
|
|
1142
|
+
}, [
|
|
1143
|
+
modalContext,
|
|
1144
|
+
config?.closeExplicitly,
|
|
1145
|
+
config?.closeOnClickOutside,
|
|
1146
|
+
useNativeDialog
|
|
1147
|
+
]);
|
|
1148
|
+
const handleCancel = useCallback((event) => {
|
|
1149
|
+
event.preventDefault();
|
|
1150
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly) modalContext.close();
|
|
1151
|
+
}, [modalContext, config?.closeExplicitly]);
|
|
1152
|
+
const handleDialogClick = useCallback((event) => {
|
|
1153
|
+
if (event.target === dialogRef.current) {
|
|
1154
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly && config?.closeOnClickOutside !== false) modalContext.close();
|
|
1155
|
+
}
|
|
1156
|
+
}, [
|
|
1157
|
+
modalContext,
|
|
1158
|
+
config?.closeExplicitly,
|
|
1159
|
+
config?.closeOnClickOutside
|
|
1160
|
+
]);
|
|
1161
|
+
const prevIsOpenRef = useRef(modalContext.isOpen);
|
|
1162
|
+
useEffect(() => {
|
|
1163
|
+
if (useNativeDialog) {
|
|
1164
|
+
if (modalContext.isOpen && !dialogRef.current?.open) {
|
|
1165
|
+
dialogRef.current?.showModal();
|
|
1166
|
+
animateIn(nativeWrapperRef.current);
|
|
1167
|
+
} else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
1168
|
+
setEntered(false);
|
|
1169
|
+
animateOut(nativeWrapperRef.current);
|
|
1170
|
+
}
|
|
1171
|
+
} else if (modalContext.isOpen && !isRendered) setIsRendered(true);
|
|
1172
|
+
else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
1173
|
+
setEntered(false);
|
|
1174
|
+
animateOut(wrapperRef.current);
|
|
1175
|
+
}
|
|
1176
|
+
prevIsOpenRef.current = modalContext.isOpen;
|
|
1177
|
+
}, [
|
|
1178
|
+
modalContext.isOpen,
|
|
1179
|
+
useNativeDialog,
|
|
1180
|
+
animateIn,
|
|
1181
|
+
animateOut,
|
|
1182
|
+
isRendered
|
|
1183
|
+
]);
|
|
1184
|
+
useEffect(() => {
|
|
1185
|
+
if (!useNativeDialog && isRendered && !entered && modalContext.isOpen) animateIn(wrapperRef.current).then(() => {
|
|
1186
|
+
setupFocusTrap();
|
|
1187
|
+
});
|
|
1188
|
+
}, [
|
|
1189
|
+
isRendered,
|
|
1190
|
+
useNativeDialog,
|
|
1191
|
+
entered,
|
|
1192
|
+
modalContext.isOpen,
|
|
1193
|
+
animateIn,
|
|
1194
|
+
setupFocusTrap
|
|
1195
|
+
]);
|
|
1196
|
+
useEffect(() => {
|
|
1197
|
+
if (!useNativeDialog) setupEscapeKey();
|
|
1198
|
+
return () => {
|
|
1199
|
+
cleanupEscapeKey();
|
|
1200
|
+
};
|
|
1201
|
+
}, [
|
|
1202
|
+
useNativeDialog,
|
|
1203
|
+
setupEscapeKey,
|
|
1204
|
+
cleanupEscapeKey
|
|
1205
|
+
]);
|
|
1206
|
+
useEffect(() => {
|
|
1207
|
+
if (useNativeDialog) return;
|
|
1208
|
+
if (modalContext.onTopOfStack) {
|
|
1209
|
+
setupEscapeKey();
|
|
1210
|
+
if (entered) setupFocusTrap();
|
|
1211
|
+
} else {
|
|
1212
|
+
cleanupFocusTrap();
|
|
1213
|
+
cleanupEscapeKey();
|
|
1214
|
+
}
|
|
1215
|
+
}, [
|
|
1216
|
+
modalContext.onTopOfStack,
|
|
1217
|
+
entered,
|
|
1218
|
+
setupEscapeKey,
|
|
1219
|
+
setupFocusTrap,
|
|
1220
|
+
cleanupFocusTrap,
|
|
1221
|
+
cleanupEscapeKey,
|
|
1222
|
+
useNativeDialog
|
|
1223
|
+
]);
|
|
1224
|
+
useEffect(() => {
|
|
1225
|
+
return () => {
|
|
1226
|
+
const wrapper = useNativeDialog ? nativeWrapperRef.current : wrapperRef.current;
|
|
1227
|
+
if (wrapper) cancelAnimations(wrapper);
|
|
1228
|
+
if (useNativeDialog) {
|
|
1229
|
+
if (dialogRef.current?.open) dialogRef.current.close();
|
|
1230
|
+
} else {
|
|
1231
|
+
cleanupFocusTrap();
|
|
1232
|
+
cleanupEscapeKey();
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
}, [
|
|
1236
|
+
useNativeDialog,
|
|
1237
|
+
cleanupFocusTrap,
|
|
1238
|
+
cleanupEscapeKey
|
|
1239
|
+
]);
|
|
1240
|
+
const renderContent = () => /* @__PURE__ */ jsxs("div", {
|
|
1241
|
+
className: `im-slideover-content relative ${config.paddingClasses} ${config.panelClasses}`,
|
|
1242
|
+
"data-inertiaui-modal-entered": entered,
|
|
1243
|
+
children: [config.closeButton && /* @__PURE__ */ jsx("div", {
|
|
1244
|
+
className: "absolute top-0 right-0 pt-3 pr-3",
|
|
1245
|
+
children: /* @__PURE__ */ jsx(CloseButton, { onClick: modalContext.close })
|
|
1246
|
+
}), typeof children === "function" ? children({
|
|
1247
|
+
modalContext,
|
|
1248
|
+
config
|
|
1249
|
+
}) : children]
|
|
1250
|
+
});
|
|
1251
|
+
if (useNativeDialog) return /* @__PURE__ */ jsx("dialog", {
|
|
1252
|
+
ref: dialogRef,
|
|
1253
|
+
className: clsx("im-slideover-dialog m-0 overflow-visible bg-transparent p-0", "size-full max-h-none max-w-none", "backdrop:bg-black/75 backdrop:transition-opacity backdrop:duration-300", isVisible ? "backdrop:opacity-100" : "backdrop:opacity-0", !isFirstModal && "backdrop:bg-transparent"),
|
|
1254
|
+
onCancel: handleCancel,
|
|
1255
|
+
onClick: handleDialogClick,
|
|
1256
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1257
|
+
className: "im-slideover-container fixed inset-0 overflow-x-hidden overflow-y-auto",
|
|
1258
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1259
|
+
className: clsx("im-slideover-positioner flex min-h-full items-center", {
|
|
1260
|
+
"justify-start rtl:justify-end": config?.position === "left",
|
|
1261
|
+
"justify-end rtl:justify-start": config?.position === "right"
|
|
1262
|
+
}),
|
|
1263
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1264
|
+
ref: nativeWrapperRef,
|
|
1265
|
+
className: clsx("im-slideover-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1266
|
+
children: renderContent()
|
|
1267
|
+
})
|
|
1268
|
+
})
|
|
1269
|
+
})
|
|
1270
|
+
});
|
|
1271
|
+
if (!isRendered) return null;
|
|
1272
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1273
|
+
className: "im-slideover-container fixed inset-0 z-40 overflow-x-hidden overflow-y-auto",
|
|
1274
|
+
onMouseDown: handleClickOutside,
|
|
1275
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1276
|
+
className: clsx("im-slideover-positioner flex min-h-full items-center", {
|
|
1277
|
+
"justify-start rtl:justify-end": config?.position === "left",
|
|
1278
|
+
"justify-end rtl:justify-start": config?.position === "right"
|
|
1279
|
+
}),
|
|
1280
|
+
onMouseDown: handleClickOutside,
|
|
1281
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1282
|
+
ref: wrapperRef,
|
|
1283
|
+
role: "dialog",
|
|
1284
|
+
"aria-modal": "true",
|
|
1285
|
+
className: clsx("im-slideover-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1286
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1287
|
+
className: "sr-only",
|
|
1288
|
+
children: "Dialog"
|
|
1289
|
+
}), renderContent()]
|
|
1290
|
+
})
|
|
1291
|
+
})
|
|
1292
|
+
});
|
|
1391
1293
|
};
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
})
|
|
1497
|
-
}
|
|
1498
|
-
) : /* @__PURE__ */ jsx(
|
|
1499
|
-
ModalContent,
|
|
1500
|
-
{
|
|
1501
|
-
modalContext,
|
|
1502
|
-
config,
|
|
1503
|
-
useNativeDialog,
|
|
1504
|
-
isFirstModal: index === 0,
|
|
1505
|
-
onAfterLeave: handleAfterLeave,
|
|
1506
|
-
children: renderChildren({
|
|
1507
|
-
...extraProps,
|
|
1508
|
-
afterLeave,
|
|
1509
|
-
close,
|
|
1510
|
-
config,
|
|
1511
|
-
emit,
|
|
1512
|
-
getChildModal,
|
|
1513
|
-
getParentModal,
|
|
1514
|
-
id,
|
|
1515
|
-
index,
|
|
1516
|
-
isOpen,
|
|
1517
|
-
modalContext,
|
|
1518
|
-
onTopOfStack,
|
|
1519
|
-
reload,
|
|
1520
|
-
setOpen,
|
|
1521
|
-
shouldRender
|
|
1522
|
-
})
|
|
1523
|
-
}
|
|
1524
|
-
)
|
|
1525
|
-
]
|
|
1526
|
-
}
|
|
1527
|
-
) })
|
|
1528
|
-
}
|
|
1529
|
-
);
|
|
1530
|
-
}
|
|
1531
|
-
);
|
|
1294
|
+
//#endregion
|
|
1295
|
+
//#region src/Modal.tsx
|
|
1296
|
+
var Modal = forwardRef((allProps, ref) => {
|
|
1297
|
+
const { name, children, onFocus, onBlur, onClose, onSuccess, onAfterLeave, ...props } = allProps;
|
|
1298
|
+
const renderChildren = (contentProps) => {
|
|
1299
|
+
if (typeof children === "function") return children(contentProps);
|
|
1300
|
+
return children;
|
|
1301
|
+
};
|
|
1302
|
+
const headlessModalRef = useRef(null);
|
|
1303
|
+
const cleanupScrollLockRef = useRef(null);
|
|
1304
|
+
const cleanupAriaHiddenRef = useRef(null);
|
|
1305
|
+
const [rendered, setRendered] = useState(false);
|
|
1306
|
+
const useNativeDialog = useMemo(() => getConfig("useNativeDialog"), []);
|
|
1307
|
+
useImperativeHandle(ref, () => headlessModalRef.current, [headlessModalRef]);
|
|
1308
|
+
useEffect(() => {
|
|
1309
|
+
return () => {
|
|
1310
|
+
cleanupScrollLockRef.current?.();
|
|
1311
|
+
cleanupAriaHiddenRef.current?.();
|
|
1312
|
+
};
|
|
1313
|
+
}, []);
|
|
1314
|
+
const handleSuccess = useCallback(() => {
|
|
1315
|
+
onSuccess?.();
|
|
1316
|
+
if (!cleanupScrollLockRef.current) {
|
|
1317
|
+
cleanupScrollLockRef.current = lockScroll();
|
|
1318
|
+
cleanupAriaHiddenRef.current = markAriaHidden(getConfig("appElement"));
|
|
1319
|
+
}
|
|
1320
|
+
}, [onSuccess]);
|
|
1321
|
+
const handleClose = useCallback(() => {
|
|
1322
|
+
onClose?.();
|
|
1323
|
+
cleanupScrollLockRef.current?.();
|
|
1324
|
+
cleanupAriaHiddenRef.current?.();
|
|
1325
|
+
cleanupScrollLockRef.current = null;
|
|
1326
|
+
cleanupAriaHiddenRef.current = null;
|
|
1327
|
+
}, [onClose]);
|
|
1328
|
+
const handleAfterLeave = useCallback(() => {
|
|
1329
|
+
onAfterLeave?.();
|
|
1330
|
+
}, [onAfterLeave]);
|
|
1331
|
+
return /* @__PURE__ */ jsx(HeadlessModal, {
|
|
1332
|
+
ref: headlessModalRef,
|
|
1333
|
+
name,
|
|
1334
|
+
onFocus: onFocus ?? void 0,
|
|
1335
|
+
onBlur: onBlur ?? void 0,
|
|
1336
|
+
onClose: handleClose,
|
|
1337
|
+
onSuccess: handleSuccess,
|
|
1338
|
+
...props,
|
|
1339
|
+
children: ({ afterLeave, close, config, emit, getChildModal, getParentModal, id, index, isOpen, modalContext, onTopOfStack, reload, setOpen, shouldRender, ...extraProps }) => /* @__PURE__ */ jsx(ModalPortal, { children: /* @__PURE__ */ jsxs("div", {
|
|
1340
|
+
className: "im-dialog relative z-20",
|
|
1341
|
+
"data-inertiaui-modal-id": id,
|
|
1342
|
+
"data-inertiaui-modal-index": index,
|
|
1343
|
+
"aria-hidden": !onTopOfStack,
|
|
1344
|
+
children: [index === 0 && !useNativeDialog && /* @__PURE__ */ jsx(BackdropTransition, {
|
|
1345
|
+
show: isOpen,
|
|
1346
|
+
appear: !rendered,
|
|
1347
|
+
onAfterAppear: () => setRendered(true)
|
|
1348
|
+
}), config.slideover ? /* @__PURE__ */ jsx(SlideoverContent, {
|
|
1349
|
+
modalContext,
|
|
1350
|
+
config,
|
|
1351
|
+
useNativeDialog,
|
|
1352
|
+
isFirstModal: index === 0,
|
|
1353
|
+
onAfterLeave: handleAfterLeave,
|
|
1354
|
+
children: renderChildren({
|
|
1355
|
+
...extraProps,
|
|
1356
|
+
afterLeave,
|
|
1357
|
+
close,
|
|
1358
|
+
config,
|
|
1359
|
+
emit,
|
|
1360
|
+
getChildModal,
|
|
1361
|
+
getParentModal,
|
|
1362
|
+
id,
|
|
1363
|
+
index,
|
|
1364
|
+
isOpen,
|
|
1365
|
+
modalContext,
|
|
1366
|
+
onTopOfStack,
|
|
1367
|
+
reload,
|
|
1368
|
+
setOpen,
|
|
1369
|
+
shouldRender
|
|
1370
|
+
})
|
|
1371
|
+
}) : /* @__PURE__ */ jsx(ModalContent, {
|
|
1372
|
+
modalContext,
|
|
1373
|
+
config,
|
|
1374
|
+
useNativeDialog,
|
|
1375
|
+
isFirstModal: index === 0,
|
|
1376
|
+
onAfterLeave: handleAfterLeave,
|
|
1377
|
+
children: renderChildren({
|
|
1378
|
+
...extraProps,
|
|
1379
|
+
afterLeave,
|
|
1380
|
+
close,
|
|
1381
|
+
config,
|
|
1382
|
+
emit,
|
|
1383
|
+
getChildModal,
|
|
1384
|
+
getParentModal,
|
|
1385
|
+
id,
|
|
1386
|
+
index,
|
|
1387
|
+
isOpen,
|
|
1388
|
+
modalContext,
|
|
1389
|
+
onTopOfStack,
|
|
1390
|
+
reload,
|
|
1391
|
+
setOpen,
|
|
1392
|
+
shouldRender
|
|
1393
|
+
})
|
|
1394
|
+
})]
|
|
1395
|
+
}) })
|
|
1396
|
+
});
|
|
1397
|
+
});
|
|
1532
1398
|
function ModalPortal({ children }) {
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1399
|
+
const [mounted, setMounted] = useState(false);
|
|
1400
|
+
useEffect(() => {
|
|
1401
|
+
setMounted(true);
|
|
1402
|
+
}, []);
|
|
1403
|
+
if (!mounted) return null;
|
|
1404
|
+
return createPortal(children, document.body);
|
|
1539
1405
|
}
|
|
1540
1406
|
function BackdropTransition({ show, appear, onAfterAppear }) {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
}
|
|
1593
|
-
);
|
|
1407
|
+
const [state, setState] = useState(() => {
|
|
1408
|
+
if (appear && show) return "entering";
|
|
1409
|
+
return show ? "entered" : "exited";
|
|
1410
|
+
});
|
|
1411
|
+
const initialRender = useRef(true);
|
|
1412
|
+
const backdropRef = useRef(null);
|
|
1413
|
+
useEffect(() => {
|
|
1414
|
+
if (initialRender.current) {
|
|
1415
|
+
initialRender.current = false;
|
|
1416
|
+
if (appear && show) requestAnimationFrame(() => {
|
|
1417
|
+
setState("entered");
|
|
1418
|
+
const backdrop = backdropRef.current;
|
|
1419
|
+
if (backdrop) {
|
|
1420
|
+
const onTransitionEnd = (e) => {
|
|
1421
|
+
if (e.target !== backdrop) return;
|
|
1422
|
+
backdrop.removeEventListener("transitionend", onTransitionEnd);
|
|
1423
|
+
onAfterAppear?.();
|
|
1424
|
+
};
|
|
1425
|
+
backdrop.addEventListener("transitionend", onTransitionEnd);
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
if (show) {
|
|
1431
|
+
setState("entering");
|
|
1432
|
+
requestAnimationFrame(() => {
|
|
1433
|
+
setState("entered");
|
|
1434
|
+
});
|
|
1435
|
+
} else {
|
|
1436
|
+
setState("leaving");
|
|
1437
|
+
const backdrop = backdropRef.current;
|
|
1438
|
+
if (backdrop) {
|
|
1439
|
+
const onTransitionEnd = (e) => {
|
|
1440
|
+
if (e.target !== backdrop) return;
|
|
1441
|
+
backdrop.removeEventListener("transitionend", onTransitionEnd);
|
|
1442
|
+
setState("exited");
|
|
1443
|
+
};
|
|
1444
|
+
backdrop.addEventListener("transitionend", onTransitionEnd);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
}, [
|
|
1448
|
+
show,
|
|
1449
|
+
appear,
|
|
1450
|
+
onAfterAppear
|
|
1451
|
+
]);
|
|
1452
|
+
if (state === "exited") return null;
|
|
1453
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1454
|
+
ref: backdropRef,
|
|
1455
|
+
className: `im-backdrop fixed inset-0 z-30 bg-black/75 transition-opacity duration-300 ease-in-out ${state === "entered" ? "opacity-100" : "opacity-0"}`,
|
|
1456
|
+
"aria-hidden": "true"
|
|
1457
|
+
});
|
|
1594
1458
|
}
|
|
1595
1459
|
Modal.displayName = "Modal";
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
onAfterLeave?.();
|
|
1714
|
-
}, [onAfterLeave]);
|
|
1715
|
-
const handle = useCallback(
|
|
1716
|
-
(e) => {
|
|
1717
|
-
e?.preventDefault();
|
|
1718
|
-
if (loading) return;
|
|
1719
|
-
if (!href.startsWith("#")) {
|
|
1720
|
-
setLoading(true);
|
|
1721
|
-
onStart?.();
|
|
1722
|
-
}
|
|
1723
|
-
visit(
|
|
1724
|
-
href,
|
|
1725
|
-
method,
|
|
1726
|
-
data,
|
|
1727
|
-
headers,
|
|
1728
|
-
rejectNullValues(only(props, modalPropNames)),
|
|
1729
|
-
() => onCloseCallback(),
|
|
1730
|
-
onAfterLeaveCallback,
|
|
1731
|
-
queryStringArrayFormat,
|
|
1732
|
-
shouldNavigate
|
|
1733
|
-
).then((newModalContext) => {
|
|
1734
|
-
setModalContext(newModalContext);
|
|
1735
|
-
newModalContext.registerEventListenersFromProps(customEvents);
|
|
1736
|
-
onSuccess?.();
|
|
1737
|
-
}).catch((error) => {
|
|
1738
|
-
console.error(error);
|
|
1739
|
-
onError?.(error);
|
|
1740
|
-
}).finally(() => setLoading(false));
|
|
1741
|
-
},
|
|
1742
|
-
[href, method, data, headers, queryStringArrayFormat, props, onCloseCallback, onAfterLeaveCallback]
|
|
1743
|
-
);
|
|
1744
|
-
return /* @__PURE__ */ jsx(
|
|
1745
|
-
Component,
|
|
1746
|
-
{
|
|
1747
|
-
...standardProps,
|
|
1748
|
-
href,
|
|
1749
|
-
onClick: handle,
|
|
1750
|
-
onMouseEnter: handleMouseEnter,
|
|
1751
|
-
onMouseLeave: handleMouseLeave,
|
|
1752
|
-
onMouseDown: handleMouseDown,
|
|
1753
|
-
children: typeof children === "function" ? children({ loading }) : children
|
|
1754
|
-
}
|
|
1755
|
-
);
|
|
1460
|
+
//#endregion
|
|
1461
|
+
//#region src/ModalLink.tsx
|
|
1462
|
+
var ModalLink = ({ href, method = "get", data = {}, as: Component = "a", headers = {}, queryStringArrayFormat = "brackets", onAfterLeave, onBlur, onClose, onError, onFocus, onStart, onSuccess, onPrefetching, onPrefetched, navigate, prefetch: prefetch$1 = false, cacheFor = 3e4, children, ...props }) => {
|
|
1463
|
+
const [loading, setLoading] = useState(false);
|
|
1464
|
+
const [modalContext, setModalContext] = useState(null);
|
|
1465
|
+
const { stack, visit } = useModalStack();
|
|
1466
|
+
const hoverTimeout = useRef(null);
|
|
1467
|
+
const shouldNavigate = useMemo(() => {
|
|
1468
|
+
return navigate ?? getConfig("navigate");
|
|
1469
|
+
}, [navigate]);
|
|
1470
|
+
const prefetchModes = useMemo(() => {
|
|
1471
|
+
if (prefetch$1 === true) return ["hover"];
|
|
1472
|
+
if (prefetch$1 === false) return [];
|
|
1473
|
+
if (Array.isArray(prefetch$1)) return prefetch$1;
|
|
1474
|
+
return [prefetch$1];
|
|
1475
|
+
}, [prefetch$1]);
|
|
1476
|
+
const doPrefetch = useCallback(() => {
|
|
1477
|
+
prefetch(href, {
|
|
1478
|
+
method,
|
|
1479
|
+
data,
|
|
1480
|
+
headers,
|
|
1481
|
+
queryStringArrayFormat,
|
|
1482
|
+
cacheFor,
|
|
1483
|
+
onPrefetching: onPrefetching ?? void 0,
|
|
1484
|
+
onPrefetched: onPrefetched ?? void 0
|
|
1485
|
+
});
|
|
1486
|
+
}, [
|
|
1487
|
+
href,
|
|
1488
|
+
method,
|
|
1489
|
+
data,
|
|
1490
|
+
headers,
|
|
1491
|
+
queryStringArrayFormat,
|
|
1492
|
+
cacheFor,
|
|
1493
|
+
onPrefetching,
|
|
1494
|
+
onPrefetched
|
|
1495
|
+
]);
|
|
1496
|
+
const handleMouseEnter = useCallback(() => {
|
|
1497
|
+
if (!prefetchModes.includes("hover")) return;
|
|
1498
|
+
hoverTimeout.current = setTimeout(() => {
|
|
1499
|
+
doPrefetch();
|
|
1500
|
+
}, 75);
|
|
1501
|
+
}, [prefetchModes, doPrefetch]);
|
|
1502
|
+
const handleMouseLeave = useCallback(() => {
|
|
1503
|
+
if (hoverTimeout.current) {
|
|
1504
|
+
clearTimeout(hoverTimeout.current);
|
|
1505
|
+
hoverTimeout.current = null;
|
|
1506
|
+
}
|
|
1507
|
+
}, []);
|
|
1508
|
+
const handleMouseDown = useCallback((event) => {
|
|
1509
|
+
if (!prefetchModes.includes("click")) return;
|
|
1510
|
+
if (event.button !== 0) return;
|
|
1511
|
+
doPrefetch();
|
|
1512
|
+
}, [prefetchModes, doPrefetch]);
|
|
1513
|
+
useEffect(() => {
|
|
1514
|
+
if (prefetchModes.includes("mount")) doPrefetch();
|
|
1515
|
+
}, []);
|
|
1516
|
+
useEffect(() => {
|
|
1517
|
+
return () => {
|
|
1518
|
+
if (hoverTimeout.current) clearTimeout(hoverTimeout.current);
|
|
1519
|
+
};
|
|
1520
|
+
}, []);
|
|
1521
|
+
const standardProps = {};
|
|
1522
|
+
const customEvents = {};
|
|
1523
|
+
Object.keys(props).forEach((key) => {
|
|
1524
|
+
if (modalPropNames.includes(key)) return;
|
|
1525
|
+
if (key.startsWith("on") && typeof props[key] === "function") if (isStandardDomEvent(key)) standardProps[key] = props[key];
|
|
1526
|
+
else customEvents[key] = props[key];
|
|
1527
|
+
else standardProps[key] = props[key];
|
|
1528
|
+
});
|
|
1529
|
+
const [isBlurred, setIsBlurred] = useState(false);
|
|
1530
|
+
useEffect(() => {
|
|
1531
|
+
if (!modalContext) return;
|
|
1532
|
+
if (modalContext.onTopOfStack && isBlurred) onFocus?.();
|
|
1533
|
+
else if (!modalContext.onTopOfStack && !isBlurred) onBlur?.();
|
|
1534
|
+
setIsBlurred(!modalContext.onTopOfStack);
|
|
1535
|
+
}, [stack]);
|
|
1536
|
+
const onCloseCallback = useCallback(() => {
|
|
1537
|
+
onClose?.();
|
|
1538
|
+
}, [onClose]);
|
|
1539
|
+
const onAfterLeaveCallback = useCallback(() => {
|
|
1540
|
+
setModalContext(null);
|
|
1541
|
+
onAfterLeave?.();
|
|
1542
|
+
}, [onAfterLeave]);
|
|
1543
|
+
const handle = useCallback((e) => {
|
|
1544
|
+
e?.preventDefault();
|
|
1545
|
+
if (loading) return;
|
|
1546
|
+
if (!href.startsWith("#")) {
|
|
1547
|
+
setLoading(true);
|
|
1548
|
+
onStart?.();
|
|
1549
|
+
}
|
|
1550
|
+
visit(href, method, data, headers, rejectNullValues(only(props, modalPropNames)), () => onCloseCallback(), onAfterLeaveCallback, queryStringArrayFormat, shouldNavigate).then((newModalContext) => {
|
|
1551
|
+
setModalContext(newModalContext);
|
|
1552
|
+
newModalContext.registerEventListenersFromProps(customEvents);
|
|
1553
|
+
onSuccess?.();
|
|
1554
|
+
}).catch((error) => {
|
|
1555
|
+
console.error(error);
|
|
1556
|
+
onError?.(error);
|
|
1557
|
+
}).finally(() => setLoading(false));
|
|
1558
|
+
}, [
|
|
1559
|
+
href,
|
|
1560
|
+
method,
|
|
1561
|
+
data,
|
|
1562
|
+
headers,
|
|
1563
|
+
queryStringArrayFormat,
|
|
1564
|
+
props,
|
|
1565
|
+
onCloseCallback,
|
|
1566
|
+
onAfterLeaveCallback
|
|
1567
|
+
]);
|
|
1568
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
1569
|
+
...standardProps,
|
|
1570
|
+
href,
|
|
1571
|
+
onClick: handle,
|
|
1572
|
+
onMouseEnter: handleMouseEnter,
|
|
1573
|
+
onMouseLeave: handleMouseLeave,
|
|
1574
|
+
onMouseDown: handleMouseDown,
|
|
1575
|
+
children: typeof children === "function" ? children({ loading }) : children
|
|
1576
|
+
});
|
|
1756
1577
|
};
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
},
|
|
1811
|
-
{
|
|
1812
|
-
rootMargin: `${buffer || 0}px`
|
|
1813
|
-
}
|
|
1814
|
-
);
|
|
1815
|
-
observer.observe(ref.current);
|
|
1816
|
-
return () => {
|
|
1817
|
-
observer.disconnect();
|
|
1818
|
-
};
|
|
1819
|
-
}, [ref, getReloadParams, buffer]);
|
|
1820
|
-
if (always || !loaded) {
|
|
1821
|
-
return createElement(
|
|
1822
|
-
as,
|
|
1823
|
-
{
|
|
1824
|
-
props: null,
|
|
1825
|
-
ref
|
|
1826
|
-
},
|
|
1827
|
-
loaded ? children : fallback
|
|
1828
|
-
);
|
|
1829
|
-
}
|
|
1830
|
-
return loaded ? children : null;
|
|
1578
|
+
//#endregion
|
|
1579
|
+
//#region src/WhenVisible.tsx
|
|
1580
|
+
var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
|
|
1581
|
+
always = always ?? false;
|
|
1582
|
+
as = as ?? "div";
|
|
1583
|
+
fallback = fallback ?? null;
|
|
1584
|
+
const [loaded, setLoaded] = useState(false);
|
|
1585
|
+
const hasFetched = useRef(false);
|
|
1586
|
+
const fetching = useRef(false);
|
|
1587
|
+
const ref = useRef(null);
|
|
1588
|
+
const modal = useModal();
|
|
1589
|
+
const getReloadParams = useCallback(() => {
|
|
1590
|
+
if (data) return { only: Array.isArray(data) ? data : [data] };
|
|
1591
|
+
if (!params) throw new Error("You must provide either a `data` or `params` prop.");
|
|
1592
|
+
return params;
|
|
1593
|
+
}, [params, data]);
|
|
1594
|
+
useEffect(() => {
|
|
1595
|
+
if (!ref.current) return;
|
|
1596
|
+
const observer = new IntersectionObserver((entries) => {
|
|
1597
|
+
if (!entries[0].isIntersecting) return;
|
|
1598
|
+
if (!always && hasFetched.current) observer.disconnect();
|
|
1599
|
+
if (fetching.current) return;
|
|
1600
|
+
hasFetched.current = true;
|
|
1601
|
+
fetching.current = true;
|
|
1602
|
+
const reloadParams = getReloadParams();
|
|
1603
|
+
modal?.reload({
|
|
1604
|
+
...reloadParams,
|
|
1605
|
+
onStart: () => {
|
|
1606
|
+
fetching.current = true;
|
|
1607
|
+
reloadParams.onStart?.();
|
|
1608
|
+
},
|
|
1609
|
+
onFinish: () => {
|
|
1610
|
+
setLoaded(true);
|
|
1611
|
+
fetching.current = false;
|
|
1612
|
+
reloadParams.onFinish?.();
|
|
1613
|
+
if (!always) observer.disconnect();
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
}, { rootMargin: `${buffer || 0}px` });
|
|
1617
|
+
observer.observe(ref.current);
|
|
1618
|
+
return () => {
|
|
1619
|
+
observer.disconnect();
|
|
1620
|
+
};
|
|
1621
|
+
}, [
|
|
1622
|
+
ref,
|
|
1623
|
+
getReloadParams,
|
|
1624
|
+
buffer
|
|
1625
|
+
]);
|
|
1626
|
+
if (always || !loaded) return createElement(as, {
|
|
1627
|
+
props: null,
|
|
1628
|
+
ref
|
|
1629
|
+
}, loaded ? children : fallback);
|
|
1630
|
+
return loaded ? children : null;
|
|
1831
1631
|
};
|
|
1832
1632
|
WhenVisible.displayName = "InertiaWhenVisible";
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
};
|
|
1837
|
-
|
|
1838
|
-
Deferred,
|
|
1839
|
-
HeadlessModal,
|
|
1840
|
-
Modal,
|
|
1841
|
-
ModalLink,
|
|
1842
|
-
ModalRoot,
|
|
1843
|
-
ModalStackProvider,
|
|
1844
|
-
WhenVisible,
|
|
1845
|
-
vanilla as dialogUtils,
|
|
1846
|
-
getConfig,
|
|
1847
|
-
initFromPageProps,
|
|
1848
|
-
modalPropNames,
|
|
1849
|
-
prefetch,
|
|
1850
|
-
putConfig,
|
|
1851
|
-
renderApp,
|
|
1852
|
-
resetConfig,
|
|
1853
|
-
setPageLayout,
|
|
1854
|
-
useModal,
|
|
1855
|
-
useModalIndex,
|
|
1856
|
-
useModalStack
|
|
1633
|
+
//#endregion
|
|
1634
|
+
//#region src/inertiauiModal.ts
|
|
1635
|
+
var setPageLayout = (layout) => (module) => {
|
|
1636
|
+
module.default.layout = (page) => createElement(layout, { children: page });
|
|
1637
|
+
return module;
|
|
1857
1638
|
};
|
|
1858
|
-
//#
|
|
1639
|
+
//#endregion
|
|
1640
|
+
export { Deferred, HeadlessModal, Modal, ModalLink, ModalRoot, ModalStackProvider, WhenVisible, dialogUtils, getConfig, initFromPageProps, modalPropNames, prefetch, putConfig, renderApp, resetConfig, setPageLayout, useModal, useModalIndex, useModalStack };
|
|
1641
|
+
|
|
1642
|
+
//# sourceMappingURL=inertiaui-modal.js.map
|