@xcelsior/ui-spreadsheets 1.1.2 → 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 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
@@ -1121,71 +1121,56 @@ function ColumnHeaderActions({
1121
1121
  unpinnedTitle = "Pin column",
1122
1122
  className
1123
1123
  }) {
1124
- const handleClick = (e) => {
1125
- e.stopPropagation();
1126
- };
1127
- const handleKeyDown = (e) => {
1128
- e.stopPropagation();
1129
- };
1130
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1131
- "button",
1132
- {
1133
- type: "button",
1134
- className: cn("flex items-center gap-0.5", className),
1135
- onClick: handleClick,
1136
- onKeyDown: handleKeyDown,
1137
- children: [
1138
- enableFiltering && onFilterClick && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1139
- "button",
1140
- {
1141
- type: "button",
1142
- onClick: (e) => {
1143
- e.stopPropagation();
1144
- onFilterClick();
1145
- },
1146
- className: cn(
1147
- "p-0.5 hover:bg-gray-200 rounded transition-opacity",
1148
- hasActiveFilter ? "text-blue-600 opacity-100" : "text-gray-400 opacity-0 group-hover:opacity-100"
1149
- ),
1150
- title: filterTitle,
1151
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HiFilter, { className: "h-3 w-3" })
1152
- }
1124
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: cn("flex items-center gap-0.5", className), children: [
1125
+ enableFiltering && onFilterClick && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1126
+ "button",
1127
+ {
1128
+ type: "button",
1129
+ onClick: (e) => {
1130
+ e.stopPropagation();
1131
+ onFilterClick();
1132
+ },
1133
+ className: cn(
1134
+ "p-0.5 hover:bg-gray-200 rounded transition-opacity",
1135
+ hasActiveFilter ? "text-blue-600 opacity-100" : "text-gray-400 opacity-0 group-hover:opacity-100"
1153
1136
  ),
1154
- enableHighlighting && onHighlightClick && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1155
- "button",
1156
- {
1157
- type: "button",
1158
- onClick: (e) => {
1159
- e.stopPropagation();
1160
- onHighlightClick();
1161
- },
1162
- className: cn(
1163
- "p-0.5 hover:bg-gray-200 rounded transition-opacity",
1164
- hasActiveHighlight ? "text-amber-500 opacity-100" : "text-gray-400 opacity-0 group-hover:opacity-100"
1165
- ),
1166
- title: highlightTitle,
1167
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AiFillHighlight, { className: "h-3 w-3" })
1168
- }
1137
+ title: filterTitle,
1138
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HiFilter, { className: "h-3 w-3" })
1139
+ }
1140
+ ),
1141
+ enableHighlighting && onHighlightClick && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1142
+ "button",
1143
+ {
1144
+ type: "button",
1145
+ onClick: (e) => {
1146
+ e.stopPropagation();
1147
+ onHighlightClick();
1148
+ },
1149
+ className: cn(
1150
+ "p-0.5 hover:bg-gray-200 rounded transition-opacity",
1151
+ hasActiveHighlight ? "text-amber-500 opacity-100" : "text-gray-400 opacity-0 group-hover:opacity-100"
1169
1152
  ),
1170
- enablePinning && onPinClick && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1171
- "button",
1172
- {
1173
- type: "button",
1174
- onClick: (e) => {
1175
- e.stopPropagation();
1176
- onPinClick();
1177
- },
1178
- className: cn(
1179
- "p-0.5 hover:bg-gray-200 rounded transition-opacity",
1180
- isPinned ? "text-blue-600 opacity-100" : "text-gray-400 opacity-0 group-hover:opacity-100"
1181
- ),
1182
- title: isPinned ? pinnedTitle : unpinnedTitle,
1183
- children: isPinned ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MdPushPin, { className: "h-3 w-3" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MdOutlinePushPin, { className: "h-3 w-3" })
1184
- }
1185
- )
1186
- ]
1187
- }
1188
- );
1153
+ title: highlightTitle,
1154
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AiFillHighlight, { className: "h-3 w-3" })
1155
+ }
1156
+ ),
1157
+ enablePinning && onPinClick && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1158
+ "button",
1159
+ {
1160
+ type: "button",
1161
+ onClick: (e) => {
1162
+ e.stopPropagation();
1163
+ onPinClick();
1164
+ },
1165
+ className: cn(
1166
+ "p-0.5 hover:bg-gray-200 rounded transition-opacity",
1167
+ isPinned ? "text-blue-600 opacity-100" : "text-gray-400 opacity-0 group-hover:opacity-100"
1168
+ ),
1169
+ title: isPinned ? pinnedTitle : unpinnedTitle,
1170
+ children: isPinned ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MdPushPin, { className: "h-3 w-3" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MdOutlinePushPin, { className: "h-3 w-3" })
1171
+ }
1172
+ )
1173
+ ] });
1189
1174
  }
