{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-overlay-docs",
  "title": "Cursor Overlay",
  "description": "Visual feedback for selections and cursor positions when editor loses focus.",
  "files": [
    {
      "path": "../../content/docs/(plugins)/(functionality)/cursor-overlay.mdx",
      "content": "---\ntitle: Cursor Overlay\ndescription: Visual feedback for selections and cursor positions when editor loses focus.\ndocs:\n  - route: /docs/components/cursor-overlay\n    title: Cursor Overlay\n---\n\n<ComponentPreview name=\"cursor-overlay-demo\" />\n\n<PackageInfo>\n\n## Features\n\n- Maintains selection highlight when another element is focused.\n- Dynamic selection display (e.g., during AI streaming).\n- Shows cursor position during drag operations.\n- Customizable styling for cursors and selections.\n- Essential for external UI interactions (e.g., link toolbar, AI combobox).\n\n</PackageInfo>\n\n## Kit Usage\n\n<Steps>\n\n### Installation\n\nThe fastest way to add cursor overlay functionality is with the `CursorOverlayKit`, which includes the pre-configured `CursorOverlayPlugin` and the [`CursorOverlay`](/docs/components/cursor-overlay) UI component.\n\n<ComponentSource name=\"cursor-overlay-kit\" />\n\n- [`CursorOverlay`](/docs/components/cursor-overlay): Renders cursor and selection overlays.\n\n### Add Kit\n\n```tsx\nimport { createPlateEditor } from 'platejs/react';\nimport { CursorOverlayKit } from '@/components/editor/plugins/cursor-overlay-kit';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    ...CursorOverlayKit,\n  ],\n});\n```\n\n</Steps>\n\n## Manual Usage\n\n<Steps>\n\n### Installation\n\n```bash\nnpm install @platejs/selection\n```\n\n### Add Plugin\n\n```tsx\nimport { CursorOverlayPlugin } from '@platejs/selection/react';\nimport { createPlateEditor } from 'platejs/react';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    CursorOverlayPlugin,\n  ],\n});\n```\n\n### Configure Plugin\n\nConfigure the cursor overlay with a component to render overlays:\n\n```tsx\nimport { CursorOverlayPlugin } from '@platejs/selection/react';\nimport { CursorOverlay } from '@/components/ui/cursor-overlay';\n\nCursorOverlayPlugin.configure({\n  render: {\n    afterEditable: () => <CursorOverlay />,\n  },\n});\n```\n\n- `render.afterEditable`: Assigns [`CursorOverlay`](/docs/components/cursor-overlay) to render after the editable content.\n\n### Editor Container Setup\n\nThe cursor overlay requires a container component to ensure correct positioning. If you're using the [Editor](/docs/components/editor) component, this is handled automatically through `EditorContainer`.\n\nFor custom setups, ensure your editor is wrapped with a container that has the editor's unique ID:\n\n```tsx\nimport { PlateContainer } from 'platejs/react';\n\nexport function EditorContainer(props: React.HTMLAttributes<HTMLDivElement>) {\n  return <PlateContainer {...props} />;\n}\n```\n\n### Preserving Selection Focus\n\nTo maintain the editor's selection state when focusing UI elements, add the `data-plate-focus=\"true\"` attribute to those elements:\n\n```tsx\n<ToolbarButton data-plate-focus=\"true\">\n  {/* toolbar content */}\n</ToolbarButton>\n```\n\nThis prevents the cursor overlay from disappearing when interacting with toolbar buttons or other UI elements.\n\n</Steps>\n\n## Plugins\n\n### `CursorOverlayPlugin`\n\nPlugin that manages cursor and selection overlays for visual feedback.\n\n<API name=\"CursorOverlayPlugin\">\n<APIOptions>\n  <APIItem name=\"cursors\" type=\"Record<string, CursorState<CursorData>>\">\n    Object containing cursor states with their unique identifiers.\n    - **Default:** `{}`\n  </APIItem>\n</APIOptions>\n</API>\n\n## API\n\n### `api.cursorOverlay.addCursor`\n\nAdds a cursor overlay with the specified key and state.\n\n<API name=\"addCursor\">\n<APIParameters>\n  <APIItem name=\"key\" type=\"string\">\n    Unique identifier for the cursor (e.g., 'blur', 'drag', 'custom').\n  </APIItem>\n  <APIItem name=\"cursor\" type=\"CursorState<CursorData>\">\n    The cursor state including selection and optional styling data.\n  </APIItem>\n</APIParameters>\n</API>\n\n### `api.cursorOverlay.removeCursor`\n\nRemoves a cursor overlay by its key.\n\n<API name=\"removeCursor\">\n<APIParameters>\n  <APIItem name=\"key\" type=\"string\">\n    The key of the cursor to remove.\n  </APIItem>\n</APIParameters>\n</API>\n\n## Hooks\n\n### `useCursorOverlay`\n\nA hook that manages cursor and selection overlay states, providing real-time cursor positions and selection rectangles.\n\n<API name=\"useCursorOverlay\">\n<APIOptions type=\"object\">\n  <APIItem name=\"minSelectionWidth\" type=\"number\" optional>\n    Minimum width in pixels for a selection rectangle. Useful for making cursor carets more visible.\n    - **Default:** `1`\n  </APIItem>\n  <APIItem name=\"refreshOnResize\" type=\"boolean\" optional>\n    Whether to recalculate cursor positions when the container is resized.\n    - **Default:** `true`\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"cursors\" type=\"CursorOverlayState<TCursorData>[]\">\n    Array of cursor states with their corresponding selection rectangles and styling data.\n  </APIItem>\n  <APIItem name=\"refresh\" type=\"() => void\">\n    Function to manually trigger a recalculation of cursor positions.\n  </APIItem>\n</APIReturns>\n</API>\n",
      "type": "registry:file",
      "target": "content/docs/plate/(plugins)/(functionality)/cursor-overlay.mdx"
    }
  ],
  "type": "registry:file"
}