@gustavo-valsechi/client 1.4.117 → 1.4.119

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,18 +50,9 @@ function InputSelect(props) {
50
50
  const register = (props.register || ((name) => ({})))(props.name || "");
51
51
  const inputValue = (_a = props.watch) == null ? void 0 : _a.call(props, props.name);
52
52
  const value = ((_b = import_lodash.default.find(props.options, (option) => Object.keys(option)[0] === inputValue)) == null ? void 0 : _b[inputValue || ""]) || "";
53
- const onBlur = (event) => {
54
- setFocus(false);
55
- setFilter("");
56
- if (register.onBlur) register.onBlur(event);
57
- };
58
- const onFocus = (event) => {
59
- setFocus(true);
60
- if (register.onFocus) register.onFocus(event);
61
- };
62
- const onClick = (event) => {
53
+ (0, import_react.useEffect)(() => {
63
54
  var _a2;
64
- if (register.onClick) register.onClick(event);
55
+ if (!(inputRef == null ? void 0 : inputRef.current) || !(containerRef == null ? void 0 : containerRef.current)) return;
65
56
  target.add({
66
57
  ref: inputRef,
67
58
  component: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -74,6 +65,16 @@ function InputSelect(props) {
74
65
  }
75
66
  )
76
67
  });
68
+ return () => target.remove(inputRef);
69
+ }, [containerRef, inputRef]);
70
+ const onBlur = (event) => {
71
+ setFocus(false);
72
+ setFilter("");
73
+ if (register.onBlur) register.onBlur(event);
74
+ };
75
+ const onFocus = (event) => {
76
+ setFocus(true);
77
+ if (register.onFocus) register.onFocus(event);
77
78
  };
78
79
  const onChange = (event) => {
79
80
  const value2 = event.target.value || "";
@@ -106,7 +107,6 @@ function InputSelect(props) {
106
107
  onChange,
107
108
  onFocus,
108
109
  onBlur,
109
- onClick,
110
110
  value: focus ? filter : "",
111
111
  placeholder: import_lodash.default.isString(value) ? value : (value == null ? void 0 : value.textContent) || ""
112
112
  }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useState, useRef } from "react";
3
+ import { useState, useRef, useEffect } from "react";
4
4
  import { Container } from "./styles";
5
5
  import { InputLabel } from "../label";
6
6
  import { InputError } from "../error";
@@ -17,18 +17,9 @@ function InputSelect(props) {
17
17
  const register = (props.register || ((name) => ({})))(props.name || "");
18
18
  const inputValue = (_a = props.watch) == null ? void 0 : _a.call(props, props.name);
19
19
  const value = ((_b = _.find(props.options, (option) => Object.keys(option)[0] === inputValue)) == null ? void 0 : _b[inputValue || ""]) || "";
20
- const onBlur = (event) => {
21
- setFocus(false);
22
- setFilter("");
23
- if (register.onBlur) register.onBlur(event);
24
- };
25
- const onFocus = (event) => {
26
- setFocus(true);
27
- if (register.onFocus) register.onFocus(event);
28
- };
29
- const onClick = (event) => {
20
+ useEffect(() => {
30
21
  var _a2;
31
- if (register.onClick) register.onClick(event);
22
+ if (!(inputRef == null ? void 0 : inputRef.current) || !(containerRef == null ? void 0 : containerRef.current)) return;
32
23
  target.add({
33
24
  ref: inputRef,
34
25
  component: /* @__PURE__ */ jsx(
@@ -41,6 +32,16 @@ function InputSelect(props) {
41
32
  }
42
33
  )
43
34
  });
35
+ return () => target.remove(inputRef);
36
+ }, [containerRef, inputRef]);
37
+ const onBlur = (event) => {
38
+ setFocus(false);
39
+ setFilter("");
40
+ if (register.onBlur) register.onBlur(event);
41
+ };
42
+ const onFocus = (event) => {
43
+ setFocus(true);
44
+ if (register.onFocus) register.onFocus(event);
44
45
  };
45
46
  const onChange = (event) => {
46
47
  const value2 = event.target.value || "";
@@ -73,7 +74,6 @@ function InputSelect(props) {
73
74
  onChange,
74
75
  onFocus,
75
76
  onBlur,
76
- onClick,
77
77
  value: focus ? filter : "",
78
78
  placeholder: _.isString(value) ? value : (value == null ? void 0 : value.textContent) || ""
79
79
  }
@@ -44,7 +44,7 @@ function InputSelectOption(props) {
44
44
  (0, import_react.useEffect)(() => {
45
45
  var _a;
46
46
  (_a = props.setValue) == null ? void 0 : _a.call(props, props.name, value);
47
- target.remove(props.inputRef);
47
+ target.close(props.inputRef);
48
48
  }, [value, props.inputRef]);
49
49
  (0, import_react.useEffect)(() => {
50
50
  const optionsElement = document.getElementById("input-options");
@@ -11,7 +11,7 @@ function InputSelectOption(props) {
11
11
  useEffect(() => {
12
12
  var _a;
13
13
  (_a = props.setValue) == null ? void 0 : _a.call(props, props.name, value);
14
- target.remove(props.inputRef);
14
+ target.close(props.inputRef);
15
15
  }, [value, props.inputRef]);
16
16
  useEffect(() => {
17
17
  const optionsElement = document.getElementById("input-options");
@@ -151,15 +151,22 @@ const TargetProviderContainer = ({ children }) => {
151
151
  const remove = (ref) => {
152
152
  const index = import_lodash.default.findIndex(memory, (data) => data.ref.current === ref.current);
153
153
  insideMemory.splice(import_lodash.default.findIndex(insideMemory, (i) => i === index), 1);
154
- memory.slice(index, 1);
154
+ memory.splice(index, 1);
155
155
  setTargets(memory);
156
156
  };
157
+ const closeTarget = (ref) => {
158
+ 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);
162
+ };
157
163
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
158
164
  TargetContext.Provider,
159
165
  {
160
166
  value: {
161
167
  add,
162
- remove
168
+ remove,
169
+ close: closeTarget
163
170
  },
164
171
  children: [
165
172
  import_lodash.default.map(
@@ -117,15 +117,22 @@ const TargetProviderContainer = ({ children }) => {
117
117
  const remove = (ref) => {
118
118
  const index = _.findIndex(memory, (data) => data.ref.current === ref.current);
119
119
  insideMemory.splice(_.findIndex(insideMemory, (i) => i === index), 1);
120
- memory.slice(index, 1);
120
+ memory.splice(index, 1);
121
121
  setTargets(memory);
122
122
  };
123
+ const closeTarget = (ref) => {
124
+ 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);
128
+ };
123
129
  return /* @__PURE__ */ jsxs(
124
130
  TargetContext.Provider,
125
131
  {
126
132
  value: {
127
133
  add,
128
- remove
134
+ remove,
135
+ close: closeTarget
129
136
  },
130
137
  children: [
131
138
  _.map(
@@ -13,4 +13,5 @@ export interface ITargetConfigCoords {
13
13
  export interface ITargetContext {
14
14
  add: (config: ITargetConfig) => void;
15
15
  remove: (ref: React.RefObject<any>) => void;
16
+ close: (ref: React.RefObject<any>) => void;
16
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.117",
3
+ "version": "1.4.119",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",