@kapiuara/ui 0.18.0 → 0.20.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.
package/README.md CHANGED
@@ -207,17 +207,18 @@ fuera de la ventana: el documento entero scrollea y se ve un reborde alrededor d
207
207
  Chromium a 1440×900: `documentElement.scrollHeight` 916 contra 900 de `clientHeight`, exactamente
208
208
  los dos márgenes. Es desconcertante porque adentro no desborda nada, así que la barra de scroll no
209
209
  corresponde a ningún contenido. La librería no pisa los estilos del host a propósito (ver «Sin
210
- `@layer`»), así que esto lo pone la app, una vez:
210
+ `@layer`»), así que esto es **opt-in**: la app que ES la página entera lo importa una vez, al lado
211
+ de la hoja de estilos.
211
212
 
212
- ```css
213
- html,
214
- body,
215
- #root {
216
- margin: 0;
217
- height: 100%;
218
- }
213
+ ```ts
214
+ import "@kapiuara/ui/styles.css";
215
+ import "@kapiuara/ui/host.css";
219
216
  ```
220
217
 
218
+ **No lo importa** una app que monta la librería como isla dentro de otra página: le pisaría el
219
+ margen a su host. Ese caso escribe el reset a mano, acotado a su propio contenedor. Con una raíz que
220
+ no sea `#root`, la app agrega su línea de alto; el margen ya queda resuelto.
221
+
221
222
  **`fill` es un contrato de a dos.** El padre tiene que tener alto y el hijo que crece tiene que
222
223
  pedirlo: `KapiStack fill` + `KapiTable fill`. Con uno solo no pasa nada, y el síntoma es mudo — la
223
224
  tabla mide lo que miden sus filas y el pie se va de la pantalla.
@@ -3,7 +3,7 @@ import type { KapiLabelsOverride } from "../labelsLogic.js";
3
3
  import { type KapiRootProps } from "../rootProps.js";
4
4
  import { type KapiTableLabels } from "./tableLabels.js";
5
5
  import { type KapiTableSortState } from "./tableLogic.js";
