@particle-academy/fancy-sheets 0.4.6 → 0.5.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
@@ -1838,6 +1838,24 @@ var Cell = react.memo(function Cell2({ address, row, col }) {
1838
1838
  if (cell?.format?.bold) formatStyle.fontWeight = "bold";
1839
1839
  if (cell?.format?.italic) formatStyle.fontStyle = "italic";
1840
1840
  if (cell?.format?.textAlign) formatStyle.textAlign = cell.format.textAlign;
1841
+ if (cell?.format?.backgroundColor) {
1842
+ formatStyle.backgroundColor = cell.format.backgroundColor;
1843
+ if (!cell.format.color) formatStyle.color = "#1f2937";
1844
+ }
1845
+ if (cell?.format?.color) formatStyle.color = cell.format.color;
1846
+ if (cell?.format?.fontSize) formatStyle.fontSize = cell.format.fontSize;
1847
+ if (cell?.format?.borderTop) {
1848
+ formatStyle.borderTopWidth = 1;
1849
+ formatStyle.borderTopStyle = "solid";
1850
+ formatStyle.borderTopColor = cell.format.borderTop;
1851
+ }
1852
+ if (cell?.format?.borderRight) formatStyle.borderRightColor = cell.format.borderRight;
1853
+ if (cell?.format?.borderBottom) formatStyle.borderBottomColor = cell.format.borderBottom;
1854
+ if (cell?.format?.borderLeft) {
1855
+ formatStyle.borderLeftWidth = 1;
1856
+ formatStyle.borderLeftStyle = "solid";
1857
+ formatStyle.borderLeftColor = cell.format.borderLeft;
1858
+ }
1841
1859
  return /* @__PURE__ */ jsxRuntime.jsx(
1842
1860
  "div",
1843
1861
  {
@@ -1997,7 +2015,8 @@ function SpreadsheetGrid({ className }) {
1997
2015
  setFrozenCols,
1998
2016
  extendSelection,
1999
2017
  undo,
2000
- redo
2018
+ redo,
2019
+ contextMenuItems
2001
2020
  } = useSpreadsheet();
2002
2021
  const containerRef = react.useRef(null);
2003
2022
  const handleKeyDown = react.useCallback(
@@ -2190,14 +2209,31 @@ function SpreadsheetGrid({ className }) {
2190
2209
  /* @__PURE__ */ jsxRuntime.jsx(reactFancy.ContextMenu.Item, { onClick: () => {
2191
2210
  const col = parseAddress(selection.activeCell).col;
2192
2211
  setFrozenCols(activeSheet.frozenCols > 0 ? 0 : col);
2193
- }, disabled: readOnly, children: activeSheet.frozenCols > 0 ? "Unfreeze columns" : "Freeze columns left" })
2212
+ }, disabled: readOnly, children: activeSheet.frozenCols > 0 ? "Unfreeze columns" : "Freeze columns left" }),
2213
+ (() => {
2214
+ const items = typeof contextMenuItems === "function" ? contextMenuItems(selection.activeCell) : contextMenuItems;
2215
+ if (!items || items.length === 0) return null;
2216
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2217
+ /* @__PURE__ */ jsxRuntime.jsx(reactFancy.ContextMenu.Separator, {}),
2218
+ items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx(
2219
+ reactFancy.ContextMenu.Item,
2220
+ {
2221
+ onClick: () => item.onClick(selection.activeCell),
2222
+ disabled: typeof item.disabled === "function" ? item.disabled(selection.activeCell) : item.disabled,
2223
+ danger: item.danger,
2224
+ children: item.label
2225
+ },
2226
+ i
2227
+ ))
2228
+ ] });
2229
+ })()
2194
2230
  ] })
2195
2231
  ] });
2196
2232
  }
2197
2233
  SpreadsheetGrid.displayName = "SpreadsheetGrid";
2198
2234
  var btnClass = "inline-flex items-center justify-center rounded px-2 py-1 text-[12px] font-medium text-zinc-600 transition-colors hover:bg-zinc-100 disabled:opacity-40 dark:text-zinc-300 dark:hover:bg-zinc-800";
2199
2235
  var activeBtnClass = "bg-zinc-200 dark:bg-zinc-700";
2200
- function DefaultToolbar() {
2236
+ function DefaultToolbar({ extra }) {
2201
2237
  const {
2202
2238
  selection,
2203
2239
  activeSheet,
@@ -2389,7 +2425,11 @@ function DefaultToolbar() {
2389
2425
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[8px]", children: "\u2192" })
2390
2426
  ]
2391
2427
  }
2392
- )
2428
+ ),
2429
+ extra && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2430
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-1 h-4 w-px bg-zinc-200 dark:bg-zinc-700" }),
2431
+ extra
2432
+ ] })
2393
2433
  ] }),
