import { Mark, mergeAttributes } from "@tiptap/core"; export interface TooltipOptions { HTMLAttributes: Record; } declare module "@tiptap/core" { interface Commands { tooltip: { /** * Set a link mark */ setTooltip: (attributes: { "data-title": string, "data-text": string }) => ReturnType; /** * Toggle a link mark */ toggleTooltip: (attributes: { "data-title": string, "data-text": string }) => ReturnType; /** * Unset a link mark */ unsetTooltip: () => ReturnType; }; } } export default Mark.create({ name: "tooltip", priority: 1000, inclusive: false, defaultOptions: { HTMLAttributes: { class: "tooltip", target: "_blank" } }, addAttributes() { return { "data-title": { default: "" }, "data-text": { default: "" } }; }, parseHTML() { return [ { tag: "span", class: "tooltip" } ]; }, renderHTML({ HTMLAttributes }) { return [ "span", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0 ]; }, addCommands() { return { setTooltip: attributes => ({ commands }) => { return commands.setMark("tooltip", attributes); }, toggleTooltip: attributes => ({ commands }) => { return commands.toggleMark("tooltip", attributes, { extendEmptyMarkRange: true }); }, unsetTooltip: () => ({ commands }) => { return commands.unsetMark("tooltip", { extendEmptyMarkRange: true }); } }; } });