@svadmin/ui 0.110.0 → 0.111.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.
@@ -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.110.0";
14
+ const buildVersion = "0.111.0";
15
15
  const version = $derived(suppliedVersion ?? (
16
16
  buildVersion.startsWith('__')
17
17
  ? (i18n.locale === 'zh-CN' ? '开发构建(未提供版本)' : 'Development build (version unavailable)')
@@ -1,5 +1,11 @@
1
1
  <script lang="ts">
2
- import { assertSchemaFormSchema, isSchemaFormNodeVisible, prepareSchemaFormValue, type SchemaFormSchema } from '@svadmin/core/schema-form';
2
+ import {
3
+ applySchemaFormComputed,
4
+ assertSchemaFormSchema,
5
+ isSchemaFormNodeVisible,
6
+ prepareSchemaFormValue,
7
+ type SchemaFormSchema,
8
+ } from '@svadmin/core/schema-form';
3
9
  import { tick } from 'svelte';
4
10
  import { useTranslation } from '@svadmin/core/i18n';
5
11
  import { Button } from './ui/button/index.js';
@@ -156,6 +162,19 @@
156
162
  return { ok: false as const };
157
163
  }
158
164
  });
165
+ // Computed fields are derived from the projected value; they render read-only
166
+ // and are recomputed on submit instead of being trusted from local input.
167
+ const computedValue = $derived.by(() => {
168
+ if (!coreSchema || !prepared.ok) return undefined;
169
+ try {
170
+ const result = applySchemaFormComputed(coreSchema, prepared.value);
171
+ return result !== null && typeof result === 'object' && !Array.isArray(result)
172
+ ? result as Record<string, unknown>
173
+ : undefined;
174
+ } catch {
175
+ return undefined;
176
+ }
177
+ });
159
178
  const locked = $derived(disabled || readonly || isSubmitting || !prepared.ok);
160
179
  let reportedConfiguration = '';
161
180
  let reportedSchema: JsonSchema | undefined;
@@ -290,7 +309,7 @@
290
309
  function readPath(path: string[]): unknown {
291
310
  return path.reduce<unknown>((current, key) => (
292
311
  current && typeof current === 'object' && Object.hasOwn(current, key) ? (current as Record<string, unknown>)[key] : undefined
293
- ), prepared.ok ? prepared.value : {});
312
+ ), computedValue ?? (prepared.ok ? prepared.value : {}));
294
313
  }
