soma-kit 0.1.17 → 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 (55) hide show
  1. package/package.json +1 -1
  2. package/spec/generated/kit-page.schema.json +11 -1
  3. package/spec/kit-grammar.json +174 -13
  4. package/spec/kit-grammar.schema.json +4 -0
  5. package/src/app/component-gate.ts +668 -55
  6. package/src/app/define-kit-app.ts +75 -6
  7. package/src/app/index.ts +4 -1
  8. package/src/app/internal-lab.ts +90 -0
  9. package/src/app/kit-view-context.ts +44 -2
  10. package/src/app/server.ts +51 -9
  11. package/src/biz/compose.ts +66 -0
  12. package/src/biz/define.ts +38 -1
  13. package/src/biz/index.ts +1 -0
  14. package/src/biz/layout-contracts.ts +119 -4
  15. package/src/biz/link/hub.ts +31 -0
  16. package/src/biz/master-sub/compile.ts +45 -3
  17. package/src/biz/master-sub/index.ts +3 -1
  18. package/src/biz/record-detail/compile.ts +120 -10
  19. package/src/biz/shared/coordinator.ts +245 -48
  20. package/src/biz/shared/index.ts +5 -1
  21. package/src/biz/shared/object-aliases.ts +14 -3
  22. package/src/biz/shared/overlay-compile.ts +56 -5
  23. package/src/biz/shared/overlay-shell.ts +5 -2
  24. package/src/biz/shared/page-form.ts +9 -5
  25. package/src/biz/shared/page-overlay-host.ts +126 -0
  26. package/src/biz/shared/page-overlay-names.ts +27 -0
  27. package/src/biz/shared/runtime-hub.ts +37 -2
  28. package/src/biz/single-form/compile.ts +60 -5
  29. package/src/biz/single-form/index.ts +2 -1
  30. package/src/biz/standard-crud/compile.ts +9 -2
  31. package/src/biz/types.ts +26 -0
  32. package/src/cli/kit-cli.ts +1 -0
  33. package/src/cli/view-writes.ts +130 -3
  34. package/src/compile/compile-page.ts +49 -4
  35. package/src/compile/page-pipeline.ts +4 -0
  36. package/src/compile/parse.ts +14 -0
  37. package/src/compile/stages.ts +5 -4
  38. package/src/compile/types.ts +1 -1
  39. package/src/compile/view-check.ts +49 -17
  40. package/src/data/comment-thread.ts +78 -18
  41. package/src/data/navbar.ts +4 -0
  42. package/src/data/object-form.ts +17 -3
  43. package/src/data/prompt-dialog.ts +102 -15
  44. package/src/frames/page-header.ts +11 -2
  45. package/src/frames/shared.ts +6 -0
  46. package/src/frames/types.ts +2 -0
  47. package/src/generated/kit-grammar-runtime.ts +47 -5
  48. package/src/i18n/kit-text.ts +1 -0
  49. package/src/object-renderer/request-actions.ts +145 -17
  50. package/src/object-renderer/types.ts +7 -0
  51. package/src/shared/dom-attrs-registry.ts +5 -3
  52. package/src/shared/dom-attrs.ts +2 -0
  53. package/src/spatial/declared-actions.ts +6 -3
  54. package/src/spatial/emit.ts +1 -1
  55. package/src/spatial/expand.ts +7 -2
@@ -21,7 +21,7 @@ import type { KitAction, KitDiagnostic, KitObject, KitView, KitViewForm } from '
21
21
  import { busyActionOf, kitObjectBusyChannel } from '../../base/action-busy';
22
22
  import type { SomaScopeMirrorDecl } from 'soma-core';
23
23
  import type { KitBizContext, KitOverlayDecl, KitOverlayEventAction } from '../types';
24
- import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS, overlayMirrorKey } from './coordinator';
24
+ import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS, overlayEventTag, overlayMirrorKey } from './coordinator';
25
25
  import { addEmit, IDENT, isRec, labelDiagnostics, mirrorPath, patchProps, type Parts, type Rec } from '../link/shared';
26
26
  import { semanticPipe, wireDialogForm } from './pipes';
27
27
  import { overlayHtml, overlayIds } from './overlay-shell';
@@ -79,6 +79,19 @@ const OVERLAY_ROLE_SEMANTIC: Record<string, string> = {
79
79
  close: KIT_COORD_EVENTS.close,
80
80
  reload: KIT_COORD_EVENTS.reload,
81
81
  };
82
+ /** 浮层内数据组件的状态事件(与官方表单 KitObjectForm 发给宿主的同名):组件事件名 -> 协调组件语义事件 */
83
+ const OVERLAY_STATE_EVENTS: ReadonlyArray<readonly [string, string]> = [
84
+ ['busy_change', KIT_COORD_EVENTS.busy],
85
+ ['dirty_change', KIT_COORD_EVENTS.dirty],
86
+ ];
87
+
88
+ /** 数据组件契约 emits 里声明了 dirty_change(会报「有改动」):draft: keep 对它也有效 */
89
+ function reportsDirty(view: KitView, staticComponents: Readonly<Record<string, { emits?: readonly string[] } | undefined>>): boolean {
90
+ return (['list', 'summary'] as const).some((slot) => {
91
+ const comp = view[slot]?.staticComponent;
92
+ return comp !== undefined && staticComponents[comp]?.emits?.includes('dirty_change') === true;
93
+ });
94
+ }
82
95
 
83
96
  /** 关联键镜像:当前行主键(附加对象的 from.params 引用) */
84
97
  export const KIT_CRUD_LINK_KEY = 'crud_link';
@@ -94,6 +107,19 @@ export function normalizeOverlayView(view: unknown): KitView | undefined {
94
107
  return undefined;
95
108
  }
96
109
 
110
+ /**
111
+ * 浮层是否需要自动绑定 focus.ovMode 镜像(供 ctx.openOverlay(name, { values }) 等无行入口进入 create 模式):
112
+ * 1) 含表单视图且不按当前行取数(无 behavior.from、非 kind: expand);
113
+ * 2) 未被行级声明入口(行动作 / rowClick / editOverlay / recordOverlayEvents)占用,或显式声明了 write.create 通道。
114
+ */
115
+ export function isAutoRowlessOverlay(decl: KitOverlayDecl, rowTriggered: boolean): boolean {
116
+ if (decl.kind === 'expand' || decl.behavior?.from !== undefined) return false;
117
+ const view = normalizeOverlayView(decl.view);
118
+ if (view?.form === undefined) return false;
119
+ if (!rowTriggered) return true;
120
+ return isRec(decl.behavior?.write) && decl.behavior.write.create !== undefined;
121
+ }
122
+
97
123
  type Fail = (code: string, message: string, path: string) => void;
98
124
 
99
125
  /**
@@ -146,6 +172,13 @@ export interface OverlayHostArgs {
146
172
  * (无行打开 = create,行打开 = edit);不给 / 不在其中的浮层表单照旧写死 edit
147
173
  */
