{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "step-group-web",
  "title": "Step Group (Web Components)",
  "description": "One line that names a turn's work, with its status in words, over the host's own steps.",
  "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/step-group.ts",
      "content": "import {\n  codeSpans,\n  type StepApi,\n  type StepGroupOptions,\n  type StepGroupState,\n  type StepOpenChangeReason,\n  stepGroupPrimitive,\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 TRIGGER = `<kind-step-group-trigger><button><kind-step-group-icon></kind-step-group-icon><kind-step-group-title></kind-step-group-title><kind-step-group-meta></kind-step-group-meta></button></kind-step-group-trigger>`;\n\n// Parts this element filled in. A part someone wrote into keeps what they wrote, as React's children do. Kept\n// across instances, because UI SDK rebuilds one when the element returns to the page.\nconst owned = new WeakSet<Element>();\nconst filled = new WeakMap<Element, string>();\n\n// Writes text with its backticks as `code` elements.\nconst fill = (part: Element | null, text: string) => {\n  // Pretty-printed markup leaves whitespace in a part nobody wrote into.\n  if (!part || !(owned.has(part) || (!part.firstElementChild && !part.textContent?.trim()))) return;\n  owned.add(part);\n  if (filled.get(part) === text) return;\n  filled.set(part, text);\n  part.replaceChildren(\n    ...codeSpans(text).map((piece, index) => {\n      if (!(index % 2)) return piece;\n      const code = part.ownerDocument.createElement(\"code\");\n      code.textContent = piece;\n      return code;\n    }),\n  );\n};\n\n/**\n * `<kind-step-group>` takes its steps inside a `<kind-step-group-content>` (in a `<kind-step-group-children>`), and\n * adds its trigger before that unless it has one of its own. `items` and `kinds` are properties.\n */\nexport function defineStepGroup(): void {\n  if (customElements.get(\"kind-step-group\")) return;\n  createParts(stepGroupPrimitive, {\n    root: {\n      tag: \"kind-step-group\",\n      state: {\n        open: {\n          get: (api) => api.isOpen(),\n          set: (api, open) => api.setOpen(!!open),\n        },\n      },\n      api: [\"isOpen\", \"setOpen\", \"expand\", \"collapse\", \"toggle\"],\n      render: (el, instance) => {\n        // Lookups stay out of nested groups.\n        const own = (tag: string) =>\n          [...el.querySelectorAll(tag)].find((part) => part.closest(\"kind-step-group\") === el) ?? null;\n        // The trigger goes before the content, never the other way, so a framework rendering the steps keeps every\n        // node where it put it.\n        if (!own(\"kind-step-group-trigger\")) {\n          let content = el.querySelector(\":scope > kind-step-group-content\");\n          if (!content) content = el.appendChild(el.ownerDocument.createElement(\"kind-step-group-content\"));\n          content.insertAdjacentHTML(\"beforebegin\", TRIGGER);\n        }\n        const draw = () => {\n          const { title, meta } = instance.get() as StepGroupState;\n          fill(own(\"kind-step-group-title\"), title);\n          fill(own(\"kind-step-group-meta\"), meta);\n        };\n        draw();\n        return instance.subscribe(draw);\n      },\n    },\n    trigger: { tag: \"kind-step-group-trigger\", target: wrappedButton, display: \"contents\" },\n    icon: \"kind-step-group-icon\",\n    title: \"kind-step-group-title\",\n    meta: \"kind-step-group-meta\",\n    content: \"kind-step-group-content\",\n    children: \"kind-step-group-children\",\n  });\n}\n\nexport type KindStepGroupEvents = { openchange: UiChangeEvent<boolean, StepOpenChangeReason> };\n\nexport interface KindStepGroupElement\n  extends UiElement<KindStepGroupEvents>,\n    AttributeProperties<typeof stepGroupPrimitive, \"api\" | \"open\"> {\n  open: boolean;\n  items?: StepGroupOptions[\"items\"];\n  kinds?: StepGroupOptions[\"kinds\"];\n  api: Pick<StepApi, \"isOpen\" | \"setOpen\" | \"expand\" | \"collapse\" | \"toggle\">;\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    \"kind-step-group\": KindStepGroupElement;\n    \"kind-step-group-trigger\": HTMLElement;\n    \"kind-step-group-icon\": HTMLElement;\n    \"kind-step-group-title\": HTMLElement;\n    \"kind-step-group-meta\": HTMLElement;\n    \"kind-step-group-content\": HTMLElement;\n    \"kind-step-group-children\": HTMLElement;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/web/step-group.ts"
    }
  ],
  "meta": {
    "layer": "web"
  },
  "type": "registry:ui"
}
