@svadmin/ui 0.121.0 → 0.122.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 +204 -11
- package/dist/app.theme.css +204 -11
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AnnouncementBanner.svelte +314 -0
- package/dist/components/AnnouncementBanner.svelte.d.ts +45 -0
- package/dist/components/AsyncExportModal.svelte +551 -0
- package/dist/components/AsyncExportModal.svelte.d.ts +50 -0
- package/dist/components/AudioFeedbackProvider.svelte +131 -0
- package/dist/components/AudioFeedbackProvider.svelte.d.ts +11 -0
- package/dist/components/AuditLogViewer.svelte +1 -1
- package/dist/components/CanvasAnnotation.svelte +1 -1
- package/dist/components/ColumnFilterBuilder.svelte +135 -0
- package/dist/components/ColumnFilterBuilder.svelte.d.ts +20 -0
- package/dist/components/ColumnSettings.svelte +1 -1
- package/dist/components/ColumnVisibilityDrawer.svelte +541 -0
- package/dist/components/ColumnVisibilityDrawer.svelte.d.ts +16 -0
- package/dist/components/ConcurrentConflictModal.svelte +7 -7
- package/dist/components/ConversionFunnel.svelte +154 -0
- package/dist/components/ConversionFunnel.svelte.d.ts +22 -0
- package/dist/components/CronExpressionBuilder.svelte +1 -1
- package/dist/components/DecisionTable.svelte +1 -1
- package/dist/components/DevTools.svelte +1 -1
- package/dist/components/DraggableRowTable.svelte +1 -1
- package/dist/components/DualApprovalGate.svelte +418 -0
- package/dist/components/DualApprovalGate.svelte.d.ts +39 -0
- package/dist/components/EditableTable.svelte +1 -1
- package/dist/components/ExcelImportWizard.svelte +2 -2
- package/dist/components/GlobalShortcuts.svelte +1 -1
- package/dist/components/ImageCropper.svelte +1 -1
- package/dist/components/ImportWizard.svelte +1 -1
- package/dist/components/JsonSchemaForm.svelte +1 -1
- package/dist/components/JsonViewer.svelte +11 -11
- package/dist/components/KeyboardShortcutsModal.svelte +362 -0
- package/dist/components/KeyboardShortcutsModal.svelte.d.ts +22 -0
- package/dist/components/KpiCard.svelte +5 -5
- package/dist/components/MasterDetailView.svelte +1 -1
- package/dist/components/MetricGrid.svelte +2 -2
- package/dist/components/MicroAppBridge.svelte +59 -0
- package/dist/components/MicroAppBridge.svelte.d.ts +11 -0
- package/dist/components/OfflineSyncBanner.svelte +1 -1
- package/dist/components/OrgChart.svelte +1 -1
- package/dist/components/OrgTreePicker.svelte +1 -1
- package/dist/components/OtpInput.svelte +5 -5
- package/dist/components/PdfDocumentViewer.svelte +2 -2
- package/dist/components/PivotDrilldownModal.svelte +6 -6
- package/dist/components/PivotTable.svelte +1 -1
- package/dist/components/PricingCard.svelte +1 -1
- package/dist/components/PricingTable.svelte +1 -1
- package/dist/components/PrintableBill.svelte +2 -2
- package/dist/components/PrintableReportLayout.svelte +259 -0
- package/dist/components/PrintableReportLayout.svelte.d.ts +32 -0
- package/dist/components/ProSkeleton.svelte +6 -6
- package/dist/components/ResultPage.svelte +2 -2
- package/dist/components/SafeDeleteConfirm.svelte +5 -5
- package/dist/components/SankeyChart.svelte +111 -0
- package/dist/components/SankeyChart.svelte.d.ts +22 -0
- package/dist/components/SchemaVisualModeler.svelte +336 -0
- package/dist/components/SchemaVisualModeler.svelte.d.ts +17 -0
- package/dist/components/SensitiveDataMask.svelte +81 -22
- package/dist/components/SensitiveDataMask.svelte.d.ts +15 -10
- package/dist/components/SessionTimeoutGuard.svelte +154 -0
- package/dist/components/SessionTimeoutGuard.svelte.d.ts +25 -0
- package/dist/components/SignaturePad.svelte +1 -1
- package/dist/components/SliderCaptcha.svelte +1 -1
- package/dist/components/SplitPaneLayout.svelte +1 -1
- package/dist/components/SpreadsheetView.svelte +1 -1
- package/dist/components/StepForm.svelte +1 -1
- package/dist/components/StepWizard.svelte +513 -0
- package/dist/components/StepWizard.svelte.d.ts +49 -0
- package/dist/components/TableClipboardManager.svelte +307 -0
- package/dist/components/TableClipboardManager.svelte.d.ts +13 -0
- package/dist/components/TaskCenter.svelte +9 -9
- package/dist/components/TextDiffViewer.svelte +613 -0
- package/dist/components/TextDiffViewer.svelte.d.ts +39 -0
- package/dist/components/TreeTransfer.svelte +1 -1
- package/dist/components/UnsavedChangesGuard.svelte +5 -5
- package/dist/components/UsageCard.svelte +1 -1
- package/dist/components/VersionDiffViewer.svelte +1 -1
- package/dist/components/VirtualTable.svelte +1 -1
- package/dist/components/VirtualTreeSelect.svelte +1 -1
- package/dist/components/WorkflowDesigner.svelte +3 -3
- package/dist/components/WorkflowProcessCard.svelte +1 -1
- package/dist/components/WorkflowStepper.svelte +250 -0
- package/dist/components/WorkflowStepper.svelte.d.ts +27 -0
- package/dist/components/charts/GaugeChart.svelte +1 -1
- package/dist/components/useAudioAlert.d.svelte.ts +1 -0
- package/dist/components/useAudioAlert.svelte.d.ts +13 -0
- package/dist/components/useAudioAlert.svelte.js +90 -0
- package/dist/components/useHotkeys.d.svelte.ts +1 -0
- package/dist/components/useHotkeys.svelte.d.ts +44 -0
- package/dist/components/useHotkeys.svelte.js +190 -0
- package/dist/components/useMicroAppEvent.d.svelte.ts +1 -0
- package/dist/components/useMicroAppEvent.svelte.d.ts +16 -0
- package/dist/components/useMicroAppEvent.svelte.js +61 -0
- package/dist/components/usePrintExport.d.svelte.ts +1 -0
- package/dist/components/usePrintExport.svelte.d.ts +11 -0
- package/dist/components/usePrintExport.svelte.js +45 -0
- package/dist/components/useSessionTimeout.d.svelte.ts +1 -0
- package/dist/components/useSessionTimeout.svelte.d.ts +28 -0
- package/dist/components/useSessionTimeout.svelte.js +182 -0
- package/dist/components/useTableClipboard.d.svelte.ts +1 -0
- package/dist/components/useTableClipboard.svelte.d.ts +28 -0
- package/dist/components/useTableClipboard.svelte.js +116 -0
- package/dist/index.d.ts +28 -9
- package/dist/index.js +35 -0
- package/package.json +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { GitFork } from '@lucide/svelte';
|
|
3
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export interface SankeyNode {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
value?: number | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SankeyLink {
|
|
13
|
+
source: string;
|
|
14
|
+
target: string;
|
|
15
|
+
value: number;
|
|
16
|
+
color?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SankeyChartProps {
|
|
20
|
+
nodes: SankeyNode[];
|
|
21
|
+
links: SankeyLink[];
|
|
22
|
+
title?: string | undefined;
|
|
23
|
+
height?: number | undefined;
|
|
24
|
+
class?: string | undefined;
|
|
25
|
+
onSelectNode?: ((node: SankeyNode) => void) | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
nodes = [],
|
|
30
|
+
links = [],
|
|
31
|
+
title,
|
|
32
|
+
height = 300,
|
|
33
|
+
class: className = '',
|
|
34
|
+
onSelectNode,
|
|
35
|
+
}: SankeyChartProps = $props();
|
|
36
|
+
|
|
37
|
+
const i18n = useTranslation();
|
|
38
|
+
const chinese = $derived(i18n.locale.startsWith('zh'));
|
|
39
|
+
|
|
40
|
+
const resolvedTitle = $derived(title ?? (chinese ? '业务路径流量桑基图' : 'Path Flow Sankey'));
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<div
|
|
44
|
+
data-svadmin-component="SankeyChart"
|
|
45
|
+
class={cn(
|
|
46
|
+
'w-full rounded-md border border-border bg-card text-card-foreground shadow-xs p-6 space-y-4',
|
|
47
|
+
className,
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
<div class="flex items-center justify-between border-b border-border/60 pb-3">
|
|
51
|
+
<div class="flex items-center gap-2.5">
|
|
52
|
+
<div class="flex h-8 w-8 items-center justify-center rounded-lg bg-info/10 text-info border border-info/20">
|
|
53
|
+
<GitFork class="h-4 w-4" />
|
|
54
|
+
</div>
|
|
55
|
+
<div>
|
|
56
|
+
<h3 class="text-sm font-semibold text-foreground">{resolvedTitle}</h3>
|
|
57
|
+
<p class="text-xs text-muted-foreground">{chinese ? '多节点间流量来源与流向权重分布' : 'Flow distribution across nodes'}</p>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<!-- SVG Flow Diagram -->
|
|
63
|
+
<div class="relative w-full overflow-x-auto" style="min-height: {height}px;">
|
|
64
|
+
<div class="grid grid-cols-3 gap-6 h-full items-center py-4">
|
|
65
|
+
<!-- Source Column -->
|
|
66
|
+
<div class="space-y-3">
|
|
67
|
+
<div class="text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-2">{chinese ? '来源节点' : 'Sources'}</div>
|
|
68
|
+
{#each nodes.slice(0, 3) as node (node.id)}
|
|
69
|
+
<div
|
|
70
|
+
role="button"
|
|
71
|
+
tabindex="0"
|
|
72
|
+
onclick={() => onSelectNode?.(node)}
|
|
73
|
+
onkeydown={(e) => e.key === 'Enter' && onSelectNode?.(node)}
|
|
74
|
+
class="flex items-center justify-between rounded-lg border border-border bg-muted/40 p-2.5 text-xs font-semibold hover:border-primary transition-colors cursor-pointer"
|
|
75
|
+
>
|
|
76
|
+
<span>{node.label}</span>
|
|
77
|
+
<span class="font-mono text-muted-foreground">{node.value ?? ''}</span>
|
|
78
|
+
</div>
|
|
79
|
+
{/each}
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<!-- Links Middle Indicator -->
|
|
83
|
+
<div class="flex flex-col items-center justify-center space-y-2 text-xs text-muted-foreground">
|
|
84
|
+
{#each links.slice(0, 4) as link (link.source + link.target)}
|
|
85
|
+
<div class="w-full flex items-center justify-between bg-muted/20 border border-border/50 px-3 py-1.5 rounded text-[11px]">
|
|
86
|
+
<span class="truncate max-w-20">{link.source}</span>
|
|
87
|
+
<span class="font-mono text-primary font-bold">→ {link.value} →</span>
|
|
88
|
+
<span class="truncate max-w-20">{link.target}</span>
|
|
89
|
+
</div>
|
|
90
|
+
{/each}
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<!-- Target Column -->
|
|
94
|
+
<div class="space-y-3">
|
|
95
|
+
<div class="text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-2">{chinese ? '目标节点' : 'Targets'}</div>
|
|
96
|
+
{#each nodes.slice(3) as node (node.id)}
|
|
97
|
+
<div
|
|
98
|
+
role="button"
|
|
99
|
+
tabindex="0"
|
|
100
|
+
onclick={() => onSelectNode?.(node)}
|
|
101
|
+
onkeydown={(e) => e.key === 'Enter' && onSelectNode?.(node)}
|
|
102
|
+
class="flex items-center justify-between rounded-lg border border-border bg-muted/40 p-2.5 text-xs font-semibold hover:border-primary transition-colors cursor-pointer"
|
|
103
|
+
>
|
|
104
|
+
<span>{node.label}</span>
|
|
105
|
+
<span class="font-mono text-muted-foreground">{node.value ?? ''}</span>
|
|
106
|
+
</div>
|
|
107
|
+
{/each}
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface SankeyNode {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
value?: number | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface SankeyLink {
|
|
7
|
+
source: string;
|
|
8
|
+
target: string;
|
|
9
|
+
value: number;
|
|
10
|
+
color?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface SankeyChartProps {
|
|
13
|
+
nodes: SankeyNode[];
|
|
14
|
+
links: SankeyLink[];
|
|
15
|
+
title?: string | undefined;
|
|
16
|
+
height?: number | undefined;
|
|
17
|
+
class?: string | undefined;
|
|
18
|
+
onSelectNode?: ((node: SankeyNode) => void) | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare const SankeyChart: import("svelte").Component<SankeyChartProps, {}, "">;
|
|
21
|
+
type SankeyChart = ReturnType<typeof SankeyChart>;
|
|
22
|
+
export default SankeyChart;
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import {
|
|
4
|
+
Database,
|
|
5
|
+
Plus,
|
|
6
|
+
Trash2,
|
|
7
|
+
Code2,
|
|
8
|
+
Copy,
|
|
9
|
+
Check,
|
|
10
|
+
FileJson,
|
|
11
|
+
Sparkles,
|
|
12
|
+
Settings2,
|
|
13
|
+
} from '@lucide/svelte';
|
|
14
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
15
|
+
import { cn } from '../utils.js';
|
|
16
|
+
import { Button } from './ui/button/index.js';
|
|
17
|
+
|
|
18
|
+
export interface SchemaFieldModel {
|
|
19
|
+
key: string;
|
|
20
|
+
label: string;
|
|
21
|
+
type: 'text' | 'number' | 'boolean' | 'date' | 'select' | 'relation';
|
|
22
|
+
required: boolean;
|
|
23
|
+
filterable: boolean;
|
|
24
|
+
sortable: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SchemaVisualModelerProps {
|
|
28
|
+
resourceName?: string | undefined;
|
|
29
|
+
initialFields?: SchemaFieldModel[] | undefined;
|
|
30
|
+
class?: string | undefined;
|
|
31
|
+
onSaveSchema?: ((resourceName: string, fields: SchemaFieldModel[]) => void) | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
resourceName = 'Customer',
|
|
36
|
+
initialFields = [
|
|
37
|
+
{ key: 'id', label: 'ID', type: 'number', required: true, filterable: true, sortable: true },
|
|
38
|
+
{ key: 'name', label: 'Name', type: 'text', required: true, filterable: true, sortable: true },
|
|
39
|
+
{ key: 'email', label: 'Email', type: 'text', required: false, filterable: true, sortable: false },
|
|
40
|
+
],
|
|
41
|
+
class: className = '',
|
|
42
|
+
onSaveSchema,
|
|
43
|
+
}: SchemaVisualModelerProps = $props();
|
|
44
|
+
|
|
45
|
+
const i18n = useTranslation();
|
|
46
|
+
const chinese = $derived(i18n.locale.startsWith('zh'));
|
|
47
|
+
|
|
48
|
+
let activeTab = $state<'visual' | 'sql' | 'code'>('visual');
|
|
49
|
+
let nameState = $state(untrack(() => resourceName));
|
|
50
|
+
let fields = $state<SchemaFieldModel[]>(untrack(() => JSON.parse(JSON.stringify(initialFields))));
|
|
51
|
+
let rawImportText = $state('');
|
|
52
|
+
let isCopied = $state(false);
|
|
53
|
+
|
|
54
|
+
function addField() {
|
|
55
|
+
fields = [
|
|
56
|
+
...fields,
|
|
57
|
+
{
|
|
58
|
+
key: `field_${fields.length + 1}`,
|
|
59
|
+
label: `Field ${fields.length + 1}`,
|
|
60
|
+
type: 'text',
|
|
61
|
+
required: false,
|
|
62
|
+
filterable: true,
|
|
63
|
+
sortable: false,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function removeField(idx: number) {
|
|
69
|
+
fields = fields.filter((_, i) => i !== idx);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function inferFromJSON(jsonStr: string) {
|
|
73
|
+
try {
|
|
74
|
+
const parsed: unknown = JSON.parse(jsonStr);
|
|
75
|
+
const targetObj = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
76
|
+
if (!targetObj || typeof targetObj !== 'object') return;
|
|
77
|
+
|
|
78
|
+
const newFields: SchemaFieldModel[] = Object.entries(targetObj as Record<string, unknown>).map(
|
|
79
|
+
([key, val]) => {
|
|
80
|
+
let type: SchemaFieldModel['type'] = 'text';
|
|
81
|
+
if (typeof val === 'number') type = 'number';
|
|
82
|
+
else if (typeof val === 'boolean') type = 'boolean';
|
|
83
|
+
else if (typeof val === 'string' && /\d{4}-\d{2}-\d{2}/.test(val)) type = 'date';
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
key,
|
|
87
|
+
label: key.charAt(0).toUpperCase() + key.slice(1),
|
|
88
|
+
type,
|
|
89
|
+
required: key === 'id',
|
|
90
|
+
filterable: true,
|
|
91
|
+
sortable: type === 'number' || type === 'date',
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
if (newFields.length > 0) {
|
|
97
|
+
fields = newFields;
|
|
98
|
+
activeTab = 'visual';
|
|
99
|
+
}
|
|
100
|
+
} catch {
|
|
101
|
+
// JSON parse error
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const generatedCode = $derived.by(() => {
|
|
106
|
+
const fieldsStr = fields
|
|
107
|
+
.map(
|
|
108
|
+
(f) =>
|
|
109
|
+
` { key: '${f.key}', label: '${f.label}', type: '${f.type}', required: ${f.required}, filterable: ${f.filterable}, sortable: ${f.sortable} },`,
|
|
110
|
+
)
|
|
111
|
+
.join('\n');
|
|
112
|
+
|
|
113
|
+
return `import { defineResource } from '@svadmin/core';\n\nexport const ${nameState.toLowerCase()}Resource = defineResource({\n name: '${nameState.toLowerCase()}',\n label: '${nameState}',\n fields: [\n${fieldsStr}\n ],\n});`;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
async function copyCode() {
|
|
117
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard) {
|
|
118
|
+
await navigator.clipboard.writeText(generatedCode);
|
|
119
|
+
isCopied = true;
|
|
120
|
+
setTimeout(() => {
|
|
121
|
+
isCopied = false;
|
|
122
|
+
}, 1500);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<div
|
|
128
|
+
data-svadmin-component="SchemaVisualModeler"
|
|
129
|
+
class={cn(
|
|
130
|
+
'w-full rounded-md border border-border bg-card text-card-foreground shadow-xs overflow-hidden flex flex-col',
|
|
131
|
+
className,
|
|
132
|
+
)}
|
|
133
|
+
>
|
|
134
|
+
<!-- Header Bar -->
|
|
135
|
+
<div class="flex items-center justify-between border-b border-border/70 px-6 py-4 bg-card">
|
|
136
|
+
<div class="flex items-center gap-2.5">
|
|
137
|
+
<div class="flex h-9 w-9 items-center justify-center rounded-sm bg-primary/10 text-primary border border-primary/20">
|
|
138
|
+
<Database class="h-5 w-5" />
|
|
139
|
+
</div>
|
|
140
|
+
<div>
|
|
141
|
+
<h3 class="text-base font-semibold text-foreground">
|
|
142
|
+
{chinese ? 'Schema 可视化建模与代码生成器' : 'Visual Resource Schema Modeler'}
|
|
143
|
+
</h3>
|
|
144
|
+
<p class="text-xs text-muted-foreground">
|
|
145
|
+
{chinese ? '交互式字段编排、JSON/SQL 逆向推断与 TypeScript 契约导出' : 'Design fields, reverse-engineer JSON, export TypeScript contracts'}
|
|
146
|
+
</p>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
<!-- Mode Tabs -->
|
|
151
|
+
<div class="flex rounded-lg border border-border bg-muted/40 p-1 text-xs">
|
|
152
|
+
<button
|
|
153
|
+
type="button"
|
|
154
|
+
onclick={() => (activeTab = 'visual')}
|
|
155
|
+
class={cn(
|
|
156
|
+
'flex items-center gap-1.5 px-3 py-1.5 rounded-md font-medium transition-all',
|
|
157
|
+
activeTab === 'visual' ? 'bg-card text-foreground shadow-2xs' : 'text-muted-foreground hover:text-foreground',
|
|
158
|
+
)}
|
|
159
|
+
>
|
|
160
|
+
<Settings2 class="h-3.5 w-3.5" />
|
|
161
|
+
<span>{chinese ? '可视化建模' : 'Visual'}</span>
|
|
162
|
+
</button>
|
|
163
|
+
|
|
164
|
+
<button
|
|
165
|
+
type="button"
|
|
166
|
+
onclick={() => (activeTab = 'sql')}
|
|
167
|
+
class={cn(
|
|
168
|
+
'flex items-center gap-1.5 px-3 py-1.5 rounded-md font-medium transition-all',
|
|
169
|
+
activeTab === 'sql' ? 'bg-card text-foreground shadow-2xs' : 'text-muted-foreground hover:text-foreground',
|
|
170
|
+
)}
|
|
171
|
+
>
|
|
172
|
+
<FileJson class="h-3.5 w-3.5" />
|
|
173
|
+
<span>{chinese ? 'JSON 逆向推断' : 'JSON Infer'}</span>
|
|
174
|
+
</button>
|
|
175
|
+
|
|
176
|
+
<button
|
|
177
|
+
type="button"
|
|
178
|
+
onclick={() => (activeTab = 'code')}
|
|
179
|
+
class={cn(
|
|
180
|
+
'flex items-center gap-1.5 px-3 py-1.5 rounded-md font-medium transition-all',
|
|
181
|
+
activeTab === 'code' ? 'bg-card text-foreground shadow-2xs' : 'text-muted-foreground hover:text-foreground',
|
|
182
|
+
)}
|
|
183
|
+
>
|
|
184
|
+
<Code2 class="h-3.5 w-3.5" />
|
|
185
|
+
<span>{chinese ? '生成的代码' : 'Code'}</span>
|
|
186
|
+
</button>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<!-- Body Content -->
|
|
191
|
+
<div class="p-6 flex-1 overflow-y-auto">
|
|
192
|
+
{#if activeTab === 'visual'}
|
|
193
|
+
<div class="space-y-4">
|
|
194
|
+
<div class="flex items-center gap-3">
|
|
195
|
+
<label for="res-name" class="text-xs font-semibold text-foreground shrink-0">
|
|
196
|
+
{chinese ? '资源英文名称:' : 'Resource Name:'}
|
|
197
|
+
</label>
|
|
198
|
+
<input
|
|
199
|
+
id="res-name"
|
|
200
|
+
type="text"
|
|
201
|
+
bind:value={nameState}
|
|
202
|
+
class="h-8 max-w-xs rounded-md border border-input bg-background px-2.5 text-xs font-mono font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
203
|
+
/>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<!-- Field Rows Table -->
|
|
207
|
+
<div class="rounded-md border border-border overflow-hidden">
|
|
208
|
+
<table class="w-full text-left text-xs border-collapse">
|
|
209
|
+
<thead class="bg-muted/40 border-b border-border text-muted-foreground font-semibold">
|
|
210
|
+
<tr>
|
|
211
|
+
<th class="p-3 w-40">{chinese ? '字段标识 (Key)' : 'Field Key'}</th>
|
|
212
|
+
<th class="p-3 w-40">{chinese ? '显示名称 (Label)' : 'Label'}</th>
|
|
213
|
+
<th class="p-3 w-32">{chinese ? '数据类型' : 'Type'}</th>
|
|
214
|
+
<th class="p-3 w-20 text-center">{chinese ? '必填' : 'Required'}</th>
|
|
215
|
+
<th class="p-3 w-20 text-center">{chinese ? '可筛选' : 'Filterable'}</th>
|
|
216
|
+
<th class="p-3 w-20 text-center">{chinese ? '可排序' : 'Sortable'}</th>
|
|
217
|
+
<th class="p-3 w-16 text-center">{chinese ? '操作' : 'Action'}</th>
|
|
218
|
+
</tr>
|
|
219
|
+
</thead>
|
|
220
|
+
<tbody class="divide-y divide-border/60">
|
|
221
|
+
{#each fields as field, idx (idx)}
|
|
222
|
+
<tr class="hover:bg-muted/20">
|
|
223
|
+
<td class="p-2.5">
|
|
224
|
+
<input
|
|
225
|
+
type="text"
|
|
226
|
+
bind:value={field.key}
|
|
227
|
+
class="h-7 w-full rounded border border-input bg-background px-2 text-xs font-mono"
|
|
228
|
+
/>
|
|
229
|
+
</td>
|
|
230
|
+
<td class="p-2.5">
|
|
231
|
+
<input
|
|
232
|
+
type="text"
|
|
233
|
+
bind:value={field.label}
|
|
234
|
+
class="h-7 w-full rounded border border-input bg-background px-2 text-xs"
|
|
235
|
+
/>
|
|
236
|
+
</td>
|
|
237
|
+
<td class="p-2.5">
|
|
238
|
+
<select
|
|
239
|
+
bind:value={field.type}
|
|
240
|
+
class="h-7 w-full rounded border border-input bg-background px-1.5 text-xs"
|
|
241
|
+
>
|
|
242
|
+
<option value="text">text</option>
|
|
243
|
+
<option value="number">number</option>
|
|
244
|
+
<option value="boolean">boolean</option>
|
|
245
|
+
<option value="date">date</option>
|
|
246
|
+
<option value="select">select</option>
|
|
247
|
+
<option value="relation">relation</option>
|
|
248
|
+
</select>
|
|
249
|
+
</td>
|
|
250
|
+
<td class="p-2.5 text-center">
|
|
251
|
+
<input type="checkbox" bind:checked={field.required} />
|
|
252
|
+
</td>
|
|
253
|
+
<td class="p-2.5 text-center">
|
|
254
|
+
<input type="checkbox" bind:checked={field.filterable} />
|
|
255
|
+
</td>
|
|
256
|
+
<td class="p-2.5 text-center">
|
|
257
|
+
<input type="checkbox" bind:checked={field.sortable} />
|
|
258
|
+
</td>
|
|
259
|
+
<td class="p-2.5 text-center">
|
|
260
|
+
<button
|
|
261
|
+
type="button"
|
|
262
|
+
onclick={() => removeField(idx)}
|
|
263
|
+
class="rounded p-1 text-muted-foreground hover:text-destructive hover:bg-destructive/10"
|
|
264
|
+
aria-label="Delete field"
|
|
265
|
+
>
|
|
266
|
+
<Trash2 class="h-3.5 w-3.5" />
|
|
267
|
+
</button>
|
|
268
|
+
</td>
|
|
269
|
+
</tr>
|
|
270
|
+
{/each}
|
|
271
|
+
</tbody>
|
|
272
|
+
</table>
|
|
273
|
+
</div>
|
|
274
|
+
|
|
275
|
+
<div class="flex items-center justify-between pt-2">
|
|
276
|
+
<Button type="button" variant="outline" size="sm" onclick={addField} class="gap-1 text-xs">
|
|
277
|
+
<Plus class="h-3.5 w-3.5" />
|
|
278
|
+
<span>{chinese ? '添加字段' : 'Add Field'}</span>
|
|
279
|
+
</Button>
|
|
280
|
+
|
|
281
|
+
{#if onSaveSchema}
|
|
282
|
+
<Button
|
|
283
|
+
type="button"
|
|
284
|
+
size="sm"
|
|
285
|
+
onclick={() => onSaveSchema(nameState, fields)}
|
|
286
|
+
class="gap-1 text-xs"
|
|
287
|
+
>
|
|
288
|
+
<span>{chinese ? '保存并应用 Schema' : 'Save Schema'}</span>
|
|
289
|
+
</Button>
|
|
290
|
+
{/if}
|
|
291
|
+
</div>
|
|
292
|
+
</div>
|
|
293
|
+
{:else if activeTab === 'sql'}
|
|
294
|
+
<div class="space-y-3">
|
|
295
|
+
<label for="json-sample" class="block text-xs font-semibold text-foreground">
|
|
296
|
+
{chinese ? '粘贴 JSON 数据样例逆向推导字段结构:' : 'Paste sample JSON to infer fields:'}
|
|
297
|
+
</label>
|
|
298
|
+
<textarea
|
|
299
|
+
id="json-sample"
|
|
300
|
+
bind:value={rawImportText}
|
|
301
|
+
placeholder="输入或粘贴 JSON 数据样例..."
|
|
302
|
+
rows="8"
|
|
303
|
+
class="w-full rounded-lg border border-input bg-muted/20 p-3 font-mono text-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
304
|
+
></textarea>
|
|
305
|
+
<Button
|
|
306
|
+
type="button"
|
|
307
|
+
size="sm"
|
|
308
|
+
onclick={() => inferFromJSON(rawImportText)}
|
|
309
|
+
class="gap-1.5 text-xs"
|
|
310
|
+
>
|
|
311
|
+
<Sparkles class="h-3.5 w-3.5" />
|
|
312
|
+
<span>{chinese ? '一键逆向解析推断' : 'Infer Fields from JSON'}</span>
|
|
313
|
+
</Button>
|
|
314
|
+
</div>
|
|
315
|
+
{:else}
|
|
316
|
+
<div class="space-y-3">
|
|
317
|
+
<div class="flex items-center justify-between">
|
|
318
|
+
<span class="text-xs font-semibold text-foreground">
|
|
319
|
+
{chinese ? '生成的 Svelte 5 / @svadmin/core 资源代码:' : 'Generated Resource Code:'}
|
|
320
|
+
</span>
|
|
321
|
+
<Button variant="outline" size="sm" onclick={copyCode} class="gap-1.5 text-xs">
|
|
322
|
+
{#if isCopied}
|
|
323
|
+
<Check class="h-3.5 w-3.5 text-success" />
|
|
324
|
+
<span>{chinese ? '已复制' : 'Copied'}</span>
|
|
325
|
+
{:else}
|
|
326
|
+
<Copy class="h-3.5 w-3.5" />
|
|
327
|
+
<span>{chinese ? '复制代码' : 'Copy'}</span>
|
|
328
|
+
{/if}
|
|
329
|
+
</Button>
|
|
330
|
+
</div>
|
|
331
|
+
|
|
332
|
+
<pre class="rounded-md border border-border bg-muted/40 p-4 font-mono text-xs text-foreground overflow-x-auto"><code>{generatedCode}</code></pre>
|
|
333
|
+
</div>
|
|
334
|
+
{/if}
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface SchemaFieldModel {
|
|
2
|
+
key: string;
|
|
3
|
+
label: string;
|
|
4
|
+
type: 'text' | 'number' | 'boolean' | 'date' | 'select' | 'relation';
|
|
5
|
+
required: boolean;
|
|
6
|
+
filterable: boolean;
|
|
7
|
+
sortable: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SchemaVisualModelerProps {
|
|
10
|
+
resourceName?: string | undefined;
|
|
11
|
+
initialFields?: SchemaFieldModel[] | undefined;
|
|
12
|
+
class?: string | undefined;
|
|
13
|
+
onSaveSchema?: ((resourceName: string, fields: SchemaFieldModel[]) => void) | undefined;
|
|
14
|
+
}
|
|
15
|
+
declare const SchemaVisualModeler: import("svelte").Component<SchemaVisualModelerProps, {}, "">;
|
|
16
|
+
type SchemaVisualModeler = ReturnType<typeof SchemaVisualModeler>;
|
|
17
|
+
export default SchemaVisualModeler;
|
|
@@ -4,16 +4,32 @@
|
|
|
4
4
|
import { Button } from './ui/button/index.js';
|
|
5
5
|
import { cn } from '../utils.js';
|
|
6
6
|
|
|
7
|
-
export type MaskType =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
export type MaskType =
|
|
8
|
+
| 'phone'
|
|
9
|
+
| 'mobile'
|
|
10
|
+
| 'id-card'
|
|
11
|
+
| 'idCard'
|
|
12
|
+
| 'email'
|
|
13
|
+
| 'bank-card'
|
|
14
|
+
| 'bankCard'
|
|
15
|
+
| 'name'
|
|
16
|
+
| 'secret'
|
|
17
|
+
| 'custom';
|
|
18
|
+
|
|
19
|
+
export type CopyMode = 'raw' | 'masked' | 'auto';
|
|
20
|
+
|
|
21
|
+
export interface SensitiveDataMaskProps {
|
|
22
|
+
value?: string | number | null | undefined;
|
|
23
|
+
type?: MaskType | undefined;
|
|
24
|
+
maskPattern?: ((val: string) => string) | undefined;
|
|
25
|
+
allowUnmask?: boolean | undefined;
|
|
26
|
+
defaultMasked?: boolean | undefined;
|
|
27
|
+
allowCopy?: boolean | undefined;
|
|
28
|
+
copyMode?: CopyMode | undefined;
|
|
29
|
+
onReveal?: (() => boolean | undefined | Promise<boolean | undefined>) | undefined;
|
|
30
|
+
onUnmask?: (() => void | Promise<void>) | undefined;
|
|
31
|
+
onCopy?: ((copiedText: string) => void) | undefined;
|
|
32
|
+
class?: string | undefined;
|
|
17
33
|
}
|
|
18
34
|
|
|
19
35
|
let {
|
|
@@ -22,43 +38,66 @@
|
|
|
22
38
|
maskPattern,
|
|
23
39
|
allowUnmask = true,
|
|
24
40
|
defaultMasked = true,
|
|
41
|
+
allowCopy = true,
|
|
42
|
+
copyMode = 'raw',
|
|
43
|
+
onReveal,
|
|
25
44
|
onUnmask,
|
|
45
|
+
onCopy,
|
|
26
46
|
class: className = '',
|
|
27
|
-
}:
|
|
47
|
+
}: SensitiveDataMaskProps = $props();
|
|
28
48
|
|
|
29
49
|
let isMasked = $state(untrack(() => defaultMasked));
|
|
30
50
|
let isCopied = $state(false);
|
|
31
51
|
|
|
32
52
|
const rawString = $derived(String(value ?? ''));
|
|
33
53
|
|
|
54
|
+
function maskName(val: string): string {
|
|
55
|
+
const trimmed = val.trim();
|
|
56
|
+
if (!trimmed) return '—';
|
|
57
|
+
if (trimmed.includes(' ')) {
|
|
58
|
+
return trimmed
|
|
59
|
+
.split(/\s+/)
|
|
60
|
+
.map((part) => (part.length <= 1 ? '*' : `${part[0]}${'*'.repeat(Math.max(1, part.length - 2))}${part.length > 2 ? part.slice(-1) : '*'}`))
|
|
61
|
+
.join(' ');
|
|
62
|
+
}
|
|
63
|
+
const len = trimmed.length;
|
|
64
|
+
if (len <= 1) return '*';
|
|
65
|
+
if (len === 2) return `${trimmed[0]}*`;
|
|
66
|
+
if (len === 3) return `${trimmed[0]}*${trimmed[2]}`;
|
|
67
|
+
return `${trimmed[0]}${'*'.repeat(len - 2)}${trimmed.slice(-1)}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
34
70
|
function maskValue(val: string, maskType: MaskType): string {
|
|
35
71
|
if (!val) return '—';
|
|
36
72
|
if (maskPattern) return maskPattern(val);
|
|
37
73
|
|
|
38
74
|
switch (maskType) {
|
|
39
75
|
case 'phone':
|
|
40
|
-
|
|
76
|
+
case 'mobile':
|
|
41
77
|
return val.length >= 7
|
|
42
78
|
? `${val.slice(0, 3)}****${val.slice(-4)}`
|
|
43
79
|
: '****';
|
|
44
80
|
case 'id-card':
|
|
45
|
-
|
|
81
|
+
case 'idCard':
|
|
46
82
|
return val.length >= 10
|
|
47
83
|
? `${val.slice(0, 6)}********${val.slice(-4)}`
|
|
48
84
|
: '********';
|
|
49
85
|
case 'email': {
|
|
50
86
|
const parts = val.split('@');
|
|
51
|
-
const [
|
|
52
|
-
if (parts.length === 2 &&
|
|
53
|
-
const maskedName =
|
|
87
|
+
const [namePart, domain] = parts;
|
|
88
|
+
if (parts.length === 2 && namePart && domain) {
|
|
89
|
+
const maskedName = namePart.length > 2 ? `${namePart[0]}***${namePart.slice(-1)}` : `${namePart[0]}***`;
|
|
54
90
|
return `${maskedName}@${domain}`;
|
|
55
91
|
}
|
|
56
92
|
return '***@***.***';
|
|
57
93
|
}
|
|
58
94
|
case 'bank-card':
|
|
95
|
+
case 'bankCard':
|
|
59
96
|
return val.length >= 8
|
|
60
97
|
? `${val.slice(0, 4)} **** **** ${val.slice(-4)}`
|
|
61
98
|
: '**** ****';
|
|
99
|
+
case 'name':
|
|
100
|
+
return maskName(val);
|
|
62
101
|
case 'secret':
|
|
63
102
|
return val.length >= 8
|
|
64
103
|
? `${val.slice(0, 3)}••••••••••••${val.slice(-4)}`
|
|
@@ -71,16 +110,32 @@
|
|
|
71
110
|
const displayedText = $derived(isMasked ? maskValue(rawString, type) : rawString);
|
|
72
111
|
|
|
73
112
|
async function toggleMask() {
|
|
74
|
-
if (isMasked
|
|
75
|
-
|
|
113
|
+
if (isMasked) {
|
|
114
|
+
if (onReveal) {
|
|
115
|
+
const allowed = await onReveal();
|
|
116
|
+
if (allowed === false) return;
|
|
117
|
+
}
|
|
118
|
+
if (onUnmask) {
|
|
119
|
+
await onUnmask();
|
|
120
|
+
}
|
|
121
|
+
isMasked = false;
|
|
122
|
+
} else {
|
|
123
|
+
isMasked = true;
|
|
76
124
|
}
|
|
77
|
-
isMasked = !isMasked;
|
|
78
125
|
}
|
|
79
126
|
|
|
80
127
|
async function handleCopy() {
|
|
128
|
+
let textToCopy = rawString;
|
|
129
|
+
if (copyMode === 'masked') {
|
|
130
|
+
textToCopy = maskValue(rawString, type);
|
|
131
|
+
} else if (copyMode === 'auto') {
|
|
132
|
+
textToCopy = isMasked ? maskValue(rawString, type) : rawString;
|
|
133
|
+
}
|
|
134
|
+
|
|
81
135
|
if (typeof navigator !== 'undefined' && navigator.clipboard) {
|
|
82
|
-
await navigator.clipboard.writeText(
|
|
136
|
+
await navigator.clipboard.writeText(textToCopy);
|
|
83
137
|
isCopied = true;
|
|
138
|
+
onCopy?.(textToCopy);
|
|
84
139
|
setTimeout(() => {
|
|
85
140
|
isCopied = false;
|
|
86
141
|
}, 1500);
|
|
@@ -88,7 +143,11 @@
|
|
|
88
143
|
}
|
|
89
144
|
</script>
|
|
90
145
|
|
|
91
|
-
<div
|
|
146
|
+
<div
|
|
147
|
+
data-svadmin-component="SensitiveDataMask"
|
|
148
|
+
data-masked={isMasked ? 'true' : 'false'}
|
|
149
|
+
class={cn('inline-flex items-center gap-1.5 font-mono text-xs text-foreground', className)}
|
|
150
|
+
>
|
|
92
151
|
<span class="truncate select-all">{displayedText}</span>
|
|
93
152
|
|
|
94
153
|
{#if allowUnmask && rawString}
|
|
@@ -107,7 +166,7 @@
|
|
|
107
166
|
</Button>
|
|
108
167
|
{/if}
|
|
109
168
|
|
|
110
|
-
{#if rawString}
|
|
169
|
+
{#if allowCopy && rawString}
|
|
111
170
|
<Button
|
|
112
171
|
variant="ghost"
|
|
113
172
|
size="icon"
|