@gustavo-valsechi/client 1.4.75 → 1.4.76

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.
@@ -42,41 +42,27 @@ const memory = [];
42
42
  const TargetProviderContainer = ({ children }) => {
43
43
  const containerRef = (0, import_react.useRef)([]);
44
44
  const [targets, setTargets] = (0, import_react.useState)([]);
45
- const [show, setShow] = (0, import_react.useState)([]);
46
45
  (0, import_react.useEffect)(() => {
47
46
  import_lodash.default.forEach(targets, (target, index) => {
48
47
  var _a;
49
48
  const element = (_a = target.ref) == null ? void 0 : _a.current;
50
49
  if (!element) return;
51
50
  element.addEventListener("click", () => {
52
- const showMemory = [...show];
53
- const isShow = import_lodash.default.find(showMemory, (data) => data.index === index);
54
- if (isShow) {
55
- const showIndex = import_lodash.default.findIndex(showMemory, (data) => data.index === index);
56
- showMemory.splice(showIndex, 1);
57
- setShow(showMemory);
51
+ const targetElement = import_lodash.default.find(containerRef.current, (data, i) => i === index);
52
+ if (!targetElement) return;
53
+ if (targetElement.style.opacity === "1") {
54
+ targetElement.style.opacity = "0";
55
+ targetElement.style.zIndex = "-1";
58
56
  return;
59
57
  }
60
- showMemory.push({ index, coords: getCoords(element) });
61
- setShow(showMemory);
58
+ const coords = getCoords(element);
59
+ targetElement.style.top = `${coords.top}px`;
60
+ targetElement.style.left = `${coords.left}px`;
61
+ targetElement.style.opacity = "1";
62
+ targetElement.style.zIndex = "10";
62
63
  });
63
64
  });
64
- }, [targets, show]);
65
- (0, import_react.useEffect)(() => {
66
- if (!containerRef.current) return;
67
- import_lodash.default.forEach(containerRef.current, (element, index) => {
68
- const config = import_lodash.default.find(show, (data) => data.index === index);
69
- if (!config) {
70
- element.style.opacity = "0";
71
- element.style.zIndex = "-1";
72
- return;
73
- }
74
- element.style.top = `${config.coords.top}px`;
75
- element.style.left = `${config.coords.left}px`;
76
- element.style.opacity = "1";
77
- element.style.zIndex = "10";
78
- });
79
- }, [show, containerRef]);
65
+ }, [targets]);
80
66
  const getCoords = (target) => {
81
67
  const rect = target.getBoundingClientRect();
82
68
  const targetTop = rect.top + window.scrollY;
@@ -8,41 +8,27 @@ const memory = [];
8
8
  const TargetProviderContainer = ({ children }) => {
9
9
  const containerRef = useRef([]);
10
10
  const [targets, setTargets] = useState([]);
11
- const [show, setShow] = useState([]);
12
11
  useEffect(() => {
13
12
  _.forEach(targets, (target, index) => {
14
13
  var _a;
15
14
  const element = (_a = target.ref) == null ? void 0 : _a.current;
16
15
  if (!element) return;
17
16
  element.addEventListener("click", () => {
18
- const showMemory = [...show];
19
- const isShow = _.find(showMemory, (data) => data.index === index);
20
- if (isShow) {
21
- const showIndex = _.findIndex(showMemory, (data) => data.index === index);
22
- showMemory.splice(showIndex, 1);
23
- setShow(showMemory);
17
+ const targetElement = _.find(containerRef.current, (data, i) => i === index);
18
+ if (!targetElement) return;
19
+ if (targetElement.style.opacity === "1") {
20
+ targetElement.style.opacity = "0";
21
+ targetElement.style.zIndex = "-1";
24
22
  return;
25
23
  }
26
- showMemory.push({ index, coords: getCoords(element) });
27
- setShow(showMemory);
24
+ const coords = getCoords(element);
25
+ targetElement.style.top = `${coords.top}px`;
26
+ targetElement.style.left = `${coords.left}px`;
27
+ targetElement.style.opacity = "1";
28
+ targetElement.style.zIndex = "10";
28
29
  });
29
30
  });
30
- }, [targets, show]);
31
- useEffect(() => {
32
- if (!containerRef.current) return;
33
- _.forEach(containerRef.current, (element, index) => {
34
- const config = _.find(show, (data) => data.index === index);
35
- if (!config) {
36
- element.style.opacity = "0";
37
- element.style.zIndex = "-1";
38
- return;
39
- }
40
- element.style.top = `${config.coords.top}px`;
41
- element.style.left = `${config.coords.left}px`;
42
- element.style.opacity = "1";
43
- element.style.zIndex = "10";
44
- });
45
- }, [show, containerRef]);
31
+ }, [targets]);
46
32
  const getCoords = (target) => {
47
33
  const rect = target.getBoundingClientRect();
48
34
  const targetTop = rect.top + window.scrollY;
@@ -6,13 +6,6 @@ export interface ITargetConfig {
6
6
  ref: React.RefObject<any>;
7
7
  component: React.ReactNode;
8
8
  }
9
- export interface ITargetShow {
10
- index: number;
11
- coords: {
12
- top: number;
13
- left: number;
14
- };
15
- }
16
9
  export interface ITargetConfigCoords {
17
10
  top: number;
18
11
  left: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.75",
3
+ "version": "1.4.76",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",