@mantine/modals 9.0.0-alpha.5 → 9.0.0-alpha.7
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/ConfirmModal.cjs +42 -40
- package/cjs/ConfirmModal.cjs.map +1 -1
- package/cjs/ModalsProvider.cjs +184 -209
- package/cjs/ModalsProvider.cjs.map +1 -1
- package/cjs/context.cjs +6 -8
- package/cjs/context.cjs.map +1 -1
- package/cjs/events.cjs +33 -26
- package/cjs/events.cjs.map +1 -1
- package/cjs/index.cjs +14 -19
- package/cjs/reducer.cjs +59 -77
- package/cjs/reducer.cjs.map +1 -1
- package/cjs/use-modals/use-modals.cjs +10 -15
- package/cjs/use-modals/use-modals.cjs.map +1 -1
- package/esm/ConfirmModal.mjs +42 -38
- package/esm/ConfirmModal.mjs.map +1 -1
- package/esm/ModalsProvider.mjs +184 -207
- package/esm/ModalsProvider.mjs.map +1 -1
- package/esm/context.mjs +6 -5
- package/esm/context.mjs.map +1 -1
- package/esm/events.mjs +32 -22
- package/esm/events.mjs.map +1 -1
- package/esm/index.mjs +4 -4
- package/esm/reducer.mjs +59 -75
- package/esm/reducer.mjs.map +1 -1
- package/esm/use-modals/use-modals.mjs +10 -13
- package/esm/use-modals/use-modals.mjs.map +1 -1
- package/package.json +3 -3
- package/cjs/index.cjs.map +0 -1
- package/esm/index.mjs.map +0 -1
package/cjs/context.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","sources":["../src/context.ts"],"sourcesContent":["import { createContext, ReactNode } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & { modalId?: string };\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', ReactNode>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal<\n CustomProps extends Record<string, any> = {},\n> extends ModalSettings {\n innerProps: CustomProps;\n}\n\nexport interface ContextModalProps<T extends Record<string, any> = {}> {\n context: ModalsContextProps;\n innerProps: T;\n id: string;\n}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: OpenContextModal; type: 'context'; ctx: string };\n\nexport interface ModalsContextProps {\n modalProps: ModalSettings;\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: <TKey extends MantineModal>(\n modal: TKey,\n props: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']>\n ) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeContextModal: <TKey extends MantineModal>(id: TKey, 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 interface MantineModalsOverride {}\n\nexport type MantineModalsOverwritten = MantineModalsOverride extends {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n}\n ? MantineModalsOverride\n : {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n };\n\nexport type MantineModals = MantineModalsOverwritten['modals'];\n\nexport type MantineModal = keyof MantineModals;\n\nexport const ModalsContext = createContext<ModalsContextProps>(null as any);\nModalsContext.displayName = '@mantine/modals/ModalsContext';\n"],"
|
|
1
|
+
{"version":3,"file":"context.cjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { createContext, ReactNode } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & { modalId?: string };\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', ReactNode>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal<\n CustomProps extends Record<string, any> = {},\n> extends ModalSettings {\n innerProps: CustomProps;\n}\n\nexport interface ContextModalProps<T extends Record<string, any> = {}> {\n context: ModalsContextProps;\n innerProps: T;\n id: string;\n}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: OpenContextModal; type: 'context'; ctx: string };\n\nexport interface ModalsContextProps {\n modalProps: ModalSettings;\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: <TKey extends MantineModal>(\n modal: TKey,\n props: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']>\n ) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeContextModal: <TKey extends MantineModal>(id: TKey, 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 interface MantineModalsOverride {}\n\nexport type MantineModalsOverwritten = MantineModalsOverride extends {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n}\n ? MantineModalsOverride\n : {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n };\n\nexport type MantineModals = MantineModalsOverwritten['modals'];\n\nexport type MantineModal = keyof MantineModals;\n\nexport const ModalsContext = createContext<ModalsContextProps>(null as any);\nModalsContext.displayName = '@mantine/modals/ModalsContext';\n"],"mappings":";;AAwDA,MAAa,iBAAA,oBAAA,eAAkD,KAAY;AAC3E,cAAc,cAAc"}
|
package/cjs/events.cjs
CHANGED
|
@@ -1,42 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const [useModalsEvents, createEvent] = core.createUseExternalEvents("mantine-modals");
|
|
1
|
+
"use client";
|
|
2
|
+
let _mantine_core = require("@mantine/core");
|
|
3
|
+
let _mantine_hooks = require("@mantine/hooks");
|
|
4
|
+
//#region packages/@mantine/modals/src/events.ts
|
|
5
|
+
const [useModalsEvents, createEvent] = (0, _mantine_core.createUseExternalEvents)("mantine-modals");
|
|
8
6
|
const openModal = (payload) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const id = payload.modalId || (0, _mantine_hooks.randomId)();
|
|
8
|
+
createEvent("openModal")({
|
|
9
|
+
...payload,
|
|
10
|
+
modalId: id
|
|
11
|
+
});
|
|
12
|
+
return id;
|
|
12
13
|
};
|
|
13
14
|
const openConfirmModal = (payload) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const id = payload.modalId || (0, _mantine_hooks.randomId)();
|
|
16
|
+
createEvent("openConfirmModal")({
|
|
17
|
+
...payload,
|
|
18
|
+
modalId: id
|
|
19
|
+
});
|
|
20
|
+
return id;
|
|
17
21
|
};
|
|
18
22
|
const openContextModal = (payload) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const id = payload.modalId || (0, _mantine_hooks.randomId)();
|
|
24
|
+
createEvent("openContextModal")({
|
|
25
|
+
...payload,
|
|
26
|
+
modalId: id
|
|
27
|
+
});
|
|
28
|
+
return id;
|
|
22
29
|
};
|
|
23
30
|
const closeModal = createEvent("closeModal");
|
|
24
31
|
const closeAllModals = createEvent("closeAllModals");
|
|
25
32
|
const updateModal = (payload) => createEvent("updateModal")(payload);
|
|
26
33
|
const updateContextModal = (payload) => createEvent("updateContextModal")(payload);
|
|
27
34
|
const modals = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
open: openModal,
|
|
36
|
+
close: closeModal,
|
|
37
|
+
closeAll: closeAllModals,
|
|
38
|
+
openConfirmModal,
|
|
39
|
+
openContextModal,
|
|
40
|
+
updateModal,
|
|
41
|
+
updateContextModal
|
|
35
42
|
};
|
|
36
|
-
|
|
43
|
+
//#endregion
|
|
37
44
|
exports.closeAllModals = closeAllModals;
|
|
38
45
|
exports.closeModal = closeModal;
|
|
39
|
-
exports.createEvent = createEvent;
|
|
40
46
|
exports.modals = modals;
|
|
41
47
|
exports.openConfirmModal = openConfirmModal;
|
|
42
48
|
exports.openContextModal = openContextModal;
|
|
@@ -44,4 +50,5 @@ exports.openModal = openModal;
|
|
|
44
50
|
exports.updateContextModal = updateContextModal;
|
|
45
51
|
exports.updateModal = updateModal;
|
|
46
52
|
exports.useModalsEvents = useModalsEvents;
|
|
47
|
-
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=events.cjs.map
|
package/cjs/events.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.cjs","sources":["../src/events.ts"],"sourcesContent":["import { createUseExternalEvents, DataAttributes } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport {\n MantineModal,\n MantineModals,\n ModalSettings,\n OpenConfirmModal,\n OpenContextModal,\n} from './context';\n\ntype ModalsEvents = {\n openModal: (payload: ModalSettings) => string;\n openConfirmModal: (payload: OpenConfirmModal) => string;\n openContextModal: <TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & {\n modal: TKey;\n } & DataAttributes\n ) => string;\n closeModal: (id: string) => void;\n closeContextModal: <TKey extends MantineModal>(id: TKey) => void;\n closeAllModals: () => void;\n updateModal: (\n payload: { modalId: string } & Partial<ModalSettings> & Partial<OpenConfirmModal>\n ) => void;\n updateContextModal: (payload: { modalId: string } & Partial<OpenContextModal<any>>) => void;\n};\n\nexport const [useModalsEvents, createEvent] =\n createUseExternalEvents<ModalsEvents>('mantine-modals');\n\nexport const openModal: ModalsEvents['openModal'] = (payload) => {\n const id = payload.modalId || randomId();\n createEvent('openModal')({ ...payload, modalId: id });\n return id;\n};\n\nexport const openConfirmModal: ModalsEvents['openConfirmModal'] = (payload) => {\n const id = payload.modalId || randomId();\n createEvent('openConfirmModal')({ ...payload, modalId: id });\n return id;\n};\n\nexport const openContextModal: ModalsEvents['openContextModal'] = <TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & {\n modal: TKey;\n } & DataAttributes\n) => {\n const id = payload.modalId || randomId();\n createEvent('openContextModal')({ ...payload, modalId: id });\n return id;\n};\n\nexport const closeModal = createEvent('closeModal');\n\nexport const closeContextModal: ModalsEvents['closeContextModal'] = <TKey extends MantineModal>(\n id: TKey\n) => createEvent('closeContextModal')(id);\n\nexport const closeAllModals = createEvent('closeAllModals');\n\nexport const updateModal = (payload: { modalId: string } & Partial<ModalSettings>) =>\n createEvent('updateModal')(payload);\n\nexport const updateContextModal = (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n createEvent('updateContextModal')(payload);\n\nexport const modals: {\n open: ModalsEvents['openModal'];\n close: ModalsEvents['closeModal'];\n closeAll: ModalsEvents['closeAllModals'];\n openConfirmModal: ModalsEvents['openConfirmModal'];\n openContextModal: ModalsEvents['openContextModal'];\n updateModal: ModalsEvents['updateModal'];\n updateContextModal: ModalsEvents['updateContextModal'];\n} = {\n open: openModal,\n close: closeModal,\n closeAll: closeAllModals,\n openConfirmModal,\n openContextModal,\n updateModal,\n updateContextModal,\n};\n"],"
|
|
1
|
+
{"version":3,"file":"events.cjs","names":[],"sources":["../src/events.ts"],"sourcesContent":["import { createUseExternalEvents, DataAttributes } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport {\n MantineModal,\n MantineModals,\n ModalSettings,\n OpenConfirmModal,\n OpenContextModal,\n} from './context';\n\ntype ModalsEvents = {\n openModal: (payload: ModalSettings) => string;\n openConfirmModal: (payload: OpenConfirmModal) => string;\n openContextModal: <TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & {\n modal: TKey;\n } & DataAttributes\n ) => string;\n closeModal: (id: string) => void;\n closeContextModal: <TKey extends MantineModal>(id: TKey) => void;\n closeAllModals: () => void;\n updateModal: (\n payload: { modalId: string } & Partial<ModalSettings> & Partial<OpenConfirmModal>\n ) => void;\n updateContextModal: (payload: { modalId: string } & Partial<OpenContextModal<any>>) => void;\n};\n\nexport const [useModalsEvents, createEvent] =\n createUseExternalEvents<ModalsEvents>('mantine-modals');\n\nexport const openModal: ModalsEvents['openModal'] = (payload) => {\n const id = payload.modalId || randomId();\n createEvent('openModal')({ ...payload, modalId: id });\n return id;\n};\n\nexport const openConfirmModal: ModalsEvents['openConfirmModal'] = (payload) => {\n const id = payload.modalId || randomId();\n createEvent('openConfirmModal')({ ...payload, modalId: id });\n return id;\n};\n\nexport const openContextModal: ModalsEvents['openContextModal'] = <TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & {\n modal: TKey;\n } & DataAttributes\n) => {\n const id = payload.modalId || randomId();\n createEvent('openContextModal')({ ...payload, modalId: id });\n return id;\n};\n\nexport const closeModal = createEvent('closeModal');\n\nexport const closeContextModal: ModalsEvents['closeContextModal'] = <TKey extends MantineModal>(\n id: TKey\n) => createEvent('closeContextModal')(id);\n\nexport const closeAllModals = createEvent('closeAllModals');\n\nexport const updateModal = (payload: { modalId: string } & Partial<ModalSettings>) =>\n createEvent('updateModal')(payload);\n\nexport const updateContextModal = (payload: { modalId: string } & Partial<OpenContextModal<any>>) =>\n createEvent('updateContextModal')(payload);\n\nexport const modals: {\n open: ModalsEvents['openModal'];\n close: ModalsEvents['closeModal'];\n closeAll: ModalsEvents['closeAllModals'];\n openConfirmModal: ModalsEvents['openConfirmModal'];\n openContextModal: ModalsEvents['openContextModal'];\n updateModal: ModalsEvents['updateModal'];\n updateContextModal: ModalsEvents['updateContextModal'];\n} = {\n open: openModal,\n close: closeModal,\n closeAll: closeAllModals,\n openConfirmModal,\n openContextModal,\n updateModal,\n updateContextModal,\n};\n"],"mappings":";;;;AA2BA,MAAa,CAAC,iBAAiB,gBAAA,GAAA,cAAA,yBACS,iBAAiB;AAEzD,MAAa,aAAwC,YAAY;CAC/D,MAAM,KAAK,QAAQ,YAAA,GAAA,eAAA,WAAqB;AACxC,aAAY,YAAY,CAAC;EAAE,GAAG;EAAS,SAAS;EAAI,CAAC;AACrD,QAAO;;AAGT,MAAa,oBAAsD,YAAY;CAC7E,MAAM,KAAK,QAAQ,YAAA,GAAA,eAAA,WAAqB;AACxC,aAAY,mBAAmB,CAAC;EAAE,GAAG;EAAS,SAAS;EAAI,CAAC;AAC5D,QAAO;;AAGT,MAAa,oBACX,YAGG;CACH,MAAM,KAAK,QAAQ,YAAA,GAAA,eAAA,WAAqB;AACxC,aAAY,mBAAmB,CAAC;EAAE,GAAG;EAAS,SAAS;EAAI,CAAC;AAC5D,QAAO;;AAGT,MAAa,aAAa,YAAY,aAAa;AAMnD,MAAa,iBAAiB,YAAY,iBAAiB;AAE3D,MAAa,eAAe,YAC1B,YAAY,cAAc,CAAC,QAAQ;AAErC,MAAa,sBAAsB,YACjC,YAAY,qBAAqB,CAAC,QAAQ;AAE5C,MAAa,SAQT;CACF,MAAM;CACN,OAAO;CACP,UAAU;CACV;CACA;CACA;CACA;CACD"}
|
package/cjs/index.cjs
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.openContextModal = events.openContextModal;
|
|
16
|
-
exports.openModal = events.openModal;
|
|
17
|
-
exports.updateContextModal = events.updateContextModal;
|
|
18
|
-
exports.updateModal = events.updateModal;
|
|
19
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_use_modals = require("./use-modals/use-modals.cjs");
|
|
3
|
+
const require_events = require("./events.cjs");
|
|
4
|
+
const require_ModalsProvider = require("./ModalsProvider.cjs");
|
|
5
|
+
exports.ModalsProvider = require_ModalsProvider.ModalsProvider;
|
|
6
|
+
exports.closeAllModals = require_events.closeAllModals;
|
|
7
|
+
exports.closeModal = require_events.closeModal;
|
|
8
|
+
exports.modals = require_events.modals;
|
|
9
|
+
exports.openConfirmModal = require_events.openConfirmModal;
|
|
10
|
+
exports.openContextModal = require_events.openContextModal;
|
|
11
|
+
exports.openModal = require_events.openModal;
|
|
12
|
+
exports.updateContextModal = require_events.updateContextModal;
|
|
13
|
+
exports.updateModal = require_events.updateModal;
|
|
14
|
+
exports.useModals = require_use_modals.useModals;
|
package/cjs/reducer.cjs
CHANGED
|
@@ -1,83 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
//#region packages/@mantine/modals/src/reducer.ts
|
|
4
3
|
function handleCloseModal(modal, canceled) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
modal.props.onClose?.();
|
|
4
|
+
if (canceled && modal.type === "confirm") modal.props.onCancel?.();
|
|
5
|
+
modal.props.onClose?.();
|
|
9
6
|
}
|
|
10
7
|
function modalsReducer(state, action) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return modal;
|
|
67
|
-
});
|
|
68
|
-
const currentModal = state.current?.id === modalId ? updatedModals.find((modal) => modal.id === modalId) || state.current : state.current;
|
|
69
|
-
return {
|
|
70
|
-
...state,
|
|
71
|
-
modals: updatedModals,
|
|
72
|
-
current: currentModal
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
default: {
|
|
76
|
-
return state;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
8
|
+
switch (action.type) {
|
|
9
|
+
case "OPEN": return {
|
|
10
|
+
current: action.modal,
|
|
11
|
+
modals: [...state.modals, action.modal]
|
|
12
|
+
};
|
|
13
|
+
case "CLOSE": {
|
|
14
|
+
if (!state.modals.find((m) => m.id === action.modalId)) return state;
|
|
15
|
+
const remainingModals = state.modals.filter((m) => m.id !== action.modalId);
|
|
16
|
+
return {
|
|
17
|
+
current: remainingModals[remainingModals.length - 1] || state.current,
|
|
18
|
+
modals: remainingModals
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
case "CLOSE_ALL":
|
|
22
|
+
if (!state.modals.length) return state;
|
|
23
|
+
return {
|
|
24
|
+
current: state.current,
|
|
25
|
+
modals: []
|
|
26
|
+
};
|
|
27
|
+
case "UPDATE": {
|
|
28
|
+
const { modalId, newProps } = action;
|
|
29
|
+
const updatedModals = state.modals.map((modal) => {
|
|
30
|
+
if (modal.id !== modalId) return modal;
|
|
31
|
+
if (modal.type === "content" || modal.type === "confirm") return {
|
|
32
|
+
...modal,
|
|
33
|
+
props: {
|
|
34
|
+
...modal.props,
|
|
35
|
+
...newProps
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
if (modal.type === "context") return {
|
|
39
|
+
...modal,
|
|
40
|
+
props: {
|
|
41
|
+
...modal.props,
|
|
42
|
+
...newProps,
|
|
43
|
+
innerProps: {
|
|
44
|
+
...modal.props.innerProps,
|
|
45
|
+
...newProps.innerProps
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return modal;
|
|
50
|
+
});
|
|
51
|
+
const currentModal = state.current?.id === modalId ? updatedModals.find((modal) => modal.id === modalId) || state.current : state.current;
|
|
52
|
+
return {
|
|
53
|
+
...state,
|
|
54
|
+
modals: updatedModals,
|
|
55
|
+
current: currentModal
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
default: return state;
|
|
59
|
+
}
|
|
79
60
|
}
|
|
80
|
-
|
|
61
|
+
//#endregion
|
|
81
62
|
exports.handleCloseModal = handleCloseModal;
|
|
82
63
|
exports.modalsReducer = modalsReducer;
|
|
83
|
-
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=reducer.cjs.map
|
package/cjs/reducer.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.cjs","sources":["../src/reducer.ts"],"sourcesContent":["import { ModalSettings, ModalState, OpenContextModal } from './context';\n\ninterface ModalsState {\n modals: ModalState[];\n\n /**\n * Modal that is currently open or was the last open one.\n * Keeping the last one is necessary for providing a clean exit transition.\n */\n current: ModalState | null;\n}\n\ninterface OpenAction {\n type: 'OPEN';\n modal: ModalState;\n}\n\ninterface CloseAction {\n type: 'CLOSE';\n modalId: string;\n canceled?: boolean;\n}\n\ninterface CloseAllAction {\n type: 'CLOSE_ALL';\n canceled?: boolean;\n}\n\ninterface UpdateAction {\n type: 'UPDATE';\n modalId: string;\n newProps: Partial<ModalSettings>;\n}\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(\n state: ModalsState,\n action: OpenAction | CloseAction | CloseAllAction | UpdateAction\n): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n return {\n current: action.modal,\n modals: [...state.modals, action.modal],\n };\n }\n case 'CLOSE': {\n const modal = state.modals.find((m) => m.id === action.modalId);\n if (!modal) {\n return state;\n }\n\n const remainingModals = state.modals.filter((m) => m.id !== action.modalId);\n\n return {\n current: remainingModals[remainingModals.length - 1] || state.current,\n modals: remainingModals,\n };\n }\n case 'CLOSE_ALL': {\n if (!state.modals.length) {\n return state;\n }\n\n return {\n current: state.current,\n modals: [],\n };\n }\n case 'UPDATE': {\n const { modalId, newProps } = action;\n\n const updatedModals = state.modals.map((modal) => {\n if (modal.id !== modalId) {\n return modal;\n }\n\n if (modal.type === 'content' || modal.type === 'confirm') {\n return {\n ...modal,\n props: {\n ...modal.props,\n ...newProps,\n },\n };\n }\n\n if (modal.type === 'context') {\n return {\n ...modal,\n props: {\n ...modal.props,\n ...newProps,\n innerProps: {\n ...modal.props.innerProps,\n ...(newProps as Partial<OpenContextModal<any>>).innerProps,\n },\n },\n };\n }\n\n return modal;\n });\n\n const currentModal =\n state.current?.id === modalId\n ? updatedModals.find((modal) => modal.id === modalId) || state.current\n : state.current;\n\n return {\n ...state,\n modals: updatedModals,\n current: currentModal,\n };\n }\n default: {\n return state;\n }\n }\n}\n"],"names":[],"mappings":";;;AAkCO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAiB,CAAA,CAAA,CAAA,CAAA,GAAmB,QAAA,CAAA,CAAoB,CAAA;AACtE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,QAAA,CAAA,CAAA,CAAA,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,SAAA,CAAA,CAAW,CAAA;AACxC,CAAA,CAAA,CAAA,C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AA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAC7D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAEZ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA;AAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACL,GAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACH,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAQ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACR,OAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACX,CAAA;AAAA,CAAA,CAAA,CAAA,CACF,CAAA;AAAA,CAAA,CAAA,CAAA,CACA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA;AACP,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA,CAAA,CAAA,CAAA,CACT,CAAA;AAAA,CAAA,CAAA,CAAA;AAEJ,CAAA;;;"}
|
|
1
|
+
{"version":3,"file":"reducer.cjs","names":[],"sources":["../src/reducer.ts"],"sourcesContent":["import { ModalSettings, ModalState, OpenContextModal } from './context';\n\ninterface ModalsState {\n modals: ModalState[];\n\n /**\n * Modal that is currently open or was the last open one.\n * Keeping the last one is necessary for providing a clean exit transition.\n */\n current: ModalState | null;\n}\n\ninterface OpenAction {\n type: 'OPEN';\n modal: ModalState;\n}\n\ninterface CloseAction {\n type: 'CLOSE';\n modalId: string;\n canceled?: boolean;\n}\n\ninterface CloseAllAction {\n type: 'CLOSE_ALL';\n canceled?: boolean;\n}\n\ninterface UpdateAction {\n type: 'UPDATE';\n modalId: string;\n newProps: Partial<ModalSettings>;\n}\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(\n state: ModalsState,\n action: OpenAction | CloseAction | CloseAllAction | UpdateAction\n): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n return {\n current: action.modal,\n modals: [...state.modals, action.modal],\n };\n }\n case 'CLOSE': {\n const modal = state.modals.find((m) => m.id === action.modalId);\n if (!modal) {\n return state;\n }\n\n const remainingModals = state.modals.filter((m) => m.id !== action.modalId);\n\n return {\n current: remainingModals[remainingModals.length - 1] || state.current,\n modals: remainingModals,\n };\n }\n case 'CLOSE_ALL': {\n if (!state.modals.length) {\n return state;\n }\n\n return {\n current: state.current,\n modals: [],\n };\n }\n case 'UPDATE': {\n const { modalId, newProps } = action;\n\n const updatedModals = state.modals.map((modal) => {\n if (modal.id !== modalId) {\n return modal;\n }\n\n if (modal.type === 'content' || modal.type === 'confirm') {\n return {\n ...modal,\n props: {\n ...modal.props,\n ...newProps,\n },\n };\n }\n\n if (modal.type === 'context') {\n return {\n ...modal,\n props: {\n ...modal.props,\n ...newProps,\n innerProps: {\n ...modal.props.innerProps,\n ...(newProps as Partial<OpenContextModal<any>>).innerProps,\n },\n },\n };\n }\n\n return modal;\n });\n\n const currentModal =\n state.current?.id === modalId\n ? updatedModals.find((modal) => modal.id === modalId) || state.current\n : state.current;\n\n return {\n ...state,\n modals: updatedModals,\n current: currentModal,\n };\n }\n default: {\n return state;\n }\n }\n}\n"],"mappings":";;AAkCA,SAAgB,iBAAiB,OAAmB,UAAoB;AACt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|
|
4
|
-
|
|
5
|
-
var context = require('../context.cjs');
|
|
6
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
const require_context = require("../context.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
//#region packages/@mantine/modals/src/use-modals/use-modals.ts
|
|
7
5
|
function useModals() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component"
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
return ctx;
|
|
6
|
+
const ctx = (0, react.use)(require_context.ModalsContext);
|
|
7
|
+
if (!ctx) throw new Error("[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component");
|
|
8
|
+
return ctx;
|
|
15
9
|
}
|
|
16
|
-
|
|
10
|
+
//#endregion
|
|
17
11
|
exports.useModals = useModals;
|
|
18
|
-
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=use-modals.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-modals.cjs","sources":["../../src/use-modals/use-modals.ts"],"sourcesContent":["import { use } from 'react';\nimport { ModalsContext } from '../context';\n\nexport function useModals() {\n const ctx = use(ModalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"use-modals.cjs","names":["ModalsContext"],"sources":["../../src/use-modals/use-modals.ts"],"sourcesContent":["import { use } from 'react';\nimport { ModalsContext } from '../context';\n\nexport function useModals() {\n const ctx = use(ModalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY;CAC1B,MAAM,OAAA,GAAA,MAAA,KAAUA,gBAAAA,cAAc;AAE9B,KAAI,CAAC,IACH,OAAM,IAAI,MACR,8GACD;AAGH,QAAO"}
|
package/esm/ConfirmModal.mjs
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { Box,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function ConfirmModal({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { useModals } from "./use-modals/use-modals.mjs";
|
|
3
|
+
import { Box, Button, Group } from "@mantine/core";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region packages/@mantine/modals/src/ConfirmModal.tsx
|
|
6
|
+
function ConfirmModal({ id, cancelProps, confirmProps, labels = {
|
|
7
|
+
cancel: "",
|
|
8
|
+
confirm: ""
|
|
9
|
+
}, closeOnConfirm = true, closeOnCancel = true, groupProps, onCancel, onConfirm, children }) {
|
|
10
|
+
const { cancel: cancelLabel, confirm: confirmLabel } = labels;
|
|
11
|
+
const ctx = useModals();
|
|
12
|
+
const handleCancel = (event) => {
|
|
13
|
+
typeof cancelProps?.onClick === "function" && cancelProps?.onClick(event);
|
|
14
|
+
typeof onCancel === "function" && onCancel();
|
|
15
|
+
closeOnCancel && ctx.closeModal(id);
|
|
16
|
+
};
|
|
17
|
+
const handleConfirm = (event) => {
|
|
18
|
+
typeof confirmProps?.onClick === "function" && confirmProps?.onClick(event);
|
|
19
|
+
typeof onConfirm === "function" && onConfirm();
|
|
20
|
+
closeOnConfirm && ctx.closeModal(id);
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [children && /* @__PURE__ */ jsx(Box, {
|
|
23
|
+
mb: "md",
|
|
24
|
+
children
|
|
25
|
+
}), /* @__PURE__ */ jsxs(Group, {
|
|
26
|
+
mt: children ? 0 : "md",
|
|
27
|
+
justify: "flex-end",
|
|
28
|
+
...groupProps,
|
|
29
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
30
|
+
variant: "default",
|
|
31
|
+
...cancelProps,
|
|
32
|
+
onClick: handleCancel,
|
|
33
|
+
children: cancelProps?.children || cancelLabel
|
|
34
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
35
|
+
...confirmProps,
|
|
36
|
+
onClick: handleConfirm,
|
|
37
|
+
children: confirmProps?.children || confirmLabel
|
|
38
|
+
})]
|
|
39
|
+
})] });
|
|
37
40
|
}
|
|
38
|
-
|
|
41
|
+
//#endregion
|
|
39
42
|
export { ConfirmModal };
|
|
40
|
-
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=ConfirmModal.mjs.map
|
package/esm/ConfirmModal.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmModal.mjs","sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import { Box, Button, ButtonProps, Group, GroupProps } from '@mantine/core';\nimport { ConfirmLabels } from './context';\nimport { useModals } from './use-modals/use-modals';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?: () => void;\n onConfirm?: () => void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps & React.ComponentProps<'button'> & Record<`data-${string}`, any>;\n confirmProps?: ButtonProps & React.ComponentProps<'button'> & Record<`data-${string}`, any>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels = { cancel: '', confirm: '' },\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const { cancel: cancelLabel, confirm: confirmLabel } = labels;\n const ctx = useModals();\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx.closeModal(id!);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx.closeModal(id!);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group mt={children ? 0 : 'md'} justify=\"flex-end\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || cancelLabel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || confirmLabel}\n </Button>\n </Group>\n </>\n );\n}\n"],"
|
|
1
|
+
{"version":3,"file":"ConfirmModal.mjs","names":[],"sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import { Box, Button, ButtonProps, Group, GroupProps } from '@mantine/core';\nimport { ConfirmLabels } from './context';\nimport { useModals } from './use-modals/use-modals';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?: () => void;\n onConfirm?: () => void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps & React.ComponentProps<'button'> & Record<`data-${string}`, any>;\n confirmProps?: ButtonProps & React.ComponentProps<'button'> & Record<`data-${string}`, any>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels = { cancel: '', confirm: '' },\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const { cancel: cancelLabel, confirm: confirmLabel } = labels;\n const ctx = useModals();\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx.closeModal(id!);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx.closeModal(id!);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group mt={children ? 0 : 'md'} justify=\"flex-end\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || cancelLabel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || confirmLabel}\n </Button>\n </Group>\n </>\n );\n}\n"],"mappings":";;;;;AAiBA,SAAgB,aAAa,EAC3B,IACA,aACA,cACA,SAAS;CAAE,QAAQ;CAAI,SAAS;CAAI,EACpC,iBAAiB,MACjB,gBAAgB,MAChB,YACA,UACA,WACA,YACoB;CACpB,MAAM,EAAE,QAAQ,aAAa,SAAS,iBAAiB;CACvD,MAAM,MAAM,WAAW;CAEvB,MAAM,gBAAgB,UAA+C;AACnE,SAAO,aAAa,YAAY,cAAc,aAAa,QAAQ,MAAM;AACzE,SAAO,aAAa,cAAc,UAAU;AAC5C,mBAAiB,IAAI,WAAW,GAAI;;CAGtC,MAAM,iBAAiB,UAA+C;AACpE,SAAO,cAAc,YAAY,cAAc,cAAc,QAAQ,MAAM;AAC3E,SAAO,cAAc,cAAc,WAAW;AAC9C,oBAAkB,IAAI,WAAW,GAAI;;AAGvC,QACE,qBAAA,UAAA,EAAA,UAAA,CACG,YAAY,oBAAC,KAAD;EAAK,IAAG;EAAM;EAAe,CAAA,EAE1C,qBAAC,OAAD;EAAO,IAAI,WAAW,IAAI;EAAM,SAAQ;EAAW,GAAI;YAAvD,CACE,oBAAC,QAAD;GAAQ,SAAQ;GAAU,GAAI;GAAa,SAAS;aACjD,aAAa,YAAY;GACnB,CAAA,EAET,oBAAC,QAAD;GAAQ,GAAI;GAAc,SAAS;aAChC,cAAc,YAAY;GACpB,CAAA,CACH;IACP,EAAA,CAAA"}
|