@h-ai/ui 0.1.0-alpha.75 → 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 +10 -13
- package/README.ja.md +10 -13
- package/README.md +10 -13
- package/dist/components/compounds/Alert.svelte +2 -2
- package/dist/components/compounds/Alert.svelte.d.ts +1 -1
- package/dist/components/compounds/ToastContainer.svelte +96 -42
- package/dist/components/compounds/ToastContainer.svelte.d.ts +1 -1
- package/dist/components/scenes/app/FeedbackForm.svelte +5 -7
- package/dist/components/scenes/iam/AuthPanel.svelte +5 -3
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +1 -1
- package/dist/toast.svelte.d.ts +7 -6
- package/dist/toast.svelte.js +23 -23
- package/dist/types.d.ts +2 -2
- package/package.json +7 -2
package/README.en.md
CHANGED
|
@@ -483,24 +483,21 @@ Defaults match `@h-ai/crypto`: `SM4` for encrypted inputs, `SM3` for hashes, and
|
|
|
483
483
|
<ToastContainer />
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
+
Toasts float at the bottom right by default without shifting layout, using UI-owned semantic colors for information, success, warning and error, with a soft tinted background, a narrow color border, a distinct icon and a subtle shadow. They can be dismissed manually. Notifications share one FIFO queue and appear one at a time; each timer starts when its notification is shown (3 seconds by default, `duration: 0` waits for dismissal). Mount `<ToastContainer />` once in the root layout. Set a position with `toast.add({ message: m.saved(), variant: 'success', position: 'bottom-center' })`, where `m.saved()` is an application translation. Positions: `bottom-right` (default), `top-right`, `bottom-center`, `top-center`, `bottom-left`, `top-left`. Use Toast for save/copy results. Keep field validation, persistent business status and recovery actions inline; `Alert` uses a soft background.
|
|
487
|
+
|
|
486
488
|
> Built-in `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` remove the need for application toast wrappers. `notifyError(err, fallback?)` accepts `Error` or strings with a fallback message. Success lasts 3s and errors 5s by default.
|
|
487
489
|
|
|
488
|
-
|
|
490
|
+
State modules can import `toast`, `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` and `errorMessage` from the lightweight `@h-ai/ui/toast` entry without loading components or tour CSS. Import `ToastContainer` from a component entry and mount it in the root layout.
|
|
489
491
|
|
|
490
|
-
|
|
491
|
-
<script>
|
|
492
|
-
import { message, MessageContainer } from '@h-ai/ui'
|
|
492
|
+
#### Choosing a Toast position
|
|
493
493
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
message.info('提示信息', 5000)
|
|
499
|
-
}
|
|
500
|
-
</script>
|
|
494
|
+
The application provides the `m.saved()` translation below. Notifications at different positions still share one queue and appear in order.
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
import { toast } from '@h-ai/ui/toast'
|
|
501
498
|
|
|
502
|
-
|
|
503
|
-
|
|
499
|
+
toast.add({ message: m.saved(), variant: 'success', position: 'top-right' })
|
|
500
|
+
toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
504
501
|
```
|
|
505
502
|
|
|
506
503
|
#### Typical CRUD page
|
package/README.ja.md
CHANGED
|
@@ -483,24 +483,21 @@ components/
|
|
|
483
483
|
<ToastContainer />
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
+
通知は既定で右下に浮かび、ページのレイアウトを変えません。UI モジュールのテーマ色でお知らせ・成功・警告・エラーを区別し、淡い背景、細い色枠、種類別アイコンと控えめな影を使用し、手動で閉じられます。複数の通知は共通の FIFO キューから 1 件ずつ表示され、表示開始から計時します(既定 3 秒、`duration: 0` は手動で閉じるまで保持)。ルートに `<ToastContainer />` を 1 回だけ配置します。`toast.add({ message: m.saved(), variant: 'success', position: 'bottom-center' })` で位置を指定できます。`m.saved()` はアプリの翻訳関数です。位置は `bottom-right`(既定)、`top-right`、`bottom-center`、`top-center`、`bottom-left`、`top-left`。保存やコピーの結果は Toast、フィールド検証や継続的な業務状態、復旧操作はインラインで表示します。`Alert` は淡い背景を使用します。
|
|
487
|
+
|
|
486
488
|
> `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` を内蔵し、アプリ独自の toast ツールは不要です。`notifyError(err, fallback?)` は `Error`・文字列と代替文言を受け付け、既定は成功 3 秒・失敗 5 秒です。
|
|
487
489
|
|
|
488
|
-
|
|
490
|
+
状態層は軽量な `@h-ai/ui/toast` から `toast`、`notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning`、`errorMessage` を読み込めます。コンポーネントやガイド CSS は読み込みません。`ToastContainer` はコンポーネントの入口から読み込み、ルートに配置します。
|
|
489
491
|
|
|
490
|
-
|
|
491
|
-
<script>
|
|
492
|
-
import { message, MessageContainer } from '@h-ai/ui'
|
|
492
|
+
#### 通知の位置を指定する
|
|
493
493
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
message.info('提示信息', 5000)
|
|
499
|
-
}
|
|
500
|
-
</script>
|
|
494
|
+
以下の `m.saved()` はアプリの翻訳関数です。異なる位置の通知も共通のキューから順番に表示されます。
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
import { toast } from '@h-ai/ui/toast'
|
|
501
498
|
|
|
502
|
-
|
|
503
|
-
|
|
499
|
+
toast.add({ message: m.saved(), variant: 'success', position: 'top-right' })
|
|
500
|
+
toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
504
501
|
```
|
|
505
502
|
|
|
506
503
|
#### 標準的な CRUD ページ
|
package/README.md
CHANGED
|
@@ -482,24 +482,21 @@ components/
|
|
|
482
482
|
<ToastContainer />
|
|
483
483
|
```
|
|
484
484
|
|
|
485
|
+
默认在右下角浮动显示,不占页面布局;由 UI 模块统一使用提示蓝、成功绿、警告黄、错误红等主题语义色,以浅色底、细色边和对应图标区分,并保留轻阴影,支持手工关闭。多个提示进入同一 FIFO 队列,逐条展示,每条从展示时开始计时(默认 3 秒,`duration: 0` 等待手工关闭)。根布局只挂载一次 `<ToastContainer />`。用 `toast.add({ message: m.saved(), variant: 'success', position: 'bottom-center' })` 指定方位;`m.saved()` 是应用自身的翻译函数。可选 `bottom-right`(默认)、`top-right`、`bottom-center`、`top-center`、`bottom-left`、`top-left`。保存、复制等操作结果使用 Toast;字段校验、持续业务状态和恢复操作保留行内,`Alert` 使用柔和背景。
|
|
486
|
+
|
|
485
487
|
> 已内置 `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` 封装,业务应用无需自建 toast 工具文件:`notifyError(err, fallback?)` 接受 `Error` 或字符串并内置兑底文案,默认成功 3s / 失败 5s。
|
|
486
488
|
|
|
487
|
-
|
|
489
|
+
状态层可从轻量入口 `@h-ai/ui/toast` 导入 `toast`、`notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` 和 `errorMessage`,不会连带加载组件及引导 CSS;`ToastContainer` 仍从组件入口导入并在根布局挂载。
|
|
488
490
|
|
|
489
|
-
|
|
490
|
-
<script>
|
|
491
|
-
import { message, MessageContainer } from '@h-ai/ui'
|
|
491
|
+
#### 指定提示方位
|
|
492
492
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
message.info('提示信息', 5000)
|
|
498
|
-
}
|
|
499
|
-
</script>
|
|
493
|
+
下例 `m.saved()` 由应用自己的 i18n 提供;不同方位也共用同一个队列,按顺序展示。
|
|
494
|
+
|
|
495
|
+
```ts
|
|
496
|
+
import { toast } from '@h-ai/ui/toast'
|
|
500
497
|
|
|
501
|
-
|
|
502
|
-
|
|
498
|
+
toast.add({ message: m.saved(), variant: 'success', position: 'top-right' })
|
|
499
|
+
toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
503
500
|
```
|
|
504
501
|
|
|
505
502
|
#### 典型 CRUD 页面
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { mount, unmount, createRawSnippet } from 'svelte'
|
|
8
8
|
import type { ComponentProps } from 'svelte'
|
|
9
9
|
import { Alert } from '@h-ai/ui'
|
|
10
|
-
const props: ComponentProps<typeof Alert> = { title: '
|
|
10
|
+
const props: ComponentProps<typeof Alert> = { title: '服务状态', variant: 'info', children: createRawSnippet(() => ({ render: () => "<span>系统将于今晚进行维护。</span>" })) }
|
|
11
11
|
const component = mount(Alert, { target: document.body, props })
|
|
12
12
|
await unmount(component)
|
|
13
13
|
```
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
const alertClass = $derived(
|
|
35
35
|
cn(
|
|
36
|
-
'alert',
|
|
36
|
+
'alert alert-soft shadow-none',
|
|
37
37
|
'flex items-start gap-3',
|
|
38
38
|
getAlertVariantClass(variant),
|
|
39
39
|
className,
|
|
@@ -9,7 +9,7 @@ type $$ComponentProps = AlertProps & DataAttributes;
|
|
|
9
9
|
* import { mount, unmount, createRawSnippet } from 'svelte'
|
|
10
10
|
* import type { ComponentProps } from 'svelte'
|
|
11
11
|
* import { Alert } from '@h-ai/ui'
|
|
12
|
-
* const props: ComponentProps<typeof Alert> = { title: '
|
|
12
|
+
* const props: ComponentProps<typeof Alert> = { title: '服务状态', variant: 'info', children: createRawSnippet(() => ({ render: () => "<span>系统将于今晚进行维护。</span>" })) }
|
|
13
13
|
* const component = mount(Alert, { target: document.body, props })
|
|
14
14
|
* await unmount(component)
|
|
15
15
|
* ```
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
=============================================================================
|
|
4
4
|
@h-ai/ui - ToastContainer 组件
|
|
5
5
|
=============================================================================
|
|
6
|
-
|
|
6
|
+
浮动操作提示容器,按先后顺序逐条显示,不占用页面布局。
|
|
7
7
|
|
|
8
8
|
使用 Svelte 5 Runes ($derived / $effect)
|
|
9
9
|
|
|
@@ -29,19 +29,17 @@
|
|
|
29
29
|
import { onMount } from 'svelte'
|
|
30
30
|
import { uiM } from '../../messages.js'
|
|
31
31
|
import { toast } from '../../toast.svelte.js'
|
|
32
|
-
import { cn,
|
|
32
|
+
import { cn, getDataAttributes } from '../../utils.js'
|
|
33
33
|
import IconButton from '../primitives/IconButton.svelte'
|
|
34
34
|
|
|
35
35
|
const { ...restProps }: DataAttributes = $props()
|
|
36
36
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
37
37
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
'top-center': 'toast-top toast-center',
|
|
44
|
-
'bottom-center': 'toast-bottom toast-center',
|
|
38
|
+
const iconMap = {
|
|
39
|
+
info: 'icon-[tabler--info-circle] text-info',
|
|
40
|
+
success: 'icon-[tabler--circle-check] text-success',
|
|
41
|
+
warning: 'icon-[tabler--alert-triangle] text-warning',
|
|
42
|
+
error: 'icon-[tabler--circle-x] text-error',
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
// 容器根元素引用。
|
|
@@ -49,20 +47,7 @@
|
|
|
49
47
|
|
|
50
48
|
const hasItems = $derived(toast.items.length > 0)
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
const groupedItems = $derived(() => {
|
|
54
|
-
const groups: Record<string, typeof toast.items> = {}
|
|
55
|
-
|
|
56
|
-
for (const item of toast.items) {
|
|
57
|
-
const position = item.position ?? 'top-right'
|
|
58
|
-
if (!groups[position]) {
|
|
59
|
-
groups[position] = []
|
|
60
|
-
}
|
|
61
|
-
groups[position].push(item)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return groups
|
|
65
|
-
})
|
|
50
|
+
const currentItems = $derived(toast.items.slice(0, 1))
|
|
66
51
|
|
|
67
52
|
/** 找到最顶层处于打开状态的原生 modal dialog(位于浏览器 top layer)。 */
|
|
68
53
|
function findTopModalDialog(): HTMLDialogElement | null {
|
|
@@ -166,23 +151,23 @@
|
|
|
166
151
|
</script>
|
|
167
152
|
|
|
168
153
|
<div {...dataAttributes} bind:this={layerElement} popover='manual' class='hai-toast-layer'>
|
|
169
|
-
{#each
|
|
170
|
-
<div class=
|
|
171
|
-
{
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
154
|
+
{#each currentItems as item (item.id)}
|
|
155
|
+
<div class='hai-toast-position' data-position={item.position ?? 'bottom-right'}>
|
|
156
|
+
<div {...getDataAttributes(item)} class='hai-toast-item text-base-content' role={item.variant === 'error' ? 'alert' : 'status'} aria-live={item.variant === 'error' ? 'assertive' : 'polite'} aria-atomic='true' data-variant={item.variant ?? 'info'}>
|
|
157
|
+
<span aria-hidden='true' class={cn('size-5 shrink-0', iconMap[item.variant as keyof typeof iconMap] ?? iconMap.info)}></span>
|
|
158
|
+
<span class='hai-toast-message'>{item.message}</span>
|
|
159
|
+
{#if item.dismissible}
|
|
160
|
+
<IconButton
|
|
161
|
+
variant='ghost'
|
|
162
|
+
size='sm'
|
|
163
|
+
class='shrink-0 text-base-content/45'
|
|
164
|
+
onclick={() => toast.remove(item.id)}
|
|
165
|
+
ariaLabel={uiM('toast_dismiss')}
|
|
166
|
+
>
|
|
167
|
+
✕
|
|
168
|
+
</IconButton>
|
|
169
|
+
{/if}
|
|
170
|
+
</div>
|
|
186
171
|
</div>
|
|
187
172
|
{/each}
|
|
188
173
|
</div>
|
|
@@ -202,12 +187,81 @@
|
|
|
202
187
|
background: transparent;
|
|
203
188
|
overflow: visible;
|
|
204
189
|
pointer-events: none;
|
|
190
|
+
z-index: var(--hai-z-toast, 1200);
|
|
205
191
|
}
|
|
206
192
|
|
|
207
|
-
/* 未支持 Popover API 的浏览器忽略 popover
|
|
193
|
+
/* 未支持 Popover API 的浏览器忽略 popover 属性,容器仍保持固定定位;
|
|
208
194
|
此时无 toast 项则内部不渲染任何内容,容器透明且不拦截交互。 */
|
|
209
195
|
|
|
210
|
-
.hai-toast-
|
|
196
|
+
.hai-toast-position {
|
|
197
|
+
position: absolute;
|
|
198
|
+
width: min(24rem, calc(100% - 2rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
|
|
199
|
+
right: max(1rem, env(safe-area-inset-right, 0px));
|
|
200
|
+
bottom: max(1rem, env(safe-area-inset-bottom, 0px));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.hai-toast-position[data-position^='top-'] {
|
|
204
|
+
top: max(1rem, env(safe-area-inset-top, 0px));
|
|
205
|
+
bottom: auto;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.hai-toast-position[data-position$='-left'] {
|
|
209
|
+
left: max(1rem, env(safe-area-inset-left, 0px));
|
|
210
|
+
right: auto;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.hai-toast-position[data-position$='-center'] {
|
|
214
|
+
left: 50%;
|
|
215
|
+
right: auto;
|
|
216
|
+
transform: translateX(-50%);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.hai-toast-item {
|
|
220
|
+
--hai-toast-accent: var(--color-info);
|
|
221
|
+
display: flex;
|
|
222
|
+
align-items: center;
|
|
223
|
+
gap: 0.75rem;
|
|
224
|
+
padding: 0.75rem 1rem;
|
|
225
|
+
border-width: 1px;
|
|
226
|
+
border-style: solid;
|
|
227
|
+
border-color: color-mix(in oklab, var(--hai-toast-accent) 20%, var(--color-base-100));
|
|
228
|
+
border-inline-start: 3px solid var(--hai-toast-accent);
|
|
229
|
+
background: color-mix(in oklab, var(--hai-toast-accent) 5%, var(--color-base-100));
|
|
230
|
+
border-radius: var(--hai-radius-md, 8px);
|
|
231
|
+
box-shadow: 0 4px 18px oklch(0 0 0 / 0.08);
|
|
211
232
|
pointer-events: auto;
|
|
233
|
+
animation: hai-toast-enter 150ms ease-out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.hai-toast-item[data-variant='success'] {
|
|
237
|
+
--hai-toast-accent: var(--color-success);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.hai-toast-item[data-variant='warning'] {
|
|
241
|
+
--hai-toast-accent: var(--color-warning);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.hai-toast-item[data-variant='error'] {
|
|
245
|
+
--hai-toast-accent: var(--color-error);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.hai-toast-message {
|
|
249
|
+
flex: 1;
|
|
250
|
+
min-width: 0;
|
|
251
|
+
max-height: min(20rem, 60dvh);
|
|
252
|
+
overflow: auto;
|
|
253
|
+
overflow-wrap: anywhere;
|
|
254
|
+
white-space: pre-wrap;
|
|
255
|
+
font-size: 0.875rem;
|
|
256
|
+
line-height: 1.5;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@keyframes hai-toast-enter {
|
|
260
|
+
from { opacity: 0; transform: translateY(0.25rem); }
|
|
261
|
+
to { opacity: 1; transform: translateY(0); }
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@media (prefers-reduced-motion: reduce) {
|
|
265
|
+
.hai-toast-item { animation: none; }
|
|
212
266
|
}
|
|
213
267
|
</style>
|
|
@@ -4,7 +4,7 @@ import type { DataAttributes } from '../../types.js';
|
|
|
4
4
|
* =============================================================================
|
|
5
5
|
* @h-ai/ui - ToastContainer 组件
|
|
6
6
|
* =============================================================================
|
|
7
|
-
*
|
|
7
|
+
* 浮动操作提示容器,按先后顺序逐条显示,不占用页面布局。
|
|
8
8
|
*
|
|
9
9
|
* 使用 Svelte 5 Runes ($derived / $effect)
|
|
10
10
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import type { FeedbackAnnotation, FeedbackAttachmentView, FeedbackEvidenceSummary, FeedbackEvidenceView, FeedbackFormData, FeedbackReceipt } from './feedback-types.js'
|
|
14
14
|
import { untrack } from 'svelte'
|
|
15
15
|
import { uiM } from '../../../messages.js'
|
|
16
|
-
import { errorMessage } from '../../../toast.svelte.js'
|
|
16
|
+
import { errorMessage, toast } from '../../../toast.svelte.js'
|
|
17
17
|
import { getDataAttributes } from '../../../utils.js'
|
|
18
18
|
import FormField from '../../compounds/FormField.svelte'
|
|
19
19
|
import FormLayout from '../../compounds/FormLayout.svelte'
|
|
@@ -110,7 +110,6 @@
|
|
|
110
110
|
let filesError = $state(false)
|
|
111
111
|
let exporting = $state(false)
|
|
112
112
|
let recording = $state(false)
|
|
113
|
-
let exported = $state(false)
|
|
114
113
|
let expandedMaterials = $state<string[]>([])
|
|
115
114
|
let error = $state('')
|
|
116
115
|
let previousKey = $state(untrack(() => resetKey))
|
|
@@ -141,7 +140,6 @@
|
|
|
141
140
|
filesError = false
|
|
142
141
|
removedAttachmentIds = []
|
|
143
142
|
receipt = undefined
|
|
144
|
-
exported = false
|
|
145
143
|
error = ''
|
|
146
144
|
}
|
|
147
145
|
})
|
|
@@ -181,7 +179,8 @@
|
|
|
181
179
|
exporting = true
|
|
182
180
|
error = ''
|
|
183
181
|
try {
|
|
184
|
-
|
|
182
|
+
if (await onexport(values()) !== false)
|
|
183
|
+
toast.info(uiM('feedback_local_saved'))
|
|
185
184
|
}
|
|
186
185
|
catch (cause) {
|
|
187
186
|
error = errorMessage(cause, uiM('feedback_action_failed'))
|
|
@@ -252,7 +251,7 @@
|
|
|
252
251
|
{/if}
|
|
253
252
|
{#if error}<div class='alert alert-error break-words' role='alert'>{error}</div>{/if}
|
|
254
253
|
{#if receipt}
|
|
255
|
-
<div role='status' class='alert alert-success block space-y-2 break-words'>
|
|
254
|
+
<div role='status' class='alert alert-soft alert-success shadow-none block space-y-2 break-words'>
|
|
256
255
|
<p class='font-medium'>{uiM('feedback_accepted', { number: receipt.number })}</p>
|
|
257
256
|
<p>{collectionLabel(receipt.collectionStatus)}</p>
|
|
258
257
|
<p class='text-sm'>{uiM('feedback_accepted_hint')}</p>
|
|
@@ -268,7 +267,7 @@
|
|
|
268
267
|
{#if oncapture}<Button size='sm' variant='outline' disabled={loading || annotating || staging || exporting} onclick={() => oncapture()}>{uiM('feedback_capture_add')}</Button>{/if}
|
|
269
268
|
<label class='btn btn-sm btn-ghost focus-within:outline focus-within:outline-primary'>
|
|
270
269
|
{uiM('feedback_add_files')}
|
|
271
|
-
<BareInput id={`${instanceId}-files`} type='file'
|
|
270
|
+
<BareInput id={`${instanceId}-files`} type='file' accept='.png,.jpg,.jpeg,.webp,.webm,.mp4,.txt,.log,.json,.pdf,.zip,.gz,.tgz,image/png,image/jpeg,image/webp,video/webm,video/mp4,text/plain,application/json,application/pdf,application/zip,application/gzip' multiple disabled={loading || staging || exporting} class='sr-only' onchange={selectFiles} />
|
|
272
271
|
</label>
|
|
273
272
|
{#if onfileschange}<FeedbackRecorder maxBytes={recordingBytes} disabled={loading || annotating || staging || exporting || attachmentLimitReached} onactive={recordingChanged} onrecord={recorded} />{/if}
|
|
274
273
|
</div>
|
|
@@ -328,7 +327,6 @@
|
|
|
328
327
|
</details>
|
|
329
328
|
{/if}
|
|
330
329
|
{/if}
|
|
331
|
-
{#if exported}<p class='text-sm text-success' role='status'>{uiM('feedback_local_saved')}</p>{/if}
|
|
332
330
|
</div>
|
|
333
331
|
<div class='shrink-0 flex flex-wrap justify-end gap-2 border-t border-base-content/10 bg-base-100 pt-4 pb-2'>
|
|
334
332
|
{#if onexport}<Button variant='ghost' loading={exporting} disabled={annotating || staging} onclick={saveLocal}>{uiM('feedback_local_export')}</Button>{/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}
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
<form data-testid='sensitive-operations-form' {...dataAttributes} class='space-y-4' onsubmit={save}>
|
|
63
63
|
<label class='block space-y-2 text-sm font-medium'>
|
|
64
64
|
<span>{uiM('sensitive_operations_label')}</span>
|
|
65
|
-
<Textarea bind:value rows={6} disabled={loading}
|
|
65
|
+
<Textarea bind:value rows={6} disabled={loading} />
|
|
66
66
|
</label>
|
|
67
67
|
<p class='text-sm text-base-content/60'>{uiM('sensitive_operations_hint')}</p>
|
|
68
68
|
{#if error}<p role='alert' class='text-sm text-error'>{error}</p>{/if}
|
package/dist/toast.svelte.d.ts
CHANGED
|
@@ -22,8 +22,9 @@ export interface ToastItem extends ToastProps {
|
|
|
22
22
|
*/
|
|
23
23
|
declare class ToastState {
|
|
24
24
|
items: ToastItem[];
|
|
25
|
-
/**
|
|
26
|
-
private
|
|
25
|
+
/** 仅队首计时,等待项在展示后才开始计算停留时间。 */
|
|
26
|
+
private timer;
|
|
27
|
+
private startTimer;
|
|
27
28
|
/**
|
|
28
29
|
* 添加 Toast
|
|
29
30
|
* @param props - 组件的属性对象。
|
|
@@ -133,7 +134,7 @@ declare class ToastState {
|
|
|
133
134
|
*/
|
|
134
135
|
export declare const toast: ToastState;
|
|
135
136
|
/**
|
|
136
|
-
*
|
|
137
|
+
* 弹出操作成功提示(默认右下角)。
|
|
137
138
|
*
|
|
138
139
|
* @description 统一封装 toast 单例,业务应用无需自建 toast 工具文件即可获得一致的成功反馈。
|
|
139
140
|
*
|
|
@@ -150,7 +151,7 @@ export declare const toast: ToastState;
|
|
|
150
151
|
*/
|
|
151
152
|
export declare function notifySuccess(message: string, duration?: number): string;
|
|
152
153
|
/**
|
|
153
|
-
*
|
|
154
|
+
* 弹出操作失败提示(默认右下角)。
|
|
154
155
|
*
|
|
155
156
|
* @description 接受 `Error` 或字符串;`Error` 取其 message,其余回退到 fallback,
|
|
156
157
|
* 避免各业务页面重复实现错误文案兜底逻辑。
|
|
@@ -178,7 +179,7 @@ export declare function notifyError(error: unknown, fallback?: string, duration?
|
|
|
178
179
|
*/
|
|
179
180
|
export declare function errorMessage(error: unknown, fallback?: string): string;
|
|
180
181
|
/**
|
|
181
|
-
*
|
|
182
|
+
* 弹出信息提示(默认右下角)。
|
|
182
183
|
*
|
|
183
184
|
* @param message - 用户可见文案(已本地化)。
|
|
184
185
|
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
@@ -193,7 +194,7 @@ export declare function errorMessage(error: unknown, fallback?: string): string;
|
|
|
193
194
|
*/
|
|
194
195
|
export declare function notifyInfo(message: string, duration?: number): string;
|
|
195
196
|
/**
|
|
196
|
-
*
|
|
197
|
+
* 弹出警告提示(默认右下角)。
|
|
197
198
|
*
|
|
198
199
|
* @param message - 用户可见文案(已本地化)。
|
|
199
200
|
* @param duration - 可选停留时长(毫秒),默认 5000。
|
package/dist/toast.svelte.js
CHANGED
|
@@ -10,8 +10,14 @@ import { core } from '@h-ai/core';
|
|
|
10
10
|
*/
|
|
11
11
|
class ToastState {
|
|
12
12
|
items = $state([]);
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/** 仅队首计时,等待项在展示后才开始计算停留时间。 */
|
|
14
|
+
timer;
|
|
15
|
+
startTimer() {
|
|
16
|
+
const item = this.items[0];
|
|
17
|
+
if (item && (item.duration ?? 0) > 0) {
|
|
18
|
+
this.timer = setTimeout(() => this.remove(item.id), item.duration);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
15
21
|
/**
|
|
16
22
|
* 添加 Toast
|
|
17
23
|
* @param props - 组件的属性对象。
|
|
@@ -30,18 +36,12 @@ class ToastState {
|
|
|
30
36
|
...props,
|
|
31
37
|
id,
|
|
32
38
|
duration: props.duration ?? 3000,
|
|
33
|
-
position: props.position ?? '
|
|
39
|
+
position: props.position ?? 'bottom-right',
|
|
34
40
|
dismissible: props.dismissible ?? true,
|
|
35
41
|
};
|
|
36
42
|
this.items = [...this.items, item];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const timer = setTimeout(() => {
|
|
40
|
-
this.timers.delete(id);
|
|
41
|
-
this.remove(id);
|
|
42
|
-
}, item.duration);
|
|
43
|
-
this.timers.set(id, timer);
|
|
44
|
-
}
|
|
43
|
+
if (this.items.length === 1)
|
|
44
|
+
this.startTimer();
|
|
45
45
|
return id;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
@@ -57,12 +57,14 @@ class ToastState {
|
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
59
|
remove(id) {
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
clearTimeout(timer);
|
|
63
|
-
this.
|
|
60
|
+
const isCurrent = this.items[0]?.id === id;
|
|
61
|
+
if (isCurrent) {
|
|
62
|
+
clearTimeout(this.timer);
|
|
63
|
+
this.timer = undefined;
|
|
64
64
|
}
|
|
65
65
|
this.items = this.items.filter(item => item.id !== id);
|
|
66
|
+
if (isCurrent)
|
|
67
|
+
this.startTimer();
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
70
|
* 清空所有 Toast
|
|
@@ -76,10 +78,8 @@ class ToastState {
|
|
|
76
78
|
* ```
|
|
77
79
|
*/
|
|
78
80
|
clear() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
this.timers.clear();
|
|
81
|
+
clearTimeout(this.timer);
|
|
82
|
+
this.timer = undefined;
|
|
83
83
|
this.items = [];
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
@@ -165,7 +165,7 @@ const SUCCESS_DURATION = 3000;
|
|
|
165
165
|
/** 失败提示默认停留时长(毫秒),比成功略长便于阅读错误信息。 */
|
|
166
166
|
const ERROR_DURATION = 5000;
|
|
167
167
|
/**
|
|
168
|
-
*
|
|
168
|
+
* 弹出操作成功提示(默认右下角)。
|
|
169
169
|
*
|
|
170
170
|
* @description 统一封装 toast 单例,业务应用无需自建 toast 工具文件即可获得一致的成功反馈。
|
|
171
171
|
*
|
|
@@ -184,7 +184,7 @@ export function notifySuccess(message, duration = SUCCESS_DURATION) {
|
|
|
184
184
|
return toast.success(message, duration);
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
187
|
+
* 弹出操作失败提示(默认右下角)。
|
|
188
188
|
*
|
|
189
189
|
* @description 接受 `Error` 或字符串;`Error` 取其 message,其余回退到 fallback,
|
|
190
190
|
* 避免各业务页面重复实现错误文案兜底逻辑。
|
|
@@ -228,7 +228,7 @@ export function errorMessage(error, fallback = '') {
|
|
|
228
228
|
return core.error.formatMessage({ message, traceId: /\(traceId: [\w.:-]{1,128}\)$/.test(message) ? undefined : traceId });
|
|
229
229
|
}
|
|
230
230
|
/**
|
|
231
|
-
*
|
|
231
|
+
* 弹出信息提示(默认右下角)。
|
|
232
232
|
*
|
|
233
233
|
* @param message - 用户可见文案(已本地化)。
|
|
234
234
|
* @param duration - 可选停留时长(毫秒),默认 3000。
|
|
@@ -245,7 +245,7 @@ export function notifyInfo(message, duration = SUCCESS_DURATION) {
|
|
|
245
245
|
return toast.info(message, duration);
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
248
|
-
*
|
|
248
|
+
* 弹出警告提示(默认右下角)。
|
|
249
249
|
*
|
|
250
250
|
* @param message - 用户可见文案(已本地化)。
|
|
251
251
|
* @param duration - 可选停留时长(毫秒),默认 5000。
|
package/dist/types.d.ts
CHANGED
|
@@ -854,9 +854,9 @@ export interface ToastProps extends DataAttributes {
|
|
|
854
854
|
message: string;
|
|
855
855
|
/** 变体 */
|
|
856
856
|
variant?: Variant;
|
|
857
|
-
/**
|
|
857
|
+
/** 展示后的持续时间 (ms),默认 3000;排队等待不计时,0 为不自动关闭 */
|
|
858
858
|
duration?: number;
|
|
859
|
-
/**
|
|
859
|
+
/** 浮动位置,默认 bottom-right;多个提示按加入顺序逐条显示 */
|
|
860
860
|
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
861
861
|
/** 是否可关闭 */
|
|
862
862
|
dismissible?: boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-ai/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.0-alpha.
|
|
4
|
+
"version": "0.1.0-alpha.76",
|
|
5
5
|
"description": "Hai Framework UI component library for Svelte 5 Runes.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"svelte": "./dist/index.js",
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
"svelte": "./dist/i18n.svelte.js",
|
|
25
25
|
"import": "./dist/i18n.svelte.js"
|
|
26
26
|
},
|
|
27
|
+
"./toast": {
|
|
28
|
+
"types": "./dist/toast.svelte.d.ts",
|
|
29
|
+
"svelte": "./dist/toast.svelte.js",
|
|
30
|
+
"import": "./dist/toast.svelte.js"
|
|
31
|
+
},
|
|
27
32
|
"./theme": {
|
|
28
33
|
"types": "./dist/theme-config.d.ts",
|
|
29
34
|
"import": "./dist/theme-config.js"
|
|
@@ -119,7 +124,7 @@
|
|
|
119
124
|
"svelte": "^5.57.2"
|
|
120
125
|
},
|
|
121
126
|
"dependencies": {
|
|
122
|
-
"@h-ai/core": "0.1.0-alpha.
|
|
127
|
+
"@h-ai/core": "0.1.0-alpha.76",
|
|
123
128
|
"@internationalized/date": "^3.12.4",
|
|
124
129
|
"@rrweb/replay": "^2.1.7",
|
|
125
130
|
"@shikijs/langs": "^4.5.0",
|