@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.js CHANGED
@@ -7167,32 +7167,76 @@ var Button = function Button(_ref) {
7167
7167
  "aria-label": label
7168
7168
  };
7169
7169
  useEffect(function () {
7170
- if (!popupCode && !document && disableButtonAndLinks) return;
7170
+ if (!popupCode) return;
7171
+ var isActive = true;
7172
+ var appendedNodes = [];
7171
7173
  try {
7172
7174
  var tempDiv = document.createElement("div");
7173
7175
  tempDiv.innerHTML = popupCode;
7174
7176
  var nodes = Array.from(tempDiv.childNodes);
7175
- if (isEmpty(nodes)) return;
7176
- nodes.forEach(function () {
7177
- var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7178
- if (node.tagName === "SCRIPT") {
7179
- var script = document.createElement("script");
7180
- if (node.src) {
7181
- script.src = node.src;
7182
- script.async = node.async || false;
7177
+ if (!isEmpty(nodes)) {
7178
+ var externalScriptNodes = [];
7179
+ var inlineScriptNodes = [];
7180
+ nodes.forEach(function () {
7181
+ var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7182
+ if (node.tagName === "SCRIPT") {
7183
+ if (node.src) {
7184
+ externalScriptNodes.push(node);
7185
+ } else {
7186
+ inlineScriptNodes.push(node);
7187
+ }
7183
7188
  } else {
7184
- script.textContent = node.textContent;
7189
+ document.body.appendChild(node);
7190
+ appendedNodes.push(node);
7185
7191
  }
7186
- document.body.appendChild(script);
7192
+ });
7193
+ var appendInlineScripts = function appendInlineScripts() {
7194
+ if (!isActive) return;
7195
+ inlineScriptNodes.forEach(function (node) {
7196
+ try {
7197
+ var script = document.createElement("script");
7198
+ // Wrap content in try/catch so runtime errors are suppressed even
7199
+ // when the browser executes the script asynchronously (e.g. Safari).
7200
+ script.textContent = "try{".concat(node.textContent, "}catch(e){}");
7201
+ document.body.appendChild(script);
7202
+ appendedNodes.push(script);
7203
+ } catch (_unused) {
7204
+ // NOTE: Errors from inline embed scripts are ignored since these
7205
+ // cannot be handled by NeetoSite.
7206
+ }
7207
+ });
7208
+ };
7209
+ if (externalScriptNodes.length === 0) {
7210
+ appendInlineScripts();
7187
7211
  } else {
7188
- document.body.appendChild(node);
7212
+ var settledCount = 0;
7213
+ externalScriptNodes.forEach(function (node) {
7214
+ var script = document.createElement("script");
7215
+ script.src = node.src;
7216
+ script.async = node.async || false;
7217
+ appendedNodes.push(script);
7218
+ var onSettled = function onSettled() {
7219
+ settledCount++;
7220
+ if (settledCount === externalScriptNodes.length) appendInlineScripts();
7221
+ };
7222
+ script.onload = onSettled;
7223
+ script.onerror = onSettled;
7224
+ document.body.appendChild(script);
7225
+ });
7189
7226
  }
7190
- });
7191
- } catch (_unused) {
7227
+ }
7228
+ } catch (_unused2) {
7192
7229
  // NOTE: An error can occur while the user is typing out the embed code.
7193
7230
  // It could also throw an error if the embed code is invalid. These errors
7194
7231
  // are ignored since these cannot be handled by NeetoSite.
7195
7232
  }
7233
+ return function () {
7234
+ isActive = false;
7235
+ appendedNodes.forEach(function (node) {
7236
+ var _node$parentNode;
7237
+ return (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.removeChild(node);
7238
+ });
7239
+ };
7196
7240
  }, [popupCode]);
7197
7241
  if (action === "external") {
7198
7242
  return /*#__PURE__*/jsx(StyledAnchor, _objectSpread$B(_objectSpread$B({}, commonProps), {}, {