295
314
  function recordValue(current: unknown, key: string): unknown {
296
315
  if (current === null || typeof current !== 'object' || Array.isArray(current) || !Object.hasOwn(current, key)) return undefined;
@@ -362,7 +381,10 @@
362
381
  let payload: Record<string, unknown>;
363
382
  try {
364
383
  // 分支切换后只提交当前 discriminator 对应分支;旧分支字段不会随草稿误提交。
365
- const submittedValue = pruneRecursiveSchemaFormValue(model, prepared.value);
384
+ const pruned = pruneRecursiveSchemaFormValue(model, prepared.value);
385
+ const submittedValue = coreSchema
386
+ ? applySchemaFormComputed(coreSchema, pruned) as Record<string, unknown>
387
+ : pruned;
366
388
  const result = coreSchema ? prepareSchemaFormValue(coreSchema, submittedValue) : undefined;
367
389
  const detailedIssues = model.issues.length ? [] : validateRecursiveSchemaForm(model, submittedValue);
368
390
  // 隐藏字段暂不参与校验,但保留解析错误,重新显示时仍需修正。
@@ -427,7 +449,7 @@
427
449
  {@const current = readPath(path)}
428
450
  {@const id = `${prefix}_${path.map(encodeURIComponent).join('/')}`}
429
451
  {@const type = nodeType(node)}
430
- {@const fieldLocked = locked || pathReadonly(path)}
452
+ {@const fieldLocked = locked || pathReadonly(path) || Boolean(coreSchema && (node as SchemaFormSchema).computed)}
431
453
  {@const error = fieldInvalid(path)}
432
454
  {@const options = choices(node)}
433
455
  {@const descriptionId = node.description ? `${id}:description` : undefined}
@@ -17,13 +17,10 @@
17
17
  import * as Collapsible from './ui/collapsible/index.js';
18
18
  import { Avatar } from './ui/avatar/index.js';
19
19
  import {
20
- LayoutDashboard, FileText, Users, Settings, Home,
20
+ LayoutDashboard, Settings,
21
21
  ChevronLeft, ChevronRight, ChevronDown, LogOut, Sun, Moon, Palette,
22
- Image as ImageIcon, Layout, Folder, Type, Video,
23
- Download, ListTodo, TrendingUp, Sparkles, Images, Bot, Key, KeyRound, CreditCard, BookOpen, Wrench,
24
- Repeat, ClipboardCheck, SlidersHorizontal, AlertTriangle, Mail, Map as MapIcon, MessageSquare, Send, ShoppingBag, Star, Briefcase, Building2,
25
- Calendar, Bell, Clock, Tag, Trash2, Shield
26
22
  } from '@lucide/svelte';
23
+ import { resolveIcon, type IconComponent } from '../icons.js';
27
24
 
28
25
  const i18n = useTranslation();
29
26
 
@@ -50,54 +47,10 @@
50
47
  return effectiveRouteMode === 'hash' ? `#${path}` : path;
51
48
  }
52
49
 
53
- const iconMap: Record<string, typeof LayoutDashboard> = {
54
- 'dashboard': LayoutDashboard,
55
- 'posts': FileText,
56
- 'file': FileText,
57
- 'users': Users,
58
- 'settings': Settings,
59
- 'home': Home,
60
- 'palette': Palette,
61
- 'image': ImageIcon,
62
- 'layout': Layout,
63
- 'folder': Folder,
64
- 'type': Type,
65
- 'video': Video,
66
- 'download': Download,
67
- 'list-todo': ListTodo,
68
- 'trending-up': TrendingUp,
69
- 'sparkles': Sparkles,
70
- 'images': Images,
71
- 'bot': Bot,
72
- 'key': Key,
73
- 'key-round': KeyRound,
74
- 'credit-card': CreditCard,
75
- 'book-open': BookOpen,
76
- 'wrench': Wrench,
77
- 'repeat': Repeat,
78
- 'clipboard-check': ClipboardCheck,
79
- 'sliders-horizontal': SlidersHorizontal,
80
- 'alert-triangle': AlertTriangle,
81
- 'mail': Mail,
82
- 'map': MapIcon,
83
- 'message-square': MessageSquare,
84
- 'send': Send,
85
- 'shopping-bag': ShoppingBag,
86
- 'star': Star,
87
- 'briefcase': Briefcase,
88
- 'building': Building2,
89
- 'calendar': Calendar,
90
- 'bell': Bell,
91
- 'clock': Clock,
92
- 'tag': Tag,
93
- 'trash': Trash2,
94
- 'shield': Shield,
95
- };
96
-
97
50
  interface NavItem {
98
51
  path: string;
99
52
  label: string;
100
- Icon: typeof LayoutDashboard;
53
+ Icon: IconComponent;
101
54
  group?: string;
102
55
  }
103
56
 
@@ -193,7 +146,9 @@
193
146
  items.push(definedOptions({
194
147
  path: `/${r.name}`,
195
148
  label: r.label,
196
- Icon: (typeof r.icon === 'string' ? iconMap[r.icon] : r.icon) ?? iconMap[r.name] ?? Settings,
149
+ Icon: (typeof r.icon === 'string' ? resolveIcon(r.icon, Settings) : r.icon)
150
+ ?? resolveIcon(r.name, Settings)
151
+ ?? Settings,
197
152
  group: r.group,
198
153
  }));
199
154
  }
@@ -1,3 +1,4 @@
1
+ import type { SchemaFormComputed, SchemaFormCondition } from '@svadmin/core/schema-form';
1
2
  /** 嵌套表单的草稿与传输语义;不是替代服务端的 JSON Schema 校验器。 */
