@omegagrid/grid-core 0.10.2 → 0.10.4
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/__generated/functions.d.ts +4 -0
- package/dist/__generated/functions.d.ts.map +1 -0
- package/dist/__generated/functions.js +45 -0
- package/dist/__generated/functions.js.map +1 -0
- package/dist/calculations/autofill.d.ts +7 -0
- package/dist/calculations/autofill.d.ts.map +1 -0
- package/dist/calculations/autofill.js +84 -0
- package/dist/calculations/autofill.js.map +1 -0
- package/dist/calculations/conditions.d.ts +4 -0
- package/dist/calculations/conditions.d.ts.map +1 -0
- package/dist/calculations/conditions.js +41 -0
- package/dist/calculations/conditions.js.map +1 -0
- package/dist/calculations/context.d.ts +53 -0
- package/dist/calculations/context.d.ts.map +1 -0
- package/dist/calculations/context.js +85 -0
- package/dist/calculations/context.js.map +1 -0
- package/dist/calculations/formula.d.ts +89 -0
- package/dist/calculations/formula.d.ts.map +1 -0
- package/dist/calculations/formula.js +443 -0
- package/dist/calculations/formula.js.map +1 -0
- package/dist/calculations/functions/dates.d.ts +13 -0
- package/dist/calculations/functions/dates.d.ts.map +1 -0
- package/dist/calculations/functions/dates.js +58 -0
- package/dist/calculations/functions/dates.js.map +1 -0
- package/dist/calculations/functions/index.d.ts +11 -0
- package/dist/calculations/functions/index.d.ts.map +1 -0
- package/dist/calculations/functions/index.js +21 -0
- package/dist/calculations/functions/index.js.map +1 -0
- package/dist/calculations/functions/logical.d.ts +11 -0
- package/dist/calculations/functions/logical.d.ts.map +1 -0
- package/dist/calculations/functions/logical.js +50 -0
- package/dist/calculations/functions/logical.js.map +1 -0
- package/dist/calculations/functions/lookup.d.ts +18 -0
- package/dist/calculations/functions/lookup.d.ts.map +1 -0
- package/dist/calculations/functions/lookup.js +169 -0
- package/dist/calculations/functions/lookup.js.map +1 -0
- package/dist/calculations/functions/math.d.ts +72 -0
- package/dist/calculations/functions/math.d.ts.map +1 -0
- package/dist/calculations/functions/math.js +182 -0
- package/dist/calculations/functions/math.js.map +1 -0
- package/dist/calculations/functions/special.d.ts +2 -0
- package/dist/calculations/functions/special.d.ts.map +1 -0
- package/dist/calculations/functions/special.js +51 -0
- package/dist/calculations/functions/special.js.map +1 -0
- package/dist/calculations/functions/statistical.d.ts +7 -0
- package/dist/calculations/functions/statistical.d.ts.map +1 -0
- package/dist/calculations/functions/statistical.js +47 -0
- package/dist/calculations/functions/statistical.js.map +1 -0
- package/dist/calculations/functions/text.d.ts +29 -0
- package/dist/calculations/functions/text.d.ts.map +1 -0
- package/dist/calculations/functions/text.js +58 -0
- package/dist/calculations/functions/text.js.map +1 -0
- package/dist/calculations/helpers.d.ts +13 -0
- package/dist/calculations/helpers.d.ts.map +1 -0
- package/dist/calculations/helpers.js +32 -0
- package/dist/calculations/helpers.js.map +1 -0
- package/dist/calculations/index.d.ts +7 -0
- package/dist/calculations/index.d.ts.map +1 -0
- package/dist/calculations/index.js +7 -0
- package/dist/calculations/index.js.map +1 -0
- package/dist/calculations/operators.d.ts +19 -0
- package/dist/calculations/operators.d.ts.map +1 -0
- package/dist/calculations/operators.js +58 -0
- package/dist/calculations/operators.js.map +1 -0
- package/dist/calculations/tokenization.d.ts +36 -0
- package/dist/calculations/tokenization.d.ts.map +1 -0
- package/dist/calculations/tokenization.js +203 -0
- package/dist/calculations/tokenization.js.map +1 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +2 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/range.d.ts +66 -0
- package/dist/common/range.d.ts.map +1 -0
- package/dist/common/range.js +222 -0
- package/dist/common/range.js.map +1 -0
- package/dist/constants.d.ts +68 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +127 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/model/calculationModel.d.ts +30 -0
- package/dist/model/calculationModel.d.ts.map +1 -0
- package/dist/model/calculationModel.js +206 -0
- package/dist/model/calculationModel.js.map +1 -0
- package/dist/model/cellModel.d.ts +134 -0
- package/dist/model/cellModel.d.ts.map +1 -0
- package/dist/model/cellModel.js +371 -0
- package/dist/model/cellModel.js.map +1 -0
- package/dist/model/columnModel.d.ts +160 -0
- package/dist/model/columnModel.d.ts.map +1 -0
- package/dist/model/columnModel.js +159 -0
- package/dist/model/columnModel.js.map +1 -0
- package/dist/model/commentModel.d.ts +58 -0
- package/dist/model/commentModel.d.ts.map +1 -0
- package/dist/model/commentModel.js +81 -0
- package/dist/model/commentModel.js.map +1 -0
- package/dist/model/conditionalFormats.d.ts +104 -0
- package/dist/model/conditionalFormats.d.ts.map +1 -0
- package/dist/model/conditionalFormats.js +414 -0
- package/dist/model/conditionalFormats.js.map +1 -0
- package/dist/model/cssStyle.d.ts +20 -0
- package/dist/model/cssStyle.d.ts.map +1 -0
- package/dist/model/cssStyle.js +301 -0
- package/dist/model/cssStyle.js.map +1 -0
- package/dist/model/dependencies.d.ts +30 -0
- package/dist/model/dependencies.d.ts.map +1 -0
- package/dist/model/dependencies.js +139 -0
- package/dist/model/dependencies.js.map +1 -0
- package/dist/model/dependencyModel.d.ts +9 -0
- package/dist/model/dependencyModel.d.ts.map +1 -0
- package/dist/model/dependencyModel.js +9 -0
- package/dist/model/dependencyModel.js.map +1 -0
- package/dist/model/elementModel.d.ts +103 -0
- package/dist/model/elementModel.d.ts.map +1 -0
- package/dist/model/elementModel.js +181 -0
- package/dist/model/elementModel.js.map +1 -0
- package/dist/model/filterModel.d.ts +35 -0
- package/dist/model/filterModel.d.ts.map +1 -0
- package/dist/model/filterModel.js +153 -0
- package/dist/model/filterModel.js.map +1 -0
- package/dist/model/gridModel.d.ts +181 -0
- package/dist/model/gridModel.d.ts.map +1 -0
- package/dist/model/gridModel.js +797 -0
- package/dist/model/gridModel.js.map +1 -0
- package/dist/model/groupModel.d.ts +26 -0
- package/dist/model/groupModel.d.ts.map +1 -0
- package/dist/model/groupModel.js +112 -0
- package/dist/model/groupModel.js.map +1 -0
- package/dist/model/history.d.ts +24 -0
- package/dist/model/history.d.ts.map +1 -0
- package/dist/model/history.js +35 -0
- package/dist/model/history.js.map +1 -0
- package/dist/model/index.d.ts +23 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +23 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/iterableRange.d.ts +49 -0
- package/dist/model/iterableRange.d.ts.map +1 -0
- package/dist/model/iterableRange.js +108 -0
- package/dist/model/iterableRange.js.map +1 -0
- package/dist/model/merges.d.ts +34 -0
- package/dist/model/merges.d.ts.map +1 -0
- package/dist/model/merges.js +123 -0
- package/dist/model/merges.js.map +1 -0
- package/dist/model/namingModel.d.ts +25 -0
- package/dist/model/namingModel.d.ts.map +1 -0
- package/dist/model/namingModel.js +77 -0
- package/dist/model/namingModel.js.map +1 -0
- package/dist/model/options.d.ts +257 -0
- package/dist/model/options.d.ts.map +1 -0
- package/dist/model/options.js +35 -0
- package/dist/model/options.js.map +1 -0
- package/dist/model/rowModel.d.ts +104 -0
- package/dist/model/rowModel.d.ts.map +1 -0
- package/dist/model/rowModel.js +155 -0
- package/dist/model/rowModel.js.map +1 -0
- package/dist/model/selectionModel.d.ts +19 -0
- package/dist/model/selectionModel.d.ts.map +1 -0
- package/dist/model/selectionModel.js +40 -0
- package/dist/model/selectionModel.js.map +1 -0
- package/dist/model/sortingModel.d.ts +46 -0
- package/dist/model/sortingModel.d.ts.map +1 -0
- package/dist/model/sortingModel.js +157 -0
- package/dist/model/sortingModel.js.map +1 -0
- package/dist/model/style.d.ts +90 -0
- package/dist/model/style.d.ts.map +1 -0
- package/dist/model/style.js +34 -0
- package/dist/model/style.js.map +1 -0
- package/dist/model/styleModel.d.ts +22 -0
- package/dist/model/styleModel.d.ts.map +1 -0
- package/dist/model/styleModel.js +91 -0
- package/dist/model/styleModel.js.map +1 -0
- package/dist/model/tableTheme.d.ts +46 -0
- package/dist/model/tableTheme.d.ts.map +1 -0
- package/dist/model/tableTheme.js +93 -0
- package/dist/model/tableTheme.js.map +1 -0
- package/dist/model/validations.d.ts +5 -0
- package/dist/model/validations.d.ts.map +1 -0
- package/dist/model/validations.js +24 -0
- package/dist/model/validations.js.map +1 -0
- package/dist/sparklines/index.d.ts +2 -0
- package/dist/sparklines/index.d.ts.map +1 -0
- package/dist/sparklines/index.js +2 -0
- package/dist/sparklines/index.js.map +1 -0
- package/dist/sparklines/sparklines.d.ts +59 -0
- package/dist/sparklines/sparklines.d.ts.map +1 -0
- package/dist/sparklines/sparklines.js +176 -0
- package/dist/sparklines/sparklines.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +11 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/__generated/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;wBA4ChC,2BAA2B;AAAvD,wBAAwD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const functions = JSON.parse(`[
|
|
2
|
+
{
|
|
3
|
+
"name": "text",
|
|
4
|
+
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "left",
|
|
7
|
+
"description": "Returns the leftmost characters from a text value.",
|
|
8
|
+
"parameters": [
|
|
9
|
+
{
|
|
10
|
+
"name": "v",
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "count",
|
|
15
|
+
"type": "number"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"links": [
|
|
19
|
+
"https://support.microsoft.com/en-us/office/left-leftb-functions-9203d2d2-7960-479b-84c6-1ea52b99640c",
|
|
20
|
+
"https://support.google.com/docs/answer/3094079"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "right",
|
|
25
|
+
"description": "Returns the rightmost characters from a text value.",
|
|
26
|
+
"parameters": [
|
|
27
|
+
{
|
|
28
|
+
"name": "v",
|
|
29
|
+
"type": "string"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "count",
|
|
33
|
+
"type": "number"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"links": [
|
|
37
|
+
"https://support.microsoft.com/en-us/office/right-rightb-functions-240267ee-9afa-4639-a02b-f19e1786cf2f",
|
|
38
|
+
"https://support.google.com/docs/answer/3094087"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]`);
|
|
44
|
+
export default functions;
|
|
45
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/__generated/functions.ts"],"names":[],"mappings":"AACA,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0C3B,CAAC,CAAC;AACJ,eAAe,SAAwC,CAAC","sourcesContent":["import type { FormulaFuncGroupDescription } from '../types';\nconst functions = JSON.parse(`[\n {\n \"name\": \"text\",\n \"functions\": [\n {\n \"name\": \"left\",\n \"description\": \"Returns the leftmost characters from a text value.\",\n \"parameters\": [\n {\n \"name\": \"v\",\n \"type\": \"string\"\n },\n {\n \"name\": \"count\",\n \"type\": \"number\"\n }\n ],\n \"links\": [\n \"https://support.microsoft.com/en-us/office/left-leftb-functions-9203d2d2-7960-479b-84c6-1ea52b99640c\",\n \"https://support.google.com/docs/answer/3094079\"\n ]\n },\n {\n \"name\": \"right\",\n \"description\": \"Returns the rightmost characters from a text value.\",\n \"parameters\": [\n {\n \"name\": \"v\",\n \"type\": \"string\"\n },\n {\n \"name\": \"count\",\n \"type\": \"number\"\n }\n ],\n \"links\": [\n \"https://support.microsoft.com/en-us/office/right-rightb-functions-240267ee-9afa-4639-a02b-f19e1786cf2f\",\n \"https://support.google.com/docs/answer/3094087\"\n ]\n }\n ]\n }\n]`);\nexport default functions as FormulaFuncGroupDescription;"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Direction } from "@omegagrid/core";
|
|
2
|
+
import { CellRange } from "../common";
|
|
3
|
+
import { CellModel, GridModel } from "../model";
|
|
4
|
+
export declare function extrapolateValues(source: CellModel[], count: number): unknown[];
|
|
5
|
+
export declare function extrapolateFormulas(cell: CellModel, direction: Direction, count: number): string[];
|
|
6
|
+
export declare function autofill(model: GridModel, selectedRange: CellRange, autofillRange: CellRange, direction: Direction): import("..").SpillResult;
|
|
7
|
+
//# sourceMappingURL=autofill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autofill.d.ts","sourceRoot":"","sources":["../../src/calculations/autofill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,aA4BnE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAYvF;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,4BAsClH"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { matrix } from "@omegagrid/core";
|
|
2
|
+
import { Formula, prefixFormula } from ".";
|
|
3
|
+
export function extrapolateValues(source, count) {
|
|
4
|
+
const result = Array(count).fill(null);
|
|
5
|
+
let increment = 0;
|
|
6
|
+
let inputValues = [];
|
|
7
|
+
if (source.length > 1) {
|
|
8
|
+
inputValues = source.map(cell => parseFloat(cell.value) || 0);
|
|
9
|
+
increment = inputValues[1] - inputValues[0];
|
|
10
|
+
for (let i = 2; i < inputValues.length; i++) {
|
|
11
|
+
if (inputValues[i] - inputValues[i - 1] !== increment) {
|
|
12
|
+
increment = 0;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (increment == 0) {
|
|
18
|
+
for (let i = 0; i < count; i++) {
|
|
19
|
+
result[i] = source[i % source.length]?.value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
let prev = inputValues[inputValues.length - 1];
|
|
24
|
+
for (let i = 0; i < count; i++) {
|
|
25
|
+
prev = result[i] = prev + increment;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
export function extrapolateFormulas(cell, direction, count) {
|
|
31
|
+
const formula = new Formula(cell.formula, cell.model.calculations.tokenizer);
|
|
32
|
+
const result = [];
|
|
33
|
+
for (let i = 0; i < count; i++) {
|
|
34
|
+
result.push(prefixFormula(formula.shift({
|
|
35
|
+
index: 0,
|
|
36
|
+
offset: 1,
|
|
37
|
+
direction: direction,
|
|
38
|
+
allSheets: true
|
|
39
|
+
}).createFormulaString()));
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
export function autofill(model, selectedRange, autofillRange, direction) {
|
|
44
|
+
const sourceMatrix = model.getCellMatrix(selectedRange);
|
|
45
|
+
let input;
|
|
46
|
+
if (direction == 'right')
|
|
47
|
+
input = matrix.clone(sourceMatrix);
|
|
48
|
+
else if (direction == 'down')
|
|
49
|
+
input = matrix.transpose(sourceMatrix);
|
|
50
|
+
else if (direction == 'left')
|
|
51
|
+
input = matrix.reverseColumns(sourceMatrix);
|
|
52
|
+
else if (direction == 'up')
|
|
53
|
+
input = matrix.reverseColumns(matrix.transpose(sourceMatrix));
|
|
54
|
+
const displayValueMatrix = new Array(autofillRange.size.rows);
|
|
55
|
+
for (let r = 0; r < autofillRange.size.rows; r++) {
|
|
56
|
+
displayValueMatrix[r] = (new Array(autofillRange.size.columns));
|
|
57
|
+
for (let c = 0; c < autofillRange.size.columns; c++) {
|
|
58
|
+
const sourceCell = sourceMatrix.length > r
|
|
59
|
+
? sourceMatrix[r][sourceMatrix[r].length > c ? c : 0]
|
|
60
|
+
: sourceMatrix[0][c];
|
|
61
|
+
displayValueMatrix[r][c] = sourceCell.hasDisplayValue ? sourceCell.displayValue : null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const autofillCount = autofillRange.size[direction == 'down' || direction == 'up' ? 'rows' : 'columns'];
|
|
65
|
+
let output = input.map(vect => {
|
|
66
|
+
if (vect[vect.length - 1].hasFormula)
|
|
67
|
+
return extrapolateFormulas(vect[vect.length - 1], direction, autofillCount);
|
|
68
|
+
else
|
|
69
|
+
return extrapolateValues(vect, autofillCount);
|
|
70
|
+
});
|
|
71
|
+
if (direction == 'down')
|
|
72
|
+
output = matrix.transpose(output);
|
|
73
|
+
else if (direction == 'left')
|
|
74
|
+
output = matrix.reverseColumns(output);
|
|
75
|
+
else if (direction == 'up')
|
|
76
|
+
output = matrix.reverseRows(matrix.transpose(output));
|
|
77
|
+
return model.spillValues({
|
|
78
|
+
cell: model.getCellByRange(autofillRange.bounds[0][0]),
|
|
79
|
+
values: output,
|
|
80
|
+
propertyCell: model.getCellByRange(selectedRange.bounds[0][0]),
|
|
81
|
+
displayValues: displayValueMatrix
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=autofill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autofill.js","s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IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU;YACnC,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;;YAE5E,OAAO,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,IAAI,SAAS,IAAI,MAAM;QAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;SACtD,IAAI,SAAS,IAAI,MAAM;QAAE,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SAChE,IAAI,SAAS,IAAI,IAAI;QAAE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAElF,OAAO,KAAK,CAAC,WAAW,CAAC;QACxB,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtD,MAAM,EAAE,MAAM;QACd,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,aAAa,EAAE,kBAAkB;KACjC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Direction, Matrix, matrix } from \"@omegagrid/core\";\nimport { Formula, prefixFormula } from \".\";\nimport { CellRange } from \"../common\";\nimport { CellModel, GridModel } from \"../model\";\n\nexport function extrapolateValues(source: CellModel[], count: number) {\n\tconst result: unknown[] = Array(count).fill(null);\n\tlet increment = 0;\n\tlet inputValues: number[] = [];\n\n\tif (source.length > 1) {\n\t\tinputValues = source.map(cell => parseFloat(cell.value as string) || 0);\n\t\tincrement = inputValues[1] - inputValues[0];\n\t\tfor (let i = 2; i < inputValues.length; i++) {\n\t\t\tif (inputValues[i] - inputValues[i - 1] !== increment) {\n\t\t\t\tincrement = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (increment == 0) {\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tresult[i] = source[i % source.length]?.value;\n\t\t}\n\t} else {\n\t\tlet prev = inputValues[inputValues.length - 1];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tprev = result[i] = prev + increment;\n\t\t}\n\t}\n\n\treturn result;\n}\n\nexport function extrapolateFormulas(cell: CellModel, direction: Direction, count: number) {\n\tconst formula = new Formula(cell.formula, cell.model.calculations.tokenizer);\n\tconst result: string[] = [];\n\tfor (let i = 0; i < count; i++) {\n\t\tresult.push(prefixFormula(formula.shift({\n\t\t\tindex: 0,\n\t\t\toffset: 1,\n\t\t\tdirection: direction,\n\t\t\tallSheets: true\n\t\t}).createFormulaString()));\n\t}\n\treturn result;\n}\n\nexport function autofill(model: GridModel, selectedRange: CellRange, autofillRange: CellRange, direction: Direction) {\n\tconst sourceMatrix = model.getCellMatrix(selectedRange);\n\tlet input: Matrix<CellModel>;\n\n\tif (direction == 'right') input = matrix.clone(sourceMatrix);\n\telse if (direction == 'down') input = matrix.transpose(sourceMatrix);\n\telse if (direction == 'left') input = matrix.reverseColumns(sourceMatrix);\n\telse if (direction == 'up') input = matrix.reverseColumns(matrix.transpose(sourceMatrix));\n\n\tconst displayValueMatrix: Matrix<string> = new Array(autofillRange.size.rows);\n\tfor (let r = 0; r < autofillRange.size.rows; r++) {\n\t\tdisplayValueMatrix[r] = (new Array(autofillRange.size.columns));\n\t\tfor (let c = 0; c < autofillRange.size.columns; c++) {\n\t\t\tconst sourceCell = sourceMatrix.length > r\n\t\t\t\t? sourceMatrix[r][sourceMatrix[r].length > c ? c : 0]\n\t\t\t\t: sourceMatrix[0][c];\n\t\t\tdisplayValueMatrix[r][c] = sourceCell.hasDisplayValue ? sourceCell.displayValue : null;\n\t\t}\n\t}\n\n\tconst autofillCount = autofillRange.size[direction == 'down' || direction == 'up' ? 'rows' : 'columns'];\n\tlet output = input.map(vect => {\n\t\tif (vect[vect.length - 1].hasFormula)\n\t\t\treturn extrapolateFormulas(vect[vect.length - 1], direction, autofillCount);\n\t\telse\n\t\t\treturn extrapolateValues(vect, autofillCount);\n\t});\n\n\tif (direction == 'down') output = matrix.transpose(output);\n\telse if (direction == 'left') output = matrix.reverseColumns(output);\n\telse if (direction == 'up') output = matrix.reverseRows(matrix.transpose(output));\n\t\n\treturn model.spillValues({\n\t\tcell: model.getCellByRange(autofillRange.bounds[0][0]),\n\t\tvalues: output, \n\t\tpropertyCell: model.getCellByRange(selectedRange.bounds[0][0]),\n\t\tdisplayValues: displayValueMatrix\n\t});\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditions.d.ts","sourceRoot":"","sources":["../../src/calculations/conditions.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAC,MAAM,CAAC;AAEtC,wBAAgB,aAAa,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,GAAI,MAAM,CASvD;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,WAoBjE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { utils } from "@omegagrid/core";
|
|
3
|
+
export function scalarCompare(s1, s2) {
|
|
4
|
+
if ((isNaN(s1) || s1 == null) && (isNaN(s2) || s2 == null)) {
|
|
5
|
+
s1 = s1 == null ? '' : utils.removeAccents(s1.toString()).toLowerCase();
|
|
6
|
+
s2 = s2 == null ? '' : utils.removeAccents(s2.toString()).toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
if (s1 > s2)
|
|
9
|
+
return 1;
|
|
10
|
+
if (s1 < s2)
|
|
11
|
+
return -1;
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
export function evalCondition(condition, value) {
|
|
15
|
+
const isStringValue = utils.isString(value);
|
|
16
|
+
if (utils.isString(condition)) {
|
|
17
|
+
condition = condition.toString().trim();
|
|
18
|
+
if (condition.startsWith('=')) {
|
|
19
|
+
return scalarCompare(value, isStringValue ? condition.substring(1) : parseFloat(condition.substring(1))) == 0;
|
|
20
|
+
}
|
|
21
|
+
else if (condition.startsWith('>=')) {
|
|
22
|
+
return scalarCompare(value, isStringValue ? condition.substring(2) : parseFloat(condition.substring(2))) >= 0;
|
|
23
|
+
}
|
|
24
|
+
else if (condition.startsWith('<=')) {
|
|
25
|
+
return scalarCompare(value, isStringValue ? condition.substring(2) : parseFloat(condition.substring(2))) <= 0;
|
|
26
|
+
}
|
|
27
|
+
else if (condition.startsWith('>')) {
|
|
28
|
+
return scalarCompare(value, isStringValue ? condition.substring(1) : parseFloat(condition.substring(1))) > 0;
|
|
29
|
+
}
|
|
30
|
+
else if (condition.startsWith('<')) {
|
|
31
|
+
return scalarCompare(value, isStringValue ? condition.substring(1) : parseFloat(condition.substring(1))) < 0;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return scalarCompare(value, isStringValue ? condition : (isNaN(condition) ? (condition || '') : parseFloat(condition))) == 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return value == condition;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=conditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../../src/calculations/conditions.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,MAAM,UAAU,aAAa,CAAC,EAAO,EAAE,EAAO;IAC7C,IAAI,CAAC,KAAK,CAAC,EAAY,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAY,CAAC,IAAI,EAAE,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\n\nimport { utils } from \"@omegagrid/core\";\n\nexport type Condition = string|number;\n\nexport function scalarCompare(s1: any, s2: any) : number {\n\tif ((isNaN(s1 as number) || s1 == null) && (isNaN(s2 as number) || s2 == null)) {\n\t\ts1 = s1 == null ? '' : utils.removeAccents(s1.toString()).toLowerCase();\n\t\ts2 = s2 == null ? '' : utils.removeAccents(s2.toString()).toLowerCase();\n\t}\n\n\tif (s1 > s2) return 1;\n\tif (s1 < s2) return -1;\n\treturn 0;\n}\n\nexport function evalCondition(condition: Condition, value: unknown) {\n\tconst isStringValue = utils.isString(value);\n\tif (utils.isString(condition)) {\n\t\tcondition = condition.toString().trim();\n\t\tif (condition.startsWith('=')) {\n\t\t\treturn scalarCompare(value, isStringValue ? condition.substring(1) : parseFloat(condition.substring(1))) == 0;\n\t\t} else if (condition.startsWith('>=')) {\n\t\t\treturn scalarCompare(value, isStringValue ? condition.substring(2) : parseFloat(condition.substring(2))) >= 0;\n\t\t} else if (condition.startsWith('<=')) {\n\t\t\treturn scalarCompare(value, isStringValue ? condition.substring(2) : parseFloat(condition.substring(2))) <= 0;\n\t\t} else if (condition.startsWith('>')) {\n\t\t\treturn scalarCompare(value, isStringValue ? condition.substring(1) : parseFloat(condition.substring(1))) > 0;\n\t\t} else if (condition.startsWith('<')) {\n\t\t\treturn scalarCompare(value, isStringValue ? condition.substring(1) : parseFloat(condition.substring(1))) < 0;\n\t\t} else {\n\t\t\treturn scalarCompare(value, isStringValue ? condition : (isNaN(condition as unknown as number) ? (condition || '') : parseFloat(condition))) == 0;\n\t\t}\n\t} else {\n\t\treturn value == condition;\n\t}\n}"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Matrix } from "@omegagrid/core";
|
|
2
|
+
import { RangeAddress } from "../common";
|
|
3
|
+
import { CellModel, GridModel } from "../model";
|
|
4
|
+
import { Operator } from "./operators";
|
|
5
|
+
export declare class CalculationContext {
|
|
6
|
+
readonly model: GridModel;
|
|
7
|
+
currentCell: CellModel;
|
|
8
|
+
constructor(model: GridModel);
|
|
9
|
+
getModel: (sheet: string) => GridModel;
|
|
10
|
+
/**
|
|
11
|
+
* Returns cell value
|
|
12
|
+
* @param a1 cell addres
|
|
13
|
+
* @param sheet sheet name
|
|
14
|
+
* @returns cell value
|
|
15
|
+
*/
|
|
16
|
+
cl: (a1?: RangeAddress, sheet?: string) => unknown;
|
|
17
|
+
/**
|
|
18
|
+
* Returns range value matrix
|
|
19
|
+
* @param a1 cell addres
|
|
20
|
+
* @param sheet sheet name
|
|
21
|
+
* @returns cell value matrix
|
|
22
|
+
*/
|
|
23
|
+
rn: (a1: RangeAddress, sheet?: string) => Matrix<unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Returns cell value by range name
|
|
26
|
+
* @param name range (cell) name
|
|
27
|
+
* @param sheet sheet name
|
|
28
|
+
* @returns cell value
|
|
29
|
+
*/
|
|
30
|
+
nv: (name: string, sheet?: string) => unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Returns cell value matrix for named range
|
|
33
|
+
* @param a1 range address
|
|
34
|
+
* @param sheet sheet name
|
|
35
|
+
* @returns cell value matrix
|
|
36
|
+
*/
|
|
37
|
+
nr: (name: string, sheet?: string) => unknown;
|
|
38
|
+
/**
|
|
39
|
+
* returns formula function
|
|
40
|
+
* @param name function name
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
fn: (name: string) => import("..").FormulaFunction;
|
|
44
|
+
/**
|
|
45
|
+
* Performs matrix operation
|
|
46
|
+
* @param operand1
|
|
47
|
+
* @param operand2
|
|
48
|
+
* @param operator
|
|
49
|
+
* @return value
|
|
50
|
+
*/
|
|
51
|
+
op: (operand1: Matrix, operand2: Matrix, operator: Operator) => Matrix;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/calculations/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAa,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAmB,MAAM,aAAa,CAAC;AAExD,qBAAa,kBAAkB;aAIF,KAAK,EAAE,SAAS;IAF5C,WAAW,EAAE,SAAS,CAAC;gBAEK,KAAK,EAAE,SAAS;IAE5C,QAAQ,GAAI,OAAO,MAAM,eAIxB;IAED;;;;;OAKG;IACH,EAAE,GAAI,KAAK,YAAY,EAAE,QAAQ,MAAM,KAAG,OAAO,CAY/C;IAEF;;;;;OAKG;IACH,EAAE,GAAI,IAAI,YAAY,EAAE,QAAQ,MAAM,qBAGrC;IAED;;;;;OAKG;IACH,EAAE,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAE1C;IAEF;;;;;OAKG;IACH,EAAE,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAK1C;IAEF;;;;OAIG;IACH,EAAE,GAAI,MAAM,MAAM,kCAIhB;IAEF;;;;;;OAMG;IACH,EAAE,GAAI,UAAU,MAAM,EAAE,UAAU,MAAM,EAAE,UAAU,QAAQ,KAAG,MAAM,CAEpE;CACD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { CellRange } from "../common";
|
|
2
|
+
import { _map } from "./functions";
|
|
3
|
+
import { matrixOperation } from "./operators";
|
|
4
|
+
export class CalculationContext {
|
|
5
|
+
constructor(model) {
|
|
6
|
+
this.model = model;
|
|
7
|
+
this.getModel = (sheet) => {
|
|
8
|
+
const m = sheet ? this.model.getConnectedModel(sheet) : this.model;
|
|
9
|
+
if (m)
|
|
10
|
+
return m;
|
|
11
|
+
throw new Error(`Sheet "${sheet}" not found`);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns cell value
|
|
15
|
+
* @param a1 cell addres
|
|
16
|
+
* @param sheet sheet name
|
|
17
|
+
* @returns cell value
|
|
18
|
+
*/
|
|
19
|
+
this.cl = (a1, sheet) => {
|
|
20
|
+
const m = this.getModel(sheet);
|
|
21
|
+
if (a1 == null)
|
|
22
|
+
return this.currentCell.value;
|
|
23
|
+
const cell = m.getCellByA1(a1);
|
|
24
|
+
if (!cell) {
|
|
25
|
+
this.currentCell.error = { message: `undefined cell ${a1}` };
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return cell.value;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Returns range value matrix
|
|
32
|
+
* @param a1 cell addres
|
|
33
|
+
* @param sheet sheet name
|
|
34
|
+
* @returns cell value matrix
|
|
35
|
+
*/
|
|
36
|
+
this.rn = (a1, sheet) => {
|
|
37
|
+
const m = this.getModel(sheet);
|
|
38
|
+
return m.getValuesInRange(CellRange.fromA1(a1));
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Returns cell value by range name
|
|
42
|
+
* @param name range (cell) name
|
|
43
|
+
* @param sheet sheet name
|
|
44
|
+
* @returns cell value
|
|
45
|
+
*/
|
|
46
|
+
this.nv = (name, sheet) => {
|
|
47
|
+
return this.getModel(sheet).getCellByName(name, this.currentCell.range).value;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Returns cell value matrix for named range
|
|
51
|
+
* @param a1 range address
|
|
52
|
+
* @param sheet sheet name
|
|
53
|
+
* @returns cell value matrix
|
|
54
|
+
*/
|
|
55
|
+
this.nr = (name, sheet) => {
|
|
56
|
+
const m = this.getModel(sheet);
|
|
57
|
+
const matrix = m.getValueMatrixByName(name);
|
|
58
|
+
if (matrix.length === 1 && matrix[0].length === 1)
|
|
59
|
+
return matrix[0][0];
|
|
60
|
+
return matrix;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* returns formula function
|
|
64
|
+
* @param name function name
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
this.fn = (name) => {
|
|
68
|
+
const fn = _map.get(name);
|
|
69
|
+
if (fn)
|
|
70
|
+
return fn;
|
|
71
|
+
throw new Error(`Function "${name}" not found`);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Performs matrix operation
|
|
75
|
+
* @param operand1
|
|
76
|
+
* @param operand2
|
|
77
|
+
* @param operator
|
|
78
|
+
* @return value
|
|
79
|
+
*/
|
|
80
|
+
this.op = (operand1, operand2, operator) => {
|
|
81
|
+
return matrixOperation(operand1, operand2, operator);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/calculations/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAgB,MAAM,WAAW,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,OAAO,kBAAkB;IAI9B,YAA4B,KAAgB;QAAhB,UAAK,GAAL,KAAK,CAAW;QAE5C,aAAQ,GAAG,CAAC,KAAa,EAAE,EAAE;YAC5B,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YACnE,IAAI,CAAC;gBAAE,OAAO,CAAC,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,aAAa,CAAC,CAAA;QAC9C,CAAC,CAAA;QAED;;;;;WAKG;QACH,OAAE,GAAG,CAAC,EAAiB,EAAE,KAAc,EAAW,EAAE;YACnD,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,EAAE,IAAI,IAAI;gBAAE,OAAO,IAAI,CA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Y,EAAE,EAAE;YACrB,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC1B,IAAI,EAAE;gBAAE,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,aAAa,CAAC,CAAC;QACjD,CAAC,CAAC;QAEF;;;;;;WAMG;QACH,OAAE,GAAG,CAAC,QAAgB,EAAE,QAAgB,EAAE,QAAkB,EAAU,EAAE;YACvE,OAAO,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAA;IAlF+C,CAAC;CAmFjD","sourcesContent":["import { Matrix } from \"@omegagrid/core\";\nimport { CellRange, RangeAddress } from \"../common\";\nimport { CellModel, GridModel } from \"../model\";\nimport { _map } from \"./functions\";\nimport { Operator, matrixOperation } from \"./operators\";\n\nexport class CalculationContext {\n\n\tcurrentCell: CellModel;\n\n\tconstructor(public readonly model: GridModel) { }\n\n\tgetModel = (sheet: string) => {\n\t\tconst m = sheet ? this.model.getConnectedModel(sheet) : this.model;\n\t\tif (m) return m;\n\t\tthrow new Error(`Sheet \"${sheet}\" not found`)\n\t}\n\n\t/**\n\t * Returns cell value\n\t * @param a1 cell addres\n\t * @param sheet sheet name\n\t * @returns cell value\n\t */\n\tcl = (a1?: RangeAddress, sheet?: string): unknown => {\n\t\tconst m = this.getModel(sheet);\n\t\tif (a1 == null) return this.currentCell.value;\n\n\t\tconst cell = m.getCellByA1(a1);\n\n\t\tif (!cell) {\n\t\t\tthis.currentCell.error = {message: `undefined cell ${a1}`};\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\treturn cell.value;\n\t};\n\n\t/**\n\t * Returns range value matrix\n\t * @param a1 cell addres\n\t * @param sheet sheet name\n\t * @returns cell value matrix\n\t */\n\trn = (a1: RangeAddress, sheet?: string) => {\n\t\tconst m = this.getModel(sheet);\n\t\treturn m.getValuesInRange(CellRange.fromA1(a1));\n\t}\n\t\n\t/**\n\t * Returns cell value by range name\n\t * @param name range (cell) name\n\t * @param sheet sheet name\n\t * @returns cell value\n\t */\n\tnv = (name: string, sheet?: string): unknown => {\n\t\treturn this.getModel(sheet).getCellByName(name, this.currentCell.range).value;\n\t};\n\n\t/**\n\t * Returns cell value matrix for named range\n\t * @param a1 range address\n\t * @param sheet sheet name\n\t * @returns cell value matrix\n\t */\n\tnr = (name: string, sheet?: string): unknown => {\n\t\tconst m = this.getModel(sheet);\n\t\tconst matrix = m.getValueMatrixByName(name);\n\t\tif (matrix.length === 1 && matrix[0].length === 1) return matrix[0][0];\n\t\treturn matrix;\n\t};\n\n\t/**\n\t * returns formula function\n\t * @param name function name\n\t * @returns \n\t */\n\tfn = (name: string) => {\n\t\tconst fn = _map.get(name);\n\t\tif (fn) return fn;\n\t\tthrow new Error(`Function \"${name}\" not found`);\n\t};\n\n\t/**\n\t * Performs matrix operation\n\t * @param operand1\n\t * @param operand2\n\t * @param operator\n\t * @return value\n\t */\n\top = (operand1: Matrix, operand2: Matrix, operator: Operator): Matrix => {\n\t\treturn matrixOperation(operand1, operand2, operator);\n\t}\n}"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Token, Tokenizer, TokenType } from "./tokenization";
|
|
2
|
+
import { FormulaFunction, ShiftOptions } from '../types';
|
|
3
|
+
import { CellRange } from "../common";
|
|
4
|
+
import { CellModel } from "../model";
|
|
5
|
+
export type FormulaString = string;
|
|
6
|
+
export type FormulaContext = {
|
|
7
|
+
cell: CellModel;
|
|
8
|
+
formula: Formula;
|
|
9
|
+
};
|
|
10
|
+
export type FormulaColorItem = {
|
|
11
|
+
color: string;
|
|
12
|
+
address: string;
|
|
13
|
+
sheet?: string;
|
|
14
|
+
type: TokenType;
|
|
15
|
+
tokenIndex: number;
|
|
16
|
+
};
|
|
17
|
+
type ExpressionNode = {
|
|
18
|
+
/** token */
|
|
19
|
+
t: string;
|
|
20
|
+
/** token type */
|
|
21
|
+
tt: TokenType;
|
|
22
|
+
/** sheet */
|
|
23
|
+
s?: string;
|
|
24
|
+
/** children */
|
|
25
|
+
c?: ExpressionNode[];
|
|
26
|
+
};
|
|
27
|
+
export declare const isFormula: (value: string) => boolean;
|
|
28
|
+
export declare const prefixFormula: (value: string) => string;
|
|
29
|
+
export declare const stripFormulaPrefix: (value: string) => string;
|
|
30
|
+
export declare class Formula {
|
|
31
|
+
private expression;
|
|
32
|
+
readonly tokenizer: Tokenizer;
|
|
33
|
+
private _formula;
|
|
34
|
+
private _xlFormula;
|
|
35
|
+
private _variables;
|
|
36
|
+
private _cells;
|
|
37
|
+
private _ranges;
|
|
38
|
+
private _fn;
|
|
39
|
+
get fn(): FormulaFunction;
|
|
40
|
+
private _tokens;
|
|
41
|
+
get tokens(): Token[];
|
|
42
|
+
get variables(): [number, string, string?][];
|
|
43
|
+
get cells(): [number, CellRange, string?][];
|
|
44
|
+
get ranges(): [number, CellRange, string?][];
|
|
45
|
+
private _colors;
|
|
46
|
+
get colors(): Map<string, FormulaColorItem>;
|
|
47
|
+
constructor(expression: FormulaString, tokenizer: Tokenizer);
|
|
48
|
+
findTokenIndexAtPosition(pos: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Finds sheet token for the given reange token index
|
|
51
|
+
*
|
|
52
|
+
* @param tokenIndex
|
|
53
|
+
*/
|
|
54
|
+
findSheetTokenIndex(tokenIndex: number): number;
|
|
55
|
+
/**
|
|
56
|
+
* Removes sheet token for the given token index (range or sheet itself)
|
|
57
|
+
* @param tokenIndex
|
|
58
|
+
* @returns number of tokens removed
|
|
59
|
+
*/
|
|
60
|
+
removeSheetToken(tokenIndex: number): number;
|
|
61
|
+
getNamedColor(name: string): string;
|
|
62
|
+
getTokenPosition(index: number): {
|
|
63
|
+
min: number;
|
|
64
|
+
max: number;
|
|
65
|
+
};
|
|
66
|
+
updateToken(index: number, newValue: string): void;
|
|
67
|
+
removeToken(index: number): void;
|
|
68
|
+
/**
|
|
69
|
+
* Inserts a new token at the given index
|
|
70
|
+
* @param index
|
|
71
|
+
* @param value
|
|
72
|
+
* @param type
|
|
73
|
+
* @returns number of inserted tokens
|
|
74
|
+
*/
|
|
75
|
+
insertToken(index: number, value: string, type: TokenType): number;
|
|
76
|
+
clone(): Formula;
|
|
77
|
+
updateDependecies(): void;
|
|
78
|
+
createFormulaString(html?: boolean, fnPrefixes?: boolean): string;
|
|
79
|
+
createExpressionTree(): ExpressionNode;
|
|
80
|
+
createExpressionJSCode(node: ExpressionNode, parent?: ExpressionNode, arrayMode?: boolean): string;
|
|
81
|
+
compile(): string;
|
|
82
|
+
toString(prefix?: boolean): string;
|
|
83
|
+
toExcelString(): string;
|
|
84
|
+
shift(options: ShiftOptions): this;
|
|
85
|
+
hasSheetReference(sheet: string): boolean;
|
|
86
|
+
renameSheet(oldName: string, newName: string): boolean;
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=formula.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formula.d.ts","sourceRoot":"","sources":["../../src/calculations/formula.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIrC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,MAAM,CA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