y11n-spreadsheet 1.0.1 → 1.0.2
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/README.md +2 -2
- package/dist/components/y11n-format-toolbar.d.ts +17 -4
- package/dist/components/y11n-format-toolbar.d.ts.map +1 -1
- package/dist/components/y11n-formula-bar.d.ts +10 -3
- package/dist/components/y11n-formula-bar.d.ts.map +1 -1
- package/dist/controllers/clipboard-manager.d.ts +42 -11
- package/dist/controllers/clipboard-manager.d.ts.map +1 -1
- package/dist/controllers/selection-manager.d.ts +35 -6
- package/dist/controllers/selection-manager.d.ts.map +1 -1
- package/dist/engine/formula-engine.d.ts +73 -10
- package/dist/engine/formula-engine.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2407 -2189
- package/dist/types.d.ts +103 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/y11n-spreadsheet.d.ts +99 -13
- package/dist/y11n-spreadsheet.d.ts.map +1 -1
- package/package.json +13 -14
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ An accessible spreadsheet web component built with [Lit 3.0](https://lit.dev). I
|
|
|
6
6
|
|
|
7
7
|
- Full keyboard navigation (arrows, Tab, Enter, Escape, Ctrl+A)
|
|
8
8
|
- Copy/cut/paste with TSV clipboard format
|
|
9
|
-
- Undo/redo with Ctrl+Z / Ctrl+Shift+Z
|
|
9
|
+
- Undo/redo with Ctrl+Z / Ctrl+Shift+Z (or Ctrl+Y)
|
|
10
10
|
- Formula engine with 20+ built-in functions and custom function support
|
|
11
11
|
- Arrow key cell reference insertion during formula editing
|
|
12
12
|
- Virtual rendering for large datasets (1000+ rows)
|
|
@@ -187,7 +187,7 @@ y11n-spreadsheet::part(editor) {
|
|
|
187
187
|
| Ctrl+A | Select all |
|
|
188
188
|
| Ctrl+C / X / V | Copy / Cut / Paste |
|
|
189
189
|
| Ctrl+Z | Undo |
|
|
190
|
-
| Ctrl+Shift+Z | Redo |
|
|
190
|
+
| Ctrl+Shift+Z / Ctrl+Y | Redo |
|
|
191
191
|
| Any printable character | Start editing with that character |
|
|
192
192
|
|
|
193
193
|
During formula editing, arrow keys insert cell references instead of navigating.
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
+
/** Detail for the `format-action` custom event dispatched by the format toolbar. */
|
|
2
3
|
export interface FormatActionDetail {
|
|
4
|
+
/** The formatting action to perform */
|
|
3
5
|
action: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'textColor' | 'backgroundColor' | 'textAlign' | 'fontSize' | 'clearFormat';
|
|
6
|
+
/** The new value for the action (e.g. true/false for toggles, color string, font size number) */
|
|
4
7
|
value?: string | number | boolean;
|
|
5
8
|
}
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
10
|
+
* `<y11n-format-toolbar>` -- A companion toolbar for cell formatting.
|
|
8
11
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
12
|
+
* This component does not manage state internally. The consumer wires it
|
|
13
|
+
* to `<y11n-spreadsheet>` by binding selection-derived properties and
|
|
14
|
+
* handling the `format-action` event:
|
|
11
15
|
*
|
|
12
16
|
* ```html
|
|
13
17
|
* <y11n-format-toolbar
|
|
@@ -15,6 +19,8 @@ export interface FormatActionDetail {
|
|
|
15
19
|
* @format-action=${handle}
|
|
16
20
|
* ></y11n-format-toolbar>
|
|
17
21
|
* ```
|
|
22
|
+
*
|
|
23
|
+
* @fires format-action - Dispatched when the user clicks a formatting button or changes a value
|
|
18
24
|
*/
|
|
19
25
|
export declare class Y11nFormatToolbar extends LitElement {
|
|
20
26
|
bold: boolean;
|
|
@@ -31,7 +37,14 @@ export declare class Y11nFormatToolbar extends LitElement {
|
|
|
31
37
|
private _handleToolbarKeydown;
|
|
32
38
|
render(): import("lit-html").TemplateResult<1>;
|
|
33
39
|
}
|
|
34
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Compute the consensus format from all cells in a selection range.
|
|
42
|
+
* For each property, returns the common value if all cells agree, or undefined if mixed.
|
|
43
|
+
*
|
|
44
|
+
* @param getData - Callback to retrieve cell data by key
|
|
45
|
+
* @param range - The selection range to inspect
|
|
46
|
+
* @returns A CellFormat with only the unanimously shared properties set
|
|
47
|
+
*/
|
|
35
48
|
export declare function computeSelectionFormat(getData: (cellId: string) => {
|
|
36
49
|
format?: import('../types.js').CellFormat;
|
|
37
50
|
} | undefined, range: import('../types.js').SelectionRange): import('../types.js').CellFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"y11n-format-toolbar.d.ts","sourceRoot":"","sources":["../../src/components/y11n-format-toolbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EACF,MAAM,GACN,QAAQ,GACR,WAAW,GACX,eAAe,GACf,WAAW,GACX,iBAAiB,GACjB,WAAW,GACX,UAAU,GACV,aAAa,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACnC;AAED
|
|
1
|
+
{"version":3,"file":"y11n-format-toolbar.d.ts","sourceRoot":"","sources":["../../src/components/y11n-format-toolbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,MAAM,EACF,MAAM,GACN,QAAQ,GACR,WAAW,GACX,eAAe,GACf,WAAW,GACX,iBAAiB,GACjB,WAAW,GACX,UAAU,GACV,aAAa,CAAC;IAClB,iGAAiG;IACjG,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACnC;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBACa,iBAAkB,SAAQ,UAAU;IAGlB,IAAI,UAAS;IACb,MAAM,UAAS;IACf,SAAS,UAAS;IAClB,aAAa,UAAS;IACvB,SAAS,SAAa;IACtB,eAAe,SAAa;IAC5B,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAU;IAChD,QAAQ,SAAM;IAC0B,QAAQ,UAAS;IAIrF,MAAM,CAAC,MAAM,0BAiKX;IAIF,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,qBAAqB;IAgC7B,MAAM,yCAsJL;CACF;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK;IAAE,MAAM,CAAC,EAAE,OAAO,aAAa,EAAE,UAAU,CAAA;CAAE,GAAG,SAAS,EACtF,KAAK,EAAE,OAAO,aAAa,EAAE,cAAc,GAC1C,OAAO,aAAa,EAAE,UAAU,CAkDlC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,qBAAqB,EAAE,iBAAiB,CAAC;KAC1C;CACF"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
+
/** Display mode for the formula bar input. */
|
|
2
3
|
export type FormulaBarMode = 'raw' | 'formatted';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* `<y11n-formula-bar>` -- Reusable formula bar sub-component.
|
|
6
|
+
*
|
|
7
|
+
* Displays the active cell reference and an input for editing cell values.
|
|
8
|
+
* Supports toggling between raw (formula) and formatted (display) modes.
|
|
9
|
+
* All data persistence is handled by the parent component; this component
|
|
10
|
+
* communicates via two custom events:
|
|
11
|
+
*
|
|
12
|
+
* @fires formula-bar-commit - Fired on Enter or blur when the draft differs from the source value
|
|
13
|
+
* @fires formula-bar-mode-change - Fired when the user toggles between raw and formatted mode
|
|
6
14
|
*/
|
|
7
15
|
export declare class Y11nFormulaBar extends LitElement {
|
|
8
16
|
cellRef: string;
|
|
@@ -11,7 +19,6 @@ export declare class Y11nFormulaBar extends LitElement {
|
|
|
11
19
|
mode: FormulaBarMode;
|
|
12
20
|
readOnly: boolean;
|
|
13
21
|
private _draft;
|
|
14
|
-
private _suppressNextBlur;
|
|
15
22
|
static styles: import("lit").CSSResult;
|
|
16
23
|
willUpdate(changedProps: Map<string, unknown>): void;
|
|
17
24
|
private _sourceValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"y11n-formula-bar.d.ts","sourceRoot":"","sources":["../../src/components/y11n-formula-bar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"y11n-formula-bar.d.ts","sourceRoot":"","sources":["../../src/components/y11n-formula-bar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,8CAA8C;AAC9C,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,WAAW,CAAC;AAgBjD;;;;;;;;;;GAUG;AACH,qBACa,cAAe,SAAQ,UAAU;IACO,OAAO,SAAQ;IACd,QAAQ,SAAM;IACV,YAAY,SAAM;IAC9C,IAAI,EAAE,cAAc,CAAS;IACW,QAAQ,UAAS;IAE5E,OAAO,CAAC,MAAM,CAAM;IAE7B,MAAM,CAAC,MAAM,0BAuEX;IAEF,UAAU,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAQnD;IAED,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,QAAQ;IAWhB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,OAAO;IAMf,MAAM,yCA6BL;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,kBAAkB,EAAE,cAAc,CAAC;KACpC;CACF"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type CellFormat, type GridData, type SelectionRange } from '../types.js';
|
|
2
|
+
/** A single cell update produced by a paste operation. */
|
|
2
3
|
export interface PasteUpdate {
|
|
4
|
+
/** Cell key in `"row:col"` format */
|
|
3
5
|
id: string;
|
|
6
|
+
/** Raw value to write to the cell */
|
|
4
7
|
value: string;
|
|
8
|
+
/** Optional format to apply (from HTML or internal paste) */
|
|
5
9
|
format?: CellFormat;
|
|
6
10
|
}
|
|
7
11
|
/**
|
|
@@ -12,20 +16,35 @@ export declare class ClipboardManager {
|
|
|
12
16
|
/** Source range and data from the last internal copy/cut, used for reference adjustment on paste */
|
|
13
17
|
private _copySourceRange;
|
|
14
18
|
private _copySourceData;
|
|
19
|
+
/** The TSV text we last wrote to the clipboard, used to detect external overwrites */
|
|
20
|
+
private _lastWrittenText;
|
|
15
21
|
/**
|
|
16
|
-
* Copy the selected range to the clipboard
|
|
17
|
-
*
|
|
22
|
+
* Copy the selected range to the system clipboard.
|
|
23
|
+
* Writes two formats: `text/html` (table with inline styles and data-format attributes)
|
|
24
|
+
* and `text/plain` (TSV). Falls back to text-only if ClipboardItem API is unavailable.
|
|
25
|
+
*
|
|
26
|
+
* @param data - The grid data to read cell values from
|
|
27
|
+
* @param range - The rectangular range to copy
|
|
18
28
|
*/
|
|
19
29
|
copy(data: GridData, range: SelectionRange): Promise<void>;
|
|
20
30
|
/**
|
|
21
|
-
* Cut: copy to clipboard and return the keys that should be cleared.
|
|
31
|
+
* Cut: copy to clipboard and return the cell keys that should be cleared by the caller.
|
|
32
|
+
*
|
|
33
|
+
* @param data - The grid data to read cell values from
|
|
34
|
+
* @param range - The rectangular range to cut
|
|
35
|
+
* @returns Array of cell keys (in `"row:col"` format) that were included in the cut
|
|
22
36
|
*/
|
|
23
37
|
cut(data: GridData, range: SelectionRange): Promise<string[]>;
|
|
24
38
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
39
|
+
* Read from the system clipboard and return cell updates for pasting.
|
|
40
|
+
* Priority chain: internal copy data (with formula reference adjustment)
|
|
41
|
+
* -> HTML table -> plain text TSV.
|
|
42
|
+
*
|
|
43
|
+
* @param targetRow - 0-indexed row of the top-left paste destination
|
|
44
|
+
* @param targetCol - 0-indexed column of the top-left paste destination
|
|
45
|
+
* @param maxRows - Grid row count (for bounds clamping)
|
|
46
|
+
* @param maxCols - Grid column count (for bounds clamping)
|
|
47
|
+
* @returns Array of cell updates to apply, or null if clipboard is empty/inaccessible
|
|
29
48
|
*/
|
|
30
49
|
paste(targetRow: number, targetCol: number, maxRows: number, maxCols: number): Promise<PasteUpdate[] | null>;
|
|
31
50
|
/**
|
|
@@ -49,9 +68,14 @@ export declare class ClipboardManager {
|
|
|
49
68
|
* Parse a TSV string and generate cell updates.
|
|
50
69
|
* Handles RFC 4180-style quoting: fields containing tabs, newlines, or
|
|
51
70
|
* double-quotes are wrapped in double-quotes, with internal quotes escaped
|
|
52
|
-
* as ""
|
|
71
|
+
* as `""`. This is the format Excel and Google Sheets use on the clipboard.
|
|
53
72
|
*
|
|
54
|
-
*
|
|
73
|
+
* @param text - The TSV text to parse
|
|
74
|
+
* @param targetRow - 0-indexed row of the top-left paste destination
|
|
75
|
+
* @param targetCol - 0-indexed column of the top-left paste destination
|
|
76
|
+
* @param maxRows - Grid row count (for bounds clamping)
|
|
77
|
+
* @param maxCols - Grid column count (for bounds clamping)
|
|
78
|
+
* @returns Array of cell updates with keys and values
|
|
55
79
|
*/
|
|
56
80
|
parseTSV(text: string, targetRow: number, targetCol: number, maxRows: number, maxCols: number): Array<{
|
|
57
81
|
id: string;
|
|
@@ -64,8 +88,14 @@ export declare class ClipboardManager {
|
|
|
64
88
|
private _parseTSVRows;
|
|
65
89
|
/**
|
|
66
90
|
* Adjust cell references in a formula by the given row/col offset.
|
|
67
|
-
* Absolute references (
|
|
68
|
-
* Mixed references (
|
|
91
|
+
* Absolute references (`$A$1`) are not adjusted.
|
|
92
|
+
* Mixed references (`$A1`, `A$1`) only adjust the non-absolute component.
|
|
93
|
+
* References inside string literals are left untouched.
|
|
94
|
+
*
|
|
95
|
+
* @param formula - The formula string (must start with "=")
|
|
96
|
+
* @param rowOffset - Number of rows to shift relative references
|
|
97
|
+
* @param colOffset - Number of columns to shift relative references
|
|
98
|
+
* @returns The adjusted formula string, with `#REF!` for out-of-bounds refs
|
|
69
99
|
*/
|
|
70
100
|
adjustFormulaReferences(formula: string, rowOffset: number, colOffset: number): string;
|
|
71
101
|
private serializeRange;
|
|
@@ -82,6 +112,7 @@ export declare class ClipboardManager {
|
|
|
82
112
|
private _parseStyleToFormat;
|
|
83
113
|
/** Validate and sanitize a parsed CellFormat from an external source */
|
|
84
114
|
private _sanitizeFormat;
|
|
115
|
+
private _sanitizeNumberFormat;
|
|
85
116
|
private _extractStyleProp;
|
|
86
117
|
/** Escape special HTML characters */
|
|
87
118
|
private _escapeHTML;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard-manager.d.ts","sourceRoot":"","sources":["../../src/controllers/clipboard-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"clipboard-manager.d.ts","sourceRoot":"","sources":["../../src/controllers/clipboard-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,EAEb,KAAK,cAAc,EAIpB,MAAM,aAAa,CAAC;AAErB,0DAA0D;AAC1D,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,oGAAoG;IACpG,OAAO,CAAC,gBAAgB,CAA+B;IACvD,OAAO,CAAC,eAAe,CAAyB;IAChD,sFAAsF;IACtF,OAAO,CAAC,gBAAgB,CAAu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,OAAO,CAAC,oBAAoB;IAe5B,2FAA2F;IAC3F,OAAO,CAAC,mBAAmB;IAsC3B,wEAAwE;IACxE,OAAO,CAAC,eAAe;IA+BvB,OAAO,CAAC,qBAAqB;IAkB7B,OAAO,CAAC,iBAAiB;IAQzB,qCAAqC;IACrC,OAAO,CAAC,WAAW;IAUnB,wIAAwI;IACxI,OAAO,CAAC,YAAY;CAerB"}
|
|
@@ -32,21 +32,50 @@ export declare class SelectionManager implements ReactiveController {
|
|
|
32
32
|
isCellSelected(row: number, col: number): boolean;
|
|
33
33
|
/** Check if a cell is the active cell (head) */
|
|
34
34
|
isCellActive(row: number, col: number): boolean;
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Begin a new selection (mousedown/pointerdown on a cell).
|
|
37
|
+
*
|
|
38
|
+
* @param row - Row index of the clicked cell
|
|
39
|
+
* @param col - Column index of the clicked cell
|
|
40
|
+
* @param extend - If true (Shift+click), keeps the anchor and moves the head
|
|
41
|
+
*/
|
|
36
42
|
startSelection(row: number, col: number, extend?: boolean): void;
|
|
37
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Extend the selection during a drag (mousemove while dragging).
|
|
45
|
+
*
|
|
46
|
+
* @param row - Row index the mouse is over
|
|
47
|
+
* @param col - Column index the mouse is over
|
|
48
|
+
*/
|
|
38
49
|
extendSelection(row: number, col: number): void;
|
|
39
|
-
/**
|
|
50
|
+
/** Finalize the drag selection (mouseup). Clears the dragging flag. */
|
|
40
51
|
endSelection(): void;
|
|
41
52
|
get isDragging(): boolean;
|
|
42
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Move the active cell by a delta offset.
|
|
55
|
+
*
|
|
56
|
+
* @param dRow - Row delta (-1 = up, +1 = down)
|
|
57
|
+
* @param dCol - Column delta (-1 = left, +1 = right)
|
|
58
|
+
* @param extend - If true, keeps the anchor and extends the selection (Shift+arrow)
|
|
59
|
+
*/
|
|
43
60
|
move(dRow: number, dCol: number, extend?: boolean): void;
|
|
44
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Move to a specific cell by absolute position.
|
|
63
|
+
*
|
|
64
|
+
* @param row - Target row index
|
|
65
|
+
* @param col - Target column index
|
|
66
|
+
* @param extend - If true, keeps the anchor and extends the selection
|
|
67
|
+
*/
|
|
45
68
|
moveTo(row: number, col: number, extend?: boolean): void;
|
|
46
69
|
/** Select all cells */
|
|
47
70
|
selectAll(): void;
|
|
48
71
|
/** Clear selection (collapse to active cell) */
|
|
49
72
|
clearSelection(): void;
|
|
50
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Clamp a coordinate to the valid grid bounds.
|
|
75
|
+
*
|
|
76
|
+
* @param coord - The coordinate to clamp
|
|
77
|
+
* @returns A new coordinate within `[0, maxRows-1]` x `[0, maxCols-1]`
|
|
78
|
+
*/
|
|
79
|
+
clamp(coord: CellCoord): CellCoord;
|
|
51
80
|
}
|
|
52
81
|
//# sourceMappingURL=selection-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection-manager.d.ts","sourceRoot":"","sources":["../../src/controllers/selection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAC3E,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAElE;;;;;;;GAOG;AACH,qBAAa,gBAAiB,YAAW,kBAAkB;IACzD,IAAI,EAAE,sBAAsB,CAAC;IAE7B,iDAAiD;IACjD,MAAM,EAAE,SAAS,CAAsB;IAEvC,uCAAuC;IACvC,IAAI,EAAE,SAAS,CAAsB;IAErC,8CAA8C;IAC9C,OAAO,CAAC,WAAW,CAAS;IAE5B,kBAAkB;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;
|
|
1
|
+
{"version":3,"file":"selection-manager.d.ts","sourceRoot":"","sources":["../../src/controllers/selection-man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,YAAY,IAAI,IAAI,CAEnB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAID;;;;;;OAMG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,IAAI,CAWrD;IAED;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,IAAI,CAOrD;IAED,uBAAuB;IACvB,SAAS,IAAI,IAAI,CAIhB;IAED,gDAAgD;IAChD,cAAc,IAAI,IAAI,CAGrB;IAID;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAKjC;CACF"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type GridData, type FormulaFunction } from '../types.js';
|
|
2
|
+
type EvalResult = {
|
|
3
|
+
displayValue: string;
|
|
4
|
+
type: 'text' | 'number' | 'boolean' | 'error';
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Represents a 2D range of values with shape information.
|
|
4
8
|
* Used by lookup functions (VLOOKUP, INDEX, etc.) that need row/col structure.
|
|
@@ -14,6 +18,7 @@ export declare class RangeValue {
|
|
|
14
18
|
}
|
|
15
19
|
export declare class FormulaEngine {
|
|
16
20
|
private _functions;
|
|
21
|
+
private _builtinFunctionNames;
|
|
17
22
|
private _data;
|
|
18
23
|
private _evaluating;
|
|
19
24
|
private _evalDepth;
|
|
@@ -21,9 +26,29 @@ export declare class FormulaEngine {
|
|
|
21
26
|
private _reverseDeps;
|
|
22
27
|
private _trackingCellKey;
|
|
23
28
|
private _cache;
|
|
29
|
+
/**
|
|
30
|
+
* Values of referenced formula cells computed during the current
|
|
31
|
+
* evaluation pass (one top-level `evaluate()`, or a whole `recalculate()` /
|
|
32
|
+
* `recalculateAffected()`). Avoids re-evaluating shared precedents, which is
|
|
33
|
+
* otherwise exponential, and lets deep chains be resolved incrementally.
|
|
34
|
+
* Null outside a pass, so standalone `evaluate()` calls always see fresh data.
|
|
35
|
+
*/
|
|
36
|
+
private _memo;
|
|
24
37
|
constructor();
|
|
25
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Register a user-defined formula function.
|
|
40
|
+
* The name is normalized to uppercase for case-insensitive lookup.
|
|
41
|
+
*
|
|
42
|
+
* @param name - Function name (e.g. "MYFUNC"); stored as uppercase
|
|
43
|
+
* @param fn - The function implementation
|
|
44
|
+
*/
|
|
26
45
|
registerFunction(name: string, fn: FormulaFunction): void;
|
|
46
|
+
/**
|
|
47
|
+
* Replace the entire set of user-defined functions while keeping built-ins.
|
|
48
|
+
*
|
|
49
|
+
* @param functions - New custom functions keyed by name
|
|
50
|
+
*/
|
|
51
|
+
setFunctions(functions: Record<string, FormulaFunction>): void;
|
|
27
52
|
/** Update the data reference for evaluation (full reset of dep graph and cache) */
|
|
28
53
|
setData(data: GridData): void;
|
|
29
54
|
/**
|
|
@@ -33,23 +58,42 @@ export declare class FormulaEngine {
|
|
|
33
58
|
*/
|
|
34
59
|
updateData(data: GridData, changedKeys: string[]): void;
|
|
35
60
|
/**
|
|
36
|
-
* Evaluate a raw value. If it starts with
|
|
37
|
-
* Otherwise, return the value as-is (possibly coerced).
|
|
61
|
+
* Evaluate a raw value. If it starts with `=`, parse and execute the formula.
|
|
62
|
+
* Otherwise, return the value as-is (possibly coerced to number/boolean).
|
|
38
63
|
*
|
|
39
|
-
* @param
|
|
64
|
+
* @param rawValue - The raw cell value (formula or literal)
|
|
65
|
+
* @param forCellKey - If provided, registers dependencies for this cell key
|
|
66
|
+
* (side-effect: updates the forward/reverse dep graph and result cache)
|
|
67
|
+
* @returns The display value and resolved type
|
|
68
|
+
*/
|
|
69
|
+
evaluate(rawValue: string, forCellKey?: string): EvalResult;
|
|
70
|
+
private _evaluateDeferred;
|
|
71
|
+
/** Run `fn` inside an evaluation pass, creating the pass memo if needed. */
|
|
72
|
+
private _withMemo;
|
|
73
|
+
/**
|
|
74
|
+
* Evaluate a raw value as the top-level formula of `forCellKey`.
|
|
75
|
+
* Throws only EvalDepthError; every other failure becomes an error result.
|
|
40
76
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
77
|
+
private _evaluateTopLevel;
|
|
78
|
+
/**
|
|
79
|
+
* Convert a formula result to its display string and type based on the
|
|
80
|
+
* JS type of the result, so text results like "007" or TEXT() output stay text.
|
|
81
|
+
*/
|
|
82
|
+
private _resultToDisplay;
|
|
45
83
|
/**
|
|
46
84
|
* Re-evaluate all formula cells in the grid.
|
|
47
|
-
*
|
|
85
|
+
* Clears and rebuilds the entire dependency graph and result cache.
|
|
86
|
+
*
|
|
87
|
+
* @returns Set of cell keys whose display value or type changed
|
|
48
88
|
*/
|
|
49
89
|
recalculate(): Set<string>;
|
|
50
90
|
/**
|
|
51
91
|
* Recalculate only formulas affected by the given changed cell keys.
|
|
52
|
-
* Uses the dependency graph for targeted recalculation
|
|
92
|
+
* Uses BFS traversal of the reverse dependency graph for targeted recalculation.
|
|
93
|
+
* Falls back to full `recalculate()` if the dep graph is empty.
|
|
94
|
+
*
|
|
95
|
+
* @param changedKeys - Cell keys whose raw values changed
|
|
96
|
+
* @returns Set of cell keys whose display value or type changed
|
|
53
97
|
*/
|
|
54
98
|
recalculateAffected(changedKeys: string[]): Set<string>;
|
|
55
99
|
private _clearDepsFor;
|
|
@@ -66,10 +110,29 @@ export declare class FormulaEngine {
|
|
|
66
110
|
private _parseUnary;
|
|
67
111
|
private _parsePrimary;
|
|
68
112
|
private _parseFunction;
|
|
113
|
+
/**
|
|
114
|
+
* Parse IFERROR(value, fallback) with error trapping on the first argument.
|
|
115
|
+
* Called after LPAREN has already been consumed.
|
|
116
|
+
*/
|
|
117
|
+
private _parseIFERROR;
|
|
118
|
+
/**
|
|
119
|
+
* Parse IF(condition, then, else), evaluating only the selected branch.
|
|
120
|
+
* Called after LPAREN has already been consumed.
|
|
121
|
+
*/
|
|
122
|
+
private _parseIF;
|
|
123
|
+
/** Advance past one function argument without evaluating it. */
|
|
124
|
+
private _skipArgument;
|
|
69
125
|
private _compareValues;
|
|
70
126
|
private _resolveRef;
|
|
127
|
+
/**
|
|
128
|
+
* Evaluate a referenced formula cell, reusing its value if it was already
|
|
129
|
+
* computed in this evaluation pass. Keeps `_trackingCellKey` so transitive
|
|
130
|
+
* dependencies are recorded (e.g. C1→B1→A1 means C1 depends on A1 too).
|
|
131
|
+
*/
|
|
132
|
+
private _evaluateFormulaCell;
|
|
71
133
|
private _resolveRange;
|
|
72
134
|
private _createContext;
|
|
73
135
|
private registerBuiltins;
|
|
74
136
|
}
|
|
137
|
+
export {};
|
|
75
138
|
//# sourceMappingURL=formula-engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formula-engine.d.ts","sourceRoot":"","sources":["../../src/engine/formula-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,eAAe,EAGrB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"formula-engine.d.ts","sourceRoot":"","sources":["../../src/engine/formula-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,eAAe,EAGrB,MAAM,aAAa,CAAC;AAgJrB,KAAK,UAAU,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAA;CAAE,CAAC;AAE1F;;;GAGG;AACH,qBAAa,UAAU;IACrB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAIxD;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,G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;;OAOG;IACH,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CA4CtD;IAID,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,SAAS;IAoBjB,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,QAAQ;IA4KhB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,YAAY;IAqBpB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,aAAa;IAsCrB,OAAO,CAAC,cAAc;IA2DtB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAmCrB;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAqBhB,gEAAgE;IAChE,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,cAAc;IA+CtB,OAAO,CAAC,WAAW;IA0BnB;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IA+B5B,OAAO,CAAC,aAAa;IAyDrB,OAAO,CAAC,cAAc;IAuCtB,OAAO,CAAC,gBAAgB;CA8czB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export { FormulaEngine, RangeValue } from './engine/formula-engine.js';
|
|
|
6
6
|
export { SelectionManager } from './controllers/selection-manager.js';
|
|
7
7
|
export { ClipboardManager } from './controllers/clipboard-manager.js';
|
|
8
8
|
export type { PasteUpdate } from './controllers/clipboard-manager.js';
|
|
9
|
-
export type { CellCoord, CellData, CellFormat, GridData, SelectionRange, FormulaContext, FormulaFunction, CellChangeDetail, SelectionChangeDetail, DataChangeDetail, FormatChangeDetail, } from './types.js';
|
|
10
|
-
export { cellKey, parseKey, colToLetter, letterToCol, refToCoord, coordToRef, formatsEqual } from './types.js';
|
|
9
|
+
export type { CellCoord, CellData, CellFormat, GridData, SelectionRange, FormulaContext, FormulaFunction, CellChangeDetail, SelectionChangeDetail, DataChangeDetail, FormatChangeDetail, NumberFormatType, NumberFormatOptions, } from './types.js';
|
|
10
|
+
export { cellKey, parseKey, colToLetter, letterToCol, refToCoord, coordToRef, formatsEqual, formatNumber } from './types.js';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAChG,YAAY,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,YAAY,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACtE,YAAY,EACV,SAAS,EACT,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAChG,YAAY,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE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