148
174
  rowless?: ReadonlySet<string>;
175
+ /** 诊断路径前缀(缺省 product.overlays;页面级浮层宿主给 page.overlays) */
176
+ basePath?: string;
177
+ /**
178
+ * 带表单的窗口能否按容器公式变成整页表单视图(缺省 true)。页面级浮层宿主给 false:它不在列表 / 主从区里,
179
+ * 没有让位的外层,整页视图会画在页面底部——恒按对话框渲染
180
+ */
181
+ allowPage?: boolean;
149
182
  }
150
183
 
151
184
  export interface CompiledOverlay {
@@ -161,9 +194,8 @@ export interface CompiledOverlay {
161
194
  export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverlayDecl): CompiledOverlay | undefined {
162
195
  const { out, ctx, scope, object, keyField, actions, areaClass } = h;
163
196
  const fail: Fail = (code, message, path) => { out.diagnostics.push({ code, message, path } as KitDiagnostic); };
164
- const at = `product.overlays.${name}`;
197
+ const at = `${h.basePath ?? 'product.overlays'}.${name}`;
165
198
  if (!IDENT.test(name)) return undefined;
166
- // 抽屉宽度档:width 只对 kind: drawer 有效(对话框宽度由内容定档),取值闭集 narrow / default / wide
167
199
  // 窗口的大小与外观由框架按内容推导(确认 400、表单 480 / 640 / 800、只读抽屉 480 / 640,尺寸规格 §5),页面不写 width / class(KIT-OVL-003)
168
200
  // 过渡期:KIT-OVL-002 / 003 先以告警落地(不挡编译,kit check 的弃用提示段带出),应用按 apps-todo 改完后升为错误
169
201
  const warn = (code: string, message: string, path: string, hint: string): void => {
@@ -180,7 +212,15 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
180
212
  }
181
213
  // 形态:没写 kind 时由内容推出(带提交 → 窗口 / 整页,只读 → 抽屉);带表单的窗口再过容器公式(KT-P-window):整页 = 同页切换的表单视图
182
214
  const kind = overlayKindOf(decl, view, ctx.staticComponents);
183
- const asPage = kind === 'dialog' && view.form !== undefined && editContainerOf({ form: view.form, schema: decl.schema }, { edit: true }).container === 'page';
215
+ const asPage = h.allowPage !== false && kind === 'dialog' && view.form !== undefined && editContainerOf({ form: view.form, schema: decl.schema }, { edit: true }).container === 'page';
216
+ // 草稿去留(draft,缺省 discard):取值闭集 discard / keep;keep 只对含表单(或会报 dirty_change 的数据组件)的窗口有效,别处告警(KIT-OVL-005)
217
+ const editable = view.form !== undefined || reportsDirty(view, ctx.staticComponents);
218
+ const draftKeep = decl.draft === 'keep' && kind === 'dialog' && editable;
219
+ if (decl.draft !== undefined && decl.draft !== 'discard' && decl.draft !== 'keep') {
220
+ fail('KIT-BIZ-003', `浮层 ${name} 的 draft "${String(decl.draft)}" 不在 discard / keep 内`, `${at}.draft`);
221
+ } else if (decl.draft === 'keep' && !draftKeep) {
222
+ warn('KIT-OVL-005', `浮层 ${name} 写了 draft: keep,但它${!editable ? '没有表单视图 view.form(内容数据组件也没在 emits 里声明 dirty_change)' : '是抽屉'}:草稿保留只对可填写的窗口生效,这里不起作用`, `${at}.draft`, '删掉 draft;需要保留草稿的填写内容放进含 view.form 的窗口(不写 kind 或 kind: dialog),或让内容数据组件声明并抛 dirty_change');
223
+ }
184
224
  if (asPage && decl.kind === 'dialog') {
185
225
  warn('KIT-IA-009', `浮层 ${name} 写了 kind: dialog,但它的编辑表单按容器公式是整页表单(加权字段数超过对话框上限、含重型字段或多个分组):已按整页表单视图渲染`, `${at}.kind`, '删掉 kind(带提交的浮层由框架按内容推出对话框 / 整页表单,只读的推出抽屉)');
186
226
  }
@@ -239,6 +279,10 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
239
279
  const mode = h.rowless?.has(name) === true ? mirrorPath(scope, m.ovMode.key) : 'edit';
240
280
  patchProps(out.show, ovFormId, { mode, initial: injectRow ? rowPath : `page.data.${ovObject}`, scope: `${ovObject}__form`, cancelLabel: h.cancelLabel });
241
281
  wireDialogForm(out.events, ovFormId, scope);
282
+ // 按浮层名隔离表单脏状态与忙闲通道,避免多浮层共享 crud_row 刷新时隐藏浮层串台覆盖当前活动面板状态
283
+ const ovTag = overlayEventTag(name);
284
+ out.events[`${ovFormId}.dirty_change`] = semanticPipe(scope, `${KIT_COORD_EVENTS.dirty}_ov_${ovTag}`);
285
+ out.events[`${ovFormId}.busy_change`] = semanticPipe(scope, `${KIT_COORD_EVENTS.busy}_ov_${ovTag}`);
242
286
  }
243
287
  // K-1 / M1-3:浮层里的写死形状数据组件(应用组件)按约定抛 saved / cancel / close / reload,由协调组件接;
244
288
  // overlays.<名>.events 可再把自定义事件名映射到这四种之一。组件没抛的事件不会触发(core 对未声明的 emit 选择器惰性)
@@ -301,6 +345,12 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
301
345
  }
302
346
  out.events[`${anchor}.${emitName}`] = semanticPipe(scope, sem);
303
347
  }
348
+ // 数据组件报「在途 / 有改动」:与官方表单同名同载荷(busy_change { busy } / dirty_change { dirty }),接到协调组件同一条通道
349
+ // (kit_form_busy / kit_dirty)——在途时用户关窗被忽略,有改动时按 draft 处理(discard 先问、keep 不问)。
350
+ // 只接组件契约 emits 里明确声明了的(没声明 emits 或没列这两个的组件产物与改前逐字一致);events.<同名> 显式写了以显式为准
351
+ for (const [emitName, sem] of OVERLAY_STATE_EVENTS) {
352
+ if (knownEmits?.includes(emitName) === true && !(emitName in explicitEvents)) out.events[`${anchor}.${emitName}`] = semanticPipe(scope, sem);
353
+ }
304
354
  const busyNames = busyActionOf(view[slot]!.staticComponent!, namedOn);
305
355
  const shown = out.show[anchor];
306
356
  const handwritten = isRec(shown) && isRec((shown as Rec).props) ? ((shown as Rec).props as Rec).busy_action : undefined;
@@ -323,6 +373,7 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
323
373
  ...(ctx.locale !== undefined ? { locale: ctx.locale } : {}),
