{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rich-text-editor-text-style",
  "title": "Text Style",
  "description": "The text style mark with color, background, font family, font size and line height controls.",
  "dependencies": [
    "@tiptap/extension-text-style@3.32.2",
    "@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/text-style.tsx",
      "content": "import type {\n  BackgroundColorOptions,\n  ColorOptions,\n  FontFamilyOptions,\n  FontSizeOptions,\n  LineHeightOptions,\n  TextStyleOptions,\n} from '@tiptap/extension-text-style'\nimport type { Editor } from '@tiptap/react'\nimport type { ExtensionComponent } from '@/lib/blocove/rich-text-editor-extension'\nimport {\n  BackgroundColor,\n  Color,\n  FontFamily,\n  FontSize,\n  LineHeight,\n  TextStyle,\n} from '@tiptap/extension-text-style'\nimport { useCurrentEditor } from '@tiptap/react'\nimport { TypeIcon } 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\n/**\n * Registers the text style mark. Every attribute item below registers it too,\n * because the attribute extensions extend the mark and cannot work without it;\n * the editor keeps the first declaration, so composing them is safe.\n */\nexport const EditorTextStyle: ExtensionComponent<Partial<TextStyleOptions>> = defineExtensionComponent(\n  'text-style',\n  props => [\n    TextStyle.configure(props),\n  ],\n)\n\nexport const EditorColor: ExtensionComponent<Partial<ColorOptions>> = defineExtensionComponent(\n  'color',\n  props => [\n    TextStyle,\n    Color.configure(props),\n  ],\n)\n\nexport const EditorBackgroundColor: ExtensionComponent<Partial<BackgroundColorOptions>> = defineExtensionComponent(\n  'background-color',\n  props => [\n    TextStyle,\n    BackgroundColor.configure(props),\n  ],\n)\n\nexport const EditorFontFamily: ExtensionComponent<Partial<FontFamilyOptions>> = defineExtensionComponent(\n  'font-family',\n  props => [\n    TextStyle,\n    FontFamily.configure(props),\n  ],\n)\n\nexport const EditorFontSize: ExtensionComponent<Partial<FontSizeOptions>> = defineExtensionComponent(\n  'font-size',\n  props => [\n    TextStyle,\n    FontSize.configure(props),\n  ],\n)\n\nexport const EditorLineHeight: ExtensionComponent<Partial<LineHeightOptions>> = defineExtensionComponent(\n  'line-height',\n  props => [\n    TextStyle,\n    LineHeight.configure(props),\n  ],\n)\n\nexport interface EditorTextStyleToolbarProps {\n  className?: string\n}\n\n/**\n * Toolbar control for the text style mark: color, background color, font\n * family, font size and line height.\n */\nexport function EditorTextStyleToolbar({\n  className,\n}: EditorTextStyleToolbarProps) {\n  const { editor } = useCurrentEditor()\n\n  if (!editor) {\n    return null\n  }\n\n  return <EditorTextStyleToolbarContent editor={editor} className={className} />\n}\n\nfunction EditorTextStyleToolbarContent({\n  editor,\n  className,\n}: {\n  editor: Editor\n  className?: string\n}) {\n  const [open, setOpen] = useState(false)\n  const [color, setColor] = useState('#111827')\n  const [background, setBackground] = useState('#fde68a')\n  const [family, setFamily] = useState('')\n  const [size, setSize] = useState('')\n  const [lineHeight, setLineHeight] = useState('')\n\n  function run(command: (chain: ReturnType<Editor['chain']>) => ReturnType<Editor['chain']>) {\n    command(editor.chain().focus()).run()\n  }\n\n  function applyFamily() {\n    const value = family.trim()\n\n    run(chain => value === ''\n      ? chain.unsetFontFamily()\n      : chain.setFontFamily(value))\n  }\n\n  function applySize() {\n    const value = size.trim()\n\n    run(chain => value === ''\n      ? chain.unsetFontSize()\n      : chain.setFontSize(value))\n  }\n\n  function applyLineHeight() {\n    const value = lineHeight.trim()\n\n    run(chain => value === ''\n      ? chain.unsetLineHeight()\n      : chain.setLineHeight(value))\n  }\n\n  function clearTextStyle() {\n    run(chain => chain\n      .unsetColor()\n      .unsetBackgroundColor()\n      .unsetFontFamily()\n      .unsetFontSize()\n      .unsetLineHeight())\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=\"Text style\" className={className}>\n          <TypeIcon />\n        </EditorToolbarButton>\n      </PopoverTrigger>\n      <PopoverContent aria-label=\"Text style\" align=\"start\" className=\"w-72\">\n        <div className=\"flex flex-col gap-2\">\n          <label className=\"flex items-center justify-between gap-2 text-xs text-muted-foreground\">\n            <span>Text color</span>\n            <input\n              type=\"color\"\n              aria-label=\"Text color\"\n              value={color}\n              onChange={(event) => {\n                setColor(event.target.value)\n                run(chain => chain.setColor(event.target.value))\n              }}\n              className=\"h-7 w-10 cursor-pointer rounded border border-input bg-transparent\"\n            />\n          </label>\n          <label className=\"flex items-center justify-between gap-2 text-xs text-muted-foreground\">\n            <span>Background</span>\n            <input\n              type=\"color\"\n              aria-label=\"Background color\"\n              value={background}\n              onChange={(event) => {\n                setBackground(event.target.value)\n                run(chain => chain.setBackgroundColor(event.target.value))\n              }}\n              className=\"h-7 w-10 cursor-pointer rounded border border-input bg-transparent\"\n            />\n          </label>\n          <Input\n            aria-label=\"Font family\"\n            placeholder=\"Georgia, serif\"\n            value={family}\n            onChange={event => setFamily(event.target.value)}\n            onBlur={applyFamily}\n            onKeyDown={(event) => {\n              if (event.key === 'Enter') {\n                event.preventDefault()\n                applyFamily()\n              }\n            }}\n          />\n          <Input\n            aria-label=\"Font size\"\n            placeholder=\"1.25em\"\n            value={size}\n            onChange={event => setSize(event.target.value)}\n            onBlur={applySize}\n            onKeyDown={(event) => {\n              if (event.key === 'Enter') {\n                event.preventDefault()\n                applySize()\n              }\n            }}\n          />\n          <Input\n            aria-label=\"Line height\"\n            placeholder=\"1.5\"\n            value={lineHeight}\n            onChange={event => setLineHeight(event.target.value)}\n            onBlur={applyLineHeight}\n            onKeyDown={(event) => {\n              if (event.key === 'Enter') {\n                event.preventDefault()\n                applyLineHeight()\n              }\n            }}\n          />\n          <div className=\"flex items-center justify-end\">\n            <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={clearTextStyle}>\n              Clear text style\n            </Button>\n          </div>\n        </div>\n      </PopoverContent>\n    </Popover>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/rich-text-editor/text-style.tsx"
    }
  ],
  "categories": [
    "rich-text-editor",
    "mark"
  ],
  "type": "registry:ui"
}