@saasquatch/squatch-js 2.6.0-9 → 2.6.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.
Files changed (40) hide show
  1. package/.github/workflows/size-limit.yml +14 -14
  2. package/.github/workflows/static.yml +89 -89
  3. package/CHANGELOG.md +388 -329
  4. package/LICENSE +20 -20
  5. package/README.md +259 -208
  6. package/babel.config.js +7 -7
  7. package/cucumber.js +45 -45
  8. package/demo/sandbox.ts +124 -124
  9. package/demo/toolbar.tsx +526 -526
  10. package/dist/api/WidgetApi.d.ts +1 -0
  11. package/dist/squatch.esm.js +45 -28
  12. package/dist/squatch.esm.js.map +1 -1
  13. package/dist/squatch.js +45 -28
  14. package/dist/squatch.js.map +1 -1
  15. package/dist/squatch.min.js +1 -1
  16. package/dist/squatch.min.js.br +0 -0
  17. package/dist/squatch.min.js.map +1 -0
  18. package/dist/squatch.modern.js +2 -0
  19. package/dist/squatch.modern.js.map +1 -0
  20. package/dist/stats.html +208 -0
  21. package/dist/utils/decodeJwt.d.ts +1 -0
  22. package/dist/utils/domUtils.d.ts +1 -0
  23. package/dist/utils/loadEvent.d.ts +2 -0
  24. package/dist/widgets/CtaWidget.d.ts +24 -0
  25. package/dist/widgets/IREmbedWidget.d.ts +29 -0
  26. package/dist/widgets/IRPopupWidget.d.ts +32 -0
  27. package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +12 -0
  28. package/jest.config.ts +200 -200
  29. package/package.json +123 -123
  30. package/tsconfig.json +23 -23
  31. package/coverage/clover.xml +0 -880
  32. package/coverage/coverage-final.json +0 -21
  33. package/coverage/lcov-report/base.css +0 -224
  34. package/coverage/lcov-report/block-navigation.js +0 -87
  35. package/coverage/lcov-report/favicon.png +0 -0
  36. package/coverage/lcov-report/prettify.css +0 -1
  37. package/coverage/lcov-report/prettify.js +0 -2
  38. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  39. package/coverage/lcov-report/sorter.js +0 -196
  40. package/coverage/lcov.info +0 -1621
@@ -60,4 +60,5 @@ export default class WidgetApi {
60
60
  * @return {Promise<ReferralCookie>} code referral code if true.
61
61
  */
62
62
  squatchReferralCookie(): Promise<ReferralCookie>;
63
+ referralCookie: () => Promise<ReferralCookie>;
63
64
  }
