@cerberus-design/data-grid 0.25.3 → 1.0.0-rc.6

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