@krak-stack/registry 0.10.11 → 0.10.13

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.
@@ -1,6 +1,8 @@
1
1
  // ../../src/components/ui/data-table.tsx
2
2
  import { useAtom, useAtomSet } from "@effect/atom-react";
3
+ import { ScrollArea as ScrollAreaPrimitive2 } from "@base-ui/react/scroll-area";
3
4
  import { BrowserKeyValueStore } from "@effect/platform-browser";
5
+ import { useVirtualizer, useWindowVirtualizer } from "@tanstack/react-virtual";
4
6
  import { DateTime as DateTime2, Effect as Effect2, Formatter, Option as Option2, Schema as Schema2, Stream } from "effect";
5
7
  import { Csv } from "effect/encoding";
6
8
  import { AsyncResult, Atom } from "effect/reactivity";
@@ -756,7 +758,7 @@ function Pagination({
756
758
  page,
757
759
  pageCount,
758
760
  pageSize,
759
- pageSizes = [10, 20, 30, 40, 50],
761
+ pageSizes = [20, 50, 100],
760
762
  selectedRows = 0,
761
763
  showResults = true,
762
764
  totalRows
@@ -1164,14 +1166,15 @@ var ColumnFilters = Schema.declare(Schema.is(ColumnFiltersArray), {
1164
1166
  toCodec: () => Schema.link()(ColumnFiltersArray, SchemaTransformation.passthrough()),
1165
1167
  toCodecStringTree: () => Schema.link()(Schema.fromJsonString(ColumnFiltersArray), SchemaTransformation.passthrough())
1166
1168
  });
1169
+ var DEFAULT_PAGE_SIZE = 100;
1167
1170
  var Query = Schema.Struct({
1168
1171
  page: Schema.optional(Schema.Union([Schema.Finite, Schema.FiniteFromString]).check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))).pipe(Schema.decodeTo(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)), {
1169
1172
  decode: SchemaGetter.withDefault(Effect.succeed(0)),
1170
1173
  encode: SchemaGetter.transformOptional(Option.filter((page) => page !== 0))
1171
1174
  })),
1172
1175
  pageSize: Schema.optional(Schema.Union([Schema.Finite, Schema.FiniteFromString]).check(Schema.isInt(), Schema.isBetween({ minimum: 1, maximum: 100 }))).pipe(Schema.decodeTo(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })), {
1173
- decode: SchemaGetter.withDefault(Effect.succeed(20)),
1174
- encode: SchemaGetter.transformOptional(Option.filter((pageSize) => pageSize !== 20))
1176
+ decode: SchemaGetter.withDefault(Effect.succeed(DEFAULT_PAGE_SIZE)),
1177
+ encode: SchemaGetter.transformOptional(Option.filter((pageSize) => pageSize !== DEFAULT_PAGE_SIZE))
1175
1178
  })),
1176
1179
  globalFilter: Schema.optional(Schema.String),
1177
1180
  sort: Schema.optional(SortParams),
