soma-kit 0.1.15 → 0.1.17

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 +935 -93
  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 +188 -62
  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 +152 -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 +1016 -54
  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 +423 -104
  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
@@ -10,18 +10,22 @@
10
10
  import type { SomaComponentDefinition } from 'soma-core';
11
11
  import {
12
12
  CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
13
- applyCompositeField, applyDisabled, bool, createKitController, formatValue, joinClass, num, setAttr, sizeOf, str,
13
+ applyCompositeField, applyDisabled, bool, classCandidates, createKitController, formatValue, joinClass, kitControlSizeOf, kitMarkDataState, kitMarkInteract, kitReportSelf, num, reconcileKeyedElements, setAttr, str,
14
14
  type KitApi, type KitProps, type KitSize,
15
15
  } from './shared';
16
16
  import { safeSrc } from './avatar';
17
17
  import { kitLocaleAt, kitText } from '../i18n/kit-text';
18
- import { kitIcon } from '../shared/icons';
18
+ import { kitIcon, KIT_ICON_CLASS_CANDIDATES } from '../shared/icons';
19
19
  import { setKitFace } from '../recipes';
20
20
  import { kitControlEdgeRecipe } from '../recipes/control';
21
- import { kitDivideRecipe } from '../recipes/divider';
21
+ import { kitDropTargetRecipe, kitFocusRingRecipe } from '../recipes/state';
22
22
  import { kitShellRecipe } from '../recipes/container';
23
- import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
23
+ import { kitActionRecipe, kitEmphasisButtonRecipe } from '../recipes/emphasis';
24
+ import { kitMiniBarNode, clampPercent } from './progress';
24
25
  import { mergeClass } from '../shared/merge-class';
26
+ import { kitWellRecipe } from '../recipes/surface';
27
+ import { kitClosedValueTone } from '../recipes/field-text';
28
+ import { KIT_ATTR_ADD, KIT_ATTR_CANCEL, KIT_ATTR_REMOVE, KIT_ATTR_RETRY, KIT_ATTR_START, KIT_ATTR_STATUS } from '../shared/dom-attrs';
25
29
 
26
30
  type FileStatus = 'pending' | 'uploading' | 'done' | 'error';
27
31
  type RejectReason = 'type' | 'size' | 'count';
@@ -29,13 +33,45 @@ type RejectReason = 'type' | 'size' | 'count';
29
33
  interface FileItem {
30
34
  name: string;
31
35
  size?: number;
36
+ type?: string;
32
37
  status?: FileStatus;
33
38
  percent?: number;
34
39
  url?: string;
40
+ thumbnail?: string;
35
41
  [extra: string]: unknown;
36
42
  }
37
43
 
