@fw-components/formula-editor 2.1.1-formula-editor-regex-fix.0 → 2.1.1-formula-editor-regex-fix.1
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.
|
@@ -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;
|
|
79
|
+
token = recommendation;
|
|
80
80
|
recommendation = null;
|
|
81
81
|
}
|
|
82
82
|
parseOutput.recommendations = this._recommender.getRecommendations(token);
|
|
@@ -90,11 +90,11 @@ export class Parser {
|
|
|
90
90
|
* Unknown symbol/variable/word
|
|
91
91
|
*/
|
|
92
92
|
if (!(isNumber || isOperator || isBracket || isSpace)) {
|
|
93
|
-
parseOutput.errorString = `${this.variableType} : '${token}'
|
|
93
|
+
parseOutput.errorString = `${this.variableType} : '${token}' doesn't exist.`;
|
|
94
94
|
expectation = Expectation.UNDEFINED;
|
|
95
95
|
}
|
|
96
96
|
else if (this.allowedOperators.has(previousToken) && isOperator) {
|
|
97
|
-
parseOutput.errorString = `Please use ${
|
|
97
|
+
parseOutput.errorString = `Please don't use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) consecutively.`;
|
|
98
98
|
expectation = Expectation.UNDEFINED;
|
|
99
99
|
}
|
|
100
100
|
else if (parentheses.isEmpty() && token === ")") {
|
|
@@ -107,28 +107,28 @@ export class Parser {
|
|
|
107
107
|
*/
|
|
108
108
|
else if (expectation === Expectation.VARIABLE && !isNumber && !isSpace && token != "("
|
|
109
109
|
&& !((unaryOperators.includes(token)) && (!parsedString.trim() || previousToken === "(" || this.allowedOperators.has(previousToken)))) {
|
|
110
|
-
parseOutput.errorString = `Please use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after '${previousToken}'.`;
|
|
110
|
+
parseOutput.errorString = `Please use ${this.variableType} ${this.variableType && this.allowedNumbers ? " or " : ''} ${this.allowedNumbers ? "numbers" : ""} after '${previousToken}'.`;
|
|
111
111
|
expectation = Expectation.UNDEFINED;
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
114
|
* Multiple number/variable together without operator
|
|
115
115
|
*/
|
|
116
116
|
else if (expectation === Expectation.OPERATOR && !isOperator && !isSpace && token != ")") {
|
|
117
|
-
parseOutput.errorString = `Please use
|
|
117
|
+
parseOutput.errorString = `Please use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) after '${previousToken}'.`;
|
|
118
118
|
expectation = Expectation.UNDEFINED;
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
121
|
* division by zero
|
|
122
122
|
*/
|
|
123
123
|
else if (isNumber && previousToken === "/" && (this.variables.get(token) === 0 || Number(token) === 0)) {
|
|
124
|
-
parseOutput.errorString = `Division by zero is not possible
|
|
124
|
+
parseOutput.errorString = `Division by zero is not possible.`;
|
|
125
125
|
expectation = Expectation.UNDEFINED;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Empty brackets
|
|
129
129
|
*/
|
|
130
130
|
else if (previousToken === "(" && token === ")") {
|
|
131
|
-
parseOutput.errorString = `
|
|
131
|
+
parseOutput.errorString = `Please don't use empty brackets ().`;
|
|
132
132
|
expectation = Expectation.UNDEFINED;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
@@ -153,15 +153,15 @@ 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;
|
|
157
|
+
parseOutput.formattedString += recommendation;
|
|
158
158
|
previousToken = recommendation;
|
|
159
159
|
}
|
|
160
160
|
if (this.allowedOperators.has(previousToken) || !previousToken.trim().length) {
|
|
161
161
|
parseOutput.recommendations = !parseOutput.errorString?.length ? Array.from(this.variables.keys()) : [];
|
|
162
162
|
}
|
|
163
163
|
if (this.allowedOperators.has(previousToken)) {
|
|
164
|
-
parseOutput.errorString = `
|
|
164
|
+
parseOutput.errorString = `Please don't use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) at the end.`;
|
|
165
165
|
}
|
|
166
166
|
if (!parentheses.isEmpty()) {
|
|
167
167
|
parseOutput.errorString = "Unexpected opening bracket. Make sure all closing brackets ')' have matching opening brackets '('.";
|
|
@@ -285,13 +285,9 @@ 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);
|
|
289
288
|
const [sign, variableKey] = /^[+-]/.test(frontItem) ? [frontItem[0], frontItem.slice(1)] : ["", frontItem];
|
|
290
289
|
const operandValue = Number.parseFloat(this.variables.get(variableKey)?.toString() ?? variableKey);
|
|
291
|
-
console.log("sign", sign);
|
|
292
|
-
console.log("variable", variableKey);
|
|
293
290
|
const number = Number.parseFloat(sign + "1") * operandValue;
|
|
294
|
-
console.log("number", number);
|
|
295
291
|
calcStack.push(Big(number));
|
|
296
292
|
}
|
|
297
293
|
else {
|
|
@@ -305,7 +301,6 @@ export class Parser {
|
|
|
305
301
|
try {
|
|
306
302
|
switch (operator) {
|
|
307
303
|
case "+":
|
|
308
|
-
console.log("+", numA, " ", numB);
|
|
309
304
|
calcStack.push(Big(numA).add(Big(numB)));
|
|
310
305
|
break;
|
|
311
306
|
case "-":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fw-components/formula-editor",
|
|
3
|
-
"version": "2.1.1-formula-editor-regex-fix.
|
|
3
|
+
"version": "2.1.1-formula-editor-regex-fix.1",
|
|
4
4
|
"description": "A WYSIWYG type formula editor",
|
|
5
5
|
"main": "dist/formula-editor/src/formula-editor.js",
|
|
6
6
|
"exports": {
|
|
@@ -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": "f2e7bb9ad6bb5cc28f19505193aaa0bbc9bb5cf7"
|
|
35
35
|
}
|