import { Editor, Node, mergeAttributes, type CommandProps, type NodeViewProps } from '@tiptap/core' import type { Component } from 'svelte' import { SvelteNodeViewRenderer } from 'svelte-tiptap' export interface GalleryPlaceholderOptions { HTMLAttributes: Record onSelectImages: (images: any[], editor: Editor) => void } declare module '@tiptap/core' { interface Commands { galleryPlaceholder: { /** * Inserts a gallery placeholder */ insertGalleryPlaceholder: () => ReturnType } } } export const GalleryPlaceholder = ( component: Component ): Node => Node.create({ name: 'gallery-placeholder', addOptions() { return { HTMLAttributes: {}, onSelectImages: () => {} } }, parseHTML() { return [{ tag: `div[data-type="${this.name}"]` }] }, renderHTML({ HTMLAttributes }) { return ['div', mergeAttributes(HTMLAttributes)] }, group: 'block', draggable: true, atom: true, content: 'inline*', isolating: true, addNodeView() { return SvelteNodeViewRenderer(component) }, addCommands() { return { insertGalleryPlaceholder: () => (props: CommandProps) => { return props.commands.insertContent({ type: 'gallery-placeholder' }) } } } })