@inf-monkeys-tech/monkeys-design 0.4.34 → 0.4.35
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/LICENSE +21 -21
- package/README.md +226 -226
- package/dist/components/base/index.d.mts +2 -2
- package/dist/components/base/index.d.ts +2 -2
- package/dist/components/base/index.js +2 -445
- package/dist/components/base/index.js.map +1 -1
- package/dist/components/base/index.mjs +3 -445
- package/dist/components/base/index.mjs.map +1 -1
- package/dist/components/data-explorer/index.js.map +1 -1
- package/dist/components/data-explorer/index.mjs.map +1 -1
- package/dist/components/layout/index.js.map +1 -1
- package/dist/components/layout/index.mjs.map +1 -1
- package/dist/components/login/index.js.map +1 -1
- package/dist/components/login/index.mjs.map +1 -1
- package/dist/components/toast/index.d.mts +75 -0
- package/dist/components/toast/index.d.ts +75 -0
- package/dist/components/toast/index.js +283 -0
- package/dist/components/toast/index.js.map +1 -0
- package/dist/components/toast/index.mjs +273 -0
- package/dist/components/toast/index.mjs.map +1 -0
- package/dist/components/toolbar/index.js.map +1 -1
- package/dist/components/toolbar/index.mjs.map +1 -1
- package/dist/components/workbench/index.d.mts +1 -1
- package/dist/components/workbench/index.d.ts +1 -1
- package/dist/components/workbench/index.js +2 -444
- package/dist/components/workbench/index.js.map +1 -1
- package/dist/components/workbench/index.mjs +2 -444
- package/dist/components/workbench/index.mjs.map +1 -1
- package/dist/icons/oauth/index.js.map +1 -1
- package/dist/icons/oauth/index.mjs.map +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +286 -455
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +278 -455
- package/dist/index.mjs.map +1 -1
- package/dist/palette/index.js.map +1 -1
- package/dist/palette/index.mjs.map +1 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/index.mjs.map +1 -1
- package/dist/styles/artist-login.scss +374 -374
- package/dist/styles/global.scss +21 -21
- package/dist/styles/workflow-board.scss +440 -440
- package/dist/styles/workflow-nodes.css +340 -340
- package/dist/{theme-sIoU5-YC.d.ts → theme-CoG9vCPT.d.mts} +2 -4
- package/dist/{theme-Clm5dVb0.d.mts → theme-Cuy60thu.d.ts} +2 -4
- package/dist/theme-system/index.d.mts +1 -1
- package/dist/theme-system/index.d.ts +1 -1
- package/dist/theme-system/index.js +2 -444
- package/dist/theme-system/index.js.map +1 -1
- package/dist/theme-system/index.mjs +2 -444
- package/dist/theme-system/index.mjs.map +1 -1
- package/dist/themes/artist/index.js.map +1 -1
- package/dist/themes/artist/index.mjs.map +1 -1
- package/dist/themes/bsd/index.js.map +1 -1
- package/dist/themes/bsd/index.mjs.map +1 -1
- package/dist/themes/concept/index.js.map +1 -1
- package/dist/themes/concept/index.mjs.map +1 -1
- package/dist/themes/default/index.js.map +1 -1
- package/dist/themes/default/index.mjs.map +1 -1
- package/dist/{types-Bn6PEDsX.d.mts → types-CZALgtez.d.mts} +1 -43
- package/dist/{types-Bn6PEDsX.d.ts → types-CZALgtez.d.ts} +1 -43
- package/package.json +146 -139
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, ReactElement } from 'react';
|
|
3
|
+
import { ToasterProps, ExternalToast, ToastT, ToastToDismiss } from 'sonner';
|
|
4
|
+
export { ExternalToast, ToasterProps } from 'sonner';
|
|
5
|
+
|
|
6
|
+
type ToastVariant = 'error' | 'warning' | 'success' | 'info';
|
|
7
|
+
type ToastInput = Omit<ExternalToast, 'description'> & {
|
|
8
|
+
title?: ReactNode;
|
|
9
|
+
description?: ReactNode;
|
|
10
|
+
variant?: ToastVariant;
|
|
11
|
+
};
|
|
12
|
+
type MonkeysToasterProps = ToasterProps & {
|
|
13
|
+
useThemeClassNames?: boolean;
|
|
14
|
+
};
|
|
15
|
+
type MonkeysToastProviderProps = {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
toasterProps?: MonkeysToasterProps;
|
|
18
|
+
};
|
|
19
|
+
type ToastValue = Error | string | {
|
|
20
|
+
message?: unknown;
|
|
21
|
+
title?: unknown;
|
|
22
|
+
} | null | undefined;
|
|
23
|
+
type ToastResolver<T> = T | ((value: ToastValue) => T);
|
|
24
|
+
type ToastTranslate = (value: string, params?: Record<string, unknown>) => string;
|
|
25
|
+
type ToastValueOptions = {
|
|
26
|
+
variant?: ToastResolver<ToastVariant | undefined>;
|
|
27
|
+
title?: ToastResolver<string | undefined>;
|
|
28
|
+
description?: ToastResolver<string | undefined>;
|
|
29
|
+
fallbackDescription?: ToastResolver<string | undefined>;
|
|
30
|
+
signature?: ToastResolver<string | undefined>;
|
|
31
|
+
duration?: ToastResolver<number | undefined>;
|
|
32
|
+
translate?: ToastTranslate;
|
|
33
|
+
messages?: Partial<ToastDefaultMessages>;
|
|
34
|
+
};
|
|
35
|
+
type ToastFeedEntry = {
|
|
36
|
+
variant?: ToastVariant;
|
|
37
|
+
title?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
duration?: number;
|
|
40
|
+
signature?: string;
|
|
41
|
+
} | null | undefined;
|
|
42
|
+
type ToastDefaultMessages = {
|
|
43
|
+
errorTitle: string;
|
|
44
|
+
warningTitle: string;
|
|
45
|
+
defaultErrorDescription: string;
|
|
46
|
+
defaultWarningDescription: string;
|
|
47
|
+
};
|
|
48
|
+
type ToastPromiseInput<T = unknown> = Promise<T> | (() => Promise<T>);
|
|
49
|
+
type ToastPromiseReturn<T = unknown> = string | number | {
|
|
50
|
+
unwrap: () => Promise<T>;
|
|
51
|
+
};
|
|
52
|
+
type MonkeysToastApi = {
|
|
53
|
+
(message: ReactNode, options?: ExternalToast): string | number;
|
|
54
|
+
show: (input: ToastInput) => string | number | undefined;
|
|
55
|
+
error: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;
|
|
56
|
+
warning: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;
|
|
57
|
+
success: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;
|
|
58
|
+
info: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;
|
|
59
|
+
message: (message: ReactNode, options?: ExternalToast) => string | number;
|
|
60
|
+
promise: <T = unknown>(promise: ToastPromiseInput<T>, data?: unknown) => ToastPromiseReturn<T>;
|
|
61
|
+
dismiss: (id?: number | string) => string | number;
|
|
62
|
+
loading: (message: ReactNode, options?: ExternalToast) => string | number;
|
|
63
|
+
custom: (jsx: (id: number | string) => ReactElement, data?: ExternalToast) => string | number;
|
|
64
|
+
getHistory: () => Array<ToastT | ToastToDismiss>;
|
|
65
|
+
getToasts: () => Array<ToastT | ToastToDismiss>;
|
|
66
|
+
};
|
|
67
|
+
declare function extractToastMessage(value: ToastValue, fallback?: string): string;
|
|
68
|
+
declare function resolveToastVariantForMessage(value: ToastValue): ToastVariant;
|
|
69
|
+
declare function MonkeysToaster({ className, closeButton, position, richColors, toastOptions, useThemeClassNames, visibleToasts, ...props }: MonkeysToasterProps): react_jsx_runtime.JSX.Element;
|
|
70
|
+
declare function MonkeysToastProvider({ children, toasterProps }: MonkeysToastProviderProps): react_jsx_runtime.JSX.Element;
|
|
71
|
+
declare function useToastOnValue(value: ToastValue, options?: ToastValueOptions): void;
|
|
72
|
+
declare function useToastFeed(items: ToastFeedEntry[], options?: Pick<ToastValueOptions, 'messages' | 'translate'>): void;
|
|
73
|
+
declare const toast: MonkeysToastApi;
|
|
74
|
+
|
|
75
|
+
export { type MonkeysToastApi, MonkeysToastProvider, type MonkeysToastProviderProps, MonkeysToaster, type MonkeysToasterProps, type ToastInput, MonkeysToastProvider as ToastProvider, type ToastVariant, MonkeysToaster as Toaster, extractToastMessage, resolveToastVariantForMessage, toast, useToastFeed, useToastOnValue };
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var sonner = require('sonner');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/components/toast/index.tsx
|
|
8
|
+
var DEFAULT_TOAST_DURATION = 5200;
|
|
9
|
+
var TOAST_DEDUPE_WINDOW = 1200;
|
|
10
|
+
var DEFAULT_MESSAGES = {
|
|
11
|
+
errorTitle: "Error",
|
|
12
|
+
warningTitle: "Warning",
|
|
13
|
+
defaultErrorDescription: "Something went wrong.",
|
|
14
|
+
defaultWarningDescription: "Please check and try again."
|
|
15
|
+
};
|
|
16
|
+
var ACTIONABLE_TOAST_PATTERNS = [
|
|
17
|
+
/^(please|select|enter|provide|write|choose|confirm|fill)\b/i,
|
|
18
|
+
/^(请|请选择|请先|请输入|请填写|请确认|请留意)/
|
|
19
|
+
];
|
|
20
|
+
var DEFAULT_TOAST_CLASS_NAMES = {
|
|
21
|
+
toast: "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
|
22
|
+
description: "group-[.toast]:text-muted-foreground",
|
|
23
|
+
actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
|
24
|
+
cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"
|
|
25
|
+
};
|
|
26
|
+
var recentToastSignatures = /* @__PURE__ */ new Map();
|
|
27
|
+
function cn(...classNames) {
|
|
28
|
+
return classNames.filter(Boolean).join(" ");
|
|
29
|
+
}
|
|
30
|
+
function isToastInput(input) {
|
|
31
|
+
if (!input || typeof input !== "object" || react.isValidElement(input)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return "title" in input || "description" in input || "variant" in input;
|
|
35
|
+
}
|
|
36
|
+
function isEmptyToastContent(value) {
|
|
37
|
+
return value == null || typeof value === "string" && !value.trim();
|
|
38
|
+
}
|
|
39
|
+
function normalizeToastInput(input, variant, options) {
|
|
40
|
+
const { description: _description, ...baseOptions } = options ?? {};
|
|
41
|
+
if (isToastInput(input)) {
|
|
42
|
+
return {
|
|
43
|
+
...baseOptions,
|
|
44
|
+
...input,
|
|
45
|
+
variant: input.variant ?? variant
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...baseOptions,
|
|
50
|
+
title: input,
|
|
51
|
+
variant
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function resolveValue(candidate, value) {
|
|
55
|
+
if (typeof candidate === "function") {
|
|
56
|
+
return candidate(value);
|
|
57
|
+
}
|
|
58
|
+
return candidate;
|
|
59
|
+
}
|
|
60
|
+
function shouldEmitToast(signature) {
|
|
61
|
+
const now = Date.now();
|
|
62
|
+
for (const [key, timestamp] of recentToastSignatures.entries()) {
|
|
63
|
+
if (now - timestamp > TOAST_DEDUPE_WINDOW) {
|
|
64
|
+
recentToastSignatures.delete(key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const previousTimestamp = recentToastSignatures.get(signature);
|
|
68
|
+
if (previousTimestamp && now - previousTimestamp < TOAST_DEDUPE_WINDOW) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
recentToastSignatures.set(signature, now);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
function translateMessage(translate, value) {
|
|
75
|
+
return translate ? translate(value, { defaultValue: value }) : value;
|
|
76
|
+
}
|
|
77
|
+
function getDefaultMessage(messages, key) {
|
|
78
|
+
return messages?.[key] ?? DEFAULT_MESSAGES[key];
|
|
79
|
+
}
|
|
80
|
+
function emitToast(input) {
|
|
81
|
+
const { title, description, duration, variant = "info", ...options } = input;
|
|
82
|
+
const message = isEmptyToastContent(title) ? description : title;
|
|
83
|
+
if (isEmptyToastContent(message)) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const descriptionValue = !isEmptyToastContent(description) && description !== message ? description : void 0;
|
|
87
|
+
const sonnerOptions = {
|
|
88
|
+
...options,
|
|
89
|
+
description: descriptionValue,
|
|
90
|
+
duration: duration ?? DEFAULT_TOAST_DURATION
|
|
91
|
+
};
|
|
92
|
+
switch (variant) {
|
|
93
|
+
case "error":
|
|
94
|
+
return sonner.toast.error(message, sonnerOptions);
|
|
95
|
+
case "warning":
|
|
96
|
+
return sonner.toast.warning(message, sonnerOptions);
|
|
97
|
+
case "success":
|
|
98
|
+
return sonner.toast.success(message, sonnerOptions);
|
|
99
|
+
default:
|
|
100
|
+
return sonner.toast(message, sonnerOptions);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function extractToastMessage(value, fallback = "") {
|
|
104
|
+
if (!value) return fallback;
|
|
105
|
+
if (typeof value === "string") {
|
|
106
|
+
const nextMessage = value.trim();
|
|
107
|
+
return nextMessage || fallback;
|
|
108
|
+
}
|
|
109
|
+
if (value instanceof Error) {
|
|
110
|
+
const nextMessage = String(value.message || "").trim();
|
|
111
|
+
return nextMessage || fallback;
|
|
112
|
+
}
|
|
113
|
+
if (typeof value === "object" && typeof value.message === "string") {
|
|
114
|
+
const nextMessage = value.message.trim();
|
|
115
|
+
if (nextMessage) return nextMessage;
|
|
116
|
+
}
|
|
117
|
+
if (typeof value === "object" && typeof value.title === "string") {
|
|
118
|
+
const nextTitle = value.title.trim();
|
|
119
|
+
if (nextTitle) return nextTitle;
|
|
120
|
+
}
|
|
121
|
+
return fallback;
|
|
122
|
+
}
|
|
123
|
+
function resolveToastVariantForMessage(value) {
|
|
124
|
+
const message = extractToastMessage(value);
|
|
125
|
+
if (ACTIONABLE_TOAST_PATTERNS.some((pattern) => pattern.test(message))) {
|
|
126
|
+
return "warning";
|
|
127
|
+
}
|
|
128
|
+
return "error";
|
|
129
|
+
}
|
|
130
|
+
function MonkeysToaster({
|
|
131
|
+
className,
|
|
132
|
+
closeButton = true,
|
|
133
|
+
position = "bottom-right",
|
|
134
|
+
richColors = true,
|
|
135
|
+
toastOptions,
|
|
136
|
+
useThemeClassNames = true,
|
|
137
|
+
visibleToasts = 10,
|
|
138
|
+
...props
|
|
139
|
+
}) {
|
|
140
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
141
|
+
sonner.Toaster,
|
|
142
|
+
{
|
|
143
|
+
className: cn("pointer-events-auto toaster group", className),
|
|
144
|
+
closeButton,
|
|
145
|
+
position,
|
|
146
|
+
richColors,
|
|
147
|
+
toastOptions: {
|
|
148
|
+
...toastOptions,
|
|
149
|
+
classNames: useThemeClassNames ? {
|
|
150
|
+
...DEFAULT_TOAST_CLASS_NAMES,
|
|
151
|
+
...toastOptions?.classNames
|
|
152
|
+
} : toastOptions?.classNames
|
|
153
|
+
},
|
|
154
|
+
visibleToasts,
|
|
155
|
+
...props
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
function MonkeysToastProvider({ children, toasterProps }) {
|
|
160
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
161
|
+
children,
|
|
162
|
+
/* @__PURE__ */ jsxRuntime.jsx(MonkeysToaster, { ...toasterProps })
|
|
163
|
+
] });
|
|
164
|
+
}
|
|
165
|
+
function useToastOnValue(value, options = {}) {
|
|
166
|
+
const previousSignatureRef = react.useRef(null);
|
|
167
|
+
const translate = options.translate;
|
|
168
|
+
react.useEffect(() => {
|
|
169
|
+
if (!value) {
|
|
170
|
+
previousSignatureRef.current = null;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const variant = resolveValue(options.variant, value) ?? "error";
|
|
174
|
+
const rawTitle = resolveValue(options.title, value);
|
|
175
|
+
const rawFallbackDescription = resolveValue(options.fallbackDescription, value);
|
|
176
|
+
const rawDescription = resolveValue(options.description, value) ?? extractToastMessage(value, rawFallbackDescription || "");
|
|
177
|
+
const title = translateMessage(
|
|
178
|
+
translate,
|
|
179
|
+
rawTitle || getDefaultMessage(options.messages, variant === "warning" ? "warningTitle" : "errorTitle")
|
|
180
|
+
);
|
|
181
|
+
const description = translateMessage(
|
|
182
|
+
translate,
|
|
183
|
+
rawDescription || getDefaultMessage(
|
|
184
|
+
options.messages,
|
|
185
|
+
variant === "warning" ? "defaultWarningDescription" : "defaultErrorDescription"
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
const signature = resolveValue(options.signature, value) || [variant, title, description].join("|");
|
|
189
|
+
if (previousSignatureRef.current === signature) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
previousSignatureRef.current = signature;
|
|
193
|
+
if (!shouldEmitToast(signature)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
toast.show({
|
|
197
|
+
variant,
|
|
198
|
+
title,
|
|
199
|
+
description,
|
|
200
|
+
duration: resolveValue(options.duration, value)
|
|
201
|
+
});
|
|
202
|
+
}, [
|
|
203
|
+
options.description,
|
|
204
|
+
options.duration,
|
|
205
|
+
options.fallbackDescription,
|
|
206
|
+
options.messages,
|
|
207
|
+
options.signature,
|
|
208
|
+
options.title,
|
|
209
|
+
options.variant,
|
|
210
|
+
translate,
|
|
211
|
+
value
|
|
212
|
+
]);
|
|
213
|
+
}
|
|
214
|
+
function useToastFeed(items, options = {}) {
|
|
215
|
+
const previousVisibleSignaturesRef = react.useRef(/* @__PURE__ */ new Set());
|
|
216
|
+
const translate = options.translate;
|
|
217
|
+
const emitItem = react.useCallback(
|
|
218
|
+
(item, index, visibleSignatures) => {
|
|
219
|
+
const variant = item.variant ?? "info";
|
|
220
|
+
const title = translateMessage(
|
|
221
|
+
translate,
|
|
222
|
+
item.title || getDefaultMessage(options.messages, variant === "warning" ? "warningTitle" : "errorTitle")
|
|
223
|
+
);
|
|
224
|
+
const description = translateMessage(
|
|
225
|
+
translate,
|
|
226
|
+
item.description || getDefaultMessage(
|
|
227
|
+
options.messages,
|
|
228
|
+
variant === "warning" ? "defaultWarningDescription" : "defaultErrorDescription"
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
const signature = item.signature || [variant, title, description, index].join("|");
|
|
232
|
+
visibleSignatures.add(signature);
|
|
233
|
+
if (previousVisibleSignaturesRef.current.has(signature) || !shouldEmitToast(signature)) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
toast.show({
|
|
237
|
+
variant,
|
|
238
|
+
title,
|
|
239
|
+
description,
|
|
240
|
+
duration: item.duration
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
[options.messages, translate]
|
|
244
|
+
);
|
|
245
|
+
react.useEffect(() => {
|
|
246
|
+
const visibleSignatures = /* @__PURE__ */ new Set();
|
|
247
|
+
items.forEach((item, index) => {
|
|
248
|
+
if (item) {
|
|
249
|
+
emitItem(item, index, visibleSignatures);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
previousVisibleSignaturesRef.current = visibleSignatures;
|
|
253
|
+
}, [emitItem, items]);
|
|
254
|
+
}
|
|
255
|
+
var toast = Object.assign(
|
|
256
|
+
(message, options) => sonner.toast(message, options),
|
|
257
|
+
{
|
|
258
|
+
show: emitToast,
|
|
259
|
+
error: (input, options) => emitToast(normalizeToastInput(input, "error", options)),
|
|
260
|
+
warning: (input, options) => emitToast(normalizeToastInput(input, "warning", options)),
|
|
261
|
+
success: (input, options) => emitToast(normalizeToastInput(input, "success", options)),
|
|
262
|
+
info: (input, options) => emitToast(normalizeToastInput(input, "info", options)),
|
|
263
|
+
message: sonner.toast.message,
|
|
264
|
+
promise: sonner.toast.promise,
|
|
265
|
+
dismiss: sonner.toast.dismiss,
|
|
266
|
+
loading: sonner.toast.loading,
|
|
267
|
+
custom: sonner.toast.custom,
|
|
268
|
+
getHistory: sonner.toast.getHistory,
|
|
269
|
+
getToasts: sonner.toast.getToasts
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
exports.MonkeysToastProvider = MonkeysToastProvider;
|
|
274
|
+
exports.MonkeysToaster = MonkeysToaster;
|
|
275
|
+
exports.ToastProvider = MonkeysToastProvider;
|
|
276
|
+
exports.Toaster = MonkeysToaster;
|
|
277
|
+
exports.extractToastMessage = extractToastMessage;
|
|
278
|
+
exports.resolveToastVariantForMessage = resolveToastVariantForMessage;
|
|
279
|
+
exports.toast = toast;
|
|
280
|
+
exports.useToastFeed = useToastFeed;
|
|
281
|
+
exports.useToastOnValue = useToastOnValue;
|
|
282
|
+
//# sourceMappingURL=index.js.map
|
|
283
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/toast/index.tsx"],"names":["isValidElement","sonnerToast","jsx","SonnerToaster","jsxs","Fragment","useRef","useEffect","useCallback"],"mappings":";;;;;;;AA+FA,IAAM,sBAAA,GAAyB,IAAA;AAC/B,IAAM,mBAAA,GAAsB,IAAA;AAE5B,IAAM,gBAAA,GAAyC;AAAA,EAC7C,UAAA,EAAY,OAAA;AAAA,EACZ,YAAA,EAAc,SAAA;AAAA,EACd,uBAAA,EAAyB,uBAAA;AAAA,EACzB,yBAAA,EAA2B;AAC7B,CAAA;AAEA,IAAM,yBAAA,GAA4B;AAAA,EAChC,6DAAA;AAAA,EACA;AACF,CAAA;AAEA,IAAM,yBAAA,GAA4B;AAAA,EAChC,KAAA,EACE,uIAAA;AAAA,EACF,WAAA,EAAa,sCAAA;AAAA,EACb,YAAA,EAAc,kEAAA;AAAA,EACd,YAAA,EAAc;AAChB,CAAA;AAEA,IAAM,qBAAA,uBAA4B,GAAA,EAAoB;AAEtD,SAAS,MAAM,UAAA,EAA+C;AAC5D,EAAA,OAAO,UAAA,CAAW,MAAA,CAAO,OAAO,CAAA,CAAE,KAAK,GAAG,CAAA;AAC5C;AAEA,SAAS,aAAa,KAAA,EAAqC;AACzD,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,UAAU,QAAA,IAAYA,oBAAA,CAAe,KAAK,CAAA,EAAG;AAChE,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,OAAA,IAAW,KAAA,IAAS,aAAA,IAAiB,KAAA,IAAS,SAAA,IAAa,KAAA;AACpE;AAEA,SAAS,oBAAoB,KAAA,EAAkB;AAC7C,EAAA,OAAO,SAAS,IAAA,IAAS,OAAO,UAAU,QAAA,IAAY,CAAC,MAAM,I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{\n isValidElement,\n type ReactElement,\n type ReactNode,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\nimport {\n Toaster as SonnerToaster,\n toast as sonnerToast,\n type ExternalToast,\n type ToastT,\n type ToastToDismiss,\n type ToasterProps,\n} from 'sonner';\n\nexport type ToastVariant = 'error' | 'warning' | 'success' | 'info';\n\nexport type ToastInput = Omit<ExternalToast, 'description'> & {\n title?: ReactNode;\n description?: ReactNode;\n variant?: ToastVariant;\n};\n\nexport type MonkeysToasterProps = ToasterProps & {\n useThemeClassNames?: boolean;\n};\n\nexport type MonkeysToastProviderProps = {\n children: ReactNode;\n toasterProps?: MonkeysToasterProps;\n};\n\ntype ToastValue =\n | Error\n | string\n | {\n message?: unknown;\n title?: unknown;\n }\n | null\n | undefined;\n\ntype ToastResolver<T> = T | ((value: ToastValue) => T);\ntype ToastTranslate = (value: string, params?: Record<string, unknown>) => string;\n\ntype ToastValueOptions = {\n variant?: ToastResolver<ToastVariant | undefined>;\n title?: ToastResolver<string | undefined>;\n description?: ToastResolver<string | undefined>;\n fallbackDescription?: ToastResolver<string | undefined>;\n signature?: ToastResolver<string | undefined>;\n duration?: ToastResolver<number | undefined>;\n translate?: ToastTranslate;\n messages?: Partial<ToastDefaultMessages>;\n};\n\ntype ToastFeedEntry =\n | {\n variant?: ToastVariant;\n title?: string;\n description?: string;\n duration?: number;\n signature?: string;\n }\n | null\n | undefined;\n\ntype ToastDefaultMessages = {\n errorTitle: string;\n warningTitle: string;\n defaultErrorDescription: string;\n defaultWarningDescription: string;\n};\n\ntype ToastPromiseInput<T = unknown> = Promise<T> | (() => Promise<T>);\ntype ToastPromiseReturn<T = unknown> = string | number | { unwrap: () => Promise<T> };\n\nexport type MonkeysToastApi = {\n (message: ReactNode, options?: ExternalToast): string | number;\n show: (input: ToastInput) => string | number | undefined;\n error: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;\n warning: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;\n success: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;\n info: (input: ReactNode | ToastInput, options?: ExternalToast) => string | number | undefined;\n message: (message: ReactNode, options?: ExternalToast) => string | number;\n promise: <T = unknown>(promise: ToastPromiseInput<T>, data?: unknown) => ToastPromiseReturn<T>;\n dismiss: (id?: number | string) => string | number;\n loading: (message: ReactNode, options?: ExternalToast) => string | number;\n custom: (jsx: (id: number | string) => ReactElement, data?: ExternalToast) => string | number;\n getHistory: () => Array<ToastT | ToastToDismiss>;\n getToasts: () => Array<ToastT | ToastToDismiss>;\n};\n\nconst DEFAULT_TOAST_DURATION = 5200;\nconst TOAST_DEDUPE_WINDOW = 1200;\n\nconst DEFAULT_MESSAGES: ToastDefaultMessages = {\n errorTitle: 'Error',\n warningTitle: 'Warning',\n defaultErrorDescription: 'Something went wrong.',\n defaultWarningDescription: 'Please check and try again.',\n};\n\nconst ACTIONABLE_TOAST_PATTERNS = [\n /^(please|select|enter|provide|write|choose|confirm|fill)\\b/i,\n /^(请|请选择|请先|请输入|请填写|请确认|请留意)/,\n];\n\nconst DEFAULT_TOAST_CLASS_NAMES = {\n toast:\n 'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',\n description: 'group-[.toast]:text-muted-foreground',\n actionButton: 'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',\n cancelButton: 'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',\n};\n\nconst recentToastSignatures = new Map<string, number>();\n\nfunction cn(...classNames: Array<string | undefined | false>) {\n return classNames.filter(Boolean).join(' ');\n}\n\nfunction isToastInput(input: unknown): input is ToastInput {\n if (!input || typeof input !== 'object' || isValidElement(input)) {\n return false;\n }\n\n return 'title' in input || 'description' in input || 'variant' in input;\n}\n\nfunction isEmptyToastContent(value: ReactNode) {\n return value == null || (typeof value === 'string' && !value.trim());\n}\n\nfunction normalizeToastInput(input: ReactNode | ToastInput, variant: ToastVariant, options?: ExternalToast): ToastInput {\n const { description: _description, ...baseOptions } = options ?? {};\n\n if (isToastInput(input)) {\n return {\n ...baseOptions,\n ...input,\n variant: input.variant ?? variant,\n };\n }\n\n return {\n ...baseOptions,\n title: input,\n variant,\n };\n}\n\nfunction resolveValue<T>(candidate: ToastResolver<T> | undefined, value: ToastValue) {\n if (typeof candidate === 'function') {\n return (candidate as (input: ToastValue) => T)(value);\n }\n\n return candidate;\n}\n\nfunction shouldEmitToast(signature: string) {\n const now = Date.now();\n\n for (const [key, timestamp] of recentToastSignatures.entries()) {\n if (now - timestamp > TOAST_DEDUPE_WINDOW) {\n recentToastSignatures.delete(key);\n }\n }\n\n const previousTimestamp = recentToastSignatures.get(signature);\n if (previousTimestamp && now - previousTimestamp < TOAST_DEDUPE_WINDOW) {\n return false;\n }\n\n recentToastSignatures.set(signature, now);\n return true;\n}\n\nfunction translateMessage(translate: ToastTranslate | undefined, value: string) {\n return translate ? translate(value, { defaultValue: value }) : value;\n}\n\nfunction getDefaultMessage(messages: Partial<ToastDefaultMessages> | undefined, key: keyof ToastDefaultMessages) {\n return messages?.[key] ?? DEFAULT_MESSAGES[key];\n}\n\nfunction emitToast(input: ToastInput) {\n const { title, description, duration, variant = 'info', ...options } = input;\n const message = isEmptyToastContent(title) ? description : title;\n\n if (isEmptyToastContent(message)) {\n return undefined;\n }\n\n const descriptionValue =\n !isEmptyToastContent(description) && description !== message ? description : undefined;\n const sonnerOptions: ExternalToast = {\n ...options,\n description: descriptionValue,\n duration: duration ?? DEFAULT_TOAST_DURATION,\n };\n\n switch (variant) {\n case 'error':\n return sonnerToast.error(message, sonnerOptions);\n case 'warning':\n return sonnerToast.warning(message, sonnerOptions);\n case 'success':\n return sonnerToast.success(message, sonnerOptions);\n default:\n return sonnerToast(message, sonnerOptions);\n }\n}\n\nexport function extractToastMessage(value: ToastValue, fallback = '') {\n if (!value) return fallback;\n\n if (typeof value === 'string') {\n const nextMessage = value.trim();\n return nextMessage || fallback;\n }\n\n if (value instanceof Error) {\n const nextMessage = String(value.message || '').trim();\n return nextMessage || fallback;\n }\n\n if (typeof value === 'object' && typeof value.message === 'string') {\n const nextMessage = value.message.trim();\n if (nextMessage) return nextMessage;\n }\n\n if (typeof value === 'object' && typeof value.title === 'string') {\n const nextTitle = value.title.trim();\n if (nextTitle) return nextTitle;\n }\n\n return fallback;\n}\n\nexport function resolveToastVariantForMessage(value: ToastValue): ToastVariant {\n const message = extractToastMessage(value);\n\n if (ACTIONABLE_TOAST_PATTERNS.some((pattern) => pattern.test(message))) {\n return 'warning';\n }\n\n return 'error';\n}\n\nexport function MonkeysToaster({\n className,\n closeButton = true,\n position = 'bottom-right',\n richColors = true,\n toastOptions,\n useThemeClassNames = true,\n visibleToasts = 10,\n ...props\n}: MonkeysToasterProps) {\n return (\n <SonnerToaster\n className={cn('pointer-events-auto toaster group', className)}\n closeButton={closeButton}\n position={position}\n richColors={richColors}\n toastOptions={{\n ...toastOptions,\n classNames: useThemeClassNames\n ? {\n ...DEFAULT_TOAST_CLASS_NAMES,\n ...toastOptions?.classNames,\n }\n : toastOptions?.classNames,\n }}\n visibleToasts={visibleToasts}\n {...props}\n />\n );\n}\n\nexport function MonkeysToastProvider({ children, toasterProps }: MonkeysToastProviderProps) {\n return (\n <>\n {children}\n <MonkeysToaster {...toasterProps} />\n </>\n );\n}\n\nexport function useToastOnValue(value: ToastValue, options: ToastValueOptions = {}) {\n const previousSignatureRef = useRef<string | null>(null);\n const translate = options.translate;\n\n useEffect(() => {\n if (!value) {\n previousSignatureRef.current = null;\n return;\n }\n\n const variant = resolveValue(options.variant, value) ?? 'error';\n const rawTitle = resolveValue(options.title, value);\n const rawFallbackDescription = resolveValue(options.fallbackDescription, value);\n const rawDescription =\n resolveValue(options.description, value) ?? extractToastMessage(value, rawFallbackDescription || '');\n const title = translateMessage(\n translate,\n rawTitle || getDefaultMessage(options.messages, variant === 'warning' ? 'warningTitle' : 'errorTitle'),\n );\n const description = translateMessage(\n translate,\n rawDescription ||\n getDefaultMessage(\n options.messages,\n variant === 'warning' ? 'defaultWarningDescription' : 'defaultErrorDescription',\n ),\n );\n const signature = resolveValue(options.signature, value) || [variant, title, description].join('|');\n\n if (previousSignatureRef.current === signature) {\n return;\n }\n\n previousSignatureRef.current = signature;\n\n if (!shouldEmitToast(signature)) {\n return;\n }\n\n toast.show({\n variant,\n title,\n description,\n duration: resolveValue(options.duration, value),\n });\n }, [\n options.description,\n options.duration,\n options.fallbackDescription,\n options.messages,\n options.signature,\n options.title,\n options.variant,\n translate,\n value,\n ]);\n}\n\nexport function useToastFeed(items: ToastFeedEntry[], options: Pick<ToastValueOptions, 'messages' | 'translate'> = {}) {\n const previousVisibleSignaturesRef = useRef<Set<string>>(new Set());\n const translate = options.translate;\n const emitItem = useCallback(\n (item: NonNullable<ToastFeedEntry>, index: number, visibleSignatures: Set<string>) => {\n const variant = item.variant ?? 'info';\n const title = translateMessage(\n translate,\n item.title || getDefaultMessage(options.messages, variant === 'warning' ? 'warningTitle' : 'errorTitle'),\n );\n const description = translateMessage(\n translate,\n item.description ||\n getDefaultMessage(\n options.messages,\n variant === 'warning' ? 'defaultWarningDescription' : 'defaultErrorDescription',\n ),\n );\n const signature = item.signature || [variant, title, description, index].join('|');\n\n visibleSignatures.add(signature);\n\n if (previousVisibleSignaturesRef.current.has(signature) || !shouldEmitToast(signature)) {\n return;\n }\n\n toast.show({\n variant,\n title,\n description,\n duration: item.duration,\n });\n },\n [options.messages, translate],\n );\n\n useEffect(() => {\n const visibleSignatures = new Set<string>();\n\n items.forEach((item, index) => {\n if (item) {\n emitItem(item, index, visibleSignatures);\n }\n });\n\n previousVisibleSignaturesRef.current = visibleSignatures;\n }, [emitItem, items]);\n}\n\nexport const toast: MonkeysToastApi = Object.assign(\n (message: ReactNode, options?: ExternalToast) => sonnerToast(message, options),\n {\n show: emitToast,\n error: (input: ReactNode | ToastInput, options?: ExternalToast) =>\n emitToast(normalizeToastInput(input, 'error', options)),\n warning: (input: ReactNode | ToastInput, options?: ExternalToast) =>\n emitToast(normalizeToastInput(input, 'warning', options)),\n success: (input: ReactNode | ToastInput, options?: ExternalToast) =>\n emitToast(normalizeToastInput(input, 'success', options)),\n info: (input: ReactNode | ToastInput, options?: ExternalToast) =>\n emitToast(normalizeToastInput(input, 'info', options)),\n message: sonnerToast.message,\n promise: sonnerToast.promise as MonkeysToastApi['promise'],\n dismiss: sonnerToast.dismiss,\n loading: sonnerToast.loading,\n custom: sonnerToast.custom as (jsx: (id: number | string) => ReactElement, data?: ExternalToast) => string | number,\n getHistory: sonnerToast.getHistory,\n getToasts: sonnerToast.getToasts,\n },\n);\n\nexport { MonkeysToaster as Toaster, MonkeysToastProvider as ToastProvider };\nexport type { ExternalToast, ToasterProps };\n"]}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { isValidElement, useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import { toast as toast$1, Toaster } from 'sonner';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// src/components/toast/index.tsx
|
|
6
|
+
var DEFAULT_TOAST_DURATION = 5200;
|
|
7
|
+
var TOAST_DEDUPE_WINDOW = 1200;
|
|
8
|
+
var DEFAULT_MESSAGES = {
|
|
9
|
+
errorTitle: "Error",
|
|
10
|
+
warningTitle: "Warning",
|
|
11
|
+
defaultErrorDescription: "Something went wrong.",
|
|
12
|
+
defaultWarningDescription: "Please check and try again."
|
|
13
|
+
};
|
|
14
|
+
var ACTIONABLE_TOAST_PATTERNS = [
|
|
15
|
+
/^(please|select|enter|provide|write|choose|confirm|fill)\b/i,
|
|
16
|
+
/^(请|请选择|请先|请输入|请填写|请确认|请留意)/
|
|
17
|
+
];
|
|
18
|
+
var DEFAULT_TOAST_CLASS_NAMES = {
|
|
19
|
+
toast: "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
|
20
|
+
description: "group-[.toast]:text-muted-foreground",
|
|
21
|
+
actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
|
22
|
+
cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"
|
|
23
|
+
};
|
|
24
|
+
var recentToastSignatures = /* @__PURE__ */ new Map();
|
|
25
|
+
function cn(...classNames) {
|
|
26
|
+
return classNames.filter(Boolean).join(" ");
|
|
27
|
+
}
|
|
28
|
+
function isToastInput(input) {
|
|
29
|
+
if (!input || typeof input !== "object" || isValidElement(input)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return "title" in input || "description" in input || "variant" in input;
|
|
33
|
+
}
|
|
34
|
+
function isEmptyToastContent(value) {
|
|
35
|
+
return value == null || typeof value === "string" && !value.trim();
|
|
36
|
+
}
|
|
37
|
+
function normalizeToastInput(input, variant, options) {
|
|
38
|
+
const { description: _description, ...baseOptions } = options ?? {};
|
|
39
|
+
if (isToastInput(input)) {
|
|
40
|
+
return {
|
|
41
|
+
...baseOptions,
|
|
42
|
+
...input,
|
|
43
|
+
variant: input.variant ?? variant
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...baseOptions,
|
|
48
|
+
title: input,
|
|
49
|
+
variant
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function resolveValue(candidate, value) {
|
|
53
|
+
if (typeof candidate === "function") {
|
|
54
|
+
return candidate(value);
|
|
55
|
+
}
|
|
56
|
+
return candidate;
|
|
57
|
+
}
|
|
58
|
+
function shouldEmitToast(signature) {
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
for (const [key, timestamp] of recentToastSignatures.entries()) {
|
|
61
|
+
if (now - timestamp > TOAST_DEDUPE_WINDOW) {
|
|
62
|
+
recentToastSignatures.delete(key);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const previousTimestamp = recentToastSignatures.get(signature);
|
|
66
|
+
if (previousTimestamp && now - previousTimestamp < TOAST_DEDUPE_WINDOW) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
recentToastSignatures.set(signature, now);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
function translateMessage(translate, value) {
|
|
73
|
+
return translate ? translate(value, { defaultValue: value }) : value;
|
|
74
|
+
}
|
|
75
|
+
function getDefaultMessage(messages, key) {
|
|
76
|
+
return messages?.[key] ?? DEFAULT_MESSAGES[key];
|
|
77
|
+
}
|
|
78
|
+
function emitToast(input) {
|
|
79
|
+
const { title, description, duration, variant = "info", ...options } = input;
|
|
80
|
+
const message = isEmptyToastContent(title) ? description : title;
|
|
81
|
+
if (isEmptyToastContent(message)) {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
const descriptionValue = !isEmptyToastContent(description) && description !== message ? description : void 0;
|
|
85
|
+
const sonnerOptions = {
|
|
86
|
+
...options,
|
|
87
|
+
description: descriptionValue,
|
|
88
|
+
duration: duration ?? DEFAULT_TOAST_DURATION
|
|
89
|
+
};
|
|
90
|
+
switch (variant) {
|
|
91
|
+
case "error":
|
|
92
|
+
return toast$1.error(message, sonnerOptions);
|
|
93
|
+
case "warning":
|
|
94
|
+
return toast$1.warning(message, sonnerOptions);
|
|
95
|
+
case "success":
|
|
96
|
+
return toast$1.success(message, sonnerOptions);
|
|
97
|
+
default:
|
|
98
|
+
return toast$1(message, sonnerOptions);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function extractToastMessage(value, fallback = "") {
|
|
102
|
+
if (!value) return fallback;
|
|
103
|
+
if (typeof value === "string") {
|
|
104
|
+
const nextMessage = value.trim();
|
|
105
|
+
return nextMessage || fallback;
|
|
106
|
+
}
|
|
107
|
+
if (value instanceof Error) {
|
|
108
|
+
const nextMessage = String(value.message || "").trim();
|
|
109
|
+
return nextMessage || fallback;
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === "object" && typeof value.message === "string") {
|
|
112
|
+
const nextMessage = value.message.trim();
|
|
113
|
+
if (nextMessage) return nextMessage;
|
|
114
|
+
}
|
|
115
|
+
if (typeof value === "object" && typeof value.title === "string") {
|
|
116
|
+
const nextTitle = value.title.trim();
|
|
117
|
+
if (nextTitle) return nextTitle;
|
|
118
|
+
}
|
|
119
|
+
return fallback;
|
|
120
|
+
}
|
|
121
|
+
function resolveToastVariantForMessage(value) {
|
|
122
|
+
const message = extractToastMessage(value);
|
|
123
|
+
if (ACTIONABLE_TOAST_PATTERNS.some((pattern) => pattern.test(message))) {
|
|
124
|
+
return "warning";
|
|
125
|
+
}
|
|
126
|
+
return "error";
|
|
127
|
+
}
|
|
128
|
+
function MonkeysToaster({
|
|
129
|
+
className,
|
|
130
|
+
closeButton = true,
|
|
131
|
+
position = "bottom-right",
|
|
132
|
+
richColors = true,
|
|
133
|
+
toastOptions,
|
|
134
|
+
useThemeClassNames = true,
|
|
135
|
+
visibleToasts = 10,
|
|
136
|
+
...props
|
|
137
|
+
}) {
|
|
138
|
+
return /* @__PURE__ */ jsx(
|
|
139
|
+
Toaster,
|
|
140
|
+
{
|
|
141
|
+
className: cn("pointer-events-auto toaster group", className),
|
|
142
|
+
closeButton,
|
|
143
|
+
position,
|
|
144
|
+
richColors,
|
|
145
|
+
toastOptions: {
|
|
146
|
+
...toastOptions,
|
|
147
|
+
classNames: useThemeClassNames ? {
|
|
148
|
+
...DEFAULT_TOAST_CLASS_NAMES,
|
|
149
|
+
...toastOptions?.classNames
|
|
150
|
+
} : toastOptions?.classNames
|
|
151
|
+
},
|
|
152
|
+
visibleToasts,
|
|
153
|
+
...props
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function MonkeysToastProvider({ children, toasterProps }) {
|
|
158
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
159
|
+
children,
|
|
160
|
+
/* @__PURE__ */ jsx(MonkeysToaster, { ...toasterProps })
|
|
161
|
+
] });
|
|
162
|
+
}
|
|
163
|
+
function useToastOnValue(value, options = {}) {
|
|
164
|
+
const previousSignatureRef = useRef(null);
|
|
165
|
+
const translate = options.translate;
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!value) {
|
|
168
|
+
previousSignatureRef.current = null;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const variant = resolveValue(options.variant, value) ?? "error";
|
|
172
|
+
const rawTitle = resolveValue(options.title, value);
|
|
173
|
+
const rawFallbackDescription = resolveValue(options.fallbackDescription, value);
|
|
174
|
+
const rawDescription = resolveValue(options.description, value) ?? extractToastMessage(value, rawFallbackDescription || "");
|
|
175
|
+
const title = translateMessage(
|
|
176
|
+
translate,
|
|
177
|
+
rawTitle || getDefaultMessage(options.messages, variant === "warning" ? "warningTitle" : "errorTitle")
|
|
178
|
+
);
|
|
179
|
+
const description = translateMessage(
|
|
180
|
+
translate,
|
|
181
|
+
rawDescription || getDefaultMessage(
|
|
182
|
+
options.messages,
|
|
183
|
+
variant === "warning" ? "defaultWarningDescription" : "defaultErrorDescription"
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
const signature = resolveValue(options.signature, value) || [variant, title, description].join("|");
|
|
187
|
+
if (previousSignatureRef.current === signature) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
previousSignatureRef.current = signature;
|
|
191
|
+
if (!shouldEmitToast(signature)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
toast.show({
|
|
195
|
+
variant,
|
|
196
|
+
title,
|
|
197
|
+
description,
|
|
198
|
+
duration: resolveValue(options.duration, value)
|
|
199
|
+
});
|
|
200
|
+
}, [
|
|
201
|
+
options.description,
|
|
202
|
+
options.duration,
|
|
203
|
+
options.fallbackDescription,
|
|
204
|
+
options.messages,
|
|
205
|
+
options.signature,
|
|
206
|
+
options.title,
|
|
207
|
+
options.variant,
|
|
208
|
+
translate,
|
|
209
|
+
value
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
function useToastFeed(items, options = {}) {
|
|
213
|
+
const previousVisibleSignaturesRef = useRef(/* @__PURE__ */ new Set());
|
|
214
|
+
const translate = options.translate;
|
|
215
|
+
const emitItem = useCallback(
|
|
216
|
+
(item, index, visibleSignatures) => {
|
|
217
|
+
const variant = item.variant ?? "info";
|
|
218
|
+
const title = translateMessage(
|
|
219
|
+
translate,
|
|
220
|
+
item.title || getDefaultMessage(options.messages, variant === "warning" ? "warningTitle" : "errorTitle")
|
|
221
|
+
);
|
|
222
|
+
const description = translateMessage(
|
|
223
|
+
translate,
|
|
224
|
+
item.description || getDefaultMessage(
|
|
225
|
+
options.messages,
|
|
226
|
+
variant === "warning" ? "defaultWarningDescription" : "defaultErrorDescription"
|
|
227
|
+
)
|
|
228
|
+
);
|
|
229
|
+
const signature = item.signature || [variant, title, description, index].join("|");
|
|
230
|
+
visibleSignatures.add(signature);
|
|
231
|
+
if (previousVisibleSignaturesRef.current.has(signature) || !shouldEmitToast(signature)) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
toast.show({
|
|
235
|
+
variant,
|
|
236
|
+
title,
|
|
237
|
+
description,
|
|
238
|
+
duration: item.duration
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
[options.messages, translate]
|
|
242
|
+
);
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
const visibleSignatures = /* @__PURE__ */ new Set();
|
|
245
|
+
items.forEach((item, index) => {
|
|
246
|
+
if (item) {
|
|
247
|
+
emitItem(item, index, visibleSignatures);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
previousVisibleSignaturesRef.current = visibleSignatures;
|
|
251
|
+
}, [emitItem, items]);
|
|
252
|
+
}
|
|
253
|
+
var toast = Object.assign(
|
|
254
|
+
(message, options) => toast$1(message, options),
|
|
255
|
+
{
|
|
256
|
+
show: emitToast,
|
|
257
|
+
error: (input, options) => emitToast(normalizeToastInput(input, "error", options)),
|
|
258
|
+
warning: (input, options) => emitToast(normalizeToastInput(input, "warning", options)),
|
|
259
|
+
success: (input, options) => emitToast(normalizeToastInput(input, "success", options)),
|
|
260
|
+
info: (input, options) => emitToast(normalizeToastInput(input, "info", options)),
|
|
261
|
+
message: toast$1.message,
|
|
262
|
+
promise: toast$1.promise,
|
|
263
|
+
dismiss: toast$1.dismiss,
|
|
264
|
+
loading: toast$1.loading,
|
|
265
|
+
custom: toast$1.custom,
|
|
266
|
+
getHistory: toast$1.getHistory,
|
|
267
|
+
getToasts: toast$1.getToasts
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
export { MonkeysToastProvider, MonkeysToaster, MonkeysToastProvider as ToastProvider, MonkeysToaster as Toaster, extractToastMessage, resolveToastVariantForMessage, toast, useToastFeed, useToastOnValue };
|
|
272
|
+
//# sourceMappingURL=index.mjs.map
|
|
273
|
+
//# sourceMappingURL=index.mjs.map
|