@krak-stack/registry 0.1.21 → 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,20 +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
+ import type { QueryType } from "../../lib/query.js";
4
4
  type RowData = object;
5
- export type DataTableSorting = readonly {
6
- id: string;
7
- desc: boolean;
8
- }[];
9
- export type DataTablePaginationState = {
10
- pageIndex: number;
11
- pageSize: number;
12
- };
13
5
  export type DataTableView = "table" | "gallery";
14
- export interface DataTablePublicState {
15
- globalFilter: string;
16
- sorting: DataTableSorting;
17
- pagination: DataTablePaginationState;
6
+ export interface DataTableUiState {
18
7
  columnVisibility: Record<string, boolean>;
19
8
  columnSizing: Record<string, number>;
20
9
  rowSelection: Record<string, boolean>;
@@ -22,6 +11,7 @@ export interface DataTablePublicState {
22
11
  collapsedGroups: Record<string, boolean>;
23
12
  view: DataTableView;
24
13
  }
14
+ export type DataTablePublicState = QueryType & DataTableUiState;
25
15
  export interface DataTableValueGetterParams<TData extends RowData> {
26
16
  data: TData;
27
17
  rowId: string;
@@ -241,11 +231,9 @@ export interface DataTableProps<TData extends RowData> {
241
231
  rowData: readonly TData[];
242
232
  columnDefs: readonly DataTableColDef<TData>[];
243
233
  getRowId?: (row: TData) => string;
244
- state?: Partial<DataTablePublicState>;
234
+ state?: DataTablePublicState;
245
235
  initialState?: Partial<DataTablePublicState>;
246
236
  onStateChange?: (state: DataTablePublicState) => void;
247
- query?: QueryType;
248
- onQueryChange?: (query: QueryType) => void;
249
237
  status?: DataTableStatus;
250
238
  features?: DataTableFeatures<TData>;
251
239
  onRowClicked?: (row: TData) => void;
@@ -276,9 +264,8 @@ export declare const normalizeDataTableColumns: <TData extends RowData>(columnDe
276
264
  export declare const getDataTableWidth: <TData extends RowData>(columns: readonly DataTableColumn<TData>[], utilityColumns?: number) => number;
277
265
  export declare const buildDataTableRows: <TData extends RowData>(rowData: readonly TData[], columns: readonly DataTableColumn<TData>[], getRowId?: (row: TData) => string) => DataTableModelRow<TData>[];
278
266
  export declare const filterDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], columns: readonly DataTableColumn<TData>[], globalFilter: string) => DataTableModelRow<TData>[];
279
- export declare const sortDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], columns: readonly DataTableColumn<TData>[], sorting: DataTableSorting) => DataTableModelRow<TData>[];
280
- export declare const paginateDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], pagination: DataTablePaginationState) => DataTableModelRow<TData>[];
281
- 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>[];
282
269
  export declare const reorderDataTableRows: <TData extends RowData>(rows: readonly DataTableModelRow<TData>[], sourceRowId: string, targetRowId: string) => TData[];
283
270
  type GroupSection<TData extends RowData> = {
284
271
  key: string;
@@ -1,6 +1,6 @@
1
1
  // ../../src/components/ui/data-table.tsx
2
2
  import { useAtom, useAtomSet } from "@effect/atom-react";
3
- import { Schema as Schema2 } from "effect";
3
+ import { Schema } from "effect";
4
4
  import { Atom } from "effect/unstable/reactivity";
5
5
  import {
6
6
  ArrowDown,
@@ -1804,123 +1804,6 @@ function VirtualizedCombobox(props) {
1804
1804
  });
1805
1805
  }
1806
1806
 
