@tensor_1/react 2.6.0 → 2.7.0
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/components/Field.js +10 -4
- package/dist/components/Popover.d.ts +18 -4
- package/dist/components/Popover.js +31 -2
- package/dist/components/Toast.js +5 -4
- package/dist/components/Tooltip.d.ts +9 -5
- package/dist/components/Tooltip.js +61 -3
- package/dist/components/Tree.d.ts +15 -1
- package/dist/components/Tree.js +247 -35
- package/dist/hooks/useAnchoredPosition.d.ts +22 -0
- package/dist/hooks/useAnchoredPosition.js +44 -0
- package/dist/hooks/useDialog.js +36 -5
- package/dist/index.cjs +657 -100
- package/dist/index.d.cts +164 -11
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/overlay-position.d.ts +59 -0
- package/dist/overlay-position.js +62 -0
- package/dist/table-engine.js +72 -6
- package/dist/tree-model.d.ts +48 -0
- package/dist/tree-model.js +49 -0
- package/package.json +1 -1
package/dist/hooks/useDialog.js
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useRef, useEffect } from "react";
|
|
3
|
+
let lockCount = 0;
|
|
4
|
+
let saved = null;
|
|
5
|
+
function lockBodyScroll() {
|
|
6
|
+
if (typeof document === "undefined") return;
|
|
7
|
+
if (++lockCount > 1) return;
|
|
8
|
+
const el = document.scrollingElement ?? document.documentElement;
|
|
9
|
+
const scrollbarW = window.innerWidth - document.documentElement.clientWidth;
|
|
10
|
+
saved = {
|
|
11
|
+
el,
|
|
12
|
+
overflow: el.style.overflow,
|
|
13
|
+
paddingRight: el.style.paddingRight,
|
|
14
|
+
overscroll: el.style.overscrollBehavior
|
|
15
|
+
};
|
|
16
|
+
el.style.overflow = "hidden";
|
|
17
|
+
if (scrollbarW > 0) {
|
|
18
|
+
const current = parseFloat(getComputedStyle(el).paddingRight) || 0;
|
|
19
|
+
el.style.paddingRight = `${current + scrollbarW}px`;
|
|
20
|
+
}
|
|
21
|
+
el.style.overscrollBehavior = "contain";
|
|
22
|
+
}
|
|
23
|
+
function unlockBodyScroll() {
|
|
24
|
+
if (typeof document === "undefined" || lockCount === 0) return;
|
|
25
|
+
if (--lockCount > 0) return;
|
|
26
|
+
if (saved) {
|
|
27
|
+
saved.el.style.overflow = saved.overflow;
|
|
28
|
+
saved.el.style.paddingRight = saved.paddingRight;
|
|
29
|
+
saved.el.style.overscrollBehavior = saved.overscroll;
|
|
30
|
+
saved = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
3
33
|
function useDialog(open) {
|
|
4
34
|
const ref = useRef(null);
|
|
5
35
|
useEffect(() => {
|
|
6
36
|
const el = ref.current;
|
|
7
|
-
if (!el)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} else {
|
|
11
|
-
if (el.open) el.close();
|
|
37
|
+
if (!el || !open) {
|
|
38
|
+
if (el && el.open) el.close();
|
|
39
|
+
return;
|
|
12
40
|
}
|
|
41
|
+
if (!el.open) el.showModal();
|
|
42
|
+
lockBodyScroll();
|
|
13
43
|
return () => {
|
|
44
|
+
unlockBodyScroll();
|
|
14
45
|
if (el.open) el.close();
|
|
15
46
|
};
|
|
16
47
|
}, [open]);
|