dtable-ui-component 6.0.51 → 6.0.52-alpha.1
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.
|
@@ -14,54 +14,84 @@ function ColorPickerPortal(_ref) {
|
|
|
14
14
|
let {
|
|
15
15
|
target,
|
|
16
16
|
scrollContainerId,
|
|
17
|
-
throttleDelay,
|
|
17
|
+
throttleDelay = 16,
|
|
18
18
|
children
|
|
19
19
|
} = _ref;
|
|
20
20
|
const containerRef = (0, _react.useRef)(null);
|
|
21
|
-
const [
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const [isPositioned, setIsPositioned] = (0, _react.useState)(false);
|
|
22
|
+
const [position, setPosition] = (0, _react.useState)(() => {
|
|
23
|
+
return {
|
|
24
|
+
top: '-9999px',
|
|
25
|
+
left: '-9999px',
|
|
26
|
+
visibility: 'hidden'
|
|
27
|
+
};
|
|
24
28
|
});
|
|
25
|
-
(0, _react.
|
|
29
|
+
const updatePosition = (0, _react.useCallback)(() => {
|
|
26
30
|
if (!target || !containerRef.current) return;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
top: "calc(".concat(spaceAbove, "px + 2.375rem)"),
|
|
37
|
-
left: left + 1 + 'px'
|
|
38
|
-
});
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
setPosition({
|
|
42
|
-
top: "calc(".concat(spaceAbove - portalRectHeight, "px)"),
|
|
43
|
-
left: left + 1 + 'px'
|
|
44
|
-
});
|
|
31
|
+
const targetRect = target.getBoundingClientRect();
|
|
32
|
+
const {
|
|
33
|
+
top: spaceAbove,
|
|
34
|
+
left
|
|
35
|
+
} = targetRect;
|
|
36
|
+
const portalRectHeight = containerRef.current.clientHeight;
|
|
37
|
+
const newPosition = {
|
|
38
|
+
left: "".concat(left + 1, "px"),
|
|
39
|
+
visibility: 'visible'
|
|
45
40
|
};
|
|
46
|
-
|
|
41
|
+
if (spaceAbove < portalRectHeight) {
|
|
42
|
+
newPosition.top = "calc(".concat(spaceAbove, "px + 2.375rem)");
|
|
43
|
+
} else {
|
|
44
|
+
newPosition.top = "calc(".concat(spaceAbove - portalRectHeight, "px)");
|
|
45
|
+
}
|
|
46
|
+
setPosition(prev => ({
|
|
47
|
+
...prev,
|
|
48
|
+
...newPosition
|
|
49
|
+
}));
|
|
50
|
+
if (!isPositioned) {
|
|
51
|
+
setIsPositioned(true);
|
|
52
|
+
}
|
|
53
|
+
}, [target, isPositioned]);
|
|
54
|
+
(0, _react.useEffect)(() => {
|
|
55
|
+
if (!target) return;
|
|
56
|
+
|
|
57
|
+
// 初始计算位置
|
|
58
|
+
const initialPosition = () => {
|
|
59
|
+
updatePosition();
|
|
60
|
+
// 强制重排,确保位置计算准确
|
|
61
|
+
requestAnimationFrame(updatePosition);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// 使用setTimeout确保DOM更新后再计算位置
|
|
65
|
+
const timer = setTimeout(initialPosition, 0);
|
|
47
66
|
const throttledUpdatePosition = (0, _utils.throttle)(updatePosition, throttleDelay);
|
|
48
67
|
const scrollContainer = scrollContainerId ? document.getElementById(scrollContainerId) : null;
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
|
|
69
|
+
// 添加事件监听
|
|
70
|
+
scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.addEventListener('scroll', throttledUpdatePosition, {
|
|
71
|
+
passive: true
|
|
72
|
+
});
|
|
73
|
+
window.addEventListener('resize', throttledUpdatePosition, {
|
|
74
|
+
passive: true
|
|
75
|
+
});
|
|
51
76
|
return () => {
|
|
52
|
-
|
|
53
|
-
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
window.removeEventListener('resize', throttledUpdatePosition);
|
|
79
|
+
scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener('scroll', throttledUpdatePosition);
|
|
54
80
|
};
|
|
55
|
-
}, [target,
|
|
81
|
+
}, [target, scrollContainerId, throttleDelay, updatePosition]);
|
|
82
|
+
if (!target) return null;
|
|
56
83
|
return /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
57
84
|
className: "dtable-color-picker-portal",
|
|
58
85
|
style: {
|
|
59
|
-
position: '
|
|
86
|
+
position: 'fixed',
|
|
60
87
|
zIndex: '10',
|
|
61
88
|
left: position.left,
|
|
62
89
|
top: position.top,
|
|
63
90
|
width: '240px',
|
|
64
|
-
height: '370px'
|
|
91
|
+
height: '370px',
|
|
92
|
+
visibility: position.visibility,
|
|
93
|
+
opacity: isPositioned ? 1 : 0,
|
|
94
|
+
transition: 'opacity 0.15s ease-in-out'
|
|
65
95
|
},
|
|
66
96
|
ref: containerRef,
|
|
67
97
|
children: children
|