6
- import type { KapiTableColumn, KapiTableKeyField, KapiTableRowHooks } from "./tableTypes.js";
6
+ import type { KapiTableColumn, KapiTableGetRowKey, KapiTableKeyField, KapiTableRowHooks } from "./tableTypes.js";
7
7
  export type KapiDataTableProps<T, K extends KapiTableKeyField<T> = KapiTableKeyField<T>> = KapiRootProps<HTMLDivElement> & {
8
8
  /** Definición de columnas: las mismas que `KapiTable` (clave, encabezado, render, orden, ancho, fija…). */
9
9
  columns: ReadonlyArray<KapiTableColumn<T>>;
@@ -11,6 +11,16 @@ export type KapiDataTableProps<T, K extends KapiTableKeyField<T> = KapiTableKeyF
11
11
  rows: ReadonlyArray<T>;
12
12
  /** Propiedad con el id único de la fila. Default `"id"`. */
13
13
  keyField?: K | undefined;
14
+ /**
15
+ * Calcula la clave de cada fila, en vez de leerla de una propiedad. Gana sobre `keyField`.
16
+ *
17
+ * Es la salida para un wrapper genérico —donde `T` no está resuelto y el tipo de `keyField` no se
18
+ * puede evaluar— y para una fila cuyo id es opcional o `null`. Deriva la clave de los DATOS de la
19
+ * fila: no recibe el índice a propósito, porque una clave por posición deja de identificar a la
20
+ * fila al ordenar o filtrar. El aviso de claves repetidas o vacías sigue midiendo las que salen
21
+ * de acá.
22
+ */
23
+ getRowKey?: KapiTableGetRowKey<T> | undefined;
14
24
  /** Elemento raíz (la caja que envuelve la tabla). */
15
25
  ref?: Ref<HTMLDivElement> | undefined;
16
26
  /** Alto máximo del área con scroll. Se ignora con `fill`. */
@@ -53,4 +63,4 @@ export type KapiDataTableProps<T, K extends KapiTableKeyField<T> = KapiTableKeyF
53
63
  * acciones por fila y tarjetas en celular. Usa las mismas columnas y estilos que `KapiTable` pero no
54
64
  * carga selección, menús, filtro, columnas, paginación, redimensionado, virtualización ni CSV.
55
65
  */
56
- export declare function KapiDataTable<T, K extends KapiTableKeyField<T> = KapiTableKeyField<T>>({ columns, rows, keyField, ref, maxHeight, fill, card, density, rowHover, mobileCards, labels, sort, defaultSort, onSortChange, manualSort, loading, loadingRows, loadingMessage, emptyMessage, onCopy, actions, onRowClick, getRowProps, className, style, id }: KapiDataTableProps<T, K>): import("react").JSX.Element;
66
+ export declare function KapiDataTable<T, K extends KapiTableKeyField<T> = KapiTableKeyField<T>>({ columns, rows, keyField, getRowKey, ref, maxHeight, fill, card, density, rowHover, mobileCards, labels, sort, defaultSort, onSortChange, manualSort, loading, loadingRows, loadingMessage, emptyMessage, onCopy, actions, onRowClick, getRowProps, className, style, id }: KapiDataTableProps<T, K>): import("react").JSX.Element;
@@ -3,60 +3,62 @@ import "#kapi-css/components/data/KapiTable.css";
3
3
  import { joinClasses as e } from "../rootProps.js";
4
4
  import { useKapiLocale as t, useLabels as n } from "../locale/KapiLocaleProvider.js";
5
5
  import { winOf as r } from "../../hooks/ownerDocument.js";
6
- import { useControllableState as i } from "../../hooks/useControllableState.js";
7
- import { columnAlign as ee, computeStickyOffsets as te, computeStickyRightOffsets as ne, effectiveColumnWidth as re, firstRightStickyIndex as ie, lastStickyIndex as ae, nextSortState as oe, sortRowsByColumn as a, stickySideOf as o, tableWrapClass as s } from "./tableLogic.js";
8
- import { KapiSkeleton as c } from "../feedback/KapiSkeleton.js";
6
+ import { useControllableState as ee } from "../../hooks/useControllableState.js";
7
+ import { columnAlign as te, computeStickyOffsets as ne, computeStickyRightOffsets as re, effectiveColumnWidth as ie, firstRightStickyIndex as ae, lastStickyIndex as oe, nextSortState as se, sortRowsByColumn as ce, stickySideOf as le, tableWrapClass as ue } from "./tableLogic.js";
8
+ import { KapiSkeleton as i } from "../feedback/KapiSkeleton.js";
9
9
  /* empty css */
10
- import { DEFAULT_TABLE_LABELS as l } from "./tableLabels.js";
11
- import { actColClass as u, ariaSortOf as d, bodyCell as f, cellClass as p, columnBoxStyle as m, headerContent as se, skeletonBar as ce, stateRow as h, stickyInset as g } from "./tableCells.js";
12
- import { useRowKeyWarning as le } from "./useRowKeyWarning.js";
13
- import { useTableEdges as ue } from "./useTableEdges.js";
14
- import { isRowActivationKey as de, mergeRowProps as fe, shouldFireRowClick as pe } from "./rowClickLogic.js";
15
- import { useLayoutEffect as me, useMemo as _, useRef as v, useState as he } from "react";
16
- import { jsx as y, jsxs as b } from "react/jsx-runtime";
10
+ import { DEFAULT_TABLE_LABELS as a } from "./tableLabels.js";
11
+ import { actColClass as o, ariaSortOf as s, bodyCell as c, cellClass as l, columnBoxStyle as u, headerContent as de, skeletonBar as fe, stateRow as d, stickyInset as f } from "./tableCells.js";
12
+ import { useRowKeyWarning as pe } from "./useRowKeyWarning.js";
13
+ import { useTableEdges as me } from "./useTableEdges.js";
14
+ import { isRowActivationKey as he, mergeRowProps as ge, shouldFireRowClick as _e } from "./rowClickLogic.js";
15
+ import { useCallback as ve, useLayoutEffect as ye, useMemo as p, useRef as m, useState as be } from "react";
16
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
17
17
  //#region src/components/data/KapiDataTable.tsx
18
- var x = {};
19
- function S({ columns: S, rows: C, keyField: w = "id", ref: T, maxHeight: E = "58vh", fill: D = !1, card: O = !1, density: k = "default", rowHover: A = !1, mobileCards: j = !1, labels: M, sort: N, defaultSort: P = null, onSortChange: F, manualSort: I = !1, loading: L = !1, loadingRows: R = 5, loadingMessage: z, emptyMessage: B, onCopy: ge, actions: V, onRowClick: H, getRowProps: _e, className: ve, style: ye, id: be }) {
20
- let U = n("table", l, M);
21
- le("KapiDataTable", C, w);
22
- let W = t(), [G, xe] = i(N, P, F), Se = (e) => xe(oe(G, e)), K = _(() => I ? C : a(C, S, G, W), [
23
- I,
24
- C,
25
- S,
18
+ var _ = {};
19
+ function v({ columns: v, rows: y, keyField: b = "id", getRowKey: x, ref: S, maxHeight: C = "58vh", fill: w = !1, card: T = !1, density: E = "default", rowHover: D = !1, mobileCards: O = !1, labels: k, sort: A, defaultSort: j = null, onSortChange: M, manualSort: N = !1, loading: P = !1, loadingRows: F = 5, loadingMessage: I, emptyMessage: L, onCopy: xe, actions: R, onRowClick: z, getRowProps: Se, className: Ce, style: we, id: Te }) {
20
+ let B = n("table", a, k), V = m(x);
21
+ V.current = x;
22
+ let H = x !== void 0, U = ve((e) => H ? V.current(e) : e[b], [H, b]);
23
+ pe("KapiDataTable", y, U, x ? "getRowKey" : `keyField ("${String(b)}")`);
24
+ let W = t(), [G, Ee] = ee(A, j, M), De = (e) => Ee(se(G, e)), K = p(() => N ? y : ce(y, v, G, W), [
25
+ N,
26
+ y,
27
+ v,
26
28
  G,
27
29
  W
28
- ]), q = !!V, J = S.some((e) => o(e.sticky) === "right"), Y = v(null), [X, Ce] = he(0);
29
- me(() => {
30
+ ]), q = !!R, J = v.some((e) => le(e.sticky) === "right"), Y = m(null), [X, Oe] = be(0);
31
+ ye(() => {
30
32
  let e = Y.current;
31
33
  if (!e || !J) return;
32
34
  let t = () => {
33
35
  let t = e.getBoundingClientRect().width;
34
- Ce((e) => e === t ? e : t);
36
+ Oe((e) => e === t ? e : t);
35
37
  };
36
38
  if (t(), typeof ResizeObserver > "u") return;
37
39
  let n = new ResizeObserver(t);
38
40
  return n.observe(e), () => n.disconnect();
39
41
  }, [J, q]);
40
- let Z = _(() => {
41
- let e = S.map((e) => ({
42
+ let Z = p(() => {
43
+ let e = v.map((e) => ({
42
44
  sticky: e.sticky,
43
- width: re(e, x)
45
+ width: ie(e, _)
44
46
  }));
45
47
  return {
46
- lefts: te(e, 0),
47
- rights: ne(e, q ? X : 0),
48
- lastLeft: ae(S),
49
- firstRight: ie(S)
48
+ lefts: ne(e, 0),
49
+ rights: re(e, q ? X : 0),
50
+ lastLeft: oe(v),
51
+ firstRight: ae(v)
50
52
  };
51
53
  }, [
52
- S,
54
+ v,
53
55
  q,
54
56
  X
55
- ]), Q = v(null), { cortaDerecha: we, cortaIzquierda: Te, medirBordes: Ee } = ue(Q, S), $ = S.length + +!!q, De = B === void 0 ? U.empty : B, Oe = z === void 0 ? U.loading : z, ke = (e) => H ? {
57
+ ]), Q = m(null), { cortaDerecha: ke, cortaIzquierda: Ae, medirBordes: je } = me(Q, v), $ = v.length + +!!q, Me = L === void 0 ? B.empty : L, Ne = I === void 0 ? B.loading : I, Pe = (e) => z ? {
56
58
  className: "is-clickable",
57
59
  tabIndex: 0,
58
60
  onClick: (t) => {
59
- pe(t.target, t.currentTarget, r(t.currentTarget)?.getSelection() ?? null) && H(e, t);
61
+ _e(t.target, t.currentTarget, r(t.currentTarget)?.getSelection() ?? null) && z(e, t);
60
62
  },
61
63
  onKeyDown: (t) => {
62
64
  let n = {
@@ -64,25 +66,25 @@ function S({ columns: S, rows: C, keyField: w = "id", ref: T, maxHeight: E = "58
64
66
  target: t.target,
65
67
  currentTarget: t.currentTarget
66
68
  };
67
- de({
69
+ he({
68
70
  ...n,
69
71
  isComposing: t.nativeEvent.isComposing
70
- }) && (t.preventDefault(), H(e, t));
72
+ }) && (t.preventDefault(), z(e, t));
71
73
  }
72
- } : {}, Ae = Array.from({ length: R }, (e, t) => /* @__PURE__ */ b("tr", {
74
+ } : {}, Fe = Array.from({ length: F }, (e, t) => /* @__PURE__ */ g("tr", {
73
75
  className: "kapi-table-skrow",
74
76
  "aria-hidden": !0,
75
- children: [S.map((e, n) => /* @__PURE__ */ y("td", {
77
+ children: [v.map((e, n) => /* @__PURE__ */ h("td", {
76
78
  "data-col": e.key,
77
- className: p(e, n, Z),
79
+ className: l(e, n, Z),
78
80
  style: {
79
- ...g(n, Z),
80
- ...m(e, "td", x)
81
+ ...f(n, Z),
82
+ ...u(e, "td", _)
81
83
  },
82
- children: ce(e, n, t)
83
- }, e.key)), q && /* @__PURE__ */ y("td", {
84
- className: u(Z),
85
- children: /* @__PURE__ */ y(c, {
84
+ children: fe(e, n, t)
85
+ }, e.key)), q && /* @__PURE__ */ h("td", {
86
+ className: o(Z),
87
+ children: /* @__PURE__ */ h(i, {
86
88
  width: 28,
87
89
  height: 14,
88
90
  radius: 6,
@@ -90,54 +92,54 @@ function S({ columns: S, rows: C, keyField: w = "id", ref: T, maxHeight: E = "58
90
92
  })
91
93
  })]
92
94
  }, `sk-${t}`));
93
- return /* @__PURE__ */ y("div", {
94
- ref: T,
95
- id: be,
96
- style: ye,
97
- className: e("kapi-table-shell", O && "kapi-table-shell--card", D && "kapi-table-shell--fill", j && "kapi-table-shell--cards", ve),
98
- children: /* @__PURE__ */ y("div", {
95
+ return /* @__PURE__ */ h("div", {
96
+ ref: S,
97
+ id: Te,
98
+ style: we,
99
+ className: e("kapi-table-shell", T && "kapi-table-shell--card", w && "kapi-table-shell--fill", O && "kapi-table-shell--cards", Ce),
100
+ children: /* @__PURE__ */ h("div", {
99
101
  ref: Q,
100
- className: s({
101
- cortaDerecha: we,
102
- cortaIzquierda: Te,
102
+ className: ue({
103
+ cortaDerecha: ke,
104
+ cortaIzquierda: Ae,
103
105
  rightEdge: q || J
104
106
  }),
105
107
  tabIndex: 0,
106
- style: D ? void 0 : { maxHeight: E },
107
- onScroll: (e) => Ee(e.currentTarget),
108
- children: /* @__PURE__ */ b("table", {
109
- className: e("kapi-table2", k === "card" && "kapi-table2--card", A && "kapi-table2--hover"),
110
- children: [/* @__PURE__ */ y("thead", { children: /* @__PURE__ */ b("tr", { children: [S.map((t, n) => /* @__PURE__ */ y("th", {
108
+ style: w ? void 0 : { maxHeight: C },
109
+ onScroll: (e) => je(e.currentTarget),
110
+ children: /* @__PURE__ */ g("table", {
111
+ className: e("kapi-table2", E === "card" && "kapi-table2--card", D && "kapi-table2--hover"),
112
+ children: [/* @__PURE__ */ h("thead", { children: /* @__PURE__ */ g("tr", { children: [v.map((t, n) => /* @__PURE__ */ h("th", {
111
113
  "data-col": t.key,
112
- className: e(p(t, n, Z), t.sortable && "is-sortable"),
113
- "aria-sort": d(t, G),
114
+ className: e(l(t, n, Z), t.sortable && "is-sortable"),
115
+ "aria-sort": s(t, G),
114
116
  style: {
115
- ...g(n, Z),
116
- ...m(t, "th", x),
117
- textAlign: ee(t.align)
117
+ ...f(n, Z),
118
+ ...u(t, "th", _),
119
+ textAlign: te(t.align)
118
120
  },
119
- children: se(t, G, Se, U)
120
- }, t.key)), q && /* @__PURE__ */ y("th", {
121
+ children: de(t, G, De, B)
122
+ }, t.key)), q && /* @__PURE__ */ h("th", {
121
123
  ref: Y,
122
- className: u(Z),
123
- children: U.actions
124
- })] }) }), /* @__PURE__ */ b("tbody", { children: [
125
- L && (R > 0 ? Ae : h($, Oe, !0)),
126
- !L && K.length === 0 && h($, De),
127
- !L && K.map((e, t) => /* @__PURE__ */ b("tr", {
128
- ...fe(_e?.(e, t), ke(e)),
129
- children: [S.map((t, n) => f(t, n, e, Z, x, U, ge)), q && /* @__PURE__ */ y("td", {
130
- className: u(Z),
131
- children: /* @__PURE__ */ y("div", {
124
+ className: o(Z),
125
+ children: B.actions
126
+ })] }) }), /* @__PURE__ */ g("tbody", { children: [
127
+ P && (F > 0 ? Fe : d($, Ne, !0)),
128
+ !P && K.length === 0 && d($, Me),
129
+ !P && K.map((e, t) => /* @__PURE__ */ g("tr", {
130
+ ...ge(Se?.(e, t), Pe(e)),
131
+ children: [v.map((t, n) => c(t, n, e, Z, _, B, xe)), q && /* @__PURE__ */ h("td", {
132
+ className: o(Z),
133
+ children: /* @__PURE__ */ h("div", {
132
134
  className: "kapi-actcol__in",
133
- children: V?.(e)
135
+ children: R?.(e)
134
136
  })
135
137
  })]
136
- }, e[w]))
138
+ }, U(e)))
137
139
  ] })]
138
140
  })
139
141
  })
140
142
  });
141
143
  }
142
144
  //#endregion
143
- export { S as KapiDataTable };
145
+ export { v as KapiDataTable };
@@ -1,6 +1,6 @@
1
1
  import type { KapiTableKeyField, KapiTableProps } from "./tableTypes.js";
2
2
  export { DEFAULT_TABLE_LABELS } from "./tableLabels.js";
3
- export type { KapiTableCellValue, KapiTableClassNames, KapiTableColumn, KapiTableContext, KapiTableActionHandler, KapiTableActionItem, KapiTableAction, KapiTableCsvOptions, KapiTableSelectionPreset, KapiTableDataset, KapiTableFooterCell, KapiTableFooterRow, KapiTablePagination, KapiTableClientPagination, KapiTableKey, KapiTableKeyField, KapiTableProps, KapiTableRowHooks } from "./tableTypes.js";
3
+ export type { KapiTableCellValue, KapiTableClassNames, KapiTableColumn, KapiTableContext, KapiTableActionHandler, KapiTableActionItem, KapiTableAction, KapiTableCsvOptions, KapiTableSelectionPreset, KapiTableDataset, KapiTableFooterCell, KapiTableFooterRow, KapiTablePagination, KapiTableClientPagination, KapiTableGetRowKey, KapiTableKey, KapiTableKeyField, KapiTableProps, KapiTableRowHooks } from "./tableTypes.js";
4
4
  export type { KapiTableRowAttributes } from "./rowClickLogic.js";
5
5
  export type { KapiTableLabels } from "./tableLabels.js";
6
6
  export type { KapiTableSortDirection, KapiTableSortState, KapiTableSortValue, KapiTableFilterState } from "./tableLogic.js";
@@ -9,4 +9,4 @@ export type { KapiTableSortDirection, KapiTableSortState, KapiTableSortValue, Ka
9
9
  * por header, columna de acciones fija, copiar por celda, virtualización de altura fija,
10
10
  * drag-scroll con click derecho y menú contextual con doble click derecho.
11
11
  */
12
- export declare function KapiTable<T, K extends KapiTableKeyField<T> = KapiTableKeyField<T>>({ columns: columnsProp, rows, keyField, maxHeight, fill, footer, bulkActionsPlacement, className, classNames, style, id, ref: shellRef, labels, actions, rowMenu, contextMenu, onCopy, selectable, rowSelect, rowLabel, selectedIds, defaultSelectedIds, onSelectedIdsChange, bulkActions, rangeSelect, selectionPresets, virtual, rowHeight, estimatedRowHeight, sort, defaultSort, onSortChange, manualSort, pagination, dataset, loading, loadingRows, card, emptyMessage, loadingMessage, isRowSelectable, renderSubComponent, expandedIds, defaultExpandedIds, onExpandedIdsChange, density, rowHover, columnToggle, columnVisibility, defaultColumnVisibility, onColumnVisibilityChange, columnPinning, pinnedColumns, defaultPinnedColumns, onPinnedColumnsChange, headerMenu, resizableColumns, columnWidths, defaultColumnWidths, onColumnWidthsChange, filterable, filter, defaultFilter, onFilterChange, manualFilter, filterDebounce, exportCsv, toolbar, toolbarActions, onRefresh, mobileCards, onRowClick, getRowProps }: KapiTableProps<T, K>): import("react").JSX.Element;
12
+ export declare function KapiTable<T, K extends KapiTableKeyField<T> = KapiTableKeyField<T>>({ columns: columnsProp, rows, keyField, getRowKey, maxHeight, fill, footer, bulkActionsPlacement, className, classNames, style, id, ref: shellRef, labels, actions, rowMenu, contextMenu, onCopy, selectable, rowSelect, rowLabel, selectedIds, defaultSelectedIds, onSelectedIdsChange, bulkActions, rangeSelect, selectionPresets, virtual, rowHeight, estimatedRowHeight, sort, defaultSort, onSortChange, manualSort, pagination, dataset, loading, loadingRows, card, emptyMessage, loadingMessage, isRowSelectable, renderSubComponent, expandedIds, defaultExpandedIds, onExpandedIdsChange, density, rowHover, columnToggle, columnVisibility, defaultColumnVisibility, onColumnVisibilityChange, columnPinning, pinnedColumns, defaultPinnedColumns, onPinnedColumnsChange, headerMenu, resizableColumns, columnWidths, defaultColumnWidths, onColumnWidthsChange, filterable, filter, defaultFilter, onFilterChange, manualFilter, filterDebounce, exportCsv, toolbar, toolbarActions, onRefresh, mobileCards, onRowClick, getRowProps }: KapiTableProps<T, K>): import("react").JSX.Element;