@kapiuara/ui 0.4.0 → 0.6.0

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.
Files changed (44) hide show
  1. package/README.md +54 -1
  2. package/dist/components/chat/KapiChatDivider.d.ts +15 -0
  3. package/dist/components/chat/KapiChatDivider.js +17 -0
  4. package/dist/components/chat/KapiChatList.d.ts +57 -0
  5. package/dist/components/chat/KapiChatList.js +71 -0
  6. package/dist/components/chat/KapiChatThread.d.ts +35 -0
  7. package/dist/components/chat/KapiChatThread.js +85 -0
  8. package/dist/components/chat/KapiComposer.d.ts +60 -0
  9. package/dist/components/chat/KapiComposer.js +89 -0
  10. package/dist/components/chat/KapiMessageBubble.d.ts +43 -0
  11. package/dist/components/chat/KapiMessageBubble.js +67 -0
  12. package/dist/components/chat/KapiTypingIndicator.d.ts +27 -0
  13. package/dist/components/chat/KapiTypingIndicator.js +34 -0
  14. package/dist/components/chat/chatLogic.d.ts +76 -0
  15. package/dist/components/chat/chatLogic.js +34 -0
  16. package/dist/components/chat/index.d.ts +14 -0
  17. package/dist/components/display/KapiCommentComposer.d.ts +4 -0
  18. package/dist/components/display/KapiCommentComposer.js +43 -46
  19. package/dist/components/display/commentLogic.d.ts +9 -2
  20. package/dist/components/display/commentLogic.js +1 -1
  21. package/dist/components/display/index.d.ts +1 -0
  22. package/dist/components/inputs/KapiFacetedSearch.d.ts +14 -1
  23. package/dist/components/inputs/KapiFacetedSearch.js +172 -110
  24. package/dist/components/inputs/KapiSelect.d.ts +7 -0
  25. package/dist/components/inputs/KapiSelect.js +233 -229
  26. package/dist/components/inputs/facetedSearchLogic.d.ts +12 -2
  27. package/dist/components/inputs/facetedSearchLogic.js +10 -7
  28. package/dist/components/layout/KapiPanelParts.js +9 -9
  29. package/dist/components/layout/KapiRail.js +8 -8
  30. package/dist/components/locale/labelRegistry.d.ts +10 -0
  31. package/dist/components/navigation/KapiContextPanel.js +86 -86
  32. package/dist/components/navigation/KapiPanelGroup.js +18 -18
  33. package/dist/components/navigation/KapiTabs.js +1 -1
  34. package/dist/components/navigation/MiniNavItem.js +1 -1
  35. package/dist/hooks/dateFormat.d.ts +7 -0
  36. package/dist/hooks/dateFormat.js +16 -2
  37. package/dist/hooks/index.d.ts +1 -1
  38. package/dist/hooks/useSubmitDraft.d.ts +34 -0
  39. package/dist/hooks/useSubmitDraft.js +28 -0
  40. package/dist/index.d.ts +1 -0
  41. package/dist/index.js +83 -76
  42. package/dist/kapi.css +1 -1
  43. package/dist/kapi.layered.css +1 -1
  44. package/package.json +1 -1
@@ -1,17 +1,18 @@
1
1
  "use client";
2
2
  import { useLabels as e } from "../locale/KapiLocaleProvider.js";
3
- import { joinClasses as t } from "../rootProps.js";
4
- import { KapiDatePicker as n } from "./KapiDatePicker.js";
5
- import { KapiDateRangePicker as r } from "./KapiDateRangePicker.js";
6
- import { KapiTag as i } from "../display/KapiTag.js";
7
- import { KapiPopover as a } from "../overlays/KapiPopover.js";
8
- import { facetKeyAction as o, facetMenuItems as s, facetOptionName as c, isDateFacet as l, moveActive as u, toDateRangeValue as d, toDateValue as f } from "./facetedSearchLogic.js";
3
+ import { createLoadSequencer as t } from "./asyncSelectLogic.js";
4
+ import { joinClasses as n } from "../rootProps.js";
5
+ import { KapiDatePicker as r } from "./KapiDatePicker.js";
6
+ import { KapiDateRangePicker as i } from "./KapiDateRangePicker.js";
7
+ import { KapiTag as a } from "../display/KapiTag.js";
8
+ import { KapiPopover as o } from "../overlays/KapiPopover.js";
9
+ import { facetKeyAction as ee, facetMenuItems as te, facetOptionName as ne, isDateFacet as s, moveActive as re, toDateRangeValue as c, toDateValue as l } from "./facetedSearchLogic.js";
9
10
  /* empty css */
