@fw-components/formula-editor 2.0.3-formula-editor.1 → 2.0.7-cline-formulaeditor.0
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.
- package/dist/formula-editor/src/cursor.js +142 -0
- package/dist/formula-editor/src/formula-builder.js +139 -0
- package/dist/formula-editor/src/formula-creator.js +83 -0
- package/dist/formula-editor/src/formula-editor.js +367 -0
- package/dist/formula-editor/src/helpers/types.js +16 -0
- package/dist/formula-editor/src/helpers.js +72 -0
- package/dist/formula-editor/src/parser.js +461 -0
- package/dist/formula-editor/src/recommendor.js +18 -0
- package/dist/formula-editor/src/styles/formula-editor-styles.js +149 -0
- package/dist/formula-editor/src/sub-components/operator-input.js +24 -0
- package/dist/formula-editor/src/suggestion-menu.js +198 -0
- package/dist/styles/src/button-styles.js +419 -0
- package/package.json +9 -6
- package/src/cursor.js +126 -0
- package/src/cursor.js.map +1 -0
- package/src/formula-builder.js +148 -0
- package/src/formula-builder.js.map +1 -0
- package/src/formula-creator.js +84 -0
- package/src/formula-creator.js.map +1 -0
- package/src/formula-editor.js +219 -0
- package/src/formula-editor.js.map +1 -0
- package/src/helpers/types.js +17 -0
- package/src/helpers/types.js.map +1 -0
- package/src/helpers.js +55 -0
- package/src/helpers.js.map +1 -0
- package/src/parser.js +359 -0
- package/src/parser.js.map +1 -0
- package/src/recommendor.js +68 -0
- package/src/recommendor.js.map +1 -0
- package/src/styles/{formula-editor-styles.ts → formula-editor-styles.js} +2 -2
- package/src/styles/formula-editor-styles.js.map +1 -0
- package/src/sub-components/operator-input.js +25 -0
- package/src/sub-components/operator-input.js.map +1 -0
- package/src/suggestion-menu.js +73 -0
- package/src/suggestion-menu.js.map +1 -0
- package/tsconfig.json +20 -0
- package/src/cursor.ts +0 -134
- package/src/formula-builder.ts +0 -141
- package/src/formula-creator.ts +0 -99
- package/src/formula-editor.ts +0 -236
- package/src/helpers/types.ts +0 -20
- package/src/helpers.ts +0 -62
- package/src/parser.ts +0 -465
- package/src/recommendor.ts +0 -106
- package/src/sub-components/operator-input.ts +0 -13
- package/src/suggestion-menu.ts +0 -61
package/src/cursor.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
export class Cursor {
|
|
3
|
+
/**
|
|
4
|
+
* The functions `getCurrentCursorPosition`, `setCurrentCursorPosition` and their
|
|
5
|
+
* helpers `_createRange` and `_isChildOf` are not used for caret manipulation,
|
|
6
|
+
* but are still in the code for future reference, if the functionality breaks
|
|
7
|
+
* somehow in some obsolete browser.
|
|
8
|
+
*/
|
|
9
|
+
static getCurrentCursorPosition(parentElement) {
|
|
10
|
+
var _b, _c;
|
|
11
|
+
let selection = window.getSelection(), charCount = -1, node;
|
|
12
|
+
if (selection === null || selection === void 0 ? void 0 : selection.focusNode) {
|
|
13
|
+
if (_a._isChildOf(selection.focusNode, parentElement)) {
|
|
14
|
+
node = selection.focusNode;
|
|
15
|
+
charCount = selection.focusOffset;
|
|
16
|
+
while (node) {
|
|
17
|
+
if (node === parentElement) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
if (node.previousSibling) {
|
|
21
|
+
node = node.previousSibling;
|
|
22
|
+
charCount += (_c = (_b = node.textContent) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
node = node.parentNode;
|
|
26
|
+
if (node === null) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return charCount;
|
|
34
|
+
}
|
|
35
|
+
static setCurrentCursorPosition(chars, element) {
|
|
36
|
+
if (chars >= 0) {
|
|
37
|
+
var selection = window.getSelection();
|
|
38
|
+
let range = _a._createRange(element, { count: chars }, undefined);
|
|
39
|
+
if (range) {
|
|
40
|
+
range.collapse(false);
|
|
41
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
42
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
static _createRange(node, chars, range) {
|
|
47
|
+
if (!range) {
|
|
48
|
+
range = document.createRange();
|
|
49
|
+
range.selectNode(node);
|
|
50
|
+
range.setStart(node, 0);
|
|
51
|
+
}
|
|
52
|
+
if (chars.count === 0) {
|
|
53
|
+
range.setEnd(node, chars.count);
|
|
54
|
+
}
|
|
55
|
+
else if (node && chars.count > 0) {
|
|
56
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
57
|
+
if (node.textContent.length < chars.count) {
|
|
58
|
+
chars.count -= node.textContent.length;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
range.setEnd(node, chars.count);
|
|
62
|
+
chars.count = 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
for (var lp = 0; lp < node.childNodes.length; lp++) {
|
|
67
|
+
range = _a._createRange(node.childNodes[lp], chars, range);
|
|
68
|
+
if (chars.count === 0) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return range;
|
|
75
|
+
}
|
|
76
|
+
static _isChildOf(node, parentElement) {
|
|
77
|
+
while (node !== null) {
|
|
78
|
+
if (node === parentElement) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
node = node.parentNode;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
static getCaretPosition(shadowRoot, element) {
|
|
86
|
+
// `getSelection` is not defined for the type ShadowRoot in TS,
|
|
87
|
+
// but it does exist.
|
|
88
|
+
const range = shadowRoot.getSelection().getRangeAt(0);
|
|
89
|
+
const prefix = range.cloneRange();
|
|
90
|
+
prefix.selectNodeContents(element);
|
|
91
|
+
prefix.setEnd(range.endContainer, range.endOffset);
|
|
92
|
+
return prefix.toString().length;
|
|
93
|
+
}
|
|
94
|
+
static getCursorRect(shadowRoot) {
|
|
95
|
+
var _b, _c;
|
|
96
|
+
return (_c = (_b = shadowRoot
|
|
97
|
+
.getSelection()) === null || _b === void 0 ? void 0 : _b.getRangeAt(0)) === null || _c === void 0 ? void 0 : _c.getClientRects()[0];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
_a = Cursor;
|
|
101
|
+
Cursor.setCaretPosition = (pos, parent) => {
|
|
102
|
+
for (const node of parent.childNodes) {
|
|
103
|
+
if (node.nodeType == Node.TEXT_NODE) {
|
|
104
|
+
if (node.length >= pos) {
|
|
105
|
+
const range = document.createRange();
|
|
106
|
+
const sel = window.getSelection();
|
|
107
|
+
range.setStart(node, pos);
|
|
108
|
+
range.collapse(true);
|
|
109
|
+
sel.removeAllRanges();
|
|
110
|
+
sel.addRange(range);
|
|
111
|
+
return -1;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
pos = pos - node.length;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
pos = _a.setCaretPosition(pos, node);
|
|
119
|
+
if (pos < 0) {
|
|
120
|
+
return pos;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return pos;
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=cursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor.js","sourceRoot":"","sources":["cursor.ts"],"names":[],"mappings":";AAAA,MAAM,OAAO,MAAM;IACjB;;;;;OAKG;IACH,MAAM,CAAC,wBAAwB,CAAC,aAAkB;;QAChD,IAAI,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,EACnC,SAAS,GAAG,CAAC,CAAC,EACd,IAAI,CAAC;QAEP,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,EAAE,CAAC;YACzB,IAAI,EAAM,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,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,CAAC,eAAe,EAAE,CAAC;gBACtB,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,CAAC,CAAC,CAAC;YACZ,CAAC;iBAAM,CAAC;gBACN,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;YAC1B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,EAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;gBACZ,OAAO,GAAG,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,AAtBsB,CAsBrB"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement, css, html } from "lit";
|
|
8
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
9
|
+
import { Formula } from "./helpers/types.js";
|
|
10
|
+
import { TextButtonStyles } from "../../styles/src/button-styles.js";
|
|
11
|
+
let FormulaBuilder = class FormulaBuilder extends LitElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.variables = new Map([
|
|
15
|
+
["sales_expense", 2],
|
|
16
|
+
["sales_in_quarter", 3],
|
|
17
|
+
["sales_cummulative", 3],
|
|
18
|
+
["cummulative_sum", 4],
|
|
19
|
+
["mayank", 10],
|
|
20
|
+
]);
|
|
21
|
+
this.formula = new Formula("", "");
|
|
22
|
+
this.handleCalculate = () => {
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = this.formulaEditor) === null || _a === void 0 ? void 0 : _a.requestCalculate();
|
|
25
|
+
};
|
|
26
|
+
this.handleFormat = () => {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = this.formulaEditor) === null || _a === void 0 ? void 0 : _a.requestFormat();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
handleChange() {
|
|
32
|
+
var _a;
|
|
33
|
+
this.dispatchEvent(new CustomEvent("fw-formula-changed", {
|
|
34
|
+
detail: {
|
|
35
|
+
name: (_a = this.nameInput) === null || _a === void 0 ? void 0 : _a.value,
|
|
36
|
+
rawFormula: this.formula.formulaString,
|
|
37
|
+
error: this.formula.error,
|
|
38
|
+
precision: this.formula.precision,
|
|
39
|
+
},
|
|
40
|
+
bubbles: true,
|
|
41
|
+
}));
|
|
42
|
+
this.requestUpdate();
|
|
43
|
+
}
|
|
44
|
+
render() {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return html `
|
|
47
|
+
${TextButtonStyles}
|
|
48
|
+
|
|
49
|
+
<div>
|
|
50
|
+
<label for="metric-name-input">Metric Name</label>
|
|
51
|
+
<input
|
|
52
|
+
id="metric-name-input"
|
|
53
|
+
.value=${this.formula.name}
|
|
54
|
+
@input=${(e) => {
|
|
55
|
+
this.handleChange();
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
<label>Formula</label>
|
|
60
|
+
<formula-editor
|
|
61
|
+
class="fe"
|
|
62
|
+
minSuggestionLen="0"
|
|
63
|
+
@fw-formula-content-changed=${(e) => {
|
|
64
|
+
this.formula.formulaString = e.detail.formulaString;
|
|
65
|
+
this.formula.error = e.detail.error;
|
|
66
|
+
this.handleChange();
|
|
67
|
+
}}
|
|
68
|
+
.variables=${this.variables}
|
|
69
|
+
.content=${this.formula.formulaString}
|
|
70
|
+
.errorString=${this.formula.error}
|
|
71
|
+
>
|
|
72
|
+
</formula-editor>
|
|
73
|
+
<div id="wysiwyg-err" class="${(_a = this.formula.error) !== null && _a !== void 0 ? _a : "wysiwyg-no-err"}">
|
|
74
|
+
${(_b = this.formula.error) !== null && _b !== void 0 ? _b : `${this.formula.name} = ${this.formula.formulaString}`}
|
|
75
|
+
</div>
|
|
76
|
+
<button class="primary-text-button" @click=${this.handleCalculate}>
|
|
77
|
+
Calculate
|
|
78
|
+
</button>
|
|
79
|
+
<button class="primary-text-button" @click=${this.handleFormat}>
|
|
80
|
+
Format
|
|
81
|
+
</button>
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
FormulaBuilder.styles = css `
|
|
86
|
+
#wysiwyg-err {
|
|
87
|
+
width: 100%;
|
|
88
|
+
border-radius: 0px 0px var(--fe-err-border-radius, 4px)
|
|
89
|
+
var(--fe-err-border-radius, 4px);
|
|
90
|
+
color: var(--fe-err-text-color, #fc514f);
|
|
91
|
+
border: var(--fe-err-border-width, 2px) solid black;
|
|
92
|
+
/* border-top: 0px; */
|
|
93
|
+
background-color: var(--fe-background-color, #222222);
|
|
94
|
+
padding: 4px;
|
|
95
|
+
margin: 0px 0px 8px 0px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.wysiwyg-no-err {
|
|
99
|
+
color: #098668 !important;
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
__decorate([
|
|
103
|
+
property({
|
|
104
|
+
type: (Map),
|
|
105
|
+
converter: {
|
|
106
|
+
fromAttribute: (value) => {
|
|
107
|
+
if (value) {
|
|
108
|
+
return new Map(JSON.parse(value));
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
toAttribute: (value) => {
|
|
112
|
+
return JSON.stringify(Array.from(value.entries()));
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
], FormulaBuilder.prototype, "variables", void 0);
|
|
117
|
+
__decorate([
|
|
118
|
+
property({
|
|
119
|
+
type: Formula,
|
|
120
|
+
converter: {
|
|
121
|
+
fromAttribute: (value) => {
|
|
122
|
+
if (value) {
|
|
123
|
+
const formulaJSON = JSON.parse(value);
|
|
124
|
+
return new Formula(formulaJSON.name, formulaJSON.formulaString, formulaJSON.precision);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
toAttribute: (value) => {
|
|
128
|
+
return JSON.stringify(value);
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
], FormulaBuilder.prototype, "formula", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
property()
|
|
135
|
+
], FormulaBuilder.prototype, "handleCalculate", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
property()
|
|
138
|
+
], FormulaBuilder.prototype, "handleFormat", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
query("#metric-name-input")
|
|
141
|
+
], FormulaBuilder.prototype, "nameInput", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
query("formula-editor")
|
|
144
|
+
], FormulaBuilder.prototype, "formulaEditor", void 0);
|
|
145
|
+
FormulaBuilder = __decorate([
|
|
146
|
+
customElement("formula-builder")
|
|
147
|
+
], FormulaBuilder);
|
|
148
|
+
//# sourceMappingURL=formula-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formula-builder.js","sourceRoot":"","sources":["formula-builder.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAIrE,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,UAAU;IAAvC;;QAg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AChB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,aAAa,EACzB,WAAW,CAAC,SAAS,CACtB,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;gBACrB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC;SACF;KACF,CAAC;+CAC4B;AAG9B;IADC,QAAQ,EAAE;uDAGT;AAGF;IADC,QAAQ,EAAE;oDAGT;AAGF;IADC,KAAK,CAAC,oBAAoB,CAAC;iDACY;AAGxC;IADC,KAAK,CAAC,gBAAgB,CAAC;qDACiB;AA1ErC,cAAc;IADnB,aAAa,CAAC,iBAAiB,CAAC;GAC3B,cAAc,CAoInB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement, html } from "lit";
|
|
8
|
+
import { customElement, state } from "lit/decorators.js";
|
|
9
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
10
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
11
|
+
import { Operator } from "./helpers/types";
|
|
12
|
+
var FormulaEntityType;
|
|
13
|
+
(function (FormulaEntityType) {
|
|
14
|
+
FormulaEntityType[FormulaEntityType["Operator"] = 0] = "Operator";
|
|
15
|
+
FormulaEntityType[FormulaEntityType["Entity"] = 1] = "Entity";
|
|
16
|
+
})(FormulaEntityType || (FormulaEntityType = {}));
|
|
17
|
+
class FormulaEntity {
|
|
18
|
+
constructor(type, metric, operator = Operator.NONE) {
|
|
19
|
+
this.type = type;
|
|
20
|
+
this.metric = metric;
|
|
21
|
+
this.operator = operator;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class FormulaRow {
|
|
25
|
+
constructor(type, metrices = null, operator = Operator.NONE) {
|
|
26
|
+
this.operator = Operator.NONE;
|
|
27
|
+
this.type = type;
|
|
28
|
+
this.metrices = metrices;
|
|
29
|
+
this.operator = operator;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
let FormulaCreator = class FormulaCreator extends LitElement {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
this.formulaState = [
|
|
36
|
+
new FormulaRow(FormulaEntityType.Entity, [
|
|
37
|
+
new FormulaEntity(FormulaEntityType.Entity, "Sales Expense"),
|
|
38
|
+
new FormulaEntity(FormulaEntityType.Operator, null, Operator.MINUS),
|
|
39
|
+
new FormulaEntity(FormulaEntityType.Entity, "Marketing Expense"),
|
|
40
|
+
]),
|
|
41
|
+
new FormulaRow(FormulaEntityType.Operator, null, Operator.DIV),
|
|
42
|
+
new FormulaRow(FormulaEntityType.Entity, [
|
|
43
|
+
new FormulaEntity(FormulaEntityType.Entity, "Sales Expense"),
|
|
44
|
+
new FormulaEntity(FormulaEntityType.Operator, null, Operator.PLUS),
|
|
45
|
+
new FormulaEntity(FormulaEntityType.Entity, "Marketing Expense"),
|
|
46
|
+
]),
|
|
47
|
+
new FormulaRow(FormulaEntityType.Operator, null, Operator.DIV),
|
|
48
|
+
new FormulaRow(FormulaEntityType.Entity, [
|
|
49
|
+
new FormulaEntity(FormulaEntityType.Entity, "Sales Expense"),
|
|
50
|
+
new FormulaEntity(FormulaEntityType.Operator, null, Operator.DIV),
|
|
51
|
+
new FormulaEntity(FormulaEntityType.Entity, "Marketing Expense"),
|
|
52
|
+
]),
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
render() {
|
|
56
|
+
return html `
|
|
57
|
+
<label>Formula</label>
|
|
58
|
+
${repeat(this.formulaState, (_, rowIndex) => `row-${rowIndex}`, (formulaRow, rowIndex) => {
|
|
59
|
+
return formulaRow.type == FormulaEntityType.Entity
|
|
60
|
+
? html ` <div>
|
|
61
|
+
${repeat(formulaRow.metrices, (_, columnIndex) => `col-(${rowIndex},${columnIndex})`, (formulaEntity, columnIndex) => {
|
|
62
|
+
return formulaEntity.type == FormulaEntityType.Entity
|
|
63
|
+
? html `<input
|
|
64
|
+
value=${ifDefined(formulaEntity.metric === null
|
|
65
|
+
? undefined
|
|
66
|
+
: formulaEntity.metric)}
|
|
67
|
+
/>`
|
|
68
|
+
: html `<operator-input
|
|
69
|
+
.operator=${formulaEntity.operator}
|
|
70
|
+
></operator-input>`;
|
|
71
|
+
})}
|
|
72
|
+
</div>`
|
|
73
|
+
: html `<div>${formulaRow.operator}</div>`;
|
|
74
|
+
})}
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
__decorate([
|
|
79
|
+
state()
|
|
80
|
+
], FormulaCreator.prototype, "formulaState", void 0);
|
|
81
|
+
FormulaCreator = __decorate([
|
|
82
|
+
customElement("formula-creator")
|
|
83
|
+
], FormulaCreator);
|
|
84
|
+
//# sourceMappingURL=formula-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formula-creator.js","sourceRoot":"","sources":["formula-creator.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,IAAK,iBAGJ;AAHD,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,CAAC,CACF;qBACI;gBACT,CAAC,CAAC,IAAI,CAAA,QAAQ,UAAU,CAAC,QAAQ,QAAQ,CAAC;QAC9C,CAAC,CACF;KACF,CAAC;IACJ,CAAC;CACF,CAAA;AApDC;IADC,KAAK,EAAE;oDAmBN;AApBE,cAAc;IADnB,aAAa,CAAC,iBAAiB,CAAC;GAC3B,cAAc,CAsDnB"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, LitElement } from "lit";
|
|
8
|
+
import { customElement, property, state, query } from "lit/decorators.js";
|
|
9
|
+
import { FormulaEditorStyles } from "./styles/formula-editor-styles.js";
|
|
10
|
+
import { Parser } from "./parser.js";
|
|
11
|
+
import { Cursor } from "./cursor.js";
|
|
12
|
+
import "./suggestion-menu.js";
|
|
13
|
+
let FormulaEditor = class FormulaEditor extends LitElement {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
/**
|
|
17
|
+
* These `states` and `properties` can't be defined as `static get properties`,
|
|
18
|
+
* because TS doesn't support that.
|
|
19
|
+
* @see https://github.com/lit/lit-element/issues/414
|
|
20
|
+
*/
|
|
21
|
+
this._formattedContent = null;
|
|
22
|
+
this._recommendations = null;
|
|
23
|
+
this._calculatedResult = undefined;
|
|
24
|
+
/**
|
|
25
|
+
* If `parseInput` is called to add a recommendation, say by clicking,
|
|
26
|
+
* browser removes focus from the input box. In that case, we have no way
|
|
27
|
+
* of knowing where the cursor previously was, other than storing it somewhere.
|
|
28
|
+
*/
|
|
29
|
+
this.currentCursorPosition = null;
|
|
30
|
+
this.currentCursorRect = undefined;
|
|
31
|
+
this.lastInputType = "undef";
|
|
32
|
+
this.content = "";
|
|
33
|
+
this.variables = new Map();
|
|
34
|
+
this.minSuggestionLen = 2;
|
|
35
|
+
this.errorString = null;
|
|
36
|
+
this._parser = new Parser(this.variables, this.minSuggestionLen);
|
|
37
|
+
}
|
|
38
|
+
firstUpdated(_changedProperties) {
|
|
39
|
+
this._parser = new Parser(this.variables, this.minSuggestionLen);
|
|
40
|
+
this.parseInput(null, false);
|
|
41
|
+
}
|
|
42
|
+
handleChange(event) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
this.lastInputType = event.inputType;
|
|
45
|
+
this.content = event.target.innerText;
|
|
46
|
+
this.parseInput();
|
|
47
|
+
event.target.focus();
|
|
48
|
+
}
|
|
49
|
+
handleTab(event) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (event.code == "Tab" && ((_a = this._recommendations) === null || _a === void 0 ? void 0 : _a.length) == 1) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
this.parseInput(this._recommendations[0]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
onClickRecommendation(recommendation) {
|
|
57
|
+
var _a;
|
|
58
|
+
let editor = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById("wysiwyg-editor");
|
|
59
|
+
if (!editor)
|
|
60
|
+
return;
|
|
61
|
+
this.parseInput(recommendation);
|
|
62
|
+
this.currentCursorPosition = null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param recommendation The recommendation which needs to be inserted
|
|
67
|
+
* at the current cursor position
|
|
68
|
+
* @param manageCursor Whether or not cursor management is needed. Not
|
|
69
|
+
* needed when manual insertion of text is required (eg: during initialization)
|
|
70
|
+
* @returns void
|
|
71
|
+
*/
|
|
72
|
+
parseInput(recommendation = null, manageCursor = true) {
|
|
73
|
+
var _a;
|
|
74
|
+
let editor = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById("wysiwyg-editor");
|
|
75
|
+
if (!editor)
|
|
76
|
+
return;
|
|
77
|
+
/**
|
|
78
|
+
* @see https://github.com/WICG/webcomponents/issues/79
|
|
79
|
+
*/
|
|
80
|
+
if (manageCursor)
|
|
81
|
+
this.currentCursorPosition = recommendation
|
|
82
|
+
? this.currentCursorPosition
|
|
83
|
+
: Cursor.getCaretPosition(this.shadowRoot, editor);
|
|
84
|
+
const parseOutput = this._parser.parseInput(this.content, this.currentCursorPosition, recommendation);
|
|
85
|
+
this._recommendations = parseOutput.recommendations;
|
|
86
|
+
this._formattedContent = parseOutput.formattedContent;
|
|
87
|
+
this.errorString = parseOutput.errorString;
|
|
88
|
+
/**
|
|
89
|
+
* Don't modify the text stream manually if the text is being composed,
|
|
90
|
+
* unless the user manually chooses to do so by selecting a suggestion.
|
|
91
|
+
* @see https://github.com/w3c/input-events/issues/86
|
|
92
|
+
* @see https://github.com/w3c/input-events/pull/122
|
|
93
|
+
* @see https://bugs.chromium.org/p/chromium/issues/detail?id=689541
|
|
94
|
+
* */
|
|
95
|
+
if (this.lastInputType != "insertCompositionText" || recommendation) {
|
|
96
|
+
editor.innerHTML = parseOutput.formattedString;
|
|
97
|
+
}
|
|
98
|
+
this.content = editor.innerText;
|
|
99
|
+
if (recommendation) {
|
|
100
|
+
this._recommendations = null;
|
|
101
|
+
this.currentCursorPosition = parseOutput.newCursorPosition;
|
|
102
|
+
}
|
|
103
|
+
if (manageCursor)
|
|
104
|
+
Cursor.setCaretPosition(this.currentCursorPosition, editor);
|
|
105
|
+
editor === null || editor === void 0 ? void 0 : editor.focus();
|
|
106
|
+
if (manageCursor)
|
|
107
|
+
this.currentCursorRect = Cursor.getCursorRect(this.shadowRoot);
|
|
108
|
+
this.requestUpdate();
|
|
109
|
+
this.dispatchEvent(new CustomEvent("fw-formula-content-changed", {
|
|
110
|
+
detail: {
|
|
111
|
+
formulaString: this.content,
|
|
112
|
+
error: this.errorString,
|
|
113
|
+
},
|
|
114
|
+
bubbles: true,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
requestCalculate() {
|
|
118
|
+
var _a;
|
|
119
|
+
if (this._parser.parseInput(this.content).errorString) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const calculatedResult = this._parser.calculate(this.content);
|
|
123
|
+
this.content = (_a = this._parser.addParentheses(this.content)) !== null && _a !== void 0 ? _a : this.content;
|
|
124
|
+
this.parseInput();
|
|
125
|
+
this._calculatedResult = calculatedResult.result;
|
|
126
|
+
this.errorString = calculatedResult.errorString;
|
|
127
|
+
this._recommendations = null;
|
|
128
|
+
this.requestUpdate();
|
|
129
|
+
}
|
|
130
|
+
requestFormat() {
|
|
131
|
+
var _a;
|
|
132
|
+
this.content = (_a = this._parser.addParentheses(this.content)) !== null && _a !== void 0 ? _a : this.content;
|
|
133
|
+
this.parseInput();
|
|
134
|
+
this._recommendations = null;
|
|
135
|
+
this.requestUpdate();
|
|
136
|
+
}
|
|
137
|
+
render() {
|
|
138
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
139
|
+
return html `
|
|
140
|
+
<style>
|
|
141
|
+
${FormulaEditorStyles}
|
|
142
|
+
</style>
|
|
143
|
+
<div
|
|
144
|
+
contenteditable
|
|
145
|
+
id="wysiwyg-editor"
|
|
146
|
+
spellcheck="false"
|
|
147
|
+
autocomplete="off"
|
|
148
|
+
@input=${this.handleChange}
|
|
149
|
+
@keydown=${this.handleTab}
|
|
150
|
+
></div>
|
|
151
|
+
${this._recommendations
|
|
152
|
+
? html ` <suggestion-menu
|
|
153
|
+
style="
|
|
154
|
+
position: absolute;
|
|
155
|
+
left: ${((_b = (_a = this.currentCursorRect) === null || _a === void 0 ? void 0 : _a.left) !== null && _b !== void 0 ? _b : 0) -
|
|
156
|
+
((_e = (_d = (_c = this.editor) === null || _c === void 0 ? void 0 : _c.getClientRect()[0]) === null || _d === void 0 ? void 0 : _d.left) !== null && _e !== void 0 ? _e : 0) +
|
|
157
|
+
"px"};
|
|
158
|
+
top: ${((_g = (_f = this.currentCursorRect) === null || _f === void 0 ? void 0 : _f.top) !== null && _g !== void 0 ? _g : 0 - ((_k = (_j = (_h = this.editor) === null || _h === void 0 ? void 0 : _h.getClientRect()[0]) === null || _j === void 0 ? void 0 : _j.top) !== null && _k !== void 0 ? _k : 0)) +
|
|
159
|
+
window.scrollY +
|
|
160
|
+
"px"};
|
|
161
|
+
"
|
|
162
|
+
.recommendations=${this._recommendations}
|
|
163
|
+
.onClickRecommendation=${(e) => this.onClickRecommendation(e)}
|
|
164
|
+
></suggestion-menu>`
|
|
165
|
+
: html ``}
|
|
166
|
+
<p>${this._calculatedResult}</p>
|
|
167
|
+
`;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
__decorate([
|
|
171
|
+
state()
|
|
172
|
+
], FormulaEditor.prototype, "_formattedContent", void 0);
|
|
173
|
+
__decorate([
|
|
174
|
+
state()
|
|
175
|
+
], FormulaEditor.prototype, "_recommendations", void 0);
|
|
176
|
+
__decorate([
|
|
177
|
+
state()
|
|
178
|
+
], FormulaEditor.prototype, "_calculatedResult", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
state()
|
|
181
|
+
], FormulaEditor.prototype, "currentCursorPosition", void 0);
|
|
182
|
+
__decorate([
|
|
183
|
+
state()
|
|
184
|
+
], FormulaEditor.prototype, "currentCursorRect", void 0);
|
|
185
|
+
__decorate([
|
|
186
|
+
state()
|
|
187
|
+
], FormulaEditor.prototype, "lastInputType", void 0);
|
|
188
|
+
__decorate([
|
|
189
|
+
property()
|
|
190
|
+
], FormulaEditor.prototype, "content", void 0);
|
|
191
|
+
__decorate([
|
|
192
|
+
property({
|
|
193
|
+
type: (Map),
|
|
194
|
+
converter: {
|
|
195
|
+
fromAttribute: (value) => {
|
|
196
|
+
if (value) {
|
|
197
|
+
return new Map(JSON.parse(value));
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
toAttribute: (value) => {
|
|
201
|
+
return JSON.stringify(Array.from(value.entries()));
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
], FormulaEditor.prototype, "variables", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
property()
|
|
208
|
+
], FormulaEditor.prototype, "minSuggestionLen", void 0);
|
|
209
|
+
__decorate([
|
|
210
|
+
property()
|
|
211
|
+
], FormulaEditor.prototype, "errorString", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
query("wysiwyg-editor")
|
|
214
|
+
], FormulaEditor.prototype, "editor", void 0);
|
|
215
|
+
FormulaEditor = __decorate([
|
|
216
|
+
customElement("formula-editor")
|
|
217
|
+
], FormulaEditor);
|
|
218
|
+
export { FormulaEditor };
|
|
219
|
+
//# sourceMappingURL=formula-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formula-editor.js","sourceRoot":"","sources":["formula-editor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAoB,MAAM,KAAK,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,sBAAsB,CAAC;AAGvB,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IAG3C;QACE,KAAK,EAAE,CAAC;QAYV;;;;WAIG;QAGH,sBAAiB,GAAmB,IAAI,CAAC;QAGzC,qBAAgB,GAAoB,IAAI,CAAC;QAGzC,sBAAiB,GAAuB,SAAS,CAAC;QAElD;;;;WAIG;QA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,SAAS,EAAE;YACT,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvB,IAAI,KAAK,EAAE,CAAC;oBACV,OAAO,IAAI,GAAG,CAAiB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBACpD,CAAC;YACH,CAAC;YACD,WAAW,EAAE,CAAC,KAA0B,EAAE,EAAE;gBAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACrD,CAAC;SACF;KACF,CAAC;gDACoB;AAGtB;IADC,QAAQ,EAAE;uDACkB;AAG7B;IADC,QAAQ,EAAE;kDACuB;AAGlC;IADC,KAAK,CAAC,gBAAgB,CAAC;6CACZ;AAvED,aAAa;IADzB,aAAa,CAAC,gBAAgB,CAAC;GACnB,aAAa,CAmOzB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export var Operator;
|
|
2
|
+
(function (Operator) {
|
|
3
|
+
Operator["PLUS"] = "+";
|
|
4
|
+
Operator["MINUS"] = "-";
|
|
5
|
+
Operator["MUL"] = "*";
|
|
6
|
+
Operator["DIV"] = "/";
|
|
7
|
+
Operator["NONE"] = "";
|
|
8
|
+
})(Operator || (Operator = {}));
|
|
9
|
+
export class Formula {
|
|
10
|
+
constructor(name, formulaString, precision = -1) {
|
|
11
|
+
this.error = null;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.formulaString = formulaString;
|
|
14
|
+
this.precision = precision;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,sBAAU,CAAA;IACV,uBAAW,CAAA;IACX,qBAAS,CAAA;IACT,qBAAS,CAAA;IACT,qBAAS,CAAA;AACX,CAAC,EANW,QAAQ,KAAR,QAAQ,QAMnB;AAED,MAAM,OAAO,OAAO;IAClB,YAAY,IAAY,EAAE,aAAqB,EAAE,YAAoB,CAAC,CAAC;QASvE,UAAK,GAAkB,IAAI,CAAC;QAR1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CAMF"}
|