@h-ai/ui 0.1.0-alpha.68 → 0.1.0-alpha.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -292,7 +292,7 @@ Client validation appears on the first blur and updates as invalid input is corr
292
292
  | ------------ | ----------- | ----------------------------------------------- |
293
293
  | `PageHeader` | Page header | `title`, `description`; supports `actions` slot |
294
294
 
295
- #### Scenes (36)
295
+ #### Scenes (40)
296
296
 
297
297
  ##### Guide (2)
298
298
 
@@ -301,11 +301,15 @@ Client validation appears on the first blur and updates as invalid input is corr
301
301
  | `GuideHost` | First-use invitations, tours and help dialog host | `guide`, `locale`, `scope`, `autoStart` |
302
302
  | `HelpCenter` | Standalone searchable help center | `articles`, `tours`, `locale`, `selectedId`, `onstart` |
303
303
 
304
- ##### App (7)
304
+ ##### App (11)
305
305
 
306
306
  | Component | Description | Key props |
307
307
  | ------------------ | ---------------------------------------------- | -------------------------------------------------------- |
308
308
  | `FeedbackModal` | Feedback modal | `open`, `onsubmit` |
309
+ | `FeedbackForm` | Standalone feedback form | `attachments`, `evidenceSummary`, `onsubmit`, `onfileschange` |
310
+ | `FeedbackList` | Server pagination, filters and processing actions | `data`, `query`, `permissions`, `onquerychange`, `onstatus` |
311
+ | `FeedbackDetail` | Diagnostic evidence, history and exports | `report`, `evidence`, `attachments`, `history`, `onexport` |
312
+ | `FeedbackScreenshot` | Image preview, highlighting and masking | `attachment`, `onannotate` |
309
313
  | `SettingsModal` | Settings modal | `open`, `onclose` |
310
314
  | `SettingsLayout` | Settings layout (section navigation + content) | `title`, `description`, `sections`, `active`, `onselect` |
311
315
  | `LanguageSwitch` | Language switcher | No props required |
@@ -313,6 +317,8 @@ Client validation appears on the first blur and updates as invalid input is corr
313
317
  | `ThemeSelector` | Full theme selector | No props required |
314
318
  | `ThemeToggle` | Light/dark toggle | No props required |
315
319
 
320
+ Descriptions are optional. Call `prepare()` from `@h-ai/feedback/client` before opening the modal. Connect `onfileschange` to attachment preparation and `onannotate` to image editing that burns annotations into the pixels. Failed submissions retain input and support local export. The list shows the description or server summary and requests pages through `onquerychange`; UI permissions do not replace server authorization. See the [feedback module](../feedback/README.en.md) for integration and offline tools.
321
+
316
322
  ##### IAM authentication (10)
317
323
 
318
324
  | Component | Description | Key props |
package/README.ja.md CHANGED
@@ -292,7 +292,7 @@ components/
292
292
  | -------------- | -------------- | ---------------------------------------------- |
293
293
  | `PageHeader` | ページヘッダー | `title`, `description`、`actions` スロット対応 |
294
294
 
295
- #### Scenes:用途別コンポーネント(36)
295
+ #### Scenes:用途別コンポーネント(40)
296
296
 
297
297
  ##### Guide:案内・ヘルプ(2)
298
298
 
@@ -301,11 +301,15 @@ components/
301
301
  | `GuideHost` | 初回案内・ガイド・ヘルプダイアログ | `guide`, `locale`, `scope`, `autoStart` |
302
302
  | `HelpCenter` | 独立して使える検索付きヘルプ | `articles`, `tours`, `locale`, `selectedId`, `onstart` |
303
303
 
304
- ##### App:アプリ全体(7)
304
+ ##### App:アプリ全体(11)
305
305
 
306
306
  | コンポーネント | 説明 | 主なプロパティ |
307
307
  | ------------------ | ------------------------------------------- | -------------------------------------------------------- |
308
308
  | `FeedbackModal` | フィードバックモーダル | `open`, `onsubmit` |
309
+ | `FeedbackForm` | 独立したフィードバックフォーム | `attachments`, `evidenceSummary`, `onsubmit`, `onfileschange` |
310
+ | `FeedbackList` | サーバー側ページング・絞り込み・処理操作 | `data`, `query`, `permissions`, `onquerychange`, `onstatus` |
311
+ | `FeedbackDetail` | 診断情報・処理履歴・エクスポート | `report`, `evidence`, `attachments`, `history`, `onexport` |
312
+ | `FeedbackScreenshot` | 画像のプレビュー・強調・マスキング | `attachment`, `onannotate` |
309
313
  | `SettingsModal` | 設定モーダル | `open`, `onclose` |
310
314
  | `SettingsLayout` | 設定レイアウト(区分ナビゲーション + 本文) | `title`, `description`, `sections`, `active`, `onselect` |
311
315
  | `LanguageSwitch` | 言語切り替え | プロパティ不要 |
@@ -313,6 +317,8 @@ components/
313
317
  | `ThemeSelector` | テーマ選択パネル | プロパティ不要 |
314
318
  | `ThemeToggle` | ライト・ダーク切り替え | プロパティ不要 |
