@particle-academy/fancy-sheets 0.6.3 → 0.7.0

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
@@ -1349,6 +1349,8 @@ function reducer(state, action) {
1349
1349
  const sheet = getActiveSheet(state);
1350
1350
  const existing = sheet.cells[action.address];
1351
1351
  if (existing?.format) cellData.format = existing.format;
1352
+ if (existing?.meta) cellData.meta = existing.meta;
1353
+ if (existing?.comment) cellData.comment = existing.comment;
1352
1354
  const updatedWorkbook = updateActiveSheet(state, (s) => ({
1353
1355
  ...s,
1354
1356
  cells: { ...s.cells, [action.address]: cellData }
@@ -1805,9 +1807,11 @@ var Cell = React.memo(function Cell2({ address, row, col }) {
1805
1807
  getColumnWidth,
1806
1808
  isCellSelected,
1807
1809
  isCellActive,
1810
+ highlights,
1808
1811
  _isDragging
1809
1812
  } = useSpreadsheet();
1810
1813
  const cell = activeSheet.cells[address];
1814
+ const highlight = highlights[address];
1811
1815
  const isActive = isCellActive(address);
1812
1816
  const isSelected = isCellSelected(address);
1813
1817
  const isEditing = editingCell === address;
@@ -1875,11 +1879,13 @@ var Cell = React.memo(function Cell2({ address, row, col }) {
1875
1879
  "data-fancy-sheets-cell": "",
1876
1880
  "data-selected": isSelected || void 0,
1877
1881
  "data-active": isActive || void 0,
1882
+ "data-highlighted": !!highlight || void 0,
1878
1883
  role: "gridcell",
1879
1884
  className: reactFancy.cn(
1880
1885
  "relative flex items-center truncate border-r border-b border-zinc-200 bg-white px-1.5 text-[13px] select-none dark:border-zinc-700 dark:bg-zinc-900",
1881
1886
  isActive && "ring-2 ring-inset ring-blue-500",
1882
- isSelected && !isActive && "bg-blue-50 dark:bg-blue-950/40"
1887
+ isSelected && !isActive && "bg-blue-50 dark:bg-blue-950/40",
1888
+ cell?.format?.className
1883
1889
  ),
1884
1890
  style: { width, minWidth: width, height: rowHeight, ...formatStyle },
1885
1891
  onMouseDown: handleMouseDown,
@@ -1893,6 +1899,27 @@ var Cell = React.memo(function Cell2({ address, row, col }) {
1893
1899
  },
1894
1900
  onDoubleClick: handleDoubleClick,
1895
1901
  children: [
1902
+ highlight && /* @__PURE__ */ jsxRuntime.jsx(
1903
+ "div",
1904
+ {
1905
+ className: "pointer-events-none absolute inset-0",
1906
+ style: {
1907
+ outline: `2px solid ${highlight.color}`,
1908
+ outlineOffset: "-2px",
1909
+ backgroundColor: highlight.backgroundColor ?? (highlight.color.startsWith("#") ? `${highlight.color}1A` : void 0)
1910
+ },
1911
+ "aria-hidden": true
1912
+ }
1913
+ ),
1914
+ highlight?.label && /* @__PURE__ */ jsxRuntime.jsx(
1915
+ "span",
1916
+ {
1917
+ className: "pointer-events-none absolute top-0 left-0 z-[1] px-0.5 text-[8px] font-bold leading-none text-white",
1918
+ style: { backgroundColor: highlight.color },
1919
+ "aria-hidden": true,
1920
+ children: highlight.label
1921
+ }
1922
+ ),
1896
1923
  !isEditing && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: displayValue }),
1897
1924
  comment && /* @__PURE__ */ jsxRuntime.jsx(
1898
1925
  "div",
@@ -2588,7 +2615,9 @@ function SpreadsheetRoot({
2588
2615
  defaultColumnWidth = 100,
2589
2616
  rowHeight = 28,
2590
2617
  readOnly = false,
2591
- contextMenuItems
2618
+ contextMenuItems,
2619
+ highlights,
2620
+ onActiveCellChange
2592
2621
  }) {
2593
2622
  const { state, actions } = useSpreadsheetStore(data ?? defaultData);
2594
2623
  const onChangeRef = React.useRef(onChange);
@@ -2634,7 +2663,15 @@ function SpreadsheetRoot({
2634
2663
  (address) => state.selection.activeCell === address,
2635
2664
  [state.selection.activeCell]
2636
2665
  );
2666
+ const onActiveCellChangeRef = React.useRef(onActiveCellChange);
2667
+ onActiveCellChangeRef.current = onActiveCellChange;
2668
+ React.useEffect(() => {
2669
+ const addr = state.selection.activeCell;
2670
+ const cell = activeSheet.cells[addr];
2671
+ onActiveCellChangeRef.current?.(addr, cell);
2672
+ }, [state.selection.activeCell, activeSheet]);
2637
2673
  const isDraggingRef = React.useRef(false);
2674
+ const highlightsResolved = highlights ?? {};
2638
2675
  const ctx = React.useMemo(
2639
2676
  () => ({
2640
2677
  workbook: state.workbook,
@@ -2654,9 +2691,10 @@ function SpreadsheetRoot({
2654
2691
  isCellSelected,
2655
2692
  isCellActive,
2656
2693
  contextMenuItems,
2694
+ highlights: highlightsResolved,
2657
2695
  _isDragging: isDraggingRef
2658
2696
  }),
2659
- [state, activeSheet, columnCount, rowCount, defaultColumnWidth, rowHeight, readOnly, actions, getColumnWidth, isCellSelected, isCellActive, contextMenuItems]
2697
+ [state, activeSheet, columnCount, rowCount, defaultColumnWidth, rowHeight, readOnly, actions, getColumnWidth, isCellSelected, isCellActive, contextMenuItems, highlightsResolved]
2660
2698
  );
2661
2699
  return /* @__PURE__ */ jsxRuntime.jsx(SpreadsheetContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxRuntime.jsx(
2662
2700
  "div",
@@ -2673,7 +2711,7 @@ var Spreadsheet = Object.assign(SpreadsheetRoot, {
2673
2711
  Grid: SpreadsheetGrid,
2674
2712
  SheetTabs: SpreadsheetSheetTabs
2675
2713
  });
2676
- function Sheet({ data, onChange, contextMenuItems, ...props }) {
2714
+ function Sheet({ data, onChange, contextMenuItems, highlights, onActiveCellChange, ...props }) {
2677
2715
  const workbook = React.useMemo(
2678
2716
  () => data ? { sheets: [data], activeSheetId: data.id } : void 0,
2679
2717
  [data]
@@ -2682,7 +2720,7 @@ function Sheet({ data, onChange, contextMenuItems, ...props }) {
2682
2720
  if (!onChange) return void 0;
2683
2721
  return (wb) => onChange(wb.sheets[0]);
2684
2722
  }, [onChange]);
2685
- return /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet, { data: workbook, onChange: handleChange, contextMenuItems, ...props, children: /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Grid, {}) });
2723
+ return /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet, { data: workbook, onChange: handleChange, contextMenuItems, highlights, onActiveCellChange, ...props, children: /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Grid, {}) });
2686
2724
  }
2687
2725
  Sheet.displayName = "Sheet";
2688
2726
  function SheetWorkbook({
@@ -2691,9 +2729,11 @@ function SheetWorkbook({
2691
2729
  toolbarExtra,
2692
2730
  toolbarButtons,
2693
2731
  contextMenuItems,
2732
+ highlights,
2733
+ onActiveCellChange,
2694
2734
  ...props
2695
2735
  }) {
2696
- return /* @__PURE__ */ jsxRuntime.jsxs(Spreadsheet, { ...props, contextMenuItems, children: [
2736
+ return /* @__PURE__ */ jsxRuntime.jsxs(Spreadsheet, { ...props, contextMenuItems, highlights, onActiveCellChange, children: [
2697
2737
  !hideToolbar && /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Toolbar, { extra: toolbarExtra, buttons: toolbarButtons }),
2698
2738
  /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Grid, {}),
2699
2739
  !hideTabs && /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.SheetTabs, {})