@h-ai/ui 1.0.0-beta.17 → 1.0.0-beta.19

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 (100) hide show
  1. package/README.en.md +30 -27
  2. package/README.ja.md +30 -27
  3. package/README.md +30 -27
  4. package/auto-import.js +118 -53
  5. package/dist/components/compounds/Accordion.svelte +6 -2
  6. package/dist/components/compounds/BottomNav.svelte +6 -2
  7. package/dist/components/compounds/Card.svelte +3 -1
  8. package/dist/components/compounds/Combobox.svelte +24 -6
  9. package/dist/components/compounds/DataTable.svelte +28 -8
  10. package/dist/components/compounds/DatePicker.svelte +6 -1
  11. package/dist/components/compounds/Drawer.svelte +12 -4
  12. package/dist/components/compounds/Dropdown.svelte +9 -2
  13. package/dist/components/compounds/Empty.svelte +10 -2
  14. package/dist/components/compounds/FormField.svelte +10 -2
  15. package/dist/components/compounds/JsonViewer.svelte +18 -6
  16. package/dist/components/compounds/Modal.svelte +8 -2
  17. package/dist/components/compounds/Pagination.svelte +22 -7
  18. package/dist/components/compounds/Popover.svelte +28 -3
  19. package/dist/components/compounds/Steps.svelte +6 -2
  20. package/dist/components/compounds/SwipeCell.svelte +3 -1
  21. package/dist/components/compounds/TableToolbar.svelte +32 -9
  22. package/dist/components/compounds/Tabs.svelte +15 -5
  23. package/dist/components/compounds/Timeline.svelte +6 -2
  24. package/dist/components/compounds/ToastContainer.svelte +27 -7
  25. package/dist/components/control-size.js +48 -8
  26. package/dist/components/primitives/Avatar.svelte +9 -3
  27. package/dist/components/primitives/BareInput.svelte +3 -1
  28. package/dist/components/primitives/Button.svelte +6 -2
  29. package/dist/components/primitives/IconButton.svelte +3 -1
  30. package/dist/components/primitives/Input.svelte +18 -2
  31. package/dist/components/primitives/Radio.svelte +3 -1
  32. package/dist/components/primitives/Range.svelte +3 -1
  33. package/dist/components/primitives/Rating.svelte +9 -3
  34. package/dist/components/primitives/Select.svelte +21 -5
  35. package/dist/components/primitives/Textarea.svelte +14 -2
  36. package/dist/components/scenes/ai/AiDocumentEditor.svelte +40 -12
  37. package/dist/components/scenes/ai/document-download.js +6 -2
  38. package/dist/components/scenes/ai/document-parse.js +24 -8
  39. package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
  40. package/dist/components/scenes/ai/highlight.js +3 -1
  41. package/dist/components/scenes/ai/markdown-parse.js +36 -10
  42. package/dist/components/scenes/ai/mermaid-render.js +13 -1
  43. package/dist/components/scenes/ai/safe-html.js +9 -3
  44. package/dist/components/scenes/ai/table/AiTableEditor.svelte +27 -9
  45. package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
  46. package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
  47. package/dist/components/scenes/app/FeedbackList.svelte +138 -21
  48. package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
  49. package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
  50. package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
  51. package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
  52. package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
  53. package/dist/components/scenes/app/ThemeSelector.svelte +22 -4
  54. package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
  55. package/dist/components/scenes/app/feedback-functions.js +6 -2
  56. package/dist/components/scenes/charts/Chart.svelte +16 -5
  57. package/dist/components/scenes/charts/MetricCard.svelte +21 -4
  58. package/dist/components/scenes/charts/chart-presets.js +42 -5
  59. package/dist/components/scenes/charts/renderers/LineChart.svelte +38 -12
  60. package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
  61. package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
  62. package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
  63. package/dist/components/scenes/crud/CrudPage.svelte +34 -9
  64. package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
  65. package/dist/components/scenes/crud/crud-form-validation.js +27 -9
  66. package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
  67. package/dist/components/scenes/error/error-presets.js +30 -5
  68. package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
  69. package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
  70. package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
  71. package/dist/components/scenes/iam/AuthPanel.svelte +73 -15
  72. package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
  73. package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
  74. package/dist/components/scenes/iam/LoginForm.svelte +32 -8
  75. package/dist/components/scenes/iam/PasswordInput.svelte +49 -11
  76. package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
  77. package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
  78. package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
  79. package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
  80. package/dist/components/scenes/iam/UserProfile.svelte +41 -14
  81. package/dist/components/scenes/iam/auth-captcha.js +9 -2
  82. package/dist/components/scenes/iam/auth-error-message.js +11 -3
  83. package/dist/components/scenes/iam/password-utils.js +9 -2
  84. package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
  85. package/dist/components/scenes/storage/FileList.svelte +3 -1
  86. package/dist/components/scenes/storage/FileUpload.svelte +7 -2
  87. package/dist/components/scenes/types.d.ts +2 -2
  88. package/dist/guide-storage.js +12 -4
  89. package/dist/guide.svelte.js +59 -16
  90. package/dist/i18n.svelte.js +9 -3
  91. package/dist/internal/dialog-focus.d.ts +19 -0
  92. package/dist/internal/dialog-focus.js +104 -4
  93. package/dist/internal/form-validation.svelte.js +46 -15
  94. package/dist/internal/icon-safety.js +6 -2
  95. package/dist/message.svelte.js +6 -2
  96. package/dist/messagebox.svelte.js +6 -2
  97. package/dist/theme-config.js +135 -21
  98. package/dist/toast.svelte.js +14 -3
  99. package/dist/utils.js +6 -2
  100. package/package.json +19 -19
