{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inline-citation-solid",
  "title": "Inline Citation (Solid)",
  "description": "A marker in running text whose card shows the sources it points to, paging through several.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/solid@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/solid/inline-citation.tsx",
      "content": "import { inlineCitationPrimitive } from \"@kind-ui/agent-ui/core\";\nimport type { ComponentProps, JSX } from \"@solidjs/web\";\nimport { Avatar, AvatarFallback, AvatarImage } from \"@ui-sdk/solid/avatar\";\nimport {\n  Carousel,\n  CarouselContent,\n  CarouselItem,\n  CarouselNext,\n  CarouselPrevious,\n  CarouselViewport,\n} from \"@ui-sdk/solid/carousel\";\nimport { createParts } from \"@ui-sdk/solid/primitive\";\nimport { For, Match, omit, Show, Switch } from \"solid-js\";\n\n// Every part is a `span`, so a citation is valid inside a paragraph.\nconst parts = createParts(inlineCitationPrimitive, {\n  root: \"span\",\n  trigger: \"button\",\n  content: \"span\",\n  carousel: \"span\",\n  item: \"span\",\n  link: \"a\",\n  icon: \"span\",\n  host: \"span\",\n  \"source-title\": \"span\",\n  snippet: \"span\",\n  index: \"span\",\n});\n\nconst span = (props: JSX.HTMLAttributes<HTMLSpanElement>) => <span {...props} />;\n\n// Lucide \"chevron-left\" and \"chevron-right\", see THIRD_PARTY_NOTICES.md.\nconst chevronLeft = () => (\n  <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\">\n    <path d=\"m15 18-6-6 6-6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" />\n  </svg>\n);\nconst chevronRight = () => (\n  <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\">\n    <path d=\"m9 18 6-6-6-6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" />\n  </svg>\n);\n\nexport type InlineCitationProps = Omit<ComponentProps<typeof parts.Root>, \"children\"> & {\n  children?: JSX.Element;\n};\n\n/**\n * A marker in running text for the sources a sentence came from, with a card that opens on hover, keyboard focus and\n * press. More than one source pages in the card. Any `children` replace the marker and the card.\n */\nexport function InlineCitation(props: InlineCitationProps) {\n  return (\n    <parts.Root {...omit(props, \"children\")}>\n      {(state) =>\n        props.children ?? (\n          <>\n            <InlineCitationTrigger />\n            <InlineCitationContent>\n              <Switch>\n                <Match when={state.ids.length > 1}>\n                  <InlineCitationCarousel />\n                </Match>\n                <Match when={state.ids[0]}>{(id) => <InlineCitationItem value={id()} />}</Match>\n              </Switch>\n            </InlineCitationContent>\n          </>\n        )\n      }\n    </parts.Root>\n  );\n}\n\nexport type InlineCitationTriggerProps = ComponentProps<typeof parts.Trigger>;\n\n/** The marker, which opens the card. Reads the `label` unless you pass children. */\nexport function InlineCitationTrigger(props: InlineCitationTriggerProps) {\n  return (\n    <parts.Trigger {...omit(props, \"children\")}>{props.children ?? ((state) => state.label)}</parts.Trigger>\n  );\n}\n\nexport type InlineCitationContentProps = ComponentProps<typeof parts.Content>;\n\n/** The card. Leaves focus on the marker when it opens. */\nexport function InlineCitationContent(props: InlineCitationContentProps) {\n  return <parts.Content initialFocus=\"none\" {...props} />;\n}\n\nexport type InlineCitationCarouselProps = Omit<ComponentProps<typeof parts.Carousel>, \"children\"> & {\n  children?: JSX.Element;\n};\n\n/**\n * UI SDK's Carousel, a slide per source with Previous, the page and Next below. Rendered only for more than one\n * source. Any `children` replace the slides and controls, inside the Carousel.\n */\nexport function InlineCitationCarousel(props: InlineCitationCarouselProps) {\n  return (\n    <parts.Carousel {...omit(props, \"children\")}>\n      {(state) => (\n        <Carousel\n          render={span}\n          controller={state.controller}\n          defaultPage={state.defaultPage}\n          drag={false}\n          aria-label=\"Sources\"\n        >\n          {props.children ?? (\n            <>\n              <CarouselViewport render={span}>\n                <CarouselContent render={span}>\n                  <For each={state.ids}>\n                    {(id) => (\n                      <CarouselItem render={span}>\n                        <InlineCitationItem value={id} />\n                      </CarouselItem>\n                    )}\n                  </For>\n                </CarouselContent>\n              </CarouselViewport>\n              <span data-inline-citation-controls=\"\">\n                <InlineCitationPrevious />\n                <InlineCitationIndex />\n                <InlineCitationNext />\n              </span>\n            </>\n          )}\n        </Carousel>\n      )}\n    </parts.Carousel>\n  );\n}\n\nexport type InlineCitationItemProps = ComponentProps<typeof parts.Item>;\n\n/**\n * The source whose `id` is `value`. Without children, it shows its icon, title and host name, a link when its `url`\n * is safe, then its snippet.\n */\nexport function InlineCitationItem(props: InlineCitationItemProps) {\n  return <parts.Item {...omit(props, \"children\")}>{props.children ?? <DefaultItemParts />}</parts.Item>;\n}\n\n/** Links to the source's `url` in a new tab; an `a` without `href`, which is text, when the URL isn't safe. */\nexport const InlineCitationLink = parts.Link;\n\nexport type InlineCitationIconProps = ComponentProps<typeof parts.Icon>;\n\n/** A UI SDK Avatar of the source's `favicon`, showing a link glyph until it loads or without one. */\nexport function InlineCitationIcon(props: InlineCitationIconProps) {\n  return (\n    <parts.Icon {...omit(props, \"children\")}>\n      {props.children ??\n        ((state) => (\n          <Avatar>\n            <Show when={state.favicon}>{(favicon) => <AvatarImage src={favicon()} alt=\"\" />}</Show>\n            <AvatarFallback />\n          </Avatar>\n        ))}\n    </parts.Icon>\n  );\n}\n\nexport type InlineCitationHostProps = ComponentProps<typeof parts.Host>;\n\n/** The host name of the source's `url`, unless you pass children. Rendered only with a safe `url`. */\nexport function InlineCitationHost(props: InlineCitationHostProps) {\n  return <parts.Host {...omit(props, \"children\")}>{props.children ?? ((state) => state.host)}</parts.Host>;\n}\n\nexport type InlineCitationSourceTitleProps = ComponentProps<typeof parts.SourceTitle>;\n\n/** The source's `title`, unless you pass children. */\nexport function InlineCitationSourceTitle(props: InlineCitationSourceTitleProps) {\n  return (\n    <parts.SourceTitle {...omit(props, \"children\")}>\n      {props.children ?? ((state) => state.title)}\n    </parts.SourceTitle>\n  );\n}\n\nexport type InlineCitationSnippetProps = ComponentProps<typeof parts.Snippet>;\n\n/** The source's `snippet`, unless you pass children. Rendered only with a `snippet`. */\nexport function InlineCitationSnippet(props: InlineCitationSnippetProps) {\n  return (\n    <parts.Snippet {...omit(props, \"children\")}>{props.children ?? ((state) => state.snippet)}</parts.Snippet>\n  );\n}\n\nexport type InlineCitationIndexProps = ComponentProps<typeof parts.Index>;\n\n/** Which source the card shows, like \"1 of 3\", unless you pass children. */\nexport function InlineCitationIndex(props: InlineCitationIndexProps) {\n  return <parts.Index {...omit(props, \"children\")}>{props.children ?? ((state) => state.text)}</parts.Index>;\n}\n\n// Previous and Next are hidden from agents, which takes the Carousel out of their snapshot: an agent pages with the\n// citation's own `next` and `previous`.\n\n/** Shows the previous source. */\nexport function InlineCitationPrevious(props: ComponentProps<typeof CarouselPrevious>) {\n  return (\n    <CarouselPrevious\n      aria-label=\"Previous source\"\n      data-agent-hidden=\"\"\n      data-kind-icon-button=\"\"\n      {...omit(props, \"children\")}\n    >\n      {props.children ?? chevronLeft()}\n    </CarouselPrevious>\n  );\n}\n\n/** Shows the next source. */\nexport function InlineCitationNext(props: ComponentProps<typeof CarouselNext>) {\n  return (\n    <CarouselNext\n      aria-label=\"Next source\"\n      data-agent-hidden=\"\"\n      data-kind-icon-button=\"\"\n      {...omit(props, \"children\")}\n    >\n      {props.children ?? chevronRight()}\n    </CarouselNext>\n  );\n}\n\nfunction DefaultItemParts() {\n  return (\n    <>\n      <InlineCitationLink>\n        <InlineCitationIcon />\n        <InlineCitationSourceTitle />\n        <InlineCitationHost />\n      </InlineCitationLink>\n      <InlineCitationSnippet />\n    </>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/solid/inline-citation.tsx"
    }
  ],
  "meta": {
    "layer": "solid"
  },
  "type": "registry:ui"
}
