@h-ai/ui 0.1.0-alpha.70 → 0.1.0-alpha.71

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
@@ -636,6 +636,10 @@ Defaults match `@h-ai/crypto`: `SM4` for encrypted inputs, `SM3` for hashes, and
636
636
  />
637
637
  ```
638
638
 
639
+ ### Feedback capture and delivery checks
640
+
641
+ Feedback `evidence` shows sanitized material contents. `oncapture(id?)` hides the modal for navigation and adds or replaces a screenshot. With `onfileschange`, native silent screen recording produces a previewable, removable WebM/MP4 attachment (up to 60 seconds / 5 MiB; video is not automatically masked). `FeedbackDetail.onreplay` loads complete page events on demand for playback and seeking; logs and environment remain paginated.
642
+
639
643
  ### Style dependencies
640
644
 
641
645
  Components use TailwindCSS v4 + DaisyUI. Configure application `app.css` as follows:
@@ -916,6 +920,18 @@ Browsers keep application-level `setGlobalLocale` / `createLocaleStore`. During
916
920
 
917
921
  Object keys are limited to 1024 UTF-8 bytes and reject absolute paths, backslashes, control characters and dot segments. Each public HTTP batch delete accepts 1–1000 entries. `@h-ai/storage/schemas` exposes the shared browser-safe rules. Presign expiry is an integer from 1 to 604800 seconds (Node default 3600, HTTP default 900). Upload signing accepts only key/contentType/expiresIn; contentLength/maxSize/metadata/checksum are unsupported. Invalid input returns HTTP 400 and the typed client maps it to VALIDATION_FAILED. FileUpload limits guide file selection; applications must validate actual objects on the server. Node streaming/checksum/conditional-write options have no default HTTP endpoints. See the [capability and authorization matrix (Chinese)](../storage/README.md#存储输入约束与跨端能力).
918
922
 
923
+ ## Design and interaction acceptance
924
+
925
+ Use [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md) for page decisions, [hai-ui](../cli/templates/skills/hai-ui/SKILL.md) for implementation, and [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md) for rendered UI review. See the [shared design guidance](../../.agents/instructions/ui-design.md).
926
+
927
+ Tabs support arrow/Home/End navigation, disabled items and one Tab stop. Tables expose sort/loading state and keyboard row activation. Pagination labels follow locale and external page changes update the jump input. Toolbar panels manage focus and view buttons expose selection. Empty/Alert wrap long content. theme.css imports shared tokens; focus follows the current theme and global.css respects reduced motion. Applications still implement filtering, sorting, paging and recovery.
928
+
929
+ ## Error messages and correlated logs
930
+
931
+ HTTP errors expose localized safe messages followed by `(traceId: …)`, with the same ID in `error.traceId` and `X-Trace-Id`. The framework reuses the request ID to correlate browser and server logs. Sanitized exceptions, stacks and operation context remain in logs; internal cause/ext are not exposed. Field validation returns localized field names and messages only.
932
+
933
+ Use `core.error.toPublic(error, traceId?)` at HTTP/UI boundaries and `core.error.formatMessage(error)` after translating messages; formatting is idempotent. Pass complete Error objects to logs instead of discarding their context. Database failures log driver codes, sanitized messages/stacks and table/column context; SQL text, bound values and connection credentials are excluded.
934
+
919
935
  ## Development and testing
920
936
 
921
937
  ```sh
@@ -925,12 +941,6 @@ pnpm --filter @h-ai/ui build
925
941
  pnpm --filter @h-ai/ui test
926
942
  ```
927
943
 
928
- ## Design and interaction acceptance
929
-
930
- Use [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md) for page decisions, [hai-ui](../cli/templates/skills/hai-ui/SKILL.md) for implementation, and [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md) for rendered UI review. See the [shared design guidance](../../.agents/instructions/ui-design.md).
931
-
932
- Tabs support arrow/Home/End navigation, disabled items and one Tab stop. Tables expose sort/loading state and keyboard row activation. Pagination labels follow locale and external page changes update the jump input. Toolbar panels manage focus and view buttons expose selection. Empty/Alert wrap long content. theme.css imports shared tokens; focus follows the current theme and global.css respects reduced motion. Applications still implement filtering, sorting, paging and recovery.
933
-
934
944
  ## License
935
945
 
936
946
  Apache-2.0
package/README.ja.md CHANGED
@@ -636,6 +636,10 @@ components/
636
636
  />
637
637
  ```
638
638
 
639
+ ### フィードバック収集と配布確認
640
+
641
+ フィードバックの `evidence` は脱敏済み資料の内容を表示します。`oncapture(id?)` はページ移動中に画面を閉じ、画像を追加・置換します。`onfileschange` 接続時はブラウザーの無音録画をWebM/MP4添付として確認・削除できます(最大60秒 / 5 MiB、動画は自動マスクされません)。`FeedbackDetail.onreplay` で完全な操作記録を必要時に取得して再生・移動し、ログと環境はページングで取得します。
642
+
639
643
  ### スタイルの依存関係
640
644
 
641
645
  コンポーネントは TailwindCSS v4 + DaisyUI を使います。アプリの `app.css` に次を設定します:
