made-refine 0.2.3 → 0.2.4
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 +59 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4057,6 +4057,7 @@ function useCanvas({ stateRef, setState }) {
|
|
|
4057
4057
|
const savedHtmlOverflowRef = React7.useRef("");
|
|
4058
4058
|
const savedHtmlBgColorRef = React7.useRef("");
|
|
4059
4059
|
const savedBodyDimensionsRef = React7.useRef({ width: 0, height: 0 });
|
|
4060
|
+
const savedScrollContainersRef = React7.useRef([]);
|
|
4060
4061
|
const rafIdRef = React7.useRef(null);
|
|
4061
4062
|
const rafPendingRef = React7.useRef(false);
|
|
4062
4063
|
const spaceHeldRef = React7.useRef(false);
|
|
@@ -4112,6 +4113,58 @@ function useCanvas({ stateRef, setState }) {
|
|
|
4112
4113
|
});
|
|
4113
4114
|
}
|
|
4114
4115
|
}, [applyTransform, dispatchCanvasChange, setState]);
|
|
4116
|
+
function isScrollableContainer(el) {
|
|
4117
|
+
if (el.scrollHeight <= el.clientHeight + 1) return false;
|
|
4118
|
+
const style = getComputedStyle(el);
|
|
4119
|
+
const overflowY = style.overflowY || style.overflow;
|
|
4120
|
+
if (overflowY === "hidden" || overflowY === "clip") return false;
|
|
4121
|
+
return overflowY === "auto" || overflowY === "scroll" || overflowY === "overlay";
|
|
4122
|
+
}
|
|
4123
|
+
function expandScrollContainers() {
|
|
4124
|
+
const saved = [];
|
|
4125
|
+
const queue = Array.from(document.body.children).filter(
|
|
4126
|
+
(el) => el instanceof HTMLElement
|
|
4127
|
+
);
|
|
4128
|
+
let visited = 0;
|
|
4129
|
+
const maxNodes = 5e3;
|
|
4130
|
+
while (queue.length > 0 && visited < maxNodes) {
|
|
4131
|
+
const nextQueue = [];
|
|
4132
|
+
for (const el of queue) {
|
|
4133
|
+
if (visited >= maxNodes) break;
|
|
4134
|
+
visited++;
|
|
4135
|
+
if (isScrollableContainer(el)) {
|
|
4136
|
+
const style = el.style;
|
|
4137
|
+
saved.push({
|
|
4138
|
+
el,
|
|
4139
|
+
height: style.height,
|
|
4140
|
+
maxHeight: style.maxHeight,
|
|
4141
|
+
overflowX: style.overflowX,
|
|
4142
|
+
overflowY: style.overflowY
|
|
4143
|
+
});
|
|
4144
|
+
style.height = "auto";
|
|
4145
|
+
style.maxHeight = "none";
|
|
4146
|
+
style.overflowX = "visible";
|
|
4147
|
+
style.overflowY = "visible";
|
|
4148
|
+
}
|
|
4149
|
+
for (const child of el.children) {
|
|
4150
|
+
if (child instanceof HTMLElement) nextQueue.push(child);
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
queue.length = 0;
|
|
4154
|
+
queue.push(...nextQueue);
|
|
4155
|
+
}
|
|
4156
|
+
savedScrollContainersRef.current = saved;
|
|
4157
|
+
}
|
|
4158
|
+
function restoreScrollContainers() {
|
|
4159
|
+
for (let i = savedScrollContainersRef.current.length - 1; i >= 0; i--) {
|
|
4160
|
+
const { el, height, maxHeight, overflowX, overflowY } = savedScrollContainersRef.current[i];
|
|
4161
|
+
el.style.height = height;
|
|
4162
|
+
el.style.maxHeight = maxHeight;
|
|
4163
|
+
el.style.overflowX = overflowX;
|
|
4164
|
+
el.style.overflowY = overflowY;
|
|
4165
|
+
}
|
|
4166
|
+
savedScrollContainersRef.current = [];
|
|
4167
|
+
}
|
|
4115
4168
|
const enterCanvas = React7.useCallback(() => {
|
|
4116
4169
|
const scrollX = window.scrollX;
|
|
4117
4170
|
const scrollY = window.scrollY;
|
|
@@ -4119,15 +4172,16 @@ function useCanvas({ stateRef, setState }) {
|
|
|
4119
4172
|
savedBodyOverflowRef.current = document.body.style.overflow;
|
|
4120
4173
|
savedHtmlOverflowRef.current = document.documentElement.style.overflow;
|
|
4121
4174
|
savedHtmlBgColorRef.current = document.documentElement.style.backgroundColor;
|
|
4122
|
-
savedBodyDimensionsRef.current = {
|
|
4123
|
-
width: document.body.scrollWidth,
|
|
4124
|
-
height: document.body.scrollHeight
|
|
4125
|
-
};
|
|
4126
4175
|
const existingTransform = document.body.style.transform;
|
|
4127
4176
|
if (existingTransform && existingTransform !== "none" && existingTransform !== "") {
|
|
4128
4177
|
console.warn("[made-refine] canvas mode: overriding existing body transform:", existingTransform);
|
|
4129
4178
|
}
|
|
4130
4179
|
window.scrollTo(0, 0);
|
|
4180
|
+
expandScrollContainers();
|
|
4181
|
+
savedBodyDimensionsRef.current = {
|
|
4182
|
+
width: document.body.scrollWidth,
|
|
4183
|
+
height: document.body.scrollHeight
|
|
4184
|
+
};
|
|
4131
4185
|
updateBodyOffset();
|
|
4132
4186
|
document.body.style.overflow = "hidden";
|
|
4133
4187
|
document.documentElement.style.overflow = "hidden";
|
|
@@ -4147,6 +4201,7 @@ function useCanvas({ stateRef, setState }) {
|
|
|
4147
4201
|
cancelPendingRaf();
|
|
4148
4202
|
document.body.style.transform = "";
|
|
4149
4203
|
document.body.style.transformOrigin = "";
|
|
4204
|
+
restoreScrollContainers();
|
|
4150
4205
|
document.body.style.overflow = savedBodyOverflowRef.current;
|
|
4151
4206
|
document.documentElement.style.overflow = savedHtmlOverflowRef.current;
|
|
4152
4207
|
document.documentElement.style.backgroundColor = savedHtmlBgColorRef.current;
|