@gustavo-valsechi/client 1.4.77 → 1.4.79

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,36 +34,37 @@ __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;
56
+ console.log(index, "onClick");
53
57
  if (targetElement.style.opacity === "1") {
54
58
  targetElement.style.opacity = "0";
55
59
  targetElement.style.zIndex = "-1";
56
60
  return;
57
61
  }
58
- import_lodash.default.forEach(containerRef.current, () => {
59
- targetElement.style.opacity = "0";
60
- targetElement.style.zIndex = "-1";
61
- });
62
62
  const coords = getCoords(element);
63
63
  targetElement.style.top = `${coords.top}px`;
64
64
  targetElement.style.left = `${coords.left}px`;
65
65
  targetElement.style.opacity = "1";
66
66
  targetElement.style.zIndex = "10";
67
+ (_b = (_a2 = inputRef.current) == null ? void 0 : _a2[index]) == null ? void 0 : _b.focus();
67
68
  });
68
69
  });
69
70
  }, [targets]);
@@ -102,14 +103,41 @@ const TargetProviderContainer = ({ children }) => {
102
103
  children: [
103
104
  import_lodash.default.map(
104
105
  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
- )
106
+ (target, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.default.Fragment, { children: [
107
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
108
+ import_styles.Container,
109
+ {
110
+ ref: (element) => containerRef.current[index] = element,
111
+ onMouseEnter: () => {
112
+ var _a;
113
+ setInside(true);
114
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
115
+ },
116
+ onMouseLeave: () => {
117
+ var _a;
118
+ setInside(false);
119
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
120
+ },
121
+ children: target.component
122
+ }
123
+ ),
124
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
+ "input",
126
+ {
127
+ hidden: true,
128
+ ref: (element) => inputRef.current[index] = element,
129
+ onBlur: () => {
130
+ var _a;
131
+ if (inside) return;
132
+ console.log(index, "onBlur");
133
+ (_a = containerRef.current[index]) == null ? void 0 : _a.click();
134
+ },
135
+ onFocus: () => {
136
+ console.log(index, "onFocus");
137
+ }
138
+ }
139
+ )
140
+ ] }, index)
113
141
  ),
114
142
  children
115
143
  ]
@@ -1,35 +1,36 @@
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;
22
+ console.log(index, "onClick");
19
23
  if (targetElement.style.opacity === "1") {
20
24
  targetElement.style.opacity = "0";
21
25
  targetElement.style.zIndex = "-1";
22
26
  return;
23
27
  }
24
- _.forEach(containerRef.current, () => {
25
- targetElement.style.opacity = "0";
26
- targetElement.style.zIndex = "-1";
27
- });
28
28
  const coords = getCoords(element);
29
29
  targetElement.style.top = `${coords.top}px`;
30
30
  targetElement.style.left = `${coords.left}px`;
31
31
  targetElement.style.opacity = "1";
32
32
  targetElement.style.zIndex = "10";
33
+ (_b = (_a2 = inputRef.current) == null ? void 0 : _a2[index]) == null ? void 0 : _b.focus();
33
34
  });
34
35
  });
35
36
  }, [targets]);
@@ -68,14 +69,41 @@ const TargetProviderContainer = ({ children }) => {
68
69
  children: [
69
70
  _.map(
70
71
  targets,
71
- (target, index) => /* @__PURE__ */ jsx(
72
- Container,
73
- {
74
- ref: (element) => containerRef.current[index] = element,
75
- children: target.component
76
- },
77
- index
78
- )
72
+ (target, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
73
+ /* @__PURE__ */ jsx(
74
+ Container,
75
+ {
76
+ ref: (element) => containerRef.current[index] = element,
77
+ onMouseEnter: () => {
78
+ var _a;
79
+ setInside(true);
80
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
81
+ },
82
+ onMouseLeave: () => {
83
+ var _a;
84
+ setInside(false);
85
+ (_a = inputRef.current[index]) == null ? void 0 : _a.focus();
86
+ },
87
+ children: target.component
88
+ }
89
+ ),
90
+ /* @__PURE__ */ jsx(
91
+ "input",
92
+ {
93
+ hidden: true,
94
+ ref: (element) => inputRef.current[index] = element,
95
+ onBlur: () => {
96
+ var _a;
97
+ if (inside) return;
98
+ console.log(index, "onBlur");
99
+ (_a = containerRef.current[index]) == null ? void 0 : _a.click();
100
+ },
101
+ onFocus: () => {
102
+ console.log(index, "onFocus");
103
+ }
104
+ }
105
+ )
106
+ ] }, index)
79
107
  ),
80
108
  children
81
109
  ]
@@ -1 +1 @@
1
- export {};
1
+ import "./setup.mts";
@@ -0,0 +1 @@
1
+ export {};
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.79",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "build:assets": "node scripts/assets.js",
17
17
  "build": "npm run clean && npm run build:js && npm run build:types && npm run build:assets && npm run build:remodel",
18
18
  "commit": "npm run build && npm version patch --no-git-tag-version && npm publish --access public",
19
- "dev": "vite --open test/index.html"
19
+ "dev": "vite"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "react": "18.3.1",
@@ -59,7 +59,8 @@
59
59
  "styled-components": "6.1.12",
60
60
  "tsc-alias": "1.8.16",
61
61
  "typescript": "5.5.4",
62
- "vite": "^7.2.1"
62
+ "vite": "^7.2.1",
63
+ "vitest": "^4.0.8"
63
64
  },
64
65
  "publishConfig": {
65
66
  "access": "public"