@inertiajs/react 2.1.11 → 2.2.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.esm.js +277 -34
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +290 -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,241 @@ 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 callbackPropsRef = (0, import_react11.useRef)({
|
|
839
|
+
buffer,
|
|
840
|
+
onlyNext,
|
|
841
|
+
onlyPrevious,
|
|
842
|
+
reverse,
|
|
843
|
+
preserveUrl
|
|
844
|
+
});
|
|
845
|
+
callbackPropsRef.current = {
|
|
846
|
+
buffer,
|
|
847
|
+
onlyNext,
|
|
848
|
+
onlyPrevious,
|
|
849
|
+
reverse,
|
|
850
|
+
preserveUrl
|
|
851
|
+
};
|
|
852
|
+
const [infiniteScroll, setInfiniteScroll] = (0, import_react11.useState)(null);
|
|
853
|
+
const dataManager = (0, import_react11.useMemo)(() => infiniteScroll?.dataManager, [infiniteScroll]);
|
|
854
|
+
const elementManager = (0, import_react11.useMemo)(() => infiniteScroll?.elementManager, [infiniteScroll]);
|
|
855
|
+
const scrollToBottom = (0, import_react11.useCallback)(() => {
|
|
856
|
+
if (scrollableParent) {
|
|
857
|
+
scrollableParent.scrollTo({
|
|
858
|
+
top: scrollableParent.scrollHeight,
|
|
859
|
+
behavior: "instant"
|
|
860
|
+
});
|
|
861
|
+
} else {
|
|
862
|
+
window.scrollTo({
|
|
863
|
+
top: document.body.scrollHeight,
|
|
864
|
+
behavior: "instant"
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
}, [scrollableParent]);
|
|
868
|
+
(0, import_react11.useEffect)(() => {
|
|
869
|
+
if (!resolvedItemsElement) {
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
const infiniteScrollInstance = (0, import_core6.useInfiniteScroll)({
|
|
873
|
+
// Data
|
|
874
|
+
getPropName: () => data,
|
|
875
|
+
inReverseMode: () => callbackPropsRef.current.reverse,
|
|
876
|
+
shouldFetchNext: () => !callbackPropsRef.current.onlyPrevious,
|
|
877
|
+
shouldFetchPrevious: () => !callbackPropsRef.current.onlyNext,
|
|
878
|
+
shouldPreserveUrl: () => callbackPropsRef.current.preserveUrl,
|
|
879
|
+
// Elements
|
|
880
|
+
getTriggerMargin: () => callbackPropsRef.current.buffer,
|
|
881
|
+
getStartElement: () => resolvedStartElement,
|
|
882
|
+
getEndElement: () => resolvedEndElement,
|
|
883
|
+
getItemsElement: () => resolvedItemsElement,
|
|
884
|
+
getScrollableParent: () => scrollableParent,
|
|
885
|
+
// Callbacks
|
|
886
|
+
onBeforePreviousRequest: () => setLoadingPrevious(true),
|
|
887
|
+
onBeforeNextRequest: () => setLoadingNext(true),
|
|
888
|
+
onCompletePreviousRequest: () => {
|
|
889
|
+
setLoadingPrevious(false);
|
|
890
|
+
setRequestCount(infiniteScrollInstance.dataManager.getRequestCount());
|
|
891
|
+
},
|
|
892
|
+
onCompleteNextRequest: () => {
|
|
893
|
+
setLoadingNext(false);
|
|
894
|
+
setRequestCount(infiniteScrollInstance.dataManager.getRequestCount());
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
setInfiniteScroll(infiniteScrollInstance);
|
|
898
|
+
const { dataManager: dataManager2, elementManager: elementManager2 } = infiniteScrollInstance;
|
|
899
|
+
setRequestCount(dataManager2.getRequestCount());
|
|
900
|
+
elementManager2.setupObservers();
|
|
901
|
+
elementManager2.processServerLoadedElements(dataManager2.getLastLoadedPage());
|
|
902
|
+
if (autoLoad) {
|
|
903
|
+
elementManager2.enableTriggers();
|
|
904
|
+
}
|
|
905
|
+
return () => {
|
|
906
|
+
elementManager2.flushAll();
|
|
907
|
+
setInfiniteScroll(null);
|
|
908
|
+
};
|
|
909
|
+
}, [data, resolvedItemsElement, resolvedStartElement, resolvedEndElement, scrollableParent]);
|
|
910
|
+
const manualMode = (0, import_react11.useMemo)(
|
|
911
|
+
() => manual || manualAfter > 0 && requestCount >= manualAfter,
|
|
912
|
+
[manual, manualAfter, requestCount]
|
|
913
|
+
);
|
|
914
|
+
const autoLoad = (0, import_react11.useMemo)(() => !manualMode, [manualMode]);
|
|
915
|
+
(0, import_react11.useEffect)(() => {
|
|
916
|
+
autoLoad ? elementManager?.enableTriggers() : elementManager?.disableTriggers();
|
|
917
|
+
}, [autoLoad, onlyNext, onlyPrevious, resolvedStartElement, resolvedEndElement]);
|
|
918
|
+
(0, import_react11.useEffect)(() => {
|
|
919
|
+
const shouldAutoScroll = autoScroll !== void 0 ? autoScroll : reverse;
|
|
920
|
+
if (shouldAutoScroll) {
|
|
921
|
+
scrollToBottom();
|
|
922
|
+
}
|
|
923
|
+
}, [scrollableParent]);
|
|
924
|
+
(0, import_react11.useImperativeHandle)(
|
|
925
|
+
ref,
|
|
926
|
+
() => ({
|
|
927
|
+
fetchNext: dataManager?.fetchNext || (() => {
|
|
928
|
+
}),
|
|
929
|
+
fetchPrevious: dataManager?.fetchPrevious || (() => {
|
|
930
|
+
}),
|
|
931
|
+
hasPrevious: dataManager?.hasPrevious || (() => false),
|
|
932
|
+
hasNext: dataManager?.hasNext || (() => false)
|
|
933
|
+
}),
|
|
934
|
+
[dataManager]
|
|
935
|
+
);
|
|
936
|
+
const headerAutoMode = autoLoad && !onlyNext;
|
|
937
|
+
const footerAutoMode = autoLoad && !onlyPrevious;
|
|
938
|
+
const sharedExposed = {
|
|
939
|
+
loadingPrevious,
|
|
940
|
+
loadingNext,
|
|
941
|
+
hasPrevious: dataManager?.hasPrevious() ?? false,
|
|
942
|
+
hasNext: dataManager?.hasNext() ?? false
|
|
943
|
+
};
|
|
944
|
+
const exposedPrevious = {
|
|
945
|
+
loading: loadingPrevious,
|
|
946
|
+
fetch: dataManager?.fetchPrevious ?? (() => {
|
|
947
|
+
}),
|
|
948
|
+
autoMode: headerAutoMode,
|
|
949
|
+
manualMode: !headerAutoMode,
|
|
950
|
+
hasMore: dataManager?.hasPrevious() ?? false,
|
|
951
|
+
...sharedExposed
|
|
952
|
+
};
|
|
953
|
+
const exposedNext = {
|
|
954
|
+
loading: loadingNext,
|
|
955
|
+
fetch: dataManager?.fetchNext ?? (() => {
|
|
956
|
+
}),
|
|
957
|
+
autoMode: footerAutoMode,
|
|
958
|
+
manualMode: !footerAutoMode,
|
|
959
|
+
hasMore: dataManager?.hasNext() ?? false,
|
|
960
|
+
...sharedExposed
|
|
961
|
+
};
|
|
962
|
+
const exposedSlot = {
|
|
963
|
+
loading: loadingPrevious || loadingNext,
|
|
964
|
+
loadingPrevious,
|
|
965
|
+
loadingNext
|
|
966
|
+
};
|
|
967
|
+
const renderElements = [];
|
|
968
|
+
if (!startElement) {
|
|
969
|
+
renderElements.push(
|
|
970
|
+
(0, import_react11.createElement)(
|
|
971
|
+
"div",
|
|
972
|
+
{ ref: startElementRef },
|
|
973
|
+
// Render previous slot or fallback to loading indicator
|
|
974
|
+
renderSlot(previous, exposedPrevious, loadingPrevious ? renderSlot(loading, exposedPrevious) : null)
|
|
975
|
+
)
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
renderElements.push(
|
|
979
|
+
(0, import_react11.createElement)(
|
|
980
|
+
as,
|
|
981
|
+
{ ...props, ref: itemsElementRef },
|
|
982
|
+
typeof children === "function" ? children(exposedSlot) : children
|
|
983
|
+
)
|
|
984
|
+
);
|
|
985
|
+
if (!endElement) {
|
|
986
|
+
renderElements.push(
|
|
987
|
+
(0, import_react11.createElement)(
|
|
988
|
+
"div",
|
|
989
|
+
{ ref: endElementRef },
|
|
990
|
+
// Render next slot or fallback to loading indicator
|
|
991
|
+
renderSlot(next, exposedNext, loadingNext ? renderSlot(loading, exposedNext) : null)
|
|
992
|
+
)
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
return (0, import_react11.createElement)(import_react11.default.Fragment, {}, ...reverse ? [...renderElements].reverse() : renderElements);
|
|
996
|
+
}
|
|
997
|
+
);
|
|
998
|
+
InfiniteScroll.displayName = "InertiaInfiniteScroll";
|
|
999
|
+
var InfiniteScroll_default = InfiniteScroll;
|
|
1000
|
+
|
|
1001
|
+
// src/Link.ts
|
|
1002
|
+
var import_core7 = require("@inertiajs/core");
|
|
1003
|
+
var import_react12 = require("react");
|
|
773
1004
|
var noop2 = () => void 0;
|
|
774
|
-
var Link = (0,
|
|
1005
|
+
var Link = (0, import_react12.forwardRef)(
|
|
775
1006
|
({
|
|
776
1007
|
children,
|
|
777
1008
|
as = "a",
|
|
@@ -802,24 +1033,24 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
802
1033
|
cacheTags = [],
|
|
803
1034
|
...props
|
|
804
1035
|
}, ref) => {
|
|
805
|
-
const [inFlightCount, setInFlightCount] = (0,
|
|
806
|
-
const hoverTimeout = (0,
|
|
807
|
-
const _method = (0,
|
|
808
|
-
return (0,
|
|
1036
|
+
const [inFlightCount, setInFlightCount] = (0, import_react12.useState)(0);
|
|
1037
|
+
const hoverTimeout = (0, import_react12.useRef)(null);
|
|
1038
|
+
const _method = (0, import_react12.useMemo)(() => {
|
|
1039
|
+
return (0, import_core7.isUrlMethodPair)(href) ? href.method : method.toLowerCase();
|
|
809
1040
|
}, [href, method]);
|
|
810
|
-
const _as = (0,
|
|
1041
|
+
const _as = (0, import_react12.useMemo)(() => {
|
|
811
1042
|
if (typeof as !== "string" || as.toLowerCase() !== "a") {
|
|
812
1043
|
return as;
|
|
813
1044
|
}
|
|
814
1045
|
return _method !== "get" ? "button" : as.toLowerCase();
|
|
815
1046
|
}, [as, _method]);
|
|
816
|
-
const mergeDataArray = (0,
|
|
817
|
-
() => (0,
|
|
1047
|
+
const mergeDataArray = (0, import_react12.useMemo)(
|
|
1048
|
+
() => (0, import_core7.mergeDataIntoQueryString)(_method, (0, import_core7.isUrlMethodPair)(href) ? href.url : href, data, queryStringArrayFormat),
|
|
818
1049
|
[href, _method, data, queryStringArrayFormat]
|
|
819
1050
|
);
|
|
820
|
-
const url = (0,
|
|
821
|
-
const _data = (0,
|
|
822
|
-
const baseParams = (0,
|
|
1051
|
+
const url = (0, import_react12.useMemo)(() => mergeDataArray[0], [mergeDataArray]);
|
|
1052
|
+
const _data = (0, import_react12.useMemo)(() => mergeDataArray[1], [mergeDataArray]);
|
|
1053
|
+
const baseParams = (0, import_react12.useMemo)(
|
|
823
1054
|
() => ({
|
|
824
1055
|
data: _data,
|
|
825
1056
|
method: _method,
|
|
@@ -833,7 +1064,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
833
1064
|
}),
|
|
834
1065
|
[_data, _method, preserveScroll, preserveState, replace, only, except, headers, async]
|
|
835
1066
|
);
|
|
836
|
-
const visitParams = (0,
|
|
1067
|
+
const visitParams = (0, import_react12.useMemo)(
|
|
837
1068
|
() => ({
|
|
838
1069
|
...baseParams,
|
|
839
1070
|
onCancelToken,
|
|
@@ -853,7 +1084,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
853
1084
|
}),
|
|
854
1085
|
[baseParams, onCancelToken, onBefore, onStart, onProgress, onFinish, onCancel, onSuccess, onError]
|
|
855
1086
|
);
|
|
856
|
-
const prefetchModes = (0,
|
|
1087
|
+
const prefetchModes = (0, import_react12.useMemo)(
|
|
857
1088
|
() => {
|
|
858
1089
|
if (prefetch === true) {
|
|
859
1090
|
return ["hover"];
|
|
@@ -868,7 +1099,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
868
1099
|
},
|
|
869
1100
|
Array.isArray(prefetch) ? prefetch : [prefetch]
|
|
870
1101
|
);
|
|
871
|
-
const cacheForValue = (0,
|
|
1102
|
+
const cacheForValue = (0, import_react12.useMemo)(() => {
|
|
872
1103
|
if (cacheFor !== 0) {
|
|
873
1104
|
return cacheFor;
|
|
874
1105
|
}
|
|
@@ -877,9 +1108,9 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
877
1108
|
}
|
|
878
1109
|
return 3e4;
|
|
879
1110
|
}, [cacheFor, prefetchModes]);
|
|
880
|
-
const doPrefetch = (0,
|
|
1111
|
+
const doPrefetch = (0, import_react12.useMemo)(() => {
|
|
881
1112
|
return () => {
|
|
882
|
-
|
|
1113
|
+
import_core7.router.prefetch(
|
|
883
1114
|
url,
|
|
884
1115
|
{
|
|
885
1116
|
...baseParams,
|
|
@@ -890,12 +1121,12 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
890
1121
|
);
|
|
891
1122
|
};
|
|
892
1123
|
}, [url, baseParams, onPrefetching, onPrefetched, cacheForValue, cacheTags]);
|
|
893
|
-
(0,
|
|
1124
|
+
(0, import_react12.useEffect)(() => {
|
|
894
1125
|
return () => {
|
|
895
1126
|
clearTimeout(hoverTimeout.current);
|
|
896
1127
|
};
|
|
897
1128
|
}, []);
|
|
898
|
-
(0,
|
|
1129
|
+
(0, import_react12.useEffect)(() => {
|
|
899
1130
|
if (prefetchModes.includes("mount")) {
|
|
900
1131
|
setTimeout(() => doPrefetch());
|
|
901
1132
|
}
|
|
@@ -903,9 +1134,9 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
903
1134
|
const regularEvents = {
|
|
904
1135
|
onClick: (event) => {
|
|
905
1136
|
onClick(event);
|
|
906
|
-
if ((0,
|
|
1137
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
907
1138
|
event.preventDefault();
|
|
908
|
-
|
|
1139
|
+
import_core7.router.visit(url, visitParams);
|
|
909
1140
|
}
|
|
910
1141
|
}
|
|
911
1142
|
};
|
|
@@ -922,35 +1153,35 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
922
1153
|
};
|
|
923
1154
|
const prefetchClickEvents = {
|
|
924
1155
|
onMouseDown: (event) => {
|
|
925
|
-
if ((0,
|
|
1156
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
926
1157
|
event.preventDefault();
|
|
927
1158
|
doPrefetch();
|
|
928
1159
|
}
|
|
929
1160
|
},
|
|
930
1161
|
onKeyDown: (event) => {
|
|
931
|
-
if ((0,
|
|
1162
|
+
if ((0, import_core7.shouldIntercept)(event) && (0, import_core7.shouldNavigate)(event)) {
|
|
932
1163
|
event.preventDefault();
|
|
933
1164
|
doPrefetch();
|
|
934
1165
|
}
|
|
935
1166
|
},
|
|
936
1167
|
onMouseUp: (event) => {
|
|
937
1168
|
event.preventDefault();
|
|
938
|
-
|
|
1169
|
+
import_core7.router.visit(url, visitParams);
|
|
939
1170
|
},
|
|
940
1171
|
onKeyUp: (event) => {
|
|
941
|
-
if ((0,
|
|
1172
|
+
if ((0, import_core7.shouldNavigate)(event)) {
|
|
942
1173
|
event.preventDefault();
|
|
943
|
-
|
|
1174
|
+
import_core7.router.visit(url, visitParams);
|
|
944
1175
|
}
|
|
945
1176
|
},
|
|
946
1177
|
onClick: (event) => {
|
|
947
1178
|
onClick(event);
|
|
948
|
-
if ((0,
|
|
1179
|
+
if ((0, import_core7.shouldIntercept)(event)) {
|
|
949
1180
|
event.preventDefault();
|
|
950
1181
|
}
|
|
951
1182
|
}
|
|
952
1183
|
};
|
|
953
|
-
const elProps = (0,
|
|
1184
|
+
const elProps = (0, import_react12.useMemo)(() => {
|
|
954
1185
|
if (_as === "button") {
|
|
955
1186
|
return { type: "button" };
|
|
956
1187
|
}
|
|
@@ -959,7 +1190,7 @@ var Link = (0, import_react11.forwardRef)(
|
|
|
959
1190
|
}
|
|
960
1191
|
return {};
|
|
961
1192
|
}, [_as, url]);
|
|
962
|
-
return (0,
|
|
1193
|
+
return (0, import_react12.createElement)(
|
|
963
1194
|
_as,
|
|
964
1195
|
{
|
|
965
1196
|
...props,
|
|
@@ -984,19 +1215,19 @@ Link.displayName = "InertiaLink";
|
|
|
984
1215
|
var Link_default = Link;
|
|
985
1216
|
|
|
986
1217
|
// src/usePoll.ts
|
|
987
|
-
var
|
|
988
|
-
var
|
|
1218
|
+
var import_core8 = require("@inertiajs/core");
|
|
1219
|
+
var import_react13 = require("react");
|
|
989
1220
|
function usePoll(interval, requestOptions = {}, options = {
|
|
990
1221
|
keepAlive: false,
|
|
991
1222
|
autoStart: true
|
|
992
1223
|
}) {
|
|
993
|
-
const pollRef = (0,
|
|
994
|
-
|
|
1224
|
+
const pollRef = (0, import_react13.useRef)(
|
|
1225
|
+
import_core8.router.poll(interval, requestOptions, {
|
|
995
1226
|
...options,
|
|
996
1227
|
autoStart: false
|
|
997
1228
|
})
|
|
998
1229
|
);
|
|
999
|
-
(0,
|
|
1230
|
+
(0, import_react13.useEffect)(() => {
|
|
1000
1231
|
if (options.autoStart ?? true) {
|
|
1001
1232
|
pollRef.current.start();
|
|
1002
1233
|
}
|
|
@@ -1009,21 +1240,21 @@ function usePoll(interval, requestOptions = {}, options = {
|
|
|
1009
1240
|
}
|
|
1010
1241
|
|
|
1011
1242
|
// src/usePrefetch.ts
|
|
1012
|
-
var
|
|
1013
|
-
var
|
|
1243
|
+
var import_core9 = require("@inertiajs/core");
|
|
1244
|
+
var import_react14 = require("react");
|
|
1014
1245
|
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 =
|
|
1246
|
+
const cached = typeof window === "undefined" ? null : import_core9.router.getCached(window.location.pathname, options);
|
|
1247
|
+
const inFlight = typeof window === "undefined" ? null : import_core9.router.getPrefetching(window.location.pathname, options);
|
|
1248
|
+
const [lastUpdatedAt, setLastUpdatedAt] = (0, import_react14.useState)(cached?.staleTimestamp || null);
|
|
1249
|
+
const [isPrefetching, setIsPrefetching] = (0, import_react14.useState)(inFlight !== null);
|
|
1250
|
+
const [isPrefetched, setIsPrefetched] = (0, import_react14.useState)(cached !== null);
|
|
1251
|
+
(0, import_react14.useEffect)(() => {
|
|
1252
|
+
const onPrefetchingListener = import_core9.router.on("prefetching", (e) => {
|
|
1022
1253
|
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1023
1254
|
setIsPrefetching(true);
|
|
1024
1255
|
}
|
|
1025
1256
|
});
|
|
1026
|
-
const onPrefetchedListener =
|
|
1257
|
+
const onPrefetchedListener = import_core9.router.on("prefetched", (e) => {
|
|
1027
1258
|
if (e.detail.visit.url.pathname === window.location.pathname) {
|
|
1028
1259
|
setIsPrefetching(false);
|
|
1029
1260
|
setIsPrefetched(true);
|
|
@@ -1039,22 +1270,22 @@ function usePrefetch(options = {}) {
|
|
|
1039
1270
|
lastUpdatedAt,
|
|
1040
1271
|
isPrefetching,
|
|
1041
1272
|
isPrefetched,
|
|
1042
|
-
flush: () =>
|
|
1273
|
+
flush: () => import_core9.router.flush(window.location.pathname, options)
|
|
1043
1274
|
};
|
|
1044
1275
|
}
|
|
1045
1276
|
|
|
1046
1277
|
// src/WhenVisible.ts
|
|
1047
|
-
var
|
|
1048
|
-
var
|
|
1278
|
+
var import_core10 = require("@inertiajs/core");
|
|
1279
|
+
var import_react15 = require("react");
|
|
1049
1280
|
var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
|
|
1050
1281
|
always = always ?? false;
|
|
1051
1282
|
as = as ?? "div";
|
|
1052
1283
|
fallback = fallback ?? null;
|
|
1053
|
-
const [loaded, setLoaded] = (0,
|
|
1054
|
-
const hasFetched = (0,
|
|
1055
|
-
const fetching = (0,
|
|
1056
|
-
const ref = (0,
|
|
1057
|
-
const getReloadParams = (0,
|
|
1284
|
+
const [loaded, setLoaded] = (0, import_react15.useState)(false);
|
|
1285
|
+
const hasFetched = (0, import_react15.useRef)(false);
|
|
1286
|
+
const fetching = (0, import_react15.useRef)(false);
|
|
1287
|
+
const ref = (0, import_react15.useRef)(null);
|
|
1288
|
+
const getReloadParams = (0, import_react15.useCallback)(() => {
|
|
1058
1289
|
if (data) {
|
|
1059
1290
|
return {
|
|
1060
1291
|
only: Array.isArray(data) ? data : [data]
|
|
@@ -1065,7 +1296,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1065
1296
|
}
|
|
1066
1297
|
return params;
|
|
1067
1298
|
}, [params, data]);
|
|
1068
|
-
(0,
|
|
1299
|
+
(0, import_react15.useEffect)(() => {
|
|
1069
1300
|
if (!ref.current) {
|
|
1070
1301
|
return;
|
|
1071
1302
|
}
|
|
@@ -1083,7 +1314,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1083
1314
|
hasFetched.current = true;
|
|
1084
1315
|
fetching.current = true;
|
|
1085
1316
|
const reloadParams = getReloadParams();
|
|
1086
|
-
|
|
1317
|
+
import_core10.router.reload({
|
|
1087
1318
|
...reloadParams,
|
|
1088
1319
|
onStart: (e) => {
|
|
1089
1320
|
fetching.current = true;
|
|
@@ -1111,7 +1342,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1111
1342
|
const resolveChildren = () => typeof children === "function" ? children() : children;
|
|
1112
1343
|
const resolveFallback = () => typeof fallback === "function" ? fallback() : fallback;
|
|
1113
1344
|
if (always || !loaded) {
|
|
1114
|
-
return (0,
|
|
1345
|
+
return (0, import_react15.createElement)(
|
|
1115
1346
|
as,
|
|
1116
1347
|
{
|
|
1117
1348
|
props: null,
|
|
@@ -1126,6 +1357,6 @@ WhenVisible.displayName = "InertiaWhenVisible";
|
|
|
1126
1357
|
var WhenVisible_default = WhenVisible;
|
|
1127
1358
|
|
|
1128
1359
|
// src/index.ts
|
|
1129
|
-
var progress =
|
|
1130
|
-
var router3 =
|
|
1360
|
+
var progress = import_core11.progress;
|
|
1361
|
+
var router3 = import_core11.router;
|
|
1131
1362
|
//# sourceMappingURL=index.js.map
|