@gustavo-valsechi/client 1.4.119 → 1.4.121

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.
@@ -50,22 +50,29 @@ const TargetProviderContainer = ({ children }) => {
50
50
  if (isFocusable) return target.ref.current;
51
51
  return inputRef.current[index];
52
52
  };
53
- const close = (element, index) => {
53
+ const blur = (index) => {
54
+ insideMemory.splice(import_lodash.default.findIndex(insideMemory, (i) => i === index), 1);
55
+ elementFocusable(targets[index], index).blur();
56
+ };
57
+ const close = (target, index) => {
58
+ const element = containerRef.current[index];
54
59
  element.style.opacity = "0";
55
60
  element.style.zIndex = "-1";
56
61
  insideMemory.splice(import_lodash.default.findIndex(insideMemory, (i) => i === index), 1);
57
62
  };
58
- const open = (element, coords) => {
63
+ const open = (target, index, coords) => {
64
+ const element = containerRef.current[index];
59
65
  element.style.top = `${coords.top}px`;
60
66
  element.style.left = `${coords.left}px`;
61
67
  element.style.opacity = "1";
62
68
  element.style.zIndex = "10";
69
+ elementFocusable(target, index).focus();
63
70
  };
64
71
  (0, import_react.useEffect)(() => {
65
72
  const handleScroll = () => {
66
73
  import_lodash.default.forEach(containerRef.current, (element, index) => {
67
74
  if (import_lodash.default.some(insideMemory, (i) => i === index)) return;
68
- close(element, index);
75
+ close(targets[index], index);
69
76
  });
70
77
  };
71
78
  window.addEventListener("scroll", handleScroll, { passive: true });
@@ -98,31 +105,29 @@ const TargetProviderContainer = ({ children }) => {
98
105
  });
99
106
  observer.disconnect();
100
107
  };
101
- }, []);
108
+ }, [targets]);
102
109
  (0, import_react.useEffect)(() => {
103
110
  import_lodash.default.forEach(targets, (target, index) => {
104
111
  var _a;
105
112
  const element = (_a = target.ref) == null ? void 0 : _a.current;
106
113
  if (!(element == null ? void 0 : element.addEventListener)) return;
107
114
  const focusable = elementFocusable(target, index);
108
- const targetElement = import_lodash.default.find(containerRef.current, (data, i) => i === index);
115
+ const targetElement = containerRef.current[index];
109
116
  element.addEventListener("click", () => {
110
- if (!targetElement) return;
111
117
  const styles = window.getComputedStyle(targetElement);
112
118
  if (styles.opacity === "1") {
113
- close(targetElement, index);
119
+ close(target, index);
114
120
  return;
115
121
  }
116
122
  const coords = getCoords(element);
117
- open(targetElement, coords);
118
- focusable.focus();
123
+ open(target, index, coords);
119
124
  });
120
125
  element.addEventListener("resize", () => {
121
- import_lodash.default.forEach(containerRef.current, (elementRef) => close(elementRef, index));
126
+ import_lodash.default.forEach(containerRef.current, (elementRef) => blur(index));
122
127
  });
123
128
  focusable.addEventListener("blur", () => {
124
129
  if (import_lodash.default.some(insideMemory, (i) => i === index)) return;
125
- close(containerRef.current[index], index);
130
+ close(target, index);
126
131
  });
127
132
  });
128
133
  }, [targets, inputRef, containerRef]);
@@ -156,9 +161,7 @@ const TargetProviderContainer = ({ children }) => {
156
161
  };
157
162
  const closeTarget = (ref) => {
158
163
  const index = import_lodash.default.findIndex(memory, (data) => data.ref.current === ref.current);
159
- const targetElement = import_lodash.default.find(containerRef.current, (data, i) => i === index);
160
- if (!targetElement) return;
161
- close(targetElement, index);
164
+ blur(index);
162
165
  };
163
166
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
164
167
  TargetContext.Provider,
@@ -16,22 +16,29 @@ const TargetProviderContainer = ({ children }) => {
16
16
  if (isFocusable) return target.ref.current;
17
17
  return inputRef.current[index];
18
18
  };
19
- const close = (element, index) => {
19
+ const blur = (index) => {
20
+ insideMemory.splice(_.findIndex(insideMemory, (i) => i === index), 1);
21
+ elementFocusable(targets[index], index).blur();
22
+ };
23
+ const close = (target, index) => {
24
+ const element = containerRef.current[index];
20
25
  element.style.opacity = "0";
21
26
  element.style.zIndex = "-1";
22
27
  insideMemory.splice(_.findIndex(insideMemory, (i) => i === index), 1);
23
28
  };
24
- const open = (element, coords) => {
29
+ const open = (target, index, coords) => {
30
+ const element = containerRef.current[index];
25
31
  element.style.top = `${coords.top}px`;
26
32
  element.style.left = `${coords.left}px`;
27
33
  element.style.opacity = "1";
28
34
  element.style.zIndex = "10";
35
+ elementFocusable(target, index).focus();
29
36
  };
30
37
  useEffect(() => {
31
38
  const handleScroll = () => {
32
39
  _.forEach(containerRef.current, (element, index) => {
33
40
  if (_.some(insideMemory, (i) => i === index)) return;
34
- close(element, index);
41
+ close(targets[index], index);
35
42
  });
36
43
  };
37
44
  window.addEventListener("scroll", handleScroll, { passive: true });
@@ -64,31 +71,29 @@ const TargetProviderContainer = ({ children }) => {
64
71
  });
65
72
  observer.disconnect();
66
73
  };
67
- }, []);
74
+ }, [targets]);
68
75
  useEffect(() => {
69
76
  _.forEach(targets, (target, index) => {
70
77
  var _a;
71
78
  const element = (_a = target.ref) == null ? void 0 : _a.current;
72
79
  if (!(element == null ? void 0 : element.addEventListener)) return;
73
80
  const focusable = elementFocusable(target, index);
74
- const targetElement = _.find(containerRef.current, (data, i) => i === index);
81
+ const targetElement = containerRef.current[index];
75
82
  element.addEventListener("click", () => {
76
- if (!targetElement) return;
77
83
  const styles = window.getComputedStyle(targetElement);
78
84
  if (styles.opacity === "1") {
79
- close(targetElement, index);
85
+ close(target, index);
80
86
  return;
81
87
  }
82
88
  const coords = getCoords(element);
83
- open(targetElement, coords);
84
- focusable.focus();
89
+ open(target, index, coords);
85
90
  });
86
91
  element.addEventListener("resize", () => {
87
- _.forEach(containerRef.current, (elementRef) => close(elementRef, index));
92
+ _.forEach(containerRef.current, (elementRef) => blur(index));
88
93
  });
89
94
  focusable.addEventListener("blur", () => {
90
95
  if (_.some(insideMemory, (i) => i === index)) return;
91
- close(containerRef.current[index], index);
96
+ close(target, index);
92
97
  });
93
98
  });
94
99
  }, [targets, inputRef, containerRef]);
@@ -122,9 +127,7 @@ const TargetProviderContainer = ({ children }) => {
122
127
  };
123
128
  const closeTarget = (ref) => {
124
129
  const index = _.findIndex(memory, (data) => data.ref.current === ref.current);
125
- const targetElement = _.find(containerRef.current, (data, i) => i === index);
126
- if (!targetElement) return;
127
- close(targetElement, index);
130
+ blur(index);
128
131
  };
129
132
  return /* @__PURE__ */ jsxs(
130
133
  TargetContext.Provider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.119",
3
+ "version": "1.4.121",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",