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

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.
@@ -0,0 +1,61 @@
1
+ import type { DataAttributes, FormLayoutOptions } from '../../../types.js';
2
+ import type { FeedbackAnnotation, FeedbackAttachmentView, FeedbackEvidenceSummary, FeedbackFormData, FeedbackReceipt } from './feedback-types.js';
3
+ /**
4
+ * 反馈表单的宿主注入契约,网络和采集服务通过动作回调接入。
5
+ * @example
6
+ * ```ts
7
+ * import type { ComponentProps } from 'svelte'
8
+ * import { FeedbackForm } from '@h-ai/ui'
9
+ * const props: ComponentProps<typeof FeedbackForm> = {
10
+ * onsubmit: async () => ({ number: 'FB-1', collectionStatus: 'collecting' }),
11
+ * }
12
+ * ```
13
+ */
14
+ interface Props extends FormLayoutOptions {
15
+ labels?: {
16
+ title?: string;
17
+ description?: string;
18
+ typeLabel?: string;
19
+ contentLabel?: string;
20
+ contentPlaceholder?: string;
21
+ contactLabel?: string;
22
+ contactPlaceholder?: string;
23
+ cancel?: string;
24
+ submit?: string;
25
+ errorEmpty?: string;
26
+ errorSubmit?: string;
27
+ types?: {
28
+ bug?: string;
29
+ feature?: string;
30
+ question?: string;
31
+ other?: string;
32
+ };
33
+ };
34
+ attachments?: FeedbackAttachmentView[];
35
+ evidenceSummary?: FeedbackEvidenceSummary[];
36
+ onsubmit?: (input: FeedbackFormData) => Promise<void | FeedbackReceipt>;
37
+ onannotate?: (annotation: FeedbackAnnotation) => Promise<void>;
38
+ /** 宿主准备附件并回填 attachments,使主动添加的图片也可预览、遮挡和标注。 */
39
+ onfileschange?: (files: File[]) => Promise<void>;
40
+ onexport?: (input: FeedbackFormData) => Promise<void>;
41
+ oncancel?: () => void;
42
+ oncomplete?: () => void;
43
+ /** 准备新现场后更新,关闭弹窗不会丢失未提交内容。 */
44
+ resetKey?: string;
45
+ receipt?: FeedbackReceipt;
46
+ class?: string;
47
+ }
48
+ type $$ComponentProps = Props & DataAttributes;
49
+ /**
50
+ * FeedbackForm
51
+ * 可独立承载的反馈收集表单;采集、上传和导出由宿主提供。
52
+ * @example
53
+ * ```ts
54
+ * import type { ComponentProps } from 'svelte'
55
+ * import { FeedbackForm } from '@h-ai/ui'
56
+ * const props: ComponentProps<typeof FeedbackForm> = { onsubmit: async () => ({ number: 'FB-1', collectionStatus: 'collecting' }) }
57
+ * ```
58
+ */
59
+ declare const FeedbackForm: import("svelte").Component<$$ComponentProps, {}, "receipt">;
60
+ type FeedbackForm = ReturnType<typeof FeedbackForm>;
61
+ export default FeedbackForm;
@@ -0,0 +1,147 @@
1
+ <!--
2
+ @component FeedbackList
3
+ 反馈管理列表;分页、筛选及操作通过宿主回调接入,列表不读取完整材料。
4
+ @example
5
+ ```ts
6
+ import type { ComponentProps } from 'svelte'
7
+ import { FeedbackList } from '@h-ai/ui'
8
+ const props: ComponentProps<typeof FeedbackList> = { data: { items: [], total: 0, page: 1, pageSize: 20 } }
9
+ ```
10
+ -->
11
+ <script lang='ts'>
12
+ import type { DataAttributes } from '../../../types.js'
13
+ import type { FeedbackListQuery, FeedbackPage, FeedbackPermissions, FeedbackReportView, FeedbackStatusChange } from './feedback-types.js'
14
+ import { uiM } from '../../../messages.js'
15
+ import { getDataAttributes } from '../../../utils.js'
16
+ import DataTable from '../../compounds/DataTable.svelte'
17
+ import Pagination from '../../compounds/Pagination.svelte'
18
+ import TableToolbar from '../../compounds/TableToolbar.svelte'
19
+ import Badge from '../../primitives/Badge.svelte'
20
+ import Button from '../../primitives/Button.svelte'
21
+ import { collectionLabel, feedbackTime, notificationLabel } from './feedback-functions.js'
22
+
23
+ let {
24
+ data,
25
+ query = $bindable(),
26
+ permissions = {},
27
+ loading = false,
28
+ error = '',
29
+ onquerychange,
30
+ onview,
31
+ onstatus,
32
+ onexport,
33
+ onretry,
34
+ class: className = '',
35
+ ...restProps
36
+ }: {
37
+ data: FeedbackPage<FeedbackReportView>
38
+ query?: FeedbackListQuery
39
+ permissions?: FeedbackPermissions
40
+ loading?: boolean
41
+ error?: string
42
+ onquerychange?: (query: FeedbackListQuery) => void | Promise<void>
43
+ onview?: (report: FeedbackReportView) => void | Promise<void>
44
+ onstatus?: (change: FeedbackStatusChange) => void | Promise<void>
45
+ onexport?: (report: FeedbackReportView) => void | Promise<void>
46
+ onretry?: (report: FeedbackReportView) => void | Promise<void>
47
+ class?: string
48
+ } & DataAttributes = $props()
49
+
50
+ const dataAttributes = $derived(getDataAttributes(restProps))
51
+ const effectiveQuery = $derived(query ?? { page: data.page, pageSize: data.pageSize })
52
+ const pageSizeOptions = $derived([...new Set([data.pageSize, 10, 20, 50, 100])].sort((left, right) => left - right))
53
+ let actionError = $state('')
54
+ let busyId = $state('')
55
+ let search = $derived(effectiveQuery.search ?? '')
56
+ let sortDirection = $derived(effectiveQuery.sortDirection ?? 'desc')
57
+ let filterValues = $derived<Record<string, unknown>>({ status: effectiveQuery.status ?? '', collectionStatus: effectiveQuery.collectionStatus ?? '', appId: effectiveQuery.appId ?? '', appVersion: effectiveQuery.appVersion ?? '', from: effectiveQuery.from ? new Date(effectiveQuery.from).toISOString().slice(0, 10) : '', to: effectiveQuery.to ? new Date(effectiveQuery.to).toISOString().slice(0, 10) : '' })
58
+ const columns = $derived([
59
+ { key: 'number', label: uiM('feedback_number') },
60
+ { key: 'description', label: uiM('feedback_summary') },
61
+ { key: 'appId', label: uiM('feedback_application') },
62
+ { key: 'appVersion', label: uiM('feedback_version') },
63
+ { key: 'userId', label: uiM('feedback_submitter') },
64
+ { key: 'createdAt', label: uiM('feedback_created_at'), sortable: true },
65
+ { key: 'status', label: uiM('feedback_processing') },
66
+ { key: 'collectionStatus', label: uiM('feedback_collection') },
67
+ { key: 'notificationStatus', label: uiM('feedback_notification') },
68
+ ])
69
+ const filterFields = $derived([
70
+ { id: 'status', label: uiM('feedback_processing'), type: 'select', options: [{ label: uiM('feedback_pending'), value: 'pending' }, { label: uiM('feedback_handled'), value: 'handled' }] },
71
+ { id: 'collectionStatus', label: uiM('feedback_collection'), type: 'select', options: ['collecting', 'complete', 'partial', 'failed'].map(value => ({ value, label: collectionLabel(value as FeedbackReportView['collectionStatus']) })) },
72
+ { id: 'appId', label: uiM('feedback_application'), type: 'text' },
73
+ { id: 'appVersion', label: uiM('feedback_version'), type: 'text' },
74
+ { id: 'createdAt', label: uiM('feedback_date_range'), type: 'date-range', startKey: 'from', endKey: 'to' },
75
+ ])
76
+
77
+ async function update(next: Partial<FeedbackListQuery>) {
78
+ query = { ...effectiveQuery, ...next }
79
+ actionError = ''
80
+ try {
81
+ await onquerychange?.(query)
82
+ }
83
+ catch (cause) {
84
+ actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
85
+ }
86
+ }
87
+ function filter(values: Record<string, unknown>) {
88
+ const from = values.from ? Date.parse(String(values.from)) : undefined
89
+ const to = values.to ? Date.parse(String(values.to)) + 86_400_000 - 1 : undefined
90
+ void update({ page: 1, status: values.status === 'pending' || values.status === 'handled' ? values.status : undefined, collectionStatus: ['collecting', 'complete', 'partial', 'failed'].includes(String(values.collectionStatus)) ? values.collectionStatus as FeedbackReportView['collectionStatus'] : undefined, appId: String(values.appId ?? '') || undefined, appVersion: String(values.appVersion ?? '') || undefined, from: Number.isFinite(from) ? from : undefined, to: Number.isFinite(to) ? to : undefined })
91
+ }
92
+ async function run(report: FeedbackReportView, action: (() => void | Promise<void>) | undefined) {
93
+ if (!action || busyId)
94
+ return
95
+ busyId = report.id
96
+ actionError = ''
97
+ try {
98
+ await action()
99
+ }
100
+ catch (cause) {
101
+ actionError = cause instanceof Error ? cause.message : uiM('feedback_action_failed')
102
+ }
103
+ finally {
104
+ busyId = ''
105
+ }
106
+ }
107
+ </script>
108
+
109
+ <section {...dataAttributes} class={`feedback-list flex min-h-0 min-w-0 flex-1 flex-col gap-3 ${className}`} aria-label={uiM('feedback_list_title')}>
110
+ {#if permissions.read === false}
111
+ <p role='alert' class='alert alert-warning'>{uiM('feedback_permission_denied')}</p>
112
+ {:else}
113
+ <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 })}>
114
+ {#snippet leading()}<h2 class='font-semibold text-lg'>{uiM('feedback_list_title')}</h2>{/snippet}
115
+ </TableToolbar>
116
+ {#if error || actionError}<p role='alert' class='alert alert-error break-words'>{error || actionError}</p>{/if}
117
+ <div class='min-h-0 min-w-0 flex-1 overflow-hidden'>
118
+ <DataTable data={data.items} {columns} keyField='id' density='compact' {loading} sortKey='createdAt' sortDir={sortDirection} onsort={(_, direction) => update({ page: 1, sortDirection: direction })} class='h-full'>
119
+ {#snippet cell(item, key)}
120
+ {#if key === 'number'}
121
+ {#if onview}<Button size='xs' variant='ghost' onclick={() => run(item, () => onview(item))}>{item.number}</Button>{:else}{item.number}{/if}
122
+ {:else if key === 'description'}<span class='block max-w-sm truncate' title={item.description || item.summary || uiM('feedback_no_description')}>{item.description || item.summary || uiM('feedback_no_description')}</span>
123
+ {:else if key === 'appId'}{item.appId}
124
+ {:else if key === 'appVersion'}{item.appVersion || '—'}
125
+ {:else if key === 'userId'}{item.userId || '—'}
126
+ {:else if key === 'createdAt'}{feedbackTime(item.createdAt)}
127
+ {:else if key === 'status'}<Badge size='sm' variant={item.status === 'handled' ? 'success' : 'ghost'}>{uiM(item.status === 'handled' ? 'feedback_handled' : 'feedback_pending')}</Badge>
128
+ {:else if key === 'collectionStatus'}<span class:text-warning={item.collectionStatus === 'failed' || item.collectionStatus === 'partial'}>{collectionLabel(item.collectionStatus)}</span>
129
+ {:else if key === 'notificationStatus'}{notificationLabel(item.notificationStatus)}{/if}
130
+ {/snippet}
131
+ {#snippet actions(item)}
132
+ <div class='flex flex-wrap items-center gap-1'>
133
+ {#if onview}<Button size='xs' variant='ghost' disabled={Boolean(busyId)} onclick={() => run(item, () => onview(item))}>{uiM('feedback_details')}</Button>{/if}
134
+ {#if onstatus && ((item.status === 'pending' && permissions.process) || (item.status === 'handled' && permissions.reopen))}
135
+ <Button size='xs' variant='ghost' loading={busyId === item.id} disabled={Boolean(busyId)} onclick={() => run(item, () => onstatus({ id: item.id, status: item.status === 'pending' ? 'handled' : 'pending', expectedVersion: item.version }))}>{uiM(item.status === 'pending' ? 'feedback_handle' : 'feedback_reopen')}</Button>
136
+ {/if}
137
+ {#if permissions.export && onexport}<Button size='xs' variant='ghost' disabled={Boolean(busyId)} onclick={() => run(item, () => onexport(item))}>{uiM('feedback_export')}</Button>{/if}
138
+ {#if permissions.retry && onretry && (item.collectionStatus === 'partial' || item.collectionStatus === 'failed' || item.notificationStatus === 'failed')}<Button size='xs' variant='ghost' disabled={Boolean(busyId)} onclick={() => run(item, () => onretry(item))}>{uiM('feedback_retry')}</Button>{/if}
139
+ </div>
140
+ {/snippet}
141
+ </DataTable>
142
+ </div>
143
+ <div class='shrink-0 rounded-lg border border-base-content/10 bg-base-100 px-3 py-2 overflow-x-auto'>
144
+ <Pagination page={data.page} total={data.total} pageSize={data.pageSize} {pageSizeOptions} showSizeChanger showJumper onchange={page => update({ page })} onpagesizechange={pageSize => update({ page: 1, pageSize })} />
145
+ </div>
146
+ {/if}
147
+ </section>
@@ -0,0 +1,28 @@
1
+ import type { DataAttributes } from '../../../types.js';
2
+ import type { FeedbackListQuery, FeedbackPage, FeedbackPermissions, FeedbackReportView, FeedbackStatusChange } from './feedback-types.js';
3
+ type $$ComponentProps = {
4
+ data: FeedbackPage<FeedbackReportView>;
5
+ query?: FeedbackListQuery;
6
+ permissions?: FeedbackPermissions;
7
+ loading?: boolean;
8
+ error?: string;
9
+ onquerychange?: (query: FeedbackListQuery) => void | Promise<void>;
10
+ onview?: (report: FeedbackReportView) => void | Promise<void>;
11
+ onstatus?: (change: FeedbackStatusChange) => void | Promise<void>;
12
+ onexport?: (report: FeedbackReportView) => void | Promise<void>;
13
+ onretry?: (report: FeedbackReportView) => void | Promise<void>;
14
+ class?: string;
15
+ } & DataAttributes;
16
+ /**
17
+ * FeedbackList
18
+ * 反馈管理列表;分页、筛选及操作通过宿主回调接入,列表不读取完整材料。
19
+ * @example
20
+ * ```ts
21
+ * import type { ComponentProps } from 'svelte'
22
+ * import { FeedbackList } from '@h-ai/ui'
23
+ * const props: ComponentProps<typeof FeedbackList> = { data: { items: [], total: 0, page: 1, pageSize: 20 } }
24
+ * ```
25
+ */
26
+ declare const FeedbackList: import("svelte").Component<$$ComponentProps, {}, "query">;
27
+ type FeedbackList = ReturnType<typeof FeedbackList>;
28
+ export default FeedbackList;
@@ -1,214 +1,38 @@
1
1
  <!--
2
2
  @component FeedbackModal
3
- 用户反馈模态框,支持 Bug 报告、功能建议等多种反馈类型。
4
-
5
- @prop {boolean} open - 是否显示模态框(双向绑定)
6
- @prop {function} onsubmit - 提交反馈的回调
3
+ 一键问题反馈弹窗。宿主先准备现场,再打开弹窗;采集与上传通过回调接入。
7
4
 
8
5
  @example
9
6
  ```ts
10
7
  import { mount, unmount } from 'svelte'
11
8
  import type { ComponentProps } from 'svelte'
12
9
  import { FeedbackModal } from '@h-ai/ui'
13
- const props: ComponentProps<typeof FeedbackModal> = { open: true, labels: { title: '提交反馈' } }
10
+ const props: ComponentProps<typeof FeedbackModal> = { open: true, onsubmit: async () => ({ number: 'FB-1', collectionStatus: 'collecting' }) }
14
11
  const component = mount(FeedbackModal, { target: document.body, props })
15
12
  await unmount(component)
16
13
  ```
17
14
  -->
18
15
  <script lang='ts'>
19
- import FormField from '../../compounds/FormField.svelte'
20
- import FormLayout from '../../compounds/FormLayout.svelte'
21
- import Modal from '../../compounds/Modal.svelte'
22
- import Button from '../../primitives/Button.svelte'
23
- import Input from '../../primitives/Input.svelte'
24
- import Select from '../../primitives/Select.svelte'
25
- import Textarea from '../../primitives/Textarea.svelte'
26
-
27
- /**
28
- * 反馈表单可选的问题类别。
29
- *
30
- * @example 模块内部上下文
31
- * ```ts
32
- * const example: FeedbackType = 'bug'
33
- * ```
34
- */
35
- type FeedbackType = 'bug' | 'feature' | 'question' | 'other'
36
-
37
- /**
38
- * 反馈表单提交值;描述和联系方式由宿主验证并保存。
39
- *
40
- * @example 模块内部上下文
41
- * ```ts
42
- * const example: FeedbackData = { type: 'bug', description: '保存后列表没有刷新', contact: 'ada@example.com' }
43
- * ```
44
- */
45
- interface FeedbackData {
46
- type: FeedbackType
47
- description: string
48
- contact?: string
49
- }
50
-
51
- /**
52
- * i18n 文案配置
53
- *
54
- * @example 模块内部上下文
55
- * ```ts
56
- * const example: FeedbackLabels = { title: '提交反馈', contentLabel: '问题描述' }
57
- * ```
58
- */
59
- interface FeedbackLabels {
60
- title?: string
61
- description?: string
62
- typeLabel?: string
63
- contentLabel?: string
64
- contentPlaceholder?: string
65
- contactLabel?: string
66
- contactPlaceholder?: string
67
- cancel?: string
68
- submit?: string
69
- errorEmpty?: string
70
- errorSubmit?: string
71
- types?: {
72
- bug?: string
73
- feature?: string
74
- question?: string
75
- other?: string
76
- }
77
- }
78
-
79
- import type { DataAttributes, FormLayoutOptions } from '../../../types.js'
16
+ import type { ComponentProps } from 'svelte'
80
17
  import { uiM } from '../../../messages.js'
81
- import { getDataAttributes } from '../../../utils.js'
82
-
83
- /**
84
- * FeedbackModal 组件的属性契约;通过公开组件配置使用。
85
- *
86
- * @example
87
- * ```ts
88
- * import { mount, unmount } from 'svelte'
89
- * import type { ComponentProps } from 'svelte'
90
- * import { FeedbackModal } from '@h-ai/ui'
91
- * const props: ComponentProps<typeof FeedbackModal> = { open: true, labels: { title: '提交反馈' } }
92
- * const component = mount(FeedbackModal, { target: document.body, props })
93
- * await unmount(component)
94
- * ```
95
- */
96
- interface Props extends FormLayoutOptions {
97
- open?: boolean
98
- labels?: FeedbackLabels
99
- onsubmit?: (data: FeedbackData) => Promise<void>
100
- class?: string
101
- }
102
-
103
- let { open = $bindable(false), labels = {}, columns = 1, labelPosition = 'top', labelWidth = '8rem', onsubmit, class: className = '', ...restProps }: Props & DataAttributes = $props()
18
+ import { getDataAttributes, portal } from '../../../utils.js'
19
+ import Modal from '../../compounds/Modal.svelte'
20
+ import FeedbackForm from './FeedbackForm.svelte'
104
21
 
22
+ let { open = $bindable(false), ...restProps }: ComponentProps<typeof FeedbackForm> & { open?: boolean } = $props()
105
23
  const dataAttributes = $derived(getDataAttributes(restProps))
106
- // 文案优先使用传入的 labels,缺省回退到内置消息 uiM(...)
107
-
108
- let feedbackType = $state<FeedbackType>('bug')
109
- let description = $state('')
110
- let contact = $state('')
111
- let loading = $state(false)
112
- let error = $state<'empty' | 'submit' | ''>('')
113
- let submitError = $state('')
114
- const errorText = $derived(error === 'empty' ? labels.errorEmpty ?? uiM('feedback_error_empty') : error === 'submit' ? submitError || labels.errorSubmit || uiM('feedback_error_submit') : '')
115
-
116
- const typeOptions = $derived([
117
- { value: 'bug', label: labels.types?.bug ?? uiM('feedback_type_bug') },
118
- { value: 'feature', label: labels.types?.feature ?? uiM('feedback_type_feature') },
119
- { value: 'question', label: labels.types?.question ?? uiM('feedback_type_question') },
120
- { value: 'other', label: labels.types?.other ?? uiM('feedback_type_other') },
121
- ])
122
-
123
- async function handleSubmit() {
124
- if (loading)
125
- return
126
- if (!description.trim()) {
127
- error = 'empty'
128
- return
129
- }
130
-
131
- loading = true
132
- error = ''
133
-
134
- try {
135
- await onsubmit?.({
136
- type: feedbackType,
137
- description: description.trim(),
138
- contact: contact.trim() || undefined,
139
- })
140
- open = false
141
- resetForm()
142
- }
143
- catch (e) {
144
- submitError = e instanceof Error ? e.message : ''
145
- error = 'submit'
146
- }
147
- finally {
148
- loading = false
149
- }
150
- }
151
-
152
- function resetForm() {
153
- feedbackType = 'bug'
154
- description = ''
155
- contact = ''
156
- error = ''
157
- submitError = ''
158
- }
24
+ const formProps = $derived(Object.fromEntries(Object.entries(restProps).filter(([key]) => !key.startsWith('data-'))) as ComponentProps<typeof FeedbackForm>)
159
25
  </script>
160
26
 
161
- <Modal {...dataAttributes} class={className} bind:open title={labels.title ?? uiM('feedback_title')}>
162
- <p class='text-base-content/70 mb-4'>{labels.description ?? uiM('feedback_description')}</p>
163
-
164
- {#if error === 'submit'}
165
- <div class='alert alert-error mb-4'>
166
- <span class='icon-[tabler--alert-circle] size-5'></span>
167
- <span>{errorText}</span>
168
- </div>
169
- {/if}
170
-
171
- <FormLayout {columns} {labelPosition} {labelWidth}>
172
- <FormField for='feedback-type' label={labels.typeLabel ?? uiM('feedback_type_label')}>
173
- <Select
174
- id='feedback-type'
175
- options={typeOptions}
176
- bind:value={feedbackType}
177
- />
178
- </FormField>
179
-
180
- <FormField for='feedback-desc' label={labels.contentLabel ?? uiM('feedback_content_label')} required error={error === 'empty' ? errorText : ''}>
181
- <Textarea
182
- id='feedback-desc'
183
- class='h-32'
184
- placeholder={labels.contentPlaceholder ?? uiM('feedback_content_placeholder')}
185
- bind:value={description}
186
- disabled={loading}
187
- oninput={() => {
188
- if (description.trim())
189
- error = ''
190
- }}
191
- />
192
- </FormField>
193
-
194
- <FormField for='feedback-contact' label={labels.contactLabel ?? uiM('feedback_contact_label')}>
195
- <Input
196
- id='feedback-contact'
197
- type='text'
198
- class='w-full'
199
- placeholder={labels.contactPlaceholder ?? uiM('feedback_contact_placeholder')}
200
- bind:value={contact}
201
- autocomplete='email'
202
- />
203
- </FormField>
204
- </FormLayout>
205
-
206
- {#snippet footer()}
207
- <Button variant='ghost' onclick={() => open = false}>
208
- {labels.cancel ?? uiM('feedback_cancel')}
209
- </Button>
210
- <Button variant='primary' {loading} onclick={handleSubmit}>
211
- {labels.submit ?? uiM('feedback_submit')}
212
- </Button>
213
- {/snippet}
214
- </Modal>
27
+ <!-- 脱离顶栏的 fixed 包含块与层叠上下文;包装层不参与布局,卸载由 portal 清理。 -->
28
+ <div use:portal class='contents'>
29
+ <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={() => {
31
+ open = false
32
+ formProps.oncancel?.()
33
+ }} oncomplete={() => {
34
+ open = false
35
+ formProps.oncomplete?.()
36
+ }} />
37
+ </Modal>
38
+ </div>
@@ -1,86 +1,18 @@
1
- import type { DataAttributes, FormLayoutOptions } from '../../../types.js';
2
- /**
3
- * 反馈表单可选的问题类别。
4
- *
5
- * @example 模块内部上下文
6
- * ```ts
7
- * const example: FeedbackType = 'bug'
8
- * ```
9
- */
10
- type FeedbackType = 'bug' | 'feature' | 'question' | 'other';
11
- /**
12
- * 反馈表单提交值;描述和联系方式由宿主验证并保存。
13
- *
14
- * @example 模块内部上下文
15
- * ```ts
16
- * const example: FeedbackData = { type: 'bug', description: '保存后列表没有刷新', contact: 'ada@example.com' }
17
- * ```
18
- */
19
- interface FeedbackData {
20
- type: FeedbackType;
21
- description: string;
22
- contact?: string;
23
- }
24
- /**
25
- * i18n 文案配置
26
- *
27
- * @example 模块内部上下文
28
- * ```ts
29
- * const example: FeedbackLabels = { title: '提交反馈', contentLabel: '问题描述' }
30
- * ```
31
- */
32
- interface FeedbackLabels {
33
- title?: string;
34
- description?: string;
35
- typeLabel?: string;
36
- contentLabel?: string;
37
- contentPlaceholder?: string;
38
- contactLabel?: string;
39
- contactPlaceholder?: string;
40
- cancel?: string;
41
- submit?: string;
42
- errorEmpty?: string;
43
- errorSubmit?: string;
44
- types?: {
45
- bug?: string;
46
- feature?: string;
47
- question?: string;
48
- other?: string;
49
- };
50
- }
51
- /**
52
- * FeedbackModal 组件的属性契约;通过公开组件配置使用。
53
- *
54
- * @example
55
- * ```ts
56
- * import { mount, unmount } from 'svelte'
57
- * import type { ComponentProps } from 'svelte'
58
- * import { FeedbackModal } from '@h-ai/ui'
59
- * const props: ComponentProps<typeof FeedbackModal> = { open: true, labels: { title: '提交反馈' } }
60
- * const component = mount(FeedbackModal, { target: document.body, props })
61
- * await unmount(component)
62
- * ```
63
- */
64
- interface Props extends FormLayoutOptions {
1
+ import type { ComponentProps } from 'svelte';
2
+ import FeedbackForm from './FeedbackForm.svelte';
3
+ type $$ComponentProps = ComponentProps<typeof FeedbackForm> & {
65
4
  open?: boolean;
66
- labels?: FeedbackLabels;
67
- onsubmit?: (data: FeedbackData) => Promise<void>;
68
- class?: string;
69
- }
70
- type $$ComponentProps = Props & DataAttributes;
5
+ };
71
6
  /**
72
7
  * FeedbackModal
73
- * 用户反馈模态框,支持 Bug 报告、功能建议等多种反馈类型。
74
- *
75
- * @prop {boolean} open - 是否显示模态框(双向绑定)
76
- * @prop {function} onsubmit - 提交反馈的回调
8
+ * 一键问题反馈弹窗。宿主先准备现场,再打开弹窗;采集与上传通过回调接入。
77
9
  *
78
10
  * @example
79
11
  * ```ts
80
12
  * import { mount, unmount } from 'svelte'
81
13
  * import type { ComponentProps } from 'svelte'
82
14
  * import { FeedbackModal } from '@h-ai/ui'
83
- * const props: ComponentProps<typeof FeedbackModal> = { open: true, labels: { title: '提交反馈' } }
15
+ * const props: ComponentProps<typeof FeedbackModal> = { open: true, onsubmit: async () => ({ number: 'FB-1', collectionStatus: 'collecting' }) }
84
16
  * const component = mount(FeedbackModal, { target: document.body, props })
85
17
  * await unmount(component)
86
18
  * ```