@saasquatch/squatch-js 2.8.2-16 → 2.8.2-17

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.
@@ -1119,104 +1119,13 @@ class EmbedWidget extends Widget {
1119
1119
  }
1120
1120
  }
1121
1121
  //Old code for testing
1122
- async load() {
1123
- var _a2, _b, _c, _d, _e;
1124
- const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1125
- const sizes = (_c = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _c.embeddedWidgets;
1126
- const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "";
1127
- const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "";
1128
- const frame = this._createFrame({ minWidth, maxWidth });
1129
- const element = this._findElement();
1130
- if ((_d = this.context) == null ? void 0 : _d.container) {
1131
- element.style.visibility = "hidden";
1132
- element.style.height = "0";
1133
- element.style["overflow-y"] = "hidden";
1134
- }
1135
- if (this.container) {
1136
- if (element.shadowRoot) {
1137
- if (((_e = element.shadowRoot.lastChild) == null ? void 0 : _e.nodeName) === "IFRAME") {
1138
- element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
1139
- } else {
1140
- element.shadowRoot.appendChild(frame);
1141
- }
1142
- } else if (element.firstChild) {
1143
- element.replaceChild(frame, element.firstChild);
1144
- } else {
1145
- element.appendChild(frame);
1146
- }
1147
- } else if (!element.firstChild || element.firstChild.nodeName === "#text") {
1148
- element.appendChild(frame);
1149
- }
1150
- const { contentWindow } = frame;
1151
- if (!contentWindow) {
1152
- throw new Error("Frame needs a content window");
1153
- }
1154
- const frameDoc = contentWindow.document;
1155
- frameDoc.open();
1156
- frameDoc.write(this.content);
1157
- frameDoc.write(
1158
- `<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`
1159
- );
1160
- frameDoc.close();
1161
- domready(frameDoc, async () => {
1162
- const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1163
- frame.height = frameDoc.body.scrollHeight;
1164
- const ro = new contentWindow["ResizeObserver"]((entries) => {
1165
- for (const entry of entries) {
1166
- const { height } = entry.contentRect;
1167
- frame.height = height;
1168
- }
1169
- });
1170
- const container = await this._findInnerContainer(frame);
1171
- ro.observe(container);
1172
- if (this._shouldFireLoadEvent()) {
1173
- this._loadEvent(_sqh);
1174
- _log$7("loaded");
1175
- } else if (frameDoc) {
1176
- this._attachLoadEventListener(frameDoc, _sqh);
1177
- }
1178
- });
1179
- }
1180
1122
  // async load() {
1181
1123
  // const brandingConfig = this.context.widgetConfig?.values?.brandingConfig;
1182
- // // @ts-ignore
1183
- // const initialHeight = brandingConfig?.loadingHeight;
1184
- // const skeletonBackgroundColor =
1185
- // brandingConfig?.color?.loadingSkeleton?.background;
1186
- // const skeletonShimmerColor =
1187
- // brandingConfig?.color?.loadingSkeleton?.animationBackground;
1188
- // const borderColor = brandingConfig?.border?.borderColor;
1189
1124
  // const sizes = brandingConfig?.widgetSize?.embeddedWidgets;
1190
1125
  // const maxWidth = sizes?.maxWidth ? formatWidth(sizes.maxWidth) : "";
1191
1126
  // const minWidth = sizes?.minWidth ? formatWidth(sizes.minWidth) : "";
1192
- // console.log({
1193
- // brandingConfig,
1194
- // initialHeight,
1195
- // widgetConfig: this.context.widgetConfig,
1196
- // });
1197
- // // const skeletonHTML = getSkeleton({
1198
- // // height: initialHeight,
1199
- // // skeletonBackgroundColor,
1200
- // // skeletonShimmerColor,
1201
- // // borderColor,
1202
- // // });
1203
- // // const skeletonContainer = document.createElement("div");
1204
- // // skeletonContainer.innerHTML = skeletonHTML;
1205
- // const frame = this._createFrame({
1206
- // minWidth,
1207
- // maxWidth,
1208
- // initialHeight,
1209
- // });
1127
+ // const frame = this._createFrame({ minWidth, maxWidth });
1210
1128
  // const element = this._findElement();
1211
- // // element.innerHTML = skeletonHTML;
1212
- // // Hide frame initially
1213
- // frame.style.display = "none";
1214
- // const injectContents = (target: HTMLElement | ShadowRoot) => {
1215
- // // Optional: Clear target to prevent duplicates if load() is called twice
1216
- // // target.innerHTML = "";
1217
- // // target.appendChild(skeletonContainer);
1218
- // target.appendChild(frame);
1219
- // };
1220
1129
  // if (this.context?.container) {
1221
1130
  // // Custom container is used
1222
1131
  // element.style.visibility = "hidden";
@@ -1228,56 +1137,34 @@ class EmbedWidget extends Widget {
1228
1137
  // if (element.shadowRoot.lastChild?.nodeName === "IFRAME") {
1229
1138
  // element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
1230
1139
  // } else {
1231
- // injectContents(element.shadowRoot);
1140
+ // element.shadowRoot.appendChild(frame);
1232
1141
  // }
1233
- // } else if (element.firstChild) {
1234
- // // If replacing, wipe and reload
1235
- // element.innerHTML = "";
1236
- // injectContents(element);
1142
+ // }
1143
+ // // Widget reloaded - replace existing element
1144
+ // else if (element.firstChild) {
1145
+ // element.replaceChild(frame, element.firstChild);
1146
+ // // Add iframe for the first time
1237
1147
  // } else {
1238
- // injectContents(element);
1148
+ // element.appendChild(frame);
1239
1149
  // }
1150
+ // } else if (!element.firstChild || element.firstChild.nodeName === "#text") {
1151
+ // element.appendChild(frame);
1240
1152
  // }
1241
- // // else if (!element.firstChild || element.firstChild.nodeName === "#text") {
1242
- // // injectContents(element);
1243
- // // }
1244
1153
  // const { contentWindow } = frame;
1245
1154
  // if (!contentWindow) {
1246
1155
  // throw new Error("Frame needs a content window");
1247
1156
  // }
1248
1157
  // const frameDoc = contentWindow.document;
1249
1158
  // frameDoc.open();
1250
- // console.log({ content: this.content, context: this.context, this: this });
1251
- // const domain = this.widgetApi.domain;
1252
- // frameDoc.write(`
1253
- // ${
1254
- // brandingConfig?.main?.brandFont &&
1255
- // `
1256
- // <link rel="preconnect" href="https://fast${
1257
- // domain === "https://staging.referralsaasquatch.com" && "-staging"
1258
- // }.ssqt.io">
1259
- // <link rel="preconnect" href="https://fonts.gstatic.com">
1260
- // <link rel="preconnect" href="https://fonts.googleapis.com">
1261
- // <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent(
1262
- // brandingConfig?.main?.brandFont
1263
- // )}" as="style">`
1264
- // }
1265
- // <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
1266
- // <style data-styles>
1267
- // html { visibility:hidden;}
1268
- // </style>
1269
- // ${this.content}
1270
- // `);
1159
+ // frameDoc.write(this.content);
1160
+ // frameDoc.write(
1161
+ // `<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`
1162
+ // );
1271
1163
  // frameDoc.close();
1272
1164
  // domready(frameDoc, async () => {
1273
- // // if (skeletonContainer && skeletonContainer.parentNode) {
1274
- // // skeletonContainer.parentNode.removeChild(skeletonContainer);
1275
- // // }
1276
- // frame.style.display = "block";
1277
1165
  // const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1278
1166
  // // @ts-ignore -- number will be cast to string by browsers
1279
- // frame.height = initialHeight || frameDoc.body.scrollHeight;
1280
- // console.log({ height: frameDoc.body.scrollHeight });
1167
+ // frame.height = frameDoc.body.scrollHeight;
1281
1168
  // // Adjust frame height when size of body changes
1282
1169
  // /* istanbul ignore next: hard to test */
1283
1170
  // const ro = new contentWindow["ResizeObserver"]((entries) => {
@@ -1297,6 +1184,95 @@ class EmbedWidget extends Widget {
1297
1184
  // }
1298
1185
  // });
1299
1186
  // }
1187
+ async load() {
1188
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1189
+ const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1190
+ const initialHeight = brandingConfig == null ? void 0 : brandingConfig.loadingHeight;
1191
+ (_d = (_c = brandingConfig == null ? void 0 : brandingConfig.color) == null ? void 0 : _c.loadingSkeleton) == null ? void 0 : _d.background;
1192
+ (_f = (_e = brandingConfig == null ? void 0 : brandingConfig.color) == null ? void 0 : _e.loadingSkeleton) == null ? void 0 : _f.animationBackground;
1193
+ (_g = brandingConfig == null ? void 0 : brandingConfig.border) == null ? void 0 : _g.borderColor;
1194
+ const sizes = (_h = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _h.embeddedWidgets;
1195
+ const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "";
1196
+ const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "";
1197
+ console.log({
1198
+ brandingConfig,
1199
+ initialHeight,
1200
+ widgetConfig: this.context.widgetConfig
1201
+ });
1202
+ const frame = this._createFrame({
1203
+ minWidth,
1204
+ maxWidth,
1205
+ initialHeight
1206
+ });
1207
+ const element = this._findElement();
1208
+ frame.style.display = "none";
1209
+ const injectContents = (target) => {
1210
+ target.appendChild(frame);
1211
+ };
1212
+ if ((_i = this.context) == null ? void 0 : _i.container) {
1213
+ element.style.visibility = "hidden";
1214
+ element.style.height = "0";
1215
+ element.style["overflow-y"] = "hidden";
1216
+ }
1217
+ if (this.container) {
1218
+ if (element.shadowRoot) {
1219
+ if (((_j = element.shadowRoot.lastChild) == null ? void 0 : _j.nodeName) === "IFRAME") {
1220
+ element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
1221
+ } else {
1222
+ injectContents(element.shadowRoot);
1223
+ }
1224
+ } else if (element.firstChild) {
1225
+ element.replaceChild(frame, element.firstChild);
1226
+ } else {
1227
+ injectContents(element);
1228
+ }
1229
+ } else if (!element.firstChild || element.firstChild.nodeName === "#text") {
1230
+ injectContents(element);
1231
+ }
1232
+ const { contentWindow } = frame;
1233
+ if (!contentWindow) {
1234
+ throw new Error("Frame needs a content window");
1235
+ }
1236
+ const frameDoc = contentWindow.document;
1237
+ frameDoc.open();
1238
+ console.log({ content: this.content, context: this.context, this: this });
1239
+ const domain = this.widgetApi.domain;
1240
+ frameDoc.write(`
1241
+ ${((_k = brandingConfig == null ? void 0 : brandingConfig.main) == null ? void 0 : _k.brandFont) && `
1242
+ <link rel="preconnect" href="https://fast${domain === "https://staging.referralsaasquatch.com" && "-staging"}.ssqt.io">
1243
+ <link rel="preconnect" href="https://fonts.gstatic.com">
1244
+ <link rel="preconnect" href="https://fonts.googleapis.com">
1245
+ <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent(
1246
+ (_l = brandingConfig == null ? void 0 : brandingConfig.main) == null ? void 0 : _l.brandFont
1247
+ )}" as="style">`}
1248
+ <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
1249
+ <style data-styles>
1250
+ html { visibility:hidden;}
1251
+ </style>
1252
+ ${this.content}
1253
+
1254
+ `);
1255
+ frameDoc.close();
1256
+ domready(frameDoc, async () => {
1257
+ const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1258
+ frame.height = initialHeight || frameDoc.body.scrollHeight;
1259
+ console.log({ height: frameDoc.body.scrollHeight });
1260
+ const ro = new contentWindow["ResizeObserver"]((entries) => {
1261
+ for (const entry of entries) {
1262
+ const { height } = entry.contentRect;
1263
+ frame.height = height;
1264
+ }
1265
+ });
1266
+ const container = await this._findInnerContainer(frame);
1267
+ ro.observe(container);
1268
+ if (this._shouldFireLoadEvent()) {
1269
+ this._loadEvent(_sqh);
1270
+ _log$7("loaded");
1271
+ } else if (frameDoc) {
1272
+ this._attachLoadEventListener(frameDoc, _sqh);
1273
+ }
1274
+ });
1275
+ }
1300
1276
  /**
1301
1277
  * Un-hide if element is available and refresh data
1302
1278
  */