@saas-ui/modals 2.4.2 → 3.0.0-alpha.0
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.
- package/CHANGELOG.md +11 -5
- package/dist/index.cjs +206 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +182 -0
- package/dist/index.d.ts +110 -185
- package/dist/index.js +86 -531
- package/dist/index.js.map +1 -1
- package/package.json +15 -33
- package/src/alert-dialog.tsx +156 -0
- package/src/default-modals.ts +3 -7
- package/src/drawer.tsx +46 -60
- package/src/form.tsx +15 -22
- package/src/index.ts +22 -38
- package/src/modal.tsx +43 -52
- package/src/types.ts +46 -33
- package/dist/chunk-FRC2HTO7.mjs +0 -154
- package/dist/chunk-FRC2HTO7.mjs.map +0 -1
- package/dist/form-BtCUKHAs.d.mts +0 -82
- package/dist/form-BtCUKHAs.d.ts +0 -82
- package/dist/index.d.mts +0 -257
- package/dist/index.mjs +0 -469
- package/dist/index.mjs.map +0 -1
- package/dist/yup/index.d.mts +0 -15
- package/dist/yup/index.d.ts +0 -15
- package/dist/yup/index.js +0 -165
- package/dist/yup/index.js.map +0 -1
- package/dist/yup/index.mjs +0 -20
- package/dist/yup/index.mjs.map +0 -1
- package/dist/zod/index.d.mts +0 -15
- package/dist/zod/index.d.ts +0 -15
- package/dist/zod/index.js +0 -165
- package/dist/zod/index.js.map +0 -1
- package/dist/zod/index.mjs +0 -20
- package/dist/zod/index.mjs.map +0 -1
- package/src/create-modals.tsx +0 -30
- package/src/dialog.tsx +0 -151
- package/src/menu.tsx +0 -107
- package/src/provider.tsx +0 -357
package/dist/index.js
CHANGED
@@ -1,70 +1,25 @@
|
|
1
1
|
'use client'
|
2
|
-
"use strict";
|
3
|
-
var __create = Object.create;
|
4
|
-
var __defProp = Object.defineProperty;
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
-
var __export = (target, all) => {
|
10
|
-
for (var name in all)
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
-
};
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
15
|
-
for (let key of __getOwnPropNames(from))
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
|
-
}
|
19
|
-
return to;
|
20
|
-
};
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
-
mod
|
28
|
-
));
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
2
|
|
31
3
|
// src/index.ts
|
32
|
-
|
33
|
-
__export(src_exports, {
|
34
|
-
BaseDrawer: () => BaseDrawer,
|
35
|
-
BaseModal: () => BaseModal,
|
36
|
-
ConfirmDialog: () => ConfirmDialog,
|
37
|
-
Drawer: () => Drawer,
|
38
|
-
FormDialog: () => FormDialog,
|
39
|
-
MenuDialog: () => MenuDialog,
|
40
|
-
MenuDialogList: () => MenuDialogList,
|
41
|
-
Modal: () => Modal,
|
42
|
-
ModalsContext: () => ModalsContext,
|
43
|
-
ModalsProvider: () => ModalsProvider,
|
44
|
-
createFormDialog: () => createFormDialog,
|
45
|
-
createModals: () => createModals,
|
46
|
-
useModals: () => useModals,
|
47
|
-
useModalsContext: () => useModalsContext
|
48
|
-
});
|
49
|
-
module.exports = __toCommonJS(src_exports);
|
4
|
+
import { createModals } from "@saas-ui/modals-provider";
|
50
5
|
|
51
|
-
// src/dialog.tsx
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
6
|
+
// src/alert-dialog.tsx
|
7
|
+
import * as React from "react";
|
8
|
+
import { Button } from "@chakra-ui/react";
|
9
|
+
import { callAll } from "@saas-ui/core/utils";
|
10
|
+
import { Dialog } from "@saas-ui/react/dialog";
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
12
|
+
var AlertDialog = (props) => {
|
13
|
+
var _a, _b, _c, _d;
|
56
14
|
const {
|
57
15
|
title,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
confirmProps,
|
62
|
-
buttonGroupProps,
|
63
|
-
isOpen,
|
16
|
+
translations,
|
17
|
+
slotProps,
|
18
|
+
open,
|
64
19
|
closeOnCancel = true,
|
65
20
|
closeOnConfirm = true,
|
66
21
|
leastDestructiveFocus = "cancel",
|
67
|
-
|
22
|
+
onOpenChange,
|
68
23
|
onCancel,
|
69
24
|
onConfirm,
|
70
25
|
children,
|
@@ -80,534 +35,134 @@ var ConfirmDialog = (props) => {
|
|
80
35
|
setIsLoading(true);
|
81
36
|
await result;
|
82
37
|
}
|
83
|
-
closeOnConfirm &&
|
38
|
+
closeOnConfirm && onOpenChange({ open: false });
|
84
39
|
} catch (e) {
|
85
40
|
throw e;
|
86
41
|
} finally {
|
87
42
|
setIsLoading(false);
|
88
43
|
}
|
89
44
|
};
|
90
|
-
|
91
|
-
|
45
|
+
const titleId = React.useId();
|
46
|
+
const contentId = React.useId();
|
47
|
+
return /* @__PURE__ */ jsx(
|
48
|
+
Dialog.Root,
|
92
49
|
{
|
93
|
-
|
94
|
-
|
50
|
+
open,
|
51
|
+
onOpenChange,
|
52
|
+
size: "sm",
|
53
|
+
"aria-labelledby": titleId,
|
54
|
+
"aria-describedby": contentId,
|
95
55
|
...rest,
|
96
|
-
|
97
|
-
children: /* @__PURE__ */
|
98
|
-
/* @__PURE__ */ (
|
99
|
-
/* @__PURE__ */
|
100
|
-
/* @__PURE__ */ (
|
101
|
-
/* @__PURE__ */
|
102
|
-
|
56
|
+
initialFocusEl: () => leastDestructiveFocus === "cancel" ? cancelRef.current : confirmRef.current,
|
57
|
+
children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
58
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: /* @__PURE__ */ jsx(Dialog.Title, { id: titleId, children: title }) }),
|
59
|
+
/* @__PURE__ */ jsx(Dialog.Body, { id: contentId, children }),
|
60
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { ...slotProps == null ? void 0 : slotProps.footer, children: [
|
61
|
+
/* @__PURE__ */ jsx(
|
62
|
+
Button,
|
103
63
|
{
|
104
64
|
ref: cancelRef,
|
105
|
-
|
106
|
-
|
65
|
+
variant: "ghost",
|
66
|
+
colorPalette: "gray",
|
67
|
+
...slotProps == null ? void 0 : slotProps.cancel,
|
68
|
+
onClick: callAll((_a = slotProps == null ? void 0 : slotProps.cancel) == null ? void 0 : _a.onClick, () => {
|
107
69
|
onCancel == null ? void 0 : onCancel();
|
108
|
-
closeOnCancel &&
|
109
|
-
},
|
110
|
-
children: (
|
70
|
+
closeOnCancel && onOpenChange({ open: false });
|
71
|
+
}),
|
72
|
+
children: ((_b = slotProps == null ? void 0 : slotProps.cancel) == null ? void 0 : _b.children) || (translations == null ? void 0 : translations.cancel) || "Cancel"
|
111
73
|
}
|
112
74
|
),
|
113
|
-
/* @__PURE__ */
|
114
|
-
|
75
|
+
/* @__PURE__ */ jsx(
|
76
|
+
Button,
|
115
77
|
{
|
116
78
|
ref: confirmRef,
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
79
|
+
variant: "solid",
|
80
|
+
disabled: isLoading,
|
81
|
+
...slotProps == null ? void 0 : slotProps.confirm,
|
82
|
+
onClick: callAll(handleConfirm, (_c = slotProps == null ? void 0 : slotProps.confirm) == null ? void 0 : _c.onClick),
|
83
|
+
children: ((_d = slotProps == null ? void 0 : slotProps.confirm) == null ? void 0 : _d.children) || (translations == null ? void 0 : translations.confirm) || "OK"
|
121
84
|
}
|
122
85
|
)
|
123
|
-
] })
|
124
|
-
] })
|
86
|
+
] })
|
87
|
+
] })
|
125
88
|
}
|
126
89
|
);
|
127
90
|
};
|
128
91
|
|
129
92
|
// src/drawer.tsx
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
var
|
93
|
+
import { runIfFn } from "@saas-ui/core/utils";
|
94
|
+
import { Drawer as BaseDrawer } from "@saas-ui/react/drawer";
|
95
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
96
|
+
var Drawer = (props) => {
|
134
97
|
const {
|
135
98
|
title,
|
136
99
|
children,
|
137
100
|
footer,
|
138
|
-
|
139
|
-
|
101
|
+
open,
|
102
|
+
onOpenChange,
|
140
103
|
hideCloseButton,
|
141
|
-
|
104
|
+
hideBackdrop,
|
142
105
|
headerProps,
|
143
106
|
contentProps,
|
107
|
+
bodyProps,
|
144
108
|
footerProps,
|
145
109
|
...rest
|
146
110
|
} = props;
|
147
|
-
return /* @__PURE__ */ (
|
148
|
-
!
|
149
|
-
/* @__PURE__ */ (
|
150
|
-
title && /* @__PURE__ */ (
|
151
|
-
!hideCloseButton && /* @__PURE__ */ (
|
152
|
-
(
|
153
|
-
|
154
|
-
onClose
|
155
|
-
}),
|
156
|
-
footer && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.DrawerFooter, { ...footerProps, children: footer })
|
111
|
+
return /* @__PURE__ */ jsxs2(BaseDrawer.Root, { open, onOpenChange, ...rest, children: [
|
112
|
+
!hideBackdrop && /* @__PURE__ */ jsx2(BaseDrawer.Backdrop, {}),
|
113
|
+
/* @__PURE__ */ jsxs2(BaseDrawer.Content, { ...contentProps, children: [
|
114
|
+
title && /* @__PURE__ */ jsx2(BaseDrawer.Header, { ...headerProps, children: title }),
|
115
|
+
!hideCloseButton && /* @__PURE__ */ jsx2(BaseDrawer.CloseTrigger, {}),
|
116
|
+
/* @__PURE__ */ jsx2(BaseDrawer.Body, { ...bodyProps, children: /* @__PURE__ */ jsx2(BaseDrawer.Context, { children: ({ open: open2, setOpen }) => runIfFn(children, { open: open2, setOpen }) }) }),
|
117
|
+
footer && /* @__PURE__ */ jsx2(BaseDrawer.Footer, { ...footerProps, children: footer })
|
157
118
|
] })
|
158
119
|
] });
|
159
120
|
};
|
160
|
-
var Drawer = (props) => {
|
161
|
-
const { children, isOpen, onClose, ...rest } = props;
|
162
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BaseDrawer, { isOpen, onClose, ...rest, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.DrawerBody, { children: (0, import_utils.runIfFn)(children, {
|
163
|
-
isOpen,
|
164
|
-
onClose
|
165
|
-
}) }) });
|
166
|
-
};
|
167
121
|
|
168
122
|
// src/modal.tsx
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
var
|
123
|
+
import { runIfFn as runIfFn2 } from "@saas-ui/core/utils";
|
124
|
+
import { Dialog as BaseDialog } from "@saas-ui/react/dialog";
|
125
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
126
|
+
var Modal = (props) => {
|
173
127
|
const {
|
174
128
|
title,
|
175
129
|
footer,
|
176
130
|
children,
|
177
|
-
|
178
|
-
|
131
|
+
open,
|
132
|
+
onOpenChange,
|
179
133
|
hideCloseButton,
|
180
|
-
|
134
|
+
hideBackdrop,
|
181
135
|
headerProps,
|
182
136
|
contentProps,
|
137
|
+
bodyProps,
|
183
138
|
footerProps,
|
184
139
|
...rest
|
185
140
|
} = props;
|
186
|
-
return /* @__PURE__ */ (
|
187
|
-
|
188
|
-
/* @__PURE__ */ (
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
isOpen,
|
193
|
-
onClose
|
194
|
-
}),
|
195
|
-
footer && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react3.ModalFooter, { ...footerProps, children: footer })
|
196
|
-
] })
|
197
|
-
] });
|
198
|
-
};
|
199
|
-
var Modal = (props) => {
|
200
|
-
const { children, isOpen, onClose, ...rest } = props;
|
201
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(BaseModal, { ...rest, isOpen, onClose, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react3.ModalBody, { children: (0, import_utils2.runIfFn)(children, {
|
202
|
-
isOpen,
|
203
|
-
onClose
|
204
|
-
}) }) });
|
205
|
-
};
|
206
|
-
|
207
|
-
// src/menu.tsx
|
208
|
-
var import_react4 = require("@chakra-ui/react");
|
209
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
210
|
-
var [StylesProvider] = (0, import_react4.createStylesContext)("SuiMenuDialog");
|
211
|
-
var MenuDialog = (props) => {
|
212
|
-
const { onClose, onCloseComplete, ...rest } = props;
|
213
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
214
|
-
import_react4.Menu,
|
215
|
-
{
|
216
|
-
variant: "dialog",
|
217
|
-
onClose: () => {
|
218
|
-
onClose == null ? void 0 : onClose();
|
219
|
-
onCloseComplete == null ? void 0 : onCloseComplete();
|
220
|
-
},
|
221
|
-
...rest
|
222
|
-
}
|
223
|
-
);
|
224
|
-
};
|
225
|
-
var MenuDialogList = (0, import_react4.forwardRef)(
|
226
|
-
(props, forwardedRef) => {
|
227
|
-
const {
|
228
|
-
rootProps,
|
229
|
-
title,
|
230
|
-
footer,
|
231
|
-
initialFocusRef,
|
232
|
-
hideCloseButton,
|
233
|
-
motionPreset = "slideInBottom",
|
234
|
-
isCentered: isCenteredProp,
|
235
|
-
...rest
|
236
|
-
} = props;
|
237
|
-
const { isOpen, onClose, menuRef } = (0, import_react4.useMenuContext)();
|
238
|
-
const { ref, ...ownProps } = (0, import_react4.useMenuList)(rest, forwardedRef);
|
239
|
-
const styles = (0, import_react4.useMultiStyleConfig)("Menu", props);
|
240
|
-
const isCentered = (0, import_react4.useBreakpointValue)({ base: true, md: false });
|
241
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
242
|
-
BaseModal,
|
243
|
-
{
|
244
|
-
isOpen,
|
245
|
-
onClose,
|
246
|
-
initialFocusRef: initialFocusRef || menuRef,
|
247
|
-
title,
|
248
|
-
hideCloseButton,
|
249
|
-
motionPreset,
|
250
|
-
isCentered: isCenteredProp != null ? isCenteredProp : isCentered,
|
251
|
-
contentProps: { mx: 4 },
|
252
|
-
children: [
|
253
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(StylesProvider, { value: styles, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
254
|
-
import_react4.chakra.div,
|
255
|
-
{
|
256
|
-
...ownProps,
|
257
|
-
ref,
|
258
|
-
__css: {
|
259
|
-
outline: 0,
|
260
|
-
maxHeight: "80vh",
|
261
|
-
// can override this in theme
|
262
|
-
overflowY: "auto",
|
263
|
-
// can override this in theme
|
264
|
-
...styles.list,
|
265
|
-
boxShadow: "none",
|
266
|
-
border: 0,
|
267
|
-
_dark: {
|
268
|
-
/* @ts-expect-error */
|
269
|
-
...styles.list._dark || {},
|
270
|
-
boxShadow: "none"
|
271
|
-
}
|
272
|
-
}
|
273
|
-
}
|
274
|
-
) }),
|
275
|
-
footer && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.ModalFooter, { children: footer })
|
276
|
-
]
|
277
|
-
}
|
278
|
-
);
|
279
|
-
}
|
280
|
-
);
|
281
|
-
|
282
|
-
// src/form.tsx
|
283
|
-
var import_react5 = require("@chakra-ui/react");
|
284
|
-
var import_react_utils = require("@saas-ui/react-utils");
|
285
|
-
var import_forms = require("@saas-ui/forms");
|
286
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
287
|
-
var useFormProps = (props) => {
|
288
|
-
const {
|
289
|
-
schema,
|
290
|
-
resolver,
|
291
|
-
fieldResolver,
|
292
|
-
defaultValues,
|
293
|
-
values,
|
294
|
-
context,
|
295
|
-
onChange,
|
296
|
-
onSubmit,
|
297
|
-
onError,
|
298
|
-
mode,
|
299
|
-
reValidateMode,
|
300
|
-
shouldFocusError = true,
|
301
|
-
shouldUnregister,
|
302
|
-
shouldUseNativeValidation,
|
303
|
-
criteriaMode,
|
304
|
-
delayError = 100,
|
305
|
-
fields,
|
306
|
-
formRef,
|
307
|
-
...modalProps
|
308
|
-
} = props;
|
309
|
-
const formProps = {
|
310
|
-
schema,
|
311
|
-
resolver,
|
312
|
-
defaultValues,
|
313
|
-
values,
|
314
|
-
context,
|
315
|
-
onChange,
|
316
|
-
onSubmit,
|
317
|
-
onError,
|
318
|
-
mode,
|
319
|
-
reValidateMode,
|
320
|
-
shouldFocusError,
|
321
|
-
shouldUnregister,
|
322
|
-
shouldUseNativeValidation,
|
323
|
-
criteriaMode,
|
324
|
-
delayError,
|
325
|
-
fields,
|
326
|
-
formRef
|
327
|
-
};
|
328
|
-
return { modalProps, formProps, fields };
|
141
|
+
return /* @__PURE__ */ jsx3(BaseDialog.Root, { open, onOpenChange, ...rest, children: /* @__PURE__ */ jsxs3(BaseDialog.Content, { ...contentProps, children: [
|
142
|
+
title && /* @__PURE__ */ jsx3(BaseDialog.Header, { ...headerProps, children: title }),
|
143
|
+
!hideCloseButton && /* @__PURE__ */ jsx3(BaseDialog.CloseTrigger, {}),
|
144
|
+
/* @__PURE__ */ jsx3(BaseDialog.Body, { children: /* @__PURE__ */ jsx3(BaseDialog.Context, { children: ({ open: open2, setOpen }) => runIfFn2(children, { open: open2, setOpen }) }) }),
|
145
|
+
footer && /* @__PURE__ */ jsx3(BaseDialog.Footer, { ...footerProps, children: footer })
|
146
|
+
] }) });
|
329
147
|
};
|
330
|
-
function createFormDialog(Form2) {
|
331
|
-
const Dialog = (0, import_react5.forwardRef)((props, ref) => {
|
332
|
-
const { isOpen, onClose, footer, children, ...rest } = props;
|
333
|
-
const { modalProps, formProps, fields } = useFormProps(rest);
|
334
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BaseModal, { ...modalProps, isOpen, onClose, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
335
|
-
Form2,
|
336
|
-
{
|
337
|
-
ref,
|
338
|
-
...formProps,
|
339
|
-
flex: "1",
|
340
|
-
minHeight: "0px",
|
341
|
-
display: "flex",
|
342
|
-
flexDirection: "column",
|
343
|
-
children: (form) => {
|
344
|
-
var _a, _b;
|
345
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
346
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react5.ModalBody, { height: "100%", children: (0, import_react_utils.runIfFn)(children, form) || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_forms.AutoFields, {}) }),
|
347
|
-
footer || /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react5.ModalFooter, { children: [
|
348
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
349
|
-
import_react5.Button,
|
350
|
-
{
|
351
|
-
variant: "ghost",
|
352
|
-
mr: 3,
|
353
|
-
onClick: onClose,
|
354
|
-
...fields == null ? void 0 : fields.cancel,
|
355
|
-
children: (_b = (_a = fields == null ? void 0 : fields.cancel) == null ? void 0 : _a.children) != null ? _b : "Cancel"
|
356
|
-
}
|
357
|
-
),
|
358
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_forms.SubmitButton, { ...fields == null ? void 0 : fields.submit })
|
359
|
-
] })
|
360
|
-
] });
|
361
|
-
}
|
362
|
-
}
|
363
|
-
) });
|
364
|
-
});
|
365
|
-
Dialog.displayName = `${Form2.displayName || Form2.name}Dialog`;
|
366
|
-
Dialog.id = Form2.id;
|
367
|
-
return Dialog;
|
368
|
-
}
|
369
|
-
var FormDialog = createFormDialog(import_forms.Form);
|
370
|
-
|
371
|
-
// src/provider.tsx
|
372
|
-
var React2 = __toESM(require("react"));
|
373
148
|
|
374
149
|
// src/default-modals.ts
|
375
150
|
var defaultModals = {
|
376
|
-
alert:
|
377
|
-
confirm:
|
151
|
+
alert: AlertDialog,
|
152
|
+
confirm: AlertDialog,
|
378
153
|
drawer: Drawer,
|
379
|
-
modal: Modal
|
380
|
-
menu: MenuDialog,
|
381
|
-
form: FormDialog
|
382
|
-
};
|
383
|
-
|
384
|
-
// src/provider.tsx
|
385
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
386
|
-
var ModalsContext = React2.createContext(null);
|
387
|
-
var initialModalState = {
|
388
|
-
id: null,
|
389
|
-
props: null,
|
390
|
-
type: "modal"
|
391
|
-
};
|
392
|
-
function ModalsProvider({ children, modals }) {
|
393
|
-
const _instances = React2.useMemo(() => /* @__PURE__ */ new Set(), []);
|
394
|
-
const [activeModals, setActiveModals] = React2.useState({
|
395
|
-
modal: initialModalState
|
396
|
-
});
|
397
|
-
const getModalComponent = React2.useMemo(() => {
|
398
|
-
const _modals = {
|
399
|
-
...defaultModals,
|
400
|
-
...modals
|
401
|
-
};
|
402
|
-
return (type = "modal") => {
|
403
|
-
const component = _modals[type] || _modals.modal;
|
404
|
-
return component;
|
405
|
-
};
|
406
|
-
}, [modals]);
|
407
|
-
const setActiveModal = (modal, scope) => {
|
408
|
-
if (!scope) {
|
409
|
-
return setActiveModals({
|
410
|
-
modal
|
411
|
-
});
|
412
|
-
}
|
413
|
-
setActiveModals((prevState) => ({
|
414
|
-
...prevState,
|
415
|
-
[scope]: modal
|
416
|
-
}));
|
417
|
-
};
|
418
|
-
const open = (componentOrOptions, options) => {
|
419
|
-
let _options;
|
420
|
-
if (typeof componentOrOptions === "function") {
|
421
|
-
_options = {
|
422
|
-
component: componentOrOptions,
|
423
|
-
...options
|
424
|
-
};
|
425
|
-
} else {
|
426
|
-
_options = componentOrOptions;
|
427
|
-
}
|
428
|
-
const {
|
429
|
-
id = _instances.size + 1,
|
430
|
-
type = "modal",
|
431
|
-
scope = "modal",
|
432
|
-
component,
|
433
|
-
...props
|
434
|
-
} = _options;
|
435
|
-
const modal = {
|
436
|
-
id,
|
437
|
-
props,
|
438
|
-
type,
|
439
|
-
scope,
|
440
|
-
component,
|
441
|
-
isOpen: true
|
442
|
-
};
|
443
|
-
_instances.add(modal);
|
444
|
-
setActiveModal(modal, scope);
|
445
|
-
return id;
|
446
|
-
};
|
447
|
-
const drawer = (options) => {
|
448
|
-
return open({
|
449
|
-
...options,
|
450
|
-
type: "drawer"
|
451
|
-
});
|
452
|
-
};
|
453
|
-
const alert = (options) => {
|
454
|
-
return open({
|
455
|
-
...options,
|
456
|
-
scope: "alert",
|
457
|
-
type: "alert",
|
458
|
-
cancelProps: {
|
459
|
-
display: "none"
|
460
|
-
},
|
461
|
-
confirmProps: {
|
462
|
-
label: "OK"
|
463
|
-
},
|
464
|
-
leastDestructiveFocus: "confirm"
|
465
|
-
});
|
466
|
-
};
|
467
|
-
const confirm = (options) => {
|
468
|
-
return open({
|
469
|
-
...options,
|
470
|
-
scope: "alert",
|
471
|
-
type: "confirm"
|
472
|
-
});
|
473
|
-
};
|
474
|
-
const menu = (options) => {
|
475
|
-
return open({
|
476
|
-
...options,
|
477
|
-
type: "menu"
|
478
|
-
});
|
479
|
-
};
|
480
|
-
const form = (options) => {
|
481
|
-
return open({
|
482
|
-
...options,
|
483
|
-
type: "form"
|
484
|
-
});
|
485
|
-
};
|
486
|
-
const close = async (id, force) => {
|
487
|
-
var _a, _b;
|
488
|
-
const modals2 = [...Array.from(_instances)];
|
489
|
-
const modal = modals2.filter((modal2) => modal2.id === id)[0];
|
490
|
-
if (!modal) {
|
491
|
-
return;
|
492
|
-
}
|
493
|
-
const shouldClose = await ((_b = (_a = modal.props) == null ? void 0 : _a.onClose) == null ? void 0 : _b.call(_a, { force }));
|
494
|
-
if (shouldClose === false) {
|
495
|
-
return;
|
496
|
-
}
|
497
|
-
const scoped = modals2.filter(({ scope }) => scope === modal.scope);
|
498
|
-
if (scoped.length === 1) {
|
499
|
-
setActiveModal(
|
500
|
-
{
|
501
|
-
...modal,
|
502
|
-
isOpen: false
|
503
|
-
},
|
504
|
-
modal.scope
|
505
|
-
);
|
506
|
-
} else if (scoped.length > 1) {
|
507
|
-
setActiveModal(scoped[scoped.length - 2], modal.scope);
|
508
|
-
} else {
|
509
|
-
setActiveModal(
|
510
|
-
{
|
511
|
-
id: null,
|
512
|
-
props: null,
|
513
|
-
type: modal.type
|
514
|
-
// Keep type same as last modal type to make sure the animation isn't interrupted
|
515
|
-
},
|
516
|
-
modal.scope
|
517
|
-
);
|
518
|
-
}
|
519
|
-
setTimeout(() => closeComplete(id), 200);
|
520
|
-
};
|
521
|
-
const closeComplete = (id) => {
|
522
|
-
const modals2 = [...Array.from(_instances)];
|
523
|
-
const modal = modals2.filter((modal2) => modal2.id === id)[0];
|
524
|
-
_instances.delete(modal);
|
525
|
-
const scoped = modal && modals2.filter(({ scope }) => scope === modal.scope);
|
526
|
-
if ((scoped == null ? void 0 : scoped.length) === 1) {
|
527
|
-
setActiveModal(initialModalState, modal.scope);
|
528
|
-
}
|
529
|
-
};
|
530
|
-
const closeAll = () => {
|
531
|
-
_instances.forEach((modal) => {
|
532
|
-
var _a, _b;
|
533
|
-
return (_b = (_a = modal.props) == null ? void 0 : _a.onClose) == null ? void 0 : _b.call(_a, { force: true });
|
534
|
-
});
|
535
|
-
_instances.clear();
|
536
|
-
setActiveModal(initialModalState);
|
537
|
-
};
|
538
|
-
const context = {
|
539
|
-
open,
|
540
|
-
drawer,
|
541
|
-
alert,
|
542
|
-
confirm,
|
543
|
-
menu,
|
544
|
-
form,
|
545
|
-
close,
|
546
|
-
closeAll
|
547
|
-
};
|
548
|
-
const content = React2.useMemo(
|
549
|
-
() => Object.entries(activeModals).map(([scope, config]) => {
|
550
|
-
const Component = config.component || getModalComponent(config.type);
|
551
|
-
const { title, body, children: children2, ...props } = config.props || {};
|
552
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
553
|
-
Component,
|
554
|
-
{
|
555
|
-
title,
|
556
|
-
children: body || children2,
|
557
|
-
...props,
|
558
|
-
isOpen: !!config.isOpen,
|
559
|
-
onClose: () => close(config.id),
|
560
|
-
onCloseComplete: () => closeComplete(config.id)
|
561
|
-
},
|
562
|
-
scope
|
563
|
-
);
|
564
|
-
}),
|
565
|
-
[activeModals]
|
566
|
-
);
|
567
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ModalsContext.Provider, { value: context, children: [
|
568
|
-
content,
|
569
|
-
children
|
570
|
-
] });
|
571
|
-
}
|
572
|
-
var useModalsContext = () => React2.useContext(ModalsContext);
|
573
|
-
var useModals = () => {
|
574
|
-
const modals = useModalsContext();
|
575
|
-
if (!modals) {
|
576
|
-
throw new Error("useModals must be used within a ModalsProvider");
|
577
|
-
}
|
578
|
-
return modals;
|
154
|
+
modal: Modal
|
579
155
|
};
|
580
156
|
|
581
|
-
// src/
|
582
|
-
var
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
};
|
588
|
-
const Provider = (props) => {
|
589
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ModalsProvider, { children: props.children, modals });
|
590
|
-
};
|
591
|
-
return {
|
592
|
-
ModalsProvider: Provider,
|
593
|
-
useModals
|
594
|
-
};
|
595
|
-
};
|
596
|
-
// Annotate the CommonJS export names for ESM import in node:
|
597
|
-
0 && (module.exports = {
|
598
|
-
BaseDrawer,
|
599
|
-
BaseModal,
|
600
|
-
ConfirmDialog,
|
157
|
+
// src/index.ts
|
158
|
+
var { useModals, ModalsProvider } = createModals({
|
159
|
+
modals: defaultModals
|
160
|
+
});
|
161
|
+
export {
|
162
|
+
AlertDialog,
|
601
163
|
Drawer,
|
602
|
-
FormDialog,
|
603
|
-
MenuDialog,
|
604
|
-
MenuDialogList,
|
605
164
|
Modal,
|
606
|
-
ModalsContext,
|
607
165
|
ModalsProvider,
|
608
|
-
|
609
|
-
|
610
|
-
useModals,
|
611
|
-
useModalsContext
|
612
|
-
});
|
166
|
+
useModals
|
167
|
+
};
|
613
168
|
//# sourceMappingURL=index.js.map
|