@fw-components/formula-editor 2.0.3-formula-editor.1 → 2.0.7-formula-editor.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.
@@ -0,0 +1,419 @@
1
+ import { html } from 'lit';
2
+ export const UnderlinedButtonStyles = html `
3
+ <style>
4
+ .primary-text-underlined {
5
+ font-family: var(--theme-font);
6
+ border: none;
7
+ font-size: var(--secondary-font-size, 16px);
8
+ color: var(--primary-color, #205081);
9
+ padding: 0;
10
+ margin: 0;
11
+ border-radius: 0;
12
+ min-width: max-content;
13
+ text-transform: none;
14
+ border-bottom: 1px solid rgba(var(--secondary-color-rgb), 0.3);
15
+ }
16
+
17
+ .secondary-text-underlined {
18
+ font-family: var(--theme-font);
19
+ border: none;
20
+ font-size: var(--secondary-font-size, 16px);
21
+ color: var(--secondary-color, #515151);
22
+ margin: 0;
23
+ padding: 0;
24
+ border-radius: 0;
25
+ min-width: max-content;
26
+ text-transform: none;
27
+ border-bottom: 1px solid rgba(var(--secondary-color-rgb), 0.3);
28
+ }
29
+ </style>
30
+ `;
31
+ export const TextButtonStyles = html `
32
+ <style>
33
+ .primary-text-button {
34
+ font-family: var(--theme-font);
35
+ border: none;
36
+ font-size: var(--secondary-font-size, 16px);
37
+ color: var(--primary-color, #205081);
38
+ padding: 0 8px;
39
+ min-width: 64px;
40
+ height: var(--button-height, 36px);
41
+ margin: 0;
42
+ text-transform: none;
43
+ }
44
+
45
+ .secondary-text-button {
46
+ font-family: var(--theme-font);
47
+ border: none;
48
+ font-size: var(--secondary-font-size, 16px);
49
+ color: var(--secondary-color, #515151);
50
+ padding: 0 8px;
51
+ min-width: 64px;
52
+ margin: 0;
53
+ height: var(--button-height, 36px);
54
+ text-transform: none;
55
+ }
56
+
57
+ .primary-text-button:hover {
58
+ font-weight: bold;
59
+ }
60
+
61
+ .secondary-text-button:hover {
62
+ font-weight: bold;
63
+ }
64
+
65
+ .primary-text-button[disabled], .secondary-text-button[disabled] {
66
+ opacity: 0.5;
67
+ }
68
+ </style>
69
+ `;
70
+ export const PrimaryButtonStyles = html `
71
+ <style>
72
+ .primary-outlined {
73
+ font-family: var(--theme-font);
74
+ border: 1px solid var(--primary-color, #205081);
75
+ border-radius: 5px;
76
+ font-size: var(--secondary-font-size, 16px);
77
+ color: var(--secondary-color, #515151);
78
+ padding: 0 var(--button-padding, 16px);
79
+ min-width: 64px;
80
+ margin: 0;
81
+ height: var(--button-height, 36px);
82
+ text-transform: none;
83
+ }
84
+ .primary-outlined:hover {
85
+ background-color: var(--primary-color, #205081);
86
+ color: var(--light-color, #fff);
87
+ }
88
+ .primary-colored {
89
+ font-family: var(--theme-font);
90
+ background-color: var(--primary-color, #205081);
91
+ border-radius: 5px;
92
+ font-size: var(--secondary-font-size, 16px);
93
+ color: var(--light-color, #fff);
94
+ margin: 0;
95
+ padding: 0 var(--button-padding, 16px);
96
+ min-width: 64px;
97
+ height: var(--button-height, 36px);
98
+ text-transform: none;
99
+ }
100
+ .primary-colored:hover {
101
+ box-shadow: 0 1px 2px 1px var(--primary-color, #205081);
102
+ }
103
+ .primary-outlined[disabled], .primary-colored[disabled] {
104
+ opacity: 0.5;
105
+ }
106
+ </style>
107
+ `;
108
+ export const SecondaryButtonStyles = html `
109
+ <style>
110
+ .secondary-outlined {
111
+ font-family: var(--theme-font);
112
+ border: 1px solid rgba(var(--secondary-color-rgb), 0.3);
113
+ border-radius: 5px;
114
+ font-size: var(--secondary-font-size, 16px);
115
+ color: var(--secondary-color, #515151);
116
+ padding: 0 var(--button-padding, 16px);
117
+ margin: 0;
118
+ min-width: 64px;
119
+ height: var(--button-height, 36px);
120
+ text-transform: none;
121
+ }
122
+
123
+ .secondary-outlined:hover {
124
+ background-color: var(--secondary-color, #515151);
125
+ color: var(--light-color, #fff);
126
+ }
127
+
128
+ .secondary-colored {
129
+ font-family: var(--theme-font);
130
+ background-color: var(--secondary-color, #515151);
131
+ border-radius: 5px;
132
+ font-size: var(--secondary-font-size, 16px);
133
+ color: var(--light-color, #fff);
134
+ padding: 0 var(--button-padding, 16px);
135
+ margin: 0;
136
+ min-width: 64px;
137
+ height: var(--button-height, 36px);
138
+ text-transform: none;
139
+ }
140
+
141
+ .secondary-colored:hover {
142
+ box-shadow: 0 1px 2px 1px var(--secondary-color, #515151);
143
+ }
144
+
145
+ .secondary-outlined[disabled], .secondary-colored[disabled] {
146
+ opacity: 0.5;
147
+ }
148
+ </style>
149
+ `;
150
+ export const AlertButtonStyles = html `
151
+ <style>
152
+ .alert-outlined {
153
+ font-family: var(--theme-font);
154
+ border: 1px solid var(--error-color);
155
+ border-radius: 5px;
156
+ font-size: var(--secondary-font-size, 16px);
157
+ color: var(--error-color, #d50000);
158
+ padding: 0 var(--button-padding, 16px);
159
+ margin: 0;
160
+ min-width: 64px;
161
+ height: var(--button-height, 36px);
162
+ text-transform: none;
163
+ }
164
+
165
+ .alert-outlined:hover {
166
+ background-color: var(--error-color-l1, #db4437);
167
+ color: var(--light-color, #fff);
168
+ }
169
+
170
+ .alert-colored {
171
+ font-family: var(--theme-font);
172
+ background-color: var(--error-color, #d50000);
173
+ border-radius: 5px;
174
+ font-size: var(--secondary-font-size, 16px);
175
+ color: var(--light-color, #fff);
176
+ padding: 0 var(--button-padding, 16px);
177
+ margin: 0;
178
+ min-width: 64px;
179
+ height: var(--button-height, 36px);
180
+ text-transform: none;
181
+ }
182
+
183
+ .alert-colored:hover {
184
+ box-shadow: 0 1px 2px 1px var(--error-color, #d50000);
185
+ }
186
+
187
+ .alert-outlined[disabled], .alert-colored[disabled] {
188
+ opacity: 0.5;
189
+ }
190
+ </style>
191
+ `;
192
+ export const ToggleButtonStyles = html `
193
+ <style>
194
+ .toggle-group {
195
+ display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap;
196
+ }
197
+
198
+ .toggle-group .toggle:first-child{
199
+ border-top-left-radius: 5px; border-bottom-left-radius: 5px;
200
+ }
201
+ .toggle-group .toggle:last-child{
202
+ border-top-right-radius: 5px; border-bottom-right-radius: 5px;
203
+ }
204
+
205
+ .toggle {
206
+ text-transform: none;
207
+ margin: 0px;
208
+ border-radius: 0px;
209
+ background-color: transparent;
210
+ border: 1px solid var(--secondary-color-l3);
211
+ color: var(--secondary-color);
212
+ font-size: var(--secondary-font-size, 16px);
213
+ font-family: var(--theme-font);
214
+ display: flex;
215
+ justify-content: space-around;
216
+ min-width: 64px;
217
+ align-items: center;
218
+ }
219
+
220
+ .toggle.small {
221
+ height: 30px;
222
+ font-size: var(--tertiary-font-size, 14px);
223
+ }
224
+
225
+ .toggle:hover {
226
+ box-shadow: 0 1px 2px 1px rgba(var(--secondary-color-rgb), 0.1);
227
+ }
228
+
229
+ .selected-toggle {
230
+ background-color: var(--secondary-color);
231
+ color: var(--light-color, #fff);
232
+ }
233
+
234
+ .toggle iron-icon{
235
+ --iron-icon-height: var(--body-font-size, 16px);
236
+ margin-right: 5px;
237
+ }
238
+
239
+ .toggle mwc-icon{
240
+ --mdc-icon-size: var(--body-font-size, 16px);
241
+ margin-right: 5px;
242
+ }
243
+ </style>
244
+ `;
245
+ export const FabStyles = html `
246
+ <style>
247
+ paper-fab {
248
+ position: fixed;
249
+ display: flex;
250
+ flex-direction: column;
251
+ justify-content: center;
252
+ align-items: center;
253
+ bottom: 3%;
254
+ right: 2%;
255
+ }
256
+
257
+ paper-fab[disabled], .fab[disabled] {
258
+ opacity: 0.5;
259
+ }
260
+
261
+ .fab {
262
+ font-size: var(--secondary-font-size, 16px);
263
+ position: fixed;
264
+ display: flex;
265
+ justify-content: center;
266
+ align-items: center;
267
+ bottom: 3%;
268
+ right: 2%;
269
+ box-shadow: var(--paper-material-elevation-2_-_box-shadow);
270
+ font-family: var(--theme-font);
271
+ }
272
+
273
+ .colored-fab {
274
+ background-color: var(--secondary-color, #515151);
275
+ --iron-icon-height: var(--h2-font-size, 26px);
276
+ --iron-icon-width: var(--h2-font-size, 26px);
277
+ color: var(--light-color, #fff);
278
+ }
279
+
280
+ .light-colored-fab {
281
+ background-color: var(--light-color, #fff);
282
+ --iron-icon-height: var(--h2-font-size, 20px);
283
+ --iron-icon-width: var(--h2-font-size, 20px);
284
+ color: var(--secondary-color);
285
+ /* --iron-icon-stroke-color: var(--secondary-color); */
286
+ }
287
+
288
+ .light-colored-fab:hover,
289
+ .colored-fab:hover {
290
+ box-shadow: var(--paper-material-elevation-3_-_box-shadow);
291
+ font-weight: bold;
292
+ }
293
+
294
+ .rectangular-fab {
295
+ height: var(--rectangular-fab-height, 50px);
296
+ width: var(--rectangular-fab-width, 120px);
297
+ border-radius: var(--rectangular-fab-height, 50px);
298
+ padding: var(--rectangular-fab-padding, 0px);
299
+ max-height: var(--rectangular-fab-max-height, 50px);
300
+ z-index: var(--rectangular-fab-z-index, 1);
301
+ }
302
+ .small-fab {
303
+ height: 50px;
304
+ width: 50px;
305
+ padding: 5px;
306
+ }
307
+ @media all and (max-width: 767px) {
308
+ .rectangular-fab {
309
+ height: var(--rectangular-fab-height, 40px);
310
+ width: var(--rectangular-fab-width, 120px);
311
+ border-radius: 50px;
312
+ padding: 0;
313
+ --fab-icon-height: 40px;
314
+ }
315
+ }
316
+ </style>
317
+ `;
318
+ export const ButtonSpinnerStyles = html `
319
+ <style>
320
+ .colored-bt-spinner {
321
+ width: 18px;
322
+ height: 18px;
323
+ --paper-spinner-color: var(--light-color, #fff);
324
+ --paper-spinner-stroke-width: 3px;
325
+ margin-right: 8px;
326
+ }
327
+
328
+ .secondary-outlined-bt-spinner {
329
+ width: 18px;
330
+ height: 18px;
331
+ --paper-spinner-color: var(--secondary-color, #fff);
332
+ --paper-spinner-stroke-width: 3px;
333
+ margin-right: 8px;
334
+ }
335
+
336
+ .primary-outlined-bt-spinner {
337
+ width: 18px;
338
+ height: 18px;
339
+ --paper-spinner-color: var(--primary-color, #fff);
340
+ --paper-spinner-stroke-width: 3px;
341
+ margin-right: 8px;
342
+ }
343
+
344
+ .button-prefix-icon {
345
+ --iron-icon-height: var(--body-font-size, 16px);
346
+ --mdc-icon-size: var(--body-font-size, 16px);
347
+ margin-right: 5px;
348
+ }
349
+ </style>
350
+ `;
351
+ export const SmallButtonStyles = html `
352
+ <style>
353
+ .small-button {
354
+ height: 25px !important;
355
+ width: auto !important;
356
+ padding: 0px !important;
357
+ font-size: var(--tertiary-font-size) !important;
358
+ }
359
+ @media all and (max-width: 767px) {
360
+ .small-button{
361
+ height: 20px !important;
362
+ }
363
+ }
364
+ </style>
365
+ `;
366
+ export const PaperToggleButtonStyles = html `
367
+ <custom-style>
368
+ <style>
369
+ paper-toggle-button {
370
+ font-family: var(--theme-font);
371
+ cursor: pointer;
372
+ --paper-toggle-button-checked-button: {
373
+ height: 15px;
374
+ width: 50%;
375
+ border-radius: 0;
376
+ bottom: 2px;
377
+ box-shadow: none;
378
+ border-bottom-right-radius : 8px;
379
+ border-top-right-radius: 8px;
380
+ }
381
+ --paper-toggle-button-unchecked-button: {
382
+ height: 15px;
383
+ width: 50%;
384
+ border-radius: 0;
385
+ bottom: 2px;
386
+ box-shadow: none;
387
+ border-bottom-left-radius : 8px;
388
+ border-top-left-radius: 8px;
389
+ }
390
+ --paper-toggle-button-unchecked-bar: {
391
+ height: 15px;
392
+ bottom: 2px;
393
+ box-shadow: none;
394
+ }
395
+ --paper-toggle-button-checked-bar: {
396
+ height: 15px;
397
+ bottom: 2px;
398
+ box-shadow: none;
399
+ }
400
+ --paper-toggle-button-label-color: var(--secondary-color);
401
+ align-items: flex-start;
402
+ }
403
+
404
+ paper-toggle-button.primary-colored {
405
+ --paper-toggle-button-unchecked-bar-color: var(--secondary-color-l1);
406
+ --paper-toggle-button-unchecked-button-color: var(--secondary-color-l1);
407
+ --paper-toggle-button-checked-bar-color: var(--primary-color-l1);
408
+ --paper-toggle-button-checked-button-color: var(--primary-color);
409
+ }
410
+
411
+ paper-toggle-button.secondary-colored {
412
+ --paper-toggle-button-unchecked-bar-color: var(--secondary-color-l2);
413
+ --paper-toggle-button-unchecked-button-color: var(--secondary-color-l2);
414
+ --paper-toggle-button-checked-bar-color: var(--secondary-color-l1);
415
+ --paper-toggle-button-checked-button-color: var(--secondary-color);
416
+ }
417
+ </style>
418
+ </custom-style>
419
+ `;
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@fw-components/formula-editor",
3
- "version": "2.0.3-formula-editor.1",
4
- "type": "module",
3
+ "version": "2.0.7-formula-editor.0",
5
4
  "description": "A WYSIWYG type formula editor",
