@luzmo/embed 6.1.2-beta.6 → 6.1.2-beta.7

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.
Files changed (45) hide show
  1. package/index.cjs +56871 -0
  2. package/index.d.ts +7 -0
  3. package/index.js +56841 -0
  4. package/lib/dashboard-component/dashboard-base.d.ts +98 -0
  5. package/lib/dashboard-component/dashboard-component.d.ts +8 -0
  6. package/lib/dashboard-component/dashboard-styles.d.ts +1 -0
  7. package/lib/helper/event-bus-handler.d.ts +1 -0
  8. package/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +22 -0
  9. package/lib/luzmo-iq-components/luzmo-iq-chat.d.ts +23 -0
  10. package/lib/luzmo-service.d.ts +6 -0
  11. package/lib/viz-item/viz-item-component.d.ts +4 -0
  12. package/lib/viz-item/viz-item.base.d.ts +72 -0
  13. package/luzmo-embed.min.js +58912 -0
  14. package/package.json +2 -2
  15. package/src/index.d.ts +7 -0
  16. package/src/lib/dashboard-component/dashboard-base.d.ts +98 -0
  17. package/src/lib/dashboard-component/dashboard-component.d.ts +8 -0
  18. package/src/lib/dashboard-component/dashboard-styles.d.ts +1 -0
  19. package/src/lib/helper/event-bus-handler.d.ts +1 -0
  20. package/src/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +22 -0
  21. package/src/lib/luzmo-iq-components/luzmo-iq-chat.d.ts +23 -0
  22. package/src/lib/luzmo-service.d.ts +6 -0
  23. package/src/lib/viz-item/viz-item-component.d.ts +4 -0
  24. package/src/lib/viz-item/viz-item.base.d.ts +72 -0
  25. package/.prettierignore +0 -4
  26. package/esbuild.config.cjs +0 -13
  27. package/eslint.config.cjs +0 -8
  28. package/jest.config.ts +0 -11
  29. package/project.json +0 -50
  30. package/src/index.ts +0 -46
  31. package/src/lib/dashboard-component/dashboard-base.ts +0 -827
  32. package/src/lib/dashboard-component/dashboard-component.spec.ts +0 -27
  33. package/src/lib/dashboard-component/dashboard-component.ts +0 -12
  34. package/src/lib/dashboard-component/dashboard-styles.ts +0 -117
  35. package/src/lib/helper/event-bus-handler.ts +0 -184
  36. package/src/lib/luzmo-iq-components/luzmo-iq-answer.ts +0 -105
  37. package/src/lib/luzmo-iq-components/luzmo-iq-chat.ts +0 -105
  38. package/src/lib/luzmo-service.ts +0 -7
  39. package/src/lib/viz-item/viz-item-component.ts +0 -9
  40. package/src/lib/viz-item/viz-item.base.ts +0 -231
  41. package/src/vite-env.d.ts +0 -1
  42. package/tsconfig.json +0 -27
  43. package/tsconfig.lib.json +0 -10
  44. package/tsconfig.spec.json +0 -9
  45. package/tsconfig.typings.json +0 -11
