@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.
Files changed (43) 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/ConfigProvider.svelte +78 -1
  5. package/dist/components/ConfigProvider.svelte.d.ts +36 -0
  6. package/dist/components/DevTools.svelte +198 -0
  7. package/dist/components/EditableTable.svelte +59 -6
  8. package/dist/components/EditableTable.svelte.d.ts +13 -0
  9. package/dist/components/EmptyState.svelte +19 -6
  10. package/dist/components/ListPagination.svelte +59 -11
  11. package/dist/components/NotificationHost.svelte +5 -4
  12. package/dist/components/RouteAccessGuard.svelte +42 -0
  13. package/dist/components/RouteAccessGuard.svelte.d.ts +11 -0
  14. package/dist/components/component-messages.d.ts +3 -3
  15. package/dist/components/config-provider-defaults.reader.svelte +8 -0
  16. package/dist/components/config-provider-defaults.reader.svelte.d.ts +3 -0
  17. package/dist/components/custom-route-access.d.ts +28 -0
  18. package/dist/components/custom-route-access.js +57 -0
  19. package/dist/components/notification-scope-probe.svelte +9 -0
  20. package/dist/components/notification-scope-probe.svelte.d.ts +6 -0
  21. package/dist/components/popup-portal-host.svelte +41 -0
  22. package/dist/components/popup-portal-host.svelte.d.ts +7 -0
  23. package/dist/components/ui/alert-dialog/alert-dialog-portal.svelte +3 -1
  24. package/dist/components/ui/button/button.svelte +15 -2
  25. package/dist/components/ui/dialog/dialog-portal.svelte +2 -1
  26. package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +5 -2
  27. package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte.d.ts +1 -1
  28. package/dist/components/ui/popover/popover-content.svelte +6 -2
  29. package/dist/components/ui/popup-anchor.d.ts +6 -0
  30. package/dist/components/ui/popup-anchor.js +65 -0
  31. package/dist/components/ui/popup-portal.svelte +42 -0
  32. package/dist/components/ui/popup-portal.svelte.d.ts +11 -0
  33. package/dist/components/ui/sheet/sheet.svelte +3 -3
  34. package/dist/components/ui/tooltip/tooltip-content.svelte +5 -1
  35. package/dist/components/ui/tooltip/tooltip-portal.svelte +6 -2
  36. package/dist/components/ui/tooltip/tooltip-portal.svelte.d.ts +4 -1
  37. package/dist/devtools-inspector.d.ts +37 -0
  38. package/dist/devtools-inspector.js +56 -0
  39. package/dist/index.d.ts +7 -5
  40. package/dist/index.js +3 -2
  41. package/dist/notifications.svelte.d.ts +23 -12
  42. package/dist/notifications.svelte.js +118 -39
  43. package/package.json +4 -4