38
- const ROOT_CLASS = 'flex w-full flex-col gap-2';
44
+ const IMAGE_EXT_RE = /\.(?:png|jpe?g|gif|webp|svg|avif|bmp|ico)$/i;
45
+ const ANY_EXT_RE = /\.[a-z0-9]{1,8}$/i;
46
+
47
+ /** 仅当文件项为图片(显式 thumbnail / data:image / image/* MIME / 图片扩展名)时返回安全缩略图地址,避免对 .pdf 等非图片 url 发起无谓 404 请求 */
48
+ function imageThumbSrc(item: FileItem): string {
49
+ if (typeof item.thumbnail === 'string' && item.thumbnail !== '') {
50
+ const thumb = safeSrc(item.thumbnail);
51
+ if (thumb !== '') return thumb;
52
+ }
53
+ if (typeof item.url !== 'string' || item.url === '') return '';
54
+ const src = safeSrc(item.url);
55
+ if (src === '') return '';
56
+ if (/^data:image\//i.test(src)) return src;
57
+ const mime = (
58
+ typeof item.type === 'string' && item.type !== ''
59
+ ? item.type
60
+ : typeof File !== 'undefined' && item.file instanceof File
61
+ ? item.file.type
62
+ : ''
63
+ ).toLowerCase();
64
+ if (mime.startsWith('image/')) return src;
65
+ if (mime !== '') return '';
66
+ const path = src.split(/[?#]/, 1)[0] ?? '';
67
+ if (IMAGE_EXT_RE.test(path)) return src;
68
+ const lastSeg = path.slice(path.lastIndexOf('/') + 1);
69
+ if (ANY_EXT_RE.test(lastSeg)) return '';
70
+ return IMAGE_EXT_RE.test(item.name) ? src : '';
71
+ }
72
+
73
+ // 根内段距 16(拖拽区 / 按钮与文件列表间距,组件卡 Upload §7);锁死 min-w-0 max-w-full overflow-hidden 防止窄舞台/touch-pill 向邻列右溢(PW-1 R1-P1-04)
74
+ const ROOT_CLASS = 'flex w-full min-w-0 max-w-full flex-col gap-4 overflow-hidden';
39
75
  const PICK_CLASS: Record<KitSize, string> = {
40
76
  // 选择文件钮 = 带文字的中性按钮:直接取按钮配方(描边走按钮描边令牌,随边界维度求解),只补「按内容收窄 + 手形光标」
41
77
  sm: mergeClass(kitEmphasisButtonRecipe('button.toolbar', { size: 'sm' }), 'w-fit cursor-pointer'),
@@ -44,59 +80,96 @@ const PICK_CLASS: Record<KitSize, string> = {
44
80
  };
45
81
  // 投放区:静止 / 拖入高亮 / 禁用,各一整串
46
82
  // 投放区与「+」添加格是控件(投放目标):边 = 控件轮廓出口(KT-B1 / §4 C6)+ 虚线;拖入 / 悬停变主色(强调指示)
83
+ // 焦点环走唯一出口(KT-K0-3:块 = 2px 环外偏移 2)
84
+ const UP_FOCUS = kitFocusRingRecipe('button');
47
85
  const DROP_LINE = kitControlEdgeRecipe({ wrapper: true, hover: false });
48
86
  const DROP_EDGE = `${DROP_LINE} border-dashed`;
49
87
  const DROP_CLASS = {
50
- idle: `flex w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg ${DROP_EDGE} bg-surface px-4 py-6 text-sm text-fg-muted transition-colors hover:border-primary state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,
51
- over: 'flex w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-primary bg-primary-soft px-4 py-6 text-sm text-primary-on-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
52
- disabled: `flex w-full cursor-not-allowed flex-col items-center justify-center gap-1 rounded-lg ${DROP_EDGE} bg-surface-sunken px-4 py-6 text-sm text-fg-subtle opacity-60`,
88
+ // 取值表 01 §12.1(Ant dragger.ts / Arco / TDesign):内边距上下 32 左右 16、最小高 144、1 虚线中性边、圆角 lg、极浅中性底(surface-sunken);
89
+ // 悬停边 + 底变主色浅底(拖入态同);主文字 14 正文墨,提示 12 弱化墨上距 4,图标主色下距 12
90
+ idle: mergeClass(
91
+ mergeClass(`flex min-h-36 w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-card ${DROP_EDGE}`, kitWellRecipe()),
92
+ `px-4 py-8 text-sm text-fg transition-colors state-layer ${UP_FOCUS}`,
93
+ ),
94
+ over: mergeClass(
95
+ mergeClass('flex min-h-36 w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-card', kitDropTargetRecipe()),
96
+ `px-4 py-8 text-sm ${UP_FOCUS}`,
97
+ ),
98
+ disabled: `flex min-h-36 w-full cursor-not-allowed flex-col items-center justify-center gap-1 rounded-card ${DROP_EDGE} bg-control-disabled px-4 py-8 text-sm text-fg-disabled`,
53
99
  } as const;
54
- const HINT_CLASS = 'text-xs text-fg-subtle';
100
+ // 展示图标 32(真源 icons.sizes.display),下距 16、主色
101
+ const DROP_ICON_CLASS = 'mb-4 text-primary';
102
+ const DROP_ICON_DISABLED_CLASS = 'mb-4';
103
+ const HINT_CLASS = 'min-w-0 text-xs text-fg-subtle';
55
104
  const REJECT_NOTE_CLASS = 'text-danger-on-soft';
56
105
  // 无 preflight:ul 默认的圆点与缩进要自己清掉
57
- // 文件列表 = 一个列表框(壳配方的容器边,KT-B2),文件行之间的线由父出(kitDivideRecipe,KT-B5),行自己不描边
58
- const LIST_CLASS = mergeClass('m-0 flex list-none flex-col p-0 overflow-hidden', `${kitShellRecipe({ tone: 'base', shadow: false })} ${kitDivideRecipe('y')}`);
59
- const ITEM_CLASS = 'flex items-center gap-2 bg-surface px-3 py-2 text-sm text-fg';
60
- const THUMB_CLASS = 'h-8 w-8 shrink-0 rounded-md object-cover';
106
+ // 文件列表 = 无框列表(Ant upload-list,每条边只有一个所有者:列表放进面里时外框归面,列表自己不画盒):
107
+ // 外层不画框不画底,行与行之间只留 8 的间距,靠悬停浅填充区分(组件卡 Upload §7)
108
+ const LIST_CLASS = 'm-0 flex min-w-0 max-w-full list-none flex-col gap-2 p-0';
109
+ // 取值表 01 §12.2:文件行 = 上下 5 + 行高 22 = 32、左右 12、图标与文字 8、悬停中性浅填充(行在列表框内,悬停只换底不加边)
110
+ const ITEM_CLASS = 'flex min-w-0 max-w-full items-center gap-2 overflow-hidden rounded-item px-3 py-1.25 text-sm text-fg transition-colors hover:bg-state-layer-hover';
111
+ // 媒体缩略图使用非 pill 语义圆角 rounded-float(默认 8px / pill 12px / sharp 0px),防止 shape=pill 将 --soma-radius-item(9999px) 裁成圆形,同时严守语义圆角卫生门禁
112
+ const THUMB_CLASS = 'h-8 w-8 shrink-0 rounded-float object-cover';
61
113
  const NAME_CLASS = 'min-w-0 flex-1 truncate';
62
114
  const SIZE_TEXT_CLASS = 'shrink-0 text-xs text-fg-subtle';
63
115
  const STATUS_CLASS: Record<FileStatus, string> = {
64
116
  // 状态芯片:浅底、无描边(芯片一种形体)
65
- pending: 'shrink-0 rounded-md bg-surface-sunken px-1.5 py-0.5 text-xs font-medium text-fg-muted',
66
- uploading: 'shrink-0 rounded-md bg-info-soft px-1.5 py-0.5 text-xs font-medium text-info-on-soft',
67
- done: 'shrink-0 rounded-md bg-success-soft px-1.5 py-0.5 text-xs font-medium text-success-on-soft',
68
- error: 'shrink-0 rounded-md bg-danger-soft px-1.5 py-0.5 text-xs font-medium text-danger-on-soft',
117
+ // 待传 = 无 tone 的闭集状态值:缺省标签底色对,不取井色
118
+ pending: `shrink-0 rounded-item ${kitClosedValueTone('neutral')} px-1.5 py-0.5 text-xs font-medium`,
119
+ uploading: 'shrink-0 rounded-item bg-info-soft px-1.5 py-0.5 text-xs font-medium text-info-on-soft',
120
+ done: 'shrink-0 rounded-item bg-success-soft px-1.5 py-0.5 text-xs font-medium text-success-on-soft',
121
+ error: 'shrink-0 rounded-item bg-danger-soft px-1.5 py-0.5 text-xs font-medium text-danger-on-soft',
69
122
  };
70
123
  const statusText = (status: FileStatus, at: Element): string => kitText(
71
124
  status === 'pending' ? 'soma.kit.upload_pending' : status === 'uploading' ? 'soma.kit.upload_uploading' : status === 'done' ? 'soma.kit.upload_done' : 'soma.kit.upload_error',
72
125
  undefined, at,
73
126
  );
74
- const REMOVE_CLASS = 'shrink-0 cursor-pointer rounded-md px-1 text-fg-subtle hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
127
+ // 文件项结构(Upload 卡):[文件图标 / 缩略图][名称行 + 进度 / 失败原因][状态图标][重试 / 取消·移除];两行结构承载进度条与原因行
128
+ const ITEM_ICON_CLASS = 'text-fg-subtle';
129
+ const ITEM_BODY_CLASS = 'flex min-w-0 flex-1 flex-col gap-1';
130
+ const ITEM_NAME_ROW_CLASS = 'flex min-w-0 items-center gap-2';
131
+ const PROGRESS_ROW_CLASS = 'flex min-w-0 items-center gap-2';
132
+ const PROGRESS_BAR_CLASS = 'min-w-0 flex-1';
133
+ const PERCENT_CLASS = 'shrink-0 text-xs tabular-nums text-fg-subtle';
134
+ const REASON_CLASS = 'min-w-0 text-xs text-danger-on-soft';
135
+ const STATUS_ICON_CLASS: Record<'done' | 'error', string> = {
136
+ done: 'inline-flex shrink-0 text-success-on-soft',
137
+ error: 'inline-flex shrink-0 text-danger-on-soft',
138
+ };
139
+ const SR_ONLY_CLASS = 'sr-only';
140
+ // 行内操作 = 安静的图标钮(有后果的操作是按钮、行内用 subtle,组件卡 §6):重试取 refresh、取消 / 移除取 close
141
+ const ROW_ACTION_CLASS = `inline-flex shrink-0 cursor-pointer items-center justify-center rounded-item px-1 text-fg-subtle transition-colors hover:text-fg ${UP_FOCUS}`;
142
+ const REMOVE_CLASS = `shrink-0 cursor-pointer rounded-item px-1 text-fg-subtle hover:opacity-80 ${UP_FOCUS}`;
75
143
  const HIDDEN_CLASS = 'hidden';
144
+ // 隐藏的可点钮(开始上传 / 墙形态下的触发钮)仍在 DOM 里:带焦点环出口(可点的块宿主),G121 ⑥
145
+ const HIDDEN_BTN_CLASS = mergeClass('hidden', kitFocusRingRecipe('button'));
76
146
  // 照片墙(list: picture):方形缩略图格 + 末尾的「+」添加格
77
147
  const WALL_CLASS = 'm-0 grid list-none grid-cols-4 gap-2 p-0';
78
148
  const TILE_CLASS = mergeClass('relative flex aspect-square items-center justify-center overflow-hidden', kitShellRecipe({ tone: 'sunken', shadow: false }));
79
149
  const TILE_IMG_CLASS = 'h-full w-full object-cover';
80
150
  const TILE_NAME_CLASS = 'break-all px-2 text-center text-xs text-fg-muted';
81
151
  const TILE_STATUS_CLASS = 'absolute bottom-1 start-1';
82
- const TILE_REMOVE_CLASS = 'absolute end-1 top-1 cursor-pointer rounded-md bg-surface/80 px-1.5 text-sm text-fg transition-colors hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
83
- const ADD_TILE_CLASS = `flex aspect-square w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg ${DROP_EDGE} bg-surface text-sm text-fg-muted transition-colors hover:border-primary state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;
84
- const ADD_TILE_PLUS_CLASS = 'text-xl text-fg-subtle';
152
+ const TILE_REMOVE_CLASS = `absolute end-1 top-1 cursor-pointer rounded-item bg-surface/80 px-1.5 text-sm text-fg transition-colors hover:bg-surface ${UP_FOCUS}`;
153
+ const ADD_TILE_CLASS = `flex aspect-square w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-card ${DROP_EDGE} bg-surface text-sm text-fg-muted transition-colors hover:border-primary state-layer ${UP_FOCUS}`;
154
+ const ADD_TILE_PLUS_CLASS = 'inline-flex items-center justify-center text-fg-subtle';
85
155
  // 手动上传按钮:主色实心,文字 -fg
156
+ // 「开始上传」= 推进类动作(功能名 submit):按钮配方出口取色与禁用,不再自写实心主按钮类串
86
157
  const START_CLASS: Record<KitSize, string> = {
87
- sm: 'inline-flex h-6 w-fit cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
88
- md: 'inline-flex h-8 w-fit cursor-pointer items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
89
- lg: 'inline-flex h-10 w-fit cursor-pointer items-center justify-center rounded-md bg-primary px-5 text-base font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
158
+ sm: mergeClass(kitActionRecipe('submit', { size: 'sm' }), 'w-fit cursor-pointer'),
159
+ md: mergeClass(kitActionRecipe('submit', { size: 'md' }), 'w-fit cursor-pointer'),
160
+ lg: mergeClass(kitActionRecipe('submit', { size: 'lg' }), 'w-fit cursor-pointer'),
90
161
  };
91
162
 
92
163
  /** 本组件自带的类(并入基础组件候选类清单) */
93
- export const KIT_UPLOAD_CLASS_CANDIDATES: readonly string[] = Object.freeze([
94
- ...new Set([
95
- ROOT_CLASS, HIDDEN_CLASS, HINT_CLASS, REJECT_NOTE_CLASS, LIST_CLASS, ITEM_CLASS, THUMB_CLASS, NAME_CLASS, SIZE_TEXT_CLASS, REMOVE_CLASS,
96
- WALL_CLASS, TILE_CLASS, TILE_IMG_CLASS, TILE_NAME_CLASS, TILE_STATUS_CLASS, TILE_REMOVE_CLASS, ADD_TILE_CLASS, ADD_TILE_PLUS_CLASS,
97
- ...Object.values(PICK_CLASS), ...Object.values(DROP_CLASS), ...Object.values(STATUS_CLASS), ...Object.values(START_CLASS),
98
- ].join(' ').split(' ')),
99
- ]);
164
+ export const KIT_UPLOAD_CLASS_CANDIDATES: readonly string[] = classCandidates(
165
+ ROOT_CLASS, HIDDEN_CLASS, HIDDEN_BTN_CLASS, DROP_ICON_CLASS, DROP_ICON_DISABLED_CLASS, HINT_CLASS, REJECT_NOTE_CLASS,
166
+ LIST_CLASS, ITEM_CLASS, THUMB_CLASS, NAME_CLASS, SIZE_TEXT_CLASS, REMOVE_CLASS,
167
+ ITEM_ICON_CLASS, ITEM_BODY_CLASS, ITEM_NAME_ROW_CLASS, PROGRESS_ROW_CLASS, PROGRESS_BAR_CLASS, PERCENT_CLASS, REASON_CLASS, SR_ONLY_CLASS,
168
+ Object.values(STATUS_ICON_CLASS), ROW_ACTION_CLASS,
169
+ WALL_CLASS, TILE_CLASS, TILE_IMG_CLASS, TILE_NAME_CLASS, TILE_STATUS_CLASS, TILE_REMOVE_CLASS, ADD_TILE_CLASS, ADD_TILE_PLUS_CLASS,
170
+ Object.values(PICK_CLASS), Object.values(DROP_CLASS), Object.values(STATUS_CLASS), Object.values(START_CLASS),
171
+ KIT_ICON_CLASS_CANDIDATES,
172
+ );
100
173
 
101
174
  export type UploadList = 'text' | 'picture';
102
175
 
@@ -183,21 +256,27 @@ interface Ui {
183
256
  api: KitApi;
184
257
  }
185
258
 
186
- /** 新选图片文件的本地预览地址;环境没有 createObjectURL 或不是图片时为空 */
259
+ /** 新选图片文件的本地预览地址;环境没有 createObjectURL、跨宿主 Blob 不兼容或不是图片时为空 */
187
260
  function previewOf(ui: Ui, raw: unknown): string {
188
261
  if (typeof File === 'undefined' || !(raw instanceof File) || !raw.type.startsWith('image/')) return '';
189
262
  const hit = ui.previews.get(raw);
190
263
  if (hit !== undefined) return hit;
191
264
  if (typeof URL === 'undefined' || typeof URL.createObjectURL !== 'function') return '';
192
- const url = URL.createObjectURL(raw);
193
- ui.previews.set(raw, url);
194
- return url;
265
+ try {
266
+ const url = URL.createObjectURL(raw);
267
+ ui.previews.set(raw, url);
268
+ return url;
269
+ } catch {
270
+ return '';
271
+ }
195
272
  }
196
273
 
197
274
  function revokePreviews(ui: Ui, keep: ReadonlySet<unknown>): void {
198
275
  for (const [file, url] of ui.previews) {
199
276
  if (keep.has(file)) continue;
200
- if (typeof URL.revokeObjectURL === 'function') URL.revokeObjectURL(url);
277
+ if (typeof URL !== 'undefined' && typeof URL.revokeObjectURL === 'function') {
278
+ try { URL.revokeObjectURL(url); } catch { /* ignore */ }
279
+ }
201
280
  ui.previews.delete(file);
202
281
  }
203
282
  }
@@ -235,7 +314,8 @@ function takeFiles(ui: Ui, files: readonly File[]): void {
235
314
  }
236
315
 
237
316
  function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
238
- const size = sizeOf(p.size);
317
+ // 按钮档位:自己的非缺省 size 优先,否则取页面线的 kit.controlSize(没有 kit 时与 sizeOf 相同)
318
+ const size = kitControlSizeOf(p);
239
319
  const editable = canEdit(p);
240
320
  const dropzone = bool(p.dropzone);
241
321
  root.className = joinClass(ROOT_CLASS, p.class);
@@ -263,6 +343,9 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
263
343
  trigger.className = !editable ? DROP_CLASS.disabled : ui.over ? DROP_CLASS.over : DROP_CLASS.idle;
264
344
  // 虚线投放区不是控件面,不标
265
345
  setKitFace(trigger, null);
346
+ // 图标:主色上传箭头(装饰,aria-hidden),禁用态随文字变禁用墨
347
+ const icon = kitIcon('upload', 'display', editable ? DROP_ICON_CLASS : DROP_ICON_DISABLED_CLASS);
348
+ trigger.appendChild(icon);
266
349
  const main = document.createElement('span');
267
350
  main.textContent = str(p.drop_text, kitText('soma.kit.upload_drop', undefined, root));
268
351
  trigger.appendChild(main);
@@ -274,6 +357,8 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
274
357
  }
275
358
  if (editable) trigger.removeAttribute('aria-disabled'); else trigger.setAttribute('aria-disabled', 'true');
276
359
  } else {
360
+ // 按钮形态没有拖入态;同一元素若刚从投放区换回,清掉拖拽中
361
+ kitMarkInteract(trigger, 'dragging', false);
277
362
  trigger.removeAttribute('role');
278
363
  trigger.removeAttribute('tabindex');
279
364
  trigger.className = PICK_CLASS[size];
@@ -285,7 +370,7 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
285
370
  // 照片墙:末尾的「+」格代替按钮触发器(投放区形态则两者并存,不再画添加格)
286
371
  const picture = listModeOf(p.list) === 'picture';
287
372
  const wallAdd = picture && !dropzone;
288
- if (wallAdd) trigger.className = HIDDEN_CLASS;
373
+ if (wallAdd) trigger.className = HIDDEN_BTN_CLASS;
289
374
  setAttr(trigger, 'id', wallAdd ? '' : str(p.id));
290
375
  setAttr(trigger, 'aria-label', wallAdd ? '' : str(p.aria_label));
291
376
  // 作表单字段:根承载字段名(labelledby)/ 说明 / 错误关联与无效标记
@@ -295,146 +380,493 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
295
380
  ui.hint.textContent = hint;
296
381
  ui.hint.className = hint === '' ? HIDDEN_CLASS : HINT_CLASS;
297
382
 
298
- // 列表
383
+ // 列表(基于 reconcileKeyedElements 原地调和,进度跳变不重建未变的 <img> 与 <button>)
299
384
  const items = itemsOf(p.value);
300
- ui.list.textContent = '';
385
+ const keep = new Set<unknown>();
301
386
  if (picture) {
302
- paintWall(ui, p, items, editable, wallAdd);
387
+ paintWall(ui, p, items, editable, wallAdd, keep);
303
388
  } else {
304
- revokePreviews(ui, new Set());
305
389
  ui.list.className = items.length === 0 ? HIDDEN_CLASS : LIST_CLASS;
306
- paintRows(ui, items, editable, kitLocaleAt(root) || 'zh-CN');
390
+ paintRows(ui, items, editable, kitLocaleAt(root) || 'zh-CN', keep);
307
391
  }
392
+ revokePreviews(ui, keep);
393
+ // 文件拖入投放区 = 拖拽中,是结构性交互状态,自报给主题(悬停 / 聚焦仍走伪类);触发器可能随形态重建,所以每轮按当前状态写
394
+ if (dropzone) kitMarkInteract(trigger, 'dragging', editable && ui.over);
395
+ // 数据状态:只读;否则列表里有上传出错的文件时整块报「出错」(组件自己知道的事实,主题据此取值)
396
+ kitMarkDataState(root, bool(p.readonly) ? 'readonly' : items.some((it) => statusOf(it.status) === 'error') ? 'error' : 'normal');
308
397
 
309
398
  // 手动上传:有待上传的项才出现;点它抛 upload { files }
310
399
  const pending = pendingOf(items);
311
400
  ui.start.textContent = str(p.upload_text, kitText('soma.kit.upload_start', undefined, root));
312
- ui.start.className = bool(p.manual) && pending.length > 0 ? START_CLASS[size] : HIDDEN_CLASS;
401
+ ui.start.className = bool(p.manual) && pending.length > 0 ? START_CLASS[size] : HIDDEN_BTN_CLASS;
313
402
  // 「开始上传」是实心主按钮,同 Button 标 raised
314
403
  setKitFace(ui.start, 'raised');
315
404
  ui.start.disabled = !editable;
316
405
  }
317
406
 
318
- function paintWall(ui: Ui, p: KitProps, items: readonly FileItem[], editable: boolean, wallAdd: boolean): void {
407
+ const FILE_REF_IDS = new WeakMap<object, number>();
408
+ let fileRefSeq = 0;
409
+
410
+ function fileKeyOf(item: FileItem, index: number): string {
411
+ const explicit = item.uid ?? item.id;
412
+ if ((typeof explicit === 'string' && explicit !== '') || typeof explicit === 'number') {
413
+ return `id:${String(explicit)}`;
414
+ }
415
+ if (item.file !== null && typeof item.file === 'object') {
416
+ let refId = FILE_REF_IDS.get(item.file);
417
+ if (refId === undefined) {
418
+ fileRefSeq += 1;
419
+ refId = fileRefSeq;
420
+ FILE_REF_IDS.set(item.file, refId);
421
+ }
422
+ return `file:${refId}:${item.name}`;
423
+ }
424
+ return `${index}:${item.name}`;
425
+ }
426
+
427
+ interface WallTileRefs {
428
+ imgEl: HTMLImageElement | null;
429
+ nameEl: HTMLElement | null;
430
+ thumbUrl: string;
431
+ brokenUrl: string | null;
432
+ statusWrap: HTMLElement | null;
433
+ statusTag: HTMLElement | null;
434
+ rmBtn: HTMLButtonElement | null;
435
+ }
436
+
437
+ interface WallAddRefs {
438
+ addBtn: HTMLButtonElement;
439
+ textEl: HTMLElement;
440
+ }
441
+
442
+ const WALL_TILE_REFS = new WeakMap<HTMLElement, WallTileRefs>();
443
+ const WALL_ADD_REFS = new WeakMap<HTMLElement, WallAddRefs>();
444
+
445
+ type WallEntry = { kind: 'file'; item: FileItem; index: number } | { kind: 'add' };
446
+
447
+ function syncAttrIfChanged(el: Element, attr: string, next: string): void {
448
+ if (next === '') {
449
+ if (el.hasAttribute(attr)) el.removeAttribute(attr);
450
+ } else if (el.getAttribute(attr) !== next) {
451
+ el.setAttribute(attr, next);
452
+ }
453
+ }
454
+
455
+ function paintWall(
456
+ ui: Ui, p: KitProps, items: readonly FileItem[], editable: boolean, wallAdd: boolean, keep: Set<unknown>,
457
+ ): void {
319
458
  ui.list.className = WALL_CLASS;
320
- const keep = new Set<unknown>();
321
- items.forEach((item, index) => {
322
- const tile = document.createElement('li');
323
- tile.className = TILE_CLASS;
324
- // 已传文件的地址来自数据:过 safeSrc(只放行相对 / http(s) / blob / data:image);本地预览是自己建的 blob 地址
325
- const url = typeof item.url === 'string' && item.url !== '' ? safeSrc(item.url) : previewOf(ui, item.file);
459
+ for (const item of items) {
326
460
  if (item.file !== undefined) keep.add(item.file);
327
- if (url !== '') {
328
- const img = document.createElement('img');
329
- img.src = url;
330
- img.alt = item.name;
331
- img.className = TILE_IMG_CLASS;
332
- // 加载失败(不是图片):摘掉,退回显示文件名
333
- img.addEventListener('error', () => {
334
- img.remove();
335
- tile.insertBefore(nameSpan(item.name), tile.firstChild);
336
- }, { once: true });
337
- tile.appendChild(img);
338
- } else {
339
- tile.appendChild(nameSpan(item.name));
340
- }
341
- const status = statusOf(item.status);
342
- if (status) {
343
- const wrap = document.createElement('span');
344
- wrap.className = TILE_STATUS_CLASS;
345
- const tag = document.createElement('span');
346
- tag.className = STATUS_CLASS[status];
347
- const pct = typeof item.percent === 'number' && Number.isFinite(item.percent) ? Math.max(0, Math.min(100, Math.round(item.percent))) : null;
348
- tag.textContent = status === 'uploading' && pct !== null ? `${statusText('uploading', ui.list)} ${pct}%` : statusText(status, ui.list);
349
- wrap.appendChild(tag);
350
- tile.appendChild(wrap);
351
- }
352
- if (editable) {
353
- const rm = document.createElement('button');
354
- rm.type = 'button';
355
- rm.className = TILE_REMOVE_CLASS;
356
- rm.setAttribute('data-kit-remove', String(index));
357
- rm.setAttribute('aria-label', kitText('soma.kit.remove_named', { name: item.name }, ui.list));
358
- rm.appendChild(kitIcon('close', 'sm'));
359
- tile.appendChild(rm);
360
- }
361
- ui.list.appendChild(tile);
362
- });
363
- revokePreviews(ui, keep);
364
- // 添加格:可编辑、没有投放区、单选已有一张或多选已达上限时不再出现
461
+ }
365
462
  const maxCount = num(p.max_count);
366
463
  const full = bool(p.multiple) ? maxCount !== null && maxCount > 0 && items.length >= maxCount : items.length >= 1;
367
- if (wallAdd && editable && !full) {
368
- const li = document.createElement('li');
369
- const add = document.createElement('button');
370
- add.type = 'button';
371
- add.className = ADD_TILE_CLASS;
372
- add.setAttribute('data-kit-add', '');
373
- setAttr(add, 'id', str(p.id));
374
- const pickLabel = str(p.button_text, kitText('soma.kit.upload_pick', undefined, ui.list));
375
- setAttr(add, 'aria-label', str(p.aria_label, '') === '' ? pickLabel : str(p.aria_label));
376
- const plus = document.createElement('span');
377
- plus.className = ADD_TILE_PLUS_CLASS;
378
- plus.setAttribute('aria-hidden', 'true');
379
- plus.textContent = '+';
380
- const text = document.createElement('span');
381
- text.textContent = pickLabel;
382
- add.appendChild(plus);
383
- add.appendChild(text);
384
- li.appendChild(add);
385
- ui.list.appendChild(li);
386
- }
464
+ const entries: WallEntry[] = items.map((item, index) => ({ kind: 'file', item, index }));
465
+ if (wallAdd && editable && !full) entries.push({ kind: 'add' });
466
+
467
+ reconcileKeyedElements(
468
+ ui.list,
469
+ entries,
470
+ (entry) => (entry.kind === 'add' ? 'pic:__add__' : `pic:${fileKeyOf(entry.item, entry.index)}`),
471
+ (entry) => {
472
+ const li = document.createElement('li');
473
+ if (entry.kind === 'add') {
474
+ const add = document.createElement('button');
475
+ add.type = 'button';
476
+ kitReportSelf(add, { part: 'action' });
477
+ add.className = ADD_TILE_CLASS;
478
+ add.setAttribute(KIT_ATTR_ADD, '');
479
+ const plus = document.createElement('span');
480
+ plus.className = ADD_TILE_PLUS_CLASS;
481
+ plus.setAttribute('aria-hidden', 'true');
482
+ plus.appendChild(kitIcon('plus', 'lg'));
483
+ const textEl = document.createElement('span');
484
+ add.append(plus, textEl);
485
+ li.appendChild(add);
486
+ WALL_ADD_REFS.set(li, { addBtn: add, textEl });
487
+ return li;
488
+ }
489
+ li.className = TILE_CLASS;
490
+ WALL_TILE_REFS.set(li, {
491
+ imgEl: null, nameEl: null, thumbUrl: '', brokenUrl: null, statusWrap: null, statusTag: null, rmBtn: null,
492
+ });
493
+ return li;
494
+ },
495
+ (li, entry) => {
496
+ if (entry.kind === 'add') {
497
+ const refs = WALL_ADD_REFS.get(li);
498
+ if (!refs) return;
499
+ const pickLabel = str(p.button_text, kitText('soma.kit.upload_pick', undefined, ui.list));
500
+ syncAttrIfChanged(refs.addBtn, 'id', str(p.id));
501
+ syncAttrIfChanged(refs.addBtn, 'aria-label', str(p.aria_label, '') === '' ? pickLabel : str(p.aria_label));
502
+ if (refs.textEl.textContent !== pickLabel) refs.textEl.textContent = pickLabel;
503
+ return;
504
+ }
505
+ const refs = WALL_TILE_REFS.get(li);
506
+ if (!refs) return;
507
+ const { item, index } = entry;
508
+ const url = imageThumbSrc(item) || previewOf(ui, item.file);
509
+ const canShowImg = url !== '' && url !== refs.brokenUrl;
510
+
511
+ if (canShowImg) {
512
+ refs.nameEl?.remove();
513
+ refs.nameEl = null;
514
+ if (refs.imgEl === null) {
515
+ const img = document.createElement('img');
516
+ img.className = TILE_IMG_CLASS;
517
+ img.src = url;
518
+ img.alt = item.name;
519
+ refs.thumbUrl = url;
520
+ img.addEventListener('error', () => {
521
+ if (refs.imgEl !== img) return;
522
+ refs.brokenUrl = refs.thumbUrl;
523
+ img.remove();
524
+ refs.imgEl = null;
525
+ refs.thumbUrl = '';
526
+ const fallback = nameSpan(item.name);
527
+ refs.nameEl = fallback;
528
+ li.insertBefore(fallback, li.firstChild);
529
+ }, { once: true });
530
+ refs.imgEl = img;
531
+ li.insertBefore(img, li.firstChild);
532
+ } else {
533
+ if (refs.thumbUrl !== url) {
534
+ refs.imgEl.src = url;
535
+ refs.thumbUrl = url;
536
+ }
537
+ if (refs.imgEl.alt !== item.name) refs.imgEl.alt = item.name;
538
+ }
539
+ } else {
540
+ refs.imgEl?.remove();
541
+ refs.imgEl = null;
542
+ refs.thumbUrl = '';
543
+ if (refs.nameEl === null) {
544
+ refs.nameEl = nameSpan(item.name);
545
+ li.insertBefore(refs.nameEl, li.firstChild);
546
+ } else if (refs.nameEl.textContent !== item.name) {
547
+ refs.nameEl.textContent = item.name;
548
+ }
549
+ }
550
+
551
+ const status = statusOf(item.status);
552
+ if (status) {
553
+ if (refs.statusWrap === null || refs.statusTag === null) {
554
+ const wrap = document.createElement('span');
555
+ wrap.className = TILE_STATUS_CLASS;
556
+ const tag = document.createElement('span');
557
+ kitReportSelf(tag, { part: 'status' });
558
+ wrap.appendChild(tag);
559
+ refs.statusWrap = wrap;
560
+ refs.statusTag = tag;
561
+ if (refs.rmBtn !== null && refs.rmBtn.parentElement === li) {
562
+ li.insertBefore(wrap, refs.rmBtn);
563
+ } else {
564
+ li.appendChild(wrap);
565
+ }
566
+ }
567
+ if (refs.statusTag.className !== STATUS_CLASS[status]) refs.statusTag.className = STATUS_CLASS[status];
568
+ const pct = typeof item.percent === 'number' && Number.isFinite(item.percent) ? Math.max(0, Math.min(100, Math.round(item.percent))) : null;
569
+ const nextStatusText = status === 'uploading' && pct !== null ? `${statusText('uploading', ui.list)} ${pct}%` : statusText(status, ui.list);
570
+ if (refs.statusTag.textContent !== nextStatusText) refs.statusTag.textContent = nextStatusText;
571
+ } else if (refs.statusWrap !== null) {
572
+ refs.statusWrap.remove();
573
+ refs.statusWrap = null;
574
+ refs.statusTag = null;
575
+ }
576
+
577
+ if (editable) {
578
+ if (refs.rmBtn === null) {
579
+ const rm = document.createElement('button');
580
+ rm.type = 'button';
581
+ rm.className = TILE_REMOVE_CLASS;
582
+ kitReportSelf(rm, { part: 'action' });
583
+ rm.appendChild(kitIcon('close', 'sm'));
584
+ refs.rmBtn = rm;
585
+ li.appendChild(rm);
586
+ }
587
+ syncAttrIfChanged(refs.rmBtn, KIT_ATTR_REMOVE, String(index));
588
+ syncAttrIfChanged(refs.rmBtn, 'aria-label', kitText('soma.kit.remove_named', { name: item.name }, ui.list));
589
+ } else if (refs.rmBtn !== null) {
590
+ refs.rmBtn.remove();
591
+ refs.rmBtn = null;
592
+ }
593
+ },
594
+ );
387
595
  }
388
596
 
389
597
  function nameSpan(name: string): HTMLElement {
390
598
  const span = document.createElement('span');
391
599
  span.className = TILE_NAME_CLASS;
600
+ // 文件名是这一格的值
601
+ kitReportSelf(span, { part: 'value' });
392
602
  span.textContent = name;
393
603
  return span;
394
604
  }
395
605
 
396
- function paintRows(ui: Ui, items: readonly FileItem[], editable: boolean, locale: string): void {
397
- items.forEach((item, index) => {
398
- const row = document.createElement('li');
399
- row.className = ITEM_CLASS;
400
- if (typeof item.url === 'string' && safeSrc(item.url) !== '') {
401
- const img = document.createElement('img');
402
- img.src = safeSrc(item.url);
403
- img.alt = '';
404
- img.className = THUMB_CLASS;
405
- // url 不一定是图片(pdf、压缩包):加载失败就摘掉,不留破图
406
- img.addEventListener('error', () => img.remove(), { once: true });
407
- row.appendChild(img);
408
- }
409
- const name = document.createElement('span');
410
- name.className = NAME_CLASS;
411
- name.textContent = item.name;
412
- row.appendChild(name);
413
- if (typeof item.size === 'number' && Number.isFinite(item.size)) {
414
- const sz = document.createElement('span');
415
- sz.className = SIZE_TEXT_CLASS;
416
- sz.textContent = formatValue(item.size, 'bytes', locale);
417
- row.appendChild(sz);
418
- }
419
- const status = statusOf(item.status);
420
- if (status) {
421
- const tag = document.createElement('span');
422
- tag.className = STATUS_CLASS[status];
606
+ interface TextRowRefs {
607
+ leadEl: HTMLElement | SVGSVGElement;
608
+ leadUrl: string;
609
+ brokenUrl: string | null;
610
+ bodyEl: HTMLSpanElement;
611
+ nameRowEl: HTMLSpanElement;
612
+ nameEl: HTMLSpanElement;
613
+ sizeEl: HTMLSpanElement | null;
614
+ prowEl: HTMLSpanElement | null;
615
+ barEl: HTMLSpanElement | null;
616
+ fillRect: Element | null;
617
+ pctSrEl: HTMLSpanElement | null;
618
+ pctValNode: Text | null;
619
+ reasonEl: HTMLSpanElement | null;
620
+ statusEl: HTMLSpanElement | null;
621
+ lastStatusMark: FileStatus | null;
622
+ retryBtn: HTMLButtonElement | null;
623
+ rmBtn: HTMLButtonElement | null;
624
+ }
625
+
626
+ const TEXT_ROW_REFS = new WeakMap<HTMLElement, TextRowRefs>();
627
+
628
+ function paintRows(ui: Ui, items: readonly FileItem[], editable: boolean, locale: string, keep: Set<unknown>): void {
629
+ for (const item of items) {
630
+ if (item.file !== undefined) keep.add(item.file);
631
+ }
632
+ reconcileKeyedElements(
633
+ ui.list,
634
+ items,
635
+ (item, index) => `text:${fileKeyOf(item, index)}`,
636
+ () => {
637
+ const row = document.createElement('li');
638
+ row.className = ITEM_CLASS;
639
+ // 文件列表的一行:元素部件「行」;文件名是值
640
+ kitReportSelf(row, { part: 'line' });
641
+ const leadEl = kitIcon('file', 'md', ITEM_ICON_CLASS);
642
+ const bodyEl = document.createElement('span');
643
+ bodyEl.className = ITEM_BODY_CLASS;
644
+ const nameRowEl = document.createElement('span');
645
+ nameRowEl.className = ITEM_NAME_ROW_CLASS;
646
+ const nameEl = document.createElement('span');
647
+ nameEl.className = NAME_CLASS;
648
+ kitReportSelf(nameEl, { part: 'value' });
649
+ nameRowEl.appendChild(nameEl);
650
+ bodyEl.appendChild(nameRowEl);
651
+ row.append(leadEl, bodyEl);
652
+ TEXT_ROW_REFS.set(row, {
653
+ leadEl, leadUrl: '', brokenUrl: null,
654
+ bodyEl, nameRowEl, nameEl, sizeEl: null,
655
+ prowEl: null, barEl: null, fillRect: null, pctSrEl: null, pctValNode: null,
656
+ reasonEl: null,
657
+ statusEl: null, lastStatusMark: null,
658
+ retryBtn: null, rmBtn: null,
659
+ });
660
+ return row;
661
+ },
662
+ (row, item, index) => {
663
+ const refs = TEXT_ROW_REFS.get(row);
664
+ if (!refs) return;
665
+
666
+ // 1. 项首缩略图(含 item.file 本地图片预览)或文件图标,进度跳变不重建 <img>
667
+ const thumbSrc = imageThumbSrc(item) || previewOf(ui, item.file);
668
+ const canShowThumb = thumbSrc !== '' && thumbSrc !== refs.brokenUrl;
669
+ if (canShowThumb) {
670
+ if (refs.leadEl.tagName === 'IMG') {
671
+ if (refs.leadUrl !== thumbSrc) {
672
+ (refs.leadEl as HTMLImageElement).src = thumbSrc;
673
+ refs.leadUrl = thumbSrc;
674
+ }
675
+ } else {
676
+ const img = document.createElement('img');
677
+ img.src = thumbSrc;
678
+ img.alt = '';
679
+ img.className = THUMB_CLASS;
680
+ refs.leadUrl = thumbSrc;
681
+ img.addEventListener('error', () => {
682
+ if (refs.leadEl !== img) return;
683
+ refs.brokenUrl = refs.leadUrl;
684
+ refs.leadUrl = '';
685
+ const fallback = kitIcon('file', 'md', ITEM_ICON_CLASS);
686
+ img.replaceWith(fallback);
687
+ refs.leadEl = fallback;
688
+ }, { once: true });
689
+ refs.leadEl.replaceWith(img);
690
+ refs.leadEl = img;
691
+ }
692
+ } else if (refs.leadEl.tagName === 'IMG') {
693
+ const icon = kitIcon('file', 'md', ITEM_ICON_CLASS);
694
+ refs.leadEl.replaceWith(icon);
695
+ refs.leadEl = icon;
696
+ refs.leadUrl = '';
697
+ }
698
+
699
+ // 2. 名称与文件大小
700
+ if (refs.nameEl.textContent !== item.name) refs.nameEl.textContent = item.name;
701
+ if (typeof item.size === 'number' && Number.isFinite(item.size)) {
702
+ const sizeStr = formatValue(item.size, 'bytes', locale);
703
+ if (refs.sizeEl === null) {
704
+ const sz = document.createElement('span');
705
+ sz.className = SIZE_TEXT_CLASS;
706
+ sz.textContent = sizeStr;
707
+ refs.sizeEl = sz;
708
+ refs.nameRowEl.appendChild(sz);
709
+ } else if (refs.sizeEl.textContent !== sizeStr) {
710
+ refs.sizeEl.textContent = sizeStr;
711
+ }
712
+ } else if (refs.sizeEl !== null) {
713
+ refs.sizeEl.remove();
714
+ refs.sizeEl = null;
715
+ }
716
+
717
+ // 3. 进度条(原地改 width 与百分比文字,不销毁重建)或失败原因行
718
+ const status = statusOf(item.status);
423
719
  const pct = typeof item.percent === 'number' && Number.isFinite(item.percent) ? Math.max(0, Math.min(100, Math.round(item.percent))) : null;
424
- tag.textContent = status === 'uploading' && pct !== null ? `${statusText('uploading', ui.list)} ${pct}%` : statusText(status, ui.list);
425
- row.appendChild(tag);
426
- }
427
- if (editable) {
428
- const rm = document.createElement('button');
429
- rm.type = 'button';
430
- rm.className = REMOVE_CLASS;
431
- rm.setAttribute('data-kit-remove', String(index));
432
- rm.setAttribute('aria-label', kitText('soma.kit.remove_named', { name: item.name }, ui.list));
433
- rm.appendChild(kitIcon('close', 'sm'));
434
- row.appendChild(rm);
435
- }
436
- ui.list.appendChild(row);
437
- });
720
+ if (status === 'uploading') {
721
+ refs.reasonEl?.remove();
722
+ refs.reasonEl = null;
723
+ if (refs.prowEl === null) {
724
+ const prow = document.createElement('span');
725
+ prow.className = PROGRESS_ROW_CLASS;
726
+ const bar = document.createElement('span');
727
+ bar.className = PROGRESS_BAR_CLASS;
728
+ bar.setAttribute('role', 'progressbar');
729
+ bar.setAttribute('aria-valuemin', '0');
730
+ bar.setAttribute('aria-valuemax', '100');
731
+ const mini = kitMiniBarNode(row.ownerDocument, clampPercent(pct ?? 0));
732
+ bar.appendChild(mini);
733
+ const pctText = document.createElement('span');
734
+ pctText.className = PERCENT_CLASS;
735
+ const sr = document.createElement('span');
736
+ sr.className = SR_ONLY_CLASS;
737
+ const valNode = row.ownerDocument.createTextNode('');
738
+ pctText.append(sr, valNode);
739
+ prow.append(bar, pctText);
740
+ refs.bodyEl.appendChild(prow);
741
+ refs.prowEl = prow;
742
+ refs.barEl = bar;
743
+ refs.fillRect = mini.lastElementChild;
744
+ refs.pctSrEl = sr;
745
+ refs.pctValNode = valNode;
746
+ }
747
+ if (refs.barEl) {
748
+ syncAttrIfChanged(refs.barEl, 'aria-valuenow', pct !== null ? String(pct) : '');
749
+ syncAttrIfChanged(refs.barEl, 'aria-label', item.name);
750
+ }
751
+ const widthStr = `${clampPercent(pct ?? 0)}%`;
752
+ if (refs.fillRect && refs.fillRect.getAttribute('width') !== widthStr) {
753
+ refs.fillRect.setAttribute('width', widthStr);
754
+ }
755
+ const srLabel = `${statusText('uploading', ui.list)} `;
756
+ if (refs.pctSrEl && refs.pctSrEl.textContent !== srLabel) refs.pctSrEl.textContent = srLabel;
757
+ const pctStr = pct !== null ? `${pct}%` : '';
758
+ if (refs.pctValNode && refs.pctValNode.data !== pctStr) refs.pctValNode.data = pctStr;
759
+ } else {
760
+ if (refs.prowEl !== null) {
761
+ refs.prowEl.remove();
762
+ refs.prowEl = null;
763
+ refs.barEl = null;
764
+ refs.fillRect = null;
765
+ refs.pctSrEl = null;
766
+ refs.pctValNode = null;
767
+ }
768
+ if (status === 'error') {
769
+ const reasonText = typeof item.error === 'string' && item.error !== '' ? item.error : statusText('error', ui.list);
770
+ if (refs.reasonEl === null) {
771
+ const reason = document.createElement('span');
772
+ reason.className = REASON_CLASS;
773
+ reason.setAttribute('role', 'alert');
774
+ reason.textContent = reasonText;
775
+ refs.reasonEl = reason;
776
+ refs.bodyEl.appendChild(reason);
777
+ } else if (refs.reasonEl.textContent !== reasonText) {
778
+ refs.reasonEl.textContent = reasonText;
779
+ }
780
+ } else if (refs.reasonEl !== null) {
781
+ refs.reasonEl.remove();
782
+ refs.reasonEl = null;
783
+ }
784
+ }
785
+
786
+ // 4. 右侧状态徽标 / 图标(仅状态档切换时变更)
787
+ const wantMark: FileStatus | null = status === 'pending' || status === 'done' || status === 'error' ? status : null;
788
+ if (wantMark === null) {
789
+ refs.statusEl?.remove();
790
+ refs.statusEl = null;
791
+ refs.lastStatusMark = null;
792
+ } else if (refs.statusEl === null || refs.lastStatusMark !== wantMark) {
793
+ refs.statusEl?.remove();
794
+ const mark = document.createElement('span');
795
+ // 右侧状态徽标 / 图标:元素部件「状态」
796
+ kitReportSelf(mark, { part: 'status' });
797
+ if (wantMark === 'pending') {
798
+ mark.className = STATUS_CLASS.pending;
799
+ mark.textContent = statusText('pending', ui.list);
800
+ } else {
801
+ mark.className = STATUS_ICON_CLASS[wantMark];
802
+ mark.setAttribute(KIT_ATTR_STATUS, wantMark);
803
+ mark.appendChild(kitIcon(wantMark === 'done' ? 'success' : 'error', 'md'));
804
+ const sr = document.createElement('span');
805
+ sr.className = SR_ONLY_CLASS;
806
+ sr.textContent = statusText(wantMark, ui.list);
807
+ mark.appendChild(sr);
808
+ }
809
+ const beforeAction = refs.retryBtn ?? refs.rmBtn;
810
+ if (beforeAction !== null && beforeAction.parentElement === row) {
811
+ row.insertBefore(mark, beforeAction);
812
+ } else {
813
+ row.appendChild(mark);
814
+ }
815
+ refs.statusEl = mark;
816
+ refs.lastStatusMark = wantMark;
817
+ } else if (wantMark === 'pending') {
818
+ const pendingLabel = statusText('pending', ui.list);
819
+ if (refs.statusEl.textContent !== pendingLabel) refs.statusEl.textContent = pendingLabel;
820
+ }
821
+
822
+ // 5. 操作按钮(重试 / 取消·移除):保留同一 <button> 引用,绝不吞掉点击
823
+ if (editable) {
824
+ if (status === 'error') {
825
+ if (refs.retryBtn === null) {
826
+ const retry = document.createElement('button');
827
+ retry.type = 'button';
828
+ retry.className = ROW_ACTION_CLASS;
829
+ kitReportSelf(retry, { part: 'action' });
830
+ retry.appendChild(kitIcon('refresh', 'sm'));
831
+ refs.retryBtn = retry;
832
+ if (refs.rmBtn !== null && refs.rmBtn.parentElement === row) {
833
+ row.insertBefore(retry, refs.rmBtn);
834
+ } else {
835
+ row.appendChild(retry);
836
+ }
837
+ }
838
+ syncAttrIfChanged(refs.retryBtn, KIT_ATTR_RETRY, String(index));
839
+ syncAttrIfChanged(refs.retryBtn, 'aria-label', kitText('soma.kit.retry_load', { name: item.name }, ui.list));
840
+ } else if (refs.retryBtn !== null) {
841
+ refs.retryBtn.remove();
842
+ refs.retryBtn = null;
843
+ }
844
+
845
+ if (refs.rmBtn === null) {
846
+ const rm = document.createElement('button');
847
+ rm.type = 'button';
848
+ rm.className = REMOVE_CLASS;
849
+ kitReportSelf(rm, { part: 'action' });
850
+ rm.appendChild(kitIcon('close', 'sm'));
851
+ refs.rmBtn = rm;
852
+ row.appendChild(rm);
853
+ }
854
+ syncAttrIfChanged(refs.rmBtn, KIT_ATTR_REMOVE, String(index));
855
+ if (status === 'uploading') {
856
+ syncAttrIfChanged(refs.rmBtn, KIT_ATTR_CANCEL, String(index));
857
+ syncAttrIfChanged(refs.rmBtn, 'aria-label', kitText('soma.kit.cancel', undefined, ui.list));
858
+ } else {
859
+ syncAttrIfChanged(refs.rmBtn, KIT_ATTR_CANCEL, '');
860
+ syncAttrIfChanged(refs.rmBtn, 'aria-label', kitText('soma.kit.remove_named', { name: item.name }, ui.list));
861
+ }
862
+ } else {
863
+ refs.retryBtn?.remove();
864
+ refs.retryBtn = null;
865
+ refs.rmBtn?.remove();
866
+ refs.rmBtn = null;
867
+ }
868
+ },
869
+ );
438
870
  }
439
871
 
440
872
  export function createUpload(): SomaComponentDefinition {
@@ -443,7 +875,7 @@ export function createUpload(): SomaComponentDefinition {
443
875
  name: 'Upload',
444
876
  layer: 'basic',
445
877
  props: {
446
- value: { type: 'array', default: [], desc: '文件列表 [{ name, size?, status?(pending/uploading/done/error), percent?, url?, file? }](页面持有)' },
878
+ value: { type: 'array', default: [], desc: '文件列表 [{ name, size?, status?(pending/uploading/done/error), percent?, error?(失败原因,画在失败项的下一行), url?, file? }](页面持有)' },
447
879
  accept: { type: 'string', default: '', desc: '可选类型(input accept 语法:.pdf / image/* / 精确 MIME,逗号分隔);空 = 不限;拖放同样会判' },
448
880
  multiple: { type: 'boolean', default: false, desc: '可多选;false 时新选的文件替换整张列表' },
449
881
  max_size: { type: 'number', default: 0, desc: '单文件最大字节数;0 = 不限(呈现级校验)' },
@@ -465,6 +897,8 @@ export function createUpload(): SomaComponentDefinition {
465
897
  emits: {
466
898
  change: { payload: { value: { type: 'array' } }, desc: '列表变化(选择追加、删除),value 是完整新列表;新选文件 status 为 pending 并带 file;disabled / readonly 时不抛' },
467
899
  reject: { payload: { rejected: { type: 'array' } }, desc: '被 accept / max_size / max_count 挡下的文件 [{ name, reason }],它们不会出现在 change 里' },
900
+ cancel: { payload: { index: { type: 'number' }, item: { type: 'object' } }, desc: '点上传中项的「取消」:页面据此中止该文件的上传;随后同时抛 change(该项已从列表去掉)' },
901
+ retry: { payload: { index: { type: 'number' }, item: { type: 'object' } }, desc: '点失败项的「重试」:页面据此重新上传该文件并回写 status / percent' },
468
902
  upload: { payload: { files: { type: 'array' } }, desc: 'manual 时点「开始上传」:当前所有 status 为 pending 的项(带 file);页面据此发起上传并回写 status / percent' },
469
903
  },
470
904
  },
@@ -491,7 +925,7 @@ export function createUpload(): SomaComponentDefinition {
491
925
  const start = document.createElement('button');
492
926
  start.type = 'button';
493
927
  start.className = HIDDEN_CLASS;
494
- start.setAttribute('data-kit-start', '');
928
+ start.setAttribute(KIT_ATTR_START, '');
495
929
  root.appendChild(start);
496
930
  const ui: Ui = { file, trigger, hint, rejectNote, list, start, over: false, previews: new Map(), api };
497
931
  uis.set(root, ui);
@@ -506,19 +940,31 @@ export function createUpload(): SomaComponentDefinition {
506
940
  };
507
941
  const onRootClick = (event: Event): void => {
508
942
  const target = event.target as HTMLElement | null;
509
- const rm = target?.closest<HTMLElement>('[data-kit-remove]');
943
+ const retry = target?.closest<HTMLElement>(`[${KIT_ATTR_RETRY}]`);
944
+ if (retry) {
945
+ const p = api.props();
946
+ if (!canEdit(p)) return;
947
+ const index = Number(retry.getAttribute(KIT_ATTR_RETRY));
948
+ const hit = itemsOf(p.value)[index];
949
+ if (hit !== undefined) api.emit('retry', { index, item: hit });
950
+ return;
951
+ }
952
+ const rm = target?.closest<HTMLElement>(`[${KIT_ATTR_REMOVE}]`);
510
953
  if (rm) {
511
954
  const p = api.props();
512
955
  if (!canEdit(p)) return;
513
- const index = Number(rm.getAttribute('data-kit-remove'));
514
- api.emit('change', { value: itemsOf(p.value).filter((_it, i) => i !== index) });
956
+ const index = Number(rm.getAttribute(KIT_ATTR_REMOVE));
957
+ const all = itemsOf(p.value);
958
+ // 上传中的项点它 = 取消:先抛 cancel(页面据此中止上传),再从列表移除
959
+ if (rm.hasAttribute(KIT_ATTR_CANCEL) && all[index] !== undefined) api.emit('cancel', { index, item: all[index] });
960
+ api.emit('change', { value: all.filter((_it, i) => i !== index) });
515
961
  return;
516
962
  }
517
- if (target?.closest('[data-kit-add]')) {
963
+ if (target?.closest(`[${KIT_ATTR_ADD}]`)) {
518
964
  open();
519
965
  return;
520
966
  }
521
- if (target?.closest('[data-kit-start]')) {
967
+ if (target?.closest(`[${KIT_ATTR_START}]`)) {
522
968
  const p = api.props();
523
969
  if (!canEdit(p)) return;
524
970
  const files = pendingOf(itemsOf(p.value));
@@ -586,6 +1032,6 @@ export function createUpload(): SomaComponentDefinition {
586
1032
  const ui = uis.get(root);
587
1033
  if (ui) paint(root, p, ui);
588
1034
  },
589
- })),
1035
+ }), { self: { level: 'control' } }), // 上传整体是一个输入控件(字段值是文件列表)
590
1036
  };
591
1037
  }