@alaarab/ogrid-core 1.3.2 → 1.5.0

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 (45) hide show
  1. package/dist/esm/components/OGridLayout.js +74 -7
  2. package/dist/esm/components/SideBar.js +98 -0
  3. package/dist/esm/hooks/index.js +2 -0
  4. package/dist/esm/hooks/useActiveCell.js +5 -0
  5. package/dist/esm/hooks/useCellSelection.js +84 -0
  6. package/dist/esm/hooks/useColumnHeaderFilterState.js +25 -3
  7. package/dist/esm/hooks/useColumnResize.js +47 -32
  8. package/dist/esm/hooks/useDataGridState.js +50 -5
  9. package/dist/esm/hooks/useKeyboardNavigation.js +56 -4
  10. package/dist/esm/hooks/useOGrid.js +160 -4
  11. package/dist/esm/hooks/useRichSelectState.js +53 -0
  12. package/dist/esm/hooks/useSideBarState.js +34 -0
  13. package/dist/esm/index.js +3 -2
  14. package/dist/esm/types/dataGridTypes.js +9 -2
  15. package/dist/esm/utils/aggregationUtils.js +41 -0
  16. package/dist/esm/utils/columnUtils.js +97 -0
  17. package/dist/esm/utils/dataGridViewModel.js +105 -6
  18. package/dist/esm/utils/index.js +3 -2
  19. package/dist/esm/utils/ogridHelpers.js +4 -2
  20. package/dist/esm/utils/paginationHelpers.js +1 -1
  21. package/dist/esm/utils/statusBarHelpers.js +11 -2
  22. package/dist/esm/utils/valueParsers.js +15 -1
  23. package/dist/types/components/OGridLayout.d.ts +22 -5
  24. package/dist/types/components/SideBar.d.ts +34 -0
  25. package/dist/types/components/StatusBar.d.ts +9 -0
  26. package/dist/types/hooks/index.d.ts +5 -1
  27. package/dist/types/hooks/useColumnHeaderFilterState.d.ts +9 -1
  28. package/dist/types/hooks/useColumnResize.d.ts +3 -1
  29. package/dist/types/hooks/useDataGridState.d.ts +3 -0
  30. package/dist/types/hooks/useInlineCellEditorState.d.ts +1 -1
  31. package/dist/types/hooks/useOGrid.d.ts +7 -0
  32. package/dist/types/hooks/useRichSelectState.d.ts +17 -0
  33. package/dist/types/hooks/useSideBarState.d.ts +15 -0
  34. package/dist/types/index.d.ts +7 -5
  35. package/dist/types/types/columnTypes.d.ts +26 -2
  36. package/dist/types/types/dataGridTypes.d.ts +68 -6
  37. package/dist/types/types/index.d.ts +2 -2
  38. package/dist/types/utils/aggregationUtils.d.ts +15 -0
  39. package/dist/types/utils/columnUtils.d.ts +16 -1
  40. package/dist/types/utils/dataGridViewModel.d.ts +67 -2
  41. package/dist/types/utils/index.d.ts +5 -3
  42. package/dist/types/utils/ogridHelpers.d.ts +2 -2
  43. package/dist/types/utils/paginationHelpers.d.ts +1 -1
  44. package/dist/types/utils/statusBarHelpers.d.ts +10 -0
  45. package/package.json +1 -1
@@ -1,16 +1,83 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- const defaultGap = 16;
2
+ import { SideBar } from './SideBar';
3
+ // Stable style objects (avoid re-creating on every render)
4
+ const borderedContainerStyle = {
5
+ border: '1px solid var(--ogrid-border, #e0e0e0)',
6
+ borderRadius: 6,
7
+ overflow: 'hidden',
8
+ display: 'flex',
9
+ flexDirection: 'column',
10
+ flex: 1,
11
+ minHeight: 0,
12
+ background: 'var(--ogrid-bg, #fff)',
13
+ };
14
+ const toolbarStripStyle = {
15
+ display: 'flex',
16
+ justifyContent: 'space-between',
17
+ alignItems: 'center',
18
+ padding: '6px 12px',
19
+ borderBottom: '1px solid var(--ogrid-border, #e0e0e0)',
20
+ background: 'var(--ogrid-header-bg, #f5f5f5)',
21
+ gap: 8,
22
+ flexWrap: 'wrap',
23
+ minHeight: 0,
24
+ };
25
+ const toolbarSectionStyle = {
26
+ display: 'flex',
27
+ alignItems: 'center',
28
+ gap: 8,
29
+ };
30
+ const footerStripStyle = {
31
+ borderTop: '1px solid var(--ogrid-border, #e0e0e0)',
32
+ background: 'var(--ogrid-header-bg, #f5f5f5)',
33
+ padding: '6px 12px',
34
+ };
35
+ const gridAreaFlexStyle = {
36
+ width: '100%',
37
+ minWidth: 0,
38
+ minHeight: 0,
39
+ flex: 1,
40
+ display: 'flex',
41
+ };
42
+ const gridAreaSoloStyle = {
43
+ width: '100%',
44
+ minWidth: 0,
45
+ minHeight: 0,
46
+ flex: 1,
47
+ display: 'flex',
48
+ flexDirection: 'column',
49
+ };
50
+ const gridChildStyle = {
51
+ flex: 1,
52
+ minWidth: 0,
53
+ minHeight: 0,
54
+ display: 'flex',
55
+ flexDirection: 'column',
56
+ };
3
57
  /**
4
- * Renders OGrid layout: [toolbar row | title, toolbar, columnChooser] [grid] [pagination].
5
- * Inner structure uses divs; only the root uses Container so UIs can use Box/div and pass gap.
58
+ * Renders OGrid layout as a unified bordered container:
59
+ * [deprecated title above]
60
+ * ┌────────────────────────────────────┐
61
+ * │ [toolbar strip] │
62
+ * ├────────────────────────────────────┤
63
+ * │ [sidebar]? [grid] │
64
+ * ├────────────────────────────────────┤
65
+ * │ [footer strip / pagination] │
66
+ * └────────────────────────────────────┘
6
67
  */
