@luzmo/embed 5.1.3-beta.0 → 5.1.3-beta.10

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.libs.js CHANGED
@@ -32,7 +32,7 @@ import {
32
32
  } from "@luzmo/shared-embed";
33
33
 
34
34
  // libs/embed-libs/embed/package.json
35
- var version = "5.1.3-beta.0";
35
+ var version = "5.1.3-beta.10";
36
36
 
37
37
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
38
38
  var LuzmoService = class {
@@ -333,7 +333,7 @@ var LuzmoDashboard = class extends LitElement {
333
333
  this.browserErrorMsg = "";
334
334
  this.dashboardError = false;
335
335
  this.browserNotSupported = [];
336
- this.version = version + "-wc-luzmo";
336
+ this.libVersion = version + "-wc-luzmo";
337
337
  this.isLibraryLoaded = false;
338
338
  this.currentAuthKey = null;
339
339
  this.currentAuthToken = null;
@@ -1007,7 +1007,7 @@ __decorateClass([
1007
1007
  ], LuzmoDashboard.prototype, "browserNotSupported", 2);
1008
1008
  __decorateClass([
1009
1009
  property()
1010
- ], LuzmoDashboard.prototype, "version", 2);
1010
+ ], LuzmoDashboard.prototype, "libVersion", 2);
1011
1011
  __decorateClass([
1012
1012
  state()
1013
1013
  ], LuzmoDashboard.prototype, "isLibraryLoaded", 2);
@@ -1032,25 +1032,22 @@ LuzmoDashboardWebComponent = __decorateClass([
1032
1032
  ], LuzmoDashboardWebComponent);
1033
1033
 
1034
1034
  // libs/embed-libs/embed/src/lib/viz-item/viz-item-web-component.ts
1035
- import { customElement as customElement3 } from "lit/decorators.js";
1035
+ import { customElement as customElement2 } from "lit/decorators.js";
1036
1036
 
1037
1037
  // libs/embed-libs/embed/src/lib/viz-item/viz-item.base.ts
1038
1038
  import { property as property2 } from "lit/decorators.js";
1039
1039
  import { LitElement as LitElement2, html as html2, css as css2 } from "lit";
1040
1040
  import * as SharedLib3 from "@luzmo/shared-embed";
