@svadmin/ui 0.17.0 → 0.19.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/package.json +20 -2
- package/src/components/AboutSettings.svelte +106 -0
- package/src/components/AdminApp.svelte +5 -1
- package/src/components/AppearanceSettings.svelte +183 -0
- package/src/components/AuditLogViewer.svelte +226 -0
- package/src/components/AutoTable.svelte +12 -6
- package/src/components/CanAccess.svelte +1 -1
- package/src/components/DraggableGrid.svelte +90 -0
- package/src/components/FieldRenderer.svelte +4 -0
- package/src/components/MarkdownRenderer.svelte +0 -4
- package/src/components/PermissionMatrix.svelte +190 -0
- package/src/components/ProfilePage.svelte +139 -25
- package/src/components/RolesSettings.svelte +144 -0
- package/src/components/SettingsPage.svelte +113 -0
- package/src/components/Sidebar.svelte +3 -0
- package/src/components/TaskQueueDrawer.svelte +170 -0
- package/src/components/TenantSwitcher.svelte +90 -0
- package/src/components/buttons/CloneButton.svelte +3 -3
- package/src/components/buttons/CreateButton.svelte +3 -3
- package/src/components/buttons/DeleteButton.svelte +3 -3
- package/src/components/buttons/EditButton.svelte +3 -3
- package/src/components/buttons/ExportButton.svelte +3 -3
- package/src/components/buttons/ImportButton.svelte +3 -3
- package/src/components/buttons/ShowButton.svelte +3 -3
- package/src/components/fields/ArrayField.svelte +86 -0
- package/src/index.ts +14 -0
- package/src/markdown-deps.d.ts +21 -0
- package/src/components/stories/BarChart.stories.ts +0 -43
- package/src/components/stories/LineChart.stories.ts +0 -48
- package/src/components/stories/PieChart.stories.ts +0 -41
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { t } from '@svadmin/core/i18n';
|
|
3
|
+
import { navigate } from '@svadmin/core/router';
|
|
4
|
+
import { currentPath } from '@svadmin/core/router';
|
|
5
|
+
import { User, Palette, Info, Shield, FileSearch } from 'lucide-svelte';
|
|
6
|
+
import ProfilePage from './ProfilePage.svelte';
|
|
7
|
+
import AppearanceSettings from './AppearanceSettings.svelte';
|
|
8
|
+
import AboutSettings from './AboutSettings.svelte';
|
|
9
|
+
import RolesSettings from './RolesSettings.svelte';
|
|
10
|
+
import AuditLogViewer from './AuditLogViewer.svelte';
|
|
11
|
+
|
|
12
|
+
const sections = [
|
|
13
|
+
{
|
|
14
|
+
group: 'settings.general',
|
|
15
|
+
items: [
|
|
16
|
+
{ key: 'profile', path: '/settings/profile', icon: User, label: 'settings.profile' },
|
|
17
|
+
{ key: 'appearance', path: '/settings/appearance', icon: Palette, label: 'settings.appearance' },
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
group: 'settings.system',
|
|
22
|
+
items: [
|
|
23
|
+
{ key: 'roles', path: '/settings/roles', icon: Shield, label: 'settings.rolesAndPermissions' },
|
|
24
|
+
{ key: 'audit', path: '/settings/audit', icon: FileSearch, label: 'settings.auditLogs' },
|
|
25
|
+
{ key: 'about', path: '/settings/about', icon: Info, label: 'settings.about' },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
let activeKey = $derived.by(() => {
|
|
31
|
+
const path = currentPath();
|
|
32
|
+
if (path.includes('/settings/appearance')) return 'appearance';
|
|
33
|
+
if (path.includes('/settings/roles')) return 'roles';
|
|
34
|
+
if (path.includes('/settings/audit')) return 'audit';
|
|
35
|
+
if (path.includes('/settings/about')) return 'about';
|
|
36
|
+
return 'profile';
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Default redirect to profile
|
|
40
|
+
$effect(() => {
|
|
41
|
+
const path = currentPath();
|
|
42
|
+
if (path === '/settings') {
|
|
43
|
+
navigate('/settings/profile');
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<div class="flex flex-col lg:flex-row gap-0 min-h-full">
|
|
49
|
+
<!-- Left sidebar navigation -->
|
|
50
|
+
<nav class="w-full lg:w-56 shrink-0 border-b lg:border-b-0 lg:border-r border-border bg-muted/30">
|
|
51
|
+
<!-- Mobile: horizontal scroll tabs -->
|
|
52
|
+
<div class="flex lg:hidden overflow-x-auto px-4 py-2 gap-1">
|
|
53
|
+
{#each sections as section}
|
|
54
|
+
{#each section.items as item}
|
|
55
|
+
{@const active = activeKey === item.key}
|
|
56
|
+
<button
|
|
57
|
+
class="flex items-center gap-2 px-3 py-2 text-sm font-medium rounded-md whitespace-nowrap transition-colors
|
|
58
|
+
{active ? 'bg-background text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground hover:bg-background/50'}"
|
|
59
|
+
onclick={() => navigate(item.path)}
|
|
60
|
+
>
|
|
61
|
+
<item.icon class="h-4 w-4" />
|
|
62
|
+
{t(item.label)}
|
|
63
|
+
</button>
|
|
64
|
+
{/each}
|
|
65
|
+
{/each}
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<!-- Desktop: vertical nav with groups -->
|
|
69
|
+
<div class="hidden lg:block py-6 px-3 space-y-6">
|
|
70
|
+
<div class="px-3">
|
|
71
|
+
<h2 class="text-lg font-semibold text-foreground">{t('settings.title')}</h2>
|
|
72
|
+
<p class="text-xs text-muted-foreground mt-1">{t('settings.settingsDescription')}</p>
|
|
73
|
+
</div>
|
|
74
|
+
{#each sections as section}
|
|
75
|
+
<div>
|
|
76
|
+
<h3 class="px-3 mb-1 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60">
|
|
77
|
+
{t(section.group)}
|
|
78
|
+
</h3>
|
|
79
|
+
<div class="space-y-0.5">
|
|
80
|
+
{#each section.items as item}
|
|
81
|
+
{@const active = activeKey === item.key}
|
|
82
|
+
<button
|
|
83
|
+
class="flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm transition-all
|
|
84
|
+
{active
|
|
85
|
+
? 'bg-primary/10 text-primary font-medium'
|
|
86
|
+
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'}"
|
|
87
|
+
onclick={() => navigate(item.path)}
|
|
88
|
+
>
|
|
89
|
+
<item.icon class="h-4 w-4 shrink-0" />
|
|
90
|
+
{t(item.label)}
|
|
91
|
+
</button>
|
|
92
|
+
{/each}
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
{/each}
|
|
96
|
+
</div>
|
|
97
|
+
</nav>
|
|
98
|
+
|
|
99
|
+
<!-- Right content area -->
|
|
100
|
+
<div class="flex-1 p-6 lg:p-8 {activeKey === 'roles' || activeKey === 'audit' ? 'max-w-6xl' : 'max-w-3xl'}">
|
|
101
|
+
{#if activeKey === 'profile'}
|
|
102
|
+
<ProfilePage />
|
|
103
|
+
{:else if activeKey === 'appearance'}
|
|
104
|
+
<AppearanceSettings />
|
|
105
|
+
{:else if activeKey === 'roles'}
|
|
106
|
+
<RolesSettings />
|
|
107
|
+
{:else if activeKey === 'audit'}
|
|
108
|
+
<AuditLogViewer />
|
|
109
|
+
{:else if activeKey === 'about'}
|
|
110
|
+
<AboutSettings />
|
|
111
|
+
{/if}
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
@@ -325,6 +325,9 @@
|
|
|
325
325
|
<Moon class="h-4 w-4" />
|
|
326
326
|
{/if}
|
|
327
327
|
</TooltipButton>
|
|
328
|
+
<TooltipButton tooltip={t('settings.title')} variant="ghost" size="icon-sm" onclick={() => navigate('/settings')} class="text-sidebar-foreground/60 hover:text-sidebar-foreground">
|
|
329
|
+
<Settings class="h-4 w-4" />
|
|
330
|
+
</TooltipButton>
|
|
328
331
|
<TooltipButton tooltip={t('common.logout')} variant="ghost" size="icon-sm" onclick={onLogout} class="text-sidebar-foreground/60 hover:text-destructive">
|
|
329
332
|
<LogOut class="h-4 w-4" />
|
|
330
333
|
</TooltipButton>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { Loader2, CheckCircle2, XCircle, Clock, Download, X, ListTodo } from 'lucide-svelte';
|
|
4
|
+
import { Button } from './ui/button/index.js';
|
|
5
|
+
import { Badge } from './ui/badge/index.js';
|
|
6
|
+
|
|
7
|
+
export type TaskStatus = 'pending' | 'running' | 'completed' | 'failed';
|
|
8
|
+
|
|
9
|
+
export interface BackgroundTask {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
status: TaskStatus;
|
|
13
|
+
progress?: number; // 0-100
|
|
14
|
+
message?: string;
|
|
15
|
+
createdAt: string | Date;
|
|
16
|
+
downloadUrl?: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
open = $bindable(false),
|
|
22
|
+
tasks = $bindable<BackgroundTask[]>([]),
|
|
23
|
+
onDismiss,
|
|
24
|
+
onRetry,
|
|
25
|
+
onDownload,
|
|
26
|
+
}: {
|
|
27
|
+
open?: boolean;
|
|
28
|
+
tasks?: BackgroundTask[];
|
|
29
|
+
onDismiss?: (taskId: string) => void;
|
|
30
|
+
onRetry?: (taskId: string) => void;
|
|
31
|
+
onDownload?: (taskId: string, url: string) => void;
|
|
32
|
+
} = $props();
|
|
33
|
+
|
|
34
|
+
let runningCount = $derived(tasks.filter(t => t.status === 'running' || t.status === 'pending').length);
|
|
35
|
+
|
|
36
|
+
const statusIcon: Record<TaskStatus, typeof Loader2> = {
|
|
37
|
+
pending: Clock,
|
|
38
|
+
running: Loader2,
|
|
39
|
+
completed: CheckCircle2,
|
|
40
|
+
failed: XCircle,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const statusColor: Record<TaskStatus, string> = {
|
|
44
|
+
pending: 'text-muted-foreground',
|
|
45
|
+
running: 'text-primary',
|
|
46
|
+
completed: 'text-green-500',
|
|
47
|
+
failed: 'text-destructive',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function formatTime(d: string | Date) {
|
|
51
|
+
return new Date(d).toLocaleTimeString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function dismissTask(id: string) {
|
|
55
|
+
tasks = tasks.filter(t => t.id !== id);
|
|
56
|
+
onDismiss?.(id);
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<!-- Trigger Button (to be placed in Header) -->
|
|
61
|
+
<Button
|
|
62
|
+
variant="ghost"
|
|
63
|
+
size="icon"
|
|
64
|
+
class="relative"
|
|
65
|
+
onclick={() => open = !open}
|
|
66
|
+
>
|
|
67
|
+
<ListTodo class="h-4 w-4" />
|
|
68
|
+
{#if runningCount > 0}
|
|
69
|
+
<span class="absolute -top-0.5 -right-0.5 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] font-bold text-primary-foreground">
|
|
70
|
+
{runningCount}
|
|
71
|
+
</span>
|
|
72
|
+
{/if}
|
|
73
|
+
</Button>
|
|
74
|
+
|
|
75
|
+
<!-- Task Queue Drawer -->
|
|
76
|
+
{#if open}
|
|
77
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
78
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
79
|
+
<div class="fixed inset-0 z-[90] flex justify-end" onclick={() => open = false}>
|
|
80
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
81
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
82
|
+
<div
|
|
83
|
+
class="bg-card shadow-2xl w-full max-w-sm h-full flex flex-col border-l border-border animate-in slide-in-from-right duration-200"
|
|
84
|
+
onclick={(e) => e.stopPropagation()}
|
|
85
|
+
>
|
|
86
|
+
<!-- Header -->
|
|
87
|
+
<div class="p-4 border-b border-border flex items-center justify-between bg-muted/30">
|
|
88
|
+
<div class="flex items-center gap-2">
|
|
89
|
+
<ListTodo class="h-5 w-5 text-muted-foreground" />
|
|
90
|
+
<h2 class="text-sm font-semibold">Background Tasks</h2>
|
|
91
|
+
{#if runningCount > 0}
|
|
92
|
+
<Badge variant="secondary" class="text-xs">{runningCount} active</Badge>
|
|
93
|
+
{/if}
|
|
94
|
+
</div>
|
|
95
|
+
<Button variant="ghost" size="icon" class="h-7 w-7" onclick={() => open = false}>
|
|
96
|
+
<X class="h-4 w-4" />
|
|
97
|
+
</Button>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<!-- Task List -->
|
|
101
|
+
<div class="flex-1 overflow-y-auto">
|
|
102
|
+
{#each tasks as task}
|
|
103
|
+
{@const Icon = statusIcon[task.status]}
|
|
104
|
+
<div class="p-4 border-b border-border hover:bg-muted/30 transition-colors">
|
|
105
|
+
<div class="flex items-start justify-between gap-2">
|
|
106
|
+
<div class="flex items-start gap-3 flex-1 min-w-0">
|
|
107
|
+
<div class="{statusColor[task.status]} mt-0.5 shrink-0">
|
|
108
|
+
<Icon class="h-4 w-4 {task.status === 'running' ? 'animate-spin' : ''}" />
|
|
109
|
+
</div>
|
|
110
|
+
<div class="flex-1 min-w-0">
|
|
111
|
+
<p class="text-sm font-medium truncate text-foreground">{task.title}</p>
|
|
112
|
+
{#if task.message}
|
|
113
|
+
<p class="text-xs text-muted-foreground mt-0.5">{task.message}</p>
|
|
114
|
+
{/if}
|
|
115
|
+
<p class="text-[10px] text-muted-foreground/60 mt-1 font-mono">{formatTime(task.createdAt)}</p>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
<button
|
|
119
|
+
class="text-muted-foreground/40 hover:text-muted-foreground transition shrink-0"
|
|
120
|
+
onclick={() => dismissTask(task.id)}
|
|
121
|
+
>
|
|
122
|
+
<X class="h-3.5 w-3.5" />
|
|
123
|
+
</button>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<!-- Progress bar -->
|
|
127
|
+
{#if task.status === 'running' && task.progress != null}
|
|
128
|
+
<div class="mt-3 ml-7">
|
|
129
|
+
<div class="h-1.5 w-full bg-muted rounded-full overflow-hidden">
|
|
130
|
+
<div
|
|
131
|
+
class="h-full bg-primary rounded-full transition-all duration-500 ease-out"
|
|
132
|
+
style="width: {task.progress}%"
|
|
133
|
+
></div>
|
|
134
|
+
</div>
|
|
135
|
+
<p class="text-[10px] text-muted-foreground mt-1">{task.progress}%</p>
|
|
136
|
+
</div>
|
|
137
|
+
{/if}
|
|
138
|
+
|
|
139
|
+
<!-- Actions -->
|
|
140
|
+
{#if task.status === 'completed' && task.downloadUrl}
|
|
141
|
+
<div class="mt-2 ml-7">
|
|
142
|
+
<Button
|
|
143
|
+
variant="outline" size="sm" class="h-7 text-xs"
|
|
144
|
+
onclick={() => onDownload?.(task.id, task.downloadUrl!)}
|
|
145
|
+
>
|
|
146
|
+
<Download class="h-3 w-3 mr-1" />
|
|
147
|
+
Download
|
|
148
|
+
</Button>
|
|
149
|
+
</div>
|
|
150
|
+
{:else if task.status === 'failed' && onRetry}
|
|
151
|
+
<div class="mt-2 ml-7">
|
|
152
|
+
<Button
|
|
153
|
+
variant="outline" size="sm" class="h-7 text-xs text-destructive"
|
|
154
|
+
onclick={() => onRetry?.(task.id)}
|
|
155
|
+
>
|
|
156
|
+
Retry
|
|
157
|
+
</Button>
|
|
158
|
+
</div>
|
|
159
|
+
{/if}
|
|
160
|
+
</div>
|
|
161
|
+
{:else}
|
|
162
|
+
<div class="flex flex-col items-center justify-center h-48 text-muted-foreground">
|
|
163
|
+
<ListTodo class="h-8 w-8 mb-2 opacity-30" />
|
|
164
|
+
<p class="text-sm">No background tasks</p>
|
|
165
|
+
</div>
|
|
166
|
+
{/each}
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
{/if}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { ChevronsUpDown, Building2, Check } from 'lucide-svelte';
|
|
4
|
+
import { Button } from './ui/button/index.js';
|
|
5
|
+
import * as DropdownMenu from './ui/dropdown-menu/index.js';
|
|
6
|
+
|
|
7
|
+
export interface Tenant {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
logo?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
tenants = [],
|
|
16
|
+
currentTenantId = $bindable(''),
|
|
17
|
+
collapsed = false,
|
|
18
|
+
onSwitch,
|
|
19
|
+
headerSnippet,
|
|
20
|
+
}: {
|
|
21
|
+
tenants: Tenant[];
|
|
22
|
+
currentTenantId?: string;
|
|
23
|
+
collapsed?: boolean;
|
|
24
|
+
onSwitch?: (tenantId: string) => void;
|
|
25
|
+
headerSnippet?: Snippet;
|
|
26
|
+
} = $props();
|
|
27
|
+
|
|
28
|
+
let currentTenant = $derived(tenants.find(t => t.id === currentTenantId) ?? tenants[0]);
|
|
29
|
+
|
|
30
|
+
function selectTenant(id: string) {
|
|
31
|
+
currentTenantId = id;
|
|
32
|
+
onSwitch?.(id);
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{#if tenants.length > 0}
|
|
37
|
+
<DropdownMenu.Root>
|
|
38
|
+
<DropdownMenu.Trigger>
|
|
39
|
+
{#snippet child({ props }: { props: Record<string, unknown> })}
|
|
40
|
+
<button
|
|
41
|
+
{...props}
|
|
42
|
+
class="flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left transition-colors hover:bg-sidebar-accent/50
|
|
43
|
+
{collapsed ? 'justify-center' : ''}"
|
|
44
|
+
>
|
|
45
|
+
<div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary text-sm font-bold">
|
|
46
|
+
{#if currentTenant?.logo}
|
|
47
|
+
<img src={currentTenant.logo} alt={currentTenant.name} class="h-full w-full rounded-lg object-cover" />
|
|
48
|
+
{:else}
|
|
49
|
+
<Building2 class="h-4 w-4" />
|
|
50
|
+
{/if}
|
|
51
|
+
</div>
|
|
52
|
+
{#if !collapsed}
|
|
53
|
+
<div class="flex-1 min-w-0">
|
|
54
|
+
<p class="truncate text-sm font-semibold text-sidebar-foreground">{currentTenant?.name ?? 'Select'}</p>
|
|
55
|
+
<p class="truncate text-[10px] text-sidebar-foreground/50">Workspace</p>
|
|
56
|
+
</div>
|
|
57
|
+
<ChevronsUpDown class="h-4 w-4 shrink-0 text-sidebar-foreground/40" />
|
|
58
|
+
{/if}
|
|
59
|
+
</button>
|
|
60
|
+
{/snippet}
|
|
61
|
+
</DropdownMenu.Trigger>
|
|
62
|
+
<DropdownMenu.Content class="w-56" align="start" side="right" sideOffset={8}>
|
|
63
|
+
{#if headerSnippet}
|
|
64
|
+
<div class="px-2 py-1.5">
|
|
65
|
+
{@render headerSnippet()}
|
|
66
|
+
</div>
|
|
67
|
+
<DropdownMenu.Separator />
|
|
68
|
+
{/if}
|
|
69
|
+
<DropdownMenu.Label class="text-xs text-muted-foreground">Workspaces</DropdownMenu.Label>
|
|
70
|
+
{#each tenants as tenant}
|
|
71
|
+
<DropdownMenu.Item
|
|
72
|
+
class="flex items-center gap-3 cursor-pointer"
|
|
73
|
+
onclick={() => selectTenant(tenant.id)}
|
|
74
|
+
>
|
|
75
|
+
<div class="flex h-6 w-6 shrink-0 items-center justify-center rounded bg-primary/10 text-primary text-xs font-bold">
|
|
76
|
+
{#if tenant.logo}
|
|
77
|
+
<img src={tenant.logo} alt={tenant.name} class="h-full w-full rounded object-cover" />
|
|
78
|
+
{:else}
|
|
79
|
+
{tenant.name.charAt(0).toUpperCase()}
|
|
80
|
+
{/if}
|
|
81
|
+
</div>
|
|
82
|
+
<span class="flex-1 truncate">{tenant.name}</span>
|
|
83
|
+
{#if tenant.id === currentTenantId}
|
|
84
|
+
<Check class="h-4 w-4 text-primary" />
|
|
85
|
+
{/if}
|
|
86
|
+
</DropdownMenu.Item>
|
|
87
|
+
{/each}
|
|
88
|
+
</DropdownMenu.Content>
|
|
89
|
+
</DropdownMenu.Root>
|
|
90
|
+
{/if}
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
}>();
|
|
13
13
|
|
|
14
14
|
const nav = useNavigation();
|
|
15
|
-
const can =
|
|
16
|
-
const hidden = $derived(accessControl?.hideIfUnauthorized &&
|
|
15
|
+
const can = useCan(() => ({ resource, action: 'create', queryOptions: { enabled: accessControl?.enabled ?? true } }));
|
|
16
|
+
const hidden = $derived(accessControl?.hideIfUnauthorized && !can.allowed);
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
19
|
{#if !hidden}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
variant="outline"
|
|
22
22
|
size={hideText ? 'icon' : 'sm'}
|
|
23
23
|
class={className}
|
|
24
|
-
disabled={
|
|
24
|
+
disabled={!can.allowed}
|
|
25
25
|
onclick={() => nav.clone(resource, recordItemId)}
|
|
26
26
|
>
|
|
27
27
|
<Copy class="h-4 w-4" />
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
}>();
|
|
12
12
|
|
|
13
13
|
const nav = useNavigation();
|
|
14
|
-
const can =
|
|
15
|
-
const hidden = $derived(accessControl?.hideIfUnauthorized &&
|
|
14
|
+
const can = useCan(() => ({ resource, action: 'create', queryOptions: { enabled: accessControl?.enabled ?? true } }));
|
|
15
|
+
const hidden = $derived(accessControl?.hideIfUnauthorized && !can.allowed);
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
{#if !hidden}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
variant="default"
|
|
21
21
|
size={hideText ? 'icon' : 'default'}
|
|
22
22
|
class={className}
|
|
23
|
-
disabled={
|
|
23
|
+
disabled={!can.allowed}
|
|
24
24
|
onclick={() => nav.create(resource)}
|
|
25
25
|
>
|
|
26
26
|
<Plus class="h-4 w-4" />
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
}>();
|
|
18
18
|
|
|
19
19
|
const deleteMut = useDelete({ get resource() { return resource; }, get mutationMode() { return undoable ? 'undoable' as const : 'pessimistic' as const; } });
|
|
20
|
-
const can =
|
|
21
|
-
const hidden = $derived(accessControl?.hideIfUnauthorized &&
|
|
20
|
+
const can = useCan(() => ({ resource, action: 'delete', queryOptions: { enabled: accessControl?.enabled ?? true } }));
|
|
21
|
+
const hidden = $derived(accessControl?.hideIfUnauthorized && !can.allowed);
|
|
22
22
|
let confirming = $state(false);
|
|
23
23
|
|
|
24
24
|
async function handleDelete() {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
variant="ghost"
|
|
50
50
|
size={hideText ? 'icon' : 'sm'}
|
|
51
51
|
class="text-destructive hover:text-destructive {className}"
|
|
52
|
-
disabled={
|
|
52
|
+
disabled={!can.allowed}
|
|
53
53
|
onclick={handleDelete}
|
|
54
54
|
>
|
|
55
55
|
<Trash2 class="h-4 w-4" />
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
}>();
|
|
13
13
|
|
|
14
14
|
const nav = useNavigation();
|
|
15
|
-
const can =
|
|
16
|
-
const hidden = $derived(accessControl?.hideIfUnauthorized &&
|
|
15
|
+
const can = useCan(() => ({ resource, action: 'edit', queryOptions: { enabled: accessControl?.enabled ?? true } }));
|
|
16
|
+
const hidden = $derived(accessControl?.hideIfUnauthorized && !can.allowed);
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
19
|
{#if !hidden}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
variant="outline"
|
|
22
22
|
size={hideText ? 'icon' : 'sm'}
|
|
23
23
|
class={className}
|
|
24
|
-
disabled={
|
|
24
|
+
disabled={!can.allowed}
|
|
25
25
|
onclick={() => nav.edit(resource, recordItemId)}
|
|
26
26
|
>
|
|
27
27
|
<Pencil class="h-4 w-4" />
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
}>();
|
|
12
12
|
|
|
13
13
|
const { triggerExport, isLoading } = useExport({ get resource() { return resource; } });
|
|
14
|
-
const can =
|
|
15
|
-
const hidden = $derived(accessControl?.hideIfUnauthorized &&
|
|
14
|
+
const can = useCan(() => ({ resource, action: 'export', queryOptions: { enabled: accessControl?.enabled ?? true } }));
|
|
15
|
+
const hidden = $derived(accessControl?.hideIfUnauthorized && !can.allowed);
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
{#if !hidden}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
variant="outline"
|
|
22
22
|
size={hideText ? 'icon' : 'sm'}
|
|
23
23
|
class={className}
|
|
24
|
-
disabled={isLoading ||
|
|
24
|
+
disabled={isLoading || !can.allowed}
|
|
25
25
|
onclick={triggerExport}
|
|
26
26
|
>
|
|
27
27
|
<Download class="h-4 w-4" />
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const can =
|
|
35
|
-
const hidden = $derived(accessControl?.hideIfUnauthorized &&
|
|
34
|
+
const can = useCan(() => ({ resource, action: 'import', queryOptions: { enabled: accessControl?.enabled ?? true } }));
|
|
35
|
+
const hidden = $derived(accessControl?.hideIfUnauthorized && !can.allowed);
|
|
36
36
|
</script>
|
|
37
37
|
|
|
38
38
|
{#if !hidden}
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
variant="outline"
|
|
48
48
|
size={hideText ? 'icon' : 'sm'}
|
|
49
49
|
class={className}
|
|
50
|
-
disabled={importHook.isLoading ||
|
|
50
|
+
disabled={importHook.isLoading || !can.allowed}
|
|
51
51
|
onclick={triggerImport}
|
|
52
52
|
>
|
|
53
53
|
<Upload class="h-4 w-4" />
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
}>();
|
|
13
13
|
|
|
14
14
|
const nav = useNavigation();
|
|
15
|
-
const can =
|
|
16
|
-
const hidden = $derived(accessControl?.hideIfUnauthorized &&
|
|
15
|
+
const can = useCan(() => ({ resource, action: 'show', queryOptions: { enabled: accessControl?.enabled ?? true } }));
|
|
16
|
+
const hidden = $derived(accessControl?.hideIfUnauthorized && !can.allowed);
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
19
|
{#if !hidden}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
variant="ghost"
|
|
23
23
|
size={hideText ? 'icon' : 'sm'}
|
|
24
24
|
class={className}
|
|
25
|
-
disabled={
|
|
25
|
+
disabled={!can.allowed}
|
|
26
26
|
onclick={() => nav.show(resource, recordItemId)}
|
|
27
27
|
>
|
|
28
28
|
<Eye class="h-4 w-4" />
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { FieldDefinition } from '@svadmin/core';
|
|
3
|
+
import { t } from '@svadmin/core/i18n';
|
|
4
|
+
import { Button } from '../ui/button/index.js';
|
|
5
|
+
import { Plus, Trash2 } from 'lucide-svelte';
|
|
6
|
+
import TooltipButton from '../TooltipButton.svelte';
|
|
7
|
+
import FieldRenderer from '../FieldRenderer.svelte';
|
|
8
|
+
|
|
9
|
+
let { field, value, onchange } = $props<{
|
|
10
|
+
field: FieldDefinition;
|
|
11
|
+
value: unknown;
|
|
12
|
+
onchange: (val: unknown) => void;
|
|
13
|
+
}>();
|
|
14
|
+
|
|
15
|
+
const arrayVal = $derived(Array.isArray(value) ? value : []);
|
|
16
|
+
const subFields = $derived(field.subFields || []);
|
|
17
|
+
|
|
18
|
+
function getDefaultForType(type: string): unknown {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'text': case 'textarea': case 'richtext': case 'image': return '';
|
|
21
|
+
case 'number': return 0;
|
|
22
|
+
case 'boolean': return false;
|
|
23
|
+
case 'tags': case 'images': case 'multiselect': case 'array': return [];
|
|
24
|
+
case 'json': return {};
|
|
25
|
+
default: return '';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function handleAdd() {
|
|
30
|
+
const newItem: Record<string, unknown> = {};
|
|
31
|
+
for (const f of subFields) {
|
|
32
|
+
newItem[f.key] = f.defaultValue ?? getDefaultForType(f.type);
|
|
33
|
+
}
|
|
34
|
+
onchange([...arrayVal, newItem]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function handleRemove(index: number) {
|
|
38
|
+
onchange(arrayVal.filter((_, i) => i !== index));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function handleChange(index: number, key: string, val: unknown) {
|
|
42
|
+
const next = [...arrayVal];
|
|
43
|
+
next[index] = { ...next[index], [key]: val };
|
|
44
|
+
onchange(next);
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<div class="space-y-4 rounded-lg border border-dashed p-4">
|
|
49
|
+
<div class="flex items-center justify-between">
|
|
50
|
+
<div class="text-sm font-medium text-foreground">
|
|
51
|
+
{field.label}
|
|
52
|
+
{#if field.required}
|
|
53
|
+
<span class="text-destructive">*</span>
|
|
54
|
+
{/if}
|
|
55
|
+
</div>
|
|
56
|
+
<Button variant="outline" size="sm" type="button" onclick={handleAdd}>
|
|
57
|
+
<Plus class="h-3.5 w-3.5 mr-1" /> {t('common.add') || 'Add'}
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<div class="space-y-4 pt-2">
|
|
62
|
+
{#each arrayVal as item, i}
|
|
63
|
+
<div class="relative rounded-md border bg-card p-4 pt-6 shadow-sm">
|
|
64
|
+
<div class="absolute right-2 top-2">
|
|
65
|
+
<TooltipButton tooltip={t('common.remove') || 'Remove'} variant="ghost" size="icon" class="h-8 w-8 text-muted-foreground hover:text-destructive transition-colors" onclick={() => handleRemove(i)}>
|
|
66
|
+
<Trash2 class="h-4 w-4" />
|
|
67
|
+
</TooltipButton>
|
|
68
|
+
</div>
|
|
69
|
+
<div class="grid gap-5">
|
|
70
|
+
{#each subFields as subField (subField.key)}
|
|
71
|
+
<FieldRenderer
|
|
72
|
+
field={subField}
|
|
73
|
+
value={item[subField.key]}
|
|
74
|
+
onchange={(val) => handleChange(i, subField.key, val)}
|
|
75
|
+
/>
|
|
76
|
+
{/each}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
{/each}
|
|
80
|
+
{#if arrayVal.length === 0}
|
|
81
|
+
<div class="flex flex-col items-center justify-center py-6 text-sm text-muted-foreground bg-muted/10 rounded-md">
|
|
82
|
+
<span>{t('common.noData') || 'No items added yet.'}</span>
|
|
83
|
+
</div>
|
|
84
|
+
{/if}
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ export { default as LoginPage } from './components/LoginPage.svelte';
|
|
|
22
22
|
export { default as RegisterPage } from './components/RegisterPage.svelte';
|
|
23
23
|
export { default as ForgotPasswordPage } from './components/ForgotPasswordPage.svelte';
|
|
24
24
|
export { default as CanAccess } from './components/CanAccess.svelte';
|
|
25
|
+
export { default as Can } from './components/CanAccess.svelte';
|
|
25
26
|
export { default as UndoableNotification } from './components/UndoableNotification.svelte';
|
|
26
27
|
export { default as ModalForm } from './components/ModalForm.svelte';
|
|
27
28
|
export { default as DrawerForm } from './components/DrawerForm.svelte';
|
|
@@ -59,6 +60,19 @@ export { default as KeyboardShortcuts } from "./components/KeyboardShortcuts.sve
|
|
|
59
60
|
export { default as InlineEdit } from "./components/InlineEdit.svelte";
|
|
60
61
|
export { default as VirtualTable } from "./components/VirtualTable.svelte";
|
|
61
62
|
export { default as DraggableHeader } from "./components/DraggableHeader.svelte";
|
|
63
|
+
export { default as SettingsPage } from "./components/SettingsPage.svelte";
|
|
64
|
+
export { default as AppearanceSettings } from "./components/AppearanceSettings.svelte";
|
|
65
|
+
export { default as AboutSettings } from "./components/AboutSettings.svelte";
|
|
66
|
+
export { default as PermissionMatrix } from "./components/PermissionMatrix.svelte";
|
|
67
|
+
export type { RoleInfo, ResourceInfo, ActionInfo } from "./components/PermissionMatrix.svelte";
|
|
68
|
+
export { default as RolesSettings } from "./components/RolesSettings.svelte";
|
|
69
|
+
export { default as AuditLogViewer } from "./components/AuditLogViewer.svelte";
|
|
70
|
+
export { default as TenantSwitcher } from "./components/TenantSwitcher.svelte";
|
|
71
|
+
export type { Tenant } from "./components/TenantSwitcher.svelte";
|
|
72
|
+
export { default as TaskQueueDrawer } from "./components/TaskQueueDrawer.svelte";
|
|
73
|
+
export type { BackgroundTask, TaskStatus } from "./components/TaskQueueDrawer.svelte";
|
|
74
|
+
export { default as DraggableGrid } from "./components/DraggableGrid.svelte";
|
|
75
|
+
export type { GridModule } from "./components/DraggableGrid.svelte";
|
|
62
76
|
|
|
63
77
|
// Dashboard Charts (zero-dependency SVG)
|
|
64
78
|
export { BarChart, LineChart, PieChart } from './components/charts/index.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Type declarations for MarkdownRenderer dependencies
|
|
2
|
+
declare module 'marked' {
|
|
3
|
+
export class Marked {
|
|
4
|
+
constructor(...extensions: unknown[]);
|
|
5
|
+
parse(src: string): string;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module 'marked-highlight' {
|
|
10
|
+
export function markedHighlight(options: {
|
|
11
|
+
langPrefix?: string;
|
|
12
|
+
highlight: (code: string, lang: string) => string;
|
|
13
|
+
}): unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module 'isomorphic-dompurify' {
|
|
17
|
+
const DOMPurify: {
|
|
18
|
+
sanitize(dirty: string, config?: Record<string, unknown>): string;
|
|
19
|
+
};
|
|
20
|
+
export default DOMPurify;
|
|
21
|
+
}
|