@mantine-vue/modals 3.0.0 → 3.1.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/esm/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineComponent, h, inject, provide } from "vue";
1
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, inject, mergeProps, normalizeProps, openBlock, provide, renderSlot, resolveDynamicComponent, unref, useSlots, withCtx } from "vue";
2
2
  import { Box, Button, Group, Modal, getDefaultZIndex } from "@mantine-vue/core";
3
3
  import { createStore } from "@mantine-vue/store";
4
4
  //#region src/context.ts
@@ -11,23 +11,13 @@ function useModals() {
11
11
  return ctx;
12
12
  }
13
13
  //#endregion
14
- //#region src/ConfirmModal.ts
15
- var ConfirmModal = defineComponent({
14
+ //#region src/components/ConfirmModal/ConfirmModal.vue
15
+ var ConfirmModal_default = /* @__PURE__ */ defineComponent({
16
16
  name: "ConfirmModal",
17
17
  inheritAttrs: false,
18
+ __name: "ConfirmModal",
18
19
  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
- },
20
+ id: {},
31
21
  closeOnConfirm: {
32
22
  type: Boolean,
33
23
  default: true
@@ -36,53 +26,68 @@ var ConfirmModal = defineComponent({
36
26
  type: Boolean,
37
27
  default: true
38
28
  },
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
- }
29
+ cancelProps: {},
30
+ confirmProps: {},
31
+ groupProps: {},
32
+ labels: { default: () => ({
33
+ cancel: "",
34
+ confirm: ""
35
+ }) }
58
36
  },
59
- setup(props, { slots }) {
37
+ emits: ["cancel", "confirm"],
38
+ setup(__props, { emit: __emit }) {
39
+ const props = __props;
40
+ const emit = __emit;
41
+ const slots = useSlots();
60
42
  const ctx = useModals();
61
- const handleCancel = (event) => {
43
+ const hasChildren = computed(() => Boolean(slots.default));
44
+ const cancelButtonProps = computed(() => {
45
+ const value = { ...props.cancelProps };
46
+ delete value.onClick;
47
+ delete value.children;
48
+ return value;
49
+ });
50
+ const confirmButtonProps = computed(() => {
51
+ const value = { ...props.confirmProps };
52
+ delete value.onClick;
53
+ delete value.children;
54
+ return value;
55
+ });
56
+ const renderCancelLabel = () => props.cancelProps?.children ?? props.labels.cancel;
57
+ const renderConfirmLabel = () => props.confirmProps?.children ?? props.labels.confirm;
58
+ function cancel(event) {
62
59
  props.cancelProps?.onClick?.(event);
63
- props.onCancel?.();
60
+ emit("cancel");
64
61
  if (props.closeOnCancel) ctx.closeModal(props.id);
65
- };
66
- const handleConfirm = (event) => {
62
+ }
63
+ function confirm(event) {
67
64
  props.confirmProps?.onClick?.(event);
68
- props.onConfirm?.();
65
+ emit("confirm");
69
66
  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)])];
67
+ }
68
+ return (_ctx, _cache) => {
69
+ return openBlock(), createElementBlock(Fragment, null, [hasChildren.value ? (openBlock(), createBlock(unref(Box), {
70
+ key: 0,
71
+ mb: "md"
72
+ }, {
73
+ default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
74
+ _: 3
75
+ })) : createCommentVNode("", true), createVNode(unref(Group), mergeProps(props.groupProps, {
76
+ mt: hasChildren.value ? 0 : "md",
77
+ justify: "flex-end"
78
+ }), {
79
+ default: withCtx(() => [createVNode(unref(Button), mergeProps(cancelButtonProps.value, {
80
+ variant: "default",
81
+ onClick: cancel
82
+ }), {
83
+ default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(renderCancelLabel)))]),
84
+ _: 1
85
+ }, 16), createVNode(unref(Button), mergeProps(confirmButtonProps.value, { onClick: confirm }), {
86
+ default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(renderConfirmLabel)))]),
87
+ _: 1
88
+ }, 16)]),
89
+ _: 1
90
+ }, 16, ["mt"])], 64);
86
91
  };
87
92
  }
88
93
  });
@@ -243,12 +248,19 @@ function openContextModalPayload(payload, store = modalsStore) {
243
248
  return openContextModalAction(modal, rest, store);
244
249
  }
