soma-kit 0.1.18 → 0.1.19

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.
Files changed (53) hide show
  1. package/package.json +1 -1
  2. package/spec/generated/kit-page.schema.json +11 -1
  3. package/spec/kit-grammar.json +133 -13
  4. package/spec/kit-grammar.schema.json +4 -0
  5. package/src/app/component-gate.ts +247 -16
  6. package/src/app/index.ts +4 -1
  7. package/src/app/kit-view-context.ts +44 -2
  8. package/src/app/server.ts +11 -2
  9. package/src/biz/compose.ts +66 -0
  10. package/src/biz/define.ts +8 -0
  11. package/src/biz/index.ts +1 -0
  12. package/src/biz/layout-contracts.ts +119 -4
  13. package/src/biz/link/hub.ts +31 -0
  14. package/src/biz/master-sub/compile.ts +45 -3
  15. package/src/biz/master-sub/index.ts +3 -1
  16. package/src/biz/record-detail/compile.ts +120 -10
  17. package/src/biz/shared/coordinator.ts +245 -48
  18. package/src/biz/shared/index.ts +5 -1
  19. package/src/biz/shared/object-aliases.ts +14 -3
  20. package/src/biz/shared/overlay-compile.ts +56 -5
  21. package/src/biz/shared/overlay-shell.ts +5 -2
  22. package/src/biz/shared/page-form.ts +9 -5
  23. package/src/biz/shared/page-overlay-host.ts +126 -0
  24. package/src/biz/shared/page-overlay-names.ts +27 -0
  25. package/src/biz/shared/runtime-hub.ts +37 -2
  26. package/src/biz/single-form/compile.ts +60 -5
  27. package/src/biz/single-form/index.ts +2 -1
  28. package/src/biz/standard-crud/compile.ts +9 -2
  29. package/src/biz/types.ts +18 -0
  30. package/src/cli/kit-cli.ts +1 -0
  31. package/src/cli/view-writes.ts +130 -3
  32. package/src/compile/compile-page.ts +49 -4
  33. package/src/compile/page-pipeline.ts +4 -0
  34. package/src/compile/parse.ts +14 -0
  35. package/src/compile/stages.ts +5 -4
  36. package/src/compile/types.ts +1 -1
  37. package/src/compile/view-check.ts +49 -17
  38. package/src/data/comment-thread.ts +78 -18
  39. package/src/data/navbar.ts +4 -0
  40. package/src/data/object-form.ts +17 -3
  41. package/src/data/prompt-dialog.ts +102 -15
  42. package/src/frames/page-header.ts +11 -2
  43. package/src/frames/shared.ts +6 -0
  44. package/src/frames/types.ts +2 -0
  45. package/src/generated/kit-grammar-runtime.ts +43 -5
  46. package/src/i18n/kit-text.ts +1 -0
  47. package/src/object-renderer/request-actions.ts +145 -17
  48. package/src/object-renderer/types.ts +7 -0
  49. package/src/shared/dom-attrs-registry.ts +5 -3
  50. package/src/shared/dom-attrs.ts +2 -0
  51. package/src/spatial/declared-actions.ts +6 -3
  52. package/src/spatial/emit.ts +1 -1
  53. package/src/spatial/expand.ts +7 -2
package/src/biz/define.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  import type { KitBizDefinition } from './types';
6
6
  import { kitFail } from '../shared/kit-error';
7
+ import { kitLayoutContractProblems } from './layout-contracts';
7
8
 
8
9
  const KIND = /^[A-Z][A-Za-z0-9]*$/;
9
10
  const DEFINED_BIZ_COMPONENTS = new WeakSet<KitBizDefinition>();
@@ -48,6 +49,13 @@ export function defineKitBizComponent(def: KitBizDefinition): KitBizDefinition {
48
49
  if (typeof def.compile !== 'function') {
49
50
  kitFail('KIT-COMP-002', `bizComponents.${def.kind}.compile`, `业务组件 ${def.kind} 缺 compile()`, '提供 compile(input, ctx) 返回片段');
50
51
  }
52
+ // 版式契约(可选):与内置冻结表同一份不变量(kitLayoutContractProblems);不写或写 null = 不声明(页面线取 FREE,动作报 KIT-PAGE-GATE-006 告警)
53
+ if (def.layoutContract !== undefined && def.layoutContract !== null) {
54
+ const problems = kitLayoutContractProblems(def.kind, def.roles, def.layoutContract);
55
+ if (problems.length > 0) {
56
+ kitFail('KIT-COMP-007', `bizComponents.${def.kind}.layoutContract`, `业务组件 ${def.kind} 的版式契约不合法:${problems.join(';')}`, '契约角色键与 roles 一一相等、取值在闭集内、锚点拼法带 {page} / {object} 占位;用 kitLayoutContract({...}) 简写补缺省');
57
+ }
58
+ }
51
59
  DEFINED_BIZ_COMPONENTS.add(def);
52
60
  return def;
53
61
  }
package/src/biz/index.ts CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  import type { KitBizDefinition } from './types';
35
35
 
36
36
  export { defineKitBizComponent } from './define';
37
+ export { kitLayoutContract, kitLayoutContractProblems, type KitBizLayoutContract, type KitLayoutContractInput, type KitRoleLayout } from './layout-contracts';
37
38
  export { wrapKitBizComponent, composeKitBizComponents } from './compose';
38
39
  export type { WrapBizOptions, WrapBizShellContext, ComposeBizPart, ComposeBizOptions, ComposeBizShellContext } from './compose';
39
40
  export type {
@@ -5,10 +5,13 @@
5
5
  // 版面事实依据 compile/stages.ts 的 derivePageEnvelopeFacts 与各业务组件声明的版心特征(envelope)。
6
6
  // 栅格份数的出处(grid,SCON-151 构成同源)也登记在这里:模板交给构成求解的输入与页面线交给构成求解的输入走本文件同一个构造函数
7
7
  // (kitBoardPanelFacts / kitBoardCompositionNodes / kitDomainRegions / kitDomainCompositionInput),份数只有这一个出处。
8
- // 只 import shared/page-attrs 与排布门面的类型(构成节点 / 构成计划)和列表栏份数一个常量:spatial/ 从 biz/ 只许读本文件,不能借它把具体组件目录带进来。
8
+ // 只 import shared/page-attrs(类型与闭集,契约校验 kitLayoutContractProblems 用)、排布门面的类型(构成节点 / 构成计划)和列表栏份数一个常量:
9
+ // spatial/ 从 biz/ 只许读本文件,不能借它把具体组件目录带进来。
10
+ // 应用业务组件也可以声明契约(defineKitBizComponent({ layoutContract })):查表顺序为内置冻结表 → 应用声明(编排层传入)→ FREE。
9
11
 
10
12
  import type { CompositionNodeInput, CompositionPlan } from 'soma-foundation/arrange';
11
13
  import type { KitArrange, KitExclusive, KitFunc, KitIdentity, KitPresent, KitRegionKind, KitStripKind } from '../shared/page-attrs';
14
+ import { KIT_ARRANGES, KIT_EXCLUSIVES, KIT_FUNCS, KIT_IDENTITIES, KIT_PRESENTS } from '../shared/page-attrs';
12
15
  import { KIT_LIST_PANE_SPAN } from '../recipes/page-width';
13
16
 
14
17
  /** 声明里表示「这是一个数据对象」的公共键表(展开 / 动作计数 / 界面规则投影 / 层级求解 / 尺寸推导统一共用) */
@@ -740,6 +743,8 @@ export const KIT_BIZ_LAYOUT_CONTRACTS: Readonly<Record<string, KitBizLayoutContr
740
743
  subs: role('secondary', 'tab-face', { attachTo: 'record', exclusiveGroup: 'subs', memberPrefix: 'sub_', anchor: OBJ }),
741
744
  },
