@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/CHANGELOG.md CHANGED
@@ -1,6 +1,19 @@
1
1
 
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [6.0.0] - 2024-05-31
5
+
6
+ ### Breaking changes
7
+
8
+ - Removed `<luzmo-dashboard>` web component, It has been replaced with `<luzmo-embed-dashboard>`.
9
+ - `LuzmoDashboard` has been replaced with `LuzmoEmbedDashboard`
10
+
11
+ ## [5.1.5] - 2024-05-03
12
+
13
+ ### Bugfixes
14
+
15
+ - Fix bugs in experimental=true, dashboard not loading at times.
16
+
4
17
  ## [5.1.4] - 2024-05-02
5
18
 
6
19
  ### Bugfixes
package/MIGRATIONS.md CHANGED
@@ -1 +1,7 @@
1
1
  # Luzmo embed migrations
2
+
3
+ ## [5.X.X] -> [6.0.0] - 2024-05-31
4
+
5
+ ### Breaking changes
6
+
7
+ * Change all references of `<luzmo-dashboard>` to `<luzmo-embed-dashboard>`.
package/index.cjs CHANGED
@@ -39,8 +39,8 @@ var __decorateClass = (decorators, target, key, kind) => {
39
39
  // libs/embed-libs/embed/src/index.ts
40
40
  var src_exports = {};
41
41
  __export(src_exports, {
42
- LuzmoDashboard: () => LuzmoDashboard2,
43
- LuzmoEmbedDashboard: () => LuzmoEmbedDashboard
42
+ LuzmoEmbedDashboard: () => LuzmoEmbedDashboard,
43
+ LuzmoEmbedVizItem: () => LuzmoEmbedVizItem
44
44
  });
45
45
  module.exports = __toCommonJS(src_exports);
46
46
 
@@ -55,7 +55,7 @@ var import_style_map = require("lit/directives/style-map.js");
55
55
  var import_shared_embed = require("@luzmo/shared-embed");
56
56
 
57
57
  // libs/embed-libs/embed/package.json
58
- var version = "5.1.4";
58
+ var version = "6.0.0-beta.0";
59
59
 
60
60
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
61
61
  var LuzmoService = class {
@@ -100,7 +100,7 @@ var _setEventHandler = () => {
100
100
  }
101
101
  dashboardComponent.iframeLoaded = true;
102
102
  dashboardComponent._displayError();
103
- console.error("Dashboard error: ", event.data.errorMsg);
103
+ console.error("Dashboard error: ", event.data.errorMsg ?? event.data.error?.msg);
104
104
  break;
105
105
  }
106
106
  case "data": {
@@ -341,7 +341,7 @@ var dashboardStyles = import_lit.css`
341
341
 
342
342
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-base.ts
343
343
  var LuzmoDashboard = class extends import_lit2.LitElement {
344
- constructor(inputParameters) {
344
+ constructor() {
345
345
  super();
346
346
  this.language = "auto";
347
347
  this.screenMode = "auto";
@@ -360,10 +360,11 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
360
360
  this.browserErrorMsg = "";
361
361
  this.dashboardError = false;
362
362
  this.browserNotSupported = [];
363
- this.VERSION = version + "-wc-luzmo";
363
+ this.libVersion = version + "-wc-luzmo";
364
364
  this.isLibraryLoaded = false;
365
365
  this.currentAuthKey = null;
366
366
  this.currentAuthToken = null;
367
+ this.isInitCalled = false;
367
368
  this.attributesMap = {
368
369
  dashboardId: "dashboard-id",
369
370
  dashboardSlug: "dashboard-slug",
@@ -393,7 +394,6 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
393
394
  this._iframeId = `luzmo-dashboard-${this._containerId}`;
394
395
  this.iframeLoaded = false;
395
396
  this.promises = {};
396
- this.setInputParameters(inputParameters);
397
397
  this.params = this._setOptions();
398
398
  this._onResize = () => {
399
399
  if (this.shadowRoot?.querySelector(".dashboard-container")) {
@@ -424,60 +424,6 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
424
424
  });
425
425
  });
426
426
  }
427
- loadLibrary(appServer) {
428
- if (import_shared_embed.remotesMap[appServer]) {
429
- return Promise.resolve(import_shared_embed.remotesMap[appServer].module);
430
- }
431
- import_shared_embed.remotesMap[appServer] = {
432
- url: appServer?.startsWith("http://localhost") ? `${SharedLib2.removeTrailingSlash(appServer)}/remoteEntry.mjs` : `${SharedLib2.removeTrailingSlash(appServer)}/dashboard-app/remoteEntry.mjs`,
433
- format: "esm",
434
- from: "vite",
435
- module: void 0
436
- };
437
- return (0, import_shared_embed.__federationMethodGetRemote)(appServer, "./DashboardApp").then((module2) => {
438
- const wrappedModule = (0, import_shared_embed.__federationMethodWrapDefault)(module2, true);
439
- import_shared_embed.remotesMap[appServer].module = wrappedModule;
440
- return wrappedModule;
441
- });
442
- }
443
- setInputParameters(inputParameters) {
444
- if (!inputParameters) {
445
- return;
446
- }
447
- const params = [
448
- "dashboardId",
449
- "dashboardSlug",
450
- "itemId",
451
- "language",
452
- "qeVersion",
453
- "screenMode",
454
- "switchScreenModeOnResize",
455
- "accentColor",
456
- "mainColor",
457
- "authToken",
458
- "authKey",
459
- "editMode",
460
- "loaderBackground",
461
- "loaderFontColor",
462
- "loaderSpinnerColor",
463
- "loaderSpinnerBackground",
464
- "timezoneId",
465
- "itemDimensions",
466
- "apiHost"
467
- ];
468
- for (const key of params) {
469
- const value = inputParameters[key];
470
- if (value) {
471
- this[key] = value;
472
- }
473
- }
474
- if (inputParameters.experimental) {
475
- this.experimental = inputParameters.experimental;
476
- }
477
- if (inputParameters.appServer) {
478
- this.appServer = SharedLib2.addTrailingSlash(inputParameters.appServer);
479
- }
480
- }
481
427
  // Set resize event listener
482
428
  connectedCallback() {
483
429
  super.connectedCallback();
@@ -496,7 +442,6 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
496
442
  this._loaderMsg = SharedLib2.getLoader(this)?.loadingMsg;
497
443
  this._loaderStyles();
498
444
  luzmo_service_default._components.push(this);
499
- this.initComponent();
500
445
  if (this.luzmoEmbedContainer) {
501
446
  this._resizeObserver.observe(this.luzmoEmbedContainer);
502
447
  }
@@ -504,7 +449,7 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
504
449
  initComponent() {
505
450
  this.params = this._setOptions();
506
451
  if (this.getIsViewMode()) {
507
- this.loadLibrary(this.params.appServer).then(async () => {
452
+ SharedLib2.loadLibrary(this.params.appServer).then(async () => {
508
453
  this.isLibraryLoaded = true;
509
454
  await this.updateComplete;
510
455
  const oldReference = this.renderRoot.querySelector("dashboard-component");
@@ -576,11 +521,21 @@ var LuzmoDashboard = class extends import_lit2.LitElement {
576
521
  "timezoneId",
577
522
  "itemDimensions"
578
523
  ]);
524
+ const conditionsToCheck = ["dashboardId", "dashboardSlug", "itemId"];
525
+ let callInitComponent = false;
526
+ for (const condition of conditionsToCheck) {
527
+ callInitComponent = callInitComponent || changedProperties.get(condition) === void 0 && this[condition] !== void 0;
528
+ }
529
+ if (callInitComponent && !this.isInitCalled) {
530
+ this.initComponent();
531
+ this.isInitCalled = true;
532
+ return;
533
+ }
579
534
  if (this.getIsViewMode()) {
580
535
  if (this.dashboardReference) {
581
536
  for (const [propertyName] of changedProperties.entries()) {
582
537
  if (propertyName === "appSever") {
583
- this.loadLibrary(changedProperties[propertyName]).then(async () => {
538
+ SharedLib2.loadLibrary(changedProperties[propertyName]).then(async () => {
584
539
  this.isLibraryLoaded = true;
585
540
  await this.updateComplete;
586
541
  this.dashboardReference = this.renderRoot.querySelector("dashboard-component");
@@ -1079,7 +1034,7 @@ __decorateClass([
1079
1034
  ], LuzmoDashboard.prototype, "browserNotSupported", 2);
1080
1035
  __decorateClass([
1081
1036
  (0, import_decorators.property)()
1082
- ], LuzmoDashboard.prototype, "VERSION", 2);
1037
+ ], LuzmoDashboard.prototype, "libVersion", 2);
1083
1038
  __decorateClass([
1084
1039
  (0, import_decorators.state)()
1085
1040
  ], LuzmoDashboard.prototype, "isLibraryLoaded", 2);
@@ -1092,20 +1047,217 @@ __decorateClass([
1092
1047
  __decorateClass([
1093
1048
  (0, import_decorators.state)()
1094
1049
  ], LuzmoDashboard.prototype, "currentAuthToken", 2);
1050
+ __decorateClass([
1051
+ (0, import_decorators.state)()
1052
+ ], LuzmoDashboard.prototype, "isInitCalled", 2);
1095
1053
 
1096
1054
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-component.ts
1097
- var LuzmoDashboard2 = class extends LuzmoDashboard {
1098
- };
1099
- LuzmoDashboard2 = __decorateClass([
1100
- (0, import_decorators2.customElement)("luzmo-dashboard")
1101
- ], LuzmoDashboard2);
1102
1055
  var LuzmoEmbedDashboard = class extends LuzmoDashboard {
1103
1056
  };
1104
1057
  LuzmoEmbedDashboard = __decorateClass([
1105
1058
  (0, import_decorators2.customElement)("luzmo-embed-dashboard")
1106
1059
  ], LuzmoEmbedDashboard);
1060
+
1061
+ // libs/embed-libs/embed/src/lib/viz-item/viz-item-component.ts
1062
+ var import_decorators4 = require("lit/decorators.js");
1063
+
1064
+ // libs/embed-libs/embed/src/lib/viz-item/viz-item.base.ts
1065
+ var import_decorators3 = require("lit/decorators.js");
1066
+ var import_lit3 = require("lit");
1067
+ var SharedLib3 = __toESM(require("@luzmo/shared-embed"), 1);
1068
+ var import_zod_validation_error = require("zod-validation-error");
1069
+ var LuzmoBaseVizItem = class extends import_lit3.LitElement {
1070
+ constructor() {
1071
+ super();
1072
+ this.appServer = "https://app.luzmo.com";
1073
+ this.apiHost = "https://api.luzmo.com";
1074
+ this.slots = [];
1075
+ this.version = version + "-wc-luzmo";
1076
+ this.libVersion = version + "-wc-luzmo";
1077
+ this.postInitCallQueue = [];
1078
+ }
1079
+ static {
1080
+ // Static styles to set host display to block, else it is not shown at all for some reason.
1081
+ this.styles = import_lit3.css`
1082
+ :host {
1083
+ display: block;
1084
+ width: 100%;
1085
+ height: 100%;
1086
+ }
1087
+ `;
1088
+ }
1089
+ canInitializeVizItem() {
1090
+ return !!(this.type || this.dashboardId && this.itemId);
1091
+ }
1092
+ getFilters() {
1093
+ return this.chartElement.getFilters();
1094
+ }
1095
+ export() {
1096
+ return this.chartElement.export();
1097
+ }
1098
+ getData() {
1099
+ return this.chartElement.getData();
1100
+ }
1101
+ refreshData() {
1102
+ return this.chartElement.refreshData();
1103
+ }
1104
+ setFilters(filterInput) {
1105
+ return this.chartElement.setFilters(void 0, filterInput);
1106
+ }
1107
+ setAuthorization(key, token) {
1108
+ return this.chartElement.setAuthorization(key, token);
1109
+ }
1110
+ attributeChangedCallback(name, _old, value) {
1111
+ super.attributeChangedCallback(name, _old, value);
1112
+ if (name === "selecteddata") {
1113
+ if (this.chartElement) {
1114
+ this.setFilters(JSON.parse(value ?? "{}"));
1115
+ } else {
1116
+ this.postInitCallQueue.push([this.setFilters, [JSON.parse(value ?? "{}")]]);
1117
+ }
1118
+ }
1119
+ }
1120
+ async firstUpdated(_changedProperties) {
1121
+ super.firstUpdated(_changedProperties);
1122
+ if (this.canInitializeVizItem()) {
1123
+ await SharedLib3.loadLibrary(this.appServer, "DashboardApp");
1124
+ this.createAndAppendElement();
1125
+ }
1126
+ }
1127
+ createAndAppendElement() {
1128
+ if (!this.chartElement) {
1129
+ this.chartElement = document.createElement("chart-component");
1130
+ this.chartElement.setAttribute("embedding-mode", "chart");
1131
+ this.chartElement.addEventListener("load", (payload) => this.dispatchEvent(new CustomEvent("load", payload)));
1132
+ this.chartElement.addEventListener("rendered", (payload) => {
1133
+ for (const functionToCall of this.postInitCallQueue) {
1134
+ functionToCall[0].bind(this)(...functionToCall[1]);
1135
+ }
1136
+ this.dispatchEvent(new CustomEvent("rendered", payload));
1137
+ });
1138
+ this.chartElement.addEventListener("changedFilters", (payload) => this.dispatchEvent(new CustomEvent("changedFilters", payload)));
1139
+ this.chartElement.addEventListener("exported", (payload) => this.dispatchEvent(new CustomEvent("exported", payload)));
1140
+ this.chartElement.addEventListener("customEvent", (payload) => this.dispatchEvent(new CustomEvent("customEvent", payload)));
1141
+ this.updateVizItemProperties();
1142
+ this.renderRoot.append(this.chartElement);
1143
+ }
1144
+ }
1145
+ updateVizItemProperties() {
1146
+ if (this.chartElement) {
1147
+ for (const key in SharedLib3.libraryTypeToWebComponentTypeMapping) {
1148
+ const value = this[key];
1149
+ if (value) {
1150
+ this.parseAndValidate(key);
1151
+ const attributeValue = ["appServer", "apiHost"].includes(key) ? SharedLib3.removeTrailingSlash(value) : value;
1152
+ this.chartElement.setAttribute(
1153
+ SharedLib3.libraryTypeToWebComponentTypeMapping[key],
1154
+ typeof attributeValue === "object" ? JSON.stringify(attributeValue) : attributeValue
1155
+ );
1156
+ }
1157
+ }
1158
+ }
1159
+ }
1160
+ async updated(changedProperties) {
1161
+ if (this.chartElement) {
1162
+ for (const [propertyName] of changedProperties.entries()) {
1163
+ const mappedAttributeName = SharedLib3.libraryTypeToWebComponentTypeMapping[propertyName] ?? propertyName;
1164
+ this.parseAndValidate(propertyName);
1165
+ const attributeValue = typeof this[propertyName] === "object" ? JSON.stringify(this[propertyName]) : this[propertyName]?.toString() ?? this[propertyName];
1166
+ this.chartElement.setAttribute(mappedAttributeName, attributeValue);
1167
+ }
1168
+ } else {
1169
+ if (this.canInitializeVizItem()) {
1170
+ if (this.type) {
1171
+ this.parseAndValidate("type");
1172
+ }
1173
+ await SharedLib3.loadLibrary(this.appServer, "DashboardApp");
1174
+ this.createAndAppendElement();
1175
+ }
1176
+ }
1177
+ }
1178
+ parseAndValidate(key) {
1179
+ try {
1180
+ if (key === "slots") {
1181
+ SharedLib3.slotsParser.parse(this.slots);
1182
+ } else if (key === "options") {
1183
+ SharedLib3.vizItemOptionsParser.parse(this.options);
1184
+ } else if (key === "canFilter") {
1185
+ SharedLib3.canFilterParser.parse(this.canFilter);
1186
+ } else if (key === "type") {
1187
+ SharedLib3.itemTypeParser.parse(this.type);
1188
+ }
1189
+ } catch (err) {
1190
+ const validationError = (0, import_zod_validation_error.fromError)(err);
1191
+ console.warn(err);
1192
+ console.warn(validationError.toString());
1193
+ }
1194
+ }
1195
+ render() {
1196
+ return import_lit3.html` `;
1197
+ }
1198
+ };
1199
+ __decorateClass([
1200
+ (0, import_decorators3.property)()
1201
+ ], LuzmoBaseVizItem.prototype, "appServer", 2);
1202
+ __decorateClass([
1203
+ (0, import_decorators3.property)()
1204
+ ], LuzmoBaseVizItem.prototype, "apiHost", 2);
1205
+ __decorateClass([
1206
+ (0, import_decorators3.property)({ type: Array })
1207
+ ], LuzmoBaseVizItem.prototype, "slots", 2);
1208
+ __decorateClass([
1209
+ (0, import_decorators3.property)({ type: Object })
1210
+ ], LuzmoBaseVizItem.prototype, "options", 2);
1211
+ __decorateClass([
1212
+ (0, import_decorators3.property)()
1213
+ ], LuzmoBaseVizItem.prototype, "type", 2);
1214
+ __decorateClass([
1215
+ (0, import_decorators3.property)()
1216
+ ], LuzmoBaseVizItem.prototype, "authKey", 2);
1217
+ __decorateClass([
1218
+ (0, import_decorators3.property)()
1219
+ ], LuzmoBaseVizItem.prototype, "authToken", 2);
1220
+ __decorateClass([
1221
+ (0, import_decorators3.property)()
1222
+ ], LuzmoBaseVizItem.prototype, "version", 2);
1223
+ __decorateClass([
1224
+ (0, import_decorators3.property)()
1225
+ ], LuzmoBaseVizItem.prototype, "contextId", 2);
1226
+ __decorateClass([
1227
+ (0, import_decorators3.property)({
1228
+ converter: (value) => {
1229
+ try {
1230
+ return JSON.parse(value);
1231
+ } catch (exc) {
1232
+ return value;
1233
+ }
1234
+ }
1235
+ })
1236
+ ], LuzmoBaseVizItem.prototype, "canFilter", 2);
1237
+ __decorateClass([
1238
+ (0, import_decorators3.property)({ type: Array })
1239
+ ], LuzmoBaseVizItem.prototype, "filters", 2);
1240
+ __decorateClass([
1241
+ (0, import_decorators3.property)()
1242
+ ], LuzmoBaseVizItem.prototype, "dashboardId", 2);
1243
+ __decorateClass([
1244
+ (0, import_decorators3.property)()
1245
+ ], LuzmoBaseVizItem.prototype, "itemId", 2);
1246
+ __decorateClass([
1247
+ (0, import_decorators3.property)({ type: Object })
1248
+ ], LuzmoBaseVizItem.prototype, "selectedData", 2);
1249
+ __decorateClass([
1250
+ (0, import_decorators3.property)()
1251
+ ], LuzmoBaseVizItem.prototype, "libVersion", 2);
1252
+
1253
+ // libs/embed-libs/embed/src/lib/viz-item/viz-item-component.ts
1254
+ var LuzmoEmbedVizItem = class extends LuzmoBaseVizItem {
1255
+ };
1256
+ LuzmoEmbedVizItem = __decorateClass([
1257
+ (0, import_decorators4.customElement)("luzmo-embed-viz-item")
1258
+ ], LuzmoEmbedVizItem);
1107
1259
  // Annotate the CommonJS export names for ESM import in node:
1108
1260
  0 && (module.exports = {
1109
- LuzmoDashboard,
1110
- LuzmoEmbedDashboard
1261
+ LuzmoEmbedDashboard,
1262
+ LuzmoEmbedVizItem
1111
1263
  });
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export type { LoadEvent, ChangedFiltersEvent, CustomEvent, ItemsRenderedEvent, ExportedEvent, DashboardActionEvent, Filter, FilterExpression, FilterOrigin, FilterInput, FilterGroup, ExportType, ItemData, ExportDashboard, AccessibleDashboard, SetEditMode } from '@luzmo/shared-embed';
2
2
  export * from './lib/dashboard-component/dashboard-component';
3
+ export * from './lib/viz-item/viz-item-component';