UNPKG

react-iframe-wrapper

Version:

A React component that can wrap your components into an iframe

711 lines (707 loc) 23.5 kB
import V, { forwardRef as dr, useState as De, useRef as vr, useEffect as se } from "react"; import Fe from "react-dom"; var k = {}, pr = { get exports() { return k; }, set exports(v) { k = v; } }, U = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ae; function mr() { if (Ae) return U; Ae = 1; var v = V, h = Symbol.for("react.element"), w = Symbol.for("react.fragment"), g = Object.prototype.hasOwnProperty, D = v.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, S = { key: !0, ref: !0, __self: !0, __source: !0 }; function x(E, d, C) { var p, b = {}, R = null, F = null; C !== void 0 && (R = "" + C), d.key !== void 0 && (R = "" + d.key), d.ref !== void 0 && (F = d.ref); for (p in d) g.call(d, p) && !S.hasOwnProperty(p) && (b[p] = d[p]); if (E && E.defaultProps) for (p in d = E.defaultProps, d) b[p] === void 0 && (b[p] = d[p]); return { $$typeof: h, type: E, key: R, ref: F, props: b, _owner: D.current }; } return U.Fragment = w, U.jsx = x, U.jsxs = x, U; } var N = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ie; function hr() { return Ie || (Ie = 1, process.env.NODE_ENV !== "production" && function() { var v = V, h = Symbol.for("react.element"), w = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), D = Symbol.for("react.strict_mode"), S = Symbol.for("react.profiler"), x = Symbol.for("react.provider"), E = Symbol.for("react.context"), d = Symbol.for("react.forward_ref"), C = Symbol.for("react.suspense"), p = Symbol.for("react.suspense_list"), b = Symbol.for("react.memo"), R = Symbol.for("react.lazy"), F = Symbol.for("react.offscreen"), O = Symbol.iterator, Y = "@@iterator"; function H(e) { if (e === null || typeof e != "object") return null; var r = O && e[O] || e[Y]; return typeof r == "function" ? r : null; } var P = v.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function f(e) { { for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++) t[n - 1] = arguments[n]; X("error", e, t); } } function X(e, r, t) { { var n = P.ReactDebugCurrentFrame, i = n.getStackAddendum(); i !== "" && (r += "%s", t = t.concat([i])); var u = t.map(function(o) { return String(o); }); u.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, u); } } var Z = !1, Q = !1, l = !1, A = !1, I = !1, B; B = Symbol.for("react.module.reference"); function $e(e) { return !!(typeof e == "string" || typeof e == "function" || e === g || e === S || I || e === D || e === C || e === p || A || e === F || Z || Q || l || typeof e == "object" && e !== null && (e.$$typeof === R || e.$$typeof === b || e.$$typeof === x || e.$$typeof === E || e.$$typeof === d || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === B || e.getModuleId !== void 0)); } function Me(e, r, t) { var n = e.displayName; if (n) return n; var i = r.displayName || r.name || ""; return i !== "" ? t + "(" + i + ")" : t; } function le(e) { return e.displayName || "Context"; } function _(e) { if (e == null) return null; if (typeof e.tag == "number" && f("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case g: return "Fragment"; case w: return "Portal"; case S: return "Profiler"; case D: return "StrictMode"; case C: return "Suspense"; case p: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case E: var r = e; return le(r) + ".Consumer"; case x: var t = e; return le(t._context) + ".Provider"; case d: return Me(e, e.render, "ForwardRef"); case b: var n = e.displayName || null; return n !== null ? n : _(e.type) || "Memo"; case R: { var i = e, u = i._payload, o = i._init; try { return _(o(u)); } catch { return null; } } } return null; } var j = Object.assign, $ = 0, ce, fe, de, ve, pe, me, he; function ge() { } ge.__reactDisabledLog = !0; function Ue() { { if ($ === 0) { ce = console.log, fe = console.info, de = console.warn, ve = console.error, pe = console.group, me = console.groupCollapsed, he = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: ge, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } $++; } } function Ne() { { if ($--, $ === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: j({}, e, { value: ce }), info: j({}, e, { value: fe }), warn: j({}, e, { value: de }), error: j({}, e, { value: ve }), group: j({}, e, { value: pe }), groupCollapsed: j({}, e, { value: me }), groupEnd: j({}, e, { value: he }) }); } $ < 0 && f("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var ee = P.ReactCurrentDispatcher, re; function q(e, r, t) { { if (re === void 0) try { throw Error(); } catch (i) { var n = i.stack.trim().match(/\n( *(at )?)/); re = n && n[1] || ""; } return ` ` + re + e; } } var te = !1, J; { var Ve = typeof WeakMap == "function" ? WeakMap : Map; J = new Ve(); } function ye(e, r) { if (!e || te) return ""; { var t = J.get(e); if (t !== void 0) return t; } var n; te = !0; var i = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var u; u = ee.current, ee.current = null, Ue(); try { if (r) { var o = function() { throw Error(); }; if (Object.defineProperty(o.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(o, []); } catch (T) { n = T; } Reflect.construct(e, [], o); } else { try { o.call(); } catch (T) { n = T; } e.call(o.prototype); } } else { try { throw Error(); } catch (T) { n = T; } e(); } } catch (T) { if (T && n && typeof T.stack == "string") { for (var a = T.stack.split(` `), m = n.stack.split(` `), s = a.length - 1, c = m.length - 1; s >= 1 && c >= 0 && a[s] !== m[c]; ) c--; for (; s >= 1 && c >= 0; s--, c--) if (a[s] !== m[c]) { if (s !== 1 || c !== 1) do if (s--, c--, c < 0 || a[s] !== m[c]) { var y = ` ` + a[s].replace(" at new ", " at "); return e.displayName && y.includes("<anonymous>") && (y = y.replace("<anonymous>", e.displayName)), typeof e == "function" && J.set(e, y), y; } while (s >= 1 && c >= 0); break; } } } finally { te = !1, ee.current = u, Ne(), Error.prepareStackTrace = i; } var W = e ? e.displayName || e.name : "", ke = W ? q(W) : ""; return typeof e == "function" && J.set(e, ke), ke; } function Be(e, r, t) { return ye(e, !1); } function qe(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function G(e, r, t) { if (e == null) return ""; if (typeof e == "function") return ye(e, qe(e)); if (typeof e == "string") return q(e); switch (e) { case C: return q("Suspense"); case p: return q("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case d: return Be(e.render); case b: return G(e.type, r, t); case R: { var n = e, i = n._payload, u = n._init; try { return G(u(i), r, t); } catch { } } } return ""; } var z = Object.prototype.hasOwnProperty, be = {}, Ee = P.ReactDebugCurrentFrame; function K(e) { if (e) { var r = e._owner, t = G(e.type, e._source, r ? r.type : null); Ee.setExtraStackFrame(t); } else Ee.setExtraStackFrame(null); } function Je(e, r, t, n, i) { { var u = Function.call.bind(z); for (var o in e) if (u(e, o)) { var a = void 0; try { if (typeof e[o] != "function") { var m = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw m.name = "Invariant Violation", m; } a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (s) { a = s; } a && !(a instanceof Error) && (K(i), f("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, o, typeof a), K(null)), a instanceof Error && !(a.message in be) && (be[a.message] = !0, K(i), f("Failed %s type: %s", t, a.message), K(null)); } } } var Ge = Array.isArray; function ne(e) { return Ge(e); } function ze(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function Ke(e) { try { return Re(e), !1; } catch { return !0; } } function Re(e) { return "" + e; } function _e(e) { if (Ke(e)) return f("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ze(e)), Re(e); } var M = P.ReactCurrentOwner, He = { key: !0, ref: !0, __self: !0, __source: !0 }, Te, we, ae; ae = {}; function Xe(e) { if (z.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function Ze(e) { if (z.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function Qe(e, r) { if (typeof e.ref == "string" && M.current && r && M.current.stateNode !== r) { var t = _(M.current.type); ae[t] || (f('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', _(M.current.type), e.ref), ae[t] = !0); } } function er(e, r) { { var t = function() { Te || (Te = !0, f("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "key", { get: t, configurable: !0 }); } } function rr(e, r) { { var t = function() { we || (we = !0, f("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "ref", { get: t, configurable: !0 }); } } var tr = function(e, r, t, n, i, u, o) { var a = { // This tag allows us to uniquely identify this as a React Element $$typeof: h, // Built-in properties that belong on the element type: e, key: r, ref: t, props: o, // Record the component responsible for creating this element. _owner: u }; return a._store = {}, Object.defineProperty(a._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(a, "_self", { configurable: !1, enumerable: !1, writable: !1, value: n }), Object.defineProperty(a, "_source", { configurable: !1, enumerable: !1, writable: !1, value: i }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a; }; function nr(e, r, t, n, i) { { var u, o = {}, a = null, m = null; t !== void 0 && (_e(t), a = "" + t), Ze(r) && (_e(r.key), a = "" + r.key), Xe(r) && (m = r.ref, Qe(r, i)); for (u in r) z.call(r, u) && !He.hasOwnProperty(u) && (o[u] = r[u]); if (e && e.defaultProps) { var s = e.defaultProps; for (u in s) o[u] === void 0 && (o[u] = s[u]); } if (a || m) { var c = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; a && er(o, c), m && rr(o, c); } return tr(e, a, m, i, n, M.current, o); } } var oe = P.ReactCurrentOwner, Ce = P.ReactDebugCurrentFrame; function L(e) { if (e) { var r = e._owner, t = G(e.type, e._source, r ? r.type : null); Ce.setExtraStackFrame(t); } else Ce.setExtraStackFrame(null); } var ie; ie = !1; function ue(e) { return typeof e == "object" && e !== null && e.$$typeof === h; } function Oe() { { if (oe.current) { var e = _(oe.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function ar(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber; return ` Check your code at ` + r + ":" + t + "."; } return ""; } } var Pe = {}; function or(e) { { var r = Oe(); if (!r) { var t = typeof e == "string" ? e : e.displayName || e.name; t && (r = ` Check the top-level render call using <` + t + ">."); } return r; } } function Se(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = or(r); if (Pe[t]) return; Pe[t] = !0; var n = ""; e && e._owner && e._owner !== oe.current && (n = " It was passed a child from " + _(e._owner.type) + "."), L(e), f('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), L(null); } } function xe(e, r) { { if (typeof e != "object") return; if (ne(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; ue(n) && Se(n, r); } else if (ue(e)) e._store && (e._store.validated = !0); else if (e) { var i = H(e); if (typeof i == "function" && i !== e.entries) for (var u = i.call(e), o; !(o = u.next()).done; ) ue(o.value) && Se(o.value, r); } } } function ir(e) { { var r = e.type; if (r == null || typeof r == "string") return; var t; if (typeof r == "function") t = r.propTypes; else if (typeof r == "object" && (r.$$typeof === d || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === b)) t = r.propTypes; else return; if (t) { var n = _(r); Je(t, e.props, "prop", n, e); } else if (r.PropTypes !== void 0 && !ie) { ie = !0; var i = _(r); f("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && f("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function ur(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var n = r[t]; if (n !== "children" && n !== "key") { L(e), f("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), L(null); break; } } e.ref !== null && (L(e), f("Invalid attribute `ref` supplied to `React.Fragment`."), L(null)); } } function je(e, r, t, n, i, u) { { var o = $e(e); if (!o) { var a = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var m = ar(i); m ? a += m : a += Oe(); var s; e === null ? s = "null" : ne(e) ? s = "array" : e !== void 0 && e.$$typeof === h ? (s = "<" + (_(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : s = typeof e, f("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", s, a); } var c = nr(e, r, t, i, u); if (c == null) return c; if (o) { var y = r.children; if (y !== void 0) if (n) if (ne(y)) { for (var W = 0; W < y.length; W++) xe(y[W], e); Object.freeze && Object.freeze(y); } else f("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else xe(y, e); } return e === g ? ur(c) : ir(c), c; } } function sr(e, r, t) { return je(e, r, t, !0); } function lr(e, r, t) { return je(e, r, t, !1); } var cr = lr, fr = sr; N.Fragment = g, N.jsx = cr, N.jsxs = fr; }()), N; } (function(v) { process.env.NODE_ENV === "production" ? v.exports = mr() : v.exports = hr(); })(pr); const gr = (v, h) => { const w = new Set(h); return Object.fromEntries(Object.entries(v).filter(([g]) => !w.has(g))); }; let Le, We; typeof document < "u" && (Le = document); typeof window < "u" && (We = window); const Ye = V.createContext({ document: Le, window: We }), Rr = () => V.useContext(Ye), yr = (v) => { const { children: h, onMount: w, onUpdate: g } = v; return se(() => { w(); }, []), se(() => { g(); }), /* @__PURE__ */ k.jsx(k.Fragment, { children: h }); }, _r = dr((v, h) => { const { style: w = {}, head: g = null, children: D = void 0, mountTarget: S = void 0, onMount: x = () => { }, onUpdate: E = () => { }, initialContent: d = "<!DOCTYPE html><html><head></head><body></body></html>" } = v, C = V.useReducer(() => ({}), {})[1], [p, b] = De(!1), [R, F] = De(!1), O = vr(null); se(() => { var A; b(!0); const l = Y(); return l && l.readyState === "complete" ? C() : (A = O.current) == null || A.addEventListener("load", f), () => { var I; (I = O.current) == null || I.removeEventListener("load", f); }; }, []); const Y = () => O.current ? O.current.contentDocument : null, H = () => { const l = Y(); return S ? l == null ? void 0 : l.querySelector(S) : l == null ? void 0 : l.body; }, P = (l) => { O.current = l, typeof h == "function" ? h(l) : h && (h.current = l); }, f = () => { F(!0); }; function X() { if (!p) return null; const l = Y(); if (!l) return null; const A = l.defaultView || void 0, I = /* @__PURE__ */ k.jsx(yr, { onMount: x, onUpdate: E, children: /* @__PURE__ */ k.jsx(Ye.Provider, { value: { document: l, window: A }, children: D }) }), B = H(); return [Fe.createPortal(g, l.head), Fe.createPortal(I, B)]; } const Z = { ...v, srcDoc: d, children: void 0 }, Q = gr(Z, ["head", "initialContent", "mountTarget", "onMount", "onUpdate"]); return /* @__PURE__ */ k.jsx( "iframe", { sandbox: "allow-same-origin allow-scripts allow-top-navigation", ref: P, ...Q, onLoad: f, children: R && X() } ); }); export { _r as Iframe, Rr as useFrame }; //# sourceMappingURL=elements.es.js.map