@kapiuara/ui 0.17.0 → 0.19.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 (94) hide show
  1. package/README.md +259 -9
  2. package/dist/components/data/KapiDataTable.d.ts +12 -2
  3. package/dist/components/data/KapiDataTable.js +78 -76
  4. package/dist/components/data/KapiScatterChart.d.ts +56 -0
  5. package/dist/components/data/KapiScatterChart.js +90 -0
  6. package/dist/components/data/KapiTable.d.ts +2 -2
  7. package/dist/components/data/KapiTable.js +229 -227
  8. package/dist/components/data/chartFrame.d.ts +20 -2
  9. package/dist/components/data/chartFrame.js +33 -24
  10. package/dist/components/data/index.d.ts +5 -1
  11. package/dist/components/data/scatterLogic.d.ts +56 -0
  12. package/dist/components/data/scatterLogic.js +43 -0
  13. package/dist/components/data/tableTypes.d.ts +37 -0
  14. package/dist/components/data/useRowKeyWarning.d.ts +9 -3
  15. package/dist/components/data/useRowKeyWarning.js +7 -7
  16. package/dist/components/data/useTableSelection.d.ts +3 -2
  17. package/dist/components/data/useTableSelection.js +3 -3
  18. package/dist/components/display/KapiAvatarGroup.d.ts +14 -2
  19. package/dist/components/display/KapiAvatarGroup.js +25 -23
  20. package/dist/components/display/KapiTimeline.d.ts +14 -0
  21. package/dist/components/display/KapiTimeline.js +28 -21
  22. package/dist/components/display/avatarGroupSlots.d.ts +6 -0
  23. package/dist/components/display/avatarGroupSlots.js +9 -0
  24. package/dist/components/display/index.d.ts +1 -1
  25. package/dist/components/feedback/KapiAlert.d.ts +6 -1
  26. package/dist/components/feedback/KapiAlert.js +45 -44
  27. package/dist/components/feedback/KapiCountdown.d.ts +12 -1
  28. package/dist/components/feedback/KapiCountdown.js +34 -31
  29. package/dist/components/feedback/KapiEmpty.d.ts +6 -1
  30. package/dist/components/feedback/KapiEmpty.js +20 -18
  31. package/dist/components/feedback/KapiProgress.js +1 -1
  32. package/dist/components/feedback/KapiSpinner.d.ts +48 -0
  33. package/dist/components/feedback/KapiSpinner.js +27 -0
  34. package/dist/components/feedback/KapiToastContainer.js +1 -1
  35. package/dist/components/feedback/KapiTour.js +1 -1
  36. package/dist/components/feedback/alertSlots.d.ts +9 -0
  37. package/dist/components/feedback/alertSlots.js +12 -0
  38. package/dist/components/feedback/countdownSlots.d.ts +6 -0
  39. package/dist/components/feedback/countdownSlots.js +9 -0
  40. package/dist/components/feedback/emptySlots.d.ts +8 -0
  41. package/dist/components/feedback/emptySlots.js +11 -0
  42. package/dist/components/feedback/index.d.ts +5 -3
  43. package/dist/components/inputs/KapiFileUpload.d.ts +14 -1
  44. package/dist/components/inputs/KapiFileUpload.js +80 -67
  45. package/dist/components/inputs/formBridgeLogic.d.ts +104 -0
  46. package/dist/components/inputs/formBridgeLogic.js +25 -0
  47. package/dist/components/inputs/index.d.ts +2 -0
  48. package/dist/components/locale/labelRegistry.d.ts +8 -0
  49. package/dist/components/navigation/KapiSteps.d.ts +26 -5
  50. package/dist/components/navigation/KapiSteps.js +55 -43
  51. package/dist/components/overlays/KapiImageViewer.d.ts +63 -0
  52. package/dist/components/overlays/KapiImageViewer.js +106 -0
  53. package/dist/components/overlays/KapiShortcutsHelp.d.ts +53 -0
  54. package/dist/components/overlays/KapiShortcutsHelp.js +55 -0
  55. package/dist/components/overlays/KapiTooltip.d.ts +49 -10
  56. package/dist/components/overlays/KapiTooltip.js +110 -58
  57. package/dist/components/overlays/KapiViewport.d.ts +63 -0
  58. package/dist/components/overlays/KapiViewport.js +195 -0
  59. package/dist/components/overlays/index.d.ts +8 -0
  60. package/dist/components/overlays/shortcutsHelpSlots.d.ts +9 -0
  61. package/dist/components/overlays/shortcutsHelpSlots.js +12 -0
  62. package/dist/components/overlays/viewportLogic.d.ts +73 -0
  63. package/dist/components/overlays/viewportLogic.js +54 -0
  64. package/dist/components/slotCatalog.d.ts +33 -0
  65. package/dist/components/slotCatalog.js +30 -20
  66. package/dist/css/base.css +1 -1
  67. package/dist/css/components/data/KapiScatterChart.css +1 -0
  68. package/dist/css/components/display/display.css +1 -1
  69. package/dist/css/components/inputs/KapiFileUpload.css +1 -1
  70. package/dist/css/components/navigation/KapiSteps.css +1 -1
  71. package/dist/css/components/overlays/KapiViewport.css +1 -0
  72. package/dist/css/components/overlays/overlays.css +1 -1
  73. package/dist/hooks/elementSizeLogic.d.ts +15 -0
  74. package/dist/hooks/elementSizeLogic.js +7 -0
  75. package/dist/hooks/hotkeyLogic.d.ts +9 -0
  76. package/dist/hooks/hotkeyLogic.js +16 -15
  77. package/dist/hooks/hotkeyRegistry.d.ts +44 -0
  78. package/dist/hooks/hotkeyRegistry.js +32 -0
  79. package/dist/hooks/index.d.ts +10 -0
  80. package/dist/hooks/themeDeriveLogic.js +2 -2
  81. package/dist/hooks/useDebouncedValue.d.ts +30 -0
  82. package/dist/hooks/useDebouncedValue.js +26 -0
  83. package/dist/hooks/useDisclosure.d.ts +39 -0
  84. package/dist/hooks/useDisclosure.js +35 -0
  85. package/dist/hooks/useElementSize.d.ts +27 -0
  86. package/dist/hooks/useElementSize.js +29 -0
  87. package/dist/hooks/useHotkey.d.ts +8 -0
  88. package/dist/hooks/useHotkey.js +27 -15
  89. package/dist/index.js +201 -188
  90. package/dist/kapi.css +1 -1
  91. package/dist/kapi.layered.css +1 -1
  92. package/dist/logic.d.ts +4 -0
  93. package/dist/logic.js +33 -29
  94. package/package.json +2 -2
