UNPKG

preact-portal

Version:

Render Preact components somewhere in [a different] space.

2 lines 3.07 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact")):"function"==typeof define&&define.amd?define(["preact"],e):t.preactPortal=e(t.preact)}(this,function(t){"use strict";var e=(function(){function t(t){this.value=t}function e(e){function n(t,e){return new Promise(function(n,r){var s={key:t,arg:e,resolve:n,reject:r,next:null};u?u=u.next=s:(i=u=s,o(t,e))})}function o(n,i){try{var u=e[n](i),s=u.value;s instanceof t?Promise.resolve(s.value).then(function(t){o("next",t)},function(t){o("throw",t)}):r(u.done?"return":"normal",u.value)}catch(t){r("throw",t)}}function r(t,e){switch(t){case"return":i.resolve({value:e,done:!0});break;case"throw":i.reject(e);break;default:i.resolve({value:e,done:!1})}i=i.next,i?o(i.key,i.arg):u=null}var i,u;this._invoke=n,"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),n=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},r=function(r){function u(){return e(this,u),o(this,r.apply(this,arguments))}return n(u,r),u.prototype.componentDidUpdate=function(t){for(var e in t)if(t[e]!==this.props[e])return setTimeout(this.renderLayer)},u.prototype.componentDidMount=function(){this.isMounted=!0,this.renderLayer=this.renderLayer.bind(this),this.renderLayer()},u.prototype.componentWillUnmount=function(){this.renderLayer(!1),this.isMounted=!1,this.remote&&this.remote.parentNode.removeChild(this.remote)},u.prototype.findNode=function(t){return"string"==typeof t?document.querySelector(t):t},u.prototype.renderLayer=function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.isMounted&&(this.props.into!==this.intoPointer&&(this.intoPointer=this.props.into,this.into&&this.remote&&(this.remote=t.render(t.h(i,null),this.into,this.remote)),this.into=this.findNode(this.props.into)),this.remote=t.render(t.h(i,{context:this.context},e&&this.props.children||null),this.into,this.remote))},u.prototype.render=function(){return null},u}(t.Component),i=function(t){function r(){return e(this,r),o(this,t.apply(this,arguments))}return n(r,t),r.prototype.getChildContext=function(){return this.props.context},r.prototype.render=function(t){var e=t.children;return e&&e[0]||null},r}(t.Component);return r}); //# sourceMappingURL=preact-portal.min.js.map