@xcelsior/ui-spreadsheets 1.3.1 → 1.3.3

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.mjs CHANGED
@@ -439,9 +439,10 @@ var SpreadsheetCell = ({
439
439
  return typeof value === "number" ? value.toLocaleString() : value;
440
440
  }
441
441
  if (column.type === "autocomplete") {
442
- if (column.getOptionLabel) return column.getOptionLabel(value, row);
443
- const match = column.autocompleteOptions?.find((o) => o.value === value);
444
- return match ? match.label : String(value);
442
+ const displayVal = localValue ?? value;
443
+ if (column.getOptionLabel) return column.getOptionLabel(displayVal, row);
444
+ const match = column.autocompleteOptions?.find((o) => o.value === displayVal);
445
+ return match ? match.label : displayVal != null && displayVal !== "" ? String(displayVal) : null;
445
446
  }
446
447
  return String(value);
447
448
  };
@@ -456,7 +457,10 @@ var SpreadsheetCell = ({
456
457
  value: localValue,
457
458
  column,
458
459
  compactMode,
459
- onConfirm,
460
+ onConfirm: (newVal) => {
461
+ setLocalValue(newVal);
462
+ onConfirm?.(newVal);
463
+ },
460
464
  onCancel
461
465
  }
462
466
  );
@@ -3196,7 +3200,8 @@ function useSpreadsheetFiltering({
3196
3200
  return false;
3197
3201
  }
3198
3202
  if (filter.textCondition) {
3199
- return applyTextCondition(value, filter.textCondition);
3203
+ const filterableValue = column.type === "autocomplete" && column.getOptionLabel ? column.getOptionLabel(value, row) : value;
3204
+ return applyTextCondition(filterableValue, filter.textCondition);
3200
3205
  }
3201
3206
  if (filter.numberCondition) {
3202
3207
  return applyNumberCondition(value, filter.numberCondition);
@@ -3810,6 +3815,11 @@ function useSpreadsheetKeyboardShortcuts({
3810
3815
  useEffect7(() => {
3811
3816
  if (!enabled) return;
3812
3817
  const handleKeyDown = (event) => {
3818
+ const activeEl = document.activeElement;
3819
+ const isInFormElement = activeEl instanceof HTMLInputElement || activeEl instanceof HTMLTextAreaElement || activeEl instanceof HTMLSelectElement;
3820
+ if (isInFormElement && event.key !== "Escape") {
3821
+ return;
3822
+ }
3813
3823
  if (event.key === "Escape") {
3814
3824
  if (showKeyboardShortcuts) {
3815
3825
  setShowKeyboardShortcuts(false);
@@ -4385,7 +4395,7 @@ function useSpreadsheetSummary({
4385
4395
  const numericValues = [];
4386
4396
  for (const { position, value } of selectedCellValues) {
4387
4397
  const column = columns.find((c) => c.id === position.columnId);
4388
- if (column?.type === "number" || typeof value === "number") {
4398
+ if (column?.type === "number") {
4389
4399
  const num = typeof value === "number" ? value : parseFloat(value);
4390
4400
  if (!isNaN(num)) {
4391
4401
  numericValues.push(num);
@@ -4735,7 +4745,7 @@ function Spreadsheet({
4735
4745
  onToggleCommentResolved
4736
4746
  });
4737
4747
  const [showSettingsModal, setShowSettingsModal] = useState16(false);
4738
- const [showFiltersPanel, setShowFiltersPanel] = useState16(false);
4748
+ const [showFiltersPanel, setShowFiltersPanel] = useState16(true);
4739
4749
  const {
4740
4750
  canUndo,
4741
4751
  canRedo,
@@ -5088,8 +5098,14 @@ function Spreadsheet({
5088
5098
  (rowId, columnId, event) => {
5089
5099
  event.stopPropagation();
5090
5100
  handleCellMouseDown(rowId, columnId, event);
5101
+ if (!event.shiftKey && !event.metaKey && !event.ctrlKey) {
5102
+ const column = columns.find((c) => c.id === columnId);
5103
+ if (column?.editable && enableCellEditing) {
5104
+ setEditingCell({ rowId, columnId });
5105
+ }
5106
+ }
5091
5107
  },
5092
- [handleCellMouseDown]
5108
+ [handleCellMouseDown, columns, enableCellEditing, setEditingCell]
5093
5109
  );
5094
5110
  const handleCellDoubleClick = useCallback11(
5095
5111
  (rowId, columnId) => {
@@ -5355,17 +5371,65 @@ function Spreadsheet({
5355
5371
  })
5356
5372
  ] })
5357
5373
  ] }),
5358
- /* @__PURE__ */ jsx14("tbody", { children: isLoading ? /* @__PURE__ */ jsx14("tr", { children: /* @__PURE__ */ jsx14(
5359
- "td",
5360
- {
5361
- colSpan: columnRenderItems.length + 1,
5362
- className: "text-center py-8 text-gray-500",
5363
- children: /* @__PURE__ */ jsxs14("div", { className: "flex items-center justify-center gap-2", children: [
5364
- /* @__PURE__ */ jsx14("div", { className: "w-4 h-4 border-2 border-blue-600 border-t-transparent rounded-full animate-spin" }),
5365
- "Loading..."
5366
- ] })
5367
- }
5368
- ) }) : paginatedData.length === 0 ? /* @__PURE__ */ jsx14("tr", { children: /* @__PURE__ */ jsx14(
5374
+ /* @__PURE__ */ jsx14("tbody", { children: isLoading ? Array.from({ length: Math.min(pageSize, 40) }).map((_, rowIdx) => /* @__PURE__ */ jsxs14("tr", { children: [
5375
+ /* @__PURE__ */ jsx14(
5376
+ "td",
5377
+ {
5378
+ className: cn(
5379
+ "sticky",
5380
+ effectiveCompactMode ? "px-1.5 py-0.5" : "px-2.5 py-1.5"
5381
+ ),
5382
+ style: {
5383
+ minWidth: `${ROW_INDEX_COLUMN_WIDTH}px`,
5384
+ width: `${ROW_INDEX_COLUMN_WIDTH}px`,
5385
+ left: 0,
5386
+ zIndex: 40,
5387
+ backgroundColor: rowIdx % 2 !== 0 ? "#f9fafb" : "white"
5388
+ },
5389
+ children: /* @__PURE__ */ jsx14(
5390
+ "div",
5391
+ {
5392
+ className: "h-4 bg-gray-200 rounded animate-pulse",
5393
+ style: { width: "60%", animationDelay: `${rowIdx * 50}ms` }
5394
+ }
5395
+ )
5396
+ }
5397
+ ),
5398
+ columnRenderItems.map((item, colIdx) => {
5399
+ if (item.type === "collapsed-placeholder") {
5400
+ return /* @__PURE__ */ jsx14(
5401
+ "td",
5402
+ {
5403
+ style: { backgroundColor: rowIdx % 2 !== 0 ? "#f9fafb" : "white" }
5404
+ },
5405
+ `skeleton-${rowIdx}-placeholder-${item.groupId}`
5406
+ );
5407
+ }
5408
+ return /* @__PURE__ */ jsx14(
5409
+ "td",
5410
+ {
5411
+ className: cn(
5412
+ effectiveCompactMode ? "px-1.5 py-0.5" : "px-2.5 py-1.5"
5413
+ ),
5414
+ style: {
5415
+ minWidth: item.column.width ?? 120,
5416
+ backgroundColor: rowIdx % 2 !== 0 ? "#f9fafb" : "white"
5417
+ },
5418
+ children: /* @__PURE__ */ jsx14(
5419
+ "div",
5420
+ {
5421
+ className: "h-4 bg-gray-200 rounded animate-pulse",
5422
+ style: {
5423
+ width: `${55 + (rowIdx * 7 + colIdx * 13) % 35}%`,
5424
+ animationDelay: `${(rowIdx * columnRenderItems.length + colIdx) * 30}ms`
5425
+ }
5426
+ }
5427
+ )
5428
+ },
5429
+ `skeleton-${rowIdx}-${item.column.id}`
5430
+ );
5431
+ })
5432
+ ] }, `skeleton-${rowIdx}`)) : paginatedData.length === 0 ? /* @__PURE__ */ jsx14("tr", { children: /* @__PURE__ */ jsx14(
5369
5433
  "td",
5370
5434
  {
5371
5435
  colSpan: columnRenderItems.length + 1,