@h-ai/ui 0.1.0-alpha.74 → 0.1.0-alpha.75

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.
Files changed (58) hide show
  1. package/README.en.md +36 -4
  2. package/README.ja.md +36 -4
  3. package/README.md +36 -4
  4. package/auto-import.d.ts +2 -0
  5. package/auto-import.js +2 -0
  6. package/dist/components/compounds/Confirm.svelte +12 -2
  7. package/dist/components/compounds/Drawer.svelte +32 -14
  8. package/dist/components/compounds/FilterBar.svelte +77 -0
  9. package/dist/components/compounds/FilterBar.svelte.d.ts +39 -0
  10. package/dist/components/compounds/Modal.svelte +4 -37
  11. package/dist/components/compounds/PageHeader.svelte +18 -11
  12. package/dist/components/compounds/TableToolbar.svelte +1 -1
  13. package/dist/components/compounds/index.d.ts +1 -0
  14. package/dist/components/compounds/index.js +1 -0
  15. package/dist/components/primitives/Button.svelte +7 -0
  16. package/dist/components/primitives/Input.svelte +1 -1
  17. package/dist/components/primitives/Textarea.svelte +1 -1
  18. package/dist/components/scenes/app/FeedbackDetail.svelte +2 -2
  19. package/dist/components/scenes/app/FeedbackList.svelte +4 -4
  20. package/dist/components/scenes/app/SettingsLayout.svelte +4 -15
  21. package/dist/components/scenes/app/ThemeSelector.svelte +56 -16
  22. package/dist/components/scenes/app/WorkspaceLayout.svelte +64 -0
  23. package/dist/components/scenes/app/WorkspaceLayout.svelte.d.ts +36 -0
  24. package/dist/components/scenes/app/feedback-functions.d.ts +16 -0
  25. package/dist/components/scenes/app/feedback-functions.js +31 -0
  26. package/dist/components/scenes/app/index.d.ts +1 -0
  27. package/dist/components/scenes/app/index.js +1 -0
  28. package/dist/components/scenes/crud/CrudEditPanel.svelte +18 -9
  29. package/dist/components/scenes/crud/CrudFilterBar.svelte +39 -30
  30. package/dist/components/scenes/crud/CrudFilterBar.svelte.d.ts +4 -1
  31. package/dist/components/scenes/crud/CrudPage.svelte +27 -7
  32. package/dist/components/scenes/crud/CrudPage.svelte.d.ts +1 -1
  33. package/dist/components/scenes/crud/crud-types.d.ts +1 -1
  34. package/dist/components/scenes/guide/GuideHost.svelte +22 -102
  35. package/dist/components/scenes/guide/GuideHost.svelte.d.ts +5 -13
  36. package/dist/components/scenes/guide/GuideHostContent.svelte +143 -0
  37. package/dist/components/scenes/guide/GuideHostContent.svelte.d.ts +43 -0
  38. package/dist/components/scenes/guide/HelpCenter.svelte +22 -9
  39. package/dist/components/scenes/iam/LoginForm.svelte +25 -1
  40. package/dist/components/scenes/iam/PasswordInput.svelte +1 -1
  41. package/dist/components/scenes/types.d.ts +2 -0
  42. package/dist/guide.svelte.js +61 -26
  43. package/dist/internal/dialog-focus.d.ts +21 -0
  44. package/dist/internal/dialog-focus.js +77 -0
  45. package/dist/internal/form-validation.svelte.d.ts +2 -1
  46. package/dist/internal/form-validation.svelte.js +9 -1
  47. package/dist/messages/en-US.json +9 -2
  48. package/dist/messages/ja-JP.json +9 -2
  49. package/dist/messages/zh-CN.json +9 -2
  50. package/dist/styles/formal.css +55 -0
  51. package/dist/styles/high-contrast.css +64 -0
  52. package/dist/styles/theme.css +2 -0
  53. package/dist/theme-config.d.ts +2 -2
  54. package/dist/theme-config.js +5 -2
  55. package/dist/types.d.ts +4 -0
  56. package/dist/workspace-context.d.ts +20 -0
  57. package/dist/workspace-context.js +9 -0
  58. package/package.json +2 -2
