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.
@@ -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 w, useRef as T, useEffect as m, useMemo as Z, useCallback as ee } from "react";
4
- function re(e) {
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: y,
7
- fetcher: a,
8
- asyncMode: p = "fetch_in_open",
9
- disabled: O = !1,
10
- debounceDelay: I = 500,
11
- minCharacters: C = 3,
12
- optionLabel: f,
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: b,
15
- isOpen: F,
16
- inputRef: k,
17
- name: v
18
- } = e || {}, j = y ? y.filter((t) => t != null) : [], [V, R] = w(j || []), [M, x] = w(j || []), [c, A] = w(""), [l, d] = w(!1), [g, P] = w(!1), E = T(null), N = T(null), z = T(!1), J = T(a), U = e?.multiple === !0 || !1, L = T(U ? [] : void 0), [h, D] = w(U ? [] : void 0);
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
- J.current = a;
21
- }, [a]), m(() => {
22
- if (b !== void 0) {
23
- const t = $(b, "value");
24
- D(t);
25
- }
26
- }, [b]), m(() => {
27
- L.current = b !== void 0 ? b : h;
28
- }, [b, h]), m(() => {
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
- R(t), x(t);
33
+ _(t), y(t);
32
34
  }
33
35
  }, [e?.options]);
34
36
  const B = Z(() => (t, n) => new Promise((o, r) => {
35
- E.current && clearTimeout(E.current), E.current = setTimeout(() => t(c).then(o).catch(r), n);
36
- }), [c]), te = (t) => {
37
- const n = b !== void 0, o = (r) => s ? i(r, s) : i(r, "id");
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 = L.current || [];
40
- let u;
41
- r.some((_) => o(_) === o(t)) ? u = r.filter((_) => o(_) !== o(t)) : u = [...r, t], n ? (L.current = u, e?.onChange?.(u, v)) : (L.current = u, D(u), e?.onChange?.(u, v));
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 ? (L.current = t, e?.onChange?.(t, v)) : (L.current = t, D(t), e?.onChange?.(t, v));
44
- }, q = (t) => (e?.onFetchingStart?.(), J.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
+ 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
- P(o);
51
+ b(o);
50
52
  });
51
53
  return () => {
52
54
  n && n();
53
55
  };
54
56
  }, [e?.subscribeOpenChange]);