@@ -46,7 +46,7 @@ export type KapiChartView = "chart" | "table";
46
46
  * El prefijo de clases del gráfico concreto. Es una unión y no un `string` porque un typo acá
47
47
  * produce marcado sin estilo que nada detecta: el CSS simplemente no engancha.
48
48
  */
49
- export type KapiChartBlock = "kapi-barchart" | "kapi-linechart";
49
+ export type KapiChartBlock = "kapi-barchart" | "kapi-linechart" | "kapi-scatterchart";
50
50
  /** Lo mínimo que la cáscara necesita saber de una serie para la leyenda y la tabla. */
51
51
  export type KapiChartSeriesInfo = {
52
52
  /** Id estable; clave de React y de la fila. */
@@ -54,6 +54,17 @@ export type KapiChartSeriesInfo = {
54
54
  /** Nombre en la leyenda y en la tabla. */
55
55
  label: string;
56
56
  };
57
+ /** Una fila de la tabla cuando el dato no es categoría × serie (ver `tableRows`). */
58
+ export type KapiChartTableRow = {
59
+ /** Clave de React. */
60
+ id: string;
61
+ /** Índice de la serie, para pintar su muestra de color. */
62
+ slot: number;
63
+ /** Nombre de la fila (la primera celda, en `<th scope="row">`). */
64
+ header: string;
65
+ /** Celdas ya formateadas, en el orden de `categories`. */
66
+ cells: readonly string[];
67
+ };
57
68
  export type KapiChartFrameProps = {
58
69
  /** Título visible; sin él hace falta `aria-label` en la raíz. */
59
70
  title?: ReactNode | undefined;
@@ -65,6 +76,13 @@ export type KapiChartFrameProps = {
65
76
  categories: readonly string[];
66
77
  /** El valor de una celda, por índice de serie y de categoría. */
67
78
  valueAt: (seriesIndex: number, categoryIndex: number) => number;
79
+ /**
80
+ * Filas propias de la tabla, para un gráfico cuyo dato **no** es categoría × serie. La dispersión
81
+ * es ese caso: cada punto tiene DOS valores (x, y) y no hay una celda por categoría, así que sin
82
+ * esto su tabla tendría que tirar una de las dos coordenadas. Con `tableRows`, `categories` pasa a
83
+ * ser el encabezado de las columnas y cada fila trae su propio nombre y sus celdas ya formateadas.
84
+ */
85
+ tableRows?: readonly KapiChartTableRow[] | undefined;
68
86
  /** La unidad del valor, aplicada a las celdas de la tabla. Ver `KapiChartUnit`. */
69
87
  unit?: KapiChartUnit | undefined;
70
88
  /** Vista mostrada. */
@@ -107,6 +125,6 @@ export declare const ChartSwatch: ({ block, slot }: {
107
125
  block: KapiChartBlock;
108
126
  slot: number;
109
127
  }) => import("react").JSX.Element;
110
- export declare const KapiChartFrame: ({ title, titleId, series, categories, valueAt, unit, view, onViewChange, text, block, children }: KapiChartFrameProps) => import("react").JSX.Element;
128
+ export declare const KapiChartFrame: ({ title, titleId, series, categories, valueAt, tableRows, unit, view, onViewChange, text, block, children }: KapiChartFrameProps) => import("react").JSX.Element;
111
129
  /** El `useId` de la cáscara, para que el gráfico ate su título sin repetir el hook. */
112
130
  export declare const useChartTitleId: () => string;
@@ -29,60 +29,69 @@ var l = {
29
29
  }), h = ({ block: e, slot: t }) => /* @__PURE__ */ s("span", {
30
30
  className: `${e}__swatch`,
31
31
  style: m({ slot: t })
32
- }), g = ({ title: t, titleId: n, series: a, categories: l, valueAt: u, unit: f, view: p, onViewChange: m, text: g, block: _, children: v }) => {
33
- let y = e(), b = a.length === 0 || l.length === 0;
32
+ }), g = ({ title: t, titleId: n, series: a, categories: l, valueAt: u, tableRows: f, unit: p, view: m, onViewChange: g, text: _, block: v, children: y }) => {
33
+ let b = e(), x = a.length === 0 || l.length === 0;
34
34
  return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ c("div", {
35
- className: `${_}__head`,
35
+ className: `${v}__head`,
36
36
  children: [t ? /* @__PURE__ */ s("div", {
37
- className: `${_}__title`,
37
+ className: `${v}__title`,
38
38
  id: n,
39
39
  children: t
40
40
  }) : null, /* @__PURE__ */ s(i, {
41
- "aria-label": g.view,
41
+ "aria-label": _.view,
42
42
  items: [{
43
43
  id: "chart",
44
- label: g.chartView
44
+ label: _.chartView
45
45
  }, {
46
46
  id: "table",
47
- label: g.tableView
47
+ label: _.tableView
48
48
  }],
49
- value: p,
50
- onChange: m
49
+ value: m,
50
+ onChange: g
51
51
  })]
52
- }), b ? /* @__PURE__ */ s("p", {
53
- className: `${_}__empty kapi-muted`,
54
- children: g.empty
55
- }) : p === "table" ? /* @__PURE__ */ s("div", {
56
- className: `${_}__tablewrap`,
52
+ }), x ? /* @__PURE__ */ s("p", {
53
+ className: `${v}__empty kapi-muted`,
54
+ children: _.empty
55
+ }) : m === "table" ? /* @__PURE__ */ s("div", {
56
+ className: `${v}__tablewrap`,
57
57
  children: /* @__PURE__ */ c("table", {
58
- className: `${_}__table`,
58
+ className: `${v}__table`,
59
59
  children: [/* @__PURE__ */ s("thead", { children: /* @__PURE__ */ c("tr", { children: [/* @__PURE__ */ s("th", {
60
60
  scope: "col",
61
- children: g.series
61
+ children: _.series
62
62
  }), l.map((e, t) => /* @__PURE__ */ s("th", {
63
63
  scope: "col",
64
64
  children: e
65
- }, `${e}-${t}`))] }) }), /* @__PURE__ */ s("tbody", { children: a.map((e, t) => /* @__PURE__ */ c("tr", { children: [/* @__PURE__ */ s("th", {
65
+ }, `${e}-${t}`))] }) }), /* @__PURE__ */ s("tbody", { children: f ? f.map((e) => /* @__PURE__ */ c("tr", { children: [/* @__PURE__ */ s("th", {
66
66
  scope: "row",
67
67
  children: /* @__PURE__ */ c("span", {
68
- className: `${_}__serie`,
68
+ className: `${v}__serie`,
69
69
  children: [/* @__PURE__ */ s(h, {
70
- block: _,
70
+ block: v,
71
+ slot: e.slot
72
+ }), e.header]
73
+ })
74
+ }), e.cells.map((e, t) => /* @__PURE__ */ s("td", { children: e }, t))] }, e.id)) : a.map((e, t) => /* @__PURE__ */ c("tr", { children: [/* @__PURE__ */ s("th", {
75
+ scope: "row",
76
+ children: /* @__PURE__ */ c("span", {
77
+ className: `${v}__serie`,
78
+ children: [/* @__PURE__ */ s(h, {
79
+ block: v,
71
80
  slot: t
72
81
  }), e.label]
73
82
  })
74
- }), l.map((e, n) => /* @__PURE__ */ s("td", { children: d(r(u(t, n), y), f) }, `${e}-${n}`))] }, e.id)) })]
83
+ }), l.map((e, n) => /* @__PURE__ */ s("td", { children: d(r(u(t, n), b), p) }, `${e}-${n}`))] }, e.id)) })]
75
84
  })
