soma-kit 0.1.11 → 0.1.13

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 (376) hide show
  1. package/README.md +106 -112
  2. package/bin/soma-kit.mjs +32 -2
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +14 -7
  5. package/packs/finance/reconcile-board.ts +5 -2
  6. package/packs/finance/reconcile-desk/compile.ts +3 -2
  7. package/spec/generated/kit-app.schema.json +929 -37
  8. package/spec/generated/kit-page.schema.json +1684 -161
  9. package/spec/kit-grammar.json +1176 -584
  10. package/spec/kit-grammar.schema.json +1971 -393
  11. package/src/app/app-config.ts +449 -347
  12. package/src/app/component-gate.ts +283 -28
  13. package/src/app/compose-apps.ts +79 -8
  14. package/src/app/define-kit-actions.ts +245 -41
  15. package/src/app/define-kit-app.ts +176 -33
  16. package/src/app/define-kit-view.ts +104 -0
  17. package/src/app/dev-diagnostic.ts +5 -0
  18. package/src/app/envelope.ts +1 -161
  19. package/src/app/index.ts +29 -6
  20. package/src/app/kit-view-context.ts +439 -0
  21. package/src/app/notify-renderer.ts +1 -115
  22. package/src/app/paged-list-adapter.ts +1 -240
  23. package/src/app/render-ports.ts +18 -0
  24. package/src/app/server-pages.ts +11 -3
  25. package/src/app/server.ts +530 -103
  26. package/src/app/submit.types.ts +1 -1
  27. package/src/app/theme-endpoint.ts +63 -0
  28. package/src/app/theme-runtime-shared.ts +1 -0
  29. package/src/app/theme-runtime.ts +667 -0
  30. package/src/base/action-busy.ts +103 -6
  31. package/src/base/action-gate.ts +4 -255
  32. package/src/base/action-slots.ts +58 -0
  33. package/src/base/alert.ts +5 -3
  34. package/src/base/anchored-layer.ts +50 -0
  35. package/src/base/avatar.ts +2 -2
  36. package/src/base/button.ts +99 -37
  37. package/src/base/cascader.ts +11 -12
  38. package/src/base/check-core.ts +9 -1
  39. package/src/base/checkbox.ts +2 -1
  40. package/src/base/choice.ts +49 -28
  41. package/src/base/class-candidates.ts +17 -0
  42. package/src/base/color-picker.ts +16 -11
  43. package/src/base/combobox.ts +5 -3
  44. package/src/base/command-palette.ts +10 -6
  45. package/src/base/context-menu.ts +10 -7
  46. package/src/base/countdown.ts +1 -1
  47. package/src/base/date-range.ts +32 -18
  48. package/src/base/date.ts +135 -28
  49. package/src/base/delta.ts +72 -0
  50. package/src/base/divider.ts +2 -2
  51. package/src/base/end-edge.ts +49 -0
  52. package/src/base/fab.ts +12 -5
  53. package/src/base/gap-value.ts +148 -0
  54. package/src/base/hint-tips.ts +170 -0
  55. package/src/base/icons.ts +8 -0
  56. package/src/base/illustrations.ts +94 -0
  57. package/src/base/image.ts +1 -1
  58. package/src/base/index.ts +35 -11
  59. package/src/base/input.ts +42 -13
  60. package/src/base/kbd.ts +3 -1
  61. package/src/base/link.ts +4 -4
  62. package/src/base/listbox-core.ts +56 -35
  63. package/src/base/loading-gate.ts +186 -0
  64. package/src/base/mentions.ts +7 -6
  65. package/src/base/menu-button.ts +28 -12
  66. package/src/base/menu-core.ts +41 -8
  67. package/src/base/motion/aura.ts +2 -2
  68. package/src/base/motion/hover-3d.ts +3 -3
  69. package/src/base/motion/hover-gallery.ts +2 -2
  70. package/src/base/motion/marquee.ts +3 -3
  71. package/src/base/motion/text-rotate.ts +2 -2
  72. package/src/base/number.ts +93 -80
  73. package/src/base/otp.ts +9 -5
  74. package/src/base/overlay-runtime.ts +235 -0
  75. package/src/base/permission-gate.ts +6 -0
  76. package/src/base/popover.ts +48 -16
  77. package/src/base/popup.ts +143 -19
  78. package/src/base/portal-core.ts +4 -0
  79. package/src/base/price-text.ts +2 -2
  80. package/src/base/progress.ts +2 -2
  81. package/src/base/qr-code.ts +4 -4
  82. package/src/base/qty-stepper.ts +14 -8
  83. package/src/base/radio.ts +2 -1
  84. package/src/base/range.ts +21 -4
  85. package/src/base/rating.ts +12 -7
  86. package/src/base/reason-tip.ts +150 -0
  87. package/src/base/segmented.ts +27 -21
  88. package/src/base/select.ts +4 -3
  89. package/src/base/shared.ts +387 -49
  90. package/src/base/state-panel.ts +346 -0
  91. package/src/base/status-tone.ts +27 -0
  92. package/src/base/sticky-edge.ts +116 -0
  93. package/src/base/swap.ts +10 -7
  94. package/src/base/switch.ts +11 -6
  95. package/src/base/tag-input.ts +20 -16
  96. package/src/base/tag.ts +68 -34
  97. package/src/base/text.ts +80 -18
  98. package/src/base/textarea.ts +37 -11
  99. package/src/base/time-picker.ts +18 -13
  100. package/src/base/tree-select.ts +21 -12
  101. package/src/base/trend-tone.ts +9 -0
  102. package/src/base/upload.ts +48 -14
  103. package/src/base/view-transition.ts +77 -0
  104. package/src/base/virtual-list.ts +107 -1
  105. package/src/biz/approval-desk/compile.ts +23 -41
  106. package/src/biz/approval-desk/shell.ts +11 -8
  107. package/src/biz/auth-panel/compile.ts +37 -52
  108. package/src/biz/auth-panel/index.ts +1 -1
  109. package/src/biz/auth-panel/shell.ts +5 -4
  110. package/src/biz/category-crud/compile.ts +23 -37
  111. package/src/biz/category-crud/shell.ts +2 -1
  112. package/src/biz/checkout-page/compile.ts +22 -5
  113. package/src/biz/checkout-page/shell.ts +4 -3
  114. package/src/biz/compose.ts +13 -27
  115. package/src/biz/define.ts +5 -4
  116. package/src/biz/import-wizard/compile.ts +22 -26
  117. package/src/biz/import-wizard/hub.ts +126 -61
  118. package/src/biz/import-wizard/shell.ts +5 -4
  119. package/src/biz/index.ts +3 -3
  120. package/src/biz/landing-page/compile.ts +19 -3
  121. package/src/biz/link/hub.ts +69 -22
  122. package/src/biz/link/shared.ts +127 -119
  123. package/src/biz/master-sub/compile.ts +127 -48
  124. package/src/biz/master-sub/index.ts +5 -2
  125. package/src/biz/master-sub/shell.ts +95 -18
  126. package/src/biz/multi-board/compile.ts +38 -50
  127. package/src/biz/multi-board/index.ts +18 -1
  128. package/src/biz/multi-board/shell.ts +32 -20
  129. package/src/biz/notification-center/compile.ts +21 -33
  130. package/src/biz/notification-center/shell.ts +6 -4
  131. package/src/biz/page-templates/domain-templates.ts +80 -13
  132. package/src/biz/page-templates/result-page/compile.ts +11 -2
  133. package/src/biz/page-templates/result-page/shell.ts +2 -1
  134. package/src/biz/page-templates/shared.ts +34 -36
  135. package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
  136. package/src/biz/record-detail/compile.ts +48 -43
  137. package/src/biz/record-detail/index.ts +11 -1
  138. package/src/biz/record-detail/shell.ts +8 -6
  139. package/src/biz/settings-center/compile.ts +7 -5
  140. package/src/biz/settings-center/shell.ts +6 -4
  141. package/src/biz/shared/action-host.ts +97 -211
  142. package/src/biz/shared/compile-helpers.ts +98 -0
  143. package/src/biz/shared/coordinator.ts +472 -92
  144. package/src/biz/shared/index.ts +13 -2
  145. package/src/biz/shared/object-aliases.ts +154 -0
  146. package/src/biz/shared/overlay-compile.ts +239 -0
  147. package/src/biz/shared/overlay-shell.ts +209 -0
  148. package/src/biz/shared/pipes.ts +50 -31
  149. package/src/biz/shared/remove-wire.ts +14 -0
  150. package/src/biz/shared/runtime-hub.ts +226 -24
  151. package/src/biz/single-form/compile.ts +16 -37
  152. package/src/biz/single-form/shell.ts +4 -3
  153. package/src/biz/standard-crud/compile.ts +72 -255
  154. package/src/biz/standard-crud/shell.ts +21 -99
  155. package/src/biz/step-form/compile.ts +26 -97
  156. package/src/biz/step-form/hub.ts +34 -41
  157. package/src/biz/step-form/shell.ts +5 -5
  158. package/src/biz/types.ts +4 -3
  159. package/src/cli/core-imports.ts +54 -0
  160. package/src/cli/kit-cli.ts +254 -25
  161. package/src/cli/kit-init.ts +227 -0
  162. package/src/cli/layout-cli.ts +167 -0
  163. package/src/cli/migrate/index.ts +10 -0
  164. package/src/cli/migrate/migrate.ts +248 -0
  165. package/src/cli/migrate/text-utils.ts +306 -0
  166. package/src/cli/migrate/theme-map.ts +104 -0
  167. package/src/cli/migrate/ts-rules.ts +235 -0
  168. package/src/cli/migrate/types.ts +95 -0
  169. package/src/cli/migrate/view-skeleton.ts +159 -0
  170. package/src/cli/migrate/yaml-report.ts +376 -0
  171. package/src/cli/migrate/yaml-rules.ts +465 -0
  172. package/src/cli/service-endpoint-check.ts +425 -0
  173. package/src/cli/source-path-check.d.mts +17 -0
  174. package/src/cli/source-path-check.mjs +334 -0
  175. package/src/cli/view-writes.ts +761 -0
  176. package/src/compile/action-host-attach.ts +21 -29
  177. package/src/compile/closed-set.ts +570 -0
  178. package/src/compile/compile-page.ts +267 -76
  179. package/src/compile/component-candidates.ts +13 -2
  180. package/src/compile/hints.ts +30 -1
  181. package/src/compile/index.ts +1 -0
  182. package/src/compile/kit-error.ts +1 -0
  183. package/src/compile/layout-lint/engine.ts +82 -0
  184. package/src/compile/layout-lint/index.ts +55 -0
  185. package/src/compile/layout-lint/rules-composition.ts +218 -0
  186. package/src/compile/layout-lint/rules-form.ts +192 -0
  187. package/src/compile/layout-lint/rules-table.ts +194 -0
  188. package/src/compile/layout-lint/score.ts +52 -0
  189. package/src/compile/layout-lint/types.ts +51 -0
  190. package/src/compile/locate.ts +21 -1
  191. package/src/compile/parse.ts +370 -41
  192. package/src/compile/redirect.ts +6 -2
  193. package/src/compile/remove-guard.ts +10 -7
  194. package/src/compile/styles.ts +63 -2
  195. package/src/compile/types.ts +31 -3
  196. package/src/compile/view-check.ts +284 -0
  197. package/src/data/amount-breakdown.ts +8 -3
  198. package/src/data/anchor-nav.ts +2 -2
  199. package/src/data/approval-flow.ts +3 -3
  200. package/src/data/assignment-picker.ts +92 -55
  201. package/src/data/async-result-panel.ts +111 -9
  202. package/src/data/breadcrumbs.ts +5 -4
  203. package/src/data/calendar.ts +24 -27
  204. package/src/data/carousel.ts +13 -8
  205. package/src/data/chart.ts +183 -44
  206. package/src/data/checklist.ts +20 -7
  207. package/src/data/code-view.ts +12 -6
  208. package/src/data/comment-thread.ts +7 -4
  209. package/src/data/confirm-dialog.ts +81 -18
  210. package/src/data/context-menu.ts +29 -37
  211. package/src/data/d9-util.ts +2 -18
  212. package/src/data/diff.ts +4 -2
  213. package/src/data/dock.ts +3 -3
  214. package/src/data/embed.ts +233 -30
  215. package/src/data/field-mapper.ts +35 -30
  216. package/src/data/flow-editor-contract.ts +8 -1
  217. package/src/data/flow-editor.ts +113 -108
  218. package/src/data/flow-node-options.ts +120 -0
  219. package/src/data/flow-remote-options.ts +0 -103
  220. package/src/data/footer.ts +2 -2
  221. package/src/data/form-draft-registry.ts +2 -4
  222. package/src/data/gantt.ts +19 -19
  223. package/src/data/hero.ts +4 -3
  224. package/src/data/image-viewer.ts +27 -30
  225. package/src/data/index.ts +5 -2
  226. package/src/data/item-list.ts +48 -31
  227. package/src/data/kanban.ts +82 -52
  228. package/src/data/media-grid.ts +20 -20
  229. package/src/data/mega-menu.ts +6 -4
  230. package/src/data/menu-dom.ts +4 -2
  231. package/src/data/menu.ts +47 -15
  232. package/src/data/mockup.ts +10 -6
  233. package/src/data/modal-dialog.ts +49 -25
  234. package/src/data/navbar.ts +12 -7
  235. package/src/data/notice-list.ts +268 -0
  236. package/src/data/notify-renderer.ts +250 -0
  237. package/src/data/object-form.ts +1360 -666
  238. package/src/data/outcome-watch.ts +61 -2
  239. package/src/data/pager.ts +80 -34
  240. package/src/data/permission-matrix.ts +52 -31
  241. package/src/data/permission-tree.ts +71 -44
  242. package/src/data/pricing-table.ts +30 -14
  243. package/src/data/prompt-dialog.ts +124 -194
  244. package/src/data/reaction-bar.ts +83 -92
  245. package/src/data/read-rollback.ts +73 -0
  246. package/src/data/record-card.ts +26 -5
  247. package/src/data/record-picker.ts +104 -55
  248. package/src/data/redirect.ts +32 -32
  249. package/src/data/remote-options.ts +13 -6
  250. package/src/data/request-console.ts +5 -3
  251. package/src/data/resident.ts +2 -1
  252. package/src/data/result-panel.ts +8 -4
  253. package/src/data/rich-text.ts +61 -55
  254. package/src/data/row-editor.ts +362 -76
  255. package/src/data/rule-builder.ts +26 -20
  256. package/src/data/shape-util.ts +27 -9
  257. package/src/data/stat-group.ts +392 -109
  258. package/src/data/static-lazy.ts +1 -0
  259. package/src/data/static-registry.ts +24 -11
  260. package/src/data/steps.ts +10 -5
  261. package/src/data/survey.ts +27 -32
  262. package/src/data/system-switcher.ts +3 -3
  263. package/src/data/text-action-button.ts +17 -0
  264. package/src/data/timeline.ts +19 -8
  265. package/src/data/tour-guide.ts +23 -30
  266. package/src/data/transfer.ts +62 -38
  267. package/src/data/tree-table.ts +152 -78
  268. package/src/data/tree.ts +49 -36
  269. package/src/data/trend-line.ts +6 -24
  270. package/src/data/virtual-rows.ts +133 -82
  271. package/src/data/watermark.ts +2 -2
  272. package/src/data/wrap.ts +63 -38
  273. package/src/data/wrapped-candidates.ts +10 -0
  274. package/src/frames/blank-frame.ts +1 -0
  275. package/src/frames/index.ts +2 -2
  276. package/src/frames/page-bar.ts +26 -24
  277. package/src/frames/page-header.ts +14 -5
  278. package/src/frames/page-status.ts +9 -7
  279. package/src/frames/shared.ts +36 -25
  280. package/src/frames/single-frame.ts +1 -0
  281. package/src/frames/split-frame/shell.ts +6 -6
  282. package/src/frames/split-frame/wiring.ts +2 -2
  283. package/src/frames/tabs-frame/shell.ts +4 -14
  284. package/src/frames/tabs-frame/wiring.ts +5 -8
  285. package/src/frames/top-main-frame.ts +3 -2
  286. package/src/frames/types.ts +13 -2
  287. package/src/frames/workspace-frame/extras.ts +21 -5
  288. package/src/frames/workspace-frame/index.ts +1 -1
  289. package/src/frames/workspace-frame/shell.ts +3 -2
  290. package/src/frames/workspace-frame/state.ts +13 -6
  291. package/src/frames/workspace-frame/view.ts +250 -48
  292. package/src/generated/kit-grammar-runtime.ts +645 -397
  293. package/src/generated/page-origin.ts +0 -11
  294. package/src/i18n/kit-text.ts +84 -29
  295. package/src/i18n/resolve-text-refs.ts +22 -6
  296. package/src/index.ts +2 -1
  297. package/src/object-renderer/action-gate.ts +11 -147
  298. package/src/object-renderer/arrange.ts +112 -84
  299. package/src/object-renderer/collapse-wiring.ts +2 -2
  300. package/src/object-renderer/collection-expand.ts +2 -2
  301. package/src/object-renderer/collection-parts.ts +401 -104
  302. package/src/object-renderer/collection-table.ts +287 -45
  303. package/src/object-renderer/collection.ts +258 -104
  304. package/src/object-renderer/compile-data.ts +112 -102
  305. package/src/object-renderer/crud-bridge.ts +32 -0
  306. package/src/object-renderer/defaults.ts +38 -16
  307. package/src/object-renderer/display-checks.ts +4 -25
  308. package/src/object-renderer/emit-events.ts +224 -176
  309. package/src/object-renderer/emit-object.ts +15 -2
  310. package/src/object-renderer/emit-static.ts +533 -151
  311. package/src/object-renderer/field-value.ts +593 -396
  312. package/src/object-renderer/filter-reload.ts +70 -0
  313. package/src/object-renderer/form-detail.ts +111 -2
  314. package/src/object-renderer/form-notify.ts +45 -0
  315. package/src/object-renderer/index.ts +26 -0
  316. package/src/object-renderer/key-field.ts +12 -0
  317. package/src/object-renderer/layout-facts.ts +386 -0
  318. package/src/object-renderer/layout-plan.ts +132 -0
  319. package/src/object-renderer/layout-plan.types.ts +22 -0
  320. package/src/object-renderer/linkage.ts +7 -270
  321. package/src/object-renderer/merge-class.ts +18 -1
  322. package/src/object-renderer/parts.ts +252 -1
  323. package/src/object-renderer/path-pick.ts +27 -0
  324. package/src/object-renderer/render-object.ts +456 -89
  325. package/src/object-renderer/request-actions.ts +232 -249
  326. package/src/object-renderer/skeleton.ts +58 -19
  327. package/src/object-renderer/table-actions.ts +319 -111
  328. package/src/object-renderer/table-summary.ts +2 -2
  329. package/src/object-renderer/table-tools.ts +429 -94
  330. package/src/object-renderer/types.ts +204 -127
  331. package/src/object-renderer/view-binding.ts +393 -0
  332. package/src/page-target/ai-surface.ts +37 -0
  333. package/src/page-target/compile.ts +48 -8
  334. package/src/page-target/index.ts +8 -1
  335. package/src/page-target/intent-schema.ts +165 -28
  336. package/src/page-target/target.ts +262 -51
  337. package/src/page-target/writer-policy.ts +14 -3
  338. package/src/recipes/container.ts +210 -0
  339. package/src/recipes/control.ts +277 -0
  340. package/src/recipes/index.ts +312 -0
  341. package/src/recipes/nowrap.ts +16 -0
  342. package/src/recipes/overlay.ts +240 -0
  343. package/src/recipes/placeholder.ts +79 -0
  344. package/src/recipes/rail-grid.ts +45 -0
  345. package/src/recipes/slot-align.ts +56 -0
  346. package/src/recipes/state.ts +99 -0
  347. package/src/recipes/status.ts +139 -0
  348. package/src/recipes/surface.ts +40 -0
  349. package/src/recipes/table-row.ts +88 -0
  350. package/src/recipes/title-row.ts +37 -0
  351. package/src/recipes/typography.ts +99 -0
  352. package/src/shared/action-field-guard.ts +41 -0
  353. package/src/shared/confirm-decl.ts +118 -0
  354. package/src/shared/envelope.ts +207 -0
  355. package/src/shared/escape.ts +57 -0
  356. package/src/shared/kit-error.ts +21 -0
  357. package/src/shared/paged-list-adapter.ts +15 -0
  358. package/src/shared/path-guard.ts +127 -0
  359. package/src/shared/theme-runtime-shared.ts +180 -0
  360. package/src/shared/view-info.ts +10 -0
  361. package/src/theme/index.ts +13 -0
  362. package/src/theme/kit-theme-text.ts +1 -1
  363. package/src/theme/kit-theme.css +407 -10
  364. package/src/theme/kit-theme.tpl +407 -10
  365. package/src/theme/nine-dim-structure.ts +247 -0
  366. package/src/theme/surface-layers.ts +101 -0
  367. package/src/theme/theme-tokens.ts +130 -84
  368. package/src/theme/theme-types.ts +103 -0
  369. package/src/theme/typography.ts +17 -17
  370. package/src/biz/shared/step-values.ts +0 -25
  371. package/src/biz/step-form/steps-ref.ts +0 -112
  372. package/src/data/options-bus.ts +0 -24
  373. package/src/object-renderer/adopt-gate.ts +0 -333
  374. package/src/object-renderer/field-policy.ts +0 -89
  375. package/src/object-renderer/outcome-draft.ts +0 -61
  376. package/src/theme/nine-dim-palettes.ts +0 -1473
