import type { CommentItem } from '../comment-item' import type { CommentReplyItem } from '../reply-item' import type { CommentCallbackInput, CommentCallbackPair, CommentItemCallback } from '../types' export abstract class CommentArea { element: HTMLElement items: CommentItem[] = [] protected itemCallbacks: CommentCallbackPair[] = [] constructor(element: HTMLElement) { this.element = element } abstract observe(): void | Promise abstract disconnect(): void | Promise abstract addMenuItem( item: CommentReplyItem, config: { className: string text: string action: (e: MouseEvent) => void }, ): void | Promise static resolveCallbackPair void>( input: CommentCallbackInput, ): CommentCallbackPair { if (typeof input === 'function') { return { added: input } } return input } forEachCommentItem(input: CommentCallbackInput) { const pair = CommentArea.resolveCallbackPair(input) this.items.forEach(item => pair.added?.(item)) this.itemCallbacks.push(pair) } }