@luzmo/embed 6.2.1-beta.0 → 6.2.2

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 (37) hide show
  1. package/.prettierignore +4 -0
  2. package/CHANGELOG.md +0 -6
  3. package/esbuild.config.cjs +13 -0
  4. package/eslint.config.cjs +8 -0
  5. package/jest.config.ts +11 -0
  6. package/package.json +1 -1
  7. package/project.json +39 -0
  8. package/src/index.ts +42 -0
  9. package/src/lib/dashboard-component/dashboard-base.ts +828 -0
  10. package/src/lib/dashboard-component/dashboard-component.spec.ts +27 -0
  11. package/src/lib/dashboard-component/dashboard-component.ts +12 -0
  12. package/src/lib/dashboard-component/dashboard-styles.ts +117 -0
  13. package/src/lib/helper/event-bus-handler.ts +195 -0
  14. package/src/lib/helper/json-schema-utils.ts +129 -0
  15. package/src/lib/luzmo-iq-components/luzmo-iq-answer.ts +106 -0
  16. package/src/lib/luzmo-iq-components/luzmo-iq-chat.ts +106 -0
  17. package/src/lib/luzmo-service.ts +7 -0
  18. package/src/lib/viz-item/viz-item-component.ts +9 -0
  19. package/src/lib/viz-item/viz-item.base.ts +227 -0
  20. package/src/vite-env.d.ts +1 -0
  21. package/tsconfig.json +27 -0
  22. package/tsconfig.lib.json +10 -0
  23. package/tsconfig.spec.json +9 -0
  24. package/index.cjs +0 -1581
  25. package/index.js +0 -1550
  26. package/luzmo-embed.min.js +0 -3632
  27. package/src/index.d.ts +0 -8
  28. package/src/lib/dashboard-component/dashboard-base.d.ts +0 -98
  29. package/src/lib/dashboard-component/dashboard-component.d.ts +0 -8
  30. package/src/lib/dashboard-component/dashboard-styles.d.ts +0 -1
  31. package/src/lib/helper/event-bus-handler.d.ts +0 -1
  32. package/src/lib/helper/json-schema-utils.d.ts +0 -64
  33. package/src/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +0 -22
  34. package/src/lib/luzmo-iq-components/luzmo-iq-chat.d.ts +0 -23
  35. package/src/lib/luzmo-service.d.ts +0 -6
  36. package/src/lib/viz-item/viz-item-component.d.ts +0 -4
  37. package/src/lib/viz-item/viz-item.base.d.ts +0 -71
