@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.
Files changed (47) hide show
  1. package/dist/components/AboutSettings.svelte +1 -1
  2. package/dist/components/AdminApp.svelte +20 -1
  3. package/dist/components/AdminApp.svelte.d.ts +6 -0
  4. package/dist/components/Calendar.svelte +28 -8
  5. package/dist/components/ConfigProvider.svelte +101 -10
  6. package/dist/components/ConfigProvider.svelte.d.ts +39 -0
  7. package/dist/components/DatePicker.svelte +32 -9
  8. package/dist/components/DatePicker.svelte.d.ts +3 -0
  9. package/dist/components/DevTools.svelte +198 -0
  10. package/dist/components/EditableTable.svelte +59 -6
  11. package/dist/components/EditableTable.svelte.d.ts +13 -0
  12. package/dist/components/EmptyState.svelte +19 -6
  13. package/dist/components/ListPagination.svelte +59 -11
  14. package/dist/components/NotificationHost.svelte +5 -4
  15. package/dist/components/RouteAccessGuard.svelte +42 -0
  16. package/dist/components/RouteAccessGuard.svelte.d.ts +11 -0
  17. package/dist/components/component-messages.d.ts +59 -0
  18. package/dist/components/component-messages.js +47 -0
  19. package/dist/components/config-provider-defaults.reader.svelte +8 -0
  20. package/dist/components/config-provider-defaults.reader.svelte.d.ts +3 -0
  21. package/dist/components/custom-route-access.d.ts +28 -0
  22. package/dist/components/custom-route-access.js +57 -0
  23. package/dist/components/notification-scope-probe.svelte +9 -0
  24. package/dist/components/notification-scope-probe.svelte.d.ts +6 -0
  25. package/dist/components/popup-portal-host.svelte +41 -0
  26. package/dist/components/popup-portal-host.svelte.d.ts +7 -0
  27. package/dist/components/ui/alert-dialog/alert-dialog-portal.svelte +3 -1
  28. package/dist/components/ui/button/button.svelte +15 -2
  29. package/dist/components/ui/dialog/dialog-portal.svelte +2 -1
  30. package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +5 -2
  31. package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte.d.ts +1 -1
  32. package/dist/components/ui/popover/popover-content.svelte +6 -2
  33. package/dist/components/ui/popup-anchor.d.ts +6 -0
  34. package/dist/components/ui/popup-anchor.js +65 -0
  35. package/dist/components/ui/popup-portal.svelte +42 -0
  36. package/dist/components/ui/popup-portal.svelte.d.ts +11 -0
  37. package/dist/components/ui/sheet/sheet.svelte +3 -3
  38. package/dist/components/ui/tooltip/tooltip-content.svelte +5 -1
  39. package/dist/components/ui/tooltip/tooltip-portal.svelte +6 -2
  40. package/dist/components/ui/tooltip/tooltip-portal.svelte.d.ts +4 -1
  41. package/dist/devtools-inspector.d.ts +37 -0
  42. package/dist/devtools-inspector.js +56 -0
  43. package/dist/index.d.ts +7 -5
  44. package/dist/index.js +3 -2
  45. package/dist/notifications.svelte.d.ts +23 -12
  46. package/dist/notifications.svelte.js +118 -39
  47. package/package.json +4 -4
