@saasquatch/squatch-js 2.6.0-8 → 2.6.0-9

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 (47) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/coverage/clover.xml +584 -569
  3. package/coverage/coverage-final.json +20 -19
  4. package/coverage/lcov.info +965 -937
  5. package/dist/async.d.ts +2 -0
  6. package/dist/globals.d.ts +4 -0
  7. package/dist/squatch.esm.js +41 -27
  8. package/dist/squatch.esm.js.map +1 -1
  9. package/dist/squatch.js +41 -27
  10. package/dist/squatch.js.map +1 -1
  11. package/dist/squatch.min.js +1 -1
  12. package/dist/utils/validate.d.ts +0 -2
  13. package/dist/widgets/PopupWidget.d.ts +2 -2
  14. package/dist/widgets/declarative/DeclarativeWidget.d.ts +5 -0
  15. package/package.json +1 -1
  16. package/coverage/lcov-report/DeclarativeWidget.ts.html +0 -790
  17. package/coverage/lcov-report/WidgetApi.ts.html +0 -631
  18. package/coverage/lcov-report/Widgets.ts.html +0 -1105
  19. package/coverage/lcov-report/api/AnalyticsApi.ts.html +0 -304
  20. package/coverage/lcov-report/api/EventsApi.ts.html +0 -352
  21. package/coverage/lcov-report/api/WidgetApi.ts.html +0 -658
  22. package/coverage/lcov-report/api/graphql.ts.html +0 -130
  23. package/coverage/lcov-report/squatch.ts.html +0 -721
  24. package/coverage/lcov-report/utils/cookieUtils.ts.html +0 -415
  25. package/coverage/lcov-report/utils/decodeUserJwt.ts.html +0 -133
  26. package/coverage/lcov-report/utils/domready.ts.html +0 -160
  27. package/coverage/lcov-report/utils/io.ts.html +0 -400
  28. package/coverage/lcov-report/utils/utmUtils.ts.html +0 -277
  29. package/coverage/lcov-report/utils/validate.ts.html +0 -268
  30. package/coverage/lcov-report/validate.ts.html +0 -268
  31. package/coverage/lcov-report/widgets/EmbedWidget.ts.html +0 -481
  32. package/coverage/lcov-report/widgets/PopupWidget.ts.html +0 -685
  33. package/coverage/lcov-report/widgets/Widget.ts.html +0 -1159
  34. package/coverage/lcov-report/widgets/Widgets.ts.html +0 -1102
  35. package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +0 -790
  36. package/coverage/lcov-report/widgets/declarative/DeclarativeWidgets.ts.html +0 -388
  37. package/dist/squatch.min.js.map +0 -1
  38. package/dist/squatch.modern.js +0 -2
  39. package/dist/squatch.modern.js.map +0 -1
  40. package/dist/stats.html +0 -208
  41. package/dist/utils/domUtils.d.ts +0 -1
  42. package/dist/utils/loadEvent.d.ts +0 -2
  43. package/dist/widgets/CtaWidget.d.ts +0 -24
  44. package/dist/widgets/IREmbedWidget.d.ts +0 -29
  45. package/dist/widgets/IRPopupWidget.d.ts +0 -32
  46. package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +0 -12
  47. package/stats.json +0 -1
package/dist/squatch.js CHANGED
@@ -41,6 +41,9 @@ function _objectWithoutPropertiesLoose(source, excluded) {
41
41
 
42
42
  var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
43
43
  var DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
44
+ var DEFAULT_NAMESPACE = "squatch";
45
+ var IMPACT_NAMESPACE = "impact";
46
+
44
47
  function validateConfig(_raw) {
45
48
  if (typeof _raw !== "object") throw new Error("config must be an object");
46
49
  var tenant = window.squatchTenant;
@@ -342,12 +345,11 @@ function _buildParams(_ref) {
342
345
  engagementMedium,
343
346
  locale
344
347
  } = _ref;
345
- var engagementMediumP = "engagementMedium=" + encodeURIComponent(engagementMedium);
346
- var widgetTypeP = widgetType && "widgetType=" + encodeURIComponent(widgetType);
347
- var localeP = locale && "locale=" + encodeURIComponent(locale);
348
- var params = [engagementMediumP, widgetTypeP, localeP].filter(x => !!x);
349
- var queryString = "?" + params.join("&");
350
- return queryString;
348
+ var queryParams = new URLSearchParams();
349
+ queryParams.append("engagementMedium", engagementMedium);
350
+ if (widgetType) queryParams.append("widgetType", widgetType);
351
+ if (locale) queryParams.append("locale", locale);
352
+ return "?" + queryParams.toString();
351
353
  }
352
354
 
353
355
  // @ts-check
@@ -442,7 +444,7 @@ class Widget {
442
444
  domain: params.domain
443
445
  });