1807
- // ../../src/lib/query.ts
1808
- import {
1809
- Effect,
1810
- Option,
1811
- Schema,
1812
- SchemaIssue,
1813
- SchemaTransformation
1814
- } from "effect";
1815
- var parseSortParam = (sort) => {
1816
- const id = sort.startsWith("-") ? sort.slice(1) : sort;
1817
- if (!id || id.includes(",") || id.includes(":")) {
1818
- return null;
1819
- }
1820
- return { id, direction: sort.startsWith("-") ? "desc" : "asc" };
1821
- };
1822
- var SortDirection = Schema.Union([
1823
- Schema.Literal("asc"),
1824
- Schema.Literal("desc")
1825
- ]).pipe(Schema.annotate({
1826
- identifier: "SortDirection",
1827
- title: "Sort Direction",
1828
- description: "Sort direction for list query results.",
1829
- examples: ["asc", "desc"]
1830
- }));
1831
- var SortParam = Schema.Struct({
1832
- id: Schema.NonEmptyString,
1833
- direction: SortDirection
1834
- }).pipe(Schema.annotate({
1835
- identifier: "SortParam",
1836
- title: "Sort Parameter",
1837
- description: "Decoded sort parameter with a field id and direction.",
1838
- examples: [{ id: "publicName", direction: "asc" }]
1839
- }));
1840
- var SortParamFromString = Schema.String.pipe(Schema.decodeTo(SortParam, SchemaTransformation.transformOrFail({
1841
- decode: (sort) => {
1842
- const sortParam = parseSortParam(sort);
1843
- if (!sortParam) {
1844
- return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
1845
- message: 'Expected sort in the format "field" or "-field"'
1846
- }));
1847
- }
1848
- return Effect.succeed(sortParam);
1849
- },
1850
- encode: (sort) => Effect.succeed(sort.direction === "desc" ? `-${sort.id}` : sort.id)
1851
- })), Schema.annotate({
1852
- identifier: "SortParamFromString",
1853
- title: "Sort Parameter From String",
1854
- description: 'URL encoded single sort parameter where descending fields are prefixed with "-".',
1855
- examples: [{ id: "publicName", direction: "asc" }]
1856
- }));
1857
- var SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Array(SortParam), SchemaTransformation.transformOrFail({
1858
- decode: (sort) => {
1859
- const parts = sort.split(",");
1860
- const sortParams = [];
1861
- for (const part of parts) {
1862
- const sortParam = parseSortParam(part);
1863
- if (!sortParam) {
1864
- return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
1865
- message: 'Expected sort in the format "field,-otherField"'
1866
- }));
1867
- }
1868
- sortParams.push(sortParam);
1869
- }
1870
- return Effect.succeed(sortParams);
1871
- },
1872
- encode: (sort) => Effect.succeed(sort.map((part) => Schema.encodeSync(SortParamFromString)(part)).join(","))
1873
- })), Schema.annotate({
1874
- identifier: "SortParamsFromString",
1875
- title: "Sort Parameters From String",
1876
- description: 'URL encoded sort parameters where descending fields are prefixed with "-" and multiple fields are comma-separated.',
1877
- examples: [
1878
- [
1879
- { id: "name", direction: "desc" },
1880
- { id: "age", direction: "asc" }
1881
- ]
1882
- ]
1883
- }));
1884
- var SortParamSearch = SortParamsFromString.pipe(Schema.decodeTo(Schema.String, SchemaTransformation.transform({
1885
- decode: (sort) => Schema.encodeSync(SortParamsFromString)(sort),
1886
- encode: (sort) => Schema.decodeUnknownSync(SortParamsFromString)(sort)
1887
- })), Schema.annotate({
1888
- identifier: "SortParamSearch",
1889
- title: "Sort Search Parameter",
1890
- description: 'Search parameter sort value normalized to the compact "-field,otherField" URL format.',
1891
- examples: ["-name,age"]
1892
- }));
1893
- var Query = Schema.Struct({
1894
- page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)).pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
1895
- pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })).pipe(Schema.withDecodingDefaultKey(Effect.succeed(10))),
1896
- globalFilter: Schema.optional(Schema.String),
1897
- sort: Schema.optional(SortParamSearch)
1898
- }).annotate({
1899
- identifier: "Query",
1900
- title: "Query",
1901
- description: "Zero-based page request parameters with optional filtering and sorting for list endpoints.",
1902
- examples: [
1903
- {
1904
- page: 0,
1905
- pageSize: 10,
1906
- globalFilter: "housing",
1907
- sort: "-publicName,createdAt"
1908
- }
1909
- ]
1910
- });
1911
- var QueryStandard = Schema.toStandardSchemaV1(Query);
1912
- var PaginationMeta = Schema.Struct({
1913
- page: Schema.Int,
1914
- pageSize: Schema.Int,
1915
- total: Schema.Int,
1916
- pageCount: Schema.Int
1917
- }).pipe(Schema.annotate({
1918
- identifier: "PaginationMeta",
1919
- title: "Pagination Metadata",
1920
- description: "Pagination metadata returned with a paginated list response.",
1921
- examples: [{ page: 0, pageSize: 10, total: 125, pageCount: 13 }]
1922
- }));
1923
-
1924
1807
  // ../../src/components/ui/data-table.tsx
