@xcelsior/ui-spreadsheets 1.1.3 → 1.1.4
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.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +73 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -38
- package/dist/index.mjs.map +1 -1
- package/dist/styles/globals.css +23 -0
- package/dist/styles/globals.css.map +1 -1
- package/package.json +1 -1
- package/src/components/Spreadsheet.stories.tsx +214 -0
- package/src/components/Spreadsheet.tsx +10 -0
- package/src/hooks/useSpreadsheetComments.ts +17 -5
- package/src/hooks/useSpreadsheetFiltering.ts +1 -1
- package/src/hooks/useSpreadsheetHighlighting.ts +63 -34
- package/src/types.ts +10 -0
package/dist/index.d.mts
CHANGED
|
@@ -277,8 +277,14 @@ interface SpreadsheetProps<T = any> {
|
|
|
277
277
|
onRowDelete?: (row: T, rowId: string | number) => void;
|
|
278
278
|
/** Callback when a cell comment is added */
|
|
279
279
|
onAddCellComment?: (rowId: string | number, columnId: string, comment: string) => void;
|
|
280
|
+
/** Callback when a comment's resolved status is toggled */
|
|
281
|
+
onToggleCommentResolved?: (commentId: string) => void;
|
|
280
282
|
/** Callback when row highlight is toggled */
|
|
281
283
|
onRowHighlight?: (rowId: string | number, color: string | null) => void;
|
|
284
|
+
/** Callback when column highlight is toggled */
|
|
285
|
+
onColumnHighlight?: (columnId: string, color: string | null) => void;
|
|
286
|
+
/** Callback when cell highlight is toggled */
|
|
287
|
+
onCellHighlight?: (rowId: string | number, columnId: string, color: string | null) => void;
|
|
282
288
|
/** Whether to show the toolbar */
|
|
283
289
|
showToolbar?: boolean;
|
|
284
290
|
/** Whether to show pagination */
|
|
@@ -329,6 +335,10 @@ interface SpreadsheetProps<T = any> {
|
|
|
329
335
|
emptyMessage?: string;
|
|
330
336
|
/** Row highlights (externally controlled) */
|
|
331
337
|
rowHighlights?: CellHighlight[];
|
|
338
|
+
/** Column highlights (externally controlled) */
|
|
339
|
+
columnHighlights?: Record<string, string>;
|
|
340
|
+
/** Cell highlights (externally controlled) */
|
|
341
|
+
cellHighlights?: CellHighlight[];
|
|
332
342
|
/** Cell comments (externally controlled) */
|
|
333
343
|
cellComments?: CellComment[];
|
|
334
344
|
/** Custom row actions to display in the index column */
|
|
@@ -620,7 +630,7 @@ interface SpreadsheetColumnGroupHeaderProps {
|
|
|
620
630
|
* />
|
|
621
631
|
* ```
|
|
622
632
|
*/
|
|
623
|
-
declare function Spreadsheet<T extends Record<string, any>>({ data, columns, columnGroups, getRowId, onCellsEdit, onSelectionChange, onSortChange, onFilterChange, onRowClick, onRowDoubleClick, onRowClone, onRowDelete, onAddCellComment, onRowHighlight, showToolbar, showPagination, enableRowSelection, enableCellEditing, enableComments, enableHighlighting, enableUndoRedo, pageSizeOptions, onSave, settings: initialSettings, onSettingsChange, isLoading, className, emptyMessage, rowHighlights: externalRowHighlights, cellComments: externalCellComments, rowActions, toolbarMenuItems, serverSide, totalItems, currentPage: controlledCurrentPage, pageSize: controlledPageSize, sortConfig: controlledSortConfig, onPageChange, filters: controlledFilters, }: SpreadsheetProps<T>): react_jsx_runtime.JSX.Element;
|
|
633
|
+
declare function Spreadsheet<T extends Record<string, any>>({ data, columns, columnGroups, getRowId, onCellsEdit, onSelectionChange, onSortChange, onFilterChange, onRowClick, onRowDoubleClick, onRowClone, onRowDelete, onAddCellComment, onToggleCommentResolved, onRowHighlight, onColumnHighlight, onCellHighlight, showToolbar, showPagination, enableRowSelection, enableCellEditing, enableComments, enableHighlighting, enableUndoRedo, pageSizeOptions, onSave, settings: initialSettings, onSettingsChange, isLoading, className, emptyMessage, rowHighlights: externalRowHighlights, columnHighlights: externalColumnHighlights, cellHighlights: externalCellHighlights, cellComments: externalCellComments, rowActions, toolbarMenuItems, serverSide, totalItems, currentPage: controlledCurrentPage, pageSize: controlledPageSize, sortConfig: controlledSortConfig, onPageChange, filters: controlledFilters, }: SpreadsheetProps<T>): react_jsx_runtime.JSX.Element;
|
|
624
634
|
declare namespace Spreadsheet {
|
|
625
635
|
var displayName: string;
|
|
626
636
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -277,8 +277,14 @@ interface SpreadsheetProps<T = any> {
|
|
|
277
277
|
onRowDelete?: (row: T, rowId: string | number) => void;
|
|
278
278
|
/** Callback when a cell comment is added */
|
|
279
279
|
onAddCellComment?: (rowId: string | number, columnId: string, comment: string) => void;
|
|
280
|
+
/** Callback when a comment's resolved status is toggled */
|
|
281
|
+
onToggleCommentResolved?: (commentId: string) => void;
|
|
280
282
|
/** Callback when row highlight is toggled */
|
|
281
283
|
onRowHighlight?: (rowId: string | number, color: string | null) => void;
|
|
284
|
+
/** Callback when column highlight is toggled */
|
|
285
|
+
onColumnHighlight?: (columnId: string, color: string | null) => void;
|
|
286
|
+
/** Callback when cell highlight is toggled */
|
|
287
|
+
onCellHighlight?: (rowId: string | number, columnId: string, color: string | null) => void;
|
|
282
288
|
/** Whether to show the toolbar */
|
|
283
289
|
showToolbar?: boolean;
|
|
284
290
|
/** Whether to show pagination */
|
|
@@ -329,6 +335,10 @@ interface SpreadsheetProps<T = any> {
|
|
|
329
335
|
emptyMessage?: string;
|
|
330
336
|
/** Row highlights (externally controlled) */
|
|
331
337
|
rowHighlights?: CellHighlight[];
|
|
338
|
+
/** Column highlights (externally controlled) */
|
|
339
|
+
columnHighlights?: Record<string, string>;
|
|
340
|
+
/** Cell highlights (externally controlled) */
|
|
341
|
+
cellHighlights?: CellHighlight[];
|
|
332
342
|
/** Cell comments (externally controlled) */
|
|
333
343
|
cellComments?: CellComment[];
|
|
334
344
|
/** Custom row actions to display in the index column */
|
|
@@ -620,7 +630,7 @@ interface SpreadsheetColumnGroupHeaderProps {
|
|
|
620
630
|
* />
|
|
621
631
|
* ```
|
|
622
632
|
*/
|
|
623
|
-
declare function Spreadsheet<T extends Record<string, any>>({ data, columns, columnGroups, getRowId, onCellsEdit, onSelectionChange, onSortChange, onFilterChange, onRowClick, onRowDoubleClick, onRowClone, onRowDelete, onAddCellComment, onRowHighlight, showToolbar, showPagination, enableRowSelection, enableCellEditing, enableComments, enableHighlighting, enableUndoRedo, pageSizeOptions, onSave, settings: initialSettings, onSettingsChange, isLoading, className, emptyMessage, rowHighlights: externalRowHighlights, cellComments: externalCellComments, rowActions, toolbarMenuItems, serverSide, totalItems, currentPage: controlledCurrentPage, pageSize: controlledPageSize, sortConfig: controlledSortConfig, onPageChange, filters: controlledFilters, }: SpreadsheetProps<T>): react_jsx_runtime.JSX.Element;
|
|
633
|
+
declare function Spreadsheet<T extends Record<string, any>>({ data, columns, columnGroups, getRowId, onCellsEdit, onSelectionChange, onSortChange, onFilterChange, onRowClick, onRowDoubleClick, onRowClone, onRowDelete, onAddCellComment, onToggleCommentResolved, onRowHighlight, onColumnHighlight, onCellHighlight, showToolbar, showPagination, enableRowSelection, enableCellEditing, enableComments, enableHighlighting, enableUndoRedo, pageSizeOptions, onSave, settings: initialSettings, onSettingsChange, isLoading, className, emptyMessage, rowHighlights: externalRowHighlights, columnHighlights: externalColumnHighlights, cellHighlights: externalCellHighlights, cellComments: externalCellComments, rowActions, toolbarMenuItems, serverSide, totalItems, currentPage: controlledCurrentPage, pageSize: controlledPageSize, sortConfig: controlledSortConfig, onPageChange, filters: controlledFilters, }: SpreadsheetProps<T>): react_jsx_runtime.JSX.Element;
|
|
624
634
|
declare namespace Spreadsheet {
|
|
625
635
|
var displayName: string;
|
|
626
636
|
}
|
package/dist/index.js
CHANGED
|
@@ -1492,15 +1492,21 @@ var HIGHLIGHT_COLORS = {
|
|
|
1492
1492
|
};
|
|
1493
1493
|
function useSpreadsheetHighlighting({
|
|
1494
1494
|
externalRowHighlights,
|
|
1495
|
-
onRowHighlight
|
|
1495
|
+
onRowHighlight,
|
|
1496
|
+
externalColumnHighlights,
|
|
1497
|
+
onColumnHighlight,
|
|
1498
|
+
externalCellHighlights,
|
|
1499
|
+
onCellHighlight
|
|
1496
1500
|
} = {}) {
|
|
1497
|
-
const [
|
|
1501
|
+
const [cellHighlightsInternal, setCellHighlightsInternal] = (0, import_react7.useState)([]);
|
|
1498
1502
|
const [rowHighlightsInternal, setRowHighlightsInternal] = (0, import_react7.useState)([]);
|
|
1499
|
-
const [
|
|
1503
|
+
const [columnHighlightsInternal, setColumnHighlightsInternal] = (0, import_react7.useState)({});
|
|
1500
1504
|
const [highlightPickerRow, setHighlightPickerRow] = (0, import_react7.useState)(null);
|
|
1501
1505
|
const [highlightPickerColumn, setHighlightPickerColumn] = (0, import_react7.useState)(null);
|
|
1502
1506
|
const [highlightPickerCell, setHighlightPickerCell] = (0, import_react7.useState)(null);
|
|
1507
|
+
const cellHighlights = externalCellHighlights || cellHighlightsInternal;
|
|
1503
1508
|
const rowHighlights = externalRowHighlights || rowHighlightsInternal;
|
|
1509
|
+
const columnHighlights = externalColumnHighlights || columnHighlightsInternal;
|
|
1504
1510
|
const getCellHighlight = (0, import_react7.useCallback)(
|
|
1505
1511
|
(rowId, columnId) => {
|
|
1506
1512
|
return cellHighlights.find((h) => h.rowId === rowId && h.columnId === columnId)?.color;
|
|
@@ -1509,24 +1515,28 @@ function useSpreadsheetHighlighting({
|
|
|
1509
1515
|
);
|
|
1510
1516
|
const handleCellHighlightToggle = (0, import_react7.useCallback)(
|
|
1511
1517
|
(rowId, columnId, color = "#fef08a") => {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1518
|
+
if (onCellHighlight) {
|
|
1519
|
+
onCellHighlight(rowId, columnId, color);
|
|
1520
|
+
} else {
|
|
1521
|
+
setCellHighlightsInternal((prev) => {
|
|
1522
|
+
const existing = prev.find((h) => h.rowId === rowId && h.columnId === columnId);
|
|
1523
|
+
if (existing) {
|
|
1524
|
+
if (color === null) {
|
|
1525
|
+
return prev.filter((h) => !(h.rowId === rowId && h.columnId === columnId));
|
|
1526
|
+
}
|
|
1527
|
+
return prev.map(
|
|
1528
|
+
(h) => h.rowId === rowId && h.columnId === columnId ? { ...h, color } : h
|
|
1529
|
+
);
|
|
1517
1530
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
}
|
|
1525
|
-
return prev;
|
|
1526
|
-
});
|
|
1531
|
+
if (color) {
|
|
1532
|
+
return [...prev, { rowId, columnId, color }];
|
|
1533
|
+
}
|
|
1534
|
+
return prev;
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1527
1537
|
setHighlightPickerCell(null);
|
|
1528
1538
|
},
|
|
1529
|
-
[]
|
|
1539
|
+
[onCellHighlight]
|
|
1530
1540
|
);
|
|
1531
1541
|
const getRowHighlight = (0, import_react7.useCallback)(
|
|
1532
1542
|
(rowId) => {
|
|
@@ -1565,22 +1575,29 @@ function useSpreadsheetHighlighting({
|
|
|
1565
1575
|
},
|
|
1566
1576
|
[columnHighlights]
|
|
1567
1577
|
);
|
|
1568
|
-
const handleColumnHighlightToggle = (0, import_react7.useCallback)(
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
delete newHighlights[columnId];
|
|
1578
|
+
const handleColumnHighlightToggle = (0, import_react7.useCallback)(
|
|
1579
|
+
(columnId, color) => {
|
|
1580
|
+
if (onColumnHighlight) {
|
|
1581
|
+
onColumnHighlight(columnId, color);
|
|
1573
1582
|
} else {
|
|
1574
|
-
|
|
1583
|
+
setColumnHighlightsInternal((prev) => {
|
|
1584
|
+
const newHighlights = { ...prev };
|
|
1585
|
+
if (color === null) {
|
|
1586
|
+
delete newHighlights[columnId];
|
|
1587
|
+
} else {
|
|
1588
|
+
newHighlights[columnId] = color;
|
|
1589
|
+
}
|
|
1590
|
+
return newHighlights;
|
|
1591
|
+
});
|
|
1575
1592
|
}
|
|
1576
|
-
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
|
|
1593
|
+
setHighlightPickerColumn(null);
|
|
1594
|
+
},
|
|
1595
|
+
[onColumnHighlight]
|
|
1596
|
+
);
|
|
1580
1597
|
const clearAllHighlights = (0, import_react7.useCallback)(() => {
|
|
1581
|
-
|
|
1598
|
+
setCellHighlightsInternal([]);
|
|
1582
1599
|
setRowHighlightsInternal([]);
|
|
1583
|
-
|
|
1600
|
+
setColumnHighlightsInternal({});
|
|
1584
1601
|
}, []);
|
|
1585
1602
|
return {
|
|
1586
1603
|
// Cell highlights
|
|
@@ -2502,7 +2519,8 @@ function useSpreadsheetFiltering({
|
|
|
2502
2519
|
var import_react12 = require("react");
|
|
2503
2520
|
function useSpreadsheetComments({
|
|
2504
2521
|
externalCellComments,
|
|
2505
|
-
onAddCellComment
|
|
2522
|
+
onAddCellComment,
|
|
2523
|
+
onToggleCommentResolved
|
|
2506
2524
|
} = {}) {
|
|
2507
2525
|
const [cellCommentsInternal, setCellCommentsInternal] = (0, import_react12.useState)([]);
|
|
2508
2526
|
const [commentModalCell, setCommentModalCell] = (0, import_react12.useState)(null);
|
|
@@ -2550,11 +2568,18 @@ function useSpreadsheetComments({
|
|
|
2550
2568
|
},
|
|
2551
2569
|
[onAddCellComment]
|
|
2552
2570
|
);
|
|
2553
|
-
const handleToggleCommentResolved = (0, import_react12.useCallback)(
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2571
|
+
const handleToggleCommentResolved = (0, import_react12.useCallback)(
|
|
2572
|
+
(commentId) => {
|
|
2573
|
+
if (onToggleCommentResolved) {
|
|
2574
|
+
onToggleCommentResolved(commentId);
|
|
2575
|
+
} else {
|
|
2576
|
+
setCellCommentsInternal(
|
|
2577
|
+
(prev) => prev.map((c) => c.id === commentId ? { ...c, resolved: !c.resolved } : c)
|
|
2578
|
+
);
|
|
2579
|
+
}
|
|
2580
|
+
},
|
|
2581
|
+
[onToggleCommentResolved]
|
|
2582
|
+
);
|
|
2558
2583
|
return {
|
|
2559
2584
|
// Comments data
|
|
2560
2585
|
cellComments,
|
|
@@ -3296,7 +3321,10 @@ function Spreadsheet({
|
|
|
3296
3321
|
onRowClone,
|
|
3297
3322
|
onRowDelete,
|
|
3298
3323
|
onAddCellComment,
|
|
3324
|
+
onToggleCommentResolved,
|
|
3299
3325
|
onRowHighlight,
|
|
3326
|
+
onColumnHighlight,
|
|
3327
|
+
onCellHighlight,
|
|
3300
3328
|
showToolbar = true,
|
|
3301
3329
|
showPagination = true,
|
|
3302
3330
|
enableRowSelection = true,
|
|
@@ -3312,6 +3340,8 @@ function Spreadsheet({
|
|
|
3312
3340
|
className,
|
|
3313
3341
|
emptyMessage = "No data available",
|
|
3314
3342
|
rowHighlights: externalRowHighlights,
|
|
3343
|
+
columnHighlights: externalColumnHighlights,
|
|
3344
|
+
cellHighlights: externalCellHighlights,
|
|
3315
3345
|
cellComments: externalCellComments,
|
|
3316
3346
|
rowActions,
|
|
3317
3347
|
toolbarMenuItems,
|
|
@@ -3368,7 +3398,11 @@ function Spreadsheet({
|
|
|
3368
3398
|
setHighlightPickerCell
|
|
3369
3399
|
} = useSpreadsheetHighlighting({
|
|
3370
3400
|
externalRowHighlights,
|
|
3371
|
-
onRowHighlight
|
|
3401
|
+
onRowHighlight,
|
|
3402
|
+
externalColumnHighlights,
|
|
3403
|
+
onColumnHighlight,
|
|
3404
|
+
externalCellHighlights,
|
|
3405
|
+
onCellHighlight
|
|
3372
3406
|
});
|
|
3373
3407
|
const {
|
|
3374
3408
|
pinnedColumns,
|
|
@@ -3398,7 +3432,8 @@ function Spreadsheet({
|
|
|
3398
3432
|
handleToggleCommentResolved
|
|
3399
3433
|
} = useSpreadsheetComments({
|
|
3400
3434
|
externalCellComments,
|
|
3401
|
-
onAddCellComment
|
|
3435
|
+
onAddCellComment,
|
|
3436
|
+
onToggleCommentResolved
|
|
3402
3437
|
});
|
|
3403
3438
|
const [showSettingsModal, setShowSettingsModal] = (0, import_react16.useState)(false);
|
|
3404
3439
|
const {
|