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

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
@@ -241,6 +241,7 @@ Client validation appears on the first blur and updates as invalid input is corr
241
241
  | Component | Description | Key props |
242
242
  | ----------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
243
243
  | `Card` | Card container | `title`, `bordered`, `shadow`, `padding` |
244
+ | `JsonViewer` | JSON tree viewer | `value`, `defaultExpandedDepth`, `maxScalarLength`, `showCopy`, `onCopy`; circular references are replaced with a placeholder |
244
245
  | `DataTable` | Data table | `data`, `columns`, `keyField`, `loading`, `sortKey`, `sortDir`, `onsort`; `cell` slot and `onrowclick` (`sortable` columns support sorting) |
245
246
  | `Accordion` | Accordion | `items: AccordionItem[]` |
246
247
  | `Timeline` | Timeline | `items: TimelineItem[]` |
@@ -640,6 +641,8 @@ Defaults match `@h-ai/crypto`: `SM4` for encrypted inputs, `SM3` for hashes, and
640
641
 
641
642
  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
643
 
644
+ Feedback materials scroll independently while action buttons remain visible, so expanded content never crosses the action bar. `FeedbackList` retains an accessible name; its host provides the page heading to avoid duplicate titles.
645
+
643
646
  ### Style dependencies
644
647
 
645
648
  Components use TailwindCSS v4 + DaisyUI. Configure application `app.css` as follows:
package/README.ja.md CHANGED
@@ -241,6 +241,7 @@ components/
241
241
  | コンポーネント | 説明 | 主なプロパティ |
242
242
  | -------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
243
243
  | `Card` | カードコンテナー | `title`, `bordered`, `shadow`, `padding` |
244
+ | `JsonViewer` | JSON ツリービューアー | `value`, `defaultExpandedDepth`, `maxScalarLength`, `showCopy`, `onCopy`;循環参照はプレースホルダーに置換 |
244
245
  | `DataTable` | データテーブル | `data`, `columns`, `keyField`, `loading`, `sortKey`, `sortDir`, `onsort`、`cell` スロット、`onrowclick`(列の `sortable` で並び替え) |
245
246
  | `Accordion` | アコーディオン | `items: AccordionItem[]` |
246
247
  | `Timeline` | タイムライン | `items: TimelineItem[]` |
@@ -640,6 +641,8 @@ components/
640
641
 
641
642
  フィードバックの `evidence` は脱敏済み資料の内容を表示します。`oncapture(id?)` はページ移動中に画面を閉じ、画像を追加・置換します。`onfileschange` 接続時はブラウザーの無音録画をWebM/MP4添付として確認・削除できます(最大60秒 / 5 MiB、動画は自動マスクされません)。`FeedbackDetail.onreplay` で完全な操作記録を必要時に取得して再生・移動し、ログと環境はページングで取得します。
642
643
 
644
+ フィードバックの資料部分は独立してスクロールし、操作ボタンを常に表示して展開内容との重なりを防ぎます。`FeedbackList` はアクセシブル名を保持し、ページ見出しはホストが表示して重複を避けます。
645
+
643
646
  ### スタイルの依存関係
644
647
 
645
648
  コンポーネントは TailwindCSS v4 + DaisyUI を使います。アプリの `app.css` に次を設定します:
package/README.md CHANGED
@@ -241,6 +241,7 @@ components/
241
241
  | 组件 | 描述 | 主要属性 |
242
242
  | ----------- | -------- | ---------------------------------------- |
243
243
  | `Card` | 卡片容器 | `title`, `bordered`, `shadow`, `padding` |
244
+ | `JsonViewer` | JSON 树查看器 | `value`, `defaultExpandedDepth`, `maxScalarLength`, `showCopy`, `onCopy`;循环引用自动替换为占位符 |
244
245
  | `DataTable` | 数据表格 | `data`, `columns`, `keyField`, `loading`, `sortKey`, `sortDir`, `onsort`,`cell` 单元格插槽、`onrowclick`(列 `sortable` 可排序) |
245
246
  | `Accordion` | 手风琴 | `items: AccordionItem[]` |
246
247
  | `Timeline` | 时间线 | `items: TimelineItem[]` |
@@ -639,6 +640,8 @@ components/
639
640
 
640
641
  反馈的 `evidence` 显示实际已脱敏材料;`oncapture(id?)` 支持隐藏弹窗后跨页补图或替换。接入 `onfileschange` 后提供浏览器原生无声短录屏,停止后作为 WebM/MP4 附件预览或删除(最多 60 秒 / 5 MiB,录屏不自动脱敏)。`FeedbackDetail.onreplay` 按需返回完整页面事件,在“页面回放”播放和定位;日志/环境仍分页读取。
