@kapiuara/ui 0.3.1 → 0.5.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.
@@ -13,8 +13,16 @@ export type KapiFacet = {
13
13
  key: string;
14
14
  label: string;
15
15
  kind: KapiFacetKind;
16
- /** Opciones de una faceta `list`. */
16
+ /** Opciones de una faceta `list`, cuando se conocen de antemano. */
17
17
  options?: ReadonlyArray<KapiFacetOption> | undefined;
18
+ /**
19
+ * Carga de opciones según lo tipeado, para una faceta `list` cuyos valores vive en el servidor.
20
+ * REEMPLAZA al filtro local: lo que devuelve se muestra tal cual, porque el que filtró fue el
21
+ * servidor. Se aborta con `signal` cuando empieza otro pedido, al cerrar el menú o al desmontar.
22
+ */
23
+ loadOptions?: ((query: string, context: {
24
+ signal: AbortSignal;
25
+ }) => Promise<ReadonlyArray<KapiFacetOption>>) | undefined;
18
26
  /**
19
27
  * Recibe el valor elegido: el `value` de la opción, la fecha como `yyyy-mm-dd`, el rango como
20
28
  * `yyyy-mm-dd/yyyy-mm-dd` (ver `parseDateRangeValue`) o `"true"` (flag).
@@ -42,7 +50,9 @@ export type KapiFacetMenuItem = {
42
50
  * Con una faceta `list` pendiente: sus opciones que coinciden. Con una `date` o `dateRange`: nada (decide
43
51
  * el calendario).
44
52
  */
45
- export declare function facetMenuItems(facets: ReadonlyArray<KapiFacet>, pending: KapiFacet | null, input: string): KapiFacetMenuItem[];
53
+ export declare function facetMenuItems(facets: ReadonlyArray<KapiFacet>, pending: KapiFacet | null, input: string,
54
+ /** Opciones ya cargadas para la faceta pendiente. Si vienen, NO se filtran de nuevo: filtró el servidor. */
55
+ loaded?: ReadonlyArray<KapiFacetOption> | undefined): KapiFacetMenuItem[];
46
56
  /** Mueve el ítem activo con vuelta; desde `-1` entra por el extremo según la dirección. */
47
57
  export declare const moveActive: (index: number, count: number, delta: 1 | -1) => number;
48
58
  export type KapiFacetKeyAction = "next" | "prev" | "select" | "text" | "cancel" | "close" | "dropPending" | "removeLast";
@@ -1,21 +1,24 @@
1
1
  import { normalizeFilterText as e } from "../data/tableLogic.js";
2
2
  //#region src/components/inputs/facetedSearchLogic.ts
3
3
  var t = (t, n) => !n || e(t).includes(n);
4
- function n(n, r, i) {
5
- let a = e(i);
6
- if (r) return r.kind === "list" ? (r.options ?? []).filter((e) => t(e.label, a)).map((e) => ({
4
+ function n(n, r, i, a) {
5
+ let o = e(i);
6
+ if (r) return r.kind === "list" ? a ? a.map((e) => ({
7
+ type: "option",
8
+ option: e
9
+ })) : (r.options ?? []).filter((e) => t(e.label, o)).map((e) => ({
7
10
  type: "option",
8
11
  option: e
9
12
  })) : [];
10
- let o = i.trim(), s = o ? [{
13
+ let s = i.trim(), c = s ? [{
11
14
  type: "text",
12
- text: o
15
+ text: s
13
16
  }] : [];
14
- for (let e of n) t(e.label, a) && s.push({
17
+ for (let e of n) t(e.label, o) && c.push({
15
18
  type: "facet",
16
19
  facet: e
17
20
  });
18
- return s;
21
+ return c;
19
22
  }
20
23
  var r = (e, t, n) => t === 0 ? -1 : e < 0 ? n > 0 ? 0 : t - 1 : (e + n + t) % t;
21
24
  function i(e, t) {
@@ -6,6 +6,8 @@ export type KapiFieldContextValue = {
6
6
  helpId?: string | undefined;
7
7
  required: boolean;
8
8
  invalid: boolean;
9
+ /** El campo está esperando una validación asíncrona: ocupado, pero todavía no inválido. */
10
+ busy: boolean;
9
11
  };
10
12
  /** Suma ids para `aria-describedby`/`aria-labelledby`: sin vacíos ni repetidos; `undefined` si no queda ninguno. */
11
13
  export declare const joinIds: (...ids: (string | undefined | null | false)[]) => string | undefined;
@@ -30,6 +32,7 @@ export declare const fieldControlProps: (ctx: KapiFieldContextValue | null, own:
30
32
  describedBy?: string | undefined;
31
33
  invalid?: boolean | undefined;
32
34
  required?: boolean | undefined;
35
+ busy?: boolean | undefined;
33
36
  labelable?: boolean | undefined;
34
37
  ariaLabel?: string | undefined;
35
38
  }) => {
@@ -37,6 +40,7 @@ export declare const fieldControlProps: (ctx: KapiFieldContextValue | null, own:
37
40
  "aria-describedby": string | undefined;
38
41
  "aria-invalid": true | undefined;
39
42
  "aria-required": true | undefined;
43
+ "aria-busy": true | undefined;
40
44
  "aria-labelledby": string | undefined;
41
45
  };
42
46
  /**
@@ -49,6 +53,7 @@ export declare const nativeFieldProps: (ctx: KapiFieldContextValue | null, own:
49
53
  describedBy?: string | undefined;
50
54
  invalid?: boolean | undefined;
51
55
  required?: boolean | undefined;
56
+ busy?: boolean | undefined;
52
57
  ariaInvalid?: AriaAttributes["aria-invalid"] | undefined;
53
58
  ariaRequired?: AriaAttributes["aria-required"] | undefined;
54
59
  takeId?: boolean | undefined;
@@ -57,6 +62,7 @@ export declare const nativeFieldProps: (ctx: KapiFieldContextValue | null, own:
57
62
  "aria-describedby": string | undefined;
58
63
  "aria-invalid": boolean | "true" | "false" | "grammar" | "spelling" | undefined;
59
64
  "aria-required": (boolean | "true" | "false") | undefined;
65
+ "aria-busy": true | undefined;
60
66
  };
61
67
  /**
62
68
  * ¿El foco sale del control? `next` es el `relatedTarget` del blur; `containers` son las partes del
@@ -14,19 +14,22 @@ var e = (...e) => {
14
14
  "aria-describedby": e(t?.helpId, n.describedBy),
15
15
  "aria-invalid": n.invalid ?? t?.invalid ? !0 : void 0,
16
16
  "aria-required": n.required ?? t?.required ? !0 : void 0,
17
+ "aria-busy": n.busy ?? t?.busy ? !0 : void 0,
17
18
  "aria-labelledby": n.labelable === !1 && !n.ariaLabel ? t?.labelId : void 0
18
19
  }), r = (e, t) => {
19
20
  let r = n(e, {
20
21
  id: t.id,
21
22
  describedBy: t.describedBy,
22
23
  invalid: t.invalid,
23
- required: t.required
24
+ required: t.required,
25
+ busy: t.busy
24
26
  });
25
27
  return {
26
28
  id: t.takeId === !1 ? t.id : r.id,
27
29
  "aria-describedby": r["aria-describedby"],
28
30
  "aria-invalid": t.ariaInvalid ?? r["aria-invalid"],
29
- "aria-required": t.ariaRequired ?? r["aria-required"]
31
+ "aria-required": t.ariaRequired ?? r["aria-required"],
32
+ "aria-busy": r["aria-busy"]
30
33
  };
31
34
  }, i = (e, ...t) => !(e instanceof Node && t.some((t) => t?.contains(e))), a = (e, t) => {
32
35
  typeof e == "function" ? e(t) : e && (e.current = t);
@@ -4,8 +4,13 @@ export type KapiWizardStep = {
4
4
  title: string;
5
5
  desc?: ReactNode | undefined;
6
6
  content: ReactNode;
7
- /** Si devuelve false, "Siguiente"/"Finalizar" NO avanza (validación por paso). */
8
- validate?: (() => boolean) | undefined;
7
+ /**
8
+ * Si devuelve `false`, "Siguiente"/"Finalizar" NO avanza. Puede devolver una promesa: mientras
9
+ * resuelve, el wizard marca los botones como ocupados y no deja volver a apretar. Cada paso
10
+ * decide por su cuenta, así que un wizard puede mezclar pasos sincrónicos con otros que
11
+ * consultan al servidor. Una promesa rechazada se trata como `false`: no avanza.
12
+ */
13
+ validate?: (() => boolean | Promise<boolean>) | undefined;
9
14
  };
10
15
  export type KapiWizardOrientation = "horizontal" | "vertical";
11
16
  export type KapiWizardLabels = {
@@ -13,6 +18,8 @@ export type KapiWizardLabels = {
13
18
  cancel: string;
14
19
  back: string;
15
20
  next: string;
21
+ /** Reemplaza al texto de avanzar mientras un `validate` asíncrono está resolviendo. */
22
+ validating: string;
16
23
  };
17
24
  export declare const DEFAULT_WIZARD_LABELS: KapiWizardLabels;
18
25
  /** Atributos nativos (`id`, `style`, `data-*`…) van al contenedor del wizard. */
@@ -2,103 +2,120 @@
2
2
  import { KapiButton as e } from "../inputs/KapiButton.js";
3
3
  import { useLabels as t } from "../locale/KapiLocaleProvider.js";
4
4
  import { joinClasses as n } from "../rootProps.js";
5
- import { canJumpTo as r, clampStep as i, resolveAdvance as a } from "./wizardLogic.js";
6
- import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
7
- import { useState as l } from "react";
8
- import { Check as u, ChevronLeft as d, ChevronRight as f } from "lucide-react";
5
+ import { canJumpTo as r, clampStep as i, isThenable as a, resolveAdvance as o } from "./wizardLogic.js";
6
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
7
+ import { useRef as u, useState as d } from "react";
8
+ import { Check as f, ChevronLeft as p, ChevronRight as m } from "lucide-react";
9
9
  //#region src/components/navigation/KapiWizard.tsx
10
- var p = {
10
+ var h = {
11
11
  finish: "Finalizar",
12
12
  cancel: "Cancelar",
13
13
  back: "Atrás",
14
- next: "Siguiente"
15
- }, m = {
14
+ next: "Siguiente",
15
+ validating: "Validando…"
16
+ }, g = {
16
17
  size: 15,
17
18
  strokeWidth: 2.2
18
- }, h = (e, t) => e === void 0 ? t : e, g = ({ steps: g, orientation: _ = "horizontal", onFinish: v, onCancel: y, finishLabel: b, cancelLabel: x, backLabel: S, nextLabel: C, labels: w, step: T, defaultStep: E = 0, onStepChange: D, className: O, ...k }) => {
19
- let A = t("wizard", p, w), [j, M] = l(E), N = i(T ?? j, g.length), P = g[N];
20
- if (!P) return null;
21
- let F = N === g.length - 1, I = (e) => {
22
- let t = i(e, g.length);
23
- t !== N && (T === void 0 && M(t), D?.(t));
24
- }, L = (e) => {
25
- r(e, N) && I(e);
26
- }, R = () => {
27
- let e = a(g, N);
28
- e === "next" ? I(N + 1) : e === "finish" && v?.();
29
- }, z = /* @__PURE__ */ c("div", {
19
+ }, _ = (e, t) => e === void 0 ? t : e, v = ({ steps: v, orientation: y = "horizontal", onFinish: b, onCancel: x, finishLabel: S, cancelLabel: C, backLabel: w, nextLabel: T, labels: E, step: D, defaultStep: O = 0, onStepChange: k, className: A, ...j }) => {
20
+ let M = t("wizard", h, E), [N, P] = d(O), [F, I] = d(!1), L = u(0), R = u(0), z = i(D ?? N, v.length);
21
+ R.current = z;
22
+ let B = v[z];
23
+ if (!B) return null;
24
+ let V = z === v.length - 1, H = (e) => {
25
+ let t = i(e, v.length);
26
+ t !== z && (D === void 0 && P(t), k?.(t));
27
+ }, U = (e) => {
28
+ r(e, z) && H(e);
29
+ }, W = (e, t) => {
30
+ let n = o(v, e, t);
31
+ n === "next" ? H(e + 1) : n === "finish" && b?.();
32
+ }, G = (e, t, n) => {
33
+ e === L.current && (I(!1), t === R.current && W(t, n));
34
+ }, K = () => {
35
+ if (F) return;
36
+ let e = !B.validate || B.validate();
37
+ if (!a(e)) {
38
+ W(z, !!e);
39
+ return;
40
+ }
41
+ let t = L.current += 1, n = z;
42
+ I(!0), e.then((e) => G(t, n, !!e), () => G(t, n, !1));
43
+ }, q = /* @__PURE__ */ l("div", {
30
44
  className: "kapi-wz__nav",
31
- children: [/* @__PURE__ */ s(e, {
32
- onClick: N === 0 ? y : () => I(N - 1),
33
- children: N === 0 ? h(x, A.cancel) : /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s(d, { ...m }), h(S, A.back)] })
34
- }), /* @__PURE__ */ s(e, {
45
+ children: [/* @__PURE__ */ c(e, {
46
+ onClick: z === 0 ? x : () => H(z - 1),
47
+ disabled: F,
48
+ children: z === 0 ? _(C, M.cancel) : /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c(p, { ...g }), _(w, M.back)] })
49
+ }), /* @__PURE__ */ c(e, {
35
50
  variant: "primary",
36
- onClick: R,
37
- children: F ? h(b, A.finish) : /* @__PURE__ */ c(o, { children: [h(C, A.next), /* @__PURE__ */ s(f, { ...m })] })
51
+ onClick: K,
52
+ disabled: F,
53
+ "aria-busy": F || void 0,
54
+ children: F ? M.validating : V ? _(S, M.finish) : /* @__PURE__ */ l(s, { children: [_(T, M.next), /* @__PURE__ */ c(m, { ...g })] })
38
55
  })]
39
- }), B = /* @__PURE__ */ s("div", {
56
+ }), J = /* @__PURE__ */ c("div", {
40
57
  className: "kapi-wz__pane",
41
- children: P.content
42
- }, N);
43
- return _ === "vertical" ? /* @__PURE__ */ c("div", {
44
- ...k,
45
- className: n("kapi-wz kapi-wz--v", O),
46
- children: [/* @__PURE__ */ s("div", {
58
+ children: B.content
59
+ }, z);
60
+ return y === "vertical" ? /* @__PURE__ */ l("div", {
61
+ ...j,
62
+ className: n("kapi-wz kapi-wz--v", A),
63
+ children: [/* @__PURE__ */ c("div", {
47
64
  className: "kapi-wz__rail",
48
- children: g.map((e, t) => /* @__PURE__ */ c("button", {
65
+ children: v.map((e, t) => /* @__PURE__ */ l("button", {
49
66
  type: "button",
50
- className: `kapi-wz__vstep${t === N ? " is-on" : ""}`,
51
- "aria-current": t === N ? "step" : void 0,
52
- onClick: () => L(t),
53
- children: [/* @__PURE__ */ s("span", {
54
- className: `kapi-step__dot${t < N ? " kapi-step__dot--done" : ""}${t === N ? " kapi-step__dot--on" : ""}`,
55
- children: t < N ? /* @__PURE__ */ s(u, {
67
+ className: `kapi-wz__vstep${t === z ? " is-on" : ""}`,
68
+ "aria-current": t === z ? "step" : void 0,
69
+ onClick: () => U(t),
70
+ children: [/* @__PURE__ */ c("span", {
71
+ className: `kapi-step__dot${t < z ? " kapi-step__dot--done" : ""}${t === z ? " kapi-step__dot--on" : ""}`,
72
+ children: t < z ? /* @__PURE__ */ c(f, {
56
73
  size: 13,
57
74
  strokeWidth: 3
58
75
  }) : t + 1
59
- }), /* @__PURE__ */ c("span", {
76
+ }), /* @__PURE__ */ l("span", {
60
77
  className: "kapi-wz__vlabel",
61
- children: [/* @__PURE__ */ s("b", { children: e.title }), e.desc && /* @__PURE__ */ s("span", { children: e.desc })]
78
+ children: [/* @__PURE__ */ c("b", { children: e.title }), e.desc && /* @__PURE__ */ c("span", { children: e.desc })]
62
79
  })]
63
80
  }, `${t}-${e.title}`))
64
- }), /* @__PURE__ */ c("div", {
81
+ }), /* @__PURE__ */ l("div", {
65
82
  className: "kapi-wz__main",
66
- children: [B, z]
83
+ children: [J, q]
67
84
  })]
68
- }) : /* @__PURE__ */ c("div", {
69
- ...k,
70
- className: n("kapi-wz", O),
85
+ }) : /* @__PURE__ */ l("div", {
86
+ ...j,
87
+ className: n("kapi-wz", A),
71
88
  children: [
72
- /* @__PURE__ */ s("div", {
89
+ /* @__PURE__ */ c("div", {
73
90
  className: "kapi-wz__steps",
74
- children: g.map((e, t) => /* @__PURE__ */ c("button", {
91
+ children: v.map((e, t) => /* @__PURE__ */ l("button", {
75
92
  type: "button",
76
- className: `kapi-wz__step${t === N ? " is-on" : ""}${t < N ? " is-done" : ""}`,
77
- "aria-current": t === N ? "step" : void 0,
78
- onClick: () => L(t),
93
+ className: `kapi-wz__step${t === z ? " is-on" : ""}${t < z ? " is-done" : ""}`,
94
+ "aria-current": t === z ? "step" : void 0,
95
+ onClick: () => U(t),
79
96
  children: [
80
- /* @__PURE__ */ s("span", {
97
+ /* @__PURE__ */ c("span", {
81
98
  className: "kapi-wz__num",
82
- children: t < N ? /* @__PURE__ */ s(u, {
99
+ children: t < z ? /* @__PURE__ */ c(f, {
83
100
  size: 16,
84
101
  strokeWidth: 3
85
102
  }) : t + 1
86
103
  }),
87
- /* @__PURE__ */ s("span", {
104
+ /* @__PURE__ */ c("span", {
88
105
  className: "kapi-wz__st",
89
106
  children: e.title
90
107
  }),
91
- e.desc && /* @__PURE__ */ s("span", {
108
+ e.desc && /* @__PURE__ */ c("span", {
92
109
  className: "kapi-wz__ss",
93
110
  children: e.desc
94
111
  })
95
112
  ]
96
113
  }, `${t}-${e.title}`))
97
114
  }),
98
- B,
99
- z
115
+ J,
116
+ q
100
117
  ]
101
118
  });
102
119
  };
103
120
  //#endregion
104
- export { p as DEFAULT_WIZARD_LABELS, g as KapiWizard };
121
+ export { h as DEFAULT_WIZARD_LABELS, v as KapiWizard };
@@ -1,11 +1,21 @@
1
1
  /** Lo mínimo que la lógica necesita de un paso. */
2
2
  export type WizardStepLike = {
3
- validate?: (() => boolean) | undefined;
3
+ validate?: (() => boolean | Promise<boolean>) | undefined;
4
4
  };
5
5
  export type WizardAdvance = "blocked" | "next" | "finish";
6
6
  /** Mantiene el índice dentro de [0, total-1]. Con 0 pasos devuelve 0. */
7
7
  export declare const clampStep: (index: number, total: number) => number;
8
8
  /** Sólo se puede saltar hacia atrás por click (nunca adelante). */
9
9
  export declare const canJumpTo: (target: number, current: number) => boolean;
10
- /** Qué pasa al apretar "Siguiente": respeta `validate()` del paso actual. */
11
- export declare const resolveAdvance: (steps: readonly WizardStepLike[], current: number) => WizardAdvance;
10
+ /**
11
+ * Un `validate` que devuelve una promesa. Se mira el `then` y no `instanceof Promise`: un
12
+ * consumidor puede devolver la promesa de otra realm o de una librería, y seguiría siendo
13
+ * esperable.
14
+ */
15
+ export declare const isThenable: (value: unknown) => value is Promise<boolean>;
16
+ /**
17
+ * Qué pasa al apretar "Siguiente", una vez que YA se sabe si el paso dio por válido. No llama a
18
+ * `validate`: quien la llama decide si esperó una promesa o no, y así esta función queda pura y
19
+ * sirve igual para el camino sincrónico y para el asíncrono.
20
+ */
21
+ export declare const resolveAdvance: (steps: readonly WizardStepLike[], current: number, valid: boolean) => WizardAdvance;
@@ -1,7 +1,4 @@
1
1
  //#region src/components/navigation/wizardLogic.ts
2
- var e = (e, t) => t <= 0 ? 0 : Math.min(Math.max(Math.trunc(e) || 0, 0), t - 1), t = (e, t) => e < t, n = (e, t) => {
3
- let n = e[t];
4
- return !n || n.validate && !n.validate() ? "blocked" : t >= e.length - 1 ? "finish" : "next";
5
- };
2
+ var e = (e, t) => t <= 0 ? 0 : Math.min(Math.max(Math.trunc(e) || 0, 0), t - 1), t = (e, t) => e < t, n = (e) => typeof e?.then == "function", r = (e, t, n) => !e[t] || !n ? "blocked" : t >= e.length - 1 ? "finish" : "next";
6
3
  //#endregion
7
- export { t as canJumpTo, e as clampStep, n as resolveAdvance };
4
+ export { t as canJumpTo, e as clampStep, n as isThenable, r as resolveAdvance };