19 lines
1.1 KiB
TypeScript
19 lines
1.1 KiB
TypeScript
/**
|
|
* 应用层Sonner通知适配。领域/editor包不依赖具体toast库,宿主在收到状态后选择调用此模块。
|
|
* use client界定通知只在客户端使用,函数不修改画布任务事实。
|
|
*/
|
|
"use client";
|
|
|
|
import { toast } from "sonner";
|
|
|
|
/** Application adapter. Domain/editor packages must not import Sonner. */
|
|
/** 稳定id用于更新/关闭同一通知,level决定显示样式,description是可选补充文案。
|
|
* level 的联合类型是调用约束,运行时不另行验证;调用方必须提供通知库支持的级别。 */
|
|
export type Notification = { id: string; title: string; description?: string; level?: "info" | "success" | "warning" | "error" };
|
|
/** 按指定level调用Sonner,默认info;相同id的合并/更新行为交给通知库。 */
|
|
export function notify({ id, title, description, level = "info" }: Notification) {
|
|
return toast[level](title, { id, description });
|
|
}
|
|
/** 按id关闭通知,不表示对应业务任务已取消或错误已恢复。 */
|
|
export function dismissNotification(id: string) { toast.dismiss(id); }
|