10
- import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
11
- import { useId as g, useRef as _, useState as v } from "react";
12
- import { Search as y } from "lucide-react";
11
+ import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
12
+ import { useEffect as p, useId as m, useRef as h, useState as g } from "react";
13
+ import { Search as ie } from "lucide-react";
13
14
  //#region src/components/inputs/KapiFacetedSearch.tsx
14
- var b = {
15
+ var _ = {
15
16
  input: "Buscar o filtrar",
16
17
  region: "Búsqueda",
17
18
  placeholder: "Buscar o filtrar…",
@@ -20,171 +21,232 @@ var b = {
20
21
  empty: "Sin opciones",
21
22
  remove: "Quitar",
22
23
  valueOf: "Valor de",
23
- clearAll: "Limpiar todo"
24
+ clearAll: "Limpiar todo",
25
+ loading: "Buscando…",
26
+ loadError: "No se pudieron cargar los valores"
24
27
  };
25
- function x({ facets: x, chips: S, onText: C, onClearAll: w, labels: T, className: E, onMouseDown: D, "aria-label": O, ...k }) {
26
- let A = e("facetedSearch", b, T), j = g(), M = `${j}-list`, N = _(null), P = _(null), F = _(null), [I, L] = v(""), [R, z] = v(null), [B, V] = v(!1), [H, U] = v(-1), W = s(x, R, I), G = l(R), K = B && !G, q = () => requestAnimationFrame(() => P.current?.focus()), J = () => {
27
- L(""), z(null), U(-1);
28
- }, Y = () => {
29
- J(), V(!1), q();
30
- }, X = (e) => {
31
- e.type === "text" ? (C(e.text), Y()) : e.type === "option" ? (R?.apply(e.option.value), Y()) : e.facet.kind === "flag" ? (e.facet.apply("true"), Y()) : (z(e.facet), L(""), U(-1), V(!0), l(e.facet) ? requestAnimationFrame(() => F.current?.focus()) : q());
32
- }, Z = (e) => {
33
- let t = o(e.key, {
34
- input: I,
35
- pending: !!R,
36
- active: H,
37
- open: K,
38
- chips: S.length
28
+ function v({ facets: v, chips: y, onText: b, onClearAll: x, loadDelay: S = 300, reloadKey: C, labels: ae, className: oe, onMouseDown: se, "aria-label": ce, ...le }) {
29
+ let w = e("facetedSearch", _, ae), T = m(), E = `${T}-list`, D = h(null), O = h(null), k = h(null), [A, j] = g(""), [M, N] = g(null), [ue, P] = g(!1), [F, I] = g(-1), [L, R] = g(null), [z] = g(t), B = h(C);
30
+ p(() => {
31
+ Object.is(B.current, C) || (B.current = C, z.cancel(), R(null));
32
+ }, [C, z]);
33
+ let V = A.trim(), H = typeof M?.loadOptions == "function", U = H && L?.key === M?.key && L?.query === V ? L : null, W = H && !U, G = te(v, M, A, U && !U.error ? U.options : void 0), K = s(M), q = ue && !K, J = h(M?.loadOptions);
34
+ p(() => {
35
+ J.current = M?.loadOptions;
36
+ }), p(() => {
37
+ if (!H || !q || U) return;
38
+ let e = M?.key ?? "", t = setTimeout(() => {
39
+ let t = J.current;
40
+ if (!t) return;
41
+ let n = z.start(), r;
42
+ try {
43
+ r = t(V, { signal: n.signal });
44
+ } catch (e) {
45
+ r = Promise.reject(e);
46
+ }
47
+ r.then((t) => {
48
+ n.isCurrent() && (R({
49
+ key: e,
50
+ query: V,
51
+ options: t,
52
+ error: !1
53
+ }), I(-1));
54
+ }, () => {
55
+ n.isCurrent() && R({
56
+ key: e,
57
+ query: V,
58
+ options: [],
59
+ error: !0
60
+ });
61
+ });
62
+ }, S);
63
+ return () => clearTimeout(t);
64
+ }, [
65
+ H,
66
+ q,
67
+ U,
68
+ V,
69
+ S,
70
+ M?.key,
71
+ z
72
+ ]), p(() => ((!q || !M) && (z.cancel(), R((e) => e?.error ? null : e)), () => z.cancel()), [
73
+ q,
74
+ M,
75
+ z
76
+ ]);
77
+ let Y = () => requestAnimationFrame(() => O.current?.focus()), X = () => {
78
+ j(""), N(null), I(-1);
79
+ }, Z = () => {
80
+ X(), P(!1), Y();
81
+ }, Q = (e) => {
82
+ e.type === "text" ? (b(e.text), Z()) : e.type === "option" ? (M?.apply(e.option.value), Z()) : e.facet.kind === "flag" ? (e.facet.apply("true"), Z()) : (N(e.facet), j(""), I(-1), P(!0), s(e.facet) ? requestAnimationFrame(() => k.current?.focus()) : Y());
83
+ }, de = (e) => {
84
+ let t = ee(e.key, {
85
+ input: A,
86
+ pending: !!M,
87
+ active: F,
88
+ open: q,
89
+ chips: y.length
39
90
  });
40
91
  if (t) switch (e.preventDefault(), t) {
41
92
  case "next":
42
93
  case "prev":
43
- V(!0), U((e) => u(K ? e : -1, W.length, t === "next" ? 1 : -1));
94
+ P(!0), I((e) => re(q ? e : -1, G.length, t === "next" ? 1 : -1));
44
95
  break;
45
96
  case "select": {
46
- let e = W[H];
47
- e && X(e);
97
+ let e = G[F];
98
+ e && Q(e);
48
99
  break;
49
100
  }
50
101
  case "text":
51
- C(I.trim()), Y();
102
+ b(A.trim()), Z();
52
103
  break;
53
104
  case "cancel":
54
- J();
105
+ X();
55
106
  break;
56
107
  case "close":
57
- V(!1), U(-1);
108
+ P(!1), I(-1);
58
109
  break;
59
110
  case "dropPending":
60
- z(null), U(-1);
111
+ N(null), I(-1);
61
112
  break;
62
- case "removeLast": S[S.length - 1]?.onRemove();
113
+ case "removeLast": y[y.length - 1]?.onRemove();
63
114
  }
64
- }, Q = (e) => {
115
+ }, fe = (e) => {
65
116
  let t = e.target.value === "";
66
- (e.key === "Escape" || e.key === "Backspace" && t) && (e.preventDefault(), J(), q());
67
- }, $ = (e) => `${j}-opt-${e}`;
68
- return /* @__PURE__ */ h("div", {
69
- ...k,
70
- ref: N,
71
- className: t("kapi-facets", E),
117
+ (e.key === "Escape" || e.key === "Backspace" && t) && (e.preventDefault(), X(), Y());
118
+ }, $ = (e) => `${T}-opt-${e}`;
119
+ return /* @__PURE__ */ f("div", {
120
+ ...le,
121
+ ref: D,
122
+ className: n("kapi-facets", oe),
72
123
  role: "search",
73
- "aria-label": O ?? A.region,
124
+ "aria-label": ce ?? w.region,
74
125
  onMouseDown: (e) => {
75
- D?.(e), !e.defaultPrevented && e.target === e.currentTarget && (e.preventDefault(), P.current?.focus(), V(!0));
126
+ se?.(e), !e.defaultPrevented && e.target === e.currentTarget && (e.preventDefault(), O.current?.focus(), P(!0));
76
127
  },
77
128
  children: [
78
- /* @__PURE__ */ m(y, {
129
+ /* @__PURE__ */ d(ie, {
79
130
  className: "kapi-facets__icon",
80
131
  size: 15,
81
132
  "aria-hidden": !0
82
133
  }),
83
- S.map((e) => /* @__PURE__ */ m(i, {
134
+ y.map((e) => /* @__PURE__ */ d(a, {
84
135
  size: "sm",
85
136
  onRemove: () => {
86
- e.onRemove(), q();
137
+ e.onRemove(), Y();
87
138
  },
88
- removeLabel: `${A.remove} ${e.label}`,
139
+ removeLabel: `${w.remove} ${e.label}`,
89
140
  children: e.label
90
141
  }, e.key)),
91
- R && /* @__PURE__ */ h(i, {
142
+ M && /* @__PURE__ */ f(a, {
92
143
  size: "sm",
93
144
  tone: "primary",
94
145
  className: "kapi-facets__pending",
95
- children: [R.label, ":"]
146
+ children: [M.label, ":"]
96
147
  }),
97
- G && R ? /* @__PURE__ */ m("span", {
148
+ K && M ? /* @__PURE__ */ d("span", {
98
149
  className: "kapi-facets__date",
99
- onKeyDown: Q,
100
- children: R.kind === "dateRange" ? /* @__PURE__ */ m(r, {
101
- ref: F,
102
- "aria-label": `${A.valueOf} ${R.label}`,
150
+ onKeyDown: fe,
151
+ children: M.kind === "dateRange" ? /* @__PURE__ */ d(i, {
152
+ ref: k,
153
+ "aria-label": `${w.valueOf} ${M.label}`,
103
154
  onChange: ({ from: e, to: t }) => {
104
- e && t && (R.apply(d(e, t)), Y());
155
+ e && t && (M.apply(c(e, t)), Z());
105
156
  }
106
- }) : /* @__PURE__ */ m(n, {
107
- ref: F,
108
- "aria-label": `${A.valueOf} ${R.label}`,
157
+ }) : /* @__PURE__ */ d(r, {
158
+ ref: k,
159
+ "aria-label": `${w.valueOf} ${M.label}`,
109
160
  onChange: (e) => {
110
- e && (R.apply(f(e)), Y());
161
+ e && (M.apply(l(e)), Z());
111
162
  }
112
163
  })
113
- }) : /* @__PURE__ */ m("input", {
114
- ref: P,
164
+ }) : /* @__PURE__ */ d("input", {
165
+ ref: O,
115
166
  className: "kapi-facets__input",
116
167
  type: "text",
117
168
  role: "combobox",
118
169
  autoComplete: "off",
119
- "aria-label": A.input,
120
- "aria-expanded": K,
121
- "aria-controls": M,
170
+ "aria-label": w.input,
171
+ "aria-expanded": q,
172
+ "aria-controls": E,
122
173
  "aria-autocomplete": "list",
123
- "aria-activedescendant": K && H >= 0 ? $(H) : void 0,
124
- placeholder: S.length === 0 && !R ? A.placeholder : void 0,
125
- value: I,
126
- onFocus: () => V(!0),
127
- onClick: () => V(!0),
174
+ "aria-activedescendant": q && F >= 0 ? $(F) : void 0,
175
+ placeholder: y.length === 0 && !M ? w.placeholder : void 0,
176
+ value: A,
177
+ onFocus: () => P(!0),
178
+ onClick: () => P(!0),
128
179
  onBlur: (e) => {
129
180
  let t = e.relatedTarget;
130
- (!t || !N.current?.contains(t)) && V(!1);
181
+ (!t || !D.current?.contains(t)) && P(!1);
131
182
  },
132
183
  onChange: (e) => {
133
- L(e.target.value), V(!0), U(-1);
184
+ j(e.target.value), P(!0), I(-1);
134
185
  },
135
- onKeyDown: Z
186
+ onKeyDown: de
136
187
  }),
137
- w && S.length > 0 && /* @__PURE__ */ m("button", {
188
+ x && y.length > 0 && /* @__PURE__ */ d("button", {
138
189
  type: "button",
139
190
  className: "kapi-facets__clear",
140
191
  onClick: () => {
141
- w(), J(), q();
192
+ x(), X(), Y();
142
193
  },
143
- children: A.clearAll
194
+ children: w.clearAll
144
195
  }),
145
- /* @__PURE__ */ h(a, {
146
- open: K,
147
- anchorRef: N,
148
- onClose: () => V(!1),
196
+ /* @__PURE__ */ f(o, {
197
+ open: q,
198
+ anchorRef: D,
199
+ onClose: () => P(!1),
149
200
  matchAnchorWidth: !0,
150
201
  role: "listbox",
151
- id: M,
152
- "aria-label": R ? R.label : A.input,
202
+ id: E,
203
+ "aria-label": M ? M.label : w.input,
153
204
  closeOnEscape: !1,
154
205
  restoreFocus: !1,
155
206
  className: "kapi-facets__menu",
156
- children: [W.length === 0 && /* @__PURE__ */ m("div", {
157
- className: "kapi-facets__empty",
158
- children: A.empty
159
- }), W.map((e, t) => /* @__PURE__ */ m("div", {
160
- id: $(t),
161
- role: "option",
162
- "aria-selected": t === H,
163
- "aria-label": e.type === "option" ? c(e.option) : void 0,
164
- className: `kapi-facets__opt${t === H ? " kapi-facets__opt--active" : ""}`,
165
- onMouseDown: (e) => e.preventDefault(),
166
- onMouseEnter: () => U(t),
167
- onClick: () => X(e),
168
- children: e.type === "text" ? /* @__PURE__ */ h("span", { children: [
169
- A.searchFor,
170
- " “",
171
- e.text,
172
- "”"
173
- ] }) : e.type === "option" ? /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m("span", { children: e.option.label }), e.option.count !== void 0 && /* @__PURE__ */ m("span", {
174
- className: "kapi-facets__count",
175
- "aria-hidden": "true",
176
- children: e.option.count
177
- })] }) : /* @__PURE__ */ h("span", { children: [/* @__PURE__ */ m("span", {
178
- className: "kapi-facets__facet",
179
- children: e.facet.label
180
- }), e.facet.kind !== "flag" && /* @__PURE__ */ h("span", {
181
- className: "kapi-facets__hint",
182
- children: [" · ", A.pickValue]
183
- })] })
184
- }, e.type === "facet" ? `f-${e.facet.key}` : e.type === "option" ? `o-${e.option.value}` : "t"))]
207
+ children: [
208
+ W && /* @__PURE__ */ d("div", {
209
+ className: "kapi-facets__empty",
210
+ children: w.loading
211
+ }),
212
+ !W && U?.error && /* @__PURE__ */ d("div", {
213
+ className: "kapi-facets__empty kapi-facets__empty--err",
214
+ children: w.loadError
215
+ }),
216
+ !W && !U?.error && G.length === 0 && /* @__PURE__ */ d("div", {
217
+ className: "kapi-facets__empty",
218
+ children: w.empty
219
+ }),
220
+ !W && !U?.error && G.map((e, t) => /* @__PURE__ */ d("div", {
221
+ id: $(t),
222
+ role: "option",
223
+ "aria-selected": t === F,
224
+ "aria-label": e.type === "option" ? ne(e.option) : void 0,
225
+ className: `kapi-facets__opt${t === F ? " kapi-facets__opt--active" : ""}`,
226
+ onMouseDown: (e) => e.preventDefault(),
227
+ onMouseEnter: () => I(t),
228
+ onClick: () => Q(e),
229
+ children: e.type === "text" ? /* @__PURE__ */ f("span", { children: [
230
+ w.searchFor,
231
+ " “",
232
+ e.text,
233
+ "”"
234
+ ] }) : e.type === "option" ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("span", { children: e.option.label }), e.option.count !== void 0 && /* @__PURE__ */ d("span", {
235
+ className: "kapi-facets__count",
236
+ "aria-hidden": "true",
237
+ children: e.option.count
238
+ })] }) : /* @__PURE__ */ f("span", { children: [/* @__PURE__ */ d("span", {
239
+ className: "kapi-facets__facet",
240
+ children: e.facet.label
241
+ }), e.facet.kind !== "flag" && /* @__PURE__ */ f("span", {
242
+ className: "kapi-facets__hint",
243
+ children: [" · ", w.pickValue]
244
+ })] })
245
+ }, e.type === "facet" ? `f-${e.facet.key}` : e.type === "option" ? `o-${e.option.value}` : "t"))
246
+ ]
185
247
  })
186
248
  ]
187
249
  });
188
250
  }
189
251
  //#endregion
190
- export { b as DEFAULT_FACETED_SEARCH_LABELS, x as KapiFacetedSearch };
252
+ export { _ as DEFAULT_FACETED_SEARCH_LABELS, v as KapiFacetedSearch };
@@ -40,6 +40,13 @@ export interface KapiSelectBaseProps<T = unknown> {
40
40
  }) => Promise<KapiSelectEntry<T>[]>;
41
41
  /** Espera tras la última tecla antes de llamar a `loadOptions`, en ms. @default 300 */
42
42
  loadDelay?: number;
43
+ /**
44
+ * Cambiar este valor tira el resultado cacheado y vuelve a pedir. Es la única forma de refrescar
45
+ * lo que cargó `loadOptions`, porque ese estado vive adentro del componente y el consumidor no
46
+ * lo puede alcanzar. Los datos que el consumidor YA tiene (filas, opciones estáticas) se
47
+ * refrescan pasando props nuevas: para eso no hace falta esto.
48
+ */
49
+ reloadKey?: unknown;
43
50
  /** Ofrece "Crear “texto”" si ninguna opción coincide exacto; si devuelve una opción, se elige. Una promesa debe terminar (resolver o rechazar): mientras está pendiente no se puede crear otra. */
44
51
  onCreate?: (text: string) => KapiSelectOption<T> | void | Promise<KapiSelectOption<T> | void>;
45
52
  /** Filtrar tipeando. Default `true`. */