@gustavo-valsechi/client 1.4.111 → 1.4.113

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.
@@ -49,9 +49,7 @@ function InputSelect(props) {
49
49
  const [filter, setFilter] = (0, import_react.useState)("");
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
- console.log("inputValue", inputValue);
53
52
  const value = ((_b = import_lodash.default.find(props.options, (option) => Object.keys(option)[0] === inputValue)) == null ? void 0 : _b[inputValue || ""]) || "";
54
- console.log("valueContent", value);
55
53
  (0, import_react.useEffect)(() => {
56
54
  var _a2;
57
55
  if (!(inputRef == null ? void 0 : inputRef.current) || !(containerRef == null ? void 0 : containerRef.current)) return;
@@ -16,9 +16,7 @@ function InputSelect(props) {
16
16
  const [filter, setFilter] = useState("");
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
- console.log("inputValue", inputValue);
20
19
  const value = ((_b = _.find(props.options, (option) => Object.keys(option)[0] === inputValue)) == null ? void 0 : _b[inputValue || ""]) || "";
21
- console.log("valueContent", value);
22
20
  useEffect(() => {
23
21
  var _a2;
24
22
  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;
@@ -43,26 +43,20 @@ function InputSelectOption(props) {
43
43
  var _a, _b;
44
44
  (_a = props.setValue) == null ? void 0 : _a.call(props, props.name, value);
45
45
  if (!value || !((_b = props.inputRef) == null ? void 0 : _b.current)) return;
46
- props.inputRef.current.click();
46
+ props.inputRef.current.blur();
47
47
  }, [value, props.inputRef]);
48
48
  (0, import_react.useEffect)(() => {
49
- const inputRef = document.getElementById(`input-${props.name}`);
50
- if (!inputRef) return;
51
- inputRef.addEventListener("change", (e) => {
52
- e.preventDefault();
53
- const target = e.target;
54
- const filter = target.value || "";
55
- console.log("filter", filter);
56
- if (!filter) return setOptions(props.options);
57
- const filtredOptions = import_lodash.default.filter(props.options, (data) => {
58
- var _a;
59
- const value2 = ((_a = Object.values(data || {})) == null ? void 0 : _a[0]) || "";
60
- if (import_lodash.default.isString(value2)) return import_lodash.default.includes(value2, filter);
61
- return import_lodash.default.includes(value2 == null ? void 0 : value2.textContent, filter);
62
- });
63
- 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);
64
57
  });
65
- }, []);
58
+ setOptions(filtredOptions);
59
+ }, [props.value]);
66
60
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.Container, { width: props.width, children: import_lodash.default.map(
67
61
  options,
68
62
  (data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -10,26 +10,20 @@ function InputSelectOption(props) {
10
10
  var _a, _b;
11
11
  (_a = props.setValue) == null ? void 0 : _a.call(props, props.name, value);
12
12
  if (!value || !((_b = props.inputRef) == null ? void 0 : _b.current)) return;
13
- props.inputRef.current.click();
13
+ props.inputRef.current.blur();
14
14
  }, [value, props.inputRef]);
15
15
  useEffect(() => {
16
- const inputRef = document.getElementById(`input-${props.name}`);
17
- if (!inputRef) return;
18
- inputRef.addEventListener("change", (e) => {
19
- e.preventDefault();
20
- const target = e.target;
21
- const filter = target.value || "";
22
- console.log("filter", filter);
23
- if (!filter) return setOptions(props.options);
24
- const filtredOptions = _.filter(props.options, (data) => {
25
- var _a;
26
- const value2 = ((_a = Object.values(data || {})) == null ? void 0 : _a[0]) || "";
27
- if (_.isString(value2)) return _.includes(value2, filter);
28
- return _.includes(value2 == null ? void 0 : value2.textContent, filter);
29
- });
30
- 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);
31
24
  });
32
- }, []);
25
+ setOptions(filtredOptions);
26
+ }, [props.value]);
33
27
  return /* @__PURE__ */ jsx(Container, { width: props.width, children: _.map(
34
28
  options,
35
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,18 @@ 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
+ e.preventDefault();
130
+ const value = ((_a2 = e.target) == null ? void 0 : _a2.value) || "";
131
+ console.log("input target value", value);
132
+ target.component = import_react.default.cloneElement(target.component, { value });
125
133
  });
126
134
  });
127
135
  }, [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,18 @@ 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
+ e.preventDefault();
96
+ const value = ((_a2 = e.target) == null ? void 0 : _a2.value) || "";
97
+ console.log("input target value", value);
98
+ target.component = React.cloneElement(target.component, { value });
91
99
  });
92
100
  });
93
101
  }, [targets, inputRef, containerRef]);
@@ -4,7 +4,7 @@ export interface ITargetProvider extends IBaseProvider {
4
4
  }
5
5
  export interface ITargetConfig {
6
6
  ref: React.RefObject<any>;
7
- component: React.ReactNode;
7
+ component: React.ReactElement;
8
8
  }
9
9
  export interface ITargetConfigCoords {
10
10
  top: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.111",
3
+ "version": "1.4.113",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",