@@ -0,0 +1,42 @@
1
+ <script lang="ts">
2
+ import { Portal, type PortalProps } from 'bits-ui';
3
+ import { resolvePopupContainer, useComponentConfig } from '../ConfigProvider.svelte';
4
+ import { resolvePopupAnchor, type PopupAnchorKind } from './popup-anchor.js';
5
+
6
+ let {
7
+ to,
8
+ anchor = null,
9
+ kind,
10
+ children,
11
+ ...restProps
12
+ }: PortalProps & {
13
+ /** 调用方已知的触发器或定位锚点。优先传给 getPopupContainer。 */
14
+ anchor?: HTMLElement | null;
15
+ /** 用来把打开的触发器配到这一层浮层,避免串到别的弹层。 */
16
+ kind?: PopupAnchorKind;
17
+ } = $props();
18
+
19
+ const config = useComponentConfig();
20
+ // 留在源码树中的标记。触发器尚未绑定时,用它做 closest() 的回退节点。
21
+ let marker = $state<HTMLElement | null>(null);
22
+ const popupNode = $derived(resolvePopupAnchor(anchor, marker, kind));
23
+ const portalReady = $derived(to !== undefined || popupNode !== undefined || typeof document === 'undefined');
24
+ const target = $derived.by(() => {
25
+ if (to !== undefined) return to;
26
+ if (!portalReady) return undefined;
27
+ return resolvePopupContainer(config.getPopupContainer, popupNode);
28
+ });
29
+ </script>
30
+
31
+ <span bind:this={marker} class="svadmin-popup-anchor" data-svadmin-popup-anchor={kind ?? ''} aria-hidden="true"></span>
32
+ {#if portalReady}
33
+ {#if target}
34
+ <Portal to={target} {...restProps}>{@render children?.()}</Portal>
35
+ {:else}
36
+ <Portal {...restProps}>{@render children?.()}</Portal>
37
+ {/if}
38
+ {/if}
39
+
40
+ <style>
41
+ .svadmin-popup-anchor { display: contents; }
42
+ </style>
@@ -0,0 +1,11 @@
1
+ import { type PortalProps } from 'bits-ui';
2
+ import { type PopupAnchorKind } from './popup-anchor.js';
3
+ type $$ComponentProps = PortalProps & {
4
+ /** 调用方已知的触发器或定位锚点。优先传给 getPopupContainer。 */
5
+ anchor?: HTMLElement | null;
6
+ /** 用来把打开的触发器配到这一层浮层,避免串到别的弹层。 */
7
+ kind?: PopupAnchorKind;
8
+ };
9
+ declare const PopupPortal: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type PopupPortal = ReturnType<typeof PopupPortal>;
11
+ export default PopupPortal;
@@ -33,7 +33,7 @@
33
33
  <script lang="ts">
34
34
  /* eslint-disable svelte/no-unused-svelte-ignore */
35
35
  import { tick } from "svelte";
36
- import { Portal } from "bits-ui";
36
+ import PopupPortal from "../popup-portal.svelte";
37
37
  import { cn, type WithElementRef } from "../../../utils.js";
38
38
  import { useTranslation } from "@svadmin/core/i18n";
39
39
  import type { HTMLAttributes } from "svelte/elements";
@@ -163,7 +163,7 @@
163
163
  <svelte:document onkeydown={handleKeydown} />
164
164
 
165
165
  {#if open}
166
- <Portal>
166
+ <PopupPortal kind="sheet">
167
167
  <!-- Overlay -->
168
168
  <!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
169
169
  <div
@@ -196,5 +196,5 @@
196
196
  <span class="svadmin-sr-only">{closeLabel}</span>
197
197
  </button>
198
198
  </div>
199
- </Portal>
199
+ </PopupPortal>
200
200
  {/if}
@@ -197,6 +197,10 @@
197
197
  );
198
198
  const wrapperProps = $derived({ style: "display: contents" });
199
199
 
200
+ function htmlPopupAnchor(value: unknown): HTMLElement | null {
201
+ return typeof HTMLElement !== 'undefined' && value instanceof HTMLElement ? value : null;
202
+ }
203
+
200
204
  function getAnchor(): ReferenceElement | null {
201
205
  if (typeof customAnchor === "string") return document.querySelector(customAnchor);
202
206
  return customAnchor ?? tooltip.trigger;
@@ -306,7 +310,7 @@
306
310
  </script>
307
311
 
308
312
  {#if tooltip.shouldRender || forceMount}
309
- <TooltipPortal {...portalProps}>
313
+ <TooltipPortal {...portalProps} anchor={htmlPopupAnchor(customAnchor) ?? tooltip.trigger}>
310
314
  {#if child}
311
315
  {@render child({ props: contentProps, wrapperProps, open: tooltip.open })}
312
316
  {:else}
@@ -1,7 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { Tooltip as TooltipPrimitive } from "bits-ui";
3
+ import PopupPortal from "../popup-portal.svelte";
3
4
 
4
- let { ...restProps }: TooltipPrimitive.PortalProps = $props();
5
+ let {
6
+ anchor = null,
7
+ ...restProps
8
+ }: TooltipPrimitive.PortalProps & { anchor?: HTMLElement | null } = $props();
5
9
  </script>
6
10
 
7
- <TooltipPrimitive.Portal {...restProps} />
11
+ <PopupPortal {...restProps} kind="tooltip" {anchor} />
@@ -1,4 +1,7 @@
1
1
  import { Tooltip as TooltipPrimitive } from "bits-ui";
2
- declare const TooltipPortal: import("svelte").Component<TooltipPrimitive.PortalProps, {}, "">;
2
+ type $$ComponentProps = TooltipPrimitive.PortalProps & {
3
+ anchor?: HTMLElement | null;
4
+ };
5
+ declare const TooltipPortal: import("svelte").Component<$$ComponentProps, {}, "">;
3
6
  type TooltipPortal = ReturnType<typeof TooltipPortal>;
4
7
  export default TooltipPortal;
@@ -0,0 +1,37 @@
1
+ export type DevtoolsInspectorKind = 'query' | 'mutation';
2
+ export interface DevtoolsInspectorRow {
3
+ id: string;
4
+ kind: DevtoolsInspectorKind;
5
+ provider: string;
6
+ resource: string;
7
+ operation: string;
8
+ status: string;
9
+ component: string;
10
+ trigger: string;
11
+ source: string;
12
+ requestSummary: string;
13
+ responseSummary: string;
14
+ }
15
+ export interface DevtoolsTimelineEntry {
16
+ at: number;
17
+ kind: DevtoolsInspectorKind;
18
+ resource: string;
19
+ operation: string;
20
+ status: string;
21
+ trigger: string;
22
+ source: string;
23
+ }
24
+ export interface DevtoolsInspectorFilter {
25
+ text: string;
26
+ kind: 'all' | DevtoolsInspectorKind;
27
+ resource: string;
28
+ status: string;
29
+ component: string;
30
+ }
31
+ /** Shape-only summary. String and number values are never copied into the result. */
32
+ export declare function redactValueSummary(value: unknown, depth?: number): string;
33
+ export declare function filterInspectorRows(rows: readonly DevtoolsInspectorRow[], filter: DevtoolsInspectorFilter): DevtoolsInspectorRow[];
34
+ export declare function componentSource(meta: unknown, observerCount: number): {
35
+ component: string;
36
+ source: string;
37
+ };
@@ -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, hasComponentConfig } 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, hasComponentConfig } 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.3",
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",