641
642
 
643
+ 反馈表单的材料内容独立滚动,底部按钮始终可见,展开内容不会穿过操作栏。`FeedbackList` 保留无障碍名称,页面标题由宿主显示,避免管理页重复标题。
644
+
642
645
  ### 样式依赖
643
646
 
644
647
  组件基于 TailwindCSS v4 + DaisyUI。应用层 `app.css` 需要以下配置:
package/auto-import.d.ts CHANGED
@@ -60,6 +60,7 @@ declare global {
60
60
  const FormField: typeof import('@h-ai/ui')['FormField']
61
61
  const FormLayout: typeof import('@h-ai/ui')['FormLayout']
62
62
  const InfiniteScroll: typeof import('@h-ai/ui')['InfiniteScroll']
63
+ const JsonViewer: typeof import('@h-ai/ui')['JsonViewer']
63
64
  const MessageContainer: typeof import('@h-ai/ui')['MessageContainer']
64
65
  const MessageBoxContainer: typeof import('@h-ai/ui')['MessageBoxContainer']
65
66
  const MessageBoxDialog: typeof import('@h-ai/ui')['MessageBoxDialog']
package/auto-import.js CHANGED
@@ -51,6 +51,7 @@ const UI_COMPONENTS = new Set([
51
51
  'FormField',
52
52
  'FormLayout',
53
53
  'InfiniteScroll',
54
+ 'JsonViewer',
54
55
  'MessageContainer',
55
56
  'MessageBoxContainer',
56
57
  'MessageBoxDialog',
@@ -0,0 +1,214 @@
1
+ <!--
2
+ @component JsonViewer
3
+ =============================================================================
4
+ @h-ai/ui - JsonViewer 组件
5
+ =============================================================================
6
+ JSON 数据查看组件:可折叠树、类型着色(DaisyUI 语义色,跟随主题与暗色模式)、
7
+ 复制按钮、超长文本截断。用于诊断数据、运行快照等任意 JSON 展示场景。
8
+
9
+ 使用 Svelte 5 Runes ($props, $state, $derived, $props)
10
+ =============================================================================
11
+
12
+ @example
13
+ ```ts
14
+ import { mount, unmount } from 'svelte'
15
+ import type { ComponentProps } from 'svelte'
16
+ import { JsonViewer } from '@h-ai/ui'
17
+ const props: ComponentProps<typeof JsonViewer> = { value: { name: 'wf', nested: { list: [1, 2] } } }
18
+ const component = mount(JsonViewer, { target: document.body, props })
19
+ await unmount(component)
20
+ ```
21
+ -->
22
+
23
+ <script lang='ts'>
24
+ import type { DataAttributes, JsonViewerProps } from '../../types.js'
25
+ import { onDestroy } from 'svelte'
26
+ import { uiM } from '../../messages.js'
27
+ import { cn, getDataAttributes } from '../../utils.js'
28
+
29
+ const {
30
+ value,
31
+ defaultExpandedDepth = 0,
32
+ maxScalarLength = 240,
33
+ showCopy = true,
34
+ class: className = '',
35
+ onCopy,
36
+ ...restProps
37
+ }: JsonViewerProps & DataAttributes = $props()
38
+
39
+ const dataAttributes = $derived(getDataAttributes(restProps))
40
+
41
+ /// 循环引用会出现在诊断数据中,渲染和复制前统一替换为占位符而不是抛错。
42
+ function decycle(input: unknown): unknown {
43
+ const seen = new WeakSet<object>()
44
+ function walk(current: unknown): unknown {
45
+ if (typeof current !== 'object' || current === null)
46
+ return current
47
+ if (seen.has(current))
48
+ return '[Circular]'
49
+ seen.add(current)
50
+ if (Array.isArray(current))
51
+ return current.map(walk)
52
+ const next: Record<string, unknown> = {}
53
+ for (const [key, val] of Object.entries(current))
54
+ next[key] = walk(val)
55
+ return next
56
+ }
57
+ return walk(input)
58
+ }
59
+
60
+ const safeValue = $derived(decycle(value))
61
+ const serialized = $derived(JSON.stringify(safeValue, null, 2) ?? 'undefined')
62
+
63
+ let copied = $state(false)
64
+ let copyTimer: ReturnType<typeof setTimeout> | undefined
65
+
66
+ function truncate(text: string): string {
67
+ return text.length > maxScalarLength ? `${text.slice(0, maxScalarLength)}…` : text
68
+ }
69
+
70
+ async function copyValue(event: Event) {
71
+ event.preventDefault()
72
+ event.stopPropagation()
73
+ try {
74
+ await navigator.clipboard.writeText(serialized)
75
+ copied = true
76
+ onCopy?.(serialized)
77
+ clearTimeout(copyTimer)
78
+ copyTimer = setTimeout(() => (copied = false), 2000)
79
+ }
80
+ catch {
81
+ // 剪贴板不可用(非安全上下文或权限拒绝)时静默降级,不打断树浏览。
82
+ }
83
+ }
84
+
85
+ /**
86
+ * 节点自描述:标量直接渲染,容器交给递归片段。
87
+ * @example 模块内部上下文
88
+ * ```ts
89
+ * const node: NodeModel = { key: 'enabled', value: true, depth: 1 }
90
+ * ```
91
+ */
92
+ interface NodeModel {
93
+ key: string | null
94
+ value: unknown
95
+ depth: number
96
+ }
97
+
98
+ function isContainer(v: unknown): v is Record<string, unknown> | unknown[] {
99
+ return typeof v === 'object' && v !== null
100
+ }
101
+
102
+ function containerSize(v: Record<string, unknown> | unknown[]): number {
103
+ return Array.isArray(v) ? v.length : Object.keys(v).length
104
+ }
105
+
106
+ function containerEntries(v: Record<string, unknown> | unknown[]): Array<[string, unknown]> {
107
+ if (Array.isArray(v))
108
+ return v.map((item, index) => [String(index), item] as [string, unknown])
109
+ return Object.entries(v)
110
+ }
111
+
112
+ function typeClass(v: unknown): string {
113
+ if (v === null)
114
+ return 'text-base-content/50'
115
+ switch (typeof v) {
116
+ case 'string': return 'text-success'
117
+ case 'number': return 'text-info'
118
+ case 'boolean': return 'text-warning'
119
+ case 'undefined': return 'text-base-content/50'
120
+ default: return 'text-base-content'
121
+ }
122
+ }
123
+
124
+ function scalarText(v: unknown): string {
125
+ if (v === undefined)
126
+ return 'undefined'
127
+ if (v === null)
128
+ return 'null'
129
+ if (typeof v === 'string')
130
+ return JSON.stringify(truncate(v))
131
+ return truncate(String(v))
132
+ }
133
+
134
+ /** 大容器折叠可显著降低 DOM 数量,200 条以内保持完整交互。 */
135
+ function childKeys(v: Record<string, unknown> | unknown[]): Array<[string, unknown]> {
136
+ return containerSize(v) > 200 ? containerEntries(v).slice(0, 200) : containerEntries(v)
137
+ }
138
+
139
+ onDestroy(() => clearTimeout(copyTimer))
140
+ </script>
141
+
142
+ {#snippet treeNode(node: NodeModel)}
143
+ {#if isContainer(node.value)}
144
+ {#each childKeys(node.value) as [key, child] (key)}
145
+ {#if isContainer(child)}
146
+ <details
147
+ class='group'
148
+ open={node.depth < defaultExpandedDepth}
149
+ data-testid='json-viewer-node'
150
+ >
151
+ <summary class='flex min-w-0 cursor-pointer select-none items-center gap-1 py-0.5 text-base-content/80'>
152
+ <span class='text-base-content/40 group-open:hidden transition-transform' aria-hidden='true'>▶</span>
153
+ <span class='text-base-content/40 hidden group-open:inline transition-transform' aria-hidden='true'>▼</span>
154
+ <span class='font-mono text-xs font-medium'>{key}:</span>
155
+ <span class='font-mono text-xs text-base-content/50'>
156
+ {Array.isArray(child) ? `Array(${containerSize(child)})` : `Object(${containerSize(child)})`}
157
+ </span>
158
+ </summary>
159
+ <div class='ml-3 border-l border-base-content/10 pl-3'>
160
+ {@render treeNode({ key, value: child, depth: node.depth + 1 })}
161
+ </div>
162
+ </details>
163
+ {:else}
164
+ <div class='flex min-w-0 items-baseline gap-1 py-0.5'>
165
+ <span class='font-mono text-xs font-medium text-base-content/80'>{key}:</span>
166
+ <span class='font-mono text-xs {typeClass(child)} [overflow-wrap:anywhere]'>{scalarText(child)}</span>
167
+ </div>
168
+ {/if}
169
+ {/each}
170
+ {:else}
171
+ <div class='flex min-w-0 items-baseline gap-1 py-0.5'>
172
+ <span class='font-mono text-xs {typeClass(node.value)} [overflow-wrap:anywhere]'>{scalarText(node.value)}</span>
173
+ </div>
174
+ {/if}
175
+ {/snippet}
176
+
177
+ <div
178
+ {...dataAttributes}
179
+ class={cn(
180
+ 'flex min-w-0 flex-col gap-2 rounded-container bg-base-200/40 p-3',
181
+ className,
182
+ )}
183
+ data-testid='json-viewer'
184
+ >
185
+ {#if showCopy}
186
+ <div class='flex justify-end'>
187
+ <button
188
+ type='button'
189
+ class='btn btn-ghost btn-xs gap-1 font-normal text-base-content/60'
190
+ data-testid='json-viewer-copy'
191
+ onclick={copyValue}
192
+ >
193
+ {#if copied}
194
+ <svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='2' stroke='currentColor' class='size-3.5' aria-hidden='true'>
195
+ <path stroke-linecap='round' stroke-linejoin='round' d='M4.5 12.75l6 6 9-13.5' />
196
+ </svg>
197
+ {uiM('json_viewer_copied')}
198
+ {:else}
199
+ <svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' class='size-3.5' aria-hidden='true'>
200
+ <path stroke-linecap='round' stroke-linejoin='round' d='M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-15.043-6.603-8.25-8.25-9.75L15.75 17.25z' />
201
+ </svg>
202
+ {uiM('json_viewer_copy')}
203
+ {/if}
204
+ </button>
205
+ </div>
206
+ {/if}
207
+ <div class='min-w-0 overflow-x-auto font-mono text-xs leading-relaxed'>
208
+ {#if isContainer(safeValue)}
209
+ {@render treeNode({ key: null, value: safeValue, depth: 0 })}
210
+ {:else}
211
+ <span class={typeClass(safeValue)}>{scalarText(safeValue)}</span>
212
+ {/if}
213
+ </div>
214
+ </div>
@@ -0,0 +1,26 @@
1
+ import type { DataAttributes, JsonViewerProps } from '../../types.js';
2
+ type $$ComponentProps = JsonViewerProps & DataAttributes;
3
+ /**
4
+ * JsonViewer
5
+ * =============================================================================
6
+ * @h-ai/ui - JsonViewer 组件
7
+ * =============================================================================
8
+ * JSON 数据查看组件:可折叠树、类型着色(DaisyUI 语义色,跟随主题与暗色模式)、
9
+ * 复制按钮、超长文本截断。用于诊断数据、运行快照等任意 JSON 展示场景。
10
+ *
11
+ * 使用 Svelte 5 Runes ($props, $state, $derived, $props)
12
+ * =============================================================================
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { mount, unmount } from 'svelte'
17
+ * import type { ComponentProps } from 'svelte'
18
+ * import { JsonViewer } from '@h-ai/ui'
19
+ * const props: ComponentProps<typeof JsonViewer> = { value: { name: 'wf', nested: { list: [1, 2] } } }
20
+ * const component = mount(JsonViewer, { target: document.body, props })
21
+ * await unmount(component)
22
+ * ```
23
+ */
24
+ declare const JsonViewer: import("svelte").Component<$$ComponentProps, {}, "">;
25
+ type JsonViewer = ReturnType<typeof JsonViewer>;
26
+ export default JsonViewer;
@@ -26,6 +26,7 @@ export { default as Form } from './Form.svelte';
26
26
  export { default as FormField } from './FormField.svelte';
27
27
  export { default as FormLayout } from './FormLayout.svelte';
28
28
  export { default as InfiniteScroll } from './InfiniteScroll.svelte';
29
+ export { default as JsonViewer } from './JsonViewer.svelte';
29
30
  export { default as MessageBoxContainer } from './MessageBoxContainer.svelte';
30
31
  export { default as MessageBoxDialog } from './MessageBoxDialog.svelte';
31
32
  export { default as MessageContainer } from './MessageContainer.svelte';
@@ -34,6 +34,8 @@ export { default as FormField } from './FormField.svelte';
34
34
  export { default as FormLayout } from './FormLayout.svelte';
35
35
  // 无限滚动 / 上拉加载
36
36
  export { default as InfiniteScroll } from './InfiniteScroll.svelte';
37
+ // JSON 树查看器(可折叠、复制、主题自适应)
38
+ export { default as JsonViewer } from './JsonViewer.svelte';
37
39
  // MessageBox 命令式弹框(类似 ElementUI MessageBox)
38
40
  export { default as MessageBoxContainer } from './MessageBoxContainer.svelte';
39
41
  export { default as MessageBoxDialog } from './MessageBoxDialog.svelte';
@@ -12,6 +12,7 @@ export type { AiDocumentDownloadFormat, AiDocumentDownloadRequest, AiDocumentRes
12
12
  export { renderMarkdownDocument } from './document-parse.js';
13
13
  export type { MarkdownDocumentBlock, MarkdownDocumentHtmlBlock, MarkdownDocumentMermaidBlock, MarkdownDocumentParseOptions, MarkdownRenderResult, } from './document-parse.js';
14
14
  export type { AiDocumentEditorProps, MarkdownBlockFormatKind, MarkdownBlockStyleKind, MarkdownCodeBlockItem, MarkdownCodeRunRequest, MarkdownCodeRunResult, MarkdownColorFormatRequest, MarkdownInlineFormatKind, MarkdownOutlineItem, MarkdownRewriteAction, MarkdownRewriteRequest, MarkdownTextAlignKind, MarkdownToolbarDownloadAction, } from './document-types.js';
15
+ export { highlightCode, isLanguageSupported } from './highlight.js';
15
16
  export { parseMarkdown } from './markdown-parse.js';
16
17
  export type { MarkdownParseOptions } from './markdown-parse.js';
17
18
  export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
@@ -9,6 +9,8 @@ export { default as AiDocumentDownloadMenu } from './AiDocumentDownloadMenu.svel
9
9
  export { default as AiDocumentEditor } from './AiDocumentEditor.svelte';
10
10
  export { downloadAiDocument, resolveDocumentDownloadActions, resolveDocumentMarkdownContent, } from './document-download.js';
11
11
  export { renderMarkdownDocument } from './document-parse.js';
12
+ // Shiki 同步语法高亮(CSS Variables 主题,DaisyUI 自适应)
13
+ export { highlightCode, isLanguageSupported } from './highlight.js';
12
14
  export { parseMarkdown } from './markdown-parse.js';
13
15
  export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
14
16
  export { default as AiTableEditor } from './table/AiTableEditor.svelte';
@@ -245,90 +245,92 @@
245
245
  }
246
246
  </script>
247
247
 
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}
252
- {#if error}<div class='alert alert-error break-words' role='alert'>{error}</div>{/if}
253
- {#if receipt}
254
- <div role='status' class='alert alert-success block space-y-2 break-words'>
255
- <p class='font-medium'>{uiM('feedback_accepted', { number: receipt.number })}</p>
256
- <p>{collectionLabel(receipt.collectionStatus)}</p>
257
- <p class='text-sm'>{uiM('feedback_accepted_hint')}</p>
258
- </div>
259
- {:else}
260
- <p class='text-sm text-base-content/65'>{labels.description ?? uiM('feedback_quick_hint')}</p>
261
- <FormLayout {columns} {labelPosition} {labelWidth}>
262
- <FormField for={`${instanceId}-description`} label={labels.contentLabel ?? uiM('feedback_optional_description')}>
263
- <Textarea id={`${instanceId}-description`} name='description' class='h-28' maxlength={10000} placeholder={labels.contentPlaceholder ?? uiM('feedback_content_placeholder')} bind:value={description} disabled={loading} />
264
- </FormField>
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}
278
- {#if visibleAttachments.length}
279
- <section class='space-y-3' aria-label={uiM('feedback_screenshots')}>
280
- {#each visibleAttachments as attachment (attachment.id)}
281
- <div class='rounded-lg border border-base-content/10 p-3 min-w-0 space-y-2'>
282
- <div class='flex items-center justify-between gap-3'>
283
- <span class='min-w-0 text-sm break-all'>{attachment.name}</span>
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>
288
- </div>
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}
292
- {#if attachment.missingReason}<p class='text-warning text-sm break-words'>{uiM('feedback_missing')}: {attachment.missingReason}</p>{/if}
293
- </div>
294
- {/each}
295
- </section>
248
+ <form {...dataAttributes} class={`feedback-form flex min-h-0 min-w-0 flex-1 flex-col gap-4 ${className}`} onsubmit={submit} data-feedback-ui='true' data-feedback-ignore='true'>
249
+ <div class='min-h-0 flex-1 space-y-4 overflow-y-auto'>
250
+ {#if budget}
251
+ <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>
296
252
  {/if}
297
- <details class='rounded-lg border border-base-content/10 p-3'>
298
- <summary class='cursor-pointer text-sm font-medium'>{uiM('feedback_more')}</summary>
299
- <div class='pt-3 space-y-4'>
300
- <FormLayout {columns} {labelPosition} {labelWidth}>
301
- <FormField for={`${instanceId}-type`} label={labels.typeLabel ?? uiM('feedback_type_label')}><Select id={`${instanceId}-type`} options={typeOptions} bind:value={feedbackType} disabled={loading} /></FormField>
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>
303
- </FormLayout>
253
+ {#if error}<div class='alert alert-error break-words' role='alert'>{error}</div>{/if}
254
+ {#if receipt}
255
+ <div role='status' class='alert alert-success block space-y-2 break-words'>
256
+ <p class='font-medium'>{uiM('feedback_accepted', { number: receipt.number })}</p>
257
+ <p>{collectionLabel(receipt.collectionStatus)}</p>
258
+ <p class='text-sm'>{uiM('feedback_accepted_hint')}</p>
304
259
  </div>
305
- </details>
306
- {#if evidenceSummary.length || evidence.length}
307
- <details class='rounded-lg border border-base-content/10 p-3'>
308
- <summary class='cursor-pointer text-sm font-medium'>{uiM('feedback_materials')}</summary>
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>
260
+ {:else}
261
+ <p class='text-sm text-base-content/65'>{labels.description ?? uiM('feedback_quick_hint')}</p>
262
+ <FormLayout {columns} {labelPosition} {labelWidth}>
263
+ <FormField for={`${instanceId}-description`} label={labels.contentLabel ?? uiM('feedback_optional_description')}>
264
+ <Textarea id={`${instanceId}-description`} name='description' class='h-28' maxlength={10000} placeholder={labels.contentPlaceholder ?? uiM('feedback_content_placeholder')} bind:value={description} disabled={loading} />
265
+ </FormField>
266
+ </FormLayout>
267
+ <div class='flex flex-wrap gap-2'>
268
+ {#if oncapture}<Button size='sm' variant='outline' disabled={loading || annotating || staging || exporting} onclick={() => oncapture()}>{uiM('feedback_capture_add')}</Button>{/if}
269
+ <label class='btn btn-sm btn-ghost focus-within:outline focus-within:outline-primary'>
270
+ {uiM('feedback_add_files')}
271
+ <BareInput id={`${instanceId}-files`} type='file' aria-label={uiM('feedback_add_files')} accept='.png,.jpg,.jpeg,.webp,.webm,.mp4,.txt,.log,.json,.pdf,image/png,image/jpeg,image/webp,video/webm,video/mp4,text/plain,application/json,application/pdf' multiple disabled={loading || staging || exporting} class='sr-only' onchange={selectFiles} />
272
+ </label>
273
+ {#if onfileschange}<FeedbackRecorder maxBytes={recordingBytes} disabled={loading || annotating || staging || exporting || attachmentLimitReached} onactive={recordingChanged} onrecord={recorded} />{/if}
274
+ </div>
275
+ {#each files as file, index (`${file.name}:${file.lastModified}:${index}`)}
276
+ <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>
277
+ {/each}
278
+ {#if onfileschange && filesError}<Button size='sm' loading={staging} onclick={stageFiles}>{uiM('feedback_retry')}</Button>{/if}
279
+ {#if visibleAttachments.length}
280
+ <section class='space-y-3' aria-label={uiM('feedback_screenshots')}>
281
+ {#each visibleAttachments as attachment (attachment.id)}
282
+ <div class='rounded-lg border border-base-content/10 p-3 min-w-0 space-y-2'>
283
+ <div class='flex items-center justify-between gap-3'>
284
+ <span class='min-w-0 text-sm break-all'>{attachment.name}</span>
285
+ <div class='flex shrink-0 gap-1'>
286
+ {#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}
287
+ <Button size='xs' variant='ghost' disabled={loading || annotating || exporting} ariaLabel={`${uiM('feedback_remove')} ${attachment.name}`} onclick={() => removedAttachmentIds = [...removedAttachmentIds, attachment.id]}>{uiM('feedback_remove')}</Button>
288
+ </div>
289
+ </div>
290
+ {#if attachment.mimeType?.startsWith('image/') && attachment.url}<FeedbackScreenshot {attachment} onannotate={!loading && !exporting && !staging && onannotate ? annotate : undefined} />{/if}
291
+ {#if attachment.mimeType?.startsWith('video/') && attachment.url}<!-- svelte-ignore a11y_media_has_caption (用户上传的无声录屏) -->
292
+ <video src={attachment.url} controls preload='metadata' class='max-w-full rounded' aria-label={attachment.name}></video>{/if}
293
+ {#if attachment.missingReason}<p class='text-warning text-sm break-words'>{uiM('feedback_missing')}: {attachment.missingReason}</p>{/if}
321
294
  </div>
322
295
  {/each}
323
- {#each evidenceSummary as item, index (`${item.label}:${index}`)}
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>
325
- {/each}
326
- </dl>
296
+ </section>
297
+ {/if}
298
+ <details class='rounded-lg border border-base-content/10 p-3'>
299
+ <summary class='cursor-pointer text-sm font-medium'>{uiM('feedback_more')}</summary>
300
+ <div class='pt-3 space-y-4'>
301
+ <FormLayout {columns} {labelPosition} {labelWidth}>
302
+ <FormField for={`${instanceId}-type`} label={labels.typeLabel ?? uiM('feedback_type_label')}><Select id={`${instanceId}-type`} options={typeOptions} bind:value={feedbackType} disabled={loading} /></FormField>
303
+ <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>
304
+ </FormLayout>
305
+ </div>
327
306
  </details>
307
+ {#if evidenceSummary.length || evidence.length}
308
+ <details class='rounded-lg border border-base-content/10 p-3'>
309
+ <summary class='cursor-pointer text-sm font-medium'>{uiM('feedback_materials')}</summary>
310
+ <dl class='space-y-2 pt-3 text-sm'>
311
+ {#each materialGroups as group (group.label)}
312
+ <div class='min-w-0'>
313
+ <dt class='font-medium'>{group.label} · {group.items.length}</dt>
314
+ <dd class='space-y-2 pt-2'>
315
+ {#each group.items as item (item.id)}
316
+ <details class='rounded bg-base-200 p-2' ontoggle={event => expandedMaterials = event.currentTarget.open ? [...expandedMaterials, item.id] : expandedMaterials.filter(id => id !== item.id)}>
317
+ <summary class='cursor-pointer break-all text-xs'>{feedbackTime(item.timestamp)} · {item.kind} · {item.source} #{item.sequence}</summary>
318
+ {#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}
319
+ </details>
320
+ {/each}
321
+ </dd>
322
+ </div>
323
+ {/each}
324
+ {#each evidenceSummary as item, index (`${item.label}:${index}`)}
325
+ <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>
326
+ {/each}
327
+ </dl>
328
+ </details>
329
+ {/if}
328
330
  {/if}
329
- {/if}
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'>
331
+ {#if exported}<p class='text-sm text-success' role='status'>{uiM('feedback_local_saved')}</p>{/if}
332
+ </div>
333
+ <div class='shrink-0 flex flex-wrap justify-end gap-2 border-t border-base-content/10 bg-base-100 pt-4 pb-2'>
332
334
  {#if onexport}<Button variant='ghost' loading={exporting} disabled={annotating || staging} onclick={saveLocal}>{uiM('feedback_local_export')}</Button>{/if}
333
335
  {#if oncancel}<Button variant='ghost' onclick={oncancel}>{receipt ? uiM('feedback_close') : labels.cancel ?? uiM('feedback_cancel')}</Button>{/if}
334
336
  {#if !receipt}<Button type='submit' variant='primary' loading={loading || staging} disabled={annotating || exporting || recording || Boolean(onfileschange && filesError)}>{labels.submit ?? uiM('feedback_submit')}</Button>{/if}
@@ -112,7 +112,6 @@
112
112
  <p role='alert' class='alert alert-warning'>{uiM('feedback_permission_denied')}</p>
113
113
  {:else}
114
114
  <TableToolbar bind:searchValue={search} {filterFields} bind:filterValues sortableColumns={[{ key: 'createdAt', label: uiM('feedback_created_at') }]} sortBy='createdAt' bind:sortDirection searchPlaceholder={uiM('feedback_search')} onsearch={value => update({ page: 1, search: value || undefined })} onfilterchange={filter} onclearfilters={() => update({ page: 1, status: undefined, collectionStatus: undefined, appId: undefined, appVersion: undefined, from: undefined, to: undefined })} onsort={(_, direction) => update({ page: 1, sortDirection: direction })}>
115
- {#snippet leading()}<h2 class='font-semibold text-lg'>{uiM('feedback_list_title')}</h2>{/snippet}
116
115
  </TableToolbar>
117
116
  {#if error || actionError}<p role='alert' class='alert alert-error break-words'>{error || actionError}</p>{/if}
118
117
  <div class='min-h-0 min-w-0 flex-1 overflow-hidden'>
@@ -74,7 +74,7 @@
74
74
  </div>
75
75
  </aside>
76
76
  {/if}
77
- <Modal {...dataAttributes} bind:open title={formProps.labels?.title ?? uiM('feedback_title')} size='lg' data-feedback-ui='true' data-feedback-ignore='true'>
77
+ <Modal {...dataAttributes} bind:open title={formProps.labels?.title ?? uiM('feedback_title')} size='lg' bodyOverflow='hidden' bodyClass='flex flex-col' data-feedback-ui='true' data-feedback-ignore='true'>
78
78
  <FeedbackForm {...formProps} onrecordingchange={recordingChanged} oncapture={formProps.oncapture ? selectPage : undefined} oncancel={() => {
79
79
  open = false
80
80
  formProps.oncancel?.()
@@ -476,5 +476,7 @@
476
476
  "feedback_record_empty": "No video was recorded. Please retry.",
477
477
  "feedback_local_saved": "Your feedback download has started.",
478
478
  "feedback_notification_disabled": "Notifications disabled",
479
- "feedback_capacity_hint": "Attachments {used}/{total} MiB · {single} MiB each · up to {count}"
479
+ "feedback_capacity_hint": "Attachments {used}/{total} MiB · {single} MiB each · up to {count}",
480
+ "json_viewer_copy": "Copy",
481
+ "json_viewer_copied": "Copied"
480
482
  }
@@ -476,5 +476,7 @@
476
476
  "feedback_record_empty": "映像がありません。再試行してください。",
477
477
  "feedback_local_saved": "フィードバックのダウンロードを開始しました。",
478
478
  "feedback_notification_disabled": "通知は無効です",
479
- "feedback_capacity_hint": "添付 {used}/{total} MiB · 各 {single} MiB まで · 最大 {count} 件"
479
+ "feedback_capacity_hint": "添付 {used}/{total} MiB · 各 {single} MiB まで · 最大 {count} 件",
480
+ "json_viewer_copy": "コピー",
481
+ "json_viewer_copied": "コピーしました"
480
482
  }
@@ -476,5 +476,7 @@
476
476
  "feedback_record_empty": "未录制到画面,请重试。",
477
477
  "feedback_local_saved": "已开始下载反馈文件。",
478
478
  "feedback_notification_disabled": "未启用通知",
479
- "feedback_capacity_hint": "附件 {used}/{total} MiB · 单个最多 {single} MiB · 最多 {count} 项"
479
+ "feedback_capacity_hint": "附件 {used}/{total} MiB · 单个最多 {single} MiB · 最多 {count} 项",
480
+ "json_viewer_copy": "复制",
481
+ "json_viewer_copied": "已复制"
480
482
  }
package/dist/types.d.ts CHANGED
@@ -1299,6 +1299,33 @@ export interface EmptyProps extends DataAttributes {
1299
1299
  /** 自定义图标插槽 */
1300
1300
  children?: Snippet;
1301
1301
  }
1302
+ /**
1303
+ * JSON 查看器属性
1304
+ *
1305
+ * @example
1306
+ * ```svelte
1307
+ * <script lang="ts">
1308
+ * import { JsonViewer } from '@h-ai/ui'
1309
+ * import type { JsonViewerProps } from '@h-ai/ui'
1310
+ * const props: JsonViewerProps = { value: { name: 'wf', nested: { list: [1, 2] } } }
1311
+ * </script>
1312
+ * <JsonViewer {...props} />
1313
+ * ```
1314
+ */
1315
+ export interface JsonViewerProps extends DataAttributes {
1316
+ /** 要展示的 JSON 数据;循环引用自动替换为占位符 */
1317
+ value: unknown;
1318
+ /** 初始展开深度;0 表示全部折叠,1 展开顶层容器 */
1319
+ defaultExpandedDepth?: number;
1320
+ /** 标量文本截断长度;超出部分以省略号结尾 */
1321
+ maxScalarLength?: number;
1322
+ /** 是否显示复制按钮 */
1323
+ showCopy?: boolean;
1324
+ /** 自定义类名 */
1325
+ class?: string;
1326
+ /** 复制成功后的回调,参数为复制的格式化 JSON 文本 */
1327
+ onCopy?: (text: string) => void;
1328
+ }
1302
1329
  /**
1303
1330
  * 结果页属性
1304
1331
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/ui",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.71",
4
+ "version": "0.1.0-alpha.72",
5
5
  "description": "Hai Framework UI component library for Svelte 5 Runes.",
6
6
  "license": "Apache-2.0",
7
7
  "svelte": "./dist/index.js",
@@ -119,7 +119,7 @@
119
119
  "svelte": "^5.57.2"
120
120
  },
121
121
  "dependencies": {
122
- "@h-ai/core": "0.1.0-alpha.71",
122
+ "@h-ai/core": "0.1.0-alpha.72",
123
123
  "@internationalized/date": "^3.12.4",
124
124
  "@rrweb/replay": "^2.1.7",
125
125
  "@shikijs/langs": "^4.5.0",