{
  "name": "react-example-text-align",
  "title": "react-example-text-align",
  "type": "registry:block",
  "description": "Text alignment options (left, center, right, justify).",
  "registryDependencies": [
    "https://unpkg.com/prosekit-registry/dist/r/react-sample-sample-doc-text-align.json",
    "https://unpkg.com/prosekit-registry/dist/r/react-ui-button.json"
  ],
  "dependencies": [
    "prosekit@^0.23.2"
  ],
  "files": [
    {
      "path": "registry/src/react/examples/text-align/editor.tsx",
      "type": "registry:component",
      "target": "components/editor/examples/text-align/editor.tsx",
      "content": "'use client'\n\nimport 'prosekit/basic/style.css'\nimport 'prosekit/basic/typography.css'\n\nimport { createEditor, type NodeJSON } from 'prosekit/core'\nimport { ProseKit } from 'prosekit/react'\nimport { useMemo } from 'react'\n\nimport { sampleContent } from '../../sample/sample-doc-text-align.ts'\n\nimport { defineExtension } from './extension.ts'\nimport Toolbar from './toolbar.tsx'\n\ninterface EditorProps {\n  initialContent?: NodeJSON\n}\n\nexport default function Editor(props: EditorProps) {\n  const defaultContent = props.initialContent ?? sampleContent\n  const editor = useMemo(() => {\n    const extension = defineExtension()\n    return createEditor({ extension, defaultContent })\n  }, [defaultContent])\n\n  return (\n    <ProseKit editor={editor}>\n      <div className=\"box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-[canvas] text-black dark:text-white\">\n        <Toolbar />\n        <div className=\"relative w-full flex-1 box-border overflow-y-auto\">\n          <div ref={editor.mount} className=\"ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500\"></div>\n        </div>\n      </div>\n    </ProseKit>\n  )\n}\n"
    },
    {
      "path": "registry/src/react/examples/text-align/extension.ts",
      "type": "registry:component",
      "target": "components/editor/examples/text-align/extension.ts",
      "content": "import { defineBasicExtension } from 'prosekit/basic'\nimport { union } from 'prosekit/core'\nimport { defineTextAlign } from 'prosekit/extensions/text-align'\n\nexport function defineExtension() {\n  return union(\n    defineBasicExtension(),\n    defineTextAlign({ types: ['paragraph', 'heading'] }),\n  )\n}\n\nexport type EditorExtension = ReturnType<typeof defineExtension>\n"
    },
    {
      "path": "registry/src/react/examples/text-align/index.ts",
      "type": "registry:component",
      "target": "components/editor/examples/text-align/index.ts",
      "content": "export { default as ExampleEditor } from './editor.tsx'\n"
    },
    {
      "path": "registry/src/react/examples/text-align/toolbar.tsx",
      "type": "registry:component",
      "target": "components/editor/examples/text-align/toolbar.tsx",
      "content": "'use client'\n\nimport type { Editor } from 'prosekit/core'\nimport { useEditorDerivedValue } from 'prosekit/react'\n\nimport { Button } from '../../ui/button/index.ts'\n\nimport type { EditorExtension } from './extension.ts'\n\nfunction isTextAlignActive(editor: Editor<EditorExtension>, value: string) {\n  return Object.values(editor.nodes).some((node) => {\n    // @ts-expect-error textAlign may not be available on every node\n    return node.isActive({ textAlign: value })\n  })\n}\n\nfunction getToolbarItems(editor: Editor<EditorExtension>) {\n  return {\n    left: {\n      isActive: isTextAlignActive(editor, 'left'),\n      canExec: editor.commands.setTextAlign.canExec('left'),\n      command: () => editor.commands.setTextAlign('left'),\n    },\n    center: {\n      isActive: isTextAlignActive(editor, 'center'),\n      canExec: editor.commands.setTextAlign.canExec('center'),\n      command: () => editor.commands.setTextAlign('center'),\n    },\n    right: {\n      isActive: isTextAlignActive(editor, 'right'),\n      canExec: editor.commands.setTextAlign.canExec('right'),\n      command: () => editor.commands.setTextAlign('right'),\n    },\n    justify: {\n      isActive: isTextAlignActive(editor, 'justify'),\n      canExec: editor.commands.setTextAlign.canExec('justify'),\n      command: () => editor.commands.setTextAlign('justify'),\n    },\n  }\n}\n\nexport default function Toolbar() {\n  const items = useEditorDerivedValue(getToolbarItems)\n\n  return (\n    <div className=\"z-2 box-border border-gray-200 dark:border-gray-800 border-solid border-l-0 border-r-0 border-t-0 border-b flex flex-wrap gap-1 p-2 items-center\">\n      <Button\n        pressed={items.left.isActive}\n        disabled={!items.left.canExec}\n        onClick={items.left.command}\n      >\n        Left\n      </Button>\n\n      <Button\n        pressed={items.center.isActive}\n        disabled={!items.center.canExec}\n        onClick={items.center.command}\n      >\n        Center\n      </Button>\n\n      <Button\n        pressed={items.right.isActive}\n        disabled={!items.right.canExec}\n        onClick={items.right.command}\n      >\n        Right\n      </Button>\n\n      <Button\n        pressed={items.justify.isActive}\n        disabled={!items.justify.canExec}\n        onClick={items.justify.command}\n      >\n        Justify\n      </Button>\n    </div>\n  )\n}\n"
    }
  ],
  "meta": {
    "hasIcons": false,
    "hidden": false,
    "story": "text-align",
    "framework": "react",
    "accumulatedFiles": [
      "registry/src/react/examples/text-align/editor.tsx",
      "registry/src/react/examples/text-align/extension.ts",
      "registry/src/react/examples/text-align/index.ts",
      "registry/src/react/examples/text-align/toolbar.tsx",
      "registry/src/react/sample/sample-doc-text-align.ts",
      "registry/src/react/ui/button/button.tsx",
      "registry/src/react/ui/button/index.ts"
    ],
    "internalDependencies": [
      "react-sample-sample-doc-text-align",
      "react-ui-button"
    ]
  },
  "$schema": "https://ui.shadcn.com/schema/registry-item.json"
}
