@fw-components/formula-editor 2.0.7-formula-editor.43 → 2.1.1-formula-editor-regex-fix.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.
|
@@ -6,7 +6,7 @@ import { Expectation } from "../types";
|
|
|
6
6
|
import { operatorPrecedence, unaryOperators, mathematicalOperators } from "./constants.js";
|
|
7
7
|
import { getFormulaTokens } from "./get-formula-tokens.js";
|
|
8
8
|
export class Parser {
|
|
9
|
-
constructor(variables, minSuggestionLen, formulaRegex = /[A-Za-z0-9_
|
|
9
|
+
constructor(variables, minSuggestionLen, formulaRegex = /[A-Za-z0-9_#@.]+|[-+(),*^/\s]/g, allowedNumbers = true, allowedOperators = mathematicalOperators, variableType = "") {
|
|
10
10
|
this.variables = variables;
|
|
11
11
|
this.formulaRegex = formulaRegex;
|
|
12
12
|
this._recommender = new Recommender(Array.from(this.variables.keys()), minSuggestionLen);
|
|
@@ -66,7 +66,7 @@ export class Parser {
|
|
|
66
66
|
if (recommendation) {
|
|
67
67
|
isNumber = true;
|
|
68
68
|
if (this.allowedOperators.has(token)) {
|
|
69
|
-
const updatedTokenString = `${token} ${recommendation}`;
|
|
69
|
+
const updatedTokenString = `${token} ${recommendation} `;
|
|
70
70
|
parseOutput.formattedString += updatedTokenString;
|
|
71
71
|
currentPosition += updatedTokenString.length;
|
|
72
72
|
parseOutput.newCursorPosition = currentPosition;
|
|
@@ -75,8 +75,8 @@ export class Parser {
|
|
|
75
75
|
}
|
|
76
76
|
;
|
|
77
77
|
const updatedTokenLength = recommendation.length - token.length;
|
|
78
|
-
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + updatedTokenLength;
|
|
79
|
-
token = recommendation;
|
|
78
|
+
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + updatedTokenLength + 1;
|
|
79
|
+
token = recommendation + " ";
|
|
80
80
|
recommendation = null;
|
|
81
81
|
}
|
|
82
82
|
parseOutput.recommendations = this._recommender.getRecommendations(token);
|
|
@@ -153,8 +153,8 @@ export class Parser {
|
|
|
153
153
|
previousToken = token;
|
|
154
154
|
});
|
|
155
155
|
if (recommendation) {
|
|
156
|
-
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + recommendation.length;
|
|
157
|
-
parseOutput.formattedString += recommendation;
|
|
156
|
+
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + recommendation.length + 1;
|
|
157
|
+
parseOutput.formattedString += recommendation + " ";
|
|
158
158
|
previousToken = recommendation;
|
|
159
159
|
}
|
|
160
160
|
if (this.allowedOperators.has(previousToken) || !previousToken.trim().length) {
|
|
@@ -285,9 +285,13 @@ export class Parser {
|
|
|
285
285
|
while (!formulaRPN.isEmpty()) {
|
|
286
286
|
const frontItem = formulaRPN.dequeue();
|
|
287
287
|
if (!this.allowedOperators.has(frontItem)) {
|
|
288
|
+
console.log("frontitem", frontItem);
|
|
288
289
|
const [sign, variableKey] = /^[+-]/.test(frontItem) ? [frontItem[0], frontItem.slice(1)] : ["", frontItem];
|
|
289
290
|
const operandValue = Number.parseFloat(this.variables.get(variableKey)?.toString() ?? variableKey);
|
|
291
|
+
console.log("sign", sign);
|
|
292
|
+
console.log("variable", variableKey);
|
|
290
293
|
const number = Number.parseFloat(sign + "1") * operandValue;
|
|
294
|
+
console.log("number", number);
|
|
291
295
|
calcStack.push(Big(number));
|
|
292
296
|
}
|
|
293
297
|
else {
|
|
@@ -301,6 +305,7 @@ export class Parser {
|
|
|
301
305
|
try {
|
|
302
306
|
switch (operator) {
|
|
303
307
|
case "+":
|
|
308
|
+
console.log("+", numA, " ", numB);
|
|
304
309
|
calcStack.push(Big(numA).add(Big(numB)));
|
|
305
310
|
break;
|
|
306
311
|
case "-":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fw-components/formula-editor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1-formula-editor-regex-fix.0",
|
|
4
4
|
"description": "A WYSIWYG type formula editor",
|
|
5
5
|
"main": "dist/formula-editor/src/formula-editor.js",
|
|
6
6
|
"exports": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fw-components/styles": "^2.
|
|
22
|
+
"@fw-components/styles": "^2.1.1-formula-editor-regex-fix.0",
|
|
23
23
|
"big.js": "^6.2.1",
|
|
24
24
|
"lit": "^2.1.2",
|
|
25
25
|
"match-sorter": "^8.0.0",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@types/big.js": "^6.1.6",
|
|
32
32
|
"es-dev-server": "^2.1.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "701ff5ec75328a31286c1fc3c4359d90d16dd288"
|
|
35
35
|
}
|