@kapiuara/ui 0.17.0 → 0.18.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 (84) hide show
  1. package/README.md +259 -9
  2. package/dist/components/data/KapiScatterChart.d.ts +56 -0
  3. package/dist/components/data/KapiScatterChart.js +90 -0
  4. package/dist/components/data/chartFrame.d.ts +20 -2
  5. package/dist/components/data/chartFrame.js +33 -24
  6. package/dist/components/data/index.d.ts +4 -0
  7. package/dist/components/data/scatterLogic.d.ts +56 -0
  8. package/dist/components/data/scatterLogic.js +43 -0
  9. package/dist/components/display/KapiAvatarGroup.d.ts +14 -2
  10. package/dist/components/display/KapiAvatarGroup.js +25 -23
  11. package/dist/components/display/KapiTimeline.d.ts +14 -0
  12. package/dist/components/display/KapiTimeline.js +28 -21
  13. package/dist/components/display/avatarGroupSlots.d.ts +6 -0
  14. package/dist/components/display/avatarGroupSlots.js +9 -0
  15. package/dist/components/display/index.d.ts +1 -1
  16. package/dist/components/feedback/KapiAlert.d.ts +6 -1
  17. package/dist/components/feedback/KapiAlert.js +45 -44
  18. package/dist/components/feedback/KapiCountdown.d.ts +12 -1
  19. package/dist/components/feedback/KapiCountdown.js +34 -31
  20. package/dist/components/feedback/KapiEmpty.d.ts +6 -1
  21. package/dist/components/feedback/KapiEmpty.js +20 -18
  22. package/dist/components/feedback/KapiProgress.js +1 -1
  23. package/dist/components/feedback/KapiSpinner.d.ts +48 -0
  24. package/dist/components/feedback/KapiSpinner.js +27 -0
  25. package/dist/components/feedback/KapiToastContainer.js +1 -1
  26. package/dist/components/feedback/KapiTour.js +1 -1
  27. package/dist/components/feedback/alertSlots.d.ts +9 -0
  28. package/dist/components/feedback/alertSlots.js +12 -0
  29. package/dist/components/feedback/countdownSlots.d.ts +6 -0
  30. package/dist/components/feedback/countdownSlots.js +9 -0
  31. package/dist/components/feedback/emptySlots.d.ts +8 -0
  32. package/dist/components/feedback/emptySlots.js +11 -0
  33. package/dist/components/feedback/index.d.ts +5 -3
  34. package/dist/components/inputs/KapiFileUpload.d.ts +14 -1
  35. package/dist/components/inputs/KapiFileUpload.js +80 -67
  36. package/dist/components/inputs/formBridgeLogic.d.ts +104 -0
  37. package/dist/components/inputs/formBridgeLogic.js +25 -0
  38. package/dist/components/inputs/index.d.ts +2 -0
  39. package/dist/components/locale/labelRegistry.d.ts +8 -0
  40. package/dist/components/navigation/KapiSteps.d.ts +26 -5
  41. package/dist/components/navigation/KapiSteps.js +55 -43
  42. package/dist/components/overlays/KapiImageViewer.d.ts +63 -0
  43. package/dist/components/overlays/KapiImageViewer.js +106 -0
  44. package/dist/components/overlays/KapiShortcutsHelp.d.ts +53 -0
  45. package/dist/components/overlays/KapiShortcutsHelp.js +55 -0
  46. package/dist/components/overlays/KapiTooltip.d.ts +49 -10
  47. package/dist/components/overlays/KapiTooltip.js +110 -58
  48. package/dist/components/overlays/KapiViewport.d.ts +63 -0
  49. package/dist/components/overlays/KapiViewport.js +195 -0
  50. package/dist/components/overlays/index.d.ts +8 -0
  51. package/dist/components/overlays/shortcutsHelpSlots.d.ts +9 -0
  52. package/dist/components/overlays/shortcutsHelpSlots.js +12 -0
  53. package/dist/components/overlays/viewportLogic.d.ts +73 -0
  54. package/dist/components/overlays/viewportLogic.js +54 -0
  55. package/dist/components/slotCatalog.d.ts +33 -0
  56. package/dist/components/slotCatalog.js +30 -20
  57. package/dist/css/base.css +1 -1
  58. package/dist/css/components/data/KapiScatterChart.css +1 -0
  59. package/dist/css/components/display/display.css +1 -1
  60. package/dist/css/components/inputs/KapiFileUpload.css +1 -1
  61. package/dist/css/components/navigation/KapiSteps.css +1 -1
  62. package/dist/css/components/overlays/KapiViewport.css +1 -0
  63. package/dist/css/components/overlays/overlays.css +1 -1
  64. package/dist/hooks/elementSizeLogic.d.ts +15 -0
  65. package/dist/hooks/elementSizeLogic.js +7 -0
  66. package/dist/hooks/hotkeyLogic.d.ts +9 -0
  67. package/dist/hooks/hotkeyLogic.js +16 -15
  68. package/dist/hooks/hotkeyRegistry.d.ts +44 -0
  69. package/dist/hooks/hotkeyRegistry.js +32 -0
  70. package/dist/hooks/index.d.ts +10 -0
  71. package/dist/hooks/useDebouncedValue.d.ts +30 -0
  72. package/dist/hooks/useDebouncedValue.js +26 -0
  73. package/dist/hooks/useDisclosure.d.ts +39 -0
  74. package/dist/hooks/useDisclosure.js +35 -0
  75. package/dist/hooks/useElementSize.d.ts +27 -0
  76. package/dist/hooks/useElementSize.js +29 -0
  77. package/dist/hooks/useHotkey.d.ts +8 -0
  78. package/dist/hooks/useHotkey.js +27 -15
  79. package/dist/index.js +201 -188
  80. package/dist/kapi.css +1 -1
  81. package/dist/kapi.layered.css +1 -1
  82. package/dist/logic.d.ts +4 -0
  83. package/dist/logic.js +33 -29
  84. package/package.json +1 -1
