soma-kit 0.0.0-stage → 0.1.0

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 (353) hide show
  1. package/README.md +539 -2
  2. package/bin/soma-kit.mjs +27 -0
  3. package/package.json +66 -4
  4. package/packs/ai/agent-run-card.ts +64 -0
  5. package/packs/ai/evaluation-card.ts +51 -0
  6. package/packs/ai/guardrail-policy-card.ts +48 -0
  7. package/packs/ai/index.ts +31 -0
  8. package/packs/ai/model-card.ts +55 -0
  9. package/packs/ai/model-routing-card.ts +49 -0
  10. package/packs/ai/prompt-template-card.ts +49 -0
  11. package/packs/ai/texts.ts +19 -0
  12. package/packs/commerce/address-card.ts +58 -0
  13. package/packs/commerce/coupon-card.ts +64 -0
  14. package/packs/commerce/index.ts +25 -0
  15. package/packs/commerce/order-card.ts +60 -0
  16. package/packs/commerce/purchase-order-card.ts +74 -0
  17. package/packs/commerce/texts.ts +14 -0
  18. package/packs/finance/index.ts +30 -0
  19. package/packs/finance/invoice-summary-card.ts +48 -0
  20. package/packs/finance/reconcile-board.ts +450 -0
  21. package/packs/finance/reconcile-case-card.ts +70 -0
  22. package/packs/finance/reconcile-desk/compile.ts +208 -0
  23. package/packs/finance/reconcile-desk/index.ts +20 -0
  24. package/packs/finance/reconcile-desk/shell.ts +27 -0
  25. package/packs/finance/texts.ts +21 -0
  26. package/packs/ops/change-window-card.ts +54 -0
  27. package/packs/ops/dependency-status-card.ts +50 -0
  28. package/packs/ops/error-budget-card.ts +60 -0
  29. package/packs/ops/execution-task-runner.ts +61 -0
  30. package/packs/ops/index.ts +36 -0
  31. package/packs/ops/integration-status-card.ts +45 -0
  32. package/packs/ops/release-readiness-card.ts +63 -0
  33. package/packs/ops/runbook-execution-card.ts +81 -0
  34. package/packs/ops/texts.ts +21 -0
  35. package/packs/security/control-evidence-card.ts +54 -0
  36. package/packs/security/finding-card.ts +96 -0
  37. package/packs/security/index.ts +29 -0
  38. package/packs/security/texts.ts +31 -0
  39. package/packs/shared/card-util.ts +60 -0
  40. package/packs/shared/wrap.ts +13 -0
  41. package/spec/generated/kit-app.schema.json +84 -0
  42. package/spec/generated/kit-page.schema.json +2766 -0
  43. package/spec/kit-grammar.json +1358 -0
  44. package/spec/kit-grammar.schema.json +716 -0
  45. package/src/app/app-config.ts +108 -0
  46. package/src/app/compose-apps.ts +139 -0
  47. package/src/app/define-kit-actions.ts +89 -0
  48. package/src/app/define-kit-app.ts +362 -0
  49. package/src/app/define-kit-pack.ts +114 -0
  50. package/src/app/envelope.ts +117 -0
  51. package/src/app/index.ts +50 -0
  52. package/src/app/notify-renderer.ts +114 -0
  53. package/src/app/paged-list-adapter.ts +246 -0
  54. package/src/app/server-pages.ts +303 -0
  55. package/src/app/server.ts +244 -0
  56. package/src/app/submit.types.ts +87 -0
  57. package/src/base/action-busy.ts +159 -0
  58. package/src/base/action-gate.ts +267 -0
  59. package/src/base/action-status.ts +31 -0
  60. package/src/base/alert.ts +136 -0
  61. package/src/base/avatar.ts +271 -0
  62. package/src/base/button.ts +139 -0
  63. package/src/base/cascader.ts +523 -0
  64. package/src/base/check-core.ts +214 -0
  65. package/src/base/checkbox.ts +35 -0
  66. package/src/base/choice.ts +183 -0
  67. package/src/base/color-picker.ts +316 -0
  68. package/src/base/combobox.ts +61 -0
  69. package/src/base/command-palette.ts +371 -0
  70. package/src/base/context-menu.ts +103 -0
  71. package/src/base/countdown.ts +168 -0
  72. package/src/base/date-range.ts +444 -0
  73. package/src/base/date.ts +899 -0
  74. package/src/base/divider.ts +156 -0
  75. package/src/base/fab.ts +192 -0
  76. package/src/base/icons.ts +106 -0
  77. package/src/base/image.ts +177 -0
  78. package/src/base/index.ts +214 -0
  79. package/src/base/input.ts +316 -0
  80. package/src/base/kbd.ts +99 -0
  81. package/src/base/link.ts +167 -0
  82. package/src/base/listbox-core.ts +965 -0
  83. package/src/base/mentions.ts +323 -0
  84. package/src/base/menu-button.ts +240 -0
  85. package/src/base/menu-core.ts +341 -0
  86. package/src/base/month-grid.ts +171 -0
  87. package/src/base/motion/aura.ts +94 -0
  88. package/src/base/motion/hover-3d.ts +154 -0
  89. package/src/base/motion/hover-gallery.ts +185 -0
  90. package/src/base/motion/index.ts +27 -0
  91. package/src/base/motion/limits.ts +75 -0
  92. package/src/base/motion/marquee.ts +157 -0
  93. package/src/base/motion/text-rotate.ts +195 -0
  94. package/src/base/number.ts +121 -0
  95. package/src/base/otp.ts +259 -0
  96. package/src/base/permission-gate.ts +99 -0
  97. package/src/base/popover.ts +352 -0
  98. package/src/base/popup.ts +542 -0
  99. package/src/base/portal-core.ts +297 -0
  100. package/src/base/price-text.ts +126 -0
  101. package/src/base/progress.ts +216 -0
  102. package/src/base/qr-code.ts +446 -0
  103. package/src/base/qty-stepper.ts +241 -0
  104. package/src/base/radio.ts +33 -0
  105. package/src/base/range.ts +444 -0
  106. package/src/base/rating.ts +249 -0
  107. package/src/base/segmented.ts +286 -0
  108. package/src/base/select.ts +57 -0
  109. package/src/base/shared.ts +708 -0
  110. package/src/base/swap.ts +86 -0
  111. package/src/base/switch.ts +111 -0
  112. package/src/base/tag-input.ts +464 -0
  113. package/src/base/tag.ts +250 -0
  114. package/src/base/text.ts +126 -0
  115. package/src/base/textarea.ts +129 -0
  116. package/src/base/time-picker.ts +606 -0
  117. package/src/base/tree-select.ts +629 -0
  118. package/src/base/upload.ts +548 -0
  119. package/src/base/virtual-list.ts +286 -0
  120. package/src/biz/approval-desk/compile.ts +179 -0
  121. package/src/biz/approval-desk/index.ts +21 -0
  122. package/src/biz/approval-desk/shell.ts +50 -0
  123. package/src/biz/auth-panel/compile.ts +196 -0
  124. package/src/biz/auth-panel/index.ts +24 -0
  125. package/src/biz/auth-panel/shell.ts +46 -0
  126. package/src/biz/category-crud/compile.ts +173 -0
  127. package/src/biz/category-crud/index.ts +19 -0
  128. package/src/biz/category-crud/shell.ts +29 -0
  129. package/src/biz/checkout-page/compile.ts +111 -0
  130. package/src/biz/checkout-page/index.ts +20 -0
  131. package/src/biz/checkout-page/shell.ts +50 -0
  132. package/src/biz/compose.ts +313 -0
  133. package/src/biz/data-components.ts +26 -0
  134. package/src/biz/define.ts +23 -0
  135. package/src/biz/import-wizard/compile.ts +204 -0
  136. package/src/biz/import-wizard/hub.ts +540 -0
  137. package/src/biz/import-wizard/index.ts +24 -0
  138. package/src/biz/import-wizard/shell.ts +161 -0
  139. package/src/biz/index.ts +80 -0
  140. package/src/biz/landing-page/compile.ts +67 -0
  141. package/src/biz/landing-page/index.ts +20 -0
  142. package/src/biz/landing-page/shell.ts +48 -0
  143. package/src/biz/link/hub.ts +255 -0
  144. package/src/biz/link/shared.ts +493 -0
  145. package/src/biz/master-sub/compile.ts +232 -0
  146. package/src/biz/master-sub/index.ts +20 -0
  147. package/src/biz/master-sub/shell.ts +56 -0
  148. package/src/biz/multi-board/compile.ts +234 -0
  149. package/src/biz/multi-board/index.ts +19 -0
  150. package/src/biz/multi-board/shell.ts +70 -0
  151. package/src/biz/names.ts +30 -0
  152. package/src/biz/notification-center/compile.ts +138 -0
  153. package/src/biz/notification-center/index.ts +29 -0
  154. package/src/biz/notification-center/shell.ts +42 -0
  155. package/src/biz/page-templates/result-page/compile.ts +46 -0
  156. package/src/biz/page-templates/result-page/index.ts +19 -0
  157. package/src/biz/page-templates/result-page/shell.ts +31 -0
  158. package/src/biz/page-templates/shared.ts +121 -0
  159. package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
  160. package/src/biz/page-templates/sign-in-page/index.ts +18 -0
  161. package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
  162. package/src/biz/record-detail/compile.ts +290 -0
  163. package/src/biz/record-detail/index.ts +22 -0
  164. package/src/biz/record-detail/shell.ts +64 -0
  165. package/src/biz/settings-center/compile.ts +100 -0
  166. package/src/biz/settings-center/index.ts +18 -0
  167. package/src/biz/settings-center/shell.ts +51 -0
  168. package/src/biz/shared/action-host.ts +469 -0
  169. package/src/biz/shared/coordinator.ts +516 -0
  170. package/src/biz/shared/index.ts +9 -0
  171. package/src/biz/shared/pipes.ts +58 -0
  172. package/src/biz/shared/runtime-hub.ts +112 -0
  173. package/src/biz/shared/step-values.ts +25 -0
  174. package/src/biz/single-form/compile.ts +146 -0
  175. package/src/biz/single-form/index.ts +18 -0
  176. package/src/biz/single-form/shell.ts +38 -0
  177. package/src/biz/standard-crud/bridge.ts +11 -0
  178. package/src/biz/standard-crud/compile.ts +546 -0
  179. package/src/biz/standard-crud/index.ts +18 -0
  180. package/src/biz/standard-crud/shell.ts +157 -0
  181. package/src/biz/step-form/compile.ts +400 -0
  182. package/src/biz/step-form/hub.ts +412 -0
  183. package/src/biz/step-form/index.ts +23 -0
  184. package/src/biz/step-form/shell.ts +96 -0
  185. package/src/biz/step-form/steps-ref.ts +112 -0
  186. package/src/biz/types.ts +96 -0
  187. package/src/cli/kit-cli.ts +102 -0
  188. package/src/compile/action-host-attach.ts +76 -0
  189. package/src/compile/compile-page.ts +472 -0
  190. package/src/compile/component-candidates.ts +147 -0
  191. package/src/compile/fragment.ts +104 -0
  192. package/src/compile/hints.ts +255 -0
  193. package/src/compile/index.ts +16 -0
  194. package/src/compile/locate.ts +166 -0
  195. package/src/compile/page-params.ts +80 -0
  196. package/src/compile/parse.ts +355 -0
  197. package/src/compile/redirect.ts +90 -0
  198. package/src/compile/registry.ts +30 -0
  199. package/src/compile/remove-guard.ts +99 -0
  200. package/src/compile/styles.ts +244 -0
  201. package/src/compile/types.ts +106 -0
  202. package/src/data/amount-breakdown.ts +132 -0
  203. package/src/data/anchor-nav.ts +225 -0
  204. package/src/data/approval-flow.ts +269 -0
  205. package/src/data/assignment-picker.ts +652 -0
  206. package/src/data/async-result-panel.ts +308 -0
  207. package/src/data/breadcrumbs.ts +197 -0
  208. package/src/data/calendar.ts +363 -0
  209. package/src/data/carousel.ts +408 -0
  210. package/src/data/chart.ts +726 -0
  211. package/src/data/checklist.ts +215 -0
  212. package/src/data/code-view.ts +415 -0
  213. package/src/data/comment-thread.ts +342 -0
  214. package/src/data/confirm-dialog.ts +144 -0
  215. package/src/data/context-menu.ts +216 -0
  216. package/src/data/d9-limits.ts +42 -0
  217. package/src/data/d9-util.ts +81 -0
  218. package/src/data/diff.ts +239 -0
  219. package/src/data/display-util.ts +135 -0
  220. package/src/data/dock.ts +152 -0
  221. package/src/data/embed.ts +200 -0
  222. package/src/data/field-mapper.ts +544 -0
  223. package/src/data/flow-editor-contract.ts +41 -0
  224. package/src/data/flow-editor.ts +2622 -0
  225. package/src/data/flow-remote-options.ts +257 -0
  226. package/src/data/footer.ts +157 -0
  227. package/src/data/form-draft-registry.ts +76 -0
  228. package/src/data/gantt.ts +430 -0
  229. package/src/data/hero.ts +149 -0
  230. package/src/data/image-viewer.ts +333 -0
  231. package/src/data/index.ts +268 -0
  232. package/src/data/item-list.ts +335 -0
  233. package/src/data/kanban.ts +667 -0
  234. package/src/data/media-grid.ts +246 -0
  235. package/src/data/mega-menu.ts +257 -0
  236. package/src/data/menu-dom.ts +169 -0
  237. package/src/data/menu.ts +464 -0
  238. package/src/data/mockup.ts +176 -0
  239. package/src/data/modal-dialog.ts +182 -0
  240. package/src/data/navbar.ts +292 -0
  241. package/src/data/object-form.ts +1981 -0
  242. package/src/data/options-bus.ts +24 -0
  243. package/src/data/outcome-watch.ts +40 -0
  244. package/src/data/overlay-portal.ts +6 -0
  245. package/src/data/pager.ts +473 -0
  246. package/src/data/permission-matrix.ts +432 -0
  247. package/src/data/permission-tree.ts +916 -0
  248. package/src/data/pricing-table.ts +269 -0
  249. package/src/data/prompt-dialog.ts +235 -0
  250. package/src/data/reaction-bar.ts +236 -0
  251. package/src/data/record-card.ts +413 -0
  252. package/src/data/record-picker.ts +489 -0
  253. package/src/data/redirect.ts +109 -0
  254. package/src/data/remote-options.ts +54 -0
  255. package/src/data/request-console.ts +399 -0
  256. package/src/data/resident.ts +58 -0
  257. package/src/data/result-panel.ts +160 -0
  258. package/src/data/rich-text.ts +626 -0
  259. package/src/data/row-editor.ts +1066 -0
  260. package/src/data/rule-builder.ts +1137 -0
  261. package/src/data/shape-util.ts +221 -0
  262. package/src/data/staged-rows.ts +69 -0
  263. package/src/data/stat-group.ts +231 -0
  264. package/src/data/static-lazy.ts +63 -0
  265. package/src/data/static-registry.ts +227 -0
  266. package/src/data/steps.ts +195 -0
  267. package/src/data/survey.ts +455 -0
  268. package/src/data/system-switcher.ts +243 -0
  269. package/src/data/timeline.ts +204 -0
  270. package/src/data/tour-guide.ts +392 -0
  271. package/src/data/transfer.ts +597 -0
  272. package/src/data/tree-check.ts +30 -0
  273. package/src/data/tree-table.ts +674 -0
  274. package/src/data/tree.ts +656 -0
  275. package/src/data/trend-line.ts +147 -0
  276. package/src/data/virtual-rows.ts +556 -0
  277. package/src/data/watermark.ts +140 -0
  278. package/src/data/wrap.ts +267 -0
  279. package/src/data/wrapped-candidates.ts +96 -0
  280. package/src/frames/blank-frame.ts +19 -0
  281. package/src/frames/index.ts +44 -0
  282. package/src/frames/page-bar.ts +185 -0
  283. package/src/frames/page-header.ts +185 -0
  284. package/src/frames/page-status.ts +54 -0
  285. package/src/frames/resize-handle.ts +147 -0
  286. package/src/frames/shared.ts +242 -0
  287. package/src/frames/single-frame.ts +16 -0
  288. package/src/frames/split-frame/index.ts +4 -0
  289. package/src/frames/split-frame/shell.ts +219 -0
  290. package/src/frames/split-frame/span.ts +64 -0
  291. package/src/frames/split-frame/wiring.ts +164 -0
  292. package/src/frames/tabs-frame/index.ts +3 -0
  293. package/src/frames/tabs-frame/shell.ts +112 -0
  294. package/src/frames/tabs-frame/wiring.ts +69 -0
  295. package/src/frames/top-main-frame.ts +20 -0
  296. package/src/frames/types.ts +72 -0
  297. package/src/frames/workspace-frame/extras.ts +197 -0
  298. package/src/frames/workspace-frame/index.ts +13 -0
  299. package/src/frames/workspace-frame/shell.ts +282 -0
  300. package/src/frames/workspace-frame/state.ts +152 -0
  301. package/src/frames/workspace-frame/view.ts +1013 -0
  302. package/src/generated/kit-grammar-runtime.ts +2822 -0
  303. package/src/generated/page-origin.ts +57 -0
  304. package/src/i18n/index.ts +22 -0
  305. package/src/i18n/kit-text.ts +692 -0
  306. package/src/i18n/resolve-text-refs.ts +128 -0
  307. package/src/index.ts +6 -0
  308. package/src/object-renderer/action-gate.ts +216 -0
  309. package/src/object-renderer/adopt-gate.ts +333 -0
  310. package/src/object-renderer/arrange.ts +411 -0
  311. package/src/object-renderer/candidates.ts +68 -0
  312. package/src/object-renderer/collapse-wiring.ts +99 -0
  313. package/src/object-renderer/collection-expand.ts +185 -0
  314. package/src/object-renderer/collection-parts.ts +653 -0
  315. package/src/object-renderer/collection-table.ts +503 -0
  316. package/src/object-renderer/collection.ts +628 -0
  317. package/src/object-renderer/compile-data.ts +549 -0
  318. package/src/object-renderer/defaults.ts +252 -0
  319. package/src/object-renderer/display-checks.ts +153 -0
  320. package/src/object-renderer/emit-events.ts +498 -0
  321. package/src/object-renderer/emit-object.ts +98 -0
  322. package/src/object-renderer/emit-static.ts +1036 -0
  323. package/src/object-renderer/field-policy.ts +89 -0
  324. package/src/object-renderer/field-value.ts +581 -0
  325. package/src/object-renderer/form-detail.ts +116 -0
  326. package/src/object-renderer/index.ts +13 -0
  327. package/src/object-renderer/linkage.ts +371 -0
  328. package/src/object-renderer/merge-class.ts +126 -0
  329. package/src/object-renderer/mode.ts +25 -0
  330. package/src/object-renderer/outcome-draft.ts +61 -0
  331. package/src/object-renderer/parts.ts +136 -0
  332. package/src/object-renderer/pick-component.ts +36 -0
  333. package/src/object-renderer/render-object.ts +724 -0
  334. package/src/object-renderer/request-actions.ts +581 -0
  335. package/src/object-renderer/skeleton.ts +101 -0
  336. package/src/object-renderer/table-actions.ts +438 -0
  337. package/src/object-renderer/table-summary.ts +105 -0
  338. package/src/object-renderer/table-tools.ts +1072 -0
  339. package/src/object-renderer/types.ts +936 -0
  340. package/src/page-target/ai-surface.ts +154 -0
  341. package/src/page-target/compile.ts +354 -0
  342. package/src/page-target/drift.ts +186 -0
  343. package/src/page-target/index.ts +25 -0
  344. package/src/page-target/intent-map.ts +137 -0
  345. package/src/page-target/intent-schema.ts +711 -0
  346. package/src/page-target/origin.ts +17 -0
  347. package/src/page-target/target.ts +450 -0
  348. package/src/page-target/writer-policy.ts +315 -0
  349. package/src/theme/block-theme.ts +202 -0
  350. package/src/theme/kit-theme-text.ts +2 -0
  351. package/src/theme/kit-theme.css +275 -0
  352. package/src/theme/kit-theme.tpl +275 -0
  353. package/src/theme/theme-tokens.ts +135 -0
