react-modal-global
Advanced tools
Comparing version 0.9.3 to 0.9.4
@@ -54,3 +54,3 @@ import { FunctionComponent, Component } from 'react'; | ||
declare class Modal { | ||
static open<P extends object = {}, AC extends Partial<ModalParams> & P = Partial<ModalParams> & P>(component: ModalComponent<P>, params?: AC): { | ||
static open<P extends object = {}, AC extends Partial<ModalParams> & P = Partial<ModalParams> & P>(component: ModalComponent<P>, ...[params]: P extends object ? [AC] : [AC?]): { | ||
promise: Promise<void>; | ||
@@ -57,0 +57,0 @@ window: ModalWindow<AC>; |
@@ -6,9 +6,9 @@ 'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),react=require("react"),extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var e in c)Object.prototype.hasOwnProperty.call(c,e)&&(a[e]=c[e])};return extendStatics(d,b)}; | ||
function stopPropagation(d){return function(b){var a=b.target;b=b.currentTarget;a instanceof Element&&b instanceof Element&&a!==b||(null===d||void 0===d?void 0:d())}} | ||
var DEFAULT_STATE={active:!1,queue:[],forkedQueue:[]},DEFAULT_PARAMS={id:0,closable:!0,weak:!1,fork:!1},modalPrivate={dispatch:function(){throw Error("ModalError: no containers were found");}},Modal=function(){function d(){}d.open=function(b,a){var c=function(){},e=new Promise(function(g){return c=g}),f={component:b,params:__assign(__assign(__assign({},DEFAULT_PARAMS),{id:Date.now()}),a),close:function(){c();d.remove(f)}};d.add(f);return{promise:e,window:f}};d.replace=function(b){for(var a=[],c=1;c< | ||
arguments.length;c++)a[c-1]=arguments[c];a=__read(a,1)[0];modalPrivate.dispatch(function(e){return __assign(__assign({},e),{queue:e.queue.slice(0,-1)})});return d.open(b,a)};d.add=function(b){b.params.fork?modalPrivate.dispatch(function(a){return __assign(__assign({},a),{forkedQueue:__spreadArray(__spreadArray([],__read(a.forkedQueue),!1),[b],!1)})}):modalPrivate.dispatch(function(a){var c;return(null===(c=b.params)||void 0===c||!c.weak)&&0<a.queue.length&&(c=a.queue[a.queue.length-1],serialize(c.params)=== | ||
serialize(b.params)&&c.component===b.component)?__assign(__assign({},a),{active:!0,queue:[b]}):!1===a.active&&1===a.queue.length?__assign(__assign({},a),{active:!0,queue:[b]}):__assign(__assign({},a),{active:!0,queue:__spreadArray(__spreadArray([],__read(a.queue),!1),[b],!1)})})};d.remove=function(b){b.params.fork?modalPrivate.dispatch(function(a){var c=a.forkedQueue.filter(function(e){return e!==b});return __assign(__assign({},a),{forkedQueue:c})}):modalPrivate.dispatch(function(a){var c=a.queue.filter(function(e){return e!== | ||
b});return b.params.weak||0!==c.length?__assign(__assign({},a),{queue:c,active:!1}):__assign(__assign({},a),{active:!1,queue:[b]})})};d.closeAll=function(){modalPrivate.dispatch(function(b){b.queue.forEach(function(a){return a.close()});return DEFAULT_STATE})};return d}(),modalContext=react.createContext(null),ModalContainer=function(d){function b(a){a=d.call(this,a)||this;a.state={active:!1,queue:[],forkedQueue:[]};modalPrivate.dispatch=a.setState.bind(a);return a}__extends(b,d);Object.defineProperty(b.prototype, | ||
"className",{get:function(){return this.props.className||"modal"},enumerable:!1,configurable:!0});b.prototype.render=function(){var a,c,e=this.state,f=e.active;e=e.queue;e=e[e.length-1];var g=(null===(a=null===e||void 0===e?void 0:e.params)||void 0===a?0:a.closable)?stopPropagation(close):void 0;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",__assign({className:classWithModifiers(this.className,f&&"active"),"aria-modal":!0,"aria-hidden":!f},{children:jsxRuntime.jsx("div", | ||
__assign({className:this.className+"__container",onClick:g},{children:jsxRuntime.jsx(modalContext.Provider,__assign({value:e||null},{children:(null===e||void 0===e?void 0:e.component)&&jsxRuntime.jsx(e.component,__assign({},e.params))}))}))}),null===(c=null===e||void 0===e?void 0:e.params)||void 0===c?void 0:c.id),this.renderForks()]})};b.prototype.renderForks=function(){var a=this;return this.state.forkedQueue.map(function(c){var e;return jsxRuntime.jsx("div",__assign({className:a.className,"aria-modal":!0}, | ||
{children:jsxRuntime.jsx("div",__assign({className:a.className+"__container",onClick:(null===(e=c.params)||void 0===e?0:e.closable)?stopPropagation(c.close):void 0},{children:jsxRuntime.jsx(modalContext.Provider,__assign({value:c},{children:jsxRuntime.jsx(c.component,__assign({},c.params))}))}))}),c.params.id)})};return b}(react.Component);function useModalContext(){var d=react.useContext(modalContext);if(!d)throw Error("ModalError: Out of Modal context");return d}exports.Modal=Modal; | ||
exports.ModalContainer=ModalContainer;exports.useModalContext=useModalContext | ||
var DEFAULT_STATE={active:!1,queue:[],forkedQueue:[]},DEFAULT_PARAMS={id:0,closable:!0,weak:!1,fork:!1},modalPrivate={dispatch:function(){throw Error("ModalError: no containers were found");}},Modal=function(){function d(){}d.open=function(b){for(var a=[],c=1;c<arguments.length;c++)a[c-1]=arguments[c];a=__read(a,1)[0];var e=function(){};c=new Promise(function(g){return e=g});var f={component:b,params:__assign(__assign(__assign({},DEFAULT_PARAMS),{id:Date.now()}),a),close:function(){e();d.remove(f)}}; | ||
d.add(f);return{promise:c,window:f}};d.replace=function(b){for(var a=[],c=1;c<arguments.length;c++)a[c-1]=arguments[c];a=__read(a,1)[0];modalPrivate.dispatch(function(e){return __assign(__assign({},e),{queue:e.queue.slice(0,-1)})});return d.open(b,a)};d.add=function(b){b.params.fork?modalPrivate.dispatch(function(a){return __assign(__assign({},a),{forkedQueue:__spreadArray(__spreadArray([],__read(a.forkedQueue),!1),[b],!1)})}):modalPrivate.dispatch(function(a){var c;return(null===(c=b.params)||void 0=== | ||
c||!c.weak)&&0<a.queue.length&&(c=a.queue[a.queue.length-1],serialize(c.params)===serialize(b.params)&&c.component===b.component)?__assign(__assign({},a),{active:!0,queue:[b]}):!1===a.active&&1===a.queue.length?__assign(__assign({},a),{active:!0,queue:[b]}):__assign(__assign({},a),{active:!0,queue:__spreadArray(__spreadArray([],__read(a.queue),!1),[b],!1)})})};d.remove=function(b){b.params.fork?modalPrivate.dispatch(function(a){var c=a.forkedQueue.filter(function(e){return e!==b});return __assign(__assign({}, | ||
a),{forkedQueue:c})}):modalPrivate.dispatch(function(a){var c=a.queue.filter(function(e){return e!==b});return b.params.weak||0!==c.length?__assign(__assign({},a),{queue:c,active:!1}):__assign(__assign({},a),{active:!1,queue:[b]})})};d.closeAll=function(){modalPrivate.dispatch(function(b){b.queue.forEach(function(a){return a.close()});return DEFAULT_STATE})};return d}(),modalContext=react.createContext(null),ModalContainer=function(d){function b(a){a=d.call(this,a)||this;a.state={active:!1,queue:[], | ||
forkedQueue:[]};modalPrivate.dispatch=a.setState.bind(a);return a}__extends(b,d);Object.defineProperty(b.prototype,"className",{get:function(){return this.props.className||"modal"},enumerable:!1,configurable:!0});b.prototype.render=function(){var a,c,e=this.state,f=e.active;e=e.queue;e=e[e.length-1];var g=(null===(a=null===e||void 0===e?void 0:e.params)||void 0===a?0:a.closable)?stopPropagation(close):void 0;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",__assign({className:classWithModifiers(this.className, | ||
f&&"active"),"aria-modal":!0,"aria-hidden":!f},{children:jsxRuntime.jsx("div",__assign({className:this.className+"__container",onClick:g},{children:jsxRuntime.jsx(modalContext.Provider,__assign({value:e||null},{children:(null===e||void 0===e?void 0:e.component)&&jsxRuntime.jsx(e.component,__assign({},e.params))}))}))}),null===(c=null===e||void 0===e?void 0:e.params)||void 0===c?void 0:c.id),this.renderForks()]})};b.prototype.renderForks=function(){var a=this;return this.state.forkedQueue.map(function(c){var e; | ||
return jsxRuntime.jsx("div",__assign({className:a.className,"aria-modal":!0},{children:jsxRuntime.jsx("div",__assign({className:a.className+"__container",onClick:(null===(e=c.params)||void 0===e?0:e.closable)?stopPropagation(c.close):void 0},{children:jsxRuntime.jsx(modalContext.Provider,__assign({value:c},{children:jsxRuntime.jsx(c.component,__assign({},c.params))}))}))}),c.params.id)})};return b}(react.Component); | ||
function useModalContext(){var d=react.useContext(modalContext);if(!d)throw Error("ModalError: Out of Modal context");return d}exports.Modal=Modal;exports.ModalContainer=ModalContainer;exports.useModalContext=useModalContext |
{ | ||
"name": "react-modal-global", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"description": "React Modal but Global", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13453
80
4