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
@@ -10,9 +10,10 @@ import type { SomaComponentDefinition } from 'soma-core';
10
10
  import type { CollectionItem } from 'soma-core/keyboard';
11
11
  import { kitKey, kitText } from '../i18n/kit-text';
12
12
  import { kitIcon } from './icons';
13
+ import { setKitFace } from '../recipes';
13
14
  import {
14
- CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP,
15
- applyDisabled, bool, createKitController, joinClass, nextUid, num, optionsOf, sameValue, setAttr, setBoolAttr, sizeOf, str,
15
+ CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, OPTIONS_PROP, SIZE_PROP,
16
+ applyCommon, applyDisabled, bool, createKitController, joinClass, nextUid, num, optionsOf, sameValue, setAttr, setBoolAttr, sizeOf, str, withInvalid,
16
17
  type KitApi, type KitOption, type KitProps, type KitSize,
17
18
  } from './shared';
18
19
  import {
@@ -24,25 +25,25 @@ import {
24
25
  // ---- Tailwind 类常量与候选类清单 ----
25
26
 
26
27
  const ROOT_CLASS: Record<KitSize, string> = {
27
- sm: 'relative flex min-h-8 w-full flex-wrap items-center gap-1 rounded-md border border-input bg-surface px-2 py-0.5 text-sm text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
28
- md: 'relative flex min-h-9 w-full flex-wrap items-center gap-1 rounded-md border border-input bg-surface px-2 py-1 text-sm text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
28
+ sm: 'relative flex min-h-6 w-full flex-wrap items-center gap-1 rounded-md border border-input bg-surface px-2 py-0.5 text-sm text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
29
+ md: 'relative flex min-h-8 w-full flex-wrap items-center gap-1 rounded-md border border-input bg-surface px-2 py-0.5 text-sm text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
29
30
  lg: 'relative flex min-h-10 w-full flex-wrap items-center gap-2 rounded-md border border-input bg-surface px-3 py-1 text-base text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
30
31
  };
31
32
  const ROOT_DISABLED_CLASS: Record<KitSize, string> = {
32
- sm: 'relative flex min-h-8 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md border border-input bg-surface-sunken px-2 py-0.5 text-sm text-fg-subtle opacity-60',
33
- md: 'relative flex min-h-9 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md border border-input bg-surface-sunken px-2 py-1 text-sm text-fg-subtle opacity-60',
33
+ sm: 'relative flex min-h-6 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md border border-input bg-surface-sunken px-2 py-0.5 text-sm text-fg-subtle opacity-60',
34
+ md: 'relative flex min-h-8 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md border border-input bg-surface-sunken px-2 py-0.5 text-sm text-fg-subtle opacity-60',
34
35
  lg: 'relative flex min-h-10 w-full cursor-not-allowed flex-wrap items-center gap-2 rounded-md border border-input bg-surface-sunken px-3 py-1 text-base text-fg-subtle opacity-60',
35
36
  };
36
- const TOKEN_CLASS = 'inline-flex items-center gap-1 rounded-md border border-border-subtle bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted';
37
- const REMOVE_CLASS = 'inline-flex cursor-pointer items-center rounded-md px-0.5 text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
38
- const INPUT_CLASS = 'min-w-24 flex-1 appearance-none autofill-clear bg-surface px-1 py-0.5 text-fg placeholder:text-fg-subtle focus-visible:outline-none disabled:cursor-not-allowed disabled:bg-surface-sunken';
37
+ const TOKEN_CLASS = 'inline-flex items-center gap-1 rounded-md border border-border-subtle bg-surface-sunken px-2 py-0 text-sm font-medium text-fg-muted';
38
+ const REMOVE_CLASS = 'inline-flex min-h-5 min-w-5 cursor-pointer items-center justify-center rounded-md px-0.5 text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
39
+ const INPUT_CLASS = 'min-w-24 flex-1 appearance-none autofill-clear bg-surface px-1 py-0 text-fg placeholder:text-fg-subtle focus-visible:outline-none disabled:cursor-not-allowed disabled:bg-surface-sunken';
39
40
 
40
41
  /** 本组件自带的类(并入基础组件候选类清单) */
41
42
  export const KIT_TAG_INPUT_CLASS_CANDIDATES: readonly string[] = Object.freeze([
42
43
  ...new Set([
43
44
  ...Object.values(ROOT_CLASS).join(' ').split(' '),
44
45
  ...Object.values(ROOT_DISABLED_CLASS).join(' ').split(' '),
45
- ...[TOKEN_CLASS, REMOVE_CLASS, INPUT_CLASS, EMPTY_ROW_CLASS].join(' ').split(' '),
46
+ ...[TOKEN_CLASS, REMOVE_CLASS, INPUT_CLASS, EMPTY_ROW_CLASS, FIELD_INVALID_CLASS].join(' ').split(' '),
46
47
  ...KIT_POPUP_CLASS_CANDIDATES,
47
48
  ...KIT_DROPDOWN_CLASS_CANDIDATES,
48
49
  ]),
@@ -203,7 +204,9 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
203
204
  const values = valuesOf(p.value);
204
205
  const editable = canEdit(p);
205
206
  const size = sizeOf(p.size);
206
- root.className = joinClass(bool(p.disabled) ? ROOT_DISABLED_CLASS[size] : ROOT_CLASS[size], p.class);
207
+ root.className = joinClass(withInvalid(bool(p.disabled) ? ROOT_DISABLED_CLASS[size] : ROOT_CLASS[size], bool(p.invalid)), p.class);
208
+ // 质感标记:根是带边框的输入外壳(field),里面的 input 无边不标
209
+ setKitFace(root, 'field');
207
210
  root.setAttribute('role', 'group');
208
211
  setAttr(root, 'aria-label', str(p.aria_label));
209
212
  // 标签:每次重建(数量小),输入框与面板元素保持不变以保住焦点与输入法状态
@@ -212,6 +215,7 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
212
215
  const token = document.createElement('span');
213
216
  token.setAttribute(TOKEN_ATTR, String(index));
214
217
  token.className = TOKEN_CLASS;
218
+ setKitFace(token, 'raised');
215
219
  const text = document.createElement('span');
216
220
  text.textContent = labelOf(options, v);
217
221
  token.appendChild(text);
@@ -231,9 +235,8 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
231
235
  applyDisabled(ui.input, bool(p.disabled));
232
236
  setBoolAttr(ui.input, 'readonly', bool(p.readonly));
233
237
  if (bool(p.readonly)) ui.input.setAttribute('aria-readonly', 'true'); else ui.input.removeAttribute('aria-readonly');
234
- setAttr(ui.input, 'id', str(p.id));
235
- setAttr(ui.input, 'name', str(p.name));
236
- setAttr(ui.input, 'aria-label', str(p.aria_label) === '' ? str(p.placeholder, kitText('soma.kit.ti_placeholder', undefined, root)) : str(p.aria_label));
238
+ const ariaLabel = str(p.aria_label) === '' ? str(p.placeholder, kitText('soma.kit.ti_placeholder', undefined, root)) : str(p.aria_label);
239
+ applyCommon(ui.input, { ...p, aria_label: ariaLabel });
237
240
  if (!editable) ui.open = false;
238
241
  paintPanel(ui, p);
239
242
  if (ui.pendingFocus !== null) {
@@ -294,6 +297,7 @@ export function createTagInput(): SomaComponentDefinition {
294
297
  disabled: { type: 'boolean', default: false },
295
298
  readonly: { type: 'boolean', default: false },
296
299
  ...ID_PROPS,
300
+ ...INVALID_PROPS,
297
301
  size: SIZE_PROP,
298
302
  class: CLASS_PROP,
299
303
  },
@@ -303,7 +307,7 @@ export function createTagInput(): SomaComponentDefinition {
303
307
  },
304
308
  },
305
309
  templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS.md}"></div>`,
306
- controllerFactory: createKitController({
310
+ controllerFactory: createKitController(() => ({
307
311
  attach(root, api) {
308
312
  const ui = buildUi(root, api);
309
313
  uis.set(root, ui);
@@ -459,6 +463,6 @@ export function createTagInput(): SomaComponentDefinition {
459
463
  const ui = uis.get(root);
460
464
  if (ui) paint(root, p, ui);
461
465
  },
462
- }),
466
+ })),
463
467
  };
464
468
  }
package/src/base/tag.ts CHANGED
@@ -3,35 +3,42 @@
3
3
 
4
4
  import type { SomaComponentDefinition } from 'soma-core';
5
5
  import { kitLocaleAt, kitText } from '../i18n/kit-text';
6
- import { kitIcon } from './icons';
6
+ import { KIT_ICON_NAMES, kitIcon, type KitIconName } from './icons';
7
+ import { setKitFace } from '../recipes';
8
+ import {
9
+ KIT_TAG_UNKNOWN_DOT, KIT_TAG_UNKNOWN_DOT_CORE, KIT_TAG_UNKNOWN_OUTLINE, KIT_TAG_UNKNOWN_SOFT, KIT_TAG_UNKNOWN_CLASS_CANDIDATES,
10
+ } from '../recipes/status';
7
11
  import {
8
12
  CLASS_PROP, SIZE_PROP, OPTIONS_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES,
9
13
  bool, classCandidates, createKitController, displayOf, joinClass, optionsOf, paintBadge, sizeOf, str, toneOf, withBadgeAnchor, withTooltip,
10
- type KitSize, type KitTone,
14
+ valueIsEmpty, type KitSize, type KitTone,
11
15
  } from './shared';
12
16
 
17
+ /** 空值占位(静默灰字,无底无边无内边距) */
18
+ const EMPTY_PLACEHOLDER_CLASS = 'text-fg-subtle';
19
+
13
20
  // 档位 × 语气,每格一整串字面量
14
21
  export const TAG_CLASS: Record<KitSize, Record<KitTone, string>> = {
15
22
  sm: {
16
- neutral: 'inline-flex items-center rounded-md border border-border-subtle bg-surface-sunken px-1.5 py-0.5 text-xs font-medium text-fg-muted',
17
- info: 'inline-flex items-center rounded-md border border-info-on-soft/20 bg-info-soft px-1.5 py-0.5 text-xs font-medium text-info-on-soft',
18
- success: 'inline-flex items-center rounded-md border border-success-on-soft/20 bg-success-soft px-1.5 py-0.5 text-xs font-medium text-success-on-soft',
19
- warning: 'inline-flex items-center rounded-md border border-warning-on-soft/20 bg-warning-soft px-1.5 py-0.5 text-xs font-medium text-warning-on-soft',
20
- danger: 'inline-flex items-center rounded-md border border-danger-on-soft/20 bg-danger-soft px-1.5 py-0.5 text-xs font-medium text-danger-on-soft',
23
+ neutral: 'inline-flex items-center rounded-full bg-surface-sunken px-1.5 py-0.5 text-xs font-medium text-fg-muted',
24
+ info: 'inline-flex items-center rounded-full bg-info-soft px-1.5 py-0.5 text-xs font-medium text-info-on-soft',
25
+ success: 'inline-flex items-center rounded-full bg-success-soft px-1.5 py-0.5 text-xs font-medium text-success-on-soft',
26
+ warning: 'inline-flex items-center rounded-full bg-warning-soft px-1.5 py-0.5 text-xs font-medium text-warning-on-soft',
27
+ danger: 'inline-flex items-center rounded-full bg-danger-soft px-1.5 py-0.5 text-xs font-medium text-danger-on-soft',
21
28
  },
22
29
  md: {
23
- neutral: 'inline-flex items-center rounded-md border border-border-subtle bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted',
24
- info: 'inline-flex items-center rounded-md border border-info-on-soft/20 bg-info-soft px-2 py-0.5 text-sm font-medium text-info-on-soft',
25
- success: 'inline-flex items-center rounded-md border border-success-on-soft/20 bg-success-soft px-2 py-0.5 text-sm font-medium text-success-on-soft',
26
- warning: 'inline-flex items-center rounded-md border border-warning-on-soft/20 bg-warning-soft px-2 py-0.5 text-sm font-medium text-warning-on-soft',
27
- danger: 'inline-flex items-center rounded-md border border-danger-on-soft/20 bg-danger-soft px-2 py-0.5 text-sm font-medium text-danger-on-soft',
30
+ neutral: 'inline-flex items-center rounded-full bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted',
31
+ info: 'inline-flex items-center rounded-full bg-info-soft px-2 py-0.5 text-sm font-medium text-info-on-soft',
32
+ success: 'inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-sm font-medium text-success-on-soft',
33
+ warning: 'inline-flex items-center rounded-full bg-warning-soft px-2 py-0.5 text-sm font-medium text-warning-on-soft',
34
+ danger: 'inline-flex items-center rounded-full bg-danger-soft px-2 py-0.5 text-sm font-medium text-danger-on-soft',
28
35
  },
29
36
  lg: {
30
- neutral: 'inline-flex items-center rounded-md border border-border-subtle bg-surface-sunken px-2.5 py-1 text-base font-medium text-fg-muted',
31
- info: 'inline-flex items-center rounded-md border border-info-on-soft/20 bg-info-soft px-2.5 py-1 text-base font-medium text-info-on-soft',
32
- success: 'inline-flex items-center rounded-md border border-success-on-soft/20 bg-success-soft px-2.5 py-1 text-base font-medium text-success-on-soft',
33
- warning: 'inline-flex items-center rounded-md border border-warning-on-soft/20 bg-warning-soft px-2.5 py-1 text-base font-medium text-warning-on-soft',
34
- danger: 'inline-flex items-center rounded-md border border-danger-on-soft/20 bg-danger-soft px-2.5 py-1 text-base font-medium text-danger-on-soft',
37
+ neutral: 'inline-flex items-center rounded-full bg-surface-sunken px-2.5 py-1 text-base font-medium text-fg-muted',
38
+ info: 'inline-flex items-center rounded-full bg-info-soft px-2.5 py-1 text-base font-medium text-info-on-soft',
39
+ success: 'inline-flex items-center rounded-full bg-success-soft px-2.5 py-1 text-base font-medium text-success-on-soft',
40
+ warning: 'inline-flex items-center rounded-full bg-warning-soft px-2.5 py-1 text-base font-medium text-warning-on-soft',
41
+ danger: 'inline-flex items-center rounded-full bg-danger-soft px-2.5 py-1 text-base font-medium text-danger-on-soft',
35
42
  },
36
43
  };
37
44
 
@@ -72,9 +79,9 @@ const DOT_RING: Record<KitTone, string> = {
72
79
 
73
80
  // variant: outline / solid:尺寸壳与色彩分开给(互不含对方的属性,不会同类冲突)
74
81
  const SHAPE_CLASS: Record<KitSize, string> = {
75
- sm: 'inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-xs font-medium',
76
- md: 'inline-flex items-center gap-1.5 rounded-md px-2 py-0.5 text-sm font-medium',
77
- lg: 'inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-base font-medium',
82
+ sm: 'inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-xs font-medium',
83
+ md: 'inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-sm font-medium',
84
+ lg: 'inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-base font-medium',
78
85
  };
79
86
  const OUTLINE_CLASS: Record<KitTone, string> = {
80
87
  neutral: 'border border-border bg-transparent text-fg-muted',
@@ -92,7 +99,7 @@ const SOLID_CLASS: Record<KitTone, string> = {
92
99
  };
93
100
  // 可点击:整枚标签是一个按钮(内层 span),悬停淡出、焦点环
94
101
  const CLICK_CLASS = 'inline-flex cursor-pointer items-center gap-1.5 rounded-sm transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
95
- const REMOVE_CLASS = 'inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm text-current opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
102
+ const REMOVE_CLASS = 'hit-area inline-flex h-4 w-4 shrink-0 p-0 items-center justify-center rounded-sm text-current opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
96
103
  const ICON_CLASS = 'inline-block shrink-0';
97
104
  const SOFT_GAP_CLASS = 'gap-1.5';
98
105
 
@@ -102,14 +109,19 @@ export const KIT_TAG_CLASS_CANDIDATES: readonly string[] = Object.freeze([
102
109
  ...Object.values(DOT_CLASS).join(' ').split(' '),
103
110
  ...[Object.values(DOT_ROOT), Object.values(DOT_WRAP), Object.values(DOT_CORE), Object.values(DOT_RING)].flat().join(' ').split(' '),
104
111
  ...classCandidates(
105
- Object.values(SHAPE_CLASS), Object.values(OUTLINE_CLASS), Object.values(SOLID_CLASS), CLICK_CLASS, REMOVE_CLASS, ICON_CLASS, SOFT_GAP_CLASS,
106
- KIT_BADGE_CLASS_CANDIDATES,
112
+ Object.values(SHAPE_CLASS), Object.values(OUTLINE_CLASS), Object.values(SOLID_CLASS), CLICK_CLASS, REMOVE_CLASS, ICON_CLASS, SOFT_GAP_CLASS, EMPTY_PLACEHOLDER_CLASS,
113
+ KIT_BADGE_CLASS_CANDIDATES, KIT_TAG_UNKNOWN_CLASS_CANDIDATES,
107
114
  ),
108
115
  ]),
109
116
  ]);
110
117
 
111
118
  type TagVariant = 'soft' | 'outline' | 'solid' | 'dot';
112
119
 
120
+ /** 选项 icon 只认 kit 图标名(SVG);符号字符 / 未知名一律忽略,状态要双编码就写图标名 + 文字 */
121
+ function optionIconOf(raw: unknown): KitIconName | null {
122
+ return typeof raw === 'string' && (KIT_ICON_NAMES as readonly string[]).includes(raw) ? raw as KitIconName : null;
123
+ }
124
+
113
125
  function variantOf(raw: unknown): TagVariant {
114
126
  return raw === 'outline' || raw === 'solid' || raw === 'dot' ? raw : 'soft';
115
127
  }
@@ -124,7 +136,7 @@ export function createTag(): SomaComponentDefinition {
124
136
  options: OPTIONS_PROP,
125
137
  format: { type: 'string', default: '', desc: '同 Text.format' },
126
138
  locale: { type: 'string', default: '', desc: '格式化语言;缺省取页面语言(page.locale),都没声明为 zh-CN' },
127
- tone: { type: 'enum', values: ['neutral', 'info', 'success', 'warning', 'danger'], default: 'neutral', desc: '语气' },
139
+ tone: { type: 'enum', values: ['neutral', 'info', 'success', 'warning', 'danger', 'unknown'], default: 'neutral', desc: '语气;unknown = 未知 / 无法判断(虚线描边、透明底、中性字色,与 neutral 区分)。选项 options[].tone 同样可写 unknown;options[].icon 写 kit 图标名(如 info / check / warning)则文字前画该图标,与文字双编码(装饰,读屏忽略)' },
128
140
  placeholder: { type: 'string', default: '', desc: '空值时显示的文字' },
129
141
  dot: { type: 'boolean', default: false, desc: '文字前加一个按语气着色的状态点(在线 / 离线这类状态列);值到语气的对照用 options[].tone 显式给' },
130
142
  variant: { type: 'enum', values: ['soft', 'outline', 'solid', 'dot'], default: 'soft', desc: 'soft = 带浅底;outline = 描边;solid = 实心;dot = 只有状态点 + 文字(StatusDot 用法,点按 tone 着色)' },
@@ -143,8 +155,8 @@ export function createTag(): SomaComponentDefinition {
143
155
  click: { payload: { value: { type: 'string' } }, desc: 'clickable 时点击或 Enter / Space' },
144
156
  },
145
157
  },
146
- templateHtml: '<span data-soma-id="root" class="inline-flex items-center rounded-md border border-border-subtle bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted"></span>',
147
- controllerFactory: createKitController(withTooltip({
158
+ templateHtml: '<span data-soma-id="root" class="inline-flex items-center rounded-full bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted"></span>',
159
+ controllerFactory: createKitController(() => withTooltip({
148
160
  attach(root, api) {
149
161
  const valueOf = (): unknown => api.props().value;
150
162
  const onClick = (event: Event): void => {
@@ -178,24 +190,38 @@ export function createTag(): SomaComponentDefinition {
178
190
  };
179
191
  },
180
192
  render(root, p) {
181
- const { text, option } = displayOf(p.value, optionsOf(p.options), str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), str(p.placeholder));
193
+ const shown = displayOf(p.value, optionsOf(p.options), str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), str(p.placeholder));
194
+ const option = shown.option;
195
+ // 选项只写 icon 没写 label(optionsOf 视作纯图标选项):Tag 的图标是装饰,状态靠文字,回退显示值文字,不留一枚没有可读文字的标签
196
+ const text = shown.text === '' && option !== null && option.icon !== undefined ? str(option.value) : shown.text;
182
197
  const tone = option?.tone ?? toneOf(p.tone, 'neutral');
198
+ // unknown 语气:命中选项带 unknown,或没有命中语气的选项且 tone prop 为 unknown
199
+ const unknownTone = option?.unknown === true || (option?.tone === undefined && p.tone === 'unknown');
183
200
  root.textContent = '';
201
+ // 空值(null / undefined / '' / [])不画标签:只是一个标准的静默占位(placeholder,空则什么也不画),
202
+ // 摘要 / 详情 / 表格单元格由此一致,不会出现一枚写着「-」的空标签
203
+ if (valueIsEmpty(p.value)) {
204
+ setKitFace(root, null);
205
+ root.className = joinClass(EMPTY_PLACEHOLDER_CLASS, p.class);
206
+ root.textContent = shown.text;
207
+ return;
208
+ }
184
209
  if (p.variant === 'dot') {
185
210
  const size = sizeOf(p.size);
186
211
  const wrap = document.createElement('span');
187
212
  wrap.setAttribute('aria-hidden', 'true');
188
213
  wrap.className = DOT_WRAP[size];
189
- if (bool(p.pulse)) {
214
+ if (bool(p.pulse) && !unknownTone) {
190
215
  const ring = document.createElement('span');
191
216
  ring.className = DOT_RING[tone];
192
217
  wrap.appendChild(ring);
193
218
  }
194
219
  const core = document.createElement('span');
195
- core.className = DOT_CORE[tone];
220
+ core.className = unknownTone ? KIT_TAG_UNKNOWN_DOT_CORE : DOT_CORE[tone];
196
221
  wrap.appendChild(core);
197
222
  root.appendChild(wrap);
198
223
  if (text !== '') root.appendChild(document.createTextNode(text));
224
+ setKitFace(root, null);
199
225
  root.className = joinClass(DOT_ROOT[size], p.class);
200
226
  return;
201
227
  }
@@ -217,10 +243,14 @@ export function createTag(): SomaComponentDefinition {
217
243
  if (bool(p.dot) && variant !== 'solid') {
218
244
  const dot = document.createElement('span');
219
245
  dot.setAttribute('aria-hidden', 'true');
220
- dot.className = DOT_CLASS[tone];
246
+ dot.className = unknownTone ? KIT_TAG_UNKNOWN_DOT : DOT_CLASS[tone];
221
247
  body.appendChild(dot);
222
248
  }
223
- if (icon !== '') {
249
+ // 选项图标(kit 图标名,SVG):与文字双编码;有它时优先于 icon prop 的符号字符
250
+ const optIcon = optionIconOf(option?.icon);
251
+ if (optIcon !== null) {
252
+ body.appendChild(kitIcon(optIcon, size === 'lg' ? 'sm' : 'xs'));
253
+ } else if (icon !== '') {
224
254
  const ic = document.createElement('span');
225
255
  ic.setAttribute('aria-hidden', 'true');
226
256
  ic.className = ICON_CLASS;
@@ -237,12 +267,16 @@ export function createTag(): SomaComponentDefinition {
237
267
  x.appendChild(kitIcon('close', 'xs'));
238
268
  root.appendChild(x);
239
269
  }
270
+ // 质感标记:soft(浅底)/ solid(实心)有「面」标 raised;outline 透明底、dot 无面,不标
271
+ setKitFace(root, variant === 'outline' ? null : 'raised');
240
272
  const hasBadge = paintBadge(root, p);
273
+ const hasIcon = icon !== '' || optIcon !== null;
274
+ const softLook = unknownTone ? KIT_TAG_UNKNOWN_SOFT[size] : TAG_CLASS[size][tone];
241
275
  const look = variant === 'outline'
242
- ? `${SHAPE_CLASS[size]} ${OUTLINE_CLASS[tone]}`
276
+ ? `${SHAPE_CLASS[size]} ${unknownTone ? KIT_TAG_UNKNOWN_OUTLINE : OUTLINE_CLASS[tone]}`
243
277
  : variant === 'solid'
244
- ? `${SHAPE_CLASS[size]} ${SOLID_CLASS[tone]}`
245
- : (icon !== '' || removable || clickable) ? `${TAG_CLASS[size][tone]} ${SOFT_GAP_CLASS}` : TAG_CLASS[size][tone];
278
+ ? `${SHAPE_CLASS[size]} ${unknownTone ? KIT_TAG_UNKNOWN_OUTLINE : SOLID_CLASS[tone]}`
279
+ : (hasIcon || removable || clickable) ? `${softLook} ${SOFT_GAP_CLASS}` : softLook;
246
280
  root.className = joinClass(withBadgeAnchor(look, hasBadge), p.class);
247
281
  },
248
282
  })),
package/src/base/text.ts CHANGED
@@ -5,27 +5,50 @@
5
5
 
6
6
  import type { SomaComponentDefinition } from 'soma-core';
7
7
  import { TAG_CLASS } from './tag';
8
+ import { formatDateRangeValue, formatMoneyValue, formatPercentValue } from '../object-renderer/field-value';
8
9
  import { kitLocaleAt, kitText } from '../i18n/kit-text';
10
+ import { KIT_TIPS_SCOPE_ATTR } from './hint-tips';
9
11
  import {
10
12
  CLASS_PROP, SIZE_PROP, OPTIONS_PROP,
11
- bool, classCandidates, createKitController, displayOf, joinClass, optionsOf, sizeOf, str, type KitSize,
13
+ bool, classCandidates, createKitController, displayOf, joinClass, optionsOf, sizeOf, str, type KitSize, type KitTone,
12
14
  } from './shared';
13
15
 
14
16
  // 每档一整串字面量,不拼接
17
+ const TEXT_SIZE_CLASS: Record<KitSize, string> = {
18
+ sm: 'text-sm',
19
+ md: 'text-base',
20
+ lg: 'text-lg',
21
+ };
15
22
  const TEXT_CLASS: Record<KitSize, string> = {
16
- sm: 'text-sm text-fg',
17
- md: 'text-base text-fg',
18
- lg: 'text-lg text-fg',
23
+ sm: `${TEXT_SIZE_CLASS.sm} text-fg`,
24
+ md: `${TEXT_SIZE_CLASS.md} text-fg`,
25
+ lg: `${TEXT_SIZE_CLASS.lg} text-fg`,
26
+ };
27
+ // 语气纯文字着色(tone_as: text):只换字色,无底无描边;neutral 用次要字色,其余取 -on-soft 配对字色
28
+ export const TONE_AS_TEXT = 'text' as const;
29
+ const TONE_TEXT_COLOR: Record<KitTone, string> = {
30
+ neutral: 'text-fg-muted',
31
+ info: 'text-info-on-soft',
32
+ success: 'text-success-on-soft',
33
+ warning: 'text-warning-on-soft',
34
+ danger: 'text-danger-on-soft',
35
+ };
36
+ // 字阶取 TEXT_SIZE_CLASS 里已有的那一档(不另写一份字阶类,G101 typography 不增)
37
+ const toneTextClass = (size: KitSize, tone: KitTone): string => `${TEXT_SIZE_CLASS[size]} ${TONE_TEXT_COLOR[tone]}`;
38
+ const TONE_TEXT_CLASS: Record<KitSize, Record<KitTone, string>> = {
39
+ sm: { neutral: toneTextClass('sm', 'neutral'), info: toneTextClass('sm', 'info'), success: toneTextClass('sm', 'success'), warning: toneTextClass('sm', 'warning'), danger: toneTextClass('sm', 'danger') },
40
+ md: { neutral: toneTextClass('md', 'neutral'), info: toneTextClass('md', 'info'), success: toneTextClass('md', 'success'), warning: toneTextClass('md', 'warning'), danger: toneTextClass('md', 'danger') },
41
+ lg: { neutral: toneTextClass('lg', 'neutral'), info: toneTextClass('lg', 'info'), success: toneTextClass('lg', 'success'), warning: toneTextClass('lg', 'warning'), danger: toneTextClass('lg', 'danger') },
19
42
  };
20
- // copyable 时根元素变成一行:文字 + 复制钮
43
+ // copyable 时根元素变成一行:文字 + 复制钮(whitespace-nowrap:值与复制钮是同一个不折行的行内组,宽松密度 / 窄格里也不会把钮挤到下一行)
21
44
  const COPY_ROOT_CLASS: Record<KitSize, string> = {
22
- sm: 'inline-flex items-center gap-2 text-sm text-fg',
23
- md: 'inline-flex items-center gap-2 text-base text-fg',
24
- lg: 'inline-flex items-center gap-2 text-lg text-fg',
45
+ sm: 'inline-flex items-center gap-2 whitespace-nowrap text-sm text-fg',
46
+ md: 'inline-flex items-center gap-2 whitespace-nowrap text-base text-fg',
47
+ lg: 'inline-flex items-center gap-2 whitespace-nowrap text-lg text-fg',
25
48
  };
26
- const COPY_BTN_CLASS = 'inline-flex shrink-0 cursor-pointer items-center rounded-sm px-1.5 py-0.5 text-xs font-medium text-primary transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
49
+ const COPY_BTN_CLASS = 'inline-flex shrink-0 cursor-pointer items-center rounded-sm px-1.5 py-0.5 text-xs font-medium text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
27
50
 
28
- export const KIT_TEXT_CLASS_CANDIDATES: readonly string[] = classCandidates(Object.values(COPY_ROOT_CLASS), COPY_BTN_CLASS, ...Object.values(TAG_CLASS).flatMap((m) => Object.values(m)));
51
+ export const KIT_TEXT_CLASS_CANDIDATES: readonly string[] = classCandidates(Object.values(COPY_ROOT_CLASS), COPY_BTN_CLASS, ...Object.values(TONE_TEXT_CLASS).flatMap((m) => Object.values(m)), ...Object.values(TAG_CLASS).flatMap((m) => Object.values(m)));
29
52
 
30
53
  const COPIED_MS = 1500;
31
54
 
@@ -43,6 +66,38 @@ function stateOf(root: HTMLElement): CopyState {
43
66
  return s;
44
67
  }
45
68
 
69
+ function resolveTextDisplay(p: Record<string, unknown>, root: HTMLElement): { text: string; option: ReturnType<typeof displayOf>['option'] } {
70
+ const opts = optionsOf(p.options);
71
+ const raw = p.value;
72
+ const placeholder = str(p.placeholder);
73
+ // 显式空串 '' = 有意留白,渲染为空白;null / undefined / 空数组按占位
74
+ if (raw === '') return { text: '', option: null };
75
+ if (raw === null || raw === undefined || raw === '' || (Array.isArray(raw) && raw.length === 0)) {
76
+ return { text: placeholder, option: null };
77
+ }
78
+ if (opts.length > 0) {
79
+ return displayOf(raw, opts, str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), placeholder);
80
+ }
81
+ const fmt = str(p.format).trim();
82
+ const unit = str(p.unit).trim();
83
+ const currency = str(p.currency).trim();
84
+ if (
85
+ fmt === 'daterange' ||
86
+ (fmt === '' && Array.isArray(raw) && raw.length === 2 && typeof raw[0] === 'string' && /^\d{4}-\d{2}-\d{2}/.test(raw[0])) ||
87
+ (fmt === '' && typeof raw === 'object' && !Array.isArray(raw) && ('start' in (raw as object) || 'end' in (raw as object) || 'from' in (raw as object) || 'to' in (raw as object)))
88
+ ) {
89
+ const dr = formatDateRangeValue(raw);
90
+ return { text: dr !== '' ? dr : placeholder, option: null };
91
+ }
92
+ if (fmt === 'percent') {
93
+ return { text: formatPercentValue(raw), option: null };
94
+ }
95
+ if (fmt === 'money' || fmt === 'currency' || fmt.startsWith('currency:') || (fmt === '' && (unit !== '' || currency !== ''))) {
96
+ return { text: formatMoneyValue(raw, { unit, currency, format: fmt }), option: null };
97
+ }
98
+ return displayOf(raw, opts, fmt, str(p.locale, kitLocaleAt(root) || 'zh-CN'), placeholder);
99
+ }
100
+
46
101
  export function createText(): SomaComponentDefinition {
47
102
  return {
48
103
  contract: {
@@ -51,12 +106,15 @@ export function createText(): SomaComponentDefinition {
51
106
  props: {
52
107
  value: { type: 'string', default: '', desc: '任意标量或数组;统一以文字显示' },
53
108
  options: OPTIONS_PROP,
54
- format: { type: 'string', default: '', desc: 'number / percent / currency:CNY / date / datetime / relative / bytes / duration:s' },
109
+ format: { type: 'string', default: '', desc: 'number / money / percent / currency:CNY / date / datetime / daterange / relative / bytes / duration:s' },
110
+ unit: { type: 'string', default: '', desc: '金额或数值单位符号(如 $ / € / ¥)' },
111
+ currency: { type: 'string', default: '', desc: '币种代码(如 USD / EUR / CNY)' },
55
112
  locale: { type: 'string', default: '', desc: '格式化语言;缺省取页面语言(page.locale),都没声明为 zh-CN' },
56
113
  placeholder: { type: 'string', default: '', desc: '空值时显示的文字' },
57
114
  copyable: { type: 'boolean', default: false, desc: '文字后带「复制」钮,复制显示出来的文字' },
58
115
  copy_label: { type: 'string', default: '', desc: '复制钮文字;缺省取内置文案(按页面语言)' },
59
116
  copied_label: { type: 'string', default: '', desc: '复制成功后短暂显示的文字;缺省取内置文案(按页面语言)' },
117
+ tone_as: { type: 'string', default: 'tag', desc: '选项带 tone 时的呈现:tag = 徽标(缺省)/ text = 纯文字着色(无底无描边)' },
60
118
  size: SIZE_PROP,
61
119
  class: CLASS_PROP,
62
120
  },
@@ -65,14 +123,14 @@ export function createText(): SomaComponentDefinition {
65
123
  },
66
124
  },
67
125
  templateHtml: '<span data-soma-id="root" class="text-base text-fg"></span>',
68
- controllerFactory: createKitController({
126
+ controllerFactory: createKitController(() => ({
69
127
  attach(root, api) {
70
128
  const s = stateOf(root);
71
129
  const onClick = (event: Event): void => {
72
130
  const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-action="copy"]');
73
131
  if (!btn || !root.contains(btn)) return;
74
132
  const p = api.props();
75
- const { text } = displayOf(p.value, optionsOf(p.options), str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), str(p.placeholder));
133
+ const { text } = resolveTextDisplay(p, root);
76
134
  const done = (ok: boolean): void => {
77
135
  if (ok) {
78
136
  s.copied = true;
@@ -104,14 +162,17 @@ export function createText(): SomaComponentDefinition {
104
162
  };
105
163
  },
106
164
  render(root, p) {
107
- const { text, option } = displayOf(p.value, optionsOf(p.options), str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), str(p.placeholder));
165
+ const { text, option } = resolveTextDisplay(p, root);
108
166
  const tone = option?.tone;
109
167
  const size = sizeOf(p.size);
110
168
  const raw = p.value;
111
169
  const empty = raw === null || raw === undefined || raw === '' || (Array.isArray(raw) && raw.length === 0);
112
170
  root.textContent = text;
113
- if (!empty && text !== "") root.title = text;
114
- else root.removeAttribute("title");
171
+ // 不再给每个值写原生 title(无论是否被截断都冒气泡,且不可键盘 / 读屏):被截断的文字由 hint-tips 的委托在悬停 / 聚焦时现量、才挂 kitTooltip
172
+ root.removeAttribute('title');
173
+ // 自带 truncate 类的值自己标出提示作用范围(独立使用、不在表格 / 摘要格里时也有截断全文提示)
174
+ if (/(?:^|\s)(?:[a-z0-9*@-]+:)*truncate(?=\s|$)/.test(str(p.class))) root.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
175
+ else root.removeAttribute(KIT_TIPS_SCOPE_ATTR);
115
176
  if (bool(p.copyable) && !empty) {
116
177
  const s = stateOf(root);
117
178
  const btn = document.createElement('button');
@@ -124,11 +185,12 @@ export function createText(): SomaComponentDefinition {
124
185
  return;
125
186
  }
126
187
  if (!empty && !bool(p.copyable) && tone !== undefined) {
127
- root.className = joinClass(TAG_CLASS[size][tone], p.class);
188
+ // tone_as: text = 纯文字着色(text-<tone>-on-soft,无底无描边);缺省 tag = 徽标
189
+ root.className = joinClass(str(p.tone_as) === TONE_AS_TEXT ? TONE_TEXT_CLASS[size][tone] : TAG_CLASS[size][tone], p.class);
128
190
  return;
129
191
  }
130
192
  root.className = joinClass(TEXT_CLASS[size], p.class);
131
193
  },
132
- }),
194
+ })),
133
195
  };
134
196
  }
@@ -4,15 +4,38 @@
4
4
  // 根元素(data-soma-id="root")始终是原生 textarea;计数在它外层 span 的第二个子元素里。
5
5
 
6
6
  import type { SomaComponentDefinition } from 'soma-core';
7
+ import { mergeClass } from '../object-renderer/merge-class';
7
8
  import {
8
- CLASS_PROP, ID_PROPS, SIZE_PROP,
9
- applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, num, setBoolAttr, sizeOf, str, type KitProps, type KitSize,
9
+ CLASS_PROP, FIELD_INVALID_CLASS, FOCUS_RING, ID_PROPS, INVALID_PROPS, SIZE_PROP,
10
+ applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, num, setBoolAttr, sizeOf, str, withInvalid, type KitProps, type KitSize,
10
11
  } from './shared';
12
+ import {
13
+ KIT_PART_ATTRIBUTE,
14
+ KIT_PART_BUTTON,
15
+ KIT_PART_CONTROL,
16
+ KIT_PART_TEXTAREA,
17
+ kitControlPartOf,
18
+ kitControlRecipe,
19
+ kitSelectedRecipe,
20
+ } from '../recipes';
21
+
22
+ export {
23
+ KIT_PART_TEXTAREA,
24
+ KIT_PART_CONTROL,
25
+ KIT_PART_BUTTON,
26
+ kitControlRecipe,
27
+ kitControlPartOf,
28
+ kitSelectedRecipe,
29
+ };
30
+
31
+ function buildTextareaClass(size: KitSize): string {
32
+ return mergeClass(kitControlRecipe({ size, variant: 'outline', multiline: true }), 'aria-invalid:border-danger');
33
+ }
11
34
 
12
35
  const TEXTAREA_CLASS: Record<KitSize, string> = {
13
- sm: 'block w-full appearance-none autofill-clear resize-none rounded-md border border-input bg-surface px-2.5 py-1.5 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
14
- md: 'block w-full appearance-none autofill-clear resize-none rounded-md border border-input bg-surface px-3 py-2 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
15
- lg: 'block w-full appearance-none autofill-clear resize-none rounded-md border border-input bg-surface px-4 py-2.5 text-base text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
36
+ sm: buildTextareaClass('sm'),
37
+ md: buildTextareaClass('md'),
38
+ lg: buildTextareaClass('lg'),
16
39
  };
17
40
  const WRAP_CLASS = 'block w-full';
18
41
  const COUNTER_CLASS = 'mt-1 block text-end text-xs tabular-nums text-fg-subtle';
@@ -22,7 +45,7 @@ const FIT_SCROLL_CLASS = 'resize-none overflow-y-auto';
22
45
  const HIDDEN = 'hidden';
23
46
 
24
47
  export const KIT_TEXTAREA_CLASS_CANDIDATES: readonly string[] = classCandidates(
25
- Object.values(TEXTAREA_CLASS), WRAP_CLASS, COUNTER_CLASS, FIT_CLASS, FIT_SCROLL_CLASS, HIDDEN,
48
+ Object.values(TEXTAREA_CLASS), WRAP_CLASS, COUNTER_CLASS, FIT_CLASS, FIT_SCROLL_CLASS, HIDDEN, FIELD_INVALID_CLASS,
26
49
  );
27
50
 
28
51
  const ROWS_CAP = 40;
@@ -54,7 +77,7 @@ function fit(el: HTMLTextAreaElement, p: KitProps): void {
54
77
  scroll = need > max + 0.25;
55
78
  }
56
79
  el.rows = rows;
57
- el.className = joinClass(`${TEXTAREA_CLASS[sizeOf(p.size)]} ${scroll ? FIT_SCROLL_CLASS : FIT_CLASS}`, p.class);
80
+ el.className = joinClass(withInvalid(`${TEXTAREA_CLASS[sizeOf(p.size)]} ${scroll ? FIT_SCROLL_CLASS : FIT_CLASS}`, bool(p.invalid)), p.class);
58
81
  }
59
82
 
60
83
  function paintCounter(el: HTMLTextAreaElement, p: KitProps): void {
@@ -87,6 +110,7 @@ export function createTextarea(): SomaComponentDefinition {
87
110
  disabled: { type: 'boolean', default: false },
88
111
  readonly: { type: 'boolean', default: false },
89
112
  ...ID_PROPS,
113
+ ...INVALID_PROPS,
90
114
  size: SIZE_PROP,
91
115
  class: CLASS_PROP,
92
116
  },
@@ -94,8 +118,8 @@ export function createTextarea(): SomaComponentDefinition {
94
118
  change: { payload: { value: { type: 'string' } }, desc: '输入变化;disabled / readonly 时不抛' },
95
119
  },
96
120
  },
97
- templateHtml: `<span class="${WRAP_CLASS}"><textarea data-soma-id="root" rows="3" class="${TEXTAREA_CLASS.md}"></textarea><span class="${HIDDEN}"></span></span>`,
98
- controllerFactory: createKitController({
121
+ templateHtml: `<span class="${WRAP_CLASS}"><textarea data-soma-id="root" data-kit-part="${KIT_PART_TEXTAREA}" data-kit-face="field" rows="3" class="${TEXTAREA_CLASS.md}"></textarea><span class="${HIDDEN}"></span></span>`,
122
+ controllerFactory: createKitController(() => ({
99
123
  attach(root, api) {
100
124
  const el = root as HTMLTextAreaElement;
101
125
  const onInput = (): void => {
@@ -120,10 +144,12 @@ export function createTextarea(): SomaComponentDefinition {
120
144
  setBoolAttr(el, 'readonly', bool(p.readonly));
121
145
  applyDisabled(el, bool(p.disabled));
122
146
  applyCommon(el, p);
123
- el.className = joinClass(TEXTAREA_CLASS[sizeOf(p.size)], p.class);
147
+ const size = sizeOf(p.size);
148
+ el.setAttribute(KIT_PART_ATTRIBUTE, kitControlPartOf({ size, multiline: true }));
149
+ el.className = joinClass(withInvalid(TEXTAREA_CLASS[size], bool(p.invalid)), p.class);
124
150
  if (bool(p.auto_size)) fit(el, p);
125
151
  paintCounter(el, p);
126
152
  },
127
- }),
153
+ })),
128
154
  };
129
155
  }