7
68
  export function OGridLayout(props) {
8
- const { containerComponent: Container = 'div', containerProps = {}, gap = defaultGap, className, title, toolbar, columnChooser, children, pagination, } = props;
9
- // Always apply flex layout; merge with any containerProps styles
69
+ const { containerComponent: Container = 'div', containerProps = {}, gap = 8, className, title, toolbar, columnChooser, toolbarEnd: toolbarEndProp, children, pagination, sideBar, } = props;
70
+ const hasSideBar = sideBar != null;
71
+ const sideBarPosition = sideBar?.position ?? 'right';
72
+ // Backward compat: columnChooser prop → toolbarEnd
73
+ const toolbarEnd = toolbarEndProp ?? columnChooser;
74
+ const hasToolbar = toolbar != null || toolbarEnd != null;
75
+ // Root styles: flex column, fill parent height, gap for deprecated title spacing
10
76
  const rootStyle = {
11
77
  display: 'flex',
12
78
  flexDirection: 'column',
13
- gap: typeof gap === 'number' ? `${gap}px` : gap,
79
+ height: '100%',
80
+ gap: title != null ? (typeof gap === 'number' ? `${gap}px` : gap) : undefined,
14
81
  };
15
- return (_jsxs(Container, { className: className, style: rootStyle, ...containerProps, children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 8, minHeight: 40 }, children: [title != null ? _jsx("div", { style: { margin: 0 }, children: title }) : null, toolbar, columnChooser] }), _jsx("div", { style: { width: '100%', minWidth: 0, flex: 1 }, children: children }), pagination] }));
82
+ return (_jsxs(Container, { className: className, style: rootStyle, ...containerProps, children: [title != null && _jsx("div", { style: { margin: 0 }, children: title }), _jsxs("div", { style: borderedContainerStyle, children: [hasToolbar && (_jsxs("div", { style: toolbarStripStyle, children: [_jsx("div", { style: toolbarSectionStyle, children: toolbar }), _jsx("div", { style: toolbarSectionStyle, children: toolbarEnd })] })), hasSideBar ? (_jsxs("div", { style: gridAreaFlexStyle, children: [sideBarPosition === 'left' && _jsx(SideBar, { ...sideBar }), _jsx("div", { style: gridChildStyle, children: children }), sideBarPosition !== 'left' && _jsx(SideBar, { ...sideBar })] })) : (_jsx("div", { style: gridAreaSoloStyle, children: children })), pagination && (_jsx("div", { style: footerStripStyle, children: pagination }))] })] }));
16
83
  }
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ const PANEL_WIDTH = 240;
3
+ const TAB_WIDTH = 36;
4
+ const PANEL_LABELS = {
5
+ columns: 'Columns',
6
+ filters: 'Filters',
7
+ };
8
+ export function SideBar(props) {
9
+ const { activePanel, onPanelChange, panels, position, columns, visibleColumns, onVisibilityChange, onSetVisibleColumns, filterableColumns, multiSelectFilters, textFilters, onMultiSelectFilterChange, onTextFilterChange, dateFilters, onDateFilterChange, filterOptions, } = props;
10
+ const isOpen = activePanel !== null;
11
+ const handleTabClick = (panel) => {
12
+ onPanelChange(activePanel === panel ? null : panel);
13
+ };
14
+ const tabStrip = (_jsx("div", { style: {
15
+ display: 'flex',
16
+ flexDirection: 'column',
17
+ width: TAB_WIDTH,
18
+ borderLeft: position === 'right' ? '1px solid var(--ogrid-border, #e0e0e0)' : undefined,
19
+ borderRight: position === 'left' ? '1px solid var(--ogrid-border, #e0e0e0)' : undefined,
20
+ background: 'var(--ogrid-header-bg, #f5f5f5)',
21
+ }, role: "tablist", "aria-label": "Side bar tabs", children: panels.map((panel) => (_jsx("button", { role: "tab", "aria-selected": activePanel === panel, "aria-label": PANEL_LABELS[panel], onClick: () => handleTabClick(panel), title: PANEL_LABELS[panel], style: {
22
+ width: TAB_WIDTH,
23
+ height: TAB_WIDTH,
24
+ border: 'none',
25
+ cursor: 'pointer',
26
+ background: activePanel === panel ? 'var(--ogrid-bg, #fff)' : 'transparent',
27
+ color: 'var(--ogrid-fg, #242424)',
28
+ fontWeight: activePanel === panel ? 'bold' : 'normal',
29
+ fontSize: 14,
30
+ display: 'flex',
31
+ alignItems: 'center',
32
+ justifyContent: 'center',
33
+ }, children: panel === 'columns' ? '\u2261' : '\u2A65' }, panel))) }));
34
+ const panelContent = isOpen ? (_jsxs("div", { role: "tabpanel", "aria-label": PANEL_LABELS[activePanel], style: {
35
+ width: PANEL_WIDTH,
36
+ display: 'flex',
37
+ flexDirection: 'column',
38
+ borderLeft: position === 'right' ? '1px solid var(--ogrid-border, #e0e0e0)' : undefined,
39
+ borderRight: position === 'left' ? '1px solid var(--ogrid-border, #e0e0e0)' : undefined,
40
+ overflow: 'hidden',
41
+ background: 'var(--ogrid-bg, #fff)',
42
+ color: 'var(--ogrid-fg, #242424)',
43
+ }, children: [_jsxs("div", { style: {
44
+ display: 'flex',
45
+ justifyContent: 'space-between',
46
+ alignItems: 'center',
47
+ padding: '8px 12px',
48
+ borderBottom: '1px solid var(--ogrid-border, #e0e0e0)',
49
+ fontWeight: 600,
50
+ }, children: [_jsx("span", { children: PANEL_LABELS[activePanel] }), _jsx("button", { onClick: () => onPanelChange(null), style: { border: 'none', background: 'transparent', cursor: 'pointer', fontSize: 16, color: 'var(--ogrid-fg, #242424)' }, "aria-label": "Close panel", children: "\u00D7" })] }), _jsxs("div", { style: { flex: 1, overflowY: 'auto', padding: '8px 12px' }, children: [activePanel === 'columns' && (_jsx(ColumnsPanel, { columns: columns, visibleColumns: visibleColumns, onVisibilityChange: onVisibilityChange, onSetVisibleColumns: onSetVisibleColumns })), activePanel === 'filters' && (_jsx(FiltersPanel, { filterableColumns: filterableColumns, multiSelectFilters: multiSelectFilters, textFilters: textFilters, onMultiSelectFilterChange: onMultiSelectFilterChange, onTextFilterChange: onTextFilterChange, dateFilters: dateFilters, onDateFilterChange: onDateFilterChange, filterOptions: filterOptions }))] })] })) : null;
51
+ return (_jsxs("div", { style: { display: 'flex', flexDirection: 'row', flexShrink: 0 }, role: "complementary", "aria-label": "Side bar", children: [position === 'left' && tabStrip, position === 'left' && panelContent, position === 'right' && panelContent, position === 'right' && tabStrip] }));
52
+ }
53
+ // --- Internal sub-components ---
54
+ function ColumnsPanel(props) {
55
+ const { columns, visibleColumns, onVisibilityChange, onSetVisibleColumns } = props;
56
+ const allVisible = columns.every((c) => visibleColumns.has(c.columnId));
57
+ const handleSelectAll = () => {
58
+ const next = new Set(visibleColumns);
59
+ columns.forEach((c) => next.add(c.columnId));
60
+ onSetVisibleColumns(next);
61
+ };
62
+ const handleClearAll = () => {
63
+ const next = new Set();
64
+ columns.forEach((c) => {
65
+ if (c.required && visibleColumns.has(c.columnId))
66
+ next.add(c.columnId);
67
+ });
68
+ onSetVisibleColumns(next);
69
+ };
70
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { style: { display: 'flex', gap: 8, marginBottom: 8 }, children: [_jsx("button", { onClick: handleSelectAll, disabled: allVisible, style: { flex: 1, cursor: 'pointer', background: 'var(--ogrid-bg-subtle, #f3f2f1)', color: 'var(--ogrid-fg, #242424)', border: '1px solid var(--ogrid-border, #e0e0e0)', borderRadius: 4, padding: '4px 8px' }, children: "Select All" }), _jsx("button", { onClick: handleClearAll, style: { flex: 1, cursor: 'pointer', background: 'var(--ogrid-bg-subtle, #f3f2f1)', color: 'var(--ogrid-fg, #242424)', border: '1px solid var(--ogrid-border, #e0e0e0)', borderRadius: 4, padding: '4px 8px' }, children: "Clear All" })] }), columns.map((col) => (_jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: 6, padding: '2px 0', cursor: 'pointer' }, children: [_jsx("input", { type: "checkbox", checked: visibleColumns.has(col.columnId), onChange: (e) => onVisibilityChange(col.columnId, e.target.checked), disabled: col.required }), _jsx("span", { children: col.name })] }, col.columnId)))] }));
71
+ }
72
+ function FiltersPanel(props) {
73
+ const { filterableColumns, multiSelectFilters, textFilters, onMultiSelectFilterChange, onTextFilterChange, dateFilters, onDateFilterChange, filterOptions } = props;
74
+ if (filterableColumns.length === 0) {
75
+ return _jsx("div", { style: { color: 'var(--ogrid-muted, #999)', fontStyle: 'italic' }, children: "No filterable columns" });
76
+ }
77
+ return (_jsx(_Fragment, { children: filterableColumns.map((col) => {
78
+ const filterKey = col.filterField;
79
+ return (_jsxs("div", { style: { marginBottom: 12 }, children: [_jsx("div", { style: { fontWeight: 500, marginBottom: 4, fontSize: 13 }, children: col.name }), col.filterType === 'text' && (_jsx("input", { type: "text", value: textFilters[filterKey] ?? '', onChange: (e) => onTextFilterChange(filterKey, e.target.value), placeholder: `Filter ${col.name}...`, "aria-label": `Filter ${col.name}`, style: { width: '100%', boxSizing: 'border-box', padding: '4px 6px', background: 'var(--ogrid-bg, #fff)', color: 'var(--ogrid-fg, #242424)', border: '1px solid var(--ogrid-border, #e0e0e0)', borderRadius: 4 } })), col.filterType === 'date' && (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 4 }, children: [_jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: 4, fontSize: 12 }, children: ["From:", _jsx("input", { type: "date", value: dateFilters[filterKey]?.from ?? '', onChange: (e) => {
80
+ const from = e.target.value || undefined;
81
+ const to = dateFilters[filterKey]?.to;
82
+ onDateFilterChange(filterKey, from || to ? { from, to } : undefined);
83
+ }, "aria-label": `${col.name} from date`, style: { flex: 1, padding: '2px 4px', background: 'var(--ogrid-bg, #fff)', color: 'var(--ogrid-fg, #242424)', border: '1px solid var(--ogrid-border, #e0e0e0)', borderRadius: 4 } })] }), _jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: 4, fontSize: 12 }, children: ["To:", _jsx("input", { type: "date", value: dateFilters[filterKey]?.to ?? '', onChange: (e) => {
84
+ const to = e.target.value || undefined;
85
+ const from = dateFilters[filterKey]?.from;
86
+ onDateFilterChange(filterKey, from || to ? { from, to } : undefined);
87
+ }, "aria-label": `${col.name} to date`, style: { flex: 1, padding: '2px 4px', background: 'var(--ogrid-bg, #fff)', color: 'var(--ogrid-fg, #242424)', border: '1px solid var(--ogrid-border, #e0e0e0)', borderRadius: 4 } })] })] })), col.filterType === 'multiSelect' && (_jsx("div", { style: { maxHeight: 120, overflowY: 'auto' }, role: "group", "aria-label": `${col.name} options`, children: (filterOptions[filterKey] ?? []).map((opt) => {
88
+ const selected = (multiSelectFilters[filterKey] ?? []).includes(opt);
89
+ return (_jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: 4, padding: '1px 0', cursor: 'pointer', fontSize: 13 }, children: [_jsx("input", { type: "checkbox", checked: selected, onChange: (e) => {
90
+ const current = multiSelectFilters[filterKey] ?? [];
91
+ const next = e.target.checked
92
+ ? [...current, opt]
93
+ : current.filter((v) => v !== opt);
94
+ onMultiSelectFilterChange(filterKey, next);
95
+ } }), _jsx("span", { children: opt })] }, opt));
96
+ }) }))] }, col.columnId));
97
+ }) }));
98
+ }
@@ -15,3 +15,5 @@ export { useColumnHeaderFilterState } from './useColumnHeaderFilterState';
15
15
  export { useColumnChooserState } from './useColumnChooserState';
