soma-kit 0.1.7 → 0.1.10

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.
@@ -0,0 +1,184 @@
1
+ // 跨领域标准业务组件模板库(domain-templates.ts)
2
+ // 承接来自企业级与各行业场景的 8 个高频跨领域标准业务组件模板:
3
+ // 1. KanbanBoardDesk(敏捷泳道看板工作台:roles filter? + board + summary?)
4
+ // 2. ScheduleGanttDesk(里程碑甘特排期工作台:roles filter? + schedule + milestones?)
5
+ // 3. JobQueueMonitor(异步任务队列与执行日志调度台:roles metrics? + queue + logs?)
6
+ // 4. BulkMergeDesk(批量编辑与重复记录合并去重台:roles candidates + comparison + target?)
7
+ // 5. RuleEngineDesk(可视化规则引擎与流程编排台:roles catalog? + rules + simulation?)
8
+ // 6. CapacityScheduleDesk(排班轮值与资源容量看板:roles filter? + capacity + rotation?)
9
+ // 7. TraceDiagnosticDesk(调用链瀑布流与服务拓扑诊断台:roles topology? + traces + spans?)
10
+ // 8. TicketServiceDesk(全渠道工单客服与协同评论台:roles queue + ticket + comments?)
11
+
12
+ import { defineKitBizComponent } from "../define";
13
+ import type { KitBizContext, KitBizDefinition, KitBizInput, KitBizRole } from "../types";
14
+ import type { KitFragment } from "../../compile/fragment";
15
+ import type { KitObject } from "../../object-renderer/types";
16
+ import { emitObject } from "../../object-renderer/emit-object";
17
+ import { addEmit, classesIn, isRec, newParts } from "../link/shared";
18
+ import { checkAreas, finishTemplate, templateObjectName } from "./shared";
19
+
20
+ function compileDomainTemplate(
21
+ input: KitBizInput,
22
+ ctx: KitBizContext,
23
+ kind: string,
24
+ roleDefs: Record<string, KitBizRole>,
25
+ areas: readonly string[],
26
+ ): KitFragment {
27
+ const out = newParts([]);
28
+ const fail = (code: string, message: string, path: string): void => {
29
+ out.diagnostics.push({ code, message, path });
30
+ };
31
+
32
+ // 1. 检查必填角色
33
+ for (const [rName, rDef] of Object.entries(roleDefs)) {
34
+ if (rDef.required) {
35
+ const raw = input.objects[rName];
36
+ if (!isRec(raw)) {
37
+ fail("KIT-BIZ-001", `${kind} 缺少必填对象角色槽 ${rName}`, `product.objects.${rName}`);
38
+ }
39
+ }
40
+ }
41
+
42
+ // 2. 检查区域类
43
+ checkAreas(input, kind, areas, out);
44
+ if (out.diagnostics.length > 0) return finishTemplate(out, "");
45
+
46
+ const areaClass = input.areaClass ?? {};
47
+ const sectionHtmls: string[] = [];
48
+
49
+ // 3. 逐个角色发射对象
50
+ for (const [rName] of Object.entries(roleDefs)) {
51
+ const raw = input.objects[rName];
52
+ if (!isRec(raw)) continue;
53
+
54
+ const objectName = templateObjectName(ctx.pageId, rName);
55
+ const hasFrom = isRec(raw.behavior) && raw.behavior.from !== undefined;
56
+
57
+ const emitRes = emitObject(
58
+ raw as unknown as KitObject,
59
+ {
60
+ object: objectName,
61
+ scope: `${objectName}_scope`,
62
+ registered: ctx.registeredComponents,
63
+ staticComponents: ctx.staticComponents,
64
+ },
65
+ {
66
+ registeredActions: ctx.registeredActions,
67
+ formMode: hasFrom ? "edit" : "create",
68
+ ...(hasFrom ? { formInitialPath: `page.data.${objectName}` } : {}),
69
+ },
70
+ );
71
+
72
+ addEmit(out, emitRes);
73
+
74
+ const customClass = areaClass[rName] ?? "";
75
+ const sectionClass = customClass ? ` ${customClass}` : "";
76
+ sectionHtmls.push(
77
+ `<section class="p-4 rounded-lg bg-surface border border-border-subtle${sectionClass}" data-soma-id="${objectName}__root">\n${emitRes.html}\n</section>`,
78
+ );
79
+ }
80
+
81
+ if (out.diagnostics.length > 0) return finishTemplate(out, "");
82
+
83
+ const rootClass = input.class ? ` ${input.class}` : "";
84
+ const html = `<div data-soma-id="${ctx.pageId}__${kind.toLowerCase()}_root" class="flex flex-col gap-4 p-4${rootClass}">\n${sectionHtmls.join("\n")}\n</div>`;
85
+
86
+ for (const c of classesIn(html)) out.candidates.add(c);
87
+ return finishTemplate(out, html);
88
+ }
89
+
90
+ // 1. 敏捷泳道看板工作台
91
+ export const KanbanBoardDesk: KitBizDefinition = defineKitBizComponent({
92
+ kind: "KanbanBoardDesk",
93
+ roles: {
94
+ filter: { required: false, views: ["filter", "form"] },
95
+ board: { required: true, views: ["list", "summary"] },
96
+ summary: { required: false, views: ["summary", "list"] },
97
+ },
98
+ areas: ["root", "filter", "board", "summary"],
99
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "KanbanBoardDesk", KanbanBoardDesk.roles, KanbanBoardDesk.areas),
100
+ });
101
+
102
+ // 2. 里程碑甘特排期工作台
103
+ export const ScheduleGanttDesk: KitBizDefinition = defineKitBizComponent({
104
+ kind: "ScheduleGanttDesk",
105
+ roles: {
106
+ filter: { required: false, views: ["filter", "form"] },
107
+ schedule: { required: true, views: ["list", "summary"] },
108
+ milestones: { required: false, views: ["list", "summary"] },
109
+ },
110
+ areas: ["root", "filter", "schedule", "milestones"],
111
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "ScheduleGanttDesk", ScheduleGanttDesk.roles, ScheduleGanttDesk.areas),
112
+ });
113
+
114
+ // 3. 异步任务队列与执行日志调度台
115
+ export const JobQueueMonitor: KitBizDefinition = defineKitBizComponent({
116
+ kind: "JobQueueMonitor",
117
+ roles: {
118
+ metrics: { required: false, views: ["summary", "list"] },
119
+ queue: { required: true, views: ["list", "summary"] },
120
+ logs: { required: false, views: ["list", "summary"] },
121
+ },
122
+ areas: ["root", "metrics", "queue", "logs"],
123
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "JobQueueMonitor", JobQueueMonitor.roles, JobQueueMonitor.areas),
124
+ });
125
+
126
+ // 4. 批量编辑与重复记录合并去重台
127
+ export const BulkMergeDesk: KitBizDefinition = defineKitBizComponent({
128
+ kind: "BulkMergeDesk",
129
+ roles: {
130
+ candidates: { required: true, views: ["list", "summary"] },
131
+ comparison: { required: true, views: ["list", "summary", "form"] },
132
+ target: { required: false, views: ["form", "summary"] },
133
+ },
134
+ areas: ["root", "candidates", "comparison", "target"],
135
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "BulkMergeDesk", BulkMergeDesk.roles, BulkMergeDesk.areas),
136
+ });
137
+
138
+ // 5. 可视化规则引擎与流程编排台
139
+ export const RuleEngineDesk: KitBizDefinition = defineKitBizComponent({
140
+ kind: "RuleEngineDesk",
141
+ roles: {
142
+ catalog: { required: false, views: ["list", "summary"] },
143
+ rules: { required: true, views: ["list", "summary", "form"] },
144
+ simulation: { required: false, views: ["form", "summary"] },
145
+ },
146
+ areas: ["root", "catalog", "rules", "simulation"],
147
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "RuleEngineDesk", RuleEngineDesk.roles, RuleEngineDesk.areas),
148
+ });
149
+
150
+ // 6. 排班轮值与资源容量看板
151
+ export const CapacityScheduleDesk: KitBizDefinition = defineKitBizComponent({
152
+ kind: "CapacityScheduleDesk",
153
+ roles: {
154
+ filter: { required: false, views: ["filter", "form"] },
155
+ capacity: { required: true, views: ["list", "summary"] },
156
+ rotation: { required: false, views: ["list", "summary"] },
157
+ },
158
+ areas: ["root", "filter", "capacity", "rotation"],
159
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "CapacityScheduleDesk", CapacityScheduleDesk.roles, CapacityScheduleDesk.areas),
160
+ });
161
+
162
+ // 7. 调用链瀑布流与服务拓扑诊断台
163
+ export const TraceDiagnosticDesk: KitBizDefinition = defineKitBizComponent({
164
+ kind: "TraceDiagnosticDesk",
165
+ roles: {
166
+ topology: { required: false, views: ["summary", "list"] },
167
+ traces: { required: true, views: ["list", "summary"] },
168
+ spans: { required: false, views: ["list", "summary"] },
169
+ },
170
+ areas: ["root", "topology", "traces", "spans"],
171
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "TraceDiagnosticDesk", TraceDiagnosticDesk.roles, TraceDiagnosticDesk.areas),
172
+ });
173
+
174
+ // 8. 全渠道工单客服与协同评论台
175
+ export const TicketServiceDesk: KitBizDefinition = defineKitBizComponent({
176
+ kind: "TicketServiceDesk",
177
+ roles: {
178
+ queue: { required: true, views: ["list", "summary"] },
179
+ ticket: { required: true, views: ["summary", "form", "list"] },
180
+ comments: { required: false, views: ["list", "summary"] },
181
+ },
182
+ areas: ["root", "queue", "ticket", "comments"],
183
+ compile: (input, ctx) => compileDomainTemplate(input, ctx, "TicketServiceDesk", TicketServiceDesk.roles, TicketServiceDesk.areas),
184
+ });
@@ -23,6 +23,8 @@ import { redirectFragment } from './redirect';
23
23
  import { guardRemoveActions } from './remove-guard';