6
- "main": "dist/src/formula-builder.js",
5
+ "main": "dist/formula-editor/src/formula-builder.js",
7
6
  "publishConfig": {
8
7
  "access": "public"
9
8
  },
10
9
  "scripts": {
11
- "start": "es-dev-server --app-index ../../index.html --node-resolve --watch --open"
10
+ "start": "es-dev-server --app-index ../../index.html --node-resolve --watch --open",
11
+ "build": "tsc --composite false",
12
+ "dev": "tsc -w --composite false",
13
+ "prepublishOnly": "npm run build"
12
14
  },
13
15
  "dependencies": {
14
- "@fw-components/styles": "^2.0.3-formula-editor.1",
16
+ "@fw-components/styles": "^2.0.7-formula-editor.0",
15
17
  "big.js": "^6.2.1",
16
18
  "lit": "^2.1.2",
17
19
  "typescript": "^5.0.4"
@@ -22,5 +24,5 @@
22
24
  "@types/big.js": "^6.1.6",
23
25
  "es-dev-server": "^2.1.0"
24
26
  },
25
- "gitHead": "f0c8eaf674cdbc6d104fcedb36ddbb6036af40db"
27
+ "gitHead": "05f8378db753ed6edfd56b945162795de33ae0fe"
26
28
  }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "experimentalDecorators": true,