444
446
  this.context = params.context;
445
- this.container = params.context.container;
447
+ this.container = params.container || params.context.container;
446
448
  }
447
449
 
448
450
  _findElement() {
@@ -465,12 +467,12 @@ class Widget {
465
467
  _log$8("container must be an HTMLElement or string", this.container); // find element on page
466
468
 
467
469
  } else {
468
- element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
470
+ element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed");
469
471
 
470
472
  _log$8("loading widget with default selector", element);
471
473
  }
472
474
 
473
- if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .squatchembed") + "' not found.'");
475
+ if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed, .squatchembed, #impactembed, or .impactembed") + "' not found.'");
474
476
  return element;
475
477
  }
476
478
 
@@ -812,20 +814,19 @@ class EmbedWidget extends Widget {
812
814
 
813
815
 
814
816
  open() {
815
- var _frame$contentDocumen, _frame$contentWindow, _frame$contentWindow2;
816
-
817
817
  var frame = this._findFrame();
818
818
 
819
819
  if (!frame) return _log$7("no target element to open");
820
+ if (!frame.contentWindow) return _log$7("Frame needs a content window");
820
821
 
821
822
  var element = this._findElement();
822
823
 
823
824
  element.style.visibility = "unset";
824
825
  element.style.height = "auto";
825
826
  element.style["overflow-y"] = "auto";
826
- frame == null ? void 0 : (_frame$contentDocumen = frame.contentDocument) == null ? void 0 : _frame$contentDocumen.dispatchEvent(new CustomEvent("sq:refresh"));
827
+ frame.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
827
828
 
828
- var _sqh = (frame == null ? void 0 : (_frame$contentWindow = frame.contentWindow) == null ? void 0 : _frame$contentWindow.squatch) || (frame == null ? void 0 : (_frame$contentWindow2 = frame.contentWindow) == null ? void 0 : _frame$contentWindow2.widgetIdent);
829
+ var _sqh = frame.contentWindow.squatch || frame.contentWindow.widgetIdent;
829
830
 
830
831
  if (this.context.user) {
831
832
  this._loadEvent(_sqh);
@@ -917,7 +918,7 @@ class PopupWidget extends Widget {
917
918
  try {
918
919
  triggerElement
919
920
  /* HTMLButton */
920
- = document.querySelector(this.trigger);
921
+ = document.querySelector(this.trigger) || document.querySelector(".impactpop");
921
922
  if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
922
923
  } catch (_unused) {
923
924
  _log$6("Not a valid selector", this.trigger);
@@ -945,7 +946,7 @@ class PopupWidget extends Widget {
945
946
  return dialog;
946
947
  }
947
948
 
948
- load() {
949
+ async load() {
949
950
  var _dialogParent$lastChi;
950
951
 
951
952
  var frame = this._createFrame();
@@ -983,10 +984,10 @@ class PopupWidget extends Widget {
983
984
 
984
985
  _log$6("Popup template loaded into iframe");
985
986
 
986
- this._setupResizeHandler(frame);
987
+ await this._setupResizeHandler(frame);
987
988
  }
988
989
 
989
- _setupResizeHandler(frame) {
990
+ async _setupResizeHandler(frame) {
990
991
  var {
991
992
  contentWindow
992
993
  } = frame;
@@ -1488,16 +1489,17 @@ function _validateTrackOptions(raw) {
1488
1489
  }
1489
1490
 
1490
1491
  /** @hidden */
1492
+
1491
1493
  function asyncLoad() {
1492
- var impactNamespace = "impactTBD";
1493
- var namespace = window[impactNamespace] ? impactNamespace : "squatch";
1494
+ var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
1494
1495
  var loaded = window[namespace] || null;
1495
1496
  var cached = window["_" + namespace] || null;
1497
+ var declarativeCache = window.impactOnReady || window.squatchOnReady;
1498
+ setTimeout(() => window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE], 0);
1499
+ if (declarativeCache) setTimeout(() => declarativeCache(), 0);
1496
1500
 
1497
- if (loaded && cached) {
1498
- var ready = cached.ready || [];
1499
- setTimeout(() => window["impactTBD"] = window.squatch, 0);
1500
- ready.forEach(cb => setTimeout(() => cb(), 0));
1501
+ if (loaded) {
1502
+ if (cached) (cached.ready || []).forEach(cb => setTimeout(() => cb(), 0));
1501
1503
  setTimeout(() => {
1502
1504
  window.squatch._auto();
1503
1505
  }, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
@@ -1760,6 +1762,11 @@ class DeclarativeWidget extends HTMLElement {
1760
1762
  * Container element to contain the widget iframe
1761
1763
  * @default this
1762
1764
  */
1765
+
1766
+ /**
1767
+ * Flag for if the component has been loaded or not
1768
+ * @hidden
1769
+ */
1763
1770
  constructor() {
1764
1771
  super();
1765
1772
  this.config = void 0;
@@ -1773,6 +1780,7 @@ class DeclarativeWidget extends HTMLElement {
1773
1780
  this.type = void 0;
1774
1781
  this.container = void 0;
1775
1782
  this.element = void 0;
1783
+ this.loaded = void 0;
1776
1784
 
1777
1785
  this._setWidget = (template, config) => {
1778
1786
  var _this$config;
@@ -1794,7 +1802,8 @@ class DeclarativeWidget extends HTMLElement {
1794
1802
  if (this.type === "EMBED") {
1795
1803
  return new EmbedWidget(params, params.context.container);
1796
1804
  } else {
1797
- return new PopupWidget(params, this.firstChild ? null : undefined);
1805
+ var useFirstChildTrigger = this.firstChild ? null : undefined;
1806
+ return new PopupWidget(params, useFirstChildTrigger);
1798
1807
  }
1799
1808
  };
1800
1809
 
@@ -1816,7 +1825,8 @@ class DeclarativeWidget extends HTMLElement {
1816
1825
  if (this.type === "EMBED") {
1817
1826
  return new EmbedWidget(params, params.context.container);
1818
1827
  } else {
1819
- return new PopupWidget(params, this.firstChild ? null : undefined);
1828
+ var useFirstChildTrigger = this.firstChild ? null : undefined;
1829
+ return new PopupWidget(params, useFirstChildTrigger);
1820
1830
  }
1821
1831
  };
1822
1832
 
@@ -1959,6 +1969,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1959
1969
  */
1960
1970
 
1961
1971
  this.type = "EMBED";
1972
+ this.loaded = false;
1962
1973
  }
1963
1974
 
1964
1975
  static get observedAttributes() {
@@ -1966,7 +1977,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1966
1977
  }
1967
1978
 
1968
1979
  attributeChangedCallback(attr, oldVal, newVal) {
1969
- if (oldVal === newVal || !oldVal) return; // nothing to do
1980
+ if (oldVal === newVal || !this.loaded) return; // nothing to do
1970
1981
 
1971
1982
  switch (attr) {
1972
1983
  case "locale":
@@ -1983,6 +1994,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1983
1994
  await this.renderWidget();
1984
1995
  var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
1985
1996
  if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
1997
+ this.loaded = true;
1986
1998
  }
1987
1999
 
1988
2000
  }
@@ -2006,6 +2018,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2006
2018
  */
2007
2019
 
2008
2020
  this.type = "POPUP";
2021
+ this.loaded = false;
2009
2022
  this.addEventListener("click", e => {
2010
2023
  e.stopPropagation();
2011
2024
  this.open();
@@ -2017,7 +2030,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2017
2030
  }
2018
2031
 
2019
2032
  attributeChangedCallback(attr, oldVal, newVal) {
2020
- if (oldVal === newVal || !oldVal) return; // nothing to do
2033
+ if (oldVal === newVal || !this.loaded) return; // nothing to do
2021
2034
 
2022
2035
  switch (attr) {
2023
2036
  case "locale":
@@ -2031,6 +2044,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2031
2044
  this.container = this.getAttribute("container") || this;
2032
2045
  await this.renderWidget();
2033
2046
  if (this.getAttribute("open") !== null) this.open();
2047
+ this.loaded = true;
2034
2048
  }
2035
2049
 
2036
2050
  }