react-confirm-lite 1.2.5 → 1.4.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/README.md +567 -247
- package/dist/index.d.ts +42 -10
- package/dist/index.js +309 -129
- package/dist/index.js.map +1 -1
- package/package.json +13 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
3
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import React, { CSSProperties, ReactNode } from 'react';
|
|
4
3
|
|
|
5
4
|
type ColorSchema = 'light' | 'dark' | 'blue' | 'red' | 'green' | 'purple';
|
|
5
|
+
type AnimationType = 'slide' | 'fadeScale' | 'bounce' | 'flip' | 'zoom' | 'rotate' | 'fadeUp' | 'drop' | 'slideRight' | 'slideLeft' | 'fadeDown' | 'slideDown' | 'rotateRight' | 'zoomSmall' | 'bounceSmall' | 'fadeBlur' | 'fadeShrink';
|
|
6
6
|
type ConfirmClasses = {
|
|
7
7
|
overlay?: string;
|
|
8
8
|
wrapper?: string;
|
|
@@ -12,38 +12,70 @@ type ConfirmClasses = {
|
|
|
12
12
|
cancel?: string;
|
|
13
13
|
ok?: string;
|
|
14
14
|
};
|
|
15
|
-
type ConfirmInput =
|
|
15
|
+
type ConfirmInput = {
|
|
16
|
+
id?: string;
|
|
16
17
|
title?: string;
|
|
17
18
|
message: string;
|
|
18
19
|
colorSchema?: ColorSchema;
|
|
19
20
|
okText?: string;
|
|
20
21
|
cancelText?: string;
|
|
21
|
-
isDestructive?: boolean;
|
|
22
22
|
};
|
|
23
23
|
type ConfirmOptions = {
|
|
24
|
+
id: string;
|
|
24
25
|
title: string;
|
|
25
26
|
message: string;
|
|
26
|
-
resolve: (value: boolean) => void;
|
|
27
|
+
resolve: (value: boolean | null) => void;
|
|
27
28
|
colorSchema?: ColorSchema;
|
|
28
29
|
okText?: string;
|
|
29
30
|
cancelText?: string;
|
|
30
|
-
isDestructive?: boolean;
|
|
31
31
|
};
|
|
32
|
+
interface EnterExit {
|
|
33
|
+
enter: string;
|
|
34
|
+
exit: string;
|
|
35
|
+
}
|
|
36
|
+
interface animationPairs {
|
|
37
|
+
slide: EnterExit;
|
|
38
|
+
fadeScale: EnterExit;
|
|
39
|
+
bounce: EnterExit;
|
|
40
|
+
flip: EnterExit;
|
|
41
|
+
zoom: EnterExit;
|
|
42
|
+
rotate: EnterExit;
|
|
43
|
+
fadeUp: EnterExit;
|
|
44
|
+
drop: EnterExit;
|
|
45
|
+
slideRight: EnterExit;
|
|
46
|
+
slideLeft: EnterExit;
|
|
47
|
+
fadeDown: EnterExit;
|
|
48
|
+
slideVertical: EnterExit;
|
|
49
|
+
rotateRight: EnterExit;
|
|
50
|
+
zoomSmall: EnterExit;
|
|
51
|
+
bounceSmall: EnterExit;
|
|
52
|
+
fadeBlur: EnterExit;
|
|
53
|
+
fadeShrink: EnterExit;
|
|
54
|
+
}
|
|
32
55
|
|
|
33
56
|
type Props = {
|
|
34
57
|
classes?: ConfirmClasses;
|
|
35
|
-
animationDuration?: number;
|
|
36
58
|
defaultColorSchema?: ColorSchema;
|
|
59
|
+
closeOnEscape?: boolean;
|
|
60
|
+
closeOnClickOutside?: boolean;
|
|
61
|
+
animation?: AnimationType;
|
|
62
|
+
animationDuration?: number;
|
|
63
|
+
animationDurationIn?: number;
|
|
64
|
+
animationDurationOut?: number;
|
|
37
65
|
children?: (props: {
|
|
38
66
|
isVisible: boolean;
|
|
39
67
|
confirm: ConfirmOptions;
|
|
40
68
|
handleCancel: () => void;
|
|
41
69
|
handleOk: () => void;
|
|
70
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
42
71
|
colorSchema: ColorSchema;
|
|
72
|
+
animationClass: string;
|
|
73
|
+
animationStyle: CSSProperties;
|
|
43
74
|
}) => ReactNode;
|
|
75
|
+
id?: string;
|
|
44
76
|
};
|
|
45
|
-
declare const ConfirmContainer: ({ classes, animationDuration, defaultColorSchema,
|
|
77
|
+
declare const ConfirmContainer: ({ classes, animationDuration, defaultColorSchema, closeOnEscape, closeOnClickOutside, animation, animationDurationIn, animationDurationOut, children, id }: Props) => react_jsx_runtime.JSX.Element;
|
|
46
78
|
|
|
47
|
-
declare function confirm(input: ConfirmInput): Promise<boolean>;
|
|
79
|
+
declare function confirm(input: string | ConfirmInput): Promise<boolean | null>;
|
|
48
80
|
|
|
49
|
-
export { type ColorSchema, type ConfirmClasses, ConfirmContainer, type ConfirmInput, type ConfirmOptions, confirm };
|
|
81
|
+
export { type AnimationType, type ColorSchema, type ConfirmClasses, ConfirmContainer, type ConfirmInput, type ConfirmOptions, type animationPairs, confirm };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
// src/confirm_store.ts
|
|
6
|
+
var containerId = "";
|
|
6
7
|
var confirms = [];
|
|
7
8
|
var listeners = /* @__PURE__ */ new Set();
|
|
8
|
-
|
|
9
|
+
var isActiveContainer = false;
|
|
10
|
+
var containers = [];
|
|
11
|
+
var activeContainerId = null;
|
|
12
|
+
function setIsContainerActive(value) {
|
|
13
|
+
isActiveContainer = value;
|
|
14
|
+
}
|
|
15
|
+
function getIsContainerActive() {
|
|
16
|
+
return isActiveContainer;
|
|
17
|
+
}
|
|
18
|
+
function setActiveContainer(id) {
|
|
19
|
+
activeContainerId = id;
|
|
20
|
+
}
|
|
21
|
+
function getActiveContainerId() {
|
|
22
|
+
return activeContainerId;
|
|
23
|
+
}
|
|
24
|
+
async function addAlert(input) {
|
|
9
25
|
return new Promise((resolve) => {
|
|
10
|
-
const alert =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
resolve
|
|
14
|
-
} : {
|
|
26
|
+
const alert = {
|
|
27
|
+
id: input.id || "",
|
|
28
|
+
// Keep the ID for container targeting
|
|
15
29
|
title: input.title || "Confirm",
|
|
16
30
|
message: input.message,
|
|
17
31
|
okText: input.okText,
|
|
@@ -20,16 +34,25 @@ function addAlert(input) {
|
|
|
20
34
|
resolve
|
|
21
35
|
};
|
|
22
36
|
confirms = [...confirms, alert];
|
|
37
|
+
if (input.id) {
|
|
38
|
+
setActiveContainer(input.id);
|
|
39
|
+
} else {
|
|
40
|
+
setActiveContainer(null);
|
|
41
|
+
}
|
|
23
42
|
if (confirms.length === 1) {
|
|
24
43
|
emit();
|
|
25
44
|
}
|
|
26
45
|
});
|
|
27
46
|
}
|
|
28
|
-
function closeAlert(result) {
|
|
47
|
+
async function closeAlert(result) {
|
|
29
48
|
const alert = confirms[0];
|
|
49
|
+
containerId = "";
|
|
30
50
|
if (!alert) return;
|
|
31
51
|
alert.resolve(result);
|
|
32
52
|
confirms = confirms.slice(1);
|
|
53
|
+
if (confirms.length === 0) {
|
|
54
|
+
setActiveContainer(null);
|
|
55
|
+
}
|
|
33
56
|
emit();
|
|
34
57
|
}
|
|
35
58
|
function subscribe(listener) {
|
|
@@ -40,12 +63,46 @@ function subscribe(listener) {
|
|
|
40
63
|
function emit() {
|
|
41
64
|
listeners.forEach((listener) => listener(confirms));
|
|
42
65
|
}
|
|
66
|
+
var EventListener = (e) => {
|
|
67
|
+
if (containers.length === 0) {
|
|
68
|
+
containers.push(document.querySelectorAll(".null-confirm-container"));
|
|
69
|
+
}
|
|
70
|
+
if (containers.length === 0) return;
|
|
71
|
+
let parentElement = e.view?.document.activeElement?.parentElement;
|
|
72
|
+
let container = parentElement?.querySelector(".null-confirm-container");
|
|
73
|
+
while (true) {
|
|
74
|
+
if (container?.id) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
parentElement = parentElement?.parentElement;
|
|
78
|
+
container = parentElement?.querySelector(".null-confirm-container");
|
|
79
|
+
}
|
|
80
|
+
if (container?.id) {
|
|
81
|
+
containerId = container.id;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
async function getElement() {
|
|
85
|
+
document.addEventListener("click", EventListener, { once: true });
|
|
86
|
+
await new Promise((resolve) => {
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
document.removeEventListener("click", EventListener);
|
|
89
|
+
resolve();
|
|
90
|
+
}, 0);
|
|
91
|
+
});
|
|
92
|
+
if (containerId === "") {
|
|
93
|
+
if (containers.length === 0) {
|
|
94
|
+
containers.push(document.querySelectorAll(".null-confirm-container"));
|
|
95
|
+
}
|
|
96
|
+
return containers[0][0].id;
|
|
97
|
+
}
|
|
98
|
+
return containerId;
|
|
99
|
+
}
|
|
43
100
|
|
|
44
101
|
// src/confirm.css
|
|
45
|
-
var confirm_default = "/* confirm.css */\n.alert-overlay {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n z-index: 9999;\n display: flex;\n align-items: center;\n justify-content: center;\n backdrop-filter: blur(4px);\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n animation: overlayFadeIn 0.3s ease-out forwards;\n}\n\n.alert-overlay-exit {\n animation: overlayFadeOut 0.3s ease-in forwards;\n}\n\n.alert-wrapper {\n width: 90%;\n max-width: 400px;\n border-radius: 12px;\n padding: 24px;\n box-shadow: \n 0 20px 25px -5px rgba(0, 0, 0, 0.1),\n 0 10px 10px -5px rgba(0, 0, 0, 0.04),\n 0 0 0 1px rgba(0, 0, 0, 0.05);\n animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n
|
|
102
|
+
var confirm_default = "/* confirm.css */\n.alert-overlay {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n z-index: 9999;\n display: flex;\n align-items: center;\n justify-content: center;\n backdrop-filter: blur(4px);\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n animation: overlayFadeIn 0.3s ease-out forwards;\n}\n\n.alert-overlay-exit {\n animation: overlayFadeOut 0.3s ease-in forwards;\n}\n\n.alert-wrapper {\n width: 90%;\n max-width: 400px;\n border-radius: 12px;\n padding: 24px;\n box-shadow: \n 0 20px 25px -5px rgba(0, 0, 0, 0.1),\n 0 10px 10px -5px rgba(0, 0, 0, 0.04),\n 0 0 0 1px rgba(0, 0, 0, 0.05);\n animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n transform: translateY(20px) scale(0.98);\n}\n\n.alert-wrapper-exit {\n animation: modalSlideDown 0.3s ease-in forwards;\n}\n\n.alert-title {\n font-size: 18px;\n font-weight: 600;\n line-height: 1.4;\n margin: 0 0 12px 0;\n}\n\n.alert-message {\n font-size: 14px;\n line-height: 1.5;\n margin: 0 0 24px 0;\n}\n\n.alert-buttons {\n display: flex;\n justify-content: flex-end;\n gap: 12px;\n margin-top: 8px;\n}\n\n.alert-button {\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 14px;\n font-weight: 500;\n border: none;\n cursor: pointer;\n font-family: inherit;\n transition: all 0.2s ease;\n min-width: 80px;\n text-align: center;\n}\n\n.alert-button:focus {\n outline-offset: 2px;\n}\n\n.alert-button:active {\n transform: translateY(1px);\n}\n\n/* Default animations */\n.alert-wrapper-exit {\n animation: modalSlideDown 0.3s ease-in forwards;\n}\n\n/* Entrance Animation Classes */\n.alert-animate-fadeInScale {\n animation: fadeInScale 0.4s ease-out forwards;\n}\n\n.alert-animate-bounceIn {\n animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;\n}\n\n.alert-animate-flipIn {\n animation: flipIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;\n}\n\n.alert-animate-zoomIn {\n animation: zoomIn 0.3s ease-out forwards;\n}\n\n.alert-animate-rotateIn {\n animation: rotateIn 0.5s ease-out forwards;\n}\n\n.alert-animate-fadeInUp {\n animation: fadeInUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n}\n\n.alert-animate-dropIn {\n animation: dropIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;\n}\n\n.alert-animate-slideInRight {\n animation: slideInRight 0.4s ease-out forwards;\n}\n\n.alert-animate-slideInLeft {\n animation: slideInLeft 0.4s ease-out forwards;\n}\n\n.alert-animate-fadeInDown {\n animation: fadeInDown 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n}\n\n.alert-animate-slideDownIn {\n animation: slideDownIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n}\n\n.alert-animate-rotateInRight {\n animation: rotateInRight 0.5s ease-out forwards;\n}\n\n.alert-animate-zoomInSmall {\n animation: zoomInSmall 0.3s ease-out forwards;\n}\n\n.alert-animate-bounceInSmall {\n animation: bounceInSmall 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;\n}\n\n.alert-animate-fadeInBlur {\n animation: fadeInBlur 0.4s ease-out forwards;\n}\n\n.alert-animate-fadeInShrink {\n animation: fadeInShrink 0.3s ease-out forwards;\n}\n\n/* Exit Animation Classes */\n.alert-animate-fadeOutScale {\n animation: fadeOutScale 0.3s ease-in forwards;\n}\n\n.alert-animate-bounceOut {\n animation: bounceOut 0.4s ease-in forwards;\n}\n\n.alert-animate-zoomOut {\n animation: zoomOut 0.3s ease-in forwards;\n}\n\n.alert-animate-rotateOut {\n animation: rotateOut 0.3s ease-in forwards;\n}\n\n.alert-animate-fadeOutDown {\n animation: fadeOutDown 0.3s ease-in forwards;\n}\n\n.alert-animate-slideOutRight {\n animation: slideOutRight 0.3s ease-in forwards;\n}\n\n.alert-animate-slideOutLeft {\n animation: slideOutLeft 0.3s ease-in forwards;\n}\n\n.alert-animate-flipOut {\n animation: flipOut 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;\n}\n\n.alert-animate-dropOut {\n animation: dropOut 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;\n}\n\n.alert-animate-fadeOutUp {\n animation: fadeOutUp 0.3s ease-in forwards;\n}\n\n.alert-animate-slideUpOut {\n animation: slideUpOut 0.3s ease-in forwards;\n}\n\n.alert-animate-rotateOutLeft {\n animation: rotateOutLeft 0.3s ease-in forwards;\n}\n\n.alert-animate-zoomOutSmall {\n animation: zoomOutSmall 0.3s ease-in forwards;\n}\n\n.alert-animate-bounceOutSmall {\n animation: bounceOutSmall 0.4s ease-in forwards;\n}\n\n.alert-animate-fadeOutBlur {\n animation: fadeOutBlur 0.4s ease-in forwards;\n}\n\n.alert-animate-fadeOutShrink {\n animation: fadeOutShrink 0.3s ease-in forwards;\n}\n\n.alert-wrapper {\n width: 90%;\n max-width: 400px;\n border-radius: 12px;\n padding: 24px;\n box-shadow: \n 0 20px 25px -5px rgba(0, 0, 0, 0.1),\n 0 10px 10px -5px rgba(0, 0, 0, 0.04),\n 0 0 0 1px rgba(0, 0, 0, 0.05);\n}\n\n.null-confirm-container{\n width: 0;\n height: 0;\n opacity: 0;\n}";
|
|
46
103
|
|
|
47
104
|
// src/animations.css
|
|
48
|
-
var animations_default = "/* Animation Keyframes */\n@keyframes overlayFadeIn {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n\n@keyframes overlayFadeOut {\n from {\n opacity: 1;\n }\n to {\n opacity: 0;\n }\n}\n\n@keyframes modalSlideUp {\n from {\n opacity: 0;\n transform: translateY(20px) scale(0.98);\n }\n to {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n}\n\n@keyframes modalSlideDown {\n from {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n to {\n opacity: 0;\n transform: translateY(20px) scale(0.98);\n }\n}\n\n/* Accessibility: Reduce motion */\n@media (prefers-reduced-motion: reduce) {\n .alert-overlay,\n .alert-wrapper,\n .alert-button {\n animation-duration: 0.01ms;\n animation-iteration-count: 1;\n transition-duration: 0.01ms;\n }\n \n .alert-overlay {\n animation: none;\n opacity: 1;\n }\n \n .alert-wrapper {\n animation: none;\n opacity: 1;\n transform: none;\n }\n}";
|
|
105
|
+
var animations_default = "/* animations.css - Complete Animation Keyframes */\n\n/* Overlay Animations */\n@keyframes overlayFadeIn {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n\n@keyframes overlayFadeOut {\n from {\n opacity: 1;\n }\n to {\n opacity: 0;\n }\n}\n\n/* Default Modal Animations */\n@keyframes modalSlideUp {\n from {\n opacity: 0;\n transform: translateY(20px) scale(0.98);\n }\n to {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n}\n\n@keyframes modalSlideDown {\n from {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n to {\n opacity: 0;\n transform: translateY(20px) scale(0.98);\n }\n}\n\n/* Fade In/Out with Scale */\n@keyframes fadeInScale {\n from {\n opacity: 0;\n transform: scale(0.95);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n\n@keyframes fadeOutScale {\n from {\n opacity: 1;\n transform: scale(1);\n }\n to {\n opacity: 0;\n transform: scale(0.95);\n }\n}\n\n/* Slide In/Out from Right */\n@keyframes slideInRight {\n from {\n opacity: 0;\n transform: translateX(30px);\n }\n to {\n opacity: 1;\n transform: translateX(0);\n }\n}\n\n@keyframes slideOutRight {\n from {\n opacity: 1;\n transform: translateX(0);\n }\n to {\n opacity: 0;\n transform: translateX(30px);\n }\n}\n\n/* Slide In/Out from Left */\n@keyframes slideInLeft {\n from {\n opacity: 0;\n transform: translateX(-30px);\n }\n to {\n opacity: 1;\n transform: translateX(0);\n }\n}\n\n@keyframes slideOutLeft {\n from {\n opacity: 1;\n transform: translateX(0);\n }\n to {\n opacity: 0;\n transform: translateX(-30px);\n }\n}\n\n/* Bounce In/Out */\n@keyframes bounceIn {\n 0% {\n opacity: 0;\n transform: scale(0.3);\n }\n 50% {\n opacity: 1;\n transform: scale(1.05);\n }\n 70% {\n transform: scale(0.9);\n }\n 100% {\n transform: scale(1);\n }\n}\n\n@keyframes bounceOut {\n 20% {\n transform: scale(1.1);\n }\n 100% {\n opacity: 0;\n transform: scale(0.3);\n }\n}\n\n/* Small Bounce In/Out */\n@keyframes bounceInSmall {\n 0% {\n opacity: 0;\n transform: scale(0.8);\n }\n 50% {\n opacity: 1;\n transform: scale(1.05);\n }\n 70% {\n transform: scale(0.95);\n }\n 100% {\n transform: scale(1);\n }\n}\n\n@keyframes bounceOutSmall {\n 20% {\n transform: scale(1.05);\n }\n 100% {\n opacity: 0;\n transform: scale(0.8);\n }\n}\n\n/* Flip In/Out */\n@keyframes flipIn {\n 0% {\n opacity: 0;\n transform: perspective(400px) rotateY(90deg);\n }\n 100% {\n opacity: 1;\n transform: perspective(400px) rotateY(0deg);\n }\n}\n\n@keyframes flipOut {\n 0% {\n opacity: 1;\n transform: perspective(400px) rotateY(0deg);\n }\n 100% {\n opacity: 0;\n transform: perspective(400px) rotateY(90deg);\n }\n}\n\n/* Zoom In/Out */\n@keyframes zoomIn {\n from {\n opacity: 0;\n transform: scale(0.5);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n\n@keyframes zoomOut {\n from {\n opacity: 1;\n transform: scale(1);\n }\n to {\n opacity: 0;\n transform: scale(0.5);\n }\n}\n\n/* Small Zoom In/Out */\n@keyframes zoomInSmall {\n from {\n opacity: 0;\n transform: scale(0.8);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n\n@keyframes zoomOutSmall {\n from {\n opacity: 1;\n transform: scale(1);\n }\n to {\n opacity: 0;\n transform: scale(0.8);\n }\n}\n\n/* Rotate In/Out */\n@keyframes rotateIn {\n from {\n opacity: 0;\n transform: rotate(-15deg) scale(0.95);\n }\n to {\n opacity: 1;\n transform: rotate(0deg) scale(1);\n }\n}\n\n@keyframes rotateOut {\n from {\n opacity: 1;\n transform: rotate(0deg) scale(1);\n }\n to {\n opacity: 0;\n transform: rotate(15deg) scale(0.95);\n }\n}\n\n/* Rotate Right In/Left Out */\n@keyframes rotateInRight {\n from {\n opacity: 0;\n transform: rotate(15deg) scale(0.95);\n }\n to {\n opacity: 1;\n transform: rotate(0deg) scale(1);\n }\n}\n\n@keyframes rotateOutLeft {\n from {\n opacity: 1;\n transform: rotate(0deg) scale(1);\n }\n to {\n opacity: 0;\n transform: rotate(-15deg) scale(0.95);\n }\n}\n\n/* Fade Up In/Down Out */\n@keyframes fadeInUp {\n from {\n opacity: 0;\n transform: translateY(40px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@keyframes fadeOutDown {\n from {\n opacity: 1;\n transform: translateY(0);\n }\n to {\n opacity: 0;\n transform: translateY(40px);\n }\n}\n\n/* Fade Down In/Up Out */\n@keyframes fadeInDown {\n from {\n opacity: 0;\n transform: translateY(-40px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@keyframes fadeOutUp {\n from {\n opacity: 1;\n transform: translateY(0);\n }\n to {\n opacity: 0;\n transform: translateY(-40px);\n }\n}\n\n/* Drop In/Out (3D) */\n@keyframes dropIn {\n 0% {\n opacity: 0;\n transform: translateY(-100px) rotateX(90deg);\n }\n 70% {\n opacity: 1;\n transform: translateY(10px) rotateX(-10deg);\n }\n 100% {\n transform: translateY(0) rotateX(0deg);\n }\n}\n\n@keyframes dropOut {\n 0% {\n opacity: 1;\n transform: translateY(0) rotateX(0deg);\n }\n 30% {\n opacity: 1;\n transform: translateY(10px) rotateX(-10deg);\n }\n 100% {\n opacity: 0;\n transform: translateY(-100px) rotateX(90deg);\n }\n}\n\n/* Slide Up Out/Down In */\n@keyframes slideUpOut {\n from {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n to {\n opacity: 0;\n transform: translateY(-20px) scale(0.98);\n }\n}\n\n@keyframes slideDownIn {\n from {\n opacity: 0;\n transform: translateY(-20px) scale(0.98);\n }\n to {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n}\n\n/* Blur In/Out Effects */\n@keyframes fadeInBlur {\n from {\n opacity: 0;\n filter: blur(10px);\n }\n to {\n opacity: 1;\n filter: blur(0px);\n }\n}\n\n@keyframes fadeOutBlur {\n from {\n opacity: 1;\n filter: blur(0px);\n }\n to {\n opacity: 0;\n filter: blur(10px);\n }\n}\n\n/* Shrink In/Out Effects */\n@keyframes fadeInShrink {\n from {\n opacity: 0;\n transform: scale(1.2) translateY(20px);\n }\n to {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n}\n\n@keyframes fadeOutShrink {\n from {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n to {\n opacity: 0;\n transform: scale(0.8) translateY(20px);\n }\n}\n\n/* Background Blur Animations */\n@keyframes blurIn {\n from {\n backdrop-filter: blur(0px);\n }\n to {\n backdrop-filter: blur(4px);\n }\n}\n\n@keyframes blurOut {\n from {\n backdrop-filter: blur(4px);\n }\n to {\n backdrop-filter: blur(0px);\n }\n}\n\n/* Special Effects Animations */\n\n/* Shake Animation (for errors) */\n@keyframes shake {\n 0%, 100% {\n transform: translateX(0);\n }\n 10%, 30%, 50%, 70%, 90% {\n transform: translateX(-5px);\n }\n 20%, 40%, 60%, 80% {\n transform: translateX(5px);\n }\n}\n\n/* Pulse Animation (for emphasis) */\n@keyframes pulse {\n 0% {\n transform: scale(1);\n }\n 50% {\n transform: scale(1.05);\n }\n 100% {\n transform: scale(1);\n }\n}\n\n/* Button Hover Effects */\n@keyframes buttonHover {\n 0% {\n transform: translateY(0);\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n }\n 50% {\n transform: translateY(-2px);\n box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);\n }\n 100% {\n transform: translateY(-1px);\n box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);\n }\n}\n\n/* Accessibility: Reduce motion */\n@media (prefers-reduced-motion: reduce) {\n .alert-overlay,\n .alert-wrapper,\n .alert-button {\n animation-duration: 0.01ms;\n animation-iteration-count: 1;\n transition-duration: 0.01ms;\n }\n \n .alert-overlay {\n animation: none;\n opacity: 1;\n }\n \n .alert-wrapper {\n animation: none;\n opacity: 1;\n transform: none;\n }\n}";
|
|
49
106
|
|
|
50
107
|
// src/colorSchemas.css
|
|
51
108
|
var colorSchemas_default = "/* ========== LIGHT SCHEMA (Default) ========== */\n.schema-light-overlay {\n background-color: rgba(0, 0, 0, 0.5);\n}\n\n.schema-light-wrapper {\n background-color: #ffffff;\n color: #111827;\n}\n\n.schema-light-title {\n color: #111827;\n}\n\n.schema-light-message {\n color: #6b7280;\n}\n\n.schema-light-cancel {\n background-color: #f3f4f6;\n color: #374151;\n outline-color: #9ca3af;\n}\n\n.schema-light-cancel:hover {\n background-color: #e5e7eb;\n transform: translateY(-1px);\n}\n\n.schema-light-cancel:active {\n background-color: #d1d5db;\n}\n\n.schema-light-cancel-danger {\n background-color: #fee2e2;\n color: #991b1b;\n outline-color: #f87171;\n}\n\n.schema-light-cancel-danger:hover {\n background-color: #fecaca;\n}\n\n.schema-light-ok {\n background-color: #10b981;\n color: #ffffff;\n outline-color: #34d399;\n}\n\n.schema-light-ok:hover {\n background-color: #059669;\n transform: translateY(-1px);\n}\n\n.schema-light-ok:active {\n background-color: #047857;\n}\n\n.schema-light-ok-danger {\n background-color: #ef4444;\n color: #ffffff;\n outline-color: #f87171;\n}\n\n.schema-light-ok-danger:hover {\n background-color: #dc2626;\n}\n\n/* ========== DARK SCHEMA ========== */\n.schema-dark-overlay {\n background-color: rgba(0, 0, 0, 0.7);\n}\n\n.schema-dark-wrapper {\n background-color: #18181b;\n color: #f4f4f5;\n box-shadow: \n 0 20px 25px -5px rgba(0, 0, 0, 0.3),\n 0 10px 10px -5px rgba(0, 0, 0, 0.2),\n 0 0 0 1px rgba(255, 255, 255, 0.1);\n}\n\n.schema-dark-title {\n color: #f4f4f5;\n}\n\n.schema-dark-message {\n color: #a1a1aa;\n}\n\n.schema-dark-cancel {\n background-color: #27272a;\n color: #e4e4e7;\n outline-color: #71717a;\n}\n\n.schema-dark-cancel:hover {\n background-color: #3f3f46;\n transform: translateY(-1px);\n}\n\n.schema-dark-cancel:active {\n background-color: #52525b;\n}\n\n.schema-dark-cancel-danger {\n background-color: #7f1d1d;\n color: #fecaca;\n outline-color: #ef4444;\n}\n\n.schema-dark-cancel-danger:hover {\n background-color: #991b1b;\n}\n\n.schema-dark-ok {\n background-color: #10b981;\n color: #ffffff;\n outline-color: #34d399;\n}\n\n.schema-dark-ok:hover {\n background-color: #059669;\n transform: translateY(-1px);\n}\n\n.schema-dark-ok:active {\n background-color: #047857;\n}\n\n.schema-dark-ok-danger {\n background-color: #dc2626;\n color: #ffffff;\n outline-color: #ef4444;\n}\n\n.schema-dark-ok-danger:hover {\n background-color: #b91c1c;\n}\n\n/* ========== BLUE SCHEMA ========== */\n.schema-blue-overlay {\n background-color: rgba(59, 130, 246, 0.3);\n}\n\n.schema-blue-wrapper {\n background-color: #eff6ff;\n color: #1e3a8a;\n box-shadow: \n 0 20px 25px -5px rgba(59, 130, 246, 0.15),\n 0 10px 10px -5px rgba(59, 130, 246, 0.1),\n 0 0 0 1px rgba(59, 130, 246, 0.1);\n}\n\n.schema-blue-title {\n color: #1e3a8a;\n}\n\n.schema-blue-message {\n color: #3b82f6;\n}\n\n.schema-blue-cancel {\n background-color: #dbeafe;\n color: #1e40af;\n outline-color: #60a5fa;\n}\n\n.schema-blue-cancel:hover {\n background-color: #bfdbfe;\n transform: translateY(-1px);\n}\n\n.schema-blue-cancel:active {\n background-color: #93c5fd;\n}\n\n.schema-blue-cancel-danger {\n background-color: #fee2e2;\n color: #991b1b;\n outline-color: #f87171;\n}\n\n.schema-blue-ok {\n background-color: #3b82f6;\n color: #ffffff;\n outline-color: #60a5fa;\n}\n\n.schema-blue-ok:hover {\n background-color: #2563eb;\n transform: translateY(-1px);\n}\n\n.schema-blue-ok:active {\n background-color: #1d4ed8;\n}\n\n.schema-blue-ok-danger {\n background-color: #ef4444;\n color: #ffffff;\n outline-color: #f87171;\n}\n\n/* ========== RED SCHEMA ========== */\n.schema-red-overlay {\n background-color: rgba(220, 38, 38, 0.2);\n}\n\n.schema-red-wrapper {\n background-color: #fef2f2;\n color: #7f1d1d;\n box-shadow: \n 0 20px 25px -5px rgba(220, 38, 38, 0.15),\n 0 10px 10px -5px rgba(220, 38, 38, 0.1),\n 0 0 0 1px rgba(220, 38, 38, 0.1);\n}\n\n.schema-red-title {\n color: #7f1d1d;\n}\n\n.schema-red-message {\n color: #ef4444;\n}\n\n.schema-red-cancel {\n background-color: #fecaca;\n color: #991b1b;\n outline-color: #f87171;\n}\n\n.schema-red-cancel:hover {\n background-color: #fca5a5;\n transform: translateY(-1px);\n}\n\n.schema-red-cancel:active {\n background-color: #f87171;\n}\n\n.schema-red-ok {\n background-color: #dc2626;\n color: #ffffff;\n outline-color: #ef4444;\n}\n\n.schema-red-ok:hover {\n background-color: #b91c1c;\n transform: translateY(-1px);\n}\n\n.schema-red-ok:active {\n background-color: #991b1b;\n}\n\n.schema-red-ok-danger {\n background-color: #991b1b;\n color: #ffffff;\n outline-color: #dc2626;\n}\n\n/* ========== GREEN SCHEMA ========== */\n.schema-green-overlay {\n background-color: rgba(16, 185, 129, 0.2);\n}\n\n.schema-green-wrapper {\n background-color: #ecfdf5;\n color: #064e3b;\n box-shadow: \n 0 20px 25px -5px rgba(16, 185, 129, 0.15),\n 0 10px 10px -5px rgba(16, 185, 129, 0.1),\n 0 0 0 1px rgba(16, 185, 129, 0.1);\n}\n\n.schema-green-title {\n color: #064e3b;\n}\n\n.schema-green-message {\n color: #10b981;\n}\n\n.schema-green-cancel {\n background-color: #d1fae5;\n color: #047857;\n outline-color: #34d399;\n}\n\n.schema-green-cancel:hover {\n background-color: #a7f3d0;\n transform: translateY(-1px);\n}\n\n.schema-green-cancel:active {\n background-color: #6ee7b7;\n}\n\n.schema-green-cancel-danger {\n background-color: #fee2e2;\n color: #991b1b;\n outline-color: #f87171;\n}\n\n.schema-green-ok {\n background-color: #10b981;\n color: #ffffff;\n outline-color: #34d399;\n}\n\n.schema-green-ok:hover {\n background-color: #059669;\n transform: translateY(-1px);\n}\n\n.schema-green-ok:active {\n background-color: #047857;\n}\n\n.schema-green-ok-danger {\n background-color: #ef4444;\n color: #ffffff;\n outline-color: #f87171;\n}\n\n/* ========== PURPLE SCHEMA ========== */\n.schema-purple-overlay {\n background-color: rgba(139, 92, 246, 0.2);\n}\n\n.schema-purple-wrapper {\n background-color: #f5f3ff;\n color: #5b21b6;\n box-shadow: \n 0 20px 25px -5px rgba(139, 92, 246, 0.15),\n 0 10px 10px -5px rgba(139, 92, 246, 0.1),\n 0 0 0 1px rgba(139, 92, 246, 0.1);\n}\n\n.schema-purple-title {\n color: #5b21b6;\n}\n\n.schema-purple-message {\n color: #8b5cf6;\n}\n\n.schema-purple-cancel {\n background-color: #ede9fe;\n color: #6d28d9;\n outline-color: #a78bfa;\n}\n\n.schema-purple-cancel:hover {\n background-color: #ddd6fe;\n transform: translateY(-1px);\n}\n\n.schema-purple-cancel:active {\n background-color: #c4b5fd;\n}\n\n.schema-purple-cancel-danger {\n background-color: #fee2e2;\n color: #991b1b;\n outline-color: #f87171;\n}\n\n.schema-purple-ok {\n background-color: #8b5cf6;\n color: #ffffff;\n outline-color: #a78bfa;\n}\n\n.schema-purple-ok:hover {\n background-color: #7c3aed;\n transform: translateY(-1px);\n}\n\n.schema-purple-ok:active {\n background-color: #6d28d9;\n}\n\n.schema-purple-ok-danger {\n background-color: #ef4444;\n color: #ffffff;\n outline-color: #f87171;\n}\n";
|
|
@@ -67,22 +124,51 @@ function ensureStyles() {
|
|
|
67
124
|
style.textContent = ALL_CSS;
|
|
68
125
|
document.head.appendChild(style);
|
|
69
126
|
stylesInjected = true;
|
|
70
|
-
console.log("React Confirm Lite: Styles injected");
|
|
71
127
|
}
|
|
72
128
|
function cx(...classes) {
|
|
73
129
|
return classes.filter(Boolean).join(" ");
|
|
74
130
|
}
|
|
131
|
+
var animationPairs = {
|
|
132
|
+
slide: { enter: "", exit: "alert-wrapper-exit" },
|
|
133
|
+
fadeScale: { enter: "alert-animate-fadeInScale", exit: "alert-animate-fadeOutScale" },
|
|
134
|
+
bounce: { enter: "alert-animate-bounceIn", exit: "alert-animate-bounceOut" },
|
|
135
|
+
flip: { enter: "alert-animate-flipIn", exit: "alert-animate-flipOut" },
|
|
136
|
+
zoom: { enter: "alert-animate-zoomIn", exit: "alert-animate-zoomOut" },
|
|
137
|
+
rotate: { enter: "alert-animate-rotateIn", exit: "alert-animate-rotateOut" },
|
|
138
|
+
fadeUp: { enter: "alert-animate-fadeInUp", exit: "alert-animate-fadeOutDown" },
|
|
139
|
+
drop: { enter: "alert-animate-dropIn", exit: "alert-animate-dropOut" },
|
|
140
|
+
slideRight: { enter: "alert-animate-slideInRight", exit: "alert-animate-slideOutLeft" },
|
|
141
|
+
slideLeft: { enter: "alert-animate-slideInLeft", exit: "alert-animate-slideOutRight" },
|
|
142
|
+
fadeDown: { enter: "alert-animate-fadeInDown", exit: "alert-animate-fadeOutUp" },
|
|
143
|
+
slideVertical: { enter: "alert-animate-slideDownIn", exit: "alert-animate-slideUpOut" },
|
|
144
|
+
rotateRight: { enter: "alert-animate-rotateInRight", exit: "alert-animate-rotateOutLeft" },
|
|
145
|
+
zoomSmall: { enter: "alert-animate-zoomInSmall", exit: "alert-animate-zoomOutSmall" },
|
|
146
|
+
bounceSmall: { enter: "alert-animate-bounceInSmall", exit: "alert-animate-bounceOutSmall" },
|
|
147
|
+
fadeBlur: { enter: "alert-animate-fadeInBlur", exit: "alert-animate-fadeOutBlur" },
|
|
148
|
+
fadeShrink: { enter: "alert-animate-fadeInShrink", exit: "alert-animate-fadeOutShrink" }
|
|
149
|
+
};
|
|
75
150
|
var ConfirmContainer = ({
|
|
76
151
|
classes = {},
|
|
77
152
|
animationDuration = 300,
|
|
78
153
|
defaultColorSchema = "dark",
|
|
79
|
-
|
|
154
|
+
closeOnEscape = true,
|
|
155
|
+
closeOnClickOutside = true,
|
|
156
|
+
animation = "slide",
|
|
157
|
+
animationDurationIn,
|
|
158
|
+
animationDurationOut,
|
|
159
|
+
children,
|
|
160
|
+
id
|
|
80
161
|
}) => {
|
|
81
162
|
const [alerts, setAlerts] = useState([]);
|
|
82
163
|
const [isVisible, setIsVisible] = useState(false);
|
|
83
164
|
const [currentAlert, setCurrentAlert] = useState(null);
|
|
84
|
-
const [
|
|
165
|
+
const [isExiting, setIsExiting] = useState(false);
|
|
166
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
85
167
|
const overlayRef = useRef(null);
|
|
168
|
+
const wrapperRef = useRef(null);
|
|
169
|
+
const exitTimerRef = useRef(null);
|
|
170
|
+
const containerId2 = useRef(id || `confirm-${Date.now().toString()}`);
|
|
171
|
+
const nullElement = /* @__PURE__ */ jsx("div", { id: containerId2.current, className: "null-confirm-container" });
|
|
86
172
|
useEffect(() => {
|
|
87
173
|
subscribe((newAlerts) => {
|
|
88
174
|
setAlerts(newAlerts);
|
|
@@ -92,135 +178,229 @@ var ConfirmContainer = ({
|
|
|
92
178
|
ensureStyles();
|
|
93
179
|
}, []);
|
|
94
180
|
useEffect(() => {
|
|
95
|
-
if (alerts.length > 0 && !currentAlert) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
181
|
+
if (alerts.length > 0 && !currentAlert && !isExiting) {
|
|
182
|
+
const nextAlert = alerts[0];
|
|
183
|
+
const shouldShowAlert = (
|
|
184
|
+
// Case 1: Alert has no ID (can be shown by any container)
|
|
185
|
+
!nextAlert.id || // Case 2: Alert has an ID that matches our container ID
|
|
186
|
+
nextAlert.id === containerId2.current || // Case 3: No container is currently active
|
|
187
|
+
!getActiveContainerId()
|
|
188
|
+
);
|
|
189
|
+
if (shouldShowAlert) {
|
|
190
|
+
const currentActive = getActiveContainerId();
|
|
191
|
+
if (!currentActive || currentActive === containerId2.current) {
|
|
192
|
+
setActiveContainer(containerId2.current);
|
|
193
|
+
setIsContainerActive(true);
|
|
194
|
+
setIsMounted(true);
|
|
195
|
+
setCurrentAlert(nextAlert);
|
|
196
|
+
setIsVisible(true);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} else if (alerts.length === 0 && currentAlert && isVisible) {
|
|
200
|
+
console.log("Starting exit animation");
|
|
201
|
+
setIsExiting(true);
|
|
202
|
+
setIsVisible(false);
|
|
203
|
+
if (exitTimerRef.current) {
|
|
204
|
+
clearTimeout(exitTimerRef.current);
|
|
205
|
+
}
|
|
206
|
+
const exitDuration = animationDurationOut || animationDuration;
|
|
207
|
+
exitTimerRef.current = setTimeout(() => {
|
|
208
|
+
console.log("Exit animation complete");
|
|
209
|
+
setIsContainerActive(false);
|
|
210
|
+
setIsExiting(false);
|
|
211
|
+
setCurrentAlert(null);
|
|
212
|
+
setIsMounted(false);
|
|
213
|
+
}, exitDuration);
|
|
214
|
+
} else if (alerts.length > 0 && currentAlert && alerts[0].id !== currentAlert.id) {
|
|
215
|
+
console.log("Replacing with new alert");
|
|
216
|
+
setIsExiting(true);
|
|
217
|
+
setIsVisible(false);
|
|
218
|
+
if (exitTimerRef.current) {
|
|
219
|
+
clearTimeout(exitTimerRef.current);
|
|
220
|
+
}
|
|
221
|
+
const exitDuration = animationDurationOut || animationDuration;
|
|
222
|
+
exitTimerRef.current = setTimeout(() => {
|
|
223
|
+
setIsContainerActive(false);
|
|
224
|
+
setIsExiting(false);
|
|
109
225
|
setCurrentAlert(null);
|
|
110
|
-
|
|
226
|
+
setIsMounted(false);
|
|
227
|
+
}, exitDuration);
|
|
111
228
|
}
|
|
112
|
-
}, [alerts, animationDuration]);
|
|
229
|
+
}, [alerts, currentAlert, animationDuration, animationDurationOut, isVisible]);
|
|
230
|
+
const handleClose = useCallback(async (value) => {
|
|
231
|
+
if (!currentAlert || isExiting) return;
|
|
232
|
+
setIsExiting(true);
|
|
233
|
+
setIsVisible(false);
|
|
234
|
+
const exitDuration = animationDurationOut || animationDuration;
|
|
235
|
+
if (exitTimerRef.current) {
|
|
236
|
+
clearTimeout(exitTimerRef.current);
|
|
237
|
+
}
|
|
238
|
+
exitTimerRef.current = setTimeout(() => {
|
|
239
|
+
closeAlert(value);
|
|
240
|
+
setIsExiting(false);
|
|
241
|
+
setCurrentAlert(null);
|
|
242
|
+
setIsMounted(false);
|
|
243
|
+
setIsContainerActive(false);
|
|
244
|
+
}, exitDuration);
|
|
245
|
+
}, [currentAlert, isExiting, animationDuration, animationDurationOut]);
|
|
246
|
+
const handleCancel = useCallback(() => {
|
|
247
|
+
if (currentAlert && isVisible && !isExiting) {
|
|
248
|
+
handleClose(false);
|
|
249
|
+
}
|
|
250
|
+
}, [currentAlert, isVisible, isExiting, handleClose]);
|
|
251
|
+
const handleOk = useCallback(() => {
|
|
252
|
+
if (currentAlert && isVisible && !isExiting) {
|
|
253
|
+
handleClose(true);
|
|
254
|
+
}
|
|
255
|
+
}, [currentAlert, isVisible, isExiting, handleClose]);
|
|
256
|
+
const handleEscKey = useCallback((event) => {
|
|
257
|
+
if (event.key === "Escape" && closeOnEscape && currentAlert && isVisible && !isExiting) {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
event.stopPropagation();
|
|
260
|
+
handleClose(null);
|
|
261
|
+
}
|
|
262
|
+
}, [closeOnEscape, currentAlert, isVisible, isExiting, handleClose]);
|
|
113
263
|
useEffect(() => {
|
|
114
|
-
if (currentAlert) {
|
|
115
|
-
|
|
116
|
-
} else if (!currentAlert) {
|
|
117
|
-
setisAnimating(false);
|
|
264
|
+
if (currentAlert && isVisible && !isExiting) {
|
|
265
|
+
window.addEventListener("keydown", handleEscKey, { capture: true });
|
|
118
266
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
267
|
+
return () => {
|
|
268
|
+
window.removeEventListener("keydown", handleEscKey, { capture: true });
|
|
269
|
+
};
|
|
270
|
+
}, [handleEscKey, currentAlert, isVisible, isExiting]);
|
|
271
|
+
useEffect(() => {
|
|
272
|
+
const handleClickOutside = (event) => {
|
|
273
|
+
if (wrapperRef.current && !wrapperRef.current.contains(event.target) && closeOnClickOutside && currentAlert && isVisible && !isExiting) {
|
|
274
|
+
handleClose(null);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
if (currentAlert && isVisible && !isExiting) {
|
|
278
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
125
279
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}, []);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!currentAlert && !isVisible) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
if (!currentAlert) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
if (currentAlert && !isAnimating) {
|
|
139
|
-
return null;
|
|
280
|
+
return () => {
|
|
281
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
282
|
+
};
|
|
283
|
+
}, [closeOnClickOutside, currentAlert, isVisible, isExiting, handleClose]);
|
|
284
|
+
if (!isMounted && !isExiting) {
|
|
285
|
+
return nullElement;
|
|
140
286
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return children({
|
|
144
|
-
isVisible,
|
|
145
|
-
confirm: currentAlert,
|
|
146
|
-
handleCancel,
|
|
147
|
-
handleOk,
|
|
148
|
-
colorSchema
|
|
149
|
-
});
|
|
287
|
+
if (!currentAlert || !getIsContainerActive()) {
|
|
288
|
+
return nullElement;
|
|
150
289
|
}
|
|
290
|
+
const colorSchema = currentAlert?.colorSchema || defaultColorSchema;
|
|
151
291
|
const schemaClass = `schema-${colorSchema}`;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
292
|
+
const animationStyle = {};
|
|
293
|
+
const currentDuration = isVisible ? animationDurationIn || animationDuration : animationDurationOut || animationDuration;
|
|
294
|
+
animationStyle.animationDuration = `${currentDuration}ms`;
|
|
295
|
+
animationStyle.animationFillMode = "forwards";
|
|
296
|
+
const animationClass = isVisible ? animationPairs[animation].enter : animationPairs[animation].exit;
|
|
297
|
+
if (children && currentAlert && getActiveContainerId() === containerId2.current) {
|
|
298
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
299
|
+
nullElement,
|
|
300
|
+
children({
|
|
301
|
+
isVisible: isVisible && !isExiting,
|
|
302
|
+
confirm: currentAlert,
|
|
303
|
+
handleCancel,
|
|
304
|
+
handleOk,
|
|
305
|
+
containerRef: wrapperRef,
|
|
306
|
+
colorSchema,
|
|
307
|
+
animationClass,
|
|
308
|
+
animationStyle
|
|
309
|
+
})
|
|
310
|
+
] });
|
|
311
|
+
}
|
|
312
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
313
|
+
nullElement,
|
|
314
|
+
/* @__PURE__ */ jsx(
|
|
315
|
+
"div",
|
|
316
|
+
{
|
|
317
|
+
ref: overlayRef,
|
|
318
|
+
className: cx(
|
|
319
|
+
"alert-overlay",
|
|
320
|
+
!isVisible ? "alert-overlay-exit" : "",
|
|
321
|
+
`${schemaClass}-overlay`,
|
|
322
|
+
classes.overlay
|
|
323
|
+
),
|
|
324
|
+
style: animationStyle,
|
|
325
|
+
children: /* @__PURE__ */ jsxs(
|
|
326
|
+
"div",
|
|
327
|
+
{
|
|
328
|
+
ref: wrapperRef,
|
|
329
|
+
className: cx(
|
|
330
|
+
"alert-wrapper",
|
|
331
|
+
animationClass,
|
|
332
|
+
`${schemaClass}-wrapper`,
|
|
333
|
+
classes.wrapper
|
|
334
|
+
),
|
|
335
|
+
style: animationStyle,
|
|
336
|
+
children: [
|
|
337
|
+
/* @__PURE__ */ jsx("h2", { className: cx(
|
|
338
|
+
"alert-title",
|
|
339
|
+
`${schemaClass}-title`,
|
|
340
|
+
classes.title
|
|
341
|
+
), children: currentAlert.title }),
|
|
342
|
+
/* @__PURE__ */ jsx("p", { className: cx(
|
|
343
|
+
"alert-message",
|
|
344
|
+
`${schemaClass}-message`,
|
|
345
|
+
classes.message
|
|
346
|
+
), children: currentAlert.message }),
|
|
347
|
+
/* @__PURE__ */ jsxs("div", { className: "alert-buttons", children: [
|
|
348
|
+
/* @__PURE__ */ jsx(
|
|
349
|
+
"button",
|
|
350
|
+
{
|
|
351
|
+
onClick: handleCancel,
|
|
352
|
+
disabled: isExiting || !isVisible,
|
|
353
|
+
className: cx(
|
|
354
|
+
"alert-button alert-button-cancel",
|
|
355
|
+
`${schemaClass}-cancel`,
|
|
356
|
+
classes.button,
|
|
357
|
+
classes.cancel
|
|
358
|
+
),
|
|
359
|
+
children: currentAlert.cancelText || "Cancel"
|
|
360
|
+
}
|
|
361
|
+
),
|
|
362
|
+
/* @__PURE__ */ jsx(
|
|
363
|
+
"button",
|
|
364
|
+
{
|
|
365
|
+
onClick: handleOk,
|
|
366
|
+
disabled: isExiting || !isVisible,
|
|
367
|
+
className: cx(
|
|
368
|
+
"alert-button alert-button-ok",
|
|
369
|
+
`${schemaClass}-ok`,
|
|
370
|
+
classes.button,
|
|
371
|
+
classes.ok
|
|
372
|
+
),
|
|
373
|
+
children: currentAlert.okText || "OK"
|
|
374
|
+
}
|
|
375
|
+
)
|
|
376
|
+
] })
|
|
377
|
+
]
|
|
378
|
+
}
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
)
|
|
382
|
+
] });
|
|
219
383
|
};
|
|
220
384
|
var confirmContainer_default = ConfirmContainer;
|
|
221
385
|
|
|
222
386
|
// src/confirm.ts
|
|
223
387
|
async function confirm(input) {
|
|
388
|
+
if (typeof input === "string") {
|
|
389
|
+
const containerId2 = await getElement();
|
|
390
|
+
const result2 = await addAlert({
|
|
391
|
+
message: input,
|
|
392
|
+
id: containerId2
|
|
393
|
+
});
|
|
394
|
+
return result2;
|
|
395
|
+
}
|
|
396
|
+
if (!input.id) {
|
|
397
|
+
const containerId2 = await getElement();
|
|
398
|
+
const result2 = await addAlert({
|
|
399
|
+
...input,
|
|
400
|
+
id: containerId2
|
|
401
|
+
});
|
|
402
|
+
return result2;
|
|
403
|
+
}
|
|
224
404
|
const result = await addAlert(input);
|
|
225
405
|
return result;
|
|
226
406
|
}
|