@h-ai/ui 0.1.0-alpha.73 → 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.
- package/README.en.md +70 -7
- package/README.ja.md +71 -8
- package/README.md +72 -9
- package/auto-import.d.ts +4 -0
- package/auto-import.js +4 -0
- package/dist/components/compounds/Confirm.svelte +12 -2
- package/dist/components/compounds/Drawer.svelte +32 -14
- package/dist/components/compounds/FilterBar.svelte +77 -0
- package/dist/components/compounds/FilterBar.svelte.d.ts +39 -0
- package/dist/components/compounds/Modal.svelte +4 -37
- package/dist/components/compounds/PageHeader.svelte +18 -11
- package/dist/components/compounds/TableToolbar.svelte +1 -1
- package/dist/components/compounds/index.d.ts +1 -0
- package/dist/components/compounds/index.js +1 -0
- package/dist/components/primitives/Button.svelte +7 -0
- package/dist/components/primitives/Input.svelte +1 -1
- package/dist/components/primitives/Textarea.svelte +1 -1
- package/dist/components/scenes/app/FeedbackDetail.svelte +13 -3
- package/dist/components/scenes/app/FeedbackDetail.svelte.d.ts +6 -0
- package/dist/components/scenes/app/FeedbackForm.svelte +1 -1
- package/dist/components/scenes/app/FeedbackList.svelte +4 -4
- package/dist/components/scenes/app/SettingsLayout.svelte +4 -15
- package/dist/components/scenes/app/ThemeSelector.svelte +56 -16
- package/dist/components/scenes/app/WorkspaceLayout.svelte +64 -0
- package/dist/components/scenes/app/WorkspaceLayout.svelte.d.ts +36 -0
- package/dist/components/scenes/app/feedback-functions.d.ts +16 -0
- package/dist/components/scenes/app/feedback-functions.js +31 -0
- package/dist/components/scenes/app/index.d.ts +1 -0
- package/dist/components/scenes/app/index.js +1 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte +18 -9
- package/dist/components/scenes/crud/CrudFilterBar.svelte +39 -30
- package/dist/components/scenes/crud/CrudFilterBar.svelte.d.ts +4 -1
- package/dist/components/scenes/crud/CrudPage.svelte +27 -7
- package/dist/components/scenes/crud/CrudPage.svelte.d.ts +1 -1
- package/dist/components/scenes/crud/crud-types.d.ts +1 -1
- package/dist/components/scenes/guide/GuideHost.svelte +22 -102
- package/dist/components/scenes/guide/GuideHost.svelte.d.ts +5 -13
- package/dist/components/scenes/guide/GuideHostContent.svelte +143 -0
- package/dist/components/scenes/guide/GuideHostContent.svelte.d.ts +43 -0
- package/dist/components/scenes/guide/HelpCenter.svelte +22 -9
- package/dist/components/scenes/iam/AuthPanel.svelte +7 -7
- package/dist/components/scenes/iam/AuthShell.svelte +6 -1
- package/dist/components/scenes/iam/AuthShell.svelte.d.ts +2 -0
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +1 -1
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +1 -1
- package/dist/components/scenes/iam/LoginForm.svelte +29 -3
- package/dist/components/scenes/iam/PasswordInput.svelte +1 -1
- package/dist/components/scenes/iam/RegisterForm.svelte +1 -1
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +70 -0
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte.d.ts +21 -0
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +64 -0
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte.d.ts +22 -0
- package/dist/components/scenes/iam/index.d.ts +6 -0
- package/dist/components/scenes/iam/index.js +4 -0
- package/dist/components/scenes/iam/sensitive-actions.svelte.d.ts +68 -0
- package/dist/components/scenes/iam/sensitive-actions.svelte.js +100 -0
- package/dist/components/scenes/iam/session-recovery.svelte.d.ts +44 -0
- package/dist/components/scenes/iam/session-recovery.svelte.js +57 -0
- package/dist/components/scenes/types.d.ts +9 -0
- package/dist/guide.svelte.js +61 -26
- package/dist/internal/dialog-focus.d.ts +21 -0
- package/dist/internal/dialog-focus.js +77 -0
- package/dist/internal/form-validation.svelte.d.ts +2 -1
- package/dist/internal/form-validation.svelte.js +9 -1
- package/dist/messages/en-US.json +21 -4
- package/dist/messages/ja-JP.json +21 -4
- package/dist/messages/zh-CN.json +21 -4
- package/dist/styles/formal.css +55 -0
- package/dist/styles/high-contrast.css +64 -0
- package/dist/styles/theme.css +2 -0
- package/dist/theme-config.d.ts +2 -2
- package/dist/theme-config.js +5 -2
- package/dist/types.d.ts +4 -0
- package/dist/workspace-context.d.ts +20 -0
- package/dist/workspace-context.js +9 -0
- package/package.json +2 -2
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
<Button
|
|
151
151
|
type='submit'
|
|
152
152
|
variant='primary'
|
|
153
|
-
class='w-full sm:w-auto sm:min-w-40'
|
|
153
|
+
class='disabled:text-base-content/70 w-full sm:w-auto sm:min-w-40'
|
|
154
154
|
disabled={loading || disabled || !canSubmit || Boolean(policyError)}
|
|
155
155
|
{loading}
|
|
156
156
|
>
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import type { HaiError } from '@h-ai/core'
|
|
17
17
|
import type { DataAttributes } from '../../../types.js'
|
|
18
18
|
import type { AuthLoginMethod, LoginFormData, LoginFormProps } from '../types.js'
|
|
19
|
+
import { untrack } from 'svelte'
|
|
19
20
|
import { uiM } from '../../../messages.js'
|
|
20
21
|
import { cn, getDataAttributes } from '../../../utils.js'
|
|
21
22
|
import Alert from '../../compounds/Alert.svelte'
|
|
@@ -30,6 +31,8 @@
|
|
|
30
31
|
|
|
31
32
|
const {
|
|
32
33
|
methods = ['password'],
|
|
34
|
+
autoFocus = true,
|
|
35
|
+
initialIdentifier = '',
|
|
33
36
|
otpLength = 6,
|
|
34
37
|
resendInterval = 60,
|
|
35
38
|
onsendotp,
|
|
@@ -56,12 +59,33 @@
|
|
|
56
59
|
}: LoginFormProps & DataAttributes = $props()
|
|
57
60
|
|
|
58
61
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
62
|
+
let formElement = $state<HTMLFormElement>()
|
|
63
|
+
let focusedInitially = false
|
|
59
64
|
|
|
60
|
-
let username = $state(
|
|
65
|
+
let username = $state(untrack(() => initialIdentifier))
|
|
61
66
|
let password = $state('')
|
|
62
67
|
let selectedMethod = $state<AuthLoginMethod>('password')
|
|
63
68
|
const method = $derived(methods.includes(selectedMethod) ? selectedMethod : methods[0])
|
|
64
69
|
const isOtp = $derived(method === 'email' || method === 'sms')
|
|
70
|
+
$effect(() => {
|
|
71
|
+
if (!autoFocus || focusedInitially || disabled || loading || !method || !formElement)
|
|
72
|
+
return
|
|
73
|
+
const input = formElement.querySelector<HTMLInputElement>('input[autocomplete="username"]')
|
|
74
|
+
if (!input?.getClientRects().length)
|
|
75
|
+
return
|
|
76
|
+
if (globalThis.matchMedia?.('(pointer: coarse)').matches) {
|
|
77
|
+
focusedInitially = true
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
input.autofocus = true
|
|
81
|
+
// 首帧布局和宿主导航完成后设置默认焦点;尊重用户已经选择的其它控件。
|
|
82
|
+
const frame = requestAnimationFrame(() => {
|
|
83
|
+
focusedInitially = true
|
|
84
|
+
if (document.activeElement === document.body || document.activeElement === document.documentElement)
|
|
85
|
+
input.focus()
|
|
86
|
+
})
|
|
87
|
+
return () => cancelAnimationFrame(frame)
|
|
88
|
+
})
|
|
65
89
|
let code = $state('')
|
|
66
90
|
let sending = $state(false)
|
|
67
91
|
let sendFailure = $state<Pick<HaiError, 'code' | 'message'> | 'network'>()
|
|
@@ -137,7 +161,7 @@
|
|
|
137
161
|
}
|
|
138
162
|
</script>
|
|
139
163
|
|
|
140
|
-
<form {...dataAttributes} class={formClass} onsubmit={handleSubmit}>
|
|
164
|
+
<form {...dataAttributes} bind:this={formElement} class={formClass} onsubmit={handleSubmit}>
|
|
141
165
|
<FormLayout {columns} {labelPosition} {labelWidth}>
|
|
142
166
|
<!-- 标题 -->
|
|
143
167
|
{#if showTitle}
|
|
@@ -166,6 +190,7 @@
|
|
|
166
190
|
{/each}
|
|
167
191
|
</div>
|
|
168
192
|
{/if}
|
|
193
|
+
{#if method === 'ldap'}<p class='text-sm text-base-content/70'>{uiM('login_method_ldap_hint')}</p>{/if}
|
|
169
194
|
{#if !method}
|
|
170
195
|
<Alert variant='warning'>{uiM('auth_unavailable')}</Alert>
|
|
171
196
|
{:else}
|
|
@@ -242,10 +267,11 @@
|
|
|
242
267
|
<!-- 提交按钮 -->
|
|
243
268
|
<Button
|
|
244
269
|
type='submit'
|
|
270
|
+
submitHint
|
|
245
271
|
variant='primary'
|
|
246
272
|
{loading}
|
|
247
273
|
disabled={loading || disabled || !method}
|
|
248
|
-
class='w-full'
|
|
274
|
+
class='disabled:text-base-content/70 w-full'
|
|
249
275
|
>
|
|
250
276
|
{submitText || uiM('login_submit')}
|
|
251
277
|
</Button>
|
|
@@ -201,7 +201,7 @@
|
|
|
201
201
|
ariaDescribedby={[field?.messageId, localError && !field?.error ? messageId : ''].filter(Boolean).join(' ') || undefined}
|
|
202
202
|
oninput={handleInput}
|
|
203
203
|
onchange={handleChange}
|
|
204
|
-
onblur={e => validation.
|
|
204
|
+
onblur={e => validation.blur(e.currentTarget)}
|
|
205
205
|
oninvalid={(e) => {
|
|
206
206
|
validation.validate(e.currentTarget)
|
|
207
207
|
oninvalid?.(e)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component 编辑权限关联的敏感操作 ID;只处理表单,持久化和授权由宿主负责。
|
|
3
|
+
@example
|
|
4
|
+
```ts
|
|
5
|
+
import { mount, unmount } from 'svelte'
|
|
6
|
+
import { ok } from '@h-ai/core'
|
|
7
|
+
import { SensitiveOperationsForm } from '@h-ai/ui'
|
|
8
|
+
const component = mount(SensitiveOperationsForm, { target: document.body, props: { operations: ['orders.approve'], onsubmit: async () => ok(undefined) } })
|
|
9
|
+
await unmount(component)
|
|
10
|
+
```
|
|
11
|
+
-->
|
|
12
|
+
<script lang='ts'>
|
|
13
|
+
import type { HaiResult } from '@h-ai/core'
|
|
14
|
+
import type { DataAttributes } from '../../../types.js'
|
|
15
|
+
import { onDestroy, untrack } from 'svelte'
|
|
16
|
+
import { uiM } from '../../../messages.js'
|
|
17
|
+
import { getDataAttributes } from '../../../utils.js'
|
|
18
|
+
import Button from '../../primitives/Button.svelte'
|
|
19
|
+
import Textarea from '../../primitives/Textarea.svelte'
|
|
20
|
+
|
|
21
|
+
const { operations, onsubmit, ondone, ...restProps }: {
|
|
22
|
+
operations: readonly string[]
|
|
23
|
+
onsubmit: (operations: string[]) => Promise<HaiResult<unknown>>
|
|
24
|
+
ondone?: () => void
|
|
25
|
+
} & DataAttributes = $props()
|
|
26
|
+
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
27
|
+
let value = $state(untrack(() => operations.join('\n')))
|
|
28
|
+
let loading = $state(false)
|
|
29
|
+
let error = $state('')
|
|
30
|
+
let disposed = false
|
|
31
|
+
onDestroy(() => {
|
|
32
|
+
disposed = true
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
async function save(event: SubmitEvent): Promise<void> {
|
|
36
|
+
event.preventDefault()
|
|
37
|
+
if (loading)
|
|
38
|
+
return
|
|
39
|
+
const items = [...new Set(value.split(/\r?\n/).map(item => item.trim()).filter(Boolean))]
|
|
40
|
+
if (items.length > 1000 || items.some(item => item.length > 128)) {
|
|
41
|
+
error = uiM('sensitive_operations_invalid')
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
loading = true
|
|
45
|
+
error = ''
|
|
46
|
+
try {
|
|
47
|
+
const result = await onsubmit(items)
|
|
48
|
+
if (!result.success)
|
|
49
|
+
error = result.error.message
|
|
50
|
+
else if (!disposed)
|
|
51
|
+
ondone?.()
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
error = uiM('auth_network_error')
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
loading = false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<form data-testid='sensitive-operations-form' {...dataAttributes} class='space-y-4' onsubmit={save}>
|
|
63
|
+
<label class='block space-y-2 text-sm font-medium'>
|
|
64
|
+
<span>{uiM('sensitive_operations_label')}</span>
|
|
65
|
+
<Textarea bind:value rows={6} disabled={loading} aria-label={uiM('sensitive_operations_label')} />
|
|
66
|
+
</label>
|
|
67
|
+
<p class='text-sm text-base-content/60'>{uiM('sensitive_operations_hint')}</p>
|
|
68
|
+
{#if error}<p role='alert' class='text-sm text-error'>{error}</p>{/if}
|
|
69
|
+
<div class='flex justify-end'><Button type='submit' variant='primary' {loading}>{uiM('crud_save')}</Button></div>
|
|
70
|
+
</form>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HaiResult } from '@h-ai/core';
|
|
2
|
+
import type { DataAttributes } from '../../../types.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
operations: readonly string[];
|
|
5
|
+
onsubmit: (operations: string[]) => Promise<HaiResult<unknown>>;
|
|
6
|
+
ondone?: () => void;
|
|
7
|
+
} & DataAttributes;
|
|
8
|
+
/**
|
|
9
|
+
* 编辑权限关联的敏感操作 ID;只处理表单,持久化和授权由宿主负责。
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { mount, unmount } from 'svelte'
|
|
13
|
+
* import { ok } from '@h-ai/core'
|
|
14
|
+
* import { SensitiveOperationsForm } from '@h-ai/ui'
|
|
15
|
+
* const component = mount(SensitiveOperationsForm, { target: document.body, props: { operations: ['orders.approve'], onsubmit: async () => ok(undefined) } })
|
|
16
|
+
* await unmount(component)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const SensitiveOperationsForm: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
20
|
+
type SensitiveOperationsForm = ReturnType<typeof SensitiveOperationsForm>;
|
|
21
|
+
export default SensitiveOperationsForm;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component SessionRecoveryDialog 原地恢复已失效会话,复用正常认证、验证码、锁定与改密流程。
|
|
3
|
+
@example
|
|
4
|
+
```ts
|
|
5
|
+
import { mount, unmount } from 'svelte'
|
|
6
|
+
import { createSessionRecovery, SessionRecoveryDialog } from '@h-ai/ui'
|
|
7
|
+
import { kit } from '@h-ai/kit'
|
|
8
|
+
const recovery = createSessionRecovery()
|
|
9
|
+
const component = mount(SessionRecoveryDialog, { target: document.body, props: { recovery, actions: kit.client.createAuthActions() } })
|
|
10
|
+
await unmount(component)
|
|
11
|
+
```
|
|
12
|
+
-->
|
|
13
|
+
<script lang='ts'>
|
|
14
|
+
import type { DataAttributes } from '../../../types.js'
|
|
15
|
+
import type { AuthPanelActions } from '../types.js'
|
|
16
|
+
import type { SessionRecovery } from './session-recovery.svelte.js'
|
|
17
|
+
import { err, HaiCommonError } from '@h-ai/core'
|
|
18
|
+
import { uiM } from '../../../messages.js'
|
|
19
|
+
import { getDataAttributes } from '../../../utils.js'
|
|
20
|
+
import Modal from '../../compounds/Modal.svelte'
|
|
21
|
+
import Button from '../../primitives/Button.svelte'
|
|
22
|
+
import AuthPanel from './AuthPanel.svelte'
|
|
23
|
+
|
|
24
|
+
const { recovery, actions, ...restProps }: { recovery: SessionRecovery, actions: AuthPanelActions } & DataAttributes = $props()
|
|
25
|
+
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
26
|
+
let authenticating = $state(false)
|
|
27
|
+
let authenticatedId = ''
|
|
28
|
+
let authenticatedVersion = 0
|
|
29
|
+
const recoveryActions = $derived({
|
|
30
|
+
...actions,
|
|
31
|
+
login: async (input: Parameters<AuthPanelActions['login']>[0]) => {
|
|
32
|
+
const expectedUserId = recovery.user?.id
|
|
33
|
+
const version = recovery.version
|
|
34
|
+
if (!expectedUserId || !recovery.open)
|
|
35
|
+
return err(HaiCommonError.UNAUTHORIZED, uiM('session_recovery_account_error'))
|
|
36
|
+
authenticating = true
|
|
37
|
+
try {
|
|
38
|
+
const result = await actions.login({ ...input, expectedUserId })
|
|
39
|
+
if (result.success) {
|
|
40
|
+
const data = result.data
|
|
41
|
+
if (!data || typeof data !== 'object' || !('user' in data) || !data.user || typeof data.user !== 'object' || !('id' in data.user) || data.user.id !== expectedUserId)
|
|
42
|
+
return err(HaiCommonError.UNAUTHORIZED, uiM('session_recovery_account_error'))
|
|
43
|
+
authenticatedId = expectedUserId
|
|
44
|
+
authenticatedVersion = version
|
|
45
|
+
}
|
|
46
|
+
return result
|
|
47
|
+
}
|
|
48
|
+
finally { authenticating = false }
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<Modal {...dataAttributes} open={recovery.open} title={uiM('session_recovery_title')} onclose={() => recovery.cancel()} closeOnBackdrop={!authenticating} closeOnEscape={!authenticating} showClose={!authenticating} size='md'>
|
|
54
|
+
{#if recovery.open}
|
|
55
|
+
<div data-testid='session-recovery-dialog'>
|
|
56
|
+
<p class='mb-4 text-sm text-base-content/60'>{uiM('session_recovery_hint')}</p>
|
|
57
|
+
{#if recovery.user?.username}<p class='mb-4 text-sm font-medium'>{recovery.user.username}</p>{/if}
|
|
58
|
+
{#if recovery.config}
|
|
59
|
+
<AuthPanel embedded initialIdentifier={recovery.user?.username} config={{ ...recovery.config, register: { enabled: false } }} actions={recoveryActions} onauthenticated={() => recovery.complete(authenticatedId, authenticatedVersion)} />
|
|
60
|
+
{/if}
|
|
61
|
+
<div class='mt-4 flex justify-end'><Button variant='ghost' disabled={authenticating} onclick={() => recovery.cancel()}>{uiM('session_recovery_later')}</Button></div>
|
|
62
|
+
</div>
|
|
63
|
+
{/if}
|
|
64
|
+
</Modal>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DataAttributes } from '../../../types.js';
|
|
2
|
+
import type { AuthPanelActions } from '../types.js';
|
|
3
|
+
import type { SessionRecovery } from './session-recovery.svelte.js';
|
|
4
|
+
type $$ComponentProps = {
|
|
5
|
+
recovery: SessionRecovery;
|
|
6
|
+
actions: AuthPanelActions;
|
|
7
|
+
} & DataAttributes;
|
|
8
|
+
/**
|
|
9
|
+
* SessionRecoveryDialog 原地恢复已失效会话,复用正常认证、验证码、锁定与改密流程。
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { mount, unmount } from 'svelte'
|
|
13
|
+
* import { createSessionRecovery, SessionRecoveryDialog } from '@h-ai/ui'
|
|
14
|
+
* import { kit } from '@h-ai/kit'
|
|
15
|
+
* const recovery = createSessionRecovery()
|
|
16
|
+
* const component = mount(SessionRecoveryDialog, { target: document.body, props: { recovery, actions: kit.client.createAuthActions() } })
|
|
17
|
+
* await unmount(component)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare const SessionRecoveryDialog: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
21
|
+
type SessionRecoveryDialog = ReturnType<typeof SessionRecoveryDialog>;
|
|
22
|
+
export default SessionRecoveryDialog;
|
|
@@ -16,4 +16,10 @@ export type { PermissionContext } from './permission-context.svelte.js';
|
|
|
16
16
|
export { default as ReauthenticationDialog } from './ReauthenticationDialog.svelte';
|
|
17
17
|
export { default as RegisterForm } from './RegisterForm.svelte';
|
|
18
18
|
export { default as ResetPasswordForm } from './ResetPasswordForm.svelte';
|
|
19
|
+
export { createSensitiveActions } from './sensitive-actions.svelte.js';
|
|
20
|
+
export type { SensitiveActions, SensitiveActionsOptions } from './sensitive-actions.svelte.js';
|
|
21
|
+
export { default as SensitiveOperationsForm } from './SensitiveOperationsForm.svelte';
|
|
22
|
+
export { createSessionRecovery } from './session-recovery.svelte.js';
|
|
23
|
+
export type { SessionRecovery } from './session-recovery.svelte.js';
|
|
24
|
+
export { default as SessionRecoveryDialog } from './SessionRecoveryDialog.svelte';
|
|
19
25
|
export { default as UserProfile } from './UserProfile.svelte';
|
|
@@ -17,5 +17,9 @@ export { matchPermission, setPermissionContext, usePermission, } from './permiss
|
|
|
17
17
|
export { default as ReauthenticationDialog } from './ReauthenticationDialog.svelte';
|
|
18
18
|
export { default as RegisterForm } from './RegisterForm.svelte';
|
|
19
19
|
export { default as ResetPasswordForm } from './ResetPasswordForm.svelte';
|
|
20
|
+
export { createSensitiveActions } from './sensitive-actions.svelte.js';
|
|
21
|
+
export { default as SensitiveOperationsForm } from './SensitiveOperationsForm.svelte';
|
|
22
|
+
export { createSessionRecovery } from './session-recovery.svelte.js';
|
|
23
|
+
export { default as SessionRecoveryDialog } from './SessionRecoveryDialog.svelte';
|
|
20
24
|
// 用户信息
|
|
21
25
|
export { default as UserProfile } from './UserProfile.svelte';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** 敏感操作密码确认的页面级状态;网络传输及业务动作仍由宿主提供。 */
|
|
2
|
+
import type { HaiResult } from '@h-ai/core';
|
|
3
|
+
/**
|
|
4
|
+
* 二次认证动作;直接接受 Kit/API client 的 createAuthActions() 返回值。
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { SensitiveActionsOptions } from '@h-ai/ui'
|
|
8
|
+
* import { kit } from '@h-ai/kit'
|
|
9
|
+
* const options: SensitiveActionsOptions = kit.client.createAuthActions()
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface SensitiveActionsOptions {
|
|
13
|
+
/** 验证当前账号密码,取得仅供指定操作使用的短期单次凭据。 */
|
|
14
|
+
reauthenticate: (password: string, operation: string) => Promise<HaiResult<{
|
|
15
|
+
ticket: string;
|
|
16
|
+
}>>;
|
|
17
|
+
/** 标准动作可提供实时公开策略,权限表变更无需等待重新加载页面。 */
|
|
18
|
+
publicConfig?: () => Promise<HaiResult<{
|
|
19
|
+
reauthentication?: {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
operations: string[];
|
|
22
|
+
};
|
|
23
|
+
} | null>>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 绑定 ReauthenticationDialog 的状态与动作;每个应用根布局创建一份。
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { createSensitiveActions } from '@h-ai/ui'
|
|
30
|
+
* import { kit } from '@h-ai/kit'
|
|
31
|
+
* const confirmation = createSensitiveActions(kit.client.createAuthActions())
|
|
32
|
+
* confirmation.configure({ enabled: true, operations: ['orders.approve'] })
|
|
33
|
+
* confirmation.cancel()
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface SensitiveActions {
|
|
37
|
+
readonly open: boolean;
|
|
38
|
+
readonly loading: boolean;
|
|
39
|
+
readonly error: string;
|
|
40
|
+
/** 设置服务端公开策略;撤销当前操作时取消待确认动作。 */
|
|
41
|
+
configure: (policy: {
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
operations: readonly string[];
|
|
44
|
+
}) => void;
|
|
45
|
+
/** undefined 表示无需确认,null 表示取消/忙,字符串为本次操作证明。 */
|
|
46
|
+
authorize: (operation: string) => Promise<string | null | undefined>;
|
|
47
|
+
/** 提交当前密码;错误在弹窗内显示,重复点击不会重复请求。 */
|
|
48
|
+
submit: (password: string) => Promise<void>;
|
|
49
|
+
/** 关闭弹窗或布局卸载时调用;迟到响应不能放行其他动作。 */
|
|
50
|
+
cancel: () => void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 创建可跨业务复用的敏感动作确认状态,与 ReauthenticationDialog 配套。
|
|
54
|
+
* 密码不写入状态或存储;证明仅返回给 authorize 的对应调用者,不设置全局请求头。
|
|
55
|
+
* @param options - Kit/API client 的标准认证动作,或同签名自定义动作。
|
|
56
|
+
* @returns 页面级确认控制器;业务授权和凭据消费始终由服务端执行。
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { createSensitiveActions } from '@h-ai/ui'
|
|
60
|
+
* import { kit } from '@h-ai/kit'
|
|
61
|
+
* const confirmation = createSensitiveActions(kit.client.createAuthActions())
|
|
62
|
+
* confirmation.configure({ enabled: false, operations: [] })
|
|
63
|
+
* const ticket = await confirmation.authorize('orders.approve')
|
|
64
|
+
* // null 时中止;有 ticket 时仅传给这一笔请求。
|
|
65
|
+
* void ticket
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function createSensitiveActions(options: SensitiveActionsOptions): SensitiveActions;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { untrack } from 'svelte';
|
|
2
|
+
import { uiM } from '../../../messages.js';
|
|
3
|
+
/**
|
|
4
|
+
* 创建可跨业务复用的敏感动作确认状态,与 ReauthenticationDialog 配套。
|
|
5
|
+
* 密码不写入状态或存储;证明仅返回给 authorize 的对应调用者,不设置全局请求头。
|
|
6
|
+
* @param options - Kit/API client 的标准认证动作,或同签名自定义动作。
|
|
7
|
+
* @returns 页面级确认控制器;业务授权和凭据消费始终由服务端执行。
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createSensitiveActions } from '@h-ai/ui'
|
|
11
|
+
* import { kit } from '@h-ai/kit'
|
|
12
|
+
* const confirmation = createSensitiveActions(kit.client.createAuthActions())
|
|
13
|
+
* confirmation.configure({ enabled: false, operations: [] })
|
|
14
|
+
* const ticket = await confirmation.authorize('orders.approve')
|
|
15
|
+
* // null 时中止;有 ticket 时仅传给这一笔请求。
|
|
16
|
+
* void ticket
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function createSensitiveActions(options) {
|
|
20
|
+
class Confirmation {
|
|
21
|
+
open = $state(false);
|
|
22
|
+
loading = $state(false);
|
|
23
|
+
error = $state('');
|
|
24
|
+
policy = { enabled: false, operations: [] };
|
|
25
|
+
operation = '';
|
|
26
|
+
generation = 0;
|
|
27
|
+
resolve;
|
|
28
|
+
configure(policy) {
|
|
29
|
+
this.policy = { enabled: policy.enabled, operations: [...policy.operations] };
|
|
30
|
+
// configure 通常从宿主 $effect 调用;不要把弹窗状态变成该 effect 的依赖。
|
|
31
|
+
untrack(() => {
|
|
32
|
+
if (this.open && (!policy.enabled || !policy.operations.includes(this.operation)))
|
|
33
|
+
this.cancel();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async authorize(operation) {
|
|
37
|
+
if (this.open)
|
|
38
|
+
return null;
|
|
39
|
+
if (this.policy.enabled && options.publicConfig) {
|
|
40
|
+
const current = await options.publicConfig();
|
|
41
|
+
if (!current.success || !current.data)
|
|
42
|
+
return null;
|
|
43
|
+
if (current.data.reauthentication)
|
|
44
|
+
this.configure(current.data.reauthentication);
|
|
45
|
+
}
|
|
46
|
+
if (!this.policy.enabled || !this.policy.operations.includes(operation))
|
|
47
|
+
return undefined;
|
|
48
|
+
if (this.open)
|
|
49
|
+
return null;
|
|
50
|
+
this.operation = operation;
|
|
51
|
+
this.generation++;
|
|
52
|
+
this.error = '';
|
|
53
|
+
this.open = true;
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
this.resolve = resolve;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async submit(password) {
|
|
59
|
+
if (!this.open || this.loading)
|
|
60
|
+
return;
|
|
61
|
+
this.loading = true;
|
|
62
|
+
this.error = '';
|
|
63
|
+
const operation = this.operation;
|
|
64
|
+
const generation = this.generation;
|
|
65
|
+
const pending = this.resolve;
|
|
66
|
+
try {
|
|
67
|
+
const proof = await options.reauthenticate(password, operation);
|
|
68
|
+
if (generation !== this.generation)
|
|
69
|
+
return;
|
|
70
|
+
if (!proof.success) {
|
|
71
|
+
this.error = proof.error.message;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.resolve = undefined;
|
|
75
|
+
this.operation = '';
|
|
76
|
+
this.open = false;
|
|
77
|
+
pending?.(proof.data.ticket);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
if (generation === this.generation)
|
|
81
|
+
this.error = uiM('auth_network_error');
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
if (generation === this.generation)
|
|
85
|
+
this.loading = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
cancel() {
|
|
89
|
+
this.generation++;
|
|
90
|
+
const resolve = this.resolve;
|
|
91
|
+
this.resolve = undefined;
|
|
92
|
+
this.operation = '';
|
|
93
|
+
this.open = false;
|
|
94
|
+
this.loading = false;
|
|
95
|
+
this.error = '';
|
|
96
|
+
resolve?.(null);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return new Confirmation();
|
|
100
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** 会话失效时保留页面,以正常登录流程恢复原主体;不保存密码、请求体或凭据。 */
|
|
2
|
+
import type { AuthPanelConfig } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* 页面级会话恢复控制器;同一时刻多个请求共享一次确认。
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createSessionRecovery, type SessionRecovery } from '@h-ai/ui'
|
|
8
|
+
* const recovery: SessionRecovery = createSessionRecovery()
|
|
9
|
+
* recovery.configure(null)
|
|
10
|
+
* const restored = await recovery.recover()
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface SessionRecovery {
|
|
14
|
+
readonly open: boolean;
|
|
15
|
+
readonly config: AuthPanelConfig | null;
|
|
16
|
+
readonly user: {
|
|
17
|
+
id: string;
|
|
18
|
+
username?: string;
|
|
19
|
+
} | undefined;
|
|
20
|
+
readonly version: number;
|
|
21
|
+
/** 在应用根布局同步公开配置及当前用户;退出/切换用户时取消原待恢复请求。 */
|
|
22
|
+
configure: (config: AuthPanelConfig | null, user?: {
|
|
23
|
+
id: string;
|
|
24
|
+
username?: string;
|
|
25
|
+
}) => void;
|
|
26
|
+
/** 传给Kit/API client的recoverSession;没有已登录主体时不弹窗。 */
|
|
27
|
+
recover: () => Promise<boolean>;
|
|
28
|
+
/** 仅在限定原userId的正常登录成功后调用。 */
|
|
29
|
+
complete: (userId: string, version: number) => void;
|
|
30
|
+
/** 取消只中止原请求的恢复,不自动清空页面草稿。 */
|
|
31
|
+
cancel: () => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 创建与SessionRecoveryDialog配套的页面级恢复控制器,不依赖具体业务路由。
|
|
35
|
+
* @returns 只保留公开配置、原主体及单个等待Promise的控制器。
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { createSessionRecovery } from '@h-ai/ui'
|
|
39
|
+
* const recovery = createSessionRecovery()
|
|
40
|
+
* // 布局以 configure(publicConfig, currentUser) 装配;销毁时 cancel()。
|
|
41
|
+
* recovery.cancel()
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createSessionRecovery(): SessionRecovery;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { untrack } from 'svelte';
|
|
2
|
+
/**
|
|
3
|
+
* 创建与SessionRecoveryDialog配套的页面级恢复控制器,不依赖具体业务路由。
|
|
4
|
+
* @returns 只保留公开配置、原主体及单个等待Promise的控制器。
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createSessionRecovery } from '@h-ai/ui'
|
|
8
|
+
* const recovery = createSessionRecovery()
|
|
9
|
+
* // 布局以 configure(publicConfig, currentUser) 装配;销毁时 cancel()。
|
|
10
|
+
* recovery.cancel()
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function createSessionRecovery() {
|
|
14
|
+
class Recovery {
|
|
15
|
+
open = $state(false);
|
|
16
|
+
config = $state(null);
|
|
17
|
+
user = $state();
|
|
18
|
+
pending;
|
|
19
|
+
resolve;
|
|
20
|
+
generation = 0;
|
|
21
|
+
get version() { return this.generation; }
|
|
22
|
+
configure(config, user) {
|
|
23
|
+
untrack(() => {
|
|
24
|
+
if (this.user?.id !== user?.id)
|
|
25
|
+
this.cancel();
|
|
26
|
+
});
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.user = user;
|
|
29
|
+
}
|
|
30
|
+
recover = async () => {
|
|
31
|
+
if (!this.user || !this.config)
|
|
32
|
+
return false;
|
|
33
|
+
if (this.pending)
|
|
34
|
+
return this.pending;
|
|
35
|
+
this.generation++;
|
|
36
|
+
this.open = true;
|
|
37
|
+
this.pending = new Promise((resolve) => {
|
|
38
|
+
this.resolve = resolve;
|
|
39
|
+
});
|
|
40
|
+
return this.pending;
|
|
41
|
+
};
|
|
42
|
+
complete(userId, version) {
|
|
43
|
+
if (this.open && userId === this.user?.id && version === this.generation)
|
|
44
|
+
this.finish(true);
|
|
45
|
+
}
|
|
46
|
+
cancel() { this.finish(false); }
|
|
47
|
+
finish(restored) {
|
|
48
|
+
this.generation++;
|
|
49
|
+
const resolve = this.resolve;
|
|
50
|
+
this.resolve = undefined;
|
|
51
|
+
this.pending = undefined;
|
|
52
|
+
this.open = false;
|
|
53
|
+
resolve?.(restored);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return new Recovery();
|
|
57
|
+
}
|
|
@@ -107,6 +107,10 @@ export interface LoginFormData {
|
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
109
|
export interface LoginFormProps extends FormLayoutOptions, DataAttributes {
|
|
110
|
+
/** 默认在桌面首次就绪且页面尚无焦点时聚焦登录标识;触屏不主动弹出键盘。 */
|
|
111
|
+
autoFocus?: boolean;
|
|
112
|
+
/** 初始登录标识;原地恢复时预填原用户名,仍走正常鉴别。 */
|
|
113
|
+
initialIdentifier?: string;
|
|
110
114
|
/** 实际可用的方式;空数组表示无可用登录方式。 */
|
|
111
115
|
methods?: AuthLoginMethod[];
|
|
112
116
|
/** 验证码长度 */
|
|
@@ -523,6 +527,7 @@ export interface AuthPanelActions {
|
|
|
523
527
|
method?: AuthLoginMethod;
|
|
524
528
|
code?: string;
|
|
525
529
|
captcha?: string;
|
|
530
|
+
expectedUserId?: string;
|
|
526
531
|
}) => Promise<HaiResult<unknown>>;
|
|
527
532
|
/** 注册并登录;禁用新账户的待启用状态由面板单独提示。 */
|
|
528
533
|
register: (input: {
|
|
@@ -580,6 +585,10 @@ export type AuthPanelMode = 'login' | 'register' | 'forgot' | 'reset' | 'renew';
|
|
|
580
585
|
* ```
|
|
581
586
|
*/
|
|
582
587
|
export interface AuthPanelProps extends FormLayoutOptions, DataAttributes {
|
|
588
|
+
/** 嵌入弹窗等已有布局,省略整页背景和重复标题。 */
|
|
589
|
+
embedded?: boolean;
|
|
590
|
+
/** 登录标识初始值;不能替代服务端主体约束。 */
|
|
591
|
+
initialIdentifier?: string;
|
|
583
592
|
/** 未取得配置时显示加载状态,只消费 IAM 的公开配置。 */
|
|
584
593
|
config: AuthPanelConfig | null;
|
|
585
594
|
/** 由 Kit 或 API client 提供标准动作,组件不处理底层传输。 */
|