4
+ "useDefineForClassFields":false,
5
+ "outDir": "./dist",
6
+ "rootDir": "../",
7
+ "target": "esnext",
8
+ "module": "esnext",
9
+ "moduleResolution": "node",
10
+ "declaration": true,
11
+ "declarationDir": "./dist/types",
12
+ "composite": false,
13
+ "lib": ["esnext", "dom"],
14
+ "esModuleInterop": true,
15
+ "skipLibCheck": true,
16
+ "noEmitOnError": false
17
+ },
18
+ "include": ["src/**/*.ts"],
19
+ "exclude": ["node_modules", "dist"]
20
+ }
package/src/cursor.ts DELETED
@@ -1,134 +0,0 @@
1
- export class Cursor {
2
- /**
3
- * The functions `getCurrentCursorPosition`, `setCurrentCursorPosition` and their
4
- * helpers `_createRange` and `_isChildOf` are not used for caret manipulation,
5
- * but are still in the code for future reference, if the functionality breaks
6
- * somehow in some obsolete browser.
7
- */
8
- static getCurrentCursorPosition(parentElement: any): number {
9
- let selection = window.getSelection(),
10
- charCount = -1,
11
- node;
12
-
13
- if (selection?.focusNode) {
14
- if (Cursor._isChildOf(selection.focusNode, parentElement)) {
15
- node = selection.focusNode;
16
- charCount = selection.focusOffset;
17
-
18
- while (node) {
19
- if (node === parentElement) {
20
- break;
21
- }
22
-
23
- if (node.previousSibling) {
24
- node = node.previousSibling;
25
- charCount += node.textContent?.length ?? 0;
26
- } else {
27
- node = node.parentNode;
28
- if (node === null) {
29
- break;
30
- }
31
- }
32
- }
33
- }
34
- }
35
-
36
- return charCount;
37
- }
38
-
39
- static setCurrentCursorPosition(chars: number, element: any) {
40
- if (chars >= 0) {
41
- var selection = window.getSelection();
42
- let range = Cursor._createRange(element, { count: chars }, undefined);
43
-
44
- if (range) {
45
- range.collapse(false);
46
- selection?.removeAllRanges();
47
- selection?.addRange(range);
48
- }
49
- }
50
- }
51
-
52
- static _createRange(node: any, chars: any, range: any) {
53
- if (!range) {
54
- range = document.createRange();
55
- range.selectNode(node);
56
- range.setStart(node, 0);
57
- }
58
-
59
- if (chars.count === 0) {
60
- range.setEnd(node, chars.count);
61
- } else if (node && chars.count > 0) {
62
- if (node.nodeType === Node.TEXT_NODE) {
63
- if (node.textContent.length < chars.count) {
64
- chars.count -= node.textContent.length;
65
- } else {
66
- range.setEnd(node, chars.count);
67
- chars.count = 0;
68
- }
69
- } else {
70
- for (var lp = 0; lp < node.childNodes.length; lp++) {
71
- range = Cursor._createRange(node.childNodes[lp], chars, range);
72
-
73
- if (chars.count === 0) {
74
- break;
75
- }
76
- }
77
- }
78
- }
79
-
80
- return range;
81
- }
82
-
83
- static _isChildOf(node: any, parentElement: any) {
84
- while (node !== null) {
85
- if (node === parentElement) {
86
- return true;
87
- }
88
- node = node.parentNode;
89
- }
90
-
91
- return false;
92
- }
93
-
94
- static getCaretPosition(shadowRoot: ShadowRoot, element: HTMLElement) {
95
- // `getSelection` is not defined for the type ShadowRoot in TS,
96
- // but it does exist.
97
- const range = (shadowRoot as any).getSelection()!.getRangeAt(0);
98
- const prefix = range.cloneRange();
99
- prefix.selectNodeContents(element);
100
- prefix.setEnd(range.endContainer, range.endOffset);
101
- return prefix.toString().length;
102
- }
103
-
104
- static setCaretPosition = (pos: any, parent: any) => {
105
- for (const node of parent.childNodes) {
106
- if (node.nodeType == Node.TEXT_NODE) {
107
- if (node.length >= pos) {
108
- const range = document.createRange();
109
- const sel = window.getSelection()!;
110
- range.setStart(node, pos);
111
- range.collapse(true);
112
- sel.removeAllRanges();
113
- sel.addRange(range);
114
- return -1;
115
- } else {
116
- pos = pos - node.length;
117
- }
118
- } else {
119
- pos = this.setCaretPosition(pos, node);
120
- if (pos < 0) {
121
- return pos;
122
- }
123
- }
124
- }
125
- return pos;
126
- };
127
-
128
- static getCursorRect(shadowRoot: ShadowRoot) {
129
- return (shadowRoot as any)
130
- .getSelection()
131
- ?.getRangeAt(0)
132
- ?.getClientRects()[0];
133
- }
134
- }