@gustavo-valsechi/client 1.4.33 → 1.4.34

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.
@@ -43,12 +43,21 @@ var import_options = __toESM(require("./options"));
43
43
  function InputSelect(props) {
44
44
  const inputRef = (0, import_react.useRef)({});
45
45
  const target = (0, import_contexts.useTarget)();
46
+ const option = (0, import_react.useState)("");
46
47
  const [focus, setFocus] = (0, import_react.useState)(false);
47
48
  const register = (props.register || ((name) => ({})))(props.name || "");
48
49
  (0, import_react.useEffect)(() => {
49
- target.add({ ref: inputRef, component: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_options.default, {}) });
50
+ target.add({ ref: inputRef, component: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_options.default, { option: true, ...props }) });
50
51
  return () => target.remove(inputRef);
51
52
  }, []);
53
+ const onBlur = (event) => {
54
+ setFocus(false);
55
+ if (register.onBlur) register.onBlur(event);
56
+ };
57
+ const onFocus = (event) => {
58
+ setFocus(true);
59
+ if (register.onFocus) register.onFocus(event);
60
+ };
52
61
  const onChange = (event) => {
53
62
  const value = event.target.value || "";
54
63
  event.target.value = props.mask ? props.mask(value) : value;
@@ -67,34 +76,9 @@ function InputSelect(props) {
67
76
  type: "text",
68
77
  maxLength: props.maxLength || 255,
69
78
  ...register,
70
- onChange
71
- }
72
- ),
73
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
74
- "select",
75
- {
76
- ...import_lodash.default.omit(props, ["className", "onChange", "onFocus", "options", "onMouseDown", "onBlur", "maxLength", "required", "register"]),
77
- onMouseDown: () => setFocus(!focus),
78
- onFocus: () => {
79
- if (props.onFocus) props.onFocus(props.name);
80
- },
81
- ...register,
82
- onBlur: (event) => {
83
- if (register.onBlur) register.onBlur(event);
84
- setFocus(false);
85
- },
86
79
  onChange,
87
- children: import_lodash.default.map(
88
- props.options,
89
- (data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
90
- "option",
91
- {
92
- value: Object.keys(data),
93
- children: Object.values(data)
94
- },
95
- index
96
- )
97
- )
80
+ onFocus,
81
+ onBlur
98
82
  }
99
83
  ),