@@ -1,827 +0,0 @@
1
- import * as SharedLib from '@luzmo/shared-embed';
2
- import {
3
- html,
4
- LitElement,
5
- PropertyValues,
6
- TemplateResult
7
- } from 'lit';
8
- import {
9
- property,
10
- query,
11
- state
12
- } from 'lit/decorators.js';
13
- import {
14
- StyleInfo,
15
- styleMap
16
- } from 'lit/directives/style-map.js';
17
- import {
18
- LuzmoElement,
19
- CombinedSelectedDataInput,
20
- luzmoEmbedContainerClass
21
- } from '@luzmo/shared-embed';
22
- import type { FilterGroup } from '@luzmo/dashboard-contents-types';
23
- import * as pkg from '../../../package.json';
24
- import LuzmoService from '../luzmo-service';
25
- import { _setEventHandler } from '../helper/event-bus-handler';
26
- import { dashboardStyles } from './dashboard-styles';
27
-
28
- /**
29
- * Luzmo Dashboard
30
- * Base component isn't registered in customEvents registry so that it can be reused.
31
- */
32
-
33
- export class LuzmoDashboard
34
- extends LitElement
35
- implements SharedLib.ES6LuzmoDashboard {
36
- // Get container from shadow DOM for containerwidth
37
- @query('.dashboard-container') container!: HTMLElement;
38
- @query(`.${luzmoEmbedContainerClass}`) luzmoEmbedContainer!: HTMLElement;
39
-
40
- // Get iframe for post messages
41
- @query('iframe') iframe!: HTMLIFrameElement;
42
- // Input properties
43
- @property() dashboardId?: SharedLib.DashboardInputs['dashboardId'];
44
- @property() dashboardSlug?: SharedLib.DashboardInputs['dashboardSlug'];
45
- @property() itemId?: SharedLib.DashboardInputs['itemId'];
46
- @property() language: SharedLib.DashboardInputs['language'] = 'auto';
47
- @property() qeVersion: SharedLib.DashboardInputs['qeVersion'];
48
- @property() screenMode: SharedLib.DashboardInputs['screenMode'] = 'auto';
49
- @property({
50
- converter: {
51
- fromAttribute: (value) => value === 'true',
52
- toAttribute: String
53
- }
54
- })
55
- switchScreenModeOnResize = true;
56
- @property() editMode: SharedLib.DashboardInputs['editMode'] = 'view';
57
- @property() mainColor?: SharedLib.DashboardInputs['mainColor'];
58
- @property() accentColor?: SharedLib.DashboardInputs['accentColor'];
59
- @property() authToken?: SharedLib.DashboardInputs['authToken'];
60
- @property() authKey?: SharedLib.DashboardInputs['authKey'];
61
- @property() loaderBackground?: SharedLib.DashboardInputs['loaderBackground'];
62
- @property() loaderFontColor?: SharedLib.DashboardInputs['loaderFontColor'];
63
- @property()
64
- loaderSpinnerColor?: SharedLib.DashboardInputs['loaderSpinnerColor'];
65
- @property()
66
- loaderSpinnerBackground?: SharedLib.DashboardInputs['loaderSpinnerBackground'];
67
- @property() appServer?: SharedLib.DashboardInputs['appServer'];
68
- @property() timezoneId?: SharedLib.DashboardInputs['timezoneId'];
69
- @property() apiHost?: SharedLib.DashboardInputs['apiHost'];
70
- @property({ type: Object })
71
- itemDimensions: SharedLib.DashboardInputs['itemDimensions'];
72
- @property({
73
- converter: {
74
- fromAttribute: (value) => value === 'true',
75
- toAttribute: String
76
- }
77
- }) experimental = false;
78
- // TODO: Shouldn't be properties?
79
- // TODO: Accessible from component -> make private?
80
- // Dashboard version
81
- @property({ attribute: false }) _containerId: string;
82
- @property({ attribute: false }) _iframeId: string;
83
- @property({ attribute: false }) params!: SharedLib.DashboardContentParams;
84
- @property({ attribute: false }) _iframeUrl?: string;
85
- @property({ attribute: false }) iframeLoaded: boolean;
86
- @property({ attribute: false }) promises: SharedLib.DashboardPromises;
87
-
88
- // Styles
89
- @property({ attribute: false }) iframeStyle: SharedLib.IframeStyles = {};
90
- @property({ attribute: false }) _containerStyle: SharedLib.ContainerStyles
91
- = {};
92
- @property({ attribute: false }) _loaderStyle: SharedLib.LoaderStyles = {};
93
- @property({ attribute: false }) _lcStyle: SharedLib.LcStyles = {};
94
- @property({ attribute: false }) _loadingCircleStyle: SharedLib.PlStyles = {};
95
- @property({ attribute: false })
96
- _containerLoaderStyle: SharedLib.ContainerLoaderStyles = {};
97
- @property({ attribute: false }) _loaderMsg = '';
98
- @property({ attribute: false }) containerWidth?: number;
99
- @property({ attribute: false }) dimensions?: SharedLib.DashboardDimensions;
100
- @property({ attribute: false }) currentScreenMode?: SharedLib.ScreenMode;
101
- @property({ attribute: false }) _itemEmbedding = false;
102
- @property({ attribute: false }) browserError = false;
103
- @property({ attribute: false }) browserErrorMsg = '';
104
- @property({ attribute: false }) dashboardError = false;
105
- @property({ attribute: false }) browserNotSupported = [];
106
- @property() libVersion = pkg.version + '-wc-luzmo';
107
-
108
- @state() protected isLibraryLoaded = false;
109
- @state() protected dashboardReference: LuzmoElement;
110
-
111
- @state() currentAuthKey: string = null;
112
- @state() currentAuthToken: string = null;
113
- @state() isInitCalled = false;
114
-
115
- private attributesMap: {
116
- [key: string]: string;
117
- } = {
118
- dashboardId: 'dashboard-id',
119
- dashboardSlug: 'dashboard-slug',
120
- itemId: 'item-id',
121
- language: 'language',
122
- qeVersion: 'qe-version',
123
- screenMode: 'screen-mode',
124
- switchScreenModeOnResize: 'switch-screen-mode-on-resize',
125
- authKey: 'auth-key',
126
- authToken: 'auth-token',
127
- editMode: 'edit-mode',
128
- mainColor: 'main-color',
129
- accentColor: 'accent-color',
130
- loaderBackground: 'loader-background',
131
- loaderFontColor: 'loader-font-color',
132
- loaderSpinnerColor: 'loader-spinner-color',
133
- loaderSpinnerBackground: 'loader-spinner-background',
134
- appServer: 'app-server',
135
- apiHost: 'api-host',
136
- itemDimensions: 'item-dimensions',
137
- timezoneId: 'timezone-id'
138
- };
139
- _loadTimeoutHandle?: number;
140
- _onResize: () => void;
141
- loaderSize = 32;
142
- borderWidth = 3;
143
- minHeight = 400;
144
- iframeHeight?: string;
145
- iframeWidth?: string;
146
- _resizeObserver: ResizeObserver;
147
-
148
- constructor() {
149
- super();
150
- this._containerId = SharedLib.uuidv4();
151
- this._iframeId = `luzmo-dashboard-${this._containerId}`;
152
- this.iframeLoaded = false;
153
- this.promises = {};
154
-
155
- this.params = this._setOptions();
156
-
157
- this._onResize = () => {
158
- // Set width of container
159
- if (this.shadowRoot?.querySelector('.dashboard-container')) {
160
- // this.containerWidth = this.shadowRoot.querySelector(".dashboard-container").clientWidth;
161
- this.containerWidth = this.luzmoEmbedContainer.offsetWidth;
162
-
163
- // Set the new screenMode if screenMode can be switched
164
- if (
165
- this.params.switchScreenModeOnResize
166
- && this.params.screenMode === 'auto'
167
- ) {
168
- for (const d of SharedLib.EXTENTS) {
169
- if (
170
- d.width[0] <= window.innerWidth
171
- && window.innerWidth <= d.width[1]
172
- ) {
173
- this.currentScreenMode = d.mode;
174
- }
175
- }
176
- }
177
-
178
- // Calculate new dimensions
179
- // Make sure the dashboard is loaded before calculating dim, else results in error
180
- if (this.iframeLoaded) {
181
- this._calculateDimAfterDashboardLoaded();
182
- }
183
- else {
184
- if (this.dimensions) {
185
- this.containerWidth = this.luzmoEmbedContainer.offsetWidth;
186
- SharedLib._setCalculatedDimensions(this);
187
- }
188
- }
189
- }
190
- };
191
-
192
- this._resizeObserver = new ResizeObserver((entries) => {
193
- // https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded
194
- window.requestAnimationFrame(() => {
195
- if (!Array.isArray(entries) || entries.length === 0) {
196
- return;
197
- }
198
-
199
- this._onResize();
200
- });
201
- });
202
- }
203
-
204
- // Set resize event listener
205
- connectedCallback(): void {
206
- super.connectedCallback();
207
- }
208
-
209
- // Set resize event listener
210
- disconnectedCallback(): void {
211
- super.disconnectedCallback();
212
- this._resizeObserver.disconnect();
213
-
214
- // reject existing promises
215
- for (const promiseKey of Object.keys(this.promises)) {
216
- this.promises[promiseKey].reject(
217
- new Error('Dashboard component was removed')
218
- );
219
- }
220
- }
221
-
222
- firstUpdated(): void {
223
- // In firstUpdated dashboardId may or may not be available.
224
- // Some variables can be false, like experimental (even if they are passed as true.)
225
- this._loaderMsg = SharedLib.getLoader(this)?.loadingMsg;
226
- this._loaderStyles();
227
-
228
- LuzmoService._components.push(this);
229
-
230
- if (this.luzmoEmbedContainer) {
231
- this._resizeObserver.observe(this.luzmoEmbedContainer);
232
- }
233
- }
234
-
235
- initComponent(): void {
236
- this.params = this._setOptions();
237
-
238
- if (this.getIsViewMode()) {
239
- SharedLib.loadLibrary(this.params.appServer).then(async () => {
240
- this.isLibraryLoaded = true;
241
- await this.updateComplete;
242
-
243
- const oldReference = this.renderRoot.querySelector('dashboard-component');
244
-
245
- // Removes old listeners.
246
- this.dashboardReference = oldReference.cloneNode(true) as LuzmoElement;
247
-
248
- oldReference.replaceWith(this.dashboardReference);
249
-
250
- this.dashboardReference.addEventListener('load', (payload: any) => {
251
- this.containerWidth = this.dashboardReference.offsetWidth;
252
- this.dimensions = payload.detail.dimensions;
253
- SharedLib._setCalculatedDimensions(this);
254
- // Need resize event here because the dashboardReference doesn't have correct width when it's first loaded. It's computed after the dashboard is loaded in dashboard.component.
255
- window.dispatchEvent(new Event('resize'));
256
- this.dispatchEvent(new CustomEvent('load', payload));
257
- });
258
- this.dashboardReference.addEventListener('itemsRendered', (payload: any) => this.dispatchEvent(new CustomEvent('itemsRendered', payload)));
259
- this.dashboardReference.addEventListener('customEvent', (payload: any) => this.dispatchEvent(new CustomEvent('customEvent', payload)));
260
- this.dashboardReference.addEventListener('changedFilters', (payload: any) => this.dispatchEvent(new CustomEvent('changedFilters', payload)));
261
- this.dashboardReference.addEventListener('dashboardAction', (payload: any) => this.dispatchEvent(new CustomEvent('dashboardAction', payload)));
262
- this.dashboardReference.addEventListener('export', (payload: any) => this.dispatchEvent(new CustomEvent('exported', payload)));
263
-
264
- this.setAllAttributes();
265
- });
266
- }
267
- else {
268
- // Initial container width
269
- this.containerWidth = this.container?.clientWidth;
270
- // extend & test validity params + set itemEmbedding
271
- SharedLib._extendAndValidate(this);
272
-
273
- // test browser compatibility: svg, flexbox, postmessage / set browserNotSupported for unsupported browser
274
- SharedLib._browserCheck(this);
275
-
276
- // Setup loader
277
- this._setupLoader();
278
-
279
- if (!this.params.error) {
280
- this._loaderStyles();
281
-
282
- // create the iframe event listener -> this will on receive of message loaded hide the loader and show the dashboard
283
- _setEventHandler();
284
- // generate url & set iframe url
285
- this._iframeUrl = SharedLib.createIframeUrl(this);
286
- this.iframe?.setAttribute('src', this._iframeUrl);
287
- // Calculate iframe style
288
- this.iframeStyle = SharedLib.calculateIframeStyles(this);
289
- }
290
- }
291
- }
292
-
293
- setAllAttributes(): void {
294
- if (this.dashboardReference) {
295
- for (const key in this.attributesMap) {
296
- if (!['authKey', 'authToken', 'apiHost', 'itemDimensions'].includes(key) && this.params[key]) {
297
- this.dashboardReference.setAttribute(this.attributesMap[key], this.params[key]);
298
- }
299
- }
300
-
301
- if (this.params.itemDimensions) {
302
- this.dashboardReference.setAttribute('item-dimensions', JSON.stringify(this.params.itemDimensions));
303
- }
304
-
305
- if (this.params.apiHost) {
306
- this.dashboardReference.setAttribute('api-host', SharedLib.removeTrailingSlash(this.params.apiHost));
307
- }
308
-
309
- if (this.params.key) {
310
- this.dashboardReference.setAttribute('auth-key', this.params.key);
311
- }
312
-
313
- if (this.params.token) {
314
- this.dashboardReference.setAttribute('auth-token', this.params.token);
315
- }
316
- }
317
- }
318
-
319
- // Reload dashboard when triggerproperty changes
320
- updated(changedProperties: PropertyValues): void {
321
- const triggerProperties = new Set([
322
- 'dashboardId',
323
- 'dashboardSlug',
324
- 'itemId',
325
- 'language',
326
- 'qeVersion',
327
- 'editMode',
328
- 'screenMode',
329
- 'switchScreenModeOnResize',
330
- 'authToken',
331
- 'authKey',
332
- 'appServer',
333
- 'timezoneId',
334
- 'itemDimensions'
335
- ]);
336
-
337
- // Call initComponent if dashboardId is available, dashboardSlug is available or itemid is available
338
- // old dashboardId === undefined && this.dashboardId is defined OR
339
- // old dashboardSlug === undefined && this.dashboardSlug is defined OR
340
- // old itemId === undefined && this.itemId is defined
341
-
342
- const conditionsToCheck: (keyof LuzmoDashboard)[] = ['dashboardId', 'dashboardSlug', 'itemId'];
343
- let callInitComponent = false;
344
-
345
- for (const condition of conditionsToCheck) {
346
- callInitComponent = callInitComponent || (changedProperties.get(condition) === undefined && this[condition] !== undefined);
347
- }
348
- if (callInitComponent && !this.isInitCalled) {
349
- this.initComponent();
350
- this.isInitCalled = true;
351
- return;
352
- }
353
-
354
- if (this.getIsViewMode()) {
355
- if (this.dashboardReference) {
356
- for (const [propertyName] of changedProperties.entries()) {
357
- if ((propertyName as string) === 'appSever') {
358
- SharedLib.loadLibrary(changedProperties[propertyName]).then(async () => {
359
- this.isLibraryLoaded = true;
360
- await this.updateComplete;
361
- this.dashboardReference = this.renderRoot.querySelector('dashboard-component');
362
- this.setAllAttributes();
363
- });
364
- }
365
- else if (this.attributesMap[propertyName as string]) {
366
- const mappedAttributeName = this.attributesMap[propertyName as string] ?? (propertyName as string);
367
- const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() || this[propertyName]);
368
-
369
- this.dashboardReference.setAttribute(mappedAttributeName, attributeValue);
370
- }
371
- }
372
- }
373
- }
374
- else {
375
- for (const [propertyName] of changedProperties.entries()) {
376
- if (
377
- triggerProperties.has(propertyName as string)
378
- && propertyName !== 'editMode'
379
- ) {
380
- this.iframeLoaded = false;
381
-
382
- if (this._loadTimeoutHandle) {
383
- clearTimeout(this._loadTimeoutHandle);
384
- }
385
-
386
- this._loadTimeoutHandle = setTimeout(() => {
387
- console.warn(
388
- 'Failed to load dashboard, appServer is likely down or unreachable.'
389
- );
390
- }, 15 * 1000) as any as number;
391
- // extend & test validity params + set itemEmbedding
392
- this.params = this._setOptions();
393
- SharedLib._extendAndValidate(this);
394
-
395
- this._setupLoader();
396
- this._loaderStyles();
397
- // generate url & set iframe url
398
- this._iframeUrl = SharedLib.createIframeUrl(this);
399
-
400
- if (this.iframe) {
401
- this._updateIframeUrl();
402
- }
403
-
404
- // Calculate iframe style
405
- this.iframeStyle = SharedLib.calculateIframeStyles(this);
406
- }
407
- else if (
408
- triggerProperties.has(propertyName as string)
409
- && propertyName === 'editMode'
410
- ) {
411
- // Special case for editMode parameter: don't fully reload the dashboard, but call the setEditMode postMessage for a smooth transition.
412
- // Only when the dashboard has already loaded, or errors will occur.
413
- if (this.iframeLoaded) {
414
- this.setEditMode(this.editMode);
415
- }
416
-
417
- this.params = this._setOptions();
418
- }
419
- }
420
- }
421
- }
422
-
423
- // Set params
424
- _setOptions(): SharedLib.DashboardContentParams {
425
- const defaultParameters: SharedLib.DashboardContentParams = {
426
- dashboardId: this.dashboardId,
427
- dashboardSlug: this.dashboardSlug
428
- };
429
-
430
- if (this.itemId) {
431
- defaultParameters.itemId = this.itemId;
432
- this._itemEmbedding = true;
433
- }
434
- else {
435
- this._itemEmbedding = false;
436
- }
437
-
438
- if (this.language) {
439
- defaultParameters.language = this.language;
440
- }
441
-
442
- if (this.qeVersion) {
443
- defaultParameters.qeVersion = this.qeVersion;
444
- }
445
-
446
- if (this.screenMode) {
447
- defaultParameters.screenMode = this.screenMode;
448
- }
449
-
450
- defaultParameters.switchScreenModeOnResize = this.switchScreenModeOnResize;
451
-
452
- if (this.authToken) {
453
- defaultParameters.token = this.authToken;
454
- }
455
-
456
- if (this.authKey) {
457
- defaultParameters.key = this.authKey;
458
- }
459
-
460
- if (this.editMode) {
461
- defaultParameters.editMode = this.editMode;
462
- }
463
-
464
- if (this.mainColor) {
465
- defaultParameters.mainColor = this.mainColor;
466
- }
467
-
468
- if (this.accentColor) {
469
- defaultParameters.accentColor = this.accentColor;
470
- }
471
-
472
- if (this.loaderBackground) {
473
- defaultParameters.loaderBackground = this.loaderBackground;
474
- }
475
-
476
- if (this.loaderFontColor) {
477
- defaultParameters.loaderFontColor = this.loaderFontColor;
478
- }
479
-
480
- if (this.loaderSpinnerColor) {
481
- defaultParameters.loaderSpinnerColor = this.loaderSpinnerColor;
482
- }
483
-
484
- if (this.loaderSpinnerBackground) {
485
- defaultParameters.loaderSpinnerBackground = this.loaderSpinnerBackground;
486
- }
487
-
488
- if (this.timezoneId) {
489
- defaultParameters.timezoneId = this.timezoneId;
490
- }
491
-
492
- if (this.itemDimensions) {
493
- defaultParameters.itemDimensions = this.itemDimensions;
494
- }
495
-
496
- if (this.appServer) {
497
- this.appServer = this.getIsViewMode() ? SharedLib.removeTrailingSlash(this.appServer) : SharedLib.addTrailingSlash(this.appServer);
498
- defaultParameters.appServer = this.appServer;
499
- }
500
- else {
501
- this.appServer = SharedLib.addTrailingSlash(
502
- SharedLib.DEFAULT_PARAMETERS.appServer
503
- );
504
- defaultParameters.appServer = this.appServer;
505
- }
506
-
507
- if (this.apiHost) {
508
- this.apiHost = this.getIsViewMode() ? SharedLib.removeTrailingSlash(this.apiHost) : SharedLib.addTrailingSlash(this.apiHost);
509
- defaultParameters.apiHost = this.apiHost;
510
- }
511
- else {
512
- this.apiHost = this.appServer.includes('luzmo.com')
513
- ? this.appServer.replace('app', 'api')
514
- : this.appServer;
515
- defaultParameters.apiHost = this.apiHost;
516
- }
517
-
518
- this.currentAuthKey = this.authKey;
519
- this.currentAuthToken = this.authToken;
520
-
521
- return defaultParameters;
522
- }
523
-
524
- _updateIframeUrl(): void {
525
- SharedLib.updateIframeUrl(this.iframe, this._iframeUrl);
526
- }
527
-
528
- // Setup loader / browser error
529
- _setupLoader(): void {
530
- const data = SharedLib.getLoader(this);
531
-
532
- this._loaderMsg = data.loadingMsg;
533
-
534
- // Browser error
535
- if (data.errorMsg) {
536
- this.browserError = true;
537
- this.browserErrorMsg = data.errorMsg;
538
- this._displayError();
539
- }
540
- }
541
-
542
- _displayError(): void {
543
- // Show iframe error
544
- if (this.dashboardError) {
545
- this._loaderStyles();
546
- this.iframeStyle.opacity = 1;
547
- }
548
-
549
- // Show browser error
550
- if (this.browserError) {
551
- this._containerStyle.display = 'none';
552
- }
553
- }
554
-
555
- _calculateDimAfterDashboardLoaded(): void {
556
- this.dashboardError = false;
557
- this._loaderStyles();
558
- SharedLib._setCalculatedDimensions(this);
559
- }
560
-
561
- // Set loader styles
562
- _loaderStyles(): void {
563
- this._containerStyle = SharedLib.containerStyles(this);
564
- this._loaderStyle = SharedLib.loaderStyles(this);
565
- this._loadingCircleStyle = SharedLib.plStyles(this);
566
- this._containerLoaderStyle = SharedLib.containerLoaderStyles(this);
567
- this._lcStyle = SharedLib.lcStyles(this);
568
- }
569
-
570
- static get styles() {
571
- return [dashboardStyles];
572
- }
573
-
574
- render(): TemplateResult {
575
- let toBeRenderedHTML: TemplateResult;
576
- const loader = html`
577
- <div
578
- class="luzmo-container-loader"
579
- id="luzmo-container-loader-${this._containerId}"
580
- style=${styleMap(
581
- this._containerLoaderStyle as unknown as StyleInfo
582
- )}
583
- >
584
- <div
585
- class="luzmo-loader"
586
- id="luzmo-loader-${this._containerId}"
587
- style=${styleMap(this._loaderStyle as unknown as StyleInfo)}
588
- >
589
- <div
590
- class="luzmo-lc"
591
- style=${styleMap(this._lcStyle as unknown as StyleInfo)}
592
- >
593
- <div
594
- class="luzmo-loading-circle"
595
- style=${styleMap(
596
- this._loadingCircleStyle as unknown as StyleInfo
597
- )}
598
- ></div>
599
- ${this._itemEmbedding
600
- ? ''
601
- : html`
602
- <div
603
- class="luzmo-loading-message"
604
- style=${styleMap({color: this.loaderFontColor})}
605
- >
606
- ${this._loaderMsg}
607
- </div>
608
- `}
609
- </div>
610
- </div>
611
- </div>
612
- `;
613
-
614
- if (this.getIsViewMode()) {
615
- toBeRenderedHTML = this.isLibraryLoaded
616
- ? html`
617
- ${this.dashboardId || this.dashboardSlug ? html`
618
- <dashboard-component dashboard-id="${this.params.dashboardId}" app-server="${this.params.appServer}"
619
- api-host="${this.params.apiHost}"></dashboard-component>` : html`
620
- <div id="luzmo-error-${this._containerId}">
621
- <h3 class="luzmo-error">${this.browserErrorMsg}</h3>
622
- </div>
623
- `}
624
- `
625
- : html`${loader}`;
626
- }
627
- else {
628
- toBeRenderedHTML = html`
629
- ${this.dashboardId || this.dashboardSlug
630
- ? html`
631
- ${loader}
632
- <iframe
633
- class="luzmo-embed-dashboard ${!this.getIsViewMode() ? `luzmo-embed-dashboard-ede` : ''}"
634
- id="${this._iframeId}"
635
- name="${this._iframeId}"
636
- style=${styleMap(this.iframeStyle as unknown as StyleInfo)}
637
- src="${this._iframeUrl}"
638
- frameborder="0"
639
- ></iframe>
640
- `
641
- : html`<!-- the dashboard will inititialize when you provide a dashboardSlug or a dashboardId -->`}
642
- ${this.browserError
643
- ? html`
644
- <div id="luzmo-error-${this._containerId}">
645
- <h3 class="luzmo-error">${this.browserErrorMsg}</h3>
646
- </div>
647
- `
648
- : ''}
649
- `;
650
- }
651
-
652
- return html`
653
- <div class="${luzmoEmbedContainerClass} ${!this.getIsViewMode() ? `${luzmoEmbedContainerClass}-ede` : ''}">
654
- <div
655
- class="dashboard-container"
656
- style=${styleMap(Object.assign({}, this._containerStyle, {
657
- width: this.iframeStyle.width ?? '100%',
658
- height: this.iframeStyle.height ?? '100%'
659
- }) as unknown as StyleInfo)}
660
- >
661
- ${toBeRenderedHTML}
662
- </div>
663
- </div>
664
-
665
- `;
666
- }
667
-
668
- getDashboards(): Promise<LuzmoDashboard[]> {
669
- return new Promise((resolve) =>
670
- resolve(LuzmoService._components)
671
- );
672
- }
673
-
674
- // Public methods
675
- getData(itemId: string): Promise<SharedLib.ItemData> {
676
- if (this.getIsViewMode() && this.dashboardReference) {
677
- return this.dashboardReference.getData(itemId);
678
- }
679
-
680
- if (!this.getIsViewMode()) {
681
- return SharedLib.getData(this, this.iframe, itemId);
682
- }
683
-
684
- return Promise.reject();
685
- }
686
-
687
- getFilters(): Promise<FilterGroup[]> {
688
- if (this.getIsViewMode() && this.dashboardReference) {
689
- return this.dashboardReference.getFilters();
690
- }
691
-
692
- if (!this.getIsViewMode()) {
693
- return SharedLib.getFilters(this, this.iframe);
694
- }
695
-
696
- return Promise.reject();
697
- }
698
-
699
- setSelectedData<K extends CombinedSelectedDataInput>(
700
- itemId: string,
701
- filters: K
702
- ): Promise<SharedLib.SetSelectedData> {
703
- if (this.getIsViewMode() && this.dashboardReference) {
704
- return this.dashboardReference.setSelectedData<K>(itemId, filters);
705
- }
706
-
707
- if (!this.getIsViewMode()) {
708
- return SharedLib.setSelectedData(this, this.iframe, itemId, filters);
709
- }
710
-
711
- return Promise.reject();
712
- }
713
-
714
- setAuthorization(key: string, token: string): Promise<void> {
715
- this.currentAuthKey = key;
716
- this.currentAuthToken = token;
717
- if (this.getIsViewMode() && this.dashboardReference) {
718
- return this.dashboardReference.setAuthorization(key, token);
719
- }
720
-
721
- if (!this.getIsViewMode()) {
722
- return SharedLib.setAuthorization(this, this.iframe, key, token);
723
- }
724
-
725
- return Promise.reject();
726
- }
727
-
728
- refreshData(itemId?: string): Promise<void> {
729
- if (this.getIsViewMode() && this.dashboardReference) {
730
- return this.dashboardReference.refreshData(itemId);
731
- }
732
-
733
- if (!this.getIsViewMode()) {
734
- return itemId
735
- ? SharedLib.refreshData(this, this.iframe, itemId)
736
- : SharedLib.refreshData(this, this.iframe);
737
- }
738
-
739
- return Promise.reject();
740
- }
741
-
742
- reloadDashboard(): Promise<void> {
743
- if (this.getIsViewMode() && this.dashboardReference) {
744
- return this.dashboardReference.reloadDashboard();
745
- }
746
-
747
- if (!this.getIsViewMode()) {
748
- return SharedLib.reloadDashboard(this, this.iframe);
749
- }
750
-
751
- return Promise.reject();
752
- }
753
-
754
- exportDashboard(
755
- format?: SharedLib.ExportType
756
- ): Promise<SharedLib.ExportDashboard> {
757
- if (this.getIsViewMode() && this.dashboardReference) {
758
- return this.dashboardReference.exportDashboard(format);
759
- }
760
-
761
- if (!this.getIsViewMode()) {
762
- return format
763
- ? SharedLib.exportDashboard(this, this.iframe, format)
764
- : SharedLib.exportDashboard(this, this.iframe);
765
- }
766
-
767
- return Promise.reject();
768
- }
769
-
770
- getAccessibleDashboards(): Promise<SharedLib.AccessibleDashboard[]> {
771
- return SharedLib.getAccessibleDashboards(this);
772
- }
773
-
774
- addFilters(itemId: string, filters: FilterGroup[]): Promise<SharedLib.AddFilters> {
775
- return this.dashboardReference.addFilters(itemId, filters);
776
- }
777
-
778
- setEditMode(
779
- editMode?: SharedLib.DashboardEditMode
780
- ): Promise<SharedLib.SetEditMode> {
781
- if (this.dashboardReference && editMode === 'view') {
782
- // switch to use dashboard as web component
783
- this.editMode = 'view';
784
- this.params.editMode = 'view';
785
- this.initComponent();
786
-
787
- return Promise.resolve({
788
- type: 'setEditMode',
789
- editMode
790
- });
791
- }
792
-
793
- if (this.dashboardReference && ['editFull', 'editLimited'].includes(editMode)) {
794
- this.editMode = editMode;
795
- this.params.editMode = editMode;
796
-
797
- this.initComponent();
798
-
799
- return Promise.resolve({
800
- type: 'setEditMode',
801
- editMode
802
- });
803
- }
804
-
805
- if (this.getIsViewMode() && this.dashboardReference) {
806
- return this.dashboardReference.setEditMode(editMode);
807
- }
808
-
809
- if (!this.getIsViewMode()) {
810
- return SharedLib.setEditMode(this, this.iframe, editMode);
811
- }
812
-
813
- return Promise.reject();
814
- }
815
-
816
- setPreview(preview: boolean): Promise<SharedLib.SetPreview> {
817
- if (this.getIsViewMode() && this.dashboardReference) {
818
- return this.dashboardReference.setPreview(preview);
819
- }
820
-
821
- return SharedLib.setPreview(this, this.iframe, preview);
822
- }
823
-
824
- getIsViewMode(): boolean {
825
- return this.experimental && this.params.editMode === 'view' || this.params.editMode === undefined;
826
- }
827
- }