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