UNPKG

@blinkk/editor

Version:

Structured content editor with live previews.

133 lines (132 loc) 5.12 kB
import { BasePart, Part } from '.'; import { DialogModal } from '../ui/modal'; import { TemplateResult } from '@blinkk/selective-edit'; import { LiveEditor } from '../editor'; export declare enum NotificationLevel { Debug = 0, Info = 1, Warning = 2, Error = 3 } /** * Announcements can define actions that are available to the user. * These will appear as options for when the user views the notification * such as in a toast, a modal window, or the notifications view. * * For security cannot provide a callback, instead triggers a * custom event that contains additional details. */ export interface NotificationAction { /** * Action label. */ label: string; /** * Custom event to dispatch. */ customEvent: string; /** * Details to send along with the custom event. */ details?: Record<string, any>; } /** * When events or actions take place in the editor notifications * can be displayed to the user, often as a toast or for more * serious issues a modal window. * * Notifications are also stored temporarily for easy review of * recent notifications. */ export interface EditorNotification { /** * Actions that can be taken based on the notification. */ actions?: Array<NotificationAction>; /** * Additional details that the user needs to know or possible * resolutions to an issue. */ description?: string; /** * The level of priority to give the message. Lower priority * messages will be quickly displayed then disappear (like a toast). * Higher priority messages will display a modal to ensure it is * viewed. */ level?: NotificationLevel; /** * Message to display to the user. */ message: string; /** * Title to use in the modal title when viewing individual * notifications. */ title?: string; } /** * Used to track notification state in the notification part. */ interface InternalNotification extends EditorNotification { /** * Date the notification was added. */ addedOn?: Date; /** * Is the notification expanded? */ isExpanded?: boolean; /** * Has the notification been read by the user? */ isRead?: boolean; /** * Some sub-notification types have addition properties. */ [x: string]: any; } /** * Modals are centralized in the display to be outside of other * modals and structures. Modal windows live as siblings in the * DOM. * * This helps to prevent issues where one modal is clipping * another without having to pass the modal through the template * stack to be outside of another modal. * * This also allows reuse of modals across parts of the editor. */ export declare class NotificationsPart extends BasePart implements Part { protected notifications: Set<InternalNotification>; protected hasNewError: boolean; protected currentNotification?: InternalNotification; constructor(); addDebug(notification: EditorNotification): void; addError(notification: EditorNotification, isDisplayed?: boolean): void; addInfo(notification: EditorNotification): void; addNotification(notification: EditorNotification, defaultLevel?: NotificationLevel, isDisplayed?: boolean): void; addWarning(notification: EditorNotification): void; classesForNotification(notification: InternalNotification): Record<string, boolean>; classesForPart(): Record<string, boolean>; protected getOrCreateModalNotificationSingle(editor: LiveEditor): DialogModal; protected getOrCreateModalNotifications(editor: LiveEditor): DialogModal; getIconForNotificationLevel(level: NotificationLevel, isRead: boolean): "notifications" | "notification_important" | "notifications_active"; get hasUnreadNotifications(): boolean; hasUnreadNotificationsAtLevel(level: NotificationLevel): boolean; markAllAsRead(): void; readNotification(notification: EditorNotification, defaultLevel?: NotificationLevel): void; protected scrubNewNotification(notification: EditorNotification, defaultLevel: NotificationLevel): InternalNotification; showNotification(notification: EditorNotification, defaultLevel?: NotificationLevel): void; template(editor: LiveEditor): TemplateResult; templateNotification(editor: LiveEditor, notification: InternalNotification): TemplateResult; templateNotificationActions(editor: LiveEditor, notification: InternalNotification): TemplateResult; templateNotificationDescription(editor: LiveEditor, notification: InternalNotification): TemplateResult; templateNotificationMeta(editor: LiveEditor, notification: InternalNotification): TemplateResult; templateNotificationSingle(editor: LiveEditor): TemplateResult; templateNotifications(editor: LiveEditor): TemplateResult; } export declare function announceNotification(notification: EditorNotification): void; export declare function readNotification(notification: EditorNotification): void; export declare function showNotification(notification: EditorNotification): void; export {};