soma-kit 0.1.15 → 0.1.16

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 (470) hide show
  1. package/README.md +1 -1
  2. package/package.json +8 -5
  3. package/packs/ai/model-card.ts +3 -3
  4. package/packs/ops/error-budget-card.ts +3 -3
  5. package/packs/ops/release-readiness-card.ts +3 -3
  6. package/packs/security/control-evidence-card.ts +3 -3
  7. package/packs/security/finding-card.ts +3 -2
  8. package/packs/shared/card-util.ts +17 -0
  9. package/spec/generated/kit-app.schema.json +2148 -340
  10. package/spec/generated/kit-page.schema.json +1134 -139
  11. package/spec/kit-grammar.json +934 -92
  12. package/spec/kit-grammar.schema.json +167 -2
  13. package/src/app/app-config.ts +219 -186
  14. package/src/app/define-kit-actions.ts +126 -20
  15. package/src/app/define-kit-app.ts +49 -4
  16. package/src/app/index.ts +5 -0
  17. package/src/app/kit-view-context.ts +39 -1
  18. package/src/app/list-page-defaults.ts +14 -0
  19. package/src/app/server-pages.ts +239 -7
  20. package/src/app/server.ts +466 -25
  21. package/src/app/theme-endpoint.ts +67 -23
  22. package/src/app/theme-runtime.ts +414 -85
  23. package/src/app/theme-shards.ts +69 -0
  24. package/src/app/tier-compat.ts +107 -0
  25. package/src/base/action-busy.ts +215 -38
  26. package/src/base/affix.ts +137 -0
  27. package/src/base/alert.ts +104 -59
  28. package/src/base/anchored-layer.ts +7 -6
  29. package/src/base/avatar.ts +147 -61
  30. package/src/base/badge.ts +186 -0
  31. package/src/base/button-group.ts +227 -0
  32. package/src/base/button.ts +347 -50
  33. package/src/base/card.ts +233 -0
  34. package/src/base/cascader.ts +143 -32
  35. package/src/base/check-core.ts +193 -33
  36. package/src/base/checkbox.ts +67 -2
  37. package/src/base/choice.ts +132 -31
  38. package/src/base/collapse.ts +249 -0
  39. package/src/base/color-picker.ts +399 -27
  40. package/src/base/combobox.ts +6 -2
  41. package/src/base/command-palette.ts +148 -36
  42. package/src/base/context-menu.ts +23 -6
  43. package/src/base/countdown.ts +37 -15
  44. package/src/base/date-range.ts +114 -96
  45. package/src/base/date.ts +481 -74
  46. package/src/base/delta.ts +16 -9
  47. package/src/base/divider.ts +51 -33
  48. package/src/base/end-edge.ts +10 -4
  49. package/src/base/fab.ts +57 -21
  50. package/src/base/gap-value.ts +34 -15
  51. package/src/base/hint-tips.ts +99 -29
  52. package/src/base/identity-cells.ts +839 -0
  53. package/src/base/illustrations.ts +6 -4
  54. package/src/base/image.ts +40 -19
  55. package/src/base/index.ts +79 -22
  56. package/src/base/inline-error.ts +13 -7
  57. package/src/base/input.ts +135 -35
  58. package/src/base/kbd.ts +30 -17
  59. package/src/base/kit-contract.ts +400 -0
  60. package/src/base/link.ts +41 -20
  61. package/src/base/listbox-core.ts +282 -101
  62. package/src/base/loading-gate.ts +3 -0
  63. package/src/base/look.ts +197 -0
  64. package/src/base/mentions.ts +55 -22
  65. package/src/base/menu-button.ts +73 -22
  66. package/src/base/menu-core.ts +201 -24
  67. package/src/base/month-grid.ts +60 -3
  68. package/src/base/motion/aura.ts +52 -10
  69. package/src/base/motion/hover-3d.ts +7 -5
  70. package/src/base/motion/hover-gallery.ts +16 -12
  71. package/src/base/motion/limits.ts +10 -0
  72. package/src/base/motion/marquee.ts +18 -11
  73. package/src/base/motion/text-rotate.ts +34 -16
  74. package/src/base/notification.ts +292 -0
  75. package/src/base/number.ts +93 -12
  76. package/src/base/otp.ts +139 -27
  77. package/src/base/overlay-runtime.ts +30 -23
  78. package/src/base/overlay-shell.ts +59 -14
  79. package/src/base/period-picker.ts +868 -0
  80. package/src/base/popover.ts +624 -73
  81. package/src/base/popup.ts +187 -52
  82. package/src/base/portal-core.ts +99 -2
  83. package/src/base/price-text.ts +51 -17
  84. package/src/base/progress.ts +100 -18
  85. package/src/base/qr-code.ts +64 -17
  86. package/src/base/qty-stepper.ts +141 -22
  87. package/src/base/radio.ts +43 -2
  88. package/src/base/range.ts +194 -39
  89. package/src/base/rating.ts +117 -31
  90. package/src/base/reason-tip.ts +58 -16
  91. package/src/base/relation-cells.ts +541 -0
  92. package/src/base/resize-handle.ts +5 -3
  93. package/src/base/row-fresh.ts +84 -0
  94. package/src/base/section-spy.ts +79 -0
  95. package/src/base/segmented.ts +70 -26
  96. package/src/base/select.ts +8 -3
  97. package/src/base/shared.ts +482 -71
  98. package/src/base/spinner.ts +107 -0
  99. package/src/base/state-panel.ts +77 -22
  100. package/src/base/sticky-edge.ts +96 -29
  101. package/src/base/swap.ts +39 -21
  102. package/src/base/switch.ts +158 -38
  103. package/src/base/tabs.ts +292 -0
  104. package/src/base/tag-input.ts +123 -54
  105. package/src/base/tag.ts +184 -66
  106. package/src/base/text.ts +461 -71
  107. package/src/base/textarea.ts +88 -39
  108. package/src/base/time-picker.ts +335 -55
  109. package/src/base/time-range.ts +846 -0
  110. package/src/base/tree-select.ts +342 -88
  111. package/src/base/upload.ts +604 -158
  112. package/src/base/view-transition.ts +7 -3
  113. package/src/base/virtual-list.ts +49 -14
  114. package/src/biz/approval-desk/compile.ts +70 -5
  115. package/src/biz/approval-desk/index.ts +2 -0
  116. package/src/biz/approval-desk/shell.ts +52 -12
  117. package/src/biz/auth-panel/compile.ts +13 -3
  118. package/src/biz/auth-panel/shell.ts +27 -7
  119. package/src/biz/category-crud/compile.ts +51 -13
  120. package/src/biz/category-crud/index.ts +2 -0
  121. package/src/biz/category-crud/shell.ts +29 -9
  122. package/src/biz/checkout-page/compile.ts +37 -3
  123. package/src/biz/checkout-page/index.ts +1 -0
  124. package/src/biz/checkout-page/shell.ts +26 -9
  125. package/src/biz/compose.ts +6 -1
  126. package/src/biz/data-components.ts +2 -0
  127. package/src/biz/import-wizard/compile.ts +4 -1
  128. package/src/biz/import-wizard/index.ts +1 -0
  129. package/src/biz/import-wizard/shell.ts +32 -18
  130. package/src/biz/index.ts +1 -1
  131. package/src/biz/landing-page/compile.ts +3 -2
  132. package/src/biz/landing-page/shell.ts +22 -3
  133. package/src/biz/layout-contracts.ts +918 -0
  134. package/src/biz/link/hub.ts +199 -8
  135. package/src/biz/link/shared.ts +54 -15
  136. package/src/biz/master-sub/compile.ts +194 -57
  137. package/src/biz/master-sub/detail-head.ts +141 -18
  138. package/src/biz/master-sub/index.ts +3 -0
  139. package/src/biz/master-sub/shell.ts +186 -57
  140. package/src/biz/multi-board/compile.ts +87 -36
  141. package/src/biz/multi-board/composition.ts +7 -20
  142. package/src/biz/multi-board/index.ts +3 -2
  143. package/src/biz/multi-board/prose-fold.ts +15 -11
  144. package/src/biz/multi-board/shell.ts +148 -37
  145. package/src/biz/notification-center/compile.ts +20 -6
  146. package/src/biz/notification-center/index.ts +2 -0
  147. package/src/biz/notification-center/shell.ts +43 -10
  148. package/src/biz/page-templates/domain-templates.ts +145 -22
  149. package/src/biz/page-templates/result-page/compile.ts +4 -1
  150. package/src/biz/page-templates/result-page/index.ts +1 -0
  151. package/src/biz/page-templates/result-page/shell.ts +17 -4
  152. package/src/biz/page-templates/sign-in-page/compile.ts +19 -8
  153. package/src/biz/page-templates/sign-in-page/index.ts +1 -0
  154. package/src/biz/page-templates/sign-in-page/shell.ts +28 -12
  155. package/src/biz/record-detail/compile.ts +39 -11
  156. package/src/biz/record-detail/index.ts +1 -0
  157. package/src/biz/record-detail/shell.ts +41 -10
  158. package/src/biz/settings-center/compile.ts +4 -1
  159. package/src/biz/settings-center/index.ts +1 -0
  160. package/src/biz/settings-center/shell.ts +30 -9
  161. package/src/biz/shared/action-host.ts +137 -46
  162. package/src/biz/shared/compile-helpers.ts +130 -28
  163. package/src/biz/shared/coordinator.ts +628 -147
  164. package/src/biz/shared/focus-return.ts +180 -0
  165. package/src/biz/shared/object-aliases.ts +7 -1
  166. package/src/biz/shared/overlay-compile.ts +58 -10
  167. package/src/biz/shared/overlay-shell.ts +40 -10
  168. package/src/biz/shared/page-form-actions.ts +151 -0
  169. package/src/biz/shared/page-form.ts +255 -0
  170. package/src/biz/shared/pipeline.ts +74 -0
  171. package/src/biz/shared/runtime-hub.ts +101 -8
  172. package/src/biz/shared/verbs.ts +129 -0
  173. package/src/biz/single-form/compile.ts +4 -2
  174. package/src/biz/single-form/index.ts +2 -0
  175. package/src/biz/single-form/shell.ts +21 -11
  176. package/src/biz/standard-crud/compile.ts +206 -38
  177. package/src/biz/standard-crud/index.ts +2 -1
  178. package/src/biz/standard-crud/shell.ts +82 -22
  179. package/src/biz/standard-crud/summary.ts +2 -37
  180. package/src/biz/step-form/compile.ts +12 -3
  181. package/src/biz/step-form/hub.ts +165 -50
  182. package/src/biz/step-form/index.ts +1 -0
  183. package/src/biz/step-form/shell.ts +31 -15
  184. package/src/biz/types.ts +40 -4
  185. package/src/cli/kit-cli.ts +145 -26
  186. package/src/cli/kit-init.ts +3 -3
  187. package/src/cli/migrate/theme-map.ts +35 -28
  188. package/src/cli/migrate/ts-rules.ts +2 -2
  189. package/src/cli/migrate/types.ts +3 -3
  190. package/src/cli/migrate/yaml-rules.ts +11 -9
  191. package/src/cli/view-writes.ts +13 -0
  192. package/src/compile/closed-set.ts +102 -6
  193. package/src/compile/compile-page.ts +446 -53
  194. package/src/compile/component-candidates.ts +56 -4
  195. package/src/compile/danger-tier.ts +65 -0
  196. package/src/compile/hints.ts +1 -1
  197. package/src/compile/info-structure.ts +155 -0
  198. package/src/compile/layout-lint/rules-composition.ts +2 -1
  199. package/src/compile/layout-lint/rules-table.ts +4 -19
  200. package/src/compile/look-page.ts +551 -0
  201. package/src/compile/look.ts +376 -0
  202. package/src/compile/page-composition.ts +382 -46
  203. package/src/compile/page-hierarchy.ts +131 -0
  204. package/src/compile/page-pipeline-look.ts +156 -0
  205. package/src/compile/page-pipeline.ts +200 -0
  206. package/src/compile/parse.ts +12 -11
  207. package/src/compile/relation-render.ts +120 -0
  208. package/src/compile/remove-guard.ts +115 -41
  209. package/src/compile/stages.ts +645 -28
  210. package/src/compile/styles.ts +226 -26
  211. package/src/compile/types.ts +62 -5
  212. package/src/compile/view-check.ts +190 -1
  213. package/src/data/access-gate.ts +17 -9
  214. package/src/data/amount-breakdown.ts +49 -22
  215. package/src/data/anchor-nav.ts +73 -15
  216. package/src/data/approval-flow.ts +210 -124
  217. package/src/data/assignment-picker.ts +163 -85
  218. package/src/data/async-result-panel.ts +110 -46
  219. package/src/data/audit-log.ts +461 -0
  220. package/src/data/breadcrumbs.ts +141 -19
  221. package/src/data/calendar.ts +434 -96
  222. package/src/data/card-grid.ts +319 -0
  223. package/src/data/carousel.ts +72 -38
  224. package/src/data/cell-value.ts +253 -0
  225. package/src/data/chart.ts +904 -77
  226. package/src/data/checklist.ts +78 -35
  227. package/src/data/code-view.ts +106 -48
  228. package/src/data/comment-thread.ts +607 -87
  229. package/src/data/compare-view.ts +227 -0
  230. package/src/data/confirm-dialog.ts +198 -30
  231. package/src/data/context-menu.ts +95 -21
  232. package/src/data/d9-limits.ts +2 -0
  233. package/src/data/d9-util.ts +13 -5
  234. package/src/data/diff.ts +107 -50
  235. package/src/data/display-util.ts +9 -4
  236. package/src/data/dock.ts +33 -17
  237. package/src/data/embed.ts +142 -7
  238. package/src/data/engine-ports.ts +13 -4
  239. package/src/data/field-mapper.ts +104 -48
  240. package/src/data/file-list.ts +522 -0
  241. package/src/data/flow-editor.ts +603 -142
  242. package/src/data/flow-node-options.ts +24 -5
  243. package/src/data/flow-remote-options.ts +94 -19
  244. package/src/data/footer.ts +85 -27
  245. package/src/data/form-draft-registry.ts +183 -12
  246. package/src/data/gantt.ts +637 -117
  247. package/src/data/graph-view.ts +51 -0
  248. package/src/data/heat-calendar.ts +412 -0
  249. package/src/data/hero.ts +38 -15
  250. package/src/data/image-viewer.ts +261 -62
  251. package/src/data/index.ts +63 -1
  252. package/src/data/item-list.ts +217 -57
  253. package/src/data/json-view.ts +165 -100
  254. package/src/data/kanban.ts +339 -87
  255. package/src/data/kit-contract.ts +230 -0
  256. package/src/data/leaderboard.ts +343 -0
  257. package/src/data/level-class.ts +21 -0
  258. package/src/data/log-stream.ts +347 -0
  259. package/src/data/markdown-view.ts +155 -45
  260. package/src/data/matrix.ts +217 -112
  261. package/src/data/media-grid.ts +162 -38
  262. package/src/data/mega-menu.ts +39 -23
  263. package/src/data/menu-bar.ts +254 -0
  264. package/src/data/menu-dom.ts +50 -15
  265. package/src/data/menu.ts +131 -47
  266. package/src/data/mockup.ts +30 -22
  267. package/src/data/modal-dialog.ts +90 -13
  268. package/src/data/navbar.ts +143 -61
  269. package/src/data/notice-list.ts +100 -48
  270. package/src/data/notify-renderer.ts +61 -7
  271. package/src/data/object-form.ts +1389 -130
  272. package/src/data/org-chart.ts +544 -0
  273. package/src/data/outcome-watch.ts +90 -21
  274. package/src/data/pager.ts +122 -42
  275. package/src/data/panel-head.ts +237 -75
  276. package/src/data/permission-matrix.ts +371 -119
  277. package/src/data/permission-tree.ts +135 -80
  278. package/src/data/pricing-table.ts +106 -42
  279. package/src/data/prompt-dialog.ts +49 -21
  280. package/src/data/reaction-bar.ts +63 -31
  281. package/src/data/record-card.ts +239 -70
  282. package/src/data/record-picker.ts +56 -27
  283. package/src/data/redirect.ts +39 -15
  284. package/src/data/request-console.ts +131 -41
  285. package/src/data/resident.ts +11 -1
  286. package/src/data/result-panel.ts +65 -27
  287. package/src/data/rich-text.ts +206 -35
  288. package/src/data/row-confirm.ts +47 -0
  289. package/src/data/row-editor.ts +376 -102
  290. package/src/data/rule-builder.ts +129 -80
  291. package/src/data/schedule-grid.ts +238 -0
  292. package/src/data/segment-bar.ts +221 -0
  293. package/src/data/shape-util.ts +86 -43
  294. package/src/data/stage-flow.ts +244 -0
  295. package/src/data/staged-rows.ts +207 -24
  296. package/src/data/stat-group.ts +438 -86
  297. package/src/data/static-lazy.ts +18 -0
  298. package/src/data/static-registry.ts +38 -2
  299. package/src/data/status-strip.ts +171 -0
  300. package/src/data/steps.ts +63 -34
  301. package/src/data/summary-strip.ts +136 -0
  302. package/src/data/summary-util.ts +116 -0
  303. package/src/data/survey.ts +128 -47
  304. package/src/data/system-switcher.ts +40 -20
  305. package/src/data/target-progress.ts +208 -0
  306. package/src/data/text-action-button.ts +28 -7
  307. package/src/data/text-diff.ts +99 -31
  308. package/src/data/tile-grid.ts +343 -0
  309. package/src/data/timeline.ts +205 -36
  310. package/src/data/tour-guide.ts +110 -47
  311. package/src/data/transfer.ts +195 -47
  312. package/src/data/tree-table.ts +194 -112
  313. package/src/data/tree.ts +191 -70
  314. package/src/data/trend-line.ts +68 -12
  315. package/src/data/virtual-rows.ts +242 -102
  316. package/src/data/waterfall.ts +171 -0
  317. package/src/data/watermark.ts +35 -6
  318. package/src/data/wrap.ts +26 -4
  319. package/src/frames/blank-frame.ts +6 -4
  320. package/src/frames/index.ts +1 -2
  321. package/src/frames/inherited-shell.ts +54 -13
  322. package/src/frames/page-bar.ts +205 -27
  323. package/src/frames/page-status.ts +3 -2
  324. package/src/frames/resident-components.ts +0 -2
  325. package/src/frames/shared.ts +64 -21
  326. package/src/frames/single-frame.ts +20 -4
  327. package/src/frames/split-frame/shell.ts +11 -7
  328. package/src/frames/split-frame/wiring.ts +14 -10
  329. package/src/frames/tabs-frame/shell.ts +3 -2
  330. package/src/frames/tabs-frame/wiring.ts +2 -1
  331. package/src/frames/top-main-frame.ts +55 -3
  332. package/src/frames/types.ts +2 -0
  333. package/src/frames/workspace-frame/extras.ts +5 -3
  334. package/src/frames/workspace-frame/index.ts +1 -1
  335. package/src/frames/workspace-frame/pipeline-key.ts +6 -0
  336. package/src/frames/workspace-frame/shell.ts +22 -2
  337. package/src/frames/workspace-frame/state.ts +42 -14
  338. package/src/frames/workspace-frame/view.ts +697 -167
  339. package/src/generated/kit-grammar-runtime.ts +1015 -53
  340. package/src/generated/kit-page.ts +272 -0
  341. package/src/i18n/index.ts +2 -0
  342. package/src/i18n/kit-text.ts +96 -3
  343. package/src/object-renderer/action-group.ts +175 -23
  344. package/src/object-renderer/action-more.ts +48 -17
  345. package/src/object-renderer/arrange.ts +241 -29
  346. package/src/object-renderer/category-tone.ts +96 -0
  347. package/src/object-renderer/collapse-wiring.ts +19 -9
  348. package/src/object-renderer/collection-expand.ts +3 -3
  349. package/src/object-renderer/collection-parts.ts +432 -107
  350. package/src/object-renderer/collection-table.ts +347 -45
  351. package/src/object-renderer/collection.ts +291 -62
  352. package/src/object-renderer/compile-data.ts +12 -2
  353. package/src/object-renderer/defaults.ts +6 -5
  354. package/src/object-renderer/emit-events.ts +45 -19
  355. package/src/object-renderer/emit-object.ts +35 -9
  356. package/src/object-renderer/emit-static.ts +734 -159
  357. package/src/object-renderer/filter-plan.ts +3 -3
  358. package/src/object-renderer/filter-toolbar.ts +105 -18
  359. package/src/object-renderer/form-detail.ts +87 -2
  360. package/src/object-renderer/key-field.ts +21 -0
  361. package/src/object-renderer/layout-facts.ts +18 -2
  362. package/src/object-renderer/layout-plan.ts +6 -3
  363. package/src/object-renderer/overlay-decide.ts +44 -2
  364. package/src/object-renderer/pick-component.ts +8 -2
  365. package/src/object-renderer/pipeline-mode.ts +6 -0
  366. package/src/object-renderer/relation-field.ts +79 -0
  367. package/src/object-renderer/render-object.ts +71 -26
  368. package/src/object-renderer/request-actions.ts +119 -21
  369. package/src/object-renderer/table-actions.ts +424 -103
  370. package/src/object-renderer/table-gap.ts +2 -1
  371. package/src/object-renderer/table-reorder.ts +237 -0
  372. package/src/object-renderer/table-summary.ts +26 -12
  373. package/src/object-renderer/table-tools.ts +428 -128
  374. package/src/object-renderer/types.ts +91 -2
  375. package/src/object-renderer/value-present.ts +49 -0
  376. package/src/page-target/ai-surface.ts +15 -22
  377. package/src/page-target/compile.ts +5 -6
  378. package/src/page-target/drift.ts +0 -7
  379. package/src/page-target/intent-schema.ts +46 -43
  380. package/src/page-target/target.ts +4 -5
  381. package/src/page-target/writer-policy.ts +4 -5
  382. package/src/recipes/chrome-surface.ts +20 -0
  383. package/src/recipes/code-view.ts +15 -14
  384. package/src/recipes/color-role.ts +442 -0
  385. package/src/recipes/compact-group.ts +3 -2
  386. package/src/recipes/composition-projector.ts +321 -0
  387. package/src/recipes/container.ts +76 -19
  388. package/src/recipes/control.ts +64 -5
  389. package/src/recipes/desc-list.ts +101 -7
  390. package/src/recipes/divider.ts +30 -9
  391. package/src/recipes/emphasis.ts +90 -5
  392. package/src/recipes/field-text.ts +72 -0
  393. package/src/recipes/form-section.ts +177 -0
  394. package/src/recipes/frame-bleed.ts +3 -2
  395. package/src/recipes/index.ts +28 -4
  396. package/src/recipes/inherited-shell.ts +21 -15
  397. package/src/recipes/json-view.ts +6 -5
  398. package/src/recipes/look.ts +56 -0
  399. package/src/recipes/mark.ts +138 -0
  400. package/src/recipes/markdown.ts +16 -6
  401. package/src/recipes/overlay.ts +47 -19
  402. package/src/recipes/page-width.ts +31 -0
  403. package/src/recipes/pipeline-runtime.ts +366 -0
  404. package/src/recipes/placeholder.ts +37 -19
  405. package/src/recipes/rail-grid.ts +6 -3
  406. package/src/recipes/self-owned.ts +59 -0
  407. package/src/recipes/slot-align.ts +5 -3
  408. package/src/recipes/stat-state.ts +5 -5
  409. package/src/recipes/state.ts +54 -3
  410. package/src/recipes/status.ts +14 -14
  411. package/src/recipes/strip.ts +47 -5
  412. package/src/recipes/surface-edge.ts +3 -1
  413. package/src/recipes/surface.ts +33 -4
  414. package/src/recipes/table-gap.ts +3 -2
  415. package/src/recipes/table-native-edit.ts +22 -9
  416. package/src/recipes/table-row.ts +45 -12
  417. package/src/recipes/tabs.ts +54 -22
  418. package/src/recipes/text-diff.ts +15 -8
  419. package/src/recipes/text-fit.ts +132 -0
  420. package/src/recipes/title-row.ts +68 -3
  421. package/src/shared/action-func.ts +106 -0
  422. package/src/shared/color-scheme.ts +127 -0
  423. package/src/shared/confirm-decl.ts +5 -2
  424. package/src/shared/danger-facts.ts +55 -0
  425. package/src/shared/dom-attrs-registry.ts +1009 -0
  426. package/src/shared/dom-attrs.ts +743 -0
  427. package/src/shared/field-kind.ts +49 -0
  428. package/src/shared/field-value-format.ts +58 -12
  429. package/src/shared/glyphs.ts +127 -0
  430. package/src/shared/icons.ts +28 -1
  431. package/src/shared/identifier-field.ts +66 -0
  432. package/src/shared/list-pager.ts +23 -0
  433. package/src/shared/list-title.ts +29 -0
  434. package/src/shared/order-value.ts +15 -0
  435. package/src/shared/page-attrs-runtime.ts +327 -0
  436. package/src/shared/page-attrs.ts +262 -0
  437. package/src/shared/pipeline-mode.ts +64 -0
  438. package/src/shared/row-key.ts +15 -0
  439. package/src/shared/theme-runtime-shared.ts +165 -24
  440. package/src/shared/theme-usage.ts +16 -0
  441. package/src/shared/value-table-contract.ts +68 -0
  442. package/src/spatial/action-func.ts +4 -0
  443. package/src/spatial/declared-actions.ts +116 -0
  444. package/src/spatial/emit.ts +660 -0
  445. package/src/spatial/expand.ts +1482 -0
  446. package/src/spatial/field-types.ts +48 -0
  447. package/src/spatial/index.ts +82 -0
  448. package/src/spatial/layout.ts +697 -0
  449. package/src/spatial/look-apply.ts +206 -0
  450. package/src/spatial/page-decl.ts +44 -0
  451. package/src/spatial/page-object.ts +349 -0
  452. package/src/spatial/recognize.ts +491 -0
  453. package/src/spatial/self-report.ts +571 -0
  454. package/src/spatial/shape.ts +205 -0
  455. package/src/spatial/spatial-map.ts +136 -0
  456. package/src/spatial/tone.ts +145 -0
  457. package/src/theme/index.ts +11 -2
  458. package/src/theme/kit-theme-text.ts +1 -1
  459. package/src/theme/kit-theme.css +527 -16
  460. package/src/theme/kit-theme.tpl +491 -16
  461. package/src/theme/look-carrier.ts +65 -0
  462. package/src/theme/nine-dim-structure.ts +522 -185
  463. package/src/theme/private-vars.ts +153 -0
  464. package/src/theme/surface-layers.ts +3 -2
  465. package/src/theme/theme-tokens.ts +1601 -93
  466. package/src/theme/theme-types.ts +38 -59
  467. package/src/theme/value-table.ts +2379 -0
  468. package/src/frames/list-summary.ts +0 -123
  469. package/src/recipes/nowrap.ts +0 -16
  470. package/src/theme/block-theme.ts +0 -202