315
319
 
320
+ 説明は任意です。モーダルを開く前に `@h-ai/feedback/client` の `prepare()` で現場を固定します。`onfileschange` で添付を準備し、`onannotate` で注釈を画像のピクセルに反映します。送信失敗時は入力を保持し、ローカルに出力できます。一覧は説明またはサーバーの要約を表示し、`onquerychange` でページを取得します。UI の権限表示とは別にサーバーの認可が必要です。接続方法とオフラインツールは [feedback モジュール](../feedback/README.ja.md) を参照してください。
321
+
316
322
  ##### IAM:認証(10)
317
323
 
318
324
  | コンポーネント | 説明 | 主なプロパティ |
package/README.md CHANGED
@@ -292,7 +292,7 @@ components/
292
292
  | ------------ | -------- | ------------------------------------------- |
293
293
  | `PageHeader` | 页面头部 | `title`, `description`,支持 `actions` 插槽 |
294
294
 
295
- #### 场景组件 Scenes(36 个)
295
+ #### 场景组件 Scenes(40 个)
296
296
 
297
297
  ##### Guide 引导与帮助(2 个)
298
298
 
@@ -301,11 +301,15 @@ components/
301
301
  | `GuideHost` | 首次邀请、页面导览与帮助弹窗宿主 | `guide`, `locale`, `scope`, `autoStart` |
302
302
  | `HelpCenter` | 可独立使用的帮助中心 | `articles`, `tours`, `locale`, `selectedId`, `onstart` |
303
303
 
304
- ##### App 应用级(7 个)
304
+ ##### App 应用级(11 个)
305
305
 
306
306
  | 组件 | 描述 | 主要属性 |
307
307
  | ---------------- | ---------------- | ------------------ |
308
308
  | `FeedbackModal` | 反馈模态框 | `open`, `onsubmit` |
309
+ | `FeedbackForm` | 独立反馈表单 | `attachments`, `evidenceSummary`, `onsubmit`, `onfileschange` |
310
+ | `FeedbackList` | 服务端分页、筛选与处理操作 | `data`, `query`, `permissions`, `onquerychange`, `onstatus` |
311
+ | `FeedbackDetail` | 诊断材料、处理历史与导出 | `report`, `evidence`, `attachments`, `history`, `onexport` |
312
+ | `FeedbackScreenshot` | 图片预览、圈选与遮挡 | `attachment`, `onannotate` |
309
313
  | `SettingsModal` | 设置模态框 | `open`, `onclose` |
310
314
  | `SettingsLayout` | 设置页布局(分区导航 + 内容区) | `title`, `description`, `sections`, `active`, `onselect` |
311
315
  | `LanguageSwitch` | 语言切换 | 无需 Props |
@@ -313,6 +317,8 @@ components/
313
317
  | `ThemeSelector` | 完整主题选择面板 | 无需 Props |
314
318
  | `ThemeToggle` | 明/暗主题切换 | 无需 Props |
315
319
 
320
+ 反馈说明可为空;宿主先用 `@h-ai/feedback/client` 的 `prepare()` 固定现场,再打开弹窗。表单通过 `onfileschange` 准备主动附件、通过 `onannotate` 将标注烧录到图片;受理失败保留输入并可本地导出。列表展示说明或服务端事实摘要,以 `onquerychange` 取得分页数据;界面权限不代替服务端授权。完整接入与离线工具见 [feedback 模块](../feedback/README.md)。
321
+
316
322
  ##### IAM 身份认证(10 个)
317
323
 
318
324
  | 组件 | 描述 | 主要属性 |