@@ -213,6 +213,7 @@ class WidgetApi {
213
213
  this.tenantAlias = void 0;
214
214
  this.domain = void 0;
215
215
  this.npmCdn = void 0;
216
+ this.referralCookie = this.squatchReferralCookie;
216
217
  var raw = config;
217
218
  var clean = validateConfig(raw);
218
219
  this.tenantAlias = clean.tenantAlias;
@@ -421,6 +422,8 @@ var _log$8 = debug("squatch-js:widget");
421
422
 
422
423
  class Widget {
423
424
  constructor(params) {
425
+ var _params$context;
426
+
424
427
  this.type = void 0;
425
428
  this.content = void 0;
426
429
  this.analyticsApi = void 0;
@@ -439,7 +442,7 @@ class Widget {
439
442
  domain: params.domain
440
443
  });
441
444
  this.context = params.context;
442
- this.container = params.container || params.context.container;
445
+ this.container = ((_params$context = params.context) == null ? void 0 : _params$context.container) || params.container;
443
446
  }
444
447
 
445
448
  _findElement() {
@@ -740,10 +743,19 @@ class EmbedWidget extends Widget {
740
743
  }
741
744
 
742
745
  async load() {
746
+ var _this$context;
747
+
743
748
  var frame = this._createFrame();
744
749
 
745
750
  var element = this._findElement();
746
751
 
752
+ if ((_this$context = this.context) != null && _this$context.container) {
753
+ // Custom container is used
754
+ element.style.visibility = "hidden";
755
+ element.style.height = "0";
756
+ element.style["overflow-y"] = "hidden";
757
+ }
758
+
747
759
  if (this.container) {
748
760
  if (element.shadowRoot) {
749
761
  var _element$shadowRoot$l;
@@ -791,6 +803,7 @@ class EmbedWidget extends Widget {
791
803
  } = entry.contentRect; // @ts-ignore -- number will be cast to string by browsers
792
804
 
793
805
  frame.height = height;
806
+ console.log("RESIZE");
794
807
  }
795
808
  });
796
809
  var container = await this._findInnerContainer(frame);
@@ -1486,27 +1499,27 @@ function _validateTrackOptions(raw) {
1486
1499
  /** @hidden */
1487
1500
 
1488
1501
  function asyncLoad() {
1502
+ var _window;
1503
+
1489
1504
  var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
1490
- var loaded = window[namespace] || null;
1491
- var cached = window["_" + namespace] || null;
1505
+ var cached = ((_window = window["_" + namespace]) == null ? void 0 : _window.ready) || [];
1492
1506
  var declarativeCache = window.impactOnReady || window.squatchOnReady;
1493
- setTimeout(() => window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE], 0);
1494
- if (declarativeCache) setTimeout(() => declarativeCache(), 0);
1507
+ var readyFns = [...cached, declarativeCache].filter(a => !!a); // Run all of this in a setTimeout because we need to wait for the squatch module to finish loading
1495
1508
 
1496
- if (loaded) {
1497
- if (cached) (cached.ready || []).forEach(cb => setTimeout(() => cb(), 0));
1498
- setTimeout(() => {
1499
- window.squatch._auto();
1500
- }, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
1509
+ setTimeout(() => {
1510
+ // Exit early if module wasn't loaded onto window
1511
+ if (!window[DEFAULT_NAMESPACE]) return; // Set window.impact as an alias for window.squatch.
1501
1512
 
1502
- window["_" + namespace] = undefined;
1513
+ window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE]; // Run all the ready functions in a set timeout to they happen after namespace aliasing.
1503
1514
 
1504
- try {
1505
- delete window["_" + namespace];
1506
- } catch (e) {
1507
- throw e;
1508
- }
1509
- }
1515
+ readyFns.forEach(cb => cb()); // Perform auto popup
1516
+
1517
+ window[DEFAULT_NAMESPACE]._auto(); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
1518
+
1519
+
1520
+ window["_" + namespace] = undefined;
1521
+ delete window["_" + namespace];
1522
+ }, 0);
1510
1523
  }
1511
1524
 
1512
1525
  /** @hidden */
@@ -1786,16 +1799,17 @@ class DeclarativeWidget extends HTMLElement {
1786
1799
  context: {
1787
1800
  type: config.type,
1788
1801
  user: config.user,
1789
- container: this.container || this,
1802
+ container: this.container || undefined,
1790
1803
  engagementMedium: this.type
1791
1804
  },
1792
1805
  type: this.widgetType,
1793
1806
  domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
1794
- npmCdn: DEFAULT_NPM_CDN
1807
+ npmCdn: DEFAULT_NPM_CDN,
1808
+ container: this
1795
1809
  };
1796
1810
 
1797
1811
  if (this.type === "EMBED") {
1798
- return new EmbedWidget(params, params.context.container);
1812
+ return new EmbedWidget(params);
1799
1813
  } else {
1800
1814
  var useFirstChildTrigger = this.firstChild ? null : undefined;
1801
1815
  return new PopupWidget(params, useFirstChildTrigger);
@@ -1810,15 +1824,16 @@ class DeclarativeWidget extends HTMLElement {
1810
1824
  content: "error",
1811
1825
  context: {
1812
1826
  type: "error",
1813
- container: this.container || this
1827
+ container: this.container || undefined
1814
1828
  },
1815
1829
  type: "ERROR_WIDGET",
1816
1830
  domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
1817
- npmCdn: DEFAULT_NPM_CDN
1831
+ npmCdn: DEFAULT_NPM_CDN,
1832
+ container: this
1818
1833
  };
1819
1834
 
1820
1835
  if (this.type === "EMBED") {
1821
- return new EmbedWidget(params, params.context.container);
1836
+ return new EmbedWidget(params);
1822
1837
  } else {
1823
1838
  var useFirstChildTrigger = this.firstChild ? null : undefined;
1824
1839
  return new PopupWidget(params, useFirstChildTrigger);
@@ -1830,7 +1845,7 @@ class DeclarativeWidget extends HTMLElement {
1830
1845
  this.hide = this.close;
1831
1846
  this.attachShadow({
1832
1847
  mode: "open"
1833
- }).innerHTML = "<style>:host { display: contents; }</style><slot></slot>";
1848
+ }).innerHTML = "<style>:host { display: block; }</style><slot></slot>";
1834
1849
  this.config = getConfig();
1835
1850
  this.token = getToken();
1836
1851
  this.tenant = window.squatchTenant;
@@ -1906,6 +1921,7 @@ class DeclarativeWidget extends HTMLElement {
1906
1921
  }
1907
1922
 
1908
1923
  this.widgetInstance = widgetInstance;
1924
+ if (this.widgetInstance) this.dispatchEvent(new CustomEvent("sq:widget-loaded"));
1909
1925
  return widgetInstance;
1910
1926
  }
1911
1927
  /**
@@ -1985,11 +2001,12 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1985
2001
  async connectedCallback() {
1986
2002
  var _ref, _this$shadowRoot;
1987
2003
 
1988
- this.container = this.getAttribute("container") || this;
2004
+ this.loaded = true;
2005
+ this.container = this.getAttribute("container");
1989
2006
  await this.renderWidget();
1990
2007
  var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
1991
2008
  if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
1992
- this.loaded = true;
2009
+ if (this.getAttribute("open") !== null) this.open();
1993
2010
  }
1994
2011
 
1995
2012
  }
@@ -2036,10 +2053,10 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2036
2053
  }
2037
2054
 
2038
2055
  async connectedCallback() {
2039
- this.container = this.getAttribute("container") || this;
2056
+ this.loaded = true;
2057
+ this.container = this.getAttribute("container");
2040
2058
  await this.renderWidget();
2041
2059
  if (this.getAttribute("open") !== null) this.open();
2042
- this.loaded = true;
2043
2060
  }
2044
2061
 
2045
2062
  }