@svadmin/core 0.57.0 → 0.58.0
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/package.json +2 -1
- package/src/theme.svelte.ts +13 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"author": "zuohuadong",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -133,6 +133,7 @@
|
|
|
133
133
|
"type": "module",
|
|
134
134
|
"types": "src/index.ts",
|
|
135
135
|
"dependencies": {
|
|
136
|
+
"@types/papaparse": "^5.5.2",
|
|
136
137
|
"@internationalized/date": "^3.12.3",
|
|
137
138
|
"@sinclair/typebox": "^0.34.52",
|
|
138
139
|
"papaparse": "^5.5.4"
|
package/src/theme.svelte.ts
CHANGED
|
@@ -246,6 +246,8 @@ export interface ThemeConfig {
|
|
|
246
246
|
|
|
247
247
|
/** Explicit document-level values contributed by one mounted AdminApp. */
|
|
248
248
|
export interface ThemeOwnerOptions {
|
|
249
|
+
/** 仅在没有显式主题 owner 或 legacy 配置时使用,不接管其他实例的主题。 */
|
|
250
|
+
fallbackThemeConfig?: ThemeConfig;
|
|
249
251
|
themeConfig?: ThemeConfig;
|
|
250
252
|
defaultTheme?: ThemeMode;
|
|
251
253
|
}
|
|
@@ -285,6 +287,9 @@ function cloneThemeConfig(config: ThemeConfig={}): ThemeConfig {
|
|
|
285
287
|
|
|
286
288
|
function cloneOwnerOptions(options: ThemeOwnerOptions): ThemeOwnerOptions {
|
|
287
289
|
return definedOptions({
|
|
290
|
+
fallbackThemeConfig: options.fallbackThemeConfig === undefined
|
|
291
|
+
? undefined
|
|
292
|
+
: cloneThemeConfig(options.fallbackThemeConfig),
|
|
288
293
|
defaultTheme: options.defaultTheme,
|
|
289
294
|
themeConfig: options.themeConfig===undefined
|
|
290
295
|
? undefined
|
|
@@ -409,8 +414,10 @@ function applyCssOverrides(overrides: Record<string,string>): void {
|
|
|
409
414
|
function applyEffectiveTheme(): void {
|
|
410
415
|
const owner=getActiveOwner();
|
|
411
416
|
const nextConfig=owner
|
|
412
|
-
? cloneThemeConfig(owner.options.themeConfig)
|
|
413
|
-
:cloneThemeConfig(legacyThemeConfig)
|
|
417
|
+
? cloneThemeConfig(owner.options.themeConfig ?? owner.options.fallbackThemeConfig)
|
|
418
|
+
:cloneThemeConfig(Object.keys(legacyThemeConfig).length
|
|
419
|
+
? legacyThemeConfig
|
|
420
|
+
: themeOwners.at(-1)?.options.fallbackThemeConfig);
|
|
414
421
|
const nextMode=selectedMode??owner?.options.defaultTheme??'system';
|
|
415
422
|
const configuredPreset=!colorSelectionOverridesConfig&&nextConfig.colorPreset
|
|
416
423
|
? resolvePreset(nextConfig.colorPreset)
|
|
@@ -513,8 +520,8 @@ export function registerThemeOwner(options: ThemeOwnerOptions): ThemeOwnerToken|
|
|
|
513
520
|
|
|
514
521
|
if(isExplicitOwner(entry.options)) {
|
|
515
522
|
colorSelectionOverridesConfig=false;
|
|
516
|
-
applyEffectiveTheme();
|
|
517
523
|
}
|
|
524
|
+
if(isExplicitOwner(entry.options)||entry.options.fallbackThemeConfig) applyEffectiveTheme();
|
|
518
525
|
|
|
519
526
|
return token;
|
|
520
527
|
}
|
|
@@ -529,11 +536,12 @@ export function updateThemeOwner(
|
|
|
529
536
|
if(!owner) return;
|
|
530
537
|
|
|
531
538
|
const wasExplicit=isExplicitOwner(owner.options);
|
|
539
|
+
const hadFallback=owner.options.fallbackThemeConfig!==undefined;
|
|
532
540
|
owner.options=cloneOwnerOptions(options);
|
|
533
541
|
if(wasExplicit||isExplicitOwner(owner.options)) {
|
|
534
542
|
colorSelectionOverridesConfig=false;
|
|
535
|
-
applyEffectiveTheme();
|
|
536
543
|
}
|
|
544
|
+
if(wasExplicit||isExplicitOwner(owner.options)||hadFallback||owner.options.fallbackThemeConfig) applyEffectiveTheme();
|
|
537
545
|
}
|
|
538
546
|
|
|
539
547
|
/** Remove an owner safely regardless of its position in the stack. */
|
|
@@ -545,8 +553,8 @@ export function unregisterThemeOwner(token: ThemeOwnerToken|undefined): void {
|
|
|
545
553
|
const [removed]=themeOwners.splice(index,1);
|
|
546
554
|
if(removed&&isExplicitOwner(removed.options)) {
|
|
547
555
|
colorSelectionOverridesConfig=false;
|
|
548
|
-
applyEffectiveTheme();
|
|
549
556
|
}
|
|
557
|
+
if(removed&&(isExplicitOwner(removed.options)||removed.options.fallbackThemeConfig)) applyEffectiveTheme();
|
|
550
558
|
}
|
|
551
559
|
|
|
552
560
|
export function resetTheme(): void {
|