soma-kit 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/README.md +106 -112
  2. package/bin/soma-kit.mjs +32 -2
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +14 -7
  5. package/packs/finance/reconcile-board.ts +5 -2
  6. package/packs/finance/reconcile-desk/compile.ts +3 -2
  7. package/spec/generated/kit-app.schema.json +929 -37
  8. package/spec/generated/kit-page.schema.json +1684 -161
  9. package/spec/kit-grammar.json +1176 -584
  10. package/spec/kit-grammar.schema.json +1971 -393
  11. package/src/app/app-config.ts +449 -347
  12. package/src/app/component-gate.ts +283 -28
  13. package/src/app/compose-apps.ts +79 -8
  14. package/src/app/define-kit-actions.ts +245 -41
  15. package/src/app/define-kit-app.ts +176 -33
  16. package/src/app/define-kit-view.ts +104 -0
  17. package/src/app/dev-diagnostic.ts +5 -0
  18. package/src/app/envelope.ts +1 -161
  19. package/src/app/index.ts +29 -6
  20. package/src/app/kit-view-context.ts +439 -0
  21. package/src/app/notify-renderer.ts +1 -115
  22. package/src/app/paged-list-adapter.ts +1 -240
  23. package/src/app/render-ports.ts +18 -0
  24. package/src/app/server-pages.ts +11 -3
  25. package/src/app/server.ts +530 -103
  26. package/src/app/submit.types.ts +1 -1
  27. package/src/app/theme-endpoint.ts +63 -0
  28. package/src/app/theme-runtime-shared.ts +1 -0
  29. package/src/app/theme-runtime.ts +667 -0
  30. package/src/base/action-busy.ts +103 -6
  31. package/src/base/action-gate.ts +4 -255
  32. package/src/base/action-slots.ts +58 -0
  33. package/src/base/alert.ts +5 -3
  34. package/src/base/anchored-layer.ts +50 -0
  35. package/src/base/avatar.ts +2 -2
  36. package/src/base/button.ts +99 -37
  37. package/src/base/cascader.ts +11 -12
  38. package/src/base/check-core.ts +9 -1
  39. package/src/base/checkbox.ts +2 -1
  40. package/src/base/choice.ts +49 -28
  41. package/src/base/class-candidates.ts +17 -0
  42. package/src/base/color-picker.ts +16 -11
  43. package/src/base/combobox.ts +5 -3
  44. package/src/base/command-palette.ts +10 -6
  45. package/src/base/context-menu.ts +10 -7
  46. package/src/base/countdown.ts +1 -1
  47. package/src/base/date-range.ts +32 -18
  48. package/src/base/date.ts +135 -28
  49. package/src/base/delta.ts +72 -0
  50. package/src/base/divider.ts +2 -2
  51. package/src/base/end-edge.ts +49 -0
  52. package/src/base/fab.ts +12 -5
  53. package/src/base/gap-value.ts +148 -0
  54. package/src/base/hint-tips.ts +170 -0
  55. package/src/base/icons.ts +8 -0
  56. package/src/base/illustrations.ts +94 -0
  57. package/src/base/image.ts +1 -1
  58. package/src/base/index.ts +35 -11
  59. package/src/base/input.ts +42 -13
  60. package/src/base/kbd.ts +3 -1
  61. package/src/base/link.ts +4 -4
  62. package/src/base/listbox-core.ts +56 -35
  63. package/src/base/loading-gate.ts +186 -0
  64. package/src/base/mentions.ts +7 -6
  65. package/src/base/menu-button.ts +28 -12
  66. package/src/base/menu-core.ts +41 -8
  67. package/src/base/motion/aura.ts +2 -2
  68. package/src/base/motion/hover-3d.ts +3 -3
  69. package/src/base/motion/hover-gallery.ts +2 -2
  70. package/src/base/motion/marquee.ts +3 -3
  71. package/src/base/motion/text-rotate.ts +2 -2
  72. package/src/base/number.ts +93 -80
  73. package/src/base/otp.ts +9 -5
  74. package/src/base/overlay-runtime.ts +235 -0
  75. package/src/base/permission-gate.ts +6 -0
  76. package/src/base/popover.ts +48 -16
  77. package/src/base/popup.ts +143 -19
  78. package/src/base/portal-core.ts +4 -0
  79. package/src/base/price-text.ts +2 -2
  80. package/src/base/progress.ts +2 -2
  81. package/src/base/qr-code.ts +4 -4
  82. package/src/base/qty-stepper.ts +14 -8
  83. package/src/base/radio.ts +2 -1
  84. package/src/base/range.ts +21 -4
  85. package/src/base/rating.ts +12 -7
  86. package/src/base/reason-tip.ts +150 -0
  87. package/src/base/segmented.ts +27 -21
  88. package/src/base/select.ts +4 -3
  89. package/src/base/shared.ts +387 -49
  90. package/src/base/state-panel.ts +346 -0
  91. package/src/base/status-tone.ts +27 -0
  92. package/src/base/sticky-edge.ts +116 -0
  93. package/src/base/swap.ts +10 -7
  94. package/src/base/switch.ts +11 -6
  95. package/src/base/tag-input.ts +20 -16
  96. package/src/base/tag.ts +68 -34
  97. package/src/base/text.ts +80 -18
  98. package/src/base/textarea.ts +37 -11
  99. package/src/base/time-picker.ts +18 -13
  100. package/src/base/tree-select.ts +21 -12
  101. package/src/base/trend-tone.ts +9 -0
  102. package/src/base/upload.ts +48 -14
  103. package/src/base/view-transition.ts +77 -0
  104. package/src/base/virtual-list.ts +107 -1
  105. package/src/biz/approval-desk/compile.ts +23 -41
  106. package/src/biz/approval-desk/shell.ts +11 -8
  107. package/src/biz/auth-panel/compile.ts +37 -52
  108. package/src/biz/auth-panel/index.ts +1 -1
  109. package/src/biz/auth-panel/shell.ts +5 -4
  110. package/src/biz/category-crud/compile.ts +23 -37
  111. package/src/biz/category-crud/shell.ts +2 -1
  112. package/src/biz/checkout-page/compile.ts +22 -5
  113. package/src/biz/checkout-page/shell.ts +4 -3
  114. package/src/biz/compose.ts +13 -27
  115. package/src/biz/define.ts +5 -4
  116. package/src/biz/import-wizard/compile.ts +22 -26
  117. package/src/biz/import-wizard/hub.ts +126 -61
  118. package/src/biz/import-wizard/shell.ts +5 -4
  119. package/src/biz/index.ts +3 -3
  120. package/src/biz/landing-page/compile.ts +19 -3
  121. package/src/biz/link/hub.ts +69 -22
  122. package/src/biz/link/shared.ts +127 -119
  123. package/src/biz/master-sub/compile.ts +127 -48
  124. package/src/biz/master-sub/index.ts +5 -2
  125. package/src/biz/master-sub/shell.ts +95 -18
  126. package/src/biz/multi-board/compile.ts +38 -50
  127. package/src/biz/multi-board/index.ts +18 -1
  128. package/src/biz/multi-board/shell.ts +32 -20
  129. package/src/biz/notification-center/compile.ts +21 -33
  130. package/src/biz/notification-center/shell.ts +6 -4
  131. package/src/biz/page-templates/domain-templates.ts +80 -13
  132. package/src/biz/page-templates/result-page/compile.ts +11 -2
  133. package/src/biz/page-templates/result-page/shell.ts +2 -1
  134. package/src/biz/page-templates/shared.ts +34 -36
  135. package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
  136. package/src/biz/record-detail/compile.ts +48 -43
  137. package/src/biz/record-detail/index.ts +11 -1
  138. package/src/biz/record-detail/shell.ts +8 -6
  139. package/src/biz/settings-center/compile.ts +7 -5
  140. package/src/biz/settings-center/shell.ts +6 -4
  141. package/src/biz/shared/action-host.ts +97 -211
  142. package/src/biz/shared/compile-helpers.ts +98 -0
  143. package/src/biz/shared/coordinator.ts +472 -92
  144. package/src/biz/shared/index.ts +13 -2
  145. package/src/biz/shared/object-aliases.ts +154 -0
  146. package/src/biz/shared/overlay-compile.ts +239 -0
  147. package/src/biz/shared/overlay-shell.ts +209 -0
  148. package/src/biz/shared/pipes.ts +50 -31
  149. package/src/biz/shared/remove-wire.ts +14 -0
  150. package/src/biz/shared/runtime-hub.ts +226 -24
  151. package/src/biz/single-form/compile.ts +16 -37
  152. package/src/biz/single-form/shell.ts +4 -3
  153. package/src/biz/standard-crud/compile.ts +72 -255
  154. package/src/biz/standard-crud/shell.ts +21 -99
  155. package/src/biz/step-form/compile.ts +26 -97
  156. package/src/biz/step-form/hub.ts +34 -41
  157. package/src/biz/step-form/shell.ts +5 -5
  158. package/src/biz/types.ts +4 -3
  159. package/src/cli/core-imports.ts +54 -0
  160. package/src/cli/kit-cli.ts +254 -25
  161. package/src/cli/kit-init.ts +227 -0
  162. package/src/cli/layout-cli.ts +167 -0
  163. package/src/cli/migrate/index.ts +10 -0
  164. package/src/cli/migrate/migrate.ts +248 -0
  165. package/src/cli/migrate/text-utils.ts +306 -0
  166. package/src/cli/migrate/theme-map.ts +104 -0
  167. package/src/cli/migrate/ts-rules.ts +235 -0
  168. package/src/cli/migrate/types.ts +95 -0
  169. package/src/cli/migrate/view-skeleton.ts +159 -0
  170. package/src/cli/migrate/yaml-report.ts +376 -0
  171. package/src/cli/migrate/yaml-rules.ts +465 -0
  172. package/src/cli/service-endpoint-check.ts +425 -0
  173. package/src/cli/source-path-check.d.mts +17 -0
  174. package/src/cli/source-path-check.mjs +334 -0
  175. package/src/cli/view-writes.ts +761 -0
  176. package/src/compile/action-host-attach.ts +21 -29
  177. package/src/compile/closed-set.ts +570 -0
  178. package/src/compile/compile-page.ts +267 -76
  179. package/src/compile/component-candidates.ts +13 -2
  180. package/src/compile/hints.ts +30 -1
  181. package/src/compile/index.ts +1 -0
  182. package/src/compile/kit-error.ts +1 -0
  183. package/src/compile/layout-lint/engine.ts +82 -0
  184. package/src/compile/layout-lint/index.ts +55 -0
  185. package/src/compile/layout-lint/rules-composition.ts +218 -0
  186. package/src/compile/layout-lint/rules-form.ts +192 -0
  187. package/src/compile/layout-lint/rules-table.ts +194 -0
  188. package/src/compile/layout-lint/score.ts +52 -0
  189. package/src/compile/layout-lint/types.ts +51 -0
  190. package/src/compile/locate.ts +21 -1
  191. package/src/compile/parse.ts +370 -41
  192. package/src/compile/redirect.ts +6 -2
  193. package/src/compile/remove-guard.ts +10 -7
  194. package/src/compile/styles.ts +63 -2
  195. package/src/compile/types.ts +31 -3
  196. package/src/compile/view-check.ts +284 -0
  197. package/src/data/amount-breakdown.ts +8 -3
  198. package/src/data/anchor-nav.ts +2 -2
  199. package/src/data/approval-flow.ts +3 -3
  200. package/src/data/assignment-picker.ts +92 -55
  201. package/src/data/async-result-panel.ts +111 -9
  202. package/src/data/breadcrumbs.ts +5 -4
  203. package/src/data/calendar.ts +24 -27
  204. package/src/data/carousel.ts +13 -8
  205. package/src/data/chart.ts +183 -44
  206. package/src/data/checklist.ts +20 -7
  207. package/src/data/code-view.ts +12 -6
  208. package/src/data/comment-thread.ts +7 -4
  209. package/src/data/confirm-dialog.ts +81 -18
  210. package/src/data/context-menu.ts +29 -37
  211. package/src/data/d9-util.ts +2 -18
  212. package/src/data/diff.ts +4 -2
  213. package/src/data/dock.ts +3 -3
  214. package/src/data/embed.ts +233 -30
  215. package/src/data/field-mapper.ts +35 -30
  216. package/src/data/flow-editor-contract.ts +8 -1
  217. package/src/data/flow-editor.ts +113 -108
  218. package/src/data/flow-node-options.ts +120 -0
  219. package/src/data/flow-remote-options.ts +0 -103
  220. package/src/data/footer.ts +2 -2
  221. package/src/data/form-draft-registry.ts +2 -4
  222. package/src/data/gantt.ts +19 -19
  223. package/src/data/hero.ts +4 -3
  224. package/src/data/image-viewer.ts +27 -30
  225. package/src/data/index.ts +5 -2
  226. package/src/data/item-list.ts +48 -31
  227. package/src/data/kanban.ts +82 -52
  228. package/src/data/media-grid.ts +20 -20
  229. package/src/data/mega-menu.ts +6 -4
  230. package/src/data/menu-dom.ts +4 -2
  231. package/src/data/menu.ts +47 -15
  232. package/src/data/mockup.ts +10 -6
  233. package/src/data/modal-dialog.ts +49 -25
  234. package/src/data/navbar.ts +12 -7
  235. package/src/data/notice-list.ts +268 -0
  236. package/src/data/notify-renderer.ts +250 -0
  237. package/src/data/object-form.ts +1360 -666
  238. package/src/data/outcome-watch.ts +61 -2
  239. package/src/data/pager.ts +80 -34
  240. package/src/data/permission-matrix.ts +52 -31
  241. package/src/data/permission-tree.ts +71 -44
  242. package/src/data/pricing-table.ts +30 -14
  243. package/src/data/prompt-dialog.ts +124 -194
  244. package/src/data/reaction-bar.ts +83 -92
  245. package/src/data/read-rollback.ts +73 -0
  246. package/src/data/record-card.ts +26 -5
  247. package/src/data/record-picker.ts +104 -55
  248. package/src/data/redirect.ts +32 -32
  249. package/src/data/remote-options.ts +13 -6
  250. package/src/data/request-console.ts +5 -3
  251. package/src/data/resident.ts +2 -1
  252. package/src/data/result-panel.ts +8 -4
  253. package/src/data/rich-text.ts +61 -55
  254. package/src/data/row-editor.ts +362 -76
  255. package/src/data/rule-builder.ts +26 -20
  256. package/src/data/shape-util.ts +27 -9
  257. package/src/data/stat-group.ts +392 -109
  258. package/src/data/static-lazy.ts +1 -0
  259. package/src/data/static-registry.ts +24 -11
  260. package/src/data/steps.ts +10 -5
  261. package/src/data/survey.ts +27 -32
  262. package/src/data/system-switcher.ts +3 -3
  263. package/src/data/text-action-button.ts +17 -0
  264. package/src/data/timeline.ts +19 -8
  265. package/src/data/tour-guide.ts +23 -30
  266. package/src/data/transfer.ts +62 -38
  267. package/src/data/tree-table.ts +152 -78
  268. package/src/data/tree.ts +49 -36
  269. package/src/data/trend-line.ts +6 -24
  270. package/src/data/virtual-rows.ts +133 -82
  271. package/src/data/watermark.ts +2 -2
  272. package/src/data/wrap.ts +63 -38
  273. package/src/data/wrapped-candidates.ts +10 -0
  274. package/src/frames/blank-frame.ts +1 -0
  275. package/src/frames/index.ts +2 -2
  276. package/src/frames/page-bar.ts +26 -24
  277. package/src/frames/page-header.ts +14 -5
  278. package/src/frames/page-status.ts +9 -7
  279. package/src/frames/shared.ts +36 -25
  280. package/src/frames/single-frame.ts +1 -0
  281. package/src/frames/split-frame/shell.ts +6 -6
  282. package/src/frames/split-frame/wiring.ts +2 -2
  283. package/src/frames/tabs-frame/shell.ts +4 -14
  284. package/src/frames/tabs-frame/wiring.ts +5 -8
  285. package/src/frames/top-main-frame.ts +3 -2
  286. package/src/frames/types.ts +13 -2
  287. package/src/frames/workspace-frame/extras.ts +21 -5
  288. package/src/frames/workspace-frame/index.ts +1 -1
  289. package/src/frames/workspace-frame/shell.ts +3 -2
  290. package/src/frames/workspace-frame/state.ts +13 -6
  291. package/src/frames/workspace-frame/view.ts +250 -48
  292. package/src/generated/kit-grammar-runtime.ts +645 -397
  293. package/src/generated/page-origin.ts +0 -11
  294. package/src/i18n/kit-text.ts +84 -29
  295. package/src/i18n/resolve-text-refs.ts +22 -6
  296. package/src/index.ts +2 -1
  297. package/src/object-renderer/action-gate.ts +11 -147
  298. package/src/object-renderer/arrange.ts +112 -84
  299. package/src/object-renderer/collapse-wiring.ts +2 -2
  300. package/src/object-renderer/collection-expand.ts +2 -2
  301. package/src/object-renderer/collection-parts.ts +401 -104
  302. package/src/object-renderer/collection-table.ts +287 -45
  303. package/src/object-renderer/collection.ts +258 -104
  304. package/src/object-renderer/compile-data.ts +112 -102
  305. package/src/object-renderer/crud-bridge.ts +32 -0
  306. package/src/object-renderer/defaults.ts +38 -16
  307. package/src/object-renderer/display-checks.ts +4 -25
  308. package/src/object-renderer/emit-events.ts +224 -176
  309. package/src/object-renderer/emit-object.ts +15 -2
  310. package/src/object-renderer/emit-static.ts +533 -151
  311. package/src/object-renderer/field-value.ts +593 -396
  312. package/src/object-renderer/filter-reload.ts +70 -0
  313. package/src/object-renderer/form-detail.ts +111 -2
  314. package/src/object-renderer/form-notify.ts +45 -0
  315. package/src/object-renderer/index.ts +26 -0
  316. package/src/object-renderer/key-field.ts +12 -0
  317. package/src/object-renderer/layout-facts.ts +386 -0
  318. package/src/object-renderer/layout-plan.ts +132 -0
  319. package/src/object-renderer/layout-plan.types.ts +22 -0
  320. package/src/object-renderer/linkage.ts +7 -270
  321. package/src/object-renderer/merge-class.ts +18 -1
  322. package/src/object-renderer/parts.ts +252 -1
  323. package/src/object-renderer/path-pick.ts +27 -0
  324. package/src/object-renderer/render-object.ts +456 -89
  325. package/src/object-renderer/request-actions.ts +232 -249
  326. package/src/object-renderer/skeleton.ts +58 -19
  327. package/src/object-renderer/table-actions.ts +319 -111
  328. package/src/object-renderer/table-summary.ts +2 -2
  329. package/src/object-renderer/table-tools.ts +429 -94
  330. package/src/object-renderer/types.ts +204 -127
  331. package/src/object-renderer/view-binding.ts +393 -0
  332. package/src/page-target/ai-surface.ts +37 -0
  333. package/src/page-target/compile.ts +48 -8
  334. package/src/page-target/index.ts +8 -1
  335. package/src/page-target/intent-schema.ts +165 -28
  336. package/src/page-target/target.ts +262 -51
  337. package/src/page-target/writer-policy.ts +14 -3
  338. package/src/recipes/container.ts +210 -0
  339. package/src/recipes/control.ts +277 -0
  340. package/src/recipes/index.ts +312 -0
  341. package/src/recipes/nowrap.ts +16 -0
  342. package/src/recipes/overlay.ts +240 -0
  343. package/src/recipes/placeholder.ts +79 -0
  344. package/src/recipes/rail-grid.ts +45 -0
  345. package/src/recipes/slot-align.ts +56 -0
  346. package/src/recipes/state.ts +99 -0
  347. package/src/recipes/status.ts +139 -0
  348. package/src/recipes/surface.ts +40 -0
  349. package/src/recipes/table-row.ts +88 -0
  350. package/src/recipes/title-row.ts +37 -0
  351. package/src/recipes/typography.ts +99 -0
  352. package/src/shared/action-field-guard.ts +41 -0
  353. package/src/shared/confirm-decl.ts +118 -0
  354. package/src/shared/envelope.ts +207 -0
  355. package/src/shared/escape.ts +57 -0
  356. package/src/shared/kit-error.ts +21 -0
  357. package/src/shared/paged-list-adapter.ts +15 -0
  358. package/src/shared/path-guard.ts +127 -0
  359. package/src/shared/theme-runtime-shared.ts +180 -0
  360. package/src/shared/view-info.ts +10 -0
  361. package/src/theme/index.ts +13 -0
  362. package/src/theme/kit-theme-text.ts +1 -1
  363. package/src/theme/kit-theme.css +407 -10
  364. package/src/theme/kit-theme.tpl +407 -10
  365. package/src/theme/nine-dim-structure.ts +247 -0
  366. package/src/theme/surface-layers.ts +101 -0
  367. package/src/theme/theme-tokens.ts +130 -84
  368. package/src/theme/theme-types.ts +103 -0
  369. package/src/theme/typography.ts +17 -17
  370. package/src/biz/shared/step-values.ts +0 -25
  371. package/src/biz/step-form/steps-ref.ts +0 -112
  372. package/src/data/options-bus.ts +0 -24
  373. package/src/object-renderer/adopt-gate.ts +0 -333
  374. package/src/object-renderer/field-policy.ts +0 -89
  375. package/src/object-renderer/outcome-draft.ts +0 -61
  376. package/src/theme/nine-dim-palettes.ts +0 -1473
