@particle-academy/fancy-sheets 0.4.3 → 0.4.5

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.cjs CHANGED
@@ -1607,7 +1607,7 @@ function ColumnResizeHandle({ colIndex }) {
1607
1607
  }
1608
1608
  ColumnResizeHandle.displayName = "ColumnResizeHandle";
1609
1609
  function ColumnHeaders() {
1610
- const { columnCount, rowCount, rowHeight, getColumnWidth, selection, selectRange, _isDragging, isCellSelected } = useSpreadsheet();
1610
+ const { columnCount, rowCount, rowHeight, getColumnWidth, selection, selectRange, _isDragging } = useSpreadsheet();
1611
1611
  const handleColumnMouseDown = react.useCallback(
1612
1612
  (colIdx, e) => {
1613
1613
  if (e.button !== 0) return;
@@ -1652,7 +1652,15 @@ function ColumnHeaders() {
1652
1652
  }
1653
1653
  ),
1654
1654
  Array.from({ length: columnCount }, (_, i) => {
1655
- const isColSelected = isCellSelected(toAddress(0, i));
1655
+ const isColSelected = selection.ranges.some((range) => {
1656
+ const s = parseAddress(range.start);
1657
+ const e = parseAddress(range.end);
1658
+ const minCol = Math.min(s.col, e.col);
1659
+ const maxCol = Math.max(s.col, e.col);
1660
+ const minRow = Math.min(s.row, e.row);
1661
+ const maxRow = Math.max(s.row, e.row);
1662
+ return i >= minCol && i <= maxCol && minRow === 0 && maxRow >= rowCount - 1;
1663
+ });
1656
1664
  return /* @__PURE__ */ jsxRuntime.jsxs(
1657
1665
  "div",
1658
1666
  {
@@ -1678,8 +1686,16 @@ function ColumnHeaders() {
1678
1686
  }
1679
1687
  ColumnHeaders.displayName = "ColumnHeaders";
1680
1688
  function RowHeader({ rowIndex }) {
1681
- const { rowHeight, columnCount, selection, selectRange, _isDragging, isCellSelected } = useSpreadsheet();
1682
- const isRowSelected = isCellSelected(toAddress(rowIndex, 0));
1689
+ const { rowHeight, columnCount, selection, selectRange, _isDragging } = useSpreadsheet();
1690
+ const isRowSelected = selection.ranges.some((range) => {
1691
+ const s = parseAddress(range.start);
1692
+ const e = parseAddress(range.end);
1693
+ const minRow = Math.min(s.row, e.row);
1694
+ const maxRow = Math.max(s.row, e.row);
1695
+ const minCol = Math.min(s.col, e.col);
1696
+ const maxCol = Math.max(s.col, e.col);
1697
+ return rowIndex >= minRow && rowIndex <= maxRow && minCol === 0 && maxCol >= columnCount - 1;
1698
+ });
1683
1699
  const handleMouseDown = react.useCallback(
1684
1700
  (e) => {
1685
1701
  if (e.button !== 0) return;
@@ -2204,7 +2220,18 @@ function DefaultToolbar() {
2204
2220
  const isItalic = cell?.format?.italic ?? false;
2205
2221
  const textAlign = cell?.format?.textAlign ?? "left";
2206
2222
  const displayFormat = cell?.format?.displayFormat ?? "auto";
2207
- const decimals = cell?.format?.decimals;
2223
+ const explicitDecimals = cell?.format?.decimals;
2224
+ const cellValue = cell?.computedValue ?? cell?.value;
2225
+ const inferredDecimals = (() => {
2226
+ if (explicitDecimals !== void 0) return explicitDecimals;
2227
+ if (typeof cellValue === "number") {
2228
+ const str = String(cellValue);
2229
+ const dotIdx = str.indexOf(".");
2230
+ return dotIdx === -1 ? 0 : str.length - dotIdx - 1;
2231
+ }
2232
+ return 0;
2233
+ })();
2234
+ const currentDecimals = explicitDecimals ?? inferredDecimals;
2208
2235
  const selectedAddresses = [selection.activeCell];
2209
2236
  const handleFormulaBarChange = (e) => {
2210
2237
  if (editingCell) {
@@ -2341,9 +2368,9 @@ function DefaultToolbar() {
2341
2368
  "button",
2342
2369
  {
2343
2370
  className: btnClass,
2344
- onClick: () => setCellFormat(selectedAddresses, { decimals: Math.max(0, (decimals ?? 0) - 1) }),
2345
- disabled: readOnly || (decimals ?? 0) <= 0,
2346
- title: "Decrease decimal places",
2371
+ onClick: () => setCellFormat(selectedAddresses, { decimals: Math.max(0, currentDecimals - 1) }),
2372
+ disabled: readOnly || currentDecimals <= 0,
2373
+ title: `Decrease decimal places (currently ${currentDecimals})`,
2347
2374
  children: [
2348
2375
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px]", children: ".0" }),
2349
2376
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[8px]", children: "\u2190" })
@@ -2354,9 +2381,9 @@ function DefaultToolbar() {
2354
2381
  "button",
2355
2382
  {
2356
2383
  className: btnClass,
2357
- onClick: () => setCellFormat(selectedAddresses, { decimals: (decimals ?? 0) + 1 }),
2384
+ onClick: () => setCellFormat(selectedAddresses, { decimals: currentDecimals + 1 }),
2358
2385
  disabled: readOnly,
2359
- title: "Increase decimal places",
2386
+ title: `Increase decimal places (currently ${currentDecimals})`,
2360
2387
  children: [
2361
2388
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px]", children: ".00" }),
2362
2389
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[8px]", children: "\u2192" })