react-cool-portal
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,1 @@ | ||
import{useRef as t,useEffect as n,useState as r,useCallback as e}from"react";import{createPortal as o}from"react-dom";function i(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],e=!0,o=!1,i=void 0;try{for(var u,c=t[Symbol.iterator]();!(e=(u=c.next()).done)&&(r.push(u.value),!n||r.length!==n);e=!0);}catch(t){o=!0,i=t}finally{try{e||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,n)||function(t,n){if(!t)return;if("string"==typeof t)return u(t,n);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return u(t,n)}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=new Array(n);r<n;r++)e[r]=t[r];return e}var c=function(r){var e=t(r);return n((function(){e.current=r}),[r]),e},a=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=setTimeout((function(){clearTimeout(r),t()}),n)},d=function(t,e,u,c){return function(d){var f=d.children,l=i(r(null),2),m=l[0],v=l[1];return n((function(){return v(document.getElementById(t)||function(t){var n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n}(t)),function(){m&&a((function(){""===m.innerHTML&&m.remove()}))}}),[m]),n((function(){if(e&&m){var t=function(t){m.contains(t.target)||u(t)},n=function(t){27===t.keyCode&&c(t)};return u&&document.addEventListener("click",t),c&&document.addEventListener("keydown",n),function(){u&&document.removeEventListener("click",t),c&&document.removeEventListener("keydown",n)}}}),[m]),e&&m&&o(f,m)}},f="react-cool-portal",l=!0;export default function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=n.containerId,u=void 0===o?"react-cool-portal":o,f=n.defaultShow,l=void 0===f||f,m=n.clickOutsideToHide,v=void 0===m||m,s=n.escToHide,y=void 0===s||s,h=n.internalShowHide,p=void 0===h||h,b=n.onShow,g=n.onHide,w=r(l),S=i(w,2),A=S[0],E=S[1],k=t(!1),T=c(b),H=c(g),I=t(l),L=e((function(){v&&(k.current=!0,a((function(){k.current=!1})))}),[v]),j=e((function(t){L(),I.current||(E(!0),I.current=!0,T.current&&T.current(t))}),[L,T]),O=e((function(t){L(),I.current&&(E(!1),I.current=!1,H.current&&H.current(t))}),[L,H]),x=e((function(t){I.current?O(t):j(t)}),[O,j]),C=e((function(t){k.current||O(t)}),[O]),M=e(d(u,!p||A,v&&C,y&&C),[p&&A]);return{Portal:M,isShow:A,show:j,hide:O,toggle:x}}export{f as defaultContainerId,l as initShow}; | ||
import{useRef as t,useEffect as n,useState as r,useCallback as e}from"react";import{createPortal as o}from"react-dom";function i(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],e=!0,o=!1,i=void 0;try{for(var u,c=t[Symbol.iterator]();!(e=(u=c.next()).done)&&(r.push(u.value),!n||r.length!==n);e=!0);}catch(t){o=!0,i=t}finally{try{e||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,n)||function(t,n){if(!t)return;if("string"==typeof t)return u(t,n);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return u(t,n)}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=new Array(n);r<n;r++)e[r]=t[r];return e}var c=function(r){var e=t(r);return n((function(){e.current=r}),[r]),e},a=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=setTimeout((function(){clearTimeout(r),t()}),n)},d=function(t,e,u,c){return function(d){var f=d.children,l=i(r(null),2),m=l[0],v=l[1];return n((function(){return v(document.getElementById(t)||function(t){var n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n}(t)),function(){m&&a((function(){""===m.innerHTML&&m.remove()}))}}),[m]),n((function(){if(e&&m){var t=function(t){m.contains(t.target)||u(t)},n=function(t){27===t.keyCode&&c(t)};return u&&document.addEventListener("click",t),c&&document.addEventListener("keydown",n),function(){u&&document.removeEventListener("click",t),c&&document.removeEventListener("keydown",n)}}}),[m]),e&&m&&o(f,m)}},f="react-cool-portal",l=!0;export default function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=n.containerId,u=void 0===o?"react-cool-portal":o,f=n.defaultShow,l=void 0===f||f,m=n.clickOutsideToHide,v=void 0===m||m,s=n.escToHide,y=void 0===s||s,h=n.internalShowHide,p=void 0===h||h,b=n.onShow,g=n.onHide,w=r(l),S=i(w,2),A=S[0],E=S[1],k=t(!1),T=c(b),H=c(g),I=t(l),L=e((function(){v&&(k.current=!0,a((function(){k.current=!1})))}),[v]),j=e((function(t){L(),I.current||(E(!0),I.current=!0,T.current&&T.current(t))}),[L]),O=e((function(t){L(),I.current&&(E(!1),I.current=!1,H.current&&H.current(t))}),[L]),x=e((function(t){I.current?O(t):j(t)}),[O,j]),C=e((function(t){k.current||O(t)}),[O]),M=e(d(u,!p||A,v&&C,y&&C),[p&&A]);return{Portal:M,isShow:A,show:j,hide:O,toggle:x}}export{f as defaultContainerId,l as initShow}; |
@@ -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("undefined"==typeof Symbol||!(Symbol.iterator in Object(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(e,t){if(!e)return;if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var o=function(t){var n=e.useRef(t);return e.useEffect((function(){n.current=t}),[t]),n},u=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,n=setTimeout((function(){clearTimeout(n),e()}),t)},c=function(r,o,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(r)||function(e){var t=document.createElement("div");return t.setAttribute("id",e),document.body.appendChild(t),t}(r)),function(){d&&u((function(){""===d.innerHTML&&d.remove()}))}}),[d]),e.useEffect((function(){if(o&&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]),o&&d&&t.createPortal(l,d)}};exports.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.containerId,i=void 0===r?"react-cool-portal":r,a=t.defaultShow,l=void 0===a||a,f=t.clickOutsideToHide,d=void 0===f||f,s=t.escToHide,v=void 0===s||s,m=t.internalShowHide,y=void 0===m||m,b=t.onShow,h=t.onHide,p=e.useState(l),S=n(p,2),g=S[0],k=S[1],w=e.useRef(!1),C=o(b),E=o(h),A=e.useRef(l),I=e.useCallback((function(){d&&(w.current=!0,u((function(){w.current=!1})))}),[d]),T=e.useCallback((function(e){I(),A.current||(k(!0),A.current=!0,C.current&&C.current(e))}),[I,C]),j=e.useCallback((function(e){I(),A.current&&(k(!1),A.current=!1,E.current&&E.current(e))}),[I,E]),x=e.useCallback((function(e){A.current?j(e):T(e)}),[j,T]),H=e.useCallback((function(e){w.current||j(e)}),[j]),L=e.useCallback(c(i,!y||g,d&&H,v&&H),[y&&g]);return{Portal:L,isShow:g,show:T,hide:j,toggle:x}},exports.defaultContainerId="react-cool-portal",exports.initShow=!0; | ||
"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("undefined"==typeof Symbol||!(Symbol.iterator in Object(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(e,t){if(!e)return;if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var o=function(t){var n=e.useRef(t);return e.useEffect((function(){n.current=t}),[t]),n},u=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,n=setTimeout((function(){clearTimeout(n),e()}),t)},c=function(r,o,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(r)||function(e){var t=document.createElement("div");return t.setAttribute("id",e),document.body.appendChild(t),t}(r)),function(){d&&u((function(){""===d.innerHTML&&d.remove()}))}}),[d]),e.useEffect((function(){if(o&&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]),o&&d&&t.createPortal(l,d)}};exports.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.containerId,i=void 0===r?"react-cool-portal":r,a=t.defaultShow,l=void 0===a||a,f=t.clickOutsideToHide,d=void 0===f||f,s=t.escToHide,v=void 0===s||s,m=t.internalShowHide,y=void 0===m||m,b=t.onShow,h=t.onHide,p=e.useState(l),S=n(p,2),g=S[0],k=S[1],w=e.useRef(!1),C=o(b),E=o(h),A=e.useRef(l),I=e.useCallback((function(){d&&(w.current=!0,u((function(){w.current=!1})))}),[d]),T=e.useCallback((function(e){I(),A.current||(k(!0),A.current=!0,C.current&&C.current(e))}),[I]),j=e.useCallback((function(e){I(),A.current&&(k(!1),A.current=!1,E.current&&E.current(e))}),[I]),x=e.useCallback((function(e){A.current?j(e):T(e)}),[j,T]),H=e.useCallback((function(e){w.current||j(e)}),[j]),L=e.useCallback(c(i,!y||g,d&&H,v&&H),[y&&g]);return{Portal:L,isShow:g,show:T,hide:j,toggle:x}},exports.defaultContainerId="react-cool-portal",exports.initShow=!0; |
{ | ||
"name": "react-cool-portal", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "React hook for Portals, which renders modals, dropdowns, tooltips etc. to <body> or else.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
28987