@inertiajs/react 2.1.11 → 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 +276 -34
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +289 -59
- 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 +1 -0
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ __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,
|
|
@@ -44,7 +45,7 @@ __export(index_exports, {
|
|
|
44
45
|
useRemember: () => useRemember
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(index_exports);
|
|
47
|
-
var
|
|
48
|
+
var import_core11 = require("@inertiajs/core");
|
|
48
49
|
|
|
49
50
|
// src/createInertiaApp.ts
|
|
50
51
|
var import_core2 = require("@inertiajs/core");
|
|
@@ -767,11 +768,240 @@ var Head = function({ children, title }) {
|
|
|
767
768
|
};
|
|
768
769
|
var Head_default = Head;
|
|
769
770
|
|
|
770
|
-
// src/
|
|
771
|
+
// src/InfiniteScroll.ts
|
|
771
772
|
var import_core6 = require("@inertiajs/core");
|
|
772
|
-
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");
|
|
773
1003
|
var noop2 = () => void 0;
|
|
774
|
-
var Link = (0,
|
|
1004
|
+
var Link = (0, import_react12.forwardRef)(
|
|
775
1005
|
({
|
|
776
1006
|
children,
|
|
777
1007
|
as = "a",
|
|
@@ -802,24 +1032,24 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
802
1032
|
cacheTags = [],
|
|
803
1033
|
...props
|
|
804
1034
|
}, ref) => {
|
|
805
|
-
const [inFlightCount, setInFlightCount] = (0,
|
|
806
|
-
const hoverTimeout = (0,
|
|
807
|
-
const _method = (0,
|
|
808
|
-
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();
|
|
809
1039
|
}, [href, method]);
|
|
810
|
-
const _as = (0,
|
|
1040
|
+
const _as = (0, import_react12.useMemo)(() => {
|
|
811
1041
|
if (typeof as !== "string" || as.toLowerCase() !== "a") {
|
|
812
1042
|
return as;
|
|
813
1043
|
}
|
|
814
1044
|
return _method !== "get" ? "button" : as.toLowerCase();
|
|
815
1045
|
}, [as, _method]);
|
|
816
|
-
const mergeDataArray = (0,
|
|
817
|
-
() => (0,
|
|
1046
|
+
const mergeDataArray = (0, import_react12.useMemo)(
|
|
1047
|
+
() => (0, import_core7.mergeDataIntoQueryString)(_method, (0, import_core7.isUrlMethodPair)(href) ? href.url : href, data, queryStringArrayFormat),
|
|
818
1048
|
[href, _method, data, queryStringArrayFormat]
|
|
819
1049
|
);
|
|
820
|
-
const url = (0,
|
|
821
|
-
const _data = (0,
|
|
822
|
-
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)(
|
|
823
1053
|
() => ({
|
|
824
1054
|
data: _data,
|
|
825
1055
|
method: _method,
|
|
@@ -833,7 +1063,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
833
1063
|
}),
|
|
834
1064
|
[_data, _method, preserveScroll, preserveState, replace, only, except, headers, async]
|
|
835
1065
|
);
|
|
836
|
-
const visitParams = (0,
|
|
1066
|
+
const visitParams = (0, import_react12.useMemo)(
|
|
837
1067
|
() => ({
|
|
838
1068
|
...baseParams,
|
|
839
1069
|
onCancelToken,
|
|
@@ -853,7 +1083,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
853
1083
|
}),
|
|
854
1084
|
[baseParams, onCancelToken, onBefore, onStart, onProgress, onFinish, onCancel, onSuccess, onError]
|
|
855
1085
|
);
|
|
856
|
-
const prefetchModes = (0,
|
|
1086
|
+
const prefetchModes = (0, import_react12.useMemo)(
|
|
857
1087
|
() => {
|
|
858
1088
|
if (prefetch === true) {
|
|
859
1089
|
return ["hover"];
|
|
@@ -868,7 +1098,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
868
1098
|
},
|
|
869
1099
|
Array.isArray(prefetch) ? prefetch : [prefetch]
|
|
870
1100
|
);
|
|
871
|
-
const cacheForValue = (0,
|
|
1101
|
+
const cacheForValue = (0, import_react12.useMemo)(() => {
|
|
872
1102
|
if (cacheFor !== 0) {
|
|
873
1103
|
return cacheFor;
|
|
874
1104
|
}
|
|
@@ -877,9 +1107,9 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
877
1107
|
}
|
|
878
1108
|
return 3e4;
|
|
879
1109
|
}, [cacheFor, prefetchModes]);
|
|
880
|
-
const doPrefetch = (0,
|
|
1110
|
+
const doPrefetch = (0, import_react12.useMemo)(() => {
|
|
881
1111
|
return () => {
|
|
882
|
-
|
|
1112
|
+
import_core7.router.prefetch(
|
|
883
1113
|
url,
|
|
884
1114
|
{
|
|
885
1115
|
...baseParams,
|
|
@@ -890,12 +1120,12 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
890
1120
|
);
|
|
891
1121
|
};
|
|
892
1122
|
}, [url, baseParams, onPrefetching, onPrefetched, cacheForValue, cacheTags]);
|
|
893
|
-
(0,
|
|
1123
|
+
(0, import_react12.useEffect)(() => {
|
|
894
1124
|
return () => {
|
|
895
1125
|
clearTimeout(hoverTimeout.current);
|
|
896
1126
|
};
|
|
897
1127
|
}, []);
|
|
898
|
-
(0,
|
|
1128
|
+
(0, import_react12.useEffect)(() => {
|
|
899
1129
|
if (prefetchModes.includes("mount")) {
|
|
900
1130
|
setTimeout(() => doPrefetch());
|
|
901
1131
|
}
|
|
@@ -903,9 +1133,9 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
903
1133
|
const regularEvents = {
|
|
904
1134
|
onClick: (event) => {
|
|
905
1135
|
onClick(event);
|
|
906
|
-
if ((0,
|
|
1136
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
907
1137
|
event.preventDefault();
|
|
908
|
-
|
|
1138
|
+
import_core7.router.visit(url, visitParams);
|
|
909
1139
|
}
|
|
910
1140
|
}
|
|
911
1141
|
};
|
|
@@ -922,35 +1152,35 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
922
1152
|
};
|
|
923
1153
|
const prefetchClickEvents = {
|
|
924
1154
|
onMouseDown: (event) => {
|
|
925
|
-
if ((0,
|
|
1155
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
926
1156
|
event.preventDefault();
|
|
927
1157
|
doPrefetch();
|
|
928
1158
|
}
|
|
929
1159
|
},
|
|
930
1160
|
onKeyDown: (event) => {
|
|
931
|
-
if ((0,
|
|
1161
|
+
if ((0, import_core7.shouldIntercept)(event) && (0, import_core7.shouldNavigate)(event)) {
|
|
932
1162
|
event.preventDefault();
|
|
933
1163
|
doPrefetch();
|
|
934
1164
|
}
|
|
935
1165
|
},
|
|
936
1166
|
onMouseUp: (event) => {
|
|
937
1167
|
event.preventDefault();
|
|
938
|
-
|
|
1168
|
+
import_core7.router.visit(url, visitParams);
|
|
939
1169
|
},
|
|
940
1170
|
onKeyUp: (event) => {
|
|
941
|
-
if ((0,
|
|
1171
|
+
if ((0, import_core7.shouldNavigate)(event)) {
|
|
942
1172
|
event.preventDefault();
|
|
943
|
-
|
|
1173
|
+
import_core7.router.visit(url, visitParams);
|
|
944
1174
|
}
|
|
945
1175
|
},
|
|
946
1176
|
onClick: (event) => {
|
|
947
1177
|
onClick(event);
|
|
948
|
-
if ((0,
|
|
1178
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
949
1179
|
event.preventDefault();
|
|
950
1180
|
}
|
|
951
1181
|
}
|
|
952
1182
|
};
|
|
953
|
-
const elProps = (0,
|
|
1183
|
+
const elProps = (0, import_react12.useMemo)(() => {
|
|
954
1184
|
if (_as === "button") {
|
|
955
1185
|
return { type: "button" };
|
|
956
1186
|
}
|
|
@@ -959,7 +1189,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
959
1189
|
}
|
|
960
1190
|
return {};
|
|
961
1191
|
}, [_as, url]);
|
|
962
|
-
return (0,
|
|
1192
|
+
return (0, import_react12.createElement)(
|
|
963
1193
|
_as,
|
|
964
1194
|
{
|
|
965
1195
|
...props,
|
|
@@ -984,19 +1214,19 @@ Link.displayName = "InertiaLink";
|
|
|
984
1214
|
var Link_default = Link;
|
|
985
1215
|
|
|
986
1216
|
// src/usePoll.ts
|
|
987
|
-
var
|
|
988
|
-
var
|
|
1217
|
+
var import_core8 = require("@inertiajs/core");
|
|
1218
|
+
var import_react13 = require("react");
|
|
989
1219
|
function usePoll(interval, requestOptions = {}, options = {
|
|
990
1220
|
keepAlive: false,
|
|
991
1221
|
autoStart: true
|
|
992
1222
|
}) {
|
|
993
|
-
const pollRef = (0,
|
|
994
|
-
|
|
1223
|
+
const pollRef = (0, import_react13.useRef)(
|
|
1224
|
+
import_core8.router.poll(interval, requestOptions, {
|
|
995
1225
|
...options,
|
|
996
1226
|
autoStart: false
|
|
997
1227
|
})
|
|
998
1228
|
);
|
|
999
|
-
(0,
|
|
1229
|
+
(0, import_react13.useEffect)(() => {
|
|
1000
1230
|
if (options.autoStart ?? true) {
|
|
1001
1231
|
pollRef.current.start();
|
|
1002
1232
|
}
|
|
@@ -1009,21 +1239,21 @@ function usePoll(interval, requestOptions = {}, options = {
|
|
|
1009
1239
|
}
|
|
1010
1240
|
|
|
1011
1241
|
// src/usePrefetch.ts
|
|
1012
|
-
var
|
|
1013
|
-
var
|
|
1242
|
+
var import_core9 = require("@inertiajs/core");
|
|
1243
|
+
var import_react14 = require("react");
|
|
1014
1244
|
function usePrefetch(options = {}) {
|
|
1015
|
-
const cached = typeof window === "undefined" ? null :
|
|
1016
|
-
const inFlight = typeof window === "undefined" ? null :
|
|
1017
|
-
const [lastUpdatedAt, setLastUpdatedAt] = (0,
|
|
1018
|
-
const [isPrefetching, setIsPrefetching] = (0,
|
|
1019
|
-
const [isPrefetched, setIsPrefetched] = (0,
|
|
1020
|
-
(0,
|
|
1021
|
-
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) => {
|
|
1022
1252
|
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1023
1253
|
setIsPrefetching(true);
|
|
1024
1254
|
}
|
|
1025
1255
|
});
|
|
1026
|
-
const onPrefetchedListener =
|
|
1256
|
+
const onPrefetchedListener = import_core9.router.on("prefetched", (e) => {
|
|
1027
1257
|
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1028
1258
|
setIsPrefetching(false);
|
|
1029
1259
|
setIsPrefetched(true);
|
|
@@ -1039,22 +1269,22 @@ function usePrefetch(options = {}) {
|
|
|
1039
1269
|
lastUpdatedAt,
|
|
1040
1270
|
isPrefetching,
|
|
1041
1271
|
isPrefetched,
|
|
1042
|
-
flush: () =>
|
|
1272
|
+
flush: () => import_core9.router.flush(window.location.pathname, options)
|
|
1043
1273
|
};
|
|
1044
1274
|
}
|
|
1045
1275
|
|
|
1046
1276
|
// src/WhenVisible.ts
|
|
1047
|
-
var
|
|
1048
|
-
var
|
|
1277
|
+
var import_core10 = require("@inertiajs/core");
|
|
1278
|
+
var import_react15 = require("react");
|
|
1049
1279
|
var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
|
|
1050
1280
|
always = always ?? false;
|
|
1051
1281
|
as = as ?? "div";
|
|
1052
1282
|
fallback = fallback ?? null;
|
|
1053
|
-
const [loaded, setLoaded] = (0,
|
|
1054
|
-
const hasFetched = (0,
|
|
1055
|
-
const fetching = (0,
|
|
1056
|
-
const ref = (0,
|
|
1057
|
-
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)(() => {
|
|
1058
1288
|
if (data) {
|
|
1059
1289
|
return {
|
|
1060
1290
|
only: Array.isArray(data) ? data : [data]
|
|
@@ -1065,7 +1295,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1065
1295
|
}
|
|
1066
1296
|
return params;
|
|
1067
1297
|
}, [params, data]);
|
|
1068
|
-
(0,
|
|
1298
|
+
(0, import_react15.useEffect)(() => {
|
|
1069
1299
|
if (!ref.current) {
|
|
1070
1300
|
return;
|
|
1071
1301
|
}
|
|
@@ -1083,7 +1313,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1083
1313
|
hasFetched.current = true;
|
|
1084
1314
|
fetching.current = true;
|
|
1085
1315
|
const reloadParams = getReloadParams();
|
|
1086
|
-
|
|
1316
|
+
import_core10.router.reload({
|
|
1087
1317
|
...reloadParams,
|
|
1088
1318
|
onStart: (e) => {
|
|
1089
1319
|
fetching.current = true;
|
|
@@ -1111,7 +1341,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1111
1341
|
const resolveChildren = () => typeof children === "function" ? children() : children;
|
|
1112
1342
|
const resolveFallback = () => typeof fallback === "function" ? fallback() : fallback;
|
|
1113
1343
|
if (always || !loaded) {
|
|
1114
|
-
return (0,
|
|
1344
|
+
return (0, import_react15.createElement)(
|
|
1115
1345
|
as,
|
|
1116
1346
|
{
|
|
1117
1347
|
props: null,
|
|
@@ -1126,6 +1356,6 @@ WhenVisible.displayName = "InertiaWhenVisible";
|
|
|
1126
1356
|
var WhenVisible_default = WhenVisible;
|
|
1127
1357
|
|
|
1128
1358
|
// src/index.ts
|
|
1129
|
-
var progress =
|
|
1130
|
-
var router3 =
|
|
1359
|
+
var progress = import_core11.progress;
|
|
1360
|
+
var router3 = import_core11.router;
|
|
1131
1361
|
//# sourceMappingURL=index.js.map
|