@inertiajs/react 2.3.16 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +986 -532
- package/dist/index.js.map +4 -4
- package/dist/server.js +4 -35
- package/dist/server.js.map +2 -2
- package/package.json +12 -13
- package/resources/boost/guidelines/core.blade.php +3 -0
- package/resources/boost/skills/inertia-react-development/SKILL.blade.php +362 -0
- package/types/App.d.ts +3 -2
- package/types/Deferred.d.ts +4 -1
- package/types/Form.d.ts +10 -19
- package/types/InfiniteScroll.d.ts +2 -1
- package/types/createInertiaApp.d.ts +15 -4
- package/types/index.d.ts +6 -15
- package/types/layoutProps.d.ts +8 -0
- package/types/react.d.ts +0 -1
- package/types/types.d.ts +3 -1
- package/types/useForm.d.ts +10 -12
- package/types/useFormState.d.ts +79 -0
- package/types/useHttp.d.ts +65 -0
- package/dist/index.esm.js +0 -1651
- package/dist/index.esm.js.map +0 -7
- package/dist/server.esm.js +0 -6
- package/dist/server.esm.js.map +0 -7
package/dist/index.esm.js
DELETED
|
@@ -1,1651 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { config as coreConfig, progress as Progress2, router as Router } from "@inertiajs/core";
|
|
3
|
-
|
|
4
|
-
// src/App.ts
|
|
5
|
-
import {
|
|
6
|
-
createHeadManager,
|
|
7
|
-
router
|
|
8
|
-
} from "@inertiajs/core";
|
|
9
|
-
import { createElement, useEffect, useMemo, useState } from "react";
|
|
10
|
-
import { flushSync } from "react-dom";
|
|
11
|
-
|
|
12
|
-
// src/HeadContext.ts
|
|
13
|
-
import { createContext } from "react";
|
|
14
|
-
var headContext = createContext(null);
|
|
15
|
-
headContext.displayName = "InertiaHeadContext";
|
|
16
|
-
var HeadContext_default = headContext;
|
|
17
|
-
|
|
18
|
-
// src/PageContext.ts
|
|
19
|
-
import { createContext as createContext2 } from "react";
|
|
20
|
-
var pageContext = createContext2(null);
|
|
21
|
-
pageContext.displayName = "InertiaPageContext";
|
|
22
|
-
var PageContext_default = pageContext;
|
|
23
|
-
|
|
24
|
-
// src/App.ts
|
|
25
|
-
var currentIsInitialPage = true;
|
|
26
|
-
var routerIsInitialized = false;
|
|
27
|
-
var swapComponent = async () => {
|
|
28
|
-
currentIsInitialPage = false;
|
|
29
|
-
};
|
|
30
|
-
function App({
|
|
31
|
-
children,
|
|
32
|
-
initialPage,
|
|
33
|
-
initialComponent,
|
|
34
|
-
resolveComponent,
|
|
35
|
-
titleCallback,
|
|
36
|
-
onHeadUpdate
|
|
37
|
-
}) {
|
|
38
|
-
const [current, setCurrent] = useState({
|
|
39
|
-
component: initialComponent || null,
|
|
40
|
-
page: { ...initialPage, flash: initialPage.flash ?? {} },
|
|
41
|
-
key: null
|
|
42
|
-
});
|
|
43
|
-
const headManager = useMemo(() => {
|
|
44
|
-
return createHeadManager(
|
|
45
|
-
typeof window === "undefined",
|
|
46
|
-
titleCallback || ((title) => title),
|
|
47
|
-
onHeadUpdate || (() => {
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
}, []);
|
|
51
|
-
if (!routerIsInitialized) {
|
|
52
|
-
router.init({
|
|
53
|
-
initialPage,
|
|
54
|
-
resolveComponent,
|
|
55
|
-
swapComponent: async (args) => swapComponent(args),
|
|
56
|
-
onFlash: (flash) => {
|
|
57
|
-
setCurrent((current2) => ({
|
|
58
|
-
...current2,
|
|
59
|
-
page: { ...current2.page, flash }
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
routerIsInitialized = true;
|
|
64
|
-
}
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
swapComponent = async ({ component, page, preserveState }) => {
|
|
67
|
-
if (currentIsInitialPage) {
|
|
68
|
-
currentIsInitialPage = false;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
flushSync(
|
|
72
|
-
() => setCurrent((current2) => ({
|
|
73
|
-
component,
|
|
74
|
-
page,
|
|
75
|
-
key: preserveState ? current2.key : Date.now()
|
|
76
|
-
}))
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
router.on("navigate", () => headManager.forceUpdate());
|
|
80
|
-
}, []);
|
|
81
|
-
if (!current.component) {
|
|
82
|
-
return createElement(
|
|
83
|
-
HeadContext_default.Provider,
|
|
84
|
-
{ value: headManager },
|
|
85
|
-
createElement(PageContext_default.Provider, { value: current.page }, null)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const renderChildren = children || (({ Component, props, key }) => {
|
|
89
|
-
const child = createElement(Component, { key, ...props });
|
|
90
|
-
if (typeof Component.layout === "function") {
|
|
91
|
-
return Component.layout(child);
|
|
92
|
-
}
|
|
93
|
-
if (Array.isArray(Component.layout)) {
|
|
94
|
-
return Component.layout.concat(child).reverse().reduce((children2, Layout) => createElement(Layout, { children: children2, ...props }));
|
|
95
|
-
}
|
|
96
|
-
return child;
|
|
97
|
-
});
|
|
98
|
-
return createElement(
|
|
99
|
-
HeadContext_default.Provider,
|
|
100
|
-
{ value: headManager },
|
|
101
|
-
createElement(
|
|
102
|
-
PageContext_default.Provider,
|
|
103
|
-
{ value: current.page },
|
|
104
|
-
renderChildren({
|
|
105
|
-
Component: current.component,
|
|
106
|
-
key: current.key,
|
|
107
|
-
props: current.page.props
|
|
108
|
-
})
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
App.displayName = "Inertia";
|
|
113
|
-
|
|
114
|
-
// src/createInertiaApp.ts
|
|
115
|
-
import {
|
|
116
|
-
getInitialPageFromDOM,
|
|
117
|
-
router as router2,
|
|
118
|
-
setupProgress
|
|
119
|
-
} from "@inertiajs/core";
|
|
120
|
-
import { createElement as createElement2, Fragment } from "react";
|
|
121
|
-
async function createInertiaApp({
|
|
122
|
-
id = "app",
|
|
123
|
-
resolve,
|
|
124
|
-
setup,
|
|
125
|
-
title,
|
|
126
|
-
progress: progress2 = {},
|
|
127
|
-
page,
|
|
128
|
-
render,
|
|
129
|
-
defaults = {}
|
|
130
|
-
}) {
|
|
131
|
-
config.replace(defaults);
|
|
132
|
-
const isServer = typeof window === "undefined";
|
|
133
|
-
const useScriptElementForInitialPage = config.get("future.useScriptElementForInitialPage");
|
|
134
|
-
const initialPage = page || getInitialPageFromDOM(id, useScriptElementForInitialPage);
|
|
135
|
-
const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module) => module.default || module);
|
|
136
|
-
let head = [];
|
|
137
|
-
const reactApp = await Promise.all([
|
|
138
|
-
resolveComponent(initialPage.component),
|
|
139
|
-
router2.decryptHistory().catch(() => {
|
|
140
|
-
})
|
|
141
|
-
]).then(([initialComponent]) => {
|
|
142
|
-
const props = {
|
|
143
|
-
initialPage,
|
|
144
|
-
initialComponent,
|
|
145
|
-
resolveComponent,
|
|
146
|
-
titleCallback: title
|
|
147
|
-
};
|
|
148
|
-
if (isServer) {
|
|
149
|
-
const ssrSetup = setup;
|
|
150
|
-
return ssrSetup({
|
|
151
|
-
el: null,
|
|
152
|
-
App,
|
|
153
|
-
props: { ...props, onHeadUpdate: (elements) => head = elements }
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
const csrSetup = setup;
|
|
157
|
-
return csrSetup({
|
|
158
|
-
el: document.getElementById(id),
|
|
159
|
-
App,
|
|
160
|
-
props
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
if (!isServer && progress2) {
|
|
164
|
-
setupProgress(progress2);
|
|
165
|
-
}
|
|
166
|
-
if (isServer && render) {
|
|
167
|
-
const element = () => {
|
|
168
|
-
if (!useScriptElementForInitialPage) {
|
|
169
|
-
return createElement2(
|
|
170
|
-
"div",
|
|
171
|
-
{
|
|
172
|
-
id,
|
|
173
|
-
"data-page": JSON.stringify(initialPage)
|
|
174
|
-
},
|
|
175
|
-
reactApp
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
return createElement2(
|
|
179
|
-
Fragment,
|
|
180
|
-
null,
|
|
181
|
-
createElement2("script", {
|
|
182
|
-
"data-page": id,
|
|
183
|
-
type: "application/json",
|
|
184
|
-
dangerouslySetInnerHTML: { __html: JSON.stringify(initialPage).replace(/\//g, "\\/") }
|
|
185
|
-
}),
|
|
186
|
-
createElement2("div", { id }, reactApp)
|
|
187
|
-
);
|
|
188
|
-
};
|
|
189
|
-
const body = await render(element());
|
|
190
|
-
return { head, body };
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// src/Deferred.ts
|
|
195
|
-
import { useEffect as useEffect3, useMemo as useMemo2, useState as useState2 } from "react";
|
|
196
|
-
|
|
197
|
-
// src/usePage.ts
|
|
198
|
-
import React2 from "react";
|
|
199
|
-
|
|
200
|
-
// src/react.ts
|
|
201
|
-
import React, { useEffect as useEffect2, useLayoutEffect } from "react";
|
|
202
|
-
function useIsomorphicLayoutEffect(effect, deps) {
|
|
203
|
-
typeof window === "undefined" ? useEffect2(effect, deps) : useLayoutEffect(effect, deps);
|
|
204
|
-
}
|
|
205
|
-
var isReact19 = typeof React.use === "function";
|
|
206
|
-
|
|
207
|
-
// src/usePage.ts
|
|
208
|
-
function usePage() {
|
|
209
|
-
const page = isReact19 ? React2.use(PageContext_default) : React2.useContext(PageContext_default);
|
|
210
|
-
if (!page) {
|
|
211
|
-
throw new Error("usePage must be used within the Inertia component");
|
|
212
|
-
}
|
|
213
|
-
return page;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// src/Deferred.ts
|
|
217
|
-
var urlWithoutHash = (url) => {
|
|
218
|
-
url = new URL(url.href);
|
|
219
|
-
url.hash = "";
|
|
220
|
-
return url;
|
|
221
|
-
};
|
|
222
|
-
var isSameUrlWithoutHash = (url1, url2) => {
|
|
223
|
-
return urlWithoutHash(url1).href === urlWithoutHash(url2).href;
|
|
224
|
-
};
|
|
225
|
-
var Deferred = ({ children, data, fallback }) => {
|
|
226
|
-
if (!data) {
|
|
227
|
-
throw new Error("`<Deferred>` requires a `data` prop to be a string or array of strings");
|
|
228
|
-
}
|
|
229
|
-
const [loaded, setLoaded] = useState2(false);
|
|
230
|
-
const pageProps = usePage().props;
|
|
231
|
-
const keys = useMemo2(() => Array.isArray(data) ? data : [data], [data]);
|
|
232
|
-
useEffect3(() => {
|
|
233
|
-
const removeListener = router3.on("start", (e) => {
|
|
234
|
-
const isPartialVisit = e.detail.visit.only.length > 0 || e.detail.visit.except.length > 0;
|
|
235
|
-
const isReloadingKey = e.detail.visit.only.find((key) => keys.includes(key));
|
|
236
|
-
if (isSameUrlWithoutHash(e.detail.visit.url, window.location) && (!isPartialVisit || isReloadingKey)) {
|
|
237
|
-
setLoaded(false);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
return () => {
|
|
241
|
-
removeListener();
|
|
242
|
-
};
|
|
243
|
-
}, []);
|
|
244
|
-
useEffect3(() => {
|
|
245
|
-
setLoaded(keys.every((key) => pageProps[key] !== void 0));
|
|
246
|
-
}, [pageProps, keys]);
|
|
247
|
-
const propsAreDefined = useMemo2(() => keys.every((key) => pageProps[key] !== void 0), [keys, pageProps]);
|
|
248
|
-
if (loaded && propsAreDefined) {
|
|
249
|
-
return typeof children === "function" ? children() : children;
|
|
250
|
-
}
|
|
251
|
-
return typeof fallback === "function" ? fallback() : fallback;
|
|
252
|
-
};
|
|
253
|
-
Deferred.displayName = "InertiaDeferred";
|
|
254
|
-
var Deferred_default = Deferred;
|
|
255
|
-
|
|
256
|
-
// src/Form.ts
|
|
257
|
-
import {
|
|
258
|
-
config as config2,
|
|
259
|
-
FormComponentResetSymbol,
|
|
260
|
-
formDataToObject,
|
|
261
|
-
isUrlMethodPair,
|
|
262
|
-
mergeDataIntoQueryString,
|
|
263
|
-
resetFormFields,
|
|
264
|
-
UseFormUtils as UseFormUtils2
|
|
265
|
-
} from "@inertiajs/core";
|
|
266
|
-
import { isEqual as isEqual2 } from "lodash-es";
|
|
267
|
-
import React3, {
|
|
268
|
-
createContext as createContext3,
|
|
269
|
-
createElement as createElement3,
|
|
270
|
-
forwardRef,
|
|
271
|
-
useContext,
|
|
272
|
-
useEffect as useEffect6,
|
|
273
|
-
useImperativeHandle,
|
|
274
|
-
useMemo as useMemo4,
|
|
275
|
-
useRef as useRef2,
|
|
276
|
-
useState as useState5
|
|
277
|
-
} from "react";
|
|
278
|
-
|
|
279
|
-
// src/useForm.ts
|
|
280
|
-
import {
|
|
281
|
-
router as router5,
|
|
282
|
-
UseFormUtils
|
|
283
|
-
} from "@inertiajs/core";
|
|
284
|
-
import {
|
|
285
|
-
createValidator,
|
|
286
|
-
resolveName,
|
|
287
|
-
toSimpleValidationErrors
|
|
288
|
-
} from "laravel-precognition";
|
|
289
|
-
import { cloneDeep, get, has, isEqual, set } from "lodash-es";
|
|
290
|
-
import { useCallback, useEffect as useEffect5, useMemo as useMemo3, useRef, useState as useState4 } from "react";
|
|
291
|
-
|
|
292
|
-
// src/useRemember.ts
|
|
293
|
-
import { router as router4 } from "@inertiajs/core";
|
|
294
|
-
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
295
|
-
function useRemember(initialState, key, excludeKeysRef) {
|
|
296
|
-
const [state, setState] = useState3(() => {
|
|
297
|
-
const restored = router4.restore(key);
|
|
298
|
-
return restored !== void 0 ? restored : initialState;
|
|
299
|
-
});
|
|
300
|
-
useEffect4(() => {
|
|
301
|
-
const keys = excludeKeysRef?.current;
|
|
302
|
-
if (keys && keys.length > 0 && typeof state === "object" && state !== null) {
|
|
303
|
-
const filtered = { ...state };
|
|
304
|
-
keys.forEach((k) => delete filtered[k]);
|
|
305
|
-
router4.remember(filtered, key);
|
|
306
|
-
} else {
|
|
307
|
-
router4.remember(state, key);
|
|
308
|
-
}
|
|
309
|
-
}, [state, key]);
|
|
310
|
-
return [state, setState];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// src/useForm.ts
|
|
314
|
-
function useForm(...args) {
|
|
315
|
-
const isMounted = useRef(false);
|
|
316
|
-
const parsedArgs = UseFormUtils.parseUseFormArguments(...args);
|
|
317
|
-
const { rememberKey, data: initialData } = parsedArgs;
|
|
318
|
-
const precognitionEndpoint = useRef(parsedArgs.precognitionEndpoint);
|
|
319
|
-
const [defaults, setDefaults] = useState4(
|
|
320
|
-
typeof initialData === "function" ? cloneDeep(initialData()) : cloneDeep(initialData)
|
|
321
|
-
);
|
|
322
|
-
const cancelToken = useRef(null);
|
|
323
|
-
const recentlySuccessfulTimeoutId = useRef(void 0);
|
|
324
|
-
const excludeKeysRef = useRef([]);
|
|
325
|
-
const [data, setData] = rememberKey ? useRemember(defaults, `${rememberKey}:data`, excludeKeysRef) : useState4(defaults);
|
|
326
|
-
const [errors, setErrors] = rememberKey ? useRemember({}, `${rememberKey}:errors`) : useState4({});
|
|
327
|
-
const [hasErrors, setHasErrors] = useState4(false);
|
|
328
|
-
const [processing, setProcessing] = useState4(false);
|
|
329
|
-
const [progress2, setProgress] = useState4(null);
|
|
330
|
-
const [wasSuccessful, setWasSuccessful] = useState4(false);
|
|
331
|
-
const [recentlySuccessful, setRecentlySuccessful] = useState4(false);
|
|
332
|
-
const transform = useRef((data2) => data2);
|
|
333
|
-
const isDirty = useMemo3(() => !isEqual(data, defaults), [data, defaults]);
|
|
334
|
-
const validatorRef = useRef(null);
|
|
335
|
-
const [validating, setValidating] = useState4(false);
|
|
336
|
-
const [touchedFields, setTouchedFields] = useState4([]);
|
|
337
|
-
const [validFields, setValidFields] = useState4([]);
|
|
338
|
-
const withAllErrors = useRef(null);
|
|
339
|
-
useEffect5(() => {
|
|
340
|
-
isMounted.current = true;
|
|
341
|
-
return () => {
|
|
342
|
-
isMounted.current = false;
|
|
343
|
-
};
|
|
344
|
-
}, []);
|
|
345
|
-
const setDefaultsCalledInOnSuccess = useRef(false);
|
|
346
|
-
const submit = useCallback(
|
|
347
|
-
(...args2) => {
|
|
348
|
-
const { method, url, options } = UseFormUtils.parseSubmitArguments(args2, precognitionEndpoint.current);
|
|
349
|
-
setDefaultsCalledInOnSuccess.current = false;
|
|
350
|
-
const _options = {
|
|
351
|
-
...options,
|
|
352
|
-
onCancelToken: (token) => {
|
|
353
|
-
cancelToken.current = token;
|
|
354
|
-
if (options.onCancelToken) {
|
|
355
|
-
return options.onCancelToken(token);
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
onBefore: (visit) => {
|
|
359
|
-
setWasSuccessful(false);
|
|
360
|
-
setRecentlySuccessful(false);
|
|
361
|
-
clearTimeout(recentlySuccessfulTimeoutId.current);
|
|
362
|
-
if (options.onBefore) {
|
|
363
|
-
return options.onBefore(visit);
|
|
364
|
-
}
|
|
365
|
-
},
|
|
366
|
-
onStart: (visit) => {
|
|
367
|
-
setProcessing(true);
|
|
368
|
-
if (options.onStart) {
|
|
369
|
-
return options.onStart(visit);
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
onProgress: (event) => {
|
|
373
|
-
setProgress(event || null);
|
|
374
|
-
if (options.onProgress) {
|
|
375
|
-
return options.onProgress(event);
|
|
376
|
-
}
|
|
377
|
-
},
|
|
378
|
-
onSuccess: async (page) => {
|
|
379
|
-
if (isMounted.current) {
|
|
380
|
-
setProcessing(false);
|
|
381
|
-
setProgress(null);
|
|
382
|
-
setErrors({});
|
|
383
|
-
setHasErrors(false);
|
|
384
|
-
setWasSuccessful(true);
|
|
385
|
-
setRecentlySuccessful(true);
|
|
386
|
-
recentlySuccessfulTimeoutId.current = setTimeout(() => {
|
|
387
|
-
if (isMounted.current) {
|
|
388
|
-
setRecentlySuccessful(false);
|
|
389
|
-
}
|
|
390
|
-
}, config.get("form.recentlySuccessfulDuration"));
|
|
391
|
-
}
|
|
392
|
-
const onSuccess = options.onSuccess ? await options.onSuccess(page) : null;
|
|
393
|
-
if (isMounted.current && !setDefaultsCalledInOnSuccess.current) {
|
|
394
|
-
setData((data2) => {
|
|
395
|
-
setDefaults(cloneDeep(data2));
|
|
396
|
-
return data2;
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
return onSuccess;
|
|
400
|
-
},
|
|
401
|
-
onError: (errors2) => {
|
|
402
|
-
if (isMounted.current) {
|
|
403
|
-
setProcessing(false);
|
|
404
|
-
setProgress(null);
|
|
405
|
-
setErrors(errors2);
|
|
406
|
-
setHasErrors(Object.keys(errors2).length > 0);
|
|
407
|
-
validatorRef.current?.setErrors(errors2);
|
|
408
|
-
}
|
|
409
|
-
if (options.onError) {
|
|
410
|
-
return options.onError(errors2);
|
|
411
|
-
}
|
|
412
|
-
},
|
|
413
|
-
onCancel: () => {
|
|
414
|
-
if (isMounted.current) {
|
|
415
|
-
setProcessing(false);
|
|
416
|
-
setProgress(null);
|
|
417
|
-
}
|
|
418
|
-
if (options.onCancel) {
|
|
419
|
-
return options.onCancel();
|
|
420
|
-
}
|
|
421
|
-
},
|
|
422
|
-
onFinish: (visit) => {
|
|
423
|
-
if (isMounted.current) {
|
|
424
|
-
setProcessing(false);
|
|
425
|
-
setProgress(null);
|
|
426
|
-
}
|
|
427
|
-
cancelToken.current = null;
|
|
428
|
-
if (options.onFinish) {
|
|
429
|
-
return options.onFinish(visit);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
const transformedData = transform.current(data);
|
|
434
|
-
if (method === "delete") {
|
|
435
|
-
router5.delete(url, { ..._options, data: transformedData });
|
|
436
|
-
} else {
|
|
437
|
-
router5[method](url, transformedData, _options);
|
|
438
|
-
}
|
|
439
|
-
},
|
|
440
|
-
[data, setErrors, transform]
|
|
441
|
-
);
|
|
442
|
-
const setDataFunction = useCallback(
|
|
443
|
-
(keyOrData, maybeValue) => {
|
|
444
|
-
if (typeof keyOrData === "string") {
|
|
445
|
-
setData((data2) => set(cloneDeep(data2), keyOrData, maybeValue));
|
|
446
|
-
} else if (typeof keyOrData === "function") {
|
|
447
|
-
setData((data2) => keyOrData(data2));
|
|
448
|
-
} else {
|
|
449
|
-
setData(keyOrData);
|
|
450
|
-
}
|
|
451
|
-
},
|
|
452
|
-
[setData]
|
|
453
|
-
);
|
|
454
|
-
const [dataAsDefaults, setDataAsDefaults] = useState4(false);
|
|
455
|
-
const dataRef = useRef(data);
|
|
456
|
-
useEffect5(() => {
|
|
457
|
-
dataRef.current = data;
|
|
458
|
-
});
|
|
459
|
-
const setDefaultsFunction = useCallback(
|
|
460
|
-
(fieldOrFields, maybeValue) => {
|
|
461
|
-
setDefaultsCalledInOnSuccess.current = true;
|
|
462
|
-
let newDefaults = {};
|
|
463
|
-
if (typeof fieldOrFields === "undefined") {
|
|
464
|
-
newDefaults = { ...dataRef.current };
|
|
465
|
-
setDefaults(dataRef.current);
|
|
466
|
-
setDataAsDefaults(true);
|
|
467
|
-
} else {
|
|
468
|
-
setDefaults((defaults2) => {
|
|
469
|
-
newDefaults = typeof fieldOrFields === "string" ? set(cloneDeep(defaults2), fieldOrFields, maybeValue) : Object.assign(cloneDeep(defaults2), fieldOrFields);
|
|
470
|
-
return newDefaults;
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
validatorRef.current?.defaults(newDefaults);
|
|
474
|
-
},
|
|
475
|
-
[setDefaults]
|
|
476
|
-
);
|
|
477
|
-
useIsomorphicLayoutEffect(() => {
|
|
478
|
-
if (!dataAsDefaults) {
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
if (isDirty) {
|
|
482
|
-
setDefaults(data);
|
|
483
|
-
}
|
|
484
|
-
setDataAsDefaults(false);
|
|
485
|
-
}, [dataAsDefaults]);
|
|
486
|
-
const reset = useCallback(
|
|
487
|
-
(...fields) => {
|
|
488
|
-
if (fields.length === 0) {
|
|
489
|
-
setData(defaults);
|
|
490
|
-
} else {
|
|
491
|
-
setData(
|
|
492
|
-
(data2) => fields.filter((key) => has(defaults, key)).reduce(
|
|
493
|
-
(carry, key) => {
|
|
494
|
-
return set(carry, key, get(defaults, key));
|
|
495
|
-
},
|
|
496
|
-
{ ...data2 }
|
|
497
|
-
)
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
validatorRef.current?.reset(...fields);
|
|
501
|
-
},
|
|
502
|
-
[setData, defaults]
|
|
503
|
-
);
|
|
504
|
-
const setError = useCallback(
|
|
505
|
-
(fieldOrFields, maybeValue) => {
|
|
506
|
-
setErrors((errors2) => {
|
|
507
|
-
const newErrors = {
|
|
508
|
-
...errors2,
|
|
509
|
-
...typeof fieldOrFields === "string" ? { [fieldOrFields]: maybeValue } : fieldOrFields
|
|
510
|
-
};
|
|
511
|
-
setHasErrors(Object.keys(newErrors).length > 0);
|
|
512
|
-
validatorRef.current?.setErrors(newErrors);
|
|
513
|
-
return newErrors;
|
|
514
|
-
});
|
|
515
|
-
},
|
|
516
|
-
[setErrors, setHasErrors]
|
|
517
|
-
);
|
|
518
|
-
const clearErrors = useCallback(
|
|
519
|
-
(...fields) => {
|
|
520
|
-
setErrors((errors2) => {
|
|
521
|
-
const newErrors = Object.keys(errors2).reduce(
|
|
522
|
-
(carry, field) => ({
|
|
523
|
-
...carry,
|
|
524
|
-
...fields.length > 0 && !fields.includes(field) ? { [field]: errors2[field] } : {}
|
|
525
|
-
}),
|
|
526
|
-
{}
|
|
527
|
-
);
|
|
528
|
-
setHasErrors(Object.keys(newErrors).length > 0);
|
|
529
|
-
if (validatorRef.current) {
|
|
530
|
-
if (fields.length === 0) {
|
|
531
|
-
validatorRef.current.setErrors({});
|
|
532
|
-
} else {
|
|
533
|
-
fields.forEach(validatorRef.current.forgetError);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
return newErrors;
|
|
537
|
-
});
|
|
538
|
-
},
|
|
539
|
-
[setErrors, setHasErrors]
|
|
540
|
-
);
|
|
541
|
-
const resetAndClearErrors = useCallback(
|
|
542
|
-
(...fields) => {
|
|
543
|
-
reset(...fields);
|
|
544
|
-
clearErrors(...fields);
|
|
545
|
-
},
|
|
546
|
-
[reset, clearErrors]
|
|
547
|
-
);
|
|
548
|
-
const createSubmitMethod = (method) => (url, options = {}) => {
|
|
549
|
-
submit(method, url, options);
|
|
550
|
-
};
|
|
551
|
-
const getMethod = useCallback(createSubmitMethod("get"), [submit]);
|
|
552
|
-
const post = useCallback(createSubmitMethod("post"), [submit]);
|
|
553
|
-
const put = useCallback(createSubmitMethod("put"), [submit]);
|
|
554
|
-
const patch = useCallback(createSubmitMethod("patch"), [submit]);
|
|
555
|
-
const deleteMethod = useCallback(createSubmitMethod("delete"), [submit]);
|
|
556
|
-
const cancel = useCallback(() => {
|
|
557
|
-
if (cancelToken.current) {
|
|
558
|
-
cancelToken.current.cancel();
|
|
559
|
-
}
|
|
560
|
-
}, []);
|
|
561
|
-
const transformFunction = useCallback((callback) => {
|
|
562
|
-
transform.current = callback;
|
|
563
|
-
}, []);
|
|
564
|
-
const form = {
|
|
565
|
-
data,
|
|
566
|
-
setData: setDataFunction,
|
|
567
|
-
isDirty,
|
|
568
|
-
errors,
|
|
569
|
-
hasErrors,
|
|
570
|
-
processing,
|
|
571
|
-
progress: progress2,
|
|
572
|
-
wasSuccessful,
|
|
573
|
-
recentlySuccessful,
|
|
574
|
-
transform: transformFunction,
|
|
575
|
-
setDefaults: setDefaultsFunction,
|
|
576
|
-
reset,
|
|
577
|
-
setError,
|
|
578
|
-
clearErrors,
|
|
579
|
-
resetAndClearErrors,
|
|
580
|
-
submit,
|
|
581
|
-
get: getMethod,
|
|
582
|
-
post,
|
|
583
|
-
put,
|
|
584
|
-
patch,
|
|
585
|
-
delete: deleteMethod,
|
|
586
|
-
cancel,
|
|
587
|
-
dontRemember: (...keys) => {
|
|
588
|
-
excludeKeysRef.current = keys;
|
|
589
|
-
return form;
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
const tap = (value, callback) => {
|
|
593
|
-
callback(value);
|
|
594
|
-
return value;
|
|
595
|
-
};
|
|
596
|
-
const valid = useCallback(
|
|
597
|
-
(field) => validFields.includes(field),
|
|
598
|
-
[validFields]
|
|
599
|
-
);
|
|
600
|
-
const invalid = useCallback((field) => field in errors, [errors]);
|
|
601
|
-
const touched = useCallback(
|
|
602
|
-
(field) => typeof field === "string" ? touchedFields.includes(field) : touchedFields.length > 0,
|
|
603
|
-
[touchedFields]
|
|
604
|
-
);
|
|
605
|
-
const validate = (field, config3) => {
|
|
606
|
-
if (typeof field === "object" && !("target" in field)) {
|
|
607
|
-
config3 = field;
|
|
608
|
-
field = void 0;
|
|
609
|
-
}
|
|
610
|
-
if (field === void 0) {
|
|
611
|
-
validatorRef.current.validate(config3);
|
|
612
|
-
} else {
|
|
613
|
-
const fieldName = resolveName(field);
|
|
614
|
-
const currentData = dataRef.current;
|
|
615
|
-
const transformedData = transform.current(currentData);
|
|
616
|
-
validatorRef.current.validate(fieldName, get(transformedData, fieldName), config3);
|
|
617
|
-
}
|
|
618
|
-
return form;
|
|
619
|
-
};
|
|
620
|
-
const withPrecognition = (...args2) => {
|
|
621
|
-
precognitionEndpoint.current = UseFormUtils.createWayfinderCallback(...args2);
|
|
622
|
-
if (!validatorRef.current) {
|
|
623
|
-
const validator = createValidator((client) => {
|
|
624
|
-
const { method, url } = precognitionEndpoint.current();
|
|
625
|
-
const currentData = dataRef.current;
|
|
626
|
-
const transformedData = transform.current(currentData);
|
|
627
|
-
return client[method](url, transformedData);
|
|
628
|
-
}, cloneDeep(defaults));
|
|
629
|
-
validatorRef.current = validator;
|
|
630
|
-
validator.on("validatingChanged", () => {
|
|
631
|
-
setValidating(validator.validating());
|
|
632
|
-
}).on("validatedChanged", () => {
|
|
633
|
-
setValidFields(validator.valid());
|
|
634
|
-
}).on("touchedChanged", () => {
|
|
635
|
-
setTouchedFields(validator.touched());
|
|
636
|
-
}).on("errorsChanged", () => {
|
|
637
|
-
const validationErrors = withAllErrors.current ?? config.get("form.withAllErrors") ? validator.errors() : toSimpleValidationErrors(validator.errors());
|
|
638
|
-
setErrors(validationErrors);
|
|
639
|
-
setHasErrors(Object.keys(validationErrors).length > 0);
|
|
640
|
-
setValidFields(validator.valid());
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
const precognitiveForm = Object.assign(form, {
|
|
644
|
-
validating,
|
|
645
|
-
validator: () => validatorRef.current,
|
|
646
|
-
valid,
|
|
647
|
-
invalid,
|
|
648
|
-
touched,
|
|
649
|
-
withoutFileValidation: () => tap(precognitiveForm, () => validatorRef.current?.withoutFileValidation()),
|
|
650
|
-
touch: (field, ...fields) => {
|
|
651
|
-
if (Array.isArray(field)) {
|
|
652
|
-
validatorRef.current?.touch(field);
|
|
653
|
-
} else if (typeof field === "string") {
|
|
654
|
-
validatorRef.current?.touch([field, ...fields]);
|
|
655
|
-
} else {
|
|
656
|
-
validatorRef.current?.touch(field);
|
|
657
|
-
}
|
|
658
|
-
return precognitiveForm;
|
|
659
|
-
},
|
|
660
|
-
withAllErrors: () => tap(precognitiveForm, () => withAllErrors.current = true),
|
|
661
|
-
setValidationTimeout: (duration) => tap(precognitiveForm, () => validatorRef.current?.setTimeout(duration)),
|
|
662
|
-
validateFiles: () => tap(precognitiveForm, () => validatorRef.current?.validateFiles()),
|
|
663
|
-
validate,
|
|
664
|
-
setErrors: (errors2) => tap(precognitiveForm, () => form.setError(errors2)),
|
|
665
|
-
forgetError: (field) => tap(
|
|
666
|
-
precognitiveForm,
|
|
667
|
-
() => form.clearErrors(resolveName(field))
|
|
668
|
-
)
|
|
669
|
-
});
|
|
670
|
-
return precognitiveForm;
|
|
671
|
-
};
|
|
672
|
-
form.withPrecognition = withPrecognition;
|
|
673
|
-
return precognitionEndpoint.current ? form.withPrecognition(precognitionEndpoint.current) : form;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// src/Form.ts
|
|
677
|
-
var deferStateUpdate = (callback) => {
|
|
678
|
-
typeof React3.startTransition === "function" ? React3.startTransition(callback) : setTimeout(callback, 0);
|
|
679
|
-
};
|
|
680
|
-
var noop = () => void 0;
|
|
681
|
-
var FormContext = createContext3(void 0);
|
|
682
|
-
var Form = forwardRef(
|
|
683
|
-
({
|
|
684
|
-
action = "",
|
|
685
|
-
method = "get",
|
|
686
|
-
headers = {},
|
|
687
|
-
queryStringArrayFormat = "brackets",
|
|
688
|
-
errorBag = null,
|
|
689
|
-
showProgress = true,
|
|
690
|
-
transform = (data) => data,
|
|
691
|
-
options = {},
|
|
692
|
-
onStart = noop,
|
|
693
|
-
onProgress = noop,
|
|
694
|
-
onFinish = noop,
|
|
695
|
-
onBefore = noop,
|
|
696
|
-
onCancel = noop,
|
|
697
|
-
onSuccess = noop,
|
|
698
|
-
onError = noop,
|
|
699
|
-
onCancelToken = noop,
|
|
700
|
-
onSubmitComplete = noop,
|
|
701
|
-
disableWhileProcessing = false,
|
|
702
|
-
resetOnError = false,
|
|
703
|
-
resetOnSuccess = false,
|
|
704
|
-
setDefaultsOnSuccess = false,
|
|
705
|
-
invalidateCacheTags = [],
|
|
706
|
-
validateFiles = false,
|
|
707
|
-
validationTimeout = 1500,
|
|
708
|
-
withAllErrors = null,
|
|
709
|
-
children,
|
|
710
|
-
...props
|
|
711
|
-
}, ref) => {
|
|
712
|
-
const getTransformedData = () => {
|
|
713
|
-
const [_url, data] = getUrlAndData();
|
|
714
|
-
return transform(data);
|
|
715
|
-
};
|
|
716
|
-
const form = useForm({}).withPrecognition(
|
|
717
|
-
() => resolvedMethod,
|
|
718
|
-
() => getUrlAndData()[0]
|
|
719
|
-
).setValidationTimeout(validationTimeout);
|
|
720
|
-
if (validateFiles) {
|
|
721
|
-
form.validateFiles();
|
|
722
|
-
}
|
|
723
|
-
if (withAllErrors ?? config2.get("form.withAllErrors")) {
|
|
724
|
-
form.withAllErrors();
|
|
725
|
-
}
|
|
726
|
-
form.transform(getTransformedData);
|
|
727
|
-
const formElement = useRef2(void 0);
|
|
728
|
-
const resolvedMethod = useMemo4(() => {
|
|
729
|
-
return isUrlMethodPair(action) ? action.method : method.toLowerCase();
|
|
730
|
-
}, [action, method]);
|
|
731
|
-
const [isDirty, setIsDirty] = useState5(false);
|
|
732
|
-
const defaultData = useRef2(new FormData());
|
|
733
|
-
const getFormData = (submitter) => new FormData(formElement.current, submitter);
|
|
734
|
-
const getData = (submitter) => formDataToObject(getFormData(submitter));
|
|
735
|
-
const getUrlAndData = (submitter) => {
|
|
736
|
-
return mergeDataIntoQueryString(
|
|
737
|
-
resolvedMethod,
|
|
738
|
-
isUrlMethodPair(action) ? action.url : action,
|
|
739
|
-
getData(submitter),
|
|
740
|
-
queryStringArrayFormat
|
|
741
|
-
);
|
|
742
|
-
};
|
|
743
|
-
const updateDirtyState = (event) => {
|
|
744
|
-
if (event.type === "reset" && event.detail?.[FormComponentResetSymbol]) {
|
|
745
|
-
event.preventDefault();
|
|
746
|
-
}
|
|
747
|
-
deferStateUpdate(
|
|
748
|
-
() => setIsDirty(event.type === "reset" ? false : !isEqual2(getData(), formDataToObject(defaultData.current)))
|
|
749
|
-
);
|
|
750
|
-
};
|
|
751
|
-
const clearErrors = (...names) => {
|
|
752
|
-
form.clearErrors(...names);
|
|
753
|
-
return form;
|
|
754
|
-
};
|
|
755
|
-
useEffect6(() => {
|
|
756
|
-
defaultData.current = getFormData();
|
|
757
|
-
form.setDefaults(getData());
|
|
758
|
-
const formEvents = ["input", "change", "reset"];
|
|
759
|
-
formEvents.forEach((e) => formElement.current.addEventListener(e, updateDirtyState));
|
|
760
|
-
return () => {
|
|
761
|
-
formEvents.forEach((e) => formElement.current?.removeEventListener(e, updateDirtyState));
|
|
762
|
-
};
|
|
763
|
-
}, []);
|
|
764
|
-
useEffect6(() => {
|
|
765
|
-
form.setValidationTimeout(validationTimeout);
|
|
766
|
-
}, [validationTimeout]);
|
|
767
|
-
useEffect6(() => {
|
|
768
|
-
if (validateFiles) {
|
|
769
|
-
form.validateFiles();
|
|
770
|
-
} else {
|
|
771
|
-
form.withoutFileValidation();
|
|
772
|
-
}
|
|
773
|
-
}, [validateFiles]);
|
|
774
|
-
const reset = (...fields) => {
|
|
775
|
-
if (formElement.current) {
|
|
776
|
-
resetFormFields(formElement.current, defaultData.current, fields);
|
|
777
|
-
}
|
|
778
|
-
form.reset(...fields);
|
|
779
|
-
};
|
|
780
|
-
const resetAndClearErrors = (...fields) => {
|
|
781
|
-
clearErrors(...fields);
|
|
782
|
-
reset(...fields);
|
|
783
|
-
};
|
|
784
|
-
const maybeReset = (resetOption) => {
|
|
785
|
-
if (!resetOption) {
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
|
-
if (resetOption === true) {
|
|
789
|
-
reset();
|
|
790
|
-
} else if (resetOption.length > 0) {
|
|
791
|
-
reset(...resetOption);
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
const submit = (submitter) => {
|
|
795
|
-
const [url, data] = getUrlAndData(submitter);
|
|
796
|
-
const formTarget = submitter?.getAttribute("formtarget");
|
|
797
|
-
if (formTarget === "_blank" && resolvedMethod === "get") {
|
|
798
|
-
window.open(url, "_blank");
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
const submitOptions = {
|
|
802
|
-
headers,
|
|
803
|
-
queryStringArrayFormat,
|
|
804
|
-
errorBag,
|
|
805
|
-
showProgress,
|
|
806
|
-
invalidateCacheTags,
|
|
807
|
-
onCancelToken,
|
|
808
|
-
onBefore,
|
|
809
|
-
onStart,
|
|
810
|
-
onProgress,
|
|
811
|
-
onFinish,
|
|
812
|
-
onCancel,
|
|
813
|
-
onSuccess: (...args) => {
|
|
814
|
-
onSuccess(...args);
|
|
815
|
-
onSubmitComplete({
|
|
816
|
-
reset,
|
|
817
|
-
defaults
|
|
818
|
-
});
|
|
819
|
-
maybeReset(resetOnSuccess);
|
|
820
|
-
if (setDefaultsOnSuccess === true) {
|
|
821
|
-
defaults();
|
|
822
|
-
}
|
|
823
|
-
},
|
|
824
|
-
onError(...args) {
|
|
825
|
-
onError(...args);
|
|
826
|
-
maybeReset(resetOnError);
|
|
827
|
-
},
|
|
828
|
-
...options
|
|
829
|
-
};
|
|
830
|
-
form.transform(() => transform(data));
|
|
831
|
-
form.submit(resolvedMethod, url, submitOptions);
|
|
832
|
-
form.transform(getTransformedData);
|
|
833
|
-
};
|
|
834
|
-
const defaults = () => {
|
|
835
|
-
defaultData.current = getFormData();
|
|
836
|
-
setIsDirty(false);
|
|
837
|
-
};
|
|
838
|
-
const exposed = {
|
|
839
|
-
errors: form.errors,
|
|
840
|
-
hasErrors: form.hasErrors,
|
|
841
|
-
processing: form.processing,
|
|
842
|
-
progress: form.progress,
|
|
843
|
-
wasSuccessful: form.wasSuccessful,
|
|
844
|
-
recentlySuccessful: form.recentlySuccessful,
|
|
845
|
-
isDirty,
|
|
846
|
-
clearErrors,
|
|
847
|
-
resetAndClearErrors,
|
|
848
|
-
setError: form.setError,
|
|
849
|
-
reset,
|
|
850
|
-
submit,
|
|
851
|
-
defaults,
|
|
852
|
-
getData,
|
|
853
|
-
getFormData,
|
|
854
|
-
// Precognition
|
|
855
|
-
validator: () => form.validator(),
|
|
856
|
-
validating: form.validating,
|
|
857
|
-
valid: form.valid,
|
|
858
|
-
invalid: form.invalid,
|
|
859
|
-
validate: (field, config3) => form.validate(...UseFormUtils2.mergeHeadersForValidation(field, config3, headers)),
|
|
860
|
-
touch: form.touch,
|
|
861
|
-
touched: form.touched
|
|
862
|
-
};
|
|
863
|
-
useImperativeHandle(ref, () => exposed, [form, isDirty, submit]);
|
|
864
|
-
const formNode = createElement3(
|
|
865
|
-
"form",
|
|
866
|
-
{
|
|
867
|
-
...props,
|
|
868
|
-
ref: formElement,
|
|
869
|
-
action: isUrlMethodPair(action) ? action.url : action,
|
|
870
|
-
method: resolvedMethod,
|
|
871
|
-
onSubmit: (event) => {
|
|
872
|
-
event.preventDefault();
|
|
873
|
-
submit(event.nativeEvent.submitter);
|
|
874
|
-
},
|
|
875
|
-
// React 19 supports passing a boolean to the `inert` attribute, but shows
|
|
876
|
-
// a warning when receiving a string. Earlier versions require the string 'true'.
|
|
877
|
-
// See: https://github.com/inertiajs/inertia/pull/2536
|
|
878
|
-
inert: disableWhileProcessing && form.processing && (isReact19 ? true : "true")
|
|
879
|
-
},
|
|
880
|
-
typeof children === "function" ? children(exposed) : children
|
|
881
|
-
);
|
|
882
|
-
return createElement3(FormContext.Provider, { value: exposed }, formNode);
|
|
883
|
-
}
|
|
884
|
-
);
|
|
885
|
-
Form.displayName = "InertiaForm";
|
|
886
|
-
function useFormContext() {
|
|
887
|
-
return useContext(FormContext);
|
|
888
|
-
}
|
|
889
|
-
var Form_default = Form;
|
|
890
|
-
|
|
891
|
-
// src/Head.ts
|
|
892
|
-
import { escape } from "lodash-es";
|
|
893
|
-
import React4, { useContext as useContext2, useEffect as useEffect7, useMemo as useMemo5 } from "react";
|
|
894
|
-
var Head = function({ children, title }) {
|
|
895
|
-
const headManager = useContext2(HeadContext_default);
|
|
896
|
-
const provider = useMemo5(() => headManager.createProvider(), [headManager]);
|
|
897
|
-
const isServer = typeof window === "undefined";
|
|
898
|
-
useEffect7(() => {
|
|
899
|
-
provider.reconnect();
|
|
900
|
-
provider.update(renderNodes(children));
|
|
901
|
-
return () => {
|
|
902
|
-
provider.disconnect();
|
|
903
|
-
};
|
|
904
|
-
}, [provider, children, title]);
|
|
905
|
-
function isUnaryTag(node) {
|
|
906
|
-
return typeof node.type === "string" && [
|
|
907
|
-
"area",
|
|
908
|
-
"base",
|
|
909
|
-
"br",
|
|
910
|
-
"col",
|
|
911
|
-
"embed",
|
|
912
|
-
"hr",
|
|
913
|
-
"img",
|
|
914
|
-
"input",
|
|
915
|
-
"keygen",
|
|
916
|
-
"link",
|
|
917
|
-
"meta",
|
|
918
|
-
"param",
|
|
919
|
-
"source",
|
|
920
|
-
"track",
|
|
921
|
-
"wbr"
|
|
922
|
-
].indexOf(node.type) > -1;
|
|
923
|
-
}
|
|
924
|
-
function renderTagStart(node) {
|
|
925
|
-
const attrs = Object.keys(node.props).reduce((carry, name) => {
|
|
926
|
-
if (["head-key", "children", "dangerouslySetInnerHTML"].includes(name)) {
|
|
927
|
-
return carry;
|
|
928
|
-
}
|
|
929
|
-
const value = String(node.props[name]);
|
|
930
|
-
if (value === "") {
|
|
931
|
-
return carry + ` ${name}`;
|
|
932
|
-
}
|
|
933
|
-
return carry + ` ${name}="${escape(value)}"`;
|
|
934
|
-
}, "");
|
|
935
|
-
return `<${String(node.type)}${attrs}>`;
|
|
936
|
-
}
|
|
937
|
-
function renderTagChildren(node) {
|
|
938
|
-
const { children: children2 } = node.props;
|
|
939
|
-
if (typeof children2 === "string") {
|
|
940
|
-
return children2;
|
|
941
|
-
}
|
|
942
|
-
if (Array.isArray(children2)) {
|
|
943
|
-
return children2.reduce((html, child) => html + renderTag(child), "");
|
|
944
|
-
}
|
|
945
|
-
return "";
|
|
946
|
-
}
|
|
947
|
-
function renderTag(node) {
|
|
948
|
-
let html = renderTagStart(node);
|
|
949
|
-
if (node.props.children) {
|
|
950
|
-
html += renderTagChildren(node);
|
|
951
|
-
}
|
|
952
|
-
if (node.props.dangerouslySetInnerHTML) {
|
|
953
|
-
html += node.props.dangerouslySetInnerHTML.__html;
|
|
954
|
-
}
|
|
955
|
-
if (!isUnaryTag(node)) {
|
|
956
|
-
html += `</${String(node.type)}>`;
|
|
957
|
-
}
|
|
958
|
-
return html;
|
|
959
|
-
}
|
|
960
|
-
function ensureNodeHasInertiaProp(node) {
|
|
961
|
-
return React4.cloneElement(node, {
|
|
962
|
-
[provider.preferredAttribute()]: node.props["head-key"] !== void 0 ? node.props["head-key"] : ""
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
function renderNode(node) {
|
|
966
|
-
return renderTag(ensureNodeHasInertiaProp(node));
|
|
967
|
-
}
|
|
968
|
-
function renderNodes(nodes) {
|
|
969
|
-
const elements = React4.Children.toArray(nodes).filter((node) => node).map((node) => renderNode(node));
|
|
970
|
-
if (title && !elements.find((tag) => tag.startsWith("<title"))) {
|
|
971
|
-
elements.push(`<title ${provider.preferredAttribute()}>${title}</title>`);
|
|
972
|
-
}
|
|
973
|
-
return elements;
|
|
974
|
-
}
|
|
975
|
-
if (isServer) {
|
|
976
|
-
provider.update(renderNodes(children));
|
|
977
|
-
}
|
|
978
|
-
return null;
|
|
979
|
-
};
|
|
980
|
-
var Head_default = Head;
|
|
981
|
-
|
|
982
|
-
// src/InfiniteScroll.ts
|
|
983
|
-
import {
|
|
984
|
-
getScrollableParent,
|
|
985
|
-
useInfiniteScroll
|
|
986
|
-
} from "@inertiajs/core";
|
|
987
|
-
import React5, {
|
|
988
|
-
createElement as createElement4,
|
|
989
|
-
forwardRef as forwardRef2,
|
|
990
|
-
useCallback as useCallback2,
|
|
991
|
-
useEffect as useEffect8,
|
|
992
|
-
useImperativeHandle as useImperativeHandle2,
|
|
993
|
-
useMemo as useMemo6,
|
|
994
|
-
useRef as useRef3,
|
|
995
|
-
useState as useState6
|
|
996
|
-
} from "react";
|
|
997
|
-
var resolveHTMLElement = (value, fallback) => {
|
|
998
|
-
if (!value) {
|
|
999
|
-
return fallback;
|
|
1000
|
-
}
|
|
1001
|
-
if (value && typeof value === "object" && "current" in value) {
|
|
1002
|
-
return value.current;
|
|
1003
|
-
}
|
|
1004
|
-
if (typeof value === "string") {
|
|
1005
|
-
return document.querySelector(value);
|
|
1006
|
-
}
|
|
1007
|
-
return fallback;
|
|
1008
|
-
};
|
|
1009
|
-
var renderSlot = (slotContent, slotProps, fallback = null) => {
|
|
1010
|
-
if (!slotContent) {
|
|
1011
|
-
return fallback;
|
|
1012
|
-
}
|
|
1013
|
-
return typeof slotContent === "function" ? slotContent(slotProps) : slotContent;
|
|
1014
|
-
};
|
|
1015
|
-
var InfiniteScroll = forwardRef2(
|
|
1016
|
-
({
|
|
1017
|
-
data,
|
|
1018
|
-
buffer = 0,
|
|
1019
|
-
as = "div",
|
|
1020
|
-
manual = false,
|
|
1021
|
-
manualAfter = 0,
|
|
1022
|
-
preserveUrl = false,
|
|
1023
|
-
reverse = false,
|
|
1024
|
-
autoScroll,
|
|
1025
|
-
children,
|
|
1026
|
-
startElement,
|
|
1027
|
-
endElement,
|
|
1028
|
-
itemsElement,
|
|
1029
|
-
previous,
|
|
1030
|
-
next,
|
|
1031
|
-
loading,
|
|
1032
|
-
onlyNext = false,
|
|
1033
|
-
onlyPrevious = false,
|
|
1034
|
-
...props
|
|
1035
|
-
}, ref) => {
|
|
1036
|
-
const [startElementFromRef, setStartElementFromRef] = useState6(null);
|
|
1037
|
-
const startElementRef = useCallback2((node) => setStartElementFromRef(node), []);
|
|
1038
|
-
const [endElementFromRef, setEndElementFromRef] = useState6(null);
|
|
1039
|
-
const endElementRef = useCallback2((node) => setEndElementFromRef(node), []);
|
|
1040
|
-
const [itemsElementFromRef, setItemsElementFromRef] = useState6(null);
|
|
1041
|
-
const itemsElementRef = useCallback2((node) => setItemsElementFromRef(node), []);
|
|
1042
|
-
const [loadingPrevious, setLoadingPrevious] = useState6(false);
|
|
1043
|
-
const [loadingNext, setLoadingNext] = useState6(false);
|
|
1044
|
-
const [requestCount, setRequestCount] = useState6(0);
|
|
1045
|
-
const [hasPreviousPage, setHasPreviousPage] = useState6(false);
|
|
1046
|
-
const [hasNextPage, setHasNextPage] = useState6(false);
|
|
1047
|
-
const [resolvedStartElement, setResolvedStartElement] = useState6(null);
|
|
1048
|
-
const [resolvedEndElement, setResolvedEndElement] = useState6(null);
|
|
1049
|
-
const [resolvedItemsElement, setResolvedItemsElement] = useState6(null);
|
|
1050
|
-
useEffect8(() => {
|
|
1051
|
-
const element = startElement ? resolveHTMLElement(startElement, startElementFromRef) : startElementFromRef;
|
|
1052
|
-
setResolvedStartElement(element);
|
|
1053
|
-
}, [startElement, startElementFromRef]);
|
|
1054
|
-
useEffect8(() => {
|
|
1055
|
-
const element = endElement ? resolveHTMLElement(endElement, endElementFromRef) : endElementFromRef;
|
|
1056
|
-
setResolvedEndElement(element);
|
|
1057
|
-
}, [endElement, endElementFromRef]);
|
|
1058
|
-
useEffect8(() => {
|
|
1059
|
-
const element = itemsElement ? resolveHTMLElement(itemsElement, itemsElementFromRef) : itemsElementFromRef;
|
|
1060
|
-
setResolvedItemsElement(element);
|
|
1061
|
-
}, [itemsElement, itemsElementFromRef]);
|
|
1062
|
-
const scrollableParent = useMemo6(() => getScrollableParent(resolvedItemsElement), [resolvedItemsElement]);
|
|
1063
|
-
const callbackPropsRef = useRef3({
|
|
1064
|
-
buffer,
|
|
1065
|
-
onlyNext,
|
|
1066
|
-
onlyPrevious,
|
|
1067
|
-
reverse,
|
|
1068
|
-
preserveUrl
|
|
1069
|
-
});
|
|
1070
|
-
callbackPropsRef.current = {
|
|
1071
|
-
buffer,
|
|
1072
|
-
onlyNext,
|
|
1073
|
-
onlyPrevious,
|
|
1074
|
-
reverse,
|
|
1075
|
-
preserveUrl
|
|
1076
|
-
};
|
|
1077
|
-
const [infiniteScroll, setInfiniteScroll] = useState6(null);
|
|
1078
|
-
const dataManager = useMemo6(() => infiniteScroll?.dataManager, [infiniteScroll]);
|
|
1079
|
-
const elementManager = useMemo6(() => infiniteScroll?.elementManager, [infiniteScroll]);
|
|
1080
|
-
const scrollToBottom = useCallback2(() => {
|
|
1081
|
-
if (scrollableParent) {
|
|
1082
|
-
scrollableParent.scrollTo({
|
|
1083
|
-
top: scrollableParent.scrollHeight,
|
|
1084
|
-
behavior: "instant"
|
|
1085
|
-
});
|
|
1086
|
-
} else {
|
|
1087
|
-
window.scrollTo({
|
|
1088
|
-
top: document.body.scrollHeight,
|
|
1089
|
-
behavior: "instant"
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
}, [scrollableParent]);
|
|
1093
|
-
useEffect8(() => {
|
|
1094
|
-
if (!resolvedItemsElement) {
|
|
1095
|
-
return;
|
|
1096
|
-
}
|
|
1097
|
-
function syncStateFromDataManager() {
|
|
1098
|
-
setRequestCount(infiniteScrollInstance.dataManager.getRequestCount());
|
|
1099
|
-
setHasPreviousPage(infiniteScrollInstance.dataManager.hasPrevious());
|
|
1100
|
-
setHasNextPage(infiniteScrollInstance.dataManager.hasNext());
|
|
1101
|
-
}
|
|
1102
|
-
const infiniteScrollInstance = useInfiniteScroll({
|
|
1103
|
-
// Data
|
|
1104
|
-
getPropName: () => data,
|
|
1105
|
-
inReverseMode: () => callbackPropsRef.current.reverse,
|
|
1106
|
-
shouldFetchNext: () => !callbackPropsRef.current.onlyPrevious,
|
|
1107
|
-
shouldFetchPrevious: () => !callbackPropsRef.current.onlyNext,
|
|
1108
|
-
shouldPreserveUrl: () => callbackPropsRef.current.preserveUrl,
|
|
1109
|
-
// Elements
|
|
1110
|
-
getTriggerMargin: () => callbackPropsRef.current.buffer,
|
|
1111
|
-
getStartElement: () => resolvedStartElement,
|
|
1112
|
-
getEndElement: () => resolvedEndElement,
|
|
1113
|
-
getItemsElement: () => resolvedItemsElement,
|
|
1114
|
-
getScrollableParent: () => scrollableParent,
|
|
1115
|
-
// Callbacks
|
|
1116
|
-
onBeforePreviousRequest: () => setLoadingPrevious(true),
|
|
1117
|
-
onBeforeNextRequest: () => setLoadingNext(true),
|
|
1118
|
-
onCompletePreviousRequest: () => {
|
|
1119
|
-
setLoadingPrevious(false);
|
|
1120
|
-
syncStateFromDataManager();
|
|
1121
|
-
},
|
|
1122
|
-
onCompleteNextRequest: () => {
|
|
1123
|
-
setLoadingNext(false);
|
|
1124
|
-
syncStateFromDataManager();
|
|
1125
|
-
},
|
|
1126
|
-
onDataReset: syncStateFromDataManager
|
|
1127
|
-
});
|
|
1128
|
-
setInfiniteScroll(infiniteScrollInstance);
|
|
1129
|
-
const { dataManager: dataManager2, elementManager: elementManager2 } = infiniteScrollInstance;
|
|
1130
|
-
syncStateFromDataManager();
|
|
1131
|
-
elementManager2.setupObservers();
|
|
1132
|
-
elementManager2.processServerLoadedElements(dataManager2.getLastLoadedPage());
|
|
1133
|
-
if (autoLoad) {
|
|
1134
|
-
elementManager2.enableTriggers();
|
|
1135
|
-
}
|
|
1136
|
-
return () => {
|
|
1137
|
-
infiniteScrollInstance.flush();
|
|
1138
|
-
setInfiniteScroll(null);
|
|
1139
|
-
};
|
|
1140
|
-
}, [data, resolvedItemsElement, resolvedStartElement, resolvedEndElement, scrollableParent]);
|
|
1141
|
-
const manualMode = useMemo6(
|
|
1142
|
-
() => manual || manualAfter > 0 && requestCount >= manualAfter,
|
|
1143
|
-
[manual, manualAfter, requestCount]
|
|
1144
|
-
);
|
|
1145
|
-
const autoLoad = useMemo6(() => !manualMode, [manualMode]);
|
|
1146
|
-
useEffect8(() => {
|
|
1147
|
-
autoLoad ? elementManager?.enableTriggers() : elementManager?.disableTriggers();
|
|
1148
|
-
}, [autoLoad, onlyNext, onlyPrevious, resolvedStartElement, resolvedEndElement]);
|
|
1149
|
-
useEffect8(() => {
|
|
1150
|
-
const shouldAutoScroll = autoScroll !== void 0 ? autoScroll : reverse;
|
|
1151
|
-
if (shouldAutoScroll) {
|
|
1152
|
-
scrollToBottom();
|
|
1153
|
-
}
|
|
1154
|
-
}, [scrollableParent]);
|
|
1155
|
-
useImperativeHandle2(
|
|
1156
|
-
ref,
|
|
1157
|
-
() => ({
|
|
1158
|
-
fetchNext: dataManager?.fetchNext || (() => {
|
|
1159
|
-
}),
|
|
1160
|
-
fetchPrevious: dataManager?.fetchPrevious || (() => {
|
|
1161
|
-
}),
|
|
1162
|
-
hasPrevious: dataManager?.hasPrevious || (() => false),
|
|
1163
|
-
hasNext: dataManager?.hasNext || (() => false)
|
|
1164
|
-
}),
|
|
1165
|
-
[dataManager]
|
|
1166
|
-
);
|
|
1167
|
-
const headerAutoMode = autoLoad && !onlyNext;
|
|
1168
|
-
const footerAutoMode = autoLoad && !onlyPrevious;
|
|
1169
|
-
const sharedExposed = {
|
|
1170
|
-
loadingPrevious,
|
|
1171
|
-
loadingNext,
|
|
1172
|
-
hasPrevious: hasPreviousPage,
|
|
1173
|
-
hasNext: hasNextPage
|
|
1174
|
-
};
|
|
1175
|
-
const exposedPrevious = {
|
|
1176
|
-
loading: loadingPrevious,
|
|
1177
|
-
fetch: dataManager?.fetchPrevious ?? (() => {
|
|
1178
|
-
}),
|
|
1179
|
-
autoMode: headerAutoMode,
|
|
1180
|
-
manualMode: !headerAutoMode,
|
|
1181
|
-
hasMore: hasPreviousPage,
|
|
1182
|
-
...sharedExposed
|
|
1183
|
-
};
|
|
1184
|
-
const exposedNext = {
|
|
1185
|
-
loading: loadingNext,
|
|
1186
|
-
fetch: dataManager?.fetchNext ?? (() => {
|
|
1187
|
-
}),
|
|
1188
|
-
autoMode: footerAutoMode,
|
|
1189
|
-
manualMode: !footerAutoMode,
|
|
1190
|
-
hasMore: hasNextPage,
|
|
1191
|
-
...sharedExposed
|
|
1192
|
-
};
|
|
1193
|
-
const exposedSlot = {
|
|
1194
|
-
loading: loadingPrevious || loadingNext,
|
|
1195
|
-
loadingPrevious,
|
|
1196
|
-
loadingNext
|
|
1197
|
-
};
|
|
1198
|
-
const renderElements = [];
|
|
1199
|
-
if (!startElement) {
|
|
1200
|
-
renderElements.push(
|
|
1201
|
-
createElement4(
|
|
1202
|
-
"div",
|
|
1203
|
-
{ ref: startElementRef },
|
|
1204
|
-
// Render previous slot or fallback to loading indicator
|
|
1205
|
-
renderSlot(previous, exposedPrevious, loadingPrevious ? renderSlot(loading, exposedPrevious) : null)
|
|
1206
|
-
)
|
|
1207
|
-
);
|
|
1208
|
-
}
|
|
1209
|
-
renderElements.push(
|
|
1210
|
-
createElement4(
|
|
1211
|
-
as,
|
|
1212
|
-
{ ...props, ref: itemsElementRef },
|
|
1213
|
-
typeof children === "function" ? children(exposedSlot) : children
|
|
1214
|
-
)
|
|
1215
|
-
);
|
|
1216
|
-
if (!endElement) {
|
|
1217
|
-
renderElements.push(
|
|
1218
|
-
createElement4(
|
|
1219
|
-
"div",
|
|
1220
|
-
{ ref: endElementRef },
|
|
1221
|
-
// Render next slot or fallback to loading indicator
|
|
1222
|
-
renderSlot(next, exposedNext, loadingNext ? renderSlot(loading, exposedNext) : null)
|
|
1223
|
-
)
|
|
1224
|
-
);
|
|
1225
|
-
}
|
|
1226
|
-
return createElement4(React5.Fragment, {}, ...reverse ? [...renderElements].reverse() : renderElements);
|
|
1227
|
-
}
|
|
1228
|
-
);
|
|
1229
|
-
InfiniteScroll.displayName = "InertiaInfiniteScroll";
|
|
1230
|
-
var InfiniteScroll_default = InfiniteScroll;
|
|
1231
|
-
|
|
1232
|
-
// src/Link.ts
|
|
1233
|
-
import {
|
|
1234
|
-
isUrlMethodPair as isUrlMethodPair2,
|
|
1235
|
-
mergeDataIntoQueryString as mergeDataIntoQueryString2,
|
|
1236
|
-
router as router6,
|
|
1237
|
-
shouldIntercept,
|
|
1238
|
-
shouldNavigate
|
|
1239
|
-
} from "@inertiajs/core";
|
|
1240
|
-
import { createElement as createElement5, forwardRef as forwardRef3, useEffect as useEffect9, useMemo as useMemo7, useRef as useRef4, useState as useState7 } from "react";
|
|
1241
|
-
var noop2 = () => void 0;
|
|
1242
|
-
var Link = forwardRef3(
|
|
1243
|
-
({
|
|
1244
|
-
children,
|
|
1245
|
-
as = "a",
|
|
1246
|
-
data = {},
|
|
1247
|
-
href = "",
|
|
1248
|
-
method = "get",
|
|
1249
|
-
preserveScroll = false,
|
|
1250
|
-
preserveState = null,
|
|
1251
|
-
preserveUrl = false,
|
|
1252
|
-
replace = false,
|
|
1253
|
-
only = [],
|
|
1254
|
-
except = [],
|
|
1255
|
-
headers = {},
|
|
1256
|
-
queryStringArrayFormat = "brackets",
|
|
1257
|
-
async = false,
|
|
1258
|
-
onClick = noop2,
|
|
1259
|
-
onCancelToken = noop2,
|
|
1260
|
-
onBefore = noop2,
|
|
1261
|
-
onStart = noop2,
|
|
1262
|
-
onProgress = noop2,
|
|
1263
|
-
onFinish = noop2,
|
|
1264
|
-
onCancel = noop2,
|
|
1265
|
-
onSuccess = noop2,
|
|
1266
|
-
onError = noop2,
|
|
1267
|
-
onPrefetching = noop2,
|
|
1268
|
-
onPrefetched = noop2,
|
|
1269
|
-
prefetch = false,
|
|
1270
|
-
cacheFor = 0,
|
|
1271
|
-
cacheTags = [],
|
|
1272
|
-
viewTransition = false,
|
|
1273
|
-
...props
|
|
1274
|
-
}, ref) => {
|
|
1275
|
-
const [inFlightCount, setInFlightCount] = useState7(0);
|
|
1276
|
-
const hoverTimeout = useRef4(void 0);
|
|
1277
|
-
const _method = useMemo7(() => {
|
|
1278
|
-
return isUrlMethodPair2(href) ? href.method : method.toLowerCase();
|
|
1279
|
-
}, [href, method]);
|
|
1280
|
-
const _as = useMemo7(() => {
|
|
1281
|
-
if (typeof as !== "string" || as.toLowerCase() !== "a") {
|
|
1282
|
-
return as;
|
|
1283
|
-
}
|
|
1284
|
-
return _method !== "get" ? "button" : as.toLowerCase();
|
|
1285
|
-
}, [as, _method]);
|
|
1286
|
-
const mergeDataArray = useMemo7(
|
|
1287
|
-
() => mergeDataIntoQueryString2(_method, isUrlMethodPair2(href) ? href.url : href, data, queryStringArrayFormat),
|
|
1288
|
-
[href, _method, data, queryStringArrayFormat]
|
|
1289
|
-
);
|
|
1290
|
-
const url = useMemo7(() => mergeDataArray[0], [mergeDataArray]);
|
|
1291
|
-
const _data = useMemo7(() => mergeDataArray[1], [mergeDataArray]);
|
|
1292
|
-
const baseParams = useMemo7(
|
|
1293
|
-
() => ({
|
|
1294
|
-
data: _data,
|
|
1295
|
-
method: _method,
|
|
1296
|
-
preserveScroll,
|
|
1297
|
-
preserveState: preserveState ?? _method !== "get",
|
|
1298
|
-
preserveUrl,
|
|
1299
|
-
replace,
|
|
1300
|
-
only,
|
|
1301
|
-
except,
|
|
1302
|
-
headers,
|
|
1303
|
-
async
|
|
1304
|
-
}),
|
|
1305
|
-
[_data, _method, preserveScroll, preserveState, preserveUrl, replace, only, except, headers, async]
|
|
1306
|
-
);
|
|
1307
|
-
const visitParams = useMemo7(
|
|
1308
|
-
() => ({
|
|
1309
|
-
...baseParams,
|
|
1310
|
-
viewTransition,
|
|
1311
|
-
onCancelToken,
|
|
1312
|
-
onBefore,
|
|
1313
|
-
onStart(visit) {
|
|
1314
|
-
setInFlightCount((count) => count + 1);
|
|
1315
|
-
onStart(visit);
|
|
1316
|
-
},
|
|
1317
|
-
onProgress,
|
|
1318
|
-
onFinish(visit) {
|
|
1319
|
-
setInFlightCount((count) => count - 1);
|
|
1320
|
-
onFinish(visit);
|
|
1321
|
-
},
|
|
1322
|
-
onCancel,
|
|
1323
|
-
onSuccess,
|
|
1324
|
-
onError
|
|
1325
|
-
}),
|
|
1326
|
-
[
|
|
1327
|
-
baseParams,
|
|
1328
|
-
viewTransition,
|
|
1329
|
-
onCancelToken,
|
|
1330
|
-
onBefore,
|
|
1331
|
-
onStart,
|
|
1332
|
-
onProgress,
|
|
1333
|
-
onFinish,
|
|
1334
|
-
onCancel,
|
|
1335
|
-
onSuccess,
|
|
1336
|
-
onError
|
|
1337
|
-
]
|
|
1338
|
-
);
|
|
1339
|
-
const prefetchModes = useMemo7(
|
|
1340
|
-
() => {
|
|
1341
|
-
if (prefetch === true) {
|
|
1342
|
-
return ["hover"];
|
|
1343
|
-
}
|
|
1344
|
-
if (prefetch === false) {
|
|
1345
|
-
return [];
|
|
1346
|
-
}
|
|
1347
|
-
if (Array.isArray(prefetch)) {
|
|
1348
|
-
return prefetch;
|
|
1349
|
-
}
|
|
1350
|
-
return [prefetch];
|
|
1351
|
-
},
|
|
1352
|
-
Array.isArray(prefetch) ? prefetch : [prefetch]
|
|
1353
|
-
);
|
|
1354
|
-
const cacheForValue = useMemo7(() => {
|
|
1355
|
-
if (cacheFor !== 0) {
|
|
1356
|
-
return cacheFor;
|
|
1357
|
-
}
|
|
1358
|
-
if (prefetchModes.length === 1 && prefetchModes[0] === "click") {
|
|
1359
|
-
return 0;
|
|
1360
|
-
}
|
|
1361
|
-
return config.get("prefetch.cacheFor");
|
|
1362
|
-
}, [cacheFor, prefetchModes]);
|
|
1363
|
-
const doPrefetch = useMemo7(() => {
|
|
1364
|
-
return () => {
|
|
1365
|
-
router6.prefetch(
|
|
1366
|
-
url,
|
|
1367
|
-
{
|
|
1368
|
-
...baseParams,
|
|
1369
|
-
onPrefetching,
|
|
1370
|
-
onPrefetched
|
|
1371
|
-
},
|
|
1372
|
-
{ cacheFor: cacheForValue, cacheTags }
|
|
1373
|
-
);
|
|
1374
|
-
};
|
|
1375
|
-
}, [url, baseParams, onPrefetching, onPrefetched, cacheForValue, cacheTags]);
|
|
1376
|
-
useEffect9(() => {
|
|
1377
|
-
return () => {
|
|
1378
|
-
clearTimeout(hoverTimeout.current);
|
|
1379
|
-
};
|
|
1380
|
-
}, []);
|
|
1381
|
-
useEffect9(() => {
|
|
1382
|
-
if (prefetchModes.includes("mount")) {
|
|
1383
|
-
setTimeout(() => doPrefetch());
|
|
1384
|
-
}
|
|
1385
|
-
}, prefetchModes);
|
|
1386
|
-
const regularEvents = {
|
|
1387
|
-
onClick: (event) => {
|
|
1388
|
-
onClick(event);
|
|
1389
|
-
if (shouldIntercept(event)) {
|
|
1390
|
-
event.preventDefault();
|
|
1391
|
-
router6.visit(url, visitParams);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
};
|
|
1395
|
-
const prefetchHoverEvents = {
|
|
1396
|
-
onMouseEnter: () => {
|
|
1397
|
-
hoverTimeout.current = window.setTimeout(() => {
|
|
1398
|
-
doPrefetch();
|
|
1399
|
-
}, config.get("prefetch.hoverDelay"));
|
|
1400
|
-
},
|
|
1401
|
-
onMouseLeave: () => {
|
|
1402
|
-
clearTimeout(hoverTimeout.current);
|
|
1403
|
-
},
|
|
1404
|
-
onClick: regularEvents.onClick
|
|
1405
|
-
};
|
|
1406
|
-
const prefetchClickEvents = {
|
|
1407
|
-
onMouseDown: (event) => {
|
|
1408
|
-
if (shouldIntercept(event)) {
|
|
1409
|
-
event.preventDefault();
|
|
1410
|
-
doPrefetch();
|
|
1411
|
-
}
|
|
1412
|
-
},
|
|
1413
|
-
onKeyDown: (event) => {
|
|
1414
|
-
if (shouldNavigate(event)) {
|
|
1415
|
-
event.preventDefault();
|
|
1416
|
-
doPrefetch();
|
|
1417
|
-
}
|
|
1418
|
-
},
|
|
1419
|
-
onMouseUp: (event) => {
|
|
1420
|
-
if (shouldIntercept(event)) {
|
|
1421
|
-
event.preventDefault();
|
|
1422
|
-
router6.visit(url, visitParams);
|
|
1423
|
-
}
|
|
1424
|
-
},
|
|
1425
|
-
onKeyUp: (event) => {
|
|
1426
|
-
if (shouldNavigate(event)) {
|
|
1427
|
-
event.preventDefault();
|
|
1428
|
-
router6.visit(url, visitParams);
|
|
1429
|
-
}
|
|
1430
|
-
},
|
|
1431
|
-
onClick: (event) => {
|
|
1432
|
-
onClick(event);
|
|
1433
|
-
if (shouldIntercept(event)) {
|
|
1434
|
-
event.preventDefault();
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
const elProps = useMemo7(() => {
|
|
1439
|
-
if (_as === "button") {
|
|
1440
|
-
return { type: "button" };
|
|
1441
|
-
}
|
|
1442
|
-
if (_as === "a" || typeof _as !== "string") {
|
|
1443
|
-
return { href: url };
|
|
1444
|
-
}
|
|
1445
|
-
return {};
|
|
1446
|
-
}, [_as, url]);
|
|
1447
|
-
return createElement5(
|
|
1448
|
-
_as,
|
|
1449
|
-
{
|
|
1450
|
-
...props,
|
|
1451
|
-
...elProps,
|
|
1452
|
-
ref,
|
|
1453
|
-
...(() => {
|
|
1454
|
-
if (prefetchModes.includes("hover")) {
|
|
1455
|
-
return prefetchHoverEvents;
|
|
1456
|
-
}
|
|
1457
|
-
if (prefetchModes.includes("click")) {
|
|
1458
|
-
return prefetchClickEvents;
|
|
1459
|
-
}
|
|
1460
|
-
return regularEvents;
|
|
1461
|
-
})(),
|
|
1462
|
-
"data-loading": inFlightCount > 0 ? "" : void 0
|
|
1463
|
-
},
|
|
1464
|
-
children
|
|
1465
|
-
);
|
|
1466
|
-
}
|
|
1467
|
-
);
|
|
1468
|
-
Link.displayName = "InertiaLink";
|
|
1469
|
-
var Link_default = Link;
|
|
1470
|
-
|
|
1471
|
-
// src/usePoll.ts
|
|
1472
|
-
import { router as router7 } from "@inertiajs/core";
|
|
1473
|
-
import { useEffect as useEffect10, useRef as useRef5 } from "react";
|
|
1474
|
-
function usePoll(interval, requestOptions = {}, options = {
|
|
1475
|
-
keepAlive: false,
|
|
1476
|
-
autoStart: true
|
|
1477
|
-
}) {
|
|
1478
|
-
const pollRef = useRef5(
|
|
1479
|
-
router7.poll(interval, requestOptions, {
|
|
1480
|
-
...options,
|
|
1481
|
-
autoStart: false
|
|
1482
|
-
})
|
|
1483
|
-
);
|
|
1484
|
-
useEffect10(() => {
|
|
1485
|
-
if (options.autoStart ?? true) {
|
|
1486
|
-
pollRef.current.start();
|
|
1487
|
-
}
|
|
1488
|
-
return () => pollRef.current.stop();
|
|
1489
|
-
}, []);
|
|
1490
|
-
return {
|
|
1491
|
-
stop: pollRef.current.stop,
|
|
1492
|
-
start: pollRef.current.start
|
|
1493
|
-
};
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
// src/usePrefetch.ts
|
|
1497
|
-
import { router as router8 } from "@inertiajs/core";
|
|
1498
|
-
import { useEffect as useEffect11, useState as useState8 } from "react";
|
|
1499
|
-
function usePrefetch(options = {}) {
|
|
1500
|
-
const cached = typeof window === "undefined" ? null : router8.getCached(window.location.pathname, options);
|
|
1501
|
-
const inFlight = typeof window === "undefined" ? null : router8.getPrefetching(window.location.pathname, options);
|
|
1502
|
-
const [lastUpdatedAt, setLastUpdatedAt] = useState8(cached?.staleTimestamp || null);
|
|
1503
|
-
const [isPrefetching, setIsPrefetching] = useState8(inFlight !== null);
|
|
1504
|
-
const [isPrefetched, setIsPrefetched] = useState8(cached !== null);
|
|
1505
|
-
useEffect11(() => {
|
|
1506
|
-
const onPrefetchingListener = router8.on("prefetching", (e) => {
|
|
1507
|
-
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1508
|
-
setIsPrefetching(true);
|
|
1509
|
-
}
|
|
1510
|
-
});
|
|
1511
|
-
const onPrefetchedListener = router8.on("prefetched", (e) => {
|
|
1512
|
-
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1513
|
-
setIsPrefetching(false);
|
|
1514
|
-
setIsPrefetched(true);
|
|
1515
|
-
setLastUpdatedAt(e.detail.fetchedAt);
|
|
1516
|
-
}
|
|
1517
|
-
});
|
|
1518
|
-
return () => {
|
|
1519
|
-
onPrefetchedListener();
|
|
1520
|
-
onPrefetchingListener();
|
|
1521
|
-
};
|
|
1522
|
-
}, []);
|
|
1523
|
-
return {
|
|
1524
|
-
lastUpdatedAt,
|
|
1525
|
-
isPrefetching,
|
|
1526
|
-
isPrefetched,
|
|
1527
|
-
flush: () => router8.flush(window.location.pathname, options)
|
|
1528
|
-
};
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
// src/WhenVisible.ts
|
|
1532
|
-
import { router as router9 } from "@inertiajs/core";
|
|
1533
|
-
import { createElement as createElement6, useCallback as useCallback3, useEffect as useEffect12, useMemo as useMemo8, useRef as useRef6, useState as useState9 } from "react";
|
|
1534
|
-
var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
|
|
1535
|
-
always = always ?? false;
|
|
1536
|
-
as = as ?? "div";
|
|
1537
|
-
fallback = fallback ?? null;
|
|
1538
|
-
const pageProps = usePage().props;
|
|
1539
|
-
const keys = useMemo8(() => data ? Array.isArray(data) ? data : [data] : [], [data]);
|
|
1540
|
-
const [loaded, setLoaded] = useState9(() => keys.length > 0 && keys.every((key) => pageProps[key] !== void 0));
|
|
1541
|
-
const [isFetching, setIsFetching] = useState9(false);
|
|
1542
|
-
const fetching = useRef6(false);
|
|
1543
|
-
const ref = useRef6(null);
|
|
1544
|
-
const observer = useRef6(null);
|
|
1545
|
-
const getReloadParamsRef = useRef6(() => ({}));
|
|
1546
|
-
useEffect12(() => {
|
|
1547
|
-
if (keys.length > 0) {
|
|
1548
|
-
setLoaded(keys.every((key) => pageProps[key] !== void 0));
|
|
1549
|
-
}
|
|
1550
|
-
}, [pageProps, keys]);
|
|
1551
|
-
const getReloadParams = useCallback3(() => {
|
|
1552
|
-
const reloadParams = { ...params };
|
|
1553
|
-
if (data) {
|
|
1554
|
-
reloadParams.only = Array.isArray(data) ? data : [data];
|
|
1555
|
-
}
|
|
1556
|
-
return reloadParams;
|
|
1557
|
-
}, [params, data]);
|
|
1558
|
-
getReloadParamsRef.current = getReloadParams;
|
|
1559
|
-
const registerObserver = () => {
|
|
1560
|
-
observer.current?.disconnect();
|
|
1561
|
-
observer.current = new IntersectionObserver(
|
|
1562
|
-
(entries) => {
|
|
1563
|
-
if (!entries[0].isIntersecting) {
|
|
1564
|
-
return;
|
|
1565
|
-
}
|
|
1566
|
-
if (fetching.current) {
|
|
1567
|
-
return;
|
|
1568
|
-
}
|
|
1569
|
-
if (!always && loaded) {
|
|
1570
|
-
return;
|
|
1571
|
-
}
|
|
1572
|
-
fetching.current = true;
|
|
1573
|
-
setIsFetching(true);
|
|
1574
|
-
const reloadParams = getReloadParamsRef.current();
|
|
1575
|
-
router9.reload({
|
|
1576
|
-
...reloadParams,
|
|
1577
|
-
onStart: (e) => {
|
|
1578
|
-
fetching.current = true;
|
|
1579
|
-
setIsFetching(true);
|
|
1580
|
-
reloadParams.onStart?.(e);
|
|
1581
|
-
},
|
|
1582
|
-
onFinish: (e) => {
|
|
1583
|
-
setLoaded(true);
|
|
1584
|
-
fetching.current = false;
|
|
1585
|
-
setIsFetching(false);
|
|
1586
|
-
reloadParams.onFinish?.(e);
|
|
1587
|
-
if (!always) {
|
|
1588
|
-
observer.current?.disconnect();
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
});
|
|
1592
|
-
},
|
|
1593
|
-
{
|
|
1594
|
-
rootMargin: `${buffer || 0}px`
|
|
1595
|
-
}
|
|
1596
|
-
);
|
|
1597
|
-
observer.current.observe(ref.current);
|
|
1598
|
-
};
|
|
1599
|
-
useEffect12(() => {
|
|
1600
|
-
if (!ref.current) {
|
|
1601
|
-
return;
|
|
1602
|
-
}
|
|
1603
|
-
if (loaded && !always) {
|
|
1604
|
-
return;
|
|
1605
|
-
}
|
|
1606
|
-
registerObserver();
|
|
1607
|
-
return () => {
|
|
1608
|
-
observer.current?.disconnect();
|
|
1609
|
-
};
|
|
1610
|
-
}, [always, loaded, buffer]);
|
|
1611
|
-
const resolveChildren = () => typeof children === "function" ? children({ fetching: isFetching }) : children;
|
|
1612
|
-
const resolveFallback = () => typeof fallback === "function" ? fallback() : fallback;
|
|
1613
|
-
if (always || !loaded) {
|
|
1614
|
-
return createElement6(
|
|
1615
|
-
as,
|
|
1616
|
-
{
|
|
1617
|
-
props: null,
|
|
1618
|
-
ref
|
|
1619
|
-
},
|
|
1620
|
-
loaded ? resolveChildren() : resolveFallback()
|
|
1621
|
-
);
|
|
1622
|
-
}
|
|
1623
|
-
return loaded ? resolveChildren() : null;
|
|
1624
|
-
};
|
|
1625
|
-
WhenVisible.displayName = "InertiaWhenVisible";
|
|
1626
|
-
var WhenVisible_default = WhenVisible;
|
|
1627
|
-
|
|
1628
|
-
// src/index.ts
|
|
1629
|
-
var progress = Progress2;
|
|
1630
|
-
var router3 = Router;
|
|
1631
|
-
var config = coreConfig.extend();
|
|
1632
|
-
export {
|
|
1633
|
-
App,
|
|
1634
|
-
Deferred_default as Deferred,
|
|
1635
|
-
Form_default as Form,
|
|
1636
|
-
Head_default as Head,
|
|
1637
|
-
InfiniteScroll_default as InfiniteScroll,
|
|
1638
|
-
Link_default as Link,
|
|
1639
|
-
WhenVisible_default as WhenVisible,
|
|
1640
|
-
config,
|
|
1641
|
-
createInertiaApp,
|
|
1642
|
-
progress,
|
|
1643
|
-
router3 as router,
|
|
1644
|
-
useForm,
|
|
1645
|
-
useFormContext,
|
|
1646
|
-
usePage,
|
|
1647
|
-
usePoll,
|
|
1648
|
-
usePrefetch,
|
|
1649
|
-
useRemember
|
|
1650
|
-
};
|
|
1651
|
-
//# sourceMappingURL=index.esm.js.map
|