@h-ai/ui 1.0.0-beta.3 → 1.0.0-beta.30
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 +251 -71
- package/README.ja.md +250 -70
- package/README.md +252 -73
- package/auto-import.d.ts +5 -0
- package/auto-import.js +242 -65
- package/dist/components/compounds/Accordion.svelte +6 -2
- package/dist/components/compounds/BottomNav.svelte +14 -2
- package/dist/components/compounds/Card.svelte +3 -1
- package/dist/components/compounds/Combobox.svelte +41 -5
- package/dist/components/compounds/DataTable.svelte +28 -8
- package/dist/components/compounds/DatePicker.svelte +6 -1
- package/dist/components/compounds/Drawer.svelte +12 -4
- package/dist/components/compounds/Dropdown.svelte +135 -59
- package/dist/components/compounds/Empty.svelte +10 -2
- package/dist/components/compounds/FormField.svelte +10 -2
- package/dist/components/compounds/JsonViewer.svelte +18 -6
- package/dist/components/compounds/Modal.svelte +8 -2
- package/dist/components/compounds/Pagination.svelte +22 -7
- package/dist/components/compounds/Popover.svelte +93 -12
- package/dist/components/compounds/Steps.svelte +24 -8
- package/dist/components/compounds/SwipeCell.svelte +3 -1
- package/dist/components/compounds/TableToolbar.svelte +32 -9
- package/dist/components/compounds/Tabs.svelte +25 -5
- package/dist/components/compounds/TagInput.svelte +2 -0
- package/dist/components/compounds/Timeline.svelte +6 -2
- package/dist/components/compounds/ToastContainer.svelte +41 -10
- package/dist/components/compounds/Tooltip.svelte +1 -1
- package/dist/components/compounds/Tooltip.svelte.d.ts +1 -1
- package/dist/components/control-size.js +48 -8
- package/dist/components/primitives/Avatar.svelte +9 -3
- package/dist/components/primitives/BareInput.svelte +3 -1
- package/dist/components/primitives/Button.svelte +6 -2
- package/dist/components/primitives/Checkbox.svelte +5 -0
- package/dist/components/primitives/IconButton.svelte +3 -1
- package/dist/components/primitives/Input.svelte +19 -3
- package/dist/components/primitives/Radio.svelte +4 -1
- package/dist/components/primitives/Range.svelte +3 -1
- package/dist/components/primitives/Rating.svelte +9 -3
- package/dist/components/primitives/Select.svelte +21 -5
- package/dist/components/primitives/Tag.svelte +6 -10
- package/dist/components/primitives/Textarea.svelte +14 -2
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +45 -69
- package/dist/components/scenes/ai/document-download.js +6 -2
- package/dist/components/scenes/ai/document-parse.js +24 -8
- package/dist/components/scenes/ai/document-types.d.ts +0 -12
- package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
- package/dist/components/scenes/ai/highlight.js +3 -1
- package/dist/components/scenes/ai/index.d.ts +1 -1
- package/dist/components/scenes/ai/markdown-parse.js +36 -10
- package/dist/components/scenes/ai/mermaid-render.js +13 -1
- package/dist/components/scenes/ai/safe-html.js +9 -3
- package/dist/components/scenes/ai/table/AiTableEditor.svelte +28 -16
- package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
- package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
- package/dist/components/scenes/app/FeedbackList.svelte +138 -21
- package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
- package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
- package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
- package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
- package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
- package/dist/components/scenes/app/ThemeSelector.svelte +29 -5
- package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
- package/dist/components/scenes/app/WorkspaceLayout.svelte +1 -1
- package/dist/components/scenes/app/feedback-functions.js +6 -2
- package/dist/components/scenes/charts/Chart.svelte +55 -21
- package/dist/components/scenes/charts/Chart.svelte.d.ts +0 -1
- package/dist/components/scenes/charts/ChartLoadError.svelte +13 -0
- package/dist/components/scenes/charts/ChartLoadError.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte +34 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/MetricCard.svelte +69 -0
- package/dist/components/scenes/charts/MetricCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/ReportCard.svelte +48 -0
- package/dist/components/scenes/charts/ReportCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.js +56 -0
- package/dist/components/scenes/charts/chart-types.d.ts +13 -2
- package/dist/components/scenes/charts/dashboard-types.d.ts +79 -0
- package/dist/components/scenes/charts/dashboard-types.js +1 -0
- package/dist/components/scenes/charts/index.d.ts +6 -2
- package/dist/components/scenes/charts/index.js +4 -1
- package/dist/components/scenes/charts/renderers/AreaChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte +39 -12
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +1 -0
- package/dist/components/scenes/code/CodeWorkspace.svelte +946 -0
- package/dist/components/scenes/code/CodeWorkspace.svelte.d.ts +21 -0
- package/dist/components/scenes/code/CodeWorkspaceEditor.svelte +737 -0
- package/dist/components/scenes/code/CodeWorkspaceEditor.svelte.d.ts +37 -0
- package/dist/components/scenes/code/CodeWorkspaceGutter.svelte +246 -0
- package/dist/components/scenes/code/CodeWorkspaceGutter.svelte.d.ts +23 -0
- package/dist/components/scenes/code/CodeWorkspaceSearch.svelte +234 -0
- package/dist/components/scenes/code/CodeWorkspaceSearch.svelte.d.ts +23 -0
- package/dist/components/scenes/code/CodeWorkspaceTree.svelte +519 -0
- package/dist/components/scenes/code/CodeWorkspaceTree.svelte.d.ts +26 -0
- package/dist/components/scenes/code/code-editor.d.ts +12 -0
- package/dist/components/scenes/code/code-editor.js +93 -0
- package/dist/components/scenes/code/code-types.d.ts +346 -0
- package/dist/components/scenes/code/code-types.js +1 -0
- package/dist/components/scenes/code/index.d.ts +2 -0
- package/dist/components/scenes/code/index.js +1 -0
- package/dist/components/scenes/code/workers/css.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/css.worker.js +1 -0
- package/dist/components/scenes/code/workers/editor.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/editor.worker.js +1 -0
- package/dist/components/scenes/code/workers/html.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/html.worker.js +1 -0
- package/dist/components/scenes/code/workers/json.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/json.worker.js +1 -0
- package/dist/components/scenes/code/workers/ts.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/ts.worker.js +1 -0
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
- package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
- package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
- package/dist/components/scenes/crud/CrudPage.svelte +34 -9
- package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
- package/dist/components/scenes/crud/crud-form-validation.js +27 -9
- package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
- package/dist/components/scenes/error/error-presets.js +30 -5
- package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
- package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
- package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
- package/dist/components/scenes/iam/AuthPanel.svelte +74 -16
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
- package/dist/components/scenes/iam/LoginForm.svelte +32 -8
- package/dist/components/scenes/iam/PasswordInput.svelte +50 -12
- package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
- package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
- package/dist/components/scenes/iam/UserProfile.svelte +41 -14
- package/dist/components/scenes/iam/auth-captcha.js +9 -2
- package/dist/components/scenes/iam/auth-error-message.d.ts +2 -2
- package/dist/components/scenes/iam/auth-error-message.js +16 -3
- package/dist/components/scenes/iam/password-utils.js +9 -2
- package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
- package/dist/components/scenes/index.d.ts +1 -0
- package/dist/components/scenes/index.js +2 -0
- package/dist/components/scenes/storage/FileList.svelte +3 -1
- package/dist/components/scenes/storage/FileUpload.svelte +7 -2
- package/dist/components/scenes/types.d.ts +2 -2
- package/dist/guide-storage.js +12 -4
- package/dist/guide.svelte.js +59 -16
- package/dist/i18n.svelte.js +9 -3
- package/dist/internal/dialog-focus.d.ts +19 -0
- package/dist/internal/dialog-focus.js +104 -4
- package/dist/internal/form-validation.svelte.js +46 -15
- package/dist/internal/icon-safety.js +6 -2
- package/dist/message.svelte.js +6 -2
- package/dist/messagebox.svelte.js +6 -2
- package/dist/messages/en-US.json +60 -2
- package/dist/messages/ja-JP.json +60 -2
- package/dist/messages/zh-CN.json +60 -2
- package/dist/styles/eye-care.css +55 -0
- package/dist/styles/global.css +16 -0
- package/dist/styles/theme.css +1 -0
- package/dist/theme-config.d.ts +1 -3
- package/dist/theme-config.js +137 -22
- package/dist/toast.svelte.js +27 -7
- package/dist/types.d.ts +3 -3
- package/dist/utils.js +6 -2
- package/package.json +25 -19
|
@@ -49,7 +49,10 @@
|
|
|
49
49
|
cancelled = false
|
|
50
50
|
try {
|
|
51
51
|
// 必须直接来自点击事件,保留浏览器的用户激活授权。
|
|
52
|
-
const selected = await navigator.mediaDevices.getDisplayMedia({
|
|
52
|
+
const selected = await navigator.mediaDevices.getDisplayMedia({
|
|
53
|
+
video: { width: 1280, height: 720, frameRate: 10 },
|
|
54
|
+
audio: false,
|
|
55
|
+
})
|
|
53
56
|
if (!mounted) {
|
|
54
57
|
selected.getTracks().forEach(track => track.stop())
|
|
55
58
|
return
|
|
@@ -72,7 +75,9 @@
|
|
|
72
75
|
}
|
|
73
76
|
current.onerror = (event) => {
|
|
74
77
|
cancelled = true
|
|
75
|
-
error = errorMessage('error' in event
|
|
78
|
+
error = errorMessage('error' in event
|
|
79
|
+
? event.error
|
|
80
|
+
: new Error('MediaRecorder failed'), uiM('feedback_record_failed'))
|
|
76
81
|
stop(true)
|
|
77
82
|
}
|
|
78
83
|
current.onstart = () => {
|
|
@@ -94,11 +99,15 @@
|
|
|
94
99
|
if (!mounted || cancelled)
|
|
95
100
|
return
|
|
96
101
|
if (!size || size > maxBytes) {
|
|
97
|
-
error = errorMessage(new Error('Recording output was empty or exceeded budget', {
|
|
102
|
+
error = errorMessage(new Error('Recording output was empty or exceeded budget', {
|
|
103
|
+
cause: { size, maxBytes, seconds, mimeType },
|
|
104
|
+
}), uiM('feedback_record_empty'))
|
|
98
105
|
return
|
|
99
106
|
}
|
|
100
107
|
const type = mimeType.split(';')[0]!
|
|
101
|
-
await onrecord(new File(chunks, `recording-${Date.now()}.${type === 'video/mp4'
|
|
108
|
+
await onrecord(new File(chunks, `recording-${Date.now()}.${type === 'video/mp4'
|
|
109
|
+
? 'mp4'
|
|
110
|
+
: 'webm'}`, { type }))
|
|
102
111
|
expanded = false
|
|
103
112
|
}
|
|
104
113
|
catch (cause) {
|
|
@@ -139,7 +148,11 @@
|
|
|
139
148
|
<div class='space-y-2 min-w-0'>
|
|
140
149
|
<Button size='sm' variant='ghost' disabled={disabled || active || busy} onclick={() => expanded = !expanded}>{uiM('feedback_record')}</Button>
|
|
141
150
|
{#if expanded}
|
|
142
|
-
<p class='text-xs text-base-content/65'>{supported
|
|
151
|
+
<p class='text-xs text-base-content/65'>{supported
|
|
152
|
+
? uiM('feedback_record_hint', {
|
|
153
|
+
size: (maxBytes / 1048576).toFixed(1),
|
|
154
|
+
})
|
|
155
|
+
: uiM('feedback_record_unsupported')}</p>
|
|
143
156
|
{#if supported}<Button size='sm' loading={busy} disabled={disabled || active} onclick={start}>{uiM('feedback_record_start')}</Button>{/if}
|
|
144
157
|
{/if}
|
|
145
158
|
</div>
|
|
@@ -38,7 +38,12 @@
|
|
|
38
38
|
return
|
|
39
39
|
const Player = player.constructor as typeof Replayer
|
|
40
40
|
player.destroy()
|
|
41
|
-
player = new Player(events, {
|
|
41
|
+
player = new Player(events, {
|
|
42
|
+
root: target,
|
|
43
|
+
showWarning: false,
|
|
44
|
+
showDebug: false,
|
|
45
|
+
loadTimeout: 1000,
|
|
46
|
+
})
|
|
42
47
|
}
|
|
43
48
|
function seek(value: number) {
|
|
44
49
|
playing = false
|
|
@@ -100,7 +105,12 @@
|
|
|
100
105
|
return
|
|
101
106
|
duration = Math.max(0, events.at(-1)!.timestamp - events[0]!.timestamp)
|
|
102
107
|
snapshotOffset = Math.max(0, snapshot.timestamp - events[0]!.timestamp)
|
|
103
|
-
player = new Player(events, {
|
|
108
|
+
player = new Player(events, {
|
|
109
|
+
root,
|
|
110
|
+
showWarning: false,
|
|
111
|
+
showDebug: false,
|
|
112
|
+
loadTimeout: 1000,
|
|
113
|
+
})
|
|
104
114
|
player.pause(snapshotOffset + 1)
|
|
105
115
|
observer.observe(container)
|
|
106
116
|
}
|
|
@@ -128,7 +138,9 @@
|
|
|
128
138
|
<p class='text-sm text-base-content/65'>{uiM('feedback_replay_hint')}</p>
|
|
129
139
|
{#if loading}<p role='status'>{uiM('feedback_loading')}</p>
|
|
130
140
|
{:else if !player}<p class='rounded bg-base-200 p-4 text-sm'>{uiM('feedback_replay_empty')}</p>{/if}
|
|
131
|
-
<div bind:this={viewport} class='relative w-full overflow-hidden rounded-lg bg-base-200' style:height={player
|
|
141
|
+
<div bind:this={viewport} class='relative w-full overflow-hidden rounded-lg bg-base-200' style:height={player
|
|
142
|
+
? `${height}px`
|
|
143
|
+
: '0'}>
|
|
132
144
|
<div bind:this={target} class='origin-top-left' style:transform={`scale(${scale})`}></div>
|
|
133
145
|
</div>
|
|
134
146
|
{#if player}
|
|
@@ -12,20 +12,30 @@
|
|
|
12
12
|
} = $props()
|
|
13
13
|
|
|
14
14
|
let mode = $state<'mask' | 'outline'>('outline')
|
|
15
|
-
let rect = $state({
|
|
15
|
+
let rect = $state({
|
|
16
|
+
x: 0.1,
|
|
17
|
+
y: 0.1,
|
|
18
|
+
width: 0.2,
|
|
19
|
+
height: 0.2,
|
|
20
|
+
})
|
|
16
21
|
let start = $state<{ x: number, y: number } | null>(null)
|
|
17
22
|
let selected = $state(false)
|
|
18
23
|
let loading = $state(false)
|
|
19
24
|
let error = $state('')
|
|
20
25
|
let imageFailed = $state(false)
|
|
21
|
-
useToastFeedback(() => imageFailed
|
|
26
|
+
useToastFeedback(() => imageFailed
|
|
27
|
+
? uiM('feedback_preview_failed')
|
|
28
|
+
: '', 'warning')
|
|
22
29
|
const url = $derived(imagePreviewUrl(attachment.url))
|
|
23
30
|
|
|
24
31
|
function point(event: PointerEvent & { currentTarget: HTMLDivElement }) {
|
|
25
32
|
const bounds = (event.currentTarget.querySelector('img') ?? event.currentTarget).getBoundingClientRect()
|
|
26
33
|
if (!bounds.width || !bounds.height)
|
|
27
34
|
return { x: 0, y: 0 }
|
|
28
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
x: Math.max(0, Math.min(1, (event.clientX - bounds.left) / bounds.width)),
|
|
37
|
+
y: Math.max(0, Math.min(1, (event.clientY - bounds.top) / bounds.height)),
|
|
38
|
+
}
|
|
29
39
|
}
|
|
30
40
|
function begin(event: PointerEvent & { currentTarget: HTMLDivElement }) {
|
|
31
41
|
if (!onannotate || loading)
|
|
@@ -40,7 +50,12 @@
|
|
|
40
50
|
if (!start)
|
|
41
51
|
return
|
|
42
52
|
const end = point(event)
|
|
43
|
-
rect = {
|
|
53
|
+
rect = {
|
|
54
|
+
x: Math.min(start.x, end.x),
|
|
55
|
+
y: Math.min(start.y, end.y),
|
|
56
|
+
width: Math.abs(end.x - start.x),
|
|
57
|
+
height: Math.abs(end.y - start.y),
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
function keydown(event: KeyboardEvent) {
|
|
46
61
|
if (!onannotate || loading)
|
|
@@ -50,15 +65,37 @@
|
|
|
50
65
|
selected = true
|
|
51
66
|
return
|
|
52
67
|
}
|
|
53
|
-
if (![
|
|
68
|
+
if (![
|
|
69
|
+
'ArrowLeft',
|
|
70
|
+
'ArrowRight',
|
|
71
|
+
'ArrowUp',
|
|
72
|
+
'ArrowDown',
|
|
73
|
+
].includes(event.key)) {
|
|
54
74
|
return
|
|
75
|
+
}
|
|
55
76
|
event.preventDefault()
|
|
56
77
|
selected = true
|
|
57
|
-
const dx = event.key === 'ArrowLeft'
|
|
58
|
-
|
|
78
|
+
const dx = event.key === 'ArrowLeft'
|
|
79
|
+
? -0.01
|
|
80
|
+
: event.key === 'ArrowRight'
|
|
81
|
+
? 0.01
|
|
82
|
+
: 0
|
|
83
|
+
const dy = event.key === 'ArrowUp'
|
|
84
|
+
? -0.01
|
|
85
|
+
: event.key === 'ArrowDown'
|
|
86
|
+
? 0.01
|
|
87
|
+
: 0
|
|
59
88
|
rect = event.shiftKey
|
|
60
|
-
? {
|
|
61
|
-
|
|
89
|
+
? {
|
|
90
|
+
...rect,
|
|
91
|
+
width: Math.max(0.01, Math.min(1 - rect.x, rect.width + dx)),
|
|
92
|
+
height: Math.max(0.01, Math.min(1 - rect.y, rect.height + dy)),
|
|
93
|
+
}
|
|
94
|
+
: {
|
|
95
|
+
...rect,
|
|
96
|
+
x: Math.max(0, Math.min(1 - rect.width, rect.x + dx)),
|
|
97
|
+
y: Math.max(0, Math.min(1 - rect.height, rect.y + dy)),
|
|
98
|
+
}
|
|
62
99
|
}
|
|
63
100
|
function end(event: PointerEvent & { currentTarget: HTMLDivElement }) {
|
|
64
101
|
move(event)
|
|
@@ -74,7 +111,15 @@
|
|
|
74
111
|
loading = true
|
|
75
112
|
error = ''
|
|
76
113
|
try {
|
|
77
|
-
await onannotate({
|
|
114
|
+
await onannotate({
|
|
115
|
+
id: attachment.id,
|
|
116
|
+
mode,
|
|
117
|
+
rect: {
|
|
118
|
+
...rect,
|
|
119
|
+
width: Math.min(rect.width, 1 - rect.x),
|
|
120
|
+
height: Math.min(rect.height, 1 - rect.y),
|
|
121
|
+
},
|
|
122
|
+
})
|
|
78
123
|
selected = false
|
|
79
124
|
}
|
|
80
125
|
catch (cause) {
|
|
@@ -89,7 +134,9 @@
|
|
|
89
134
|
|
|
90
135
|
{#if url}
|
|
91
136
|
<div class='space-y-3 min-w-0'>
|
|
92
|
-
<div class='relative w-fit max-w-full overflow-hidden rounded-lg border border-base-content/10 select-none' role='button' aria-label={attachment.name} aria-disabled={!onannotate} tabindex={onannotate
|
|
137
|
+
<div class='relative w-fit max-w-full overflow-hidden rounded-lg border border-base-content/10 select-none' role='button' aria-label={attachment.name} aria-disabled={!onannotate} tabindex={onannotate
|
|
138
|
+
? 0
|
|
139
|
+
: -1} onkeydown={keydown} style:touch-action={onannotate ? 'none' : 'auto'} onpointerdown={begin} onpointermove={move} onpointerup={end} onpointercancel={cancel}>
|
|
93
140
|
<img src={url} alt={attachment.name} class='block max-w-full h-auto' draggable='false' referrerpolicy='no-referrer' onerror={() => imageFailed = true} onload={() => imageFailed = false} />
|
|
94
141
|
{#if selected}
|
|
95
142
|
<div class:mask-preview={mode === 'mask'} class='pointer-events-none absolute border-2 border-error' style:left={`${rect.x * 100}%`} style:top={`${rect.y * 100}%`} style:width={`${rect.width * 100}%`} style:height={`${rect.height * 100}%`}></div>
|
|
@@ -97,11 +144,15 @@
|
|
|
97
144
|
</div>
|
|
98
145
|
{#if onannotate && !imageFailed}
|
|
99
146
|
<div class='flex flex-wrap gap-2'>
|
|
100
|
-
<Button size='xs' variant={mode === 'outline'
|
|
147
|
+
<Button size='xs' variant={mode === 'outline'
|
|
148
|
+
? 'primary'
|
|
149
|
+
: 'ghost'} onclick={() => {
|
|
101
150
|
mode = 'outline'
|
|
102
151
|
selected = true
|
|
103
152
|
}}>{uiM('feedback_mark_outline')}</Button>
|
|
104
|
-
<Button size='xs' variant={mode === 'mask'
|
|
153
|
+
<Button size='xs' variant={mode === 'mask'
|
|
154
|
+
? 'primary'
|
|
155
|
+
: 'ghost'} onclick={() => {
|
|
105
156
|
mode = 'mask'
|
|
106
157
|
selected = true
|
|
107
158
|
}}>{uiM('feedback_mark_mask')}</Button>
|
|
@@ -108,7 +108,9 @@
|
|
|
108
108
|
})
|
|
109
109
|
</script>
|
|
110
110
|
|
|
111
|
-
<div {...dataAttributes} bind:this={containerRef} class='dropdown {align === 'end'
|
|
111
|
+
<div {...dataAttributes} bind:this={containerRef} class='dropdown {align === 'end'
|
|
112
|
+
? 'dropdown-end'
|
|
113
|
+
: ''} {open ? 'dropdown-open' : ''} {className}'>
|
|
112
114
|
<BareButton
|
|
113
115
|
type='button'
|
|
114
116
|
class='btn btn-ghost {compact ? 'btn-sm btn-square' : 'btn-sm gap-2 min-w-fit'}'
|
|
@@ -134,7 +136,9 @@
|
|
|
134
136
|
{#each languages as lang (lang.value)}
|
|
135
137
|
<BareButton
|
|
136
138
|
type='button'
|
|
137
|
-
class='flex items-center gap-2 w-full px-3 py-2 rounded-lg text-left transition-colors whitespace-nowrap {lang.value === currentLanguage
|
|
139
|
+
class='flex items-center gap-2 w-full px-3 py-2 rounded-lg text-left transition-colors whitespace-nowrap {lang.value === currentLanguage
|
|
140
|
+
? 'bg-primary/10 text-primary'
|
|
141
|
+
: 'hover:bg-base-200'}'
|
|
138
142
|
onclick={() => selectLanguage(lang.value)}
|
|
139
143
|
>
|
|
140
144
|
{#if lang.flag}
|
|
@@ -90,7 +90,9 @@
|
|
|
90
90
|
<nav class='flex gap-1 overflow-x-auto lg:flex-col lg:overflow-visible'>
|
|
91
91
|
{#each sections as section (section.id)}
|
|
92
92
|
{#if section.href}
|
|
93
|
-
<a href={section.href} class={navItemClass(section.id)} aria-current={section.id === active
|
|
93
|
+
<a href={section.href} class={navItemClass(section.id)} aria-current={section.id === active
|
|
94
|
+
? 'page'
|
|
95
|
+
: undefined}>
|
|
94
96
|
{#if section.icon}<span class='{section.icon} size-4 shrink-0'></span>{/if}
|
|
95
97
|
<span class='whitespace-nowrap'>{section.label}</span>
|
|
96
98
|
</a>
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<script lang='ts'>
|
|
21
21
|
import type { ThemeInfo } from '../../../theme-config.js'
|
|
22
22
|
import type { DataAttributes } from '../../../types.js'
|
|
23
|
-
import { tick } from 'svelte'
|
|
23
|
+
import { onMount, tick } from 'svelte'
|
|
24
24
|
import { uiM } from '../../../messages.js'
|
|
25
25
|
import { THEME_GROUPS, THEMES } from '../../../theme-config.js'
|
|
26
26
|
import { cn, getDataAttributes } from '../../../utils.js'
|
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
const displaySelectLabel = $derived(selectLabel ?? uiM('theme_selector_label'))
|
|
69
69
|
const menuId = $props.id()
|
|
70
70
|
|
|
71
|
+
// SSR 先渲染按钮,等客户端绑定点击和键盘事件后再启用。
|
|
72
|
+
let ready = $state(false)
|
|
73
|
+
onMount(() => {
|
|
74
|
+
ready = true
|
|
75
|
+
})
|
|
71
76
|
let open = $state(false)
|
|
72
77
|
let containerRef = $state<HTMLDivElement | null>(null)
|
|
73
78
|
|
|
@@ -95,15 +100,31 @@
|
|
|
95
100
|
const opening = !open
|
|
96
101
|
open = true
|
|
97
102
|
await tick()
|
|
98
|
-
const choices = [
|
|
103
|
+
const choices = [
|
|
104
|
+
...containerRef?.querySelectorAll<HTMLButtonElement>('[data-theme-option]') ?? [],
|
|
105
|
+
]
|
|
99
106
|
const current = choices.findIndex(button => button === document.activeElement)
|
|
100
107
|
const selected = choices.findIndex(button => button.dataset.themeOption === currentTheme)
|
|
101
|
-
const index = event.key === 'Home'
|
|
108
|
+
const index = event.key === 'Home'
|
|
109
|
+
? 0
|
|
110
|
+
: event.key === 'End'
|
|
111
|
+
? choices.length - 1
|
|
112
|
+
: opening
|
|
113
|
+
? Math.max(0, selected)
|
|
114
|
+
: (current + (event.key === 'ArrowDown'
|
|
115
|
+
? 1
|
|
116
|
+
: -1) + choices.length) % choices.length
|
|
102
117
|
choices[index]?.focus()
|
|
103
118
|
}
|
|
104
119
|
|
|
105
120
|
function themeName(theme: ThemeInfo): string {
|
|
106
|
-
return theme.id === 'high-contrast'
|
|
121
|
+
return theme.id === 'high-contrast'
|
|
122
|
+
? uiM('theme_high_contrast')
|
|
123
|
+
: theme.id === 'formal'
|
|
124
|
+
? uiM('theme_formal')
|
|
125
|
+
: theme.id === 'eye-care'
|
|
126
|
+
? uiM('theme_eye_care')
|
|
127
|
+
: theme.name
|
|
107
128
|
}
|
|
108
129
|
|
|
109
130
|
function renderThemePreview(theme: ThemeInfo) {
|
|
@@ -132,9 +153,12 @@
|
|
|
132
153
|
})
|
|
133
154
|
</script>
|
|
134
155
|
|
|
135
|
-
<div {...dataAttributes} bind:this={containerRef} class={cn('dropdown', align === 'end'
|
|
156
|
+
<div {...dataAttributes} bind:this={containerRef} class={cn('dropdown', align === 'end'
|
|
157
|
+
? 'dropdown-end'
|
|
158
|
+
: '', open ? 'dropdown-open' : '', className)}>
|
|
136
159
|
<button
|
|
137
160
|
type='button'
|
|
161
|
+
disabled={!ready}
|
|
138
162
|
class='btn btn-ghost {compact ? 'btn-sm btn-square' : 'gap-2'}'
|
|
139
163
|
onclick={() => (open = !open)}
|
|
140
164
|
onkeydown={handleKeydown}
|
|
@@ -69,12 +69,16 @@
|
|
|
69
69
|
}
|
|
70
70
|
</script>
|
|
71
71
|
|
|
72
|
-
<div {...dataAttributes} class='tooltip tooltip-bottom {className}' data-tip={isDark
|
|
72
|
+
<div {...dataAttributes} class='tooltip tooltip-bottom {className}' data-tip={isDark
|
|
73
|
+
? (labels.switchToLight ?? uiM('theme_switch_to_light'))
|
|
74
|
+
: (labels.switchToDark ?? uiM('theme_switch_to_dark'))}>
|
|
73
75
|
<IconButton
|
|
74
76
|
variant='ghost'
|
|
75
77
|
size='sm'
|
|
76
78
|
onclick={toggleTheme}
|
|
77
|
-
ariaLabel={isDark
|
|
79
|
+
ariaLabel={isDark
|
|
80
|
+
? (labels.switchToLight ?? uiM('theme_switch_to_light'))
|
|
81
|
+
: (labels.switchToDark ?? uiM('theme_switch_to_dark'))}
|
|
78
82
|
>
|
|
79
83
|
{#if isDark}
|
|
80
84
|
<svg xmlns='http://www.w3.org/2000/svg' class='h-5 w-5' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'>
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
{#if actions}<div class='ml-auto flex max-w-full shrink-0 flex-wrap items-center gap-1.5 sm:gap-2'>{@render actions()}</div>{/if}
|
|
58
58
|
</header>
|
|
59
59
|
{/if}
|
|
60
|
-
<main {...dataAttributes} aria-labelledby={title ? headingId : undefined} class='flex min-h-0 min-w-0 flex-1 flex-col overflow-auto p-3 sm:p-4'>
|
|
60
|
+
<main {...dataAttributes} aria-labelledby={title ? headingId : undefined} class='relative flex min-h-0 min-w-0 flex-1 flex-col overflow-auto p-3 sm:p-4'>
|
|
61
61
|
{@render children()}
|
|
62
62
|
</main>
|
|
63
63
|
{#if footer}<footer class='shrink-0 border-t border-base-content/8 px-3 py-1 text-center text-xs text-base-content/45 sm:px-4'>{@render footer()}</footer>{/if}
|
|
@@ -41,7 +41,9 @@ export function notificationLabel(status) {
|
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
43
|
export function feedbackTime(timestamp) {
|
|
44
|
-
return Number.isFinite(timestamp)
|
|
44
|
+
return Number.isFinite(timestamp)
|
|
45
|
+
? new Date(timestamp).toLocaleString(getUILocale())
|
|
46
|
+
: '—';
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* 按本地日历回填日期输入,避免 UTC 转换改变用户选择的日期。
|
|
@@ -72,7 +74,9 @@ export function feedbackDayBoundary(value, boundary) {
|
|
|
72
74
|
return undefined;
|
|
73
75
|
if (boundary === 'end')
|
|
74
76
|
date.setDate(date.getDate() + 1);
|
|
75
|
-
return date.getTime() - (boundary === 'end'
|
|
77
|
+
return date.getTime() - (boundary === 'end'
|
|
78
|
+
? 1
|
|
79
|
+
: 0);
|
|
76
80
|
}
|
|
77
81
|
/**
|
|
78
82
|
* 以文本显示 JSON,不将诊断材料解释为 HTML。
|
|
@@ -20,18 +20,16 @@
|
|
|
20
20
|
-->
|
|
21
21
|
<script lang='ts'>
|
|
22
22
|
import type { ChartProps, ChartSeries, ChartType } from './chart-types.js'
|
|
23
|
+
import { onMount } from 'svelte'
|
|
23
24
|
import { uiM } from '../../../messages.js'
|
|
24
25
|
import { cn, getDataAttributes } from '../../../utils.js'
|
|
26
|
+
import { resolveChartPreset } from './chart-presets.js'
|
|
25
27
|
import { DAISYUI_CHART_COLORS, resolveChartColors } from './chart-theme.js'
|
|
26
|
-
import
|
|
27
|
-
import BarChart from './renderers/BarChart.svelte'
|
|
28
|
-
import LineChart from './renderers/LineChart.svelte'
|
|
29
|
-
import PieChart from './renderers/PieChart.svelte'
|
|
30
|
-
import ScatterChart from './renderers/ScatterChart.svelte'
|
|
31
|
-
import 'layerchart/daisyui-5.css'
|
|
28
|
+
import ChartLoadError from './ChartLoadError.svelte'
|
|
32
29
|
|
|
33
30
|
const {
|
|
34
|
-
type,
|
|
31
|
+
type: requestedType,
|
|
32
|
+
preset,
|
|
35
33
|
data = [],
|
|
36
34
|
x,
|
|
37
35
|
y,
|
|
@@ -46,8 +44,27 @@
|
|
|
46
44
|
...restProps
|
|
47
45
|
}: ChartProps = $props()
|
|
48
46
|
|
|
47
|
+
const presetConfig = $derived(resolveChartPreset(preset))
|
|
48
|
+
const type = $derived(requestedType ?? presetConfig.type ?? 'line')
|
|
49
|
+
const nativeProps = $derived({
|
|
50
|
+
...presetConfig.props,
|
|
51
|
+
...restProps,
|
|
52
|
+
})
|
|
49
53
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
50
54
|
|
|
55
|
+
// 仅浏览器挂载且确有数据时加载对应图形;Svelte await 自动丢弃过期 Promise 的结果。
|
|
56
|
+
const renderers = {
|
|
57
|
+
bar: () => import('./renderers/BarChart.svelte'),
|
|
58
|
+
line: () => import('./renderers/LineChart.svelte'),
|
|
59
|
+
area: () => import('./renderers/AreaChart.svelte'),
|
|
60
|
+
pie: () => import('./renderers/PieChart.svelte'),
|
|
61
|
+
scatter: () => import('./renderers/ScatterChart.svelte'),
|
|
62
|
+
}
|
|
63
|
+
let mounted = $state(false)
|
|
64
|
+
onMount(() => {
|
|
65
|
+
mounted = true
|
|
66
|
+
})
|
|
67
|
+
|
|
51
68
|
const chartSizeHeights: Record<NonNullable<ChartProps['size']>, number> = {
|
|
52
69
|
sm: 200,
|
|
53
70
|
md: 300,
|
|
@@ -58,10 +75,15 @@
|
|
|
58
75
|
|
|
59
76
|
/** 图表可视高度优先尊重 LayerChart 原生 height,未传时使用 @h-ai/ui 的 size 预设。 */
|
|
60
77
|
const chartHeight = $derived(
|
|
61
|
-
typeof
|
|
78
|
+
typeof nativeProps.height === 'number'
|
|
79
|
+
? nativeProps.height
|
|
80
|
+
: chartSizeHeights[size],
|
|
62
81
|
)
|
|
63
82
|
|
|
64
83
|
const isEmpty = $derived(empty || data.length === 0)
|
|
84
|
+
const rendererPromise = $derived(mounted && !loading && !isEmpty
|
|
85
|
+
? renderers[type]()
|
|
86
|
+
: undefined)
|
|
65
87
|
const hasHeader = $derived(Boolean(title || description))
|
|
66
88
|
|
|
67
89
|
const rootClass = $derived(
|
|
@@ -106,13 +128,15 @@
|
|
|
106
128
|
const resolvedSeries = $derived(resolveChartColors(normalizedSeries))
|
|
107
129
|
|
|
108
130
|
/** 饼图使用统一 x/y API 时,将 x 映射为 key/label,y 的第一项映射为 value。 */
|
|
109
|
-
const pieValue = $derived(Array.isArray(y)
|
|
131
|
+
const pieValue = $derived(Array.isArray(y)
|
|
132
|
+
? y[0]
|
|
133
|
+
: y)
|
|
110
134
|
|
|
111
135
|
const cartesianLayerProps = $derived({
|
|
112
136
|
data,
|
|
113
137
|
height: chartHeight,
|
|
114
138
|
cRange: DAISYUI_CHART_COLORS,
|
|
115
|
-
...
|
|
139
|
+
...nativeProps,
|
|
116
140
|
orientation,
|
|
117
141
|
series: resolvedSeries,
|
|
118
142
|
x,
|
|
@@ -126,7 +150,7 @@
|
|
|
126
150
|
label: x,
|
|
127
151
|
value: pieValue,
|
|
128
152
|
cRange: DAISYUI_CHART_COLORS,
|
|
129
|
-
...
|
|
153
|
+
...nativeProps,
|
|
130
154
|
series: resolvedSeries,
|
|
131
155
|
})
|
|
132
156
|
</script>
|
|
@@ -148,16 +172,26 @@
|
|
|
148
172
|
<span class='loading loading-spinner loading-md text-primary' aria-label={uiM('chart_loading')}></span>
|
|
149
173
|
{:else if isEmpty}
|
|
150
174
|
<p class='text-sm text-base-content/50'>{uiM('chart_empty')}</p>
|
|
151
|
-
{:else if
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
{:else
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
175
|
+
{:else if !mounted}
|
|
176
|
+
<div class='flex h-full items-center justify-center' role='status' aria-label={uiM('chart_loading')}>
|
|
177
|
+
<span class='loading loading-spinner loading-md text-primary'></span>
|
|
178
|
+
</div>
|
|
179
|
+
{:else}
|
|
180
|
+
{#await rendererPromise}
|
|
181
|
+
<div class='flex h-full items-center justify-center' role='status' aria-label={uiM('chart_loading')}>
|
|
182
|
+
<span class='loading loading-spinner loading-md text-primary'></span>
|
|
183
|
+
</div>
|
|
184
|
+
{:then renderer}
|
|
185
|
+
{#if renderer}
|
|
186
|
+
{@const Renderer = renderer.default}
|
|
187
|
+
<Renderer {...(type === 'pie'
|
|
188
|
+
? pieLayerProps
|
|
189
|
+
: cartesianLayerProps)} />
|
|
190
|
+
{/if}
|
|
191
|
+
{:catch}
|
|
192
|
+
<!-- 浏览器可能缓存失败的模块请求;刷新文档后才能可靠重试同一资源。 -->
|
|
193
|
+
<ChartLoadError onretry={() => window.location.reload()} />
|
|
194
|
+
{/await}
|
|
161
195
|
{/if}
|
|
162
196
|
</div>
|
|
163
197
|
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- 图形模块加载失败时使用统一 Toast,原位保留重试操作。 -->
|
|
2
|
+
<script lang='ts'>
|
|
3
|
+
import { uiM } from '../../../messages.js'
|
|
4
|
+
import { useToastFeedback } from '../../../toast.svelte.js'
|
|
5
|
+
import Button from '../../primitives/Button.svelte'
|
|
6
|
+
/** 重试由 Chart 重新创建本次动态导入。 */
|
|
7
|
+
const { onretry }: { onretry: () => void } = $props()
|
|
8
|
+
useToastFeedback(() => uiM('chart_load_failed'))
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<div class='flex h-full items-center justify-center'>
|
|
12
|
+
<Button onclick={onretry} size='sm'>{uiM('chart_retry')}</Button>
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component DashboardGrid
|
|
3
|
+
使用容器查询适配看板,不依赖视口宽度或图形引擎。
|
|
4
|
+
@example
|
|
5
|
+
```ts
|
|
6
|
+
import { mount, unmount } from 'svelte'
|
|
7
|
+
import { DashboardGrid } from '@h-ai/ui'
|
|
8
|
+
const component = mount(DashboardGrid, { target: document.body, props: { label: 'Reports', columns: 2 } })
|
|
9
|
+
await unmount(component)
|
|
10
|
+
```
|
|
11
|
+
-->
|
|
12
|
+
<script lang='ts'>
|
|
13
|
+
import type { DashboardGridProps } from './dashboard-types.js'
|
|
14
|
+
import { cn, getDataAttributes } from '../../../utils.js'
|
|
15
|
+
|
|
16
|
+
const { label, columns = 2, children, class: className = '', ...restProps }: DashboardGridProps = $props()
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div {...getDataAttributes(restProps)} role='group' aria-label={label} class={cn('hai-dashboard-grid min-w-0', className)} style={`--hai-dashboard-columns: ${columns}; --hai-dashboard-medium-columns: ${Math.min(columns, 2)};`}>
|
|
20
|
+
<div class='hai-dashboard-grid__items'>
|
|
21
|
+
{#if children}{@render children()}{/if}
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<style>
|
|
26
|
+
.hai-dashboard-grid { container: hai-dashboard / inline-size; }
|
|
27
|
+
.hai-dashboard-grid__items { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
|
|
28
|
+
@container hai-dashboard (min-width: 40rem) {
|
|
29
|
+
.hai-dashboard-grid__items { grid-template-columns: repeat(var(--hai-dashboard-medium-columns), minmax(0, 1fr)); }
|
|
30
|
+
}
|
|
31
|
+
@container hai-dashboard (min-width: 64rem) {
|
|
32
|
+
.hai-dashboard-grid__items { grid-template-columns: repeat(var(--hai-dashboard-columns), minmax(0, 1fr)); }
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DashboardGridProps } from './dashboard-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* DashboardGrid
|
|
4
|
+
* 使用容器查询适配看板,不依赖视口宽度或图形引擎。
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { mount, unmount } from 'svelte'
|
|
8
|
+
* import { DashboardGrid } from '@h-ai/ui'
|
|
9
|
+
* const component = mount(DashboardGrid, { target: document.body, props: { label: 'Reports', columns: 2 } })
|
|
10
|
+
* await unmount(component)
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
declare const DashboardGrid: import("svelte").Component<DashboardGridProps, {}, "">;
|
|
14
|
+
type DashboardGrid = ReturnType<typeof DashboardGrid>;
|
|
15
|
+
export default DashboardGrid;
|