@pixerate/editor 0.3.0 → 0.4.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.
@@ -0,0 +1,269 @@
1
+ type CellFormat = 'text' | 'number' | 'currency' | 'percentage' | 'date' | 'badge' | 'status' | 'assignee';
2
+ type ColumnType = 'bound' | 'freeform' | 'formula';
3
+ interface ColumnBinding {
4
+ dataSource: string;
5
+ field: string;
6
+ }
7
+ interface SpreadsheetColumn {
8
+ id: string;
9
+ key: string;
10
+ title: string;
11
+ width?: number;
12
+ type: ColumnType;
13
+ binding?: ColumnBinding;
14
+ formula?: string;
15
+ format?: CellFormat;
16
+ readOnly?: boolean;
17
+ }
18
+ type RowType = 'record' | 'freeform';
19
+ interface SpreadsheetRow {
20
+ id: string;
21
+ index: number;
22
+ height?: number;
23
+ recordId?: string;
24
+ type: RowType;
25
+ }
26
+ interface CellCoordinate {
27
+ row: number;
28
+ col: number;
29
+ rowId?: string;
30
+ colId?: string;
31
+ }
32
+ interface CellRange {
33
+ startRow: number;
34
+ startCol: number;
35
+ endRow: number;
36
+ endCol: number;
37
+ }
38
+ interface CellData {
39
+ raw: string;
40
+ value: any;
41
+ error?: string;
42
+ format?: CellFormat;
43
+ readOnly?: boolean;
44
+ }
45
+ interface SpreadsheetDocument {
46
+ id: string;
47
+ name: string;
48
+ columns: SpreadsheetColumn[];
49
+ rows: SpreadsheetRow[];
50
+ cells: Record<string, Record<string, CellData>>;
51
+ createdAt?: number;
52
+ updatedAt?: number;
53
+ }
54
+ interface SpreadsheetDataSourceField {
55
+ key: string;
56
+ label: string;
57
+ type: 'string' | 'number' | 'date' | 'boolean' | 'enum';
58
+ options?: Array<{
59
+ key: string;
60
+ label: string;
61
+ color?: string;
62
+ }>;
63
+ }
64
+ interface SpreadsheetDataSource {
65
+ id: string;
66
+ name: string;
67
+ getRecords(): Array<{
68
+ id: string;
69
+ [key: string]: any;
70
+ }>;
71
+ getFields(): SpreadsheetDataSourceField[];
72
+ updateRecord(recordId: string, field: string, value: any): Promise<void> | void;
73
+ }
74
+
75
+ type FormulaTokenType = 'NUMBER' | 'STRING' | 'BOOLEAN' | 'CELL_REF' | 'RANGE' | 'PROPERTY_REF' | 'IDENTIFIER' | 'OPERATOR' | 'LPAREN' | 'RPAREN' | 'COMMA' | 'EOF';
76
+ interface FormulaToken {
77
+ type: FormulaTokenType;
78
+ value: string;
79
+ position: number;
80
+ }
81
+ declare function tokenizeFormula(formula: string): FormulaToken[];
82
+
83
+ type ASTNode = LiteralNode | CellRefNode | RangeNode | PropertyRefNode | BinaryOpNode | UnaryOpNode | FunctionCallNode;
84
+ interface LiteralNode {
85
+ type: 'Literal';
86
+ value: number | string | boolean;
87
+ }
88
+ interface CellRefNode {
89
+ type: 'CellRef';
90
+ ref: string;
91
+ col: string;
92
+ row: number;
93
+ }
94
+ interface RangeNode {
95
+ type: 'Range';
96
+ raw: string;
97
+ startCol: string;
98
+ startRow: number;
99
+ endCol: string;
100
+ endRow: number;
101
+ }
102
+ interface PropertyRefNode {
103
+ type: 'PropertyRef';
104
+ property: string;
105
+ }
106
+ interface BinaryOpNode {
107
+ type: 'BinaryOp';
108
+ op: string;
109
+ left: ASTNode;
110
+ right: ASTNode;
111
+ }
112
+ interface UnaryOpNode {
113
+ type: 'UnaryOp';
114
+ op: string;
115
+ argument: ASTNode;
116
+ }
117
+ interface FunctionCallNode {
118
+ type: 'FunctionCall';
119
+ name: string;
120
+ args: ASTNode[];
121
+ }
122
+ declare function parseCellReference(ref: string): {
123
+ col: string;
124
+ row: number;
125
+ };
126
+ declare function parseRange(rangeStr: string): RangeNode;
127
+ declare class FormulaParser {
128
+ private tokens;
129
+ private current;
130
+ constructor(tokens: FormulaToken[]);
131
+ parse(): ASTNode;
132
+ private expression;
133
+ private comparison;
134
+ private concatenation;
135
+ private addition;
136
+ private multiplication;
137
+ private exponentiation;
138
+ private unary;
139
+ private primary;
140
+ private match;
141
+ private matchOperator;
142
+ private check;
143
+ private advance;
144
+ private isAtEnd;
145
+ private peek;
146
+ private previous;
147
+ private consume;
148
+ }
149
+ declare function parseFormula(formula: string): ASTNode;
150
+
151
+ interface EvaluationContext {
152
+ resolveCell?: (col: string, row: number) => any;
153
+ resolveRange?: (startCol: string, startRow: number, endCol: string, endRow: number) => any[];
154
+ resolveProperty?: (property: string) => any;
155
+ }
156
+ declare function colNameToIndex(col: string): number;
157
+ declare function indexToColName(index: number): string;
158
+ declare class FormulaEvaluator {
159
+ private context;
160
+ constructor(context?: EvaluationContext);
161
+ evaluate(astOrFormula: ASTNode | string): any;
162
+ private evaluateNode;
163
+ private callFunction;
164
+ }
165
+
166
+ interface CellDep {
167
+ col: string;
168
+ row: number;
169
+ }
170
+ declare function extractCellDependencies(node: ASTNode): CellDep[];
171
+ declare class DependencyGraph {
172
+ private dependencies;
173
+ private dependents;
174
+ setCellFormula(cellKey: string, formulaStr: string | null): void;
175
+ getDependencies(cellKey: string): string[];
176
+ getDependents(cellKey: string): string[];
177
+ /**
178
+ * Detects if there is a cycle containing cellKey.
179
+ */
180
+ hasCycle(cellKey: string): boolean;
181
+ /**
182
+ * Returns cells affected by updating cellKey in topological order.
183
+ */
184
+ getEvaluationOrder(startCellKey: string): {
185
+ order: string[];
186
+ hasCycle: boolean;
187
+ };
188
+ }
189
+
190
+ declare class DataSourceBinder {
191
+ private dataSources;
192
+ register(dataSource: SpreadsheetDataSource): void;
193
+ unregister(dataSourceId: string): void;
194
+ getDataSource(id: string): SpreadsheetDataSource | undefined;
195
+ /**
196
+ * Generates or reconciles spreadsheet rows from a primary data source.
197
+ */
198
+ syncRows(currentRows: SpreadsheetRow[], dataSourceId: string): SpreadsheetRow[];
199
+ /**
200
+ * Resolves a record's bound field value.
201
+ */
202
+ resolveBoundValue(dataSourceId: string, recordId: string, field: string): any;
203
+ /**
204
+ * Dispatches an update to the underlying data source.
205
+ */
206
+ commitBoundValue(dataSourceId: string, recordId: string, field: string, value: any): Promise<void>;
207
+ }
208
+
209
+ interface SpreadsheetControllerOptions {
210
+ document?: Partial<SpreadsheetDocument>;
211
+ dataSources?: SpreadsheetDataSource[];
212
+ primaryDataSourceId?: string;
213
+ onDocumentChange?: (doc: SpreadsheetDocument) => void;
214
+ onSelectionChange?: (activeCell: CellCoordinate | null, range: CellRange | null) => void;
215
+ onCellCommit?: (rowId: string, colId: string, raw: string, value: any) => void;
216
+ }
217
+ declare class SpreadsheetController {
218
+ document: SpreadsheetDocument;
219
+ activeCell: CellCoordinate | null;
220
+ selectedRange: CellRange | null;
221
+ editingCell: CellCoordinate | null;
222
+ draftValue: string;
223
+ readonly binder: DataSourceBinder;
224
+ readonly depGraph: DependencyGraph;
225
+ readonly evaluator: FormulaEvaluator;
226
+ private primaryDataSourceId?;
227
+ private onDocumentChange?;
228
+ private onSelectionChange?;
229
+ private onCellCommit?;
230
+ private undoStack;
231
+ private redoStack;
232
+ private isApplyingHistory;
233
+ constructor(options?: SpreadsheetControllerOptions);
234
+ loadDocument(document: SpreadsheetDocument): void;
235
+ registerDataSource(ds: SpreadsheetDataSource): void;
236
+ setPrimaryDataSource(dataSourceId: string | undefined): void;
237
+ syncWithDataSource(): void;
238
+ private recomputeRowIndices;
239
+ getColumn(colIdOrKey: string): SpreadsheetColumn | undefined;
240
+ getRow(rowIdOrIndex: string | number): SpreadsheetRow | undefined;
241
+ getCell(rowId: string, colId: string): CellData;
242
+ setCellValue(rowId: string, colId: string, raw: string): void;
243
+ private getCellKey;
244
+ recalculateCell(rowId: string, colId: string): void;
245
+ recalculateAll(): void;
246
+ private evalSingleCellByKey;
247
+ private resolveCellByCoord;
248
+ private resolveRangeByCoords;
249
+ private resolveCurrentRowProperty;
250
+ selectCell(row: number, col: number, extendSelection?: boolean): void;
251
+ selectRange(range: CellRange): void;
252
+ startEditing(row?: number, col?: number, initialValue?: string): void;
253
+ commitEditing(valueToCommit?: string): void;
254
+ cancelEditing(): void;
255
+ moveCursor(direction: 'up' | 'down' | 'left' | 'right', extendSelection?: boolean): void;
256
+ insertColumn(index: number, config?: Partial<SpreadsheetColumn>): void;
257
+ deleteColumn(colId: string): void;
258
+ insertRow(index: number, config?: Partial<SpreadsheetRow>): void;
259
+ deleteRow(rowId: string): void;
260
+ setColumnWidth(colId: string, width: number): void;
261
+ exportToTsv(): string;
262
+ importFromTsv(tsvData: string, startRow?: number, startCol?: number): void;
263
+ private recordSnapshot;
264
+ undo(): void;
265
+ redo(): void;
266
+ private notifyChange;
267
+ }
268
+
269
+ export { type ASTNode, type BinaryOpNode, type CellCoordinate, type CellData, type CellDep, type CellFormat, type CellRange, type CellRefNode, type ColumnBinding, type ColumnType, DataSourceBinder, DependencyGraph, type EvaluationContext, FormulaEvaluator, FormulaParser, type FormulaToken, type FormulaTokenType, type FunctionCallNode, type LiteralNode, type PropertyRefNode, type RangeNode, type RowType, type SpreadsheetColumn, SpreadsheetController, type SpreadsheetControllerOptions, type SpreadsheetDataSource, type SpreadsheetDataSourceField, type SpreadsheetDocument, type SpreadsheetRow, type UnaryOpNode, colNameToIndex, extractCellDependencies, indexToColName, parseCellReference, parseFormula, parseRange, tokenizeFormula };