@@ -1,32 +1,34 @@
1
1
  "use client";
2
2
  import "#kapi-css/components/feedback/feedback.css";
3
+ import { slot as e } from "../slotsLogic.js";
3
4
  /* empty css */
4
- import { jsx as e, jsxs as t } from "react/jsx-runtime";
5
+ import { EMPTY_SLOTS as t } from "./emptySlots.js";
6
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
5
7
  //#region src/components/feedback/KapiEmpty.tsx
6
- function n({ icon: n, title: r, description: i, action: a, className: o, ...s }) {
7
- return /* @__PURE__ */ t("div", {
8
- className: ["kapi-empty", o].filter(Boolean).join(" "),
9
- ...s,
8
+ function i({ icon: i, title: a, description: o, action: s, className: c, classNames: l, ...u }) {
9
+ return /* @__PURE__ */ r("div", {
10
+ ...u,
11
+ ...e(t, "root", l, c),
10
12
  children: [
11
- n != null && /* @__PURE__ */ e("div", {
12
- className: "kapi-empty__icon",
13
+ i != null && /* @__PURE__ */ n("div", {
14
+ ...e(t, "icon", l),
13
15
  "aria-hidden": !0,
14
- children: n
15
- }),
16
- /* @__PURE__ */ e("div", {
17
- className: "kapi-empty__title",
18
- children: r
19
- }),
20
- i != null && /* @__PURE__ */ e("div", {
21
- className: "kapi-empty__desc",
22
16
  children: i
23
17
  }),
24
- a != null && /* @__PURE__ */ e("div", {
25
- className: "kapi-empty__action",
18
+ /* @__PURE__ */ n("div", {
19
+ ...e(t, "title", l),
26
20
  children: a
21
+ }),
22
+ o != null && /* @__PURE__ */ n("div", {
23
+ ...e(t, "description", l),
24
+ children: o
25
+ }),
26
+ s != null && /* @__PURE__ */ n("div", {
27
+ ...e(t, "action", l),
28
+ children: s
27
29
  })
28
30
  ]
29
31
  });
30
32
  }
31
33
  //#endregion
32
- export { n as KapiEmpty };
34
+ export { i as KapiEmpty };
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import "#kapi-css/components/feedback/feedback.css";
3
3
  import { useToneLook as e } from "../../hooks/useToneFamilies.js";
4
- /* empty css */
5
4
  import { circleDash as t, clampPercent as n, formatPercent as r, progressClasses as i } from "./progressLogic.js";
5
+ /* empty css */
6
6
  import { jsx as a, jsxs as o } from "react/jsx-runtime";
7
7
  //#region src/components/feedback/KapiProgress.tsx
8
8
  var s = {
@@ -0,0 +1,48 @@
1
+ import type { HTMLAttributes, Ref } from "react";
2
+ import type { KapiLabelsOverride } from "../labelsLogic.js";
3
+ /** Textos de `KapiSpinner`. */
4
+ export type KapiSpinnerLabels = {
5
+ /** Nombre accesible (y texto visible con `labelVisible`). */
6
+ loading: string;
7
+ };
8
+ export declare const DEFAULT_SPINNER_LABELS: KapiSpinnerLabels;
9
+ /** Tamaños de `KapiSpinner`: los dos que dibuja la hoja base. */
10
+ export type KapiSpinnerSize = "sm" | "md";
11
+ /** Atributos nativos (`id`, `style`, `data-*`…) van al contenedor. */
12
+ export type KapiSpinnerProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
13
+ /** Ref al `<div>` raíz. */
14
+ ref?: Ref<HTMLDivElement> | undefined;
15
+ /**
16
+ * `sm` mide 20px y entra al lado de un texto; `md` mide 46px y es el de una zona que carga entera.
17
+ * @default "md"
18
+ */
19
+ size?: KapiSpinnerSize | undefined;
20
+ /** Nombre accesible propio. Sin él, el del locale (`Cargando`). */
21
+ label?: string | undefined;
22
+ /** Además de nombrarlo, muestra el texto debajo del disco. */
23
+ labelVisible?: boolean | undefined;
24
+ /**
25
+ * Lo saca del árbol de accesibilidad. Para cuando el estado de carga **ya lo anuncia otra cosa**
26
+ * (un `KapiButton loading`, una tabla con `aria-busy`): dos anuncios del mismo hecho son ruido
27
+ * para quien usa un lector de pantalla.
28
+ */
29
+ decorative?: boolean | undefined;
30
+ /** Textos fijos (el nombre accesible). */
31
+ labels?: KapiLabelsOverride<KapiSpinnerLabels> | undefined;
32
+ };
33
+ /**
34
+ * Indicador de carga en línea.
35
+ *
36
+ * Existe porque hasta ahora había dos extremos y nada en el medio: `.kapi-spinner` es **sólo una
37
+ * clase** —cada pantalla escribía el `<span>` a mano y casi siempre sin anunciar nada— y
38
+ * `KapiLoading` es un **overlay** que tapa la pantalla entera. Esto es el disco solo, con el
39
+ * anuncio hecho bien: `role="status"` y un nombre accesible, o nada en absoluto con `decorative`.
40
+ * **No lleva `aria-busy`**, y es a propósito: sobre una región viva le diría al lector que espere y
41
+ * se perdería el anuncio, que es justo lo que este componente existe para hacer. El motivo completo
42
+ * está en el comentario de la raíz, al lado del `role`.
43
+ *
44
+ * No trae CSS propio: usa las clases que la hoja base ya dibuja, así que el gate de movimiento lo
45
+ * sigue tratando como loop de carga (gira lento en vez de congelarse con `data-motion="reduced"`,
46
+ * porque un spinner congelado parece colgado).
47
+ */
48
+ export declare const KapiSpinner: ({ size, label, labelVisible, decorative, labels, className, ...rest }: KapiSpinnerProps) => import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { joinClasses as e } from "../rootProps.js";
3
+ import { useLabels as t } from "../locale/KapiLocaleProvider.js";
4
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
5
+ //#region src/components/feedback/KapiSpinner.tsx
6
+ var i = { loading: "Cargando" }, a = ({ size: a = "md", label: o, labelVisible: s, decorative: c, labels: l, className: u, ...d }) => {
7
+ let f = t("spinner", i, l), p = o ?? f.loading, m = /* @__PURE__ */ n("div", {
8
+ className: e("kapi-spinner", a === "sm" && "kapi-spinner--sm"),
9
+ "aria-hidden": "true"
10
+ });
11
+ return c ? /* @__PURE__ */ n("div", {
12
+ ...d,
13
+ className: u,
14
+ "aria-hidden": "true",
15
+ children: m
16
+ }) : /* @__PURE__ */ r("div", {
17
+ ...d,
18
+ className: u,
19
+ role: "status",
20
+ children: [m, /* @__PURE__ */ n("span", {
21
+ className: s ? void 0 : "kapi-sr-only",
22
+ children: p
23
+ })]
24
+ });
25
+ };
26
+ //#endregion
27
+ export { i as DEFAULT_SPINNER_LABELS, a as KapiSpinner };
@@ -6,8 +6,8 @@ import { useLabels as n } from "../locale/KapiLocaleProvider.js";
6
6
  import { activeElementOf as r, docOf as i } from "../../hooks/ownerDocument.js";
7
7
  import { usePortalRootOverride as a } from "../../hooks/portalRoot.js";
8
8
  import { modalStack as o } from "../overlays/modalStack.js";
9
- import { getPortalRoot as s } from "../overlays/useNativeDialog.js";
10
9
  /* empty css */
10
+ import { getPortalRoot as s } from "../overlays/useNativeDialog.js";
11
11
  import { moveNode as c, raisePopover as l } from "./toastLayer.js";
12
12
  import { toastStore as u } from "./toastStore.js";
13
13
  import { useEffect as d, useLayoutEffect as f, useRef as p, useState as m, useSyncExternalStore as h } from "react";
@@ -9,8 +9,8 @@ import { useKapiRoot as s } from "../../hooks/kapiRoot.js";
9
9
  import { onViewportChange as c } from "../../hooks/rafThrottle.js";
10
10
  import { usePlacement as l } from "../../hooks/usePlacement.js";
11
11
  import { useDismiss as u } from "../../hooks/useDismiss.js";
12
- import { trapTabKey as d } from "../../hooks/focusLogic.js";
13
12
  /* empty css */
13
+ import { trapTabKey as d } from "../../hooks/focusLogic.js";
14
14
  import { TOUR_PLACEMENT as f, filterAvailableSteps as p, highlightBox as m, markTourSeen as h } from "./tourLogic.js";
15
15
  import { useCallback as g, useEffect as _, useId as v, useLayoutEffect as y, useRef as b, useState as x } from "react";
16
16
  import { jsx as S, jsxs as C } from "react/jsx-runtime";
@@ -0,0 +1,9 @@
1
+ /** Partes de `alert` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
2
+ export declare const ALERT_SLOTS: import("../slotsLogic.js").SlotTable<"alert", {
3
+ readonly root: "kapi-alert";
4
+ readonly icon: "kapi-alert__ico";
5
+ readonly body: "kapi-alert__body";
6
+ readonly title: "kapi-alert__title";
7
+ readonly message: "kapi-alert__msg";
8
+ readonly close: "kapi-alert__close";
9
+ }>;
@@ -0,0 +1,12 @@
1
+ import { defineSlots as e } from "../slotsLogic.js";
2
+ //#region src/components/feedback/alertSlots.ts
3
+ var t = e("alert", {
4
+ root: "kapi-alert",
5
+ icon: "kapi-alert__ico",
6
+ body: "kapi-alert__body",
7
+ title: "kapi-alert__title",
8
+ message: "kapi-alert__msg",
9
+ close: "kapi-alert__close"
10
+ });
11
+ //#endregion
12
+ export { t as ALERT_SLOTS };
@@ -0,0 +1,6 @@
1
+ /** Partes de `countdown` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
2
+ export declare const COUNTDOWN_SLOTS: import("../slotsLogic.js").SlotTable<"countdown", {
3
+ readonly root: "kapi-countdown";
4
+ readonly prefix: "kapi-countdown__prefix";
5
+ readonly time: "kapi-countdown__time";
6
+ }>;
@@ -0,0 +1,9 @@
1
+ import { defineSlots as e } from "../slotsLogic.js";
2
+ //#region src/components/feedback/countdownSlots.ts
3
+ var t = e("countdown", {
4
+ root: "kapi-countdown",
5
+ prefix: "kapi-countdown__prefix",
6
+ time: "kapi-countdown__time"
7
+ });
8
+ //#endregion
9
+ export { t as COUNTDOWN_SLOTS };
@@ -0,0 +1,8 @@
1
+ /** Partes de `empty` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
2
+ export declare const EMPTY_SLOTS: import("../slotsLogic.js").SlotTable<"empty", {
3
+ readonly root: "kapi-empty";
4
+ readonly icon: "kapi-empty__icon";
5
+ readonly title: "kapi-empty__title";
6
+ readonly description: "kapi-empty__desc";
7
+ readonly action: "kapi-empty__action";
8
+ }>;
@@ -0,0 +1,11 @@
1
+ import { defineSlots as e } from "../slotsLogic.js";
2
+ //#region src/components/feedback/emptySlots.ts
3
+ var t = e("empty", {
4
+ root: "kapi-empty",
5
+ icon: "kapi-empty__icon",
6
+ title: "kapi-empty__title",
7
+ description: "kapi-empty__desc",
8
+ action: "kapi-empty__action"
9
+ });
10
+ //#endregion
11
+ export { t as EMPTY_SLOTS };
@@ -1,13 +1,15 @@
1
1
  export { KapiAlert,
2
2
  /** @deprecated Interno, se quita en 1.0. */
3
3
  alertRole, DEFAULT_ALERT_LABELS } from "./KapiAlert.js";
4
- export type { KapiAlertLabels, KapiAlertProps, KapiAlertRole, KapiAlertTone, KapiAlertVariant } from "./KapiAlert.js";
4
+ export type { KapiAlertLabels, KapiAlertClassNames, KapiAlertProps, KapiAlertRole, KapiAlertTone, KapiAlertVariant } from "./KapiAlert.js";
5
5
  export { KapiToastContainer, DEFAULT_TOAST_LABELS } from "./KapiToastContainer.js";
6
6
  export type { KapiToastContainerProps, KapiToastLabels } from "./KapiToastContainer.js";
7
7
  export { kapiToast, toastStore,
8
8
  /** @deprecated Interno, se quita en 1.0. */
9
9
  createToastStore, TOAST_ACTION_DURATION, TOAST_DEFAULT_DURATION } from "./toastStore.js";
10
10
  export type { KapiToastAction, KapiToastItem, KapiToastMessage, KapiToastOptions, KapiToastPromiseMessages, KapiToastShowOptions, KapiToastStore, KapiToastStoreOptions, KapiToastTone, KapiToastUpdate, KapiToastVariant } from "./toastStore.js";
11
+ export { KapiSpinner, DEFAULT_SPINNER_LABELS } from "./KapiSpinner.js";
12
+ export type { KapiSpinnerProps, KapiSpinnerLabels, KapiSpinnerSize } from "./KapiSpinner.js";
11
13
  export { KapiSkeleton } from "./KapiSkeleton.js";
12
14
  export type { KapiSkeletonProps } from "./KapiSkeleton.js";
13
15
  export { KapiFab, DEFAULT_FAB_LABELS } from "./KapiFab.js";
@@ -27,9 +29,9 @@ clampPercent, formatPercent,
27
29
  progressClasses } from "./progressLogic.js";
28
30
  export type { KapiProgressTone } from "./progressLogic.js";
29
31
  export { KapiEmpty } from "./KapiEmpty.js";
30
- export type { KapiEmptyProps } from "./KapiEmpty.js";
32
+ export type { KapiEmptyClassNames, KapiEmptyProps } from "./KapiEmpty.js";
31
33
  export { KapiCountdown } from "./KapiCountdown.js";
32
- export type { KapiCountdownProps } from "./KapiCountdown.js";
34
+ export type { KapiCountdownClassNames, KapiCountdownProps } from "./KapiCountdown.js";
33
35
  export { KapiUnsavedBar, DEFAULT_UNSAVED_BAR_LABELS } from "./KapiUnsavedBar.js";
34
36
  export type { KapiUnsavedBarProps, KapiUnsavedBarLabels } from "./KapiUnsavedBar.js";
35
37
  export { KapiBulkBar, DEFAULT_BULK_BAR_LABELS } from "./KapiBulkBar.js";
@@ -32,6 +32,17 @@ export type KapiFileUploadProps = {
32
32
  onBlur?: ((event: FocusEvent<HTMLDivElement>) => void) | undefined;
33
33
  /** Marca la zona como inválida (`aria-invalid`). Sin la prop, lo toma del `KapiField` (`invalid`). */
34
34
  invalid?: boolean | undefined;
35
+ /**
36
+ * Progreso de subida de cada archivo, 0–100. Devolver `undefined` para un archivo es no mostrarle
37
+ * barra (todavía no empezó, o ya terminó). Es una **función y no un mapa por nombre** porque la
38
+ * lista admite dos archivos con el mismo nombre y un mapa se los pisaría entre sí.
39
+ */
40
+ progress?: ((file: File, index: number) => number | undefined) | undefined;
41
+ /**
42
+ * Permite pegar archivos del portapapeles con Ctrl/Cmd+V cuando la zona tiene el foco (una captura
43
+ * de pantalla, por ejemplo). Respeta `accept` y `multiple`, igual que arrastrar.
44
+ */
45
+ paste?: boolean | undefined;
35
46
  /** `id`s extra para `aria-describedby` (se suman a la ayuda del campo y al hint). */
36
47
  "aria-describedby"?: string | undefined;
37
48
  /** Ref a la zona (el elemento enfocable, `role="button"`). */
@@ -46,6 +57,8 @@ export type KapiFileUploadLabels = {
46
57
  remove: string;
47
58
  /** Ayuda bajo el título (sin `hint`). */
48
59
  hint: string;
60
+ /** Prefijo del nombre accesible de la barra de progreso ("Subiendo informe.pdf"). */
61
+ uploading: string;
49
62
  };
50
63
  export declare const DEFAULT_FILE_UPLOAD_LABELS: KapiFileUploadLabels;
51
64
  /**
@@ -54,4 +67,4 @@ export declare const DEFAULT_FILE_UPLOAD_LABELS: KapiFileUploadLabels;
54
67
  * Dentro de un `KapiField` la zona toma id, nombre (label del campo + texto de la zona), ayuda y `aria-invalid`.
55
68
  * No lleva `aria-required` (no es válido en `role="button"`): el obligatorio se ve en el asterisco del label.
56
69
  */
57
- export declare const KapiFileUpload: ({ multiple, accept, hint: hintProp, onChange, disabled, className, style, labels, name, id, onBlur, invalid, "aria-describedby": describedBy, ref }: KapiFileUploadProps) => import("react").JSX.Element;
70
+ export declare const KapiFileUpload: ({ multiple, accept, hint: hintProp, onChange, disabled, className, style, labels, name, id, onBlur, invalid, progress, paste, "aria-describedby": describedBy, ref }: KapiFileUploadProps) => import("react").JSX.Element;
@@ -6,124 +6,137 @@ import { fieldControlProps as n, joinIds as r } from "./fieldLogic.js";
6
6
  import { useKapiField as i } from "./KapiField.js";
7
7
  import { formatFileSize as a, isActivationKey as o, matchesAccept as s, mergeFiles as c, removeFileAt as l } from "./fileUploadLogic.js";
8
8
  /* empty css */
9
- import { useEffect as u, useId as d, useRef as f, useState as p } from "react";
10
- import { jsx as m, jsxs as h } from "react/jsx-runtime";
11
- import { FileText as g, UploadCloud as _, X as v } from "lucide-react";
9
+ import { KapiProgress as u } from "../feedback/KapiProgress.js";
10
+ import { useEffect as d, useId as f, useRef as p, useState as m } from "react";
11
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
12
+ import { FileText as _, UploadCloud as v, X as y } from "lucide-react";
12
13
  //#region src/components/inputs/KapiFileUpload.tsx
13
- var y = {
14
+ var b = {
14
15
  drop: "Arrastra archivos o",
15
16
  choose: "elige",
16
17
  remove: "Quitar",
17
- hint: "PDF, JPG, PNG · hasta 10MB"
18
- }, b = ({ multiple: b = !0, accept: x, hint: S, onChange: C, disabled: w = !1, className: T, style: E, labels: D, name: O, id: k, onBlur: A, invalid: j, "aria-describedby": M, ref: N }) => {
19
- let P = t("fileUpload", y, D), F = S ?? P.hint, I = i(), [L, R] = p([]), [z, B] = p(!1), V = f(null), H = d(), U = `${H}-title`, W = `${H}-hint`, G = !!I?.labelId, K = n(I, {
20
- id: k,
21
- describedBy: r(G && W, M),
22
- invalid: j
18
+ hint: "PDF, JPG, PNG · hasta 10MB",
19
+ uploading: "Subiendo"
20
+ }, x = ({ multiple: x = !0, accept: S, hint: C, onChange: w, disabled: T = !1, className: E, style: D, labels: O, name: k, id: A, onBlur: j, invalid: M, progress: N, paste: P = !1, "aria-describedby": F, ref: I }) => {
21
+ let L = t("fileUpload", b, O), R = C ?? L.hint, z = i(), [B, V] = m([]), [H, U] = m(!1), W = p(null), G = f(), K = `${G}-title`, q = `${G}-hint`, J = !!z?.labelId, Y = n(z, {
22
+ id: A,
23
+ describedBy: r(J && q, F),
24
+ invalid: M
23
25
  });
24
- u(() => {
25
- let e = V.current;
26
- if (!O || !e || typeof DataTransfer > "u" || L.length === 0 && !e.files?.length) return;
26
+ d(() => {
27
+ let e = W.current;
28
+ if (!k || !e || typeof DataTransfer > "u" || B.length === 0 && !e.files?.length) return;
27
29
  let t = new DataTransfer();
28
- L.forEach((e) => t.items.add(e)), e.files = t.files;
29
- }, [L, O]);
30
- let q = (e) => {
31
- R(e), C?.(e);
32
- }, J = (e) => {
30
+ B.forEach((e) => t.items.add(e)), e.files = t.files;
31
+ }, [B, k]);
32
+ let X = (e) => {
33
+ V(e), w?.(e);
34
+ }, Z = (e) => {
33
35
  let t = Array.from(e ?? []);
34
- t.length !== 0 && q(c(L, t, b));
35
- }, Y = () => V.current?.click();
36
- return /* @__PURE__ */ h("div", {
37
- className: e("kapi-upload-wrap", T),
38
- style: E,
36
+ t.length !== 0 && X(c(B, t, x));
37
+ }, Q = () => W.current?.click();
38
+ return /* @__PURE__ */ g("div", {
39
+ className: e("kapi-upload-wrap", E),
40
+ style: D,
39
41
  children: [
40
- /* @__PURE__ */ h("div", {
41
- ref: N,
42
- id: K.id,
43
- "aria-describedby": K["aria-describedby"],
44
- "aria-invalid": K["aria-invalid"],
45
- "aria-labelledby": G ? r(I?.labelId, U) : void 0,
46
- onBlur: A,
47
- className: `kapi-upload${z ? " is-over" : ""}`,
48
- onClick: Y,
42
+ /* @__PURE__ */ g("div", {
43
+ ref: I,
44
+ id: Y.id,
45
+ "aria-describedby": Y["aria-describedby"],
46
+ "aria-invalid": Y["aria-invalid"],
47
+ "aria-labelledby": J ? r(z?.labelId, K) : void 0,
48
+ onBlur: j,
49
+ className: `kapi-upload${H ? " is-over" : ""}`,
50
+ onClick: Q,
49
51
  onKeyDown: (e) => {
50
- o(e.key) && (e.preventDefault(), Y());
52
+ o(e.key) && (e.preventDefault(), Q());
51
53
  },
52
54
  onDragOver: (e) => {
53
- e.preventDefault(), w || B(!0);
55
+ e.preventDefault(), T || U(!0);
54
56
  },
55
- onDragLeave: () => B(!1),
57
+ onDragLeave: () => U(!1),
56
58
  onDrop: (e) => {
57
- if (e.preventDefault(), B(!1), w) return;
58
- let t = Array.from(e.dataTransfer.files).filter((e) => s(e, x));
59
- t.length !== 0 && q(c(L, t, b));
59
+ if (e.preventDefault(), U(!1), T) return;
60
+ let t = Array.from(e.dataTransfer.files).filter((e) => s(e, S));
61
+ t.length !== 0 && X(c(B, t, x));
62
+ },
63
+ onPaste: (e) => {
64
+ if (!P || T) return;
65
+ let t = Array.from(e.clipboardData?.files ?? []).filter((e) => s(e, S));
66
+ t.length !== 0 && (e.preventDefault(), X(c(B, t, x)));
60
67
  },
61
68
  role: "button",
62
- tabIndex: w ? -1 : 0,
63
- "aria-disabled": w || void 0,
64
- children: [/* @__PURE__ */ m("span", {
69
+ tabIndex: T ? -1 : 0,
70
+ "aria-disabled": T || void 0,
71
+ children: [/* @__PURE__ */ h("span", {
65
72
  className: "kapi-upload__ico",
66
- children: /* @__PURE__ */ m(_, {
73
+ children: /* @__PURE__ */ h(v, {
67
74
  size: 22,
68
75
  strokeWidth: 1.9
69
76
  })
70
- }), /* @__PURE__ */ h("div", {
77
+ }), /* @__PURE__ */ g("div", {
71
78
  className: "kapi-upload__body",
72
- children: [/* @__PURE__ */ h("div", {
73
- id: U,
79
+ children: [/* @__PURE__ */ g("div", {
80
+ id: K,
74
81
  className: "kapi-upload__t",
75
82
  children: [
76
- P.drop,
83
+ L.drop,
77
84
  " ",
78
- /* @__PURE__ */ m("b", { children: P.choose })
85
+ /* @__PURE__ */ h("b", { children: L.choose })
79
86
  ]
80
- }), /* @__PURE__ */ m("div", {
81
- id: W,
87
+ }), /* @__PURE__ */ h("div", {
88
+ id: q,
82
89
  className: "kapi-upload__s",
83
- children: F
90
+ children: R
84
91
  })]
85
92
  })]
86
93
  }),
87
- /* @__PURE__ */ m("input", {
88
- ref: V,
94
+ /* @__PURE__ */ h("input", {
95
+ ref: W,
89
96
  className: "kapi-upload__input",
90
97
  type: "file",
91
98
  hidden: !0,
92
- name: O,
93
- multiple: b,
94
- accept: x,
95
- disabled: w,
99
+ name: k,
100
+ multiple: x,
101
+ accept: S,
102
+ disabled: T,
96
103
  tabIndex: -1,
97
104
  onChange: (e) => {
98
- J(e.target.files), e.target.value = "";
105
+ Z(e.target.files), e.target.value = "";
99
106
  }
100
107
  }),
101
- L.length > 0 && /* @__PURE__ */ m("div", {
108
+ B.length > 0 && /* @__PURE__ */ h("div", {
102
109
  className: "kapi-upload__list",
103
- children: L.map((e, t) => /* @__PURE__ */ h("div", {
110
+ children: B.map((e, t) => /* @__PURE__ */ g("div", {
104
111
  className: "kapi-upload__file",
105
112
  children: [
106
- /* @__PURE__ */ m(g, {
113
+ /* @__PURE__ */ h(_, {
107
114
  className: "kapi-upload__fileico",
108
115
  size: 16,
109
116
  strokeWidth: 1.9
110
117
  }),
111
- /* @__PURE__ */ m("span", {
118
+ /* @__PURE__ */ h("span", {
112
119
  className: "kapi-upload__name",
113
120
  children: e.name
114
121
  }),
115
- /* @__PURE__ */ m("span", {
122
+ /* @__PURE__ */ h("span", {
116
123
  className: "kapi-upload__size",
117
124
  children: a(e.size)
118
125
  }),
119
- /* @__PURE__ */ m("button", {
126
+ /* @__PURE__ */ h("button", {
120
127
  type: "button",
121
- "aria-label": `${P.remove} ${e.name}`,
122
- onClick: () => q(l(L, t)),
123
- children: /* @__PURE__ */ m(v, {
128
+ "aria-label": `${L.remove} ${e.name}`,
129
+ onClick: () => X(l(B, t)),
130
+ children: /* @__PURE__ */ h(y, {
124
131
  size: 15,
125
132
  strokeWidth: 2.2
126
133
  })
134
+ }),
135
+ N?.(e, t) !== void 0 && /* @__PURE__ */ h(u, {
136
+ className: "kapi-upload__progress",
137
+ value: N(e, t) ?? 0,
138
+ size: "sm",
139
+ label: `${L.uploading} ${e.name}`
127
140
  })
128
141
  ]
129
142
  }, `${e.name}-${t}`))
@@ -132,4 +145,4 @@ var y = {
132
145
  });
133
146
  };
134
147
  //#endregion
135
- export { y as DEFAULT_FILE_UPLOAD_LABELS, b as KapiFileUpload };
148
+ export { b as DEFAULT_FILE_UPLOAD_LABELS, x as KapiFileUpload };
@@ -0,0 +1,104 @@
1
+ import type { ChangeEvent, FocusEvent, ReactNode } from "react";
2
+ /**
3
+ * Lo que entrega el `getInputProps(path)` de una librería de formularios (`@mantine/form`,
4
+ * `react-hook-form` vía `register`, Formik…). Se describe por su FORMA, no importando la librería:
5
+ * el paquete no tiene dependencias de runtime y el contrato que importa es público.
6
+ *
7
+ * El `onChange` se escribe `(payload: never) => void` **a propósito, y es lo único raro del tipo**.
8
+ * Es el único tipo de parámetro que acepta un handler de cualquier aridad de un argumento: por
9
+ * contravarianza, el parámetro del destino tiene que ser asignable al del origen, y `never` lo es a
10
+ * todo. Con `unknown` no compilaría un `(e: ChangeEvent) => void`, y con `any` se apagaría el
11
+ * chequeo en vez de resolverlo.
12
+ */
13
+ export type KapiFieldSource<V = unknown> = {
14
+ /** Valor actual del campo (modo controlado). */
15
+ value?: V | undefined;
16
+ /** Valor inicial (modo no controlado de la librería). Se reenvía sólo si no vino `value`. */
17
+ defaultValue?: V | undefined;
18
+ /** Estado del campo cuando la librería lo pidió con `type: "checkbox"`. */
19
+ checked?: boolean | undefined;
20
+ /** Estado inicial de la marca (modo no controlado de la librería). Se reenvía sólo si no vino `checked`. */
21
+ defaultChecked?: boolean | undefined;
22
+ /** Handler de la librería; acepta un evento del DOM o un valor pelado. */
23
+ onChange?: ((payload: never) => void) | undefined;
24
+ /** Handler de salida de foco, para marcar el campo como tocado. */
25
+ onBlur?: ((event: never) => void) | undefined;
26
+ /** Handler de entrada de foco, para marcar el campo como tocado. */
27
+ onFocus?: ((event: never) => void) | undefined;
28
+ /** Motivo por el que el campo está mal, tal como lo entrega la librería. */
29
+ error?: ReactNode;
30
+ /** Nombre del campo, si la librería lo entrega. */
31
+ name?: string | undefined;
32
+ };
33
+ /**
34
+ * Qué clase de control recibe el resultado, porque de eso depende la firma de su `onChange`:
35
+ * `event` para los wrappers de un control nativo (`KapiInput`, `KapiTextarea`), `value` para los
36
+ * que eligen un valor (`KapiSelect`, `KapiDatePicker`, `KapiRating`…) y `checked` para los que son
37
+ * una casilla (`KapiCheckbox`, `KapiSwitch`).
38
+ */
39
+ export type KapiFieldMode = "event" | "value" | "checked";
40
+ /** Props para un control que avisa con el evento del DOM (`KapiInput`, `KapiTextarea`). */
41
+ export type KapiEventFieldProps<V = string> = {
42
+ name?: string | undefined;
43
+ value?: V | undefined;
44
+ defaultValue?: V | undefined;
45
+ onChange?: ((event: ChangeEvent<HTMLInputElement & HTMLTextAreaElement>) => void) | undefined;
46
+ onBlur?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
47
+ onFocus?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
48
+ error?: ReactNode;
49
+ };
50
+ /** Props para un control que avisa con el valor ya tipado (`KapiSelect`, `KapiDatePicker`). */
51
+ export type KapiValueFieldProps<V> = {
52
+ name?: string | undefined;
53
+ value?: V | undefined;
54
+ defaultValue?: V | undefined;
55
+ onChange?: ((value: V) => void) | undefined;
56
+ onBlur?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
57
+ onFocus?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
58
+ error?: ReactNode;
59
+ };
60
+ /**
61
+ * Props para una casilla (`KapiCheckbox`, `KapiSwitch`). Lleva `invalid` y **no** `error`: esos dos
62
+ * controles no dibujan mensaje, así que mandarles el texto lo perdería en silencio. El mensaje va
63
+ * al `KapiField` que los envuelve.
64
+ */
65
+ export type KapiCheckedFieldProps = {
66
+ name?: string | undefined;
67
+ checked?: boolean | undefined;
68
+ defaultChecked?: boolean | undefined;
69
+ onChange?: ((event: ChangeEvent<HTMLInputElement>) => void) | undefined;
70
+ onBlur?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
71
+ onFocus?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
72
+ invalid: boolean;
73
+ };
74
+ /**
75
+ * Ata un campo de una librería de formularios a un control de Kapi.
76
+ *
77
+ * **Para la mayoría de los campos no hace falta**, y conviene decirlo antes que venderlo: el
78
+ * `onChange` que devuelve `getInputProps` ya absorbe tanto un evento del DOM como un valor pelado
79
+ * —por eso el mismo spread anda en el `TextInput` y en el `Select` de la propia Mantine—, así que
80
+ * un `{...form.getInputProps("x")}` sobre un `KapiInput` funciona en runtime. Lo que esta función
81
+ * resuelve son las tres cosas que ese spread sí rompe:
82
+ *
83
+ * 1. **Los tipos.** El `onChange` de la librería no tiene la firma del control de destino, y el
84
+ * `mode` obliga a declarar qué clase de control lo recibe, así que `tsc` caza el cruce (un
85
+ * `"value"` spreadeado sobre un `KapiInput` no compila).
86
+ * 2. **`value` + `defaultValue` juntos.** El modo no controlado devuelve los dos y React avisa que
87
+ * el control pasó de no controlado a controlado. Acá se reenvía uno solo.
88
+ * 3. **Las props de más.** `enhanceGetInputProps` deja claves que el control de Kapi no declara y
89
+ * que ponen `tsc` en rojo al spreadearlas; se descartan.
90
+ *
91
+ * Más `error` → `invalid` en las casillas, que no dibujan mensaje.
92
+ *
93
+ * @example
94
+ * ```tsx
95
+ * <KapiInput label="Correo" {...bindField(form.getInputProps("correo"))} />
96
+ * <KapiSelect label="Área" options={areas} {...bindField<string | null>(form.getInputProps("area"), "value")} />
97
+ * <KapiField label="Términos" error={form.errors.ok}>
98
+ * <KapiCheckbox {...bindField(form.getInputProps("ok", { type: "checkbox" }), "checked")} />
99
+ * </KapiField>
100
+ * ```
101
+ */
102
+ export declare function bindField<V = string>(source: KapiFieldSource<V>, mode?: "event"): KapiEventFieldProps<V>;
103
+ export declare function bindField<V>(source: KapiFieldSource<V>, mode: "value"): KapiValueFieldProps<V>;
104
+ export declare function bindField<V = unknown>(source: KapiFieldSource<V>, mode: "checked"): KapiCheckedFieldProps;
@@ -0,0 +1,25 @@
1
+ import { present as e } from "./inputLogic.js";
2
+ //#region src/components/inputs/formBridgeLogic.ts
3
+ var t = (e, t) => t === void 0 ? {} : { [e]: t };
4
+ function n(n, r = "event") {
5
+ let i = n.onChange, a = {
6
+ ...t("onBlur", n.onBlur),
7
+ ...t("onFocus", n.onFocus),
8
+ ...t("name", n.name)
9
+ };
10
+ if (r === "checked") return {
11
+ ...a,
12
+ ...n.checked === void 0 ? t("defaultChecked", n.defaultChecked) : t("checked", n.checked),
13
+ ...t("onChange", i),
14
+ invalid: e(n.error)
15
+ };
16
+ let o = n.value === void 0 ? t("defaultValue", n.defaultValue) : t("value", n.value);
17
+ return {
18
+ ...a,
19
+ ...o,
20
+ ...t("onChange", i),
21
+ ...t("error", n.error)
22
+ };
23
+ }
24
+ //#endregion
25
+ export { n as bindField };
@@ -124,3 +124,5 @@ export type { KapiFacet, KapiFacetChip, KapiFacetKind, KapiFacetOption, KapiFace
124
124
  export { KapiPropsForm } from "./KapiPropsForm.js";
125
125
  export type { KapiPropsFormField, KapiPropsFormProps, KapiPropsFormValue, KapiPropsFormValues } from "./KapiPropsForm.js";
126
126
  export { initialPropsFormValues, isPropsFormFieldEmpty, missingPropsFormFields, reconcilePropsFormValues } from "./propsFormLogic.js";
127
+ export { bindField } from "./formBridgeLogic.js";
128
+ export type { KapiCheckedFieldProps, KapiEventFieldProps, KapiFieldMode, KapiFieldSource, KapiValueFieldProps } from "./formBridgeLogic.js";