@@ -0,0 +1,393 @@
1
+ // 展示对象的纯路径绑定(三层分工:页面只做视觉翻译与纯绑定,交互逻辑在展示对象)。
2
+ // 页面里字段项的 hidden / disabled / required 与动作的 disabled 只许写 `view.<成员>`;本文件是这条规则的唯一实现:
3
+ // · 判纯路径(语法真源 viewObject.pathPattern,不是谓词 / 表达式 / 取反 / 字面量);
4
+ // · 把 `view.` 换成 core 的页面变量(page.),编成 core 的路径绑定;
5
+ // · 收集字段项绑定成表单的 fieldState prop 的形态,收集 view.form.onDraft。
6
+ // 纯函数,不碰 DOM;成员 / 方法是否在展示对象上声明过,由 compile/view-check.ts 对着登记表核(这里不认登记表)。
7
+
8
+ import { KIT_GRAMMAR } from './defaults';
9
+ import type { KitCell, KitDiagnostic, KitFieldRef, KitSchema, KitViewForm, KitViewSlot } from './types';
10
+ import { normalizeRef } from './arrange';
11
+
12
+ type Json = Record<string, any>;
13
+ const VO = (KIT_GRAMMAR as Json).viewObject as {
14
+ pathPattern: string; pathRoot: string; pathCoreVar: string; namePattern: string;
15
+ rowState: { pathPattern: string; pathRoot: string; actionKeys: string[]; toneTiers: Record<string, string>; itemToneTiers: Record<string, string> };
16
+ };
17
+ const RS = VO.rowState;
18
+ const ROW_RE = new RegExp(RS.pathPattern);
19
+
20
+ const PATH_RE = new RegExp(VO.pathPattern);
21
+ const NAME_RE = new RegExp(VO.namePattern);
22
+ const METHOD_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
23
+
24
+ /** 字段项上的状态键(hidden / disabled / required 要标量,options 要数组成员,nodeOptions 要对象成员,只用于画布字段) */
25
+ export const KIT_FIELD_STATE_KEYS = ['hidden', 'disabled', 'required', 'options', 'nodeOptions', 'columnOptions', 'suggestions'] as const;
26
+ export type KitFieldStateKey = (typeof KIT_FIELD_STATE_KEYS)[number];
27
+
28
+ /** 页面上写的 view 路径(view.<成员>[.<子成员>])? */
29
+ export function isViewPath(value: unknown): value is string {
30
+ return typeof value === 'string' && PATH_RE.test(value);
31
+ }
32
+
33
+ /** 展示对象类名(页面 page.view 的值)合法? */
34
+ export function isViewName(value: unknown): value is string {
35
+ return typeof value === 'string' && NAME_RE.test(value);
36
+ }
37
+
38
+ /** 展示对象方法名合法(标识符)? */
39
+ export function isViewMethodName(value: unknown): value is string {
40
+ return typeof value === 'string' && METHOD_RE.test(value);
41
+ }
42
+
43
+ /** view.<成员> -> core 路径 page.<成员>(调用前须先过 isViewPath) */
44
+ export function viewPathToCore(path: string): string {
45
+ return `${VO.pathCoreVar}.${path.slice(VO.pathRoot.length + 1)}`;
46
+ }
47
+
48
+ /** 路径的第一段成员名(view.remark.x -> remark) */
49
+ export function viewPathMember(path: string): string {
50
+ return path.slice(VO.pathRoot.length + 1).split('.')[0]!;
51
+ }
52
+
53
+ /** 校验一个视图绑定值;不是纯 view 路径记 KIT-VIEW-001 并返回 undefined,是则返回 core 路径 */
54
+ export function checkViewPath(value: unknown, at: string, what: string, diags: KitDiagnostic[]): string | undefined {
55
+ if (isViewPath(value)) return viewPathToCore(value);
56
+ diags.push({
57
+ code: 'KIT-VIEW-001',
58
+ path: at,
59
+ message: `${what} 只许写展示对象成员路径 ${VO.pathRoot}.<成员>,收到 ${JSON.stringify(value)}(不许字面量真假、谓词、表达式、取反、非 ${VO.pathRoot}. 前缀)`,
60
+ });
61
+ return undefined;
62
+ }
63
+
64
+ // ---------------------------------------------------------------- 行级状态的纯绑定(取值来自业务对象逐行给出的字段)
65
+
66
+ /** 行动作上的两个状态键(hidden / disabled) */
67
+ export const KIT_ROW_ACTION_KEYS = RS.actionKeys as readonly ('hidden' | 'disabled')[];
68
+ /** 行样式档位 -> 类串(闭集,真源 viewObject.rowState.toneTiers) */
69
+ export const KIT_ROW_TONE_CLASS: Readonly<Record<string, string>> = RS.toneTiers;
70
+ export const KIT_ROW_TONE_TIERS: readonly string[] = Object.keys(RS.toneTiers);
71
+ /** 卡 / 块条目的档位 -> 类串(闭集,真源 viewObject.rowState.itemToneTiers):条目自带底色与边框,档位只用描边 / 透明度,不改底色 */
72
+ export const KIT_ITEM_TONE_CLASS: Readonly<Record<string, string>> = RS.itemToneTiers;
73
+ export type KitRowToneSet = 'row' | 'item';
74
+
75
+ /** 页面上写的行路径(row.<字段>,单段字段名)? */
76
+ export function isRowPath(value: unknown): value is string {
77
+ return typeof value === 'string' && ROW_RE.test(value);
78
+ }
79
+
80
+ /** row.<字段> -> 字段名(调用前须先过 isRowPath) */
81
+ export function rowPathField(path: string): string {
82
+ return path.slice(RS.pathRoot.length + 1);
83
+ }
84
+
85
+ /** row.<字段> -> core 路径 <行变量>.<字段>(行变量由发射层给,是行模板里的 bind.var) */
86
+ export function rowPathToCore(path: string, rowVar: string): string {
87
+ return `${rowVar}.${rowPathField(path)}`;
88
+ }
89
+
90
+ /**
91
+ * 校验一个行级绑定值;不是纯 row 路径记 KIT-ROW-001 并返回 undefined;
92
+ * 给了 schema 时字段还必须在该对象 schema 里声明过,否则记 KIT-ROW-003(拼错字段名在编译期暴露,不等到运行期当假值)。
93
+ * 通过则返回字段名。
94
+ */
95
+ export function checkRowPath(value: unknown, at: string, what: string, diags: KitDiagnostic[], schema?: Readonly<Record<string, unknown>>): string | undefined {
96
+ if (!isRowPath(value)) {
97
+ diags.push({
98
+ code: 'KIT-ROW-001',
99
+ path: at,
100
+ message: `${what} 只许写行字段路径 ${RS.pathRoot}.<字段>(由业务对象逐行给出),收到 ${JSON.stringify(value)}(不许字面量真假、谓词、表达式、取反、类名、非 ${RS.pathRoot}. 前缀)`,
101
+ });
102
+ return undefined;
103
+ }
104
+ const field = rowPathField(value);
105
+ if (schema !== undefined && !Object.prototype.hasOwnProperty.call(schema, field)) {
106
+ diags.push({
107
+ code: 'KIT-ROW-003',
108
+ path: at,
109
+ message: `${what} 引用的行字段 ${field} 没有在该对象 schema 里声明(已声明:${Object.keys(schema).join(' / ') || '无'});状态字段在 schema 里声明、但不放进 view.list.fields 即不显示成列`,
110
+ });
111
+ return undefined;
112
+ }
113
+ return field;
114
+ }
115
+
116
+ /** 运行期:从 actionState prop({ 动作id: { hidden?, disabled? } },叶子已被 core 逐行求成值)取一个动作此刻的状态;只认真值 true / 'true' */
117
+ export function rowActionState(all: unknown, id: string): { hidden: boolean; disabled: boolean } {
118
+ const one = all !== null && typeof all === 'object' ? (all as Record<string, unknown>)[id] : undefined;
119
+ const rec = one !== null && typeof one === 'object' ? (one as Record<string, unknown>) : {};
120
+ const on = (v: unknown): boolean => v === true || v === 'true';
121
+ return { hidden: on(rec.hidden), disabled: on(rec.disabled) };
122
+ }
123
+
124
+ // ---------------------------------------------------------------- 置灰原因(动作 disabledReason)
125
+
126
+ /** 动作上的置灰原因键(键名登记在语法真源顶层 actionKeys;必须与 disabled 同写,置灰才显示) */
127
+ export const KIT_ACTION_REASON_KEY = 'disabledReason' as const;
128
+
129
+ /** disabledReason 取值的来源:字面量文案 | 行字段路径 | 展示对象成员路径 | 非法 */
130
+ export type KitReasonSource =
131
+ | { kind: 'literal'; text: string }
132
+ | { kind: 'row'; path: string }
133
+ | { kind: 'view'; path: string }
134
+ | { kind: 'invalid'; code: 'KIT-ACT-010' | 'KIT-ROW-001' | 'KIT-VIEW-001'; message: string };
135
+
136
+ /**
137
+ * 判一个 disabledReason 值的来源(唯一实现):
138
+ * 以 row. 开头必须是纯 row.<字段>、以 view. 开头必须是纯 view.<成员>,别的(含空串)一律是字面量文案;
139
+ * 对象 / 数字 / 含 {…} 占位(拼值)一律拒绝——原因文案由接口逐行给成品,或由展示对象给成品成员。
140
+ */
141
+ export function classifyDisabledReason(raw: unknown): KitReasonSource {
142
+ if (typeof raw !== 'string') {
143
+ return { kind: 'invalid', code: 'KIT-ACT-010', message: `disabledReason 必须是字符串(字面量文案 | view.<成员> | row.<字段>),收到 ${JSON.stringify(raw)}` };
144
+ }
145
+ if (/[{}]/.test(raw)) {
146
+ return { kind: 'invalid', code: 'KIT-ACT-010', message: `disabledReason 不支持 {…} 占位或拼值(${JSON.stringify(raw)}):原因文案由接口逐行给成品字段(row.<字段>),或由展示对象给成品成员(view.<成员>)` };
147
+ }
148
+ if (raw.startsWith(`${RS.pathRoot}.`)) {
149
+ return isRowPath(raw)
150
+ ? { kind: 'row', path: raw }
151
+ : { kind: 'invalid', code: 'KIT-ROW-001', message: `disabledReason 的行路径只许写 ${RS.pathRoot}.<字段>(单段字段名),收到 ${JSON.stringify(raw)}` };
152
+ }
153
+ if (raw.startsWith(`${VO.pathRoot}.`)) {
154
+ return isViewPath(raw)
155
+ ? { kind: 'view', path: raw }
156
+ : { kind: 'invalid', code: 'KIT-VIEW-001', message: `disabledReason 的展示对象路径只许写 ${VO.pathRoot}.<成员>,收到 ${JSON.stringify(raw)}` };
157
+ }
158
+ return { kind: 'literal', text: raw };
159
+ }
160
+
161
+ /** 运行期:从 actionState prop 取一个动作此刻的置灰原因文案(叶子 disabledReason 已被 core 逐行求成值);只认非空字符串,其余 ''(与没写时一致) */
162
+ export function rowActionReason(all: unknown, id: string): string {
163
+ const one = all !== null && typeof all === 'object' ? (all as Record<string, unknown>)[id] : undefined;
164
+ const v = one !== null && typeof one === 'object' ? (one as Record<string, unknown>)[KIT_ACTION_REASON_KEY] : undefined;
165
+ return typeof v === 'string' ? v.trim() : '';
166
+ }
167
+
168
+ /** 运行期:行动作 / 菜单项此刻的置灰原因:只在动作置灰时有效;行 / 展示对象给的值优先,其次是 actions 项里的字面量 */
169
+ export function disabledReasonOf(all: unknown, item: { id: string; disabledReason?: string }): string {
170
+ if (!rowActionState(all, item.id).disabled) return '';
171
+ const bound = rowActionReason(all, item.id);
172
+ return bound !== '' ? bound : (item.disabledReason ?? '').trim();
173
+ }
174
+
175
+ // ---------------------------------------------------------------- 组件 props / 请求 params / 组件事件 绑展示对象(RV-1119)
176
+ // 页面只写纯路径:props / params 的值写 view.<成员>[.<子成员>](字段项 props 在列表里另许 row.<字段>)或字面量;
177
+ // 事件的值写 view.<方法>(组件抛出的事件调展示对象方法,载荷 = 组件 emit 的载荷)。本节是这条规则的唯一实现,
178
+ // 渲染层(render-object / arrange / compile-data)与编译期核对(compile/view-check)共用,不各写一份。
179
+
180
+ /** 页面里写的原始运行期路径(page.* / kit_row_* / $page.* / $row.*):props 里会被 core 静默当路径绑定,params 里会绕过展示对象,一律拒绝 */
181
+ const RUNTIME_PATH_RE = /^(\$?page\.|\$?kit_row_[A-Za-z0-9_]+\.|\$row\.)/;
182
+ /** 取反写法(!view.x / !row.x / !page.x):页面不写取反,相反的值由展示对象另给成员 */
183
+ const NEGATED_PATH_RE = /^!\s*(view|row|page)\./;
184
+
185
+ export type KitBindingSource =
186
+ | { kind: 'literal' }
187
+ | { kind: 'view'; path: string }
188
+ | { kind: 'row'; path: string }
189
+ | { kind: 'invalid'; code: 'KIT-VIEW-001' | 'KIT-ROW-001' | 'KIT-VIEW-010'; message: string };
190
+
191
+ /**
192
+ * 判一个 props / params 取值的来源(唯一实现):
193
+ * 以 view. 开头必须是纯 view.<成员>[.<子成员>]、以 row. 开头必须是纯 row.<字段>,否则 invalid;
194
+ * 原始运行期路径(page. / kit_row_ / $page. / $row.)与取反写法 invalid;别的字符串与非字符串一律是字面量。
195
+ */
196
+ export function classifyBindingValue(raw: unknown, what: string): KitBindingSource {
197
+ if (typeof raw !== 'string') return { kind: 'literal' };
198
+ if (NEGATED_PATH_RE.test(raw)) {
199
+ return { kind: 'invalid', code: 'KIT-VIEW-001', message: `${what} 不许取反(${JSON.stringify(raw)}):页面只写纯路径,相反的值由展示对象另给一个成员` };
200
+ }
201
+ if (raw.startsWith(`${VO.pathRoot}.`)) {
202
+ return isViewPath(raw)
203
+ ? { kind: 'view', path: raw }
204
+ : { kind: 'invalid', code: 'KIT-VIEW-001', message: `${what} 只许写展示对象成员路径 ${VO.pathRoot}.<成员>[.<子成员>],收到 ${JSON.stringify(raw)}(不许表达式、比较、下标、插值)` };
205
+ }
206
+ if (raw.startsWith(`${RS.pathRoot}.`)) {
207
+ return isRowPath(raw)
208
+ ? { kind: 'row', path: raw }
209
+ : { kind: 'invalid', code: 'KIT-ROW-001', message: `${what} 的行路径只许写 ${RS.pathRoot}.<字段>(单段字段名),收到 ${JSON.stringify(raw)}` };
210
+ }
211
+ if (RUNTIME_PATH_RE.test(raw)) {
212
+ return { kind: 'invalid', code: 'KIT-VIEW-010', message: `${what} 不许写原始运行期路径 ${JSON.stringify(raw)}(page.* / kit_row_* / $page.* 等):值由展示对象成员(view.<成员>)或行字段(row.<字段>,仅列表字段项)给出` };
213
+ }
214
+ return { kind: 'literal' };
215
+ }
216
+
217
+ /** 页面声明的请求参数里不许出现的跨对象 / 行运行期路径(params 合法的 $page.query.* / $page.params.* 不在其中) */
218
+ const FORBIDDEN_PARAM_PATH_RE = /^\$?(page\.(data|region_mirror)\.|kit_row_[A-Za-z0-9_]+\.)|^\$row\./;
219
+
220
+ /**
221
+ * 判一个 behavior.params 取值的来源:同 classifyBindingValue,但 params 里合法的 $page.query.* / $page.params.* 等 $ 路径是字面量(原样透传给 core);
222
+ * rejectRuntime 为真(核页面声明)时,跨对象运行期路径($page.data.* / $page.region_mirror.* / $kit_row_* / $row.*)记 KIT-VIEW-010;
223
+ * 编译产物里 biz 层会合法注入镜像路径,所以发射阶段不开 rejectRuntime。
224
+ */
225
+ export function classifyParamBinding(raw: unknown, what: string, rejectRuntime: boolean): KitBindingSource {
226
+ if (typeof raw === 'string' && FORBIDDEN_PARAM_PATH_RE.test(raw)) {
227
+ return rejectRuntime
228
+ ? { kind: 'invalid', code: 'KIT-VIEW-010', message: `${what} 不许写跨对象 / 行的运行期路径 ${JSON.stringify(raw)}:另一个对象的数据由展示对象转存成成员后写 view.<成员>(ctx.data(对象).onChange)` }
229
+ : { kind: 'literal' };
230
+ }
231
+ const b = classifyBindingValue(raw, what);
232
+ return b.kind === 'invalid' && b.code === 'KIT-VIEW-010' ? { kind: 'literal' } : b;
233
+ }
234
+
235
+ /**
236
+ * 嵌套在对象 / 数组里的字符串:绑定只认整个值,嵌套处写了原始运行期路径记 KIT-VIEW-010(core 会静默绑定它),
237
+ * 写了 view. / row. 纯路径或取反记 KIT-VIEW-001(嵌套处不会被绑定,不许静默当字面量)。
238
+ */
239
+ export function checkNestedBindingValues(value: unknown, at: string, diags: KitDiagnostic[]): void {
240
+ if (value === null || typeof value !== 'object') return;
241
+ const entries: Array<[string, unknown]> = Array.isArray(value) ? value.map((v, i): [string, unknown] => [`[${i}]`, v]) : Object.entries(value).map(([k, v]): [string, unknown] => [`.${k}`, v]);
242
+ for (const [sub, v] of entries) {
243
+ const here = `${at}${sub}`;
244
+ if (typeof v === 'string') {
245
+ const b = classifyBindingValue(v, `${here}`);
246
+ if (b.kind === 'invalid') diags.push({ code: b.code, path: here, message: b.message });
247
+ else if (b.kind === 'view' || b.kind === 'row') {
248
+ diags.push({ code: 'KIT-VIEW-001', path: here, message: `${here} 是嵌套在对象 / 数组里的绑定路径 ${JSON.stringify(v)}:绑定只认整个 prop 值,请把整个 prop 写成 ${VO.pathRoot}.<成员>(展示对象整体替换引用)` });
249
+ }
250
+ } else checkNestedBindingValues(v, here, diags);
251
+ }
252
+ }
253
+
254
+ /** 事件值的来源:展示对象方法(view.<方法>)| 不是 view. 写法(按动作名处理)| 非法(view. 开头却不是单段方法名) */
255
+ export type KitEventBinding =
256
+ | { kind: 'method'; name: string }
257
+ | { kind: 'other' }
258
+ | { kind: 'invalid'; message: string };
259
+
260
+ const VIEW_METHOD_REF_RE = /^view\.[A-Za-z][A-Za-z0-9_]*$/;
261
+
262
+ /** 判一个事件值是不是 view.<方法>(组件事件 / 浮层事件 / 动作 submit 共用);唯一实现 */
263
+ export function classifyEventBinding(raw: unknown, what: string): KitEventBinding {
264
+ if (typeof raw !== 'string' || !raw.startsWith(`${VO.pathRoot}.`)) return { kind: 'other' };
265
+ if (VIEW_METHOD_REF_RE.test(raw)) return { kind: 'method', name: raw.slice(VO.pathRoot.length + 1) };
266
+ return { kind: 'invalid', message: `${what} 只许写展示对象方法 ${VO.pathRoot}.<方法>(单段方法名),收到 ${JSON.stringify(raw)}` };
267
+ }
268
+
269
+ /**
270
+ * 字段项 props 的绑定(只读单元:list / summary / 只读 form 的字段):值写 view.<成员> 编成 core 页面变量路径;
271
+ * 列表字段项另许 row.<字段>(业务对象逐行给的字段,字段须在 schema 里声明,KIT-ROW-003),记进 cell.rowProps 由发射层按行变量换成 core 行路径。
272
+ * 可编辑单元(edit 态 form / filter)不支持(表单草稿与重画互相打架):写了记 KIT-VIEW-006;row. 写在 list 以外记 KIT-ROW-002。
273
+ * cells 是该视图排布出的全部格(按字段名对应字段项);调用前格的 props 里仍是页面原值,这里就地改写。
274
+ */
275
+ export function bindFieldProps(slot: KitViewSlot, form: KitViewForm, cells: readonly KitCell[], path: string, diags: KitDiagnostic[], schema?: KitSchema): void {
276
+ const byField = new Map<string, KitCell>();
277
+ for (const c of cells) if (c.placeholder !== true && c.divider !== true && !byField.has(c.field)) byField.set(c.field, c);
278
+ for (const { ref, at } of refsOf(form, path)) {
279
+ const raw = ref.props;
280
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) continue;
281
+ const cell = byField.get(ref.name);
282
+ for (const [k, v] of Object.entries(raw as Record<string, unknown>)) {
283
+ const where = `${at}.props.${k}`;
284
+ const what = `字段 ${ref.name} 的 props.${k}`;
285
+ const b = classifyBindingValue(v, what);
286
+ if (b.kind === 'literal') { checkNestedBindingValues(v, where, diags); continue; }
287
+ if (cell !== undefined) delete cell.props[k];
288
+ if (b.kind === 'invalid') { diags.push({ code: b.code, path: where, message: b.message }); continue; }
289
+ if (cell === undefined) continue;
290
+ if (cell.mode !== 'show') {
291
+ diags.push({ code: 'KIT-VIEW-006', path: where, message: `${what} 绑定到展示对象只对只读单元生效(list / summary / 只读 form);${slot} 视图的可编辑字段不支持` });
292
+ continue;
293
+ }
294
+ if (b.kind === 'view') { cell.props[k] = viewPathToCore(b.path); continue; }
295
+ if (slot !== 'list') {
296
+ diags.push({ code: 'KIT-ROW-002', path: where, message: `${what} 不能绑 row.<字段>:row.<字段> 只用于列表视图的字段项;${slot} 视图没有行,写 view.<成员>` });
297
+ continue;
298
+ }
299
+ const field = checkRowPath(b.path, where, what, diags, schema);
300
+ if (field !== undefined) (cell.rowProps ??= {})[k] = field;
301
+ }
302
+ }
303
+ }
304
+
305
+ /** 运行期:行样式档位名 -> 类串;不在闭集(含空、未知)返回 ''(不加任何类) */
306
+ export function rowToneClass(tier: unknown, set: KitRowToneSet = 'row'): string {
307
+ const map = set === 'item' ? KIT_ITEM_TONE_CLASS : KIT_ROW_TONE_CLASS;
308
+ return typeof tier === 'string' && Object.prototype.hasOwnProperty.call(map, tier) ? map[tier]! : '';
309
+ }
310
+
311
+ /** nodeOptions 的宿主:只有这个编辑组件的字段项可写 nodeOptions */
312
+ const NODE_OPTIONS_EDITOR = 'FlowEditor';
313
+ /** columnOptions 的宿主:只有这个编辑组件(子表)的字段项可写 columnOptions */
314
+ const COLUMN_OPTIONS_EDITOR = 'RowEditor';
315
+
316
+ export type KitFieldStateIR = Record<string, Partial<Record<KitFieldStateKey, string>>>;
317
+
318
+ /** 一个视图 fields / groups[].fields 里全部字段项(已规范化,带它们的路径) */
319
+ function refsOf(form: KitViewForm, path: string): Array<{ ref: KitFieldRef; at: string }> {
320
+ const out: Array<{ ref: KitFieldRef; at: string }> = [];
321
+ const push = (items: unknown, base: string): void => {
322
+ if (!Array.isArray(items)) return;
323
+ items.forEach((item, i) => {
324
+ if (item === null || (typeof item !== 'string' && typeof item !== 'object')) return;
325
+ out.push({ ref: normalizeRef(item as never), at: `${base}[${i}]` });
326
+ });
327
+ };
328
+ push(form.fields, `${path}.fields`);
329
+ if (Array.isArray(form.groups)) form.groups.forEach((g, gi) => push((g as { fields?: unknown }).fields, `${path}.groups[${gi}].fields`));
330
+ return out;
331
+ }
332
+
333
+ /**
334
+ * 收集一个视图字段项上的状态绑定。可编辑 form 视图全部键有意义;filter 视图只认 options;其它写法 / 视图记 KIT-VIEW-006;
335
+ * 值不是纯 view 路径记 KIT-VIEW-001。返回 { 字段: { hidden?, disabled?, required? } }(路径已换成 core 的 page.<成员>)。
336
+ */
337
+ export function collectFieldState(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[], schema?: KitSchema): KitFieldStateIR {
338
+ const out: KitFieldStateIR = {};
339
+ for (const { ref, at } of refsOf(form, path)) {
340
+ for (const key of KIT_FIELD_STATE_KEYS) {
341
+ const raw = (ref as unknown as Record<string, unknown>)[key];
342
+ if (raw === undefined) continue;
343
+ const where = `${at}.${key}`;
344
+ // filter 视图只放行 options(候选随另一个筛选字段变化);hidden / disabled / required 在筛选栏没有对应语义(筛选字段恒可选填),其余键是画布 / 子表专用
345
+ if (slot !== 'form' && !(slot === 'filter' && key === 'options')) {
346
+ diags.push({ code: 'KIT-VIEW-006', path: where, message: slot === 'filter'
347
+ ? `字段项的 ${key} 在 filter 视图里不能写(筛选视图的字段项只支持 options: view.<成员>;${key} 只对可编辑 form 视图生效)`
348
+ : `字段项的 ${key} 只对可编辑 form 视图生效${key === 'options' ? '(options 另可写在 filter 视图)' : ''},${slot} 视图不能写` });
349
+ continue;
350
+ }
351
+ // nodeOptions 是画布字段(编辑组件 FlowEditor)的节点候选项,写在别的字段上没有落点
352
+ if (key === 'nodeOptions' && (ref.component ?? schema?.[ref.name]?.edit) !== NODE_OPTIONS_EDITOR) {
353
+ diags.push({ code: 'KIT-VIEW-006', path: where, message: `字段 ${ref.name} 的 nodeOptions 只对编辑组件是 ${NODE_OPTIONS_EDITOR} 的字段生效(schema 里 edit: ${NODE_OPTIONS_EDITOR},或字段项 component: ${NODE_OPTIONS_EDITOR})` });
354
+ }
355
+ if (key === 'columnOptions' && (ref.component ?? schema?.[ref.name]?.edit) !== COLUMN_OPTIONS_EDITOR) {
356
+ diags.push({ code: 'KIT-VIEW-006', path: where, message: `字段 ${ref.name} 的 columnOptions 只对编辑组件是 ${COLUMN_OPTIONS_EDITOR} 的字段生效(schema 里 edit: ${COLUMN_OPTIONS_EDITOR},或字段项 component: ${COLUMN_OPTIONS_EDITOR})` });
357
+ }
358
+ // suggestions 是画布字段(FlowEditor)的 AI 建议,只在画布上有落点
359
+ if (key === 'suggestions' && (ref.component ?? schema?.[ref.name]?.edit) !== NODE_OPTIONS_EDITOR) {
360
+ diags.push({ code: 'KIT-VIEW-006', path: where, message: `字段 ${ref.name} 的 suggestions 只对编辑组件是 ${NODE_OPTIONS_EDITOR} 的字段生效(schema 里 edit: ${NODE_OPTIONS_EDITOR},或字段项 component: ${NODE_OPTIONS_EDITOR})` });
361
+ }
362
+ const core = checkViewPath(raw, where, `字段 ${ref.name} 的 ${key}`, diags);
363
+ if (core !== undefined) (out[ref.name] ??= {})[key] = core;
364
+ }
365
+ }
366
+ return out;
367
+ }
368
+
369
+ /** view.form.submitDisabled:纯 view 路径,返回 core 路径;只许可编辑 form 视图 */
370
+ export function checkSubmitDisabled(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): string | undefined {
371
+ const raw = (form as unknown as Record<string, unknown>).submitDisabled;
372
+ if (raw === undefined) return undefined;
373
+ if (slot !== 'form') {
374
+ diags.push({ code: 'KIT-VIEW-006', path: `${path}.submitDisabled`, message: 'submitDisabled 只用于 form 视图' });
375
+ return undefined;
376
+ }
377
+ return checkViewPath(raw, `${path}.submitDisabled`, 'submitDisabled', diags);
378
+ }
379
+
380
+ /** view.form.onDraft:展示对象方法名;只许 form 视图 */
381
+ export function checkOnDraft(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): string | undefined {
382
+ const raw = (form as unknown as Record<string, unknown>).onDraft;
383
+ if (raw === undefined) return undefined;
384
+ if (slot !== 'form') {
385
+ diags.push({ code: 'KIT-VIEW-006', path: `${path}.onDraft`, message: 'onDraft 只用于 form 视图' });
386
+ return undefined;
387
+ }
388
+ if (!isViewMethodName(raw)) {
389
+ diags.push({ code: 'KIT-VIEW-001', path: `${path}.onDraft`, message: `onDraft 只许写展示对象方法名(标识符),收到 ${JSON.stringify(raw)}` });
390
+ return undefined;
391
+ }
392
+ return raw;
393
+ }
@@ -119,6 +119,37 @@ export function knownNonAiKeys(): ReadonlySet<string> {
119
119
  return out;
120
120
  }