742
745
  exclusiveGroups: { subs: 'tabs', edit: 'swap' },
746
+ // 附加浮层(overlays.<名>)容器锚点:与 StandardCrud / MasterSub 同一拼法(共享 compileOverlay 在新模式下写 kitObjectAnchor(浮层对象))
747
+ overlayAnchor: OBJ,
743
748
  rootAnchor: '{page}__rd_root',
744
749
  frameFacts: facts('detail', { detail: true }),
745
750
  }),
@@ -912,7 +917,117 @@ export const KIT_FREE_LAYOUT_CONTRACT: KitBizLayoutContract = contract({
912
917
  frameFacts: facts('free'),
913
918
  });
914
919
 
915
- /** 未登记的业务组件(应用自定义)取缺省:不猜它的版式,交给识别按构成规则推 */
916
- export function kitBizLayoutContract(kind: string): KitBizLayoutContract {
917
- return Object.hasOwn(KIT_BIZ_LAYOUT_CONTRACTS, kind) ? KIT_BIZ_LAYOUT_CONTRACTS[kind]! : KIT_FREE_LAYOUT_CONTRACT;
920
+ /**
921
+ * 业务组件的版式契约:内置冻结表优先;其次应用业务组件在 defineKitBizComponent({ layoutContract }) 里声明的契约
922
+ * (extra:由编排层从 app.bizComponents 收集后传入,spatial/ 不 import 业务组件定义);都没有取缺省 FREE(不猜版式,交给识别按构成规则推)
923
+ */
924
+ export function kitBizLayoutContract(kind: string, extra?: Readonly<Record<string, KitBizLayoutContract>>): KitBizLayoutContract {
925
+ if (Object.hasOwn(KIT_BIZ_LAYOUT_CONTRACTS, kind)) return KIT_BIZ_LAYOUT_CONTRACTS[kind]!;
926
+ if (extra !== undefined && Object.hasOwn(extra, kind)) return extra[kind]!;
927
+ return KIT_FREE_LAYOUT_CONTRACT;
928
+ }
929
+
930
+ // ── 应用业务组件声明的版式契约(defineKitBizComponent({ layoutContract }))────────────────────────────
931
+
932
+ /** 应用声明契约的入参:frameFacts 只写差异(缺省同 FACTS),pageMode 必填 */
933
+ export type KitLayoutContractInput = Omit<KitBizLayoutContract, 'frameFacts'> & {
934
+ readonly frameFacts: Partial<Omit<KitBizLayoutContract['frameFacts'], 'pageMode'>> & { readonly pageMode: KitPageMode };
935
+ };
936
+
937
+ /** 应用声明契约的简写:frameFacts 只写差异(缺省同 FACTS),pageMode 必填;返回冻结的完整契约(合法性由 defineKitBizComponent 定义期校验) */
938
+ export function kitLayoutContract(c: KitLayoutContractInput): KitBizLayoutContract {
939
+ const { pageMode, ...over } = c.frameFacts;
940
+ return contract({
941
+ ...c,
942
+ roles: Object.fromEntries(Object.entries(c.roles).map(([k, r]) => [k, Object.freeze({ ...r })])),
943
+ frameFacts: facts(pageMode, over),
944
+ });
945
+ }
946
+
947
+ /** 页面模式的闭集(与 KitPageMode 一一对应;意图词表逐词对账见 tests/spatial/layout-contracts.test.ts) */
948
+ const PAGE_MODES: readonly KitPageMode[] = Object.freeze(['crud', 'master-detail', 'category', 'board', 'report', 'form', 'detail', 'steps', 'approval', 'settings', 'import', 'result', 'free'] as const);
949
+ const NAV_RAILS: readonly string[] = Object.freeze(['none', 'narrow', 'wide']);
950
+
951
+ const isPlainRec = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
952
+
953
+ /**
954
+ * 版式契约的不变量(冻结表单测 tests/spatial/layout-contracts.test.ts 与 defineKitBizComponent 定义期共用这一份判据)。
955
+ * roles:组件定义的角色表(契约角色键必须与它一一相等)。返回问题清单(空 = 合法),每条带组件名前缀。
956
+ * grid.by: domain 只供内置领域模板:只认 KIT_DOMAIN_TOPOLOGY 里的拓扑(包装 / 组合内置领域模板时原样继承的那份)
957
+ */
958
+ export function kitLayoutContractProblems(kind: string, roles: Readonly<Record<string, unknown>>, c: KitBizLayoutContract): string[] {
959
+ const out: string[] = [];
960
+ if (!isPlainRec(c) || !isPlainRec(c.roles) || !isPlainRec(c.frameFacts)) {
961
+ return [`${kind}:契约必须是对象,且含 roles 与 frameFacts(用 kitLayoutContract({...}) 构造)`];
962
+ }
963
+ const keys = Object.keys(c.roles).sort();
964
+ const want = Object.keys(roles).sort();
965
+ if (keys.join('|') !== want.join('|')) out.push(`契约角色键(${keys.join(' / ') || '无'})与组件角色键(${want.join(' / ') || '无'})不一致`);
966
+ if (!KIT_ARRANGES.includes(c.arrange)) out.push(`arrange "${String(c.arrange)}" 不在闭集`);
967
+ if (!KIT_EXCLUSIVES.includes(c.exclusive)) out.push(`exclusive "${String(c.exclusive)}" 不在闭集`);
968
+ if (typeof c.defaultSelected !== 'boolean') out.push('defaultSelected 必须是布尔');
969
+ if (c.exclusiveGroups !== undefined) {
970
+ const kinds = Object.values(c.exclusiveGroups);
971
+ for (const [g, e] of Object.entries(c.exclusiveGroups)) if (!KIT_EXCLUSIVES.includes(e)) out.push(`exclusiveGroups.${g} "${String(e)}" 不在闭集`);
972
+ if (!kinds.includes(c.exclusive)) out.push(`顶层 exclusive "${String(c.exclusive)}" 必须是 exclusiveGroups 里的一组`);
973
+ }
974
+ for (const [name, r] of Object.entries(c.roles)) {
975
+ if (!isPlainRec(r)) { out.push(`roles.${name} 必须是对象`); continue; }
976
+ if (!KIT_IDENTITIES.includes(r.identity)) out.push(`roles.${name}.identity "${String(r.identity)}" 不在闭集`);
977
+ if (r.present !== 'unset' && !KIT_PRESENTS.includes(r.present)) out.push(`roles.${name}.present "${String(r.present)}" 不在闭集`);
978
+ if (typeof r.inset !== 'boolean') out.push(`roles.${name}.inset 必须是布尔`);
979
+ if (r.attachTo !== undefined && (!Object.hasOwn(c.roles, r.attachTo) || r.attachTo === name)) out.push(`roles.${name}.attachTo 必须指向另一个已登记角色`);
980
+ if (r.exclusiveGroup !== undefined && c.exclusiveGroups !== undefined && !Object.hasOwn(c.exclusiveGroups, r.exclusiveGroup)) out.push(`roles.${name}.exclusiveGroup "${r.exclusiveGroup}" 未在 exclusiveGroups 登记`);
981
+ for (const f of r.defaultActions ?? []) if (!KIT_FUNCS.includes(typeof f === 'string' ? f : f.func)) out.push(`roles.${name}.defaultActions 含未知功能`);
982
+ for (const a of [r.anchor, r.editAnchor, ...Object.values(r.stripAnchors ?? {}), ...(r.rowActionAnchors ?? [])]) {
983
+ if (a !== undefined && (typeof a !== 'string' || (!a.includes('{page}') && !a.includes('{object}')))) out.push(`roles.${name} 的锚点拼法 "${String(a)}" 必须含 {page} 或 {object} 占位(同页多槽不撞)`);
984
+ }
985
+ }
986
+ const all = Object.values(c.roles).filter(isPlainRec);
987
+ const primaries = all.filter((r) => r.identity === 'primary').length;
988
+ if (primaries > 1 && !all.some((r) => r.identity === 'peers')) out.push('主对象(identity: primary)至多一个,除非另有平级组');
989
+ if (c.rootAnchor !== undefined && (typeof c.rootAnchor !== 'string' || !c.rootAnchor.includes('{page}'))) out.push('rootAnchor 必须含 {page} 占位');
990
+ if (c.overlayAnchor !== undefined && (typeof c.overlayAnchor !== 'string' || (!c.overlayAnchor.includes('{page}') && !c.overlayAnchor.includes('{object}')))) out.push('overlayAnchor 必须含 {page} 或 {object} 占位');
991
+ const ff = c.frameFacts;
992
+ if (!PAGE_MODES.includes(ff.pageMode)) out.push(`frameFacts.pageMode "${String(ff.pageMode)}" 不在闭集`);
993
+ if (!Number.isInteger(ff.panes) || ff.panes < 1) out.push('frameFacts.panes 必须是不小于 1 的整数');
994
+ if (!NAV_RAILS.includes(ff.navRail)) out.push(`frameFacts.navRail "${String(ff.navRail)}" 不在闭集(none / narrow / wide)`);
995
+ for (const k of ['stepper', 'reading', 'showcase', 'detail'] as const) if (typeof ff[k] !== 'boolean') out.push(`frameFacts.${k} 必须是布尔`);
996
+ if (c.grid !== undefined && c.grid.by === 'domain' && !Object.values(KIT_DOMAIN_TOPOLOGY).includes(c.grid.topology)) {
997
+ out.push('grid.by: domain 只供内置领域模板;应用组件用 fixed / board 或不写');
998
+ }
999
+ return out.map((m) => `${kind}:${m}`);
1000
+ }
1001
+
1002
+ /**
1003
+ * 把子部件的契约改写成复合组件里的样子(composeKitBizComponents 缺省合成契约用):
1004
+ * 子部件以 `${pageId}_${part}` 为前缀编译(compose.ts 的 subCtx),对象运行期名是 `<页>_<子部件>_<子角色>`(分组成员 `<页>_<子部件>_<成员前缀><成员名>`),
1005
+ * 而展开按复合组件的对外角色拼 `{object}`(`<页>_<对外角色>`)。所以锚点拼法里的 `{object}` 先按子角色写成字面前缀,`{page}` 换成 `{page}_<子部件>`;
1006
+ * 角色名按 roleMap 改名(未映射的可选角色不出现)、互斥组加子部件前缀。
1007
+ * 已知限制:对象渲染器的宿主锚点(工具条按钮、行操作等,KIT_HOST_ANCHOR_PATTERN)由展开按对外角色的运行期名拼,与子部件产物对不上,会报「没有落到产物上」的 KIT-PAGE-GATE-006
1008
+ */
1009
+ export function kitRebaseLayoutContract(
1010
+ c: KitBizLayoutContract, roleMap: Readonly<Record<string, string>>, part: string,
1011
+ ): { roles: Record<string, KitRoleLayout>; exclusiveGroups: Record<string, KitExclusive>; overlayAnchor?: string } {
1012
+ const rebase = (s: string, objectAs: string): string => s.split('{object}').join(objectAs).split('{page}').join(`{page}_${part}`);
1013
+ const roles: Record<string, KitRoleLayout> = {};
1014
+ for (const [inner, r] of Object.entries(c.roles)) {
1015
+ const outer = roleMap[inner];
1016
+ if (outer === undefined) continue; // 未映射的可选角色不出现在复合组件里
1017
+ // 子部件里这个角色对象的运行期名(改写前的拼法,下一步统一把 {page} 换成 {page}_<子部件>)
1018
+ const objectAs = r.memberPrefix !== undefined ? `{page}_${r.memberPrefix}{member}` : `{page}_${inner}`;
1019
+ const re = (s: string): string => rebase(s, objectAs);
1020
+ roles[outer] = Object.freeze({
1021
+ ...r,
1022
+ ...(r.attachTo !== undefined ? { attachTo: roleMap[r.attachTo] ?? r.attachTo } : {}),
1023
+ ...(r.exclusiveGroup !== undefined ? { exclusiveGroup: `${part}.${r.exclusiveGroup}` } : {}),
1024
+ ...(r.anchor !== undefined ? { anchor: re(r.anchor) } : {}),
1025
+ ...(r.editAnchor !== undefined ? { editAnchor: re(r.editAnchor) } : {}),
1026
+ ...(r.stripAnchors !== undefined ? { stripAnchors: Object.freeze(Object.fromEntries(Object.entries(r.stripAnchors).map(([k, v]) => [k, re(v)]))) } : {}),
1027
+ ...(r.rowActionAnchors !== undefined ? { rowActionAnchors: Object.freeze(r.rowActionAnchors.map((a) => re(a))) } : {}),
1028
+ });
1029
+ }
1030
+ const exclusiveGroups = Object.fromEntries(Object.entries(c.exclusiveGroups ?? {}).map(([g, e]) => [`${part}.${g}`, e]));
1031
+ // 附加浮层对象的运行期名是 `<页>_<浮层名>`(展开里 member = 浮层名)
1032
+ return { roles, exclusiveGroups, ...(c.overlayAnchor !== undefined ? { overlayAnchor: rebase(c.overlayAnchor, '{page}_{member}') } : {}) };
918
1033
  }
@@ -4,6 +4,7 @@
4
4
  // KitCoordinator focus 切片 owner:表单弹窗开关与初值、保存 / 重取 / 删除、kit_pick(写选中键与新建预填并重取)
5
5
  // KitLinkHub selection 切片 owner(MasterSub)或只读订阅者(CategoryCrud,分类树自己写):
6
6
  // · 行选中(语义事件 link_pick,载荷带整行)→ 写 selection;行数据到达时默认选首行(autoSelect);
7
+ // 页面指定了选中键(preferKey,MasterSub master.selectedFrom 绑地址参数)时先选主键等于它的行,找不到再回落首行;
7
8
  // · 选中项一变(不论谁写的):把依赖对象的 view 切片回第 1 页(经路径写者 `page`),等镜像落地后上抛 picked { id, item, prefill },
8
9
  // 页面再接 `SCOPE | window-reload`(MasterSub)或 `SCOPE | semantic kit_pick`(CategoryCrud,交给协调组件写预填并重取);
9
10
  // · 摘要字段动作(语义事件 link_field_<序号>):字段事件自己的载荷只有 { value },由本组件补上当前选中行后抛槽位事件 field_action_<序号> { value, row },
@@ -94,6 +95,15 @@ export function pickDefault(
94
95
  return JSON.stringify(next) === JSON.stringify(current) ? undefined : next;
95
96
  }
96
97
 
98
+ /**
99
+ * 页面指定的初始选中(MasterSub master.selectedFrom,绑地址参数):行里主键等于 prefer 的那一行;
100
+ * prefer 为空 / 行里没有它返回 undefined(调用方回落到 pickDefault 的现有行为)
101
+ */
102
+ export function pickPreferred(rows: readonly unknown[], prefer: string | null, keyField: string): Rec | undefined {
103
+ if (prefer === null || prefer === '') return undefined;
104
+ return rows.filter(isRec).find((r) => linkKeyOf(r, keyField) === prefer);
105
+ }
106
+
97
107
  /** 新建时的预填:关联键 = 当前选中项的主键 */
98
108
  export function createPrefill(selected: unknown, keyField: string, linkKey: string): Rec {
99
109
  if (linkKey === '' || keyField === '' || !isRec(selected)) return {};
@@ -122,6 +132,7 @@ export function createKitLinkHub(): SomaComponentDefinition {
122
132
  createObjects: { type: 'object', default: {}, desc: '新建保存成功回第 1 页后要发起第 1 页重取的映射(scopeId -> objectName);仅对原 view.page > 1 的作用域回页并重取' },
123
133
  pickSlots: { type: 'number', default: 0, desc: '选中项变化时依次抛 picked_0 … picked_<n-1> 的个数(每个依赖对象的重取各绑一个槽位;0 = 只抛 picked)' },
124
134
  watchFilters: { type: 'array', default: [], desc: '筛选条的作用域 id:它们的 filter 切片一变(每次提交 / 重置都算,值没变也算)就回第 1 页并上抛 picked,页面据此重取(MultiObjectBoard 的全局筛选)' },
135
+ preferKey: { type: 'string', default: '', desc: '页面指定的选中键(MasterSub master.selectedFrom 编成的页面路径绑定,如 page.query.task_id;值按字符串比对主键):行数据到达时选中主键等于它的行,找不到回落 autoSelect 的现有行为;它变化时重新对齐一次(用户点选后的行数据刷新不会被它拉回)' },
125
136
  },
126
137
  emits: {
127
138
  picked: { payload: { id: { type: 'string' }, item: { type: 'object' }, prefill: { type: 'object' } }, desc: '选中项变化(页面据此重取依赖对象)' },
@@ -292,6 +303,14 @@ export function createKitLinkHub(): SomaComponentDefinition {
292
303
  }));
293
304
  };