76
85
  }) : /* @__PURE__ */ c(o, { children: [a.length > 1 ? /* @__PURE__ */ s("ul", {
77
- className: `${_}__legend`,
86
+ className: `${v}__legend`,
78
87
  children: a.map((e, t) => /* @__PURE__ */ c("li", {
79
- className: `${_}__legenditem`,
88
+ className: `${v}__legenditem`,
80
89
  children: [/* @__PURE__ */ s(h, {
81
- block: _,
90
+ block: v,
82
91
  slot: t
83
92
  }), e.label]
84
93
  }, e.id))
85
- }) : null, v] })] });
94
+ }) : null, y] })] });
86
95
  }, _ = () => a();
87
96
  //#endregion
88
97
  export { h as ChartSwatch, l as DEFAULT_CHART_LABELS, g as KapiChartFrame, u as chartSummary, m as chartVars, f as useChartLabels, _ as useChartTitleId, p as useChartView, d as withChartUnit };
@@ -56,7 +56,7 @@ export { KapiSheet, KapiSheetHead, KapiSheetBody, KapiSheetFoot, KapiSheetRow, K
56
56
  export type { KapiSheetProps, KapiSheetHeadProps, KapiSheetBodyProps, KapiSheetFootProps, KapiSheetRowProps, KapiSheetCellProps, KapiSheetHeaderCellProps } from "./KapiSheet.js";
57
57
  export { KapiDataTable } from "./KapiDataTable.js";
58
58
  export type { KapiDataTableProps } from "./KapiDataTable.js";
59
- export type { KapiTableCellValue, KapiTableColumn, KapiTableAction, KapiTableActionHandler, KapiTableActionItem, KapiTableClientPagination, KapiTableContext, KapiTableCsvOptions, KapiTableDataset, KapiTableFooterCell, KapiTableFooterRow, KapiTableKey, KapiTableKeyField, KapiTableLabels, KapiTablePagination, KapiTableClassNames, KapiTableProps, KapiTableRowAttributes, KapiTableRowHooks, KapiTableSelectionPreset, KapiTableSortDirection, KapiTableSortState, KapiTableSortValue } from "./KapiTable.js";
59
+ export type { KapiTableCellValue, KapiTableColumn, KapiTableAction, KapiTableActionHandler, KapiTableActionItem, KapiTableClientPagination, KapiTableContext, KapiTableCsvOptions, KapiTableDataset, KapiTableFooterCell, KapiTableFooterRow, KapiTableKey, KapiTableGetRowKey, KapiTableKeyField, KapiTableLabels, KapiTablePagination, KapiTableClassNames, KapiTableProps, KapiTableRowAttributes, KapiTableRowHooks, KapiTableSelectionPreset, KapiTableSortDirection, KapiTableSortState, KapiTableSortValue } from "./KapiTable.js";
60
60
  export {
61
61
  /** @deprecated Interno; usa `KapiTable` en su lugar. Se quita en 1.0. */
62
62
  datasetNoticeState,
@@ -108,3 +108,7 @@ rowMatchesFilter,
108
108
  /** @deprecated Interno, se quita en 1.0. */
109
109
  filterTerms, normalizeFilterText, buildCsv, csvCell } from "./tableLogic.js";
110
110
  export type { KapiTableColumnPinning, KapiTableHeaderAction, KapiTableSticky, KapiTableStickySide, KapiTableColumnVisibility, KapiTableColumnWidths, KapiTableFilterState } from "./tableLogic.js";
111
+ export { KapiScatterChart } from "./KapiScatterChart.js";
112
+ export type { KapiScatterChartProps, KapiScatterSeries, KapiScatterPoint } from "./KapiScatterChart.js";
113
+ export { scatterAxis, scatterInside, scatterPosition, scatterTickLabel } from "./scatterLogic.js";
114
+ export type { KapiScatterAxis } from "./scatterLogic.js";
@@ -0,0 +1,56 @@
1
+ /** Un punto de dispersión: dos valores numéricos y una etiqueta opcional. */
2
+ export type KapiScatterPoint = {
3
+ /** Valor sobre el eje horizontal. */
4
+ x: number;
5
+ /** Valor sobre el eje vertical. */
6
+ y: number;
7
+ /**
8
+ * Nombre del punto: es la cabecera de su fila en la tabla y abre su descripción accesible. Sin
9
+ * él, la fila se llama con el nombre de la serie y la posición del punto (`Ventas 3`).
10
+ */
11
+ label?: string | undefined;
12
+ };
13
+ /** Eje de dispersión: su ventana y las marcas de adentro, en unidades de dato. */
14
+ export type KapiScatterAxis = {
15
+ /** Valor del borde inferior. */
16
+ min: number;
17
+ /** Valor del borde superior. */
18
+ max: number;
19
+ /** Marcas, de `min` a `max` inclusive. */
20
+ ticks: readonly number[];
21
+ };
22
+ /**
23
+ * Ventana redondeada que cubre `values`, con a lo sumo `tickCount` tramos.
24
+ *
25
+ * **No es `barScale` y no debe serlo.** El eje de un gráfico de barras tiene que arrancar en CERO,
26
+ * porque el largo de la barra ES el valor y truncar el eje miente sobre las proporciones. El de una
27
+ * dispersión es una ventana sobre los datos: forzarlo a cero aplastaría la nube contra una esquina
28
+ * cuando los valores están lejos del origen (sueldos, años, temperaturas). Son dos reglas distintas
29
+ * sobre el mismo problema, no la misma regla escrita dos veces.
30
+ */
31
+ export declare const scatterAxis: (values: readonly number[], tickCount?: number) => KapiScatterAxis;
32
+ /**
33
+ * Posición de un punto en porcentaje de la ventana (0 a 100 en los dos ejes). `cy` se mide **desde
34
+ * arriba**, que es la convención de la que vienen los nombres `cx`/`cy`; el gráfico no usa SVG,
35
+ * posiciona HTML desde abajo y da vuelta el valor al aplicarlo (`y: 100 - cy`).
36
+ *
37
+ * Un eje de ancho cero devuelve el centro en vez de dividir por cero.
38
+ */
39
+ export declare const scatterPosition: (point: KapiScatterPoint, x: KapiScatterAxis, y: KapiScatterAxis) => {
40
+ cx: number;
41
+ cy: number;
42
+ };
43
+ /**
44
+ * ¿El punto cae dentro de la ventana? Sirve para no dibujar un punto pisado contra el borde, donde
45
+ * mentiría sobre su valor.
46
+ *
47
+ * Qué filtra HOY en `KapiScatterChart`, que es lo único que lo usa: sólo los puntos **no finitos**
48
+ * (`NaN`, infinitos), porque toda comparación con ellos es falsa. Un punto finito no puede quedar
49
+ * afuera, porque los dos ejes salen de `scatterAxis` sobre esos mismos puntos y esa función
50
+ * redondea la ventana hacia afuera. El componente no acepta ejes fijos del consumidor; la función
51
+ * es pública y sí sirve para eso, pero esa combinación todavía no existe acá. Ojo con el filtro:
52
+ * un punto no finito desaparece del dibujo y la tabla lo sigue listando.
53
+ */
54
+ export declare const scatterInside: (point: KapiScatterPoint, x: KapiScatterAxis, y: KapiScatterAxis) => boolean;
55
+ /** Texto corto de una marca: entero si lo es, si no con los decimales que haga falta (hasta 2). */
56
+ export declare const scatterTickLabel: (value: number) => string;
@@ -0,0 +1,43 @@
1
+ //#region src/components/data/scatterLogic.ts
2
+ var e = (e, t = 0) => Number.isFinite(e) ? e : t, t = (e, t) => {
3
+ let n = e / Math.max(1, t), r = 10 ** Math.floor(Math.log10(n)), i = n / r;
4
+ return (i <= 1 ? 1 : i <= 2 ? 2 : i <= 5 ? 5 : 10) * r;
5
+ }, n = (n, r = 4) => {
6
+ let i = Math.max(1, Math.floor(e(r, 4))), a = n.filter((e) => Number.isFinite(e));
7
+ if (a.length === 0) return {
8
+ min: 0,
9
+ max: 1,
10
+ ticks: [0, 1]
11
+ };
12
+ let o = a[0], s = o;
13
+ for (let e of a) e < o && (o = e), e > s && (s = e);
14
+ if (o === s) {
15
+ let e = Math.abs(o) > 0 ? Math.abs(o) / 10 : 1;
16
+ o -= e, s += e;
17
+ }
18
+ let c = t(s - o, i);
19
+ if (!(c > 0) || !Number.isFinite(c)) return {
20
+ min: 0,
21
+ max: 1,
22
+ ticks: [0, 1]
23
+ };
24
+ let l = Math.floor(o / c) * c, u = Math.ceil(s / c) * c, d = Math.max(1, Math.round((u - l) / c)), f = [...new Set(Array.from({ length: d + 1 }, (e, t) => Number((l + t * c).toPrecision(12))))];
25
+ return {
26
+ min: Number(l.toPrecision(12)),
27
+ max: Number(u.toPrecision(12)),
28
+ ticks: f
29
+ };
30
+ }, r = (e, t, n) => {
31
+ let r = t.max - t.min, i = n.max - n.min, a = r === 0 ? 50 : (e.x - t.min) / r * 100, o = i === 0 ? 50 : 100 - (e.y - n.min) / i * 100;
32
+ return {
33
+ cx: Number(a.toFixed(3)),
34
+ cy: Number(o.toFixed(3))
35
+ };
36
+ }, i = (e, t, n) => e.x >= t.min && e.x <= t.max && e.y >= n.min && e.y <= n.max, a = (e) => {
37
+ if (!Number.isFinite(e)) return "";
38
+ if (Number.isInteger(e)) return String(e);
39
+ let t = Math.abs(e);
40
+ return e.toFixed(t < 1 ? 2 : 1);
41
+ };
42
+ //#endregion
43
+ export { n as scatterAxis, i as scatterInside, r as scatterPosition, a as scatterTickLabel };
@@ -336,6 +336,33 @@ export type KapiTableKey = string | number;
336
336
  export type KapiTableKeyField<T> = {
337
337
  [P in keyof T]-?: T[P] extends KapiTableKey ? P : never;
338
338
  }[keyof T];
339
+ /**
340
+ * Salida de escape de `keyField`: la clave de una fila calculada, en vez de leída de una propiedad.
341
+ *
342
+ * Por qué hace falta. `keyField` se tipa con `KapiTableKeyField<T>`, que es un tipo condicional
343
+ * sobre `T`. Eso está bien y se queda: con un `T` concreto impide elegir una columna que no sirve
344
+ * como id. Pero un **wrapper genérico** —`const MiTabla = <T,>(props) => <KapiTable<T> … />`, que es
345
+ * lo primero que hace cualquier app para fijar sus defaults— tiene un `T` sin resolver, y entonces
346
+ * TypeScript no puede evaluar el condicional y rechaza hasta un `keyof T & string`. El componente
347
+ * quedaba inenvolvible, que para un design system es un problema de uso, no de tipos.
348
+ *
349
+ * Esta prop no depende de ningún condicional sobre `T`, así que atraviesa un wrapper genérico sin
350
+ * pelear. Y sirve para el otro caso que `keyField` no puede cubrir: una fila cuyo id es opcional o
351
+ * `null`, donde el tipo colapsa a `never` —con razón, porque una clave vacía rompe la selección, la
352
+ * expansión y las keys de React—, pero el consumidor sí sabe derivar una clave estable.
353
+ *
354
+ * **No recibe el índice, y es a propósito.** La primera versión lo pasaba, y eso invitaba a una clave
355
+ * posicional que está rota de dos maneras. La primera, medida: el índice que cada llamador tiene a
356
+ * mano es de una lista DISTINTA —la filtrada por `isRowSelectable` en la selección, la del preset en
357
+ * los presets, la de la página al dibujar, la cruda en el aviso—, así que «seleccionar todo» elegía
358
+ * ids que las filas dibujadas no tenían. La segunda es de fondo: una clave por posición deja de
359
+ * identificar a la fila apenas se ordena, se filtra o se pagina, que es exactamente para lo que una
360
+ * tabla existe. Si el id hay que derivarlo, se deriva de los DATOS de la fila.
361
+ *
362
+ * Lo que NO afloja: el aviso de desarrollo de claves repetidas o vacías mide las claves que la tabla
363
+ * usa de verdad, vengan de donde vengan. La salida es de tipos, no de seguridad.
364
+ */
365
+ export type KapiTableGetRowKey<T> = (row: T) => KapiTableKey;
339
366
  export type KapiTableProps<T, K extends KapiTableKeyField<T> = KapiTableKeyField<T>> = KapiRootProps<HTMLDivElement> & {
340
367
  /** Definición de columnas (clave, encabezado, render, orden, filtro, ancho…). */
341
368
  columns: ReadonlyArray<KapiTableColumn<T>>;
@@ -343,6 +370,16 @@ export type KapiTableProps<T, K extends KapiTableKeyField<T> = KapiTableKeyField
343
370
  rows: ReadonlyArray<T>;
344
371
  /** Propiedad con el id único de la fila. Default `"id"`. */
345
372
  keyField?: K | undefined;
373
+ /**
374
+ * Calcula la clave de cada fila, en vez de leerla de una propiedad. Gana sobre `keyField`.
375
+ *
376
+ * Es la salida para un wrapper genérico —donde `T` no está resuelto y el tipo de `keyField` no se
377
+ * puede evaluar— y para una fila cuyo id es opcional o `null`. Deriva la clave de los DATOS de la
378
+ * fila: no recibe el índice a propósito, porque una clave por posición deja de identificar a la
379
+ * fila al ordenar o filtrar. El aviso de claves repetidas o vacías sigue midiendo las que salen
380
+ * de acá.
381
+ */
382
+ getRowKey?: KapiTableGetRowKey<T> | undefined;
346
383
  /** Alto máximo del área con scroll. Se ignora con `fill`. */
347
384
  maxHeight?: CSSProperties["maxHeight"];
348
385
  /**
@@ -1,10 +1,16 @@
1
1
  /** Qué falla en las claves de fila: alguna sin valor en `keyField`, o dos filas con el mismo. */
2
2
  export type RowKeyProblem = "missing" | "duplicate";
3
- /** Primer problema de las claves de `rows` según `keyField`, o `null` si cada fila tiene una propia. */
4
- export declare const rowKeyProblem: <T>(rows: readonly T[], keyField: keyof T) => RowKeyProblem | null;
3
+ /**
4
+ * Primer problema de las claves de `rows`, o `null` si cada fila tiene una propia.
5
+ *
6
+ * Recibe cómo se saca la clave, no de qué campo: así mide las claves que la tabla usa DE VERDAD,
7
+ * vengan de `keyField` o de un `getRowKey` del consumidor. La salida de escape de tipos no afloja
8
+ * este aviso.
9
+ */
10
+ export declare const rowKeyProblem: <T>(rows: readonly T[], clave: (row: T) => unknown) => RowKeyProblem | null;
5
11
  /**
6
12
  * Aviso de desarrollo (una vez por problema y por instancia): filas sin clave propia. Con claves
7
13
  * repetidas o vacías, la selección, la expansión y las keys de React se mezclan entre filas (un clic
8
14
  * selecciona todas) y nada más lo señala. En producción no hace nada.
9
15
  */
10
- export declare const useRowKeyWarning: <T>(name: string, rows: readonly T[], keyField: keyof T) => void;
16
+ export declare const useRowKeyWarning: <T>(name: string, rows: readonly T[], clave: (row: T) => unknown, origen: string) => void;
@@ -4,7 +4,7 @@ import { useEffect as e, useRef as t } from "react";
4
4
  var n = (e, t) => {
5
5
  let n = /* @__PURE__ */ new Set();
6
6
  for (let r of e) {
7
- let e = r[t];
7
+ let e = t(r);
8
8
  if (e == null) return "missing";
9
9
  if (n.has(e)) return "duplicate";
10
10
  n.add(e);
@@ -13,16 +13,16 @@ var n = (e, t) => {
13
13
  }, r = {
14
14
  missing: "hay filas sin valor en",
15
15
  duplicate: "hay filas con el mismo valor en"
16
- }, i = (i, a, o) => {
17
- let s = t(null);
18
- e(() => {
16
+ }, i = (i, a, o, s) => {
17
+ let c = t(null), l = t(o);
18
+ l.current = o, e(() => {
19
19
  if (process.env.NODE_ENV === "production") return;
20
- let e = n(a, o);
21
- e && s.current !== e && (s.current = e, console.warn(`${i}: ${r[e]} keyField ("${String(o)}"). La selección, la expansión y las keys de React se mezclan entre filas. Pasa keyField con el campo que identifica a cada fila.`));
20
+ let e = n(a, l.current);
21
+ e && c.current !== e && (c.current = e, console.warn(`${i}: ${r[e]} ${s}. La selección, la expansión y las keys de React se mezclan entre filas. Pasa keyField con el campo que identifica a cada fila, o getRowKey si la clave hay que calcularla.`));
22
22
  }, [
23
23
  i,
24
24
  a,
25
- o
25
+ s
26
26
  ]);
27
27
  };
28
28
  //#endregion
@@ -4,7 +4,8 @@ import type { KapiTableClassNames, KapiTableDataset, KapiTableKeyField, KapiTabl
4
4
  type TableSelectionInput<T, K extends KapiTableKeyField<T>> = {
5
5
  /** Filas que la tabla muestra (ya filtradas y ordenadas). */
6
6
  rows: ReadonlyArray<T>;
7
- keyField: K;
7
+ /** Cómo sale la clave de una fila: `getRowKey` del consumidor, o la propiedad `keyField`. */
8
+ claveDe: (row: T) => unknown;
8
9
  selectable: boolean;
9
10
  selectedIds: ReadonlyArray<T[K]> | undefined;
10
11
  defaultSelectedIds: ReadonlyArray<T[K]> | undefined;
@@ -17,7 +18,7 @@ type TableSelectionInput<T, K extends KapiTableKeyField<T>> = {
17
18
  loadingLabel: string;
18
19
  locale: string | undefined;
19
20
  };
20
- export declare const useTableSelection: <T, K extends KapiTableKeyField<T>>({ rows, keyField, selectable, selectedIds, defaultSelectedIds, onSelectedIdsChange, isRowSelectable, selectionPresets, rangeSelect, dataset, loadingLabel, locale }: TableSelectionInput<T, K>) => {
21
+ export declare const useTableSelection: <T, K extends KapiTableKeyField<T>>({ rows, claveDe, selectable, selectedIds, defaultSelectedIds, onSelectedIdsChange, isRowSelectable, selectionPresets, rangeSelect, dataset, loadingLabel, locale }: TableSelectionInput<T, K>) => {
21
22
  sel: ReadonlySet<T[K]>;
22
23
  commitSelection: (next: Set<T[K]>) => void;
23
24
  clearSelection: () => void;
@@ -10,10 +10,10 @@ import { useMemo as d } from "react";
10
10
  import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
11
11
  import { Loader2 as h } from "lucide-react";
12
12
  //#region src/components/data/useTableSelection.tsx
13
- var g = [], _ = ({ rows: n, keyField: o, selectable: s, selectedIds: c, defaultSelectedIds: u, onSelectedIdsChange: _, isRowSelectable: v, selectionPresets: y, rangeSelect: b, dataset: x, loadingLabel: S, locale: C }) => {
14
- let [w, T] = e(c, u ?? g, _ && ((e) => _([...e]))), E = d(() => new Set(w), [w]), D = (e) => T([...e]), O = () => D(/* @__PURE__ */ new Set()), k = [...E], A = t(), j = s && y !== void 0 && y.length > 0, M = d(() => n.filter((e) => !v || v(e)), [n, v]), N = d(() => M.map((e) => e[o]), [M, o]), P = d(() => j && y ? y.map((e) => ({
13
+ var g = [], _ = ({ rows: n, claveDe: o, selectable: s, selectedIds: c, defaultSelectedIds: u, onSelectedIdsChange: _, isRowSelectable: v, selectionPresets: y, rangeSelect: b, dataset: x, loadingLabel: S, locale: C }) => {
14
+ let [w, T] = e(c, u ?? g, _ && ((e) => _([...e]))), E = d(() => new Set(w), [w]), D = (e) => T([...e]), O = () => D(/* @__PURE__ */ new Set()), k = [...E], A = t(), j = s && y !== void 0 && y.length > 0, M = d(() => n.filter((e) => !v || v(e)), [n, v]), N = d(() => M.map((e) => o(e)), [M, o]), P = d(() => j && y ? y.map((e) => ({
15
15
  preset: e,
16
- matching: e.match === void 0 ? [] : M.filter(e.match).map((e) => e[o])
16
+ matching: e.match === void 0 ? [] : M.filter(e.match).map((e) => o(e))
17
17
  })) : [], [
18
18
  j,
19
19
  y,
@@ -1,6 +1,9 @@
1
1
  import type { HTMLAttributes, Ref } from "react";
2
2
  import { type KapiAvatarSize, type KapiAvatarTone } from "./KapiAvatar.js";
3
3
  import type { KapiLabelsOverride } from "../labelsLogic.js";
4
+ import type { KapiClassNames } from "../slotCatalog.js";
5
+ /** Partes de `KapiAvatarGroup` que acepta `classNames` (`root`, `item`, `more`). */
6
+ export type KapiAvatarGroupClassNames = KapiClassNames<"avatarGroup">;
4
7
  /** Textos de `KapiAvatarGroup`; se pisan con `labels` o el `KapiLocaleProvider`. */
5
8
  export type KapiAvatarGroupLabels = {
6
9
  /** Nombre accesible del "+N"; `{n}` = personas que no se muestran. */
@@ -19,7 +22,14 @@ export type KapiAvatarGroupItem = {
19
22
  /** Nombre anterior de `tone`, deprecado. @deprecated Usar `tone` (mismos valores). */
20
23
  color?: KapiAvatarTone | undefined;
21
24
  };
22
- export type KapiAvatarGroupProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
25
+ /**
26
+ * `role` se omite porque el componente lo fija: la raíz es siempre `role="group"`. Antes el
27
+ * `{...rest}` iba ÚLTIMO y un `role` del consumidor ganaba; ahora va primero —como pide la
28
+ * convención de passthrough, para que rol, ARIA y handlers propios no se pisen— así que un
29
+ * `role` pasado se descartaría EN SILENCIO. Omitirlo lo convierte en un error de compilación,
30
+ * que es lo que ya hace `KapiAlert` con el suyo.
31
+ */
32
+ export type KapiAvatarGroupProps = Omit<HTMLAttributes<HTMLDivElement>, "children" | "role"> & {
23
33
  /** Ref al `<div>` raíz del grupo. */
24
34
  ref?: Ref<HTMLDivElement> | undefined;
25
35
  /** Personas a mostrar, en orden; las que pasan de `max` se resumen en "+N". */
@@ -30,6 +40,8 @@ export type KapiAvatarGroupProps = Omit<HTMLAttributes<HTMLDivElement>, "childre
30
40
  size?: KapiAvatarSize | undefined;
31
41
  /** Textos propios; pisan los del `KapiLocaleProvider` y los defaults. */
32
42
  labels?: KapiLabelsOverride<KapiAvatarGroupLabels> | undefined;
43
+ /** Clases por parte (`root`, `item`, `more`). Se suman a las propias. */
44
+ classNames?: KapiAvatarGroupClassNames | undefined;
33
45
  };
34
46
  /** Overlapping avatars capped at `max`, with a trailing "+N" tile. Each avatar keeps its name as tooltip. */
35
- export declare function KapiAvatarGroup({ items, max, size, labels, className, style, ...rest }: KapiAvatarGroupProps): import("react").JSX.Element;
47
+ export declare function KapiAvatarGroup({ items, max, size, labels, className, classNames, style, ...rest }: KapiAvatarGroupProps): import("react").JSX.Element;
@@ -1,40 +1,42 @@
1
1
  "use client";
2
2
  import "#kapi-css/components/display/display.css";
3
3
  import { useLabels as e } from "../locale/KapiLocaleProvider.js";
4
+ import { slot as t } from "../slotsLogic.js";
4
5
  /* empty css */
5
- import { KapiAvatar as t } from "./KapiAvatar.js";
6
- import { avatarOverlapPx as n, overflowLabel as r, splitAvatarGroup as i } from "./avatarGroupLogic.js";
7
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
6
+ import { KapiAvatar as n } from "./KapiAvatar.js";
7
+ import { avatarOverlapPx as r, overflowLabel as i, splitAvatarGroup as a } from "./avatarGroupLogic.js";
8
+ import { AVATAR_GROUP_SLOTS as o } from "./avatarGroupSlots.js";
9
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
8
10
  //#region src/components/display/KapiAvatarGroup.tsx
9
- var s = { overflow: "{n} más" }, c = {
11
+ var l = { overflow: "{n} más" }, u = {
10
12
  sm: 28,
11
13
  md: 36,
12
14
  lg: 48
13
15
  };
14
- function l({ items: l, max: u = 4, size: d = "md", labels: f, className: p, style: m, ...h }) {
15
- let g = e("avatarGroup", s, f), { visible: _, overflow: v } = i(l, u), y = typeof d == "number" ? d : c[d], b = {
16
- "--kapi-avatargroup-overlap": `${n(y)}px`,
17
- ...m
18
- }, x = l.slice(_.length).map((e) => e.name).filter(Boolean).join(", ");
19
- return /* @__PURE__ */ o("div", {
20
- className: ["kapi-avatargroup", p].filter(Boolean).join(" "),
21
- style: b,
16
+ function d({ items: d, max: f = 4, size: p = "md", labels: m, className: h, classNames: g, style: _, ...v }) {
17
+ let y = e("avatarGroup", l, m), { visible: b, overflow: x } = a(d, f), S = typeof p == "number" ? p : u[p], C = {
18
+ "--kapi-avatargroup-overlap": `${r(S)}px`,
19
+ ..._
20
+ }, w = d.slice(b.length).map((e) => e.name).filter(Boolean).join(", ");
21
+ return /* @__PURE__ */ c("div", {
22
+ ...v,
23
+ ...t(o, "root", g, h),
24
+ style: C,
22
25
  role: "group",
23
- ...h,
24
- children: [_.map((e, n) => /* @__PURE__ */ a(t, {
25
- className: "kapi-avatargroup__item",
26
+ children: [b.map((e, r) => /* @__PURE__ */ s(n, {
27
+ ...t(o, "item", g),
26
28
  title: e.name,
27
- size: d,
29
+ size: p,
28
30
  ...e
29
- }, `${e.name ?? e.initials ?? ""}-${n}`)), v > 0 && /* @__PURE__ */ a(t, {
30
- className: "kapi-avatargroup__item kapi-avatargroup__more",
31
+ }, `${e.name ?? e.initials ?? ""}-${r}`)), x > 0 && /* @__PURE__ */ s(n, {
32
+ ...t(o, "more", g, o.parts.item, "kapi-avatargroup__more", g?.item),
31
33
  tone: "neutral",
32
- size: d,
33
- initials: r(v),
34
- title: x || void 0,
35
- "aria-label": g.overflow.replace("{n}", String(v))
34
+ size: p,
35
+ initials: i(x),
36
+ title: w || void 0,
37
+ "aria-label": y.overflow.replace("{n}", String(x))
36
38
  })]
37
39
  });
38
40
  }
39
41
  //#endregion
40
- export { s as DEFAULT_AVATAR_GROUP_LABELS, l as KapiAvatarGroup };
42
+ export { l as DEFAULT_AVATAR_GROUP_LABELS, d as KapiAvatarGroup };
@@ -1,4 +1,5 @@
1
1
  import type { HTMLAttributes, ReactNode, Ref } from "react";
2
+ import type { KapiRender } from "../renderSlot.js";
2
3
  import { type KapiTimelineToneName } from "./timelineLogic.js";
3
4
  export type KapiTimelineItem = {
4
5
  /** Qué pasó. */
@@ -7,6 +8,19 @@ export type KapiTimelineItem = {
7
8
  date?: ReactNode;
8
9
  /** Color del punto: un tono de la línea de tiempo o una familia propia de la app. @default "primary" */
9
10
  tone?: KapiTimelineToneName | undefined;
11
+ /**
12
+ * Convierte el texto en un link al destino. La **fecha queda afuera** a propósito: es contexto,
13
+ * no destino, y adentro haría que el lector anuncie «texto fecha, enlace».
14
+ */
15
+ href?: string | undefined;
16
+ /** Abre el link en una pestaña nueva, con el aviso compartido del locale. Sólo con `href`. */
17
+ newTab?: boolean | undefined;
18
+ /** Dibuja otro elemento con el aspecto del link (el `<Link>` de tu router). Sólo con `href`. */
19
+ render?: KapiRender | undefined;
20
+ /** Ícono adentro del punto. Decorativo: el riel entero es `aria-hidden`, así que el significado va en el texto. */
21
+ icon?: ReactNode;
22
+ /** Reemplaza el punto entero por un nodo propio. Gana sobre `icon` y sobre `tone`. */
23
+ marker?: ReactNode;
10
24
  };
11
25
  /** Atributos nativos (`id`, `style`, `data-*`, `aria-*`…) van al `<ol>`. */
12
26
  export type KapiTimelineProps = Omit<HTMLAttributes<HTMLOListElement>, "children"> & {
@@ -2,38 +2,45 @@
2
2
  import "#kapi-css/components/display/display.css";
3
3
  import { useToneLookResolver as e } from "../../hooks/useToneFamilies.js";
4
4
  /* empty css */
5
- import { isTimelineTone as t, needsToneResolver as n, showConnector as r, timelineDotClass as i } from "./timelineLogic.js";
6
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
5
+ import { KapiAnchor as t } from "./KapiAnchor.js";
6
+ import { isTimelineTone as n, needsToneResolver as r, showConnector as i, timelineDotClass as a } from "./timelineLogic.js";
7
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
7
8
  //#region src/components/display/KapiTimeline.tsx
8
- function s({ items: s, className: c, ...l }) {
9
- let u = e("KapiTimeline");
10
- return /* @__PURE__ */ a("ol", {
11
- ...l,
12
- className: ["kapi-timeline", c].filter(Boolean).join(" "),
13
- children: s.map((e, c) => {
14
- let l = n(e.tone) ? u(e.tone) : void 0;
15
- return /* @__PURE__ */ o("li", {
9
+ function c({ items: c, className: l, ...u }) {
10
+ let d = e("KapiTimeline");
11
+ return /* @__PURE__ */ o("ol", {
12
+ ...u,
13
+ className: ["kapi-timeline", l].filter(Boolean).join(" "),
14
+ children: c.map((e, l) => {
15
+ let u = r(e.tone) ? d(e.tone) : void 0;
16
+ return /* @__PURE__ */ s("li", {
16
17
  className: "kapi-timeline__item",
17
- children: [/* @__PURE__ */ o("div", {
18
+ children: [/* @__PURE__ */ s("div", {
18
19
  className: "kapi-timeline__rail",
19
20
  "aria-hidden": !0,
20
- children: [/* @__PURE__ */ a("span", {
21
- className: i(t(e.tone) ? e.tone : void 0, l?.style !== void 0),
22
- style: l?.style
23
- }), r(c, s.length) && /* @__PURE__ */ a("span", { className: "kapi-tl-line" })]
24
- }), /* @__PURE__ */ o("div", {
21
+ children: [e.marker ?? /* @__PURE__ */ o("span", {
22
+ className: a(n(e.tone) ? e.tone : void 0, u?.style !== void 0),
23
+ style: u?.style,
24
+ children: e.icon
25
+ }), i(l, c.length) && /* @__PURE__ */ o("span", { className: "kapi-tl-line" })]
26
+ }), /* @__PURE__ */ s("div", {
25
27
  className: "kapi-timeline__body",
26
- children: [/* @__PURE__ */ a("div", {
28
+ children: [/* @__PURE__ */ o("div", {
27
29
  className: "kapi-strong",
28
- children: e.text
29
- }), e.date != null && /* @__PURE__ */ a("div", {
30
+ children: e.href === void 0 ? e.text : /* @__PURE__ */ o(t, {
31
+ href: e.href,
32
+ ...e.newTab ? { newTab: !0 } : {},
33
+ ...e.render ? { render: e.render } : {},
34
+ children: e.text
35
+ })
36
+ }), e.date != null && /* @__PURE__ */ o("div", {
30
37
  className: "kapi-muted",
31
38
  children: e.date
32
39
  })]
33
40
  })]
34
- }, c);
41
+ }, l);
35
42
  })
36
43
  });
37
44
  }
38
45
  //#endregion
39
- export { s as KapiTimeline };
46
+ export { c as KapiTimeline };
@@ -0,0 +1,6 @@
1
+ /** Partes de `avatarGroup` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
2
+ export declare const AVATAR_GROUP_SLOTS: import("../slotsLogic.js").SlotTable<"avatarGroup", {
3
+ readonly root: "kapi-avatargroup";
4
+ readonly item: "kapi-avatargroup__item";
5
+ readonly more: null;
6
+ }>;
@@ -0,0 +1,9 @@
1
+ import { defineSlots as e } from "../slotsLogic.js";
2
+ //#region src/components/display/avatarGroupSlots.ts
3
+ var t = e("avatarGroup", {
4
+ root: "kapi-avatargroup",
5
+ item: "kapi-avatargroup__item",
6
+ more: null
7
+ });
8
+ //#endregion
9
+ export { t as AVATAR_GROUP_SLOTS };
@@ -44,7 +44,7 @@ iconTileSizePx,
44
44
  iconTileRadiusPx } from "./iconTileLogic.js";
45
45
  export type { KapiIconTileSize, KapiIconTileTone } from "./iconTileLogic.js";
46
46
  export { DEFAULT_AVATAR_GROUP_LABELS, KapiAvatarGroup } from "./KapiAvatarGroup.js";
47
- export type { KapiAvatarGroupItem, KapiAvatarGroupLabels, KapiAvatarGroupProps } from "./KapiAvatarGroup.js";
47
+ export type { KapiAvatarGroupClassNames, KapiAvatarGroupItem, KapiAvatarGroupLabels, KapiAvatarGroupProps } from "./KapiAvatarGroup.js";
48
48
  export {
49
49
  /** @deprecated Interno; usa `KapiAvatarGroup` en su lugar. Se quita en 1.0. */
50
50
  splitAvatarGroup,