@cerberus-design/data-grid 0.25.3 → 1.0.0-rc.5
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/column-helpers.cjs +55 -21
- package/dist/column-helpers.js +55 -17
- package/dist/components/cerby-data-grid.client.cjs +12 -11
- package/dist/components/cerby-data-grid.client.js +12 -7
- package/dist/components/count-menu.client.cjs +46 -49
- package/dist/components/count-menu.client.js +46 -45
- package/dist/components/data-grid.client.cjs +89 -82
- package/dist/components/data-grid.client.js +89 -78
- package/dist/components/features.client.cjs +72 -76
- package/dist/components/features.client.js +72 -72
- package/dist/components/grid.client.cjs +280 -309
- package/dist/components/grid.client.js +281 -303
- package/dist/components/pagination.client.cjs +90 -113
- package/dist/components/pagination.client.js +90 -109
- package/dist/components/pinned-items.client.cjs +60 -59
- package/dist/components/pinned-items.client.js +60 -55
- package/dist/components/sort-items.client.cjs +44 -49
- package/dist/components/sort-items.client.js +44 -45
- package/dist/const.cjs +32 -43
- package/dist/const.js +33 -31
- package/dist/context.client.cjs +12 -12
- package/dist/context.client.js +12 -8
- package/dist/hooks.client.cjs +13 -20
- package/dist/hooks.client.js +13 -16
- package/dist/index.cjs +9 -15
- package/dist/index.js +5 -4
- package/dist/store.cjs +241 -284
- package/dist/store.js +241 -280
- package/dist/utils.cjs +23 -45
- package/dist/utils.js +23 -41
- package/dist/virtualizer.client.cjs +63 -53
- package/dist/virtualizer.client.js +63 -49
- package/package.json +29 -26
|
@@ -1,81 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
import { PARTS, SCOPE } from "../const.js";
|
|
4
|
+
import { DataGridProvider } from "../context.client.js";
|
|
5
|
+
import { createGridStore } from "../store.js";
|
|
6
|
+
import { GridViewport } from "./grid.client.js";
|
|
7
|
+
import { GridPagination } from "./pagination.client.js";
|
|
8
|
+
import { Show } from "@cerberus-design/react";
|
|
9
|
+
import { createEffect, useSignal } from "@cerberus-design/signals";
|
|
10
|
+
import { memo, useEffect, useMemo, useRef } from "react";
|
|
11
|
+
import { HStack, Stack } from "styled-system/jsx";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
//#region src/components/data-grid.client.tsx
|
|
13
14
|
function DataGridEl(props) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
15
|
+
const { data } = props;
|
|
16
|
+
const store = useMemo(() => createGridStore({
|
|
17
|
+
data,
|
|
18
|
+
columns: props.columns,
|
|
19
|
+
initialState: props.initialState,
|
|
20
|
+
rowSize: props.rowSize,
|
|
21
|
+
onPageChange: props.onPageChange
|
|
22
|
+
}), []);
|
|
23
|
+
const [ready, setReady] = useSignal(false);
|
|
24
|
+
const rootRef = useRef(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
store.updateData(data);
|
|
27
|
+
}, [data, store]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const el = rootRef.current;
|
|
30
|
+
if (!el) return;
|
|
31
|
+
const observer = new ResizeObserver((entries) => {
|
|
32
|
+
for (const entry of entries) store.setContainerWidth(entry.contentRect.width);
|
|
33
|
+
});
|
|
34
|
+
observer.observe(el);
|
|
35
|
+
const cleanupSignalEffect = createEffect(() => {
|
|
36
|
+
Object.entries(store.rootCssVars()).forEach(([key, val]) => {
|
|
37
|
+
el.style.setProperty(key, val);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
setReady(true);
|
|
41
|
+
return () => {
|
|
42
|
+
observer.disconnect();
|
|
43
|
+
cleanupSignalEffect();
|
|
44
|
+
};
|
|
45
|
+
}, [store, setReady]);
|
|
46
|
+
return /* @__PURE__ */ jsxs(DataGridProvider, {
|
|
47
|
+
createStore: () => store,
|
|
48
|
+
children: [/* @__PURE__ */ jsx(Show, {
|
|
49
|
+
when: props.toolbar,
|
|
50
|
+
children: () => /* @__PURE__ */ jsx(HStack, {
|
|
51
|
+
"data-scope": SCOPE,
|
|
52
|
+
"data-part": PARTS.TOOLBAR,
|
|
53
|
+
w: "full",
|
|
54
|
+
children: props.toolbar
|
|
55
|
+
})
|
|
56
|
+
}), /* @__PURE__ */ jsxs(Stack, {
|
|
57
|
+
"data-scope": SCOPE,
|
|
58
|
+
"data-part": PARTS.ROOT,
|
|
59
|
+
dir: "columns",
|
|
60
|
+
maxH: "inherit",
|
|
61
|
+
minH: "inherit",
|
|
62
|
+
gap: "0",
|
|
63
|
+
h: "full",
|
|
64
|
+
bgColor: "page.surface.100/55",
|
|
65
|
+
border: "1px solid",
|
|
66
|
+
borderColor: "page.border.initial",
|
|
67
|
+
rounded: "lg",
|
|
68
|
+
overflow: "hidden",
|
|
69
|
+
w: "full",
|
|
70
|
+
ref: rootRef,
|
|
71
|
+
children: [
|
|
72
|
+
/* @__PURE__ */ jsx(Show, {
|
|
73
|
+
when: ready,
|
|
74
|
+
children: () => /* @__PURE__ */ jsx(GridViewport, {})
|
|
75
|
+
}),
|
|
76
|
+
/* @__PURE__ */ jsx(Show, {
|
|
77
|
+
when: props.footer,
|
|
78
|
+
children: () => /* @__PURE__ */ jsx(HStack, {
|
|
79
|
+
"data-scope": SCOPE,
|
|
80
|
+
"data-part": PARTS.FOOTER,
|
|
81
|
+
w: "full",
|
|
82
|
+
children: props.footer
|
|
83
|
+
})
|
|
84
|
+
}),
|
|
85
|
+
/* @__PURE__ */ jsx(GridPagination, {})
|
|
86
|
+
]
|
|
87
|
+
})]
|
|
88
|
+
});
|
|
78
89
|
}
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
var DataGrid = memo(DataGridEl);
|
|
91
|
+
//#endregion
|
|
81
92
|
export { DataGrid };
|
|
@@ -1,79 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const pinnedItems_client = require('./pinned-items.client.cjs');
|
|
12
|
-
const sortItems_client = require('./sort-items.client.cjs');
|
|
13
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
const require_context_client = require("../context.client.cjs");
|
|
4
|
+
const require_pinned_items_client = require("./pinned-items.client.cjs");
|
|
5
|
+
const require_sort_items_client = require("./sort-items.client.cjs");
|
|
6
|
+
let _cerberus_design_react = require("@cerberus-design/react");
|
|
7
|
+
let _cerberus_design_signals = require("@cerberus-design/signals");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
//#region src/components/features.client.tsx
|
|
14
11
|
function HeaderCellOptions(props) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
] });
|
|
12
|
+
const store = require_context_client.useDataGridContext();
|
|
13
|
+
const sorting = (0, _cerberus_design_signals.useRead)(store.sorting);
|
|
14
|
+
const { icons } = (0, _cerberus_design_react.useCerberusContext)();
|
|
15
|
+
const MoreOptionsIcon = icons.moreVertical;
|
|
16
|
+
const sortedVal = (0, react.useMemo)(() => {
|
|
17
|
+
const idx = sorting.findIndex((data) => data.id === props.id);
|
|
18
|
+
if (idx === -1) return void 0;
|
|
19
|
+
return sorting[idx];
|
|
20
|
+
}, [sorting, props.id]);
|
|
21
|
+
function handleSelect(details) {
|
|
22
|
+
const val = details.value;
|
|
23
|
+
const specialVal = val.split("_");
|
|
24
|
+
const category = specialVal[0];
|
|
25
|
+
const action = specialVal[1];
|
|
26
|
+
if (val === "filter") return console.log("Show Filter popover...");
|
|
27
|
+
if (val === "unsort") return store.setSort(props.id, null);
|
|
28
|
+
switch (category) {
|
|
29
|
+
case "pin": return store.togglePinned(props.id, action);
|
|
30
|
+
case "unpin": return store.togglePinned(props.id, false);
|
|
31
|
+
case "sort": return store.setSort(props.id, action ?? null);
|
|
32
|
+
default: console.error("Unhandled action:", {
|
|
33
|
+
details,
|
|
34
|
+
action
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!props.sortable && !props.pinnable && !props.filterable) return null;
|
|
39
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_cerberus_design_react.Menu, {
|
|
40
|
+
onSelect: handleSelect,
|
|
41
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.MenuTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.IconButton, {
|
|
42
|
+
ariaLabel: "View more options",
|
|
43
|
+
size: "sm",
|
|
44
|
+
opacity: {
|
|
45
|
+
base: 1,
|
|
46
|
+
md: 0
|
|
47
|
+
},
|
|
48
|
+
transitionProperty: "opacity",
|
|
49
|
+
transitionDuration: "fast",
|
|
50
|
+
_groupHover: { opacity: 1 },
|
|
51
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MoreOptionsIcon, {})
|
|
52
|
+
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_cerberus_design_react.MenuContent, { children: [
|
|
53
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.Show, {
|
|
54
|
+
when: props.sortable,
|
|
55
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_sort_items_client.MatchSortItems, { sorting: sortedVal })
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_cerberus_design_react.Show, {
|
|
58
|
+
when: props.pinnable,
|
|
59
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.Show, {
|
|
60
|
+
when: props.sortable,
|
|
61
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.MenuSeparator, {})
|
|
62
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_pinned_items_client.MatchPinnedItems, { pinned: props.pinned })]
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_cerberus_design_react.Show, {
|
|
65
|
+
when: props.filterable,
|
|
66
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.MenuSeparator, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_cerberus_design_react.MenuItem, {
|
|
67
|
+
value: "filter",
|
|
68
|
+
children: "Filter"
|
|
69
|
+
})]
|
|
70
|
+
})
|
|
71
|
+
] })]
|
|
72
|
+
});
|
|
77
73
|
}
|
|
78
|
-
|
|
74
|
+
//#endregion
|
|
79
75
|
exports.HeaderCellOptions = HeaderCellOptions;
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
import { useDataGridContext } from "../context.client.js";
|
|
4
|
+
import { MatchPinnedItems } from "./pinned-items.client.js";
|
|
5
|
+
import { MatchSortItems } from "./sort-items.client.js";
|
|
6
|
+
import { IconButton, Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Show, useCerberusContext } from "@cerberus-design/react";
|
|
7
|
+
import { useRead } from "@cerberus-design/signals";
|
|
8
|
+
import { useMemo } from "react";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
//#region src/components/features.client.tsx
|
|
10
11
|
function HeaderCellOptions(props) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
] });
|
|
12
|
+
const store = useDataGridContext();
|
|
13
|
+
const sorting = useRead(store.sorting);
|
|
14
|
+
const { icons } = useCerberusContext();
|
|
15
|
+
const MoreOptionsIcon = icons.moreVertical;
|
|
16
|
+
const sortedVal = useMemo(() => {
|
|
17
|
+
const idx = sorting.findIndex((data) => data.id === props.id);
|
|
18
|
+
if (idx === -1) return void 0;
|
|
19
|
+
return sorting[idx];
|
|
20
|
+
}, [sorting, props.id]);
|
|
21
|
+
function handleSelect(details) {
|
|
22
|
+
const val = details.value;
|
|
23
|
+
const specialVal = val.split("_");
|
|
24
|
+
const category = specialVal[0];
|
|
25
|
+
const action = specialVal[1];
|
|
26
|
+
if (val === "filter") return console.log("Show Filter popover...");
|
|
27
|
+
if (val === "unsort") return store.setSort(props.id, null);
|
|
28
|
+
switch (category) {
|
|
29
|
+
case "pin": return store.togglePinned(props.id, action);
|
|
30
|
+
case "unpin": return store.togglePinned(props.id, false);
|
|
31
|
+
case "sort": return store.setSort(props.id, action ?? null);
|
|
32
|
+
default: console.error("Unhandled action:", {
|
|
33
|
+
details,
|
|
34
|
+
action
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!props.sortable && !props.pinnable && !props.filterable) return null;
|
|
39
|
+
return /* @__PURE__ */ jsxs(Menu, {
|
|
40
|
+
onSelect: handleSelect,
|
|
41
|
+
children: [/* @__PURE__ */ jsx(MenuTrigger, { children: /* @__PURE__ */ jsx(IconButton, {
|
|
42
|
+
ariaLabel: "View more options",
|
|
43
|
+
size: "sm",
|
|
44
|
+
opacity: {
|
|
45
|
+
base: 1,
|
|
46
|
+
md: 0
|
|
47
|
+
},
|
|
48
|
+
transitionProperty: "opacity",
|
|
49
|
+
transitionDuration: "fast",
|
|
50
|
+
_groupHover: { opacity: 1 },
|
|
51
|
+
children: /* @__PURE__ */ jsx(MoreOptionsIcon, {})
|
|
52
|
+
}) }), /* @__PURE__ */ jsxs(MenuContent, { children: [
|
|
53
|
+
/* @__PURE__ */ jsx(Show, {
|
|
54
|
+
when: props.sortable,
|
|
55
|
+
children: /* @__PURE__ */ jsx(MatchSortItems, { sorting: sortedVal })
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ jsxs(Show, {
|
|
58
|
+
when: props.pinnable,
|
|
59
|
+
children: [/* @__PURE__ */ jsx(Show, {
|
|
60
|
+
when: props.sortable,
|
|
61
|
+
children: /* @__PURE__ */ jsx(MenuSeparator, {})
|
|
62
|
+
}), /* @__PURE__ */ jsx(MatchPinnedItems, { pinned: props.pinned })]
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ jsxs(Show, {
|
|
65
|
+
when: props.filterable,
|
|
66
|
+
children: [/* @__PURE__ */ jsx(MenuSeparator, {}), /* @__PURE__ */ jsx(MenuItem, {
|
|
67
|
+
value: "filter",
|
|
68
|
+
children: "Filter"
|
|
69
|
+
})]
|
|
70
|
+
})
|
|
71
|
+
] })]
|
|
72
|
+
});
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
//#endregion
|
|
75
75
|
export { HeaderCellOptions };
|