294
305
 
306
+ /** 页面指定的选中键(preferKey 绑地址参数,整数参数到这里是 number):空 / 未绑到值为 null */
307
+ const preferOf = (): string | null => {
308
+ const v = props().preferKey;
309
+ return typeof v === 'string' ? (v === '' ? null : v) : typeof v === 'number' && Number.isFinite(v) ? String(v) : null;
310
+ };
311
+ /** 已对齐过的页面指定键:同一个值只在首批非空行到达时对齐一次,之后行刷新不再把用户点选拉回;值变了(地址参数变化)再对齐一次 */
312
+ let appliedPrefer: string | null = null;
313
+
295
314
  const syncDefault = (): void => {
296
315
  const p = props();
297
316
  if (p.autoSelect !== true && p.autoSelect !== 'true') return;
@@ -300,6 +319,18 @@ export function createKitLinkHub(): SomaComponentDefinition {
300
319
  const rows = Array.isArray(p.rows) ? p.rows : [];
301
320
  const previous = lastRows;
302
321
  lastRows = rows;
322
+ const prefer = preferOf();
323
+ if (prefer === null) {
324
+ appliedPrefer = null;
325
+ } else if (prefer !== appliedPrefer && rows.some(isRec)) {
326
+ // 行到了才算对齐过:找到就选它,找不到回落下面的现有行为(保留仍在行里的当前项 / 首行)
327
+ appliedPrefer = prefer;
328
+ const hit = pickPreferred(rows, prefer, keyField());
329
+ if (hit !== undefined) {
330
+ if (JSON.stringify(hit) !== JSON.stringify(selectedOf(sel.get()))) setSelection(hit);
331
+ return;
332
+ }
333
+ }
303
334
  const next = pickDefault(rows, selectedOf(sel.get()), keyField(), p.afterRemove === 'next' ? { afterRemove: 'next', previous } : undefined);
304
335
  if (next !== undefined) setSelection(next);
305
336
  };
@@ -1,7 +1,9 @@
1
1
  // MasterSubWorkstation 编译:左栏主列表 + 右栏主对象摘要与多个从属对象(规格 5.3)。
2
2
  // 对象渲染全部交 emitObject;本文件只做壳和写死的协作链:
3
3
  //
4
- // 初次加载默认选中首条 KitLinkHub 的 rows(绑主列表行数据)到达时选首行
4
+ // 初次加载默认选中首条 KitLinkHub 的 rows(绑主列表行数据)到达时选首行;master.selectedFrom($page.params.* / $page.query.*)
5
+ // 编成枢纽 preferKey(页面路径绑定):先选主键相等的行,找不到回落首行,地址参数变化时再对齐;
6
+ // master.selectAction:枢纽 picked 事件接具名动作(如回写地址参数)
5
7
  // 切换选中行 行点击(pickOnRow,kit_action: select)-> SCOPE semantic link_pick -> 枢纽写 selection
6
8
  // -> 摘要读 selection 镜像(summaryPath);各从属对象 from.params 带关联键(link_sel_key);
7
9
  // 枢纽抛 picked -> 页面对每个从属对象 `SCOPE | window-reload` 并行重取(回第 1 页由枢纽经 page 路径写者完成)
@@ -31,7 +33,7 @@ import { OVERLAY_SHELL_CLASS, dialogHtml, dialogIds } from '../shared/overlay-sh
31
33
  import { applyFlowCopy } from '../shared/verbs';
32
34
  import { dialogWidthOf, editContainerOf } from '../../object-renderer/overlay-decide';
33
35
  import { PAGE_FORM_FOCUS_INITIAL, pageBrowsingMirror, wireMainPageForm } from '../shared/page-form';
34
- import { KIT_CRUD_LINK_KEY, adviseDialogFooter, compileOverlay, validateOverlayNames } from '../shared/overlay-compile';
36
+ import { KIT_CRUD_LINK_KEY, adviseDialogFooter, compileOverlay, isAutoRowlessOverlay, validateOverlayNames } from '../shared/overlay-compile';
35
37
  import type { KitAction } from '../../object-renderer/types';
36
38
  import { KIT_LINK_MIRRORS, KIT_NONE_PATH, KIT_SEL_PATH } from '../link/hub';
37
39
  import {
@@ -51,6 +53,9 @@ export function masterSubObjectName(pageId: string, role: string): string {
51
53
  return bizObjectName(pageId, role);
52
54
  }
53
55
 
56
+ /** master.selectedFrom 的合法写法:地址路径参数或查询参数(名与 page.params / page.query 的命名规则一致) */
57
+ const SELECTED_FROM = /^\$page\.(params|query)\.[a-z][a-z0-9_]{0,31}$/;
58
+
54
59
  /** 详情头记录卡的 map 占位键:数据里没有它,卡就不画对应项(标题 / 状态让给详情头) */
55
60
  const HEADLESS_KEY = '__ms_head__';
56
61
 
@@ -273,6 +278,34 @@ export function compileMasterSub(input: KitBizInput, ctx: KitBizContext): KitFra
273
278
  else if (!isStatic) fail('KIT-PAGE-001', `subs.${n} 是详情头成员,必须是写死形状组件(StatGroup / RecordCard 等 staticComponent)`, `product.objects.subs.${n}.view`);
274
279
  }
275
280
  }