121
121
 
122
+ /**
123
+ * 视图字段引用里编译器代写的提示键:aiWriter.fieldRef 的 ai 级键去掉 label
124
+ * (label 编成 schema 的显示名,不另写在视图引用上)。蓝图字段用同名键承载,只落在 form / filter 视图。
125
+ */
126
+ export const fieldHintKeys = (): readonly string[] => aiKeysOf(kitAiWriter().fieldRef).filter((k) => k === 'placeholder' || k === 'help');
127
+
128
+ /** 提示文字落在哪些视图槽位:展示词不作用的槽位(aiDisplayMap.slots 之外);list / summary 里的字段引用只承载展示词 */
129
+ export const hintSlots = (): readonly string[] => kitViewSlots().filter((s) => !KIT_AI_DISPLAY_MAP.slots.includes(s));
130
+
131
+ /** 对象角色的形状要求(真源 aiWriter.roleShape;未列出的角色取缺省 any、不禁任何键) */
132
+ export interface KitRoleShape {
133
+ readonly channel: 'any' | 'read' | 'write' | 'free';
134
+ readonly omit: readonly ('schema' | 'behavior' | 'view')[];
135
+ }
136
+
137
+ export function roleShapeOf(kind: string, role: string): KitRoleShape {
138
+ const table = kitAiWriter().roleShape;
139
+ const hit = Object.hasOwn(table, kind) && Object.hasOwn(table[kind]!, role) ? table[kind]![role] : undefined;
140
+ return { channel: hit?.channel ?? 'any', omit: hit?.omit ?? [] };
141
+ }
142
+
143
+ /** 授权接口的用途 */
144
+ export type ApiPurpose = 'api' | 'write_api' | 'delete_api';
145
+
146
+ /** 某用途允许的 HTTP 方法集(真源 aiWriter 的 readMethods / writeMethods / deleteMethods,大写) */
147
+ export function methodsFor(purpose: ApiPurpose): readonly string[] {
148
+ const w = kitAiWriter();
149
+ const list = purpose === 'api' ? w.readMethods : purpose === 'write_api' ? w.writeMethods : w.deleteMethods;
150
+ return list.map((m) => m.toUpperCase());
151
+ }
152
+
122
153
  /** 字段类型闭集:真源 types 表的键 */
