@luzmo/embed 6.13.3 → 6.13.6-es2021

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
@@ -23,7 +23,7 @@ import { property, query, state } from "lit/decorators.js";
23
23
  import { styleMap } from "lit/directives/style-map.js";
24
24
 
25
25
  // libs/embed-libs/embed/package.json
26
- var version = "6.13.3";
26
+ var version = "6.13.6";
27
27
 
28
28
  // libs/embed-libs/embed/src/lib/helper/event-bus-handler.ts
29
29
  import * as SharedLib from "@luzmo/shared-embed";
@@ -89,6 +89,14 @@ var _setEventHandler = () => {
89
89
  );
90
90
  break;
91
91
  }
92
+ case "dashboardContext": {
93
+ SharedLib.resolvePromise(
94
+ dashboardComponent,
95
+ event.data.requestId,
96
+ event.data.context
97
+ );
98
+ break;
99
+ }
92
100
  case "getAccessibleDashboards": {
93
101
  SharedLib.resolvePromise(
94
102
  dashboardComponent,
@@ -128,6 +136,12 @@ var _setEventHandler = () => {
128
136
  );
129
137
  break;
130
138
  }
139
+ case "contextChanged": {
140
+ dashboardComponent.dispatchEvent(
141
+ new CustomEvent("contextChanged", { detail: { data: event.data } })
142
+ );
143
+ break;
144
+ }
131
145
  case "customEvent": {
132
146
  dashboardComponent.dispatchEvent(
133
147
  new CustomEvent("customEvent", { detail: { data: event.data } })
@@ -169,6 +183,14 @@ var _setEventHandler = () => {
169
183
  SharedLib._setCalculatedDimensions(dashboardComponent);
170
184
  break;
171
185
  }
186
+ case "trackViewport": {
187
+ if (event.data.enabled) {
188
+ dashboardComponent._startViewportTracking();
189
+ } else {
190
+ dashboardComponent._stopViewportTracking();
191
+ }
192
+ break;
193
+ }
172
194
  case "setSelectedData":
173
195
  case "setFilters": {
174
196
  if (event.data.error) {
@@ -255,6 +277,24 @@ var dashboardStyles = css`
255
277
  height: 100%;
256
278
  }
257
279
 
280
+ /*
281
+ * Web component mode: the dashboard app renders directly (no iframe). Make its host fill the
282
+ * sized .dashboard-container so the app's internal height:100% chain resolves to the calculated
283
+ * dashboard height - exactly like the iframe gets its height. Without this the app collapses to
284
+ * its intrinsic size and its inner scroll container produces a second scrollbar, and content can
285
+ * spill outside the container.
286
+ */
287
+ #dashboard-wc-container {
288
+ width: 100%;
289
+ height: 100%;
290
+ }
291
+
292
+ #dashboard-wc-container dashboard-component {
293
+ display: block;
294
+ width: 100%;
295
+ height: 100%;
296
+ }
297
+
258
298
  .luzmo-container-loader {
259
299
  width: 100%;
260
300
  position: relative;
@@ -379,6 +419,12 @@ var LuzmoDashboard = class extends LitElement {
379
419
  this.loaderSize = 32;
380
420
  this.borderWidth = 3;
381
421
  this.minHeight = 400;
422
+ this._viewportTrackingActive = false;
423
+ // Post synchronously on scroll/resize (not via requestAnimationFrame) so the iframe receives the
424
+ // new slice as early as possible in the frame, minimizing the lag of the pinned analyst panel.
425
+ this._onViewportChange = () => {
426
+ this._postViewport();
427
+ };
382
428
  this._containerId = SharedLib2.uuidv4();
383
429
  this._iframeId = `luzmo-dashboard-${this._containerId}`;
384
430
  this.iframeLoaded = false;
@@ -421,12 +467,48 @@ var LuzmoDashboard = class extends LitElement {
421
467
  disconnectedCallback() {
422
468
  super.disconnectedCallback();
423
469
  this._resizeObserver.disconnect();
470
+ this._stopViewportTracking();
424
471
  for (const promiseKey of Object.keys(this.promises)) {
425
472
  this.promises[promiseKey].reject(
426
473
  new Error("Dashboard component was removed")
427
474
  );
428
475
  }
429
476
  }
477
+ // Relay the iframe's visible slice within the host viewport to the dashboard app, so embedded
478
+ // overlays (e.g. the IQ analyst) can pin themselves to the visible area while the host page
479
+ // scrolls the full-height iframe. Opt-in: started when the iframe requests it via 'trackViewport'.
480
+ _startViewportTracking() {
481
+ if (this.embedMode !== "iframe") {
482
+ return;
483
+ }
484
+ if (!this._viewportTrackingActive) {
485
+ this._viewportTrackingActive = true;
486
+ window.addEventListener("scroll", this._onViewportChange, { passive: true, capture: true });
487
+ window.addEventListener("resize", this._onViewportChange, { passive: true });
488
+ }
489
+ this._postViewport();
490
+ }
491
+ _stopViewportTracking() {
492
+ if (!this._viewportTrackingActive) {
493
+ return;
494
+ }
495
+ this._viewportTrackingActive = false;
496
+ window.removeEventListener("scroll", this._onViewportChange, { capture: true });
497
+ window.removeEventListener("resize", this._onViewportChange);
498
+ }
499
+ _postViewport() {
500
+ const contentWindow = this.iframe?.contentWindow;
501
+ if (!contentWindow) {
502
+ return;
503
+ }
504
+ const rect = this.iframe.getBoundingClientRect();
505
+ const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
506
+ const visibleTop = Math.max(rect.top, 0);
507
+ const visibleBottom = Math.min(rect.bottom, viewportHeight);
508
+ const visibleHeight = Math.max(visibleBottom - visibleTop, 0);
509
+ const offsetTop = Math.min(Math.max(-rect.top, 0), rect.height);
510
+ contentWindow.postMessage({ action: "setViewport", offsetTop, visibleHeight }, "*");
511
+ }
430
512
  firstUpdated() {
431
513
  this._loaderMsg = SharedLib2.getLoader(this)?.loadingMsg;
432
514
  this._loaderStyles();
@@ -455,6 +537,7 @@ var LuzmoDashboard = class extends LitElement {
455
537
  el.addEventListener("changedFilters", (payload) => this.dispatchEvent(new CustomEvent("changedFilters", payload)));
456
538
  el.addEventListener("dashboardAction", (payload) => this.dispatchEvent(new CustomEvent("dashboardAction", payload)));
457
539
  el.addEventListener("export", (payload) => this.dispatchEvent(new CustomEvent("exported", payload)));
540
+ el.addEventListener("contextChanged", (payload) => this.dispatchEvent(new CustomEvent("contextChanged", payload)));
458
541
  const container = this.renderRoot.querySelector("#dashboard-wc-container");
459
542
  if (container) {
460
543
  container.append(el);
@@ -810,6 +893,15 @@ var LuzmoDashboard = class extends LitElement {
810
893
  }
811
894
  return Promise.reject();
812
895
  }
896
+ getDashboardContext() {
897
+ if (this.isWebComponentViewMode() && this.dashboardReference) {
898
+ return this.dashboardReference.getDashboardContext();
899
+ }
900
+ if (!this.isWebComponentViewMode()) {
901
+ return SharedLib2.getDashboardContext(this, this.iframe);
902
+ }
903
+ return Promise.reject(new Error("getDashboardContext is not available: dashboard reference is not ready."));
904
+ }
813
905
  setSelectedData(itemId, filters) {
814
906
  if (this.isWebComponentViewMode() && this.dashboardReference) {
815
907
  return this.dashboardReference.setSelectedData(itemId, filters);
@@ -1080,15 +1172,26 @@ if (!customElements.get("luzmo-embed-dashboard")) {
1080
1172
  customElements.define("luzmo-embed-dashboard", LuzmoEmbedDashboard);
1081
1173
  }
1082
1174
 
1083
- // libs/dashboard-contents-types/src/lib/shared/version.ts
1084
- var CONTENTS_VERSION = "0.1.100";
1085
-
1086
1175
  // libs/embed-libs/embed/src/lib/viz-item/viz-item.base.ts
1176
+ import { CONTENTS_VERSION } from "@luzmo/dashboard-contents-types";
1087
1177
  import * as SharedLib3 from "@luzmo/shared-embed";
1088
1178
  import { css as css2, html as html2, LitElement as LitElement2 } from "lit";
1089
1179
  import { property as property2 } from "lit/decorators.js";
1090
1180
  var dashboardContentsVersion = CONTENTS_VERSION;
1091
1181
  var vizItemRemote = "VizItemApp";
1182
+ function collectVizItemDatasetIds(slots) {
1183
+ const ids = /* @__PURE__ */ new Set();
1184
+ for (const slot of slots ?? []) {
1185
+ for (const content of slot?.content ?? []) {
1186
+ const column = content;
1187
+ const datasetId = column.datasetId ?? column.set;
1188
+ if (datasetId) {
1189
+ ids.add(datasetId);
1190
+ }
1191
+ }
1192
+ }
1193
+ return [...ids];
1194
+ }
1092
1195
  var LuzmoBaseVizItem = class extends LitElement2 {
1093
1196
  constructor() {
1094
1197
  super(...arguments);
@@ -1100,22 +1203,6 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1100
1203
  this.libVersion = version + "-wc-luzmo";
1101
1204
  this.postInitCallQueue = [];
1102
1205
  }
1103
- static {
1104
- // Static styles to set host display to block, else it is not shown at all for some reason.
1105
- this.styles = css2`
1106
- :host {
1107
- display: block;
1108
- width: 100%;
1109
- height: 100%;
1110
- }
1111
-
1112
- luzmo-embed-viz-item {
1113
- width: 100%;
1114
- height: 1000%;
1115
- display: block;
1116
- }
1117
- `;
1118
- }
1119
1206
  createRenderRoot() {
1120
1207
  if (!this.style.display) {
1121
1208
  this.style.display = "block";
@@ -1134,6 +1221,22 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1134
1221
  getFilters() {
1135
1222
  return this.chartElement.getFilters();
1136
1223
  }
1224
+ /**
1225
+ * Snapshot of this flex chart's live context: its definition (type, slots,
1226
+ * options), current filters and the datasets it reads. Used by context-aware
1227
+ * embeds such as the Luzmo IQ chat component.
1228
+ */
1229
+ getVizItemContext() {
1230
+ const slots = this.slots ?? [];
1231
+ return {
1232
+ id: this.contextId ?? this.getAttribute("context-id") ?? this.id ?? this.itemId ?? "",
1233
+ type: this.type,
1234
+ slots,
1235
+ options: this.options,
1236
+ filters: typeof this.chartElement?.getFilters === "function" ? this.getFilters() : this.filters ?? [],
1237
+ datasetIds: collectVizItemDatasetIds(slots)
1238
+ };
1239
+ }
1137
1240
  export(type = "png") {
1138
1241
  return this.chartElement.export(type);
1139
1242
  }
@@ -1186,7 +1289,12 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1186
1289
  }
1187
1290
  this.dispatchEvent(new CustomEvent("rendered", payload));
1188
1291
  });
1189
- this.chartElement.addEventListener("changedFilters", (payload) => this.dispatchEvent(new CustomEvent("changedFilters", payload)));
1292
+ this.chartElement.addEventListener("changedFilters", (payload) => {
1293
+ this.dispatchEvent(new CustomEvent("changedFilters", payload));
1294
+ this.dispatchEvent(new CustomEvent("contextChanged", {
1295
+ detail: { data: { type: "contextChanged", context: this.getVizItemContext() } }
1296
+ }));
1297
+ });
1190
1298
  this.chartElement.addEventListener("exported", (payload) => this.dispatchEvent(new CustomEvent("exported", payload)));
1191
1299
  this.chartElement.addEventListener("customEvent", (payload) => this.dispatchEvent(new CustomEvent("customEvent", payload)));
1192
1300
  this.chartElement.addEventListener("authorizationExpired", (payload) => this.dispatchEvent(new CustomEvent("authorizationExpired", payload)));
@@ -1226,6 +1334,20 @@ var LuzmoBaseVizItem = class extends LitElement2 {
1226
1334
  return html2` `;
1227
1335
  }
1228
1336
  };
1337
+ // Static styles to set host display to block, else it is not shown at all for some reason.
1338
+ LuzmoBaseVizItem.styles = css2`
1339
+ :host {
1340
+ display: block;
1341
+ width: 100%;
1342
+ height: 100%;
1343
+ }
1344
+
1345
+ luzmo-embed-viz-item {
1346
+ width: 100%;
1347
+ height: 1000%;
1348
+ display: block;
1349
+ }
1350
+ `;
1229
1351
  __decorateClass([
1230
1352
  property2()
1231
1353
  ], LuzmoBaseVizItem.prototype, "appServer", 2);
@@ -1273,6 +1395,9 @@ __decorateClass([
1273
1395
  __decorateClass([
1274
1396
  property2()
1275
1397
  ], LuzmoBaseVizItem.prototype, "itemId", 2);
1398
+ __decorateClass([
1399
+ property2({ attribute: "ai-message-asset-id" })
1400
+ ], LuzmoBaseVizItem.prototype, "aiMessageAssetId", 2);
1276
1401
  __decorateClass([
1277
1402
  property2({ type: Object })
1278
1403
  ], LuzmoBaseVizItem.prototype, "selectedData", 2);
@@ -1305,7 +1430,10 @@ var inputMap = {
1305
1430
  version: "version",
1306
1431
  libVersion: "lib-version",
1307
1432
  aydHost: "ayd-host",
1308
- availableDatasets: "available-datasets"
1433
+ availableDatasets: "available-datasets",
1434
+ dashboardContext: "dashboard-context",
1435
+ dashboardId: "dashboard-id",
1436
+ contextIds: "context-ids"
1309
1437
  };
1310
1438
  var embedChatTag = "luzmo-iq-embed-chat";
1311
1439
  var chatComponentTag = "luzmo-iq-chat-component";
@@ -1319,16 +1447,6 @@ var LuzmoIQEmbedChatComponent = class extends LitElement3 {
1319
1447
  this.remoteEntryServer = "http://localhost:4202/";
1320
1448
  this.aydHost = "https://ayd.luzmo.com/";
1321
1449
  }
1322
- static {
1323
- // Static styles to set host display to block, else it is not shown at all for some reason.
1324
- this.styles = css3`
1325
- :host {
1326
- display: block;
1327
- width: 100%;
1328
- height: 100%;
1329
- }
1330
- `;
1331
- }
1332
1450
  createRenderRoot() {
1333
1451
  return this;
1334
1452
  }
@@ -1344,6 +1462,10 @@ var LuzmoIQEmbedChatComponent = class extends LitElement3 {
1344
1462
  if (!this.chartElement) {
1345
1463
  this.chartElement = document.createElement(chatComponentTag);
1346
1464
  this.chartElement.addEventListener("load", (payload) => this.dispatchEvent(new CustomEvent("load", payload)));
1465
+ this.chartElement.addEventListener(
1466
+ "connectionStatusChanged",
1467
+ (event) => this.dispatchEvent(new CustomEvent("connectionStatusChanged", { detail: event.detail }))
1468
+ );
1347
1469
  this.updateVizItemProperties();
1348
1470
  this.renderRoot.append(this.chartElement);
1349
1471
  }
@@ -1366,7 +1488,12 @@ var LuzmoIQEmbedChatComponent = class extends LitElement3 {
1366
1488
  if (this.chartElement) {
1367
1489
  for (const [propertyName] of changedProperties.entries()) {
1368
1490
  const mappedAttributeName = inputMap[propertyName] ?? propertyName;
1369
- const attributeValue = typeof this[propertyName] === "object" ? JSON.stringify(this[propertyName]) : this[propertyName]?.toString() ?? this[propertyName];
1491
+ const propertyValue = this[propertyName];
1492
+ if (propertyValue == null) {
1493
+ this.chartElement.removeAttribute(mappedAttributeName);
1494
+ continue;
1495
+ }
1496
+ const attributeValue = typeof propertyValue === "object" ? JSON.stringify(propertyValue) : propertyValue.toString();
1370
1497
  this.chartElement.setAttribute(mappedAttributeName, attributeValue);
1371
1498
  }
1372
1499
  } else {
@@ -1397,6 +1524,14 @@ var LuzmoIQEmbedChatComponent = class extends LitElement3 {
1397
1524
  observer.observe(embedChat, { childList: true, subtree: true });
1398
1525
  }
1399
1526
  };
1527
+ // Static styles to set host display to block, else it is not shown at all for some reason.
1528
+ LuzmoIQEmbedChatComponent.styles = css3`
1529
+ :host {
1530
+ display: block;
1531
+ width: 100%;
1532
+ height: 100%;
1533
+ }
1534
+ `;
1400
1535
  __decorateClass([
1401
1536
  property3()
1402
1537
  ], LuzmoIQEmbedChatComponent.prototype, "appServer", 2);
@@ -1433,6 +1568,15 @@ __decorateClass([
1433
1568
  __decorateClass([
1434
1569
  property3({ type: Array })
1435
1570
  ], LuzmoIQEmbedChatComponent.prototype, "availableDatasets", 2);
1571
+ __decorateClass([
1572
+ property3({ type: Object })
1573
+ ], LuzmoIQEmbedChatComponent.prototype, "dashboardContext", 2);
1574
+ __decorateClass([
1575
+ property3()
1576
+ ], LuzmoIQEmbedChatComponent.prototype, "dashboardId", 2);
1577
+ __decorateClass([
1578
+ property3({ type: Array })
1579
+ ], LuzmoIQEmbedChatComponent.prototype, "contextIds", 2);
1436
1580
  if (!customElements.get(embedChatTag)) {
1437
1581
  customElements.define(embedChatTag, LuzmoIQEmbedChatComponent);
1438
1582
  }
@@ -1462,16 +1606,6 @@ var LuzmoIQEmbedAnswerComponent = class extends LitElement4 {
1462
1606
  this.libVersion = version + "-wc-luzmo";
1463
1607
  this.remoteEntryServer = "http://localhost:4202";
1464
1608
  }
1465
- static {
1466
- // Static styles to set host display to block, else it is not shown at all for some reason.
1467
- this.styles = css4`
1468
- :host {
1469
- display: block;
1470
- width: 100%;
1471
- height: 100%;
1472
- }
1473
- `;
1474
- }
1475
1609
  createRenderRoot() {
1476
1610
  return this;
1477
1611
  }
@@ -1522,6 +1656,14 @@ var LuzmoIQEmbedAnswerComponent = class extends LitElement4 {
1522
1656
  return html4` `;
1523
1657
  }
1524
1658
  };
1659
+ // Static styles to set host display to block, else it is not shown at all for some reason.
1660
+ LuzmoIQEmbedAnswerComponent.styles = css4`
1661
+ :host {
1662
+ display: block;
1663
+ width: 100%;
1664
+ height: 100%;
1665
+ }
1666
+ `;
1525
1667
  __decorateClass([
1526
1668
  property4()
1527
1669
  ], LuzmoIQEmbedAnswerComponent.prototype, "appServer", 2);