@@ -24,9 +24,12 @@
24
24
  // 与 `change { value }`(value 为移动后的全部行,供 view.value 写回)。
25
25
  // 点卡片抛 `select { id, item }`。data 内容变化(内容签名变)才重置本地顺序。
26
26
 
27
- import type { SomaComponentControllerContext, SomaComponentDefinition, SomaDataPort } from 'soma-core';
28
- import { bool, findRoot, joinClass, str } from '../base/shared';
29
- import { kitText } from '../i18n/kit-text';
27
+ import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
28
+ import { bool, createKitController, joinClass, str } from '../base/shared';
29
+ import { kitKey, kitText } from '../i18n/kit-text';
30
+ import { createKeyboardWiring } from 'soma-core/keyboard';
31
+ import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
32
+ import { setKitFace } from '../recipes';
30
33
  import { provideCtxRows } from './context-menu';
31
34
 
32
35
  // ───────── 样式常量:Tailwind 类串与候选类清单 ─────────
@@ -40,15 +43,15 @@ const COUNT_CLASS = 'text-fg-muted';
40
43
  const COUNT_OVER_CLASS = 'font-medium text-danger-on-soft';
41
44
  const LANE_BODY_CLASS = 'flex min-h-16 flex-col gap-2 rounded-md';
42
45
  const DROP_CLASS = 'ring-2 ring-inset ring-ring';
