@lobehub/ui 5.26.0 → 5.27.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.
|
@@ -34,17 +34,19 @@ const toastManagers = {
|
|
|
34
34
|
"top-left": Toast.createToastManager(),
|
|
35
35
|
"top-right": Toast.createToastManager()
|
|
36
36
|
};
|
|
37
|
-
const
|
|
38
|
-
"bottom": /* @__PURE__ */ new
|
|
39
|
-
"bottom-left": /* @__PURE__ */ new
|
|
40
|
-
"bottom-right": /* @__PURE__ */ new
|
|
41
|
-
"top": /* @__PURE__ */ new
|
|
42
|
-
"top-left": /* @__PURE__ */ new
|
|
43
|
-
"top-right": /* @__PURE__ */ new
|
|
37
|
+
const activeToasts = {
|
|
38
|
+
"bottom": /* @__PURE__ */ new Map(),
|
|
39
|
+
"bottom-left": /* @__PURE__ */ new Map(),
|
|
40
|
+
"bottom-right": /* @__PURE__ */ new Map(),
|
|
41
|
+
"top": /* @__PURE__ */ new Map(),
|
|
42
|
+
"top-left": /* @__PURE__ */ new Map(),
|
|
43
|
+
"top-right": /* @__PURE__ */ new Map()
|
|
44
44
|
};
|
|
45
45
|
const getManager = (position) => toastManagers[position];
|
|
46
46
|
let toastIdCounter = 0;
|
|
47
47
|
const generateToastId = () => `toast-${Date.now().toString(36)}-${(toastIdCounter++).toString(36)}`;
|
|
48
|
+
const findActivePosition = (id) => ALL_POSITIONS.find((pos) => activeToasts[pos].has(id));
|
|
49
|
+
const isFrontMost = (position, id) => Array.from(activeToasts[position].keys()).at(-1) === id;
|
|
48
50
|
const normalizeOptions = (optionsOrMessage, type) => {
|
|
49
51
|
if (typeof optionsOrMessage === "string") return {
|
|
50
52
|
description: optionsOrMessage,
|
|
@@ -69,17 +71,30 @@ const createToastInstance = (id, position) => ({
|
|
|
69
71
|
const addToast = (options) => {
|
|
70
72
|
const position = options.placement ?? globalState.position;
|
|
71
73
|
const manager = getManager(position);
|
|
72
|
-
const onRemove = options
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
const { id: dedupeId, onClose, onRemove } = options;
|
|
75
|
+
if (dedupeId) {
|
|
76
|
+
const prevPosition = findActivePosition(dedupeId);
|
|
77
|
+
if (prevPosition && !(prevPosition === position && isFrontMost(position, dedupeId))) {
|
|
78
|
+
activeToasts[prevPosition].get(dedupeId).superseded = true;
|
|
79
|
+
activeToasts[prevPosition].delete(dedupeId);
|
|
80
|
+
runWhenToastHostReady(() => getManager(prevPosition).close(dedupeId));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const id = dedupeId ?? generateToastId();
|
|
84
|
+
const active = { superseded: false };
|
|
85
|
+
activeToasts[position].set(id, active);
|
|
75
86
|
runWhenToastHostReady(() => {
|
|
76
87
|
manager.add({
|
|
77
88
|
id,
|
|
78
89
|
data: options,
|
|
79
90
|
description: options.description,
|
|
80
|
-
onClose:
|
|
91
|
+
onClose: () => {
|
|
92
|
+
if (active.superseded) return;
|
|
93
|
+
onClose?.();
|
|
94
|
+
},
|
|
81
95
|
onRemove: () => {
|
|
82
|
-
|
|
96
|
+
if (active.superseded) return;
|
|
97
|
+
activeToasts[position].delete(id);
|
|
83
98
|
onRemove?.();
|
|
84
99
|
},
|
|
85
100
|
timeout: options.duration ?? globalState.duration,
|
|
@@ -90,12 +105,12 @@ const addToast = (options) => {
|
|
|
90
105
|
};
|
|
91
106
|
const dismissToast = (id) => {
|
|
92
107
|
if (id) for (const [position, manager] of Object.entries(toastManagers)) {
|
|
93
|
-
|
|
108
|
+
activeToasts[position].delete(id);
|
|
94
109
|
runWhenToastHostReady(() => manager.close(id));
|
|
95
110
|
}
|
|
96
111
|
else for (const [position, manager] of Object.entries(toastManagers)) {
|
|
97
|
-
const ids = Array.from(
|
|
98
|
-
|
|
112
|
+
const ids = Array.from(activeToasts[position].keys());
|
|
113
|
+
activeToasts[position].clear();
|
|
99
114
|
runWhenToastHostReady(() => {
|
|
100
115
|
for (const toastId of ids) manager.close(toastId);
|
|
101
116
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative.mjs","names":["BaseToast"],"sources":["../../../src/base-ui/Toast/imperative.tsx"],"sourcesContent":["'use client';\n\nimport { Toast as BaseToast } from '@base-ui/react/toast';\nimport { cx } from 'antd-style';\nimport { memo, useEffect, useId, useState, useSyncExternalStore } from 'react';\n\nimport { useIsClient } from '@/hooks/useIsClient';\nimport { useAppElement } from '@/ThemeProvider';\n\nimport { acquireLayerZIndex } from '../zIndex';\nimport { ToastContext } from './context';\nimport { isActiveToastHost, registerToastHost, subscribeToastHost } from './hostGuard';\nimport {\n __resetPendingToastQueueForTests,\n markToastHostNotReady,\n markToastHostReady,\n runWhenToastHostReady,\n} from './pendingQueue';\nimport { viewportVariants } from './style';\nimport ToastItem from './Toast';\nimport {\n type ToastAPI,\n type ToastInstance,\n type ToastOptions,\n type ToastPosition,\n type ToastPromiseOptions,\n type ToastType,\n} from './type';\n\n// All possible positions\nconst ALL_POSITIONS: ToastPosition[] = [\n 'top',\n 'top-left',\n 'top-right',\n 'bottom',\n 'bottom-left',\n 'bottom-right',\n];\n\n// Global state management\ninterface ToastState {\n duration: number;\n limit: number;\n position: ToastPosition;\n swipeDirection: ('left' | 'right' | 'up' | 'down') | ('left' | 'right' | 'up' | 'down')[];\n}\n\nlet globalState: ToastState = {\n duration: 5000,\n limit: 5,\n position: 'bottom-right',\n swipeDirection: ['down', 'right'],\n};\n\n// Toast managers for each position\nconst toastManagers: Record<ToastPosition, ReturnType<typeof BaseToast.createToastManager>> = {\n 'bottom': BaseToast.createToastManager(),\n 'bottom-left': BaseToast.createToastManager(),\n 'bottom-right': BaseToast.createToastManager(),\n 'top': BaseToast.createToastManager(),\n 'top-left': BaseToast.createToastManager(),\n 'top-right': BaseToast.createToastManager(),\n};\n\nconst activeToastIds: Record<ToastPosition, Set<string>> = {\n 'bottom': new Set(),\n 'bottom-left': new Set(),\n 'bottom-right': new Set(),\n 'top': new Set(),\n 'top-left': new Set(),\n 'top-right': new Set(),\n};\n\nconst getManager = (position: ToastPosition) => toastManagers[position];\n\nlet toastIdCounter = 0;\nconst generateToastId = (): string =>\n `toast-${Date.now().toString(36)}-${(toastIdCounter++).toString(36)}`;\n\nconst normalizeOptions = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n type: ToastType,\n): ToastOptions => {\n if (typeof optionsOrMessage === 'string') {\n return {\n description: optionsOrMessage,\n type,\n };\n }\n return {\n ...optionsOrMessage,\n type,\n };\n};\n\nconst createToastInstance = (id: string, position: ToastPosition): ToastInstance => ({\n close: () => runWhenToastHostReady(() => getManager(position).close(id)),\n id,\n update: (options) => {\n runWhenToastHostReady(() =>\n getManager(position).update(id, {\n data: options,\n description: options.description,\n title: options.title,\n }),\n );\n },\n});\n\n// createToastManager() is a stateless emitter (see @base-ui/react/toast/createToastManager):\n// add/close/update just broadcast to whatever is currently subscribed, and the\n// ToastProvider that owns the real toast state only subscribes from a passive\n// useEffect. Calls made while no host is ready (e.g. mid-handoff between the\n// previously-active ToastHost unmounting and its successor's Provider\n// subscribing) would otherwise be silently dropped, so every manager call is\n// routed through runWhenToastHostReady to queue until a host is listening.\nconst addToast = (options: ToastOptions): ToastInstance => {\n const position = options.placement ?? globalState.position;\n const manager = getManager(position);\n const onRemove = options.onRemove;\n const id = generateToastId();\n activeToastIds[position].add(id);\n runWhenToastHostReady(() => {\n manager.add({\n id,\n data: options,\n description: options.description,\n onClose: options.onClose,\n onRemove: () => {\n activeToastIds[position].delete(id);\n onRemove?.();\n },\n timeout: options.duration ?? globalState.duration,\n title: options.title,\n });\n });\n return createToastInstance(id, position);\n};\n\nconst dismissToast = (id?: string) => {\n if (id) {\n // Try to close from all managers since we don't know which position the toast is in\n for (const [position, manager] of Object.entries(toastManagers)) {\n activeToastIds[position as ToastPosition].delete(id);\n runWhenToastHostReady(() => manager.close(id));\n }\n } else {\n // Clear all toasts\n for (const [position, manager] of Object.entries(toastManagers)) {\n const ids = Array.from(activeToastIds[position as ToastPosition]);\n activeToastIds[position as ToastPosition].clear();\n runWhenToastHostReady(() => {\n for (const toastId of ids) {\n manager.close(toastId);\n }\n });\n }\n }\n};\n\nconst createSuccessToast = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'success'));\n};\n\nconst createErrorToast = (optionsOrMessage: Omit<ToastOptions, 'type'> | string): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'error'));\n};\n\nconst createInfoToast = (optionsOrMessage: Omit<ToastOptions, 'type'> | string): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'info'));\n};\n\nconst createWarningToast = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'warning'));\n};\n\nconst createLoadingToast = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n): ToastInstance => {\n const options = normalizeOptions(optionsOrMessage, 'loading');\n // Loading toasts don't auto-dismiss by default\n return addToast({ duration: 0, ...options });\n};\n\nasync function promiseToast<T>(promise: Promise<T>, options: ToastPromiseOptions<T>): Promise<T> {\n const loadingOptions =\n typeof options.loading === 'string'\n ? { description: options.loading }\n : (options.loading as ToastOptions);\n\n const loadingToast = addToast({\n closable: false,\n duration: 0,\n type: 'loading',\n ...loadingOptions,\n });\n\n try {\n const result = await promise;\n\n loadingToast.close();\n\n const successOptions = (() => {\n if (typeof options.success === 'string') {\n return { description: options.success };\n }\n if (typeof options.success === 'function') {\n return { description: options.success(result) };\n }\n return options.success as ToastOptions;\n })();\n\n addToast({ type: 'success', ...successOptions });\n\n return result;\n } catch (error) {\n loadingToast.close();\n\n const errorOptions = (() => {\n if (typeof options.error === 'string') {\n return { description: options.error };\n }\n if (typeof options.error === 'function') {\n return { description: options.error(error as Error) };\n }\n return options.error as ToastOptions;\n })();\n\n addToast({ type: 'error', ...errorOptions });\n\n throw error;\n }\n}\n\n// Base toast function\nconst baseToast = (options: ToastOptions): ToastInstance => {\n return addToast({ type: 'default', ...options });\n};\n\n// Toast API\nexport const toast: ToastAPI = Object.assign(baseToast, {\n dismiss: dismissToast,\n error: createErrorToast,\n info: createInfoToast,\n loading: createLoadingToast,\n promise: promiseToast,\n success: createSuccessToast,\n warning: createWarningToast,\n});\n\n// Toast List Component\nconst ToastList = memo(() => {\n const { toasts } = BaseToast.useToastManager();\n return toasts.map((t) => <ToastItem key={t.id} toast={t} />);\n});\n\nToastList.displayName = 'ToastList';\n\nexport interface ToastHostProps {\n className?: string;\n /**\n * Default duration for toasts\n * @default 5000\n */\n duration?: number;\n /**\n * Maximum number of toasts\n * @default 5\n */\n limit?: number;\n /**\n * Toast position\n * @default 'bottom-right'\n */\n position?: ToastPosition;\n /**\n * Root element for portal\n */\n root?: HTMLElement | ShadowRoot | null;\n /**\n * Swipe direction to dismiss\n * @default ['down', 'right']\n */\n swipeDirection?: ('left' | 'right' | 'up' | 'down') | ('left' | 'right' | 'up' | 'down')[];\n}\n\nexport const ToastHost = memo(\n ({\n root,\n className,\n duration = 5000,\n limit = 5,\n position = 'bottom-right',\n swipeDirection = ['down', 'right'],\n }: ToastHostProps) => {\n const isClient = useIsClient();\n const appElement = useAppElement();\n const [viewportZIndex, setViewportZIndex] = useState<number | undefined>(undefined);\n const hostId = useId();\n\n useEffect(() => registerToastHost(hostId), [hostId]);\n\n const isActive = useSyncExternalStore(\n subscribeToastHost,\n () => isActiveToastHost(hostId),\n () => false,\n );\n\n useEffect(() => {\n if (!isActive) return;\n globalState = {\n duration,\n limit,\n position,\n swipeDirection,\n };\n }, [duration, limit, position, swipeDirection, isActive]);\n\n useEffect(() => {\n if (!isActive) return;\n setViewportZIndex(acquireLayerZIndex('toast'));\n }, [isActive]);\n\n useEffect(() => {\n if (!isActive || !isClient) return undefined;\n // Runs after the six BaseToast.Provider children below have committed\n // and subscribed (child effects run before the parent's), so the\n // managers are guaranteed to have a live listener once this fires.\n markToastHostReady();\n return () => {\n markToastHostNotReady();\n };\n }, [isActive, isClient]);\n\n if (!isClient || !isActive) return null;\n\n const container = root ?? appElement ?? document.body;\n\n return ALL_POSITIONS.map((pos) => (\n <ToastContext key={pos} value={{ position: pos, swipeDirection }}>\n <BaseToast.Provider limit={limit} timeout={duration} toastManager={getManager(pos)}>\n <BaseToast.Portal container={container}>\n <BaseToast.Viewport\n className={cx(viewportVariants({ position: pos }), className)}\n style={{ zIndex: viewportZIndex }}\n >\n <ToastList />\n </BaseToast.Viewport>\n </BaseToast.Portal>\n </BaseToast.Provider>\n </ToastContext>\n ));\n },\n);\n\nToastHost.displayName = 'ToastHost';\n\n// Hook to use toast manager\nexport const useToast = () => toast;\n\nexport const __resetToastStateForTests = (): void => {\n globalState = {\n duration: 5000,\n limit: 5,\n position: 'bottom-right',\n swipeDirection: ['down', 'right'],\n };\n for (const position of ALL_POSITIONS) {\n toastManagers[position] = BaseToast.createToastManager();\n activeToastIds[position].clear();\n }\n __resetPendingToastQueueForTests();\n};\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,gBAAiC;CACrC;CACA;CACA;CACA;CACA;CACA;AACF;AAUA,IAAI,cAA0B;CAC5B,UAAU;CACV,OAAO;CACP,UAAU;CACV,gBAAgB,CAAC,QAAQ,OAAO;AAClC;AAGA,MAAM,gBAAwF;CAC5F,UAAUA,MAAU,mBAAmB;CACvC,eAAeA,MAAU,mBAAmB;CAC5C,gBAAgBA,MAAU,mBAAmB;CAC7C,OAAOA,MAAU,mBAAmB;CACpC,YAAYA,MAAU,mBAAmB;CACzC,aAAaA,MAAU,mBAAmB;AAC5C;AAEA,MAAM,iBAAqD;CACzD,0BAAU,IAAI,IAAI;CAClB,+BAAe,IAAI,IAAI;CACvB,gCAAgB,IAAI,IAAI;CACxB,uBAAO,IAAI,IAAI;CACf,4BAAY,IAAI,IAAI;CACpB,6BAAa,IAAI,IAAI;AACvB;AAEA,MAAM,cAAc,aAA4B,cAAc;AAE9D,IAAI,iBAAiB;AACrB,MAAM,wBACJ,SAAS,KAAK,IAA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GAAG,CAAC,UAAU,QAAQ,CAAC;CAEvB,IAAI,CAAC,YAAY,CAAC,UAAU,OAAO;CAEnC,MAAM,YAAY,QAAQ,cAAc,SAAS;CAEjD,OAAO,cAAc,KAAK,QACxB,oBAAC,cAAD;EAAwB,OAAO;GAAE,UAAU;GAAK;EAAe;EAC7D,UAAA,oBAACA,MAAU,UAAX;GAA2B;GAAO,SAAS;GAAU,cAAc,WAAW,GAAG;GAC/E,UAAA,oBAACA,MAAU,QAAX;IAA6B;IAC3B,UAAA,oBAACA,MAAU,UAAX;KACE,WAAW,GAAG,iBAAiB,EAAE,UAAU,IAAI,CAAC,GAAG,SAAS;KAC5D,OAAO,EAAE,QAAQ,eAAe;KAEhC,UAAA,oBAAC,WAAD,CAAY,CAAA;IACM,CAAA;GACJ,CAAA;EACA,CAAA;CACR,GAXK,GAWL,CACf;AACH,CACF;AAEA,UAAU,cAAc;AAGxB,MAAa,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"imperative.mjs","names":["BaseToast"],"sources":["../../../src/base-ui/Toast/imperative.tsx"],"sourcesContent":["'use client';\n\nimport { Toast as BaseToast } from '@base-ui/react/toast';\nimport { cx } from 'antd-style';\nimport { memo, useEffect, useId, useState, useSyncExternalStore } from 'react';\n\nimport { useIsClient } from '@/hooks/useIsClient';\nimport { useAppElement } from '@/ThemeProvider';\n\nimport { acquireLayerZIndex } from '../zIndex';\nimport { ToastContext } from './context';\nimport { isActiveToastHost, registerToastHost, subscribeToastHost } from './hostGuard';\nimport {\n __resetPendingToastQueueForTests,\n markToastHostNotReady,\n markToastHostReady,\n runWhenToastHostReady,\n} from './pendingQueue';\nimport { viewportVariants } from './style';\nimport ToastItem from './Toast';\nimport {\n type ToastAPI,\n type ToastInstance,\n type ToastOptions,\n type ToastPosition,\n type ToastPromiseOptions,\n type ToastType,\n} from './type';\n\n// All possible positions\nconst ALL_POSITIONS: ToastPosition[] = [\n 'top',\n 'top-left',\n 'top-right',\n 'bottom',\n 'bottom-left',\n 'bottom-right',\n];\n\n// Global state management\ninterface ToastState {\n duration: number;\n limit: number;\n position: ToastPosition;\n swipeDirection: ('left' | 'right' | 'up' | 'down') | ('left' | 'right' | 'up' | 'down')[];\n}\n\nlet globalState: ToastState = {\n duration: 5000,\n limit: 5,\n position: 'bottom-right',\n swipeDirection: ['down', 'right'],\n};\n\n// Toast managers for each position\nconst toastManagers: Record<ToastPosition, ReturnType<typeof BaseToast.createToastManager>> = {\n 'bottom': BaseToast.createToastManager(),\n 'bottom-left': BaseToast.createToastManager(),\n 'bottom-right': BaseToast.createToastManager(),\n 'top': BaseToast.createToastManager(),\n 'top-left': BaseToast.createToastManager(),\n 'top-right': BaseToast.createToastManager(),\n};\n\ninterface ActiveToast {\n superseded: boolean;\n}\n\nconst activeToasts: Record<ToastPosition, Map<string, ActiveToast>> = {\n 'bottom': new Map(),\n 'bottom-left': new Map(),\n 'bottom-right': new Map(),\n 'top': new Map(),\n 'top-left': new Map(),\n 'top-right': new Map(),\n};\n\nconst getManager = (position: ToastPosition) => toastManagers[position];\n\nlet toastIdCounter = 0;\nconst generateToastId = (): string =>\n `toast-${Date.now().toString(36)}-${(toastIdCounter++).toString(36)}`;\n\nconst findActivePosition = (id: string) => ALL_POSITIONS.find((pos) => activeToasts[pos].has(id));\n\n// Base UI prepends every new toast, so the last entry we registered is the one\n// currently rendered at the front of the stack.\nconst isFrontMost = (position: ToastPosition, id: string) =>\n Array.from(activeToasts[position].keys()).at(-1) === id;\n\nconst normalizeOptions = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n type: ToastType,\n): ToastOptions => {\n if (typeof optionsOrMessage === 'string') {\n return {\n description: optionsOrMessage,\n type,\n };\n }\n return {\n ...optionsOrMessage,\n type,\n };\n};\n\nconst createToastInstance = (id: string, position: ToastPosition): ToastInstance => ({\n close: () => runWhenToastHostReady(() => getManager(position).close(id)),\n id,\n update: (options) => {\n runWhenToastHostReady(() =>\n getManager(position).update(id, {\n data: options,\n description: options.description,\n title: options.title,\n }),\n );\n },\n});\n\n// createToastManager() is a stateless emitter (see @base-ui/react/toast/createToastManager):\n// add/close/update just broadcast to whatever is currently subscribed, and the\n// ToastProvider that owns the real toast state only subscribes from a passive\n// useEffect. Calls made while no host is ready (e.g. mid-handoff between the\n// previously-active ToastHost unmounting and its successor's Provider\n// subscribing) would otherwise be silently dropped, so every manager call is\n// routed through runWhenToastHostReady to queue until a host is listening.\nconst addToast = (options: ToastOptions): ToastInstance => {\n const position = options.placement ?? globalState.position;\n const manager = getManager(position);\n const { id: dedupeId, onClose, onRemove } = options;\n\n if (dedupeId) {\n const prevPosition = findActivePosition(dedupeId);\n // Already the front-most toast: let Base UI upsert it in place so it only\n // refreshes its content and timer, without replaying the slide-in animation.\n const shouldPromote =\n prevPosition && !(prevPosition === position && isFrontMost(position, dedupeId));\n\n if (shouldPromote) {\n // Closing marks the toast as `ending`, which makes the following `add`\n // drop it and prepend a fresh one — Base UI's own upsert keeps the\n // original slot instead.\n activeToasts[prevPosition].get(dedupeId)!.superseded = true;\n activeToasts[prevPosition].delete(dedupeId);\n runWhenToastHostReady(() => getManager(prevPosition).close(dedupeId));\n }\n }\n\n const id = dedupeId ?? generateToastId();\n const active: ActiveToast = { superseded: false };\n activeToasts[position].set(id, active);\n runWhenToastHostReady(() => {\n manager.add({\n id,\n data: options,\n description: options.description,\n onClose: () => {\n if (active.superseded) return;\n onClose?.();\n },\n onRemove: () => {\n if (active.superseded) return;\n activeToasts[position].delete(id);\n onRemove?.();\n },\n timeout: options.duration ?? globalState.duration,\n title: options.title,\n });\n });\n return createToastInstance(id, position);\n};\n\nconst dismissToast = (id?: string) => {\n if (id) {\n // Try to close from all managers since we don't know which position the toast is in\n for (const [position, manager] of Object.entries(toastManagers)) {\n activeToasts[position as ToastPosition].delete(id);\n runWhenToastHostReady(() => manager.close(id));\n }\n } else {\n // Clear all toasts\n for (const [position, manager] of Object.entries(toastManagers)) {\n const ids = Array.from(activeToasts[position as ToastPosition].keys());\n activeToasts[position as ToastPosition].clear();\n runWhenToastHostReady(() => {\n for (const toastId of ids) {\n manager.close(toastId);\n }\n });\n }\n }\n};\n\nconst createSuccessToast = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'success'));\n};\n\nconst createErrorToast = (optionsOrMessage: Omit<ToastOptions, 'type'> | string): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'error'));\n};\n\nconst createInfoToast = (optionsOrMessage: Omit<ToastOptions, 'type'> | string): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'info'));\n};\n\nconst createWarningToast = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n): ToastInstance => {\n return addToast(normalizeOptions(optionsOrMessage, 'warning'));\n};\n\nconst createLoadingToast = (\n optionsOrMessage: Omit<ToastOptions, 'type'> | string,\n): ToastInstance => {\n const options = normalizeOptions(optionsOrMessage, 'loading');\n // Loading toasts don't auto-dismiss by default\n return addToast({ duration: 0, ...options });\n};\n\nasync function promiseToast<T>(promise: Promise<T>, options: ToastPromiseOptions<T>): Promise<T> {\n const loadingOptions =\n typeof options.loading === 'string'\n ? { description: options.loading }\n : (options.loading as ToastOptions);\n\n const loadingToast = addToast({\n closable: false,\n duration: 0,\n type: 'loading',\n ...loadingOptions,\n });\n\n try {\n const result = await promise;\n\n loadingToast.close();\n\n const successOptions = (() => {\n if (typeof options.success === 'string') {\n return { description: options.success };\n }\n if (typeof options.success === 'function') {\n return { description: options.success(result) };\n }\n return options.success as ToastOptions;\n })();\n\n addToast({ type: 'success', ...successOptions });\n\n return result;\n } catch (error) {\n loadingToast.close();\n\n const errorOptions = (() => {\n if (typeof options.error === 'string') {\n return { description: options.error };\n }\n if (typeof options.error === 'function') {\n return { description: options.error(error as Error) };\n }\n return options.error as ToastOptions;\n })();\n\n addToast({ type: 'error', ...errorOptions });\n\n throw error;\n }\n}\n\n// Base toast function\nconst baseToast = (options: ToastOptions): ToastInstance => {\n return addToast({ type: 'default', ...options });\n};\n\n// Toast API\nexport const toast: ToastAPI = Object.assign(baseToast, {\n dismiss: dismissToast,\n error: createErrorToast,\n info: createInfoToast,\n loading: createLoadingToast,\n promise: promiseToast,\n success: createSuccessToast,\n warning: createWarningToast,\n});\n\n// Toast List Component\nconst ToastList = memo(() => {\n const { toasts } = BaseToast.useToastManager();\n return toasts.map((t) => <ToastItem key={t.id} toast={t} />);\n});\n\nToastList.displayName = 'ToastList';\n\nexport interface ToastHostProps {\n className?: string;\n /**\n * Default duration for toasts\n * @default 5000\n */\n duration?: number;\n /**\n * Maximum number of toasts\n * @default 5\n */\n limit?: number;\n /**\n * Toast position\n * @default 'bottom-right'\n */\n position?: ToastPosition;\n /**\n * Root element for portal\n */\n root?: HTMLElement | ShadowRoot | null;\n /**\n * Swipe direction to dismiss\n * @default ['down', 'right']\n */\n swipeDirection?: ('left' | 'right' | 'up' | 'down') | ('left' | 'right' | 'up' | 'down')[];\n}\n\nexport const ToastHost = memo(\n ({\n root,\n className,\n duration = 5000,\n limit = 5,\n position = 'bottom-right',\n swipeDirection = ['down', 'right'],\n }: ToastHostProps) => {\n const isClient = useIsClient();\n const appElement = useAppElement();\n const [viewportZIndex, setViewportZIndex] = useState<number | undefined>(undefined);\n const hostId = useId();\n\n useEffect(() => registerToastHost(hostId), [hostId]);\n\n const isActive = useSyncExternalStore(\n subscribeToastHost,\n () => isActiveToastHost(hostId),\n () => false,\n );\n\n useEffect(() => {\n if (!isActive) return;\n globalState = {\n duration,\n limit,\n position,\n swipeDirection,\n };\n }, [duration, limit, position, swipeDirection, isActive]);\n\n useEffect(() => {\n if (!isActive) return;\n setViewportZIndex(acquireLayerZIndex('toast'));\n }, [isActive]);\n\n useEffect(() => {\n if (!isActive || !isClient) return undefined;\n // Runs after the six BaseToast.Provider children below have committed\n // and subscribed (child effects run before the parent's), so the\n // managers are guaranteed to have a live listener once this fires.\n markToastHostReady();\n return () => {\n markToastHostNotReady();\n };\n }, [isActive, isClient]);\n\n if (!isClient || !isActive) return null;\n\n const container = root ?? appElement ?? document.body;\n\n return ALL_POSITIONS.map((pos) => (\n <ToastContext key={pos} value={{ position: pos, swipeDirection }}>\n <BaseToast.Provider limit={limit} timeout={duration} toastManager={getManager(pos)}>\n <BaseToast.Portal container={container}>\n <BaseToast.Viewport\n className={cx(viewportVariants({ position: pos }), className)}\n style={{ zIndex: viewportZIndex }}\n >\n <ToastList />\n </BaseToast.Viewport>\n </BaseToast.Portal>\n </BaseToast.Provider>\n </ToastContext>\n ));\n },\n);\n\nToastHost.displayName = 'ToastHost';\n\n// Hook to use toast manager\nexport const useToast = () => toast;\n\nexport const __resetToastStateForTests = (): void => {\n globalState = {\n duration: 5000,\n limit: 5,\n position: 'bottom-right',\n swipeDirection: ['down', 'right'],\n };\n for (const position of ALL_POSITIONS) {\n toastManagers[position] = BaseToast.createToastManager();\n activeToasts[position].clear();\n }\n __resetPendingToastQueueForTests();\n};\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,gBAAiC;CACrC;CACA;CACA;CACA;CACA;CACA;AACF;AAUA,IAAI,cAA0B;CAC5B,UAAU;CACV,OAAO;CACP,UAAU;CACV,gBAAgB,CAAC,QAAQ,OAAO;AAClC;AAGA,MAAM,gBAAwF;CAC5F,UAAUA,MAAU,mBAAmB;CACvC,eAAeA,MAAU,mBAAmB;CAC5C,gBAAgBA,MAAU,mBAAmB;CAC7C,OAAOA,MAAU,mBAAmB;CACpC,YAAYA,MAAU,mBAAmB;CACzC,aAAaA,MAAU,mBAAmB;AAC5C;AAMA,MAAM,eAAgE;CACpE,0BAAU,IAAI,IAAI;CAClB,+BAAe,IAAI,IAAI;CACvB,gCAAgB,IAAI,IAAI;CACxB,uBAAO,IAAI,IAAI;CACf,4BAAY,IAAI,IAAI;CACpB,6BAAa,IAAI,IAAI;AACvB;AAEA,MAAM,cAAc,aAA4B,cAAc;AAE9D,IAAI,iBAAiB;AACrB,MAAM,wBACJ,SAAS,KAAK,IAAI,CAAC,CAA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|
* Custom icon
|
|
67
67
|
*/
|
|
68
68
|
icon?: IconProps['icon'];
|
|
69
|
+
/**
|
|
70
|
+
* Stable identifier used to deduplicate toasts. Showing a toast with an id
|
|
71
|
+
* that is already visible refreshes it in place and resets its timer instead
|
|
72
|
+
* of stacking a second copy; if it is no longer the newest toast it is also
|
|
73
|
+
* moved back to the front of the stack.
|
|
74
|
+
*/
|
|
75
|
+
id?: string;
|
|
69
76
|
/**
|
|
70
77
|
* Callback when toast is closed
|
|
71
78
|
*/
|