@particle-academy/fancy-sheets 0.3.0 → 0.3.1

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
@@ -1601,7 +1601,15 @@ function ColumnResizeHandle({ colIndex }) {
1601
1601
  }
1602
1602
  ColumnResizeHandle.displayName = "ColumnResizeHandle";
1603
1603
  function ColumnHeaders() {
1604
- const { columnCount, rowHeight, getColumnWidth } = useSpreadsheet();
1604
+ const { columnCount, rowCount, rowHeight, getColumnWidth, selectRange } = useSpreadsheet();
1605
+ const handleColumnClick = react.useCallback(
1606
+ (colIdx) => {
1607
+ const start = toAddress(0, colIdx);
1608
+ const end = toAddress(rowCount - 1, colIdx);
1609
+ selectRange(start, end);
1610
+ },
1611
+ [rowCount, selectRange]
1612
+ );
1605
1613
  return /* @__PURE__ */ jsxRuntime.jsxs(
1606
1614
  "div",
1607
1615
  {
@@ -1619,8 +1627,9 @@ function ColumnHeaders() {
1619
1627
  Array.from({ length: columnCount }, (_, i) => /* @__PURE__ */ jsxRuntime.jsxs(
1620
1628
  "div",
1621
1629
  {
1622
- className: "relative flex shrink-0 items-center justify-center border-r border-zinc-300 text-[11px] font-medium text-zinc-500 select-none dark:border-zinc-600 dark:text-zinc-400",
1630
+ className: "relative flex shrink-0 cursor-pointer items-center justify-center border-r border-zinc-300 text-[11px] font-medium text-zinc-500 select-none hover:bg-zinc-200 dark:border-zinc-600 dark:text-zinc-400 dark:hover:bg-zinc-700",
1623
1631
  style: { width: getColumnWidth(i), minWidth: getColumnWidth(i) },
1632
+ onClick: () => handleColumnClick(i),
1624
1633
  children: [
1625
1634
  columnToLetter(i),
1626
1635
  /* @__PURE__ */ jsxRuntime.jsx(ColumnResizeHandle, { colIndex: i })
@@ -1634,13 +1643,19 @@ function ColumnHeaders() {
1634
1643
  }
1635
1644
  ColumnHeaders.displayName = "ColumnHeaders";
1636
1645
  function RowHeader({ rowIndex }) {
1637
- const { rowHeight } = useSpreadsheet();
1646
+ const { rowHeight, columnCount, selectRange } = useSpreadsheet();
1647
+ const handleClick = react.useCallback(() => {
1648
+ const start = toAddress(rowIndex, 0);
1649
+ const end = toAddress(rowIndex, columnCount - 1);
1650
+ selectRange(start, end);
1651
+ }, [rowIndex, columnCount, selectRange]);
1638
1652
  return /* @__PURE__ */ jsxRuntime.jsx(
1639
1653
  "div",
1640
1654
  {
1641
1655
  "data-fancy-sheets-row-header": "",
1642
- className: "flex shrink-0 items-center justify-center border-r border-b border-zinc-300 bg-zinc-100 text-[11px] font-medium text-zinc-500 select-none dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-400",
1656
+ className: "flex shrink-0 cursor-pointer items-center justify-center border-r border-b border-zinc-300 bg-zinc-100 text-[11px] font-medium text-zinc-500 select-none hover:bg-zinc-200 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-400 dark:hover:bg-zinc-700",
1643
1657
  style: { width: 48, minWidth: 48, height: rowHeight },
1658
+ onClick: handleClick,
1644
1659
  children: rowIndex + 1
1645
1660
  }
1646
1661
  );
@@ -2047,6 +2062,8 @@ function DefaultToolbar() {
2047
2062
  confirmEdit,
2048
2063
  startEdit,
2049
2064
  setCellFormat,
2065
+ setFrozenRows,
2066
+ setFrozenCols,
2050
2067
  undo,
2051
2068
  redo,
2052
2069
  canUndo,
@@ -2118,7 +2135,57 @@ function DefaultToolbar() {
2118
2135
  ] })
2119
2136
  },
2120
2137
  align
2121
- ))
2138
+ )),
2139
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-1 h-4 w-px bg-zinc-200 dark:bg-zinc-700" }),
2140
+ /* @__PURE__ */ jsxRuntime.jsx(
2141
+ "button",
2142
+ {
2143
+ className: reactFancy.cn(btnClass, activeSheet.frozenRows > 0 && activeBtnClass),
2144
+ onClick: () => {
2145
+ if (activeSheet.frozenRows > 0) {
2146
+ setFrozenRows(0);
2147
+ } else {
2148
+ const row = selection.activeCell.match(/\d+/);
2149
+ setFrozenRows(row ? parseInt(row[0], 10) - 1 || 1 : 1);
2150
+ }
2151
+ },
2152
+ disabled: readOnly,
2153
+ title: activeSheet.frozenRows > 0 ? `Unfreeze rows (${activeSheet.frozenRows} frozen)` : "Freeze rows above current cell",
2154
+ children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: [
2155
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "9", x2: "21", y2: "9" }),
2156
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "4", x2: "21", y2: "4" }),
2157
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "14", x2: "21", y2: "14", strokeDasharray: "3 3" }),
2158
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "19", x2: "21", y2: "19", strokeDasharray: "3 3" })
2159
+ ] })
2160
+ }
2161
+ ),
2162
+ /* @__PURE__ */ jsxRuntime.jsx(
2163
+ "button",
2164
+ {
2165
+ className: reactFancy.cn(btnClass, activeSheet.frozenCols > 0 && activeBtnClass),
2166
+ onClick: () => {
2167
+ if (activeSheet.frozenCols > 0) {
2168
+ setFrozenCols(0);
2169
+ } else {
2170
+ const colMatch = selection.activeCell.match(/^([A-Z]+)/);
2171
+ if (colMatch) {
2172
+ const col = colMatch[1].split("").reduce((acc, ch) => acc * 26 + ch.charCodeAt(0) - 64, 0) - 1;
2173
+ setFrozenCols(col || 1);
2174
+ } else {
2175
+ setFrozenCols(1);
2176
+ }
2177
+ }
2178
+ },
2179
+ disabled: readOnly,
2180
+ title: activeSheet.frozenCols > 0 ? `Unfreeze columns (${activeSheet.frozenCols} frozen)` : "Freeze columns left of current cell",
2181
+ children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: [
2182
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "9", y1: "3", x2: "9", y2: "21" }),
2183
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "3", x2: "4", y2: "21" }),
2184
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "14", y1: "3", x2: "14", y2: "21", strokeDasharray: "3 3" }),
2185
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "19", y1: "3", x2: "19", y2: "21", strokeDasharray: "3 3" })
2186
+ ] })
2187
+ }
2188
+ )
2122
2189
  ] }),
2123
2190
  /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-fancy-sheets-formula-bar": "", className: "flex items-center gap-2 border-b border-zinc-200 px-2 py-1 dark:border-zinc-700", children: [
2124
2191
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "w-12 shrink-0 text-center text-[11px] font-medium text-zinc-500 dark:text-zinc-400", children: selection.activeCell }),