prometeo-design-system 3.1.0 → 3.1.1
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.
package/dist/SelectSearch.es.js
CHANGED
|
@@ -1,97 +1,99 @@
|
|
|
1
1
|
import { j as X } from "./jsx-runtime-DKDX3adD.js";
|
|
2
2
|
import { g as i, S as Y } from "./Select-mdLPyy7g.js";
|
|
3
|
-
import { useState as
|
|
4
|
-
function
|
|
3
|
+
import { useState as k, useRef as j, useEffect as m, useMemo as Z, useCallback as ee } from "react";
|
|
4
|
+
function le(e) {
|
|
5
5
|
const {
|
|
6
|
-
options:
|
|
7
|
-
fetcher:
|
|
8
|
-
asyncMode:
|
|
9
|
-
disabled:
|
|
10
|
-
debounceDelay:
|
|
11
|
-
minCharacters:
|
|
12
|
-
optionLabel:
|
|
6
|
+
options: p,
|
|
7
|
+
fetcher: u,
|
|
8
|
+
asyncMode: C = "fetch_in_open",
|
|
9
|
+
disabled: V = !1,
|
|
10
|
+
debounceDelay: R = 500,
|
|
11
|
+
minCharacters: L = 3,
|
|
12
|
+
optionLabel: h,
|
|
13
13
|
optionValue: s,
|
|
14
|
-
controlledValue:
|
|
15
|
-
isOpen:
|
|
16
|
-
inputRef:
|
|
17
|
-
name:
|
|
18
|
-
} = e || {},
|
|
14
|
+
controlledValue: c,
|
|
15
|
+
isOpen: P,
|
|
16
|
+
inputRef: x,
|
|
17
|
+
name: S
|
|
18
|
+
} = e || {}, A = p ? p.filter((t) => t != null) : [], [v, _] = k(A || []), [D, y] = k(A || []), [d, E] = k(""), [J, l] = k(!1), [O, b] = k(!1), g = j(null), N = j(null), z = j(!1), U = j(u), F = e?.multiple === !0 || !1, w = j(F ? [] : void 0), [f, M] = k(F ? [] : void 0);
|
|
19
19
|
m(() => {
|
|
20
|
-
|
|
21
|
-
}, [
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, [
|
|
20
|
+
U.current = u;
|
|
21
|
+
}, [u]), m(() => {
|
|
22
|
+
if (c !== void 0)
|
|
23
|
+
if (F) {
|
|
24
|
+
const t = $(c, "value");
|
|
25
|
+
M(t);
|
|
26
|
+
} else
|
|
27
|
+
c != null && M(c);
|
|
28
|
+
}, [c]), m(() => {
|
|
29
|
+
w.current = c !== void 0 ? c : f;
|
|
30
|
+
}, [c, f]), m(() => {
|
|
29
31
|
if (e?.options) {
|
|
30
32
|
const t = e.options.filter((n) => n != null);
|
|
31
|
-
|
|
33
|
+
_(t), y(t);
|
|
32
34
|
}
|
|
33
35
|
}, [e?.options]);
|
|
34
36
|
const B = Z(() => (t, n) => new Promise((o, r) => {
|
|
35
|
-
|
|
36
|
-
}), [
|
|
37
|
-
const n =
|
|
37
|
+
g.current && clearTimeout(g.current), g.current = setTimeout(() => t(d).then(o).catch(r), n);
|
|
38
|
+
}), [d]), te = (t) => {
|
|
39
|
+
const n = c !== void 0, o = (r) => s ? i(r, s) : i(r, "id");
|
|
38
40
|
if (e?.multiple === !0) {
|
|
39
|
-
const r =
|
|
40
|
-
let
|
|
41
|
-
r.some((
|
|
41
|
+
const r = w.current || [];
|
|
42
|
+
let a;
|
|
43
|
+
r.some((I) => o(I) === o(t)) ? a = r.filter((I) => o(I) !== o(t)) : a = [...r, t], n ? (w.current = a, e?.onChange?.(a, S)) : (w.current = a, M(a), e?.onChange?.(a, S));
|
|
42
44
|
} else
|
|
43
|
-
n ? (
|
|
44
|
-
}, q = (t) => (e?.onFetchingStart?.(),
|
|
45
|
+
n ? (w.current = t, e?.onChange?.(t, S)) : (w.current = t, M(t), e?.onChange?.(t, S));
|
|
46
|
+
}, q = (t) => (e?.onFetchingStart?.(), U.current?.(t) || Promise.resolve([])), $ = (t, n) => Array.isArray(t) ? (t.some((o) => typeof o != "object" || o === null) && console.debug(`El valor del ${n || "resultado del fetcher"} contiene elementos no válidos (null,undefined, no-object)`, t), t?.filter((o) => o != null) || []) : (console.debug(`El valor del ${n || "resultado del fetcher"} no es un Array (tipo de dato obtenido: ${typeof t})`), []), K = ee((t, n) => t.length === 0 ? n : s ? n.filter((o) => !t.some((r) => i(r, s) === i(o, s))) : n.filter((o) => !t.some((r) => i(r, "id") === i(o, "id"))), [s]);
|
|
45
47
|
m(() => {
|
|
46
48
|
const t = e?.subscribeOpenChange;
|
|
47
49
|
if (!t) return;
|
|
48
50
|
const n = t((o) => {
|
|
49
|
-
|
|
51
|
+
b(o);
|
|
50
52
|
});
|
|
51
53
|
return () => {
|
|
52
54
|
n && n();
|
|
53
55
|
};
|
|
54
56
|
}, [e?.subscribeOpenChange]);
|
|
55
|
-
const G =
|
|
57
|
+
const G = P !== void 0 ? P : O;
|
|
56
58
|
m(() => {
|
|
57
|
-
if (!
|
|
58
|
-
if (!
|
|
59
|
-
|
|
59
|
+
if (!V && U.current && C === "fetch_on_type") {
|
|
60
|
+
if (!d || d === "" || d.length < L) {
|
|
61
|
+
g.current && clearTimeout(g.current), l(!1);
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
|
-
const t = B(q,
|
|
63
|
-
|
|
64
|
+
const t = B(q, R);
|
|
65
|
+
l(!0), t.then((n) => {
|
|
64
66
|
const o = $(n);
|
|
65
|
-
|
|
67
|
+
_(o);
|
|
66
68
|
}).finally(() => {
|
|
67
|
-
|
|
69
|
+
l(!1), e?.onFetchingEnd?.();
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
|
-
}, [
|
|
71
|
-
if (!
|
|
72
|
+
}, [C, d, V, R, B, L]), m(() => {
|
|
73
|
+
if (!V)
|
|
72
74
|
if (G) {
|
|
73
|
-
if (e?.onOpen?.(),
|
|
74
|
-
if (!
|
|
75
|
+
if (e?.onOpen?.(), C === "fetch_in_open") {
|
|
76
|
+
if (!U.current)
|
|
75
77
|
return;
|
|
76
|
-
|
|
78
|
+
l(!0), q().then((t) => {
|
|
77
79
|
const n = $(t);
|
|
78
|
-
|
|
80
|
+
_(() => {
|
|
79
81
|
const o = n.filter((r) => {
|
|
80
82
|
if (s)
|
|
81
83
|
return i(r, s) !== void 0;
|
|
82
84
|
});
|
|
83
|
-
return
|
|
85
|
+
return F && f.length > 0 ? [...K(f, o), ...f] : o;
|
|
84
86
|
});
|
|
85
87
|
}).finally(() => {
|
|
86
|
-
|
|
88
|
+
l(!1), e?.onFetchingEnd?.();
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
91
|
} else
|
|
90
92
|
e?.onClose?.();
|
|
91
|
-
}, [G,
|
|
93
|
+
}, [G, C, V]);
|
|
92
94
|
const H = (t, n) => t?.filter((o) => {
|
|
93
|
-
if (
|
|
94
|
-
return i(o,
|
|
95
|
+
if (h)
|
|
96
|
+
return i(o, h)?.toLowerCase().includes(n.toLowerCase());
|
|
95
97
|
{
|
|
96
98
|
const r = o;
|
|
97
99
|
switch (typeof r) {
|
|
@@ -100,24 +102,24 @@ function re(e) {
|
|
|
100
102
|
case "number":
|
|
101
103
|
return r.toString().includes(n);
|
|
102
104
|
case "object":
|
|
103
|
-
return Object.values(r).some((
|
|
105
|
+
return Object.values(r).some((T) => T.toString()?.toLowerCase().includes(n.toLowerCase()));
|
|
104
106
|
default:
|
|
105
107
|
return !1;
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
}) || [], ne = (t) => t?.sort((n, o) => {
|
|
109
|
-
if (
|
|
110
|
-
return i(n,
|
|
111
|
+
if (h)
|
|
112
|
+
return i(n, h) < i(o, h) ? -1 : 1;
|
|
111
113
|
{
|
|
112
|
-
const
|
|
113
|
-
switch (typeof
|
|
114
|
+
const a = ["label", "name", "value"].find((W) => typeof n == "object" && Object.keys(n).includes(W)), T = n, I = o;
|
|
115
|
+
switch (typeof T) {
|
|
114
116
|
case "string":
|
|
115
|
-
return
|
|
117
|
+
return T < I ? -1 : 1;
|
|
116
118
|
case "number":
|
|
117
|
-
return
|
|
119
|
+
return T < I ? -1 : 1;
|
|
118
120
|
case "object":
|
|
119
|
-
if (
|
|
120
|
-
const W = i(n,
|
|
121
|
+
if (a) {
|
|
122
|
+
const W = i(n, a), oe = i(o, a);
|
|
121
123
|
return W < oe ? -1 : 1;
|
|
122
124
|
} else
|
|
123
125
|
return 1;
|
|
@@ -126,82 +128,87 @@ function re(e) {
|
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
}) || [], Q = (t) => {
|
|
129
|
-
const n = typeof
|
|
131
|
+
const n = typeof x == "function" ? x() : x;
|
|
130
132
|
t.target === n?.current && (N.current && clearTimeout(N.current), z.current || (z.current = !0, e?.onTypeStart?.()), N.current = setTimeout(() => {
|
|
131
133
|
z.current = !1;
|
|
132
|
-
},
|
|
134
|
+
}, R));
|
|
133
135
|
};
|
|
134
136
|
return m(() => {
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
else if (
|
|
138
|
-
const t = K(
|
|
139
|
-
|
|
137
|
+
if (d === "")
|
|
138
|
+
y(ne(v));
|
|
139
|
+
else if (F) {
|
|
140
|
+
const t = K(f, v);
|
|
141
|
+
y([...H(t, d), ...f]);
|
|
140
142
|
} else {
|
|
141
|
-
const t = K([
|
|
142
|
-
|
|
143
|
+
const t = K([f], v);
|
|
144
|
+
y([...H(t, d), f]);
|
|
143
145
|
}
|
|
144
|
-
}, [
|
|
146
|
+
}, [v]), m(() => (document.addEventListener("keydown", Q), () => {
|
|
145
147
|
document.removeEventListener("keydown", Q);
|
|
146
148
|
}), []), {
|
|
147
|
-
inputValue:
|
|
148
|
-
setInputValue:
|
|
149
|
+
inputValue: d,
|
|
150
|
+
setInputValue: E,
|
|
149
151
|
cleanInputValue: () => {
|
|
150
|
-
|
|
152
|
+
E("");
|
|
153
|
+
},
|
|
154
|
+
cleanOptions: () => {
|
|
155
|
+
_(f);
|
|
151
156
|
},
|
|
152
|
-
filteredOptions:
|
|
153
|
-
isLoading:
|
|
154
|
-
value:
|
|
155
|
-
setValue:
|
|
157
|
+
filteredOptions: D,
|
|
158
|
+
isLoading: J,
|
|
159
|
+
value: f,
|
|
160
|
+
setValue: M,
|
|
156
161
|
onOptionClick: te
|
|
157
162
|
};
|
|
158
163
|
}
|
|
159
|
-
const
|
|
160
|
-
const
|
|
164
|
+
const de = (e) => {
|
|
165
|
+
const p = j(null);
|
|
161
166
|
m(() => {
|
|
162
|
-
e.controls && (e.controls.current =
|
|
167
|
+
e.controls && (e.controls.current = p.current);
|
|
163
168
|
}, [e.controls]);
|
|
164
|
-
const { asyncMode:
|
|
165
|
-
const
|
|
169
|
+
const { asyncMode: u = "fetch_in_open" } = e, C = (l, O, b) => {
|
|
170
|
+
const g = {
|
|
166
171
|
options: l.options,
|
|
167
172
|
fetcher: l.fetcher,
|
|
168
|
-
asyncMode:
|
|
173
|
+
asyncMode: O,
|
|
169
174
|
debounceDelay: l.debounceDelay,
|
|
170
175
|
minCharacters: l.minCharacters,
|
|
171
176
|
disabled: l.disabled,
|
|
172
177
|
optionValue: l.optionValue,
|
|
173
178
|
optionLabel: l.optionLabel,
|
|
174
179
|
onFetchingStart: () => {
|
|
175
|
-
|
|
180
|
+
O === "fetch_on_type" && b.current?.open();
|
|
176
181
|
},
|
|
177
182
|
onTypeStart: () => {
|
|
178
|
-
!l?.fetcher &&
|
|
183
|
+
!l?.fetcher && b.current?.open();
|
|
179
184
|
},
|
|
180
|
-
inputRef: () =>
|
|
181
|
-
subscribeOpenChange:
|
|
185
|
+
inputRef: () => b.current?.searchInputRef,
|
|
186
|
+
subscribeOpenChange: b.current?.subscribeOpenChange,
|
|
182
187
|
name: l.name
|
|
183
188
|
};
|
|
184
189
|
return l.multiple ? {
|
|
185
|
-
...
|
|
190
|
+
...g,
|
|
186
191
|
multiple: !0,
|
|
187
192
|
controlledValue: l.value,
|
|
188
193
|
onChange: l.onChange
|
|
189
194
|
} : {
|
|
190
|
-
...
|
|
195
|
+
...g,
|
|
191
196
|
multiple: !1,
|
|
192
197
|
controlledValue: l.value,
|
|
193
198
|
onChange: l.onChange
|
|
194
199
|
};
|
|
195
|
-
}, { inputValue:
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
}, { displayMode:
|
|
199
|
-
controledSearchValue:
|
|
200
|
-
onSearchValueChange:
|
|
201
|
-
onSearchClear:
|
|
200
|
+
}, { inputValue: V, setInputValue: R, filteredOptions: L, isLoading: h, value: s, onOptionClick: c, cleanInputValue: P, cleanOptions: x } = le(C(e, u, p)), S = ee(() => u === "fetch_on_type" ? h : !1, [u, h]), A = Z(() => e.multiple ? s.map((l) => i(l, e.optionValue)) : s ? i(s, e.optionValue) : void 0, [s, e.optionValue, e.multiple]), v = (l) => {
|
|
201
|
+
const O = L.find((b) => i(b, e.optionValue) === l.id);
|
|
202
|
+
O && c(O);
|
|
203
|
+
}, { displayMode: _ = e.multiple ? "chips" : "compact", dropdownOptions: D, overflow: y = "scroll", onChange: d, ...E } = e.selectComponentProps || {}, J = {
|
|
204
|
+
controledSearchValue: V,
|
|
205
|
+
onSearchValueChange: u === "fetch_on_type" ? R : void 0,
|
|
206
|
+
onSearchClear: u === "fetch_on_type" ? () => {
|
|
207
|
+
P(), x();
|
|
208
|
+
} : void 0,
|
|
202
209
|
inputSearchPlaceholder: e.inputSearchPlaceholder,
|
|
203
|
-
isLoading:
|
|
204
|
-
...
|
|
210
|
+
isLoading: S(),
|
|
211
|
+
...D || {}
|
|
205
212
|
};
|
|
206
213
|
return e.multiple ? /* @__PURE__ */ X.jsx(
|
|
207
214
|
Y,
|
|
@@ -209,46 +216,46 @@ const ae = (e) => {
|
|
|
209
216
|
disabled: e.disabled,
|
|
210
217
|
className: e.className,
|
|
211
218
|
name: e.name,
|
|
212
|
-
overflow:
|
|
213
|
-
...
|
|
219
|
+
overflow: y,
|
|
220
|
+
...E,
|
|
214
221
|
multiple: !0,
|
|
215
|
-
value:
|
|
222
|
+
value: A,
|
|
216
223
|
label: e.label || "",
|
|
217
|
-
options:
|
|
224
|
+
options: L,
|
|
218
225
|
optionValue: e.optionValue,
|
|
219
226
|
optionLabel: e.optionLabel,
|
|
220
227
|
renderOption: e.renderOption,
|
|
221
|
-
onOptionClick:
|
|
222
|
-
displayMode:
|
|
223
|
-
controls:
|
|
228
|
+
onOptionClick: v,
|
|
229
|
+
displayMode: _,
|
|
230
|
+
controls: p,
|
|
224
231
|
emptyMessage: "Use el buscador para obtener las opciones disponibles",
|
|
225
|
-
dropdownOptions:
|
|
226
|
-
isLoading:
|
|
232
|
+
dropdownOptions: J,
|
|
233
|
+
isLoading: u === "fetch_in_open" ? h : !1
|
|
227
234
|
}
|
|
228
235
|
) : /* @__PURE__ */ X.jsx(
|
|
229
236
|
Y,
|
|
230
237
|
{
|
|
231
238
|
disabled: e.disabled,
|
|
232
|
-
...
|
|
239
|
+
...E,
|
|
233
240
|
className: e.className,
|
|
234
|
-
overflow:
|
|
241
|
+
overflow: y,
|
|
235
242
|
name: e.name,
|
|
236
243
|
multiple: !1,
|
|
237
|
-
value:
|
|
244
|
+
value: A,
|
|
238
245
|
label: e.label || "",
|
|
239
|
-
options:
|
|
246
|
+
options: L,
|
|
240
247
|
optionValue: e.optionValue,
|
|
241
248
|
optionLabel: e.optionLabel,
|
|
242
249
|
renderOption: e.renderOption,
|
|
243
|
-
onOptionClick:
|
|
250
|
+
onOptionClick: v,
|
|
244
251
|
displayMode: "compact",
|
|
245
|
-
controls:
|
|
252
|
+
controls: p,
|
|
246
253
|
emptyMessage: "Use el buscador para obtener las opciones disponibles",
|
|
247
|
-
dropdownOptions:
|
|
248
|
-
isLoading:
|
|
254
|
+
dropdownOptions: J,
|
|
255
|
+
isLoading: u === "fetch_in_open" ? h : !1
|
|
249
256
|
}
|
|
250
257
|
);
|
|
251
258
|
};
|
|
252
259
|
export {
|
|
253
|
-
|
|
260
|
+
de as default
|
|
254
261
|
};
|
|
@@ -33,6 +33,7 @@ export declare function useAutocomplete<T extends object>(options?: UseAutocompl
|
|
|
33
33
|
inputValue: string;
|
|
34
34
|
setInputValue: import('react').Dispatch<import('react').SetStateAction<string>>;
|
|
35
35
|
cleanInputValue: () => void;
|
|
36
|
+
cleanOptions: () => void;
|
|
36
37
|
filteredOptions: T[];
|
|
37
38
|
isLoading: boolean;
|
|
38
39
|
value: T | T[] | undefined;
|