281
+ // 页面指定的初始选中(selectedFrom:$page.params.<名> / $page.query.<名>)与选中变化后执行的具名动作(selectAction,如回写地址参数)
282
+ const selectedFromRaw = (rawMaster as Rec).selectedFrom;
283
+ let preferKey: string | undefined;
284
+ if (selectedFromRaw !== undefined) {
285
+ if (typeof selectedFromRaw !== 'string' || !SELECTED_FROM.test(selectedFromRaw)) {
286
+ fail('KIT-BIZ-003', `master.selectedFrom 取值 ${JSON.stringify(selectedFromRaw)} 不合法:只许 $page.params.<名> 或 $page.query.<名>(地址参数决定初始选中的主记录)`, 'product.objects.master.selectedFrom');
287
+ } else {
288
+ // 引用的参数必须在 page.params / page.query 里声明(上下文带了声明名才校验;没带时跳过,不误报)
289
+ const [, kindOf, pname] = selectedFromRaw.split('.') as [string, 'params' | 'query', string];
290
+ const declared = kindOf === 'params' ? ctx.pageParams : ctx.pageQuery;
291
+ if (declared !== undefined && !declared.includes(pname)) {
292
+ fail('KIT-PAGE-004', `master.selectedFrom 引用的 ${selectedFromRaw} 未在 page.${kindOf} 里声明(已声明:${declared.length > 0 ? declared.join(' / ') : '无'})`, 'product.objects.master.selectedFrom');
293
+ }
294
+ // 编成枢纽 prop 的页面路径绑定(core 首段是页面变量即按路径读,地址参数变化时随之更新)
295
+ preferKey = selectedFromRaw.slice(1);
296
+ }
297
+ }
298
+ const selectActionRaw = (rawMaster as Rec).selectAction;
299
+ let selectAction: string | undefined;
300
+ if (selectActionRaw !== undefined) {
301
+ if (typeof selectActionRaw !== 'string' || selectActionRaw === '') {
302
+ fail('KIT-BIZ-003', 'master.selectAction 必须是非空字符串(应用登记的具名动作名)', 'product.objects.master.selectAction');
303
+ } else if (!ctx.registeredActions.has(selectActionRaw)) {
304
+ fail('KIT-EVT-001', `master.selectAction "${selectActionRaw}" 未在应用的具名动作中登记`, 'product.objects.master.selectAction');
305
+ } else {
306
+ selectAction = selectActionRaw;
307
+ }
308
+ }
276
309
  if (out.diagnostics.length > 0) return finishBizCompile(out, '');