324
374
  // 新模式:整页编辑面就是这个附加浮层对象的容器,给它补对象锚点(与版式契约 overlays 角色的 anchor 同一拼法)
325
375
  ...(isNextPipeline(ctx) ? { bodyAnchor: kitObjectAnchor(ovObject) } : {}),
376
+ ...(draftKeep ? { draftKeep: true } : {}),
326
377
  });
327
378
  return { html, mirror, object: ovObject, page: true };
328
379
  }
@@ -345,7 +396,7 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
345
396
  schema: decl.schema,
346
397
  staticComponent: view.list?.staticComponent ?? view.summary?.staticComponent,
347
398
  tableList: view.list !== undefined && view.list.staticComponent === undefined && (view.list.collection === undefined || view.list.collection.type === 'table'),
348
- }), [...submitActions], true, isNextPipeline(ctx) ? kitObjectAnchor(ovObject) : undefined),
399
+ }), [...submitActions], true, isNextPipeline(ctx) ? kitObjectAnchor(ovObject) : undefined, draftKeep ? 'keep' : undefined),
349
400
  mirror,
350
401
  object: ovObject,
351
402
  page: false,
@@ -7,7 +7,7 @@
7
7
  import { kitWithCompilePipeline } from '../../object-renderer/pipeline-mode';
8
8
  import { esc } from '../../shared/escape';
9
9
  import { mergeClass } from '../../shared/merge-class';
10
- import { KIT_ATTR_FIXED, KIT_ATTR_SUBMIT_ACTIONS, kitAttrHtml } from '../../shared/dom-attrs';
10
+ import { KIT_ATTR_DRAFT, KIT_ATTR_FIXED, KIT_ATTR_SUBMIT_ACTIONS, kitAttrHtml } from '../../shared/dom-attrs';
11
11
  import type { KitDialogTier, KitDrawerWidth } from '../../recipes/overlay';
12
12
  import { kitShellClasses, kitShellHtml } from '../../base/overlay-shell';
13
13
  import { kitIconHtml } from '../../shared/icons';
@@ -166,6 +166,8 @@ export function overlayHtml(
166
166
  modal = true,
167
167
  /** 新模式下浮层面板的锚点(附加浮层对象的容器);旧版不给 */
168
168
  panelAnchor?: string,
169
+ /** 浮层声明 draft: keep 时给 'keep':宿主层打出草稿保留标记(协调组件据它关窗不问、不还原);不给时产物逐字节不变 */
170
+ draftMode?: 'keep',
169
171
  ): string {
170
172
  const decision = kind === 'drawer' ? { kind, drawerWidth } as const : { kind, dialogTier: tierOf(wide) } as const;
171
173
  const panel = mergeClass(mergeClass(kitShellClasses(decision).panel, stripOverlayWidthClasses(areaClass[kind])), stripOverlayWidthClasses(panelClass));
@@ -187,6 +189,7 @@ export function overlayHtml(
187
189
  footerHtml: footer !== '' ? footer : null,
188
190
  };
189
191
  const shell = next ? kitWithCompilePipeline('next', () => kitShellHtml(spec)) : kitShellHtml(spec);
190
- const html = `<div data-soma-id="${esc(ids.layer)}"${submitMark}${LAYER_HOST_CLASS_ATTR}>${shell}</div>`;
192
+ const draftMark = draftMode === 'keep' ? kitAttrHtml(KIT_ATTR_DRAFT, 'keep') : '';
193
+ const html = `<div data-soma-id="${esc(ids.layer)}"${submitMark}${draftMark}${LAYER_HOST_CLASS_ATTR}>${shell}</div>`;
191
194
  return next ? withPanelAnchor(html, panelAnchor) : html;
192
195
  }
@@ -11,7 +11,7 @@ import { kitNeutralClass } from './pipeline';
11
11
  import { KIT_TIPS_SCOPE_ATTR } from '../../base/hint-tips';
12
12
  import { kitText } from '../../i18n/kit-text';
13
13
  import { mergeClass } from '../../shared/merge-class';
14
- import { KIT_ATTR_CONTAINER, KIT_ATTR_EMPHASIS, KIT_ATTR_PART } from '../../shared/dom-attrs';
14
+ import { KIT_ATTR_CONTAINER, KIT_ATTR_DRAFT, KIT_ATTR_EMPHASIS, KIT_ATTR_PART, kitAttrHtml } from '../../shared/dom-attrs';
15
15
  import { kitIconHtml } from '../../shared/icons';
16
16
  import { KIT_BROWSE_ATTR, KIT_PAGE_FORM_ATTR } from '../../recipes/container';
17
17
  import { kitControlRecipe } from '../../recipes/control';
