@skygraph/react 0.0.0-placeholder.0 → 0.4.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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Table-BqN2u5ma.d.cts +1015 -0
  3. package/dist/Table-IvijKCyd.d.ts +1015 -0
  4. package/dist/chunk-2OCEO636.js +91 -0
  5. package/dist/chunk-2OCEO636.js.map +1 -0
  6. package/dist/chunk-6SHHUUAE.js +1667 -0
  7. package/dist/chunk-6SHHUUAE.js.map +1 -0
  8. package/dist/chunk-BNMJSYI2.js +54 -0
  9. package/dist/chunk-BNMJSYI2.js.map +1 -0
  10. package/dist/chunk-DRBAZI46.js +57 -0
  11. package/dist/chunk-DRBAZI46.js.map +1 -0
  12. package/dist/chunk-GJDDPZH7.js +226 -0
  13. package/dist/chunk-GJDDPZH7.js.map +1 -0
  14. package/dist/chunk-KCFWFDSP.js +847 -0
  15. package/dist/chunk-KCFWFDSP.js.map +1 -0
  16. package/dist/chunk-MJAEAFPN.js +3791 -0
  17. package/dist/chunk-MJAEAFPN.js.map +1 -0
  18. package/dist/chunk-MLEBVELO.js +1412 -0
  19. package/dist/chunk-MLEBVELO.js.map +1 -0
  20. package/dist/chunk-SEQI65CF.js +61 -0
  21. package/dist/chunk-SEQI65CF.js.map +1 -0
  22. package/dist/chunk-ZJF6SJLP.js +200 -0
  23. package/dist/chunk-ZJF6SJLP.js.map +1 -0
  24. package/dist/common-CdpocIEz.d.cts +27 -0
  25. package/dist/common-CdpocIEz.d.ts +27 -0
  26. package/dist/datagrid-B6hg5yJh.d.cts +200 -0
  27. package/dist/datagrid-B6hg5yJh.d.ts +200 -0
  28. package/dist/datagrid.cjs +1052 -0
  29. package/dist/datagrid.cjs.map +1 -0
  30. package/dist/datagrid.d.cts +2 -0
  31. package/dist/datagrid.d.ts +2 -0
  32. package/dist/datagrid.js +10 -0
  33. package/dist/datagrid.js.map +1 -0
  34. package/dist/devtools.cjs +253 -0
  35. package/dist/devtools.cjs.map +1 -0
  36. package/dist/devtools.d.cts +29 -0
  37. package/dist/devtools.d.ts +29 -0
  38. package/dist/devtools.js +9 -0
  39. package/dist/devtools.js.map +1 -0
  40. package/dist/form.cjs +1723 -0
  41. package/dist/form.cjs.map +1 -0
  42. package/dist/form.d.cts +530 -0
  43. package/dist/form.d.ts +530 -0
  44. package/dist/form.js +49 -0
  45. package/dist/form.js.map +1 -0
  46. package/dist/index.cjs +22419 -0
  47. package/dist/index.cjs.map +1 -0
  48. package/dist/index.d.cts +3671 -0
  49. package/dist/index.d.ts +3671 -0
  50. package/dist/index.js +14087 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/table.cjs +4130 -0
  53. package/dist/table.cjs.map +1 -0
  54. package/dist/table.d.cts +31 -0
  55. package/dist/table.d.ts +31 -0
  56. package/dist/table.js +26 -0
  57. package/dist/table.js.map +1 -0
  58. package/dist/tree.cjs +1821 -0
  59. package/dist/tree.cjs.map +1 -0
  60. package/dist/tree.d.cts +348 -0
  61. package/dist/tree.d.ts +348 -0
  62. package/dist/tree.js +13 -0
  63. package/dist/tree.js.map +1 -0
  64. package/dist/virtual.cjs +145 -0
  65. package/dist/virtual.cjs.map +1 -0
  66. package/dist/virtual.d.cts +50 -0
  67. package/dist/virtual.d.ts +50 -0
  68. package/dist/virtual.js +11 -0
  69. package/dist/virtual.js.map +1 -0
  70. package/package.json +108 -18
  71. package/README.md +0 -12
  72. package/index.js +0 -3
