{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rich-text-editor-mathematics",
  "title": "Mathematics",
  "description": "Inline and block formulas rendered with KaTeX.",
  "dependencies": [
    "@tiptap/extension-mathematics@3.32.2",
    "katex@^0.19.1",
    "@tiptap/react@3.32.2",
    "lucide-react"
  ],
  "registryDependencies": [
    "litingyes/blocove/rich-text-editor",
    "litingyes/blocove/rich-text-editor-extension",
    "button",
    "input",
    "popover"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/rich-text-editor/mathematics.tsx",
      "content": "import type { MathematicsOptions } from '@tiptap/extension-mathematics'\nimport type { Editor } from '@tiptap/react'\nimport type { ExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\nimport { Mathematics } from '@tiptap/extension-mathematics'\nimport { useCurrentEditor } from '@tiptap/react'\nimport { SigmaIcon } from 'lucide-react'\nimport { useState } from 'react'\nimport { EditorToolbarButton } from '@/components/blocove/rich-text-editor/editor'\nimport { Button } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'\nimport { defineExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\n\nconst defaultLatex = 'E = mc^2'\n\n/**\n * Registers the KaTeX backed inline and block math nodes.\n */\nexport const EditorMathematics: ExtensionComponent<Partial<MathematicsOptions>> = defineExtensionComponent(\n  'mathematics',\n  props => [\n    Mathematics.configure(props),\n  ],\n)\n\nexport interface EditorMathematicsToolbarProps {\n  className?: string\n}\n\n/**\n * Toolbar control that inserts an inline or a block formula.\n */\nexport function EditorMathematicsToolbar({\n  className,\n}: EditorMathematicsToolbarProps) {\n  const { editor } = useCurrentEditor()\n\n  if (!editor) {\n    return null\n  }\n\n  return <EditorMathematicsToolbarContent editor={editor} className={className} />\n}\n\nfunction EditorMathematicsToolbarContent({\n  editor,\n  className,\n}: {\n  editor: Editor\n  className?: string\n}) {\n  const [open, setOpen] = useState(false)\n  const [latex, setLatex] = useState('')\n\n  function insert(kind: 'inline' | 'block') {\n    const value = latex.trim() === ''\n      ? defaultLatex\n      : latex.trim()\n\n    if (kind === 'inline') {\n      editor.chain().focus().insertInlineMath({ latex: value }).run()\n    }\n    else {\n      editor.chain().focus().insertBlockMath({ latex: value }).run()\n    }\n\n    setLatex('')\n    setOpen(false)\n  }\n\n  return (\n    <Popover open={open} onOpenChange={setOpen}>\n      {/* `EditorToolbarButton` does not forward the trigger props Base UI hands\n          out, so the popup is anchored to a presentational wrapper. */}\n      <PopoverTrigger\n        nativeButton={false}\n        render={<span className=\"inline-flex\" role=\"presentation\" tabIndex={-1} />}\n      >\n        <EditorToolbarButton label=\"Math\" className={className}>\n          <SigmaIcon />\n        </EditorToolbarButton>\n      </PopoverTrigger>\n      <PopoverContent aria-label=\"Math\" align=\"start\" className=\"w-80\">\n        <Input\n          aria-label=\"LaTeX\"\n          placeholder={defaultLatex}\n          value={latex}\n          onChange={event => setLatex(event.target.value)}\n          onKeyDown={(event) => {\n            if (event.key === 'Enter') {\n              event.preventDefault()\n              insert('inline')\n            }\n          }}\n        />\n        <div className=\"flex items-center justify-end gap-1.5\">\n          <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={() => insert('block')}>\n            Block math\n          </Button>\n          <Button type=\"button\" size=\"sm\" onClick={() => insert('inline')}>\n            Inline math\n          </Button>\n        </div>\n      </PopoverContent>\n    </Popover>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/rich-text-editor/mathematics.tsx"
    }
  ],
  "categories": [
    "rich-text-editor",
    "node"
  ],
  "type": "registry:ui"
}