@svadmin/ui 0.115.0 → 0.117.0

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.
Files changed (46) hide show
  1. package/dist/app.css +260 -26
  2. package/dist/app.theme.css +260 -26
  3. package/dist/components/AboutSettings.svelte +1 -1
  4. package/dist/components/AppearanceSettings.svelte +70 -1
  5. package/dist/components/CheckCard.svelte +149 -0
  6. package/dist/components/CheckCard.svelte.d.ts +31 -0
  7. package/dist/components/CopyableText.svelte +90 -0
  8. package/dist/components/CopyableText.svelte.d.ts +13 -0
  9. package/dist/components/Divider.svelte +89 -0
  10. package/dist/components/Divider.svelte.d.ts +19 -0
  11. package/dist/components/EllipsisText.svelte +78 -0
  12. package/dist/components/EllipsisText.svelte.d.ts +15 -0
  13. package/dist/components/FullscreenButton.svelte +88 -0
  14. package/dist/components/FullscreenButton.svelte.d.ts +10 -0
  15. package/dist/components/GlobalShortcuts.svelte +229 -0
  16. package/dist/components/GlobalShortcuts.svelte.d.ts +18 -0
  17. package/dist/components/Header.svelte +17 -1
  18. package/dist/components/Header.svelte.d.ts +3 -0
  19. package/dist/components/Layout.svelte +51 -4
  20. package/dist/components/Layout.svelte.d.ts +1 -0
  21. package/dist/components/LightFilter.svelte +281 -0
  22. package/dist/components/LightFilter.svelte.d.ts +36 -0
  23. package/dist/components/LockScreen.svelte +295 -0
  24. package/dist/components/LockScreen.svelte.d.ts +21 -0
  25. package/dist/components/PricingCard.svelte +158 -0
  26. package/dist/components/PricingCard.svelte.d.ts +42 -0
  27. package/dist/components/PricingTable.svelte +185 -0
  28. package/dist/components/PricingTable.svelte.d.ts +40 -0
  29. package/dist/components/ProCard.svelte +267 -0
  30. package/dist/components/ProCard.svelte.d.ts +56 -0
  31. package/dist/components/QuotaProgressBar.svelte +139 -0
  32. package/dist/components/QuotaProgressBar.svelte.d.ts +27 -0
  33. package/dist/components/StatisticCard.svelte +167 -0
  34. package/dist/components/StatisticCard.svelte.d.ts +41 -0
  35. package/dist/components/TypographyEllipsis.svelte +12 -9
  36. package/dist/components/TypographyEllipsis.svelte.d.ts +9 -8
  37. package/dist/components/TypographyText.svelte +41 -3
  38. package/dist/components/TypographyText.svelte.d.ts +10 -2
  39. package/dist/components/UsageCard.svelte +97 -0
  40. package/dist/components/UsageCard.svelte.d.ts +26 -0
  41. package/dist/components/ui/badge/badge.svelte +156 -12
  42. package/dist/components/ui/badge/badge.svelte.d.ts +9 -0
  43. package/dist/components/ui/badge/index.d.ts +1 -1
  44. package/dist/index.d.ts +34 -3
  45. package/dist/index.js +24 -2
  46. package/package.json +5 -5
