@dou-ui/sheet 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/cell-types.js +20 -0
- package/dist/cell-types.js.map +1 -0
- package/dist/code/code-formula-bar.js +6 -0
- package/dist/code/code-formula-bar.js.map +1 -0
- package/dist/code/code-formula-bar.vue_vue_type_script_setup_true_lang.js +192 -0
- package/dist/code/code-formula-bar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code/index.js +12 -0
- package/dist/code/index.js.map +1 -0
- package/dist/code/language.js +51 -0
- package/dist/code/language.js.map +1 -0
- package/dist/code/style.d.ts +1 -0
- package/dist/code/style.js +2 -0
- package/dist/collaboration/anchor.js +143 -0
- package/dist/collaboration/anchor.js.map +1 -0
- package/dist/collaboration/index.js +770 -0
- package/dist/collaboration/index.js.map +1 -0
- package/dist/collaboration/peers.js +87 -0
- package/dist/collaboration/peers.js.map +1 -0
- package/dist/collaboration/shared.js +450 -0
- package/dist/collaboration/shared.js.map +1 -0
- package/dist/components/cell-panel.js +6 -0
- package/dist/components/cell-panel.js.map +1 -0
- package/dist/components/cell-panel.vue_vue_type_script_setup_true_lang.js +70 -0
- package/dist/components/cell-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/cell-renders.js +40 -0
- package/dist/components/cell-renders.js.map +1 -0
- package/dist/components/date-panel.js +6 -0
- package/dist/components/date-panel.js.map +1 -0
- package/dist/components/date-panel.vue_vue_type_script_setup_true_lang.js +48 -0
- package/dist/components/date-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/filter-panel.js +6 -0
- package/dist/components/filter-panel.js.map +1 -0
- package/dist/components/filter-panel.vue_vue_type_script_setup_true_lang.js +259 -0
- package/dist/components/filter-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/format-dialog.js +6 -0
- package/dist/components/format-dialog.js.map +1 -0
- package/dist/components/format-dialog.vue_vue_type_script_setup_true_lang.js +432 -0
- package/dist/components/format-dialog.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/format-list.js +6 -0
- package/dist/components/format-list.js.map +1 -0
- package/dist/components/format-list.vue_vue_type_script_setup_true_lang.js +187 -0
- package/dist/components/format-list.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/format-presets.js +97 -0
- package/dist/components/format-presets.js.map +1 -0
- package/dist/components/option-panel.js +6 -0
- package/dist/components/option-panel.js.map +1 -0
- package/dist/components/option-panel.vue_vue_type_script_setup_true_lang.js +117 -0
- package/dist/components/option-panel.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-comment.js +6 -0
- package/dist/components/sheet-comment.js.map +1 -0
- package/dist/components/sheet-comment.vue_vue_type_script_setup_true_lang.js +104 -0
- package/dist/components/sheet-comment.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-formula-bar.js +6 -0
- package/dist/components/sheet-formula-bar.js.map +1 -0
- package/dist/components/sheet-formula-bar.vue_vue_type_script_setup_true_lang.js +124 -0
- package/dist/components/sheet-formula-bar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-link.js +6 -0
- package/dist/components/sheet-link.js.map +1 -0
- package/dist/components/sheet-link.vue_vue_type_script_setup_true_lang.js +249 -0
- package/dist/components/sheet-link.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-menu.js +6 -0
- package/dist/components/sheet-menu.js.map +1 -0
- package/dist/components/sheet-menu.vue_vue_type_script_setup_true_lang.js +115 -0
- package/dist/components/sheet-menu.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-name-box.js +6 -0
- package/dist/components/sheet-name-box.js.map +1 -0
- package/dist/components/sheet-name-box.vue_vue_type_script_setup_true_lang.js +91 -0
- package/dist/components/sheet-name-box.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-note.js +6 -0
- package/dist/components/sheet-note.js.map +1 -0
- package/dist/components/sheet-note.vue_vue_type_script_setup_true_lang.js +146 -0
- package/dist/components/sheet-note.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-outline.js +6 -0
- package/dist/components/sheet-outline.js.map +1 -0
- package/dist/components/sheet-outline.vue_vue_type_script_setup_true_lang.js +237 -0
- package/dist/components/sheet-outline.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-tabs.js +6 -0
- package/dist/components/sheet-tabs.js.map +1 -0
- package/dist/components/sheet-tabs.vue_vue_type_script_setup_true_lang.js +487 -0
- package/dist/components/sheet-tabs.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/sheet-toolbar.js +6 -0
- package/dist/components/sheet-toolbar.js.map +1 -0
- package/dist/components/sheet-toolbar.vue_vue_type_script_setup_true_lang.js +1562 -0
- package/dist/components/sheet-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/validation-dialog.js +6 -0
- package/dist/components/validation-dialog.js.map +1 -0
- package/dist/components/validation-dialog.vue_vue_type_script_setup_true_lang.js +370 -0
- package/dist/components/validation-dialog.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/context.js +12 -0
- package/dist/context.js.map +1 -0
- package/dist/core/address.js +256 -0
- package/dist/core/address.js.map +1 -0
- package/dist/core/axis.js +72 -0
- package/dist/core/axis.js.map +1 -0
- package/dist/core/cell-type.js +30 -0
- package/dist/core/cell-type.js.map +1 -0
- package/dist/core/clipboard.js +141 -0
- package/dist/core/clipboard.js.map +1 -0
- package/dist/core/commands.js +63 -0
- package/dist/core/commands.js.map +1 -0
- package/dist/core/comments.js +74 -0
- package/dist/core/comments.js.map +1 -0
- package/dist/core/conditional.js +362 -0
- package/dist/core/conditional.js.map +1 -0
- package/dist/core/csv.js +191 -0
- package/dist/core/csv.js.map +1 -0
- package/dist/core/data.js +118 -0
- package/dist/core/data.js.map +1 -0
- package/dist/core/document.js +187 -0
- package/dist/core/document.js.map +1 -0
- package/dist/core/extension.js +60 -0
- package/dist/core/extension.js.map +1 -0
- package/dist/core/file.js +336 -0
- package/dist/core/file.js.map +1 -0
- package/dist/core/fill.js +153 -0
- package/dist/core/fill.js.map +1 -0
- package/dist/core/find.js +42 -0
- package/dist/core/find.js.map +1 -0
- package/dist/core/format.js +404 -0
- package/dist/core/format.js.map +1 -0
- package/dist/core/group.js +134 -0
- package/dist/core/group.js.map +1 -0
- package/dist/core/history.js +68 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/index.js +17 -0
- package/dist/core/link.js +34 -0
- package/dist/core/link.js.map +1 -0
- package/dist/core/merge.js +105 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/model.js +48 -0
- package/dist/core/model.js.map +1 -0
- package/dist/core/nav.js +44 -0
- package/dist/core/nav.js.map +1 -0
- package/dist/core/paint.js +106 -0
- package/dist/core/paint.js.map +1 -0
- package/dist/core/plain-cell-types.js +54 -0
- package/dist/core/plain-cell-types.js.map +1 -0
- package/dist/core/protect.js +246 -0
- package/dist/core/protect.js.map +1 -0
- package/dist/core/selection.js +37 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/transaction.js +1582 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/core/validation.js +135 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/core/versions.js +161 -0
- package/dist/core/versions.js.map +1 -0
- package/dist/export/color.js +36 -0
- package/dist/export/color.js.map +1 -0
- package/dist/export/draw.js +316 -0
- package/dist/export/draw.js.map +1 -0
- package/dist/export/index.js +390 -0
- package/dist/export/index.js.map +1 -0
- package/dist/formula/edit.js +210 -0
- package/dist/formula/edit.js.map +1 -0
- package/dist/formula/engine.js +526 -0
- package/dist/formula/engine.js.map +1 -0
- package/dist/formula/error.js +39 -0
- package/dist/formula/error.js.map +1 -0
- package/dist/formula/functions.js +1493 -0
- package/dist/formula/functions.js.map +1 -0
- package/dist/formula/help.js +408 -0
- package/dist/formula/help.js.map +1 -0
- package/dist/formula/index.js +7 -0
- package/dist/formula/parse.js +369 -0
- package/dist/formula/parse.js.map +1 -0
- package/dist/formula/values.js +123 -0
- package/dist/formula/values.js.map +1 -0
- package/dist/formulas.js +30 -0
- package/dist/formulas.js.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/locale.js +1312 -0
- package/dist/locale.js.map +1 -0
- package/dist/sheet.js +6 -0
- package/dist/sheet.js.map +1 -0
- package/dist/sheet.vue_vue_type_script_setup_true_lang.js +7166 -0
- package/dist/sheet.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/style.d.ts +1 -0
- package/dist/style.js +17 -0
- package/dist/types/cell-types.d.ts +2 -0
- package/dist/types/code/code-formula-bar.vue.d.ts +3 -0
- package/dist/types/code/index.d.ts +12 -0
- package/dist/types/code/language.d.ts +13 -0
- package/dist/types/collaboration/anchor.d.ts +65 -0
- package/dist/types/collaboration/index.d.ts +59 -0
- package/dist/types/collaboration/peers.d.ts +21 -0
- package/dist/types/collaboration/shared.d.ts +75 -0
- package/dist/types/components/cell-panel.vue.d.ts +20 -0
- package/dist/types/components/cell-renders.d.ts +9 -0
- package/dist/types/components/date-panel.vue.d.ts +9 -0
- package/dist/types/components/filter-panel.vue.d.ts +21 -0
- package/dist/types/components/format-dialog.vue.d.ts +24 -0
- package/dist/types/components/format-list.vue.d.ts +25 -0
- package/dist/types/components/format-presets.d.ts +30 -0
- package/dist/types/components/option-panel.vue.d.ts +13 -0
- package/dist/types/components/sheet-comment.vue.d.ts +29 -0
- package/dist/types/components/sheet-formula-bar.vue.d.ts +3 -0
- package/dist/types/components/sheet-link.vue.d.ts +32 -0
- package/dist/types/components/sheet-menu.vue.d.ts +20 -0
- package/dist/types/components/sheet-name-box.vue.d.ts +3 -0
- package/dist/types/components/sheet-note.vue.d.ts +22 -0
- package/dist/types/components/sheet-outline.vue.d.ts +36 -0
- package/dist/types/components/sheet-tabs.vue.d.ts +9 -0
- package/dist/types/components/sheet-toolbar.vue.d.ts +11 -0
- package/dist/types/components/validation-dialog.vue.d.ts +25 -0
- package/dist/types/context.d.ts +189 -0
- package/dist/types/core/address.d.ts +109 -0
- package/dist/types/core/axis.d.ts +23 -0
- package/dist/types/core/cell-type.d.ts +157 -0
- package/dist/types/core/clipboard.d.ts +48 -0
- package/dist/types/core/commands.d.ts +76 -0
- package/dist/types/core/comments.d.ts +22 -0
- package/dist/types/core/conditional.d.ts +114 -0
- package/dist/types/core/csv.d.ts +93 -0
- package/dist/types/core/data.d.ts +26 -0
- package/dist/types/core/document.d.ts +49 -0
- package/dist/types/core/extension.d.ts +177 -0
- package/dist/types/core/file.d.ts +301 -0
- package/dist/types/core/fill.d.ts +23 -0
- package/dist/types/core/find.d.ts +39 -0
- package/dist/types/core/format.d.ts +47 -0
- package/dist/types/core/group.d.ts +76 -0
- package/dist/types/core/history.d.ts +27 -0
- package/dist/types/core/index.d.ts +33 -0
- package/dist/types/core/link.d.ts +14 -0
- package/dist/types/core/merge.d.ts +26 -0
- package/dist/types/core/model.d.ts +363 -0
- package/dist/types/core/nav.d.ts +15 -0
- package/dist/types/core/paint.d.ts +19 -0
- package/dist/types/core/plain-cell-types.d.ts +6 -0
- package/dist/types/core/protect.d.ts +34 -0
- package/dist/types/core/selection.d.ts +25 -0
- package/dist/types/core/transaction.d.ts +470 -0
- package/dist/types/core/validation.d.ts +55 -0
- package/dist/types/core/versions.d.ts +38 -0
- package/dist/types/export/color.d.ts +7 -0
- package/dist/types/export/draw.d.ts +98 -0
- package/dist/types/export/index.d.ts +47 -0
- package/dist/types/formula/edit.d.ts +62 -0
- package/dist/types/formula/engine.d.ts +99 -0
- package/dist/types/formula/error.d.ts +30 -0
- package/dist/types/formula/functions.d.ts +62 -0
- package/dist/types/formula/help.d.ts +12 -0
- package/dist/types/formula/index.d.ts +13 -0
- package/dist/types/formula/parse.d.ts +92 -0
- package/dist/types/formula/values.d.ts +65 -0
- package/dist/types/formulas.d.ts +32 -0
- package/dist/types/index.d.ts +225 -0
- package/dist/types/locale.d.ts +531 -0
- package/dist/types/sheet.vue.d.ts +60 -0
- package/dist/types/types.d.ts +498 -0
- package/dist/types/use-comments.d.ts +47 -0
- package/dist/types/use-messages.d.ts +7 -0
- package/dist/use-comments.js +130 -0
- package/dist/use-comments.js.map +1 -0
- package/dist/use-messages.js +29 -0
- package/dist/use-messages.js.map +1 -0
- package/package.json +93 -4
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SheetAxis } from '../core/axis';
|
|
2
|
+
import type { SheetBounds } from '../core/address';
|
|
3
|
+
import { type SheetCellType, type SheetDrawContext } from '../core/cell-type';
|
|
4
|
+
import type { SheetMerges } from '../core/merge';
|
|
5
|
+
import type { SheetData } from '../core/model';
|
|
6
|
+
import type { SheetRef } from '../core/transaction';
|
|
7
|
+
import type { SheetExportOptions, SheetImageOptions, SheetPrintOptions } from '../types';
|
|
8
|
+
import { type SheetDrawing } from './draw';
|
|
9
|
+
/** A cell as the grid draws it, which images and pages draw the same way. */
|
|
10
|
+
export interface ExportCellView {
|
|
11
|
+
text: string;
|
|
12
|
+
cls: string;
|
|
13
|
+
css: string;
|
|
14
|
+
render?: SheetCellType['render'];
|
|
15
|
+
props?: Record<string, unknown>;
|
|
16
|
+
/** A cell type's own drawing, as SVG markup. */
|
|
17
|
+
draw?: (draw: SheetDrawContext) => string;
|
|
18
|
+
label?: string;
|
|
19
|
+
hidden?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** A sheet as images and pages draw it: its data, laid out, and its cells as the grid draws them. */
|
|
22
|
+
export interface SheetExportTarget {
|
|
23
|
+
data: SheetData;
|
|
24
|
+
rows: SheetAxis;
|
|
25
|
+
cols: SheetAxis;
|
|
26
|
+
frozen: {
|
|
27
|
+
rows: number;
|
|
28
|
+
cols: number;
|
|
29
|
+
};
|
|
30
|
+
merges: SheetMerges;
|
|
31
|
+
cellView: (row: number, col: number, line: SheetData['cells'][number], width: number, span?: SheetBounds) => ExportCellView;
|
|
32
|
+
}
|
|
33
|
+
/** What of the grid images and pages are drawn from. */
|
|
34
|
+
export interface SheetExportSource {
|
|
35
|
+
root: () => HTMLElement | undefined;
|
|
36
|
+
/** The sheet shown, or the one named. */
|
|
37
|
+
target: (sheet?: SheetRef) => SheetExportTarget;
|
|
38
|
+
rowHeight: () => number;
|
|
39
|
+
gridlines: () => boolean;
|
|
40
|
+
}
|
|
41
|
+
/** `exportSVG`, `exportPNG` and `print` of a grid. */
|
|
42
|
+
export declare function createSheetExport(src: SheetExportSource): {
|
|
43
|
+
exportSVG: (options?: SheetExportOptions) => string;
|
|
44
|
+
exportPNG: (options?: SheetImageOptions) => Promise<Blob>;
|
|
45
|
+
print: (options?: SheetPrintOptions) => void;
|
|
46
|
+
drawing: (options?: SheetExportOptions) => SheetDrawing;
|
|
47
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { SheetBounds } from '../core/address';
|
|
2
|
+
/** How many colors references cycle through while a formula is edited. */
|
|
3
|
+
export declare const REF_COLORS = 7;
|
|
4
|
+
/** A reference in a formula being edited, with the color it is marked in. */
|
|
5
|
+
export interface SheetFormulaRefMark {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
text: string;
|
|
9
|
+
/** The sheet it names, as written; `undefined` for the formula's own sheet. */
|
|
10
|
+
sheet?: string;
|
|
11
|
+
bounds: SheetBounds;
|
|
12
|
+
/** From 0; the same reference written twice has the same color. */
|
|
13
|
+
color: number;
|
|
14
|
+
}
|
|
15
|
+
/** The references of a formula being typed, each with a color. */
|
|
16
|
+
export declare function formulaReferences(formula: string): SheetFormulaRefMark[];
|
|
17
|
+
/**
|
|
18
|
+
* Whether a reference can be put at the caret of a formula being typed:
|
|
19
|
+
* right after `=`, an operator, `(` or `,`, and before nothing that is a
|
|
20
|
+
* value itself. There, the arrow keys and clicking cells write references.
|
|
21
|
+
*/
|
|
22
|
+
export declare function canPointAt(formula: string, caret: number): boolean;
|
|
23
|
+
/** The function call the caret is in, innermost first, and which of its arguments, from 0. */
|
|
24
|
+
export declare function callAt(formula: string, caret: number): {
|
|
25
|
+
name: string;
|
|
26
|
+
arg: number;
|
|
27
|
+
count: number;
|
|
28
|
+
} | null;
|
|
29
|
+
/**
|
|
30
|
+
* Which of a function's argument names the argument at `index` (of `count`)
|
|
31
|
+
* is, or -1. After `…` the names before it repeat as a group, such as the
|
|
32
|
+
* pairs of `SUMIFS` or `SWITCH`, numbered alike (`区域1, 条件1`); names after
|
|
33
|
+
* `…`, such as `SWITCH`'s default, are the last arguments when the pairs come out even.
|
|
34
|
+
*/
|
|
35
|
+
export declare function argNameAt(args: string[], index: number, count: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* The name being typed at the caret, to complete as a function: letters
|
|
38
|
+
* ending at the caret, not yet followed by `(`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function nameAt(formula: string, caret: number): {
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
text: string;
|
|
44
|
+
} | null;
|
|
45
|
+
/** A piece of a formula being typed, as it is colored in the edit box and the formula bar. */
|
|
46
|
+
export interface SheetFormulaPart {
|
|
47
|
+
text: string;
|
|
48
|
+
/** The reference's color, as in `SheetFormulaRefMark`. */
|
|
49
|
+
color?: number;
|
|
50
|
+
/** The syntax color (`dou-syntax-…`) of what isn't a reference. */
|
|
51
|
+
syntax?: 'function' | 'string' | 'number' | 'invalid' | 'keyword' | 'variable' | 'operator' | 'punctuation';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A formula cut into its colored pieces: references in their colors, and
|
|
55
|
+
* function names, "text", numbers, error values and operators in the
|
|
56
|
+
* syntax colors of `@dou-ui/code`, so the cell and either formula bar color
|
|
57
|
+
* it alike. Ends with a zero-width space, so a last line break still takes
|
|
58
|
+
* a line.
|
|
59
|
+
*/
|
|
60
|
+
export declare function formulaParts(formula: string, marks?: readonly SheetFormulaRefMark[]): SheetFormulaPart[];
|
|
61
|
+
/** The class a piece of `formulaParts` is shown with. */
|
|
62
|
+
export declare function partClass(part: SheetFormulaPart): string | undefined;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type SheetWorkbook } from '../core/model';
|
|
2
|
+
import { type SheetCellTarget } from '../core/address';
|
|
3
|
+
import { type SheetStep } from '../core/transaction';
|
|
4
|
+
import { type SheetFunction } from './functions';
|
|
5
|
+
import { type SheetResult } from './values';
|
|
6
|
+
export interface SheetFormulaEngineOptions {
|
|
7
|
+
/** More functions, or ones that replace built-in ones of the same name. */
|
|
8
|
+
functions?: readonly SheetFunction[];
|
|
9
|
+
/** The language `TEXT` writes dates in. */
|
|
10
|
+
locale?: string;
|
|
11
|
+
/** The time `TODAY()` and `NOW()` use; the current time by default. */
|
|
12
|
+
now?: () => Date;
|
|
13
|
+
}
|
|
14
|
+
/** A change for `update`: a `SheetTransaction` is one. */
|
|
15
|
+
export interface SheetFormulaChange {
|
|
16
|
+
/** The workbook after the change. */
|
|
17
|
+
readonly doc: SheetWorkbook;
|
|
18
|
+
/** What changed. */
|
|
19
|
+
readonly steps: readonly SheetStep[];
|
|
20
|
+
/** The workbook before it: when it isn't the one the engine has, it starts over. */
|
|
21
|
+
readonly before: SheetWorkbook;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The formulas of a workbook and their results. Load a workbook, ask for
|
|
25
|
+
* results with `result`, and tell it about each change with `update`.
|
|
26
|
+
*/
|
|
27
|
+
export declare class SheetFormulaEngine {
|
|
28
|
+
private slots;
|
|
29
|
+
private byName;
|
|
30
|
+
private functions;
|
|
31
|
+
private parsed;
|
|
32
|
+
private volatiles;
|
|
33
|
+
private clock;
|
|
34
|
+
private epoch;
|
|
35
|
+
private context;
|
|
36
|
+
private now;
|
|
37
|
+
/** Where the formula running links to, once it called `HYPERLINK`. */
|
|
38
|
+
private linked;
|
|
39
|
+
/** The formulas the one running needed but had no results for. */
|
|
40
|
+
private missing;
|
|
41
|
+
private current;
|
|
42
|
+
/** The workbook it has. */
|
|
43
|
+
get doc(): SheetWorkbook;
|
|
44
|
+
constructor(doc?: SheetWorkbook, options?: SheetFormulaEngineOptions);
|
|
45
|
+
/** The functions formulas can call, built in and added, by name. */
|
|
46
|
+
functionList(): SheetFunction[];
|
|
47
|
+
/** Whether a function of this name can be called, built in or added. */
|
|
48
|
+
hasFunction(name: string): boolean;
|
|
49
|
+
/** Starts over with a workbook: every result is worked out again when asked for. */
|
|
50
|
+
load(doc: SheetWorkbook): void;
|
|
51
|
+
/**
|
|
52
|
+
* Catches up with a change, such as a `SheetTransaction`: changes to
|
|
53
|
+
* cells forget only the results depending on them; rows, columns or
|
|
54
|
+
* sheets added, removed, moved or renamed start over, and so does a
|
|
55
|
+
* change made to a workbook other than the one it has.
|
|
56
|
+
*/
|
|
57
|
+
update(change: SheetFormulaChange): void;
|
|
58
|
+
/**
|
|
59
|
+
* What a cell comes to: its formula's result, or its value (`'=…` text
|
|
60
|
+
* without its `'`, empty text as nothing). `sheet` is a sheet's key
|
|
61
|
+
* (its `id`, or its name) or index; the cell is a name such as `'D7'`, a
|
|
62
|
+
* point, or a row and a column.
|
|
63
|
+
*/
|
|
64
|
+
result(sheet: string | number, cell: SheetCellTarget): SheetResult;
|
|
65
|
+
result(sheet: string | number, row: number, col: number): SheetResult;
|
|
66
|
+
/**
|
|
67
|
+
* When the results in a row last changed, to redraw only rows whose
|
|
68
|
+
* results did; any change to the workbook that starts over changes all.
|
|
69
|
+
*/
|
|
70
|
+
rowVersion(sheet: string | number, row: number): number;
|
|
71
|
+
/**
|
|
72
|
+
* Where a formula's cell links to, when the formula called `HYPERLINK`;
|
|
73
|
+
* the cell as in `result`.
|
|
74
|
+
*/
|
|
75
|
+
link(sheet: string | number, cell: SheetCellTarget): string | undefined;
|
|
76
|
+
link(sheet: string | number, row: number, col: number): string | undefined;
|
|
77
|
+
/** Whether a cell holds a formula; the cell as in `result`. */
|
|
78
|
+
isFormula(sheet: string | number, cell: SheetCellTarget): boolean;
|
|
79
|
+
isFormula(sheet: string | number, row: number, col: number): boolean;
|
|
80
|
+
/** Works out a formula as if it were in a cell, without keeping it, e.g. for a preview while typing. */
|
|
81
|
+
evaluate(formula: string, sheet?: string | number): SheetResult;
|
|
82
|
+
private slotOf;
|
|
83
|
+
private parse;
|
|
84
|
+
private add;
|
|
85
|
+
private isVolatile;
|
|
86
|
+
private remove;
|
|
87
|
+
/** Forgets the results of these cells and of every formula depending on them. */
|
|
88
|
+
private forget;
|
|
89
|
+
/** A cell's value or result; `top` works out a result not kept yet, otherwise it is noted as missing. */
|
|
90
|
+
private read;
|
|
91
|
+
/** Works out a formula's result, and first those it needs, one after another. */
|
|
92
|
+
private compute;
|
|
93
|
+
private run;
|
|
94
|
+
private scalar;
|
|
95
|
+
private range;
|
|
96
|
+
private entries;
|
|
97
|
+
private ev;
|
|
98
|
+
private binary;
|
|
99
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The error values a formula can give. */
|
|
2
|
+
export declare const ERROR_CODES: readonly ["#DIV/0!", "#N/A", "#NAME?", "#NULL!", "#NUM!", "#REF!", "#VALUE!", "#CYCLE!", "#ERROR!"];
|
|
3
|
+
/**
|
|
4
|
+
* - `#DIV/0!` dividing by zero
|
|
5
|
+
* - `#N/A` a lookup found nothing
|
|
6
|
+
* - `#NAME?` an unknown function or name
|
|
7
|
+
* - `#NUM!` a number out of range
|
|
8
|
+
* - `#REF!` a reference to cells or a sheet that are gone
|
|
9
|
+
* - `#VALUE!` a value of the wrong kind, such as text in a sum of two cells
|
|
10
|
+
* - `#CYCLE!` the formula depends on itself
|
|
11
|
+
* - `#ERROR!` the text isn't a formula
|
|
12
|
+
*/
|
|
13
|
+
export type SheetErrorCode = (typeof ERROR_CODES)[number];
|
|
14
|
+
/** An error value; there is one of each, so they compare with `===`. */
|
|
15
|
+
export declare class SheetError {
|
|
16
|
+
readonly code: SheetErrorCode;
|
|
17
|
+
private constructor();
|
|
18
|
+
static readonly all: Map<"#REF!" | "#DIV/0!" | "#N/A" | "#NAME?" | "#NULL!" | "#NUM!" | "#VALUE!" | "#CYCLE!" | "#ERROR!", SheetError>;
|
|
19
|
+
static of(code: SheetErrorCode): SheetError;
|
|
20
|
+
toString(): "#REF!" | "#DIV/0!" | "#N/A" | "#NAME?" | "#NULL!" | "#NUM!" | "#VALUE!" | "#CYCLE!" | "#ERROR!";
|
|
21
|
+
}
|
|
22
|
+
export declare const isSheetError: (value: unknown) => value is SheetError;
|
|
23
|
+
export declare const DIV0: SheetError;
|
|
24
|
+
export declare const NA: SheetError;
|
|
25
|
+
export declare const NAME: SheetError;
|
|
26
|
+
export declare const NUM: SheetError;
|
|
27
|
+
export declare const REF: SheetError;
|
|
28
|
+
export declare const VALUE: SheetError;
|
|
29
|
+
export declare const CYCLE: SheetError;
|
|
30
|
+
export declare const SYNTAX: SheetError;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { SheetError } from './error';
|
|
2
|
+
import { type SheetArg, type SheetResult } from './values';
|
|
3
|
+
/** What every function call is given besides its arguments. */
|
|
4
|
+
export interface SheetFunctionContext {
|
|
5
|
+
/** When the calculation started; `TODAY()` and `NOW()` read it. */
|
|
6
|
+
now: Date;
|
|
7
|
+
/** The language dates are written in, for `TEXT`. */
|
|
8
|
+
locale?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Makes the cell whose formula is running a link to `target`, as
|
|
11
|
+
* `HYPERLINK` does: an address as a cell's `link` takes.
|
|
12
|
+
*/
|
|
13
|
+
link?: (target: string) => void;
|
|
14
|
+
}
|
|
15
|
+
interface FunctionBase {
|
|
16
|
+
/** The name formulas call it by; matched in any case. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** The fewest and most arguments it takes; `#VALUE!` otherwise. */
|
|
19
|
+
minArgs?: number;
|
|
20
|
+
maxArgs?: number;
|
|
21
|
+
/** Gives a new result on every recalculation, like `TODAY()`. */
|
|
22
|
+
volatile?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The arguments' names, shown while typing a call: `[name]` may be left
|
|
25
|
+
* out and `…` repeats the one before, e.g. `['金额', '[税率]']`.
|
|
26
|
+
*/
|
|
27
|
+
args?: string[];
|
|
28
|
+
/** What it does, in a few words, shown in the list of functions. */
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A formula function. `run` gets each argument as a value, or as a range
|
|
33
|
+
* for a reference to more than one cell (see `numbersOf`, `toNumber` and
|
|
34
|
+
* the other helpers), and returns the result, or a range as `CHOOSE` can.
|
|
35
|
+
* With `lazy`, it gets each argument as a function to call when needed, as
|
|
36
|
+
* `IF` does to work out only the branch it takes.
|
|
37
|
+
*/
|
|
38
|
+
export type SheetFunction = (FunctionBase & {
|
|
39
|
+
lazy?: false;
|
|
40
|
+
run: (args: SheetArg[], context: SheetFunctionContext) => SheetArg;
|
|
41
|
+
}) | (FunctionBase & {
|
|
42
|
+
lazy: true;
|
|
43
|
+
run: (args: (() => SheetArg)[], context: SheetFunctionContext) => SheetArg;
|
|
44
|
+
});
|
|
45
|
+
/** Declares a formula function; only gives it a type. */
|
|
46
|
+
export declare function defineSheetFunction<T extends SheetFunction>(definition: T): T;
|
|
47
|
+
/** A single value from an argument: a range of one cell is that cell, a bigger one `#VALUE!`. */
|
|
48
|
+
export declare function scalarOf(arg: SheetArg): SheetResult;
|
|
49
|
+
/**
|
|
50
|
+
* The numbers in some arguments, the way sums count them: in ranges only
|
|
51
|
+
* numbers, dates and times count (other text, `TRUE` / `FALSE` and empty cells are skipped);
|
|
52
|
+
* given directly, text that reads as a number and `TRUE` / `FALSE` count
|
|
53
|
+
* too. The first error found is returned instead.
|
|
54
|
+
*/
|
|
55
|
+
export declare function numbersOf(args: SheetArg[]): number[] | SheetError;
|
|
56
|
+
/**
|
|
57
|
+
* A condition as `SUMIF` and `COUNTIF` take it: a value to equal, or text
|
|
58
|
+
* such as `">5"`, `"<>完成"`, `"上海*"` (with `*` and `?`), `""` for empty.
|
|
59
|
+
*/
|
|
60
|
+
export declare function criteriaOf(criteria: SheetResult): (value: SheetResult) => boolean;
|
|
61
|
+
export declare const builtinFunctions: SheetFunction[];
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a function takes and does, for completion and the argument hint
|
|
3
|
+
* while typing a formula. `args` are the argument names in order:
|
|
4
|
+
* `[name]` may be left out, and `…` means the one before can repeat.
|
|
5
|
+
*/
|
|
6
|
+
export interface SheetFunctionHelp {
|
|
7
|
+
args: string[];
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const helpZhCN: Record<string, SheetFunctionHelp>;
|
|
11
|
+
export declare const helpZhTW: Record<string, SheetFunctionHelp>;
|
|
12
|
+
export declare const helpEn: Record<string, SheetFunctionHelp>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { SheetFormulaEngine } from './engine';
|
|
2
|
+
export type { SheetFormulaChange, SheetFormulaEngineOptions } from './engine';
|
|
3
|
+
export { ERROR_CODES, isSheetError, SheetError } from './error';
|
|
4
|
+
export type { SheetErrorCode } from './error';
|
|
5
|
+
export { builtinFunctions, criteriaOf, defineSheetFunction, numbersOf, scalarOf } from './functions';
|
|
6
|
+
export type { SheetFunction, SheetFunctionContext } from './functions';
|
|
7
|
+
export { formulaTokens, functionsOf, parseFormula, referencesOf, SheetFormulaSyntaxError, } from './parse';
|
|
8
|
+
export type { BinaryOp, SheetFormulaNode, SheetFormulaToken } from './parse';
|
|
9
|
+
export { argNameAt, callAt, canPointAt, formulaReferences, nameAt } from './edit';
|
|
10
|
+
export type { SheetFormulaRefMark } from './edit';
|
|
11
|
+
export type { SheetFunctionHelp } from './help';
|
|
12
|
+
export { compareValues, dateText, isDateText, isRange, serialOf, shownValue, toBoolean, toNumber, toText, } from './values';
|
|
13
|
+
export type { SheetArg, SheetRangeArg, SheetResult } from './values';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type SheetErrorCode } from './error';
|
|
2
|
+
export type SheetFormulaNode = {
|
|
3
|
+
type: 'number';
|
|
4
|
+
value: number;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'text';
|
|
7
|
+
value: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'boolean';
|
|
10
|
+
value: boolean;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'error';
|
|
13
|
+
code: SheetErrorCode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A reference, with its sheet as written (unquoted); whole columns run
|
|
17
|
+
* from row 0 to `Infinity`, whole rows likewise. `cell` is a single cell.
|
|
18
|
+
*/
|
|
19
|
+
| {
|
|
20
|
+
type: 'ref';
|
|
21
|
+
sheet?: string;
|
|
22
|
+
top: number;
|
|
23
|
+
left: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
right: number;
|
|
26
|
+
cell: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** A function call; `name` in capitals. */
|
|
29
|
+
| {
|
|
30
|
+
type: 'call';
|
|
31
|
+
name: string;
|
|
32
|
+
args: SheetFormulaNode[];
|
|
33
|
+
} | {
|
|
34
|
+
type: 'unary';
|
|
35
|
+
op: '-' | '+' | '%';
|
|
36
|
+
arg: SheetFormulaNode;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'binary';
|
|
39
|
+
op: BinaryOp;
|
|
40
|
+
left: SheetFormulaNode;
|
|
41
|
+
right: SheetFormulaNode;
|
|
42
|
+
}
|
|
43
|
+
/** An argument left out, as in `IF(A1,,1)`. */
|
|
44
|
+
| {
|
|
45
|
+
type: 'empty';
|
|
46
|
+
};
|
|
47
|
+
export type BinaryOp = '+' | '-' | '*' | '/' | '^' | '&' | '=' | '<>' | '<' | '>' | '<=' | '>=';
|
|
48
|
+
/** Thrown for text that isn't a formula; it shows as `#ERROR!`. */
|
|
49
|
+
export declare class SheetFormulaSyntaxError extends Error {
|
|
50
|
+
readonly at: number;
|
|
51
|
+
constructor(message: string, at: number);
|
|
52
|
+
}
|
|
53
|
+
/** A piece of a formula as written, with where it is in the text (counting the `=`). */
|
|
54
|
+
export type SheetFormulaToken = {
|
|
55
|
+
kind: 'number' | 'text' | 'name' | 'op' | 'error';
|
|
56
|
+
start: number;
|
|
57
|
+
end: number;
|
|
58
|
+
text: string;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'ref';
|
|
61
|
+
start: number;
|
|
62
|
+
end: number;
|
|
63
|
+
text: string;
|
|
64
|
+
ref: Extract<SheetFormulaNode, {
|
|
65
|
+
type: 'ref';
|
|
66
|
+
}>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The pieces of a formula, also one being typed and not finished, e.g. for
|
|
70
|
+
* coloring it: numbers, "text", names (of functions), references,
|
|
71
|
+
* operators and brackets, and error values. Spaces are left out.
|
|
72
|
+
*/
|
|
73
|
+
export declare function formulaTokens(formula: string): SheetFormulaToken[];
|
|
74
|
+
/**
|
|
75
|
+
* Reads a formula, with or without its `=`, into a tree. Throws
|
|
76
|
+
* `SheetFormulaSyntaxError` for text that isn't one.
|
|
77
|
+
*/
|
|
78
|
+
export declare function parseFormula(formula: string): SheetFormulaNode;
|
|
79
|
+
/** Every reference in a formula tree. */
|
|
80
|
+
export declare function referencesOf(node: SheetFormulaNode, out?: Extract<SheetFormulaNode, {
|
|
81
|
+
type: 'ref';
|
|
82
|
+
}>[]): {
|
|
83
|
+
type: "ref";
|
|
84
|
+
sheet?: string;
|
|
85
|
+
top: number;
|
|
86
|
+
left: number;
|
|
87
|
+
bottom: number;
|
|
88
|
+
right: number;
|
|
89
|
+
cell: boolean;
|
|
90
|
+
}[];
|
|
91
|
+
/** The functions a formula calls, in capitals. */
|
|
92
|
+
export declare function functionsOf(node: SheetFormulaNode, out?: Set<string>): Set<string>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { SheetValue } from '../core/model';
|
|
2
|
+
import { type SheetError } from './error';
|
|
3
|
+
/**
|
|
4
|
+
* What a formula gives: a number, text, `TRUE` / `FALSE`, nothing (an
|
|
5
|
+
* empty cell), or an error. Dates are text written `2026-03-05` (or
|
|
6
|
+
* `2026-03-05 09:30`), as cells hold them.
|
|
7
|
+
*/
|
|
8
|
+
export type SheetResult = number | string | boolean | null | SheetError;
|
|
9
|
+
/** A range a function is given: its cells, as their values or their formulas' results. */
|
|
10
|
+
export interface SheetRangeArg {
|
|
11
|
+
readonly kind: 'range';
|
|
12
|
+
/** Its size, kept inside the sheet: `A:A` is as tall as the sheet. */
|
|
13
|
+
readonly rows: number;
|
|
14
|
+
readonly cols: number;
|
|
15
|
+
/** The cell at a row and column counted from the range's top left, from 0. */
|
|
16
|
+
at(row: number, col: number): SheetResult;
|
|
17
|
+
/**
|
|
18
|
+
* The cells with something in them, row by row, with where they are.
|
|
19
|
+
* Empty cells are left out, so a whole column costs only its data.
|
|
20
|
+
*/
|
|
21
|
+
entries(): Iterable<[row: number, col: number, value: SheetResult]>;
|
|
22
|
+
}
|
|
23
|
+
/** What a function is given for each argument: a value, or a range for a reference to more than one cell. */
|
|
24
|
+
export type SheetArg = SheetResult | SheetRangeArg;
|
|
25
|
+
export declare const isRange: (arg: unknown) => arg is SheetRangeArg;
|
|
26
|
+
/** Whether a value is a date (or date and time) as cells write them. */
|
|
27
|
+
export declare const isDateText: (value: unknown) => value is string;
|
|
28
|
+
/** Whether a value is a time of day as cells write it, such as `09:30`. */
|
|
29
|
+
export declare const isTimeText: (value: unknown) => value is string;
|
|
30
|
+
/** A date or time written in a cell as a day number (a time as part of a day); `null` when it isn't one. */
|
|
31
|
+
export declare function serialOf(text: string): number | null;
|
|
32
|
+
/** A day number as a date, with its time when it has a part of a day. */
|
|
33
|
+
export declare function dateText(serial: number): string;
|
|
34
|
+
/** A part of a day as `hh:mm`, or `hh:mm:ss` with seconds; a whole day and more wraps round. */
|
|
35
|
+
export declare function timeText(fraction: number): string;
|
|
36
|
+
/** A part of a day as a time; a whole day or more, or below nothing, stays a number of days. */
|
|
37
|
+
export declare const timeOrDays: (days: number) => number | string;
|
|
38
|
+
/** The parts of a date, from a date or a day number; `null` when it is neither. */
|
|
39
|
+
export declare function dateParts(value: SheetResult): {
|
|
40
|
+
year: number;
|
|
41
|
+
month: number;
|
|
42
|
+
day: number;
|
|
43
|
+
serial: number;
|
|
44
|
+
} | null;
|
|
45
|
+
/**
|
|
46
|
+
* A value as a number: `TRUE` is 1, an empty cell 0, text that reads as a
|
|
47
|
+
* number (`12`, `1,280`, `12%`) or a date its number; other text is
|
|
48
|
+
* `#VALUE!`. Errors pass through.
|
|
49
|
+
*/
|
|
50
|
+
export declare function toNumber(value: SheetResult): number | SheetError;
|
|
51
|
+
/** A value as text: numbers as a cell shows them without a format, `TRUE` / `FALSE`. */
|
|
52
|
+
export declare function toText(value: SheetResult): string | SheetError;
|
|
53
|
+
/** A value as `TRUE` / `FALSE`: numbers are true unless 0; text `TRUE` / `FALSE` reads as such. */
|
|
54
|
+
export declare function toBoolean(value: SheetResult): boolean | SheetError;
|
|
55
|
+
/**
|
|
56
|
+
* Compares two values the way formulas do: numbers by size, text by
|
|
57
|
+
* letters ignoring case, `FALSE` before `TRUE`; numbers come before text,
|
|
58
|
+
* and text before `TRUE` / `FALSE`. An empty cell is 0, or "" next to text.
|
|
59
|
+
*/
|
|
60
|
+
export declare function compareValues(a: SheetResult, b: SheetResult): number;
|
|
61
|
+
/**
|
|
62
|
+
* A cell's value as it shows: for a formula, its result from `result`
|
|
63
|
+
* (an error as its code, such as `#N/A`), when given.
|
|
64
|
+
*/
|
|
65
|
+
export declare function shownValue(value: SheetValue, result: ((row: number, col: number) => SheetResult) | undefined, row: number, col: number): SheetValue;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import type { SheetCellTarget } from './core/address';
|
|
3
|
+
import type { SheetWorkbook } from './core/model';
|
|
4
|
+
import { SheetFormulaEngine, type SheetFormulaChange, type SheetFormulaEngineOptions } from './formula/engine';
|
|
5
|
+
import type { SheetResult } from './formula/values';
|
|
6
|
+
/** The results of a workbook's formulas, read reactively. */
|
|
7
|
+
export interface SheetFormulas {
|
|
8
|
+
/**
|
|
9
|
+
* A cell's result, as `SheetFormulaEngine.result` gives it. Read in a
|
|
10
|
+
* `computed` or a template, it is read again when the workbook changes.
|
|
11
|
+
*/
|
|
12
|
+
result: {
|
|
13
|
+
(sheet: string | number, cell: SheetCellTarget): SheetResult;
|
|
14
|
+
(sheet: string | number, row: number, col: number): SheetResult;
|
|
15
|
+
};
|
|
16
|
+
/** Works out a formula without writing it into a cell, reactively too. */
|
|
17
|
+
evaluate: (formula: string, sheet?: string | number) => SheetResult;
|
|
18
|
+
/**
|
|
19
|
+
* Catches up with a change of the grid: pass it the `transaction` event
|
|
20
|
+
* (`@transaction="formulas.update"`), and only the formulas the change
|
|
21
|
+
* reaches are worked out again. Without it, every change of the workbook
|
|
22
|
+
* works all of them out again.
|
|
23
|
+
*/
|
|
24
|
+
update: (change: SheetFormulaChange) => void;
|
|
25
|
+
/** The engine underneath. */
|
|
26
|
+
readonly engine: SheetFormulaEngine;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Works out a workbook's formulas outside the grid, such as for totals
|
|
30
|
+
* shown above it. `book` is the workbook bound to the grid's `v-model`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useSheetFormulas(book: MaybeRefOrGetter<SheetWorkbook>, options?: SheetFormulaEngineOptions): SheetFormulas;
|