# Sources

> 把引用依据收为轻量来源列表，并将打开动作交给宿主。

网页来源：/components/sources

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

`QuireSources` 接收有稳定 `id` 的来源，可用于文档依据、研究资料或 Chat 回答。默认收起；展开后仍可读到不可用的条目，但只有可用来源会发出 `navigate` 意图。组件不会自行打开 URL。

### 示例：sources/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireSources } from '@quirekit/ui/vue';
import type { QuireKitSource, QuireKitSourceNavigateDetails } from '@quirekit/ui';

const sources: QuireKitSource[] = [
  { id: 'guide', title: '公共 UI 组件接入指南', label: '设计文档', description: '组件通过公开属性和事件交付展示与操作意图。' },
  { id: 'contract', title: 'Message 与 MessagePart 合同', label: '开发资料', description: 'Part 具有稳定身份，内容更新不会重挂相邻来源。' },
  { id: 'old', title: '旧版计划附件', unavailable: true, description: '原资源已移除，保留引用位置供核查。' }
];
const result = ref('');
/** Show the host-owned request without navigating away from the example.
 * @param details - Source identity selected by the reader.
 */
function navigate(details: QuireKitSourceNavigateDetails): void {
  result.value = `请求打开：${details.sourceId}`;
}
</script>

<template>
  <div class="grid min-w-0 gap-qk-inline p-qk-surface" data-sources-demo>
    <p class="m-0">这份方案综合了组件指南与消息合同，旧附件仍保留来源说明。</p>
    <QuireSources :sources="sources" @navigate="navigate" />
    <p v-if="result" class="m-0 text-qk-helper text-qk-text-secondary" role="status">{{ result }}</p>
  </div>
</template>
```

放在 Message 的 `sources` Part 中时，导航事件还包含 `messageId` 和 `partId`，方便宿主定位对应资源。

### 示例：sources/message

文件：`message.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireChatMessage } from '@quirekit/ui/vue';
import type { QuireKitChatSourceNavigateDetails } from '@quirekit/ui';

const result = ref('');
const parts = [
  { id: 'answer', kind: 'text' as const, text: '建议先统一消息的阅读层级，再让各产品接入自己的来源解析。' },
  { id: 'sources', kind: 'sources' as const, sources: [
    { id: 'design', title: '消息视觉与交互方案', label: '设计资料', description: '正文、过程与操作分别承担不同层级。' },
    { id: 'matrix', title: '公共组件能力矩阵', label: '开发资料', description: '来源展示公共化，资源鉴权和跳转由宿主处理。' }
  ] }
];
/** Report the scoped intent rather than navigating from the documentation page.
 * @param details - Message, part and source identities.
 */
function navigate(details: QuireKitChatSourceNavigateDetails): void {
  result.value = `${details.messageId} / ${details.partId} / ${details.sourceId}`;
}
</script>

<template>
  <div class="grid min-w-0 gap-qk-inline p-qk-surface" data-sources-message>
    <QuireChatMessage message-id="answer-1" author="助手" :parts="parts" @source-navigate="navigate" />
    <p v-if="result" class="m-0 text-qk-helper text-qk-text-secondary" role="status">{{ result }}</p>
  </div>
</template>
```

## API

### QuireSources

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| sources | 是 | — | Stable, ordered source projections. |
| title | 否 | — | Trigger title; the item count is appended automatically. The language pack supplies the default. |
| defaultOpen | 否 | false | Uncontrolled initial disclosure state. |
| open | 否 | undefined | Controlled disclosure state. |

**sources**

```ts
readonly QuireKitSource[]
```

```ts
readonly ({
  /** Stable identity supplied by the host; it is not an array position. */
  id: string;
  /** Human-readable document or page title. */
  title: string;
  /** Optional origin, such as a host name or document collection. */
  label?: undefined | string;
  /** Short context shown in the expanded list and citation preview. */
  description?: string | undefined;
  /** Optional exact excerpt; never inferred from the answer text. */
  quote?: string | undefined;
  /** A host-owned address included in the intent, never opened by the component. */
  href?: string | undefined;
  /** Missing or inaccessible resources remain visible but cannot request navigation. */
  unavailable?: boolean | undefined;
})[]
```

**title**

```ts
string | undefined
```

```ts
undefined | string
```

**defaultOpen**

```ts
boolean | undefined
```

**open**

```ts
boolean | undefined
```

#### Events

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| update\:open | 否 | — |  |
| navigate | 否 | — |  |

**update:open**

```ts
[value: boolean]
```

**navigate**

```ts
[details: QuireKitSourceNavigateDetails]
```

#### Slots

无。

#### 公开实例成员

无。

#### 相关类型

```ts
type QuireKitSource = {
  /** Stable identity supplied by the host; it is not an array position. */
  id: string;
  /** Human-readable document or page title. */
  title: string;
  /** Optional origin, such as a host name or document collection. */
  label?: undefined | string;
  /** Short context shown in the expanded list and citation preview. */
  description?: string | undefined;
  /** Optional exact excerpt; never inferred from the answer text. */
  quote?: string | undefined;
  /** A host-owned address included in the intent, never opened by the component. */
  href?: string | undefined;
  /** Missing or inaccessible resources remain visible but cannot request navigation. */
  unavailable?: boolean | undefined;
};
```
