react-new-window
Advanced tools
Comparing version 0.2.2 to 0.2.3-beta.0
@@ -1,17 +0,2 @@ | ||
import e from"react";import t from"react-dom";function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function o(e,t){return o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},o(e,t)}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}var s={exports:{}},u={}; | ||
/** @license React v16.8.6 | ||
* react-is.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. | ||
*/ | ||
Object.defineProperty(u,"__esModule",{value:!0});var a="function"==typeof Symbol&&Symbol.for,l=a?Symbol.for("react.element"):60103,f=a?Symbol.for("react.portal"):60106,d=a?Symbol.for("react.fragment"):60107,p=a?Symbol.for("react.strict_mode"):60108,y=a?Symbol.for("react.profiler"):60114,h=a?Symbol.for("react.provider"):60109,w=a?Symbol.for("react.context"):60110,m=a?Symbol.for("react.async_mode"):60111,b=a?Symbol.for("react.concurrent_mode"):60111,v=a?Symbol.for("react.forward_ref"):60112,O=a?Symbol.for("react.suspense"):60113,S=a?Symbol.for("react.memo"):60115,g=a?Symbol.for("react.lazy"):60116;function j(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case l:switch(e=e.type){case m:case b:case d:case y:case p:case O:return e;default:switch(e=e&&e.$$typeof){case w:case v:case h:return e;default:return t}}case g:case S:case f:return t}}}function E(e){return j(e)===b}u.typeOf=j,u.AsyncMode=m,u.ConcurrentMode=b,u.ContextConsumer=w,u.ContextProvider=h,u.Element=l,u.ForwardRef=v,u.Fragment=d,u.Lazy=g,u.Memo=S,u.Portal=f,u.Profiler=y,u.StrictMode=p,u.Suspense=O,u.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===d||e===b||e===y||e===p||e===O||"object"==typeof e&&null!==e&&(e.$$typeof===g||e.$$typeof===S||e.$$typeof===h||e.$$typeof===w||e.$$typeof===v)},u.isAsyncMode=function(e){return E(e)||j(e)===m},u.isConcurrentMode=E,u.isContextConsumer=function(e){return j(e)===w},u.isContextProvider=function(e){return j(e)===h},u.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===l},u.isForwardRef=function(e){return j(e)===v},u.isFragment=function(e){return j(e)===d},u.isLazy=function(e){return j(e)===g},u.isMemo=function(e){return j(e)===S},u.isPortal=function(e){return j(e)===f},u.isProfiler=function(e){return j(e)===y},u.isStrictMode=function(e){return j(e)===p},u.isSuspense=function(e){return j(e)===O}; | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
Object.getOwnPropertySymbols,Object.prototype.hasOwnProperty,Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;var o=Object.getOwnPropertyNames(t).map((function(e){return t[e]}));if("0123456789"!==o.join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()||Object.assign;Function.call.bind(Object.prototype.hasOwnProperty);function C(){}function P(){}P.resetWarningCache=C;s.exports=function(){function e(e,t,n,o,r,i){if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==i){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:P,resetWarningCache:C};return n.PropTypes=n,n}();var _=s.exports;function R(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=c(e);if(t){var r=c(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return i(this,n)}}var k,T,x,$=function(r){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(a,e.PureComponent);var i,c,s,u=R(a);function a(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),(t=u.call(this,e)).container=null,t.window=null,t.windowCheckerInterval=null,t.released=!1,t.state={mounted:!1},t}return i=a,(c=[{key:"render",value:function(){return this.state.mounted?t.createPortal(this.props.children,this.container):null}},{key:"componentDidMount",value:function(){this.openChild(),this.setState({mounted:!0})}},{key:"openChild",value:function(){var e,t=this,n=this.props,o=n.url,r=n.title,i=n.name,c=n.features,s=n.onBlock,u=n.onOpen,a=n.center;if("string"!=typeof a||void 0!==c.width&&void 0!==c.height){if("parent"===a)c.left=window.top.outerWidth/2+window.top.screenX-c.width/2,c.top=window.top.outerHeight/2+window.top.screenY-c.height/2;else if("screen"===a){var l=void 0!==window.screenLeft?window.screenLeft:window.screen.left,f=void 0!==window.screenTop?window.screenTop:window.screen.top,d=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,p=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height;c.left=d/2-c.width/2+l,c.top=p/2-c.height/2+f}}else console.warn("width and height window features must be present when a center prop is provided");if(this.window=window.open(o,i,(e=c,Object.keys(e).reduce((function(t,n){var o=e[n];return"boolean"==typeof o?t.push("".concat(n,"=").concat(o?"yes":"no")):t.push("".concat(n,"=").concat(o)),t}),[]).join(","))),this.container=this.window.document.createElement("div"),this.windowCheckerInterval=setInterval((function(){t.window&&!t.window.closed||t.release()}),50),this.window){if(this.window.document.title=r,this.container=this.window.document.getElementById("new-window-container"),null===this.container)this.container=this.window.document.createElement("div"),this.container.setAttribute("id","new-window-container"),this.window.document.body.appendChild(this.container);else{var y=this.window.document.getElementById("new-window-container-static");this.window.document.body.removeChild(y)}this.props.copyStyles&&setTimeout((function(){return e=document,n=t.window.document,o=n.createDocumentFragment(),Array.from(e.styleSheets).forEach((function(e){var t;try{t=e.cssRules}catch(e){console.error(e)}if(t){var r=[];Array.from(e.cssRules).forEach((function(e){var t=e.type;if(t!==CSSRule.UNKNOWN_RULE){var n="";n=t===CSSRule.KEYFRAMES_RULE?function(e){var t=["@keyframes",e.name,"{"];return Array.from(e.cssRules).forEach((function(e){t.push(e.keyText,"{",e.style.cssText,"}")})),t.push("}"),t.join(" ")}(e):[CSSRule.IMPORT_RULE,CSSRule.FONT_FACE_RULE].includes(t)?function(e){return e.cssText.split("url(").map((function(e){return"/"===e[1]?"".concat(e.slice(0,1)).concat(window.location.origin).concat(e.slice(1)):e})).join("url(")}(e):e.cssText,r.push(n)}}));var i=n.createElement("style");i.textContent=r.join("\n"),o.appendChild(i)}else if(e.href){var c=n.createElement("link");c.rel="stylesheet",c.href=e.href,o.appendChild(c)}})),void n.head.appendChild(o);var e,n,o}),0),"function"==typeof u&&u(this.window),this.window.addEventListener("beforeunload",(function(){return t.release()}))}else"function"==typeof s?s(null):console.warn("A new window could not be opened. Maybe it was blocked.")}},{key:"componentWillUnmount",value:function(){if(this.window)if(this.props.closeOnUnmount)this.window.close();else if(this.props.children){var e=this.container.cloneNode(!0);e.setAttribute("id","new-window-container-static"),this.window.document.body.appendChild(e)}}},{key:"release",value:function(){if(!this.released){this.released=!0,clearInterval(this.windowCheckerInterval);var e=this.props.onUnload;"function"==typeof e&&e(null)}}}])&&n(i.prototype,c),s&&n(i,s),a}();x={url:"",name:"",title:"",features:{width:"600px",height:"640px"},onBlock:null,onOpen:null,onUnload:null,center:"parent",copyStyles:!0,closeOnUnmount:!0},(T="defaultProps")in(k=$)?Object.defineProperty(k,T,{value:x,enumerable:!0,configurable:!0,writable:!0}):k[T]=x,$.propTypes={children:_.node,url:_.string,name:_.string,title:_.string,features:_.object,onUnload:_.func,onBlock:_.func,onOpen:_.func,center:_.oneOf(["parent","screen"]),copyStyles:_.bool,closeOnUnmount:_.bool};export{$ as default}; | ||
import e from"react";import t from"react-dom";function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function o(e,t){return o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},o(e,t)}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}var s,u,l,a,d={exports:{}};function p(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=c(e);if(t){var r=c(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return i(this,n)}}d.exports=function(){if(a)return l;a=1;var e=u?s:(u=1,s="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");function t(){}function n(){}return n.resetWarningCache=t,l=function(){function o(t,n,o,r,i,c){if(c!==e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function r(){return o}o.isRequired=o;var i={array:o,bool:o,func:o,number:o,object:o,string:o,symbol:o,any:o,arrayOf:r,element:o,elementType:o,instanceOf:r,node:o,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r,checkPropTypes:n,resetWarningCache:t};return i.PropTypes=i,i}}()();var f,h,w,y=function(r){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(l,e.PureComponent);var i,c,s,u=p(l);function l(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l),(t=u.call(this,e)).container=null,t.window=null,t.windowCheckerInterval=null,t.released=!1,t.state={mounted:!1},t}return i=l,(c=[{key:"render",value:function(){return this.state.mounted?t.createPortal(this.props.children,this.container):null}},{key:"componentDidMount",value:function(){this.window||this.container||(this.openChild(),this.setState({mounted:!0}))}},{key:"openChild",value:function(){var e,t=this,n=this.props,o=n.url,r=n.title,i=n.name,c=n.features,s=n.onBlock,u=n.onOpen,l=n.center;if("string"!=typeof l||void 0!==c.width&&void 0!==c.height){if("parent"===l)c.left=window.top.outerWidth/2+window.top.screenX-c.width/2,c.top=window.top.outerHeight/2+window.top.screenY-c.height/2;else if("screen"===l){var a=void 0!==window.screenLeft?window.screenLeft:window.screen.left,d=void 0!==window.screenTop?window.screenTop:window.screen.top,p=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,f=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height;c.left=p/2-c.width/2+a,c.top=f/2-c.height/2+d}}else console.warn("width and height window features must be present when a center prop is provided");if(this.window=window.open(o,i,(e=c,Object.keys(e).reduce((function(t,n){var o=e[n];return"boolean"==typeof o?t.push("".concat(n,"=").concat(o?"yes":"no")):t.push("".concat(n,"=").concat(o)),t}),[]).join(","))),this.container=this.window.document.createElement("div"),this.windowCheckerInterval=setInterval((function(){t.window&&!t.window.closed||t.release()}),50),this.window){if(this.window.document.title=r,this.container=this.window.document.getElementById("new-window-container"),null===this.container)this.container=this.window.document.createElement("div"),this.container.setAttribute("id","new-window-container"),this.window.document.body.appendChild(this.container);else{var h=this.window.document.getElementById("new-window-container-static");this.window.document.body.removeChild(h)}this.props.copyStyles&&setTimeout((function(){return e=document,n=t.window.document,o=n.createDocumentFragment(),Array.from(e.styleSheets).forEach((function(e){var t;try{t=e.cssRules}catch(e){console.error(e)}if(t){var r=[];Array.from(e.cssRules).forEach((function(e){var t=e.type;if(t!==CSSRule.UNKNOWN_RULE){var n="";n=t===CSSRule.KEYFRAMES_RULE?function(e){var t=["@keyframes",e.name,"{"];return Array.from(e.cssRules).forEach((function(e){t.push(e.keyText,"{",e.style.cssText,"}")})),t.push("}"),t.join(" ")}(e):[CSSRule.IMPORT_RULE,CSSRule.FONT_FACE_RULE].includes(t)?function(e){return e.cssText.split("url(").map((function(e){return"/"===e[1]?"".concat(e.slice(0,1)).concat(window.location.origin).concat(e.slice(1)):e})).join("url(")}(e):e.cssText,r.push(n)}}));var i=n.createElement("style");i.textContent=r.join("\n"),o.appendChild(i)}else if(e.href){var c=n.createElement("link");c.rel="stylesheet",c.href=e.href,o.appendChild(c)}})),void n.head.appendChild(o);var e,n,o}),0),"function"==typeof u&&u(this.window),this.window.addEventListener("beforeunload",(function(){return t.release()}))}else"function"==typeof s?s(null):console.warn("A new window could not be opened. Maybe it was blocked.")}},{key:"componentWillUnmount",value:function(){if(this.state.mounted&&this.window)if(this.props.closeOnUnmount)this.window.close();else if(this.props.children){var e=this.container.cloneNode(!0);e.setAttribute("id","new-window-container-static"),this.window.document.body.appendChild(e)}}},{key:"release",value:function(){if(!this.released){this.released=!0,clearInterval(this.windowCheckerInterval);var e=this.props.onUnload;"function"==typeof e&&e(null)}}}])&&n(i.prototype,c),s&&n(i,s),l}();w={url:"",name:"",title:"",features:{width:"600px",height:"640px"},onBlock:null,onOpen:null,onUnload:null,center:"parent",copyStyles:!0,closeOnUnmount:!0},(h="defaultProps")in(f=y)?Object.defineProperty(f,h,{value:w,enumerable:!0,configurable:!0,writable:!0}):f[h]=w,y.propTypes={children:d.exports.node,url:d.exports.string,name:d.exports.string,title:d.exports.string,features:d.exports.object,onUnload:d.exports.func,onBlock:d.exports.func,onOpen:d.exports.func,center:d.exports.oneOf(["parent","screen"]),copyStyles:d.exports.bool,closeOnUnmount:d.exports.bool};export{y as default}; | ||
//# sourceMappingURL=react-new-window.js.map |
@@ -1,17 +0,2 @@ | ||
"use strict";var e=require("react"),t=require("react-dom");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t);function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(e,t)}function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function s(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}var l={exports:{}},f={}; | ||
/** @license React v16.8.6 | ||
* react-is.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. | ||
*/ | ||
Object.defineProperty(f,"__esModule",{value:!0});var d="function"==typeof Symbol&&Symbol.for,p=d?Symbol.for("react.element"):60103,y=d?Symbol.for("react.portal"):60106,h=d?Symbol.for("react.fragment"):60107,w=d?Symbol.for("react.strict_mode"):60108,m=d?Symbol.for("react.profiler"):60114,b=d?Symbol.for("react.provider"):60109,v=d?Symbol.for("react.context"):60110,O=d?Symbol.for("react.async_mode"):60111,S=d?Symbol.for("react.concurrent_mode"):60111,g=d?Symbol.for("react.forward_ref"):60112,j=d?Symbol.for("react.suspense"):60113,E=d?Symbol.for("react.memo"):60115,C=d?Symbol.for("react.lazy"):60116;function P(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case p:switch(e=e.type){case O:case S:case h:case m:case w:case j:return e;default:switch(e=e&&e.$$typeof){case v:case g:case b:return e;default:return t}}case C:case E:case y:return t}}}function _(e){return P(e)===S}f.typeOf=P,f.AsyncMode=O,f.ConcurrentMode=S,f.ContextConsumer=v,f.ContextProvider=b,f.Element=p,f.ForwardRef=g,f.Fragment=h,f.Lazy=C,f.Memo=E,f.Portal=y,f.Profiler=m,f.StrictMode=w,f.Suspense=j,f.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===h||e===S||e===m||e===w||e===j||"object"==typeof e&&null!==e&&(e.$$typeof===C||e.$$typeof===E||e.$$typeof===b||e.$$typeof===v||e.$$typeof===g)},f.isAsyncMode=function(e){return _(e)||P(e)===O},f.isConcurrentMode=_,f.isContextConsumer=function(e){return P(e)===v},f.isContextProvider=function(e){return P(e)===b},f.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===p},f.isForwardRef=function(e){return P(e)===g},f.isFragment=function(e){return P(e)===h},f.isLazy=function(e){return P(e)===C},f.isMemo=function(e){return P(e)===E},f.isPortal=function(e){return P(e)===y},f.isProfiler=function(e){return P(e)===m},f.isStrictMode=function(e){return P(e)===w},f.isSuspense=function(e){return P(e)===j}; | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
Object.getOwnPropertySymbols,Object.prototype.hasOwnProperty,Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;var o=Object.getOwnPropertyNames(t).map((function(e){return t[e]}));if("0123456789"!==o.join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()||Object.assign;Function.call.bind(Object.prototype.hasOwnProperty);function R(){}function k(){}k.resetWarningCache=R;l.exports=function(){function e(e,t,n,o,r,i){if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==i){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:k,resetWarningCache:R};return n.PropTypes=n,n}();var T=l.exports;function x(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=a(e);if(t){var r=a(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return s(this,n)}}var $,U,I,M=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(a,o["default"].PureComponent);var t,n,u,s=x(a);function a(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),(t=s.call(this,e)).container=null,t.window=null,t.windowCheckerInterval=null,t.released=!1,t.state={mounted:!1},t}return t=a,(n=[{key:"render",value:function(){return this.state.mounted?r.default.createPortal(this.props.children,this.container):null}},{key:"componentDidMount",value:function(){this.openChild(),this.setState({mounted:!0})}},{key:"openChild",value:function(){var e,t=this,n=this.props,o=n.url,r=n.title,i=n.name,c=n.features,u=n.onBlock,s=n.onOpen,a=n.center;if("string"!=typeof a||void 0!==c.width&&void 0!==c.height){if("parent"===a)c.left=window.top.outerWidth/2+window.top.screenX-c.width/2,c.top=window.top.outerHeight/2+window.top.screenY-c.height/2;else if("screen"===a){var l=void 0!==window.screenLeft?window.screenLeft:window.screen.left,f=void 0!==window.screenTop?window.screenTop:window.screen.top,d=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,p=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height;c.left=d/2-c.width/2+l,c.top=p/2-c.height/2+f}}else console.warn("width and height window features must be present when a center prop is provided");if(this.window=window.open(o,i,(e=c,Object.keys(e).reduce((function(t,n){var o=e[n];return"boolean"==typeof o?t.push("".concat(n,"=").concat(o?"yes":"no")):t.push("".concat(n,"=").concat(o)),t}),[]).join(","))),this.container=this.window.document.createElement("div"),this.windowCheckerInterval=setInterval((function(){t.window&&!t.window.closed||t.release()}),50),this.window){if(this.window.document.title=r,this.container=this.window.document.getElementById("new-window-container"),null===this.container)this.container=this.window.document.createElement("div"),this.container.setAttribute("id","new-window-container"),this.window.document.body.appendChild(this.container);else{var y=this.window.document.getElementById("new-window-container-static");this.window.document.body.removeChild(y)}this.props.copyStyles&&setTimeout((function(){return e=document,n=t.window.document,o=n.createDocumentFragment(),Array.from(e.styleSheets).forEach((function(e){var t;try{t=e.cssRules}catch(e){console.error(e)}if(t){var r=[];Array.from(e.cssRules).forEach((function(e){var t=e.type;if(t!==CSSRule.UNKNOWN_RULE){var n="";n=t===CSSRule.KEYFRAMES_RULE?function(e){var t=["@keyframes",e.name,"{"];return Array.from(e.cssRules).forEach((function(e){t.push(e.keyText,"{",e.style.cssText,"}")})),t.push("}"),t.join(" ")}(e):[CSSRule.IMPORT_RULE,CSSRule.FONT_FACE_RULE].includes(t)?function(e){return e.cssText.split("url(").map((function(e){return"/"===e[1]?"".concat(e.slice(0,1)).concat(window.location.origin).concat(e.slice(1)):e})).join("url(")}(e):e.cssText,r.push(n)}}));var i=n.createElement("style");i.textContent=r.join("\n"),o.appendChild(i)}else if(e.href){var c=n.createElement("link");c.rel="stylesheet",c.href=e.href,o.appendChild(c)}})),void n.head.appendChild(o);var e,n,o}),0),"function"==typeof s&&s(this.window),this.window.addEventListener("beforeunload",(function(){return t.release()}))}else"function"==typeof u?u(null):console.warn("A new window could not be opened. Maybe it was blocked.")}},{key:"componentWillUnmount",value:function(){if(this.window)if(this.props.closeOnUnmount)this.window.close();else if(this.props.children){var e=this.container.cloneNode(!0);e.setAttribute("id","new-window-container-static"),this.window.document.body.appendChild(e)}}},{key:"release",value:function(){if(!this.released){this.released=!0,clearInterval(this.windowCheckerInterval);var e=this.props.onUnload;"function"==typeof e&&e(null)}}}])&&i(t.prototype,n),u&&i(t,u),a}();I={url:"",name:"",title:"",features:{width:"600px",height:"640px"},onBlock:null,onOpen:null,onUnload:null,center:"parent",copyStyles:!0,closeOnUnmount:!0},(U="defaultProps")in($=M)?Object.defineProperty($,U,{value:I,enumerable:!0,configurable:!0,writable:!0}):$[U]=I,M.propTypes={children:T.node,url:T.string,name:T.string,title:T.string,features:T.object,onUnload:T.func,onBlock:T.func,onOpen:T.func,center:T.oneOf(["parent","screen"]),copyStyles:T.bool,closeOnUnmount:T.bool},module.exports=M; | ||
"use strict";var e=require("react"),t=require("react-dom");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t);function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(e,t)}function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function u(e,t){if(t&&("object"===s(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}var a,d,f,p,h={exports:{}};function w(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=l(e);if(t){var r=l(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return u(this,n)}}h.exports=function(){if(p)return f;p=1;var e=d?a:(d=1,a="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");function t(){}function n(){}return n.resetWarningCache=t,f=function(){function o(t,n,o,r,i,c){if(c!==e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function r(){return o}o.isRequired=o;var i={array:o,bool:o,func:o,number:o,object:o,string:o,symbol:o,any:o,arrayOf:r,element:o,elementType:o,instanceOf:r,node:o,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r,checkPropTypes:n,resetWarningCache:t};return i.PropTypes=i,i}}()();var y,m,v,b=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(l,o["default"].PureComponent);var t,n,s,u=w(l);function l(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l),(t=u.call(this,e)).container=null,t.window=null,t.windowCheckerInterval=null,t.released=!1,t.state={mounted:!1},t}return t=l,(n=[{key:"render",value:function(){return this.state.mounted?r.default.createPortal(this.props.children,this.container):null}},{key:"componentDidMount",value:function(){this.window||this.container||(this.openChild(),this.setState({mounted:!0}))}},{key:"openChild",value:function(){var e,t=this,n=this.props,o=n.url,r=n.title,i=n.name,c=n.features,s=n.onBlock,u=n.onOpen,l=n.center;if("string"!=typeof l||void 0!==c.width&&void 0!==c.height){if("parent"===l)c.left=window.top.outerWidth/2+window.top.screenX-c.width/2,c.top=window.top.outerHeight/2+window.top.screenY-c.height/2;else if("screen"===l){var a=void 0!==window.screenLeft?window.screenLeft:window.screen.left,d=void 0!==window.screenTop?window.screenTop:window.screen.top,f=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,p=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height;c.left=f/2-c.width/2+a,c.top=p/2-c.height/2+d}}else console.warn("width and height window features must be present when a center prop is provided");if(this.window=window.open(o,i,(e=c,Object.keys(e).reduce((function(t,n){var o=e[n];return"boolean"==typeof o?t.push("".concat(n,"=").concat(o?"yes":"no")):t.push("".concat(n,"=").concat(o)),t}),[]).join(","))),this.container=this.window.document.createElement("div"),this.windowCheckerInterval=setInterval((function(){t.window&&!t.window.closed||t.release()}),50),this.window){if(this.window.document.title=r,this.container=this.window.document.getElementById("new-window-container"),null===this.container)this.container=this.window.document.createElement("div"),this.container.setAttribute("id","new-window-container"),this.window.document.body.appendChild(this.container);else{var h=this.window.document.getElementById("new-window-container-static");this.window.document.body.removeChild(h)}this.props.copyStyles&&setTimeout((function(){return e=document,n=t.window.document,o=n.createDocumentFragment(),Array.from(e.styleSheets).forEach((function(e){var t;try{t=e.cssRules}catch(e){console.error(e)}if(t){var r=[];Array.from(e.cssRules).forEach((function(e){var t=e.type;if(t!==CSSRule.UNKNOWN_RULE){var n="";n=t===CSSRule.KEYFRAMES_RULE?function(e){var t=["@keyframes",e.name,"{"];return Array.from(e.cssRules).forEach((function(e){t.push(e.keyText,"{",e.style.cssText,"}")})),t.push("}"),t.join(" ")}(e):[CSSRule.IMPORT_RULE,CSSRule.FONT_FACE_RULE].includes(t)?function(e){return e.cssText.split("url(").map((function(e){return"/"===e[1]?"".concat(e.slice(0,1)).concat(window.location.origin).concat(e.slice(1)):e})).join("url(")}(e):e.cssText,r.push(n)}}));var i=n.createElement("style");i.textContent=r.join("\n"),o.appendChild(i)}else if(e.href){var c=n.createElement("link");c.rel="stylesheet",c.href=e.href,o.appendChild(c)}})),void n.head.appendChild(o);var e,n,o}),0),"function"==typeof u&&u(this.window),this.window.addEventListener("beforeunload",(function(){return t.release()}))}else"function"==typeof s?s(null):console.warn("A new window could not be opened. Maybe it was blocked.")}},{key:"componentWillUnmount",value:function(){if(this.state.mounted&&this.window)if(this.props.closeOnUnmount)this.window.close();else if(this.props.children){var e=this.container.cloneNode(!0);e.setAttribute("id","new-window-container-static"),this.window.document.body.appendChild(e)}}},{key:"release",value:function(){if(!this.released){this.released=!0,clearInterval(this.windowCheckerInterval);var e=this.props.onUnload;"function"==typeof e&&e(null)}}}])&&i(t.prototype,n),s&&i(t,s),l}();v={url:"",name:"",title:"",features:{width:"600px",height:"640px"},onBlock:null,onOpen:null,onUnload:null,center:"parent",copyStyles:!0,closeOnUnmount:!0},(m="defaultProps")in(y=b)?Object.defineProperty(y,m,{value:v,enumerable:!0,configurable:!0,writable:!0}):y[m]=v,b.propTypes={children:h.exports.node,url:h.exports.string,name:h.exports.string,title:h.exports.string,features:h.exports.object,onUnload:h.exports.func,onBlock:h.exports.func,onOpen:h.exports.func,center:h.exports.oneOf(["parent","screen"]),copyStyles:h.exports.bool,closeOnUnmount:h.exports.bool},module.exports=b; | ||
//# sourceMappingURL=react-new-window.js.map |
{ | ||
"name": "react-new-window", | ||
"description": "Pop a new window in React, using window.open API", | ||
"version": "0.2.2", | ||
"version": "0.2.3-beta.0", | ||
"keywords": [ | ||
@@ -32,6 +32,6 @@ "react", | ||
"@babel/preset-env": "^7.15.8", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.6", | ||
"@rollup/plugin-replace": "^3.0.0", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-commonjs": "^22.0.2", | ||
"@rollup/plugin-node-resolve": "^14.1.0", | ||
"@rollup/plugin-replace": "^4.0.0", | ||
"@storybook/addon-actions": "^6.3.12", | ||
@@ -46,3 +46,2 @@ "@storybook/addon-links": "^6.3.12", | ||
"husky": "^7.0.4", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.4.1", | ||
@@ -54,9 +53,9 @@ "pretty-quick": "^3.1.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.58.1", | ||
"rollup-plugin-filesize": "^9.1.1", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-filesize": "^9.1.2", | ||
"rollup-plugin-terser": "^7.0.2" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.0.0 || ^17.0.0", | ||
"react-dom": "^16.0.0 || ^17.0.0" | ||
"react": "^16.0.0 || ^18.0.0", | ||
"react-dom": "^16.0.0 || ^18.0.0" | ||
}, | ||
@@ -66,4 +65,5 @@ "scripts": { | ||
"clean": "rimraf 'es' 'lib' 'umd' 'docs'", | ||
"build-storybook": "cross-env NODE_ENV=test build-storybook -o docs", | ||
"build-storybook": "cross-env NODE_ENV=test NODE_OPTIONS=--openssl-legacy-provider build-storybook -o docs", | ||
"lint": "eslint ./src", | ||
"version": "npm run build && npm run build-storybook && git add -A docs", | ||
"postversion": "git push origin && git push origin --tags", | ||
@@ -70,0 +70,0 @@ "storybook": "cross-env NODE_ENV=test start-storybook -p 6006" |
@@ -9,3 +9,3 @@ [![React New Window - Pop new windows in React, using window.open API.](.github/banner.svg)](#features) | ||
- **Only 4.05KB** (gzipped!). | ||
- **Only 3.68KB** (gzipped!). | ||
- **Support the full `window.open` api**. | ||
@@ -12,0 +12,0 @@ - **Built for React 16** (uses `ReactDOM.createPortal`). |
@@ -1,17 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).ReactNewWindow=t(e.React,e.ReactDOM)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t);function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(e,t)}function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function s(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}var l={exports:{}},f={}; | ||
/** @license React v16.8.6 | ||
* react-is.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. | ||
*/ | ||
Object.defineProperty(f,"__esModule",{value:!0});var d="function"==typeof Symbol&&Symbol.for,p=d?Symbol.for("react.element"):60103,y=d?Symbol.for("react.portal"):60106,h=d?Symbol.for("react.fragment"):60107,w=d?Symbol.for("react.strict_mode"):60108,m=d?Symbol.for("react.profiler"):60114,b=d?Symbol.for("react.provider"):60109,v=d?Symbol.for("react.context"):60110,O=d?Symbol.for("react.async_mode"):60111,g=d?Symbol.for("react.concurrent_mode"):60111,S=d?Symbol.for("react.forward_ref"):60112,j=d?Symbol.for("react.suspense"):60113,E=d?Symbol.for("react.memo"):60115,C=d?Symbol.for("react.lazy"):60116;function P(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case p:switch(e=e.type){case O:case g:case h:case m:case w:case j:return e;default:switch(e=e&&e.$$typeof){case v:case S:case b:return e;default:return t}}case C:case E:case y:return t}}}function R(e){return P(e)===g}f.typeOf=P,f.AsyncMode=O,f.ConcurrentMode=g,f.ContextConsumer=v,f.ContextProvider=b,f.Element=p,f.ForwardRef=S,f.Fragment=h,f.Lazy=C,f.Memo=E,f.Portal=y,f.Profiler=m,f.StrictMode=w,f.Suspense=j,f.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===h||e===g||e===m||e===w||e===j||"object"==typeof e&&null!==e&&(e.$$typeof===C||e.$$typeof===E||e.$$typeof===b||e.$$typeof===v||e.$$typeof===S)},f.isAsyncMode=function(e){return R(e)||P(e)===O},f.isConcurrentMode=R,f.isContextConsumer=function(e){return P(e)===v},f.isContextProvider=function(e){return P(e)===b},f.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===p},f.isForwardRef=function(e){return P(e)===S},f.isFragment=function(e){return P(e)===h},f.isLazy=function(e){return P(e)===C},f.isMemo=function(e){return P(e)===E},f.isPortal=function(e){return P(e)===y},f.isProfiler=function(e){return P(e)===m},f.isStrictMode=function(e){return P(e)===w},f.isSuspense=function(e){return P(e)===j}; | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
Object.getOwnPropertySymbols,Object.prototype.hasOwnProperty,Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;var o=Object.getOwnPropertyNames(t).map((function(e){return t[e]}));if("0123456789"!==o.join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()||Object.assign;Function.call.bind(Object.prototype.hasOwnProperty);function _(){}function T(){}T.resetWarningCache=_;l.exports=function(){function e(e,t,n,o,r,i){if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==i){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:T,resetWarningCache:_};return n.PropTypes=n,n}();var k=l.exports;function x(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=a(e);if(t){var r=a(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return s(this,n)}}var $,M,U,I=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(s,e);var t,n,o,u=x(s);function s(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),(t=u.call(this,e)).container=null,t.window=null,t.windowCheckerInterval=null,t.released=!1,t.state={mounted:!1},t}return t=s,(n=[{key:"render",value:function(){return this.state.mounted?r.default.createPortal(this.props.children,this.container):null}},{key:"componentDidMount",value:function(){this.openChild(),this.setState({mounted:!0})}},{key:"openChild",value:function(){var e,t=this,n=this.props,o=n.url,r=n.title,i=n.name,c=n.features,u=n.onBlock,s=n.onOpen,a=n.center;if("string"!=typeof a||void 0!==c.width&&void 0!==c.height){if("parent"===a)c.left=window.top.outerWidth/2+window.top.screenX-c.width/2,c.top=window.top.outerHeight/2+window.top.screenY-c.height/2;else if("screen"===a){var l=void 0!==window.screenLeft?window.screenLeft:window.screen.left,f=void 0!==window.screenTop?window.screenTop:window.screen.top,d=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,p=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height;c.left=d/2-c.width/2+l,c.top=p/2-c.height/2+f}}else console.warn("width and height window features must be present when a center prop is provided");if(this.window=window.open(o,i,(e=c,Object.keys(e).reduce((function(t,n){var o=e[n];return"boolean"==typeof o?t.push("".concat(n,"=").concat(o?"yes":"no")):t.push("".concat(n,"=").concat(o)),t}),[]).join(","))),this.container=this.window.document.createElement("div"),this.windowCheckerInterval=setInterval((function(){t.window&&!t.window.closed||t.release()}),50),this.window){if(this.window.document.title=r,this.container=this.window.document.getElementById("new-window-container"),null===this.container)this.container=this.window.document.createElement("div"),this.container.setAttribute("id","new-window-container"),this.window.document.body.appendChild(this.container);else{var y=this.window.document.getElementById("new-window-container-static");this.window.document.body.removeChild(y)}this.props.copyStyles&&setTimeout((function(){return e=document,n=t.window.document,o=n.createDocumentFragment(),Array.from(e.styleSheets).forEach((function(e){var t;try{t=e.cssRules}catch(e){console.error(e)}if(t){var r=[];Array.from(e.cssRules).forEach((function(e){var t=e.type;if(t!==CSSRule.UNKNOWN_RULE){var n="";n=t===CSSRule.KEYFRAMES_RULE?function(e){var t=["@keyframes",e.name,"{"];return Array.from(e.cssRules).forEach((function(e){t.push(e.keyText,"{",e.style.cssText,"}")})),t.push("}"),t.join(" ")}(e):[CSSRule.IMPORT_RULE,CSSRule.FONT_FACE_RULE].includes(t)?function(e){return e.cssText.split("url(").map((function(e){return"/"===e[1]?"".concat(e.slice(0,1)).concat(window.location.origin).concat(e.slice(1)):e})).join("url(")}(e):e.cssText,r.push(n)}}));var i=n.createElement("style");i.textContent=r.join("\n"),o.appendChild(i)}else if(e.href){var c=n.createElement("link");c.rel="stylesheet",c.href=e.href,o.appendChild(c)}})),void n.head.appendChild(o);var e,n,o}),0),"function"==typeof s&&s(this.window),this.window.addEventListener("beforeunload",(function(){return t.release()}))}else"function"==typeof u?u(null):console.warn("A new window could not be opened. Maybe it was blocked.")}},{key:"componentWillUnmount",value:function(){if(this.window)if(this.props.closeOnUnmount)this.window.close();else if(this.props.children){var e=this.container.cloneNode(!0);e.setAttribute("id","new-window-container-static"),this.window.document.body.appendChild(e)}}},{key:"release",value:function(){if(!this.released){this.released=!0,clearInterval(this.windowCheckerInterval);var e=this.props.onUnload;"function"==typeof e&&e(null)}}}])&&i(t.prototype,n),o&&i(t,o),s}(o.default.PureComponent);return U={url:"",name:"",title:"",features:{width:"600px",height:"640px"},onBlock:null,onOpen:null,onUnload:null,center:"parent",copyStyles:!0,closeOnUnmount:!0},(M="defaultProps")in($=I)?Object.defineProperty($,M,{value:U,enumerable:!0,configurable:!0,writable:!0}):$[M]=U,I.propTypes={children:k.node,url:k.string,name:k.string,title:k.string,features:k.object,onUnload:k.func,onBlock:k.func,onOpen:k.func,center:k.oneOf(["parent","screen"]),copyStyles:k.bool,closeOnUnmount:k.bool},I})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).ReactNewWindow=t(e.React,e.ReactDOM)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t);function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(e,t)}function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function u(e,t){if(t&&("object"===s(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}var a,d,f,p,h={exports:{}};function w(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=l(e);if(t){var r=l(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return u(this,n)}}h.exports=function(){if(p)return f;p=1;var e=d?a:(d=1,a="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");function t(){}function n(){}return n.resetWarningCache=t,f=function(){function o(t,n,o,r,i,c){if(c!==e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function r(){return o}o.isRequired=o;var i={array:o,bool:o,func:o,number:o,object:o,string:o,symbol:o,any:o,arrayOf:r,element:o,elementType:o,instanceOf:r,node:o,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r,checkPropTypes:n,resetWarningCache:t};return i.PropTypes=i,i}}()();var y,m,v,b=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(u,e);var t,n,o,s=w(u);function u(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),(t=s.call(this,e)).container=null,t.window=null,t.windowCheckerInterval=null,t.released=!1,t.state={mounted:!1},t}return t=u,(n=[{key:"render",value:function(){return this.state.mounted?r.default.createPortal(this.props.children,this.container):null}},{key:"componentDidMount",value:function(){this.window||this.container||(this.openChild(),this.setState({mounted:!0}))}},{key:"openChild",value:function(){var e,t=this,n=this.props,o=n.url,r=n.title,i=n.name,c=n.features,s=n.onBlock,u=n.onOpen,l=n.center;if("string"!=typeof l||void 0!==c.width&&void 0!==c.height){if("parent"===l)c.left=window.top.outerWidth/2+window.top.screenX-c.width/2,c.top=window.top.outerHeight/2+window.top.screenY-c.height/2;else if("screen"===l){var a=void 0!==window.screenLeft?window.screenLeft:window.screen.left,d=void 0!==window.screenTop?window.screenTop:window.screen.top,f=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,p=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height;c.left=f/2-c.width/2+a,c.top=p/2-c.height/2+d}}else console.warn("width and height window features must be present when a center prop is provided");if(this.window=window.open(o,i,(e=c,Object.keys(e).reduce((function(t,n){var o=e[n];return"boolean"==typeof o?t.push("".concat(n,"=").concat(o?"yes":"no")):t.push("".concat(n,"=").concat(o)),t}),[]).join(","))),this.container=this.window.document.createElement("div"),this.windowCheckerInterval=setInterval((function(){t.window&&!t.window.closed||t.release()}),50),this.window){if(this.window.document.title=r,this.container=this.window.document.getElementById("new-window-container"),null===this.container)this.container=this.window.document.createElement("div"),this.container.setAttribute("id","new-window-container"),this.window.document.body.appendChild(this.container);else{var h=this.window.document.getElementById("new-window-container-static");this.window.document.body.removeChild(h)}this.props.copyStyles&&setTimeout((function(){return e=document,n=t.window.document,o=n.createDocumentFragment(),Array.from(e.styleSheets).forEach((function(e){var t;try{t=e.cssRules}catch(e){console.error(e)}if(t){var r=[];Array.from(e.cssRules).forEach((function(e){var t=e.type;if(t!==CSSRule.UNKNOWN_RULE){var n="";n=t===CSSRule.KEYFRAMES_RULE?function(e){var t=["@keyframes",e.name,"{"];return Array.from(e.cssRules).forEach((function(e){t.push(e.keyText,"{",e.style.cssText,"}")})),t.push("}"),t.join(" ")}(e):[CSSRule.IMPORT_RULE,CSSRule.FONT_FACE_RULE].includes(t)?function(e){return e.cssText.split("url(").map((function(e){return"/"===e[1]?"".concat(e.slice(0,1)).concat(window.location.origin).concat(e.slice(1)):e})).join("url(")}(e):e.cssText,r.push(n)}}));var i=n.createElement("style");i.textContent=r.join("\n"),o.appendChild(i)}else if(e.href){var c=n.createElement("link");c.rel="stylesheet",c.href=e.href,o.appendChild(c)}})),void n.head.appendChild(o);var e,n,o}),0),"function"==typeof u&&u(this.window),this.window.addEventListener("beforeunload",(function(){return t.release()}))}else"function"==typeof s?s(null):console.warn("A new window could not be opened. Maybe it was blocked.")}},{key:"componentWillUnmount",value:function(){if(this.state.mounted&&this.window)if(this.props.closeOnUnmount)this.window.close();else if(this.props.children){var e=this.container.cloneNode(!0);e.setAttribute("id","new-window-container-static"),this.window.document.body.appendChild(e)}}},{key:"release",value:function(){if(!this.released){this.released=!0,clearInterval(this.windowCheckerInterval);var e=this.props.onUnload;"function"==typeof e&&e(null)}}}])&&i(t.prototype,n),o&&i(t,o),u}(o.default.PureComponent);return v={url:"",name:"",title:"",features:{width:"600px",height:"640px"},onBlock:null,onOpen:null,onUnload:null,center:"parent",copyStyles:!0,closeOnUnmount:!0},(m="defaultProps")in(y=b)?Object.defineProperty(y,m,{value:v,enumerable:!0,configurable:!0,writable:!0}):y[m]=v,b.propTypes={children:h.exports.node,url:h.exports.string,name:h.exports.string,title:h.exports.string,features:h.exports.object,onUnload:h.exports.func,onBlock:h.exports.func,onOpen:h.exports.func,center:h.exports.oneOf(["parent","screen"]),copyStyles:h.exports.bool,closeOnUnmount:h.exports.bool},b})); | ||
//# sourceMappingURL=react-new-window.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26
104295
158
1