@gustavo-valsechi/client 1.4.48 → 1.4.50
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/contexts/target/index.js +12 -13
- package/dist/contexts/target/index.mjs +13 -14
- package/package.json +1 -1
|
@@ -39,6 +39,7 @@ var import_styles = require("./styles");
|
|
|
39
39
|
var import_lodash = __toESM(require("lodash"));
|
|
40
40
|
const TargetContext = (0, import_react.createContext)({});
|
|
41
41
|
const memory = [];
|
|
42
|
+
const show = [];
|
|
42
43
|
const TargetProviderContainer = ({ children }) => {
|
|
43
44
|
const [targets, setTargets] = (0, import_react.useState)([]);
|
|
44
45
|
(0, import_react.useEffect)(() => {
|
|
@@ -47,14 +48,16 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
47
48
|
const element = (_a = target.ref) == null ? void 0 : _a.current;
|
|
48
49
|
if (!element) return;
|
|
49
50
|
element.addEventListener("click", () => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const isShow = import_lodash.default.find(show, (data) => data.index === index);
|
|
52
|
+
if (isShow) {
|
|
53
|
+
show.slice(index, 1);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
show.push({ index, coords: getCoords(element) });
|
|
53
57
|
});
|
|
54
58
|
});
|
|
55
|
-
}, []);
|
|
59
|
+
}, [targets]);
|
|
56
60
|
const getCoords = (target) => {
|
|
57
|
-
if (!target) return {};
|
|
58
61
|
const rect = target.getBoundingClientRect();
|
|
59
62
|
const targetTop = rect.top + window.scrollY;
|
|
60
63
|
const targetLeft = rect.left + window.scrollX;
|
|
@@ -71,7 +74,7 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
71
74
|
return coords;
|
|
72
75
|
};
|
|
73
76
|
const add = (target) => {
|
|
74
|
-
memory.push(
|
|
77
|
+
memory.push(target);
|
|
75
78
|
setTargets(memory);
|
|
76
79
|
};
|
|
77
80
|
const remove = (ref) => {
|
|
@@ -91,18 +94,14 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
91
94
|
targets,
|
|
92
95
|
(target, index) => {
|
|
93
96
|
var _a;
|
|
94
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
97
|
+
return import_lodash.default.some(show, (data) => data.index === index) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
95
98
|
import_styles.Container,
|
|
96
99
|
{
|
|
97
|
-
style:
|
|
98
|
-
...getCoords((_a = target.ref) == null ? void 0 : _a.current),
|
|
99
|
-
zIndex: target.show ? "10" : "-1",
|
|
100
|
-
opacity: target.show ? "1" : "0"
|
|
101
|
-
},
|
|
100
|
+
style: (_a = import_lodash.default.find(show, (data) => data.index === index)) == null ? void 0 : _a.coords,
|
|
102
101
|
children: target.component
|
|
103
102
|
},
|
|
104
103
|
index
|
|
105
|
-
);
|
|
104
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
106
105
|
}
|
|
107
106
|
),
|
|
108
107
|
children
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
4
|
import { Container } from "./styles";
|
|
5
5
|
import _ from "lodash";
|
|
6
6
|
const TargetContext = createContext({});
|
|
7
7
|
const memory = [];
|
|
8
|
+
const show = [];
|
|
8
9
|
const TargetProviderContainer = ({ children }) => {
|
|
9
10
|
const [targets, setTargets] = useState([]);
|
|
10
11
|
useEffect(() => {
|
|
@@ -13,14 +14,16 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
13
14
|
const element = (_a = target.ref) == null ? void 0 : _a.current;
|
|
14
15
|
if (!element) return;
|
|
15
16
|
element.addEventListener("click", () => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const isShow = _.find(show, (data) => data.index === index);
|
|
18
|
+
if (isShow) {
|
|
19
|
+
show.slice(index, 1);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
show.push({ index, coords: getCoords(element) });
|
|
19
23
|
});
|
|
20
24
|
});
|
|
21
|
-
}, []);
|
|
25
|
+
}, [targets]);
|
|
22
26
|
const getCoords = (target) => {
|
|
23
|
-
if (!target) return {};
|
|
24
27
|
const rect = target.getBoundingClientRect();
|
|
25
28
|
const targetTop = rect.top + window.scrollY;
|
|
26
29
|
const targetLeft = rect.left + window.scrollX;
|
|
@@ -37,7 +40,7 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
37
40
|
return coords;
|
|
38
41
|
};
|
|
39
42
|
const add = (target) => {
|
|
40
|
-
memory.push(
|
|
43
|
+
memory.push(target);
|
|
41
44
|
setTargets(memory);
|
|
42
45
|
};
|
|
43
46
|
const remove = (ref) => {
|
|
@@ -57,18 +60,14 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
57
60
|
targets,
|
|
58
61
|
(target, index) => {
|
|
59
62
|
var _a;
|
|
60
|
-
return /* @__PURE__ */ jsx(
|
|
63
|
+
return _.some(show, (data) => data.index === index) ? /* @__PURE__ */ jsx(
|
|
61
64
|
Container,
|
|
62
65
|
{
|
|
63
|
-
style:
|
|
64
|
-
...getCoords((_a = target.ref) == null ? void 0 : _a.current),
|
|
65
|
-
zIndex: target.show ? "10" : "-1",
|
|
66
|
-
opacity: target.show ? "1" : "0"
|
|
67
|
-
},
|
|
66
|
+
style: (_a = _.find(show, (data) => data.index === index)) == null ? void 0 : _a.coords,
|
|
68
67
|
children: target.component
|
|
69
68
|
},
|
|
70
69
|
index
|
|
71
|
-
);
|
|
70
|
+
) : /* @__PURE__ */ jsx(Fragment, {});
|
|
72
71
|
}
|
|
73
72
|
),
|
|
74
73
|
children
|