245
250
  var modals = {
251
+ /** Opens a regular modal and returns its id. */
246
252
  open: (props) => openModalAction(props),
253
+ /** Closes the modal with the given id. */
247
254
  close: (id) => closeModalAction(id),
255
+ /** Closes all opened modals. */
248
256
  closeAll: () => closeAllModalsAction(),
257
+ /** Opens a confirm modal and returns its id. */
249
258
  openConfirmModal: (props) => openConfirmModalAction(props),
259
+ /** Opens a predefined context modal and returns its id. */
250
260
  openContextModal: (payload) => openContextModalPayload(payload),
261
+ /** Dynamically updates the content and properties of a regular or confirm modal. */
251
262
  updateModal: (payload) => updateModalAction(payload),
263
+ /** Dynamically updates the content and properties of a context modal. */
252
264
  updateContextModal: (payload) => updateContextModalAction(payload)
253
265
  };
254
266
  var openModal = modals.open;
@@ -259,44 +271,17 @@ var openContextModal = modals.openContextModal;
259
271
  var updateModal = modals.updateModal;
260
272
  var updateContextModal = modals.updateContextModal;
261
273
  //#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({
274
+ //#region src/components/ModalsProvider/ModalsProvider.vue
275
+ var ModalsProvider_default = /* @__PURE__ */ defineComponent({
284
276
  name: "ModalsProvider",
277
+ __name: "ModalsProvider",
285
278
  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
- }
279
+ modals: {},
280
+ modalProps: {},
281
+ labels: {}
298
282
  },
