@gustavo-valsechi/client 1.4.47 → 1.4.49

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