1925
1808
  import { jsx as jsx17, jsxs as jsxs9, Fragment } from "react/jsx-runtime";
1926
1809
  var messages3 = {
@@ -1991,9 +1874,8 @@ var DEFAULT_MIN_WIDTH = 96;
1991
1874
  var DEFAULT_WIDTH = 208;
1992
1875
  var DEFAULT_MAX_WIDTH = 640;
1993
1876
  var DEFAULT_STATE = {
1994
- globalFilter: "",
1995
- sorting: [],
1996
- pagination: { pageIndex: 0, pageSize: 10 },
1877
+ page: 0,
1878
+ pageSize: 10,
1997
1879
  columnVisibility: {},
1998
1880
  columnSizing: {},
1999
1881
  rowSelection: {},
@@ -2056,9 +1938,9 @@ var sortDataTableRows = (rows, columns, sorting) => {
2056
1938
  continue;
2057
1939
  const leftValue = left.row.values.get(sort.id);
2058
1940
  const rightValue = right.row.values.get(sort.id);
2059
- 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 : Schema2.is(Schema2.Number)(leftValue) && Schema2.is(Schema2.Number)(rightValue) ? leftValue - rightValue : String(leftValue).localeCompare(String(rightValue), undefined, { numeric: true, sensitivity: "base" });
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" });
2060
1942
  if (comparison !== 0)
2061
- return sort.desc ? -comparison : comparison;
1943
+ return sort.direction === "desc" ? -comparison : comparison;
2062
1944
  }
2063
1945
  return left.stableIndex - right.stableIndex;
2064
1946
  }).map(({ row }) => row);
