@alaarab/ogrid-react 2.0.0-beta
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/README.md +55 -0
- package/dist/esm/components/BaseInlineCellEditor.js +112 -0
- package/dist/esm/components/CellErrorBoundary.js +43 -0
- package/dist/esm/components/EmptyState.js +19 -0
- package/dist/esm/components/GridContextMenu.js +35 -0
- package/dist/esm/components/MarchingAntsOverlay.js +110 -0
- package/dist/esm/components/OGridLayout.js +91 -0
- package/dist/esm/components/SideBar.js +122 -0
- package/dist/esm/components/StatusBar.js +6 -0
- package/dist/esm/hooks/index.js +25 -0
- package/dist/esm/hooks/useActiveCell.js +62 -0
- package/dist/esm/hooks/useCellEditing.js +15 -0
- package/dist/esm/hooks/useCellSelection.js +327 -0
- package/dist/esm/hooks/useClipboard.js +161 -0
- package/dist/esm/hooks/useColumnChooserState.js +62 -0
- package/dist/esm/hooks/useColumnHeaderFilterState.js +180 -0
- package/dist/esm/hooks/useColumnResize.js +92 -0
- package/dist/esm/hooks/useContextMenu.js +21 -0
- package/dist/esm/hooks/useDataGridState.js +313 -0
- package/dist/esm/hooks/useDateFilterState.js +34 -0
- package/dist/esm/hooks/useDebounce.js +35 -0
- package/dist/esm/hooks/useFillHandle.js +195 -0
- package/dist/esm/hooks/useFilterOptions.js +40 -0
- package/dist/esm/hooks/useInlineCellEditorState.js +44 -0
- package/dist/esm/hooks/useKeyboardNavigation.js +419 -0
- package/dist/esm/hooks/useLatestRef.js +11 -0
- package/dist/esm/hooks/useMultiSelectFilterState.js +59 -0
- package/dist/esm/hooks/useOGrid.js +465 -0
- package/dist/esm/hooks/usePeopleFilterState.js +68 -0
- package/dist/esm/hooks/useRichSelectState.js +58 -0
- package/dist/esm/hooks/useRowSelection.js +80 -0
- package/dist/esm/hooks/useSideBarState.js +39 -0
- package/dist/esm/hooks/useTableLayout.js +77 -0
- package/dist/esm/hooks/useTextFilterState.js +25 -0
- package/dist/esm/hooks/useUndoRedo.js +83 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/storybook/index.js +1 -0
- package/dist/esm/storybook/mockData.js +73 -0
- package/dist/esm/types/columnTypes.js +1 -0
- package/dist/esm/types/dataGridTypes.js +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/dataGridViewModel.js +220 -0
- package/dist/esm/utils/gridRowComparator.js +2 -0
- package/dist/esm/utils/index.js +5 -0
- package/dist/types/components/BaseInlineCellEditor.d.ts +33 -0
- package/dist/types/components/CellErrorBoundary.d.ts +25 -0
- package/dist/types/components/EmptyState.d.ts +26 -0
- package/dist/types/components/GridContextMenu.d.ts +18 -0
- package/dist/types/components/MarchingAntsOverlay.d.ts +15 -0
- package/dist/types/components/OGridLayout.d.ts +37 -0
- package/dist/types/components/SideBar.d.ts +30 -0
- package/dist/types/components/StatusBar.d.ts +24 -0
- package/dist/types/hooks/index.d.ts +48 -0
- package/dist/types/hooks/useActiveCell.d.ts +13 -0
- package/dist/types/hooks/useCellEditing.d.ts +16 -0
- package/dist/types/hooks/useCellSelection.d.ts +22 -0
- package/dist/types/hooks/useClipboard.d.ts +30 -0
- package/dist/types/hooks/useColumnChooserState.d.ts +27 -0
- package/dist/types/hooks/useColumnHeaderFilterState.d.ts +73 -0
- package/dist/types/hooks/useColumnResize.d.ts +23 -0
- package/dist/types/hooks/useContextMenu.d.ts +19 -0
- package/dist/types/hooks/useDataGridState.d.ts +137 -0
- package/dist/types/hooks/useDateFilterState.d.ts +19 -0
- package/dist/types/hooks/useDebounce.d.ts +9 -0
- package/dist/types/hooks/useFillHandle.d.ts +33 -0
- package/dist/types/hooks/useFilterOptions.d.ts +16 -0
- package/dist/types/hooks/useInlineCellEditorState.d.ts +24 -0
- package/dist/types/hooks/useKeyboardNavigation.d.ts +47 -0
- package/dist/types/hooks/useLatestRef.d.ts +6 -0
- package/dist/types/hooks/useMultiSelectFilterState.d.ts +24 -0
- package/dist/types/hooks/useOGrid.d.ts +52 -0
- package/dist/types/hooks/usePeopleFilterState.d.ts +25 -0
- package/dist/types/hooks/useRichSelectState.d.ts +22 -0
- package/dist/types/hooks/useRowSelection.d.ts +22 -0
- package/dist/types/hooks/useSideBarState.d.ts +20 -0
- package/dist/types/hooks/useTableLayout.d.ts +27 -0
- package/dist/types/hooks/useTextFilterState.d.ts +16 -0
- package/dist/types/hooks/useUndoRedo.d.ts +23 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/storybook/index.d.ts +2 -0
- package/dist/types/storybook/mockData.d.ts +37 -0
- package/dist/types/types/columnTypes.d.ts +25 -0
- package/dist/types/types/dataGridTypes.d.ts +152 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/utils/dataGridViewModel.d.ts +161 -0
- package/dist/types/utils/gridRowComparator.d.ts +2 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/package.json +46 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* View model helpers for DataGridTable. Core owns the logic; UI packages only render.
|
|
3
|
+
*/
|
|
4
|
+
import type * as React from 'react';
|
|
5
|
+
import type { ColumnFilterType, ICellEditorProps, IDateFilterValue } from '../types/columnTypes';
|
|
6
|
+
import type { IColumnDef } from '../types/columnTypes';
|
|
7
|
+
import type { RowId, UserLike, IFilters, FilterValue } from '../types/dataGridTypes';
|
|
8
|
+
export interface HeaderFilterConfigInput {
|
|
9
|
+
sortBy?: string;
|
|
10
|
+
sortDirection: 'asc' | 'desc';
|
|
11
|
+
onColumnSort: (columnKey: string) => void;
|
|
12
|
+
filters: IFilters;
|
|
13
|
+
onFilterChange: (key: string, value: FilterValue | undefined) => void;
|
|
14
|
+
filterOptions: Record<string, string[]>;
|
|
15
|
+
loadingFilterOptions: Record<string, boolean>;
|
|
16
|
+
peopleSearch?: (query: string) => Promise<UserLike[]>;
|
|
17
|
+
}
|
|
18
|
+
/** Props to pass to ColumnHeaderFilter. Matches IColumnHeaderFilterProps. */
|
|
19
|
+
export interface HeaderFilterConfig {
|
|
20
|
+
columnKey: string;
|
|
21
|
+
columnName: string;
|
|
22
|
+
filterType: ColumnFilterType;
|
|
23
|
+
isSorted?: boolean;
|
|
24
|
+
isSortedDescending?: boolean;
|
|
25
|
+
onSort?: () => void;
|
|
26
|
+
selectedValues?: string[];
|
|
27
|
+
onFilterChange?: (values: string[]) => void;
|
|
28
|
+
options?: string[];
|
|
29
|
+
isLoadingOptions?: boolean;
|
|
30
|
+
textValue?: string;
|
|
31
|
+
onTextChange?: (value: string) => void;
|
|
32
|
+
selectedUser?: UserLike;
|
|
33
|
+
onUserChange?: (user: UserLike | undefined) => void;
|
|
34
|
+
peopleSearch?: (query: string) => Promise<UserLike[]>;
|
|
35
|
+
dateValue?: IDateFilterValue;
|
|
36
|
+
onDateChange?: (value: IDateFilterValue | undefined) => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns ColumnHeaderFilter props from column def and grid filter/sort state.
|
|
40
|
+
* Use in Fluent/Material/Radix DataGridTable instead of createHeaderWithFilter.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getHeaderFilterConfig<T>(col: IColumnDef<T>, input: HeaderFilterConfigInput): HeaderFilterConfig;
|
|
43
|
+
export type CellRenderMode = 'editing-inline' | 'editing-popover' | 'display';
|
|
44
|
+
export interface CellRenderDescriptorInput<T> {
|
|
45
|
+
editingCell: {
|
|
46
|
+
rowId: RowId;
|
|
47
|
+
columnId: string;
|
|
48
|
+
} | null;
|
|
49
|
+
activeCell: {
|
|
50
|
+
rowIndex: number;
|
|
51
|
+
columnIndex: number;
|
|
52
|
+
} | null;
|
|
53
|
+
selectionRange: {
|
|
54
|
+
startRow: number;
|
|
55
|
+
startCol: number;
|
|
56
|
+
endRow: number;
|
|
57
|
+
endCol: number;
|
|
58
|
+
} | null;
|
|
59
|
+
cutRange: {
|
|
60
|
+
startRow: number;
|
|
61
|
+
startCol: number;
|
|
62
|
+
endRow: number;
|
|
63
|
+
endCol: number;
|
|
64
|
+
} | null;
|
|
65
|
+
copyRange: {
|
|
66
|
+
startRow: number;
|
|
67
|
+
startCol: number;
|
|
68
|
+
endRow: number;
|
|
69
|
+
endCol: number;
|
|
70
|
+
} | null;
|
|
71
|
+
colOffset: number;
|
|
72
|
+
itemsLength: number;
|
|
73
|
+
getRowId: (item: T) => RowId;
|
|
74
|
+
editable?: boolean;
|
|
75
|
+
onCellValueChanged?: (event: import('../types/columnTypes').ICellValueChangedEvent<T>) => void;
|
|
76
|
+
/** True while user is drag-selecting cells — hides fill handle during drag. */
|
|
77
|
+
isDragging?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface CellRenderDescriptor {
|
|
80
|
+
mode: CellRenderMode;
|
|
81
|
+
editorType?: 'text' | 'select' | 'checkbox' | 'richSelect' | 'date';
|
|
82
|
+
value?: unknown;
|
|
83
|
+
isActive: boolean;
|
|
84
|
+
isInRange: boolean;
|
|
85
|
+
isInCutRange: boolean;
|
|
86
|
+
isInCopyRange: boolean;
|
|
87
|
+
isSelectionEndCell: boolean;
|
|
88
|
+
canEditAny: boolean;
|
|
89
|
+
isPinned: boolean;
|
|
90
|
+
pinnedSide?: 'left' | 'right';
|
|
91
|
+
globalColIndex: number;
|
|
92
|
+
rowId: RowId;
|
|
93
|
+
rowIndex: number;
|
|
94
|
+
/** Raw value for display (when mode === 'display'). UI uses col.renderCell or col.valueFormatter. */
|
|
95
|
+
displayValue?: unknown;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns a descriptor for rendering a cell. UI uses this to decide editing-inline vs editing-popover vs display
|
|
99
|
+
* and to apply isActive, isInRange, etc. without duplicating the boolean logic.
|
|
100
|
+
*/
|
|
101
|
+
export declare function getCellRenderDescriptor<T>(item: T, col: IColumnDef<T>, rowIndex: number, colIdx: number, input: CellRenderDescriptorInput<T>): CellRenderDescriptor;
|
|
102
|
+
/**
|
|
103
|
+
* Resolves display content for a cell in display mode.
|
|
104
|
+
* Handles the renderCell → valueFormatter → String() fallback chain.
|
|
105
|
+
*/
|
|
106
|
+
export declare function resolveCellDisplayContent<T>(col: IColumnDef<T>, item: T, displayValue: unknown): React.ReactNode;
|
|
107
|
+
/**
|
|
108
|
+
* Resolves the cellStyle from a column def, handling both function and static values.
|
|
109
|
+
*/
|
|
110
|
+
export declare function resolveCellStyle<T>(col: IColumnDef<T>, item: T): React.CSSProperties | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Builds props for InlineCellEditor. Shared across all UI packages.
|
|
113
|
+
*/
|
|
114
|
+
export declare function buildInlineEditorProps<T>(item: T, col: IColumnDef<T>, descriptor: CellRenderDescriptor, callbacks: {
|
|
115
|
+
commitCellEdit: (item: T, columnId: string, oldValue: unknown, newValue: unknown, rowIndex: number, globalColIndex: number) => void;
|
|
116
|
+
setEditingCell: (cell: null) => void;
|
|
117
|
+
}): {
|
|
118
|
+
value: unknown;
|
|
119
|
+
item: T;
|
|
120
|
+
column: IColumnDef<T>;
|
|
121
|
+
rowIndex: number;
|
|
122
|
+
editorType: "text" | "select" | "checkbox" | "richSelect" | "date";
|
|
123
|
+
onCommit: (newValue: unknown) => void;
|
|
124
|
+
onCancel: () => void;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Builds ICellEditorProps for custom popover editors. Shared across all UI packages.
|
|
128
|
+
*/
|
|
129
|
+
export declare function buildPopoverEditorProps<T>(item: T, col: IColumnDef<T>, descriptor: CellRenderDescriptor, pendingEditorValue: unknown, callbacks: {
|
|
130
|
+
setPendingEditorValue: (value: unknown) => void;
|
|
131
|
+
commitCellEdit: (item: T, columnId: string, oldValue: unknown, newValue: unknown, rowIndex: number, globalColIndex: number) => void;
|
|
132
|
+
cancelPopoverEdit: () => void;
|
|
133
|
+
}): ICellEditorProps<T>;
|
|
134
|
+
/**
|
|
135
|
+
* Common interaction props for cell wrapper elements.
|
|
136
|
+
* Includes data attributes, event handlers, and accessibility props.
|
|
137
|
+
* Spread onto the cell wrapper div/Box in each UI package.
|
|
138
|
+
*/
|
|
139
|
+
export interface CellInteractionHandlers {
|
|
140
|
+
handleCellMouseDown: (e: React.MouseEvent, rowIndex: number, colIndex: number) => void;
|
|
141
|
+
setActiveCell: (cell: {
|
|
142
|
+
rowIndex: number;
|
|
143
|
+
columnIndex: number;
|
|
144
|
+
}) => void;
|
|
145
|
+
setEditingCell: (cell: {
|
|
146
|
+
rowId: RowId;
|
|
147
|
+
columnId: string;
|
|
148
|
+
} | null) => void;
|
|
149
|
+
handleCellContextMenu: (e: React.MouseEvent) => void;
|
|
150
|
+
}
|
|
151
|
+
export declare function getCellInteractionProps(descriptor: CellRenderDescriptor, columnId: string, handlers: CellInteractionHandlers): {
|
|
152
|
+
role?: "button" | undefined;
|
|
153
|
+
onDoubleClick?: (() => void) | undefined;
|
|
154
|
+
tabIndex: number;
|
|
155
|
+
onMouseDown: (e: React.MouseEvent) => void;
|
|
156
|
+
onClick: () => void;
|
|
157
|
+
onContextMenu: (e: React.MouseEvent) => void;
|
|
158
|
+
'data-in-range'?: "true" | undefined;
|
|
159
|
+
'data-row-index': number;
|
|
160
|
+
'data-col-index': number;
|
|
161
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { escapeCsvValue, buildCsvHeader, buildCsvRows, exportToCsv, triggerCsvDownload, getCellValue, flattenColumns, buildHeaderRows, getFilterField, mergeFilter, deriveFilterOptionsFromData, getMultiSelectFilterFields, getStatusBarParts, getDataGridStatusBarConfig, getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, GRID_CONTEXT_MENU_ITEMS, getContextMenuHandlers, formatShortcut, parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, computeAggregations, processClientSideData, } from '@alaarab/ogrid-core';
|
|
2
|
+
export type { CsvColumn, StatusBarPart, StatusBarPartsInput, GridContextMenuItem, GridContextMenuHandlerProps, PaginationViewModel, ParseValueResult, AggregationResult, } from '@alaarab/ogrid-core';
|
|
3
|
+
export { getHeaderFilterConfig, getCellRenderDescriptor, resolveCellDisplayContent, resolveCellStyle, buildInlineEditorProps, buildPopoverEditorProps, getCellInteractionProps, } from './dataGridViewModel';
|
|
4
|
+
export type { HeaderFilterConfigInput, HeaderFilterConfig, CellRenderDescriptorInput, CellRenderDescriptor, CellRenderMode, CellInteractionHandlers, } from './dataGridViewModel';
|
|
5
|
+
export { areGridRowPropsEqual, isRowInRange } from './gridRowComparator';
|
|
6
|
+
export type { GridRowComparatorProps } from './gridRowComparator';
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alaarab/ogrid-react",
|
|
3
|
+
"version": "2.0.0-beta",
|
|
4
|
+
"description": "OGrid React – React hooks, headless components, and utilities for OGrid data grids.",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/esm/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
17
|
+
"test": "jest"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ogrid",
|
|
21
|
+
"datatable",
|
|
22
|
+
"react",
|
|
23
|
+
"typescript",
|
|
24
|
+
"grid",
|
|
25
|
+
"core"
|
|
26
|
+
],
|
|
27
|
+
"author": "Ala Arab",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@alaarab/ogrid-core": "2.0.0-beta"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|