@particle-academy/fancy-sheets 0.1.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.
@@ -0,0 +1,189 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ /** Column-letter + row-number string, e.g. "A1", "BC42" */
5
+ type CellAddress = string;
6
+ /** Primitive cell value */
7
+ type CellValue = string | number | boolean | null;
8
+ /** Text alignment */
9
+ type TextAlign = "left" | "center" | "right";
10
+ /** Cell formatting */
11
+ interface CellFormat {
12
+ bold?: boolean;
13
+ italic?: boolean;
14
+ textAlign?: TextAlign;
15
+ }
16
+ /** A single cell's complete data */
17
+ interface CellData {
18
+ /** The raw value (what the user typed) */
19
+ value: CellValue;
20
+ /** Formula string without leading "=", e.g. "SUM(A1:A5)" */
21
+ formula?: string;
22
+ /** Computed value after formula evaluation */
23
+ computedValue?: CellValue;
24
+ /** Display formatting */
25
+ format?: CellFormat;
26
+ }
27
+
28
+ /** Sparse cell map — only stores cells that have data */
29
+ type CellMap = Record<string, CellData>;
30
+ /** Column width overrides (col index -> px) */
31
+ type ColumnWidths = Record<number, number>;
32
+ /** Merged region defined by top-left and bottom-right addresses */
33
+ interface MergedRegion {
34
+ start: string;
35
+ end: string;
36
+ }
37
+ /** A single sheet within a workbook */
38
+ interface SheetData {
39
+ id: string;
40
+ name: string;
41
+ cells: CellMap;
42
+ columnWidths: ColumnWidths;
43
+ mergedRegions: MergedRegion[];
44
+ columnFilters: Record<number, string>;
45
+ sortColumn?: number;
46
+ sortDirection?: "asc" | "desc";
47
+ frozenRows: number;
48
+ frozenCols: number;
49
+ }
50
+ /** The complete workbook */
51
+ interface WorkbookData {
52
+ sheets: SheetData[];
53
+ activeSheetId: string;
54
+ }
55
+ /** Create an empty sheet */
56
+ declare function createEmptySheet(id: string, name: string): SheetData;
57
+ /** Create an empty workbook with one sheet */
58
+ declare function createEmptyWorkbook(): WorkbookData;
59
+
60
+ /** A rectangular range of cells */
61
+ interface CellRange {
62
+ start: string;
63
+ end: string;
64
+ }
65
+ /** Full selection state */
66
+ interface SelectionState {
67
+ /** The anchor cell (where selection started) */
68
+ activeCell: string;
69
+ /** Ranges currently selected (supports multi-select via Ctrl+Click) */
70
+ ranges: CellRange[];
71
+ }
72
+
73
+ interface SpreadsheetProps {
74
+ children: ReactNode;
75
+ className?: string;
76
+ /** Controlled workbook data */
77
+ data?: WorkbookData;
78
+ /** Default data (uncontrolled) */
79
+ defaultData?: WorkbookData;
80
+ /** Called on any data change */
81
+ onChange?: (data: WorkbookData) => void;
82
+ /** Number of columns (default: 26) */
83
+ columnCount?: number;
84
+ /** Number of rows (default: 100) */
85
+ rowCount?: number;
86
+ /** Default column width in px (default: 100) */
87
+ defaultColumnWidth?: number;
88
+ /** Row height in px (default: 28) */
89
+ rowHeight?: number;
90
+ /** Read-only mode */
91
+ readOnly?: boolean;
92
+ }
93
+ interface SpreadsheetContextValue {
94
+ workbook: WorkbookData;
95
+ activeSheet: SheetData;
96
+ columnCount: number;
97
+ rowCount: number;
98
+ defaultColumnWidth: number;
99
+ rowHeight: number;
100
+ readOnly: boolean;
101
+ selection: SelectionState;
102
+ editingCell: string | null;
103
+ editValue: string;
104
+ setCellValue: (address: string, value: string) => void;
105
+ setCellFormat: (addresses: string[], format: Partial<CellFormat>) => void;
106
+ setSelection: (cell: string) => void;
107
+ extendSelection: (cell: string) => void;
108
+ addSelection: (cell: string) => void;
109
+ navigate: (direction: "up" | "down" | "left" | "right", extend?: boolean) => void;
110
+ startEdit: (value?: string) => void;
111
+ updateEdit: (value: string) => void;
112
+ confirmEdit: () => void;
113
+ cancelEdit: () => void;
114
+ resizeColumn: (col: number, width: number) => void;
115
+ addSheet: () => void;
116
+ renameSheet: (sheetId: string, name: string) => void;
117
+ deleteSheet: (sheetId: string) => void;
118
+ setActiveSheet: (sheetId: string) => void;
119
+ undo: () => void;
120
+ redo: () => void;
121
+ canUndo: boolean;
122
+ canRedo: boolean;
123
+ getColumnWidth: (col: number) => number;
124
+ isCellSelected: (address: string) => boolean;
125
+ isCellActive: (address: string) => boolean;
126
+ }
127
+
128
+ interface SpreadsheetGridProps {
129
+ className?: string;
130
+ }
131
+ declare function SpreadsheetGrid({ className }: SpreadsheetGridProps): react_jsx_runtime.JSX.Element;
132
+ declare namespace SpreadsheetGrid {
133
+ var displayName: string;
134
+ }
135
+
136
+ interface SpreadsheetToolbarProps {
137
+ children?: React.ReactNode;
138
+ className?: string;
139
+ }
140
+ declare function SpreadsheetToolbar({ children, className }: SpreadsheetToolbarProps): react_jsx_runtime.JSX.Element;
141
+ declare namespace SpreadsheetToolbar {
142
+ var displayName: string;
143
+ }
144
+
145
+ interface SpreadsheetSheetTabsProps {
146
+ className?: string;
147
+ }
148
+ declare function SpreadsheetSheetTabs({ className }: SpreadsheetSheetTabsProps): react_jsx_runtime.JSX.Element;
149
+ declare namespace SpreadsheetSheetTabs {
150
+ var displayName: string;
151
+ }
152
+
153
+ declare function SpreadsheetRoot({ children, className, data, defaultData, onChange, columnCount, rowCount, defaultColumnWidth, rowHeight, readOnly, }: SpreadsheetProps): react_jsx_runtime.JSX.Element;
154
+ declare namespace SpreadsheetRoot {
155
+ var displayName: string;
156
+ }
157
+ declare const Spreadsheet: typeof SpreadsheetRoot & {
158
+ Toolbar: typeof SpreadsheetToolbar;
159
+ Grid: typeof SpreadsheetGrid;
160
+ SheetTabs: typeof SpreadsheetSheetTabs;
161
+ };
162
+
163
+ declare function useSpreadsheet(): SpreadsheetContextValue;
164
+
165
+ /** Convert 0-based column index to letter(s): 0="A", 25="Z", 26="AA" */
166
+ declare function columnToLetter(col: number): string;
167
+ /** Convert column letter(s) to 0-based index: "A"=0, "Z"=25, "AA"=26 */
168
+ declare function letterToColumn(letters: string): number;
169
+ /** Parse address string to 0-based row and col: "B3" -> { row: 2, col: 1 } */
170
+ declare function parseAddress(addr: string): {
171
+ row: number;
172
+ col: number;
173
+ };
174
+ /** Convert 0-based row and col to address string: (2, 1) -> "B3" */
175
+ declare function toAddress(row: number, col: number): string;
176
+
177
+ /** Parse CSV text into a 2D string array */
178
+ declare function parseCSV(text: string): string[][];
179
+ /** Stringify a 2D array to CSV text */
180
+ declare function stringifyCSV(data: string[][]): string;
181
+ /** Convert CSV text to a WorkbookData */
182
+ declare function csvToWorkbook(csv: string, sheetName?: string): WorkbookData;
183
+ /** Convert WorkbookData active sheet to CSV */
184
+ declare function workbookToCSV(workbook: WorkbookData, sheetId?: string): string;
185
+
186
+ type FormulaRangeFunction = (args: CellValue[][]) => CellValue;
187
+ declare function registerFunction(name: string, fn: FormulaRangeFunction): void;
188
+
189
+ export { type CellAddress, type CellData, type CellFormat, type CellMap, type CellRange, type CellValue, type ColumnWidths, type MergedRegion, type SelectionState, type SheetData, Spreadsheet, type SpreadsheetContextValue, type SpreadsheetProps, type TextAlign, type WorkbookData, columnToLetter, createEmptySheet, createEmptyWorkbook, csvToWorkbook, letterToColumn, parseAddress, parseCSV, registerFunction, stringifyCSV, toAddress, useSpreadsheet, workbookToCSV };