@@ -53,7 +53,15 @@
53
53
  let renewalIdentifier = $state('')
54
54
  let actionError = $state<HaiError>()
55
55
  let networkFailed = $state(false)
56
- const errors = $derived<Record<string, string>>(actionError ? { general: authErrorMessage(actionError) } : networkFailed ? { general: uiM('auth_network_error') } : {})
56
+ const errors = $derived<Record<string, string>>(actionError
57
+ ? {
58
+ general: authErrorMessage(actionError),
59
+ }
60
+ : networkFailed
61
+ ? {
62
+ general: uiM('auth_network_error'),
63
+ }
64
+ : {})
57
65
  let notice = $state<UIMessageKey | ''>('')
58
66
  // SSR 表单先显示但不可编辑;客户端绑定事件后开放输入,避免接管时丢失早到的输入。
59
67
  let interactive = $state(false)
@@ -63,9 +71,23 @@
63
71
  interactive = true
64
72
  return () => captchaController?.abort()
65
73
  })
66
- const methods = $derived(config ? (['password', 'ldap', 'email', 'sms'] as AuthLoginMethod[]).filter(method => config.login[method]) : [])
67
- const title = $derived(mode === 'register' ? uiM('register_title') : mode === 'forgot' ? uiM('forgot_password_title') : mode === 'renew' ? uiM('auth_renew_title') : mode === 'reset' ? uiM('reset_password_title') : uiM('login_title'))
68
- const available = $derived(config && (mode === 'login' || (mode === 'renew' ? Boolean(actions.renewPassword) : mode === 'register' ? config.register.enabled : config.passwordReset.enabled)))
74
+ const methods = $derived(config
75
+ ? (['password', 'ldap', 'email', 'sms'] as AuthLoginMethod[]).filter(method => config.login[method])
76
+ : [])
77
+ const title = $derived(mode === 'register'
78
+ ? uiM('register_title')
79
+ : mode === 'forgot'
80
+ ? uiM('forgot_password_title')
81
+ : mode === 'renew'
82
+ ? uiM('auth_renew_title')
83
+ : mode === 'reset'
84
+ ? uiM('reset_password_title')
85
+ : uiM('login_title'))
86
+ const available = $derived(config && (mode === 'login' || (mode === 'renew'
87
+ ? Boolean(actions.renewPassword)
88
+ : mode === 'register'
89
+ ? config.register.enabled
90
+ : config.passwordReset.enabled)))
69
91
 
70
92
  function switchMode(next: AuthPanelMode) {
71
93
  captchaController?.abort()
@@ -141,13 +163,22 @@
141
163
  const renew = actions.renewPassword
142
164
  if (!renew || loading || !renewalIdentifier.trim())
143
165
  return
144
- await run(() => withCaptcha('renewPassword', captcha => renew({ identifier: renewalIdentifier.trim(), password, newPassword, captcha })), false, 'auth_reset_done')
166
+ await run(() => withCaptcha('renewPassword', captcha => renew({
167
+ identifier: renewalIdentifier.trim(),
168
+ password,
169
+ newPassword,
170
+ captcha,
171
+ })), false, 'auth_reset_done')
145
172
  if (!actionError && !networkFailed)
146
173
  mode = 'login'
147
174
  }
148
175
  useToastFeedback(() => error)
149
- useToastFeedback(() => notice ? uiM(notice) : '', 'info')
150
- useToastFeedback(() => config && !available ? uiM('auth_unavailable') : '', 'warning')
176
+ useToastFeedback(() => notice
177
+ ? uiM(notice)
178
+ : '', 'info')
179
+ useToastFeedback(() => config && !available
180
+ ? uiM('auth_unavailable')
181
+ : '', 'warning')
151
182
  </script>
152
183
 