@@ -0,0 +1,229 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+ import { Keyboard, Search, X } from '@lucide/svelte';
4
+ import { useTranslation } from '@svadmin/core';
5
+ import { cn } from '../utils.js';
6
+
7
+ export interface ShortcutItem {
8
+ id: string;
9
+ category: 'navigation' | 'view' | 'action' | 'system';
10
+ label: string;
11
+ keys: string[];
12
+ description?: string;
13
+ action?: () => void;
14
+ }
15
+
16
+ interface Props {
17
+ open?: boolean;
18
+ shortcuts?: ShortcutItem[];
19
+ enableBuiltins?: boolean;
20
+ class?: string;
21
+ onAction?: (shortcutId: string) => void;
22
+ }
23
+
24
+ let {
25
+ open = $bindable(false),
26
+ shortcuts = [],
27
+ enableBuiltins = true,
28
+ class: className = '',
29
+ onAction,
30
+ }: Props = $props();
31
+
32
+ const i18n = useTranslation();
33
+ let query = $state('');
34
+
35
+ const defaultShortcuts: ShortcutItem[] = [
36
+ {
37
+ id: 'command-palette',
38
+ category: 'navigation',
39
+ label: '全局搜索 / 命令面板',
40
+ keys: ['⌘ / Ctrl', 'K'],
41
+ description: '快速定位资源、页面与菜单',
42
+ },
43
+ {
44
+ id: 'toggle-lock',
45
+ category: 'system',
46
+ label: '会话安全锁屏',
47
+ keys: ['Alt', 'L'],
48
+ description: '离开工位时快速锁定当前会话',
49
+ },
50
+ {
51
+ id: 'toggle-fullscreen',
52
+ category: 'view',
53
+ label: '全屏模式切换',
54
+ keys: ['F11'],
55
+ description: '展开全屏或退出全屏',
56
+ },
57
+ {
58
+ id: 'toggle-theme',
59
+ category: 'view',
60
+ label: '切换主题外观',
61
+ keys: ['Alt', 'T'],
62
+ description: '在浅色与深色主题间切换',
63
+ },
64
+ {
65
+ id: 'shortcuts-help',
66
+ category: 'system',
67
+ label: '打开快捷键向导',
68
+ keys: ['?'],
69
+ description: '查看当前系统全部可用快捷键',
70
+ },
71
+ ];
72
+
73
+ const allShortcuts = $derived(enableBuiltins ? [...defaultShortcuts, ...shortcuts] : shortcuts);
74
+
75
+ const filteredShortcuts = $derived.by(() => {
76
+ if (!query.trim()) return allShortcuts;
77
+ const q = query.toLowerCase();
78
+ return allShortcuts.filter(
79
+ (item) =>
80
+ item.label.toLowerCase().includes(q) ||
81
+ item.description?.toLowerCase().includes(q) ||
82
+ item.keys.some((k) => k.toLowerCase().includes(q)),
83
+ );
84
+ });
85
+
86
+ const categories: Record<string, string> = {
87
+ navigation: '导航与检索',
88
+ view: '视图与外观',
89
+ action: '数据操作',
90
+ system: '系统安全',
91
+ };
92
+
93
+ const groupedShortcuts = $derived.by(() => {
94
+ const groups: Record<string, ShortcutItem[]> = {};
95
+ for (const item of filteredShortcuts) {
96
+ const group = groups[item.category] ?? (groups[item.category] = []);
97
+ group.push(item);
98
+ }
99
+ return groups;
100
+ });
101
+
102
+ function handleKeydown(event: KeyboardEvent) {
103
+ const target = event.target as HTMLElement | null;
104
+ const isEditing = target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable);
105
+
106
+ // 按 ? (Shift + /) 且非编辑状态唤出帮助面板
107
+ if (event.key === '?' && !isEditing) {
108
+ event.preventDefault();
109
+ open = !open;
110
+ return;
111
+ }
112
+
113
+ // Cmd + / 或 Ctrl + /
114
+ if ((event.metaKey || event.ctrlKey) && event.key === '/') {
115
+ event.preventDefault();
116
+ open = !open;
117
+ return;
118
+ }
119
+
120
+ if (open && event.key === 'Escape') {
121
+ event.preventDefault();
122
+ open = false;
123
+ }
124
+ }
125
+
126
+ function triggerItem(item: ShortcutItem) {
127
+ item.action?.();
128
+ onAction?.(item.id);
129
+ }
130
+
131
+ onMount(() => {
132
+ window.addEventListener('keydown', handleKeydown);
133
+ return () => {
134
+ window.removeEventListener('keydown', handleKeydown);
135
+ };
136
+ });
137
+ </script>
138
+
139
+ {#if open}
140
+ <div
141
+ data-svadmin-component="global-shortcuts"
142
+ class="fixed inset-0 z-50 flex items-center justify-center bg-background/80 p-4 backdrop-blur-xs select-none"
143
+ role="dialog"
144
+ aria-modal="true"
145
+ aria-label={i18n.t('common.shortcutsHelp')}
146
+ >
147
+ <div
148
+ class={cn(
149
+ 'relative flex flex-col w-full max-w-xl max-h-[85vh] rounded-xl border border-border bg-card text-card-foreground shadow-2xl overflow-hidden',
150
+ className,
151
+ )}
152
+ >
153
+ <!-- 头部 -->
154
+ <div class="flex items-center justify-between border-b border-border px-6 py-4">
155
+ <div class="flex items-center gap-2">
156
+ <Keyboard class="h-5 w-5 text-primary" />
157
+ <h2 class="text-base font-semibold">{i18n.t('common.shortcutsHelp')}</h2>
158
+ </div>
159
+ <button
160
+ type="button"
161
+ class="rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground"
162
+ onclick={() => (open = false)}
163
+ aria-label="Close"
164
+ >
165
+ <X size={16} />
166
+ </button>
167
+ </div>
168
+
169
+ <!-- 搜索过滤栏 -->
170
+ <div class="px-6 py-3 border-b border-border/50 bg-muted/30">
171
+ <div class="relative flex items-center">
172
+ <Search size={16} class="absolute left-3 text-muted-foreground pointer-events-none" />
173
+ <input
174
+ type="text"
175
+ bind:value={query}
176
+ placeholder="搜索快捷键..."
177
+ class="flex h-9 w-full rounded-md border border-input bg-background pl-9 pr-3 py-1 text-sm shadow-2xs placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring"
178
+ />
179
+ </div>
180
+ </div>
181
+
182
+ <!-- 快捷键列表 -->
183
+ <div class="flex-1 overflow-y-auto px-6 py-4 space-y-6">
184
+ {#each Object.entries(groupedShortcuts) as [categoryKey, items] (categoryKey)}
185
+ <div class="space-y-2.5">
186
+ <div class="text-xs font-medium text-muted-foreground uppercase tracking-wider">
187
+ {categories[categoryKey] || categoryKey}
188
+ </div>
189
+ <div class="space-y-1.5">
190
+ {#each items as item (item.id)}
191
+ <div
192
+ class="flex items-center justify-between rounded-lg px-3 py-2 text-sm transition-colors hover:bg-accent/50 cursor-pointer"
193
+ onclick={() => triggerItem(item)}
194
+ role="button"
195
+ tabindex="0"
196
+ onkeydown={(e) => e.key === 'Enter' && triggerItem(item)}
197
+ >
198
+ <div class="flex flex-col">
199
+ <span class="font-medium text-foreground">{item.label}</span>
200
+ {#if item.description}
201
+ <span class="text-xs text-muted-foreground">{item.description}</span>
202
+ {/if}
203
+ </div>
204
+ <div class="flex items-center gap-1.5 shrink-0">
205
+ {#each item.keys as key, keyIdx (keyIdx)}
206
+ <kbd class="inline-flex min-w-6 h-6 items-center justify-center rounded-md border border-border bg-muted px-1.5 text-xs font-mono font-medium text-muted-foreground shadow-2xs">
207
+ {key}
208
+ </kbd>
209
+ {/each}
210
+ </div>
211
+ </div>
212
+ {/each}
213
+ </div>
214
+ </div>
215
+ {/each}
216
+
217
+ {#if filteredShortcuts.length === 0}
218
+ <div class="text-center py-8 text-sm text-muted-foreground">未找到匹配的快捷键</div>
219
+ {/if}
220
+ </div>
221
+
222
+ <!-- 底部提示 -->
223
+ <div class="border-t border-border px-6 py-3 bg-muted/20 text-xs text-muted-foreground flex items-center justify-between">
224
+ <span>按 <kbd class="px-1 py-0.5 rounded bg-muted border text-[10px]">Esc</kbd> 退出向导</span>
225
+ <span>按 <kbd class="px-1 py-0.5 rounded bg-muted border text-[10px]">?</kbd> 随时唤出</span>
226
+ </div>
227
+ </div>
228
+ </div>
229
+ {/if}
@@ -0,0 +1,18 @@
1
+ export interface ShortcutItem {
2
+ id: string;
3
+ category: 'navigation' | 'view' | 'action' | 'system';
4
+ label: string;
5
+ keys: string[];
6
+ description?: string;
7
+ action?: () => void;
8
+ }
9
+ interface Props {
10
+ open?: boolean;
11
+ shortcuts?: ShortcutItem[];
12
+ enableBuiltins?: boolean;
13
+ class?: string;
14
+ onAction?: (shortcutId: string) => void;
15
+ }
16
+ declare const GlobalShortcuts: import("svelte").Component<Props, {}, "open">;
17
+ type GlobalShortcuts = ReturnType<typeof GlobalShortcuts>;
18
+ export default GlobalShortcuts;
@@ -1,11 +1,12 @@
1
1
  <script lang="ts">
2
- import { Moon, Sun, Search, MonitorUp } from '@lucide/svelte';
2
+ import { Moon, Sun, Search, MonitorUp, Lock } from '@lucide/svelte';
3
3
  import { Button } from './ui/button';
4
4
  import TooltipButton from './TooltipButton.svelte';
5
5
  import { getResolvedTheme, toggleTheme, type MenuItem } from '@svadmin/core';
6
6
  import Breadcrumbs from './Breadcrumbs.svelte';
7
7
  import NotificationCenter, { type NotificationItem } from './NotificationCenter.svelte';
8
8
  import ThemeSettingsDrawer from './ThemeSettingsDrawer.svelte';
9
+ import FullscreenButton from './FullscreenButton.svelte';
9
10
  import { useTranslation } from '@svadmin/core/i18n';
10
11
 
11
12
  import { getComponentRegistry } from '../component-registry.svelte.js';
@@ -15,6 +16,7 @@
15
16
  let {
16
17
  showThemeToggle = false,
17
18
  showThemeSettings = true,
19
+ showFullscreen = false,
18
20
  showNotifications = true,
19
21
  notificationItems = [],
20
22
  notificationUnreadCount,
@@ -29,9 +31,12 @@
29
31
  rightActions,
30
32
  siteUrl,
31
33
  menu,
34
+ showLock = false,
35
+ onlock,
32
36
  } = $props<{
33
37
  showThemeToggle?: boolean;
34
38
  showThemeSettings?: boolean;
39
+ showFullscreen?: boolean;
35
40
  showNotifications?: boolean;
36
41
  notificationItems?: NotificationItem[];
37
42
  notificationUnreadCount?: number;
@@ -45,6 +50,8 @@
45
50
  rightActions?: import('svelte').Snippet;
46
51
  siteUrl?: string;
47
52
  menu?: MenuItem[];
53
+ showLock?: boolean;
54
+ onlock?: () => void;
48
55
  }>();
49
56
 
50
57
  // Retrieve optional component overrides from registry
@@ -95,6 +102,15 @@
95
102
  <ThemeSettingsDrawer />
96
103
  {/if}
97
104
 
105
+ {#if showFullscreen}
106
+ <FullscreenButton />
107
+ {/if}
108
+ {#if showLock}
109
+ <TooltipButton tooltip={i18n.t('common.lockScreen')} onclick={() => onlock?.()} class="rounded-full">
110
+ <Lock class="h-4 w-4" />
111
+ </TooltipButton>
112
+ {/if}
113
+
98
114
  {#if showSearch && onSearchClick}
99
115
  <Button variant="outline" size="sm" onclick={onSearchClick} aria-label={i18n.t('common.search')} class="svadmin-header-search gap-2 text-muted-foreground h-9 px-3 rounded-lg border-border/60">
100
116
  <Search class="h-3.5 w-3.5" />
@@ -3,6 +3,7 @@ import { type NotificationItem } from './NotificationCenter.svelte';
3
3
  type $$ComponentProps = {
4
4
  showThemeToggle?: boolean;
5
5
  showThemeSettings?: boolean;
6
+ showFullscreen?: boolean;
6
7
  showNotifications?: boolean;
7
8
  notificationItems?: NotificationItem[];
8
9
  notificationUnreadCount?: number;
@@ -16,6 +17,8 @@ type $$ComponentProps = {
16
17
  rightActions?: import('svelte').Snippet;
17
18
  siteUrl?: string;
18
19
  menu?: MenuItem[];
20
+ showLock?: boolean;
21
+ onlock?: () => void;
19
22
  };
20
23
  declare const Header: import("svelte").Component<$$ComponentProps, {}, "">;
21
24
  type Header = ReturnType<typeof Header>;
@@ -49,6 +49,7 @@
49
49
  onnotificationread?: (item: NotificationItem) => void | Promise<void>;
50
50
  onnotificationreadall?: () => void | Promise<void>;
51
51
  onnotificationopen?: (item: NotificationItem) => void | Promise<void>;
52
+ showFullscreen?: boolean;
52
53
  class?: string;
53
54
  }
54
55
 
@@ -64,6 +65,7 @@
64
65
  onnotificationread,
65
66
  onnotificationreadall,
66
67
  onnotificationopen,
68
+ showFullscreen = false,
67
69
  class: className = '',
68
70
  }: Props = $props();
69
71
  const layoutId = $props.id();
@@ -76,6 +78,39 @@
76
78
  const showTopNavigation = $derived(navigation === 'top' || navigation === 'mix');
77
79
  const topLevelMenu = $derived((menu ?? []).filter((item) => !item.meta?.hidden));
78
80
 
81
+ let selectedMixRootKey = $state<string | null>(null);
82
+
83
+ // 混合导航模式下,当前激活的一级根菜单项
84
+ const activeMixRoot = $derived.by(() => {
85
+ if (navigation !== 'mix') return null;
86
+ const currentPath = getPath();
87
+ // URL 是深链接、后退和外部导航的事实来源。
88
+ for (const item of topLevelMenu) {
89
+ if (item.children && item.children.some((c) => c.href && (currentPath === c.href || currentPath.startsWith(`${c.href}/`)))) {
90
+ return item;
91
+ }
92
+ if (item.href && (currentPath === item.href || currentPath.startsWith(`${item.href}/`))) {
93
+ return item;
94
+ }
95
+ }
96
+ if (selectedMixRootKey) {
97
+ const match = topLevelMenu.find((m) => m.name === selectedMixRootKey);
98
+ if (match) return match;
99
+ }
100
+ return topLevelMenu[0] ?? null;
101
+ });
102
+
103
+ // 在 mix 模式下,左侧侧边栏联动展示当前激活根菜单的子菜单
104
+ const effectiveSidebarMenu = $derived.by(() => {
105
+ if (navigation === 'mix' && activeMixRoot) {
106
+ if (activeMixRoot.children && activeMixRoot.children.length > 0) {
107
+ return activeMixRoot.children;
108
+ }
109
+ return [activeMixRoot];
110
+ }
111
+ return menu;
112
+ });
113
+
79
114
  const auth = $derived(adminContext.authProvider);
80
115
  let loading = $state(true);
81
116
  let identity = $state<Identity | null>(null);
@@ -236,7 +271,7 @@
236
271
  <!-- Desktop sidebar -->
237
272
  {#if showSidebar}
238
273
  <div class="svadmin-layout__desktop-sidebar">
239
- <Sidebar {collapsed} {identity} {title} {...definedOptions({ "menu": menu })} {routeMode} onToggle={() => collapsed = !collapsed} onLogout={handleLogout} />
274
+ <Sidebar {collapsed} {identity} {title} {...definedOptions({ "menu": effectiveSidebarMenu })} {routeMode} onToggle={() => collapsed = !collapsed} onLogout={handleLogout} />
240
275
  </div>
241
276
  {/if}
242
277
 
@@ -250,7 +285,7 @@
250
285
  >
251
286
  <Sheet.Title id={`${layoutScope}-mobile-navigation-title`} class="sr-only">{title}</Sheet.Title>
252
287
  <div class="md:hidden">
253
- <Sidebar collapsed={false} {identity} {title} {...definedOptions({ "menu": menu })} {routeMode} onToggle={() => { mobileMenuOpen = false; }} onLogout={handleLogout} />
288
+ <Sidebar collapsed={false} {identity} {title} {...definedOptions({ "menu": effectiveSidebarMenu })} {routeMode} onToggle={() => { mobileMenuOpen = false; }} onLogout={handleLogout} />
254
289
  </div>
255
290
  </Sheet.Root>
256
291
 
@@ -265,6 +300,7 @@
265
300
  <Header
266
301
  {...definedOptions({ "siteUrl": siteUrl })}
267
302
  {...definedOptions({ "menu": menu })}
303
+ {showFullscreen}
268
304
  showSearch={true}
269
305
  showThemeToggle={true}
270
306
  notificationItems={notifications ?? []}
@@ -300,8 +336,19 @@
300
336
  {#if showTopNavigation}
301
337
  <nav class="svadmin-top-navigation" aria-label={title}>
302
338
  {#each topLevelMenu as item (item.name)}
303
- {@const active = item.href ? getPath().startsWith(item.href) : false}
304
- <a class="svadmin-top-navigation__item" class:is-active={active} href={item.href ?? '#'}>
339
+ {@const isMixActive = navigation === 'mix' && activeMixRoot?.name === item.name}
340
+ {@const isPathActive = item.href ? getPath().startsWith(item.href) : false}
341
+ {@const active = navigation === 'mix' ? isMixActive : isPathActive}
342
+ <a
343
+ class="svadmin-top-navigation__item"
344
+ class:is-active={active}
345
+ href={item.href ?? (item.children?.[0]?.href ?? '#')}
346
+ onclick={() => {
347
+ if (navigation === 'mix') {
348
+ selectedMixRootKey = item.name;
349
+ }
350
+ }}
351
+ >
305
352
  {item.label ?? i18n.t(`menu.${item.name}`)}
306
353
  </a>
307
354
  {/each}
@@ -18,6 +18,7 @@ interface Props {
18
18
  onnotificationread?: (item: NotificationItem) => void | Promise<void>;
19
19
  onnotificationreadall?: () => void | Promise<void>;
20
20
  onnotificationopen?: (item: NotificationItem) => void | Promise<void>;
21
+ showFullscreen?: boolean;
21
22
  class?: string;
22
23
  }
23
24
  declare const Layout: import("svelte").Component<Props, {}, "">;