@krak-stack/registry 0.1.20 → 0.1.22

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,19 +1,9 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { type PaginationMessages } from "./pagination.js";
3
+ import type { QueryType } from "../../lib/query.js";
3
4
  type RowData = object;
4
- export type DataTableSorting = readonly {
5
- id: string;
6
- desc: boolean;
7
- }[];
8
- export type DataTablePaginationState = {
9
- pageIndex: number;
10
- pageSize: number;
11
- };
12
5
  export type DataTableView = "table" | "gallery";
13
- export interface DataTablePublicState {
14
- globalFilter: string;
15
- sorting: DataTableSorting;
16
- pagination: DataTablePaginationState;
6
+ export interface DataTableUiState {
17
7
  columnVisibility: Record<string, boolean>;
18
8
  columnSizing: Record<string, number>;
19
9
  rowSelection: Record<string, boolean>;
@@ -21,6 +11,7 @@ export interface DataTablePublicState {
21
11
  collapsedGroups: Record<string, boolean>;
22
12
  view: DataTableView;
23
13
  }
14
+ export type DataTablePublicState = QueryType & DataTableUiState;
24
15
  export interface DataTableValueGetterParams<TData extends RowData> {
25
16
  data: TData;
26
17
  rowId: string;
@@ -156,6 +147,8 @@ export type DataTableMessages = PaginationMessages & {
156
147
  sortBy: string;
157
148
  hideColumn: string;
158
149
  reorder: string;
150
+ moveUp: string;
151
+ moveDown: string;
159
152
  resizeColumn: (column: string) => string;
160
153
  listOthers: (count: number) => string;
161
154
  selectAllRows: string;
@@ -191,6 +184,8 @@ export declare const dataTableMessages: (overrides?: DataTableMessageOverrides)
191
184
  sortBy: string;
192
185
  hideColumn: string;
193
186
  reorder: string;
187
+ moveUp: string;
188
+ moveDown: string;
194
189
  resizeColumn: (column: string) => string;
195
190
  listOthers: (count: number) => string;
196
191
  selectAllRows: string;
@@ -224,6 +219,8 @@ export declare const dataTableMessages: (overrides?: DataTableMessageOverrides)
224
219
  sortBy: string;
225
220
  hideColumn: string;
226
221
  reorder: string;
222
+ moveUp: string;
223
+ moveDown: string;
227
224
  resizeColumn: (column: string) => string;
228
225
  listOthers: (count: number) => string;
229
226
  selectAllRows: string;
@@ -234,7 +231,7 @@ export interface DataTableProps<TData extends RowData> {
234
231
  rowData: readonly TData[];
235
232
  columnDefs: readonly DataTableColDef<TData>[];
236
233
  getRowId?: (row: TData) => string;
237
- state?: Partial<DataTablePublicState>;
234
+ state?: DataTablePublicState;
238
235
  initialState?: Partial<DataTablePublicState>;
239
236
  onStateChange?: (state: DataTablePublicState) => void;
240
237
  status?: DataTableStatus;
@@ -267,9 +264,8 @@ export declare const normalizeDataTableColumns: <TData extends RowData>(columnDe
267
264
  export declare const getDataTableWidth: <TData extends RowData>(columns: readonly DataTableColumn<TData>[], utilityColumns?: number) => number;
268
265
  export declare const buildDataTableRows: <TData extends RowData>(rowData: readonly TData[], columns: readonly DataTableColumn<TData>[], getRowId?: (row: TData) => string) => DataTableModelRow<TData>[];
269
266
  export declare const filterDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], columns: readonly DataTableColumn<TData>[], globalFilter: string) => DataTableModelRow<TData>[];
270
- export declare const sortDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], columns: readonly DataTableColumn<TData>[], sorting: DataTableSorting) => DataTableModelRow<TData>[];
271
- export declare const paginateDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], pagination: DataTablePaginationState) => DataTableModelRow<TData>[];
272
- export declare const mergeDataTableState: (state: DataTablePublicState, controlledState?: Partial<DataTablePublicState>) => DataTablePublicState;
267
+ export declare const sortDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], columns: readonly DataTableColumn<TData>[], sorting: NonNullable<QueryType["sort"]>) => DataTableModelRow<TData>[];
268
+ export declare const paginateDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], pagination: Pick<QueryType, "page" | "pageSize">) => DataTableModelRow<TData>[];
273
269
  export declare const reorderDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], sourceRowId: string, targetRowId: string) => TData[];
