@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
|
@@ -21,12 +21,15 @@
|
|
|
21
21
|
<script lang='ts'>
|
|
22
22
|
import type { Snippet } from 'svelte'
|
|
23
23
|
import type { DataAttributes } from '../../../types.js'
|
|
24
|
+
import type { WorkspaceContext } from '../../../workspace-context.js'
|
|
24
25
|
import type { CrudFieldDef } from './crud-controller.svelte.js'
|
|
25
26
|
import type { CrudDensity, CrudFormConfig, CrudPaginationConfig, CrudToolbarStyle } from './crud-types.js'
|
|
26
27
|
import type { NavAdapter } from './nav-adapter.js'
|
|
28
|
+
import { getContext } from 'svelte'
|
|
27
29
|
import { SvelteURLSearchParams } from 'svelte/reactivity'
|
|
28
30
|
import { uiM } from '../../../messages.js'
|
|
29
31
|
import { getDataAttributes } from '../../../utils.js'
|
|
32
|
+
import { workspaceContextKey } from '../../../workspace-context.js'
|
|
30
33
|
import Card from '../../compounds/Card.svelte'
|
|
31
34
|
import DataTable from '../../compounds/DataTable.svelte'
|
|
32
35
|
import PageHeader from '../../compounds/PageHeader.svelte'
|
|
@@ -134,7 +137,7 @@
|
|
|
134
137
|
density = 'normal',
|
|
135
138
|
rowClickDetail = true,
|
|
136
139
|
detailColumns = [],
|
|
137
|
-
showHeader
|
|
140
|
+
showHeader,
|
|
138
141
|
listItemActions,
|
|
139
142
|
tableCell,
|
|
140
143
|
onrowclick,
|
|
@@ -176,7 +179,7 @@
|
|
|
176
179
|
rowClickDetail?: boolean
|
|
177
180
|
/** 点击后打开详情的列 key。 */
|
|
178
181
|
detailColumns?: string[]
|
|
179
|
-
/**
|
|
182
|
+
/** 工作区导航已有标题时默认隐藏;可显式开启,独立使用时默认显示。 */
|
|
180
183
|
showHeader?: boolean
|
|
181
184
|
/** 每行额外操作按钮插槽。 */
|
|
182
185
|
listItemActions?: Snippet<[Record<string, unknown>]>
|
|
@@ -236,6 +239,7 @@
|
|
|
236
239
|
|
|
237
240
|
/** 透传到根节点的 data-* 属性。 */
|
|
238
241
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
242
|
+
const workspace = getContext<WorkspaceContext | undefined>(workspaceContextKey)
|
|
239
243
|
|
|
240
244
|
// ─── 加载 / 空 / 错误展示态 ───
|
|
241
245
|
|
|
@@ -259,6 +263,8 @@
|
|
|
259
263
|
const keyField = $derived(crud.resource.keyField ?? 'id')
|
|
260
264
|
/** 当前资源的本地化标题。 */
|
|
261
265
|
const resourceLabel = $derived(resolveText(crud.resource.label))
|
|
266
|
+
/** 同名导航已显示标题时,将页面操作并入筛选工具栏。 */
|
|
267
|
+
const effectiveShowHeader = $derived(showHeader ?? !workspace?.title)
|
|
262
268
|
/** 根据权限和 API 能力判断是否显示新建入口。 */
|
|
263
269
|
const canCreate = $derived(permissions.create !== false && Boolean(crud.api.create))
|
|
264
270
|
/** 根据权限和 API 能力判断是否显示编辑入口。 */
|
|
@@ -270,7 +276,7 @@
|
|
|
270
276
|
/** 是否使用紧凑列表密度。 */
|
|
271
277
|
const isCompact = $derived(density === 'compact')
|
|
272
278
|
/** 页面主体垂直间距;列表卡片会占满其余可用高度。 */
|
|
273
|
-
const pageGapClass = 'flex min-h-0 h-full min-w-0 flex-1 flex-col gap-
|
|
279
|
+
const pageGapClass = 'flex min-h-0 h-full min-w-0 flex-1 flex-col gap-3'
|
|
274
280
|
/** 行内操作按钮尺寸。 */
|
|
275
281
|
const actionButtonSize = $derived(isCompact ? 'xs' : 'sm')
|
|
276
282
|
/** 行内操作图标尺寸。 */
|
|
@@ -287,7 +293,7 @@
|
|
|
287
293
|
: 'flex min-h-0 flex-1 flex-col overflow-hidden rounded-[1.25rem] border-base-content/7 shadow-sm [&>.card-body]:min-h-0 [&>.card-body]:flex-1',
|
|
288
294
|
)
|
|
289
295
|
/** 分页栏样式;shrink-0 保证它始终贴在卡片底部。 */
|
|
290
|
-
const paginationBarClass = 'mt-auto shrink-0 border-t border-base-content/5 px-
|
|
296
|
+
const paginationBarClass = 'mt-auto shrink-0 border-t border-base-content/5 px-3 py-2'
|
|
291
297
|
|
|
292
298
|
// 表单展示配置(抽屉 / 弹窗)
|
|
293
299
|
/** 编辑/新建面板类型。 */
|
|
@@ -666,7 +672,7 @@
|
|
|
666
672
|
|
|
667
673
|
<div {...dataAttributes} class='{pageGapClass} {className}'>
|
|
668
674
|
<!-- 页面标题;toolbarLeading 承载标题时由调用方关闭,避免重复占用垂直空间。 -->
|
|
669
|
-
{#if
|
|
675
|
+
{#if effectiveShowHeader}
|
|
670
676
|
<PageHeader title={resourceLabel} class='mb-0 shrink-0'>
|
|
671
677
|
{#snippet actions()}
|
|
672
678
|
{#if headerActions}
|
|
@@ -683,7 +689,7 @@
|
|
|
683
689
|
{/if}
|
|
684
690
|
|
|
685
691
|
<!-- 搜索 + 过滤栏 -->
|
|
686
|
-
{#if searchable || filterFields.length > 0 || toolbarLeading || toolbarActions}
|
|
692
|
+
{#if searchable || filterFields.length > 0 || toolbarLeading || toolbarActions || (toolbarStyle === 'toolbar' && canCreate) || (!effectiveShowHeader && (canCreate || headerActions))}
|
|
687
693
|
{#if toolbarStyle === 'toolbar'}
|
|
688
694
|
<TableToolbar
|
|
689
695
|
{searchable}
|
|
@@ -705,6 +711,9 @@
|
|
|
705
711
|
onsort={handleSort}
|
|
706
712
|
onclearsort={handleClearSort}
|
|
707
713
|
>
|
|
714
|
+
{#if !effectiveShowHeader && headerActions}
|
|
715
|
+
{@render headerActions()}
|
|
716
|
+
{/if}
|
|
708
717
|
{#if toolbarActions}
|
|
709
718
|
{@render toolbarActions()}
|
|
710
719
|
{/if}
|
|
@@ -719,7 +728,18 @@
|
|
|
719
728
|
onsearch={handleSearch}
|
|
720
729
|
onfilterchange={handleFilterChange}
|
|
721
730
|
onreset={handleResetFilters}
|
|
722
|
-
|
|
731
|
+
>
|
|
732
|
+
{#snippet actions()}
|
|
733
|
+
{#if !effectiveShowHeader}
|
|
734
|
+
{#if headerActions}{@render headerActions()}{/if}
|
|
735
|
+
{#if canCreate}
|
|
736
|
+
<Button variant='primary' size='sm' onclick={openCreate}>
|
|
737
|
+
<span class='icon-[tabler--plus] mr-1.5 size-4'></span>{uiM('crud_create')}
|
|
738
|
+
</Button>
|
|
739
|
+
{/if}
|
|
740
|
+
{/if}
|
|
741
|
+
{/snippet}
|
|
742
|
+
</CrudFilterBar>
|
|
723
743
|
{/if}
|
|
724
744
|
{/if}
|
|
725
745
|
|
|
@@ -117,7 +117,7 @@ type $$ComponentProps = {
|
|
|
117
117
|
rowClickDetail?: boolean;
|
|
118
118
|
/** 点击后打开详情的列 key。 */
|
|
119
119
|
detailColumns?: string[];
|
|
120
|
-
/**
|
|
120
|
+
/** 工作区导航已有标题时默认隐藏;可显式开启,独立使用时默认显示。 */
|
|
121
121
|
showHeader?: boolean;
|
|
122
122
|
/** 每行额外操作按钮插槽。 */
|
|
123
123
|
listItemActions?: Snippet<[Record<string, unknown>]>;
|
|
@@ -198,7 +198,7 @@ export interface CrudPageProps<T = Record<string, unknown>> extends DataAttribut
|
|
|
198
198
|
rowClickDetail?: boolean;
|
|
199
199
|
/** 点击后打开详情的列 key;只让标题等主标识列可点击时使用 */
|
|
200
200
|
detailColumns?: string[];
|
|
201
|
-
/**
|
|
201
|
+
/** 工作区导航已有标题时默认隐藏,独立使用时默认显示;true/false 显式覆盖,操作仍保留在工具栏。 */
|
|
202
202
|
showHeader?: boolean;
|
|
203
203
|
/** 列表行操作按钮插槽 */
|
|
204
204
|
listItemActions?: Snippet<[T]>;
|
|
@@ -15,124 +15,44 @@
|
|
|
15
15
|
<script lang='ts'>
|
|
16
16
|
import type { GuideController } from '../../../guide-types.js'
|
|
17
17
|
import type { DataAttributes } from '../../../types.js'
|
|
18
|
-
import { onMount, untrack } from 'svelte'
|
|
19
|
-
import { resolveGuideText } from '../../../guide.svelte.js'
|
|
20
18
|
import { getUILocale, uiM } from '../../../messages.js'
|
|
21
|
-
import { getDataAttributes } from '../../../utils.js'
|
|
22
19
|
import Alert from '../../compounds/Alert.svelte'
|
|
23
|
-
import Modal from '../../compounds/Modal.svelte'
|
|
24
20
|
import Button from '../../primitives/Button.svelte'
|
|
25
|
-
import
|
|
26
|
-
import 'driver.js/dist/driver.css'
|
|
27
|
-
import '../../../styles/guide.css'
|
|
21
|
+
import GuideHostContent from './GuideHostContent.svelte'
|
|
28
22
|
|
|
29
|
-
/**
|
|
30
|
-
* 导览宿主属性;绑定应用语言、非敏感身份范围和控制器。
|
|
31
|
-
*
|
|
23
|
+
/** GuideHost 组件的属性契约。
|
|
32
24
|
* @example
|
|
33
25
|
* ```ts
|
|
34
|
-
* import {
|
|
35
|
-
* import { GuideHost
|
|
36
|
-
* const
|
|
37
|
-
*
|
|
38
|
-
* await unmount(host)
|
|
39
|
-
* guide.stop()
|
|
26
|
+
* import type { ComponentProps } from 'svelte'
|
|
27
|
+
* import { GuideHost } from '@h-ai/ui'
|
|
28
|
+
* const props: Partial<ComponentProps<typeof GuideHost>> = {}
|
|
29
|
+
* void props
|
|
40
30
|
* ```
|
|
41
31
|
*/
|
|
42
32
|
interface Props {
|
|
43
33
|
guide: GuideController
|
|
44
34
|
locale?: string
|
|
45
|
-
/** 非敏感的用户标识,账号切换后独立记录引导偏好。 */
|
|
46
35
|
scope?: string
|
|
47
|
-
/** 挂载后提示首次使用者,不会直接打断操作或自动跳转。 */
|
|
48
36
|
autoStart?: string
|
|
49
37
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
void locale
|
|
56
|
-
const tour = guide.offeredTour
|
|
57
|
-
return tour ? { id: tour.id, title: resolveGuideText(tour.title), description: resolveGuideText(tour.description) } : null
|
|
58
|
-
})
|
|
59
|
-
const text = $derived.by(() => ({
|
|
60
|
-
welcome: uiM('guide_welcome', undefined, locale),
|
|
61
|
-
start: uiM('guide_start', undefined, locale),
|
|
62
|
-
later: uiM('guide_later', undefined, locale),
|
|
63
|
-
dismiss: uiM('guide_dismiss', undefined, locale),
|
|
64
|
-
help: uiM('guide_help', undefined, locale),
|
|
65
|
-
close: uiM('guide_close', undefined, locale),
|
|
66
|
-
loading: uiM('guide_loading', undefined, locale),
|
|
67
|
-
}))
|
|
68
|
-
|
|
69
|
-
$effect(() => {
|
|
70
|
-
const currentLocale = locale
|
|
71
|
-
untrack(() => guide.setLocale(currentLocale))
|
|
72
|
-
})
|
|
73
|
-
$effect(() => {
|
|
74
|
-
const currentScope = scope
|
|
75
|
-
const tourId = autoStart
|
|
76
|
-
if (ready) {
|
|
77
|
-
untrack(() => {
|
|
78
|
-
guide.setScope(currentScope)
|
|
79
|
-
if (tourId)
|
|
80
|
-
guide.startIfNeeded(tourId)
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
$effect(() => {
|
|
85
|
-
const pathname = guide.pathname
|
|
86
|
-
untrack(() => guide.handleNavigation(pathname))
|
|
87
|
-
})
|
|
88
|
-
onMount(() => {
|
|
89
|
-
let alive = true
|
|
90
|
-
guide.setScope(scope)
|
|
91
|
-
guide.setLocale(locale)
|
|
92
|
-
void guide.resume().then(() => {
|
|
93
|
-
if (alive)
|
|
94
|
-
ready = true
|
|
95
|
-
})
|
|
96
|
-
return () => {
|
|
97
|
-
alive = false
|
|
98
|
-
guide.stop()
|
|
99
|
-
}
|
|
100
|
-
})
|
|
38
|
+
const { guide, locale = getUILocale(), ...rest }: Props & DataAttributes = $props()
|
|
39
|
+
function release() {
|
|
40
|
+
guide.stop()
|
|
41
|
+
guide.closeHelp()
|
|
42
|
+
}
|
|
101
43
|
</script>
|
|
102
44
|
|
|
103
|
-
<
|
|
104
|
-
|
|
105
|
-
{#
|
|
106
|
-
<
|
|
107
|
-
<p class='text-xs font-medium text-primary'>{text.welcome}</p>
|
|
108
|
-
<h2 class='mt-2 text-base font-semibold'>{offered.title}</h2>
|
|
109
|
-
<p class='mt-2 text-sm leading-6 text-base-content/65'>{offered.description}</p>
|
|
110
|
-
<div class='mt-4 flex flex-wrap gap-2'>
|
|
111
|
-
<Button variant='primary' size='sm' onclick={() => offered && void guide.start(offered.id)} data-testid='guide-start'>{text.start}</Button>
|
|
112
|
-
<Button variant='ghost' size='sm' onclick={() => guide.defer()} data-testid='guide-later'>{text.later}</Button>
|
|
113
|
-
<Button variant='ghost' size='sm' onclick={() => guide.dismiss()} data-testid='guide-dismiss'>{text.dismiss}</Button>
|
|
114
|
-
</div>
|
|
115
|
-
</aside>
|
|
116
|
-
{/if}
|
|
117
|
-
|
|
118
|
-
{#if guide.busy}
|
|
119
|
-
<div class='hai-guide-loading fixed bottom-4 left-1/2 z-[1000000001] flex max-w-[calc(100vw-2rem)] -translate-x-1/2 items-center gap-3 rounded-xl border border-base-content/10 bg-base-100 px-4 py-2 text-sm text-base-content shadow-lg' role='status' data-testid='guide-loading'>
|
|
120
|
-
<span class='loading loading-spinner loading-xs'></span>{text.loading}
|
|
121
|
-
<Button size='sm' variant='ghost' onclick={() => guide.stop()} data-testid='guide-cancel'>{text.close}</Button>
|
|
122
|
-
</div>
|
|
123
|
-
{/if}
|
|
124
|
-
|
|
125
|
-
{#if guide.error}
|
|
126
|
-
<div class='fixed bottom-4 right-4 z-[1500] max-w-[calc(100vw-2rem)]' data-testid='guide-error'>
|
|
45
|
+
<svelte:boundary onerror={release}>
|
|
46
|
+
<GuideHostContent {guide} {locale} {...rest} />
|
|
47
|
+
{#snippet failed(_error, reset)}
|
|
48
|
+
<div class='fixed bottom-4 right-4 z-[1150] max-w-[calc(100vw-2rem)]' data-testid='guide-error'>
|
|
127
49
|
<Alert variant='warning'>
|
|
128
|
-
<
|
|
50
|
+
<span>{uiM('guide_startFailed', undefined, locale)}</span>
|
|
51
|
+
<Button variant='ghost' size='sm' onclick={() => {
|
|
52
|
+
guide.defer()
|
|
53
|
+
reset()
|
|
54
|
+
}}>{uiM('guide_close', undefined, locale)}</Button>
|
|
129
55
|
</Alert>
|
|
130
56
|
</div>
|
|
131
|
-
{/
|
|
132
|
-
|
|
133
|
-
{#if guide.helpOpen}
|
|
134
|
-
<Modal open title={text.help} size='4xl' height='min(80dvh, 48rem)' bodyClass='p-0' onclose={() => guide.closeHelp()} data-testid='guide-help'>
|
|
135
|
-
<HelpCenter articles={guide.articles} tours={guide.tours} selectedId={guide.articleId} {locale} onstart={id => void guide.start(id)} />
|
|
136
|
-
</Modal>
|
|
137
|
-
{/if}
|
|
138
|
-
</div>
|
|
57
|
+
{/snippet}
|
|
58
|
+
</svelte:boundary>
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import type { GuideController } from '../../../guide-types.js';
|
|
2
2
|
import type { DataAttributes } from '../../../types.js';
|
|
3
|
-
|
|
4
|
-
import '../../../styles/guide.css';
|
|
5
|
-
/**
|
|
6
|
-
* 导览宿主属性;绑定应用语言、非敏感身份范围和控制器。
|
|
7
|
-
*
|
|
3
|
+
/** GuideHost 组件的属性契约。
|
|
8
4
|
* @example
|
|
9
5
|
* ```ts
|
|
10
|
-
* import {
|
|
11
|
-
* import { GuideHost
|
|
12
|
-
* const
|
|
13
|
-
*
|
|
14
|
-
* await unmount(host)
|
|
15
|
-
* guide.stop()
|
|
6
|
+
* import type { ComponentProps } from 'svelte'
|
|
7
|
+
* import { GuideHost } from '@h-ai/ui'
|
|
8
|
+
* const props: Partial<ComponentProps<typeof GuideHost>> = {}
|
|
9
|
+
* void props
|
|
16
10
|
* ```
|
|
17
11
|
*/
|
|
18
12
|
interface Props {
|
|
19
13
|
guide: GuideController;
|
|
20
14
|
locale?: string;
|
|
21
|
-
/** 非敏感的用户标识,账号切换后独立记录引导偏好。 */
|
|
22
15
|
scope?: string;
|
|
23
|
-
/** 挂载后提示首次使用者,不会直接打断操作或自动跳转。 */
|
|
24
16
|
autoStart?: string;
|
|
25
17
|
}
|
|
26
18
|
type $$ComponentProps = Props & DataAttributes;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component GuideHost
|
|
3
|
+
GuideHost 组件的公开使用示例。
|
|
4
|
+
|
|
5
|
+
@example
|
|
6
|
+
```ts
|
|
7
|
+
import { mount, unmount } from 'svelte'
|
|
8
|
+
import { GuideHost, createGuide } from '@h-ai/ui'
|
|
9
|
+
const guide = createGuide({ tours: [], persistence: 'memory' })
|
|
10
|
+
const host = mount(GuideHost, { target: document.body, props: { guide, locale: 'zh-CN', scope: 'demo' } })
|
|
11
|
+
await unmount(host)
|
|
12
|
+
guide.stop()
|
|
13
|
+
```
|
|
14
|
+
-->
|
|
15
|
+
<script lang='ts'>
|
|
16
|
+
import type { GuideController } from '../../../guide-types.js'
|
|
17
|
+
import type { DataAttributes } from '../../../types.js'
|
|
18
|
+
import { onMount, untrack } from 'svelte'
|
|
19
|
+
import { resolveGuideText } from '../../../guide.svelte.js'
|
|
20
|
+
import { getUILocale, uiM } from '../../../messages.js'
|
|
21
|
+
import { getDataAttributes } from '../../../utils.js'
|
|
22
|
+
import Alert from '../../compounds/Alert.svelte'
|
|
23
|
+
import Modal from '../../compounds/Modal.svelte'
|
|
24
|
+
import Button from '../../primitives/Button.svelte'
|
|
25
|
+
import HelpCenter from './HelpCenter.svelte'
|
|
26
|
+
import 'driver.js/dist/driver.css'
|
|
27
|
+
import '../../../styles/guide.css'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 导览宿主属性;绑定应用语言、非敏感身份范围和控制器。
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { mount, unmount } from 'svelte'
|
|
35
|
+
* import { GuideHost, createGuide } from '@h-ai/ui'
|
|
36
|
+
* const guide = createGuide({ tours: [], persistence: 'memory' })
|
|
37
|
+
* const host = mount(GuideHost, { target: document.body, props: { guide, locale: 'zh-CN', scope: 'demo' } })
|
|
38
|
+
* await unmount(host)
|
|
39
|
+
* guide.stop()
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
interface Props {
|
|
43
|
+
guide: GuideController
|
|
44
|
+
locale?: string
|
|
45
|
+
/** 非敏感的用户标识,账号切换后独立记录引导偏好。 */
|
|
46
|
+
scope?: string
|
|
47
|
+
/** 挂载后提示首次使用者,不会直接打断操作或自动跳转。 */
|
|
48
|
+
autoStart?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { guide, locale = getUILocale(), scope = 'anonymous', autoStart, ...restProps }: Props & DataAttributes = $props()
|
|
52
|
+
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
53
|
+
let ready = $state(false)
|
|
54
|
+
const offered = $derived.by(() => {
|
|
55
|
+
void locale
|
|
56
|
+
const tour = guide.offeredTour
|
|
57
|
+
return tour ? { id: tour.id, title: resolveGuideText(tour.title), description: resolveGuideText(tour.description) } : null
|
|
58
|
+
})
|
|
59
|
+
const text = $derived.by(() => ({
|
|
60
|
+
welcome: uiM('guide_welcome', undefined, locale),
|
|
61
|
+
start: uiM('guide_start', undefined, locale),
|
|
62
|
+
later: uiM('guide_later', undefined, locale),
|
|
63
|
+
dismiss: uiM('guide_dismiss', undefined, locale),
|
|
64
|
+
help: uiM('guide_help', undefined, locale),
|
|
65
|
+
close: uiM('guide_close', undefined, locale),
|
|
66
|
+
loading: uiM('guide_loading', undefined, locale),
|
|
67
|
+
}))
|
|
68
|
+
|
|
69
|
+
$effect(() => {
|
|
70
|
+
const currentLocale = locale
|
|
71
|
+
untrack(() => guide.setLocale(currentLocale))
|
|
72
|
+
})
|
|
73
|
+
$effect(() => {
|
|
74
|
+
const currentScope = scope
|
|
75
|
+
const tourId = autoStart
|
|
76
|
+
if (ready) {
|
|
77
|
+
untrack(() => {
|
|
78
|
+
guide.setScope(currentScope)
|
|
79
|
+
if (tourId)
|
|
80
|
+
guide.startIfNeeded(tourId)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
$effect(() => {
|
|
85
|
+
const pathname = guide.pathname
|
|
86
|
+
untrack(() => guide.handleNavigation(pathname))
|
|
87
|
+
})
|
|
88
|
+
onMount(() => {
|
|
89
|
+
let alive = true
|
|
90
|
+
guide.setScope(scope)
|
|
91
|
+
guide.setLocale(locale)
|
|
92
|
+
void guide.resume().then(() => {
|
|
93
|
+
if (alive)
|
|
94
|
+
ready = true
|
|
95
|
+
}).catch(() => {
|
|
96
|
+
if (alive) {
|
|
97
|
+
guide.stop()
|
|
98
|
+
guide.closeHelp()
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
return () => {
|
|
102
|
+
alive = false
|
|
103
|
+
guide.stop()
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<div {...dataAttributes} class='contents'>
|
|
109
|
+
|
|
110
|
+
{#if offered}
|
|
111
|
+
<aside class='hai-guide-offer fixed bottom-4 right-4 z-[1150] w-96 max-w-[calc(100vw-2rem)] rounded-2xl border border-base-content/10 bg-base-100 p-5 text-base-content shadow-(--shadow-overlay)' aria-label={text.welcome} data-testid='guide-offer'>
|
|
112
|
+
<p class='text-xs font-medium text-primary'>{text.welcome}</p>
|
|
113
|
+
<h2 class='mt-2 text-base font-semibold'>{offered.title}</h2>
|
|
114
|
+
<p class='mt-2 text-sm leading-6 text-base-content/65'>{offered.description}</p>
|
|
115
|
+
<div class='mt-4 flex flex-wrap gap-2'>
|
|
116
|
+
<Button variant='primary' size='sm' onclick={() => offered && void guide.start(offered.id)} data-testid='guide-start'>{text.start}</Button>
|
|
117
|
+
<Button variant='ghost' size='sm' onclick={() => guide.defer()} data-testid='guide-later'>{text.later}</Button>
|
|
118
|
+
<Button variant='ghost' size='sm' onclick={() => guide.dismiss()} data-testid='guide-dismiss'>{text.dismiss}</Button>
|
|
119
|
+
</div>
|
|
120
|
+
</aside>
|
|
121
|
+
{/if}
|
|
122
|
+
|
|
123
|
+
{#if guide.busy}
|
|
124
|
+
<div class='hai-guide-loading fixed bottom-4 left-1/2 z-[1000000001] flex max-w-[calc(100vw-2rem)] -translate-x-1/2 items-center gap-3 rounded-xl border border-base-content/10 bg-base-100 px-4 py-2 text-sm text-base-content shadow-lg' role='status' data-testid='guide-loading'>
|
|
125
|
+
<span class='loading loading-spinner loading-xs'></span>{text.loading}
|
|
126
|
+
<Button size='sm' variant='ghost' onclick={() => guide.stop()} data-testid='guide-cancel'>{text.close}</Button>
|
|
127
|
+
</div>
|
|
128
|
+
{/if}
|
|
129
|
+
|
|
130
|
+
{#if guide.error}
|
|
131
|
+
<div class='fixed bottom-4 right-4 z-[1500] max-w-[calc(100vw-2rem)]' data-testid='guide-error'>
|
|
132
|
+
<Alert variant='warning'>
|
|
133
|
+
<div class='flex items-center gap-3'><span>{guide.error}</span><Button size='sm' variant='ghost' onclick={() => guide.clearError()}>{text.close}</Button></div>
|
|
134
|
+
</Alert>
|
|
135
|
+
</div>
|
|
136
|
+
{/if}
|
|
137
|
+
|
|
138
|
+
{#if guide.helpOpen}
|
|
139
|
+
<Modal open title={text.help} size='4xl' height='min(80dvh, 48rem)' bodyClass='p-0' onclose={() => guide.closeHelp()} data-testid='guide-help'>
|
|
140
|
+
<HelpCenter articles={guide.articles} tours={guide.tours} selectedId={guide.articleId} {locale} onstart={id => void guide.start(id)} />
|
|
141
|
+
</Modal>
|
|
142
|
+
{/if}
|
|
143
|
+
</div>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GuideController } from '../../../guide-types.js';
|
|
2
|
+
import type { DataAttributes } from '../../../types.js';
|
|
3
|
+
import 'driver.js/dist/driver.css';
|
|
4
|
+
import '../../../styles/guide.css';
|
|
5
|
+
/**
|
|
6
|
+
* 导览宿主属性;绑定应用语言、非敏感身份范围和控制器。
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { mount, unmount } from 'svelte'
|
|
11
|
+
* import { GuideHost, createGuide } from '@h-ai/ui'
|
|
12
|
+
* const guide = createGuide({ tours: [], persistence: 'memory' })
|
|
13
|
+
* const host = mount(GuideHost, { target: document.body, props: { guide, locale: 'zh-CN', scope: 'demo' } })
|
|
14
|
+
* await unmount(host)
|
|
15
|
+
* guide.stop()
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
interface Props {
|
|
19
|
+
guide: GuideController;
|
|
20
|
+
locale?: string;
|
|
21
|
+
/** 非敏感的用户标识,账号切换后独立记录引导偏好。 */
|
|
22
|
+
scope?: string;
|
|
23
|
+
/** 挂载后提示首次使用者,不会直接打断操作或自动跳转。 */
|
|
24
|
+
autoStart?: string;
|
|
25
|
+
}
|
|
26
|
+
type $$ComponentProps = Props & DataAttributes;
|
|
27
|
+
/**
|
|
28
|
+
* GuideHost
|
|
29
|
+
* GuideHost 组件的公开使用示例。
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { mount, unmount } from 'svelte'
|
|
34
|
+
* import { GuideHost, createGuide } from '@h-ai/ui'
|
|
35
|
+
* const guide = createGuide({ tours: [], persistence: 'memory' })
|
|
36
|
+
* const host = mount(GuideHost, { target: document.body, props: { guide, locale: 'zh-CN', scope: 'demo' } })
|
|
37
|
+
* await unmount(host)
|
|
38
|
+
* guide.stop()
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare const GuideHostContent: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
42
|
+
type GuideHostContent = ReturnType<typeof GuideHostContent>;
|
|
43
|
+
export default GuideHostContent;
|
|
@@ -48,19 +48,31 @@
|
|
|
48
48
|
const searchId = $props.id()
|
|
49
49
|
let currentId = $derived(selectedId)
|
|
50
50
|
// 显式依赖宿主语言,确保回调返回的业务翻译也重新求值。
|
|
51
|
-
const
|
|
51
|
+
const articleState = $derived.by(() => {
|
|
52
52
|
void locale
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
let failed = false
|
|
54
|
+
const localized = articles.flatMap((article) => {
|
|
55
|
+
try {
|
|
56
|
+
if (article.enabled && !article.enabled())
|
|
57
|
+
return []
|
|
58
|
+
return [{ ...article, title: resolveGuideText(article.title), description: resolveGuideText(article.description), category: resolveGuideText(article.category), content: resolveGuideText(article.content) }]
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
failed = true
|
|
62
|
+
return []
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
return { localized, failed }
|
|
60
66
|
})
|
|
67
|
+
const localized = $derived(articleState.localized)
|
|
61
68
|
const availableTours = $derived.by(() => {
|
|
62
69
|
void locale
|
|
63
|
-
return tours.
|
|
70
|
+
return tours.flatMap((tour) => {
|
|
71
|
+
try {
|
|
72
|
+
return !tour.enabled || tour.enabled() ? [{ id: tour.id, title: resolveGuideText(tour.title) }] : []
|
|
73
|
+
}
|
|
74
|
+
catch { return [] }
|
|
75
|
+
})
|
|
64
76
|
})
|
|
65
77
|
const visible = $derived(localized.filter(article => (`${article.title} ${article.description} ${article.category} ${article.content}`).toLowerCase().includes(search.trim().toLowerCase())))
|
|
66
78
|
const selected = $derived(visible.find(article => article.id === currentId) ?? visible[0])
|
|
@@ -97,6 +109,7 @@
|
|
|
97
109
|
{/if}
|
|
98
110
|
</nav>
|
|
99
111
|
<article class='min-w-0 flex-1 p-5 md:p-7' data-testid='guide-article-content'>
|
|
112
|
+
{#if articleState.failed}<p class='text-sm text-error' role='alert'>{text.failed}</p>{/if}
|
|
100
113
|
{#if selected}
|
|
101
114
|
<h2 class='text-xl font-semibold'>{selected.title}</h2>
|
|
102
115
|
{#if selected.description}<p class='mt-2 text-sm text-base-content/60'>{selected.description}</p>{/if}
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
import RegisterForm from './RegisterForm.svelte'
|
|
47
47
|
import ResetPasswordForm from './ResetPasswordForm.svelte'
|
|
48
48
|
|
|
49
|
-
const { config, actions, columns = 1, labelPosition = 'top', labelWidth = '8rem', initialMode = 'login', resetToken = '', loginUrl, registerUrl, forgotPasswordUrl, onauthenticated, error = '', onretry, loginHeader, loginFields, loginFooter, registerHeader, registerFields, registerFooter, ...restProps }: AuthPanelProps = $props()
|
|
49
|
+
const { config, actions, embedded = false, initialIdentifier = '', columns = 1, labelPosition = 'top', labelWidth = '8rem', initialMode = 'login', resetToken = '', loginUrl, registerUrl, forgotPasswordUrl, onauthenticated, error = '', onretry, loginHeader, loginFields, loginFooter, registerHeader, registerFields, registerFooter, ...restProps }: AuthPanelProps = $props()
|
|
50
50
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
51
51
|
let mode = $state<AuthPanelMode>(untrack(() => initialMode))
|
|
52
52
|
let loading = $state(false)
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
{:else}<BareButton type='button' class='link link-primary text-sm' disabled={loading} onclick={() => switchMode(next)}>{label}</BareButton>{/if}
|
|
165
165
|
{/snippet}
|
|
166
166
|
|
|
167
|
-
<AuthShell {...dataAttributes} {...config?.ui} title={config?.ui.title || title} brandTitle={config?.ui.brandTitle || uiM('auth_brand')}>
|
|
167
|
+
<AuthShell {embedded} {...dataAttributes} {...config?.ui} title={config?.ui.title || title} brandTitle={config?.ui.brandTitle || uiM('auth_brand')}>
|
|
168
168
|
<fieldset class='m-0 min-w-0 border-0 p-0' disabled={!interactive}>
|
|
169
169
|
<!-- 固定内容包装节点,避免 fieldset 插入通知时丢失容器查询子树的布局。 -->
|
|
170
170
|
<div class='min-w-0'>
|
|
@@ -178,9 +178,9 @@
|
|
|
178
178
|
<div class='mt-4 text-center'>{@render link('login', uiM('login_submit'), loginUrl)}</div>
|
|
179
179
|
{:else}
|
|
180
180
|
{#if notice}<Alert variant='success' class='mb-4'>{uiM(notice)}</Alert>{/if}
|
|
181
|
-
|
|
181
|
+
<span role='status' class='sr-only'>{verifying ? uiM('auth_captcha_verifying') : ''}</span>
|
|
182
182
|
{#if mode === 'login'}
|
|
183
|
-
<LoginForm {columns} {labelPosition} {labelWidth} {methods} {loading} {errors} header={loginHeader} extraFields={loginFields} showForgotPassword={config.passwordReset.enabled} {forgotPasswordUrl}
|
|
183
|
+
<LoginForm {initialIdentifier} submitText={verifying ? uiM('auth_captcha_verifying') : undefined} {columns} {labelPosition} {labelWidth} {methods} {loading} {errors} header={loginHeader} extraFields={loginFields} showForgotPassword={config.passwordReset.enabled} {forgotPasswordUrl}
|
|
184
184
|
onforgotpassword={forgotPasswordUrl ? undefined : () => switchMode('forgot')}
|
|
185
185
|
otpLength={config.otp.length} resendInterval={config.otp.resendInterval} onsendotp={identifier => withCaptcha('sendOtp', captcha => actions.sendOtp(identifier, { captcha }))}
|
|
186
186
|
agreements={config.agreements.showOnLogin ? config.agreements : undefined}
|
|
@@ -194,7 +194,7 @@
|
|
|
194
194
|
{/snippet}
|
|
195
195
|
</LoginForm>
|
|
196
196
|
{:else if mode === 'register'}
|
|
197
|
-
<RegisterForm {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}
|
|
197
|
+
<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}
|
|
198
198
|
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)}>
|
|
199
199
|
{#snippet footer()}
|
|
200
200
|
{#if registerFooter}{@render registerFooter()}{/if}
|
|
@@ -202,7 +202,7 @@
|
|
|
202
202
|
{/snippet}
|
|
203
203
|
</RegisterForm>
|
|
204
204
|
{:else if mode === 'forgot'}
|
|
205
|
-
<ForgotPasswordForm {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')}>
|
|
205
|
+
<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')}>
|
|
206
206
|
{#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}
|
|
207
207
|
</ForgotPasswordForm>
|
|
208
208
|
{:else if mode === 'renew'}
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
<Input id='renew-identifier' autocomplete='username' bind:value={renewalIdentifier} disabled={loading} required />
|
|
212
212
|
</FormField>
|
|
213
213
|
</div>
|
|
214
|
-
<ChangePasswordForm {columns} {labelPosition} {labelWidth} {loading} {errors} disabled={!renewalIdentifier.trim()} passwordPolicy={config.password} minPasswordLength={config.password.minLength}
|
|
214
|
+
<ChangePasswordForm submitText={verifying ? uiM('auth_captcha_verifying') : undefined} {columns} {labelPosition} {labelWidth} {loading} {errors} disabled={!renewalIdentifier.trim()} passwordPolicy={config.password} minPasswordLength={config.password.minLength}
|
|
215
215
|
onsubmit={data => renewPassword(data.oldPassword || '', data.newPassword)} />
|
|
216
216
|
<div class='mt-4 text-center'>{@render link('login', uiM('login_submit'), loginUrl)}</div>
|
|
217
217
|
{:else}
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
const {
|
|
26
26
|
variant = 'card',
|
|
27
27
|
title = '',
|
|
28
|
+
embedded = false,
|
|
28
29
|
subtitle = '',
|
|
29
30
|
brandTitle = '',
|
|
30
31
|
brandText = '',
|
|
@@ -42,6 +43,8 @@
|
|
|
42
43
|
}: {
|
|
43
44
|
/** 布局形态:'card'(居中卡片,默认)或 'split'(左右分栏) */
|
|
44
45
|
variant?: 'card' | 'split'
|
|
46
|
+
/** 嵌入已有弹窗/布局,只渲染表单内容。 */
|
|
47
|
+
embedded?: boolean
|
|
45
48
|
/** 表单区标题 */
|
|
46
49
|
title?: string
|
|
47
50
|
/** 表单区副标题 */
|
|
@@ -96,7 +99,9 @@
|
|
|
96
99
|
</div>
|
|
97
100
|
{/snippet}
|
|
98
101
|
|
|
99
|
-
{#if
|
|
102
|
+
{#if embedded}
|
|
103
|
+
<div {...dataAttributes} class={className}>{#if children}{@render children()}{/if}</div>
|
|
104
|
+
{:else if isSplit}
|
|
100
105
|
<div class={cn('grid min-h-screen lg:grid-cols-2', className)}>
|
|
101
106
|
<!-- 品牌区 -->
|
|
102
107
|
<div class='relative hidden overflow-hidden bg-primary p-10 text-primary-content lg:flex'>
|