{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rich-text-editor-heading",
  "title": "Heading",
  "description": "Heading nodes with a toolbar selector for levels 1–3.",
  "dependencies": [
    "@tiptap/extension-heading@3.32.2",
    "@tiptap/react@3.32.2",
    "cn",
    "lucide-react"
  ],
  "registryDependencies": [
    "litingyes/blocove/rich-text-editor",
    "litingyes/blocove/rich-text-editor-extension",
    "select"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/rich-text-editor/heading.tsx",
      "content": "import type { Level } from '@tiptap/extension-heading'\nimport type { Editor } from '@tiptap/react'\nimport { Heading } from '@tiptap/extension-heading'\nimport { useCurrentEditor, useEditorState } from '@tiptap/react'\nimport { cn } from 'cn'\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from '@/components/ui/select'\nimport { defineExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\n\nconst defaultLevels: Level[] = [1, 2, 3]\n\nconst paragraphValue = 'paragraph'\n\ninterface BlockTypeOption {\n  label: string\n  value: string\n}\n\nexport interface EditorHeadingProps {\n  /**\n   * The heading levels registered with the node.\n   * @default [1, 2, 3]\n   */\n  levels?: Level[]\n}\n\n/**\n * Registers the Tiptap Heading node.\n */\nexport const EditorHeading = defineExtensionComponent<EditorHeadingProps>(\n  'heading',\n  ({ levels = defaultLevels, ...options }) => [\n    Heading.configure({ ...options, levels }),\n  ],\n)\n\nexport interface EditorHeadingToolbarProps {\n  className?: string\n}\n\n/**\n * Toolbar selector for the current block type: a paragraph or one of the\n * registered heading levels.\n */\nexport function EditorHeadingToolbar({\n  className,\n}: EditorHeadingToolbarProps) {\n  const { editor } = useCurrentEditor()\n\n  if (!editor) {\n    return null\n  }\n\n  return <EditorHeadingToolbarContent editor={editor} className={className} />\n}\n\nfunction EditorHeadingToolbarContent({\n  editor,\n  className,\n}: {\n  editor: Editor\n  className?: string\n}) {\n  const levels = getHeadingLevels(editor)\n  const hasParagraph = Boolean(editor.schema.nodes.paragraph)\n  const state = useEditorState({\n    editor,\n    selector: ({ editor: instance }) => ({\n      activeLevel: getActiveHeadingLevel(instance, levels),\n      paragraphActive: instance.isActive('paragraph'),\n    }),\n  })\n  const options = getBlockTypeOptions(levels, hasParagraph)\n  const value = resolveBlockTypeValue(state.activeLevel, state.paragraphActive)\n\n  const handleValueChange = (nextValue: string | null) => {\n    if (!nextValue) {\n      return\n    }\n\n    if (nextValue === paragraphValue) {\n      editor.chain().focus().setParagraph().run()\n      return\n    }\n\n    const level = levels.find(candidate => String(candidate) === nextValue)\n\n    if (level) {\n      editor.chain().focus().setHeading({ level }).run()\n    }\n  }\n\n  return (\n    <Select value={value} onValueChange={handleValueChange} items={options}>\n      <SelectTrigger\n        size=\"sm\"\n        aria-label=\"Block type\"\n        className={cn('w-28', className)}\n      >\n        <SelectValue placeholder=\"Text\" />\n      </SelectTrigger>\n      <SelectContent>\n        {options.map(option => (\n          <SelectItem key={option.value} value={option.value}>\n            {option.label}\n          </SelectItem>\n        ))}\n      </SelectContent>\n    </Select>\n  )\n}\n\n/**\n * Reads the levels actually registered by the Heading extension, so the\n * selector never offers a level the schema cannot create.\n */\nfunction getHeadingLevels(editor: Editor): Level[] {\n  const extension = editor.extensionManager.extensions.find(\n    item => item.name === 'heading',\n  )\n  const levels = extension?.options.levels as Level[] | undefined\n\n  return levels ?? []\n}\n\n/**\n * Builds the selector options: the paragraph block when the schema has one,\n * then every registered heading level.\n */\nfunction getBlockTypeOptions(\n  levels: Level[],\n  hasParagraph: boolean,\n): BlockTypeOption[] {\n  const headingOptions = levels.map(level => ({\n    label: `Heading ${level}`,\n    value: String(level),\n  }))\n\n  if (!hasParagraph) {\n    return headingOptions\n  }\n\n  return [\n    { label: 'Paragraph', value: paragraphValue },\n    ...headingOptions,\n  ]\n}\n\nfunction getActiveHeadingLevel(editor: Editor, levels: Level[]): Level | null {\n  return levels.find(level => editor.isActive('heading', { level })) ?? null\n}\n\nfunction resolveBlockTypeValue(\n  activeLevel: Level | null,\n  paragraphActive: boolean,\n): string | null {\n  if (activeLevel !== null) {\n    return String(activeLevel)\n  }\n\n  return paragraphActive ? paragraphValue : null\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/rich-text-editor/heading.tsx"
    }
  ],
  "categories": [
    "rich-text-editor",
    "node"
  ],
  "type": "registry:ui"
}