@particle-academy/fancy-sheets 0.4.6 → 0.5.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 +75 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -3
- package/dist/index.d.ts +90 -3
- package/dist/index.js +74 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1838,6 +1838,21 @@ 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) formatStyle.backgroundColor = cell.format.backgroundColor;
|
|
1842
|
+
if (cell?.format?.color) formatStyle.color = cell.format.color;
|
|
1843
|
+
if (cell?.format?.fontSize) formatStyle.fontSize = cell.format.fontSize;
|
|
1844
|
+
if (cell?.format?.borderTop) {
|
|
1845
|
+
formatStyle.borderTopWidth = 1;
|
|
1846
|
+
formatStyle.borderTopStyle = "solid";
|
|
1847
|
+
formatStyle.borderTopColor = cell.format.borderTop;
|
|
1848
|
+
}
|
|
1849
|
+
if (cell?.format?.borderRight) formatStyle.borderRightColor = cell.format.borderRight;
|
|
1850
|
+
if (cell?.format?.borderBottom) formatStyle.borderBottomColor = cell.format.borderBottom;
|
|
1851
|
+
if (cell?.format?.borderLeft) {
|
|
1852
|
+
formatStyle.borderLeftWidth = 1;
|
|
1853
|
+
formatStyle.borderLeftStyle = "solid";
|
|
1854
|
+
formatStyle.borderLeftColor = cell.format.borderLeft;
|
|
1855
|
+
}
|
|
1841
1856
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1842
1857
|
"div",
|
|
1843
1858
|
{
|
|
@@ -1997,7 +2012,8 @@ function SpreadsheetGrid({ className }) {
|
|
|
1997
2012
|
setFrozenCols,
|
|
1998
2013
|
extendSelection,
|
|
1999
2014
|
undo,
|
|
2000
|
-
redo
|
|
2015
|
+
redo,
|
|
2016
|
+
contextMenuItems
|
|
2001
2017
|
} = useSpreadsheet();
|
|
2002
2018
|
const containerRef = react.useRef(null);
|
|
2003
2019
|
const handleKeyDown = react.useCallback(
|
|
@@ -2190,14 +2206,31 @@ function SpreadsheetGrid({ className }) {
|
|
|
2190
2206
|
/* @__PURE__ */ jsxRuntime.jsx(reactFancy.ContextMenu.Item, { onClick: () => {
|
|
2191
2207
|
const col = parseAddress(selection.activeCell).col;
|
|
2192
2208
|
setFrozenCols(activeSheet.frozenCols > 0 ? 0 : col);
|
|
2193
|
-
}, disabled: readOnly, children: activeSheet.frozenCols > 0 ? "Unfreeze columns" : "Freeze columns left" })
|
|
2209
|
+
}, disabled: readOnly, children: activeSheet.frozenCols > 0 ? "Unfreeze columns" : "Freeze columns left" }),
|
|
2210
|
+
(() => {
|
|
2211
|
+
const items = typeof contextMenuItems === "function" ? contextMenuItems(selection.activeCell) : contextMenuItems;
|
|
2212
|
+
if (!items || items.length === 0) return null;
|
|
2213
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2214
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactFancy.ContextMenu.Separator, {}),
|
|
2215
|
+
items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2216
|
+
reactFancy.ContextMenu.Item,
|
|
2217
|
+
{
|
|
2218
|
+
onClick: () => item.onClick(selection.activeCell),
|
|
2219
|
+
disabled: typeof item.disabled === "function" ? item.disabled(selection.activeCell) : item.disabled,
|
|
2220
|
+
danger: item.danger,
|
|
2221
|
+
children: item.label
|
|
2222
|
+
},
|
|
2223
|
+
i
|
|
2224
|
+
))
|
|
2225
|
+
] });
|
|
2226
|
+
})()
|
|
2194
2227
|
] })
|
|
2195
2228
|
] });
|
|
2196
2229
|
}
|
|
2197
2230
|
SpreadsheetGrid.displayName = "SpreadsheetGrid";
|
|
2198
2231
|
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
2232
|
var activeBtnClass = "bg-zinc-200 dark:bg-zinc-700";
|
|
2200
|
-
function DefaultToolbar() {
|
|
2233
|
+
function DefaultToolbar({ extra }) {
|
|
2201
2234
|
const {
|
|
2202
2235
|
selection,
|
|
2203
2236
|
activeSheet,
|
|
@@ -2389,7 +2422,11 @@ function DefaultToolbar() {
|
|
|
2389
2422
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[8px]", children: "\u2192" })
|
|
2390
2423
|
]
|
|
2391
2424
|
}
|
|
2392
|
-
)
|
|
2425
|
+
),
|
|
2426
|
+
extra && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2427
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-1 h-4 w-px bg-zinc-200 dark:bg-zinc-700" }),
|
|
2428
|
+
extra
|
|
2429
|
+
] })
|
|
2393
2430
|
] }),
|
|
2394
2431
|
/* @__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
2432
|
/* @__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 +2445,8 @@ function DefaultToolbar() {
|
|
|
2408
2445
|
] })
|
|
2409
2446
|
] });
|
|
2410
2447
|
}
|
|
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, {}) });
|
|
2448
|
+
function SpreadsheetToolbar({ children, className, extra }) {
|
|
2449
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-fancy-sheets-toolbar": "", className: reactFancy.cn("", className), children: children ?? /* @__PURE__ */ jsxRuntime.jsx(DefaultToolbar, { extra }) });
|
|
2413
2450
|
}
|
|
2414
2451
|
SpreadsheetToolbar.displayName = "SpreadsheetToolbar";
|
|
2415
2452
|
function SpreadsheetSheetTabs({ className }) {
|
|
@@ -2506,7 +2543,8 @@ function SpreadsheetRoot({
|
|
|
2506
2543
|
rowCount = 100,
|
|
2507
2544
|
defaultColumnWidth = 100,
|
|
2508
2545
|
rowHeight = 28,
|
|
2509
|
-
readOnly = false
|
|
2546
|
+
readOnly = false,
|
|
2547
|
+
contextMenuItems
|
|
2510
2548
|
}) {
|
|
2511
2549
|
const { state, actions } = useSpreadsheetStore(data ?? defaultData);
|
|
2512
2550
|
const onChangeRef = react.useRef(onChange);
|
|
@@ -2571,9 +2609,10 @@ function SpreadsheetRoot({
|
|
|
2571
2609
|
getColumnWidth,
|
|
2572
2610
|
isCellSelected,
|
|
2573
2611
|
isCellActive,
|
|
2612
|
+
contextMenuItems,
|
|
2574
2613
|
_isDragging: isDraggingRef
|
|
2575
2614
|
}),
|
|
2576
|
-
[state, activeSheet, columnCount, rowCount, defaultColumnWidth, rowHeight, readOnly, actions, getColumnWidth, isCellSelected, isCellActive]
|
|
2615
|
+
[state, activeSheet, columnCount, rowCount, defaultColumnWidth, rowHeight, readOnly, actions, getColumnWidth, isCellSelected, isCellActive, contextMenuItems]
|
|
2577
2616
|
);
|
|
2578
2617
|
return /* @__PURE__ */ jsxRuntime.jsx(SpreadsheetContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2579
2618
|
"div",
|
|
@@ -2590,6 +2629,32 @@ var Spreadsheet = Object.assign(SpreadsheetRoot, {
|
|
|
2590
2629
|
Grid: SpreadsheetGrid,
|
|
2591
2630
|
SheetTabs: SpreadsheetSheetTabs
|
|
2592
2631
|
});
|
|
2632
|
+
function Sheet({ data, onChange, contextMenuItems, ...props }) {
|
|
2633
|
+
const workbook = react.useMemo(
|
|
2634
|
+
() => data ? { sheets: [data], activeSheetId: data.id } : void 0,
|
|
2635
|
+
[data]
|
|
2636
|
+
);
|
|
2637
|
+
const handleChange = react.useMemo(() => {
|
|
2638
|
+
if (!onChange) return void 0;
|
|
2639
|
+
return (wb) => onChange(wb.sheets[0]);
|
|
2640
|
+
}, [onChange]);
|
|
2641
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet, { data: workbook, onChange: handleChange, contextMenuItems, ...props, children: /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Grid, {}) });
|
|
2642
|
+
}
|
|
2643
|
+
Sheet.displayName = "Sheet";
|
|
2644
|
+
function SheetWorkbook({
|
|
2645
|
+
hideToolbar = false,
|
|
2646
|
+
hideTabs = false,
|
|
2647
|
+
toolbarExtra,
|
|
2648
|
+
contextMenuItems,
|
|
2649
|
+
...props
|
|
2650
|
+
}) {
|
|
2651
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Spreadsheet, { ...props, contextMenuItems, children: [
|
|
2652
|
+
!hideToolbar && /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Toolbar, { extra: toolbarExtra }),
|
|
2653
|
+
/* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.Grid, {}),
|
|
2654
|
+
!hideTabs && /* @__PURE__ */ jsxRuntime.jsx(Spreadsheet.SheetTabs, {})
|
|
2655
|
+
] });
|
|
2656
|
+
}
|
|
2657
|
+
SheetWorkbook.displayName = "SheetWorkbook";
|
|
2593
2658
|
|
|
2594
2659
|
// src/engine/csv.ts
|
|
2595
2660
|
function parseCSV(text) {
|
|
@@ -2687,6 +2752,8 @@ function workbookToCSV(workbook, sheetId) {
|
|
|
2687
2752
|
return stringifyCSV(data);
|
|
2688
2753
|
}
|
|
2689
2754
|
|
|
2755
|
+
exports.Sheet = Sheet;
|
|
2756
|
+
exports.SheetWorkbook = SheetWorkbook;
|
|
2690
2757
|
exports.Spreadsheet = Spreadsheet;
|
|
2691
2758
|
exports.columnToLetter = columnToLetter;
|
|
2692
2759
|
exports.createEmptySheet = createEmptySheet;
|