gp-grid-react 0.1.3 → 0.1.5
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/LICENSE +203 -0
- package/README.md +593 -520
- package/dist/index.d.ts +89 -6
- package/dist/index.js +35 -15
- package/dist/index.js.map +1 -1
- package/package.json +26 -10
- package/src/Grid.tsx +0 -1334
- package/src/SlotRow.tsx +0 -258
- package/src/index.ts +0 -47
- package/src/styles.ts +0 -440
- package/tsconfig.json +0 -29
- package/tsdown.config.ts +0 -11
- package/vitest.config.ts +0 -16
package/src/SlotRow.tsx
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
// packages/react/src/SlotRow.tsx
|
|
2
|
-
|
|
3
|
-
import React, { memo, useCallback } from "react";
|
|
4
|
-
import type {
|
|
5
|
-
ColumnDefinition,
|
|
6
|
-
Row,
|
|
7
|
-
CellValue,
|
|
8
|
-
CellRendererParams,
|
|
9
|
-
EditRendererParams,
|
|
10
|
-
} from "gp-grid-core";
|
|
11
|
-
|
|
12
|
-
// =============================================================================
|
|
13
|
-
// Types
|
|
14
|
-
// =============================================================================
|
|
15
|
-
|
|
16
|
-
export type ReactCellRenderer = (params: CellRendererParams) => React.ReactNode;
|
|
17
|
-
export type ReactEditRenderer = (params: EditRendererParams) => React.ReactNode;
|
|
18
|
-
|
|
19
|
-
export interface SlotRowProps {
|
|
20
|
-
slotId: string;
|
|
21
|
-
rowIndex: number;
|
|
22
|
-
rowData: Row;
|
|
23
|
-
translateY: number;
|
|
24
|
-
columns: ColumnDefinition[];
|
|
25
|
-
columnPositions: number[];
|
|
26
|
-
rowHeight: number;
|
|
27
|
-
contentWidth: number;
|
|
28
|
-
|
|
29
|
-
// Selection state
|
|
30
|
-
activeCell: { row: number; col: number } | null;
|
|
31
|
-
selectionRange: { startRow: number; startCol: number; endRow: number; endCol: number } | null;
|
|
32
|
-
editingCell: { row: number; col: number; initialValue: CellValue } | null;
|
|
33
|
-
|
|
34
|
-
// Renderers
|
|
35
|
-
cellRenderers: Record<string, ReactCellRenderer>;
|
|
36
|
-
editRenderers: Record<string, ReactEditRenderer>;
|
|
37
|
-
cellRenderer?: ReactCellRenderer;
|
|
38
|
-
editRenderer?: ReactEditRenderer;
|
|
39
|
-
|
|
40
|
-
// Callbacks
|
|
41
|
-
onCellClick: (rowIndex: number, colIndex: number, e: React.MouseEvent) => void;
|
|
42
|
-
onCellDoubleClick: (rowIndex: number, colIndex: number) => void;
|
|
43
|
-
onEditValueChange: (value: CellValue) => void;
|
|
44
|
-
onEditCommit: () => void;
|
|
45
|
-
onEditCancel: () => void;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// =============================================================================
|
|
49
|
-
// Helper Functions
|
|
50
|
-
// =============================================================================
|
|
51
|
-
|
|
52
|
-
function getCellValue(rowData: Row, field: string): CellValue {
|
|
53
|
-
const parts = field.split(".");
|
|
54
|
-
let value: unknown = rowData;
|
|
55
|
-
|
|
56
|
-
for (const part of parts) {
|
|
57
|
-
if (value == null || typeof value !== "object") {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
value = (value as Record<string, unknown>)[part];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return (value ?? null) as CellValue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function isInRange(
|
|
67
|
-
row: number,
|
|
68
|
-
col: number,
|
|
69
|
-
range: { startRow: number; startCol: number; endRow: number; endCol: number } | null
|
|
70
|
-
): boolean {
|
|
71
|
-
if (!range) return false;
|
|
72
|
-
|
|
73
|
-
const minRow = Math.min(range.startRow, range.endRow);
|
|
74
|
-
const maxRow = Math.max(range.startRow, range.endRow);
|
|
75
|
-
const minCol = Math.min(range.startCol, range.endCol);
|
|
76
|
-
const maxCol = Math.max(range.startCol, range.endCol);
|
|
77
|
-
|
|
78
|
-
return row >= minRow && row <= maxRow && col >= minCol && col <= maxCol;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// =============================================================================
|
|
82
|
-
// SlotRow Component
|
|
83
|
-
// =============================================================================
|
|
84
|
-
|
|
85
|
-
export const SlotRow = memo(function SlotRow(props: SlotRowProps) {
|
|
86
|
-
const {
|
|
87
|
-
slotId,
|
|
88
|
-
rowIndex,
|
|
89
|
-
rowData,
|
|
90
|
-
translateY,
|
|
91
|
-
columns,
|
|
92
|
-
columnPositions,
|
|
93
|
-
rowHeight,
|
|
94
|
-
contentWidth,
|
|
95
|
-
activeCell,
|
|
96
|
-
selectionRange,
|
|
97
|
-
editingCell,
|
|
98
|
-
cellRenderers,
|
|
99
|
-
editRenderers,
|
|
100
|
-
cellRenderer,
|
|
101
|
-
editRenderer,
|
|
102
|
-
onCellClick,
|
|
103
|
-
onCellDoubleClick,
|
|
104
|
-
onEditValueChange,
|
|
105
|
-
onEditCommit,
|
|
106
|
-
onEditCancel,
|
|
107
|
-
} = props;
|
|
108
|
-
|
|
109
|
-
const renderCellContent = useCallback(
|
|
110
|
-
(column: ColumnDefinition, colIndex: number): React.ReactNode => {
|
|
111
|
-
const value = getCellValue(rowData, column.field);
|
|
112
|
-
const isActive = activeCell?.row === rowIndex && activeCell?.col === colIndex;
|
|
113
|
-
const isSelected = isInRange(rowIndex, colIndex, selectionRange);
|
|
114
|
-
const isEditing = editingCell?.row === rowIndex && editingCell?.col === colIndex;
|
|
115
|
-
|
|
116
|
-
// Editing mode
|
|
117
|
-
if (isEditing && editingCell) {
|
|
118
|
-
const params: EditRendererParams = {
|
|
119
|
-
value,
|
|
120
|
-
rowData,
|
|
121
|
-
column,
|
|
122
|
-
rowIndex,
|
|
123
|
-
colIndex,
|
|
124
|
-
isActive: true,
|
|
125
|
-
isSelected: true,
|
|
126
|
-
isEditing: true,
|
|
127
|
-
initialValue: editingCell.initialValue,
|
|
128
|
-
onValueChange: onEditValueChange,
|
|
129
|
-
onCommit: onEditCommit,
|
|
130
|
-
onCancel: onEditCancel,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// Check for column-specific edit renderer
|
|
134
|
-
if (column.editRenderer && typeof column.editRenderer === "string") {
|
|
135
|
-
const renderer = editRenderers[column.editRenderer];
|
|
136
|
-
if (renderer) {
|
|
137
|
-
return renderer(params);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Fall back to global edit renderer
|
|
142
|
-
if (editRenderer) {
|
|
143
|
-
return editRenderer(params);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Default input
|
|
147
|
-
return (
|
|
148
|
-
<input
|
|
149
|
-
className="gp-grid-edit-input"
|
|
150
|
-
type="text"
|
|
151
|
-
defaultValue={editingCell.initialValue == null ? "" : String(editingCell.initialValue)}
|
|
152
|
-
autoFocus
|
|
153
|
-
style={{ width: "100%", height: "100%", border: "none", outline: "none" }}
|
|
154
|
-
onChange={(e) => onEditValueChange(e.target.value)}
|
|
155
|
-
onKeyDown={(e) => {
|
|
156
|
-
if (e.key === "Enter") {
|
|
157
|
-
onEditCommit();
|
|
158
|
-
} else if (e.key === "Escape") {
|
|
159
|
-
onEditCancel();
|
|
160
|
-
}
|
|
161
|
-
}}
|
|
162
|
-
onBlur={onEditCommit}
|
|
163
|
-
/>
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Normal display mode
|
|
168
|
-
const params: CellRendererParams = {
|
|
169
|
-
value,
|
|
170
|
-
rowData,
|
|
171
|
-
column,
|
|
172
|
-
rowIndex,
|
|
173
|
-
colIndex,
|
|
174
|
-
isActive,
|
|
175
|
-
isSelected,
|
|
176
|
-
isEditing: false,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// Check for column-specific renderer
|
|
180
|
-
if (column.cellRenderer && typeof column.cellRenderer === "string") {
|
|
181
|
-
const renderer = cellRenderers[column.cellRenderer];
|
|
182
|
-
if (renderer) {
|
|
183
|
-
return renderer(params);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Fall back to global renderer
|
|
188
|
-
if (cellRenderer) {
|
|
189
|
-
return cellRenderer(params);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Default text rendering
|
|
193
|
-
return value == null ? "" : String(value);
|
|
194
|
-
},
|
|
195
|
-
[
|
|
196
|
-
rowData,
|
|
197
|
-
rowIndex,
|
|
198
|
-
activeCell,
|
|
199
|
-
selectionRange,
|
|
200
|
-
editingCell,
|
|
201
|
-
cellRenderers,
|
|
202
|
-
editRenderers,
|
|
203
|
-
cellRenderer,
|
|
204
|
-
editRenderer,
|
|
205
|
-
onEditValueChange,
|
|
206
|
-
onEditCommit,
|
|
207
|
-
onEditCancel,
|
|
208
|
-
]
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
return (
|
|
212
|
-
<div
|
|
213
|
-
data-slot-id={slotId}
|
|
214
|
-
style={{
|
|
215
|
-
position: "absolute",
|
|
216
|
-
top: 0,
|
|
217
|
-
left: 0,
|
|
218
|
-
transform: `translateY(${translateY}px)`,
|
|
219
|
-
width: contentWidth,
|
|
220
|
-
height: rowHeight,
|
|
221
|
-
display: "flex",
|
|
222
|
-
}}
|
|
223
|
-
>
|
|
224
|
-
{columns.map((column, colIndex) => {
|
|
225
|
-
const isActive = activeCell?.row === rowIndex && activeCell?.col === colIndex;
|
|
226
|
-
const isSelected = isInRange(rowIndex, colIndex, selectionRange);
|
|
227
|
-
const isEditing = editingCell?.row === rowIndex && editingCell?.col === colIndex;
|
|
228
|
-
|
|
229
|
-
const cellClasses = [
|
|
230
|
-
"gp-grid-cell",
|
|
231
|
-
isActive && "gp-grid-cell--active",
|
|
232
|
-
isSelected && "gp-grid-cell--selected",
|
|
233
|
-
isEditing && "gp-grid-cell--editing",
|
|
234
|
-
]
|
|
235
|
-
.filter(Boolean)
|
|
236
|
-
.join(" ");
|
|
237
|
-
|
|
238
|
-
return (
|
|
239
|
-
<div
|
|
240
|
-
key={`${slotId}-${colIndex}`}
|
|
241
|
-
className={cellClasses}
|
|
242
|
-
style={{
|
|
243
|
-
position: "absolute",
|
|
244
|
-
left: columnPositions[colIndex],
|
|
245
|
-
width: column.width,
|
|
246
|
-
height: rowHeight,
|
|
247
|
-
}}
|
|
248
|
-
onClick={(e) => onCellClick(rowIndex, colIndex, e)}
|
|
249
|
-
onDoubleClick={() => onCellDoubleClick(rowIndex, colIndex)}
|
|
250
|
-
>
|
|
251
|
-
{renderCellContent(column, colIndex)}
|
|
252
|
-
</div>
|
|
253
|
-
);
|
|
254
|
-
})}
|
|
255
|
-
</div>
|
|
256
|
-
);
|
|
257
|
-
});
|
|
258
|
-
|
package/src/index.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// packages/react/src/index.ts
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
Grid,
|
|
5
|
-
type GridProps,
|
|
6
|
-
type ReactCellRenderer,
|
|
7
|
-
type ReactEditRenderer,
|
|
8
|
-
type ReactHeaderRenderer,
|
|
9
|
-
} from "./Grid";
|
|
10
|
-
|
|
11
|
-
// Re-export core types for convenience
|
|
12
|
-
export type {
|
|
13
|
-
// Basic types
|
|
14
|
-
CellDataType,
|
|
15
|
-
CellValue,
|
|
16
|
-
Row,
|
|
17
|
-
SortDirection,
|
|
18
|
-
SortModel,
|
|
19
|
-
FilterModel,
|
|
20
|
-
|
|
21
|
-
// Column definition
|
|
22
|
-
ColumnDefinition,
|
|
23
|
-
|
|
24
|
-
// Cell position & range
|
|
25
|
-
CellPosition,
|
|
26
|
-
CellRange,
|
|
27
|
-
|
|
28
|
-
// DataSource
|
|
29
|
-
DataSource,
|
|
30
|
-
DataSourceRequest,
|
|
31
|
-
DataSourceResponse,
|
|
32
|
-
|
|
33
|
-
// Renderer params
|
|
34
|
-
CellRendererParams,
|
|
35
|
-
EditRendererParams,
|
|
36
|
-
HeaderRendererParams,
|
|
37
|
-
|
|
38
|
-
// Instructions (for advanced use cases)
|
|
39
|
-
GridInstruction,
|
|
40
|
-
} from "gp-grid-core";
|
|
41
|
-
|
|
42
|
-
// Re-export data source factories
|
|
43
|
-
export {
|
|
44
|
-
createClientDataSource,
|
|
45
|
-
createServerDataSource,
|
|
46
|
-
createDataSourceFromArray,
|
|
47
|
-
} from "gp-grid-core";
|