274
270
  type GroupSection<TData extends RowData> = {
275
271
  key: string;
@@ -1828,6 +1828,8 @@ var messages3 = {
1828
1828
  sortBy: "Sort by",
1829
1829
  hideColumn: "Hide column",
1830
1830
  reorder: "Drag to reorder",
1831
+ moveUp: "Move up",
1832
+ moveDown: "Move down",
1831
1833
  resizeColumn: (column) => `Resize ${column} column`,
1832
1834
  listOthers: (count) => count === 1 ? "and 1 other" : `and ${count} others`,
1833
1835
  selectAllRows: "Select all rows on this page",
@@ -1855,6 +1857,8 @@ var messages3 = {
1855
1857
  sortBy: "Trier par",
1856
1858
  hideColumn: "Masquer la colonne",
1857
1859
  reorder: "Glisser pour réordonner",
1860
+ moveUp: "Déplacer vers le haut",
1861
+ moveDown: "Déplacer vers le bas",
1858
1862
  resizeColumn: (column) => `Redimensionner la colonne ${column}`,
1859
1863
  listOthers: (count) => count === 1 ? "et 1 autre" : `et ${count} autres`,
1860
1864
  selectAllRows: "Sélectionner toutes les lignes de cette page",
@@ -1870,9 +1874,8 @@ var DEFAULT_MIN_WIDTH = 96;
1870
1874
  var DEFAULT_WIDTH = 208;
1871
1875
  var DEFAULT_MAX_WIDTH = 640;
1872
1876
  var DEFAULT_STATE = {
1873
- globalFilter: "",
1874
- sorting: [],
1875
- pagination: { pageIndex: 0, pageSize: 10 },
1877
+ page: 0,
1878
+ pageSize: 10,
1876
1879
  columnVisibility: {},
1877
1880
  columnSizing: {},
1878
1881
  rowSelection: {},
@@ -1937,7 +1940,7 @@ var sortDataTableRows = (rows, columns, sorting) => {
1937
1940
  const rightValue = right.row.values.get(sort.id);
1938
1941
  const comparison = column.colDef.comparator ? column.colDef.comparator(leftValue, rightValue, left.row.data, right.row.data) : Object.is(leftValue, rightValue) ? 0 : leftValue === null || leftValue === undefined ? 1 : rightValue === null || rightValue === undefined ? -1 : Schema.is(Schema.Number)(leftValue) && Schema.is(Schema.Number)(rightValue) ? leftValue - rightValue : String(leftValue).localeCompare(String(rightValue), undefined, { numeric: true, sensitivity: "base" });
1939
1942
  if (comparison !== 0)
1940
- return sort.desc ? -comparison : comparison;
1943
+ return sort.direction === "desc" ? -comparison : comparison;
1941
1944
  }
1942
1945
  return left.stableIndex - right.stableIndex;
1943
1946
  }).map(({ row }) => row);
@@ -1945,22 +1948,11 @@ var sortDataTableRows = (rows, columns, sorting) => {
1945
1948
  var paginateDataTableRows = (rows, pagination) => {
1946
1949
  const pageSize = Math.max(1, pagination.pageSize);
1947
1950
  const lastPageIndex = Math.max(0, Math.ceil(rows.length / pageSize) - 1);
1948
- const pageIndex = Math.min(lastPageIndex, Math.max(0, pagination.pageIndex));
1951
+ const pageIndex = Math.min(lastPageIndex, Math.max(0, pagination.page));
1949
1952
  const start = pageIndex * pageSize;
1950
1953
  return rows.slice(start, start + pageSize);
1951
1954
  };
1952
- var mergeDataTableState = (state, controlledState = {}) => ({
1953
- globalFilter: controlledState.globalFilter ?? state.globalFilter,
1954
- sorting: controlledState.sorting ?? state.sorting,
1955
- pagination: controlledState.pagination ?? state.pagination,
1956
- columnVisibility: controlledState.columnVisibility ?? state.columnVisibility,
1957
- columnSizing: controlledState.columnSizing ?? state.columnSizing,
1958
- rowSelection: controlledState.rowSelection ?? state.rowSelection,
1959
- grouping: controlledState.grouping ?? state.grouping,
1960
- collapsedGroups: controlledState.collapsedGroups ?? state.collapsedGroups,
1961
- view: controlledState.view ?? state.view
1962
- });
1963
- var sameDataTableState = (left, right) => left.globalFilter === right.globalFilter && left.sorting === right.sorting && left.pagination === right.pagination && left.columnVisibility === right.columnVisibility && left.columnSizing === right.columnSizing && left.rowSelection === right.rowSelection && left.grouping === right.grouping && left.collapsedGroups === right.collapsedGroups && left.view === right.view;
1955
+ var sameDataTableState = (left, right) => left.page === right.page && left.pageSize === right.pageSize && left.globalFilter === right.globalFilter && left.sort === right.sort && left.columnVisibility === right.columnVisibility && left.columnSizing === right.columnSizing && left.rowSelection === right.rowSelection && left.grouping === right.grouping && left.collapsedGroups === right.collapsedGroups && left.view === right.view;
1964
1956
  var reorderDataTableRows = (rows, sourceRowId, targetRowId) => {
1965
1957
  const sourceIndex = rows.findIndex((row) => row.id === sourceRowId);
1966
1958
  const targetIndex = rows.findIndex((row) => row.id === targetRowId);
@@ -2025,11 +2017,10 @@ var resolveConfig = (props) => {
2025
2017
  var initialPublicState = (props) => {
2026
2018
  const grouping = props.features?.grouping;
2027
2019
  const groupingInitial = grouping && grouping.initial ? grouping.initial : [];
2028
- return {
2020
+ return props.state ?? {
2029
2021
  ...DEFAULT_STATE,
2030
2022
  grouping: groupingInitial,
2031
- ...props.initialState,
2032
- ...props.state
2023
+ ...props.initialState
2033
2024
  };
2034
2025
  };
2035
2026
  var buildDataTableModel = (store) => {
@@ -2039,9 +2030,9 @@ var buildDataTableModel = (store) => {
2039
2030
  const rows = buildDataTableRows(store.rowData, columns, rowId);
2040
2031
  const pagination = store.config.features.pagination ?? { mode: "client" };
2041
2032
  const server = pagination !== false && pagination.mode === "server";
2042
- const filteredRows = server ? [...rows] : filterDataTableRows(rows, columns, store.state.globalFilter);
2043
- const sortedRows = server ? filteredRows : sortDataTableRows(filteredRows, columns, store.state.sorting);
2044
- const pageRows = pagination === false || server ? sortedRows : paginateDataTableRows(sortedRows, store.state.pagination);
2033
+ const filteredRows = server ? [...rows] : filterDataTableRows(rows, columns, store.state.globalFilter ?? "");
2034
+ const sortedRows = server ? filteredRows : sortDataTableRows(filteredRows, columns, store.state.sort ?? []);
2035
+ const pageRows = pagination === false || server ? sortedRows : paginateDataTableRows(sortedRows, store.state);
2045
2036
  const totalRows = server ? pagination.rowCount : sortedRows.length;
2046
2037
  return {
2047
2038
  columns,
@@ -2050,7 +2041,7 @@ var buildDataTableModel = (store) => {
2050
2041
  filteredRows,
2051
2042
  sortedRows,
2052
2043
  pageRows,
2053
- pageCount: Math.max(1, Math.ceil(totalRows / Math.max(1, store.state.pagination.pageSize))),
2044
+ pageCount: Math.max(1, Math.ceil(totalRows / Math.max(1, store.state.pageSize))),
2054
2045
  totalRows
2055
2046
  };
2056
2047
  };
@@ -2059,7 +2050,7 @@ var changeState = (setStore, update) => {
2059
2050
  setStore((store) => {
2060
2051
  const proposed = update(store.state);
2061
2052
  store.config.onStateChange?.(proposed);
2062
- const state = mergeDataTableState(proposed, store.controlledState);
2053
+ const state = store.controlledState ?? proposed;
2063
2054
  if (sameDataTableState(state, store.state))
2064
2055
  return store;
2065
2056
  const next = { ...store, state };
@@ -2104,10 +2095,11 @@ var getActiveGrouping = (store) => {
2104
2095
  };
2105
2096
  var canReorderRows = (store) => {
2106
2097
  const pagination = store.config.features.pagination;
2107
- return !!store.config.features.reordering && !getActiveGrouping(store).length && !store.state.globalFilter && !store.state.sorting.length && !(pagination && pagination.mode === "server");
2098
+ return !!store.config.features.reordering && !getActiveGrouping(store).length && !store.state.globalFilter && !store.state.sort?.length && !(pagination && pagination.mode === "server");
2108
2099
  };
2109
2100
  var canMoveRowsToGroups = (store) => getActiveGrouping(store).some((field) => !!field.onMoveToGroup);
2110
2101
  var canDragRows = (store) => getActiveGrouping(store).length ? canMoveRowsToGroups(store) : canReorderRows(store);
2102
+ var hasRowActionMenu = (store) => !!store.config.features.rowActions || canReorderRows(store);
2111
2103
  var getSelectedRows = (store, model) => model.rows.filter((row) => store.state.rowSelection[row.id]).map((row) => row.data);
2112
2104
  var renderCell = (row, column) => {
2113
2105
  const value = row.values.get(column.id);
@@ -2209,6 +2201,45 @@ var DataTableRowActions = ({
2209
2201
  ]
2210
2202
  });
2211
2203
  };
2204
+ var DataTableRowActionMenu = ({
2205
+ tableAtom
2206
+ }) => {
2207
+ const [store] = useTableAtom(tableAtom);
2208
+ const rowId = useRequiredId(RowIdContext);
2209
+ const model = deriveModel(store);
2210
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
2211
+ if (!row)
2212
+ return null;
2213
+ const rowActions = store.config.features.rowActions || undefined;
2214
+ const visibleRows = model.pageRows;
2215
+ const rowIndex = visibleRows.findIndex((candidate) => candidate.id === rowId);
2216
+ const reordering = store.config.features.reordering;
2217
+ const reorderActions = [];
2218
+ if (reordering && canReorderRows(store)) {
2219
+ const move = (targetIndex) => reordering.onReorder(reorderDataTableRows(model.rows, rowId, visibleRows[targetIndex].id));
2220
+ if (rowIndex > 0) {
2221
+ reorderActions.push({
2222
+ id: "data-table-move-up",
2223
+ name: store.config.labels.moveUp,
2224
+ icon: /* @__PURE__ */ jsx17(ArrowUp, {}),
2225
+ onClick: () => move(rowIndex - 1)
2226
+ });
2227
+ }
2228
+ if (rowIndex !== -1 && rowIndex < visibleRows.length - 1) {
2229
+ reorderActions.push({
2230
+ id: "data-table-move-down",
2231
+ name: store.config.labels.moveDown,
2232
+ icon: /* @__PURE__ */ jsx17(ArrowDown, {}),
2233
+ onClick: () => move(rowIndex + 1)
2234
+ });
2235
+ }
2236
+ }
2237
+ return /* @__PURE__ */ jsx17(DataTableRowActions, {
2238
+ actions: [...reorderActions, ...rowActions ? rowActions.items : []],
2239
+ row: row.data,
2240
+ title: rowActions?.label ?? store.config.labels.actions
2241
+ });
2242
+ };
2212
2243
  var DataTableToolbar = ({
2213
2244
  tableAtom
2214
2245
  }) => {
@@ -2238,18 +2269,18 @@ var DataTableToolbar = ({
2238
2269
  onChange: (event) => update((state) => ({
2239
2270
  ...state,
2240
2271
  globalFilter: event.target.value,
2241
- pagination: { ...state.pagination, pageIndex: 0 }
2272
+ page: 0
2242
2273
  })),
2243
2274
  placeholder: labels2.filter,
2244
- value: store.state.globalFilter
2275
+ value: store.state.globalFilter ?? ""
2245
2276
  }),
2246
2277
  store.state.globalFilter ? /* @__PURE__ */ jsx17(Button, {
2247
2278
  "aria-label": labels2.filter,
2248
2279
  className: "absolute top-1/2 right-1 size-7 -translate-y-1/2",
2249
2280
  onClick: () => update((state) => ({
2250
2281
  ...state,
2251
- globalFilter: "",
2252
- pagination: { ...state.pagination, pageIndex: 0 }
2282
+ globalFilter: undefined,
2283
+ page: 0
2253
2284
  })),
2254
2285
  size: "icon",
2255
2286
  variant: "ghost",
@@ -2408,18 +2439,18 @@ var SortMenu = ({
2408
2439
  const columns = deriveModel(store).columns.filter(({ colDef }) => colDef.sortable !== false);
2409
2440
  if (!columns.length)
2410
2441
  return null;
2411
- const current = store.state.sorting[0];
2412
- const sort = (id, desc) => changeState(setStore, (state) => ({
2442
+ const current = store.state.sort?.[0];
2443
+ const sort = (id, direction) => changeState(setStore, (state) => ({
2413
2444
  ...state,
2414
- sorting: [{ id, desc }],
2415
- pagination: { ...state.pagination, pageIndex: 0 }
2445
+ sort: [{ id, direction }],
2446
+ page: 0
2416
2447
  }));
2417
2448
  return /* @__PURE__ */ jsxs9(MenubarMenu, {
2418
2449
  children: [
2419
2450
  /* @__PURE__ */ jsxs9(MenubarTrigger, {
2420
2451
  "aria-label": store.config.labels.sortBy,
2421
2452
  children: [
2422
- current ? current.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : /* @__PURE__ */ jsx17(ChevronsUpDown2, {}),
2453
+ current ? current.direction === "desc" ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : /* @__PURE__ */ jsx17(ChevronsUpDown2, {}),
2423
2454
  /* @__PURE__ */ jsx17("span", {
2424
2455
  className: "hidden sm:inline",
2425
2456
  children: store.config.labels.sortBy
@@ -2430,19 +2461,19 @@ var SortMenu = ({
2430
2461
  align: "end",
2431
2462
  className: "w-52",
2432
2463
  children: columns.map((column) => {
2433
- const sortState = store.state.sorting.find(({ id }) => id === column.id);
2464
+ const sortState = store.state.sort?.find(({ id }) => id === column.id);
2434
2465
  return /* @__PURE__ */ jsxs9(MenubarSub, {
2435
2466
  children: [
2436
2467
  /* @__PURE__ */ jsxs9(MenubarSubTrigger, {
2437
2468
  children: [
2438
- sortState ? sortState.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : null,
2469
+ sortState ? sortState.direction === "desc" ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : null,
2439
2470
  columnLabel(column)
2440
2471
  ]
2441
2472
  }),
2442
2473
  /* @__PURE__ */ jsxs9(MenubarSubContent, {
2443
2474
  children: [
2444
2475
  /* @__PURE__ */ jsxs9(MenubarItem, {
2445
- onClick: () => sort(column.id, false),
2476
+ onClick: () => sort(column.id, "asc"),
2446
2477
  children: [
2447
2478
  /* @__PURE__ */ jsx17(ArrowUp, {}),
2448
2479
  " ",
@@ -2450,7 +2481,7 @@ var SortMenu = ({
2450
2481
  ]
2451
2482
  }),
2452
2483
  /* @__PURE__ */ jsxs9(MenubarItem, {
2453
- onClick: () => sort(column.id, true),
2484
+ onClick: () => sort(column.id, "desc"),
2454
2485
  children: [
2455
2486
  /* @__PURE__ */ jsx17(ArrowDown, {}),
2456
2487
  " ",
@@ -2463,7 +2494,7 @@ var SortMenu = ({
2463
2494
  /* @__PURE__ */ jsxs9(MenubarItem, {
2464
2495
  onClick: () => changeState(setStore, (state) => ({
2465
2496
  ...state,
2466
- sorting: state.sorting.filter(({ id }) => id !== column.id)
2497
+ sort: state.sort?.filter(({ id }) => id !== column.id)
2467
2498
  })),
2468
2499
  children: [
2469
2500
  /* @__PURE__ */ jsx17(X2, {}),
@@ -2772,7 +2803,6 @@ var TableDataRow = ({
2772
2803
  return null;
2773
2804
  const selection = store.config.features.selection;
2774
2805
  const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
2775
- const rowActions = store.config.features.rowActions;
2776
2806
  const draggable = canDragRows(store);
2777
2807
  return /* @__PURE__ */ jsxs9(TableRow, {
2778
2808
  className: cn("group/row h-16 data-[drag-source=true]:opacity-40 data-[drop-position=before]:[&>td]:border-t-2 data-[drop-position=before]:[&>td]:border-primary data-[drop-position=after]:[&>td]:border-b-2 data-[drop-position=after]:[&>td]:border-primary", store.config.onRowClicked && "cursor-pointer"),
@@ -2811,15 +2841,13 @@ var TableDataRow = ({
2811
2841
  children: renderCell(row, column)
2812
2842
  })
2813
2843
  }, column.id)),
2814
- rowActions ? /* @__PURE__ */ jsx17(TableCell, {
2844
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx17(TableCell, {
2815
2845
  className: "bg-background group-data-[state=selected]/row:bg-muted sticky right-0 z-20 w-10 min-w-10 cursor-default p-0 transition-colors group-hover/row:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))]",
2816
2846
  onClick: (event) => event.stopPropagation(),
2817
2847
  children: /* @__PURE__ */ jsx17("div", {
2818
2848
  className: "flex h-16 items-center justify-center",
2819
- children: /* @__PURE__ */ jsx17(DataTableRowActions, {
2820
- actions: rowActions.items,
2821
- row: row.data,
2822
- title: rowActions.label ?? store.config.labels.actions
2849
+ children: /* @__PURE__ */ jsx17(DataTableRowActionMenu, {
2850
+ tableAtom
2823
2851
  })
2824
2852
  })
2825
2853
  }) : null
@@ -2873,7 +2901,7 @@ var GroupedTable = ({
2873
2901
  const [store, setStore] = useTableAtom(tableAtom);
2874
2902
  const model = deriveModel(store);
2875
2903
  const sections = groupDataTableRows(model.sortedRows, getActiveGrouping(store));
2876
- const extra = (store.config.features.selection ? 1 : 0) + (store.config.features.rowActions ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2904
+ const extra = (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2877
2905
  const renderSections = (items) => items.flatMap((section) => {
2878
2906
  const collapsed = !!store.state.collapsedGroups[section.key];
2879
2907
  const targetKey = getGroupDropKey(section.field.id, section.groupId);
@@ -2957,12 +2985,12 @@ var ColumnHeaderMenu = ({
2957
2985
  return null;
2958
2986
  const sortingEnabled = store.config.features.sorting !== false && column.colDef.sortable !== false;
2959
2987
  const hidingEnabled = store.config.features.columnVisibility !== false && column.colDef.hideable !== false;
2960
- const sort = store.state.sorting.find(({ id }) => id === column.id);
2988
+ const sort = store.state.sort?.find(({ id }) => id === column.id);
2961
2989
  const update = (next) => changeState(setStore, next);
2962
- const setSort = (desc) => update((state) => ({
2990
+ const setSort = (direction) => update((state) => ({
2963
2991
  ...state,
2964
- sorting: [{ id: column.id, desc }],
2965
- pagination: { ...state.pagination, pageIndex: 0 }
2992
+ sort: [{ id: column.id, direction }],
2993
+ page: 0
2966
2994
  }));
2967
2995
  const label = columnLabel(column);
2968
2996
  if (!sortingEnabled && !hidingEnabled) {
@@ -2984,7 +3012,7 @@ var ColumnHeaderMenu = ({
2984
3012
  className: "truncate",
2985
3013
  children: column.colDef.headerName
2986
3014
  }),
2987
- sort ? sort.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : sortingEnabled ? /* @__PURE__ */ jsx17(ChevronsUpDown2, {}) : null
3015
+ sort ? sort.direction === "desc" ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : sortingEnabled ? /* @__PURE__ */ jsx17(ChevronsUpDown2, {}) : null
2988
3016
  ]
2989
3017
  })
2990
3018
  }),
@@ -2996,7 +3024,7 @@ var ColumnHeaderMenu = ({
2996
3024
  sortingEnabled ? /* @__PURE__ */ jsxs9(Fragment, {
2997
3025
  children: [
2998
3026
  /* @__PURE__ */ jsxs9(DropdownMenuItem, {
2999
- onClick: () => setSort(false),
3027
+ onClick: () => setSort("asc"),
3000
3028
  children: [
3001
3029
  /* @__PURE__ */ jsx17(ArrowUp, {}),
3002
3030
  " ",
@@ -3004,7 +3032,7 @@ var ColumnHeaderMenu = ({
3004
3032
  ]
3005
3033
  }),
3006
3034
  /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3007
- onClick: () => setSort(true),
3035
+ onClick: () => setSort("desc"),
3008
3036
  children: [
3009
3037
  /* @__PURE__ */ jsx17(ArrowDown, {}),
3010
3038
  " ",
@@ -3014,7 +3042,7 @@ var ColumnHeaderMenu = ({
3014
3042
  sort ? /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3015
3043
  onClick: () => update((state) => ({
3016
3044
  ...state,
3017
- sorting: state.sorting.filter(({ id }) => id !== column.id)
3045
+ sort: state.sort?.filter(({ id }) => id !== column.id)
3018
3046
  })),
3019
3047
  children: [
3020
3048
  /* @__PURE__ */ jsx17(X2, {}),
@@ -3095,7 +3123,7 @@ var DataTableHeader = ({
3095
3123
  })
3096
3124
  }, column.id);
3097
3125
  }),
3098
- store.config.features.rowActions ? /* @__PURE__ */ jsx17(TableHead, {
3126
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx17(TableHead, {
3099
3127
  className: "w-10"
3100
3128
  }) : null
3101
3129
  ]
@@ -3109,7 +3137,7 @@ var DataTableBody = ({
3109
3137
  const model = deriveModel(store);
3110
3138
  const grouped = getActiveGrouping(store).length > 0;
3111
3139
  const rows = grouped ? model.sortedRows : model.pageRows;
3112
- const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (store.config.features.rowActions ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3140
+ const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3113
3141
  if (grouped && rows.length && !store.config.status.error) {
3114
3142
  return /* @__PURE__ */ jsx17(GroupedTable, {
3115
3143
  tableAtom
@@ -3154,7 +3182,6 @@ var GalleryCard = ({
3154
3182
  const tag = find(gallery.tag);
3155
3183
  const selection = store.config.features.selection;
3156
3184
  const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
3157
- const rowActions = store.config.features.rowActions;
3158
3185
  const draggable = canDragRows(store);
3159
3186
  return /* @__PURE__ */ jsx17(Card, {
3160
3187
  className: cn("relative gap-3 data-[drag-source=true]:opacity-40 data-[drop-position=before]:border-t-2 data-[drop-position=before]:border-t-primary data-[drop-position=after]:border-b-2 data-[drop-position=after]:border-b-primary", store.config.onRowClicked && "cursor-pointer"),
@@ -3199,13 +3226,11 @@ var GalleryCard = ({
3199
3226
  className: "text-muted-foreground line-clamp-3 text-sm",
3200
3227
  children: renderCell(row, description)
3201
3228
  }) : null,
3202
- rowActions ? /* @__PURE__ */ jsx17("div", {
3229
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx17("div", {
3203
3230
  className: "absolute top-4 right-4",
3204
3231
  onClick: (event) => event.stopPropagation(),
3205
- children: /* @__PURE__ */ jsx17(DataTableRowActions, {
3206
- actions: rowActions.items,
3207
- row: row.data,
3208
- title: rowActions.label ?? store.config.labels.actions
3232
+ children: /* @__PURE__ */ jsx17(DataTableRowActionMenu, {
3233
+ tableAtom
3209
3234
  })
3210
3235
  }) : null
3211
3236
  ]
@@ -3322,29 +3347,29 @@ var DataTablePagination = ({
3322
3347
  const pagination = store.config.features.pagination ?? { mode: "client" };
3323
3348
  const clientGrouping = pagination !== false && pagination.mode === "client" && getActiveGrouping(store).length > 0;
3324
3349
  const paginationVisible = pagination !== false && !clientGrouping;
3325
- const pageIndex = store.state.pagination.pageIndex;
3350
+ const pageIndex = store.state.page;
3326
3351
  const maxPageIndex = model.pageCount - 1;
3327
3352
  useLayoutEffect(() => {
3328
3353
  if (paginationVisible && pageIndex > maxPageIndex) {
3329
3354
  changeState(setStore, (state) => ({
3330
3355
  ...state,
3331
- pagination: { ...state.pagination, pageIndex: maxPageIndex }
3356
+ page: maxPageIndex
3332
3357
  }));
3333
3358
  }
3334
3359
  }, [maxPageIndex, pageIndex, paginationVisible, setStore]);
3335
3360
  if (!paginationVisible)
3336
3361
  return null;
3337
3362
  const selected = model.rows.filter((row) => store.state.rowSelection[row.id]).length;
3338
- const setPagination = (next) => changeState(setStore, (state) => ({ ...state, pagination: next }));
3363
+ const setPagination = (next) => changeState(setStore, (state) => ({ ...state, ...next }));
3339
3364
  return /* @__PURE__ */ jsx17("div", {
3340
3365
  className: "pt-4",
3341
3366
  children: /* @__PURE__ */ jsx17(Pagination, {
3342
3367
  messages: store.config.labels,
3343
- onPageChange: (pageIndex2) => setPagination({ ...store.state.pagination, pageIndex: pageIndex2 }),
3344
- onPageSizeChange: (pageSize) => setPagination({ pageIndex: 0, pageSize }),
3345
- page: Math.min(store.state.pagination.pageIndex, model.pageCount - 1),
3368
+ onPageChange: (page) => setPagination({ page, pageSize: store.state.pageSize }),
3369
+ onPageSizeChange: (pageSize) => setPagination({ page: 0, pageSize }),
3370
+ page: Math.min(store.state.page, model.pageCount - 1),
3346
3371
  pageCount: model.pageCount,
3347
- pageSize: store.state.pagination.pageSize,
3372
+ pageSize: store.state.pageSize,
3348
3373
  pageSizes: pagination.pageSizes,
3349
3374
  selectedRows: selected,
3350
3375
  totalRows: model.totalRows
@@ -3360,7 +3385,7 @@ var DataTable = (props) => {
3360
3385
  columnDefs: props.columnDefs,
3361
3386
  config: validatedConfig,
3362
3387
  state: initialPublicState(props),
3363
- controlledState: props.state ?? {}
3388
+ controlledState: props.state
3364
3389
  };
3365
3390
  atomRef.current = Atom.make({
3366
3391
  ...initial,
@@ -3381,14 +3406,14 @@ var DataTable = (props) => {
3381
3406
  onRowClicked: props.onRowClicked,
3382
3407
  labels: dataTableMessages(props.messages)
3383
3408
  };
3384
- const state = mergeDataTableState(store.state, props.state);
3409
+ const state = props.state ?? store.state;
3385
3410
  const modelChanged = store.rowData !== props.rowData || store.columnDefs !== props.columnDefs || !sameDataTableState(store.state, state) || store.config.getRowId !== config.getRowId || store.config.features.pagination !== config.features.pagination;
3386
3411
  const next = {
3387
3412
  ...store,
3388
3413
  rowData: props.rowData,
3389
3414
  columnDefs: props.columnDefs,
3390
3415
  config,
3391
- controlledState: props.state ?? {},
3416
+ controlledState: props.state,
3392
3417
  state
3393
3418
  };
3394
3419
  return modelChanged ? { ...next, model: buildDataTableModel(next) } : next;
@@ -3431,7 +3456,7 @@ var DataTableContent = ({
3431
3456
  });
3432
3457
  }
3433
3458
  const model = deriveModel(store);
3434
- const width = getDataTableWidth(model.visibleColumns, (store.config.features.selection ? 1 : 0) + (store.config.features.rowActions ? 1 : 0) + (canDragRows(store) ? 1 : 0));
3459
+ const width = getDataTableWidth(model.visibleColumns, (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0));
3435
3460
  return /* @__PURE__ */ jsxs9(ScrollArea, {
3436
3461
  className: "max-w-full min-w-0",
3437
3462
  children: [
@@ -3602,7 +3627,6 @@ export {
3602
3627
  getDataTableSelectableRows,
3603
3628
  getDataTableWidth,
3604
3629
  groupDataTableRows,
3605
- mergeDataTableState,
3606
3630
  normalizeDataTableColumns,
3607
3631
  paginateDataTableRows,
3608
3632
  reorderDataTableRows,
@@ -22,15 +22,17 @@ export declare const SortParamsFromString: Schema.decodeTo<Schema.$Array<Schema.
22
22
  readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
23
23
  }>>, Schema.String, never, never>;
24
24
  export declare const Query: Schema.Struct<{
25
- readonly page: Schema.Int;
26
- readonly pageSize: Schema.Int;
25
+ readonly page: Schema.withDecodingDefaultKey<Schema.Int, never>;
26
+ readonly pageSize: Schema.withDecodingDefaultKey<Schema.Int, never>;
27
27
  readonly globalFilter: Schema.optional<Schema.String>;
28
- readonly sort: Schema.optional<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.$Array<Schema.Struct<{
28
+ readonly sort: Schema.optional<Schema.decodeTo<Schema.$Array<Schema.Struct<{
29
29
  readonly id: Schema.NonEmptyString;
30
30
  readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
31
- }>>, Schema.String, never, never>, never, never>>;
31
+ }>>, Schema.String, never, never>>;
32
32
  }>;
33
33
  export type QueryType = typeof Query.Type;
34
+ export type QueryEncoded = typeof Query.Encoded;
35
+ export declare const QueryStandard: ReturnType<typeof Schema.toStandardSchemaV1<typeof Query>>;
34
36
  export declare const PaginationMeta: Schema.Struct<{
35
37
  readonly page: Schema.Int;
36
38
  readonly pageSize: Schema.Int;
package/dist/lib/query.js CHANGED
@@ -75,20 +75,11 @@ var SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Array(SortP
75
75
  ]
76
76
  ]
77
77
  }));
78
- var SortParamSearch = SortParamsFromString.pipe(Schema.decodeTo(Schema.String, SchemaTransformation.transform({
79
- decode: (sort) => Schema.encodeSync(SortParamsFromString)(sort),
80
- encode: (sort) => Schema.decodeUnknownSync(SortParamsFromString)(sort)
81
- })), Schema.annotate({
82
- identifier: "SortParamSearch",
83
- title: "Sort Search Parameter",
84
- description: 'Search parameter sort value normalized to the compact "-field,otherField" URL format.',
85
- examples: ["-name,age"]
86
- }));
87
78
  var Query = Schema.Struct({
88
- page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
89
- pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })),
79
+ page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)).pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
80
+ pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })).pipe(Schema.withDecodingDefaultKey(Effect.succeed(10))),
90
81
  globalFilter: Schema.optional(Schema.String),
91
- sort: Schema.optional(SortParamSearch)
82
+ sort: Schema.optional(SortParamsFromString)
92
83
  }).annotate({
93
84
  identifier: "Query",
94
85
  title: "Query",
@@ -98,10 +89,14 @@ var Query = Schema.Struct({
98
89
  page: 0,
99
90
  pageSize: 10,
100
91
  globalFilter: "housing",
101
- sort: "-publicName,createdAt"
92
+ sort: [
93
+ { id: "publicName", direction: "desc" },
94
+ { id: "createdAt", direction: "asc" }
95
+ ]
102
96
  }
103
97
  ]
104
98
  });
99
+ var QueryStandard = Schema.toStandardSchemaV1(Query);
105
100
  var PaginationMeta = Schema.Struct({
106
101
  page: Schema.Int,
107
102
  pageSize: Schema.Int,
@@ -121,6 +116,7 @@ export {
121
116
  PaginatedResponse,
122
117
  PaginationMeta,
123
118
  Query,
119
+ QueryStandard,
124
120
  SortDirection,
125
121
  SortParam,
126
122
  SortParamFromString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {