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
@@ -4,10 +4,11 @@
4
4
  // 1) KIT-APP-004:所有登记进 baseComponents / staticObjectComponents 的 App* 组件,必须经
5
5
  // wrapKitDataComponent、composeKitDataComponents 或 declareKitUses 显式登记依赖组件与候选类元数据;
6
6
  // 声明的 uses 必须是真实存在的内置组件名,own 候选类必须通过 checkClasses 校验(禁方括号任意值)。
7
- // 2) KIT-APP-005:严禁应用组件在 templateHtml、控制器或 components/ 辅助模块中私自拼写已被 soma-kit
7
+ // 2) KIT-APP-005:严禁应用组件在 templateHtml、控制器或源码中私自拼写已被 soma-kit
8
8
  // 标准组件接管的原生表单控件(原生 <select>、原生 <input type="range">、原生 <input type="date|datetime-local|time|month|week">),
9
- // 也严禁在 templateHtml 中书写内联 style 属性。下拉一律走 Select / Combobox / mountKitSelectField,
10
- // 滑块一律走 Range,日期时间一律走 Date / DateRange / TimePicker。
9
+ // 严禁在 TS/HTML 中书写内联 style / 操作 .style / setAttribute('style', ...),
10
+ // 也严禁在非组件 TS(views/actions/api/soma.app.ts 等)中操作 .className / .classList 或手绑 addEventListener 等 DOM 事件。
11
+ // 下拉一律走 Select / Combobox / mountKitSelectField,滑块一律走 Range,日期时间一律走 Date / DateRange / TimePicker。
11
12
 
12
13
  import type { SomaComponentDefinition } from 'soma-core';
13
14
  import { KIT_BASE_COMPONENTS } from '../base/index';
@@ -16,6 +17,8 @@ import { KIT_STATIC_BUILTIN_LAZY_NAMES } from '../data/static-lazy';
16
17
  import { KIT_RESIDENT_COMPONENT_NAMES, wrappedCandidateSource } from '../data/wrapped-candidates';
17
18
  import { checkClasses } from '../object-renderer/merge-class';
18
19
  import type { KitDiagnostic } from '../object-renderer/types';
20
+ import { kitFail } from '../compile/kit-error';
21
+ import { getKitControllerSource, isKitControllerFactory } from '../base/shared';
19
22
 
20
23
  /** declareKitUses 允许引用的内置组件全集 */
