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 CHANGED
@@ -4135,6 +4135,7 @@ function useCanvas({ stateRef, setState }) {
4135
4135
  const savedHtmlOverflowRef = React7.useRef("");
4136
4136
  const savedHtmlBgColorRef = React7.useRef("");
4137
4137
  const savedBodyDimensionsRef = React7.useRef({ width: 0, height: 0 });
4138
+ const savedScrollContainersRef = React7.useRef([]);
4138
4139
  const rafIdRef = React7.useRef(null);
4139
4140
  const rafPendingRef = React7.useRef(false);
4140
4141
  const spaceHeldRef = React7.useRef(false);
@@ -4190,6 +4191,58 @@ function useCanvas({ stateRef, setState }) {
4190
4191
  });
4191
4192
  }
4192
4193
  }, [applyTransform, dispatchCanvasChange, setState]);
4194
+ function isScrollableContainer(el) {
4195
+ if (el.scrollHeight <= el.clientHeight + 1) return false;
4196
+ const style = getComputedStyle(el);
4197
+ const overflowY = style.overflowY || style.overflow;
4198
+ if (overflowY === "hidden" || overflowY === "clip") return false;
4199
+ return overflowY === "auto" || overflowY === "scroll" || overflowY === "overlay";
4200
+ }
4201
+ function expandScrollContainers() {
4202
+ const saved = [];
4203
+ const queue = Array.from(document.body.children).filter(
4204
+ (el) => el instanceof HTMLElement
4205
+ );
4206
+ let visited = 0;
4207
+ const maxNodes = 5e3;
4208
+ while (queue.length > 0 && visited < maxNodes) {
4209
+ const nextQueue = [];
4210
+ for (const el of queue) {
4211
+ if (visited >= maxNodes) break;
4212
+ visited++;
4213
+ if (isScrollableContainer(el)) {
4214
+ const style = el.style;
4215
+ saved.push({
4216
+ el,
4217
+ height: style.height,
4218
+ maxHeight: style.maxHeight,
4219
+ overflowX: style.overflowX,
4220
+ overflowY: style.overflowY
4221
+ });
4222
+ style.height = "auto";
4223
+ style.maxHeight = "none";
4224
+ style.overflowX = "visible";
4225
+ style.overflowY = "visible";
4226
+ }
4227
+ for (const child of el.children) {
4228
+ if (child instanceof HTMLElement) nextQueue.push(child);
4229
+ }
4230
+ }
4231
+ queue.length = 0;
4232
+ queue.push(...nextQueue);
4233
+ }
4234
+ savedScrollContainersRef.current = saved;
4235
+ }
4236
+ function restoreScrollContainers() {
4237
+ for (let i = savedScrollContainersRef.current.length - 1; i >= 0; i--) {
4238
+ const { el, height, maxHeight, overflowX, overflowY } = savedScrollContainersRef.current[i];
4239
+ el.style.height = height;
4240
+ el.style.maxHeight = maxHeight;
4241
+ el.style.overflowX = overflowX;
4242
+ el.style.overflowY = overflowY;
4243
+ }
4244
+ savedScrollContainersRef.current = [];
4245
+ }
4193
4246
  const enterCanvas = React7.useCallback(() => {
4194
4247
  const scrollX = window.scrollX;
4195
4248
  const scrollY = window.scrollY;
@@ -4197,15 +4250,16 @@ function useCanvas({ stateRef, setState }) {
4197
4250
  savedBodyOverflowRef.current = document.body.style.overflow;
4198
4251
  savedHtmlOverflowRef.current = document.documentElement.style.overflow;
4199
4252
  savedHtmlBgColorRef.current = document.documentElement.style.backgroundColor;
4200
- savedBodyDimensionsRef.current = {
4201
- width: document.body.scrollWidth,
4202
- height: document.body.scrollHeight
4203
- };
4204
4253
  const existingTransform = document.body.style.transform;
4205
4254
  if (existingTransform && existingTransform !== "none" && existingTransform !== "") {
4206
4255
  console.warn("[made-refine] canvas mode: overriding existing body transform:", existingTransform);
4207
4256
  }
4208
4257
  window.scrollTo(0, 0);
4258
+ expandScrollContainers();
4259
+ savedBodyDimensionsRef.current = {
4260
+ width: document.body.scrollWidth,
4261
+ height: document.body.scrollHeight
4262
+ };
4209
4263
  updateBodyOffset();
4210
4264
  document.body.style.overflow = "hidden";
4211
4265
  document.documentElement.style.overflow = "hidden";
@@ -4225,6 +4279,7 @@ function useCanvas({ stateRef, setState }) {
4225
4279
  cancelPendingRaf();
4226
4280
  document.body.style.transform = "";
4227
4281
  document.body.style.transformOrigin = "";
4282
+ restoreScrollContainers();
4228
4283
  document.body.style.overflow = savedBodyOverflowRef.current;
4229
4284
  document.documentElement.style.overflow = savedHtmlOverflowRef.current;
4230
4285
  document.documentElement.style.backgroundColor = savedHtmlBgColorRef.current;