@svadmin/ui 0.108.3 → 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/ConfigProvider.svelte +78 -1
- package/dist/components/ConfigProvider.svelte.d.ts +36 -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 +3 -3
- 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
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
const resources = $derived(adminContext.resources.filter((resource) => resource.meta?.['aboutVisible'] !== false));
|
|
12
12
|
const providerNames = $derived(adminContext.getDataProviderNames());
|
|
13
13
|
let { version: suppliedVersion, headingLevel = 'h1' }: { version?: string; headingLevel?: 'h1' | 'h2' } = $props();
|
|
14
|
-
const buildVersion = "0.108.
|
|
14
|
+
const buildVersion = "0.108.4";
|
|
15
15
|
const version = $derived(suppliedVersion ?? (
|
|
16
16
|
buildVersion.startsWith('__')
|
|
17
17
|
? (i18n.locale === 'zh-CN' ? '开发构建(未提供版本)' : 'Development build (version unavailable)')
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import type { Component as PageComponent } from 'svelte';
|
|
3
|
+
import type { CustomRouteAccessConfig } from './custom-route-access.js';
|
|
3
4
|
|
|
4
5
|
export interface AdminPageRoute {
|
|
5
6
|
readonly path: string;
|
|
6
7
|
readonly component: PageComponent<{ route: string; params: Record<string, string | undefined> }>;
|
|
7
8
|
readonly title?: string;
|
|
9
|
+
/**
|
|
10
|
+
* 直接 URL 的权限。省略时继承同路径菜单的 `meta.resource` / `meta.action`。
|
|
11
|
+
* `false` 保持公开,即使菜单项受保护。
|
|
12
|
+
*/
|
|
13
|
+
readonly access?: CustomRouteAccessConfig | false;
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
const loadPublicProfilePage = () => import('./profile/PublicProfilePage.svelte');
|
|
@@ -92,6 +98,9 @@
|
|
|
92
98
|
import SystemPageShell from './SystemPageShell.svelte';
|
|
93
99
|
import LazyPage from './LazyPage.svelte';
|
|
94
100
|
import ResourceAccessGuard from './ResourceAccessGuard.svelte';
|
|
101
|
+
import RouteAccessGuard from './RouteAccessGuard.svelte';
|
|
102
|
+
import { resolveCustomRouteAccess } from './custom-route-access.js';
|
|
103
|
+
import { bindNotificationRoot, provideNotificationController } from '../notifications.svelte.js';
|
|
95
104
|
import { Button } from './ui/button/index.js';
|
|
96
105
|
import { Input } from './ui/input/index.js';
|
|
97
106
|
import { Badge } from './ui/badge/index.js';
|
|
@@ -352,6 +361,7 @@
|
|
|
352
361
|
get tenant() { return tenant; },
|
|
353
362
|
}));
|
|
354
363
|
const adminContext = captureAdminContext();
|
|
364
|
+
const appNotifications = provideNotificationController();
|
|
355
365
|
|
|
356
366
|
// Context must be available synchronously to descendants during their first render.
|
|
357
367
|
syncComponentRegistry();
|
|
@@ -576,6 +586,7 @@
|
|
|
576
586
|
</script>
|
|
577
587
|
|
|
578
588
|
<QueryClientProvider client={queryClient}>
|
|
589
|
+
<div class="svadmin-admin-app" style="display: contents" use:bindNotificationRoot={appNotifications}>
|
|
579
590
|
{#if !resolvedDataProvider}
|
|
580
591
|
<ConfigErrorScreen title="{title} — DataProvider is required" />
|
|
581
592
|
{:else if !authChecked || authProviderPending}
|
|
@@ -665,7 +676,14 @@
|
|
|
665
676
|
<SettingsPage {...notificationPreferencesProvider ? { preferencesProvider: notificationPreferencesProvider } : {}} />
|
|
666
677
|
{:else if customRouteMatch}
|
|
667
678
|
{@const CustomPage = customRouteMatch.candidate.component}
|
|
668
|
-
|
|
679
|
+
{@const routeAccess = resolveCustomRouteAccess(customRouteMatch.candidate, path, menu, customRouteMatch.params)}
|
|
680
|
+
{#if routeAccess}
|
|
681
|
+
<RouteAccessGuard resource={routeAccess.resource} action={routeAccess.action} {...routeAccess.id === undefined ? {} : { id: routeAccess.id }}>
|
|
682
|
+
<CustomPage route={customRouteMatch.candidate.path} params={customRouteMatch.params} />
|
|
683
|
+
</RouteAccessGuard>
|
|
684
|
+
{:else}
|
|
685
|
+
<CustomPage route={customRouteMatch.candidate.path} params={customRouteMatch.params} />
|
|
686
|
+
{/if}
|
|
669
687
|
{:else if renderedRoute === '/' || renderedRoute === '' || renderedRoute === '/inventory-dashboard'}
|
|
670
688
|
{#if dashboard}
|
|
671
689
|
{@render dashboard()}
|
|
@@ -725,4 +743,5 @@
|
|
|
725
743
|
{/if}
|
|
726
744
|
<Toast />
|
|
727
745
|
<NotificationHost />
|
|
746
|
+
</div>
|
|
728
747
|
</QueryClientProvider>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Component as PageComponent } from 'svelte';
|
|
2
|
+
import type { CustomRouteAccessConfig } from './custom-route-access.js';
|
|
2
3
|
export interface AdminPageRoute {
|
|
3
4
|
readonly path: string;
|
|
4
5
|
readonly component: PageComponent<{
|
|
@@ -6,6 +7,11 @@ export interface AdminPageRoute {
|
|
|
6
7
|
params: Record<string, string | undefined>;
|
|
7
8
|
}>;
|
|
8
9
|
readonly title?: string;
|
|
10
|
+
/**
|
|
11
|
+
* 直接 URL 的权限。省略时继承同路径菜单的 `meta.resource` / `meta.action`。
|
|
12
|
+
* `false` 保持公开,即使菜单项受保护。
|
|
13
|
+
*/
|
|
14
|
+
readonly access?: CustomRouteAccessConfig | false;
|
|
9
15
|
}
|
|
10
16
|
import '../app.css';
|
|
11
17
|
import { type Component, type Snippet } from 'svelte';
|
|
@@ -1,22 +1,91 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import { getContext } from 'svelte';
|
|
3
3
|
|
|
4
|
+
export type ComponentPropDefaults = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
5
|
+
|
|
6
|
+
export interface EmptyStateDefaults {
|
|
7
|
+
readonly title?: string;
|
|
8
|
+
readonly description?: string;
|
|
9
|
+
readonly image?: string;
|
|
10
|
+
readonly imageAlt?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PaginationDefaults {
|
|
14
|
+
readonly pageSize?: number;
|
|
15
|
+
readonly pageSizeOptions?: readonly number[];
|
|
16
|
+
readonly showSummary?: boolean;
|
|
17
|
+
readonly simple?: boolean;
|
|
18
|
+
readonly showJumper?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 弹出层挂载点。`node` 是触发器或锚点,不是已经挂到 body 上的浮层。
|
|
23
|
+
* 返回元素、选择器,或空值以回退到 document.body。
|
|
24
|
+
*/
|
|
25
|
+
export type GetPopupContainer = (node?: HTMLElement) => HTMLElement | string | null | undefined;
|
|
26
|
+
|
|
27
|
+
/** Node SSR 没有 HTMLElement。typeof 守卫避免 `instanceof` 触发 ReferenceError。 */
|
|
28
|
+
function isHtmlElement(value: unknown): value is HTMLElement {
|
|
29
|
+
return typeof HTMLElement !== 'undefined' && value instanceof HTMLElement;
|
|
30
|
+
}
|
|
31
|
+
|
|
4
32
|
export interface ComponentConfig {
|
|
5
33
|
theme?: 'light' | 'dark' | 'system';
|
|
6
34
|
density?: 'default' | 'compact';
|
|
7
35
|
direction?: 'ltr' | 'rtl';
|
|
8
36
|
locale?: string;
|
|
9
37
|
componentSize?: 'sm' | 'md' | 'lg';
|
|
38
|
+
/**
|
|
39
|
+
* 按组件名设置的默认参数,例如 `{ Button: { variant: 'outline' } }`。显式 props 优先。
|
|
40
|
+
* 目前只有 Button、Empty(EmptyState)和 Pagination(ListPagination)会读取。
|
|
41
|
+
*/
|
|
42
|
+
componentDefaults?: ComponentPropDefaults;
|
|
43
|
+
/** 空状态默认文案和插图。 */
|
|
44
|
+
empty?: EmptyStateDefaults;
|
|
45
|
+
/** 分页默认参数。 */
|
|
46
|
+
pagination?: PaginationDefaults;
|
|
47
|
+
/** 弹出层与浮层的挂载容器,语义对齐 getPopupContainer。 */
|
|
48
|
+
getPopupContainer?: GetPopupContainer;
|
|
10
49
|
}
|
|
11
50
|
|
|
12
51
|
export const CONFIG_CONTEXT_KEY = Symbol('svadmin-component-config');
|
|
13
52
|
|
|
53
|
+
export const DEFAULT_PAGE_SIZE_OPTIONS = Object.freeze([10, 20, 50]);
|
|
54
|
+
|
|
55
|
+
export const DEFAULT_COMPONENT_DEFAULTS: ComponentPropDefaults = Object.freeze({});
|
|
56
|
+
|
|
57
|
+
export const DEFAULT_EMPTY_STATE: EmptyStateDefaults = Object.freeze({});
|
|
58
|
+
|
|
59
|
+
export const DEFAULT_PAGINATION: PaginationDefaults = Object.freeze({});
|
|
60
|
+
|
|
61
|
+
export function defaultGetPopupContainer(node?: HTMLElement): HTMLElement | undefined {
|
|
62
|
+
const doc = node?.ownerDocument ?? (typeof document === 'undefined' ? undefined : document);
|
|
63
|
+
return doc?.body;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function resolvePopupContainer(getPopupContainer: GetPopupContainer | undefined, node?: HTMLElement): HTMLElement | undefined {
|
|
67
|
+
const fallback = defaultGetPopupContainer(node);
|
|
68
|
+
if (!getPopupContainer) return fallback;
|
|
69
|
+
const resolved = getPopupContainer(node);
|
|
70
|
+
if (isHtmlElement(resolved)) return resolved;
|
|
71
|
+
if (typeof resolved === 'string' && resolved.length > 0) {
|
|
72
|
+
const doc = node?.ownerDocument ?? (typeof document === 'undefined' ? undefined : document);
|
|
73
|
+
const found = doc?.querySelector(resolved);
|
|
74
|
+
if (isHtmlElement(found)) return found;
|
|
75
|
+
}
|
|
76
|
+
return fallback;
|
|
77
|
+
}
|
|
78
|
+
|
|
14
79
|
export const DEFAULT_COMPONENT_CONFIG: Required<ComponentConfig> = {
|
|
15
80
|
theme: 'system',
|
|
16
81
|
density: 'default',
|
|
17
82
|
direction: 'ltr',
|
|
18
83
|
locale: 'en',
|
|
19
84
|
componentSize: 'md',
|
|
85
|
+
componentDefaults: DEFAULT_COMPONENT_DEFAULTS,
|
|
86
|
+
empty: DEFAULT_EMPTY_STATE,
|
|
87
|
+
pagination: DEFAULT_PAGINATION,
|
|
88
|
+
getPopupContainer: defaultGetPopupContainer,
|
|
20
89
|
};
|
|
21
90
|
|
|
22
91
|
/** 当前组件是否位于 ConfigProvider 内。只能在组件初始化时调用。 */
|
|
@@ -45,6 +114,10 @@
|
|
|
45
114
|
direction = 'ltr',
|
|
46
115
|
locale = 'en',
|
|
47
116
|
componentSize = 'md',
|
|
117
|
+
componentDefaults = DEFAULT_COMPONENT_DEFAULTS,
|
|
118
|
+
empty = DEFAULT_EMPTY_STATE,
|
|
119
|
+
pagination = DEFAULT_PAGINATION,
|
|
120
|
+
getPopupContainer = defaultGetPopupContainer,
|
|
48
121
|
class: className = '',
|
|
49
122
|
children,
|
|
50
123
|
}: Props = $props();
|
|
@@ -56,6 +129,10 @@
|
|
|
56
129
|
get direction() { return direction; },
|
|
57
130
|
get locale() { return locale; },
|
|
58
131
|
get componentSize() { return componentSize; },
|
|
132
|
+
get componentDefaults() { return componentDefaults; },
|
|
133
|
+
get empty() { return empty; },
|
|
134
|
+
get pagination() { return pagination; },
|
|
135
|
+
get getPopupContainer() { return getPopupContainer; },
|
|
59
136
|
} satisfies Required<ComponentConfig>);
|
|
60
137
|
</script>
|
|
61
138
|
|
|
@@ -72,4 +149,4 @@
|
|
|
72
149
|
|
|
73
150
|
<style>
|
|
74
151
|
.svadmin-config-provider { display: contents; }
|
|
75
|
-
</style>
|
|
152
|
+
</style>
|
|
@@ -1,11 +1,47 @@
|
|
|
1
|
+
export type ComponentPropDefaults = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
2
|
+
export interface EmptyStateDefaults {
|
|
3
|
+
readonly title?: string;
|
|
4
|
+
readonly description?: string;
|
|
5
|
+
readonly image?: string;
|
|
6
|
+
readonly imageAlt?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PaginationDefaults {
|
|
9
|
+
readonly pageSize?: number;
|
|
10
|
+
readonly pageSizeOptions?: readonly number[];
|
|
11
|
+
readonly showSummary?: boolean;
|
|
12
|
+
readonly simple?: boolean;
|
|
13
|
+
readonly showJumper?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 弹出层挂载点。`node` 是触发器或锚点,不是已经挂到 body 上的浮层。
|
|
17
|
+
* 返回元素、选择器,或空值以回退到 document.body。
|
|
18
|
+
*/
|
|
19
|
+
export type GetPopupContainer = (node?: HTMLElement) => HTMLElement | string | null | undefined;
|
|
1
20
|
export interface ComponentConfig {
|
|
2
21
|
theme?: 'light' | 'dark' | 'system';
|
|
3
22
|
density?: 'default' | 'compact';
|
|
4
23
|
direction?: 'ltr' | 'rtl';
|
|
5
24
|
locale?: string;
|
|
6
25
|
componentSize?: 'sm' | 'md' | 'lg';
|
|
26
|
+
/**
|
|
27
|
+
* 按组件名设置的默认参数,例如 `{ Button: { variant: 'outline' } }`。显式 props 优先。
|
|
28
|
+
* 目前只有 Button、Empty(EmptyState)和 Pagination(ListPagination)会读取。
|
|
29
|
+
*/
|
|
30
|
+
componentDefaults?: ComponentPropDefaults;
|
|
31
|
+
/** 空状态默认文案和插图。 */
|
|
32
|
+
empty?: EmptyStateDefaults;
|
|
33
|
+
/** 分页默认参数。 */
|
|
34
|
+
pagination?: PaginationDefaults;
|
|
35
|
+
/** 弹出层与浮层的挂载容器,语义对齐 getPopupContainer。 */
|
|
36
|
+
getPopupContainer?: GetPopupContainer;
|
|
7
37
|
}
|
|
8
38
|
export declare const CONFIG_CONTEXT_KEY: unique symbol;
|
|
39
|
+
export declare const DEFAULT_PAGE_SIZE_OPTIONS: readonly number[];
|
|
40
|
+
export declare const DEFAULT_COMPONENT_DEFAULTS: ComponentPropDefaults;
|
|
41
|
+
export declare const DEFAULT_EMPTY_STATE: EmptyStateDefaults;
|
|
42
|
+
export declare const DEFAULT_PAGINATION: PaginationDefaults;
|
|
43
|
+
export declare function defaultGetPopupContainer(node?: HTMLElement): HTMLElement | undefined;
|
|
44
|
+
export declare function resolvePopupContainer(getPopupContainer: GetPopupContainer | undefined, node?: HTMLElement): HTMLElement | undefined;
|
|
9
45
|
export declare const DEFAULT_COMPONENT_CONFIG: Required<ComponentConfig>;
|
|
10
46
|
/** 当前组件是否位于 ConfigProvider 内。只能在组件初始化时调用。 */
|
|
11
47
|
export declare function hasComponentConfig(): boolean;
|
|
@@ -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">;
|