@xcelsior/ui-spreadsheets 1.1.1 → 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.js +42 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Spreadsheet.tsx +30 -0
- package/src/components/SpreadsheetCell.tsx +1 -1
- package/src/hooks/useSpreadsheetPinning.ts +26 -45
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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?.
|
|
1374
|
+
offset += col?.minWidth || col?.width || 100;
|
|
1385
1375
|
}
|
|
1386
1376
|
return offset;
|
|
1387
1377
|
},
|
|
1388
|
-
[pinnedColumns, columns, showRowIndex
|
|
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
|
};
|
|
@@ -3409,7 +3396,8 @@ function Spreadsheet({
|
|
|
3409
3396
|
getColumnPinSide
|
|
3410
3397
|
} = useSpreadsheetPinning({
|
|
3411
3398
|
columns,
|
|
3412
|
-
columnGroups
|
|
3399
|
+
columnGroups,
|
|
3400
|
+
defaultPinnedColumns: initialSettings?.defaultPinnedColumns
|
|
3413
3401
|
});
|
|
3414
3402
|
const {
|
|
3415
3403
|
getCellComments,
|
|
@@ -3478,6 +3466,27 @@ function Spreadsheet({
|
|
|
3478
3466
|
defaultSort: sortConfig
|
|
3479
3467
|
}));
|
|
3480
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]);
|
|
3481
3490
|
const applyUndo = (0, import_react16.useCallback)(() => {
|
|
3482
3491
|
const entry = popUndoEntry();
|
|
3483
3492
|
if (!entry || !onCellsEdit) return;
|