@fw-components/formula-editor 2.0.7-formula-editor.5 → 2.0.7-formula-editor.6

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,6 +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
34
  this.variables = new Map();
34
35
  this.minSuggestionLen = 2;
35
36
  this.errorString = null;
@@ -176,6 +177,7 @@ let FormulaEditor = class FormulaEditor extends LitElement {
176
177
  </style>
177
178
  <div
178
179
  contenteditable
180
+ placeholder=${this.placeholder}
179
181
  id="wysiwyg-editor"
180
182
  spellcheck="false"
181
183
  autocomplete="off"
@@ -217,6 +219,9 @@ __decorate([
217
219
  __decorate([
218
220
  property()
219
221
  ], FormulaEditor.prototype, "content", void 0);
222
+ __decorate([
223
+ property()
224
+ ], FormulaEditor.prototype, "placeholder", void 0);
220
225
  __decorate([
221
226
  property({
222
227
  type: (Map),
@@ -61,6 +61,9 @@ export class Parser {
61
61
  // Since we are sure that the recommendation will always correspond
62
62
  // to a variable.
63
63
  isNumber = true;
64
+ if (this.mathematicalOperators.has(token)) {
65
+ recommendation = token + recommendation;
66
+ }
64
67
  // If the new cursor length somehow becomes larger than the
65
68
  // length of the formula string, setting the caret to that
66
69
  // length will move the caret to the start. Although this overflow
@@ -80,7 +83,7 @@ export class Parser {
80
83
  if (expectation != Expectation.UNDEFINED) {
81
84
  // Unnecessary closing parenthesis
82
85
  if (parentheses.isEmpty() && token == ")") {
83
- parseOutput.errorString = `Unexpected ')' at pos: ${currentPosition}`;
86
+ parseOutput.errorString = `Unexpected ')' at position ${currentPosition}`;
84
87
  tokenClassName += " error";
85
88
  expectation = Expectation.UNDEFINED;
86
89
  }
@@ -93,7 +96,7 @@ export class Parser {
93
96
  token != "(" &&
94
97
  !((token == "-" || token == "+") &&
95
98
  this.mathematicalOperators.has(previousToken))) {
96
- parseOutput.errorString = `Expected variable/number at pos: ${currentPosition}`;
99
+ parseOutput.errorString = `Expected variable/number at position ${currentPosition}`;
97
100
  tokenClassName += " error";
98
101
  expectation = Expectation.UNDEFINED;
99
102
  }
@@ -102,13 +105,13 @@ export class Parser {
102
105
  else if (expectation == Expectation.OPERATOR &&
103
106
  !isOperator &&
104
107
  token != ")") {
105
- parseOutput.errorString = `Expected mathematical operator at pos: ${currentPosition}`;
108
+ parseOutput.errorString = `Expected mathematical operator at position ${currentPosition}`;
106
109
  tokenClassName += " error";
107
110
  expectation = Expectation.UNDEFINED;
108
111
  }
109
112
  // Unknown symbol/variable/word
110
113
  else if (!(isNumber || isOperator || isBracket)) {
111
- parseOutput.errorString = `Unknown word at pos: ${currentPosition}`;
114
+ parseOutput.errorString = `Unknown word at position ${currentPosition}`;
112
115
  tokenClassName += " error";
113
116
  expectation = Expectation.UNDEFINED;
114
117
  }
@@ -117,7 +120,7 @@ export class Parser {
117
120
  else if (isNumber &&
118
121
  previousToken == "/" &&
119
122
  (this.variables.get(token) == 0 || Number(token) == 0)) {
120
- parseOutput.errorString = `Division by zero at pos: ${currentPosition}`;
123
+ parseOutput.errorString = `Division by zero at position ${currentPosition}`;
121
124
  tokenClassName += " error";
122
125
  expectation = Expectation.UNDEFINED;
123
126
  }
@@ -162,7 +165,8 @@ export class Parser {
162
165
  });
163
166
  // If the formula ends with a mathematical operator, or has unclosed `(`
164
167
  if (this.mathematicalOperators.has(previousToken)) {
165
- parseOutput.errorString = "Unexpected ending of formula.";
168
+ // parseOutput.errorString = "Unexpected ending of formula.";
169
+ parseOutput.recommendations = Array.from(this.variables.keys());
166
170
  }
167
171
  else if (!parentheses.isEmpty()) {
168
172
  parseOutput.errorString = `Unclosed '(' at position: ${parentheses.top()}`;
@@ -19,6 +19,12 @@ export const FormulaEditorStyles = css `
19
19
  /* position: relative; */
20
20
  }
21
21
 
22
+ #wysiwyg-editor:empty:before {
23
+ content: attr(placeholder);
24
+ color: var(--fe-placeholder-color,grey);
25
+ pointer-events: none;
26
+ }
27
+
22
28
  .wysiwygInternals.error {
23
29
  text-decoration: underline;
24
30
  -webkit-text-decoration-color: var(--fe-err-underline-color, #fc514f);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fw-components/formula-editor",
3
- "version": "2.0.7-formula-editor.5",
3
+ "version": "2.0.7-formula-editor.6",
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": "f71fd4e137320d18e8d95f05e58f3d0de8eeae8e"
28
+ "gitHead": "dfd5a0d70498d8b9fc4d57253720e9b20e44c2b1"
29
29
  }