@svadmin/ui 0.108.3 → 0.108.6
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/FilterBuilder.svelte +10 -7
- 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/enterprise/filter-tree.d.ts +4 -1
- package/dist/components/enterprise/filter-tree.js +28 -10
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { Dialog as DialogPrimitive } from "bits-ui";
|
|
3
|
+
import PopupPortal from "../popup-portal.svelte";
|
|
3
4
|
|
|
4
5
|
let { ...restProps }: DialogPrimitive.PortalProps = $props();
|
|
5
6
|
</script>
|
|
6
7
|
|
|
7
|
-
<
|
|
8
|
+
<PopupPortal {...restProps} kind="dialog" />
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import { cn, type WithElementRef } from "../../../utils.js";
|
|
3
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
4
4
|
import { getContext } from "svelte";
|
|
5
|
+
import { resolvePopupContainer, useComponentConfig } from "../../ConfigProvider.svelte";
|
|
5
6
|
|
|
6
7
|
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
7
8
|
align?: "start" | "center" | "end";
|
|
8
|
-
/** 挂到 document.body,避免表格等 overflow 容器裁切菜单。 */
|
|
9
|
+
/** 挂到 getPopupContainer,默认 document.body,避免表格等 overflow 容器裁切菜单。 */
|
|
9
10
|
portal?: boolean;
|
|
10
11
|
};
|
|
11
12
|
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
...restProps
|
|
19
20
|
}: Props = $props();
|
|
20
21
|
|
|
22
|
+
const config = useComponentConfig();
|
|
21
23
|
const getOpen = getContext<() => boolean>("svadmin-dropdown-open");
|
|
22
24
|
const getRoot = getContext<(() => HTMLElement | null) | undefined>("svadmin-dropdown-root");
|
|
23
25
|
const contentBridge = getContext<{ node: HTMLElement | null } | undefined>("svadmin-dropdown-content");
|
|
@@ -55,7 +57,8 @@
|
|
|
55
57
|
|
|
56
58
|
function positionLayer(node: HTMLElement, enabled: boolean) {
|
|
57
59
|
if (!enabled || typeof document === "undefined") return;
|
|
58
|
-
document.body
|
|
60
|
+
const target = resolvePopupContainer(config.getPopupContainer, node) ?? document.body;
|
|
61
|
+
target.appendChild(node);
|
|
59
62
|
if (contentBridge) contentBridge.node = node;
|
|
60
63
|
const update = () => place(node);
|
|
61
64
|
update();
|
|
@@ -2,7 +2,7 @@ import { type WithElementRef } from "../../../utils.js";
|
|
|
2
2
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
3
|
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
4
4
|
align?: "start" | "center" | "end";
|
|
5
|
-
/** 挂到 document.body,避免表格等 overflow 容器裁切菜单。 */
|
|
5
|
+
/** 挂到 getPopupContainer,默认 document.body,避免表格等 overflow 容器裁切菜单。 */
|
|
6
6
|
portal?: boolean;
|
|
7
7
|
};
|
|
8
8
|
declare const DropdownMenuContent: import("svelte").Component<Props, {}, "ref">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { Popover as PopoverPrimitive } from "bits-ui";
|
|
3
3
|
import { cn } from "../../../utils.js";
|
|
4
|
+
import PopupPortal from "../popup-portal.svelte";
|
|
4
5
|
|
|
5
6
|
let {
|
|
6
7
|
ref = $bindable(null),
|
|
@@ -9,9 +10,12 @@
|
|
|
9
10
|
sideOffset = 4,
|
|
10
11
|
...restProps
|
|
11
12
|
}: PopoverPrimitive.ContentProps & { class?: string } = $props();
|
|
13
|
+
|
|
14
|
+
const customAnchor = $derived(restProps.customAnchor);
|
|
15
|
+
const anchor = $derived(typeof HTMLElement !== 'undefined' && customAnchor instanceof HTMLElement ? customAnchor : null);
|
|
12
16
|
</script>
|
|
13
17
|
|
|
14
|
-
<
|
|
18
|
+
<PopupPortal kind="popover" {anchor}>
|
|
15
19
|
<PopoverPrimitive.Content
|
|
16
20
|
bind:ref
|
|
17
21
|
{align}
|
|
@@ -19,4 +23,4 @@
|
|
|
19
23
|
class={cn("svadmin-popover-content", className)}
|
|
20
24
|
{...restProps}
|
|
21
25
|
/>
|
|
22
|
-
</
|
|
26
|
+
</PopupPortal>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type PopupAnchorKind = 'popover' | 'dialog' | 'alert-dialog' | 'tooltip' | 'sheet';
|
|
2
|
+
/**
|
|
3
|
+
* getPopupContainer 收到的节点:显式锚点优先,否则是同类型触发器,最后才是源码树里的锚点标记。
|
|
4
|
+
* Sheet 没有触发器,使用声明位置上的标记,这样 node?.closest() 仍能看到所在容器。
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolvePopupAnchor(explicit: HTMLElement | null | undefined, marker: HTMLElement | null | undefined, kind?: PopupAnchorKind): HTMLElement | undefined;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const TRIGGER_SELECTOR = {
|
|
2
|
+
popover: '[data-popover-trigger]',
|
|
3
|
+
dialog: '[data-dialog-trigger], [data-slot="dialog-trigger"]',
|
|
4
|
+
'alert-dialog': '[data-alert-dialog-trigger]',
|
|
5
|
+
tooltip: '[data-tooltip-trigger], [data-slot="tooltip-trigger"]',
|
|
6
|
+
};
|
|
7
|
+
function isHtmlElement(value) {
|
|
8
|
+
return typeof HTMLElement !== 'undefined' && value instanceof HTMLElement;
|
|
9
|
+
}
|
|
10
|
+
function isOpenTrigger(element) {
|
|
11
|
+
const state = element.getAttribute('data-state');
|
|
12
|
+
if (state && state !== 'closed')
|
|
13
|
+
return true;
|
|
14
|
+
return element.getAttribute('aria-expanded') === 'true';
|
|
15
|
+
}
|
|
16
|
+
function nextMarkerAfter(trigger, markers, NodeCtor) {
|
|
17
|
+
let candidate;
|
|
18
|
+
for (const marker of markers) {
|
|
19
|
+
const position = trigger.compareDocumentPosition(marker);
|
|
20
|
+
if ((position & NodeCtor.DOCUMENT_POSITION_FOLLOWING) === 0)
|
|
21
|
+
continue;
|
|
22
|
+
if (!candidate || (marker.compareDocumentPosition(candidate) & NodeCtor.DOCUMENT_POSITION_FOLLOWING) !== 0) {
|
|
23
|
+
candidate = marker;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return candidate;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 把打开的触发器配到它后面最近的同类型锚点。
|
|
30
|
+
* 后出现的触发器会覆盖更早的配对,因此紧挨着浮层的那个触发器胜出。
|
|
31
|
+
*/
|
|
32
|
+
function triggerForMarker(marker, kind) {
|
|
33
|
+
if (!kind || kind === 'sheet')
|
|
34
|
+
return undefined;
|
|
35
|
+
const doc = marker.ownerDocument;
|
|
36
|
+
const NodeCtor = doc?.defaultView?.Node;
|
|
37
|
+
const selector = TRIGGER_SELECTOR[kind];
|
|
38
|
+
if (!doc || !NodeCtor || !selector)
|
|
39
|
+
return undefined;
|
|
40
|
+
const markers = [...doc.querySelectorAll(`[data-svadmin-popup-anchor="${kind}"]`)];
|
|
41
|
+
const triggers = [...doc.querySelectorAll(selector)];
|
|
42
|
+
const openOwner = ownersFor(triggers.filter(isOpenTrigger), markers, NodeCtor).get(marker);
|
|
43
|
+
// 受控 open 时触发器的 data-state 可能仍是 closed。没有打开中的触发器时,退回同类型里紧邻的那个。
|
|
44
|
+
return openOwner ?? ownersFor(triggers, markers, NodeCtor).get(marker);
|
|
45
|
+
}
|
|
46
|
+
function ownersFor(triggers, markers, NodeCtor) {
|
|
47
|
+
const owners = new Map();
|
|
48
|
+
for (const trigger of triggers) {
|
|
49
|
+
const owner = nextMarkerAfter(trigger, markers, NodeCtor);
|
|
50
|
+
if (owner)
|
|
51
|
+
owners.set(owner, trigger);
|
|
52
|
+
}
|
|
53
|
+
return owners;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* getPopupContainer 收到的节点:显式锚点优先,否则是同类型触发器,最后才是源码树里的锚点标记。
|
|
57
|
+
* Sheet 没有触发器,使用声明位置上的标记,这样 node?.closest() 仍能看到所在容器。
|
|
58
|
+
*/
|
|
59
|
+
export function resolvePopupAnchor(explicit, marker, kind) {
|
|
60
|
+
if (isHtmlElement(explicit))
|
|
61
|
+
return explicit;
|
|
62
|
+
if (!isHtmlElement(marker))
|
|
63
|
+
return undefined;
|
|
64
|
+
return triggerForMarker(marker, kind) ?? marker;
|
|
65
|
+
}
|
|
@@ -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
|
|
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
|
-
<
|
|
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
|
-
</
|
|
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 {
|
|
5
|
+
let {
|
|
6
|
+
anchor = null,
|
|
7
|
+
...restProps
|
|
8
|
+
}: TooltipPrimitive.PortalProps & { anchor?: HTMLElement | null } = $props();
|
|
5
9
|
</script>
|
|
6
10
|
|
|
7
|
-
<
|
|
11
|
+
<PopupPortal {...restProps} kind="tooltip" {anchor} />
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Tooltip as TooltipPrimitive } from "bits-ui";
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
16
|
-
closeNotification(item.id);
|
|
113
|
+
activeController().closeByKey(key);
|
|
17
114
|
}
|
|
18
115
|
export function clearNotifications() {
|
|
19
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
};
|