@fw-components/formula-editor 2.0.7-formula-editor.33 → 2.0.7-formula-editor.35

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.
@@ -9,6 +9,7 @@ import { customElement, property, state, query } from "lit/decorators.js";
9
9
  import "./suggestion-menu.js";
10
10
  import { Parser } from "./utils/parser.js";
11
11
  import { FormulaEditorStyles } from "./styles/editor.js";
12
+ import { getFormulaTokens } from "./utils/get-formula-tokens.js";
12
13
  let FormulaEditor = class FormulaEditor extends LitElement {
13
14
  constructor() {
14
15
  super(...arguments);
@@ -23,6 +24,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
23
24
  this.variables = new Map();
24
25
  this.minSuggestionLen = 2;
25
26
  this.errorString = "";
27
+ this.formulaRegex = /'[^']*'|[A-Za-z0-9_#@]+|[-+(),*^/\s]/g;
26
28
  }
27
29
  firstUpdated(_changedProperties) {
28
30
  this.editor.focus();
@@ -35,9 +37,8 @@ let FormulaEditor = class FormulaEditor extends LitElement {
35
37
  this._adjustTextAreaHeight();
36
38
  }
37
39
  if (_changedProperties.has("variables")) {
38
- this._parser = new Parser(this.variables, this.minSuggestionLen);
40
+ this._parser = new Parser(this.variables, this.formulaRegex, this.minSuggestionLen);
39
41
  this.recommendations = Array.from(this.variables.keys());
40
- ;
41
42
  }
42
43
  }
43
44
  onRecommendationClick(recommendation) {
@@ -88,6 +89,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
88
89
  formulaString: this.content,
89
90
  error: this.errorString,
90
91
  recommendations: this.recommendations,
92
+ formulaTokens: getFormulaTokens(this.content || "", this.formulaRegex)
91
93
  },
92
94
  bubbles: true,
93
95
  }));
@@ -187,6 +189,9 @@ __decorate([
187
189
  __decorate([
188
190
  property()
189
191
  ], FormulaEditor.prototype, "errorString", void 0);
192
+ __decorate([
193
+ property()
194
+ ], FormulaEditor.prototype, "formulaRegex", void 0);
190
195
  __decorate([
191
196
  query("#wysiwyg-editor")
192
197
  ], FormulaEditor.prototype, "editor", void 0);
@@ -0,0 +1,5 @@
1
+ export function getFormulaTokens(formulaString, formulaRegex) {
2
+ if (!formulaString?.length)
3
+ return [];
4
+ return formulaString.match(formulaRegex) || [];
5
+ }
@@ -4,18 +4,15 @@ import { Stack } from "./stack.js";
4
4
  import { Queue } from "./queue.js";
5
5
  import { Expectation } from "../types";
6
6
  import { mathematicalOperators, operatorPrecedence, unaryOperators } from "./constants.js";
7
+ import { getFormulaTokens } from "./get-formula-tokens.js";
7
8
  export class Parser {
8
- constructor(variables, minSuggestionLen) {
9
+ constructor(variables, formulaRegex, minSuggestionLen) {
9
10
  this.variables = variables;
11
+ this.formulaRegex = formulaRegex;
10
12
  this._recommender = new Recommender(Array.from(this.variables.keys()), minSuggestionLen);
11
13
  }
12
- getFormulaTokens(formulaString) {
13
- if (!formulaString?.length)
14
- return [];
15
- return formulaString.match(/'[^']*'|[A-Za-z0-9_#@]+|[-+(),*^/\s]/g);
16
- }
17
14
  parseInput(formula, prevCurPos = null, recommendation = null) {
18
- const tokens = this.getFormulaTokens(formula);
15
+ const tokens = getFormulaTokens(formula, this.formulaRegex);
19
16
  const parentheses = new Stack();
20
17
  let expectation = Expectation.VARIABLE;
21
18
  let currentPosition = 0;
@@ -157,7 +154,7 @@ export class Parser {
157
154
  buildRPN(formula) {
158
155
  if (this.parseInput(formula).errorString)
159
156
  return null;
160
- const tokens = this.getFormulaTokens(formula)?.filter((el) => !/\s+/.test(el) && el !== "");
157
+ const tokens = getFormulaTokens(formula, this.formulaRegex)?.filter((el) => !/\s+/.test(el) && el !== "");
161
158
  let previousToken = "";
162
159
  let carriedToken = null;
163
160
  const parsedTokens = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fw-components/formula-editor",
3
- "version": "2.0.7-formula-editor.33",
3
+ "version": "2.0.7-formula-editor.35",
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": "36453031cbadda6a8f2e36dcbd409935051e986e"
34
+ "gitHead": "ef64463d26814b5eb6389aa3a1f9ce12f26c46a6"
35
35
  }