@mantine/modals 4.0.2 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/cjs/ConfirmModal.js +4 -4
  2. package/cjs/ConfirmModal.js.map +1 -1
  3. package/cjs/ModalsProvider.js +104 -47
  4. package/cjs/ModalsProvider.js.map +1 -1
  5. package/cjs/context.js +3 -11
  6. package/cjs/context.js.map +1 -1
  7. package/cjs/index.js +1 -1
  8. package/cjs/reducer.js +32 -0
  9. package/cjs/reducer.js.map +1 -0
  10. package/cjs/{use-modals.js → use-modals/use-modals.js} +2 -2
  11. package/cjs/use-modals/use-modals.js.map +1 -0
  12. package/esm/ConfirmModal.js +5 -5
  13. package/esm/ConfirmModal.js.map +1 -1
  14. package/esm/ModalsProvider.js +107 -50
  15. package/esm/ModalsProvider.js.map +1 -1
  16. package/esm/context.js +3 -11
  17. package/esm/context.js.map +1 -1
  18. package/esm/index.js +1 -1
  19. package/esm/reducer.js +28 -0
  20. package/esm/reducer.js.map +1 -0
  21. package/esm/{use-modals.js → use-modals/use-modals.js} +2 -2
  22. package/esm/use-modals/use-modals.js.map +1 -0
  23. package/lib/ConfirmModal.d.ts.map +1 -1
  24. package/lib/ModalsProvider.d.ts +1 -6
  25. package/lib/ModalsProvider.d.ts.map +1 -1
  26. package/lib/context.d.ts +11 -5
  27. package/lib/context.d.ts.map +1 -1
  28. package/lib/index.d.ts +3 -2
  29. package/lib/index.d.ts.map +1 -1
  30. package/lib/reducer.d.ts +19 -0
  31. package/lib/reducer.d.ts.map +1 -0
  32. package/lib/use-modals/use-modals.d.ts +2 -0
  33. package/lib/use-modals/use-modals.d.ts.map +1 -0
  34. package/lib/use-modals/use-modals.test.d.ts +2 -0
  35. package/lib/use-modals/use-modals.test.d.ts.map +1 -0
  36. package/package.json +3 -3
  37. package/cjs/use-modals.js.map +0 -1
  38. package/esm/use-modals.js.map +0 -1
  39. package/lib/use-modals.d.ts +0 -2
  40. package/lib/use-modals.d.ts.map +0 -1
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var core = require('@mantine/core');
7
- var context = require('./context.js');
7
+ var useModals = require('./use-modals/use-modals.js');
8
8
 
9
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
10
10
 
@@ -41,16 +41,16 @@ function ConfirmModal({
41
41
  onConfirm,
42
42
  children
43
43
  }) {
44
- const ctx = React.useContext(context.modalsContext);
44
+ const ctx = useModals.useModals();
45
45
  const handleCancel = (event) => {
46
46
  typeof (cancelProps == null ? void 0 : cancelProps.onClick) === "function" && (cancelProps == null ? void 0 : cancelProps.onClick(event));
47
47
  typeof onCancel === "function" && onCancel();
48
- closeOnCancel && (ctx == null ? void 0 : ctx.closeModal(id));
48
+ closeOnCancel && ctx.closeModal(id);
49
49
  };
50
50
  const handleConfirm = (event) => {
51
51
  typeof (confirmProps == null ? void 0 : confirmProps.onClick) === "function" && (confirmProps == null ? void 0 : confirmProps.onClick(event));
52
52
  typeof onConfirm === "function" && onConfirm();
53
- closeOnConfirm && (ctx == null ? void 0 : ctx.closeModal(id));
53
+ closeOnConfirm && ctx.closeModal(id);
54
54
  };
55
55
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, children && /* @__PURE__ */ React__default.createElement(core.Box, {
56
56
  mb: "md"
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmModal.js","sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { Button, Group, Box, ButtonProps, GroupProps } from '@mantine/core';\nimport { modalsContext, ConfirmLabels } from './context';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?(): void;\n onConfirm?(): void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps<'button'>;\n confirmProps?: ButtonProps<'button'>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels,\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const ctx = useContext(modalsContext);\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx?.closeModal(id);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx?.closeModal(id);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group position=\"right\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || labels.cancel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || labels.confirm}\n </Button>\n </Group>\n </>\n );\n}\n"],"names":["useContext","modalsContext","React","Box","Group","Button"],"mappings":";;;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,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AC,EAAE,CAAC,WAAW,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,kBAAkBH,cAAK,CAAC,aAAa,CAACG,WAAM,EAAE,aAAa,CAAC,cAAc,CAAC,EAAE,EAAE,YAAY,CAAC,EAAE;AAC3K,IAAI,OAAO,EAAE,aAAa;AAC1B,GAAG,CAAC,EAAE,CAAC,YAAY,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,YAAY,CAAC,QAAQ,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACnF;;;;"}
1
+ {"version":3,"file":"ConfirmModal.js","sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import React from 'react';\nimport { Button, Group, Box, ButtonProps, GroupProps } from '@mantine/core';\nimport { ConfirmLabels } from './context';\nimport { useModals } from './use-modals/use-modals';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?(): void;\n onConfirm?(): void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps<'button'>;\n confirmProps?: ButtonProps<'button'>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels,\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const ctx = useModals();\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx.closeModal(id);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx.closeModal(id);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group position=\"right\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || labels.cancel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || labels.confirm}\n </Button>\n </Group>\n </>\n );\n}\n"],"names":["useModals","React","Box","Group","Button"],"mappings":";;;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,IAAI,mBAAmB;AACzB,IAAI,KAAK,IAAI,IAAI,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;AAC7C,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,E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K,UAAU,IAAI,SAAS,EAAE,CAAC;AACnD,IAAI,cAAc,IAAI,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACzC,GAAG,CAAC;AACJ,EAAE,uBAAuBC,cAAK,CAAC,aAAa,CAACA,cAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,oBAAoBA,cAAK,CAAC,aAAa,CAACC,QAAG,EAAE;AACxH,IAAI,EAAE,EAAE,IAAI;AACZ,GAAG,EAAE,QAAQ,CAAC,kBAAkBD,cAAK,CAAC,aAAa,CAACE,UAAK,EAAE,cAAc,CAAC;AAC1E,IAAI,QAAQ,EAAE,OAAO;AACrB,GAAG,EAAE,UAAU,CAAC,kBAAkBF,cAAK,CAAC,aAAa,CAACG,WAAM,EAAE,aAAa,CAAC,cAAc,CAAC;AAC3F,IAAI,OAAO,EAAE,SAAS;AACtB,GAAG,EAAE,WAAW,CAAC,EAAE;AACnB,IAAI,OAAO,EAAE,YAAY;AACzB,GAAG,CAAC,EAAE,CAAC,WAAW,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,kBAAkBH,cAAK,CAAC,aAAa,CAACG,WAAM,EAAE,aAAa,CAAC,cAAc,CAAC,EAAE,EAAE,YAAY,CAAC,EAAE;AAC3K,IAAI,OAAO,EAAE,aAAa;AAC1B,GAAG,CAAC,EAAE,CAAC,YAAY,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,YAAY,CAAC,QAAQ,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACnF;;;;"}
@@ -7,6 +7,7 @@ var core = require('@mantine/core');
7
7
  var hooks = require('@mantine/hooks');
8
8
  var context = require('./context.js');
9
9
  var ConfirmModal = require('./ConfirmModal.js');
10
+ var reducer = require('./reducer.js');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
12
13
 
@@ -43,7 +44,7 @@ var __objRest = (source, exclude) => {
43
44
  }
44
45
  return target;
45
46
  };
46
- function extractConfirmModalProps(props) {
47
+ function separateConfirmModalProps(props) {
47
48
  if (!props) {
48
49
  return { confirmProps: {}, modalProps: {} };
49
50
  }
@@ -70,84 +71,140 @@ function extractConfirmModalProps(props) {
70
71
  "groupProps",
71
72
  "labels"
72
73
  ]);
73
- return __spreadValues({ id }, others);
74
+ return {
75
+ confirmProps: {
76
+ id,
77
+ children,
78
+ onCancel,
79
+ onConfirm,
80
+ closeOnConfirm,
81
+ closeOnCancel,
82
+ cancelProps,
83
+ confirmProps,
84
+ groupProps,
85
+ labels
86
+ },
87
+ modalProps: __spreadValues({
88
+ id
89
+ }, others)
90
+ };
74
91
  }