@@ -1183,7 +1186,7 @@ var Query = Schema.Struct({
1183
1186
  examples: [
1184
1187
  {
1185
1188
  page: 0,
1186
- pageSize: 20,
1189
+ pageSize: DEFAULT_PAGE_SIZE,
1187
1190
  globalFilter: "housing",
1188
1191
  sort: [
1189
1192
  { id: "publicName", direction: "desc" },
@@ -1409,7 +1412,7 @@ var DEFAULT_WIDTH = 208;
1409
1412
  var DEFAULT_MAX_WIDTH = 640;
1410
1413
  var DEFAULT_QUERY = {
1411
1414
  page: 0,
1412
- pageSize: 20
1415
+ pageSize: DEFAULT_PAGE_SIZE
1413
1416
  };
1414
1417
  var DEFAULT_UI_STATE = {
1415
1418
  columnVisibility: {},
@@ -1795,7 +1798,7 @@ var buildDataTableModel = (store) => {
1795
1798
  const selection = store.config.features.selection;
1796
1799
  const rowId = selection && selection.getRowId || store.config.getRowId || undefined;
1797
1800
  const rows = buildDataTableRows(store.rowData, columns, rowId);
1798
- const pagination = store.config.features.pagination ?? { mode: "client" };
1801
+ const pagination = store.config.features.pagination ?? false;
1799
1802
  const server = pagination !== false && pagination.mode === "server";
1800
1803
  const filteredRows = server ? [...rows] : filterDataTableColumnRows(filterDataTableRows(rows, columns, store.state.globalFilter ?? "", store.config.locale), columns, store.state.filters ?? []);
1801
1804
  const sortedRows = server ? filteredRows : sortDataTableRows(filteredRows, columns, store.state.sort ?? []);
@@ -1808,7 +1811,7 @@ var buildDataTableModel = (store) => {
1808
1811
  filteredRows,
1809
1812
  sortedRows,
1810
1813
  pageRows,
1811
- pageCount: Math.max(1, Math.ceil(totalRows / Math.max(1, store.state.pageSize))),
1814
+ pageCount: pagination ? Math.max(1, Math.ceil(totalRows / Math.max(1, store.state.pageSize))) : 1,
1812
1815
  totalRows
1813
1816
  };
1814
1817
  };
@@ -1842,7 +1845,13 @@ var groupDataTableRows = (rows, fields, depth = 0, parentKey = "") => {
1842
1845
  const ids = field.getRowGroupIds?.(row.data) ?? [
1843
1846
  field.getGroupId(row.data)
1844
1847
  ];
1845
- ids.forEach((id) => groups.set(id, [...groups.get(id) ?? [], row]));
1848
+ ids.forEach((id) => {
1849
+ const group = groups.get(id);
1850
+ if (group)
1851
+ group.push(row);
1852
+ else
1853
+ groups.set(id, [row]);
1854
+ });
1846
1855
  });
1847
1856
  return Array.from(groups, ([groupId, groupRows]) => {
1848
1857
  const segment = `${encodeURIComponent(field.id)}:${encodeURIComponent(groupId)}`;
@@ -2052,20 +2061,18 @@ var DataTableRowActions = ({
2052
2061
  });
2053
2062
  };
2054
2063
  var DataTableRowActionMenu = ({
2055
- tableAtom
2064
+ tableAtom,
2065
+ row
2056
2066
  }) => {
2057
2067
  const [store] = useTableAtom(tableAtom);
2058
- const rowId = useRequiredId(RowIdContext);
2059
- const model = deriveModel(store);
2060
- const row = model.sortedRows.find((candidate) => candidate.id === rowId);
2061
- if (!row)
2062
- return null;
2068
+ const rowId = row.id;
2063
2069
  const rowActions = store.config.features.rowActions || undefined;
2064
- const visibleRows = model.pageRows;
2065
- const rowIndex = visibleRows.findIndex((candidate) => candidate.id === rowId);
2066
2070
  const reordering = store.config.features.reordering;
2067
2071
  const reorderActions = [];
2068
2072
  if (reordering && canReorderRows(store)) {
2073
+ const model = deriveModel(store);
2074
+ const visibleRows = model.pageRows;
2075
+ const rowIndex = visibleRows.findIndex((candidate) => candidate.id === rowId);
2069
2076
  const move = (targetIndex) => reordering.onReorder(reorderDataTableRows(model.rows, rowId, visibleRows[targetIndex].id));
2070
2077
  if (rowIndex > 0) {
2071
2078
  reorderActions.push({
@@ -2132,7 +2139,7 @@ var DataTableToolbar = ({
2132
2139
  }
2133
2140
  };
2134
2141
  return /* @__PURE__ */ jsxs9("div", {
2135
- className: "flex flex-col gap-2 pb-4",
2142
+ className: cn("grid min-w-0 items-center gap-2 pb-4", features.search !== false && "md:grid-cols-[minmax(12rem,1fr)_minmax(0,auto)]"),
2136
2143
  children: [
2137
2144
  features.search !== false ? /* @__PURE__ */ jsxs9("div", {
2138
2145
  className: "relative min-w-0",
@@ -2165,9 +2172,10 @@ var DataTableToolbar = ({
2165
2172
  ]
2166
2173
  }) : null,
2167
2174
  /* @__PURE__ */ jsx15("div", {
2168
- className: "-m-1 flex overflow-x-auto p-1",
2175
+ className: "-m-1 flex min-w-0 overflow-x-auto p-1",
2169
2176
  children: /* @__PURE__ */ jsxs9(Menubar2, {
2170
- className: "h-auto w-max min-w-full justify-start bg-transparent shadow-none [&_[data-slot=menubar-trigger]]:gap-2 [&_[data-slot=menubar-trigger]_svg]:size-4",
2177
+ modal: false,
2178
+ className: "border-input h-auto w-max min-w-full justify-start bg-transparent [&_[data-slot=menubar-trigger]]:gap-2 [&_[data-slot=menubar-trigger]_svg]:size-4",
2171
2179
  children: [
2172
2180
  visibleBulkActions.length ? /* @__PURE__ */ jsxs9(MenubarMenu, {
2173
2181
  children: [
@@ -2329,7 +2337,7 @@ var DataTableToolbar = ({
2329
2337
  }),
2330
2338
  exportFeature && exportFailed ? /* @__PURE__ */ jsx15("p", {
2331
2339
  role: "alert",
2332
- className: "text-destructive text-sm",
2340
+ className: "text-destructive col-span-full text-sm",
2333
2341
  children: labels.exportFailed ?? dataTableMessages(store.config.locale).exportFailed
2334
2342
  }) : null
2335
2343
  ]
@@ -2610,6 +2618,7 @@ var FilterMenu = ({
2610
2618
  children: [
2611
2619
  /* @__PURE__ */ jsx15(ListFilter, {}),
2612
2620
  /* @__PURE__ */ jsx15("span", {
2621
+ className: "hidden sm:inline",
2613
2622
  children: store.config.labels.filters
2614
2623
  }),
2615
2624
  filters.length ? /* @__PURE__ */ jsx15(Badge, {
@@ -3066,18 +3075,20 @@ var toggleRow = (store, setStore, rowId, selected) => changeState(setStore, (sta
3066
3075
  return { ...state, rowSelection };
3067
3076
  });
3068
3077
  var TableDataRow = ({
3069
- tableAtom
3078
+ tableAtom,
3079
+ row,
3080
+ virtualIndex,
3081
+ measureRef
3070
3082
  }) => {
3071
3083
  const [store, setStore] = useTableAtom(tableAtom);
3072
- const rowId = useRequiredId(RowIdContext);
3073
3084
  const model = deriveModel(store);
3074
- const row = model.sortedRows.find((candidate) => candidate.id === rowId);
3075
- if (!row)
3076
- return null;
3077
3085
  const selection = store.config.features.selection;
3078
3086
  const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
3079
3087
  const draggable = canDragRows(store);
3080
3088
  return /* @__PURE__ */ jsxs9(TableRow2, {
3089
+ ref: measureRef,
3090
+ "data-index": virtualIndex,
3091
+ "aria-rowindex": virtualIndex === undefined ? undefined : virtualIndex + 2,
3081
3092
  className: cn("group/row data-[drop-position=before]:[&>td]:border-primary data-[drop-position=after]:[&>td]:border-primary h-16 data-[drag-source=true]:opacity-40 data-[drop-position=after]:[&>td]:border-b-2 data-[drop-position=before]:[&>td]:border-t-2", store.config.onRowClicked && "cursor-pointer"),
3082
3093
  "data-state": store.state.rowSelection[row.id] && "selected",
3083
3094
  "data-table-row": row.id,
@@ -3120,6 +3131,7 @@ var TableDataRow = ({
3120
3131
  children: /* @__PURE__ */ jsx15("div", {
3121
3132
  className: "flex h-16 items-center justify-end pr-1",
3122
3133
  children: /* @__PURE__ */ jsx15(DataTableRowActionMenu, {
3134
+ row,
3123
3135
  tableAtom
3124
3136
  })
3125
3137
  })
@@ -3169,70 +3181,88 @@ var GroupActions = ({
3169
3181
  ]
3170
3182
  });
3171
3183
  };
3184
+ var GroupHeaderRow = ({
3185
+ tableAtom,
3186
+ section,
3187
+ colSpan,
3188
+ virtualIndex,
3189
+ measureRef
3190
+ }) => {
3191
+ const [store, setStore] = useTableAtom(tableAtom);
3192
+ const collapsed = !!store.state.collapsedGroups[section.key];
3193
+ return /* @__PURE__ */ jsx15(TableRow2, {
3194
+ ref: measureRef,
3195
+ "data-index": virtualIndex,
3196
+ "aria-rowindex": virtualIndex === undefined ? undefined : virtualIndex + 2,
3197
+ className: "bg-muted/40 hover:bg-accent! cursor-pointer",
3198
+ onClick: () => changeState(setStore, (state) => ({
3199
+ ...state,
3200
+ collapsedGroups: {
3201
+ ...state.collapsedGroups,
3202
+ [section.key]: !collapsed
3203
+ }
3204
+ })),
3205
+ children: /* @__PURE__ */ jsx15(TableCell2, {
3206
+ className: "p-0",
3207
+ colSpan,
3208
+ children: /* @__PURE__ */ jsxs9("div", {
3209
+ className: "sticky left-0 flex w-[100cqw] max-w-full items-center gap-2 py-2 pr-1 pl-2",
3210
+ children: [
3211
+ /* @__PURE__ */ jsxs9("button", {
3212
+ "aria-expanded": !collapsed,
3213
+ className: "flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-left font-medium",
3214
+ style: { paddingLeft: section.depth * 20 },
3215
+ type: "button",
3216
+ children: [
3217
+ collapsed ? /* @__PURE__ */ jsx15(ChevronRight2, {
3218
+ className: "size-4 shrink-0"
3219
+ }) : /* @__PURE__ */ jsx15(ChevronDown, {
3220
+ className: "size-4 shrink-0"
3221
+ }),
3222
+ /* @__PURE__ */ jsx15("span", {
3223
+ className: "min-w-0 flex-1 truncate",
3224
+ children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
3225
+ })
3226
+ ]
3227
+ }),
3228
+ /* @__PURE__ */ jsx15(Badge, {
3229
+ className: "shrink-0",
3230
+ variant: "secondary",
3231
+ children: section.rows.length
3232
+ }),
3233
+ /* @__PURE__ */ jsx15(GroupActions, {
3234
+ actions: section.field.actions,
3235
+ groupId: section.groupId,
3236
+ title: section.field.actionsLabel ?? store.config.labels.actions
3237
+ })
3238
+ ]
3239
+ })
3240
+ })
3241
+ });
3242
+ };
3172
3243
  var GroupedTable = ({
3173
3244
  tableAtom,
3174
3245
  sections
3175
3246
  }) => {
3176
- const [store, setStore] = useTableAtom(tableAtom);
3247
+ const [store] = useTableAtom(tableAtom);
3177
3248
  const model = deriveModel(store);
3178
3249
  const extra = (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3179
3250
  const renderSections = (items) => items.flatMap((section) => {
3180
3251
  const collapsed = !!store.state.collapsedGroups[section.key];
3181
3252
  const targetKey = getGroupDropKey(section.field.id, section.groupId);
3182
- const toggleCollapsed = () => changeState(setStore, (state) => ({
3183
- ...state,
3184
- collapsedGroups: {
3185
- ...state.collapsedGroups,
3186
- [section.key]: !collapsed
3187
- }
3188
- }));
3189
3253
  const body = /* @__PURE__ */ jsxs9(TableBody2, {
3190
3254
  className: "data-[drop-target=true]:outline-primary relative data-[drop-target=true]:z-30 data-[drop-target=true]:outline-2 data-[drop-target=true]:-outline-offset-2 data-[drop-target=true]:[&>tr]:border-transparent data-[drop-target=true]:[&>tr>td:last-child]:z-0",
3191
3255
  "data-table-group": section.field.onMoveToGroup ? targetKey : undefined,
3192
3256
  children: [
3193
- /* @__PURE__ */ jsx15(TableRow2, {
3194
- className: "bg-muted/40 hover:bg-accent! cursor-pointer",
3195
- onClick: toggleCollapsed,
3196
- children: /* @__PURE__ */ jsx15(TableCell2, {
3197
- className: "p-0",
3198
- colSpan: model.visibleColumns.length + extra,
3199
- children: /* @__PURE__ */ jsxs9("div", {
3200
- className: "sticky left-0 flex w-[100cqw] max-w-full items-center gap-2 py-2 pr-1 pl-2",
3201
- children: [
3202
- /* @__PURE__ */ jsxs9("button", {
3203
- "aria-expanded": !collapsed,
3204
- className: "flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-left font-medium",
3205
- style: { paddingLeft: section.depth * 20 },
3206
- type: "button",
3207
- children: [
3208
- collapsed ? /* @__PURE__ */ jsx15(ChevronRight2, {
3209
- className: "size-4 shrink-0"
3210
- }) : /* @__PURE__ */ jsx15(ChevronDown, {
3211
- className: "size-4 shrink-0"
3212
- }),
3213
- /* @__PURE__ */ jsx15("span", {
3214
- className: "min-w-0 flex-1 truncate",
3215
- children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
3216
- })
3217
- ]
3218
- }),
3219
- /* @__PURE__ */ jsx15(Badge, {
3220
- className: "shrink-0",
3221
- variant: "secondary",
3222
- children: section.rows.length
3223
- }),
3224
- /* @__PURE__ */ jsx15(GroupActions, {
3225
- actions: section.field.actions,
3226
- groupId: section.groupId,
3227
- title: section.field.actionsLabel ?? store.config.labels.actions
3228
- })
3229
- ]
3230
- })
3231
- })
3257
+ /* @__PURE__ */ jsx15(GroupHeaderRow, {
3258
+ tableAtom,
3259
+ section,
3260
+ colSpan: model.visibleColumns.length + extra
3232
3261
  }),
3233
3262
  !collapsed && !section.children.length ? section.rows.length ? section.rows.map((row) => /* @__PURE__ */ jsx15(RowIdContext.Provider, {
3234
3263
  value: row.id,
3235
3264
  children: /* @__PURE__ */ jsx15(TableDataRow, {
3265
+ row,
3236
3266
  tableAtom
3237
3267
  })
3238
3268
  }, `${section.key}:${row.id}`)) : [
@@ -3430,7 +3460,8 @@ var ColumnHeaderMenu = ({
3430
3460
  });
3431
3461
  };
3432
3462
  var DataTableHeader = ({
3433
- tableAtom
3463
+ tableAtom,
3464
+ sticky
3434
3465
  }) => {
3435
3466
  const [store, setStore] = useTableAtom(tableAtom);
3436
3467
  const model = deriveModel(store);
@@ -3441,7 +3472,9 @@ var DataTableHeader = ({
3441
3472
  const allSelected = selectableRows.length > 0 && selectableRows.every((row) => store.state.rowSelection[row.id]);
3442
3473
  const someSelected = selectableRows.some((row) => store.state.rowSelection[row.id]);
3443
3474
  return /* @__PURE__ */ jsx15(TableHeader2, {
3475
+ className: sticky ? "bg-background after:border-border sticky top-0 z-30 after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:border-b [&_tr]:border-b-0" : undefined,
3444
3476
  children: /* @__PURE__ */ jsxs9(TableRow2, {
3477
+ "aria-rowindex": sticky ? 1 : undefined,
3445
3478
  children: [
3446
3479
  selection ? /* @__PURE__ */ jsx15(TableHead2, {
3447
3480
  className: "w-10 pr-0",
@@ -3489,8 +3522,127 @@ var DataTableHeader = ({
3489
3522
  })
3490
3523
  });
3491
3524
  };
3525
+ var VirtualTableRows = ({
3526
+ tableAtom,
3527
+ rows,
3528
+ sections,
3529
+ viewport,
3530
+ colSpan
3531
+ }) => {
3532
+ const [{ state, config }] = useTableAtom(tableAtom);
3533
+ const { element: scrollElement, headerHeight } = viewport;
3534
+ const pageScroll = viewport.options.scroll === "page";
3535
+ const scrollMargin = viewport.pageOffset ?? headerHeight;
3536
+ const entries = useMemo2(() => {
3537
+ const result = [];
3538
+ const addSections = (groups) => {
3539
+ for (const section of groups) {
3540
+ result.push({ key: `${section.key}/header`, kind: "header", section });
3541
+ if (state.collapsedGroups[section.key])
3542
+ continue;
3543
+ if (section.children.length)
3544
+ addSections(section.children);
3545
+ else if (section.rows.length) {
3546
+ for (const row of section.rows) {
3547
+ result.push({
3548
+ key: `${section.key}/row:${row.id}`,
3549
+ kind: "data",
3550
+ row
3551
+ });
3552
+ }
3553
+ } else
3554
+ result.push({ key: `${section.key}/empty`, kind: "empty", section });
3555
+ }
3556
+ };
3557
+ if (sections.length)
3558
+ addSections(sections);
3559
+ else
3560
+ for (const row of rows)
3561
+ result.push({ key: `row:${row.id}`, kind: "data", row });
3562
+ return result;
3563
+ }, [rows, sections, state.collapsedGroups]);
3564
+ useLayoutEffect(() => {
3565
+ if (!pageScroll && scrollElement)
3566
+ scrollElement.scrollTop = 0;
3567
+ }, [
3568
+ pageScroll,
3569
+ scrollElement,
3570
+ state.page,
3571
+ state.pageSize,
3572
+ state.globalFilter,
3573
+ state.filters,
3574
+ state.sort,
3575
+ state.grouping
3576
+ ]);
3577
+ const options = {
3578
+ count: entries.length,
3579
+ getItemKey: useCallback((index) => entries[index].key, [entries]),
3580
+ estimateSize: () => viewport.options.estimateRowHeight ?? 64,
3581
+ overscan: viewport.options.overscan ?? 5,
3582
+ scrollMargin
3583
+ };
3584
+ const tableVirtualizer = useVirtualizer({
3585
+ ...options,
3586
+ enabled: !pageScroll,
3587
+ getScrollElement: () => scrollElement,
3588
+ scrollPaddingStart: headerHeight
3589
+ });
3590
+ const pageVirtualizer = useWindowVirtualizer({
3591
+ ...options,
3592
+ enabled: pageScroll && viewport.pageOffset !== undefined
3593
+ });
3594
+ const virtualizer = pageScroll ? pageVirtualizer : tableVirtualizer;
3595
+ const items = virtualizer.getVirtualItems();
3596
+ const first = items[0];
3597
+ const last = items.at(-1);
3598
+ const before = first ? first.start - scrollMargin : 0;
3599
+ const after = virtualizer.getTotalSize() - (last ? last.end - scrollMargin : 0);
3600
+ const spacer = (height) => height > 0 ? /* @__PURE__ */ jsx15("tr", {
3601
+ "aria-hidden": "true",
3602
+ children: /* @__PURE__ */ jsx15("td", {
3603
+ colSpan: Math.max(1, colSpan),
3604
+ className: "border-0 p-0",
3605
+ style: { height }
3606
+ })
3607
+ }) : null;
3608
+ return /* @__PURE__ */ jsxs9(Fragment, {
3609
+ children: [
3610
+ spacer(before),
3611
+ items.map(({ index, key }) => {
3612
+ const entry = entries[index];
3613
+ if (entry.kind === "data")
3614
+ return /* @__PURE__ */ jsx15(TableDataRow, {
3615
+ measureRef: virtualizer.measureElement,
3616
+ row: entry.row,
3617
+ tableAtom,
3618
+ virtualIndex: index
3619
+ }, key);
3620
+ if (entry.kind === "header")
3621
+ return /* @__PURE__ */ jsx15(GroupHeaderRow, {
3622
+ measureRef: virtualizer.measureElement,
3623
+ section: entry.section,
3624
+ colSpan,
3625
+ tableAtom,
3626
+ virtualIndex: index
3627
+ }, key);
3628
+ return /* @__PURE__ */ jsx15(TableRow2, {
3629
+ ref: virtualizer.measureElement,
3630
+ "data-index": index,
3631
+ "aria-rowindex": index + 2,
3632
+ children: /* @__PURE__ */ jsx15(TableCell2, {
3633
+ className: "text-muted-foreground h-16",
3634
+ colSpan,
3635
+ children: entry.section.field.renderEmptyGroup?.(entry.section.groupId) ?? config.labels.empty
3636
+ })
3637
+ }, key);
3638
+ }),
3639
+ spacer(after)
3640
+ ]
3641
+ });
3642
+ };
3492
3643
  var DataTableBody = ({
3493
- tableAtom
3644
+ tableAtom,
3645
+ viewport
3494
3646
  }) => {
3495
3647
  const styles = useContext(DataTableStylesContext);
3496
3648
  const [store] = useTableAtom(tableAtom);
@@ -3498,23 +3650,24 @@ var DataTableBody = ({
3498
3650
  const fields = getActiveGrouping(store);
3499
3651
  const grouped = fields.length > 0;
3500
3652
  const rows = grouped ? model.sortedRows : model.pageRows;
3501
- const sections = groupDataTableRows(rows, fields);
3653
+ const sections = useMemo2(() => groupDataTableRows(rows, fields), [rows, fields]);
3502
3654
  const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3503
- if (sections.length && (rows.length || !store.config.status.loading) && !store.config.status.error) {
3655
+ const showGroups = sections.length && (rows.length || !store.config.status.loading) && !store.config.status.error;
3656
+ if (showGroups && !viewport) {
3504
3657
  return /* @__PURE__ */ jsx15(GroupedTable, {
3505
3658
  tableAtom,
3506
3659
  sections
3507
3660
  });
3508
3661
  }
3509
3662
  return /* @__PURE__ */ jsx15(TableBody2, {
3510
- children: store.config.status.error || !rows.length && !store.config.status.loading ? /* @__PURE__ */ jsx15(TableRow2, {
3663
+ children: store.config.status.error || !showGroups && !rows.length && !store.config.status.loading ? /* @__PURE__ */ jsx15(TableRow2, {
3511
3664
  children: /* @__PURE__ */ jsx15(TableCell2, {
3512
3665
  "data-table-slot": store.config.status.error ? "error" : "empty",
3513
3666
  className: cn("h-24 text-center", store.config.status.error ? styles?.feedback?.error : styles?.feedback?.empty),
3514
3667
  colSpan: Math.max(colSpan, 1),
3515
3668
  children: store.config.status.error ?? store.config.status.empty ?? store.config.labels.empty
3516
3669
  })
3517
- }) : store.config.status.loading && !rows.length ? /* @__PURE__ */ jsx15(TableRow2, {
3670
+ }) : !showGroups && store.config.status.loading && !rows.length ? /* @__PURE__ */ jsx15(TableRow2, {
3518
3671
  children: /* @__PURE__ */ jsx15(TableCell2, {
3519
3672
  "data-table-slot": "loading",
3520
3673
  className: cn("h-24 p-0", styles?.feedback?.loading),
@@ -3524,9 +3677,16 @@ var DataTableBody = ({
3524
3677
  label: store.config.labels.loading
3525
3678
  })
3526
3679
  })
3680
+ }) : viewport ? /* @__PURE__ */ jsx15(VirtualTableRows, {
3681
+ colSpan,
3682
+ rows,
3683
+ sections,
3684
+ tableAtom,
3685
+ viewport
3527
3686
  }) : rows.map((row) => /* @__PURE__ */ jsx15(RowIdContext.Provider, {
3528
3687
  value: row.id,
3529
3688
  children: /* @__PURE__ */ jsx15(TableDataRow, {
3689
+ row,
3530
3690
  tableAtom
3531
3691
  })
3532
3692
  }, row.id))
@@ -3648,6 +3808,7 @@ var GalleryCard = ({
3648
3808
  className: "absolute top-0 right-4",
3649
3809
  onClick: (event) => event.stopPropagation(),
3650
3810
  children: /* @__PURE__ */ jsx15(DataTableRowActionMenu, {
3811
+ row,
3651
3812
  tableAtom
3652
3813
  })
3653
3814
  }) : null
@@ -3772,7 +3933,7 @@ var DataTablePagination = ({
3772
3933
  const styles = useContext(DataTableStylesContext);
3773
3934
  const [store, setStore] = useTableAtom(tableAtom);
3774
3935
  const model = deriveModel(store);
3775
- const pagination = store.config.features.pagination ?? { mode: "client" };
3936
+ const pagination = store.config.features.pagination ?? false;
3776
3937
  const clientGrouping = pagination !== false && pagination.mode === "client" && getActiveGrouping(store).length > 0;
3777
3938
  const paginationVisible = pagination !== false && !clientGrouping;
3778
3939
  const pageIndex = store.state.page;
@@ -3951,6 +4112,37 @@ var DataTableContent = ({
3951
4112
  tableAtom
3952
4113
  }) => {
3953
4114
  const [store] = useTableAtom(tableAtom);
4115
+ const [scrollElement, setScrollElement] = useState(null);
4116
+ const [headerHeight, setHeaderHeight] = useState(48);
4117
+ const [pageTable, setPageTable] = useState(null);
4118
+ const [pageOffset, setPageOffset] = useState();
4119
+ useLayoutEffect(() => {
4120
+ const header = pageTable?.querySelector("thead");
4121
+ if (!pageTable || !header)
4122
+ return;
4123
+ const measure = () => setPageOffset(window.scrollY + header.getBoundingClientRect().bottom);
4124
+ measure();
4125
+ window.addEventListener("resize", measure);
4126
+ const observer = globalThis.ResizeObserver ? new ResizeObserver(measure) : undefined;
4127
+ observer?.observe(document.body);
4128
+ observer?.observe(header);
4129
+ return () => {
4130
+ window.removeEventListener("resize", measure);
4131
+ observer?.disconnect();
4132
+ };
4133
+ }, [pageTable]);
4134
+ useLayoutEffect(() => {
4135
+ const header = scrollElement?.querySelector("thead");
4136
+ if (!header)
4137
+ return;
4138
+ const measure = () => setHeaderHeight(header.getBoundingClientRect().height);
4139
+ measure();
4140
+ if (!globalThis.ResizeObserver)
4141
+ return;
4142
+ const observer = new globalThis.ResizeObserver(measure);
4143
+ observer.observe(header);
4144
+ return () => observer.disconnect();
4145
+ }, [scrollElement]);
3954
4146
  if (store.config.features.gallery && store.state.view === "gallery") {
3955
4147
  return /* @__PURE__ */ jsx15(DataTableGallery, {
3956
4148
  tableAtom
@@ -3958,6 +4150,87 @@ var DataTableContent = ({
3958
4150
  }
3959
4151
  const model = deriveModel(store);
3960
4152
  const width = getDataTableWidth(model.visibleColumns, (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0));
4153
+ const virtualization = store.config.features.virtualization;
4154
+ const fields = getActiveGrouping(store);
4155
+ const visibleCount = (sections) => sections.reduce((count, section) => count + 1 + (store.state.collapsedGroups[section.key] ? 0 : section.children.length ? visibleCount(section.children) : Math.max(1, section.rows.length)), 0);
4156
+ const automaticallyVirtualize = virtualization === undefined && !store.config.status.error && (fields.length ? visibleCount(groupDataTableRows(model.sortedRows, fields)) : model.pageRows.length) >= 100;
4157
+ if ((virtualization || automaticallyVirtualize) && !canDragRows(store)) {
4158
+ const options = virtualization && virtualization !== true ? virtualization : {};
4159
+ const rowCount = !getActiveGrouping(store).length && model.pageRows.length && !store.config.status.error ? model.pageRows.length + 1 : undefined;
4160
+ if (options.scroll === "page") {
4161
+ return /* @__PURE__ */ jsx15("div", {
4162
+ ref: setPageTable,
4163
+ "data-table-page-virtualization": "",
4164
+ className: "[overflow-anchor:none]",
4165
+ children: /* @__PURE__ */ jsxs9(ScrollArea, {
4166
+ className: "@container max-w-full min-w-0",
4167
+ children: [
4168
+ /* @__PURE__ */ jsxs9(Table2, {
4169
+ "aria-rowcount": rowCount,
4170
+ className: "table-fixed",
4171
+ style: { width: `max(100%, ${width}px)` },
4172
+ children: [
4173
+ /* @__PURE__ */ jsx15(DataTableHeader, {
4174
+ tableAtom
4175
+ }),
4176
+ /* @__PURE__ */ jsx15(DataTableBody, {
4177
+ tableAtom,
4178
+ viewport: {
4179
+ element: null,
4180
+ headerHeight: 0,
4181
+ pageOffset,
4182
+ options
4183
+ }
4184
+ })
4185
+ ]
4186
+ }),
4187
+ /* @__PURE__ */ jsx15(ScrollBar, {
4188
+ orientation: "horizontal"
4189
+ })
4190
+ ]
4191
+ })
4192
+ });
4193
+ }
4194
+ return /* @__PURE__ */ jsxs9(ScrollAreaPrimitive2.Root, {
4195
+ className: "relative isolate max-w-full min-w-0",
4196
+ children: [
4197
+ /* @__PURE__ */ jsx15(ScrollAreaPrimitive2.Viewport, {
4198
+ ref: setScrollElement,
4199
+ "data-table-virtual-viewport": "",
4200
+ className: "@container [overflow-anchor:none] data-has-overflow-y:me-2.5 [&_[data-slot=table-container]]:overflow-visible",
4201
+ style: {
4202
+ maxHeight: options.height ?? 480,
4203
+ scrollPaddingTop: headerHeight
4204
+ },
4205
+ children: /* @__PURE__ */ jsx15(ScrollAreaPrimitive2.Content, {
4206
+ children: /* @__PURE__ */ jsxs9(Table2, {
4207
+ "aria-rowcount": rowCount,
4208
+ className: "table-fixed",
4209
+ style: { width: `max(100%, ${width}px)` },
4210
+ children: [
4211
+ /* @__PURE__ */ jsx15(DataTableHeader, {
4212
+ sticky: true,
4213
+ tableAtom
4214
+ }),
4215
+ /* @__PURE__ */ jsx15(DataTableBody, {
4216
+ tableAtom,
4217
+ viewport: { element: scrollElement, headerHeight, options }
4218
+ })
4219
+ ]
4220
+ })
4221
+ })
4222
+ }),
4223
+ /* @__PURE__ */ jsx15(ScrollBar, {
4224
+ className: "data-vertical:h-auto",
4225
+ style: { top: headerHeight }
4226
+ }),
4227
+ /* @__PURE__ */ jsx15(ScrollBar, {
4228
+ orientation: "horizontal"
4229
+ }),
4230
+ /* @__PURE__ */ jsx15(ScrollAreaPrimitive2.Corner, {})
4231
+ ]
4232
+ });
4233
+ }
3961
4234
  return /* @__PURE__ */ jsxs9(ScrollArea, {
3962
4235
  className: "@container max-w-full min-w-0",
3963
4236
  children: [
@@ -4139,6 +4412,7 @@ var DataTableListMenu = ({
4139
4412
  const labels = dataTableMessages(locale, messages);
4140
4413
  const resolvedLabel = label ?? (hasActions ? labels.actions : labels.listDetails);
4141
4414
  return /* @__PURE__ */ jsxs9(DropdownMenu, {
4415
+ modal: false,
4142
4416
  children: [
4143
4417
  /* @__PURE__ */ jsx15(DropdownMenuTrigger2, {
4144
4418
  onClick: (event) => event.stopPropagation(),
@@ -223,7 +223,7 @@ function Pagination({
223
223
  page,
224
224
  pageCount,
225
225
  pageSize,
226
- pageSizes = [10, 20, 30, 40, 50],
226
+ pageSizes = [20, 50, 100],
227
227
  selectedRows = 0,
228
228
  showResults = true,
229
229
  totalRows
@@ -102,6 +102,7 @@ export declare const ColumnFilters: Schema.declare<readonly ({
102
102
  readonly kind: "values";
103
103
  readonly values: readonly [string, ...string[]];
104
104
  })[]>;
105
+ export declare const DEFAULT_PAGE_SIZE = 100;
105
106
  export declare const Query: Schema.Struct<{
106
107
  readonly page: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Finite, Schema.FiniteFromString]>>, never, never>;
107
108
  readonly pageSize: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Finite, Schema.FiniteFromString]>>, never, never>;