{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rich-text-editor-collaboration-caret",
  "title": "Collaboration Caret",
  "description": "Renders the cursors and selections of the other collaborators from the provider awareness.",
  "dependencies": [
    "@tiptap/extension-collaboration-caret@3.32.2",
    "@tiptap/pm@3.32.2"
  ],
  "registryDependencies": [
    "litingyes/blocove/rich-text-editor-collaboration",
    "litingyes/blocove/rich-text-editor-extension"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/rich-text-editor/collaboration-caret.tsx",
      "content": "import type { DecorationAttrs } from '@tiptap/pm/view'\nimport type { CollaborationProvider, CollaborationUser } from '@/components/blocove/rich-text-editor/collaboration'\nimport type { ExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\nimport { CollaborationCaret } from '@tiptap/extension-collaboration-caret'\nimport { defineExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\n\nconst fallbackColor = '#3b82f6'\n\nfunction caretColor(user: Record<string, unknown>) {\n  return typeof user.color === 'string'\n    ? user.color\n    : fallbackColor\n}\n\nfunction caretName(user: Record<string, unknown>) {\n  return typeof user.name === 'string' && user.name.trim()\n    ? user.name\n    : 'Anonymous'\n}\n\n/**\n * The default cursor: a coloured caret with the collaborator's name above it.\n * It is built with inline styles so it works without a stylesheet.\n */\nexport function renderCollaborationCaret(user: Record<string, unknown>) {\n  const color = caretColor(user)\n  const caret = document.createElement('span')\n  caret.className = 'collaboration-carets__caret'\n  caret.style.borderLeft = `2px solid ${color}`\n  caret.style.marginLeft = '-1px'\n  caret.style.marginRight = '-1px'\n  caret.style.pointerEvents = 'none'\n  caret.style.position = 'relative'\n  caret.style.wordBreak = 'normal'\n\n  const label = document.createElement('span')\n  label.className = 'collaboration-carets__label'\n  label.style.backgroundColor = color\n  label.style.borderRadius = '3px'\n  label.style.color = '#fff'\n  label.style.fontSize = '11px'\n  label.style.fontStyle = 'normal'\n  label.style.fontWeight = '600'\n  label.style.left = '-1px'\n  label.style.lineHeight = 'normal'\n  label.style.padding = '1px 4px'\n  label.style.position = 'absolute'\n  label.style.top = '-1.5em'\n  label.style.userSelect = 'none'\n  label.style.whiteSpace = 'nowrap'\n  label.textContent = caretName(user)\n\n  caret.append(label)\n\n  return caret\n}\n\n/**\n * The default remotely selected range: the collaborator's colour at low\n * opacity, so the text stays readable under it.\n */\nexport function renderCollaborationSelection(\n  user: Record<string, unknown>,\n): DecorationAttrs {\n  return {\n    'nodeName': 'span',\n    'class': 'collaboration-carets__selection',\n    'style': `background-color: ${caretColor(user)}33`,\n    'data-user': caretName(user),\n  }\n}\n\nexport interface EditorCollaborationCaretProps {\n  /** The connected provider. Its awareness carries the cursors. */\n  provider: CollaborationProvider\n  /** The current user advertised to the peers. */\n  user: CollaborationUser\n  /** Replace the default cursor element. */\n  render?: (user: Record<string, unknown>) => HTMLElement\n  /** Replace the default selection decoration. */\n  selectionRender?: (user: Record<string, unknown>) => DecorationAttrs\n}\n\n/**\n * Renders the cursors and selections of the other collaborators. The extension\n * publishes the local user through awareness, which is also what the presence\n * bar reads.\n */\nexport const EditorCollaborationCaret: ExtensionComponent<EditorCollaborationCaretProps>\n  = defineExtensionComponent('collaboration-caret', ({ provider, user, render, selectionRender }) => {\n    if (!provider) {\n      throw new Error(\n        '[blocove/rich-text-editor] EditorCollaborationCaret requires the provider that syncs the shared document.',\n      )\n    }\n\n    if (!provider.awareness) {\n      throw new Error(\n        '[blocove/rich-text-editor] EditorCollaborationCaret requires awareness. Create the provider with awareness enabled before mounting the editor.',\n      )\n    }\n\n    return [\n      CollaborationCaret.configure({\n        provider,\n        user,\n        render: render ?? renderCollaborationCaret,\n        selectionRender: selectionRender ?? renderCollaborationSelection,\n      }),\n    ]\n  })\n",
      "type": "registry:ui",
      "target": "components/blocove/rich-text-editor/collaboration-caret.tsx"
    }
  ],
  "categories": [
    "rich-text-editor",
    "collaboration"
  ],
  "type": "registry:ui"
}