@fw-components/formula-editor 2.0.7-formula-editor.7 → 2.0.7-formula-editor.9

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.
@@ -30,7 +30,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
30
30
  this.currentCursorRect = undefined;
31
31
  this.lastInputType = "undef";
32
32
  this.content = "";
33
- this.placeholder = "";
33
+ this.placeholder = "Type your formula...";
34
34
  this.variables = new Map();
35
35
  this.minSuggestionLen = 2;
36
36
  this.errorString = null;
@@ -170,6 +170,13 @@ let FormulaEditor = class FormulaEditor extends LitElement {
170
170
  this._recommendations = null;
171
171
  this.requestUpdate();
172
172
  }
173
+ async updated(_changedProperties) {
174
+ if (_changedProperties.has("content")) {
175
+ if (!this.content.trim()) {
176
+ this._recommendations = Array.from(this.variables.keys());
177
+ }
178
+ }
179
+ }
173
180
  render() {
174
181
  return html `
175
182
  <style>
@@ -28,6 +28,7 @@ export class Parser {
28
28
  let currentPosition = 0;
29
29
  // Previous 'token' (not a space or a new line) that we just encountered.
30
30
  let previousToken = "";
31
+ let currentTokens = "";
31
32
  // The object that we return as the output of the parsing result.
32
33
  let parseOutput = {
33
34
  recommendations: null,
@@ -36,6 +37,18 @@ export class Parser {
36
37
  newCursorPosition: prevCurPos ?? -1,
37
38
  errorString: null,
38
39
  };
40
+ if (!formula.trim()) {
41
+ if (recommendation) {
42
+ formattedString = `<span class="wysiwygInternals">${recommendation}</span>`;
43
+ currentPosition += recommendation.length;
44
+ const parser = new DOMParser();
45
+ const doc = parser.parseFromString(formattedString, "text/html");
46
+ parseOutput.formattedContent = doc.querySelector("body");
47
+ parseOutput.formattedString = formattedString;
48
+ parseOutput.newCursorPosition = recommendation.length;
49
+ return parseOutput;
50
+ }
51
+ }
39
52
  tokens.forEach((token) => {
40
53
  // It is a number is either it's in the defined variables, or
41
54
  // it's a valid number literal.
@@ -95,7 +108,7 @@ export class Parser {
95
108
  !isNumber &&
96
109
  token != "(" &&
97
110
  !((token == "-" || token == "+") &&
98
- (this.mathematicalOperators.has(previousToken) || previousToken === ""))) {
111
+ (!currentTokens.trim() || this.mathematicalOperators.has(previousToken)))) {
99
112
  parseOutput.errorString = `Expected variable/number at position ${currentPosition}`;
100
113
  tokenClassName += " error";
101
114
  expectation = Expectation.UNDEFINED;
@@ -162,6 +175,7 @@ export class Parser {
162
175
  formattedString = `${formattedString}<span class="wysiwygInternals ${tokenClassName}">${token}</span>`;
163
176
  currentPosition += token.length;
164
177
  previousToken = token;
178
+ currentTokens += token;
165
179
  });
166
180
  // If the formula ends with a mathematical operator, or has unclosed `(`
167
181
  if (this.mathematicalOperators.has(previousToken)) {
@@ -188,11 +202,10 @@ export class Parser {
188
202
  let previousToken = "";
189
203
  let carriedToken = null;
190
204
  const parsedTokens = [];
205
+ let currentTokens = "";
191
206
  for (const token of tokens) {
192
207
  if ((token == "+" || token == "-") &&
193
- (this.mathematicalOperators.has(previousToken) ||
194
- previousToken === "" ||
195
- previousToken === "(")) {
208
+ (!currentTokens.trim() || this.mathematicalOperators.has(previousToken))) {
196
209
  carriedToken = token;
197
210
  }
198
211
  else if (carriedToken) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fw-components/formula-editor",
3
- "version": "2.0.7-formula-editor.7",
3
+ "version": "2.0.7-formula-editor.9",
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": "c4519eefc65b67e7e8ce4d6c3e942d55c5f3c5d4"
28
+ "gitHead": "8ec9bb1e89c289c5334db8f99d1a359c731a4375"
29
29
  }