MLightCAD
    Preparing search index...

    Function useNotificationCenter

    • Composable that exposes the global notification center.

      Provides a centralized notification system similar to Visual Studio Code. All returned state is reactive; multiple callers share the same underlying list.

      Returns {
          add: (notification: Omit<Notification, "id" | "timestamp">) => string;
          clear: () => void;
          clearAll: () => void;
          error: (
              title: string,
              message?: string,
              options?: Partial<Notification>,
          ) => string;
          hasNotifications: ComputedRef<boolean>;
          info: (
              title: string,
              message?: string,
              options?: Partial<Notification>,
          ) => string;
          notifications: ComputedRef<
              {
                  actions?: { action: () => void; label: string; primary?: boolean }[];
                  fontNames?: string[];
                  id: string;
                  message?: string;
                  persistent?: boolean;
                  source?: "font-missed";
                  timeout?: number;
                  timestamp: Date;
                  title: string;
                  type: "warning" | "error" | "info" | "success";
              }[],
          >;
          remove: (id: string) => void;
          removeBySource: (source: "font-missed") => void;
          removeResolvedFontMissedNotifications: (
              missedFontNames: Iterable<string>,
          ) => void;
          removeWhere: (predicate: (notification: Notification) => boolean) => void;
          success: (
              title: string,
              message?: string,
              options?: Partial<Notification>,
          ) => string;
          unreadCount: ComputedRef<number>;
          warning: (
              title: string,
              message?: string,
              options?: Partial<Notification>,
          ) => string;
      }

      Notification management functions and reactive state.

      • add: (notification: Omit<Notification, "id" | "timestamp">) => string

        Creates and prepends a custom notification. Returns the new notification ID.

      • clear: () => void

        Removes all notifications from the center.

      • clearAll: () => void
      • error: (title: string, message?: string, options?: Partial<Notification>) => string

        Adds an error notification (persistent by default). Returns the new notification ID.

      • hasNotifications: ComputedRef<boolean>

        Reactive boolean; true when at least one notification exists.

      • info: (title: string, message?: string, options?: Partial<Notification>) => string

        Adds an informational notification. Returns the new notification ID.

      • notifications: ComputedRef<
            {
                actions?: { action: () => void; label: string; primary?: boolean }[];
                fontNames?: string[];
                id: string;
                message?: string;
                persistent?: boolean;
                source?: "font-missed";
                timeout?: number;
                timestamp: Date;
                title: string;
                type: "warning" | "error" | "info" | "success";
            }[],
        >

        Reactive list of all notifications, ordered newest first.

      • remove: (id: string) => void

        Removes a notification by ID. No-op if the ID is not found.

      • removeBySource: (source: "font-missed") => void

        Removes all notifications tagged with the given NotificationSource.

      • removeResolvedFontMissedNotifications: (missedFontNames: Iterable<string>) => void

        Removes resolved font-missed notifications based on the current missed-font set.

      • removeWhere: (predicate: (notification: Notification) => boolean) => void

        Removes notifications for which the predicate returns true.

      • success: (title: string, message?: string, options?: Partial<Notification>) => string

        Adds a success notification. Returns the new notification ID.

      • unreadCount: ComputedRef<number>

        Reactive count of active notifications.

      • warning: (title: string, message?: string, options?: Partial<Notification>) => string

        Adds a warning notification. Returns the new notification ID.

      import { useNotificationCenter } from '@mlightcad/cad-viewer'

      const { info, warning, error, success, notifications, unreadCount } = useNotificationCenter()

      // Add different types of notifications
      info('Information', 'This is an info message')
      warning('Warning', 'This is a warning message')
      error('Error', 'This is an error message')
      success('Success', 'This is a success message')

      // Add notification with actions
      error('File Error', 'Failed to load file', {
      actions: [
      { label: 'Retry', action: () => retryLoad(), primary: true },
      { label: 'Cancel', action: () => cancel() }
      ],
      persistent: true
      })

      // Check notification count
      console.log(`You have ${unreadCount.value} notifications`)