{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "conversation-search-web",
  "title": "Conversation Search (Web Components)",
  "description": "A find bar over a conversation's messages that counts matches, moves between them and marks them on the scrollbar.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/web@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/web/conversation-search.ts",
      "content": "import \"@ui-sdk/web/input\";\nimport {\n  type ConversationSearchApi,\n  type ConversationSearchOpenChangeReason,\n  type ConversationSearchOptions,\n  type ConversationSearchQueryChangeReason,\n  type ConversationSearchState,\n  conversationSearchPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts, wrappedButton } from \"@ui-sdk/web\";\nimport type { AttributeProperties, UiChangeEvent, UiElement } from \"@ui-sdk/web/events\";\n\nconst defaultParts = (describedBy: string) =>\n  `<kind-conversation-search-input><ui-input-group><ui-input data-agent-hidden><input type=\"search\" placeholder=\"Find…\" aria-describedby=\"${describedBy}\"></ui-input><kind-conversation-search-count></kind-conversation-search-count></ui-input-group></kind-conversation-search-input><kind-conversation-search-previous><button></button></kind-conversation-search-previous><kind-conversation-search-next><button></button></kind-conversation-search-next><kind-conversation-search-close><button></button></kind-conversation-search-close>`;\n\n/**\n * `<kind-conversation-search>` fills in its parts when it has no children, and points the field's description at the\n * count. Set `messages` and `conversation` (a\n * Conversation's `controller`) as properties, and pass `markschange`'s `detail.value` to the Conversation's `marks`.\n * Searching fires `querychange`, and opening or closing fires `openchange`.\n */\nexport function defineConversationSearch(): void {\n  if (customElements.get(\"kind-conversation-search\")) return;\n  createParts(conversationSearchPrimitive, {\n    root: {\n      tag: \"kind-conversation-search\",\n      state: {\n        query: { get: (api) => api.getQuery(), set: (api, query) => api.setQuery(String(query ?? \"\")) },\n        open: { get: (api) => api.isOpen(), set: (api, open) => api.setOpen(Boolean(open)) },\n      },\n      // `next`, `previous` and `close` are getters, offered only while they can run, which a copied list would freeze.\n      api: [\"search\", \"getQuery\", \"setQuery\", \"isOpen\", \"setOpen\"],\n      render: (el, instance) => {\n        const api = instance.api as ConversationSearchApi;\n        if (!el.firstElementChild) {\n          el.innerHTML = defaultParts(api.inputState().describedBy);\n          const input = el.querySelector(\"input\");\n          if (input) input.value = (instance.get() as ConversationSearchState).query;\n        }\n        const draw = () => {\n          const state = instance.get() as ConversationSearchState;\n          // UI SDK builds a new instance, with a new controller, when the element returns to the page.\n          const field = el.querySelector<Element & { controller?: unknown }>(\n            \"kind-conversation-search-input ui-input\",\n          );\n          const count = el.querySelector(\"kind-conversation-search-count\");\n          const { controller, label } = api.inputState();\n          if (field && field.controller !== controller) field.controller = controller;\n          const input = field?.querySelector(\"input\");\n          if (input && input.ariaLabel !== label) input.ariaLabel = label;\n          // The count's id follows the instance, which UI SDK builds again when the element returns to the page.\n          const stale = input && count?.id && input.getAttribute(\"aria-describedby\") !== count.id;\n          if (stale && input.ariaDescribedByElements?.[0] !== count) input.ariaDescribedByElements = [count];\n          const text = api.countText(state);\n          if (count && count.textContent !== text) count.textContent = text;\n          api.syncInput();\n        };\n        draw();\n        return instance.subscribe(draw);\n      },\n    },\n    input: \"kind-conversation-search-input\",\n    count: \"kind-conversation-search-count\",\n    previous: { tag: \"kind-conversation-search-previous\", target: wrappedButton, display: \"contents\" },\n    next: { tag: \"kind-conversation-search-next\", target: wrappedButton, display: \"contents\" },\n    close: { tag: \"kind-conversation-search-close\", target: wrappedButton, display: \"contents\" },\n  });\n}\n\nexport type KindConversationSearchEvents = {\n  querychange: UiChangeEvent<string, ConversationSearchQueryChangeReason>;\n  openchange: UiChangeEvent<boolean, ConversationSearchOpenChangeReason>;\n  markschange: CustomEvent<{ value: readonly number[] }>;\n};\n\nexport interface KindConversationSearchElement\n  extends UiElement<KindConversationSearchEvents>,\n    AttributeProperties<\n      typeof conversationSearchPrimitive,\n      \"api\" | \"messages\" | \"conversation\" | \"query\" | \"open\"\n    > {\n  messages?: ConversationSearchOptions[\"messages\"];\n  conversation?: ConversationSearchOptions[\"conversation\"];\n  get query(): string;\n  set query(query: string);\n  get open(): boolean;\n  set open(open: boolean);\n  api: Pick<ConversationSearchApi, \"search\" | \"getQuery\" | \"setQuery\" | \"isOpen\" | \"setOpen\">;\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    \"kind-conversation-search\": KindConversationSearchElement;\n    \"kind-conversation-search-input\": HTMLElement;\n    \"kind-conversation-search-count\": HTMLElement;\n    \"kind-conversation-search-previous\": HTMLElement;\n    \"kind-conversation-search-next\": HTMLElement;\n    \"kind-conversation-search-close\": HTMLElement;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/web/conversation-search.ts"
    }
  ],
  "meta": {
    "layer": "web"
  },
  "type": "registry:ui"
}