43
- const CARD_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface p-3 text-sm text-fg shadow-xs transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
46
+ const CARD_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface p-3 text-sm text-fg shadow-xs transition-colors state-layer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
44
47
  const CARD_DRAG_CLASS = 'cursor-grab active:cursor-grabbing';
45
48
  const CARD_TITLE_CLASS = 'font-medium text-fg';
46
49
  const FACT_CLASS = 'flex items-baseline justify-between gap-2 text-xs text-fg-muted';
47
50
  const FACT_VALUE_CLASS = 'truncate text-fg';
48
51
  const EMPTY_CLASS = 'px-2 py-3 text-center text-sm text-fg-muted';
49
- const MOVE_BTN_CLASS = 'inline-flex h-7 items-center self-start rounded-md border border-border bg-surface px-2 text-xs text-fg hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
52
+ const MOVE_BTN_CLASS = 'inline-flex h-7 items-center self-start rounded-md border border-button-edge bg-surface px-4 text-xs text-fg state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
50
53
  const MENU_CLASS = 'flex flex-col gap-1 rounded-md border border-border bg-surface p-1';
51
- const MENU_ITEM_CLASS = 'flex h-7 items-center rounded-md px-2 text-start text-xs text-fg hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-subtle';
54
+ const MENU_ITEM_CLASS = 'flex h-7 items-center rounded-md px-2 text-start text-xs text-fg hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-subtle';
52
55
  const NOTICE_CLASS = 'rounded-md border border-border-subtle bg-warning-soft px-3 py-1.5 text-xs text-warning-on-soft';
