@gustavo-valsechi/client 1.4.77 → 1.4.78

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.
@@ -40,10 +40,8 @@ function InputSelectOption(props) {
40
40
  var _a, _b;
41
41
  const [value, set] = (0, import_react.useState)("");
42
42
  (0, import_react.useEffect)(() => {
43
- var _a2, _b2;
43
+ var _a2;
44
44
  (_a2 = props.setValue) == null ? void 0 : _a2.call(props, value);
45
- if (!value || !((_b2 = props.inputRef) == null ? void 0 : _b2.current)) return;
46
- props.inputRef.current.click();
47
45
  }, [value, props.inputRef]);
48
46
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.Container, { width: (_b = (_a = props.inputRef) == null ? void 0 : _a.current) == null ? void 0 : _b.offsetWidth, children: import_lodash.default.map(
49
47
  props.options,
@@ -7,10 +7,8 @@ function InputSelectOption(props) {
7
7
  var _a, _b;
8
8
  const [value, set] = useState("");
9
9
  useEffect(() => {
10
- var _a2, _b2;
10
+ var _a2;
11
11
  (_a2 = props.setValue) == null ? void 0 : _a2.call(props, value);
12
- if (!value || !((_b2 = props.inputRef) == null ? void 0 : _b2.current)) return;
13
- props.inputRef.current.click();
14
12
  }, [value, props.inputRef]);
15
13
  return /* @__PURE__ */ jsx(Container, { width: (_b = (_a = props.inputRef) == null ? void 0 : _a.current) == null ? void 0 : _b.offsetWidth, children: _.map(
16
14
  props.options,
@@ -34,20 +34,23 @@ __export(target_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(target_exports);
36
36
  var import_jsx_runtime = require("react/jsx-runtime");
37
- var import_react = require("react");
37
+ var import_react = __toESM(require("react"));
38
38
  var import_styles = require("./styles");
39
39
  var import_lodash = __toESM(require("lodash"));
40
40
  const TargetContext = (0, import_react.createContext)({});
41
41
  const memory = [];
42
42
  const TargetProviderContainer = ({ children }) => {
43
+ const inputRef = (0, import_react.useRef)([]);
43
44
  const containerRef = (0, import_react.useRef)([]);
44
45
  const [targets, setTargets] = (0, import_react.useState)([]);
46
+ const [inside, setInside] = (0, import_react.useState)(false);
45
47
  (0, import_react.useEffect)(() => {
46
48
  import_lodash.default.forEach(targets, (target, index) => {
47
49
  var _a;
48
50
  const element = (_a = target.ref) == null ? void 0 : _a.current;
49
51
  if (!element) return;
50
52
  element.addEventListener("click", () => {
53
+ var _a2, _b;
51
54
  const targetElement = import_lodash.default.find(containerRef.current, (data, i) => i === index);
52
55
  if (!targetElement) return;
53
56
  if (targetElement.style.opacity === "1") {
@@ -55,15 +58,12 @@ const TargetProviderContainer = ({ children }) => {
55
58
  targetElement.style.zIndex = "-1";
56
59
  return;
57
60
  }
58
- import_lodash.default.forEach(containerRef.current, () => {
59
- targetElement.style.opacity = "0";
60
- targetElement.style.zIndex = "-1";
61
- });
62
61
  const coords = getCoords(element);
63
62
  targetElement.style.top = `${coords.top}px`;
64
63
  targetElement.style.left = `${coords.left}px`;
65
64
  targetElement.style.opacity = "1";
66
65
  targetElement.style.zIndex = "10";
66
+ (_b = (_a2 = inputRef.current) == null ? void 0 : _a2[index]) == null ? void 0 : _b.focus();
67
67
  });
68
68
  });
69
69
  }, [targets]);
@@ -102,14 +102,36 @@ const TargetProviderContainer = ({ children }) => {
102
102
  children: [
103
103
  import_lodash.default.map(
104
104
  targets,
105
- (target, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
106
- import_styles.Container,
107
- {
108
- ref: (element) => containerRef.current[index] = element,
109
- children: target.component
110
- },
111
- index
112
- )
105
+ (target, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.default.Fragment, { children: [
106
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
+ import_styles.Container,
108
+ {
109
+ ref: (element) => containerRef.current[index] = element,
110
+ onMouseEnter: () => {
111
+ var _a;
112
+ setInside(true);
113
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
114
+ },
115
+ onMouseLeave: () => {
116
+ var _a;
117
+ setInside(false);
118
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
119
+ },
120
+ children: target.component
121
+ }
122
+ ),
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
+ "input",
125
+ {
126
+ hidden: true,
127
+ ref: (element) => inputRef.current[index] = element,
128
+ onBlur: () => {
129
+ var _a;
130
+ return !inside && ((_a = containerRef.current[index]) == null ? void 0 : _a.click());
131
+ }
132
+ }
133
+ )
134
+ ] }, index)
113
135
  ),
114
136
  children
115
137
  ]
@@ -1,19 +1,22 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { createContext, useContext, useEffect, useState, useRef } from "react";
3
+ import React, { createContext, useContext, useEffect, useState, useRef } from "react";
4
4
  import { Container } from "./styles";
5
5
  import _ from "lodash";
6
6
  const TargetContext = createContext({});
7
7
  const memory = [];
8
8
  const TargetProviderContainer = ({ children }) => {
9
+ const inputRef = useRef([]);
9
10
  const containerRef = useRef([]);
10
11
  const [targets, setTargets] = useState([]);
12
+ const [inside, setInside] = useState(false);
11
13
  useEffect(() => {
12
14
  _.forEach(targets, (target, index) => {
13
15
  var _a;
14
16
  const element = (_a = target.ref) == null ? void 0 : _a.current;
15
17
  if (!element) return;
16
18
  element.addEventListener("click", () => {
19
+ var _a2, _b;
17
20
  const targetElement = _.find(containerRef.current, (data, i) => i === index);
18
21
  if (!targetElement) return;
19
22
  if (targetElement.style.opacity === "1") {
@@ -21,15 +24,12 @@ const TargetProviderContainer = ({ children }) => {
21
24
  targetElement.style.zIndex = "-1";
22
25
  return;
23
26
  }
24
- _.forEach(containerRef.current, () => {
25
- targetElement.style.opacity = "0";
26
- targetElement.style.zIndex = "-1";
27
- });
28
27
  const coords = getCoords(element);
29
28
  targetElement.style.top = `${coords.top}px`;
30
29
  targetElement.style.left = `${coords.left}px`;
31
30
  targetElement.style.opacity = "1";
32
31
  targetElement.style.zIndex = "10";
32
+ (_b = (_a2 = inputRef.current) == null ? void 0 : _a2[index]) == null ? void 0 : _b.focus();
33
33
  });
34
34
  });
35
35
  }, [targets]);
@@ -68,14 +68,36 @@ const TargetProviderContainer = ({ children }) => {
68
68
  children: [
69
69
  _.map(
70
70
  targets,
71
- (target, index) => /* @__PURE__ */ jsx(
72
- Container,
73
- {
74
- ref: (element) => containerRef.current[index] = element,
75
- children: target.component
76
- },
77
- index
78
- )
71
+ (target, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
72
+ /* @__PURE__ */ jsx(
73
+ Container,
74
+ {
75
+ ref: (element) => containerRef.current[index] = element,
76
+ onMouseEnter: () => {
77
+ var _a;
78
+ setInside(true);
79
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
80
+ },
81
+ onMouseLeave: () => {
82
+ var _a;
83
+ setInside(false);
84
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
85
+ },
86
+ children: target.component
87
+ }
88
+ ),
89
+ /* @__PURE__ */ jsx(
90
+ "input",
91
+ {
92
+ hidden: true,
93
+ ref: (element) => inputRef.current[index] = element,
94
+ onBlur: () => {
95
+ var _a;
96
+ return !inside && ((_a = containerRef.current[index]) == null ? void 0 : _a.click());
97
+ }
98
+ }
99
+ )
100
+ ] }, index)
79
101
  ),
80
102
  children
81
103
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.77",
3
+ "version": "1.4.78",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",