@xcelsior/ui-spreadsheets 1.1.7 → 1.1.9
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 +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Spreadsheet.stories.tsx +56 -0
- package/src/components/Spreadsheet.tsx +9 -0
- package/src/components/SpreadsheetCell.tsx +3 -3
- package/src/components/SpreadsheetHeader.tsx +1 -1
- package/src/hooks/useSpreadsheetPinning.ts +30 -0
- package/src/types.ts +8 -1
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,10 @@ interface SpreadsheetColumn<T = any> {
|
|
|
23
23
|
editable?: boolean;
|
|
24
24
|
/** Whether the column can be pinned */
|
|
25
25
|
pinnable?: boolean;
|
|
26
|
+
/** Whether the column can be highlighted (defaults to true) */
|
|
27
|
+
highlightable?: boolean;
|
|
28
|
+
/** Whether the column can have comments (defaults to true) */
|
|
29
|
+
commentable?: boolean;
|
|
26
30
|
/** Type of data in the column (for filtering/formatting) */
|
|
27
31
|
type?: 'text' | 'number' | 'date' | 'select' | 'boolean' | 'checkbox';
|
|
28
32
|
/** Options for select type columns */
|
|
@@ -323,8 +327,10 @@ interface SpreadsheetProps<T = any> {
|
|
|
323
327
|
onSave?: () => void | Promise<void>;
|
|
324
328
|
/** Initial settings (optional). All settings can be changed by user in the settings modal. */
|
|
325
329
|
settings?: {
|
|
326
|
-
/** Default pinned column IDs */
|
|
330
|
+
/** Default pinned column IDs (pinned to left) */
|
|
327
331
|
defaultPinnedColumns?: string[];
|
|
332
|
+
/** Default pinned column IDs (pinned to right) */
|
|
333
|
+
defaultPinnedRightColumns?: string[];
|
|
328
334
|
/** Default sort configuration */
|
|
329
335
|
defaultSort?: SpreadsheetSortConfig | null;
|
|
330
336
|
/** Default page size */
|
|
@@ -343,6 +349,7 @@ interface SpreadsheetProps<T = any> {
|
|
|
343
349
|
defaultPageSize?: number;
|
|
344
350
|
defaultZoom?: number;
|
|
345
351
|
defaultPinnedColumns?: string[];
|
|
352
|
+
defaultPinnedRightColumns?: string[];
|
|
346
353
|
defaultSort?: SpreadsheetSortConfig | null;
|
|
347
354
|
}) => void;
|
|
348
355
|
/** Loading state */
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ interface SpreadsheetColumn<T = any> {
|
|
|
23
23
|
editable?: boolean;
|
|
24
24
|
/** Whether the column can be pinned */
|
|
25
25
|
pinnable?: boolean;
|
|
26
|
+
/** Whether the column can be highlighted (defaults to true) */
|
|
27
|
+
highlightable?: boolean;
|
|
28
|
+
/** Whether the column can have comments (defaults to true) */
|
|
29
|
+
commentable?: boolean;
|
|
26
30
|
/** Type of data in the column (for filtering/formatting) */
|
|
27
31
|
type?: 'text' | 'number' | 'date' | 'select' | 'boolean' | 'checkbox';
|
|
28
32
|
/** Options for select type columns */
|
|
@@ -323,8 +327,10 @@ interface SpreadsheetProps<T = any> {
|
|
|
323
327
|
onSave?: () => void | Promise<void>;
|
|
324
328
|
/** Initial settings (optional). All settings can be changed by user in the settings modal. */
|
|
325
329
|
settings?: {
|
|
326
|
-
/** Default pinned column IDs */
|
|
330
|
+
/** Default pinned column IDs (pinned to left) */
|
|
327
331
|
defaultPinnedColumns?: string[];
|
|
332
|
+
/** Default pinned column IDs (pinned to right) */
|
|
333
|
+
defaultPinnedRightColumns?: string[];
|
|
328
334
|
/** Default sort configuration */
|
|
329
335
|
defaultSort?: SpreadsheetSortConfig | null;
|
|
330
336
|
/** Default page size */
|
|
@@ -343,6 +349,7 @@ interface SpreadsheetProps<T = any> {
|
|
|
343
349
|
defaultPageSize?: number;
|
|
344
350
|
defaultZoom?: number;
|
|
345
351
|
defaultPinnedColumns?: string[];
|
|
352
|
+
defaultPinnedRightColumns?: string[];
|
|
346
353
|
defaultSort?: SpreadsheetSortConfig | null;
|
|
347
354
|
}) => void;
|
|
348
355
|
/** Loading state */
|
package/dist/index.js
CHANGED
|
@@ -419,7 +419,7 @@ var SpreadsheetCell = ({
|
|
|
419
419
|
}
|
|
420
420
|
),
|
|
421
421
|
!isInSelection && !isFocused && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-0.5 shrink-0", children: [
|
|
422
|
-
onHighlight && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
422
|
+
column.highlightable !== false && onHighlight && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
423
423
|
"button",
|
|
424
424
|
{
|
|
425
425
|
type: "button",
|
|
@@ -440,7 +440,7 @@ var SpreadsheetCell = ({
|
|
|
440
440
|
)
|
|
441
441
|
}
|
|
442
442
|
),
|
|
443
|
-
hasComments && onViewComments ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
443
|
+
column.commentable !== false && hasComments && onViewComments ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
444
444
|
"button",
|
|
445
445
|
{
|
|
446
446
|
type: "button",
|
|
@@ -455,7 +455,7 @@ var SpreadsheetCell = ({
|
|
|
455
455
|
unresolvedCommentCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-[9px] font-medium text-amber-600", children: unresolvedCommentCount > 99 ? "99+" : unresolvedCommentCount })
|
|
456
456
|
]
|
|
457
457
|
}
|
|
458
|
-
) : onAddComment ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
458
|
+
) : column.commentable !== false && onAddComment ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
459
459
|
"button",
|
|
460
460
|
{
|
|
461
461
|
type: "button",
|
|
@@ -1258,7 +1258,7 @@ var SpreadsheetHeader = ({
|
|
|
1258
1258
|
ColumnHeaderActions,
|
|
1259
1259
|
{
|
|
1260
1260
|
enableFiltering: column.filterable,
|
|
1261
|
-
enableHighlighting: !!onHighlightClick,
|
|
1261
|
+
enableHighlighting: column.highlightable !== false && !!onHighlightClick,
|
|
1262
1262
|
enablePinning: column.pinnable !== false,
|
|
1263
1263
|
hasActiveFilter,
|
|
1264
1264
|
hasActiveHighlight: !!highlightColor,
|
|
@@ -1284,13 +1284,17 @@ function useSpreadsheetPinning({
|
|
|
1284
1284
|
columns,
|
|
1285
1285
|
columnGroups,
|
|
1286
1286
|
showRowIndex = true,
|
|
1287
|
-
defaultPinnedColumns = []
|
|
1287
|
+
defaultPinnedColumns = [],
|
|
1288
|
+
defaultPinnedRightColumns = []
|
|
1288
1289
|
}) {
|
|
1289
1290
|
const [pinnedColumns, setPinnedColumns] = (0, import_react6.useState)(() => {
|
|
1290
1291
|
const map = /* @__PURE__ */ new Map();
|
|
1291
1292
|
defaultPinnedColumns.forEach((col) => {
|
|
1292
1293
|
map.set(col, "left");
|
|
1293
1294
|
});
|
|
1295
|
+
defaultPinnedRightColumns.forEach((col) => {
|
|
1296
|
+
map.set(col, "right");
|
|
1297
|
+
});
|
|
1294
1298
|
return map;
|
|
1295
1299
|
});
|
|
1296
1300
|
const [collapsedGroups, setCollapsedGroups] = (0, import_react6.useState)(/* @__PURE__ */ new Set());
|
|
@@ -1393,6 +1397,20 @@ function useSpreadsheetPinning({
|
|
|
1393
1397
|
},
|
|
1394
1398
|
[pinnedColumns]
|
|
1395
1399
|
);
|
|
1400
|
+
const getColumnRightOffset = (0, import_react6.useCallback)(
|
|
1401
|
+
(columnId) => {
|
|
1402
|
+
const pinnedRight = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "right").map(([id]) => id);
|
|
1403
|
+
const index = pinnedRight.indexOf(columnId);
|
|
1404
|
+
if (index === -1) return 0;
|
|
1405
|
+
let offset = 0;
|
|
1406
|
+
for (let i = pinnedRight.length - 1; i > index; i--) {
|
|
1407
|
+
const col = columns.find((c) => c.id === pinnedRight[i]);
|
|
1408
|
+
offset += col?.minWidth || col?.width || 100;
|
|
1409
|
+
}
|
|
1410
|
+
return offset;
|
|
1411
|
+
},
|
|
1412
|
+
[pinnedColumns, columns]
|
|
1413
|
+
);
|
|
1396
1414
|
return {
|
|
1397
1415
|
pinnedColumns,
|
|
1398
1416
|
isRowIndexPinned,
|
|
@@ -1402,6 +1420,7 @@ function useSpreadsheetPinning({
|
|
|
1402
1420
|
handleToggleGroupCollapse,
|
|
1403
1421
|
setPinnedColumnsFromIds,
|
|
1404
1422
|
getColumnLeftOffset,
|
|
1423
|
+
getColumnRightOffset,
|
|
1405
1424
|
isColumnPinned,
|
|
1406
1425
|
getColumnPinSide
|
|
1407
1426
|
};
|
|
@@ -3496,12 +3515,14 @@ function Spreadsheet({
|
|
|
3496
3515
|
handleToggleGroupCollapse,
|
|
3497
3516
|
setPinnedColumnsFromIds,
|
|
3498
3517
|
getColumnLeftOffset,
|
|
3518
|
+
getColumnRightOffset,
|
|
3499
3519
|
isColumnPinned,
|
|
3500
3520
|
getColumnPinSide
|
|
3501
3521
|
} = useSpreadsheetPinning({
|
|
3502
3522
|
columns,
|
|
3503
3523
|
columnGroups,
|
|
3504
|
-
defaultPinnedColumns: initialSettings?.defaultPinnedColumns
|
|
3524
|
+
defaultPinnedColumns: initialSettings?.defaultPinnedColumns,
|
|
3525
|
+
defaultPinnedRightColumns: initialSettings?.defaultPinnedRightColumns
|
|
3505
3526
|
});
|
|
3506
3527
|
const {
|
|
3507
3528
|
getCellComments,
|
|
@@ -3953,6 +3974,7 @@ function Spreadsheet({
|
|
|
3953
3974
|
),
|
|
3954
3975
|
visibleColumns.map((column) => {
|
|
3955
3976
|
const isPinnedLeft = isColumnPinned(column.id) && getColumnPinSide(column.id) === "left";
|
|
3977
|
+
const isPinnedRight = isColumnPinned(column.id) && getColumnPinSide(column.id) === "right";
|
|
3956
3978
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3957
3979
|
SpreadsheetHeader,
|
|
3958
3980
|
{
|
|
@@ -3962,6 +3984,7 @@ function Spreadsheet({
|
|
|
3962
3984
|
isPinned: isColumnPinned(column.id),
|
|
3963
3985
|
pinSide: getColumnPinSide(column.id),
|
|
3964
3986
|
leftOffset: isPinnedLeft ? getColumnLeftOffset(column.id) : 0,
|
|
3987
|
+
rightOffset: isPinnedRight ? getColumnRightOffset(column.id) : 0,
|
|
3965
3988
|
highlightColor: getColumnHighlight(column.id),
|
|
3966
3989
|
compactMode: effectiveCompactMode,
|
|
3967
3990
|
onClick: () => handleSort(column.id),
|
|
@@ -4178,6 +4201,7 @@ function Spreadsheet({
|
|
|
4178
4201
|
isPinned: isColPinned,
|
|
4179
4202
|
pinSide: colPinSide,
|
|
4180
4203
|
leftOffset: getColumnLeftOffset(column.id),
|
|
4204
|
+
rightOffset: getColumnRightOffset(column.id),
|
|
4181
4205
|
onClick: (e) => handleCellClick(rowId, column.id, e),
|
|
4182
4206
|
onConfirm: handleConfirmEdit,
|
|
4183
4207
|
onCancel: handleCancelEdit,
|