16
16
  export { useInlineCellEditorState } from './useInlineCellEditorState';
17
17
  export { useColumnResize } from './useColumnResize';
18
+ export { useRichSelectState } from './useRichSelectState';
19
+ export { useSideBarState } from './useSideBarState';
@@ -17,6 +17,11 @@ export function useActiveCell(wrapperRef, editingCell) {
17
17
  const cell = wrapperRef.current.querySelector(selector);
18
18
  if (cell) {
19
19
  if (typeof cell.scrollIntoView === 'function') {
20
+ // Account for sticky <thead> so scrollIntoView doesn't leave
21
+ // the cell hidden behind the header.
22
+ const thead = wrapperRef.current.querySelector('thead');
23
+ const headerHeight = thead ? thead.getBoundingClientRect().height : 0;
24
+ cell.style.scrollMarginTop = `${headerHeight}px`;
20
25
  cell.scrollIntoView({ block: 'nearest', inline: 'nearest' });
21
26
  }
22
27
  if (document.activeElement !== cell && typeof cell.focus === 'function') {
@@ -2,6 +2,16 @@ import { useState, useCallback, useRef, useEffect } from 'react';
2
2
  import { normalizeSelectionRange } from '../types';
3
3
  /** DOM attribute name used for drag-range highlighting (bypasses React). */
4
4
  const DRAG_ATTR = 'data-drag-range';
5
+ /** Auto-scroll config */
6
+ const AUTO_SCROLL_EDGE = 40; // px from wrapper edge to trigger
7
+ const AUTO_SCROLL_MIN_SPEED = 2;
8
+ const AUTO_SCROLL_MAX_SPEED = 20;
9
+ const AUTO_SCROLL_INTERVAL = 16; // ~60fps
10
+ /** Compute scroll speed proportional to distance past the edge, capped. */
11
+ function autoScrollSpeed(distance) {
12
+ const t = Math.min(distance / AUTO_SCROLL_EDGE, 1);
13
+ return AUTO_SCROLL_MIN_SPEED + t * (AUTO_SCROLL_MAX_SPEED - AUTO_SCROLL_MIN_SPEED);
14
+ }
5
15
  export function useCellSelection(params) {
6
16
  const { colOffset, rowCount, visibleColCount, setActiveCell, wrapperRef } = params;
7
17
  const [selectionRange, setSelectionRange] = useState(null);
@@ -11,6 +21,8 @@ export function useCellSelection(params) {
11
21
  const rafRef = useRef(0);
12
22
  /** Live drag range kept in a ref — only committed to React state on mouseup. */
13
23
  const liveDragRangeRef = useRef(null);
24
+ /** Auto-scroll interval during drag. */
25
+ const autoScrollRef = useRef(null);
14
26
  const handleCellMouseDown = useCallback((e, rowIndex, globalColIndex) => {
15
27
  // Only handle primary (left) button — let middle-click scroll and right-click context menu work natively
16
28
  if (e.button !== 0)
@@ -116,11 +128,81 @@ export function useCellSelection(params) {
116
128
  endCol: dataCol,
117
129
  });
118
130
  };
131
+ /** Start or update auto-scroll interval based on mouse position relative to wrapper edges. */
132
+ const updateAutoScroll = () => {
133
+ const wrapper = wrapperRef.current;
134
+ const pos = lastMousePosRef.current;
135
+ if (!wrapper || !pos || !isDraggingRef.current) {
136
+ stopAutoScroll();
137
+ return;
138
+ }
139
+ const rect = wrapper.getBoundingClientRect();
140
+ let dx = 0;
141
+ let dy = 0;
142
+ if (pos.cy < rect.top + AUTO_SCROLL_EDGE) {
143
+ dy = -autoScrollSpeed(rect.top + AUTO_SCROLL_EDGE - pos.cy);
144
+ }
145
+ else if (pos.cy > rect.bottom - AUTO_SCROLL_EDGE) {
146
+ dy = autoScrollSpeed(pos.cy - (rect.bottom - AUTO_SCROLL_EDGE));
147
+ }
148
+ if (pos.cx < rect.left + AUTO_SCROLL_EDGE) {
149
+ dx = -autoScrollSpeed(rect.left + AUTO_SCROLL_EDGE - pos.cx);
150
+ }
151
+ else if (pos.cx > rect.right - AUTO_SCROLL_EDGE) {
152
+ dx = autoScrollSpeed(pos.cx - (rect.right - AUTO_SCROLL_EDGE));
153
+ }
154
+ if (dx === 0 && dy === 0) {
155
+ stopAutoScroll();
156
+ return;
157
+ }
158
+ // Start interval if not already running
159
+ if (!autoScrollRef.current) {
160
+ autoScrollRef.current = setInterval(() => {
161
+ const w = wrapperRef.current;
162
+ const p = lastMousePosRef.current;
163
+ if (!w || !p || !isDraggingRef.current) {
164
+ stopAutoScroll();
165
+ return;
166
+ }
167
+ const r = w.getBoundingClientRect();
168
+ let sdx = 0;
169
+ let sdy = 0;
170
+ if (p.cy < r.top + AUTO_SCROLL_EDGE)
171
+ sdy = -autoScrollSpeed(r.top + AUTO_SCROLL_EDGE - p.cy);
172
+ else if (p.cy > r.bottom - AUTO_SCROLL_EDGE)
173
+ sdy = autoScrollSpeed(p.cy - (r.bottom - AUTO_SCROLL_EDGE));
174
+ if (p.cx < r.left + AUTO_SCROLL_EDGE)
175
+ sdx = -autoScrollSpeed(r.left + AUTO_SCROLL_EDGE - p.cx);
176
+ else if (p.cx > r.right - AUTO_SCROLL_EDGE)
177
+ sdx = autoScrollSpeed(p.cx - (r.right - AUTO_SCROLL_EDGE));
178
+ if (sdx === 0 && sdy === 0) {
179
+ stopAutoScroll();
180
+ return;
181
+ }
182
+ w.scrollTop += sdy;
183
+ w.scrollLeft += sdx;
184
+ // After scrolling, re-resolve the cell under the mouse and update drag range
185
+ const newRange = resolveRange(p.cx, p.cy);
186
+ if (newRange) {
187
+ liveDragRangeRef.current = newRange;
188
+ applyDragAttrs(newRange);
189
+ }
190
+ }, AUTO_SCROLL_INTERVAL);
191
+ }
192
+ };
193
+ const stopAutoScroll = () => {
194
+ if (autoScrollRef.current) {
195
+ clearInterval(autoScrollRef.current);
196
+ autoScrollRef.current = null;
197
+ }
198
+ };
119
199
  const onMove = (e) => {
120
200
  if (!isDraggingRef.current || !dragStartRef.current)
121
201
  return;
122
202
  // Always store latest position so mouseUp can flush if RAF hasn't executed
123
203
  lastMousePosRef.current = { cx: e.clientX, cy: e.clientY };
204
+ // Update auto-scroll based on mouse proximity to edges
205
+ updateAutoScroll();
124
206
  // Cancel previous pending frame
125
207
  if (rafRef.current)
126
208
  cancelAnimationFrame(rafRef.current);
@@ -149,6 +231,7 @@ export function useCellSelection(params) {
149
231
  const onUp = () => {
150
232
  if (!isDraggingRef.current)
151
233
  return;
234
+ stopAutoScroll();
152
235
  if (rafRef.current) {
153
236
  cancelAnimationFrame(rafRef.current);
154
237
  rafRef.current = 0;
@@ -185,6 +268,7 @@ export function useCellSelection(params) {
185
268
  window.removeEventListener('mouseup', onUp, true);
186
269
  if (rafRef.current)
187
270
  cancelAnimationFrame(rafRef.current);
271
+ stopAutoScroll();
188
272
  };
189
273
  }, [colOffset, setActiveCell, wrapperRef]);
190
274
  return {
@@ -7,7 +7,7 @@ import { useDebounce } from './useDebounce';
7
7
  const SEARCH_DEBOUNCE_MS = 150;
8
8
  const EMPTY_OPTIONS = [];
9
9
  export function useColumnHeaderFilterState(params) {
10
- const { filterType, onSort, selectedValues, onFilterChange, options, textValue = '', onTextChange, selectedUser, onUserChange, peopleSearch, } = params;
10
+ const { filterType, onSort, selectedValues, onFilterChange, options, textValue = '', onTextChange, selectedUser, onUserChange, peopleSearch, dateValue, onDateChange, } = params;
11
11
  const safeSelectedValues = selectedValues ?? EMPTY_OPTIONS;
12
12
  const safeOptions = options ?? EMPTY_OPTIONS;
13
13
  const headerRef = useRef(null);
@@ -22,12 +22,16 @@ export function useColumnHeaderFilterState(params) {
22
22
  const [peopleSuggestions, setPeopleSuggestions] = useState([]);
23
23
  const [isPeopleLoading, setIsPeopleLoading] = useState(false);
24
24
  const [peopleSearchText, setPeopleSearchText] = useState('');
25
+ const [tempDateFrom, setTempDateFrom] = useState(dateValue?.from ?? '');
26
+ const [tempDateTo, setTempDateTo] = useState(dateValue?.to ?? '');
25
27
  const [popoverPosition, setPopoverPosition] = useState(null);
26
28
  // Sync temp state when popover opens
27
29
  useEffect(() => {
28
30
  if (isFilterOpen) {
29
31
  setTempSelected(new Set(safeSelectedValues));
30
32
  setTempTextValue(textValue);
33
+ setTempDateFrom(dateValue?.from ?? '');
34
+ setTempDateTo(dateValue?.to ?? '');
31
35
  setSearchText('');
32
36
  setPeopleSearchText('');
33
37
  setPeopleSuggestions([]);
@@ -38,7 +42,7 @@ export function useColumnHeaderFilterState(params) {
38
42
  else {
39
43
  setPopoverPosition(null);
40
44
  }
41
- }, [isFilterOpen, filterType, safeSelectedValues, textValue]);
45
+ }, [isFilterOpen, filterType, safeSelectedValues, textValue, dateValue]);
42
46
  // Click outside and Escape to close
43
47
  useEffect(() => {
44
48
  if (!isFilterOpen)
@@ -144,6 +148,16 @@ export function useColumnHeaderFilterState(params) {
144
148
  onUserChange?.(user);
145
149
  setFilterOpen(false);
146
150
  }, [onUserChange]);
151
+ const handleDateApply = useCallback(() => {
152
+ const from = tempDateFrom || undefined;
153
+ const to = tempDateTo || undefined;
154
+ onDateChange?.(from || to ? { from, to } : undefined);
155
+ setFilterOpen(false);
156
+ }, [onDateChange, tempDateFrom, tempDateTo]);
157
+ const handleDateClear = useCallback(() => {
158
+ setTempDateFrom('');
159
+ setTempDateTo('');
160
+ }, []);
147
161
  const handleClearUser = useCallback(() => {
148
162
  onUserChange?.(undefined);
149
163
  setFilterOpen(false);
@@ -163,8 +177,10 @@ export function useColumnHeaderFilterState(params) {
163
177
  return !!textValue.trim();
164
178
  if (filterType === 'people')
165
179
  return !!selectedUser;
180
+ if (filterType === 'date')
181
+ return !!(dateValue?.from || dateValue?.to);
166
182
  return false;
167
- }, [filterType, safeSelectedValues, textValue, selectedUser]);
183
+ }, [filterType, safeSelectedValues, textValue, selectedUser, dateValue]);
168
184
  return {
169
185
  headerRef,
170
186
  popoverRef,
@@ -183,6 +199,10 @@ export function useColumnHeaderFilterState(params) {
183
199
  isPeopleLoading,
184
200
  peopleSearchText,
185
201
  setPeopleSearchText,
202
+ tempDateFrom,
203
+ setTempDateFrom,
204
+ tempDateTo,
205
+ setTempDateTo,
186
206
  hasActiveFilter,
187
207
  popoverPosition,
188
208
  handlers: {
@@ -192,6 +212,8 @@ export function useColumnHeaderFilterState(params) {
192
212
  handleTextClear,
193
213
  handleUserSelect,
194
214
  handleClearUser,
215
+ handleDateApply,
216
+ handleDateClear,
195
217
  handleCheckboxChange,
196
218
  handleSelectAll,
197
219
  handleClearSelection,
@@ -1,43 +1,58 @@
1
- import { useCallback, useRef, useEffect } from 'react';
2
- export function useColumnResize({ columnSizingOverrides, setColumnSizingOverrides, minWidth = 80, defaultWidth = 120, }) {
3
- const resizingRef = useRef(null);
1
+ import { useCallback, useRef } from 'react';
2
+ export function useColumnResize({ columnSizingOverrides, setColumnSizingOverrides, minWidth = 80, defaultWidth = 120, onColumnResized, }) {
3
+ const rafRef = useRef(0);
4
+ const onColumnResizedRef = useRef(onColumnResized);
5
+ onColumnResizedRef.current = onColumnResized;
4
6
  const handleResizeStart = useCallback((e, col) => {
5
7
  e.preventDefault();
6
8
  e.stopPropagation();
7
- const currentWidth = columnSizingOverrides[col.columnId]?.widthPx
9
+ const startX = e.clientX;
10
+ const columnId = col.columnId;
11
+ const startWidth = columnSizingOverrides[columnId]?.widthPx
8
12
  ?? col.idealWidth
9
13
  ?? col.defaultWidth
10
14
  ?? defaultWidth;
11
- resizingRef.current = {
12
- columnId: col.columnId,
13
- startX: e.clientX,
14
- startWidth: currentWidth,
15
+ let latestWidth = startWidth;
16
+ // Lock cursor and prevent text selection during drag
17
+ const prevCursor = document.body.style.cursor;
18
+ const prevUserSelect = document.body.style.userSelect;
19
+ document.body.style.cursor = 'col-resize';
20
+ document.body.style.userSelect = 'none';
21
+ const flushWidth = () => {
22
+ setColumnSizingOverrides((prev) => ({
23
+ ...prev,
24
+ [columnId]: { widthPx: latestWidth },
25
+ }));
15
26
  };
16
- }, [columnSizingOverrides, defaultWidth]);
17
- const handleResizeMove = useCallback((e) => {
18
- if (!resizingRef.current)
19
- return;
20
- const { columnId, startX, startWidth } = resizingRef.current;
21
- const deltaX = e.clientX - startX;
22
- const newWidth = Math.max(minWidth, startWidth + deltaX);
23
- setColumnSizingOverrides((prev) => ({
24
- ...prev,
25
- [columnId]: { widthPx: newWidth },
26
- }));
27
- }, [setColumnSizingOverrides, minWidth]);
28
- const handleResizeEnd = useCallback(() => {
29
- resizingRef.current = null;
30
- }, []);
31
- useEffect(() => {
32
- const handleMouseMove = (e) => handleResizeMove(e);
33
- const handleMouseUp = () => handleResizeEnd();
34
- document.addEventListener('mousemove', handleMouseMove);
35
- document.addEventListener('mouseup', handleMouseUp);
36
- return () => {
37
- document.removeEventListener('mousemove', handleMouseMove);
38
- document.removeEventListener('mouseup', handleMouseUp);
27
+ const onMove = (moveEvent) => {
28
+ const deltaX = moveEvent.clientX - startX;
29
+ latestWidth = Math.max(minWidth, startWidth + deltaX);
30
+ if (!rafRef.current) {
31
+ rafRef.current = requestAnimationFrame(() => {
32
+ rafRef.current = 0;
33
+ flushWidth();
34
+ });
35
+ }
36
+ };
37
+ const onUp = () => {
38
+ document.removeEventListener('mousemove', onMove);
39
+ document.removeEventListener('mouseup', onUp);
40
+ // Restore cursor and user-select
41
+ document.body.style.cursor = prevCursor;
42
+ document.body.style.userSelect = prevUserSelect;
43
+ // Cancel pending RAF and flush final width synchronously
44
+ if (rafRef.current) {
45
+ cancelAnimationFrame(rafRef.current);
46
+ rafRef.current = 0;
47
+ }
48
+ flushWidth();
49
+ if (onColumnResizedRef.current) {
50
+ onColumnResizedRef.current(columnId, latestWidth);
51
+ }
39
52
  };
40
- }, [handleResizeMove, handleResizeEnd]);
53
+ document.addEventListener('mousemove', onMove);
54
+ document.addEventListener('mouseup', onUp);
55
+ }, [columnSizingOverrides, defaultWidth, minWidth, setColumnSizingOverrides]);
41
56
  const getColumnWidth = useCallback((col) => {
42
57
  return columnSizingOverrides[col.columnId]?.widthPx
43
58
  ?? col.idealWidth
@@ -1,6 +1,7 @@
1
1
  import { useMemo, useCallback, useEffect, useState } from 'react';
2
2
  import { flattenColumns, getDataGridStatusBarConfig } from '../utils';
3
3
  import { parseValue } from '../utils/valueParsers';
4
+ import { computeAggregations } from '../utils/aggregationUtils';
4
5
  import { useRowSelection } from './useRowSelection';
5
6
  import { useCellEditing } from './useCellEditing';
6
7
  import { useActiveCell } from './useActiveCell';
@@ -22,12 +23,25 @@ const NOOP_CTX = (_e) => { };
22
23
  */
23
24
  export function useDataGridState(params) {
24
25
  const { props, wrapperRef } = params;
25
- const { items, columns, getRowId, visibleColumns, columnOrder, rowSelection = 'none', selectedRows: controlledSelectedRows, onSelectionChange, statusBar, emptyState, editable, cellSelection: cellSelectionProp, onCellValueChanged: onCellValueChangedProp, } = props;
26
+ const { items, columns, getRowId, visibleColumns, columnOrder, rowSelection = 'none', selectedRows: controlledSelectedRows, onSelectionChange, statusBar, emptyState, editable, cellSelection: cellSelectionProp, onCellValueChanged: onCellValueChangedProp, initialColumnWidths, onColumnResized, pinnedColumns, } = props;
26
27
  const cellSelection = cellSelectionProp !== false;
27
28
  // Wrap onCellValueChanged with undo/redo tracking — all edits are recorded automatically
28
29
  const undoRedo = useUndoRedo({ onCellValueChanged: onCellValueChangedProp });
29
30
  const onCellValueChanged = undoRedo.onCellValueChanged;
30
- const flatColumns = useMemo(() => flattenColumns(columns), [columns]);
31
+ const flatColumnsRaw = useMemo(() => flattenColumns(columns), [columns]);
32
+ // Apply runtime pin overrides (from applyColumnState or programmatic changes)
33
+ const flatColumns = useMemo(() => {
34
+ if (!pinnedColumns || Object.keys(pinnedColumns).length === 0)
35
+ return flatColumnsRaw;
36
+ return flatColumnsRaw.map((col) => {
37
+ const override = pinnedColumns[col.columnId];
38
+ if (override && col.pinned !== override) {
39
+ return { ...col, pinned: override };
40
+ }
41
+ // If col was pinned by definition but not in overrides, keep original
42
+ return col;
43
+ });
44
+ }, [flatColumnsRaw, pinnedColumns]);
31
45
  const visibleCols = useMemo(() => {
32
46
  const filtered = visibleColumns
33
47
  ? flatColumns.filter((c) => visibleColumns.has(c.columnId))
@@ -146,12 +160,20 @@ export function useDataGridState(params) {
146
160
  measure();
147
161
  return () => ro.disconnect();
148
162
  }, [wrapperRef]);
163
+ const [columnSizingOverrides, setColumnSizingOverrides] = useState(() => {
164
+ if (!initialColumnWidths)
165
+ return {};
166
+ const result = {};
167
+ for (const [id, width] of Object.entries(initialColumnWidths)) {
168
+ result[id] = { widthPx: width };
169
+ }
170
+ return result;
171
+ });
149
172
  const minTableWidth = useMemo(() => {
150
173
  const PADDING = 16;
151
174
  const checkboxW = hasCheckboxCol ? 48 : 0;
152
175
  return visibleCols.reduce((sum, c) => sum + (c.minWidth ?? 80) + PADDING, checkboxW);
153
176
  }, [visibleCols, hasCheckboxCol]);
154
- const [columnSizingOverrides, setColumnSizingOverrides] = useState({});
155
177
  useEffect(() => {
156
178
  const colIds = new Set(flatColumns.map((c) => c.columnId));
157
179
  setColumnSizingOverrides((prev) => {
@@ -166,11 +188,28 @@ export function useDataGridState(params) {
166
188
  return changed ? next : prev;
167
189
  });
168
190
  }, [flatColumns]);
169
- const statusBarConfig = useMemo(() => getDataGridStatusBarConfig(statusBar, items.length, selectedRowIds.size), [statusBar, items.length, selectedRowIds.size]);
191
+ const desiredTableWidth = useMemo(() => {
192
+ const PADDING = 16;
193
+ const checkboxW = hasCheckboxCol ? 48 : 0;
194
+ return visibleCols.reduce((sum, c) => {
195
+ const override = columnSizingOverrides[c.columnId];
196
+ const w = override
197
+ ? override.widthPx
198
+ : (c.idealWidth ?? c.defaultWidth ?? c.minWidth ?? 80);
199
+ return sum + Math.max(c.minWidth ?? 80, w) + PADDING;
200
+ }, checkboxW);
201
+ }, [visibleCols, columnSizingOverrides, hasCheckboxCol]);
202
+ const aggregation = useMemo(() => computeAggregations(items, visibleCols, cellSelection ? selectionRange : null), [items, visibleCols, selectionRange, cellSelection]);
203
+ const statusBarConfig = useMemo(() => {
204
+ const base = getDataGridStatusBarConfig(statusBar, items.length, selectedRowIds.size);
205
+ if (!base)
206
+ return null;
207
+ return { ...base, aggregation: aggregation ?? undefined };
208
+ }, [statusBar, items.length, selectedRowIds.size, aggregation]);
170
209
  const showEmptyInGrid = items.length === 0 && !!emptyState;
171
210
  const hasCellSelection = selectionRange != null || activeCell != null;
172
211
  // --- View-model inputs (shared across all 3 DataGridTables) ---
173
- const { sortBy, sortDirection, onColumnSort, textFilters = {}, onTextFilterChange, peopleFilters = {}, onPeopleFilterChange, peopleSearch, filterOptions, loadingFilterOptions, multiSelectFilters, onMultiSelectFilterChange, } = props;
212
+ const { sortBy, sortDirection, onColumnSort, textFilters = {}, onTextFilterChange, peopleFilters = {}, onPeopleFilterChange, peopleSearch, filterOptions, loadingFilterOptions, multiSelectFilters, onMultiSelectFilterChange, dateFilters = {}, onDateFilterChange, } = props;
174
213
  const headerFilterInput = useMemo(() => ({
175
214
  sortBy,
176
215
  sortDirection,
@@ -184,6 +223,8 @@ export function useDataGridState(params) {
184
223
  loadingFilterOptions,
185
224
  multiSelectFilters,
186
225
  onMultiSelectFilterChange,
226
+ dateFilters,
227
+ onDateFilterChange,
187
228
  }), [
188
229
  sortBy,
189
230
  sortDirection,
@@ -197,6 +238,8 @@ export function useDataGridState(params) {
197
238
  loadingFilterOptions,
198
239
  multiSelectFilters,
199
240
  onMultiSelectFilterChange,
241
+ dateFilters,
242
+ onDateFilterChange,
200
243
  ]);
201
244
  const cellDescriptorInput = useMemo(() => ({
202
245
  editingCell,
@@ -302,8 +345,10 @@ export function useDataGridState(params) {
302
345
  handleFillHandleMouseDown: cellSelection ? handleFillHandleMouseDown : NOOP,
303
346
  containerWidth,
304
347
  minTableWidth,
348
+ desiredTableWidth,
305
349
  columnSizingOverrides,
306
350
  setColumnSizingOverrides,
351
+ onColumnResized,
307
352
  headerFilterInput,
308
353
  cellDescriptorInput,
309
354
  commitCellEdit,