53
56
  const HIDDEN_CLASS = 'hidden';
54
57
  const LIVE_CLASS = 'sr-only';
@@ -192,8 +195,8 @@ export function createKanban(): SomaComponentDefinition {
192
195
  },
193
196
  services: ['engines', 'data', 'notify'],
194
197
  templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
195
- controllerFactory: (ctx: SomaComponentControllerContext) => {
196
- const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
198
+ controllerFactory: createKitController((api) => {
199
+ const P = (): Record<string, unknown> => api.props();
197
200
  const uid = `kit-kanban-${++instanceCount}`;
198
201
  let root: HTMLElement | null = null;
199
202
  let noticeEl: HTMLElement | null = null;
@@ -217,11 +220,11 @@ export function createKanban(): SomaComponentDefinition {
217
220
  let armTimer: ReturnType<typeof setTimeout> | null = null;
218
221
  let offOutcome: (() => void) | null = null;
219
222
  const dataPort = (): SomaDataPort | undefined => {
220
- const port = (ctx.services as { data?: SomaDataPort } | undefined)?.data;
223
+ const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
221
224
  return port && typeof port === 'object' ? port : undefined;
222
225
  };
223
226
  const notifyPort = (): { toast?: (o: { level: string; message: string }) => void } | undefined =>
224
- (ctx.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
227
+ (api.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
225
228
 
226
229
  const config = (): KitKanbanConfig => {
227
230
  const p = P();
@@ -232,7 +235,7 @@ export function createKanban(): SomaComponentDefinition {
232
235
  const softWip = (): boolean => str(P().wip_mode) === 'soft';
233
236
  const idOf = (r: Row): string => str(r[idField()]);
234
237
  const dndPort = (): DragPortLike | null => {
235
- const engines = (ctx.services as { engines?: { dnd?: DragPortLike } } | undefined)?.engines;
238
+ const engines = (api.services as { engines?: { dnd?: DragPortLike } } | undefined)?.engines;
236
239
  return engines?.dnd ?? null;
237
240
  };
238
241
 
@@ -263,12 +266,12 @@ export function createKanban(): SomaComponentDefinition {
263
266
  const restore = first !== undefined && snapEpoch === epoch;
264
267
  clearTrack();
265
268
  const reason = message !== '' ? message
266
- : kitText(conflict ? 'soma.kit.order_unsaved_conflict' : 'soma.kit.order_unsaved_unknown', undefined, ctx.host);
267
- const text = kitText('soma.kit.order_unsaved', { reason }, ctx.host);
269
+ : kitText(conflict ? 'soma.kit.order_unsaved_conflict' : 'soma.kit.order_unsaved_unknown', undefined, api.host);
270
+ const text = kitText('soma.kit.order_unsaved', { reason }, api.host);
268
271
  if (restore && first !== undefined) {
269
272
  rows = first.map((r) => ({ ...r }));
270
273
  menuFor = null;
271
- ctx.emit('change', { value: rows.map((r) => ({ ...r })) });
274
+ api.emit('change', { value: rows.map((r) => ({ ...r })) });
272
275
  }
273
276
  showNotice(text);
274
277
  announce(text);
@@ -339,17 +342,17 @@ export function createKanban(): SomaComponentDefinition {
339
342
  if (from !== to && limit !== undefined && laneRows(cfg, to).length >= limit) {
340
343
  const laneLabel = cfg.lanes.find((l) => l.value === to)?.label ?? to;
341
344
  if (!softWip()) {
342
- const msg = kitText('soma.kit.wip_limit', { lane: laneLabel, n: limit }, ctx.host);
345
+ const msg = kitText('soma.kit.wip_limit', { lane: laneLabel, n: limit }, api.host);
343
346
  announce(msg);
344
347
  showNotice(msg);
345
- ctx.emit('wip_blocked', { id, to, limit });
348
+ api.emit('wip_blocked', { id, to, limit });
346
349
  return false;
347
350
  }
348
351
  // 软上限:只提示与抛事件,移入照常进行(超限的计数由 paint 标红)
349
- const msg = kitText('soma.kit.wip_exceeded', { lane: laneLabel, n: limit }, ctx.host);
352
+ const msg = kitText('soma.kit.wip_exceeded', { lane: laneLabel, n: limit }, api.host);
350
353
  announce(msg);
351
354
  showNotice(msg);
352
- ctx.emit('wip_exceeded', { id, to, limit });
355
+ api.emit('wip_exceeded', { id, to, limit });
353
356
  }
354
357
  const peers = laneRows(cfg, to).filter((r) => idOf(r) !== id);
355
358
  const position = Math.max(0, Math.min(index, peers.length));
@@ -367,7 +370,7 @@ export function createKanban(): SomaComponentDefinition {
367
370
  menuFor = null;
368
371
  tabKey = id;
369
372
  pendingFocus = id;
370
- ctx.emit('move', {
373
+ api.emit('move', {
371
374
  id, from, to, index: position,
372
375
  target: id,
373
376
  ...(orderField !== '' ? { orderField } : {}),
@@ -375,9 +378,9 @@ export function createKanban(): SomaComponentDefinition {
375
378
  set: { [cfg.group]: to },
376
379
  object: str(P().object),
377
380
  });
378
- ctx.emit('change', { value: rows.map((r) => ({ ...r })) });
381
+ api.emit('change', { value: rows.map((r) => ({ ...r })) });
379
382
  showNotice('');
380
- announce(kitText('soma.kit.moved_to', { lane: cfg.lanes.find((l) => l.value === to)?.label ?? to, n: position + 1 }, ctx.host));
383
+ announce(kitText('soma.kit.moved_to', { lane: cfg.lanes.find((l) => l.value === to)?.label ?? to, n: position + 1 }, api.host));
381
384
  paint();
382
385
  return true;
383
386
  };
@@ -410,9 +413,11 @@ export function createKanban(): SomaComponentDefinition {
410
413
  line.appendChild(el('span', FACT_VALUE_CLASS, str(v)));
411
414
  card.appendChild(line);
412
415
  }
413
- if (!hasDnd && !locked()) {
414
- const btn = el('button', MOVE_BTN_CLASS, str(P().move_label) || kitText('soma.kit.move_to', undefined, ctx.host));
416
+ // 移动菜单始终提供(WCAG 2.5.7:拖放之外必须有单指针替代;有拖放端口时也不隐藏)
417
+ if (!locked()) {
418
+ const btn = el('button', MOVE_BTN_CLASS, str(P().move_label) || kitText('soma.kit.move_to', undefined, api.host));
415
419
  btn.type = 'button';
420
+ setKitFace(btn, 'raised');
416
421
  btn.setAttribute('data-kit-move', id);
417
422
  btn.setAttribute('aria-haspopup', 'menu');
418
423
  btn.setAttribute('aria-expanded', menuFor === id ? 'true' : 'false');
@@ -451,7 +456,7 @@ export function createKanban(): SomaComponentDefinition {
451
456
  const cfg = config();
452
457
  const port = dndPort();
453
458
  const hasDnd = port !== null;
454
- const emptyText = str(p.empty_text, kitText('soma.kit.empty_card', undefined, ctx.host));
459
+ const emptyText = str(p.empty_text, kitText('soma.kit.empty_card', undefined, api.host));
455
460
  const keys = cardKeys(cfg);
456
461
  const all = keys.flat();
457
462
  if (tabKey === null || !all.includes(tabKey)) tabKey = all[0] ?? null;
@@ -525,6 +530,22 @@ export function createKanban(): SomaComponentDefinition {
525
530
  [...board.querySelectorAll<HTMLElement>('[data-kit-key]')].find((n) => n.getAttribute('data-kit-key') === id)?.focus();
526
531
  };
527
532
 
533
+ // 泳道内的纵向导航走 core 的共享键盘接线:集合 = 当前泳道的卡(按键前由 onKeydown 填),游标 = 焦点卡
534
+ let wireLane: string[] = [];
535
+ let wireCursor: string | null = null;
536
+ const laneWiring = createKeyboardWiring({
537
+ host: () => board,
538
+ contract: { layout: 'list', orientation: 'vertical', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
539
+ typeaheadDebounceMs: 0,
540
+ paging: {
541
+ listItems: SOMA_SIZE_UNITS.collection.keyboard.pageStep.listItems,
542
+ gridRows: SOMA_SIZE_UNITS.collection.keyboard.pageStep.gridRows,
543
+ },
544
+ items: () => wireLane.map((k) => ({ key: k, text: k })),
545
+ getCursor: () => wireCursor,
546
+ setCursor: (k) => focusCard(k),
547
+ });
548
+
528
549
  const onKeydown = (event: Event): void => {
529
550
  const e = event as KeyboardEvent;
530
551
  if (e.isComposing) return;
@@ -550,13 +571,14 @@ export function createKanban(): SomaComponentDefinition {
550
571
  if (li < 0) return;
551
572
  const ci = keys[li]!.indexOf(id);
552
573
  const lane = cfg.lanes[li]!.value;
553
- const key = e.key;
574
+ // 左右键按书写方向换向(RTL 下 ← 去后一条泳道);泳道内的上下 / Home / End / 翻页走共享键盘接线
575
+ const key = kitKey(e.key, root);
554
576
  if (key === 'Enter' || key === ' ') {
555
577
  e.preventDefault();
556
- ctx.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
578
+ api.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
557
579
  return;
558
580
  }
559
- if ((key === 'm' || key === 'M') && !e.altKey && !e.ctrlKey && !e.metaKey && !dndPort() && !locked()) {
581
+ if ((key === 'm' || key === 'M') && !e.altKey && !e.ctrlKey && !e.metaKey && !locked()) {
560
582
  e.preventDefault();
561
583
  menuFor = menuFor === id ? null : id;
562
584
  pendingFocus = menuFor === null ? id : null;
@@ -569,9 +591,9 @@ export function createKanban(): SomaComponentDefinition {
569
591
  }
570
592
  const horizontal = key === 'ArrowLeft' ? -1 : key === 'ArrowRight' ? 1 : 0;
571
593
  const vertical = key === 'ArrowUp' ? -1 : key === 'ArrowDown' ? 1 : 0;
572
- if (horizontal === 0 && vertical === 0) return;
573
- e.preventDefault();
574
594
  if (e.altKey) {
595
+ if (horizontal === 0 && vertical === 0) return;
596
+ e.preventDefault();
575
597
  if (horizontal !== 0) {
576
598
  const nl = cfg.lanes[li + horizontal];
577
599
  if (nl) move(id, nl.value, laneRows(cfg, nl.value).length);
@@ -580,7 +602,16 @@ export function createKanban(): SomaComponentDefinition {
580
602
  }
581
603
  return;
582
604
  }
583
- if (vertical !== 0) { focusCard(keys[li]![ci + vertical]); return; }
605
+ if (horizontal === 0) {
606
+ // 泳道内:↑ ↓ Home End PageUp PageDown 由共享接线(list / vertical,到边不回绕)决定落点,焦点经 setCursor 落到卡
607
+ if (e.ctrlKey || e.metaKey) return;
608
+ wireLane = keys[li]!;
609
+ wireCursor = id;
610
+ const handled = laneWiring.onKeydown(e);
611
+ if (handled || vertical !== 0) e.preventDefault();
612
+ return;
613
+ }
614
+ e.preventDefault();
584
615
  let nl = li + horizontal;
585
616
  while (nl >= 0 && nl < keys.length && keys[nl]!.length === 0) nl += horizontal;
586
617
  const col = keys[nl];
@@ -610,13 +641,13 @@ export function createKanban(): SomaComponentDefinition {
610
641
  if (cardEl) {
611
642
  const id = cardEl.getAttribute('data-kit-key')!;
612
643
  tabKey = id;
613
- ctx.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
644
+ api.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
614
645
  }
615
646
  };
616
647
 
617
648
  return {
618
- onMount(): void {
619
- root = findRoot(ctx.host);
649
+ attach(rootEl) {
650
+ root = rootEl;
620
651
  root.textContent = '';
621
652
  noticeEl = el('div', HIDDEN_CLASS);
622
653
  noticeEl.setAttribute('role', 'alert');
@@ -639,29 +670,28 @@ export function createKanban(): SomaComponentDefinition {
639
670
  if (port) offMove = port.onMove(intentMove);
640
671
  // 右键菜单(页面声明了 contextMenu 才有宿主壳):按卡主键取行
641
672
  removers.push(provideCtxRows(root, (key) => rows.find((r) => idOf(r) === key)));
642
- sync();
643
- paint();
673
+ return () => {
674
+ for (const fn of cleanups) fn();
675
+ cleanups = [];
676
+ for (const fn of removers) fn();
677
+ removers = [];
678
+ offMove?.();
679
+ offMove = null;
680
+ offOutcome?.();
681
+ offOutcome = null;
682
+ clearTrack();
683
+ root = null;
684
+ noticeEl = null;
685
+ board = null;
686
+ live = null;
687
+ };
644
688
  },
645
- onPropsChange(): void {
689
+ render(rootEl) {
690
+ root = rootEl;
646
691
  sync();
647
692
  paint();
648
693
  },
649
- onUnmount(): void {
650
- for (const fn of cleanups) fn();
651
- cleanups = [];
652
- for (const fn of removers) fn();
653
- removers = [];
654
- offMove?.();
655
- offMove = null;
656
- offOutcome?.();
657
- offOutcome = null;
658
- clearTrack();
659
- root = null;
660
- noticeEl = null;
661
- board = null;
662
- live = null;
663
- },
664
694
  };
665
- },
695
+ }),
666
696
  };
667
697
  }
@@ -6,8 +6,9 @@
6
6
  // 列数 `columns` 取 kit-grammar#dataLimits.mediaGrid.columns 闭集,窄容器固定 2 列,达到 md 档才用设定列数。
7
7
  // 点图片抛 `select { id, item }`;视频自带控件,不抛事件。
8
8
 
9
- import type { SomaComponentControllerContext, SomaComponentDefinition } from 'soma-core';
10
- import { joinClass, num, str } from '../base/shared';
9
+ import type { SomaComponentDefinition } from 'soma-core';
10
+ import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
11
+ import { createKitController, joinClass, num, str } from '../base/shared';
11
12
  import { classTokens, emptyNode, keyMap, mk, rowsOf, textOf } from './shape-util';
12
13
  import { rowKey, safeImgSrc } from './d9-util';
13
14
  import { kitText } from '../i18n/kit-text';
@@ -125,10 +126,9 @@ export function createMediaGrid(): SomaComponentDefinition {
125
126
  },
126
127
  },
127
128
  templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
128
- controllerFactory: (ctx: SomaComponentControllerContext) => {
129
- const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
129
+ controllerFactory: createKitController((api) => {
130
+ const P = (): Record<string, unknown> => api.props();
130
131
  let root: HTMLElement | null = null;
131
- let off: (() => void) | undefined;
132
132
 
133
133
  const itemNode = (e: KitMediaEntry, aspect: string, flow: boolean, withCaption: boolean): HTMLElement => {
134
134
  const box = mk('figure', ITEM_CLASS);
@@ -157,7 +157,11 @@ export function createMediaGrid(): SomaComponentDefinition {
157
157
  media = btn;
158
158
  }
159
159
  box.appendChild(media);
160
- if (withCaption && e.title !== '') box.appendChild(mk('figcaption', CAPTION_CLASS, e.title));
160
+ if (withCaption && e.title !== '') {
161
+ const caption = mk('figcaption', CAPTION_CLASS, e.title);
162
+ caption.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
163
+ box.appendChild(caption);
164
+ }
161
165
  return box;
162
166
  };
163
167
 
@@ -217,30 +221,26 @@ export function createMediaGrid(): SomaComponentDefinition {
217
221
  };
218
222
 
219
223
  return {
220
- onMount(): void {
221
- root = ctx.host.querySelector<HTMLElement>('[data-soma-scoped-id="root"]')
222
- ?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
223
- ?? ctx.host;
224
+ attach(rootEl) {
225
+ root = rootEl;
224
226
  const r = root;
225
227
  const onClick = (event: Event): void => {
226
228
  const key = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-pick]')?.getAttribute('data-kit-pick');
227
229
  if (key === null || key === undefined) return;
228
230
  const hit = mediaEntriesOf(P().data, P().map).find((e) => e.key === key);
229
- if (hit) ctx.emit('select', { id: hit.key, item: hit.raw });
231
+ if (hit) api.emit('select', { id: hit.key, item: hit.raw });
230
232
  };
231
233
  r.addEventListener('click', onClick);
232
- off = () => r.removeEventListener('click', onClick);
233
- paint();
234
+ return () => {
235
+ r.removeEventListener('click', onClick);
236
+ root = null;
237
+ };
234
238
  },
235
- onPropsChange(): void {
239
+ render(rootEl) {
240
+ root = rootEl;
236
241
  paint();
237
242
  },
238
- onUnmount(): void {
239
- off?.();
240
- off = undefined;
241
- root = null;
242
- },
243
243
  };
244
- },
244
+ }),
245
245
  };
246
246
  }
@@ -13,14 +13,16 @@ import { kitKey, kitText } from '../i18n/kit-text';
13
13
  import { safeHref } from '../base/link';
14
14
  import { KIT_DROPDOWN_CLASS_CANDIDATES, queryWithDropdowns, releaseDropdownsIn, syncDropdown } from '../base/popup';
15
15
  import { attrEsc } from './d9-util';
16
+ import { mergeClass } from '../object-renderer/merge-class';
17
+ import { kitSurfaceRecipe } from '../recipes/surface';
16
18
  import { classSet, FOCUS, h, isRec, onOutsidePointer, recList, textOf, type Rec } from './menu-dom';
17
19
 
18
20
  const ROOT_CLASS = 'relative flex flex-wrap items-center gap-1 text-sm text-fg';
19
- const TRIGGER_CLASS = `inline-flex h-9 cursor-pointer items-center gap-1 rounded-md px-3 text-sm font-medium text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg ${FOCUS}`;
20
- const TRIGGER_OPEN_CLASS = `inline-flex h-9 cursor-pointer items-center gap-1 rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft ${FOCUS}`;
21
+ const TRIGGER_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md px-3 text-sm font-medium text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg ${FOCUS}`;
22
+ const TRIGGER_OPEN_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft ${FOCUS}`;
21
23
  const CARET_CLASS = 'inline-flex';
22
24
  // 位置类由 popup.ts 的 syncDropdown 贴边翻转时拼上(默认 left-0 top-full mt-1)
23
- const PANEL_BASE_CLASS = 'absolute z-30 flex w-max max-w-full flex-col gap-3 rounded-lg border border-border-subtle bg-surface-raised p-4 shadow-lg motion-safe:animate-kit-menu-in';
25
+ const PANEL_BASE_CLASS = mergeClass('absolute z-30 flex w-max max-w-full flex-col gap-3 p-4', kitSurfaceRecipe('raised'));
24
26
  const PANEL_CLASS = `${PANEL_BASE_CLASS} start-0 top-full mt-1`;
25
27
  const GRID_CLASS: Record<number, string> = {
26
28
  1: 'grid grid-cols-1 gap-6',
@@ -30,7 +32,7 @@ const GRID_CLASS: Record<number, string> = {
30
32
  };
31
33
  const COLUMN_CLASS = 'flex min-w-40 flex-col gap-1';
32
34
  const COLUMN_TITLE_CLASS = 'px-3 pb-1 text-xs font-semibold text-fg-subtle';
33
- const ITEM_CLASS = `flex w-full cursor-pointer flex-col gap-0.5 rounded-md px-3 py-2 text-start transition-colors hover:bg-surface-sunken ${FOCUS}`;
35
+ const ITEM_CLASS = `flex w-full cursor-pointer flex-col gap-0.5 rounded-md px-3 py-2 text-start transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${FOCUS}`;
34
36
  const ITEM_DISABLED_CLASS = 'flex w-full cursor-not-allowed flex-col gap-0.5 rounded-md px-3 py-2 text-start text-fg-subtle opacity-60';
35
37
  const ITEM_HEAD_CLASS = 'flex items-center justify-between gap-2';
36
38
  const ITEM_LABEL_CLASS = 'min-w-0 truncate text-sm font-medium text-fg';
@@ -2,6 +2,8 @@
2
2
  // 全部纯函数或无状态:建元素、类串拆候选、记录读取、下拉菜单(弹层 + 焦点进入 / 回焦 / Esc / 点外面关)。
3
3
 
4
4
  import { KIT_DROPDOWN_CLASS_CANDIDATES, dropdownOwnerOf, syncDropdown } from '../base/popup';
5
+ import { mergeClass } from '../object-renderer/merge-class';
6
+ import { kitSurfaceRecipe } from '../recipes/surface';
5
7
 
6
8
  export type Child =Node | string | null | undefined | false;
7
9
 
@@ -76,14 +78,14 @@ export interface KitDropdownItem {
76
78
  }
77
79
 
78
80
  // 外观类;位置类(默认右对齐、下方)由 popup.ts 的 syncDropdown 贴边翻转时拼上
79
- const DROP_BASE = 'absolute z-30 flex min-w-40 flex-col rounded-lg border border-border-subtle bg-surface-raised p-1 shadow-lg motion-safe:animate-kit-menu-in';
81
+ const DROP_BASE = mergeClass('absolute z-30 flex min-w-40 flex-col p-1', kitSurfaceRecipe('raised'));
80
82
  const DROP_BOX = `${DROP_BASE} end-0 top-full mt-1.5`;
81
83
 
82
84
  /** 下拉面板已挂进 relative 容器之后调用:贴边翻转(上 / 下、左 / 右端),空间都不够时取较大侧并内部滚动 */
83
85
  export function fitDropdownPanel(panel: HTMLElement): void {
84
86
  syncDropdown(panel, true, DROP_BASE, undefined, 'end');
85
87
  }
86
- const DROP_ITEM = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg transition-colors hover:bg-fg/8 active:bg-fg/12 ${FOCUS_INSET}`;
88
+ const DROP_ITEM = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${FOCUS_INSET}`;
87
89
  const DROP_ITEM_DISABLED = 'flex h-9 w-full cursor-not-allowed items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg-subtle opacity-60';
88
90
  const DROP_ITEM_DANGER = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-danger-on-soft transition-colors hover:bg-danger-soft ${FOCUS_INSET}`;
89
91
  const DROP_SEP = 'my-1 h-px w-full bg-border-subtle';
package/src/data/menu.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  // - divider: true 的项是「分隔线」:只画一条线,不可聚焦、不可选;
6
6
  // - 带 children 的项是可折叠分支,点击展开 / 折叠;openable: true 的分支点击时同时选中(抛 select);
7
7
  // - open: true 的分支初始展开;
8
- // - icon 是一个短字符(emoji 或符号),缺省收起态取标签首字;badge 是徽标文字或数字。
8
+ // - icon 可写 kit 图标名(home / user / users / key / shield / file / sparkles 等 kitIcon 名,画 SVG),
9
+ // 或一个短字符(emoji 或符号,原样画);缺省收起态取标签首字;badge 是徽标文字或数字。
9
10
  // `map` 改写键名(组件期望的键 -> 数据里的键)。当前项由 `selected`(id)给出,祖先分支自动展开;
10
11
  // `collapsed` 为真时收成仅图标窄栏:只画一级项,分支点击抛 toggle { rail: true } 交宿主决定(通常是展开侧栏)。
11
12
  // 键盘走 core 键盘接线(layout: tree):↑↓ 走可见项,→ 展开 / 进入子项,← 折叠 / 回父项,Home / End,Enter / Space 选中。
@@ -16,8 +17,9 @@ import { kitText } from '../i18n/kit-text';
16
17
  import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
17
18
  import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
18
19
  import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
20
+ import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
19
21
  import { bool, createKitController, joinClass, str } from '../base/shared';
20
- import { kitIcon } from '../base/icons';
22
+ import { KIT_ICON_NAMES, kitIcon, type KitIconName } from '../base/icons';
21
23
  import { classSet, cssEscape, firstChar, h, isRec, textOf, type Rec } from './menu-dom';
22
24
  import { mountKitMegaMenu } from './mega-menu';
23
25
 
@@ -26,16 +28,35 @@ import { mountKitMegaMenu } from './mega-menu';
26
28
  const ROOT_CLASS = 'flex flex-col text-sm text-fg';
27
29
  const LIST_CLASS = 'flex flex-col gap-1';
28
30
  const LIST_RAIL_CLASS = 'flex flex-col items-center gap-1';
29
- const GROUP_CLASS = 'flex flex-col gap-1 ps-3';
31
+ // 子项文字相对父级文字缩进一档(评审 S2:子项不得比父级更靠左):父项有图标时,父级文字起点 = 行内边距 3 + 图标 5 + 间距 2 = 10 个间距单位,
32
+ // 子项行自带 3 的内边距,所以子容器 ps-11(10 + 4 - 3)让子文字落在父文字右侧 4 个单位;父项无图标时父文字起点是 3,子容器 ps-4。
33
+ const GROUP_CLASS = 'flex flex-col gap-1 ps-4';
34
+ const GROUP_ICON_CLASS = 'flex flex-col gap-1 ps-11';
30
35
  const ITEM_CLASS = 'flex flex-col gap-1 rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
31
36
  const ITEM_RAIL_CLASS = 'flex w-full flex-col rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
32
- const ROW_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md px-3 text-sm text-fg-muted transition-colors hover:bg-fg/8 active:bg-fg/12 hover:text-fg';
37
+ const ROW_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md px-3 text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg';
33
38
  const ROW_ACTIVE_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft';
34
39
  const ROW_DISABLED_CLASS = 'flex h-9 cursor-not-allowed items-center gap-2 rounded-md px-3 text-sm text-fg-subtle opacity-60';
35
- const ROW_RAIL_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md text-sm text-fg-muted transition-colors hover:bg-fg/8 active:bg-fg/12 hover:text-fg';
40
+ const ROW_RAIL_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg';
36
41
  const ROW_RAIL_ACTIVE_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md bg-primary-soft text-sm font-medium text-primary-on-soft';
37
42
  const HEADING_CLASS = 'px-3 pb-1 pt-3 text-xs font-semibold text-fg-subtle';
38
43
  const ICON_CLASS = 'w-5 shrink-0 text-center';
44
+ /** icon 写 kit 图标名时画 SVG:容器居中,不依赖字符基线 */
45
+ const ICON_SVG_CLASS = 'flex w-5 shrink-0 items-center justify-center';
46
+
47
+ /** icon 是 kit 图标名(KitIconName)则返回它,否则 null(仍按短字符原样画,兼容 emoji / 符号 / ≤2 字文本) */
48
+ export function menuIconNameOf(icon: string): KitIconName | null {
49
+ return (KIT_ICON_NAMES as readonly string[]).includes(icon) ? (icon as KitIconName) : null;
50
+ }
51
+
52
+ /** 菜单项图标节点:图标名 → SVG;其余 → 文本(空串返回 null) */
53
+ function menuIconNode(icon: string): HTMLElement | null {
54
+ if (icon === '') return null;
55
+ const name = menuIconNameOf(icon);
56
+ return name !== null
57
+ ? h('span', ICON_SVG_CLASS, { 'aria-hidden': 'true' }, kitIcon(name, 'md'))
58
+ : h('span', ICON_CLASS, { 'aria-hidden': 'true' }, icon);
59
+ }
39
60
  const LABEL_CLASS = 'min-w-0 flex-1 truncate';
40
61
  const CARET_CLASS = 'w-4 shrink-0 text-center text-xs text-fg-subtle';
41
62
  const BADGE_CLASS = 'shrink-0 rounded-full bg-surface-sunken px-2 text-xs font-medium text-fg-muted';
@@ -46,9 +67,9 @@ const SEP_CLASS = 'my-1 h-px w-full bg-border-subtle';
46
67
 
47
68
  /** 本组件自带的全部类(供编译器并入候选类) */
48
69
  export const KIT_MENU_CLASS_CANDIDATES: readonly string[] = classSet(
49
- ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS, ITEM_CLASS, ITEM_RAIL_CLASS, ROW_CLASS, ROW_ACTIVE_CLASS, ROW_DISABLED_CLASS,
70
+ ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS, GROUP_ICON_CLASS, ITEM_CLASS, ITEM_RAIL_CLASS, ROW_CLASS, ROW_ACTIVE_CLASS, ROW_DISABLED_CLASS,
50
71
  ROW_RAIL_CLASS, ROW_RAIL_ACTIVE_CLASS, HEADING_CLASS, ICON_CLASS, LABEL_CLASS, CARET_CLASS, BADGE_CLASS, BADGE_PRIMARY_CLASS,
51
- BADGE_DANGER_CLASS, BADGE_ACTIVE_CLASS, SEP_CLASS,
72
+ BADGE_DANGER_CLASS, BADGE_ACTIVE_CLASS, SEP_CLASS, ICON_SVG_CLASS,
52
73
  );
53
74
 
54
75
  // ───────── 数据规整纯函数:键名对照、节点树、祖先链、可见项 ─────────
@@ -209,6 +230,8 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
209
230
  let cursor: string | null = null;
210
231
  let selected = '';
211
232
  let lastGiven: string | null = null;
233
+ /** 手风琴:上一次选中项所在的一级分支('' = 选中的是一级叶子或没有选中);null = 还没选过 */
234
+ let lastTop: string | null = null;
212
235
  let dataSig = '';
213
236
  let rail = false;
214
237
  let props: Rec = {};
@@ -287,6 +310,7 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
287
310
  sig = `cyclic:${Math.random()}`;
288
311
  }
289
312
  const expandAll = bool(props.expand_all);
313
+ const accordion = bool(props.accordion);
290
314
  if (sig !== dataSig) {
291
315
  dataSig = sig;
292
316
  nodes = buildMenuNodes(props.data, map);
@@ -306,7 +330,14 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
306
330
  if (given !== lastGiven) {
307
331
  lastGiven = given;
308
332
  selected = given;
309
- for (const a of menuAncestors(nodes, given)) open.add(a);
333
+ const trail = menuAncestors(nodes, given);
334
+ // 手风琴:选中项落进另一个一级分支(或一级叶子)时,先收起其余分支;同一分支内换项、用户手动展开的分支都保留
335
+ if (accordion && given !== '') {
336
+ const top = trail[0] ?? '';
337
+ if (top !== lastTop) open.clear();
338
+ lastTop = top;
339
+ }
340
+ for (const a of trail) open.add(a);
310
341
  }
311
342
  rail = bool(props.collapsed);
312
343
  };
@@ -336,20 +367,20 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
336
367
  let row: HTMLElement;
337
368
  if (rail) {
338
369
  row = h('div', active ? ROW_RAIL_ACTIVE_CLASS : ROW_RAIL_CLASS, {},
339
- h('span', '', { 'aria-hidden': 'true' }, n.icon !== '' ? n.icon : firstChar(n.label)));
370
+ menuIconNode(n.icon) ?? h('span', '', { 'aria-hidden': 'true' }, firstChar(n.label)));
340
371
  } else {
341
372
  const badgeClass = active ? BADGE_ACTIVE_CLASS
342
373
  : n.badgeTone === 'danger' ? BADGE_DANGER_CLASS
343
374
  : n.badgeTone === 'primary' ? BADGE_PRIMARY_CLASS : BADGE_CLASS;
344
375
  row = h('div', n.disabled ? ROW_DISABLED_CLASS : active ? ROW_ACTIVE_CLASS : ROW_CLASS, {},
345
- n.icon !== '' ? h('span', ICON_CLASS, { 'aria-hidden': 'true' }, n.icon) : null,
346
- h('span', LABEL_CLASS, {}, n.label),
376
+ menuIconNode(n.icon),
377
+ h('span', LABEL_CLASS, { [KIT_TIPS_SCOPE_ATTR]: '' }, n.label),
347
378
  n.badge !== '' ? h('span', badgeClass, { 'data-kit-badge': '' }, n.badge) : null,
348
379
  branch ? h('span', CARET_CLASS, { 'aria-hidden': 'true', 'data-kit-toggle': '' }, kitIcon(isOpen ? 'chevron-down' : 'chevron-right', 'sm', 'rtl:-scale-x-100')) : null);
349
380
  }
350
381
  li.append(row);
351
382
  if (isOpen) {
352
- const group = h('ul', GROUP_CLASS, { role: 'group' });
383
+ const group = h('ul', n.icon !== '' ? GROUP_ICON_CLASS : GROUP_CLASS, { role: 'group' });
353
384
  for (const child of n.children) for (const node of buildItem(child, tabbable)) group.append(node);
354
385
  li.append(group);
355
386
  }
@@ -413,9 +444,10 @@ export function createMenu(): SomaComponentDefinition {
413
444
  layer: 'data',
414
445
  props: {
415
446
  layout: { type: 'enum', values: ['tree', 'columns'], default: 'tree', desc: 'tree = 多级菜单(侧栏式);columns = 多列下拉导航(data 为触发钮数组 [{ id, label, columns[{ title?, items[{ id, label, desc?, href?, badge?, disabled? }] }], footer? }])' },
416
- data: { type: 'array', default: [], desc: '菜单数据 [{ id, label, icon?, badge?, badge_tone?, href?, disabled?, openable?, group?, open?, children? }];group 为分组标题。layout=columns 时见 layout' },
447
+ data: { type: 'array', default: [], desc: '菜单数据 [{ id, label, icon?, badge?, badge_tone?, href?, disabled?, openable?, group?, open?, children? }];group 为分组标题;icon 可写 kit 图标名(画 SVG)或短字符。layout=columns 时见 layout' },
417
448
  map: { type: 'object', default: {}, desc: '键名对照 { id, label, children, icon, badge, href }:组件期望的键 -> 数据里的键' },
418
449
  selected: { type: 'string', default: '', desc: '当前项 id;祖先分支自动展开' },
450
+ accordion: { type: 'boolean', default: false, desc: '手风琴:选中项变化时只展开其所在的一级分支(其余收起);用户手动展开的分支保留,直到选中项落进另一个一级分支。工作台侧栏默认开启(sidebar.accordion),独立 Menu 缺省关闭' },
419
451
  collapsed: { type: 'boolean', default: false, desc: '收起成仅图标窄栏(只画一级,分支点击抛 toggle { rail: true })' },
420
452
  expand_all: { type: 'boolean', default: false, desc: '初始全部展开' },
421
453
  label: { type: 'string', default: '', desc: '导航区域的可访问名;缺省取内置文案(按页面语言)' },
@@ -430,7 +462,7 @@ export function createMenu(): SomaComponentDefinition {
430
462
  keyboard: { layout: 'tree', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
431
463
  },
432
464
  templateHtml: `<nav data-soma-id="root" class="${ROOT_CLASS}"></nav>`,
433
- controllerFactory: createKitController({
465
+ controllerFactory: createKitController(() => ({
434
466
  attach(root, api) {
435
467
  // 一个基准、两种布局:layout 变了就拆掉旧挂载换新的
436
468
  let cur: { layout: string; handle: KitMenuHandle } | null = null;
@@ -459,6 +491,6 @@ export function createMenu(): SomaComponentDefinition {
459
491
  render(root, p) {
460
492
  HANDLES.get(root)?.update(p);
461
493
  },
462
- }),
494
+ })),
463
495
  };
464
496
  }
@@ -8,6 +8,7 @@
8
8
  // 纯展示,无事件。
9
9
 
10
10
  import type { SomaComponentDefinition } from 'soma-core';
11
+ import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
11
12
  import { createKitController, joinClass, num, str } from '../base/shared';
12
13
  import { kitText } from '../i18n/kit-text';
13
14
  import { classTokens, emptyNode, mk, shapeToneOf, textOf, TONE_SOFT, type Rec, type ShapeTone } from './shape-util';
@@ -111,7 +112,7 @@ export function createMockup(): SomaComponentDefinition {
111
112
  emits: {},
112
113
  },
113
114
  templateHtml: `<figure data-soma-id="root" class="${ROOT_CLASS}"></figure>`,
114
- controllerFactory: createKitController({
115
+ controllerFactory: createKitController(() => ({
115
116
  render(root, p) {
116
117
  root.className = joinClass(ROOT_CLASS, p.class);
117
118
  root.textContent = '';
@@ -120,7 +121,7 @@ export function createMockup(): SomaComponentDefinition {
120
121
  root.setAttribute('data-kit-variant', variant);
121
122
  if (variant === 'code') {
122
123
  const lines = mockupLinesOf(src.lines, num(p.start) ?? 1);
123
- if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)))); return; }
124
+ if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true)); return; }
124
125
  const frame = mk('div', CODE_CLASS);
125
126
  const bar = mk('div', BAR_CLASS);
126
127
  const dots = mk('div', DOTS_CLASS);
@@ -147,7 +148,7 @@ export function createMockup(): SomaComponentDefinition {
147
148
  const frame = mk('div', PHONE_CLASS);
148
149
  frame.appendChild(mk('div', NOTCH_CLASS));
149
150
  const screen = mk('div', SCREEN_CLASS);
150
- if (body) screen.appendChild(body); else screen.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
151
+ if (body) screen.appendChild(body); else screen.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true));
151
152
  frame.appendChild(screen);
152
153
  root.appendChild(frame);
153
154
  return;
@@ -160,17 +161,20 @@ export function createMockup(): SomaComponentDefinition {
160
161
  if (variant === 'browser') {
161
162
  const address = mk('div', ADDRESS_CLASS, textOf(src.url));
162
163
  address.setAttribute('data-kit-address', '');
164
+ address.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
163
165
  bar.appendChild(address);
164
166
  } else {
165
- bar.appendChild(mk('div', TITLE_CLASS, textOf(src.title)));
167
+ const barTitle = mk('div', TITLE_CLASS, textOf(src.title));
168
+ barTitle.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
169
+ bar.appendChild(barTitle);
166
170
  bar.appendChild(mk('span', SPACER_CLASS));
167
171
  }
168
172
  frame.appendChild(bar);
169
173
  const area = mk('div', BODY_CLASS);
170
- if (body) area.appendChild(body); else area.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
174
+ if (body) area.appendChild(body); else area.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true));
171
175
  frame.appendChild(area);
172
176
  root.appendChild(frame);
173
177
  },
174
- }),
178
+ })),
175
179
  };
176
180
  }