55
- const G = F !== void 0 ? F : g;
57
+ const G = P !== void 0 ? P : O;
56
58
  m(() => {
57
- if (!O && J.current && p === "fetch_on_type") {
58
- if (!c || c === "" || c.length < C) {
59
- E.current && clearTimeout(E.current), d(!1);
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, I);
63
- d(!0), t.then((n) => {
64
+ const t = B(q, R);
65
+ l(!0), t.then((n) => {
64
66
  const o = $(n);
65
- R(o);
67
+ _(o);
66
68
  }).finally(() => {
67
- d(!1), e?.onFetchingEnd?.();
69
+ l(!1), e?.onFetchingEnd?.();
68
70
  });
69
71
  }
70
- }, [p, c, O, I, B, C]), m(() => {
71
- if (!O)
72
+ }, [C, d, V, R, B, L]), m(() => {
73
+ if (!V)
72
74
  if (G) {
73
- if (e?.onOpen?.(), p === "fetch_in_open") {
74
- if (!J.current)
75
+ if (e?.onOpen?.(), C === "fetch_in_open") {
76
+ if (!U.current)
75
77
  return;
76
- d(!0), q().then((t) => {
78
+ l(!0), q().then((t) => {
77
79
  const n = $(t);
78
- R(() => {
80
+ _(() => {
79
81
  const o = n.filter((r) => {
80
82
  if (s)
81
83
  return i(r, s) !== void 0;
82
84
  });
83
- return U && h.length > 0 ? [...K(h, o), ...h] : o;
85
+ return F && f.length > 0 ? [...K(f, o), ...f] : o;
84
86
  });
85
87
  }).finally(() => {
86
- d(!1), e?.onFetchingEnd?.();
88
+ l(!1), e?.onFetchingEnd?.();
87
89
  });
88
90
  }
89
91
  } else
90
92
  e?.onClose?.();
91
- }, [G, p, O]);
93
+ }, [G, C, V]);
92
94
  const H = (t, n) => t?.filter((o) => {
93
- if (f)
94
- return i(o, f)?.toLowerCase().includes(n.toLowerCase());
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((S) => S.toString()?.toLowerCase().includes(n.toLowerCase()));
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 (f)
110
- return i(n, f) < i(o, f) ? -1 : 1;
111
+ if (h)
112
+ return i(n, h) < i(o, h) ? -1 : 1;
111
113
  {
112
- const u = ["label", "name", "value"].find((W) => typeof n == "object" && Object.keys(n).includes(W)), S = n, _ = o;
113
- switch (typeof S) {
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 S < _ ? -1 : 1;
117
+ return T < I ? -1 : 1;
116
118
  case "number":
117
- return S < _ ? -1 : 1;
119
+ return T < I ? -1 : 1;
118
120
  case "object":
119
- if (u) {
120
- const W = i(n, u), oe = i(o, u);
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 k == "function" ? k() : k;
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
- }, I));
134
+ }, R));
133
135
  };
134
136
  return m(() => {
135
- if (c === "")
136
- x(ne(V));
137
- else if (U) {
138
- const t = K(h, V);
139
- x([...H(t, c), ...h]);
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([h], V);
142
- x([...H(t, c), h]);
143
+ const t = K([f], v);
144
+ y([...H(t, d), f]);
143
145
  }
144
- }, [V]), m(() => (document.addEventListener("keydown", Q), () => {
146
+ }, [v]), m(() => (document.addEventListener("keydown", Q), () => {
145
147
  document.removeEventListener("keydown", Q);
146
148
  }), []), {
147
- inputValue: c,
148
- setInputValue: A,
149
+ inputValue: d,
150
+ setInputValue: E,
149
151
  cleanInputValue: () => {
150
- A("");
152
+ E("");
153
+ },
154
+ cleanOptions: () => {
155
+ _(f);
151
156
  },
152
- filteredOptions: M,
153
- isLoading: l,
154
- value: h,
155
- setValue: D,
157
+ filteredOptions: D,
158
+ isLoading: J,
159
+ value: f,
160
+ setValue: M,
156
161
  onOptionClick: te
157
162
  };
158
163
  }
159
- const ae = (e) => {
160
- const y = T(null);
164
+ const de = (e) => {
165
+ const p = j(null);
161
166
  m(() => {
162
- e.controls && (e.controls.current = y.current);
167
+ e.controls && (e.controls.current = p.current);
163
168
  }, [e.controls]);
164
- const { asyncMode: a = "fetch_in_open" } = e, p = (l, d, g) => {
165
- const P = {
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: d,
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
- d === "fetch_on_type" && g.current?.open();
180
+ O === "fetch_on_type" && b.current?.open();
176
181
  },
177
182
  onTypeStart: () => {
178
- !l?.fetcher && g.current?.open();
183
+ !l?.fetcher && b.current?.open();
179
184
  },
180
- inputRef: () => g.current?.searchInputRef,
181
- subscribeOpenChange: g.current?.subscribeOpenChange,
185
+ inputRef: () => b.current?.searchInputRef,
186
+ subscribeOpenChange: b.current?.subscribeOpenChange,
182
187
  name: l.name
183
188
  };
184
189
  return l.multiple ? {
185
- ...P,
190
+ ...g,
186
191
  multiple: !0,
187
192
  controlledValue: l.value,
188
193
  onChange: l.onChange
189
194
  } : {
190
- ...P,
195
+ ...g,
191
196
  multiple: !1,
192
197
  controlledValue: l.value,
193
198
  onChange: l.onChange
194
199
  };
195
- }, { inputValue: O, setInputValue: I, filteredOptions: C, isLoading: f, value: s, onOptionClick: b, cleanInputValue: F } = re(p(e, a, y)), k = ee(() => a === "fetch_on_type" ? f : !1, [a, f]), v = Z(() => e.multiple ? s.map((l) => i(l, e.optionValue)) : s ? i(s, e.optionValue) : void 0, [s, e.optionValue, e.multiple]), j = (l) => {
196
- const d = C.find((g) => i(g, e.optionValue) === l.id);
197
- d && b(d);
198
- }, { displayMode: V = e.multiple ? "chips" : "compact", dropdownOptions: R, overflow: M = "scroll", onChange: x, ...c } = e.selectComponentProps || {}, A = {
199
- controledSearchValue: O,
200
- onSearchValueChange: a === "fetch_on_type" ? I : void 0,
201
- onSearchClear: a === "fetch_on_type" ? F : void 0,
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: k(),
204
- ...R || {}
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: M,
213
- ...c,
219
+ overflow: y,
220
+ ...E,
214
221
  multiple: !0,
215
- value: v,
222
+ value: A,
216
223
  label: e.label || "",
217
- options: C,
224
+ options: L,
218
225
  optionValue: e.optionValue,
219
226
  optionLabel: e.optionLabel,
220
227
  renderOption: e.renderOption,
221
- onOptionClick: j,
222
- displayMode: V,
223
- controls: y,
228
+ onOptionClick: v,
229
+ displayMode: _,
230
+ controls: p,
224
231
  emptyMessage: "Use el buscador para obtener las opciones disponibles",
225
- dropdownOptions: A,
226
- isLoading: a === "fetch_in_open" ? f : !1
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
- ...c,
239
+ ...E,
233
240
  className: e.className,
234
- overflow: M,
241
+ overflow: y,
235
242
  name: e.name,
236
243
  multiple: !1,
237
- value: v,
244
+ value: A,
238
245
  label: e.label || "",
239
- options: C,
246
+ options: L,
240
247
  optionValue: e.optionValue,
241
248
  optionLabel: e.optionLabel,
242
249
  renderOption: e.renderOption,
243
- onOptionClick: j,
250
+ onOptionClick: v,
244
251
  displayMode: "compact",
245
- controls: y,
252
+ controls: p,
246
253
  emptyMessage: "Use el buscador para obtener las opciones disponibles",
247
- dropdownOptions: A,
248
- isLoading: a === "fetch_in_open" ? f : !1
254
+ dropdownOptions: J,
255
+ isLoading: u === "fetch_in_open" ? h : !1
249
256
  }
250
257
  );
251
258
  };
252
259
  export {
253
- ae as default
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prometeo-design-system",
3
3
  "private": false,
4
- "version": "3.1.0",
4
+ "version": "3.1.1",
5
5
  "type": "module",
6
6
  "description": "design kit system",
7
7
  "main": "dist/prometeo-design-system.umd.js",