{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rich-text-editor-image",
  "title": "Image",
  "description": "Image nodes inserted by URL from the toolbar.",
  "dependencies": [
    "@tiptap/extension-image@3.32.2",
    "@tiptap/react@3.32.2",
    "cn",
    "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/image.tsx",
      "content": "import type { ImageOptions } from '@tiptap/extension-image'\nimport type { Editor } from '@tiptap/react'\nimport type { FormEvent } from 'react'\nimport type { ExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\nimport { Image } from '@tiptap/extension-image'\nimport { useCurrentEditor, useEditorState } from '@tiptap/react'\nimport { cn } from 'cn'\nimport { ImageIcon } 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 {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from '@/components/ui/popover'\nimport { defineExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\n\n/**\n * Registers the Tiptap Image node. Options pass straight through to the\n * extension, e.g. `<EditorImage inline allowBase64 />`.\n */\nexport const EditorImage: ExtensionComponent<Partial<ImageOptions>> = defineExtensionComponent(\n  'image',\n  props => [\n    Image.configure(props),\n  ],\n)\n\nexport interface EditorImageToolbarProps {\n  className?: string\n}\n\n/**\n * Toolbar control for inserting an image by URL. Opening it while an image is\n * selected pre-fills the current source, so both insertion and replacement go\n * through the same input.\n */\nexport function EditorImageToolbar({ className }: EditorImageToolbarProps) {\n  const { editor } = useCurrentEditor()\n\n  if (!editor) {\n    return null\n  }\n\n  return <EditorImageToolbarContent editor={editor} className={className} />\n}\n\nconst protocolPattern = /^[a-z][\\w+.-]*:/i\n\nfunction normalizeImageUrl(value: string): string {\n  const url = value.trim()\n\n  if (url === '') {\n    return ''\n  }\n\n  if (protocolPattern.test(url)) {\n    return url\n  }\n\n  if (url.startsWith('//')) {\n    return `https:${url}`\n  }\n\n  return `https://${url}`\n}\n\nfunction EditorImageToolbarContent({\n  editor,\n  className,\n}: {\n  editor: Editor\n  className?: string\n}) {\n  const [open, setOpen] = useState(false)\n  const [url, setUrl] = useState('')\n  const isActive = useEditorState({\n    editor,\n    selector: ({ editor: instance }) => instance.isActive('image'),\n  })\n\n  const handleOpenChange = (nextOpen: boolean) => {\n    if (nextOpen) {\n      const attributes = editor.getAttributes('image') as { src?: string }\n      setUrl(attributes.src ?? '')\n    }\n\n    setOpen(nextOpen)\n  }\n\n  const handleSubmit = (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault()\n\n    const src = normalizeImageUrl(url)\n\n    if (src === '') {\n      return\n    }\n\n    editor.chain().focus().setImage({ src }).run()\n    setOpen(false)\n  }\n\n  return (\n    <Popover open={open} onOpenChange={handleOpenChange}>\n      {/*\n        Base UI anchors the popup to the trigger element and needs its ref, so\n        the trigger is a host element that renders the toolbar button inside it.\n      */}\n      <PopoverTrigger\n        nativeButton={false}\n        tabIndex={-1}\n        render={<span className=\"inline-flex\" />}\n      >\n        <EditorToolbarButton\n          label=\"Image\"\n          className={cn(isActive && 'bg-muted text-foreground', className)}\n        >\n          <ImageIcon />\n        </EditorToolbarButton>\n      </PopoverTrigger>\n      <PopoverContent\n        finalFocus={() => {\n          editor.chain().focus().run()\n          return false\n        }}\n      >\n        <form className=\"flex flex-col gap-2\" onSubmit={handleSubmit}>\n          <Input\n            aria-label=\"Image URL\"\n            placeholder=\"https://example.com/image.png\"\n            value={url}\n            onChange={event => setUrl(event.target.value)}\n          />\n          <Button type=\"submit\" size=\"sm\">\n            Insert image\n          </Button>\n        </form>\n      </PopoverContent>\n    </Popover>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/rich-text-editor/image.tsx"
    }
  ],
  "categories": [
    "rich-text-editor",
    "node"
  ],
  "type": "registry:ui"
}