@xcelsior/ui-spreadsheets 1.1.0 → 1.1.2

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
@@ -620,7 +620,7 @@ interface SpreadsheetColumnGroupHeaderProps {
620
620
  * />
621
621
  * ```
622
622
  */
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, onPageChange, filters: controlledFilters, }: SpreadsheetProps<T>): react_jsx_runtime.JSX.Element;
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;
624
624
  declare namespace Spreadsheet {
625
625
  var displayName: string;
626
626
  }
package/dist/index.d.ts CHANGED
@@ -620,7 +620,7 @@ interface SpreadsheetColumnGroupHeaderProps {
620
620
  * />
621
621
  * ```
622
622
  */
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, onPageChange, filters: controlledFilters, }: SpreadsheetProps<T>): react_jsx_runtime.JSX.Element;
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;
624
624
  declare namespace Spreadsheet {
625
625
  var displayName: string;
626
626
  }
package/dist/index.js CHANGED
@@ -370,7 +370,7 @@ var SpreadsheetCell = ({
370
370
  onKeyDown: handleCellKeyDown,
371
371
  "data-cell-id": `${rowId}-${column.id}`,
372
372
  className: cn(
373
- "border border-gray-200 group cursor-pointer select-none",
373
+ "border border-gray-200 group cursor-pointer transition-colors select-none",
374
374
  compactMode ? "text-[10px]" : "text-xs",
375
375
  cellPadding,
376
376
  column.align === "right" && "text-right",
@@ -1280,22 +1280,17 @@ function useSpreadsheetPinning({
1280
1280
  columns,
1281
1281
  columnGroups,
1282
1282
  showRowIndex = true,
1283
- defaultPinnedColumns = [],
1284
- defaultPinRowIndex = false
1283
+ defaultPinnedColumns = []
1285
1284
  }) {
1286
1285
  const [pinnedColumns, setPinnedColumns] = (0, import_react6.useState)(() => {
1287
1286
  const map = /* @__PURE__ */ new Map();
1288
1287
  defaultPinnedColumns.forEach((col) => {
1289
- if (col !== ROW_INDEX_COLUMN_ID) {
1290
- map.set(col, "left");
1291
- }
1288
+ map.set(col, "left");
1292
1289
  });
1293
1290
  return map;
1294
1291
  });
1295
- const [isRowIndexPinned, setIsRowIndexPinned] = (0, import_react6.useState)(
1296
- defaultPinRowIndex || defaultPinnedColumns.includes(ROW_INDEX_COLUMN_ID)
1297
- );
1298
1292
  const [collapsedGroups, setCollapsedGroups] = (0, import_react6.useState)(/* @__PURE__ */ new Set());
1293
+ const isRowIndexPinned = pinnedColumns.has(ROW_INDEX_COLUMN_ID);
1299
1294
  const handleTogglePin = (0, import_react6.useCallback)((columnId) => {
1300
1295
  setPinnedColumns((prev) => {
1301
1296
  const newMap = new Map(prev);
@@ -1307,21 +1302,12 @@ function useSpreadsheetPinning({
1307
1302
  return newMap;
1308
1303
  });
1309
1304
  }, []);
1310
- const handleToggleRowIndexPin = (0, import_react6.useCallback)(() => {
1311
- setIsRowIndexPinned((prev) => !prev);
1312
- }, []);
1313
1305
  const setPinnedColumnsFromIds = (0, import_react6.useCallback)((columnIds) => {
1314
1306
  const map = /* @__PURE__ */ new Map();
1315
1307
  columnIds.forEach((col) => {
1316
- if (col !== ROW_INDEX_COLUMN_ID) {
1317
- map.set(col, "left");
1318
- }
1308
+ map.set(col, "left");
1319
1309
  });
1320
1310
  setPinnedColumns(map);
1321
- setIsRowIndexPinned(columnIds.includes(ROW_INDEX_COLUMN_ID));
1322
- }, []);
1323
- const setRowIndexPinned = (0, import_react6.useCallback)((pinned) => {
1324
- setIsRowIndexPinned(pinned);
1325
1311
  }, []);
1326
1312
  const handleToggleGroupCollapse = (0, import_react6.useCallback)((groupId) => {
1327
1313
  setCollapsedGroups((prev) => {
@@ -1347,14 +1333,17 @@ function useSpreadsheetPinning({
1347
1333
  return pinnedColumns.has(column.id);
1348
1334
  });
1349
1335
  }
1350
- if (pinnedColumns.size === 0) {
1336
+ const nonRowIndexPinned = Array.from(pinnedColumns.keys()).filter(
1337
+ (id) => id !== ROW_INDEX_COLUMN_ID
1338
+ );
1339
+ if (nonRowIndexPinned.length === 0) {
1351
1340
  return result;
1352
1341
  }
1353
1342
  const leftPinned = [];
1354
1343
  const unpinned = [];
1355
1344
  const rightPinned = [];
1356
- const pinnedLeftIds = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "left").map(([id]) => id);
1357
- const pinnedRightIds = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "right").map(([id]) => id);
1345
+ const pinnedLeftIds = Array.from(pinnedColumns.entries()).filter(([id, side]) => side === "left" && id !== ROW_INDEX_COLUMN_ID).map(([id]) => id);
1346
+ const pinnedRightIds = Array.from(pinnedColumns.entries()).filter(([id, side]) => side === "right" && id !== ROW_INDEX_COLUMN_ID).map(([id]) => id);
1358
1347
  for (const column of result) {
1359
1348
  const pinSide = pinnedColumns.get(column.id);
1360
1349
  if (pinSide === "left") {
@@ -1369,23 +1358,24 @@ function useSpreadsheetPinning({
1369
1358
  rightPinned.sort((a, b) => pinnedRightIds.indexOf(a.id) - pinnedRightIds.indexOf(b.id));
1370
1359
  return [...leftPinned, ...unpinned, ...rightPinned];
1371
1360
  }, [columns, columnGroups, collapsedGroups, pinnedColumns]);
1372
- const getRowIndexLeftOffset = (0, import_react6.useCallback)(() => {
1373
- return 0;
1374
- }, []);
1375
1361
  const getColumnLeftOffset = (0, import_react6.useCallback)(
1376
1362
  (columnId) => {
1377
- const pinnedLeft = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "left").map(([id]) => id);
1363
+ if (columnId === ROW_INDEX_COLUMN_ID) {
1364
+ return 0;
1365
+ }
1366
+ const pinnedLeft = Array.from(pinnedColumns.entries()).filter(([id, side]) => side === "left" && id !== ROW_INDEX_COLUMN_ID).map(([id]) => id);
1378
1367
  const index = pinnedLeft.indexOf(columnId);
1379
- const baseOffset = showRowIndex && isRowIndexPinned ? ROW_INDEX_COLUMN_WIDTH : 0;
1368
+ const isRowIndexPinnedNow = pinnedColumns.has(ROW_INDEX_COLUMN_ID);
1369
+ const baseOffset = showRowIndex && isRowIndexPinnedNow ? ROW_INDEX_COLUMN_WIDTH : 0;
1380
1370
  if (index === -1) return baseOffset;
1381
1371
  let offset = baseOffset;
1382
1372
  for (let i = 0; i < index; i++) {
1383
1373
  const col = columns.find((c) => c.id === pinnedLeft[i]);
1384
- offset += col?.width || col?.minWidth || 100;
1374
+ offset += col?.minWidth || col?.width || 100;
1385
1375
  }
1386
1376
  return offset;
1387
1377
  },
1388
- [pinnedColumns, columns, showRowIndex, isRowIndexPinned]
1378
+ [pinnedColumns, columns, showRowIndex]
1389
1379
  );
1390
1380
  const isColumnPinned = (0, import_react6.useCallback)(
1391
1381
  (columnId) => {
@@ -1405,12 +1395,9 @@ function useSpreadsheetPinning({
1405
1395
  collapsedGroups,
1406
1396
  visibleColumns,
1407
1397
  handleTogglePin,
1408
- handleToggleRowIndexPin,
1409
1398
  handleToggleGroupCollapse,
1410
1399
  setPinnedColumnsFromIds,
1411
- setRowIndexPinned,
1412
1400
  getColumnLeftOffset,
1413
- getRowIndexLeftOffset,
1414
1401
  isColumnPinned,
1415
1402
  getColumnPinSide
1416
1403
  };
@@ -3347,6 +3334,7 @@ function Spreadsheet({
3347
3334
  totalItems,
3348
3335
  currentPage: controlledCurrentPage,
3349
3336
  pageSize: controlledPageSize,
3337
+ sortConfig: controlledSortConfig,
3350
3338
  onPageChange,
3351
3339
  filters: controlledFilters
3352
3340
  }) {
@@ -3376,7 +3364,7 @@ function Spreadsheet({
3376
3364
  onSortChange,
3377
3365
  serverSide,
3378
3366
  controlledFilters,
3379
- controlledSortConfig: spreadsheetSettings?.defaultSort
3367
+ controlledSortConfig: controlledSortConfig ?? spreadsheetSettings?.defaultSort
3380
3368
  });
3381
3369
  const {
3382
3370
  getCellHighlight,
@@ -3408,7 +3396,8 @@ function Spreadsheet({
3408
3396
  getColumnPinSide
3409
3397
  } = useSpreadsheetPinning({
3410
3398
  columns,
3411
- columnGroups
3399
+ columnGroups,
3400
+ defaultPinnedColumns: initialSettings?.defaultPinnedColumns
3412
3401
  });
3413
3402
  const {
3414
3403
  getCellComments,
@@ -3477,6 +3466,27 @@ function Spreadsheet({
3477
3466
  defaultSort: sortConfig
3478
3467
  }));
3479
3468
  }, [sortConfig]);
3469
+ (0, import_react16.useEffect)(() => {
3470
+ const pinnedColumnIds = Array.from(pinnedColumns.keys());
3471
+ setSpreadsheetSettings((prev) => {
3472
+ const prevIds = prev.defaultPinnedColumns;
3473
+ if (prevIds.length === pinnedColumnIds.length && prevIds.every((id, idx) => id === pinnedColumnIds[idx])) {
3474
+ return prev;
3475
+ }
3476
+ return {
3477
+ ...prev,
3478
+ defaultPinnedColumns: pinnedColumnIds
3479
+ };
3480
+ });
3481
+ }, [pinnedColumns]);
3482
+ const isInitialMount = (0, import_react16.useRef)(true);
3483
+ (0, import_react16.useEffect)(() => {
3484
+ if (isInitialMount.current) {
3485
+ isInitialMount.current = false;
3486
+ return;
3487
+ }
3488
+ onSettingsChange?.(spreadsheetSettings);
3489
+ }, [spreadsheetSettings, onSettingsChange]);
3480
3490
  const applyUndo = (0, import_react16.useCallback)(() => {
3481
3491
  const entry = popUndoEntry();
3482
3492
  if (!entry || !onCellsEdit) return;