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

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