gp-grid-react 0.1.6 → 0.2.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.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import React from "react";
1
+ import React$1 from "react";
2
2
 
3
- //#region ../core/src/types.d.ts
3
+ //#region ../core/src/types/basic.d.ts
4
4
  /** Cell data type primitive types */
5
5
  type CellDataType = "text" | "number" | "boolean" | "date" | "dateString" | "dateTime" | "dateTimeString" | "object";
6
6
  /** Cell value type */
7
7
  type CellValue = string | number | boolean | Date | object | null;
8
8
  /** Row type */
9
9
  type Row = unknown;
10
+ /** Row ID type for transaction operations */
11
+ type RowId = string | number;
10
12
  /** Sort direction type */
11
13
  type SortDirection = "asc" | "desc";
12
14
  /** Sort model type */
@@ -14,8 +16,21 @@ type SortModel = {
14
16
  colId: string;
15
17
  direction: SortDirection;
16
18
  };
17
- /** Filter model type */
18
- type FilterModel = Record<string, string>;
19
+ /** Cell position */
20
+ interface CellPosition {
21
+ row: number;
22
+ col: number;
23
+ }
24
+ /** Cell range */
25
+ interface CellRange {
26
+ startRow: number;
27
+ startCol: number;
28
+ endRow: number;
29
+ endCol: number;
30
+ }
31
+ //#endregion
32
+ //#region ../core/src/types/columns.d.ts
33
+ /** Column definition */
19
34
  interface ColumnDefinition {
20
35
  field: string;
21
36
  colId?: string;
@@ -23,21 +38,68 @@ interface ColumnDefinition {
23
38
  width: number;
24
39
  headerName?: string;
25
40
  editable?: boolean;
41
+ /** Whether column is sortable. Default: true when sortingEnabled */
42
+ sortable?: boolean;
43
+ /** Whether column is filterable. Default: true */
44
+ filterable?: boolean;
26
45
  /** Renderer key for adapter lookup, or inline renderer function */
27
46
  cellRenderer?: string;
28
47
  editRenderer?: string;
29
48
  headerRenderer?: string;
30
49
  }
31
- interface CellPosition {
32
- row: number;
33
- col: number;
50
+ //#endregion
51
+ //#region ../core/src/types/filters.d.ts
52
+ /** Text filter operators */
53
+ type TextFilterOperator = "contains" | "notContains" | "equals" | "notEquals" | "startsWith" | "endsWith" | "blank" | "notBlank";
54
+ /** Number filter operators (symbols for display) */
55
+ type NumberFilterOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "between" | "blank" | "notBlank";
56
+ /** Date filter operators */
57
+ type DateFilterOperator = "=" | "!=" | ">" | "<" | "between" | "blank" | "notBlank";
58
+ /** Filter combination mode */
59
+ type FilterCombination = "and" | "or";
60
+ /** Text filter condition */
61
+ interface TextFilterCondition {
62
+ type: "text";
63
+ operator: TextFilterOperator;
64
+ value?: string;
65
+ /** Selected distinct values for checkbox-style filtering */
66
+ selectedValues?: Set<string>;
67
+ /** Include blank values */
68
+ includeBlank?: boolean;
69
+ /** Operator connecting this condition to the next. Defaults to ColumnFilterModel.combination */
70
+ nextOperator?: FilterCombination;
34
71
  }
35
- interface CellRange {
36
- startRow: number;
37
- startCol: number;
38
- endRow: number;
39
- endCol: number;
72
+ /** Number filter condition */
73
+ interface NumberFilterCondition {
74
+ type: "number";
75
+ operator: NumberFilterOperator;
76
+ value?: number;
77
+ /** Second value for "between" operator */
78
+ valueTo?: number;
79
+ /** Operator connecting this condition to the next. Defaults to ColumnFilterModel.combination */
80
+ nextOperator?: FilterCombination;
81
+ }
82
+ /** Date filter condition */
83
+ interface DateFilterCondition {
84
+ type: "date";
85
+ operator: DateFilterOperator;
86
+ value?: Date | string;
87
+ /** Second value for "between" operator */
88
+ valueTo?: Date | string;
89
+ /** Operator connecting this condition to the next. Defaults to ColumnFilterModel.combination */
90
+ nextOperator?: FilterCombination;
40
91
  }
92
+ /** Union of filter condition types */
93
+ type FilterCondition = TextFilterCondition | NumberFilterCondition | DateFilterCondition;
94
+ /** Column filter model with multiple conditions */
95
+ interface ColumnFilterModel {
96
+ conditions: FilterCondition[];
97
+ combination: FilterCombination;
98
+ }
99
+ /** Filter model type - maps column ID to filter */
100
+ type FilterModel = Record<string, ColumnFilterModel>;
101
+ //#endregion
102
+ //#region ../core/src/types/data-source.d.ts
41
103
  /** Data source request */
42
104
  interface DataSourceRequest {
43
105
  /** Pagination */
@@ -59,10 +121,13 @@ interface DataSourceResponse<TData = Row> {
59
121
  /** Total rows */
60
122
  totalRows: number;
61
123
  }
124
+ /** Data source interface */
62
125
  interface DataSource<TData = Row> {
63
126
  fetch(request: DataSourceRequest): Promise<DataSourceResponse<TData>>;
64
127
  }
65
- /** Slot lifecycle instructions */
128
+ //#endregion
129
+ //#region ../core/src/types/instructions.d.ts
130
+ /** Create slot instruction */
66
131
  interface CreateSlotInstruction {
67
132
  type: "CREATE_SLOT";
68
133
  slotId: string;
@@ -85,7 +150,7 @@ interface MoveSlotInstruction {
85
150
  slotId: string;
86
151
  translateY: number;
87
152
  }
88
- /** Selection instructions */
153
+ /** Set active cell instruction */
89
154
  interface SetActiveCellInstruction {
90
155
  type: "SET_ACTIVE_CELL";
91
156
  position: CellPosition | null;
@@ -95,7 +160,13 @@ interface SetSelectionRangeInstruction {
95
160
  type: "SET_SELECTION_RANGE";
96
161
  range: CellRange | null;
97
162
  }
98
- /** Edit instructions */
163
+ /** Update visible range instruction - emitted when selection moves outside visible viewport */
164
+ interface UpdateVisibleRangeInstruction {
165
+ type: "UPDATE_VISIBLE_RANGE";
166
+ start: number;
167
+ end: number;
168
+ }
169
+ /** Start edit instruction */
99
170
  interface StartEditInstruction {
100
171
  type: "START_EDIT";
101
172
  row: number;
@@ -113,7 +184,7 @@ interface CommitEditInstruction {
113
184
  col: number;
114
185
  value: CellValue;
115
186
  }
116
- /** Layout instructions */
187
+ /** Set content size instruction */
117
188
  interface SetContentSizeInstruction {
118
189
  type: "SET_CONTENT_SIZE";
119
190
  width: number;
@@ -126,8 +197,32 @@ interface UpdateHeaderInstruction {
126
197
  column: ColumnDefinition;
127
198
  sortDirection?: SortDirection;
128
199
  sortIndex?: number;
200
+ /** Whether column is sortable */
201
+ sortable: boolean;
202
+ /** Whether column is filterable */
203
+ filterable: boolean;
204
+ /** Whether column has an active filter */
205
+ hasFilter: boolean;
129
206
  }
130
- /** Fill handle instructions */
207
+ /** Open filter popup instruction */
208
+ interface OpenFilterPopupInstruction {
209
+ type: "OPEN_FILTER_POPUP";
210
+ colIndex: number;
211
+ column: ColumnDefinition;
212
+ anchorRect: {
213
+ top: number;
214
+ left: number;
215
+ width: number;
216
+ height: number;
217
+ };
218
+ distinctValues: CellValue[];
219
+ currentFilter?: ColumnFilterModel;
220
+ }
221
+ /** Close filter popup instruction */
222
+ interface CloseFilterPopupInstruction {
223
+ type: "CLOSE_FILTER_POPUP";
224
+ }
225
+ /** Start fill instruction */
131
226
  interface StartFillInstruction {
132
227
  type: "START_FILL";
133
228
  sourceRange: CellRange;
@@ -165,14 +260,42 @@ interface DataErrorInstruction {
165
260
  type: "DATA_ERROR";
166
261
  error: string;
167
262
  }
263
+ /** Rows added instruction */
264
+ interface RowsAddedInstruction {
265
+ type: "ROWS_ADDED";
266
+ count: number;
267
+ totalRows: number;
268
+ }
269
+ /** Rows removed instruction */
270
+ interface RowsRemovedInstruction {
271
+ type: "ROWS_REMOVED";
272
+ count: number;
273
+ totalRows: number;
274
+ }
275
+ /** Rows updated instruction */
276
+ interface RowsUpdatedInstruction {
277
+ type: "ROWS_UPDATED";
278
+ count: number;
279
+ }
280
+ /** Transaction processed instruction */
281
+ interface TransactionProcessedInstruction {
282
+ type: "TRANSACTION_PROCESSED";
283
+ added: number;
284
+ removed: number;
285
+ updated: number;
286
+ }
168
287
  /** Union type of all instructions */
169
288
  type GridInstruction = /** Slot lifecycle */
170
289
  CreateSlotInstruction | DestroySlotInstruction | AssignSlotInstruction | MoveSlotInstruction
171
- /** Selection */ | SetActiveCellInstruction | SetSelectionRangeInstruction
290
+ /** Selection */ | SetActiveCellInstruction | SetSelectionRangeInstruction | UpdateVisibleRangeInstruction
172
291
  /** Editing */ | StartEditInstruction | StopEditInstruction | CommitEditInstruction
173
292
  /** Layout */ | SetContentSizeInstruction | UpdateHeaderInstruction
293
+ /** Filter popup */ | OpenFilterPopupInstruction | CloseFilterPopupInstruction
174
294
  /** Fill handle */ | StartFillInstruction | UpdateFillInstruction | CommitFillInstruction | CancelFillInstruction
175
- /** Data */ | DataLoadingInstruction | DataLoadedInstruction | DataErrorInstruction;
295
+ /** Data */ | DataLoadingInstruction | DataLoadedInstruction | DataErrorInstruction
296
+ /** Transactions */ | RowsAddedInstruction | RowsRemovedInstruction | RowsUpdatedInstruction | TransactionProcessedInstruction;
297
+ //#endregion
298
+ //#region ../core/src/types/renderers.d.ts
176
299
  /** Cell renderer params */
177
300
  interface CellRendererParams {
178
301
  /** Cell value */
@@ -213,35 +336,98 @@ interface HeaderRendererParams {
213
336
  sortDirection?: SortDirection;
214
337
  /** Sort index */
215
338
  sortIndex?: number;
339
+ /** Whether column is sortable */
340
+ sortable: boolean;
341
+ /** Whether column is filterable */
342
+ filterable: boolean;
343
+ /** Whether column has an active filter */
344
+ hasFilter: boolean;
216
345
  /** On sort */
217
346
  onSort: (direction: SortDirection | null, addToExisting: boolean) => void;
347
+ /** On filter click */
348
+ onFilterClick: () => void;
218
349
  }
219
350
  //#endregion
220
- //#region ../core/src/data-source.d.ts
221
- /**
222
- * Creates a client-side data source that holds all data in memory.
223
- * Sorting and filtering are performed client-side.
224
- * For large datasets (10k+ rows), sorting is automatically offloaded to a Web Worker.
225
- */
226
- declare function createClientDataSource<TData extends Row = Row>(data: TData[], options?: {
351
+ //#region ../core/src/data-source/client-data-source.d.ts
352
+ interface ClientDataSourceOptions<TData> {
227
353
  /** Custom field accessor for nested properties */
228
354
  getFieldValue?: (row: TData, field: string) => CellValue;
229
355
  /** Use Web Worker for sorting large datasets (default: true) */
230
356
  useWorker?: boolean;
231
- }): DataSource<TData>;
357
+ }
358
+ /**
359
+ * Creates a client-side data source that holds all data in memory.
360
+ * Sorting and filtering are performed client-side.
361
+ * For large datasets, sorting is automatically offloaded to a Web Worker.
362
+ */
363
+ declare function createClientDataSource<TData extends Row = Row>(data: TData[], options?: ClientDataSourceOptions<TData>): DataSource<TData>;
364
+ /**
365
+ * Convenience function to create a data source from an array.
366
+ * This provides backwards compatibility with the old `rowData` prop.
367
+ */
368
+ declare function createDataSourceFromArray<TData extends Row = Row>(data: TData[]): DataSource<TData>;
369
+ //#endregion
370
+ //#region ../core/src/data-source/server-data-source.d.ts
232
371
  type ServerFetchFunction<TData> = (request: DataSourceRequest) => Promise<DataSourceResponse<TData>>;
233
372
  /**
234
373
  * Creates a server-side data source that delegates all operations to the server.
235
374
  * The fetch function receives sort/filter/pagination params to pass to the API.
236
375
  */
237
376
  declare function createServerDataSource<TData extends Row = Row>(fetchFn: ServerFetchFunction<TData>): DataSource<TData>;
377
+ //#endregion
378
+ //#region ../core/src/transaction-manager.d.ts
379
+ interface TransactionResult {
380
+ added: number;
381
+ removed: number;
382
+ updated: number;
383
+ }
384
+ //#endregion
385
+ //#region ../core/src/data-source/mutable-data-source.d.ts
386
+ /** Callback for data change notifications */
387
+ type DataChangeListener = (result: TransactionResult) => void;
238
388
  /**
239
- * Convenience function to create a data source from an array.
240
- * This provides backwards compatibility with the old `rowData` prop.
389
+ * Data source with mutation capabilities.
390
+ * Extends DataSource with add, remove, and update operations.
241
391
  */
242
- declare function createDataSourceFromArray<TData extends Row = Row>(data: TData[]): DataSource<TData>;
392
+ interface MutableDataSource<TData = Row> extends DataSource<TData> {
393
+ /** Add rows to the data source. Queued and processed after debounce. */
394
+ addRows(rows: TData[]): void;
395
+ /** Remove rows by ID. Queued and processed after debounce. */
396
+ removeRows(ids: RowId[]): void;
397
+ /** Update a cell value. Queued and processed after debounce. */
398
+ updateCell(id: RowId, field: string, value: CellValue): void;
399
+ /** Update multiple fields on a row. Queued and processed after debounce. */
400
+ updateRow(id: RowId, data: Partial<TData>): void;
401
+ /** Force immediate processing of queued transactions. */
402
+ flushTransactions(): Promise<void>;
403
+ /** Check if there are pending transactions. */
404
+ hasPendingTransactions(): boolean;
405
+ /** Get distinct values for a field (for filter UI). */
406
+ getDistinctValues(field: string): CellValue[];
407
+ /** Get a row by ID. */
408
+ getRowById(id: RowId): TData | undefined;
409
+ /** Get total row count. */
410
+ getTotalRowCount(): number;
411
+ /** Subscribe to data change notifications. Returns unsubscribe function. */
412
+ subscribe(listener: DataChangeListener): () => void;
413
+ }
414
+ interface MutableClientDataSourceOptions<TData> {
415
+ /** Function to extract unique ID from row. Required. */
416
+ getRowId: (row: TData) => RowId;
417
+ /** Custom field accessor for nested properties. */
418
+ getFieldValue?: (row: TData, field: string) => CellValue;
419
+ /** Debounce time for transactions in ms. Default 50. Set to 0 for sync. */
420
+ debounceMs?: number;
421
+ /** Callback when transactions are processed. */
422
+ onTransactionProcessed?: (result: TransactionResult) => void;
423
+ }
424
+ /**
425
+ * Creates a mutable client-side data source with transaction support.
426
+ * Uses IndexedDataStore for efficient incremental operations.
427
+ */
428
+ declare function createMutableClientDataSource<TData extends Row = Row>(data: TData[], options: MutableClientDataSourceOptions<TData>): MutableDataSource<TData>;
243
429
  //#endregion
244
- //#region src/Grid.d.ts
430
+ //#region src/types.d.ts
245
431
  /** React cell renderer: A function that renders a cell */
246
432
  type ReactCellRenderer = (params: CellRendererParams) => React.ReactNode;
247
433
  /** React edit renderer: A function that renders the cell while in edit mode */
@@ -262,10 +448,8 @@ interface GridProps<TData extends Row = Row> {
262
448
  headerHeight?: number;
263
449
  /** Overscan: How many rows to render outside the viewport */
264
450
  overscan?: number;
265
- /** Show filter row below headers: Default to false */
266
- showFilters?: boolean;
267
- /** Debounce time for filter input (ms): Default to 300 */
268
- filterDebounce?: number;
451
+ /** Enable/disable sorting globally. Default: true */
452
+ sortingEnabled?: boolean;
269
453
  /** Enable dark mode styling: Default to false */
270
454
  darkMode?: boolean;
271
455
  /** Wheel scroll dampening factor when virtual scrolling is active (0-1): Default 0.1 */
@@ -283,12 +467,13 @@ interface GridProps<TData extends Row = Row> {
283
467
  /** Global header renderer */
284
468
  headerRenderer?: ReactHeaderRenderer;
285
469
  }
470
+ //#endregion
471
+ //#region src/Grid.d.ts
286
472
  /**
287
473
  * Grid component
288
474
  * @param props - Grid component props
289
475
  * @returns Grid React component
290
476
  */
291
- declare function Grid<TData extends Row = Row>(props: GridProps<TData>): React.ReactNode;
477
+ declare function Grid<TData extends Row = Row>(props: GridProps<TData>): React$1.ReactNode;
292
478
  //#endregion
293
- export { type CellDataType, type CellPosition, type CellRange, type CellRendererParams, type CellValue, type ColumnDefinition, type DataSource, type DataSourceRequest, type DataSourceResponse, type EditRendererParams, type FilterModel, Grid, type GridInstruction, type GridProps, type HeaderRendererParams, type ReactCellRenderer, type ReactEditRenderer, type ReactHeaderRenderer, type Row, type SortDirection, type SortModel, createClientDataSource, createDataSourceFromArray, createServerDataSource };
294
- //# sourceMappingURL=index.d.ts.map
479
+ export { type CellDataType, type CellPosition, type CellRange, type CellRendererParams, type CellValue, type ColumnDefinition, type DataSource, type DataSourceRequest, type DataSourceResponse, type EditRendererParams, type FilterModel, Grid, type GridInstruction, type GridProps, type HeaderRendererParams, type MutableDataSource, type ReactCellRenderer, type ReactEditRenderer, type ReactHeaderRenderer, type Row, type SortDirection, type SortModel, createClientDataSource, createDataSourceFromArray, createMutableClientDataSource, createServerDataSource };