@alaarab/ogrid-core 1.8.2 → 1.9.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 (71) hide show
  1. package/README.md +42 -31
  2. package/dist/esm/components/BaseInlineCellEditor.js +112 -0
  3. package/dist/esm/components/CellErrorBoundary.js +43 -0
  4. package/dist/esm/components/EmptyState.js +19 -0
  5. package/dist/esm/components/GridContextMenu.js +4 -3
  6. package/dist/esm/components/MarchingAntsOverlay.js +6 -5
  7. package/dist/esm/components/OGridLayout.js +7 -6
  8. package/dist/esm/components/SideBar.js +66 -44
  9. package/dist/esm/constants.js +11 -0
  10. package/dist/esm/hooks/index.js +6 -0
  11. package/dist/esm/hooks/useActiveCell.js +25 -9
  12. package/dist/esm/hooks/useCellEditing.js +4 -0
  13. package/dist/esm/hooks/useCellSelection.js +7 -1
  14. package/dist/esm/hooks/useClipboard.js +36 -36
  15. package/dist/esm/hooks/useColumnHeaderFilterState.js +71 -119
  16. package/dist/esm/hooks/useColumnResize.js +27 -4
  17. package/dist/esm/hooks/useContextMenu.js +9 -5
  18. package/dist/esm/hooks/useDataGridState.js +110 -162
  19. package/dist/esm/hooks/useDateFilterState.js +34 -0
  20. package/dist/esm/hooks/useFillHandle.js +7 -2
  21. package/dist/esm/hooks/useFilterOptions.js +5 -5
  22. package/dist/esm/hooks/useKeyboardNavigation.js +18 -34
  23. package/dist/esm/hooks/useLatestRef.js +11 -0
  24. package/dist/esm/hooks/useMultiSelectFilterState.js +59 -0
  25. package/dist/esm/hooks/useOGrid.js +71 -18
  26. package/dist/esm/hooks/usePeopleFilterState.js +68 -0
  27. package/dist/esm/hooks/useRichSelectState.js +5 -0
  28. package/dist/esm/hooks/useRowSelection.js +14 -4
  29. package/dist/esm/hooks/useSideBarState.js +5 -0
  30. package/dist/esm/hooks/useTableLayout.js +77 -0
  31. package/dist/esm/hooks/useTextFilterState.js +25 -0
  32. package/dist/esm/hooks/useUndoRedo.js +6 -5
  33. package/dist/esm/index.js +7 -2
  34. package/dist/esm/utils/clientSideData.js +25 -12
  35. package/dist/esm/utils/columnUtils.js +6 -0
  36. package/dist/esm/utils/gridRowComparator.js +68 -0
  37. package/dist/esm/utils/index.js +1 -0
  38. package/dist/esm/utils/ogridHelpers.js +2 -1
  39. package/dist/esm/utils/paginationHelpers.js +7 -1
  40. package/dist/types/components/BaseInlineCellEditor.d.ts +33 -0
  41. package/dist/types/components/CellErrorBoundary.d.ts +25 -0
  42. package/dist/types/components/EmptyState.d.ts +26 -0
  43. package/dist/types/constants.d.ts +11 -0
  44. package/dist/types/hooks/index.d.ts +12 -1
  45. package/dist/types/hooks/useCellEditing.d.ts +4 -0
  46. package/dist/types/hooks/useCellSelection.d.ts +5 -0
  47. package/dist/types/hooks/useClipboard.d.ts +5 -0
  48. package/dist/types/hooks/useColumnHeaderFilterState.d.ts +1 -0
  49. package/dist/types/hooks/useColumnResize.d.ts +5 -0
  50. package/dist/types/hooks/useContextMenu.d.ts +6 -2
  51. package/dist/types/hooks/useDataGridState.d.ts +1 -0
  52. package/dist/types/hooks/useDateFilterState.d.ts +19 -0
  53. package/dist/types/hooks/useFillHandle.d.ts +5 -0
  54. package/dist/types/hooks/useKeyboardNavigation.d.ts +38 -25
  55. package/dist/types/hooks/useLatestRef.d.ts +6 -0
  56. package/dist/types/hooks/useMultiSelectFilterState.d.ts +24 -0
  57. package/dist/types/hooks/useOGrid.d.ts +30 -9
  58. package/dist/types/hooks/usePeopleFilterState.d.ts +25 -0
  59. package/dist/types/hooks/useRichSelectState.d.ts +5 -0
  60. package/dist/types/hooks/useRowSelection.d.ts +5 -0
  61. package/dist/types/hooks/useSideBarState.d.ts +5 -0
  62. package/dist/types/hooks/useTableLayout.d.ts +27 -0
  63. package/dist/types/hooks/useTextFilterState.d.ts +16 -0
  64. package/dist/types/hooks/useUndoRedo.d.ts +3 -1
  65. package/dist/types/index.d.ts +11 -4
  66. package/dist/types/types/columnTypes.d.ts +2 -3
  67. package/dist/types/types/dataGridTypes.d.ts +32 -4
  68. package/dist/types/types/index.d.ts +1 -1
  69. package/dist/types/utils/gridRowComparator.d.ts +49 -0
  70. package/dist/types/utils/index.d.ts +2 -0
  71. package/package.json +1 -1