@@ -0,0 +1,847 @@
1
+ import {
2
+ Checkbox
3
+ } from "./chunk-DRBAZI46.js";
4
+ import {
5
+ Spin
6
+ } from "./chunk-2OCEO636.js";
7
+ import {
8
+ useVirtualScroll
9
+ } from "./chunk-SEQI65CF.js";
10
+
11
+ // src/components/complex/DataGrid/DataGrid.tsx
12
+ import React, { forwardRef, useImperativeHandle, useCallback as useCallback2, useRef as useRef2, useMemo, useState as useState2 } from "react";
13
+
14
+ // src/components/complex/DataGrid/useDataGridState.ts
15
+ import { useState, useCallback, useRef } from "react";
16
+ function useDataGridState(columns, data) {
17
+ const [activeCell, setActiveCell] = useState(null);
18
+ const [editingCell, setEditingCell] = useState(null);
19
+ const [selection, setSelection] = useState(null);
20
+ const [columnWidths, setColumnWidths] = useState(() => {
21
+ const map = /* @__PURE__ */ new Map();
22
+ for (const col of columns) {
23
+ if (col.width) map.set(col.key, col.width);
24
+ }
25
+ return map;
26
+ });
27
+ const [columnOrder, setColumnOrder] = useState(null);
28
+ const editValueRef = useRef(void 0);
29
+ const dragColumnRef = useRef(null);
30
+ const startEditing = useCallback(
31
+ (pos) => {
32
+ const col = columns[pos.col];
33
+ if (!col) return;
34
+ const isEditable = typeof col.editable === "function" ? col.editable(data[pos.row], pos.row) : col.editable !== false;
35
+ if (!isEditable) return;
36
+ editValueRef.current = data[pos.row][col.key];
37
+ setEditingCell(pos);
38
+ },
39
+ [columns, data]
40
+ );
41
+ const stopEditing = useCallback(() => {
42
+ setEditingCell(null);
43
+ editValueRef.current = void 0;
44
+ }, []);
45
+ const navigate = useCallback(
46
+ (from, direction, shiftKey = false) => {
47
+ let { row, col } = from;
48
+ switch (direction) {
49
+ case "up":
50
+ row = Math.max(0, row - 1);
51
+ break;
52
+ case "down":
53
+ row = Math.min(data.length - 1, row + 1);
54
+ break;
55
+ case "left":
56
+ col = Math.max(0, col - 1);
57
+ break;
58
+ case "right":
59
+ col = Math.min(columns.length - 1, col + 1);
60
+ break;
61
+ }
62
+ const next = { row, col };
63
+ if (shiftKey) {
64
+ setSelection((prev) => ({
65
+ start: prev?.start ?? from,
66
+ end: next
67
+ }));
68
+ } else {
69
+ setSelection(null);
70
+ }
71
+ setActiveCell(next);
72
+ return next;
73
+ },
74
+ [data.length, columns.length]
75
+ );
76
+ const resizeColumn = useCallback(
77
+ (key, width) => {
78
+ const col = columns.find((c) => c.key === key);
79
+ const minW = col?.minWidth ?? 50;
80
+ const maxW = col?.maxWidth ?? Infinity;
81
+ const clamped = Math.max(minW, Math.min(maxW, width));
82
+ setColumnWidths((prev) => new Map(prev).set(key, clamped));
83
+ },
84
+ [columns]
85
+ );
86
+ const getColumnWidth = useCallback(
87
+ (key) => {
88
+ return columnWidths.get(key) ?? columns.find((c) => c.key === key)?.width ?? 120;
89
+ },
90
+ [columnWidths, columns]
91
+ );
92
+ const reorderColumns = useCallback(
93
+ (fromKey, toKey) => {
94
+ const order = columnOrder ?? columns.map((c) => c.key);
95
+ const fromIdx = order.indexOf(fromKey);
96
+ const toIdx = order.indexOf(toKey);
97
+ if (fromIdx === -1 || toIdx === -1 || fromIdx === toIdx) return order;
98
+ const next = [...order];
99
+ const [moved] = next.splice(fromIdx, 1);
100
+ next.splice(toIdx, 0, moved);
101
+ setColumnOrder(next);
102
+ return next;
103
+ },
104
+ [columnOrder, columns]
105
+ );
106
+ return {
107
+ activeCell,
108
+ setActiveCell,
109
+ editingCell,
110
+ startEditing,
111
+ stopEditing,
112
+ editValueRef,
113
+ selection,
114
+ setSelection,
115
+ navigate,
116
+ resizeColumn,
117
+ getColumnWidth,
118
+ columnOrder,
119
+ setColumnOrder,
120
+ reorderColumns,
121
+ dragColumnRef
122
+ };
123
+ }
124
+
125
+ // src/components/complex/DataGrid/DataGrid.tsx
126
+ import { jsx, jsxs } from "react/jsx-runtime";
127
+ var cls = {
128
+ root: "sg-datagrid",
129
+ header: "sg-datagrid-header",
130
+ headerCell: "sg-datagrid-header-cell",
131
+ body: "sg-datagrid-body",
132
+ row: "sg-datagrid-row",
133
+ rowEven: "sg-datagrid-row--even",
134
+ rowOdd: "sg-datagrid-row--odd",
135
+ rowHoverable: "sg-datagrid-row--hoverable",
136
+ rowSelected: "sg-datagrid-row--selected",
137
+ cell: "sg-datagrid-cell",
138
+ cellActive: "sg-datagrid-cell--active",
139
+ cellEditing: "sg-datagrid-cell--editing",
140
+ cellSelected: "sg-datagrid-cell--selected",
141
+ frozen: "sg-datagrid-cell--frozen",
142
+ sortable: "sg-datagrid-header-cell--sortable",
143
+ sortAsc: "sg-datagrid-header-cell--asc",
144
+ sortDesc: "sg-datagrid-header-cell--desc",
145
+ resizer: "sg-datagrid-resizer",
146
+ empty: "sg-datagrid-empty",
147
+ summary: "sg-datagrid-summary",
148
+ summaryRow: "sg-datagrid-summary-row",
149
+ summaryCell: "sg-datagrid-summary-cell",
150
+ contextMenu: "sg-datagrid-context-menu",
151
+ contextMenuItem: "sg-datagrid-context-menu-item",
152
+ contextMenuDanger: "sg-datagrid-context-menu-item--danger",
153
+ contextMenuDisabled: "sg-datagrid-context-menu-item--disabled",
154
+ contextMenuDivider: "sg-datagrid-context-menu-divider",
155
+ loading: "sg-datagrid-loading",
156
+ selectionCell: "sg-datagrid-selection-cell",
157
+ rowNumberCell: "sg-datagrid-row-number-cell",
158
+ headerDragOver: "sg-datagrid-header-cell--drag-over"
159
+ };
160
+ var SELECTION_COL_WIDTH = 40;
161
+ var ROW_NUMBER_COL_WIDTH = 48;
162
+ function DefaultEditor({ value, onChange, onCommit, onCancel }) {
163
+ return /* @__PURE__ */ jsx(
164
+ "input",
165
+ {
166
+ autoFocus: true,
167
+ defaultValue: value == null ? "" : String(value),
168
+ onChange: (e) => onChange(e.target.value),
169
+ onBlur: onCommit,
170
+ onKeyDown: (e) => {
171
+ if (e.key === "Enter") onCommit();
172
+ if (e.key === "Escape") onCancel();
173
+ },
174
+ style: {
175
+ width: "100%",
176
+ height: "100%",
177
+ border: "none",
178
+ outline: "none",
179
+ padding: "0 8px",
180
+ background: "transparent",
181
+ font: "inherit"
182
+ }
183
+ }
184
+ );
185
+ }
186
+ function isCellInRange(row, col, range) {
187
+ if (!range) return false;
188
+ const minRow = Math.min(range.start.row, range.end.row);
189
+ const maxRow = Math.max(range.start.row, range.end.row);
190
+ const minCol = Math.min(range.start.col, range.end.col);
191
+ const maxCol = Math.max(range.start.col, range.end.col);
192
+ return row >= minRow && row <= maxRow && col >= minCol && col <= maxCol;
193
+ }
194
+ function ContextMenuPopup({
195
+ items,
196
+ position,
197
+ onClose
198
+ }) {
199
+ const ref = useRef2(null);
200
+ React.useEffect(() => {
201
+ const handler = (e) => {
202
+ if (ref.current && !ref.current.contains(e.target)) onClose();
203
+ };
204
+ document.addEventListener("mousedown", handler);
205
+ return () => document.removeEventListener("mousedown", handler);
206
+ }, [onClose]);
207
+ return /* @__PURE__ */ jsx(
208
+ "div",
209
+ {
210
+ ref,
211
+ className: cls.contextMenu,
212
+ style: { position: "fixed", top: position.y, left: position.x },
213
+ children: items.map(
214
+ (item) => item.divider ? /* @__PURE__ */ jsx("div", { className: cls.contextMenuDivider }, item.key) : /* @__PURE__ */ jsx(
215
+ "div",
216
+ {
217
+ className: [
218
+ cls.contextMenuItem,
219
+ item.danger ? cls.contextMenuDanger : "",
220
+ item.disabled ? cls.contextMenuDisabled : ""
221
+ ].filter(Boolean).join(" "),
222
+ onClick: () => {
223
+ if (!item.disabled) {
224
+ item.onClick();
225
+ onClose();
226
+ }
227
+ },
228
+ children: item.label
229
+ },
230
+ item.key
231
+ )
232
+ )
233
+ }
234
+ );
235
+ }
236
+ function DataGridInner(props, ref) {
237
+ const {
238
+ columns,
239
+ data,
240
+ rowKey,
241
+ rowHeight = 36,
242
+ headerHeight = 40,
243
+ width = "100%",
244
+ height = 400,
245
+ className,
246
+ style,
247
+ onCellEdit,
248
+ sortColumn,
249
+ sortDirection,
250
+ onSort,
251
+ onCopy,
252
+ onPaste,
253
+ overscan = 5,
254
+ locale,
255
+ rowSelection,
256
+ selectedRows,
257
+ onSelectedRowsChange,
258
+ striped,
259
+ highlightOnHover = true,
260
+ showRowNumber,
261
+ summaryRows,
262
+ cellClassName,
263
+ cellStyle: cellStyleFn,
264
+ columnReorder,
265
+ onColumnOrderChange,
266
+ onContextMenu,
267
+ onRowClick,
268
+ onRowDoubleClick,
269
+ rowClassName,
270
+ loading,
271
+ emptyContent
272
+ } = props;
273
+ const containerRef = useRef2(null);
274
+ const state = useDataGridState(columns, data);
275
+ const {
276
+ activeCell,
277
+ setActiveCell,
278
+ editingCell,
279
+ startEditing,
280
+ stopEditing,
281
+ editValueRef,
282
+ selection,
283
+ navigate,
284
+ resizeColumn,
285
+ getColumnWidth,
286
+ columnOrder,
287
+ reorderColumns,
288
+ dragColumnRef
289
+ } = state;
290
+ const [ctxMenu, setCtxMenu] = useState2(null);
291
+ const [dragOverCol, setDragOverCol] = useState2(null);
292
+ const { range, containerRef: scrollRef, scrollToIndex } = useVirtualScroll({
293
+ itemCount: data.length,
294
+ itemHeight: rowHeight,
295
+ overscan
296
+ });
297
+ const getRowKey = useCallback2(
298
+ (row, index) => {
299
+ if (typeof rowKey === "function") return rowKey(row, index);
300
+ return row[rowKey];
301
+ },
302
+ [rowKey]
303
+ );
304
+ const frozenLeft = useMemo(
305
+ () => columns.filter((c) => c.frozen === "left"),
306
+ [columns]
307
+ );
308
+ const frozenRight = useMemo(
309
+ () => columns.filter((c) => c.frozen === "right"),
310
+ [columns]
311
+ );
312
+ const scrollable = useMemo(
313
+ () => columns.filter((c) => !c.frozen),
314
+ [columns]
315
+ );
316
+ const orderedColumns = useMemo(() => {
317
+ const base = [...frozenLeft, ...scrollable, ...frozenRight];
318
+ if (!columnOrder) return base;
319
+ const map = new Map(base.map((c) => [c.key, c]));
320
+ const ordered = [];
321
+ for (const key of columnOrder) {
322
+ const col = map.get(key);
323
+ if (col) ordered.push(col);
324
+ }
325
+ for (const col of base) {
326
+ if (!columnOrder.includes(col.key)) ordered.push(col);
327
+ }
328
+ return ordered;
329
+ }, [frozenLeft, scrollable, frozenRight, columnOrder]);
330
+ const extraColsWidth = (rowSelection ? SELECTION_COL_WIDTH : 0) + (showRowNumber ? ROW_NUMBER_COL_WIDTH : 0);
331
+ const totalWidth = useMemo(
332
+ () => orderedColumns.reduce((sum, col) => sum + getColumnWidth(col.key), 0) + extraColsWidth,
333
+ [orderedColumns, getColumnWidth, extraColsWidth]
334
+ );
335
+ const allSelected = useMemo(() => {
336
+ if (!selectedRows || data.length === 0) return false;
337
+ return data.every((row, i) => selectedRows.has(getRowKey(row, i)));
338
+ }, [selectedRows, data, getRowKey]);
339
+ const someSelected = useMemo(() => {
340
+ if (!selectedRows || data.length === 0) return false;
341
+ const count = data.filter((row, i) => selectedRows.has(getRowKey(row, i))).length;
342
+ return count > 0 && count < data.length;
343
+ }, [selectedRows, data, getRowKey]);
344
+ const handleSelectAll = useCallback2(() => {
345
+ if (!onSelectedRowsChange) return;
346
+ if (allSelected) {
347
+ onSelectedRowsChange(/* @__PURE__ */ new Set());
348
+ } else {
349
+ const all = new Set(data.map((row, i) => getRowKey(row, i)));
350
+ onSelectedRowsChange(all);
351
+ }
352
+ }, [allSelected, data, getRowKey, onSelectedRowsChange]);
353
+ const handleSelectRow = useCallback2(
354
+ (row, index) => {
355
+ if (!onSelectedRowsChange || !selectedRows) return;
356
+ const key = getRowKey(row, index);
357
+ const next = new Set(selectedRows);
358
+ if (next.has(key)) next.delete(key);
359
+ else next.add(key);
360
+ onSelectedRowsChange(next);
361
+ },
362
+ [getRowKey, onSelectedRowsChange, selectedRows]
363
+ );
364
+ const handleCellClick = useCallback2(
365
+ (rowIndex, colIndex) => {
366
+ if (editingCell) {
367
+ if (onCellEdit && editValueRef.current !== void 0) {
368
+ onCellEdit(editingCell.row, orderedColumns[editingCell.col].key, editValueRef.current);
369
+ }
370
+ stopEditing();
371
+ }
372
+ setActiveCell({ row: rowIndex, col: colIndex });
373
+ },
374
+ [editingCell, onCellEdit, editValueRef, orderedColumns, stopEditing, setActiveCell]
375
+ );
376
+ const handleCellDoubleClick = useCallback2(
377
+ (rowIndex, colIndex) => {
378
+ startEditing({ row: rowIndex, col: colIndex });
379
+ },
380
+ [startEditing]
381
+ );
382
+ const handleCommitEdit = useCallback2(() => {
383
+ if (editingCell && onCellEdit && editValueRef.current !== void 0) {
384
+ onCellEdit(editingCell.row, orderedColumns[editingCell.col].key, editValueRef.current);
385
+ }
386
+ stopEditing();
387
+ }, [editingCell, onCellEdit, editValueRef, orderedColumns, stopEditing]);
388
+ const handleCancelEdit = useCallback2(() => {
389
+ stopEditing();
390
+ }, [stopEditing]);
391
+ const handleKeyDown = useCallback2(
392
+ (e) => {
393
+ if (!activeCell) return;
394
+ if (editingCell) return;
395
+ switch (e.key) {
396
+ case "ArrowUp":
397
+ e.preventDefault();
398
+ navigate(activeCell, "up", e.shiftKey);
399
+ break;
400
+ case "ArrowDown":
401
+ e.preventDefault();
402
+ navigate(activeCell, "down", e.shiftKey);
403
+ break;
404
+ case "ArrowLeft":
405
+ e.preventDefault();
406
+ navigate(activeCell, "left", e.shiftKey);
407
+ break;
408
+ case "ArrowRight":
409
+ e.preventDefault();
410
+ navigate(activeCell, "right", e.shiftKey);
411
+ break;
412
+ case "Enter":
413
+ e.preventDefault();
414
+ startEditing(activeCell);
415
+ break;
416
+ case "Tab":
417
+ e.preventDefault();
418
+ navigate(activeCell, e.shiftKey ? "left" : "right");
419
+ break;
420
+ case "Escape":
421
+ setActiveCell(null);
422
+ break;
423
+ case " ":
424
+ if (rowSelection && selectedRows) {
425
+ e.preventDefault();
426
+ const row = data[activeCell.row];
427
+ if (row) handleSelectRow(row, activeCell.row);
428
+ }
429
+ break;
430
+ case "a":
431
+ if ((e.ctrlKey || e.metaKey) && rowSelection) {
432
+ e.preventDefault();
433
+ handleSelectAll();
434
+ }
435
+ break;
436
+ case "c":
437
+ if ((e.ctrlKey || e.metaKey) && onCopy) {
438
+ e.preventDefault();
439
+ const col = orderedColumns[activeCell.col];
440
+ const val = data[activeCell.row]?.[col.key];
441
+ onCopy(val == null ? "" : String(val));
442
+ }
443
+ break;
444
+ case "v":
445
+ if ((e.ctrlKey || e.metaKey) && onPaste) {
446
+ e.preventDefault();
447
+ navigator.clipboard?.readText().then((text) => {
448
+ onPaste(text, activeCell);
449
+ });
450
+ }
451
+ break;
452
+ }
453
+ },
454
+ [
455
+ activeCell,
456
+ editingCell,
457
+ navigate,
458
+ startEditing,
459
+ setActiveCell,
460
+ onCopy,
461
+ onPaste,
462
+ orderedColumns,
463
+ data,
464
+ rowSelection,
465
+ selectedRows,
466
+ handleSelectRow,
467
+ handleSelectAll
468
+ ]
469
+ );
470
+ const handleSort = useCallback2(
471
+ (col) => {
472
+ if (!col.sortable || !onSort) return;
473
+ const dir = sortColumn === col.key && sortDirection === "asc" ? "desc" : "asc";
474
+ onSort(col.key, dir);
475
+ },
476
+ [sortColumn, sortDirection, onSort]
477
+ );
478
+ const handleCellContextMenu = useCallback2(
479
+ (e, rowIndex, col) => {
480
+ if (!onContextMenu) return;
481
+ e.preventDefault();
482
+ const row = data[rowIndex];
483
+ if (!row) return;
484
+ const items = onContextMenu(rowIndex, col.key, row);
485
+ if (items.length === 0) return;
486
+ setCtxMenu({ items, position: { x: e.clientX, y: e.clientY } });
487
+ },
488
+ [onContextMenu, data]
489
+ );
490
+ const handleHeaderDragStart = useCallback2(
491
+ (e, colKey) => {
492
+ if (!columnReorder) return;
493
+ dragColumnRef.current = colKey;
494
+ e.dataTransfer.effectAllowed = "move";
495
+ },
496
+ [columnReorder, dragColumnRef]
497
+ );
498
+ const handleHeaderDragOver = useCallback2(
499
+ (e, colKey) => {
500
+ if (!columnReorder || !dragColumnRef.current) return;
501
+ e.preventDefault();
502
+ setDragOverCol(colKey);
503
+ },
504
+ [columnReorder, dragColumnRef]
505
+ );
506
+ const handleHeaderDrop = useCallback2(
507
+ (e, colKey) => {
508
+ e.preventDefault();
509
+ if (!columnReorder || !dragColumnRef.current) return;
510
+ const newOrder = reorderColumns(dragColumnRef.current, colKey);
511
+ dragColumnRef.current = null;
512
+ setDragOverCol(null);
513
+ onColumnOrderChange?.(newOrder);
514
+ },
515
+ [columnReorder, dragColumnRef, reorderColumns, onColumnOrderChange]
516
+ );
517
+ const handleHeaderDragEnd = useCallback2(() => {
518
+ dragColumnRef.current = null;
519
+ setDragOverCol(null);
520
+ }, [dragColumnRef]);
521
+ useImperativeHandle(
522
+ ref,
523
+ () => ({
524
+ scrollToRow: scrollToIndex,
525
+ scrollToColumn: () => {
526
+ },
527
+ getActiveCell: () => activeCell,
528
+ setActiveCell
529
+ }),
530
+ [scrollToIndex, activeCell, setActiveCell]
531
+ );
532
+ const handleResizeStart = useCallback2(
533
+ (colKey, startX) => {
534
+ const startWidth = getColumnWidth(colKey);
535
+ const onMouseMove = (e) => {
536
+ const delta = e.clientX - startX;
537
+ resizeColumn(colKey, startWidth + delta);
538
+ };
539
+ const onMouseUp = () => {
540
+ document.removeEventListener("mousemove", onMouseMove);
541
+ document.removeEventListener("mouseup", onMouseUp);
542
+ };
543
+ document.addEventListener("mousemove", onMouseMove);
544
+ document.addEventListener("mouseup", onMouseUp);
545
+ },
546
+ [getColumnWidth, resizeColumn]
547
+ );
548
+ const renderCell = useCallback2(
549
+ (row, rowIndex, col, colIndex) => {
550
+ const isActive = activeCell?.row === rowIndex && activeCell?.col === colIndex;
551
+ const isEditing = editingCell?.row === rowIndex && editingCell?.col === colIndex;
552
+ const isSelected = isCellInRange(rowIndex, colIndex, selection);
553
+ const rawValue = col.formula ? col.formula(row) : row[col.key];
554
+ const extraClass = cellClassName?.(rawValue, row, rowIndex, col) ?? "";
555
+ const extraStyle = cellStyleFn?.(rawValue, row, rowIndex, col);
556
+ const cellClassNames = [
557
+ cls.cell,
558
+ isActive ? cls.cellActive : "",
559
+ isEditing ? cls.cellEditing : "",
560
+ isSelected ? cls.cellSelected : "",
561
+ col.frozen ? cls.frozen : "",
562
+ col.className ?? "",
563
+ extraClass
564
+ ].filter(Boolean).join(" ");
565
+ const baseCellStyle = {
566
+ width: getColumnWidth(col.key),
567
+ minWidth: getColumnWidth(col.key),
568
+ textAlign: col.align ?? "left",
569
+ ...extraStyle
570
+ };
571
+ return /* @__PURE__ */ jsx(
572
+ "div",
573
+ {
574
+ className: cellClassNames,
575
+ style: baseCellStyle,
576
+ onClick: () => handleCellClick(rowIndex, colIndex),
577
+ onDoubleClick: () => handleCellDoubleClick(rowIndex, colIndex),
578
+ onContextMenu: (e) => handleCellContextMenu(e, rowIndex, col),
579
+ role: "gridcell",
580
+ "aria-colindex": colIndex + 1 + (rowSelection ? 1 : 0) + (showRowNumber ? 1 : 0),
581
+ "aria-selected": isActive || isSelected,
582
+ children: isEditing ? (col.editor ?? DefaultEditor)({
583
+ value: rawValue,
584
+ row,
585
+ rowIndex,
586
+ column: col,
587
+ onChange: (v) => {
588
+ editValueRef.current = v;
589
+ },
590
+ onCommit: handleCommitEdit,
591
+ onCancel: handleCancelEdit
592
+ }) : col.render ? col.render(rawValue, row, rowIndex) : /* @__PURE__ */ jsx("span", { children: rawValue == null ? "" : String(rawValue) })
593
+ },
594
+ col.key
595
+ );
596
+ },
597
+ [
598
+ activeCell,
599
+ editingCell,
600
+ selection,
601
+ getColumnWidth,
602
+ handleCellClick,
603
+ handleCellDoubleClick,
604
+ handleCommitEdit,
605
+ handleCancelEdit,
606
+ editValueRef,
607
+ cellClassName,
608
+ cellStyleFn,
609
+ handleCellContextMenu,
610
+ rowSelection,
611
+ showRowNumber
612
+ ]
613
+ );
614
+ const heightValue = typeof height === "number" ? height : void 0;
615
+ const bodyHeight = heightValue ? heightValue - headerHeight : void 0;
616
+ const rootCls = [
617
+ cls.root,
618
+ striped ? "sg-datagrid--striped" : "",
619
+ loading ? "sg-datagrid--loading" : "",
620
+ className ?? ""
621
+ ].filter(Boolean).join(" ");
622
+ return /* @__PURE__ */ jsxs(
623
+ "div",
624
+ {
625
+ ref: containerRef,
626
+ className: rootCls,
627
+ style: { width, height, display: "flex", flexDirection: "column", position: "relative", ...style },
628
+ onKeyDown: handleKeyDown,
629
+ tabIndex: 0,
630
+ role: "grid",
631
+ "aria-rowcount": data.length,
632
+ "aria-colcount": orderedColumns.length,
633
+ children: [
634
+ /* @__PURE__ */ jsxs(
635
+ "div",
636
+ {
637
+ className: cls.header,
638
+ style: {
639
+ display: "flex",
640
+ height: headerHeight,
641
+ minHeight: headerHeight,
642
+ minWidth: totalWidth
643
+ },
644
+ role: "row",
645
+ children: [
646
+ rowSelection && /* @__PURE__ */ jsx(
647
+ "div",
648
+ {
649
+ className: `${cls.headerCell} ${cls.selectionCell}`,
650
+ style: { width: SELECTION_COL_WIDTH, minWidth: SELECTION_COL_WIDTH, display: "flex", alignItems: "center", justifyContent: "center" },
651
+ role: "columnheader",
652
+ children: /* @__PURE__ */ jsx(
653
+ Checkbox,
654
+ {
655
+ checked: allSelected,
656
+ indeterminate: someSelected,
657
+ onChange: handleSelectAll
658
+ }
659
+ )
660
+ }
661
+ ),
662
+ showRowNumber && /* @__PURE__ */ jsx(
663
+ "div",
664
+ {
665
+ className: `${cls.headerCell} ${cls.rowNumberCell}`,
666
+ style: { width: ROW_NUMBER_COL_WIDTH, minWidth: ROW_NUMBER_COL_WIDTH, display: "flex", alignItems: "center", justifyContent: "center", userSelect: "none" },
667
+ role: "columnheader",
668
+ children: "#"
669
+ }
670
+ ),
671
+ orderedColumns.map((col) => {
672
+ const isSorted = sortColumn === col.key;
673
+ const headerCls = [
674
+ cls.headerCell,
675
+ col.sortable ? cls.sortable : "",
676
+ isSorted && sortDirection === "asc" ? cls.sortAsc : "",
677
+ isSorted && sortDirection === "desc" ? cls.sortDesc : "",
678
+ col.headerClassName ?? "",
679
+ dragOverCol === col.key ? cls.headerDragOver : ""
680
+ ].filter(Boolean).join(" ");
681
+ return /* @__PURE__ */ jsxs(
682
+ "div",
683
+ {
684
+ className: headerCls,
685
+ style: {
686
+ width: getColumnWidth(col.key),
687
+ minWidth: getColumnWidth(col.key),
688
+ position: "relative",
689
+ display: "flex",
690
+ alignItems: "center",
691
+ padding: "0 8px",
692
+ cursor: col.sortable ? "pointer" : "default",
693
+ userSelect: "none"
694
+ },
695
+ onClick: () => handleSort(col),
696
+ draggable: !!columnReorder,
697
+ onDragStart: (e) => handleHeaderDragStart(e, col.key),
698
+ onDragOver: (e) => handleHeaderDragOver(e, col.key),
699
+ onDrop: (e) => handleHeaderDrop(e, col.key),
700
+ onDragEnd: handleHeaderDragEnd,
701
+ onDragLeave: () => setDragOverCol(null),
702
+ role: "columnheader",
703
+ children: [
704
+ col.title,
705
+ isSorted && /* @__PURE__ */ jsx("span", { style: { marginLeft: 4, fontSize: 10 }, children: sortDirection === "asc" ? "\u25B2" : "\u25BC" }),
706
+ col.resizable !== false && /* @__PURE__ */ jsx(
707
+ "div",
708
+ {
709
+ className: cls.resizer,
710
+ style: {
711
+ position: "absolute",
712
+ right: 0,
713
+ top: 0,
714
+ bottom: 0,
715
+ width: 4,
716
+ cursor: "col-resize"
717
+ },
718
+ onMouseDown: (e) => {
719
+ e.stopPropagation();
720
+ handleResizeStart(col.key, e.clientX);
721
+ }
722
+ }
723
+ )
724
+ ]
725
+ },
726
+ col.key
727
+ );
728
+ })
729
+ ]
730
+ }
731
+ ),
732
+ /* @__PURE__ */ jsx(
733
+ "div",
734
+ {
735
+ ref: scrollRef,
736
+ className: cls.body,
737
+ style: {
738
+ flex: 1,
739
+ overflow: "auto",
740
+ position: "relative",
741
+ height: bodyHeight
742
+ },
743
+ children: data.length === 0 ? /* @__PURE__ */ jsx("div", { className: cls.empty, style: { padding: 24, textAlign: "center" }, children: emptyContent ?? locale?.noData ?? "No data" }) : /* @__PURE__ */ jsx("div", { style: { height: range.totalHeight, position: "relative", minWidth: totalWidth }, children: range.visibleItems.map((vi) => {
744
+ const row = data[vi.index];
745
+ if (!row) return null;
746
+ const rKey = getRowKey(row, vi.index);
747
+ const isRowSelected = selectedRows?.has(rKey) ?? false;
748
+ const rowExtraClass = typeof rowClassName === "function" ? rowClassName(row, vi.index) : rowClassName ?? "";
749
+ const rowCls = [
750
+ cls.row,
751
+ striped ? vi.index % 2 === 0 ? cls.rowEven : cls.rowOdd : "",
752
+ highlightOnHover ? cls.rowHoverable : "",
753
+ isRowSelected ? cls.rowSelected : "",
754
+ rowExtraClass
755
+ ].filter(Boolean).join(" ");
756
+ return /* @__PURE__ */ jsxs(
757
+ "div",
758
+ {
759
+ className: rowCls,
760
+ style: {
761
+ display: "flex",
762
+ position: "absolute",
763
+ top: vi.offsetTop,
764
+ height: vi.height,
765
+ width: "100%"
766
+ },
767
+ role: "row",
768
+ "aria-rowindex": vi.index + 1,
769
+ "aria-selected": isRowSelected,
770
+ onClick: () => onRowClick?.(row, vi.index),
771
+ onDoubleClick: () => onRowDoubleClick?.(row, vi.index),
772
+ children: [
773
+ rowSelection && /* @__PURE__ */ jsx(
774
+ "div",
775
+ {
776
+ className: `${cls.cell} ${cls.selectionCell}`,
777
+ style: { width: SELECTION_COL_WIDTH, minWidth: SELECTION_COL_WIDTH, display: "flex", alignItems: "center", justifyContent: "center" },
778
+ onClick: (e) => e.stopPropagation(),
779
+ children: /* @__PURE__ */ jsx(
780
+ Checkbox,
781
+ {
782
+ checked: isRowSelected,
783
+ onChange: () => handleSelectRow(row, vi.index)
784
+ }
785
+ )
786
+ }
787
+ ),
788
+ showRowNumber && /* @__PURE__ */ jsx(
789
+ "div",
790
+ {
791
+ className: `${cls.cell} ${cls.rowNumberCell}`,
792
+ style: { width: ROW_NUMBER_COL_WIDTH, minWidth: ROW_NUMBER_COL_WIDTH, display: "flex", alignItems: "center", justifyContent: "center", color: "var(--sg-text-tertiary, #999)" },
793
+ children: vi.index + 1
794
+ }
795
+ ),
796
+ orderedColumns.map((col, ci) => renderCell(row, vi.index, col, ci))
797
+ ]
798
+ },
799
+ rKey
800
+ );
801
+ }) })
802
+ }
803
+ ),
804
+ summaryRows && summaryRows.length > 0 && data.length > 0 && /* @__PURE__ */ jsx("div", { className: cls.summary, style: { minWidth: totalWidth }, children: summaryRows.map((sr, sri) => /* @__PURE__ */ jsxs(
805
+ "div",
806
+ {
807
+ className: `${cls.summaryRow} ${sr.className ?? ""}`,
808
+ style: { display: "flex", height: rowHeight },
809
+ children: [
810
+ rowSelection && /* @__PURE__ */ jsx("div", { className: `${cls.summaryCell}`, style: { width: SELECTION_COL_WIDTH, minWidth: SELECTION_COL_WIDTH } }),
811
+ showRowNumber && /* @__PURE__ */ jsx("div", { className: `${cls.summaryCell}`, style: { width: ROW_NUMBER_COL_WIDTH, minWidth: ROW_NUMBER_COL_WIDTH } }),
812
+ orderedColumns.map((col) => /* @__PURE__ */ jsx(
813
+ "div",
814
+ {
815
+ className: cls.summaryCell,
816
+ style: {
817
+ width: getColumnWidth(col.key),
818
+ minWidth: getColumnWidth(col.key),
819
+ textAlign: col.align ?? "left"
820
+ },
821
+ children: sr.render(col.key, data)
822
+ },
823
+ col.key
824
+ ))
825
+ ]
826
+ },
827
+ sri
828
+ )) }),
829
+ ctxMenu && /* @__PURE__ */ jsx(
830
+ ContextMenuPopup,
831
+ {
832
+ items: ctxMenu.items,
833
+ position: ctxMenu.position,
834
+ onClose: () => setCtxMenu(null)
835
+ }
836
+ ),
837
+ loading && /* @__PURE__ */ jsx("div", { className: cls.loading, style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", background: "rgba(255,255,255,0.6)", zIndex: 10 }, children: /* @__PURE__ */ jsx(Spin, { size: "large" }) })
838
+ ]
839
+ }
840
+ );
841
+ }
842
+ var DataGrid = forwardRef(DataGridInner);
843
+
844
+ export {
845
+ DataGrid
846
+ };
847
+ //# sourceMappingURL=chunk-KCFWFDSP.js.map