react-iframe-wrapper
Version:
A React component that can wrap your components into an iframe
29 lines (25 loc) • 15.6 kB
JavaScript
(function(_,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],v):(_=typeof globalThis<"u"?globalThis:_||self,v(_.pfelements={},_.React,_.ReactDOM))})(this,function(_,v,fe){"use strict";var j={},Ye={get exports(){return j},set exports(p){j=p}},M={};/**
* @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 le;function $e(){if(le)return M;le=1;var p=v,g=Symbol.for("react.element"),O=Symbol.for("react.fragment"),y=Object.prototype.hasOwnProperty,A=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,k={key:!0,ref:!0,__self:!0,__source:!0};function D(R,d,S){var m,b={},T=null,I=null;S!==void 0&&(T=""+S),d.key!==void 0&&(T=""+d.key),d.ref!==void 0&&(I=d.ref);for(m in d)y.call(d,m)&&!k.hasOwnProperty(m)&&(b[m]=d[m]);if(R&&R.defaultProps)for(m in d=R.defaultProps,d)b[m]===void 0&&(b[m]=d[m]);return{$$typeof:g,type:R,key:T,ref:I,props:b,_owner:A.current}}return M.Fragment=O,M.jsx=D,M.jsxs=D,M}var U={};/**
* @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 ce;function Me(){return ce||(ce=1,process.env.NODE_ENV!=="production"&&function(){var p=v,g=Symbol.for("react.element"),O=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),k=Symbol.for("react.profiler"),D=Symbol.for("react.provider"),R=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),T=Symbol.for("react.lazy"),I=Symbol.for("react.offscreen"),P=Symbol.iterator,N="@@iterator";function X(e){if(e===null||typeof e!="object")return null;var r=P&&e[P]||e[N];return typeof r=="function"?r:null}var x=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function c(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Z("error",e,t)}}function Z(e,r,t){{var n=x.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 Q=!1,ee=!1,f=!1,L=!1,W=!1,B;B=Symbol.for("react.module.reference");function Be(e){return!!(typeof e=="string"||typeof e=="function"||e===y||e===k||W||e===A||e===S||e===m||L||e===I||Q||ee||f||typeof e=="object"&&e!==null&&(e.$$typeof===T||e.$$typeof===b||e.$$typeof===D||e.$$typeof===R||e.$$typeof===d||e.$$typeof===B||e.getModuleId!==void 0))}function Je(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function me(e){return e.displayName||"Context"}function w(e){if(e==null)return null;if(typeof e.tag=="number"&&c("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 y:return"Fragment";case O:return"Portal";case k:return"Profiler";case A:return"StrictMode";case S:return"Suspense";case m:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case R:var r=e;return me(r)+".Consumer";case D:var t=e;return me(t._context)+".Provider";case d:return Je(e,e.render,"ForwardRef");case b:var n=e.displayName||null;return n!==null?n:w(e.type)||"Memo";case T:{var i=e,u=i._payload,o=i._init;try{return w(o(u))}catch{return null}}}return null}var F=Object.assign,V=0,he,ge,ye,Ee,be,_e,Re;function Te(){}Te.__reactDisabledLog=!0;function Ge(){{if(V===0){he=console.log,ge=console.info,ye=console.warn,Ee=console.error,be=console.group,_e=console.groupCollapsed,Re=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Te,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}V++}}function ze(){{if(V--,V===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:he}),info:F({},e,{value:ge}),warn:F({},e,{value:ye}),error:F({},e,{value:Ee}),group:F({},e,{value:be}),groupCollapsed:F({},e,{value:_e}),groupEnd:F({},e,{value:Re})})}V<0&&c("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var re=x.ReactCurrentDispatcher,te;function J(e,r,t){{if(te===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);te=n&&n[1]||""}return`
`+te+e}}var ne=!1,G;{var Ke=typeof WeakMap=="function"?WeakMap:Map;G=new Ke}function we(e,r){if(!e||ne)return"";{var t=G.get(e);if(t!==void 0)return t}var n;ne=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=re.current,re.current=null,Ge();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(C){n=C}Reflect.construct(e,[],o)}else{try{o.call()}catch(C){n=C}e.call(o.prototype)}}else{try{throw Error()}catch(C){n=C}e()}}catch(C){if(C&&n&&typeof C.stack=="string"){for(var a=C.stack.split(`
`),h=n.stack.split(`
`),s=a.length-1,l=h.length-1;s>=1&&l>=0&&a[s]!==h[l];)l--;for(;s>=1&&l>=0;s--,l--)if(a[s]!==h[l]){if(s!==1||l!==1)do if(s--,l--,l<0||a[s]!==h[l]){var E=`
`+a[s].replace(" at new "," at ");return e.displayName&&E.includes("<anonymous>")&&(E=E.replace("<anonymous>",e.displayName)),typeof e=="function"&&G.set(e,E),E}while(s>=1&&l>=0);break}}}finally{ne=!1,re.current=u,ze(),Error.prepareStackTrace=i}var $=e?e.displayName||e.name:"",We=$?J($):"";return typeof e=="function"&&G.set(e,We),We}function He(e,r,t){return we(e,!1)}function Xe(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function z(e,r,t){if(e==null)return"";if(typeof e=="function")return we(e,Xe(e));if(typeof e=="string")return J(e);switch(e){case S:return J("Suspense");case m:return J("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return He(e.render);case b:return z(e.type,r,t);case T:{var n=e,i=n._payload,u=n._init;try{return z(u(i),r,t)}catch{}}}return""}var K=Object.prototype.hasOwnProperty,Ce={},Oe=x.ReactDebugCurrentFrame;function H(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);Oe.setExtraStackFrame(t)}else Oe.setExtraStackFrame(null)}function Ze(e,r,t,n,i){{var u=Function.call.bind(K);for(var o in e)if(u(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var h=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 h.name="Invariant Violation",h}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)&&(H(i),c("%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),H(null)),a instanceof Error&&!(a.message in Ce)&&(Ce[a.message]=!0,H(i),c("Failed %s type: %s",t,a.message),H(null))}}}var Qe=Array.isArray;function ae(e){return Qe(e)}function er(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function rr(e){try{return Se(e),!1}catch{return!0}}function Se(e){return""+e}function Pe(e){if(rr(e))return c("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",er(e)),Se(e)}var q=x.ReactCurrentOwner,tr={key:!0,ref:!0,__self:!0,__source:!0},xe,je,oe;oe={};function nr(e){if(K.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function ar(e){if(K.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function or(e,r){if(typeof e.ref=="string"&&q.current&&r&&q.current.stateNode!==r){var t=w(q.current.type);oe[t]||(c('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',w(q.current.type),e.ref),oe[t]=!0)}}function ir(e,r){{var t=function(){xe||(xe=!0,c("%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 ur(e,r){{var t=function(){je||(je=!0,c("%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 sr=function(e,r,t,n,i,u,o){var a={$$typeof:g,type:e,key:r,ref:t,props:o,_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 fr(e,r,t,n,i){{var u,o={},a=null,h=null;t!==void 0&&(Pe(t),a=""+t),ar(r)&&(Pe(r.key),a=""+r.key),nr(r)&&(h=r.ref,or(r,i));for(u in r)K.call(r,u)&&!tr.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||h){var l=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&ir(o,l),h&&ur(o,l)}return sr(e,a,h,i,n,q.current,o)}}var ie=x.ReactCurrentOwner,ke=x.ReactDebugCurrentFrame;function Y(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);ke.setExtraStackFrame(t)}else ke.setExtraStackFrame(null)}var ue;ue=!1;function se(e){return typeof e=="object"&&e!==null&&e.$$typeof===g}function De(){{if(ie.current){var e=w(ie.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function lr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
Check your code at `+r+":"+t+"."}return""}}var Fe={};function cr(e){{var r=De();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 Ae(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=cr(r);if(Fe[t])return;Fe[t]=!0;var n="";e&&e._owner&&e._owner!==ie.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),Y(e),c('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),Y(null)}}function Ie(e,r){{if(typeof e!="object")return;if(ae(e))for(var t=0;t<e.length;t++){var n=e[t];se(n)&&Ae(n,r)}else if(se(e))e._store&&(e._store.validated=!0);else if(e){var i=X(e);if(typeof i=="function"&&i!==e.entries)for(var u=i.call(e),o;!(o=u.next()).done;)se(o.value)&&Ae(o.value,r)}}}function dr(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||r.$$typeof===b))t=r.propTypes;else return;if(t){var n=w(r);Ze(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ue){ue=!0;var i=w(r);c("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&c("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function vr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){Y(e),c("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),Y(null);break}}e.ref!==null&&(Y(e),c("Invalid attribute `ref` supplied to `React.Fragment`."),Y(null))}}function Le(e,r,t,n,i,u){{var o=Be(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 h=lr(i);h?a+=h:a+=De();var s;e===null?s="null":ae(e)?s="array":e!==void 0&&e.$$typeof===g?(s="<"+(w(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,c("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 l=fr(e,r,t,i,u);if(l==null)return l;if(o){var E=r.children;if(E!==void 0)if(n)if(ae(E)){for(var $=0;$<E.length;$++)Ie(E[$],e);Object.freeze&&Object.freeze(E)}else c("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 Ie(E,e)}return e===y?vr(l):dr(l),l}}function pr(e,r,t){return Le(e,r,t,!0)}function mr(e,r,t){return Le(e,r,t,!1)}var hr=mr,gr=pr;U.Fragment=y,U.jsx=hr,U.jsxs=gr}()),U}(function(p){process.env.NODE_ENV==="production"?p.exports=$e():p.exports=Me()})(Ye);const Ue=(p,g)=>{const O=new Set(g);return Object.fromEntries(Object.entries(p).filter(([y])=>!O.has(y)))};let de,ve;typeof document<"u"&&(de=document),typeof window<"u"&&(ve=window);const pe=v.createContext({document:de,window:ve}),Ne=()=>v.useContext(pe),Ve=p=>{const{children:g,onMount:O,onUpdate:y}=p;return v.useEffect(()=>{O()},[]),v.useEffect(()=>{y()}),j.jsx(j.Fragment,{children:g})},qe=v.forwardRef((p,g)=>{const{style:O={},head:y=null,children:A=void 0,mountTarget:k=void 0,onMount:D=()=>{},onUpdate:R=()=>{},initialContent:d="<!DOCTYPE html><html><head></head><body></body></html>"}=p,S=v.useReducer(()=>({}),{})[1],[m,b]=v.useState(!1),[T,I]=v.useState(!1),P=v.useRef(null);v.useEffect(()=>{var L;b(!0);const f=N();return f&&f.readyState==="complete"?S():(L=P.current)==null||L.addEventListener("load",c),()=>{var W;(W=P.current)==null||W.removeEventListener("load",c)}},[]);const N=()=>P.current?P.current.contentDocument:null,X=()=>{const f=N();return k?f==null?void 0:f.querySelector(k):f==null?void 0:f.body},x=f=>{P.current=f,typeof g=="function"?g(f):g&&(g.current=f)},c=()=>{I(!0)};function Z(){if(!m)return null;const f=N();if(!f)return null;const L=f.defaultView||void 0,W=j.jsx(Ve,{onMount:D,onUpdate:R,children:j.jsx(pe.Provider,{value:{document:f,window:L},children:A})}),B=X();return[fe.createPortal(y,f.head),fe.createPortal(W,B)]}const Q={...p,srcDoc:d,children:void 0},ee=Ue(Q,["head","initialContent","mountTarget","onMount","onUpdate"]);return j.jsx("iframe",{sandbox:"allow-same-origin allow-scripts allow-top-navigation",ref:x,...ee,onLoad:c,children:T&&Z()})});_.Iframe=qe,_.useFrame=Ne,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=elements.umd.js.map