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