@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.
- package/dist/components/data-grid.client.cjs +4 -4
- package/dist/components/data-grid.client.js +6 -6
- package/dist/components/grid.client.cjs +0 -1
- package/dist/components/grid.client.js +0 -1
- package/dist/components/pagination.client.cjs +1 -1
- package/dist/components/pagination.client.js +1 -1
- package/dist/components/viewport.client.cjs +2 -3
- package/dist/components/viewport.client.js +2 -3
- package/dist/context.client.cjs +3 -3
- package/dist/context.client.d.cts +3 -4
- package/dist/context.client.d.ts +3 -4
- package/dist/context.client.js +3 -3
- package/dist/panda.buildinfo.json +3 -1
- package/dist/store.cjs +33 -281
- package/dist/store.js +35 -283
- package/dist/stores/data.cjs +65 -0
- package/dist/stores/data.d.cts +10 -0
- package/dist/stores/data.d.ts +10 -0
- package/dist/stores/data.js +65 -0
- package/dist/stores/filter.cjs +51 -0
- package/dist/stores/filter.d.cts +13 -0
- package/dist/stores/filter.d.ts +13 -0
- package/dist/stores/filter.js +51 -0
- package/dist/stores/index.cjs +11 -0
- package/dist/stores/index.d.cts +5 -0
- package/dist/stores/index.d.ts +5 -0
- package/dist/stores/index.js +6 -0
- package/dist/stores/layout.cjs +97 -0
- package/dist/stores/layout.d.cts +21 -0
- package/dist/stores/layout.d.ts +21 -0
- package/dist/stores/layout.js +97 -0
- package/dist/stores/pagination.cjs +35 -0
- package/dist/stores/pagination.d.cts +18 -0
- package/dist/stores/pagination.d.ts +18 -0
- package/dist/stores/pagination.js +35 -0
- package/dist/stores/sort.cjs +70 -0
- package/dist/stores/sort.d.cts +16 -0
- package/dist/stores/sort.d.ts +16 -0
- package/dist/stores/sort.js +70 -0
- package/package.json +18 -18
|
@@ -14,7 +14,9 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
14
14
|
//#region src/components/data-grid.client.tsx
|
|
15
15
|
function DataGridEl(props) {
|
|
16
16
|
const { data } = props;
|
|
17
|
-
const
|
|
17
|
+
const [ready, setReady] = (0, _cerberus_design_signals.useSignal)(false);
|
|
18
|
+
const rootRef = (0, react.useRef)(null);
|
|
19
|
+
const store = (0, _cerberus_design_signals.useStore)(() => require_store.createGridStore({
|
|
18
20
|
data,
|
|
19
21
|
columns: props.columns,
|
|
20
22
|
initialState: props.initialState,
|
|
@@ -23,9 +25,7 @@ function DataGridEl(props) {
|
|
|
23
25
|
overlays: props.overlays,
|
|
24
26
|
pending: props.pending,
|
|
25
27
|
theme: props.theme
|
|
26
|
-
})
|
|
27
|
-
const [ready, setReady] = (0, _cerberus_design_signals.useSignal)(false);
|
|
28
|
-
const rootRef = (0, react.useRef)(null);
|
|
28
|
+
}));
|
|
29
29
|
(0, react.useEffect)(() => {
|
|
30
30
|
store.updateData(data);
|
|
31
31
|
}, [data, store]);
|
|
@@ -7,14 +7,16 @@ import { GridPagination } from "./pagination.client.js";
|
|
|
7
7
|
import { DGPopover, DGPopoverAnchor } from "./popover.client.js";
|
|
8
8
|
import { GridViewport } from "./viewport.client.js";
|
|
9
9
|
import { Show } from "@cerberus-design/react";
|
|
10
|
-
import { createEffect, useSignal } from "@cerberus-design/signals";
|
|
11
|
-
import { memo, useEffect,
|
|
10
|
+
import { createEffect, useSignal, useStore } from "@cerberus-design/signals";
|
|
11
|
+
import { memo, useEffect, useRef } from "react";
|
|
12
12
|
import { HStack, Stack } from "styled-system/jsx";
|
|
13
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
14
|
//#region src/components/data-grid.client.tsx
|
|
15
15
|
function DataGridEl(props) {
|
|
16
16
|
const { data } = props;
|
|
17
|
-
const
|
|
17
|
+
const [ready, setReady] = useSignal(false);
|
|
18
|
+
const rootRef = useRef(null);
|
|
19
|
+
const store = useStore(() => createGridStore({
|
|
18
20
|
data,
|
|
19
21
|
columns: props.columns,
|
|
20
22
|
initialState: props.initialState,
|
|
@@ -23,9 +25,7 @@ function DataGridEl(props) {
|
|
|
23
25
|
overlays: props.overlays,
|
|
24
26
|
pending: props.pending,
|
|
25
27
|
theme: props.theme
|
|
26
|
-
})
|
|
27
|
-
const [ready, setReady] = useSignal(false);
|
|
28
|
-
const rootRef = useRef(null);
|
|
28
|
+
}));
|
|
29
29
|
useEffect(() => {
|
|
30
30
|
store.updateData(data);
|
|
31
31
|
}, [data, store]);
|
|
@@ -105,7 +105,6 @@ var GridHeaderCell = (0, react.memo)(function GridHeaderCell(props) {
|
|
|
105
105
|
openDelay: 800,
|
|
106
106
|
portal: true,
|
|
107
107
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.IconButtonRoot, {
|
|
108
|
-
clipboard: true,
|
|
109
108
|
size: "sm",
|
|
110
109
|
onClick: handleEditFilters,
|
|
111
110
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditFilterIcon, {})
|
|
@@ -105,7 +105,6 @@ var GridHeaderCell = memo(function GridHeaderCell(props) {
|
|
|
105
105
|
openDelay: 800,
|
|
106
106
|
portal: true,
|
|
107
107
|
children: /* @__PURE__ */ jsx(IconButtonRoot, {
|
|
108
|
-
clipboard: true,
|
|
109
108
|
size: "sm",
|
|
110
109
|
onClick: handleEditFilters,
|
|
111
110
|
children: /* @__PURE__ */ jsx(EditFilterIcon, {})
|
|
@@ -80,8 +80,7 @@ var TableRows = (0, react.memo)((props) => {
|
|
|
80
80
|
const store = require_context_client.useDataGridContext();
|
|
81
81
|
const { virtualRows, totalHeight } = require_virtualizer_client.useVirtualizer(store, props.viewportRef);
|
|
82
82
|
const isServerPaginated = (0, _cerberus_design_signals.useRead)(store.isServerPaginated);
|
|
83
|
-
const staticRows = (0, _cerberus_design_signals.useRead)(store.
|
|
84
|
-
const currentPageRange = (0, _cerberus_design_signals.useRead)(store.currentPageRange);
|
|
83
|
+
const staticRows = (0, _cerberus_design_signals.useRead)(store.visibleRows);
|
|
85
84
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.Show, {
|
|
86
85
|
when: isServerPaginated,
|
|
87
86
|
fallback: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(styled_system_jsx.Box, {
|
|
@@ -102,7 +101,7 @@ var TableRows = (0, react.memo)((props) => {
|
|
|
102
101
|
gap: "0",
|
|
103
102
|
w: "var(--total-grid-width)",
|
|
104
103
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.For, {
|
|
105
|
-
each: staticRows
|
|
104
|
+
each: staticRows,
|
|
106
105
|
children: (row, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_grid_client.GridRow, {
|
|
107
106
|
row,
|
|
108
107
|
index
|
|
@@ -80,8 +80,7 @@ var TableRows = memo((props) => {
|
|
|
80
80
|
const store = useDataGridContext();
|
|
81
81
|
const { virtualRows, totalHeight } = useVirtualizer(store, props.viewportRef);
|
|
82
82
|
const isServerPaginated = useRead(store.isServerPaginated);
|
|
83
|
-
const staticRows = useRead(store.
|
|
84
|
-
const currentPageRange = useRead(store.currentPageRange);
|
|
83
|
+
const staticRows = useRead(store.visibleRows);
|
|
85
84
|
return /* @__PURE__ */ jsx(Show, {
|
|
86
85
|
when: isServerPaginated,
|
|
87
86
|
fallback: /* @__PURE__ */ jsx(Box, {
|
|
@@ -102,7 +101,7 @@ var TableRows = memo((props) => {
|
|
|
102
101
|
gap: "0",
|
|
103
102
|
w: "var(--total-grid-width)",
|
|
104
103
|
children: /* @__PURE__ */ jsx(For, {
|
|
105
|
-
each: staticRows
|
|
104
|
+
each: staticRows,
|
|
106
105
|
children: (row, index) => /* @__PURE__ */ jsx(GridRow, {
|
|
107
106
|
row,
|
|
108
107
|
index
|
package/dist/context.client.cjs
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
let _cerberus_design_signals = require("@cerberus-design/signals");
|
|
4
4
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
5
|
//#region src/context.client.tsx
|
|
6
|
-
var { StoreProvider
|
|
6
|
+
var { StoreProvider, useStore } = (0, _cerberus_design_signals.createStoreContext)();
|
|
7
7
|
function DataGridProvider(props) {
|
|
8
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
8
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StoreProvider, {
|
|
9
9
|
createStore: props.createStore,
|
|
10
10
|
children: props.children
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
function useDataGridContext() {
|
|
14
|
-
return
|
|
14
|
+
return useStore();
|
|
15
15
|
}
|
|
16
16
|
//#endregion
|
|
17
17
|
exports.DataGridProvider = DataGridProvider;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { GridStore } from './types';
|
|
3
|
-
export declare function DataGridProvider<TData>(props: {
|
|
3
|
+
export declare function DataGridProvider<TData>(props: PropsWithChildren<{
|
|
4
4
|
createStore: () => GridStore<TData>;
|
|
5
|
-
|
|
6
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
7
6
|
export declare function useDataGridContext<TData>(): GridStore<TData>;
|
package/dist/context.client.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { GridStore } from './types';
|
|
3
|
-
export declare function DataGridProvider<TData>(props: {
|
|
3
|
+
export declare function DataGridProvider<TData>(props: PropsWithChildren<{
|
|
4
4
|
createStore: () => GridStore<TData>;
|
|
5
|
-
|
|
6
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
7
6
|
export declare function useDataGridContext<TData>(): GridStore<TData>;
|
package/dist/context.client.js
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
import { createStoreContext } from "@cerberus-design/signals";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/context.client.tsx
|
|
6
|
-
var { StoreProvider
|
|
6
|
+
var { StoreProvider, useStore: useStore$1 } = createStoreContext();
|
|
7
7
|
function DataGridProvider(props) {
|
|
8
|
-
return /* @__PURE__ */ jsx(
|
|
8
|
+
return /* @__PURE__ */ jsx(StoreProvider, {
|
|
9
9
|
createStore: props.createStore,
|
|
10
10
|
children: props.children
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
function useDataGridContext() {
|
|
14
|
-
return
|
|
14
|
+
return useStore$1();
|
|
15
15
|
}
|
|
16
16
|
//#endregion
|
|
17
17
|
export { DataGridProvider, useDataGridContext };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"schemaVersion": "1.11.
|
|
2
|
+
"schemaVersion": "1.11.1",
|
|
3
3
|
"styles": {
|
|
4
4
|
"atomic": [
|
|
5
5
|
"display]___[value:flex",
|
|
@@ -192,6 +192,7 @@
|
|
|
192
192
|
"colorPalette]___[value:page",
|
|
193
193
|
"colorPalette]___[value:action",
|
|
194
194
|
"colorPalette]___[value:secondary-action",
|
|
195
|
+
"colorPalette]___[value:secondaryAction",
|
|
195
196
|
"colorPalette]___[value:info",
|
|
196
197
|
"colorPalette]___[value:success",
|
|
197
198
|
"colorPalette]___[value:warning",
|
|
@@ -347,6 +348,7 @@
|
|
|
347
348
|
"size]___[value:xs]___[recipe:progressBar",
|
|
348
349
|
"usage]___[value:block]___[recipe:progressBar"
|
|
349
350
|
],
|
|
351
|
+
"marquee": [],
|
|
350
352
|
"toast": [],
|
|
351
353
|
"group": [
|
|
352
354
|
"orientation]___[value:horizontal]___[recipe:group",
|
package/dist/store.cjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const require_const = require("./const.cjs");
|
|
3
2
|
const require_utils = require("./utils.cjs");
|
|
3
|
+
const require_data = require("./stores/data.cjs");
|
|
4
|
+
const require_pagination = require("./stores/pagination.cjs");
|
|
5
|
+
const require_filter = require("./stores/filter.cjs");
|
|
6
|
+
const require_sort = require("./stores/sort.cjs");
|
|
7
|
+
const require_layout = require("./stores/layout.cjs");
|
|
4
8
|
let _cerberus_design_signals = require("@cerberus-design/signals");
|
|
5
9
|
//#region src/store.ts
|
|
6
10
|
/**
|
|
@@ -8,294 +12,42 @@ let _cerberus_design_signals = require("@cerberus-design/signals");
|
|
|
8
12
|
* the public Context API.
|
|
9
13
|
*/
|
|
10
14
|
function createGridStore(options) {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const [globalFilter, setGlobalFilter] = (0, _cerberus_design_signals.createSignal)({
|
|
18
|
-
operator: require_const.OPERATORS.contains,
|
|
19
|
-
value: null
|
|
15
|
+
const dataStore = require_data.createDataStore(options);
|
|
16
|
+
const paginationStore = require_pagination.createPaginationStore(options);
|
|
17
|
+
const filterStore = require_filter.createFilterStore(dataStore);
|
|
18
|
+
const sortStore = require_sort.createSortStore({
|
|
19
|
+
columns: dataStore.columns,
|
|
20
|
+
filteredRows: filterStore.filteredRows
|
|
20
21
|
});
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const [sorting, setSorting] = (0, _cerberus_design_signals.createSignal)([]);
|
|
27
|
-
const [pageIndex, setPageIndex] = (0, _cerberus_design_signals.createSignal)(require_utils.determinePageIndex(options.initialState?.pagination));
|
|
28
|
-
const [pageSize, setPageSize] = (0, _cerberus_design_signals.createSignal)(require_utils.determinePageSize(options.initialState?.pagination));
|
|
29
|
-
const [pageRange] = (0, _cerberus_design_signals.createSignal)(require_utils.determinePageRange(options.initialState?.pagination));
|
|
30
|
-
const [isServerPaginated] = (0, _cerberus_design_signals.createSignal)(Boolean(require_utils.determineInitialCount(options.initialState?.pagination)));
|
|
31
|
-
const [columns] = (0, _cerberus_design_signals.createSignal)(options.columns.map((col) => {
|
|
32
|
-
const pinnable = Boolean(col.features?.pinning);
|
|
33
|
-
const filterable = Boolean(col.features?.filter);
|
|
34
|
-
const sortable = Boolean(col.features?.sort);
|
|
35
|
-
const hasFeatures = pinnable || filterable || sortable;
|
|
36
|
-
const minWForFeatures = 100;
|
|
37
|
-
let finalWidth = col.width ?? 150;
|
|
38
|
-
if (hasFeatures && col.width && col.width < minWForFeatures) finalWidth = minWForFeatures;
|
|
39
|
-
const [isVisible] = (0, _cerberus_design_signals.createSignal)(true);
|
|
40
|
-
const [isFlex, setFlex] = (0, _cerberus_design_signals.createSignal)(col.width === void 0);
|
|
41
|
-
const [pinned, setPinned] = (0, _cerberus_design_signals.createSignal)(col.features?.pinning?.defaultPosition ?? false);
|
|
42
|
-
const [width, setColWidth] = (0, _cerberus_design_signals.createSignal)(finalWidth);
|
|
43
|
-
return {
|
|
44
|
-
id: col.id,
|
|
45
|
-
isFlex,
|
|
46
|
-
isVisible,
|
|
47
|
-
original: col,
|
|
48
|
-
pinned,
|
|
49
|
-
width,
|
|
50
|
-
getValue: col.accessor,
|
|
51
|
-
pinnable,
|
|
52
|
-
filterable,
|
|
53
|
-
sortable,
|
|
54
|
-
setFlex,
|
|
55
|
-
setPinned,
|
|
56
|
-
setColWidth
|
|
57
|
-
};
|
|
58
|
-
}));
|
|
59
|
-
const currentPageRange = (0, _cerberus_design_signals.createComputed)(() => {
|
|
60
|
-
const dataIdx = pageIndex() - 1;
|
|
61
|
-
return {
|
|
62
|
-
start: dataIdx === 0 ? 0 : dataIdx * pageSize() - 1,
|
|
63
|
-
end: pageIndex() * pageSize()
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
const filteredRows = (0, _cerberus_design_signals.createComputed)(() => {
|
|
67
|
-
let result = [...rows()];
|
|
68
|
-
const gFilter = globalFilter();
|
|
69
|
-
const cFilters = colFilters();
|
|
70
|
-
if (cFilters.active.length > 0) result = result.filter((row) => {
|
|
71
|
-
return cFilters.active.every((filterId) => {
|
|
72
|
-
const col = columns().find((c) => c.id === filterId);
|
|
73
|
-
const filter = cFilters.filters[filterId];
|
|
74
|
-
if (!col || !col.filterable) return true;
|
|
75
|
-
const customFn = typeof col.original.features?.filter === "function" ? col.original.features.filter : void 0;
|
|
76
|
-
if (customFn) return customFn(row, col.id, filter.value);
|
|
77
|
-
return require_utils.applyFilterOperator(col.getValue(row), filter.value, filter.operator);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
if (gFilter.value) result = result.filter((row) => {
|
|
81
|
-
return columns().some((col) => {
|
|
82
|
-
if (!col.filterable) return false;
|
|
83
|
-
return require_utils.applyFilterOperator(col.getValue(row), gFilter.value, gFilter.operator);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
return result;
|
|
87
|
-
});
|
|
88
|
-
const sortedRows = (0, _cerberus_design_signals.createComputed)(() => {
|
|
89
|
-
const currentRows = [...filteredRows()];
|
|
90
|
-
const sortState = sorting();
|
|
91
|
-
if (sortState.length === 0) return currentRows;
|
|
92
|
-
return currentRows.sort((a, b) => {
|
|
93
|
-
for (const sort of sortState) {
|
|
94
|
-
const col = columns().find((c) => c.id === sort.id);
|
|
95
|
-
if (!col) continue;
|
|
96
|
-
const valA = col.getValue(a);
|
|
97
|
-
const valB = col.getValue(b);
|
|
98
|
-
if (valA === valB) continue;
|
|
99
|
-
let comparison = 0;
|
|
100
|
-
const customComparator = typeof col.original.features?.sort === "object" ? col.original.features.sort.comparator : void 0;
|
|
101
|
-
if (customComparator) comparison = customComparator(valA, valB);
|
|
102
|
-
else comparison = valA > valB ? 1 : -1;
|
|
103
|
-
return sort.desc ? -comparison : comparison;
|
|
104
|
-
}
|
|
105
|
-
return 0;
|
|
106
|
-
});
|
|
22
|
+
const layoutStore = require_layout.createLayoutStore({
|
|
23
|
+
...options,
|
|
24
|
+
orderedColumns: dataStore.orderedColumns,
|
|
25
|
+
columns: dataStore.columns,
|
|
26
|
+
rowSize: dataStore.rowSize
|
|
107
27
|
});
|
|
108
28
|
const rowCount = (0, _cerberus_design_signals.createComputed)(() => {
|
|
109
|
-
return require_utils.determineInitialCount(options?.initialState?.pagination) ??
|
|
29
|
+
return require_utils.determineInitialCount(options?.initialState?.pagination) ?? filterStore.filteredRows().length;
|
|
110
30
|
});
|
|
111
|
-
const pageCount = (0, _cerberus_design_signals.createComputed)(() => Math.ceil(rowCount() / pageSize()));
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
return [
|
|
123
|
-
...left,
|
|
124
|
-
...center,
|
|
125
|
-
...right
|
|
126
|
-
];
|
|
31
|
+
const pageCount = (0, _cerberus_design_signals.createComputed)(() => Math.ceil(rowCount() / paginationStore.pageSize()));
|
|
32
|
+
const visibleRows = (0, _cerberus_design_signals.createComputed)(() => {
|
|
33
|
+
const size = paginationStore.pageSize();
|
|
34
|
+
const rows = sortStore.sortedRows();
|
|
35
|
+
if (paginationStore.isServerPaginated()) return rows;
|
|
36
|
+
if (size) {
|
|
37
|
+
const ctx = paginationStore.currentPageRange();
|
|
38
|
+
return rows.slice(ctx.start, ctx.end);
|
|
39
|
+
}
|
|
40
|
+
return rows;
|
|
127
41
|
});
|
|
128
42
|
return {
|
|
129
|
-
|
|
130
|
-
|
|
43
|
+
...dataStore,
|
|
44
|
+
...paginationStore,
|
|
45
|
+
...filterStore,
|
|
46
|
+
...sortStore,
|
|
47
|
+
...layoutStore,
|
|
131
48
|
rowCount,
|
|
132
|
-
rowSize,
|
|
133
|
-
visibleRows: (0, _cerberus_design_signals.createComputed)(() => {
|
|
134
|
-
if (pageSize() && pageCount() > 1) {
|
|
135
|
-
const currentRange = currentPageRange();
|
|
136
|
-
return sortedRows().slice(currentRange.start, currentRange.end);
|
|
137
|
-
}
|
|
138
|
-
return sortedRows();
|
|
139
|
-
}),
|
|
140
|
-
showColFilter,
|
|
141
|
-
globalFilter,
|
|
142
|
-
colFilters,
|
|
143
|
-
sorting,
|
|
144
|
-
pending,
|
|
145
|
-
hasSkeleton,
|
|
146
49
|
pageCount,
|
|
147
|
-
|
|
148
|
-
pageSize,
|
|
149
|
-
pageRange,
|
|
150
|
-
currentPageRange,
|
|
151
|
-
isServerPaginated,
|
|
152
|
-
rootCssVars: (0, _cerberus_design_signals.createComputed)(() => {
|
|
153
|
-
const vars = {};
|
|
154
|
-
const visibleCols = [];
|
|
155
|
-
const cols = columns();
|
|
156
|
-
const cWidth = containerWidth();
|
|
157
|
-
let fixedSpace = 0;
|
|
158
|
-
let flexCount = 0;
|
|
159
|
-
for (let i = 0; i < cols.length; i++) {
|
|
160
|
-
const col = cols[i];
|
|
161
|
-
if (!col.isVisible()) continue;
|
|
162
|
-
visibleCols.push(col);
|
|
163
|
-
if (col.isFlex()) flexCount++;
|
|
164
|
-
else fixedSpace += col.width();
|
|
165
|
-
const order = orderedColumns().findIndex((orderedCol) => orderedCol.id === col.id);
|
|
166
|
-
vars[`--col-${col.id}-order`] = `${order}`;
|
|
167
|
-
}
|
|
168
|
-
const remainingSpace = Math.max(0, cWidth - fixedSpace);
|
|
169
|
-
const flexWidth = flexCount > 0 ? remainingSpace / flexCount : 0;
|
|
170
|
-
let leftOffset = 0;
|
|
171
|
-
let totalW = 0;
|
|
172
|
-
const computedWidths = new Float64Array(visibleCols.length);
|
|
173
|
-
for (let i = 0; i < visibleCols.length; i++) {
|
|
174
|
-
const col = visibleCols[i];
|
|
175
|
-
let finalWidth = col.width();
|
|
176
|
-
if (col.isFlex()) finalWidth = Math.max(col.original.minWidth ?? 150, flexWidth);
|
|
177
|
-
computedWidths[i] = finalWidth;
|
|
178
|
-
totalW += finalWidth;
|
|
179
|
-
vars[`--col-${col.id}-width`] = `${finalWidth}px`;
|
|
180
|
-
if (col.pinned() === "left") {
|
|
181
|
-
vars[`--col-${col.id}-left`] = `${leftOffset}px`;
|
|
182
|
-
leftOffset += finalWidth;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
let rightOffset = 0;
|
|
186
|
-
for (let i = visibleCols.length - 1; i >= 0; i--) {
|
|
187
|
-
const col = visibleCols[i];
|
|
188
|
-
if (col.pinned() === "right") {
|
|
189
|
-
vars[`--col-${col.id}-right`] = `${rightOffset}px`;
|
|
190
|
-
rightOffset += computedWidths[i];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
vars["--total-grid-width"] = `${totalW}px`;
|
|
194
|
-
vars["--row-height"] = `${rowSize()}px`;
|
|
195
|
-
const theme = {
|
|
196
|
-
...require_const.DEFAULT_THEME,
|
|
197
|
-
...options.theme
|
|
198
|
-
};
|
|
199
|
-
vars["--border"] = theme.border;
|
|
200
|
-
vars["--border-color"] = theme.borderColor;
|
|
201
|
-
vars["--rounded"] = theme.rounded;
|
|
202
|
-
vars["--row-bg-color"] = theme.rowBgColor;
|
|
203
|
-
vars["--row-even-bg-color"] = theme.rowEvenBgColor;
|
|
204
|
-
vars["--row-hover-bg-color"] = theme.rowHoverBgColor;
|
|
205
|
-
vars["--head-cell-bg-color"] = theme.headCellBgColor;
|
|
206
|
-
vars["--head-cell-border-bottom-color"] = theme.headCellBorderBottomColor;
|
|
207
|
-
vars["--grid-cell-border-color"] = theme.gridCellBorderColor;
|
|
208
|
-
vars["--grid-cell-pinned-border-color"] = theme.gridCellPinnedBorderColor;
|
|
209
|
-
return vars;
|
|
210
|
-
}),
|
|
211
|
-
totalWidth: (0, _cerberus_design_signals.createComputed)(() => columns().reduce((acc, c) => acc + c.width(), 0)),
|
|
212
|
-
updateData: (newData) => {
|
|
213
|
-
setRows(newData);
|
|
214
|
-
},
|
|
215
|
-
updatePending: (newState) => {
|
|
216
|
-
setPending(newState);
|
|
217
|
-
},
|
|
218
|
-
setSort: (colId, direction, multi = false) => {
|
|
219
|
-
if (direction === null) {
|
|
220
|
-
setSorting(sorting().filter((s) => s.id !== colId));
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const current = sorting();
|
|
224
|
-
const newSort = {
|
|
225
|
-
id: colId,
|
|
226
|
-
desc: direction === "desc"
|
|
227
|
-
};
|
|
228
|
-
if (multi) {
|
|
229
|
-
const existingIndex = current.findIndex((s) => s.id === colId);
|
|
230
|
-
if (existingIndex >= 0) {
|
|
231
|
-
const next = [...current];
|
|
232
|
-
next[existingIndex] = newSort;
|
|
233
|
-
setSorting(next);
|
|
234
|
-
} else setSorting([...current, newSort]);
|
|
235
|
-
} else setSorting([newSort]);
|
|
236
|
-
},
|
|
237
|
-
togglePinned: (colId, state) => {
|
|
238
|
-
const col = columns().find((c) => c.id === colId);
|
|
239
|
-
if (col) col.setPinned(state ?? false);
|
|
240
|
-
},
|
|
241
|
-
toggleSort: (colId, multi) => {
|
|
242
|
-
const current = sorting();
|
|
243
|
-
const exists = current.findIndex((s) => s.id === colId) !== -1;
|
|
244
|
-
const updatedSort = current.map((s) => {
|
|
245
|
-
if (s.id === colId) return {
|
|
246
|
-
...s,
|
|
247
|
-
desc: !s.desc
|
|
248
|
-
};
|
|
249
|
-
return s;
|
|
250
|
-
});
|
|
251
|
-
if (exists) setSorting(multi ? [...current, ...updatedSort] : [...updatedSort]);
|
|
252
|
-
else {
|
|
253
|
-
const newSort = {
|
|
254
|
-
id: colId,
|
|
255
|
-
desc: true
|
|
256
|
-
};
|
|
257
|
-
setSorting(multi ? [...current, newSort] : [newSort]);
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
setPage: (details) => {
|
|
261
|
-
setPageIndex(details.page);
|
|
262
|
-
options.onPageChange?.(details);
|
|
263
|
-
},
|
|
264
|
-
setPageSize: (size) => {
|
|
265
|
-
if (isServerPaginated()) setPageIndex(1);
|
|
266
|
-
setPageSize(size);
|
|
267
|
-
},
|
|
268
|
-
setGlobalFilter: (val) => {
|
|
269
|
-
(0, _cerberus_design_signals.batch)(() => {
|
|
270
|
-
setGlobalFilter((prev) => ({
|
|
271
|
-
...prev,
|
|
272
|
-
...val
|
|
273
|
-
}));
|
|
274
|
-
setPageIndex(1);
|
|
275
|
-
});
|
|
276
|
-
},
|
|
277
|
-
setColFilter: (val) => {
|
|
278
|
-
setColFilters(val);
|
|
279
|
-
},
|
|
280
|
-
setShowColFilter: (val) => {
|
|
281
|
-
setShowColFilter(val);
|
|
282
|
-
},
|
|
283
|
-
setContainerWidth: (w) => {
|
|
284
|
-
setContainerWidth(w);
|
|
285
|
-
},
|
|
286
|
-
resizeColumn: (colId, delta) => {
|
|
287
|
-
const col = columns().find((c) => c.id === colId);
|
|
288
|
-
if (col) {
|
|
289
|
-
if (col.isFlex()) {
|
|
290
|
-
const fixedSpace = columns().filter((c) => !c.isFlex()).reduce((a, b) => a + b.width(), 0);
|
|
291
|
-
const flexCount = columns().filter((c) => c.isFlex()).length;
|
|
292
|
-
const currentFlexWidth = Math.max(col.original.minWidth ?? 150, (containerWidth() - fixedSpace) / flexCount);
|
|
293
|
-
col.setColWidth(currentFlexWidth);
|
|
294
|
-
col.setFlex(false);
|
|
295
|
-
}
|
|
296
|
-
col.setColWidth(Math.max(col.original.minWidth ?? 50, col.width() + delta));
|
|
297
|
-
}
|
|
298
|
-
}
|
|
50
|
+
visibleRows
|
|
299
51
|
};
|
|
300
52
|
}
|
|
301
53
|
//#endregion
|