1190
1175
  ColumnHeaderActions.displayName = "ColumnHeaderActions";
1191
1176
 
@@ -1507,15 +1492,21 @@ var HIGHLIGHT_COLORS = {
1507
1492
  };
1508
1493
  function useSpreadsheetHighlighting({
1509
1494
  externalRowHighlights,
1510
- onRowHighlight
1495
+ onRowHighlight,
1496
+ externalColumnHighlights,
1497
+ onColumnHighlight,
1498
+ externalCellHighlights,
1499
+ onCellHighlight
1511
1500
  } = {}) {
1512
- const [cellHighlights, setCellHighlights] = (0, import_react7.useState)([]);
1501
+ const [cellHighlightsInternal, setCellHighlightsInternal] = (0, import_react7.useState)([]);
1513
1502
  const [rowHighlightsInternal, setRowHighlightsInternal] = (0, import_react7.useState)([]);
1514
- const [columnHighlights, setColumnHighlights] = (0, import_react7.useState)({});
1503
+ const [columnHighlightsInternal, setColumnHighlightsInternal] = (0, import_react7.useState)({});
1515
1504
  const [highlightPickerRow, setHighlightPickerRow] = (0, import_react7.useState)(null);
1516
1505
  const [highlightPickerColumn, setHighlightPickerColumn] = (0, import_react7.useState)(null);
1517
1506
  const [highlightPickerCell, setHighlightPickerCell] = (0, import_react7.useState)(null);
1507
+ const cellHighlights = externalCellHighlights || cellHighlightsInternal;
1518
1508
  const rowHighlights = externalRowHighlights || rowHighlightsInternal;
1509
+ const columnHighlights = externalColumnHighlights || columnHighlightsInternal;
1519
1510
  const getCellHighlight = (0, import_react7.useCallback)(
1520
1511
  (rowId, columnId) => {
1521
1512
  return cellHighlights.find((h) => h.rowId === rowId && h.columnId === columnId)?.color;
@@ -1524,24 +1515,28 @@ function useSpreadsheetHighlighting({
1524
1515
  );
1525
1516
  const handleCellHighlightToggle = (0, import_react7.useCallback)(
1526
1517
  (rowId, columnId, color = "#fef08a") => {
1527
- setCellHighlights((prev) => {
1528
- const existing = prev.find((h) => h.rowId === rowId && h.columnId === columnId);
1529
- if (existing) {
1530
- if (color === null) {
1531
- return prev.filter((h) => !(h.rowId === rowId && h.columnId === columnId));
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
+ );
1532
1530
  }
1533
- return prev.map(
1534
- (h) => h.rowId === rowId && h.columnId === columnId ? { ...h, color } : h
1535
- );
1536
- }
1537
- if (color) {
1538
- return [...prev, { rowId, columnId, color }];
1539
- }
1540
- return prev;
1541
- });
1531
+ if (color) {
1532
+ return [...prev, { rowId, columnId, color }];
1533
+ }
1534
+ return prev;
1535
+ });
1536
+ }
1542
1537
  setHighlightPickerCell(null);
1543
1538
  },
1544
- []
1539
+ [onCellHighlight]
1545
1540
  );
