{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "document-vue",
  "title": "Document (Vue)",
  "description": "A document card with its title, kind and size, copy and download, and a preview that expands.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/vue@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/markdown-vue",
    "@kind-ui/code-block-vue",
    "@kind-ui/internal-toolbar-vue",
    "@kind-ui/internal-scroll-area-vue"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/vue/document.ts",
      "content": "import {\n  type DocumentDownload as DocumentDownloadEntry,\n  documentPrimitive,\n  type Highlight,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/vue/primitive\";\nimport { type Component, defineComponent, h, type Slot, type Slots, type VNode } from \"vue\";\nimport { CodeBlock } from \"./code-block\";\nimport {\n  KindScrollArea,\n  KindScrollAreaContent,\n  KindScrollAreaScrollbar,\n  KindScrollAreaThumb,\n  KindScrollAreaViewport,\n} from \"./internal/scroll-area\";\nimport { KindToolbar, KindToolbarButton } from \"./internal/toolbar\";\nimport { Markdown } from \"./markdown\";\n\n// `$stable` tells Vue these slots never change, so a part that renders again doesn't render the parts inside it.\nconst stable = (slot: () => unknown) => ({ default: slot, $stable: true });\n\nconst parts = createParts(documentPrimitive, {\n  root: \"div\",\n  header: \"div\",\n  title: \"span\",\n  meta: \"span\",\n  toolbar: \"div\",\n  copy: \"span\",\n  download: \"span\",\n  body: \"div\",\n  content: \"div\",\n  expand: \"button\",\n});\n\n// A part whose default slot falls back to content built from its state.\nfunction withDefault<C extends Component, State>(part: C, name: string, fallback: (state: State) => unknown) {\n  return defineComponent({\n    name,\n    inheritAttrs: false,\n    setup(_, { attrs, slots }) {\n      const fill: Slot = ({ state }) => fallback(state) as VNode[];\n      return () => h(part, attrs, { ...slots, default: slots.default ?? fill } as Slots);\n    },\n  }) as unknown as C;\n}\n\n/** Holds the title, the meta line and the toolbar. */\nexport const DocumentHeader = parts.Header;\n\n/** The `label`, unless you fill the default slot. */\nexport const DocumentTitle = withDefault(\n  parts.Title,\n  \"DocumentTitle\",\n  (state: { label: string }) => state.label,\n);\n\n/** What the document is and its size, like \"Markdown · 2.4 kB\", unless you fill the default slot. */\nexport const DocumentMeta = withDefault(parts.Meta, \"DocumentMeta\", (state: { meta: string }) => state.meta);\n\n/** Copies the `content`. Wraps a `KindToolbarButton` named \"Copy\", unless you fill the default slot. */\nexport const DocumentCopy = withDefault(parts.Copy, \"DocumentCopy\", () =>\n  h(KindToolbarButton, { \"aria-label\": \"Copy\" }),\n);\n\n/**\n * Calls `onDownload` with its `value`, a download's `id`. Wraps a `KindToolbarButton` named \"Download\", or showing\n * the download's `label` when there are several, unless you fill the default slot.\n */\nexport const DocumentDownload = withDefault(\n  parts.Download,\n  \"DocumentDownload\",\n  (state: { label: string | undefined }) => {\n    const label = state.label;\n    return h(\n      KindToolbarButton,\n      { \"aria-label\": label ? `Download ${label}` : \"Download\" },\n      label ? () => h(\"span\", { \"data-document-download-label\": \"\" }, label) : undefined,\n    );\n  },\n);\n\n/** A `KindToolbar` with Copy and a Download for each of the `downloads`, unless you fill the default slot. */\nexport const DocumentToolbar = withDefault(\n  parts.Toolbar,\n  \"DocumentToolbar\",\n  (state: { downloads: DocumentDownloadEntry[]; canDownload: boolean }) => {\n    const { downloads, canDownload } = state;\n    return h(KindToolbar, { \"aria-label\": \"Document actions\" }, () => [\n      h(DocumentCopy),\n      canDownload &&\n        (downloads.length > 1\n          ? downloads.map(({ id }) => h(DocumentDownload, { key: id, value: id }))\n          : h(DocumentDownload, { value: downloads[0]?.id })),\n    ]);\n  },\n);\n\ntype ContentState = {\n  format: \"markdown\" | \"code\" | \"text\";\n  content: string;\n  language: string | undefined;\n  highlight: Highlight | undefined;\n  streaming: boolean;\n};\n\n/**\n * The `content` as its `format` says: Markdown, a Code Block without its header, or wrapped plain text, unless you\n * fill the default slot.\n */\nexport const DocumentContent = withDefault(parts.Content, \"DocumentContent\", (state: ContentState) => {\n  const { format, content, language, highlight, streaming } = state;\n  if (format === \"markdown\") return h(Markdown, { source: content, streaming, highlight });\n  if (format === \"code\")\n    return h(CodeBlock, { header: false, code: content, language, streaming, highlight });\n  return h(\"pre\", content);\n});\n\n/** \"Show more\", or \"Show less\" while expanded. Rendered only while the content overflows the preview. */\nexport const DocumentExpand = withDefault(\n  parts.Expand,\n  \"DocumentExpand\",\n  (state: { label: string }) => state.label,\n);\n\nconst scrollContent = () => [\n  h(\n    KindScrollAreaViewport,\n    null,\n    stable(() =>\n      h(\n        KindScrollAreaContent,\n        null,\n        stable(() => h(DocumentContent)),\n      ),\n    ),\n  ),\n  h(\n    KindScrollAreaScrollbar,\n    null,\n    stable(() => h(KindScrollAreaThumb)),\n  ),\n];\n\n/** The preview: a `KindScrollArea` holding the content, followed by Show more, unless you fill the default slot. */\nexport const DocumentBody = withDefault(parts.Body, \"DocumentBody\", (state: { streaming: boolean }) => [\n  h(KindScrollArea, { stickToEnd: state.streaming }, stable(scrollContent)),\n  h(DocumentExpand),\n]);\n\nconst defaultParts = () => [\n  h(\n    DocumentHeader,\n    null,\n    stable(() => [h(DocumentTitle), h(DocumentMeta), h(DocumentToolbar)]),\n  ),\n  h(DocumentBody),\n];\n\n/**\n * A document as a card: its title, kind and size, Copy and Download, and a preview that expands. A filled default\n * slot replaces the default header and body.\n */\nexport const Document = withDefault(parts.Root, \"Document\", defaultParts);\n",
      "type": "registry:ui",
      "target": "@ui/vue/document.ts"
    }
  ],
  "meta": {
    "layer": "vue"
  },
  "type": "registry:ui"
}
