mui-modal-provider
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -172,2 +172,3 @@ 'use strict'; | ||
var _excluded = ["open"]; | ||
function ModalProvider(_ref) { | ||
@@ -183,3 +184,3 @@ var children = _ref.children, | ||
var _update = React__default.useCallback(function (id, _ref2) { | ||
var props = _objectWithoutPropertiesLoose(_ref2, ["open"]); | ||
var props = _objectWithoutPropertiesLoose(_ref2, _excluded); | ||
@@ -293,7 +294,7 @@ if (!id) { | ||
if (props === null || props === void 0 ? void 0 : props.onExited) { | ||
if (props != null && props.onExited) { | ||
props.onExited.apply(props, arguments); | ||
} | ||
if (props === null || props === void 0 ? void 0 : (_props$TransitionProp = props.TransitionProps) === null || _props$TransitionProp === void 0 ? void 0 : _props$TransitionProp.onExited) { | ||
if (props != null && (_props$TransitionProp = props.TransitionProps) != null && _props$TransitionProp.onExited) { | ||
var _props$TransitionProp2; | ||
@@ -311,3 +312,3 @@ | ||
extraProps = { | ||
TransitionProps: _extends({}, props === null || props === void 0 ? void 0 : props.TransitionProps, { | ||
TransitionProps: _extends({}, props == null ? void 0 : props.TransitionProps, { | ||
onExited: handleExited | ||
@@ -341,2 +342,3 @@ }) | ||
var _excluded$1 = ["showModal", "destroyModalsByRootId"]; | ||
var defaultOptions = { | ||
@@ -356,3 +358,3 @@ disableAutoDestroy: false | ||
destroy = _useContext.destroyModalsByRootId, | ||
otherContextProps = _objectWithoutPropertiesLoose(_useContext, ["showModal", "destroyModalsByRootId"]); | ||
otherContextProps = _objectWithoutPropertiesLoose(_useContext, _excluded$1); | ||
@@ -359,0 +361,0 @@ var id = React.useRef(uid(6)); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o,e,t=require("react"),n=(o=t)&&"object"==typeof o&&"default"in o?o.default:o;function r(){return(r=Object.assign||function(o){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n])}return o}).apply(this,arguments)}function a(o,e){if(null==o)return{};var t,n,r={},a=Object.keys(o);for(n=0;n<a.length;n++)e.indexOf(t=a[n])>=0||(r[t]=o[t]);return r}!function(o){o.SHOW="SHOW",o.HIDE="HIDE",o.UPDATE="UPDATE",o.DESTROY="DESTROY",o.DESTROY_BY_ROOT_ID="DESTROY_BY_ROOT_ID",o.UNKNOWN="UNKNOWN"}(e||(e={}));var i={};function s(o,t){switch(t.type){case e.SHOW:var n,a=t.payload,i=a.options;return r({},o,((n={})[a.id]={component:a.component,props:r({},a.props,{open:!0}),options:i},n));case e.HIDE:var s,d=t.payload.id;return o[d]?r({},o,((s={})[d]=r({},o[d],{props:r({},o[d].props,{open:!1})}),s)):o;case e.UPDATE:var u,l=t.payload,c=l.id;return o[c]?r({},o,((u={})[c]=r({},o[c],{props:r({},o[c].props,l.props)}),u)):o;case e.DESTROY:var p=t.payload.id,f=r({},o);return delete f[p],f;case e.DESTROY_BY_ROOT_ID:var y=t.payload.rootId;return Object.keys(o).filter((function(o){return o.split(".")[0]!==y})).reduce((function(e,t){var n;return r({},e,((n={})[t]=o[t],n))}),{});default:throw new Error("Unexpected action")}}var d=t.createContext({state:i,hideModal:function(){},showModal:function(){return{id:"id",hide:function(){},destroy:function(){},update:function(){}}},destroyModal:function(){},updateModal:function(){},destroyModalsByRootId:function(){}}),u=function(o){void 0===o&&(o=8);for(var e=[],t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=t.length,r=0;r<o;r++)e[r]=t.charAt(Math.floor(Math.random()*n));return e.join("")},l={disableAutoDestroy:!1};exports.default=function(o){var t=o.children,l=o.legacy,c=void 0!==l&&l,p=n.useReducer(s,i),f=p[0],y=p[1],O=n.useCallback((function(o,t){var n=a(t,["open"]);o?y({type:e.UPDATE,payload:{id:o,props:n}}):console.error("[ERROR]: Modal ID is missing")}),[y]),v=n.useCallback((function(o){o?y({type:e.HIDE,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[y]),E=n.useCallback((function(o){o?y({type:e.DESTROY,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[y]),R=n.useCallback((function(o){o?y({type:e.DESTROY_BY_ROOT_ID,payload:{rootId:o}}):console.error("[ERROR]: Modal root ID is missing")}),[y]),D=n.useCallback((function(o,t,n){var r=u(8);return n&&n.rootId&&(r=n.rootId+"."+r),y({type:e.SHOW,payload:{id:r,component:o,props:t,options:n}}),{id:r,hide:function(){return v(r)},destroy:function(){return E(r)},update:function(o){return O(r,o)}}}),[y,v,E,O]);return n.createElement(d.Provider,{value:{state:f,updateModal:O,hideModal:v,destroyModal:E,showModal:D,destroyModalsByRootId:R}},t,Object.keys(f).map((function(o){var e,t=f[o],a=t.component,i=t.props,s=t.options,d=function(){var e,t;(null==i?void 0:i.onExited)&&i.onExited.apply(i,arguments),(null==i||null===(e=i.TransitionProps)||void 0===e?void 0:e.onExited)&&(t=i.TransitionProps).onExited.apply(t,arguments),E(o)};return e=c?{onExited:d}:{TransitionProps:r({},null==i?void 0:i.TransitionProps,{onExited:d})},n.createElement(a,Object.assign({},i,{key:o,onClose:function(){s&&s.destroyOnClose?E(o):v(o),i&&i.onClose&&i.onClose.apply(i,arguments)}},s&&!s.destroyOnClose&&e))})))},exports.useModal=function(o){void 0===o&&(o=l);var e=r({},l,o).disableAutoDestroy,n=t.useContext(d),i=n.showModal,s=n.destroyModalsByRootId,c=a(n,["showModal","destroyModalsByRootId"]),p=t.useRef(u(6));return t.useEffect((function(){return function(){e||s(p.current)}}),[e,s]),r({showModal:t.useCallback((function(o,e,t){return i(o,e,r({rootId:p.current},t))}),[i])},c)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o,e,t=require("react"),n=(o=t)&&"object"==typeof o&&"default"in o?o.default:o;function r(){return(r=Object.assign||function(o){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n])}return o}).apply(this,arguments)}function a(o,e){if(null==o)return{};var t,n,r={},a=Object.keys(o);for(n=0;n<a.length;n++)e.indexOf(t=a[n])>=0||(r[t]=o[t]);return r}!function(o){o.SHOW="SHOW",o.HIDE="HIDE",o.UPDATE="UPDATE",o.DESTROY="DESTROY",o.DESTROY_BY_ROOT_ID="DESTROY_BY_ROOT_ID",o.UNKNOWN="UNKNOWN"}(e||(e={}));var s={};function i(o,t){switch(t.type){case e.SHOW:var n,a=t.payload,s=a.options;return r({},o,((n={})[a.id]={component:a.component,props:r({},a.props,{open:!0}),options:s},n));case e.HIDE:var i,d=t.payload.id;return o[d]?r({},o,((i={})[d]=r({},o[d],{props:r({},o[d].props,{open:!1})}),i)):o;case e.UPDATE:var u,l=t.payload,c=l.id;return o[c]?r({},o,((u={})[c]=r({},o[c],{props:r({},o[c].props,l.props)}),u)):o;case e.DESTROY:var p=t.payload.id,f=r({},o);return delete f[p],f;case e.DESTROY_BY_ROOT_ID:var y=t.payload.rootId;return Object.keys(o).filter((function(o){return o.split(".")[0]!==y})).reduce((function(e,t){var n;return r({},e,((n={})[t]=o[t],n))}),{});default:throw new Error("Unexpected action")}}var d=t.createContext({state:s,hideModal:function(){},showModal:function(){return{id:"id",hide:function(){},destroy:function(){},update:function(){}}},destroyModal:function(){},updateModal:function(){},destroyModalsByRootId:function(){}}),u=function(o){void 0===o&&(o=8);for(var e=[],t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=t.length,r=0;r<o;r++)e[r]=t.charAt(Math.floor(Math.random()*n));return e.join("")},l=["open"],c=["showModal","destroyModalsByRootId"],p={disableAutoDestroy:!1};exports.default=function(o){var t=o.children,c=o.legacy,p=void 0!==c&&c,f=n.useReducer(i,s),y=f[0],O=f[1],E=n.useCallback((function(o,t){var n=a(t,l);o?O({type:e.UPDATE,payload:{id:o,props:n}}):console.error("[ERROR]: Modal ID is missing")}),[O]),R=n.useCallback((function(o){o?O({type:e.HIDE,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[O]),v=n.useCallback((function(o){o?O({type:e.DESTROY,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[O]),D=n.useCallback((function(o){o?O({type:e.DESTROY_BY_ROOT_ID,payload:{rootId:o}}):console.error("[ERROR]: Modal root ID is missing")}),[O]),M=n.useCallback((function(o,t,n){var r=u(8);return n&&n.rootId&&(r=n.rootId+"."+r),O({type:e.SHOW,payload:{id:r,component:o,props:t,options:n}}),{id:r,hide:function(){return R(r)},destroy:function(){return v(r)},update:function(o){return E(r,o)}}}),[O,R,v,E]);return n.createElement(d.Provider,{value:{state:y,updateModal:E,hideModal:R,destroyModal:v,showModal:M,destroyModalsByRootId:D}},t,Object.keys(y).map((function(o){var e,t=y[o],a=t.component,s=t.props,i=t.options,d=function(){var e,t;null!=s&&s.onExited&&s.onExited.apply(s,arguments),null!=s&&null!=(e=s.TransitionProps)&&e.onExited&&(t=s.TransitionProps).onExited.apply(t,arguments),v(o)};return e=p?{onExited:d}:{TransitionProps:r({},null==s?void 0:s.TransitionProps,{onExited:d})},n.createElement(a,Object.assign({},s,{key:o,onClose:function(){i&&i.destroyOnClose?v(o):R(o),s&&s.onClose&&s.onClose.apply(s,arguments)}},i&&!i.destroyOnClose&&e))})))},exports.useModal=function(o){void 0===o&&(o=p);var e=r({},p,o).disableAutoDestroy,n=t.useContext(d),s=n.showModal,i=n.destroyModalsByRootId,l=a(n,c),f=t.useRef(u(6));return t.useEffect((function(){return function(){e||i(f.current)}}),[e,i]),r({showModal:t.useCallback((function(o,e,t){return s(o,e,r({rootId:f.current},t))}),[s])},l)}; | ||
//# sourceMappingURL=mui-modal-provider.cjs.production.min.js.map |
@@ -165,2 +165,3 @@ import React, { createContext, useContext, useRef, useEffect, useCallback } from 'react'; | ||
var _excluded = ["open"]; | ||
function ModalProvider(_ref) { | ||
@@ -176,3 +177,3 @@ var children = _ref.children, | ||
var _update = React.useCallback(function (id, _ref2) { | ||
var props = _objectWithoutPropertiesLoose(_ref2, ["open"]); | ||
var props = _objectWithoutPropertiesLoose(_ref2, _excluded); | ||
@@ -286,7 +287,7 @@ if (!id) { | ||
if (props === null || props === void 0 ? void 0 : props.onExited) { | ||
if (props != null && props.onExited) { | ||
props.onExited.apply(props, arguments); | ||
} | ||
if (props === null || props === void 0 ? void 0 : (_props$TransitionProp = props.TransitionProps) === null || _props$TransitionProp === void 0 ? void 0 : _props$TransitionProp.onExited) { | ||
if (props != null && (_props$TransitionProp = props.TransitionProps) != null && _props$TransitionProp.onExited) { | ||
var _props$TransitionProp2; | ||
@@ -304,3 +305,3 @@ | ||
extraProps = { | ||
TransitionProps: _extends({}, props === null || props === void 0 ? void 0 : props.TransitionProps, { | ||
TransitionProps: _extends({}, props == null ? void 0 : props.TransitionProps, { | ||
onExited: handleExited | ||
@@ -334,2 +335,3 @@ }) | ||
var _excluded$1 = ["showModal", "destroyModalsByRootId"]; | ||
var defaultOptions = { | ||
@@ -349,3 +351,3 @@ disableAutoDestroy: false | ||
destroy = _useContext.destroyModalsByRootId, | ||
otherContextProps = _objectWithoutPropertiesLoose(_useContext, ["showModal", "destroyModalsByRootId"]); | ||
otherContextProps = _objectWithoutPropertiesLoose(_useContext, _excluded$1); | ||
@@ -352,0 +354,0 @@ var id = useRef(uid(6)); |
@@ -1,6 +0,10 @@ | ||
import React from 'react'; | ||
import { ReactNode, FC } from 'react'; | ||
export declare const OnCloseEvent: Event; | ||
export declare const OnExitedEvent: Event; | ||
export declare const ModalProviderWrapper: React.FC; | ||
export declare const LegacyModalProviderWrapper: React.FC; | ||
export declare const ModalContextProviderWrapper: React.FC; | ||
interface Props { | ||
children: ReactNode; | ||
} | ||
export declare const ModalProviderWrapper: FC<Props>; | ||
export declare const LegacyModalProviderWrapper: FC<Props>; | ||
export declare const ModalContextProviderWrapper: FC<Props>; | ||
export {}; |
{ | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -89,5 +89,5 @@ "name": "mui-modal-provider", | ||
"peerDependencies": { | ||
"@types/react": "^16.8.6 || ^17.0.0", | ||
"react": "^16.8.0 || ^17.0.0", | ||
"react-dom": "^16.8.0 || ^17.0.0" | ||
"@types/react": "^16.8.6 || ^17.0.0 || ^18.0.0", | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0", | ||
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0" | ||
}, | ||
@@ -100,16 +100,17 @@ "peerDependenciesMeta": { | ||
"devDependencies": { | ||
"@testing-library/react": "^13.1.1", | ||
"@testing-library/react-hooks": "^8.0.0", | ||
"@types/jest": "^26.0.23", | ||
"@types/react": "^17.0.6", | ||
"@types/react-dom": "^17.0.6", | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/react": "^13.3.0", | ||
"@testing-library/react-hooks": "^8.0.1", | ||
"@types/jest": "^28.1.6", | ||
"@types/react": "^18.0.15", | ||
"@types/react-dom": "^18.0.6", | ||
"husky": "^4.2.5", | ||
"install-peers-cli": "^2.2.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"semantic-release": "^18.0.1", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.6.3" | ||
"typescript": "^4.7.4" | ||
} | ||
} |
@@ -20,3 +20,3 @@ # mui-modal-provider | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createRoot } from 'react-dom/client'; | ||
import ModalProvider, { useModal } from 'mui-modal-provider'; | ||
@@ -27,8 +27,8 @@ import Dialog, { DialogProps } from '@mui/material/Dialog'; | ||
type Props = DialogProps & { | ||
interface SimpleDialogProps extends DialogProps { | ||
title: string, | ||
}; | ||
// ✔️ create the dialog you want to use | ||
const SimpleDialog: React.FC<Props> = ({ title, ...props }) => ( | ||
// Create the dialog you want to use | ||
const SimpleDialog: React.FC<SimpleDialogProps> = ({ title, ...props }) => ( | ||
<Dialog {...props}> | ||
@@ -39,3 +39,3 @@ <DialogTitle>{title}</DialogTitle> | ||
// ✔️ use modal hook and show the dialog | ||
// Use modal hook and show the dialog | ||
const App = () => { | ||
@@ -55,8 +55,10 @@ const { showModal } = useModal(); | ||
// ✔️ wrap the app with modal provider | ||
ReactDOM.render( | ||
const container = document.getElementById('root'); | ||
const root = createRoot(container); | ||
// Wrap the app with modal provider | ||
root.render( | ||
<ModalProvider> | ||
<App /> | ||
</ModalProvider>, | ||
document.getElementById('root') | ||
</ModalProvider> | ||
); | ||
@@ -63,0 +65,0 @@ ``` |
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
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
83967
791
82
14