@@ -154,7 +154,9 @@ export function pageFormIds(object: string): PageFormIds {
154
154
  * 整页表单层 HTML:页头(画布上:页标题 + 右侧「返回」)+ 正文(表单:版心卡 + 目录)。
155
155
  * 标题按 creating / editing 两个真值显隐(与对话框标题同一对镜像);附加浮层的编辑表单(overlays.<名>)只有一种状态:copy 不给 edit 时只出一个标题(不挂显隐)。
156
156
  */
157
- export function pageFormHtml(ids: PageFormIds, copy: { create: string; edit?: string; back: string }, formHtml: string, bodyAnchor?: string): string {
157
+ export function pageFormHtml(ids: PageFormIds, copy: { create: string; edit?: string; back: string }, formHtml: string, bodyAnchor?: string, draftKeep = false): string {
158
+ // 附加浮层声明 draft: keep 时层上打出草稿保留标记(协调组件据它关窗不问、不还原);不写时产物逐字节不变
159
+ const keepMark = draftKeep ? kitAttrHtml(KIT_ATTR_DRAFT, 'keep') : '';
158
160
  const back = `<button type="button" data-soma-id="${esc(ids.back)}"${cls(PAGE_FORM_CLASS.back)}>${kitIconHtml('chevron-left', 'sm')}<span>${esc(copy.back)}</span></button>`;
159
161
  const titles = copy.edit === undefined
160
162
  ? esc(copy.create)
@@ -164,11 +166,11 @@ export function pageFormHtml(ids: PageFormIds, copy: { create: string; edit?: st
164
166
  const head = `<header${cls(PAGE_FORM_CLASS.head)}><div${cls(PAGE_FORM_CLASS.row)}><div${cls(PAGE_FORM_CLASS.titleRow)}>${title}</div><div${cls(PAGE_FORM_CLASS.actions)}>${back}</div></div></header>`;
165
167
  // 新模式:正文区是编辑视图(或整页附加浮层对象)的容器——补锚点,不写强调级与容器形态(由识别、布局给)
166
168
  if (bodyAnchor !== undefined) {
167
- return `<div data-soma-id="${esc(ids.layer)}" ${KIT_PAGE_FORM_ATTR}="">${head}`
169
+ return `<div data-soma-id="${esc(ids.layer)}" ${KIT_PAGE_FORM_ATTR}=""${keepMark}>${head}`
168
170
  + `<section data-soma-id="${esc(bodyAnchor)}" role="region" aria-labelledby="${esc(ids.title)}"${cls(kitNeutralClass(PAGE_FORM_CLASS.body))}>${formHtml}</section></div>`;
169
171
  }
170
172
  // 正文区不画面(面 = 表单的版心卡),构成闭集声明为 plain(D-08)
171
- return `<div data-soma-id="${esc(ids.layer)}" ${KIT_PAGE_FORM_ATTR}="">${head}`
173
+ return `<div data-soma-id="${esc(ids.layer)}" ${KIT_PAGE_FORM_ATTR}=""${keepMark}>${head}`
172
174
  + `<section role="region" aria-labelledby="${esc(ids.title)}" ${KIT_ATTR_EMPHASIS}="primary" ${KIT_ATTR_CONTAINER}="plain"${cls(PAGE_FORM_CLASS.body)}>${formHtml}</section></div>`;
173
175
  }
174
176
 
@@ -243,6 +245,8 @@ export function wireOverlayPageForm(out: PageFormOut, a: {
243
245
  object: string; scope: string; overlay: string; formId: string; formHtml: string; title: string; submit: string; locale?: string;
244
246
  /** 新模式下整页面的锚点(附加浮层对象的容器);旧版不给 */
245
247
  bodyAnchor?: string;
248
+ /** 浮层声明 draft: keep:层上打出草稿保留标记;不给时产物逐字节不变 */
249
+ draftKeep?: boolean;
246
250
  }): string {
247
251
  const ids = pageFormIds(a.object);
248
252
  patchProps(out.show, a.formId, { formDomId: ids.formDom });
@@ -251,5 +255,5 @@ export function wireOverlayPageForm(out: PageFormOut, a: {
251
255
  out.events[`${ids.back}.click`] = semanticPipe(a.scope, KIT_COORD_EVENTS.close);
252
256
  wirePageFormFoot(out, a, { submit: a.submit });
253
257
  addPageFormCandidates(out);
254
- return pageFormHtml(ids, { create: a.title, back: kitText('soma.kit.back', undefined, a.locale) }, a.formHtml, a.bodyAnchor);
258
+ return pageFormHtml(ids, { create: a.title, back: kitText('soma.kit.back', undefined, a.locale) }, a.formHtml, a.bodyAnchor, a.draftKeep === true);
255
259
  }
@@ -0,0 +1,126 @@
1
+ // 页面级浮层宿主(page.overlays):不属于任何业务组件的浮层(如页头「新建需求」、展示对象按数据自动弹出的裁决窗)挂在一个无界面的宿主下。
2
+ //
3
+ // 宿主 = 一个 KitCrudBridge 协调组件(hostOnly: true)+ 各浮层的窗口 / 抽屉壳,浮层编译与业务组件里的 overlays.<名> 同一份实现
4
+ // (overlay-compile#compileOverlay):浮层名、事件映射、表单、声明式请求、draft 草稿去留规则都一样。差别只有三处:
5
+ // 1. 没有主对象与行:每个浮层都按「无行入口」编(表单 mode 绑 focus.ovMode,无行打开 = 新建;ctx.openOverlay(名, { row }) 以行打开 = 编辑);
6
+ // 2. 带表单的窗口恒为对话框(allowPage: false):宿主不在列表 / 主从区里,没有让位的外层,整页视图会画在页面底部;
7
+ // 3. 不写 rowClick / kind: expand(那是业务组件列表的入口),写了报 KIT-PAGE-007。
8
+ // 名字约定(pageId kit_page、宿主名、作用域、页头事件名)在叶子模块 page-overlay-names.ts,页面框与编排方共用。
9
+
10
+ import type { SomaScopeMirrorDecl } from 'soma-core';
11
+ import type { KitFragment } from '../../object-renderer/fragment';
12
+ import { classesInHtml } from '../../object-renderer/candidates';
13
+ import type { KitBizContext, KitOverlayDecl } from '../types';
14
+ import { kitText } from '../../i18n/kit-text';
15
+ import { KIT_COORD_MIRRORS } from './coordinator';
16
+ import { compileOverlay, validateOverlayNames } from './overlay-compile';
17
+ import { finishBizCompile } from './compile-helpers';
18
+ import { esc, host, isRec, newParts } from '../link/shared';
19
+ import {
20
+ KIT_PAGE_OVERLAY_COORD, KIT_PAGE_OVERLAY_HOST, KIT_PAGE_OVERLAY_PAGE_ID, KIT_PAGE_OVERLAY_SCOPE, kitPageOverlayOpenEvent,
21
+ } from './page-overlay-names';
22
+
23
+ export {
24
+ KIT_PAGE_OVERLAY_COORD, KIT_PAGE_OVERLAY_HOST, KIT_PAGE_OVERLAY_PAGE_ID, KIT_PAGE_OVERLAY_SCOPE, kitPageOverlayOpenEvent, kitPageOverlayOpenPipe,
25
+ } from './page-overlay-names';
26
+
27
+ export interface KitOverlayHostArgs {
28
+ /** 业务组件上下文(compile-page 给页面的那一份;默认页面级浮层将 pageId 换成 kit_page,自定义 hostId / 非默认 basePath 时按宿主前缀隔离) */
29
+ ctx: KitBizContext;
30
+ /** page.overlays 的声明:浮层名 -> 声明(形状同 product.objects.overlays.<名>) */
31
+ overlays: Record<string, KitOverlayDecl>;
32
+ /** 诊断路径前缀(缺省 page.overlays) */
33
+ basePath?: string;
34
+ /** 可选宿主标识前缀(自定义业务组件 / 多槽位调用时隔离 pageId / scope / object / coord 主键) */
35
+ hostId?: string;
36
+ }
37
+
38
+ /**
39
+ * 编出页面级浮层宿主的片段(HTML + ui + events):编排方 compile-page 把它并进页面框产物。
40
+ * 没有声明浮层时返回空片段(html 为空串)。协调组件 props:{ scope, object: 宿主名, keyField: '', overlays, showEdit, hostOnly: true, overlayEvents }。
41
+ */
42
+ export function emitKitOverlayHost(args: KitOverlayHostArgs): KitFragment {
43
+ const basePath = args.basePath ?? 'page.overlays';
44
+ const isDefaultPageHost = args.hostId === undefined && (args.basePath === undefined || args.basePath === 'page.overlays');
45
+ const hostPrefix = isDefaultPageHost ? KIT_PAGE_OVERLAY_PAGE_ID : (args.hostId ?? args.ctx.pageId);
46
+ const scope = isDefaultPageHost ? KIT_PAGE_OVERLAY_SCOPE : `${hostPrefix}__ovhost_scope`;
47
+ const object = isDefaultPageHost ? KIT_PAGE_OVERLAY_HOST : `${hostPrefix}__ovhost`;
48
+ const coord = isDefaultPageHost ? KIT_PAGE_OVERLAY_COORD : `${hostPrefix}__ovhost_coord`;
49
+ const ctx: KitBizContext = { ...args.ctx, pageId: hostPrefix };
50
+ const out = newParts(['Button', 'KitCrudBridge']);
51
+ const fail = (code: string, message: string, path: string): void => { out.diagnostics.push({ code, message, path }); };
52
+ const overlays = isRec(args.overlays) ? args.overlays : {};
53
+ if (Object.keys(overlays).length === 0) return finishBizCompile(out, '');
54
+
55
+ const showEdit = validateOverlayNames(overlays, [], fail, basePath);
56
+ // 页面级浮层没有列表:rowClick / kind: expand 不适用
57
+ const usable: Array<[string, KitOverlayDecl]> = [];
58
+ const seenEvents = new Map<string, string>();
59
+ for (const [name, decl] of Object.entries(overlays)) {
60
+ if (!isRec(decl)) {
61
+ fail('KIT-PAGE-007', `页面级浮层 ${name} 必须是对象声明(形状同 product.objects.overlays.<名>)`, `${basePath}.${name}`);
62
+ continue;
63
+ }
64
+ if (decl.rowClick !== undefined) {
65
+ fail('KIT-PAGE-007', `页面级浮层 ${name} 写了 rowClick:整行点击只属于业务组件的列表,页面级浮层由页头动作 openOverlay 或展示对象 ctx.openOverlay 打开`, `${basePath}.${name}.rowClick`);
66
+ continue;
67
+ }
68
+ if (decl.kind === 'expand') {
69
+ fail('KIT-PAGE-007', `页面级浮层 ${name} 写了 kind: expand:展开行子表只属于 StandardCrud 的列表,页面级浮层只能是窗口或抽屉`, `${basePath}.${name}.kind`);
70
+ continue;
71
+ }
72
+ const event = kitPageOverlayOpenEvent(name);
73
+ const other = seenEvents.get(event);
74
+ if (other !== undefined) {
75
+ fail('KIT-PAGE-007', `页面级浮层 ${name} 与 ${other} 的打开事件名相同(${event},大小写 / 下划线换算后撞名):改一个浮层名`, `${basePath}.${name}`);
76
+ continue;
77
+ }
78
+ seenEvents.set(event, name);
79
+ usable.push([name, decl]);
80
+ }
81
+ if (out.diagnostics.length > 0) return finishBizCompile(out, '');
82
+
83
+ // 每个页面级浮层都只有无行入口(页头动作 / ctx.openOverlay 无行):表单 mode 绑 focus.ovMode
84
+ const rowless = new Set(usable.map(([name]) => name));
85
+ const overlayObjects: Record<string, string> = {};
86
+ const overlayMirrors: SomaScopeMirrorDecl[] = [];
87
+ const overlayHtmls: string[] = [];
88
+ for (const [name, decl] of usable) {
89
+ const compiled = compileOverlay(
90
+ {
91
+ out, ctx, scope, object, keyField: undefined, actions: [], areaClass: {},
92
+ closeLabel: kitText('soma.kit.close', undefined, ctx.locale),
93
+ cancelLabel: kitText('soma.kit.cancel', undefined, ctx.locale),
94
+ editLabel: kitText('soma.kit.edit', undefined, ctx.locale),
95
+ showEdit, rowless, basePath, allowPage: false,
96
+ },
97
+ name,
98
+ decl,
99
+ );
100
+ if (compiled === undefined) continue;
101
+ overlayObjects[name] = compiled.object;
102
+ overlayMirrors.push(compiled.mirror);
103
+ overlayHtmls.push(compiled.html);
104
+ }
105
+ if (overlayHtmls.length === 0) return finishBizCompile(out, '');
106
+
107
+ // 宿主作用域:focus 切片(owner 是协调组件)+ 当前行 / 新建编辑 / 各浮层显隐镜像;不挂数据对象(宿主不是数据对象)
108
+ const m = KIT_COORD_MIRRORS;
109
+ const mirrors: SomaScopeMirrorDecl[] = [
110
+ ...[m.row, m.ovMode].map((x) => ({ key: x.key, slice: 'focus' as const, path: x.path, as: x.as })),
111
+ ...overlayMirrors,
112
+ ].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
113
+ out.scopes[scope] = { id: scope, slices: [{ name: 'focus', owner: coord }], mirrors };
114
+
115
+ const overlayEvents: Record<string, string> = {};
116
+ for (const name of Object.keys(overlayObjects)) overlayEvents[kitPageOverlayOpenEvent(name)] = name;
117
+ out.show[coord] = {
118
+ props: {
119
+ scope, object, keyField: '', reloads: [], overlays: overlayObjects, showEdit, hostOnly: true, overlayEvents,
120
+ },
121
+ };
122
+ const html = `<div data-soma-id="${esc(object)}">\n${[host('KitCrudBridge', coord), ...overlayHtmls].join('\n')}\n</div>`;
123
+ // 浮层壳的类进候选类(与业务组件壳同一做法)
124
+ for (const c of classesInHtml(html)) out.candidates.add(c);
125
+ return finishBizCompile(out, html);
126
+ }
@@ -0,0 +1,27 @@
1
+ // 页面级浮层(page.overlays)的名字约定:叶子模块(不 import 别的模块),页面框(页头动作接线)、编排方 compile-page 与宿主编译共用一份。
2
+ //
3
+ // 页面级浮层挂在一个无界面的宿主下(page-overlay-host.ts#emitKitOverlayHost 编出):
4
+ // pageId kit_page 浮层对象运行期名 kit_page_<浮层名>,限定名 kit_page.<浮层名>
5
+ // 宿主名 kit_page__ovhost 浮层 id 前缀;声明式请求登记在它名下(成功后经它的协调组件关窗)
6
+ // 协调组件作用域 kit_page__ovhost_scope focus 切片与浮层显隐镜像、语义事件都在这里
7
+ // 页头动作事件 page_open_<浮层名 snake> page.actions[].openOverlay 的按钮点击 -> 以空行打开该浮层
8
+
9
+ /** 页面级浮层的 pageId(对象名契约里的「槽名」):运行期名 kit_page_<浮层名> */
10
+ export const KIT_PAGE_OVERLAY_PAGE_ID = 'kit_page';
11
+ /** 页面级浮层宿主名(浮层 id 前缀、声明式请求的登记对象名) */
12
+ export const KIT_PAGE_OVERLAY_HOST = `${KIT_PAGE_OVERLAY_PAGE_ID}__ovhost`;
13
+ /** 页面级浮层宿主的作用域 id(协调组件的 focus 切片在这里) */
14
+ export const KIT_PAGE_OVERLAY_SCOPE = `${KIT_PAGE_OVERLAY_HOST}_scope`;
15
+ /** 页面级浮层宿主的协调组件实例 id */
16
+ export const KIT_PAGE_OVERLAY_COORD = `${KIT_PAGE_OVERLAY_HOST}__link`;
17
+
18
+ /** 浮层名 -> 页头动作打开它的语义事件名(core 语义事件名只许小写 snake_case):page_open_<snake>;两个浮层名得出同一事件名时由 compile-page 报 KIT-PAGE-007 */
19
+ export function kitPageOverlayOpenEvent(overlay: string): string {
20
+ const snake = overlay.replace(/([A-Z])/g, '_$1').toLowerCase().replace(/[^a-z0-9_]/g, '_').replace(/_+/g, '_').replace(/^_|_$/g, '');
21
+ return `page_open_${snake === '' ? 'overlay' : snake}`;
22
+ }
23
+
24
+ /** 页头动作打开页面级浮层的事件管道:SCOPE | semantic | kit_page__ovhost_scope | page_open_<snake>(与 biz/shared/pipes#semanticPipe 同一格式) */
25
+ export function kitPageOverlayOpenPipe(overlay: string): string {
26
+ return ['SCOPE', 'semantic', KIT_PAGE_OVERLAY_SCOPE, kitPageOverlayOpenEvent(overlay)].join(' | ');
27
+ }
@@ -44,6 +44,18 @@ export interface KitHubEntry {
44
44
  close?(): void;
45
45
  /** 打开新建表单并带初值(展示对象 ctx.openCreate 用;初值盖在组件级预填之上,用户随后可改) */
46
46
  openCreate?(prefill?: Record<string, unknown>): void;
47
+ /**
48
+ * 按运行期对象名打开附加浮层(展示对象 ctx.openOverlay 用):给 row 以该行打开(表单按编辑),不给按无行打开(values 为初值)。
49
+ * 对象不是本协调组件的浮层、或表单提交中返回 false
50
+ */
51
+ openOverlay?(objectRuntime: string, opts: { row?: Record<string, unknown>; values?: Record<string, unknown> }): boolean;
52
+ /** 按运行期对象名关闭附加浮层(ctx.closeOverlay 用):它此刻不是打开的返回 false;discard = 不问、放弃草稿(含 draft: keep 保留的) */
53
+ closeOverlay?(objectRuntime: string, opts: { discard?: boolean }): boolean;
54
+ /**
55
+ * 页面级浮层宿主(page.overlays,协调组件 hostOnly):只按 scope / 对象名精确命中,不当作「最近登记的协调组件」兜底
56
+ * (否则同页业务组件的具名动作重取 / 筛选 / 勾选会落到它身上)
57
+ */
58
+ hostOnly?: boolean;
47
59
  }
48
60
 
49
61
  /** 按 scopeId / instanceId 索引的协调组件映射表(同 scope 多实例挂载时按栈保存,卸载时精确移除自身) */
@@ -253,10 +265,14 @@ function resolveHub(target?: string | HTMLElement): KitHubEntry | undefined {
253
265
  // 兜底:最近登记的协调组件。有触发元素(目标或动作栈顶是元素)时只在对它可用的里取(kitHubUsableFrom):
254
266
  // 页签框当前签没有协调组件、隐藏签有,或同文档另一个页面宿主有时,不把动作的筛选 / 分页 / 勾选 / 重取落到它们身上(F-06)
255
267
  const from = isElementTarget(target) ? target : isElementTarget(active) ? active : undefined;
256
- if (from === undefined) return entryOrder[entryOrder.length - 1];
268
+ // 页面级浮层宿主(hostOnly)不参与兜底;页面上没有它时与改前逐条相同
269
+ if (from === undefined) {
270
+ for (let i = entryOrder.length - 1; i >= 0; i -= 1) if (entryOrder[i]!.hostOnly !== true) return entryOrder[i];
271
+ return undefined;
272
+ }
257
273
  for (let i = entryOrder.length - 1; i >= 0; i -= 1) {
258
274
  const e = entryOrder[i]!;
259
- if (kitHubUsableFrom(e, from)) return e;
275
+ if (e.hostOnly !== true && kitHubUsableFrom(e, from)) return e;
260
276
  }
261
277
  return undefined;
262
278
  }
@@ -318,6 +334,25 @@ export function openKitHubCreate(target: string, prefill?: Record<string, unknow
318
334
  return true;
319
335
  }
320
336
 
337
+ /**
338
+ * 在浮层对象(运行期名 <pageId>_<浮层名>)所属的协调组件上打开该浮层(ctx.openOverlay):只按对象名精确路由(不走兜底),
339
+ * 没有协调组件 / 对象不是它的浮层 / 表单提交中返回 false
340
+ */
341
+ export function openKitHubOverlay(objectRuntime: string, opts: { row?: Record<string, unknown>; values?: Record<string, unknown> }): boolean {
342
+ if (typeof objectRuntime !== 'string' || objectRuntime === '') return false;
343
+ const list = entriesByObject.get(objectRuntime);
344
+ const hub = list !== undefined && list.length > 0 ? list[list.length - 1] : undefined;
345
+ return hub?.openOverlay?.(objectRuntime, opts) ?? false;
346
+ }
347
+
348
+ /** 关闭浮层对象所属协调组件上的该浮层(ctx.closeOverlay):路由同 openKitHubOverlay;浮层没开着返回 false */
349
+ export function closeKitHubOverlay(objectRuntime: string, opts: { discard?: boolean } = {}): boolean {
350
+ if (typeof objectRuntime !== 'string' || objectRuntime === '') return false;
351
+ const list = entriesByObject.get(objectRuntime);
352
+ const hub = list !== undefined && list.length > 0 ? list[list.length - 1] : undefined;
353
+ return hub?.closeOverlay?.(objectRuntime, opts) ?? false;
354
+ }
355
+
321
356
  /** 页面上有没有协调组件登记(支持按 scope / 宿主查询;KitActionHost 据此决定刷新走协调组件还是直接重取动作所属对象) */
322
357
  export function hasKitHub(target?: string | HTMLElement): boolean {
323
358
  if (target !== undefined) return resolveHub(target) !== undefined;
@@ -6,7 +6,10 @@
6
6
  // 反馈 失败 / 冲突由表单自己画在字段错误行与顶部提示条;成功抛 saved,页面弹成功通知;write.reload: self 让 core 重取,initial 随之回填新值
7
7
  // 重置 表单的「重置」按钮把草稿恢复到当前 initial
8
8
  //
9
- // 带 from 一律按 edit 打开,提交 mode 为 update(走 write 的 update 通道;write 写成字符串时 create / update 同一端点);没有 from 才是 create。
9
+ // 运行期模式(target.modeFrom:$page.params.* / $page.query.* / view.<成员>,值 create | edit):表单 mode 绑该路径(emit-static 的 formModePath),
10
+ // KitObjectForm 按 mode 选写通道;预取仍由 behavior.from + behavior.require 决定(关联参数为空时 core 不发请求,新建即空表单;
11
+ // 复制新建 = mode 为 create 且带源记录主键:取回源记录作初值、走新建通道)。target.initialFrom(view.<成员>)把表单初值改绑展示对象成员。
12
+ // 不写 modeFrom 时:带 from 一律按 edit 打开,提交 mode 为 update(走 write 的 update 通道;write 写成字符串时 create / update 同一端点);没有 from 才是 create。
10
13
  // 通知:`NOTIFY | success | <文案>` 的文案按 i18n key 经 translate 取词,core 的 `locale-catalog.t()` 查不到时原样返回 key,
11
14
  // 所以写死的中文文案直接显示;应用想换语言,在词表里加 `保存成功` 这个键即可。
12
15
  // 规则写死:target 必有 behavior.write 与 form 视图;没有 toolbar / row 动作;通知文案是写死的。
@@ -17,6 +20,7 @@ import { KIT_VIEW_FORM_KEYS, KIT_VIEW_SLOTS } from '../../object-renderer/defaul
17
20
  import { emitObject } from '../../object-renderer/emit-object';
18
21
  import { savedNoticePipe } from '../../object-renderer/form-notify';
19
22
  import { viewAnchor } from '../../object-renderer/emit-static';
23
+ import { isViewPath, viewPathToCore } from '../../object-renderer/view-binding';
20
24
  import type { KitDiagnostic, KitObject, KitViewForm } from '../../object-renderer/types';
21
25
  import type { KitFragment } from '../../object-renderer/fragment';
22
26
  import type { KitBizContext, KitBizInput } from '../types';
@@ -28,6 +32,19 @@ import { addEmit, classesIn, isRec, newParts, patchProps, type Rec } from '../li
28
32
  import { SingleObjectForm } from './index';
29
33
  import { SINGLE_FORM_AREAS, SINGLE_FORM_CLASS, singleFormHtml, singleFormIds } from './shell';
30
34
 
35
+ /** 地址参数表达式(名与 page.params / page.query 的命名规则一致) */
36
+ const PAGE_PARAM_REF = /^\$page\.(params|query)\.[a-z][a-z0-9_]{0,31}$/;
37
+
38
+ /**
39
+ * modeFrom / initialFrom 的取值 -> 表单 prop 的运行期路径绑定(core:首段是页面变量即按路径读):
40
+ * `$page.params.<名>` / `$page.query.<名>` -> `page.params.<名>` / `page.query.<名>`(allowPage 时);`view.<成员>` -> 展示对象成员的页面路径;其余返回 undefined
41
+ */
42
+ function runtimePathOf(raw: unknown, allowPage: boolean): string | undefined {
43
+ if (typeof raw !== 'string') return undefined;
44
+ if (allowPage && PAGE_PARAM_REF.test(raw)) return raw.slice(1);
45
+ return isViewPath(raw) ? viewPathToCore(raw) : undefined;
46
+ }
47
+
31
48
  export function singleFormObjectName(pageId: string): string {
32
49
  return bizObjectName(pageId, 'target');
33
50
  }
@@ -78,7 +95,36 @@ export function compileSingleForm(input: KitBizInput, ctx: KitBizContext): KitFr
78
95
  return finishBizCompile(out, '');
79
96
  }
80
97
  validateBizAreaClass(input, 'SingleObjectForm', SINGLE_FORM_AREAS, out.diagnostics);
81
- const target = normalizeTarget(rawTarget as unknown as Rec, out.diagnostics);
98
+ // 运行期模式与初值来源(target.modeFrom / target.initialFrom):只在业务组件层解释,不交对象渲染(从对象声明上摘掉)
99
+ const { modeFrom: modeFromRaw, initialFrom: initialFromRaw, ...targetDecl } = rawTarget as unknown as Rec;
100
+ const target = normalizeTarget(targetDecl, out.diagnostics);
101
+ const modePath = modeFromRaw === undefined ? undefined : runtimePathOf(modeFromRaw, true);
102
+ if (modeFromRaw !== undefined && modePath === undefined) {
103
+ fail('KIT-BIZ-003', `target.modeFrom 取值 ${JSON.stringify(modeFromRaw)} 不合法:只许 $page.params.<名> / $page.query.<名> / view.<成员>(运行期值为 create 或 edit)`, 'product.objects.target.modeFrom');
104
+ }
105
+ // 地址参数写法引用的参数必须在 page.params / page.query 里声明(上下文带了声明名才校验;没带时跳过,不误报;view.<成员> 不在此校验)
106
+ if (typeof modeFromRaw === 'string' && PAGE_PARAM_REF.test(modeFromRaw)) {
107
+ const [, kindOf, pname] = modeFromRaw.split('.') as [string, 'params' | 'query', string];
108
+ const declared = kindOf === 'params' ? ctx.pageParams : ctx.pageQuery;
109
+ if (declared !== undefined && !declared.includes(pname)) {
110
+ fail('KIT-PAGE-004', `target.modeFrom 引用的 ${modeFromRaw} 未在 page.${kindOf} 里声明(已声明:${declared.length > 0 ? declared.join(' / ') : '无'})`, 'product.objects.target.modeFrom');
111
+ }
112
+ }
113
+ const initialPath = initialFromRaw === undefined ? undefined : runtimePathOf(initialFromRaw, false);
114
+ if (initialFromRaw !== undefined && initialPath === undefined) {
115
+ fail('KIT-BIZ-003', `target.initialFrom 取值 ${JSON.stringify(initialFromRaw)} 不合法:只许展示对象成员路径 view.<成员>(表单初值对象)`, 'product.objects.target.initialFrom');
116
+ }
117
+ if (modePath !== undefined) {
118
+ // 运行期两种模式都可能提交:write 写成对象时 create / update 两个通道都要有(写成字符串时两种模式同一端点)
119
+ const write = target.behavior.write;
120
+ if (isRec(write) && (write.create === undefined || write.update === undefined)) {
121
+ fail('KIT-BIZ-003', 'target 写了 modeFrom(运行期决定新建或编辑)时,behavior.write 写成对象须同时有 create 与 update', 'product.objects.target.behavior.write');
122
+ }
123
+ // 标题在壳里是静态文字,两态标题 { create, edit } 无法随运行期模式切换
124
+ if (isRec(target.view?.form?.title)) {
125
+ fail('KIT-BIZ-003', 'target 写了 modeFrom 时 view.form.title 只许写字符串(壳内标题不随运行期模式切换;两态文案请放页头或展示对象)', 'product.objects.target.view.form.title');
126
+ }
127
+ }
82
128
  if (out.diagnostics.length > 0) return finishBizCompile(out, '');
83
129
 
84
130
  const areaClass = input.areaClass ?? {};
@@ -86,6 +132,8 @@ export function compileSingleForm(input: KitBizInput, ctx: KitBizContext): KitFr
86
132
  const scope = `${object}_scope`;
87
133
  const hasFrom = target.behavior.from !== undefined;
88
134
  const formView = target.view!.form as KitViewForm;
135
+ // 初值:initialFrom(展示对象成员)优先;否则有读接口时是挂载时取回的单对象(复制新建 = modeFrom 为 create 且读接口取回源记录)
136
+ const formInitialPath = initialPath ?? (hasFrom ? `page.data.${object}` : undefined);
89
137
 
90
138
  const r = emitObject(
91
139
  target,
@@ -93,8 +141,9 @@ export function compileSingleForm(input: KitBizInput, ctx: KitBizContext): KitFr
93
141
  {
94
142
  registeredActions: ctx.registeredActions,
95
143
  formMode: hasFrom ? 'edit' : 'create',
96
- // 有读接口:表单的初值就是挂载时取回的单对象
97
- ...(hasFrom ? { formInitialPath: `page.data.${object}` } : {}),
144
+ // modeFrom:表单 mode 绑运行期路径(KitObjectForm 按 mode 选写通道:edit -> update,create -> create);不写时照旧按有无读接口写死
145
+ ...(modePath !== undefined ? { formModePath: modePath } : {}),
146
+ ...(formInitialPath !== undefined ? { formInitialPath } : {}),
98
147
  },
99
148
  );
100
149
  addEmit(out, r);
@@ -103,7 +152,13 @@ export function compileSingleForm(input: KitBizInput, ctx: KitBizContext): KitFr
103
152
  const formId = viewAnchor(object, 'form');
104
153
  const entry = out.show[formId];
105
154
  const submitLabel = typeof formView.submitLabel === 'string' && formView.submitLabel !== '' ? formView.submitLabel : SUBMIT_LABEL;
106
- patchProps(out.show, formId, { scope: `${object}__form`, submitLabel, resetLabel: RESET_LABEL });
155
+ patchProps(out.show, formId, {
156
+ scope: `${object}__form`,
157
+ submitLabel,
158
+ resetLabel: RESET_LABEL,
159
+ // modeFrom 绑地址参数 / 展示对象成员时禁止 ?mode=filter 劫持表单切入筛选态
160
+ ...(modePath !== undefined ? { forbidFilterMode: true } : {}),
161
+ });
107
162
  if (isRec(entry) && isRec(entry.props)) {
108
163
  const classes = isRec(entry.props.classes) ? entry.props.classes : {};
109
164
  // 独立的可编辑表单:草稿有改动时拦截刷新 / 关闭与站内链接点击(表单已有的离开守卫,业务壳里默认打开;尊重页面显式关闭 false / 'none')
@@ -8,7 +8,8 @@ import { SINGLE_FORM_AREAS } from './shell';
8
8
  export const SingleObjectForm = defineKitBizComponent({
9
9
  kind: 'SingleObjectForm',
10
10
  roles: {
11
- target: { required: true, views: ['form'] },
11
+ // modeFrom:运行期决定新建 / 编辑($page.params.<名> / $page.query.<名> / view.<成员>,值 create | edit);initialFrom:表单初值改绑展示对象成员 view.<成员>
12
+ target: { required: true, views: ['form'], extraKeys: ['modeFrom', 'initialFrom'] },
12
13
  },
13
14
  areas: [...SINGLE_FORM_AREAS],
14
15
  // 声明式表单版心特征(短单组自动 narrow 640px,多字段/多组自动升 wide 960px 解锁 @2xl 双栏,无内层硬夹紧)
@@ -25,7 +25,7 @@ import type { KitAction, KitDiagnostic, KitObject, KitViewForm } from '../../obj
25
25
  import type { KitFragment } from '../../object-renderer/fragment';
26
26
  import type { KitBizContext, KitBizInput, KitOverlayDecl } from '../types';
27
27
  import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS, rewriteRowActions, type KitRowActionRoute } from '../shared/coordinator';
28
- import { KIT_CRUD_LINK_KEY, adviseDialogFooter, compileOverlay, normalizeOverlayView, validateOverlayNames } from '../shared/overlay-compile';
28
+ import { KIT_CRUD_LINK_KEY, adviseDialogFooter, compileOverlay, isAutoRowlessOverlay, normalizeOverlayView, validateOverlayNames } from '../shared/overlay-compile';
29
29
  import {
30
30
  bizObjectName, checkRoleAllowedViews, finishBizCompile, validateBizAreaClass,
31
31
  } from '../shared/compile-helpers';
@@ -262,8 +262,10 @@ export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): Kit
262
262
  }
263
263
  const rowClickName = rowClickNames.length === 1 && hasList ? rowClickNames[0] : undefined;
264
264
  if (rowClickNames.length === 1 && !hasList) fail('KIT-BIZ-003', 'rowClick 需要 entity 有 list 视图', `product.overlays.${rowClickNames[0]}.rowClick`);
265
- // 无行浮层(SCON-170):被工具条(及上提到页头的)openOverlay 动作以空行打开的浮层名;它们的表单 mode 绑协调组件的 ovMode 镜像
265
+ // 无行浮层(SCON-170):被工具条(及上提到页头的)openOverlay 动作以空行打开的浮层名,以及无行级声明入口 / 显式带 write.create 的表单浮层;它们的表单 mode 绑协调组件的 ovMode 镜像
266
266
  const rowlessOverlays = new Set<string>();
267
+ const rowTriggeredOverlays = new Set<string>(Object.values(showEdit));
268
+ if (rowClickName !== undefined) rowTriggeredOverlays.add(rowClickName);
267
269
  actions.forEach((a, i) => {
268
270
  const at = `product.objects.entity.behavior.actions[${i}]`;
269
271
  if (a.builtin === 'openOverlay') {
@@ -276,12 +278,17 @@ export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): Kit
276
278
  const why = rowlessOverlayProblem(overlays[a.targetOverlay]!, keyField);
277
279
  if (why !== null) fail('KIT-EVT-001', `动作 ${a.id}:工具条动作没有当前行,不能打开浮层 ${a.targetOverlay}(${why});改成行动作(on: row),或让浮层不按当前行取数、表单能按新建提交`, `${at}.targetOverlay`);
278
280
  else rowlessOverlays.add(a.targetOverlay);
281
+ } else if (a.on === 'row') {
282
+ rowTriggeredOverlays.add(a.targetOverlay);
279
283
  }
280
284
  }
281
285
  if ((a.builtin === 'openEdit' || a.builtin === 'remove') && a.on !== 'row') {
282
286
  fail('KIT-EVT-001', `动作 ${a.id}:${a.builtin} 只能是行操作(要带当前行)`, at);
283
287
  }
284
288
  });
289
+ for (const [name, decl] of Object.entries(overlays)) {
290
+ if (isAutoRowlessOverlay(decl, rowTriggeredOverlays.has(name))) rowlessOverlays.add(name);
291
+ }
285
292
  if (out.diagnostics.length > 0) return finishBizCompile(out, '');
286
293
 
287
294
  // ---- 展开行子表(Q 波 G5):kind: expand 的附加对象不画浮层,由 entity 的 collection.expand.list 引用