@h-ai/ui 1.0.0-beta.18 → 1.0.0-beta.19
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 +30 -27
- package/README.ja.md +30 -27
- package/README.md +30 -27
- package/auto-import.js +118 -53
- package/dist/components/compounds/Accordion.svelte +6 -2
- package/dist/components/compounds/BottomNav.svelte +6 -2
- package/dist/components/compounds/Card.svelte +3 -1
- package/dist/components/compounds/Combobox.svelte +24 -6
- 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 +9 -2
- 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 +28 -3
- package/dist/components/compounds/Steps.svelte +6 -2
- package/dist/components/compounds/SwipeCell.svelte +3 -1
- package/dist/components/compounds/TableToolbar.svelte +32 -9
- package/dist/components/compounds/Tabs.svelte +15 -5
- package/dist/components/compounds/Timeline.svelte +6 -2
- package/dist/components/compounds/ToastContainer.svelte +27 -7
- 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/IconButton.svelte +3 -1
- package/dist/components/primitives/Input.svelte +18 -2
- package/dist/components/primitives/Radio.svelte +3 -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/Textarea.svelte +14 -2
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +40 -12
- 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/editor-markdown-extensions.js +9 -3
- package/dist/components/scenes/ai/highlight.js +3 -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 +27 -9
- 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 +22 -4
- package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
- package/dist/components/scenes/app/feedback-functions.js +6 -2
- package/dist/components/scenes/charts/Chart.svelte +16 -5
- package/dist/components/scenes/charts/MetricCard.svelte +21 -4
- package/dist/components/scenes/charts/chart-presets.js +42 -5
- package/dist/components/scenes/charts/renderers/LineChart.svelte +38 -12
- 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 +73 -15
- 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 +49 -11
- 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.js +11 -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/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/theme-config.js +135 -21
- package/dist/toast.svelte.js +14 -3
- package/dist/utils.js +6 -2
- package/package.json +19 -19
|
@@ -66,7 +66,9 @@
|
|
|
66
66
|
|
|
67
67
|
// 格式化日期
|
|
68
68
|
function formatDate(date: Date | string): string {
|
|
69
|
-
const d = typeof date === 'string'
|
|
69
|
+
const d = typeof date === 'string'
|
|
70
|
+
? new Date(date)
|
|
71
|
+
: date
|
|
70
72
|
return d.toLocaleDateString(getUILocale(), {
|
|
71
73
|
year: 'numeric',
|
|
72
74
|
month: '2-digit',
|
|
@@ -135,7 +135,9 @@
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
function abortAllActiveRequests(): void {
|
|
138
|
-
for (const fileId of [
|
|
138
|
+
for (const fileId of [
|
|
139
|
+
...activeRequests.keys(),
|
|
140
|
+
]) {
|
|
139
141
|
abortActiveRequest(fileId)
|
|
140
142
|
}
|
|
141
143
|
}
|
|
@@ -199,7 +201,10 @@
|
|
|
199
201
|
newFiles.push(uploadFile)
|
|
200
202
|
}
|
|
201
203
|
|
|
202
|
-
files = [
|
|
204
|
+
files = [
|
|
205
|
+
...files,
|
|
206
|
+
...newFiles,
|
|
207
|
+
]
|
|
203
208
|
onchange?.(files)
|
|
204
209
|
|
|
205
210
|
// 自动上传
|
|
@@ -694,8 +694,8 @@ export interface UserProfileProps extends FormLayoutOptions, DataAttributes {
|
|
|
694
694
|
class?: string;
|
|
695
695
|
/** 错误信息 */
|
|
696
696
|
errors?: Record<string, string>;
|
|
697
|
-
/**
|
|
698
|
-
onsubmit?: (data: UserProfileSubmitData) =>
|
|
697
|
+
/** 保存事件;只有 true 表示成功并退出编辑,false 保留编辑器与草稿。 */
|
|
698
|
+
onsubmit?: (data: UserProfileSubmitData) => boolean | Promise<boolean>;
|
|
699
699
|
/** 头像变更事件 */
|
|
700
700
|
onavatarchange?: (file: File) => void | Promise<void>;
|
|
701
701
|
}
|
package/dist/guide-storage.js
CHANGED
|
@@ -24,7 +24,9 @@ export function createGuideStorage(options) {
|
|
|
24
24
|
if (persistence === 'cookie' && typeof document !== 'undefined') {
|
|
25
25
|
const prefix = `${encodeURIComponent(key)}=`;
|
|
26
26
|
const value = document.cookie.split('; ').find(item => item.startsWith(prefix));
|
|
27
|
-
return value
|
|
27
|
+
return value
|
|
28
|
+
? decodeURIComponent(value.slice(prefix.length))
|
|
29
|
+
: memory.get(key) ?? null;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
catch {
|
|
@@ -45,8 +47,12 @@ export function createGuideStorage(options) {
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
else if (persistence === 'cookie' && typeof document !== 'undefined') {
|
|
48
|
-
const secure = globalThis.location?.protocol === 'https:'
|
|
49
|
-
|
|
50
|
+
const secure = globalThis.location?.protocol === 'https:'
|
|
51
|
+
? '; Secure'
|
|
52
|
+
: '';
|
|
53
|
+
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value ?? '')}; Path=/; SameSite=Lax; Max-Age=${value === null
|
|
54
|
+
? '0'
|
|
55
|
+
: '31536000'}${secure}`;
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
catch {
|
|
@@ -73,7 +79,9 @@ export function createGuideStorage(options) {
|
|
|
73
79
|
return null;
|
|
74
80
|
},
|
|
75
81
|
set(key, progress) {
|
|
76
|
-
write(key, progress
|
|
82
|
+
write(key, progress
|
|
83
|
+
? JSON.stringify(progress)
|
|
84
|
+
: null);
|
|
77
85
|
},
|
|
78
86
|
};
|
|
79
87
|
}
|
package/dist/guide.svelte.js
CHANGED
|
@@ -17,7 +17,9 @@ let stopActiveGuide;
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export function resolveGuideText(text) {
|
|
20
|
-
return typeof text === 'function'
|
|
20
|
+
return typeof text === 'function'
|
|
21
|
+
? text()
|
|
22
|
+
: text ?? '';
|
|
21
23
|
}
|
|
22
24
|
function escapeGuideText(text) {
|
|
23
25
|
return resolveGuideText(text).replace(/[&<>"']/g, character => ({
|
|
@@ -32,11 +34,15 @@ function findTarget(step) {
|
|
|
32
34
|
try {
|
|
33
35
|
const element = typeof step.target === 'function'
|
|
34
36
|
? step.target()
|
|
35
|
-
: [
|
|
37
|
+
: [
|
|
38
|
+
...document.querySelectorAll('[data-guide]'),
|
|
39
|
+
].find(item => item.getAttribute('data-guide') === step.target);
|
|
36
40
|
if (!element?.isConnected || !element.getClientRects().length || element.closest('[hidden], [aria-hidden="true"]'))
|
|
37
41
|
return null;
|
|
38
42
|
const style = getComputedStyle(element);
|
|
39
|
-
return style.visibility === 'hidden' || style.display === 'none'
|
|
43
|
+
return style.visibility === 'hidden' || style.display === 'none'
|
|
44
|
+
? null
|
|
45
|
+
: element;
|
|
40
46
|
}
|
|
41
47
|
catch {
|
|
42
48
|
return null;
|
|
@@ -64,7 +70,9 @@ function waitForTarget(step, signal, timeout, ready) {
|
|
|
64
70
|
return;
|
|
65
71
|
}
|
|
66
72
|
try {
|
|
67
|
-
const element = ready()
|
|
73
|
+
const element = ready()
|
|
74
|
+
? findTarget(step)
|
|
75
|
+
: null;
|
|
68
76
|
if (element)
|
|
69
77
|
finish(element);
|
|
70
78
|
}
|
|
@@ -77,7 +85,9 @@ function waitForTarget(step, signal, timeout, ready) {
|
|
|
77
85
|
return;
|
|
78
86
|
}
|
|
79
87
|
try {
|
|
80
|
-
const initial = ready()
|
|
88
|
+
const initial = ready()
|
|
89
|
+
? findTarget(step)
|
|
90
|
+
: null;
|
|
81
91
|
if (initial) {
|
|
82
92
|
finish(initial);
|
|
83
93
|
return;
|
|
@@ -170,7 +180,11 @@ export function createGuide(options) {
|
|
|
170
180
|
focusBefore = null;
|
|
171
181
|
}
|
|
172
182
|
function mark(tour, status) {
|
|
173
|
-
storage.set(progressKey(tour.id), {
|
|
183
|
+
storage.set(progressKey(tour.id), {
|
|
184
|
+
version: tour.version ?? 1,
|
|
185
|
+
status,
|
|
186
|
+
updatedAt: Date.now(),
|
|
187
|
+
});
|
|
174
188
|
}
|
|
175
189
|
function getProgress(id) {
|
|
176
190
|
return storage.get(progressKey(id));
|
|
@@ -215,7 +229,9 @@ export function createGuide(options) {
|
|
|
215
229
|
activeTourId = id;
|
|
216
230
|
busy = true;
|
|
217
231
|
stopActiveGuide = stop;
|
|
218
|
-
focusBefore = document.activeElement instanceof HTMLElement
|
|
232
|
+
focusBefore = document.activeElement instanceof HTMLElement
|
|
233
|
+
? document.activeElement
|
|
234
|
+
: null;
|
|
219
235
|
const requiredSeen = new SvelteSet();
|
|
220
236
|
let finishHighlight;
|
|
221
237
|
function hasPreviousStep(index = driver?.getActiveIndex() ?? 0) {
|
|
@@ -254,7 +270,10 @@ export function createGuide(options) {
|
|
|
254
270
|
}
|
|
255
271
|
requiredSeen.add(index);
|
|
256
272
|
activeElement = element;
|
|
257
|
-
driver?.setConfig({
|
|
273
|
+
driver?.setConfig({
|
|
274
|
+
...driver.getConfig(),
|
|
275
|
+
...translatedConfig(tour),
|
|
276
|
+
});
|
|
258
277
|
// 等到引擎完成首帧定位后再报告启动成功,键盘此时已可操作。
|
|
259
278
|
await new Promise((resolve) => {
|
|
260
279
|
const finished = () => {
|
|
@@ -313,7 +332,12 @@ export function createGuide(options) {
|
|
|
313
332
|
expectedPath = tour.route.split('?')[0];
|
|
314
333
|
navigating = true;
|
|
315
334
|
try {
|
|
316
|
-
sessionStorage.setItem(pendingKey, JSON.stringify({
|
|
335
|
+
sessionStorage.setItem(pendingKey, JSON.stringify({
|
|
336
|
+
id,
|
|
337
|
+
scope,
|
|
338
|
+
route: expectedPath,
|
|
339
|
+
createdAt: Date.now(),
|
|
340
|
+
}));
|
|
317
341
|
}
|
|
318
342
|
catch {
|
|
319
343
|
// Cookie 或 WebView 存储限制不阻止客户端导航。
|
|
@@ -368,7 +392,9 @@ export function createGuide(options) {
|
|
|
368
392
|
const step = tour.steps[index];
|
|
369
393
|
popover.title.textContent = resolveGuideText(step?.title);
|
|
370
394
|
popover.description.textContent = resolveGuideText(step?.description);
|
|
371
|
-
popover.nextButton.textContent = msg(index === tour.steps.length - 1
|
|
395
|
+
popover.nextButton.textContent = msg(index === tour.steps.length - 1
|
|
396
|
+
? 'guide_done'
|
|
397
|
+
: 'guide_next');
|
|
372
398
|
popover.previousButton.textContent = msg('guide_previous');
|
|
373
399
|
popover.progress.textContent = uiM('guide_progress', { current: index + 1, total: tour.steps.length }, locale);
|
|
374
400
|
popover.nextButton.disabled = busy;
|
|
@@ -405,10 +431,18 @@ export function createGuide(options) {
|
|
|
405
431
|
return {
|
|
406
432
|
get tours() { return options.tours.filter(tour => !tour.enabled || tour.enabled()); },
|
|
407
433
|
get articles() { return (options.articles ?? []).filter(article => !article.enabled || article.enabled()); },
|
|
408
|
-
get offeredTour() {
|
|
434
|
+
get offeredTour() {
|
|
435
|
+
return offeredId
|
|
436
|
+
? tourFor(offeredId)
|
|
437
|
+
: undefined;
|
|
438
|
+
},
|
|
409
439
|
get activeTourId() { return activeTourId; },
|
|
410
440
|
get busy() { return busy; },
|
|
411
|
-
get error() {
|
|
441
|
+
get error() {
|
|
442
|
+
return error
|
|
443
|
+
? msg(error)
|
|
444
|
+
: '';
|
|
445
|
+
},
|
|
412
446
|
get locale() { return locale; },
|
|
413
447
|
get pathname() { return nav.pathname; },
|
|
414
448
|
get helpOpen() { return helpOpen; },
|
|
@@ -427,13 +461,17 @@ export function createGuide(options) {
|
|
|
427
461
|
return true;
|
|
428
462
|
},
|
|
429
463
|
defer() {
|
|
430
|
-
const tour = offeredId
|
|
464
|
+
const tour = offeredId
|
|
465
|
+
? tourFor(offeredId)
|
|
466
|
+
: undefined;
|
|
431
467
|
if (tour)
|
|
432
468
|
mark(tour, 'deferred');
|
|
433
469
|
offeredId = null;
|
|
434
470
|
},
|
|
435
471
|
dismiss() {
|
|
436
|
-
const tour = offeredId
|
|
472
|
+
const tour = offeredId
|
|
473
|
+
? tourFor(offeredId)
|
|
474
|
+
: undefined;
|
|
437
475
|
if (tour)
|
|
438
476
|
mark(tour, 'dismissed');
|
|
439
477
|
offeredId = null;
|
|
@@ -452,10 +490,15 @@ export function createGuide(options) {
|
|
|
452
490
|
clearError() { error = ''; },
|
|
453
491
|
setLocale(value) {
|
|
454
492
|
locale = value;
|
|
455
|
-
const tour = activeTourId
|
|
493
|
+
const tour = activeTourId
|
|
494
|
+
? tourFor(activeTourId)
|
|
495
|
+
: undefined;
|
|
456
496
|
if (driver && tour) {
|
|
457
497
|
try {
|
|
458
|
-
driver.setConfig({
|
|
498
|
+
driver.setConfig({
|
|
499
|
+
...driver.getConfig(),
|
|
500
|
+
...translatedConfig(tour),
|
|
501
|
+
});
|
|
459
502
|
driver.drive(driver.getActiveIndex() ?? 0);
|
|
460
503
|
}
|
|
461
504
|
catch {
|
package/dist/i18n.svelte.js
CHANGED
|
@@ -23,7 +23,9 @@ function matchSupportedLocale(locale, supportedLocales) {
|
|
|
23
23
|
if (variant)
|
|
24
24
|
return variant.code;
|
|
25
25
|
const separator = candidate.lastIndexOf('-');
|
|
26
|
-
candidate = separator < 0
|
|
26
|
+
candidate = separator < 0
|
|
27
|
+
? ''
|
|
28
|
+
: candidate.slice(0, separator);
|
|
27
29
|
}
|
|
28
30
|
return null;
|
|
29
31
|
}
|
|
@@ -99,7 +101,9 @@ function detectBrowserLocale(supportedLocales = DEFAULT_LOCALES) {
|
|
|
99
101
|
function interpolate(template, params = {}) {
|
|
100
102
|
return template.replace(/\{(\w+)\}/g, (_, key) => {
|
|
101
103
|
const value = params[key];
|
|
102
|
-
return value !== undefined
|
|
104
|
+
return value !== undefined
|
|
105
|
+
? String(value)
|
|
106
|
+
: `{${key}}`;
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
// ─── LocalStorage Key ───
|
|
@@ -130,7 +134,9 @@ export function createLocaleStore(options = {}) {
|
|
|
130
134
|
if (typeof window !== 'undefined') {
|
|
131
135
|
// 1. 优先从 localStorage 读取
|
|
132
136
|
const savedLocale = readStoredValue(persistKey);
|
|
133
|
-
const supportedSavedLocale = savedLocale
|
|
137
|
+
const supportedSavedLocale = savedLocale
|
|
138
|
+
? matchSupportedLocale(savedLocale, supportedLocales)
|
|
139
|
+
: null;
|
|
134
140
|
if (supportedSavedLocale) {
|
|
135
141
|
initialLocale = supportedSavedLocale;
|
|
136
142
|
}
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从触发位置找到所属模态框;嵌套 portal 沿已登记的所属关系查找。
|
|
3
|
+
* @example 模块内部上下文
|
|
4
|
+
* ```ts
|
|
5
|
+
* function owner(anchor: HTMLElement) { return findDialogOwner(anchor) }
|
|
6
|
+
* ```
|
|
7
|
+
*/
|
|
8
|
+
export declare function findDialogOwner(anchor: HTMLElement): HTMLElement | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* 将 portal 纳入所属弹窗的 Tab 顺序,关闭或卸载时撤销登记。
|
|
11
|
+
* @example 模块内部上下文
|
|
12
|
+
* ```ts
|
|
13
|
+
* function connect(anchor: HTMLElement, popup: HTMLElement) {
|
|
14
|
+
* const unregister = registerDialogPortal(anchor, popup)
|
|
15
|
+
* unregister()
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function registerDialogPortal(anchor: HTMLElement, portal: HTMLElement): () => void;
|
|
1
20
|
/**
|
|
2
21
|
* 打开后优先聚焦可编辑字段,清理时取消首帧校准并恢复触发控件。
|
|
3
22
|
* @example 模块内部上下文
|
|
@@ -1,8 +1,77 @@
|
|
|
1
|
+
/** 弹窗拥有的 portal 分支及其原始触发位置,不改变浏览器的全局焦点。 */
|
|
2
|
+
const portalBranches = new WeakMap();
|
|
3
|
+
const portalOwners = new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* 从触发位置找到所属模态框;嵌套 portal 沿已登记的所属关系查找。
|
|
6
|
+
* @example 模块内部上下文
|
|
7
|
+
* ```ts
|
|
8
|
+
* function owner(anchor: HTMLElement) { return findDialogOwner(anchor) }
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export function findDialogOwner(anchor) {
|
|
12
|
+
const direct = anchor.closest('[role="dialog"][aria-modal="true"]');
|
|
13
|
+
if (direct)
|
|
14
|
+
return direct;
|
|
15
|
+
for (let node = anchor; node; node = node.parentElement) {
|
|
16
|
+
const owner = portalOwners.get(node);
|
|
17
|
+
if (owner)
|
|
18
|
+
return owner;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 将 portal 纳入所属弹窗的 Tab 顺序,关闭或卸载时撤销登记。
|
|
24
|
+
* @example 模块内部上下文
|
|
25
|
+
* ```ts
|
|
26
|
+
* function connect(anchor: HTMLElement, popup: HTMLElement) {
|
|
27
|
+
* const unregister = registerDialogPortal(anchor, popup)
|
|
28
|
+
* unregister()
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function registerDialogPortal(anchor, portal) {
|
|
33
|
+
const owner = findDialogOwner(anchor);
|
|
34
|
+
if (!owner)
|
|
35
|
+
return () => { };
|
|
36
|
+
const branches = portalBranches.get(owner) ?? new Map();
|
|
37
|
+
portalBranches.set(owner, branches);
|
|
38
|
+
branches.set(portal, anchor);
|
|
39
|
+
portalOwners.set(portal, owner);
|
|
40
|
+
return () => {
|
|
41
|
+
branches.delete(portal);
|
|
42
|
+
portalOwners.delete(portal);
|
|
43
|
+
if (!branches.size)
|
|
44
|
+
portalBranches.delete(owner);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
1
47
|
/** 弹窗和抽屉共享可见、可操作的焦点边界。 */
|
|
2
|
-
function
|
|
3
|
-
return [
|
|
48
|
+
function localFocusable(panel) {
|
|
49
|
+
return [
|
|
50
|
+
...panel.querySelectorAll('button, a[href], input:not([type="hidden"]), select, textarea, [tabindex]'),
|
|
51
|
+
]
|
|
4
52
|
.filter(element => element.tabIndex >= 0 && !element.matches(':disabled') && element.getClientRects().length > 0);
|
|
5
53
|
}
|
|
54
|
+
/** 从虚拟焦点序列尾部查找触发器,兼容组件库的 ES2022 目标。 */
|
|
55
|
+
function lastAnchorIndex(elements, anchor) {
|
|
56
|
+
for (let index = elements.length - 1; index >= 0; index--) {
|
|
57
|
+
const element = elements[index];
|
|
58
|
+
if (element === anchor || anchor.contains(element))
|
|
59
|
+
return index;
|
|
60
|
+
}
|
|
61
|
+
return -1;
|
|
62
|
+
}
|
|
63
|
+
/** portal 的控件在触发器之后参与阅读顺序,不把它们放到整个文档末尾。 */
|
|
64
|
+
function focusable(panel) {
|
|
65
|
+
const elements = localFocusable(panel);
|
|
66
|
+
for (const [portal, anchor] of portalBranches.get(panel) ?? []) {
|
|
67
|
+
if (!portal.isConnected)
|
|
68
|
+
continue;
|
|
69
|
+
const index = lastAnchorIndex(elements, anchor);
|
|
70
|
+
if (index >= 0)
|
|
71
|
+
elements.splice(index + 1, 0, ...localFocusable(portal));
|
|
72
|
+
}
|
|
73
|
+
return elements;
|
|
74
|
+
}
|
|
6
75
|
/**
|
|
7
76
|
* 打开后优先聚焦可编辑字段,清理时取消首帧校准并恢复触发控件。
|
|
8
77
|
* @example 模块内部上下文
|
|
@@ -14,7 +83,9 @@ function focusable(panel) {
|
|
|
14
83
|
* ```
|
|
15
84
|
*/
|
|
16
85
|
export function focusDialog(panel) {
|
|
17
|
-
const previous = document.activeElement instanceof HTMLElement
|
|
86
|
+
const previous = document.activeElement instanceof HTMLElement
|
|
87
|
+
? document.activeElement
|
|
88
|
+
: null;
|
|
18
89
|
function preferred() {
|
|
19
90
|
const elements = focusable(panel);
|
|
20
91
|
return elements.find(element => element.matches('input:not([readonly]), textarea, select, [role="combobox"]')) ?? elements[0] ?? panel;
|
|
@@ -31,7 +102,9 @@ export function focusDialog(panel) {
|
|
|
31
102
|
alignFocus();
|
|
32
103
|
}
|
|
33
104
|
panel.addEventListener('transitionend', onTransition);
|
|
34
|
-
const frame = typeof requestAnimationFrame === 'function'
|
|
105
|
+
const frame = typeof requestAnimationFrame === 'function'
|
|
106
|
+
? requestAnimationFrame(alignFocus)
|
|
107
|
+
: undefined;
|
|
35
108
|
return () => {
|
|
36
109
|
panel.removeEventListener('transitionend', onTransition);
|
|
37
110
|
if (frame !== undefined)
|
|
@@ -61,10 +134,37 @@ export function handleDialogKeydown(event, panel, close) {
|
|
|
61
134
|
const elements = focusable(panel);
|
|
62
135
|
const first = elements[0];
|
|
63
136
|
const last = elements.at(-1);
|
|
137
|
+
const active = document.activeElement;
|
|
138
|
+
let index = elements.findIndex(element => element === active);
|
|
139
|
+
const registrations = [
|
|
140
|
+
...(portalBranches.get(panel)?.entries() ?? []),
|
|
141
|
+
];
|
|
142
|
+
const focusedBranch = registrations.find(([branch]) => branch.contains(active));
|
|
143
|
+
if (index < 0 && focusedBranch) {
|
|
144
|
+
const [branch, anchor] = focusedBranch;
|
|
145
|
+
const children = localFocusable(branch);
|
|
146
|
+
const anchorIndex = lastAnchorIndex(elements, anchor);
|
|
147
|
+
index = event.shiftKey
|
|
148
|
+
? children.length
|
|
149
|
+
? elements.indexOf(children[0])
|
|
150
|
+
: anchorIndex + 1
|
|
151
|
+
: anchorIndex;
|
|
152
|
+
}
|
|
153
|
+
const next = index >= 0
|
|
154
|
+
? elements[(index + (event.shiftKey
|
|
155
|
+
? -1
|
|
156
|
+
: 1) + elements.length) % elements.length]
|
|
157
|
+
: undefined;
|
|
158
|
+
const branches = registrations.map(([branch]) => branch);
|
|
159
|
+
const crossesPortal = next && branches.some(branch => branch.contains(active) || branch.contains(next));
|
|
64
160
|
if (!first) {
|
|
65
161
|
event.preventDefault();
|
|
66
162
|
panel.focus();
|
|
67
163
|
}
|
|
164
|
+
else if (next && crossesPortal) {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
next.focus();
|
|
167
|
+
}
|
|
68
168
|
else if (event.shiftKey && (document.activeElement === first || document.activeElement === panel)) {
|
|
69
169
|
event.preventDefault();
|
|
70
170
|
last?.focus();
|
|
@@ -20,7 +20,9 @@ export function useControlFeedback(message, label) {
|
|
|
20
20
|
if (!value || field?.error || visibility?.open === false)
|
|
21
21
|
return '';
|
|
22
22
|
const name = label?.() || field?.label;
|
|
23
|
-
return name
|
|
23
|
+
return name
|
|
24
|
+
? uiM('form_field_error', { label: name, message: value })
|
|
25
|
+
: value;
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
@@ -46,21 +48,46 @@ function readIssue(control) {
|
|
|
46
48
|
const validity = control.validity;
|
|
47
49
|
if (validity.valueMissing)
|
|
48
50
|
return { key: 'form_required' };
|
|
49
|
-
if (validity.typeMismatch)
|
|
50
|
-
return {
|
|
51
|
+
if (validity.typeMismatch) {
|
|
52
|
+
return {
|
|
53
|
+
key: control.getAttribute('type') === 'email'
|
|
54
|
+
? 'form_email'
|
|
55
|
+
: 'form_url',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
51
58
|
// 程序回填的值也需校验长度,原生 tooShort/tooLong 只覆盖用户输入。
|
|
52
59
|
const minLength = control.getAttribute('minlength');
|
|
53
60
|
const maxLength = control.getAttribute('maxlength');
|
|
54
|
-
if (validity.tooShort || (control.value && minLength !== null && control.value.length < Number(minLength)))
|
|
55
|
-
return {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (validity.
|
|
61
|
-
return {
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
if (validity.tooShort || (control.value && minLength !== null && control.value.length < Number(minLength))) {
|
|
62
|
+
return {
|
|
63
|
+
key: 'form_min_length',
|
|
64
|
+
params: { min: control.getAttribute('minlength') ?? '' },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (validity.tooLong || (control.value && maxLength !== null && control.value.length > Number(maxLength))) {
|
|
68
|
+
return {
|
|
69
|
+
key: 'form_max_length',
|
|
70
|
+
params: { max: control.getAttribute('maxlength') ?? '' },
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (validity.rangeUnderflow) {
|
|
74
|
+
return {
|
|
75
|
+
key: 'form_min',
|
|
76
|
+
params: { min: control.getAttribute('min') ?? '' },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (validity.rangeOverflow) {
|
|
80
|
+
return {
|
|
81
|
+
key: 'form_max',
|
|
82
|
+
params: { max: control.getAttribute('max') ?? '' },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (validity.stepMismatch) {
|
|
86
|
+
return {
|
|
87
|
+
key: 'form_step',
|
|
88
|
+
params: { step: control.getAttribute('step') ?? '1' },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
64
91
|
if (validity.badInput)
|
|
65
92
|
return { key: 'form_number' };
|
|
66
93
|
if (validity.patternMismatch)
|
|
@@ -117,13 +144,17 @@ export function createControlValidation(getOverride = () => undefined, getValue)
|
|
|
117
144
|
});
|
|
118
145
|
return {
|
|
119
146
|
get message() {
|
|
120
|
-
return issue
|
|
147
|
+
return issue
|
|
148
|
+
? resolveFormText(getOverride()) || uiM(issue.key, issue.params)
|
|
149
|
+
: '';
|
|
121
150
|
},
|
|
122
151
|
validate(control) {
|
|
123
152
|
currentControl = control;
|
|
124
153
|
control.setCustomValidity('');
|
|
125
154
|
issue = readIssue(control);
|
|
126
|
-
control.setCustomValidity(issue
|
|
155
|
+
control.setCustomValidity(issue
|
|
156
|
+
? resolveFormText(getOverride()) || uiM(issue.key, issue.params)
|
|
157
|
+
: '');
|
|
127
158
|
},
|
|
128
159
|
blur(control) {
|
|
129
160
|
// 默认焦点离开未输入的空字段时不挤动按钮/链接;提交仍由原生 invalid 校验。
|
|
@@ -32,9 +32,13 @@ export function sanitizeInlineSvg(markup) {
|
|
|
32
32
|
const trimmed = markup.trim();
|
|
33
33
|
if (!trimmed || !/^<svg(?:\s[^>]*)?>[\s\S]*<\/svg>$/i.test(trimmed))
|
|
34
34
|
return '';
|
|
35
|
-
const hasUnsafeElement = [
|
|
35
|
+
const hasUnsafeElement = [
|
|
36
|
+
...trimmed.matchAll(/<\s*([a-z][\w-]*)\b/gi),
|
|
37
|
+
]
|
|
36
38
|
.some(([, tagName]) => tagName && unsafeSvgElements.has(tagName.toLowerCase()));
|
|
37
39
|
const hasUnsafeAttribute = /\s(?:on[a-z]+|style|href|xlink:href|src)\s*=/i.test(trimmed);
|
|
38
40
|
const hasExternalReference = /url\s*\(|@import|javascript:|vbscript:|data:text\/html|<\s*!/i.test(trimmed);
|
|
39
|
-
return hasUnsafeElement || hasUnsafeAttribute || hasExternalReference
|
|
41
|
+
return hasUnsafeElement || hasUnsafeAttribute || hasExternalReference
|
|
42
|
+
? ''
|
|
43
|
+
: trimmed;
|
|
40
44
|
}
|
package/dist/message.svelte.js
CHANGED
|
@@ -14,7 +14,9 @@ class MessageState {
|
|
|
14
14
|
return toast.items.map(item => ({
|
|
15
15
|
id: item.id,
|
|
16
16
|
message: item.message,
|
|
17
|
-
type: item.variant === 'success' || item.variant === 'warning' || item.variant === 'error'
|
|
17
|
+
type: item.variant === 'success' || item.variant === 'warning' || item.variant === 'error'
|
|
18
|
+
? item.variant
|
|
19
|
+
: 'info',
|
|
18
20
|
duration: item.duration ?? 3000,
|
|
19
21
|
closable: item.dismissible ?? true,
|
|
20
22
|
}));
|
|
@@ -32,7 +34,9 @@ class MessageState {
|
|
|
32
34
|
* ```
|
|
33
35
|
*/
|
|
34
36
|
add(options) {
|
|
35
|
-
const opts = typeof options === 'string'
|
|
37
|
+
const opts = typeof options === 'string'
|
|
38
|
+
? { message: options }
|
|
39
|
+
: options;
|
|
36
40
|
return toast.add({
|
|
37
41
|
message: opts.message,
|
|
38
42
|
variant: opts.type ?? 'info',
|
|
@@ -48,7 +48,9 @@ class MessageBoxState {
|
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
confirm(options) {
|
|
51
|
-
const opts = typeof options === 'string'
|
|
51
|
+
const opts = typeof options === 'string'
|
|
52
|
+
? { message: options }
|
|
53
|
+
: options;
|
|
52
54
|
return this.createItem({ type: 'confirm', ...opts });
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
@@ -63,7 +65,9 @@ class MessageBoxState {
|
|
|
63
65
|
* ```
|
|
64
66
|
*/
|
|
65
67
|
alert(options) {
|
|
66
|
-
const opts = typeof options === 'string'
|
|
68
|
+
const opts = typeof options === 'string'
|
|
69
|
+
? { message: options }
|
|
70
|
+
: options;
|
|
67
71
|
return this.createItem({ type: 'alert', showCancel: false, ...opts });
|
|
68
72
|
}
|
|
69
73
|
/**
|