@particle-academy/fancy-sheets 0.5.1 → 0.6.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 +42 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +44 -5
- package/dist/index.js.map +1 -1
- package/docs/Spreadsheet.md +140 -77
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -33,6 +33,15 @@ interface CellFormat {
|
|
|
33
33
|
/** Left border color (renders 1px solid) */
|
|
34
34
|
borderLeft?: string;
|
|
35
35
|
}
|
|
36
|
+
/** Cell comment */
|
|
37
|
+
interface CellComment {
|
|
38
|
+
/** Comment text */
|
|
39
|
+
text: string;
|
|
40
|
+
/** Author name (optional) */
|
|
41
|
+
author?: string;
|
|
42
|
+
/** Comment color — used for the corner triangle indicator and cell border (default: #f59e0b / amber-500) */
|
|
43
|
+
color?: string;
|
|
44
|
+
}
|
|
36
45
|
/** A single cell's complete data */
|
|
37
46
|
interface CellData {
|
|
38
47
|
/** The raw value (what the user typed) */
|
|
@@ -43,6 +52,8 @@ interface CellData {
|
|
|
43
52
|
computedValue?: CellValue;
|
|
44
53
|
/** Display formatting */
|
|
45
54
|
format?: CellFormat;
|
|
55
|
+
/** Cell comment — shows a triangle indicator in the corner */
|
|
56
|
+
comment?: CellComment;
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
/** Sparse cell map — only stores cells that have data */
|
|
@@ -284,4 +295,4 @@ declare function workbookToCSV(workbook: WorkbookData, sheetId?: string): string
|
|
|
284
295
|
type FormulaRangeFunction = (args: CellValue[][]) => CellValue;
|
|
285
296
|
declare function registerFunction(name: string, fn: FormulaRangeFunction): void;
|
|
286
297
|
|
|
287
|
-
export { type CellAddress, type CellData, type CellFormat, type CellMap, type CellRange, type CellValue, type ColumnWidths, type FormulaRangeFunction, type MergedRegion, type SelectionState, Sheet, type SheetData, type SheetProps, SheetWorkbook, type SheetWorkbookProps, Spreadsheet, type SpreadsheetContextMenuItem, type SpreadsheetContextValue, type SpreadsheetProps, type TextAlign, type WorkbookData, columnToLetter, createEmptySheet, createEmptyWorkbook, csvToWorkbook, letterToColumn, parseAddress, parseCSV, registerFunction, stringifyCSV, toAddress, useSpreadsheet, workbookToCSV };
|
|
298
|
+
export { type CellAddress, type CellComment, type CellData, type CellFormat, type CellMap, type CellRange, type CellValue, type ColumnWidths, type FormulaRangeFunction, type MergedRegion, type SelectionState, Sheet, type SheetData, type SheetProps, SheetWorkbook, type SheetWorkbookProps, Spreadsheet, type SpreadsheetContextMenuItem, type SpreadsheetContextValue, type SpreadsheetProps, type TextAlign, type WorkbookData, columnToLetter, createEmptySheet, createEmptyWorkbook, csvToWorkbook, letterToColumn, parseAddress, parseCSV, registerFunction, stringifyCSV, toAddress, useSpreadsheet, workbookToCSV };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,15 @@ interface CellFormat {
|
|
|
33
33
|
/** Left border color (renders 1px solid) */
|
|
34
34
|
borderLeft?: string;
|
|
35
35
|
}
|
|
36
|
+
/** Cell comment */
|
|
37
|
+
interface CellComment {
|
|
38
|
+
/** Comment text */
|
|
39
|
+
text: string;
|
|
40
|
+
/** Author name (optional) */
|
|
41
|
+
author?: string;
|
|
42
|
+
/** Comment color — used for the corner triangle indicator and cell border (default: #f59e0b / amber-500) */
|
|
43
|
+
color?: string;
|
|
44
|
+
}
|
|
36
45
|
/** A single cell's complete data */
|
|
37
46
|
interface CellData {
|
|
38
47
|
/** The raw value (what the user typed) */
|
|
@@ -43,6 +52,8 @@ interface CellData {
|
|
|
43
52
|
computedValue?: CellValue;
|
|
44
53
|
/** Display formatting */
|
|
45
54
|
format?: CellFormat;
|
|
55
|
+
/** Cell comment — shows a triangle indicator in the corner */
|
|
56
|
+
comment?: CellComment;
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
/** Sparse cell map — only stores cells that have data */
|
|
@@ -284,4 +295,4 @@ declare function workbookToCSV(workbook: WorkbookData, sheetId?: string): string
|
|
|
284
295
|
type FormulaRangeFunction = (args: CellValue[][]) => CellValue;
|
|
285
296
|
declare function registerFunction(name: string, fn: FormulaRangeFunction): void;
|
|
286
297
|
|
|
287
|
-
export { type CellAddress, type CellData, type CellFormat, type CellMap, type CellRange, type CellValue, type ColumnWidths, type FormulaRangeFunction, type MergedRegion, type SelectionState, Sheet, type SheetData, type SheetProps, SheetWorkbook, type SheetWorkbookProps, Spreadsheet, type SpreadsheetContextMenuItem, type SpreadsheetContextValue, type SpreadsheetProps, type TextAlign, type WorkbookData, columnToLetter, createEmptySheet, createEmptyWorkbook, csvToWorkbook, letterToColumn, parseAddress, parseCSV, registerFunction, stringifyCSV, toAddress, useSpreadsheet, workbookToCSV };
|
|
298
|
+
export { type CellAddress, type CellComment, type CellData, type CellFormat, type CellMap, type CellRange, type CellValue, type ColumnWidths, type FormulaRangeFunction, type MergedRegion, type SelectionState, Sheet, type SheetData, type SheetProps, SheetWorkbook, type SheetWorkbookProps, Spreadsheet, type SpreadsheetContextMenuItem, type SpreadsheetContextValue, type SpreadsheetProps, type TextAlign, type WorkbookData, columnToLetter, createEmptySheet, createEmptyWorkbook, csvToWorkbook, letterToColumn, parseAddress, parseCSV, registerFunction, stringifyCSV, toAddress, useSpreadsheet, workbookToCSV };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createContext, memo, useCallback, useContext, useRef, useEffect, useMemo,
|
|
1
|
+
import { createContext, memo, useCallback, useState, useContext, useRef, useEffect, useMemo, useReducer } from 'react';
|
|
2
2
|
import { cn, ContextMenu } from '@particle-academy/react-fancy';
|
|
3
|
-
import {
|
|
3
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
// src/components/Spreadsheet/Spreadsheet.tsx
|
|
6
6
|
var SpreadsheetContext = createContext(null);
|
|
@@ -1737,6 +1737,7 @@ function RowHeader({ rowIndex }) {
|
|
|
1737
1737
|
);
|
|
1738
1738
|
}
|
|
1739
1739
|
RowHeader.displayName = "RowHeader";
|
|
1740
|
+
var DEFAULT_COMMENT_COLOR = "#f59e0b";
|
|
1740
1741
|
var EXCEL_EPOCH2 = new Date(1899, 11, 30).getTime();
|
|
1741
1742
|
function serialToDateStr(serial) {
|
|
1742
1743
|
const d = new Date(EXCEL_EPOCH2 + Math.floor(serial) * 864e5);
|
|
@@ -1854,7 +1855,15 @@ var Cell = memo(function Cell2({ address, row, col }) {
|
|
|
1854
1855
|
formatStyle.borderLeftStyle = "solid";
|
|
1855
1856
|
formatStyle.borderLeftColor = cell.format.borderLeft;
|
|
1856
1857
|
}
|
|
1857
|
-
|
|
1858
|
+
const comment = cell?.comment;
|
|
1859
|
+
const commentColor = comment?.color ?? DEFAULT_COMMENT_COLOR;
|
|
1860
|
+
if (comment) {
|
|
1861
|
+
formatStyle.borderColor = commentColor;
|
|
1862
|
+
formatStyle.borderWidth = 1;
|
|
1863
|
+
formatStyle.borderStyle = "solid";
|
|
1864
|
+
}
|
|
1865
|
+
const [showComment, setShowComment] = useState(false);
|
|
1866
|
+
return /* @__PURE__ */ jsxs(
|
|
1858
1867
|
"div",
|
|
1859
1868
|
{
|
|
1860
1869
|
"data-fancy-sheets-cell": "",
|
|
@@ -1868,10 +1877,40 @@ var Cell = memo(function Cell2({ address, row, col }) {
|
|
|
1868
1877
|
),
|
|
1869
1878
|
style: { width, minWidth: width, height: rowHeight, ...formatStyle },
|
|
1870
1879
|
onMouseDown: handleMouseDown,
|
|
1871
|
-
onMouseEnter:
|
|
1880
|
+
onMouseEnter: (e) => {
|
|
1881
|
+
handleMouseEnter();
|
|
1882
|
+
if (comment) setShowComment(true);
|
|
1883
|
+
},
|
|
1872
1884
|
onMouseUp: handleMouseUp,
|
|
1885
|
+
onMouseLeave: () => {
|
|
1886
|
+
if (comment) setShowComment(false);
|
|
1887
|
+
},
|
|
1873
1888
|
onDoubleClick: handleDoubleClick,
|
|
1874
|
-
children:
|
|
1889
|
+
children: [
|
|
1890
|
+
!isEditing && /* @__PURE__ */ jsx("span", { className: "truncate", children: displayValue }),
|
|
1891
|
+
comment && /* @__PURE__ */ jsx(
|
|
1892
|
+
"div",
|
|
1893
|
+
{
|
|
1894
|
+
className: "absolute top-0 right-0 h-0 w-0",
|
|
1895
|
+
style: {
|
|
1896
|
+
borderTop: `6px solid ${commentColor}`,
|
|
1897
|
+
borderLeft: "6px solid transparent"
|
|
1898
|
+
},
|
|
1899
|
+
"aria-hidden": true
|
|
1900
|
+
}
|
|
1901
|
+
),
|
|
1902
|
+
comment && showComment && /* @__PURE__ */ jsxs(
|
|
1903
|
+
"div",
|
|
1904
|
+
{
|
|
1905
|
+
className: "absolute top-full left-0 z-50 mt-0.5 max-w-[200px] rounded border bg-white px-2 py-1.5 text-[11px] leading-tight shadow-lg dark:bg-zinc-800",
|
|
1906
|
+
style: { borderColor: commentColor },
|
|
1907
|
+
children: [
|
|
1908
|
+
comment.author && /* @__PURE__ */ jsx("div", { className: "mb-0.5 font-semibold", style: { color: commentColor }, children: comment.author }),
|
|
1909
|
+
/* @__PURE__ */ jsx("div", { className: "text-zinc-700 dark:text-zinc-200 whitespace-pre-wrap", children: comment.text })
|
|
1910
|
+
]
|
|
1911
|
+
}
|
|
1912
|
+
)
|
|
1913
|
+
]
|
|
1875
1914
|
}
|
|
1876
1915
|
);
|
|
1877
1916
|
});
|