@gustavo-valsechi/client 1.4.45 → 1.4.47

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.
@@ -47,13 +47,14 @@ const TargetProviderContainer = ({ children }) => {
47
47
  const element = (_a = target.ref) == null ? void 0 : _a.current;
48
48
  if (!element) return;
49
49
  element.addEventListener("click", () => {
50
- const coords = getCoords(element);
51
- memory.splice(index, 1, { ...target, show: !target.show, coords });
52
- setTargets(memory);
50
+ const newTargets = [...targets];
51
+ newTargets.splice(index, 1, { ...target, show: !target.show });
52
+ setTargets(newTargets);
53
53
  });
54
54
  });
55
55
  }, [targets]);
56
56
  const getCoords = (target) => {
57
+ if (!target) return {};
57
58
  const rect = target.getBoundingClientRect();
58
59
  const targetTop = rect.top + window.scrollY;
59
60
  const targetLeft = rect.left + window.scrollX;
@@ -70,7 +71,7 @@ const TargetProviderContainer = ({ children }) => {
70
71
  return coords;
71
72
  };
72
73
  const add = (target) => {
73
- memory.push({ ...target, show: false, coords: { top: 0, left: 0 } });
74
+ memory.push({ ...target, show: false });
74
75
  setTargets(memory);
75
76
  };
76
77
  const remove = (ref) => {
@@ -88,14 +89,21 @@ const TargetProviderContainer = ({ children }) => {
88
89
  children: [
89
90
  import_lodash.default.map(
90
91
  targets,
91
- (target, index) => target.show ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
- import_styles.Container,
93
- {
94
- style: target.coords,
95
- children: target.component
96
- },
97
- index
98
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {})
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
+ }
99
107
  ),
100
108
  children
101
109
  ]
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { 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";
@@ -13,13 +13,14 @@ const TargetProviderContainer = ({ children }) => {
13
13
  const element = (_a = target.ref) == null ? void 0 : _a.current;
14
14
  if (!element) return;
15
15
  element.addEventListener("click", () => {
16
- const coords = getCoords(element);
17
- memory.splice(index, 1, { ...target, show: !target.show, coords });
18
- setTargets(memory);
16
+ const newTargets = [...targets];
17
+ newTargets.splice(index, 1, { ...target, show: !target.show });
18
+ setTargets(newTargets);
19
19
  });
20
20
  });
21
21
  }, [targets]);
22
22
  const getCoords = (target) => {
23
+ if (!target) return {};
23
24
  const rect = target.getBoundingClientRect();
24
25
  const targetTop = rect.top + window.scrollY;
25
26
  const targetLeft = rect.left + window.scrollX;
@@ -36,7 +37,7 @@ const TargetProviderContainer = ({ children }) => {
36
37
  return coords;
37
38
  };
38
39
  const add = (target) => {
39
- memory.push({ ...target, show: false, coords: { top: 0, left: 0 } });
40
+ memory.push({ ...target, show: false });
40
41
  setTargets(memory);
41
42
  };
42
43
  const remove = (ref) => {
@@ -54,14 +55,21 @@ const TargetProviderContainer = ({ children }) => {
54
55
  children: [
55
56
  _.map(
56
57
  targets,
57
- (target, index) => target.show ? /* @__PURE__ */ jsx(
58
- Container,
59
- {
60
- style: target.coords,
61
- children: target.component
62
- },
63
- index
64
- ) : /* @__PURE__ */ jsx(Fragment, {})
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
+ }
65
73
  ),
66
74
  children
67
75
  ]
@@ -34,7 +34,6 @@ module.exports = __toCommonJS(styles_exports);
34
34
  var import_styled_components = __toESM(require("styled-components"));
35
35
  const Container = import_styled_components.default.div`
36
36
  position: absolute;
37
- z-index: 10;
38
37
 
39
38
  @media(max-width: ${({ theme }) => theme.mobileMaxWidth}) {
40
39
  width: 100%;
@@ -1,7 +1,6 @@
1
1
  import styled from "styled-components";
2
2
  const Container = styled.div`
3
3
  position: absolute;
4
- z-index: 10;
5
4
 
6
5
  @media(max-width: ${({ theme }) => theme.mobileMaxWidth}) {
7
6
  width: 100%;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.45",
3
+ "version": "1.4.47",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",