2394
2434
  /* @__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: [
2395
2435
  /* @__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 }),
@@ -2408,8 +2448,8 @@ function DefaultToolbar() {
2408
2448
  ] })
2409
2449
  ] });
2410
2450
  }
2411
- function SpreadsheetToolbar({ children, className }) {
2412
- return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-fancy-sheets-toolbar": "", className: reactFancy.cn("", className), children: children ?? /* @__PURE__ */ jsxRuntime.jsx(DefaultToolbar, {}) });
2451
+ function SpreadsheetToolbar({ children, className, extra }) {
2452
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-fancy-sheets-toolbar": "", className: reactFancy.cn("", className), children: children ?? /* @__PURE__ */ jsxRuntime.jsx(DefaultToolbar, { extra }) });
2413
2453
  }
2414
2454
  SpreadsheetToolbar.displayName = "SpreadsheetToolbar";
2415
2455
  function SpreadsheetSheetTabs({ className }) {
@@ -2506,7 +2546,8 @@ function SpreadsheetRoot({
2506
2546
  rowCount = 100,
2507
2547
  defaultColumnWidth = 100,
2508
2548
  rowHeight = 28,
2509
- readOnly = false
2549
+ readOnly = false,
2550
+ contextMenuItems
2510
2551
  }) {
2511
2552
  const { state, actions } = useSpreadsheetStore(data ?? defaultData);
2512
2553
  const onChangeRef = react.useRef(onChange);
@@ -2571,9 +2612,10 @@ function SpreadsheetRoot({
2571
2612
  getColumnWidth,
2572
2613
  isCellSelected,
2573
2614
  isCellActive,
2615
+ contextMenuItems,
2574
2616
  _isDragging: isDraggingRef
2575
2617
  }),
2576
- [state, activeSheet, columnCount, rowCount, defaultColumnWidth, rowHeight, readOnly, actions, getColumnWidth, isCellSelected, isCellActive]
2618
+ [state, activeSheet, columnCount, rowCount, defaultColumnWidth, rowHeight, readOnly, actions, getColumnWidth, isCellSelected, isCellActive, contextMenuItems]
2577
2619
  );
2578
2620
  return /* @__PURE__ */ jsxRuntime.jsx(SpreadsheetContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxRuntime.jsx(
2579
2621
  "div",
@@ -2590,6 +2632,32 @@ var Spreadsheet = Object.assign(SpreadsheetRoot, {
2590
2632
  Grid: SpreadsheetGrid,
2591
2633
  SheetTabs: SpreadsheetSheetTabs
2592
2634
  });
2635
+ function Sheet({ data, onChange, contextMenuItems, ...props }) {
2636
+ const workbook = react.useMemo(
2637
+ () => data ? { sheets: [data], activeSheetId: data.id } : void 0,
2638
+ [data]
2639
+ );
2640
+ const handleChange = react.useMemo(() => {
2641
+ if (!onChange) return void 0;
2642
+ return (wb) => onChange(wb.sheets[0]);
2643
+ }, [onChange]);
2644
+ return /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet, { data: workbook, onChange: handleChange, contextMenuItems, ...props, children: /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Grid, {}) });
2645
+ }
2646
+ Sheet.displayName = "Sheet";
2647
+ function SheetWorkbook({
2648
+ hideToolbar = false,
2649
+ hideTabs = false,
2650
+ toolbarExtra,
2651
+ contextMenuItems,
2652
+ ...props
2653
+ }) {
2654
+ return /* @__PURE__ */ jsxRuntime.jsxs(Spreadsheet, { ...props, contextMenuItems, children: [
2655
+ !hideToolbar && /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Toolbar, { extra: toolbarExtra }),
2656
+ /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Grid, {}),
2657
+ !hideTabs && /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.SheetTabs, {})
2658
+ ] });
2659
+ }
2660
+ SheetWorkbook.displayName = "SheetWorkbook";
2593
2661
 
2594
2662
  // src/engine/csv.ts
2595
2663
  function parseCSV(text) {
@@ -2687,6 +2755,8 @@ function workbookToCSV(workbook, sheetId) {
2687
2755
  return stringifyCSV(data);
2688
2756
  }
2689
2757
 
2758
+ exports.Sheet = Sheet;
2759
+ exports.SheetWorkbook = SheetWorkbook;
2690
2760
  exports.Spreadsheet = Spreadsheet;
2691
2761
  exports.columnToLetter = columnToLetter;
2692
2762
  exports.createEmptySheet = createEmptySheet;