277
310
 
278
311
  const ids = masterSubIds(ctx.pageId);
@@ -490,10 +523,14 @@ export function compileMasterSub(input: KitBizInput, ctx: KitBizContext): KitFra
490
523
  const overlayObjects: Record<string, string> = {};
491
524
  /** 编辑表单按容器公式得整页的附加浮层(协调组件 pageOverlays) */
492
525
  const pageOverlays: string[] = [];
526
+ const rowTriggeredOverlays = new Set<string>([...Object.values(overlayActions), ...Object.values(showEdit)]);
527
+ const rowlessOverlays = new Set<string>(
528
+ Object.entries(overlays).filter(([n, d]) => isAutoRowlessOverlay(d, rowTriggeredOverlays.has(n))).map(([n]) => n),
529
+ );
493
530
  const EDIT_LABEL = kitText('soma.kit.edit', undefined, ctx.locale);
494
531
  for (const [name, decl] of Object.entries(overlays)) {
495
532
  const compiled = compileOverlay(
496
- { out, ctx, scope: link, object: masterName, keyField: masterKey, actions: requestPool, areaClass, closeLabel: CLOSE_LABEL, cancelLabel: CANCEL_LABEL, editLabel: EDIT_LABEL, showEdit },
533
+ { out, ctx, scope: link, object: masterName, keyField: masterKey, actions: requestPool, areaClass, closeLabel: CLOSE_LABEL, cancelLabel: CANCEL_LABEL, editLabel: EDIT_LABEL, showEdit, ...(rowlessOverlays.size > 0 ? { rowless: rowlessOverlays } : {}) },
497
534
  name,
498
535
  decl,
499
536
  );
@@ -517,6 +554,7 @@ export function compileMasterSub(input: KitBizInput, ctx: KitBizContext): KitFra
517
554
  out.show[ids.subs] = { when: mirrorPath(link, KIT_LINK_MIRRORS.selHas) };
518
555
  out.show[ids.empty] = { when: mirrorPath(link, KIT_LINK_MIRRORS.selNone) };
519
556
  for (const x of [mk.openForm, mk.creating, mk.editing, mk.mode, mk.row, mk.id, mk.sel]) mirrors.push({ key: x.key, slice: 'focus', path: x.path, as: x.as });
557
+ if (rowlessOverlays.size > 0) mirrors.push({ key: mk.ovMode.key, slice: 'focus', path: mk.ovMode.path, as: mk.ovMode.as });
520
558
  mirrors.push(...overlayMirrors);
521
559
  if (Object.keys(overlayObjects).length > 0) mirrors.push({ key: KIT_CRUD_LINK_KEY, slice: 'focus', path: `row.${masterKey}`, as: 'value' });
522
560
  // 新建 / 编辑表单(只有主对象有)的容器由公式推出(KT-P-window):对话框,或同页切换的整页表单视图;
@@ -570,8 +608,12 @@ export function compileMasterSub(input: KitBizInput, ctx: KitBizContext): KitFra
570
608
  scope: link, keyField: masterKey, linkKey: '', autoSelect: true, rows: rowsPath, pageScopes,
571
609
  ...(createScopes.length > 0 ? { createScopes } : {}),
572
610
  ...(Object.keys(createObjects).length > 0 ? { createObjects } : {}),
611
+ // 页面指定的选中键(selectedFrom):不声明时不带,产物与改前一致
612
+ ...(preferKey !== undefined ? { preferKey } : {}),
573
613
  },
574
614
  };
