@gridsheet/react-core 1.4.0-alpha.2 → 1.4.0-alpha.3
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/_virtual/_commonjsHelpers.js +7 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/dayjs.min.js +8 -0
- package/dist/_virtual/dayjs.min.js.map +1 -0
- package/dist/_virtual/dayjs.min2.js +5 -0
- package/dist/_virtual/dayjs.min2.js.map +1 -0
- package/dist/_virtual/jsx-runtime.js +6 -0
- package/dist/_virtual/jsx-runtime.js.map +1 -0
- package/dist/_virtual/jsx-runtime2.js +5 -0
- package/dist/_virtual/jsx-runtime2.js.map +1 -0
- package/dist/_virtual/react-jsx-runtime.development.js +5 -0
- package/dist/_virtual/react-jsx-runtime.development.js.map +1 -0
- package/dist/_virtual/react-jsx-runtime.production.js +5 -0
- package/dist/_virtual/react-jsx-runtime.production.js.map +1 -0
- package/dist/_virtual/timezone.js +8 -0
- package/dist/_virtual/timezone.js.map +1 -0
- package/dist/_virtual/timezone2.js +5 -0
- package/dist/_virtual/timezone2.js.map +1 -0
- package/dist/_virtual/utc.js +8 -0
- package/dist/_virtual/utc.js.map +1 -0
- package/dist/_virtual/utc2.js +5 -0
- package/dist/_virtual/utc2.js.map +1 -0
- package/dist/components/Cell.js +232 -0
- package/dist/components/Cell.js.map +1 -0
- package/dist/components/ContextMenu.js +297 -0
- package/dist/components/ContextMenu.js.map +1 -0
- package/dist/components/Editor.js +455 -0
- package/dist/components/Editor.js.map +1 -0
- package/dist/components/Emitter.js +26 -0
- package/dist/components/Emitter.js.map +1 -0
- package/dist/components/Fixed.js +17 -0
- package/dist/components/Fixed.js.map +1 -0
- package/dist/components/FormulaBar.js +149 -0
- package/dist/components/FormulaBar.js.map +1 -0
- package/dist/components/GridSheet.js +246 -0
- package/dist/components/GridSheet.js.map +1 -0
- package/dist/components/HeaderCellLeft.js +131 -0
- package/dist/components/HeaderCellLeft.js.map +1 -0
- package/dist/components/HeaderCellTop.js +132 -0
- package/dist/components/HeaderCellTop.js.map +1 -0
- package/dist/components/PluginBase.js +35 -0
- package/dist/components/PluginBase.js.map +1 -0
- package/dist/components/Resizer.js +98 -0
- package/dist/components/Resizer.js.map +1 -0
- package/dist/components/SearchBar.js +108 -0
- package/dist/components/SearchBar.js.map +1 -0
- package/dist/components/SheetProvider.js +56 -0
- package/dist/components/SheetProvider.js.map +1 -0
- package/dist/components/StoreInitializer.js +84 -0
- package/dist/components/StoreInitializer.js.map +1 -0
- package/dist/components/Tabular.js +308 -0
- package/dist/components/Tabular.js.map +1 -0
- package/dist/components/hooks.js +15 -0
- package/dist/components/hooks.js.map +1 -0
- package/dist/components/svg/Base.js +24 -0
- package/dist/components/svg/Base.js.map +1 -0
- package/dist/components/svg/CloseIcon.js +13 -0
- package/dist/components/svg/CloseIcon.js.map +1 -0
- package/dist/components/svg/SearchIcon.js +13 -0
- package/dist/components/svg/SearchIcon.js.map +1 -0
- package/dist/constants.js +43 -0
- package/dist/constants.js.map +1 -0
- package/dist/formula/evaluator.js +674 -0
- package/dist/formula/evaluator.js.map +1 -0
- package/dist/formula/functions/__base.js +19 -0
- package/dist/formula/functions/__base.js.map +1 -0
- package/dist/formula/functions/__utils.js +145 -0
- package/dist/formula/functions/__utils.js.map +1 -0
- package/dist/formula/functions/abs.js +24 -0
- package/dist/formula/functions/abs.js.map +1 -0
- package/dist/formula/functions/acos.js +32 -0
- package/dist/formula/functions/acos.js.map +1 -0
- package/dist/formula/functions/add.js +57 -0
- package/dist/formula/functions/add.js.map +1 -0
- package/dist/formula/functions/and.js +28 -0
- package/dist/formula/functions/and.js.map +1 -0
- package/dist/formula/functions/asin.js +32 -0
- package/dist/formula/functions/asin.js.map +1 -0
- package/dist/formula/functions/atan.js +29 -0
- package/dist/formula/functions/atan.js.map +1 -0
- package/dist/formula/functions/atan2.js +35 -0
- package/dist/formula/functions/atan2.js.map +1 -0
- package/dist/formula/functions/average.js +44 -0
- package/dist/formula/functions/average.js.map +1 -0
- package/dist/formula/functions/col.js +31 -0
- package/dist/formula/functions/col.js.map +1 -0
- package/dist/formula/functions/concat.js +27 -0
- package/dist/formula/functions/concat.js.map +1 -0
- package/dist/formula/functions/concatenate.js +28 -0
- package/dist/formula/functions/concatenate.js.map +1 -0
- package/dist/formula/functions/cos.js +29 -0
- package/dist/formula/functions/cos.js.map +1 -0
- package/dist/formula/functions/count.js +38 -0
- package/dist/formula/functions/count.js.map +1 -0
- package/dist/formula/functions/counta.js +38 -0
- package/dist/formula/functions/counta.js.map +1 -0
- package/dist/formula/functions/countif.js +32 -0
- package/dist/formula/functions/countif.js.map +1 -0
- package/dist/formula/functions/divide.js +33 -0
- package/dist/formula/functions/divide.js.map +1 -0
- package/dist/formula/functions/eq.js +29 -0
- package/dist/formula/functions/eq.js.map +1 -0
- package/dist/formula/functions/exp.js +29 -0
- package/dist/formula/functions/exp.js.map +1 -0
- package/dist/formula/functions/gt.js +29 -0
- package/dist/formula/functions/gt.js.map +1 -0
- package/dist/formula/functions/gte.js +29 -0
- package/dist/formula/functions/gte.js.map +1 -0
- package/dist/formula/functions/hlookup.js +75 -0
- package/dist/formula/functions/hlookup.js.map +1 -0
- package/dist/formula/functions/if.js +39 -0
- package/dist/formula/functions/if.js.map +1 -0
- package/dist/formula/functions/iferror.js +45 -0
- package/dist/formula/functions/iferror.js.map +1 -0
- package/dist/formula/functions/len.js +29 -0
- package/dist/formula/functions/len.js.map +1 -0
- package/dist/formula/functions/lenb.js +29 -0
- package/dist/formula/functions/lenb.js.map +1 -0
- package/dist/formula/functions/ln.js +32 -0
- package/dist/formula/functions/ln.js.map +1 -0
- package/dist/formula/functions/log.js +36 -0
- package/dist/formula/functions/log.js.map +1 -0
- package/dist/formula/functions/log10.js +32 -0
- package/dist/formula/functions/log10.js.map +1 -0
- package/dist/formula/functions/lt.js +29 -0
- package/dist/formula/functions/lt.js.map +1 -0
- package/dist/formula/functions/lte.js +29 -0
- package/dist/formula/functions/lte.js.map +1 -0
- package/dist/formula/functions/max.js +47 -0
- package/dist/formula/functions/max.js.map +1 -0
- package/dist/formula/functions/min.js +47 -0
- package/dist/formula/functions/min.js.map +1 -0
- package/dist/formula/functions/minus.js +57 -0
- package/dist/formula/functions/minus.js.map +1 -0
- package/dist/formula/functions/mod.js +33 -0
- package/dist/formula/functions/mod.js.map +1 -0
- package/dist/formula/functions/multiply.js +27 -0
- package/dist/formula/functions/multiply.js.map +1 -0
- package/dist/formula/functions/ne.js +29 -0
- package/dist/formula/functions/ne.js.map +1 -0
- package/dist/formula/functions/not.js +30 -0
- package/dist/formula/functions/not.js.map +1 -0
- package/dist/formula/functions/now.js +22 -0
- package/dist/formula/functions/now.js.map +1 -0
- package/dist/formula/functions/or.js +28 -0
- package/dist/formula/functions/or.js.map +1 -0
- package/dist/formula/functions/pi.js +22 -0
- package/dist/formula/functions/pi.js.map +1 -0
- package/dist/formula/functions/power.js +27 -0
- package/dist/formula/functions/power.js.map +1 -0
- package/dist/formula/functions/product.js +40 -0
- package/dist/formula/functions/product.js.map +1 -0
- package/dist/formula/functions/radians.js +29 -0
- package/dist/formula/functions/radians.js.map +1 -0
- package/dist/formula/functions/rand.js +22 -0
- package/dist/formula/functions/rand.js.map +1 -0
- package/dist/formula/functions/round.js +35 -0
- package/dist/formula/functions/round.js.map +1 -0
- package/dist/formula/functions/rounddown.js +35 -0
- package/dist/formula/functions/rounddown.js.map +1 -0
- package/dist/formula/functions/roundup.js +35 -0
- package/dist/formula/functions/roundup.js.map +1 -0
- package/dist/formula/functions/row.js +31 -0
- package/dist/formula/functions/row.js.map +1 -0
- package/dist/formula/functions/sin.js +29 -0
- package/dist/formula/functions/sin.js.map +1 -0
- package/dist/formula/functions/sqrt.js +32 -0
- package/dist/formula/functions/sqrt.js.map +1 -0
- package/dist/formula/functions/sum.js +47 -0
- package/dist/formula/functions/sum.js.map +1 -0
- package/dist/formula/functions/sumif.js +65 -0
- package/dist/formula/functions/sumif.js.map +1 -0
- package/dist/formula/functions/tan.js +29 -0
- package/dist/formula/functions/tan.js.map +1 -0
- package/dist/formula/functions/uminus.js +24 -0
- package/dist/formula/functions/uminus.js.map +1 -0
- package/dist/formula/functions/vlookup.js +75 -0
- package/dist/formula/functions/vlookup.js.map +1 -0
- package/dist/formula/mapping.js +118 -0
- package/dist/formula/mapping.js.map +1 -0
- package/dist/formula/solver.js +70 -0
- package/dist/formula/solver.js.map +1 -0
- package/dist/index.js +16 -9113
- package/dist/index.js.map +1 -1
- package/dist/lib/autofill.js +391 -0
- package/dist/lib/autofill.js.map +1 -0
- package/dist/lib/clipboard.js +46 -0
- package/dist/lib/clipboard.js.map +1 -0
- package/dist/lib/converters.js +141 -0
- package/dist/lib/converters.js.map +1 -0
- package/dist/lib/input.js +52 -0
- package/dist/lib/input.js.map +1 -0
- package/dist/lib/palette.js +24 -0
- package/dist/lib/palette.js.map +1 -0
- package/dist/lib/prevention.js +82 -0
- package/dist/lib/prevention.js.map +1 -0
- package/dist/lib/structs.js +276 -0
- package/dist/lib/structs.js.map +1 -0
- package/dist/lib/table.js +1248 -0
- package/dist/lib/table.js.map +1 -0
- package/dist/lib/time.js +79 -0
- package/dist/lib/time.js.map +1 -0
- package/dist/lib/virtualization.js +129 -0
- package/dist/lib/virtualization.js.map +1 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js +287 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js.map +1 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/timezone.js +72 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/timezone.js.map +1 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/utc.js +85 -0
- package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/utc.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +454 -0
- package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +42 -0
- package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +18 -0
- package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js.map +1 -0
- package/dist/parsers/core.js +139 -0
- package/dist/parsers/core.js.map +1 -0
- package/dist/renderers/checkbox.js +20 -0
- package/dist/renderers/checkbox.js.map +1 -0
- package/dist/renderers/core.js +147 -0
- package/dist/renderers/core.js.map +1 -0
- package/dist/renderers/thousand_separator.js +17 -0
- package/dist/renderers/thousand_separator.js.map +1 -0
- package/dist/store/actions.js +762 -0
- package/dist/store/actions.js.map +1 -0
- package/dist/store/helpers.js +88 -0
- package/dist/store/helpers.js.map +1 -0
- package/dist/store/index.js +8 -0
- package/dist/store/index.js.map +1 -0
- package/dist/styles/embedder.js +19 -0
- package/dist/styles/embedder.js.map +1 -0
- package/dist/styles/minified.js +7 -0
- package/dist/styles/minified.js.map +1 -0
- package/package.json +1 -7
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { FormulaError } from "../evaluator.js";
|
|
2
|
+
import { solveTable } from "../solver.js";
|
|
3
|
+
import { Table } from "../../lib/table.js";
|
|
4
|
+
import { BaseFunction } from "./__base.js";
|
|
5
|
+
import { stripTable, ensureNumber, ensureBoolean } from "./__utils.js";
|
|
6
|
+
class VlookupFunction extends BaseFunction {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.example = "VLOOKUP(10003, A2:B26, 2, FALSE)";
|
|
10
|
+
this.helpText = [
|
|
11
|
+
"Searches vertically for the specified key in the first column of the range and returns the value of the specified cell in the same row."
|
|
12
|
+
];
|
|
13
|
+
this.helpArgs = [
|
|
14
|
+
{ name: "key", description: "Search key." },
|
|
15
|
+
{
|
|
16
|
+
name: "range",
|
|
17
|
+
description: "A range for search"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "index",
|
|
21
|
+
description: "The index of the column in the range."
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "is_sorted",
|
|
25
|
+
description: "FALSE: Exact match. This is recommended. TRUE: Approximate match. Before you use an approximate match, sort your search key in ascending order. Otherwise, you may likely get a wrong return value.",
|
|
26
|
+
option: true
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
validate() {
|
|
31
|
+
if (this.bareArgs.length !== 3 && this.bareArgs.length !== 4) {
|
|
32
|
+
throw new FormulaError("#N/A", "Number of arguments for VLOOKUP is incorrect.");
|
|
33
|
+
}
|
|
34
|
+
if (this.bareArgs[0] instanceof Table) {
|
|
35
|
+
this.bareArgs[0] = stripTable(this.bareArgs[0]);
|
|
36
|
+
}
|
|
37
|
+
if (!(this.bareArgs[1] instanceof Table)) {
|
|
38
|
+
throw new FormulaError("#REF!", "2nd argument must be range");
|
|
39
|
+
}
|
|
40
|
+
this.bareArgs[2] = ensureNumber(this.bareArgs[2]);
|
|
41
|
+
this.bareArgs[3] = ensureBoolean(this.bareArgs[3], true);
|
|
42
|
+
}
|
|
43
|
+
main(key, range, index, isSorted) {
|
|
44
|
+
var _a, _b, _c, _d;
|
|
45
|
+
const matrix = solveTable({ table: range });
|
|
46
|
+
if (isSorted) {
|
|
47
|
+
let last = -1;
|
|
48
|
+
for (let y = 0; y <= range.getNumRows(); y++) {
|
|
49
|
+
const v = (_a = matrix[y]) == null ? void 0 : _a[0];
|
|
50
|
+
if (v == null) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (v <= key) {
|
|
54
|
+
last = y;
|
|
55
|
+
} else {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (last !== -1) {
|
|
60
|
+
return (_b = matrix[last]) == null ? void 0 : _b[index - 1];
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
for (let y = 0; y <= range.getNumRows(); y++) {
|
|
64
|
+
if (((_c = matrix[y]) == null ? void 0 : _c[0]) === key) {
|
|
65
|
+
return (_d = matrix[y]) == null ? void 0 : _d[index - 1];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
throw new FormulaError("#N/A", `No values found for '${key}'.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
VlookupFunction
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=vlookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vlookup.js","sources":["../../../formula/functions/vlookup.ts"],"sourcesContent":["import { FormulaError } from '../evaluator';\nimport { solveTable } from '../solver';\nimport { Table } from '../../lib/table';\nimport { BaseFunction } from './__base';\nimport { ensureBoolean, ensureNumber, stripTable } from './__utils';\n\nexport class VlookupFunction extends BaseFunction {\n example = 'VLOOKUP(10003, A2:B26, 2, FALSE)';\n helpText = [\n 'Searches vertically for the specified key in the first column of the range and returns the value of the specified cell in the same row.',\n ];\n helpArgs = [\n { name: 'key', description: 'Search key.' },\n {\n name: 'range',\n description: 'A range for search',\n },\n {\n name: 'index',\n description: 'The index of the column in the range.',\n },\n {\n name: 'is_sorted',\n description:\n 'FALSE: Exact match. This is recommended. TRUE: Approximate match. Before you use an approximate match, sort your search key in ascending order. Otherwise, you may likely get a wrong return value.',\n option: true,\n },\n ];\n\n protected validate() {\n if (this.bareArgs.length !== 3 && this.bareArgs.length !== 4) {\n throw new FormulaError('#N/A', 'Number of arguments for VLOOKUP is incorrect.');\n }\n if (this.bareArgs[0] instanceof Table) {\n this.bareArgs[0] = stripTable(this.bareArgs[0]);\n }\n if (!(this.bareArgs[1] instanceof Table)) {\n throw new FormulaError('#REF!', '2nd argument must be range');\n }\n this.bareArgs[2] = ensureNumber(this.bareArgs[2]);\n this.bareArgs[3] = ensureBoolean(this.bareArgs[3], true);\n }\n\n protected main(key: any, range: Table, index: number, isSorted: boolean) {\n const matrix = solveTable({ table: range });\n if (isSorted) {\n let last = -1;\n for (let y = 0; y <= range.getNumRows(); y++) {\n const v = matrix[y]?.[0];\n if (v == null) {\n continue;\n }\n if (v <= key) {\n last = y;\n } else {\n break;\n }\n }\n if (last !== -1) {\n return matrix[last]?.[index - 1];\n }\n } else {\n for (let y = 0; y <= range.getNumRows(); y++) {\n if (matrix[y]?.[0] === key) {\n return matrix[y]?.[index - 1];\n }\n }\n }\n throw new FormulaError('#N/A', `No values found for '${key}'.`);\n }\n}\n"],"names":[],"mappings":";;;;;AAMO,MAAM,wBAAwB,aAAa;AAAA,EAA3C,cAAA;AAAA,UAAA,GAAA,SAAA;AACK,SAAA,UAAA;AACC,SAAA,WAAA;AAAA,MACT;AAAA,IACF;AACW,SAAA,WAAA;AAAA,MACT,EAAE,MAAM,OAAO,aAAa,cAAc;AAAA,MAC1C;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aACE;AAAA,QACF,QAAQ;AAAA,MAAA;AAAA,IAEZ;AAAA,EAAA;AAAA,EAEU,WAAW;AACnB,QAAI,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,WAAW,GAAG;AACtD,YAAA,IAAI,aAAa,QAAQ,+CAA+C;AAAA,IAAA;AAEhF,QAAI,KAAK,SAAS,CAAC,aAAa,OAAO;AACrC,WAAK,SAAS,CAAC,IAAI,WAAW,KAAK,SAAS,CAAC,CAAC;AAAA,IAAA;AAEhD,QAAI,EAAE,KAAK,SAAS,CAAC,aAAa,QAAQ;AAClC,YAAA,IAAI,aAAa,SAAS,4BAA4B;AAAA,IAAA;AAE9D,SAAK,SAAS,CAAC,IAAI,aAAa,KAAK,SAAS,CAAC,CAAC;AAC3C,SAAA,SAAS,CAAC,IAAI,cAAc,KAAK,SAAS,CAAC,GAAG,IAAI;AAAA,EAAA;AAAA,EAG/C,KAAK,KAAU,OAAc,OAAe,UAAmB;;AACvE,UAAM,SAAS,WAAW,EAAE,OAAO,OAAO;AAC1C,QAAI,UAAU;AACZ,UAAI,OAAO;AACX,eAAS,IAAI,GAAG,KAAK,MAAM,WAAA,GAAc,KAAK;AAC5C,cAAM,KAAI,YAAO,CAAC,MAAR,mBAAY;AACtB,YAAI,KAAK,MAAM;AACb;AAAA,QAAA;AAEF,YAAI,KAAK,KAAK;AACL,iBAAA;AAAA,QAAA,OACF;AACL;AAAA,QAAA;AAAA,MACF;AAEF,UAAI,SAAS,IAAI;AACf,gBAAO,YAAO,IAAI,MAAX,mBAAe,QAAQ;AAAA,MAAC;AAAA,IACjC,OACK;AACL,eAAS,IAAI,GAAG,KAAK,MAAM,WAAA,GAAc,KAAK;AAC5C,cAAI,YAAO,CAAC,MAAR,mBAAY,QAAO,KAAK;AAC1B,kBAAO,YAAO,CAAC,MAAR,mBAAY,QAAQ;AAAA,QAAC;AAAA,MAC9B;AAAA,IACF;AAEF,UAAM,IAAI,aAAa,QAAQ,wBAAwB,GAAG,IAAI;AAAA,EAAA;AAElE;"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { AddFunction } from "./functions/add.js";
|
|
2
|
+
import { MinusFunction } from "./functions/minus.js";
|
|
3
|
+
import { MultiplyFunction } from "./functions/multiply.js";
|
|
4
|
+
import { DivideFunction } from "./functions/divide.js";
|
|
5
|
+
import { ModFunction } from "./functions/mod.js";
|
|
6
|
+
import { SumFunction } from "./functions/sum.js";
|
|
7
|
+
import { ConcatFunction } from "./functions/concat.js";
|
|
8
|
+
import { ConcatenateFunction } from "./functions/concatenate.js";
|
|
9
|
+
import { EqFunction } from "./functions/eq.js";
|
|
10
|
+
import { NeFunction } from "./functions/ne.js";
|
|
11
|
+
import { GtFunction } from "./functions/gt.js";
|
|
12
|
+
import { GteFunction } from "./functions/gte.js";
|
|
13
|
+
import { LtFunction } from "./functions/lt.js";
|
|
14
|
+
import { LteFunction } from "./functions/lte.js";
|
|
15
|
+
import { NowFunction } from "./functions/now.js";
|
|
16
|
+
import { AndFunction } from "./functions/and.js";
|
|
17
|
+
import { OrFunction } from "./functions/or.js";
|
|
18
|
+
import { IfFunction } from "./functions/if.js";
|
|
19
|
+
import { IfErrorFunction } from "./functions/iferror.js";
|
|
20
|
+
import { NotFunction } from "./functions/not.js";
|
|
21
|
+
import { CountFunction } from "./functions/count.js";
|
|
22
|
+
import { CountifFunction } from "./functions/countif.js";
|
|
23
|
+
import { SumifFunction } from "./functions/sumif.js";
|
|
24
|
+
import { VlookupFunction } from "./functions/vlookup.js";
|
|
25
|
+
import { HlookupFunction } from "./functions/hlookup.js";
|
|
26
|
+
import { LogFunction } from "./functions/log.js";
|
|
27
|
+
import { Log10Function } from "./functions/log10.js";
|
|
28
|
+
import { LnFunction } from "./functions/ln.js";
|
|
29
|
+
import { AbsFunction } from "./functions/abs.js";
|
|
30
|
+
import { ProductFunction } from "./functions/product.js";
|
|
31
|
+
import { RandFunction } from "./functions/rand.js";
|
|
32
|
+
import { PiFunction } from "./functions/pi.js";
|
|
33
|
+
import { ExpFunction } from "./functions/exp.js";
|
|
34
|
+
import { RadiansFunction } from "./functions/radians.js";
|
|
35
|
+
import { PowerFunction } from "./functions/power.js";
|
|
36
|
+
import { SqrtFunction } from "./functions/sqrt.js";
|
|
37
|
+
import { RoundFunction } from "./functions/round.js";
|
|
38
|
+
import { RoundupFunction } from "./functions/roundup.js";
|
|
39
|
+
import { RounddownFunction } from "./functions/rounddown.js";
|
|
40
|
+
import { SinFunction } from "./functions/sin.js";
|
|
41
|
+
import { CosFunction } from "./functions/cos.js";
|
|
42
|
+
import { TanFunction } from "./functions/tan.js";
|
|
43
|
+
import { AsinFunction } from "./functions/asin.js";
|
|
44
|
+
import { AcosFunction } from "./functions/acos.js";
|
|
45
|
+
import { AtanFunction } from "./functions/atan.js";
|
|
46
|
+
import { Atan2Function } from "./functions/atan2.js";
|
|
47
|
+
import { CountaFunction } from "./functions/counta.js";
|
|
48
|
+
import { AverageFunction } from "./functions/average.js";
|
|
49
|
+
import { MaxFunction } from "./functions/max.js";
|
|
50
|
+
import { MinFunction } from "./functions/min.js";
|
|
51
|
+
import { LenFunction } from "./functions/len.js";
|
|
52
|
+
import { LenbFunction } from "./functions/lenb.js";
|
|
53
|
+
import { UminusFunction } from "./functions/uminus.js";
|
|
54
|
+
import { RowFunction } from "./functions/row.js";
|
|
55
|
+
import { ColFunction } from "./functions/col.js";
|
|
56
|
+
const functions = {
|
|
57
|
+
abs: AbsFunction,
|
|
58
|
+
add: AddFunction,
|
|
59
|
+
divide: DivideFunction,
|
|
60
|
+
mod: ModFunction,
|
|
61
|
+
minus: MinusFunction,
|
|
62
|
+
uminus: UminusFunction,
|
|
63
|
+
multiply: MultiplyFunction,
|
|
64
|
+
pow: PowerFunction,
|
|
65
|
+
power: PowerFunction,
|
|
66
|
+
sqrt: SqrtFunction,
|
|
67
|
+
sum: SumFunction,
|
|
68
|
+
sumif: SumifFunction,
|
|
69
|
+
max: MaxFunction,
|
|
70
|
+
min: MinFunction,
|
|
71
|
+
average: AverageFunction,
|
|
72
|
+
count: CountFunction,
|
|
73
|
+
counta: CountaFunction,
|
|
74
|
+
countif: CountifFunction,
|
|
75
|
+
product: ProductFunction,
|
|
76
|
+
concat: ConcatFunction,
|
|
77
|
+
concatenate: ConcatenateFunction,
|
|
78
|
+
eq: EqFunction,
|
|
79
|
+
ne: NeFunction,
|
|
80
|
+
gt: GtFunction,
|
|
81
|
+
gte: GteFunction,
|
|
82
|
+
lt: LtFunction,
|
|
83
|
+
lte: LteFunction,
|
|
84
|
+
and: AndFunction,
|
|
85
|
+
or: OrFunction,
|
|
86
|
+
round: RoundFunction,
|
|
87
|
+
rounddown: RounddownFunction,
|
|
88
|
+
roundup: RoundupFunction,
|
|
89
|
+
if: IfFunction,
|
|
90
|
+
// @ts-expect-error iferror does not extends BaseFunction
|
|
91
|
+
iferror: IfErrorFunction,
|
|
92
|
+
not: NotFunction,
|
|
93
|
+
vlookup: VlookupFunction,
|
|
94
|
+
hlookup: HlookupFunction,
|
|
95
|
+
row: RowFunction,
|
|
96
|
+
col: ColFunction,
|
|
97
|
+
now: NowFunction,
|
|
98
|
+
rand: RandFunction,
|
|
99
|
+
log: LogFunction,
|
|
100
|
+
log10: Log10Function,
|
|
101
|
+
ln: LnFunction,
|
|
102
|
+
exp: ExpFunction,
|
|
103
|
+
pi: PiFunction,
|
|
104
|
+
radians: RadiansFunction,
|
|
105
|
+
sin: SinFunction,
|
|
106
|
+
cos: CosFunction,
|
|
107
|
+
tan: TanFunction,
|
|
108
|
+
asin: AsinFunction,
|
|
109
|
+
acos: AcosFunction,
|
|
110
|
+
atan: AtanFunction,
|
|
111
|
+
atan2: Atan2Function,
|
|
112
|
+
len: LenFunction,
|
|
113
|
+
lenb: LenbFunction
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
functions
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","sources":["../../formula/mapping.ts"],"sourcesContent":["import { AddFunction } from './functions/add';\nimport { MinusFunction } from './functions/minus';\nimport { MultiplyFunction } from './functions/multiply';\nimport { DivideFunction } from './functions/divide';\nimport { ModFunction } from './functions/mod';\nimport { SumFunction } from './functions/sum';\nimport { ConcatFunction } from './functions/concat';\nimport { ConcatenateFunction } from './functions/concatenate';\nimport { EqFunction } from './functions/eq';\nimport { NeFunction } from './functions/ne';\nimport { GtFunction } from './functions/gt';\nimport { GteFunction } from './functions/gte';\nimport { LtFunction } from './functions/lt';\nimport { LteFunction } from './functions/lte';\nimport { NowFunction } from './functions/now';\nimport { AndFunction } from './functions/and';\nimport { OrFunction } from './functions/or';\nimport { IfFunction } from './functions/if';\nimport { IfErrorFunction } from './functions/iferror';\nimport { NotFunction } from './functions/not';\nimport { CountFunction } from './functions/count';\nimport { CountifFunction } from './functions/countif';\nimport { SumifFunction } from './functions/sumif';\nimport { VlookupFunction } from './functions/vlookup';\nimport { HlookupFunction } from './functions/hlookup';\nimport { LogFunction } from './functions/log';\nimport { Log10Function } from './functions/log10';\nimport { LnFunction } from './functions/ln';\nimport { AbsFunction } from './functions/abs';\nimport { ProductFunction } from './functions/product';\nimport { RandFunction } from './functions/rand';\nimport { PiFunction } from './functions/pi';\nimport { ExpFunction } from './functions/exp';\nimport { RadiansFunction } from './functions/radians';\nimport { PowerFunction } from './functions/power';\nimport { SqrtFunction } from './functions/sqrt';\nimport { RoundFunction } from './functions/round';\nimport { RoundupFunction } from './functions/roundup';\nimport { RounddownFunction } from './functions/rounddown';\nimport { SinFunction } from './functions/sin';\nimport { CosFunction } from './functions/cos';\nimport { TanFunction } from './functions/tan';\nimport { AsinFunction } from './functions/asin';\nimport { AcosFunction } from './functions/acos';\nimport { AtanFunction } from './functions/atan';\nimport { Atan2Function } from './functions/atan2';\nimport { CountaFunction } from './functions/counta';\nimport { AverageFunction } from './functions/average';\nimport { MaxFunction } from './functions/max';\nimport { MinFunction } from './functions/min';\nimport { LenFunction } from './functions/len';\nimport { LenbFunction } from './functions/lenb';\nimport { UminusFunction } from './functions/uminus';\nimport { RowFunction } from './functions/row';\nimport { ColFunction } from './functions/col';\nimport type { FunctionMapping } from './functions/__base';\n\nexport const functions: FunctionMapping = {\n abs: AbsFunction,\n add: AddFunction,\n divide: DivideFunction,\n mod: ModFunction,\n minus: MinusFunction,\n uminus: UminusFunction,\n multiply: MultiplyFunction,\n pow: PowerFunction,\n power: PowerFunction,\n sqrt: SqrtFunction,\n sum: SumFunction,\n sumif: SumifFunction,\n max: MaxFunction,\n min: MinFunction,\n average: AverageFunction,\n count: CountFunction,\n counta: CountaFunction,\n countif: CountifFunction,\n product: ProductFunction,\n concat: ConcatFunction,\n concatenate: ConcatenateFunction,\n eq: EqFunction,\n ne: NeFunction,\n gt: GtFunction,\n gte: GteFunction,\n lt: LtFunction,\n lte: LteFunction,\n and: AndFunction,\n or: OrFunction,\n round: RoundFunction,\n rounddown: RounddownFunction,\n roundup: RoundupFunction,\n if: IfFunction,\n // @ts-expect-error iferror does not extends BaseFunction\n iferror: IfErrorFunction,\n not: NotFunction,\n vlookup: VlookupFunction,\n hlookup: HlookupFunction,\n row: RowFunction,\n col: ColFunction,\n now: NowFunction,\n rand: RandFunction,\n log: LogFunction,\n log10: Log10Function,\n ln: LnFunction,\n exp: ExpFunction,\n pi: PiFunction,\n radians: RadiansFunction,\n sin: SinFunction,\n cos: CosFunction,\n tan: TanFunction,\n asin: AsinFunction,\n acos: AcosFunction,\n atan: AtanFunction,\n atan2: Atan2Function,\n len: LenFunction,\n lenb: LenbFunction,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAM,YAA6B;AAAA,EACxC,KAAK;AAAA,EACL,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,KAAK;AAAA,EACL,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,KAAK;AAAA,EACL,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,WAAW;AAAA,EACX,SAAS;AAAA,EACT,IAAI;AAAA;AAAA,EAEJ,SAAS;AAAA,EACT,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS;AAAA,EACT,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,MAAM;AACR;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Special } from "../constants.js";
|
|
2
|
+
import { Table } from "../lib/table.js";
|
|
3
|
+
import { Lexer, Parser, FormulaError } from "./evaluator.js";
|
|
4
|
+
import { p2a } from "../lib/converters.js";
|
|
5
|
+
const SOLVING = new Special("solving");
|
|
6
|
+
const solveFormula = ({ value, table, raise = true, evaluates = true }) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (evaluates === null) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
let solved = value;
|
|
12
|
+
if (typeof value === "string") {
|
|
13
|
+
if (value.charAt(0) === "=") {
|
|
14
|
+
try {
|
|
15
|
+
const lexer = new Lexer(value.substring(1));
|
|
16
|
+
lexer.tokenize();
|
|
17
|
+
const parser = new Parser(lexer.tokens);
|
|
18
|
+
if (evaluates === false) {
|
|
19
|
+
return "=" + lexer.stringifyToRef(table);
|
|
20
|
+
}
|
|
21
|
+
const expr = parser.build();
|
|
22
|
+
solved = (_a = expr == null ? void 0 : expr.evaluate) == null ? void 0 : _a.call(expr, { table });
|
|
23
|
+
} catch (e) {
|
|
24
|
+
if (raise) {
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (solved instanceof Table) {
|
|
32
|
+
solved = solveTable({ table: solved, raise })[0][0];
|
|
33
|
+
}
|
|
34
|
+
return solved;
|
|
35
|
+
};
|
|
36
|
+
const solveTable = ({ table, raise = true }) => {
|
|
37
|
+
const area = table.getArea();
|
|
38
|
+
return table.getMatrixFlatten({ area, evaluates: null }).map((row, i) => {
|
|
39
|
+
const y = area.top + i;
|
|
40
|
+
return row.map((value, j) => {
|
|
41
|
+
const x = area.left + j;
|
|
42
|
+
const address = p2a({ y, x });
|
|
43
|
+
const cache = table.getSolvedCache(address);
|
|
44
|
+
try {
|
|
45
|
+
if (cache === SOLVING) {
|
|
46
|
+
throw new FormulaError("#REF!", "References are circulating.", new Error(value));
|
|
47
|
+
} else if (cache instanceof FormulaError) {
|
|
48
|
+
throw cache;
|
|
49
|
+
} else if (cache != null) {
|
|
50
|
+
return cache;
|
|
51
|
+
}
|
|
52
|
+
table.setSolvedCache(address, SOLVING);
|
|
53
|
+
const solved = solveFormula({ value, table, raise });
|
|
54
|
+
table.setSolvedCache(address, solved);
|
|
55
|
+
return solved;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
table.setSolvedCache(address, e);
|
|
58
|
+
if (raise) {
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
solveFormula,
|
|
68
|
+
solveTable
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=solver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solver.js","sources":["../../formula/solver.ts"],"sourcesContent":["import { Special } from '../constants';\nimport { Table } from '../lib/table';\nimport { MatrixType } from '../types';\nimport { FormulaError, Lexer, Parser } from './evaluator';\nimport { p2a } from '../lib/converters';\n\nconst SOLVING = new Special('solving');\n\ntype SolveFormulaType = {\n value: any;\n table: Table;\n raise?: boolean;\n evaluates?: boolean | null;\n};\n\nexport const solveFormula = ({ value, table, raise = true, evaluates = true }: SolveFormulaType) => {\n if (evaluates === null) {\n return value;\n }\n let solved = value;\n if (typeof value === 'string') {\n if (value.charAt(0) === '=') {\n try {\n const lexer = new Lexer(value.substring(1));\n lexer.tokenize();\n const parser = new Parser(lexer.tokens);\n if (evaluates === false) {\n return '=' + lexer.stringifyToRef(table);\n }\n const expr = parser.build();\n solved = expr?.evaluate?.({ table });\n } catch (e) {\n if (raise) {\n throw e;\n }\n return null;\n }\n }\n }\n if (solved instanceof Table) {\n solved = solveTable({ table: solved, raise })[0][0];\n }\n return solved;\n};\n\nexport const solveTable = ({ table, raise = true }: { table: Table; raise?: boolean }): MatrixType => {\n const area = table.getArea();\n return table.getMatrixFlatten({ area, evaluates: null }).map((row, i) => {\n const y = area.top + i;\n return row.map((value, j) => {\n const x = area.left + j;\n const address = p2a({ y, x });\n const cache = table.getSolvedCache(address);\n\n try {\n if (cache === SOLVING) {\n throw new FormulaError('#REF!', 'References are circulating.', new Error(value as string));\n } else if (cache instanceof FormulaError) {\n throw cache;\n } else if (cache != null) {\n return cache;\n }\n table.setSolvedCache(address, SOLVING);\n const solved = solveFormula({ value, table, raise });\n table.setSolvedCache(address, solved);\n return solved;\n } catch (e) {\n table.setSolvedCache(address, e);\n if (raise) {\n throw e;\n }\n return null;\n }\n });\n });\n};\n"],"names":[],"mappings":";;;;AAMA,MAAM,UAAU,IAAI,QAAQ,SAAS;AASxB,MAAA,eAAe,CAAC,EAAE,OAAO,OAAO,QAAQ,MAAM,YAAY,WAA6B;;AAClG,MAAI,cAAc,MAAM;AACf,WAAA;AAAA,EAAA;AAET,MAAI,SAAS;AACT,MAAA,OAAO,UAAU,UAAU;AAC7B,QAAI,MAAM,OAAO,CAAC,MAAM,KAAK;AACvB,UAAA;AACF,cAAM,QAAQ,IAAI,MAAM,MAAM,UAAU,CAAC,CAAC;AAC1C,cAAM,SAAS;AACf,cAAM,SAAS,IAAI,OAAO,MAAM,MAAM;AACtC,YAAI,cAAc,OAAO;AAChB,iBAAA,MAAM,MAAM,eAAe,KAAK;AAAA,QAAA;AAEnC,cAAA,OAAO,OAAO,MAAM;AAC1B,kBAAS,kCAAM,aAAN,8BAAiB,EAAE,MAAA;AAAA,eACrB,GAAG;AACV,YAAI,OAAO;AACH,gBAAA;AAAA,QAAA;AAED,eAAA;AAAA,MAAA;AAAA,IACT;AAAA,EACF;AAEF,MAAI,kBAAkB,OAAO;AAClB,aAAA,WAAW,EAAE,OAAO,QAAQ,OAAO,EAAE,CAAC,EAAE,CAAC;AAAA,EAAA;AAE7C,SAAA;AACT;AAEO,MAAM,aAAa,CAAC,EAAE,OAAO,QAAQ,WAA0D;AAC9F,QAAA,OAAO,MAAM,QAAQ;AACpB,SAAA,MAAM,iBAAiB,EAAE,MAAM,WAAW,KAAM,CAAA,EAAE,IAAI,CAAC,KAAK,MAAM;AACjE,UAAA,IAAI,KAAK,MAAM;AACrB,WAAO,IAAI,IAAI,CAAC,OAAO,MAAM;AACrB,YAAA,IAAI,KAAK,OAAO;AACtB,YAAM,UAAU,IAAI,EAAE,GAAG,GAAG;AACtB,YAAA,QAAQ,MAAM,eAAe,OAAO;AAEtC,UAAA;AACF,YAAI,UAAU,SAAS;AACrB,gBAAM,IAAI,aAAa,SAAS,+BAA+B,IAAI,MAAM,KAAe,CAAC;AAAA,QAAA,WAChF,iBAAiB,cAAc;AAClC,gBAAA;AAAA,QAAA,WACG,SAAS,MAAM;AACjB,iBAAA;AAAA,QAAA;AAEH,cAAA,eAAe,SAAS,OAAO;AACrC,cAAM,SAAS,aAAa,EAAE,OAAO,OAAO,OAAO;AAC7C,cAAA,eAAe,SAAS,MAAM;AAC7B,eAAA;AAAA,eACA,GAAG;AACJ,cAAA,eAAe,SAAS,CAAC;AAC/B,YAAI,OAAO;AACH,gBAAA;AAAA,QAAA;AAED,eAAA;AAAA,MAAA;AAAA,IACT,CACD;AAAA,EAAA,CACF;AACH;"}
|