299
- setup(props, { slots }) {
283
+ setup(__props) {
284
+ const props = __props;
300
285
  const state = useModalsState(modalsStore);
301
286
  const openModal = (settings) => openModalAction(settings, modalsStore);
302
287
  const openConfirmModal = (settings) => openConfirmModalAction(settings, modalsStore);
@@ -305,7 +290,7 @@ var ModalsProvider = defineComponent({
305
290
  const closeAll = () => closeAllModalsAction(void 0, modalsStore);
306
291
  const updateModal = (payload) => updateModalAction(payload, modalsStore);
307
292
  const updateContextModal = (payload) => updateContextModalAction(payload, modalsStore);
308
- const ctx = {
293
+ const context = {
309
294
  get modalProps() {
310
295
  return props.modalProps || {};
311
296
  },
@@ -321,44 +306,103 @@ var ModalsProvider = defineComponent({
321
306
  updateModal,
322
307
  updateContextModal
323
308
  };
324
- provide(ModalsContextKey, ctx);
325
- return () => {
309
+ provide(ModalsContextKey, context);
310
+ function separateConfirmModalProps(settings) {
311
+ const value = { ...settings };
312
+ const confirmModalProps = {
313
+ id: value.id,
314
+ onCancel: value.onCancel,
315
+ onConfirm: value.onConfirm,
316
+ closeOnConfirm: value.closeOnConfirm,
317
+ closeOnCancel: value.closeOnCancel,
318
+ cancelProps: value.cancelProps,
319
+ confirmProps: value.confirmProps,
320
+ groupProps: value.groupProps,
321
+ labels: value.labels
322
+ };
323
+ for (const key of [
324
+ "children",
325
+ "onCancel",
326
+ "onConfirm",
327
+ "closeOnConfirm",
328
+ "closeOnCancel",
329
+ "cancelProps",
330
+ "confirmProps",
331
+ "groupProps",
332
+ "labels"
333
+ ]) delete value[key];
334
+ return {
335
+ confirmModalProps,
336
+ modalProps: value
337
+ };
338
+ }
339
+ const presentation = computed(() => {
326
340
  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;
341
+ if (!current) return {
342
+ modalProps: {},
343
+ component: null,
344
+ componentProps: {}
345
+ };
346
+ if (current.type === "context") {
347
+ const { innerProps, ...modalProps } = current.props;
348
+ return {
349
+ modalProps,
350
+ component: props.modals?.[current.ctx] ?? null,
351
+ componentProps: {
352
+ innerProps,
353
+ context,
354
+ id: current.id
355
+ }
356
+ };
350
357
  }
351
- return [h(Modal, {
358
+ if (current.type === "confirm") {
359
+ const separated = separateConfirmModalProps(current.props);
360
+ return {
361
+ modalProps: separated.modalProps,
362
+ component: ConfirmModal_default,
363
+ componentProps: {
364
+ ...separated.confirmModalProps,
365
+ id: current.id,
366
+ labels: current.props.labels || props.labels
367
+ }
368
+ };
369
+ }
370
+ const modalProps = { ...current.props };
371
+ delete modalProps.children;
372
+ return {
373
+ modalProps,
374
+ component: null,
375
+ componentProps: {}
376
+ };
377
+ });
378
+ const modalAttrs = computed(() => {
379
+ const value = {
352
380
  zIndex: getDefaultZIndex("modal") + 1,
353
381
  ...props.modalProps,
354
- ...currentModalProps,
355
- opened: state.value.modals.length > 0,
356
- onClose: () => closeModal(state.value.current?.id)
357
- }, () => content), slots.default?.()];
382
+ ...presentation.value.modalProps
383
+ };
384
+ delete value.opened;
385
+ delete value.onClose;
386
+ return value;
387
+ });
388
+ const renderContent = () => {
389
+ const current = state.value.current;
390
+ if (!current || current.type !== "content") return null;
391
+ const children = current.props.children;
392
+ return typeof children === "function" ? children() : children ?? null;
393
+ };
394
+ return (_ctx, _cache) => {
395
+ return openBlock(), createElementBlock(Fragment, null, [createVNode(unref(Modal), mergeProps(modalAttrs.value, {
396
+ opened: unref(state).modals.length > 0,
397
+ onClose: _cache[0] || (_cache[0] = ($event) => closeModal(unref(state).current?.id))
398
+ }), {
399
+ default: withCtx(() => [presentation.value.component ? (openBlock(), createBlock(resolveDynamicComponent(presentation.value.component), normalizeProps(mergeProps({ key: 0 }, presentation.value.componentProps)), null, 16)) : (openBlock(), createBlock(resolveDynamicComponent(renderContent), { key: 1 }))]),
400
+ _: 1
401
+ }, 16, ["opened"]), renderSlot(_ctx.$slots, "default")], 64);
358
402
  };
359
403
  }
360
404
  });
361
405
  //#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 };
406
+ export { ConfirmModal_default as ConfirmModal, ModalsProvider_default as ModalsProvider, closeAllModals, closeAllModalsAction, closeModal, closeModalAction, createModalsStore, handleCloseModal, modals, modalsReducer, modalsStore, openConfirmModal, openConfirmModalAction, openContextModal, openContextModalAction, openModal, openModalAction, updateContextModal, updateContextModalAction, updateModal, updateModalAction, useModals, useModalsState };
363
407
 
364
408
  //# sourceMappingURL=index.mjs.map
package/esm/index.mjs.map CHANGED
@@ -1 +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,SAAS;GAAG;EAC5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AGF,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"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/context.ts","../src/use-modals.ts","../src/components/ConfirmModal/ConfirmModal.vue","../src/components/ConfirmModal/ConfirmModal.vue","../src/reducer.ts","../src/modals.store.ts","../src/components/ModalsProvider/ModalsProvider.vue","../src/components/ModalsProvider/ModalsProvider.vue"],"sourcesContent":["import type { InjectionKey, VNodeChild } from 'vue'\nimport type { ModalProps } from '@mantine-vue/core'\nimport type { ConfirmModalCallbacks, ConfirmModalProps } from './components/ConfirmModal'\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & {\n /** Modal id, defaults to a random id, can be used to close or update the modal programmatically. */\n modalId?: string\n /** Modal content. */\n children?: VNodeChild | (() => VNodeChild)\n /** Called when the modal closes. */\n onClose?: () => void\n}\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', VNodeChild>\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps, ConfirmModalCallbacks {}\n\nexport interface OpenContextModal<\n CustomProps extends Record<string, any> = Record<string, any>,\n> extends ModalSettings {\n /** Props passed to the registered context modal component. */\n innerProps: CustomProps\n}\n\nexport interface ContextModalProps<T extends Record<string, any> = Record<string, any>> {\n /** Modals manager context. */\n context: ModalsContextProps\n /** Props passed to `modals.openContextModal`. */\n innerProps: T\n /** Current modal id. */\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 /** Shared Modal component props applied to every modal. */\n modalProps: ModalSettings\n /** Currently opened modal stack. */\n modals: ModalState[]\n /** Opens a regular modal and returns its id. */\n openModal: (props: ModalSettings) => string\n /** Opens a confirm modal and returns its id. */\n openConfirmModal: (props: OpenConfirmModal) => string\n /** Opens a predefined context modal and returns its id. */\n openContextModal: (modal: string, props: OpenContextModal) => string\n /** Closes the modal with the given id. */\n closeModal: (id: string, canceled?: boolean) => void\n /** Closes the context modal with the given id. */\n closeContextModal: (id: string, canceled?: boolean) => void\n /** Closes all opened modals. */\n closeAll: () => void\n /** Dynamically updates the content and properties of a regular or confirm modal. */\n updateModal: (payload: { modalId: string } & Partial<OpenConfirmModal>) => void\n /** Dynamically updates the content and properties of a context modal. */\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","<script setup lang=\"ts\">\nimport { computed, useSlots } from 'vue'\nimport { Box, Button, Group } from '@mantine-vue/core'\nimport { useModals } from '../../use-modals'\nimport type { ConfirmModalEmits, ConfirmModalProps } from './ConfirmModal.types'\n\ndefineOptions({ name: 'ConfirmModal', inheritAttrs: false })\nconst props = withDefaults(defineProps<ConfirmModalProps>(), {\n closeOnConfirm: true,\n closeOnCancel: true,\n labels: () => ({ cancel: '', confirm: '' }),\n})\nconst emit = defineEmits<ConfirmModalEmits>()\nconst slots = useSlots()\nconst ctx = useModals()\nconst hasChildren = computed(() => Boolean(slots.default))\nconst cancelButtonProps = computed(() => {\n const value = { ...props.cancelProps }\n delete value.onClick\n delete value.children\n return value\n})\nconst confirmButtonProps = computed(() => {\n const value = { ...props.confirmProps }\n delete value.onClick\n delete value.children\n return value\n})\nconst renderCancelLabel = () => props.cancelProps?.children ?? props.labels.cancel\nconst renderConfirmLabel = () => props.confirmProps?.children ?? props.labels.confirm\n\nfunction cancel(event: MouseEvent) {\n props.cancelProps?.onClick?.(event)\n emit('cancel')\n if (props.closeOnCancel) ctx.closeModal(props.id!)\n}\nfunction confirm(event: MouseEvent) {\n props.confirmProps?.onClick?.(event)\n emit('confirm')\n if (props.closeOnConfirm) ctx.closeModal(props.id!)\n}\n</script>\n\n<template>\n <Box v-if=\"hasChildren\" mb=\"md\"><slot /></Box>\n <Group v-bind=\"props.groupProps\" :mt=\"hasChildren ? 0 : 'md'\" justify=\"flex-end\">\n <Button v-bind=\"cancelButtonProps\" variant=\"default\" @click=\"cancel\">\n <component :is=\"renderCancelLabel\" />\n </Button>\n <Button v-bind=\"confirmButtonProps\" @click=\"confirm\">\n <component :is=\"renderConfirmLabel\" />\n </Button>\n </Group>\n</template>\n","<script setup lang=\"ts\">\nimport { computed, useSlots } from 'vue'\nimport { Box, Button, Group } from '@mantine-vue/core'\nimport { useModals } from '../../use-modals'\nimport type { ConfirmModalEmits, ConfirmModalProps } from './ConfirmModal.types'\n\ndefineOptions({ name: 'ConfirmModal', inheritAttrs: false })\nconst props = withDefaults(defineProps<ConfirmModalProps>(), {\n closeOnConfirm: true,\n closeOnCancel: true,\n labels: () => ({ cancel: '', confirm: '' }),\n})\nconst emit = defineEmits<ConfirmModalEmits>()\nconst slots = useSlots()\nconst ctx = useModals()\nconst hasChildren = computed(() => Boolean(slots.default))\nconst cancelButtonProps = computed(() => {\n const value = { ...props.cancelProps }\n delete value.onClick\n delete value.children\n return value\n})\nconst confirmButtonProps = computed(() => {\n const value = { ...props.confirmProps }\n delete value.onClick\n delete value.children\n return value\n})\nconst renderCancelLabel = () => props.cancelProps?.children ?? props.labels.cancel\nconst renderConfirmLabel = () => props.confirmProps?.children ?? props.labels.confirm\n\nfunction cancel(event: MouseEvent) {\n props.cancelProps?.onClick?.(event)\n emit('cancel')\n if (props.closeOnCancel) ctx.closeModal(props.id!)\n}\nfunction confirm(event: MouseEvent) {\n props.confirmProps?.onClick?.(event)\n emit('confirm')\n if (props.closeOnConfirm) ctx.closeModal(props.id!)\n}\n</script>\n\n<template>\n <Box v-if=\"hasChildren\" mb=\"md\"><slot /></Box>\n <Group v-bind=\"props.groupProps\" :mt=\"hasChildren ? 0 : 'md'\" justify=\"flex-end\">\n <Button v-bind=\"cancelButtonProps\" variant=\"default\" @click=\"cancel\">\n <component :is=\"renderCancelLabel\" />\n </Button>\n <Button v-bind=\"confirmButtonProps\" @click=\"confirm\">\n <component :is=\"renderConfirmLabel\" />\n </Button>\n </Group>\n</template>\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 /** Opens a regular modal and returns its id. */\n open: (props: ModalSettings) => openModalAction(props),\n /** Closes the modal with the given id. */\n close: (id: string) => closeModalAction(id),\n /** Closes all opened modals. */\n closeAll: () => closeAllModalsAction(),\n /** Opens a confirm modal and returns its id. */\n openConfirmModal: (props: OpenConfirmModal) => openConfirmModalAction(props),\n /** Opens a predefined context modal and returns its id. */\n openContextModal: (payload: OpenContextModal & { modal: string }) =>\n openContextModalPayload(payload),\n /** Dynamically updates the content and properties of a regular or confirm modal. */\n updateModal: (payload: { modalId: string } & Partial<OpenConfirmModal>) =>\n updateModalAction(payload),\n /** Dynamically updates the content and properties of a context modal. */\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","<script setup lang=\"ts\">\nimport { computed, provide } from 'vue'\nimport { Modal, getDefaultZIndex } from '@mantine-vue/core'\nimport ConfirmModal from '../ConfirmModal/ConfirmModal.vue'\nimport {\n ModalsContextKey,\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'\nimport type { ModalsProviderProps } from './ModalsProvider.types'\n\ndefineOptions({ name: 'ModalsProvider' })\nconst props = defineProps<ModalsProviderProps>()\nconst state = useModalsState(modalsStore)\nconst openModal = (settings: ModalSettings) => openModalAction(settings, modalsStore)\nconst openConfirmModal = (settings: OpenConfirmModal) =>\n openConfirmModalAction(settings, modalsStore)\nconst openContextModal = (modal: string, settings: OpenContextModal) =>\n openContextModalAction(modal, settings, modalsStore)\nconst closeModal = (id: string, canceled?: boolean) => closeModalAction(id, canceled, modalsStore)\nconst closeAll = () => closeAllModalsAction(undefined, modalsStore)\nconst updateModal = (payload: { modalId: string } & Partial<OpenConfirmModal>) =>\n updateModalAction(payload, modalsStore)\nconst updateContextModal = (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n updateContextModalAction(payload, modalsStore)\n\nconst context: 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}\nprovide(ModalsContextKey, context)\n\nfunction separateConfirmModalProps(settings: OpenConfirmModal) {\n const value = { ...settings } as any\n const confirmModalProps = {\n id: value.id,\n onCancel: value.onCancel,\n onConfirm: value.onConfirm,\n closeOnConfirm: value.closeOnConfirm,\n closeOnCancel: value.closeOnCancel,\n cancelProps: value.cancelProps,\n confirmProps: value.confirmProps,\n groupProps: value.groupProps,\n labels: value.labels,\n }\n for (const key of [\n 'children',\n 'onCancel',\n 'onConfirm',\n 'closeOnConfirm',\n 'closeOnCancel',\n 'cancelProps',\n 'confirmProps',\n 'groupProps',\n 'labels',\n ])\n delete value[key]\n return { confirmModalProps, modalProps: value }\n}\n\nconst presentation = computed(() => {\n const current = state.value.current\n if (!current) return { modalProps: {}, component: null, componentProps: {} }\n if (current.type === 'context') {\n const { innerProps, ...modalProps } = current.props\n return {\n modalProps,\n component: props.modals?.[current.ctx] ?? null,\n componentProps: { innerProps, context, id: current.id },\n }\n }\n if (current.type === 'confirm') {\n const separated = separateConfirmModalProps(current.props)\n return {\n modalProps: separated.modalProps,\n component: ConfirmModal,\n componentProps: {\n ...separated.confirmModalProps,\n id: current.id,\n labels: current.props.labels || props.labels,\n },\n }\n }\n const modalProps = { ...current.props } as any\n delete modalProps.children\n return { modalProps, component: null, componentProps: {} }\n})\nconst modalAttrs = computed(() => {\n const value = {\n zIndex: getDefaultZIndex('modal') + 1,\n ...props.modalProps,\n ...presentation.value.modalProps,\n }\n delete value.opened\n delete value.onClose\n return value\n})\nconst renderContent = () => {\n const current = state.value.current\n if (!current || current.type !== 'content') return null\n const children = current.props.children\n return typeof children === 'function' ? children() : (children ?? null)\n}\n</script>\n\n<template>\n <Modal\n v-bind=\"modalAttrs\"\n :opened=\"state.modals.length > 0\"\n @close=\"closeModal(state.current?.id as string)\"\n >\n <component\n :is=\"presentation.component\"\n v-if=\"presentation.component\"\n v-bind=\"presentation.componentProps\"\n />\n <component :is=\"renderContent\" v-else />\n </Modal>\n <slot />\n</template>\n","<script setup lang=\"ts\">\nimport { computed, provide } from 'vue'\nimport { Modal, getDefaultZIndex } from '@mantine-vue/core'\nimport ConfirmModal from '../ConfirmModal/ConfirmModal.vue'\nimport {\n ModalsContextKey,\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'\nimport type { ModalsProviderProps } from './ModalsProvider.types'\n\ndefineOptions({ name: 'ModalsProvider' })\nconst props = defineProps<ModalsProviderProps>()\nconst state = useModalsState(modalsStore)\nconst openModal = (settings: ModalSettings) => openModalAction(settings, modalsStore)\nconst openConfirmModal = (settings: OpenConfirmModal) =>\n openConfirmModalAction(settings, modalsStore)\nconst openContextModal = (modal: string, settings: OpenContextModal) =>\n openContextModalAction(modal, settings, modalsStore)\nconst closeModal = (id: string, canceled?: boolean) => closeModalAction(id, canceled, modalsStore)\nconst closeAll = () => closeAllModalsAction(undefined, modalsStore)\nconst updateModal = (payload: { modalId: string } & Partial<OpenConfirmModal>) =>\n updateModalAction(payload, modalsStore)\nconst updateContextModal = (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n updateContextModalAction(payload, modalsStore)\n\nconst context: 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}\nprovide(ModalsContextKey, context)\n\nfunction separateConfirmModalProps(settings: OpenConfirmModal) {\n const value = { ...settings } as any\n const confirmModalProps = {\n id: value.id,\n onCancel: value.onCancel,\n onConfirm: value.onConfirm,\n closeOnConfirm: value.closeOnConfirm,\n closeOnCancel: value.closeOnCancel,\n cancelProps: value.cancelProps,\n confirmProps: value.confirmProps,\n groupProps: value.groupProps,\n labels: value.labels,\n }\n for (const key of [\n 'children',\n 'onCancel',\n 'onConfirm',\n 'closeOnConfirm',\n 'closeOnCancel',\n 'cancelProps',\n 'confirmProps',\n 'groupProps',\n 'labels',\n ])\n delete value[key]\n return { confirmModalProps, modalProps: value }\n}\n\nconst presentation = computed(() => {\n const current = state.value.current\n if (!current) return { modalProps: {}, component: null, componentProps: {} }\n if (current.type === 'context') {\n const { innerProps, ...modalProps } = current.props\n return {\n modalProps,\n component: props.modals?.[current.ctx] ?? null,\n componentProps: { innerProps, context, id: current.id },\n }\n }\n if (current.type === 'confirm') {\n const separated = separateConfirmModalProps(current.props)\n return {\n modalProps: separated.modalProps,\n component: ConfirmModal,\n componentProps: {\n ...separated.confirmModalProps,\n id: current.id,\n labels: current.props.labels || props.labels,\n },\n }\n }\n const modalProps = { ...current.props } as any\n delete modalProps.children\n return { modalProps, component: null, componentProps: {} }\n})\nconst modalAttrs = computed(() => {\n const value = {\n zIndex: getDefaultZIndex('modal') + 1,\n ...props.modalProps,\n ...presentation.value.modalProps,\n }\n delete value.opened\n delete value.onClose\n return value\n})\nconst renderContent = () => {\n const current = state.value.current\n if (!current || current.type !== 'content') return null\n const children = current.props.children\n return typeof children === 'function' ? children() : (children ?? null)\n}\n</script>\n\n<template>\n <Modal\n v-bind=\"modalAttrs\"\n :opened=\"state.modals.length > 0\"\n @close=\"closeModal(state.current?.id as string)\"\n >\n <component\n :is=\"presentation.component\"\n v-if=\"presentation.component\"\n v-bind=\"presentation.componentProps\"\n />\n <component :is=\"renderContent\" v-else />\n </Modal>\n <slot />\n</template>\n"],"mappings":";;;;AA6DA,IAAa,mBAAqD,OAAO,eAAe;;;AC1DxF,SAAgB,YAAgC;CAC9C,MAAM,MAAM,OAAO,kBAAkB,IAAI;CAEzC,IAAI,CAAC,KACH,MAAM,IAAI,MACR,2HACF;CAGF,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;ECNA,MAAM,QAAQ;EAKd,MAAM,OAAO;EACb,MAAM,QAAQ,SAAS;EACvB,MAAM,MAAM,UAAU;EACtB,MAAM,cAAc,eAAe,QAAQ,MAAM,OAAO,CAAC;EACzD,MAAM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{
4
+ /** Modal id, defaults to a random id, can be used to close the modal programmatically. */
5
+ id?: string;
6
+ /** Determines whether the modal should be closed when the confirm button is clicked. @default true */
7
+ closeOnConfirm?: boolean;
8
+ /** Determines whether the modal should be closed when the cancel button is clicked. @default true */
9
+ closeOnCancel?: boolean;
10
+ /** Cancel button props. */
11
+ cancelProps?: Record<string, any>;
12
+ /** Confirm button props. */
13
+ confirmProps?: Record<string, any>;
14
+ /** Buttons `Group` props. */
15
+ groupProps?: Record<string, any>;
16
+ /** Cancel and confirm button labels, can be defined on `ModalsProvider`. */
17
+ labels?: ConfirmLabels;
18
+ }
19
+ /** Events emitted by `ConfirmModal`. */
20
+ export interface ConfirmModalEmits {
21
+ /** Emitted when the cancel button is clicked. */
22
+ cancel: [];
23
+ /** Emitted when the confirm button is clicked. */
24
+ confirm: [];
25
+ }
26
+ /** Callbacks accepted by the imperative `openConfirmModal` settings object. */
27
+ export interface ConfirmModalCallbacks {
28
+ /** Called when the cancel button is clicked. */
29
+ onCancel?: () => void;
30
+ /** Called when the confirm button is clicked. */
31
+ onConfirm?: () => void;
32
+ }
@@ -0,0 +1,20 @@
1
+ import type { ConfirmModalProps } from './ConfirmModal.types';
2
+ declare var __VLS_7: {};
3
+ type __VLS_Slots = {} & {
4
+ default?: (props: typeof __VLS_7) => any;
5
+ };
6
+ declare const __VLS_base: import("vue").DefineComponent<ConfirmModalProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ cancel: () => any;
8
+ confirm: () => any;
9
+ }, string, import("vue").PublicProps, Readonly<ConfirmModalProps> & Readonly<{
10
+ onCancel?: (() => any) | undefined;
11
+ onConfirm?: (() => any) | undefined;
12
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
14
+ declare const _default: typeof __VLS_export;
15
+ export default _default;
16
+ type __VLS_WithSlots<T, S> = T & {
17
+ new (): {
18
+ $slots: S;
19
+ };
20
+ };
@@ -0,0 +1,2 @@
1
+ export { default as ConfirmModal } from './ConfirmModal.vue';
2
+ export type { ConfirmModalCallbacks, ConfirmModalEmits, ConfirmModalProps, } from './ConfirmModal.types';
@@ -0,0 +1,10 @@
1
+ import type { ConfirmLabels, ModalSettings } from '../../context';
2
+ /** Props accepted by `ModalsProvider`. */
3
+ export interface ModalsProviderProps {
4
+ /** Predefined modals. */
5
+ modals?: Record<string, any>;
6
+ /** Shared Modal component props, applied for every modal. */
7
+ modalProps?: ModalSettings;
8
+ /** Confirm modal labels. */
9
+ labels?: ConfirmLabels;
10
+ }
@@ -0,0 +1,14 @@
1
+ import type { ModalsProviderProps } from './ModalsProvider.types';
2
+ declare var __VLS_19: {};
3
+ type __VLS_Slots = {} & {
4
+ default?: (props: typeof __VLS_19) => any;
5
+ };
6
+ declare const __VLS_base: import("vue").DefineComponent<ModalsProviderProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ModalsProviderProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
8
+ declare const _default: typeof __VLS_export;
9
+ export default _default;
10
+ type __VLS_WithSlots<T, S> = T & {
11
+ new (): {
12
+ $slots: S;
13
+ };
14
+ };
@@ -0,0 +1,2 @@
1
+ export { default as ModalsProvider } from './ModalsProvider.vue';
2
+ export type { ModalsProviderProps } from './ModalsProvider.types';
package/lib/context.d.ts CHANGED
@@ -1,20 +1,27 @@
1
1
  import type { InjectionKey, VNodeChild } from 'vue';
2
2
  import type { ModalProps } from '@mantine-vue/core';
3
- import type { ConfirmModalProps } from './ConfirmModal';
3
+ import type { ConfirmModalCallbacks, ConfirmModalProps } from './components/ConfirmModal';
4
4
  export type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & {
5
+ /** Modal id, defaults to a random id, can be used to close or update the modal programmatically. */
5
6
  modalId?: string;
7
+ /** Modal content. */
6
8
  children?: VNodeChild | (() => VNodeChild);
9
+ /** Called when the modal closes. */
7
10
  onClose?: () => void;
8
11
  };
9
12
  export type ConfirmLabels = Record<'confirm' | 'cancel', VNodeChild>;
10
- export interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {
13
+ export interface OpenConfirmModal extends ModalSettings, ConfirmModalProps, ConfirmModalCallbacks {
11
14
  }
12
15
  export interface OpenContextModal<CustomProps extends Record<string, any> = Record<string, any>> extends ModalSettings {
16
+ /** Props passed to the registered context modal component. */
13
17
  innerProps: CustomProps;
14
18
  }
15
19
  export interface ContextModalProps<T extends Record<string, any> = Record<string, any>> {
20
+ /** Modals manager context. */
16
21
  context: ModalsContextProps;
22
+ /** Props passed to `modals.openContextModal`. */
17
23
  innerProps: T;
24
+ /** Current modal id. */
18
25
  id: string;
19
26
  }
20
27
  export type ModalState = {
@@ -32,17 +39,27 @@ export type ModalState = {
32
39
  ctx: string;
33
40
  };
34
41
  export interface ModalsContextProps {
42
+ /** Shared Modal component props applied to every modal. */
35
43
  modalProps: ModalSettings;
44
+ /** Currently opened modal stack. */
36
45
  modals: ModalState[];
46
+ /** Opens a regular modal and returns its id. */
37
47
  openModal: (props: ModalSettings) => string;
48
+ /** Opens a confirm modal and returns its id. */
38
49
  openConfirmModal: (props: OpenConfirmModal) => string;
50
+ /** Opens a predefined context modal and returns its id. */
39
51
  openContextModal: (modal: string, props: OpenContextModal) => string;
52
+ /** Closes the modal with the given id. */
40
53
  closeModal: (id: string, canceled?: boolean) => void;
54
+ /** Closes the context modal with the given id. */
41
55
  closeContextModal: (id: string, canceled?: boolean) => void;
56
+ /** Closes all opened modals. */
42
57
  closeAll: () => void;
58
+ /** Dynamically updates the content and properties of a regular or confirm modal. */
43
59
  updateModal: (payload: {
44
60
  modalId: string;
45
61
  } & Partial<OpenConfirmModal>) => void;
62
+ /** Dynamically updates the content and properties of a context modal. */
46
63
  updateContextModal: (payload: {
47
64
  modalId: string;
48
65
  } & Partial<OpenContextModal<any>>) => void;