21
24
  export const VALID_KIT_USES_NAMES: ReadonlySet<string> = new Set<string>([
@@ -44,6 +47,13 @@ interface ForbiddenRule {
44
47
  readonly message: string;
45
48
  }
46
49
 
50
+ const MSG_STYLE_PROP = '禁止在 TS 中操作 .style 修改内联样式;要么在组件模板写好标准类,要么通过 DSL 传入或使用 data-* 状态属性 / SVG 几何属性';
51
+ const MSG_SET_ATTR_STYLE = '禁止调用 setAttribute("style", ...) 注入内联样式;请统一使用 Tailwind 候选类与 --soma-* 设计令牌';
52
+ const MSG_INLINE_STYLE_HTML = '禁止在模板或 HTML 片段中使用内联 style="..." 属性;请统一使用 Tailwind 候选类与 --soma-* 设计令牌';
53
+ const MSG_INLINE_ON_EVENT = '禁止使用内联 on* 事件或 .on* = 赋值;业务交互请预埋到组件事件槽位并通过 DSL 绑定';
54
+ const MSG_NON_COMP_CLASS = '业务与展示对象 TS(非 components/)禁止直接操作 DOM 样式类(.className / .classList);样式要么在组件模板写好,要么由 *.kit.yaml DSL 传入';
55
+ const MSG_NON_COMP_EVENT = '业务与展示对象 TS(非 components/)禁止直接调用 addEventListener 手绑 DOM 事件;动态事件应预埋在业务组件槽位中,由 *.kit.yaml 的 behavior.actions / view.on 传入并路由至展示对象方法';
56
+
47
57
  const FORBIDDEN_DOM_PATTERNS: readonly ForbiddenRule[] = [
48
58
  {
49
59
  id: 'raw-style-tag',
@@ -55,6 +65,31 @@ const FORBIDDEN_DOM_PATTERNS: readonly ForbiddenRule[] = [
55
65
  pattern: /createElement\s*\(\s*['"`]style['"`]\s*\)/,
56
66
  message: '禁止调用 createElement("style") 动态注入样式表;请统一使用 Tailwind 候选类与 --soma-* 设计令牌',
57
67
  },
68
+ {
69
+ id: 'inline-style-html',
70
+ pattern: /<[a-zA-Z][^>]*\sstyle\s*=\s*['"]/i,
71
+ message: MSG_INLINE_STYLE_HTML,
72
+ },
73
+ {
74
+ id: 'inline-on-event-html',
75
+ pattern: /<[a-zA-Z][^>]*\son(?:click|change|input|keydown|keyup|submit|focus|blur|mousedown|mouseup|pointerdown|pointerup)\s*=\s*['"]/i,
76
+ message: MSG_INLINE_ON_EVENT,
77
+ },
78
+ {
79
+ id: 'dom-style-prop',
80
+ pattern: /\.\s*style\s*(?:\.\s*[a-zA-Z_$][\w$]*|\[\s*['"`][^'"`]+['"`]\s*\])/,
81
+ message: MSG_STYLE_PROP,
82
+ },
83
+ {
84
+ id: 'dom-set-attribute-style',
85
+ pattern: /\.\s*setAttribute(?:NS)?\s*\([^)]*['"`]style['"`]/,
86
+ message: MSG_SET_ATTR_STYLE,
87
+ },
88
+ {
89
+ id: 'dom-on-event-assign',
90
+ pattern: /\.\s*on(?:click|change|input|keydown|keyup|submit|focus|blur|mousedown|mouseup|pointerdown|pointerup)\s*=(?!=)/,
91
+ message: MSG_INLINE_ON_EVENT,
92
+ },
58
93
  {
59
94
  id: 'native-select-tag',
60
95
  pattern: /<\s*select(?=[\s>/])/i,
@@ -118,53 +153,274 @@ export function findForbiddenNativeControls(text: string): Array<{ line: number;
118
153
  export function assertSinglePathComponent(name: string, def: SomaComponentDefinition): void {
119
154
  const meta = wrappedCandidateSource(def);
120
155
  if (meta === undefined) {
121
- throw new Error(
122
- `[soma-kit] [KIT-APP-004] 应用组件 ${name} 未经唯一接入路径声明:必须通过 wrapKitDataComponent / composeKitDataComponents 包装组合,或经 declareKitUses(${name}, uses, candidates) 显式登记依赖组件与候选类`,
123
- );
156
+ kitFail('KIT-APP-004', `components.${name}`, `应用组件 ${name} 未经唯一接入路径声明:必须通过 wrapKitDataComponent / composeKitDataComponents 包装组合,或经 declareKitUses(${name}, uses, candidates) 显式登记依赖组件与候选类`, `用 wrapKitDataComponent 包装,或在定义处调用 declareKitUses(${name}, uses, candidates)`);
124
157
  }
125
158
  for (const used of meta.uses ?? []) {
126
159
  if (!VALID_KIT_USES_NAMES.has(used)) {
127
- throw new Error(
128
- `[soma-kit] [KIT-APP-004] 应用组件 ${name} 在 declareKitUses 中声明了未知的内置组件 "${used}"`,
129
- );
160
+ kitFail('KIT-APP-004', `components.${name}.uses`, `应用组件 ${name} 在 declareKitUses 中声明了未知的内置组件 "${used}"`, '依赖组件名必须是内置组件闭集里的名字');
130
161
  }
131
162
  }
132
163
  for (const tok of meta.own) {
133
164
  const bad = checkClasses(tok, `${name}.candidates`);
134
165
  if (bad.length > 0) {
135
- throw new Error(
136
- `[soma-kit] [KIT-APP-004] 应用组件 ${name} 的候选类 "${tok}" 非法:${bad[0]!.message}`,
137
- );
166
+ kitFail('KIT-APP-004', `components.${name}.candidates`, `应用组件 ${name} 的候选类 "${tok}" 非法:${bad[0]!.message}`, '候选类只能用刻度内的 Tailwind 类,不写方括号任意值');
138
167
  }
139
168
  }
169
+ if (typeof def.controllerFactory !== 'function' || !isKitControllerFactory(def.controllerFactory)) {
170
+ kitFail('KIT-APP-014', `components.${name}.controllerFactory`, `应用组件 ${name} 的 controllerFactory 必须由 createKitController((api) => ({ ... })) 生成(不接受纯声明式无控制器组件或手写工厂)`, '使用 createKitController((api) => ({ render(root, p, api) { ... } })) 定义控制器');
171
+ }
140
172
  if (typeof def.templateHtml === 'string' && /\sstyle\s*=/i.test(def.templateHtml)) {
141
- throw new Error(
142
- `[soma-kit] [KIT-APP-005] 应用组件 ${name} 的 templateHtml 含内联 style 属性;样式必须统一使用 Tailwind 候选类`,
143
- );
173
+ kitFail('KIT-APP-005', `components.${name}.templateHtml`, `应用组件 ${name} 的 templateHtml 含内联 style 属性;样式必须统一使用 Tailwind 候选类`, '删掉 style 属性,改用 class 里的 Tailwind 候选类');
144
174
  }
145
175
  const tplHits = typeof def.templateHtml === 'string' ? findForbiddenNativeControls(def.templateHtml) : [];
146
176
  if (tplHits.length > 0) {
147
- throw new Error(`[soma-kit] [KIT-APP-005] 应用组件 ${name} 的 templateHtml 违规:${tplHits[0]!.message}`);
177
+ kitFail('KIT-APP-005', `components.${name}.templateHtml`, `应用组件 ${name} 的 templateHtml 违规:${tplHits[0]!.message}`, '改用 soma-kit 标准组件(Select / Slider / DatePicker 等),不手写原生控件');
148
178
  }
149
179
  if (typeof def.controllerFactory === 'function') {
150
- const fnHits = findForbiddenNativeControls(Function.prototype.toString.call(def.controllerFactory));
180
+ const fnHits = findForbiddenNativeControls(getKitControllerSource(def.controllerFactory));
151
181
  if (fnHits.length > 0) {
152
- throw new Error(`[soma-kit] [KIT-APP-005] 应用组件 ${name} 的控制器违规:${fnHits[0]!.message}`);
182
+ kitFail('KIT-APP-005', `components.${name}.controller`, `应用组件 ${name} 的控制器违规:${fnHits[0]!.message}`, '控制器里不要创建原生控件,改用 soma-kit 标准组件');
153
183
  }
154
184
  }
155
185
  }
156
186
 
187
+ const SKIP_SCAN_DIRS = new Set([
188
+ 'node_modules',
189
+ 'dist',
190
+ 'build',
191
+ 'coverage',
192
+ 'tests',
193
+ 'test',
194
+ 'scripts',
195
+ '.soma',
196
+ ]);
197
+
198
+ const DOM_INLINE_ON_EVENTS = new Set([
199
+ 'onclick',
200
+ 'onchange',
201
+ 'oninput',
202
+ 'onkeydown',
203
+ 'onkeyup',
204
+ 'onsubmit',
205
+ 'onfocus',
206
+ 'onblur',
207
+ 'onmousedown',
208
+ 'onmouseup',
209
+ 'onpointerdown',
210
+ 'onpointerup',
211
+ ]);
212
+
213
+ const HTML_TAG_FORBIDDEN_RULES: readonly ForbiddenRule[] = [
214
+ {
215
+ id: 'raw-style-tag',
216
+ pattern: /<\s*style(?=[\s>/])/i,
217
+ message: '禁止在模板或控制器中手写 <style> 标签注入全局样式;请统一使用 Tailwind 候选类与 --soma-* 设计令牌',
218
+ },
219
+ {
220
+ id: 'native-select-tag',
221
+ pattern: /<\s*select(?=[\s>/])/i,
222
+ message: '禁止手写原生 <select> 标签;请改用 soma-kit 标准组件 Select / Combobox(命令式嵌入用 mountKitSelectField)',
223
+ },
224
+ {
225
+ id: 'native-range-tag',
226
+ pattern: /<\s*input\b[^>]*\btype\s*=\s*['"]range['"]/i,
227
+ message: '禁止手写原生 <input type="range"> 滑块;请改用 soma-kit 标准组件 Range(自绘无障碍 SVG 滑块)',
228
+ },
229
+ {
230
+ id: 'native-date-tag',
231
+ pattern: /<\s*input\b[^>]*\btype\s*=\s*['"](?:date|datetime-local|time|month|week)['"]/i,
232
+ message: '禁止手写原生日期/时间 <input>;请改用 soma-kit 标准组件 Date / DateRange / TimePicker',
233
+ },
234
+ ];
235
+
236
+ const HTML_INLINE_ATTR_RULES: readonly ForbiddenRule[] = [
237
+ {
238
+ id: 'inline-style-html',
239
+ pattern: /<[a-zA-Z][^>]*\sstyle\s*=\s*['"]/i,
240
+ message: MSG_INLINE_STYLE_HTML,
241
+ },
242
+ {
243
+ id: 'inline-on-event-html',
244
+ pattern: /<[a-zA-Z][^>]*\son(?:click|change|input|keydown|keyup|submit|focus|blur|mousedown|mouseup|pointerdown|pointerup)\s*=\s*['"]/i,
245
+ message: MSG_INLINE_ON_EVENT,
246
+ },
247
+ ];
248
+
249
+ type TsModule = typeof import('typescript');
250
+
251
+ function scriptKindForFile(ts: TsModule, fileName: string): import('typescript').ScriptKind {
252
+ if (fileName.endsWith('.tsx')) return ts.ScriptKind.TSX;
253
+ if (fileName.endsWith('.jsx')) return ts.ScriptKind.JSX;
254
+ if (fileName.endsWith('.js') || fileName.endsWith('.mjs') || fileName.endsWith('.cjs')) return ts.ScriptKind.JS;
255
+ return ts.ScriptKind.TS;
256
+ }
257
+
258
+ function extractStaticHtmlText(ts: TsModule, node: import('typescript').Expression): string {
259
+ if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node)) {
260
+ return extractStaticHtmlText(ts, node.expression);
261
+ }
262
+ if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
263
+ return node.text;
264
+ }
265
+ if (ts.isTemplateExpression(node)) {
266
+ return [node.head.text, ...node.templateSpans.map((span) => span.literal.text)].join(' ');
267
+ }
268
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
269
+ return extractStaticHtmlText(ts, node.left) + extractStaticHtmlText(ts, node.right);
270
+ }
271
+ return '';
272
+ }
273
+
274
+ function propertyAccessName(ts: TsModule, node: import('typescript').Expression): string | undefined {
275
+ if (ts.isPropertyAccessExpression(node)) return node.name.text;
276
+ if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression)) {
277
+ return node.argumentExpression.text;
278
+ }
279
+ return undefined;
280
+ }
281
+
282
+ function scanSourceWithAst(
283
+ ts: TsModule,
284
+ fullPath: string,
285
+ code: string,
286
+ inComponentsDir: boolean,
287
+ ): Array<{ line: number; message: string }> {
288
+ const sourceFile = ts.createSourceFile(fullPath, code, ts.ScriptTarget.Latest, true, scriptKindForFile(ts, fullPath));
289
+ const hits: Array<{ line: number; message: string }> = [];
290
+ const seen = new Set<string>();
291
+
292
+ const pushHit = (node: import('typescript').Node, message: string): void => {
293
+ const line = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
294
+ const key = `${line}:${message}`;
295
+ if (seen.has(key)) return;
296
+ seen.add(key);
297
+ hits.push({ line, message });
298
+ };
299
+
300
+ const checkHtmlString = (node: import('typescript').Node, html: string, includeInlineAttrs: boolean): void => {
301
+ if (!html) return;
302
+ if (includeInlineAttrs) {
303
+ for (const rule of HTML_INLINE_ATTR_RULES) {
304
+ if (rule.pattern.test(html)) pushHit(node, rule.message);
305
+ }
306
+ }
307
+ for (const rule of HTML_TAG_FORBIDDEN_RULES) {
308
+ if (rule.pattern.test(html)) pushHit(node, rule.message);
309
+ }
310
+ };
311
+
312
+ const visit = (node: import('typescript').Node, insideFunction: boolean): void => {
313
+ if (ts.isTypeNode(node) || ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) {
314
+ return;
315
+ }
316
+
317
+ // 1. AST .style / ['style'] 访问(全应用禁止)
318
+ if (
319
+ (ts.isPropertyAccessExpression(node) && node.name.text === 'style')
320
+ || (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression) && node.argumentExpression.text === 'style')
321
+ ) {
322
+ pushHit(node, MSG_STYLE_PROP);
323
+ }
324
+
325
+ // 2. AST 非组件目录禁止操作 .className / .classList
326
+ if (!inComponentsDir) {
327
+ const propName = ts.isPropertyAccessExpression(node)
328
+ ? node.name.text
329
+ : (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : undefined);
330
+ if (propName === 'className' || propName === 'classList') {
331
+ pushHit(node, MSG_NON_COMP_CLASS);
332
+ }
333
+ }
334
+
335
+ // 3. AST 函数调用检查
336
+ if (ts.isCallExpression(node)) {
337
+ const calleeName = ts.isIdentifier(node.expression)
338
+ ? node.expression.text
339
+ : (ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : undefined);
340
+
341
+ if (calleeName === 'setAttribute' && node.arguments.length >= 1 && ts.isStringLiteralLike(node.arguments[0])) {
342
+ const attr = node.arguments[0].text.toLowerCase();
343
+ if (attr === 'style') pushHit(node, MSG_SET_ATTR_STYLE);
344
+ if (!inComponentsDir && attr === 'class') pushHit(node, MSG_NON_COMP_CLASS);
345
+ } else if (calleeName === 'setAttributeNS' && node.arguments.length >= 2 && ts.isStringLiteralLike(node.arguments[1])) {
346
+ const attr = node.arguments[1].text.toLowerCase();
347
+ if (attr === 'style') pushHit(node, MSG_SET_ATTR_STYLE);
348
+ if (!inComponentsDir && attr === 'class') pushHit(node, MSG_NON_COMP_CLASS);
349
+ } else if (calleeName === 'createElement' && node.arguments.length >= 1 && ts.isStringLiteralLike(node.arguments[0])) {
350
+ const tag = node.arguments[0].text.toLowerCase();
351
+ if (tag === 'style') {
352
+ pushHit(node, '禁止调用 createElement("style") 动态注入样式表;请统一使用 Tailwind 候选类与 --soma-* 设计令牌');
353
+ } else if (tag === 'select') {
354
+ pushHit(node, '禁止调用 createElement("select") 创建原生下拉框;请改用 mountKitSelectField 或 Select 组件');
355
+ }
356
+ } else if (calleeName === 'insertAdjacentHTML' && node.arguments.length >= 2) {
357
+ checkHtmlString(node.arguments[1]!, extractStaticHtmlText(ts, node.arguments[1]!), true);
358
+ } else if (!inComponentsDir && (calleeName === 'addEventListener' || calleeName === 'removeEventListener' || calleeName === 'dispatchEvent')) {
359
+ pushHit(node, MSG_NON_COMP_EVENT);
360
+ } else if (!inComponentsDir && calleeName === 'insertRule') {
361
+ pushHit(node, MSG_NON_COMP_CLASS);
362
+ }
363
+ }
364
+
365
+ // 4. AST new CSSStyleSheet()(非组件目录禁止)
366
+ if (!inComponentsDir && ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'CSSStyleSheet') {
367
+ pushHit(node, MSG_NON_COMP_CLASS);
368
+ }
369
+
370
+ // 5. AST 赋值表达式检查(innerHTML / outerHTML / .on* = / .type = 'range'|'date')
371
+ if (ts.isBinaryExpression(node) && (node.operatorToken.kind === ts.SyntaxKind.EqualsToken || node.operatorToken.kind === ts.SyntaxKind.PlusEqualsToken)) {
372
+ const leftName = propertyAccessName(ts, node.left);
373
+ if (leftName === 'innerHTML' || leftName === 'outerHTML') {
374
+ checkHtmlString(node.right, extractStaticHtmlText(ts, node.right), true);
375
+ } else if (node.operatorToken.kind === ts.SyntaxKind.EqualsToken && leftName !== undefined) {
376
+ if (DOM_INLINE_ON_EVENTS.has(leftName)) {
377
+ pushHit(node, MSG_INLINE_ON_EVENT);
378
+ } else if (leftName === 'type' && ts.isStringLiteralLike(node.right)) {
379
+ const val = node.right.text.toLowerCase();
380
+ if (val === 'range') {
381
+ pushHit(node, '禁止设置 input.type = "range" 创建原生滑块;请改用 soma-kit 标准组件 Range');
382
+ } else if (/^(?:date|datetime-local|time|month|week)$/.test(val)) {
383
+ pushHit(node, '禁止设置原生日期/时间 input.type;请改用 soma-kit 标准组件 Date / DateRange / TimePicker');
384
+ }
385
+ }
386
+ }
387
+ }
388
+
389
+ // 6. AST 对象字面量 templateHtml 属性检查
390
+ if (ts.isPropertyAssignment(node)) {
391
+ const propName = ts.isIdentifier(node.name) || ts.isStringLiteral(node.name) ? node.name.text : undefined;
392
+ if (propName === 'templateHtml') {
393
+ checkHtmlString(node.initializer, extractStaticHtmlText(ts, node.initializer), true);
394
+ }
395
+ }
396
+
397
+ // 7. 函数体内的字符串/模板字面量中的原生控件标签(如 renderSneaky 返回 `<select>...`),不误伤顶层纯数据字典
398
+ if (insideFunction && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) || ts.isTemplateExpression(node))) {
399
+ checkHtmlString(node, extractStaticHtmlText(ts, node), false);
400
+ }
401
+
402
+ const nextInsideFunction = insideFunction || ts.isFunctionLike(node);
403
+ ts.forEachChild(node, (child) => visit(child, nextInsideFunction));
404
+ };
405
+
406
+ visit(sourceFile, false);
407
+ return hits;
408
+ }
409
+
157
410
  /**
158
- * 服务端编译与 `soma kit check` 全量源码门禁:
159
- * 递归扫描应用 `<root>/components` 目录下的全部实现文件(`.ts` / `.js` / `.mjs`),
160
- * 防止把非标原生控件拆分到辅助渲染子模块绕过单组件检查。
411
+ * 服务端编译与 `soma kit check` 全量源码 AST 门禁:
412
+ * 递归扫描应用根目录 `<root>` 下全部 `.ts` / `.tsx` / `.js` / `.mjs` 源码(跳过 `node_modules` / `dist` / `tests` / `.soma` 等),
413
+ * 1) 全应用禁止:非标原生控件、<style>、AST `.style` 访问、`setAttribute('style', ...)`、`innerHTML`/`outerHTML`/`templateHtml` 内联 `style="..."` 或 `on*`、`.onclick =` 等赋值;
414
+ * 2) 非 `components/` 目录(如 `views/**`、`actions/**`、`api/**`、`soma.app.ts`)额外禁止:操作 `.className` / `.classList` / `setAttribute('class', ...)` / `CSSStyleSheet` 与手绑 `addEventListener`。
161
415
  */
162
416
  export async function scanAppComponentSources(root: string): Promise<KitDiagnostic[]> {
163
417
  const fsSpec = 'node:fs/promises';
164
418
  const pathSpec = 'node:path';
419
+ const tsSpec = 'typescript';
165
420
  const fs = await import(fsSpec);
166
421
  const path = await import(pathSpec);
167
- const compDir = path.join(root, 'components');
422
+ const tsMod = await import(tsSpec);
423
+ const ts = (tsMod.default ?? tsMod) as TsModule;
168
424
  const diagnostics: KitDiagnostic[] = [];
169
425
 
170
426
  async function walk(dir: string): Promise<void> {
@@ -179,16 +435,15 @@ export async function scanAppComponentSources(root: string): Promise<KitDiagnost
179
435
  for (const entry of entries) {
180
436
  const full = path.join(dir, entry.name);
181
437
  if (entry.isDirectory()) {
182
- if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
438
+ if (SKIP_SCAN_DIRS.has(entry.name) || entry.name.startsWith('.')) continue;
183
439
  await walk(full);
184
440
  continue;
185
441
  }
186
- if (!/\.(?:ts|js|mjs)$/.test(entry.name) || entry.name.endsWith('.d.ts')) continue;
442
+ if (!/\.(?:ts|tsx|js|mjs)$/.test(entry.name) || entry.name.endsWith('.d.ts')) continue;
187
443
  const code = await fs.readFile(full, 'utf8');
188
- // 仅对含可执行函数或模板字面量的组件/渲染模块扫描,跳过纯 JSON 常量数据字典
189
- if (!code.includes('`') && !/\bfunction\b|=>|createElement/.test(code)) continue;
190
444
  const rel = path.relative(root, full).split(path.sep).join('/');
191
- for (const hit of findForbiddenNativeControls(code)) {
445
+ const inComponentsDir = rel === 'components' || rel.startsWith('components/');
446
+ for (const hit of scanSourceWithAst(ts, full, code, inComponentsDir)) {
192
447
  diagnostics.push({
193
448
  code: 'KIT-APP-005',
194
449
  path: `${rel}:${hit.line}`,
@@ -198,6 +453,6 @@ export async function scanAppComponentSources(root: string): Promise<KitDiagnost
198
453
  }
199
454
  }
200
455
 
201
- await walk(compDir);
456
+ await walk(root);
202
457
  return diagnostics;
203
458
  }
@@ -15,9 +15,22 @@ import { kitText } from '../i18n/kit-text';
15
15
  import { kitActionExtras } from '../biz/shared/runtime-hub';
16
16
  import { kitPermissionAllows } from '../base/permission-gate';
17
17
  import type { DefineKitAppOptions } from './define-kit-app';
18
+ import type { KitViewClass } from './define-kit-view';
19
+ import { KitDiagnosticError, kitFail } from '../compile/kit-error';
18
20
 
19
21
  type Grant = ReturnType<NonNullable<DefineKitAppOptions['pageGrants']>>[number];
20
22
  type ExclusiveKey = 'auth' | 'eventMiddleware' | 'login';
23
+ type FileLayoutKey = 'root' | 'app' | 'pagesDir' | 'extraPagesDirs' | 'services' | 'defaultTheme';
24
+ type ComposedOptionKey =
25
+ | 'appYaml' | 'devFallback' | 'dicts' | 'entities' | 'packs'
26
+ | 'baseComponents' | 'staticObjectComponents' | 'actions' | 'requestTimeout' | 'views'
27
+ | 'bizComponents' | 'frames' | 'overrides' | 'appCandidates'
28
+ | 'appName' | 'title' | 'locales' | 'defaultLocale' | 'auth' | 'eventMiddleware'
29
+ | 'renderPorts' | 'identity' | 'defaultAccess' | 'pageGrants' | 'requestHook'
30
+ | 'startup' | 'responseHeaders' | 'reservedRoutes' | 'login';
31
+ type UnhandledOptionKey = Exclude<keyof DefineKitAppOptions, FileLayoutKey | ComposedOptionKey>;
32
+ type AssertNever<T extends never> = T;
33
+ type EveryOptionHasACompositionPolicy = AssertNever<UnhandledOptionKey>;
21
34
 
22
35
  export interface ComposeKitAppsOptions {
23
36
  /** 基座独占、叠加不得再写的选项键;缺省 auth / eventMiddleware / login */
@@ -34,14 +47,56 @@ export function mergeKitTables<T>(label: string, ...tables: ReadonlyArray<Readon
34
47
  const dup: string[] = [];
35
48
  for (const table of tables) {
36
49
  for (const [name, value] of Object.entries(table ?? {})) {
37
- if (name in out) dup.push(name);
38
- else out[name] = value;
50
+ if (Object.hasOwn(out, name)) dup.push(name);
51
+ else Object.defineProperty(out, name, { value, enumerable: true, configurable: true, writable: true });
39
52
  }
40
53
  }
41
- if (dup.length > 0) throw new Error(`[soma-kit] ${label}重名:${[...new Set(dup)].join('、')}(不提供覆盖,请改名)`);
54
+ if (dup.length > 0) kitFail('KIT-APP-012', label, `${label}重名:${[...new Set(dup)].join('、')}(不提供覆盖)`, '给叠加应用里的同名项改名');
42
55
  return out;
43
56
  }
44
57
 
58
+ function normalizeViewTable(views: DefineKitAppOptions['views'], side: string): Record<string, KitViewClass> {
59
+ const out: Record<string, KitViewClass> = {};
60
+ const entries: Array<[string | undefined, KitViewClass]> = Array.isArray(views)
61
+ ? (views as readonly KitViewClass[]).map((cls) => [undefined, cls])
62
+ : Object.entries(views ?? {}) as Array<[string, KitViewClass]>;
63
+ for (const [declaredName, cls] of entries) {
64
+ const name = (cls as { viewName?: unknown } | null)?.viewName;
65
+ if (typeof name !== 'string' || name === '') {
66
+ kitFail('KIT-VIEW-005', `views.${String(declaredName ?? '')}`, `${side}的展示对象缺少有效 viewName`, '用 defineKitView 定义后再登记');
67
+ }
68
+ if (declaredName !== undefined && declaredName !== name) {
69
+ kitFail('KIT-VIEW-005', `views.${declaredName}`, `${side}展示对象登记名 ${declaredName} 与 viewName ${name} 不一致`, '登记键必须等于 defineKitView 的 viewName');
70
+ }
71
+ if (Object.hasOwn(out, name)) {
72
+ kitFail('KIT-VIEW-005', `views.${name}`, `${side}重复登记展示对象 ${name}`, '同一个展示对象只登记一次');
73
+ }
74
+ Object.defineProperty(out, name, { value: cls, enumerable: true, configurable: true, writable: true });
75
+ }
76
+ return out;
77
+ }
78
+
79
+ function mergeKitPacks(base: DefineKitAppOptions['packs'], overlay: DefineKitAppOptions['packs']): NonNullable<DefineKitAppOptions['packs']> | undefined {
80
+ const out: NonNullable<DefineKitAppOptions['packs']>[number][] = [];
81
+ const byName = new Map<string, NonNullable<DefineKitAppOptions['packs']>[number]>();
82
+ for (const pack of [...(base ?? []), ...(overlay ?? [])]) {
83
+ if (pack === null || typeof pack !== 'object' || typeof pack.name !== 'string') {
84
+ out.push(pack);
85
+ continue;
86
+ }
87
+ const previous = byName.get(pack.name);
88
+ if (previous !== undefined) {
89
+ if (previous !== pack) {
90
+ kitFail('KIT-PACK-003', `packs.${pack.name}`, `领域包名 ${pack.name} 对应不同的包实例`, '基座与叠加应用的领域包名称不得冲突');
91
+ }
92
+ continue;
93
+ }
94
+ byName.set(pack.name, pack);
95
+ out.push(pack);
96
+ }
97
+ return out.length === 0 ? undefined : out;
98
+ }
99
+
45
100
  /**
46
101
  * 合并选项(不含 root / app / pagesDir / extraPagesDirs / services / defaultTheme:那几项取决于文件布局,由应用自己的装配补)。
47
102
  * `base` 取自基座 `soma.app.ts` 默认导出的 `.options`,原样不改。
@@ -51,13 +106,14 @@ export function composeKitApps(base: DefineKitAppOptions, overlay: DefineKitAppO
51
106
  const names = opts.names ?? { base: '基座', overlay: '叠加应用' };
52
107
  const exclusive = opts.exclusive ?? ['auth', 'eventMiddleware', 'login'];
53
108
  const bad = exclusive.filter((k) => overlay[k] !== undefined);
54
- if (bad.length > 0) throw new Error(`${tag} ${names.overlay}不得设置 ${bad.join(' / ')}:由${names.base}持有`);
109
+ if (bad.length > 0) throw new KitDiagnosticError({ code: 'KIT-APP-012', path: bad.join(' / '), message: `${names.overlay}不得设置 ${bad.join(' / ')}:由${names.base}持有`, hint: `从${names.overlay}的 defineKitApp 选项里删掉 ${bad.join(' / ')}` }, tag);
55
110
 
56
111
  const table = <T>(label: string, a: Readonly<Record<string, T>> | undefined, b: Readonly<Record<string, T>> | undefined): Record<string, T> => {
57
112
  try {
58
113
  return mergeKitTables(label, a, b);
59
114
  } catch (e) {
60
- throw new Error(`${tag} ${(e as Error).message.replace('[soma-kit] ', '')}(${names.base}已登记同名项)`);
115
+ const d = (e as KitDiagnosticError).diagnostics[0]!;
116
+ throw new KitDiagnosticError({ ...d, message: `${d.message}(${names.base}已登记同名项)` }, tag);
61
117
  }
62
118
  };
63
119
  const merged: DefineKitAppOptions = {
@@ -66,13 +122,28 @@ export function composeKitApps(base: DefineKitAppOptions, overlay: DefineKitAppO
66
122
  actions: table('具名动作', base.actions, overlay.actions),
67
123
  bizComponents: table('业务组件', base.bizComponents, overlay.bizComponents),
68
124
  frames: table('页面框', base.frames, overlay.frames),
125
+ dicts: table('共享字典', base.dicts, overlay.dicts),
126
+ entities: table('共享实体', base.entities, overlay.entities),
69
127
  appCandidates: [...new Set([...(base.appCandidates ?? []), ...(overlay.appCandidates ?? [])])].sort(),
70
128
  };
71
129
 
72
- // overrides 只作用于 kit 内置名,叠加写的原样保留
73
- const overrides = [...new Set(overlay.overrides ?? [])];
130
+ const views = table('展示对象', normalizeViewTable(base.views, names.base), normalizeViewTable(overlay.views, names.overlay));
131
+ if (Object.keys(views).length > 0) merged.views = views;
132
+ const packs = mergeKitPacks(base.packs, overlay.packs);
133
+ if (packs !== undefined) merged.packs = packs;
134
+
135
+ // 覆盖白名单只授权覆盖 kit 内置名;基座与叠加的声明并集去重,绝不授权覆盖对方登记项。
136
+ const overrides = [...new Set([...(base.overrides ?? []), ...(overlay.overrides ?? [])])];
74
137
  if (overrides.length > 0) merged.overrides = overrides;
75
138
 
139
+ // 页面编译错误降级开关归叠加应用优先,显式 false 可关闭基座默认值。
140
+ const devFallback = overlay.devFallback !== undefined ? overlay.devFallback : base.devFallback;
141
+ if (devFallback !== undefined) merged.devFallback = devFallback;
142
+
143
+ // HTTP 默认超时:显式 0 有意义,只有 undefined 才继承基座。
144
+ const requestTimeout = overlay.requestTimeout !== undefined ? overlay.requestTimeout : base.requestTimeout;
145
+ if (requestTimeout !== undefined) merged.requestTimeout = requestTimeout;
146
+
76
147
  // 基座独占面:原样取基座的
77
148
  for (const k of exclusive) {
78
149
  if (base[k] !== undefined) (merged as Record<string, unknown>)[k] = base[k];
@@ -146,7 +217,7 @@ export function createKitPermissionMiddleware(): SomaMiddlewareChain<SomaEventMi
146
217
  if (typeof code === 'string' && code !== '' && !kitPermissionAllows(code)) {
147
218
  context.status = 'blocked';
148
219
  context.message = kitText('soma.kit.perm_denied', { code });
149
- kitActionExtras().notify(context.message, 'danger');
220
+ kitActionExtras(context.element).notify(context.message, 'danger');
150
221
  return;
151
222
  }
152
223
  await next();