@svadmin/ui 0.112.0 → 0.114.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 +254 -0
- package/dist/app.theme.css +254 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/DetailDrawer.svelte +4 -3
- package/dist/components/FormDependency.svelte +36 -0
- package/dist/components/FormDependency.svelte.d.ts +12 -0
- package/dist/components/PageContainer.svelte +263 -0
- package/dist/components/PageContainer.svelte.d.ts +53 -0
- package/dist/components/ProDescriptions.svelte +278 -0
- package/dist/components/ProDescriptions.svelte.d.ts +37 -0
- package/dist/components/QueryFilter.svelte +194 -0
- package/dist/components/QueryFilter.svelte.d.ts +34 -0
- package/dist/components/RealtimeMonitorView.svelte +245 -0
- package/dist/components/RealtimeMonitorView.svelte.d.ts +40 -0
- package/dist/components/RoleSwitcher.svelte +267 -0
- package/dist/components/RoleSwitcher.svelte.d.ts +40 -0
- package/dist/components/VirtualTable.svelte +2 -2
- package/dist/components/WorkflowDesigner.svelte +244 -0
- package/dist/components/WorkflowDesigner.svelte.d.ts +29 -0
- package/dist/components/fields/UploadField.svelte +222 -0
- package/dist/components/fields/UploadField.svelte.d.ts +14 -0
- package/dist/components/icons/IconApprove.svelte +35 -0
- package/dist/components/icons/IconApprove.svelte.d.ts +4 -0
- package/dist/components/icons/IconAudit.svelte +38 -0
- package/dist/components/icons/IconAudit.svelte.d.ts +4 -0
- package/dist/components/icons/IconBilling.svelte +37 -0
- package/dist/components/icons/IconBilling.svelte.d.ts +4 -0
- package/dist/components/icons/IconCluster.svelte +41 -0
- package/dist/components/icons/IconCluster.svelte.d.ts +4 -0
- package/dist/components/icons/IconMonitor.svelte +37 -0
- package/dist/components/icons/IconMonitor.svelte.d.ts +4 -0
- package/dist/components/icons/IconReject.svelte +36 -0
- package/dist/components/icons/IconReject.svelte.d.ts +4 -0
- package/dist/components/icons/IconSeal.svelte +36 -0
- package/dist/components/icons/IconSeal.svelte.d.ts +4 -0
- package/dist/components/icons/IconSecurity.svelte +35 -0
- package/dist/components/icons/IconSecurity.svelte.d.ts +4 -0
- package/dist/components/icons/IconTenant.svelte +39 -0
- package/dist/components/icons/IconTenant.svelte.d.ts +4 -0
- package/dist/components/icons/IconWorkflow.svelte +38 -0
- package/dist/components/icons/IconWorkflow.svelte.d.ts +4 -0
- package/dist/components/icons/index.d.ts +11 -0
- package/dist/components/icons/index.js +10 -0
- package/dist/components/icons/types.d.ts +15 -0
- package/dist/components/icons/types.js +1 -0
- package/dist/index.d.ts +23 -5
- package/dist/index.js +17 -5
- package/package.json +5 -5
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../utils';
|
|
4
|
+
|
|
5
|
+
export interface PageContainerTab {
|
|
6
|
+
key: string;
|
|
7
|
+
label: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PageContainerTag {
|
|
12
|
+
label: string;
|
|
13
|
+
tone?: 'primary' | 'success' | 'warning' | 'danger' | 'neutral';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PageContainerBreadcrumb {
|
|
17
|
+
label: string;
|
|
18
|
+
href?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PageContainerProps {
|
|
22
|
+
/** Main page title text */
|
|
23
|
+
title?: string;
|
|
24
|
+
/** Subtitle or secondary description text */
|
|
25
|
+
subTitle?: string;
|
|
26
|
+
/** Breadcrumb trail items */
|
|
27
|
+
breadcrumbs?: PageContainerBreadcrumb[];
|
|
28
|
+
/** Whether to show back navigation button */
|
|
29
|
+
backIcon?: boolean;
|
|
30
|
+
/** Callback when back button is clicked */
|
|
31
|
+
onback?: () => void;
|
|
32
|
+
/** Status tags or badges displayed next to the title */
|
|
33
|
+
tags?: PageContainerTag[];
|
|
34
|
+
/** Header tabs navigation items */
|
|
35
|
+
tabs?: PageContainerTab[];
|
|
36
|
+
/** Currently active tab key */
|
|
37
|
+
activeTab?: string;
|
|
38
|
+
/** Callback triggered when a tab is selected */
|
|
39
|
+
ontabchange?: (key: string) => void;
|
|
40
|
+
/** If true, content has no card wrapper background (transparent) */
|
|
41
|
+
ghost?: boolean;
|
|
42
|
+
/** Content container width layout ('fluid' or 'fixed') */
|
|
43
|
+
contentWidth?: 'fluid' | 'fixed';
|
|
44
|
+
/** Whether header is fixed at top */
|
|
45
|
+
fixedHeader?: boolean;
|
|
46
|
+
/** Main content body */
|
|
47
|
+
children?: Snippet;
|
|
48
|
+
/** Custom complete header slot */
|
|
49
|
+
header?: Snippet;
|
|
50
|
+
/** Extra actions slot placed on top right */
|
|
51
|
+
extra?: Snippet;
|
|
52
|
+
/** Footer slot for header (below tabs or extra info) */
|
|
53
|
+
footer?: Snippet;
|
|
54
|
+
/** Additional classes */
|
|
55
|
+
class?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let {
|
|
59
|
+
title,
|
|
60
|
+
subTitle,
|
|
61
|
+
breadcrumbs,
|
|
62
|
+
backIcon = false,
|
|
63
|
+
onback,
|
|
64
|
+
tags,
|
|
65
|
+
tabs,
|
|
66
|
+
activeTab = $bindable(),
|
|
67
|
+
ontabchange,
|
|
68
|
+
ghost = false,
|
|
69
|
+
contentWidth = 'fluid',
|
|
70
|
+
fixedHeader = false,
|
|
71
|
+
children,
|
|
72
|
+
header,
|
|
73
|
+
extra,
|
|
74
|
+
footer,
|
|
75
|
+
class: className = '',
|
|
76
|
+
}: PageContainerProps = $props();
|
|
77
|
+
|
|
78
|
+
let internalActiveTab = $derived(activeTab ?? tabs?.[0]?.key ?? '');
|
|
79
|
+
|
|
80
|
+
function handleTabClick(tab: PageContainerTab) {
|
|
81
|
+
if (tab.disabled) return;
|
|
82
|
+
internalActiveTab = tab.key;
|
|
83
|
+
activeTab = tab.key;
|
|
84
|
+
ontabchange?.(tab.key);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function handleBack() {
|
|
88
|
+
onback?.();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getTagToneClasses(tone?: PageContainerTag['tone']): string {
|
|
92
|
+
switch (tone) {
|
|
93
|
+
case 'success':
|
|
94
|
+
return 'bg-success/10 text-success border-success/30';
|
|
95
|
+
case 'warning':
|
|
96
|
+
return 'bg-warning/10 text-warning border-warning/30';
|
|
97
|
+
case 'danger':
|
|
98
|
+
return 'bg-destructive/10 text-destructive border-destructive/30';
|
|
99
|
+
case 'primary':
|
|
100
|
+
return 'bg-primary/10 text-primary border-primary/30';
|
|
101
|
+
case 'neutral':
|
|
102
|
+
default:
|
|
103
|
+
return 'bg-muted text-muted-foreground border-border';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<div
|
|
109
|
+
data-svadmin-component="PageContainer"
|
|
110
|
+
class={cn(
|
|
111
|
+
'svadmin-page-container min-h-full w-full bg-background',
|
|
112
|
+
className
|
|
113
|
+
)}
|
|
114
|
+
>
|
|
115
|
+
<!-- Page Header Container -->
|
|
116
|
+
{#if header}
|
|
117
|
+
{@render header()}
|
|
118
|
+
{:else if title || breadcrumbs || extra || tabs}
|
|
119
|
+
<header
|
|
120
|
+
class={cn(
|
|
121
|
+
'svadmin-page-header border-b border-border bg-card px-6 pt-4 pb-0 transition-all',
|
|
122
|
+
fixedHeader && 'sticky top-0 z-20 shadow-xs'
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
<div
|
|
126
|
+
class={cn(
|
|
127
|
+
'mx-auto w-full',
|
|
128
|
+
contentWidth === 'fixed' && 'max-w-7xl'
|
|
129
|
+
)}
|
|
130
|
+
>
|
|
131
|
+
<!-- Breadcrumb row -->
|
|
132
|
+
{#if breadcrumbs && breadcrumbs.length > 0}
|
|
133
|
+
<nav aria-label="Breadcrumb" class="mb-2 flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
134
|
+
{#each breadcrumbs as item, index (item.href ?? `${item.label}-${index}`)}
|
|
135
|
+
{#if index > 0}
|
|
136
|
+
<span class="text-muted select-none">/</span>
|
|
137
|
+
{/if}
|
|
138
|
+
{#if item.href}
|
|
139
|
+
<a
|
|
140
|
+
href={item.href}
|
|
141
|
+
class="transition-colors hover:text-primary focus-visible:outline-none"
|
|
142
|
+
>
|
|
143
|
+
{item.label}
|
|
144
|
+
</a>
|
|
145
|
+
{:else}
|
|
146
|
+
<span class="text-foreground font-normal">{item.label}</span>
|
|
147
|
+
{/if}
|
|
148
|
+
{/each}
|
|
149
|
+
</nav>
|
|
150
|
+
{/if}
|
|
151
|
+
|
|
152
|
+
<!-- Title & Extra row -->
|
|
153
|
+
<div class="flex flex-wrap items-center justify-between gap-3 pb-4">
|
|
154
|
+
<div class="flex flex-wrap items-center gap-2.5">
|
|
155
|
+
{#if backIcon || onback}
|
|
156
|
+
<button
|
|
157
|
+
type="button"
|
|
158
|
+
aria-label="返回上一页"
|
|
159
|
+
class="inline-flex h-7 w-7 items-center justify-center rounded-[4px] border border-border text-muted-foreground transition-colors hover:bg-muted hover:text-primary active:bg-accent"
|
|
160
|
+
onclick={handleBack}
|
|
161
|
+
>
|
|
162
|
+
<svg
|
|
163
|
+
class="h-4 w-4"
|
|
164
|
+
viewBox="0 0 24 24"
|
|
165
|
+
fill="none"
|
|
166
|
+
stroke="currentColor"
|
|
167
|
+
stroke-width="2"
|
|
168
|
+
stroke-linecap="round"
|
|
169
|
+
stroke-linejoin="round"
|
|
170
|
+
>
|
|
171
|
+
<path d="m15 18-6-6 6-6" />
|
|
172
|
+
</svg>
|
|
173
|
+
</button>
|
|
174
|
+
{/if}
|
|
175
|
+
|
|
176
|
+
{#if title}
|
|
177
|
+
<h1 class="text-lg font-semibold tracking-tight text-foreground">
|
|
178
|
+
{title}
|
|
179
|
+
</h1>
|
|
180
|
+
{/if}
|
|
181
|
+
|
|
182
|
+
{#if subTitle}
|
|
183
|
+
<span class="hidden sm:inline-block border-l border-border pl-2.5 text-xs text-muted-foreground">
|
|
184
|
+
{subTitle}
|
|
185
|
+
</span>
|
|
186
|
+
{/if}
|
|
187
|
+
|
|
188
|
+
{#if tags && tags.length > 0}
|
|
189
|
+
<div class="ml-1 flex items-center gap-1.5">
|
|
190
|
+
{#each tags as tag (tag.label)}
|
|
191
|
+
<span
|
|
192
|
+
class={cn(
|
|
193
|
+
'inline-flex items-center rounded-[2px] border px-2 py-0.5 text-[11px] font-medium leading-none select-none',
|
|
194
|
+
getTagToneClasses(tag.tone)
|
|
195
|
+
)}
|
|
196
|
+
>
|
|
197
|
+
{tag.label}
|
|
198
|
+
</span>
|
|
199
|
+
{/each}
|
|
200
|
+
</div>
|
|
201
|
+
{/if}
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
{#if extra}
|
|
205
|
+
<div class="flex items-center gap-2">
|
|
206
|
+
{@render extra()}
|
|
207
|
+
</div>
|
|
208
|
+
{/if}
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<!-- Header Tabs -->
|
|
212
|
+
{#if tabs && tabs.length > 0}
|
|
213
|
+
<div role="tablist" class="flex items-center gap-6 border-t border-border/60 -mb-[1px]">
|
|
214
|
+
{#each tabs as tab (tab.key)}
|
|
215
|
+
<button
|
|
216
|
+
type="button"
|
|
217
|
+
role="tab"
|
|
218
|
+
aria-selected={internalActiveTab === tab.key}
|
|
219
|
+
disabled={tab.disabled}
|
|
220
|
+
class={cn(
|
|
221
|
+
'relative py-2.5 text-xs font-medium transition-colors focus-visible:outline-none',
|
|
222
|
+
internalActiveTab === tab.key
|
|
223
|
+
? 'text-primary font-semibold'
|
|
224
|
+
: 'text-muted-foreground hover:text-primary',
|
|
225
|
+
tab.disabled && 'cursor-not-allowed opacity-40 hover:text-inherit'
|
|
226
|
+
)}
|
|
227
|
+
onclick={() => handleTabClick(tab)}
|
|
228
|
+
>
|
|
229
|
+
{tab.label}
|
|
230
|
+
{#if internalActiveTab === tab.key}
|
|
231
|
+
<span
|
|
232
|
+
class="absolute bottom-0 left-0 right-0 h-[2px] rounded-full bg-primary"
|
|
233
|
+
></span>
|
|
234
|
+
{/if}
|
|
235
|
+
</button>
|
|
236
|
+
{/each}
|
|
237
|
+
</div>
|
|
238
|
+
{/if}
|
|
239
|
+
|
|
240
|
+
{#if footer}
|
|
241
|
+
<div class="pt-2 pb-3">
|
|
242
|
+
{@render footer()}
|
|
243
|
+
</div>
|
|
244
|
+
{/if}
|
|
245
|
+
</div>
|
|
246
|
+
</header>
|
|
247
|
+
{/if}
|
|
248
|
+
|
|
249
|
+
<!-- Content Container -->
|
|
250
|
+
<main class="w-full p-5 sm:p-6">
|
|
251
|
+
<div
|
|
252
|
+
class={cn(
|
|
253
|
+
'mx-auto w-full transition-all',
|
|
254
|
+
contentWidth === 'fixed' && 'max-w-7xl',
|
|
255
|
+
!ghost && 'rounded-[4px] border border-border bg-card p-5 shadow-xs'
|
|
256
|
+
)}
|
|
257
|
+
>
|
|
258
|
+
{#if children}
|
|
259
|
+
{@render children()}
|
|
260
|
+
{/if}
|
|
261
|
+
</div>
|
|
262
|
+
</main>
|
|
263
|
+
</div>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface PageContainerTab {
|
|
3
|
+
key: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PageContainerTag {
|
|
8
|
+
label: string;
|
|
9
|
+
tone?: 'primary' | 'success' | 'warning' | 'danger' | 'neutral';
|
|
10
|
+
}
|
|
11
|
+
export interface PageContainerBreadcrumb {
|
|
12
|
+
label: string;
|
|
13
|
+
href?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PageContainerProps {
|
|
16
|
+
/** Main page title text */
|
|
17
|
+
title?: string;
|
|
18
|
+
/** Subtitle or secondary description text */
|
|
19
|
+
subTitle?: string;
|
|
20
|
+
/** Breadcrumb trail items */
|
|
21
|
+
breadcrumbs?: PageContainerBreadcrumb[];
|
|
22
|
+
/** Whether to show back navigation button */
|
|
23
|
+
backIcon?: boolean;
|
|
24
|
+
/** Callback when back button is clicked */
|
|
25
|
+
onback?: () => void;
|
|
26
|
+
/** Status tags or badges displayed next to the title */
|
|
27
|
+
tags?: PageContainerTag[];
|
|
28
|
+
/** Header tabs navigation items */
|
|
29
|
+
tabs?: PageContainerTab[];
|
|
30
|
+
/** Currently active tab key */
|
|
31
|
+
activeTab?: string;
|
|
32
|
+
/** Callback triggered when a tab is selected */
|
|
33
|
+
ontabchange?: (key: string) => void;
|
|
34
|
+
/** If true, content has no card wrapper background (transparent) */
|
|
35
|
+
ghost?: boolean;
|
|
36
|
+
/** Content container width layout ('fluid' or 'fixed') */
|
|
37
|
+
contentWidth?: 'fluid' | 'fixed';
|
|
38
|
+
/** Whether header is fixed at top */
|
|
39
|
+
fixedHeader?: boolean;
|
|
40
|
+
/** Main content body */
|
|
41
|
+
children?: Snippet;
|
|
42
|
+
/** Custom complete header slot */
|
|
43
|
+
header?: Snippet;
|
|
44
|
+
/** Extra actions slot placed on top right */
|
|
45
|
+
extra?: Snippet;
|
|
46
|
+
/** Footer slot for header (below tabs or extra info) */
|
|
47
|
+
footer?: Snippet;
|
|
48
|
+
/** Additional classes */
|
|
49
|
+
class?: string;
|
|
50
|
+
}
|
|
51
|
+
declare const PageContainer: import("svelte").Component<PageContainerProps, {}, "activeTab">;
|
|
52
|
+
type PageContainer = ReturnType<typeof PageContainer>;
|
|
53
|
+
export default PageContainer;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../utils';
|
|
4
|
+
|
|
5
|
+
export interface ProDescriptionItem {
|
|
6
|
+
key: string;
|
|
7
|
+
label: string;
|
|
8
|
+
value?: unknown;
|
|
9
|
+
span?: number;
|
|
10
|
+
editable?: boolean;
|
|
11
|
+
type?: 'text' | 'number' | 'tag' | 'badge';
|
|
12
|
+
tone?: 'primary' | 'success' | 'warning' | 'danger' | 'neutral';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ProDescriptionsProps {
|
|
16
|
+
/** Title of the descriptions card */
|
|
17
|
+
title?: string;
|
|
18
|
+
/** Whether to display a border around the container and between cells (default: true) */
|
|
19
|
+
bordered?: boolean;
|
|
20
|
+
/** Number of columns in a row (1, 2, 3, or 4, default: 3) */
|
|
21
|
+
columns?: 1 | 2 | 3 | 4;
|
|
22
|
+
/** Density / size of the cells: 'small' | 'default' | 'large' (default: 'default') */
|
|
23
|
+
size?: 'small' | 'default' | 'large';
|
|
24
|
+
/** Layout direction of label and value: 'horizontal' | 'vertical' (default: 'horizontal') */
|
|
25
|
+
layout?: 'horizontal' | 'vertical';
|
|
26
|
+
/** List of description items to render */
|
|
27
|
+
items?: ProDescriptionItem[];
|
|
28
|
+
/** Whether inline editing is enabled globally */
|
|
29
|
+
editable?: boolean;
|
|
30
|
+
/** Callback triggered when a field value is saved */
|
|
31
|
+
onedit?: (key: string, value: unknown) => void | Promise<void>;
|
|
32
|
+
/** Extra actions slot on the top right */
|
|
33
|
+
extra?: Snippet;
|
|
34
|
+
/** Children slot */
|
|
35
|
+
children?: Snippet;
|
|
36
|
+
/** Additional CSS classes */
|
|
37
|
+
class?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
title,
|
|
42
|
+
bordered = true,
|
|
43
|
+
columns = 3,
|
|
44
|
+
size = 'default',
|
|
45
|
+
layout = 'horizontal',
|
|
46
|
+
items = [],
|
|
47
|
+
editable = false,
|
|
48
|
+
onedit,
|
|
49
|
+
extra,
|
|
50
|
+
children,
|
|
51
|
+
class: className = '',
|
|
52
|
+
}: ProDescriptionsProps = $props();
|
|
53
|
+
|
|
54
|
+
let editingKey = $state<string | null>(null);
|
|
55
|
+
let editValue = $state<unknown>('');
|
|
56
|
+
let isSaving = $state(false);
|
|
57
|
+
|
|
58
|
+
function startEdit(item: ProDescriptionItem) {
|
|
59
|
+
editingKey = item.key;
|
|
60
|
+
editValue = item.value ?? '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function cancelEdit() {
|
|
64
|
+
editingKey = null;
|
|
65
|
+
editValue = '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function saveEdit(key: string) {
|
|
69
|
+
if (!onedit) {
|
|
70
|
+
editingKey = null;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
isSaving = true;
|
|
74
|
+
try {
|
|
75
|
+
await onedit(key, editValue);
|
|
76
|
+
editingKey = null;
|
|
77
|
+
} finally {
|
|
78
|
+
isSaving = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getPaddingClass(size: 'small' | 'default' | 'large'): string {
|
|
83
|
+
switch (size) {
|
|
84
|
+
case 'small':
|
|
85
|
+
return 'px-3 py-1.5 text-xs';
|
|
86
|
+
case 'large':
|
|
87
|
+
return 'px-5 py-3.5 text-sm';
|
|
88
|
+
case 'default':
|
|
89
|
+
default:
|
|
90
|
+
return 'px-4 py-2.5 text-xs';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getTagToneClasses(tone?: ProDescriptionItem['tone']): string {
|
|
95
|
+
switch (tone) {
|
|
96
|
+
case 'success':
|
|
97
|
+
return 'bg-success/10 text-success border-success/30';
|
|
98
|
+
case 'warning':
|
|
99
|
+
return 'bg-warning/10 text-warning border-warning/30';
|
|
100
|
+
case 'danger':
|
|
101
|
+
return 'bg-destructive/10 text-destructive border-destructive/30';
|
|
102
|
+
case 'primary':
|
|
103
|
+
return 'bg-primary/10 text-primary border-primary/30';
|
|
104
|
+
case 'neutral':
|
|
105
|
+
default:
|
|
106
|
+
return 'bg-muted text-muted-foreground border-border';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let gridColsClass = $derived.by(() => {
|
|
111
|
+
switch (columns) {
|
|
112
|
+
case 1:
|
|
113
|
+
return 'grid-cols-1';
|
|
114
|
+
case 2:
|
|
115
|
+
return 'grid-cols-1 md:grid-cols-2';
|
|
116
|
+
case 4:
|
|
117
|
+
return 'grid-cols-1 sm:grid-cols-2 md:grid-cols-4';
|
|
118
|
+
case 3:
|
|
119
|
+
default:
|
|
120
|
+
return 'grid-cols-1 sm:grid-cols-2 md:grid-cols-3';
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<div
|
|
126
|
+
data-svadmin-component="ProDescriptions"
|
|
127
|
+
class={cn(
|
|
128
|
+
'svadmin-pro-descriptions rounded-[4px] bg-card text-card-foreground',
|
|
129
|
+
className
|
|
130
|
+
)}
|
|
131
|
+
>
|
|
132
|
+
{#if title || extra}
|
|
133
|
+
<div class="mb-3 flex items-center justify-between gap-3">
|
|
134
|
+
{#if title}
|
|
135
|
+
<h3 class="text-sm font-semibold tracking-tight text-foreground">
|
|
136
|
+
{title}
|
|
137
|
+
</h3>
|
|
138
|
+
{/if}
|
|
139
|
+
{#if extra}
|
|
140
|
+
<div class="flex items-center gap-2">
|
|
141
|
+
{@render extra()}
|
|
142
|
+
</div>
|
|
143
|
+
{/if}
|
|
144
|
+
</div>
|
|
145
|
+
{/if}
|
|
146
|
+
|
|
147
|
+
{#if items && items.length > 0}
|
|
148
|
+
<div
|
|
149
|
+
class={cn(
|
|
150
|
+
'grid overflow-hidden rounded-[4px]',
|
|
151
|
+
bordered && 'border border-border',
|
|
152
|
+
gridColsClass
|
|
153
|
+
)}
|
|
154
|
+
>
|
|
155
|
+
{#each items as item (item.key)}
|
|
156
|
+
{@const span = Math.min(item.span || 1, columns)}
|
|
157
|
+
{@const isItemEditable = editable || item.editable}
|
|
158
|
+
<div
|
|
159
|
+
class={cn(
|
|
160
|
+
'flex flex-col border-border',
|
|
161
|
+
bordered && 'border-b border-r last:border-b-0',
|
|
162
|
+
span === 2 && 'sm:col-span-2',
|
|
163
|
+
span === 3 && 'sm:col-span-2 md:col-span-3',
|
|
164
|
+
span === 4 && 'sm:col-span-2 md:col-span-4',
|
|
165
|
+
layout === 'horizontal' ? 'sm:flex-row' : 'flex-col'
|
|
166
|
+
)}
|
|
167
|
+
>
|
|
168
|
+
<!-- Label -->
|
|
169
|
+
<div
|
|
170
|
+
class={cn(
|
|
171
|
+
'font-medium text-muted-foreground select-none',
|
|
172
|
+
getPaddingClass(size),
|
|
173
|
+
bordered
|
|
174
|
+
? 'bg-muted/40 border-border'
|
|
175
|
+
: 'bg-transparent text-muted-foreground',
|
|
176
|
+
layout === 'horizontal' ? 'sm:w-36 shrink-0 sm:border-r' : 'border-b'
|
|
177
|
+
)}
|
|
178
|
+
>
|
|
179
|
+
{item.label}
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<!-- Value -->
|
|
183
|
+
<div
|
|
184
|
+
class={cn(
|
|
185
|
+
'group/cell relative flex flex-1 items-center justify-between gap-2 text-foreground',
|
|
186
|
+
getPaddingClass(size),
|
|
187
|
+
bordered ? 'bg-card' : 'bg-transparent'
|
|
188
|
+
)}
|
|
189
|
+
>
|
|
190
|
+
{#if editingKey === item.key}
|
|
191
|
+
<!-- Inline edit mode -->
|
|
192
|
+
<div class="flex w-full items-center gap-2">
|
|
193
|
+
<input
|
|
194
|
+
type={item.type === 'number' ? 'number' : 'text'}
|
|
195
|
+
bind:value={editValue}
|
|
196
|
+
class="h-7 w-full rounded-[2px] border border-primary bg-background px-2 text-xs focus:outline-none"
|
|
197
|
+
disabled={isSaving}
|
|
198
|
+
onkeydown={(e) => {
|
|
199
|
+
if (e.key === 'Enter') saveEdit(item.key);
|
|
200
|
+
if (e.key === 'Escape') cancelEdit();
|
|
201
|
+
}}
|
|
202
|
+
/>
|
|
203
|
+
<button
|
|
204
|
+
type="button"
|
|
205
|
+
aria-label="保存"
|
|
206
|
+
class="inline-flex h-6 w-6 items-center justify-center rounded-[2px] bg-primary text-primary-foreground hover:bg-primary/90"
|
|
207
|
+
onclick={() => saveEdit(item.key)}
|
|
208
|
+
>
|
|
209
|
+
<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
210
|
+
<polyline points="20 6 9 17 4 12" />
|
|
211
|
+
</svg>
|
|
212
|
+
</button>
|
|
213
|
+
<button
|
|
214
|
+
type="button"
|
|
215
|
+
aria-label="取消"
|
|
216
|
+
class="inline-flex h-6 w-6 items-center justify-center rounded-[2px] border border-border text-muted-foreground hover:bg-muted"
|
|
217
|
+
onclick={cancelEdit}
|
|
218
|
+
>
|
|
219
|
+
<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
220
|
+
<line x1="18" y1="6" x2="6" y2="18" />
|
|
221
|
+
<line x1="6" y1="6" x2="18" y2="18" />
|
|
222
|
+
</svg>
|
|
223
|
+
</button>
|
|
224
|
+
</div>
|
|
225
|
+
{:else}
|
|
226
|
+
<!-- Display mode -->
|
|
227
|
+
<div class="flex items-center gap-2">
|
|
228
|
+
{#if item.type === 'tag'}
|
|
229
|
+
<span
|
|
230
|
+
class={cn(
|
|
231
|
+
'inline-flex items-center rounded-[2px] border px-2 py-0.5 text-[11px] font-medium leading-none',
|
|
232
|
+
getTagToneClasses(item.tone)
|
|
233
|
+
)}
|
|
234
|
+
>
|
|
235
|
+
{item.value ?? '-'}
|
|
236
|
+
</span>
|
|
237
|
+
{:else if item.type === 'badge'}
|
|
238
|
+
<span class="inline-flex items-center gap-1.5">
|
|
239
|
+
<span
|
|
240
|
+
class={cn(
|
|
241
|
+
'h-1.5 w-1.5 rounded-full',
|
|
242
|
+
item.tone === 'success' && 'bg-success',
|
|
243
|
+
item.tone === 'warning' && 'bg-warning',
|
|
244
|
+
item.tone === 'danger' && 'bg-destructive',
|
|
245
|
+
(!item.tone || item.tone === 'primary') && 'bg-primary'
|
|
246
|
+
)}
|
|
247
|
+
></span>
|
|
248
|
+
<span>{item.value ?? '-'}</span>
|
|
249
|
+
</span>
|
|
250
|
+
{:else}
|
|
251
|
+
<span>{item.value !== undefined && item.value !== null && item.value !== '' ? item.value : '-'}</span>
|
|
252
|
+
{/if}
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
{#if isItemEditable}
|
|
256
|
+
<button
|
|
257
|
+
type="button"
|
|
258
|
+
aria-label={`编辑 ${item.label}`}
|
|
259
|
+
class="opacity-0 transition-opacity group-hover/cell:opacity-100 p-1 text-muted-foreground hover:text-primary"
|
|
260
|
+
onclick={() => startEdit(item)}
|
|
261
|
+
>
|
|
262
|
+
<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
263
|
+
<path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z" />
|
|
264
|
+
<path d="m15 5 4 4" />
|
|
265
|
+
</svg>
|
|
266
|
+
</button>
|
|
267
|
+
{/if}
|
|
268
|
+
{/if}
|
|
269
|
+
</div>
|
|
270
|
+
</div>
|
|
271
|
+
{/each}
|
|
272
|
+
</div>
|
|
273
|
+
{/if}
|
|
274
|
+
|
|
275
|
+
{#if children}
|
|
276
|
+
{@render children()}
|
|
277
|
+
{/if}
|
|
278
|
+
</div>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface ProDescriptionItem {
|
|
3
|
+
key: string;
|
|
4
|
+
label: string;
|
|
5
|
+
value?: unknown;
|
|
6
|
+
span?: number;
|
|
7
|
+
editable?: boolean;
|
|
8
|
+
type?: 'text' | 'number' | 'tag' | 'badge';
|
|
9
|
+
tone?: 'primary' | 'success' | 'warning' | 'danger' | 'neutral';
|
|
10
|
+
}
|
|
11
|
+
export interface ProDescriptionsProps {
|
|
12
|
+
/** Title of the descriptions card */
|
|
13
|
+
title?: string;
|
|
14
|
+
/** Whether to display a border around the container and between cells (default: true) */
|
|
15
|
+
bordered?: boolean;
|
|
16
|
+
/** Number of columns in a row (1, 2, 3, or 4, default: 3) */
|
|
17
|
+
columns?: 1 | 2 | 3 | 4;
|
|
18
|
+
/** Density / size of the cells: 'small' | 'default' | 'large' (default: 'default') */
|
|
19
|
+
size?: 'small' | 'default' | 'large';
|
|
20
|
+
/** Layout direction of label and value: 'horizontal' | 'vertical' (default: 'horizontal') */
|
|
21
|
+
layout?: 'horizontal' | 'vertical';
|
|
22
|
+
/** List of description items to render */
|
|
23
|
+
items?: ProDescriptionItem[];
|
|
24
|
+
/** Whether inline editing is enabled globally */
|
|
25
|
+
editable?: boolean;
|
|
26
|
+
/** Callback triggered when a field value is saved */
|
|
27
|
+
onedit?: (key: string, value: unknown) => void | Promise<void>;
|
|
28
|
+
/** Extra actions slot on the top right */
|
|
29
|
+
extra?: Snippet;
|
|
30
|
+
/** Children slot */
|
|
31
|
+
children?: Snippet;
|
|
32
|
+
/** Additional CSS classes */
|
|
33
|
+
class?: string;
|
|
34
|
+
}
|
|
35
|
+
declare const ProDescriptions: import("svelte").Component<ProDescriptionsProps, {}, "">;
|
|
36
|
+
type ProDescriptions = ReturnType<typeof ProDescriptions>;
|
|
37
|
+
export default ProDescriptions;
|