inertiax-core 11.0.19 → 11.0.21
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.js +42 -75
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/types/history.d.ts +6 -10
- package/types/scroll.d.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -419,53 +419,37 @@ var History = class {
|
|
|
419
419
|
decryptPageData(pageData) {
|
|
420
420
|
return pageData instanceof ArrayBuffer ? decryptHistory(pageData) : Promise.resolve(pageData);
|
|
421
421
|
}
|
|
422
|
-
saveScrollPositions(scrollRegions
|
|
423
|
-
|
|
424
|
-
return
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
void 0,
|
|
438
|
-
frameId
|
|
439
|
-
);
|
|
440
|
-
});
|
|
441
|
-
});
|
|
422
|
+
saveScrollPositions(scrollRegions) {
|
|
423
|
+
if (isEqual(this.getScrollRegions(), scrollRegions)) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const nextState = {
|
|
427
|
+
...window.history.state,
|
|
428
|
+
scrollRegions
|
|
429
|
+
};
|
|
430
|
+
try {
|
|
431
|
+
window.history.replaceState(nextState, "");
|
|
432
|
+
} catch (e) {
|
|
433
|
+
if (!(e instanceof Error && e.name === "QuotaExceededError")) {
|
|
434
|
+
console.error("[Inertia] Failed to save scroll positions:", e);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
442
437
|
}
|
|
443
|
-
saveDocumentScrollPosition(scrollRegion
|
|
444
|
-
|
|
445
|
-
return
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
return this.doReplaceState(
|
|
454
|
-
{
|
|
455
|
-
page: frameState.page,
|
|
456
|
-
documentScrollPosition: scrollRegion
|
|
457
|
-
},
|
|
458
|
-
void 0,
|
|
459
|
-
frameId
|
|
460
|
-
);
|
|
461
|
-
});
|
|
462
|
-
});
|
|
438
|
+
saveDocumentScrollPosition(scrollRegion) {
|
|
439
|
+
if (isEqual(this.getDocumentScrollPosition(), scrollRegion)) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const nextState = {
|
|
443
|
+
...window.history.state,
|
|
444
|
+
documentScrollPosition: scrollRegion
|
|
445
|
+
};
|
|
446
|
+
window.history.replaceState(nextState, "");
|
|
463
447
|
}
|
|
464
|
-
getScrollRegions(
|
|
465
|
-
return this.
|
|
448
|
+
getScrollRegions() {
|
|
449
|
+
return this.getWindowState().scrollRegions || [];
|
|
466
450
|
}
|
|
467
|
-
getDocumentScrollPosition(
|
|
468
|
-
return this.
|
|
451
|
+
getDocumentScrollPosition() {
|
|
452
|
+
return this.getWindowState().documentScrollPosition || { top: 0, left: 0 };
|
|
469
453
|
}
|
|
470
454
|
replaceState(page2, cb = null, frameId = DEFAULT_FRAME_ID, browserUrl) {
|
|
471
455
|
if (isEqual(this.getCurrent(frameId), page2)) {
|
|
@@ -515,15 +499,12 @@ var History = class {
|
|
|
515
499
|
doReplaceState(data, url, frameId = DEFAULT_FRAME_ID) {
|
|
516
500
|
return this.withThrottleProtection(() => {
|
|
517
501
|
const existing = this.getWindowState();
|
|
518
|
-
const previous = existing.frames[frameId] ?? {};
|
|
519
502
|
const nextState = {
|
|
520
503
|
...window.history.state,
|
|
521
504
|
frames: {
|
|
522
505
|
...existing.frames,
|
|
523
506
|
[frameId]: {
|
|
524
|
-
page: data.page
|
|
525
|
-
scrollRegions: data.scrollRegions ?? previous.scrollRegions ?? [],
|
|
526
|
-
documentScrollPosition: data.documentScrollPosition ?? previous.documentScrollPosition ?? { top: 0, left: 0 }
|
|
507
|
+
page: data.page
|
|
527
508
|
}
|
|
528
509
|
}
|
|
529
510
|
};
|
|
@@ -533,15 +514,12 @@ var History = class {
|
|
|
533
514
|
doPushState(data, url, frameId = DEFAULT_FRAME_ID) {
|
|
534
515
|
return this.withThrottleProtection(() => {
|
|
535
516
|
const existing = this.getWindowState();
|
|
536
|
-
const previous = existing.frames[frameId] ?? {};
|
|
537
517
|
const nextState = {
|
|
538
518
|
...window.history.state,
|
|
539
519
|
frames: {
|
|
540
520
|
...existing.frames,
|
|
541
521
|
[frameId]: {
|
|
542
|
-
page: data.page
|
|
543
|
-
scrollRegions: data.scrollRegions ?? previous.scrollRegions ?? [],
|
|
544
|
-
documentScrollPosition: data.documentScrollPosition ?? previous.documentScrollPosition ?? { top: 0, left: 0 }
|
|
522
|
+
page: data.page
|
|
545
523
|
}
|
|
546
524
|
}
|
|
547
525
|
};
|
|
@@ -1042,8 +1020,8 @@ var isServer2 = typeof window === "undefined";
|
|
|
1042
1020
|
var isFirefox = !isServer2 && /Firefox/i.test(window.navigator.userAgent);
|
|
1043
1021
|
var DEFAULT_FRAME_ID2 = "_top";
|
|
1044
1022
|
var Scroll = class {
|
|
1045
|
-
static save(
|
|
1046
|
-
history.saveScrollPositions(this.getScrollRegions()
|
|
1023
|
+
static save() {
|
|
1024
|
+
history.saveScrollPositions(this.getScrollRegions());
|
|
1047
1025
|
}
|
|
1048
1026
|
static getScrollRegions() {
|
|
1049
1027
|
return Array.from(this.regions()).map((region) => ({
|
|
@@ -1097,7 +1075,6 @@ var Scroll = class {
|
|
|
1097
1075
|
region.scrollLeft = 0;
|
|
1098
1076
|
}
|
|
1099
1077
|
});
|
|
1100
|
-
this.save(frameId);
|
|
1101
1078
|
if (isTopFrame) {
|
|
1102
1079
|
this.scrollToAnchor(frameId);
|
|
1103
1080
|
}
|
|
@@ -1118,21 +1095,11 @@ var Scroll = class {
|
|
|
1118
1095
|
if (isServer2) {
|
|
1119
1096
|
return;
|
|
1120
1097
|
}
|
|
1121
|
-
const isTopFrame = frameId === DEFAULT_FRAME_ID2;
|
|
1122
1098
|
window.requestAnimationFrame(() => {
|
|
1123
|
-
if (
|
|
1099
|
+
if (frameId === DEFAULT_FRAME_ID2) {
|
|
1124
1100
|
this.restoreDocument(frameId);
|
|
1125
|
-
this.restoreScrollRegions(scrollRegions);
|
|
1126
|
-
} else {
|
|
1127
|
-
this.regionsForFrame(frameId).forEach((region) => {
|
|
1128
|
-
if (typeof region.scrollTo === "function") {
|
|
1129
|
-
region.scrollTo(0, 0);
|
|
1130
|
-
} else {
|
|
1131
|
-
region.scrollTop = 0;
|
|
1132
|
-
region.scrollLeft = 0;
|
|
1133
|
-
}
|
|
1134
|
-
});
|
|
1135
1101
|
}
|
|
1102
|
+
this.restoreScrollRegions(scrollRegions);
|
|
1136
1103
|
});
|
|
1137
1104
|
}
|
|
1138
1105
|
static restoreScrollRegions(scrollRegions) {
|
|
@@ -1156,7 +1123,7 @@ var Scroll = class {
|
|
|
1156
1123
|
if (frameId !== DEFAULT_FRAME_ID2) {
|
|
1157
1124
|
return;
|
|
1158
1125
|
}
|
|
1159
|
-
const scrollPosition = history.getDocumentScrollPosition(
|
|
1126
|
+
const scrollPosition = history.getDocumentScrollPosition();
|
|
1160
1127
|
window.scrollTo(scrollPosition.left, scrollPosition.top);
|
|
1161
1128
|
}
|
|
1162
1129
|
static onScroll(event) {
|
|
@@ -1165,11 +1132,11 @@ var Scroll = class {
|
|
|
1165
1132
|
this.save();
|
|
1166
1133
|
}
|
|
1167
1134
|
}
|
|
1168
|
-
static onWindowScroll(
|
|
1135
|
+
static onWindowScroll() {
|
|
1169
1136
|
history.saveDocumentScrollPosition({
|
|
1170
1137
|
top: window.scrollY,
|
|
1171
1138
|
left: window.scrollX
|
|
1172
|
-
}
|
|
1139
|
+
});
|
|
1173
1140
|
}
|
|
1174
1141
|
};
|
|
1175
1142
|
|
|
@@ -1869,7 +1836,7 @@ var InitialVisit = class {
|
|
|
1869
1836
|
if (!navigationType.isBackForward() || !history.browserHasHistoryEntry(frameId)) {
|
|
1870
1837
|
return false;
|
|
1871
1838
|
}
|
|
1872
|
-
const scrollRegions = history.getScrollRegions(
|
|
1839
|
+
const scrollRegions = history.getScrollRegions();
|
|
1873
1840
|
history.decrypt(null, frameId).then((data) => {
|
|
1874
1841
|
const visitId = uid();
|
|
1875
1842
|
page.set(data, { preserveScroll: true, preserveState: true, visitId }, frameId).then(() => {
|
|
@@ -1896,7 +1863,7 @@ var InitialVisit = class {
|
|
|
1896
1863
|
history.decrypt(page.get(frameId), frameId).then(() => {
|
|
1897
1864
|
const visitId = uid();
|
|
1898
1865
|
const rememberedState = history.getState(history.rememberedState, {}, frameId);
|
|
1899
|
-
const scrollRegions = history.getScrollRegions(
|
|
1866
|
+
const scrollRegions = history.getScrollRegions();
|
|
1900
1867
|
page.remember(rememberedState, frameId);
|
|
1901
1868
|
page.set(page.get(frameId), {
|
|
1902
1869
|
preserveScroll: locationVisit.preserveScroll,
|
|
@@ -1920,7 +1887,7 @@ var InitialVisit = class {
|
|
|
1920
1887
|
const visitId = uid();
|
|
1921
1888
|
page.set(page.get(frameId), { preserveScroll: true, preserveState: true, visitId }, frameId).then(() => {
|
|
1922
1889
|
if (navigationType.isReload()) {
|
|
1923
|
-
Scroll.restore(history.getScrollRegions(
|
|
1890
|
+
Scroll.restore(history.getScrollRegions(), frameId);
|
|
1924
1891
|
} else {
|
|
1925
1892
|
Scroll.scrollToAnchor(frameId);
|
|
1926
1893
|
}
|
|
@@ -3305,7 +3272,7 @@ var Router = class {
|
|
|
3305
3272
|
}
|
|
3306
3273
|
this.cancelAll({ prefetch: false });
|
|
3307
3274
|
page.setQuietly(data, { preserveState: this.frameId === DEFAULT_FRAME_ID4 }, this.frameId).then(() => {
|
|
3308
|
-
Scroll.restore(history.getScrollRegions(
|
|
3275
|
+
Scroll.restore(history.getScrollRegions(), this.frameId);
|
|
3309
3276
|
fireNavigateEvent(page.get(this.frameId));
|
|
3310
3277
|
const pendingDeferred = {};
|
|
3311
3278
|
const pageProps = page.get(this.frameId).props;
|
|
@@ -3465,7 +3432,7 @@ var Router = class {
|
|
|
3465
3432
|
this.applyOptimisticUpdate(options.optimistic, events);
|
|
3466
3433
|
}
|
|
3467
3434
|
if (!page.isCleared(this.frameId) && !visit.preserveUrl) {
|
|
3468
|
-
Scroll.save(
|
|
3435
|
+
Scroll.save();
|
|
3469
3436
|
}
|
|
3470
3437
|
const requestParams = {
|
|
3471
3438
|
...visit,
|