asma-ui-core 3.101.3 → 3.101.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.
|
@@ -1,42 +1,49 @@
|
|
|
1
|
-
import { cloneElement as h, useCallback as k, useEffect as
|
|
2
|
-
var
|
|
1
|
+
import { cloneElement as h, useCallback as k, useEffect as l, useRef as c } from "react";
|
|
2
|
+
var L = {
|
|
3
3
|
onClick: "click",
|
|
4
4
|
onMouseDown: "mousedown",
|
|
5
5
|
onMouseUp: "mouseup",
|
|
6
6
|
onTouchStart: "touchstart",
|
|
7
7
|
onTouchEnd: "touchend"
|
|
8
|
-
},
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}, [
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}, t = [s, f].filter((e) => e !== !1).map((e) => T[e]).filter((e) => !!e);
|
|
17
|
-
for (const e of t) document.addEventListener(e, n);
|
|
8
|
+
}, g = ({ children: o, onClickAway: s, mouseEvent: f = "onClick", touchEvent: u = "onTouchEnd", disableReactTree: d = !1 }) => {
|
|
9
|
+
const m = c(null), p = c(s), a = c(!1), i = c(!1);
|
|
10
|
+
l(() => {
|
|
11
|
+
p.current = s;
|
|
12
|
+
}, [s]), l(() => {
|
|
13
|
+
const t = setTimeout(() => {
|
|
14
|
+
i.current = !0;
|
|
15
|
+
}, 0);
|
|
18
16
|
return () => {
|
|
19
|
-
|
|
17
|
+
clearTimeout(t), i.current = !1;
|
|
18
|
+
};
|
|
19
|
+
}, []), l(() => {
|
|
20
|
+
const t = (e) => {
|
|
21
|
+
const r = m.current, E = a.current;
|
|
22
|
+
a.current = !1, i.current && r && e.target instanceof Node && !r.contains(e.target) && (d || !E) && p.current(e);
|
|
23
|
+
}, n = [f, u].filter((e) => e !== !1).map((e) => L[e]).filter((e) => !!e);
|
|
24
|
+
for (const e of n) document.addEventListener(e, t);
|
|
25
|
+
return () => {
|
|
26
|
+
for (const e of n) document.removeEventListener(e, t);
|
|
20
27
|
};
|
|
21
28
|
}, [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
d,
|
|
30
|
+
f,
|
|
31
|
+
u
|
|
25
32
|
]);
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
typeof
|
|
30
|
-
}, [
|
|
31
|
-
return h(
|
|
32
|
-
ref:
|
|
33
|
-
...[
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
typeof
|
|
37
|
-
},
|
|
33
|
+
const R = k((t) => {
|
|
34
|
+
m.current = t;
|
|
35
|
+
const n = o.ref;
|
|
36
|
+
typeof n == "function" && n(t);
|
|
37
|
+
}, [o]), T = o.props;
|
|
38
|
+
return h(o, {
|
|
39
|
+
ref: R,
|
|
40
|
+
...[f, u].filter((t) => t !== !1).reduce((t, n) => (t[n] = (e) => {
|
|
41
|
+
a.current = !0;
|
|
42
|
+
const r = T[n];
|
|
43
|
+
typeof r == "function" && r(e);
|
|
44
|
+
}, t), {})
|
|
38
45
|
});
|
|
39
46
|
};
|
|
40
47
|
export {
|
|
41
|
-
|
|
48
|
+
g as ClickAwayListener
|
|
42
49
|
};
|