2
3
  export interface JsonSchemaFormSchema {
3
4
  $schema?: string;
@@ -33,12 +34,8 @@ export interface JsonSchemaFormSchema {
33
34
  enum?: Array<string | number | boolean | null>;
34
35
  default?: unknown;
35
36
  required?: string[];
36
- visibleWhen?: {
37
- path: readonly string[];
38
- equals?: string | number | boolean | null;
39
- notEquals?: string | number | boolean | null;
40
- exists?: boolean;
41
- };
37
+ visibleWhen?: SchemaFormCondition;
38
+ computed?: SchemaFormComputed;
42
39
  }
43
40
  export declare const SCHEMA_FORM_LIMITS: Readonly<{
44
41
  depth: 32;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Icon registry — resolve icons by name instead of a hardcoded local map.
3
+ *
4
+ * Arco resolves icons from a name (`<IconUser />` / `icon="user"`). svadmin keeps
5
+ * `@lucide/svelte` as the default set, but name resolution must be extensible:
6
+ * third-party plugins contribute icons without patching `Sidebar`, and a missing
7
+ * name must fail predictably instead of rendering nothing.
8
+ *
9
+ * Resolution order: registrations (last write wins) → built-in lucide names →
10
+ * explicit fallback → `undefined`.
11
+ */
12
+ import type { Component } from 'svelte';
13
+ /** Minimal icon component contract used by navigation surfaces. */
14
+ export type IconComponent = Component<Record<string, unknown>>;
15
+ /** Handler invoked once per missing icon name. Keep it cheap: no throwing. */
16
+ export type IconMissHandler = (name: string) => void;
17
+ export interface IconRegistry {
18
+ /** Register or override icons by name. Names are matched verbatim. */
19
+ registerIcons(icons: Readonly<Record<string, IconComponent>>, options?: {
20
+ replace?: boolean;
21
+ }): void;
22
+ /** Replace the built-in vocabulary as well as registrations (design-system swap). */
23
+ replaceIcons(icons: Readonly<Record<string, IconComponent>>): void;
24
+ /** Resolve a name, optionally falling back to a caller-provided component. */
25
+ resolveIcon(name: string | undefined, fallback?: IconComponent): IconComponent | undefined;
26
+ hasIcon(name: string): boolean;
27
+ /** Registered names in registration order, built-ins first. */
28
+ getIconNames(): string[];
29
+ /** Component rendered when a name is missing; registration still wins. */
30
+ setIconFallback(icon: IconComponent | undefined): void;
31
+ /** Observe missing names (devtools bridge, warnings, telemetry). */
32
+ setIconMissHandler(handler: IconMissHandler | undefined): void;
33
+ /** Restore built-ins only; intended for tests. */
34
+ resetIconRegistry(): void;
35
+ }
36
+ export declare function createIconRegistry(builtinIcons?: Readonly<Record<string, IconComponent>>): IconRegistry;
@@ -0,0 +1,75 @@
1
+ export function createIconRegistry(builtinIcons = {}) {
2
+ const original = new Map(Object.entries(builtinIcons));
3
+ let builtin = new Map(original);
4
+ const registered = new Map();
5
+ const missing = new Set();
6
+ let fallback;
7
+ let onMiss;
8
+ let missCount = 0;
9
+ function reportMiss(name) {
10
+ // Bound the noise: one report per distinct name, and never more than 50.
11
+ if (!onMiss || missing.has(name) || missCount >= 50)
12
+ return;
13
+ missing.add(name);
14
+ missCount += 1;
15
+ try {
16
+ onMiss(name);
17
+ }
18
+ catch {
19
+ // A diagnostic hook must not break navigation rendering.
20
+ }
21
+ }
22
+ return {
23
+ registerIcons(icons, options = {}) {
24
+ if (!options.replace) {
25
+ for (const [name, icon] of Object.entries(icons)) {
26
+ if (name.trim() === '' || typeof icon !== 'function')
27
+ continue;
28
+ registered.set(name, icon);
29
+ }
30
+ return;
31
+ }
32
+ registered.clear();
33
+ for (const [name, icon] of Object.entries(icons)) {
34
+ if (name.trim() === '' || typeof icon !== 'function')
35
+ continue;
36
+ registered.set(name, icon);
37
+ }
38
+ },
39
+ replaceIcons(icons) {
40
+ builtin = new Map(Object.entries(icons).filter(([name, icon]) => name.trim() !== '' && typeof icon === 'function'));
41
+ registered.clear();
42
+ },
43
+ resolveIcon(name, fallbackIcon) {
44
+ if (name === undefined || name === '')
45
+ return fallbackIcon ?? fallback;
46
+ const direct = registered.get(name) ?? builtin.get(name);
47
+ if (direct)
48
+ return direct;
49
+ reportMiss(name);
50
+ return fallbackIcon ?? fallback;
51
+ },
52
+ hasIcon(name) {
53
+ return registered.has(name) || builtin.has(name);
54
+ },
55
+ getIconNames() {
56
+ return [...new Set([...builtin.keys(), ...registered.keys()])];
57
+ },
58
+ setIconFallback(icon) {
59
+ fallback = icon;
60
+ },
61
+ setIconMissHandler(handler) {
62
+ onMiss = handler;
63
+ missing.clear();
64
+ missCount = 0;
65
+ },
66
+ resetIconRegistry() {
67
+ builtin = new Map(original);
68
+ registered.clear();
69
+ fallback = undefined;
70
+ onMiss = undefined;
71
+ missing.clear();
72
+ missCount = 0;
73
+ },
74
+ };
75
+ }
@@ -0,0 +1,14 @@
1
+ import { type IconComponent } from './icon-registry.js';
2
+ /** Default icon vocabulary; keys are the documented string form. */
3
+ export declare const builtinIcons: Readonly<Record<string, IconComponent>>;
4
+ export declare const replaceIcons: (icons: Readonly<Record<string, IconComponent>>) => void;
5
+ export declare const registerIcons: (icons: Readonly<Record<string, IconComponent>>, options?: {
6
+ replace?: boolean;
7
+ }) => void;
8
+ export declare const resolveIcon: (name: string | undefined, fallback?: IconComponent) => IconComponent | undefined;
9
+ export declare const hasIcon: (name: string) => boolean;
10
+ export declare const getIconNames: () => string[];
11
+ export declare const setIconFallback: (icon: IconComponent | undefined) => void;
12
+ export declare const setIconMissHandler: (handler: import("./icon-registry.js").IconMissHandler | undefined) => void;
13
+ export declare const resetIconRegistry: () => void;
14
+ export type { IconComponent, IconMissHandler, IconRegistry } from './icon-registry.js';
package/dist/icons.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Built-in icon names for navigation and resource metadata.
3
+ *
4
+ * `MenuItem.icon` and `ResourceDefinition.icon` accept either a component or a
5
+ * string. This module owns the string → component mapping (lucide by default),
6
+ * so hosts and plugins can extend it through `registerIcons()` instead of
7
+ * editing `Sidebar`.
8
+ */
9
+ import { LayoutDashboard, FileText, Users, Settings, Home, Palette, Image as ImageIcon, Layout, Folder, Type, Video, Download, ListTodo, TrendingUp, Sparkles, Images, Bot, Key, KeyRound, CreditCard, BookOpen, Wrench, Repeat, ClipboardCheck, SlidersHorizontal, AlertTriangle, Mail, Map as MapIcon, MessageSquare, Send, ShoppingBag, Star, Briefcase, Building2, Calendar, Bell, Clock, Tag, Trash2, Shield, } from '@lucide/svelte';
10
+ import { createIconRegistry } from './icon-registry.js';
11
+ /** Default icon vocabulary; keys are the documented string form. */
12
+ export const builtinIcons = {
13
+ dashboard: LayoutDashboard,
14
+ posts: FileText,
15
+ file: FileText,
16
+ users: Users,
17
+ settings: Settings,
18
+ home: Home,
19
+ palette: Palette,
20
+ image: ImageIcon,
21
+ layout: Layout,
22
+ folder: Folder,
23
+ type: Type,
24
+ video: Video,
25
+ download: Download,
26
+ 'list-todo': ListTodo,
27
+ 'trending-up': TrendingUp,
28
+ sparkles: Sparkles,
29
+ images: Images,
30
+ bot: Bot,
31
+ key: Key,
32
+ 'key-round': KeyRound,
33
+ 'credit-card': CreditCard,
34
+ 'book-open': BookOpen,
35
+ wrench: Wrench,
36
+ repeat: Repeat,
37
+ 'clipboard-check': ClipboardCheck,
38
+ 'sliders-horizontal': SlidersHorizontal,
39
+ 'alert-triangle': AlertTriangle,
40
+ mail: Mail,
41
+ map: MapIcon,
42
+ 'message-square': MessageSquare,
43
+ send: Send,
44
+ 'shopping-bag': ShoppingBag,
45
+ star: Star,
46
+ briefcase: Briefcase,
47
+ building: Building2,
48
+ calendar: Calendar,
49
+ bell: Bell,
50
+ clock: Clock,
51
+ tag: Tag,
52
+ trash: Trash2,
53
+ shield: Shield,
54
+ };
55
+ const registry = createIconRegistry(builtinIcons);
56
+ export const replaceIcons = registry.replaceIcons;
57
+ export const registerIcons = registry.registerIcons;
58
+ export const resolveIcon = registry.resolveIcon;
59
+ export const hasIcon = registry.hasIcon;
60
+ export const getIconNames = registry.getIconNames;
61
+ export const setIconFallback = registry.setIconFallback;
62
+ export const setIconMissHandler = registry.setIconMissHandler;
63
+ export const resetIconRegistry = registry.resetIconRegistry;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export { surfaceDesignContract } from "./design-contract.js";
2
2
  export type { AdminPageFamily, AdminPageState, SurfaceDensity, SurfaceTone } from "./design-contract.js";
3
3
  export { designSystemComponents, type DesignComponentContract, type DesignComponentId, type DesignComponentState, } from "./design-system-components.js";
4
4
  export { metricSurfaceClasses, tableSurfaceClasses } from "./design-system.js";
5
+ export { builtinIcons, getIconNames, hasIcon, registerIcons, replaceIcons, resetIconRegistry, resolveIcon, setIconFallback, setIconMissHandler, } from "./icons.js";
6
+ export type { IconComponent, IconMissHandler, IconRegistry } from "./icons.js";
5
7
  export { default as AdminApp } from './components/AdminApp.svelte';
6
8
  export type { AdminPageRoute } from './components/AdminApp.svelte';
7
9
  export { default as AutoTable } from './components/AutoTable.svelte';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  export { surfaceDesignContract } from "./design-contract.js";
3
3
  export { designSystemComponents, } from "./design-system-components.js";
4
4
  export { metricSurfaceClasses, tableSurfaceClasses } from "./design-system.js";
5
+ export { builtinIcons, getIconNames, hasIcon, registerIcons, replaceIcons, resetIconRegistry, resolveIcon, setIconFallback, setIconMissHandler, } from "./icons.js";
5
6
  // Entry component
6
7
  export { default as AdminApp } from './components/AdminApp.svelte';
7
8
  // Admin components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/ui",
3
- "version": "0.110.0",
3
+ "version": "0.111.0",
4
4
  "description": "Pre-built admin UI components — AdminApp, AutoTable, AutoForm, Sidebar, Layout",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -88,7 +88,7 @@
88
88
  "@codemirror/lang-json": "^6.0.0",
89
89
  "@codemirror/lang-markdown": "^6.0.0",
90
90
  "@codemirror/lang-sql": "^6.0.0",
91
- "@svadmin/core": "^0.71.0",
91
+ "@svadmin/core": "^0.73.0",
92
92
  "@tanstack/svelte-query": "^6.1.48",
93
93
  "codemirror": "^6.0.0",
94
94
  "dashjs": "^4.7.4",
@@ -151,7 +151,7 @@
151
151
  }
152
152
  },
153
153
  "dependencies": {
154
- "@svadmin/devtools": "^0.6.0",
154
+ "@svadmin/devtools": "^0.6.2",
155
155
  "@svadmin/devtools-contract": "^0.3.1",
156
156
  "@vibeunion/devtools-devframe": "^0.1.0",
157
157
  "typebox": "^1.3.34",
@@ -189,7 +189,7 @@
189
189
  "@codemirror/lang-markdown": "^6.5.2",
190
190
  "@codemirror/lang-sql": "^6.10.0",
191
191
  "@happy-dom/global-registrator": "^20.11.12",
192
- "@svadmin/ai-elements": "^0.13.7",
192
+ "@svadmin/ai-elements": "^0.13.9",
193
193
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
194
194
  "@tailwindcss/cli": "4.3.3",
195
195
  "@testing-library/dom": "^10.4.1",