gp-grid-react 0.1.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 +211 -0
- package/dist/index.js +1169 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -0
- package/src/Grid.tsx +1220 -0
- package/src/SlotRow.tsx +258 -0
- package/src/index.ts +47 -0
- package/src/styles.ts +436 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +11 -0
- package/vitest.config.ts +16 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region ../core/src/types.d.ts
|
|
5
|
+
type CellDataType = "text" | "number" | "boolean" | "date" | "dateString" | "dateTime" | "dateTimeString" | "object";
|
|
6
|
+
type CellValue = string | number | boolean | Date | object | null;
|
|
7
|
+
type Row = unknown;
|
|
8
|
+
type SortDirection = "asc" | "desc";
|
|
9
|
+
type SortModel = {
|
|
10
|
+
colId: string;
|
|
11
|
+
direction: SortDirection;
|
|
12
|
+
};
|
|
13
|
+
type FilterModel = Record<string, string>;
|
|
14
|
+
interface ColumnDefinition {
|
|
15
|
+
field: string;
|
|
16
|
+
colId?: string;
|
|
17
|
+
cellDataType: CellDataType;
|
|
18
|
+
width: number;
|
|
19
|
+
headerName?: string;
|
|
20
|
+
editable?: boolean;
|
|
21
|
+
/** Renderer key for adapter lookup, or inline renderer function */
|
|
22
|
+
cellRenderer?: string;
|
|
23
|
+
editRenderer?: string;
|
|
24
|
+
headerRenderer?: string;
|
|
25
|
+
}
|
|
26
|
+
interface CellPosition {
|
|
27
|
+
row: number;
|
|
28
|
+
col: number;
|
|
29
|
+
}
|
|
30
|
+
interface CellRange {
|
|
31
|
+
startRow: number;
|
|
32
|
+
startCol: number;
|
|
33
|
+
endRow: number;
|
|
34
|
+
endCol: number;
|
|
35
|
+
}
|
|
36
|
+
interface DataSourceRequest {
|
|
37
|
+
pagination: {
|
|
38
|
+
pageIndex: number;
|
|
39
|
+
pageSize: number;
|
|
40
|
+
};
|
|
41
|
+
sort?: SortModel[];
|
|
42
|
+
filter?: FilterModel;
|
|
43
|
+
}
|
|
44
|
+
interface DataSourceResponse<TData = Row> {
|
|
45
|
+
rows: TData[];
|
|
46
|
+
totalRows: number;
|
|
47
|
+
}
|
|
48
|
+
interface DataSource<TData = Row> {
|
|
49
|
+
fetch(request: DataSourceRequest): Promise<DataSourceResponse<TData>>;
|
|
50
|
+
}
|
|
51
|
+
interface CreateSlotInstruction {
|
|
52
|
+
type: "CREATE_SLOT";
|
|
53
|
+
slotId: string;
|
|
54
|
+
}
|
|
55
|
+
interface DestroySlotInstruction {
|
|
56
|
+
type: "DESTROY_SLOT";
|
|
57
|
+
slotId: string;
|
|
58
|
+
}
|
|
59
|
+
interface AssignSlotInstruction {
|
|
60
|
+
type: "ASSIGN_SLOT";
|
|
61
|
+
slotId: string;
|
|
62
|
+
rowIndex: number;
|
|
63
|
+
rowData: Row;
|
|
64
|
+
}
|
|
65
|
+
interface MoveSlotInstruction {
|
|
66
|
+
type: "MOVE_SLOT";
|
|
67
|
+
slotId: string;
|
|
68
|
+
translateY: number;
|
|
69
|
+
}
|
|
70
|
+
interface SetActiveCellInstruction {
|
|
71
|
+
type: "SET_ACTIVE_CELL";
|
|
72
|
+
position: CellPosition | null;
|
|
73
|
+
}
|
|
74
|
+
interface SetSelectionRangeInstruction {
|
|
75
|
+
type: "SET_SELECTION_RANGE";
|
|
76
|
+
range: CellRange | null;
|
|
77
|
+
}
|
|
78
|
+
interface StartEditInstruction {
|
|
79
|
+
type: "START_EDIT";
|
|
80
|
+
row: number;
|
|
81
|
+
col: number;
|
|
82
|
+
initialValue: CellValue;
|
|
83
|
+
}
|
|
84
|
+
interface StopEditInstruction {
|
|
85
|
+
type: "STOP_EDIT";
|
|
86
|
+
}
|
|
87
|
+
interface CommitEditInstruction {
|
|
88
|
+
type: "COMMIT_EDIT";
|
|
89
|
+
row: number;
|
|
90
|
+
col: number;
|
|
91
|
+
value: CellValue;
|
|
92
|
+
}
|
|
93
|
+
interface SetContentSizeInstruction {
|
|
94
|
+
type: "SET_CONTENT_SIZE";
|
|
95
|
+
width: number;
|
|
96
|
+
height: number;
|
|
97
|
+
}
|
|
98
|
+
interface UpdateHeaderInstruction {
|
|
99
|
+
type: "UPDATE_HEADER";
|
|
100
|
+
colIndex: number;
|
|
101
|
+
column: ColumnDefinition;
|
|
102
|
+
sortDirection?: SortDirection;
|
|
103
|
+
sortIndex?: number;
|
|
104
|
+
}
|
|
105
|
+
interface StartFillInstruction {
|
|
106
|
+
type: "START_FILL";
|
|
107
|
+
sourceRange: CellRange;
|
|
108
|
+
}
|
|
109
|
+
interface UpdateFillInstruction {
|
|
110
|
+
type: "UPDATE_FILL";
|
|
111
|
+
targetRow: number;
|
|
112
|
+
targetCol: number;
|
|
113
|
+
}
|
|
114
|
+
interface CommitFillInstruction {
|
|
115
|
+
type: "COMMIT_FILL";
|
|
116
|
+
filledCells: Array<{
|
|
117
|
+
row: number;
|
|
118
|
+
col: number;
|
|
119
|
+
value: CellValue;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
interface CancelFillInstruction {
|
|
123
|
+
type: "CANCEL_FILL";
|
|
124
|
+
}
|
|
125
|
+
interface DataLoadingInstruction {
|
|
126
|
+
type: "DATA_LOADING";
|
|
127
|
+
}
|
|
128
|
+
interface DataLoadedInstruction {
|
|
129
|
+
type: "DATA_LOADED";
|
|
130
|
+
totalRows: number;
|
|
131
|
+
}
|
|
132
|
+
interface DataErrorInstruction {
|
|
133
|
+
type: "DATA_ERROR";
|
|
134
|
+
error: string;
|
|
135
|
+
}
|
|
136
|
+
type GridInstruction = CreateSlotInstruction | DestroySlotInstruction | AssignSlotInstruction | MoveSlotInstruction | SetActiveCellInstruction | SetSelectionRangeInstruction | StartEditInstruction | StopEditInstruction | CommitEditInstruction | SetContentSizeInstruction | UpdateHeaderInstruction | StartFillInstruction | UpdateFillInstruction | CommitFillInstruction | CancelFillInstruction | DataLoadingInstruction | DataLoadedInstruction | DataErrorInstruction;
|
|
137
|
+
interface CellRendererParams {
|
|
138
|
+
value: CellValue;
|
|
139
|
+
rowData: Row;
|
|
140
|
+
column: ColumnDefinition;
|
|
141
|
+
rowIndex: number;
|
|
142
|
+
colIndex: number;
|
|
143
|
+
isActive: boolean;
|
|
144
|
+
isSelected: boolean;
|
|
145
|
+
isEditing: boolean;
|
|
146
|
+
}
|
|
147
|
+
interface EditRendererParams extends CellRendererParams {
|
|
148
|
+
initialValue: CellValue;
|
|
149
|
+
onValueChange: (newValue: CellValue) => void;
|
|
150
|
+
onCommit: () => void;
|
|
151
|
+
onCancel: () => void;
|
|
152
|
+
}
|
|
153
|
+
interface HeaderRendererParams {
|
|
154
|
+
column: ColumnDefinition;
|
|
155
|
+
colIndex: number;
|
|
156
|
+
sortDirection?: SortDirection;
|
|
157
|
+
sortIndex?: number;
|
|
158
|
+
onSort: (direction: SortDirection | null, addToExisting: boolean) => void;
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region ../core/src/data-source.d.ts
|
|
162
|
+
/**
|
|
163
|
+
* Creates a client-side data source that holds all data in memory.
|
|
164
|
+
* Sorting and filtering are performed client-side.
|
|
165
|
+
*/
|
|
166
|
+
declare function createClientDataSource<TData extends Row = Row>(data: TData[], options?: {
|
|
167
|
+
/** Custom field accessor for nested properties */
|
|
168
|
+
getFieldValue?: (row: TData, field: string) => CellValue;
|
|
169
|
+
}): DataSource<TData>;
|
|
170
|
+
type ServerFetchFunction<TData> = (request: DataSourceRequest) => Promise<DataSourceResponse<TData>>;
|
|
171
|
+
/**
|
|
172
|
+
* Creates a server-side data source that delegates all operations to the server.
|
|
173
|
+
* The fetch function receives sort/filter/pagination params to pass to the API.
|
|
174
|
+
*/
|
|
175
|
+
declare function createServerDataSource<TData extends Row = Row>(fetchFn: ServerFetchFunction<TData>): DataSource<TData>;
|
|
176
|
+
/**
|
|
177
|
+
* Convenience function to create a data source from an array.
|
|
178
|
+
* This provides backwards compatibility with the old `rowData` prop.
|
|
179
|
+
*/
|
|
180
|
+
declare function createDataSourceFromArray<TData extends Row = Row>(data: TData[]): DataSource<TData>;
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/Grid.d.ts
|
|
183
|
+
type ReactCellRenderer = (params: CellRendererParams) => React.ReactNode;
|
|
184
|
+
type ReactEditRenderer = (params: EditRendererParams) => React.ReactNode;
|
|
185
|
+
type ReactHeaderRenderer = (params: HeaderRendererParams) => React.ReactNode;
|
|
186
|
+
interface GridProps<TData extends Row = Row> {
|
|
187
|
+
columns: ColumnDefinition[];
|
|
188
|
+
/** Data source for the grid */
|
|
189
|
+
dataSource?: DataSource<TData>;
|
|
190
|
+
/** Legacy: Raw row data (will be wrapped in a client data source) */
|
|
191
|
+
rowData?: TData[];
|
|
192
|
+
rowHeight: number;
|
|
193
|
+
headerHeight?: number;
|
|
194
|
+
overscan?: number;
|
|
195
|
+
/** Show filter row below headers */
|
|
196
|
+
showFilters?: boolean;
|
|
197
|
+
/** Debounce time for filter input (ms) */
|
|
198
|
+
filterDebounce?: number;
|
|
199
|
+
/** Enable dark mode styling */
|
|
200
|
+
darkMode?: boolean;
|
|
201
|
+
cellRenderers?: Record<string, ReactCellRenderer>;
|
|
202
|
+
editRenderers?: Record<string, ReactEditRenderer>;
|
|
203
|
+
headerRenderers?: Record<string, ReactHeaderRenderer>;
|
|
204
|
+
cellRenderer?: ReactCellRenderer;
|
|
205
|
+
editRenderer?: ReactEditRenderer;
|
|
206
|
+
headerRenderer?: ReactHeaderRenderer;
|
|
207
|
+
}
|
|
208
|
+
declare function Grid<TData extends Row = Row>(props: GridProps<TData>): react_jsx_runtime0.JSX.Element;
|
|
209
|
+
//#endregion
|
|
210
|
+
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 };
|
|
211
|
+
//# sourceMappingURL=index.d.ts.map
|