Repository: ueberdosis/tiptap
File: packages/extension-link/src/link.ts (TypeScript)

Code before:
   * If enabled, links will be opened on click.
   * @default true
   * @example false
   */
  openOnClick: boolean | DeprecatedOpenWhenNotEditable
  /**
   * Adds a link to the current selection if the pasted content only contains an url.
   * @default true
   * @example false
   */
  linkOnPaste: boolean

  /**
   * HTML attributes to add to the link element.
   * @default {}
   * @example { class: 'foo' }
   */
  HTMLAttributes: Record<string, any>

  /**
   * A validation function that modifies link verification for the auto linker.
   * @param url - The url to be validated.
   * @param ctx - An object containing:
   *              - `defaultValidate`: A function that performs the default URL validation.
   *              - `protocols`: An array of allowed protocols for the URL (e.g., "http", "https").
   *              - `defaultProtocol`: A string that represents the default protocol (e.g. 'http')
   * @returns - True if the url is valid, false otherwise.
   */
  validate: (url: string, ctx: { defaultValidate: (url: string) => boolean, protocols: Array<LinkProtocolOptions | string>, defaultProtocol: string }) => boolean

  /**
   * Determines whether a valid link should be automatically linked in the content.
   *
   * @param url - The URL that has already been validated.
   * @returns - True if the link should be auto-linked; false if it should not be auto-linked.
   */
  shouldAutoLink: (url: string) => boolean
}

declare module '@tiptap/core' {
  interface Commands<ReturnType> {
    link: {
      /**
       * Set a link mark
       * @param attributes The link attributes
       * @example editor.commands.setLink({ href: 'https://tiptap.dev' })
       */
      setLink: (attributes: { href: string; target?: string | null; rel?: string | null; class?: string | null }) => ReturnType
      /**
       * Toggle a link mark
       * @param attributes The link attributes

Review comment (suggestion):
You can do jsdoc on each value like this:

```
{
/** comment **/
defaultValidate: (url: string) => boolean;
/** another **/
protocols: Array<LinkProtocolOptions | string>;
/** and again **/
defaultProtocol: string
}
```

This allows typescript to show you what each key of that object does

Code after:
   * If enabled, links will be opened on click.
   * @default true
   * @example false
   */
  openOnClick: boolean | DeprecatedOpenWhenNotEditable
  /**
   * Adds a link to the current selection if the pasted content only contains an url.
   * @default true
   * @example false
   */
  linkOnPaste: boolean

  /**
   * HTML attributes to add to the link element.
   * @default {}
   * @example { class: 'foo' }
   */
  HTMLAttributes: Record<string, any>

  /**
   * A validation function that modifies link verification.
   *
   * @param {string} url - The URL to be validated.
   * @param {Object} ctx - An object containing:
   * @param {Function} ctx.defaultValidate - A function that performs the default URL validation.
   * @param {string[]} ctx.protocols - An array of allowed protocols for the URL (e.g., "http", "https").
   * @param {string} ctx.defaultProtocol - A string that represents the default protocol (e.g., 'http').
   *
   * @returns {boolean} True if the URL is valid, false otherwise.
   */
  validate: (url: string, ctx: { defaultValidate: (url: string) => boolean, protocols: Array<LinkProtocolOptions | string>, defaultProtocol: string }) => boolean

  /**
   * Determines whether a valid link should be automatically linked in the content.
   *
   * @param {string} url - The URL that has already been validated.
   * @returns {boolean} - True if the link should be auto-linked; false if it should not be auto-linked.
   */
  shouldAutoLink: (url: string) => boolean
}

declare module '@tiptap/core' {
  interface Commands<ReturnType> {
    link: {
      /**
       * Set a link mark
       * @param attributes The link attributes
       * @example editor.commands.setLink({ href: 'https://tiptap.dev' })
       */
      setLink: (attributes: { href: string; target?: string | null; rel?: string | null; class?: string | null }) => ReturnType
      /**