@kapiuara/ui 0.18.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.
- package/dist/components/data/KapiDataTable.d.ts +12 -2
- package/dist/components/data/KapiDataTable.js +78 -76
- package/dist/components/data/KapiTable.d.ts +2 -2
- package/dist/components/data/KapiTable.js +229 -227
- package/dist/components/data/index.d.ts +1 -1
- package/dist/components/data/tableTypes.d.ts +37 -0
- package/dist/components/data/useRowKeyWarning.d.ts +9 -3
- package/dist/components/data/useRowKeyWarning.js +7 -7
- package/dist/components/data/useTableSelection.d.ts +3 -2
- package/dist/components/data/useTableSelection.js +3 -3
- package/dist/css/base.css +1 -1
- package/dist/hooks/themeDeriveLogic.js +2 -2
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +2 -2
|
@@ -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
|
|
7
|
-
import { columnAlign as
|
|
8
|
-
import { KapiSkeleton as
|
|
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
|
|
11
|
-
import { actColClass as
|
|
12
|
-
import { useRowKeyWarning as
|
|
13
|
-
import { useTableEdges as
|
|
14
|
-
import { isRowActivationKey as
|
|
15
|
-
import { useLayoutEffect as
|
|
16
|
-
import { jsx as
|
|
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
|
|
19
|
-
function
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 = !!
|
|
29
|
-
|
|
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
|
-
|
|
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 =
|
|
42
|
+
let Z = p(() => {
|
|
43
|
+
let e = v.map((e) => ({
|
|
42
44
|
sticky: e.sticky,
|
|
43
|
-
width:
|
|
45
|
+
width: ie(e, _)
|
|
44
46
|
}));
|
|
45
47
|
return {
|
|
46
|
-
lefts:
|
|
47
|
-
rights:
|
|
48
|
-
lastLeft:
|
|
49
|
-
firstRight:
|
|
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
|
-
|
|
54
|
+
v,
|
|
53
55
|
q,
|
|
54
56
|
X
|
|
55
|
-
]), Q =
|
|
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
|
-
|
|
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
|
-
|
|
69
|
+
he({
|
|
68
70
|
...n,
|
|
69
71
|
isComposing: t.nativeEvent.isComposing
|
|
70
|
-
}) && (t.preventDefault(),
|
|
72
|
+
}) && (t.preventDefault(), z(e, t));
|
|
71
73
|
}
|
|
72
|
-
} : {},
|
|
74
|
+
} : {}, Fe = Array.from({ length: F }, (e, t) => /* @__PURE__ */ g("tr", {
|
|
73
75
|
className: "kapi-table-skrow",
|
|
74
76
|
"aria-hidden": !0,
|
|
75
|
-
children: [
|
|
77
|
+
children: [v.map((e, n) => /* @__PURE__ */ h("td", {
|
|
76
78
|
"data-col": e.key,
|
|
77
|
-
className:
|
|
79
|
+
className: l(e, n, Z),
|
|
78
80
|
style: {
|
|
79
|
-
...
|
|
80
|
-
...
|
|
81
|
+
...f(n, Z),
|
|
82
|
+
...u(e, "td", _)
|
|
81
83
|
},
|
|
82
|
-
children:
|
|
83
|
-
}, e.key)), q && /* @__PURE__ */
|
|
84
|
-
className:
|
|
85
|
-
children: /* @__PURE__ */
|
|
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__ */
|
|
94
|
-
ref:
|
|
95
|
-
id:
|
|
96
|
-
style:
|
|
97
|
-
className: e("kapi-table-shell",
|
|
98
|
-
children: /* @__PURE__ */
|
|
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:
|
|
101
|
-
cortaDerecha:
|
|
102
|
-
cortaIzquierda:
|
|
102
|
+
className: ue({
|
|
103
|
+
cortaDerecha: ke,
|
|
104
|
+
cortaIzquierda: Ae,
|
|
103
105
|
rightEdge: q || J
|
|
104
106
|
}),
|
|
105
107
|
tabIndex: 0,
|
|
106
|
-
style:
|
|
107
|
-
onScroll: (e) =>
|
|
108
|
-
children: /* @__PURE__ */
|
|
109
|
-
className: e("kapi-table2",
|
|
110
|
-
children: [/* @__PURE__ */
|
|
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(
|
|
113
|
-
"aria-sort":
|
|
114
|
+
className: e(l(t, n, Z), t.sortable && "is-sortable"),
|
|
115
|
+
"aria-sort": s(t, G),
|
|
114
116
|
style: {
|
|
115
|
-
...
|
|
116
|
-
...
|
|
117
|
-
textAlign:
|
|
117
|
+
...f(n, Z),
|
|
118
|
+
...u(t, "th", _),
|
|
119
|
+
textAlign: te(t.align)
|
|
118
120
|
},
|
|
119
|
-
children:
|
|
120
|
-
}, t.key)), q && /* @__PURE__ */
|
|
121
|
+
children: de(t, G, De, B)
|
|
122
|
+
}, t.key)), q && /* @__PURE__ */ h("th", {
|
|
121
123
|
ref: Y,
|
|
122
|
-
className:
|
|
123
|
-
children:
|
|
124
|
-
})] }) }), /* @__PURE__ */
|
|
125
|
-
|
|
126
|
-
!
|
|
127
|
-
!
|
|
128
|
-
...
|
|
129
|
-
children: [
|
|
130
|
-
className:
|
|
131
|
-
children: /* @__PURE__ */
|
|
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:
|
|
135
|
+
children: R?.(e)
|
|
134
136
|
})
|
|
135
137
|
})]
|
|
136
|
-
}, e
|
|
138
|
+
}, U(e)))
|
|
137
139
|
] })]
|
|
138
140
|
})
|
|
139
141
|
})
|
|
140
142
|
});
|
|
141
143
|
}
|
|
142
144
|
//#endregion
|
|
143
|
-
export {
|
|
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;
|