@inertiajs/core 2.1.1 → 2.1.2
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 +33 -5
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +33 -5
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/types/index.d.ts +1 -1
- package/types/prefetched.d.ts +2 -1
- package/types/router.d.ts +14 -13
- package/types/types.d.ts +14 -9
- package/types/url.d.ts +2 -1
package/dist/index.esm.js
CHANGED
|
@@ -384,6 +384,9 @@ var setHashIfSameUrl = (originUrl, destinationUrl) => {
|
|
|
384
384
|
var isSameUrlWithoutHash = (url1, url2) => {
|
|
385
385
|
return urlWithoutHash(url1).href === urlWithoutHash(url2).href;
|
|
386
386
|
};
|
|
387
|
+
function isUrlMethodPair(href) {
|
|
388
|
+
return href !== null && typeof href === "object" && href !== void 0 && "url" in href && "method" in href;
|
|
389
|
+
}
|
|
387
390
|
|
|
388
391
|
// src/page.ts
|
|
389
392
|
var CurrentPage = class {
|
|
@@ -1005,7 +1008,7 @@ var PrefetchedRequests = class {
|
|
|
1005
1008
|
this.removalTimers = [];
|
|
1006
1009
|
this.currentUseId = null;
|
|
1007
1010
|
}
|
|
1008
|
-
add(params, sendFunc, { cacheFor }) {
|
|
1011
|
+
add(params, sendFunc, { cacheFor, cacheTags }) {
|
|
1009
1012
|
const inFlight = this.findInFlight(params);
|
|
1010
1013
|
if (inFlight) {
|
|
1011
1014
|
return Promise.resolve();
|
|
@@ -1050,7 +1053,8 @@ var PrefetchedRequests = class {
|
|
|
1050
1053
|
response: promise,
|
|
1051
1054
|
singleUse: expires === 0,
|
|
1052
1055
|
timestamp: Date.now(),
|
|
1053
|
-
inFlight: false
|
|
1056
|
+
inFlight: false,
|
|
1057
|
+
tags: Array.isArray(cacheTags) ? cacheTags : [cacheTags]
|
|
1054
1058
|
});
|
|
1055
1059
|
this.scheduleForRemoval(params, expires);
|
|
1056
1060
|
this.removeFromInFlight(params);
|
|
@@ -1072,6 +1076,11 @@ var PrefetchedRequests = class {
|
|
|
1072
1076
|
});
|
|
1073
1077
|
this.removalTimers = [];
|
|
1074
1078
|
}
|
|
1079
|
+
removeByTags(tags) {
|
|
1080
|
+
this.cached = this.cached.filter((prefetched) => {
|
|
1081
|
+
return !prefetched.tags.some((tag) => tags.includes(tag));
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1075
1084
|
remove(params) {
|
|
1076
1085
|
this.cached = this.cached.filter((prefetched) => {
|
|
1077
1086
|
return !this.paramsAreEqual(prefetched.params, params);
|
|
@@ -1421,6 +1430,7 @@ var Response = class _Response {
|
|
|
1421
1430
|
fireErrorEvent(scopedErrors);
|
|
1422
1431
|
return this.requestParams.all().onError(scopedErrors);
|
|
1423
1432
|
}
|
|
1433
|
+
router.flushByCacheTags(this.requestParams.all().invalidateCacheTags || []);
|
|
1424
1434
|
fireSuccessEvent(page.get());
|
|
1425
1435
|
await this.requestParams.all().onSuccess(page.get());
|
|
1426
1436
|
history.preserveUrl = false;
|
|
@@ -1863,11 +1873,15 @@ var Router = class {
|
|
|
1863
1873
|
flushAll() {
|
|
1864
1874
|
prefetchedRequests.removeAll();
|
|
1865
1875
|
}
|
|
1876
|
+
flushByCacheTags(tags) {
|
|
1877
|
+
prefetchedRequests.removeByTags(Array.isArray(tags) ? tags : [tags]);
|
|
1878
|
+
}
|
|
1866
1879
|
getPrefetching(href, options = {}) {
|
|
1867
1880
|
return prefetchedRequests.findInFlight(this.getPrefetchParams(href, options));
|
|
1868
1881
|
}
|
|
1869
|
-
prefetch(href, options = {},
|
|
1870
|
-
|
|
1882
|
+
prefetch(href, options = {}, prefetchOptions = {}) {
|
|
1883
|
+
const method = options.method ?? (isUrlMethodPair(href) ? href.method : "get");
|
|
1884
|
+
if (method !== "get") {
|
|
1871
1885
|
throw new Error("Prefetch requests must use the GET method");
|
|
1872
1886
|
}
|
|
1873
1887
|
const visit = this.getPendingVisit(href, {
|
|
@@ -1909,7 +1923,11 @@ var Router = class {
|
|
|
1909
1923
|
(params) => {
|
|
1910
1924
|
this.asyncRequestStream.send(Request.create(params, page.get()));
|
|
1911
1925
|
},
|
|
1912
|
-
{
|
|
1926
|
+
{
|
|
1927
|
+
cacheFor: 3e4,
|
|
1928
|
+
cacheTags: [],
|
|
1929
|
+
...prefetchOptions
|
|
1930
|
+
}
|
|
1913
1931
|
);
|
|
1914
1932
|
});
|
|
1915
1933
|
}
|
|
@@ -1964,6 +1982,11 @@ var Router = class {
|
|
|
1964
1982
|
};
|
|
1965
1983
|
}
|
|
1966
1984
|
getPendingVisit(href, options, pendingVisitOptions = {}) {
|
|
1985
|
+
if (isUrlMethodPair(href)) {
|
|
1986
|
+
const urlMethodPair = href;
|
|
1987
|
+
href = urlMethodPair.url;
|
|
1988
|
+
options.method = options.method ?? urlMethodPair.method;
|
|
1989
|
+
}
|
|
1967
1990
|
const mergedOptions = {
|
|
1968
1991
|
method: "get",
|
|
1969
1992
|
data: {},
|
|
@@ -1982,6 +2005,7 @@ var Router = class {
|
|
|
1982
2005
|
reset: [],
|
|
1983
2006
|
preserveUrl: false,
|
|
1984
2007
|
prefetch: false,
|
|
2008
|
+
invalidateCacheTags: [],
|
|
1985
2009
|
...options
|
|
1986
2010
|
};
|
|
1987
2011
|
const [url, _data] = transformUrlAndData(
|
|
@@ -2200,6 +2224,9 @@ function resetFieldElements(elements, defaultValues) {
|
|
|
2200
2224
|
return hasChanged;
|
|
2201
2225
|
}
|
|
2202
2226
|
function resetFormFields(formElement, defaults, fieldNames) {
|
|
2227
|
+
if (!formElement) {
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2203
2230
|
if (!fieldNames || fieldNames.length === 0) {
|
|
2204
2231
|
const formData = new FormData(formElement);
|
|
2205
2232
|
const formElementNames = Array.from(formElement.elements).map((el) => isFormElement(el) ? el.name : "").filter(Boolean);
|
|
@@ -2678,6 +2705,7 @@ export {
|
|
|
2678
2705
|
formDataToObject,
|
|
2679
2706
|
hide as hideProgress,
|
|
2680
2707
|
hrefToUrl,
|
|
2708
|
+
isUrlMethodPair,
|
|
2681
2709
|
mergeDataIntoQueryString,
|
|
2682
2710
|
objectToFormData,
|
|
2683
2711
|
resetFormFields,
|