@svadmin/ui 0.108.1 → 0.108.3
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/app.css +1 -0
- package/dist/app.theme.css +1 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AppearanceSettings.svelte +18 -1
- package/dist/components/Calendar.svelte +28 -8
- package/dist/components/ConfigProvider.svelte +23 -9
- package/dist/components/ConfigProvider.svelte.d.ts +3 -0
- package/dist/components/DataTableShell.svelte +5 -1
- package/dist/components/DatePicker.svelte +32 -9
- package/dist/components/DatePicker.svelte.d.ts +3 -0
- package/dist/components/component-messages.d.ts +59 -0
- package/dist/components/component-messages.js +47 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/app.css
CHANGED
|
@@ -11146,6 +11146,7 @@ main {
|
|
|
11146
11146
|
.sidebar-content-collapsed {
|
|
11147
11147
|
margin-left: 0;
|
|
11148
11148
|
margin-right: 0;
|
|
11149
|
+
transition-property: none;
|
|
11149
11150
|
}
|
|
11150
11151
|
}
|
|
11151
11152
|
|
package/dist/app.theme.css
CHANGED
|
@@ -11146,6 +11146,7 @@ main {
|
|
|
11146
11146
|
.sidebar-content-collapsed {
|
|
11147
11147
|
margin-left: 0;
|
|
11148
11148
|
margin-right: 0;
|
|
11149
|
+
transition-property: none;
|
|
11149
11150
|
}
|
|
11150
11151
|
}
|
|
11151
11152
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
const resources = $derived(adminContext.resources.filter((resource) => resource.meta?.['aboutVisible'] !== false));
|
|
12
12
|
const providerNames = $derived(adminContext.getDataProviderNames());
|
|
13
13
|
let { version: suppliedVersion, headingLevel = 'h1' }: { version?: string; headingLevel?: 'h1' | 'h2' } = $props();
|
|
14
|
-
const buildVersion = "0.108.
|
|
14
|
+
const buildVersion = "0.108.3";
|
|
15
15
|
const version = $derived(suppliedVersion ?? (
|
|
16
16
|
buildVersion.startsWith('__')
|
|
17
17
|
? (i18n.locale === 'zh-CN' ? '开发构建(未提供版本)' : 'Development build (version unavailable)')
|
|
@@ -27,8 +27,25 @@
|
|
|
27
27
|
const storedPageSize = typeof window !== 'undefined' ? Number(localStorage.getItem(PAGE_SIZE_KEY) ?? '10') : 10;
|
|
28
28
|
let pageSize = $state(pageSizeOptions.includes(storedPageSize) ? storedPageSize : 10);
|
|
29
29
|
const localeNames: Record<string, string> = { 'zh-CN': '中文(简体)', en: 'English', ja: '日本語', ko: '한국어' };
|
|
30
|
+
const defaultColorLabels: Record<string, string> = {
|
|
31
|
+
neutral: 'Neutral',
|
|
32
|
+
indigo: 'Indigo',
|
|
33
|
+
blue: 'Blue',
|
|
34
|
+
green: 'Green',
|
|
35
|
+
rose: 'Rose',
|
|
36
|
+
orange: 'Orange',
|
|
37
|
+
violet: 'Violet',
|
|
38
|
+
default: 'Default',
|
|
39
|
+
stripe: 'Stripe',
|
|
40
|
+
};
|
|
30
41
|
function setDensity(value: 'compact' | 'standard') { density = value; if (typeof window !== 'undefined') { localStorage.setItem(DENSITY_KEY, value); window.dispatchEvent(new CustomEvent('svadmin-density-change', { detail: value })); } }
|
|
31
42
|
function setPageSize(size: number) { pageSize = size; if (typeof window !== 'undefined') localStorage.setItem(PAGE_SIZE_KEY, String(size)); }
|
|
43
|
+
function colorLabel(name: string, label: string): string {
|
|
44
|
+
if (defaultColorLabels[name] !== label) return label;
|
|
45
|
+
const key = `settings.accent.${name}`;
|
|
46
|
+
const translated = i18n.t(key);
|
|
47
|
+
return translated === key ? label : translated;
|
|
48
|
+
}
|
|
32
49
|
</script>
|
|
33
50
|
|
|
34
51
|
<div class="space-y-6">
|
|
@@ -49,7 +66,7 @@
|
|
|
49
66
|
<div class="flex flex-wrap gap-3">
|
|
50
67
|
{#each presets as preset (preset.name)}
|
|
51
68
|
{@const active = currentColor === preset.name}
|
|
52
|
-
<button class="relative size-9 rounded-full border border-border transition-opacity {active ? 'ring-2 ring-primary ring-offset-2 ring-offset-background' : 'opacity-70 hover:opacity-100'}" style="background-color: {preset.color}" onclick={() => setColorTheme(preset.name as Parameters<typeof setColorTheme>[0])} aria-label={preset.label} aria-pressed={active}>{#if active}<Check class="absolute inset-0 m-auto size-4 text-white drop-shadow-sm" />{/if}</button>
|
|
69
|
+
<button class="relative size-9 rounded-full border border-border transition-opacity {active ? 'ring-2 ring-primary ring-offset-2 ring-offset-background' : 'opacity-70 hover:opacity-100'}" style="background-color: {preset.color}" onclick={() => setColorTheme(preset.name as Parameters<typeof setColorTheme>[0])} aria-label={colorLabel(preset.name, preset.label)} aria-pressed={active}>{#if active}<Check class="absolute inset-0 m-auto size-4 text-white drop-shadow-sm" />{/if}</button>
|
|
53
70
|
{/each}
|
|
54
71
|
</div>
|
|
55
72
|
</SettingsGroup>
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { untrack } from 'svelte';
|
|
3
3
|
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from '@lucide/svelte';
|
|
4
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
4
5
|
import { Button } from './ui/button/index.js';
|
|
5
6
|
import { cn } from '../utils.js';
|
|
7
|
+
import { hasComponentConfig, useComponentConfig } from './ConfigProvider.svelte';
|
|
8
|
+
import { componentText, resolveComponentLocale } from './component-messages.js';
|
|
6
9
|
|
|
7
10
|
export interface CalendarEvent {
|
|
8
11
|
id: string;
|
|
@@ -39,12 +42,29 @@
|
|
|
39
42
|
let viewYear = $state(initial.getFullYear());
|
|
40
43
|
let viewMonth = $state(initial.getMonth());
|
|
41
44
|
|
|
45
|
+
const config = useComponentConfig();
|
|
46
|
+
const i18n = useTranslation();
|
|
47
|
+
const provided = hasComponentConfig();
|
|
48
|
+
// 显式 locale 仍优先。未传入时与 DatePicker 共用 ConfigProvider / i18n 解析。
|
|
49
|
+
const activeLocale = $derived(resolveComponentLocale({
|
|
50
|
+
explicit: locale,
|
|
51
|
+
configLocale: provided ? config.locale : undefined,
|
|
52
|
+
i18nLocale: i18n.locale,
|
|
53
|
+
}));
|
|
54
|
+
const copy = $derived({
|
|
55
|
+
previousMonth: componentText(i18n, activeLocale, 'datePicker.previousMonth'),
|
|
56
|
+
nextMonth: componentText(i18n, activeLocale, 'datePicker.nextMonth'),
|
|
57
|
+
previousYear: componentText(i18n, activeLocale, 'datePicker.previousYear'),
|
|
58
|
+
nextYear: componentText(i18n, activeLocale, 'datePicker.nextYear'),
|
|
59
|
+
calendarDates: componentText(i18n, activeLocale, 'datePicker.calendarDates'),
|
|
60
|
+
});
|
|
61
|
+
|
|
42
62
|
const weekdays = $derived.by(() => {
|
|
43
|
-
const format = new Intl.DateTimeFormat(
|
|
44
|
-
return Array.from({ length: 7 }, (_, index) => format.format(new Date(2024, 0, 7 + ((index + weekStartsOn) % 7))));
|
|
63
|
+
const format = new Intl.DateTimeFormat(activeLocale, { weekday: 'short' });
|
|
64
|
+
return Array.from({ length: 7 }, (_, index) => format.format(new Date(2024, 0, 7 + ((index + weekStartsOn) % 7), 12)));
|
|
45
65
|
});
|
|
46
66
|
|
|
47
|
-
const title = $derived(new Intl.DateTimeFormat(
|
|
67
|
+
const title = $derived(new Intl.DateTimeFormat(activeLocale, { month: 'long', year: 'numeric' }).format(new Date(viewYear, viewMonth, 1, 12)));
|
|
48
68
|
|
|
49
69
|
const days = $derived.by(() => {
|
|
50
70
|
const first = new Date(viewYear, viewMonth, 1);
|
|
@@ -107,17 +127,17 @@
|
|
|
107
127
|
<header class="svadmin-calendar__header">
|
|
108
128
|
<strong>{title}</strong>
|
|
109
129
|
<div class="svadmin-calendar__nav">
|
|
110
|
-
<Button variant="outline" size="icon-sm" aria-label=
|
|
111
|
-
<Button variant="outline" size="icon-sm" aria-label=
|
|
112
|
-
<Button variant="outline" size="icon-sm" aria-label=
|
|
113
|
-
<Button variant="outline" size="icon-sm" aria-label=
|
|
130
|
+
<Button variant="outline" size="icon-sm" aria-label={copy.previousYear} onclick={() => moveYear(-1)}><ChevronsLeft size={16} /></Button>
|
|
131
|
+
<Button variant="outline" size="icon-sm" aria-label={copy.previousMonth} onclick={() => move(-1)}><ChevronLeft size={16} /></Button>
|
|
132
|
+
<Button variant="outline" size="icon-sm" aria-label={copy.nextMonth} onclick={() => move(1)}><ChevronRight size={16} /></Button>
|
|
133
|
+
<Button variant="outline" size="icon-sm" aria-label={copy.nextYear} onclick={() => moveYear(1)}><ChevronsRight size={16} /></Button>
|
|
114
134
|
</div>
|
|
115
135
|
</header>
|
|
116
136
|
<div class="svadmin-calendar__weekdays" aria-hidden="true">
|
|
117
137
|
{#each weekdays as weekday (weekday)}<span>{weekday}</span>{/each}
|
|
118
138
|
</div>
|
|
119
139
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
120
|
-
<div class="svadmin-calendar__grid" role="group" aria-label=
|
|
140
|
+
<div class="svadmin-calendar__grid" role="group" aria-label={copy.calendarDates} onkeydown={onGridKeydown}>
|
|
121
141
|
{#each days as day (day.iso)}
|
|
122
142
|
<button
|
|
123
143
|
type="button"
|
|
@@ -11,20 +11,27 @@
|
|
|
11
11
|
|
|
12
12
|
export const CONFIG_CONTEXT_KEY = Symbol('svadmin-component-config');
|
|
13
13
|
|
|
14
|
+
export const DEFAULT_COMPONENT_CONFIG: Required<ComponentConfig> = {
|
|
15
|
+
theme: 'system',
|
|
16
|
+
density: 'default',
|
|
17
|
+
direction: 'ltr',
|
|
18
|
+
locale: 'en',
|
|
19
|
+
componentSize: 'md',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** 当前组件是否位于 ConfigProvider 内。只能在组件初始化时调用。 */
|
|
23
|
+
export function hasComponentConfig(): boolean {
|
|
24
|
+
return getContext<Required<ComponentConfig> | undefined>(CONFIG_CONTEXT_KEY) !== undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
export function useComponentConfig(): Required<ComponentConfig> {
|
|
15
|
-
return getContext<Required<ComponentConfig>>(CONFIG_CONTEXT_KEY) ??
|
|
16
|
-
theme: 'system',
|
|
17
|
-
density: 'default',
|
|
18
|
-
direction: 'ltr',
|
|
19
|
-
locale: 'en',
|
|
20
|
-
componentSize: 'md',
|
|
21
|
-
};
|
|
28
|
+
return getContext<Required<ComponentConfig>>(CONFIG_CONTEXT_KEY) ?? DEFAULT_COMPONENT_CONFIG;
|
|
22
29
|
}
|
|
23
30
|
</script>
|
|
24
31
|
|
|
25
32
|
<script lang="ts">
|
|
26
33
|
import type { Snippet } from 'svelte';
|
|
27
|
-
import { setContext
|
|
34
|
+
import { setContext } from 'svelte';
|
|
28
35
|
import { cn } from '../utils.js';
|
|
29
36
|
|
|
30
37
|
interface Props extends ComponentConfig {
|
|
@@ -42,7 +49,14 @@
|
|
|
42
49
|
children,
|
|
43
50
|
}: Props = $props();
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
// 保存读取器而不是初始化快照。子组件在渲染或 $derived 中读取字段时,会跟踪对应 prop。
|
|
53
|
+
setContext(CONFIG_CONTEXT_KEY, {
|
|
54
|
+
get theme() { return theme; },
|
|
55
|
+
get density() { return density; },
|
|
56
|
+
get direction() { return direction; },
|
|
57
|
+
get locale() { return locale; },
|
|
58
|
+
get componentSize() { return componentSize; },
|
|
59
|
+
} satisfies Required<ComponentConfig>);
|
|
46
60
|
</script>
|
|
47
61
|
|
|
48
62
|
<div
|
|
@@ -6,6 +6,9 @@ export interface ComponentConfig {
|
|
|
6
6
|
componentSize?: 'sm' | 'md' | 'lg';
|
|
7
7
|
}
|
|
8
8
|
export declare const CONFIG_CONTEXT_KEY: unique symbol;
|
|
9
|
+
export declare const DEFAULT_COMPONENT_CONFIG: Required<ComponentConfig>;
|
|
10
|
+
/** 当前组件是否位于 ConfigProvider 内。只能在组件初始化时调用。 */
|
|
11
|
+
export declare function hasComponentConfig(): boolean;
|
|
9
12
|
export declare function useComponentConfig(): Required<ComponentConfig>;
|
|
10
13
|
import type { Snippet } from 'svelte';
|
|
11
14
|
interface Props extends ComponentConfig {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
3
4
|
import { cn } from '../utils.js';
|
|
5
|
+
import { listText } from './list-i18n.js';
|
|
6
|
+
|
|
7
|
+
const i18n = useTranslation();
|
|
4
8
|
|
|
5
9
|
interface Props {
|
|
6
10
|
/** Optional table heading. Omit it when the page already owns the heading. */
|
|
@@ -40,7 +44,7 @@
|
|
|
40
44
|
<div class="svadmin-data-table-shell__heading">
|
|
41
45
|
<h2 class="svadmin-data-table-shell__title">{title}</h2>
|
|
42
46
|
{#if count !== undefined}
|
|
43
|
-
<span class="svadmin-data-table-shell__count" data-svadmin-data-table-count>{count}
|
|
47
|
+
<span class="svadmin-data-table-shell__count" data-svadmin-data-table-count>{listText(i18n, 'common.total', { total: count })}</span>
|
|
44
48
|
{/if}
|
|
45
49
|
</div>
|
|
46
50
|
{/if}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { untrack, type ComponentProps } from 'svelte';
|
|
3
3
|
import { ChevronLeft, ChevronRight } from '@lucide/svelte';
|
|
4
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
4
5
|
import DateTimeInput from './DateTimeInput.svelte';
|
|
5
6
|
import { Button } from './ui/button/index.js';
|
|
6
7
|
import * as Popover from './ui/popover/index.js';
|
|
7
8
|
import { cn } from '../utils.js';
|
|
9
|
+
import { hasComponentConfig, useComponentConfig } from './ConfigProvider.svelte';
|
|
10
|
+
import { componentText, monthLabel, resolveComponentLocale, weekdayLabels } from './component-messages.js';
|
|
8
11
|
|
|
9
12
|
export type DatePickerMode = 'date' | 'month' | 'year' | 'quarter';
|
|
10
13
|
export interface DatePreset { label: string; value: string; }
|
|
@@ -17,7 +20,10 @@
|
|
|
17
20
|
panel?: boolean;
|
|
18
21
|
picker?: DatePickerMode;
|
|
19
22
|
presets?: DatePreset[];
|
|
23
|
+
/** 未传入时跟随已解析 locale,英文为 Select date,中文为选择日期。 */
|
|
20
24
|
placeholder?: string;
|
|
25
|
+
/** 覆盖 ConfigProvider 与 i18n 的面板语言。不传则保持原有默认路径。 */
|
|
26
|
+
locale?: string;
|
|
21
27
|
onchange?: (value: string | null) => void;
|
|
22
28
|
}
|
|
23
29
|
|
|
@@ -28,14 +34,31 @@
|
|
|
28
34
|
panel = false,
|
|
29
35
|
picker = 'date',
|
|
30
36
|
presets = [],
|
|
31
|
-
placeholder
|
|
37
|
+
placeholder,
|
|
38
|
+
locale: localeProp,
|
|
32
39
|
disabled = false,
|
|
33
40
|
class: className,
|
|
34
41
|
onchange,
|
|
35
42
|
...nativeProps
|
|
36
43
|
}: Props = $props();
|
|
37
44
|
|
|
38
|
-
const
|
|
45
|
+
const config = useComponentConfig();
|
|
46
|
+
const i18n = useTranslation();
|
|
47
|
+
const provided = hasComponentConfig();
|
|
48
|
+
// 组件属性 > ConfigProvider(仅存在时)> i18n > en。无 Provider 时不拿默认 en 盖住 i18n。
|
|
49
|
+
const activeLocale = $derived(resolveComponentLocale({
|
|
50
|
+
explicit: localeProp,
|
|
51
|
+
configLocale: provided ? config.locale : undefined,
|
|
52
|
+
i18nLocale: i18n.locale,
|
|
53
|
+
}));
|
|
54
|
+
const copy = $derived({
|
|
55
|
+
previous: componentText(i18n, activeLocale, 'datePicker.previous'),
|
|
56
|
+
next: componentText(i18n, activeLocale, 'datePicker.next'),
|
|
57
|
+
clear: componentText(i18n, activeLocale, 'datePicker.clear'),
|
|
58
|
+
selectDate: componentText(i18n, activeLocale, 'datePicker.selectDate'),
|
|
59
|
+
});
|
|
60
|
+
const resolvedPlaceholder = $derived(placeholder ?? copy.selectDate);
|
|
61
|
+
const weekdays = $derived(weekdayLabels(activeLocale));
|
|
39
62
|
let open = $state(false);
|
|
40
63
|
let viewMode = $state<'day' | 'month' | 'year'>(untrack(() => picker === 'year' ? 'year' : picker === 'month' ? 'month' : 'day'));
|
|
41
64
|
let viewDate = $state(initialView(value));
|
|
@@ -92,7 +115,7 @@
|
|
|
92
115
|
|
|
93
116
|
const months = $derived(Array.from({ length: 12 }, (_, month) => {
|
|
94
117
|
const key = `${viewDate.getFullYear()}-${pad(month + 1)}`;
|
|
95
|
-
return { month, key, label:
|
|
118
|
+
return { month, key, label: monthLabel(activeLocale, viewDate.getFullYear(), month), selected: value === key, disabled: false };
|
|
96
119
|
}));
|
|
97
120
|
|
|
98
121
|
const years = $derived.by(() => {
|
|
@@ -180,22 +203,22 @@
|
|
|
180
203
|
aria-label={nativeProps.ariaLabel}
|
|
181
204
|
class="flex min-h-9 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-1.5 text-left text-sm focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
182
205
|
>
|
|
183
|
-
<span class={value ? 'text-foreground' : 'text-muted-foreground'}>{formatValue(value) ||
|
|
206
|
+
<span class={value ? 'text-foreground' : 'text-muted-foreground'}>{formatValue(value) || resolvedPlaceholder}</span>
|
|
184
207
|
<ChevronRight class="h-4 w-4 rotate-90 opacity-50" />
|
|
185
208
|
</button>
|
|
186
209
|
{/snippet}
|
|
187
210
|
</Popover.Trigger>
|
|
188
211
|
<Popover.Content class="svadmin-date-picker-panel w-auto p-0" align="start">
|
|
189
|
-
<div class="w-64 p-2">
|
|
212
|
+
<div class="w-64 p-2" lang={activeLocale}>
|
|
190
213
|
<div class="mb-2 flex items-center justify-between">
|
|
191
|
-
<Button type="button" variant="ghost" size="icon-sm" aria-label=
|
|
214
|
+
<Button type="button" variant="ghost" size="icon-sm" aria-label={copy.previous} onclick={() => move(-1)}><ChevronLeft size={16} /></Button>
|
|
192
215
|
<button type="button" class="rounded px-2 py-1 text-sm font-medium hover:bg-muted" onclick={toggleTitle}>{title}</button>
|
|
193
|
-
<Button type="button" variant="ghost" size="icon-sm" aria-label=
|
|
216
|
+
<Button type="button" variant="ghost" size="icon-sm" aria-label={copy.next} onclick={() => move(1)}><ChevronRight size={16} /></Button>
|
|
194
217
|
</div>
|
|
195
218
|
|
|
196
219
|
{#if viewMode === 'day'}
|
|
197
220
|
<div class="grid grid-cols-7 gap-0.5 text-center text-[0.6875rem] text-muted-foreground">
|
|
198
|
-
{#each weekdays as weekday (
|
|
221
|
+
{#each weekdays as weekday, index (index)}<span class="py-1">{weekday}</span>{/each}
|
|
199
222
|
</div>
|
|
200
223
|
<div class="grid grid-cols-7 gap-0.5">
|
|
201
224
|
{#each days as day (day.iso)}
|
|
@@ -242,7 +265,7 @@
|
|
|
242
265
|
{/if}
|
|
243
266
|
{#if value}
|
|
244
267
|
<div class="mt-1 flex justify-end border-t border-border pt-1">
|
|
245
|
-
<Button type="button" variant="ghost" size="sm" onclick={clear}>
|
|
268
|
+
<Button type="button" variant="ghost" size="sm" onclick={clear}>{copy.clear}</Button>
|
|
246
269
|
</div>
|
|
247
270
|
{/if}
|
|
248
271
|
</div>
|
|
@@ -12,7 +12,10 @@ interface Props extends NativeProps {
|
|
|
12
12
|
panel?: boolean;
|
|
13
13
|
picker?: DatePickerMode;
|
|
14
14
|
presets?: DatePreset[];
|
|
15
|
+
/** 未传入时跟随已解析 locale,英文为 Select date,中文为选择日期。 */
|
|
15
16
|
placeholder?: string;
|
|
17
|
+
/** 覆盖 ConfigProvider 与 i18n 的面板语言。不传则保持原有默认路径。 */
|
|
18
|
+
locale?: string;
|
|
16
19
|
onchange?: (value: string | null) => void;
|
|
17
20
|
}
|
|
18
21
|
export type DatePickerProps = Props;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础控件文案扩展点。
|
|
3
|
+
*
|
|
4
|
+
* 解析顺序:组件 `locale` 属性 > ConfigProvider.locale(仅当树中存在 Provider)> i18n.locale > `en`。
|
|
5
|
+
* 词条先走 i18n key;宿主没有该 key 时,回退到本目录的中文 / 英文表。
|
|
6
|
+
* 新的基础控件不要再写死 Previous、Clear 等英文,改为调用 `componentText`,并在下面的目录补一条词条。
|
|
7
|
+
*/
|
|
8
|
+
export declare const componentMessageCatalog: {
|
|
9
|
+
readonly 'datePicker.previous': {
|
|
10
|
+
readonly en: "Previous";
|
|
11
|
+
readonly zh: "上一个";
|
|
12
|
+
};
|
|
13
|
+
readonly 'datePicker.next': {
|
|
14
|
+
readonly en: "Next";
|
|
15
|
+
readonly zh: "下一个";
|
|
16
|
+
};
|
|
17
|
+
readonly 'datePicker.clear': {
|
|
18
|
+
readonly en: "Clear";
|
|
19
|
+
readonly zh: "清除";
|
|
20
|
+
};
|
|
21
|
+
readonly 'datePicker.selectDate': {
|
|
22
|
+
readonly en: "Select date";
|
|
23
|
+
readonly zh: "选择日期";
|
|
24
|
+
};
|
|
25
|
+
readonly 'datePicker.previousMonth': {
|
|
26
|
+
readonly en: "Previous month";
|
|
27
|
+
readonly zh: "上个月";
|
|
28
|
+
};
|
|
29
|
+
readonly 'datePicker.nextMonth': {
|
|
30
|
+
readonly en: "Next month";
|
|
31
|
+
readonly zh: "下个月";
|
|
32
|
+
};
|
|
33
|
+
readonly 'datePicker.previousYear': {
|
|
34
|
+
readonly en: "Previous year";
|
|
35
|
+
readonly zh: "上一年";
|
|
36
|
+
};
|
|
37
|
+
readonly 'datePicker.nextYear': {
|
|
38
|
+
readonly en: "Next year";
|
|
39
|
+
readonly zh: "下一年";
|
|
40
|
+
};
|
|
41
|
+
readonly 'datePicker.calendarDates': {
|
|
42
|
+
readonly en: "Calendar dates";
|
|
43
|
+
readonly zh: "日历日期";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type ComponentMessageKey = keyof typeof componentMessageCatalog;
|
|
47
|
+
export interface ComponentMessageSource {
|
|
48
|
+
t: (key: string) => string;
|
|
49
|
+
}
|
|
50
|
+
export declare function resolveComponentLocale(input: {
|
|
51
|
+
explicit?: string | null;
|
|
52
|
+
configLocale?: string | null;
|
|
53
|
+
i18nLocale?: string | null;
|
|
54
|
+
}): string;
|
|
55
|
+
/** 宿主翻译优先;缺失时按已解析 locale 选择内置中文或英文。 */
|
|
56
|
+
export declare function componentText(i18n: ComponentMessageSource, locale: string, key: ComponentMessageKey): string;
|
|
57
|
+
/** 星期一为一周起点的短星期标签,供日期面板使用。 */
|
|
58
|
+
export declare function weekdayLabels(locale: string): string[];
|
|
59
|
+
export declare function monthLabel(locale: string, year: number, monthIndex: number): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础控件文案扩展点。
|
|
3
|
+
*
|
|
4
|
+
* 解析顺序:组件 `locale` 属性 > ConfigProvider.locale(仅当树中存在 Provider)> i18n.locale > `en`。
|
|
5
|
+
* 词条先走 i18n key;宿主没有该 key 时,回退到本目录的中文 / 英文表。
|
|
6
|
+
* 新的基础控件不要再写死 Previous、Clear 等英文,改为调用 `componentText`,并在下面的目录补一条词条。
|
|
7
|
+
*/
|
|
8
|
+
export const componentMessageCatalog = {
|
|
9
|
+
'datePicker.previous': { en: 'Previous', zh: '上一个' },
|
|
10
|
+
'datePicker.next': { en: 'Next', zh: '下一个' },
|
|
11
|
+
'datePicker.clear': { en: 'Clear', zh: '清除' },
|
|
12
|
+
'datePicker.selectDate': { en: 'Select date', zh: '选择日期' },
|
|
13
|
+
'datePicker.previousMonth': { en: 'Previous month', zh: '上个月' },
|
|
14
|
+
'datePicker.nextMonth': { en: 'Next month', zh: '下个月' },
|
|
15
|
+
'datePicker.previousYear': { en: 'Previous year', zh: '上一年' },
|
|
16
|
+
'datePicker.nextYear': { en: 'Next year', zh: '下一年' },
|
|
17
|
+
'datePicker.calendarDates': { en: 'Calendar dates', zh: '日历日期' },
|
|
18
|
+
};
|
|
19
|
+
export function resolveComponentLocale(input) {
|
|
20
|
+
const explicit = input.explicit?.trim();
|
|
21
|
+
if (explicit)
|
|
22
|
+
return explicit;
|
|
23
|
+
const configLocale = input.configLocale?.trim();
|
|
24
|
+
if (configLocale)
|
|
25
|
+
return configLocale;
|
|
26
|
+
const i18nLocale = input.i18nLocale?.trim();
|
|
27
|
+
if (i18nLocale)
|
|
28
|
+
return i18nLocale;
|
|
29
|
+
return 'en';
|
|
30
|
+
}
|
|
31
|
+
/** 宿主翻译优先;缺失时按已解析 locale 选择内置中文或英文。 */
|
|
32
|
+
export function componentText(i18n, locale, key) {
|
|
33
|
+
const translated = i18n.t(key);
|
|
34
|
+
if (translated !== key)
|
|
35
|
+
return translated;
|
|
36
|
+
const entry = componentMessageCatalog[key];
|
|
37
|
+
return locale.toLowerCase().startsWith('zh') ? entry.zh : entry.en;
|
|
38
|
+
}
|
|
39
|
+
/** 星期一为一周起点的短星期标签,供日期面板使用。 */
|
|
40
|
+
export function weekdayLabels(locale) {
|
|
41
|
+
const format = new Intl.DateTimeFormat(locale, { weekday: 'short' });
|
|
42
|
+
// 2024-01-01 是星期一。取正午,避免时区把日期拨到前一天。
|
|
43
|
+
return Array.from({ length: 7 }, (_, index) => format.format(new Date(2024, 0, 1 + index, 12)));
|
|
44
|
+
}
|
|
45
|
+
export function monthLabel(locale, year, monthIndex) {
|
|
46
|
+
return new Intl.DateTimeFormat(locale, { month: 'short' }).format(new Date(year, monthIndex, 1, 12));
|
|
47
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -317,7 +317,7 @@ export { default as Tour } from './components/Tour.svelte';
|
|
|
317
317
|
export type { TourStep } from './components/Tour.svelte';
|
|
318
318
|
export { default as Menu } from './components/Menu.svelte';
|
|
319
319
|
export type { MenuEntry } from './components/Menu.svelte';
|
|
320
|
-
export { default as ConfigProvider, useComponentConfig } from './components/ConfigProvider.svelte';
|
|
320
|
+
export { default as ConfigProvider, useComponentConfig, hasComponentConfig } from './components/ConfigProvider.svelte';
|
|
321
321
|
export type { ComponentConfig } from './components/ConfigProvider.svelte';
|
|
322
322
|
export { toast, toast as message, toast as Message } from '@svadmin/core';
|
|
323
323
|
export { cn } from './utils';
|
package/dist/index.js
CHANGED
|
@@ -259,7 +259,7 @@ export { default as Countdown } from './components/Countdown.svelte';
|
|
|
259
259
|
export { default as ResizeBox } from './components/ResizeBox.svelte';
|
|
260
260
|
export { default as Tour } from './components/Tour.svelte';
|
|
261
261
|
export { default as Menu } from './components/Menu.svelte';
|
|
262
|
-
export { default as ConfigProvider, useComponentConfig } from './components/ConfigProvider.svelte';
|
|
262
|
+
export { default as ConfigProvider, useComponentConfig, hasComponentConfig } from './components/ConfigProvider.svelte';
|
|
263
263
|
export { toast, toast as message, toast as Message } from '@svadmin/core';
|
|
264
264
|
// Utils
|
|
265
265
|
export { cn } from './utils';
|