25 lines
1006 B
TypeScript
25 lines
1006 B
TypeScript
import type { Note } from '@/lib/types'
|
|
|
|
export const NOTE_CHANGE_EVENT = 'memento-note-changed'
|
|
export const NOTE_REQUEST_SAVE_EVENT = 'memento-request-note-save'
|
|
|
|
export type NoteChangeEvent =
|
|
| { type: 'updated'; note: Note }
|
|
| { type: 'deleted'; noteId: string; notebookId?: string | null }
|
|
| { type: 'created'; note: Note }
|
|
|
|
export type NoteCollectionActions = {
|
|
onTogglePin?: (note: Note) => void | Promise<void>
|
|
onDeleteNote?: (note: Note) => void | Promise<void>
|
|
onArchiveNote?: (note: Note) => void | Promise<void>
|
|
onMoveToNotebook?: (note: Note, notebookId: string | null) => void | Promise<void>
|
|
onNotePatch?: (noteId: string, patch: Partial<Note>) => void
|
|
onNoteIllustrationGenerated?: (noteId: string) => void | Promise<void>
|
|
onNoteIllustrationDeleted?: (noteId: string) => void | Promise<void>
|
|
}
|
|
|
|
export function emitNoteChange(detail: NoteChangeEvent) {
|
|
if (typeof window === 'undefined') return
|
|
window.dispatchEvent(new CustomEvent(NOTE_CHANGE_EVENT, { detail }))
|
|
}
|