@@ -2066,22 +1948,11 @@ var sortDataTableRows = (rows, columns, sorting) => {
2066
1948
  var paginateDataTableRows = (rows, pagination) => {
2067
1949
  const pageSize = Math.max(1, pagination.pageSize);
2068
1950
  const lastPageIndex = Math.max(0, Math.ceil(rows.length / pageSize) - 1);
2069
- const pageIndex = Math.min(lastPageIndex, Math.max(0, pagination.pageIndex));
1951
+ const pageIndex = Math.min(lastPageIndex, Math.max(0, pagination.page));
2070
1952
  const start = pageIndex * pageSize;
2071
1953
  return rows.slice(start, start + pageSize);
2072
1954
  };
2073
- var mergeDataTableState = (state, controlledState = {}) => ({
2074
- globalFilter: controlledState.globalFilter ?? state.globalFilter,
2075
- sorting: controlledState.sorting ?? state.sorting,
2076
- pagination: controlledState.pagination ?? state.pagination,
2077
- columnVisibility: controlledState.columnVisibility ?? state.columnVisibility,
2078
- columnSizing: controlledState.columnSizing ?? state.columnSizing,
2079
- rowSelection: controlledState.rowSelection ?? state.rowSelection,
2080
- grouping: controlledState.grouping ?? state.grouping,
2081
- collapsedGroups: controlledState.collapsedGroups ?? state.collapsedGroups,
2082
- view: controlledState.view ?? state.view
2083
- });
2084
- 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;
2085
1956
  var reorderDataTableRows = (rows, sourceRowId, targetRowId) => {
2086
1957
  const sourceIndex = rows.findIndex((row) => row.id === sourceRowId);
2087
1958
  const targetIndex = rows.findIndex((row) => row.id === targetRowId);
@@ -2136,7 +2007,6 @@ var resolveConfig = (props) => {
2136
2007
  }
2137
2008
  return {
2138
2009
  getRowId,
2139
- onQueryChange: props.onQueryChange,
2140
2010
  onStateChange: props.onStateChange,
2141
2011
  status: props.status ?? {},
2142
2012
  features,
@@ -2144,36 +2014,13 @@ var resolveConfig = (props) => {
2144
2014
  labels: dataTableMessages(props.messages)
2145
2015
  };
2146
2016
  };
2147
- var dataTableStateFromQuery = (query) => query ? {
2148
- globalFilter: query.globalFilter ?? "",
2149
- sorting: query.sort ? Schema2.decodeSync(SortParamsFromString)(query.sort).map(({ id, direction }) => ({
2150
- id,
2151
- desc: direction === "desc"
2152
- })) : [],
2153
- pagination: { pageIndex: query.page, pageSize: query.pageSize }
2154
- } : {};
2155
- var queryFromDataTableState = (state) => ({
2156
- page: state.pagination.pageIndex,
2157
- pageSize: state.pagination.pageSize,
2158
- globalFilter: state.globalFilter || undefined,
2159
- sort: state.sorting.length ? Schema2.encodeSync(SortParamsFromString)(state.sorting.map(({ id, desc }) => ({
2160
- id,
2161
- direction: desc ? "desc" : "asc"
2162
- }))) : undefined
2163
- });
2164
- var sameQuery = (left, right) => left.page === right.page && left.pageSize === right.pageSize && left.globalFilter === right.globalFilter && left.sort === right.sort;
2165
- var controlledStateFromProps = (query, state) => ({
2166
- ...dataTableStateFromQuery(query),
2167
- ...state
2168
- });
2169
2017
  var initialPublicState = (props) => {
2170
2018
  const grouping = props.features?.grouping;
2171
2019
  const groupingInitial = grouping && grouping.initial ? grouping.initial : [];
2172
- return {
2020
+ return props.state ?? {
2173
2021
  ...DEFAULT_STATE,
2174
2022
  grouping: groupingInitial,
2175
- ...props.initialState,
2176
- ...controlledStateFromProps(props.query, props.state)
2023
+ ...props.initialState
2177
2024
  };
2178
2025
  };
2179
2026
  var buildDataTableModel = (store) => {
@@ -2183,9 +2030,9 @@ var buildDataTableModel = (store) => {
2183
2030
  const rows = buildDataTableRows(store.rowData, columns, rowId);
2184
2031
  const pagination = store.config.features.pagination ?? { mode: "client" };
2185
2032
  const server = pagination !== false && pagination.mode === "server";
2186
- const filteredRows = server ? [...rows] : filterDataTableRows(rows, columns, store.state.globalFilter);
2187
- const sortedRows = server ? filteredRows : sortDataTableRows(filteredRows, columns, store.state.sorting);
2188
- 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);
2189
2036
  const totalRows = server ? pagination.rowCount : sortedRows.length;
2190
2037
  return {
2191
2038
  columns,
@@ -2194,7 +2041,7 @@ var buildDataTableModel = (store) => {
2194
2041
  filteredRows,
2195
2042
  sortedRows,
2196
2043
  pageRows,
2197
- 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))),
2198
2045
  totalRows
2199
2046
  };
2200
2047
  };
@@ -2202,13 +2049,8 @@ var useTableAtom = (tableAtom) => useAtom(tableAtom);
2202
2049
  var changeState = (setStore, update) => {
2203
2050
  setStore((store) => {
2204
2051
  const proposed = update(store.state);
2205
- const previousQuery = queryFromDataTableState(store.state);
2206
- const nextQuery = queryFromDataTableState(proposed);
2207
- if (!sameQuery(previousQuery, nextQuery)) {
2208
- store.config.onQueryChange?.(nextQuery);
2209
- }
2210
2052
  store.config.onStateChange?.(proposed);
2211
- const state = mergeDataTableState(proposed, store.controlledState);
2053
+ const state = store.controlledState ?? proposed;
2212
2054
  if (sameDataTableState(state, store.state))
2213
2055
  return store;
2214
2056
  const next = { ...store, state };
@@ -2253,7 +2095,7 @@ var getActiveGrouping = (store) => {
2253
2095
  };
2254
2096
  var canReorderRows = (store) => {
2255
2097
  const pagination = store.config.features.pagination;
2256
- 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");
2257
2099
  };
2258
2100
  var canMoveRowsToGroups = (store) => getActiveGrouping(store).some((field) => !!field.onMoveToGroup);
2259
2101
  var canDragRows = (store) => getActiveGrouping(store).length ? canMoveRowsToGroups(store) : canReorderRows(store);
@@ -2276,11 +2118,11 @@ var renderCell = (row, column) => {
2276
2118
  return column.colDef.valueFormatter?.(params) ?? (value === null || value === undefined ? null : String(value));
2277
2119
  };
2278
2120
  var nodeText = (node) => {
2279
- if (Schema2.is(Schema2.String)(node) || Schema2.is(Schema2.Number)(node))
2121
+ if (Schema.is(Schema.String)(node) || Schema.is(Schema.Number)(node))
2280
2122
  return String(node);
2281
2123
  if (!isValidElement(node))
2282
2124
  return "";
2283
- if (Schema2.is(Schema2.String)(node.props.title))
2125
+ if (Schema.is(Schema.String)(node.props.title))
2284
2126
  return node.props.title;
2285
2127
  return nodeText(node.props.children);
2286
2128
  };
@@ -2427,18 +2269,18 @@ var DataTableToolbar = ({
2427
2269
  onChange: (event) => update((state) => ({
2428
2270
  ...state,
2429
2271
  globalFilter: event.target.value,
2430
- pagination: { ...state.pagination, pageIndex: 0 }
2272
+ page: 0
2431
2273
  })),
2432
2274
  placeholder: labels2.filter,
2433
- value: store.state.globalFilter
2275
+ value: store.state.globalFilter ?? ""
2434
2276
  }),
2435
2277
  store.state.globalFilter ? /* @__PURE__ */ jsx17(Button, {
2436
2278
  "aria-label": labels2.filter,
2437
2279
  className: "absolute top-1/2 right-1 size-7 -translate-y-1/2",
2438
2280
  onClick: () => update((state) => ({
2439
2281
  ...state,
2440
- globalFilter: "",
2441
- pagination: { ...state.pagination, pageIndex: 0 }
2282
+ globalFilter: undefined,
2283
+ page: 0
2442
2284
  })),
2443
2285
  size: "icon",
2444
2286
  variant: "ghost",
@@ -2597,18 +2439,18 @@ var SortMenu = ({
2597
2439
  const columns = deriveModel(store).columns.filter(({ colDef }) => colDef.sortable !== false);
2598
2440
  if (!columns.length)
2599
2441
  return null;
2600
- const current = store.state.sorting[0];
2601
- const sort = (id, desc) => changeState(setStore, (state) => ({
2442
+ const current = store.state.sort?.[0];
2443
+ const sort = (id, direction) => changeState(setStore, (state) => ({
2602
2444
  ...state,
2603
- sorting: [{ id, desc }],
2604
- pagination: { ...state.pagination, pageIndex: 0 }
2445
+ sort: [{ id, direction }],
2446
+ page: 0
2605
2447
  }));
2606
2448
  return /* @__PURE__ */ jsxs9(MenubarMenu, {
2607
2449
  children: [
2608
2450
  /* @__PURE__ */ jsxs9(MenubarTrigger, {
2609
2451
  "aria-label": store.config.labels.sortBy,
2610
2452
  children: [
2611
- 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, {}),
2612
2454
  /* @__PURE__ */ jsx17("span", {
2613
2455
  className: "hidden sm:inline",
2614
2456
  children: store.config.labels.sortBy
@@ -2619,19 +2461,19 @@ var SortMenu = ({
2619
2461
  align: "end",
2620
2462
  className: "w-52",
2621
2463
  children: columns.map((column) => {
2622
- const sortState = store.state.sorting.find(({ id }) => id === column.id);
2464
+ const sortState = store.state.sort?.find(({ id }) => id === column.id);
2623
2465
  return /* @__PURE__ */ jsxs9(MenubarSub, {
2624
2466
  children: [
2625
2467
  /* @__PURE__ */ jsxs9(MenubarSubTrigger, {
2626
2468
  children: [
2627
- sortState ? sortState.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : null,
2469
+ sortState ? sortState.direction === "desc" ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : null,
2628
2470
  columnLabel(column)
2629
2471
  ]
2630
2472
  }),
2631
2473
  /* @__PURE__ */ jsxs9(MenubarSubContent, {
2632
2474
  children: [
2633
2475
  /* @__PURE__ */ jsxs9(MenubarItem, {
2634
- onClick: () => sort(column.id, false),
2476
+ onClick: () => sort(column.id, "asc"),
2635
2477
  children: [
2636
2478
  /* @__PURE__ */ jsx17(ArrowUp, {}),
2637
2479
  " ",
@@ -2639,7 +2481,7 @@ var SortMenu = ({
2639
2481
  ]
2640
2482
  }),
2641
2483
  /* @__PURE__ */ jsxs9(MenubarItem, {
2642
- onClick: () => sort(column.id, true),
2484
+ onClick: () => sort(column.id, "desc"),
2643
2485
  children: [
2644
2486
  /* @__PURE__ */ jsx17(ArrowDown, {}),
2645
2487
  " ",
@@ -2652,7 +2494,7 @@ var SortMenu = ({
2652
2494
  /* @__PURE__ */ jsxs9(MenubarItem, {
2653
2495
  onClick: () => changeState(setStore, (state) => ({
2654
2496
  ...state,
2655
- sorting: state.sorting.filter(({ id }) => id !== column.id)
2497
+ sort: state.sort?.filter(({ id }) => id !== column.id)
2656
2498
  })),
2657
2499
  children: [
2658
2500
  /* @__PURE__ */ jsx17(X2, {}),
@@ -3143,12 +2985,12 @@ var ColumnHeaderMenu = ({
3143
2985
  return null;
3144
2986
  const sortingEnabled = store.config.features.sorting !== false && column.colDef.sortable !== false;
3145
2987
  const hidingEnabled = store.config.features.columnVisibility !== false && column.colDef.hideable !== false;
3146
- const sort = store.state.sorting.find(({ id }) => id === column.id);
2988
+ const sort = store.state.sort?.find(({ id }) => id === column.id);
3147
2989
  const update = (next) => changeState(setStore, next);
3148
- const setSort = (desc) => update((state) => ({
2990
+ const setSort = (direction) => update((state) => ({
3149
2991
  ...state,
3150
- sorting: [{ id: column.id, desc }],
3151
- pagination: { ...state.pagination, pageIndex: 0 }
2992
+ sort: [{ id: column.id, direction }],
2993
+ page: 0
3152
2994
  }));
3153
2995
  const label = columnLabel(column);
3154
2996
  if (!sortingEnabled && !hidingEnabled) {
@@ -3170,7 +3012,7 @@ var ColumnHeaderMenu = ({
3170
3012
  className: "truncate",
3171
3013
  children: column.colDef.headerName
3172
3014
  }),
3173
- 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
3174
3016
  ]
3175
3017
  })
3176
3018
  }),
@@ -3182,7 +3024,7 @@ var ColumnHeaderMenu = ({
3182
3024
  sortingEnabled ? /* @__PURE__ */ jsxs9(Fragment, {
3183
3025
  children: [
3184
3026
  /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3185
- onClick: () => setSort(false),
3027
+ onClick: () => setSort("asc"),
3186
3028
  children: [
3187
3029
  /* @__PURE__ */ jsx17(ArrowUp, {}),
3188
3030
  " ",
@@ -3190,7 +3032,7 @@ var ColumnHeaderMenu = ({
3190
3032
  ]
3191
3033
  }),
3192
3034
  /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3193
- onClick: () => setSort(true),
3035
+ onClick: () => setSort("desc"),
3194
3036
  children: [
3195
3037
  /* @__PURE__ */ jsx17(ArrowDown, {}),
3196
3038
  " ",
@@ -3200,7 +3042,7 @@ var ColumnHeaderMenu = ({
3200
3042
  sort ? /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3201
3043
  onClick: () => update((state) => ({
3202
3044
  ...state,
3203
- sorting: state.sorting.filter(({ id }) => id !== column.id)
3045
+ sort: state.sort?.filter(({ id }) => id !== column.id)
3204
3046
  })),
3205
3047
  children: [
3206
3048
  /* @__PURE__ */ jsx17(X2, {}),
@@ -3505,29 +3347,29 @@ var DataTablePagination = ({
3505
3347
  const pagination = store.config.features.pagination ?? { mode: "client" };
3506
3348
  const clientGrouping = pagination !== false && pagination.mode === "client" && getActiveGrouping(store).length > 0;
3507
3349
  const paginationVisible = pagination !== false && !clientGrouping;
3508
- const pageIndex = store.state.pagination.pageIndex;
3350
+ const pageIndex = store.state.page;
3509
3351
  const maxPageIndex = model.pageCount - 1;
3510
3352
  useLayoutEffect(() => {
3511
3353
  if (paginationVisible && pageIndex > maxPageIndex) {
3512
3354
  changeState(setStore, (state) => ({
3513
3355
  ...state,
3514
- pagination: { ...state.pagination, pageIndex: maxPageIndex }
3356
+ page: maxPageIndex
3515
3357
  }));
3516
3358
  }
3517
3359
  }, [maxPageIndex, pageIndex, paginationVisible, setStore]);
3518
3360
  if (!paginationVisible)
3519
3361
  return null;
3520
3362
  const selected = model.rows.filter((row) => store.state.rowSelection[row.id]).length;
3521
- const setPagination = (next) => changeState(setStore, (state) => ({ ...state, pagination: next }));
3363
+ const setPagination = (next) => changeState(setStore, (state) => ({ ...state, ...next }));
3522
3364
  return /* @__PURE__ */ jsx17("div", {
3523
3365
  className: "pt-4",
3524
3366
  children: /* @__PURE__ */ jsx17(Pagination, {
3525
3367
  messages: store.config.labels,
3526
- onPageChange: (pageIndex2) => setPagination({ ...store.state.pagination, pageIndex: pageIndex2 }),
3527
- onPageSizeChange: (pageSize) => setPagination({ pageIndex: 0, pageSize }),
3528
- 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),
3529
3371
  pageCount: model.pageCount,
3530
- pageSize: store.state.pagination.pageSize,
3372
+ pageSize: store.state.pageSize,
3531
3373
  pageSizes: pagination.pageSizes,
3532
3374
  selectedRows: selected,
3533
3375
  totalRows: model.totalRows
@@ -3543,7 +3385,7 @@ var DataTable = (props) => {
3543
3385
  columnDefs: props.columnDefs,
3544
3386
  config: validatedConfig,
3545
3387
  state: initialPublicState(props),
3546
- controlledState: controlledStateFromProps(props.query, props.state)
3388
+ controlledState: props.state
3547
3389
  };
3548
3390
  atomRef.current = Atom.make({
3549
3391
  ...initial,
@@ -3558,22 +3400,20 @@ var DataTable = (props) => {
3558
3400
  const selection = features.selection;
3559
3401
  const config = {
3560
3402
  getRowId: selection && selection.getRowId || props.getRowId || undefined,
3561
- onQueryChange: props.onQueryChange,
3562
3403
  onStateChange: props.onStateChange,
3563
3404
  status: props.status ?? {},
3564
3405
  features,
3565
3406
  onRowClicked: props.onRowClicked,
3566
3407
  labels: dataTableMessages(props.messages)
3567
3408
  };
3568
- const controlledState = controlledStateFromProps(props.query, props.state);
3569
- const state = mergeDataTableState(store.state, controlledState);
3409
+ const state = props.state ?? store.state;
3570
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;
3571
3411
  const next = {
3572
3412
  ...store,
3573
3413
  rowData: props.rowData,
3574
3414
  columnDefs: props.columnDefs,
3575
3415
  config,
3576
- controlledState,
3416
+ controlledState: props.state,
3577
3417
  state
3578
3418
  };
3579
3419
  return modelChanged ? { ...next, model: buildDataTableModel(next) } : next;
@@ -3584,9 +3424,7 @@ var DataTable = (props) => {
3584
3424
  props.getRowId,
3585
3425
  props.messages,
3586
3426
  props.onRowClicked,
3587
- props.onQueryChange,
3588
3427
  props.onStateChange,
3589
- props.query,
3590
3428
  props.rowData,
3591
3429
  props.state,
3592
3430
  props.status,
@@ -3690,7 +3528,7 @@ var DataTableListSummary = ({
3690
3528
  visibleCount = 3
3691
3529
  }) => {
3692
3530
  const labels2 = dataTableMessages();
3693
- const normalized = items.map((item) => Schema2.is(Schema2.String)(item) ? { label: item } : item);
3531
+ const normalized = items.map((item) => Schema.is(Schema.String)(item) ? { label: item } : item);
3694
3532
  if (!normalized.length)
3695
3533
  return /* @__PURE__ */ jsx17("span", {
3696
3534
  className: "text-muted-foreground",
@@ -3789,7 +3627,6 @@ export {
3789
3627
  getDataTableSelectableRows,
3790
3628
  getDataTableWidth,
3791
3629
  groupDataTableRows,
3792
- mergeDataTableState,
3793
3630
  normalizeDataTableColumns,
3794
3631
  paginateDataTableRows,
3795
3632
  reorderDataTableRows,
@@ -25,12 +25,13 @@ export declare const Query: Schema.Struct<{
25
25
  readonly page: Schema.withDecodingDefaultKey<Schema.Int, never>;
26
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;
34
35
  export declare const QueryStandard: ReturnType<typeof Schema.toStandardSchemaV1<typeof Query>>;
35
36
  export declare const PaginationMeta: Schema.Struct<{
36
37
  readonly page: 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
79
  page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)).pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
89
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,7 +89,10 @@ 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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {