soma-kit 0.1.18 → 0.1.20

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 (58) hide show
  1. package/package.json +2 -2
  2. package/spec/generated/kit-page.schema.json +15 -1
  3. package/spec/kit-grammar.json +142 -18
  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/base/button.ts +11 -1
  10. package/src/biz/compose.ts +66 -0
  11. package/src/biz/define.ts +8 -0
  12. package/src/biz/index.ts +1 -0
  13. package/src/biz/layout-contracts.ts +119 -4
  14. package/src/biz/link/hub.ts +31 -0
  15. package/src/biz/master-sub/compile.ts +45 -3
  16. package/src/biz/master-sub/index.ts +3 -1
  17. package/src/biz/multi-board/compile.ts +5 -1
  18. package/src/biz/multi-board/prose-fold.ts +78 -5
  19. package/src/biz/multi-board/shell.ts +10 -3
  20. package/src/biz/record-detail/compile.ts +120 -10
  21. package/src/biz/shared/coordinator.ts +245 -48
  22. package/src/biz/shared/index.ts +5 -1
  23. package/src/biz/shared/object-aliases.ts +14 -3
  24. package/src/biz/shared/overlay-compile.ts +56 -5
  25. package/src/biz/shared/overlay-shell.ts +5 -2
  26. package/src/biz/shared/page-form.ts +9 -5
  27. package/src/biz/shared/page-overlay-host.ts +126 -0
  28. package/src/biz/shared/page-overlay-names.ts +27 -0
  29. package/src/biz/shared/runtime-hub.ts +37 -2
  30. package/src/biz/single-form/compile.ts +60 -5
  31. package/src/biz/single-form/index.ts +2 -1
  32. package/src/biz/standard-crud/compile.ts +9 -2
  33. package/src/biz/types.ts +18 -0
  34. package/src/cli/kit-cli.ts +1 -0
  35. package/src/cli/view-writes.ts +130 -3
  36. package/src/compile/compile-page.ts +49 -4
  37. package/src/compile/page-pipeline.ts +4 -0
  38. package/src/compile/parse.ts +14 -0
  39. package/src/compile/stages.ts +5 -4
  40. package/src/compile/types.ts +1 -1
  41. package/src/compile/view-check.ts +50 -19
  42. package/src/data/comment-thread.ts +78 -18
  43. package/src/data/navbar.ts +4 -0
  44. package/src/data/object-form.ts +17 -3
  45. package/src/data/prompt-dialog.ts +102 -15
  46. package/src/frames/page-header.ts +11 -2
  47. package/src/frames/shared.ts +6 -0
  48. package/src/frames/types.ts +2 -0
  49. package/src/generated/kit-grammar-runtime.ts +48 -8
  50. package/src/i18n/kit-text.ts +1 -0
  51. package/src/object-renderer/emit-static.ts +10 -3
  52. package/src/object-renderer/request-actions.ts +145 -17
  53. package/src/object-renderer/types.ts +7 -0
  54. package/src/shared/dom-attrs-registry.ts +9 -5
  55. package/src/shared/dom-attrs.ts +4 -0
  56. package/src/spatial/declared-actions.ts +6 -3
  57. package/src/spatial/emit.ts +1 -1
  58. package/src/spatial/expand.ts +7 -2
@@ -1,6 +1,6 @@
1
1
  // 生成物,不得改写:由 soma-kit/scripts/build-kit-grammar-runtime.mjs 从 spec/kit-grammar.json 抽出。
2
2
  // 浏览器侧只读这份运行期切片(闭集与限值);编译侧读完整真源。改真源后运行 `npm run grammar:runtime -w soma-kit` 重新生成。
3
- // 真源指纹 sha256:90ec5184ad50b6f7883453fb235c402ad194efe51506c441b2b61a0f95f0d52d
3
+ // 真源指纹 sha256:ad870a9f44173b16a276b471b9b83683d67912244552c7e48a0b590fa414afa4
4
4
 
