@cerberus-design/data-grid 1.3.0-rc.3 → 1.4.0-rc.1

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.
Files changed (40) hide show
  1. package/dist/components/data-grid.client.cjs +4 -4
  2. package/dist/components/data-grid.client.js +6 -6
  3. package/dist/components/grid.client.cjs +0 -1
  4. package/dist/components/grid.client.js +0 -1
  5. package/dist/components/pagination.client.cjs +1 -1
  6. package/dist/components/pagination.client.js +1 -1
  7. package/dist/components/viewport.client.cjs +2 -3
  8. package/dist/components/viewport.client.js +2 -3
  9. package/dist/context.client.cjs +3 -3
  10. package/dist/context.client.d.cts +3 -4
  11. package/dist/context.client.d.ts +3 -4
  12. package/dist/context.client.js +3 -3
  13. package/dist/panda.buildinfo.json +3 -1
  14. package/dist/store.cjs +33 -281
  15. package/dist/store.js +35 -283
  16. package/dist/stores/data.cjs +65 -0
  17. package/dist/stores/data.d.cts +10 -0
  18. package/dist/stores/data.d.ts +10 -0
  19. package/dist/stores/data.js +65 -0
  20. package/dist/stores/filter.cjs +51 -0
  21. package/dist/stores/filter.d.cts +13 -0
  22. package/dist/stores/filter.d.ts +13 -0
  23. package/dist/stores/filter.js +51 -0
  24. package/dist/stores/index.cjs +11 -0
  25. package/dist/stores/index.d.cts +5 -0
  26. package/dist/stores/index.d.ts +5 -0
  27. package/dist/stores/index.js +6 -0
  28. package/dist/stores/layout.cjs +97 -0
  29. package/dist/stores/layout.d.cts +21 -0
  30. package/dist/stores/layout.d.ts +21 -0
  31. package/dist/stores/layout.js +97 -0
  32. package/dist/stores/pagination.cjs +35 -0
  33. package/dist/stores/pagination.d.cts +18 -0
  34. package/dist/stores/pagination.d.ts +18 -0
  35. package/dist/stores/pagination.js +35 -0
  36. package/dist/stores/sort.cjs +70 -0
  37. package/dist/stores/sort.d.cts +16 -0
  38. package/dist/stores/sort.d.ts +16 -0
  39. package/dist/stores/sort.js +70 -0
  40. package/package.json +18 -18
