@inertiajs/core 2.2.7 → 2.2.9
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 +100 -35
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +114 -49
- package/dist/index.js.map +4 -4
- package/package.json +5 -5
- package/types/debug.d.ts +1 -1
- package/types/head.d.ts +2 -7
- package/types/navigationEvents.d.ts +5 -2
- package/types/page.d.ts +10 -6
- package/types/requestParams.d.ts +1 -1
- package/types/router.d.ts +1 -1
- package/types/scroll.d.ts +1 -0
- package/types/types.d.ts +53 -15
package/dist/index.esm.js
CHANGED
|
@@ -51,6 +51,9 @@ var firePrefetchingEvent = (visit) => {
|
|
|
51
51
|
return fireEvent("prefetching", { detail: { visit } });
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
// src/history.ts
|
|
55
|
+
import { isEqual } from "lodash-es";
|
|
56
|
+
|
|
54
57
|
// src/sessionStorage.ts
|
|
55
58
|
var SessionStorage = class {
|
|
56
59
|
static set(key, value) {
|
|
@@ -260,18 +263,24 @@ var Scroll = class {
|
|
|
260
263
|
}
|
|
261
264
|
window.requestAnimationFrame(() => {
|
|
262
265
|
this.restoreDocument();
|
|
263
|
-
this.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
266
|
+
this.restoreScrollRegions(scrollRegions);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
static restoreScrollRegions(scrollRegions) {
|
|
270
|
+
if (typeof window === "undefined") {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this.regions().forEach((region, index) => {
|
|
274
|
+
const scrollPosition = scrollRegions[index];
|
|
275
|
+
if (!scrollPosition) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (typeof region.scrollTo === "function") {
|
|
279
|
+
region.scrollTo(scrollPosition.left, scrollPosition.top);
|
|
280
|
+
} else {
|
|
281
|
+
region.scrollTop = scrollPosition.top;
|
|
282
|
+
region.scrollLeft = scrollPosition.left;
|
|
283
|
+
}
|
|
275
284
|
});
|
|
276
285
|
}
|
|
277
286
|
static restoreDocument() {
|
|
@@ -413,7 +422,11 @@ var CurrentPage = class {
|
|
|
413
422
|
this.cleared = false;
|
|
414
423
|
this.pendingDeferredProps = null;
|
|
415
424
|
}
|
|
416
|
-
init({
|
|
425
|
+
init({
|
|
426
|
+
initialPage,
|
|
427
|
+
swapComponent,
|
|
428
|
+
resolveComponent
|
|
429
|
+
}) {
|
|
417
430
|
this.page = initialPage;
|
|
418
431
|
this.swapComponent = swapComponent;
|
|
419
432
|
this.resolveComponent = resolveComponent;
|
|
@@ -441,7 +454,9 @@ var CurrentPage = class {
|
|
|
441
454
|
return;
|
|
442
455
|
}
|
|
443
456
|
page2.rememberedState ?? (page2.rememberedState = {});
|
|
444
|
-
const
|
|
457
|
+
const isServer2 = typeof window === "undefined";
|
|
458
|
+
const location = !isServer2 ? window.location : new URL(page2.url);
|
|
459
|
+
const scrollRegions = !isServer2 && preserveScroll ? history.getScrollRegions() : [];
|
|
445
460
|
replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
|
|
446
461
|
return new Promise((resolve) => {
|
|
447
462
|
replace ? history.replaceState(page2, () => resolve(null)) : history.pushState(page2, () => resolve(null));
|
|
@@ -457,7 +472,9 @@ var CurrentPage = class {
|
|
|
457
472
|
}
|
|
458
473
|
this.isFirstPageLoad = false;
|
|
459
474
|
return this.swap({ component, page: page2, preserveState }).then(() => {
|
|
460
|
-
if (
|
|
475
|
+
if (preserveScroll) {
|
|
476
|
+
window.requestAnimationFrame(() => Scroll.restoreScrollRegions(scrollRegions));
|
|
477
|
+
} else {
|
|
461
478
|
Scroll.reset();
|
|
462
479
|
}
|
|
463
480
|
if (this.pendingDeferredProps && this.pendingDeferredProps.component === page2.component && this.pendingDeferredProps.url === page2.url) {
|
|
@@ -633,6 +650,9 @@ var History = class {
|
|
|
633
650
|
if (!window.history.state?.page) {
|
|
634
651
|
return;
|
|
635
652
|
}
|
|
653
|
+
if (isEqual(this.getScrollRegions(), scrollRegions)) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
636
656
|
return this.doReplaceState({
|
|
637
657
|
page: window.history.state.page,
|
|
638
658
|
scrollRegions
|
|
@@ -646,6 +666,9 @@ var History = class {
|
|
|
646
666
|
if (!window.history.state?.page) {
|
|
647
667
|
return;
|
|
648
668
|
}
|
|
669
|
+
if (isEqual(this.getDocumentScrollPosition(), scrollRegion)) {
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
649
672
|
return this.doReplaceState({
|
|
650
673
|
page: window.history.state.page,
|
|
651
674
|
documentScrollPosition: scrollRegion
|
|
@@ -1332,8 +1355,8 @@ var RequestParams = class _RequestParams {
|
|
|
1332
1355
|
return headers;
|
|
1333
1356
|
}
|
|
1334
1357
|
setPreserveOptions(page2) {
|
|
1335
|
-
this.params.preserveScroll =
|
|
1336
|
-
this.params.preserveState =
|
|
1358
|
+
this.params.preserveScroll = _RequestParams.resolvePreserveOption(this.params.preserveScroll, page2);
|
|
1359
|
+
this.params.preserveState = _RequestParams.resolvePreserveOption(this.params.preserveState, page2);
|
|
1337
1360
|
}
|
|
1338
1361
|
runCallbacks() {
|
|
1339
1362
|
this.callbacks.forEach(({ name, args }) => {
|
|
@@ -1355,7 +1378,7 @@ var RequestParams = class _RequestParams {
|
|
|
1355
1378
|
recordCallback(name, args) {
|
|
1356
1379
|
this.callbacks.push({ name, args });
|
|
1357
1380
|
}
|
|
1358
|
-
resolvePreserveOption(value, page2) {
|
|
1381
|
+
static resolvePreserveOption(value, page2) {
|
|
1359
1382
|
if (typeof value === "function") {
|
|
1360
1383
|
return value(page2);
|
|
1361
1384
|
}
|
|
@@ -1834,7 +1857,11 @@ var Router = class {
|
|
|
1834
1857
|
interruptible: false
|
|
1835
1858
|
});
|
|
1836
1859
|
}
|
|
1837
|
-
init({
|
|
1860
|
+
init({
|
|
1861
|
+
initialPage,
|
|
1862
|
+
resolveComponent,
|
|
1863
|
+
swapComponent
|
|
1864
|
+
}) {
|
|
1838
1865
|
page.init({
|
|
1839
1866
|
initialPage,
|
|
1840
1867
|
resolveComponent,
|
|
@@ -2057,18 +2084,18 @@ var Router = class {
|
|
|
2057
2084
|
const current = page.get();
|
|
2058
2085
|
const props = typeof params.props === "function" ? params.props(current.props) : params.props ?? current.props;
|
|
2059
2086
|
const { onError, onFinish, onSuccess, ...pageParams } = params;
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
).then(() => {
|
|
2087
|
+
const page2 = {
|
|
2088
|
+
...current,
|
|
2089
|
+
...pageParams,
|
|
2090
|
+
props
|
|
2091
|
+
};
|
|
2092
|
+
const preserveScroll = RequestParams.resolvePreserveOption(params.preserveScroll ?? false, page2);
|
|
2093
|
+
const preserveState = RequestParams.resolvePreserveOption(params.preserveState ?? false, page2);
|
|
2094
|
+
page.set(page2, {
|
|
2095
|
+
replace,
|
|
2096
|
+
preserveScroll,
|
|
2097
|
+
preserveState
|
|
2098
|
+
}).then(() => {
|
|
2072
2099
|
const errors = page.get().props.errors || {};
|
|
2073
2100
|
if (Object.keys(errors).length === 0) {
|
|
2074
2101
|
return onSuccess?.(page.get());
|
|
@@ -2179,10 +2206,45 @@ var elementInViewport = (el) => {
|
|
|
2179
2206
|
return verticallyVisible && horizontallyVisible;
|
|
2180
2207
|
};
|
|
2181
2208
|
var getScrollableParent = (element) => {
|
|
2209
|
+
const allowsVerticalScroll = (el) => {
|
|
2210
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2211
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
|
|
2212
|
+
return true;
|
|
2213
|
+
}
|
|
2214
|
+
if (computedStyle.overflowY !== "auto") {
|
|
2215
|
+
return false;
|
|
2216
|
+
}
|
|
2217
|
+
if (["visible", "clip"].includes(computedStyle.overflowX)) {
|
|
2218
|
+
return true;
|
|
2219
|
+
}
|
|
2220
|
+
return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
|
|
2221
|
+
};
|
|
2222
|
+
const allowsHorizontalScroll = (el) => {
|
|
2223
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2224
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
|
|
2225
|
+
return true;
|
|
2226
|
+
}
|
|
2227
|
+
if (computedStyle.overflowX !== "auto") {
|
|
2228
|
+
return false;
|
|
2229
|
+
}
|
|
2230
|
+
if (["visible", "clip"].includes(computedStyle.overflowY)) {
|
|
2231
|
+
return true;
|
|
2232
|
+
}
|
|
2233
|
+
return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
|
|
2234
|
+
};
|
|
2235
|
+
const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
|
|
2236
|
+
if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
|
|
2237
|
+
return true;
|
|
2238
|
+
}
|
|
2239
|
+
if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
|
|
2240
|
+
return true;
|
|
2241
|
+
}
|
|
2242
|
+
return false;
|
|
2243
|
+
};
|
|
2182
2244
|
let parent = element?.parentElement;
|
|
2183
2245
|
while (parent) {
|
|
2184
|
-
const
|
|
2185
|
-
if (
|
|
2246
|
+
const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
|
|
2247
|
+
if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
|
|
2186
2248
|
return parent;
|
|
2187
2249
|
}
|
|
2188
2250
|
parent = parent.parentElement;
|
|
@@ -2883,13 +2945,16 @@ function useInfiniteScroll(options) {
|
|
|
2883
2945
|
}
|
|
2884
2946
|
|
|
2885
2947
|
// src/navigationEvents.ts
|
|
2948
|
+
function isContentEditableOrPrevented(event) {
|
|
2949
|
+
return event.target instanceof HTMLElement && event.target.isContentEditable || event.defaultPrevented;
|
|
2950
|
+
}
|
|
2886
2951
|
function shouldIntercept(event) {
|
|
2887
2952
|
const isLink = event.currentTarget.tagName.toLowerCase() === "a";
|
|
2888
|
-
return !(
|
|
2953
|
+
return !(isContentEditableOrPrevented(event) || isLink && event.altKey || isLink && event.ctrlKey || isLink && event.metaKey || isLink && event.shiftKey || isLink && "button" in event && event.button !== 0);
|
|
2889
2954
|
}
|
|
2890
2955
|
function shouldNavigate(event) {
|
|
2891
2956
|
const isButton = event.currentTarget.tagName.toLowerCase() === "button";
|
|
2892
|
-
return event.key === "Enter" || isButton && event.key === " ";
|
|
2957
|
+
return !isContentEditableOrPrevented(event) && (event.key === "Enter" || isButton && event.key === " ");
|
|
2893
2958
|
}
|
|
2894
2959
|
|
|
2895
2960
|
// src/progress-component.ts
|