100
84
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("i", { "aria-hidden": true, className: focus ? "fa-solid fa-chevron-up" : "fa-solid fa-chevron-down" })
@@ -10,12 +10,21 @@ import InputSelectOption from "./options";
10
10
  function InputSelect(props) {
11
11
  const inputRef = useRef({});
12
12
  const target = useTarget();
13
+ const option = useState("");
13
14
  const [focus, setFocus] = useState(false);
14
15
  const register = (props.register || ((name) => ({})))(props.name || "");
15
16
  useEffect(() => {
16
- target.add({ ref: inputRef, component: /* @__PURE__ */ jsx(InputSelectOption, {}) });
17
+ target.add({ ref: inputRef, component: /* @__PURE__ */ jsx(InputSelectOption, { option: true, ...props }) });
17
18
  return () => target.remove(inputRef);
18
19
  }, []);
20
+ const onBlur = (event) => {
21
+ setFocus(false);
22
+ if (register.onBlur) register.onBlur(event);
23
+ };
24
+ const onFocus = (event) => {
25
+ setFocus(true);
26
+ if (register.onFocus) register.onFocus(event);
27
+ };
19
28
  const onChange = (event) => {
20
29
  const value = event.target.value || "";
21
30
  event.target.value = props.mask ? props.mask(value) : value;
@@ -34,34 +43,9 @@ function InputSelect(props) {
34
43
  type: "text",
35
44
  maxLength: props.maxLength || 255,
36
45
  ...register,
37
- onChange
38
- }
39
- ),
40
- /* @__PURE__ */ jsx(
41
- "select",
42
- {
43
- ..._.omit(props, ["className", "onChange", "onFocus", "options", "onMouseDown", "onBlur", "maxLength", "required", "register"]),
44
- onMouseDown: () => setFocus(!focus),
45
- onFocus: () => {
46
- if (props.onFocus) props.onFocus(props.name);
47
- },
48
- ...register,
49
- onBlur: (event) => {
50
- if (register.onBlur) register.onBlur(event);
51
- setFocus(false);
52
- },
53
46
  onChange,
54
- children: _.map(
55
- props.options,
56
- (data, index) => /* @__PURE__ */ jsx(
57
- "option",
58
- {
59
- value: Object.keys(data),
60
- children: Object.values(data)
61
- },
62
- index
63
- )
64
- )
47
+ onFocus,
48
+ onBlur
65
49
  }
66
50
  ),
67
51
  /* @__PURE__ */ jsx("i", { "aria-hidden": true, className: focus ? "fa-solid fa-chevron-up" : "fa-solid fa-chevron-down" })
@@ -1 +1,4 @@
1
- export default function InputSelectOption(props: any): import("react/jsx-runtime").JSX.Element;
1
+ import { IInputSelect } from "@interfaces";
2
+ export default function InputSelectOption(props: IInputSelect & {
3
+ option: any;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  "use client";
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var options_exports = {};
21
31
  __export(options_exports, {
@@ -24,6 +34,18 @@ __export(options_exports, {
24
34
  module.exports = __toCommonJS(options_exports);
25
35
  var import_jsx_runtime = require("react/jsx-runtime");
26
36
  var import_styles = require("./styles");
37
+ var import_lodash = __toESM(require("lodash"));
27
38
  function InputSelectOption(props) {
28
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.Container, {});
39
+ const [value, set] = props.option;
40
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.Container, { children: import_lodash.default.map(
41
+ props.options,
42
+ (data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
43
+ "option",
44
+ {
45
+ value: Object.keys(data),
46
+ children: Object.values(data)
47
+ },
48
+ index
49
+ )
50
+ ) });
29
51
  }
@@ -1,8 +1,20 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { Container } from "./styles";
4
+ import _ from "lodash";
4
5
  function InputSelectOption(props) {
5
- return /* @__PURE__ */ jsx(Container, {});
6
+ const [value, set] = props.option;
7
+ return /* @__PURE__ */ jsx(Container, { children: _.map(
8
+ props.options,
9
+ (data, index) => /* @__PURE__ */ jsx(
10
+ "option",
11
+ {
12
+ value: Object.keys(data),
13
+ children: Object.values(data)
14
+ },
15
+ index
16
+ )
17
+ ) });
6
18
  }
7
19
  export {
8
20
  InputSelectOption as default
@@ -40,8 +40,12 @@ const TargetContext = (0, import_react.createContext)({});
40
40
  const TargetProviderContainer = ({ children }) => {
41
41
  const [targets, setTargets] = (0, import_react.useState)([]);
42
42
  (0, import_react.useEffect)(() => {
43
- import_lodash.default.forEach(targets, ({ ref }) => {
44
- ref.current.addEventListener("click", () => {
43
+ let newTargets = [...targets];
44
+ if (JSON.stringify(targets) === JSON.stringify(newTargets)) return;
45
+ import_lodash.default.forEach(targets, (target, index) => {
46
+ target.ref.current.addEventListener("click", () => {
47
+ newTargets.splice(index, 1, { ...target, show: !target.show });
48
+ setTargets(newTargets);
45
49
  });
46
50
  });
47
51
  }, [targets]);
@@ -62,7 +66,6 @@ const TargetProviderContainer = ({ children }) => {
62
66
  return coords;
63
67
  };
64
68
  const add = (target) => {
65
- target.ref.current.addEventListener("click", () => target.show = !target.show);
66
69
  setTargets(import_lodash.default.concat(targets, target));
67
70
  };
68
71
  const remove = (ref) => {
@@ -6,8 +6,12 @@ const TargetContext = createContext({});
6
6
  const TargetProviderContainer = ({ children }) => {
7
7
  const [targets, setTargets] = useState([]);
8
8
  useEffect(() => {
9
- _.forEach(targets, ({ ref }) => {
10
- ref.current.addEventListener("click", () => {
9
+ let newTargets = [...targets];
10
+ if (JSON.stringify(targets) === JSON.stringify(newTargets)) return;
11
+ _.forEach(targets, (target, index) => {
12
+ target.ref.current.addEventListener("click", () => {
13
+ newTargets.splice(index, 1, { ...target, show: !target.show });
14
+ setTargets(newTargets);
11
15
  });
12
16
  });
13
17
  }, [targets]);
@@ -28,7 +32,6 @@ const TargetProviderContainer = ({ children }) => {
28
32
  return coords;
29
33
  };
30
34
  const add = (target) => {
31
- target.ref.current.addEventListener("click", () => target.show = !target.show);
32
35
  setTargets(_.concat(targets, target));
33
36
  };
34
37
  const remove = (ref) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.33",
3
+ "version": "1.4.34",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",