@bigbinary/neeto-site-blocks 2.0.12 → 2.2.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.
package/dist/index.cjs.js CHANGED
@@ -7186,32 +7186,76 @@ var Button = function Button(_ref) {
7186
7186
  "aria-label": label
7187
7187
  };
7188
7188
  React.useEffect(function () {
7189
- if (!popupCode && !document && disableButtonAndLinks) return;
7189
+ if (!popupCode) return;
7190
+ var isActive = true;
7191
+ var appendedNodes = [];
7190
7192
  try {
7191
7193
  var tempDiv = document.createElement("div");
7192
7194
  tempDiv.innerHTML = popupCode;
7193
7195
  var nodes = Array.from(tempDiv.childNodes);
7194
- if (ramda.isEmpty(nodes)) return;
7195
- nodes.forEach(function () {
7196
- var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7197
- if (node.tagName === "SCRIPT") {
7198
- var script = document.createElement("script");
7199
- if (node.src) {
7200
- script.src = node.src;
7201
- script.async = node.async || false;
7196
+ if (!ramda.isEmpty(nodes)) {
7197
+ var externalScriptNodes = [];
7198
+ var inlineScriptNodes = [];
7199
+ nodes.forEach(function () {
7200
+ var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7201
+ if (node.tagName === "SCRIPT") {
7202
+ if (node.src) {
7203
+ externalScriptNodes.push(node);
7204
+ } else {
7205
+ inlineScriptNodes.push(node);
7206
+ }
7202
7207
  } else {
7203
- script.textContent = node.textContent;
7208
+ document.body.appendChild(node);
7209
+ appendedNodes.push(node);
7204
7210
  }
7205
- document.body.appendChild(script);
7211
+ });
7212
+ var appendInlineScripts = function appendInlineScripts() {
7213
+ if (!isActive) return;
7214
+ inlineScriptNodes.forEach(function (node) {
7215
+ try {
7216
+ var script = document.createElement("script");
7217
+ // Wrap content in try/catch so runtime errors are suppressed even
7218
+ // when the browser executes the script asynchronously (e.g. Safari).
7219
+ script.textContent = "try{".concat(node.textContent, "}catch(e){}");
7220
+ document.body.appendChild(script);
7221
+ appendedNodes.push(script);
7222
+ } catch (_unused) {
7223
+ // NOTE: Errors from inline embed scripts are ignored since these
7224
+ // cannot be handled by NeetoSite.
7225
+ }
7226
+ });
7227
+ };
7228
+ if (externalScriptNodes.length === 0) {
7229
+ appendInlineScripts();
7206
7230
  } else {
7207
- document.body.appendChild(node);
7231
+ var settledCount = 0;
7232
+ externalScriptNodes.forEach(function (node) {
7233
+ var script = document.createElement("script");
7234
+ script.src = node.src;
7235
+ script.async = node.async || false;
7236
+ appendedNodes.push(script);
7237
+ var onSettled = function onSettled() {
7238
+ settledCount++;
7239
+ if (settledCount === externalScriptNodes.length) appendInlineScripts();
7240
+ };
7241
+ script.onload = onSettled;
7242
+ script.onerror = onSettled;
7243
+ document.body.appendChild(script);
7244
+ });
7208
7245
  }
7209
- });
7210
- } catch (_unused) {
7246
+ }
7247
+ } catch (_unused2) {
7211
7248
  // NOTE: An error can occur while the user is typing out the embed code.
7212
7249
  // It could also throw an error if the embed code is invalid. These errors
7213
7250
  // are ignored since these cannot be handled by NeetoSite.
7214
7251
  }
7252
+ return function () {
7253
+ isActive = false;
7254
+ appendedNodes.forEach(function (node) {
7255
+ var _node$parentNode;
7256
+ return (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.removeChild(node);
7257
+ });
7258
+ };
7215
7259
  }, [popupCode]);
7216
7260
  if (action === "external") {
7217
7261
  return /*#__PURE__*/jsxRuntime.jsx(StyledAnchor, _objectSpread$B(_objectSpread$B({}, commonProps), {}, {