{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thread-list-vue",
  "title": "Thread List (Vue)",
  "description": "Threads grouped by date, or runs by Needs you, Running and Done, with one menu to rename, pin, share, archive and delete.",
  "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/internal-menu-vue",
    "@kind-ui/internal-alert-dialog-vue"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/vue/thread-list.ts",
      "content": "import {\n  type MenuPartState,\n  type ThreadListDialogState,\n  type ThreadListGridState,\n  type ThreadListLinkState,\n  type ThreadListMenuContentState,\n  type ThreadListState,\n  type ThreadListSummaryState,\n  type ThreadListTimeState,\n  threadListPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/vue/primitive\";\nimport { defineComponent, h, type Slots, type SlotsType, type VNode, type VNodeChild } from \"vue\";\nimport {\n  KindAlertDialog,\n  KindAlertDialogBackdrop,\n  KindAlertDialogContent,\n  KindAlertDialogDescription,\n  KindAlertDialogTitle,\n} from \"./internal/alert-dialog\";\nimport { KindMenu, KindMenuContent, KindMenuItem, menuProps } from \"./internal/menu\";\n\n// `@ui-sdk/vue`'s `createParts` hands the primitive an emitter for every callback, whether or not anything listens, so\n// the callbacks whose presence offers an action (New chat, the menu's items, `select`, loading more) are declared\n// function props instead, which `@select`, `@new`, `@pin-change`, `@share` and `@load-more` bind.\nconst primitive = Object.defineProperty(\n  Object.assign((options: never) => threadListPrimitive(options), threadListPrimitive, {\n    options: {\n      ...threadListPrimitive.options,\n      onSelect: \"action\",\n      onNew: \"action\",\n      onPinChange: \"action\",\n      onShare: \"action\",\n      onLoadMore: \"action\",\n    },\n  }),\n  \"name\",\n  { value: threadListPrimitive.name },\n) as typeof threadListPrimitive;\n\nconst parts = createParts(primitive, {\n  root: \"nav\",\n  new: \"button\",\n  viewport: \"div\",\n  grid: \"div\",\n  heading: \"div\",\n  \"heading-cell\": \"div\",\n  row: \"div\",\n  \"link-cell\": \"div\",\n  link: \"a\",\n  status: \"span\",\n  unread: \"span\",\n  summary: \"span\",\n  time: \"span\",\n  editor: \"input\",\n  \"more-cell\": \"div\",\n  more: \"button\",\n  unarchive: \"button\",\n  \"fold-row\": \"div\",\n  \"fold-cell\": \"div\",\n  fold: \"button\",\n  empty: \"p\",\n  menu: \"div\",\n  \"menu-content\": \"div\",\n  dialog: \"div\",\n  \"dialog-error\": \"span\",\n  \"dialog-cancel\": \"button\",\n  \"dialog-delete\": \"button\",\n  end: \"div\",\n  retry: \"button\",\n});\n\n// A part with default children, unless the host passes its own default slot.\nconst withDefault = <Part extends object>(\n  name: string,\n  part: Part,\n  children: (scope: { state: never }) => VNodeChild,\n): Part =>\n  defineComponent({\n    name,\n    inheritAttrs: false,\n    setup(_, { attrs, slots }) {\n      return () => h(part, attrs, { ...slots, default: slots.default ?? children } as Slots);\n    },\n  }) as unknown as Part;\n\n// Slots a row's parts hand each other only read the row's `value` and the part's own state, so they're marked stable:\n// a part that renders again, for its own state, doesn't render the parts inside it again, as React's elements don't.\nconst stable = (render: (scope: { state: never }) => VNodeChild) =>\n  ({ default: render, $stable: true }) as unknown as Slots;\n\n/** Scrolls the rows, of which it renders only those in view. Holds a `ThreadListGrid` and a `ThreadListEnd`. */\nexport const ThreadListViewport = parts.Viewport;\n\n/** Calls `onNew`. Reads \"New chat\" unless you pass a slot. Rendered only while `@new` is bound. */\nexport const ThreadListNew = withDefault(\"ThreadListNew\", parts.New, () => [\n  h(\"span\", { \"data-thread-list-icon\": \"new\", \"aria-hidden\": \"true\" }),\n  \"New chat\",\n]);\n\n/** \"Nothing is waiting on you.\" when grouped by status with nothing waiting or running, unless you pass a slot. */\nexport const ThreadListEmpty = withDefault(\n  \"ThreadListEmpty\",\n  parts.Empty,\n  ({ state }: { state: { text: string } }) => state.text,\n);\n\nconst heading = ({ state }: { state: { label: string; count: string } }) =>\n  state.count ? [state.label, \" \", h(\"span\", { \"data-thread-list-count\": \"\" }, state.count)] : state.label;\n\n/**\n * A group's heading, by its row key, with its count when grouped by status. A Vue component updates only when its\n * props change, as React's `memo` does.\n */\nexport const ThreadListHeading = defineComponent({\n  name: \"ThreadListHeading\",\n  inheritAttrs: false,\n  props: { value: { type: String, required: true } },\n  slots: Object as SlotsType<{ render?: Record<string, unknown> }>,\n  setup(props, { attrs, slots }) {\n    return () => {\n      const cell = () => h(parts.HeadingCell, { value: props.value }, stable(heading));\n      // A host's `#render` slot may change, so the heading renders again with it.\n      return h(\n        parts.Heading,\n        { ...attrs, value: props.value },\n        slots.render ? { default: cell, render: slots.render } : stable(cell),\n      );\n    };\n  },\n});\n\nconst fold = ({ state }: { state: { label: string } }) => [\n  h(\"span\", { \"data-thread-list-icon\": \"fold\", \"aria-hidden\": \"true\" }),\n  state.label,\n];\n\n/**\n * The row after \"Done\"'s threads: \"12 more done\", which shows a page more, then \"Show less\". A Vue component updates\n * only when its props change, as React's `memo` does.\n */\nexport const ThreadListFold = defineComponent({\n  name: \"ThreadListFold\",\n  inheritAttrs: false,\n  props: { value: { type: String, required: true } },\n  setup(props, { attrs }) {\n    return () =>\n      h(\n        parts.FoldRow,\n        { ...attrs, value: props.value },\n        stable(() =>\n          h(\n            parts.FoldCell,\n            { value: props.value },\n            stable(() => h(parts.Fold, { value: props.value }, stable(fold))),\n          ),\n        ),\n      );\n  },\n});\n\nconst summary = ({ state }: { state: ThreadListSummaryState }) => {\n  const pieces = state.pieces.map((piece, index) => (index % 2 ? h(\"code\", piece) : piece));\n  if (!state.lead) return pieces;\n  return pieces.length > 0 ? [state.lead, \" · \", ...pieces] : state.lead;\n};\n\n/** A thread's link: its title and its one mark, then its second line, unless you pass a slot. */\nexport const ThreadListLink = withDefault(\n  \"ThreadListLink\",\n  parts.Link,\n  ({ state }: { state: ThreadListLinkState }) => [\n    h(\"span\", { \"data-thread-list-title\": \"\" }, state.title),\n    h(parts.Status, { value: state.value }),\n    h(parts.Unread, { value: state.value }),\n    h(parts.Summary, { value: state.value }, stable(summary)),\n  ],\n);\n\nconst ellipsis = () => h(\"span\", { \"data-thread-list-icon\": \"more\", \"aria-hidden\": \"true\" });\nconst time = ({ state }: { state: ThreadListTimeState }) => state.label;\nconst unarchive = ({ state }: { state: { label: string } }) => state.label;\n\n/**\n * A thread's row, by its id: its link, which also opens the row's menu on a right-click or Shift+F10, how long ago it\n * changed, and its More button, or Unarchive in the archived view, which takes the time's place on hover and focus. The default slot, given\n * `{ state: { value, title } }`, replaces what the link shows. A Vue component updates only when its props change,\n * as React's `memo` does; a slot passed from a render function counts as a change, so leave it out of rows you\n * render in bulk, or mark it `$stable`.\n */\nexport const ThreadListRow = defineComponent({\n  name: \"ThreadListRow\",\n  inheritAttrs: false,\n  props: { value: { type: String, required: true } },\n  slots: Object as SlotsType<{ default?: { state: ThreadListLinkState }; render?: Record<string, unknown> }>,\n  setup(props, { attrs, slots }) {\n    return () => {\n      const value = props.value;\n      const link = slots.default;\n      // A host's link slot may change, so the parts that lead to it render again with it.\n      const toLink = link ? (render: () => VNodeChild) => ({ default: render }) : stable;\n      const row = (render: () => VNodeChild) =>\n        slots.render ? { default: render, render: slots.render } : toLink(render);\n      return h(\n        parts.Row,\n        { ...attrs, value },\n        row(() => [\n          h(\n            parts.LinkCell,\n            { value },\n            toLink(() => [\n              h(\n                ThreadListLink,\n                { value },\n                link\n                  ? {\n                      default: ({ state }: { state: ThreadListLinkState }) =>\n                        link({ state: { value: state.value, title: state.title } }),\n                    }\n                  : undefined,\n              ),\n              h(parts.Editor, { value, type: \"text\" }),\n              h(parts.Time, { value }, stable(time)),\n            ]),\n          ),\n          h(\n            parts.MoreCell,\n            { value },\n            stable(() => [\n              h(parts.More, { value, \"data-kind-icon-button\": \"\", \"data-kind-size\": \"sm\" }, stable(ellipsis)),\n              h(parts.Unarchive, { value }, stable(unarchive)),\n            ]),\n          ),\n        ]),\n      );\n    };\n  },\n});\n\nconst rows = ({ state }: { state: ThreadListGridState }) =>\n  state.visible.map((item) => {\n    const type = state.rows[item.index]?.type;\n    if (type === \"heading\") return h(ThreadListHeading, { key: item.key, value: item.key });\n    if (type === \"fold\") return h(ThreadListFold, { key: item.key, value: item.key });\n    return h(ThreadListRow, { key: item.key, value: item.key });\n  });\n\n/**\n * A `ThreadListHeading`, `ThreadListRow` or `ThreadListFold` for each row in view, unless you pass a slot, which gets\n * `{ state }`.\n */\nexport const ThreadListGrid = withDefault(\"ThreadListGrid\", parts.Grid, rows);\n\nconst items = (state: ThreadListMenuContentState) =>\n  state.actions.map((action) =>\n    h(\n      KindMenuItem,\n      {\n        key: action.value,\n        value: action.value,\n        \"data-destructive\": action.value === \"delete\" ? \"\" : undefined,\n      },\n      () => [h(\"span\", { \"data-thread-list-icon\": action.value, \"aria-hidden\": \"true\" }), action.label],\n    ),\n  );\n\n/**\n * UI SDK's `MenuContent` with Rename, Pin or Unpin, Share and Delete, each while its callback is set. A default slot,\n * given `{ state: { finalFocus, thread, actions } }`, replaces the items. Attributes go to the `MenuContent`.\n */\nexport const ThreadListMenuContent = defineComponent({\n  name: \"ThreadListMenuContent\",\n  inheritAttrs: false,\n  slots: Object as SlotsType<{\n    default?: { state: ThreadListMenuContentState };\n    render?: Record<string, unknown>;\n  }>,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(parts.MenuContent, null, {\n        default: ({ state }: { state: ThreadListMenuContentState }) => {\n          const plain = { finalFocus: state.finalFocus, thread: state.thread, actions: state.actions };\n          // Hidden from agents, which use the Thread List's own actions. Kept mounted, so Menu never shows up beside it.\n          return h(\n            KindMenuContent,\n            {\n              align: \"end\",\n              sideOffset: 4,\n              finalFocus: plain.finalFocus,\n              keepMounted: true,\n              \"data-agent-hidden\": \"\",\n              ...attrs,\n            },\n            {\n              default: () => (slots.default ? slots.default({ state: plain }) : items(plain)),\n              render: slots.render,\n            },\n          );\n        },\n      });\n  },\n});\n\n/** UI SDK Menu, shared by every row, holding a `ThreadListMenuContent` unless you pass a slot. */\nexport const ThreadListMenu = defineComponent({\n  name: \"ThreadListMenu\",\n  slots: Object as SlotsType<{ default?: () => VNode[] }>,\n  setup(_, { slots }) {\n    return () =>\n      h(parts.Menu, null, {\n        default: ({ state }: { state: MenuPartState }) =>\n          h(KindMenu, menuProps(state), { default: slots.default ?? (() => h(ThreadListMenuContent)) }),\n      });\n  },\n});\n\n/** \"Couldn't delete. Try again.\" after a delete fails, unless you pass a slot. */\nexport const ThreadListDialogError = withDefault(\n  \"ThreadListDialogError\",\n  parts.DialogError,\n  () => \"Couldn't delete. Try again.\",\n);\n\n/** Closes the dialog. Reads \"Cancel\" unless you pass a slot. */\nexport const ThreadListDialogCancel = withDefault(\n  \"ThreadListDialogCancel\",\n  parts.DialogCancel,\n  () => \"Cancel\",\n);\n\n/** Calls `onDelete`. Reads \"Delete\" unless you pass a slot. */\nexport const ThreadListDialogDelete = withDefault(\n  \"ThreadListDialogDelete\",\n  parts.DialogDelete,\n  () => \"Delete\",\n);\n\nconst answers = () =>\n  h(\"div\", { \"data-thread-list-answers\": \"\" }, [\n    h(ThreadListDialogError),\n    h(ThreadListDialogCancel),\n    h(ThreadListDialogDelete),\n  ]);\n\n/**\n * The Alert Dialog Delete opens: \"Delete chat?\", the thread's title, and Cancel and Delete, unless you pass a slot for\n * the answers. Rendered only while `onDelete` is set and `confirmDelete` is on.\n */\nexport const ThreadListDialog = defineComponent({\n  name: \"ThreadListDialog\",\n  slots: Object as SlotsType<{ default?: () => VNode[] }>,\n  setup(_, { slots }) {\n    return () =>\n      h(parts.Dialog, null, {\n        default: ({ state }: { state: ThreadListDialogState }) =>\n          h(KindAlertDialog, { controller: state.controller, dismissible: state.dismissible }, () => [\n            h(KindAlertDialogBackdrop),\n            h(\n              KindAlertDialogContent,\n              { initialFocus: state.initialFocus, finalFocus: state.finalFocus },\n              () => [\n                h(KindAlertDialogTitle, null, () => state.title),\n                h(KindAlertDialogDescription, null, () => state.description),\n                slots.default ? slots.default() : answers(),\n              ],\n            ),\n          ]),\n      });\n  },\n});\n\n/** Calls `onLoadMore` again. Reads \"Retry\" unless you pass a slot. */\nexport const ThreadListRetry = withDefault(\"ThreadListRetry\", parts.Retry, () => \"Retry\");\n\n/** After the rows while loading more: \"Loading more chats\", or \"Couldn't load more chats\" and Retry. */\nexport const ThreadListEnd = withDefault(\n  \"ThreadListEnd\",\n  parts.End,\n  ({ state }: { state: { status: ThreadListState[\"loadStatus\"] } }) =>\n    state.status === \"loading\"\n      ? [\n          h(\"span\", { \"aria-hidden\": \"true\", \"data-status-mark\": \"\", \"data-status\": \"running\" }),\n          \"Loading more chats\",\n        ]\n      : [\"Couldn't load more chats\", h(ThreadListRetry)],\n);\n\nconst defaultParts = () => [\n  h(ThreadListNew),\n  h(ThreadListEmpty),\n  h(\n    ThreadListViewport,\n    null,\n    stable(() => [h(ThreadListGrid), h(ThreadListEnd)]),\n  ),\n  h(ThreadListMenu),\n  h(ThreadListDialog),\n];\n\n/**\n * The threads as a navigation grid, grouped by pinned, the host's groups and date, or by what each run needs from the\n * person with `groupBy=\"status\"`, with New chat above and one menu of Rename, Pin, Share, Archive and Delete for every\n * row. A default slot replaces the default parts.\n */\nexport const ThreadList = withDefault(\"ThreadList\", parts.Root, defaultParts);\n",
      "type": "registry:ui",
      "target": "@ui/vue/thread-list.ts"
    }
  ],
  "meta": {
    "layer": "vue"
  },
  "type": "registry:ui"
}
