@h-ai/ui 0.1.0-alpha.74 → 0.1.0-alpha.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +36 -4
- package/README.ja.md +36 -4
- package/README.md +36 -4
- package/auto-import.d.ts +2 -0
- package/auto-import.js +2 -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 +2 -2
- 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/LoginForm.svelte +25 -1
- package/dist/components/scenes/iam/PasswordInput.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/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
|
@@ -15,10 +15,12 @@
|
|
|
15
15
|
```
|
|
16
16
|
-->
|
|
17
17
|
<script lang='ts'>
|
|
18
|
+
import type { Snippet } from 'svelte'
|
|
18
19
|
import type { DataAttributes } from '../../../types.js'
|
|
20
|
+
import { onDestroy } from 'svelte'
|
|
19
21
|
import { uiM } from '../../../messages.js'
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
+
import { getDataAttributes } from '../../../utils.js'
|
|
23
|
+
import FilterBar from '../../compounds/FilterBar.svelte'
|
|
22
24
|
import Input from '../../primitives/Input.svelte'
|
|
23
25
|
import Select from '../../primitives/Select.svelte'
|
|
24
26
|
|
|
@@ -49,6 +51,8 @@
|
|
|
49
51
|
searchValue = $bindable(''),
|
|
50
52
|
filterFields = [],
|
|
51
53
|
filterValues = $bindable<Record<string, unknown>>({}),
|
|
54
|
+
expanded = $bindable(false),
|
|
55
|
+
actions,
|
|
52
56
|
onsearch,
|
|
53
57
|
onfilterchange,
|
|
54
58
|
onreset,
|
|
@@ -60,6 +64,8 @@
|
|
|
60
64
|
searchValue?: string
|
|
61
65
|
filterFields?: FilterFieldDef[]
|
|
62
66
|
filterValues?: Record<string, unknown>
|
|
67
|
+
expanded?: boolean
|
|
68
|
+
actions?: Snippet
|
|
63
69
|
onsearch?: (search: string) => void
|
|
64
70
|
onfilterchange?: (filters: Record<string, unknown>) => void
|
|
65
71
|
onreset?: () => void
|
|
@@ -68,10 +74,11 @@
|
|
|
68
74
|
|
|
69
75
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
70
76
|
let searchTimer: ReturnType<typeof setTimeout> | undefined
|
|
77
|
+
onDestroy(() => clearTimeout(searchTimer))
|
|
71
78
|
|
|
72
79
|
// 是否存在已激活的搜索/过滤条件(用于显示重置按钮)
|
|
73
|
-
const
|
|
74
|
-
const hasActiveFilters = $derived(searchValue.trim() !== '' ||
|
|
80
|
+
const activeFilterCount = $derived(Object.values(filterValues).filter(v => v !== undefined && v !== '' && v !== null).length)
|
|
81
|
+
const hasActiveFilters = $derived(searchValue.trim() !== '' || activeFilterCount > 0)
|
|
75
82
|
|
|
76
83
|
const dateLikeTypes = new Set(['date', 'datetime-local', 'datetime', 'month', 'week'])
|
|
77
84
|
const numberLikeTypes = new Set(['number', 'integer'])
|
|
@@ -140,22 +147,29 @@
|
|
|
140
147
|
}
|
|
141
148
|
</script>
|
|
142
149
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
{#snippet search()}
|
|
151
|
+
<div class='relative w-full max-w-full sm:w-64 md:w-72'>
|
|
152
|
+
<span class='icon-[tabler--search] pointer-events-none absolute left-3 top-1/2 z-10 size-4 -translate-y-1/2 text-base-content/35'></span>
|
|
153
|
+
<Input
|
|
154
|
+
type='text'
|
|
155
|
+
size='sm'
|
|
156
|
+
placeholder={searchPlaceholder || uiM('crud_search_placeholder')}
|
|
157
|
+
class='h-8 pl-9 shadow-none'
|
|
158
|
+
bind:value={searchValue}
|
|
159
|
+
oninput={handleSearchInput}
|
|
160
|
+
onkeydown={(event) => {
|
|
161
|
+
if (event.key === 'Enter' && !event.isComposing) {
|
|
162
|
+
event.preventDefault()
|
|
163
|
+
clearTimeout(searchTimer)
|
|
164
|
+
onsearch?.(searchValue)
|
|
165
|
+
}
|
|
166
|
+
}}
|
|
167
|
+
autocomplete='off'
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
{/snippet}
|
|
158
171
|
|
|
172
|
+
{#snippet fields()}
|
|
159
173
|
{#each filterFields as field (field.id)}
|
|
160
174
|
{@const fieldPlaceholder = resolveText(field.placeholder)}
|
|
161
175
|
{@const opts = resolveOptions(field.options)}
|
|
@@ -248,15 +262,10 @@
|
|
|
248
262
|
</div>
|
|
249
263
|
{/if}
|
|
250
264
|
{/each}
|
|
265
|
+
{/snippet}
|
|
251
266
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
>
|
|
258
|
-
{uiM('crud_reset')}
|
|
259
|
-
<span class='icon-[tabler--x] size-3.5'></span>
|
|
260
|
-
</BareButton>
|
|
261
|
-
{/if}
|
|
262
|
-
</div>
|
|
267
|
+
{#snippet buttons()}
|
|
268
|
+
{#if actions}{@render actions()}{/if}
|
|
269
|
+
{/snippet}
|
|
270
|
+
|
|
271
|
+
<FilterBar {...dataAttributes} class={className} bind:expanded activeCount={activeFilterCount} leading={searchable ? search : undefined} actions={buttons} onreset={hasActiveFilters ? handleReset : undefined} children={filterFields.length > 0 ? fields : undefined} />
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
import type { DataAttributes } from '../../../types.js';
|
|
2
3
|
/**
|
|
3
4
|
* 工具栏过滤字段的局部视图;值由宿主条件查询消费。
|
|
@@ -31,6 +32,8 @@ type $$ComponentProps = {
|
|
|
31
32
|
searchValue?: string;
|
|
32
33
|
filterFields?: FilterFieldDef[];
|
|
33
34
|
filterValues?: Record<string, unknown>;
|
|
35
|
+
expanded?: boolean;
|
|
36
|
+
actions?: Snippet;
|
|
34
37
|
onsearch?: (search: string) => void;
|
|
35
38
|
onfilterchange?: (filters: Record<string, unknown>) => void;
|
|
36
39
|
onreset?: () => void;
|
|
@@ -52,6 +55,6 @@ type $$ComponentProps = {
|
|
|
52
55
|
* await unmount(component)
|
|
53
56
|
* ```
|
|
54
57
|
*/
|
|
55
|
-
declare const CrudFilterBar: import("svelte").Component<$$ComponentProps, {}, "searchValue" | "filterValues">;
|
|
58
|
+
declare const CrudFilterBar: import("svelte").Component<$$ComponentProps, {}, "expanded" | "searchValue" | "filterValues">;
|
|
56
59
|
type CrudFilterBar = ReturnType<typeof CrudFilterBar>;
|
|
57
60
|
export default CrudFilterBar;
|
|
@@ -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;
|