From 60b24da3a83345cf5f52b5a1e84c516a8366fc8c Mon Sep 17 00:00:00 2001 From: jainiksha Date: Sun, 21 Jun 2026 01:33:02 +0530 Subject: [PATCH] feat: add notification queue and priority management --- .../widgets/src/feedback/NotificationQueue.ts | 57 +++++++++++++++++++ packages/widgets/src/index.ts | 6 ++ 2 files changed, 63 insertions(+) create mode 100644 packages/widgets/src/feedback/NotificationQueue.ts diff --git a/packages/widgets/src/feedback/NotificationQueue.ts b/packages/widgets/src/feedback/NotificationQueue.ts new file mode 100644 index 00000000..bed07d03 --- /dev/null +++ b/packages/widgets/src/feedback/NotificationQueue.ts @@ -0,0 +1,57 @@ +export type NotificationPriority = "low" | "medium" | "high"; + +export interface Notification { + id: string; + message: string; + priority?: NotificationPriority; + duration?: number; +} + +export class NotificationQueue { + private queue: Notification[] = []; + private paused = false; + + add(notification: Notification): void { + this.queue.push({ + priority: "medium", + duration: 3000, + ...notification, + }); + + this.queue.sort((a, b) => { + const order = { + high: 3, + medium: 2, + low: 1, + }; + + return order[b.priority!] - order[a.priority!]; + }); + } + + getAll(): Notification[] { + return this.queue; + } + + remove(id: string): void { + this.queue = this.queue.filter( + item => item.id !== id + ); + } + + clear(): void { + this.queue = []; + } + + pause(): void { + this.paused = true; + } + + resume(): void { + this.paused = false; + } + + isPaused(): boolean { + return this.paused; + } +} \ No newline at end of file diff --git a/packages/widgets/src/index.ts b/packages/widgets/src/index.ts index 316ba500..05b36e96 100644 --- a/packages/widgets/src/index.ts +++ b/packages/widgets/src/index.ts @@ -128,6 +128,12 @@ export { Fill } from './layout/Fill.js'; export type { FillOptions } from './layout/Fill.js'; export { SplitPane } from './layout/SplitPane.js'; export type { SplitPaneOptions } from './layout/SplitPane.js'; +export { NotificationQueue } from "./feedback/NotificationQueue.js"; + +export type { + Notification, + NotificationPriority +} from "./feedback/NotificationQueue.js"; // ── Feedback Widgets ────────────────────────────────── export { ProgressBar } from './feedback/ProgressBar.js';