5
5
  export const KIT_GRAMMAR_RUNTIME = {
6
6
  "i18n": {
@@ -347,6 +347,7 @@ export const KIT_GRAMMAR_RUNTIME = {
347
347
  "KIT-PAGE-004": "页面结构非法(缺 page / product 或形状不对),或应用内页面 URL 重复",
348
348
  "KIT-PAGE-005": "对象名或角色名用了保留名(frame / tabs / page / p / ctrl)或非字母数字下划线,或字段名含点号",
349
349
  "KIT-PAGE-006": "页面编译发生意外内部异常(意外抛错未携带 KitDiagnosticError);对外不泄露实现错误详情,详细信息仅记录在服务端日志中",
350
+ "KIT-PAGE-007": "页面级浮层(page.overlays.<名>)写法不对:page.overlays 不是 { 浮层名: 声明 }、写了只属于业务组件列表的 rowClick 或 kind: expand,或页头动作 page.actions[].openOverlay 指向的名字不在 page.overlays 里;声明形状其余与 product.objects.overlays.<名> 相同(浮层名、editOverlay 等走同一套 KIT-PAGE-005 / KIT-OVL / KIT-BIZ 诊断;页面级浮层的 editOverlay 只能指向另一个页面级浮层)",
350
351
  "KIT-APP-001": "kit.app.yaml 非法,或其登记(组件 accept 等)与 soma.app.ts 代码登记不一致",
351
352
  "KIT-THEME-001": "(工序 ⓪)kit.app.yaml#theme 写了未知键、未知取值、非字符串(emphasis.actions 的功能名不在闭集、值不是操作角色名同报本码),或已删除的旧键(palette_scheme / font_scheme / color / color_depth / color_saturation / accent_usage 等)与已并入色族的旧色板名(如 CLASSIC_TECH_BLUE):主题只有 preset + palette / shell / neutral / layering / shape / density / texture / glow / font_scale / font_family / motion / contrast + mode,取值小写短名、与真源档位 id 恒等;诊断给出新写法(迁移表读 kit-nine-dim.json#themeMigration 与 colorScheme.migration)。业务应用迁移前,themeMigration 登记的旧拼法(大写 id、驼峰键、surface_texture、boundary、table_style、旧预设名、mode: system / soft)照常接受并换成新值,不报本码",
352
353
  "KIT-THEME-002": "(工序 ⓪)主题组合在排除表里:X1 色族 × 外壳(graphite / red × navy / brand / graphite、orange × brand);X2 glow: on × red / graphite;X3 texture: glass × contrast: strong;X4 font_scale: reading × density: compact;X5 font_scale: display × density: compact;X6 density: touch × font_scale: small。判据在参考实现 color-scheme.mjs#themeComboExclusions,诊断给原因与改法;不做静默降级",
@@ -358,7 +359,7 @@ export const KIT_GRAMMAR_RUNTIME = {
358
359
  "KIT-PAGE-GATE-003": "(主题流水线页面侧门禁,生成事件,error)某一屏的实心主色按钮多于一个。回动作的功能名(func)与配色事件的实心主色名额:每屏只有一个实心主色",
359
360
  "KIT-PAGE-GATE-004": "(主题流水线页面侧门禁,生成事件,error)出现非法父子层级角色对(不在设计真源 kit-page.json#legalPairs 里,表外一律非法)。回业务组件版式契约(src/biz/layout-contracts.ts)或真源 legalPairs 修正,不在门里放行",
360
361
  "KIT-PAGE-GATE-005": "(主题流水线页面侧门禁,生成事件,只有 error)动作不守恒,三条独立核对:① 动作节点数与展开从页面声明里独立数出的声明动作总数(spatial/declared-actions.ts)对不上(展开漏建或多建);② 某个动作节点没有落到产物的去处(既没有自己的锚点、也不进任何宿主的动作汇总;承载它的业务组件没有版式契约时不报本码,改报 -006);③ 某个动作没有可收纳(stowable)或按钮形态(variant),说明布局或定形漏了它。回展开(建节点)、版式契约(锚点与缺省动作)或漏写的那个事件",
361
- "KIT-PAGE-GATE-006": "(主题流水线页面侧,只有 warn,不挡编译)动作落点告警:写完产物后动作的锚点与它要进的宿主动作汇总在产物里都找不到(编排方 compile/compile-page.ts 出,取决于模板与对象渲染器是否真画出了对应条目);或承载它的业务组件没有版式契约(应用自定义的业务组件),页面线无法给出动作落点;或声明里的动作编号重复,几个动作共用锚点与汇总键。按报告里的节点编号回模板锚点、给业务组件登记版式契约(src/biz/layout-contracts.ts),或改掉重复的动作 id",
362
+ "KIT-PAGE-GATE-006": "(主题流水线页面侧,只有 warn,不挡编译)动作落点告警:写完产物后动作的锚点与它要进的宿主动作汇总在产物里都找不到(编排方 compile/compile-page.ts 出,取决于模板与对象渲染器是否真画出了对应条目);或承载它的业务组件没有版式契约(应用自定义的业务组件),页面线无法给出动作落点;或声明里的动作编号重复,几个动作共用锚点与汇总键。按报告里的节点编号回模板锚点、给业务组件声明版式契约(内置组件登记在 src/biz/layout-contracts.ts,应用业务组件写 defineKitBizComponent({ layoutContract })),或改掉重复的动作 id",
362
363
  "KIT-PAGE-GATE-900": "(主题流水线自身出错,warn,不挡编译)仅旧版(legacy)旁路:页面流水线的某个事件抛错或应用组件的自报声明写错,旁路报告里只有这一条,消息里带原始错误;不影响产物。按原始错误修流水线代码或声明,不吞异常",
363
364
  "KIT-PAGE-GATE-901": "(主题流水线新模式,error,挡页面编译)新模式(next)下底层页面流水线核心异常、门禁不可恢复错误、直调页面编译传入的非法自报声明,或把属性写进产物时出错:属性没有写进产物,不出页面产物(半新半旧的页面不允许),消息里带原始错误。与 KIT-COMP-006 分工:应用装配期(assembleKitServer)检测到自定义组件契约 selfReport 声明字段或类型不合法时,隔离该组件并回落缺省自报、记 KIT-COMP-006(不中断整页编译);底层流水线核心异常或门禁不可恢复错误仍报本码 KIT-PAGE-GATE-901。按原始错误修流水线代码或声明",
364
365
  "KIT-THEME-GATE-001": "(主题流水线主题侧门禁,主题求解,error:挡装配)某个合法父子层级角色对在本层级策略档下看不出分界(有 error 的档不进允许的档位)。降为告警的几种情况改记 KIT-THEME-GATE-014。回设计真源的层级策略档取值或 soma-foundation 的分界判定(arrangeBoundaryPair),不改合法对表来过门",
@@ -471,6 +472,7 @@ export const KIT_GRAMMAR_RUNTIME = {
471
472
  "KIT-VIEW-009": "同一对象挂在两个路径下(刷新会错位):defineKitView 的 state 初值里两处引用同一个对象 / 数组实例(定义期拒绝),或方法里把对象成员赋给另一个成员 view.a = view.b(check 扫描);子 Proxy 按对象缓存、路径以首次访问为准,经第二个路径写入会上报成第一个路径",
472
473
  "KIT-VIEW-010": "组件 props / 字段项 props / behavior.params 里写了原始运行期路径:props 里的 page.* / kit_row_* / $page.* / $row.*(core 会静默当路径绑定,绕过展示对象),params 里的 $page.data.* / $page.region_mirror.* / $kit_row_* / $row.*(跨对象运行期路径);值只能是字面量、展示对象成员 view.<成员>(另一个对象的数据由展示对象 ctx.data(对象).onChange 转存成成员)或(列表字段项)行字段 row.<字段>",
473
474
  "KIT-VIEW-012": "展示对象用 ctx.http 发写请求(`soma kit check` 静态扫描,J1):ctx.http 是只读面,只许 GET(与 HEAD);ctx.http.post / put / patch / delete、ctx.http(…) 的 method 字面量不是 GET / HEAD 都报本码(运行期同样抛错)。写数据一律走 ctx.request(对象, 动作 id, 载荷) 或具名动作(经 core 写通道,有忙闲 / 取消 / 结果槽 / 权限)",
475
+ "KIT-VIEW-013": "展示对象 ctx.openOverlay / ctx.closeOverlay 的名字不是绑定页面声明的浮层(product.objects.overlays.<名> 或 page.overlays.<名>;`soma kit check` 静态扫描字面量名字):写错、写成普通对象名,或整页同名浮层不止一个时没写限定名 <页签 id 或槽名>.<名>(页面级浮层的限定名是 kit_page.<名>)。运行期名字解析不到时返回 false 并在开发态告警",
474
476
  "KIT-VIEW-011": "绑定的成员形状与位置要求不符:静态组件 prop 绑的成员须符合组件契约声明的 prop 类型(string / number / boolean / enum 要标量,array 要数组,object 要对象),behavior.params 要绑标量成员;形状取自 defineKitView 的 state 初值(绑对象的标量字段写 view.<成员>.<字段>)",
475
477
  "KIT-ROW-001": "行级状态绑定不是纯 row 路径:on: row 动作的 hidden / disabled 与 view.list.rowTone、列表字段项 props 只许写 row.<字段>(业务对象逐行给出的字段),不许字面量真假、谓词、表达式、取反、类名、非 row. 前缀",
476
478
  "KIT-ROW-002": "行级绑定写在了不支持的位置:on: row 动作的 hidden / disabled / disabledReason 在 treeTable、虚拟滚动表的行操作 / 右键菜单里不支持(rowTone 所有集合都支持,不再报此码);字段项 props 的 row.<字段> 只用于列表视图(summary / form / filter 没有行)且不支持 treeTable / 虚拟滚动表;静态视图 view.props 与 behavior.params 不能写 row.<字段>",
@@ -491,6 +493,7 @@ export const KIT_GRAMMAR_RUNTIME = {
491
493
  "KIT-OVL-002": "只读内容用了居中窗口(过渡期告警,不挡编译,随 kit check 的弃用提示段带出):kind: dialog 的浮层没有表单视图、behavior.write、接到具名动作或 saved 的事件;只读内容一律抽屉,改写 kind: drawer;居中窗口只给确认与带提交的表单",
492
494
  "KIT-OVL-003": "浮层写了 width 或 class(过渡期告警,不挡编译,该键已不生效):窗口的宽度与外观由框架按内容推导(确认 400;表单窗口单列 480、两列或宽组件 640、三列或画布 800;只读抽屉 480 / 640),页面不写尺寸与外观参数,删掉即可;要换档请改内容(栏数、组件)",
493
495
  "KIT-OVL-004": "窗口底栏排不下(过渡期告警,不挡编译):底栏右侧只放「取消 + 一个主动作」,左侧至多一个次级动作(表单 footerActions 超过 1 个),可见按钮总数不超过上限;其余收进「更多」或改成正文里的控件;判定在引擎 arrangeOverlayFooter(kit-arrange#overlay.footer)",
496
+ "KIT-OVL-005": "浮层写了 draft 但不适用(告警,不挡编译):draft 只对含表单视图(view.form)或内容数据组件在 emits 里声明了 dirty_change 的窗口(dialog,含按容器公式得出的整页表单)生效;写在不可填写的浮层或 kind: drawer 上不起作用,删掉即可;取值不在 discard / keep 内报 KIT-BIZ-003",
494
497
  "KIT-DET-001": "编辑详情(behavior.detail)写法不对:须是 { from: { api, params? }, unwrap? }(api 以 / 开头的接口路径,params 的值是字面量或 $row.<字段>,unwrap 是点路径),键在闭集内;对象的读通道(behavior.from)已存在的附加浮层不能再写 detail;detail 只用于有可编辑 form 视图的对象;AI 不可写",
495
498
  "KIT-AIT-001": "AI 页意图蓝图形状不合:缺必填、类型不对、超 aiWriter.limits 的总量限值(含 confirm_text 超 confirmMax),或名字不合法",
496
499
  "KIT-AIT-002": "AI 页意图蓝图越权:写了 human-only / compiler 的键(含 confirm)、样式类、颜色、显式组件名(component / props)、theme 或其他不在 aiWriter 写面表里的键",
@@ -514,11 +517,14 @@ export const KIT_GRAMMAR_RUNTIME = {
514
517
  "KIT-APP-017": "禁止野生样式表与野生页面 HTML:应用目录不得出现 .css / .scss / .less / .sass / .styl 文件或在源码中 import / export / require 样式表,kit.app.yaml 不得配置 style: 外链样式,且 pages/、src/web/、views/、components/ 下不得手写 .html / .htm;样式外观统一走 kit.app.yaml#theme 14 维 DSL 与 Tailwind 刻度类",
515
518
  "KIT-APP-018": "禁止命令式浮层、非组件 DOM 构造与伪造框架内部符号:全应用禁止调用 .showModal() / .showPopover() / createElement('dialog') / document.body.append* 及引用或伪造 Symbol.for('soma-kit.*');components/ 之外的源码禁止调用 createElement / createElementNS / insertAdjacentHTML 或写入 innerHTML / outerHTML",
516
519
  "KIT-APP-019": "自定义业务组件或其私有协作组件违反纯声明式装数据契约:业务组件未经 defineKitBizComponent 构造、组件源码内手写 <table> / <thead> / <form> / <dialog> 或直接调用 fetch() / new XMLHttpRequest,或业务组件源码硬编码 '/api/...' 接口路径(必须从页面 input.objects 的 behavior.from 与具名动作读取)",
520
+ "KIT-APP-020": "(过渡期告警,0.2.0 并入 KIT-APP-018)应用源码导入或调用框架内部的命令式浮层原语 mountKitModal / mountKitDrawer(soma-kit/data)。窗口一律在页面 overlays / page.overlays 声明,由 builtin: openOverlay 或展示对象 ctx.openOverlay / ctx.closeOverlay 开关;简单确认与输入用 ctx.confirm / ctx.prompt。仓内实验室(soma-kit-demo)豁免",
521
+ "KIT-APP-021": "(过渡期告警,0.2.0 并入 KIT-APP-019)展示对象目录(views/、src/web/views/)直接调用 fetch() / new XMLHttpRequest:绕过 ctx.http 只读面(KIT-VIEW-012)与 ctx.request 写通道。读用 ctx.http.get,写用 ctx.request 或具名动作;浏览器侧传输封装与 SSE 读取器放 actions/(如 actions/transport/)",
517
522
  "KIT-COMP-002": "业务组件定义非法:名字不是 PascalCase、没有必填角色槽、areas 重名、缺 compile(),或 composeKitBizComponents 的子部件 / 角色映射不成立",
518
523
  "KIT-COMP-003": "组件候选类 / rootClass / slotClass 含非法 Tailwind 类(不在刻度内或带方括号任意值)",
519
524
  "KIT-COMP-004": "数据组件定义 / 包装 / 登记非法:缺 define()、accept 不是 single / list、被包装组件无控制器、登记名与契约名不一致、layer 不是 data、事件名不是 snake_case,或 composeKitDataComponents 没有子部件",
520
525
  "KIT-COMP-005": "组件 templateHtml 含脚本标签、事件属性或 javascript: 地址,拒绝挂载",
521
526
  "KIT-COMP-006": "组件契约顶层 selfReport(空间与主题取色静态自报声明)字段或类型不合法(非普通对象、componentPart / host 不在闭集内,自管布局 / 取色事实非布尔,或内容宽 contentWidth 不是容器档名(soma-design adaptive#containerTiers)、写在内置组件上):宿主已隔离该自定义组件自报并回退默认渲染",
527
+ "KIT-COMP-007": "业务组件的版式契约(defineKitBizComponent / wrapKitBizComponent / composeKitBizComponents 的 layoutContract)不合法:契约角色键与组件 roles 不一一相等、identity / present / arrange / exclusive / pageMode / navRail 不在闭集、attachTo / exclusiveGroup 指向不存在、锚点拼法缺 {page} / {object} 占位、主对象多于一个(无平级组时),或用了内置领域模板专用的 grid.by: domain。用 kitLayoutContract({...}) 简写补缺省",
522
528
  "KIT-LOCALE-003": "领域包词条键非法:不以 pack. 开头,或与已登记的键重复",
523
529
  "KIT-IA-002": "(告警,不挡编译)筛选区有 ≥ 2 个模糊文本条件(text / longtext 且不带 options、也没写 filterOp,会画成多个搜索框):筛选区只画一个关键词框——schema 加一个 keyword 文本字段(不进列表 / 表单)、filter.fields 只放它,由应用列表接口薄壳把关键词转成后台查询;kit 不做「一个词拆两个参数」的或查询。按字段精确匹配的条件(账号、编码一类,接口是独立参数)写 schema.<字段>.filterOp: eq(SCON-171,formLinkage.filterOptions.op):画成带字段名标签的筛选输入框,不计入本条",
524
530
  "KIT-LOOK-001": "界面规则(look)选择器里有未知的节点种类 / 筛选键 / 组件名 / 部件名:节点种类与筛选键见 look.nodes,部件名见该组件契约的 look.parts",
@@ -546,6 +552,26 @@ export const KIT_GRAMMAR_RUNTIME = {
546
552
  "pathPattern": "^view\\.[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*$",
547
553
  "pathCoreVar": "page",
548
554
  "objectNames": {
555
+ "runtimeNames": {
556
+ "groupPrefix": {
557
+ "MultiObjectBoard.panels": "panel_",
558
+ "ReportBoard.panels": "panel_",
559
+ "StepForm.steps": "step_",
560
+ "RecordDetail.subs": "sub_",
561
+ "RecordDetail.groups": "grp_",
562
+ "LandingPage.sections": "sec_"
563
+ },
564
+ "examples": {
565
+ "StandardCrud": "<pageId>_entity",
566
+ "MultiObjectBoard": "<pageId>_panel_<面板名>;共用筛选 <pageId>_filter",
567
+ "MasterSubWorkstation": "<pageId>_master / <pageId>_<从属名>(subs 无前缀)/ <pageId>_aside",
568
+ "RecordDetail": "<pageId>_record / <pageId>_sub_<名> / <pageId>_grp_<名>",
569
+ "StepForm": "<pageId>_step_<步骤名> / <pageId>_target",
570
+ "SingleObjectForm": "<pageId>_target",
571
+ "page.overlays": "kit_page_<浮层名>(限定名 kit_page.<浮层名>)"
572
+ },
573
+ "ambiguity": "同一个声明名在整页出现多次(如两个页签都有 entity)时,裸声明名歧义:运行期 ctx 开发态告警并原样传出(命中不到对象,等于无效调用),soma kit check 报 KIT-VIEW-003 并列出可写的限定名;须写限定名 <页签 id 或槽名>.<声明名>。限定名与运行期名永远唯一"
574
+ },
549
575
  "sourceObjectProp": "source_object",
550
576
  "ai": "human-only"
551
577
  },
@@ -595,9 +621,10 @@ export const KIT_GRAMMAR_RUNTIME = {
595
621
  "action": {
596
622
  "where": "objects.<角色>.behavior.actions[] 中 on: toolbar 的动作;被 view.form.footerActions 引用的表单底栏动作(不写 on)",
597
623
  "keys": [
598
- "disabled"
624
+ "disabled",
625
+ "hidden"
599
626
  ],
600
- "values": "view 路径;路径取值为真时动作置灰;on: toolbar 的动作只支持 disabled;表单底栏动作支持 disabled / hidden(hidden 为真不画;在途的可取消动作仍可点取消);on: row 的动作 hidden / disabled 既可写 view.<成员>(展示对象给出,整页同值)也可写 row.<字段>(见 rowState,业务对象逐行给出),二选一;on: field 的动作不支持,写了报 KIT-VIEW-006"
627
+ "values": "view 路径;路径取值为真时动作置灰;on: toolbar 的动作与表单底栏动作支持 disabled / hidden(hidden 为真不画,工具条按钮连外壳一并收起、不进「更多」菜单;在途的可取消动作仍可点取消);on: row 的动作 hidden / disabled 既可写 view.<成员>(展示对象给出,整页同值)也可写 row.<字段>(见 rowState,业务对象逐行给出),二选一;on: field 的动作不支持,写了报 KIT-VIEW-006"
601
628
  },
602
629
  "form": {
603
630
  "where": "objects.<角色>.view.form",
@@ -676,7 +703,8 @@ export const KIT_GRAMMAR_RUNTIME = {
676
703
  "span",
677
704
  "class",
678
705
  "group",
679
- "head"
706
+ "head",
707
+ "whenEmpty"
680
708
  ]
681
709
  }
682
710
  },
@@ -701,7 +729,8 @@ export const KIT_GRAMMAR_RUNTIME = {
701
729
  "cancelable",
702
730
  "status",
703
731
  "pick",
704
- "bodyMap"
732
+ "bodyMap",
733
+ "with"
705
734
  ],
706
735
  "requestStatusKeys": [
707
736
  "ok",
@@ -719,7 +748,8 @@ export const KIT_GRAMMAR_RUNTIME = {
719
748
  "method",
720
749
  "filename",
721
750
  "pick",
722
- "bodyMap"
751
+ "bodyMap",
752
+ "with"
723
753
  ],
724
754
  "requestMethods": [
725
755
  "POST",
@@ -3598,7 +3628,8 @@ export const KIT_GRAMMAR_RUNTIME = {
3598
3628
  "class",
3599
3629
  "events",
3600
3630
  "editOverlay",
3601
- "rowClick"
3631
+ "rowClick",
3632
+ "draft"
3602
3633
  ],
3603
3634
  "containerEmphasis": [
3604
3635
  "primary",
@@ -3631,6 +3662,10 @@ export const KIT_GRAMMAR_RUNTIME = {
3631
3662
  ],
3632
3663
  "editOverlayType": "string",
3633
3664
  "rowClickType": "boolean",
3665
+ "overlayDraft": [
3666
+ "discard",
3667
+ "keep"
3668
+ ],
3634
3669
  "properties": {
3635
3670
  "title": {
3636
3671
  "type": "string",
@@ -3675,6 +3710,10 @@ export const KIT_GRAMMAR_RUNTIME = {
3675
3710
  "rowClick": {
3676
3711
  "type": "boolean",
3677
3712
  "description": "整行点击是否打开该浮层(布尔值)"
3713
+ },
3714
+ "draft": {
3715
+ "enumRef": "overlayDraft",
3716
+ "description": "浮层里表单草稿的去留:discard(缺省)= 关窗时有未保存修改先问、同意后还原,每次打开按本次的行重建;keep = 关窗(关闭钮 / 取消 / Esc / 点遮罩 / 后退)不询问、不还原,再次打开同一浮层(无行打开,或以同一主键且内容未变的行打开)草稿原样保留,以别的行(或同主键但内容已变的行)打开时按新行重建、旧草稿丢弃;提交成功或显式放弃(ctx.closeOverlay(名, { discard: true }) / ctx.form(对象).discard() / 表单重置)才清空。只对含表单视图(或内容数据组件在 emits 里声明并抛 dirty_change { dirty })的窗口有意义,写在不可填写的浮层或 kind: drawer 上报 KIT-OVL-005(告警;kind: expand 的展开子表不经浮层编译,draft 不生效);取值不在 discard / keep 内报 KIT-BIZ-003"
3678
3717
  }
3679
3718
  },
3680
3719
  "staticAccept": [
@@ -3760,6 +3799,7 @@ export const KIT_AI_WRITER: KitAiWriter = {
3760
3799
  "envelope": "human-only",
3761
3800
  "inherit_layout": "human-only",
3762
3801
  "view": "human-only",
3802
+ "overlays": "human-only",
3763
3803
  "look": "human-only"
3764
3804
  },
3765
3805
  "frame": {
@@ -606,6 +606,7 @@ const TEXTS = {
606
606
  'soma.kit.ct_placeholder': { 'zh-CN': '写一条评论…', en: 'Write a comment…' },
607
607
  'soma.kit.ct_attach': { 'zh-CN': '附件', en: 'Attachment' },
608
608
  'soma.kit.ct_send': { 'zh-CN': '发表', en: 'Post' },
609
+ 'soma.kit.ct_stop': { 'zh-CN': '停止', en: 'Stop' },
609
610
  // ── 字段映射(field-mapper)──
610
611
  'soma.kit.fm_unmapped': { 'zh-CN': '(未映射)', en: '(unmapped)' },
611
612
  'soma.kit.fm_source': { 'zh-CN': '来源', en: 'Source' },
@@ -14,6 +14,7 @@ import { esc } from '../shared/escape';
14
14
  import { getCompileEnvelope } from '../shared/envelope';
15
15
  import {
16
16
  KIT_ATTR_ACTION_GROUP,
17
+ KIT_ATTR_ACTION_HIDDEN,
17
18
  KIT_ATTR_AG_ITEM,
18
19
  KIT_ATTR_AG_LABEL,
19
20
  KIT_ATTR_AG_TONE,
@@ -1940,6 +1941,9 @@ function toolbarImportance(v: ButtonVariant): KitActionImportance {
1940
1941
  * 成组排布经排布引擎(action-group.ts):恒单行、文字不折行;空间不足时次要动作按优先级逐个收进「更多」(KitActionMore,菜单里危险项置末),
1941
1942
  * 主操作恒在行尾可见;视觉序取引擎 order(非主操作按声明序在前,主操作在行尾)。
1942
1943
  */
1944
+ /** 写了 hidden 的工具条动作的外壳:里面的按钮此刻隐藏(data-kit-action-hidden)时外壳一并收起,不留空位 */
1945
+ const KIT_TOOLBAR_HIDDEN_SHELL_CLASS = `has-${KIT_ATTR_ACTION_HIDDEN}:hidden`;
1946
+
1943
1947
  function renderToolbar(ctx: Ctx, actions: readonly KitAction[]): string {
1944
1948
  const declared = actions.filter((a) => a.on === 'toolbar');
1945
1949
  if (declared.length === 0) return '';
@@ -1964,6 +1968,8 @@ function renderToolbar(ctx: Ctx, actions: readonly KitAction[]): string {
1964
1968
  ...(a.builtin === 'openCreate' ? { icon: 'plus' } : {}),
1965
1969
  // 展示对象路径:路径取值为真时按钮置灰(Button 的 disabled prop)
1966
1970
  ...(a.disabled !== undefined && isViewPath(a.disabled) ? { disabled: viewPathToCore(a.disabled) } : {}),
1971
+ // 展示对象路径:路径取值为真时按钮隐藏(Button 的 hidden prop;外壳按 data-kit-action-hidden 一并收起,「更多」菜单不列)
1972
+ ...(a.hidden !== undefined && isViewPath(a.hidden) ? { hidden: viewPathToCore(a.hidden) } : {}),
1967
1973
  // 置灰原因(disabled 为真时 Button 才显示):字面量原样带,view.<成员> 编成页面变量路径;row. 路径在入口已报 KIT-VIEW-001
1968
1974
  ...toolbarReasonProp(a),
1969
1975
  // 触发具名动作:按动作名注入 busy_action(动作在途期间按钮置灰、aria-busy,随忙闲通道恢复;不从外部改 DOM)
@@ -1974,7 +1980,7 @@ function renderToolbar(ctx: Ctx, actions: readonly KitAction[]): string {
1974
1980
  };
1975
1981
  // 外壳承载「按档隐藏」类与「更多」菜单要读的标记(标签 / 语气);壳里是真按钮,菜单选中即对它 click() 回放
1976
1982
  // next:工具条动作自报元素部件「动作」(挂在外壳上:外壳是可见性与「更多」菜单的单位)
1977
- return `<div${attr('class', projection.itemClass[a.id] ?? 'shrink-0')} ${KIT_ATTR_AG_ITEM}="${esc(a.id)}" ${KIT_ATTR_AG_LABEL}="${esc(a.name)}" ${KIT_ATTR_AG_TONE}="${esc(actionToneMark(variants.get(a.id)!))}"${nextPart(ctx, 'action')}>${host('Button', id)}</div>`;
1983
+ return `<div${attr('class', a.hidden !== undefined && isViewPath(a.hidden) ? `${projection.itemClass[a.id] ?? 'shrink-0'} ${KIT_TOOLBAR_HIDDEN_SHELL_CLASS}` : projection.itemClass[a.id] ?? 'shrink-0')} ${KIT_ATTR_AG_ITEM}="${esc(a.id)}" ${KIT_ATTR_AG_LABEL}="${esc(a.name)}" ${KIT_ATTR_AG_TONE}="${esc(actionToneMark(variants.get(a.id)!))}"${nextPart(ctx, 'action')}>${host('Button', id)}</div>`;
1978
1984
  });
1979
1985
  let more = '';
1980
1986
  if (projection.plan.hasMore || projection.moreClass !== 'hidden') {
@@ -2035,10 +2041,11 @@ function emitStaticIn(ir: KitObjectIR, options: KitStaticOptions): KitStaticEmit
2035
2041
  // 行动作:row.<字段>(业务对象逐行给出)或 view.<成员>(展示对象给出,整页同值),二选一
2036
2042
  if (!isViewPath(a[key])) checkRowPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics, options.schema);
2037
2043
  }
2038
- else if (a.on === 'toolbar' && key === 'disabled') checkViewPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics);
2044
+ // 工具条动作:disabled / hidden 都只许纯 view 路径(展示对象给出;工具栏没有「行」)
2045
+ else if (a.on === 'toolbar') checkViewPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics);
2039
2046
  // 表单底栏动作(不写 on、被 view.form.footerActions 引用):disabled / hidden 都只许纯 view 路径,收集成表单的 footerState prop
2040
2047
  else if (a.on === undefined && footerIds.has(a.id)) checkViewPath(a[key], at, `动作 ${a.id} 的 ${key}`, ctx.diagnostics);
2041
- else ctx.diagnostics.push({ code: 'KIT-VIEW-006', path: at, message: `动作 ${a.id} 的 ${key} 不支持 on: ${String(a.on)}(toolbar 只支持 disabled,底栏动作(被 footerActions 引用)支持 disabled / hidden,行级可用性写在 on: row 动作上)` });
2048
+ else ctx.diagnostics.push({ code: 'KIT-VIEW-006', path: at, message: `动作 ${a.id} 的 ${key} 不支持 on: ${String(a.on)}(toolbar 与底栏动作(被 footerActions 引用)支持 disabled / hidden,写 view.<成员>;行级可用性写在 on: row 动作上)` });
2042
2049
  }
2043
2050
  // 置灰原因(形态与取值已在 closed-set 核过,这里核落点与路径):toolbar 只收字面量 / view.<成员>;row 动作收字面量 / view.<成员> / row.<字段>(字段须在 schema 里);
2044
2051
  // 表单底栏动作(由 object-form 渲染)与其它位置暂不支持,写了报 KIT-VIEW-006,不静默丢弃
@@ -140,14 +140,24 @@ export interface KitRequestSpec {
140
140
  relationIds?: string[];
141
141
  /** 危险三档档 0(KT-P-danger):撤销调用的同对象 request 动作 id;成功后给带「撤销」的轻提示 */
142
142
  undo?: string;
143
+ /**
144
+ * 请求体常量与行字段(request.with / download.with 规整后):{ 目标键: 标量字面量 | { $field: 源字段名 } },在 pick / bodyMap 之后并入;
145
+ * 没写 with 时不带这个键(配置与改前逐字一致)
146
+ */
147
+ with?: Record<string, KitRequestWithValue>;
143
148
  }
144
149
 
150
+ /** request.with 的一项(规整后、可序列化):标量字面量,或按字段取值(取值来源同 bodyMap) */
151
+ export type KitRequestWithValue = string | number | boolean | null | { readonly $field: string };
152
+
145
153
  const snake = (s: string): string => s.replace(/([A-Z])/g, '_$1').toLowerCase().replace(/[^a-z0-9_]/g, '_').replace(/_+/g, '_').replace(/^_|_$/g, '');
146
154
 
147
155
  // ---------------------------------------------------------------- 校验
148
156
 
149
157
  const PURE_FIELD_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
150
158
  const PURE_SOURCE_FIELD = /^(?:row\.)?([A-Za-z_][A-Za-z0-9_]*)$/;
159
+ /** 禁止作为请求载荷目标键或源字段名的原型链保留键(防原型污染与原型链属性泄漏) */
160
+ export const FORBIDDEN_PAYLOAD_KEYS: ReadonlySet<string> = new Set(['__proto__', 'prototype', 'constructor']);
151
161
 
152
162
  /**
153
163
  * 校验并规整 pick 与 bodyMap(只允许纯字段名映射,严禁表达式或计算逻辑)。request 与 download(SCON-168 行级下载)共用这一个判据,
@@ -158,10 +168,11 @@ export function checkRequestFieldMapping(
158
168
  at: string,
159
169
  diagnostics: KitDiagnostic[],
160
170
  label: 'request' | 'download' = 'request',
161
- ): { pick?: string[]; bodyMap?: Record<string, string>; ok: boolean } {
171
+ ): { pick?: string[]; bodyMap?: Record<string, string>; with?: Record<string, KitRequestWithValue>; ok: boolean } {
162
172
  let ok = true;
163
173
  let pick: string[] | undefined;
164
174
  let bodyMap: Record<string, string> | undefined;
175
+ let withMap: Record<string, KitRequestWithValue> | undefined;
165
176
 
166
177
  if (r.pick !== undefined) {
167
178
  if (!Array.isArray(r.pick) || r.pick.length === 0) {
@@ -182,6 +193,15 @@ export function checkRequestFieldMapping(
182
193
  return;
183
194
  }
184
195
  const f = m[1]!;
196
+ if (FORBIDDEN_PAYLOAD_KEYS.has(f)) {
197
+ diagnostics.push({
198
+ code: 'KIT-ACT-002',
199
+ path: `${at}.pick[${idx}]`,
200
+ message: `${label}.pick[${idx}] 禁止使用原型链保留键 "${f}"`,
201
+ });
202
+ ok = false;
203
+ return;
204
+ }
185
205
  if (seen.has(f)) {
186
206
  diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.pick[${idx}]`, message: `${label}.pick 字段名 "${f}" 重复` });
187
207
  ok = false;
@@ -210,6 +230,15 @@ export function checkRequestFieldMapping(
210
230
  ok = false;
211
231
  continue;
212
232
  }
233
+ if (FORBIDDEN_PAYLOAD_KEYS.has(targetKey)) {
234
+ diagnostics.push({
235
+ code: 'KIT-ACT-002',
236
+ path: `${at}.bodyMap.${targetKey}`,
237
+ message: `${label}.bodyMap 的目标键 "${targetKey}" 禁止使用原型链保留键`,
238
+ });
239
+ ok = false;
240
+ continue;
241
+ }
213
242
  const m = typeof sourceRaw === 'string' ? PURE_SOURCE_FIELD.exec(sourceRaw) : null;
214
243
  if (!m) {
215
244
  diagnostics.push({
@@ -220,13 +249,89 @@ export function checkRequestFieldMapping(
220
249
  ok = false;
221
250
  continue;
222
251
  }
223
- mapped[targetKey] = m[1]!;
252
+ const sourceField = m[1]!;
253
+ if (FORBIDDEN_PAYLOAD_KEYS.has(sourceField)) {
254
+ diagnostics.push({
255
+ code: 'KIT-ACT-002',
256
+ path: `${at}.bodyMap.${targetKey}`,
257
+ message: `${label}.bodyMap.${targetKey} 的源字段 "${sourceField}" 禁止使用原型链保留键`,
258
+ });
259
+ ok = false;
260
+ continue;
261
+ }
262
+ mapped[targetKey] = sourceField;
224
263
  }
225
264
  if (Object.keys(mapped).length > 0) bodyMap = mapped;
226
265
  }
227
266
  }
228
267
 
229
- return { ...(pick !== undefined ? { pick } : {}), ...(bodyMap !== undefined ? { bodyMap } : {}), ok };
268
+ // with:协议常量与行字段({ 键: 标量字面量 | row.<字段> }),在 pick / bodyMap 之后并入;仍是纯声明,不收表达式 / $ 路径 / 对象字面量
269
+ if (r.with !== undefined) {
270
+ if (!isRec(r.with) || Object.keys(r.with).length === 0) {
271
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.with`, message: `${label}.with 必须是非空 { 键: 标量字面量 | row.<字段> } 对象` });
272
+ ok = false;
273
+ } else {
274
+ const taken = new Set<string>([...(pick ?? []), ...Object.keys(bodyMap ?? {})]);
275
+ const out: Record<string, KitRequestWithValue> = {};
276
+ for (const [key, value] of Object.entries(r.with)) {
277
+ const path = `${at}.with.${key}`;
278
+ if (!PURE_FIELD_KEY.test(key)) {
279
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with 的键 "${key}" 必须是纯字段标识符` });
280
+ ok = false;
281
+ continue;
282
+ }
283
+ if (FORBIDDEN_PAYLOAD_KEYS.has(key)) {
284
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with 的键 "${key}" 禁止使用原型链保留键` });
285
+ ok = false;
286
+ continue;
287
+ }
288
+ if (taken.has(key)) {
289
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with.${key} 与 pick / bodyMap 的目标键重复(同一个键只能有一个来源)` });
290
+ ok = false;
291
+ continue;
292
+ }
293
+ if (typeof value === 'string') {
294
+ if (value.startsWith('view.')) {
295
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with.${key} 暂不支持 view.<成员>(页面级动作宿主读不到展示对象状态):展示对象成员改由 ctx.request(对象, 动作 id, 载荷) 带进,或接口一侧补` });
296
+ ok = false;
297
+ continue;
298
+ }
299
+ if (value.startsWith('$')) {
300
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with.${key} 不收 $ 取值路径(收到 ${JSON.stringify(value)}):行字段写 row.<字段>,常量写字面量` });
301
+ ok = false;
302
+ continue;
303
+ }
304
+ if (value.startsWith('row.')) {
305
+ const m = /^row\.([A-Za-z_][A-Za-z0-9_]*)$/.exec(value);
306
+ if (m === null) {
307
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with.${key} 的 row. 取值只许单段字段名 row.<字段>(收到 ${JSON.stringify(value)})` });
308
+ ok = false;
309
+ continue;
310
+ }
311
+ const sourceField = m[1]!;
312
+ if (FORBIDDEN_PAYLOAD_KEYS.has(sourceField)) {
313
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with.${key} 的源字段 "${sourceField}" 禁止使用原型链保留键` });
314
+ ok = false;
315
+ continue;
316
+ }
317
+ out[key] = { $field: sourceField };
318
+ continue;
319
+ }
320
+ out[key] = value;
321
+ continue;
322
+ }
323
+ if (value === null || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value))) {
324
+ out[key] = value;
325
+ continue;
326
+ }
327
+ diagnostics.push({ code: 'KIT-ACT-002', path, message: `${label}.with.${key} 只收字符串 / 有限数字 / 布尔 / null 字面量或 row.<字段>(收到 ${Array.isArray(value) ? '数组' : typeof value})` });
328
+ ok = false;
329
+ }
330
+ if (Object.keys(out).length > 0) withMap = out;
331
+ }
332
+ }
333
+
334
+ return { ...(pick !== undefined ? { pick } : {}), ...(bodyMap !== undefined ? { bodyMap } : {}), ...(withMap !== undefined ? { with: withMap } : {}), ok };
230
335
  }
231
336
 
232
337
 
@@ -386,10 +491,12 @@ export function noteRequestRelationFields(object: string, fields: readonly strin
386
491
  }
387
492
 
388
493
  /** pick / bodyMap 取的源字段(去掉 row. 前缀、去重、按声明序)里属于关联字段的那些(SCON-177);没有返回空对象,有则 { relationIds } */
389
- function relationIdsProp(mapping: { pick?: readonly string[]; bodyMap?: Readonly<Record<string, string>> }, object: string): { relationIds?: string[] } {
494
+ function relationIdsProp(mapping: { pick?: readonly string[]; bodyMap?: Readonly<Record<string, string>>; with?: Readonly<Record<string, KitRequestWithValue>> }, object: string): { relationIds?: string[] } {
390
495
  const fields = relationIdFieldsByObject?.get(object) ?? [];
391
496
  if (fields.length === 0) return {};
392
- const sources = [...(mapping.pick ?? []), ...Object.values(mapping.bodyMap ?? {})].map((f) => (f.startsWith('row.') ? f.slice(4) : f));
497
+ // with 里按字段取值的项(row.<字段>)同样按 id 取
498
+ const withFields = Object.values(mapping.with ?? {}).flatMap((v) => (isRec(v) && typeof v.$field === 'string' ? [v.$field] : []));
499
+ const sources = [...(mapping.pick ?? []), ...Object.values(mapping.bodyMap ?? {}), ...withFields].map((f) => (f.startsWith('row.') ? f.slice(4) : f));
393
500
  const hit = [...new Set(sources)].filter((f) => fields.includes(f));
394
501
  return hit.length > 0 ? { relationIds: hit } : {};
395
502
  }
@@ -469,6 +576,7 @@ export function registerRequestAction(
469
576
  ...(r.timeoutMs !== undefined ? { timeoutMs: r.timeoutMs } : {}),
470
577
  ...(mapping.pick !== undefined ? { pick: mapping.pick } : {}),
471
578
  ...(mapping.bodyMap !== undefined ? { bodyMap: mapping.bodyMap } : {}),
579
+ ...(mapping.with !== undefined ? { with: mapping.with } : {}),
472
580
  // SCON-177:映射到的关联字段(取 id);没有时不带
473
581
  ...relationIdsProp(mapping, object),
474
582
  // undo 只在档 0 才留在动作上(compile/danger-tier.ts#applyDangerTiers 改写过)
@@ -483,6 +591,7 @@ export function registerRequestAction(
483
591
  ...(d.filename !== undefined ? { filename: d.filename } : {}),
484
592
  ...(mapping.pick !== undefined ? { pick: mapping.pick } : {}),
485
593
  ...(mapping.bodyMap !== undefined ? { bodyMap: mapping.bodyMap } : {}),
594
+ ...(mapping.with !== undefined ? { with: mapping.with } : {}),
486
595
  // SCON-177:映射到的关联字段(取 id);没有时不带
487
596
  ...relationIdsProp(mapping, object),
488
597
  };
@@ -502,8 +611,10 @@ export function requestWriteObjects(specs: ReadonlyMap<string, KitRequestSpec>):
502
611
  const onlyKeys = [
503
612
  ...(spec.pick ?? []),
504
613
  ...(spec.bodyMap ? Object.keys(spec.bodyMap) : []),
614
+ // with 的键同样圈进 write.only(否则 core 写通道会把常量从请求体里滤掉)
615
+ ...(spec.with ? Object.keys(spec.with) : []),
505
616
  ];
506
- const uniqueOnly = [...new Set(onlyKeys)];
617
+ const uniqueOnly = [...new Set(onlyKeys)].filter((k) => !FORBIDDEN_PAYLOAD_KEYS.has(k));
507
618
  // 只用来圈定请求体可出现的键(write.only):不声明 type —— 值可能是数组(ids)、数字(version)或对象,
508
619
  // 写类型会让 core 按类型规整(且 core 字段类型闭集里没有 string,旧写法整页注入失败 CORE-INJECT-PAGE-CLOSURE)
509
620
  const fields: Record<string, { name: string }> = {};
@@ -540,7 +651,7 @@ function relationIdReader(read: (field: string) => unknown, relationIds: readonl
540
651
  * - relationIds 里的源字段(引用形态的关联字段,SCON-177)取 id:{ id, name } → id,多值 → id 数组。
541
652
  */
542
653
  export function buildRequestPayload(
543
- spec: Pick<KitRequestSpec, 'pick' | 'bodyMap' | 'relationIds'>,
654
+ spec: Pick<KitRequestSpec, 'pick' | 'bodyMap' | 'relationIds' | 'with'>,
544
655
  sources: Readonly<Record<string, unknown>> | ReadonlyArray<Readonly<Record<string, unknown>> | undefined>,
545
656
  ): Record<string, unknown> {
546
657
  const list: ReadonlyArray<Readonly<Record<string, unknown>>> = Array.isArray(sources)
@@ -549,11 +660,12 @@ export function buildRequestPayload(
549
660
  ? [sources]
550
661
  : [];
551
662
  const readField = relationIdReader((field) => {
663
+ if (FORBIDDEN_PAYLOAD_KEYS.has(field)) return undefined;
552
664
  for (const src of list) {
553
- if (field in src && src[field] !== undefined) return src[field];
554
- if (isRec(src.row) && field in src.row && src.row[field] !== undefined) return src.row[field];
555
- if (isRec(src.record) && field in src.record && src.record[field] !== undefined) return src.record[field];
556
- if (isRec(src.values) && field in src.values && src.values[field] !== undefined) return src.values[field];
665
+ if (Object.hasOwn(src, field) && src[field] !== undefined) return src[field];
666
+ if (isRec(src.row) && Object.hasOwn(src.row, field) && src.row[field] !== undefined) return src.row[field];
667
+ if (isRec(src.record) && Object.hasOwn(src.record, field) && src.record[field] !== undefined) return src.record[field];
668
+ if (isRec(src.values) && Object.hasOwn(src.values, field) && src.values[field] !== undefined) return src.values[field];
557
669
  }
558
670
  return undefined;
559
671
  }, spec.relationIds);
@@ -561,17 +673,31 @@ export function buildRequestPayload(
561
673
  if (Array.isArray(spec.pick)) {
562
674
  for (const rawKey of spec.pick) {
563
675
  const key = rawKey.startsWith('row.') ? rawKey.slice(4) : rawKey;
676
+ if (FORBIDDEN_PAYLOAD_KEYS.has(key)) continue;
564
677
  const val = readField(key);
565
678
  if (val !== undefined) out[key] = val;
566
679
  }
567
680
  }
568
681
  if (isRec(spec.bodyMap)) {
569
682
  for (const [targetKey, sourceRaw] of Object.entries(spec.bodyMap)) {
570
- if (typeof sourceRaw !== 'string') continue;
683
+ if (FORBIDDEN_PAYLOAD_KEYS.has(targetKey) || typeof sourceRaw !== 'string') continue;
571
684
  const val = readField(sourceRaw);
572
685
  if (val !== undefined) out[targetKey] = val;
573
686
  }
574
687
  }
688
+ // with:最后并入——字面量原样(含 null),{ $field } 按字段取值(来源同上,取不到不带);常量不被行数据覆盖
689
+ if (isRec(spec.with)) {
690
+ for (const [key, value] of Object.entries(spec.with)) {
691
+ if (FORBIDDEN_PAYLOAD_KEYS.has(key)) continue;
692
+ if (isRec(value)) {
693
+ if (typeof value.$field !== 'string') continue;
694
+ const val = readField(value.$field);
695
+ if (val !== undefined) out[key] = val;
696
+ } else {
697
+ out[key] = value;
698
+ }
699
+ }
700
+ }
575
701
  return out;
576
702
  }
577
703
 
@@ -621,12 +747,13 @@ export function applyRequestPayloadMapping(
621
747
  mapping: { pick?: readonly string[]; bodyMap?: Readonly<Record<string, string>>; relationIds?: readonly string[] },
622
748
  ): Record<string, unknown> {
623
749
  const readField = relationIdReader((field) => {
750
+ if (FORBIDDEN_PAYLOAD_KEYS.has(field)) return undefined;
624
751
  if (source && typeof source === "object") {
625
- if (field in source && source[field] !== undefined) return source[field];
752
+ if (Object.hasOwn(source, field) && source[field] !== undefined) return source[field];
626
753
  const s = source;
627
- if (isRec(s.row) && field in s.row && s.row[field] !== undefined) return s.row[field];
628
- if (isRec(s.record) && field in s.record && s.record[field] !== undefined) return s.record[field];
629
- if (isRec(s.values) && field in s.values && s.values[field] !== undefined) return s.values[field];
754
+ if (isRec(s.row) && Object.hasOwn(s.row, field) && s.row[field] !== undefined) return s.row[field];
755
+ if (isRec(s.record) && Object.hasOwn(s.record, field) && s.record[field] !== undefined) return s.record[field];
756
+ if (isRec(s.values) && Object.hasOwn(s.values, field) && s.values[field] !== undefined) return s.values[field];
630
757
  }
631
758
  return undefined;
632
759
  }, mapping.relationIds);
@@ -638,7 +765,7 @@ export function applyRequestPayloadMapping(
638
765
 
639
766
  if (isRec(bodyMap)) {
640
767
  for (const [targetKey, sourceRaw] of Object.entries(bodyMap)) {
641
- if (typeof sourceRaw !== "string") continue;
768
+ if (FORBIDDEN_PAYLOAD_KEYS.has(targetKey) || typeof sourceRaw !== "string") continue;
642
769
  const cleanSource = sourceRaw.startsWith("row.") ? sourceRaw.slice(4) : sourceRaw;
643
770
  mappedSourceKeys.add(cleanSource);
644
771
  const val = readField(sourceRaw);
@@ -649,6 +776,7 @@ export function applyRequestPayloadMapping(
649
776
  if (Array.isArray(pick)) {
650
777
  for (const rawKey of pick) {
651
778
  const key = rawKey.startsWith("row.") ? rawKey.slice(4) : rawKey;
779
+ if (FORBIDDEN_PAYLOAD_KEYS.has(key)) continue;
652
780
  if (!mappedSourceKeys.has(key)) {
653
781
  const val = readField(key);
654
782
  if (val !== undefined) out[key] = val;
@@ -196,6 +196,11 @@ export interface KitRequestDecl {
196
196
  pick?: string[];
197
197
  /** 纯字段名重命名映射({ 请求体键名: 源字段名 },禁止表达式) */
198
198
  bodyMap?: Record<string, string>;
199
+ /**
200
+ * 请求体常量与行字段({ 键: 标量字面量 | 'row.<字段>' }):在 pick / bodyMap 之后并入(常量不被行数据覆盖),键不得与 pick / bodyMap 重复;
201
+ * 对象 / 数组、$ 路径报 KIT-ACT-002;view.<成员> 本版不支持(报 KIT-ACT-002,改由 ctx.request 载荷带进)
202
+ */
203
+ with?: Record<string, string | number | boolean | null>;
199
204
  }
200
205
 
201
206
  export interface KitDownloadDecl {
@@ -206,6 +211,8 @@ export interface KitDownloadDecl {
206
211
  pick?: string[];
207
212
  /** 纯字段名重命名映射(SCON-168:{ 参数名: 源字段名 },禁止表达式) */
208
213
  bodyMap?: Record<string, string>;
214
+ /** 下载参数常量与行字段(同 request.with:{ 参数名: 标量字面量 | 'row.<字段>' },在 pick / bodyMap 之后并入) */
215
+ with?: Record<string, string | number | boolean | null>;
209
216
  }
210
217
 
211
218
  export interface KitListShape {