@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.d.cts CHANGED
@@ -110,6 +110,7 @@ interface SpreadsheetContextValue {
110
110
  setSelection: (cell: string) => void;
111
111
  extendSelection: (cell: string) => void;
112
112
  addSelection: (cell: string) => void;
113
+ selectRange: (start: string, end: string) => void;
113
114
  navigate: (direction: "up" | "down" | "left" | "right", extend?: boolean) => void;
114
115
  startEdit: (value?: string) => void;
115
116
  updateEdit: (value: string) => void;
package/dist/index.d.ts CHANGED
@@ -110,6 +110,7 @@ interface SpreadsheetContextValue {
110
110
  setSelection: (cell: string) => void;
111
111
  extendSelection: (cell: string) => void;
112
112
  addSelection: (cell: string) => void;
113
+ selectRange: (start: string, end: string) => void;
113
114
  navigate: (direction: "up" | "down" | "left" | "right", extend?: boolean) => void;
114
115
  startEdit: (value?: string) => void;
115
116
  updateEdit: (value: string) => void;
package/dist/index.js CHANGED
@@ -1599,7 +1599,15 @@ function ColumnResizeHandle({ colIndex }) {
1599
1599
  }
1600
1600
  ColumnResizeHandle.displayName = "ColumnResizeHandle";
1601
1601
  function ColumnHeaders() {
1602
- const { columnCount, rowHeight, getColumnWidth } = useSpreadsheet();
1602
+ const { columnCount, rowCount, rowHeight, getColumnWidth, selectRange } = useSpreadsheet();
1603
+ const handleColumnClick = useCallback(
1604
+ (colIdx) => {
1605
+ const start = toAddress(0, colIdx);
1606
+ const end = toAddress(rowCount - 1, colIdx);
1607
+ selectRange(start, end);
1608
+ },
1609
+ [rowCount, selectRange]
1610
+ );
1603
1611
  return /* @__PURE__ */ jsxs(
1604
1612
  "div",
1605
1613
  {
@@ -1617,8 +1625,9 @@ function ColumnHeaders() {
1617
1625
  Array.from({ length: columnCount }, (_, i) => /* @__PURE__ */ jsxs(
1618
1626
  "div",
1619
1627
  {
1620
- 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",
1628
+ 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",
1621
1629
  style: { width: getColumnWidth(i), minWidth: getColumnWidth(i) },
1630
+ onClick: () => handleColumnClick(i),
1622
1631
  children: [
1623
1632
  columnToLetter(i),
1624
1633
  /* @__PURE__ */ jsx(ColumnResizeHandle, { colIndex: i })
@@ -1632,13 +1641,19 @@ function ColumnHeaders() {
1632
1641
  }
1633
1642
  ColumnHeaders.displayName = "ColumnHeaders";
1634
1643
  function RowHeader({ rowIndex }) {
1635
- const { rowHeight } = useSpreadsheet();
1644
+ const { rowHeight, columnCount, selectRange } = useSpreadsheet();
1645
+ const handleClick = useCallback(() => {
1646
+ const start = toAddress(rowIndex, 0);
1647
+ const end = toAddress(rowIndex, columnCount - 1);
1648
+ selectRange(start, end);
1649
+ }, [rowIndex, columnCount, selectRange]);
1636
1650
  return /* @__PURE__ */ jsx(
1637
1651
  "div",
1638
1652
  {
1639
1653
  "data-fancy-sheets-row-header": "",
1640
- 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",
1654
+ 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",
1641
1655
  style: { width: 48, minWidth: 48, height: rowHeight },
1656
+ onClick: handleClick,
1642
1657
  children: rowIndex + 1
1643
1658
  }
1644
1659
  );
@@ -2045,6 +2060,8 @@ function DefaultToolbar() {
2045
2060
  confirmEdit,
2046
2061
  startEdit,
2047
2062
  setCellFormat,
2063
+ setFrozenRows,
2064
+ setFrozenCols,
2048
2065
  undo,
2049
2066
  redo,
2050
2067
  canUndo,
@@ -2116,7 +2133,57 @@ function DefaultToolbar() {
2116
2133
  ] })
2117
2134
  },
2118
2135
  align
2119
- ))
2136
+ )),
2137
+ /* @__PURE__ */ jsx("div", { className: "mx-1 h-4 w-px bg-zinc-200 dark:bg-zinc-700" }),
2138
+ /* @__PURE__ */ jsx(
2139
+ "button",
2140
+ {
2141
+ className: cn(btnClass, activeSheet.frozenRows > 0 && activeBtnClass),
2142
+ onClick: () => {
2143
+ if (activeSheet.frozenRows > 0) {
2144
+ setFrozenRows(0);
2145
+ } else {
2146
+ const row = selection.activeCell.match(/\d+/);
2147
+ setFrozenRows(row ? parseInt(row[0], 10) - 1 || 1 : 1);
2148
+ }
2149
+ },
2150
+ disabled: readOnly,
2151
+ title: activeSheet.frozenRows > 0 ? `Unfreeze rows (${activeSheet.frozenRows} frozen)` : "Freeze rows above current cell",
2152
+ children: /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: [
2153
+ /* @__PURE__ */ jsx("line", { x1: "3", y1: "9", x2: "21", y2: "9" }),
2154
+ /* @__PURE__ */ jsx("line", { x1: "3", y1: "4", x2: "21", y2: "4" }),
2155
+ /* @__PURE__ */ jsx("line", { x1: "3", y1: "14", x2: "21", y2: "14", strokeDasharray: "3 3" }),
2156
+ /* @__PURE__ */ jsx("line", { x1: "3", y1: "19", x2: "21", y2: "19", strokeDasharray: "3 3" })
2157
+ ] })
2158
+ }
2159
+ ),
2160
+ /* @__PURE__ */ jsx(
2161
+ "button",
2162
+ {
2163
+ className: cn(btnClass, activeSheet.frozenCols > 0 && activeBtnClass),
2164
+ onClick: () => {
2165
+ if (activeSheet.frozenCols > 0) {
2166
+ setFrozenCols(0);
2167
+ } else {
2168
+ const colMatch = selection.activeCell.match(/^([A-Z]+)/);
2169
+ if (colMatch) {
2170
+ const col = colMatch[1].split("").reduce((acc, ch) => acc * 26 + ch.charCodeAt(0) - 64, 0) - 1;
2171
+ setFrozenCols(col || 1);
2172
+ } else {
2173
+ setFrozenCols(1);
2174
+ }
2175
+ }
2176
+ },
2177
+ disabled: readOnly,
2178
+ title: activeSheet.frozenCols > 0 ? `Unfreeze columns (${activeSheet.frozenCols} frozen)` : "Freeze columns left of current cell",
2179
+ children: /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: [
2180
+ /* @__PURE__ */ jsx("line", { x1: "9", y1: "3", x2: "9", y2: "21" }),
2181
+ /* @__PURE__ */ jsx("line", { x1: "4", y1: "3", x2: "4", y2: "21" }),
2182
+ /* @__PURE__ */ jsx("line", { x1: "14", y1: "3", x2: "14", y2: "21", strokeDasharray: "3 3" }),
2183
+ /* @__PURE__ */ jsx("line", { x1: "19", y1: "3", x2: "19", y2: "21", strokeDasharray: "3 3" })
2184
+ ] })
2185
+ }
2186
+ )
2120
2187
  ] }),
2121
2188
  /* @__PURE__ */ 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: [
2122
2189
  /* @__PURE__ */ jsx("span", { className: "w-12 shrink-0 text-center text-[11px] font-medium text-zinc-500 dark:text-zinc-400", children: selection.activeCell }),