@fw-components/formula-editor 2.0.7-formula-editor.18 → 2.0.7-formula-editor.20
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.
|
@@ -80,10 +80,31 @@ export class Cursor {
|
|
|
80
80
|
}
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
|
-
static
|
|
83
|
+
static _getComposedRange(shadowRoot) {
|
|
84
84
|
// `getSelection` is not defined for the type ShadowRoot in TS,
|
|
85
85
|
// but it does exist.
|
|
86
|
-
const
|
|
86
|
+
const sr = shadowRoot;
|
|
87
|
+
if (sr.getSelection && typeof sr.getSelection === 'function') {
|
|
88
|
+
const selection = sr.getSelection();
|
|
89
|
+
if (selection && selection.rangeCount > 0) {
|
|
90
|
+
return selection.getRangeAt(0);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Fallback for browsers like Firefox/Safari.
|
|
94
|
+
const selection = window.getSelection();
|
|
95
|
+
if (selection && selection.rangeCount > 0) {
|
|
96
|
+
const range = selection.getRangeAt(0);
|
|
97
|
+
if (shadowRoot.contains(range.startContainer)) {
|
|
98
|
+
return range;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
static getCaretPosition(shadowRoot, element) {
|
|
104
|
+
const range = Cursor._getComposedRange(shadowRoot);
|
|
105
|
+
if (!range) {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
87
108
|
const prefix = range.cloneRange();
|
|
88
109
|
prefix.selectNodeContents(element);
|
|
89
110
|
prefix.setEnd(range.endContainer, range.endOffset);
|
|
@@ -115,9 +136,7 @@ export class Cursor {
|
|
|
115
136
|
return pos;
|
|
116
137
|
}; }
|
|
117
138
|
static getCursorRect(shadowRoot) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
?.getRangeAt(0)
|
|
121
|
-
?.getClientRects()[0];
|
|
139
|
+
const range = Cursor._getComposedRange(shadowRoot);
|
|
140
|
+
return range ? range.getClientRects()[0] : undefined;
|
|
122
141
|
}
|
|
123
142
|
}
|
|
@@ -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.match(/'[^']*'|\d+|[A-Za-z_][A-Za-z0-9_]*|[
|
|
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
|
|
@@ -201,7 +201,7 @@ export class Parser {
|
|
|
201
201
|
return null;
|
|
202
202
|
}
|
|
203
203
|
const tokens = formula
|
|
204
|
-
.match(/'[^']*'|\d+|[A-Za-z_][A-Za-z0-9_]*|[
|
|
204
|
+
.match(/'[^']*'|\d+|[A-Za-z_][A-Za-z0-9_]*|[-+(),*^/:?\s]/g)
|
|
205
205
|
?.filter((el) => !/\s+/.test(el) && el !== "");
|
|
206
206
|
// Handling the special case of unary `-` and `+`.
|
|
207
207
|
let previousToken = "";
|
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.20",
|
|
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": "
|
|
28
|
+
"gitHead": "7784664827845580650e4c671969aab0071aa0f6"
|
|
29
29
|
}
|