- 点选金框滑动 + 检视区 150ms 交叉淡变;↑↓/J/K 即时切换、空格播放、 Delete 删除、] 检视区、浮层让位;新记录入场/完成金光/失败抖动,减动效只余短淡变 - 单条删除 5 秒撤销(Toast 金色动作钮),窗口过后才提交 DELETE,离页 flush; 任务页同队列同步;工作流删除保留旧记录并标识「工作流已删除」 - 红/琥珀界线:失败红 + 中文结论展开;done 但文件取不到 → 琥珀「文件缺失」 + 用相同参数重做/移除记录 - 参数页提交自动切结果页;工作流选择器 ↑↓ 真高亮 + Enter 使用(ShellPop arrowRoving 开关) - 记录流 80 条分页(220 条专项:50 次轮询 490ms);任务页 §3.5 芯片+搜索+ 行内进度条+ghost 重试;i18n 七语种 +17 键 Co-authored-by: multica-agent <github@multica.ai>
101 lines
2.5 KiB
TypeScript
101 lines
2.5 KiB
TypeScript
export type ToastKind = 'success' | 'error' | 'info';
|
|
|
|
/** Inline action on a toast (§四.5: 动作金色文字,如「撤销」). */
|
|
export type ToastAction = {
|
|
label: string;
|
|
run: () => void;
|
|
};
|
|
|
|
export type Toast = {
|
|
id: number;
|
|
message: string;
|
|
kind: ToastKind;
|
|
/** Auto-dismiss delay in ms. 0 = sticky until dismissed. */
|
|
duration: number;
|
|
action?: ToastAction;
|
|
};
|
|
|
|
type Listener = (toasts: Toast[]) => void;
|
|
|
|
const DEFAULT_DURATION = 3200;
|
|
|
|
let seq = 0;
|
|
let toasts: Toast[] = [];
|
|
const listeners = new Set<Listener>();
|
|
|
|
type TimerState = {
|
|
remaining: number;
|
|
startedAt: number;
|
|
handle: ReturnType<typeof setTimeout>;
|
|
};
|
|
|
|
const timers = new Map<number, TimerState>();
|
|
|
|
function emit() {
|
|
const snapshot = [...toasts];
|
|
for (const listener of listeners) listener(snapshot);
|
|
}
|
|
|
|
export function subscribeToasts(listener: Listener): () => void {
|
|
listeners.add(listener);
|
|
listener([...toasts]);
|
|
return () => listeners.delete(listener);
|
|
}
|
|
|
|
export function dismissToast(id: number) {
|
|
const timer = timers.get(id);
|
|
if (timer) {
|
|
clearTimeout(timer.handle);
|
|
timers.delete(id);
|
|
}
|
|
toasts = toasts.filter((t) => t.id !== id);
|
|
emit();
|
|
}
|
|
|
|
function schedule(id: number, delay: number) {
|
|
timers.set(id, {
|
|
remaining: delay,
|
|
startedAt: Date.now(),
|
|
handle: setTimeout(() => dismissToast(id), delay),
|
|
});
|
|
}
|
|
|
|
export function showToast(
|
|
message: string,
|
|
kind: ToastKind = 'success',
|
|
durationMs: number = DEFAULT_DURATION,
|
|
action?: ToastAction,
|
|
) {
|
|
const id = ++seq;
|
|
toasts = [...toasts, { id, message, kind, duration: durationMs, action }];
|
|
emit();
|
|
if (durationMs > 0) schedule(id, durationMs);
|
|
return id;
|
|
}
|
|
|
|
/** Pause auto-dismiss (e.g. while the pointer or focus is on the toast). */
|
|
export function pauseToast(id: number) {
|
|
const timer = timers.get(id);
|
|
if (!timer) return;
|
|
clearTimeout(timer.handle);
|
|
timer.remaining = Math.max(0, timer.remaining - (Date.now() - timer.startedAt));
|
|
timer.startedAt = Date.now();
|
|
}
|
|
|
|
/** Resume auto-dismiss after a pause. */
|
|
export function resumeToast(id: number) {
|
|
const timer = timers.get(id);
|
|
if (!timer) return;
|
|
clearTimeout(timer.handle);
|
|
const delay = Math.max(0, timer.remaining);
|
|
timer.remaining = delay;
|
|
timer.startedAt = Date.now();
|
|
timer.handle = setTimeout(() => dismissToast(id), delay);
|
|
}
|
|
|
|
export const toast = {
|
|
success: (message: string, duration?: number) => showToast(message, 'success', duration),
|
|
error: (message: string, duration?: number) => showToast(message, 'error', duration),
|
|
info: (message: string, duration?: number) => showToast(message, 'info', duration),
|
|
};
|