@xcelsior/ui-spreadsheets 1.1.6 → 1.1.8
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 +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +50 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -2
- package/dist/index.mjs.map +1 -1
- package/dist/styles/globals.css +3 -0
- package/dist/styles/globals.css.map +1 -1
- package/package.json +2 -2
- package/src/components/RowContextMenu.tsx +1 -1
- package/src/components/Spreadsheet.stories.tsx +148 -0
- package/src/components/Spreadsheet.tsx +9 -0
- package/src/components/SpreadsheetCell.tsx +28 -0
- package/src/hooks/useSpreadsheetPinning.ts +30 -0
- package/src/types.ts +5 -2
package/dist/index.mjs
CHANGED
|
@@ -215,10 +215,31 @@ var SpreadsheetCell = ({
|
|
|
215
215
|
if (isRowHovered) return "rgb(243 244 246)";
|
|
216
216
|
return "white";
|
|
217
217
|
};
|
|
218
|
+
const handleCheckboxChange = (e) => {
|
|
219
|
+
e.stopPropagation();
|
|
220
|
+
const newValue = e.target.checked;
|
|
221
|
+
onConfirm?.(newValue);
|
|
222
|
+
};
|
|
218
223
|
const renderContent = () => {
|
|
219
224
|
if (column.render) {
|
|
220
225
|
return column.render(value, row, rowIndex);
|
|
221
226
|
}
|
|
227
|
+
if (column.type === "checkbox") {
|
|
228
|
+
return /* @__PURE__ */ jsx(
|
|
229
|
+
"input",
|
|
230
|
+
{
|
|
231
|
+
type: "checkbox",
|
|
232
|
+
checked: Boolean(value),
|
|
233
|
+
onChange: handleCheckboxChange,
|
|
234
|
+
onClick: (e) => e.stopPropagation(),
|
|
235
|
+
disabled: !isEditable,
|
|
236
|
+
className: cn(
|
|
237
|
+
"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 cursor-pointer",
|
|
238
|
+
!isEditable && "cursor-not-allowed opacity-60"
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
}
|
|
222
243
|
if (value === null || value === void 0 || value === "") {
|
|
223
244
|
return /* @__PURE__ */ jsx("span", { className: "text-gray-400", children: "-" });
|
|
224
245
|
}
|
|
@@ -231,6 +252,9 @@ var SpreadsheetCell = ({
|
|
|
231
252
|
return String(value);
|
|
232
253
|
};
|
|
233
254
|
const renderEditInput = () => {
|
|
255
|
+
if (column.type === "checkbox") {
|
|
256
|
+
return renderContent();
|
|
257
|
+
}
|
|
234
258
|
if (column.type === "select" && column.options) {
|
|
235
259
|
return /* @__PURE__ */ jsx(
|
|
236
260
|
"select",
|
|
@@ -1218,13 +1242,17 @@ function useSpreadsheetPinning({
|
|
|
1218
1242
|
columns,
|
|
1219
1243
|
columnGroups,
|
|
1220
1244
|
showRowIndex = true,
|
|
1221
|
-
defaultPinnedColumns = []
|
|
1245
|
+
defaultPinnedColumns = [],
|
|
1246
|
+
defaultPinnedRightColumns = []
|
|
1222
1247
|
}) {
|
|
1223
1248
|
const [pinnedColumns, setPinnedColumns] = useState3(() => {
|
|
1224
1249
|
const map = /* @__PURE__ */ new Map();
|
|
1225
1250
|
defaultPinnedColumns.forEach((col) => {
|
|
1226
1251
|
map.set(col, "left");
|
|
1227
1252
|
});
|
|
1253
|
+
defaultPinnedRightColumns.forEach((col) => {
|
|
1254
|
+
map.set(col, "right");
|
|
1255
|
+
});
|
|
1228
1256
|
return map;
|
|
1229
1257
|
});
|
|
1230
1258
|
const [collapsedGroups, setCollapsedGroups] = useState3(/* @__PURE__ */ new Set());
|
|
@@ -1327,6 +1355,20 @@ function useSpreadsheetPinning({
|
|
|
1327
1355
|
},
|
|
1328
1356
|
[pinnedColumns]
|
|
1329
1357
|
);
|
|
1358
|
+
const getColumnRightOffset = useCallback(
|
|
1359
|
+
(columnId) => {
|
|
1360
|
+
const pinnedRight = Array.from(pinnedColumns.entries()).filter(([, side]) => side === "right").map(([id]) => id);
|
|
1361
|
+
const index = pinnedRight.indexOf(columnId);
|
|
1362
|
+
if (index === -1) return 0;
|
|
1363
|
+
let offset = 0;
|
|
1364
|
+
for (let i = pinnedRight.length - 1; i > index; i--) {
|
|
1365
|
+
const col = columns.find((c) => c.id === pinnedRight[i]);
|
|
1366
|
+
offset += col?.minWidth || col?.width || 100;
|
|
1367
|
+
}
|
|
1368
|
+
return offset;
|
|
1369
|
+
},
|
|
1370
|
+
[pinnedColumns, columns]
|
|
1371
|
+
);
|
|
1330
1372
|
return {
|
|
1331
1373
|
pinnedColumns,
|
|
1332
1374
|
isRowIndexPinned,
|
|
@@ -1336,6 +1378,7 @@ function useSpreadsheetPinning({
|
|
|
1336
1378
|
handleToggleGroupCollapse,
|
|
1337
1379
|
setPinnedColumnsFromIds,
|
|
1338
1380
|
getColumnLeftOffset,
|
|
1381
|
+
getColumnRightOffset,
|
|
1339
1382
|
isColumnPinned,
|
|
1340
1383
|
getColumnPinSide
|
|
1341
1384
|
};
|
|
@@ -3430,12 +3473,14 @@ function Spreadsheet({
|
|
|
3430
3473
|
handleToggleGroupCollapse,
|
|
3431
3474
|
setPinnedColumnsFromIds,
|
|
3432
3475
|
getColumnLeftOffset,
|
|
3476
|
+
getColumnRightOffset,
|
|
3433
3477
|
isColumnPinned,
|
|
3434
3478
|
getColumnPinSide
|
|
3435
3479
|
} = useSpreadsheetPinning({
|
|
3436
3480
|
columns,
|
|
3437
3481
|
columnGroups,
|
|
3438
|
-
defaultPinnedColumns: initialSettings?.defaultPinnedColumns
|
|
3482
|
+
defaultPinnedColumns: initialSettings?.defaultPinnedColumns,
|
|
3483
|
+
defaultPinnedRightColumns: initialSettings?.defaultPinnedRightColumns
|
|
3439
3484
|
});
|
|
3440
3485
|
const {
|
|
3441
3486
|
getCellComments,
|
|
@@ -3887,6 +3932,7 @@ function Spreadsheet({
|
|
|
3887
3932
|
),
|
|
3888
3933
|
visibleColumns.map((column) => {
|
|
3889
3934
|
const isPinnedLeft = isColumnPinned(column.id) && getColumnPinSide(column.id) === "left";
|
|
3935
|
+
const isPinnedRight = isColumnPinned(column.id) && getColumnPinSide(column.id) === "right";
|
|
3890
3936
|
return /* @__PURE__ */ jsx12(
|
|
3891
3937
|
SpreadsheetHeader,
|
|
3892
3938
|
{
|
|
@@ -3896,6 +3942,7 @@ function Spreadsheet({
|
|
|
3896
3942
|
isPinned: isColumnPinned(column.id),
|
|
3897
3943
|
pinSide: getColumnPinSide(column.id),
|
|
3898
3944
|
leftOffset: isPinnedLeft ? getColumnLeftOffset(column.id) : 0,
|
|
3945
|
+
rightOffset: isPinnedRight ? getColumnRightOffset(column.id) : 0,
|
|
3899
3946
|
highlightColor: getColumnHighlight(column.id),
|
|
3900
3947
|
compactMode: effectiveCompactMode,
|
|
3901
3948
|
onClick: () => handleSort(column.id),
|
|
@@ -4112,6 +4159,7 @@ function Spreadsheet({
|
|
|
4112
4159
|
isPinned: isColPinned,
|
|
4113
4160
|
pinSide: colPinSide,
|
|
4114
4161
|
leftOffset: getColumnLeftOffset(column.id),
|
|
4162
|
+
rightOffset: getColumnRightOffset(column.id),
|
|
4115
4163
|
onClick: (e) => handleCellClick(rowId, column.id, e),
|
|
4116
4164
|
onConfirm: handleConfirmEdit,
|
|
4117
4165
|
onCancel: handleCancelEdit,
|