153
184
  {#snippet link(next: AuthPanelMode, label: string, href?: string)}
@@ -179,15 +210,27 @@
179
210
  {:else if !available}
180
211
  <div class='mt-4 text-center'>{@render link('login', uiM('login_submit'), loginUrl)}</div>
181
212
  {:else}
182
- <span role='status' class='sr-only'>{verifying ? uiM('auth_captcha_verifying') : ''}</span>
213
+ <span role='status' class='sr-only'>{verifying
214
+ ? uiM('auth_captcha_verifying')
215
+ : ''}</span>
183
216
  {#if mode === 'login'}
184
- <LoginForm {initialIdentifier} submitText={verifying ? uiM('auth_captcha_verifying') : undefined} {columns} {labelPosition} {labelWidth} {methods} {loading} {errors} header={loginHeader} extraFields={loginFields} showForgotPassword={config.passwordReset.enabled} {forgotPasswordUrl}
185
- onforgotpassword={forgotPasswordUrl ? undefined : () => switchMode('forgot')}
217
+ <LoginForm {initialIdentifier} submitText={verifying
218
+ ? uiM('auth_captcha_verifying')
219
+ : undefined} {columns} {labelPosition} {labelWidth} {methods} {loading} {errors} header={loginHeader} extraFields={loginFields} showForgotPassword={config.passwordReset.enabled} {forgotPasswordUrl}
220
+ onforgotpassword={forgotPasswordUrl
221
+ ? undefined
222
+ : () => switchMode('forgot')}
186
223
  otpLength={config.otp.length} resendInterval={config.otp.resendInterval} onsendotp={identifier => withCaptcha('sendOtp', captcha => actions.sendOtp(identifier, { captcha }))}
187
224
  agreements={config.agreements.showOnLogin ? config.agreements : undefined}
188
225
  onsubmit={(data) => {
189
226
  renewalIdentifier = data.username
190
- return run(() => withCaptcha('login', captcha => actions.login({ identifier: data.username, password: data.password, method: data.method, code: data.code, captcha })), true)
227
+ return run(() => withCaptcha('login', captcha => actions.login({
228
+ identifier: data.username,
229
+ password: data.password,
230
+ method: data.method,
231
+ code: data.code,
232
+ captcha,
233
+ })), true)
191
234
  }}>
192
235
  {#snippet footer()}
193
236
  {#if loginFooter}{@render loginFooter()}{/if}
@@ -195,15 +238,28 @@
195
238
  {/snippet}
196
239
  </LoginForm>
197
240
  {:else if mode === 'register'}
198
- <RegisterForm submitText={verifying ? uiM('auth_captcha_verifying') : undefined} {columns} {labelPosition} {labelWidth} {loading} {errors} header={registerHeader} extraFields={registerFields} fields={config.passwordReset.mode === 'phone' ? ['username', 'phone', 'password'] : ['username', 'email', 'password']} passwordPolicy={config.password} minPasswordLength={config.password.minLength}
199
- agreements={config.agreements.showOnRegister ? config.agreements : undefined} onsubmit={data => run(() => withCaptcha('register', captcha => actions.register({ username: data.username || '', password: data.password, email: data.email, phone: data.phone, displayName: data.nickname, captcha })), true)}>
241
+ <RegisterForm submitText={verifying
242
+ ? uiM('auth_captcha_verifying')
243
+ : undefined} {columns} {labelPosition} {labelWidth} {loading} {errors} header={registerHeader} extraFields={registerFields} fields={config.passwordReset.mode === 'phone'
244
+ ? ['username', 'phone', 'password']
245
+ : ['username', 'email', 'password']} passwordPolicy={config.password} minPasswordLength={config.password.minLength}
246
+ agreements={config.agreements.showOnRegister ? config.agreements : undefined} onsubmit={data => run(() => withCaptcha('register', captcha => actions.register({
247
+ username: data.username || '',
248
+ password: data.password,
249
+ email: data.email,
250
+ phone: data.phone,
251
+ displayName: data.nickname,
252
+ captcha,
253
+ })), true)}>
200
254
  {#snippet footer()}
201
255
  {#if registerFooter}{@render registerFooter()}{/if}
202
256
  <div class='text-center'>{@render link('login', uiM('register_login_now'), loginUrl)}</div>
203
257
  {/snippet}
204
258
  </RegisterForm>
205
259
  {:else if mode === 'forgot'}
206
- <ForgotPasswordForm submitText={verifying ? uiM('auth_captcha_verifying') : undefined} {columns} {labelPosition} {labelWidth} {loading} {errors} mode={config.passwordReset.mode ?? 'email'} onsubmit={data => run(() => withCaptcha('passwordReset', captcha => actions.requestPasswordReset(data.email || data.phone || '', { captcha })), false, 'auth_reset_sent')}>
260
+ <ForgotPasswordForm submitText={verifying
261
+ ? uiM('auth_captcha_verifying')
262
+ : undefined} {columns} {labelPosition} {labelWidth} {loading} {errors} mode={config.passwordReset.mode ?? 'email'} onsubmit={data => run(() => withCaptcha('passwordReset', captcha => actions.requestPasswordReset(data.email || data.phone || '', { captcha })), false, 'auth_reset_sent')}>
207
263
  {#snippet footer()}<div class='flex justify-between gap-3'>{@render link('login', uiM('login_submit'), loginUrl)}{@render link('reset', uiM('auth_have_token'))}</div>{/snippet}
208
264
  </ForgotPasswordForm>
209
265
  {:else if mode === 'renew'}
@@ -212,7 +268,9 @@
212
268
  <Input id='renew-identifier' autocomplete='username' bind:value={renewalIdentifier} disabled={loading} required />
213
269
  </FormField>
214
270
  </div>
215
- <ChangePasswordForm submitText={verifying ? uiM('auth_captcha_verifying') : undefined} {columns} {labelPosition} {labelWidth} {loading} {errors} disabled={!renewalIdentifier.trim()} passwordPolicy={config.password} minPasswordLength={config.password.minLength}
271
+ <ChangePasswordForm submitText={verifying
272
+ ? uiM('auth_captcha_verifying')
273
+ : undefined} {columns} {labelPosition} {labelWidth} {loading} {errors} disabled={!renewalIdentifier.trim()} passwordPolicy={config.password} minPasswordLength={config.password.minLength}
216
274
  onsubmit={data => renewPassword(data.oldPassword || '', data.newPassword)} />
217
275
  <div class='mt-4 text-center'>{@render link('login', uiM('login_submit'), loginUrl)}</div>
218
276
  {:else}
@@ -46,7 +46,9 @@
46
46
  let newPassword = $state('')
47
47
  let confirmPassword = $state('')
48
48
 
49
- const policyError = $derived(passwordPolicy && newPassword ? passwordPolicyError(newPassword, passwordPolicy) : '')
49
+ const policyError = $derived(passwordPolicy && newPassword
50
+ ? passwordPolicyError(newPassword, passwordPolicy)
51
+ : '')
50
52
 
51
53
  const formClass = $derived(
52
54
  cn(
@@ -131,7 +133,9 @@
131
133
  oninput={(e) => { confirmPassword = e.currentTarget.value }}
132
134
  placeholder={uiM('change_password_confirm_placeholder')}
133
135
  {disabled}
134
- error={errors.confirmPassword || (!passwordsMatch && confirmPassword ? uiM('change_password_mismatch') : '')}
136
+ error={errors.confirmPassword || (!passwordsMatch && confirmPassword
137
+ ? uiM('change_password_mismatch')
138
+ : '')}
135
139
  showStrength={false}
136
140
  />
137
141
  </FormField>
@@ -63,7 +63,9 @@
63
63
 
64
64
  function getSubmittedValue(formData: FormData, key: string, fallback = ''): string | undefined {
65
65
  const submitted = formData.get(key)
66
- const value = typeof submitted === 'string' ? submitted : fallback
66
+ const value = typeof submitted === 'string'
67
+ ? submitted
68
+ : fallback
67
69
  const trimmed = value.trim()
68
70
  return trimmed || undefined
69
71
  }
@@ -76,8 +78,12 @@
76
78
  const submittedFormData = new FormData(e.currentTarget as HTMLFormElement)
77
79
 
78
80
  const data: ForgotPasswordFormData = {
79
- email: mode === 'email' ? getSubmittedValue(submittedFormData, 'email', email) : undefined,
80
- phone: mode === 'phone' ? getSubmittedValue(submittedFormData, 'phone', phone) : undefined,
81
+ email: mode === 'email'
82
+ ? getSubmittedValue(submittedFormData, 'email', email)
83
+ : undefined,
84
+ phone: mode === 'phone'
85
+ ? getSubmittedValue(submittedFormData, 'phone', phone)
86
+ : undefined,
81
87
  }
82
88
 
83
89
  await onsubmit?.(data)
@@ -65,8 +65,12 @@
65
65
  let username = $state(untrack(() => initialIdentifier))
66
66
  let password = $state('')
67
67
  let selectedMethod = $state<AuthLoginMethod>('password')
68
- const method = $derived(methods.includes(selectedMethod) ? selectedMethod : methods[0])
69
- useToastFeedback(() => !method ? uiM('auth_unavailable') : '', 'warning')
68
+ const method = $derived(methods.includes(selectedMethod)
69
+ ? selectedMethod
70
+ : methods[0])
71
+ useToastFeedback(() => !method
72
+ ? uiM('auth_unavailable')
73
+ : '', 'warning')
70
74
  const isOtp = $derived(method === 'email' || method === 'sms')
71
75
  $effect(() => {
72
76
  if (!autoFocus || focusedInitially || disabled || loading || !method || !formElement)
@@ -90,7 +94,11 @@
90
94
  let code = $state('')
91
95
  let sending = $state(false)
92
96
  let sendFailure = $state<Pick<HaiError, 'code' | 'message' | 'traceId' | 'httpStatus'> | 'network'>()
93
- const sendError = $derived(sendFailure === 'network' ? uiM('auth_network_error') : sendFailure ? authErrorMessage(sendFailure) : '')
97
+ const sendError = $derived(sendFailure === 'network'
98
+ ? uiM('auth_network_error')
99
+ : sendFailure
100
+ ? authErrorMessage(sendFailure)
101
+ : '')
94
102
  let resendAt = $state(0)
95
103
  let now = $state(Date.now())
96
104
  const remaining = $derived(Math.max(0, Math.ceil((resendAt - now) / 1000)))
@@ -182,7 +190,9 @@
182
190
  {#if methods.length > 1}
183
191
  <div class='grid grid-cols-2 gap-1 rounded-lg bg-base-200 p-1 sm:flex' aria-label={uiM('login_methods')}>
184
192
  {#each methods as value (value)}
185
- <button type='button' class={cn('flex-1 rounded-md px-2 py-2 text-sm transition-colors', method === value ? 'bg-base-100 font-medium shadow-sm' : 'text-base-content/60')} aria-pressed={method === value} disabled={loading || disabled} onclick={() => {
193
+ <button type='button' class={cn('flex-1 rounded-md px-2 py-2 text-sm transition-colors', method === value
194
+ ? 'bg-base-100 font-medium shadow-sm'
195
+ : 'text-base-content/60')} aria-pressed={method === value} disabled={loading || disabled} onclick={() => {
186
196
  selectedMethod = value
187
197
  password = ''
188
198
  code = ''
@@ -195,12 +205,24 @@
195
205
  {/if}
196
206
  {#if method === 'ldap'}<p class='text-sm text-base-content/70'>{uiM('login_method_ldap_hint')}</p>{/if}
197
207
  {#if method}
198
- <FormField for='login-username' label={method === 'email' ? uiM('register_email') : method === 'sms' ? uiM('register_phone') : uiM('login_username')}>
208
+ <FormField for='login-username' label={method === 'email'
209
+ ? uiM('register_email')
210
+ : method === 'sms'
211
+ ? uiM('register_phone')
212
+ : uiM('login_username')}>
199
213
  <Input
200
214
  id='login-username'
201
215
  name='username'
202
- type={method === 'email' ? 'email' : method === 'sms' ? 'tel' : 'text'}
203
- placeholder={method === 'email' ? uiM('register_email_placeholder') : method === 'sms' ? uiM('register_phone_placeholder') : uiM('login_username_placeholder')}
216
+ type={method === 'email'
217
+ ? 'email'
218
+ : method === 'sms'
219
+ ? 'tel'
220
+ : 'text'}
221
+ placeholder={method === 'email'
222
+ ? uiM('register_email_placeholder')
223
+ : method === 'sms'
224
+ ? uiM('register_phone_placeholder')
225
+ : uiM('login_username_placeholder')}
204
226
  bind:value={username}
205
227
  autocomplete='username'
206
228
  {disabled}
@@ -215,7 +237,9 @@
215
237
  <div class='flex items-start gap-2'>
216
238
  <Input id='login-code' name='code' bind:value={code} autocomplete='one-time-code' inputmode='numeric' maxlength={otpLength} pattern={`[0-9]{${otpLength}}`} placeholder={uiM('login_code_placeholder', { length: otpLength })} required {disabled} />
217
239
  <Button type='button' variant='outline' loading={sending} disabled={loading || disabled || !username.trim() || remaining > 0 || !onsendotp} onclick={sendOtp}>
218
- {remaining ? uiM('login_resend_wait', { seconds: remaining }) : uiM('login_send_code')}
240
+ {remaining
241
+ ? uiM('login_resend_wait', { seconds: remaining })
242
+ : uiM('login_send_code')}
219
243
  </Button>
220
244
  </div>
221
245
  </FormField>
@@ -102,7 +102,13 @@
102
102
 
103
103
  const dataAttributes = $derived(getDataAttributes(restProps))
104
104
  const field = getFormFieldContext()
105
- const validation = createControlValidation(undefined, () => [value, required, readonly, disabled, minLength])
105
+ const validation = createControlValidation(undefined, () => [
106
+ value,
107
+ required,
108
+ readonly,
109
+ disabled,
110
+ minLength,
111
+ ])
106
112
  const uniqueId = $props.id()
107
113
  const messageId = `${uniqueId}-error`
108
114
  const localError = $derived(resolveFormText(error) || validation.message)
@@ -150,13 +156,32 @@
150
156
  score += 1
151
157
 
152
158
  // 返回强度等级
153
- if (score <= 2)
154
- return { score: 1, label: uiM('password_strength_weak'), color: 'bg-error' }
155
- if (score <= 4)
156
- return { score: 2, label: uiM('password_strength_fair'), color: 'bg-warning' }
157
- if (score <= 5)
158
- return { score: 3, label: uiM('password_strength_good'), color: 'bg-success' }
159
- return { score: 4, label: uiM('password_strength_strong'), color: 'bg-primary' }
159
+ if (score <= 2) {
160
+ return {
161
+ score: 1,
162
+ label: uiM('password_strength_weak'),
163
+ color: 'bg-error',
164
+ }
165
+ }
166
+ if (score <= 4) {
167
+ return {
168
+ score: 2,
169
+ label: uiM('password_strength_fair'),
170
+ color: 'bg-warning',
171
+ }
172
+ }
173
+ if (score <= 5) {
174
+ return {
175
+ score: 3,
176
+ label: uiM('password_strength_good'),
177
+ color: 'bg-success',
178
+ }
179
+ }
180
+ return {
181
+ score: 4,
182
+ label: uiM('password_strength_strong'),
183
+ color: 'bg-primary',
184
+ }
160
185
  })
161
186
 
162
187
  function handleInput(e: Event & { currentTarget: HTMLInputElement }) {
@@ -199,7 +224,12 @@
199
224
  {required}
200
225
  minlength={minLength}
201
226
  ariaInvalid={effectiveError ? true : undefined}
202
- ariaDescribedby={[field?.messageId, localError && !field?.error ? messageId : ''].filter(Boolean).join(' ') || undefined}
227
+ ariaDescribedby={[
228
+ field?.messageId,
229
+ localError && !field?.error
230
+ ? messageId
231
+ : '',
232
+ ].filter(Boolean).join(' ') || undefined}
203
233
  oninput={handleInput}
204
234
  onchange={handleChange}
205
235
  onblur={e => validation.blur(e.currentTarget)}
@@ -220,7 +250,9 @@
220
250
  onclick={togglePassword}
221
251
  tabindex={-1}
222
252
  {disabled}
223
- ariaLabel={showPassword ? uiM('password_hide') : uiM('password_show')}
253
+ ariaLabel={showPassword
254
+ ? uiM('password_hide')
255
+ : uiM('password_show')}
224
256
  >
225
257
  <span class={cn(
226
258
  showPassword ? 'icon-[tabler--eye-off]' : 'icon-[tabler--eye]',
@@ -236,7 +268,13 @@
236
268
  value={strength.score}
237
269
  max={4}
238
270
  size='xs'
239
- variant={strength.score <= 1 ? 'error' : strength.score <= 2 ? 'warning' : strength.score <= 3 ? 'success' : 'primary'}
271
+ variant={strength.score <= 1
272
+ ? 'error'
273
+ : strength.score <= 2
274
+ ? 'warning'
275
+ : strength.score <= 3
276
+ ? 'success'
277
+ : 'primary'}
240
278
  />
241
279
  <span class='text-xs text-base-content/40 mt-1 block'>
242
280
  {uiM('password_strength_label')} {strength.label}
@@ -61,7 +61,9 @@
61
61
  let confirmPassword = $state('')
62
62
  let nickname = $state('')
63
63
 
64
- const policyError = $derived(passwordPolicy && password ? passwordPolicyError(password, passwordPolicy) : '')
64
+ const policyError = $derived(passwordPolicy && password
65
+ ? passwordPolicyError(password, passwordPolicy)
66
+ : '')
65
67
 
66
68
  const formClass = $derived(
67
69
  cn(
@@ -123,7 +125,9 @@
123
125
 
124
126
  function getSubmittedValue(formData: FormData, key: string, fallback = ''): string | undefined {
125
127
  const submitted = formData.get(key)
126
- const value = typeof submitted === 'string' ? submitted : fallback
128
+ const value = typeof submitted === 'string'
129
+ ? submitted
130
+ : fallback
127
131
  const trimmed = value.trim()
128
132
  return trimmed || undefined
129
133
  }
@@ -241,7 +245,11 @@
241
245
  oninput={(e: Event & { currentTarget: HTMLInputElement }) => setFieldValue(field, e.currentTarget.value)}
242
246
  {disabled}
243
247
  required={field === 'username' || field === 'email'}
244
- autocomplete={field === 'username' ? 'username' : field === 'email' ? 'email' : undefined}
248
+ autocomplete={field === 'username'
249
+ ? 'username'
250
+ : field === 'email'
251
+ ? 'email'
252
+ : undefined}
245
253
  error={errors[field]}
246
254
  />
247
255
  </FormField>
@@ -51,7 +51,9 @@
51
51
  let newPassword = $state('')
52
52
  let confirmPassword = $state('')
53
53
 
54
- const policyError = $derived(passwordPolicy && newPassword ? passwordPolicyError(newPassword, passwordPolicy) : '')
54
+ const policyError = $derived(passwordPolicy && newPassword
55
+ ? passwordPolicyError(newPassword, passwordPolicy)
56
+ : '')
55
57
 
56
58
  const formClass = $derived(
57
59
  cn(
@@ -136,7 +138,9 @@
136
138
  bind:value={confirmPassword}
137
139
  placeholder={uiM('reset_password_confirm_placeholder')}
138
140
  {disabled}
139
- error={errors.confirmPassword || (!passwordsMatch && confirmPassword ? uiM('reset_password_mismatch') : '')}
141
+ error={errors.confirmPassword || (!passwordsMatch && confirmPassword
142
+ ? uiM('reset_password_mismatch')
143
+ : '')}
140
144
  showStrength={false}
141
145
  />
142
146
  </FormField>
@@ -38,7 +38,9 @@
38
38
  event.preventDefault()
39
39
  if (loading)
40
40
  return
41
- const items = [...new Set(value.split(/\r?\n/).map(item => item.trim()).filter(Boolean))]
41
+ const items = [
42
+ ...new Set(value.split(/\r?\n/).map(item => item.trim()).filter(Boolean)),
43
+ ]
42
44
  fieldError = ''
43
45
  if (items.length > 1000 || items.some(item => item.length > 128)) {
44
46
  fieldError = uiM('sensitive_operations_invalid')
@@ -56,7 +56,10 @@
56
56
  <p class='mb-4 text-sm text-base-content/60'>{uiM('session_recovery_hint')}</p>
57
57
  {#if recovery.user?.username}<p class='mb-4 text-sm font-medium'>{recovery.user.username}</p>{/if}
58
58
  {#if recovery.config}
59
- <AuthPanel embedded initialIdentifier={recovery.user?.username} config={{ ...recovery.config, register: { enabled: false } }} actions={recoveryActions} onauthenticated={() => recovery.complete(authenticatedId, authenticatedVersion)} />
59
+ <AuthPanel embedded initialIdentifier={recovery.user?.username} config={{
60
+ ...recovery.config,
61
+ register: { enabled: false },
62
+ }} actions={recoveryActions} onauthenticated={() => recovery.complete(authenticatedId, authenticatedVersion)} />
60
63
  {/if}
61
64
  <div class='mt-4 flex justify-end'><Button variant='ghost' disabled={authenticating} onclick={() => recovery.cancel()}>{uiM('session_recovery_later')}</Button></div>
62
65
  </div>
@@ -22,8 +22,9 @@
22
22
  <script lang='ts'>
23
23
  import type { DataAttributes } from '../../../types.js'
24
24
  import type { UserProfileField, UserProfileProps, UserProfileSubmitData } from '../types.js'
25
+ import { tick } from 'svelte'
25
26
  import { uiM } from '../../../messages.js'
26
- import { useToastFeedback } from '../../../toast.svelte.js'
27
+ import { toast, useToastFeedback } from '../../../toast.svelte.js'
27
28
  import { cn, getDataAttributes } from '../../../utils.js'
28
29
  import FormField from '../../compounds/FormField.svelte'
29
30
  import FormLayout from '../../compounds/FormLayout.svelte'
@@ -41,7 +42,13 @@
41
42
  columns = 1,
42
43
  labelPosition = 'top',
43
44
  labelWidth = '8rem',
44
- fields = ['avatar', 'username', 'email', 'displayName', 'phone'],
45
+ fields = [
46
+ 'avatar',
47
+ 'username',
48
+ 'email',
49
+ 'displayName',
50
+ 'phone',
51
+ ],
45
52
  fieldConstraints = {},
46
53
  avatarAccept = 'image/*',
47
54
  avatarHint,
@@ -55,6 +62,8 @@
55
62
  const dataAttributes = $derived(getDataAttributes(restProps))
56
63
  const avatarInputId = $props.id()
57
64
  let editMode = $state(false)
65
+ let submitting = $state(false)
66
+ const busy = $derived(loading || submitting)
58
67
  let formData = $state<UserProfileSubmitData>({
59
68
  username: '',
60
69
  email: '',
@@ -151,11 +160,23 @@
151
160
  */
152
161
  async function handleSubmit(e: SubmitEvent) {
153
162
  e.preventDefault()
154
- if (loading)
163
+ if (busy)
155
164
  return
156
165
 
157
- await onsubmit?.(formData)
158
- editMode = false
166
+ submitting = true
167
+ try {
168
+ const saved = await onsubmit?.(formData)
169
+ await tick()
170
+ if (saved === true)
171
+ editMode = false
172
+ }
173
+ catch {
174
+ // 回调抛错时保留草稿,统一用 Toast 提供可重试的失败说明。
175
+ toast.error(uiM('crud_submit_failed'))
176
+ }
177
+ finally {
178
+ submitting = false
179
+ }
159
180
  }
160
181
 
161
182
  /**
@@ -196,10 +217,10 @@
196
217
  type='file'
197
218
  class='hidden'
198
219
  accept={avatarAccept}
199
- disabled={loading}
220
+ disabled={busy}
200
221
  onchange={handleAvatarChange}
201
222
  />
202
- <Button type='button' variant='outline' size='sm' disabled={loading} onclick={() => document.getElementById(avatarInputId)?.click()}>{uiM('user_profile_upload_avatar')}</Button>
223
+ <Button type='button' variant='outline' size='sm' disabled={busy} onclick={() => document.getElementById(avatarInputId)?.click()}>{uiM('user_profile_upload_avatar')}</Button>
203
224
  {#if !errors.avatar}
204
225
  <p class='text-xs text-base-content/60 mt-1'>{avatarHint ?? uiM('user_profile_avatar_hint')}</p>
205
226
  {/if}
@@ -208,7 +229,9 @@
208
229
  </div>
209
230
  {:else}
210
231
  <!-- 其他字段 -->
211
- <FormField label={getFieldLabel(field)} required={fieldConstraints[field]?.required} colSpan={field === 'bio' ? 2 : 'auto'}>
232
+ <FormField label={getFieldLabel(field)} required={fieldConstraints[field]?.required} colSpan={field === 'bio'
233
+ ? 2
234
+ : 'auto'}>
212
235
  {#if editable && (editMode || alwaysEditable)}
213
236
  {#if field === 'bio'}
214
237
  <Textarea
@@ -216,16 +239,20 @@
216
239
  name={modelKey}
217
240
  rows={3}
218
241
  bind:value={formData[modelKey]}
219
- disabled={loading}
242
+ disabled={busy}
220
243
  error={errors[field]}
221
244
  />
222
245
  {:else}
223
246
  <Input
224
247
  {...fieldConstraints[field]}
225
- type={field === 'email' ? 'email' : field === 'phone' ? 'tel' : 'text'}
248
+ type={field === 'email'
249
+ ? 'email'
250
+ : field === 'phone'
251
+ ? 'tel'
252
+ : 'text'}
226
253
  name={modelKey}
227
254
  bind:value={formData[modelKey]}
228
- disabled={loading}
255
+ disabled={busy}
229
256
  error={errors[field]}
230
257
  />
231
258
  {/if}
@@ -247,8 +274,8 @@
247
274
  <Button
248
275
  type='submit'
249
276
  variant='primary'
250
- {loading}
251
- disabled={loading}
277
+ loading={busy}
278
+ disabled={busy}
252
279
  >
253
280
  {uiM('user_profile_save')}
254
281
  </Button>
@@ -256,7 +283,7 @@
256
283
  type='button'
257
284
  variant='ghost'
258
285
  onclick={cancelEdit}
259
- disabled={loading}
286
+ disabled={busy}
260
287
  >
261
288
  {uiM('user_profile_cancel')}
262
289
  </Button>
@@ -17,7 +17,14 @@ export async function solveAuthCaptcha(input, controller) {
17
17
  controller.signal.throwIfAborted();
18
18
  const { solveChallenge, pbkdf2 } = await import('altcha/lib');
19
19
  controller.signal.throwIfAborted();
20
- const solution = await solveChallenge({ challenge: input.challenge, deriveKey: pbkdf2.deriveKey, controller, timeout: 20000 });
20
+ const solution = await solveChallenge({
21
+ challenge: input.challenge,
22
+ deriveKey: pbkdf2.deriveKey,
23
+ controller,
24
+ timeout: 20000,
25
+ });
21
26
  controller.signal.throwIfAborted();
22
- return solution ? JSON.stringify({ id: input.id, solution }) : null;
27
+ return solution
28
+ ? JSON.stringify({ id: input.id, solution })
29
+ : null;
23
30
  }
@@ -63,8 +63,16 @@ export function authErrorMessage(error) {
63
63
  const { cause } = error;
64
64
  if (error.httpStatus === 400 && (error.code === 'hai:crypto:071' || error.code === 'hai:api-client:007')
65
65
  && cause && typeof cause === 'object' && 'transportCode' in cause && cause.transportCode === 'hai:crypto:071') {
66
- return core.error.formatMessage({ message: core.sanitize.sanitizeText(error.message), traceId: error.traceId });
66
+ return core.error.formatMessage({
67
+ message: core.sanitize.sanitizeText(error.message),
68
+ traceId: error.traceId,
69
+ });
67
70
  }
68
- const key = (error.httpStatus ?? 400) >= 500 || !Object.hasOwn(messages, error.code) ? 'auth_error_service' : messages[error.code] ?? 'auth_error_service';
69
- return core.error.formatMessage({ message: uiM(key), traceId: error.traceId });
71
+ const key = (error.httpStatus ?? 400) >= 500 || !Object.hasOwn(messages, error.code)
72
+ ? 'auth_error_service'
73
+ : messages[error.code] ?? 'auth_error_service';
74
+ return core.error.formatMessage({
75
+ message: uiM(key),
76
+ traceId: error.traceId,
77
+ });
70
78
  }
@@ -41,7 +41,12 @@ export function passwordPolicyError(password, policy) {
41
41
  return uiM('password_policy_number');
42
42
  if (policy.requireSpecialChar && !/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password))
43
43
  return uiM('password_policy_special');
44
- const classes = [/[A-Z]/, /[a-z]/, /\d/, /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/].filter(pattern => pattern.test(password)).length;
44
+ const classes = [
45
+ /[A-Z]/,
46
+ /[a-z]/,
47
+ /\d/,
48
+ /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/,
49
+ ].filter(pattern => pattern.test(password)).length;
45
50
  if (classes < (policy.minCharacterClasses ?? 0))
46
51
  return uiM('password_policy_classes', { count: policy.minCharacterClasses ?? 0 });
47
52
  return '';
@@ -57,7 +62,9 @@ export function passwordPolicyError(password, policy) {
57
62
  * ```
58
63
  */
59
64
  export function passwordPolicyHint(policy) {
60
- const requirements = [uiM('password_policy_length', { min: policy.minLength, max: policy.maxLength })];
65
+ const requirements = [
66
+ uiM('password_policy_length', { min: policy.minLength, max: policy.maxLength }),
67
+ ];
61
68
  if (policy.requireUppercase)
62
69
  requirements.push(uiM('password_policy_uppercase'));
63
70
  if (policy.requireLowercase)
@@ -27,7 +27,10 @@ export function createSensitiveActions(options) {
27
27
  generation = 0;
28
28
  resolve;
29
29
  configure(policy) {
30
- this.policy = { enabled: policy.enabled, operations: [...policy.operations] };
30
+ this.policy = {
31
+ enabled: policy.enabled,
32
+ operations: [...policy.operations],
33
+ };
31
34
  // configure 通常从宿主 $effect 调用;不要把弹窗状态变成该 effect 的依赖。
32
35
  untrack(() => {
33
36
  if (this.open && (!policy.enabled || !policy.operations.includes(this.operation)))