@@ -0,0 +1,828 @@
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
+ 'apiHost',
334
+ 'timezoneId',
335
+ 'itemDimensions'
336
+ ]);
337
+
338
+ // Call initComponent if dashboardId is available, dashboardSlug is available or itemid is available
339
+ // old dashboardId === undefined && this.dashboardId is defined OR
340
+ // old dashboardSlug === undefined && this.dashboardSlug is defined OR
341
+ // old itemId === undefined && this.itemId is defined
342
+
343
+ const conditionsToCheck: (keyof LuzmoDashboard)[] = ['dashboardId', 'dashboardSlug', 'itemId'];
344
+ let callInitComponent = false;
345
+
346
+ for (const condition of conditionsToCheck) {
347
+ callInitComponent = callInitComponent || (changedProperties.get(condition) === undefined && this[condition] !== undefined);
348
+ }
349
+ if (callInitComponent && !this.isInitCalled) {
350
+ this.initComponent();
351
+ this.isInitCalled = true;
352
+ return;
353
+ }
354
+
355
+ if (this.getIsViewMode()) {
356
+ if (this.dashboardReference) {
357
+ for (const [propertyName] of changedProperties.entries()) {
358
+ if ((propertyName as string) === 'appSever') {
359
+ SharedLib.loadLibrary(changedProperties[propertyName]).then(async () => {
360
+ this.isLibraryLoaded = true;
361
+ await this.updateComplete;
362
+ this.dashboardReference = this.renderRoot.querySelector('dashboard-component');
363
+ this.setAllAttributes();
364
+ });
365
+ }
366
+ else if (this.attributesMap[propertyName as string]) {
367
+ const mappedAttributeName = this.attributesMap[propertyName as string] ?? (propertyName as string);
368
+ const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() || this[propertyName]);
369
+
370
+ this.dashboardReference.setAttribute(mappedAttributeName, attributeValue);
371
+ }
372
+ }
373
+ }
374
+ }
375
+ else {
376
+ for (const [propertyName] of changedProperties.entries()) {
377
+ if (
378
+ triggerProperties.has(propertyName as string)
379
+ && propertyName !== 'editMode'
380
+ ) {
381
+ this.iframeLoaded = false;
382
+
383
+ if (this._loadTimeoutHandle) {
384
+ clearTimeout(this._loadTimeoutHandle);
385
+ }
386
+
387
+ this._loadTimeoutHandle = setTimeout(() => {
388
+ console.warn(
389
+ 'Failed to load dashboard, appServer is likely down or unreachable.'
390
+ );
391
+ }, 15 * 1000) as any as number;
392
+ // extend & test validity params + set itemEmbedding
393
+ this.params = this._setOptions();
394
+ SharedLib._extendAndValidate(this);
395
+
396
+ this._setupLoader();
397
+ this._loaderStyles();
398
+ // generate url & set iframe url
399
+ this._iframeUrl = SharedLib.createIframeUrl(this);
400
+
401
+ if (this.iframe) {
402
+ this._updateIframeUrl();
403
+ }
404
+
405
+ // Calculate iframe style
406
+ this.iframeStyle = SharedLib.calculateIframeStyles(this);
407
+ }
408
+ else if (
409
+ triggerProperties.has(propertyName as string)
410
+ && propertyName === 'editMode'
411
+ ) {
412
+ // Special case for editMode parameter: don't fully reload the dashboard, but call the setEditMode postMessage for a smooth transition.
413
+ // Only when the dashboard has already loaded, or errors will occur.
414
+ if (this.iframeLoaded) {
415
+ this.setEditMode(this.editMode);
416
+ }
417
+
418
+ this.params = this._setOptions();
419
+ }
420
+ }
421
+ }
422
+ }
423
+
424
+ // Set params
425
+ _setOptions(): SharedLib.DashboardContentParams {
426
+ const defaultParameters: SharedLib.DashboardContentParams = {
427
+ dashboardId: this.dashboardId,
428
+ dashboardSlug: this.dashboardSlug
429
+ };
430
+
431
+ if (this.itemId) {
432
+ defaultParameters.itemId = this.itemId;
433
+ this._itemEmbedding = true;
434
+ }
435
+ else {
436
+ this._itemEmbedding = false;
437
+ }
438
+
439
+ if (this.language) {
440
+ defaultParameters.language = this.language;
441
+ }
442
+
443
+ if (this.qeVersion) {
444
+ defaultParameters.qeVersion = this.qeVersion;
445
+ }
446
+
447
+ if (this.screenMode) {
448
+ defaultParameters.screenMode = this.screenMode;
449
+ }
450
+
451
+ defaultParameters.switchScreenModeOnResize = this.switchScreenModeOnResize;
452
+
453
+ if (this.authToken) {
454
+ defaultParameters.token = this.authToken;
455
+ }
456
+
457
+ if (this.authKey) {
458
+ defaultParameters.key = this.authKey;
459
+ }
460
+
461
+ if (this.editMode) {
462
+ defaultParameters.editMode = this.editMode;
463
+ }
464
+
465
+ if (this.mainColor) {
466
+ defaultParameters.mainColor = this.mainColor;
467
+ }
468
+
469
+ if (this.accentColor) {
470
+ defaultParameters.accentColor = this.accentColor;
471
+ }
472
+
473
+ if (this.loaderBackground) {
474
+ defaultParameters.loaderBackground = this.loaderBackground;
475
+ }
476
+
477
+ if (this.loaderFontColor) {
478
+ defaultParameters.loaderFontColor = this.loaderFontColor;
479
+ }
480
+
481
+ if (this.loaderSpinnerColor) {
482
+ defaultParameters.loaderSpinnerColor = this.loaderSpinnerColor;
483
+ }
484
+
485
+ if (this.loaderSpinnerBackground) {
486
+ defaultParameters.loaderSpinnerBackground = this.loaderSpinnerBackground;
487
+ }
488
+
489
+ if (this.timezoneId) {
490
+ defaultParameters.timezoneId = this.timezoneId;
491
+ }
492
+
493
+ if (this.itemDimensions) {
494
+ defaultParameters.itemDimensions = this.itemDimensions;
495
+ }
496
+
497
+ if (this.appServer) {
498
+ this.appServer = this.getIsViewMode() ? SharedLib.removeTrailingSlash(this.appServer) : SharedLib.addTrailingSlash(this.appServer);
499
+ defaultParameters.appServer = this.appServer;
500
+ }
501
+ else {
502
+ this.appServer = SharedLib.addTrailingSlash(
503
+ SharedLib.DEFAULT_PARAMETERS.appServer
504
+ );
505
+ defaultParameters.appServer = this.appServer;
506
+ }
507
+
508
+ if (this.apiHost) {
509
+ this.apiHost = this.getIsViewMode() ? SharedLib.removeTrailingSlash(this.apiHost) : SharedLib.addTrailingSlash(this.apiHost);
510
+ defaultParameters.apiHost = this.apiHost;
511
+ }
512
+ else {
513
+ this.apiHost = this.appServer.includes('luzmo.com')
514
+ ? this.appServer.replace('app', 'api')
515
+ : this.appServer;
516
+ defaultParameters.apiHost = this.apiHost;
517
+ }
518
+
519
+ this.currentAuthKey = this.authKey;
520
+ this.currentAuthToken = this.authToken;
521
+
522
+ return defaultParameters;
523
+ }
524
+
525
+ _updateIframeUrl(): void {
526
+ SharedLib.updateIframeUrl(this.iframe, this._iframeUrl);
527
+ }
528
+
529
+ // Setup loader / browser error
530
+ _setupLoader(): void {
531
+ const data = SharedLib.getLoader(this);
532
+
533
+ this._loaderMsg = data.loadingMsg;
534
+
535
+ // Browser error
536
+ if (data.errorMsg) {
537
+ this.browserError = true;
538
+ this.browserErrorMsg = data.errorMsg;
539
+ this._displayError();
540
+ }
541
+ }
542
+
543
+ _displayError(): void {
544
+ // Show iframe error
545
+ if (this.dashboardError) {
546
+ this._loaderStyles();
547
+ this.iframeStyle.opacity = 1;
548
+ }
549
+
550
+ // Show browser error
551
+ if (this.browserError) {
552
+ this._containerStyle.display = 'none';
553
+ }
554
+ }
555
+
556
+ _calculateDimAfterDashboardLoaded(): void {
557
+ this.dashboardError = false;
558
+ this._loaderStyles();
559
+ SharedLib._setCalculatedDimensions(this);
560
+ }
561
+
562
+ // Set loader styles
563
+ _loaderStyles(): void {
564
+ this._containerStyle = SharedLib.containerStyles(this);
565
+ this._loaderStyle = SharedLib.loaderStyles(this);
566
+ this._loadingCircleStyle = SharedLib.plStyles(this);
567
+ this._containerLoaderStyle = SharedLib.containerLoaderStyles(this);
568
+ this._lcStyle = SharedLib.lcStyles(this);
569
+ }
570
+
571
+ static get styles() {
572
+ return [dashboardStyles];
573
+ }
574
+
575
+ render(): TemplateResult {
576
+ let toBeRenderedHTML: TemplateResult;
577
+ const loader = html`
578
+ <div
579
+ class="luzmo-container-loader"
580
+ id="luzmo-container-loader-${this._containerId}"
581
+ style=${styleMap(
582
+ this._containerLoaderStyle as unknown as StyleInfo
583
+ )}
584
+ >
585
+ <div
586
+ class="luzmo-loader"
587
+ id="luzmo-loader-${this._containerId}"
588
+ style=${styleMap(this._loaderStyle as unknown as StyleInfo)}
589
+ >
590
+ <div
591
+ class="luzmo-lc"
592
+ style=${styleMap(this._lcStyle as unknown as StyleInfo)}
593
+ >
594
+ <div
595
+ class="luzmo-loading-circle"
596
+ style=${styleMap(
597
+ this._loadingCircleStyle as unknown as StyleInfo
598
+ )}
599
+ ></div>
600
+ ${this._itemEmbedding
601
+ ? ''
602
+ : html`
603
+ <div
604
+ class="luzmo-loading-message"
605
+ style=${styleMap({color: this.loaderFontColor})}
606
+ >
607
+ ${this._loaderMsg}
608
+ </div>
609
+ `}
610
+ </div>
611
+ </div>
612
+ </div>
613
+ `;
614
+
615
+ if (this.getIsViewMode()) {
616
+ toBeRenderedHTML = this.isLibraryLoaded
617
+ ? html`
618
+ ${this.dashboardId || this.dashboardSlug ? html`
619
+ <dashboard-component dashboard-id="${this.params.dashboardId}" app-server="${this.params.appServer}"
620
+ api-host="${this.params.apiHost}"></dashboard-component>` : html`
621
+ <div id="luzmo-error-${this._containerId}">
622
+ <h3 class="luzmo-error">${this.browserErrorMsg}</h3>
623
+ </div>
624
+ `}
625
+ `
626
+ : html`${loader}`;
627
+ }
628
+ else {
629
+ toBeRenderedHTML = html`
630
+ ${this.dashboardId || this.dashboardSlug
631
+ ? html`
632
+ ${loader}
633
+ <iframe
634
+ class="luzmo-embed-dashboard ${!this.getIsViewMode() ? `luzmo-embed-dashboard-ede` : ''}"
635
+ id="${this._iframeId}"
636
+ name="${this._iframeId}"
637
+ style=${styleMap(this.iframeStyle as unknown as StyleInfo)}
638
+ src="${this._iframeUrl}"
639
+ frameborder="0"
640
+ ></iframe>
641
+ `
642
+ : html`<!-- the dashboard will inititialize when you provide a dashboardSlug or a dashboardId -->`}
643
+ ${this.browserError
644
+ ? html`
645
+ <div id="luzmo-error-${this._containerId}">
646
+ <h3 class="luzmo-error">${this.browserErrorMsg}</h3>
647
+ </div>
648
+ `
649
+ : ''}
650
+ `;
651
+ }
652
+
653
+ return html`
654
+ <div class="${luzmoEmbedContainerClass} ${!this.getIsViewMode() ? `${luzmoEmbedContainerClass}-ede` : ''}">
655
+ <div
656
+ class="dashboard-container"
657
+ style=${styleMap(Object.assign({}, this._containerStyle, {
658
+ width: this.iframeStyle.width ?? '100%',
659
+ height: this.iframeStyle.height ?? '100%'
660
+ }) as unknown as StyleInfo)}
661
+ >
662
+ ${toBeRenderedHTML}
663
+ </div>
664
+ </div>
665
+
666
+ `;
667
+ }
668
+
669
+ getDashboards(): Promise<LuzmoDashboard[]> {
670
+ return new Promise((resolve) =>
671
+ resolve(LuzmoService._components)
672
+ );
673
+ }
674
+
675
+ // Public methods
676
+ getData(itemId: string): Promise<SharedLib.ItemData> {
677
+ if (this.getIsViewMode() && this.dashboardReference) {
678
+ return this.dashboardReference.getData(itemId);
679
+ }
680
+
681
+ if (!this.getIsViewMode()) {
682
+ return SharedLib.getData(this, this.iframe, itemId);
683
+ }
684
+
685
+ return Promise.reject();
686
+ }
687
+
688
+ getFilters(): Promise<FilterGroup[]> {
689
+ if (this.getIsViewMode() && this.dashboardReference) {
690
+ return this.dashboardReference.getFilters();
691
+ }
692
+
693
+ if (!this.getIsViewMode()) {
694
+ return SharedLib.getFilters(this, this.iframe);
695
+ }
696
+
697
+ return Promise.reject();
698
+ }
699
+
700
+ setSelectedData<K extends CombinedSelectedDataInput>(
701
+ itemId: string,
702
+ filters: K
703
+ ): Promise<SharedLib.SetSelectedData> {
704
+ if (this.getIsViewMode() && this.dashboardReference) {
705
+ return this.dashboardReference.setSelectedData<K>(itemId, filters);
706
+ }
707
+
708
+ if (!this.getIsViewMode()) {
709
+ return SharedLib.setSelectedData(this, this.iframe, itemId, filters);
710
+ }
711
+
712
+ return Promise.reject();
713
+ }
714
+
715
+ setAuthorization(key: string, token: string): Promise<void> {
716
+ this.currentAuthKey = key;
717
+ this.currentAuthToken = token;
718
+ if (this.getIsViewMode() && this.dashboardReference) {
719
+ return this.dashboardReference.setAuthorization(key, token);
720
+ }
721
+
722
+ if (!this.getIsViewMode()) {
723
+ return SharedLib.setAuthorization(this, this.iframe, key, token);
724
+ }
725
+
726
+ return Promise.reject();
727
+ }
728
+
729
+ refreshData(itemId?: string): Promise<void> {
730
+ if (this.getIsViewMode() && this.dashboardReference) {
731
+ return this.dashboardReference.refreshData(itemId);
732
+ }
733
+
734
+ if (!this.getIsViewMode()) {
735
+ return itemId
736
+ ? SharedLib.refreshData(this, this.iframe, itemId)
737
+ : SharedLib.refreshData(this, this.iframe);
738
+ }
739
+
740
+ return Promise.reject();
741
+ }
742
+
743
+ reloadDashboard(): Promise<void> {
744
+ if (this.getIsViewMode() && this.dashboardReference) {
745
+ return this.dashboardReference.reloadDashboard();
746
+ }
747
+
748
+ if (!this.getIsViewMode()) {
749
+ return SharedLib.reloadDashboard(this, this.iframe);
750
+ }
751
+
752
+ return Promise.reject();
753
+ }
754
+
755
+ exportDashboard(
756
+ format?: SharedLib.ExportType
757
+ ): Promise<SharedLib.ExportDashboard> {
758
+ if (this.getIsViewMode() && this.dashboardReference) {
759
+ return this.dashboardReference.exportDashboard(format);
760
+ }
761
+
762
+ if (!this.getIsViewMode()) {
763
+ return format
764
+ ? SharedLib.exportDashboard(this, this.iframe, format)
765
+ : SharedLib.exportDashboard(this, this.iframe);
766
+ }
767
+
768
+ return Promise.reject();
769
+ }
770
+
771
+ getAccessibleDashboards(): Promise<SharedLib.AccessibleDashboard[]> {
772
+ return SharedLib.getAccessibleDashboards(this);
773
+ }
774
+
775
+ addFilters(itemId: string, filters: FilterGroup[]): Promise<SharedLib.AddFilters> {
776
+ return this.dashboardReference.addFilters(itemId, filters);
777
+ }
778
+
779
+ setEditMode(
780
+ editMode?: SharedLib.DashboardEditMode
781
+ ): Promise<SharedLib.SetEditMode> {
782
+ if (this.dashboardReference && editMode === 'view') {
783
+ // switch to use dashboard as web component
784
+ this.editMode = 'view';
785
+ this.params.editMode = 'view';
786
+ this.initComponent();
787
+
788
+ return Promise.resolve({
789
+ type: 'setEditMode',
790
+ editMode
791
+ });
792
+ }
793
+
794
+ if (this.dashboardReference && ['editFull', 'editLimited'].includes(editMode)) {
795
+ this.editMode = editMode;
796
+ this.params.editMode = editMode;
797
+
798
+ this.initComponent();
799
+
800
+ return Promise.resolve({
801
+ type: 'setEditMode',
802
+ editMode
803
+ });
804
+ }
805
+
806
+ if (this.getIsViewMode() && this.dashboardReference) {
807
+ return this.dashboardReference.setEditMode(editMode);
808
+ }
809
+
810
+ if (!this.getIsViewMode()) {
811
+ return SharedLib.setEditMode(this, this.iframe, editMode);
812
+ }
813
+
814
+ return Promise.reject();
815
+ }
816
+
817
+ setPreview(preview: boolean): Promise<SharedLib.SetPreview> {
818
+ if (this.getIsViewMode() && this.dashboardReference) {
819
+ return this.dashboardReference.setPreview(preview);
820
+ }
821
+
822
+ return SharedLib.setPreview(this, this.iframe, preview);
823
+ }
824
+
825
+ getIsViewMode(): boolean {
826
+ return this.experimental && this.params.editMode === 'view' || this.params.editMode === undefined;
827
+ }
828
+ }