{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "link-docs",
  "title": "Link",
  "description": "Documentation for Link",
  "files": [
    {
      "path": "../../content/docs/(plugins)/(elements)/link.mdx",
      "content": "---\ntitle: Link\ndocs:\n  - route: https://pro.platejs.org/docs/examples/link\n    title: Plus\n  - route: /docs/components/link-node\n    title: Link Element\n  - route: /docs/components/link-toolbar\n    title: Link Floating Toolbar\n  - route: /docs/components/link-toolbar-button\n    title: Link Toolbar Button\n---\n\n<ComponentPreview name=\"link-demo\" />\n\n<PackageInfo>\n\n## Features\n\n- Insert, edit, and remove hyperlinks.\n- Markdown shortcut: type `[text](url)` and close with `)` to turn it into a link.\n- Plain URL autolink: paste a URL, or type a URL then press space or `Enter`.\n\n</PackageInfo>\n\n## Kit Usage\n\n<Steps>\n\n### Installation\n\nThe fastest way to add link functionality is with the `LinkKit`, which includes pre-configured `LinkPlugin` with floating toolbar, autolink rules, and [Plate UI](/docs/installation/plate-ui) components.\n\n<ComponentSource name=\"link-kit\" />\n\n- [`LinkElement`](/docs/components/link-node): Renders link elements.\n- [`LinkFloatingToolbar`](/docs/components/link-toolbar): Provides floating toolbar for link editing.\n\n### Add Kit\n\nAdd the kit to your plugins:\n\n```tsx\nimport { createPlateEditor } from 'platejs/react';\nimport { LinkKit } from '@/components/editor/plugins/link-kit';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    ...LinkKit,\n  ],\n});\n```\n\n</Steps>\n\n## Manual Usage\n\n<Steps>\n\n### Installation\n\n```bash\nnpm install @platejs/link\n```\n\n### Add Plugin\n\nInclude `LinkPlugin` in your Plate plugins array when creating the editor.\n\n```tsx\nimport { LinkRules } from '@platejs/link';\nimport { LinkPlugin } from '@platejs/link/react';\nimport { createPlateEditor } from 'platejs/react';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    LinkPlugin,\n  ],\n});\n```\n\n### Configure Plugin\n\nConfigure the plugin with floating toolbar and custom components.\n\n```tsx\nimport { LinkPlugin } from '@platejs/link/react';\nimport { createPlateEditor } from 'platejs/react';\nimport { LinkElement } from '@/components/ui/link-node';\nimport { LinkFloatingToolbar } from '@/components/ui/link-toolbar';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    LinkPlugin.configure({\n      render: {\n        node: LinkElement,\n        afterEditable: () => <LinkFloatingToolbar />,\n      },\n    }),\n  ],\n});\n```\n\n- `render.afterEditable`: Renders [`LinkFloatingToolbar`](/docs/components/link-toolbar) after the editable area for link editing.\n- `render.node`: Assigns [`LinkElement`](/docs/components/link-node) to render link elements.\n\n### Input Rules\n\nConfigure `LinkPlugin` to enable the built-in link input presets:\n\n```tsx\nimport { LinkPlugin } from '@platejs/link/react';\n\nconst editor = createPlateEditor({\n  plugins: [\n    LinkPlugin.configure({\n      inputRules: [\n        LinkRules.markdown(),\n        LinkRules.autolink({ variant: 'paste' }),\n        LinkRules.autolink({ variant: 'space' }),\n        LinkRules.autolink({ variant: 'break' }),\n      ],\n    }),\n  ],\n});\n```\n\n- `LinkRules.autolink({ variant: 'paste' | 'space' | 'break' })`: Enables plain URL autolink.\n- `LinkRules.markdown()`: Enables `[text](url)` source-entry conversion on the closing `)`.\n\n### Add Toolbar Button\n\nYou can add [`LinkToolbarButton`](/docs/components/link-toolbar-button) to your [Toolbar](/docs/toolbar) to insert and edit links.\n\n</Steps>\n\n## Keyboard Shortcuts\n\n<KeyTable>\n  <KeyTableItem hotkey=\"Cmd + K\">Add a link on the selected text.</KeyTableItem>\n</KeyTable>\n\n## Plate Plus\n\n<ComponentPreviewPro name=\"link-pro\" />\n\n## Plugins\n\n### `LinkPlugin`\n\nPlugin for link formatting.\n\n<API name=\"LinkPlugin\">\n<APIOptions type=\"object\">\n<APIItem name=\"forceSubmit\" type=\"boolean\" optional>\nDetermines whether to force the submission of the link form.\n</APIItem>\n<APIItem name=\"rangeBeforeOptions\" type=\"RangeBeforeOptions\" optional>\nAllows custom configurations for rangeBeforeOptions.\n- **Default:**\n```ts\n{\n  matchString: ' ',\n  skipInvalid: true,\n  afterMatch: true,\n}\n```\n</APIItem>\n<APIItem name=\"triggerFloatingLinkHotkeys\" type=\"string | string[]\" optional>\nHotkeys to trigger floating link.\n- **Default:** **`'meta+k, ctrl+k'`**\n</APIItem>\n<APIItem name=\"allowedSchemes\" type=\"string[]\" optional>\nList of allowed URL schemes.\n- **Default:** **`['http', 'https', 'mailto', 'tel']`**\n</APIItem>\n<APIItem name=\"dangerouslySkipSanitization\" type=\"boolean\" optional>\nDetermines whether the sanitation of links should be skipped.\n- **Default:** **`false`**\n</APIItem>\n<APIItem name=\"defaultLinkAttributes\" type=\"AnchorHTMLAttributes&lt;HTMLAnchorElement&gt;\" optional>\nDefault HTML attributes for link elements.\n- **Default:** **`{}`**\n</APIItem>\n<APIItem name=\"keepSelectedTextOnPaste\" type=\"boolean\" optional>\nKeeps selected text on pasting links by default.\n- **Default:** **`true`**\n</APIItem>\n<APIItem name=\"isUrl\" type=\"(text: string) => boolean\" optional>\nCallback function to validate a URL.\n- **Default:** **`isUrl`**\n</APIItem>\n<APIItem name=\"getUrlHref\" type=\"(url: string) => string | undefined\" optional>\nCallback function to optionally get the href for a URL. It returns an optional link that is different from the text content. For example, returns `https://google.com` for `google.com`.\n</APIItem>\n<APIItem name=\"transformInput\" type=\"(url: string | null) => string | undefined\" optional>\nCallback function to optionally transform the submitted URL provided by the user to the URL input before validation.\n</APIItem>\n<APIItem name=\"getLinkUrl\" type=\"(prevUrl: string | null) => Promise<string | null>\" optional>\nOn keyboard shortcut or toolbar mousedown, this function is called to get the link URL. The default behavior is to use the browser's native `prompt`.\n</APIItem>\n</APIOptions>\n</API>\n\n## Transforms\n\n### `tf.insert.link`\n\nInserts a link node into the editor.\n\n<API name=\"insert.link\">\n<APIParameters>\n  <APIItem name=\"options\" type=\"object\">\n    Options for inserting the link.\n  </APIItem>\n</APIParameters>\n<APIOptions type=\"InsertLinkOptions\">\n  <APIItem name=\"createLinkNodeOptions\" type=\"CreateLinkNodeOptions\">\n    Options for creating the link node.\n  </APIItem>\n  <APIItem name=\"insertOptions\" type=\"InsertNodesOptions\" optional>\n    Additional options for inserting nodes.\n  </APIItem>\n </APIOptions>\n</API>\n\n## API\n\n### `api.floatingLink.hide`\n\nHides the floating link and resets its state.\n\n### `api.floatingLink.reset`\n\nResets the floating link state without changing the openEditorId.\n\n### `api.floatingLink.show`\n\nShows the floating link for the specified mode and editor ID.\n\n<API name=\"floatingLink.show\">\n<APIParameters>\n<APIItem name=\"mode\" type=\"FloatingLinkMode\">\nThe mode to set for the floating link ('edit' or 'insert').\n</APIItem>\n<APIItem name=\"editorId\" type=\"string\">\nThe ID of the editor where the floating link should be shown.\n</APIItem>\n</APIParameters>\n</API>\n\n### `api.link.getAttributes`\n\nGets the attributes for a link element.\n\n<API name=\"link.getAttributes\">\n<APIParameters>\n<APIItem name=\"element\" type=\"TLinkElement\">\nThe link element for which to get attributes.\n</APIItem>\n</APIParameters>\n\n<APIReturns type=\"React.AnchorHTMLAttributes<HTMLAnchorElement>\">\nThe HTML attributes for the link element.\n</APIReturns>\n</API>\n\n### `api.link.submitFloatingLink`\n\nInserts a link if the URL is valid, closes the floating link, and focuses the editor.\n\n<APIReturns type=\"boolean\">\nReturns `true` if the link was inserted successfully.\n</APIReturns>\n\n### `insertLink`\n\nInserts a link node into the editor.\n\n<API name=\"insertLink\">\n<APIParameters>\n  <APIItem name=\"createLinkNodeOptions\" type=\"CreateLinkNodeOptions\">\n    Options for creating link node.\n  </APIItem>\n  <APIItem name=\"options\" type=\"InsertNodesOptions\" optional>\n    Additional options for node insertion.\n  </APIItem>\n</APIParameters>\n</API>\n\n### `submitFloatingLink`\n\nInserts a link if the URL is valid, closes the floating link, and focuses the editor.\n\n- Insert link if url is valid.\n- Text is url if empty.\n- Close floating link.\n- Focus editor.\n\n<API name=\"submitFloatingLink\">\n<APIReturns type=\"boolean\">\nReturns `true` if the link was inserted.\n</APIReturns>\n</API>\n\n### `triggerFloatingLink`\n\nTriggers the floating link.\n\n<API name=\"triggerFloatingLink\">\n<APIOptions type=\"object\">\n<APIItem name=\"focused\" type=\"boolean\" optional>\n  Whether the floating link should be focused.\n</APIItem>\n</APIOptions>\n</API>\n\n### `triggerFloatingLinkEdit`\n\nTriggers the floating link edit.\n\n<API name=\"triggerFloatingLinkEdit\">\n<APIReturns type=\"boolean\">\nReturns `true` if the link was edited.\n</APIReturns>\n</API>\n\n### `triggerFloatingLinkInsert`\n\nTrigger floating link. Do not trigger when:\n- Selection is across blocks\n- Selection has more than one leaf node\n- Lowest selection is not text\n- Selection has a link node\n\n<API name=\"triggerFloatingLinkInsert\">\n<APIOptions type=\"TriggerFloatingLinkOptions\">\n  <APIItem name=\"focused\" type=\"boolean\" optional>\n    Whether the floating link should be focused.\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"boolean\">\n  Returns `true` if the link was inserted.\n</APIReturns>\n</API>\n\n### `unwrapLink`\n\nUnwraps a link node.\n\n<API name=\"unwrapLink\">\n<APIOptions type=\"UnwrapLinkOptions\">\n  <APIItem name=\"split\" type=\"boolean\" optional>\n    If `true`, split the nodes if the selection is inside the link.\n  </APIItem>\n</APIOptions>\n</API>\n\n### `upsertLink`\n\nInsert or update a link node. The behavior depends on the current selection and options:\n\n- If selection is in a link or not a URL:\n  - With `insertTextInLink: true`, inserts URL as text in link\n  - Otherwise, if `text` is empty, sets it to URL\n  - Validates URL unless `skipValidation: true`\n- If selection is expanded or `update: true` in a link:\n  - Removes link node and gets link text\n- Then:\n  - Inserts link node with updated URL and target\n  - If `text` is provided, replaces link text\n\n<API name=\"upsertLink\">\n<APIParameters>\n  <APIItem name=\"options\" type=\"UpsertLinkOptions\">\n    Options for upserting the link.\n  </APIItem>\n</APIParameters>\n\n<APIOptions type=\"UpsertLinkOptions\">\n  <APIItem name=\"url\" type=\"string\">\n    The URL of the link.\n  </APIItem>\n  <APIItem name=\"text\" type=\"string\" optional>\n    The text content of the link.\n  </APIItem>\n  <APIItem name=\"target\" type=\"string\" optional>\n    The target attribute of the link.\n  </APIItem>\n  <APIItem name=\"insertTextInLink\" type=\"boolean\" optional>\n    If `true`, insert the URL as text in the link.\n  </APIItem>\n  <APIItem name=\"insertNodesOptions\" type=\"InsertNodesOptions\" optional>\n    The options for inserting nodes.\n  </APIItem>\n  <APIItem name=\"skipValidation\" type=\"boolean\" optional>\n    If `true`, skips URL validation.\n    - **Default:** `false`\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"boolean\">\n  Returns `true` if the link was inserted or updated.\n</APIReturns>\n</API>\n\n### `upsertLinkText`\n\nIf the text is different from the link above text, replaces the link children with a new text node. The new text node has the same marks as the first text node in the link.\n\n<API name=\"upsertLinkText\">\n<APIOptions type=\"UpsertLinkTextOptions\">\n      <APIItem name=\"text\" type=\"string\" optional>\n        The new text to replace the link children with.\n      </APIItem>\n</APIOptions>\n</API>\n\n### `validateUrl`\n\nValidates a URL based on the plugin options.\n\n<API name=\"validateUrl\">\n<APIOptions type=\"ValidateUrlOptions\">\n  <APIItem name=\"url\" type=\"string\">\n    The URL to validate.\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"boolean\">\n  Returns `true` if the URL is valid.\n</APIReturns>\n</API>\n\n### `wrapLink`\n\nWrap a link node with split.\n\n<API name=\"wrapLink\">\n<APIOptions type=\"WrapLinkOptions\">\n  <APIItem name=\"url\" type=\"string\">\n    The URL of the link.\n  </APIItem>\n  <APIItem name=\"target\" type=\"string\" optional>\n    The target attribute of the link.\n  </APIItem>\n</APIOptions>\n</API>\n\n### `CreateLinkNodeOptions`\n\nOptions for creating a new link node.\n\n<API name=\"CreateLinkNodeOptions\">\n<APIOptions type=\"object\">\n  <APIItem name=\"url\" type=\"string\">\n    The URL of the link node that is being created.\n  </APIItem>\n  <APIItem name=\"text\" type=\"string\" optional>\n    The text that is displayed for the link node. If not provided, the URL is used as the display text.\n  </APIItem>\n  <APIItem name=\"target\" type=\"string\" optional>\n    Specifies where to open the URL:\n    - `_blank`: new tab\n    - `_self`: same frame\n    - `_parent`: parent frame\n    - `_top`: full window\n  </APIItem>\n  <APIItem name=\"children\" type=\"TText[]\" optional>\n    An array of text nodes that represent the link content.\n  </APIItem>\n</APIOptions>\n</API>\n\n## API Components\n\n### `FloatingLinkNewTabInput`\n\nThe input component for controlling whether a link opens in a new tab.\n\n<API name=\"FloatingLinkNewTabInput\">\n<APIState>\n  <APIItem name=\"checked\" type=\"boolean\">\n    Whether the link should open in a new tab.\n  </APIItem>\n  <APIItem name=\"setChecked\" type=\"React.Dispatch<React.SetStateAction<boolean>>\">\n    Function to update the checked state.\n  </APIItem>\n  <APIItem name=\"ref\" type=\"RefObject<HTMLInputElement>\">\n    Reference to the input element.\n  </APIItem>\n</APIState>\n</API>\n\n### `FloatingLinkUrlInput`\n\nThe input component for entering and editing link URLs.\n\n<API name=\"FloatingLinkUrlInput\">\n<APIState>\n  <APIItem name=\"ref\" type=\"RefObject<HTMLInputElement>\">\n    Reference to the input element.\n  </APIItem>\n</APIState>\n</API>\n\n### `LinkOpenButton`\n\nThe button component for opening the link URL.\n\n<API name=\"LinkOpenButton\">\n<APIState>\n  <APIItem name=\"element\" type=\"TLinkElement\">\n    The link element containing the URL to open.\n  </APIItem>\n</APIState>\n</API>\n\n### `useFloatingLinkEdit`\n\nThe behavior hook for the floating link edit functionality.\n\n<API name=\"useFloatingLinkEdit\">\n<APIState>\n  <APIItem name=\"floating\" type=\"object\" optional>\n    The virtual floating returned object.\n  </APIItem>\n</APIState>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"ref\" type=\"function\">\n    The ref callback for the floating element.\n  </APIItem>\n  <APIItem name=\"props\" type=\"object\">\n    Props for the floating element.\n    <APISubList>\n      <APISubListItem parent=\"props\" name=\"style\" type=\"object\">\n        The style of the floating link.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n  <APIItem name=\"editButtonProps\" type=\"object\">\n    Props for the edit button.\n    <APISubList>\n      <APISubListItem parent=\"editButtonProps\" name=\"onClick\" type=\"function\">\n        The function to call when the edit button is clicked.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n  <APIItem name=\"unlinkButtonProps\" type=\"object\">\n    Props for the unlink button.\n    <APISubList>\n      <APISubListItem parent=\"unlinkButtonProps\" name=\"onClick\" type=\"function\">\n        The function to call when the unlink button is clicked.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n</APIReturns>\n</API>\n\n### `useFloatingLinkEnter`\n\nListens for the Enter key press event and submits the floating link in the editor.\n\n### `useFloatingLinkEscape`\n\nListens for the Escape key press event and handles the behavior of the floating link in the editor.\n\n### `useFloatingLinkInsert`\n\nThe behavior hook for inserting a link.\n\n<API name=\"useFloatingLinkInsert\">\n<APIState>\n  <APIItem name=\"floating\" type=\"ReturnType<typeof useFloatingLinkInsertState>\">\n    The virtual floating returned object.\n  </APIItem>\n  <APIItem name=\"refClickOutside\" type=\"React.Ref\">\n    The ref of the floating element.\n  </APIItem>\n</APIState>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"ref\" type=\"function\">\n    The ref callback for the floating element.\n  </APIItem>\n  <APIItem name=\"props\" type=\"object\">\n    Props for the floating element.\n    <APISubList>\n      <APISubListItem parent=\"props\" name=\"style\" type=\"object\">\n        The style of the floating link.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n  <APIItem name=\"textInputProps\" type=\"object\">\n    Props for the text input.\n    <APISubList>\n      <APISubListItem parent=\"textInputProps\" name=\"onChange\" type=\"function\">\n        The function to call when the text input value changes.\n      </APISubListItem>\n      <APISubListItem parent=\"textInputProps\" name=\"defaultValue\" type=\"string\">\n        The default value of the text input.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n</APIReturns>\n</API>\n\n### `useLink`\n\nThe behavior hook for the link element.\n\n<API name=\"useLink\">\n<APIOptions type=\"UseLinkOptions\">\n  <APIItem name=\"element\" type=\"TLinkElement\">\n    The link element.\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"props\" type=\"object\">\n    Props for the link element.\n    <APISubList>\n      <APISubListItem parent=\"props\" name=\"onMouseOver\" type=\"function\">\n        The function to call when the mouse is over the link.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n</APIReturns>\n</API>\n\n### `useLinkToolbarButton`\n\nThe behavior hook for the link toolbar button.\n\n<API name=\"useLinkToolbarButton\">\n<APIState>\n  <APIItem name=\"pressed\" type=\"boolean\">\n    Whether the selection is in a link.\n  </APIItem>\n</APIState>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"props\" type=\"object\">\n    Props for the toolbar button.\n    <APISubList>\n      <APISubListItem parent=\"props\" name=\"pressed\" type=\"boolean\">\n        Whether the link is pressed.\n      </APISubListItem>\n      <APISubListItem parent=\"props\" name=\"onClick\" type=\"function\">\n        The function to call when the button is clicked.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n</APIReturns>\n</API>\n\n### `useVirtualFloatingLink`\n\nCustom hook for managing virtual floating of a link.\n\n<API name=\"useVirtualFloatingLink\">\n<APIOptions type=\"object\">\n  <APIItem name=\"editorId\" type=\"string\">\n    The ID of the editor to which the link belongs.\n  </APIItem>\n  <APIItem name=\"floatingOptions\" type=\"UseVirtualFloatingOptions\" optional>\n    Options for virtual floating.\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"UseVirtualFloatingReturn\">\n  The return value of the `useVirtualFloating` hook.\n</APIReturns>\n</API>\n",
      "type": "registry:file",
      "target": "content/docs/plate/(plugins)/(elements)/link.mdx"
    }
  ],
  "type": "registry:file"
}