@@ -916,6 +920,18 @@ Node リクエストと SSR は `core.i18n.runWithLocale(locale, () => handleReq
916
920
 
917
921
  キーは UTF-8 で最大 1024 バイトで、絶対パス、バックスラッシュ、制御文字、ドットセグメントを拒否します。公開 HTTP 一括削除は一度に 1–1000 件です。共通規則はブラウザー対応の `@h-ai/storage/schemas` から参照できます。署名有効期限は整数 1–604800 秒(Node 既定 3600、HTTP 既定 900)。アップロード署名の入力は key/contentType/expiresIn のみで、contentLength/maxSize/metadata/checksum は未対応です。不正入力は HTTP 400、typed client では VALIDATION_FAILED です。FileUpload の制限は選択時の補助であり、実際のオブジェクトはサーバーで検証してください。Node のストリーム/checksum/条件付き書き込みには既定の HTTP エンドポイントがありません。[機能と認可の対応表(中国語)](../storage/README.md#存储输入约束与跨端能力)を参照してください。
918
922
 
923
+ ## デザインと操作の検証
924
+
925
+ 画面設計は [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md)、実装は [hai-ui](../cli/templates/skills/hai-ui/SKILL.md)、実画面の確認は [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md) を参照してください。[共通設計指針](../../.agents/instructions/ui-design.md) も利用できます。
926
+
927
+ Tabs は方向キー・Home/End、無効項目のスキップと単一の Tab 入口に対応します。表は並べ替え・読み込み状態と行のキーボード操作を提供します。ページ切り替えのラベルは言語に従い、外部ページ変更を入力欄に同期します。ツールバーはフォーカスと表示切り替え状態を管理します。Empty/Alert は長文を折り返します。theme.css は共通 tokens を読み込み、global.css は動きを減らす設定に対応します。業務側で検索、並べ替え、ページ切り替えと復旧処理を接続してください。
928
+
929
+ ## エラー表示とログの関連付け
930
+
931
+ HTTP エラーはローカライズ済みの安全な表示に `(traceId: …)` を付け、同じ ID を error.traceId と X-Trace-Id に返します。requestId を traceId として共有し、ブラウザーとサーバーのログを関連付けます。脱機密化した例外・スタック・操作情報はログに残し、内部 cause/ext は公開しません。項目検証は翻訳済みの項目名とメッセージだけを返します。
932
+
933
+ HTTP/UI 境界には core.error.toPublic(error, traceId?)、再翻訳後の表示には core.error.formatMessage(error) を使い、ID を重複追加しません。ログには完全な Error を渡してください。DB ログにはドライバーコード、脱機密化したメッセージ・スタック、表・列を残し、SQL 本文、バインド値と接続認証情報を記録しません。
934
+
919
935
  ## 開発とテスト
920
936
 
921
937
  ```sh
@@ -925,12 +941,6 @@ pnpm --filter @h-ai/ui build
925
941
  pnpm --filter @h-ai/ui test
926
942
  ```
927
943
 
928
- ## デザインと操作の検証
929
-
930
- 画面設計は [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md)、実装は [hai-ui](../cli/templates/skills/hai-ui/SKILL.md)、実画面の確認は [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md) を参照してください。[共通設計指針](../../.agents/instructions/ui-design.md) も利用できます。
931
-
932
- Tabs は方向キー・Home/End、無効項目のスキップと単一の Tab 入口に対応します。表は並べ替え・読み込み状態と行のキーボード操作を提供します。ページ切り替えのラベルは言語に従い、外部ページ変更を入力欄に同期します。ツールバーはフォーカスと表示切り替え状態を管理します。Empty/Alert は長文を折り返します。theme.css は共通 tokens を読み込み、global.css は動きを減らす設定に対応します。業務側で検索、並べ替え、ページ切り替えと復旧処理を接続してください。
933
-
934
944
  ## ライセンス
935
945
 
936
946
  Apache-2.0
package/README.md CHANGED
@@ -635,6 +635,10 @@ components/
635
635
  />
636
636
  ```
637
637
 
638
+ ### 反馈现场与交付检查
639
+
640
+ 反馈的 `evidence` 显示实际已脱敏材料;`oncapture(id?)` 支持隐藏弹窗后跨页补图或替换。接入 `onfileschange` 后提供浏览器原生无声短录屏,停止后作为 WebM/MP4 附件预览或删除(最多 60 秒 / 5 MiB,录屏不自动脱敏)。`FeedbackDetail.onreplay` 按需返回完整页面事件,在“页面回放”播放和定位;日志/环境仍分页读取。
641
+
638
642
  ### 样式依赖
639
643
 
640
644
  组件基于 TailwindCSS v4 + DaisyUI。应用层 `app.css` 需要以下配置:
