@luzmo/embed 5.1.4 → 6.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -30,14 +30,11 @@ import {
30
30
  styleMap
31
31
  } from "lit/directives/style-map.js";
32
32
  import {
33
- __federationMethodGetRemote,
34
- __federationMethodWrapDefault,
35
- remotesMap,
36
33
  luzmoEmbedContainerClass
37
34
  } from "@luzmo/shared-embed";
38
35
 
39
36
  // libs/embed-libs/embed/package.json
40
- var version = "5.1.4";
37
+ var version = "6.0.0-beta.0";
41
38
 
42
39
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
43
40
  var LuzmoService = class {
@@ -82,7 +79,7 @@ var _setEventHandler = () => {
82
79
  }
83
80
  dashboardComponent.iframeLoaded = true;
84
81
  dashboardComponent._displayError();
85
- console.error("Dashboard error: ", event.data.errorMsg);
82
+ console.error("Dashboard error: ", event.data.errorMsg ?? event.data.error?.msg);
86
83
  break;
87
84
  }
88
85
  case "data": {
@@ -323,7 +320,7 @@ var dashboardStyles = css`
323
320
 
324
321
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-base.ts
325
322
  var LuzmoDashboard = class extends LitElement {
326
- constructor(inputParameters) {
323
+ constructor() {
327
324
  super();
328
325
  this.language = "auto";
329
326
  this.screenMode = "auto";
@@ -342,10 +339,11 @@ var LuzmoDashboard = class extends LitElement {
342
339
  this.browserErrorMsg = "";
343
340
  this.dashboardError = false;
344
341
  this.browserNotSupported = [];
345
- this.VERSION = version + "-wc-luzmo";
342
+ this.libVersion = version + "-wc-luzmo";
346
343
  this.isLibraryLoaded = false;
347
344
  this.currentAuthKey = null;
348
345
  this.currentAuthToken = null;
346
+ this.isInitCalled = false;
349
347
  this.attributesMap = {
350
348
  dashboardId: "dashboard-id",
351
349
  dashboardSlug: "dashboard-slug",
@@ -375,7 +373,6 @@ var LuzmoDashboard = class extends LitElement {
375
373
  this._iframeId = `luzmo-dashboard-${this._containerId}`;
376
374
  this.iframeLoaded = false;
377
375
  this.promises = {};
378
- this.setInputParameters(inputParameters);
379
376
  this.params = this._setOptions();
380
377
  this._onResize = () => {
381
378
  if (this.shadowRoot?.querySelector(".dashboard-container")) {
@@ -406,60 +403,6 @@ var LuzmoDashboard = class extends LitElement {
406
403
  });
407
404
  });
408
405
  }
409
- loadLibrary(appServer) {
410
- if (remotesMap[appServer]) {
411
- return Promise.resolve(remotesMap[appServer].module);
412
- }
413
- remotesMap[appServer] = {
414
- url: appServer?.startsWith("http://localhost") ? `${SharedLib2.removeTrailingSlash(appServer)}/remoteEntry.mjs` : `${SharedLib2.removeTrailingSlash(appServer)}/dashboard-app/remoteEntry.mjs`,
415
- format: "esm",
416
- from: "vite",
417
- module: void 0
418
- };
419
- return __federationMethodGetRemote(appServer, "./DashboardApp").then((module) => {
420
- const wrappedModule = __federationMethodWrapDefault(module, true);
421
- remotesMap[appServer].module = wrappedModule;
422
- return wrappedModule;
423
- });
424
- }
425
- setInputParameters(inputParameters) {
426
- if (!inputParameters) {
427
- return;
428
- }
429
- const params = [
430
- "dashboardId",
431
- "dashboardSlug",
432
- "itemId",
433
- "language",
434
- "qeVersion",
435
- "screenMode",
436
- "switchScreenModeOnResize",
437
- "accentColor",
438
- "mainColor",
439
- "authToken",
440
- "authKey",
441
- "editMode",
442
- "loaderBackground",
443
- "loaderFontColor",
444
- "loaderSpinnerColor",
445
- "loaderSpinnerBackground",
446
- "timezoneId",
447
- "itemDimensions",
448
- "apiHost"
449
- ];
450
- for (const key of params) {
451
- const value = inputParameters[key];
452
- if (value) {
453
- this[key] = value;
454
- }
455
- }
456
- if (inputParameters.experimental) {
457
- this.experimental = inputParameters.experimental;
458
- }
459
- if (inputParameters.appServer) {
460
- this.appServer = SharedLib2.addTrailingSlash(inputParameters.appServer);
461
- }
462
- }
463
406
  // Set resize event listener
464
407
  connectedCallback() {
465
408
  super.connectedCallback();
@@ -478,7 +421,6 @@ var LuzmoDashboard = class extends LitElement {
478
421
  this._loaderMsg = SharedLib2.getLoader(this)?.loadingMsg;
479
422
  this._loaderStyles();
480
423
  luzmo_service_default._components.push(this);
481
- this.initComponent();
482
424
  if (this.luzmoEmbedContainer) {
483
425
  this._resizeObserver.observe(this.luzmoEmbedContainer);
484
426
  }
@@ -486,7 +428,7 @@ var LuzmoDashboard = class extends LitElement {
486
428
  initComponent() {
487
429
  this.params = this._setOptions();
488
430
  if (this.getIsViewMode()) {
489
- this.loadLibrary(this.params.appServer).then(async () => {
431
+ SharedLib2.loadLibrary(this.params.appServer).then(async () => {
490
432
  this.isLibraryLoaded = true;
491
433
  await this.updateComplete;
492
434
  const oldReference = this.renderRoot.querySelector("dashboard-component");
@@ -558,11 +500,21 @@ var LuzmoDashboard = class extends LitElement {
558
500
  "timezoneId",
559
501
  "itemDimensions"
560
502
  ]);
503
+ const conditionsToCheck = ["dashboardId", "dashboardSlug", "itemId"];
504
+ let callInitComponent = false;
505
+ for (const condition of conditionsToCheck) {
506
+ callInitComponent = callInitComponent || changedProperties.get(condition) === void 0 && this[condition] !== void 0;
507
+ }
508
+ if (callInitComponent && !this.isInitCalled) {
509
+ this.initComponent();
510
+ this.isInitCalled = true;
511
+ return;
512
+ }
561
513
  if (this.getIsViewMode()) {
562
514
  if (this.dashboardReference) {
563
515
  for (const [propertyName] of changedProperties.entries()) {
564
516
  if (propertyName === "appSever") {
565
- this.loadLibrary(changedProperties[propertyName]).then(async () => {
517
+ SharedLib2.loadLibrary(changedProperties[propertyName]).then(async () => {
566
518
  this.isLibraryLoaded = true;
567
519
  await this.updateComplete;
568
520
  this.dashboardReference = this.renderRoot.querySelector("dashboard-component");
@@ -1061,7 +1013,7 @@ __decorateClass([
1061
1013
  ], LuzmoDashboard.prototype, "browserNotSupported", 2);
1062
1014
  __decorateClass([
1063
1015
  property()
1064
- ], LuzmoDashboard.prototype, "VERSION", 2);
1016
+ ], LuzmoDashboard.prototype, "libVersion", 2);
1065
1017
  __decorateClass([
1066
1018
  state()
1067
1019
  ], LuzmoDashboard.prototype, "isLibraryLoaded", 2);
@@ -1074,19 +1026,216 @@ __decorateClass([
1074
1026
  __decorateClass([
1075
1027
  state()
1076
1028
  ], LuzmoDashboard.prototype, "currentAuthToken", 2);
1029
+ __decorateClass([
1030
+ state()
1031
+ ], LuzmoDashboard.prototype, "isInitCalled", 2);
1077
1032
 
1078
1033
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-component.ts
1079
- var LuzmoDashboard2 = class extends LuzmoDashboard {
1080
- };
1081
- LuzmoDashboard2 = __decorateClass([
1082
- customElement("luzmo-dashboard")
1083
- ], LuzmoDashboard2);
1084
1034
  var LuzmoEmbedDashboard = class extends LuzmoDashboard {
1085
1035
  };
1086
1036
  LuzmoEmbedDashboard = __decorateClass([
1087
1037
  customElement("luzmo-embed-dashboard")
1088
1038
  ], LuzmoEmbedDashboard);
1039
+
1040
+ // libs/embed-libs/embed/src/lib/viz-item/viz-item-component.ts
1041
+ import { customElement as customElement2 } from "lit/decorators.js";
1042
+
1043
+ // libs/embed-libs/embed/src/lib/viz-item/viz-item.base.ts
1044
+ import { property as property2 } from "lit/decorators.js";
1045
+ import { LitElement as LitElement2, html as html2, css as css2 } from "lit";
1046
+ import * as SharedLib3 from "@luzmo/shared-embed";
1047
+ import { fromError } from "zod-validation-error";
1048
+ var LuzmoBaseVizItem = class extends LitElement2 {
1049
+ constructor() {
1050
+ super();
1051
+ this.appServer = "https://app.luzmo.com";
1052
+ this.apiHost = "https://api.luzmo.com";
1053
+ this.slots = [];
1054
+ this.version = version + "-wc-luzmo";
1055
+ this.libVersion = version + "-wc-luzmo";
1056
+ this.postInitCallQueue = [];
1057
+ }
1058
+ static {
1059
+ // Static styles to set host display to block, else it is not shown at all for some reason.
1060
+ this.styles = css2`
1061
+ :host {
1062
+ display: block;
1063
+ width: 100%;
1064
+ height: 100%;
1065
+ }
1066
+ `;
1067
+ }
1068
+ canInitializeVizItem() {
1069
+ return !!(this.type || this.dashboardId && this.itemId);
1070
+ }
1071
+ getFilters() {
1072
+ return this.chartElement.getFilters();
1073
+ }
1074
+ export() {
1075
+ return this.chartElement.export();
1076
+ }
1077
+ getData() {
1078
+ return this.chartElement.getData();
1079
+ }
1080
+ refreshData() {
1081
+ return this.chartElement.refreshData();
1082
+ }
1083
+ setFilters(filterInput) {
1084
+ return this.chartElement.setFilters(void 0, filterInput);
1085
+ }
1086
+ setAuthorization(key, token) {
1087
+ return this.chartElement.setAuthorization(key, token);
1088
+ }
1089
+ attributeChangedCallback(name, _old, value) {
1090
+ super.attributeChangedCallback(name, _old, value);
1091
+ if (name === "selecteddata") {
1092
+ if (this.chartElement) {
1093
+ this.setFilters(JSON.parse(value ?? "{}"));
1094
+ } else {
1095
+ this.postInitCallQueue.push([this.setFilters, [JSON.parse(value ?? "{}")]]);
1096
+ }
1097
+ }
1098
+ }
1099
+ async firstUpdated(_changedProperties) {
1100
+ super.firstUpdated(_changedProperties);
1101
+ if (this.canInitializeVizItem()) {
1102
+ await SharedLib3.loadLibrary(this.appServer, "DashboardApp");
1103
+ this.createAndAppendElement();
1104
+ }
1105
+ }
1106
+ createAndAppendElement() {
1107
+ if (!this.chartElement) {
1108
+ this.chartElement = document.createElement("chart-component");
1109
+ this.chartElement.setAttribute("embedding-mode", "chart");
1110
+ this.chartElement.addEventListener("load", (payload) => this.dispatchEvent(new CustomEvent("load", payload)));
1111
+ this.chartElement.addEventListener("rendered", (payload) => {
1112
+ for (const functionToCall of this.postInitCallQueue) {
1113
+ functionToCall[0].bind(this)(...functionToCall[1]);
1114
+ }
1115
+ this.dispatchEvent(new CustomEvent("rendered", payload));
1116
+ });
1117
+ this.chartElement.addEventListener("changedFilters", (payload) => this.dispatchEvent(new CustomEvent("changedFilters", payload)));
1118
+ this.chartElement.addEventListener("exported", (payload) => this.dispatchEvent(new CustomEvent("exported", payload)));
1119
+ this.chartElement.addEventListener("customEvent", (payload) => this.dispatchEvent(new CustomEvent("customEvent", payload)));
1120
+ this.updateVizItemProperties();
1121
+ this.renderRoot.append(this.chartElement);
1122
+ }
1123
+ }
1124
+ updateVizItemProperties() {
1125
+ if (this.chartElement) {
1126
+ for (const key in SharedLib3.libraryTypeToWebComponentTypeMapping) {
1127
+ const value = this[key];
1128
+ if (value) {
1129
+ this.parseAndValidate(key);
1130
+ const attributeValue = ["appServer", "apiHost"].includes(key) ? SharedLib3.removeTrailingSlash(value) : value;
1131
+ this.chartElement.setAttribute(
1132
+ SharedLib3.libraryTypeToWebComponentTypeMapping[key],
1133
+ typeof attributeValue === "object" ? JSON.stringify(attributeValue) : attributeValue
1134
+ );
1135
+ }
1136
+ }
1137
+ }
1138
+ }
1139
+ async updated(changedProperties) {
1140
+ if (this.chartElement) {
1141
+ for (const [propertyName] of changedProperties.entries()) {
1142
+ const mappedAttributeName = SharedLib3.libraryTypeToWebComponentTypeMapping[propertyName] ?? propertyName;
1143
+ this.parseAndValidate(propertyName);
1144
+ const attributeValue = typeof this[propertyName] === "object" ? JSON.stringify(this[propertyName]) : this[propertyName]?.toString() ?? this[propertyName];
1145
+ this.chartElement.setAttribute(mappedAttributeName, attributeValue);
1146
+ }
1147
+ } else {
1148
+ if (this.canInitializeVizItem()) {
1149
+ if (this.type) {
1150
+ this.parseAndValidate("type");
1151
+ }
1152
+ await SharedLib3.loadLibrary(this.appServer, "DashboardApp");
1153
+ this.createAndAppendElement();
1154
+ }
1155
+ }
1156
+ }
1157
+ parseAndValidate(key) {
1158
+ try {
1159
+ if (key === "slots") {
1160
+ SharedLib3.slotsParser.parse(this.slots);
1161
+ } else if (key === "options") {
1162
+ SharedLib3.vizItemOptionsParser.parse(this.options);
1163
+ } else if (key === "canFilter") {
1164
+ SharedLib3.canFilterParser.parse(this.canFilter);
1165
+ } else if (key === "type") {
1166
+ SharedLib3.itemTypeParser.parse(this.type);
1167
+ }
1168
+ } catch (err) {
1169
+ const validationError = fromError(err);
1170
+ console.warn(err);
1171
+ console.warn(validationError.toString());
1172
+ }
1173
+ }
1174
+ render() {
1175
+ return html2` `;
1176
+ }
1177
+ };
1178
+ __decorateClass([
1179
+ property2()
1180
+ ], LuzmoBaseVizItem.prototype, "appServer", 2);
1181
+ __decorateClass([
1182
+ property2()
1183
+ ], LuzmoBaseVizItem.prototype, "apiHost", 2);
1184
+ __decorateClass([
1185
+ property2({ type: Array })
1186
+ ], LuzmoBaseVizItem.prototype, "slots", 2);
1187
+ __decorateClass([
1188
+ property2({ type: Object })
1189
+ ], LuzmoBaseVizItem.prototype, "options", 2);
1190
+ __decorateClass([
1191
+ property2()
1192
+ ], LuzmoBaseVizItem.prototype, "type", 2);
1193
+ __decorateClass([
1194
+ property2()
1195
+ ], LuzmoBaseVizItem.prototype, "authKey", 2);
1196
+ __decorateClass([
1197
+ property2()
1198
+ ], LuzmoBaseVizItem.prototype, "authToken", 2);
1199
+ __decorateClass([
1200
+ property2()
1201
+ ], LuzmoBaseVizItem.prototype, "version", 2);
1202
+ __decorateClass([
1203
+ property2()
1204
+ ], LuzmoBaseVizItem.prototype, "contextId", 2);
1205
+ __decorateClass([
1206
+ property2({
1207
+ converter: (value) => {
1208
+ try {
1209
+ return JSON.parse(value);
1210
+ } catch (exc) {
1211
+ return value;
1212
+ }
1213
+ }
1214
+ })
1215
+ ], LuzmoBaseVizItem.prototype, "canFilter", 2);
1216
+ __decorateClass([
1217
+ property2({ type: Array })
1218
+ ], LuzmoBaseVizItem.prototype, "filters", 2);
1219
+ __decorateClass([
1220
+ property2()
1221
+ ], LuzmoBaseVizItem.prototype, "dashboardId", 2);
1222
+ __decorateClass([
1223
+ property2()
1224
+ ], LuzmoBaseVizItem.prototype, "itemId", 2);
1225
+ __decorateClass([
1226
+ property2({ type: Object })
1227
+ ], LuzmoBaseVizItem.prototype, "selectedData", 2);
1228
+ __decorateClass([
1229
+ property2()
1230
+ ], LuzmoBaseVizItem.prototype, "libVersion", 2);
1231
+
1232
+ // libs/embed-libs/embed/src/lib/viz-item/viz-item-component.ts
1233
+ var LuzmoEmbedVizItem = class extends LuzmoBaseVizItem {
1234
+ };
1235
+ LuzmoEmbedVizItem = __decorateClass([
1236
+ customElement2("luzmo-embed-viz-item")
1237
+ ], LuzmoEmbedVizItem);
1089
1238
  export {
1090
- LuzmoDashboard2 as LuzmoDashboard,
1091
- LuzmoEmbedDashboard
1239
+ LuzmoEmbedDashboard,
1240
+ LuzmoEmbedVizItem
1092
1241
  };
@@ -51,11 +51,12 @@ export declare class LuzmoDashboard extends LitElement implements SharedLib.ES6L
51
51
  browserErrorMsg: string;
52
52
  dashboardError: boolean;
53
53
  browserNotSupported: any[];
54
- VERSION: string;
54
+ libVersion: string;
55
55
  protected isLibraryLoaded: boolean;
56
56
  protected dashboardReference: SharedLib.LuzmoElement;
57
57
  currentAuthKey: string;
58
58
  currentAuthToken: string;
59
+ isInitCalled: boolean;
59
60
  private attributesMap;
60
61
  _loadTimeoutHandle?: number;
61
62
  _onResize: () => void;
@@ -65,9 +66,7 @@ export declare class LuzmoDashboard extends LitElement implements SharedLib.ES6L
65
66
  iframeHeight?: string;
66
67
  iframeWidth?: string;
67
68
  _resizeObserver: ResizeObserver;
68
- constructor(inputParameters?: Record<keyof LuzmoDashboard, any>);
69
- private loadLibrary;
70
- private setInputParameters;
69
+ constructor();
71
70
  connectedCallback(): void;
72
71
  disconnectedCallback(): void;
73
72
  firstUpdated(): void;
@@ -1,16 +1,8 @@
1
- import { LuzmoDashboard as LuzmoBaseDashboard } from './dashboard-base';
2
- /**!
3
- * @element luzmo-dashboard
4
- * @description Exposed by @luzmo/embed lib to everyone.
5
- *
6
- * @deprecated Will be removed in next major release. Switch to <luzmo-embed-dashboard> instead.
7
- */
8
- export declare class LuzmoDashboard extends LuzmoBaseDashboard {
9
- }
1
+ import { LuzmoDashboard } from './dashboard-base';
10
2
  /**!
11
3
  * @element luzmo-embed-dashboard
12
4
  * @description Exposed by @luzmo/embed lib to everyone.
13
5
  *
14
6
  */
15
- export declare class LuzmoEmbedDashboard extends LuzmoBaseDashboard {
7
+ export declare class LuzmoEmbedDashboard extends LuzmoDashboard {
16
8
  }
@@ -0,0 +1,3 @@
1
+ import { LuzmoBaseVizItem } from './viz-item.base';
2
+ export declare class LuzmoEmbedVizItem extends LuzmoBaseVizItem {
3
+ }
@@ -0,0 +1,41 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ import * as SharedLib from '@luzmo/shared-embed';
3
+ type FunctionCall = [(...args: any) => any, any[]];
4
+ export declare class LuzmoBaseVizItem extends LitElement implements SharedLib.LuzmoVizItemComponentInterface {
5
+ appServer?: string;
6
+ apiHost?: string;
7
+ slots?: SharedLib.Slots;
8
+ options?: SharedLib.VizItemOptions;
9
+ type?: SharedLib.ItemType;
10
+ authKey?: string;
11
+ authToken?: string;
12
+ version?: string;
13
+ contextId?: string;
14
+ canFilter?: SharedLib.CanFilter;
15
+ filters?: SharedLib.FilterGroup[];
16
+ dashboardId?: string;
17
+ itemId?: string;
18
+ selectedData: SharedLib.FilterInput;
19
+ libVersion?: string;
20
+ chartElement: HTMLElement & Partial<SharedLib.LuzmoVizItemComponentInterface> & {
21
+ setFilters?: (itemId?: string, filters?: SharedLib.FilterInput) => SharedLib.SetFilters;
22
+ };
23
+ postInitCallQueue: FunctionCall[];
24
+ static styles: import("lit").CSSResult;
25
+ constructor();
26
+ canInitializeVizItem(): boolean;
27
+ getFilters(): SharedLib.FilterGroup[];
28
+ export(): void;
29
+ getData(): any;
30
+ refreshData(): void;
31
+ setFilters(filterInput: SharedLib.FilterInput): SharedLib.SetFilters;
32
+ setAuthorization(key: string, token: string): void;
33
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
34
+ protected firstUpdated(_changedProperties: PropertyValues): Promise<void>;
35
+ private createAndAppendElement;
36
+ private updateVizItemProperties;
37
+ updated(changedProperties: PropertyValues): Promise<void>;
38
+ private parseAndValidate;
39
+ protected render(): unknown;
40
+ }
41
+ export {};