package/auto-import.d.ts CHANGED
@@ -81,6 +81,9 @@ declare global {
81
81
  const Tooltip: typeof import('@h-ai/ui')['Tooltip']
82
82
 
83
83
  // scenes - app
84
+ const FeedbackDetail: typeof import('@h-ai/ui')['FeedbackDetail']
85
+ const FeedbackForm: typeof import('@h-ai/ui')['FeedbackForm']
86
+ const FeedbackList: typeof import('@h-ai/ui')['FeedbackList']
84
87
  const FeedbackModal: typeof import('@h-ai/ui')['FeedbackModal']
85
88
  const LanguageSwitch: typeof import('@h-ai/ui')['LanguageSwitch']
86
89
  const SettingsLayout: typeof import('@h-ai/ui')['SettingsLayout']
package/auto-import.js CHANGED
@@ -71,6 +71,9 @@ const UI_COMPONENTS = new Set([
71
71
  'ToastContainer',
72
72
  'Tooltip',
73
73
  // scenes - app
74
+ 'FeedbackDetail',
75
+ 'FeedbackForm',
76
+ 'FeedbackList',
74
77
  'FeedbackModal',
75
78
  'LanguageSwitch',
76
79
  'SettingsLayout',
@@ -0,0 +1,215 @@
1
+ <!--
2
+ @component FeedbackDetail
3
+ 反馈详情与分页材料展示;操作由宿主执行并回填真实版本。
4
+ @example
5
+ ```ts
6
+ import type { ComponentProps } from 'svelte'
7
+ import { FeedbackDetail } from '@h-ai/ui'
8
+ const props: ComponentProps<typeof FeedbackDetail> = { permissions: { read: false } }
9
+ ```
10
+ -->
11
+ <script lang='ts'>
12
+ import type { DataAttributes } from '../../../types.js'
13
+ import type { FeedbackAttachmentView, FeedbackEvidenceQuery, FeedbackEvidenceView, FeedbackHistoryView, FeedbackPage, FeedbackPermissions, FeedbackReportView, FeedbackStatusChange } from './feedback-types.js'
14
+ import { uiM } from '../../../messages.js'
15
+ import { getDataAttributes } from '../../../utils.js'
16
+ import FormField from '../../compounds/FormField.svelte'
17
+ import FormLayout from '../../compounds/FormLayout.svelte'
18
+ import Pagination from '../../compounds/Pagination.svelte'
19
+ import Tabs from '../../compounds/Tabs.svelte'
20
+ import Badge from '../../primitives/Badge.svelte'
21
+ import Button from '../../primitives/Button.svelte'
22
+ import Input from '../../primitives/Input.svelte'
23
+ import Textarea from '../../primitives/Textarea.svelte'
24
+ import { collectionLabel, evidenceText, feedbackTime, imagePreviewUrl, notificationLabel } from './feedback-functions.js'
25
+
26
+ let {
27
+ report,
28
+ evidence = { items: [], total: 0, page: 1, pageSize: 20 },
29
+ attachments = [],
30
+ history = [],
31
+ permissions = {},
32
+ loading = false,
33
+ error = '',
34
+ evidenceQuery = $bindable({ page: 1, pageSize: 20 }),
35
+ onevidencequery,
36
+ onstatus,
37
+ onexport,
38
+ onretry,
39
+ onattachment,
40
+ onclose,
41
+ class: className = '',
42
+ ...restProps
43
+ }: {
44
+ report?: FeedbackReportView
45
+ evidence?: FeedbackPage<FeedbackEvidenceView>
46
+ attachments?: FeedbackAttachmentView[]
47
+ history?: FeedbackHistoryView[]
48
+ permissions?: FeedbackPermissions
49
+ loading?: boolean
50
+ error?: string
51
+ evidenceQuery?: FeedbackEvidenceQuery
52
+ onevidencequery?: (query: FeedbackEvidenceQuery) => void | Promise<void>
53
+ onstatus?: (input: FeedbackStatusChange) => void | Promise<void>
54
+ onexport?: (report: FeedbackReportView) => void | Promise<void>
55
+ onretry?: (report: FeedbackReportView) => void | Promise<void>
56
+ onattachment?: (attachment: FeedbackAttachmentView) => void | Promise<void>
57
+ onclose?: () => void
58
+ class?: string
59
+ } & DataAttributes = $props()
60
+
61
+ const dataAttributes = $derived(getDataAttributes(restProps))
62
+ let active = $state('overview')
63
+ let busy = $state(false)
64
+ let querying = $state(false)
65
+ let actionError = $state('')
66
+ let queryGeneration = 0
67
+ let failedPreviews = $state<string[]>([])
68
+ let note = $state('')
69
+ let requestId = $derived(evidenceQuery.requestId ?? '')
70
+ let errorId = $derived(evidenceQuery.errorId ?? '')
71
+ let kind = $derived(evidenceQuery.kind ?? '')
72
+ const tabs = $derived([
73
+ { key: 'overview', label: uiM('feedback_overview') },
74
+ { key: 'scene', label: uiM('feedback_scene') },
75
+ { key: 'logs', label: uiM('feedback_logs') },
76
+ { key: 'environment', label: uiM('feedback_environment') },
77
+ { key: 'history', label: uiM('feedback_history') },
78
+ ])
79
+
80
+ async function run(action: (() => void | Promise<void>) | undefined) {
81
+ if (!action || busy)
82
+ return
83
+ busy = true
84
+ actionError = ''
85
+ try {
86
+ await action()
87
+ }
88
+ catch (cause) {
89
+ actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
90
+ }
91
+ finally {
92
+ busy = false
93
+ }
94
+ }
95
+ async function query(next: Partial<FeedbackEvidenceQuery>) {
96
+ evidenceQuery = { ...evidenceQuery, ...next }
97
+ const generation = ++queryGeneration
98
+ querying = true
99
+ actionError = ''
100
+ try {
101
+ await onevidencequery?.(evidenceQuery)
102
+ }
103
+ catch (cause) {
104
+ if (generation === queryGeneration)
105
+ actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
106
+ }
107
+ finally {
108
+ if (generation === queryGeneration)
109
+ querying = false
110
+ }
111
+ }
112
+ function changeTab(tab: string) {
113
+ if (tab === 'environment')
114
+ void query({ page: 1, kind: 'environment' })
115
+ else if (tab === 'scene')
116
+ void query({ page: 1, kind: 'interaction' })
117
+ else if (tab === 'logs')
118
+ void query({ page: 1, kind: undefined })
119
+ }
120
+ </script>
121
+
122
+ <section {...dataAttributes} class={`feedback-detail min-w-0 space-y-4 ${className}`} aria-label={uiM('feedback_details')}>
123
+ {#if permissions.read === false}
124
+ <p class='alert alert-warning' role='alert'>{uiM('feedback_permission_denied')}</p>
125
+ {:else if report}
126
+ <header class='flex flex-wrap items-center justify-between gap-3'>
127
+ <div class='min-w-0'><h2 class='text-xl font-semibold break-all'>{report.number}</h2><p class='text-sm text-base-content/65'>{report.appId} · {report.appVersion || '—'} · {feedbackTime(report.createdAt)}</p></div>
128
+ <div class='flex flex-wrap items-center gap-2'>
129
+ <Badge variant={report.status === 'handled' ? 'success' : 'ghost'}>{uiM(report.status === 'handled' ? 'feedback_handled' : 'feedback_pending')}</Badge>
130
+ {#if permissions.export && onexport}<Button size='sm' disabled={busy} onclick={() => run(() => onexport(report!))}>{uiM('feedback_export')}</Button>{/if}
131
+ {#if onclose}<Button size='sm' variant='ghost' onclick={onclose}>{uiM('feedback_close')}</Button>{/if}
132
+ </div>
133
+ </header>
134
+ {#if error || actionError}<p class='alert alert-error break-words' role='alert'>{error || actionError}</p>{/if}
135
+ {#if loading || querying}<p class='text-sm text-base-content/60' role='status'>{uiM('feedback_loading')}</p>{/if}
136
+ <Tabs items={tabs} bind:active onchange={changeTab}>
137
+ {#snippet children({ active: tab })}
138
+ {#if tab === 'overview'}
139
+ <div class='space-y-4 py-4'>
140
+ <p class='whitespace-pre-wrap break-words'>{report.description || uiM('feedback_no_description')}</p>
141
+ <dl class='grid grid-cols-1 gap-3 text-sm sm:grid-cols-2 xl:grid-cols-3'>
142
+ <div><dt class='text-base-content/55'>{uiM('feedback_collection')}</dt><dd>{collectionLabel(report.collectionStatus)}</dd></div>
143
+ <div><dt class='text-base-content/55'>{uiM('feedback_notification')}</dt><dd>{notificationLabel(report.notificationStatus)}</dd></div>
144
+ <div><dt class='text-base-content/55'>{uiM('feedback_submitter')}</dt><dd class='break-all'>{report.userId || '—'}</dd></div>
145
+ <div><dt class='text-base-content/55'>{uiM('feedback_revision')}</dt><dd>{report.evidenceRevision}</dd></div>
146
+ {#if report.buildId}<div><dt class='text-base-content/55'>{uiM('feedback_build_id')}</dt><dd class='break-all'>{report.buildId}</dd></div>{/if}
147
+ {#if report.commit}<div><dt class='text-base-content/55'>{uiM('feedback_commit')}</dt><dd class='break-all'>{report.commit}</dd></div>{/if}
148
+ </dl>
149
+ </div>
150
+ {:else if tab === 'scene' || tab === 'logs' || tab === 'environment'}
151
+ <div class='space-y-4 py-4'>
152
+ {#if tab === 'scene'}
153
+ <div class='grid grid-cols-1 gap-3 xl:grid-cols-2'>
154
+ {#each attachments as attachment (attachment.id)}
155
+ <article class='rounded-lg border border-base-content/10 p-3 min-w-0 space-y-2'>
156
+ <p class='font-medium text-sm break-all'>{attachment.name}</p>
157
+ {#if attachment.mimeType?.startsWith('image/') && imagePreviewUrl(attachment.url)}<img src={imagePreviewUrl(attachment.url)} alt={attachment.name} class='max-w-full rounded' loading='lazy' referrerpolicy='no-referrer' onerror={() => failedPreviews = [...failedPreviews, attachment.id]} onload={() => failedPreviews = failedPreviews.filter(id => id !== attachment.id)} />{/if}
158
+ {#if failedPreviews.includes(attachment.id)}<p class='text-warning text-sm'>{uiM('feedback_preview_failed')}</p>{/if}
159
+ {#if attachment.missingReason}<p class='text-warning break-words'>{uiM('feedback_missing')}: {attachment.missingReason}</p>
160
+ {:else if onattachment}<Button size='sm' variant='ghost' disabled={busy} onclick={() => run(() => onattachment(attachment))}>{uiM('feedback_download')}</Button>{/if}
161
+ </article>
162
+ {/each}
163
+ </div>
164
+ {/if}
165
+ {#if tab === 'logs'}
166
+ <form onsubmit={(event) => {
167
+ event.preventDefault()
168
+ void query({ page: 1, kind: kind || undefined, requestId: requestId || undefined, errorId: errorId || undefined })
169
+ }}>
170
+ <FormLayout columns={2}>
171
+ <FormField label={uiM('feedback_kind')}><Input bind:value={kind} /></FormField>
172
+ <FormField label={uiM('feedback_request_id')}><Input bind:value={requestId} /></FormField>
173
+ <FormField label={uiM('feedback_error_id')}><Input bind:value={errorId} /></FormField>
174
+ <Button type='submit' size='sm' loading={querying}>{uiM('feedback_apply_filters')}</Button>
175
+ </FormLayout>
176
+ </form>
177
+ {/if}
178
+ {#if !evidence.items.length && !loading}<p class='rounded-lg bg-base-200 p-4 text-sm text-base-content/65'>{uiM('feedback_evidence_empty')}</p>{/if}
179
+ {#each evidence.items as item (item.id)}
180
+ <article class='min-w-0 rounded-lg border border-base-content/10 p-3 space-y-2'>
181
+ <div class='flex flex-wrap gap-x-3 gap-y-1 text-xs text-base-content/65'><span>{feedbackTime(item.timestamp)}</span><span>{uiM('feedback_source')}: {item.source} #{item.sequence}</span><span>{item.kind}</span>{#if item.requestId}<span class='break-all'>{uiM('feedback_request_id')}: {item.requestId}</span>{/if}{#if item.errorId}<span class='text-error break-all'>{uiM('feedback_error_id')}: {item.errorId}</span>{/if}</div>
182
+ {#if item.missingReason}<p class='text-warning text-sm break-words'>{uiM('feedback_missing')}: {item.missingReason}</p>{/if}
183
+ <pre class='max-w-full overflow-x-auto whitespace-pre-wrap break-all rounded bg-base-200 p-3 text-xs'>{evidenceText(item.data)}</pre>
184
+ </article>
185
+ {/each}
186
+ <div class='overflow-x-auto'><Pagination page={evidence.page} total={evidence.total} pageSize={evidence.pageSize} showSizeChanger onchange={page => query({ page })} onpagesizechange={pageSize => query({ page: 1, pageSize })} /></div>
187
+ </div>
188
+ {:else if tab === 'history'}
189
+ <div class='space-y-4 py-4'>
190
+ <p class='text-sm'>{uiM('feedback_notification')}: {notificationLabel(report.notificationStatus)}</p>
191
+ {#if onstatus && ((report.status === 'pending' && permissions.process) || (report.status === 'handled' && permissions.reopen))}
192
+ <form class='space-y-3' onsubmit={(event) => {
193
+ event.preventDefault()
194
+ void run(() => onstatus({ id: report!.id, status: report!.status === 'pending' ? 'handled' : 'pending', expectedVersion: report!.version, note: note.trim() || undefined }))
195
+ }}>
196
+ <FormLayout><FormField label={uiM('feedback_note')}><Textarea bind:value={note} maxlength={4000} disabled={busy} /></FormField></FormLayout>
197
+ <Button type='submit' variant='primary' loading={busy}>{uiM(report.status === 'pending' ? 'feedback_handle' : 'feedback_reopen')}</Button>
198
+ </form>
199
+ {/if}
200
+ {#if permissions.retry && onretry && (report.notificationStatus === 'failed' || report.collectionStatus === 'partial' || report.collectionStatus === 'failed')}<Button size='sm' disabled={busy} onclick={() => run(() => onretry(report!))}>{uiM('feedback_retry')}</Button>{/if}
201
+ <ol class='space-y-3'>
202
+ {#each history as change (change.id)}
203
+ <li class='rounded-lg border border-base-content/10 p-3 text-sm'><p class='text-base-content/60'>{feedbackTime(change.createdAt)} · {change.actorId}</p><p>{uiM(change.fromStatus === 'handled' ? 'feedback_handled' : 'feedback_pending')} → {uiM(change.toStatus === 'handled' ? 'feedback_handled' : 'feedback_pending')}</p>{#if change.note}<p class='mt-1 whitespace-pre-wrap break-words'>{change.note}</p>{/if}</li>
204
+ {/each}
205
+ </ol>
206
+ </div>
207
+ {/if}
208
+ {/snippet}
209
+ </Tabs>
210
+ {:else if loading}
211
+ <p role='status'>{uiM('feedback_loading')}</p>
212
+ {:else}
213
+ <p class='text-sm text-base-content/60'>{uiM('feedback_empty')}</p>
214
+ {/if}
215
+ </section>
@@ -0,0 +1,32 @@
1
+ import type { DataAttributes } from '../../../types.js';
2
+ import type { FeedbackAttachmentView, FeedbackEvidenceQuery, FeedbackEvidenceView, FeedbackHistoryView, FeedbackPage, FeedbackPermissions, FeedbackReportView, FeedbackStatusChange } from './feedback-types.js';
3
+ type $$ComponentProps = {
4
+ report?: FeedbackReportView;
5
+ evidence?: FeedbackPage<FeedbackEvidenceView>;
6
+ attachments?: FeedbackAttachmentView[];
7
+ history?: FeedbackHistoryView[];
8
+ permissions?: FeedbackPermissions;
9
+ loading?: boolean;
10
+ error?: string;
11
+ evidenceQuery?: FeedbackEvidenceQuery;
12
+ onevidencequery?: (query: FeedbackEvidenceQuery) => void | Promise<void>;
13
+ onstatus?: (input: FeedbackStatusChange) => void | Promise<void>;
14
+ onexport?: (report: FeedbackReportView) => void | Promise<void>;
15
+ onretry?: (report: FeedbackReportView) => void | Promise<void>;
16
+ onattachment?: (attachment: FeedbackAttachmentView) => void | Promise<void>;
17
+ onclose?: () => void;
18
+ class?: string;
19
+ } & DataAttributes;
20
+ /**
21
+ * FeedbackDetail
22
+ * 反馈详情与分页材料展示;操作由宿主执行并回填真实版本。
23
+ * @example
24
+ * ```ts
25
+ * import type { ComponentProps } from 'svelte'
26
+ * import { FeedbackDetail } from '@h-ai/ui'
27
+ * const props: ComponentProps<typeof FeedbackDetail> = { permissions: { read: false } }
28
+ * ```
29
+ */
30
+ declare const FeedbackDetail: import("svelte").Component<$$ComponentProps, {}, "evidenceQuery">;
31
+ type FeedbackDetail = ReturnType<typeof FeedbackDetail>;
32
+ export default FeedbackDetail;
@@ -0,0 +1,271 @@
1
+ <!--
2
+ @component FeedbackForm
3
+ 可独立承载的反馈收集表单;采集、上传和导出由宿主提供。
4
+ @example
5
+ ```ts
6
+ import type { ComponentProps } from 'svelte'
7
+ import { FeedbackForm } from '@h-ai/ui'
8
+ const props: ComponentProps<typeof FeedbackForm> = { onsubmit: async () => ({ number: 'FB-1', collectionStatus: 'collecting' }) }
9
+ ```
10
+ -->
11
+ <script lang='ts'>
12
+ import type { DataAttributes, FormLayoutOptions } from '../../../types.js'
13
+ import type { FeedbackAnnotation, FeedbackAttachmentView, FeedbackEvidenceSummary, FeedbackFormData, FeedbackReceipt } from './feedback-types.js'
14
+ import { untrack } from 'svelte'
15
+ import { uiM } from '../../../messages.js'
16
+ import { getDataAttributes } from '../../../utils.js'
17
+ import FormField from '../../compounds/FormField.svelte'
18
+ import FormLayout from '../../compounds/FormLayout.svelte'
19
+ import BareInput from '../../primitives/BareInput.svelte'
20
+ import Button from '../../primitives/Button.svelte'
21
+ import Input from '../../primitives/Input.svelte'
22
+ import Select from '../../primitives/Select.svelte'
23
+ import Textarea from '../../primitives/Textarea.svelte'
24
+ import { collectionLabel } from './feedback-functions.js'
25
+ import FeedbackScreenshot from './FeedbackScreenshot.svelte'
26
+
27
+ /**
28
+ * 反馈表单的宿主注入契约,网络和采集服务通过动作回调接入。
29
+ * @example
30
+ * ```ts
31
+ * import type { ComponentProps } from 'svelte'
32
+ * import { FeedbackForm } from '@h-ai/ui'
33
+ * const props: ComponentProps<typeof FeedbackForm> = {
34
+ * onsubmit: async () => ({ number: 'FB-1', collectionStatus: 'collecting' }),
35
+ * }
36
+ * ```
37
+ */
38
+ interface Props extends FormLayoutOptions {
39
+ labels?: {
40
+ title?: string
41
+ description?: string
42
+ typeLabel?: string
43
+ contentLabel?: string
44
+ contentPlaceholder?: string
45
+ contactLabel?: string
46
+ contactPlaceholder?: string
47
+ cancel?: string
48
+ submit?: string
49
+ errorEmpty?: string
50
+ errorSubmit?: string
51
+ types?: { bug?: string, feature?: string, question?: string, other?: string }
52
+ }
53
+ attachments?: FeedbackAttachmentView[]
54
+ evidenceSummary?: FeedbackEvidenceSummary[]
55
+ onsubmit?: (input: FeedbackFormData) => Promise<void | FeedbackReceipt>
56
+ onannotate?: (annotation: FeedbackAnnotation) => Promise<void>
57
+ /** 宿主准备附件并回填 attachments,使主动添加的图片也可预览、遮挡和标注。 */
58
+ onfileschange?: (files: File[]) => Promise<void>
59
+ onexport?: (input: FeedbackFormData) => Promise<void>
60
+ oncancel?: () => void
61
+ oncomplete?: () => void
62
+ /** 准备新现场后更新,关闭弹窗不会丢失未提交内容。 */
63
+ resetKey?: string
64
+ receipt?: FeedbackReceipt
65
+ class?: string
66
+ }
67
+
68
+ let {
69
+ labels = {},
70
+ attachments = [],
71
+ evidenceSummary = [],
72
+ onsubmit,
73
+ onannotate,
74
+ onfileschange,
75
+ onexport,
76
+ oncancel,
77
+ oncomplete,
78
+ resetKey = '',
79
+ receipt = $bindable(),
80
+ columns = 1,
81
+ labelPosition = 'top',
82
+ labelWidth = '8rem',
83
+ class: className = '',
84
+ ...restProps
85
+ }: Props & DataAttributes = $props()
86
+
87
+ const dataAttributes = $derived(getDataAttributes(restProps))
88
+ const instanceId = $props.id()
89
+ let description = $state('')
90
+ let contact = $state('')
91
+ let feedbackType = $state<NonNullable<FeedbackFormData['type']>>('bug')
92
+ let files = $state<File[]>([])
93
+ let removedAttachmentIds = $state<string[]>([])
94
+ let loading = $state(false)
95
+ let annotating = $state(false)
96
+ let staging = $state(false)
97
+ let filesError = $state(false)
98
+ let exporting = $state(false)
99
+ let error = $state('')
100
+ let previousKey = $state(untrack(() => resetKey))
101
+ const visibleAttachments = $derived(attachments.filter(item => !removedAttachmentIds.includes(item.id)))
102
+ const typeOptions = $derived([
103
+ { value: 'bug', label: labels.types?.bug ?? uiM('feedback_type_bug') },
104
+ { value: 'feature', label: labels.types?.feature ?? uiM('feedback_type_feature') },
105
+ { value: 'question', label: labels.types?.question ?? uiM('feedback_type_question') },
106
+ { value: 'other', label: labels.types?.other ?? uiM('feedback_type_other') },
107
+ ])
108
+
109
+ $effect(() => {
110
+ if (previousKey !== resetKey) {
111
+ previousKey = resetKey
112
+ description = ''
113
+ contact = ''
114
+ files = []
115
+ filesError = false
116
+ removedAttachmentIds = []
117
+ receipt = undefined
118
+ error = ''
119
+ }
120
+ })
121
+
122
+ function values(): FeedbackFormData {
123
+ return { description: description.trim(), type: feedbackType, contact: contact.trim() || undefined, files: [...files], removedAttachmentIds: [...removedAttachmentIds] }
124
+ }
125
+
126
+ async function submit(event: SubmitEvent) {
127
+ event.preventDefault()
128
+ if (loading || annotating || staging || (onfileschange && filesError) || receipt)
129
+ return
130
+ if (!onsubmit) {
131
+ error = labels.errorSubmit ?? uiM('feedback_error_submit')
132
+ return
133
+ }
134
+ loading = true
135
+ error = ''
136
+ try {
137
+ const result = await onsubmit(values())
138
+ if (result)
139
+ receipt = result
140
+ else
141
+ oncomplete?.()
142
+ }
143
+ catch (cause) {
144
+ error = cause instanceof Error ? cause.message : labels.errorSubmit ?? uiM('feedback_error_submit')
145
+ }
146
+ finally {
147
+ loading = false
148
+ }
149
+ }
150
+
151
+ async function saveLocal() {
152
+ if (!onexport || exporting || annotating || staging)
153
+ return
154
+ exporting = true
155
+ try {
156
+ await onexport(values())
157
+ }
158
+ catch (cause) {
159
+ error = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
160
+ }
161
+ finally {
162
+ exporting = false
163
+ }
164
+ }
165
+
166
+ async function annotate(annotation: FeedbackAnnotation) {
167
+ if (!onannotate || loading)
168
+ return
169
+ annotating = true
170
+ try {
171
+ await onannotate(annotation)
172
+ }
173
+ finally {
174
+ annotating = false
175
+ }
176
+ }
177
+
178
+ async function stageFiles() {
179
+ if (!onfileschange || staging || !files.length)
180
+ return
181
+ staging = true
182
+ filesError = false
183
+ error = ''
184
+ try {
185
+ await onfileschange([...files])
186
+ files = []
187
+ }
188
+ catch (cause) {
189
+ filesError = true
190
+ error = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
191
+ }
192
+ finally {
193
+ staging = false
194
+ }
195
+ }
196
+
197
+ function selectFiles(event: Event & { currentTarget: HTMLInputElement }) {
198
+ files = [...files, ...Array.from(event.currentTarget.files ?? [])]
199
+ // 清空原生选择值允许再次选择同名文件,不绑定浏览器的文件路径。
200
+ event.currentTarget.value = ''
201
+ if (onfileschange)
202
+ void stageFiles()
203
+ }
204
+
205
+ function removeFile(index: number) {
206
+ files = files.filter((_, position) => position !== index)
207
+ if (!files.length)
208
+ filesError = false
209
+ }
210
+ </script>
211
+
212
+ <form {...dataAttributes} class={`feedback-form min-w-0 space-y-4 ${className}`} onsubmit={submit} data-feedback-ui='true' data-feedback-ignore='true'>
213
+ {#if error}<div class='alert alert-error break-words' role='alert'>{error}</div>{/if}
214
+ {#if receipt}
215
+ <div role='status' class='alert alert-success block space-y-2 break-words'>
216
+ <p class='font-medium'>{uiM('feedback_accepted', { number: receipt.number })}</p>
217
+ <p>{collectionLabel(receipt.collectionStatus)}</p>
218
+ <p class='text-sm'>{uiM('feedback_accepted_hint')}</p>
219
+ </div>
220
+ {:else}
221
+ <p class='text-sm text-base-content/65'>{labels.description ?? uiM('feedback_quick_hint')}</p>
222
+ <FormLayout {columns} {labelPosition} {labelWidth}>
223
+ <FormField for={`${instanceId}-description`} label={labels.contentLabel ?? uiM('feedback_optional_description')}>
224
+ <Textarea id={`${instanceId}-description`} name='description' class='h-28' maxlength={10000} placeholder={labels.contentPlaceholder ?? uiM('feedback_content_placeholder')} bind:value={description} disabled={loading} />
225
+ </FormField>
226
+ </FormLayout>
227
+ {#if visibleAttachments.length}
228
+ <section class='space-y-3' aria-label={uiM('feedback_screenshots')}>
229
+ {#each visibleAttachments as attachment (attachment.id)}
230
+ <div class='rounded-lg border border-base-content/10 p-3 min-w-0 space-y-2'>
231
+ <div class='flex items-center justify-between gap-3'>
232
+ <span class='min-w-0 text-sm break-all'>{attachment.name}</span>
233
+ <Button size='xs' variant='ghost' disabled={loading} ariaLabel={`${uiM('feedback_remove')} ${attachment.name}`} onclick={() => removedAttachmentIds = [...removedAttachmentIds, attachment.id]}>{uiM('feedback_remove')}</Button>
234
+ </div>
235
+ {#if attachment.mimeType?.startsWith('image/') && attachment.url}<FeedbackScreenshot {attachment} onannotate={!loading && onannotate ? annotate : undefined} />{/if}
236
+ {#if attachment.missingReason}<p class='text-warning text-sm break-words'>{uiM('feedback_missing')}: {attachment.missingReason}</p>{/if}
237
+ </div>
238
+ {/each}
239
+ </section>
240
+ {/if}
241
+ <details class='rounded-lg border border-base-content/10 p-3'>
242
+ <summary class='cursor-pointer text-sm font-medium'>{uiM('feedback_more')}</summary>
243
+ <div class='pt-3 space-y-4'>
244
+ <FormLayout {columns} {labelPosition} {labelWidth}>
245
+ <FormField for={`${instanceId}-type`} label={labels.typeLabel ?? uiM('feedback_type_label')}><Select id={`${instanceId}-type`} options={typeOptions} bind:value={feedbackType} disabled={loading} /></FormField>
246
+ <FormField for={`${instanceId}-contact`} label={labels.contactLabel ?? uiM('feedback_contact_label')}><Input id={`${instanceId}-contact`} placeholder={labels.contactPlaceholder ?? uiM('feedback_contact_placeholder')} bind:value={contact} maxlength={254} autocomplete='email' disabled={loading} /></FormField>
247
+ <FormField for={`${instanceId}-files`} label={uiM('feedback_add_files')}><BareInput id={`${instanceId}-files`} type='file' accept='.png,.jpg,.jpeg,.webp,.txt,.log,.json,image/png,image/jpeg,image/webp,text/plain,application/json' multiple disabled={loading || staging} class='file-input file-input-bordered w-full' onchange={selectFiles} /></FormField>
248
+ </FormLayout>
249
+ {#each files as file, index (`${file.name}:${file.lastModified}:${index}`)}
250
+ <div class='flex items-center gap-2 min-w-0 text-sm'><span class='min-w-0 flex-1 break-all'>{file.name}</span><Button size='xs' variant='ghost' disabled={loading || staging} ariaLabel={`${uiM('feedback_remove')} ${file.name}`} onclick={() => removeFile(index)}>{uiM('feedback_remove')}</Button></div>
251
+ {/each}
252
+ {#if onfileschange && filesError}<Button size='sm' loading={staging} onclick={stageFiles}>{uiM('feedback_retry')}</Button>{/if}
253
+ </div>
254
+ </details>
255
+ {#if evidenceSummary.length}
256
+ <details class='rounded-lg border border-base-content/10 p-3'>
257
+ <summary class='cursor-pointer text-sm font-medium'>{uiM('feedback_materials')}</summary>
258
+ <dl class='space-y-2 pt-3 text-sm'>
259
+ {#each evidenceSummary as item, index (`${item.label}:${index}`)}
260
+ <div class='min-w-0'><dt class='font-medium'>{item.label}{item.count === undefined ? '' : ` · ${item.count}`}</dt><dd class='text-base-content/65 break-words'>{item.status === 'missing' ? uiM('feedback_missing') : item.status === 'not-applicable' ? uiM('feedback_not_applicable') : item.status === 'partial' ? uiM('feedback_partial') : uiM('feedback_complete')}{item.detail ? ` · ${item.detail}` : ''}</dd></div>
261
+ {/each}
262
+ </dl>
263
+ </details>
264
+ {/if}
265
+ {/if}
266
+ <div class='flex flex-wrap justify-end gap-2 border-t border-base-content/10 pt-4'>
267
+ {#if onexport}<Button variant='ghost' loading={exporting} disabled={annotating || staging} onclick={saveLocal}>{uiM('feedback_local_export')}</Button>{/if}
268
+ {#if oncancel}<Button variant='ghost' onclick={oncancel}>{receipt ? uiM('feedback_close') : labels.cancel ?? uiM('feedback_cancel')}</Button>{/if}
269
+ {#if !receipt}<Button type='submit' variant='primary' loading={loading || staging} disabled={annotating || Boolean(onfileschange && filesError)}>{labels.submit ?? uiM('feedback_submit')}</Button>{/if}
270
+ </div>
271
+ </form>