@@ -919,6 +923,18 @@ Node 请求与 SSR 使用 `core.i18n.runWithLocale(locale, () => handleRequest()
919
923
 
920
924
  存储 key 按 UTF-8 最多 1024 字节,并拒绝绝对路径、反斜线、控制字符及点路径段;公开 HTTP 批量删除每次 1–1000 项。`@h-ai/storage/schemas` 提供浏览器安全的共同规则。预签名有效期为整数 1–604800 秒(Node 默认 3600,HTTP 默认 900);HTTP 上传仅接受 key/contentType/expiresIn,不支持 contentLength/maxSize/metadata/checksum。无效输入返回 HTTP 400,typed client 映射 VALIDATION_FAILED。FileUpload 的大小/类型限制仅为前端体验,实际对象须由应用服务端复核。Node 流式读写/checksum/条件写等没有默认 HTTP 端点。完整映射与授权边界见 [存储 API 能力](../storage/README.md#存储输入约束与跨端能力)。
921
925
 
926
+ ## 设计与交互验收
927
+
928
+ 页面设计使用 [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md),组件实现使用 [hai-ui](../cli/templates/skills/hai-ui/SKILL.md),真实界面走查使用 [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md)。[设计约定](../../.agents/instructions/ui-design.md) 说明布局、状态和示例。
929
+
930
+ Tabs 支持方向键/Home/End、禁用项跳过和单一 Tab 入口;表格提供排序与加载状态和行键盘操作;分页导航/输入名称跟随语言,外部页码同步跳页输入;工具栏弹层管理焦点,视图按钮提供选中状态。Empty/Alert 支持长内容换行。theme.css 引入共享 tokens,焦点跟随当前主题,global.css 响应减少动态效果。应用仍需接入实际筛选、排序、分页与失败恢复。
931
+
932
+ ## 错误提示与关联日志
933
+
934
+ HTTP 错误只向用户返回本地化的安全提示,末尾显示 `(traceId: …)`;响应同时包含 `error.traceId` 和 `X-Trace-Id`。框架复用本次 requestId 作为 traceId,前后端日志自动关联。底层异常、堆栈和操作上下文经凭据脱敏后写入日志,不通过 cause/ext 向用户公开。字段校验只返回本地化的字段名和错误。
935
+
936
+ `core.error.toPublic(error, traceId?)` 用于接口/UI 边界;`core.error.formatMessage(error)` 用于重新翻译后的提示,重复调用不会重复追加标识。日志传入完整 Error 对象,不能只记录通用标题或提前 String(error) 丢失上下文。数据库失败记录驱动错误码、消息、堆栈及表/列;SQL 原文、绑定值和连接凭据不进入日志。
937
+
922
938
  ## 开发测试
923
939
 
924
940
  ```sh
@@ -928,12 +944,6 @@ pnpm --filter @h-ai/ui build
928
944
  pnpm --filter @h-ai/ui test
