@fw-components/formula-editor 2.0.7-formula-editor.16 → 2.0.7-formula-editor.18

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.
@@ -29,6 +29,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
29
29
  this.currentCursorPosition = null;
30
30
  this.currentCursorRect = undefined;
31
31
  this.lastInputType = "undef";
32
+ this.isFocus = false;
32
33
  this.content = "";
33
34
  this.placeholder = "Type your formula...";
34
35
  this.variables = new Map();
@@ -181,10 +182,12 @@ let FormulaEditor = class FormulaEditor extends LitElement {
181
182
  }
182
183
  }
183
184
  handleFocusOut(e) {
185
+ this.isFocus = false;
184
186
  this._recommendations = null;
185
187
  this.requestUpdate();
186
188
  }
187
189
  handleFocus(e) {
190
+ this.isFocus = true;
188
191
  if (!this.content.trim()) {
189
192
  this._recommendations = Array.from(this.variables.keys());
190
193
  }
@@ -212,7 +215,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
212
215
  @blur=${this.handleFocusOut}
213
216
  @focus=${this.handleFocus}
214
217
  ></div>
215
- ${this._recommendations && this.currentCursorPosition
218
+ ${this._recommendations && this.isFocus
216
219
  ? html ` <suggestion-menu
217
220
  .recommendations=${this._recommendations}
218
221
  .currentSelection=${this._selectedRecommendation}
@@ -245,6 +248,9 @@ __decorate([
245
248
  __decorate([
246
249
  state()
247
250
  ], FormulaEditor.prototype, "_selectedRecommendation", void 0);
251
+ __decorate([
252
+ state()
253
+ ], FormulaEditor.prototype, "isFocus", void 0);
248
254
  __decorate([
249
255
  property()
250
256
  ], FormulaEditor.prototype, "content", void 0);
@@ -15,7 +15,7 @@ export class Parser {
15
15
  this._recommender = new Recommender(this.variables, minSuggestionLen);
16
16
  }
17
17
  parseInput(formula, prevCurPos = null, recommendation = null) {
18
- let tokens = formula.split(/([-+(),*^/:?\s])/g);
18
+ let tokens = formula.match(/'[^']*'|\d+|[A-Za-z_][A-Za-z0-9_]*|[+\-(),*^\/:\?\s]/g);
19
19
  // Stores the positions of opening parentheses. This allows us to
20
20
  // show "Unclosed parenthesis error" for positions which are far behind
21
21
  // our current token
@@ -49,7 +49,7 @@ export class Parser {
49
49
  return parseOutput;
50
50
  }
51
51
  }
52
- tokens.forEach((token) => {
52
+ tokens?.forEach((token) => {
53
53
  // It is a number is either it's in the defined variables, or
54
54
  // it's a valid number literal.
55
55
  let isNumber = this.variables.has(token) || !Number.isNaN(Number(token)), isOperator = this.mathematicalOperators.has(token), isSpace = token.trim() == "", isBracket = token == "(" || token == ")";
@@ -201,8 +201,8 @@ export class Parser {
201
201
  return null;
202
202
  }
203
203
  const tokens = formula
204
- .split(/([-+(),*^/:?\s])/g)
205
- .filter((el) => !/\s+/.test(el) && el !== "");
204
+ .match(/'[^']*'|\d+|[A-Za-z_][A-Za-z0-9_]*|[+\-(),*^\/:\?\s]/g)
205
+ ?.filter((el) => !/\s+/.test(el) && el !== "");
206
206
  // Handling the special case of unary `-` and `+`.
207
207
  let previousToken = "";
208
208
  let carriedToken = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fw-components/formula-editor",
3
- "version": "2.0.7-formula-editor.16",
3
+ "version": "2.0.7-formula-editor.18",
4
4
  "description": "A WYSIWYG type formula editor",
5
5
  "main": "dist/formula-editor/src/formula-builder.js",
6
6
  "publishConfig": {
@@ -25,5 +25,5 @@
25
25
  "@types/big.js": "^6.1.6",
26
26
  "es-dev-server": "^2.1.0"
27
27
  },
28
- "gitHead": "be12aca1478fe579ff329b62b0e504d33b16d72c"
28
+ "gitHead": "1ad6ff3dc89bf4bea2547f4170744d95f0044ff9"
29
29
  }