@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
package/dist/squatch.js CHANGED
@@ -218,6 +218,7 @@ class WidgetApi {
218
218
  this.tenantAlias = void 0;
219
219
  this.domain = void 0;
220
220
  this.npmCdn = void 0;
221
+ this.referralCookie = this.squatchReferralCookie;
221
222
  var raw = config;
222
223
  var clean = validateConfig(raw);
223
224
  this.tenantAlias = clean.tenantAlias;
@@ -426,6 +427,8 @@ var _log$8 = debug.debug("squatch-js:widget");
426
427
 
427
428
  class Widget {
428
429
  constructor(params) {
430
+ var _params$context;
431
+
429
432
  this.type = void 0;
430
433
  this.content = void 0;
431
434
  this.analyticsApi = void 0;
@@ -444,7 +447,7 @@ class Widget {
444
447
  domain: params.domain
445
448
  });
446
449
  this.context = params.context;
447
- this.container = params.container || params.context.container;
450
+ this.container = ((_params$context = params.context) == null ? void 0 : _params$context.container) || params.container;
448
451
  }
449
452
 
450
453
  _findElement() {
@@ -745,10 +748,19 @@ class EmbedWidget extends Widget {
745
748
  }
746
749
 
747
750
  async load() {
751
+ var _this$context;
752
+
748
753
  var frame = this._createFrame();
749
754
 
750
755
  var element = this._findElement();
751
756
 
757
+ if ((_this$context = this.context) != null && _this$context.container) {
758
+ // Custom container is used
759
+ element.style.visibility = "hidden";
760
+ element.style.height = "0";
761
+ element.style["overflow-y"] = "hidden";
762
+ }
763
+
752
764
  if (this.container) {
753
765
  if (element.shadowRoot) {
754
766
  var _element$shadowRoot$l;
@@ -796,6 +808,7 @@ class EmbedWidget extends Widget {
796
808
  } = entry.contentRect; // @ts-ignore -- number will be cast to string by browsers
797
809
 
798
810
  frame.height = height;
811
+ console.log("RESIZE");
799
812
  }
800
813
  });
801
814
  var container = await this._findInnerContainer(frame);
@@ -1491,27 +1504,27 @@ function _validateTrackOptions(raw) {
1491
1504
  /** @hidden */
1492
1505
 
1493
1506
  function asyncLoad() {
1507
+ var _window;
1508
+
1494
1509
  var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
1495
- var loaded = window[namespace] || null;
1496
- var cached = window["_" + namespace] || null;
1510
+ var cached = ((_window = window["_" + namespace]) == null ? void 0 : _window.ready) || [];
1497
1511
  var declarativeCache = window.impactOnReady || window.squatchOnReady;
1498
- setTimeout(() => window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE], 0);
1499
- if (declarativeCache) setTimeout(() => declarativeCache(), 0);
1512
+ 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
1500
1513
 
1501
- if (loaded) {
1502
- if (cached) (cached.ready || []).forEach(cb => setTimeout(() => cb(), 0));
1503
- setTimeout(() => {
1504
- window.squatch._auto();
1505
- }, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
1514
+ setTimeout(() => {
1515
+ // Exit early if module wasn't loaded onto window
1516
+ if (!window[DEFAULT_NAMESPACE]) return; // Set window.impact as an alias for window.squatch.
1506
1517
 
1507
- window["_" + namespace] = undefined;
1518
+ window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE]; // Run all the ready functions in a set timeout to they happen after namespace aliasing.
1508
1519
 
1509
- try {
1510
- delete window["_" + namespace];
1511
- } catch (e) {
1512
- throw e;
1513
- }
1514
- }
1520
+ readyFns.forEach(cb => cb()); // Perform auto popup
1521
+
1522
+ window[DEFAULT_NAMESPACE]._auto(); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
1523
+
1524
+
1525
+ window["_" + namespace] = undefined;
1526
+ delete window["_" + namespace];
1527
+ }, 0);
1515
1528
  }
1516
1529
 
1517
1530
  /** @hidden */
@@ -1791,16 +1804,17 @@ class DeclarativeWidget extends HTMLElement {
1791
1804
  context: {
1792
1805
  type: config.type,
1793
1806
  user: config.user,
1794
- container: this.container || this,
1807
+ container: this.container || undefined,
1795
1808
  engagementMedium: this.type
1796
1809
  },
1797
1810
  type: this.widgetType,
1798
1811
  domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
1799
- npmCdn: DEFAULT_NPM_CDN
1812
+ npmCdn: DEFAULT_NPM_CDN,
1813
+ container: this
1800
1814
  };
1801
1815
 
1802
1816
  if (this.type === "EMBED") {
1803
- return new EmbedWidget(params, params.context.container);
1817
+ return new EmbedWidget(params);
1804
1818
  } else {
1805
1819
  var useFirstChildTrigger = this.firstChild ? null : undefined;
1806
1820
  return new PopupWidget(params, useFirstChildTrigger);
@@ -1815,15 +1829,16 @@ class DeclarativeWidget extends HTMLElement {
1815
1829
  content: "error",
1816
1830
  context: {
1817
1831
  type: "error",
1818
- container: this.container || this
1832
+ container: this.container || undefined
1819
1833
  },
1820
1834
  type: "ERROR_WIDGET",
1821
1835
  domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
1822
- npmCdn: DEFAULT_NPM_CDN
1836
+ npmCdn: DEFAULT_NPM_CDN,
1837
+ container: this
1823
1838
  };
1824
1839
 
1825
1840
  if (this.type === "EMBED") {
1826
- return new EmbedWidget(params, params.context.container);
1841
+ return new EmbedWidget(params);
1827
1842
  } else {
1828
1843
  var useFirstChildTrigger = this.firstChild ? null : undefined;
1829
1844
  return new PopupWidget(params, useFirstChildTrigger);
@@ -1835,7 +1850,7 @@ class DeclarativeWidget extends HTMLElement {
1835
1850
  this.hide = this.close;
1836
1851
  this.attachShadow({
1837
1852
  mode: "open"
1838
- }).innerHTML = "<style>:host { display: contents; }</style><slot></slot>";
1853
+ }).innerHTML = "<style>:host { display: block; }</style><slot></slot>";
1839
1854
  this.config = getConfig();
1840
1855
  this.token = getToken();
1841
1856
  this.tenant = window.squatchTenant;
@@ -1911,6 +1926,7 @@ class DeclarativeWidget extends HTMLElement {
1911
1926
  }
1912
1927
 
1913
1928
  this.widgetInstance = widgetInstance;
1929
+ if (this.widgetInstance) this.dispatchEvent(new CustomEvent("sq:widget-loaded"));
1914
1930
  return widgetInstance;
1915
1931
  }
1916
1932
  /**
@@ -1990,11 +2006,12 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1990
2006
  async connectedCallback() {
1991
2007
  var _ref, _this$shadowRoot;
1992
2008
 
1993
- this.container = this.getAttribute("container") || this;
2009
+ this.loaded = true;
2010
+ this.container = this.getAttribute("container");
1994
2011
  await this.renderWidget();
1995
2012
  var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
1996
2013
  if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
1997
- this.loaded = true;
2014
+ if (this.getAttribute("open") !== null) this.open();
1998
2015
  }
1999
2016
 
2000
2017
  }
@@ -2041,10 +2058,10 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2041
2058
  }
2042
2059
 
2043
2060
  async connectedCallback() {
2044
- this.container = this.getAttribute("container") || this;
2061
+ this.loaded = true;
2062
+ this.container = this.getAttribute("container");
2045
2063
  await this.renderWidget();
2046
2064
  if (this.getAttribute("open") !== null) this.open();
2047
- this.loaded = true;
2048
2065
  }
2049
2066
 
2050
2067
  }