@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
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import { PackageOpen } from '@lucide/svelte';
|
|
4
4
|
import { useTranslation } from '@svadmin/core';
|
|
5
|
+
import { useComponentConfig } from './ConfigProvider.svelte';
|
|
5
6
|
|
|
6
7
|
const i18n = useTranslation();
|
|
8
|
+
const config = useComponentConfig();
|
|
7
9
|
|
|
8
10
|
let {
|
|
9
|
-
title
|
|
10
|
-
description
|
|
11
|
+
title,
|
|
12
|
+
description,
|
|
11
13
|
image,
|
|
12
14
|
imageAlt,
|
|
13
15
|
icon,
|
|
@@ -22,6 +24,17 @@
|
|
|
22
24
|
icon?: Snippet;
|
|
23
25
|
children?: Snippet;
|
|
24
26
|
}>();
|
|
27
|
+
|
|
28
|
+
function textDefault(value: unknown): string | undefined {
|
|
29
|
+
return typeof value === 'string' ? value : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const emptyDefaults = $derived(config.empty);
|
|
33
|
+
const componentEmpty = $derived(config.componentDefaults['Empty'] ?? {});
|
|
34
|
+
const resolvedTitle = $derived(title ?? emptyDefaults.title ?? textDefault(componentEmpty['title']) ?? i18n.t('empty.title'));
|
|
35
|
+
const resolvedDescription = $derived(description ?? emptyDefaults.description ?? textDefault(componentEmpty['description']) ?? i18n.t('empty.description'));
|
|
36
|
+
const resolvedImage = $derived(image ?? emptyDefaults.image ?? textDefault(componentEmpty['image']));
|
|
37
|
+
const resolvedImageAlt = $derived(imageAlt ?? emptyDefaults.imageAlt ?? textDefault(componentEmpty['imageAlt']) ?? '');
|
|
25
38
|
</script>
|
|
26
39
|
|
|
27
40
|
<div
|
|
@@ -30,8 +43,8 @@
|
|
|
30
43
|
aria-live="polite"
|
|
31
44
|
>
|
|
32
45
|
<span class="empty-state__icon" aria-hidden="true">
|
|
33
|
-
{#if
|
|
34
|
-
<img class="empty-state__image" src={
|
|
46
|
+
{#if resolvedImage}
|
|
47
|
+
<img class="empty-state__image" src={resolvedImage} alt={resolvedImageAlt} loading="lazy" decoding="async" />
|
|
35
48
|
{:else if icon}
|
|
36
49
|
{@render icon()}
|
|
37
50
|
{:else}
|
|
@@ -39,8 +52,8 @@
|
|
|
39
52
|
{/if}
|
|
40
53
|
</span>
|
|
41
54
|
<div class="empty-state__body">
|
|
42
|
-
<h3>{
|
|
43
|
-
{#if
|
|
55
|
+
<h3>{resolvedTitle}</h3>
|
|
56
|
+
{#if resolvedDescription}<p>{resolvedDescription}</p>{/if}
|
|
44
57
|
{#if children}
|
|
45
58
|
<div class="empty-state__action">
|
|
46
59
|
{@render children()}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import type { CrudOperator, FieldDefinition, Filter } from '@svadmin/core';
|
|
10
10
|
import { isNumericFilterField as isNumericField } from '@svadmin/core';
|
|
11
11
|
import FilterCollectionInput from './FilterCollectionInput.svelte';
|
|
12
|
-
import { readFilterTree, compileFilterTree, filterOperators, parseFilterInput, isCollectionOperator, isNullOperator,
|
|
12
|
+
import { readFilterTree, compileFilterTree, filterOperators, parseFilterInput, isCollectionOperator, isListOperator, isRangeOperator, isNullOperator,
|
|
13
13
|
FILTER_EDITOR_LIMITS, type FilterGroupNode, type FilterNode, type FilterRuleNode, type FilterEditorIssue, type FilterIssueCode } from './enterprise/filter-tree.js';
|
|
14
14
|
|
|
15
15
|
export interface FilterRuleItem {
|
|
@@ -74,8 +74,11 @@
|
|
|
74
74
|
const full = $derived(nodeCount >= FILTER_EDITOR_LIMITS.nodes);
|
|
75
75
|
|
|
76
76
|
function snapshotNode(node: FilterNode): Filter {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
if (node.kind === 'group') {
|
|
78
|
+
const value = node.children.map(snapshotNode);
|
|
79
|
+
return node.key ? { key: node.key, operator: node.operator, value } : { operator: node.operator, value };
|
|
80
|
+
}
|
|
81
|
+
return { field: node.field, operator: node.operator, value: Array.isArray(node.value) ? [...node.value] : node.value };
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
function unsupportedLogic(node: FilterNode, top = false): FilterIssueCode | undefined {
|
|
@@ -212,10 +215,10 @@
|
|
|
212
215
|
const previous = rule.operator;
|
|
213
216
|
rule.operator = operator;
|
|
214
217
|
if (isNullOperator(operator)) rule.value = null;
|
|
215
|
-
else if (operator
|
|
216
|
-
if (previous
|
|
217
|
-
} else if (
|
|
218
|
-
if (previous
|
|
218
|
+
else if (isRangeOperator(operator)) {
|
|
219
|
+
if (!isRangeOperator(previous)) rule.value = [null, null];
|
|
220
|
+
} else if (isListOperator(operator)) {
|
|
221
|
+
if (!isListOperator(previous)) rule.value = [null];
|
|
219
222
|
} else if (isCollectionOperator(previous) || isNullOperator(previous)) rule.value = undefined;
|
|
220
223
|
}
|
|
221
224
|
</script>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { useTranslation } from '@svadmin/core/i18n';
|
|
4
|
+
import { useComponentConfig, DEFAULT_PAGE_SIZE_OPTIONS } from './ConfigProvider.svelte';
|
|
4
5
|
import { listText } from './list-i18n.js';
|
|
5
6
|
import { listPaginationItems } from './list-pagination.js';
|
|
6
7
|
|
|
@@ -30,11 +31,11 @@
|
|
|
30
31
|
rangeStart = 0,
|
|
31
32
|
rangeEnd = 0,
|
|
32
33
|
pageSize,
|
|
33
|
-
pageSizeOptions
|
|
34
|
+
pageSizeOptions,
|
|
34
35
|
pageSizeLabel,
|
|
35
|
-
showSummary
|
|
36
|
-
simple
|
|
37
|
-
showJumper
|
|
36
|
+
showSummary,
|
|
37
|
+
simple,
|
|
38
|
+
showJumper,
|
|
38
39
|
onPageChange,
|
|
39
40
|
onPageSizeChange,
|
|
40
41
|
class: className = '',
|
|
@@ -42,6 +43,53 @@
|
|
|
42
43
|
}: Props = $props();
|
|
43
44
|
|
|
44
45
|
const i18n = useTranslation();
|
|
46
|
+
const config = useComponentConfig();
|
|
47
|
+
|
|
48
|
+
function booleanDefault(value: unknown): boolean | undefined {
|
|
49
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function numberList(value: unknown): readonly number[] | undefined {
|
|
53
|
+
if (!Array.isArray(value) || value.length === 0) return undefined;
|
|
54
|
+
if (value.some((item) => typeof item !== 'number' || !Number.isFinite(item))) return undefined;
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function numberDefault(value: unknown): number | undefined {
|
|
59
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const paginationDefaults = $derived(config.pagination);
|
|
63
|
+
const paginationComponentDefaults = $derived(config.componentDefaults['Pagination'] ?? {});
|
|
64
|
+
const resolvedPageSizeOptions = $derived(
|
|
65
|
+
pageSizeOptions
|
|
66
|
+
?? paginationDefaults.pageSizeOptions
|
|
67
|
+
?? numberList(paginationComponentDefaults['pageSizeOptions'])
|
|
68
|
+
?? DEFAULT_PAGE_SIZE_OPTIONS,
|
|
69
|
+
);
|
|
70
|
+
const resolvedShowSummary = $derived(
|
|
71
|
+
showSummary
|
|
72
|
+
?? paginationDefaults.showSummary
|
|
73
|
+
?? booleanDefault(paginationComponentDefaults['showSummary'])
|
|
74
|
+
?? true,
|
|
75
|
+
);
|
|
76
|
+
const resolvedSimple = $derived(
|
|
77
|
+
simple
|
|
78
|
+
?? paginationDefaults.simple
|
|
79
|
+
?? booleanDefault(paginationComponentDefaults['simple'])
|
|
80
|
+
?? false,
|
|
81
|
+
);
|
|
82
|
+
const resolvedShowJumper = $derived(
|
|
83
|
+
showJumper
|
|
84
|
+
?? paginationDefaults.showJumper
|
|
85
|
+
?? booleanDefault(paginationComponentDefaults['showJumper'])
|
|
86
|
+
?? false,
|
|
87
|
+
);
|
|
88
|
+
const resolvedPageSize = $derived(
|
|
89
|
+
pageSize
|
|
90
|
+
?? paginationDefaults.pageSize
|
|
91
|
+
?? numberDefault(paginationComponentDefaults['pageSize']),
|
|
92
|
+
);
|
|
45
93
|
|
|
46
94
|
const items = $derived(listPaginationItems(page, totalPages));
|
|
47
95
|
const paginated = $derived(totalPages > 1);
|
|
@@ -58,17 +106,17 @@
|
|
|
58
106
|
|
|
59
107
|
{#if paginated}
|
|
60
108
|
<div {...restProps} class={`svadmin-list-pagination ${className}`.trim()} role="navigation" aria-label={listText(i18n, 'listPagination.navigation', { label })}>
|
|
61
|
-
{#if
|
|
109
|
+
{#if resolvedShowSummary}
|
|
62
110
|
<div class="svadmin-list-pagination__info">
|
|
63
111
|
<span>{listText(i18n, 'listPagination.range', { start: rangeStart, end: rangeEnd, total })}</span>
|
|
64
|
-
{#if onPageSizeChange &&
|
|
112
|
+
{#if onPageSizeChange && resolvedPageSize !== undefined}
|
|
65
113
|
<span class="svadmin-list-pagination__size">{pageSizeLabel ?? listText(i18n, 'listPagination.pageSizeLabel')}
|
|
66
114
|
<select
|
|
67
115
|
aria-label={listText(i18n, 'listPagination.pageSizeAria', { label })}
|
|
68
|
-
value={
|
|
116
|
+
value={resolvedPageSize}
|
|
69
117
|
onchange={(event) => onPageSizeChange?.(Number((event.currentTarget as HTMLSelectElement).value))}
|
|
70
118
|
>
|
|
71
|
-
{#each
|
|
119
|
+
{#each resolvedPageSizeOptions as size (size)}<option value={size}>{listText(i18n, 'listPagination.pageSizeOption', { size })}</option>{/each}
|
|
72
120
|
</select>
|
|
73
121
|
</span>
|
|
74
122
|
{/if}
|
|
@@ -78,7 +126,7 @@
|
|
|
78
126
|
<button type="button" class="svadmin-list-pagination__control" disabled={page <= 1}
|
|
79
127
|
title={listText(i18n, page <= 1 ? 'listPagination.firstPage' : 'listPagination.previous')}
|
|
80
128
|
aria-label={listText(i18n, 'listPagination.previousAria', { label })} onclick={() => onPageChange(page - 1)}>{listText(i18n, 'listPagination.previous')}</button>
|
|
81
|
-
{#if
|
|
129
|
+
{#if resolvedSimple}
|
|
82
130
|
<span class="svadmin-list-pagination__simple">{listText(i18n, 'listPagination.simplePage', { page, total: totalPages })}</span>
|
|
83
131
|
{:else}
|
|
84
132
|
<div class="svadmin-list-pagination__pages" role="group" aria-label={listText(i18n, 'listPagination.pageList', { label })}>
|
|
@@ -95,7 +143,7 @@
|
|
|
95
143
|
{/if}
|
|
96
144
|
{/each}
|
|
97
145
|
</div>
|
|
98
|
-
{#if
|
|
146
|
+
{#if resolvedShowJumper}
|
|
99
147
|
<label class="svadmin-list-pagination__jumper">
|
|
100
148
|
<span>{listText(i18n, 'listPagination.jumpTo')}</span>
|
|
101
149
|
<input type="number" min="1" max={totalPages} value={page}
|
|
@@ -109,7 +157,7 @@
|
|
|
109
157
|
aria-label={listText(i18n, 'listPagination.nextAria', { label })} onclick={() => onPageChange(page + 1)}>{listText(i18n, 'listPagination.next')}</button>
|
|
110
158
|
</div>
|
|
111
159
|
</div>
|
|
112
|
-
{:else if
|
|
160
|
+
{:else if resolvedShowSummary}
|
|
113
161
|
<p {...restProps} class={`svadmin-list-pagination__summary ${className}`.trim()}>{listText(i18n, 'common.total', { total })}</p>
|
|
114
162
|
{/if}
|
|
115
163
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { X } from '@lucide/svelte';
|
|
3
|
-
import {
|
|
3
|
+
import { useNotificationController, type NotificationPlacement } from '../notifications.svelte.js';
|
|
4
4
|
|
|
5
5
|
const placements: NotificationPlacement[] = ['top-right', 'top-left', 'bottom-right', 'bottom-left'];
|
|
6
|
+
const controller = useNotificationController();
|
|
6
7
|
const groups = $derived(placements
|
|
7
8
|
.map((placement) => ({
|
|
8
9
|
placement,
|
|
9
|
-
items:
|
|
10
|
+
items: controller.items.filter((item) => item.placement === placement),
|
|
10
11
|
}))
|
|
11
12
|
.filter((group) => group.items.length > 0));
|
|
12
13
|
</script>
|
|
@@ -24,10 +25,10 @@
|
|
|
24
25
|
<p class="svadmin-notification-host__title">{item.title}</p>
|
|
25
26
|
{#if item.description}<p class="svadmin-notification-host__description">{item.description}</p>{/if}
|
|
26
27
|
{#if item.actionLabel && item.onAction}
|
|
27
|
-
<button type="button" class="svadmin-notification-host__action" onclick={() => { item.onAction?.();
|
|
28
|
+
<button type="button" class="svadmin-notification-host__action" onclick={() => { item.onAction?.(); controller.close(item.id); }}>{item.actionLabel}</button>
|
|
28
29
|
{/if}
|
|
29
30
|
</div>
|
|
30
|
-
<button type="button" class="svadmin-notification-host__close" aria-label="Close notification" onclick={() =>
|
|
31
|
+
<button type="button" class="svadmin-notification-host__close" aria-label="Close notification" onclick={() => controller.close(item.id)}>
|
|
31
32
|
<X size={14} aria-hidden="true" />
|
|
32
33
|
</button>
|
|
33
34
|
</section>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
3
|
+
import { captureAdminContext, useCan, type Action } from '@svadmin/core';
|
|
4
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
import DataState from './content/DataState.svelte';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
resource: string;
|
|
10
|
+
action?: Action;
|
|
11
|
+
id?: string | number;
|
|
12
|
+
children: Snippet;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
resource,
|
|
17
|
+
action = 'list',
|
|
18
|
+
id,
|
|
19
|
+
children,
|
|
20
|
+
}: Props = $props();
|
|
21
|
+
|
|
22
|
+
const adminContext = captureAdminContext();
|
|
23
|
+
const i18n = useTranslation();
|
|
24
|
+
const accessControlEnabled = $derived(Boolean(adminContext.accessControlProvider));
|
|
25
|
+
const permission = useCan(() => (definedOptions({
|
|
26
|
+
resource,
|
|
27
|
+
action,
|
|
28
|
+
id,
|
|
29
|
+
queryOptions: { enabled: accessControlEnabled },
|
|
30
|
+
})));
|
|
31
|
+
const denialDescription = $derived(
|
|
32
|
+
permission.isError ? i18n.t('common.permissionUnavailable') : i18n.t('common.permissionDenied'),
|
|
33
|
+
);
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{#if accessControlEnabled && permission.isLoading}
|
|
37
|
+
<DataState state="loading" />
|
|
38
|
+
{:else if !accessControlEnabled || permission.allowed}
|
|
39
|
+
{@render children()}
|
|
40
|
+
{:else}
|
|
41
|
+
<DataState state={permission.isError ? 'error' : 'forbidden'} description={denialDescription} />
|
|
42
|
+
{/if}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Action } from '@svadmin/core';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
resource: string;
|
|
5
|
+
action?: Action;
|
|
6
|
+
id?: string | number;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
}
|
|
9
|
+
declare const RouteAccessGuard: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type RouteAccessGuard = ReturnType<typeof RouteAccessGuard>;
|
|
11
|
+
export default RouteAccessGuard;
|
|
@@ -48,9 +48,9 @@ export interface ComponentMessageSource {
|
|
|
48
48
|
t: (key: string) => string;
|
|
49
49
|
}
|
|
50
50
|
export declare function resolveComponentLocale(input: {
|
|
51
|
-
explicit?: string | null;
|
|
52
|
-
configLocale?: string | null;
|
|
53
|
-
i18nLocale?: string | null;
|
|
51
|
+
explicit?: string | null | undefined;
|
|
52
|
+
configLocale?: string | null | undefined;
|
|
53
|
+
i18nLocale?: string | null | undefined;
|
|
54
54
|
}): string;
|
|
55
55
|
/** 宿主翻译优先;缺失时按已解析 locale 选择内置中文或英文。 */
|
|
56
56
|
export declare function componentText(i18n: ComponentMessageSource, locale: string, key: ComponentMessageKey): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MenuItem } from '@svadmin/core';
|
|
2
|
+
/** 自定义页面的直接访问权限。与菜单 `meta.resource` / `meta.action` 使用同一套检查。 */
|
|
3
|
+
export interface CustomRouteAccessConfig {
|
|
4
|
+
readonly resource: string;
|
|
5
|
+
/** 缺省为 `list`,与侧栏菜单一致。 */
|
|
6
|
+
readonly action?: string;
|
|
7
|
+
readonly id?: string | number;
|
|
8
|
+
/** 从匹配到的路由参数读取记录 id,用于带参数的直接 URL。 */
|
|
9
|
+
readonly idParam?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CustomRouteAccess {
|
|
12
|
+
readonly resource: string;
|
|
13
|
+
readonly action: string;
|
|
14
|
+
readonly id?: string | number;
|
|
15
|
+
}
|
|
16
|
+
export interface CustomRouteAccessSource {
|
|
17
|
+
/**
|
|
18
|
+
* 显式权限覆盖菜单继承。`false` 表示该路由保持公开,即使同路径菜单受保护。
|
|
19
|
+
*/
|
|
20
|
+
readonly access?: CustomRouteAccessConfig | false;
|
|
21
|
+
}
|
|
22
|
+
export declare function normalizeNavPath(value: string | undefined): string;
|
|
23
|
+
/**
|
|
24
|
+
* 自定义路由的直接 URL 权限。
|
|
25
|
+
* 显式 `access` 优先;否则继承当前 URL 上最具体的菜单项。
|
|
26
|
+
* 更具体的菜单项没有 `meta.resource` 时视为公开,不回退到父级。
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveCustomRouteAccess(route: CustomRouteAccessSource, pathname: string, menu: readonly MenuItem[] | undefined, params?: Record<string, string | undefined>): CustomRouteAccess | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function normalizeNavPath(value) {
|
|
2
|
+
if (!value)
|
|
3
|
+
return '';
|
|
4
|
+
const path = value.replace(/^#/, '').split(/[?#]/)[0] || '/';
|
|
5
|
+
if (path === '/')
|
|
6
|
+
return '/';
|
|
7
|
+
const withSlash = path.startsWith('/') ? path : `/${path}`;
|
|
8
|
+
return withSlash.replace(/\/+$/, '');
|
|
9
|
+
}
|
|
10
|
+
function consider(item, current, best) {
|
|
11
|
+
const href = normalizeNavPath(item.href);
|
|
12
|
+
if (href) {
|
|
13
|
+
const exact = href === current;
|
|
14
|
+
const prefix = href !== '/' && current.startsWith(`${href}/`);
|
|
15
|
+
if (exact || prefix) {
|
|
16
|
+
const score = (exact ? 1_000_000 : 0) + href.length;
|
|
17
|
+
if (!best || score > best.score)
|
|
18
|
+
best = { score, item };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (const child of item.children ?? [])
|
|
22
|
+
best = consider(child, current, best);
|
|
23
|
+
return best;
|
|
24
|
+
}
|
|
25
|
+
function inheritedMenuAccess(menu, pathname) {
|
|
26
|
+
const current = normalizeNavPath(pathname);
|
|
27
|
+
if (!current)
|
|
28
|
+
return undefined;
|
|
29
|
+
let best;
|
|
30
|
+
for (const item of menu ?? [])
|
|
31
|
+
best = consider(item, current, best);
|
|
32
|
+
const resource = best?.item.meta?.resource;
|
|
33
|
+
if (!resource)
|
|
34
|
+
return undefined;
|
|
35
|
+
const action = best?.item.meta?.action;
|
|
36
|
+
return { resource, action: action && action.length > 0 ? action : 'list' };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 自定义路由的直接 URL 权限。
|
|
40
|
+
* 显式 `access` 优先;否则继承当前 URL 上最具体的菜单项。
|
|
41
|
+
* 更具体的菜单项没有 `meta.resource` 时视为公开,不回退到父级。
|
|
42
|
+
*/
|
|
43
|
+
export function resolveCustomRouteAccess(route, pathname, menu, params = {}) {
|
|
44
|
+
if (route.access === false)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (route.access) {
|
|
47
|
+
const action = route.access.action && route.access.action.length > 0 ? route.access.action : 'list';
|
|
48
|
+
const paramId = route.access.idParam ? params[route.access.idParam] : undefined;
|
|
49
|
+
const id = route.access.id !== undefined ? route.access.id : paramId;
|
|
50
|
+
return {
|
|
51
|
+
resource: route.access.resource,
|
|
52
|
+
action,
|
|
53
|
+
...(id !== undefined && id !== '' ? { id } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return inheritedMenuAccess(menu, pathname);
|
|
57
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CrudOperator, type FieldDefinition, type Filter } from '@svadmin/core';
|
|
2
2
|
export declare const FILTER_EDITOR_LIMITS: Readonly<{
|
|
3
3
|
depth: 12;
|
|
4
4
|
nodes: 256;
|
|
@@ -18,6 +18,7 @@ export interface FilterGroupNode {
|
|
|
18
18
|
operator: 'and' | 'or';
|
|
19
19
|
children: FilterNode[];
|
|
20
20
|
wrapped?: boolean;
|
|
21
|
+
key?: string;
|
|
21
22
|
}
|
|
22
23
|
export type FilterNode = FilterRuleNode | FilterGroupNode;
|
|
23
24
|
export type FilterIssueCode = 'invalid-filter' | 'limit' | 'unknown-field' | 'operator' | 'logic' | 'value' | 'empty-group';
|
|
@@ -39,6 +40,8 @@ export type FilterTreeCompile = {
|
|
|
39
40
|
ok: false;
|
|
40
41
|
issues: FilterEditorIssue[];
|
|
41
42
|
};
|
|
43
|
+
export declare const isListOperator: (operator: CrudOperator) => boolean;
|
|
44
|
+
export declare const isRangeOperator: (operator: CrudOperator) => boolean;
|
|
42
45
|
export declare const isCollectionOperator: (operator: CrudOperator) => boolean;
|
|
43
46
|
export declare const isNullOperator: (operator: CrudOperator) => boolean;
|
|
44
47
|
export declare function filterOperators(field: Pick<FieldDefinition, 'type'> | undefined): CrudOperator[];
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import { isCrudFieldOperator } from '@svadmin/core';
|
|
1
2
|
export const FILTER_EDITOR_LIMITS = Object.freeze({ depth: 12, nodes: 256, values: 1000 });
|
|
2
|
-
|
|
3
|
-
const comparison = ['eq', 'ne', 'lt', 'gt', 'lte', 'gte', 'in', 'nin', 'between', 'nbetween', 'null', 'nnull'];
|
|
4
|
-
const selection = ['eq', 'ne', 'in', 'nin', 'null', 'nnull'];
|
|
5
|
-
const text = ['eq', 'ne', 'contains', 'ncontains', 'startswith', 'endswith', 'in', 'nin', 'null', 'nnull'];
|
|
3
|
+
// 与 CRUD_FIELD_OPERATORS 对齐。带 s 的是大小写敏感变体;ina/nina 与 in/nin 一样接收数组值。
|
|
4
|
+
const comparison = ['eq', 'ne', 'eqs', 'nes', 'lt', 'gt', 'lte', 'gte', 'in', 'nin', 'ina', 'nina', 'between', 'nbetween', 'null', 'nnull'];
|
|
5
|
+
const selection = ['eq', 'ne', 'eqs', 'nes', 'in', 'nin', 'ina', 'nina', 'null', 'nnull'];
|
|
6
|
+
const text = ['eq', 'ne', 'eqs', 'nes', 'contains', 'ncontains', 'containss', 'ncontainss', 'startswith', 'nstartswith', 'startswiths', 'nstartswiths', 'endswith', 'nendswith', 'endswiths', 'nendswiths', 'in', 'nin', 'ina', 'nina', 'null', 'nnull'];
|
|
7
|
+
const operatorCoverage = true;
|
|
8
|
+
void operatorCoverage;
|
|
6
9
|
const scalar = (value) => value === null || typeof value === 'string' || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value));
|
|
10
|
+
function keyedGroup(node, children) {
|
|
11
|
+
return node.key ? { key: node.key, operator: node.operator, value: children } : { operator: node.operator, value: children };
|
|
12
|
+
}
|
|
7
13
|
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
8
|
-
|
|
14
|
+
const listOperators = ['in', 'nin', 'ina', 'nina'];
|
|
15
|
+
const rangeOperators = ['between', 'nbetween'];
|
|
16
|
+
export const isListOperator = (operator) => listOperators.includes(operator);
|
|
17
|
+
export const isRangeOperator = (operator) => rangeOperators.includes(operator);
|
|
18
|
+
export const isCollectionOperator = (operator) => isListOperator(operator) || isRangeOperator(operator);
|
|
9
19
|
export const isNullOperator = (operator) => operator === 'null' || operator === 'nnull';
|
|
10
20
|
export function filterOperators(field) {
|
|
11
21
|
if (!field)
|
|
@@ -34,7 +44,7 @@ export function readFilterTree(input) {
|
|
|
34
44
|
try {
|
|
35
45
|
const id = `node-${count}`;
|
|
36
46
|
if ('field' in raw) {
|
|
37
|
-
if (typeof raw['field'] !== 'string' || !raw['field'] || !
|
|
47
|
+
if (typeof raw['field'] !== 'string' || !raw['field'] || !isCrudFieldOperator(raw['operator'])
|
|
38
48
|
|| Object.keys(raw).some((key) => !['field', 'operator', 'value'].includes(key))) {
|
|
39
49
|
issues.push({ path, code: 'invalid-filter' });
|
|
40
50
|
return;
|
|
@@ -47,10 +57,18 @@ export function readFilterTree(input) {
|
|
|
47
57
|
return { kind: 'rule', id, field: raw['field'], operator: raw['operator'], value: Array.isArray(value) ? [...value] : value };
|
|
48
58
|
}
|
|
49
59
|
if (!['and', 'or'].includes(String(raw['operator'])) || !Array.isArray(raw['value'])
|
|
50
|
-
|| Object.keys(raw).some((key) => !['operator', 'value'].includes(key))) {
|
|
60
|
+
|| Object.keys(raw).some((key) => !['operator', 'value', 'key'].includes(key))) {
|
|
51
61
|
issues.push({ path, code: 'invalid-filter' });
|
|
52
62
|
return;
|
|
53
63
|
}
|
|
64
|
+
let groupKey;
|
|
65
|
+
if ('key' in raw) {
|
|
66
|
+
if (typeof raw['key'] !== 'string' || raw['key'].length < 1 || raw['key'].length > 128) {
|
|
67
|
+
issues.push({ path, code: 'invalid-filter' });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
groupKey = raw['key'];
|
|
71
|
+
}
|
|
54
72
|
if (raw['value'].length > FILTER_EDITOR_LIMITS.nodes) {
|
|
55
73
|
issues.push({ path, code: 'limit' });
|
|
56
74
|
return;
|
|
@@ -61,7 +79,7 @@ export function readFilterTree(input) {
|
|
|
61
79
|
if (node)
|
|
62
80
|
children.push(node);
|
|
63
81
|
}
|
|
64
|
-
return { kind: 'group', id, operator: raw['operator'], children };
|
|
82
|
+
return { kind: 'group', id, operator: raw['operator'], children, ...(groupKey ? { key: groupKey } : {}) };
|
|
65
83
|
}
|
|
66
84
|
finally {
|
|
67
85
|
active.delete(raw);
|
|
@@ -111,7 +129,7 @@ export function compileFilterTree(root, fields, preserved = new Map()) {
|
|
|
111
129
|
}
|
|
112
130
|
if (original && node.kind === 'group' && !('field' in original)
|
|
113
131
|
&& !node.children.length && !original.value.length && node.operator === original.operator) {
|
|
114
|
-
return
|
|
132
|
+
return keyedGroup(node, []);
|
|
115
133
|
}
|
|
116
134
|
if (node.kind === 'group') {
|
|
117
135
|
if (node.operator !== 'and' && node.operator !== 'or') {
|
|
@@ -130,7 +148,7 @@ export function compileFilterTree(root, fields, preserved = new Map()) {
|
|
|
130
148
|
if (filter)
|
|
131
149
|
children.push(filter);
|
|
132
150
|
}
|
|
133
|
-
return
|
|
151
|
+
return keyedGroup(node, children);
|
|
134
152
|
}
|
|
135
153
|
const field = fieldMap.get(node.field);
|
|
136
154
|
if (!field || field.filterable === false) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { notification, useNotificationController } from '../notifications.svelte.js';
|
|
3
|
+
|
|
4
|
+
let { label }: { label: string } = $props();
|
|
5
|
+
const center = useNotificationController();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<button type="button" onclick={() => center.success(`${label} scoped`, 'from context', { duration: 0 })}>Scoped {label}</button>
|
|
9
|
+
<button type="button" onclick={() => notification.success(`${label} module`, 'from module', { duration: 0 })}>Module {label}</button>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import ConfigProvider, { type GetPopupContainer } from './ConfigProvider.svelte';
|
|
3
|
+
import * as Dialog from './ui/dialog/index.js';
|
|
4
|
+
import * as Popover from './ui/popover/index.js';
|
|
5
|
+
import * as Tooltip from './ui/tooltip/index.js';
|
|
6
|
+
import { Root as Sheet } from './ui/sheet/index.js';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
calls = [],
|
|
10
|
+
useCustomContainer = true,
|
|
11
|
+
}: {
|
|
12
|
+
calls?: Array<HTMLElement | null | undefined>;
|
|
13
|
+
useCustomContainer?: boolean;
|
|
14
|
+
} = $props();
|
|
15
|
+
|
|
16
|
+
const getPopupContainer: GetPopupContainer = (node) => {
|
|
17
|
+
calls.push(node);
|
|
18
|
+
if (typeof document === 'undefined') return undefined;
|
|
19
|
+
return node?.closest('.workspace') ?? undefined;
|
|
20
|
+
};
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<ConfigProvider {...useCustomContainer ? { getPopupContainer } : {}}>
|
|
24
|
+
<div class="workspace" data-testid="workspace-a">
|
|
25
|
+
<Dialog.Root open>
|
|
26
|
+
<Dialog.Trigger>Open dialog</Dialog.Trigger>
|
|
27
|
+
<Dialog.Content>Dialog body</Dialog.Content>
|
|
28
|
+
</Dialog.Root>
|
|
29
|
+
<Tooltip.Root open>
|
|
30
|
+
<Tooltip.Trigger>Open tooltip</Tooltip.Trigger>
|
|
31
|
+
<Tooltip.Content>Tooltip body</Tooltip.Content>
|
|
32
|
+
</Tooltip.Root>
|
|
33
|
+
</div>
|
|
34
|
+
<div class="workspace" data-testid="workspace-b">
|
|
35
|
+
<Popover.Root open>
|
|
36
|
+
<Popover.Trigger>Open popover</Popover.Trigger>
|
|
37
|
+
<Popover.Content>Popover body</Popover.Content>
|
|
38
|
+
</Popover.Root>
|
|
39
|
+
<Sheet open>Sheet body</Sheet>
|
|
40
|
+
</div>
|
|
41
|
+
</ConfigProvider>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
calls?: Array<HTMLElement | null | undefined>;
|
|
3
|
+
useCustomContainer?: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare const PopupPortalHost: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type PopupPortalHost = ReturnType<typeof PopupPortalHost>;
|
|
7
|
+
export default PopupPortalHost;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { AlertDialog as AlertDialogPrimitive } from "bits-ui";
|
|
3
|
+
import PopupPortal from "../popup-portal.svelte";
|
|
4
|
+
|
|
3
5
|
let { ...restProps }: AlertDialogPrimitive.PortalProps = $props();
|
|
4
6
|
</script>
|
|
5
7
|
|
|
6
|
-
<
|
|
8
|
+
<PopupPortal {...restProps} kind="alert-dialog" />
|
|
@@ -26,10 +26,21 @@
|
|
|
26
26
|
import * as Tooltip from "../tooltip/index.js";
|
|
27
27
|
import { useComponentConfig } from "../../ConfigProvider.svelte";
|
|
28
28
|
|
|
29
|
+
const BUTTON_VARIANTS = new Set(["default", "outline", "secondary", "ghost", "destructive", "link", "dashed", "text"]);
|
|
30
|
+
const BUTTON_SIZES = new Set(["default", "xs", "sm", "lg", "icon", "icon-xs", "icon-sm", "icon-lg"]);
|
|
31
|
+
|
|
32
|
+
function readButtonVariant(value: unknown): ButtonVariantValue | undefined {
|
|
33
|
+
return typeof value === "string" && BUTTON_VARIANTS.has(value) ? value as ButtonVariantValue : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readButtonSize(value: unknown): ButtonSizeValue | undefined {
|
|
37
|
+
return typeof value === "string" && BUTTON_SIZES.has(value) ? value as ButtonSizeValue : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
const uid = $props.id();
|
|
30
41
|
let {
|
|
31
42
|
class: className,
|
|
32
|
-
variant
|
|
43
|
+
variant: variantProp,
|
|
33
44
|
size: sizeProp,
|
|
34
45
|
ref = $bindable(null),
|
|
35
46
|
href = undefined,
|
|
@@ -45,7 +56,9 @@
|
|
|
45
56
|
}: ButtonProps = $props();
|
|
46
57
|
|
|
47
58
|
const config = useComponentConfig();
|
|
48
|
-
const
|
|
59
|
+
const buttonDefaults = $derived(config.componentDefaults['Button'] ?? {});
|
|
60
|
+
const variant = $derived(variantProp ?? readButtonVariant(buttonDefaults['variant']) ?? "default");
|
|
61
|
+
const size = $derived(sizeProp ?? readButtonSize(buttonDefaults['size']) ?? (config.density === "compact" || config.componentSize === "sm" ? "sm" : config.componentSize === "lg" ? "lg" : "default"));
|
|
49
62
|
|
|
50
63
|
const restriction = $derived((disabledReason ?? "").trim());
|
|
51
64
|
const isDisabled = $derived(Boolean(disabled || restriction));
|