1041
+ import { fromError } from "zod-validation-error";
1041
1042
  var LuzmoBaseVizItem = class extends LitElement2 {
1042
1043
  constructor() {
1043
1044
  super();
1044
1045
  this.appServer = "https://app.luzmo.com";
1045
1046
  this.apiHost = "https://api.luzmo.com";
1046
1047
  this.slots = [];
1047
- this.options = {
1048
- title: {
1049
- en: ""
1050
- },
1051
- theme: "default"
1052
- };
1053
1048
  this.version = version + "-wc-luzmo";
1049
+ this.libVersion = version + "-wc-luzmo";
1050
+ this.postInitCallQueue = [];
1054
1051
  }
1055
1052
  static {
1056
1053
  // Static styles to set host display to block, else it is not shown at all for some reason.
@@ -1062,9 +1059,37 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1062
1059
  }
1063
1060
  `;
1064
1061
  }
1062
+ canInitializeVizItem() {
1063
+ return !!(this.type || this.dashboardId && this.itemId);
1064
+ }
1065
+ getFilters() {
1066
+ return this.chartElement.getFilters();
1067
+ }
1068
+ export() {
1069
+ return this.chartElement.export();
1070
+ }
1071
+ getData() {
1072
+ return this.chartElement.getData();
1073
+ }
1074
+ refreshData() {
1075
+ return this.chartElement.refreshData();
1076
+ }
1077
+ setFilters(filterInput) {
1078
+ return this.chartElement.setFilters(void 0, filterInput);
1079
+ }
1080
+ attributeChangedCallback(name, _old, value) {
1081
+ super.attributeChangedCallback(name, _old, value);
1082
+ if (name === "selecteddata") {
1083
+ if (this.chartElement) {
1084
+ this.setFilters(JSON.parse(value ?? "{}"));
1085
+ } else {
1086
+ this.postInitCallQueue.push([this.setFilters, [JSON.parse(value ?? "{}")]]);
1087
+ }
1088
+ }
1089
+ }
1065
1090
  async firstUpdated(_changedProperties) {
1066
1091
  super.firstUpdated(_changedProperties);
1067
- if (this.type) {
1092
+ if (this.canInitializeVizItem()) {
1068
1093
  await SharedLib3.loadLibrary(this.appServer, "DashboardApp");
1069
1094
  this.createAndAppendElement();
1070
1095
  }
@@ -1073,6 +1098,16 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1073
1098
  if (!this.chartElement) {
1074
1099
  this.chartElement = document.createElement("chart-component");
1075
1100
  this.chartElement.setAttribute("embedding-mode", "chart");
1101
+ this.chartElement.addEventListener("load", (payload) => this.dispatchEvent(new CustomEvent("load", payload)));
1102
+ this.chartElement.addEventListener("rendered", (payload) => {
1103
+ for (const functionToCall of this.postInitCallQueue) {
1104
+ functionToCall[0].bind(this)(...functionToCall[1]);
1105
+ }
1106
+ this.dispatchEvent(new CustomEvent("rendered", payload));
1107
+ });
1108
+ this.chartElement.addEventListener("changedFilters", (payload) => this.dispatchEvent(new CustomEvent("changedFilters", payload)));
1109
+ this.chartElement.addEventListener("exported", (payload) => this.dispatchEvent(new CustomEvent("exported", payload)));
1110
+ this.chartElement.addEventListener("customEvent", (payload) => this.dispatchEvent(new CustomEvent("customEvent", payload)));
1076
1111
  this.updateVizItemProperties();
1077
1112
  this.renderRoot.append(this.chartElement);
1078
1113
  }
@@ -1082,6 +1117,7 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1082
1117
  for (const key in SharedLib3.libraryTypeToWebComponentTypeMapping) {
1083
1118
  const value = this[key];
1084
1119
  if (value) {
1120
+ this.parseAndValidate(key);
1085
1121
  const attributeValue = ["appServer", "apiHost"].includes(key) ? SharedLib3.removeTrailingSlash(value) : value;
1086
1122
  this.chartElement.setAttribute(
1087
1123
  SharedLib3.libraryTypeToWebComponentTypeMapping[key],
@@ -1095,16 +1131,37 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1095
1131
  if (this.chartElement) {
1096
1132
  for (const [propertyName] of changedProperties.entries()) {
1097
1133
  const mappedAttributeName = SharedLib3.libraryTypeToWebComponentTypeMapping[propertyName] ?? propertyName;
1134
+ this.parseAndValidate(propertyName);
1098
1135
  const attributeValue = typeof this[propertyName] === "object" ? JSON.stringify(this[propertyName]) : this[propertyName]?.toString() ?? this[propertyName];
1099
1136
  this.chartElement.setAttribute(mappedAttributeName, attributeValue);
1100
1137
  }
1101
1138
  } else {
1102
- if (this.type) {
1139
+ if (this.canInitializeVizItem()) {
1140
+ if (this.type) {
1141
+ this.parseAndValidate("type");
1142
+ }
1103
1143
  await SharedLib3.loadLibrary(this.appServer, "DashboardApp");
1104
1144
  this.createAndAppendElement();
1105
1145
  }
1106
1146
  }
1107
1147
  }
1148
+ parseAndValidate(key) {
1149
+ try {
1150
+ if (key === "slots") {
1151
+ SharedLib3.slotsParser.parse(this.slots);
1152
+ } else if (key === "options") {
1153
+ SharedLib3.vizItemOptionsParser.parse(this.options);
1154
+ } else if (key === "canFilter") {
1155
+ SharedLib3.canFilterParser.parse(this.canFilter);
1156
+ } else if (key === "type") {
1157
+ SharedLib3.itemTypeParser.parse(this.type);
1158
+ }
1159
+ } catch (err) {
1160
+ const validationError = fromError(err);
1161
+ console.warn(err);
1162
+ console.warn(validationError.toString());
1163
+ }
1164
+ }
1108
1165
  render() {
1109
1166
  return html2` `;
1110
1167
  }
@@ -1150,12 +1207,24 @@ __decorateClass([
1150
1207
  __decorateClass([
1151
1208
  property2({ type: Array })
1152
1209
  ], LuzmoBaseVizItem.prototype, "filters", 2);
1210
+ __decorateClass([
1211
+ property2()
1212
+ ], LuzmoBaseVizItem.prototype, "dashboardId", 2);
1213
+ __decorateClass([
1214
+ property2()
1215
+ ], LuzmoBaseVizItem.prototype, "itemId", 2);
1216
+ __decorateClass([
1217
+ property2({ type: Object })
1218
+ ], LuzmoBaseVizItem.prototype, "selectedData", 2);
1219
+ __decorateClass([
1220
+ property2()
1221
+ ], LuzmoBaseVizItem.prototype, "libVersion", 2);
1153
1222
 
1154
1223
  // libs/embed-libs/embed/src/lib/viz-item/viz-item-web-component.ts
1155
1224
  var LuzmoVizItemWebComponent = class extends LuzmoBaseVizItem {
1156
1225
  };
1157
1226
  LuzmoVizItemWebComponent = __decorateClass([
1158
- customElement3("luzmo-viz-item-web-component")
1227
+ customElement2("luzmo-viz-item-web-component")
1159
1228
  ], LuzmoVizItemWebComponent);
1160
1229
  export {
1161
1230
  LuzmoDashboardWebComponent,
@@ -51,7 +51,7 @@ 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;
@@ -1,10 +1,11 @@
1
1
  import { LitElement, PropertyValues } from 'lit';
2
2
  import * as SharedLib from '@luzmo/shared-embed';
3
- export declare class LuzmoBaseVizItem extends LitElement {
4
- appServer: string;
5
- apiHost: string;
6
- slots: SharedLib.Slots;
7
- options: SharedLib.VizItemOptions;
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;
8
9
  type?: SharedLib.ItemType;
9
10
  authKey?: string;
10
11
  authToken?: string;
@@ -12,12 +13,28 @@ export declare class LuzmoBaseVizItem extends LitElement {
12
13
  contextId?: string;
13
14
  canFilter?: SharedLib.CanFilter;
14
15
  filters?: SharedLib.FilterGroup[];
15
- chartElement: HTMLElement;
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[];
16
24
  static styles: import("lit").CSSResult;
17
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
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
18
33
  protected firstUpdated(_changedProperties: PropertyValues): Promise<void>;
19
34
  private createAndAppendElement;
20
35
  private updateVizItemProperties;
21
36
  updated(changedProperties: PropertyValues): Promise<void>;
37
+ private parseAndValidate;
22
38
  protected render(): unknown;
23
39
  }
40
+ export {};