publ-echo-test 0.0.176 → 0.0.177
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.
@@ -1,8 +1,13 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { useEffect, useRef } from 'react';
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
3
3
|
var OutsideClickHandler = function (_a) {
|
4
4
|
var children = _a.children, onOutsideClick = _a.onOutsideClick;
|
5
5
|
var wrapperRef = useRef(null);
|
6
|
+
var _b = useState({
|
7
|
+
transform: '',
|
8
|
+
width: '0',
|
9
|
+
height: '0'
|
10
|
+
}), childDimensions = _b[0], setChildDimensions = _b[1];
|
6
11
|
useEffect(function () {
|
7
12
|
var handleClickOutside = function (e) {
|
8
13
|
var target = e.target;
|
@@ -10,7 +15,7 @@ var OutsideClickHandler = function (_a) {
|
|
10
15
|
return;
|
11
16
|
}
|
12
17
|
if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
|
13
|
-
onOutsideClick();
|
18
|
+
onOutsideClick();
|
14
19
|
}
|
15
20
|
};
|
16
21
|
document.addEventListener('dblclick', handleClickOutside);
|
@@ -18,6 +23,57 @@ var OutsideClickHandler = function (_a) {
|
|
18
23
|
document.removeEventListener('dblclick', handleClickOutside);
|
19
24
|
};
|
20
25
|
}, [onOutsideClick]);
|
21
|
-
|
26
|
+
// Find and set child dimensions when component mounts or children change
|
27
|
+
useEffect(function () {
|
28
|
+
if (wrapperRef.current && wrapperRef.current.children.length > 0) {
|
29
|
+
var childElement = wrapperRef.current.children[0];
|
30
|
+
// Get computed style of the child element
|
31
|
+
var computedStyle = window.getComputedStyle(childElement);
|
32
|
+
setChildDimensions({
|
33
|
+
transform: computedStyle.transform,
|
34
|
+
width: computedStyle.width,
|
35
|
+
height: computedStyle.height
|
36
|
+
});
|
37
|
+
}
|
38
|
+
}, [children, wrapperRef.current]);
|
39
|
+
// Parse dimensions to numbers for calculations
|
40
|
+
var width = parseFloat(childDimensions.width) || 0;
|
41
|
+
var height = parseFloat(childDimensions.height) || 0;
|
42
|
+
var borderThickness = 3; // 3px border thickness
|
43
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { ref: wrapperRef, className: 'outside-click-wrapper', children: children }), width > 0 && height > 0 && (_jsxs(_Fragment, { children: [_jsx("div", { className: "border-top", style: {
|
44
|
+
position: 'absolute',
|
45
|
+
transform: childDimensions.transform,
|
46
|
+
width: "".concat(width, "px"),
|
47
|
+
height: "".concat(borderThickness, "px"),
|
48
|
+
backgroundColor: 'blue',
|
49
|
+
pointerEvents: 'none',
|
50
|
+
zIndex: 999
|
51
|
+
} }), _jsx("div", { className: "border-right", style: {
|
52
|
+
position: 'absolute',
|
53
|
+
transform: childDimensions.transform,
|
54
|
+
width: "".concat(borderThickness, "px"),
|
55
|
+
height: "".concat(height, "px"),
|
56
|
+
backgroundColor: 'blue',
|
57
|
+
marginLeft: "".concat(width - borderThickness, "px"),
|
58
|
+
pointerEvents: 'none',
|
59
|
+
zIndex: 999
|
60
|
+
} }), _jsx("div", { className: "border-bottom", style: {
|
61
|
+
position: 'absolute',
|
62
|
+
transform: childDimensions.transform,
|
63
|
+
width: "".concat(width, "px"),
|
64
|
+
height: "".concat(borderThickness, "px"),
|
65
|
+
backgroundColor: 'blue',
|
66
|
+
marginTop: "".concat(height - borderThickness, "px"),
|
67
|
+
pointerEvents: 'none',
|
68
|
+
zIndex: 999
|
69
|
+
} }), _jsx("div", { className: "border-left", style: {
|
70
|
+
position: 'absolute',
|
71
|
+
transform: childDimensions.transform,
|
72
|
+
width: "".concat(borderThickness, "px"),
|
73
|
+
height: "".concat(height, "px"),
|
74
|
+
backgroundColor: 'blue',
|
75
|
+
pointerEvents: 'none',
|
76
|
+
zIndex: 999
|
77
|
+
} })] }))] }));
|
22
78
|
};
|
23
79
|
export default OutsideClickHandler;
|