@@ -149,13 +149,23 @@ export interface IOGridApi<T> {
149
149
  selectAll: () => void;
150
150
  /** Deselect all rows. */
151
151
  deselectAll: () => void;
152
+ /** Clear all filters (shorthand for setFilterModel({})). */
153
+ clearFilters: () => void;
154
+ /** Reset sort to the default (first column, ascending). */
155
+ clearSort: () => void;
156
+ /** Reset all grid state (filters, sort, selection). */
157
+ resetGridState: (options?: {
158
+ keepSelection?: boolean;
159
+ }) => void;
160
+ /** Get the currently displayed (paginated) rows. */
161
+ getDisplayedRows: () => T[];
162
+ /** Re-trigger a data fetch (server-side only; no-op for client-side). */
163
+ refreshData: () => void;
152
164
  }
153
- /** Props for the OGrid wrapper component (shared across Fluent, Material, Radix). */
154
- export interface IOGridProps<T> {
165
+ /** Base props shared by both client-side and server-side OGrid modes. */
166
+ interface IOGridBaseProps<T> {
155
167
  columns: (IColumnDef<T> | IColumnGroupDef<T>)[];
156
168
  getRowId: (item: T) => RowId;
157
- data?: T[];
158
- dataSource?: IDataSource<T>;
159
169
  page?: number;
160
170
  pageSize?: number;
161
171
  sort?: {
@@ -221,9 +231,24 @@ export interface IOGridProps<T> {
221
231
  onFirstDataRendered?: () => void;
222
232
  /** Called when server-side fetchPage fails. */
223
233
  onError?: (error: unknown) => void;
234
+ /** Called when a cell renderer or custom editor throws an error. */
235
+ onCellError?: (error: Error, errorInfo: React.ErrorInfo) => void;
224
236
  'aria-label'?: string;
225
237
  'aria-labelledby'?: string;
226
238
  }
239
+ /** Client-side mode: pass a data array. */
240
+ export interface IOGridClientProps<T> extends IOGridBaseProps<T> {
241
+ data: T[];
242
+ dataSource?: never;
243
+ }
244
+ /** Server-side mode: pass a dataSource. */
245
+ export interface IOGridServerProps<T> extends IOGridBaseProps<T> {
246
+ data?: never;
247
+ dataSource: IDataSource<T>;
248
+ }
249
+ /** Props for the OGrid wrapper component (shared across Fluent, Material, Radix).
250
+ * Must provide either `data` (client-side) or `dataSource` (server-side), not both. */
251
+ export type IOGridProps<T> = IOGridClientProps<T> | IOGridServerProps<T>;
227
252
  /** Props passed from useOGrid to the framework-specific DataGridTable. */
228
253
  export interface IOGridDataGridProps<T> {
229
254
  items: T[];
@@ -279,6 +304,9 @@ export interface IOGridDataGridProps<T> {
279
304
  message?: ReactNode;
280
305
  render?: () => ReactNode;
281
306
  };
307
+ /** Called when a cell renderer or custom editor throws an error. */
308
+ onCellError?: (error: Error, errorInfo: React.ErrorInfo) => void;
282
309
  'aria-label'?: string;
283
310
  'aria-labelledby'?: string;
284
311
  }
312
+ export {};
@@ -1,3 +1,3 @@
1
1
  export type { ColumnFilterType, IColumnFilterDef, IColumnMeta, IColumnDef, IColumnGroupDef, IColumnDefinition, ICellValueChangedEvent, ICellEditorProps, CellEditorParams, IValueParserParams, IDateFilterValue, HeaderCell, HeaderRow, } from './columnTypes';
2
- export type { RowId, UserLike, UserLikeInput, FilterValue, IFilters, IFetchParams, IPageResult, IDataSource, IGridColumnState, IOGridApi, IOGridProps, IOGridDataGridProps, RowSelectionMode, IRowSelectionChangeEvent, StatusBarPanel, IStatusBarProps, IActiveCell, ISelectionRange, SideBarPanelId, ISideBarDef, } from './dataGridTypes';
2
+ export type { RowId, UserLike, UserLikeInput, FilterValue, IFilters, IFetchParams, IPageResult, IDataSource, IGridColumnState, IOGridApi, IOGridProps, IOGridClientProps, IOGridServerProps, IOGridDataGridProps, RowSelectionMode, IRowSelectionChangeEvent, StatusBarPanel, IStatusBarProps, IActiveCell, ISelectionRange, SideBarPanelId, ISideBarDef, } from './dataGridTypes';
3
3
  export { toUserLike, isInSelectionRange, normalizeSelectionRange } from './dataGridTypes';
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Props for GridRow comparator (generic to work with all 3 UI frameworks).
3
+ * Includes both render props and comparator-only props used to decide re-renders.
4
+ */
5
+ export interface GridRowComparatorProps {
6
+ item: unknown;
7
+ rowIndex: number;
8
+ rowId: string | number;
9
+ isSelected: boolean;
10
+ hasCheckboxCol: boolean;
11
+ selectionRange: {
12
+ startRow: number;
13
+ endRow: number;
14
+ startCol: number;
15
+ endCol: number;
16
+ } | null;
17
+ activeCell: {
18
+ rowIndex: number;
19
+ columnIndex: number;
20
+ } | null;
21
+ cutRange: {
22
+ startRow: number;
23
+ endRow: number;
24
+ startCol: number;
25
+ endCol: number;
26
+ } | null;
27
+ copyRange: {
28
+ startRow: number;
29
+ endRow: number;
30
+ startCol: number;
31
+ endCol: number;
32
+ } | null;
33
+ isDragging: boolean;
34
+ editingRowId: string | number | null;
35
+ visibleCols?: unknown;
36
+ columnMeta?: unknown;
37
+ cellClassMap?: unknown;
38
+ columnLayouts?: unknown;
39
+ }
40
+ /**
41
+ * Shared React.memo comparator for GridRow components across all 3 UI packages.
42
+ * Skips re-render for rows unaffected by selection/editing/interaction changes.
43
+ *
44
+ * Used by:
45
+ * - packages/radix/src/DataGridTable/DataGridTable.tsx
46
+ * - packages/fluent/src/DataGridTable/DataGridTable.tsx
47
+ * - packages/material/src/DataGridTable/DataGridTable.tsx
48
+ */
49
+ export declare function areGridRowPropsEqual(prev: GridRowComparatorProps, next: GridRowComparatorProps): boolean;
@@ -17,3 +17,5 @@ export type { ParseValueResult } from './valueParsers';
17
17
  export { computeAggregations } from './aggregationUtils';
18
18
  export type { AggregationResult } from './aggregationUtils';
19
19
  export { processClientSideData } from './clientSideData';
20
+ export { areGridRowPropsEqual } from './gridRowComparator';
21
+ export type { GridRowComparatorProps } from './gridRowComparator';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "description": "OGrid core – framework-agnostic types, hooks, and utilities for OGrid data tables.",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",