1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { Mark, mergeAttributes } from "@tiptap/core";
- export interface TooltipOptions {
- HTMLAttributes: Record<string, any>;
- }
- declare module "@tiptap/core" {
- interface Commands<ReturnType> {
- 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<TooltipOptions>({
- 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 });
- }
- };
- }
- });
|