1546
1541
  const getRowHighlight = (0, import_react7.useCallback)(
1547
1542
  (rowId) => {
@@ -1580,22 +1575,29 @@ function useSpreadsheetHighlighting({
1580
1575
  },
1581
1576
  [columnHighlights]
1582
1577
  );
1583
- const handleColumnHighlightToggle = (0, import_react7.useCallback)((columnId, color) => {
1584
- setColumnHighlights((prev) => {
1585
- const newHighlights = { ...prev };
1586
- if (color === null) {
1587
- delete newHighlights[columnId];
1578
+ const handleColumnHighlightToggle = (0, import_react7.useCallback)(
1579
+ (columnId, color) => {
1580
+ if (onColumnHighlight) {
1581
+ onColumnHighlight(columnId, color);
1588
1582
  } else {
1589
- newHighlights[columnId] = color;
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
+ });
1590
1592
  }
1591
- return newHighlights;
1592
- });
1593
- setHighlightPickerColumn(null);
1594
- }, []);
1593
+ setHighlightPickerColumn(null);
1594
+ },
1595
+ [onColumnHighlight]
1596
+ );
1595
1597
  const clearAllHighlights = (0, import_react7.useCallback)(() => {
1596
- setCellHighlights([]);
1598
+ setCellHighlightsInternal([]);
1597
1599
  setRowHighlightsInternal([]);
1598
- setColumnHighlights({});
1600
+ setColumnHighlightsInternal({});
1599
1601
  }, []);
1600
1602
  return {
1601
1603
  // Cell highlights
@@ -2230,13 +2232,14 @@ function useSpreadsheetFiltering({
2230
2232
  onSortChange,
2231
2233
  serverSide = false,
2232
2234
  controlledFilters,
2233
- controlledSortConfig
2235
+ controlledSortConfig,
2236
+ defaultSortConfig
2234
2237
  }) {
2235
2238
  const [internalFilters, setInternalFilters] = (0, import_react11.useState)(
2236
2239
  {}
2237
2240
  );
2238
2241
  const [internalSortConfig, setInternalSortConfig] = (0, import_react11.useState)(
2239
- null
2242
+ defaultSortConfig ?? null
2240
2243
  );
2241
2244
  const [activeFilterColumn, setActiveFilterColumn] = (0, import_react11.useState)(null);
2242
2245
  const filters = controlledFilters ?? internalFilters;
@@ -2516,7 +2519,8 @@ function useSpreadsheetFiltering({
2516
2519
  var import_react12 = require("react");
2517
2520
  function useSpreadsheetComments({
2518
2521
  externalCellComments,
2519
- onAddCellComment
2522
+ onAddCellComment,
2523
+ onToggleCommentResolved
2520
2524
  } = {}) {
2521
2525
  const [cellCommentsInternal, setCellCommentsInternal] = (0, import_react12.useState)([]);
2522
2526
  const [commentModalCell, setCommentModalCell] = (0, import_react12.useState)(null);
@@ -2564,11 +2568,18 @@ function useSpreadsheetComments({
2564
2568
  },
2565
2569
  [onAddCellComment]
2566
2570
  );
2567
- const handleToggleCommentResolved = (0, import_react12.useCallback)((commentId) => {
2568
- setCellCommentsInternal(
2569
- (prev) => prev.map((c) => c.id === commentId ? { ...c, resolved: !c.resolved } : c)
2570
- );
2571
- }, []);
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
+ );
2572
2583
  return {
2573
2584
  // Comments data
2574
2585
  cellComments,
@@ -3310,7 +3321,10 @@ function Spreadsheet({
3310
3321
  onRowClone,
3311
3322
  onRowDelete,
3312
3323
  onAddCellComment,
3324
+ onToggleCommentResolved,
3313
3325
  onRowHighlight,
3326
+ onColumnHighlight,
3327
+ onCellHighlight,
3314
3328
  showToolbar = true,
3315
3329
  showPagination = true,
3316
3330
  enableRowSelection = true,
@@ -3326,6 +3340,8 @@ function Spreadsheet({
3326
3340
  className,
3327
3341
  emptyMessage = "No data available",
3328
3342
  rowHighlights: externalRowHighlights,
3343
+ columnHighlights: externalColumnHighlights,
3344
+ cellHighlights: externalCellHighlights,
3329
3345
  cellComments: externalCellComments,
3330
3346
  rowActions,
3331
3347
  toolbarMenuItems,
@@ -3364,7 +3380,8 @@ function Spreadsheet({
3364
3380
  onSortChange,
3365
3381
  serverSide,
3366
3382
  controlledFilters,
3367
- controlledSortConfig: controlledSortConfig ?? spreadsheetSettings?.defaultSort
3383
+ controlledSortConfig,
3384
+ defaultSortConfig: spreadsheetSettings.defaultSort
3368
3385
  });
3369
3386
  const {
3370
3387
  getCellHighlight,
@@ -3381,7 +3398,11 @@ function Spreadsheet({
3381
3398
  setHighlightPickerCell
3382
3399
  } = useSpreadsheetHighlighting({
3383
3400
  externalRowHighlights,
3384
- onRowHighlight
3401
+ onRowHighlight,
3402
+ externalColumnHighlights,
3403
+ onColumnHighlight,
3404
+ externalCellHighlights,
3405
+ onCellHighlight
3385
3406
  });
3386
3407
  const {
3387
3408
  pinnedColumns,
@@ -3411,7 +3432,8 @@ function Spreadsheet({
3411
3432
  handleToggleCommentResolved
3412
3433
  } = useSpreadsheetComments({
3413
3434
  externalCellComments,
3414
- onAddCellComment
3435
+ onAddCellComment,
3436
+ onToggleCommentResolved
3415
3437
  });
3416
3438
  const [showSettingsModal, setShowSettingsModal] = (0, import_react16.useState)(false);
3417
3439
  const {