@@ -28,6 +28,7 @@ export { default as Drawer } from './Drawer.svelte';
28
28
  export { default as Dropdown } from './Dropdown.svelte';
29
29
  // 状态占位
30
30
  export { default as Empty } from './Empty.svelte';
31
+ export { default as FilterBar } from './FilterBar.svelte';
31
32
  // 表单组合
32
33
  export { default as Form } from './Form.svelte';
33
34
  export { default as FormField } from './FormField.svelte';
@@ -14,6 +14,7 @@
14
14
  -->
15
15
  <script lang='ts'>
16
16
  import type { ButtonProps, DataAttributes } from '../../types.js'
17
+ import { uiM } from '../../messages.js'
17
18
  import { cn, getDataAttributes, getSizeClass, getVariantClass } from '../../utils.js'
18
19
 
19
20
  const {
@@ -27,6 +28,7 @@
27
28
  circle = false,
28
29
  class: className = '',
29
30
  type = 'button',
31
+ submitHint = false,
30
32
  onclick,
31
33
  children,
32
34
  ...restProps
@@ -63,6 +65,8 @@
63
65
  class={buttonClass}
64
66
  disabled={disabled || loading}
65
67
  aria-label={ariaLabel || undefined}
68
+ aria-keyshortcuts={type === 'submit' && submitHint ? 'Enter' : undefined}
69
+ title={type === 'submit' && submitHint ? uiM('keyboard_submit_enter') : undefined}
66
70
  onclick={handleClick}
67
71
  >
68
72
  {#if loading}
@@ -71,4 +75,7 @@
71
75
  {#if children}
72
76
  {@render children()}
73
77
  {/if}
78
+ {#if type === 'submit' && submitHint}
79
+ <kbd aria-hidden='true' class='ml-1 rounded border border-current/35 px-1 text-xs font-normal leading-tight'>↵</kbd>
80
+ {/if}
74
81
  </button>
@@ -99,7 +99,7 @@
99
99
  }
100
100
 
101
101
  function handleBlur(e: FocusEvent & { currentTarget: HTMLInputElement }) {
102
- validation.validate(e.currentTarget)
102
+ validation.blur(e.currentTarget)
103
103
  onblur?.(e)
104
104
  }
105
105
 
@@ -123,7 +123,7 @@
123
123
  class={textareaClass}
124
124
  bind:value
125
125
  oninput={handleInput}
126
- onblur={e => validation.validate(e.currentTarget)}
126
+ onblur={e => validation.blur(e.currentTarget)}
127
127
  oninvalid={handleInvalid}
128
128
  ></textarea>
129
129
  </div>
@@ -121,9 +121,9 @@
121
121
  }
122
122
  function changeTab(tab: string) {
123
123
  if (tab === 'environment')
124
- void query({ page: 1, kind: 'environment' })
124
+ void query({ page: 1, kind: 'environment', requestId: undefined, errorId: undefined })
125
125
  else if (tab === 'scene')
126
- void query({ page: 1, kind: 'interaction' })
126
+ void query({ page: 1, kind: 'interaction', requestId: undefined, errorId: undefined })
127
127
  else if (tab === 'logs')
128
128
  void query({ page: 1, kind: undefined })
129
129
  else if (tab === 'business')
@@ -19,7 +19,7 @@
19
19
  import TableToolbar from '../../compounds/TableToolbar.svelte'
20
20
  import Badge from '../../primitives/Badge.svelte'
21
21
  import Button from '../../primitives/Button.svelte'
22
- import { collectionLabel, feedbackTime, notificationLabel } from './feedback-functions.js'
22
+ import { collectionLabel, feedbackDateValue, feedbackDayBoundary, feedbackTime, notificationLabel } from './feedback-functions.js'
23
23
 
24
24
  let {
25
25
  data,
@@ -55,7 +55,7 @@
55
55
  let busyId = $state('')
56
56
  let search = $derived(effectiveQuery.search ?? '')
57
57
  let sortDirection = $derived(effectiveQuery.sortDirection ?? 'desc')
58
- 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
+ let filterValues = $derived<Record<string, unknown>>({ status: effectiveQuery.status ?? '', collectionStatus: effectiveQuery.collectionStatus ?? '', appId: effectiveQuery.appId ?? '', appVersion: effectiveQuery.appVersion ?? '', from: feedbackDateValue(effectiveQuery.from), to: feedbackDateValue(effectiveQuery.to) })
59
59
  const columns = $derived([
60
60
  { key: 'number', label: uiM('feedback_number') },
61
61
  { key: 'description', label: uiM('feedback_summary') },
@@ -86,8 +86,8 @@
86
86
  }
87
87
  }
88
88
  function filter(values: Record<string, unknown>) {
89
- const from = values.from ? Date.parse(String(values.from)) : undefined
90
- const to = values.to ? Date.parse(String(values.to)) + 86_400_000 - 1 : undefined
89
+ const from = feedbackDayBoundary(values.from, 'start')
90
+ const to = feedbackDayBoundary(values.to, 'end')
91
91
  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 })
92
92
  }
93
93
  async function run(report: FeedbackReportView, action: (() => void | Promise<void>) | undefined) {
@@ -21,6 +21,7 @@
21
21
  import type { Snippet } from 'svelte'
22
22
  import type { DataAttributes } from '../../../types.js'
23
23
  import { cn, getDataAttributes } from '../../../utils.js'
24
+ import PageHeader from '../../compounds/PageHeader.svelte'
24
25
  import BareButton from '../../primitives/BareButton.svelte'
25
26
 
26
27
  /**
@@ -76,25 +77,13 @@
76
77
  }
77
78
  </script>
78
79
 
79
- <div {...dataAttributes} class={cn('space-y-5', className)}>
80
+ <div {...dataAttributes} class={cn('space-y-4', className)}>
80
81
  <!-- 标题区 -->
81
82
  {#if title || description || headerActions}
82
- <div class='flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between'>
83
- <div>
84
- {#if title}
85
- <h1 class='text-xl font-semibold tracking-tight'>{title}</h1>
86
- {/if}
87
- {#if description}
88
- <p class='mt-0.5 text-sm text-base-content/45'>{description}</p>
89
- {/if}
90
- </div>
91
- {#if headerActions}
92
- <div class='flex items-center gap-2'>{@render headerActions()}</div>
93
- {/if}
94
- </div>
83
+ <PageHeader {title} {description} actions={headerActions} class='mb-0' />
95
84
  {/if}
96
85
 
97
- <div class='grid gap-6 lg:grid-cols-[13rem_minmax(0,1fr)]'>
86
+ <div class='grid gap-4 lg:grid-cols-[13rem_minmax(0,1fr)]'>
98
87
  <!-- 左侧分区导航 -->
99
88
  {#if sections.length > 0}
100
89
  <aside class='lg:sticky lg:top-4 lg:self-start'>
@@ -20,10 +20,10 @@
20
20
  <script lang='ts'>
21
21
  import type { ThemeInfo } from '../../../theme-config.js'
22
22
  import type { DataAttributes } from '../../../types.js'
23
+ import { tick } from 'svelte'
23
24
  import { uiM } from '../../../messages.js'
24
25
  import { THEME_GROUPS, THEMES } from '../../../theme-config.js'
25
26
  import { cn, getDataAttributes } from '../../../utils.js'
26
- import BareButton from '../../primitives/BareButton.svelte'
27
27
 
28
28
  /**
29
29
  * ThemeSelector 组件的属性契约;通过公开组件配置使用。
@@ -66,6 +66,7 @@
66
66
 
67
67
  const dataAttributes = $derived(getDataAttributes(restProps))
68
68
  const displaySelectLabel = $derived(selectLabel ?? uiM('theme_selector_label'))
69
+ const menuId = $props.id()
69
70
 
70
71
  let open = $state(false)
71
72
  let containerRef = $state<HTMLDivElement | null>(null)
@@ -77,6 +78,32 @@
77
78
  function selectTheme(themeId: string) {
78
79
  onchange?.(themeId)
79
80
  open = false
81
+ containerRef?.querySelector('button')?.focus()
82
+ }
83
+
84
+ async function handleKeydown(event: KeyboardEvent) {
85
+ if (event.key === 'Escape' && open) {
86
+ event.preventDefault()
87
+ event.stopPropagation()
88
+ open = false
89
+ containerRef?.querySelector('button')?.focus()
90
+ return
91
+ }
92
+ if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key))
93
+ return
94
+ event.preventDefault()
95
+ const opening = !open
96
+ open = true
97
+ await tick()
98
+ const choices = [...containerRef?.querySelectorAll<HTMLButtonElement>('[data-theme-option]') ?? []]
99
+ const current = choices.findIndex(button => button === document.activeElement)
100
+ const selected = choices.findIndex(button => button.dataset.themeOption === currentTheme)
101
+ const index = event.key === 'Home' ? 0 : event.key === 'End' ? choices.length - 1 : opening ? Math.max(0, selected) : (current + (event.key === 'ArrowDown' ? 1 : -1) + choices.length) % choices.length
102
+ choices[index]?.focus()
103
+ }
104
+
105
+ function themeName(theme: ThemeInfo): string {
106
+ return theme.id === 'high-contrast' ? uiM('theme_high_contrast') : theme.id === 'formal' ? uiM('theme_formal') : theme.name
80
107
  }
81
108
 
82
109
  function renderThemePreview(theme: ThemeInfo) {
@@ -86,7 +113,7 @@
86
113
  `
87
114
  }
88
115
 
89
- function handleClickOutside(event: MouseEvent) {
116
+ function handleClickOutside(event: MouseEvent | FocusEvent) {
90
117
  if (containerRef && !containerRef.contains(event.target as Node)) {
91
118
  open = false
92
119
  }
@@ -95,18 +122,25 @@
95
122
  $effect(() => {
96
123
  if (open) {
97
124
  document.addEventListener('click', handleClickOutside)
98
- return () => document.removeEventListener('click', handleClickOutside)
125
+ document.addEventListener('focusin', handleClickOutside)
126
+ return () => {
127
+ document.removeEventListener('click', handleClickOutside)
128
+ document.removeEventListener('focusin', handleClickOutside)
129
+ }
99
130
  }
100
131
  return undefined
101
132
  })
102
133
  </script>
103
134
 
104
135
  <div {...dataAttributes} bind:this={containerRef} class={cn('dropdown', align === 'end' ? 'dropdown-end' : '', open ? 'dropdown-open' : '', className)}>
105
- <BareButton
136
+ <button
106
137
  type='button'
107
138
  class='btn btn-ghost {compact ? 'btn-sm btn-square' : 'gap-2'}'
108
139
  onclick={() => (open = !open)}
109
- ariaLabel={displaySelectLabel}
140
+ onkeydown={handleKeydown}
141
+ aria-label={displaySelectLabel}
142
+ aria-expanded={open}
143
+ aria-controls={menuId}
110
144
  >
111
145
  <!-- 当前主题预览 -->
112
146
  {#if showPreview}
@@ -116,17 +150,17 @@
116
150
  ></div>
117
151
  {/if}
118
152
  {#if !compact}
119
- <span class='text-sm'>{currentInfo.name}</span>
153
+ <span class='text-sm'>{themeName(currentInfo)}</span>
120
154
  <!-- 下拉箭头 -->
121
155
  <svg xmlns='http://www.w3.org/2000/svg' class='h-4 w-4' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'>
122
156
  <path stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7' />
123
157
  </svg>
124
158
  {/if}
125
- </BareButton>
159
+ </button>
126
160
 
127
161
  {#if open}
128
162
  <!-- 主题列表 -->
129
- <div class='dropdown-content bg-base-100 rounded-box shadow-xl border border-base-content/10 z-50 p-4 max-h-[80vh] overflow-y-auto {compact ? 'w-56 right-0' : ''}'>
163
+ <div id={menuId} class='dropdown-content bg-base-100 rounded-box shadow-xl border border-base-content/10 z-50 p-4 max-h-[80vh] overflow-y-auto {compact ? 'w-56 right-0' : ''}'>
130
164
  {#if grouped}
131
165
  <!-- 分组显示 -->
132
166
  {#each THEME_GROUPS as group (group.nameKey)}
@@ -136,15 +170,18 @@
136
170
  </div>
137
171
  <div class='flex flex-wrap gap-2'>
138
172
  {#each group.themes as theme (theme.id)}
139
- <BareButton
173
+ <button
140
174
  type='button'
141
175
  class={cn(
142
- 'flex items-center gap-2 px-3 py-1.5 rounded-lg text-left transition-colors w-28',
176
+ 'flex min-w-28 max-w-full items-center gap-2 px-3 py-1.5 rounded-lg text-left transition-colors',
143
177
  theme.id === currentTheme
144
178
  ? 'bg-primary/10 text-primary ring-1 ring-primary/30'
145
179
  : 'hover:bg-base-200',
146
180
  )}
147
181
  onclick={() => selectTheme(theme.id)}
182
+ onkeydown={handleKeydown}
183
+ data-theme-option={theme.id}
184
+ aria-pressed={theme.id === currentTheme}
148
185
  >
149
186
  <!-- 主题预览色块 -->
150
187
  <div
@@ -152,14 +189,14 @@
152
189
  style={renderThemePreview(theme)}
153
190
  ></div>
154
191
  <!-- 主题名称 -->
155
- <span class='text-sm whitespace-nowrap'>{theme.name}</span>
192
+ <span class='text-sm'>{themeName(theme)}</span>
156
193
  <!-- 选中标记 -->
157
194
  {#if theme.id === currentTheme}
158
195
  <svg xmlns='http://www.w3.org/2000/svg' class='h-4 w-4 text-primary shrink-0' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'>
159
196
  <path stroke-linecap='round' stroke-linejoin='round' d='M5 13l4 4L19 7' />
160
197
  </svg>
161
198
  {/if}
162
- </BareButton>
199
+ </button>
163
200
  {/each}
164
201
  </div>
165
202
  </div>
@@ -168,27 +205,30 @@
168
205
  <!-- 平铺显示 -->
169
206
  <div class='flex flex-wrap gap-2'>
170
207
  {#each THEMES as theme (theme.id)}
171
- <BareButton
208
+ <button
172
209
  type='button'
173
210
  class={cn(
174
- 'flex items-center gap-2 px-3 py-1.5 rounded-lg text-left transition-colors w-28',
211
+ 'flex min-w-28 max-w-full items-center gap-2 px-3 py-1.5 rounded-lg text-left transition-colors',
175
212
  theme.id === currentTheme
176
213
  ? 'bg-primary/10 text-primary ring-1 ring-primary/30'
177
214
  : 'hover:bg-base-200',
178
215
  )}
179
216
  onclick={() => selectTheme(theme.id)}
217
+ onkeydown={handleKeydown}
218
+ data-theme-option={theme.id}
219
+ aria-pressed={theme.id === currentTheme}
180
220
  >
181
221
  <div
182
222
  class='w-4 h-4 rounded border shrink-0'
183
223
  style={renderThemePreview(theme)}
184
224
  ></div>
185
- <span class='text-sm whitespace-nowrap'>{theme.name}</span>
225
+ <span class='text-sm'>{themeName(theme)}</span>
186
226
  {#if theme.id === currentTheme}
187
227
  <svg xmlns='http://www.w3.org/2000/svg' class='h-4 w-4 text-primary shrink-0' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'>
188
228
  <path stroke-linecap='round' stroke-linejoin='round' d='M5 13l4 4L19 7' />
189
229
  </svg>
190
230
  {/if}
191
- </BareButton>
231
+ </button>
192
232
  {/each}
193
233
  </div>
194
234
  {/if}
@@ -0,0 +1,64 @@
1
+ <!--
2
+ @component WorkspaceLayout
3
+ 紧凑工作区内容框架;导航标题、主内容和可选页脚共享剩余高度。
4
+ @example
5
+ ```ts
6
+ import type { ComponentProps } from 'svelte'
7
+ import { WorkspaceLayout } from '@h-ai/ui/components/scenes/app/index'
8
+ const props: Pick<ComponentProps<typeof WorkspaceLayout>, 'title'> = { title: '用户管理' }
9
+ ```
10
+ -->
11
+ <script lang='ts'>
12
+ import type { Snippet } from 'svelte'
13
+ import type { DataAttributes } from '../../../types.js'
14
+ import type { WorkspaceContext } from '../../../workspace-context.js'
15
+ import { setContext } from 'svelte'
16
+ import { cn, getDataAttributes } from '../../../utils.js'
17
+ import { workspaceContextKey } from '../../../workspace-context.js'
18
+
19
+ /** WorkspaceLayout 组件的属性契约。
20
+ * @example
21
+ * ```ts
22
+ * import type { ComponentProps } from 'svelte'
23
+ * import { WorkspaceLayout } from '@h-ai/ui'
24
+ * const props: Pick<ComponentProps<typeof WorkspaceLayout>, 'title'> = { title: '工作区' }
25
+ * void props
26
+ * ```
27
+ */
28
+ interface Props extends DataAttributes {
29
+ /** 已在导航显示的页面标题;省略时仅提供内容布局。 */
30
+ title?: string
31
+ /** 导航标题前的菜单按钮或面包屑。 */
32
+ leading?: Snippet
33
+ /** 导航右侧操作。 */
34
+ actions?: Snippet
35
+ /** 页脚内容;未提供时不预留页脚高度。 */
36
+ footer?: Snippet
37
+ children: Snippet
38
+ class?: string
39
+ }
40
+ const { title = '', leading, actions, footer, children, class: className = '', ...restProps }: Props = $props()
41
+ const headingId = $props.id()
42
+ const dataAttributes = $derived(getDataAttributes(restProps))
43
+ setContext<WorkspaceContext>(workspaceContextKey, {
44
+ get title() {
45
+ return title
46
+ },
47
+ })
48
+ </script>
49
+
50
+ <div class={cn('hai-workspace flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden', className)}>
51
+ {#if title || leading || actions}
52
+ <header class='flex min-h-12 shrink-0 flex-wrap items-center justify-between gap-2 border-b border-base-content/8 bg-base-100 px-3 sm:px-4'>
53
+ <div class='flex min-w-0 flex-1 basis-40 items-center gap-2'>
54
+ {#if leading}{@render leading()}{/if}
55
+ {#if title}<h1 id={headingId} class='min-w-0 truncate text-sm font-semibold'>{title}</h1>{/if}
56
+ </div>
57
+ {#if actions}<div class='ml-auto flex max-w-full shrink-0 flex-wrap items-center gap-1.5 sm:gap-2'>{@render actions()}</div>{/if}
58
+ </header>
59
+ {/if}
60
+ <main {...dataAttributes} aria-labelledby={title ? headingId : undefined} class='flex min-h-0 min-w-0 flex-1 flex-col overflow-auto p-3 sm:p-4'>
61
+ {@render children()}
62
+ </main>
63
+ {#if footer}<footer class='shrink-0 border-t border-base-content/8 px-3 py-1 text-center text-xs text-base-content/45 sm:px-4'>{@render footer()}</footer>{/if}
64
+ </div>
@@ -0,0 +1,36 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { DataAttributes } from '../../../types.js';
3
+ /** WorkspaceLayout 组件的属性契约。
4
+ * @example
5
+ * ```ts
6
+ * import type { ComponentProps } from 'svelte'
7
+ * import { WorkspaceLayout } from '@h-ai/ui'
8
+ * const props: Pick<ComponentProps<typeof WorkspaceLayout>, 'title'> = { title: '工作区' }
9
+ * void props
10
+ * ```
11
+ */
12
+ interface Props extends DataAttributes {
13
+ /** 已在导航显示的页面标题;省略时仅提供内容布局。 */
14
+ title?: string;
15
+ /** 导航标题前的菜单按钮或面包屑。 */
16
+ leading?: Snippet;
17
+ /** 导航右侧操作。 */
18
+ actions?: Snippet;
19
+ /** 页脚内容;未提供时不预留页脚高度。 */
20
+ footer?: Snippet;
21
+ children: Snippet;
22
+ class?: string;
23
+ }
24
+ /**
25
+ * WorkspaceLayout
26
+ * 紧凑工作区内容框架;导航标题、主内容和可选页脚共享剩余高度。
27
+ * @example
28
+ * ```ts
29
+ * import type { ComponentProps } from 'svelte'
30
+ * import { WorkspaceLayout } from '@h-ai/ui/components/scenes/app/index'
31
+ * const props: Pick<ComponentProps<typeof WorkspaceLayout>, 'title'> = { title: '用户管理' }
32
+ * ```
33
+ */
34
+ declare const WorkspaceLayout: import("svelte").Component<Props, {}, "">;
35
+ type WorkspaceLayout = ReturnType<typeof WorkspaceLayout>;
36
+ export default WorkspaceLayout;
@@ -23,6 +23,22 @@ export declare function notificationLabel(status: FeedbackReportView['notificati
23
23
  * ```
24
24
  */
25
25
  export declare function feedbackTime(timestamp: number): string;
26
+ /**
27
+ * 按本地日历回填日期输入,避免 UTC 转换改变用户选择的日期。
28
+ * @example 模块内部上下文
29
+ * ```ts
30
+ * const value = feedbackDateValue(new Date(2026, 9, 27).getTime())
31
+ * ```
32
+ */
33
+ export declare function feedbackDateValue(timestamp?: number): string;
34
+ /**
35
+ * 次日零时按本地日历计算,夏令时切换日不假定固定为 24 小时。
36
+ * @example 模块内部上下文
37
+ * ```ts
38
+ * const until = feedbackDayBoundary('2026-03-08', 'end')
39
+ * ```
40
+ */
41
+ export declare function feedbackDayBoundary(value: unknown, boundary: 'start' | 'end'): number | undefined;
26
42
  /**
27
43
  * 以文本显示 JSON,不将诊断材料解释为 HTML。
28
44
  * @example 模块内部上下文
@@ -43,6 +43,37 @@ export function notificationLabel(status) {
43
43
  export function feedbackTime(timestamp) {
44
44
  return Number.isFinite(timestamp) ? new Date(timestamp).toLocaleString(getUILocale()) : '—';
45
45
  }
46
+ /**
47
+ * 按本地日历回填日期输入,避免 UTC 转换改变用户选择的日期。
48
+ * @example 模块内部上下文
49
+ * ```ts
50
+ * const value = feedbackDateValue(new Date(2026, 9, 27).getTime())
51
+ * ```
52
+ */
53
+ export function feedbackDateValue(timestamp) {
54
+ if (timestamp === undefined || !Number.isFinite(timestamp))
55
+ return '';
56
+ const date = new Date(timestamp);
57
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
58
+ }
59
+ /**
60
+ * 次日零时按本地日历计算,夏令时切换日不假定固定为 24 小时。
61
+ * @example 模块内部上下文
62
+ * ```ts
63
+ * const until = feedbackDayBoundary('2026-03-08', 'end')
64
+ * ```
65
+ */
66
+ export function feedbackDayBoundary(value, boundary) {
67
+ if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value))
68
+ return undefined;
69
+ const [year, month, day] = value.split('-').map(Number);
70
+ const date = new Date(year, month - 1, day);
71
+ if (feedbackDateValue(date.getTime()) !== value)
72
+ return undefined;
73
+ if (boundary === 'end')
74
+ date.setDate(date.getDate() + 1);
75
+ return date.getTime() - (boundary === 'end' ? 1 : 0);
76
+ }
46
77
  /**
47
78
  * 以文本显示 JSON,不将诊断材料解释为 HTML。
48
79
  * @example 模块内部上下文
@@ -15,3 +15,4 @@ export { default as SettingsModal } from './SettingsModal.svelte';
15
15
  export { default as ThemeColorPicker } from './ThemeColorPicker.svelte';
16
16
  export { default as ThemeSelector } from './ThemeSelector.svelte';
17
17
  export { default as ThemeToggle } from './ThemeToggle.svelte';
18
+ export { default as WorkspaceLayout } from './WorkspaceLayout.svelte';
@@ -14,3 +14,4 @@ export { default as SettingsModal } from './SettingsModal.svelte';
14
14
  export { default as ThemeColorPicker } from './ThemeColorPicker.svelte';
15
15
  export { default as ThemeSelector } from './ThemeSelector.svelte';
16
16
  export { default as ThemeToggle } from './ThemeToggle.svelte';
17
+ export { default as WorkspaceLayout } from './WorkspaceLayout.svelte';
@@ -90,10 +90,12 @@
90
90
  let formElement: HTMLFormElement | undefined = $state()
91
91
  let attempted = $state(false)
92
92
  let touched = $state<Record<string, boolean>>({})
93
+ let edited = $state<Record<string, boolean>>({})
93
94
  $effect(() => {
94
95
  if (!open) {
95
96
  attempted = false
96
97
  touched = {}
98
+ edited = {}
97
99
  }
98
100
  })
99
101
  function resolveOptions(options?: CrudFieldDef['options']): Array<{ label: string, value: string | number | boolean }> {
@@ -156,6 +158,7 @@
156
158
  }
157
159
 
158
160
  function updateField(fieldId: string, value: unknown) {
161
+ edited = { ...edited, [fieldId]: true }
159
162
  formData = { ...formData, [fieldId]: value }
160
163
  }
161
164
 
@@ -165,17 +168,22 @@
165
168
  const field = event.target.closest<HTMLElement>('[data-field]')
166
169
  if (!field?.dataset.field || (event.relatedTarget instanceof Node && field.contains(event.relatedTarget)))
167
170
  return
168
- touched = { ...touched, [field.dataset.field]: true }
171
+ const fieldId = field.dataset.field
172
+ const value = formData[fieldId]
173
+ // 默认焦点离开未输入空字段时保持操作位置;提交仍统一验证全部字段。
174
+ if (!attempted && !edited[fieldId] && (value === undefined || value === null || value === '' || value === false || (Array.isArray(value) && value.length === 0)))
175
+ return
176
+ touched = { ...touched, [fieldId]: true }
169
177
  }
170
178
 
171
179
  function toggleMultiSelect(fieldId: string, optValue: string | number | boolean) {
172
180
  const current = (formData[fieldId] as Array<string | number | boolean>) ?? []
173
181
  const strVal = String(optValue)
174
182
  if (current.map(String).includes(strVal)) {
175
- formData = { ...formData, [fieldId]: current.filter(v => String(v) !== strVal) }
183
+ updateField(fieldId, current.filter(v => String(v) !== strVal))
176
184
  }
177
185
  else {
178
- formData = { ...formData, [fieldId]: [...current, optValue] }
186
+ updateField(fieldId, [...current, optValue])
179
187
  }
180
188
  }
181
189
  </script>
@@ -296,7 +304,7 @@
296
304
  <Button variant='ghost' size='sm' onclick={handleClose} disabled={submitting}>
297
305
  {uiM('crud_cancel')}
298
306
  </Button>
299
- <Button variant='primary' size='sm' onclick={() => formElement?.requestSubmit()} disabled={submitting}>
307
+ <Button variant='primary' size='sm' type='submit' form={panelId} submitHint disabled={submitting}>
300
308
  {#if submitting}
301
309
  <span class='loading loading-spinner loading-xs mr-2'></span>
302
310
  {/if}
@@ -313,11 +321,11 @@
313
321
  width={modalWidth}
314
322
  height={modalHeight}
315
323
  closeOnBackdrop={false}
324
+ closeOnEscape={!submitting}
325
+ showClose={!submitting}
316
326
  onclose={handleClose}
317
327
  >
318
- <form bind:this={formElement} novalidate onsubmit={handleSubmit} onfocusout={handleFieldBlur}>
319
- <!-- 底部按钮在表单外;保留原生提交控件,使多字段表单支持回车提交。 -->
320
- <input type='submit' class='hidden' tabindex='-1' aria-hidden='true' value={uiM('crud_save')} />
328
+ <form id={panelId} bind:this={formElement} novalidate onsubmit={handleSubmit} onfocusout={handleFieldBlur}>
321
329
  {@render formFields()}
322
330
  </form>
323
331
 
@@ -337,9 +345,10 @@
337
345
  widthStorageKey={drawerWidthStorageKey}
338
346
  onclose={handleClose}
339
347
  closeOnBackdrop={false}
348
+ closeOnEscape={!submitting}
349
+ showClose={!submitting}
340
350
  >
341
- <form bind:this={formElement} novalidate onsubmit={handleSubmit} onfocusout={handleFieldBlur} class={drawerFormClass}>
342
- <input type='submit' class='hidden' tabindex='-1' aria-hidden='true' value={uiM('crud_save')} />
351
+ <form id={panelId} bind:this={formElement} novalidate onsubmit={handleSubmit} onfocusout={handleFieldBlur} class={drawerFormClass}>
343
352
  {@render formFields()}
344
353
  </form>
345
354