@@ -0,0 +1,97 @@
1
+ "use client";
2
+ const require_const = require("../const.cjs");
3
+ let _cerberus_design_signals = require("@cerberus-design/signals");
4
+ //#region src/stores/layout.ts
5
+ function createLayoutStore(options) {
6
+ const [containerWidth, setContainerWidth] = (0, _cerberus_design_signals.createSignal)(0);
7
+ const [pending, setPending] = (0, _cerberus_design_signals.createSignal)(options.pending ?? false);
8
+ const [hasSkeleton] = (0, _cerberus_design_signals.createSignal)(options.overlays?.pending === "skeleton");
9
+ return {
10
+ pending,
11
+ hasSkeleton,
12
+ rootCssVars: (0, _cerberus_design_signals.createComputed)(() => {
13
+ const vars = {};
14
+ const visibleCols = [];
15
+ const cols = options.columns();
16
+ const cWidth = containerWidth();
17
+ let fixedSpace = 0;
18
+ let flexCount = 0;
19
+ for (let i = 0; i < cols.length; i++) {
20
+ const col = cols[i];
21
+ if (!col.isVisible()) continue;
22
+ visibleCols.push(col);
23
+ if (col.isFlex()) flexCount++;
24
+ else fixedSpace += col.width();
25
+ const order = options.orderedColumns().findIndex((orderedCol) => orderedCol.id === col.id);
26
+ vars[`--col-${col.id}-order`] = `${order}`;
27
+ }
28
+ const remainingSpace = Math.max(0, cWidth - fixedSpace);
29
+ const flexWidth = flexCount > 0 ? remainingSpace / flexCount : 0;
30
+ let leftOffset = 0;
31
+ let totalW = 0;
32
+ const computedWidths = new Float64Array(visibleCols.length);
33
+ for (let i = 0; i < visibleCols.length; i++) {
34
+ const col = visibleCols[i];
35
+ let finalWidth = col.width();
36
+ if (col.isFlex()) finalWidth = Math.max(col.original.minWidth ?? 150, flexWidth);
37
+ computedWidths[i] = finalWidth;
38
+ totalW += finalWidth;
39
+ vars[`--col-${col.id}-width`] = `${finalWidth}px`;
40
+ if (col.pinned() === "left") {
41
+ vars[`--col-${col.id}-left`] = `${leftOffset}px`;
42
+ leftOffset += finalWidth;
43
+ }
44
+ }
45
+ let rightOffset = 0;
46
+ for (let i = visibleCols.length - 1; i >= 0; i--) {
47
+ const col = visibleCols[i];
48
+ if (col.pinned() === "right") {
49
+ vars[`--col-${col.id}-right`] = `${rightOffset}px`;
50
+ rightOffset += computedWidths[i];
51
+ }
52
+ }
53
+ vars["--total-grid-width"] = `${totalW}px`;
54
+ vars["--row-height"] = `${options.rowSize()}px`;
55
+ const theme = {
56
+ ...require_const.DEFAULT_THEME,
57
+ ...options.theme
58
+ };
59
+ vars["--border"] = theme.border;
60
+ vars["--border-color"] = theme.borderColor;
61
+ vars["--rounded"] = theme.rounded;
62
+ vars["--row-bg-color"] = theme.rowBgColor;
63
+ vars["--row-even-bg-color"] = theme.rowEvenBgColor;
64
+ vars["--row-hover-bg-color"] = theme.rowHoverBgColor;
65
+ vars["--head-cell-bg-color"] = theme.headCellBgColor;
66
+ vars["--head-cell-border-bottom-color"] = theme.headCellBorderBottomColor;
67
+ vars["--grid-cell-border-color"] = theme.gridCellBorderColor;
68
+ vars["--grid-cell-pinned-border-color"] = theme.gridCellPinnedBorderColor;
69
+ return vars;
70
+ }),
71
+ totalWidth: (0, _cerberus_design_signals.createComputed)(() => options.columns().reduce((acc, c) => acc + c.width(), 0)),
72
+ resizeColumn: (colId, delta) => {
73
+ const columns = options.columns();
74
+ const col = columns.find((c) => c.id === colId);
75
+ if (col) {
76
+ if (col.isFlex()) {
77
+ const fixedSpace = columns.filter((c) => !c.isFlex()).reduce((a, b) => a + b.width(), 0);
78
+ const flexCount = columns.filter((c) => c.isFlex()).length;
79
+ const currentFlexWidth = Math.max(col.original.minWidth ?? 150, (containerWidth() - fixedSpace) / flexCount);
80
+ col.setColWidth(currentFlexWidth);
81
+ col.setFlex(false);
82
+ }
83
+ col.setColWidth(Math.max(col.original.minWidth ?? 50, col.width() + delta));
84
+ }
85
+ },
86
+ setContainerWidth,
87
+ togglePinned: (colId, state) => {
88
+ const col = options.columns().find((c) => c.id === colId);
89
+ if (col) col.setPinned(state ?? false);
90
+ },
91
+ updatePending: (newState) => {
92
+ setPending(newState);
93
+ }
94
+ };
95
+ }
96
+ //#endregion
97
+ exports.createLayoutStore = createLayoutStore;
@@ -0,0 +1,21 @@
1
+ import { Accessor, Setter } from '@cerberus-design/signals';
2
+ import { GridOptions, PinnedState } from '../types';
3
+ import { DataStore } from './data';
4
+ type LayoutStore = {
5
+ pending: Accessor<boolean>;
6
+ hasSkeleton: Accessor<boolean>;
7
+ rootCssVars: Accessor<Record<string, string>>;
8
+ totalWidth: Accessor<number>;
9
+ resizeColumn: (colId: string, delta: number) => void;
10
+ setContainerWidth: Setter<number>;
11
+ togglePinned: (colId: string, state: PinnedState) => void;
12
+ updatePending: (newState: boolean) => void;
13
+ };
14
+ type LayoutGridOptions<T> = Omit<GridOptions<T>, 'columns' | 'rowSize'>;
15
+ type Options<T> = {
16
+ columns: DataStore<T>['columns'];
17
+ orderedColumns: DataStore<T>['orderedColumns'];
18
+ rowSize: DataStore<T>['rowSize'];
19
+ } & LayoutGridOptions<T>;
20
+ export declare function createLayoutStore<T>(options: Options<T>): LayoutStore;
21
+ export {};
@@ -0,0 +1,21 @@
1
+ import { Accessor, Setter } from '@cerberus-design/signals';
2
+ import { GridOptions, PinnedState } from '../types';
3
+ import { DataStore } from './data';
4
+ type LayoutStore = {
5
+ pending: Accessor<boolean>;
6
+ hasSkeleton: Accessor<boolean>;
7
+ rootCssVars: Accessor<Record<string, string>>;
8
+ totalWidth: Accessor<number>;
9
+ resizeColumn: (colId: string, delta: number) => void;
10
+ setContainerWidth: Setter<number>;
11
+ togglePinned: (colId: string, state: PinnedState) => void;
12
+ updatePending: (newState: boolean) => void;
13
+ };
14
+ type LayoutGridOptions<T> = Omit<GridOptions<T>, 'columns' | 'rowSize'>;
15
+ type Options<T> = {
16
+ columns: DataStore<T>['columns'];
17
+ orderedColumns: DataStore<T>['orderedColumns'];
18
+ rowSize: DataStore<T>['rowSize'];
19
+ } & LayoutGridOptions<T>;
20
+ export declare function createLayoutStore<T>(options: Options<T>): LayoutStore;
21
+ export {};
@@ -0,0 +1,97 @@
1
+ "use client";
2
+ import { DEFAULT_THEME } from "../const.js";
3
+ import { createComputed, createSignal } from "@cerberus-design/signals";
4
+ //#region src/stores/layout.ts
5
+ function createLayoutStore(options) {
6
+ const [containerWidth, setContainerWidth] = createSignal(0);
7
+ const [pending, setPending] = createSignal(options.pending ?? false);
8
+ const [hasSkeleton] = createSignal(options.overlays?.pending === "skeleton");
9
+ return {
10
+ pending,
11
+ hasSkeleton,
12
+ rootCssVars: createComputed(() => {
13
+ const vars = {};
14
+ const visibleCols = [];
15
+ const cols = options.columns();
16
+ const cWidth = containerWidth();
17
+ let fixedSpace = 0;
18
+ let flexCount = 0;
19
+ for (let i = 0; i < cols.length; i++) {
20
+ const col = cols[i];
21
+ if (!col.isVisible()) continue;
22
+ visibleCols.push(col);
23
+ if (col.isFlex()) flexCount++;
24
+ else fixedSpace += col.width();
25
+ const order = options.orderedColumns().findIndex((orderedCol) => orderedCol.id === col.id);
26
+ vars[`--col-${col.id}-order`] = `${order}`;
27
+ }
28
+ const remainingSpace = Math.max(0, cWidth - fixedSpace);
29
+ const flexWidth = flexCount > 0 ? remainingSpace / flexCount : 0;
30
+ let leftOffset = 0;
31
+ let totalW = 0;
32
+ const computedWidths = new Float64Array(visibleCols.length);
33
+ for (let i = 0; i < visibleCols.length; i++) {
34
+ const col = visibleCols[i];
35
+ let finalWidth = col.width();
36
+ if (col.isFlex()) finalWidth = Math.max(col.original.minWidth ?? 150, flexWidth);
37
+ computedWidths[i] = finalWidth;
38
+ totalW += finalWidth;
39
+ vars[`--col-${col.id}-width`] = `${finalWidth}px`;
40
+ if (col.pinned() === "left") {
41
+ vars[`--col-${col.id}-left`] = `${leftOffset}px`;
42
+ leftOffset += finalWidth;
43
+ }
44
+ }
45
+ let rightOffset = 0;
46
+ for (let i = visibleCols.length - 1; i >= 0; i--) {
47
+ const col = visibleCols[i];
48
+ if (col.pinned() === "right") {
49
+ vars[`--col-${col.id}-right`] = `${rightOffset}px`;
50
+ rightOffset += computedWidths[i];
51
+ }
52
+ }
53
+ vars["--total-grid-width"] = `${totalW}px`;
54
+ vars["--row-height"] = `${options.rowSize()}px`;
55
+ const theme = {
56
+ ...DEFAULT_THEME,
57
+ ...options.theme
58
+ };
59
+ vars["--border"] = theme.border;
60
+ vars["--border-color"] = theme.borderColor;
61
+ vars["--rounded"] = theme.rounded;
62
+ vars["--row-bg-color"] = theme.rowBgColor;
63
+ vars["--row-even-bg-color"] = theme.rowEvenBgColor;
64
+ vars["--row-hover-bg-color"] = theme.rowHoverBgColor;
65
+ vars["--head-cell-bg-color"] = theme.headCellBgColor;
66
+ vars["--head-cell-border-bottom-color"] = theme.headCellBorderBottomColor;
67
+ vars["--grid-cell-border-color"] = theme.gridCellBorderColor;
68
+ vars["--grid-cell-pinned-border-color"] = theme.gridCellPinnedBorderColor;
69
+ return vars;
70
+ }),
71
+ totalWidth: createComputed(() => options.columns().reduce((acc, c) => acc + c.width(), 0)),
72
+ resizeColumn: (colId, delta) => {
73
+ const columns = options.columns();
74
+ const col = columns.find((c) => c.id === colId);
75
+ if (col) {
76
+ if (col.isFlex()) {
77
+ const fixedSpace = columns.filter((c) => !c.isFlex()).reduce((a, b) => a + b.width(), 0);
78
+ const flexCount = columns.filter((c) => c.isFlex()).length;
79
+ const currentFlexWidth = Math.max(col.original.minWidth ?? 150, (containerWidth() - fixedSpace) / flexCount);
80
+ col.setColWidth(currentFlexWidth);
81
+ col.setFlex(false);
82
+ }
83
+ col.setColWidth(Math.max(col.original.minWidth ?? 50, col.width() + delta));
84
+ }
85
+ },
86
+ setContainerWidth,
87
+ togglePinned: (colId, state) => {
88
+ const col = options.columns().find((c) => c.id === colId);
89
+ if (col) col.setPinned(state ?? false);
90
+ },
91
+ updatePending: (newState) => {
92
+ setPending(newState);
93
+ }
94
+ };
95
+ }
96
+ //#endregion
97
+ export { createLayoutStore };
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ const require_utils = require("../utils.cjs");
3
+ let _cerberus_design_signals = require("@cerberus-design/signals");
4
+ //#region src/stores/pagination.ts
5
+ function createPaginationStore(options) {
6
+ const [pageIndex, setPageIndex] = (0, _cerberus_design_signals.createSignal)(require_utils.determinePageIndex(options.initialState?.pagination));
7
+ const [pageSize, setPageSize] = (0, _cerberus_design_signals.createSignal)(require_utils.determinePageSize(options.initialState?.pagination));
8
+ const [pageRange] = (0, _cerberus_design_signals.createSignal)(require_utils.determinePageRange(options.initialState?.pagination));
9
+ const [isServerPaginated] = (0, _cerberus_design_signals.createSignal)(Boolean(require_utils.determineInitialCount(options.initialState?.pagination)));
10
+ return {
11
+ currentPageRange: (0, _cerberus_design_signals.createComputed)(() => {
12
+ const idx = pageIndex();
13
+ const size = pageSize();
14
+ return {
15
+ start: (idx - 1) * size,
16
+ end: idx * size
17
+ };
18
+ }),
19
+ pageIndex,
20
+ pageSize,
21
+ pageRange,
22
+ isServerPaginated,
23
+ setPage: (details) => {
24
+ setPageIndex(details.page);
25
+ options.onPageChange?.(details);
26
+ },
27
+ setPageIndex,
28
+ setPageSize: (size) => {
29
+ if (isServerPaginated()) setPageIndex(1);
30
+ setPageSize(size);
31
+ }
32
+ };
33
+ }
34
+ //#endregion
35
+ exports.createPaginationStore = createPaginationStore;
@@ -0,0 +1,18 @@
1
+ import { PageDetails } from '@cerberus-design/react';
2
+ import { Accessor, Setter } from '@cerberus-design/signals';
3
+ import { GridOptions } from '../types';
4
+ type PaginationStore = {
5
+ currentPageRange: Accessor<{
6
+ start: number;
7
+ end: number;
8
+ }>;
9
+ pageIndex: Accessor<number>;
10
+ pageSize: Accessor<number>;
11
+ pageRange: Accessor<number[]>;
12
+ isServerPaginated: Accessor<boolean>;
13
+ setPage: (details: PageDetails) => void;
14
+ setPageIndex: Setter<number>;
15
+ setPageSize: (size: number) => void;
16
+ };
17
+ export declare function createPaginationStore<TData>(options: GridOptions<TData>): PaginationStore;
18
+ export {};
@@ -0,0 +1,18 @@
1
+ import { PageDetails } from '@cerberus-design/react';
2
+ import { Accessor, Setter } from '@cerberus-design/signals';
3
+ import { GridOptions } from '../types';
4
+ type PaginationStore = {
5
+ currentPageRange: Accessor<{
6
+ start: number;
7
+ end: number;
8
+ }>;
9
+ pageIndex: Accessor<number>;
10
+ pageSize: Accessor<number>;
11
+ pageRange: Accessor<number[]>;
12
+ isServerPaginated: Accessor<boolean>;
13
+ setPage: (details: PageDetails) => void;
14
+ setPageIndex: Setter<number>;
15
+ setPageSize: (size: number) => void;
16
+ };
17
+ export declare function createPaginationStore<TData>(options: GridOptions<TData>): PaginationStore;
18
+ export {};
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import { determineInitialCount, determinePageIndex, determinePageRange, determinePageSize } from "../utils.js";
3
+ import { createComputed, createSignal } from "@cerberus-design/signals";
4
+ //#region src/stores/pagination.ts
5
+ function createPaginationStore(options) {
6
+ const [pageIndex, setPageIndex] = createSignal(determinePageIndex(options.initialState?.pagination));
7
+ const [pageSize, setPageSize] = createSignal(determinePageSize(options.initialState?.pagination));
8
+ const [pageRange] = createSignal(determinePageRange(options.initialState?.pagination));
9
+ const [isServerPaginated] = createSignal(Boolean(determineInitialCount(options.initialState?.pagination)));
10
+ return {
11
+ currentPageRange: createComputed(() => {
12
+ const idx = pageIndex();
13
+ const size = pageSize();
14
+ return {
15
+ start: (idx - 1) * size,
16
+ end: idx * size
17
+ };
18
+ }),
19
+ pageIndex,
20
+ pageSize,
21
+ pageRange,
22
+ isServerPaginated,
23
+ setPage: (details) => {
24
+ setPageIndex(details.page);
25
+ options.onPageChange?.(details);
26
+ },
27
+ setPageIndex,
28
+ setPageSize: (size) => {
29
+ if (isServerPaginated()) setPageIndex(1);
30
+ setPageSize(size);
31
+ }
32
+ };
33
+ }
34
+ //#endregion
35
+ export { createPaginationStore };
@@ -0,0 +1,70 @@
1
+ "use client";
2
+ let _cerberus_design_signals = require("@cerberus-design/signals");
3
+ //#region src/stores/sort.ts
4
+ function createSortStore(options) {
5
+ const [sorting, setSorting] = (0, _cerberus_design_signals.createSignal)([]);
6
+ return {
7
+ sorting,
8
+ sortedRows: (0, _cerberus_design_signals.createComputed)(() => {
9
+ const currentRows = [...options.filteredRows()];
10
+ const sortState = sorting();
11
+ const cols = options.columns();
12
+ if (sortState.length === 0) return currentRows;
13
+ return currentRows.sort((a, b) => {
14
+ for (const sort of sortState) {
15
+ const col = cols.find((c) => c.id === sort.id);
16
+ if (!col) continue;
17
+ const valA = col.getValue(a);
18
+ const valB = col.getValue(b);
19
+ if (valA === valB) continue;
20
+ let comparison = 0;
21
+ const customComparator = typeof col.original.features?.sort === "object" ? col.original.features.sort.comparator : void 0;
22
+ if (customComparator) comparison = customComparator(valA, valB);
23
+ else comparison = valA > valB ? 1 : -1;
24
+ return sort.desc ? -comparison : comparison;
25
+ }
26
+ return 0;
27
+ });
28
+ }),
29
+ setSort: (colId, direction, multi = false) => {
30
+ const current = sorting();
31
+ if (direction === null) {
32
+ setSorting(current.filter((s) => s.id !== colId));
33
+ return;
34
+ }
35
+ const newSort = {
36
+ id: colId,
37
+ desc: direction === "desc"
38
+ };
39
+ if (multi) {
40
+ const existingIndex = current.findIndex((s) => s.id === colId);
41
+ if (existingIndex >= 0) {
42
+ const next = [...current];
43
+ next[existingIndex] = newSort;
44
+ setSorting(next);
45
+ } else setSorting([...current, newSort]);
46
+ } else setSorting([newSort]);
47
+ },
48
+ toggleSort: (colId, multi) => {
49
+ const current = sorting();
50
+ const exists = current.findIndex((s) => s.id === colId) !== -1;
51
+ const updatedSort = current.map((s) => {
52
+ if (s.id === colId) return {
53
+ ...s,
54
+ desc: !s.desc
55
+ };
56
+ return s;
57
+ });
58
+ if (exists) setSorting(multi ? [...current, ...updatedSort] : [...updatedSort]);
59
+ else {
60
+ const newSort = {
61
+ id: colId,
62
+ desc: true
63
+ };
64
+ setSorting(multi ? [...current, newSort] : [newSort]);
65
+ }
66
+ }
67
+ };
68
+ }
69
+ //#endregion
70
+ exports.createSortStore = createSortStore;
@@ -0,0 +1,16 @@
1
+ import { Accessor } from '@cerberus-design/signals';
2
+ import { SortState } from '../types';
3
+ import { DataStore } from './data';
4
+ import { FilterStore } from './filter';
5
+ type SortStore<TData> = {
6
+ sorting: Accessor<SortState[]>;
7
+ sortedRows: Accessor<TData[]>;
8
+ setSort: (colId: string, direction: 'asc' | 'desc' | null, multi?: boolean) => void;
9
+ toggleSort: (colId: string, multi?: boolean) => void;
10
+ };
11
+ type Options<TData> = {
12
+ columns: DataStore<TData>['columns'];
13
+ filteredRows: FilterStore<TData>['filteredRows'];
14
+ };
15
+ export declare function createSortStore<TData>(options: Options<TData>): SortStore<TData>;
16
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Accessor } from '@cerberus-design/signals';
2
+ import { SortState } from '../types';
3
+ import { DataStore } from './data';
4
+ import { FilterStore } from './filter';
5
+ type SortStore<TData> = {
6
+ sorting: Accessor<SortState[]>;
7
+ sortedRows: Accessor<TData[]>;
8
+ setSort: (colId: string, direction: 'asc' | 'desc' | null, multi?: boolean) => void;
9
+ toggleSort: (colId: string, multi?: boolean) => void;
10
+ };
11
+ type Options<TData> = {
12
+ columns: DataStore<TData>['columns'];
13
+ filteredRows: FilterStore<TData>['filteredRows'];
14
+ };
15
+ export declare function createSortStore<TData>(options: Options<TData>): SortStore<TData>;
16
+ export {};
@@ -0,0 +1,70 @@
1
+ "use client";
2
+ import { createComputed, createSignal } from "@cerberus-design/signals";
3
+ //#region src/stores/sort.ts
4
+ function createSortStore(options) {
5
+ const [sorting, setSorting] = createSignal([]);
6
+ return {
7
+ sorting,
8
+ sortedRows: createComputed(() => {
9
+ const currentRows = [...options.filteredRows()];
10
+ const sortState = sorting();
11
+ const cols = options.columns();
12
+ if (sortState.length === 0) return currentRows;
13
+ return currentRows.sort((a, b) => {
14
+ for (const sort of sortState) {
15
+ const col = cols.find((c) => c.id === sort.id);
16
+ if (!col) continue;
17
+ const valA = col.getValue(a);
18
+ const valB = col.getValue(b);
19
+ if (valA === valB) continue;
20
+ let comparison = 0;
21
+ const customComparator = typeof col.original.features?.sort === "object" ? col.original.features.sort.comparator : void 0;
22
+ if (customComparator) comparison = customComparator(valA, valB);
23
+ else comparison = valA > valB ? 1 : -1;
24
+ return sort.desc ? -comparison : comparison;
25
+ }
26
+ return 0;
27
+ });
28
+ }),
29
+ setSort: (colId, direction, multi = false) => {
30
+ const current = sorting();
31
+ if (direction === null) {
32
+ setSorting(current.filter((s) => s.id !== colId));
33
+ return;
34
+ }
35
+ const newSort = {
36
+ id: colId,
37
+ desc: direction === "desc"
38
+ };
39
+ if (multi) {
40
+ const existingIndex = current.findIndex((s) => s.id === colId);
41
+ if (existingIndex >= 0) {
42
+ const next = [...current];
43
+ next[existingIndex] = newSort;
44
+ setSorting(next);
45
+ } else setSorting([...current, newSort]);
46
+ } else setSorting([newSort]);
47
+ },
48
+ toggleSort: (colId, multi) => {
49
+ const current = sorting();
50
+ const exists = current.findIndex((s) => s.id === colId) !== -1;
51
+ const updatedSort = current.map((s) => {
52
+ if (s.id === colId) return {
53
+ ...s,
54
+ desc: !s.desc
55
+ };
56
+ return s;
57
+ });
58
+ if (exists) setSorting(multi ? [...current, ...updatedSort] : [...updatedSort]);
59
+ else {
60
+ const newSort = {
61
+ id: colId,
62
+ desc: true
63
+ };
64
+ setSorting(multi ? [...current, newSort] : [newSort]);
65
+ }
66
+ }
67
+ };
68
+ }
69
+ //#endregion
70
+ export { createSortStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerberus-design/data-grid",
3
- "version": "1.3.0-rc.3",
3
+ "version": "1.4.0-rc.1",
4
4
  "description": "The Cerberus Design React DataGrid component.",
5
5
  "keywords": [
6
6
  "data grid",
@@ -27,20 +27,20 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@cerberus-design/react": "1.3.0-rc.3",
31
- "@cerberus-design/signals": "1.3.0-rc.3"
30
+ "@cerberus-design/signals": "1.4.0-rc.1",
31
+ "@cerberus-design/react": "1.4.0-rc.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@pandacss/dev": "^1.11.0",
35
- "@types/react": "^19.2.14",
34
+ "@pandacss/dev": "^1.11.1",
35
+ "@types/react": "^19.2.15",
36
36
  "@types/react-dom": "^19.2.3",
37
37
  "@vitejs/plugin-react": "^6.0.1",
38
38
  "globby": "^16.2.0",
39
- "react": "^19.2.5",
40
- "react-dom": "^19.2.5",
41
- "vite": "^8.0.8",
42
- "vite-plugin-dts": "^5.0.0",
43
- "@cerberus/panda-preset": "1.3.0-rc.3",
39
+ "react": "^19.2.6",
40
+ "react-dom": "^19.2.6",
41
+ "vite": "^8.0.14",
42
+ "vite-plugin-dts": "^5.0.1",
43
+ "@cerberus/panda-preset": "1.4.0-rc.1",
44
44
  "styled-system": "0.0.0"
45
45
  },
46
46
  "peerDependencies": {
@@ -55,6 +55,14 @@
55
55
  "clean": "rm -rf ./dist",
56
56
  "lint:ts": "tsc --project tsconfig.lint.json --noEmit"
57
57
  },
58
+ "types": "dist/index.d.cts",
59
+ "typesVersions": {
60
+ "*": {
61
+ ".": [
62
+ "dist/index.d.cts"
63
+ ]
64
+ }
65
+ },
58
66
  "exports": {
59
67
  ".": {
60
68
  "import": {
@@ -67,13 +75,5 @@
67
75
  }
68
76
  },
69
77
  "./package.json": "./package.json"
70
- },
71
- "types": "dist/index.d.cts",
72
- "typesVersions": {
73
- "*": {
74
- ".": [
75
- "dist/index.d.cts"
76
- ]
77
- }
78
78
  }
79
79
  }