@h-ai/ui 0.1.0-alpha.74 → 0.1.0-alpha.76
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 +46 -17
- package/README.ja.md +46 -17
- package/README.md +46 -17
- package/auto-import.d.ts +2 -0
- package/auto-import.js +2 -0
- package/dist/components/compounds/Alert.svelte +2 -2
- package/dist/components/compounds/Alert.svelte.d.ts +1 -1
- 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/ToastContainer.svelte +96 -42
- package/dist/components/compounds/ToastContainer.svelte.d.ts +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 +2 -2
- package/dist/components/scenes/app/FeedbackForm.svelte +5 -7
- 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 +5 -3
- package/dist/components/scenes/iam/LoginForm.svelte +25 -1
- package/dist/components/scenes/iam/PasswordInput.svelte +1 -1
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +1 -1
- package/dist/components/scenes/types.d.ts +2 -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 +9 -2
- package/dist/messages/ja-JP.json +9 -2
- package/dist/messages/zh-CN.json +9 -2
- 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/toast.svelte.d.ts +7 -6
- package/dist/toast.svelte.js +23 -23
- package/dist/types.d.ts +6 -2
- package/dist/workspace-context.d.ts +20 -0
- package/dist/workspace-context.js +9 -0
- package/package.json +7 -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}
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import { err, HaiCommonError } from '@h-ai/core'
|
|
31
31
|
import { onMount, untrack } from 'svelte'
|
|
32
32
|
import { uiM } from '../../../messages.js'
|
|
33
|
+
import { toast } from '../../../toast.svelte.js'
|
|
33
34
|
import { getDataAttributes } from '../../../utils.js'
|
|
34
35
|
import Alert from '../../compounds/Alert.svelte'
|
|
35
36
|
import FormField from '../../compounds/FormField.svelte'
|
|
@@ -120,7 +121,7 @@
|
|
|
120
121
|
notice = 'auth_registration_pending'
|
|
121
122
|
}
|
|
122
123
|
else {
|
|
123
|
-
if (authenticate && actions.renewPassword &&
|
|
124
|
+
if (authenticate && actions.renewPassword && (result.error.code === 'hai:iam:007' || result.error.code === 'hai:iam:025'))
|
|
124
125
|
mode = 'renew'
|
|
125
126
|
actionError = result.error
|
|
126
127
|
}
|
|
@@ -129,7 +130,8 @@
|
|
|
129
130
|
await onauthenticated?.()
|
|
130
131
|
}
|
|
131
132
|
else {
|
|
132
|
-
|
|
133
|
+
if (successNotice)
|
|
134
|
+
toast.success(uiM(successNotice))
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
catch { networkFailed = true }
|
|
@@ -177,7 +179,7 @@
|
|
|
177
179
|
<Alert variant='warning'>{uiM('auth_unavailable')}</Alert>
|
|
178
180
|
<div class='mt-4 text-center'>{@render link('login', uiM('login_submit'), loginUrl)}</div>
|
|
179
181
|
{:else}
|
|
180
|
-
{#if notice}<
|
|
182
|
+
{#if notice}<p role='status' class='mb-4 text-sm text-base-content/70'>{uiM(notice)}</p>{/if}
|
|
181
183
|
<span role='status' class='sr-only'>{verifying ? uiM('auth_captcha_verifying') : ''}</span>
|
|
182
184
|
{#if mode === 'login'}
|
|
183
185
|
<LoginForm {initialIdentifier} submitText={verifying ? uiM('auth_captcha_verifying') : undefined} {columns} {labelPosition} {labelWidth} {methods} {loading} {errors} header={loginHeader} extraFields={loginFields} showForgotPassword={config.passwordReset.enabled} {forgotPasswordUrl}
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
const {
|
|
33
33
|
methods = ['password'],
|
|
34
|
+
autoFocus = true,
|
|
34
35
|
initialIdentifier = '',
|
|
35
36
|
otpLength = 6,
|
|
36
37
|
resendInterval = 60,
|
|
@@ -58,12 +59,33 @@
|
|
|
58
59
|
}: LoginFormProps & DataAttributes = $props()
|
|
59
60
|
|
|
60
61
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
62
|
+
let formElement = $state<HTMLFormElement>()
|
|
63
|
+
let focusedInitially = false
|
|
61
64
|
|
|
62
65
|
let username = $state(untrack(() => initialIdentifier))
|
|
63
66
|
let password = $state('')
|
|
64
67
|
let selectedMethod = $state<AuthLoginMethod>('password')
|
|
65
68
|
const method = $derived(methods.includes(selectedMethod) ? selectedMethod : methods[0])
|
|
66
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
|
+
})
|
|
67
89
|
let code = $state('')
|
|
68
90
|
let sending = $state(false)
|
|
69
91
|
let sendFailure = $state<Pick<HaiError, 'code' | 'message'> | 'network'>()
|
|
@@ -139,7 +161,7 @@
|
|
|
139
161
|
}
|
|
140
162
|
</script>
|
|
141
163
|
|
|
142
|
-
<form {...dataAttributes} class={formClass} onsubmit={handleSubmit}>
|
|
164
|
+
<form {...dataAttributes} bind:this={formElement} class={formClass} onsubmit={handleSubmit}>
|
|
143
165
|
<FormLayout {columns} {labelPosition} {labelWidth}>
|
|
144
166
|
<!-- 标题 -->
|
|
145
167
|
{#if showTitle}
|
|
@@ -168,6 +190,7 @@
|
|
|
168
190
|
{/each}
|
|
169
191
|
</div>
|
|
170
192
|
{/if}
|
|
193
|
+
{#if method === 'ldap'}<p class='text-sm text-base-content/70'>{uiM('login_method_ldap_hint')}</p>{/if}
|
|
171
194
|
{#if !method}
|
|
172
195
|
<Alert variant='warning'>{uiM('auth_unavailable')}</Alert>
|
|
173
196
|
{:else}
|
|
@@ -244,6 +267,7 @@
|
|
|
244
267
|
<!-- 提交按钮 -->
|
|
245
268
|
<Button
|
|
246
269
|
type='submit'
|
|
270
|
+
submitHint
|
|
247
271
|
variant='primary'
|
|
248
272
|
{loading}
|
|
249
273
|
disabled={loading || disabled || !method}
|
|
@@ -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)
|