@inertiajs/react 2.1.10 → 2.2.0
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 +284 -40
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +295 -63
- package/dist/index.js.map +4 -4
- package/package.json +8 -8
- package/types/Form.d.ts +1 -1
- package/types/InfiniteScroll.d.ts +15 -0
- package/types/index.d.ts +13 -0
package/dist/index.js
CHANGED
|
@@ -32,9 +32,11 @@ __export(index_exports, {
|
|
|
32
32
|
Deferred: () => Deferred_default,
|
|
33
33
|
Form: () => Form_default,
|
|
34
34
|
Head: () => Head_default,
|
|
35
|
+
InfiniteScroll: () => InfiniteScroll_default,
|
|
35
36
|
Link: () => Link_default,
|
|
36
37
|
WhenVisible: () => WhenVisible_default,
|
|
37
38
|
createInertiaApp: () => createInertiaApp,
|
|
39
|
+
progress: () => progress,
|
|
38
40
|
router: () => router3,
|
|
39
41
|
useForm: () => useForm,
|
|
40
42
|
usePage: () => usePage,
|
|
@@ -43,7 +45,7 @@ __export(index_exports, {
|
|
|
43
45
|
useRemember: () => useRemember
|
|
44
46
|
});
|
|
45
47
|
module.exports = __toCommonJS(index_exports);
|
|
46
|
-
var
|
|
48
|
+
var import_core11 = require("@inertiajs/core");
|
|
47
49
|
|
|
48
50
|
// src/createInertiaApp.ts
|
|
49
51
|
var import_core2 = require("@inertiajs/core");
|
|
@@ -153,7 +155,7 @@ async function createInertiaApp({
|
|
|
153
155
|
resolve,
|
|
154
156
|
setup,
|
|
155
157
|
title,
|
|
156
|
-
progress = {},
|
|
158
|
+
progress: progress2 = {},
|
|
157
159
|
page,
|
|
158
160
|
render
|
|
159
161
|
}) {
|
|
@@ -180,8 +182,8 @@ async function createInertiaApp({
|
|
|
180
182
|
}
|
|
181
183
|
});
|
|
182
184
|
});
|
|
183
|
-
if (!isServer &&
|
|
184
|
-
(0, import_core2.setupProgress)(
|
|
185
|
+
if (!isServer && progress2) {
|
|
186
|
+
(0, import_core2.setupProgress)(progress2);
|
|
185
187
|
}
|
|
186
188
|
if (isServer) {
|
|
187
189
|
const body = await render(
|
|
@@ -288,7 +290,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
288
290
|
const [errors, setErrors] = rememberKey ? useRemember({}, `${rememberKey}:errors`) : (0, import_react8.useState)({});
|
|
289
291
|
const [hasErrors, setHasErrors] = (0, import_react8.useState)(false);
|
|
290
292
|
const [processing, setProcessing] = (0, import_react8.useState)(false);
|
|
291
|
-
const [
|
|
293
|
+
const [progress2, setProgress] = (0, import_react8.useState)(null);
|
|
292
294
|
const [wasSuccessful, setWasSuccessful] = (0, import_react8.useState)(false);
|
|
293
295
|
const [recentlySuccessful, setRecentlySuccessful] = (0, import_react8.useState)(false);
|
|
294
296
|
const transform = (0, import_react8.useRef)((data2) => data2);
|
|
@@ -513,7 +515,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
513
515
|
errors,
|
|
514
516
|
hasErrors,
|
|
515
517
|
processing,
|
|
516
|
-
progress,
|
|
518
|
+
progress: progress2,
|
|
517
519
|
wasSuccessful,
|
|
518
520
|
recentlySuccessful,
|
|
519
521
|
transform: transformFunction,
|
|
@@ -766,11 +768,240 @@ var Head = function({ children, title }) {
|
|
|
766
768
|
};
|
|
767
769
|
var Head_default = Head;
|
|
768
770
|
|
|
769
|
-
// src/
|
|
771
|
+
// src/InfiniteScroll.ts
|
|
770
772
|
var import_core6 = require("@inertiajs/core");
|
|
771
|
-
var import_react11 = require("react");
|
|
773
|
+
var import_react11 = __toESM(require("react"), 1);
|
|
774
|
+
var resolveHTMLElement = (value, fallback) => {
|
|
775
|
+
if (!value) {
|
|
776
|
+
return fallback;
|
|
777
|
+
}
|
|
778
|
+
if (value && typeof value === "object" && "current" in value) {
|
|
779
|
+
return value.current;
|
|
780
|
+
}
|
|
781
|
+
if (typeof value === "string") {
|
|
782
|
+
return document.querySelector(value);
|
|
783
|
+
}
|
|
784
|
+
return fallback;
|
|
785
|
+
};
|
|
786
|
+
var renderSlot = (slotContent, slotProps, fallback = null) => {
|
|
787
|
+
if (!slotContent) {
|
|
788
|
+
return fallback;
|
|
789
|
+
}
|
|
790
|
+
return typeof slotContent === "function" ? slotContent(slotProps) : slotContent;
|
|
791
|
+
};
|
|
792
|
+
var InfiniteScroll = (0, import_react11.forwardRef)(
|
|
793
|
+
({
|
|
794
|
+
data,
|
|
795
|
+
buffer = 0,
|
|
796
|
+
as = "div",
|
|
797
|
+
manual = false,
|
|
798
|
+
manualAfter = 0,
|
|
799
|
+
preserveUrl = false,
|
|
800
|
+
reverse = false,
|
|
801
|
+
autoScroll,
|
|
802
|
+
children,
|
|
803
|
+
startElement,
|
|
804
|
+
endElement,
|
|
805
|
+
itemsElement,
|
|
806
|
+
previous,
|
|
807
|
+
next,
|
|
808
|
+
loading,
|
|
809
|
+
onlyNext = false,
|
|
810
|
+
onlyPrevious = false,
|
|
811
|
+
...props
|
|
812
|
+
}, ref) => {
|
|
813
|
+
const [startElementFromRef, setStartElementFromRef] = (0, import_react11.useState)(null);
|
|
814
|
+
const startElementRef = (0, import_react11.useCallback)((node) => setStartElementFromRef(node), []);
|
|
815
|
+
const [endElementFromRef, setEndElementFromRef] = (0, import_react11.useState)(null);
|
|
816
|
+
const endElementRef = (0, import_react11.useCallback)((node) => setEndElementFromRef(node), []);
|
|
817
|
+
const [itemsElementFromRef, setItemsElementFromRef] = (0, import_react11.useState)(null);
|
|
818
|
+
const itemsElementRef = (0, import_react11.useCallback)((node) => setItemsElementFromRef(node), []);
|
|
819
|
+
const [loadingPrevious, setLoadingPrevious] = (0, import_react11.useState)(false);
|
|
820
|
+
const [loadingNext, setLoadingNext] = (0, import_react11.useState)(false);
|
|
821
|
+
const [requestCount, setRequestCount] = (0, import_react11.useState)(0);
|
|
822
|
+
const [resolvedStartElement, setResolvedStartElement] = (0, import_react11.useState)(null);
|
|
823
|
+
const [resolvedEndElement, setResolvedEndElement] = (0, import_react11.useState)(null);
|
|
824
|
+
const [resolvedItemsElement, setResolvedItemsElement] = (0, import_react11.useState)(null);
|
|
825
|
+
(0, import_react11.useEffect)(() => {
|
|
826
|
+
const element = startElement ? resolveHTMLElement(startElement, startElementFromRef) : startElementFromRef;
|
|
827
|
+
setResolvedStartElement(element);
|
|
828
|
+
}, [startElement, startElementFromRef]);
|
|
829
|
+
(0, import_react11.useEffect)(() => {
|
|
830
|
+
const element = endElement ? resolveHTMLElement(endElement, endElementFromRef) : endElementFromRef;
|
|
831
|
+
setResolvedEndElement(element);
|
|
832
|
+
}, [endElement, endElementFromRef]);
|
|
833
|
+
(0, import_react11.useEffect)(() => {
|
|
834
|
+
const element = itemsElement ? resolveHTMLElement(itemsElement, itemsElementFromRef) : itemsElementFromRef;
|
|
835
|
+
setResolvedItemsElement(element);
|
|
836
|
+
}, [itemsElement, itemsElementFromRef]);
|
|
837
|
+
const scrollableParent = (0, import_react11.useMemo)(() => (0, import_core6.getScrollableParent)(resolvedItemsElement), [resolvedItemsElement]);
|
|
838
|
+
const manualMode = (0, import_react11.useMemo)(
|
|
839
|
+
() => manual || manualAfter > 0 && requestCount >= manualAfter,
|
|
840
|
+
[manual, manualAfter, requestCount]
|
|
841
|
+
);
|
|
842
|
+
const autoLoad = (0, import_react11.useMemo)(() => !manualMode, [manualMode]);
|
|
843
|
+
const callbackPropsRef = (0, import_react11.useRef)({
|
|
844
|
+
buffer,
|
|
845
|
+
onlyNext,
|
|
846
|
+
onlyPrevious,
|
|
847
|
+
reverse,
|
|
848
|
+
preserveUrl
|
|
849
|
+
});
|
|
850
|
+
callbackPropsRef.current = {
|
|
851
|
+
buffer,
|
|
852
|
+
onlyNext,
|
|
853
|
+
onlyPrevious,
|
|
854
|
+
reverse,
|
|
855
|
+
preserveUrl
|
|
856
|
+
};
|
|
857
|
+
const [infiniteScroll, setInfiniteScroll] = (0, import_react11.useState)(null);
|
|
858
|
+
const dataManager = (0, import_react11.useMemo)(() => infiniteScroll?.dataManager, [infiniteScroll]);
|
|
859
|
+
const elementManager = (0, import_react11.useMemo)(() => infiniteScroll?.elementManager, [infiniteScroll]);
|
|
860
|
+
const scrollToBottom = (0, import_react11.useCallback)(() => {
|
|
861
|
+
if (scrollableParent) {
|
|
862
|
+
scrollableParent.scrollTo({
|
|
863
|
+
top: scrollableParent.scrollHeight,
|
|
864
|
+
behavior: "instant"
|
|
865
|
+
});
|
|
866
|
+
} else {
|
|
867
|
+
window.scrollTo({
|
|
868
|
+
top: document.body.scrollHeight,
|
|
869
|
+
behavior: "instant"
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
}, [scrollableParent]);
|
|
873
|
+
(0, import_react11.useEffect)(() => {
|
|
874
|
+
if (!resolvedItemsElement) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
const infiniteScrollInstance = (0, import_core6.useInfiniteScroll)({
|
|
878
|
+
// Data
|
|
879
|
+
getPropName: () => data,
|
|
880
|
+
inReverseMode: () => callbackPropsRef.current.reverse,
|
|
881
|
+
shouldFetchNext: () => !callbackPropsRef.current.onlyPrevious,
|
|
882
|
+
shouldFetchPrevious: () => !callbackPropsRef.current.onlyNext,
|
|
883
|
+
shouldPreserveUrl: () => callbackPropsRef.current.preserveUrl,
|
|
884
|
+
// Elements
|
|
885
|
+
getTriggerMargin: () => callbackPropsRef.current.buffer,
|
|
886
|
+
getStartElement: () => resolvedStartElement,
|
|
887
|
+
getEndElement: () => resolvedEndElement,
|
|
888
|
+
getItemsElement: () => resolvedItemsElement,
|
|
889
|
+
getScrollableParent: () => scrollableParent,
|
|
890
|
+
// Callbacks
|
|
891
|
+
onBeforePreviousRequest: () => setLoadingPrevious(true),
|
|
892
|
+
onBeforeNextRequest: () => setLoadingNext(true),
|
|
893
|
+
onCompletePreviousRequest: () => {
|
|
894
|
+
setLoadingPrevious(false);
|
|
895
|
+
setRequestCount((count) => count + 1);
|
|
896
|
+
},
|
|
897
|
+
onCompleteNextRequest: () => {
|
|
898
|
+
setLoadingNext(false);
|
|
899
|
+
setRequestCount((count) => count + 1);
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
setInfiniteScroll(infiniteScrollInstance);
|
|
903
|
+
const { dataManager: dataManager2, elementManager: elementManager2 } = infiniteScrollInstance;
|
|
904
|
+
elementManager2.setupObservers();
|
|
905
|
+
elementManager2.processServerLoadedElements(dataManager2.getLastLoadedPage());
|
|
906
|
+
if (autoLoad) {
|
|
907
|
+
elementManager2.enableTriggers();
|
|
908
|
+
}
|
|
909
|
+
return () => {
|
|
910
|
+
elementManager2.flushAll();
|
|
911
|
+
setInfiniteScroll(null);
|
|
912
|
+
};
|
|
913
|
+
}, [data, resolvedItemsElement, resolvedStartElement, resolvedEndElement, scrollableParent]);
|
|
914
|
+
(0, import_react11.useEffect)(() => {
|
|
915
|
+
autoLoad ? elementManager?.enableTriggers() : elementManager?.disableTriggers();
|
|
916
|
+
}, [autoLoad, onlyNext, onlyPrevious, resolvedStartElement, resolvedEndElement]);
|
|
917
|
+
(0, import_react11.useEffect)(() => {
|
|
918
|
+
const shouldAutoScroll = autoScroll !== void 0 ? autoScroll : reverse;
|
|
919
|
+
if (shouldAutoScroll) {
|
|
920
|
+
scrollToBottom();
|
|
921
|
+
}
|
|
922
|
+
}, [scrollableParent]);
|
|
923
|
+
(0, import_react11.useImperativeHandle)(
|
|
924
|
+
ref,
|
|
925
|
+
() => ({
|
|
926
|
+
fetchNext: dataManager?.fetchNext || (() => {
|
|
927
|
+
}),
|
|
928
|
+
fetchPrevious: dataManager?.fetchPrevious || (() => {
|
|
929
|
+
}),
|
|
930
|
+
hasPrevious: dataManager?.hasPrevious || (() => false),
|
|
931
|
+
hasNext: dataManager?.hasNext || (() => false)
|
|
932
|
+
}),
|
|
933
|
+
[dataManager]
|
|
934
|
+
);
|
|
935
|
+
const headerAutoMode = autoLoad && !onlyNext;
|
|
936
|
+
const footerAutoMode = autoLoad && !onlyPrevious;
|
|
937
|
+
const sharedExposed = {
|
|
938
|
+
loadingPrevious,
|
|
939
|
+
loadingNext,
|
|
940
|
+
hasPrevious: dataManager?.hasPrevious() ?? false,
|
|
941
|
+
hasNext: dataManager?.hasNext() ?? false
|
|
942
|
+
};
|
|
943
|
+
const exposedPrevious = {
|
|
944
|
+
loading: loadingPrevious,
|
|
945
|
+
fetch: dataManager?.fetchPrevious ?? (() => {
|
|
946
|
+
}),
|
|
947
|
+
autoMode: headerAutoMode,
|
|
948
|
+
manualMode: !headerAutoMode,
|
|
949
|
+
hasMore: dataManager?.hasPrevious() ?? false,
|
|
950
|
+
...sharedExposed
|
|
951
|
+
};
|
|
952
|
+
const exposedNext = {
|
|
953
|
+
loading: loadingNext,
|
|
954
|
+
fetch: dataManager?.fetchNext ?? (() => {
|
|
955
|
+
}),
|
|
956
|
+
autoMode: footerAutoMode,
|
|
957
|
+
manualMode: !footerAutoMode,
|
|
958
|
+
hasMore: dataManager?.hasNext() ?? false,
|
|
959
|
+
...sharedExposed
|
|
960
|
+
};
|
|
961
|
+
const exposedSlot = {
|
|
962
|
+
loading: loadingPrevious || loadingNext,
|
|
963
|
+
loadingPrevious,
|
|
964
|
+
loadingNext
|
|
965
|
+
};
|
|
966
|
+
const renderElements = [];
|
|
967
|
+
if (!startElement) {
|
|
968
|
+
renderElements.push(
|
|
969
|
+
(0, import_react11.createElement)(
|
|
970
|
+
"div",
|
|
971
|
+
{ ref: startElementRef },
|
|
972
|
+
// Render previous slot or fallback to loading indicator
|
|
973
|
+
renderSlot(previous, exposedPrevious, loadingPrevious ? renderSlot(loading, exposedPrevious) : null)
|
|
974
|
+
)
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
renderElements.push(
|
|
978
|
+
(0, import_react11.createElement)(
|
|
979
|
+
as,
|
|
980
|
+
{ ...props, ref: itemsElementRef },
|
|
981
|
+
typeof children === "function" ? children(exposedSlot) : children
|
|
982
|
+
)
|
|
983
|
+
);
|
|
984
|
+
if (!endElement) {
|
|
985
|
+
renderElements.push(
|
|
986
|
+
(0, import_react11.createElement)(
|
|
987
|
+
"div",
|
|
988
|
+
{ ref: endElementRef },
|
|
989
|
+
// Render next slot or fallback to loading indicator
|
|
990
|
+
renderSlot(next, exposedNext, loadingNext ? renderSlot(loading, exposedNext) : null)
|
|
991
|
+
)
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
return (0, import_react11.createElement)(import_react11.default.Fragment, {}, ...reverse ? [...renderElements].reverse() : renderElements);
|
|
995
|
+
}
|
|
996
|
+
);
|
|
997
|
+
InfiniteScroll.displayName = "InertiaInfiniteScroll";
|
|
998
|
+
var InfiniteScroll_default = InfiniteScroll;
|
|
999
|
+
|
|
1000
|
+
// src/Link.ts
|
|
1001
|
+
var import_core7 = require("@inertiajs/core");
|
|
1002
|
+
var import_react12 = require("react");
|
|
772
1003
|
var noop2 = () => void 0;
|
|
773
|
-
var Link = (0,
|
|
1004
|
+
var Link = (0, import_react12.forwardRef)(
|
|
774
1005
|
({
|
|
775
1006
|
children,
|
|
776
1007
|
as = "a",
|
|
@@ -801,24 +1032,24 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
801
1032
|
cacheTags = [],
|
|
802
1033
|
...props
|
|
803
1034
|
}, ref) => {
|
|
804
|
-
const [inFlightCount, setInFlightCount] = (0,
|
|
805
|
-
const hoverTimeout = (0,
|
|
806
|
-
const _method = (0,
|
|
807
|
-
return (0,
|
|
1035
|
+
const [inFlightCount, setInFlightCount] = (0, import_react12.useState)(0);
|
|
1036
|
+
const hoverTimeout = (0, import_react12.useRef)(null);
|
|
1037
|
+
const _method = (0, import_react12.useMemo)(() => {
|
|
1038
|
+
return (0, import_core7.isUrlMethodPair)(href) ? href.method : method.toLowerCase();
|
|
808
1039
|
}, [href, method]);
|
|
809
|
-
const _as = (0,
|
|
1040
|
+
const _as = (0, import_react12.useMemo)(() => {
|
|
810
1041
|
if (typeof as !== "string" || as.toLowerCase() !== "a") {
|
|
811
1042
|
return as;
|
|
812
1043
|
}
|
|
813
1044
|
return _method !== "get" ? "button" : as.toLowerCase();
|
|
814
1045
|
}, [as, _method]);
|
|
815
|
-
const mergeDataArray = (0,
|
|
816
|
-
() => (0,
|
|
1046
|
+
const mergeDataArray = (0, import_react12.useMemo)(
|
|
1047
|
+
() => (0, import_core7.mergeDataIntoQueryString)(_method, (0, import_core7.isUrlMethodPair)(href) ? href.url : href, data, queryStringArrayFormat),
|
|
817
1048
|
[href, _method, data, queryStringArrayFormat]
|
|
818
1049
|
);
|
|
819
|
-
const url = (0,
|
|
820
|
-
const _data = (0,
|
|
821
|
-
const baseParams = (0,
|
|
1050
|
+
const url = (0, import_react12.useMemo)(() => mergeDataArray[0], [mergeDataArray]);
|
|
1051
|
+
const _data = (0, import_react12.useMemo)(() => mergeDataArray[1], [mergeDataArray]);
|
|
1052
|
+
const baseParams = (0, import_react12.useMemo)(
|
|
822
1053
|
() => ({
|
|
823
1054
|
data: _data,
|
|
824
1055
|
method: _method,
|
|
@@ -832,7 +1063,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
832
1063
|
}),
|
|
833
1064
|
[_data, _method, preserveScroll, preserveState, replace, only, except, headers, async]
|
|
834
1065
|
);
|
|
835
|
-
const visitParams = (0,
|
|
1066
|
+
const visitParams = (0, import_react12.useMemo)(
|
|
836
1067
|
() => ({
|
|
837
1068
|
...baseParams,
|
|
838
1069
|
onCancelToken,
|
|
@@ -852,7 +1083,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
852
1083
|
}),
|
|
853
1084
|
[baseParams, onCancelToken, onBefore, onStart, onProgress, onFinish, onCancel, onSuccess, onError]
|
|
854
1085
|
);
|
|
855
|
-
const prefetchModes = (0,
|
|
1086
|
+
const prefetchModes = (0, import_react12.useMemo)(
|
|
856
1087
|
() => {
|
|
857
1088
|
if (prefetch === true) {
|
|
858
1089
|
return ["hover"];
|
|
@@ -867,7 +1098,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
867
1098
|
},
|
|
868
1099
|
Array.isArray(prefetch) ? prefetch : [prefetch]
|
|
869
1100
|
);
|
|
870
|
-
const cacheForValue = (0,
|
|
1101
|
+
const cacheForValue = (0, import_react12.useMemo)(() => {
|
|
871
1102
|
if (cacheFor !== 0) {
|
|
872
1103
|
return cacheFor;
|
|
873
1104
|
}
|
|
@@ -876,9 +1107,9 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
876
1107
|
}
|
|
877
1108
|
return 3e4;
|
|
878
1109
|
}, [cacheFor, prefetchModes]);
|
|
879
|
-
const doPrefetch = (0,
|
|
1110
|
+
const doPrefetch = (0, import_react12.useMemo)(() => {
|
|
880
1111
|
return () => {
|
|
881
|
-
|
|
1112
|
+
import_core7.router.prefetch(
|
|
882
1113
|
url,
|
|
883
1114
|
{
|
|
884
1115
|
...baseParams,
|
|
@@ -889,12 +1120,12 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
889
1120
|
);
|
|
890
1121
|
};
|
|
891
1122
|
}, [url, baseParams, onPrefetching, onPrefetched, cacheForValue, cacheTags]);
|
|
892
|
-
(0,
|
|
1123
|
+
(0, import_react12.useEffect)(() => {
|
|
893
1124
|
return () => {
|
|
894
1125
|
clearTimeout(hoverTimeout.current);
|
|
895
1126
|
};
|
|
896
1127
|
}, []);
|
|
897
|
-
(0,
|
|
1128
|
+
(0, import_react12.useEffect)(() => {
|
|
898
1129
|
if (prefetchModes.includes("mount")) {
|
|
899
1130
|
setTimeout(() => doPrefetch());
|
|
900
1131
|
}
|
|
@@ -902,9 +1133,9 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
902
1133
|
const regularEvents = {
|
|
903
1134
|
onClick: (event) => {
|
|
904
1135
|
onClick(event);
|
|
905
|
-
if ((0,
|
|
1136
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
906
1137
|
event.preventDefault();
|
|
907
|
-
|
|
1138
|
+
import_core7.router.visit(url, visitParams);
|
|
908
1139
|
}
|
|
909
1140
|
}
|
|
910
1141
|
};
|
|
@@ -921,35 +1152,35 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
921
1152
|
};
|
|
922
1153
|
const prefetchClickEvents = {
|
|
923
1154
|
onMouseDown: (event) => {
|
|
924
|
-
if ((0,
|
|
1155
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
925
1156
|
event.preventDefault();
|
|
926
1157
|
doPrefetch();
|
|
927
1158
|
}
|
|
928
1159
|
},
|
|
929
1160
|
onKeyDown: (event) => {
|
|
930
|
-
if ((0,
|
|
1161
|
+
if ((0, import_core7.shouldIntercept)(event) && (0, import_core7.shouldNavigate)(event)) {
|
|
931
1162
|
event.preventDefault();
|
|
932
1163
|
doPrefetch();
|
|
933
1164
|
}
|
|
934
1165
|
},
|
|
935
1166
|
onMouseUp: (event) => {
|
|
936
1167
|
event.preventDefault();
|
|
937
|
-
|
|
1168
|
+
import_core7.router.visit(url, visitParams);
|
|
938
1169
|
},
|
|
939
1170
|
onKeyUp: (event) => {
|
|
940
|
-
if ((0,
|
|
1171
|
+
if ((0, import_core7.shouldNavigate)(event)) {
|
|
941
1172
|
event.preventDefault();
|
|
942
|
-
|
|
1173
|
+
import_core7.router.visit(url, visitParams);
|
|
943
1174
|
}
|
|
944
1175
|
},
|
|
945
1176
|
onClick: (event) => {
|
|
946
1177
|
onClick(event);
|
|
947
|
-
if ((0,
|
|
1178
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
948
1179
|
event.preventDefault();
|
|
949
1180
|
}
|
|
950
1181
|
}
|
|
951
1182
|
};
|
|
952
|
-
const elProps = (0,
|
|
1183
|
+
const elProps = (0, import_react12.useMemo)(() => {
|
|
953
1184
|
if (_as === "button") {
|
|
954
1185
|
return { type: "button" };
|
|
955
1186
|
}
|
|
@@ -958,7 +1189,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
958
1189
|
}
|
|
959
1190
|
return {};
|
|
960
1191
|
}, [_as, url]);
|
|
961
|
-
return (0,
|
|
1192
|
+
return (0, import_react12.createElement)(
|
|
962
1193
|
_as,
|
|
963
1194
|
{
|
|
964
1195
|
...props,
|
|
@@ -983,19 +1214,19 @@ Link.displayName = "InertiaLink";
|
|
|
983
1214
|
var Link_default = Link;
|
|
984
1215
|
|
|
985
1216
|
// src/usePoll.ts
|
|
986
|
-
var
|
|
987
|
-
var
|
|
1217
|
+
var import_core8 = require("@inertiajs/core");
|
|
1218
|
+
var import_react13 = require("react");
|
|
988
1219
|
function usePoll(interval, requestOptions = {}, options = {
|
|
989
1220
|
keepAlive: false,
|
|
990
1221
|
autoStart: true
|
|
991
1222
|
}) {
|
|
992
|
-
const pollRef = (0,
|
|
993
|
-
|
|
1223
|
+
const pollRef = (0, import_react13.useRef)(
|
|
1224
|
+
import_core8.router.poll(interval, requestOptions, {
|
|
994
1225
|
...options,
|
|
995
1226
|
autoStart: false
|
|
996
1227
|
})
|
|
997
1228
|
);
|
|
998
|
-
(0,
|
|
1229
|
+
(0, import_react13.useEffect)(() => {
|
|
999
1230
|
if (options.autoStart ?? true) {
|
|
1000
1231
|
pollRef.current.start();
|
|
1001
1232
|
}
|
|
@@ -1008,21 +1239,21 @@ function usePoll(interval, requestOptions = {}, options = {
|
|
|
1008
1239
|
}
|
|
1009
1240
|
|
|
1010
1241
|
// src/usePrefetch.ts
|
|
1011
|
-
var
|
|
1012
|
-
var
|
|
1242
|
+
var import_core9 = require("@inertiajs/core");
|
|
1243
|
+
var import_react14 = require("react");
|
|
1013
1244
|
function usePrefetch(options = {}) {
|
|
1014
|
-
const cached = typeof window === "undefined" ? null :
|
|
1015
|
-
const inFlight = typeof window === "undefined" ? null :
|
|
1016
|
-
const [lastUpdatedAt, setLastUpdatedAt] = (0,
|
|
1017
|
-
const [isPrefetching, setIsPrefetching] = (0,
|
|
1018
|
-
const [isPrefetched, setIsPrefetched] = (0,
|
|
1019
|
-
(0,
|
|
1020
|
-
const onPrefetchingListener =
|
|
1245
|
+
const cached = typeof window === "undefined" ? null : import_core9.router.getCached(window.location.pathname, options);
|
|
1246
|
+
const inFlight = typeof window === "undefined" ? null : import_core9.router.getPrefetching(window.location.pathname, options);
|
|
1247
|
+
const [lastUpdatedAt, setLastUpdatedAt] = (0, import_react14.useState)(cached?.staleTimestamp || null);
|
|
1248
|
+
const [isPrefetching, setIsPrefetching] = (0, import_react14.useState)(inFlight !== null);
|
|
1249
|
+
const [isPrefetched, setIsPrefetched] = (0, import_react14.useState)(cached !== null);
|
|
1250
|
+
(0, import_react14.useEffect)(() => {
|
|
1251
|
+
const onPrefetchingListener = import_core9.router.on("prefetching", (e) => {
|
|
1021
1252
|
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1022
1253
|
setIsPrefetching(true);
|
|
1023
1254
|
}
|
|
1024
1255
|
});
|
|
1025
|
-
const onPrefetchedListener =
|
|
1256
|
+
const onPrefetchedListener = import_core9.router.on("prefetched", (e) => {
|
|
1026
1257
|
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1027
1258
|
setIsPrefetching(false);
|
|
1028
1259
|
setIsPrefetched(true);
|
|
@@ -1038,22 +1269,22 @@ function usePrefetch(options = {}) {
|
|
|
1038
1269
|
lastUpdatedAt,
|
|
1039
1270
|
isPrefetching,
|
|
1040
1271
|
isPrefetched,
|
|
1041
|
-
flush: () =>
|
|
1272
|
+
flush: () => import_core9.router.flush(window.location.pathname, options)
|
|
1042
1273
|
};
|
|
1043
1274
|
}
|
|
1044
1275
|
|
|
1045
1276
|
// src/WhenVisible.ts
|
|
1046
|
-
var
|
|
1047
|
-
var
|
|
1277
|
+
var import_core10 = require("@inertiajs/core");
|
|
1278
|
+
var import_react15 = require("react");
|
|
1048
1279
|
var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
|
|
1049
1280
|
always = always ?? false;
|
|
1050
1281
|
as = as ?? "div";
|
|
1051
1282
|
fallback = fallback ?? null;
|
|
1052
|
-
const [loaded, setLoaded] = (0,
|
|
1053
|
-
const hasFetched = (0,
|
|
1054
|
-
const fetching = (0,
|
|
1055
|
-
const ref = (0,
|
|
1056
|
-
const getReloadParams = (0,
|
|
1283
|
+
const [loaded, setLoaded] = (0, import_react15.useState)(false);
|
|
1284
|
+
const hasFetched = (0, import_react15.useRef)(false);
|
|
1285
|
+
const fetching = (0, import_react15.useRef)(false);
|
|
1286
|
+
const ref = (0, import_react15.useRef)(null);
|
|
1287
|
+
const getReloadParams = (0, import_react15.useCallback)(() => {
|
|
1057
1288
|
if (data) {
|
|
1058
1289
|
return {
|
|
1059
1290
|
only: Array.isArray(data) ? data : [data]
|
|
@@ -1064,7 +1295,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1064
1295
|
}
|
|
1065
1296
|
return params;
|
|
1066
1297
|
}, [params, data]);
|
|
1067
|
-
(0,
|
|
1298
|
+
(0, import_react15.useEffect)(() => {
|
|
1068
1299
|
if (!ref.current) {
|
|
1069
1300
|
return;
|
|
1070
1301
|
}
|
|
@@ -1082,7 +1313,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1082
1313
|
hasFetched.current = true;
|
|
1083
1314
|
fetching.current = true;
|
|
1084
1315
|
const reloadParams = getReloadParams();
|
|
1085
|
-
|
|
1316
|
+
import_core10.router.reload({
|
|
1086
1317
|
...reloadParams,
|
|
1087
1318
|
onStart: (e) => {
|
|
1088
1319
|
fetching.current = true;
|
|
@@ -1110,7 +1341,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1110
1341
|
const resolveChildren = () => typeof children === "function" ? children() : children;
|
|
1111
1342
|
const resolveFallback = () => typeof fallback === "function" ? fallback() : fallback;
|
|
1112
1343
|
if (always || !loaded) {
|
|
1113
|
-
return (0,
|
|
1344
|
+
return (0, import_react15.createElement)(
|
|
1114
1345
|
as,
|
|
1115
1346
|
{
|
|
1116
1347
|
props: null,
|
|
@@ -1125,5 +1356,6 @@ WhenVisible.displayName = "InertiaWhenVisible";
|
|
|
1125
1356
|
var WhenVisible_default = WhenVisible;
|
|
1126
1357
|
|
|
1127
1358
|
// src/index.ts
|
|
1128
|
-
var
|
|
1359
|
+
var progress = import_core11.progress;
|
|
1360
|
+
var router3 = import_core11.router;
|
|
1129
1361
|
//# sourceMappingURL=index.js.map
|