@@ -0,0 +1,56 @@
1
+ const SECRET_KEY = /token|secret|password|authorization|cookie|session|api[-_]?key/i;
2
+ /** Shape-only summary. String and number values are never copied into the result. */
3
+ export function redactValueSummary(value, depth = 0) {
4
+ if (value === null)
5
+ return 'null';
6
+ if (value === undefined)
7
+ return 'undefined';
8
+ if (typeof value === 'string')
9
+ return 'string';
10
+ if (typeof value === 'number')
11
+ return 'number';
12
+ if (typeof value === 'boolean')
13
+ return 'boolean';
14
+ if (Array.isArray(value)) {
15
+ if (value.length === 0 || depth >= 2)
16
+ return `array(${value.length})`;
17
+ return `array(${value.length}: ${redactValueSummary(value[0], depth + 1)})`;
18
+ }
19
+ if (typeof value === 'object') {
20
+ const keys = Object.keys(value)
21
+ .slice(0, 8)
22
+ .map((key) => (SECRET_KEY.test(key) ? `${key}:[redacted]` : key));
23
+ if (depth >= 2)
24
+ return `object{${keys.join(', ')}}`;
25
+ return `object{${keys.join(', ')}}`;
26
+ }
27
+ return 'unknown';
28
+ }
29
+ export function filterInspectorRows(rows, filter) {
30
+ const text = filter.text.trim().toLowerCase();
31
+ const component = filter.component.trim().toLowerCase();
32
+ return rows.filter((row) => {
33
+ if (filter.kind !== 'all' && row.kind !== filter.kind)
34
+ return false;
35
+ if (filter.resource !== 'all' && row.resource !== filter.resource)
36
+ return false;
37
+ if (filter.status !== 'all' && row.status !== filter.status)
38
+ return false;
39
+ if (component.length > 0 && !row.component.toLowerCase().includes(component))
40
+ return false;
41
+ if (text.length === 0)
42
+ return true;
43
+ const haystack = `${row.kind} ${row.provider} ${row.resource} ${row.operation} ${row.status} ${row.component} ${row.source} ${row.trigger}`.toLowerCase();
44
+ return haystack.includes(text);
45
+ });
46
+ }
47
+ export function componentSource(meta, observerCount) {
48
+ const record = typeof meta === 'object' && meta !== null ? meta : {};
49
+ const named = [record['component'], record['source'], record['devtoolsComponent']]
50
+ .find((value) => typeof value === 'string' && value.length > 0 && value.length < 80);
51
+ if (typeof named === 'string')
52
+ return { component: named, source: named };
53
+ if (observerCount > 0)
54
+ return { component: 'observer', source: `observer:${observerCount}` };
55
+ return { component: 'cache', source: 'cache' };
56
+ }
package/dist/index.d.ts CHANGED
@@ -41,8 +41,8 @@ export { default as SvadminLogo } from './components/SvadminLogo.svelte';
41
41
  export { default as ErrorBoundary } from './components/ErrorBoundary.svelte';
42
42
  export { default as Toast } from './components/Toast.svelte';
43
43
  export { default as NotificationHost } from './components/NotificationHost.svelte';
44
- export { notification, notification as Notification, getNotifications, closeNotification, closeNotificationByKey, clearNotifications } from './notifications.svelte.js';
45
- export type { NotificationOptions, NotificationRecord, NotificationTone } from './notifications.svelte.js';
44
+ export { notification, notification as Notification, getNotifications, closeNotification, closeNotificationByKey, clearNotifications, createNotificationController, provideNotificationController, useNotificationController } from './notifications.svelte.js';
45
+ export type { NotificationOptions, NotificationRecord, NotificationTone, NotificationController } from './notifications.svelte.js';
46
46
  export { default as Breadcrumbs } from './components/Breadcrumbs.svelte';
47
47
  export { default as FieldRenderer } from './components/FieldRenderer.svelte';
48
48
  export { default as EmptyState } from './components/EmptyState.svelte';
@@ -56,6 +56,7 @@ export { default as AppShellPage } from './components/AppShellPage.svelte';
56
56
  export { default as ResourceOperationsPage } from './components/ResourceOperationsPage.svelte';
57
57
  export { default as RecordDetailDrawer } from './components/RecordDetailDrawer.svelte';
58
58
  export { default as ResourceAccessGuard } from './components/ResourceAccessGuard.svelte';
59
+ export { default as RouteAccessGuard } from './components/RouteAccessGuard.svelte';
59
60
  export { default as LoginPage } from './components/LoginPage.svelte';