@@ -0,0 +1,196 @@
1
+ // AuthPanel 编译:顶部当前用户摘要 + 左角色列表 + 右权限矩阵(PermissionMatrix)。沿用 ApprovalDesk 的枢纽与协调组件:
2
+ //
3
+ // 默认选中首个角色 KitLinkHub 的 rows(绑角色列表行数据)到达时选首行
4
+ // 切换角色 行点击(pickOnRow)-> SCOPE semantic link_pick -> 枢纽写 selection;
5
+ // 矩阵的 from.params 带关联键(link_sel_key);枢纽抛 picked -> 页面对矩阵 `SCOPE | window-reload`
6
+ // 授权保存 matrix.behavior.actions 里 id 为 save 的具名动作(on: toolbar,submit: 应用动作):
7
+ // 编译器取走它(不渲染工具栏按钮),名字作矩阵底部保存钮文案(save_label);
8
+ // 矩阵抛 saved { value: grants } -> 枢纽补当前选中角色行(field_action { id, value, row })
9
+ // -> 执行具名动作(row = 当前角色,value = grants)-> 成功提示 -> kit_reload(重取角色与矩阵)
10
+ // 约定:矩阵的 from 在页面刚加载、尚未选中角色时会不带关联键取一次——约定后端「缺关联键返回空」。
11
+ // user 是独立的当前用户摘要,不随角色选中变化。
12
+
13
+ import type { SomaScopeMirrorDecl } from 'soma-core';
14
+ import { viewAnchor } from '../../object-renderer/emit-static';
15
+ import type { KitObject } from '../../object-renderer/types';
16
+ import type { KitFragment } from '../../compile/fragment';
17
+ import type { KitBizContext, KitBizInput } from '../types';
18
+ import { KIT_COORD_EVENTS } from '../shared/coordinator';
19
+ import { KIT_LINK_EVENTS, KIT_LINK_MIRRORS, KIT_SEL_PATH } from '../link/hub';
20
+ import {
21
+ classesIn, dedupeDiagnostics, emitMember, fieldActionId, grantPageReset, isRec, keyFieldOf, mirrorPath, newParts,
22
+ normalizeMember, reloadPipe, semanticPipe, sortMirrors, type Parts, type Rec,
23
+ } from '../link/shared';
24
+ import { AUTH_PANEL_AREAS, AUTH_PANEL_CLASS, authPanelHtml, authPanelIds } from './shell';
25
+ import { kitText } from '../../i18n/kit-text';
26
+
27
+ const RESERVED = new Set(['page', 'p', 'ctrl', 'frame', 'tabs']);
28
+ const SAVE_ACTION = 'save';
29
+
30
+ export function authPanelObjectName(pageId: string, role: 'user' | 'roles' | 'matrix'): string {
31
+ const name = `${pageId}_${role}`;
32
+ return RESERVED.has(name) ? `${name}_obj` : name;
33
+ }
34
+
35
+ function finish(out: Parts, html: string): KitFragment {
36
+ return {
37
+ html,
38
+ ui: { data: out.data, scopes: out.scopes as unknown as Record<string, unknown>, show: out.show },
39
+ events: out.events,
40
+ components: [...out.components].sort(),
41
+ candidates: [...out.candidates].sort(),
42
+ diagnostics: dedupeDiagnostics(out.diagnostics),
43
+ };
44
+ }
45
+
46
+ function isStaticView(s: unknown): boolean {
47
+ const v = isRec(s) && isRec(s.view) ? s.view : undefined;
48
+ return !!v && (v.staticComponent !== undefined || (isRec(v.summary) && v.summary.staticComponent !== undefined));
49
+ }
50
+
51
+ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFragment {
52
+ const SAVED_NOTICE = kitText('soma.kit.auth_saved', undefined, ctx.locale);
53
+ const out = newParts(['KitLinkHub', 'KitCrudBridge']);
54
+ const fail = (code: string, message: string, path: string): void => { out.diagnostics.push({ code, message, path }); };
55
+
56
+ const rawUser = input.objects.user;
57
+ const rawRoles = input.objects.roles;
58
+ const rawMatrix = input.objects.matrix;
59
+ if (!isRec(rawRoles) || !isRec(rawRoles.schema) || !isRec(rawRoles.behavior)) {
60
+ fail('KIT-BIZ-001', 'AuthPanel 缺少必填对象角色槽 roles(需含 schema 与 behavior)', 'product.objects.roles');
61
+ }
62
+ if (!isRec(rawMatrix) || !isRec(rawMatrix.behavior)) {
63
+ fail('KIT-BIZ-001', 'AuthPanel 缺少必填对象角色槽 matrix(需含 behavior,view 为写死形状件 PermissionMatrix)', 'product.objects.matrix');
64
+ } else if (!isRec(rawMatrix.view)) {
65
+ fail('KIT-BIZ-001', 'matrix 缺少 view', 'product.objects.matrix.view');
66
+ } else if (!isStaticView(rawMatrix)) {
67
+ fail('KIT-BIZ-001', 'AuthPanel 的 matrix.view 必须是写死形状件 PermissionMatrix', 'product.objects.matrix');
68
+ }
69
+ if (rawUser !== undefined && (!isRec(rawUser) || !isRec(rawUser.schema) || !isRec(rawUser.behavior))) {
70
+ fail('KIT-BIZ-001', 'AuthPanel 的 user 必须是对象声明(需含 schema 与 behavior)', 'product.objects.user');
71
+ }
72
+ for (const key of Object.keys(input.areaClass ?? {})) {
73
+ if (!(AUTH_PANEL_AREAS as readonly string[]).includes(key)) {
74
+ fail('KIT-PAGE-001', `areaClass 里的区域名 "${key}" 不在 AuthPanel 的区域闭集 ${AUTH_PANEL_AREAS.join(' / ')} 内`, `product.areaClass.${key}`);
75
+ }
76
+ }
77
+ if (out.diagnostics.length > 0) return finish(out, '');
78
+
79
+ // matrix:取走 save 动作(名字作保存钮文案,submit 作保存时执行的具名动作)
80
+ const matrixSrc = JSON.parse(JSON.stringify(rawMatrix)) as Rec;
81
+ const mBehavior = matrixSrc.behavior as Rec;
82
+ const mActions = Array.isArray(mBehavior.actions) ? (mBehavior.actions as Array<Rec>) : [];
83
+ const saveAct = mActions.find((a) => a.id === SAVE_ACTION);
84
+ if (saveAct === undefined || typeof saveAct.submit !== 'string' || saveAct.submit === '') {
85
+ fail('KIT-BIZ-003', `matrix 必须声明 id 为 ${SAVE_ACTION} 的具名保存动作(behavior.actions,on: toolbar,submit: 应用动作名)`, 'product.objects.matrix.behavior.actions');
86
+ } else if (!ctx.registeredActions.has(saveAct.submit)) {
87
+ fail('KIT-EVT-001', `matrix 的保存动作 "${saveAct.submit}" 未在应用的具名动作中登记`, 'product.objects.matrix.behavior.actions');
88
+ }
89
+ if (out.diagnostics.length > 0 || saveAct === undefined) return finish(out, '');
90
+ mBehavior.actions = mActions.filter((a) => a.id !== SAVE_ACTION);
91
+
92
+ const ids = authPanelIds(ctx.pageId);
93
+ const areaClass = input.areaClass ?? {};
94
+ const link = ids.link;
95
+ const rolesName = authPanelObjectName(ctx.pageId, 'roles');
96
+ const matrixName = authPanelObjectName(ctx.pageId, 'matrix');
97
+ const userName = authPanelObjectName(ctx.pageId, 'user');
98
+
99
+ const rolesNorm = normalizeMember(rawRoles, {
100
+ path: 'product.objects.roles',
101
+ allowedViews: ['list'],
102
+ ensure: ['list'],
103
+ withForm: false,
104
+ });
105
+ out.diagnostics.push(...rolesNorm.diagnostics);
106
+ const roles: KitObject = rolesNorm.obj;
107
+ const roleKey = keyFieldOf(roles);
108
+ if (roleKey === undefined) {
109
+ fail('KIT-BIZ-001', 'roles 的 schema 必须有 key 字段(或名为 id 的字段):权限矩阵靠它关联', 'product.objects.roles.schema');
110
+ return finish(out, '');
111
+ }
112
+ const selKey = mirrorPath(link, KIT_LINK_MIRRORS.selKey);
113
+ const linkKey = typeof mBehavior.linkKey === 'string' && mBehavior.linkKey !== '' ? mBehavior.linkKey : roleKey;
114
+ const matrixNorm = normalizeMember(matrixSrc, {
115
+ path: 'product.objects.matrix',
116
+ allowedViews: ['summary'],
117
+ ensure: ['summary'],
118
+ withForm: false,
119
+ params: { [linkKey]: `$${selKey}` },
120
+ requireLink: true,
121
+ });
122
+ out.diagnostics.push(...matrixNorm.diagnostics);
123
+ const matrix: KitObject = matrixNorm.obj;
124
+ if (matrix.view?.summary !== undefined) {
125
+ const props = isRec(matrix.view.summary.props) ? matrix.view.summary.props : {};
126
+ matrix.view.summary = { ...matrix.view.summary, props: { save_label: String(saveAct.name ?? ''), ...props } };
127
+ }
128
+ let user: KitObject | undefined;
129
+ if (rawUser !== undefined) {
130
+ const un = normalizeMember(rawUser, { path: 'product.objects.user', allowedViews: ['summary'], ensure: ['summary'], withForm: false });
131
+ out.diagnostics.push(...un.diagnostics);
132
+ user = un.obj;
133
+ }
134
+ if (out.diagnostics.length > 0) return finish(out, '');
135
+
136
+ const refresh = [semanticPipe(link, KIT_COORD_EVENTS.reload)];
137
+ const fieldSteps: Array<Rec> = [];
138
+ const r = emitMember(out, {
139
+ object: rolesName, scope: `${rolesName}_scope`, obj: roles, ctx, link, hubId: ids.hub, refresh, pick: true, fieldSteps,
140
+ });
141
+ const mm = emitMember(out, { object: matrixName, scope: `${matrixName}_scope`, obj: matrix, ctx, link, hubId: ids.hub, refresh, fieldSteps });
142
+ const pageScopes: string[] = [];
143
+ if (grantPageReset(out, `${matrixName}_scope`, ids.hub)) pageScopes.push(`${matrixName}_scope`);
144
+ let userHtml: { title: string; html: string } | null = null;
145
+ if (user !== undefined) {
146
+ const um = emitMember(out, { object: userName, scope: `${userName}_scope`, obj: user, ctx, link, hubId: ids.hub, refresh, fieldSteps });
147
+ userHtml = {
148
+ title: typeof (rawUser as Rec).title === 'string' ? ((rawUser as Rec).title as string) : '',
149
+ html: [um.r.parts.toolbar ?? '', um.listHtml, um.r.parts.summary ?? ''].filter((x) => x !== '').join('\n'),
150
+ };
151
+ }
152
+
153
+ // 授权保存:矩阵抛 saved -> 具名动作 -> 提示 -> 重取
154
+ // 经枢纽转一道:枢纽补上当前选中的角色行,抛 field_action { id, value: grants, row: 当前角色 },动作的 row 就是当前角色
155
+ const saveId = fieldActionId('matrix', SAVE_ACTION);
156
+ out.events[`${viewAnchor(matrixName, 'summary')}.saved`] = semanticPipe(link, `${KIT_LINK_EVENTS.fieldPrefix}${saveId}`);
157
+ const saveWhen = { field: 'id', op: 'eq', value: saveId };
158
+ fieldSteps.push(
159
+ { when: saveWhen, do: `ACTION | ${saveAct.submit as string}` },
160
+ { when: saveWhen, do: `NOTIFY | success | ${SAVED_NOTICE}` },
161
+ );
162
+
163
+ const mirrors: SomaScopeMirrorDecl[] = [
164
+ { key: KIT_LINK_MIRRORS.selKey, slice: 'selection', path: `${KIT_SEL_PATH}.${roleKey}`, as: 'value' },
165
+ { key: KIT_LINK_MIRRORS.selRow, slice: 'selection', path: KIT_SEL_PATH, as: 'value' },
166
+ ];
167
+ out.scopes[link] = {
168
+ id: link,
169
+ object: rolesName,
170
+ slices: [{ name: 'selection', owner: ids.hub }, { name: 'focus', owner: ids.coord }],
171
+ mirrors: sortMirrors(mirrors),
172
+ };
173
+ out.show[ids.hub] = {
174
+ props: { scope: link, keyField: roleKey, linkKey: '', autoSelect: true, rows: `page.data.${rolesName}.${r.r.compiled.listShape.rows}`, pageScopes },
175
+ };
176
+ out.show[ids.coord] = {
177
+ props: { scope: link, object: rolesName, keyField: roleKey, reloads: [matrixName, ...(user !== undefined ? [userName] : [])], overlays: {} },
178
+ };
179
+ out.events[`${ids.hub}.picked`] = { steps: [{ do: reloadPipe(`${matrixName}_scope`) }] };
180
+ if (fieldSteps.length > 0) out.events[`${ids.hub}.field_action`] = { steps: [...fieldSteps, ...refresh.map((p) => ({ do: p }))] };
181
+
182
+ const title = (raw: unknown): string => (isRec(raw) && typeof raw.title === 'string' ? raw.title : '');
183
+ const html = authPanelHtml(
184
+ ids,
185
+ {
186
+ user: userHtml,
187
+ roles: { title: title(rawRoles), html: [r.r.parts.toolbar ?? '', r.r.parts.filter ?? '', r.listHtml].filter((x) => x !== '').join('\n') },
188
+ matrix: { title: title(rawMatrix), html: [mm.r.parts.toolbar ?? '', mm.r.parts.summary ?? ''].filter((x) => x !== '').join('\n') },
189
+ },
190
+ areaClass,
191
+ input.class,
192
+ );
193
+ for (const c of classesIn(html)) out.candidates.add(c);
194
+ for (const c of Object.values(AUTH_PANEL_CLASS)) for (const t of c.split(/\s+/)) if (t !== '') out.candidates.add(t);
195
+ return finish(out, html);
196
+ }
@@ -0,0 +1,24 @@
1
+ // AuthPanel:账户与权限(规格 5.3)——当前用户摘要 + 角色列表 + 权限矩阵 + 授权保存。
2
+ // 对象角色槽:user(可选:当前用户摘要,summary 视图)、roles(必填:角色列表,list 视图,行可点选)、
3
+ // matrix(必填:写死形状件 PermissionMatrix,随选中角色重取;授权保存写成 behavior.actions 里 id 为 save 的具名动作)。
4
+
5
+ // 授权保存是写死的具名动作:矩阵的 `saved { value: grants }` 作为动作的 value,经 KitLinkHub 补上选中的角色行(field_action),动作参数的 `row` 就是当前角色;
6
+ // 切换角色后矩阵由 KitLinkHub 的 `picked` 事件 `window-reload` 重取(同 MasterSub),不靠组件自己 watch。
7
+
8
+ import { defineKitBizComponent } from '../define';
9
+ import { compileAuthPanel } from './compile';
10
+ import { AUTH_PANEL_AREAS } from './shell';
11
+
12
+ export const AuthPanel = defineKitBizComponent({
13
+ kind: 'AuthPanel',
14
+ roles: {
15
+ user: { required: false, views: ['summary'] },
16
+ roles: { required: true, views: ['list'] },
17
+ matrix: { required: true, views: ['summary'] },
18
+ },
19
+ areas: [...AUTH_PANEL_AREAS],
20
+ compile: compileAuthPanel,
21
+ });
22
+
23
+ export { compileAuthPanel, authPanelObjectName } from './compile';
24
+ export { AUTH_PANEL_AREAS, AUTH_PANEL_CLASS, authPanelIds } from './shell';
@@ -0,0 +1,46 @@
1
+ // AuthPanel 的 HTML 代码壳:顶部当前用户摘要,下方左角色列表 + 右权限矩阵。只有结构与 Tailwind 类,不写原生 CSS。
2
+ // 分栏靠容器查询变体 `@md:`:窄容器下上下堆叠;达到 md 档角色 4 / 矩阵 8(共 12 份)。
3
+
4
+ import { mergeClass } from '../../object-renderer/merge-class';
5
+ import { cls, esc, host } from '../link/shared';
6
+
7
+ /** 壳的内部区域名(`areaClass` 的合法键) */
8
+ export const AUTH_PANEL_AREAS = ['root', 'user', 'roles', 'matrix'] as const;
9
+ export type AuthPanelArea = (typeof AUTH_PANEL_AREAS)[number];
10
+
11
+ const CARD = 'flex min-w-0 flex-col gap-3 rounded-lg border border-border-subtle bg-surface-raised p-4 shadow-xs';
12
+
13
+ export const AUTH_PANEL_CLASS = {
14
+ root: '@container flex flex-col gap-4',
15
+ user: CARD,
16
+ grid: 'grid grid-cols-12 gap-4',
17
+ roles: `col-span-12 @md:col-span-4 ${CARD}`,
18
+ matrix: `col-span-12 @md:col-span-8 ${CARD}`,
19
+ title: 'text-base font-semibold text-fg',
20
+ } as const;
21
+
22
+ export function authPanelIds(pageId: string): { root: string; hub: string; coord: string; link: string } {
23
+ return { root: `${pageId}__ap_root`, hub: `${pageId}__hub`, coord: `${pageId}__coord`, link: `${pageId}_link` };
24
+ }
25
+
26
+ export interface AuthBlock {
27
+ title: string;
28
+ html: string;
29
+ }
30
+
31
+ /** 整个壳:协作组件宿主 + 用户摘要 + 角色 / 矩阵两栏。区域类按 7.3 同族规则覆写 */
32
+ export function authPanelHtml(
33
+ ids: ReturnType<typeof authPanelIds>,
34
+ parts: { user: AuthBlock | null; roles: AuthBlock; matrix: AuthBlock },
35
+ areaClass: Record<string, string>,
36
+ extra: string | undefined,
37
+ ): string {
38
+ const block = (area: 'user' | 'roles' | 'matrix', b: AuthBlock): string => {
39
+ const title = b.title === '' ? '' : `<h3${cls(AUTH_PANEL_CLASS.title)}>${esc(b.title)}</h3>`;
40
+ return `<section${cls(mergeClass(AUTH_PANEL_CLASS[area], areaClass[area]))}>${title}${b.html}</section>`;
41
+ };
42
+ const user = parts.user === null ? '' : `${block('user', parts.user)}\n`;
43
+ const root = mergeClass(mergeClass(AUTH_PANEL_CLASS.root, areaClass.root), extra);
44
+ return `<div data-soma-id="${esc(ids.root)}"${cls(root)}>\n${host('KitLinkHub', ids.hub)}${host('KitCrudBridge', ids.coord)}\n${user}`
45
+ + `<div${cls(AUTH_PANEL_CLASS.grid)}>\n${block('roles', parts.roles)}\n${block('matrix', parts.matrix)}\n</div>\n</div>`;
46
+ }
@@ -0,0 +1,173 @@
1
+ // CategoryCrud 编译:左侧分类(树或列表)+ 右侧条目筛选 / 列表(或卡片墙)/ 表单(规格 5.3)。
2
+ //
3
+ // 点击分类节点 Tree 的 select -> `SCOPE | set | <链接作用域> | selection | from:item`(Tree 是页面直接声明的实例,自己是 selection 的 owner);
4
+ // 分类是普通列表时改用行点击(pickOnRow)走枢纽。选中项一变:枢纽把条目的 view 切片回第 1 页,抛 picked
5
+ // -> 页面 `SCOPE | semantic kit_pick`(协调组件写选中键与新建预填,并重取条目);条目 from.params 带分类主键(镜像 link_sel_key)
6
+ // 点新增条目 工具栏「新增」-> 协调组件 crud_open_create,初值预填当前分类主键(关联字段,permission: create)
7
+ // 写入成功 表单 saved -> 协调组件 kit_saved:关窗并重取条目
8
+ //
9
+ // 缺分类键不取数:条目的 from 编成 core `from[].require`(requireLink),尚未选分类时对象落 idle,不发请求。
10
+
11
+ import type { SomaScopeMirrorDecl } from 'soma-core';
12
+ import { viewAnchor } from '../../object-renderer/emit-static';
13
+ import type { KitObject, KitType } from '../../object-renderer/types';
14
+ import type { KitFragment } from '../../compile/fragment';
15
+ import type { KitBizContext, KitBizInput } from '../types';
16
+ import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS } from '../shared/coordinator';
17
+ import { wireDialogForm } from '../shared/pipes';
18
+ import { CRUD_CLASS, dialogHtml, dialogIds, dialogTitles } from '../standard-crud/shell';
19
+ import { KIT_LINK_MIRRORS, KIT_SEL_PATH } from '../link/hub';
20
+ import {
21
+ IDENT, classesIn, dedupeDiagnostics, emitMember, grantPageReset, isRec, keyFieldOf, mirrorPath, newParts,
22
+ normalizeMember, patchProps, semanticPipe, sortMirrors, type Parts, type Rec,
23
+ } from '../link/shared';
24
+ import { kitText } from '../../i18n/kit-text';
25
+ import { CATEGORY_CRUD_AREAS, CATEGORY_CRUD_CLASS, categoryCrudHtml, categoryCrudIds } from './shell';
26
+
27
+ export function categoryObjectName(pageId: string, role: 'category' | 'item'): string {
28
+ const name = `${pageId}_${role}`;
29
+ return name === 'page' || name === 'p' || name === 'ctrl' ? `${name}_obj` : name;
30
+ }
31
+
32
+ function finish(out: Parts, html: string): KitFragment {
33
+ return {
34
+ html,
35
+ ui: { data: out.data, scopes: out.scopes as unknown as Record<string, unknown>, show: out.show },
36
+ events: out.events,
37
+ components: [...out.components].sort(),
38
+ candidates: [...out.candidates].sort(),
39
+ diagnostics: dedupeDiagnostics(out.diagnostics),
40
+ };
41
+ }
42
+
43
+ export function compileCategoryCrud(input: KitBizInput, ctx: KitBizContext): KitFragment {
44
+ const CLOSE_LABEL = kitText('soma.kit.close', undefined, ctx.locale);
45
+ const CANCEL_LABEL = kitText('soma.kit.cancel', undefined, ctx.locale);
46
+ const out = newParts(['KitLinkHub', 'KitCrudBridge', 'Button']);
47
+ const fail = (code: string, message: string, path: string): void => { out.diagnostics.push({ code, message, path }); };
48
+
49
+ const rawCat = input.objects.category;
50
+ const rawItem = input.objects.item;
51
+ for (const [role, raw] of [['category', rawCat], ['item', rawItem]] as const) {
52
+ if (!isRec(raw) || !isRec(raw.behavior)) {
53
+ fail('KIT-BIZ-001', `CategoryCrud 缺少必填对象角色槽 ${role}(需含 behavior)`, `product.objects.${role}`);
54
+ }
55
+ }
56
+ for (const key of Object.keys(input.areaClass ?? {})) {
57
+ if (!(CATEGORY_CRUD_AREAS as readonly string[]).includes(key)) {
58
+ fail('KIT-PAGE-001', `areaClass 里的区域名 "${key}" 不在 CategoryCrud 的区域闭集 ${CATEGORY_CRUD_AREAS.join(' / ')} 内`, `product.areaClass.${key}`);
59
+ }
60
+ }
61
+ if (out.diagnostics.length > 0) return finish(out, '');
62
+
63
+ const ids = categoryCrudIds(ctx.pageId);
64
+ const areaClass = input.areaClass ?? {};
65
+ const link = ids.link;
66
+ const catName = categoryObjectName(ctx.pageId, 'category');
67
+ const itemName = categoryObjectName(ctx.pageId, 'item');
68
+ const catScope = `${catName}_scope`;
69
+ const itemScope = `${itemName}_scope`;
70
+ const mk = KIT_COORD_MIRRORS;
71
+
72
+ // ---- 分类
73
+ const catNorm = normalizeMember({ schema: {}, ...(rawCat as unknown as Rec) }, {
74
+ path: 'product.objects.category',
75
+ // filter:分类列表的筛选条(筛选驱动分类对象重取;分类树/列表的选中项失效时由枢纽按既有规则处理)
76
+ allowedViews: ['filter', 'list', 'summary'],
77
+ ensure: 'any',
78
+ withForm: false,
79
+ });
80
+ out.diagnostics.push(...catNorm.diagnostics);
81
+ const cat: KitObject = catNorm.obj;
82
+ const staticView = cat.view?.summary?.staticComponent !== undefined ? cat.view.summary : undefined;
83
+ const catKey = staticView?.map?.id ?? keyFieldOf(cat) ?? (staticView !== undefined ? 'id' : undefined);
84
+ if (catKey === undefined) {
85
+ fail('KIT-BIZ-001', 'category 的 schema 必须有 key 字段(或名为 id 的字段):条目靠它关联', 'product.objects.category.schema');
86
+ return finish(out, '');
87
+ }
88
+ const catType: KitType = cat.schema[catKey]?.type === 'int' ? 'int' : 'text';
89
+
90
+ // ---- 条目
91
+ const itemBehavior = (rawItem as unknown as Rec).behavior as Rec;
92
+ const linkKey = typeof itemBehavior.linkKey === 'string' && itemBehavior.linkKey !== '' ? itemBehavior.linkKey : catKey;
93
+ if (!IDENT.test(linkKey)) fail('KIT-PAGE-001', `linkKey "${linkKey}" 必须是标识符`, 'product.objects.item.behavior.linkKey');
94
+ const selKey = mirrorPath(link, KIT_LINK_MIRRORS.selKey);
95
+ const itemNorm = normalizeMember(rawItem, {
96
+ path: 'product.objects.item',
97
+ allowedViews: ['list', 'summary', 'filter', 'form'],
98
+ ensure: ['list'],
99
+ withForm: true,
100
+ ...(ctx.locale !== undefined ? { locale: ctx.locale } : {}),
101
+ params: { [linkKey]: `$${selKey}` },
102
+ requireLink: true,
103
+ link: { field: linkKey, type: catType },
104
+ });
105
+ out.diagnostics.push(...itemNorm.diagnostics);
106
+ if (out.diagnostics.length > 0) return finish(out, '');
107
+ const item: KitObject = itemNorm.obj;
108
+
109
+ const refresh = [semanticPipe(link, KIT_COORD_EVENTS.reload)];
110
+ // H1a:带预填的「新建」钮(语义事件名 -> { 字段: 字面量 }),整表交协调组件(新建表单是明细对象的,分类对象的新建钮不带预填)
111
+ const createPrefills: Record<string, Record<string, unknown>> = {};
112
+ const c = emitMember(out, { object: catName, scope: catScope, obj: cat, ctx, link, hubId: ids.hub, refresh: [], pick: staticView === undefined });
113
+ const it = emitMember(out, {
114
+ object: itemName, scope: itemScope, obj: item, ctx, link, hubId: ids.hub, refresh, createPrefills,
115
+ emitInput: { formModePath: mirrorPath(link, mk.mode.key), formInitialPath: mirrorPath(link, mk.row.key) },
116
+ });
117
+ const pageScopes = grantPageReset(out, itemScope, ids.hub) ? [itemScope] : [];
118
+
119
+ // 分类树:select 直接写 selection(Tree 自己是 owner)
120
+ const treeId = staticView !== undefined ? viewAnchor(catName, 'summary') : undefined;
121
+ // 选中后按新的类目键重取右侧列表(读接口 params 引用选中镜像)
122
+ if (treeId !== undefined) {
123
+ out.events[`${treeId}.select`] = { steps: [{ do: `SCOPE | set | ${link} | selection | path:${KIT_SEL_PATH} | from:item` }, { do: semanticPipe(link, KIT_COORD_EVENTS.reload) }] };
124
+ }
125
+
126
+ // ---- 链接作用域:selection 归分类树(或枢纽),focus 归协调组件
127
+ const mirrors: SomaScopeMirrorDecl[] = [
128
+ { key: KIT_LINK_MIRRORS.selKey, slice: 'selection', path: `${KIT_SEL_PATH}.${catKey}`, as: 'value' },
129
+ { key: KIT_LINK_MIRRORS.selRow, slice: 'selection', path: KIT_SEL_PATH, as: 'value' },
130
+ ];
131
+ for (const x of [mk.openForm, mk.creating, mk.editing, mk.mode, mk.row, mk.id]) mirrors.push({ key: x.key, slice: 'focus', path: x.path, as: x.as });
132
+ out.scopes[link] = {
133
+ id: link,
134
+ object: itemName,
135
+ slices: [{ name: 'selection', owner: treeId ?? ids.hub }, { name: 'focus', owner: ids.coord }],
136
+ mirrors: sortMirrors(mirrors),
137
+ };
138
+
139
+ // ---- 弹窗表单
140
+ let dialog = '';
141
+ if (item.view?.form !== undefined) {
142
+ const formId = viewAnchor(itemName, 'form');
143
+ patchProps(out.show, formId, { scope: `${itemName}__form`, cancelLabel: CANCEL_LABEL });
144
+ wireDialogForm(out.events, formId, link);
145
+ const d = dialogIds(itemName);
146
+ out.show[d.dialogLayer] = { when: mirrorPath(link, mk.openForm.key) };
147
+ out.show[d.dialogTitleCreate] = { when: mirrorPath(link, mk.creating.key) };
148
+ out.show[d.dialogTitleEdit] = { when: mirrorPath(link, mk.editing.key) };
149
+ out.events[`${d.dialogClose}.click`] = semanticPipe(link, KIT_COORD_EVENTS.close);
150
+ const createName = item.behavior.actions?.find((a) => a.builtin === 'openCreate')?.name ?? kitText('soma.kit.create', undefined, ctx.locale);
151
+ const editName = item.behavior.actions?.find((a) => a.builtin === 'openEdit')?.name ?? kitText('soma.kit.edit', undefined, ctx.locale);
152
+ dialog = dialogHtml(d, dialogTitles(item.view?.form?.title, { create: createName, edit: editName }), it.r.parts.form ?? '', { dialog: areaClass.dialog ?? '' }, CLOSE_LABEL);
153
+ for (const cl of Object.values(CRUD_CLASS)) for (const t of cl.split(/\s+/)) if (t !== '') out.candidates.add(t);
154
+ }
155
+
156
+ // ---- 枢纽与协调组件
157
+ out.show[ids.hub] = { props: { scope: link, keyField: catKey, linkKey, autoSelect: false, rows: [], pageScopes } };
158
+ out.show[ids.coord] = {
159
+ props: {
160
+ scope: link, object: itemName, keyField: keyFieldOf(item) ?? '', reloads: [], overlays: {},
161
+ ...(Object.keys(createPrefills).length > 0 ? { createPrefills } : {}),
162
+ },
163
+ };
164
+ out.events[`${ids.hub}.picked`] = semanticPipe(link, KIT_COORD_EVENTS.pick);
165
+
166
+ // ---- 壳
167
+ const catHtml = [c.r.parts.toolbar ?? '', c.r.parts.filter ?? '', c.listHtml, c.r.parts.summary ?? ''].filter((x) => x !== '').join('\n');
168
+ const itemHtml = [it.r.parts.toolbar ?? '', it.r.parts.filter ?? '', it.listHtml, it.r.parts.summary ?? ''].filter((x) => x !== '').join('\n');
169
+ const html = categoryCrudHtml(ids, { category: catHtml, item: itemHtml, dialog }, areaClass, input.class);
170
+ for (const cl of classesIn(html)) out.candidates.add(cl);
171
+ for (const cl of Object.values(CATEGORY_CRUD_CLASS)) for (const t of cl.split(/\s+/)) if (t !== '') out.candidates.add(t);
172
+ return finish(out, html);
173
+ }
@@ -0,0 +1,19 @@
1
+ // CategoryCrud:左分类右条目联动(规格 5.3)。
2
+ // 对象角色槽:category(必填:左侧树或分类列表);item(必填:右侧受控条目,含筛选、列表 / 卡片墙与表单态)。
3
+
4
+ import { defineKitBizComponent } from '../define';
5
+ import { compileCategoryCrud } from './compile';
6
+ import { CATEGORY_CRUD_AREAS } from './shell';
7
+
8
+ export const CategoryCrud = defineKitBizComponent({
9
+ kind: 'CategoryCrud',
10
+ roles: {
11
+ category: { required: true, views: ['filter', 'list', 'summary'] },
12
+ item: { required: true, views: ['filter', 'list', 'summary', 'form'] },
13
+ },
14
+ areas: [...CATEGORY_CRUD_AREAS],
15
+ compile: compileCategoryCrud,
16
+ });
17
+
18
+ export { compileCategoryCrud, categoryObjectName } from './compile';
19
+ export { CATEGORY_CRUD_AREAS, CATEGORY_CRUD_CLASS, categoryCrudIds } from './shell';
@@ -0,0 +1,29 @@
1
+ // CategoryCrud 的 HTML 代码壳:左侧固定紧凑分类栏(默认 w-56)+ 右侧条目管理区。只有结构与 Tailwind 类,分栏靠容器查询变体。
2
+
3
+ import { mergeClass } from '../../object-renderer/merge-class';
4
+ import { cls, esc, host } from '../link/shared';
5
+
6
+ /** 壳的内部区域名(`areaClass` 的合法键) */
7
+ export const CATEGORY_CRUD_AREAS = ['root', 'categorySidebar', 'itemWorkspace', 'dialog'] as const;
8
+
9
+ export const CATEGORY_CRUD_CLASS = {
10
+ root: '@container flex flex-col gap-4 @md:flex-row',
11
+ categorySidebar: 'w-full shrink-0 @md:w-56 rounded-lg border border-border-subtle bg-surface-raised p-3 shadow-xs flex flex-col gap-2',
12
+ itemWorkspace: 'flex min-w-0 flex-1 flex-col gap-4',
13
+ } as const;
14
+
15
+ export function categoryCrudIds(pageId: string): { root: string; hub: string; coord: string; link: string } {
16
+ return { root: `${pageId}__cc_root`, hub: `${pageId}__hub`, coord: `${pageId}__coord`, link: `${pageId}_link` };
17
+ }
18
+
19
+ export function categoryCrudHtml(
20
+ ids: ReturnType<typeof categoryCrudIds>,
21
+ parts: { category: string; item: string; dialog: string },
22
+ areaClass: Record<string, string>,
23
+ extra: string | undefined,
24
+ ): string {
25
+ const side = `<aside${cls(mergeClass(CATEGORY_CRUD_CLASS.categorySidebar, areaClass.categorySidebar))}>${parts.category}</aside>`;
26
+ const main = `<section${cls(mergeClass(CATEGORY_CRUD_CLASS.itemWorkspace, areaClass.itemWorkspace))}>${parts.item}</section>`;
27
+ const root = mergeClass(mergeClass(CATEGORY_CRUD_CLASS.root, areaClass.root), extra);
28
+ return `<div data-soma-id="${esc(ids.root)}"${cls(root)}>\n${host('KitLinkHub', ids.hub)}${host('KitCrudBridge', ids.coord)}\n${side}\n${main}\n${parts.dialog}\n</div>`;
29
+ }
@@ -0,0 +1,111 @@
1
+ // CheckoutPage 编译:左「收货 / 支付信息」表单 + 右订单摘要(明细列表 + 金额汇总)。没有协作组件。
2
+ //
3
+ // form 必有 behavior.write 与 form 视图;有 behavior.from 时挂载回填(edit),没有则空表单(create);校验后提交走 data.submit,成功弹「提交成功」
4
+ // items 只读展示对象(list 或 summary,不允许动作 / write),订单明细 / 购物车行
5
+ // amounts 可选,只读展示对象;通常写 staticComponent: AmountBreakdown(金额原样展示,不计算)
6
+ // 金额是服务端事实:组件不在前端算价;提交成功后需要刷新明细 / 金额,由应用的 saved 之后的跳转或页面刷新承担。
7
+ // 与 StepForm 的区别:单页结算,表单与摘要并排,没有分步;与 MultiObjectBoard 的区别:表单是提交主体,摘要栏是写死的附属。
8
+
9
+ import { emitObject } from '../../object-renderer/emit-object';
10
+ import { viewAnchor } from '../../object-renderer/emit-static';
11
+ import type { KitObject, KitViewForm } from '../../object-renderer/types';
12
+ import type { KitFragment } from '../../compile/fragment';
13
+ import type { KitBizContext, KitBizInput } from '../types';
14
+ import { addEmit, classesIn, isRec, newParts, patchProps, type Rec } from '../link/shared';
15
+ import {
16
+ addClassTokens, checkAreas, emitReadOnlyMember, finishTemplate, normalizeFormObject, templateObjectName,
17
+ } from '../page-templates/shared';
18
+ import { CHECKOUT_PAGE_AREAS, CHECKOUT_PAGE_CLASS, checkoutPageHtml, checkoutPageIds } from './shell';
19
+ import { kitText } from '../../i18n/kit-text';
20
+
21
+
22
+ export function checkoutPageObjectName(pageId: string, role: 'form' | 'items' | 'amounts'): string {
23
+ return templateObjectName(pageId, role);
24
+ }
25
+
26
+ export function compileCheckoutPage(input: KitBizInput, ctx: KitBizContext): KitFragment {
27
+ const SUBMIT_LABEL = kitText('soma.kit.checkout_submit', undefined, ctx.locale);
28
+ const RESET_LABEL = kitText('soma.kit.reset', undefined, ctx.locale);
29
+ const SAVED_NOTICE = kitText('soma.kit.checkout_done', undefined, ctx.locale);
30
+ const out = newParts([]);
31
+ const fail = (code: string, message: string, path: string): void => { out.diagnostics.push({ code, message, path }); };
32
+
33
+ const rawForm = input.objects.form;
34
+ const rawItems = input.objects.items;
35
+ const rawAmounts = input.objects.amounts;
36
+ if (!isRec(rawForm) || !isRec(rawForm.schema) || !isRec(rawForm.behavior)) {
37
+ fail('KIT-BIZ-001', 'CheckoutPage 缺少必填对象角色槽 form(需含 schema 与 behavior)', 'product.objects.form');
38
+ }
39
+ if (!isRec(rawItems) || !isRec(rawItems.behavior)) {
40
+ fail('KIT-BIZ-001', 'CheckoutPage 缺少必填对象角色槽 items(需含 behavior)', 'product.objects.items');
41
+ }
42
+ checkAreas(input, 'CheckoutPage', CHECKOUT_PAGE_AREAS, out);
43
+ if (out.diagnostics.length > 0) return finishTemplate(out, '');
44
+
45
+ const areaClass = input.areaClass ?? {};
46
+ const ids = checkoutPageIds(ctx.pageId);
47
+
48
+ // ---- 表单
49
+ const target = normalizeFormObject(rawForm as unknown as Rec, 'product.objects.form', 'CheckoutPage 的 form', out.diagnostics);
50
+ if (out.diagnostics.length > 0) return finishTemplate(out, '');
51
+ const formObject = checkoutPageObjectName(ctx.pageId, 'form');
52
+ const hasFrom = target.behavior.from !== undefined;
53
+ const formView = (target.view?.form ?? {}) as KitViewForm;
54
+ const r = emitObject(
55
+ target as KitObject,
56
+ { object: formObject, scope: `${formObject}_scope`, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents },
57
+ {
58
+ registeredActions: ctx.registeredActions,
59
+ formMode: hasFrom ? 'edit' : 'create',
60
+ ...(hasFrom ? { formInitialPath: `page.data.${formObject}` } : {}),
61
+ },
62
+ );
63
+ addEmit(out, r);
64
+ const formId = viewAnchor(formObject, 'form');
65
+ const entry = out.show[formId];
66
+ if (!isRec(entry) || !isRec(entry.props)) {
67
+ fail('KIT-BIZ-003', 'form 视图没有发射成可编辑表单(需要 permission 为 w / create 的字段)', 'product.objects.form.view.form');
68
+ return finishTemplate(out, '');
69
+ }
70
+ const submitLabel = typeof formView.submitLabel === 'string' && formView.submitLabel !== '' ? formView.submitLabel : SUBMIT_LABEL;
71
+ const classes = isRec(entry.props.classes) ? entry.props.classes : {};
72
+ patchProps(out.show, formId, {
73
+ scope: `${formObject}__form`,
74
+ submitLabel,
75
+ resetLabel: RESET_LABEL,
76
+ classes: { ...classes, actions: CHECKOUT_PAGE_CLASS.footer },
77
+ });
78
+ out.events[`${formId}.saved`] = { steps: [{ do: `NOTIFY | success | ${SAVED_NOTICE}` }] };
79
+ const ft = formView.title;
80
+ const formTitle = typeof ft === 'string' ? ft : isRec(ft) ? String((hasFrom ? ft.edit : ft.create) ?? '') : '';
81
+
82
+ // ---- 摘要栏
83
+ const items = emitReadOnlyMember(out, rawItems, {
84
+ object: checkoutPageObjectName(ctx.pageId, 'items'), path: 'product.objects.items', allowed: ['list', 'summary'], ctx,
85
+ });
86
+ let amounts = undefined as ReturnType<typeof emitReadOnlyMember>;
87
+ if (rawAmounts !== undefined) {
88
+ amounts = emitReadOnlyMember(out, rawAmounts, {
89
+ object: checkoutPageObjectName(ctx.pageId, 'amounts'), path: 'product.objects.amounts', allowed: ['list', 'summary'], ctx,
90
+ });
91
+ }
92
+ if (out.diagnostics.length > 0 || items === undefined) return finishTemplate(out, '');
93
+
94
+ const titleOf = (raw: unknown): string => (isRec(raw) && typeof raw.title === 'string' ? raw.title : '');
95
+ const html = checkoutPageHtml(
96
+ ids,
97
+ {
98
+ formTitle,
99
+ form: r.parts.form ?? '',
100
+ itemsTitle: titleOf(rawItems),
101
+ items: items.html,
102
+ amountsTitle: titleOf(rawAmounts),
103
+ amounts: amounts?.html ?? '',
104
+ },
105
+ areaClass,
106
+ input.class,
107
+ );
108
+ for (const c of classesIn(html)) out.candidates.add(c);
109
+ addClassTokens(out, CHECKOUT_PAGE_CLASS);
110
+ return finishTemplate(out, html);
111
+ }
@@ -0,0 +1,20 @@
1
+ // CheckoutPage:结算页(左信息表单 + 右订单摘要:明细 + 金额汇总)。
2
+ // 对象角色槽:form(必填,必有 write,只有 form 视图);items(必填,只读 list / summary);amounts(可选,只读 list / summary,常用 AmountBreakdown)。
3
+
4
+ import { defineKitBizComponent } from '../define';
5
+ import { compileCheckoutPage } from './compile';
6
+ import { CHECKOUT_PAGE_AREAS } from './shell';
7
+
8
+ export const CheckoutPage = defineKitBizComponent({
9
+ kind: 'CheckoutPage',
10
+ roles: {
11
+ form: { required: true, views: ['form'] },
12
+ items: { required: true, views: ['list', 'summary'] },
13
+ amounts: { required: false, views: ['list', 'summary'] },
14
+ },
15
+ areas: [...CHECKOUT_PAGE_AREAS],
16
+ compile: compileCheckoutPage,
17
+ });
18
+
19
+ export { compileCheckoutPage, checkoutPageObjectName } from './compile';
20
+ export { CHECKOUT_PAGE_AREAS, CHECKOUT_PAGE_CLASS, checkoutPageIds } from './shell';