123
154
  export const kitFieldTypes = (): readonly string[] => Object.keys(G.types);
124
155
 
@@ -152,3 +183,9 @@ export function kitDiagnosticText(code: string): string | undefined {
152
183
  export function kitAiProductSummary(): Readonly<Record<string, string>> {
153
184
  return KIT_AI_INTENT_MAP.summary;
154
185
  }
186
+
187
+ /** 字段视觉强调级别(真源 objectLayer.fieldEmphasis) */
188
+ export const aiFieldEmphasis = (): readonly string[] => (grammarJson as unknown as { objectLayer: { fieldEmphasis: string[] } }).objectLayer.fieldEmphasis;
189
+
190
+ /** 字段访问权限(真源 objectLayer.fieldAccess) */
191
+ export const aiFieldAccess = (): readonly string[] => (grammarJson as unknown as { objectLayer: { fieldAccess: string[] } }).objectLayer.fieldAccess;
@@ -17,7 +17,7 @@ import type { PageDiagnostic } from 'soma-core/page-target';
17
17
  import { KIT_PLACEHOLDER_URL } from '../app/submit.types';
18
18
  import { resolveBiz } from '../compile/registry';
19
19
  import type { KitAppContext } from '../compile/types';
20
- import { KIT_REMOVE_CONFIRM_REF as REMOVE_CONFIRM_REF, kitAiDisplayMap, kitAiWriter, kitViewSlots } from './ai-surface';
20
+ import { fieldHintKeys, hintSlots, KIT_REMOVE_CONFIRM_REF as REMOVE_CONFIRM_REF, kitAiDisplayMap, kitAiWriter, kitViewSlots, roleShapeOf, type KitRoleShape } from './ai-surface';
21
21
  import {
22
22
  KIT_INTENT_MAP,
23
23
  frameKindOfIntent,
@@ -73,6 +73,9 @@ function compileSchema(
73
73
  if (f.key === true || (!hasKey && i === 0)) entry.key = true;
74
74
  const permission = f.permission ?? (formFields.has(f.name) ? 'w' : undefined);
75
75
  if (permission !== undefined) entry.permission = permission;
76
+ if (f.access !== undefined) entry.access = f.access;
77
+ if (f.emphasis !== undefined) entry.emphasis = f.emphasis;
78
+ if (f.highlight !== undefined) entry.highlight = f.highlight;
76
79
  if ((f.type === 'enum' || f.type === 'enums') && (f.options === undefined || f.options.length === 0)) {
77
80
  issues.push(issue(`${at}.fields[${i}].options`, `字段 ${f.name}(${f.type})需要候选项`, '给该字段补 options(value / label / 可选 tone)'));
78
81
  }
@@ -101,12 +104,25 @@ function displayRef(object: KitIntentObject, id: string): unknown {
101
104
  return { name: id, component: entry.component, ...props };
102
105
  }
103
106
 
107
+ /**
108
+ * form / filter 视图里的一个字段引用:字段带了 placeholder / help(aiWriter.fieldRef 的 ai 键)就写成 { name, placeholder?, help? },
109
+ * 否则仍是字段 id 字符串。list / summary 的引用只承载展示词,不承载提示(蓝图解析已拒绝落不到视图上的提示)。
110
+ */
111
+ function hintRef(object: KitIntentObject, id: string): unknown {
112
+ const field = object.fields.find((f) => f.name === id);
113
+ if (field === undefined) return id;
114
+ const hints = fieldHintKeys().filter((k) => (field as unknown as Rec)[k] !== undefined);
115
+ if (hints.length === 0) return id;
116
+ return { name: id, ...Object.fromEntries(hints.map((k) => [k, (field as unknown as Rec)[k]])) };
117
+ }
118
+
104
119
  function compileObject(
105
120
  name: string,
106
121
  object: KitIntentObject,
107
122
  slots: KitIntentSlots | undefined,
108
123
  actions: readonly KitIntentAction[],
109
124
  locale: string | undefined,
125
+ shape: KitRoleShape,
110
126
  at: string,
111
127
  issues: PageDiagnostic[],
112
128
  ): Rec {
@@ -116,14 +132,18 @@ function compileObject(
116
132
  for (const slot of kitViewSlots()) {
117
133
  const fields = slots?.[slot];
118
134
  if (fields === undefined) continue;
119
- const body: Rec = { fields: displayMap.slots.includes(slot) ? fields.map((id) => displayRef(object, id)) : [...fields] };
135
+ const body: Rec = {
136
+ fields: displayMap.slots.includes(slot)
137
+ ? fields.map((id) => displayRef(object, id))
138
+ : hintSlots().includes(slot) ? fields.map((id) => hintRef(object, id)) : [...fields],
139
+ };
120
140
  if (slot === 'list') {
121
141
  const rows = actions.filter((a) => a.on === 'row').map((a) => `@${a.id}`);
122
142
  if (rows.length > 0) body.rowActions = rows;
123
143
  }
124
144
  view[slot] = body;
125
145
  }
126
- if (slots?.form !== undefined && (object.write_api === undefined || object.write_api === '')) {
146
+ if (shape.channel !== 'free' && slots?.form !== undefined && (object.write_api === undefined || object.write_api === '')) {
127
147
  issues.push(issue(`${at}.write_api`, `对象 ${name} 有 form 视图,但没有写接口(write_api),表单没有保存通道`, '在授权接口里选一个写入接口填到 write_api,或去掉 form 视图'));
128
148
  }
129
149
  if (actions.some((a) => a.on === 'row') && slots?.list === undefined) {
@@ -132,13 +152,24 @@ function compileObject(
132
152
  const hasApi = typeof object.api === 'string' && object.api !== '';
133
153
  const hasWrite = typeof object.write_api === 'string' && object.write_api !== '';
134
154
  const hasDelete = typeof object.delete_api === 'string' && object.delete_api !== '';
135
- if (!hasApi && !hasWrite) {
155
+ // 接口通道按角色形状(真源 aiWriter.roleShape):缺省要有 api 或 write_api;只读展示角色不收写入口;只提交角色须有 write_api 且不收 api;free 不要求
156
+ if (shape.channel === 'any' && !hasApi && !hasWrite) {
136
157
  issues.push(issue(`${at}`, `对象 ${name} 既没有 api 也没有 write_api:对象描述不足以编译(kit 没有样本数据通道)`, '在授权接口里选一个读接口填到 api'));
137
158
  }
159
+ if (shape.omit.includes('behavior') && (hasApi || hasWrite || hasDelete)) {
160
+ issues.push(issue(`${at}`, `对象 ${name} 所在角色的取数 / 写入由模板继承别的角色,不收 api / write_api / delete_api`, '删去 api / write_api / delete_api;字段值读自主记录'));
161
+ }
162
+ if (shape.channel === 'read' && (hasWrite || hasDelete)) {
163
+ issues.push(issue(`${at}`, `对象 ${name} 所在角色是只读展示,不收 write_api / delete_api`, '删去 write_api / delete_api;要写入换用别的页面模式'));
164
+ }
165
+ if (shape.channel === 'write') {
166
+ if (!hasWrite) issues.push(issue(`${at}.write_api`, `对象 ${name} 所在角色只负责提交,须有写接口(write_api)`, '在授权接口里选一个写入接口填到 write_api'));
167
+ if (hasApi) issues.push(issue(`${at}.api`, `对象 ${name} 所在角色只负责提交,不收读接口 api`, '删去 api'));
168
+ }
138
169
  // 写通道:只有 write_api 时保持字符串写法(创建与更新共用);带 delete_api 改成通道表,删除通道独立
139
170
  // core 的删除端点要带身份占位符(DELETE 不带请求体):编译器把主键拼进查询串 `?<主键>={<主键>}`,授权核对仍只看路径本身
140
171
  const keyField = object.fields.find((f) => f.key === true)?.name ?? object.fields[0]?.name;
141
- const deleteEndpoint = !hasDelete || keyField === undefined ? undefined : `${object.delete_api}?${keyField}={${keyField}}`;
172
+ const deleteEndpoint = !hasDelete || keyField === undefined ? undefined : `${object.delete_api}${object.delete_api!.includes('?') ? '&' : '?'}${keyField}={${keyField}}`;
142
173
  const write = deleteEndpoint !== undefined
143
174
  ? { ...(hasWrite ? { create: object.write_api, update: object.write_api } : {}), delete: deleteEndpoint }
144
175
  : hasWrite ? object.write_api : undefined;
@@ -155,7 +186,12 @@ function compileObject(
155
186
  }
156
187
  : {}),
157
188
  };
158
- return { schema: compileSchema(object, formFields, locale, at, issues), behavior, view };
189
+ // 模板写死的角色(roleShape.omit)不收 schema / behavior / view:目标不写(字段字典、取数由模板自己合并或继承)
190
+ return {
191
+ ...(shape.omit.includes('schema') ? {} : { schema: compileSchema(object, formFields, locale, at, issues) }),
192
+ ...(shape.omit.includes('behavior') ? {} : { behavior }),
193
+ ...(shape.omit.includes('view') ? {} : { view }),
194
+ };
159
195
  }
160
196
 
161
197
  function compileSection(
@@ -188,6 +224,10 @@ function compileSection(
188
224
  issues.push(issue(`${aat}.role`, `动作 ${a.id} 没有可挂的角色(${role === undefined ? '该页面模式没有主角色,请写 role' : `角色 ${role} 未绑定对象`})`, '给动作写 role,取 roles 里已绑定的角色'));
189
225
  return;
190
226
  }
227
+ if (roleShapeOf(kind, role).channel === 'read') {
228
+ issues.push(issue(`${aat}.role`, `动作 ${a.id} 挂在只读展示的角色 ${role} 上,该角色不收动作`, '删去该动作'));
229
+ return;
230
+ }
191
231
  if ((a.builtin === 'openEdit') && a.on !== 'row') issues.push(issue(`${aat}.on`, `openEdit 只能是行动作(要带当前行)`, '把 on 改成 row'));
192
232
  if ((a.builtin === 'openCreate' || a.builtin === 'reload') && a.on !== 'toolbar') issues.push(issue(`${aat}.on`, `${a.builtin} 只能放工具栏`, '把 on 改成 toolbar'));
193
233
  if (a.builtin === 'remove') {
@@ -225,13 +265,13 @@ function compileSection(
225
265
  if (typeof ref === 'string') {
226
266
  const object = section.objects[ref];
227
267
  if (object === undefined) continue;
228
- objects[role] = compileObject(ref, object, roleViews as KitIntentSlots | undefined, roleActions, locale, `${at}objects.${ref}`, issues);
268
+ objects[role] = compileObject(ref, object, roleViews as KitIntentSlots | undefined, roleActions, locale, roleShapeOf(kind, role), `${at}objects.${ref}`, issues);
229
269
  } else {
230
270
  const table: Rec = {};
231
271
  for (const n of ref) {
232
272
  const object = section.objects[n];
233
273
  if (object === undefined) continue;
234
- table[n] = compileObject(n, object, (roleViews as Record<string, KitIntentSlots> | undefined)?.[n], roleActions, locale, `${at}objects.${n}`, issues);
274
+ table[n] = compileObject(n, object, (roleViews as Record<string, KitIntentSlots> | undefined)?.[n], roleActions, locale, roleShapeOf(kind, role), `${at}objects.${n}`, issues);
235
275
  }
236
276
  objects[role] = table;
237
277
  }
@@ -6,7 +6,14 @@ export {
6
6
  KitTargetInputError,
7
7
  SOMA_KIT_TARGET_SOURCE_PATH,
8
8
  } from './target';
9
- export type { KitPageTargetApp } from './target';
9
+ export type {
10
+ KitCurrentApiAuthorizationRequest,
11
+ KitCurrentApiAuthorizationProvider,
12
+ KitPageTargetApp,
13
+ KitPageTargetOptions,
14
+ } from './target';
15
+ // 宿主装配 soma-ai-page 时标注目标类型用,应用不必 import soma-core/page-target
16
+ export type { PageTarget } from 'soma-core/page-target';
10
17
  export { kitIntentSchema, parseKitIntentBlueprint } from './intent-schema';
11
18
  export type {
12
19
  KitIntentBlueprint,