@svadmin/ui 0.108.2 → 0.108.4
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/components/AboutSettings.svelte +1 -1
- package/dist/components/AdminApp.svelte +20 -1
- package/dist/components/AdminApp.svelte.d.ts +6 -0
- package/dist/components/Calendar.svelte +28 -8
- package/dist/components/ConfigProvider.svelte +101 -10
- package/dist/components/ConfigProvider.svelte.d.ts +39 -0
- package/dist/components/DatePicker.svelte +32 -9
- package/dist/components/DatePicker.svelte.d.ts +3 -0
- package/dist/components/DevTools.svelte +198 -0
- package/dist/components/EditableTable.svelte +59 -6
- package/dist/components/EditableTable.svelte.d.ts +13 -0
- package/dist/components/EmptyState.svelte +19 -6
- package/dist/components/ListPagination.svelte +59 -11
- package/dist/components/NotificationHost.svelte +5 -4
- package/dist/components/RouteAccessGuard.svelte +42 -0
- package/dist/components/RouteAccessGuard.svelte.d.ts +11 -0
- package/dist/components/component-messages.d.ts +59 -0
- package/dist/components/component-messages.js +47 -0
- package/dist/components/config-provider-defaults.reader.svelte +8 -0
- package/dist/components/config-provider-defaults.reader.svelte.d.ts +3 -0
- package/dist/components/custom-route-access.d.ts +28 -0
- package/dist/components/custom-route-access.js +57 -0
- package/dist/components/notification-scope-probe.svelte +9 -0
- package/dist/components/notification-scope-probe.svelte.d.ts +6 -0
- package/dist/components/popup-portal-host.svelte +41 -0
- package/dist/components/popup-portal-host.svelte.d.ts +7 -0
- package/dist/components/ui/alert-dialog/alert-dialog-portal.svelte +3 -1
- package/dist/components/ui/button/button.svelte +15 -2
- package/dist/components/ui/dialog/dialog-portal.svelte +2 -1
- package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +5 -2
- package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte.d.ts +1 -1
- package/dist/components/ui/popover/popover-content.svelte +6 -2
- package/dist/components/ui/popup-anchor.d.ts +6 -0
- package/dist/components/ui/popup-anchor.js +65 -0
- package/dist/components/ui/popup-portal.svelte +42 -0
- package/dist/components/ui/popup-portal.svelte.d.ts +11 -0
- package/dist/components/ui/sheet/sheet.svelte +3 -3
- package/dist/components/ui/tooltip/tooltip-content.svelte +5 -1
- package/dist/components/ui/tooltip/tooltip-portal.svelte +6 -2
- package/dist/components/ui/tooltip/tooltip-portal.svelte.d.ts +4 -1
- package/dist/devtools-inspector.d.ts +37 -0
- package/dist/devtools-inspector.js +56 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +3 -2
- package/dist/notifications.svelte.d.ts +23 -12
- package/dist/notifications.svelte.js +118 -39
- package/package.json +4 -4
|
@@ -16,7 +16,15 @@
|
|
|
16
16
|
attachSvadminDevtoolsQueryClient,
|
|
17
17
|
installSvadminDevtoolsBridge,
|
|
18
18
|
publishSvadminDevtoolsSnapshot,
|
|
19
|
+
runSvadminDevtoolsCacheAction,
|
|
19
20
|
} from '../devtools-bridge.js';
|
|
21
|
+
import {
|
|
22
|
+
componentSource,
|
|
23
|
+
filterInspectorRows,
|
|
24
|
+
redactValueSummary,
|
|
25
|
+
type DevtoolsInspectorRow,
|
|
26
|
+
type DevtoolsTimelineEntry,
|
|
27
|
+
} from '../devtools-inspector.js';
|
|
20
28
|
|
|
21
29
|
import TooltipButton from './TooltipButton.svelte';
|
|
22
30
|
import * as Tabs from './ui/tabs/index.js';
|
|
@@ -48,7 +56,53 @@
|
|
|
48
56
|
let cacheDiagnostics = $state.raw<DevtoolsCacheDiagnostics>(EMPTY_CACHE_DIAGNOSTICS);
|
|
49
57
|
let safeQueryDiagnostics = $state.raw<DevtoolsQueryDiagnostic[]>([]);
|
|
50
58
|
let invalidations = $state.raw<Array<{ at: number; provider: string; resource: string; operation: string }>>([]);
|
|
59
|
+
let inspectorRows = $state.raw<DevtoolsInspectorRow[]>([]);
|
|
60
|
+
let timeline = $state.raw<DevtoolsTimelineEntry[]>([]);
|
|
61
|
+
let filterText = $state('');
|
|
62
|
+
let filterKind = $state<'all' | 'query' | 'mutation'>('all');
|
|
63
|
+
let filterResource = $state('all');
|
|
64
|
+
let filterStatus = $state('all');
|
|
65
|
+
let filterComponent = $state('');
|
|
51
66
|
const queryTimings = new SvelteMap<string, { startedAt?: number; duration?: number }>();
|
|
67
|
+
const triggers = new Map<string, string>();
|
|
68
|
+
|
|
69
|
+
function pushTimeline(entry: DevtoolsTimelineEntry) {
|
|
70
|
+
timeline = [entry, ...timeline].slice(0, 24);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function replayRow(row: DevtoolsInspectorRow) {
|
|
74
|
+
if (row.kind !== 'query') return;
|
|
75
|
+
triggers.set(row.id, 'devtools-replay');
|
|
76
|
+
pushTimeline({
|
|
77
|
+
at: Date.now(),
|
|
78
|
+
kind: 'query',
|
|
79
|
+
resource: row.resource,
|
|
80
|
+
operation: row.operation,
|
|
81
|
+
status: 'refetch',
|
|
82
|
+
trigger: 'devtools-replay',
|
|
83
|
+
source: 'devtools',
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
await runSvadminDevtoolsCacheAction({
|
|
87
|
+
action: 'refetch',
|
|
88
|
+
selector: {
|
|
89
|
+
provider: row.provider,
|
|
90
|
+
...(row.resource === '—' || row.resource === '[custom]' || row.resource === '[mutation]' ? {} : { resource: row.resource }),
|
|
91
|
+
operation: row.operation,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
} catch {
|
|
95
|
+
pushTimeline({
|
|
96
|
+
at: Date.now(),
|
|
97
|
+
kind: 'query',
|
|
98
|
+
resource: row.resource,
|
|
99
|
+
operation: row.operation,
|
|
100
|
+
status: 'error',
|
|
101
|
+
trigger: 'devtools-replay',
|
|
102
|
+
source: 'devtools',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
52
106
|
|
|
53
107
|
function toggle() {
|
|
54
108
|
visible = !visible;
|
|
@@ -97,8 +151,65 @@
|
|
|
97
151
|
invalidation: query.state.isInvalidated ? 'cache invalidation' : '—',
|
|
98
152
|
}];
|
|
99
153
|
});
|
|
154
|
+
const queryRows: DevtoolsInspectorRow[] = queries.flatMap((query) => {
|
|
155
|
+
const descriptor = parseQueryKey(query.queryKey);
|
|
156
|
+
if (!descriptor) return [];
|
|
157
|
+
const loose = query as typeof query & {
|
|
158
|
+
meta?: unknown;
|
|
159
|
+
options?: { meta?: unknown };
|
|
160
|
+
observers?: readonly unknown[];
|
|
161
|
+
};
|
|
162
|
+
const attribution = componentSource(loose.meta ?? loose.options?.meta, loose.observers?.length ?? 0);
|
|
163
|
+
const resource = descriptor.kind === 'custom' ? '[custom]' : (descriptor.resource ?? '—');
|
|
164
|
+
const operation = `${descriptor.kind}:${descriptor.action ?? 'call'}`;
|
|
165
|
+
return [{
|
|
166
|
+
id: query.queryHash,
|
|
167
|
+
kind: 'query' as const,
|
|
168
|
+
provider: descriptor.provider,
|
|
169
|
+
resource,
|
|
170
|
+
operation,
|
|
171
|
+
status: query.state.fetchStatus === 'fetching' ? 'fetching' : query.state.status,
|
|
172
|
+
component: attribution.component,
|
|
173
|
+
trigger: triggers.get(query.queryHash) ?? 'cache',
|
|
174
|
+
source: attribution.source,
|
|
175
|
+
requestSummary: redactValueSummary({ operation, resource }),
|
|
176
|
+
responseSummary: redactValueSummary(query.state.data),
|
|
177
|
+
}];
|
|
178
|
+
});
|
|
179
|
+
const mutationRows: DevtoolsInspectorRow[] = mutations.map((mutation, index) => {
|
|
180
|
+
const loose = mutation as typeof mutation & {
|
|
181
|
+
mutationId?: number;
|
|
182
|
+
options?: { meta?: unknown };
|
|
183
|
+
state: { status: string; variables?: unknown; data?: unknown };
|
|
184
|
+
};
|
|
185
|
+
const attribution = componentSource(loose.options?.meta, 0);
|
|
186
|
+
const id = `mutation:${loose.mutationId ?? index}`;
|
|
187
|
+
return {
|
|
188
|
+
id,
|
|
189
|
+
kind: 'mutation' as const,
|
|
190
|
+
provider: 'mutation',
|
|
191
|
+
resource: '[mutation]',
|
|
192
|
+
operation: 'mutation',
|
|
193
|
+
status: loose.state.status,
|
|
194
|
+
component: attribution.component,
|
|
195
|
+
trigger: triggers.get(id) ?? 'mutation',
|
|
196
|
+
source: attribution.source,
|
|
197
|
+
requestSummary: redactValueSummary(loose.state.variables),
|
|
198
|
+
responseSummary: redactValueSummary(loose.state.data),
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
inspectorRows = [...queryRows, ...mutationRows];
|
|
100
202
|
}
|
|
101
203
|
|
|
204
|
+
const filteredInspectorRows = $derived(filterInspectorRows(inspectorRows, {
|
|
205
|
+
text: filterText,
|
|
206
|
+
kind: filterKind,
|
|
207
|
+
resource: filterResource,
|
|
208
|
+
status: filterStatus,
|
|
209
|
+
component: filterComponent,
|
|
210
|
+
}));
|
|
211
|
+
const inspectorResources = $derived(['all', ...new Set(inspectorRows.map((row) => row.resource))]);
|
|
212
|
+
|
|
102
213
|
onMount(() => {
|
|
103
214
|
if (!isDev) return;
|
|
104
215
|
attachSvadminDevtoolsQueryClient(queryClient);
|
|
@@ -129,6 +240,20 @@
|
|
|
129
240
|
}, ...invalidations].slice(0, 8);
|
|
130
241
|
}
|
|
131
242
|
}
|
|
243
|
+
const descriptor = parseQueryKey(event.query.queryKey);
|
|
244
|
+
if (descriptor) {
|
|
245
|
+
const trigger = event.action.type;
|
|
246
|
+
triggers.set(event.query.queryHash, trigger);
|
|
247
|
+
pushTimeline({
|
|
248
|
+
at: Date.now(),
|
|
249
|
+
kind: 'query',
|
|
250
|
+
resource: descriptor.kind === 'custom' ? '[custom]' : (descriptor.resource ?? '—'),
|
|
251
|
+
operation: `${descriptor.kind}:${descriptor.action ?? 'call'}`,
|
|
252
|
+
status: event.query.state.fetchStatus === 'fetching' ? 'fetching' : event.query.state.status,
|
|
253
|
+
trigger,
|
|
254
|
+
source: 'query-cache',
|
|
255
|
+
});
|
|
256
|
+
}
|
|
132
257
|
}
|
|
133
258
|
refreshCacheDiagnostics();
|
|
134
259
|
});
|
|
@@ -468,6 +593,79 @@
|
|
|
468
593
|
{/if}
|
|
469
594
|
</section>
|
|
470
595
|
|
|
596
|
+
<section class="space-y-2 sm:col-span-2" data-testid="devtools-inspector">
|
|
597
|
+
<h4 class="text-xs font-semibold text-foreground">Activity filters</h4>
|
|
598
|
+
<div class="grid gap-2 sm:grid-cols-2">
|
|
599
|
+
<input
|
|
600
|
+
class="h-8 rounded-md border bg-background px-2 text-xs"
|
|
601
|
+
placeholder="Filter query, mutation, resource, status, component"
|
|
602
|
+
data-testid="devtools-filter-query"
|
|
603
|
+
bind:value={filterText}
|
|
604
|
+
/>
|
|
605
|
+
<input
|
|
606
|
+
class="h-8 rounded-md border bg-background px-2 text-xs"
|
|
607
|
+
placeholder="Component"
|
|
608
|
+
data-testid="devtools-filter-component"
|
|
609
|
+
bind:value={filterComponent}
|
|
610
|
+
/>
|
|
611
|
+
<select class="h-8 rounded-md border bg-background px-2 text-xs" data-testid="devtools-filter-kind" bind:value={filterKind}>
|
|
612
|
+
<option value="all">All kinds</option>
|
|
613
|
+
<option value="query">Queries</option>
|
|
614
|
+
<option value="mutation">Mutations</option>
|
|
615
|
+
</select>
|
|
616
|
+
<select class="h-8 rounded-md border bg-background px-2 text-xs" data-testid="devtools-filter-status" bind:value={filterStatus}>
|
|
617
|
+
<option value="all">All statuses</option>
|
|
618
|
+
<option value="success">success</option>
|
|
619
|
+
<option value="error">error</option>
|
|
620
|
+
<option value="fetching">fetching</option>
|
|
621
|
+
<option value="pending">pending</option>
|
|
622
|
+
</select>
|
|
623
|
+
<select class="h-8 rounded-md border bg-background px-2 text-xs sm:col-span-2" data-testid="devtools-filter-resource" bind:value={filterResource}>
|
|
624
|
+
{#each inspectorResources as resource (resource)}
|
|
625
|
+
<option value={resource}>{resource}</option>
|
|
626
|
+
{/each}
|
|
627
|
+
</select>
|
|
628
|
+
</div>
|
|
629
|
+
{#if filteredInspectorRows.length === 0}
|
|
630
|
+
<div class="rounded-md border px-2.5 py-2 text-[0.6875rem] text-muted-foreground">No matching activity.</div>
|
|
631
|
+
{:else}
|
|
632
|
+
{#each filteredInspectorRows as row (row.id)}
|
|
633
|
+
<div class="rounded-md border px-2.5 py-2 text-xs" data-testid="devtools-inspector-row">
|
|
634
|
+
<div class="flex flex-wrap items-center justify-between gap-2">
|
|
635
|
+
<span class="font-medium text-foreground">{row.kind} · {row.provider} · {row.resource}</span>
|
|
636
|
+
<Badge variant="outline">{row.operation}</Badge>
|
|
637
|
+
</div>
|
|
638
|
+
<dl class="mt-1 grid grid-cols-2 gap-1 text-[0.6875rem] text-muted-foreground sm:grid-cols-4">
|
|
639
|
+
<div><dt>Status</dt><dd class="text-foreground">{row.status}</dd></div>
|
|
640
|
+
<div><dt>Trigger</dt><dd class="text-foreground">{row.trigger}</dd></div>
|
|
641
|
+
<div><dt>Source</dt><dd class="text-foreground">{row.source}</dd></div>
|
|
642
|
+
<div><dt>Component</dt><dd class="text-foreground">{row.component}</dd></div>
|
|
643
|
+
</dl>
|
|
644
|
+
<p class="mt-1 text-[0.6875rem] text-muted-foreground" data-testid="devtools-redacted-payload">request {row.requestSummary} · response {row.responseSummary}</p>
|
|
645
|
+
{#if row.kind === 'query'}
|
|
646
|
+
<button type="button" class="mt-1 text-[0.6875rem] underline" data-testid="devtools-refetch" onclick={() => replayRow(row)}>
|
|
647
|
+
Refetch
|
|
648
|
+
</button>
|
|
649
|
+
{/if}
|
|
650
|
+
</div>
|
|
651
|
+
{/each}
|
|
652
|
+
{/if}
|
|
653
|
+
</section>
|
|
654
|
+
|
|
655
|
+
<section class="space-y-1.5 sm:col-span-2">
|
|
656
|
+
<h4 class="text-xs font-semibold text-foreground">Dependency updates</h4>
|
|
657
|
+
{#if timeline.length === 0}
|
|
658
|
+
<div class="rounded-md border px-2.5 py-2 text-[0.6875rem] text-muted-foreground">No dependency updates yet.</div>
|
|
659
|
+
{:else}
|
|
660
|
+
{#each timeline as entry, index (`${entry.at}:${entry.operation}:${index}`)}
|
|
661
|
+
<div class="flex flex-wrap items-center justify-between gap-2 rounded-md border px-2.5 py-2 text-xs" data-testid="devtools-timeline">
|
|
662
|
+
<span>{entry.resource} · {entry.operation}</span>
|
|
663
|
+
<Badge variant="outline">{entry.trigger} · {entry.source}</Badge>
|
|
664
|
+
</div>
|
|
665
|
+
{/each}
|
|
666
|
+
{/if}
|
|
667
|
+
</section>
|
|
668
|
+
|
|
471
669
|
<p class="text-[0.6875rem] text-muted-foreground sm:col-span-2">
|
|
472
670
|
Query keys, variables, cached records, mutation payloads, and error bodies are intentionally hidden.
|
|
473
671
|
</p>
|
|
@@ -14,6 +14,18 @@
|
|
|
14
14
|
readonly?: boolean;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export interface EditableTableEditor {
|
|
18
|
+
rows: Record<string, unknown>[];
|
|
19
|
+
errors?: Readonly<Record<string, string>>;
|
|
20
|
+
saving?: boolean;
|
|
21
|
+
failure?: string | null;
|
|
22
|
+
onCell?: (rowIndex: number, key: string, value: unknown) => void;
|
|
23
|
+
onSubmit?: () => void | Promise<void>;
|
|
24
|
+
onRetry?: () => void | Promise<void>;
|
|
25
|
+
onAdd?: () => void;
|
|
26
|
+
onDelete?: (rowIndex: number) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
interface Props {
|
|
18
30
|
columns: EditableTableColumn[];
|
|
19
31
|
data?: Record<string, unknown>[];
|
|
@@ -22,6 +34,8 @@
|
|
|
22
34
|
allowDelete?: boolean;
|
|
23
35
|
onchange?: (data: Record<string, unknown>[]) => void;
|
|
24
36
|
onsave?: (data: Record<string, unknown>[]) => void | Promise<void>;
|
|
37
|
+
/** Headless contract from useEditableTable().editor. */
|
|
38
|
+
editor?: EditableTableEditor;
|
|
25
39
|
class?: string;
|
|
26
40
|
}
|
|
27
41
|
|
|
@@ -33,14 +47,21 @@
|
|
|
33
47
|
allowDelete = true,
|
|
34
48
|
onchange,
|
|
35
49
|
onsave,
|
|
50
|
+
editor,
|
|
36
51
|
class: className = '',
|
|
37
52
|
}: Props = $props();
|
|
38
53
|
|
|
54
|
+
const rows = $derived(editor ? editor.rows : data);
|
|
55
|
+
|
|
39
56
|
const i18n = useTranslation();
|
|
40
57
|
|
|
41
58
|
let isSaving = $state(false);
|
|
42
59
|
|
|
43
60
|
function updateCell(rowIndex: number, columnKey: string, value: unknown) {
|
|
61
|
+
if (editor?.onCell) {
|
|
62
|
+
editor.onCell(rowIndex, columnKey, value);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
44
65
|
const nextData = [...data];
|
|
45
66
|
nextData[rowIndex] = {
|
|
46
67
|
...nextData[rowIndex],
|
|
@@ -51,6 +72,10 @@
|
|
|
51
72
|
}
|
|
52
73
|
|
|
53
74
|
function handleAddRow() {
|
|
75
|
+
if (editor?.onAdd) {
|
|
76
|
+
editor.onAdd();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
54
79
|
const newRow: Record<string, unknown> = {
|
|
55
80
|
[rowKey]: `row_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
56
81
|
};
|
|
@@ -64,11 +89,19 @@
|
|
|
64
89
|
}
|
|
65
90
|
|
|
66
91
|
function handleDeleteRow(index: number) {
|
|
92
|
+
if (editor?.onDelete) {
|
|
93
|
+
editor.onDelete(index);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
67
96
|
data = data.filter((_, idx) => idx !== index);
|
|
68
97
|
onchange?.(data);
|
|
69
98
|
}
|
|
70
99
|
|
|
71
100
|
async function handleSave() {
|
|
101
|
+
if (editor?.onSubmit) {
|
|
102
|
+
await editor.onSubmit();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
72
105
|
isSaving = true;
|
|
73
106
|
try {
|
|
74
107
|
await onsave?.(data);
|
|
@@ -76,12 +109,16 @@
|
|
|
76
109
|
isSaving = false;
|
|
77
110
|
}
|
|
78
111
|
}
|
|
112
|
+
|
|
113
|
+
async function handleRetry() {
|
|
114
|
+
await editor?.onRetry?.();
|
|
115
|
+
}
|
|
79
116
|
</script>
|
|
80
117
|
|
|
81
118
|
<div class={cn('space-y-3 rounded-xl border border-border bg-card p-4 shadow-xs text-xs', className)}>
|
|
82
119
|
<div class="flex items-center justify-between gap-2 pb-2 border-b border-border/60">
|
|
83
120
|
<div class="font-semibold text-foreground">
|
|
84
|
-
Editable Grid <span class="text-muted-foreground font-normal">({
|
|
121
|
+
Editable Grid <span class="text-muted-foreground font-normal">({rows.length} records)</span>
|
|
85
122
|
</div>
|
|
86
123
|
|
|
87
124
|
<div class="flex items-center gap-2">
|
|
@@ -91,9 +128,9 @@
|
|
|
91
128
|
Add Row
|
|
92
129
|
</Button>
|
|
93
130
|
{/if}
|
|
94
|
-
{#if onsave}
|
|
95
|
-
<Button size="sm" class="h-8 text-xs gap-1 min-w-20" disabled={isSaving} onclick={handleSave}>
|
|
96
|
-
{#if isSaving}
|
|
131
|
+
{#if onsave || editor?.onSubmit}
|
|
132
|
+
<Button size="sm" class="h-8 text-xs gap-1 min-w-20" disabled={isSaving || editor?.saving} onclick={handleSave}>
|
|
133
|
+
{#if isSaving || editor?.saving}
|
|
97
134
|
<Loader2 class="h-3.5 w-3.5 animate-spin" />
|
|
98
135
|
{:else}
|
|
99
136
|
<Save class="h-3.5 w-3.5" />
|
|
@@ -101,9 +138,18 @@
|
|
|
101
138
|
Save All
|
|
102
139
|
</Button>
|
|
103
140
|
{/if}
|
|
141
|
+
{#if editor?.failure && editor.onRetry}
|
|
142
|
+
<Button variant="outline" size="sm" class="h-8 text-xs" onclick={handleRetry}>
|
|
143
|
+
Retry
|
|
144
|
+
</Button>
|
|
145
|
+
{/if}
|
|
104
146
|
</div>
|
|
105
147
|
</div>
|
|
106
148
|
|
|
149
|
+
{#if editor?.failure}
|
|
150
|
+
<p class="text-destructive" data-testid="editable-table-failure">{editor.failure}</p>
|
|
151
|
+
{/if}
|
|
152
|
+
|
|
107
153
|
<div class="overflow-x-auto rounded-lg border border-border/60">
|
|
108
154
|
<table class="w-full text-left border-collapse">
|
|
109
155
|
<thead class="bg-muted/40 font-semibold text-muted-foreground border-b border-border/60">
|
|
@@ -120,7 +166,7 @@
|
|
|
120
166
|
</tr>
|
|
121
167
|
</thead>
|
|
122
168
|
<tbody class="divide-y divide-border/40">
|
|
123
|
-
{#each
|
|
169
|
+
{#each rows as row, rowIndex (row[rowKey] ?? rowIndex)}
|
|
124
170
|
<tr class="hover:bg-muted/20 transition-colors">
|
|
125
171
|
{#each columns as col (col.key)}
|
|
126
172
|
<td class="p-1.5">
|
|
@@ -184,9 +230,16 @@
|
|
|
184
230
|
</td>
|
|
185
231
|
{/if}
|
|
186
232
|
</tr>
|
|
233
|
+
{#if editor?.errors?.[String(row[rowKey] ?? '')]}
|
|
234
|
+
<tr>
|
|
235
|
+
<td colspan={columns.length + (allowDelete ? 1 : 0)} class="px-3 py-1 text-destructive">
|
|
236
|
+
{editor.errors[String(row[rowKey] ?? '')]}
|
|
237
|
+
</td>
|
|
238
|
+
</tr>
|
|
239
|
+
{/if}
|
|
187
240
|
{/each}
|
|
188
241
|
|
|
189
|
-
{#if
|
|
242
|
+
{#if rows.length === 0}
|
|
190
243
|
<tr>
|
|
191
244
|
<td colspan={columns.length + (allowDelete ? 1 : 0)} class="py-8 text-center text-muted-foreground">
|
|
192
245
|
No rows. Click "Add Row" to create the first record.
|
|
@@ -10,6 +10,17 @@ export interface EditableTableColumn {
|
|
|
10
10
|
width?: string;
|
|
11
11
|
readonly?: boolean;
|
|
12
12
|
}
|
|
13
|
+
export interface EditableTableEditor {
|
|
14
|
+
rows: Record<string, unknown>[];
|
|
15
|
+
errors?: Readonly<Record<string, string>>;
|
|
16
|
+
saving?: boolean;
|
|
17
|
+
failure?: string | null;
|
|
18
|
+
onCell?: (rowIndex: number, key: string, value: unknown) => void;
|
|
19
|
+
onSubmit?: () => void | Promise<void>;
|
|
20
|
+
onRetry?: () => void | Promise<void>;
|
|
21
|
+
onAdd?: () => void;
|
|
22
|
+
onDelete?: (rowIndex: number) => void;
|
|
23
|
+
}
|
|
13
24
|
interface Props {
|
|
14
25
|
columns: EditableTableColumn[];
|
|
15
26
|
data?: Record<string, unknown>[];
|
|
@@ -18,6 +29,8 @@ interface Props {
|
|
|
18
29
|
allowDelete?: boolean;
|
|
19
30
|
onchange?: (data: Record<string, unknown>[]) => void;
|
|
20
31
|
onsave?: (data: Record<string, unknown>[]) => void | Promise<void>;
|
|
32
|
+
/** Headless contract from useEditableTable().editor. */
|
|
33
|
+
editor?: EditableTableEditor;
|
|
21
34
|
class?: string;
|
|
22
35
|
}
|
|
23
36
|
declare const EditableTable: import("svelte").Component<Props, {}, "data">;
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import { PackageOpen } from '@lucide/svelte';
|
|
4
4
|
import { useTranslation } from '@svadmin/core';
|
|
5
|
+
import { useComponentConfig } from './ConfigProvider.svelte';
|
|
5
6
|
|
|
6
7
|
const i18n = useTranslation();
|
|
8
|
+
const config = useComponentConfig();
|
|
7
9
|
|
|
8
10
|
let {
|
|
9
|
-
title
|
|
10
|
-
description
|
|
11
|
+
title,
|
|
12
|
+
description,
|
|
11
13
|
image,
|
|
12
14
|
imageAlt,
|
|
13
15
|
icon,
|
|
@@ -22,6 +24,17 @@
|
|
|
22
24
|
icon?: Snippet;
|
|
23
25
|
children?: Snippet;
|
|
24
26
|
}>();
|
|
27
|
+
|
|
28
|
+
function textDefault(value: unknown): string | undefined {
|
|
29
|
+
return typeof value === 'string' ? value : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const emptyDefaults = $derived(config.empty);
|
|
33
|
+
const componentEmpty = $derived(config.componentDefaults.Empty ?? {});
|
|
34
|
+
const resolvedTitle = $derived(title ?? emptyDefaults.title ?? textDefault(componentEmpty.title) ?? i18n.t('empty.title'));
|
|
35
|
+
const resolvedDescription = $derived(description ?? emptyDefaults.description ?? textDefault(componentEmpty.description) ?? i18n.t('empty.description'));
|
|
36
|
+
const resolvedImage = $derived(image ?? emptyDefaults.image ?? textDefault(componentEmpty.image));
|
|
37
|
+
const resolvedImageAlt = $derived(imageAlt ?? emptyDefaults.imageAlt ?? textDefault(componentEmpty.imageAlt) ?? '');
|
|
25
38
|
</script>
|
|
26
39
|
|
|
27
40
|
<div
|
|
@@ -30,8 +43,8 @@
|
|
|
30
43
|
aria-live="polite"
|
|
31
44
|
>
|
|
32
45
|
<span class="empty-state__icon" aria-hidden="true">
|
|
33
|
-
{#if
|
|
34
|
-
<img class="empty-state__image" src={
|
|
46
|
+
{#if resolvedImage}
|
|
47
|
+
<img class="empty-state__image" src={resolvedImage} alt={resolvedImageAlt} loading="lazy" decoding="async" />
|
|
35
48
|
{:else if icon}
|
|
36
49
|
{@render icon()}
|
|
37
50
|
{:else}
|
|
@@ -39,8 +52,8 @@
|
|
|
39
52
|
{/if}
|
|
40
53
|
</span>
|
|
41
54
|
<div class="empty-state__body">
|
|
42
|
-
<h3>{
|
|
43
|
-
{#if
|
|
55
|
+
<h3>{resolvedTitle}</h3>
|
|
56
|
+
{#if resolvedDescription}<p>{resolvedDescription}</p>{/if}
|
|
44
57
|
{#if children}
|
|
45
58
|
<div class="empty-state__action">
|
|
46
59
|
{@render children()}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { useTranslation } from '@svadmin/core/i18n';
|
|
4
|
+
import { useComponentConfig, DEFAULT_PAGE_SIZE_OPTIONS } from './ConfigProvider.svelte';
|
|
4
5
|
import { listText } from './list-i18n.js';
|
|
5
6
|
import { listPaginationItems } from './list-pagination.js';
|
|
6
7
|
|
|
@@ -30,11 +31,11 @@
|
|
|
30
31
|
rangeStart = 0,
|
|
31
32
|
rangeEnd = 0,
|
|
32
33
|
pageSize,
|
|
33
|
-
pageSizeOptions
|
|
34
|
+
pageSizeOptions,
|
|
34
35
|
pageSizeLabel,
|
|
35
|
-
showSummary
|
|
36
|
-
simple
|
|
37
|
-
showJumper
|
|
36
|
+
showSummary,
|
|
37
|
+
simple,
|
|
38
|
+
showJumper,
|
|
38
39
|
onPageChange,
|
|
39
40
|
onPageSizeChange,
|
|
40
41
|
class: className = '',
|
|
@@ -42,6 +43,53 @@
|
|
|
42
43
|
}: Props = $props();
|
|
43
44
|
|
|
44
45
|
const i18n = useTranslation();
|
|
46
|
+
const config = useComponentConfig();
|
|
47
|
+
|
|
48
|
+
function booleanDefault(value: unknown): boolean | undefined {
|
|
49
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function numberList(value: unknown): readonly number[] | undefined {
|
|
53
|
+
if (!Array.isArray(value) || value.length === 0) return undefined;
|
|
54
|
+
if (value.some((item) => typeof item !== 'number' || !Number.isFinite(item))) return undefined;
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function numberDefault(value: unknown): number | undefined {
|
|
59
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const paginationDefaults = $derived(config.pagination);
|
|
63
|
+
const paginationComponentDefaults = $derived(config.componentDefaults.Pagination ?? {});
|
|
64
|
+
const resolvedPageSizeOptions = $derived(
|
|
65
|
+
pageSizeOptions
|
|
66
|
+
?? paginationDefaults.pageSizeOptions
|
|
67
|
+
?? numberList(paginationComponentDefaults.pageSizeOptions)
|
|
68
|
+
?? DEFAULT_PAGE_SIZE_OPTIONS,
|
|
69
|
+
);
|
|
70
|
+
const resolvedShowSummary = $derived(
|
|
71
|
+
showSummary
|
|
72
|
+
?? paginationDefaults.showSummary
|
|
73
|
+
?? booleanDefault(paginationComponentDefaults.showSummary)
|
|
74
|
+
?? true,
|
|
75
|
+
);
|
|
76
|
+
const resolvedSimple = $derived(
|
|
77
|
+
simple
|
|
78
|
+
?? paginationDefaults.simple
|
|
79
|
+
?? booleanDefault(paginationComponentDefaults.simple)
|
|
80
|
+
?? false,
|
|
81
|
+
);
|
|
82
|
+
const resolvedShowJumper = $derived(
|
|
83
|
+
showJumper
|
|
84
|
+
?? paginationDefaults.showJumper
|
|
85
|
+
?? booleanDefault(paginationComponentDefaults.showJumper)
|
|
86
|
+
?? false,
|
|
87
|
+
);
|
|
88
|
+
const resolvedPageSize = $derived(
|
|
89
|
+
pageSize
|
|
90
|
+
?? paginationDefaults.pageSize
|
|
91
|
+
?? numberDefault(paginationComponentDefaults.pageSize),
|
|
92
|
+
);
|
|
45
93
|
|
|
46
94
|
const items = $derived(listPaginationItems(page, totalPages));
|
|
47
95
|
const paginated = $derived(totalPages > 1);
|
|
@@ -58,17 +106,17 @@
|
|
|
58
106
|
|
|
59
107
|
{#if paginated}
|
|
60
108
|
<div {...restProps} class={`svadmin-list-pagination ${className}`.trim()} role="navigation" aria-label={listText(i18n, 'listPagination.navigation', { label })}>
|
|
61
|
-
{#if
|
|
109
|
+
{#if resolvedShowSummary}
|
|
62
110
|
<div class="svadmin-list-pagination__info">
|
|
63
111
|
<span>{listText(i18n, 'listPagination.range', { start: rangeStart, end: rangeEnd, total })}</span>
|
|
64
|
-
{#if onPageSizeChange &&
|
|
112
|
+
{#if onPageSizeChange && resolvedPageSize !== undefined}
|
|
65
113
|
<span class="svadmin-list-pagination__size">{pageSizeLabel ?? listText(i18n, 'listPagination.pageSizeLabel')}
|
|
66
114
|
<select
|
|
67
115
|
aria-label={listText(i18n, 'listPagination.pageSizeAria', { label })}
|
|
68
|
-
value={
|
|
116
|
+
value={resolvedPageSize}
|
|
69
117
|
onchange={(event) => onPageSizeChange?.(Number((event.currentTarget as HTMLSelectElement).value))}
|
|
70
118
|
>
|
|
71
|
-
{#each
|
|
119
|
+
{#each resolvedPageSizeOptions as size (size)}<option value={size}>{listText(i18n, 'listPagination.pageSizeOption', { size })}</option>{/each}
|
|
72
120
|
</select>
|
|
73
121
|
</span>
|
|
74
122
|
{/if}
|
|
@@ -78,7 +126,7 @@
|
|
|
78
126
|
<button type="button" class="svadmin-list-pagination__control" disabled={page <= 1}
|
|
79
127
|
title={listText(i18n, page <= 1 ? 'listPagination.firstPage' : 'listPagination.previous')}
|
|
80
128
|
aria-label={listText(i18n, 'listPagination.previousAria', { label })} onclick={() => onPageChange(page - 1)}>{listText(i18n, 'listPagination.previous')}</button>
|
|
81
|
-
{#if
|
|
129
|
+
{#if resolvedSimple}
|
|
82
130
|
<span class="svadmin-list-pagination__simple">{listText(i18n, 'listPagination.simplePage', { page, total: totalPages })}</span>
|
|
83
131
|
{:else}
|
|
84
132
|
<div class="svadmin-list-pagination__pages" role="group" aria-label={listText(i18n, 'listPagination.pageList', { label })}>
|
|
@@ -95,7 +143,7 @@
|
|
|
95
143
|
{/if}
|
|
96
144
|
{/each}
|
|
97
145
|
</div>
|
|
98
|
-
{#if
|
|
146
|
+
{#if resolvedShowJumper}
|
|
99
147
|
<label class="svadmin-list-pagination__jumper">
|
|
100
148
|
<span>{listText(i18n, 'listPagination.jumpTo')}</span>
|
|
101
149
|
<input type="number" min="1" max={totalPages} value={page}
|
|
@@ -109,7 +157,7 @@
|
|
|
109
157
|
aria-label={listText(i18n, 'listPagination.nextAria', { label })} onclick={() => onPageChange(page + 1)}>{listText(i18n, 'listPagination.next')}</button>
|
|
110
158
|
</div>
|
|
111
159
|
</div>
|
|
112
|
-
{:else if
|
|
160
|
+
{:else if resolvedShowSummary}
|
|
113
161
|
<p {...restProps} class={`svadmin-list-pagination__summary ${className}`.trim()}>{listText(i18n, 'common.total', { total })}</p>
|
|
114
162
|
{/if}
|
|
115
163
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { X } from '@lucide/svelte';
|
|
3
|
-
import {
|
|
3
|
+
import { useNotificationController, type NotificationPlacement } from '../notifications.svelte.js';
|
|
4
4
|
|
|
5
5
|
const placements: NotificationPlacement[] = ['top-right', 'top-left', 'bottom-right', 'bottom-left'];
|
|
6
|
+
const controller = useNotificationController();
|
|
6
7
|
const groups = $derived(placements
|
|
7
8
|
.map((placement) => ({
|
|
8
9
|
placement,
|
|
9
|
-
items:
|
|
10
|
+
items: controller.items.filter((item) => item.placement === placement),
|
|
10
11
|
}))
|
|
11
12
|
.filter((group) => group.items.length > 0));
|
|
12
13
|
</script>
|
|
@@ -24,10 +25,10 @@
|
|
|
24
25
|
<p class="svadmin-notification-host__title">{item.title}</p>
|
|
25
26
|
{#if item.description}<p class="svadmin-notification-host__description">{item.description}</p>{/if}
|
|
26
27
|
{#if item.actionLabel && item.onAction}
|
|
27
|
-
<button type="button" class="svadmin-notification-host__action" onclick={() => { item.onAction?.();
|
|
28
|
+
<button type="button" class="svadmin-notification-host__action" onclick={() => { item.onAction?.(); controller.close(item.id); }}>{item.actionLabel}</button>
|
|
28
29
|
{/if}
|
|
29
30
|
</div>
|
|
30
|
-
<button type="button" class="svadmin-notification-host__close" aria-label="Close notification" onclick={() =>
|
|
31
|
+
<button type="button" class="svadmin-notification-host__close" aria-label="Close notification" onclick={() => controller.close(item.id)}>
|
|
31
32
|
<X size={14} aria-hidden="true" />
|
|
32
33
|
</button>
|
|
33
34
|
</section>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
3
|
+
import { captureAdminContext, useCan, type Action } from '@svadmin/core';
|
|
4
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
import DataState from './content/DataState.svelte';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
resource: string;
|
|
10
|
+
action?: Action;
|
|
11
|
+
id?: string | number;
|
|
12
|
+
children: Snippet;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
resource,
|
|
17
|
+
action = 'list',
|
|
18
|
+
id,
|
|
19
|
+
children,
|
|
20
|
+
}: Props = $props();
|
|
21
|
+
|
|
22
|
+
const adminContext = captureAdminContext();
|
|
23
|
+
const i18n = useTranslation();
|
|
24
|
+
const accessControlEnabled = $derived(Boolean(adminContext.accessControlProvider));
|
|
25
|
+
const permission = useCan(() => (definedOptions({
|
|
26
|
+
resource,
|
|
27
|
+
action,
|
|
28
|
+
id,
|
|
29
|
+
queryOptions: { enabled: accessControlEnabled },
|
|
30
|
+
})));
|
|
31
|
+
const denialDescription = $derived(
|
|
32
|
+
permission.isError ? i18n.t('common.permissionUnavailable') : i18n.t('common.permissionDenied'),
|
|
33
|
+
);
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{#if accessControlEnabled && permission.isLoading}
|
|
37
|
+
<DataState state="loading" />
|
|
38
|
+
{:else if !accessControlEnabled || permission.allowed}
|
|
39
|
+
{@render children()}
|
|
40
|
+
{:else}
|
|
41
|
+
<DataState state={permission.isError ? 'error' : 'forbidden'} description={denialDescription} />
|
|
42
|
+
{/if}
|