import { Mark, mergeAttributes } from '@tiptap/core'; import type { SuggestionMarkAttrs } from '../types.js'; interface SuggestionDeleteOptions { HTMLAttributes: Record; } /** * Suggestion Delete mark — tracks suggested deletions. * Rendered as strikethrough text with author color. */ export const SuggestionDelete = Mark.create({ name: 'suggestionDelete', addOptions() { return { HTMLAttributes: {}, }; }, addAttributes() { return { suggestionId: { default: null, parseHTML: (el: HTMLElement) => el.getAttribute('data-suggestion-id'), renderHTML: (attrs: Record) => ({ 'data-suggestion-id': attrs.suggestionId }), }, author: { default: null, parseHTML: (el: HTMLElement) => el.getAttribute('data-suggestion-author'), renderHTML: (attrs: Record) => ({ 'data-suggestion-author': attrs.author }), }, timestamp: { default: null, parseHTML: (el: HTMLElement) => el.getAttribute('data-suggestion-timestamp'), renderHTML: (attrs: Record) => ({ 'data-suggestion-timestamp': attrs.timestamp }), }, }; }, parseHTML() { return [ { tag: 'span[data-suggestion-id][data-suggestion-type="delete"]' }, { tag: 'span.suggestion-delete' }, ]; }, renderHTML({ HTMLAttributes }) { return [ 'span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { class: 'suggestion-delete', 'data-suggestion-type': 'delete', }), 0, ]; }, addCommands() { return { setSuggestionDelete: (attrs: SuggestionMarkAttrs) => ({ commands }) => { return commands.setMark(this.name, attrs); }, unsetSuggestionDelete: () => ({ commands }) => { return commands.unsetMark(this.name); }, }; }, });