@fw-components/formula-editor 2.0.7-formula-editor-enhancements.12 → 2.0.7-formula-editor.22
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/formula-editor.js +84 -174
- package/dist/formula-editor/src/styles/{formula-editor-styles.js → editor.js} +2 -2
- package/dist/formula-editor/src/styles/suggestion-menu.js +58 -0
- package/dist/formula-editor/src/suggestion-menu.js +45 -88
- package/dist/formula-editor/src/{helpers/types.js → types/index.js} +6 -0
- package/dist/formula-editor/src/utils/constants.js +8 -0
- package/dist/formula-editor/src/{parser.js → utils/parser.js} +89 -136
- package/dist/formula-editor/src/utils/queue.js +28 -0
- package/dist/formula-editor/src/utils/recommendor.js +15 -0
- package/dist/formula-editor/src/utils/stack.js +20 -0
- package/package.json +9 -3
- package/dist/formula-editor/src/cursor.js +0 -142
- package/dist/formula-editor/src/formula-builder.js +0 -139
- package/dist/formula-editor/src/formula-creator.js +0 -83
- package/dist/formula-editor/src/helpers.js +0 -54
- package/dist/formula-editor/src/recommendor.js +0 -18
- package/dist/formula-editor/src/sub-components/operator-input.js +0 -24
- package/dist/styles/src/button-styles.js +0 -419
|
@@ -1,139 +0,0 @@
|
|
|
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
|
-
import "./formula-editor";
|
|
12
|
-
let FormulaBuilder = class FormulaBuilder extends LitElement {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
this.variables = new Map([
|
|
16
|
-
["sales_expense", 2],
|
|
17
|
-
["sales_in_quarter", 3],
|
|
18
|
-
["sales_cummulative", 3],
|
|
19
|
-
["cummulative_sum", 4],
|
|
20
|
-
["mayank", 10],
|
|
21
|
-
]);
|
|
22
|
-
this.formula = new Formula("", "");
|
|
23
|
-
this.handleCalculate = () => {
|
|
24
|
-
this.formulaEditor?.requestCalculate();
|
|
25
|
-
};
|
|
26
|
-
this.handleFormat = () => {
|
|
27
|
-
this.formulaEditor?.requestFormat();
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
static { this.styles = css `
|
|
31
|
-
#wysiwyg-err {
|
|
32
|
-
width: 100%;
|
|
33
|
-
border-radius: 0px 0px var(--fe-err-border-radius, 4px)
|
|
34
|
-
var(--fe-err-border-radius, 4px);
|
|
35
|
-
color: var(--fe-err-text-color, #fc514f);
|
|
36
|
-
border: var(--fe-err-border-width, 2px) solid black;
|
|
37
|
-
/* border-top: 0px; */
|
|
38
|
-
background-color: var(--fe-background-color, #222222);
|
|
39
|
-
padding: 4px;
|
|
40
|
-
margin: 0px 0px 8px 0px;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.wysiwyg-no-err {
|
|
44
|
-
color: #098668 !important;
|
|
45
|
-
}
|
|
46
|
-
`; }
|
|
47
|
-
handleChange() {
|
|
48
|
-
this.dispatchEvent(new CustomEvent("fw-formula-changed", {
|
|
49
|
-
detail: {
|
|
50
|
-
name: this.nameInput?.value,
|
|
51
|
-
rawFormula: this.formula.formulaString,
|
|
52
|
-
error: this.formula.error,
|
|
53
|
-
precision: this.formula.precision,
|
|
54
|
-
},
|
|
55
|
-
bubbles: true,
|
|
56
|
-
}));
|
|
57
|
-
this.requestUpdate();
|
|
58
|
-
}
|
|
59
|
-
render() {
|
|
60
|
-
return html `
|
|
61
|
-
${TextButtonStyles}
|
|
62
|
-
|
|
63
|
-
<div>
|
|
64
|
-
<label for="metric-name-input">Metric Name</label>
|
|
65
|
-
<input
|
|
66
|
-
id="metric-name-input"
|
|
67
|
-
.value=${this.formula.name}
|
|
68
|
-
@input=${(e) => {
|
|
69
|
-
this.handleChange();
|
|
70
|
-
}}
|
|
71
|
-
/>
|
|
72
|
-
</div>
|
|
73
|
-
<label>Formula</label>
|
|
74
|
-
<formula-editor
|
|
75
|
-
class="fe"
|
|
76
|
-
minSuggestionLen="0"
|
|
77
|
-
@fw-formula-content-changed=${(e) => {
|
|
78
|
-
this.formula.formulaString = e.detail.formulaString;
|
|
79
|
-
this.formula.error = e.detail.error;
|
|
80
|
-
this.handleChange();
|
|
81
|
-
}}
|
|
82
|
-
.variables=${this.variables}
|
|
83
|
-
.content=${this.formula.formulaString}
|
|
84
|
-
.errorString=${this.formula.error}
|
|
85
|
-
>
|
|
86
|
-
</formula-editor>
|
|
87
|
-
<div id="wysiwyg-err" class="${this.formula.error ?? "wysiwyg-no-err"}">
|
|
88
|
-
${this.formula.error ??
|
|
89
|
-
`${this.formula.name} = ${this.formula.formulaString}`}
|
|
90
|
-
</div>
|
|
91
|
-
<button class="primary-text-button" @click=${this.handleCalculate}>
|
|
92
|
-
Calculate
|
|
93
|
-
</button>
|
|
94
|
-
<button class="primary-text-button" @click=${this.handleFormat}>
|
|
95
|
-
Format
|
|
96
|
-
</button>
|
|
97
|
-
`;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
__decorate([
|
|
101
|
-
property({
|
|
102
|
-
type: (Map),
|
|
103
|
-
converter: {
|
|
104
|
-
fromAttribute: (value) => {
|
|
105
|
-
if (value) {
|
|
106
|
-
return new Map(JSON.parse(value));
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
toAttribute: (value) => {
|
|
110
|
-
return JSON.stringify(Array.from(value.entries()));
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
})
|
|
114
|
-
], FormulaBuilder.prototype, "variables", void 0);
|
|
115
|
-
__decorate([
|
|
116
|
-
property({
|
|
117
|
-
type: Formula,
|
|
118
|
-
converter: {
|
|
119
|
-
fromAttribute: (value) => {
|
|
120
|
-
if (value) {
|
|
121
|
-
const formulaJSON = JSON.parse(value);
|
|
122
|
-
return new Formula(formulaJSON.name, formulaJSON.formulaString, formulaJSON.precision);
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
toAttribute: (value) => {
|
|
126
|
-
return JSON.stringify(value);
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
})
|
|
130
|
-
], FormulaBuilder.prototype, "formula", void 0);
|
|
131
|
-
__decorate([
|
|
132
|
-
query("#metric-name-input")
|
|
133
|
-
], FormulaBuilder.prototype, "nameInput", void 0);
|
|
134
|
-
__decorate([
|
|
135
|
-
query("formula-editor")
|
|
136
|
-
], FormulaBuilder.prototype, "formulaEditor", void 0);
|
|
137
|
-
FormulaBuilder = __decorate([
|
|
138
|
-
customElement("formula-builder")
|
|
139
|
-
], FormulaBuilder);
|
|
@@ -1,83 +0,0 @@
|
|
|
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);
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export class Stack {
|
|
2
|
-
constructor() {
|
|
3
|
-
this._elements = [];
|
|
4
|
-
}
|
|
5
|
-
push(item) {
|
|
6
|
-
this._elements.push(item);
|
|
7
|
-
}
|
|
8
|
-
pop() {
|
|
9
|
-
return this._elements.pop();
|
|
10
|
-
}
|
|
11
|
-
top() {
|
|
12
|
-
return this._elements.at(-1);
|
|
13
|
-
}
|
|
14
|
-
isEmpty() {
|
|
15
|
-
return this._elements.length == 0;
|
|
16
|
-
}
|
|
17
|
-
print() {
|
|
18
|
-
console.log(this._elements);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export class Queue {
|
|
22
|
-
constructor() {
|
|
23
|
-
this._elements = {};
|
|
24
|
-
this._head = 0;
|
|
25
|
-
this._tail = 0;
|
|
26
|
-
}
|
|
27
|
-
enqueue(item) {
|
|
28
|
-
this._elements[this._tail] = item;
|
|
29
|
-
this._tail++;
|
|
30
|
-
}
|
|
31
|
-
dequeue() {
|
|
32
|
-
if (this._tail === this._head)
|
|
33
|
-
return undefined;
|
|
34
|
-
const element = this._elements[this._head];
|
|
35
|
-
delete this._elements[this._head];
|
|
36
|
-
this._head++;
|
|
37
|
-
return element;
|
|
38
|
-
}
|
|
39
|
-
peek() {
|
|
40
|
-
return this._elements[this._head];
|
|
41
|
-
}
|
|
42
|
-
isEmpty() {
|
|
43
|
-
return this._head == this._tail;
|
|
44
|
-
}
|
|
45
|
-
print() {
|
|
46
|
-
console.log(this._elements);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export var Expectation;
|
|
50
|
-
(function (Expectation) {
|
|
51
|
-
Expectation[Expectation["VARIABLE"] = 0] = "VARIABLE";
|
|
52
|
-
Expectation[Expectation["OPERATOR"] = 1] = "OPERATOR";
|
|
53
|
-
Expectation[Expectation["UNDEFINED"] = 2] = "UNDEFINED";
|
|
54
|
-
})(Expectation || (Expectation = {}));
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { matchSorter } from 'match-sorter';
|
|
2
|
-
export class Recommender {
|
|
3
|
-
constructor(variables, minSuggestionLen) {
|
|
4
|
-
this._minimumSuggestionLength = minSuggestionLen > 0 ? minSuggestionLen : 1;
|
|
5
|
-
this.variableList = Array.from(variables.keys());
|
|
6
|
-
}
|
|
7
|
-
getRecommendation(word) {
|
|
8
|
-
if (word.length < this._minimumSuggestionLength) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
const recommendations = matchSorter(this.variableList, word);
|
|
12
|
-
if (recommendations.length === 0 ||
|
|
13
|
-
(recommendations.length === 1 && recommendations[0] === word)) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return recommendations;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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, property } from "lit/decorators.js";
|
|
9
|
-
import { Operator } from "../helpers/types";
|
|
10
|
-
let OperatorInput = class OperatorInput extends LitElement {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.operator = Operator.NONE;
|
|
14
|
-
}
|
|
15
|
-
render() {
|
|
16
|
-
return html `<span> ${this.operator} </span>`;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
__decorate([
|
|
20
|
-
property()
|
|
21
|
-
], OperatorInput.prototype, "operator", void 0);
|
|
22
|
-
OperatorInput = __decorate([
|
|
23
|
-
customElement("operator-input")
|
|
24
|
-
], OperatorInput);
|