inertiax-core 11.0.16 → 11.0.18
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 +45 -13
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/types/scroll.d.ts +5 -0
package/dist/index.js
CHANGED
|
@@ -1054,6 +1054,27 @@ var Scroll = class {
|
|
|
1054
1054
|
static regions() {
|
|
1055
1055
|
return document.querySelectorAll("[scroll-region]");
|
|
1056
1056
|
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Returns the closest ancestor [scroll-region] of the frame's DOM anchor,
|
|
1059
|
+
* or all regions if the frame is the top frame.
|
|
1060
|
+
*/
|
|
1061
|
+
static regionsForFrame(frameId) {
|
|
1062
|
+
if (frameId === DEFAULT_FRAME_ID2) {
|
|
1063
|
+
return Array.from(this.regions());
|
|
1064
|
+
}
|
|
1065
|
+
const anchor = document.querySelector(`[data-inertia-frame="${frameId}"]`);
|
|
1066
|
+
if (!anchor?.parentElement) {
|
|
1067
|
+
return [];
|
|
1068
|
+
}
|
|
1069
|
+
let el = anchor.parentElement;
|
|
1070
|
+
while (el) {
|
|
1071
|
+
if (el.hasAttribute("scroll-region")) {
|
|
1072
|
+
return [el];
|
|
1073
|
+
}
|
|
1074
|
+
el = el.parentElement;
|
|
1075
|
+
}
|
|
1076
|
+
return [];
|
|
1077
|
+
}
|
|
1057
1078
|
static scrollToTop() {
|
|
1058
1079
|
if (isFirefox && getComputedStyle(document.documentElement).scrollBehavior === "smooth") {
|
|
1059
1080
|
return requestAnimationFrame(() => window.scrollTo(0, 0), 2);
|
|
@@ -1061,14 +1082,14 @@ var Scroll = class {
|
|
|
1061
1082
|
window.scrollTo(0, 0);
|
|
1062
1083
|
}
|
|
1063
1084
|
static reset(frameId = DEFAULT_FRAME_ID2) {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1085
|
+
const isTopFrame = frameId === DEFAULT_FRAME_ID2;
|
|
1086
|
+
if (isTopFrame) {
|
|
1087
|
+
const anchorHash = isServer2 ? null : window.location.hash;
|
|
1088
|
+
if (!anchorHash) {
|
|
1089
|
+
this.scrollToTop();
|
|
1090
|
+
}
|
|
1070
1091
|
}
|
|
1071
|
-
this.
|
|
1092
|
+
this.regionsForFrame(frameId).forEach((region) => {
|
|
1072
1093
|
if (typeof region.scrollTo === "function") {
|
|
1073
1094
|
region.scrollTo(0, 0);
|
|
1074
1095
|
} else {
|
|
@@ -1077,7 +1098,9 @@ var Scroll = class {
|
|
|
1077
1098
|
}
|
|
1078
1099
|
});
|
|
1079
1100
|
this.save(frameId);
|
|
1080
|
-
|
|
1101
|
+
if (isTopFrame) {
|
|
1102
|
+
this.scrollToAnchor(frameId);
|
|
1103
|
+
}
|
|
1081
1104
|
}
|
|
1082
1105
|
static scrollToAnchor(frameId = DEFAULT_FRAME_ID2) {
|
|
1083
1106
|
if (frameId !== DEFAULT_FRAME_ID2) {
|
|
@@ -1095,12 +1118,21 @@ var Scroll = class {
|
|
|
1095
1118
|
if (isServer2) {
|
|
1096
1119
|
return;
|
|
1097
1120
|
}
|
|
1098
|
-
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1121
|
+
const isTopFrame = frameId === DEFAULT_FRAME_ID2;
|
|
1101
1122
|
window.requestAnimationFrame(() => {
|
|
1102
|
-
|
|
1103
|
-
|
|
1123
|
+
if (isTopFrame) {
|
|
1124
|
+
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
|
+
}
|
|
1104
1136
|
});
|
|
1105
1137
|
}
|
|
1106
1138
|
static restoreScrollRegions(scrollRegions) {
|