react-cool-portal
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -1,1 +0,1 @@ | ||
import{useState as t,useEffect as n,useRef as e,useCallback as r,useMemo as o}from"react";import{createPortal as i}from"react-dom";function u(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){if(!(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)))return;var e=[],r=!0,o=!1,i=void 0;try{for(var u,c=t[Symbol.iterator]();!(r=(u=c.next()).done)&&(e.push(u.value),!n||e.length!==n);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==c.return||c.return()}finally{if(o)throw i}}return e}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var c=function(e,r,o,c){return function(a){var d=a.children,f=u(t(null),2),l=f[0],v=f[1];return n((function(){return v(document.getElementById(e)||function(t){var n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n}(e)),function(){if(l)var t=setTimeout((function(){clearTimeout(t),""===l.innerHTML&&l.remove()}),100)}}),[l]),n((function(){if(o&&c&&r&&l){var t=function(t){l.contains(t.target)||o(t)},n=function(t){27===t.keyCode&&c(t)};return o&&document.addEventListener("click",t),c&&document.addEventListener("keydown",n),function(){o&&document.removeEventListener("click",t),c&&document.removeEventListener("keydown",n)}}}),[l]),r&&l&&i(d,l)}};export default function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=i.containerId,d=void 0===a?"react-cool-portal":a,f=i.defaultShow,l=void 0===f||f,v=i.onShow,m=i.onHide,s=i.clickOutsideToHide,y=void 0===s||s,h=i.escToHide,p=void 0===h||h,w=t(l),b=u(w,2),g=b[0],T=b[1],E=e(null),k=e(null),S=e(!1);n((function(){v&&(E.current=v)}),[v]),n((function(){m&&(k.current=m)}),[m]);var L=r((function(){if(y&&g){S.current=!0;var t=setTimeout((function(){clearTimeout(t),S.current=!1}),100)}}),[y,g]),A=r((function(t){L(),g||(T(!0),v&&v(t))}),[L,g,v]),H=r((function(t){L(),g&&(T(!1),m&&m(t))}),[L,g,m]),j=r((function(t){L(),T(!g),v&&!g&&v(t),m&&g&&m(t)}),[L,g,v,m]),I=r((function(t){S.current||H(t)}),[H]),O=o((function(){return c(d,g,y&&I,p&&I)}),[d,g,y,p,I]);return{isShow:g,show:A,hide:H,toggle:j,Portal:O}} | ||
import{useState as n,useEffect as t,useRef as e,useCallback as r,useMemo as o}from"react";import{createPortal as i}from"react-dom";function u(n,t){return function(n){if(Array.isArray(n))return n}(n)||function(n,t){if(!(Symbol.iterator in Object(n)||"[object Arguments]"===Object.prototype.toString.call(n)))return;var e=[],r=!0,o=!1,i=void 0;try{for(var u,c=n[Symbol.iterator]();!(r=(u=c.next()).done)&&(e.push(u.value),!t||e.length!==t);r=!0);}catch(n){o=!0,i=n}finally{try{r||null==c.return||c.return()}finally{if(o)throw i}}return e}(n,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var c=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,e=setTimeout((function(){clearTimeout(e),n()}),t)},a=function(e,r,o,a){return function(d){var f=d.children,l=u(n(null),2),v=l[0],m=l[1];return t((function(){return m(document.getElementById(e)||function(n){var t=document.createElement("div");return t.setAttribute("id",n),document.body.appendChild(t),t}(e)),function(){v&&c((function(){""===v.innerHTML&&v.remove()}))}}),[v]),t((function(){if(o&&a&&r&&v){var n=function(n){v.contains(n.target)||o(n)},t=function(n){27===n.keyCode&&a(n)};return o&&document.addEventListener("click",n),a&&document.addEventListener("keydown",t),function(){o&&document.removeEventListener("click",n),a&&document.removeEventListener("keydown",t)}}}),[v]),r&&v&&i(f,v)}};export default function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},d=i.containerId,f=void 0===d?"react-cool-portal":d,l=i.defaultShow,v=void 0===l||l,m=i.onShow,s=i.onHide,y=i.clickOutsideToHide,h=void 0===y||y,p=i.escToHide,g=void 0===p||p,w=n(v),b=u(w,2),E=b[0],k=b[1],S=e(null),T=e(null),L=e(!1);t((function(){m&&(S.current=m)}),[m]),t((function(){s&&(T.current=s)}),[s]);var A=r((function(){h&&E&&(L.current=!0,c((function(){L.current=!1})))}),[h,E]),H=r((function(n){A(),E||(k(!0),m&&m(n))}),[A,E,m]),j=r((function(n){A(),E&&(k(!1),s&&s(n))}),[A,E,s]),I=r((function(n){A(),k(!E),m&&!E&&m(n),s&&E&&s(n)}),[A,E,m,s]),O=r((function(n){L.current||j(n)}),[j]),x=o((function(){return a(f,E,h&&O,g&&O)}),[f,E,h,g,O]);return{isShow:E,show:H,hide:j,toggle:I,Portal:x}} |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("react-dom");function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,u=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(r=(i=c.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){u=!0,o=e}finally{try{r||null==c.return||c.return()}finally{if(u)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r=function(r,u,o,i){return function(c){var a=c.children,l=n(e.useState(null),2),f=l[0],d=l[1];return e.useEffect((function(){return d(document.getElementById(r)||function(e){var t=document.createElement("div");return t.setAttribute("id",e),document.body.appendChild(t),t}(r)),function(){if(f)var e=setTimeout((function(){clearTimeout(e),""===f.innerHTML&&f.remove()}),100)}}),[f]),e.useEffect((function(){if(o&&i&&u&&f){var e=function(e){f.contains(e.target)||o(e)},t=function(e){27===e.keyCode&&i(e)};return o&&document.addEventListener("click",e),i&&document.addEventListener("keydown",t),function(){o&&document.removeEventListener("click",e),i&&document.removeEventListener("keydown",t)}}}),[f]),u&&f&&t.createPortal(a,f)}};exports.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},u=t.containerId,o=void 0===u?"react-cool-portal":u,i=t.defaultShow,c=void 0===i||i,a=t.onShow,l=t.onHide,f=t.clickOutsideToHide,d=void 0===f||f,s=t.escToHide,v=void 0===s||s,m=e.useState(c),y=n(m,2),b=y[0],h=y[1],k=e.useRef(null),p=e.useRef(null),E=e.useRef(!1);e.useEffect((function(){a&&(k.current=a)}),[a]),e.useEffect((function(){l&&(p.current=l)}),[l]);var w=e.useCallback((function(){if(d&&b){E.current=!0;var e=setTimeout((function(){clearTimeout(e),E.current=!1}),100)}}),[d,b]),g=e.useCallback((function(e){w(),b||(h(!0),a&&a(e))}),[w,b,a]),S=e.useCallback((function(e){w(),b&&(h(!1),l&&l(e))}),[w,b,l]),T=e.useCallback((function(e){w(),h(!b),a&&!b&&a(e),l&&b&&l(e)}),[w,b,a,l]),C=e.useCallback((function(e){E.current||S(e)}),[S]),L=e.useMemo((function(){return r(o,b,d&&C,v&&C)}),[o,b,d,v,C]);return{isShow:b,show:g,hide:S,toggle:T,Portal:L}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("react-dom");function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,o=!1,u=void 0;try{for(var c,i=e[Symbol.iterator]();!(r=(c=i.next()).done)&&(n.push(c.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw u}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,n=setTimeout((function(){clearTimeout(n),e()}),t)},o=function(o,u,c,i){return function(a){var l=a.children,f=n(e.useState(null),2),d=f[0],s=f[1];return e.useEffect((function(){return s(document.getElementById(o)||function(e){var t=document.createElement("div");return t.setAttribute("id",e),document.body.appendChild(t),t}(o)),function(){d&&r((function(){""===d.innerHTML&&d.remove()}))}}),[d]),e.useEffect((function(){if(c&&i&&u&&d){var e=function(e){d.contains(e.target)||c(e)},t=function(e){27===e.keyCode&&i(e)};return c&&document.addEventListener("click",e),i&&document.addEventListener("keydown",t),function(){c&&document.removeEventListener("click",e),i&&document.removeEventListener("keydown",t)}}}),[d]),u&&d&&t.createPortal(l,d)}};exports.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},u=t.containerId,c=void 0===u?"react-cool-portal":u,i=t.defaultShow,a=void 0===i||i,l=t.onShow,f=t.onHide,d=t.clickOutsideToHide,s=void 0===d||d,v=t.escToHide,m=void 0===v||v,y=e.useState(a),b=n(y,2),h=b[0],k=b[1],p=e.useRef(null),E=e.useRef(null),g=e.useRef(!1);e.useEffect((function(){l&&(p.current=l)}),[l]),e.useEffect((function(){f&&(E.current=f)}),[f]);var w=e.useCallback((function(){s&&h&&(g.current=!0,r((function(){g.current=!1})))}),[s,h]),S=e.useCallback((function(e){w(),h||(k(!0),l&&l(e))}),[w,h,l]),C=e.useCallback((function(e){w(),h&&(k(!1),f&&f(e))}),[w,h,f]),T=e.useCallback((function(e){w(),k(!h),l&&!h&&l(e),f&&h&&f(e)}),[w,h,l,f]),L=e.useCallback((function(e){g.current||C(e)}),[C]),j=e.useMemo((function(){return o(c,h,s&&L,m&&L)}),[c,h,s,m,L]);return{isShow:h,show:S,hide:C,toggle:T,Portal:j}}; |
{ | ||
"name": "react-cool-portal", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "React hook for Portals, which renders modals, dropdowns, tooltips etc. to <body> or else.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
18720
55