60
61
  export { default as AuthPageShell } from './components/AuthPageShell.svelte';
61
62
  export { default as RegisterPage } from './components/RegisterPage.svelte';
@@ -134,7 +135,7 @@ export type { DetailWorkspaceSectionsConfig, DetailWorkspaceSection, DetailWorks
134
135
  export { default as VirtualTable } from './components/VirtualTable.svelte';
135
136
  export type { VirtualTableColumn } from './components/VirtualTable.svelte';
136
137
  export { default as EditableTable } from './components/EditableTable.svelte';
137
- export type { EditableTableColumn } from './components/EditableTable.svelte';
138
+ export type { EditableTableColumn, EditableTableEditor } from './components/EditableTable.svelte';
138
139
  export { default as DraggableRowTable } from './components/DraggableRowTable.svelte';
139
140
  export type { DraggableTableColumn } from './components/DraggableRowTable.svelte';
140
141
  export { default as SplitPaneLayout, default as Split } from './components/SplitPaneLayout.svelte';
@@ -317,8 +318,9 @@ export { default as Tour } from './components/Tour.svelte';
317
318
  export type { TourStep } from './components/Tour.svelte';
318
319
  export { default as Menu } from './components/Menu.svelte';
319
320
  export type { MenuEntry } from './components/Menu.svelte';
320
- export { default as ConfigProvider, useComponentConfig } from './components/ConfigProvider.svelte';
321
- export type { ComponentConfig } from './components/ConfigProvider.svelte';
321
+ export { default as ConfigProvider, useComponentConfig, hasComponentConfig, resolvePopupContainer } from './components/ConfigProvider.svelte';
322
+ export type { ComponentConfig, ComponentPropDefaults, EmptyStateDefaults, PaginationDefaults, GetPopupContainer } from './components/ConfigProvider.svelte';
323
+ export type { CustomRouteAccessConfig } from './components/custom-route-access.js';
322
324
  export { toast, toast as message, toast as Message } from '@svadmin/core';
323
325
  export { cn } from './utils';
324
326
  export { setComponentRegistry, getComponentRegistry, useComponent, type ComponentRegistry, } from './component-registry.svelte';
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ export { default as SvadminLogo } from './components/SvadminLogo.svelte';
33
33
  export { default as ErrorBoundary } from './components/ErrorBoundary.svelte';
34
34
  export { default as Toast } from './components/Toast.svelte';
35
35
  export { default as NotificationHost } from './components/NotificationHost.svelte';
36
- export { notification, notification as Notification, getNotifications, closeNotification, closeNotificationByKey, clearNotifications } from './notifications.svelte.js';
36
+ export { notification, notification as Notification, getNotifications, closeNotification, closeNotificationByKey, clearNotifications, createNotificationController, provideNotificationController, useNotificationController } from './notifications.svelte.js';
37
37
  export { default as Breadcrumbs } from './components/Breadcrumbs.svelte';
38
38
  export { default as FieldRenderer } from './components/FieldRenderer.svelte';
39
39
  export { default as EmptyState } from './components/EmptyState.svelte';
@@ -45,6 +45,7 @@ export { default as AppShellPage } from './components/AppShellPage.svelte';
45
45
  export { default as ResourceOperationsPage } from './components/ResourceOperationsPage.svelte';
46
46
  export { default as RecordDetailDrawer } from './components/RecordDetailDrawer.svelte';
47
47
  export { default as ResourceAccessGuard } from './components/ResourceAccessGuard.svelte';
48
+ export { default as RouteAccessGuard } from './components/RouteAccessGuard.svelte';
48
49
  export { default as LoginPage } from './components/LoginPage.svelte';
49
50
  export { default as AuthPageShell } from './components/AuthPageShell.svelte';
50
51
  export { default as RegisterPage } from './components/RegisterPage.svelte';
@@ -259,7 +260,7 @@ export { default as Countdown } from './components/Countdown.svelte';
259
260
  export { default as ResizeBox } from './components/ResizeBox.svelte';
260
261
  export { default as Tour } from './components/Tour.svelte';
261
262
  export { default as Menu } from './components/Menu.svelte';
262
- export { default as ConfigProvider, useComponentConfig } from './components/ConfigProvider.svelte';
263
+ export { default as ConfigProvider, useComponentConfig, hasComponentConfig, resolvePopupContainer } from './components/ConfigProvider.svelte';
263
264
  export { toast, toast as message, toast as Message } from '@svadmin/core';
264
265
  // Utils
265
266
  export { cn } from './utils';
@@ -16,19 +16,30 @@ export interface NotificationRecord extends NotificationOptions {
16
16
  placement: NotificationPlacement;
17
17
  duration: number;
18
18
  }
19
+ export interface NotificationController {
20
+ readonly items: NotificationRecord[];
21
+ open(options: NotificationOptions): number;
22
+ close(id: number): void;
23
+ closeByKey(key: string): void;
24
+ clear(): void;
25
+ info(title: string, description?: string, options?: Omit<NotificationOptions, 'title' | 'description' | 'tone'>): number;
26
+ success(title: string, description?: string, options?: Omit<NotificationOptions, 'title' | 'description' | 'tone'>): number;
27
+ warning(title: string, description?: string, options?: Omit<NotificationOptions, 'title' | 'description' | 'tone'>): number;
28
+ danger(title: string, description?: string, options?: Omit<NotificationOptions, 'title' | 'description' | 'tone'>): number;
29
+ }
30
+ export declare function createNotificationController(): NotificationController;
31
+ /**
32
+ * 在 AdminApp(或自定义宿主)初始化时调用,使通知队列只属于当前组件树。
33
+ */
34
+ export declare function provideNotificationController(controller?: NotificationController): NotificationController;
35
+ /** 把 DOM 根和当前树的通知队列关联起来,供命令式 `notification` 在点击时定位宿主。 */
36
+ export declare function bindNotificationRoot(node: HTMLElement, controller: NotificationController): {
37
+ destroy(): void;
38
+ };
39
+ /** 组件初始化时捕获当前树的通知队列。异步回调仍写回这个队列。 */
40
+ export declare function useNotificationController(): NotificationController;
19
41
  export declare function getNotifications(): NotificationRecord[];
20
42
  export declare function closeNotification(id: number): void;
21
43
  export declare function closeNotificationByKey(key: string): void;
22
44
  export declare function clearNotifications(): void;
23
- declare function open(options: NotificationOptions): number;
24
- export declare const notification: {
25
- open: typeof open;
26
- close: typeof closeNotification;
27
- closeByKey: typeof closeNotificationByKey;
28
- clear: typeof clearNotifications;
29
- info: (title: string, description?: string, options?: Omit<NotificationOptions, "title" | "description" | "tone">) => number;
30
- success: (title: string, description?: string, options?: Omit<NotificationOptions, "title" | "description" | "tone">) => number;
31
- warning: (title: string, description?: string, options?: Omit<NotificationOptions, "title" | "description" | "tone">) => number;
32
- danger: (title: string, description?: string, options?: Omit<NotificationOptions, "title" | "description" | "tone">) => number;
33
- };
34
- export {};
45
+ export declare const notification: NotificationController;
@@ -1,49 +1,128 @@
1
- let nextId = 0;
2
- let items = $state([]);
3
- const timers = new Map();
1
+ import { getContext, onDestroy, setContext } from 'svelte';
2
+ export function createNotificationController() {
3
+ let nextId = 0;
4
+ let items = $state([]);
5
+ const timers = new Map();
6
+ function close(id) {
7
+ const timer = timers.get(id);
8
+ if (timer)
9
+ clearTimeout(timer);
10
+ timers.delete(id);
11
+ items = items.filter((item) => item.id !== id);
12
+ }
13
+ function closeByKey(key) {
14
+ for (const item of items.filter((entry) => entry.key === key))
15
+ close(item.id);
16
+ }
17
+ function clear() {
18
+ for (const timer of timers.values())
19
+ clearTimeout(timer);
20
+ timers.clear();
21
+ items = [];
22
+ }
23
+ function open(options) {
24
+ if (options.key)
25
+ closeByKey(options.key);
26
+ const item = {
27
+ ...options,
28
+ id: nextId++,
29
+ tone: options.tone ?? 'info',
30
+ placement: options.placement ?? 'top-right',
31
+ duration: options.duration ?? 5000,
32
+ };
33
+ items = [...items, item];
34
+ if (item.duration > 0) {
35
+ timers.set(item.id, setTimeout(() => close(item.id), item.duration));
36
+ }
37
+ return item.id;
38
+ }
39
+ function withTone(tone) {
40
+ return (title, description, options) => open({ ...options, title, ...(description ? { description } : {}), tone });
41
+ }
42
+ return {
43
+ get items() { return items; },
44
+ open,
45
+ close,
46
+ closeByKey,
47
+ clear,
48
+ info: withTone('info'),
49
+ success: withTone('success'),
50
+ warning: withTone('warning'),
51
+ danger: withTone('danger'),
52
+ };
53
+ }
54
+ const sharedController = createNotificationController();
55
+ const mountedControllers = new Set();
56
+ const notificationRoots = new WeakMap();
57
+ const NOTIFICATION_CONTEXT = Symbol('svadmin-notification-controller');
58
+ function onlyMountedController() {
59
+ if (mountedControllers.size !== 1)
60
+ return undefined;
61
+ for (const controller of mountedControllers)
62
+ return controller;
63
+ return undefined;
64
+ }
65
+ function controllerFromFocus() {
66
+ if (typeof document === 'undefined')
67
+ return undefined;
68
+ let current = document.activeElement;
69
+ while (current) {
70
+ const found = notificationRoots.get(current);
71
+ if (found)
72
+ return found;
73
+ current = current.parentNode;
74
+ }
75
+ return undefined;
76
+ }
77
+ /** 聚焦所在的 AdminApp 优先;只有一个已挂载应用时走该应用;否则使用未归属队列。 */
78
+ function activeController() {
79
+ return controllerFromFocus() ?? onlyMountedController() ?? sharedController;
80
+ }
81
+ /**
82
+ * 在 AdminApp(或自定义宿主)初始化时调用,使通知队列只属于当前组件树。
83
+ */
84
+ export function provideNotificationController(controller = createNotificationController()) {
85
+ setContext(NOTIFICATION_CONTEXT, controller);
86
+ mountedControllers.add(controller);
87
+ onDestroy(() => {
88
+ mountedControllers.delete(controller);
89
+ controller.clear();
90
+ });
91
+ return controller;
92
+ }
93
+ /** 把 DOM 根和当前树的通知队列关联起来,供命令式 `notification` 在点击时定位宿主。 */
94
+ export function bindNotificationRoot(node, controller) {
95
+ notificationRoots.set(node, controller);
96
+ return {
97
+ destroy() {
98
+ notificationRoots.delete(node);
99
+ },
100
+ };
101
+ }
102
+ /** 组件初始化时捕获当前树的通知队列。异步回调仍写回这个队列。 */
103
+ export function useNotificationController() {
104
+ return getContext(NOTIFICATION_CONTEXT) ?? activeController();
105
+ }
4
106
  export function getNotifications() {
5
- return items;
107
+ return activeController().items;
6
108
  }
7
109
  export function closeNotification(id) {
8
- const timer = timers.get(id);
9
- if (timer)
10
- clearTimeout(timer);
11
- timers.delete(id);
12
- items = items.filter((item) => item.id !== id);
110
+ activeController().close(id);
13
111
  }
14
112
  export function closeNotificationByKey(key) {
15
- for (const item of items.filter((entry) => entry.key === key))
16
- closeNotification(item.id);
113
+ activeController().closeByKey(key);
17
114
  }
18
115
  export function clearNotifications() {
19
- for (const timer of timers.values())
20
- clearTimeout(timer);
21
- timers.clear();
22
- items = [];
23
- }
24
- function open(options) {
25
- if (options.key)
26
- closeNotificationByKey(options.key);
27
- const item = {
28
- ...options,
29
- id: nextId++,
30
- tone: options.tone ?? 'info',
31
- placement: options.placement ?? 'top-right',
32
- duration: options.duration ?? 5000,
33
- };
34
- items = [...items, item];
35
- if (item.duration > 0) {
36
- timers.set(item.id, setTimeout(() => closeNotification(item.id), item.duration));
37
- }
38
- return item.id;
116
+ activeController().clear();
39
117
  }
40
118
  export const notification = {
41
- open,
42
- close: closeNotification,
43
- closeByKey: closeNotificationByKey,
44
- clear: clearNotifications,
45
- info: (title, description, options) => open({ ...options, title, ...(description ? { description } : {}), tone: 'info' }),
46
- success: (title, description, options) => open({ ...options, title, ...(description ? { description } : {}), tone: 'success' }),
47
- warning: (title, description, options) => open({ ...options, title, ...(description ? { description } : {}), tone: 'warning' }),
48
- danger: (title, description, options) => open({ ...options, title, ...(description ? { description } : {}), tone: 'danger' }),
119
+ get items() { return activeController().items; },
120
+ open: (options) => activeController().open(options),
121
+ close: (id) => activeController().close(id),
122
+ closeByKey: (key) => activeController().closeByKey(key),
123
+ clear: () => activeController().clear(),
124
+ info: (title, description, options) => activeController().info(title, description, options),
125
+ success: (title, description, options) => activeController().success(title, description, options),
126
+ warning: (title, description, options) => activeController().warning(title, description, options),
127
+ danger: (title, description, options) => activeController().danger(title, description, options),
49
128
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/ui",
3
- "version": "0.108.2",
3
+ "version": "0.108.4",
4
4
  "description": "Pre-built admin UI components — AdminApp, AutoTable, AutoForm, Sidebar, Layout",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -88,7 +88,7 @@
88
88
  "@codemirror/lang-json": "^6.0.0",
89
89
  "@codemirror/lang-markdown": "^6.0.0",
90
90
  "@codemirror/lang-sql": "^6.0.0",
91
- "@svadmin/core": "^0.69.2",
91
+ "@svadmin/core": "^0.69.3",
92
92
  "@tanstack/svelte-query": "^6.1.48",
93
93
  "codemirror": "^6.0.0",
94
94
  "dashjs": "^4.7.4",
@@ -151,7 +151,7 @@
151
151
  }
152
152
  },
153
153
  "dependencies": {
154
- "@svadmin/devtools": "^0.4.2",
154
+ "@svadmin/devtools": "^0.4.3",
155
155
  "@svadmin/devtools-contract": "^0.3.1",
156
156
  "@vibeunion/devtools-devframe": "^0.1.0",
157
157
  "typebox": "^1.3.34",
@@ -189,7 +189,7 @@
189
189
  "@codemirror/lang-markdown": "^6.5.2",
190
190
  "@codemirror/lang-sql": "^6.10.0",
191
191
  "@happy-dom/global-registrator": "^20.11.12",
192
- "@svadmin/ai-elements": "^0.13.4",
192
+ "@svadmin/ai-elements": "^0.13.5",
193
193
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
194
194
  "@tailwindcss/cli": "4.3.3",
195
195
  "@testing-library/dom": "^10.4.1",