{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rich-text-editor-emoji",
  "title": "Emoji",
  "description": "Emoji nodes with a shortcode suggestion and a toolbar picker.",
  "dependencies": [
    "@tiptap/extension-emoji@3.32.2",
    "@tiptap/react@3.32.2",
    "lucide-react"
  ],
  "registryDependencies": [
    "litingyes/blocove/rich-text-editor",
    "litingyes/blocove/rich-text-editor-extension",
    "litingyes/blocove/rich-text-editor-suggestion",
    "popover"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/rich-text-editor/emoji.tsx",
      "content": "import type { EmojiItem, EmojiOptions } from '@tiptap/extension-emoji'\nimport type { Editor } from '@tiptap/react'\nimport type { ExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\nimport { emojis as defaultEmojis, Emoji } from '@tiptap/extension-emoji'\nimport { useCurrentEditor } from '@tiptap/react'\nimport { SmileIcon } from 'lucide-react'\nimport { useState } from 'react'\nimport { EditorToolbarButton } from '@/components/blocove/rich-text-editor/editor'\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'\nimport { defineExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\nimport { createSuggestionRenderer } from '@/lib/blocove/rich-text-editor-suggestion'\n\n// The extension ships the insertion command and the trigger guard in its own\n// default suggestion, so the configured one only adds the item list and the\n// popup that renders it.\nconst defaultSuggestion = Emoji.options.suggestion\n\nconst toolbarPaletteSize = 120\nconst suggestionLimit = 12\n\nfunction matchesQuery(item: EmojiItem, query: string) {\n  const needle = query.toLowerCase()\n\n  if (needle === '') {\n    return true\n  }\n\n  return (\n    item.name.toLowerCase().includes(needle)\n    || item.shortcodes.some(shortcode => shortcode.toLowerCase().includes(needle))\n    || item.tags.some(tag => tag.toLowerCase().includes(needle))\n  )\n}\n\nexport interface EditorEmojiProps extends Partial<Omit<EmojiOptions, 'suggestion'>> {\n  /** Character that opens the picker while typing. */\n  char?: string\n  /** Accessible name of the picker and of the suggestion list. */\n  ariaLabel?: string\n}\n\n/** An emoji item carrying the shape the shared suggestion list renders. */\ninterface EmojiSuggestionItem extends EmojiItem {\n  id: string\n  label: string\n}\n\n/**\n * The suggestion list renders `id` and `label`; the emoji command inserts the\n * whole item as node attributes, and ProseMirror drops the attributes the\n * emoji node does not declare.\n */\nfunction toSuggestionItem(item: EmojiItem): EmojiSuggestionItem {\n  return { ...item, id: item.name, label: item.name }\n}\n\n/**\n * Registers the Tiptap emoji node. Typing the trigger character opens the\n * suggestion list; the toolbar exposes the same data as a picker.\n */\nexport const EditorEmoji: ExtensionComponent<EditorEmojiProps> = defineExtensionComponent(\n  'emoji',\n  ({ char = ':', ariaLabel = 'Emoji', ...options }: EditorEmojiProps) => {\n    const items = options.emojis ?? defaultEmojis\n\n    return [\n      Emoji.configure({\n        ...options,\n        emojis: items,\n        suggestion: {\n          ...defaultSuggestion,\n          char,\n          items: ({ query }: { query: string }) =>\n            items\n              .filter(item => matchesQuery(item, query))\n              .slice(0, suggestionLimit)\n              .map(toSuggestionItem),\n          render: createSuggestionRenderer<EmojiSuggestionItem>({ ariaLabel }),\n        },\n      }),\n    ]\n  },\n)\n\nexport interface EditorEmojiToolbarProps {\n  className?: string\n}\n\n/**\n * Toolbar picker for the emoji node.\n */\nexport function EditorEmojiToolbar({ className }: EditorEmojiToolbarProps) {\n  const { editor } = useCurrentEditor()\n\n  if (!editor) {\n    return null\n  }\n\n  return <EditorEmojiToolbarContent editor={editor} className={className} />\n}\n\nfunction EditorEmojiToolbarContent({\n  editor,\n  className,\n}: {\n  editor: Editor\n  className?: string\n}) {\n  const [open, setOpen] = useState(false)\n  const storage = editor.storage.emoji as { emojis?: EmojiItem[] } | undefined\n  const palette = (storage?.emojis ?? defaultEmojis).slice(0, toolbarPaletteSize)\n\n  function insert(item: EmojiItem) {\n    editor\n      .chain()\n      .focus()\n      .insertContent({\n        type: 'emoji',\n        attrs: { name: item.name },\n      })\n      .run()\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=\"Emoji\" className={className}>\n          <SmileIcon />\n        </EditorToolbarButton>\n      </PopoverTrigger>\n      <PopoverContent aria-label=\"Emoji\" align=\"start\" className=\"w-auto p-2\">\n        <div className=\"grid max-h-56 grid-cols-8 gap-0.5 overflow-y-auto\">\n          {palette.map(item => (\n            <button\n              key={item.name}\n              type=\"button\"\n              aria-label={item.name}\n              className=\"flex size-7 items-center justify-center rounded text-base transition-colors hover:bg-accent\"\n              onClick={() => insert(item)}\n            >\n              {item.emoji}\n            </button>\n          ))}\n        </div>\n      </PopoverContent>\n    </Popover>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/rich-text-editor/emoji.tsx"
    }
  ],
  "categories": [
    "rich-text-editor",
    "node"
  ],
  "type": "registry:ui"
}