929
945
  ```
930
946
 
931
- ## 设计与交互验收
932
-
933
- 页面设计使用 [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md),组件实现使用 [hai-ui](../cli/templates/skills/hai-ui/SKILL.md),真实界面走查使用 [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md)。[设计约定](../../.agents/instructions/ui-design.md) 说明布局、状态和示例。
934
-
935
- Tabs 支持方向键/Home/End、禁用项跳过和单一 Tab 入口;表格提供排序与加载状态和行键盘操作;分页导航/输入名称跟随语言,外部页码同步跳页输入;工具栏弹层管理焦点,视图按钮提供选中状态。Empty/Alert 支持长内容换行。theme.css 引入共享 tokens,焦点跟随当前主题,global.css 响应减少动态效果。应用仍需接入实际筛选、排序、分页与失败恢复。
936
-
937
947
  ## 许可证
938
948
 
939
949
  Apache-2.0
@@ -12,6 +12,7 @@
12
12
  import type { DataAttributes } from '../../../types.js'
13
13
  import type { FeedbackAttachmentView, FeedbackEvidenceQuery, FeedbackEvidenceView, FeedbackHistoryView, FeedbackPage, FeedbackPermissions, FeedbackReportView, FeedbackStatusChange } from './feedback-types.js'
14
14
  import { uiM } from '../../../messages.js'
15
+ import { errorMessage } from '../../../toast.svelte.js'
15
16
  import { getDataAttributes } from '../../../utils.js'
16
17
  import FormField from '../../compounds/FormField.svelte'
17
18
  import FormLayout from '../../compounds/FormLayout.svelte'
@@ -22,6 +23,7 @@
22
23
  import Input from '../../primitives/Input.svelte'
23
24
  import Textarea from '../../primitives/Textarea.svelte'
24
25
  import { collectionLabel, evidenceText, feedbackTime, imagePreviewUrl, notificationLabel } from './feedback-functions.js'
26
+ import FeedbackReplay from './FeedbackReplay.svelte'
25
27
 
26
28
  let {
27
29
  report,
@@ -37,6 +39,7 @@
37
39
  onexport,
38
40
  onretry,
39
41
  onattachment,
42
+ onreplay,
40
43
  onclose,
41
44
  class: className = '',
42
45
  ...restProps
@@ -54,6 +57,8 @@
54
57
  onexport?: (report: FeedbackReportView) => void | Promise<void>
55
58
  onretry?: (report: FeedbackReportView) => void | Promise<void>
56
59
  onattachment?: (attachment: FeedbackAttachmentView) => void | Promise<void>
60
+ /** 按需取得完整回放事件;普通材料分页不能代替完整快照。 */
61
+ onreplay?: () => Promise<FeedbackEvidenceView[]>
57
62
  onclose?: () => void
58
63
  class?: string
59
64
  } & DataAttributes = $props()
@@ -72,6 +77,7 @@
72
77
  const tabs = $derived([
73
78
  { key: 'overview', label: uiM('feedback_overview') },
74
79
  { key: 'scene', label: uiM('feedback_scene') },
80
+ { key: 'replay', label: uiM('feedback_replay') },
75
81
  { key: 'logs', label: uiM('feedback_logs') },
76
82
  { key: 'environment', label: uiM('feedback_environment') },
77
83
  { key: 'history', label: uiM('feedback_history') },
@@ -86,7 +92,7 @@
86
92
  await action()
87
93
  }
88
94
  catch (cause) {
89
- actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
95
+ actionError = errorMessage(cause, uiM('feedback_action_failed'))
90
96
  }
91
97
  finally {
92
98
  busy = false
@@ -102,7 +108,7 @@
102
108
  }
103
109
  catch (cause) {
104
110
  if (generation === queryGeneration)
105
- actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
111
+ actionError = errorMessage(cause, uiM('feedback_action_failed'))
106
112
  }
107
113
  finally {
108
114
  if (generation === queryGeneration)
@@ -147,6 +153,10 @@
147
153
  {#if report.commit}<div><dt class='text-base-content/55'>{uiM('feedback_commit')}</dt><dd class='break-all'>{report.commit}</dd></div>{/if}
148
154
  </dl>
149
155
  </div>
156
+ {:else if tab === 'replay'}
157
+ <div class='py-4'>
158
+ {#if onreplay}<FeedbackReplay load={onreplay} />{:else}<p class='text-sm'>{uiM('feedback_replay_empty')}</p>{/if}
159
+ </div>
150
160
  {:else if tab === 'scene' || tab === 'logs' || tab === 'environment'}
151
161
  <div class='space-y-4 py-4'>
152
162
  {#if tab === 'scene'}
@@ -155,6 +165,8 @@
155
165
  <article class='rounded-lg border border-base-content/10 p-3 min-w-0 space-y-2'>
156
166
  <p class='font-medium text-sm break-all'>{attachment.name}</p>
157
167
  {#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}
168
+ {#if attachment.mimeType?.startsWith('video/') && imagePreviewUrl(attachment.url)}<!-- svelte-ignore a11y_media_has_caption (用户上传的无声录屏) -->
169
+ <video src={imagePreviewUrl(attachment.url)} controls preload='metadata' class='max-w-full rounded' aria-label={attachment.name}></video>{/if}
158
170
  {#if failedPreviews.includes(attachment.id)}<p class='text-warning text-sm'>{uiM('feedback_preview_failed')}</p>{/if}
159
171
  {#if attachment.missingReason}<p class='text-warning break-words'>{uiM('feedback_missing')}: {attachment.missingReason}</p>
160
172
  {:else if onattachment}<Button size='sm' variant='ghost' disabled={busy} onclick={() => run(() => onattachment(attachment))}>{uiM('feedback_download')}</Button>{/if}
@@ -14,6 +14,8 @@ type $$ComponentProps = {
14
14
  onexport?: (report: FeedbackReportView) => void | Promise<void>;
15
15
  onretry?: (report: FeedbackReportView) => void | Promise<void>;
16
16
  onattachment?: (attachment: FeedbackAttachmentView) => void | Promise<void>;
17
+ /** 按需取得完整回放事件;普通材料分页不能代替完整快照。 */
18
+ onreplay?: () => Promise<FeedbackEvidenceView[]>;
17
19
  onclose?: () => void;
18
20
  class?: string;
19
21
  } & DataAttributes;
@@ -10,9 +10,10 @@
10
10
  -->
11
11
  <script lang='ts'>
12
12
  import type { DataAttributes, FormLayoutOptions } from '../../../types.js'
13
- import type { FeedbackAnnotation, FeedbackAttachmentView, FeedbackEvidenceSummary, FeedbackFormData, FeedbackReceipt } from './feedback-types.js'
13
+ import type { FeedbackAnnotation, FeedbackAttachmentView, FeedbackEvidenceSummary, FeedbackEvidenceView, FeedbackFormData, FeedbackReceipt } from './feedback-types.js'
14
14
  import { untrack } from 'svelte'
15
15
  import { uiM } from '../../../messages.js'
16
+ import { errorMessage } from '../../../toast.svelte.js'
16
17
  import { getDataAttributes } from '../../../utils.js'
17
18
  import FormField from '../../compounds/FormField.svelte'
18
19
  import FormLayout from '../../compounds/FormLayout.svelte'
@@ -21,7 +22,8 @@
21
22
  import Input from '../../primitives/Input.svelte'
22
23
  import Select from '../../primitives/Select.svelte'
23
24
  import Textarea from '../../primitives/Textarea.svelte'
24
- import { collectionLabel } from './feedback-functions.js'
25
+ import { collectionLabel, evidenceText, feedbackTime } from './feedback-functions.js'
26
+ import FeedbackRecorder from './FeedbackRecorder.svelte'
25
27
  import FeedbackScreenshot from './FeedbackScreenshot.svelte'
26
28
 
27
29
  /**
@@ -51,12 +53,19 @@
51
53
  types?: { bug?: string, feature?: string, question?: string, other?: string }
52
54
  }
53
55
  attachments?: FeedbackAttachmentView[]
56
+ budget?: { maxAttachmentsBytes: number, maxAttachmentBytes: number, maxAttachmentCount: number }
54
57
  evidenceSummary?: FeedbackEvidenceSummary[]
58
+ /** 采集器已脱敏的原始材料,按种类展开查看。 */
59
+ evidence?: FeedbackEvidenceView[]
55
60
  onsubmit?: (input: FeedbackFormData) => Promise<void | FeedbackReceipt>
56
61
  onannotate?: (annotation: FeedbackAnnotation) => Promise<void>
57
62
  /** 宿主准备附件并回填 attachments,使主动添加的图片也可预览、遮挡和标注。 */
58
- onfileschange?: (files: File[]) => Promise<void>
59
- onexport?: (input: FeedbackFormData) => Promise<void>
63
+ onfileschange?: (files: File[], removedAttachmentIds?: readonly string[]) => Promise<void>
64
+ /** 不传 ID 补充页面截图,传 ID 替换原截图;弹窗组件负责换页选取交互。 */
65
+ oncapture?: (attachmentId?: string) => void | Promise<void>
66
+ /** 录屏期间宿主可隐藏反馈表单,停止后重新显示。 */
67
+ onrecordingchange?: (active: boolean) => void
68
+ onexport?: (input: FeedbackFormData) => Promise<void | boolean>
60
69
  oncancel?: () => void
61
70
  oncomplete?: () => void
62
71
  /** 准备新现场后更新,关闭弹窗不会丢失未提交内容。 */
@@ -68,10 +77,14 @@
68
77
  let {
69
78
  labels = {},
70
79
  attachments = [],
80
+ budget,
71
81
  evidenceSummary = [],
82
+ evidence = [],
72
83
  onsubmit,
73
84
  onannotate,
74
85
  onfileschange,
86
+ oncapture,
87
+ onrecordingchange,
75
88
  onexport,
76
89
  oncancel,
77
90
  oncomplete,
@@ -96,9 +109,22 @@
96
109
  let staging = $state(false)
97
110
  let filesError = $state(false)
98
111
  let exporting = $state(false)
112
+ let recording = $state(false)
113
+ let exported = $state(false)
114
+ let expandedMaterials = $state<string[]>([])
99
115
  let error = $state('')
100
116
  let previousKey = $state(untrack(() => resetKey))
101
117
  const visibleAttachments = $derived(attachments.filter(item => !removedAttachmentIds.includes(item.id)))
118
+ const attachmentBytes = $derived(visibleAttachments.reduce((total, file) => total + (file.size ?? 0), 0))
119
+ const recordingBytes = $derived(budget ? Math.max(0, Math.min(budget.maxAttachmentBytes, budget.maxAttachmentsBytes - attachmentBytes)) : undefined)
120
+ const attachmentLimitReached = $derived(budget ? visibleAttachments.length >= budget.maxAttachmentCount || attachmentBytes >= budget.maxAttachmentsBytes : false)
121
+ const materialGroups = $derived([
122
+ { label: uiM('feedback_environment'), kinds: ['environment'] },
123
+ { label: uiM('feedback_logs'), kinds: ['log', 'error', 'request'] },
124
+ { label: uiM('feedback_scene'), kinds: ['interaction', 'snapshot', 'business'] },
125
+ { label: uiM('feedback_replay'), kinds: ['replay'] },
126
+ { label: uiM('feedback_missing'), kinds: ['missing'] },
127
+ ].map(group => ({ ...group, items: evidence.filter(item => group.kinds.includes(item.kind)) })).filter(group => group.items.length))
102
128
  const typeOptions = $derived([
103
129
  { value: 'bug', label: labels.types?.bug ?? uiM('feedback_type_bug') },
104
130
  { value: 'feature', label: labels.types?.feature ?? uiM('feedback_type_feature') },
@@ -115,6 +141,7 @@
115
141
  filesError = false
116
142
  removedAttachmentIds = []
117
143
  receipt = undefined
144
+ exported = false
118
145
  error = ''
119
146
  }
120
147
  })
@@ -125,7 +152,7 @@
125
152
 
126
153
  async function submit(event: SubmitEvent) {
127
154
  event.preventDefault()
128
- if (loading || annotating || staging || (onfileschange && filesError) || receipt)
155
+ if (loading || annotating || staging || exporting || recording || (onfileschange && filesError) || receipt)
129
156
  return
130
157
  if (!onsubmit) {
131
158
  error = labels.errorSubmit ?? uiM('feedback_error_submit')
@@ -141,7 +168,7 @@
141
168
  oncomplete?.()
142
169
  }
143
170
  catch (cause) {
144
- error = cause instanceof Error ? cause.message : labels.errorSubmit ?? uiM('feedback_error_submit')
171
+ error = errorMessage(cause, labels.errorSubmit ?? uiM('feedback_error_submit'))
145
172
  }
146
173
  finally {
147
174
  loading = false
@@ -152,11 +179,12 @@
152
179
  if (!onexport || exporting || annotating || staging)
153
180
  return
154
181
  exporting = true
182
+ error = ''
155
183
  try {
156
- await onexport(values())
184
+ exported = await onexport(values()) !== false
157
185
  }
158
186
  catch (cause) {
159
- error = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
187
+ error = errorMessage(cause, uiM('feedback_action_failed'))
160
188
  }
161
189
  finally {
162
190
  exporting = false
@@ -182,12 +210,12 @@
182
210
  filesError = false
183
211
  error = ''
184
212
  try {
185
- await onfileschange([...files])
213
+ await onfileschange([...files], removedAttachmentIds)
186
214
  files = []
187
215
  }
188
216
  catch (cause) {
189
217
  filesError = true
190
- error = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
218
+ error = errorMessage(cause, uiM('feedback_action_failed'))
191
219
  }
192
220
  finally {
193
221
  staging = false
@@ -207,9 +235,20 @@
207
235
  if (!files.length)
208
236
  filesError = false
209
237
  }
238
+ function recordingChanged(active: boolean) {
239
+ recording = active
240
+ onrecordingchange?.(active)
241
+ }
242
+ async function recorded(file: File) {
243
+ files = [...files, file]
244
+ await stageFiles()
245
+ }
210
246
  </script>
211
247
 
212
248
  <form {...dataAttributes} class={`feedback-form min-w-0 space-y-4 ${className}`} onsubmit={submit} data-feedback-ui='true' data-feedback-ignore='true'>
249
+ {#if budget}
250
+ <p class='text-xs text-base-content/60'>{uiM('feedback_capacity_hint', { used: (attachments.filter(item => !removedAttachmentIds.includes(item.id)).reduce((sum, item) => sum + (item.size ?? 0), 0) / 1048576).toFixed(1), total: (budget.maxAttachmentsBytes / 1048576).toFixed(1), single: (budget.maxAttachmentBytes / 1048576).toFixed(1), count: budget.maxAttachmentCount })}</p>
251
+ {/if}
213
252
  {#if error}<div class='alert alert-error break-words' role='alert'>{error}</div>{/if}
214
253
  {#if receipt}
215
254
  <div role='status' class='alert alert-success block space-y-2 break-words'>
@@ -224,15 +263,32 @@
224
263
  <Textarea id={`${instanceId}-description`} name='description' class='h-28' maxlength={10000} placeholder={labels.contentPlaceholder ?? uiM('feedback_content_placeholder')} bind:value={description} disabled={loading} />
225
264
  </FormField>
226
265
  </FormLayout>
266
+ <div class='flex flex-wrap gap-2'>
267
+ {#if oncapture}<Button size='sm' variant='outline' disabled={loading || annotating || staging || exporting} onclick={() => oncapture()}>{uiM('feedback_capture_add')}</Button>{/if}
268
+ <label class='btn btn-sm btn-ghost focus-within:outline focus-within:outline-primary'>
269
+ {uiM('feedback_add_files')}
270
+ <BareInput id={`${instanceId}-files`} type='file' aria-label={uiM('feedback_add_files')} accept='.png,.jpg,.jpeg,.webp,.webm,.mp4,.txt,.log,.json,image/png,image/jpeg,image/webp,video/webm,video/mp4,text/plain,application/json' multiple disabled={loading || staging || exporting} class='sr-only' onchange={selectFiles} />
271
+ </label>
272
+ {#if onfileschange}<FeedbackRecorder maxBytes={recordingBytes} disabled={loading || annotating || staging || exporting || attachmentLimitReached} onactive={recordingChanged} onrecord={recorded} />{/if}
273
+ </div>
274
+ {#each files as file, index (`${file.name}:${file.lastModified}:${index}`)}
275
+ <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>
276
+ {/each}
277
+ {#if onfileschange && filesError}<Button size='sm' loading={staging} onclick={stageFiles}>{uiM('feedback_retry')}</Button>{/if}
227
278
  {#if visibleAttachments.length}
228
279
  <section class='space-y-3' aria-label={uiM('feedback_screenshots')}>
229
280
  {#each visibleAttachments as attachment (attachment.id)}
230
281
  <div class='rounded-lg border border-base-content/10 p-3 min-w-0 space-y-2'>
231
282
  <div class='flex items-center justify-between gap-3'>
232
283
  <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>
284
+ <div class='flex shrink-0 gap-1'>
285
+ {#if oncapture && attachment.mimeType?.startsWith('image/')}<Button size='xs' variant='ghost' disabled={loading || annotating || staging || exporting} onclick={() => oncapture(attachment.id)}>{uiM('feedback_capture_replace')}</Button>{/if}
286
+ <Button size='xs' variant='ghost' disabled={loading || annotating || exporting} ariaLabel={`${uiM('feedback_remove')} ${attachment.name}`} onclick={() => removedAttachmentIds = [...removedAttachmentIds, attachment.id]}>{uiM('feedback_remove')}</Button>
287
+ </div>
234
288
  </div>
235
- {#if attachment.mimeType?.startsWith('image/') && attachment.url}<FeedbackScreenshot {attachment} onannotate={!loading && onannotate ? annotate : undefined} />{/if}
289
+ {#if attachment.mimeType?.startsWith('image/') && attachment.url}<FeedbackScreenshot {attachment} onannotate={!loading && !exporting && !staging && onannotate ? annotate : undefined} />{/if}
290
+ {#if attachment.mimeType?.startsWith('video/') && attachment.url}<!-- svelte-ignore a11y_media_has_caption (用户上传的无声录屏) -->
291
+ <video src={attachment.url} controls preload='metadata' class='max-w-full rounded' aria-label={attachment.name}></video>{/if}
236
292
  {#if attachment.missingReason}<p class='text-warning text-sm break-words'>{uiM('feedback_missing')}: {attachment.missingReason}</p>{/if}
237
293
  </div>
238
294
  {/each}
@@ -244,18 +300,26 @@
244
300
  <FormLayout {columns} {labelPosition} {labelWidth}>
245
301
  <FormField for={`${instanceId}-type`} label={labels.typeLabel ?? uiM('feedback_type_label')}><Select id={`${instanceId}-type`} options={typeOptions} bind:value={feedbackType} disabled={loading} /></FormField>
246
302
  <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
303
  </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
304
  </div>
254
305
  </details>
255
- {#if evidenceSummary.length}
306
+ {#if evidenceSummary.length || evidence.length}
256
307
  <details class='rounded-lg border border-base-content/10 p-3'>
257
308
  <summary class='cursor-pointer text-sm font-medium'>{uiM('feedback_materials')}</summary>
258
309
  <dl class='space-y-2 pt-3 text-sm'>
310
+ {#each materialGroups as group (group.label)}
311
+ <div class='min-w-0'>
312
+ <dt class='font-medium'>{group.label} · {group.items.length}</dt>
313
+ <dd class='space-y-2 pt-2'>
314
+ {#each group.items as item (item.id)}
315
+ <details class='rounded bg-base-200 p-2' ontoggle={event => expandedMaterials = event.currentTarget.open ? [...expandedMaterials, item.id] : expandedMaterials.filter(id => id !== item.id)}>
316
+ <summary class='cursor-pointer break-all text-xs'>{feedbackTime(item.timestamp)} · {item.kind} · {item.source} #{item.sequence}</summary>
317
+ {#if expandedMaterials.includes(item.id)}<pre class='mt-2 max-h-64 max-w-full overflow-auto whitespace-pre-wrap break-all text-xs'>{evidenceText(item.data)}</pre>{/if}
318
+ </details>
319
+ {/each}
320
+ </dd>
321
+ </div>
322
+ {/each}
259
323
  {#each evidenceSummary as item, index (`${item.label}:${index}`)}
260
324
  <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
325
  {/each}
@@ -263,9 +327,10 @@
263
327
  </details>
264
328
  {/if}
265
329
  {/if}
266
- <div class='flex flex-wrap justify-end gap-2 border-t border-base-content/10 pt-4'>
330
+ {#if exported}<p class='text-sm text-success' role='status'>{uiM('feedback_local_saved')}</p>{/if}
331
+ <div class='sticky bottom-0 z-10 flex flex-wrap justify-end gap-2 border-t border-base-content/10 bg-base-100 pt-4 pb-2'>
267
332
  {#if onexport}<Button variant='ghost' loading={exporting} disabled={annotating || staging} onclick={saveLocal}>{uiM('feedback_local_export')}</Button>{/if}
268
333
  {#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}
334
+ {#if !receipt}<Button type='submit' variant='primary' loading={loading || staging} disabled={annotating || exporting || recording || Boolean(onfileschange && filesError)}>{labels.submit ?? uiM('feedback_submit')}</Button>{/if}
270
335
  </div>
271
336
  </form>
@@ -1,5 +1,5 @@
1
1
  import type { DataAttributes, FormLayoutOptions } from '../../../types.js';
2
- import type { FeedbackAnnotation, FeedbackAttachmentView, FeedbackEvidenceSummary, FeedbackFormData, FeedbackReceipt } from './feedback-types.js';
2
+ import type { FeedbackAnnotation, FeedbackAttachmentView, FeedbackEvidenceSummary, FeedbackEvidenceView, FeedbackFormData, FeedbackReceipt } from './feedback-types.js';
3
3
  /**
4
4
  * 反馈表单的宿主注入契约,网络和采集服务通过动作回调接入。
5
5
  * @example
@@ -32,12 +32,23 @@ interface Props extends FormLayoutOptions {
32
32
  };
33
33
  };
34
34
  attachments?: FeedbackAttachmentView[];
35
+ budget?: {
36
+ maxAttachmentsBytes: number;
37
+ maxAttachmentBytes: number;
38
+ maxAttachmentCount: number;
39
+ };
35
40
  evidenceSummary?: FeedbackEvidenceSummary[];
41
+ /** 采集器已脱敏的原始材料,按种类展开查看。 */
42
+ evidence?: FeedbackEvidenceView[];
36
43
  onsubmit?: (input: FeedbackFormData) => Promise<void | FeedbackReceipt>;
37
44
  onannotate?: (annotation: FeedbackAnnotation) => Promise<void>;
38
45
  /** 宿主准备附件并回填 attachments,使主动添加的图片也可预览、遮挡和标注。 */
39
- onfileschange?: (files: File[]) => Promise<void>;
40
- onexport?: (input: FeedbackFormData) => Promise<void>;
46
+ onfileschange?: (files: File[], removedAttachmentIds?: readonly string[]) => Promise<void>;
47
+ /** 不传 ID 补充页面截图,传 ID 替换原截图;弹窗组件负责换页选取交互。 */
48
+ oncapture?: (attachmentId?: string) => void | Promise<void>;
49
+ /** 录屏期间宿主可隐藏反馈表单,停止后重新显示。 */
50
+ onrecordingchange?: (active: boolean) => void;
51
+ onexport?: (input: FeedbackFormData) => Promise<void | boolean>;
41
52
  oncancel?: () => void;
42
53
  oncomplete?: () => void;
43
54
  /** 准备新现场后更新,关闭弹窗不会丢失未提交内容。 */
@@ -12,6 +12,7 @@
12
12
  import type { DataAttributes } from '../../../types.js'
13
13
  import type { FeedbackListQuery, FeedbackPage, FeedbackPermissions, FeedbackReportView, FeedbackStatusChange } from './feedback-types.js'
14
14
  import { uiM } from '../../../messages.js'
15
+ import { errorMessage } from '../../../toast.svelte.js'
15
16
  import { getDataAttributes } from '../../../utils.js'
16
17
  import DataTable from '../../compounds/DataTable.svelte'
17
18
  import Pagination from '../../compounds/Pagination.svelte'
@@ -81,7 +82,7 @@
81
82
  await onquerychange?.(query)
82
83
  }
83
84
  catch (cause) {
84
- actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
85
+ actionError = errorMessage(cause, uiM('feedback_action_failed'))
85
86
  }
86
87
  }
87
88
  function filter(values: Record<string, unknown>) {
@@ -98,7 +99,7 @@
98
99
  await action()
99
100
  }
100
101
  catch (cause) {
101
- actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
102
+ actionError = errorMessage(cause, uiM('feedback_action_failed'))
102
103
  }
103
104
  finally {
104
105
  busyId = ''
@@ -15,19 +15,67 @@
15
15
  <script lang='ts'>
16
16
  import type { ComponentProps } from 'svelte'
17
17
  import { uiM } from '../../../messages.js'
18
+ import { errorMessage } from '../../../toast.svelte.js'
18
19
  import { getDataAttributes, portal } from '../../../utils.js'
19
20
  import Modal from '../../compounds/Modal.svelte'
21
+ import Button from '../../primitives/Button.svelte'
20
22
  import FeedbackForm from './FeedbackForm.svelte'
21
23
 
22
24
  let { open = $bindable(false), ...restProps }: ComponentProps<typeof FeedbackForm> & { open?: boolean } = $props()
23
25
  const dataAttributes = $derived(getDataAttributes(restProps))
24
26
  const formProps = $derived(Object.fromEntries(Object.entries(restProps).filter(([key]) => !key.startsWith('data-'))) as ComponentProps<typeof FeedbackForm>)
27
+ let selectingPage = $state(false)
28
+ let captureTarget = $state<string>()
29
+ let capturing = $state(false)
30
+ let captureError = $state('')
31
+
32
+ function selectPage(attachmentId?: string) {
33
+ captureTarget = attachmentId
34
+ captureError = ''
35
+ selectingPage = true
36
+ open = false
37
+ }
38
+ function returnToFeedback() {
39
+ selectingPage = false
40
+ open = true
41
+ }
42
+ function recordingChanged(active: boolean) {
43
+ open = !active
44
+ formProps.onrecordingchange?.(active)
45
+ }
46
+ async function capture() {
47
+ if (capturing)
48
+ return
49
+ capturing = true
50
+ captureError = ''
51
+ try {
52
+ await formProps.oncapture?.(captureTarget)
53
+ selectingPage = false
54
+ open = true
55
+ }
56
+ catch (cause) {
57
+ captureError = errorMessage(cause, uiM('feedback_action_failed'))
58
+ }
59
+ finally {
60
+ capturing = false
61
+ }
62
+ }
25
63
  </script>
26
64
 
27
65
  <!-- 脱离顶栏的 fixed 包含块与层叠上下文;包装层不参与布局,卸载由 portal 清理。 -->
28
66
  <div use:portal class='contents'>
67
+ {#if selectingPage && !open}
68
+ <aside class='fixed inset-x-4 bottom-4 z-[1200] mx-auto max-w-xl rounded-xl border border-base-content/15 bg-base-100 p-4 shadow-xl space-y-3' data-feedback-ignore='true' aria-label={uiM('feedback_capture_add')}>
69
+ <p class='text-sm' role='status'>{uiM('feedback_capture_hint')}</p>
70
+ {#if captureError}<p class='text-error text-sm break-words' role='alert'>{captureError}</p>{/if}
71
+ <div class='flex flex-wrap justify-end gap-2'>
72
+ <Button size='sm' variant='ghost' disabled={capturing} onclick={returnToFeedback}>{uiM('feedback_capture_return')}</Button>
73
+ <Button size='sm' variant='primary' loading={capturing} onclick={capture}>{uiM('feedback_capture_now')}</Button>
74
+ </div>
75
+ </aside>
76
+ {/if}
29
77
  <Modal {...dataAttributes} bind:open title={formProps.labels?.title ?? uiM('feedback_title')} size='lg' data-feedback-ui='true' data-feedback-ignore='true'>
30
- <FeedbackForm {...formProps} oncancel={() => {
78
+ <FeedbackForm {...formProps} onrecordingchange={recordingChanged} oncapture={formProps.oncapture ? selectPage : undefined} oncancel={() => {
31
79
  open = false
32
80
  formProps.oncancel?.()
33
81
  }} oncomplete={() => {