UNPKG

tiptap-link-card

Version:

Link Card Block for TipTap Editor

59 lines (58 loc) 1.98 kB
import { Node } from "@tiptap/core"; export type SetLinkCardOptions = { href: string; title: string; description?: string; imageSrc?: string; }; export interface LinkCardOptions { /** * Controls if the link card should open on click. * @default true * @example false */ openOnClick: boolean; /** * Controls if the paste handler for any url should be added. * @default false * @example true */ linkOnPaste: boolean; /** * HTML attributes to add to the link element. * @default {} * @example { class: 'foo' } */ HTMLAttributes: Record<string, any>; /** * Resolves the link card data from a URL. * @param url The URL to resolve. * @description This function is used to resolve the link card data from a URL. * It should return a promise that resolves to an object containing the link card attributes. * @returns A promise that resolves to an object containing the link card attributes. */ dataResolver?: (url: string) => Promise<SetLinkCardOptions>; } type LinkCardCommand<ReturnType> = { /** * Insert a link card * @param options The link card attributes * @example editor.commands.setLinkCard({ href: 'https://example.com', title: 'Example', description: 'An example link', imageSrc: 'https://example.com/image.png' }) */ setLinkCard: (options: SetLinkCardOptions) => ReturnType; /** * Set the link card URL, data will be resolved using the `dataResolver` function if provided. * @param url The URL to set * @example editor.commands.setLinkCardUrl('https://example.com') */ setLinkCardUrl: (url: string) => ReturnType; }; declare module "@tiptap/core" { interface Commands<ReturnType> { linkCard: LinkCardCommand<ReturnType>; } } export declare const pasteRegex: RegExp; declare const LinkCard: Node<LinkCardOptions, any>; export { LinkCard }; export default LinkCard;