@noaignite/react-centra-checkout
Version:
React components and helpers for Centra checkout api
64 lines (63 loc) • 2.24 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/internal/HtmlEmbed.tsx
var HtmlEmbed_exports = {};
__export(HtmlEmbed_exports, {
HtmlEmbed: () => HtmlEmbed
});
module.exports = __toCommonJS(HtmlEmbed_exports);
var import_react = require("react");
var import_jsx_runtime = require("react/jsx-runtime");
function HtmlEmbed(props) {
const { html, ...other } = props;
const ref = (0, import_react.useRef)(null);
(0, import_react.useEffect)(() => {
const createdScripts = [];
const node = ref.current;
if (node && html) {
const scripts = node.getElementsByTagName("script");
Array.from(scripts).forEach((script) => {
if (script.type === "application/json") {
return;
}
const scriptEl = document.createElement("script");
if (script.src) {
scriptEl.src = script.src;
} else {
const textNode = document.createTextNode(script.innerHTML);
scriptEl.appendChild(textNode);
}
script.remove();
createdScripts.push(scriptEl);
node.appendChild(scriptEl);
});
}
return () => {
createdScripts.forEach((script) => {
script.remove();
});
};
}, [html]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { dangerouslySetInnerHTML: { __html: html }, ref, ...other });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
HtmlEmbed
});
//# sourceMappingURL=HtmlEmbed.cjs.map