@gustavo-valsechi/client 1.4.69 → 1.4.71
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 +25 -17
- package/dist/contexts/target/index.mjs +26 -18
- package/package.json +1 -1
|
@@ -41,6 +41,7 @@ const TargetContext = (0, import_react.createContext)({});
|
|
|
41
41
|
const memory = [];
|
|
42
42
|
const showMemory = [];
|
|
43
43
|
const TargetProviderContainer = ({ children }) => {
|
|
44
|
+
const containerRef = (0, import_react.useRef)([]);
|
|
44
45
|
const [targets, setTargets] = (0, import_react.useState)([]);
|
|
45
46
|
const [show, setShow] = (0, import_react.useState)([]);
|
|
46
47
|
(0, import_react.useEffect)(() => {
|
|
@@ -63,6 +64,19 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
63
64
|
});
|
|
64
65
|
});
|
|
65
66
|
}, [targets]);
|
|
67
|
+
(0, import_react.useEffect)(() => {
|
|
68
|
+
if (!containerRef.current) return;
|
|
69
|
+
import_lodash.default.forEach(containerRef.current, (element, index) => {
|
|
70
|
+
const config = import_lodash.default.find(show, (data) => data.index === index);
|
|
71
|
+
if (!config) {
|
|
72
|
+
element.style.display = "none";
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
element.style.top = `${config.coords.top}px`;
|
|
76
|
+
element.style.left = `${config.coords.left}px`;
|
|
77
|
+
element.style.display = "block";
|
|
78
|
+
});
|
|
79
|
+
}, [show, containerRef]);
|
|
66
80
|
const getCoords = (target) => {
|
|
67
81
|
const rect = target.getBoundingClientRect();
|
|
68
82
|
const targetTop = rect.top + window.scrollY;
|
|
@@ -88,22 +102,6 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
88
102
|
memory.slice(index, 1);
|
|
89
103
|
setTargets(memory);
|
|
90
104
|
};
|
|
91
|
-
console.log("show fora", show);
|
|
92
|
-
const renderTarget = (0, import_react.useCallback)((target, index) => {
|
|
93
|
-
console.log("show dentro", show);
|
|
94
|
-
const targetContent = import_lodash.default.find(show, (data) => data.index === index);
|
|
95
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
|
-
import_styles.Container,
|
|
97
|
-
{
|
|
98
|
-
style: {
|
|
99
|
-
...(targetContent == null ? void 0 : targetContent.coords) || {},
|
|
100
|
-
visibility: !!targetContent ? "visible" : "hidden"
|
|
101
|
-
},
|
|
102
|
-
children: target.component
|
|
103
|
-
},
|
|
104
|
-
index
|
|
105
|
-
);
|
|
106
|
-
}, [show]);
|
|
107
105
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
108
106
|
TargetContext.Provider,
|
|
109
107
|
{
|
|
@@ -112,7 +110,17 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
112
110
|
remove
|
|
113
111
|
},
|
|
114
112
|
children: [
|
|
115
|
-
import_lodash.default.map(
|
|
113
|
+
import_lodash.default.map(
|
|
114
|
+
targets,
|
|
115
|
+
(target, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
116
|
+
import_styles.Container,
|
|
117
|
+
{
|
|
118
|
+
ref: (element) => containerRef.current[index] = element,
|
|
119
|
+
children: target.component
|
|
120
|
+
},
|
|
121
|
+
index
|
|
122
|
+
)
|
|
123
|
+
),
|
|
116
124
|
children
|
|
117
125
|
]
|
|
118
126
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useEffect, useState,
|
|
3
|
+
import { createContext, useContext, useEffect, useState, useRef } from "react";
|
|
4
4
|
import { Container } from "./styles";
|
|
5
5
|
import _ from "lodash";
|
|
6
6
|
const TargetContext = createContext({});
|
|
7
7
|
const memory = [];
|
|
8
8
|
const showMemory = [];
|
|
9
9
|
const TargetProviderContainer = ({ children }) => {
|
|
10
|
+
const containerRef = useRef([]);
|
|
10
11
|
const [targets, setTargets] = useState([]);
|
|
11
12
|
const [show, setShow] = useState([]);
|
|
12
13
|
useEffect(() => {
|
|
@@ -29,6 +30,19 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
29
30
|
});
|
|
30
31
|
});
|
|
31
32
|
}, [targets]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!containerRef.current) return;
|
|
35
|
+
_.forEach(containerRef.current, (element, index) => {
|
|
36
|
+
const config = _.find(show, (data) => data.index === index);
|
|
37
|
+
if (!config) {
|
|
38
|
+
element.style.display = "none";
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
element.style.top = `${config.coords.top}px`;
|
|
42
|
+
element.style.left = `${config.coords.left}px`;
|
|
43
|
+
element.style.display = "block";
|
|
44
|
+
});
|
|
45
|
+
}, [show, containerRef]);
|
|
32
46
|
const getCoords = (target) => {
|
|
33
47
|
const rect = target.getBoundingClientRect();
|
|
34
48
|
const targetTop = rect.top + window.scrollY;
|
|
@@ -54,22 +68,6 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
54
68
|
memory.slice(index, 1);
|
|
55
69
|
setTargets(memory);
|
|
56
70
|
};
|
|
57
|
-
console.log("show fora", show);
|
|
58
|
-
const renderTarget = useCallback((target, index) => {
|
|
59
|
-
console.log("show dentro", show);
|
|
60
|
-
const targetContent = _.find(show, (data) => data.index === index);
|
|
61
|
-
return /* @__PURE__ */ jsx(
|
|
62
|
-
Container,
|
|
63
|
-
{
|
|
64
|
-
style: {
|
|
65
|
-
...(targetContent == null ? void 0 : targetContent.coords) || {},
|
|
66
|
-
visibility: !!targetContent ? "visible" : "hidden"
|
|
67
|
-
},
|
|
68
|
-
children: target.component
|
|
69
|
-
},
|
|
70
|
-
index
|
|
71
|
-
);
|
|
72
|
-
}, [show]);
|
|
73
71
|
return /* @__PURE__ */ jsxs(
|
|
74
72
|
TargetContext.Provider,
|
|
75
73
|
{
|
|
@@ -78,7 +76,17 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
78
76
|
remove
|
|
79
77
|
},
|
|
80
78
|
children: [
|
|
81
|
-
_.map(
|
|
79
|
+
_.map(
|
|
80
|
+
targets,
|
|
81
|
+
(target, index) => /* @__PURE__ */ jsx(
|
|
82
|
+
Container,
|
|
83
|
+
{
|
|
84
|
+
ref: (element) => containerRef.current[index] = element,
|
|
85
|
+
children: target.component
|
|
86
|
+
},
|
|
87
|
+
index
|
|
88
|
+
)
|
|
89
|
+
),
|
|
82
90
|
children
|
|
83
91
|
]
|
|
84
92
|
}
|