@gustavo-valsechi/client 1.4.49 → 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.
@@ -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,13 +48,15 @@ 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 newTargets = [...targets];
51
- const coords = getCoords(element);
52
- newTargets.splice(index, 1, { ...target, show: !target.show, coords });
53
- setTargets(newTargets);
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) });
54
57
  });
55
58
  });
56
- }, []);
59
+ }, [targets]);
57
60
  const getCoords = (target) => {
58
61
  const rect = target.getBoundingClientRect();
59
62
  const targetTop = rect.top + window.scrollY;
@@ -71,7 +74,7 @@ const TargetProviderContainer = ({ children }) => {
71
74
  return coords;
72
75
  };
73
76
  const add = (target) => {
74
- memory.push({ ...target, show: false, coords: { top: 0, left: 0 } });
77
+ memory.push(target);
75
78
  setTargets(memory);
76
79
  };
77
80
  const remove = (ref) => {
@@ -89,14 +92,17 @@ const TargetProviderContainer = ({ children }) => {
89
92
  children: [
90
93
  import_lodash.default.map(
91
94
  targets,
92
- (target, index) => target.show ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
93
- import_styles.Container,
94
- {
95
- style: target.coords,
96
- children: target.component
97
- },
98
- index
99
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {})
95
+ (target, index) => {
96
+ var _a;
97
+ return import_lodash.default.some(show, (data) => data.index === index) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
98
+ import_styles.Container,
99
+ {
100
+ style: (_a = import_lodash.default.find(show, (data) => data.index === index)) == null ? void 0 : _a.coords,
101
+ children: target.component
102
+ },
103
+ index
104
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
105
+ }
100
106
  ),
101
107
  children
102
108
  ]
@@ -5,6 +5,7 @@ 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,13 +14,15 @@ 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 newTargets = [...targets];
17
- const coords = getCoords(element);
18
- newTargets.splice(index, 1, { ...target, show: !target.show, coords });
19
- setTargets(newTargets);
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) });
20
23
  });
21
24
  });
22
- }, []);
25
+ }, [targets]);
23
26
  const getCoords = (target) => {
24
27
  const rect = target.getBoundingClientRect();
25
28
  const targetTop = rect.top + window.scrollY;
@@ -37,7 +40,7 @@ const TargetProviderContainer = ({ children }) => {
37
40
  return coords;
38
41
  };
39
42
  const add = (target) => {
40
- memory.push({ ...target, show: false, coords: { top: 0, left: 0 } });
43
+ memory.push(target);
41
44
  setTargets(memory);
42
45
  };
43
46
  const remove = (ref) => {
@@ -55,14 +58,17 @@ const TargetProviderContainer = ({ children }) => {
55
58
  children: [
56
59
  _.map(
57
60
  targets,
58
- (target, index) => target.show ? /* @__PURE__ */ jsx(
59
- Container,
60
- {
61
- style: target.coords,
62
- children: target.component
63
- },
64
- index
65
- ) : /* @__PURE__ */ jsx(Fragment, {})
61
+ (target, index) => {
62
+ var _a;
63
+ return _.some(show, (data) => data.index === index) ? /* @__PURE__ */ jsx(
64
+ Container,
65
+ {
66
+ style: (_a = _.find(show, (data) => data.index === index)) == null ? void 0 : _a.coords,
67
+ children: target.component
68
+ },
69
+ index
70
+ ) : /* @__PURE__ */ jsx(Fragment, {});
71
+ }
66
72
  ),
67
73
  children
68
74
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.49",
3
+ "version": "1.4.50",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",