@inertiajs/core 2.2.7 → 2.2.8
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 +70 -16
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +84 -30
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/scroll.d.ts +1 -0
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() {
|
|
@@ -441,7 +450,9 @@ var CurrentPage = class {
|
|
|
441
450
|
return;
|
|
442
451
|
}
|
|
443
452
|
page2.rememberedState ?? (page2.rememberedState = {});
|
|
444
|
-
const
|
|
453
|
+
const isServer2 = typeof window === "undefined";
|
|
454
|
+
const location = !isServer2 ? window.location : new URL(page2.url);
|
|
455
|
+
const scrollRegions = !isServer2 && preserveScroll ? history.getScrollRegions() : [];
|
|
445
456
|
replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
|
|
446
457
|
return new Promise((resolve) => {
|
|
447
458
|
replace ? history.replaceState(page2, () => resolve(null)) : history.pushState(page2, () => resolve(null));
|
|
@@ -457,7 +468,9 @@ var CurrentPage = class {
|
|
|
457
468
|
}
|
|
458
469
|
this.isFirstPageLoad = false;
|
|
459
470
|
return this.swap({ component, page: page2, preserveState }).then(() => {
|
|
460
|
-
if (
|
|
471
|
+
if (preserveScroll) {
|
|
472
|
+
window.requestAnimationFrame(() => Scroll.restoreScrollRegions(scrollRegions));
|
|
473
|
+
} else {
|
|
461
474
|
Scroll.reset();
|
|
462
475
|
}
|
|
463
476
|
if (this.pendingDeferredProps && this.pendingDeferredProps.component === page2.component && this.pendingDeferredProps.url === page2.url) {
|
|
@@ -633,6 +646,9 @@ var History = class {
|
|
|
633
646
|
if (!window.history.state?.page) {
|
|
634
647
|
return;
|
|
635
648
|
}
|
|
649
|
+
if (isEqual(this.getScrollRegions(), scrollRegions)) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
636
652
|
return this.doReplaceState({
|
|
637
653
|
page: window.history.state.page,
|
|
638
654
|
scrollRegions
|
|
@@ -646,6 +662,9 @@ var History = class {
|
|
|
646
662
|
if (!window.history.state?.page) {
|
|
647
663
|
return;
|
|
648
664
|
}
|
|
665
|
+
if (isEqual(this.getDocumentScrollPosition(), scrollRegion)) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
649
668
|
return this.doReplaceState({
|
|
650
669
|
page: window.history.state.page,
|
|
651
670
|
documentScrollPosition: scrollRegion
|
|
@@ -2179,10 +2198,45 @@ var elementInViewport = (el) => {
|
|
|
2179
2198
|
return verticallyVisible && horizontallyVisible;
|
|
2180
2199
|
};
|
|
2181
2200
|
var getScrollableParent = (element) => {
|
|
2201
|
+
const allowsVerticalScroll = (el) => {
|
|
2202
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2203
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
|
|
2204
|
+
return true;
|
|
2205
|
+
}
|
|
2206
|
+
if (computedStyle.overflowY !== "auto") {
|
|
2207
|
+
return false;
|
|
2208
|
+
}
|
|
2209
|
+
if (["visible", "clip"].includes(computedStyle.overflowX)) {
|
|
2210
|
+
return true;
|
|
2211
|
+
}
|
|
2212
|
+
return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
|
|
2213
|
+
};
|
|
2214
|
+
const allowsHorizontalScroll = (el) => {
|
|
2215
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2216
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
|
|
2217
|
+
return true;
|
|
2218
|
+
}
|
|
2219
|
+
if (computedStyle.overflowX !== "auto") {
|
|
2220
|
+
return false;
|
|
2221
|
+
}
|
|
2222
|
+
if (["visible", "clip"].includes(computedStyle.overflowY)) {
|
|
2223
|
+
return true;
|
|
2224
|
+
}
|
|
2225
|
+
return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
|
|
2226
|
+
};
|
|
2227
|
+
const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
|
|
2228
|
+
if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
|
|
2229
|
+
return true;
|
|
2230
|
+
}
|
|
2231
|
+
if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
|
|
2232
|
+
return true;
|
|
2233
|
+
}
|
|
2234
|
+
return false;
|
|
2235
|
+
};
|
|
2182
2236
|
let parent = element?.parentElement;
|
|
2183
2237
|
while (parent) {
|
|
2184
|
-
const
|
|
2185
|
-
if (
|
|
2238
|
+
const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
|
|
2239
|
+
if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
|
|
2186
2240
|
return parent;
|
|
2187
2241
|
}
|
|
2188
2242
|
parent = parent.parentElement;
|