24
24
  import { bizKinds, frameKinds, resolveBiz, resolveFrame } from './registry';
25
25
  import { checkPageStyleCoverage, collectPageCandidates, compileStyles } from './styles';
26
+ import type { KitAppTheme } from "../app/app-config";
27
+ import { resolveNineDimThemeCss } from "../theme/nine-dim-palettes";
26
28
  import type {
27
29
  KitAppContext,
28
30
  KitCompileResult,
@@ -59,6 +61,93 @@ export function stableHash(text: string): string {
59
61
 
60
62
  // ---------------------------------------------------------------- 第 1 步:校验
61
63
 
64
+
65
+ function escapeHtml(text: string): string {
66
+ return text
67
+ .replace(/&/g, "&amp;")
68
+ .replace(/</g, "&lt;")
69
+ .replace(/>/g, "&gt;")
70
+ .replace(/"/g, "&quot;")
71
+ .replace(/'/g, "&#39;");
72
+ }
73
+
74
+ function renderInheritedHeader(header: NonNullable<KitAppContext["layout"]>["header"]): string {
75
+ if (!header) return "";
76
+ let brandHtml = "";
77
+ if (header.brand?.text) {
78
+ const b = header.brand;
79
+ brandHtml = b.href
80
+ ? `<a href="${escapeHtml(b.href)}" class="font-semibold text-fg hover:text-primary transition-colors">${escapeHtml(b.text)}</a>`
81
+ : `<span class="font-semibold text-fg">${escapeHtml(b.text)}</span>`;
82
+ }
83
+
84
+ let navHtml = "";
85
+ if (header.nav && header.nav.length > 0) {
86
+ const navItems = header.nav.map((it) => {
87
+ const target = it.url ?? it.href ?? "#";
88
+ return `<a href="${escapeHtml(target)}" class="text-sm text-fg-muted hover:text-fg transition-colors">${escapeHtml(it.label)}</a>`;
89
+ }).join("\n");
90
+ navHtml = `<nav class="flex items-center gap-4">\n${navItems}\n</nav>`;
91
+ }
92
+
93
+ let actionsHtml = "";
94
+ if (header.actions && header.actions.length > 0) {
95
+ const actionItems = header.actions.map((it) => {
96
+ const target = it.url ?? it.href ?? "#";
97
+ return `<a href="${escapeHtml(target)}" class="text-sm font-medium text-fg hover:text-primary transition-colors">${escapeHtml(it.label)}</a>`;
98
+ }).join("\n");
99
+ actionsHtml = `<div class="flex items-center gap-3">\n${actionItems}\n</div>`;
100
+ }
101
+
102
+ const leftPart = [brandHtml, navHtml].filter(Boolean).join("\n");
103
+ return `<header data-kit-layout-header="true" class="border-b border-subtle bg-surface px-6 py-3 flex items-center justify-between gap-4">\n<div class="flex items-center gap-6">\n${leftPart}\n</div>\n${actionsHtml}\n</header>`;
104
+ }
105
+
106
+ function renderInheritedSidebar(sidebar: NonNullable<KitAppContext["layout"]>["sidebar"]): string {
107
+ if (!sidebar) return "";
108
+ let sidebarInner = "";
109
+ if (sidebar.title) {
110
+ sidebarInner += `<div class="mb-4 text-xs font-semibold uppercase tracking-wider text-fg-muted">${escapeHtml(sidebar.title)}</div>\n`;
111
+ }
112
+ if (sidebar.menu && sidebar.menu.length > 0) {
113
+ const menuItems = sidebar.menu.map((it) => {
114
+ const target = it.url ?? it.href ?? "#";
115
+ return `<a href="${escapeHtml(target)}" class="rounded px-2 py-1.5 text-sm text-fg hover:bg-surface transition-colors">${escapeHtml(it.label)}</a>`;
116
+ }).join("\n");
117
+ sidebarInner += `<nav class="flex flex-col gap-1">\n${menuItems}\n</nav>`;
118
+ }
119
+ return sidebarInner;
120
+ }
121
+
122
+ function renderInheritedFooter(footer: NonNullable<KitAppContext["layout"]>["footer"]): string {
123
+ if (!footer) return "";
124
+ const textHtml = footer.text ? `<span>${escapeHtml(footer.text)}</span>` : "<span></span>";
125
+ let linksHtml = "";
126
+ if (footer.links && footer.links.length > 0) {
127
+ const linkItems = footer.links.map((link) => {
128
+ return `<a href="${escapeHtml(link.href)}" class="hover:text-fg transition-colors">${escapeHtml(link.label)}</a>`;
129
+ }).join("\n");
130
+ linksHtml = `<div class="flex items-center gap-4">\n${linkItems}\n</div>`;
131
+ }
132
+ return `<footer data-kit-layout-footer="true" class="border-t border-subtle bg-surface-sunken px-6 py-3 text-xs text-fg-muted flex items-center justify-between gap-4">\n${textHtml}\n${linksHtml}\n</footer>`;
133
+ }
134
+
135
+ function renderInheritedLayout(framedHtml: string, layout: NonNullable<KitAppContext["layout"]>): string {
136
+ const headerHtml = layout.header ? renderInheritedHeader(layout.header) : "";
137
+ let bodyHtml = framedHtml;
138
+ if (layout.sidebar !== undefined) {
139
+ const sidebarContent = renderInheritedSidebar(layout.sidebar);
140
+ bodyHtml = `<div class="flex min-h-screen"><aside data-kit-layout-sidebar="true" class="w-56 shrink-0 border-r border-subtle bg-surface-sunken p-4">\n${sidebarContent}\n</aside><div class="flex-1 min-w-0">\n${framedHtml}\n</div></div>`;
141
+ }
142
+ const footerHtml = layout.footer ? renderInheritedFooter(layout.footer) : "";
143
+ const parts = [headerHtml, bodyHtml, footerHtml].filter(Boolean);
144
+ return `<div data-kit-inherited-layout="true">\n${parts.join("\n")}\n</div>`;
145
+ }
146
+
147
+ function compileThemeRootCss(theme: KitAppTheme): string {
148
+ return resolveNineDimThemeCss(theme);
149
+ }
150
+
62
151
  function checkClassesAt(decl: KitPageDecl, out: KitDiagnostic[]): void {
63
152
  const f = decl.frame;
64
153
  out.push(...checkClasses(f.class, 'frame.class'));
@@ -314,11 +403,59 @@ async function compileKitPageCore(page: unknown, app: KitAppContext): Promise<Ki
314
403
  const crossDiagnostics = mergeFragments(...allFragments).diagnostics;
315
404
  if (crossDiagnostics.length > 0) return { diagnostics: crossDiagnostics };
316
405
 
406
+ // 9 维正交页面主题 DSL(theme)
407
+ const appTheme = (app as { appConfig?: { theme?: KitAppTheme }; theme?: KitAppTheme; themeConfig?: KitAppTheme }).appConfig?.theme
408
+ ?? (app as { theme?: KitAppTheme }).theme
409
+ ?? ((app as { themeConfig?: KitAppTheme }).themeConfig);
410
+
411
+ const is9DimTheme = Boolean(
412
+ appTheme && (
413
+ appTheme.palette !== undefined ||
414
+ appTheme.color_depth !== undefined ||
415
+ appTheme.colorDepth !== undefined ||
416
+ appTheme.color_saturation !== undefined ||
417
+ appTheme.colorSaturation !== undefined ||
418
+ appTheme.font_family !== undefined ||
419
+ appTheme.fontFamily !== undefined ||
420
+ appTheme.font_scale !== undefined ||
421
+ appTheme.fontScale !== undefined ||
422
+ appTheme.boundary !== undefined ||
423
+ appTheme.shape !== undefined ||
424
+ appTheme.surface_texture !== undefined ||
425
+ appTheme.surfaceTexture !== undefined ||
426
+ appTheme.density === "COMPACT_DENSE" ||
427
+ appTheme.density === "STANDARD_BALANCED" ||
428
+ appTheme.density === "SPACIOUS_AIRY"
429
+ )
430
+ );
431
+
432
+ // 继承应用级默认布局(layout)
433
+ const appLayout = app.layout;
434
+ const shouldInheritLayout =
435
+ appLayout !== undefined &&
436
+ decl.page.inheritLayout !== false &&
437
+ decl.page.redirect === undefined &&
438
+ decl.frame.kind !== "blank-frame" &&
439
+ decl.frame.kind !== "workspace-frame";
440
+
441
+ if (shouldInheritLayout) {
442
+ if (decl.page.maxWidth === undefined && appLayout.maxWidth !== undefined && (decl.frame.kind === "single-frame" || decl.frame.kind === "top-main-frame")) {
443
+ decl.page.maxWidth = appLayout.maxWidth;
444
+ }
445
+ if (decl.page.sticky === undefined && appLayout.stickyHeader !== undefined) {
446
+ decl.page.sticky = appLayout.stickyHeader;
447
+ }
448
+ }
449
+
317
450
  // 第 3 步:装入页面框
318
451
  const frameInput: KitFrameInput = { page: decl.page, slots: slotFragments };
319
452
  frameInput.registeredActions = app.registeredActions;
320
453
  frameInput.locale = pageLocale;
321
- if (app.themeConfig?.density !== undefined) frameInput.density = app.themeConfig.density;
454
+ if (is9DimTheme && appTheme?.density !== undefined) {
455
+ frameInput.density = (appTheme.density === "COMPACT_DENSE" || appTheme.density === "compact") ? "compact" : "standard";
456
+ } else if (app.themeConfig?.density !== undefined) {
457
+ frameInput.density = (app.themeConfig.density === "COMPACT_DENSE" || app.themeConfig.density === "compact") ? "compact" : "standard";
458
+ }
322
459
  if (decl.frame.class !== undefined) frameInput.class = decl.frame.class;
323
460
  if (decl.frame.slotClass !== undefined) frameInput.slotClass = decl.frame.slotClass;
324
461
  if (decl.frame.config !== undefined) frameInput.config = decl.frame.config;
@@ -388,15 +525,23 @@ async function compileKitPageCore(page: unknown, app: KitAppContext): Promise<Ki
388
525
  // 第 4 步:候选类(片段 + HTML + 基础 / 数据组件自带 + 应用组件)
389
526
  const langAttr = pageLocale !== '' ? ` lang="${pageLocale}"` : '';
390
527
  const dirAttr = pageDir !== undefined && (pageLocale !== '' || decl.page.dir !== undefined) ? ` dir="${pageDir}"` : '';
391
- const html = `<div data-soma-host="${KIT_ROOT_HOST}"${langAttr}${dirAttr}>\n${framed.html}\n</div>`;
528
+ const pageContent = shouldInheritLayout && (appLayout.header !== undefined || appLayout.sidebar !== undefined || appLayout.footer !== undefined)
529
+ ? renderInheritedLayout(framed.html, appLayout)
530
+ : framed.html;
531
+ const themeAttrs = is9DimTheme && appTheme
532
+ ? ` data-kit-palette="${appTheme.palette ?? "CLASSIC_TECH_BLUE"}" data-kit-boundary="${appTheme.boundary ?? "HAIRLINE_BORDER"}" data-kit-shape="${appTheme.shape ?? "STANDARD_ROUNDED"}" data-kit-texture="${appTheme.surface_texture ?? appTheme.surfaceTexture ?? "SOLID_MATTE"}" data-kit-density="${appTheme.density ?? "STANDARD_BALANCED"}"`
533
+ : "";
534
+ const html = `<div data-soma-host="${KIT_ROOT_HOST}"${themeAttrs}${langAttr}${dirAttr}>\n${pageContent}\n</div>`;
392
535
  const candidates = collectPageCandidates(framed, html, app);
393
536
  // 安全网:按页裁剪样式后,页面里出现的内置组件必须已并入候选类(漏登记在编译期报 KIT-STYLE-002)
394
537
  const coverage = checkPageStyleCoverage(framed, html, app);
395
538
  if (coverage.length > 0) return { diagnostics: coverage };
396
539
 
397
540
  // 第 5 步:样式 + 四件套
398
- const style = await compileStyles(candidates, app, blockTheme.css);
541
+ const themeRootCss = is9DimTheme && appTheme ? compileThemeRootCss(appTheme) : "";
542
+ const style = await compileStyles(candidates, app, `${themeRootCss ? `${themeRootCss}\n` : ""}${blockTheme.css}`);
399
543
  if (style.diagnostics.length > 0) return { diagnostics: style.diagnostics };
544
+ const finalCss = themeRootCss ? `${style.css}\n${themeRootCss}` : style.css;
400
545
 
401
546
  const envelope: Record<string, unknown> = { url: decl.page.url, title: decl.page.title };
402
547
  if (decl.page.subtitle !== undefined) envelope.subtitle = decl.page.subtitle;
@@ -466,7 +611,7 @@ async function compileKitPageCore(page: unknown, app: KitAppContext): Promise<Ki
466
611
  html,
467
612
  uiYaml,
468
613
  eventYaml,
469
- styles: [{ key: `kit-${style.digest}`, css: style.css }],
614
+ styles: [{ key: `kit-${style.digest}`, css: finalCss }],
470
615
  version: `kit-${stableHash(html + uiYaml + eventYaml + style.digest)}`,
471
616
  };
472
617
  return { artifact, diagnostics: [] };
@@ -264,6 +264,9 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
264
264
  shape('page.locale', 'page.locale 必须是语言标签(如 zh-CN / en / ar)', diagnostics);
265
265
  }
266
266
  if (rawDir !== undefined && rawDir !== 'ltr' && rawDir !== 'rtl') shape('page.dir', 'page.dir 只许 ltr / rtl', diagnostics);
267
+ if (page.inherit_layout !== undefined && typeof page.inherit_layout !== 'boolean') {
268
+ shape('page.inherit_layout', 'page.inherit_layout 必须是布尔值', diagnostics);
269
+ }
267
270
  if (raw.locales !== undefined) {
268
271
  const lc = raw.locales;
269
272
  const ok = isRecord(lc) && Object.values(lc).every((t) => isRecord(t) && Object.values(t).every((s) => typeof s === 'string'));
@@ -277,6 +280,7 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
277
280
  if (typeof eyebrow === 'string' && eyebrow !== '') meta.eyebrow = eyebrow;
278
281
  if (Array.isArray(roles)) meta.roles = roles.filter((r): r is string => typeof r === 'string');
279
282
  if (crumbs !== undefined && crumbs.length > 0) meta.breadcrumbs = crumbs;
283
+ if (typeof page.inherit_layout === 'boolean') meta.inheritLayout = page.inherit_layout;
280
284
  if (redirectDecl !== undefined) meta.redirect = redirectDecl;
281
285
  Object.assign(meta, header);
282
286
  Object.assign(meta, parsePageParams(page, url, diagnostics));
@@ -44,7 +44,7 @@ export interface KitTabDecl {
44
44
 
45
45
  /** 解析后的页面声明 */
46
46
  export interface KitPageDecl {
47
- page: { url: string; title: string; subtitle?: string; eyebrow?: string; roles?: string[]; breadcrumbs?: Array<{ label: string; href?: string }>; redirect?: KitRedirectDecl; params?: Record<string, Record<string, unknown>>; query?: Record<string, Record<string, unknown>>; locale?: string; dir?: 'ltr' | 'rtl'; theme?: string | Record<string, unknown>; envelope?: import('../app/envelope').KitEnvelope } & Pick<import('../frames/types').KitPageMeta, 'actions' | 'back' | 'status' | 'statusFollow' | 'maxWidth' | 'sticky'>;
47
+ page: { url: string; title: string; subtitle?: string; eyebrow?: string; roles?: string[]; breadcrumbs?: Array<{ label: string; href?: string }>; redirect?: KitRedirectDecl; params?: Record<string, Record<string, unknown>>; query?: Record<string, Record<string, unknown>>; locale?: string; dir?: 'ltr' | 'rtl'; theme?: string | Record<string, unknown>; envelope?: import('../app/envelope').KitEnvelope; inheritLayout?: boolean } & Pick<import('../frames/types').KitPageMeta, 'actions' | 'back' | 'status' | 'statusFollow' | 'maxWidth' | 'sticky'>;
48
48
  frame: {
49
49
  kind: string;
50
50
  class?: string;
@@ -72,6 +72,10 @@ export interface KitAppContext {
72
72
  envelope?: import('../app/envelope').KitEnvelope;
73
73
  /** 整站主题声明(规整后的 kit.app.yaml#theme):块级主题求解以它为页面基底;缺省走 foundation 默认 */
74
74
  themeConfig?: import('../theme/theme-tokens').KitThemeConfig;
75
+ /** 整站 9 维正交主题声明(规整后的 kit.app.yaml#theme) */
76
+ theme?: import('../app/app-config').KitAppTheme;
77
+ /** 应用级默认页面布局继承配置(kit.app.yaml 的 layout:) */
78
+ layout?: import('../app/app-config').KitAppLayout;
75
79
  /** 应用扩展的业务组件(与内置同名需自行保证不重名;重名以应用的为准) */
76
80
  bizComponents?: Record<string, KitBizDefinition>;
77
81
  /** 应用扩展的页面框 */
package/src/data/embed.ts CHANGED
@@ -89,6 +89,7 @@ export interface KitSelectFieldOptions {
89
89
  /** 加在 Select 根上的类(如固定宽度 w-36;须已在调用方的候选类里) */
90
90
  className?: string;
91
91
  ariaLabel?: string;
92
+ name?: string;
92
93
  /** 用户选中后调(hidden 载体的 value 已更新) */
93
94
  onChange?(value: string): void;
94
95
  }
@@ -118,6 +119,7 @@ export function mountKitSelectField(opts: KitSelectFieldOptions): KitSelectField
118
119
  disabled: opts.disabled === true,
119
120
  searchable: opts.searchable === true,
120
121
  aria_label: opts.ariaLabel ?? '',
122
+ name: opts.name ?? '',
121
123
  class: opts.className ?? '',
122
124
  }, {
123
125
  change: (payload: { value?: unknown }) => {
@@ -19,10 +19,10 @@ export type KitMockupVariant = (typeof KIT_MOCKUP_VARIANTS)[number];
19
19
  const KEYS = ['url', 'title', 'text', 'image', 'alt', 'lines'] as const;
20
20
 
21
21
  const ROOT_CLASS = 'm-0 text-fg';
22
- const BROWSER_CLASS = 'flex w-full flex-col overflow-hidden rounded-lg border border-border bg-surface-sunken shadow-sm';
23
- const WINDOW_CLASS = 'flex w-full flex-col overflow-hidden rounded-lg border border-border bg-surface-sunken shadow-sm';
24
- const PHONE_CLASS = 'mx-auto flex w-64 flex-col gap-2 rounded-xl border border-border bg-surface-sunken p-2 shadow-md ring-2 ring-border-subtle';
25
- const CODE_CLASS = 'flex w-full flex-col overflow-hidden rounded-lg border border-border bg-surface-sunken shadow-sm';
22
+ const BROWSER_CLASS = 'flex w-full flex-col overflow-hidden rounded-lg border border-border-subtle bg-surface-sunken shadow-sm';
23
+ const WINDOW_CLASS = 'flex w-full flex-col overflow-hidden rounded-lg border border-border-subtle bg-surface-sunken shadow-sm';
24
+ const PHONE_CLASS = 'mx-auto flex w-64 flex-col gap-2 rounded-xl border border-border-subtle bg-surface-sunken p-2 shadow-md ring-2 ring-border-subtle';
25
+ const CODE_CLASS = 'flex w-full flex-col overflow-hidden rounded-lg border border-border-subtle bg-surface-sunken shadow-sm';
26
26
  const BAR_CLASS = 'flex items-center gap-3 border-b border-border-subtle px-3 py-2';
27
27
  const DOTS_CLASS = 'flex items-center gap-1.5';
28
28
  const DOT_CLASS = 'size-2.5 rounded-full bg-border';
@@ -36,11 +36,11 @@ const SLOT_END ='ms-auto flex shrink-0 items-center gap-2';
36
36
  const BRAND_CLASS = `flex min-w-0 cursor-pointer items-center gap-3 rounded-md ${FOCUS}`;
37
37
  const LOGO_CLASS = 'flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary text-sm font-semibold text-primary-fg';
38
38
  const BRAND_TEXT_CLASS = 'min-w-0 truncate text-base font-semibold text-fg';
39
- const MENU_BTN_CLASS = `inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-border bg-surface text-fg transition-colors hover:bg-surface-sunken @4xl:hidden ${FOCUS}`;
39
+ const MENU_BTN_CLASS = `inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-md bg-surface-raised text-fg shadow-xs transition-colors hover:bg-surface-sunken @4xl:hidden ${FOCUS}`;
40
40
  const BTN_BASE = `inline-flex h-9 items-center justify-center gap-2 rounded-md px-3 text-sm font-medium transition-colors ${FOCUS}`;
41
41
  const VARIANT_CLASS: Record<string, string> = {
42
42
  ghost: `${BTN_BASE} text-fg-muted hover:bg-surface-sunken hover:text-fg`,
43
- outline: `${BTN_BASE} border border-border bg-surface text-fg hover:bg-surface-sunken`,
43
+ outline: `${BTN_BASE} bg-surface-raised text-fg shadow-xs hover:bg-surface-sunken`,
44
44
  primary: `${BTN_BASE} bg-primary text-primary-fg hover:bg-primary-hover active:bg-primary-active`,
45
45
  };
46
46
  const DISABLED_CLASS = 'inline-flex h-9 cursor-not-allowed items-center justify-center gap-2 rounded-md px-3 text-sm font-medium text-fg-subtle opacity-60';
@@ -46,7 +46,7 @@ const FORM_COLS: Readonly<Record<number, string>> = Object.freeze({
46
46
  const ROOT_CLASS = 'flex flex-col gap-3';
47
47
  const TITLE_CLASS = 'text-sm font-semibold text-fg';
48
48
  const HINT_CLASS = 'text-xs text-fg-subtle';
49
- const HEAD_CLASS = 'grid grid-cols-12 items-center gap-2 border-b border-border px-2 py-2 text-xs font-medium text-fg-muted';
49
+ const HEAD_CLASS = 'grid grid-cols-12 items-center gap-2 border-b border-border-divider px-2 py-2 text-xs font-medium text-fg-muted';
50
50
  const ROW_CLASS = 'grid grid-cols-12 items-center gap-2 border-b border-border-subtle px-2 py-2';
51
51
  const CELL_CLASS = 'min-w-0 break-all text-sm text-fg';
52
52
  const CELL_MONO = 'min-w-0 break-all font-mono text-xs text-fg-muted';
@@ -60,7 +60,7 @@ const TEXTAREA_LIKE = 'font-mono';
60
60
  const ERROR_CLASS = 'text-sm text-danger-on-soft';
61
61
  const LIST_WRAP = 'flex flex-col';
62
62
  const NUM_ALIGN = 'text-end tabular-nums';
63
- const FOOTER_ROW_CLASS = 'grid grid-cols-12 items-center gap-2 border-t border-border px-2 py-2 text-sm font-semibold text-fg';
63
+ const FOOTER_ROW_CLASS = 'grid grid-cols-12 items-center gap-2 border-t border-border-divider px-2 py-2 text-sm font-semibold text-fg';
64
64
  const COUNT_CLASS = 'text-xs text-fg-subtle';
65
65
  const DATE_FIELD_CLASS = 'block h-9 w-full rounded-md border border-border bg-surface ps-3 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken';
66
66
 
@@ -597,7 +597,7 @@ const COND_CLASS = 'flex flex-col gap-1 rounded-md border border-border-subtle b
597
597
  const COND_ROW_CLASS = 'flex flex-wrap items-center gap-2';
598
598
  const CELL_CLASS = 'min-w-28 flex-1';
599
599
  const ERR_CLASS = 'text-xs text-danger-on-soft';
600
- const EMPTY_CLASS = 'rounded-md border border-dashed border-border px-3 py-3 text-center text-xs text-fg-subtle';
600
+ const EMPTY_CLASS = 'rounded-md border border-dashed border-border-subtle px-3 py-3 text-center text-xs text-fg-subtle';
601
601
  const SUMMARY_CLASS = 'rounded-md bg-surface-sunken px-3 py-2 text-sm text-fg-muted';
602
602
  const READONLY_CLASS = 'text-sm text-fg';
603
603
  const FOOT_CLASS = 'flex items-center justify-end gap-2';
@@ -84,7 +84,7 @@ export const TONE_SOLID: Readonly<Record<ShapeTone, string>> = Object.freeze({
84
84
  export const BADGE_BASE = 'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium';
85
85
 
86
86
  /** 空态:实线框 */
87
- export const EMPTY_CLASS = 'rounded-lg border border-dashed border-border bg-surface-sunken px-4 py-8 text-center text-sm text-fg-subtle';
87
+ export const EMPTY_CLASS = 'rounded-lg border border-dashed border-border-subtle bg-surface-sunken px-4 py-8 text-center text-sm text-fg-subtle';
88
88
 
89
89
  // ── 动作按钮 ─────────────────────────────────────────────────
90
90
 
@@ -247,6 +247,13 @@ function actionsOf(raw: unknown): ActionItem[] {
247
247
  return out;
248
248
  }
249
249
 
250
+ function stripBorderClasses(cls: string): string {
251
+ return cls
252
+ .split(/\s+/)
253
+ .filter((t) => t !== '' && t !== 'border' && t !== 'border-b' && t !== 'border-e' && t !== 'not-last:border-e' && !t.startsWith('border-border') && !t.startsWith('not-last:border-border'))
254
+ .join(' ');
255
+ }
256
+
250
257
  function rowKeyOf(row: unknown, keyField: string): string {
251
258
  if (!isRec(row)) return '';
252
259
  const v = row[keyField];
@@ -285,6 +292,7 @@ export function createKitTreeTable(): SomaComponentDefinition {
285
292
  actions: { type: 'array', default: [], desc: '行操作 [{ id, name, tone?, builtin?, target?, permission? }]' },
286
293
  actionsClass: { type: 'string', default: '', desc: '操作列跨度类' },
287
294
  pickOnRow: { type: 'boolean', default: false, desc: '点击行抛 row_action(builtin: select)' },
295
+ bordered: { type: 'boolean', default: true, desc: '是否显示边框(collection.bordered: false 时移除边框类)' },
288
296
  expandAllLabel: { type: 'string', default: '', desc: '工具条按钮文案' },
289
297
  collapseAllLabel: { type: 'string', default: '', desc: '工具条按钮文案' },
290
298
  moreLabel: { type: 'string', default: '', desc: '分批渲染的追加按钮文案' },
@@ -497,7 +505,8 @@ export function createKitTreeTable(): SomaComponentDefinition {
497
505
 
498
506
  const anyBranch = flattenTree(forest).some((n) => n.children.length > 0 || n.lazy);
499
507
  if (c.expandAll && anyBranch) {
500
- const bar = mk('div', TOOLBAR_CLASS);
508
+ const barClass = p.bordered === false ? stripBorderClasses(TOOLBAR_CLASS) : TOOLBAR_CLASS;
509
+ const bar = mk('div', barClass);
501
510
  const expandBtn = mk('button', TOOLBAR_BUTTON_CLASS, str(p.expandAllLabel, kitText('soma.kit.expand_all', undefined, ctx.host)));
502
511
  expandBtn.setAttribute('type', 'button');
503
512
  expandBtn.setAttribute('data-kit-expand-all', '');
@@ -534,7 +543,8 @@ export function createKitTreeTable(): SomaComponentDefinition {
534
543
  if (picked) row.setAttribute('data-kit-selected', '');
535
544
 
536
545
  if (mode === 'single' || mode === 'multi') {
537
- const cell = mk('div', str(p.selectClass));
546
+ const selectClass = p.bordered === false ? stripBorderClasses(str(p.selectClass)) : str(p.selectClass);
547
+ const cell = mk('div', selectClass);
538
548
  cell.setAttribute('role', 'gridcell');
539
549
  const box = createCheck(doc(), mode === 'single' ? 'radio' : 'checkbox', { checked: picked });
540
550
  box.setAttribute('data-kit-sel', '');
@@ -543,7 +553,8 @@ export function createKitTreeTable(): SomaComponentDefinition {
543
553
  row.appendChild(cell);
544
554
  }
545
555
  cols.forEach((col) => {
546
- const cell = mk('div', col.cellClass);
556
+ const cellClass = p.bordered === false ? stripBorderClasses(col.cellClass) : col.cellClass;
557
+ const cell = mk('div', cellClass);
547
558
  cell.setAttribute('role', 'gridcell');
548
559
  const content = cellContent(col, n.row);
549
560
  if (col.field === c.indentField) {
@@ -102,6 +102,13 @@ function actionsOf(raw: unknown): ActionItem[] {
102
102
  return out;
103
103
  }
104
104
 
105
+ function stripBorderClasses(cls: string): string {
106
+ return cls
107
+ .split(/\s+/)
108
+ .filter((t) => t !== "" && t !== "border" && t !== "border-b" && t !== "border-e" && t !== "not-last:border-e" && !t.startsWith("border-border") && !t.startsWith("not-last:border-border"))
109
+ .join(" ");
110
+ }
111
+
105
112
  function rowKeyOf(row: unknown, keyField: string): string {
106
113
  if (!isRec(row)) return '';
107
114
  const v = row[keyField];
@@ -133,6 +140,7 @@ export function createKitVirtualRows(): SomaComponentDefinition {
133
140
  actions: { type: 'array', default: [], desc: '行操作 [{ id, name, tone?, builtin?, target?, permission?, when? }]' },
134
141
  actionsClass: { type: 'string', default: '', desc: '操作列跨度类' },
135
142
  pickOnRow: { type: 'boolean', default: false, desc: '点击行抛 row_action(builtin: select)' },
143
+ bordered: { type: 'boolean', default: true, desc: '是否显示边框(collection.bordered: false 时移除边框类)' },
136
144
  label: { type: 'string', default: '', desc: '表格的可访问名(aria-label)' },
137
145
  colCount: { type: 'number', default: 0, desc: '总列数(含选择列 / 操作列),aria-colcount 用;0 = 按 cells 与选择 / 操作推出' },
138
146
  class: CLASS_PROP,
@@ -291,7 +299,9 @@ export function createKitVirtualRows(): SomaComponentDefinition {
291
299
  if (m !== 'none') el.setAttribute('aria-selected', picked ? 'true' : 'false');
292
300
  if (picked) el.setAttribute('data-kit-selected', '');
293
301
  if (m === 'single' || m === 'multi') {
294
- const cell = mk('div', withoutPy(str(p.selectClass)));
302
+ const rawSelect = withoutPy(str(p.selectClass));
303
+ const selectClass = p.bordered === false ? stripBorderClasses(rawSelect) : rawSelect;
304
+ const cell = mk('div', selectClass);
295
305
  cell.setAttribute('role', 'gridcell');
296
306
  const box = createCheck(doc(), m === 'single' ? 'radio' : 'checkbox', { checked: picked });
297
307
  box.setAttribute('data-kit-sel', '');
@@ -300,7 +310,9 @@ export function createKitVirtualRows(): SomaComponentDefinition {
300
310
  el.appendChild(cell);
301
311
  }
302
312
  for (const col of cells()) {
303
- const cell = mk('div', withoutPy(col.cellClass));
313
+ const rawCell = withoutPy(col.cellClass);
314
+ const cellClass = p.bordered === false ? stripBorderClasses(rawCell) : rawCell;
315
+ const cell = mk('div', cellClass);
304
316
  cell.setAttribute('role', 'gridcell');
305
317
  cell.setAttribute('data-kit-col', col.field);
306
318
  if (col.ellipsis) cell.setAttribute('data-kit-ellipsis', '');
@@ -310,7 +322,9 @@ export function createKitVirtualRows(): SomaComponentDefinition {
310
322
  }
311
323
  const actions = actionsOf(p.actions).filter((a) => (a.permission === '' || check === null || check(a.permission)) && holds(a.when, row));
312
324
  if (actionsOf(p.actions).length > 0) {
313
- const cell = mk('div', withoutPy(str(p.actionsClass)));
325
+ const rawActions = withoutPy(str(p.actionsClass));
326
+ const actionsClass = p.bordered === false ? stripBorderClasses(rawActions) : rawActions;
327
+ const cell = mk('div', actionsClass);
314
328
  cell.setAttribute('role', 'gridcell');
315
329
  const box = mk('div', ACTIONS_CELL_CLASS);
316
330
  for (const a of actions) {