@alaarab/ogrid-core 1.2.0 → 1.2.2

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.
@@ -1,4 +1,4 @@
1
- import type { IActiveCell } from '../types';
1
+ import type { IActiveCell, RowId } from '../types';
2
2
  export interface UseActiveCellResult {
3
3
  activeCell: IActiveCell | null;
4
4
  setActiveCell: (cell: IActiveCell | null) => void;
@@ -8,6 +8,6 @@ export interface UseActiveCellResult {
8
8
  * When wrapperRef and editingCell are provided, scrolls the active cell into view when it changes (and not editing).
9
9
  */
10
10
  export declare function useActiveCell(wrapperRef?: React.RefObject<HTMLElement | null>, editingCell?: {
11
- rowId: string;
11
+ rowId: RowId;
12
12
  columnId: string;
13
13
  } | null): UseActiveCellResult;
@@ -1,5 +1,6 @@
1
+ import type { RowId } from '../types';
1
2
  export interface EditingCell {
2
- rowId: string;
3
+ rowId: RowId;
3
4
  columnId: string;
4
5
  }
5
6
  export interface UseCellEditingResult {
@@ -1,6 +1,6 @@
1
1
  import type { RefObject } from 'react';
2
2
  import type { HeaderFilterConfigInput, CellRenderDescriptorInput } from '../utils';
3
- import type { IOGridDataGridProps, IStatusBarProps, IColumnDef } from '../types';
3
+ import type { RowId, IOGridDataGridProps, IStatusBarProps, IColumnDef } from '../types';
4
4
  export interface UseDataGridStateParams<T> {
5
5
  props: IOGridDataGridProps<T>;
6
6
  wrapperRef: RefObject<HTMLDivElement | null>;
@@ -12,19 +12,19 @@ export interface UseDataGridStateResult<T> {
12
12
  totalColCount: number;
13
13
  colOffset: number;
14
14
  hasCheckboxCol: boolean;
15
- rowIndexByRowId: Map<string, number>;
16
- selectedRowIds: Set<string>;
17
- updateSelection: (newSelectedIds: Set<string>) => void;
18
- handleRowCheckboxChange: (rowId: string, checked: boolean, rowIndex: number, shiftKey: boolean) => void;
15
+ rowIndexByRowId: Map<RowId, number>;
16
+ selectedRowIds: Set<RowId>;
17
+ updateSelection: (newSelectedIds: Set<RowId>) => void;
18
+ handleRowCheckboxChange: (rowId: RowId, checked: boolean, rowIndex: number, shiftKey: boolean) => void;
19
19
  handleSelectAll: (checked: boolean) => void;
20
20
  allSelected: boolean;
21
21
  someSelected: boolean;
22
22
  editingCell: {
23
- rowId: string;
23
+ rowId: RowId;
24
24
  columnId: string;
25
25
  } | null;
26
26
  setEditingCell: (cell: {
27
- rowId: string;
27
+ rowId: RowId;
28
28
  columnId: string;
29
29
  } | null) => void;
30
30
  pendingEditorValue: unknown;
@@ -1,4 +1,4 @@
1
- import type { IActiveCell, ISelectionRange, IColumnDef, ICellValueChangedEvent, RowSelectionMode } from '../types';
1
+ import type { RowId, IActiveCell, ISelectionRange, IColumnDef, ICellValueChangedEvent, RowSelectionMode } from '../types';
2
2
  import type { EditingCell } from './useCellEditing';
3
3
  import type { ContextMenuPosition } from './useContextMenu';
4
4
  export interface UseKeyboardNavigationParams<T> {
@@ -13,12 +13,12 @@ export interface UseKeyboardNavigationParams<T> {
13
13
  setSelectionRange: (range: ISelectionRange | null) => void;
14
14
  editable: boolean | undefined;
15
15
  onCellValueChanged: ((event: ICellValueChangedEvent<T>) => void) | undefined;
16
- getRowId: (item: T) => string;
16
+ getRowId: (item: T) => RowId;
17
17
  editingCell: EditingCell | null;
18
18
  setEditingCell: (cell: EditingCell | null) => void;
19
19
  rowSelection: RowSelectionMode;
20
- selectedRowIds: Set<string>;
21
- handleRowCheckboxChange: (rowId: string, checked: boolean, rowIndex: number, shiftKey: boolean) => void;
20
+ selectedRowIds: Set<RowId>;
21
+ handleRowCheckboxChange: (rowId: RowId, checked: boolean, rowIndex: number, shiftKey: boolean) => void;
22
22
  handleCopy: () => void;
23
23
  handleCut: () => void;
24
24
  handlePaste: () => Promise<void>;
@@ -1,15 +1,15 @@
1
- import type { RowSelectionMode, IRowSelectionChangeEvent } from '../types';
1
+ import type { RowId, RowSelectionMode, IRowSelectionChangeEvent } from '../types';
2
2
  export interface UseRowSelectionParams<T> {
3
3
  items: T[];
4
- getRowId: (item: T) => string;
4
+ getRowId: (item: T) => RowId;
5
5
  rowSelection: RowSelectionMode;
6
- controlledSelectedRows: Set<string> | undefined;
6
+ controlledSelectedRows: Set<RowId> | undefined;
7
7
  onSelectionChange: ((event: IRowSelectionChangeEvent<T>) => void) | undefined;
8
8
  }
9
9
  export interface UseRowSelectionResult {
10
- selectedRowIds: Set<string>;
11
- updateSelection: (newSelectedIds: Set<string>) => void;
12
- handleRowCheckboxChange: (rowId: string, checked: boolean, rowIndex: number, shiftKey: boolean) => void;
10
+ selectedRowIds: Set<RowId>;
11
+ updateSelection: (newSelectedIds: Set<RowId>) => void;
12
+ handleRowCheckboxChange: (rowId: RowId, checked: boolean, rowIndex: number, shiftKey: boolean) => void;
13
13
  handleSelectAll: (checked: boolean) => void;
14
14
  allSelected: boolean;
15
15
  someSelected: boolean;
@@ -1,5 +1,7 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { IColumnDef, IColumnGroupDef, ICellValueChangedEvent } from './columnTypes';
3
+ /** Row identifier type — grids accept string or number IDs. */
4
+ export type RowId = string | number;
3
5
  export interface UserLike {
4
6
  id?: string;
5
7
  displayName: string;
@@ -58,9 +60,9 @@ export interface IGridColumnState {
58
60
  }
59
61
  /** Row selection mode. */
60
62
  export type RowSelectionMode = 'none' | 'single' | 'multiple';
61
- /** Event payload when row selection changes. Uses string[] for JSON-serializability. */
63
+ /** Event payload when row selection changes. */
62
64
  export interface IRowSelectionChangeEvent<T> {
63
- selectedRowIds: string[];
65
+ selectedRowIds: RowId[];
64
66
  selectedItems: T[];
65
67
  }
66
68
  /** Status bar panel definition. */
@@ -103,9 +105,9 @@ export interface IOGridApi<T> {
103
105
  /** Set filter model (unified IFilters). */
104
106
  setFilterModel: (filters: IFilters) => void;
105
107
  /** Get currently selected row IDs. */
106
- getSelectedRows: () => string[];
108
+ getSelectedRows: () => RowId[];
107
109
  /** Set selected row IDs programmatically. */
108
- setSelectedRows: (rowIds: string[]) => void;
110
+ setSelectedRows: (rowIds: RowId[]) => void;
109
111
  /** Select all rows. */
110
112
  selectAll: () => void;
111
113
  /** Deselect all rows. */
@@ -114,7 +116,7 @@ export interface IOGridApi<T> {
114
116
  /** Props for the OGrid wrapper component (shared across Fluent, Material, Radix). */
115
117
  export interface IOGridProps<T> {
116
118
  columns: (IColumnDef<T> | IColumnGroupDef<T>)[];
117
- getRowId: (item: T) => string;
119
+ getRowId: (item: T) => RowId;
118
120
  data?: T[];
119
121
  dataSource?: IDataSource<T>;
120
122
  page?: number;
@@ -143,7 +145,7 @@ export interface IOGridProps<T> {
143
145
  onUndo?: () => void;
144
146
  onRedo?: () => void;
145
147
  rowSelection?: RowSelectionMode;
146
- selectedRows?: Set<string>;
148
+ selectedRows?: Set<RowId>;
147
149
  onSelectionChange?: (event: IRowSelectionChangeEvent<T>) => void;
148
150
  statusBar?: boolean | IStatusBarProps;
149
151
  defaultPageSize?: number;
@@ -167,8 +169,8 @@ export interface IOGridProps<T> {
167
169
  export interface IOGridDataGridProps<T> {
168
170
  items: T[];
169
171
  columns: (IColumnDef<T> | IColumnGroupDef<T>)[];
170
- getRowId: (item: T) => string;
171
- sortBy: string;
172
+ getRowId: (item: T) => RowId;
173
+ sortBy?: string;
172
174
  sortDirection: 'asc' | 'desc';
173
175
  onColumnSort: (columnKey: string) => void;
174
176
  visibleColumns: Set<string>;
@@ -187,7 +189,7 @@ export interface IOGridDataGridProps<T> {
187
189
  onUndo?: () => void;
188
190
  onRedo?: () => void;
189
191
  rowSelection?: RowSelectionMode;
190
- selectedRows?: Set<string>;
192
+ selectedRows?: Set<RowId>;
191
193
  onSelectionChange?: (event: IRowSelectionChangeEvent<T>) => void;
192
194
  statusBar?: IStatusBarProps;
193
195
  multiSelectFilters: Record<string, string[]>;
@@ -1,3 +1,3 @@
1
1
  export type { ColumnFilterType, IColumnFilterDef, IColumnMeta, IColumnDef, IColumnGroupDef, IColumnDefinition, ICellValueChangedEvent, ICellEditorProps, CellEditorParams, } from './columnTypes';
2
- export type { UserLike, UserLikeInput, FilterValue, IFilters, IFetchParams, IPageResult, IDataSource, IGridColumnState, IOGridApi, IOGridProps, IOGridDataGridProps, RowSelectionMode, IRowSelectionChangeEvent, StatusBarPanel, IStatusBarProps, IActiveCell, ISelectionRange, } from './dataGridTypes';
2
+ export type { RowId, UserLike, UserLikeInput, FilterValue, IFilters, IFetchParams, IPageResult, IDataSource, IGridColumnState, IOGridApi, IOGridProps, IOGridDataGridProps, RowSelectionMode, IRowSelectionChangeEvent, StatusBarPanel, IStatusBarProps, IActiveCell, ISelectionRange, } from './dataGridTypes';
3
3
  export { toUserLike, toDataGridFilterProps, isInSelectionRange, normalizeSelectionRange } from './dataGridTypes';
@@ -3,9 +3,9 @@
3
3
  */
4
4
  import type { ColumnFilterType } from '../types/columnTypes';
5
5
  import type { IColumnDef } from '../types/columnTypes';
6
- import type { UserLike } from '../types/dataGridTypes';
6
+ import type { RowId, UserLike } from '../types/dataGridTypes';
7
7
  export interface HeaderFilterConfigInput {
8
- sortBy: string;
8
+ sortBy?: string;
9
9
  sortDirection: 'asc' | 'desc';
10
10
  onColumnSort: (columnKey: string) => void;
11
11
  textFilters?: Record<string, string>;
@@ -44,7 +44,7 @@ export declare function getHeaderFilterConfig<T>(col: IColumnDef<T>, input: Head
44
44
  export type CellRenderMode = 'editing-inline' | 'editing-popover' | 'display';
45
45
  export interface CellRenderDescriptorInput<T> {
46
46
  editingCell: {
47
- rowId: string;
47
+ rowId: RowId;
48
48
  columnId: string;
49
49
  } | null;
50
50
  activeCell: {
@@ -65,7 +65,7 @@ export interface CellRenderDescriptorInput<T> {
65
65
  } | null;
66
66
  colOffset: number;
67
67
  itemsLength: number;
68
- getRowId: (item: T) => string;
68
+ getRowId: (item: T) => RowId;
69
69
  editable?: boolean;
70
70
  onCellValueChanged?: (event: import('../types/columnTypes').ICellValueChangedEvent<T>) => void;
71
71
  }
@@ -81,7 +81,7 @@ export interface CellRenderDescriptor {
81
81
  isPinned: boolean;
82
82
  pinnedSide?: 'left' | 'right';
83
83
  globalColIndex: number;
84
- rowId: string;
84
+ rowId: RowId;
85
85
  rowIndex: number;
86
86
  /** Raw value for display (when mode === 'display'). UI uses col.renderCell or col.valueFormatter. */
87
87
  displayValue?: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
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",
@@ -16,10 +16,21 @@
16
16
  "build": "rimraf dist && tsc -p tsconfig.build.json",
17
17
  "test": "jest"
18
18
  },
19
- "keywords": ["ogrid", "datatable", "react", "typescript", "grid", "core"],
19
+ "keywords": [
20
+ "ogrid",
21
+ "datatable",
22
+ "react",
23
+ "typescript",
24
+ "grid",
25
+ "core"
26
+ ],
20
27
  "author": "Ala Arab",
21
28
  "license": "MIT",
22
- "files": ["dist", "README.md", "LICENSE"],
29
+ "files": [
30
+ "dist",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
23
34
  "engines": {
24
35
  "node": ">=18"
25
36
  },