@fw-components/formula-editor 2.0.7-formula-editor.38 → 2.0.7-formula-editor.39
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.
|
@@ -19,19 +19,17 @@ let FormulaEditor = class FormulaEditor extends LitElement {
|
|
|
19
19
|
/**
|
|
20
20
|
* Text area input value
|
|
21
21
|
*/
|
|
22
|
-
this.
|
|
22
|
+
this.formulaString = "";
|
|
23
23
|
this.placeholder = "Type your formula...";
|
|
24
24
|
this.recommendationLabels = new Map();
|
|
25
25
|
this.variables = new Map();
|
|
26
26
|
this.minSuggestionLen = 2;
|
|
27
27
|
this.errorString = "";
|
|
28
|
-
this.formulaRegex = /'[^']*'|[A-Za-z0-9_#@]+|[-+(),*^/\s]/g;
|
|
29
28
|
this.allowedNumbers = true;
|
|
30
|
-
this.allowedOperators = new Set(["^", "+", "-", "*", "/"]);
|
|
31
29
|
}
|
|
32
30
|
updated(_changedProperties) {
|
|
33
|
-
if (_changedProperties.has("
|
|
34
|
-
if (!this.
|
|
31
|
+
if (_changedProperties.has("formulaString")) {
|
|
32
|
+
if (!this.formulaString?.trim()) {
|
|
35
33
|
this.recommendations = Array.from(this.variables.keys());
|
|
36
34
|
}
|
|
37
35
|
this._adjustTextAreaHeight();
|
|
@@ -47,11 +45,11 @@ let FormulaEditor = class FormulaEditor extends LitElement {
|
|
|
47
45
|
handleContentUpdate(event) {
|
|
48
46
|
event.preventDefault();
|
|
49
47
|
this.lastInputType = event.inputType;
|
|
50
|
-
this.
|
|
48
|
+
this.formulaString = event.target.value;
|
|
51
49
|
this.parseInput();
|
|
52
50
|
}
|
|
53
51
|
_adjustTextAreaHeight() {
|
|
54
|
-
if (!this.
|
|
52
|
+
if (!this.formulaString)
|
|
55
53
|
this.editor.style.height = "var(--fe-height, 30px)";
|
|
56
54
|
if (this.editor.scrollHeight > this.editor.clientHeight)
|
|
57
55
|
this.editor.style.height = String(this.editor.scrollHeight + 5).concat("px");
|
|
@@ -63,7 +61,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
|
|
|
63
61
|
*/
|
|
64
62
|
parseInput(recommendation = "") {
|
|
65
63
|
this.currentCursorPosition = this.editor.selectionStart;
|
|
66
|
-
const { recommendations, errorString, formattedString, newCursorPosition } = this._parser.parseInput(this.
|
|
64
|
+
const { recommendations, errorString, formattedString, newCursorPosition } = this._parser.parseInput(this.formulaString, this.currentCursorPosition, recommendation);
|
|
67
65
|
this.recommendations = recommendations;
|
|
68
66
|
this.errorString = errorString;
|
|
69
67
|
/**
|
|
@@ -74,7 +72,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
|
|
|
74
72
|
* @see https://bugs.chromium.org/p/chromium/issues/detail?id=689541
|
|
75
73
|
*/
|
|
76
74
|
if (this.lastInputType !== "insertCompositionText" || recommendation) {
|
|
77
|
-
this.
|
|
75
|
+
this.formulaString = formattedString;
|
|
78
76
|
}
|
|
79
77
|
if (Boolean(recommendation)) {
|
|
80
78
|
this.recommendations = [];
|
|
@@ -86,19 +84,19 @@ let FormulaEditor = class FormulaEditor extends LitElement {
|
|
|
86
84
|
}
|
|
87
85
|
this.dispatchEvent(new CustomEvent("fw-formula-content-changed", {
|
|
88
86
|
detail: {
|
|
89
|
-
formulaString: this.
|
|
87
|
+
formulaString: this.formulaString,
|
|
90
88
|
error: this.errorString,
|
|
91
89
|
recommendations: this.recommendations,
|
|
92
|
-
formulaTokens: getFormulaTokens(this.
|
|
90
|
+
formulaTokens: getFormulaTokens(this.formulaString || "", this.formulaRegex)
|
|
93
91
|
},
|
|
94
92
|
bubbles: true,
|
|
95
93
|
}));
|
|
96
94
|
}
|
|
97
95
|
formatFormula() {
|
|
98
|
-
if (!this.
|
|
96
|
+
if (!this.formulaString)
|
|
99
97
|
return;
|
|
100
|
-
const newContent = this._parser.addParentheses(this.
|
|
101
|
-
this.
|
|
98
|
+
const newContent = this._parser.addParentheses(this.formulaString);
|
|
99
|
+
this.formulaString = newContent && newContent.length ? newContent : this.formulaString;
|
|
102
100
|
this.parseInput();
|
|
103
101
|
this.recommendations = [];
|
|
104
102
|
}
|
|
@@ -137,7 +135,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
|
|
|
137
135
|
<textarea
|
|
138
136
|
id="fw-formula-editor"
|
|
139
137
|
class=${this.errorString?.length ? "error" : ""}
|
|
140
|
-
.value=${this.
|
|
138
|
+
.value=${this.formulaString}
|
|
141
139
|
.placeholder=${this.placeholder}
|
|
142
140
|
spellcheck="false"
|
|
143
141
|
autocomplete="off"
|
|
@@ -175,7 +173,7 @@ __decorate([
|
|
|
175
173
|
], FormulaEditor.prototype, "isFocused", void 0);
|
|
176
174
|
__decorate([
|
|
177
175
|
property()
|
|
178
|
-
], FormulaEditor.prototype, "
|
|
176
|
+
], FormulaEditor.prototype, "formulaString", void 0);
|
|
179
177
|
__decorate([
|
|
180
178
|
property()
|
|
181
179
|
], FormulaEditor.prototype, "placeholder", void 0);
|
|
@@ -6,12 +6,12 @@ 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, allowedNumbers, allowedOperators, variableType) {
|
|
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);
|
|
13
|
-
this.allowedNumbers = allowedNumbers
|
|
14
|
-
this.allowedOperators = allowedOperators
|
|
13
|
+
this.allowedNumbers = allowedNumbers;
|
|
14
|
+
this.allowedOperators = allowedOperators;
|
|
15
15
|
this.variableType = variableType;
|
|
16
16
|
}
|
|
17
17
|
isNumber(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fw-components/formula-editor",
|
|
3
|
-
"version": "2.0.7-formula-editor.
|
|
3
|
+
"version": "2.0.7-formula-editor.39",
|
|
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": "a3fb82b15d40e80873eaefdc8ab5b1d0ae13096c"
|
|
35
35
|
}
|