@inertiajs/react 2.2.3 → 2.2.5
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.esm.js +36 -29
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +130 -123
- package/dist/index.js.map +4 -4
- package/package.json +5 -3
- package/types/react.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -256,22 +256,28 @@ var Deferred_default = Deferred;
|
|
|
256
256
|
// src/Form.ts
|
|
257
257
|
var import_core5 = require("@inertiajs/core");
|
|
258
258
|
var import_lodash_es2 = require("lodash-es");
|
|
259
|
-
var
|
|
259
|
+
var import_react11 = __toESM(require("react"), 1);
|
|
260
260
|
|
|
261
261
|
// src/useForm.ts
|
|
262
262
|
var import_core4 = require("@inertiajs/core");
|
|
263
263
|
var import_lodash_es = require("lodash-es");
|
|
264
|
-
var
|
|
264
|
+
var import_react9 = require("react");
|
|
265
|
+
|
|
266
|
+
// src/react.ts
|
|
267
|
+
var import_react7 = require("react");
|
|
268
|
+
function useIsomorphicLayoutEffect(effect, deps) {
|
|
269
|
+
typeof window === "undefined" ? (0, import_react7.useEffect)(effect, deps) : (0, import_react7.useLayoutEffect)(effect, deps);
|
|
270
|
+
}
|
|
265
271
|
|
|
266
272
|
// src/useRemember.ts
|
|
267
273
|
var import_core3 = require("@inertiajs/core");
|
|
268
|
-
var
|
|
274
|
+
var import_react8 = require("react");
|
|
269
275
|
function useRemember(initialState, key) {
|
|
270
|
-
const [state, setState] = (0,
|
|
276
|
+
const [state, setState] = (0, import_react8.useState)(() => {
|
|
271
277
|
const restored = import_core3.router.restore(key);
|
|
272
278
|
return restored !== void 0 ? restored : initialState;
|
|
273
279
|
});
|
|
274
|
-
(0,
|
|
280
|
+
(0, import_react8.useEffect)(() => {
|
|
275
281
|
import_core3.router.remember(state, key);
|
|
276
282
|
}, [state, key]);
|
|
277
283
|
return [state, setState];
|
|
@@ -279,30 +285,30 @@ function useRemember(initialState, key) {
|
|
|
279
285
|
|
|
280
286
|
// src/useForm.ts
|
|
281
287
|
function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
282
|
-
const isMounted = (0,
|
|
288
|
+
const isMounted = (0, import_react9.useRef)(null);
|
|
283
289
|
const rememberKey = typeof rememberKeyOrInitialValues === "string" ? rememberKeyOrInitialValues : null;
|
|
284
|
-
const [defaults, setDefaults] = (0,
|
|
290
|
+
const [defaults, setDefaults] = (0, import_react9.useState)(
|
|
285
291
|
(typeof rememberKeyOrInitialValues === "string" ? maybeInitialValues : rememberKeyOrInitialValues) || {}
|
|
286
292
|
);
|
|
287
|
-
const cancelToken = (0,
|
|
288
|
-
const recentlySuccessfulTimeoutId = (0,
|
|
289
|
-
const [data, setData] = rememberKey ? useRemember(defaults, `${rememberKey}:data`) : (0,
|
|
290
|
-
const [errors, setErrors] = rememberKey ? useRemember({}, `${rememberKey}:errors`) : (0,
|
|
291
|
-
const [hasErrors, setHasErrors] = (0,
|
|
292
|
-
const [processing, setProcessing] = (0,
|
|
293
|
-
const [progress2, setProgress] = (0,
|
|
294
|
-
const [wasSuccessful, setWasSuccessful] = (0,
|
|
295
|
-
const [recentlySuccessful, setRecentlySuccessful] = (0,
|
|
296
|
-
const transform = (0,
|
|
297
|
-
const isDirty = (0,
|
|
298
|
-
(0,
|
|
293
|
+
const cancelToken = (0, import_react9.useRef)(null);
|
|
294
|
+
const recentlySuccessfulTimeoutId = (0, import_react9.useRef)(null);
|
|
295
|
+
const [data, setData] = rememberKey ? useRemember(defaults, `${rememberKey}:data`) : (0, import_react9.useState)(defaults);
|
|
296
|
+
const [errors, setErrors] = rememberKey ? useRemember({}, `${rememberKey}:errors`) : (0, import_react9.useState)({});
|
|
297
|
+
const [hasErrors, setHasErrors] = (0, import_react9.useState)(false);
|
|
298
|
+
const [processing, setProcessing] = (0, import_react9.useState)(false);
|
|
299
|
+
const [progress2, setProgress] = (0, import_react9.useState)(null);
|
|
300
|
+
const [wasSuccessful, setWasSuccessful] = (0, import_react9.useState)(false);
|
|
301
|
+
const [recentlySuccessful, setRecentlySuccessful] = (0, import_react9.useState)(false);
|
|
302
|
+
const transform = (0, import_react9.useRef)((data2) => data2);
|
|
303
|
+
const isDirty = (0, import_react9.useMemo)(() => !(0, import_lodash_es.isEqual)(data, defaults), [data, defaults]);
|
|
304
|
+
(0, import_react9.useEffect)(() => {
|
|
299
305
|
isMounted.current = true;
|
|
300
306
|
return () => {
|
|
301
307
|
isMounted.current = false;
|
|
302
308
|
};
|
|
303
309
|
}, []);
|
|
304
|
-
const setDefaultsCalledInOnSuccess = (0,
|
|
305
|
-
const submit = (0,
|
|
310
|
+
const setDefaultsCalledInOnSuccess = (0, import_react9.useRef)(false);
|
|
311
|
+
const submit = (0, import_react9.useCallback)(
|
|
306
312
|
(...args) => {
|
|
307
313
|
const objectPassed = args[0] !== null && typeof args[0] === "object";
|
|
308
314
|
const method = objectPassed ? args[0].method : args[0];
|
|
@@ -399,7 +405,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
399
405
|
},
|
|
400
406
|
[data, setErrors, transform]
|
|
401
407
|
);
|
|
402
|
-
const setDataFunction = (0,
|
|
408
|
+
const setDataFunction = (0, import_react9.useCallback)(
|
|
403
409
|
(keyOrData, maybeValue) => {
|
|
404
410
|
if (typeof keyOrData === "string") {
|
|
405
411
|
setData((data2) => (0, import_lodash_es.set)((0, import_lodash_es.cloneDeep)(data2), keyOrData, maybeValue));
|
|
@@ -411,12 +417,12 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
411
417
|
},
|
|
412
418
|
[setData]
|
|
413
419
|
);
|
|
414
|
-
const [dataAsDefaults, setDataAsDefaults] = (0,
|
|
415
|
-
const dataRef = (0,
|
|
416
|
-
(0,
|
|
420
|
+
const [dataAsDefaults, setDataAsDefaults] = (0, import_react9.useState)(false);
|
|
421
|
+
const dataRef = (0, import_react9.useRef)(data);
|
|
422
|
+
(0, import_react9.useEffect)(() => {
|
|
417
423
|
dataRef.current = data;
|
|
418
424
|
});
|
|
419
|
-
const setDefaultsFunction = (0,
|
|
425
|
+
const setDefaultsFunction = (0, import_react9.useCallback)(
|
|
420
426
|
(fieldOrFields, maybeValue) => {
|
|
421
427
|
setDefaultsCalledInOnSuccess.current = true;
|
|
422
428
|
if (typeof fieldOrFields === "undefined") {
|
|
@@ -430,7 +436,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
430
436
|
},
|
|
431
437
|
[setDefaults]
|
|
432
438
|
);
|
|
433
|
-
(
|
|
439
|
+
useIsomorphicLayoutEffect(() => {
|
|
434
440
|
if (!dataAsDefaults) {
|
|
435
441
|
return;
|
|
436
442
|
}
|
|
@@ -439,7 +445,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
439
445
|
}
|
|
440
446
|
setDataAsDefaults(false);
|
|
441
447
|
}, [dataAsDefaults]);
|
|
442
|
-
const reset = (0,
|
|
448
|
+
const reset = (0, import_react9.useCallback)(
|
|
443
449
|
(...fields) => {
|
|
444
450
|
if (fields.length === 0) {
|
|
445
451
|
setData(defaults);
|
|
@@ -456,7 +462,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
456
462
|
},
|
|
457
463
|
[setData, defaults]
|
|
458
464
|
);
|
|
459
|
-
const setError = (0,
|
|
465
|
+
const setError = (0, import_react9.useCallback)(
|
|
460
466
|
(fieldOrFields, maybeValue) => {
|
|
461
467
|
setErrors((errors2) => {
|
|
462
468
|
const newErrors = {
|
|
@@ -469,7 +475,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
469
475
|
},
|
|
470
476
|
[setErrors, setHasErrors]
|
|
471
477
|
);
|
|
472
|
-
const clearErrors = (0,
|
|
478
|
+
const clearErrors = (0, import_react9.useCallback)(
|
|
473
479
|
(...fields) => {
|
|
474
480
|
setErrors((errors2) => {
|
|
475
481
|
const newErrors = Object.keys(errors2).reduce(
|
|
@@ -485,7 +491,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
485
491
|
},
|
|
486
492
|
[setErrors, setHasErrors]
|
|
487
493
|
);
|
|
488
|
-
const resetAndClearErrors = (0,
|
|
494
|
+
const resetAndClearErrors = (0, import_react9.useCallback)(
|
|
489
495
|
(...fields) => {
|
|
490
496
|
reset(...fields);
|
|
491
497
|
clearErrors(...fields);
|
|
@@ -495,17 +501,17 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
495
501
|
const createSubmitMethod = (method) => (url, options) => {
|
|
496
502
|
submit(method, url, options);
|
|
497
503
|
};
|
|
498
|
-
const getMethod = (0,
|
|
499
|
-
const post = (0,
|
|
500
|
-
const put = (0,
|
|
501
|
-
const patch = (0,
|
|
502
|
-
const deleteMethod = (0,
|
|
503
|
-
const cancel = (0,
|
|
504
|
+
const getMethod = (0, import_react9.useCallback)(createSubmitMethod("get"), [submit]);
|
|
505
|
+
const post = (0, import_react9.useCallback)(createSubmitMethod("post"), [submit]);
|
|
506
|
+
const put = (0, import_react9.useCallback)(createSubmitMethod("put"), [submit]);
|
|
507
|
+
const patch = (0, import_react9.useCallback)(createSubmitMethod("patch"), [submit]);
|
|
508
|
+
const deleteMethod = (0, import_react9.useCallback)(createSubmitMethod("delete"), [submit]);
|
|
509
|
+
const cancel = (0, import_react9.useCallback)(() => {
|
|
504
510
|
if (cancelToken.current) {
|
|
505
511
|
cancelToken.current.cancel();
|
|
506
512
|
}
|
|
507
513
|
}, []);
|
|
508
|
-
const transformFunction = (0,
|
|
514
|
+
const transformFunction = (0, import_react9.useCallback)((callback) => {
|
|
509
515
|
transform.current = callback;
|
|
510
516
|
}, []);
|
|
511
517
|
return {
|
|
@@ -536,10 +542,10 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
536
542
|
|
|
537
543
|
// src/Form.ts
|
|
538
544
|
var deferStateUpdate = (callback) => {
|
|
539
|
-
typeof
|
|
545
|
+
typeof import_react11.default.startTransition === "function" ? import_react11.default.startTransition(callback) : setTimeout(callback, 0);
|
|
540
546
|
};
|
|
541
547
|
var noop = () => void 0;
|
|
542
|
-
var Form = (0,
|
|
548
|
+
var Form = (0, import_react11.forwardRef)(
|
|
543
549
|
({
|
|
544
550
|
action = "",
|
|
545
551
|
method = "get",
|
|
@@ -567,18 +573,18 @@ var Form = (0, import_react9.forwardRef)(
|
|
|
567
573
|
...props
|
|
568
574
|
}, ref) => {
|
|
569
575
|
const form = useForm({});
|
|
570
|
-
const formElement = (0,
|
|
571
|
-
const resolvedMethod = (0,
|
|
576
|
+
const formElement = (0, import_react11.useRef)(null);
|
|
577
|
+
const resolvedMethod = (0, import_react11.useMemo)(() => {
|
|
572
578
|
return (0, import_core5.isUrlMethodPair)(action) ? action.method : method.toLowerCase();
|
|
573
579
|
}, [action, method]);
|
|
574
|
-
const [isDirty, setIsDirty] = (0,
|
|
575
|
-
const defaultData = (0,
|
|
580
|
+
const [isDirty, setIsDirty] = (0, import_react11.useState)(false);
|
|
581
|
+
const defaultData = (0, import_react11.useRef)(new FormData());
|
|
576
582
|
const getFormData = () => new FormData(formElement.current);
|
|
577
583
|
const getData = () => (0, import_core5.formDataToObject)(getFormData());
|
|
578
584
|
const updateDirtyState = (event) => deferStateUpdate(
|
|
579
585
|
() => setIsDirty(event.type === "reset" ? false : !(0, import_lodash_es2.isEqual)(getData(), (0, import_core5.formDataToObject)(defaultData.current)))
|
|
580
586
|
);
|
|
581
|
-
(0,
|
|
587
|
+
(0, import_react11.useEffect)(() => {
|
|
582
588
|
defaultData.current = getFormData();
|
|
583
589
|
const formEvents = ["input", "change", "reset"];
|
|
584
590
|
formEvents.forEach((e) => formElement.current.addEventListener(e, updateDirtyState));
|
|
@@ -658,8 +664,8 @@ var Form = (0, import_react9.forwardRef)(
|
|
|
658
664
|
submit,
|
|
659
665
|
defaults
|
|
660
666
|
});
|
|
661
|
-
(0,
|
|
662
|
-
return (0,
|
|
667
|
+
(0, import_react11.useImperativeHandle)(ref, exposed, [form, isDirty, submit]);
|
|
668
|
+
return (0, import_react11.createElement)(
|
|
663
669
|
"form",
|
|
664
670
|
{
|
|
665
671
|
...props,
|
|
@@ -685,12 +691,12 @@ var Form_default = Form;
|
|
|
685
691
|
|
|
686
692
|
// src/Head.ts
|
|
687
693
|
var import_lodash_es3 = require("lodash-es");
|
|
688
|
-
var
|
|
694
|
+
var import_react12 = __toESM(require("react"), 1);
|
|
689
695
|
var Head = function({ children, title }) {
|
|
690
|
-
const headManager = (0,
|
|
691
|
-
const provider = (0,
|
|
696
|
+
const headManager = (0, import_react12.useContext)(HeadContext_default);
|
|
697
|
+
const provider = (0, import_react12.useMemo)(() => headManager.createProvider(), [headManager]);
|
|
692
698
|
const isServer = typeof window === "undefined";
|
|
693
|
-
(0,
|
|
699
|
+
(0, import_react12.useEffect)(() => {
|
|
694
700
|
provider.reconnect();
|
|
695
701
|
provider.update(renderNodes(children));
|
|
696
702
|
return () => {
|
|
@@ -747,7 +753,7 @@ var Head = function({ children, title }) {
|
|
|
747
753
|
return html;
|
|
748
754
|
}
|
|
749
755
|
function ensureNodeHasInertiaProp(node) {
|
|
750
|
-
return
|
|
756
|
+
return import_react12.default.cloneElement(node, {
|
|
751
757
|
inertia: node.props["head-key"] !== void 0 ? node.props["head-key"] : ""
|
|
752
758
|
});
|
|
753
759
|
}
|
|
@@ -755,7 +761,7 @@ var Head = function({ children, title }) {
|
|
|
755
761
|
return renderTag(ensureNodeHasInertiaProp(node));
|
|
756
762
|
}
|
|
757
763
|
function renderNodes(nodes) {
|
|
758
|
-
const computed =
|
|
764
|
+
const computed = import_react12.default.Children.toArray(nodes).filter((node) => node).map((node) => renderNode(node));
|
|
759
765
|
if (title && !computed.find((tag) => tag.startsWith("<title"))) {
|
|
760
766
|
computed.push(`<title inertia>${title}</title>`);
|
|
761
767
|
}
|
|
@@ -770,7 +776,7 @@ var Head_default = Head;
|
|
|
770
776
|
|
|
771
777
|
// src/InfiniteScroll.ts
|
|
772
778
|
var import_core6 = require("@inertiajs/core");
|
|
773
|
-
var
|
|
779
|
+
var import_react13 = __toESM(require("react"), 1);
|
|
774
780
|
var resolveHTMLElement = (value, fallback) => {
|
|
775
781
|
if (!value) {
|
|
776
782
|
return fallback;
|
|
@@ -789,7 +795,7 @@ var renderSlot = (slotContent, slotProps, fallback = null) => {
|
|
|
789
795
|
}
|
|
790
796
|
return typeof slotContent === "function" ? slotContent(slotProps) : slotContent;
|
|
791
797
|
};
|
|
792
|
-
var InfiniteScroll = (0,
|
|
798
|
+
var InfiniteScroll = (0, import_react13.forwardRef)(
|
|
793
799
|
({
|
|
794
800
|
data,
|
|
795
801
|
buffer = 0,
|
|
@@ -810,32 +816,32 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
810
816
|
onlyPrevious = false,
|
|
811
817
|
...props
|
|
812
818
|
}, ref) => {
|
|
813
|
-
const [startElementFromRef, setStartElementFromRef] = (0,
|
|
814
|
-
const startElementRef = (0,
|
|
815
|
-
const [endElementFromRef, setEndElementFromRef] = (0,
|
|
816
|
-
const endElementRef = (0,
|
|
817
|
-
const [itemsElementFromRef, setItemsElementFromRef] = (0,
|
|
818
|
-
const itemsElementRef = (0,
|
|
819
|
-
const [loadingPrevious, setLoadingPrevious] = (0,
|
|
820
|
-
const [loadingNext, setLoadingNext] = (0,
|
|
821
|
-
const [requestCount, setRequestCount] = (0,
|
|
822
|
-
const [resolvedStartElement, setResolvedStartElement] = (0,
|
|
823
|
-
const [resolvedEndElement, setResolvedEndElement] = (0,
|
|
824
|
-
const [resolvedItemsElement, setResolvedItemsElement] = (0,
|
|
825
|
-
(0,
|
|
819
|
+
const [startElementFromRef, setStartElementFromRef] = (0, import_react13.useState)(null);
|
|
820
|
+
const startElementRef = (0, import_react13.useCallback)((node) => setStartElementFromRef(node), []);
|
|
821
|
+
const [endElementFromRef, setEndElementFromRef] = (0, import_react13.useState)(null);
|
|
822
|
+
const endElementRef = (0, import_react13.useCallback)((node) => setEndElementFromRef(node), []);
|
|
823
|
+
const [itemsElementFromRef, setItemsElementFromRef] = (0, import_react13.useState)(null);
|
|
824
|
+
const itemsElementRef = (0, import_react13.useCallback)((node) => setItemsElementFromRef(node), []);
|
|
825
|
+
const [loadingPrevious, setLoadingPrevious] = (0, import_react13.useState)(false);
|
|
826
|
+
const [loadingNext, setLoadingNext] = (0, import_react13.useState)(false);
|
|
827
|
+
const [requestCount, setRequestCount] = (0, import_react13.useState)(0);
|
|
828
|
+
const [resolvedStartElement, setResolvedStartElement] = (0, import_react13.useState)(null);
|
|
829
|
+
const [resolvedEndElement, setResolvedEndElement] = (0, import_react13.useState)(null);
|
|
830
|
+
const [resolvedItemsElement, setResolvedItemsElement] = (0, import_react13.useState)(null);
|
|
831
|
+
(0, import_react13.useEffect)(() => {
|
|
826
832
|
const element = startElement ? resolveHTMLElement(startElement, startElementFromRef) : startElementFromRef;
|
|
827
833
|
setResolvedStartElement(element);
|
|
828
834
|
}, [startElement, startElementFromRef]);
|
|
829
|
-
(0,
|
|
835
|
+
(0, import_react13.useEffect)(() => {
|
|
830
836
|
const element = endElement ? resolveHTMLElement(endElement, endElementFromRef) : endElementFromRef;
|
|
831
837
|
setResolvedEndElement(element);
|
|
832
838
|
}, [endElement, endElementFromRef]);
|
|
833
|
-
(0,
|
|
839
|
+
(0, import_react13.useEffect)(() => {
|
|
834
840
|
const element = itemsElement ? resolveHTMLElement(itemsElement, itemsElementFromRef) : itemsElementFromRef;
|
|
835
841
|
setResolvedItemsElement(element);
|
|
836
842
|
}, [itemsElement, itemsElementFromRef]);
|
|
837
|
-
const scrollableParent = (0,
|
|
838
|
-
const callbackPropsRef = (0,
|
|
843
|
+
const scrollableParent = (0, import_react13.useMemo)(() => (0, import_core6.getScrollableParent)(resolvedItemsElement), [resolvedItemsElement]);
|
|
844
|
+
const callbackPropsRef = (0, import_react13.useRef)({
|
|
839
845
|
buffer,
|
|
840
846
|
onlyNext,
|
|
841
847
|
onlyPrevious,
|
|
@@ -849,10 +855,10 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
849
855
|
reverse,
|
|
850
856
|
preserveUrl
|
|
851
857
|
};
|
|
852
|
-
const [infiniteScroll, setInfiniteScroll] = (0,
|
|
853
|
-
const dataManager = (0,
|
|
854
|
-
const elementManager = (0,
|
|
855
|
-
const scrollToBottom = (0,
|
|
858
|
+
const [infiniteScroll, setInfiniteScroll] = (0, import_react13.useState)(null);
|
|
859
|
+
const dataManager = (0, import_react13.useMemo)(() => infiniteScroll?.dataManager, [infiniteScroll]);
|
|
860
|
+
const elementManager = (0, import_react13.useMemo)(() => infiniteScroll?.elementManager, [infiniteScroll]);
|
|
861
|
+
const scrollToBottom = (0, import_react13.useCallback)(() => {
|
|
856
862
|
if (scrollableParent) {
|
|
857
863
|
scrollableParent.scrollTo({
|
|
858
864
|
top: scrollableParent.scrollHeight,
|
|
@@ -865,7 +871,7 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
865
871
|
});
|
|
866
872
|
}
|
|
867
873
|
}, [scrollableParent]);
|
|
868
|
-
(0,
|
|
874
|
+
(0, import_react13.useEffect)(() => {
|
|
869
875
|
if (!resolvedItemsElement) {
|
|
870
876
|
return;
|
|
871
877
|
}
|
|
@@ -903,26 +909,25 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
903
909
|
elementManager2.enableTriggers();
|
|
904
910
|
}
|
|
905
911
|
return () => {
|
|
906
|
-
|
|
907
|
-
elementManager2.flushAll();
|
|
912
|
+
infiniteScrollInstance.flush();
|
|
908
913
|
setInfiniteScroll(null);
|
|
909
914
|
};
|
|
910
915
|
}, [data, resolvedItemsElement, resolvedStartElement, resolvedEndElement, scrollableParent]);
|
|
911
|
-
const manualMode = (0,
|
|
916
|
+
const manualMode = (0, import_react13.useMemo)(
|
|
912
917
|
() => manual || manualAfter > 0 && requestCount >= manualAfter,
|
|
913
918
|
[manual, manualAfter, requestCount]
|
|
914
919
|
);
|
|
915
|
-
const autoLoad = (0,
|
|
916
|
-
(0,
|
|
920
|
+
const autoLoad = (0, import_react13.useMemo)(() => !manualMode, [manualMode]);
|
|
921
|
+
(0, import_react13.useEffect)(() => {
|
|
917
922
|
autoLoad ? elementManager?.enableTriggers() : elementManager?.disableTriggers();
|
|
918
923
|
}, [autoLoad, onlyNext, onlyPrevious, resolvedStartElement, resolvedEndElement]);
|
|
919
|
-
(0,
|
|
924
|
+
(0, import_react13.useEffect)(() => {
|
|
920
925
|
const shouldAutoScroll = autoScroll !== void 0 ? autoScroll : reverse;
|
|
921
926
|
if (shouldAutoScroll) {
|
|
922
927
|
scrollToBottom();
|
|
923
928
|
}
|
|
924
929
|
}, [scrollableParent]);
|
|
925
|
-
(0,
|
|
930
|
+
(0, import_react13.useImperativeHandle)(
|
|
926
931
|
ref,
|
|
927
932
|
() => ({
|
|
928
933
|
fetchNext: dataManager?.fetchNext || (() => {
|
|
@@ -968,7 +973,7 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
968
973
|
const renderElements = [];
|
|
969
974
|
if (!startElement) {
|
|
970
975
|
renderElements.push(
|
|
971
|
-
(0,
|
|
976
|
+
(0, import_react13.createElement)(
|
|
972
977
|
"div",
|
|
973
978
|
{ ref: startElementRef },
|
|
974
979
|
// Render previous slot or fallback to loading indicator
|
|
@@ -977,7 +982,7 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
977
982
|
);
|
|
978
983
|
}
|
|
979
984
|
renderElements.push(
|
|
980
|
-
(0,
|
|
985
|
+
(0, import_react13.createElement)(
|
|
981
986
|
as,
|
|
982
987
|
{ ...props, ref: itemsElementRef },
|
|
983
988
|
typeof children === "function" ? children(exposedSlot) : children
|
|
@@ -985,7 +990,7 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
985
990
|
);
|
|
986
991
|
if (!endElement) {
|
|
987
992
|
renderElements.push(
|
|
988
|
-
(0,
|
|
993
|
+
(0, import_react13.createElement)(
|
|
989
994
|
"div",
|
|
990
995
|
{ ref: endElementRef },
|
|
991
996
|
// Render next slot or fallback to loading indicator
|
|
@@ -993,7 +998,7 @@ var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
|
993
998
|
)
|
|
994
999
|
);
|
|
995
1000
|
}
|
|
996
|
-
return (0,
|
|
1001
|
+
return (0, import_react13.createElement)(import_react13.default.Fragment, {}, ...reverse ? [...renderElements].reverse() : renderElements);
|
|
997
1002
|
}
|
|
998
1003
|
);
|
|
999
1004
|
InfiniteScroll.displayName = "InertiaInfiniteScroll";
|
|
@@ -1001,9 +1006,9 @@ var InfiniteScroll_default = InfiniteScroll;
|
|
|
1001
1006
|
|
|
1002
1007
|
// src/Link.ts
|
|
1003
1008
|
var import_core7 = require("@inertiajs/core");
|
|
1004
|
-
var
|
|
1009
|
+
var import_react14 = require("react");
|
|
1005
1010
|
var noop2 = () => void 0;
|
|
1006
|
-
var Link = (0,
|
|
1011
|
+
var Link = (0, import_react14.forwardRef)(
|
|
1007
1012
|
({
|
|
1008
1013
|
children,
|
|
1009
1014
|
as = "a",
|
|
@@ -1012,6 +1017,7 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1012
1017
|
method = "get",
|
|
1013
1018
|
preserveScroll = false,
|
|
1014
1019
|
preserveState = null,
|
|
1020
|
+
preserveUrl = false,
|
|
1015
1021
|
replace = false,
|
|
1016
1022
|
only = [],
|
|
1017
1023
|
except = [],
|
|
@@ -1034,38 +1040,39 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1034
1040
|
cacheTags = [],
|
|
1035
1041
|
...props
|
|
1036
1042
|
}, ref) => {
|
|
1037
|
-
const [inFlightCount, setInFlightCount] = (0,
|
|
1038
|
-
const hoverTimeout = (0,
|
|
1039
|
-
const _method = (0,
|
|
1043
|
+
const [inFlightCount, setInFlightCount] = (0, import_react14.useState)(0);
|
|
1044
|
+
const hoverTimeout = (0, import_react14.useRef)(null);
|
|
1045
|
+
const _method = (0, import_react14.useMemo)(() => {
|
|
1040
1046
|
return (0, import_core7.isUrlMethodPair)(href) ? href.method : method.toLowerCase();
|
|
1041
1047
|
}, [href, method]);
|
|
1042
|
-
const _as = (0,
|
|
1048
|
+
const _as = (0, import_react14.useMemo)(() => {
|
|
1043
1049
|
if (typeof as !== "string" || as.toLowerCase() !== "a") {
|
|
1044
1050
|
return as;
|
|
1045
1051
|
}
|
|
1046
1052
|
return _method !== "get" ? "button" : as.toLowerCase();
|
|
1047
1053
|
}, [as, _method]);
|
|
1048
|
-
const mergeDataArray = (0,
|
|
1054
|
+
const mergeDataArray = (0, import_react14.useMemo)(
|
|
1049
1055
|
() => (0, import_core7.mergeDataIntoQueryString)(_method, (0, import_core7.isUrlMethodPair)(href) ? href.url : href, data, queryStringArrayFormat),
|
|
1050
1056
|
[href, _method, data, queryStringArrayFormat]
|
|
1051
1057
|
);
|
|
1052
|
-
const url = (0,
|
|
1053
|
-
const _data = (0,
|
|
1054
|
-
const baseParams = (0,
|
|
1058
|
+
const url = (0, import_react14.useMemo)(() => mergeDataArray[0], [mergeDataArray]);
|
|
1059
|
+
const _data = (0, import_react14.useMemo)(() => mergeDataArray[1], [mergeDataArray]);
|
|
1060
|
+
const baseParams = (0, import_react14.useMemo)(
|
|
1055
1061
|
() => ({
|
|
1056
1062
|
data: _data,
|
|
1057
1063
|
method: _method,
|
|
1058
1064
|
preserveScroll,
|
|
1059
1065
|
preserveState: preserveState ?? _method !== "get",
|
|
1066
|
+
preserveUrl,
|
|
1060
1067
|
replace,
|
|
1061
1068
|
only,
|
|
1062
1069
|
except,
|
|
1063
1070
|
headers,
|
|
1064
1071
|
async
|
|
1065
1072
|
}),
|
|
1066
|
-
[_data, _method, preserveScroll, preserveState, replace, only, except, headers, async]
|
|
1073
|
+
[_data, _method, preserveScroll, preserveState, preserveUrl, replace, only, except, headers, async]
|
|
1067
1074
|
);
|
|
1068
|
-
const visitParams = (0,
|
|
1075
|
+
const visitParams = (0, import_react14.useMemo)(
|
|
1069
1076
|
() => ({
|
|
1070
1077
|
...baseParams,
|
|
1071
1078
|
onCancelToken,
|
|
@@ -1085,7 +1092,7 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1085
1092
|
}),
|
|
1086
1093
|
[baseParams, onCancelToken, onBefore, onStart, onProgress, onFinish, onCancel, onSuccess, onError]
|
|
1087
1094
|
);
|
|
1088
|
-
const prefetchModes = (0,
|
|
1095
|
+
const prefetchModes = (0, import_react14.useMemo)(
|
|
1089
1096
|
() => {
|
|
1090
1097
|
if (prefetch === true) {
|
|
1091
1098
|
return ["hover"];
|
|
@@ -1100,7 +1107,7 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1100
1107
|
},
|
|
1101
1108
|
Array.isArray(prefetch) ? prefetch : [prefetch]
|
|
1102
1109
|
);
|
|
1103
|
-
const cacheForValue = (0,
|
|
1110
|
+
const cacheForValue = (0, import_react14.useMemo)(() => {
|
|
1104
1111
|
if (cacheFor !== 0) {
|
|
1105
1112
|
return cacheFor;
|
|
1106
1113
|
}
|
|
@@ -1109,7 +1116,7 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1109
1116
|
}
|
|
1110
1117
|
return 3e4;
|
|
1111
1118
|
}, [cacheFor, prefetchModes]);
|
|
1112
|
-
const doPrefetch = (0,
|
|
1119
|
+
const doPrefetch = (0, import_react14.useMemo)(() => {
|
|
1113
1120
|
return () => {
|
|
1114
1121
|
import_core7.router.prefetch(
|
|
1115
1122
|
url,
|
|
@@ -1122,12 +1129,12 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1122
1129
|
);
|
|
1123
1130
|
};
|
|
1124
1131
|
}, [url, baseParams, onPrefetching, onPrefetched, cacheForValue, cacheTags]);
|
|
1125
|
-
(0,
|
|
1132
|
+
(0, import_react14.useEffect)(() => {
|
|
1126
1133
|
return () => {
|
|
1127
1134
|
clearTimeout(hoverTimeout.current);
|
|
1128
1135
|
};
|
|
1129
1136
|
}, []);
|
|
1130
|
-
(0,
|
|
1137
|
+
(0, import_react14.useEffect)(() => {
|
|
1131
1138
|
if (prefetchModes.includes("mount")) {
|
|
1132
1139
|
setTimeout(() => doPrefetch());
|
|
1133
1140
|
}
|
|
@@ -1182,7 +1189,7 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1182
1189
|
}
|
|
1183
1190
|
}
|
|
1184
1191
|
};
|
|
1185
|
-
const elProps = (0,
|
|
1192
|
+
const elProps = (0, import_react14.useMemo)(() => {
|
|
1186
1193
|
if (_as === "button") {
|
|
1187
1194
|
return { type: "button" };
|
|
1188
1195
|
}
|
|
@@ -1191,7 +1198,7 @@ var Link = (0, import_react12.forwardRef)(
|
|
|
1191
1198
|
}
|
|
1192
1199
|
return {};
|
|
1193
1200
|
}, [_as, url]);
|
|
1194
|
-
return (0,
|
|
1201
|
+
return (0, import_react14.createElement)(
|
|
1195
1202
|
_as,
|
|
1196
1203
|
{
|
|
1197
1204
|
...props,
|
|
@@ -1217,18 +1224,18 @@ var Link_default = Link;
|
|
|
1217
1224
|
|
|
1218
1225
|
// src/usePoll.ts
|
|
1219
1226
|
var import_core8 = require("@inertiajs/core");
|
|
1220
|
-
var
|
|
1227
|
+
var import_react15 = require("react");
|
|
1221
1228
|
function usePoll(interval, requestOptions = {}, options = {
|
|
1222
1229
|
keepAlive: false,
|
|
1223
1230
|
autoStart: true
|
|
1224
1231
|
}) {
|
|
1225
|
-
const pollRef = (0,
|
|
1232
|
+
const pollRef = (0, import_react15.useRef)(
|
|
1226
1233
|
import_core8.router.poll(interval, requestOptions, {
|
|
1227
1234
|
...options,
|
|
1228
1235
|
autoStart: false
|
|
1229
1236
|
})
|
|
1230
1237
|
);
|
|
1231
|
-
(0,
|
|
1238
|
+
(0, import_react15.useEffect)(() => {
|
|
1232
1239
|
if (options.autoStart ?? true) {
|
|
1233
1240
|
pollRef.current.start();
|
|
1234
1241
|
}
|
|
@@ -1242,14 +1249,14 @@ function usePoll(interval, requestOptions = {}, options = {
|
|
|
1242
1249
|
|
|
1243
1250
|
// src/usePrefetch.ts
|
|
1244
1251
|
var import_core9 = require("@inertiajs/core");
|
|
1245
|
-
var
|
|
1252
|
+
var import_react16 = require("react");
|
|
1246
1253
|
function usePrefetch(options = {}) {
|
|
1247
1254
|
const cached = typeof window === "undefined" ? null : import_core9.router.getCached(window.location.pathname, options);
|
|
1248
1255
|
const inFlight = typeof window === "undefined" ? null : import_core9.router.getPrefetching(window.location.pathname, options);
|
|
1249
|
-
const [lastUpdatedAt, setLastUpdatedAt] = (0,
|
|
1250
|
-
const [isPrefetching, setIsPrefetching] = (0,
|
|
1251
|
-
const [isPrefetched, setIsPrefetched] = (0,
|
|
1252
|
-
(0,
|
|
1256
|
+
const [lastUpdatedAt, setLastUpdatedAt] = (0, import_react16.useState)(cached?.staleTimestamp || null);
|
|
1257
|
+
const [isPrefetching, setIsPrefetching] = (0, import_react16.useState)(inFlight !== null);
|
|
1258
|
+
const [isPrefetched, setIsPrefetched] = (0, import_react16.useState)(cached !== null);
|
|
1259
|
+
(0, import_react16.useEffect)(() => {
|
|
1253
1260
|
const onPrefetchingListener = import_core9.router.on("prefetching", (e) => {
|
|
1254
1261
|
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1255
1262
|
setIsPrefetching(true);
|
|
@@ -1277,16 +1284,16 @@ function usePrefetch(options = {}) {
|
|
|
1277
1284
|
|
|
1278
1285
|
// src/WhenVisible.ts
|
|
1279
1286
|
var import_core10 = require("@inertiajs/core");
|
|
1280
|
-
var
|
|
1287
|
+
var import_react17 = require("react");
|
|
1281
1288
|
var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
|
|
1282
1289
|
always = always ?? false;
|
|
1283
1290
|
as = as ?? "div";
|
|
1284
1291
|
fallback = fallback ?? null;
|
|
1285
|
-
const [loaded, setLoaded] = (0,
|
|
1286
|
-
const hasFetched = (0,
|
|
1287
|
-
const fetching = (0,
|
|
1288
|
-
const ref = (0,
|
|
1289
|
-
const getReloadParams = (0,
|
|
1292
|
+
const [loaded, setLoaded] = (0, import_react17.useState)(false);
|
|
1293
|
+
const hasFetched = (0, import_react17.useRef)(false);
|
|
1294
|
+
const fetching = (0, import_react17.useRef)(false);
|
|
1295
|
+
const ref = (0, import_react17.useRef)(null);
|
|
1296
|
+
const getReloadParams = (0, import_react17.useCallback)(() => {
|
|
1290
1297
|
if (data) {
|
|
1291
1298
|
return {
|
|
1292
1299
|
only: Array.isArray(data) ? data : [data]
|
|
@@ -1297,7 +1304,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1297
1304
|
}
|
|
1298
1305
|
return params;
|
|
1299
1306
|
}, [params, data]);
|
|
1300
|
-
(0,
|
|
1307
|
+
(0, import_react17.useEffect)(() => {
|
|
1301
1308
|
if (!ref.current) {
|
|
1302
1309
|
return;
|
|
1303
1310
|
}
|
|
@@ -1343,7 +1350,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1343
1350
|
const resolveChildren = () => typeof children === "function" ? children() : children;
|
|
1344
1351
|
const resolveFallback = () => typeof fallback === "function" ? fallback() : fallback;
|
|
1345
1352
|
if (always || !loaded) {
|
|
1346
|
-
return (0,
|
|
1353
|
+
return (0, import_react17.createElement)(
|
|
1347
1354
|
as,
|
|
1348
1355
|
{
|
|
1349
1356
|
props: null,
|