75
92
  function ModalsProvider({ children, modalProps, labels, modals }) {
76
- var _a;
77
- const [state, handlers] = hooks.useListState([]);
78
- const [currentModal, setCurrentModal] = React.useState({
79
- id: null,
80
- props: null,
81
- type: "content"
82
- });
93
+ const [state, dispatch] = React.useReducer(reducer.modalsReducer, { modals: [], current: null });
83
94
  const closeAll = (canceled) => {
84
- state.forEach((modal) => {
85
- var _a2, _b, _c, _d;
95
+ state.modals.forEach((modal) => {
96
+ var _a, _b, _c, _d;
86
97
  if (modal.type === "confirm" && canceled) {
87
- (_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2);
98
+ (_b = (_a = modal.props) == null ? void 0 : _a.onCancel) == null ? void 0 : _b.call(_a);
88
99
  }
89
100
  (_d = (_c = modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c);
90
101
  });
91
- handlers.setState([]);
102
+ dispatch({ type: "CLOSE_ALL" });
92
103
  };
93
104
  const openModal = (props) => {
94
105
  const id = props.id || hooks.randomId();
95
- handlers.append({ id, props, type: "content" });
96
- setCurrentModal({ id, props, type: "content" });
106
+ dispatch({
107
+ type: "OPEN",
108
+ payload: {
109
+ id,
110
+ type: "content",
111
+ props
112
+ }
113
+ });
97
114
  return id;
98
115
  };
99
116
  const openConfirmModal = (props) => {
100
117
  const id = props.id || hooks.randomId();
101
- handlers.append({ id, props, type: "confirm" });
102
- setCurrentModal({ id, props, type: "confirm" });
118
+ dispatch({
119
+ type: "OPEN",
120
+ payload: {
121
+ id,
122
+ type: "confirm",
123
+ props
124
+ }
125
+ });
103
126
  return id;
104
127
  };
105
128
  const openContextModal = (modal, props) => {
106
129
  const id = props.id || hooks.randomId();
107
- handlers.append({ id, props, type: "context", ctx: modal });
108
- setCurrentModal({ id, props, type: "context", ctx: modal });
130
+ dispatch({
131
+ type: "OPEN",
132
+ payload: {
133
+ id,
134
+ type: "context",
135
+ props,
136
+ ctx: modal
137
+ }
138
+ });
109
139
  return id;
110
140
  };
111
141
  const closeModal = (id, canceled) => {
112
- var _a2, _b, _c, _d;
113
- const index = state.findIndex((item) => item.id === id);
114
- if (state.length <= 1) {
142
+ var _a, _b, _c, _d;
143
+ if (state.modals.length <= 1) {
115
144
  closeAll(canceled);
116
- } else {
117
- const modal = state.find((item) => item.id === id);
118
- if ((modal == null ? void 0 : modal.type) === "confirm" && canceled) {
119
- (_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2);
120
- }
121
- (_d = (_c = modal == null ? void 0 : modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c);
122
- index !== -1 && handlers.remove(index);
123
- setCurrentModal(state[state.length - 2] || {
124
- id: null,
125
- props: null,
126
- type: "content"
127
- });
145
+ return;
128
146
  }
147
+ const modal = state.modals.find((item) => item.id === id);
148
+ if ((modal == null ? void 0 : modal.type) === "confirm" && canceled) {
149
+ (_b = (_a = modal.props) == null ? void 0 : _a.onCancel) == null ? void 0 : _b.call(_a);
150
+ }
151
+ (_d = (_c = modal == null ? void 0 : modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c);
152
+ dispatch({ type: "CLOSE", payload: modal.id });
129
153
  };
130
- const ContextModal = (currentModal == null ? void 0 : currentModal.type) === "context" ? modals[currentModal == null ? void 0 : currentModal.ctx] : () => null;
131
154
  const ctx = {
132
- modals: state,
155
+ modals: state.modals,
133
156
  openModal,
134
157
  openConfirmModal,
135
158
  openContextModal,
136
159
  closeModal,
137
160
  closeAll
138
161
  };
139
- const content = (currentModal == null ? void 0 : currentModal.type) === "context" ? /* @__PURE__ */ React__default.createElement(ContextModal, __spreadValues({
140
- context: ctx,
141
- id: currentModal == null ? void 0 : currentModal.id
142
- }, currentModal == null ? void 0 : currentModal.props)) : (currentModal == null ? void 0 : currentModal.type) === "confirm" ? /* @__PURE__ */ React__default.createElement(ConfirmModal.ConfirmModal, __spreadProps(__spreadValues({}, currentModal.props), {
143
- id: currentModal.id,
144
- labels: currentModal.props.labels || labels
145
- })) : (_a = currentModal == null ? void 0 : currentModal.props) == null ? void 0 : _a.children;
146
- return /* @__PURE__ */ React__default.createElement(context.modalsContext.Provider, {
162
+ const getCurrentModal = () => {
163
+ var _a;
164
+ switch ((_a = state.current) == null ? void 0 : _a.type) {
165
+ case "context": {
166
+ const _b = state.current.props, { innerProps } = _b, rest = __objRest(_b, ["innerProps"]);
167
+ const ContextModal = modals[state.current.ctx];
168
+ return {
169
+ modalProps: rest,
170
+ content: /* @__PURE__ */ React__default.createElement(ContextModal, {
171
+ innerProps,
172
+ context: ctx,
173
+ id: state.current.id
174
+ })
175
+ };
176
+ }
177
+ case "confirm": {
178
+ const { modalProps: separatedModalProps, confirmProps: separatedConfirmProps } = separateConfirmModalProps(state.current.props);
179
+ return {
180
+ modalProps: separatedModalProps,
181
+ content: /* @__PURE__ */ React__default.createElement(ConfirmModal.ConfirmModal, __spreadProps(__spreadValues({}, separatedConfirmProps), {
182
+ id: state.current.id,
183
+ labels: state.current.props.labels || labels
184
+ }))
185
+ };
186
+ }
187
+ case "content": {
188
+ const _c = state.current.props, { children: currentModalChildren } = _c, rest = __objRest(_c, ["children"]);
189
+ return {
190
+ modalProps: rest,
191
+ content: /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, currentModalChildren)
192
+ };
193
+ }
194
+ default: {
195
+ return {
196
+ modalProps: {},
197
+ content: null
198
+ };
199
+ }
200
+ }
201
+ };
202
+ const { modalProps: currentModalProps, content } = getCurrentModal();
203
+ return /* @__PURE__ */ React__default.createElement(context.ModalsContext.Provider, {
147
204
  value: ctx
148
- }, /* @__PURE__ */ React__default.createElement(core.Modal, __spreadProps(__spreadValues(__spreadValues({}, modalProps), (currentModal == null ? void 0 : currentModal.type) === "confirm" ? extractConfirmModalProps(currentModal == null ? void 0 : currentModal.props) : currentModal == null ? void 0 : currentModal.props), {
149
- opened: state.length > 0,
150
- onClose: () => closeModal(currentModal == null ? void 0 : currentModal.id, true)
205
+ }, /* @__PURE__ */ React__default.createElement(core.Modal, __spreadProps(__spreadValues(__spreadValues({}, modalProps), currentModalProps), {
206
+ opened: state.modals.length > 0,
207
+ onClose: () => closeModal(state.current.id)
151
208
  }), content), children);
152
209
  }
153
210
 
@@ -1 +1 @@
1
- {"version":3,"file":"ModalsProvider.js","sources":["../src/ModalsProvider.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { Modal } from '@mantine/core';\nimport { useListState, randomId } from '@mantine/hooks';\nimport {\n modalsContext,\n ModalsContext,\n ModalSettings,\n ConfirmLabels,\n OpenConfirmModal,\n OpenContextModal,\n ModalState,\n} from './context';\nimport { ConfirmModal } from './ConfirmModal';\n\nexport interface ContextModalProps {\n context: ModalsContext;\n props: Record<string, any>;\n id: string;\n}\n\nexport interface ModalsProviderProps {\n /** Your app */\n children: React.ReactNode;\n\n /** Predefined modals */\n modals?: Record<string, React.FC<ContextModalProps>>;\n\n /** Shared Modal component props, applied for every modal */\n modalProps?: ModalSettings;\n\n /** Confirm modal labels */\n labels?: ConfirmLabels;\n}\n\nfunction extractConfirmModalProps(props: OpenConfirmModal) {\n if (!props) {\n return { confirmProps: {}, modalProps: {} };\n }\n\n const {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...others\n } = props;\n\n return { id, ...others };\n}\n\nexport function ModalsProvider({ children, modalProps, labels, modals }: ModalsProviderProps) {\n const [state, handlers] = useListState<ModalState>([]);\n const [currentModal, setCurrentModal] = useState<ModalState>({\n id: null,\n props: null,\n type: 'content',\n });\n const closeAll = (canceled?: boolean) => {\n state.forEach((modal) => {\n if (modal.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n\n modal.props?.onClose?.();\n });\n handlers.setState([]);\n };\n\n const openModal = (props: ModalSettings) => {\n const id = props.id || randomId();\n handlers.append({ id, props, type: 'content' });\n setCurrentModal({ id, props, type: 'content' });\n return id;\n };\n\n const openConfirmModal = (props: OpenConfirmModal) => {\n const id = props.id || randomId();\n handlers.append({ id, props, type: 'confirm' });\n setCurrentModal({ id, props, type: 'confirm' });\n return id;\n };\n\n const openContextModal = (modal: string, props: OpenContextModal) => {\n const id = props.id || randomId();\n handlers.append({ id, props, type: 'context', ctx: modal });\n setCurrentModal({ id, props, type: 'context', ctx: modal });\n return id;\n };\n\n const closeModal = (id: string, canceled?: boolean) => {\n const index = state.findIndex((item) => item.id === id);\n if (state.length <= 1) {\n closeAll(canceled);\n } else {\n const modal = state.find((item) => item.id === id);\n if (modal?.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n modal?.props?.onClose?.();\n index !== -1 && handlers.remove(index);\n setCurrentModal(\n state[state.length - 2] || {\n id: null,\n props: null,\n type: 'content',\n }\n );\n }\n };\n\n const ContextModal = currentModal?.type === 'context' ? modals[currentModal?.ctx] : () => null;\n\n const ctx = {\n modals: state,\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeAll,\n };\n\n const content =\n currentModal?.type === 'context' ? (\n <ContextModal context={ctx} id={currentModal?.id} {...(currentModal?.props as any)} />\n ) : currentModal?.type === 'confirm' ? (\n <ConfirmModal\n {...currentModal.props}\n id={currentModal.id}\n labels={currentModal.props.labels || labels}\n />\n ) : (\n currentModal?.props?.children\n );\n\n return (\n <modalsContext.Provider value={ctx}>\n <Modal\n {...modalProps}\n {...(currentModal?.type === 'confirm'\n ? extractConfirmModalProps(currentModal?.props)\n : currentModal?.props)}\n opened={state.length > 0}\n onClose={() => closeModal(currentModal?.id, true)}\n >\n {content}\n </Modal>\n\n {children}\n </modalsContext.Provider>\n );\n}\n"],"names":["useListState","useState","randomId","React","ConfirmModal","modalsContext","Modal"],"mappings":";;;;;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,IAAI,mBAAmB;AACzB,IAAI,KAAK,IAAI,IAAI,IAAI,mB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}
1
+ {"version":3,"file":"ModalsProvider.js","sources":["../src/ModalsProvider.tsx"],"sourcesContent":["import React, { useReducer } from 'react';\nimport { Modal } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport {\n ModalsContext,\n ModalSettings,\n ConfirmLabels,\n OpenConfirmModal,\n OpenContextModal,\n ContextModalProps,\n ModalsContextProps,\n} from './context';\nimport { ConfirmModal } from './ConfirmModal';\nimport { modalsReducer } from './reducer';\n\nexport interface ModalsProviderProps {\n /** Your app */\n children: React.ReactNode;\n\n /** Predefined modals */\n modals?: Record<string, React.FC<ContextModalProps>>;\n\n /** Shared Modal component props, applied for every modal */\n modalProps?: ModalSettings;\n\n /** Confirm modal labels */\n labels?: ConfirmLabels;\n}\n\nfunction separateConfirmModalProps(props: OpenConfirmModal) {\n if (!props) {\n return { confirmProps: {}, modalProps: {} };\n }\n\n const {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...others\n } = props;\n\n return {\n confirmProps: {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n },\n modalProps: {\n id,\n ...others,\n },\n };\n}\n\nexport function ModalsProvider({ children, modalProps, labels, modals }: ModalsProviderProps) {\n const [state, dispatch] = useReducer(modalsReducer, { modals: [], current: null });\n const closeAll = (canceled?: boolean) => {\n state.modals.forEach((modal) => {\n if (modal.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n\n modal.props?.onClose?.();\n });\n dispatch({ type: 'CLOSE_ALL' });\n };\n\n const openModal = (props: ModalSettings) => {\n const id = props.id || randomId();\n dispatch({\n type: 'OPEN',\n payload: {\n id,\n type: 'content',\n props,\n },\n });\n return id;\n };\n\n const openConfirmModal = (props: OpenConfirmModal) => {\n const id = props.id || randomId();\n dispatch({\n type: 'OPEN',\n payload: {\n id,\n type: 'confirm',\n props,\n },\n });\n return id;\n };\n\n const openContextModal = (modal: string, props: OpenContextModal) => {\n const id = props.id || randomId();\n dispatch({\n type: 'OPEN',\n payload: {\n id,\n type: 'context',\n props,\n ctx: modal,\n },\n });\n return id;\n };\n\n const closeModal = (id: string, canceled?: boolean) => {\n if (state.modals.length <= 1) {\n closeAll(canceled);\n return;\n }\n\n const modal = state.modals.find((item) => item.id === id);\n if (modal?.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n modal?.props?.onClose?.();\n dispatch({ type: 'CLOSE', payload: modal.id });\n };\n\n const ctx: ModalsContextProps = {\n modals: state.modals,\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeAll,\n };\n\n const getCurrentModal = () => {\n switch (state.current?.type) {\n case 'context': {\n const { innerProps, ...rest } = state.current.props;\n const ContextModal = modals[state.current.ctx];\n\n return {\n modalProps: rest,\n content: <ContextModal innerProps={innerProps} context={ctx} id={state.current.id} />,\n };\n }\n case 'confirm': {\n const { modalProps: separatedModalProps, confirmProps: separatedConfirmProps } =\n separateConfirmModalProps(state.current.props);\n\n return {\n modalProps: separatedModalProps,\n content: (\n <ConfirmModal\n {...separatedConfirmProps}\n id={state.current.id}\n labels={state.current.props.labels || labels}\n />\n ),\n };\n }\n case 'content': {\n const { children: currentModalChildren, ...rest } = state.current.props;\n\n return {\n modalProps: rest,\n content: <>{currentModalChildren}</>,\n };\n }\n default: {\n return {\n modalProps: {},\n content: null,\n };\n }\n }\n };\n\n const { modalProps: currentModalProps, content } = getCurrentModal();\n\n return (\n <ModalsContext.Provider value={ctx}>\n <Modal\n {...modalProps}\n {...currentModalProps}\n opened={state.modals.length > 0}\n onClose={() => closeModal(state.current.id)}\n >\n {content}\n </Modal>\n\n {children}\n </ModalsContext.Provider>\n );\n}\n"],"names":["useReducer","modalsReducer","randomId","React","ConfirmModal","ModalsContext","Modal"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU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AAC;AAC1B;;;;"}
package/cjs/context.js CHANGED
@@ -4,16 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
 
7
- const modalsContext = React.createContext({
8
- modals: [],
9
- openModal: () => null,
10
- openConfirmModal: () => null,
11
- openContextModal: () => null,
12
- closeAll: () => {
13
- },
14
- closeModal: () => {
15
- }
16
- });
7
+ const ModalsContext = React.createContext(null);
8
+ ModalsContext.displayName = "@mantine/modals/ModalsContext";
17
9
 
18
- exports.modalsContext = modalsContext;
10
+ exports.ModalsContext = ModalsContext;
19
11
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>>;\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', string>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal extends ModalSettings {}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: Record<string, any>; type: 'context'; ctx: string };\n\nexport interface ModalsContext {\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: (modal: string, props: Record<string, any>) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeAll: () => void;\n}\n\nexport const modalsContext = createContext<ModalsContext>({\n modals: [],\n openModal: () => null,\n openConfirmModal: () => null,\n openContextModal: () => null,\n closeAll: () => {},\n closeModal: () => {},\n});\n"],"names":["createContext"],"mappings":";;;;;;AACY,MAAC,aAAa,GAAGA,mBAAa,CAAC;AAC3C,EAAE,MAAM,EAAE,EAAE;AACZ,EAAE,SAAS,EAAE,MAAM,IAAI;AACvB,EAAE,gBAAgB,EAAE,MAAM,IAAI;AAC9B,EAAE,gBAAgB,EAAE,MAAM,IAAI;AAC9B,EAAE,QAAQ,EAAE,MAAM;AAClB,GAAG;AACH,EAAE,UAAU,EAAE,MAAM;AACpB,GAAG;AACH,CAAC;;;;"}
1
+ {"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>>;\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', string>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal<CustomProps extends Record<string, unknown> = {}>\n extends ModalSettings {\n innerProps: CustomProps;\n}\n\nexport interface ContextModalProps<T extends Record<string, unknown> = {}> {\n context: ModalsContextProps;\n innerProps: T;\n id: string;\n}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: OpenContextModal; type: 'context'; ctx: string };\n\nexport interface ModalsContextProps {\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: <CustomProps extends Record<string, unknown>>(\n modal: string,\n props: OpenContextModal<CustomProps>\n ) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeAll: () => void;\n}\n\nexport const ModalsContext = createContext<ModalsContextProps>(null);\nModalsContext.displayName = '@mantine/modals/ModalsContext';\n"],"names":["createContext"],"mappings":";;;;;;AACY,MAAC,aAAa,GAAGA,mBAAa,CAAC,IAAI,EAAE;AACjD,aAAa,CAAC,WAAW,GAAG,+BAA+B;;;;"}
package/cjs/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ModalsProvider = require('./ModalsProvider.js');
6
- var useModals = require('./use-modals.js');
6
+ var useModals = require('./use-modals/use-modals.js');
7
7
 
8
8
 
9
9
 
package/cjs/reducer.js ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function modalsReducer(state, action) {
6
+ switch (action.type) {
7
+ case "OPEN": {
8
+ return {
9
+ current: action.payload,
10
+ modals: [...state.modals, action.payload]
11
+ };
12
+ }
13
+ case "CLOSE": {
14
+ return {
15
+ current: state.modals[state.modals.length - 2] || null,
16
+ modals: state.modals.filter((m) => m.id !== action.payload)
17
+ };
18
+ }
19
+ case "CLOSE_ALL": {
20
+ return {
21
+ current: state.current,
22
+ modals: []
23
+ };
24
+ }
25
+ default: {
26
+ return state;
27
+ }
28
+ }
29
+ }
30
+
31
+ exports.modalsReducer = modalsReducer;
32
+ //# sourceMappingURL=reducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.js","sources":["../src/reducer.ts"],"sourcesContent":["import { ModalState } from './context';\n\ninterface ModalsState {\n modals: ModalState[];\n current: ModalState | null;\n}\n\ninterface OpenAction {\n type: 'OPEN';\n payload: ModalState;\n}\n\ninterface CloseAction {\n type: 'CLOSE';\n payload: string;\n}\n\ninterface CloseAllAction {\n type: 'CLOSE_ALL';\n}\n\nexport function modalsReducer(\n state: ModalsState,\n action: OpenAction | CloseAction | CloseAllAction\n): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n return {\n current: action.payload,\n modals: [...state.modals, action.payload],\n };\n }\n case 'CLOSE': {\n return {\n current: state.modals[state.modals.length - 2] || null,\n modals: state.modals.filter((m) => m.id !== action.payload),\n };\n }\n case 'CLOSE_ALL': {\n return {\n current: state.current,\n modals: [],\n };\n }\n default: {\n return state;\n }\n }\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE;AAC7C,EAAE,QAAQ,MAAM,CAAC,IAAI;AACrB,IAAI,KAAK,MAAM,EAAE;AACjB,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,MAAM,CAAC,OAAO;AAC/B,QAAQ,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;AACjD,OAAO,CAAC;AACR,KAAK;AACL,IAAI,KAAK,OAAO,EAAE;AAClB,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI;AAC9D,QAAQ,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC;AACnE,OAAO,CAAC;AACR,KAAK;AACL,IAAI,KAAK,WAAW,EAAE;AACtB,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,KAAK,CAAC,OAAO;AAC9B,QAAQ,MAAM,EAAE,EAAE;AAClB,OAAO,CAAC;AACR,KAAK;AACL,IAAI,SAAS;AACb,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,GAAG;AACH;;;;"}
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var context = require('./context.js');
6
+ var context = require('../context.js');
7
7
 
8
8
  function useModals() {
9
- const ctx = React.useContext(context.modalsContext);
9
+ const ctx = React.useContext(context.ModalsContext);
10
10
  if (!ctx) {
11
11
  throw new Error("[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component");
12
12
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-modals.js","sources":["../../src/use-modals/use-modals.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { ModalsContext } from '../context';\n\nexport function useModals() {\n const ctx = useContext(ModalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"names":["useContext","ModalsContext"],"mappings":";;;;;;;AAEO,SAAS,SAAS,GAAG;AAC5B,EAAE,MAAM,GAAG,GAAGA,gBAAU,CAACC,qBAAa,CAAC,CAAC;AACxC,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,6GAA6G,CAAC,CAAC;AACnI,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
@@ -1,6 +1,6 @@
1
- import React, { useContext } from 'react';
1
+ import React from 'react';
2
2
  import { Box, Group, Button } from '@mantine/core';
3
- import { modalsContext } from './context.js';
3
+ import { useModals } from './use-modals/use-modals.js';
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defProps = Object.defineProperties;
@@ -33,16 +33,16 @@ function ConfirmModal({
33
33
  onConfirm,
34
34
  children
35
35
  }) {
36
- const ctx = useContext(modalsContext);
36
+ const ctx = useModals();
37
37
  const handleCancel = (event) => {
38
38
  typeof (cancelProps == null ? void 0 : cancelProps.onClick) === "function" && (cancelProps == null ? void 0 : cancelProps.onClick(event));
39
39
  typeof onCancel === "function" && onCancel();
40
- closeOnCancel && (ctx == null ? void 0 : ctx.closeModal(id));
40
+ closeOnCancel && ctx.closeModal(id);
41
41
  };
42
42
  const handleConfirm = (event) => {
43
43
  typeof (confirmProps == null ? void 0 : confirmProps.onClick) === "function" && (confirmProps == null ? void 0 : confirmProps.onClick(event));
44
44
  typeof onConfirm === "function" && onConfirm();
45
- closeOnConfirm && (ctx == null ? void 0 : ctx.closeModal(id));
45
+ closeOnConfirm && ctx.closeModal(id);
46
46
  };
47
47
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children && /* @__PURE__ */ React.createElement(Box, {
48
48
  mb: "md"
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmModal.js","sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { Button, Group, Box, ButtonProps, GroupProps } from '@mantine/core';\nimport { modalsContext, ConfirmLabels } from './context';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?(): void;\n onConfirm?(): void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps<'button'>;\n confirmProps?: ButtonProps<'button'>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels,\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const ctx = useContext(modalsContext);\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx?.closeModal(id);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx?.closeModal(id);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group position=\"right\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || labels.cancel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || labels.confirm}\n </Button>\n </Group>\n </>\n );\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,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;AAC3F,IAAI,OAAO,EAAE,SAAS;AACtB,GAAG,EAAE,WAAW,CAAC,EAAE;AACnB,IAAI,OAAO,EAAE,YAAY;AACzB,GAAG,CAAC,EAAE,CAAC,WAAW,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,kBAAkB,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,EAAE,EAAE,YAAY,CAAC,EAAE;AAC3K,IAAI,OAAO,EAAE,aAAa;AAC1B,GAAG,CAAC,EAAE,CAAC,YAAY,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,YAAY,CAAC,QAAQ,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACnF;;;;"}
1
+ {"version":3,"file":"ConfirmModal.js","sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import React from 'react';\nimport { Button, Group, Box, ButtonProps, GroupProps } from '@mantine/core';\nimport { ConfirmLabels } from './context';\nimport { useModals } from './use-modals/use-modals';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?(): void;\n onConfirm?(): void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps<'button'>;\n confirmProps?: ButtonProps<'button'>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels,\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const ctx = useModals();\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx.closeModal(id);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx.closeModal(id);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group position=\"right\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || labels.cancel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || labels.confirm}\n </Button>\n </Group>\n </>\n );\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,IAAI,mBAAmB;AACzB,IAAI,KAAK,IAAI,IAAI,IAAI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AAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAClJ,IAAI,OAAO,SAAS,KAAK,UAAU,IAAI,SAAS,EAAE,CAAC;AACnD,IAAI,cAAc,IAAI,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACzC,GAAG,CAAC;AACJ,EAAE,uBAAuB,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,oBAAoB,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE;AACxH,IAAI,EAAE,EAAE,IAAI;AACZ,GAAG,EAAE,QAAQ,CAAC,kBAAkB,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,cAAc,CAAC;AAC1E,IAAI,QAAQ,EAAE,OAAO;AACrB,GAAG,EAAE,UAAU,CAAC,kBAAkB,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC;AAC3F,IAAI,OAAO,EAAE,SAAS;AACtB,GAAG,EAAE,WAAW,CAAC,EAAE;AACnB,IAAI,OAAO,EAAE,YAAY;AACzB,GAAG,CAAC,EAAE,CAAC,WAAW,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,kBAAkB,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,EAAE,EAAE,YAAY,CAAC,EAAE;AAC3K,IAAI,OAAO,EAAE,aAAa;AAC1B,GAAG,CAAC,EAAE,CAAC,YAAY,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,YAAY,CAAC,QAAQ,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACnF;;;;"}
@@ -1,8 +1,9 @@
1
- import React, { useState } from 'react';
1
+ import React, { useReducer } from 'react';
2
2
  import { Modal } from '@mantine/core';
3
- import { useListState, randomId } from '@mantine/hooks';
4
- import { modalsContext } from './context.js';
3
+ import { randomId } from '@mantine/hooks';
4
+ import { ModalsContext } from './context.js';
5
5
  import { ConfirmModal } from './ConfirmModal.js';
6
+ import { modalsReducer } from './reducer.js';
6
7
 
7
8
  var __defProp = Object.defineProperty;
8
9
  var __defProps = Object.defineProperties;
@@ -35,7 +36,7 @@ var __objRest = (source, exclude) => {
35
36
  }
36
37
  return target;
37
38
  };
38
- function extractConfirmModalProps(props) {
39
+ function separateConfirmModalProps(props) {
39
40
  if (!props) {
40
41
  return { confirmProps: {}, modalProps: {} };
41
42
  }
@@ -62,84 +63,140 @@ function extractConfirmModalProps(props) {
62
63
  "groupProps",
63
64
  "labels"
64
65
  ]);
65
- return __spreadValues({ id }, others);
66
+ return {
67
+ confirmProps: {
68
+ id,
69
+ children,
70
+ onCancel,
71
+ onConfirm,
72
+ closeOnConfirm,
73
+ closeOnCancel,
74
+ cancelProps,
75
+ confirmProps,
76
+ groupProps,
77
+ labels
78
+ },
79
+ modalProps: __spreadValues({
80
+ id
81
+ }, others)
82
+ };
66
83
  }
67
84
  function ModalsProvider({ children, modalProps, labels, modals }) {
68
- var _a;
69
- const [state, handlers] = useListState([]);
70
- const [currentModal, setCurrentModal] = useState({
71
- id: null,
72
- props: null,
73
- type: "content"
74
- });
85
+ const [state, dispatch] = useReducer(modalsReducer, { modals: [], current: null });
75
86
  const closeAll = (canceled) => {
76
- state.forEach((modal) => {
77
- var _a2, _b, _c, _d;
87
+ state.modals.forEach((modal) => {
88
+ var _a, _b, _c, _d;
78
89
  if (modal.type === "confirm" && canceled) {
79
- (_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2);
90
+ (_b = (_a = modal.props) == null ? void 0 : _a.onCancel) == null ? void 0 : _b.call(_a);
80
91
  }
81
92
  (_d = (_c = modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c);
82
93
  });
83
- handlers.setState([]);
94
+ dispatch({ type: "CLOSE_ALL" });
84
95
  };
85
96
  const openModal = (props) => {
86
97
  const id = props.id || randomId();
87
- handlers.append({ id, props, type: "content" });
88
- setCurrentModal({ id, props, type: "content" });
98
+ dispatch({
99
+ type: "OPEN",
100
+ payload: {
101
+ id,
102
+ type: "content",
103
+ props
104
+ }
105
+ });
89
106
  return id;
90
107
  };
91
108
  const openConfirmModal = (props) => {
92
109
  const id = props.id || randomId();
93
- handlers.append({ id, props, type: "confirm" });
94
- setCurrentModal({ id, props, type: "confirm" });
110
+ dispatch({
111
+ type: "OPEN",
112
+ payload: {
113
+ id,
114
+ type: "confirm",
115
+ props
116
+ }
117
+ });
95
118
  return id;
96
119
  };
97
120
  const openContextModal = (modal, props) => {
98
121
  const id = props.id || randomId();
99
- handlers.append({ id, props, type: "context", ctx: modal });
100
- setCurrentModal({ id, props, type: "context", ctx: modal });
122
+ dispatch({
123
+ type: "OPEN",
124
+ payload: {
125
+ id,
126
+ type: "context",
127
+ props,
128
+ ctx: modal
129
+ }
130
+ });
101
131
  return id;
102
132
  };
103
133
  const closeModal = (id, canceled) => {
104
- var _a2, _b, _c, _d;
105
- const index = state.findIndex((item) => item.id === id);
106
- if (state.length <= 1) {
134
+ var _a, _b, _c, _d;
135
+ if (state.modals.length <= 1) {
107
136
  closeAll(canceled);
108
- } else {
109
- const modal = state.find((item) => item.id === id);
110
- if ((modal == null ? void 0 : modal.type) === "confirm" && canceled) {
111
- (_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2);
112
- }
113
- (_d = (_c = modal == null ? void 0 : modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c);
114
- index !== -1 && handlers.remove(index);
115
- setCurrentModal(state[state.length - 2] || {
116
- id: null,
117
- props: null,
118
- type: "content"
119
- });
137
+ return;
120
138
  }
139
+ const modal = state.modals.find((item) => item.id === id);
140
+ if ((modal == null ? void 0 : modal.type) === "confirm" && canceled) {
141
+ (_b = (_a = modal.props) == null ? void 0 : _a.onCancel) == null ? void 0 : _b.call(_a);
142
+ }
143
+ (_d = (_c = modal == null ? void 0 : modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c);
144
+ dispatch({ type: "CLOSE", payload: modal.id });
121
145
  };
122
- const ContextModal = (currentModal == null ? void 0 : currentModal.type) === "context" ? modals[currentModal == null ? void 0 : currentModal.ctx] : () => null;
123
146
  const ctx = {
124
- modals: state,
147
+ modals: state.modals,
125
148
  openModal,
126
149
  openConfirmModal,
127
150
  openContextModal,
128
151
  closeModal,
129
152
  closeAll
130
153
  };
131
- const content = (currentModal == null ? void 0 : currentModal.type) === "context" ? /* @__PURE__ */ React.createElement(ContextModal, __spreadValues({
132
- context: ctx,
133
- id: currentModal == null ? void 0 : currentModal.id
134
- }, currentModal == null ? void 0 : currentModal.props)) : (currentModal == null ? void 0 : currentModal.type) === "confirm" ? /* @__PURE__ */ React.createElement(ConfirmModal, __spreadProps(__spreadValues({}, currentModal.props), {
135
- id: currentModal.id,
136
- labels: currentModal.props.labels || labels
137
- })) : (_a = currentModal == null ? void 0 : currentModal.props) == null ? void 0 : _a.children;
138
- return /* @__PURE__ */ React.createElement(modalsContext.Provider, {
154
+ const getCurrentModal = () => {
155
+ var _a;
156
+ switch ((_a = state.current) == null ? void 0 : _a.type) {
157
+ case "context": {
158
+ const _b = state.current.props, { innerProps } = _b, rest = __objRest(_b, ["innerProps"]);
159
+ const ContextModal = modals[state.current.ctx];
160
+ return {
161
+ modalProps: rest,
162
+ content: /* @__PURE__ */ React.createElement(ContextModal, {
163
+ innerProps,
164
+ context: ctx,
165
+ id: state.current.id
166
+ })
167
+ };
168
+ }
169
+ case "confirm": {
170
+ const { modalProps: separatedModalProps, confirmProps: separatedConfirmProps } = separateConfirmModalProps(state.current.props);
171
+ return {
172
+ modalProps: separatedModalProps,
173
+ content: /* @__PURE__ */ React.createElement(ConfirmModal, __spreadProps(__spreadValues({}, separatedConfirmProps), {
174
+ id: state.current.id,
175
+ labels: state.current.props.labels || labels
176
+ }))
177
+ };
178
+ }
179
+ case "content": {
180
+ const _c = state.current.props, { children: currentModalChildren } = _c, rest = __objRest(_c, ["children"]);
181
+ return {
182
+ modalProps: rest,
183
+ content: /* @__PURE__ */ React.createElement(React.Fragment, null, currentModalChildren)
184
+ };
185
+ }
186
+ default: {
187
+ return {
188
+ modalProps: {},
189
+ content: null
190
+ };
191
+ }
192
+ }
193
+ };
194
+ const { modalProps: currentModalProps, content } = getCurrentModal();
195
+ return /* @__PURE__ */ React.createElement(ModalsContext.Provider, {
139
196
  value: ctx
140
- }, /* @__PURE__ */ React.createElement(Modal, __spreadProps(__spreadValues(__spreadValues({}, modalProps), (currentModal == null ? void 0 : currentModal.type) === "confirm" ? extractConfirmModalProps(currentModal == null ? void 0 : currentModal.props) : currentModal == null ? void 0 : currentModal.props), {
141
- opened: state.length > 0,
142
- onClose: () => closeModal(currentModal == null ? void 0 : currentModal.id, true)
197
+ }, /* @__PURE__ */ React.createElement(Modal, __spreadProps(__spreadValues(__spreadValues({}, modalProps), currentModalProps), {
198
+ opened: state.modals.length > 0,
199
+ onClose: () => closeModal(state.current.id)
143
200
  }), content), children);
144
201
  }
145
202
 
@@ -1 +1 @@
1
- {"version":3,"file":"ModalsProvider.js","sources":["../src/ModalsProvider.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { Modal } from '@mantine/core';\nimport { useListState, randomId } from '@mantine/hooks';\nimport {\n modalsContext,\n ModalsContext,\n ModalSettings,\n ConfirmLabels,\n OpenConfirmModal,\n OpenContextModal,\n ModalState,\n} from './context';\nimport { ConfirmModal } from './ConfirmModal';\n\nexport interface ContextModalProps {\n context: ModalsContext;\n props: Record<string, any>;\n id: string;\n}\n\nexport interface ModalsProviderProps {\n /** Your app */\n children: React.ReactNode;\n\n /** Predefined modals */\n modals?: Record<string, React.FC<ContextModalProps>>;\n\n /** Shared Modal component props, applied for every modal */\n modalProps?: ModalSettings;\n\n /** Confirm modal labels */\n labels?: ConfirmLabels;\n}\n\nfunction extractConfirmModalProps(props: OpenConfirmModal) {\n if (!props) {\n return { confirmProps: {}, modalProps: {} };\n }\n\n const {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...others\n } = props;\n\n return { id, ...others };\n}\n\nexport function ModalsProvider({ children, modalProps, labels, modals }: ModalsProviderProps) {\n const [state, handlers] = useListState<ModalState>([]);\n const [currentModal, setCurrentModal] = useState<ModalState>({\n id: null,\n props: null,\n type: 'content',\n });\n const closeAll = (canceled?: boolean) => {\n state.forEach((modal) => {\n if (modal.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n\n modal.props?.onClose?.();\n });\n handlers.setState([]);\n };\n\n const openModal = (props: ModalSettings) => {\n const id = props.id || randomId();\n handlers.append({ id, props, type: 'content' });\n setCurrentModal({ id, props, type: 'content' });\n return id;\n };\n\n const openConfirmModal = (props: OpenConfirmModal) => {\n const id = props.id || randomId();\n handlers.append({ id, props, type: 'confirm' });\n setCurrentModal({ id, props, type: 'confirm' });\n return id;\n };\n\n const openContextModal = (modal: string, props: OpenContextModal) => {\n const id = props.id || randomId();\n handlers.append({ id, props, type: 'context', ctx: modal });\n setCurrentModal({ id, props, type: 'context', ctx: modal });\n return id;\n };\n\n const closeModal = (id: string, canceled?: boolean) => {\n const index = state.findIndex((item) => item.id === id);\n if (state.length <= 1) {\n closeAll(canceled);\n } else {\n const modal = state.find((item) => item.id === id);\n if (modal?.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n modal?.props?.onClose?.();\n index !== -1 && handlers.remove(index);\n setCurrentModal(\n state[state.length - 2] || {\n id: null,\n props: null,\n type: 'content',\n }\n );\n }\n };\n\n const ContextModal = currentModal?.type === 'context' ? modals[currentModal?.ctx] : () => null;\n\n const ctx = {\n modals: state,\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeAll,\n };\n\n const content =\n currentModal?.type === 'context' ? (\n <ContextModal context={ctx} id={currentModal?.id} {...(currentModal?.props as any)} />\n ) : currentModal?.type === 'confirm' ? (\n <ConfirmModal\n {...currentModal.props}\n id={currentModal.id}\n labels={currentModal.props.labels || labels}\n />\n ) : (\n currentModal?.props?.children\n );\n\n return (\n <modalsContext.Provider value={ctx}>\n <Modal\n {...modalProps}\n {...(currentModal?.type === 'confirm'\n ? extractConfirmModalProps(currentModal?.props)\n : currentModal?.props)}\n opened={state.length > 0}\n onClose={() => closeModal(currentModal?.id, true)}\n >\n {content}\n </Modal>\n\n {children}\n </modalsContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,IAAI,mBAAmB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,CAAC,CAAC;AAC1B;;;;"}
1
+ {"version":3,"file":"ModalsProvider.js","sources":["../src/ModalsProvider.tsx"],"sourcesContent":["import React, { useReducer } from 'react';\nimport { Modal } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport {\n ModalsContext,\n ModalSettings,\n ConfirmLabels,\n OpenConfirmModal,\n OpenContextModal,\n ContextModalProps,\n ModalsContextProps,\n} from './context';\nimport { ConfirmModal } from './ConfirmModal';\nimport { modalsReducer } from './reducer';\n\nexport interface ModalsProviderProps {\n /** Your app */\n children: React.ReactNode;\n\n /** Predefined modals */\n modals?: Record<string, React.FC<ContextModalProps>>;\n\n /** Shared Modal component props, applied for every modal */\n modalProps?: ModalSettings;\n\n /** Confirm modal labels */\n labels?: ConfirmLabels;\n}\n\nfunction separateConfirmModalProps(props: OpenConfirmModal) {\n if (!props) {\n return { confirmProps: {}, modalProps: {} };\n }\n\n const {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...others\n } = props;\n\n return {\n confirmProps: {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n },\n modalProps: {\n id,\n ...others,\n },\n };\n}\n\nexport function ModalsProvider({ children, modalProps, labels, modals }: ModalsProviderProps) {\n const [state, dispatch] = useReducer(modalsReducer, { modals: [], current: null });\n const closeAll = (canceled?: boolean) => {\n state.modals.forEach((modal) => {\n if (modal.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n\n modal.props?.onClose?.();\n });\n dispatch({ type: 'CLOSE_ALL' });\n };\n\n const openModal = (props: ModalSettings) => {\n const id = props.id || randomId();\n dispatch({\n type: 'OPEN',\n payload: {\n id,\n type: 'content',\n props,\n },\n });\n return id;\n };\n\n const openConfirmModal = (props: OpenConfirmModal) => {\n const id = props.id || randomId();\n dispatch({\n type: 'OPEN',\n payload: {\n id,\n type: 'confirm',\n props,\n },\n });\n return id;\n };\n\n const openContextModal = (modal: string, props: OpenContextModal) => {\n const id = props.id || randomId();\n dispatch({\n type: 'OPEN',\n payload: {\n id,\n type: 'context',\n props,\n ctx: modal,\n },\n });\n return id;\n };\n\n const closeModal = (id: string, canceled?: boolean) => {\n if (state.modals.length <= 1) {\n closeAll(canceled);\n return;\n }\n\n const modal = state.modals.find((item) => item.id === id);\n if (modal?.type === 'confirm' && canceled) {\n modal.props?.onCancel?.();\n }\n modal?.props?.onClose?.();\n dispatch({ type: 'CLOSE', payload: modal.id });\n };\n\n const ctx: ModalsContextProps = {\n modals: state.modals,\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeAll,\n };\n\n const getCurrentModal = () => {\n switch (state.current?.type) {\n case 'context': {\n const { innerProps, ...rest } = state.current.props;\n const ContextModal = modals[state.current.ctx];\n\n return {\n modalProps: rest,\n content: <ContextModal innerProps={innerProps} context={ctx} id={state.current.id} />,\n };\n }\n case 'confirm': {\n const { modalProps: separatedModalProps, confirmProps: separatedConfirmProps } =\n separateConfirmModalProps(state.current.props);\n\n return {\n modalProps: separatedModalProps,\n content: (\n <ConfirmModal\n {...separatedConfirmProps}\n id={state.current.id}\n labels={state.current.props.labels || labels}\n />\n ),\n };\n }\n case 'content': {\n const { children: currentModalChildren, ...rest } = state.current.props;\n\n return {\n modalProps: rest,\n content: <>{currentModalChildren}</>,\n };\n }\n default: {\n return {\n modalProps: {},\n content: null,\n };\n }\n }\n };\n\n const { modalProps: currentModalProps, content } = getCurrentModal();\n\n return (\n <ModalsContext.Provider value={ctx}>\n <Modal\n {...modalProps}\n {...currentModalProps}\n opened={state.modals.length > 0}\n onClose={() => closeModal(state.current.id)}\n >\n {content}\n </Modal>\n\n {children}\n </ModalsContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,C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 +1,7 @@
1
1
  import { createContext } from 'react';
2
2
 
3
- const modalsContext = createContext({
4
- modals: [],
5
- openModal: () => null,
6
- openConfirmModal: () => null,
7
- openContextModal: () => null,
8
- closeAll: () => {
9
- },
10
- closeModal: () => {
11
- }
12
- });
3
+ const ModalsContext = createContext(null);
4
+ ModalsContext.displayName = "@mantine/modals/ModalsContext";
13
5
 
14
- export { modalsContext };
6
+ export { ModalsContext };
15
7
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>>;\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', string>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal extends ModalSettings {}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: Record<string, any>; type: 'context'; ctx: string };\n\nexport interface ModalsContext {\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: (modal: string, props: Record<string, any>) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeAll: () => void;\n}\n\nexport const modalsContext = createContext<ModalsContext>({\n modals: [],\n openModal: () => null,\n openConfirmModal: () => null,\n openContextModal: () => null,\n closeAll: () => {},\n closeModal: () => {},\n});\n"],"names":[],"mappings":";;AACY,MAAC,aAAa,GAAG,aAAa,CAAC;AAC3C,EAAE,MAAM,EAAE,EAAE;AACZ,EAAE,SAAS,EAAE,MAAM,IAAI;AACvB,EAAE,gBAAgB,EAAE,MAAM,IAAI;AAC9B,EAAE,gBAAgB,EAAE,MAAM,IAAI;AAC9B,EAAE,QAAQ,EAAE,MAAM;AAClB,GAAG;AACH,EAAE,UAAU,EAAE,MAAM;AACpB,GAAG;AACH,CAAC;;;;"}
1
+ {"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>>;\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', string>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal<CustomProps extends Record<string, unknown> = {}>\n extends ModalSettings {\n innerProps: CustomProps;\n}\n\nexport interface ContextModalProps<T extends Record<string, unknown> = {}> {\n context: ModalsContextProps;\n innerProps: T;\n id: string;\n}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: OpenContextModal; type: 'context'; ctx: string };\n\nexport interface ModalsContextProps {\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: <CustomProps extends Record<string, unknown>>(\n modal: string,\n props: OpenContextModal<CustomProps>\n ) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeAll: () => void;\n}\n\nexport const ModalsContext = createContext<ModalsContextProps>(null);\nModalsContext.displayName = '@mantine/modals/ModalsContext';\n"],"names":[],"mappings":";;AACY,MAAC,aAAa,GAAG,aAAa,CAAC,IAAI,EAAE;AACjD,aAAa,CAAC,WAAW,GAAG,+BAA+B;;;;"}
package/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { ModalsProvider } from './ModalsProvider.js';
2
- export { useModals } from './use-modals.js';
2
+ export { useModals } from './use-modals/use-modals.js';
3
3
  //# sourceMappingURL=index.js.map
package/esm/reducer.js ADDED
@@ -0,0 +1,28 @@
1
+ function modalsReducer(state, action) {
2
+ switch (action.type) {
3
+ case "OPEN": {
4
+ return {
5
+ current: action.payload,
6
+ modals: [...state.modals, action.payload]
7
+ };
8
+ }
9
+ case "CLOSE": {
10
+ return {
11
+ current: state.modals[state.modals.length - 2] || null,
12
+ modals: state.modals.filter((m) => m.id !== action.payload)
13
+ };
14
+ }
15
+ case "CLOSE_ALL": {
16
+ return {
17
+ current: state.current,
18
+ modals: []
19
+ };
20
+ }
21
+ default: {
22
+ return state;
23
+ }
24
+ }
25
+ }
26
+
27
+ export { modalsReducer };
28
+ //# sourceMappingURL=reducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.js","sources":["../src/reducer.ts"],"sourcesContent":["import { ModalState } from './context';\n\ninterface ModalsState {\n modals: ModalState[];\n current: ModalState | null;\n}\n\ninterface OpenAction {\n type: 'OPEN';\n payload: ModalState;\n}\n\ninterface CloseAction {\n type: 'CLOSE';\n payload: string;\n}\n\ninterface CloseAllAction {\n type: 'CLOSE_ALL';\n}\n\nexport function modalsReducer(\n state: ModalsState,\n action: OpenAction | CloseAction | CloseAllAction\n): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n return {\n current: action.payload,\n modals: [...state.modals, action.payload],\n };\n }\n case 'CLOSE': {\n return {\n current: state.modals[state.modals.length - 2] || null,\n modals: state.modals.filter((m) => m.id !== action.payload),\n };\n }\n case 'CLOSE_ALL': {\n return {\n current: state.current,\n modals: [],\n };\n }\n default: {\n return state;\n }\n }\n}\n"],"names":[],"mappings":"AAAO,SAAS,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE;AAC7C,EAAE,QAAQ,MAAM,CAAC,IAAI;AACrB,IAAI,KAAK,MAAM,EAAE;AACjB,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,MAAM,CAAC,OAAO;AAC/B,QAAQ,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;AACjD,OAAO,CAAC;AACR,KAAK;AACL,IAAI,KAAK,OAAO,EAAE;AAClB,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI;AAC9D,QAAQ,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC;AACnE,OAAO,CAAC;AACR,KAAK;AACL,IAAI,KAAK,WAAW,EAAE;AACtB,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,KAAK,CAAC,OAAO;AAC9B,QAAQ,MAAM,EAAE,EAAE;AAClB,OAAO,CAAC;AACR,KAAK;AACL,IAAI,SAAS;AACb,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,GAAG;AACH;;;;"}
@@ -1,8 +1,8 @@
1
1
  import { useContext } from 'react';
2
- import { modalsContext } from './context.js';
2
+ import { ModalsContext } from '../context.js';
3
3
 
4
4
  function useModals() {
5
- const ctx = useContext(modalsContext);
5
+ const ctx = useContext(ModalsContext);
6
6
  if (!ctx) {
7
7
  throw new Error("[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component");
8
8
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-modals.js","sources":["../../src/use-modals/use-modals.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { ModalsContext } from '../context';\n\nexport function useModals() {\n const ctx = useContext(ModalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,SAAS,GAAG;AAC5B,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AACxC,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,6GAA6G,CAAC,CAAC;AACnI,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmModal.d.ts","sourceRoot":"","sources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AAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IACpC,YAAY,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,YAAY,CAAC,EAC3B,EAAE,EACF,WAAW,EACX,YAAY,EACZ,MAAM,EACN,cAAqB,EACrB,aAAoB,EACpB,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,GACT,EAAE,iBAAiB,eA8BnB"}
@@ -1,10 +1,5 @@
1
1
  import React from 'react';
2
- import { ModalsContext, ModalSettings, ConfirmLabels } from './context';
3
- export interface ContextModalProps {
4
- context: ModalsContext;
5
- props: Record<string, any>;
6
- id: string;
7
- }
2
+ import { ModalSettings, ConfirmLabels, ContextModalProps } from './context';
8
3
  export interface ModalsProviderProps {
9
4
  /** Your app */
10
5
  children: React.ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"ModalsProvider.d.ts","sourceRoot":"","sources":["../src/ModalsProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAGxC,OAAO,EAEL,aAAa,EACb,aAAa,EACb,aAAa,EAId,MAAM,WAAW,CAAC;AAGnB,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe;IACf,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B,wBAAwB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAErD,4DAA4D;IAC5D,UAAU,CAAC,EAAE,aAAa,CAAC;IAE3B,2BAA2B;IAC3B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAwBD,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,mBAAmB,eAoG3F"}
1
+ {"version":3,"file":"ModalsProvider.d.ts","sourceRoot":"","sources":["../src/ModalsProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAG1C,OAAO,EAEL,aAAa,EACb,aAAa,EAGb,iBAAiB,EAElB,MAAM,WAAW,CAAC;AAInB,MAAM,WAAW,mBAAmB;IAClC,eAAe;IACf,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B,wBAAwB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAErD,4DAA4D;IAC5D,UAAU,CAAC,EAAE,aAAa,CAAC;IAE3B,2BAA2B;IAC3B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAyCD,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,mBAAmB,eAuI3F"}
package/lib/context.d.ts CHANGED
@@ -5,7 +5,13 @@ export declare type ModalSettings = Partial<Omit<ModalProps, 'opened'>>;
5
5
  export declare type ConfirmLabels = Record<'confirm' | 'cancel', string>;
6
6
  export interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {
7
7
  }
8
- export interface OpenContextModal extends ModalSettings {
8
+ export interface OpenContextModal<CustomProps extends Record<string, unknown> = {}> extends ModalSettings {
9
+ innerProps: CustomProps;
10
+ }
11
+ export interface ContextModalProps<T extends Record<string, unknown> = {}> {
12
+ context: ModalsContextProps;
13
+ innerProps: T;
14
+ id: string;
9
15
  }
10
16
  export declare type ModalState = {
11
17
  id: string;
@@ -17,17 +23,17 @@ export declare type ModalState = {
17
23
  type: 'confirm';
18
24
  } | {
19
25
  id: string;
20
- props: Record<string, any>;
26
+ props: OpenContextModal;
21
27
  type: 'context';
22
28
  ctx: string;
23
29
  };
24
- export interface ModalsContext {
30
+ export interface ModalsContextProps {
25
31
  modals: ModalState[];
26
32
  openModal: (props: ModalSettings) => string;
27
33
  openConfirmModal: (props: OpenConfirmModal) => string;
28
- openContextModal: (modal: string, props: Record<string, any>) => string;
34
+ openContextModal: <CustomProps extends Record<string, unknown>>(modal: string, props: OpenContextModal<CustomProps>) => string;
29
35
  closeModal: (id: string, canceled?: boolean) => void;
30
36
  closeAll: () => void;
31
37
  }
32
- export declare const modalsContext: import("react").Context<ModalsContext>;
38
+ export declare const ModalsContext: import("react").Context<ModalsContextProps>;
33
39
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,oBAAY,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEhE,oBAAY,aAAa,GAAG,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEjE,MAAM,WAAW,gBAAiB,SAAQ,aAAa,EAAE,iBAAiB;CAAG;AAC7E,MAAM,WAAW,gBAAiB,SAAQ,aAAa;CAAG;AAE1D,oBAAY,UAAU,GAClB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GACrD;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GACxD;IAAE,EAAE,EAAE,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AAM,EAAE,OAAO,CAAC,GAAG,EAAE;IACvE,OAAO,EAAE,kBAAkB,CAAC;IAC5B,UAAU,EAAE,CAAC,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,oBAAY,UAAU,GAClB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GACrD;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GACxD;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,MAAM,CAAC;IAC5C,gBAAgB,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,MAAM,CAAC;IACtD,gBAAgB,EAAE,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,gBAAgB,CAAC,WAAW,CAAC,KACjC,MAAM,CAAC;IACZ,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACrD,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,6CAA0C,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ModalsProvider } from './ModalsProvider';
2
- export { useModals } from './use-modals';
3
- export type { ModalsProviderProps, ContextModalProps } from './ModalsProvider';
2
+ export { useModals } from './use-modals/use-modals';
3
+ export type { ModalsProviderProps } from './ModalsProvider';
4
+ export type { ContextModalProps } from './context';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { ModalState } from './context';
2
+ interface ModalsState {
3
+ modals: ModalState[];
4
+ current: ModalState | null;
5
+ }
6
+ interface OpenAction {
7
+ type: 'OPEN';
8
+ payload: ModalState;
9
+ }
10
+ interface CloseAction {
11
+ type: 'CLOSE';
12
+ payload: string;
13
+ }
14
+ interface CloseAllAction {
15
+ type: 'CLOSE_ALL';
16
+ }
17
+ export declare function modalsReducer(state: ModalsState, action: OpenAction | CloseAction | CloseAllAction): ModalsState;
18
+ export {};
19
+ //# sourceMappingURL=reducer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,UAAU,WAAW;IACnB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;CAC5B;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,CAAC;CACrB;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,cAAc,GAChD,WAAW,CAwBb"}
@@ -0,0 +1,2 @@
1
+ export declare function useModals(): import("../context").ModalsContextProps;
2
+ //# sourceMappingURL=use-modals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-modals.d.ts","sourceRoot":"","sources":["../../src/use-modals/use-modals.ts"],"names":[],"mappings":"AAGA,wBAAgB,SAAS,4CAUxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=use-modals.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-modals.test.d.ts","sourceRoot":"","sources":["../../src/use-modals/use-modals.test.tsx"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mantine/modals",
3
3
  "description": "Modals manager based on Mantine components",
4
- "version": "4.0.2",
4
+ "version": "4.0.5",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "confirm"
28
28
  ],
29
29
  "peerDependencies": {
30
- "@mantine/core": "4.0.2",
31
- "@mantine/hooks": "4.0.2",
30
+ "@mantine/core": "4.0.5",
31
+ "@mantine/hooks": "4.0.5",
32
32
  "react": ">=16.8.0",
33
33
  "react-dom": ">=16.8.0"
34
34
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-modals.js","sources":["../src/use-modals.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { modalsContext } from './context';\n\nexport function useModals() {\n const ctx = useContext(modalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"names":["useContext","modalsContext"],"mappings":";;;;;;;AAEO,SAAS,SAAS,GAAG;AAC5B,EAAE,MAAM,GAAG,GAAGA,gBAAU,CAACC,qBAAa,CAAC,CAAC;AACxC,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,6GAA6G,CAAC,CAAC;AACnI,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-modals.js","sources":["../src/use-modals.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { modalsContext } from './context';\n\nexport function useModals() {\n const ctx = useContext(modalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,SAAS,GAAG;AAC5B,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AACxC,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,6GAA6G,CAAC,CAAC;AACnI,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
@@ -1,2 +0,0 @@
1
- export declare function useModals(): import("./context").ModalsContext;
2
- //# sourceMappingURL=use-modals.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-modals.d.ts","sourceRoot":"","sources":["../src/use-modals.ts"],"names":[],"mappings":"AAGA,wBAAgB,SAAS,sCAUxB"}