@svadmin/ui 0.128.0 → 0.130.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.
- package/dist/app.css +156 -36
- package/dist/app.theme.css +156 -36
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AppFooter.svelte +1 -1
- package/dist/components/BoundRecordDetailDrawer.svelte +1 -1
- package/dist/components/CodeEditor.svelte +1 -1
- package/dist/components/ColorPicker.svelte +2 -2
- package/dist/components/FeatureFlagStudio.svelte +583 -0
- package/dist/components/FeatureFlagStudio.svelte.d.ts +12 -0
- package/dist/components/FloatButton.svelte +1 -1
- package/dist/components/HotkeysHelpModal.svelte +286 -0
- package/dist/components/HotkeysHelpModal.svelte.d.ts +21 -0
- package/dist/components/JsonEditor.svelte +1 -1
- package/dist/components/ListPagination.svelte +19 -12
- package/dist/components/MediaGallery.svelte +575 -0
- package/dist/components/MediaGallery.svelte.d.ts +34 -0
- package/dist/components/Menu.svelte +6 -6
- package/dist/components/NotificationCenter.svelte +20 -1
- package/dist/components/NotificationCenter.svelte.d.ts +2 -0
- package/dist/components/NotificationDrawer.svelte +242 -0
- package/dist/components/NotificationDrawer.svelte.d.ts +40 -0
- package/dist/components/NotificationHost.svelte +1 -1
- package/dist/components/PhoneInput.svelte +1 -1
- package/dist/components/RadioGroup.svelte +8 -0
- package/dist/components/Rate.svelte +2 -2
- package/dist/components/RelationPicker.svelte +2 -2
- package/dist/components/ResizableGrid.svelte +1 -1
- package/dist/components/ResizableSplitter.svelte +246 -0
- package/dist/components/ResizableSplitter.svelte.d.ts +18 -0
- package/dist/components/ResizeBox.svelte +1 -1
- package/dist/components/SegmentedControl.svelte +2 -2
- package/dist/components/Steps.svelte +12 -11
- package/dist/components/SvarDataGrid.svelte +1 -1
- package/dist/components/SvarResourceTableView.svelte +3 -3
- package/dist/components/Tag.svelte +5 -4
- package/dist/components/TagsInput.svelte +2 -2
- package/dist/components/Tour.svelte +1 -1
- package/dist/components/Tree.svelte +1 -1
- package/dist/components/TreeSelect.svelte +2 -2
- package/dist/components/TypographyEllipsis.svelte +1 -1
- package/dist/components/TypographyText.svelte +2 -2
- package/dist/components/ViewModeToggle.svelte +1 -1
- package/dist/components/ui/alert/alert.svelte +1 -1
- package/dist/components/ui/tooltip/tooltip-content.svelte +2 -2
- package/dist/components/useFeatureFlag.d.svelte.ts +1 -0
- package/dist/components/useFeatureFlag.svelte.d.ts +45 -0
- package/dist/components/useFeatureFlag.svelte.js +94 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/styles/recipes.css +4 -4
- package/package.json +1 -1
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
allLabel?: string | undefined;
|
|
30
30
|
loading?: boolean | undefined;
|
|
31
31
|
open?: boolean | undefined;
|
|
32
|
+
showDrawerButton?: boolean | undefined;
|
|
33
|
+
onopendrawer?: (() => void) | undefined;
|
|
32
34
|
children?: Snippet | undefined;
|
|
33
35
|
onread?: ((item: NotificationItem) => void | Promise<void>) | undefined;
|
|
34
36
|
onreadall?: (() => void | Promise<void>) | undefined;
|
|
@@ -48,6 +50,8 @@
|
|
|
48
50
|
allLabel = 'All',
|
|
49
51
|
loading = false,
|
|
50
52
|
open = $bindable(false),
|
|
53
|
+
showDrawerButton = false,
|
|
54
|
+
onopendrawer,
|
|
51
55
|
children,
|
|
52
56
|
onread,
|
|
53
57
|
onreadall,
|
|
@@ -87,7 +91,7 @@
|
|
|
87
91
|
<Popover.Root bind:open>
|
|
88
92
|
<Popover.Trigger>
|
|
89
93
|
{#snippet child({ props })}
|
|
90
|
-
<span class="svadmin-notification-center__trigger-wrap">
|
|
94
|
+
<span class="svadmin-notification-center__trigger-wrap" data-svadmin-component="NotificationCenter">
|
|
91
95
|
<Button {...props} variant="ghost" size="icon-sm" aria-label={`${title}${resolvedUnread ? `, ${resolvedUnread} unread` : ''}`} class={className}>
|
|
92
96
|
<Bell size={16} aria-hidden="true" />
|
|
93
97
|
{#if resolvedUnread > 0}
|
|
@@ -160,6 +164,21 @@
|
|
|
160
164
|
{/each}
|
|
161
165
|
</ul>
|
|
162
166
|
{/if}
|
|
167
|
+
{#if showDrawerButton}
|
|
168
|
+
<div class="svadmin-notification-center__footer">
|
|
169
|
+
<Button
|
|
170
|
+
variant="ghost"
|
|
171
|
+
size="sm"
|
|
172
|
+
class="w-full text-xs text-primary"
|
|
173
|
+
onclick={() => {
|
|
174
|
+
open = false;
|
|
175
|
+
onopendrawer?.();
|
|
176
|
+
}}
|
|
177
|
+
>
|
|
178
|
+
Open Full Drawer →
|
|
179
|
+
</Button>
|
|
180
|
+
</div>
|
|
181
|
+
{/if}
|
|
163
182
|
{#if children}<div class="svadmin-notification-center__footer">{@render children()}</div>{/if}
|
|
164
183
|
</div>
|
|
165
184
|
</Popover.Content>
|
|
@@ -21,6 +21,8 @@ interface Props {
|
|
|
21
21
|
allLabel?: string | undefined;
|
|
22
22
|
loading?: boolean | undefined;
|
|
23
23
|
open?: boolean | undefined;
|
|
24
|
+
showDrawerButton?: boolean | undefined;
|
|
25
|
+
onopendrawer?: (() => void) | undefined;
|
|
24
26
|
children?: Snippet | undefined;
|
|
25
27
|
onread?: ((item: NotificationItem) => void | Promise<void>) | undefined;
|
|
26
28
|
onreadall?: (() => void | Promise<void>) | undefined;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export type NotificationCategory = 'TASKS' | 'ANNOUNCEMENTS' | 'SECURITY_ALERTS';
|
|
5
|
+
export interface NotificationAction {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
variant?: 'primary' | 'destructive' | 'default';
|
|
9
|
+
onClick?: (item: NotificationItem) => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface NotificationItem {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
category: NotificationCategory;
|
|
16
|
+
read: boolean;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
avatar?: string;
|
|
19
|
+
badge?: string;
|
|
20
|
+
actions?: NotificationAction[];
|
|
21
|
+
meta?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export interface NotificationDrawerProps {
|
|
24
|
+
open?: boolean;
|
|
25
|
+
items?: NotificationItem[];
|
|
26
|
+
dndEnabled?: boolean;
|
|
27
|
+
class?: string;
|
|
28
|
+
onClose?: () => void | Promise<void>;
|
|
29
|
+
onItemClick?: (item: NotificationItem) => void | Promise<void>;
|
|
30
|
+
onMarkAllRead?: () => void | Promise<void>;
|
|
31
|
+
onClearRead?: () => void | Promise<void>;
|
|
32
|
+
onToggleDnd?: (enabled: boolean) => void | Promise<void>;
|
|
33
|
+
onAction?: (actionId: string, item: NotificationItem) => void | Promise<void>;
|
|
34
|
+
onError?: (error: unknown) => void;
|
|
35
|
+
customItem?: Snippet<[{ item: NotificationItem; index: number }]>;
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script lang="ts">
|
|
40
|
+
import { Sheet } from './ui/sheet/index.js';
|
|
41
|
+
|
|
42
|
+
let {
|
|
43
|
+
open = $bindable(false), items = $bindable([]), dndEnabled = $bindable(false),
|
|
44
|
+
class: className = '', onClose, onItemClick, onMarkAllRead, onClearRead,
|
|
45
|
+
onToggleDnd, onAction, onError, customItem,
|
|
46
|
+
}: NotificationDrawerProps = $props();
|
|
47
|
+
|
|
48
|
+
type Filter = 'ALL' | 'UNREAD' | NotificationCategory;
|
|
49
|
+
const categories: { key: Filter; label: string }[] = [
|
|
50
|
+
{ key: 'ALL', label: 'All' }, { key: 'UNREAD', label: 'Unread' },
|
|
51
|
+
{ key: 'TASKS', label: 'Tasks' }, { key: 'ANNOUNCEMENTS', label: 'Notices' },
|
|
52
|
+
{ key: 'SECURITY_ALERTS', label: 'Security' },
|
|
53
|
+
];
|
|
54
|
+
let activeTab = $state<Filter>('ALL');
|
|
55
|
+
let pendingOperation = $state<string | null>(null);
|
|
56
|
+
let errorMessage = $state('');
|
|
57
|
+
const filteredItems = $derived(items.filter(item => activeTab === 'ALL'
|
|
58
|
+
|| (activeTab === 'UNREAD' ? !item.read : item.category === activeTab)));
|
|
59
|
+
const unreadCounts = $derived.by(() => {
|
|
60
|
+
const counts: Record<Filter, number> = { ALL: 0, UNREAD: 0, TASKS: 0, ANNOUNCEMENTS: 0, SECURITY_ALERTS: 0 };
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
if (!item.read) { counts.ALL++; counts.UNREAD++; counts[item.category]++; }
|
|
63
|
+
}
|
|
64
|
+
return counts;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function reportError(error: unknown) {
|
|
68
|
+
errorMessage = error instanceof Error ? error.message : 'The notification operation failed. Please try again.';
|
|
69
|
+
try { void Promise.resolve(onError?.(error)).catch(() => {}); } catch { /* 错误观察者不能打断组件恢复。 */ }
|
|
70
|
+
}
|
|
71
|
+
async function runOperation(key: string, operation: () => void | Promise<void>) {
|
|
72
|
+
if (pendingOperation) return;
|
|
73
|
+
pendingOperation = key;
|
|
74
|
+
errorMessage = '';
|
|
75
|
+
try { await operation(); } catch (error) { reportError(error); }
|
|
76
|
+
finally { pendingOperation = null; }
|
|
77
|
+
}
|
|
78
|
+
function handleMarkAllAsRead() {
|
|
79
|
+
return runOperation('mark-all', async () => {
|
|
80
|
+
const ids = new Set(items.map(item => item.id));
|
|
81
|
+
await onMarkAllRead?.();
|
|
82
|
+
items = items.map(item => ids.has(item.id) ? { ...item, read: true } : item);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function handleClearRead() {
|
|
86
|
+
return runOperation('clear-read', async () => {
|
|
87
|
+
const ids = new Set(items.filter(item => item.read).map(item => item.id));
|
|
88
|
+
await onClearRead?.();
|
|
89
|
+
items = items.filter(item => !ids.has(item.id));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function toggleDndMode() {
|
|
93
|
+
return runOperation('dnd', async () => {
|
|
94
|
+
const enabled = !dndEnabled;
|
|
95
|
+
await onToggleDnd?.(enabled);
|
|
96
|
+
dndEnabled = enabled;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function markSingleRead(item: NotificationItem) {
|
|
100
|
+
return runOperation(`read:${item.id}`, async () => {
|
|
101
|
+
const updated = { ...item, read: true };
|
|
102
|
+
await onItemClick?.(updated);
|
|
103
|
+
// 不修改调用方传入对象,允许冻结快照和受控 props。
|
|
104
|
+
items = items.map(current => current.id === item.id ? { ...current, read: true } : current);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function handleActionClick(action: NotificationAction, item: NotificationItem) {
|
|
108
|
+
return runOperation(`action:${item.id}:${action.id}`, async () => {
|
|
109
|
+
if (action.onClick) await action.onClick(item);
|
|
110
|
+
else await onAction?.(action.id, item);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function handleClose() {
|
|
114
|
+
try { void Promise.resolve(onClose?.()).catch(reportError); } catch (error) { reportError(error); }
|
|
115
|
+
}
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<Sheet
|
|
119
|
+
bind:open
|
|
120
|
+
onClose={handleClose}
|
|
121
|
+
closeLabel="Close notification drawer"
|
|
122
|
+
class="svadmin-notification-drawer {className}"
|
|
123
|
+
data-svadmin-component="NotificationDrawer"
|
|
124
|
+
data-dnd-enabled={dndEnabled}
|
|
125
|
+
role="dialog"
|
|
126
|
+
aria-modal="true"
|
|
127
|
+
aria-label="Notification Center Drawer"
|
|
128
|
+
>
|
|
129
|
+
<header class="notification-header">
|
|
130
|
+
<div>
|
|
131
|
+
<h2>Notification Center</h2>
|
|
132
|
+
<p>{unreadCounts.ALL} unread notification{unreadCounts.ALL === 1 ? '' : 's'}</p>
|
|
133
|
+
</div>
|
|
134
|
+
<button class="notification-dnd" type="button" aria-pressed={dndEnabled} disabled={pendingOperation !== null}
|
|
135
|
+
title="Quiet mode preference" onclick={toggleDndMode}>
|
|
136
|
+
{dndEnabled ? 'DND On' : 'DND'}
|
|
137
|
+
</button>
|
|
138
|
+
</header>
|
|
139
|
+
|
|
140
|
+
{#if dndEnabled}
|
|
141
|
+
<p class="notification-quiet-status" role="status">Quiet mode is on. Security alerts remain visible.</p>
|
|
142
|
+
{/if}
|
|
143
|
+
<nav class="notification-categories" aria-label="Notification categories">
|
|
144
|
+
{#each categories as category (category.key)}
|
|
145
|
+
<button type="button" aria-pressed={activeTab === category.key} onclick={() => (activeTab = category.key)}>
|
|
146
|
+
{category.label}
|
|
147
|
+
{#if unreadCounts[category.key] > 0}
|
|
148
|
+
<span class="notification-count" data-security={category.key === 'SECURITY_ALERTS'} data-muted={dndEnabled && category.key !== 'SECURITY_ALERTS'}>
|
|
149
|
+
{unreadCounts[category.key] > 99 ? '99+' : unreadCounts[category.key]}
|
|
150
|
+
</span>
|
|
151
|
+
{/if}
|
|
152
|
+
</button>
|
|
153
|
+
{/each}
|
|
154
|
+
</nav>
|
|
155
|
+
<div class="notification-toolbar">
|
|
156
|
+
<span>{filteredItems.length} item{filteredItems.length === 1 ? '' : 's'}</span>
|
|
157
|
+
<button type="button" disabled={pendingOperation !== null || unreadCounts.ALL === 0} onclick={handleMarkAllAsRead}>Mark all as read</button>
|
|
158
|
+
<button type="button" disabled={pendingOperation !== null || !items.some(item => item.read)} onclick={handleClearRead}>Clear read</button>
|
|
159
|
+
</div>
|
|
160
|
+
{#if errorMessage}<p class="notification-error" role="alert">{errorMessage}</p>{/if}
|
|
161
|
+
<div class="notification-list" aria-busy={pendingOperation !== null}>
|
|
162
|
+
{#if filteredItems.length === 0}
|
|
163
|
+
<p class="notification-empty">No notifications in this category</p>
|
|
164
|
+
{:else}
|
|
165
|
+
{#each filteredItems as item, index (item.id)}
|
|
166
|
+
{#if customItem}
|
|
167
|
+
{@render customItem({ item, index })}
|
|
168
|
+
{:else}
|
|
169
|
+
<article class="notification-item" data-read={item.read} data-security={item.category === 'SECURITY_ALERTS'}>
|
|
170
|
+
<button class="notification-item-open" type="button" disabled={pendingOperation !== null} onclick={() => markSingleRead(item)}>
|
|
171
|
+
<span class="notification-dot" data-read={item.read} data-muted={dndEnabled && item.category !== 'SECURITY_ALERTS'} data-security={item.category === 'SECURITY_ALERTS'} aria-hidden="true"></span>
|
|
172
|
+
<span class="notification-copy">
|
|
173
|
+
<strong>{item.title}</strong>
|
|
174
|
+
{#if item.description}<span>{item.description}</span>{/if}
|
|
175
|
+
<time>{item.createdAt}</time>
|
|
176
|
+
</span>
|
|
177
|
+
{#if item.badge}<span class="notification-badge">{item.badge}</span>{/if}
|
|
178
|
+
</button>
|
|
179
|
+
{#if item.actions && item.actions.length > 0}
|
|
180
|
+
<div class="notification-actions">
|
|
181
|
+
{#each item.actions as action (action.id)}
|
|
182
|
+
<button type="button" data-variant={action.variant ?? 'default'} disabled={pendingOperation !== null}
|
|
183
|
+
onclick={() => handleActionClick(action, item)}>
|
|
184
|
+
{pendingOperation === `action:${item.id}:${action.id}` ? 'Working…' : action.label}
|
|
185
|
+
</button>
|
|
186
|
+
{/each}
|
|
187
|
+
</div>
|
|
188
|
+
{/if}
|
|
189
|
+
</article>
|
|
190
|
+
{/if}
|
|
191
|
+
{/each}
|
|
192
|
+
{/if}
|
|
193
|
+
</div>
|
|
194
|
+
</Sheet>
|
|
195
|
+
|
|
196
|
+
<style>
|
|
197
|
+
:global(.svadmin-notification-drawer) {
|
|
198
|
+
display: flex;
|
|
199
|
+
flex-direction: column;
|
|
200
|
+
width: min(30rem, 100vw);
|
|
201
|
+
max-width: 100vw;
|
|
202
|
+
padding: 0;
|
|
203
|
+
color: var(--foreground);
|
|
204
|
+
background: var(--card);
|
|
205
|
+
}
|
|
206
|
+
.notification-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 3rem 1rem 1rem; border-bottom: 1px solid var(--border); }
|
|
207
|
+
.notification-header h2 { margin: 0; font-size: var(--svadmin-text-section); font-weight: 500; }
|
|
208
|
+
.notification-header p { margin: 0.25rem 0 0; color: var(--muted-foreground); font-size: var(--svadmin-text-caption); }
|
|
209
|
+
button { font: inherit; cursor: pointer; }
|
|
210
|
+
button:disabled { cursor: default; opacity: 0.5; }
|
|
211
|
+
button:focus-visible { outline: var(--svadmin-focus-width) solid var(--ring); outline-offset: var(--svadmin-focus-offset); }
|
|
212
|
+
.notification-dnd { padding: 0.375rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); color: var(--muted-foreground); font-size: var(--svadmin-text-caption); white-space: nowrap; }
|
|
213
|
+
.notification-dnd[aria-pressed='true'] { color: var(--primary); background: var(--accent); }
|
|
214
|
+
.notification-categories { display: flex; flex-wrap: wrap; padding: 0.5rem; gap: 0.25rem; border-bottom: 1px solid var(--border); }
|
|
215
|
+
.notification-categories > button { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.5rem; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted-foreground); font-size: var(--svadmin-text-caption); }
|
|
216
|
+
.notification-categories > button[aria-pressed='true'] { color: var(--primary); background: var(--accent); }
|
|
217
|
+
.notification-count { display: inline-grid; place-items: center; min-width: 1rem; padding: 0.125rem 0.25rem; border-radius: 1rem; background: var(--primary); color: var(--primary-foreground); font-size: var(--svadmin-text-caption); }
|
|
218
|
+
.notification-count[data-muted='true'] { background: var(--muted); color: var(--muted-foreground); }
|
|
219
|
+
.notification-count[data-security='true'] { background: var(--destructive); color: var(--destructive-foreground); }
|
|
220
|
+
.notification-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-size: var(--svadmin-text-caption); }
|
|
221
|
+
.notification-toolbar > span { margin-right: auto; color: var(--muted-foreground); }
|
|
222
|
+
.notification-toolbar > button { padding: 0; border: 0; background: transparent; color: var(--primary); }
|
|
223
|
+
.notification-list { flex: 1; overflow-y: auto; padding: 0.5rem; min-height: 0; }
|
|
224
|
+
.notification-item { border-bottom: 1px solid var(--border); padding: 0.75rem 0.5rem; }
|
|
225
|
+
.notification-item-open { display: flex; gap: 0.5rem; width: 100%; padding: 0.25rem; border: 0; text-align: start; background: transparent; color: var(--foreground); }
|
|
226
|
+
.notification-item-open:hover { background: var(--accent); }
|
|
227
|
+
.notification-copy { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 0.375rem; font-size: var(--svadmin-text-label); }
|
|
228
|
+
.notification-copy strong { font-weight: 600; }
|
|
229
|
+
.notification-copy > span, .notification-copy time { color: var(--muted-foreground); font-size: var(--svadmin-text-caption); line-height: 1.5; overflow-wrap: anywhere; }
|
|
230
|
+
.notification-dot { width: 0.5rem; height: 0.5rem; margin-top: 0.375rem; border-radius: 50%; flex-shrink: 0; background: var(--primary); }
|
|
231
|
+
.notification-dot[data-muted='true'] { background: var(--muted-foreground); }
|
|
232
|
+
.notification-dot[data-security='true'] { background: var(--destructive); }
|
|
233
|
+
.notification-dot[data-read='true'] { background: transparent; }
|
|
234
|
+
.notification-badge { align-self: flex-start; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.125rem 0.25rem; font-size: var(--svadmin-text-caption); }
|
|
235
|
+
.notification-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0 0 1rem; }
|
|
236
|
+
.notification-actions button { padding: 0.375rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); color: var(--foreground); font-size: var(--svadmin-text-caption); }
|
|
237
|
+
.notification-actions button[data-variant='primary'] { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
|
|
238
|
+
.notification-actions button[data-variant='destructive'] { color: var(--destructive); border-color: var(--destructive); }
|
|
239
|
+
.notification-error { margin: 0; padding: 0.75rem 1rem; color: var(--destructive); background: var(--card); font-size: var(--svadmin-text-label); }
|
|
240
|
+
.notification-empty { padding: 3rem 1rem; margin: 0; color: var(--muted-foreground); text-align: center; font-size: var(--svadmin-text-label); }
|
|
241
|
+
.notification-quiet-status { margin: 0; padding: 0.75rem 1rem; color: var(--muted-foreground); background: var(--muted); font-size: var(--svadmin-text-caption); }
|
|
242
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type NotificationCategory = 'TASKS' | 'ANNOUNCEMENTS' | 'SECURITY_ALERTS';
|
|
3
|
+
export interface NotificationAction {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
variant?: 'primary' | 'destructive' | 'default';
|
|
7
|
+
onClick?: (item: NotificationItem) => void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface NotificationItem {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
category: NotificationCategory;
|
|
14
|
+
read: boolean;
|
|
15
|
+
createdAt: string;
|
|
16
|
+
avatar?: string;
|
|
17
|
+
badge?: string;
|
|
18
|
+
actions?: NotificationAction[];
|
|
19
|
+
meta?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface NotificationDrawerProps {
|
|
22
|
+
open?: boolean;
|
|
23
|
+
items?: NotificationItem[];
|
|
24
|
+
dndEnabled?: boolean;
|
|
25
|
+
class?: string;
|
|
26
|
+
onClose?: () => void | Promise<void>;
|
|
27
|
+
onItemClick?: (item: NotificationItem) => void | Promise<void>;
|
|
28
|
+
onMarkAllRead?: () => void | Promise<void>;
|
|
29
|
+
onClearRead?: () => void | Promise<void>;
|
|
30
|
+
onToggleDnd?: (enabled: boolean) => void | Promise<void>;
|
|
31
|
+
onAction?: (actionId: string, item: NotificationItem) => void | Promise<void>;
|
|
32
|
+
onError?: (error: unknown) => void;
|
|
33
|
+
customItem?: Snippet<[{
|
|
34
|
+
item: NotificationItem;
|
|
35
|
+
index: number;
|
|
36
|
+
}]>;
|
|
37
|
+
}
|
|
38
|
+
declare const NotificationDrawer: import("svelte").Component<NotificationDrawerProps, {}, "items" | "open" | "dndEnabled">;
|
|
39
|
+
type NotificationDrawer = ReturnType<typeof NotificationDrawer>;
|
|
40
|
+
export default NotificationDrawer;
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
.svadmin-notification-host__action { margin-block-start: var(--svadmin-space-2); padding: 0; border: 0; background: transparent; color: var(--primary); font-size: var(--svadmin-text-label); font-weight: 600; cursor: pointer; }
|
|
51
51
|
.svadmin-notification-host__close { align-self: start; width: 1.5rem; height: 1.5rem; padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted-foreground); cursor: pointer; }
|
|
52
52
|
.svadmin-notification-host__close:hover { background: var(--muted); color: var(--foreground); }
|
|
53
|
-
.svadmin-notification-host__close:focus-visible { outline:
|
|
53
|
+
.svadmin-notification-host__close:focus-visible { outline: var(--svadmin-focus-width) solid var(--ring); outline-offset: var(--svadmin-focus-offset); }
|
|
54
54
|
</style>
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
color: var(--foreground, currentColor);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
.svadmin-phone-input:focus-within { outline:
|
|
108
|
+
.svadmin-phone-input:focus-within { outline: var(--svadmin-focus-width) solid var(--ring, currentColor); outline-offset: var(--svadmin-focus-offset); }
|
|
109
109
|
.svadmin-phone-input[data-invalid='true'] { border-color: var(--destructive, currentColor); }
|
|
110
110
|
.svadmin-phone-input[data-disabled='true'] { cursor: not-allowed; opacity: 0.6; }
|
|
111
111
|
|
|
@@ -304,6 +304,14 @@
|
|
|
304
304
|
cursor: pointer;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
.svadmin-radio-group__option input[type='radio'] {
|
|
308
|
+
width: 14px;
|
|
309
|
+
height: 14px;
|
|
310
|
+
margin: 0;
|
|
311
|
+
flex: 0 0 auto;
|
|
312
|
+
accent-color: var(--primary);
|
|
313
|
+
}
|
|
314
|
+
|
|
307
315
|
.svadmin-radio-group__option--disabled {
|
|
308
316
|
cursor: not-allowed;
|
|
309
317
|
color: var(--svadmin-text-4);
|
|
@@ -127,8 +127,8 @@
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
.svadmin-rate button:focus-visible {
|
|
130
|
-
outline:
|
|
131
|
-
outline-offset:
|
|
130
|
+
outline: var(--svadmin-focus-width) solid var(--ring);
|
|
131
|
+
outline-offset: var(--svadmin-focus-offset);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
.svadmin-rate button:disabled {
|
|
@@ -363,7 +363,7 @@
|
|
|
363
363
|
max-width: 100%;
|
|
364
364
|
}
|
|
365
365
|
.svadmin-relation-picker__option:focus-visible {
|
|
366
|
-
outline:
|
|
367
|
-
outline-offset:
|
|
366
|
+
outline: var(--svadmin-focus-width) solid var(--ring);
|
|
367
|
+
outline-offset: var(--svadmin-focus-offset);
|
|
368
368
|
}
|
|
369
369
|
</style>
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
color: var(--muted-foreground, currentColor);
|
|
229
229
|
cursor: pointer;
|
|
230
230
|
}
|
|
231
|
-
.svadmin-resizable-grid__handle:focus-visible { outline:
|
|
231
|
+
.svadmin-resizable-grid__handle:focus-visible { outline: var(--svadmin-focus-width) solid var(--ring, currentColor); outline-offset: calc(-1 * var(--svadmin-focus-offset)); }
|
|
232
232
|
|
|
233
233
|
.svadmin-resizable-grid__handle--move {
|
|
234
234
|
top: 0;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, untrack, type Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export interface ResizableSplitterProps {
|
|
5
|
+
direction?: 'horizontal' | 'vertical';
|
|
6
|
+
initialSizes?: [number, number];
|
|
7
|
+
minSizes?: [number, number];
|
|
8
|
+
maxSizes?: [number, number];
|
|
9
|
+
storageKey?: string;
|
|
10
|
+
collapsible?: boolean;
|
|
11
|
+
gutterSize?: number;
|
|
12
|
+
class?: string;
|
|
13
|
+
firstPane?: Snippet;
|
|
14
|
+
secondPane?: Snippet;
|
|
15
|
+
onResize?: (sizes: [number, number]) => void;
|
|
16
|
+
onCollapse?: (collapsedPane: 'first' | 'second' | null) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
direction = 'horizontal',
|
|
21
|
+
initialSizes = [50, 50],
|
|
22
|
+
minSizes = [15, 15],
|
|
23
|
+
maxSizes = [85, 85],
|
|
24
|
+
storageKey,
|
|
25
|
+
collapsible = true,
|
|
26
|
+
gutterSize = 8,
|
|
27
|
+
class: className = '',
|
|
28
|
+
firstPane,
|
|
29
|
+
secondPane,
|
|
30
|
+
onResize,
|
|
31
|
+
onCollapse,
|
|
32
|
+
}: ResizableSplitterProps = $props();
|
|
33
|
+
|
|
34
|
+
let containerEl = $state<HTMLDivElement | null>(null);
|
|
35
|
+
let sizes = $state<[number, number]>(untrack(() => normalize(initialSizes)));
|
|
36
|
+
let isDragging = $state(false);
|
|
37
|
+
let collapsedPane = $state<'first' | 'second' | null>(null);
|
|
38
|
+
let stopDragging = () => {};
|
|
39
|
+
let layoutConfiguration = '';
|
|
40
|
+
|
|
41
|
+
function bounds(): [number, number] {
|
|
42
|
+
const lower = Math.max(0, minSizes[0], 100 - maxSizes[1]);
|
|
43
|
+
const upper = Math.min(100, maxSizes[0], 100 - minSizes[1]);
|
|
44
|
+
return [lower, Math.max(lower, upper)];
|
|
45
|
+
}
|
|
46
|
+
function normalize(input: unknown): [number, number] {
|
|
47
|
+
const [lower, upper] = bounds();
|
|
48
|
+
function validPair(value: unknown): value is [number, number] {
|
|
49
|
+
return Array.isArray(value) && value.length === 2 &&
|
|
50
|
+
typeof value[0] === 'number' && Number.isFinite(value[0]) && value[0] >= 0 &&
|
|
51
|
+
typeof value[1] === 'number' && Number.isFinite(value[1]) && value[1] >= 0 &&
|
|
52
|
+
Number.isFinite(value[0] + value[1]) && value[0] + value[1] > 0;
|
|
53
|
+
}
|
|
54
|
+
const pair = validPair(input) ? input : validPair(initialSizes) ? initialSizes : [50, 50];
|
|
55
|
+
let first = (pair[0] ?? 50) / ((pair[0] ?? 50) + (pair[1] ?? 50)) * 100;
|
|
56
|
+
first = Number(Math.max(lower, Math.min(upper, first)).toFixed(2));
|
|
57
|
+
return [first, Number((100 - first).toFixed(2))];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
$effect(() => {
|
|
61
|
+
const settings = { direction, initialSizes, minSizes, maxSizes, storageKey };
|
|
62
|
+
const signature = JSON.stringify(settings);
|
|
63
|
+
if (signature === layoutConfiguration) return;
|
|
64
|
+
layoutConfiguration = signature;
|
|
65
|
+
untrack(() => {
|
|
66
|
+
// 配置切换时终止旧拖拽,避免把旧布局的移动写入新的存储键。
|
|
67
|
+
stopDragging();
|
|
68
|
+
let next: unknown = settings.initialSizes;
|
|
69
|
+
if (settings.storageKey && typeof localStorage !== 'undefined') {
|
|
70
|
+
try {
|
|
71
|
+
const saved = localStorage.getItem(`svadmin_splitter_${settings.storageKey}`);
|
|
72
|
+
if (saved) next = JSON.parse(saved);
|
|
73
|
+
} catch { /* 存储不可用时使用传入的初始比例。 */ }
|
|
74
|
+
}
|
|
75
|
+
sizes = normalize(next);
|
|
76
|
+
collapsedPane = null;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
onDestroy(() => stopDragging());
|
|
80
|
+
|
|
81
|
+
function saveSizes(input: [number, number]) {
|
|
82
|
+
const [lower, upper] = bounds();
|
|
83
|
+
const first = Number(Math.max(lower, Math.min(upper, input[0])).toFixed(2));
|
|
84
|
+
sizes = [first, Number((100 - first).toFixed(2))];
|
|
85
|
+
onResize?.([...sizes]);
|
|
86
|
+
if (storageKey && typeof localStorage !== 'undefined') {
|
|
87
|
+
try { localStorage.setItem(`svadmin_splitter_${storageKey}`, JSON.stringify(sizes)); }
|
|
88
|
+
catch { /* 禁用浏览器存储不影响拖拽。 */ }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function handlePointerDown(event: PointerEvent) {
|
|
92
|
+
if (event.button !== 0 || !containerEl || (event.target instanceof Element && event.target.closest('button'))) return;
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
stopDragging();
|
|
95
|
+
const horizontal = direction === 'horizontal';
|
|
96
|
+
const rect = containerEl.getBoundingClientRect();
|
|
97
|
+
const total = horizontal ? rect.width : rect.height;
|
|
98
|
+
if (total <= 0) return;
|
|
99
|
+
isDragging = true;
|
|
100
|
+
const start = horizontal ? event.clientX : event.clientY;
|
|
101
|
+
const first = sizes[0];
|
|
102
|
+
function move(next: PointerEvent) {
|
|
103
|
+
if (next.pointerId !== event.pointerId) return;
|
|
104
|
+
const position = horizontal ? next.clientX : next.clientY;
|
|
105
|
+
const changed = first + (position - start) / total * 100;
|
|
106
|
+
saveSizes([changed, 100 - changed]);
|
|
107
|
+
}
|
|
108
|
+
stopDragging = () => {
|
|
109
|
+
isDragging = false;
|
|
110
|
+
window.removeEventListener('pointermove', move);
|
|
111
|
+
window.removeEventListener('pointerup', stopDragging);
|
|
112
|
+
window.removeEventListener('pointercancel', stopDragging);
|
|
113
|
+
window.removeEventListener('blur', stopDragging);
|
|
114
|
+
};
|
|
115
|
+
window.addEventListener('pointermove', move);
|
|
116
|
+
window.addEventListener('pointerup', stopDragging);
|
|
117
|
+
window.addEventListener('pointercancel', stopDragging);
|
|
118
|
+
window.addEventListener('blur', stopDragging);
|
|
119
|
+
}
|
|
120
|
+
function handleDoubleClick() {
|
|
121
|
+
collapsedPane = null;
|
|
122
|
+
saveSizes(normalize([50, 50]));
|
|
123
|
+
onCollapse?.(null);
|
|
124
|
+
}
|
|
125
|
+
function toggleCollapse(pane: 'first' | 'second') {
|
|
126
|
+
if (!collapsible && collapsedPane !== pane) return;
|
|
127
|
+
stopDragging();
|
|
128
|
+
collapsedPane = collapsedPane === pane ? null : pane;
|
|
129
|
+
onCollapse?.(collapsedPane);
|
|
130
|
+
}
|
|
131
|
+
function handleKeydown(event: KeyboardEvent) {
|
|
132
|
+
const previous = direction === 'horizontal' ? 'ArrowLeft' : 'ArrowUp';
|
|
133
|
+
const next = direction === 'horizontal' ? 'ArrowRight' : 'ArrowDown';
|
|
134
|
+
if (![previous, next, 'Home', 'End'].includes(event.key)) return;
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
const [lower, upper] = bounds();
|
|
137
|
+
const first = event.key === 'Home' ? lower : event.key === 'End' ? upper :
|
|
138
|
+
Math.max(lower, Math.min(upper, sizes[0] + (event.key === previous ? -2 : 2)));
|
|
139
|
+
saveSizes([first, 100 - first]);
|
|
140
|
+
}
|
|
141
|
+
const isHorizontal = $derived(direction === 'horizontal');
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
<div
|
|
145
|
+
bind:this={containerEl}
|
|
146
|
+
class="resizable-splitter relative flex h-full w-full overflow-hidden {isHorizontal ? 'flex-row' : 'flex-col'} {isDragging ? 'select-none' : ''} {className}"
|
|
147
|
+
data-svadmin-component="ResizableSplitter"
|
|
148
|
+
>
|
|
149
|
+
<!-- First Pane -->
|
|
150
|
+
<div
|
|
151
|
+
class="relative min-h-0 min-w-0 overflow-auto transition-all duration-75 {collapsedPane === 'first' ? 'hidden' : ''}"
|
|
152
|
+
style:flex="{sizes[0]} 1 0%"
|
|
153
|
+
>
|
|
154
|
+
{#if firstPane}
|
|
155
|
+
{@render firstPane()}
|
|
156
|
+
{:else}
|
|
157
|
+
<div class="flex h-full w-full items-center justify-center p-4 text-xs text-muted-foreground">
|
|
158
|
+
面板 1 (First Pane)
|
|
159
|
+
</div>
|
|
160
|
+
{/if}
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<!-- Splitter Gutter Divider -->
|
|
164
|
+
{#if collapsedPane === null}
|
|
165
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (可调整的分隔线支持键盘和指针操作。) -->
|
|
166
|
+
<div
|
|
167
|
+
class="group relative z-10 flex shrink-0 items-center justify-center bg-border/60 transition-colors hover:bg-primary/30 active:bg-primary {isHorizontal ? 'cursor-col-resize h-full' : 'cursor-row-resize w-full'} {isDragging ? 'bg-primary' : ''}"
|
|
168
|
+
style="{isHorizontal ? `width: ${gutterSize}px` : `height: ${gutterSize}px`}; touch-action: none;"
|
|
169
|
+
role="separator"
|
|
170
|
+
tabindex="0"
|
|
171
|
+
aria-label="拖拽调整分栏大小"
|
|
172
|
+
aria-orientation={isHorizontal ? 'vertical' : 'horizontal'}
|
|
173
|
+
aria-valuenow={sizes[0]}
|
|
174
|
+
aria-valuemin={bounds()[0]}
|
|
175
|
+
aria-valuemax={bounds()[1]}
|
|
176
|
+
onpointerdown={handlePointerDown}
|
|
177
|
+
ondblclick={handleDoubleClick}
|
|
178
|
+
onkeydown={handleKeydown}
|
|
179
|
+
>
|
|
180
|
+
<!-- Center Grip Dots -->
|
|
181
|
+
<div class="pointer-events-none flex items-center justify-center opacity-60 group-hover:opacity-100 group-focus-within:opacity-100 {isHorizontal ? 'flex-col gap-1' : 'flex-row gap-1'}">
|
|
182
|
+
<span class="h-1 w-1 rounded-full bg-foreground/60"></span>
|
|
183
|
+
<span class="h-1 w-1 rounded-full bg-foreground/60"></span>
|
|
184
|
+
<span class="h-1 w-1 rounded-full bg-foreground/60"></span>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<!-- Quick collapse helper triggers on hover -->
|
|
188
|
+
{#if collapsible}
|
|
189
|
+
<div class="absolute flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 {isHorizontal ? 'flex-col' : 'flex-row'}">
|
|
190
|
+
<button
|
|
191
|
+
type="button"
|
|
192
|
+
class="flex h-4 w-4 items-center justify-center rounded-full bg-card text-[9px] text-muted-foreground shadow-xs hover:bg-primary hover:text-primary-foreground"
|
|
193
|
+
title="折叠左/上方"
|
|
194
|
+
onclick={(e) => {
|
|
195
|
+
e.stopPropagation();
|
|
196
|
+
toggleCollapse('first');
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
{isHorizontal ? '‹' : '▲'}
|
|
200
|
+
</button>
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
class="flex h-4 w-4 items-center justify-center rounded-full bg-card text-[9px] text-muted-foreground shadow-xs hover:bg-primary hover:text-primary-foreground"
|
|
204
|
+
title="折叠右/下方"
|
|
205
|
+
onclick={(e) => {
|
|
206
|
+
e.stopPropagation();
|
|
207
|
+
toggleCollapse('second');
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
{isHorizontal ? '›' : '▼'}
|
|
211
|
+
</button>
|
|
212
|
+
</div>
|
|
213
|
+
{/if}
|
|
214
|
+
</div>
|
|
215
|
+
{:else}
|
|
216
|
+
<!-- Collapsed Restore Bar -->
|
|
217
|
+
<div
|
|
218
|
+
class="relative z-10 flex shrink-0 items-center justify-center border-border bg-muted/40 p-1 {isHorizontal ? 'h-full border-x' : 'w-full border-y'}"
|
|
219
|
+
>
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
class="inline-flex items-center gap-1 rounded-md border border-border bg-card px-2 py-1 text-xs font-medium text-foreground shadow-xs hover:bg-muted"
|
|
223
|
+
onclick={() => {
|
|
224
|
+
if (collapsedPane) toggleCollapse(collapsedPane);
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
<span>恢复面板</span>
|
|
228
|
+
<span class="text-[10px] text-muted-foreground">({collapsedPane === 'first' ? '左/上' : '右/下'})</span>
|
|
229
|
+
</button>
|
|
230
|
+
</div>
|
|
231
|
+
{/if}
|
|
232
|
+
|
|
233
|
+
<!-- Second Pane -->
|
|
234
|
+
<div
|
|
235
|
+
class="relative min-h-0 min-w-0 overflow-auto transition-all duration-75 {collapsedPane === 'second' ? 'hidden' : ''}"
|
|
236
|
+
style:flex="{sizes[1]} 1 0%"
|
|
237
|
+
>
|
|
238
|
+
{#if secondPane}
|
|
239
|
+
{@render secondPane()}
|
|
240
|
+
{:else}
|
|
241
|
+
<div class="flex h-full w-full items-center justify-center p-4 text-xs text-muted-foreground">
|
|
242
|
+
面板 2 (Second Pane)
|
|
243
|
+
</div>
|
|
244
|
+
{/if}
|
|
245
|
+
</div>
|
|
246
|
+
</div>
|