@@ -0,0 +1,839 @@
1
+ // 一个值 / 一组值的展示单元(取值与解剖见 knowledge/Kit主题规则与算法.md §10.23):
2
+ // PersonCell 人员单元:头像 + 姓名 + 副文(shadcn avatar 的「头像 + 两行文字」组合;Mantine UsersTable 的人员格);
3
+ // 给 items 则成人员组(头像叠放 + 超出 +N,叠放与角标沿用 AvatarGroup 的类)。
4
+ // TagGroup 标签组:单行并排,超过 max 收成「+N」(Ant Table 多值 Tag 列、Baserow 多选单元格);被收起的标签进 +N 的悬停提示。
5
+ // Identifier 标识符:等宽、中间省略(头部可截断、尾段恒显示,纯 CSS,无运行期测量)、可复制(Ant Typography 的 copyable + ellipsis)。
6
+ // 外观只经标记出口 / 标签类 / 头像类,不自造色与字阶;全部文字走 textContent。
7
+
8
+ import type { SomaComponentDefinition } from 'soma-core';
9
+ import { kitText } from '../i18n/kit-text';
10
+ import { KIT_MARK_CLASS_CANDIDATES } from '../recipes/mark';
11
+ import { kitClosedValueRecipe, kitIdentRecipe } from '../recipes/field-text';
12
+ import { KIT_LOOK_TONE_ATTR, kitLookRecipe } from '../recipes/look';
13
+ import { kitMatchSemanticStatusTone } from '../recipes/color-role';
14
+ import { kitCategoryToneFor, kitToneMapHasAuto } from '../recipes/mark';
15
+ import { KIT_SKELETON_AVATAR, KIT_SKELETON_BAR_LABEL, KIT_SKELETON_BAR_MID, KIT_SKELETON_BAR_TAG } from '../recipes/placeholder';
16
+ import { kitFocusRingRecipe } from '../recipes/state';
17
+ import { mergeClass } from '../shared/merge-class';
18
+ import { GROUP_CLASS, GROUP_ITEM_CLASS, MORE_CLASS, ROOT_CLASS, moreClassOf, paintAvatar, shapeOf, specOf } from './avatar';
19
+ import { KIT_ATTR_ACTION, KIT_ATTR_COPY_LIVE, KIT_ATTR_TIP, KIT_ATTR_TIPS } from '../shared/dom-attrs';
20
+ // 仅为副作用保留:hint-tips 模块加载时注册提示委托(原先随常量导入一并加载,加载顺序不变)
21
+ import './hint-tips';
22
+ import { safeHref } from './link';
23
+ import { COPY_BTN_CLASS, setKitCopyButton } from './text';
24
+ import {
25
+ CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP, bool, classCandidates, createKitController, displayOf, joinClass, num, optionsOf, setAttr, sizeOf, str,
26
+ type KitOption, type KitProps, type KitSize, type KitTone, type KitView,
27
+ kitCategoryOn, kitMarkDataState, kitOuterRoot, kitReadProps, kitToneOfPipeline,
28
+ } from './shared';
29
+ import { kitCategoryAutoSequence, kitCategoryTonesByOrder } from './look';
30
+ import type { KitOverflow } from '../shared/page-attrs';
31
+
32
+ /**
33
+ * TagGroup 的成员:items 给了(非空)取 items,否则取字段值 value(数据单元绑定,relation: tags 时编译器只接 value)。
34
+ * 契约缺省 items = [] 不算「给了」:core 挂载时先铺全部契约缺省(component-manager.ts#resolveProps),按「是数组」判会让空的缺省盖掉绑定的 value,
35
+ * 数据单元里的标签组一枚都不画(SCON-173 补做时查出,按选项映射的前提)。
36
+ */
37
+ function tagMembersOf(p: KitProps): readonly unknown[] {
38
+ if (Array.isArray(p.items) && p.items.length > 0) return p.items;
39
+ return Array.isArray(p.value) ? p.value : [];
40
+ }
41
+
42
+ /**
43
+ * TagGroup 的页面线判定并进自己的入参:组语气没写时取 kit.tone;启用分类色时按标签出现顺序取主题自动序列的色号
44
+ * (超长整组退中性,见 look.ts#kitCategoryTonesByOrder)——编译期色表里显式的 cN / neutral 原样保留、不占序号,其余标签接续取色
45
+ * (E→D,与 Tag / Text 同一取法:next 下自动位被剥掉、只剩显式条目时其余标签不退中性)。没有 kit 对象时原样返回 p。
46
+ */
47
+ function withTagGroupKit(p: KitProps, host?: Element | null): KitProps {
48
+ const kit = kitReadProps(p);
49
+ if (Object.keys(kit).length === 0) return p;
50
+ const q: Record<string, unknown> = { ...p };
51
+ const kitTone = kitToneOfPipeline(kit.tone);
52
+ if ((typeof p.tone !== 'string' || p.tone.trim() === '') && kitTone !== null) q.tone = kitTone;
53
+ if (kitCategoryOn(kit)) {
54
+ // 序号按选项声明顺序取(业务功能描述 §3.6):入参带选项声明(options)时按声明顺序;没有声明时按标签首次出现的顺序(kitCategoryTonesByOrder 内去重)。
55
+ // 色表的键 = 成员的色表键 tagToneKeyOf(选项值 / 标量成员本身;对象成员有 value 取 value,否则取标签文字):
56
+ // 与编译期色表(category-tone.ts,按选项值作键)及 Tag / Text 同一取法,显式条目与按序补的条目落在同一个键上
57
+ const labelKey = str(p.label_key, 'label');
58
+ const declared = Array.isArray(p.options) && p.options.length > 0 ? p.options : null;
59
+ const raw: readonly unknown[] = declared ?? tagMembersOf(p);
60
+ // 显式色表若按标签文字写了这一项(旧写法),按序补色时用文字作键,不再给它的值另占一个自动位
61
+ const explicit = isRec(p.tag_tones) ? p.tag_tones : {};
62
+ const keyOf = (it: unknown): string => {
63
+ const key = tagToneKeyOf(it, labelKey);
64
+ const label = isRec(it) ? str(it[labelKey], str(it.label, str(it.name, key))) : key;
65
+ return label !== key && Object.hasOwn(explicit, label) && !Object.hasOwn(explicit, key) ? label : key;
66
+ };
67
+ q.tag_tones = kitCategoryTonesByOrder(raw.map((it) => ({ value: keyOf(it) })), host, p.tag_tones);
68
+ }
69
+ return q;
70
+ }
71
+
72
+ /** 溢出策略 → Identifier 的 truncate(折行 = 不省略,截断 / 两行截断 = 末尾省略,中间截断 = 中间省略) */
73
+ const IDENT_TRUNCATE_OF: Readonly<Record<KitOverflow, 'middle' | 'end' | 'none'>> = Object.freeze({ wrap: 'none', truncate: 'end', clamp2: 'end', middle: 'middle' });
74
+
75
+ const TONES: readonly KitTone[] = ['neutral', 'info', 'success', 'warning', 'danger'];
76
+ const isRec = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);
77
+ const CELL_TEXT_SIZE: Record<KitSize, string> = {
78
+ sm: 'text-xs',
79
+ md: 'text-sm',
80
+ lg: 'text-base',
81
+ };
82
+ const EMPTY_SIZE_CLASS: Record<KitSize, string> = {
83
+ sm: `${CELL_TEXT_SIZE.sm} text-fg-subtle`,
84
+ md: `${CELL_TEXT_SIZE.md} text-fg-subtle`,
85
+ lg: `${CELL_TEXT_SIZE.lg} text-fg-subtle`,
86
+ };
87
+
88
+ // ── PersonCell ────────────────────────────────────────────────
89
+
90
+ const PERSON_ROOT_CLASS = 'inline-flex max-w-full min-w-0 items-center gap-2';
91
+ // 可点态(组件卡 PersonCell §6):整个单元是按钮,悬停状态层 + 聚焦环(集合项宿主),姓名悬停下划线
92
+ const PERSON_ROOT_CLICKABLE_CLASS = mergeClass(`group/person ${PERSON_ROOT_CLASS} cursor-pointer rounded-item transition-colors hover:bg-state-layer-hover active:bg-state-layer-press`, kitFocusRingRecipe('item'));
93
+ const PERSON_NAME_HOVER_CLASS = 'group-hover/person:underline';
94
+ // 停用 / 离职:头像灰阶、姓名弱化 + 小标签
95
+ const PERSON_NAME_INACTIVE_BASE = 'truncate font-medium text-fg-subtle';
96
+ const PERSON_INACTIVE_TAG_CLASS = mergeClass(kitClosedValueRecipe('neutral'), 'shrink-0');
97
+ const PERSON_INACTIVE_FACE_CLASS = 'grayscale';
98
+ // 加载骨架:圆 + 两条灰条(同真实单元尺寸)
99
+ const PERSON_SKELETON_ROOT_CLASS = 'inline-flex items-center gap-2';
100
+ const PERSON_SKELETON_TEXT_CLASS = 'flex flex-col gap-1';
101
+ // +N 可聚焦(悬停给其余姓名,键盘聚焦同)
102
+ const MORE_FOCUS_CLASS = mergeClass('cursor-default', kitFocusRingRecipe('item'));
103
+ const PERSON_TEXT_CLASS = 'flex min-w-0 flex-col';
104
+ const PERSON_NAME_BASE = 'truncate font-medium text-fg';
105
+ const PERSON_NAME_CLASS: Record<KitSize, string> = {
106
+ sm: `${PERSON_NAME_BASE} ${CELL_TEXT_SIZE.sm}`,
107
+ md: `${PERSON_NAME_BASE} ${CELL_TEXT_SIZE.md}`,
108
+ lg: `${PERSON_NAME_BASE} ${CELL_TEXT_SIZE.lg}`,
109
+ };
110
+ const PERSON_SUB_CLASS = `truncate ${CELL_TEXT_SIZE.sm} text-fg-muted`;
111
+ /** 人员记录的约定键:name 姓名、sub 副文、avatar 头像地址(缺省再认 src);字段声明 relation 时由 display 覆盖键名(object-renderer/relation-field.ts) */
112
+ const PERSON_KEY_DEFAULT = Object.freeze({ name: 'name', sub: 'sub', avatar: 'avatar' });
113
+ /** 组的可访问名最多列出的姓名数(其余只给总数) */
114
+ const NAMES_IN_LABEL = 3;
115
+
116
+ /** 一条人员值 → 头像与文字的取值({ name, sub, src, status }):字符串 = 只有姓名;对象按约定键取;其它(空、数组、数字)没有人。
117
+ * 字段写了静态 options(SCON-173,relation: person / people)时:标量值(字符串 / 数字)命中某项 → 姓名取该项文字;
118
+ * 对象值没有姓名键、只有 id / value 时同样按选项取姓名。没有 options 或没命中照旧(与没有 options 时逐字相同)。 */
119
+ function personOf(raw: unknown, keys: { name: string; sub: string; avatar: string }, opts: readonly KitOption[] = []): Record<string, unknown> | null {
120
+ const hit = optionHitLabel(raw, opts);
121
+ if (hit !== null) return { name: hit };
122
+ if (typeof raw === 'string') return raw === '' ? null : { name: raw };
123
+ if (!isRec(raw)) return null;
124
+ const named = str(raw[keys.name]);
125
+ const name = named !== '' ? named : optionHitLabel(raw.id ?? raw.value, opts) ?? '';
126
+ if (name === '') return null;
127
+ const src = str(raw[keys.avatar]) !== '' ? raw[keys.avatar] : raw.src;
128
+ return { name, sub: raw[keys.sub], src, status: raw.status };
129
+ }
130
+
131
+ /** 值命中静态选项时返回该项文字(optionShownOf 的命中分支),否则 null(含没有选项、值为空 / 数组 / 对象、没命中) */
132
+ function optionHitLabel(raw: unknown, opts: readonly KitOption[]): string | null {
133
+ const shown = optionShownOf(raw, opts);
134
+ return shown !== null && shown.option !== null && shown.label !== '' ? shown.label : null;
135
+ }
136
+
137
+ /**
138
+ * PersonCell 的成员:items 给了(非空)取 items,否则字段值 value 是数组时取它(relation: people)。
139
+ * 契约缺省 items = [] 不算「给了」——与 TagGroup 的 tagMembersOf 同一修法(SCON-173):core 挂载先铺契约缺省,
140
+ * 按「是数组」判会让空的 items 盖掉绑定的 value 数组,人员组画成「—」。
141
+ */
142
+ function personMembersOf(p: KitProps): readonly unknown[] {
143
+ if (Array.isArray(p.items) && p.items.length > 0) return p.items;
144
+ return Array.isArray(p.value) ? p.value : [];
145
+ }
146
+
147
+ function resolvePersonModel(p: KitProps): { items: Record<string, unknown>[]; who: Record<string, unknown>; whoName: string; empty: boolean } {
148
+ const keys = { name: str(p.name_key, PERSON_KEY_DEFAULT.name), sub: str(p.sub_key, PERSON_KEY_DEFAULT.sub), avatar: str(p.avatar_key, PERSON_KEY_DEFAULT.avatar) };
149
+ const opts = optionsOf(p.options);
150
+ const items = personMembersOf(p).map((it) => personOf(it, keys, opts)).filter((it): it is Record<string, unknown> => it !== null);
151
+ const one = !Array.isArray(p.value) && isRec(p.value) ? personOf(p.value, keys, opts) : null;
152
+ const who: Record<string, unknown> = { ...p, ...Object.fromEntries(Object.entries(one ?? {}).filter(([, v]) => v !== undefined && v !== null && v !== '')) };
153
+ // 标量值命中静态选项(relation: person 存的是人员编号):姓名取选项文字,并写回 who.name 让头像首字同取
154
+ const optName = Array.isArray(p.value) ? null : optionHitLabel(p.value, opts);
155
+ if (str(who.name) === '' && optName !== null) who.name = optName;
156
+ const whoName = str(who.name) !== '' ? str(who.name) : typeof p.value === 'string' ? p.value : '';
157
+ const empty = items.length === 0 && (Array.isArray(p.value) || whoName === '');
158
+ return { items, who, whoName, empty };
159
+ }
160
+
161
+ function personView(): KitView {
162
+ const failed = new Set<string>();
163
+ return {
164
+ attach(root, api) {
165
+ // 可点:仅非空、非停用、非加载中的单人单元才抛 click
166
+ const fire = (): void => {
167
+ const q = api.props();
168
+ if (!bool(q.clickable) || bool(q.loading) || bool(q.inactive)) return;
169
+ const { items, empty } = resolvePersonModel(q);
170
+ if (empty || items.length > 0) return;
171
+ api.emit('click', {});
172
+ };
173
+ const onKey = (ev: KeyboardEvent): void => {
174
+ if (ev.target !== root) return;
175
+ if (ev.key === 'Enter' || ev.key === ' ') { ev.preventDefault(); fire(); }
176
+ };
177
+ root.addEventListener('click', fire);
178
+ root.addEventListener('keydown', onKey);
179
+ return () => { root.removeEventListener('click', fire); root.removeEventListener('keydown', onKey); };
180
+ },
181
+ render(root, p, api) {
182
+ const size = sizeOf(p.size);
183
+ const shape = shapeOf(p.shape);
184
+ const { items, who, whoName, empty } = resolvePersonModel(p);
185
+ // 数据状态自报:加载骨架 = 加载中;没有人员 = 内容全空
186
+ kitMarkDataState(kitOuterRoot(api.host, root), bool(p.loading) ? 'loading' : empty ? 'empty' : 'normal');
187
+ const redraw = (): void => {
188
+ root.textContent = '';
189
+ root.removeAttribute('tabindex');
190
+ root.removeAttribute('aria-busy');
191
+ root.removeAttribute('aria-disabled');
192
+ if (bool(p.loading)) {
193
+ // 加载骨架:圆 + 两条灰条;读屏只知道在忙
194
+ const dot = document.createElement('span');
195
+ dot.className = KIT_SKELETON_AVATAR; dot.setAttribute('aria-hidden', 'true');
196
+ const lines = document.createElement('span');
197
+ lines.className = PERSON_SKELETON_TEXT_CLASS; lines.setAttribute('aria-hidden', 'true');
198
+ const l1 = document.createElement('span'); l1.className = KIT_SKELETON_BAR_MID;
199
+ const l2 = document.createElement('span'); l2.className = KIT_SKELETON_BAR_LABEL;
200
+ lines.append(l1, l2);
201
+ root.append(dot, lines);
202
+ root.removeAttribute('role');
203
+ root.removeAttribute('aria-label');
204
+ root.setAttribute('aria-busy', 'true');
205
+ root.className = joinClass(PERSON_SKELETON_ROOT_CLASS, p.class);
206
+ setAttr(root, 'id', str(p.id));
207
+ return;
208
+ }
209
+ if (empty) {
210
+ const none = document.createElement('span');
211
+ none.className = EMPTY_SIZE_CLASS[size];
212
+ none.textContent = str(p.placeholder, '—');
213
+ root.appendChild(none);
214
+ root.removeAttribute('role');
215
+ root.removeAttribute('aria-label');
216
+ root.className = joinClass(PERSON_ROOT_CLASS, p.class);
217
+ setAttr(root, 'id', str(p.id));
218
+ return;
219
+ }
220
+ if (items.length > 0) {
221
+ const maxRaw = num(p.max);
222
+ const max = maxRaw !== null && maxRaw >= 1 ? Math.floor(maxRaw) : 4;
223
+ const shown = items.slice(0, max);
224
+ const rest = items.length - shown.length;
225
+ const allNames = items.map((it) => str(it.name)).filter((n) => n !== '');
226
+ // 组的可访问名:只列前 3 个姓名 + 总人数,不让读屏逐个念
227
+ const names = allNames.length > NAMES_IN_LABEL ? `${allNames.slice(0, NAMES_IN_LABEL).join('、')}… (${allNames.length})` : allNames.join('、');
228
+ for (const rec of shown) {
229
+ const item = document.createElement('span');
230
+ paintAvatar(item, specOf(rec, size, shape, true), failed, (src) => { failed.add(src); redraw(); });
231
+ item.className = joinClass(ROOT_CLASS[size], GROUP_ITEM_CLASS[shape]);
232
+ root.appendChild(item);
233
+ }
234
+ if (rest > 0) {
235
+ const more = document.createElement('span');
236
+ more.className = joinClass(moreClassOf(size, shape), MORE_FOCUS_CLASS);
237
+ more.setAttribute('role', 'img');
238
+ // 可聚焦;悬停 / 聚焦给被收起的姓名(hint-tips)
239
+ more.setAttribute('tabindex', '0');
240
+ const restNames = items.slice(shown.length).map((it) => str(it.name)).filter((n) => n !== '').join('、');
241
+ more.setAttribute('aria-label', restNames === '' ? kitText('soma.kit.avatar_more', { n: rest }, root) : `${kitText('soma.kit.avatar_more', { n: rest }, root)}:${restNames}`);
242
+ if (restNames !== '') more.setAttribute(KIT_ATTR_TIP, restNames);
243
+ more.textContent = `+${rest}`;
244
+ root.appendChild(more);
245
+ }
246
+ root.setAttribute('role', 'group');
247
+ if (names === '') root.removeAttribute('aria-label');
248
+ else root.setAttribute('aria-label', names);
249
+ root.className = joinClass(GROUP_CLASS, p.class);
250
+ return;
251
+ }
252
+ const face = document.createElement('span');
253
+ paintAvatar(face, specOf(who, size, shape), failed, (src) => { failed.add(src); redraw(); });
254
+ const inactive = bool(p.inactive);
255
+ const clickable = bool(p.clickable) && !inactive;
256
+ face.className = joinClass(ROOT_CLASS[size], inactive ? PERSON_INACTIVE_FACE_CLASS : '');
257
+ const text = document.createElement('span');
258
+ text.className = PERSON_TEXT_CLASS;
259
+ const name = document.createElement('span');
260
+ name.className = joinClass(
261
+ inactive ? `${PERSON_NAME_INACTIVE_BASE} ${CELL_TEXT_SIZE[size]}` : PERSON_NAME_CLASS[size],
262
+ clickable ? PERSON_NAME_HOVER_CLASS : '',
263
+ );
264
+ name.textContent = whoName;
265
+ if (inactive && str(p.inactive_label) !== '') {
266
+ // 姓名与「已停用 / 已离职」小标签同一行
267
+ const line = document.createElement('span');
268
+ line.className = 'flex min-w-0 items-center gap-1';
269
+ const tag = document.createElement('span');
270
+ tag.className = PERSON_INACTIVE_TAG_CLASS;
271
+ tag.textContent = str(p.inactive_label);
272
+ line.append(name, tag);
273
+ text.appendChild(line);
274
+ } else text.appendChild(name);
275
+ if (str(who.sub) !== '') {
276
+ const sub = document.createElement('span');
277
+ sub.className = PERSON_SUB_CLASS;
278
+ sub.textContent = str(who.sub);
279
+ text.appendChild(sub);
280
+ }
281
+ root.append(face, text);
282
+ root.removeAttribute('aria-label');
283
+ if (clickable) {
284
+ root.setAttribute('role', 'button');
285
+ root.setAttribute('tabindex', '0');
286
+ root.className = joinClass(PERSON_ROOT_CLICKABLE_CLASS, p.class);
287
+ } else if (bool(p.clickable) && inactive) {
288
+ root.setAttribute('role', 'button');
289
+ root.setAttribute('tabindex', '-1');
290
+ root.setAttribute('aria-disabled', 'true');
291
+ root.className = joinClass(PERSON_ROOT_CLASS, p.class);
292
+ } else {
293
+ root.removeAttribute('role');
294
+ root.className = joinClass(PERSON_ROOT_CLASS, p.class);
295
+ }
296
+ };
297
+ redraw();
298
+ setAttr(root, 'id', str(p.id));
299
+ },
300
+ };
301
+ }
302
+
303
+ export function createPersonCell(): SomaComponentDefinition {
304
+ return {
305
+ contract: {
306
+ name: 'PersonCell',
307
+ layer: 'basic',
308
+ props: {
309
+ name: { type: 'string', default: '', desc: '姓名' },
310
+ sub: { type: 'string', default: '', desc: '副文(角色 / 邮箱 / 部门),姓名下一行弱化墨' },
311
+ src: { type: 'string', default: '', desc: '头像图片地址;空或加载失败回退到姓名首字' },
312
+ status: { type: 'enum', values: ['', 'online', 'offline', 'busy', 'away'], default: '', desc: '头像右下角状态点' },
313
+ clickable: { type: 'boolean', default: false, desc: '单人可点:根变按钮(悬停状态层、聚焦环、姓名悬停下划线),点击 / Enter / Space 抛 click' },
314
+ inactive: { type: 'boolean', default: false, desc: '已停用 / 离职:头像灰阶、姓名弱化' },
315
+ inactive_label: { type: 'string', default: '', desc: '停用态的小标签文字(如「已离职」);空则不出标签' },
316
+ loading: { type: 'boolean', default: false, desc: '加载骨架:圆 + 两条灰条,根 aria-busy' },
317
+ items: { type: 'array', default: [], desc: '人员组 [{ name, sub?, src?, status? }]:给了(非空)就只画叠放的头像(成组),超出 max 收成 +N;空数组不盖字段值 value' },
318
+ value: { type: 'any', default: null, desc: '字段值(数据单元绑定,relation: person / people 时由编译器接上):单个人员对象 { name, sub, avatar }(或只有姓名的字符串)画成单人,人员数组画成人员组;键名按 name_key / sub_key / avatar_key' },
319
+ options: { ...OPTIONS_PROP, desc: '静态选项 [{ value, label }](relation: person / people 字段写了静态 options 时编译器接上,页面不写):字段值(或人员数组的成员)是选项值时姓名取该选项的文字,与 Text / Tag 同一取法;没命中照旧' },
320
+ name_key: { type: 'string', default: '', desc: '字段值里姓名的键名;缺省 name(schema 字段的 display 覆盖)' },
321
+ sub_key: { type: 'string', default: '', desc: '字段值里副文的键名;缺省 sub' },
322
+ avatar_key: { type: 'string', default: '', desc: '字段值里头像地址的键名;缺省 avatar(再认 src)' },
323
+ placeholder: { type: 'string', default: '', desc: '没有人员时显示的文字;缺省「—」' },
324
+ max: { type: 'string', default: '', desc: '人员组最多显示几枚;缺省 4' },
325
+ shape: { type: 'enum', values: ['circle', 'square'], default: 'circle', desc: '圆形或圆角方形' },
326
+ id: ID_PROPS.id,
327
+ size: SIZE_PROP,
328
+ class: CLASS_PROP,
329
+ },
330
+ emits: {
331
+ click: { payload: {}, desc: 'clickable 的单人单元被点击(click / Enter / Space)' },
332
+ },
333
+ },
334
+ templateHtml: `<span data-soma-id="root" class="${PERSON_ROOT_CLASS}"></span>`,
335
+ // 单元格类是值:根只报元素部件,不报层级角色
336
+ controllerFactory: createKitController(() => personView(), { self: { part: 'value' } }),
337
+ };
338
+ }
339
+
340
+ // ── TagGroup ──────────────────────────────────────────────────
341
+
342
+ const TAGS_ROOT_CLASS = 'inline-flex max-w-full min-w-0 flex-nowrap items-center gap-1 overflow-hidden';
343
+ const TAGS_ROOT_WRAP_CLASS = 'inline-flex max-w-full min-w-0 flex-wrap items-center gap-1';
344
+ // 单行:单枚标签不缩压(shrink-0 + max-w-28 可读下限,杜绝被压成 1 字「交…」),超宽自动收进 +N;换行形态:max-w-full + 省略
345
+ const TAG_ITEM_SINGLE = 'shrink-0 max-w-28 min-w-0 truncate whitespace-nowrap';
346
+ const TAG_ITEM_WRAP = 'max-w-full min-w-0 truncate whitespace-nowrap';
347
+ const TAG_ITEM_TEXT_INNER = 'min-w-0 truncate';
348
+ const TAG_MORE_EXTRA = 'shrink-0 whitespace-nowrap';
349
+ const TAG_GROUP_SIZE_EXTRA: Record<KitSize, string> = {
350
+ sm: 'min-h-5 px-1.5 py-0',
351
+ md: '',
352
+ lg: mergeClass('min-h-6 px-2.5 py-0.5', CELL_TEXT_SIZE.md),
353
+ };
354
+ // +N 悬停状态层 + 聚焦环(state-layer 叠在 bg-label-fill 上,避免 hover:bg-state-layer-hover 覆盖底色导致悬停隐身)
355
+ const TAG_MORE_CLASS = mergeClass('cursor-default transition-colors state-layer', kitFocusRingRecipe('item'));
356
+ const CATEGORY_TONED_FILL = kitLookRecipe('mark', 'tone', 'c1');
357
+ /** 缺省一行最多显示的标签数(超出收成 +N) */
358
+ const TAGS_SHOWN_DEFAULT = 3;
359
+
360
+ /** 成员(或选项声明)的色表键:标量取它本身的文字;对象有 value 取 value,否则取标签文字(label_key → label → name) */
361
+ function tagToneKeyOf(it: unknown, labelKey: string): string {
362
+ if (!isRec(it)) return str(it);
363
+ if (it.value !== undefined && it.value !== null && str(it.value) !== '') return str(it.value);
364
+ return str(it[labelKey], str(it.label, str(it.name)));
365
+ }
366
+
367
+ /**
368
+ * 分类色查表(SCON-173):先按显示文字查,再按色表键(选项值)查。编译期色表(category-tone.ts)与 Tag / Text 一样按选项值作键,
369
+ * 页面直接写的色表与旧数据按标签文字作键(契约 tag_tones 的说明);成员按选项映射成文字后两者不再相同,只按文字查会漏掉编译期色表。
370
+ */
371
+ function tagCategoryToneOf(map: unknown, key: string, label: string, auto: readonly number[] | undefined): ReturnType<typeof kitCategoryToneFor> {
372
+ // 文字键优先(与改动前逐字相同:旧色表 / 页面直写按文字),文字没命中再按值查(编译期色表)
373
+ return kitCategoryToneFor(map, label, auto) ?? (label !== key ? kitCategoryToneFor(map, key, auto) : undefined);
374
+ }
375
+
376
+ function tagToneOf(raw: unknown, fallback: KitTone): KitTone {
377
+ return typeof raw === 'string' && (TONES as readonly string[]).includes(raw) ? raw as KitTone : fallback;
378
+ }
379
+
380
+ /**
381
+ * 值按静态选项取文字(SCON-173,TagGroup 的成员与 Identifier 的引用值共用):relation: tags / record 字段写了静态 options 时,
382
+ * 编译器把选项原样交进 props.options(object-renderer/arrange.ts#fieldProps)。取法与 Text / Tag 是同一个出口 displayOf
383
+ * (base/shared.ts:按 String(值) 命中,没命中照原值文字);纯图标选项(没写 label)回退值文字,与 Tag 同。
384
+ * 没有选项、或值是空 / 数组 / 对象时返回 null:调用方照原样画(与没有 options 时逐字相同)。option 为 null = 有选项但没命中。
385
+ */
386
+ function optionShownOf(raw: unknown, opts: readonly KitOption[]): { label: string; option: KitOption | null } | null {
387
+ if (opts.length === 0 || raw === null || raw === undefined || raw === '' || Array.isArray(raw) || isRec(raw)) return null;
388
+ const shown = displayOf(raw, opts, '', '', '');
389
+ const label = shown.text === '' && shown.option !== null && shown.option.icon !== undefined ? str(shown.option.value) : shown.text;
390
+ return { label, option: shown.option };
391
+ }
392
+
393
+ function tagGroupView(): KitView {
394
+ let rafId: number | null = null;
395
+ let disposed = false;
396
+
397
+ const cancelRaf = (): void => {
398
+ if (rafId !== null && typeof cancelAnimationFrame === 'function') {
399
+ cancelAnimationFrame(rafId);
400
+ rafId = null;
401
+ }
402
+ };
403
+
404
+ return {
405
+ attach() {
406
+ disposed = false;
407
+ return () => {
408
+ disposed = true;
409
+ cancelRaf();
410
+ };
411
+ },
412
+ render(root, input, api) {
413
+ cancelRaf();
414
+ // 入参改名 input:函数体里原有的 raw 指成员数组,避免同名遮蔽
415
+ const p = withTagGroupKit(input, root);
416
+ const size = sizeOf(p.size);
417
+ const rawGroupTone = typeof p.tone === 'string' ? p.tone.trim() : '';
418
+ const hasGroupTone = rawGroupTone !== '';
419
+ const base = tagToneOf(rawGroupTone, 'neutral');
420
+ const raw = tagMembersOf(p);
421
+ // 成员是对象时标签文字取 label_key(schema 字段 display)指名的键,缺省 label,再退 name / value
422
+ const labelKey = str(p.label_key, 'label');
423
+ // 成员是静态选项的值(SCON-173):画成该选项的文字并带上它的语气,等同条目 { label, tone };没有 options 时 opts 为空,下面逐字照旧
424
+ const opts = optionsOf(p.options);
425
+ const items = raw
426
+ .map((it) => {
427
+ if (isRec(it)) {
428
+ const named = str(it[labelKey], str(it.label, str(it.name)));
429
+ // 对象成员没有文字键、只有 value 时同样按选项取文字;条目自己写的 tone 优先于选项的语气
430
+ const shown = named === '' ? optionShownOf(it.value, opts) : null;
431
+ const label = named !== '' ? named : shown !== null ? shown.label : str(it.value);
432
+ const ownTone = typeof it.tone === 'string' ? it.tone.trim() : '';
433
+ const rawItTone = ownTone !== '' ? ownTone : (shown?.option?.tone ?? '');
434
+ const hasItemTone = rawItTone !== '';
435
+ return {
436
+ label,
437
+ key: tagToneKeyOf(it, labelKey),
438
+ tone: hasItemTone ? tagToneOf(rawItTone, base) : base,
439
+ hasExplicit: hasItemTone || hasGroupTone,
440
+ nonNeutralExplicit: (hasItemTone && rawItTone !== 'neutral') || (hasGroupTone && base !== 'neutral'),
441
+ };
442
+ }
443
+ const shown = optionShownOf(it, opts);
444
+ const optTone = shown?.option?.tone ?? '';
445
+ const hasOptTone = optTone !== '';
446
+ return {
447
+ label: shown !== null ? shown.label : str(it),
448
+ key: str(it),
449
+ tone: hasOptTone ? tagToneOf(optTone, base) : base,
450
+ hasExplicit: hasOptTone || hasGroupTone,
451
+ nonNeutralExplicit: (hasOptTone && optTone !== 'neutral') || (hasGroupTone && base !== 'neutral'),
452
+ };
453
+ })
454
+ .filter((it) => it.label !== '');
455
+ const maxRaw = num(p.max);
456
+ const max = maxRaw !== null && maxRaw >= 1 ? Math.floor(maxRaw) : TAGS_SHOWN_DEFAULT;
457
+ const wrap = bool(p.wrap);
458
+ root.textContent = '';
459
+ root.removeAttribute('aria-busy');
460
+ if (bool(p.loading)) {
461
+ root.removeAttribute(KIT_ATTR_TIPS);
462
+ // 加载 = 两枚灰条骨架
463
+ for (let i = 0; i < 2; i += 1) {
464
+ const bar = document.createElement('span');
465
+ bar.className = KIT_SKELETON_BAR_TAG;
466
+ bar.setAttribute('aria-hidden', 'true');
467
+ root.appendChild(bar);
468
+ }
469
+ root.setAttribute('aria-busy', 'true');
470
+ root.removeAttribute('role');
471
+ setAttr(root, 'id', str(p.id));
472
+ root.className = joinClass(TAGS_ROOT_CLASS, p.class);
473
+ kitMarkDataState(kitOuterRoot(api.host, root), 'loading');
474
+ return;
475
+ }
476
+ if (items.length > 0) root.setAttribute(KIT_ATTR_TIPS, '');
477
+ else root.removeAttribute(KIT_ATTR_TIPS);
478
+ // 色表里未解析的自动位 '@k'(next 下编译期不解析,E→D)按主题自动序列解析,与编译期页尾一遍同一规则;legacy 色表没有自动位,不读序列(每次渲染读一次)
479
+ const autoTones = kitToneMapHasAuto(p.tag_tones) ? kitCategoryAutoSequence(root) : undefined;
480
+ const paintItems = (visibleLimit: number): void => {
481
+ root.textContent = '';
482
+ const shown = wrap ? items : items.slice(0, visibleLimit);
483
+ const hidden = wrap ? [] : items.slice(shown.length);
484
+ for (const it of shown) {
485
+ // 分类色(CS20):没有非中性显式语气且色表命中 → 淡底 + 同色字经色调载体(与 Tag 同一出口)
486
+ const cat = it.nonNeutralExplicit ? undefined : tagCategoryToneOf(p.tag_tones, it.key, it.label, autoTones);
487
+ let itemTone: KitTone = it.tone;
488
+ if (!it.hasExplicit && cat === undefined) {
489
+ const matched = kitMatchSemanticStatusTone(it.label);
490
+ if (matched === 'info' || matched === 'success' || matched === 'warning' || matched === 'danger') {
491
+ itemTone = matched;
492
+ }
493
+ }
494
+ const span = document.createElement('span');
495
+ const chipRecipe = size === 'md'
496
+ ? kitClosedValueRecipe(itemTone)
497
+ : mergeClass(kitClosedValueRecipe(itemTone), TAG_GROUP_SIZE_EXTRA[size]);
498
+ // 标签组 = 闭集值:走闭集值出口(语气淡底 + 同色字)
499
+ span.className = `${chipRecipe} ${wrap ? TAG_ITEM_WRAP : TAG_ITEM_SINGLE}`;
500
+ span.setAttribute('role', 'listitem');
501
+ if (cat !== undefined) {
502
+ span.className = `${span.className} ${CATEGORY_TONED_FILL}`;
503
+ span.setAttribute(KIT_LOOK_TONE_ATTR, cat);
504
+ }
505
+ const textInner = document.createElement('span');
506
+ textInner.className = TAG_ITEM_TEXT_INNER;
507
+ textInner.textContent = it.label;
508
+ span.appendChild(textInner);
509
+ root.appendChild(span);
510
+ }
511
+ if (hidden.length > 0) {
512
+ const more = document.createElement('span');
513
+ const moreRecipe = size === 'md'
514
+ ? kitClosedValueRecipe('neutral')
515
+ : mergeClass(kitClosedValueRecipe('neutral'), TAG_GROUP_SIZE_EXTRA[size]);
516
+ more.className = `${moreRecipe} ${TAG_MORE_EXTRA} ${TAG_MORE_CLASS}`;
517
+ more.textContent = `+${hidden.length}`;
518
+ const restLabels = hidden.map((h) => h.label).join('、');
519
+ // +N 是可聚焦的列表项,带完整可访问名(其余标签),悬停 / 聚焦给气泡
520
+ more.setAttribute('role', 'listitem');
521
+ more.setAttribute('tabindex', '0');
522
+ more.setAttribute('aria-label', `+${hidden.length}:${restLabels}`);
523
+ more.setAttribute(KIT_ATTR_TIP, restLabels);
524
+ root.appendChild(more);
525
+ }
526
+ if (items.length === 0 && str(p.placeholder) !== '') {
527
+ const none = document.createElement('span');
528
+ none.className = EMPTY_SIZE_CLASS[size];
529
+ none.textContent = str(p.placeholder);
530
+ root.appendChild(none);
531
+ }
532
+ };
533
+ // wrap(详情页):全部标签展开并换行,不收 +N;单行(缺省)超过 max 收成 +N,且在真实窄容器内按可用宽度继续折进 +N
534
+ const cap = wrap ? items.length : Math.min(items.length, max);
535
+ paintItems(cap);
536
+ kitMarkDataState(kitOuterRoot(api.host, root), items.length === 0 ? 'empty' : 'normal');
537
+ root.setAttribute('role', 'list');
538
+ setAttr(root, 'id', str(p.id));
539
+ root.className = joinClass(wrap ? TAGS_ROOT_WRAP_CLASS : TAGS_ROOT_CLASS, p.class);
540
+ if (!wrap && cap > 1) {
541
+ let currentVisible = cap;
542
+ let lastContainerW = -1;
543
+ const fit = (): void => {
544
+ if (disposed || !root.isConnected) return;
545
+ const avail = root.clientWidth;
546
+ if (avail <= 0) return;
547
+ const containerW = root.parentElement?.clientWidth ?? avail;
548
+ if (containerW === lastContainerW && root.scrollWidth <= avail + 1) return;
549
+ if (containerW !== lastContainerW && currentVisible < cap) {
550
+ currentVisible = cap;
551
+ paintItems(currentVisible);
552
+ }
553
+ lastContainerW = containerW;
554
+ while (currentVisible > 1 && root.scrollWidth > root.clientWidth + 1) {
555
+ currentVisible -= 1;
556
+ paintItems(currentVisible);
557
+ }
558
+ };
559
+ fit();
560
+ if (typeof requestAnimationFrame === 'function') {
561
+ rafId = requestAnimationFrame(() => {
562
+ rafId = null;
563
+ fit();
564
+ });
565
+ }
566
+ }
567
+ },
568
+ };
569
+ }
570
+
571
+ export function createTagGroup(): SomaComponentDefinition {
572
+ return {
573
+ contract: {
574
+ name: 'TagGroup',
575
+ layer: 'basic',
576
+ props: {
577
+ items: { type: 'array', default: [], desc: '标签 [字符串 | { label, tone? }];也可经 value 绑定字符串数组' },
578
+ value: { type: 'array', default: [], desc: '字段值(数据单元绑定):字符串数组,items 未给时取它' },
579
+ label_key: { type: 'string', default: '', desc: '成员是对象时标签文字的键名(schema 字段 display);缺省 label,再退 name / value' },
580
+ options: { ...OPTIONS_PROP, desc: '静态选项 [{ value, label, tone? }](relation: tags 字段写了静态 options 时编译器接上,页面不写):成员是选项值时画成该选项的文字、带上它的语气(条目自己写的 tone 优先),与 Text / Tag 同一取法;没命中的成员照原值' },
581
+ max: { type: 'string', default: '', desc: '一行最多显示几枚,其余收成「+N」(悬停给出被收起的标签);缺省 3' },
582
+ wrap: { type: 'boolean', default: false, desc: '详情页形态:标签全部展开并换行(不收 +N);缺省单行' },
583
+ loading: { type: 'boolean', default: false, desc: '加载骨架:两枚灰条,根 aria-busy' },
584
+ tag_tones: { type: 'object', default: {}, desc: '标签色表 { 选项值(或标签文字): 分类色名 c1…c8 }(编译期按选项值推出,页面不写):没有语气的标签画成分类色淡底;先按显示文字查、再按成员的值查' },
585
+ tone: { type: 'enum', values: ['', 'neutral', 'info', 'success', 'warning', 'danger'], default: '', desc: '标签语气(条目自带 tone 时以条目为准)' },
586
+ placeholder: { type: 'string', default: '', desc: '没有标签时显示的文字' },
587
+ id: ID_PROPS.id,
588
+ size: SIZE_PROP,
589
+ class: CLASS_PROP,
590
+ },
591
+ emits: {},
592
+ },
593
+ templateHtml: `<span data-soma-id="root" role="list" class="${TAGS_ROOT_CLASS}"></span>`,
594
+ controllerFactory: createKitController(() => tagGroupView(), { self: { part: 'mark' } }),
595
+ };
596
+ }
597
+
598
+ // ── Identifier ────────────────────────────────────────────────
599
+
600
+ const CODE_ROOT_CLASS = 'inline-flex max-w-full min-w-0 items-center gap-1';
601
+ // 标识块 = 标识出口(中性淡底等宽小块,主题公式 F7)
602
+ const IDENT_FACE_CLASS = mergeClass(kitIdentRecipe(), 'min-w-0 max-w-full');
603
+ const IDENT_SIZE_EXTRA: Record<KitSize, string> = {
604
+ sm: 'px-1 py-0',
605
+ md: '',
606
+ lg: mergeClass('px-2 py-0.5', CELL_TEXT_SIZE.md),
607
+ };
608
+ const CODE_HEAD_CLASS = 'min-w-0 truncate';
609
+ const CODE_TAIL_CLASS = 'shrink-0';
610
+ const IDENT_LINK_CLASS = mergeClass('min-w-0 truncate text-primary-on-soft hover:underline', kitFocusRingRecipe('item'));
611
+ const SEPARATORS = /[-_.:/]/;
612
+ const COPIED_MS = 1500;
613
+
614
+ /** 尾段:最后一个分隔符之后的一段(订单号、UUID 取末段);没有分隔符或末段超过一半取四分之一(哈希);头部由 CSS 截断,尾段恒显示 */
615
+ export function identifierTail(text: string): number {
616
+ const half = Math.floor(text.length / 2);
617
+ const cut = Math.max(...Array.from(text).map((ch, i) => (SEPARATORS.test(ch) ? i : -1)));
618
+ const seg = cut >= 0 ? text.length - cut - 1 : 0;
619
+ return seg > 0 && seg <= half ? seg : Math.ceil(half / 2);
620
+ }
621
+
622
+ function identifierView(): KitView {
623
+ let timer: ReturnType<typeof setTimeout> | null = null;
624
+ let copied = false;
625
+ let currentValue = '';
626
+ let copyBtn: HTMLButtonElement | null = null;
627
+ let liveEl: HTMLSpanElement | null = null;
628
+
629
+ return {
630
+ attach(root, api) {
631
+ const onRootClick = (ev: Event): void => {
632
+ const target = ev.target instanceof HTMLElement ? ev.target : null;
633
+ if (!target) return;
634
+ const link = target.closest('a[href]');
635
+ if (link && root.contains(link)) {
636
+ ev.stopPropagation();
637
+ return;
638
+ }
639
+ const btn = target.closest<HTMLButtonElement>(`[${KIT_ATTR_ACTION}="copy"]`);
640
+ if (!btn || !root.contains(btn)) return;
641
+ ev.stopPropagation();
642
+ const p = api.props();
643
+ const val = currentValue;
644
+ if (val === '') return;
645
+ const onFail = (): void => {
646
+ const hint = str(p.copy_failed_label, kitText('soma.kit.copy_failed', undefined, root));
647
+ btn.removeAttribute('title');
648
+ btn.setAttribute('aria-label', hint);
649
+ btn.setAttribute(KIT_ATTR_TIP, hint);
650
+ if (liveEl) liveEl.textContent = hint;
651
+ api.emit('copy', { ok: false });
652
+ };
653
+ const clip = typeof navigator !== 'undefined' ? navigator.clipboard : undefined;
654
+ if (!clip || typeof clip.writeText !== 'function') {
655
+ onFail();
656
+ return;
657
+ }
658
+ clip.writeText(val).then(() => {
659
+ copied = true;
660
+ const okText = str(api.props().copied_label, kitText('soma.kit.copied', undefined, root));
661
+ setKitCopyButton(btn, okText, true);
662
+ btn.removeAttribute('title');
663
+ if (liveEl) liveEl.textContent = okText;
664
+ if (timer !== null) clearTimeout(timer);
665
+ timer = setTimeout(() => {
666
+ copied = false;
667
+ timer = null;
668
+ if (liveEl) liveEl.textContent = '';
669
+ if (copyBtn && copyBtn.isConnected) {
670
+ const resetText = str(api.props().copy_label, kitText('soma.kit.copy', undefined, root));
671
+ setKitCopyButton(copyBtn, resetText, false);
672
+ copyBtn.removeAttribute('title');
673
+ }
674
+ }, COPIED_MS);
675
+ api.emit('copy', { ok: true });
676
+ }, onFail);
677
+ };
678
+ root.addEventListener('click', onRootClick);
679
+ return () => {
680
+ root.removeEventListener('click', onRootClick);
681
+ if (timer !== null) {
682
+ clearTimeout(timer);
683
+ timer = null;
684
+ }
685
+ };
686
+ },
687
+ render(root, raw, api) {
688
+ // 溢出策略:组件自己写了非缺省(middle 是契约缺省)的 truncate 优先,否则取页面线判定
689
+ const kitOverflow = kitReadProps(raw).overflow;
690
+ const p: KitProps = kitOverflow !== undefined && str(raw.truncate, 'middle') === 'middle' ? { ...raw, truncate: IDENT_TRUNCATE_OF[kitOverflow] } : raw;
691
+ const size = sizeOf(p.size);
692
+ // 引用记录(relation: record):字段值是 { id, name } 对象,名称键由 name_key(display)指名;值只有一个字符串时它就是名称
693
+ const named = str(p.name_key) !== '';
694
+ const opts = optionsOf(p.options);
695
+ // 对象值按引用记录取:写了 name_key,或写了静态 options(没有 name_key 的 { id } 也认,不把对象画成「[object Object]」)
696
+ const rec = (named || opts.length > 0) && isRec(p.value) ? p.value : null;
697
+ // 字段写了静态 options(SCON-173)且值是其中一项:名称取该选项的文字、标识块是值本身(与 Text / Tag 同一取法);没给 options 或没命中照旧
698
+ const shownOpt = named && rec === null ? optionShownOf(p.value, opts) : null;
699
+ const optHit = shownOpt !== null && shownOpt.option !== null ? shownOpt : null;
700
+ const recId = rec !== null ? rec[str(p.id_key, 'id')] : undefined;
701
+ // 引用记录没带名称(只有 { id },或名称键为空):名称按选项取 id 的文字;没命中照旧(只出标识块)
702
+ const recName = rec !== null ? (named ? str(rec[str(p.name_key)]) : '') : '';
703
+ const value = rec !== null ? str(recId) : optHit !== null ? str(p.value) : named ? '' : str(p.value);
704
+ const label = rec !== null ? (recName !== '' ? recName : optionHitLabel(recId, opts) ?? '') : optHit !== null ? optHit.label : named && !isRec(p.value) ? str(p.value) : '';
705
+ if (value !== currentValue) {
706
+ currentValue = value;
707
+ copied = false;
708
+ if (timer !== null) {
709
+ clearTimeout(timer);
710
+ timer = null;
711
+ }
712
+ }
713
+ const mode = str(p.truncate, 'middle');
714
+ root.className = joinClass(CODE_ROOT_CLASS, p.class);
715
+ setAttr(root, 'id', str(p.id));
716
+ const leadingNodes: HTMLElement[] = [];
717
+ if (label !== '') {
718
+ const nameEl = document.createElement('span');
719
+ nameEl.className = PERSON_NAME_CLASS[size];
720
+ nameEl.textContent = label;
721
+ nameEl.setAttribute(KIT_ATTR_TIP, label);
722
+ leadingNodes.push(nameEl);
723
+ }
724
+ kitMarkDataState(kitOuterRoot(api.host, root), value === '' && label === '' ? 'empty' : 'normal');
725
+ if (value === '') {
726
+ if (label === '') {
727
+ const none = document.createElement('span');
728
+ none.className = EMPTY_SIZE_CLASS[size];
729
+ none.textContent = str(p.placeholder, '—');
730
+ leadingNodes.push(none);
731
+ }
732
+ root.replaceChildren(...leadingNodes);
733
+ return;
734
+ }
735
+ // XSS 阻断:href 必须先过 safeHref,非法或空串一律渲染 <span> 绝不挂非法 href
736
+ const href = safeHref(str(p.href));
737
+ const faceBase = size === 'md' ? IDENT_FACE_CLASS : mergeClass(IDENT_FACE_CLASS, IDENT_SIZE_EXTRA[size]);
738
+ const face = document.createElement(href !== '' ? 'a' : 'span');
739
+ if (href !== '') {
740
+ face.setAttribute('href', href);
741
+ face.className = mergeClass(faceBase, IDENT_LINK_CLASS);
742
+ } else {
743
+ // 可整段选中(复制失败时用户手动复制)
744
+ face.className = `${faceBase} select-all`;
745
+ }
746
+ if (mode === 'middle' && value.length > 1) {
747
+ const n = identifierTail(value);
748
+ const head = document.createElement('span');
749
+ head.className = CODE_HEAD_CLASS;
750
+ head.textContent = value.slice(0, value.length - n);
751
+ const tail = document.createElement('span');
752
+ tail.className = CODE_TAIL_CLASS;
753
+ tail.textContent = value.slice(value.length - n);
754
+ face.append(head, tail);
755
+ } else if (mode === 'end') {
756
+ const head = document.createElement('span');
757
+ head.className = CODE_HEAD_CLASS;
758
+ head.textContent = value;
759
+ face.appendChild(head);
760
+ } else {
761
+ face.textContent = value;
762
+ }
763
+ // 截断后全文:悬停 / 聚焦提示(hint-tips 只在被截断时才出)
764
+ face.setAttribute(KIT_ATTR_TIP, value);
765
+ leadingNodes.push(face);
766
+ if (bool(p.copyable)) {
767
+ if (!copyBtn) {
768
+ copyBtn = document.createElement('button');
769
+ copyBtn.setAttribute('type', 'button');
770
+ copyBtn.setAttribute(KIT_ATTR_ACTION, 'copy');
771
+ }
772
+ if (!liveEl) {
773
+ liveEl = document.createElement('span');
774
+ liveEl.className = 'sr-only';
775
+ liveEl.setAttribute('aria-live', 'polite');
776
+ liveEl.setAttribute(KIT_ATTR_COPY_LIVE, '');
777
+ }
778
+ copyBtn.className = COPY_BTN_CLASS;
779
+ const btnLabel = copied
780
+ ? str(p.copied_label, kitText('soma.kit.copied', undefined, root))
781
+ : str(p.copy_label, kitText('soma.kit.copy', undefined, root));
782
+ setKitCopyButton(copyBtn, btnLabel, copied);
783
+ copyBtn.removeAttribute('title');
784
+ liveEl.textContent = copied ? str(p.copied_label, kitText('soma.kit.copied', undefined, root)) : '';
785
+ if (copyBtn.parentElement === root) {
786
+ for (const ch of Array.from(root.childNodes)) {
787
+ if (ch !== copyBtn && ch !== liveEl) ch.remove();
788
+ }
789
+ for (const node of leadingNodes) root.insertBefore(node, copyBtn);
790
+ if (liveEl.parentElement !== root) root.appendChild(liveEl);
791
+ } else {
792
+ root.replaceChildren(...leadingNodes, copyBtn, liveEl);
793
+ }
794
+ } else {
795
+ root.replaceChildren(...leadingNodes);
796
+ }
797
+ },
798
+ };
799
+ }
800
+
801
+ export function createIdentifier(): SomaComponentDefinition {
802
+ return {
803
+ contract: {
804
+ name: 'Identifier',
805
+ layer: 'basic',
806
+ props: {
807
+ value: { type: 'any', default: '', desc: '标识串(ID / 哈希 / 单号),字段值绑定;写了 name_key 时(relation: record)也认 { id, name } 对象与只有名称的字符串' },
808
+ name_key: { type: 'string', default: '', desc: '引用记录的名称键名(schema 字段 display):给了就把字段值当引用记录——对象取 id_key / name_key 两项,名称在前、标识块在后;字符串值当名称' },
809
+ id_key: { type: 'string', default: '', desc: '引用记录里标识的键名;缺省 id' },
810
+ options: { ...OPTIONS_PROP, desc: '静态选项 [{ value, label }](relation: record 字段写了静态 options 时编译器接上,页面不写):写了 name_key 且字段值是选项值时,名称取该选项的文字、标识块是值本身,与 Text / Tag 同一取法;没命中照旧(字符串值当名称)' },
811
+ truncate: { type: 'enum', values: ['middle', 'end', 'none'], default: 'middle', desc: '放不下时的省略:middle = 中间省略(尾段恒显示)/ end = 末尾省略 / none = 不省略' },
812
+ copyable: { type: 'boolean', default: true, desc: '带复制钮(缺省带);点后复制完整标识串' },
813
+ copy_label: { type: 'string', default: '', desc: '复制钮提示文字;缺省取内置文案' },
814
+ copied_label: { type: 'string', default: '', desc: '复制成功提示文字;缺省取内置文案' },
815
+ copy_failed_label: { type: 'string', default: '', desc: '复制失败时钮上就地给出的「请手动复制」提示文字;缺省取内置文案' },
816
+ href: { type: 'string', default: '', desc: '给了就把标识串画成链接(站内相对地址)' },
817
+ placeholder: { type: 'string', default: '—', desc: '值为空时显示的占位' },
818
+ id: ID_PROPS.id,
819
+ size: SIZE_PROP,
820
+ class: CLASS_PROP,
821
+ },
822
+ emits: {
823
+ copy: { payload: { ok: { type: 'boolean' } }, desc: '点复制钮后抛,ok 表示剪贴板写入成功(不带文本)' },
824
+ },
825
+ },
826
+ templateHtml: `<span data-soma-id="root" class="${CODE_ROOT_CLASS}"></span>`,
827
+ controllerFactory: createKitController(() => identifierView(), { self: { part: 'value' } }),
828
+ };
829
+ }
830
+
831
+ export const KIT_IDENTITY_CELLS_CLASS_CANDIDATES: readonly string[] = classCandidates(
832
+ Object.values(CELL_TEXT_SIZE), Object.values(EMPTY_SIZE_CLASS),
833
+ PERSON_ROOT_CLASS, PERSON_TEXT_CLASS, PERSON_NAME_BASE, Object.values(PERSON_NAME_CLASS), PERSON_SUB_CLASS,
834
+ PERSON_ROOT_CLICKABLE_CLASS, PERSON_NAME_HOVER_CLASS, PERSON_NAME_INACTIVE_BASE, PERSON_INACTIVE_TAG_CLASS, PERSON_INACTIVE_FACE_CLASS,
835
+ PERSON_SKELETON_ROOT_CLASS, PERSON_SKELETON_TEXT_CLASS, MORE_FOCUS_CLASS, KIT_SKELETON_AVATAR, KIT_SKELETON_BAR_MID, KIT_SKELETON_BAR_LABEL, KIT_SKELETON_BAR_TAG,
836
+ 'flex min-w-0 items-center gap-1', 'select-all', 'sr-only',
837
+ TAGS_ROOT_CLASS, TAGS_ROOT_WRAP_CLASS, TAG_ITEM_SINGLE, TAG_ITEM_WRAP, TAG_ITEM_TEXT_INNER, TAG_MORE_EXTRA, Object.values(TAG_GROUP_SIZE_EXTRA), TAG_MORE_CLASS, CATEGORY_TONED_FILL, ...KIT_MARK_CLASS_CANDIDATES,
838
+ CODE_ROOT_CLASS, IDENT_FACE_CLASS, Object.values(IDENT_SIZE_EXTRA), CODE_HEAD_CLASS, CODE_TAIL_CLASS, IDENT_LINK_CLASS, COPY_BTN_CLASS,
839
+ );