@mantine-vue/modals 1.1.1
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/cjs/index.cjs +387 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/index.mjs +364 -0
- package/esm/index.mjs.map +1 -0
- package/lib/ConfirmModal.d.ts +106 -0
- package/lib/ModalsProvider.d.ts +42 -0
- package/lib/context.d.ts +50 -0
- package/lib/index.d.mts +10 -0
- package/lib/index.d.ts +10 -0
- package/lib/modals.store.d.ts +47 -0
- package/lib/reducer.d.ts +26 -0
- package/lib/use-modals.d.ts +2 -0
- package/package.json +42 -0
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let vue = require("vue");
|
|
3
|
+
let _mantine_vue_core = require("@mantine-vue/core");
|
|
4
|
+
let _mantine_vue_store = require("@mantine-vue/store");
|
|
5
|
+
//#region src/context.ts
|
|
6
|
+
var ModalsContextKey = Symbol("ModalsContext");
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/use-modals.ts
|
|
9
|
+
function useModals() {
|
|
10
|
+
const ctx = (0, vue.inject)(ModalsContextKey, null);
|
|
11
|
+
if (!ctx) throw new Error("[@mantine-vue/modals] useModals composable was called outside of context, wrap your app with the ModalsProvider component");
|
|
12
|
+
return ctx;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/ConfirmModal.ts
|
|
16
|
+
var ConfirmModal = (0, vue.defineComponent)({
|
|
17
|
+
name: "ConfirmModal",
|
|
18
|
+
inheritAttrs: false,
|
|
19
|
+
props: {
|
|
20
|
+
id: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: void 0
|
|
23
|
+
},
|
|
24
|
+
onCancel: {
|
|
25
|
+
type: Function,
|
|
26
|
+
default: void 0
|
|
27
|
+
},
|
|
28
|
+
onConfirm: {
|
|
29
|
+
type: Function,
|
|
30
|
+
default: void 0
|
|
31
|
+
},
|
|
32
|
+
closeOnConfirm: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: true
|
|
35
|
+
},
|
|
36
|
+
closeOnCancel: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: true
|
|
39
|
+
},
|
|
40
|
+
cancelProps: {
|
|
41
|
+
type: Object,
|
|
42
|
+
default: void 0
|
|
43
|
+
},
|
|
44
|
+
confirmProps: {
|
|
45
|
+
type: Object,
|
|
46
|
+
default: void 0
|
|
47
|
+
},
|
|
48
|
+
groupProps: {
|
|
49
|
+
type: Object,
|
|
50
|
+
default: void 0
|
|
51
|
+
},
|
|
52
|
+
labels: {
|
|
53
|
+
type: Object,
|
|
54
|
+
default: () => ({
|
|
55
|
+
cancel: "",
|
|
56
|
+
confirm: ""
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
setup(props, { slots }) {
|
|
61
|
+
const ctx = useModals();
|
|
62
|
+
const handleCancel = (event) => {
|
|
63
|
+
props.cancelProps?.onClick?.(event);
|
|
64
|
+
props.onCancel?.();
|
|
65
|
+
if (props.closeOnCancel) ctx.closeModal(props.id);
|
|
66
|
+
};
|
|
67
|
+
const handleConfirm = (event) => {
|
|
68
|
+
props.confirmProps?.onClick?.(event);
|
|
69
|
+
props.onConfirm?.();
|
|
70
|
+
if (props.closeOnConfirm) ctx.closeModal(props.id);
|
|
71
|
+
};
|
|
72
|
+
return () => {
|
|
73
|
+
const children = slots.default?.();
|
|
74
|
+
const hasChildren = !!children && children.length > 0;
|
|
75
|
+
return [hasChildren ? (0, vue.h)(_mantine_vue_core.Box, { mb: "md" }, () => children) : null, (0, vue.h)(_mantine_vue_core.Group, {
|
|
76
|
+
mt: hasChildren ? 0 : "md",
|
|
77
|
+
justify: "flex-end",
|
|
78
|
+
...props.groupProps
|
|
79
|
+
}, () => [(0, vue.h)(_mantine_vue_core.Button, {
|
|
80
|
+
variant: "default",
|
|
81
|
+
...props.cancelProps,
|
|
82
|
+
onClick: handleCancel
|
|
83
|
+
}, () => props.cancelProps?.children ?? props.labels?.cancel), (0, vue.h)(_mantine_vue_core.Button, {
|
|
84
|
+
...props.confirmProps,
|
|
85
|
+
onClick: handleConfirm
|
|
86
|
+
}, () => props.confirmProps?.children ?? props.labels?.confirm)])];
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/reducer.ts
|
|
92
|
+
function handleCloseModal(modal, canceled) {
|
|
93
|
+
if (canceled && modal.type === "confirm") modal.props.onCancel?.();
|
|
94
|
+
modal.props.onClose?.();
|
|
95
|
+
}
|
|
96
|
+
function modalsReducer(state, action) {
|
|
97
|
+
switch (action.type) {
|
|
98
|
+
case "OPEN":
|
|
99
|
+
if (state.modals.some((modal) => modal.id === action.modal.id)) return state;
|
|
100
|
+
return {
|
|
101
|
+
current: action.modal,
|
|
102
|
+
modals: [...state.modals, action.modal]
|
|
103
|
+
};
|
|
104
|
+
case "CLOSE": {
|
|
105
|
+
const modals = state.modals.filter((modal) => modal.id !== action.modalId);
|
|
106
|
+
return {
|
|
107
|
+
current: modals.length > 0 ? modals[modals.length - 1] : state.current,
|
|
108
|
+
modals
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
case "CLOSE_ALL": return {
|
|
112
|
+
current: state.current,
|
|
113
|
+
modals: []
|
|
114
|
+
};
|
|
115
|
+
case "UPDATE": {
|
|
116
|
+
const modals = state.modals.map((modal) => {
|
|
117
|
+
if (modal.id !== action.modalId) return modal;
|
|
118
|
+
if (modal.type === "context") return {
|
|
119
|
+
...modal,
|
|
120
|
+
props: {
|
|
121
|
+
...modal.props,
|
|
122
|
+
...action.newProps,
|
|
123
|
+
innerProps: {
|
|
124
|
+
...modal.props.innerProps,
|
|
125
|
+
...action.newProps.innerProps
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
...modal,
|
|
131
|
+
props: {
|
|
132
|
+
...modal.props,
|
|
133
|
+
...action.newProps
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
current: state.current && state.current.id === action.modalId ? modals.find((modal) => modal.id === action.modalId) || state.current : state.current,
|
|
139
|
+
modals
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
default: return state;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/modals.store.ts
|
|
147
|
+
function randomId() {
|
|
148
|
+
return `mantine-${Math.random().toString(36).slice(2, 11)}`;
|
|
149
|
+
}
|
|
150
|
+
var createModalsStore = () => (0, _mantine_vue_store.createStore)({
|
|
151
|
+
modals: [],
|
|
152
|
+
current: null
|
|
153
|
+
});
|
|
154
|
+
var modalsStore = createModalsStore();
|
|
155
|
+
var useModalsState = (store = modalsStore) => store.value;
|
|
156
|
+
var closingMap = /* @__PURE__ */ new WeakMap();
|
|
157
|
+
function dispatch(action, store) {
|
|
158
|
+
store.setState((state) => modalsReducer(state, action));
|
|
159
|
+
}
|
|
160
|
+
function openModalAction(props, store = modalsStore) {
|
|
161
|
+
const { modalId, ...rest } = props;
|
|
162
|
+
const id = modalId || randomId();
|
|
163
|
+
dispatch({
|
|
164
|
+
type: "OPEN",
|
|
165
|
+
modal: {
|
|
166
|
+
id,
|
|
167
|
+
type: "content",
|
|
168
|
+
props: rest
|
|
169
|
+
}
|
|
170
|
+
}, store);
|
|
171
|
+
return id;
|
|
172
|
+
}
|
|
173
|
+
function openConfirmModalAction(props, store = modalsStore) {
|
|
174
|
+
const { modalId, ...rest } = props;
|
|
175
|
+
const id = modalId || randomId();
|
|
176
|
+
dispatch({
|
|
177
|
+
type: "OPEN",
|
|
178
|
+
modal: {
|
|
179
|
+
id,
|
|
180
|
+
type: "confirm",
|
|
181
|
+
props: rest
|
|
182
|
+
}
|
|
183
|
+
}, store);
|
|
184
|
+
return id;
|
|
185
|
+
}
|
|
186
|
+
function openContextModalAction(modal, props, store = modalsStore) {
|
|
187
|
+
const { modalId, ...rest } = props;
|
|
188
|
+
const id = modalId || randomId();
|
|
189
|
+
dispatch({
|
|
190
|
+
type: "OPEN",
|
|
191
|
+
modal: {
|
|
192
|
+
id,
|
|
193
|
+
type: "context",
|
|
194
|
+
props: rest,
|
|
195
|
+
ctx: modal
|
|
196
|
+
}
|
|
197
|
+
}, store);
|
|
198
|
+
return id;
|
|
199
|
+
}
|
|
200
|
+
function closeModalAction(id, canceled, store = modalsStore) {
|
|
201
|
+
if (!closingMap.get(store)) {
|
|
202
|
+
const modal = store.getState().modals.find((item) => item.id === id);
|
|
203
|
+
if (modal) {
|
|
204
|
+
closingMap.set(store, true);
|
|
205
|
+
handleCloseModal(modal, canceled);
|
|
206
|
+
closingMap.set(store, false);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
dispatch({
|
|
210
|
+
type: "CLOSE",
|
|
211
|
+
modalId: id,
|
|
212
|
+
canceled
|
|
213
|
+
}, store);
|
|
214
|
+
}
|
|
215
|
+
function closeAllModalsAction(canceled, store = modalsStore) {
|
|
216
|
+
if (!closingMap.get(store)) {
|
|
217
|
+
closingMap.set(store, true);
|
|
218
|
+
store.getState().modals.slice().reverse().forEach((modal) => handleCloseModal(modal, canceled));
|
|
219
|
+
closingMap.set(store, false);
|
|
220
|
+
}
|
|
221
|
+
dispatch({
|
|
222
|
+
type: "CLOSE_ALL",
|
|
223
|
+
canceled
|
|
224
|
+
}, store);
|
|
225
|
+
}
|
|
226
|
+
function updateModalAction(payload, store = modalsStore) {
|
|
227
|
+
const { modalId, ...newProps } = payload;
|
|
228
|
+
dispatch({
|
|
229
|
+
type: "UPDATE",
|
|
230
|
+
modalId,
|
|
231
|
+
newProps
|
|
232
|
+
}, store);
|
|
233
|
+
}
|
|
234
|
+
function updateContextModalAction(payload, store = modalsStore) {
|
|
235
|
+
const { modalId, ...newProps } = payload;
|
|
236
|
+
dispatch({
|
|
237
|
+
type: "UPDATE",
|
|
238
|
+
modalId,
|
|
239
|
+
newProps
|
|
240
|
+
}, store);
|
|
241
|
+
}
|
|
242
|
+
function openContextModalPayload(payload, store = modalsStore) {
|
|
243
|
+
const { modal, ...rest } = payload;
|
|
244
|
+
return openContextModalAction(modal, rest, store);
|
|
245
|
+
}
|
|
246
|
+
var modals = {
|
|
247
|
+
open: (props) => openModalAction(props),
|
|
248
|
+
close: (id) => closeModalAction(id),
|
|
249
|
+
closeAll: () => closeAllModalsAction(),
|
|
250
|
+
openConfirmModal: (props) => openConfirmModalAction(props),
|
|
251
|
+
openContextModal: (payload) => openContextModalPayload(payload),
|
|
252
|
+
updateModal: (payload) => updateModalAction(payload),
|
|
253
|
+
updateContextModal: (payload) => updateContextModalAction(payload)
|
|
254
|
+
};
|
|
255
|
+
var openModal = modals.open;
|
|
256
|
+
var closeModal = modals.close;
|
|
257
|
+
var closeAllModals = modals.closeAll;
|
|
258
|
+
var openConfirmModal = modals.openConfirmModal;
|
|
259
|
+
var openContextModal = modals.openContextModal;
|
|
260
|
+
var updateModal = modals.updateModal;
|
|
261
|
+
var updateContextModal = modals.updateContextModal;
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/ModalsProvider.ts
|
|
264
|
+
function separateConfirmModalProps(props) {
|
|
265
|
+
const { id, children: _children, onCancel, onConfirm, closeOnConfirm, closeOnCancel, cancelProps, confirmProps, groupProps, labels, ...modalProps } = props;
|
|
266
|
+
return {
|
|
267
|
+
confirmModalProps: {
|
|
268
|
+
id,
|
|
269
|
+
onCancel,
|
|
270
|
+
onConfirm,
|
|
271
|
+
closeOnConfirm,
|
|
272
|
+
closeOnCancel,
|
|
273
|
+
cancelProps,
|
|
274
|
+
confirmProps,
|
|
275
|
+
groupProps,
|
|
276
|
+
labels
|
|
277
|
+
},
|
|
278
|
+
modalProps: {
|
|
279
|
+
id,
|
|
280
|
+
...modalProps
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
var ModalsProvider = (0, vue.defineComponent)({
|
|
285
|
+
name: "ModalsProvider",
|
|
286
|
+
props: {
|
|
287
|
+
modals: {
|
|
288
|
+
type: Object,
|
|
289
|
+
default: void 0
|
|
290
|
+
},
|
|
291
|
+
modalProps: {
|
|
292
|
+
type: Object,
|
|
293
|
+
default: void 0
|
|
294
|
+
},
|
|
295
|
+
labels: {
|
|
296
|
+
type: Object,
|
|
297
|
+
default: void 0
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
setup(props, { slots }) {
|
|
301
|
+
const state = useModalsState(modalsStore);
|
|
302
|
+
const openModal = (settings) => openModalAction(settings, modalsStore);
|
|
303
|
+
const openConfirmModal = (settings) => openConfirmModalAction(settings, modalsStore);
|
|
304
|
+
const openContextModal = (modal, settings) => openContextModalAction(modal, settings, modalsStore);
|
|
305
|
+
const closeModal = (id, canceled) => closeModalAction(id, canceled, modalsStore);
|
|
306
|
+
const closeAll = () => closeAllModalsAction(void 0, modalsStore);
|
|
307
|
+
const updateModal = (payload) => updateModalAction(payload, modalsStore);
|
|
308
|
+
const updateContextModal = (payload) => updateContextModalAction(payload, modalsStore);
|
|
309
|
+
const ctx = {
|
|
310
|
+
get modalProps() {
|
|
311
|
+
return props.modalProps || {};
|
|
312
|
+
},
|
|
313
|
+
get modals() {
|
|
314
|
+
return state.value.modals;
|
|
315
|
+
},
|
|
316
|
+
openModal,
|
|
317
|
+
openConfirmModal,
|
|
318
|
+
openContextModal,
|
|
319
|
+
closeModal,
|
|
320
|
+
closeContextModal: closeModal,
|
|
321
|
+
closeAll,
|
|
322
|
+
updateModal,
|
|
323
|
+
updateContextModal
|
|
324
|
+
};
|
|
325
|
+
(0, vue.provide)(ModalsContextKey, ctx);
|
|
326
|
+
return () => {
|
|
327
|
+
const current = state.value.current;
|
|
328
|
+
let currentModalProps = {};
|
|
329
|
+
let content = null;
|
|
330
|
+
if (current) if (current.type === "context") {
|
|
331
|
+
const { innerProps, ...rest } = current.props;
|
|
332
|
+
currentModalProps = rest;
|
|
333
|
+
const ContextModalComponent = props.modals?.[current.ctx];
|
|
334
|
+
content = ContextModalComponent ? (0, vue.h)(ContextModalComponent, {
|
|
335
|
+
innerProps,
|
|
336
|
+
context: ctx,
|
|
337
|
+
id: current.id
|
|
338
|
+
}) : null;
|
|
339
|
+
} else if (current.type === "confirm") {
|
|
340
|
+
const { confirmModalProps, modalProps: separatedModalProps } = separateConfirmModalProps(current.props);
|
|
341
|
+
currentModalProps = separatedModalProps;
|
|
342
|
+
content = (0, vue.h)(ConfirmModal, {
|
|
343
|
+
...confirmModalProps,
|
|
344
|
+
id: current.id,
|
|
345
|
+
labels: current.props.labels || props.labels
|
|
346
|
+
});
|
|
347
|
+
} else {
|
|
348
|
+
const { children, ...rest } = current.props;
|
|
349
|
+
currentModalProps = rest;
|
|
350
|
+
content = typeof children === "function" ? children() : children ?? null;
|
|
351
|
+
}
|
|
352
|
+
return [(0, vue.h)(_mantine_vue_core.Modal, {
|
|
353
|
+
zIndex: (0, _mantine_vue_core.getDefaultZIndex)("modal") + 1,
|
|
354
|
+
...props.modalProps,
|
|
355
|
+
...currentModalProps,
|
|
356
|
+
opened: state.value.modals.length > 0,
|
|
357
|
+
onClose: () => closeModal(state.value.current?.id)
|
|
358
|
+
}, () => content), slots.default?.()];
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
//#endregion
|
|
363
|
+
exports.ConfirmModal = ConfirmModal;
|
|
364
|
+
exports.ModalsProvider = ModalsProvider;
|
|
365
|
+
exports.closeAllModals = closeAllModals;
|
|
366
|
+
exports.closeAllModalsAction = closeAllModalsAction;
|
|
367
|
+
exports.closeModal = closeModal;
|
|
368
|
+
exports.closeModalAction = closeModalAction;
|
|
369
|
+
exports.createModalsStore = createModalsStore;
|
|
370
|
+
exports.handleCloseModal = handleCloseModal;
|
|
371
|
+
exports.modals = modals;
|
|
372
|
+
exports.modalsReducer = modalsReducer;
|
|
373
|
+
exports.modalsStore = modalsStore;
|
|
374
|
+
exports.openConfirmModal = openConfirmModal;
|
|
375
|
+
exports.openConfirmModalAction = openConfirmModalAction;
|
|
376
|
+
exports.openContextModal = openContextModal;
|
|
377
|
+
exports.openContextModalAction = openContextModalAction;
|
|
378
|
+
exports.openModal = openModal;
|
|
379
|
+
exports.openModalAction = openModalAction;
|
|
380
|
+
exports.updateContextModal = updateContextModal;
|
|
381
|
+
exports.updateContextModalAction = updateContextModalAction;
|
|
382
|
+
exports.updateModal = updateModal;
|
|
383
|
+
exports.updateModalAction = updateModalAction;
|
|
384
|
+
exports.useModals = useModals;
|
|
385
|
+
exports.useModalsState = useModalsState;
|
|
386
|
+
|
|
387
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/context.ts","../src/use-modals.ts","../src/ConfirmModal.ts","../src/reducer.ts","../src/modals.store.ts","../src/ModalsProvider.ts"],"sourcesContent":["import type { InjectionKey, VNodeChild } from 'vue'\nimport type { ModalProps } from '@mantine-vue/core'\nimport type { ConfirmModalProps } from './ConfirmModal'\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & {\n modalId?: string\n children?: VNodeChild | (() => VNodeChild)\n onClose?: () => void\n}\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', VNodeChild>\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\n\nexport interface OpenContextModal<\n CustomProps extends Record<string, any> = Record<string, any>,\n> extends ModalSettings {\n innerProps: CustomProps\n}\n\nexport interface ContextModalProps<T extends Record<string, any> = Record<string, any>> {\n context: ModalsContextProps\n innerProps: T\n id: string\n}\n\nexport type ModalState =\n | { id: string; type: 'content'; props: ModalSettings }\n | { id: string; type: 'confirm'; props: OpenConfirmModal }\n | { id: string; type: 'context'; props: OpenContextModal; ctx: string }\n\nexport interface ModalsContextProps {\n modalProps: ModalSettings\n modals: ModalState[]\n openModal: (props: ModalSettings) => string\n openConfirmModal: (props: OpenConfirmModal) => string\n openContextModal: (modal: string, props: OpenContextModal) => string\n closeModal: (id: string, canceled?: boolean) => void\n closeContextModal: (id: string, canceled?: boolean) => void\n closeAll: () => void\n updateModal: (payload: { modalId: string } & Partial<OpenConfirmModal>) => void\n updateContextModal: (payload: { modalId: string } & Partial<OpenContextModal<any>>) => void\n}\n\nexport const ModalsContextKey: InjectionKey<ModalsContextProps> = Symbol('ModalsContext')\n","import { inject } from 'vue'\nimport { ModalsContextKey, type ModalsContextProps } from './context'\n\nexport function useModals(): ModalsContextProps {\n const ctx = inject(ModalsContextKey, null)\n\n if (!ctx) {\n throw new Error(\n '[@mantine-vue/modals] useModals composable was called outside of context, wrap your app with the ModalsProvider component',\n )\n }\n\n return ctx\n}\n","import { defineComponent, h, type PropType } from 'vue'\nimport { Box, Button, Group } from '@mantine-vue/core'\nimport type { ConfirmLabels } from './context'\nimport { useModals } from './use-modals'\n\nexport interface ConfirmModalProps {\n id?: string\n onCancel?: () => void\n onConfirm?: () => void\n closeOnConfirm?: boolean\n closeOnCancel?: boolean\n cancelProps?: Record<string, any>\n confirmProps?: Record<string, any>\n groupProps?: Record<string, any>\n labels?: ConfirmLabels\n}\n\nexport const ConfirmModal = defineComponent({\n name: 'ConfirmModal',\n inheritAttrs: false,\n props: {\n id: { type: String, default: undefined },\n onCancel: { type: Function as PropType<() => void>, default: undefined },\n onConfirm: { type: Function as PropType<() => void>, default: undefined },\n closeOnConfirm: { type: Boolean, default: true },\n closeOnCancel: { type: Boolean, default: true },\n cancelProps: { type: Object as PropType<Record<string, any>>, default: undefined },\n confirmProps: { type: Object as PropType<Record<string, any>>, default: undefined },\n groupProps: { type: Object as PropType<Record<string, any>>, default: undefined },\n labels: {\n type: Object as PropType<ConfirmLabels>,\n default: () => ({ cancel: '', confirm: '' }),\n },\n },\n setup(props, { slots }) {\n const ctx = useModals()\n\n const handleCancel = (event: MouseEvent) => {\n props.cancelProps?.onClick?.(event)\n props.onCancel?.()\n if (props.closeOnCancel) {\n ctx.closeModal(props.id!)\n }\n }\n\n const handleConfirm = (event: MouseEvent) => {\n props.confirmProps?.onClick?.(event)\n props.onConfirm?.()\n if (props.closeOnConfirm) {\n ctx.closeModal(props.id!)\n }\n }\n\n return () => {\n const children = slots.default?.()\n const hasChildren = !!children && children.length > 0\n\n return [\n hasChildren ? h(Box, { mb: 'md' }, () => children) : null,\n h(Group, { mt: hasChildren ? 0 : 'md', justify: 'flex-end', ...props.groupProps }, () => [\n h(\n Button,\n { variant: 'default', ...props.cancelProps, onClick: handleCancel },\n () => props.cancelProps?.children ?? props.labels?.cancel,\n ),\n h(\n Button,\n { ...props.confirmProps, onClick: handleConfirm },\n () => props.confirmProps?.children ?? props.labels?.confirm,\n ),\n ]),\n ]\n }\n },\n})\n","import type { ModalSettings, ModalState } from './context'\n\nexport interface ModalsState {\n modals: ModalState[]\n current: ModalState | null\n}\n\nexport interface OpenAction {\n type: 'OPEN'\n modal: ModalState\n}\n\nexport interface CloseAction {\n type: 'CLOSE'\n modalId: string\n canceled?: boolean\n}\n\nexport interface CloseAllAction {\n type: 'CLOSE_ALL'\n canceled?: boolean\n}\n\nexport interface UpdateAction {\n type: 'UPDATE'\n modalId: string\n newProps: Partial<ModalSettings>\n}\n\nexport type ModalsAction = OpenAction | CloseAction | CloseAllAction | UpdateAction\n\nexport function handleCloseModal(modal: ModalState, canceled?: boolean) {\n if (canceled && modal.type === 'confirm') {\n modal.props.onCancel?.()\n }\n\n modal.props.onClose?.()\n}\n\nexport function modalsReducer(state: ModalsState, action: ModalsAction): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n if (state.modals.some((modal) => modal.id === action.modal.id)) {\n return state\n }\n\n return {\n current: action.modal,\n modals: [...state.modals, action.modal],\n }\n }\n\n case 'CLOSE': {\n const modals = state.modals.filter((modal) => modal.id !== action.modalId)\n return {\n current: modals.length > 0 ? modals[modals.length - 1] : state.current,\n modals,\n }\n }\n\n case 'CLOSE_ALL': {\n return {\n current: state.current,\n modals: [],\n }\n }\n\n case 'UPDATE': {\n const modals = state.modals.map((modal) => {\n if (modal.id !== action.modalId) {\n return modal\n }\n\n if (modal.type === 'context') {\n return {\n ...modal,\n props: {\n ...modal.props,\n ...action.newProps,\n innerProps: {\n ...modal.props.innerProps,\n ...(action.newProps as any).innerProps,\n },\n },\n }\n }\n\n return { ...modal, props: { ...modal.props, ...action.newProps } } as ModalState\n })\n\n const current =\n state.current && state.current.id === action.modalId\n ? modals.find((modal) => modal.id === action.modalId) || state.current\n : state.current\n\n return { current, modals }\n }\n\n default:\n return state\n }\n}\n","import { type Ref } from 'vue'\nimport { createStore, type MantineStore } from '@mantine-vue/store'\nimport type { ModalSettings, OpenConfirmModal, OpenContextModal } from './context'\nimport { handleCloseModal, modalsReducer, type ModalsAction, type ModalsState } from './reducer'\n\nexport type ModalsStore = MantineStore<ModalsState>\n\nfunction randomId() {\n return `mantine-${Math.random().toString(36).slice(2, 11)}`\n}\n\nexport const createModalsStore = () => createStore<ModalsState>({ modals: [], current: null })\n\nexport const modalsStore = createModalsStore()\n\nexport const useModalsState = (store: ModalsStore = modalsStore): Readonly<Ref<ModalsState>> =>\n store.value\n\nconst closingMap = new WeakMap<ModalsStore, boolean>()\n\nfunction dispatch(action: ModalsAction, store: ModalsStore) {\n store.setState((state) => modalsReducer(state, action))\n}\n\nexport function openModalAction(props: ModalSettings, store: ModalsStore = modalsStore): string {\n const { modalId, ...rest } = props\n const id = modalId || randomId()\n dispatch({ type: 'OPEN', modal: { id, type: 'content', props: rest } }, store)\n return id\n}\n\nexport function openConfirmModalAction(\n props: OpenConfirmModal,\n store: ModalsStore = modalsStore,\n): string {\n const { modalId, ...rest } = props\n const id = modalId || randomId()\n dispatch({ type: 'OPEN', modal: { id, type: 'confirm', props: rest } }, store)\n return id\n}\n\nexport function openContextModalAction(\n modal: string,\n props: OpenContextModal,\n store: ModalsStore = modalsStore,\n): string {\n const { modalId, ...rest } = props\n const id = modalId || randomId()\n dispatch({ type: 'OPEN', modal: { id, type: 'context', props: rest, ctx: modal } }, store)\n return id\n}\n\nexport function closeModalAction(id: string, canceled?: boolean, store: ModalsStore = modalsStore) {\n if (!closingMap.get(store)) {\n const modal = store.getState().modals.find((item) => item.id === id)\n if (modal) {\n closingMap.set(store, true)\n handleCloseModal(modal, canceled)\n closingMap.set(store, false)\n }\n }\n\n dispatch({ type: 'CLOSE', modalId: id, canceled }, store)\n}\n\nexport function closeAllModalsAction(canceled?: boolean, store: ModalsStore = modalsStore) {\n if (!closingMap.get(store)) {\n closingMap.set(store, true)\n store\n .getState()\n .modals.slice()\n .reverse()\n .forEach((modal) => handleCloseModal(modal, canceled))\n closingMap.set(store, false)\n }\n\n dispatch({ type: 'CLOSE_ALL', canceled }, store)\n}\n\nexport function updateModalAction(\n payload: { modalId: string } & Partial<ModalSettings>,\n store: ModalsStore = modalsStore,\n) {\n const { modalId, ...newProps } = payload\n dispatch({ type: 'UPDATE', modalId, newProps }, store)\n}\n\nexport function updateContextModalAction(\n payload: { modalId: string } & Partial<OpenContextModal<any>>,\n store: ModalsStore = modalsStore,\n) {\n const { modalId, ...newProps } = payload\n dispatch({ type: 'UPDATE', modalId, newProps }, store)\n}\n\nfunction openContextModalPayload(\n payload: OpenContextModal & { modal: string },\n store: ModalsStore = modalsStore,\n): string {\n const { modal, ...rest } = payload\n return openContextModalAction(modal, rest, store)\n}\n\nexport const modals = {\n open: (props: ModalSettings) => openModalAction(props),\n close: (id: string) => closeModalAction(id),\n closeAll: () => closeAllModalsAction(),\n openConfirmModal: (props: OpenConfirmModal) => openConfirmModalAction(props),\n openContextModal: (payload: OpenContextModal & { modal: string }) =>\n openContextModalPayload(payload),\n updateModal: (payload: { modalId: string } & Partial<OpenConfirmModal>) =>\n updateModalAction(payload),\n updateContextModal: (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n updateContextModalAction(payload),\n} as const\n\nexport const openModal = modals.open\nexport const closeModal = modals.close\nexport const closeAllModals = modals.closeAll\nexport const openConfirmModal = modals.openConfirmModal\nexport const openContextModal = modals.openContextModal\nexport const updateModal = modals.updateModal\nexport const updateContextModal = modals.updateContextModal\n","import { defineComponent, h, provide, type PropType, type VNodeChild } from 'vue'\nimport { getDefaultZIndex, Modal } from '@mantine-vue/core'\nimport { ConfirmModal } from './ConfirmModal'\nimport {\n ModalsContextKey,\n type ConfirmLabels,\n type ModalsContextProps,\n type ModalSettings,\n type OpenConfirmModal,\n type OpenContextModal,\n} from './context'\nimport {\n closeAllModalsAction,\n closeModalAction,\n modalsStore,\n openConfirmModalAction,\n openContextModalAction,\n openModalAction,\n updateContextModalAction,\n updateModalAction,\n useModalsState,\n} from './modals.store'\n\nexport interface ModalsProviderProps {\n modals?: Record<string, any>\n modalProps?: ModalSettings\n labels?: ConfirmLabels\n}\n\nfunction separateConfirmModalProps(props: OpenConfirmModal) {\n const {\n id,\n children: _children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...modalProps\n } = props as any\n\n return {\n confirmModalProps: {\n id,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n },\n modalProps: { id, ...modalProps },\n }\n}\n\nexport const ModalsProvider = defineComponent({\n name: 'ModalsProvider',\n props: {\n modals: { type: Object as PropType<Record<string, any>>, default: undefined },\n modalProps: { type: Object as PropType<ModalSettings>, default: undefined },\n labels: { type: Object as PropType<ConfirmLabels>, default: undefined },\n },\n setup(props, { slots }) {\n const state = useModalsState(modalsStore)\n\n const openModal = (settings: ModalSettings) => openModalAction(settings, modalsStore)\n const openConfirmModal = (settings: OpenConfirmModal) =>\n openConfirmModalAction(settings, modalsStore)\n const openContextModal = (modal: string, settings: OpenContextModal) =>\n openContextModalAction(modal, settings, modalsStore)\n const closeModal = (id: string, canceled?: boolean) =>\n closeModalAction(id, canceled, modalsStore)\n const closeAll = () => closeAllModalsAction(undefined, modalsStore)\n const updateModal = (payload: { modalId: string } & Partial<OpenConfirmModal>) =>\n updateModalAction(payload, modalsStore)\n const updateContextModal = (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n updateContextModalAction(payload, modalsStore)\n\n const ctx: ModalsContextProps = {\n get modalProps() {\n return props.modalProps || {}\n },\n get modals() {\n return state.value.modals\n },\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeContextModal: closeModal,\n closeAll,\n updateModal,\n updateContextModal,\n }\n\n provide(ModalsContextKey, ctx)\n\n return () => {\n const current = state.value.current\n let currentModalProps: Record<string, any> = {}\n let content: VNodeChild = null\n\n if (current) {\n if (current.type === 'context') {\n const { innerProps, ...rest } = current.props\n currentModalProps = rest\n const ContextModalComponent = props.modals?.[current.ctx]\n content = ContextModalComponent\n ? h(ContextModalComponent, { innerProps, context: ctx, id: current.id })\n : null\n } else if (current.type === 'confirm') {\n const { confirmModalProps, modalProps: separatedModalProps } = separateConfirmModalProps(\n current.props,\n )\n currentModalProps = separatedModalProps\n content = h(ConfirmModal, {\n ...confirmModalProps,\n id: current.id,\n labels: current.props.labels || props.labels,\n })\n } else {\n const { children, ...rest } = current.props as any\n currentModalProps = rest\n content = typeof children === 'function' ? children() : (children ?? null)\n }\n }\n\n return [\n h(\n Modal,\n {\n zIndex: getDefaultZIndex('modal') + 1,\n ...props.modalProps,\n ...currentModalProps,\n opened: state.value.modals.length > 0,\n onClose: () => closeModal(state.value.current?.id as string),\n },\n () => content,\n ),\n slots.default?.(),\n ]\n }\n },\n})\n"],"mappings":";;;;;AA4CA,IAAa,mBAAqD,OAAO,eAAe;;;ACzCxF,SAAgB,YAAgC;CAC9C,MAAM,OAAA,GAAA,IAAA,QAAa,kBAAkB,IAAI;CAEzC,IAAI,CAAC,KACH,MAAM,IAAI,MACR,2HACF;CAGF,OAAO;AACT;;;ACIA,IAAa,gBAAA,GAAA,IAAA,iBAA+B;CAC1C,MAAM;CACN,cAAc;CACd,OAAO;EACL,IAAI;GAAE,MAAM;GAAQ,SAAS,KAAA;EAAU;EACvC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W;IAC9B,MAAM,EAAE,YAAY,GAAG,SAAS,QAAQ;IACxC,oBAAoB;IACpB,MAAM,wBAAwB,MAAM,SAAS,QAAQ;IACrD,UAAU,yBAAA,GAAA,IAAA,GACJ,uBAAuB;KAAE;KAAY,SAAS;KAAK,IAAI,QAAQ;IAAG,CAAC,IACrE;GACN,OAAO,IAAI,QAAQ,SAAS,WAAW;IACrC,MAAM,EAAE,mBAAmB,YAAY,wBAAwB,0BAC7D,QAAQ,KACV;IACA,oBAAoB;IACpB,WAAA,GAAA,IAAA,GAAY,cAAc;KACxB,GAAG;KACH,IAAI,QAAQ;KACZ,QAAQ,QAAQ,MAAM,UAAU,MAAM;IACxC,CAAC;GACH,OAAO;IACL,MAAM,EAAE,UAAU,GAAG,SAAS,QAAQ;IACtC,oBAAoB;IACpB,UAAU,OAAO,aAAa,aAAa,SAAS,IAAK,YAAY;GACvE;GAGF,OAAO,EAAA,GAAA,IAAA,GAEH,kBAAA,OACA;IACE,SAAA,GAAA,kBAAA,kBAAyB,OAAO,IAAI;IACpC,GAAG,MAAM;IACT,GAAG;IACH,QAAQ,MAAM,MAAM,OAAO,SAAS;IACpC,eAAe,WAAW,MAAM,MAAM,SAAS,EAAY;GAC7D,SACM,OACR,GACA,MAAM,UAAU,CAClB;EACF;CACF;AACF,CAAC"}
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { defineComponent, h, inject, provide } from "vue";
|
|
2
|
+
import { Box, Button, Group, Modal, getDefaultZIndex } from "@mantine-vue/core";
|
|
3
|
+
import { createStore } from "@mantine-vue/store";
|
|
4
|
+
//#region src/context.ts
|
|
5
|
+
var ModalsContextKey = Symbol("ModalsContext");
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/use-modals.ts
|
|
8
|
+
function useModals() {
|
|
9
|
+
const ctx = inject(ModalsContextKey, null);
|
|
10
|
+
if (!ctx) throw new Error("[@mantine-vue/modals] useModals composable was called outside of context, wrap your app with the ModalsProvider component");
|
|
11
|
+
return ctx;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/ConfirmModal.ts
|
|
15
|
+
var ConfirmModal = defineComponent({
|
|
16
|
+
name: "ConfirmModal",
|
|
17
|
+
inheritAttrs: false,
|
|
18
|
+
props: {
|
|
19
|
+
id: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: void 0
|
|
22
|
+
},
|
|
23
|
+
onCancel: {
|
|
24
|
+
type: Function,
|
|
25
|
+
default: void 0
|
|
26
|
+
},
|
|
27
|
+
onConfirm: {
|
|
28
|
+
type: Function,
|
|
29
|
+
default: void 0
|
|
30
|
+
},
|
|
31
|
+
closeOnConfirm: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: true
|
|
34
|
+
},
|
|
35
|
+
closeOnCancel: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: true
|
|
38
|
+
},
|
|
39
|
+
cancelProps: {
|
|
40
|
+
type: Object,
|
|
41
|
+
default: void 0
|
|
42
|
+
},
|
|
43
|
+
confirmProps: {
|
|
44
|
+
type: Object,
|
|
45
|
+
default: void 0
|
|
46
|
+
},
|
|
47
|
+
groupProps: {
|
|
48
|
+
type: Object,
|
|
49
|
+
default: void 0
|
|
50
|
+
},
|
|
51
|
+
labels: {
|
|
52
|
+
type: Object,
|
|
53
|
+
default: () => ({
|
|
54
|
+
cancel: "",
|
|
55
|
+
confirm: ""
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
setup(props, { slots }) {
|
|
60
|
+
const ctx = useModals();
|
|
61
|
+
const handleCancel = (event) => {
|
|
62
|
+
props.cancelProps?.onClick?.(event);
|
|
63
|
+
props.onCancel?.();
|
|
64
|
+
if (props.closeOnCancel) ctx.closeModal(props.id);
|
|
65
|
+
};
|
|
66
|
+
const handleConfirm = (event) => {
|
|
67
|
+
props.confirmProps?.onClick?.(event);
|
|
68
|
+
props.onConfirm?.();
|
|
69
|
+
if (props.closeOnConfirm) ctx.closeModal(props.id);
|
|
70
|
+
};
|
|
71
|
+
return () => {
|
|
72
|
+
const children = slots.default?.();
|
|
73
|
+
const hasChildren = !!children && children.length > 0;
|
|
74
|
+
return [hasChildren ? h(Box, { mb: "md" }, () => children) : null, h(Group, {
|
|
75
|
+
mt: hasChildren ? 0 : "md",
|
|
76
|
+
justify: "flex-end",
|
|
77
|
+
...props.groupProps
|
|
78
|
+
}, () => [h(Button, {
|
|
79
|
+
variant: "default",
|
|
80
|
+
...props.cancelProps,
|
|
81
|
+
onClick: handleCancel
|
|
82
|
+
}, () => props.cancelProps?.children ?? props.labels?.cancel), h(Button, {
|
|
83
|
+
...props.confirmProps,
|
|
84
|
+
onClick: handleConfirm
|
|
85
|
+
}, () => props.confirmProps?.children ?? props.labels?.confirm)])];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/reducer.ts
|
|
91
|
+
function handleCloseModal(modal, canceled) {
|
|
92
|
+
if (canceled && modal.type === "confirm") modal.props.onCancel?.();
|
|
93
|
+
modal.props.onClose?.();
|
|
94
|
+
}
|
|
95
|
+
function modalsReducer(state, action) {
|
|
96
|
+
switch (action.type) {
|
|
97
|
+
case "OPEN":
|
|
98
|
+
if (state.modals.some((modal) => modal.id === action.modal.id)) return state;
|
|
99
|
+
return {
|
|
100
|
+
current: action.modal,
|
|
101
|
+
modals: [...state.modals, action.modal]
|
|
102
|
+
};
|
|
103
|
+
case "CLOSE": {
|
|
104
|
+
const modals = state.modals.filter((modal) => modal.id !== action.modalId);
|
|
105
|
+
return {
|
|
106
|
+
current: modals.length > 0 ? modals[modals.length - 1] : state.current,
|
|
107
|
+
modals
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
case "CLOSE_ALL": return {
|
|
111
|
+
current: state.current,
|
|
112
|
+
modals: []
|
|
113
|
+
};
|
|
114
|
+
case "UPDATE": {
|
|
115
|
+
const modals = state.modals.map((modal) => {
|
|
116
|
+
if (modal.id !== action.modalId) return modal;
|
|
117
|
+
if (modal.type === "context") return {
|
|
118
|
+
...modal,
|
|
119
|
+
props: {
|
|
120
|
+
...modal.props,
|
|
121
|
+
...action.newProps,
|
|
122
|
+
innerProps: {
|
|
123
|
+
...modal.props.innerProps,
|
|
124
|
+
...action.newProps.innerProps
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
...modal,
|
|
130
|
+
props: {
|
|
131
|
+
...modal.props,
|
|
132
|
+
...action.newProps
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
current: state.current && state.current.id === action.modalId ? modals.find((modal) => modal.id === action.modalId) || state.current : state.current,
|
|
138
|
+
modals
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
default: return state;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/modals.store.ts
|
|
146
|
+
function randomId() {
|
|
147
|
+
return `mantine-${Math.random().toString(36).slice(2, 11)}`;
|
|
148
|
+
}
|
|
149
|
+
var createModalsStore = () => createStore({
|
|
150
|
+
modals: [],
|
|
151
|
+
current: null
|
|
152
|
+
});
|
|
153
|
+
var modalsStore = createModalsStore();
|
|
154
|
+
var useModalsState = (store = modalsStore) => store.value;
|
|
155
|
+
var closingMap = /* @__PURE__ */ new WeakMap();
|
|
156
|
+
function dispatch(action, store) {
|
|
157
|
+
store.setState((state) => modalsReducer(state, action));
|
|
158
|
+
}
|
|
159
|
+
function openModalAction(props, store = modalsStore) {
|
|
160
|
+
const { modalId, ...rest } = props;
|
|
161
|
+
const id = modalId || randomId();
|
|
162
|
+
dispatch({
|
|
163
|
+
type: "OPEN",
|
|
164
|
+
modal: {
|
|
165
|
+
id,
|
|
166
|
+
type: "content",
|
|
167
|
+
props: rest
|
|
168
|
+
}
|
|
169
|
+
}, store);
|
|
170
|
+
return id;
|
|
171
|
+
}
|
|
172
|
+
function openConfirmModalAction(props, store = modalsStore) {
|
|
173
|
+
const { modalId, ...rest } = props;
|
|
174
|
+
const id = modalId || randomId();
|
|
175
|
+
dispatch({
|
|
176
|
+
type: "OPEN",
|
|
177
|
+
modal: {
|
|
178
|
+
id,
|
|
179
|
+
type: "confirm",
|
|
180
|
+
props: rest
|
|
181
|
+
}
|
|
182
|
+
}, store);
|
|
183
|
+
return id;
|
|
184
|
+
}
|
|
185
|
+
function openContextModalAction(modal, props, store = modalsStore) {
|
|
186
|
+
const { modalId, ...rest } = props;
|
|
187
|
+
const id = modalId || randomId();
|
|
188
|
+
dispatch({
|
|
189
|
+
type: "OPEN",
|
|
190
|
+
modal: {
|
|
191
|
+
id,
|
|
192
|
+
type: "context",
|
|
193
|
+
props: rest,
|
|
194
|
+
ctx: modal
|
|
195
|
+
}
|
|
196
|
+
}, store);
|
|
197
|
+
return id;
|
|
198
|
+
}
|
|
199
|
+
function closeModalAction(id, canceled, store = modalsStore) {
|
|
200
|
+
if (!closingMap.get(store)) {
|
|
201
|
+
const modal = store.getState().modals.find((item) => item.id === id);
|
|
202
|
+
if (modal) {
|
|
203
|
+
closingMap.set(store, true);
|
|
204
|
+
handleCloseModal(modal, canceled);
|
|
205
|
+
closingMap.set(store, false);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
dispatch({
|
|
209
|
+
type: "CLOSE",
|
|
210
|
+
modalId: id,
|
|
211
|
+
canceled
|
|
212
|
+
}, store);
|
|
213
|
+
}
|
|
214
|
+
function closeAllModalsAction(canceled, store = modalsStore) {
|
|
215
|
+
if (!closingMap.get(store)) {
|
|
216
|
+
closingMap.set(store, true);
|
|
217
|
+
store.getState().modals.slice().reverse().forEach((modal) => handleCloseModal(modal, canceled));
|
|
218
|
+
closingMap.set(store, false);
|
|
219
|
+
}
|
|
220
|
+
dispatch({
|
|
221
|
+
type: "CLOSE_ALL",
|
|
222
|
+
canceled
|
|
223
|
+
}, store);
|
|
224
|
+
}
|
|
225
|
+
function updateModalAction(payload, store = modalsStore) {
|
|
226
|
+
const { modalId, ...newProps } = payload;
|
|
227
|
+
dispatch({
|
|
228
|
+
type: "UPDATE",
|
|
229
|
+
modalId,
|
|
230
|
+
newProps
|
|
231
|
+
}, store);
|
|
232
|
+
}
|
|
233
|
+
function updateContextModalAction(payload, store = modalsStore) {
|
|
234
|
+
const { modalId, ...newProps } = payload;
|
|
235
|
+
dispatch({
|
|
236
|
+
type: "UPDATE",
|
|
237
|
+
modalId,
|
|
238
|
+
newProps
|
|
239
|
+
}, store);
|
|
240
|
+
}
|
|
241
|
+
function openContextModalPayload(payload, store = modalsStore) {
|
|
242
|
+
const { modal, ...rest } = payload;
|
|
243
|
+
return openContextModalAction(modal, rest, store);
|
|
244
|
+
}
|
|
245
|
+
var modals = {
|
|
246
|
+
open: (props) => openModalAction(props),
|
|
247
|
+
close: (id) => closeModalAction(id),
|
|
248
|
+
closeAll: () => closeAllModalsAction(),
|
|
249
|
+
openConfirmModal: (props) => openConfirmModalAction(props),
|
|
250
|
+
openContextModal: (payload) => openContextModalPayload(payload),
|
|
251
|
+
updateModal: (payload) => updateModalAction(payload),
|
|
252
|
+
updateContextModal: (payload) => updateContextModalAction(payload)
|
|
253
|
+
};
|
|
254
|
+
var openModal = modals.open;
|
|
255
|
+
var closeModal = modals.close;
|
|
256
|
+
var closeAllModals = modals.closeAll;
|
|
257
|
+
var openConfirmModal = modals.openConfirmModal;
|
|
258
|
+
var openContextModal = modals.openContextModal;
|
|
259
|
+
var updateModal = modals.updateModal;
|
|
260
|
+
var updateContextModal = modals.updateContextModal;
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/ModalsProvider.ts
|
|
263
|
+
function separateConfirmModalProps(props) {
|
|
264
|
+
const { id, children: _children, onCancel, onConfirm, closeOnConfirm, closeOnCancel, cancelProps, confirmProps, groupProps, labels, ...modalProps } = props;
|
|
265
|
+
return {
|
|
266
|
+
confirmModalProps: {
|
|
267
|
+
id,
|
|
268
|
+
onCancel,
|
|
269
|
+
onConfirm,
|
|
270
|
+
closeOnConfirm,
|
|
271
|
+
closeOnCancel,
|
|
272
|
+
cancelProps,
|
|
273
|
+
confirmProps,
|
|
274
|
+
groupProps,
|
|
275
|
+
labels
|
|
276
|
+
},
|
|
277
|
+
modalProps: {
|
|
278
|
+
id,
|
|
279
|
+
...modalProps
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
var ModalsProvider = defineComponent({
|
|
284
|
+
name: "ModalsProvider",
|
|
285
|
+
props: {
|
|
286
|
+
modals: {
|
|
287
|
+
type: Object,
|
|
288
|
+
default: void 0
|
|
289
|
+
},
|
|
290
|
+
modalProps: {
|
|
291
|
+
type: Object,
|
|
292
|
+
default: void 0
|
|
293
|
+
},
|
|
294
|
+
labels: {
|
|
295
|
+
type: Object,
|
|
296
|
+
default: void 0
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
setup(props, { slots }) {
|
|
300
|
+
const state = useModalsState(modalsStore);
|
|
301
|
+
const openModal = (settings) => openModalAction(settings, modalsStore);
|
|
302
|
+
const openConfirmModal = (settings) => openConfirmModalAction(settings, modalsStore);
|
|
303
|
+
const openContextModal = (modal, settings) => openContextModalAction(modal, settings, modalsStore);
|
|
304
|
+
const closeModal = (id, canceled) => closeModalAction(id, canceled, modalsStore);
|
|
305
|
+
const closeAll = () => closeAllModalsAction(void 0, modalsStore);
|
|
306
|
+
const updateModal = (payload) => updateModalAction(payload, modalsStore);
|
|
307
|
+
const updateContextModal = (payload) => updateContextModalAction(payload, modalsStore);
|
|
308
|
+
const ctx = {
|
|
309
|
+
get modalProps() {
|
|
310
|
+
return props.modalProps || {};
|
|
311
|
+
},
|
|
312
|
+
get modals() {
|
|
313
|
+
return state.value.modals;
|
|
314
|
+
},
|
|
315
|
+
openModal,
|
|
316
|
+
openConfirmModal,
|
|
317
|
+
openContextModal,
|
|
318
|
+
closeModal,
|
|
319
|
+
closeContextModal: closeModal,
|
|
320
|
+
closeAll,
|
|
321
|
+
updateModal,
|
|
322
|
+
updateContextModal
|
|
323
|
+
};
|
|
324
|
+
provide(ModalsContextKey, ctx);
|
|
325
|
+
return () => {
|
|
326
|
+
const current = state.value.current;
|
|
327
|
+
let currentModalProps = {};
|
|
328
|
+
let content = null;
|
|
329
|
+
if (current) if (current.type === "context") {
|
|
330
|
+
const { innerProps, ...rest } = current.props;
|
|
331
|
+
currentModalProps = rest;
|
|
332
|
+
const ContextModalComponent = props.modals?.[current.ctx];
|
|
333
|
+
content = ContextModalComponent ? h(ContextModalComponent, {
|
|
334
|
+
innerProps,
|
|
335
|
+
context: ctx,
|
|
336
|
+
id: current.id
|
|
337
|
+
}) : null;
|
|
338
|
+
} else if (current.type === "confirm") {
|
|
339
|
+
const { confirmModalProps, modalProps: separatedModalProps } = separateConfirmModalProps(current.props);
|
|
340
|
+
currentModalProps = separatedModalProps;
|
|
341
|
+
content = h(ConfirmModal, {
|
|
342
|
+
...confirmModalProps,
|
|
343
|
+
id: current.id,
|
|
344
|
+
labels: current.props.labels || props.labels
|
|
345
|
+
});
|
|
346
|
+
} else {
|
|
347
|
+
const { children, ...rest } = current.props;
|
|
348
|
+
currentModalProps = rest;
|
|
349
|
+
content = typeof children === "function" ? children() : children ?? null;
|
|
350
|
+
}
|
|
351
|
+
return [h(Modal, {
|
|
352
|
+
zIndex: getDefaultZIndex("modal") + 1,
|
|
353
|
+
...props.modalProps,
|
|
354
|
+
...currentModalProps,
|
|
355
|
+
opened: state.value.modals.length > 0,
|
|
356
|
+
onClose: () => closeModal(state.value.current?.id)
|
|
357
|
+
}, () => content), slots.default?.()];
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
//#endregion
|
|
362
|
+
export { ConfirmModal, ModalsProvider, closeAllModals, closeAllModalsAction, closeModal, closeModalAction, createModalsStore, handleCloseModal, modals, modalsReducer, modalsStore, openConfirmModal, openConfirmModalAction, openContextModal, openContextModalAction, openModal, openModalAction, updateContextModal, updateContextModalAction, updateModal, updateModalAction, useModals, useModalsState };
|
|
363
|
+
|
|
364
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/context.ts","../src/use-modals.ts","../src/ConfirmModal.ts","../src/reducer.ts","../src/modals.store.ts","../src/ModalsProvider.ts"],"sourcesContent":["import type { InjectionKey, VNodeChild } from 'vue'\nimport type { ModalProps } from '@mantine-vue/core'\nimport type { ConfirmModalProps } from './ConfirmModal'\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & {\n modalId?: string\n children?: VNodeChild | (() => VNodeChild)\n onClose?: () => void\n}\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', VNodeChild>\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\n\nexport interface OpenContextModal<\n CustomProps extends Record<string, any> = Record<string, any>,\n> extends ModalSettings {\n innerProps: CustomProps\n}\n\nexport interface ContextModalProps<T extends Record<string, any> = Record<string, any>> {\n context: ModalsContextProps\n innerProps: T\n id: string\n}\n\nexport type ModalState =\n | { id: string; type: 'content'; props: ModalSettings }\n | { id: string; type: 'confirm'; props: OpenConfirmModal }\n | { id: string; type: 'context'; props: OpenContextModal; ctx: string }\n\nexport interface ModalsContextProps {\n modalProps: ModalSettings\n modals: ModalState[]\n openModal: (props: ModalSettings) => string\n openConfirmModal: (props: OpenConfirmModal) => string\n openContextModal: (modal: string, props: OpenContextModal) => string\n closeModal: (id: string, canceled?: boolean) => void\n closeContextModal: (id: string, canceled?: boolean) => void\n closeAll: () => void\n updateModal: (payload: { modalId: string } & Partial<OpenConfirmModal>) => void\n updateContextModal: (payload: { modalId: string } & Partial<OpenContextModal<any>>) => void\n}\n\nexport const ModalsContextKey: InjectionKey<ModalsContextProps> = Symbol('ModalsContext')\n","import { inject } from 'vue'\nimport { ModalsContextKey, type ModalsContextProps } from './context'\n\nexport function useModals(): ModalsContextProps {\n const ctx = inject(ModalsContextKey, null)\n\n if (!ctx) {\n throw new Error(\n '[@mantine-vue/modals] useModals composable was called outside of context, wrap your app with the ModalsProvider component',\n )\n }\n\n return ctx\n}\n","import { defineComponent, h, type PropType } from 'vue'\nimport { Box, Button, Group } from '@mantine-vue/core'\nimport type { ConfirmLabels } from './context'\nimport { useModals } from './use-modals'\n\nexport interface ConfirmModalProps {\n id?: string\n onCancel?: () => void\n onConfirm?: () => void\n closeOnConfirm?: boolean\n closeOnCancel?: boolean\n cancelProps?: Record<string, any>\n confirmProps?: Record<string, any>\n groupProps?: Record<string, any>\n labels?: ConfirmLabels\n}\n\nexport const ConfirmModal = defineComponent({\n name: 'ConfirmModal',\n inheritAttrs: false,\n props: {\n id: { type: String, default: undefined },\n onCancel: { type: Function as PropType<() => void>, default: undefined },\n onConfirm: { type: Function as PropType<() => void>, default: undefined },\n closeOnConfirm: { type: Boolean, default: true },\n closeOnCancel: { type: Boolean, default: true },\n cancelProps: { type: Object as PropType<Record<string, any>>, default: undefined },\n confirmProps: { type: Object as PropType<Record<string, any>>, default: undefined },\n groupProps: { type: Object as PropType<Record<string, any>>, default: undefined },\n labels: {\n type: Object as PropType<ConfirmLabels>,\n default: () => ({ cancel: '', confirm: '' }),\n },\n },\n setup(props, { slots }) {\n const ctx = useModals()\n\n const handleCancel = (event: MouseEvent) => {\n props.cancelProps?.onClick?.(event)\n props.onCancel?.()\n if (props.closeOnCancel) {\n ctx.closeModal(props.id!)\n }\n }\n\n const handleConfirm = (event: MouseEvent) => {\n props.confirmProps?.onClick?.(event)\n props.onConfirm?.()\n if (props.closeOnConfirm) {\n ctx.closeModal(props.id!)\n }\n }\n\n return () => {\n const children = slots.default?.()\n const hasChildren = !!children && children.length > 0\n\n return [\n hasChildren ? h(Box, { mb: 'md' }, () => children) : null,\n h(Group, { mt: hasChildren ? 0 : 'md', justify: 'flex-end', ...props.groupProps }, () => [\n h(\n Button,\n { variant: 'default', ...props.cancelProps, onClick: handleCancel },\n () => props.cancelProps?.children ?? props.labels?.cancel,\n ),\n h(\n Button,\n { ...props.confirmProps, onClick: handleConfirm },\n () => props.confirmProps?.children ?? props.labels?.confirm,\n ),\n ]),\n ]\n }\n },\n})\n","import type { ModalSettings, ModalState } from './context'\n\nexport interface ModalsState {\n modals: ModalState[]\n current: ModalState | null\n}\n\nexport interface OpenAction {\n type: 'OPEN'\n modal: ModalState\n}\n\nexport interface CloseAction {\n type: 'CLOSE'\n modalId: string\n canceled?: boolean\n}\n\nexport interface CloseAllAction {\n type: 'CLOSE_ALL'\n canceled?: boolean\n}\n\nexport interface UpdateAction {\n type: 'UPDATE'\n modalId: string\n newProps: Partial<ModalSettings>\n}\n\nexport type ModalsAction = OpenAction | CloseAction | CloseAllAction | UpdateAction\n\nexport function handleCloseModal(modal: ModalState, canceled?: boolean) {\n if (canceled && modal.type === 'confirm') {\n modal.props.onCancel?.()\n }\n\n modal.props.onClose?.()\n}\n\nexport function modalsReducer(state: ModalsState, action: ModalsAction): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n if (state.modals.some((modal) => modal.id === action.modal.id)) {\n return state\n }\n\n return {\n current: action.modal,\n modals: [...state.modals, action.modal],\n }\n }\n\n case 'CLOSE': {\n const modals = state.modals.filter((modal) => modal.id !== action.modalId)\n return {\n current: modals.length > 0 ? modals[modals.length - 1] : state.current,\n modals,\n }\n }\n\n case 'CLOSE_ALL': {\n return {\n current: state.current,\n modals: [],\n }\n }\n\n case 'UPDATE': {\n const modals = state.modals.map((modal) => {\n if (modal.id !== action.modalId) {\n return modal\n }\n\n if (modal.type === 'context') {\n return {\n ...modal,\n props: {\n ...modal.props,\n ...action.newProps,\n innerProps: {\n ...modal.props.innerProps,\n ...(action.newProps as any).innerProps,\n },\n },\n }\n }\n\n return { ...modal, props: { ...modal.props, ...action.newProps } } as ModalState\n })\n\n const current =\n state.current && state.current.id === action.modalId\n ? modals.find((modal) => modal.id === action.modalId) || state.current\n : state.current\n\n return { current, modals }\n }\n\n default:\n return state\n }\n}\n","import { type Ref } from 'vue'\nimport { createStore, type MantineStore } from '@mantine-vue/store'\nimport type { ModalSettings, OpenConfirmModal, OpenContextModal } from './context'\nimport { handleCloseModal, modalsReducer, type ModalsAction, type ModalsState } from './reducer'\n\nexport type ModalsStore = MantineStore<ModalsState>\n\nfunction randomId() {\n return `mantine-${Math.random().toString(36).slice(2, 11)}`\n}\n\nexport const createModalsStore = () => createStore<ModalsState>({ modals: [], current: null })\n\nexport const modalsStore = createModalsStore()\n\nexport const useModalsState = (store: ModalsStore = modalsStore): Readonly<Ref<ModalsState>> =>\n store.value\n\nconst closingMap = new WeakMap<ModalsStore, boolean>()\n\nfunction dispatch(action: ModalsAction, store: ModalsStore) {\n store.setState((state) => modalsReducer(state, action))\n}\n\nexport function openModalAction(props: ModalSettings, store: ModalsStore = modalsStore): string {\n const { modalId, ...rest } = props\n const id = modalId || randomId()\n dispatch({ type: 'OPEN', modal: { id, type: 'content', props: rest } }, store)\n return id\n}\n\nexport function openConfirmModalAction(\n props: OpenConfirmModal,\n store: ModalsStore = modalsStore,\n): string {\n const { modalId, ...rest } = props\n const id = modalId || randomId()\n dispatch({ type: 'OPEN', modal: { id, type: 'confirm', props: rest } }, store)\n return id\n}\n\nexport function openContextModalAction(\n modal: string,\n props: OpenContextModal,\n store: ModalsStore = modalsStore,\n): string {\n const { modalId, ...rest } = props\n const id = modalId || randomId()\n dispatch({ type: 'OPEN', modal: { id, type: 'context', props: rest, ctx: modal } }, store)\n return id\n}\n\nexport function closeModalAction(id: string, canceled?: boolean, store: ModalsStore = modalsStore) {\n if (!closingMap.get(store)) {\n const modal = store.getState().modals.find((item) => item.id === id)\n if (modal) {\n closingMap.set(store, true)\n handleCloseModal(modal, canceled)\n closingMap.set(store, false)\n }\n }\n\n dispatch({ type: 'CLOSE', modalId: id, canceled }, store)\n}\n\nexport function closeAllModalsAction(canceled?: boolean, store: ModalsStore = modalsStore) {\n if (!closingMap.get(store)) {\n closingMap.set(store, true)\n store\n .getState()\n .modals.slice()\n .reverse()\n .forEach((modal) => handleCloseModal(modal, canceled))\n closingMap.set(store, false)\n }\n\n dispatch({ type: 'CLOSE_ALL', canceled }, store)\n}\n\nexport function updateModalAction(\n payload: { modalId: string } & Partial<ModalSettings>,\n store: ModalsStore = modalsStore,\n) {\n const { modalId, ...newProps } = payload\n dispatch({ type: 'UPDATE', modalId, newProps }, store)\n}\n\nexport function updateContextModalAction(\n payload: { modalId: string } & Partial<OpenContextModal<any>>,\n store: ModalsStore = modalsStore,\n) {\n const { modalId, ...newProps } = payload\n dispatch({ type: 'UPDATE', modalId, newProps }, store)\n}\n\nfunction openContextModalPayload(\n payload: OpenContextModal & { modal: string },\n store: ModalsStore = modalsStore,\n): string {\n const { modal, ...rest } = payload\n return openContextModalAction(modal, rest, store)\n}\n\nexport const modals = {\n open: (props: ModalSettings) => openModalAction(props),\n close: (id: string) => closeModalAction(id),\n closeAll: () => closeAllModalsAction(),\n openConfirmModal: (props: OpenConfirmModal) => openConfirmModalAction(props),\n openContextModal: (payload: OpenContextModal & { modal: string }) =>\n openContextModalPayload(payload),\n updateModal: (payload: { modalId: string } & Partial<OpenConfirmModal>) =>\n updateModalAction(payload),\n updateContextModal: (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n updateContextModalAction(payload),\n} as const\n\nexport const openModal = modals.open\nexport const closeModal = modals.close\nexport const closeAllModals = modals.closeAll\nexport const openConfirmModal = modals.openConfirmModal\nexport const openContextModal = modals.openContextModal\nexport const updateModal = modals.updateModal\nexport const updateContextModal = modals.updateContextModal\n","import { defineComponent, h, provide, type PropType, type VNodeChild } from 'vue'\nimport { getDefaultZIndex, Modal } from '@mantine-vue/core'\nimport { ConfirmModal } from './ConfirmModal'\nimport {\n ModalsContextKey,\n type ConfirmLabels,\n type ModalsContextProps,\n type ModalSettings,\n type OpenConfirmModal,\n type OpenContextModal,\n} from './context'\nimport {\n closeAllModalsAction,\n closeModalAction,\n modalsStore,\n openConfirmModalAction,\n openContextModalAction,\n openModalAction,\n updateContextModalAction,\n updateModalAction,\n useModalsState,\n} from './modals.store'\n\nexport interface ModalsProviderProps {\n modals?: Record<string, any>\n modalProps?: ModalSettings\n labels?: ConfirmLabels\n}\n\nfunction separateConfirmModalProps(props: OpenConfirmModal) {\n const {\n id,\n children: _children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...modalProps\n } = props as any\n\n return {\n confirmModalProps: {\n id,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n },\n modalProps: { id, ...modalProps },\n }\n}\n\nexport const ModalsProvider = defineComponent({\n name: 'ModalsProvider',\n props: {\n modals: { type: Object as PropType<Record<string, any>>, default: undefined },\n modalProps: { type: Object as PropType<ModalSettings>, default: undefined },\n labels: { type: Object as PropType<ConfirmLabels>, default: undefined },\n },\n setup(props, { slots }) {\n const state = useModalsState(modalsStore)\n\n const openModal = (settings: ModalSettings) => openModalAction(settings, modalsStore)\n const openConfirmModal = (settings: OpenConfirmModal) =>\n openConfirmModalAction(settings, modalsStore)\n const openContextModal = (modal: string, settings: OpenContextModal) =>\n openContextModalAction(modal, settings, modalsStore)\n const closeModal = (id: string, canceled?: boolean) =>\n closeModalAction(id, canceled, modalsStore)\n const closeAll = () => closeAllModalsAction(undefined, modalsStore)\n const updateModal = (payload: { modalId: string } & Partial<OpenConfirmModal>) =>\n updateModalAction(payload, modalsStore)\n const updateContextModal = (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n updateContextModalAction(payload, modalsStore)\n\n const ctx: ModalsContextProps = {\n get modalProps() {\n return props.modalProps || {}\n },\n get modals() {\n return state.value.modals\n },\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeContextModal: closeModal,\n closeAll,\n updateModal,\n updateContextModal,\n }\n\n provide(ModalsContextKey, ctx)\n\n return () => {\n const current = state.value.current\n let currentModalProps: Record<string, any> = {}\n let content: VNodeChild = null\n\n if (current) {\n if (current.type === 'context') {\n const { innerProps, ...rest } = current.props\n currentModalProps = rest\n const ContextModalComponent = props.modals?.[current.ctx]\n content = ContextModalComponent\n ? h(ContextModalComponent, { innerProps, context: ctx, id: current.id })\n : null\n } else if (current.type === 'confirm') {\n const { confirmModalProps, modalProps: separatedModalProps } = separateConfirmModalProps(\n current.props,\n )\n currentModalProps = separatedModalProps\n content = h(ConfirmModal, {\n ...confirmModalProps,\n id: current.id,\n labels: current.props.labels || props.labels,\n })\n } else {\n const { children, ...rest } = current.props as any\n currentModalProps = rest\n content = typeof children === 'function' ? children() : (children ?? null)\n }\n }\n\n return [\n h(\n Modal,\n {\n zIndex: getDefaultZIndex('modal') + 1,\n ...props.modalProps,\n ...currentModalProps,\n opened: state.value.modals.length > 0,\n onClose: () => closeModal(state.value.current?.id as string),\n },\n () => content,\n ),\n slots.default?.(),\n ]\n }\n },\n})\n"],"mappings":";;;;AA4CA,IAAa,mBAAqD,OAAO,eAAe;;;ACzCxF,SAAgB,YAAgC;CAC9C,MAAM,MAAM,OAAO,kBAAkB,IAAI;CAEzC,IAAI,CAAC,KACH,MAAM,IAAI,MACR,2HACF;CAGF,OAAO;AACT;;;ACIA,IAAa,eAAe,gBAAgB;CAC1C,MAAM;CACN,cAAc;CACd,OAAO;EACL,IAAI;GAAE,MAAM;GAAQ,SAAS,KAAA;EAAU;EACvC,UAAU;GAAE,MAAM;GAAkC,SAAS,KAAA;EAAU;EACvE,WAAW;GAAE,MAAM;GAAkC,SAAS,KAAA;EAAU;EACxE,gBAAgB;GAAE,MAAM;GAAS,SAAS;EAAK;EAC/C,eAAe;GAAE,MAAM;GAAS,SAAS;EAAK;EAC9C,aAAa;GAAE,MAAM;GAAyC,SAAS,KAAA;EAAU;EACjF,cAAc;GAAE,MAAM;GAAyC,SAAS,KAAA;EAAU;EAClF,YAAY;GAAE,MAAM;GAAyC,SAAS,KAAA;EAAU;EAChF,QAAQ;GACN,MAAM;GACN,gBAAgB;IAAE,QAAQ;IAAI,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AK,YAAY;GACvE;GAGF,OAAO,CACL,EACE,OACA;IACE,QAAQ,iBAAiB,OAAO,IAAI;IACpC,GAAG,MAAM;IACT,GAAG;IACH,QAAQ,MAAM,MAAM,OAAO,SAAS;IACpC,eAAe,WAAW,MAAM,MAAM,SAAS,EAAY;GAC7D,SACM,OACR,GACA,MAAM,UAAU,CAClB;EACF;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
2
|
+
import type { ConfirmLabels } from './context';
|
|
3
|
+
export interface ConfirmModalProps {
|
|
4
|
+
id?: string;
|
|
5
|
+
onCancel?: () => void;
|
|
6
|
+
onConfirm?: () => void;
|
|
7
|
+
closeOnConfirm?: boolean;
|
|
8
|
+
closeOnCancel?: boolean;
|
|
9
|
+
cancelProps?: Record<string, any>;
|
|
10
|
+
confirmProps?: Record<string, any>;
|
|
11
|
+
groupProps?: Record<string, any>;
|
|
12
|
+
labels?: ConfirmLabels;
|
|
13
|
+
}
|
|
14
|
+
export declare const ConfirmModal: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
15
|
+
id: {
|
|
16
|
+
type: StringConstructor;
|
|
17
|
+
default: undefined;
|
|
18
|
+
};
|
|
19
|
+
onCancel: {
|
|
20
|
+
type: PropType<() => void>;
|
|
21
|
+
default: undefined;
|
|
22
|
+
};
|
|
23
|
+
onConfirm: {
|
|
24
|
+
type: PropType<() => void>;
|
|
25
|
+
default: undefined;
|
|
26
|
+
};
|
|
27
|
+
closeOnConfirm: {
|
|
28
|
+
type: BooleanConstructor;
|
|
29
|
+
default: boolean;
|
|
30
|
+
};
|
|
31
|
+
closeOnCancel: {
|
|
32
|
+
type: BooleanConstructor;
|
|
33
|
+
default: boolean;
|
|
34
|
+
};
|
|
35
|
+
cancelProps: {
|
|
36
|
+
type: PropType<Record<string, any>>;
|
|
37
|
+
default: undefined;
|
|
38
|
+
};
|
|
39
|
+
confirmProps: {
|
|
40
|
+
type: PropType<Record<string, any>>;
|
|
41
|
+
default: undefined;
|
|
42
|
+
};
|
|
43
|
+
groupProps: {
|
|
44
|
+
type: PropType<Record<string, any>>;
|
|
45
|
+
default: undefined;
|
|
46
|
+
};
|
|
47
|
+
labels: {
|
|
48
|
+
type: PropType<ConfirmLabels>;
|
|
49
|
+
default: () => {
|
|
50
|
+
cancel: string;
|
|
51
|
+
confirm: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}>, () => (import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}> | null)[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
57
|
+
id: {
|
|
58
|
+
type: StringConstructor;
|
|
59
|
+
default: undefined;
|
|
60
|
+
};
|
|
61
|
+
onCancel: {
|
|
62
|
+
type: PropType<() => void>;
|
|
63
|
+
default: undefined;
|
|
64
|
+
};
|
|
65
|
+
onConfirm: {
|
|
66
|
+
type: PropType<() => void>;
|
|
67
|
+
default: undefined;
|
|
68
|
+
};
|
|
69
|
+
closeOnConfirm: {
|
|
70
|
+
type: BooleanConstructor;
|
|
71
|
+
default: boolean;
|
|
72
|
+
};
|
|
73
|
+
closeOnCancel: {
|
|
74
|
+
type: BooleanConstructor;
|
|
75
|
+
default: boolean;
|
|
76
|
+
};
|
|
77
|
+
cancelProps: {
|
|
78
|
+
type: PropType<Record<string, any>>;
|
|
79
|
+
default: undefined;
|
|
80
|
+
};
|
|
81
|
+
confirmProps: {
|
|
82
|
+
type: PropType<Record<string, any>>;
|
|
83
|
+
default: undefined;
|
|
84
|
+
};
|
|
85
|
+
groupProps: {
|
|
86
|
+
type: PropType<Record<string, any>>;
|
|
87
|
+
default: undefined;
|
|
88
|
+
};
|
|
89
|
+
labels: {
|
|
90
|
+
type: PropType<ConfirmLabels>;
|
|
91
|
+
default: () => {
|
|
92
|
+
cancel: string;
|
|
93
|
+
confirm: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
}>> & Readonly<{}>, {
|
|
97
|
+
onCancel: () => void;
|
|
98
|
+
id: string;
|
|
99
|
+
labels: ConfirmLabels;
|
|
100
|
+
onConfirm: () => void;
|
|
101
|
+
closeOnConfirm: boolean;
|
|
102
|
+
closeOnCancel: boolean;
|
|
103
|
+
cancelProps: Record<string, any>;
|
|
104
|
+
confirmProps: Record<string, any>;
|
|
105
|
+
groupProps: Record<string, any>;
|
|
106
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
2
|
+
import { type ConfirmLabels, type ModalSettings } from './context';
|
|
3
|
+
export interface ModalsProviderProps {
|
|
4
|
+
modals?: Record<string, any>;
|
|
5
|
+
modalProps?: ModalSettings;
|
|
6
|
+
labels?: ConfirmLabels;
|
|
7
|
+
}
|
|
8
|
+
export declare const ModalsProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
9
|
+
modals: {
|
|
10
|
+
type: PropType<Record<string, any>>;
|
|
11
|
+
default: undefined;
|
|
12
|
+
};
|
|
13
|
+
modalProps: {
|
|
14
|
+
type: PropType<ModalSettings>;
|
|
15
|
+
default: undefined;
|
|
16
|
+
};
|
|
17
|
+
labels: {
|
|
18
|
+
type: PropType<ConfirmLabels>;
|
|
19
|
+
default: undefined;
|
|
20
|
+
};
|
|
21
|
+
}>, () => (import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}> | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}>[] | undefined)[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
26
|
+
modals: {
|
|
27
|
+
type: PropType<Record<string, any>>;
|
|
28
|
+
default: undefined;
|
|
29
|
+
};
|
|
30
|
+
modalProps: {
|
|
31
|
+
type: PropType<ModalSettings>;
|
|
32
|
+
default: undefined;
|
|
33
|
+
};
|
|
34
|
+
labels: {
|
|
35
|
+
type: PropType<ConfirmLabels>;
|
|
36
|
+
default: undefined;
|
|
37
|
+
};
|
|
38
|
+
}>> & Readonly<{}>, {
|
|
39
|
+
labels: ConfirmLabels;
|
|
40
|
+
modalProps: ModalSettings;
|
|
41
|
+
modals: Record<string, any>;
|
|
42
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
package/lib/context.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { InjectionKey, VNodeChild } from 'vue';
|
|
2
|
+
import type { ModalProps } from '@mantine-vue/core';
|
|
3
|
+
import type { ConfirmModalProps } from './ConfirmModal';
|
|
4
|
+
export type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & {
|
|
5
|
+
modalId?: string;
|
|
6
|
+
children?: VNodeChild | (() => VNodeChild);
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
};
|
|
9
|
+
export type ConfirmLabels = Record<'confirm' | 'cancel', VNodeChild>;
|
|
10
|
+
export interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {
|
|
11
|
+
}
|
|
12
|
+
export interface OpenContextModal<CustomProps extends Record<string, any> = Record<string, any>> extends ModalSettings {
|
|
13
|
+
innerProps: CustomProps;
|
|
14
|
+
}
|
|
15
|
+
export interface ContextModalProps<T extends Record<string, any> = Record<string, any>> {
|
|
16
|
+
context: ModalsContextProps;
|
|
17
|
+
innerProps: T;
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
20
|
+
export type ModalState = {
|
|
21
|
+
id: string;
|
|
22
|
+
type: 'content';
|
|
23
|
+
props: ModalSettings;
|
|
24
|
+
} | {
|
|
25
|
+
id: string;
|
|
26
|
+
type: 'confirm';
|
|
27
|
+
props: OpenConfirmModal;
|
|
28
|
+
} | {
|
|
29
|
+
id: string;
|
|
30
|
+
type: 'context';
|
|
31
|
+
props: OpenContextModal;
|
|
32
|
+
ctx: string;
|
|
33
|
+
};
|
|
34
|
+
export interface ModalsContextProps {
|
|
35
|
+
modalProps: ModalSettings;
|
|
36
|
+
modals: ModalState[];
|
|
37
|
+
openModal: (props: ModalSettings) => string;
|
|
38
|
+
openConfirmModal: (props: OpenConfirmModal) => string;
|
|
39
|
+
openContextModal: (modal: string, props: OpenContextModal) => string;
|
|
40
|
+
closeModal: (id: string, canceled?: boolean) => void;
|
|
41
|
+
closeContextModal: (id: string, canceled?: boolean) => void;
|
|
42
|
+
closeAll: () => void;
|
|
43
|
+
updateModal: (payload: {
|
|
44
|
+
modalId: string;
|
|
45
|
+
} & Partial<OpenConfirmModal>) => void;
|
|
46
|
+
updateContextModal: (payload: {
|
|
47
|
+
modalId: string;
|
|
48
|
+
} & Partial<OpenContextModal<any>>) => void;
|
|
49
|
+
}
|
|
50
|
+
export declare const ModalsContextKey: InjectionKey<ModalsContextProps>;
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ModalsProvider } from './ModalsProvider';
|
|
2
|
+
export { useModals } from './use-modals';
|
|
3
|
+
export { ConfirmModal } from './ConfirmModal';
|
|
4
|
+
export { modals, openModal, closeModal, closeAllModals, openConfirmModal, openContextModal, updateModal, updateContextModal, createModalsStore, modalsStore, useModalsState, openModalAction, openConfirmModalAction, openContextModalAction, closeModalAction, closeAllModalsAction, updateModalAction, updateContextModalAction, } from './modals.store';
|
|
5
|
+
export { modalsReducer, handleCloseModal } from './reducer';
|
|
6
|
+
export type { ModalsProviderProps } from './ModalsProvider';
|
|
7
|
+
export type { ConfirmModalProps } from './ConfirmModal';
|
|
8
|
+
export type { ModalsStore } from './modals.store';
|
|
9
|
+
export type { ModalsState, ModalsAction } from './reducer';
|
|
10
|
+
export type { ContextModalProps, ModalSettings, ModalState, ModalsContextProps, OpenConfirmModal, OpenContextModal, ConfirmLabels, } from './context';
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ModalsProvider } from './ModalsProvider';
|
|
2
|
+
export { useModals } from './use-modals';
|
|
3
|
+
export { ConfirmModal } from './ConfirmModal';
|
|
4
|
+
export { modals, openModal, closeModal, closeAllModals, openConfirmModal, openContextModal, updateModal, updateContextModal, createModalsStore, modalsStore, useModalsState, openModalAction, openConfirmModalAction, openContextModalAction, closeModalAction, closeAllModalsAction, updateModalAction, updateContextModalAction, } from './modals.store';
|
|
5
|
+
export { modalsReducer, handleCloseModal } from './reducer';
|
|
6
|
+
export type { ModalsProviderProps } from './ModalsProvider';
|
|
7
|
+
export type { ConfirmModalProps } from './ConfirmModal';
|
|
8
|
+
export type { ModalsStore } from './modals.store';
|
|
9
|
+
export type { ModalsState, ModalsAction } from './reducer';
|
|
10
|
+
export type { ContextModalProps, ModalSettings, ModalState, ModalsContextProps, OpenConfirmModal, OpenContextModal, ConfirmLabels, } from './context';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import { type MantineStore } from '@mantine-vue/store';
|
|
3
|
+
import type { ModalSettings, OpenConfirmModal, OpenContextModal } from './context';
|
|
4
|
+
import { type ModalsState } from './reducer';
|
|
5
|
+
export type ModalsStore = MantineStore<ModalsState>;
|
|
6
|
+
export declare const createModalsStore: () => MantineStore<ModalsState>;
|
|
7
|
+
export declare const modalsStore: MantineStore<ModalsState>;
|
|
8
|
+
export declare const useModalsState: (store?: ModalsStore) => Readonly<Ref<ModalsState>>;
|
|
9
|
+
export declare function openModalAction(props: ModalSettings, store?: ModalsStore): string;
|
|
10
|
+
export declare function openConfirmModalAction(props: OpenConfirmModal, store?: ModalsStore): string;
|
|
11
|
+
export declare function openContextModalAction(modal: string, props: OpenContextModal, store?: ModalsStore): string;
|
|
12
|
+
export declare function closeModalAction(id: string, canceled?: boolean, store?: ModalsStore): void;
|
|
13
|
+
export declare function closeAllModalsAction(canceled?: boolean, store?: ModalsStore): void;
|
|
14
|
+
export declare function updateModalAction(payload: {
|
|
15
|
+
modalId: string;
|
|
16
|
+
} & Partial<ModalSettings>, store?: ModalsStore): void;
|
|
17
|
+
export declare function updateContextModalAction(payload: {
|
|
18
|
+
modalId: string;
|
|
19
|
+
} & Partial<OpenContextModal<any>>, store?: ModalsStore): void;
|
|
20
|
+
export declare const modals: {
|
|
21
|
+
readonly open: (props: ModalSettings) => string;
|
|
22
|
+
readonly close: (id: string) => void;
|
|
23
|
+
readonly closeAll: () => void;
|
|
24
|
+
readonly openConfirmModal: (props: OpenConfirmModal) => string;
|
|
25
|
+
readonly openContextModal: (payload: OpenContextModal & {
|
|
26
|
+
modal: string;
|
|
27
|
+
}) => string;
|
|
28
|
+
readonly updateModal: (payload: {
|
|
29
|
+
modalId: string;
|
|
30
|
+
} & Partial<OpenConfirmModal>) => void;
|
|
31
|
+
readonly updateContextModal: (payload: {
|
|
32
|
+
modalId: string;
|
|
33
|
+
} & Partial<OpenContextModal<any>>) => void;
|
|
34
|
+
};
|
|
35
|
+
export declare const openModal: (props: ModalSettings) => string;
|
|
36
|
+
export declare const closeModal: (id: string) => void;
|
|
37
|
+
export declare const closeAllModals: () => void;
|
|
38
|
+
export declare const openConfirmModal: (props: OpenConfirmModal) => string;
|
|
39
|
+
export declare const openContextModal: (payload: OpenContextModal & {
|
|
40
|
+
modal: string;
|
|
41
|
+
}) => string;
|
|
42
|
+
export declare const updateModal: (payload: {
|
|
43
|
+
modalId: string;
|
|
44
|
+
} & Partial<OpenConfirmModal>) => void;
|
|
45
|
+
export declare const updateContextModal: (payload: {
|
|
46
|
+
modalId: string;
|
|
47
|
+
} & Partial<OpenContextModal<any>>) => void;
|
package/lib/reducer.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ModalSettings, ModalState } from './context';
|
|
2
|
+
export interface ModalsState {
|
|
3
|
+
modals: ModalState[];
|
|
4
|
+
current: ModalState | null;
|
|
5
|
+
}
|
|
6
|
+
export interface OpenAction {
|
|
7
|
+
type: 'OPEN';
|
|
8
|
+
modal: ModalState;
|
|
9
|
+
}
|
|
10
|
+
export interface CloseAction {
|
|
11
|
+
type: 'CLOSE';
|
|
12
|
+
modalId: string;
|
|
13
|
+
canceled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface CloseAllAction {
|
|
16
|
+
type: 'CLOSE_ALL';
|
|
17
|
+
canceled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface UpdateAction {
|
|
20
|
+
type: 'UPDATE';
|
|
21
|
+
modalId: string;
|
|
22
|
+
newProps: Partial<ModalSettings>;
|
|
23
|
+
}
|
|
24
|
+
export type ModalsAction = OpenAction | CloseAction | CloseAllAction | UpdateAction;
|
|
25
|
+
export declare function handleCloseModal(modal: ModalState, canceled?: boolean): void;
|
|
26
|
+
export declare function modalsReducer(state: ModalsState, action: ModalsAction): ModalsState;
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mantine-vue/modals",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Vue modals management system equivalent to @mantine/modals",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"cjs",
|
|
8
|
+
"esm",
|
|
9
|
+
"lib",
|
|
10
|
+
"styles.css",
|
|
11
|
+
"styles.layer.css",
|
|
12
|
+
"styles"
|
|
13
|
+
],
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"main": "./cjs/index.cjs",
|
|
16
|
+
"module": "./esm/index.mjs",
|
|
17
|
+
"types": "./lib/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./lib/index.d.mts",
|
|
22
|
+
"default": "./esm/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./lib/index.d.ts",
|
|
26
|
+
"default": "./cjs/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@mantine-vue/core": "workspace:*",
|
|
32
|
+
"@mantine-vue/store": "workspace:*",
|
|
33
|
+
"@vue/compiler-dom": "^3.5.0",
|
|
34
|
+
"@vue/test-utils": "^2.4.6",
|
|
35
|
+
"vue": "^3.5.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@mantine-vue/core": "1.1.1",
|
|
39
|
+
"@mantine-vue/store": "1.1.1",
|
|
40
|
+
"vue": "^3.5.0"
|
|
41
|
+
}
|
|
42
|
+
}
|