@gustavo-valsechi/client 1.4.110 → 1.4.112

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.
@@ -52,10 +52,6 @@ function InputSelect(props) {
52
52
  console.log("inputValue", inputValue);
53
53
  const value = ((_b = import_lodash.default.find(props.options, (option) => Object.keys(option)[0] === inputValue)) == null ? void 0 : _b[inputValue || ""]) || "";
54
54
  console.log("valueContent", value);
55
- (0, import_react.useEffect)(() => {
56
- var _a2;
57
- (_a2 = props.setValue) == null ? void 0 : _a2.call(props, "1");
58
- }, []);
59
55
  (0, import_react.useEffect)(() => {
60
56
  var _a2;
61
57
  if (!(inputRef == null ? void 0 : inputRef.current) || !(containerRef == null ? void 0 : containerRef.current)) return;
@@ -19,10 +19,6 @@ function InputSelect(props) {
19
19
  console.log("inputValue", inputValue);
20
20
  const value = ((_b = _.find(props.options, (option) => Object.keys(option)[0] === inputValue)) == null ? void 0 : _b[inputValue || ""]) || "";
21
21
  console.log("valueContent", value);
22
- useEffect(() => {
23
- var _a2;
24
- (_a2 = props.setValue) == null ? void 0 : _a2.call(props, "1");
25
- }, []);
26
22
  useEffect(() => {
27
23
  var _a2;
28
24
  if (!(inputRef == null ? void 0 : inputRef.current) || !(containerRef == null ? void 0 : containerRef.current)) return;
@@ -2,4 +2,5 @@ import { IInputSelect } from "@interfaces";
2
2
  export default function InputSelectOption(props: IInputSelect & {
3
3
  inputRef: any;
4
4
  width: number;
5
+ value?: string;
5
6
  }): import("react/jsx-runtime").JSX.Element;
@@ -41,29 +41,22 @@ function InputSelectOption(props) {
41
41
  const [options, setOptions] = (0, import_react.useState)(props.options);
42
42
  (0, import_react.useEffect)(() => {
43
43
  var _a, _b;
44
- console.log("value", value);
45
- console.log("setValue", props.setValue);
46
- (_a = props.setValue) == null ? void 0 : _a.call(props, value);
44
+ (_a = props.setValue) == null ? void 0 : _a.call(props, props.name, value);
47
45
  if (!value || !((_b = props.inputRef) == null ? void 0 : _b.current)) return;
48
46
  props.inputRef.current.click();
49
47
  }, [value, props.inputRef]);
50
48
  (0, import_react.useEffect)(() => {
51
- var _a;
52
- if (!((_a = props.inputRef) == null ? void 0 : _a.current)) return;
53
- props.inputRef.current.addEventListener("change", (e) => {
54
- e.preventDefault();
55
- const filter = e.target.value || "";
56
- console.log("filter", filter);
57
- if (!filter) return setOptions(props.options);
58
- const filtredOptions = import_lodash.default.filter(props.options, (data) => {
59
- var _a2;
60
- const value2 = ((_a2 = Object.values(data || {})) == null ? void 0 : _a2[0]) || "";
61
- if (import_lodash.default.isString(value2)) return import_lodash.default.includes(value2, filter);
62
- return import_lodash.default.includes(value2 == null ? void 0 : value2.textContent, filter);
63
- });
64
- setOptions(filtredOptions);
49
+ const filter = props.value || "";
50
+ console.log("filter", filter);
51
+ if (!filter) return setOptions(props.options);
52
+ const filtredOptions = import_lodash.default.filter(props.options, (data) => {
53
+ var _a;
54
+ const value2 = ((_a = Object.values(data || {})) == null ? void 0 : _a[0]) || "";
55
+ if (import_lodash.default.isString(value2)) return import_lodash.default.includes(value2, filter);
56
+ return import_lodash.default.includes(value2 == null ? void 0 : value2.textContent, filter);
65
57
  });
66
- }, [props.inputRef]);
58
+ setOptions(filtredOptions);
59
+ }, [props.value]);
67
60
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.Container, { width: props.width, children: import_lodash.default.map(
68
61
  options,
69
62
  (data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -8,29 +8,22 @@ function InputSelectOption(props) {
8
8
  const [options, setOptions] = useState(props.options);
9
9
  useEffect(() => {
10
10
  var _a, _b;
11
- console.log("value", value);
12
- console.log("setValue", props.setValue);
13
- (_a = props.setValue) == null ? void 0 : _a.call(props, value);
11
+ (_a = props.setValue) == null ? void 0 : _a.call(props, props.name, value);
14
12
  if (!value || !((_b = props.inputRef) == null ? void 0 : _b.current)) return;
15
13
  props.inputRef.current.click();
16
14
  }, [value, props.inputRef]);
17
15
  useEffect(() => {
18
- var _a;
19
- if (!((_a = props.inputRef) == null ? void 0 : _a.current)) return;
20
- props.inputRef.current.addEventListener("change", (e) => {
21
- e.preventDefault();
22
- const filter = e.target.value || "";
23
- console.log("filter", filter);
24
- if (!filter) return setOptions(props.options);
25
- const filtredOptions = _.filter(props.options, (data) => {
26
- var _a2;
27
- const value2 = ((_a2 = Object.values(data || {})) == null ? void 0 : _a2[0]) || "";
28
- if (_.isString(value2)) return _.includes(value2, filter);
29
- return _.includes(value2 == null ? void 0 : value2.textContent, filter);
30
- });
31
- setOptions(filtredOptions);
16
+ const filter = props.value || "";
17
+ console.log("filter", filter);
18
+ if (!filter) return setOptions(props.options);
19
+ const filtredOptions = _.filter(props.options, (data) => {
20
+ var _a;
21
+ const value2 = ((_a = Object.values(data || {})) == null ? void 0 : _a[0]) || "";
22
+ if (_.isString(value2)) return _.includes(value2, filter);
23
+ return _.includes(value2 == null ? void 0 : value2.textContent, filter);
32
24
  });
33
- }, [props.inputRef]);
25
+ setOptions(filtredOptions);
26
+ }, [props.value]);
34
27
  return /* @__PURE__ */ jsx(Container, { width: props.width, children: _.map(
35
28
  options,
36
29
  (data, index) => /* @__PURE__ */ jsx(
@@ -50,9 +50,10 @@ const TargetProviderContainer = ({ children }) => {
50
50
  if (isFocusable) return target.ref.current;
51
51
  return inputRef.current[index];
52
52
  };
53
- const close = (element) => {
53
+ const close = (element, index) => {
54
54
  element.style.opacity = "0";
55
55
  element.style.zIndex = "-1";
56
+ insideMemory.splice(import_lodash.default.findIndex(insideMemory, (i) => i === index), 1);
56
57
  };
57
58
  const open = (element, coords) => {
58
59
  element.style.top = `${coords.top}px`;
@@ -64,7 +65,7 @@ const TargetProviderContainer = ({ children }) => {
64
65
  const handleScroll = () => {
65
66
  import_lodash.default.forEach(containerRef.current, (element, index) => {
66
67
  if (import_lodash.default.some(insideMemory, (i) => i === index)) return;
67
- close(element);
68
+ close(element, index);
68
69
  });
69
70
  };
70
71
  window.addEventListener("scroll", handleScroll, { passive: true });
@@ -104,12 +105,12 @@ const TargetProviderContainer = ({ children }) => {
104
105
  const element = (_a = target.ref) == null ? void 0 : _a.current;
105
106
  if (!(element == null ? void 0 : element.addEventListener)) return;
106
107
  const focusable = elementFocusable(target, index);
108
+ const targetElement = import_lodash.default.find(containerRef.current, (data, i) => i === index);
107
109
  element.addEventListener("click", () => {
108
- const targetElement = import_lodash.default.find(containerRef.current, (data, i) => i === index);
109
110
  if (!targetElement) return;
110
111
  const styles = window.getComputedStyle(targetElement);
111
112
  if (styles.opacity === "1") {
112
- close(targetElement);
113
+ close(targetElement, index);
113
114
  return;
114
115
  }
115
116
  const coords = getCoords(element);
@@ -117,11 +118,17 @@ const TargetProviderContainer = ({ children }) => {
117
118
  focusable.focus();
118
119
  });
119
120
  element.addEventListener("resize", () => {
120
- import_lodash.default.forEach(containerRef.current, (elementRef) => close(elementRef));
121
+ import_lodash.default.forEach(containerRef.current, (elementRef) => close(elementRef, index));
121
122
  });
122
123
  focusable.addEventListener("blur", () => {
123
124
  if (import_lodash.default.some(insideMemory, (i) => i === index)) return;
124
- close(containerRef.current[index]);
125
+ close(containerRef.current[index], index);
126
+ });
127
+ focusable.addEventListener("change", (e) => {
128
+ var _a2;
129
+ if (!targetElement) return;
130
+ e.preventDefault();
131
+ targetElement.setAttribute("value", ((_a2 = e.target) == null ? void 0 : _a2.value) || "");
125
132
  });
126
133
  });
127
134
  }, [targets, inputRef, containerRef]);
@@ -16,9 +16,10 @@ const TargetProviderContainer = ({ children }) => {
16
16
  if (isFocusable) return target.ref.current;
17
17
  return inputRef.current[index];
18
18
  };
19
- const close = (element) => {
19
+ const close = (element, index) => {
20
20
  element.style.opacity = "0";
21
21
  element.style.zIndex = "-1";
22
+ insideMemory.splice(_.findIndex(insideMemory, (i) => i === index), 1);
22
23
  };
23
24
  const open = (element, coords) => {
24
25
  element.style.top = `${coords.top}px`;
@@ -30,7 +31,7 @@ const TargetProviderContainer = ({ children }) => {
30
31
  const handleScroll = () => {
31
32
  _.forEach(containerRef.current, (element, index) => {
32
33
  if (_.some(insideMemory, (i) => i === index)) return;
33
- close(element);
34
+ close(element, index);
34
35
  });
35
36
  };
36
37
  window.addEventListener("scroll", handleScroll, { passive: true });
@@ -70,12 +71,12 @@ const TargetProviderContainer = ({ children }) => {
70
71
  const element = (_a = target.ref) == null ? void 0 : _a.current;
71
72
  if (!(element == null ? void 0 : element.addEventListener)) return;
72
73
  const focusable = elementFocusable(target, index);
74
+ const targetElement = _.find(containerRef.current, (data, i) => i === index);
73
75
  element.addEventListener("click", () => {
74
- const targetElement = _.find(containerRef.current, (data, i) => i === index);
75
76
  if (!targetElement) return;
76
77
  const styles = window.getComputedStyle(targetElement);
77
78
  if (styles.opacity === "1") {
78
- close(targetElement);
79
+ close(targetElement, index);
79
80
  return;
80
81
  }
81
82
  const coords = getCoords(element);
@@ -83,11 +84,17 @@ const TargetProviderContainer = ({ children }) => {
83
84
  focusable.focus();
84
85
  });
85
86
  element.addEventListener("resize", () => {
86
- _.forEach(containerRef.current, (elementRef) => close(elementRef));
87
+ _.forEach(containerRef.current, (elementRef) => close(elementRef, index));
87
88
  });
88
89
  focusable.addEventListener("blur", () => {
89
90
  if (_.some(insideMemory, (i) => i === index)) return;
90
- close(containerRef.current[index]);
91
+ close(containerRef.current[index], index);
92
+ });
93
+ focusable.addEventListener("change", (e) => {
94
+ var _a2;
95
+ if (!targetElement) return;
96
+ e.preventDefault();
97
+ targetElement.setAttribute("value", ((_a2 = e.target) == null ? void 0 : _a2.value) || "");
91
98
  });
92
99
  });
93
100
  }, [targets, inputRef, containerRef]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.110",
3
+ "version": "1.4.112",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",