@apotech-os/ui-sdk 7.3.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +421 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -6
- package/dist/index.d.ts +91 -6
- package/dist/index.js +421 -152
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -439,18 +439,18 @@ function TableHeader({
|
|
|
439
439
|
function TableBody({ className, ...props }) {
|
|
440
440
|
return /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: cn("[&_tr:last-child]:border-0", className), ...props });
|
|
441
441
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
442
|
+
var TableRow = React2__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
443
|
+
"tr",
|
|
444
|
+
{
|
|
445
|
+
ref,
|
|
446
|
+
className: cn(
|
|
447
|
+
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
|
448
|
+
className
|
|
449
|
+
),
|
|
450
|
+
...props
|
|
451
|
+
}
|
|
452
|
+
));
|
|
453
|
+
TableRow.displayName = "TableRow";
|
|
454
454
|
function TableHead({ className, ...props }) {
|
|
455
455
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
456
456
|
"th",
|
|
@@ -893,7 +893,7 @@ var EMPTY_STATE = {
|
|
|
893
893
|
};
|
|
894
894
|
var MIN_COLUMN_WIDTH_PX = 64;
|
|
895
895
|
var DEFAULT_VIRTUALIZE_FROM = 100;
|
|
896
|
-
var ROW_HEIGHT_PX = 53;
|
|
896
|
+
var ROW_HEIGHT_PX = { comfortable: 53, compact: 33 };
|
|
897
897
|
var VIRTUAL_VIEWPORT_PX = 640;
|
|
898
898
|
function useDataTableState(controlled, initial, onStateChange) {
|
|
899
899
|
const [internal, setInternal] = React2__namespace.useState({ ...EMPTY_STATE, ...initial });
|
|
@@ -912,23 +912,39 @@ function DataTable({
|
|
|
912
912
|
columns,
|
|
913
913
|
rows,
|
|
914
914
|
rowId,
|
|
915
|
+
rowLabel = rowId,
|
|
916
|
+
label,
|
|
915
917
|
state: controlled,
|
|
916
918
|
defaultState,
|
|
917
919
|
onStateChange,
|
|
918
920
|
facets = [],
|
|
921
|
+
searchable = true,
|
|
919
922
|
searchPlaceholder = "Rechercher\u2026",
|
|
923
|
+
columnPicker = true,
|
|
924
|
+
filters,
|
|
925
|
+
actions,
|
|
926
|
+
csvExport,
|
|
920
927
|
selectable = false,
|
|
928
|
+
isRowSelectable,
|
|
929
|
+
bulkActions = [],
|
|
921
930
|
onRowClick,
|
|
931
|
+
rowActions,
|
|
932
|
+
renderExpanded,
|
|
922
933
|
pagination,
|
|
934
|
+
pageSize,
|
|
923
935
|
manual = false,
|
|
924
936
|
loading = false,
|
|
925
937
|
error,
|
|
926
938
|
empty = "Aucun r\xE9sultat.",
|
|
939
|
+
density = "comfortable",
|
|
940
|
+
variant = "default",
|
|
927
941
|
virtualizeFrom = DEFAULT_VIRTUALIZE_FROM,
|
|
928
942
|
className
|
|
929
943
|
}) {
|
|
930
944
|
const [state, patch] = useDataTableState(controlled, defaultState, onStateChange);
|
|
931
945
|
const [widths, setWidths] = React2__namespace.useState({});
|
|
946
|
+
const [expanded, setExpanded] = React2__namespace.useState(/* @__PURE__ */ new Set());
|
|
947
|
+
const [page, setPage] = React2__namespace.useState(0);
|
|
932
948
|
const hidden = React2__namespace.useMemo(() => new Set(state.hidden), [state.hidden]);
|
|
933
949
|
const selected = React2__namespace.useMemo(() => new Set(state.selected), [state.selected]);
|
|
934
950
|
const visibleColumns = React2__namespace.useMemo(
|
|
@@ -938,10 +954,10 @@ function DataTable({
|
|
|
938
954
|
const columnDefs = React2__namespace.useMemo(
|
|
939
955
|
() => visibleColumns.map((column) => ({
|
|
940
956
|
id: column.key,
|
|
941
|
-
accessorFn: (row) => column
|
|
957
|
+
accessorFn: (row) => rawValue(column, row),
|
|
942
958
|
enableSorting: column.sortable ?? false,
|
|
943
959
|
size: column.width,
|
|
944
|
-
cell: ({ row }) => column.cell ? column.cell(row.original) :
|
|
960
|
+
cell: ({ row }) => column.cell ? column.cell(row.original) : formatCellValue(rawValue(column, row.original), column.format, column.currency)
|
|
945
961
|
})),
|
|
946
962
|
[visibleColumns]
|
|
947
963
|
);
|
|
@@ -963,17 +979,23 @@ function DataTable({
|
|
|
963
979
|
return table.getRowModel().rows.filter(
|
|
964
980
|
(row) => active.every(([key, filter]) => {
|
|
965
981
|
const column = columns.find((c) => c.key === key);
|
|
966
|
-
const raw = column
|
|
982
|
+
const raw = column ? rawValue(column, row.original) : row.original[key];
|
|
967
983
|
return matches(raw, filter);
|
|
968
984
|
})
|
|
969
985
|
);
|
|
970
986
|
}, [columns, manual, state.filters, table.getRowModel().rows]);
|
|
987
|
+
const criteria = JSON.stringify([state.search, state.filters, state.sort]);
|
|
988
|
+
React2__namespace.useEffect(() => setPage(0), [criteria]);
|
|
989
|
+
const paged = !manual && pageSize !== void 0 && pageSize > 0;
|
|
990
|
+
const pageCount = paged ? Math.max(1, Math.ceil(facetedRows.length / pageSize)) : 1;
|
|
991
|
+
const currentPage = Math.min(page, pageCount - 1);
|
|
992
|
+
const pageRows = paged ? facetedRows.slice(currentPage * pageSize, (currentPage + 1) * pageSize) : facetedRows;
|
|
971
993
|
const bodyRef = React2__namespace.useRef(null);
|
|
972
|
-
const longEnoughToVirtualise =
|
|
994
|
+
const longEnoughToVirtualise = !paged && !renderExpanded && pageRows.length > virtualizeFrom;
|
|
973
995
|
const virtualizer = reactVirtual.useVirtualizer({
|
|
974
|
-
count:
|
|
996
|
+
count: pageRows.length,
|
|
975
997
|
getScrollElement: () => bodyRef.current,
|
|
976
|
-
estimateSize: () => ROW_HEIGHT_PX,
|
|
998
|
+
estimateSize: () => ROW_HEIGHT_PX[density],
|
|
977
999
|
overscan: 8,
|
|
978
1000
|
enabled: longEnoughToVirtualise
|
|
979
1001
|
});
|
|
@@ -989,9 +1011,22 @@ function DataTable({
|
|
|
989
1011
|
else next.add(id);
|
|
990
1012
|
patch({ selected: [...next] });
|
|
991
1013
|
};
|
|
992
|
-
const
|
|
1014
|
+
const canSelect = (row) => isRowSelectable?.(row) ?? true;
|
|
1015
|
+
const selectableRows = pageRows.filter((row) => canSelect(row.original));
|
|
1016
|
+
const allVisibleSelected = selectableRows.length > 0 && selectableRows.every((row) => selected.has(row.id));
|
|
993
1017
|
const toggleAll = () => {
|
|
994
|
-
|
|
1018
|
+
const pageIds = new Set(selectableRows.map((row) => row.id));
|
|
1019
|
+
patch({
|
|
1020
|
+
selected: allVisibleSelected ? state.selected.filter((id) => !pageIds.has(id)) : [.../* @__PURE__ */ new Set([...state.selected, ...pageIds])]
|
|
1021
|
+
});
|
|
1022
|
+
};
|
|
1023
|
+
const toggleExpanded = (id) => {
|
|
1024
|
+
setExpanded((current) => {
|
|
1025
|
+
const next = new Set(current);
|
|
1026
|
+
if (next.has(id)) next.delete(id);
|
|
1027
|
+
else next.add(id);
|
|
1028
|
+
return next;
|
|
1029
|
+
});
|
|
995
1030
|
};
|
|
996
1031
|
const setFilter = (facetKey, filter) => {
|
|
997
1032
|
const next = { ...state.filters };
|
|
@@ -999,13 +1034,39 @@ function DataTable({
|
|
|
999
1034
|
else delete next[facetKey];
|
|
1000
1035
|
patch({ filters: next });
|
|
1001
1036
|
};
|
|
1002
|
-
const
|
|
1037
|
+
const exportCsv = () => {
|
|
1038
|
+
if (!csvExport) return;
|
|
1039
|
+
if ("onExport" in csvExport) {
|
|
1040
|
+
csvExport.onExport();
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const header = visibleColumns.map((column) => headerText(column));
|
|
1044
|
+
const body = facetedRows.map(
|
|
1045
|
+
(row) => visibleColumns.map((column) => {
|
|
1046
|
+
const value = column.exportValue ? column.exportValue(row.original) : rawValue(column, row.original);
|
|
1047
|
+
if (value == null) return "";
|
|
1048
|
+
return value instanceof Date ? value.toISOString() : String(value);
|
|
1049
|
+
})
|
|
1050
|
+
);
|
|
1051
|
+
const filename = csvExport.filename.endsWith(".csv") ? csvExport.filename : `${csvExport.filename}.csv`;
|
|
1052
|
+
downloadCsv([header, ...body], filename);
|
|
1053
|
+
};
|
|
1054
|
+
const renderedRows = virtualise ? virtualItems.map((item) => ({ row: pageRows[item.index], index: item.index })) : pageRows.map((row, index) => ({ row, index }));
|
|
1003
1055
|
const spaceAbove = virtualise ? virtualItems[0]?.start ?? 0 : 0;
|
|
1004
1056
|
const spaceBelow = virtualise ? virtualizer.getTotalSize() - (virtualItems[virtualItems.length - 1]?.end ?? 0) : 0;
|
|
1005
|
-
const
|
|
1057
|
+
const expandable = renderExpanded !== void 0;
|
|
1058
|
+
const leadingCount = (expandable ? 1 : 0) + (selectable ? 1 : 0);
|
|
1059
|
+
const columnCount = visibleColumns.length + leadingCount + (rowActions ? 1 : 0);
|
|
1060
|
+
const hasFooter = visibleColumns.some((column) => column.footer !== void 0);
|
|
1061
|
+
const compact = density === "compact";
|
|
1062
|
+
const embedded = variant === "embedded";
|
|
1063
|
+
const headClass = compact ? "h-8 px-3" : void 0;
|
|
1064
|
+
const cellClass = compact ? "px-3 py-1.5" : void 0;
|
|
1065
|
+
const selectionActive = selectable && selected.size > 0;
|
|
1066
|
+
const showToolbar = searchable || facets.length > 0 || filters !== void 0 || actions !== void 0 || csvExport !== void 0 || columnPicker || selectionActive;
|
|
1006
1067
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col gap-3", className), children: [
|
|
1007
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
1008
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1068
|
+
showToolbar && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-wrap items-center gap-2", embedded && "px-6"), children: [
|
|
1069
|
+
searchable && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1009
1070
|
Input,
|
|
1010
1071
|
{
|
|
1011
1072
|
value: state.search,
|
|
@@ -1024,148 +1085,356 @@ function DataTable({
|
|
|
1024
1085
|
},
|
|
1025
1086
|
facet.key
|
|
1026
1087
|
)),
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
{
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
})
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1088
|
+
filters,
|
|
1089
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ml-auto flex flex-wrap items-center gap-2", children: [
|
|
1090
|
+
selectionActive && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1091
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-muted-foreground", role: "status", children: [
|
|
1092
|
+
selected.size,
|
|
1093
|
+
" s\xE9lectionn\xE9",
|
|
1094
|
+
selected.size > 1 ? "s" : ""
|
|
1095
|
+
] }),
|
|
1096
|
+
bulkActions.map((action, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1097
|
+
Button,
|
|
1098
|
+
{
|
|
1099
|
+
variant: action.destructive ? "destructive" : "outline",
|
|
1100
|
+
size: "sm",
|
|
1101
|
+
disabled: action.disabled,
|
|
1102
|
+
onClick: () => action.onSelect(state.selected),
|
|
1103
|
+
children: action.label
|
|
1104
|
+
},
|
|
1105
|
+
index
|
|
1106
|
+
)),
|
|
1107
|
+
bulkActions.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", size: "sm", onClick: () => patch({ selected: [] }), children: "D\xE9s\xE9lectionner" })
|
|
1108
|
+
] }),
|
|
1109
|
+
actions,
|
|
1110
|
+
csvExport && /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "sm", onClick: exportCsv, children: "Exporter" }),
|
|
1111
|
+
columnPicker && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1112
|
+
ColumnPicker,
|
|
1113
|
+
{
|
|
1114
|
+
columns,
|
|
1115
|
+
hidden,
|
|
1116
|
+
onToggle: (key) => patch({
|
|
1117
|
+
hidden: hidden.has(key) ? state.hidden.filter((k) => k !== key) : [...state.hidden, key]
|
|
1118
|
+
})
|
|
1119
|
+
}
|
|
1120
|
+
)
|
|
1041
1121
|
] })
|
|
1042
1122
|
] }),
|
|
1043
1123
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1044
1124
|
"div",
|
|
1045
1125
|
{
|
|
1046
1126
|
ref: bodyRef,
|
|
1047
|
-
className: cn(
|
|
1127
|
+
className: cn(
|
|
1128
|
+
"relative overflow-auto",
|
|
1129
|
+
embedded ? "border-y" : "rounded-xl border bg-card",
|
|
1130
|
+
virtualise && "max-h-160"
|
|
1131
|
+
),
|
|
1048
1132
|
style: virtualise ? { maxHeight: VIRTUAL_VIEWPORT_PX } : void 0,
|
|
1049
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
"
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1133
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1134
|
+
Table,
|
|
1135
|
+
{
|
|
1136
|
+
"aria-label": label,
|
|
1137
|
+
className: embedded ? "[&_tr>*:first-child]:pl-6 [&_tr>*:last-child]:pr-6" : void 0,
|
|
1138
|
+
children: [
|
|
1139
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableHeader, { className: virtualise ? "sticky top-0 z-10 bg-card" : void 0, children: /* @__PURE__ */ jsxRuntime.jsxs(TableRow, { children: [
|
|
1140
|
+
expandable && /* @__PURE__ */ jsxRuntime.jsx(TableHead, { className: cn("w-10", headClass), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "D\xE9tails" }) }),
|
|
1141
|
+
selectable && /* @__PURE__ */ jsxRuntime.jsx(TableHead, { className: cn("w-10", headClass), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1142
|
+
Checkbox,
|
|
1143
|
+
{
|
|
1144
|
+
checked: allVisibleSelected,
|
|
1145
|
+
onCheckedChange: toggleAll,
|
|
1146
|
+
disabled: selectableRows.length === 0,
|
|
1147
|
+
"aria-label": "Tout s\xE9lectionner"
|
|
1148
|
+
}
|
|
1149
|
+
) }),
|
|
1150
|
+
visibleColumns.map((column) => {
|
|
1151
|
+
const label2 = headerText(column);
|
|
1152
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1153
|
+
TableHead,
|
|
1154
|
+
{
|
|
1155
|
+
style: { width: widths[column.key] ?? column.width },
|
|
1156
|
+
className: cn(
|
|
1157
|
+
"relative",
|
|
1158
|
+
headClass,
|
|
1159
|
+
alignOf(column) === "right" && "text-right",
|
|
1160
|
+
column.hideOnMobile && "hidden md:table-cell"
|
|
1161
|
+
),
|
|
1162
|
+
"aria-sort": !column.sortable ? void 0 : state.sort?.key === column.key ? state.sort.direction === "asc" ? "ascending" : "descending" : "none",
|
|
1163
|
+
children: [
|
|
1164
|
+
column.sortable ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1165
|
+
"button",
|
|
1166
|
+
{
|
|
1167
|
+
type: "button",
|
|
1168
|
+
onClick: () => toggleSort(column.key),
|
|
1169
|
+
className: "inline-flex cursor-pointer items-center gap-1 uppercase hover:text-foreground",
|
|
1170
|
+
children: [
|
|
1171
|
+
column.header,
|
|
1172
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1173
|
+
SortGlyph,
|
|
1174
|
+
{
|
|
1175
|
+
direction: state.sort?.key === column.key ? state.sort.direction : null
|
|
1176
|
+
}
|
|
1177
|
+
)
|
|
1178
|
+
]
|
|
1179
|
+
}
|
|
1180
|
+
) : column.header,
|
|
1181
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1182
|
+
ResizeHandle,
|
|
1183
|
+
{
|
|
1184
|
+
label: label2,
|
|
1185
|
+
onResize: (delta, from) => setWidths((current) => ({
|
|
1186
|
+
...current,
|
|
1187
|
+
[column.key]: Math.max(MIN_COLUMN_WIDTH_PX, from + delta)
|
|
1188
|
+
}))
|
|
1189
|
+
}
|
|
1190
|
+
)
|
|
1191
|
+
]
|
|
1192
|
+
},
|
|
1193
|
+
column.key
|
|
1194
|
+
);
|
|
1195
|
+
}),
|
|
1196
|
+
rowActions && /* @__PURE__ */ jsxRuntime.jsx(TableHead, { className: cn("w-12", headClass), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Actions" }) })
|
|
1197
|
+
] }) }),
|
|
1198
|
+
/* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: error ? /* @__PURE__ */ jsxRuntime.jsx(StatusRow, { colSpan: columnCount, tone: "error", children: error }) : loading ? /* @__PURE__ */ jsxRuntime.jsx(SkeletonRows, { columns: columnCount, compact }) : pageRows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(StatusRow, { colSpan: columnCount, children: empty }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1199
|
+
spaceAbove > 0 && /* @__PURE__ */ jsxRuntime.jsx("tr", { "aria-hidden": true, style: { height: spaceAbove } }),
|
|
1200
|
+
renderedRows.map(({ row, index }) => {
|
|
1201
|
+
const detail = renderExpanded?.(row.original) ?? null;
|
|
1202
|
+
const isExpanded = detail !== null && expanded.has(row.id);
|
|
1203
|
+
const menu = rowActions?.(row.original) ?? [];
|
|
1204
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(React2__namespace.Fragment, { children: [
|
|
1205
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1206
|
+
TableRow,
|
|
1070
1207
|
{
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1208
|
+
ref: virtualise ? virtualizer.measureElement : void 0,
|
|
1209
|
+
"data-index": index,
|
|
1210
|
+
"data-state": selected.has(row.id) ? "selected" : void 0,
|
|
1211
|
+
className: onRowClick ? "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset" : "hover:bg-transparent",
|
|
1212
|
+
tabIndex: onRowClick ? 0 : void 0,
|
|
1213
|
+
onClick: onRowClick ? (event) => {
|
|
1214
|
+
if (opensRow(event)) onRowClick(row.original);
|
|
1215
|
+
} : void 0,
|
|
1216
|
+
onKeyDown: onRowClick ? (event) => {
|
|
1217
|
+
if (event.target !== event.currentTarget) return;
|
|
1218
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1219
|
+
event.preventDefault();
|
|
1220
|
+
onRowClick(row.original);
|
|
1221
|
+
} : void 0,
|
|
1074
1222
|
children: [
|
|
1075
|
-
|
|
1223
|
+
expandable && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1224
|
+
TableCell,
|
|
1225
|
+
{
|
|
1226
|
+
className: cellClass,
|
|
1227
|
+
onClick: (event) => event.stopPropagation(),
|
|
1228
|
+
children: detail !== null && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1229
|
+
"button",
|
|
1230
|
+
{
|
|
1231
|
+
type: "button",
|
|
1232
|
+
"aria-expanded": isExpanded,
|
|
1233
|
+
"aria-label": `${isExpanded ? "Replier" : "D\xE9plier"} ${rowLabel(row.original)}`,
|
|
1234
|
+
onClick: () => toggleExpanded(row.id),
|
|
1235
|
+
className: "inline-flex size-6 cursor-pointer items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
1236
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1237
|
+
"span",
|
|
1238
|
+
{
|
|
1239
|
+
"aria-hidden": true,
|
|
1240
|
+
className: cn(
|
|
1241
|
+
"text-xs transition-transform",
|
|
1242
|
+
isExpanded && "rotate-90"
|
|
1243
|
+
),
|
|
1244
|
+
children: "\u25B6"
|
|
1245
|
+
}
|
|
1246
|
+
)
|
|
1247
|
+
}
|
|
1248
|
+
)
|
|
1249
|
+
}
|
|
1250
|
+
),
|
|
1251
|
+
selectable && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1252
|
+
TableCell,
|
|
1253
|
+
{
|
|
1254
|
+
className: cellClass,
|
|
1255
|
+
onClick: (event) => event.stopPropagation(),
|
|
1256
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1257
|
+
Checkbox,
|
|
1258
|
+
{
|
|
1259
|
+
checked: selected.has(row.id),
|
|
1260
|
+
disabled: !canSelect(row.original),
|
|
1261
|
+
onCheckedChange: () => toggleSelected(row.id),
|
|
1262
|
+
"aria-label": `S\xE9lectionner ${rowLabel(row.original)}`
|
|
1263
|
+
}
|
|
1264
|
+
)
|
|
1265
|
+
}
|
|
1266
|
+
),
|
|
1267
|
+
row.getVisibleCells().map((cell) => {
|
|
1268
|
+
const column = visibleColumns.find((c) => c.key === cell.column.id);
|
|
1269
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1270
|
+
TableCell,
|
|
1271
|
+
{
|
|
1272
|
+
className: cn(cellClass, column && cellAlignClass(column)),
|
|
1273
|
+
children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
1274
|
+
},
|
|
1275
|
+
cell.id
|
|
1276
|
+
);
|
|
1277
|
+
}),
|
|
1278
|
+
rowActions && // Menu items render in a portal, but React events still
|
|
1279
|
+
// bubble through this cell: stopping them here is what
|
|
1280
|
+
// keeps a menu choice from also opening the row.
|
|
1076
1281
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1077
|
-
|
|
1282
|
+
TableCell,
|
|
1078
1283
|
{
|
|
1079
|
-
|
|
1284
|
+
className: cn("text-right", cellClass),
|
|
1285
|
+
onClick: (event) => event.stopPropagation(),
|
|
1286
|
+
onKeyDown: (event) => event.stopPropagation(),
|
|
1287
|
+
children: menu.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1288
|
+
DropdownMenu,
|
|
1289
|
+
{
|
|
1290
|
+
items: menu,
|
|
1291
|
+
trigger: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1292
|
+
Button,
|
|
1293
|
+
{
|
|
1294
|
+
variant: "ghost",
|
|
1295
|
+
size: "icon",
|
|
1296
|
+
className: "size-8",
|
|
1297
|
+
"aria-label": `Actions \u2014 ${rowLabel(row.original)}`,
|
|
1298
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, children: "\u22EF" })
|
|
1299
|
+
}
|
|
1300
|
+
)
|
|
1301
|
+
}
|
|
1302
|
+
)
|
|
1080
1303
|
}
|
|
1081
1304
|
)
|
|
1082
1305
|
]
|
|
1083
1306
|
}
|
|
1084
|
-
)
|
|
1085
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
/* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: error ? /* @__PURE__ */ jsxRuntime.jsx(StatusRow, { colSpan: columnCount, tone: "error", children: error }) : loading ? /* @__PURE__ */ jsxRuntime.jsx(SkeletonRows, { columns: columnCount }) : facetedRows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(StatusRow, { colSpan: columnCount, children: empty }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1102
|
-
spaceAbove > 0 && /* @__PURE__ */ jsxRuntime.jsx("tr", { "aria-hidden": true, style: { height: spaceAbove } }),
|
|
1103
|
-
renderedRows.map((row) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1104
|
-
TableRow,
|
|
1105
|
-
{
|
|
1106
|
-
"data-state": selected.has(row.id) ? "selected" : void 0,
|
|
1107
|
-
className: onRowClick ? "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset" : "hover:bg-transparent",
|
|
1108
|
-
tabIndex: onRowClick ? 0 : void 0,
|
|
1109
|
-
onClick: onRowClick ? () => onRowClick(row.original) : void 0,
|
|
1110
|
-
onKeyDown: onRowClick ? (event) => {
|
|
1111
|
-
if (event.target !== event.currentTarget) return;
|
|
1112
|
-
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1113
|
-
event.preventDefault();
|
|
1114
|
-
onRowClick(row.original);
|
|
1115
|
-
} : void 0,
|
|
1116
|
-
children: [
|
|
1117
|
-
selectable && /* @__PURE__ */ jsxRuntime.jsx(TableCell, { onClick: (event) => event.stopPropagation(), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1118
|
-
Checkbox,
|
|
1119
|
-
{
|
|
1120
|
-
checked: selected.has(row.id),
|
|
1121
|
-
onCheckedChange: () => toggleSelected(row.id),
|
|
1122
|
-
"aria-label": `S\xE9lectionner ${row.id}`
|
|
1123
|
-
}
|
|
1124
|
-
) }),
|
|
1125
|
-
row.getVisibleCells().map((cell) => {
|
|
1126
|
-
const column = visibleColumns.find((c) => c.key === cell.column.id);
|
|
1127
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1128
|
-
TableCell,
|
|
1129
|
-
{
|
|
1130
|
-
className: column?.align === "right" ? "text-right" : void 0,
|
|
1131
|
-
children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
1132
|
-
},
|
|
1133
|
-
cell.id
|
|
1134
|
-
);
|
|
1135
|
-
})
|
|
1136
|
-
]
|
|
1137
|
-
},
|
|
1138
|
-
row.id
|
|
1139
|
-
)),
|
|
1140
|
-
spaceBelow > 0 && /* @__PURE__ */ jsxRuntime.jsx("tr", { "aria-hidden": true, style: { height: spaceBelow } })
|
|
1141
|
-
] }) })
|
|
1142
|
-
] })
|
|
1307
|
+
),
|
|
1308
|
+
isExpanded && /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "bg-muted/30 hover:bg-muted/30", children: /* @__PURE__ */ jsxRuntime.jsx(TableCell, { colSpan: columnCount, className: cellClass, children: detail }) })
|
|
1309
|
+
] }, row.id);
|
|
1310
|
+
}),
|
|
1311
|
+
spaceBelow > 0 && /* @__PURE__ */ jsxRuntime.jsx("tr", { "aria-hidden": true, style: { height: spaceBelow } })
|
|
1312
|
+
] }) }),
|
|
1313
|
+
hasFooter && !error && !loading && pageRows.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("tfoot", { className: "border-t bg-muted/40 font-medium", children: /* @__PURE__ */ jsxRuntime.jsxs(TableRow, { className: "hover:bg-transparent", children: [
|
|
1314
|
+
leadingCount > 0 && /* @__PURE__ */ jsxRuntime.jsx(TableCell, { colSpan: leadingCount, className: cellClass }),
|
|
1315
|
+
visibleColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { className: cn(cellClass, cellAlignClass(column)), children: renderFooter(
|
|
1316
|
+
column,
|
|
1317
|
+
facetedRows.map((row) => row.original)
|
|
1318
|
+
) }, column.key)),
|
|
1319
|
+
rowActions && /* @__PURE__ */ jsxRuntime.jsx(TableCell, { className: cellClass })
|
|
1320
|
+
] }) })
|
|
1321
|
+
]
|
|
1322
|
+
}
|
|
1323
|
+
)
|
|
1143
1324
|
}
|
|
1144
1325
|
),
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1326
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1327
|
+
Pager,
|
|
1328
|
+
{
|
|
1329
|
+
pagination,
|
|
1330
|
+
client: paged && facetedRows.length > pageSize ? {
|
|
1331
|
+
page: currentPage,
|
|
1332
|
+
pageCount,
|
|
1333
|
+
pageSize,
|
|
1334
|
+
total: facetedRows.length,
|
|
1335
|
+
onPage: setPage
|
|
1336
|
+
} : void 0,
|
|
1337
|
+
className: embedded ? "px-6 pb-4" : void 0
|
|
1338
|
+
}
|
|
1339
|
+
)
|
|
1340
|
+
] });
|
|
1341
|
+
}
|
|
1342
|
+
function opensRow(event) {
|
|
1343
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return false;
|
|
1344
|
+
const control = event.target instanceof Element ? event.target.closest('a, button, input, label, select, textarea, [role="checkbox"]') : null;
|
|
1345
|
+
if (control && control !== event.currentTarget && event.currentTarget.contains(control)) {
|
|
1346
|
+
return false;
|
|
1347
|
+
}
|
|
1348
|
+
const selection = window.getSelection();
|
|
1349
|
+
return !selection || selection.isCollapsed;
|
|
1350
|
+
}
|
|
1351
|
+
function Pager({
|
|
1352
|
+
pagination,
|
|
1353
|
+
client,
|
|
1354
|
+
className
|
|
1355
|
+
}) {
|
|
1356
|
+
if (pagination && "onLoadMore" in pagination) {
|
|
1357
|
+
if (!pagination.hasMore) return null;
|
|
1358
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex justify-center", className), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1359
|
+
Button,
|
|
1360
|
+
{
|
|
1361
|
+
variant: "outline",
|
|
1362
|
+
size: "sm",
|
|
1363
|
+
disabled: pagination.loading,
|
|
1364
|
+
onClick: pagination.onLoadMore,
|
|
1365
|
+
children: pagination.loading ? "Chargement\u2026" : "Charger plus"
|
|
1366
|
+
}
|
|
1367
|
+
) });
|
|
1368
|
+
}
|
|
1369
|
+
const nav = pagination ? pagination : client ? {
|
|
1370
|
+
hasPrevious: client.page > 0,
|
|
1371
|
+
hasNext: client.page < client.pageCount - 1,
|
|
1372
|
+
onPrevious: () => client.onPage(client.page - 1),
|
|
1373
|
+
onNext: () => client.onPage(client.page + 1),
|
|
1374
|
+
label: `${client.page * client.pageSize + 1}\u2013${Math.min(
|
|
1375
|
+
(client.page + 1) * client.pageSize,
|
|
1376
|
+
client.total
|
|
1377
|
+
)} sur ${client.total}`
|
|
1378
|
+
} : null;
|
|
1379
|
+
if (!nav) return null;
|
|
1380
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex items-center justify-end gap-2", className), children: [
|
|
1381
|
+
nav.label !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-auto text-xs text-muted-foreground tabular-nums", children: nav.label }),
|
|
1382
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "sm", disabled: !nav.hasPrevious, onClick: nav.onPrevious, children: "Pr\xE9c\xE9dent" }),
|
|
1383
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "sm", disabled: !nav.hasNext, onClick: nav.onNext, children: "Suivant" })
|
|
1167
1384
|
] });
|
|
1168
1385
|
}
|
|
1386
|
+
var NUMERIC_FORMATS = /* @__PURE__ */ new Set([
|
|
1387
|
+
"number",
|
|
1388
|
+
"currency",
|
|
1389
|
+
"percent"
|
|
1390
|
+
]);
|
|
1391
|
+
var EMPTY_CELL = "\u2014";
|
|
1392
|
+
function rawValue(column, row) {
|
|
1393
|
+
return column.value ? column.value(row) : row[column.key];
|
|
1394
|
+
}
|
|
1395
|
+
function headerText(column) {
|
|
1396
|
+
return typeof column.header === "string" ? column.header : column.key;
|
|
1397
|
+
}
|
|
1398
|
+
function alignOf(column) {
|
|
1399
|
+
return column.align ?? (NUMERIC_FORMATS.has(column.format) ? "right" : "left");
|
|
1400
|
+
}
|
|
1401
|
+
function cellAlignClass(column) {
|
|
1402
|
+
return cn(
|
|
1403
|
+
alignOf(column) === "right" && "text-right",
|
|
1404
|
+
NUMERIC_FORMATS.has(column.format) && "tabular-nums",
|
|
1405
|
+
column.hideOnMobile && "hidden md:table-cell"
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
var CALENDAR_DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
1409
|
+
function formatCellValue(value, format2 = "text", currency = "EUR") {
|
|
1410
|
+
if (value == null || value === "") return EMPTY_CELL;
|
|
1411
|
+
switch (format2) {
|
|
1412
|
+
case "number":
|
|
1413
|
+
case "currency":
|
|
1414
|
+
case "percent": {
|
|
1415
|
+
const number = typeof value === "number" ? value : Number(value);
|
|
1416
|
+
if (Number.isNaN(number)) return String(value);
|
|
1417
|
+
const options = format2 === "currency" ? { style: "currency", currency } : format2 === "percent" ? { style: "percent", maximumFractionDigits: 1 } : { maximumFractionDigits: 2 };
|
|
1418
|
+
return new Intl.NumberFormat("fr-FR", options).format(number);
|
|
1419
|
+
}
|
|
1420
|
+
case "date": {
|
|
1421
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
1422
|
+
if (Number.isNaN(date.getTime())) return String(value);
|
|
1423
|
+
return date.toLocaleDateString("fr-FR", {
|
|
1424
|
+
day: "2-digit",
|
|
1425
|
+
month: "2-digit",
|
|
1426
|
+
year: "numeric",
|
|
1427
|
+
...typeof value === "string" && CALENDAR_DAY.test(value) ? { timeZone: "UTC" } : {}
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
case "text":
|
|
1431
|
+
return String(value);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
function renderFooter(column, rows) {
|
|
1435
|
+
const content = typeof column.footer === "function" ? column.footer(rows) : column.footer;
|
|
1436
|
+
return typeof content === "number" ? formatCellValue(content, column.format ?? "number", column.currency) : content;
|
|
1437
|
+
}
|
|
1169
1438
|
function ResizeHandle({
|
|
1170
1439
|
label,
|
|
1171
1440
|
onResize
|
|
@@ -1207,15 +1476,15 @@ function StatusRow({
|
|
|
1207
1476
|
{
|
|
1208
1477
|
colSpan,
|
|
1209
1478
|
className: cn(
|
|
1210
|
-
"text-sm",
|
|
1479
|
+
"py-10 text-center text-sm",
|
|
1211
1480
|
tone === "error" ? "text-status-blocked" : "text-muted-foreground"
|
|
1212
1481
|
),
|
|
1213
1482
|
children
|
|
1214
1483
|
}
|
|
1215
1484
|
) });
|
|
1216
1485
|
}
|
|
1217
|
-
function SkeletonRows({ columns }) {
|
|
1218
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: Array.from({ length: 5 }, (_, row) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "hover:bg-transparent", children: Array.from({ length: columns }, (_2, cell) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block h-3 w-full animate-pulse rounded bg-muted" }) }, cell)) }, row)) });
|
|
1486
|
+
function SkeletonRows({ columns, compact }) {
|
|
1487
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: Array.from({ length: 5 }, (_, row) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "hover:bg-transparent", children: Array.from({ length: columns }, (_2, cell) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { className: compact ? "px-3 py-1.5" : void 0, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block h-3 w-full animate-pulse rounded bg-muted" }) }, cell)) }, row)) });
|
|
1219
1488
|
}
|
|
1220
1489
|
var VALUELESS = /* @__PURE__ */ new Set(["empty", "nempty"]);
|
|
1221
1490
|
var SINGLE_VALUE = /* @__PURE__ */ new Set([
|
|
@@ -2432,6 +2701,7 @@ exports.comparisonRange = comparisonRange;
|
|
|
2432
2701
|
exports.copyToClipboard = copyToClipboard;
|
|
2433
2702
|
exports.downloadBlob = downloadBlob;
|
|
2434
2703
|
exports.downloadCsv = downloadCsv;
|
|
2704
|
+
exports.formatCellValue = formatCellValue;
|
|
2435
2705
|
exports.formatPeriod = formatPeriod;
|
|
2436
2706
|
exports.formatRange = formatRange;
|
|
2437
2707
|
exports.makePeriod = makePeriod;
|