import { Extension } from '@tiptap/core' import type { EditorView } from '@tiptap/pm/view' import { Plugin, PluginKey } from '@tiptap/pm/state' export type SmartPasteHandler = (view: EditorView, event: ClipboardEvent) => boolean export const smartPastePluginKey = new PluginKey('smartPaste') declare module '@tiptap/core' { interface Storage { smartPaste: { onPaste: SmartPasteHandler | null } } } export const SmartPasteExtension = Extension.create({ name: 'smartPaste', addStorage() { return { onPaste: null as SmartPasteHandler | null, } }, addProseMirrorPlugins() { const storage = this.storage return [ new Plugin({ key: smartPastePluginKey, props: { handlePaste(view, event) { return storage.onPaste?.(view, event) ?? false }, }, }), ] }, })