615
+ // 选中变化(含默认选中、地址参数对齐):枢纽的 picked { id, item, prefill } 交具名动作(如回写地址参数);picked_<序号> 槽位仍各管各的重取
616
+ if (selectAction !== undefined) out.events[`${ids.hub}.picked`] = `ACTION | ${selectAction}`;
575
617
  out.show[ids.coord] = {
576
618
  props: {
577
619
  scope: link, objectScope: masterScope, object: masterName, keyField: masterKey, reloads: reloadTargets.map((s) => s.object), overlays: overlayObjects, showEdit, rowsPath: m.r.compiled.listShape.rows,
@@ -9,7 +9,9 @@ export const MasterSubWorkstation = defineKitBizComponent({
9
9
  kind: 'MasterSubWorkstation',
10
10
  roles: {
11
11
  // unselectedText:没有选中主行时从属区整区空态的文案(缺省取内置「请选择左侧记录」)
12
- master: { required: true, views: ['filter', 'list', 'summary', 'form'], extraKeys: ['unselectedText'] },
12
+ // selectedFrom:页面指定初始选中的主记录($page.params.<名> / $page.query.<名>,主键相等的行;找不到回落首行)
13
+ // selectAction:选中变化后执行的具名动作(载荷 { id, item, prefill },如回写地址参数)
14
+ master: { required: true, views: ['filter', 'list', 'summary', 'form'], extraKeys: ['unselectedText', 'selectedFrom', 'selectAction'] },
13
15
  // group:详情里的分组名(同名从属收进页内页签的同一签;不写 group 的常显在页签之上)
14
16
  subs: { required: true, views: ['list', 'summary'], many: true, extraKeys: ['group'] },
15
17
  aside: { required: false, views: ['list', 'summary'] },
@@ -12,6 +12,10 @@
12
12
  // 应用动作 record 的具名工具栏动作之后追加 kit_reload;载荷里没有行(工具栏无 row),动作用 `focusRow()` 取当前记录:
13
13
  // KitCrudBridge 的 record prop 绑 `page.data.<记录对象>`,focus 没有当前行时 focusRow() 退回它(记录取回即可用)。
14
14
  // 选此路而非「取回后写 focus.row」:后者要订阅取数完成、且会污染编辑表单回填的 row,绑定读取无副作用、重取后自动刷新
15
+ // 附加浮层 overlays.<名>(dialog / drawer):从属对象的行动作 builtin: openOverlay + targetOverlay 打开,被点的行是浮层表单初值;
16
+ // 浮层编译、事件映射、请求动作提交(成功关窗并重取记录与全部从属对象)与 StandardCrud / MasterSub 共用 shared/overlay-compile.ts。
17
+ // 记录头(record 工具栏动作 builtin: openOverlay)也能打开:点击载荷为空,按钮编成独立语义事件 crud_open_overlay_<动作 id>,
18
+ // 经协调组件 recordOverlayEvents 以当前记录(props.record)为行、按编辑模式打开(记录未取回时不响应)
15
19
  // 限制:record.from 的接口必须直接返回记录对象(不带响应外壳 / 列表信封);写了 behavior.into 或非字符串 from 报 KIT-BIZ-003。
16
20
  // 子对象的关联键写 from[].require(core 的 CORE-DATA-REQUIRE):记录尚未取回、关联键为空时子对象不发请求(状态 idle),不再依赖后端「缺关联键返回空」。
17
21
 
@@ -32,7 +36,7 @@ import {
32
36
  } from '../shared/compile-helpers';
33
37
  import { pipeTails, wireDialogForm } from '../shared/pipes';
34
38
  import { OVERLAY_SHELL_CLASS, dialogHtml, dialogIds, dialogTitles } from '../shared/overlay-shell';
35
- import { adviseDialogFooter } from '../shared/overlay-compile';
39
+ import { KIT_CRUD_LINK_KEY, adviseDialogFooter, compileOverlay, isAutoRowlessOverlay, validateOverlayNames } from '../shared/overlay-compile';
36
40
  import { dialogWidthOf, editContainerOf } from '../../object-renderer/overlay-decide';
37
41
  import { PAGE_FORM_FOCUS_INITIAL, pageBrowsingMirror, wireMainPageForm } from '../shared/page-form';
38
42
  import {
@@ -60,6 +64,18 @@ function clone<T>(v: T): T {
60
64
  return JSON.parse(JSON.stringify(v)) as T;
61
65
  }
62
66
 
67
+ /**
68
+ * 记录头浮层的语义事件名:crud_open_overlay_<动作 id 的 snake_case>(与 StandardCrud 工具条浮层 rowlessOverlayEvent 同一拼法;
69
+ * core 的语义事件名只许小写 snake_case);撞名或与行动作的 crud_open_overlay 相同时补序号
70
+ */
71
+ function recordOverlayEvent(actionId: string, taken: Readonly<Record<string, string>>): string {
72
+ const snake = actionId.replace(/([A-Z])/g, '_$1').toLowerCase().replace(/[^a-z0-9_]/g, '_').replace(/_+/g, '_').replace(/^_|_$/g, '');
73
+ const base = snake === '' ? KIT_COORD_EVENTS.openOverlay : `${KIT_COORD_EVENTS.openOverlay}_${snake}`;
74
+ let name = base;
75
+ for (let n = 2; name === KIT_COORD_EVENTS.openOverlay || Object.hasOwn(taken, name); n += 1) name = `${base}_${n}`;
76
+ return name;
77
+ }
78
+
63
79
  export function compileRecordDetail(input: KitBizInput, ctx: KitBizContext): KitFragment {
64
80
  const CLOSE_LABEL = kitText('soma.kit.close', undefined, ctx.locale);
65
81
  const CANCEL_LABEL = kitText('soma.kit.cancel', undefined, ctx.locale);
@@ -152,6 +168,14 @@ export function compileRecordDetail(input: KitBizInput, ctx: KitBizContext): Kit
152
168
  actions.forEach((a, i) => {
153
169
  if (a.on === 'row') fail('KIT-BIZ-003', `record 的动作 ${a.id}:详情台没有行,动作只许 on: toolbar / field`, `product.objects.record.behavior.actions[${i}].on`);
154
170
  if (a.builtin === 'openCreate') fail('KIT-BIZ-003', `record 的动作 ${a.id}:详情台不能新增,builtin 只许 openEdit / reload`, `product.objects.record.behavior.actions[${i}].builtin`);
171
+ // 记录头打开附加浮层:只许工具条动作(on: row 上一行已拒),目标必须是已声明的浮层;以当前记录为行、按编辑打开(协调组件 recordOverlayEvents)
172
+ if (a.builtin === 'openOverlay') {
173
+ const at = `product.objects.record.behavior.actions[${i}]`;
174
+ if (a.on !== 'toolbar' && a.on !== 'row') fail('KIT-EVT-001', `record 的动作 ${a.id}:openOverlay 只能是记录头工具条动作(on: toolbar,以当前记录打开浮层)`, at);
175
+ if (a.targetOverlay === undefined || !Object.hasOwn(input.overlays ?? {}, a.targetOverlay)) {
176
+ fail('KIT-EVT-001', `动作 ${a.id} 的 targetOverlay "${a.targetOverlay ?? ''}" 不在 overlays 里`, `${at}.targetOverlay`);
177
+ }
178
+ }
155
179
  });
156
180
  if (out.diagnostics.length > 0) return finishBizCompile(out, '');
157
181
  // 缺省「编辑」补不补:声明里已有「功能为编辑」的动作(builtin: openEdit、id: edit、写了 function: edit …)就不补,
@@ -163,7 +187,7 @@ export function compileRecordDetail(input: KitBizInput, ctx: KitBizContext): Kit
163
187
  if (hasWrite) record.view = { ...record.view, form: isRec(formView) ? (formView as KitObject['view'] & Rec as never) : {} };
164
188
 
165
189
  // ---- 子对象
166
- const subs: Array<{ object: string; scope: string; obj: KitObject; title: string }> = [];
190
+ const subs: Array<{ object: string; scope: string; obj: KitObject; title: string; name: string }> = [];
167
191
  for (const n of subNames) {
168
192
  const raw = (rawSubs as Rec)[n] as Rec;
169
193
  const behavior = raw.behavior as Rec;
@@ -184,23 +208,68 @@ export function compileRecordDetail(input: KitBizInput, ctx: KitBizContext): Kit
184
208
  });
185
209
  out.diagnostics.push(...sn.diagnostics);
186
210
  const object = recordDetailObjectName(ctx.pageId, `sub_${n}`);
187
- subs.push({ object, scope: `${object}_scope`, obj: sn.obj, title: typeof raw.title === 'string' ? raw.title : '' });
211
+ subs.push({ object, scope: `${object}_scope`, obj: sn.obj, title: typeof raw.title === 'string' ? raw.title : '', name: n });
188
212
  }
189
213
  if (out.diagnostics.length > 0) return finishBizCompile(out, '');
190
214
 
215
+ // ---- 附加浮层(overlays.*):与 StandardCrud / MasterSubWorkstation 同一份校验与编译(shared/overlay-compile.ts)。
216
+ // 从属对象的行动作 builtin: openOverlay + targetOverlay -> crud_open_overlay(载荷带被点的行)-> 协调组件写 focus(浮层显隐镜像 + 当前行);
217
+ // 浮层表单 initial 绑当前行,提交走表单 write / 浮层事件 { action }(request 动作登记在记录对象名下),成功后关窗并重取记录与全部从属对象
218
+ const overlays = input.overlays ?? {};
219
+ const hasOverlays = Object.keys(overlays).length > 0;
220
+ const showEdit = validateOverlayNames(overlays, ['record', ...groupNames, ...subNames], fail);
221
+ for (const [name, decl] of Object.entries(overlays)) {
222
+ const at = `product.overlays.${name}`;
223
+ if (decl.kind !== undefined && decl.kind !== 'dialog' && decl.kind !== 'drawer') {
224
+ fail('KIT-BIZ-003', `RecordDetail 的附加浮层 ${name} 只支持 kind: dialog / drawer(expand 展开行子表只属于 StandardCrud)`, `${at}.kind`);
225
+ }
226
+ if (decl.rowClick !== undefined) {
227
+ fail('KIT-BIZ-003', `浮层 ${name} 的 rowClick 只属于 StandardCrud;详情台用从属对象的行动作 builtin: openOverlay 打开浮层`, `${at}.rowClick`);
228
+ }
229
+ }
230
+ /** 行动作 id -> 浮层名;同 id 在不同从属对象里指向不同浮层时协调组件无法反查,直接拒收 */
231
+ const overlayActions: Record<string, string> = {};
232
+ /** 浮层事件 { action } 可引用的声明式请求 / 下载动作池:记录动作在前,各从属对象的动作按声明序 */
233
+ const requestPool: KitAction[] = [...actions];
234
+ for (const s of subs) {
235
+ (s.obj.behavior.actions ?? []).forEach((a, i) => {
236
+ requestPool.push(a);
237
+ if (a.builtin !== 'openOverlay') return;
238
+ const where = `product.objects.subs.${s.name}.behavior.actions[${i}]`;
239
+ if (a.on !== 'row') fail('KIT-EVT-001', `动作 ${a.id}:openOverlay 只能是行操作(以被点的行打开浮层)`, where);
240
+ if (a.targetOverlay === undefined || !(a.targetOverlay in overlays)) {
241
+ fail('KIT-EVT-001', `动作 ${a.id} 的 targetOverlay "${a.targetOverlay ?? ''}" 不在 overlays 里`, `${where}.targetOverlay`);
242
+ } else if (overlayActions[a.id] !== undefined && overlayActions[a.id] !== a.targetOverlay) {
243
+ fail('KIT-EVT-001', `动作 id ${a.id} 在多个从属对象里指向不同浮层(${overlayActions[a.id]} / ${a.targetOverlay}):协调组件按动作 id 反查浮层,请改成不同的动作 id`, `${where}.targetOverlay`);
244
+ } else {
245
+ overlayActions[a.id] = a.targetOverlay;
246
+ }
247
+ });
248
+ }
249
+ if (out.diagnostics.length > 0) return finishBizCompile(out, '');
250
+ const overlayTargets = hasOverlays ? new Set(Object.keys(overlays)) : undefined;
251
+
191
252
  // ---- 发射
192
253
  const mk = KIT_COORD_MIRRORS;
193
254
  const m = emitMember(out, {
194
255
  object: recName, scope: recScope, obj: record, ctx, link, hubId: ids.coord,
195
256
  emitInput: { formMode: 'edit', formInitialPath: recPath },
196
257
  });
197
- // 工具栏内置动作:编辑 / 刷新交协调组件
258
+ // 工具栏内置动作:编辑 / 刷新 / 打开浮层交协调组件
259
+ /** 记录头浮层:语义事件名 -> 浮层名(协调组件 props.recordOverlayEvents;没有这类动作时不带) */
260
+ const recordOverlayEvents: Record<string, string> = {};
198
261
  actions.forEach((act, i) => {
199
262
  if (act.on !== 'toolbar') return;
200
263
  const click = `${toolbarAnchor(recName, act.id)}.click`;
201
264
  const tails = (): string[] => pipeTails(act, `behavior.actions[${i}]`, out.diagnostics);
202
265
  if (act.builtin === 'openEdit') out.events[click] = semanticPipe(link, KIT_COORD_EVENTS.openEdit, tails());
203
266
  else if (act.builtin === 'reload') out.events[click] = semanticPipe(link, KIT_COORD_EVENTS.reload, tails());
267
+ else if (act.builtin === 'openOverlay' && act.targetOverlay !== undefined) {
268
+ // 记录头浮层:按钮点击载荷为空,每个动作一个独立语义事件名(与 StandardCrud 工具条浮层同一拼法),协调组件按 recordOverlayEvents 反查目标、以 props.record 为行打开
269
+ const event = recordOverlayEvent(act.id, recordOverlayEvents);
270
+ recordOverlayEvents[event] = act.targetOverlay;
271
+ out.events[click] = semanticPipe(link, event, tails());
272
+ }
204
273
  });
205
274
 
206
275
  const groups: DetailBlock[] = [];
@@ -237,7 +306,7 @@ export function compileRecordDetail(input: KitBizInput, ctx: KitBizContext): Kit
237
306
 
238
307
  const subBlocks: DetailBlock[] = [];
239
308
  for (const s of subs) {
240
- const sm = emitMember(out, { object: s.object, scope: s.scope, obj: s.obj, ctx, link, hubId: ids.coord });
309
+ const sm = emitMember(out, { object: s.object, scope: s.scope, obj: s.obj, ctx, link, hubId: ids.coord, ...(overlayTargets !== undefined ? { overlayTargets } : {}) });
241
310
  subBlocks.push({
242
311
  title: s.title,
243
312
  html: [sm.r.parts.toolbar ?? '', sm.r.parts.filter ?? '', sm.listHtml, sm.r.parts.summary ?? ''].filter((x) => x !== '').join('\n'),
@@ -261,26 +330,62 @@ export function compileRecordDetail(input: KitBizInput, ctx: KitBizContext): Kit
261
330
  subBlocks.length = 0;
262
331
  }
263
332
 
333
+ // ---- 附加浮层:协调组件是 focus 切片 owner,显隐镜像、当前行镜像与关联键镜像(当前行主键)声明在链接作用域上
334
+ const overlayHtmls: string[] = [];
335
+ const overlayMirrors: SomaScopeMirrorDecl[] = [];
336
+ const overlayObjects: Record<string, string> = {};
337
+ /** 编辑表单按容器公式得整页的附加浮层(协调组件 pageOverlays) */
338
+ const pageOverlays: string[] = [];
339
+ const rowTriggeredOverlays = new Set<string>([...Object.values(overlayActions), ...Object.values(recordOverlayEvents), ...Object.values(showEdit)]);
340
+ const rowlessOverlays = new Set<string>(
341
+ Object.entries(overlays).filter(([n, d]) => isAutoRowlessOverlay(d, rowTriggeredOverlays.has(n))).map(([n]) => n),
342
+ );
343
+ for (const [name, decl] of Object.entries(overlays)) {
344
+ const compiled = compileOverlay(
345
+ { out, ctx, scope: link, object: recName, keyField: recKey, actions: requestPool, areaClass, closeLabel: CLOSE_LABEL, cancelLabel: CANCEL_LABEL, editLabel: EDIT_LABEL, showEdit, ...(rowlessOverlays.size > 0 ? { rowless: rowlessOverlays } : {}) },
346
+ name,
347
+ decl,
348
+ );
349
+ if (compiled === undefined) continue;
350
+ if (compiled.page) pageOverlays.push(name);
351
+ overlayObjects[name] = compiled.object;
352
+ overlayMirrors.push(compiled.mirror);
353
+ overlayHtmls.push(compiled.html);
354
+ }
355
+
264
356
  // ---- 链接作用域:focus 归协调组件
265
357
  const mirrors: SomaScopeMirrorDecl[] = [];
266
358
  for (const x of [mk.openForm, mk.creating, mk.editing]) mirrors.push({ key: x.key, slice: 'focus', path: x.path, as: x.as });
359
+ // 有附加浮层才声明:当前行镜像(浮层表单 initial / 写死形状组件 data 注入被点的行)、各浮层显隐镜像、关联键镜像(产物在未声明 overlays 时与改前一致)
360
+ if (hasOverlays) {
361
+ mirrors.push({ key: mk.row.key, slice: 'focus', path: mk.row.path, as: mk.row.as }, ...overlayMirrors);
362
+ if (rowlessOverlays.size > 0) mirrors.push({ key: mk.ovMode.key, slice: 'focus', path: mk.ovMode.path, as: mk.ovMode.as });
363
+ if (recKey !== undefined && Object.keys(overlayObjects).length > 0) mirrors.push({ key: KIT_CRUD_LINK_KEY, slice: 'focus', path: `row.${recKey}`, as: 'value' });
364
+ }
267
365
  // 编辑表单的容器(KT-P-window;只有编辑,永不分步):对话框,或同页切换的整页表单视图(详情区让位)
268
366
  const pageForm = hasWrite && record.view?.form !== undefined && editContainerOf({ form: record.view.form, schema: record.schema }, { edit: true }).container === 'page';
269
- if (pageForm) mirrors.push(pageBrowsingMirror());
367
+ // 整页(记录编辑表单或附加浮层的编辑表单)打开时详情区让位(绑协调组件的「浏览中」镜像)
368
+ const yields = pageForm || pageOverlays.length > 0;
369
+ if (yields) mirrors.push(pageBrowsingMirror());
270
370
  out.scopes[link] = {
271
371
  id: link,
272
372
  object: recName,
273
- slices: [{ name: 'focus', owner: ids.coord, ...(pageForm ? { initial: PAGE_FORM_FOCUS_INITIAL } : {}) }],
373
+ slices: [{ name: 'focus', owner: ids.coord, ...(yields ? { initial: PAGE_FORM_FOCUS_INITIAL } : {}) }],
274
374
  mirrors: sortMirrors(mirrors),
275
375
  };
276
376
  out.show[ids.coord] = {
277
377
  props: {
278
- scope: link, object: recName, keyField: recKey ?? '', reloads: subs.map((s) => s.object), overlays: {}, record: recPath,
378
+ scope: link, object: recName, keyField: recKey ?? '', reloads: subs.map((s) => s.object), overlays: overlayObjects, record: recPath,
379
+ // 行动作 id -> 附加浮层名(行字段盖掉载荷 target 时按动作 id 反查);只读浮层 -> 编辑浮层
380
+ ...(hasOverlays ? { overlayActions, showEdit } : {}),
381
+ // 记录头浮层(工具条 openOverlay):语义事件名 -> 浮层名,协调组件以 props.record 为行、按编辑打开;没有这类动作时不带(产物与改前一致)
382
+ ...(Object.keys(recordOverlayEvents).length > 0 ? { recordOverlayEvents } : {}),
279
383
  ...(pageForm ? { pageForm: true } : {}),
384
+ ...(pageOverlays.length > 0 ? { pageOverlays } : {}),
280
385
  ...linkRemoveProps(out),
281
386
  },
282
387
  };
283
- if (pageForm) out.show[`${ids.root}_browse`] = { when: mirrorPath(link, KIT_COORD_MIRRORS.browsing.key) };
388
+ if (yields) out.show[`${ids.root}_browse`] = { when: mirrorPath(link, KIT_COORD_MIRRORS.browsing.key) };
284
389
 
285
390
  // ---- 编辑表单
286
391
  let dialog = '';
@@ -316,10 +421,15 @@ export function compileRecordDetail(input: KitBizInput, ctx: KitBizContext): Kit
316
421
  adviseDialogFooter(ctx, record.view.form, 'product.objects.record.view.form.footerActions');
317
422
  for (const c of Object.values(OVERLAY_SHELL_CLASS)) for (const t of c.split(/\s+/)) if (t !== '') out.candidates.add(t);
318
423
  }
424
+ // 附加浮层的窗口 / 抽屉 / 整页编辑面跟在记录编辑弹窗之后(与 MasterSub 同一拼法;没有浮层时 dialog 原样)
425
+ if (overlayHtmls.length > 0) {
426
+ dialog = [dialog, ...overlayHtmls].filter((x) => x !== '').join('\n');
427
+ for (const c of Object.values(OVERLAY_SHELL_CLASS)) for (const t of c.split(/\s+/)) if (t !== '') out.candidates.add(t);
428
+ }
319
429
 
320
430
  const html = recordDetailHtml(
321
431
  ids,
322
- { summary: m.r.parts.summary ?? '', actions: m.r.parts.toolbar ?? '', groups, subs: subBlocks, dialog, ...(subsTabs !== undefined ? { subsTabs } : {}), ...(pageForm ? { browseId: `${ids.root}_browse` } : {}), ...(next ? { next: { record: recName } } : {}) },
432
+ { summary: m.r.parts.summary ?? '', actions: m.r.parts.toolbar ?? '', groups, subs: subBlocks, dialog, ...(subsTabs !== undefined ? { subsTabs } : {}), ...(yields ? { browseId: `${ids.root}_browse` } : {}), ...(next ? { next: { record: recName } } : {}) },
323
433
  areaClass,
324
434
  input.class,
325
435
  );