soma-kit 0.1.11 → 0.1.12

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 (302) hide show
  1. package/README.md +103 -110
  2. package/bin/soma-kit.mjs +1 -1
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +13 -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 +776 -38
  8. package/spec/generated/kit-page.schema.json +1613 -224
  9. package/spec/kit-grammar.json +770 -529
  10. package/spec/kit-grammar.schema.json +1962 -392
  11. package/src/app/app-config.ts +371 -347
  12. package/src/app/component-gate.ts +12 -15
  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 +174 -31
  16. package/src/app/define-kit-view.ts +100 -0
  17. package/src/app/envelope.ts +1 -161
  18. package/src/app/index.ts +13 -2
  19. package/src/app/kit-view-context.ts +290 -0
  20. package/src/app/notify-renderer.ts +1 -115
  21. package/src/app/paged-list-adapter.ts +1 -240
  22. package/src/app/server-pages.ts +8 -2
  23. package/src/app/server.ts +491 -101
  24. package/src/app/submit.types.ts +1 -1
  25. package/src/app/theme-endpoint.ts +63 -0
  26. package/src/app/theme-runtime-shared.ts +1 -0
  27. package/src/app/theme-runtime.ts +663 -0
  28. package/src/base/action-busy.ts +2 -2
  29. package/src/base/action-gate.ts +4 -255
  30. package/src/base/action-slots.ts +47 -0
  31. package/src/base/alert.ts +5 -3
  32. package/src/base/avatar.ts +2 -2
  33. package/src/base/button.ts +46 -29
  34. package/src/base/cascader.ts +11 -12
  35. package/src/base/check-core.ts +1 -1
  36. package/src/base/choice.ts +28 -26
  37. package/src/base/class-candidates.ts +17 -0
  38. package/src/base/color-picker.ts +6 -6
  39. package/src/base/combobox.ts +5 -3
  40. package/src/base/command-palette.ts +9 -5
  41. package/src/base/countdown.ts +1 -1
  42. package/src/base/date-range.ts +25 -11
  43. package/src/base/date.ts +85 -17
  44. package/src/base/divider.ts +2 -2
  45. package/src/base/fab.ts +11 -4
  46. package/src/base/image.ts +1 -1
  47. package/src/base/index.ts +9 -3
  48. package/src/base/input.ts +42 -13
  49. package/src/base/kbd.ts +3 -1
  50. package/src/base/link.ts +4 -4
  51. package/src/base/listbox-core.ts +50 -30
  52. package/src/base/loading-gate.ts +133 -0
  53. package/src/base/mentions.ts +5 -5
  54. package/src/base/menu-button.ts +6 -1
  55. package/src/base/menu-core.ts +4 -0
  56. package/src/base/motion/aura.ts +2 -2
  57. package/src/base/motion/hover-3d.ts +2 -2
  58. package/src/base/motion/hover-gallery.ts +2 -2
  59. package/src/base/motion/marquee.ts +2 -2
  60. package/src/base/motion/text-rotate.ts +2 -2
  61. package/src/base/number.ts +93 -80
  62. package/src/base/otp.ts +4 -1
  63. package/src/base/permission-gate.ts +6 -0
  64. package/src/base/popover.ts +40 -8
  65. package/src/base/popup.ts +79 -14
  66. package/src/base/price-text.ts +2 -2
  67. package/src/base/progress.ts +2 -2
  68. package/src/base/qr-code.ts +4 -4
  69. package/src/base/qty-stepper.ts +9 -3
  70. package/src/base/range.ts +2 -2
  71. package/src/base/rating.ts +1 -1
  72. package/src/base/segmented.ts +4 -0
  73. package/src/base/select.ts +4 -3
  74. package/src/base/shared.ts +221 -29
  75. package/src/base/swap.ts +4 -1
  76. package/src/base/switch.ts +1 -1
  77. package/src/base/tag-input.ts +14 -10
  78. package/src/base/tag.ts +5 -1
  79. package/src/base/text.ts +39 -6
  80. package/src/base/textarea.ts +37 -11
  81. package/src/base/time-picker.ts +12 -9
  82. package/src/base/tree-select.ts +15 -8
  83. package/src/base/upload.ts +34 -5
  84. package/src/base/virtual-list.ts +107 -1
  85. package/src/biz/approval-desk/compile.ts +23 -41
  86. package/src/biz/auth-panel/compile.ts +37 -52
  87. package/src/biz/auth-panel/index.ts +1 -1
  88. package/src/biz/category-crud/compile.ts +22 -36
  89. package/src/biz/checkout-page/compile.ts +21 -5
  90. package/src/biz/compose.ts +13 -27
  91. package/src/biz/define.ts +5 -4
  92. package/src/biz/import-wizard/compile.ts +22 -26
  93. package/src/biz/import-wizard/hub.ts +126 -61
  94. package/src/biz/import-wizard/shell.ts +3 -3
  95. package/src/biz/index.ts +3 -3
  96. package/src/biz/landing-page/compile.ts +19 -3
  97. package/src/biz/link/hub.ts +49 -20
  98. package/src/biz/link/shared.ts +115 -118
  99. package/src/biz/master-sub/compile.ts +31 -44
  100. package/src/biz/multi-board/compile.ts +34 -49
  101. package/src/biz/multi-board/index.ts +18 -1
  102. package/src/biz/multi-board/shell.ts +24 -15
  103. package/src/biz/notification-center/compile.ts +21 -33
  104. package/src/biz/page-templates/domain-templates.ts +80 -13
  105. package/src/biz/page-templates/result-page/compile.ts +11 -2
  106. package/src/biz/page-templates/shared.ts +34 -36
  107. package/src/biz/record-detail/compile.ts +47 -42
  108. package/src/biz/record-detail/index.ts +11 -1
  109. package/src/biz/settings-center/compile.ts +6 -5
  110. package/src/biz/shared/action-host.ts +91 -211
  111. package/src/biz/shared/compile-helpers.ts +80 -0
  112. package/src/biz/shared/coordinator.ts +486 -83
  113. package/src/biz/shared/index.ts +8 -2
  114. package/src/biz/shared/overlay-shell.ts +80 -0
  115. package/src/biz/shared/pipes.ts +43 -30
  116. package/src/biz/shared/remove-key.ts +6 -0
  117. package/src/biz/shared/remove-wire.ts +29 -0
  118. package/src/biz/shared/runtime-hub.ts +216 -24
  119. package/src/biz/single-form/compile.ts +15 -37
  120. package/src/biz/standard-crud/compile.ts +62 -107
  121. package/src/biz/standard-crud/shell.ts +16 -66
  122. package/src/biz/step-form/compile.ts +26 -97
  123. package/src/biz/step-form/hub.ts +34 -41
  124. package/src/biz/types.ts +4 -3
  125. package/src/cli/core-imports.ts +54 -0
  126. package/src/cli/kit-cli.ts +130 -26
  127. package/src/cli/kit-init.ts +222 -0
  128. package/src/cli/service-endpoint-check.ts +425 -0
  129. package/src/cli/source-path-check.d.mts +17 -0
  130. package/src/cli/source-path-check.mjs +334 -0
  131. package/src/cli/view-writes.ts +752 -0
  132. package/src/compile/action-host-attach.ts +21 -29
  133. package/src/compile/closed-set.ts +509 -0
  134. package/src/compile/compile-page.ts +219 -72
  135. package/src/compile/component-candidates.ts +1 -1
  136. package/src/compile/hints.ts +30 -1
  137. package/src/compile/index.ts +1 -0
  138. package/src/compile/kit-error.ts +1 -0
  139. package/src/compile/locate.ts +21 -1
  140. package/src/compile/parse.ts +370 -41
  141. package/src/compile/redirect.ts +6 -2
  142. package/src/compile/styles.ts +35 -2
  143. package/src/compile/types.ts +18 -2
  144. package/src/compile/view-check.ts +151 -0
  145. package/src/data/amount-breakdown.ts +2 -2
  146. package/src/data/anchor-nav.ts +2 -2
  147. package/src/data/approval-flow.ts +2 -2
  148. package/src/data/assignment-picker.ts +40 -29
  149. package/src/data/async-result-panel.ts +62 -6
  150. package/src/data/breadcrumbs.ts +2 -2
  151. package/src/data/calendar.ts +22 -25
  152. package/src/data/carousel.ts +5 -2
  153. package/src/data/chart.ts +42 -34
  154. package/src/data/checklist.ts +2 -2
  155. package/src/data/code-view.ts +4 -2
  156. package/src/data/comment-thread.ts +5 -2
  157. package/src/data/confirm-dialog.ts +10 -0
  158. package/src/data/context-menu.ts +29 -37
  159. package/src/data/d9-util.ts +2 -18
  160. package/src/data/diff.ts +4 -2
  161. package/src/data/dock.ts +2 -2
  162. package/src/data/embed.ts +2 -1
  163. package/src/data/field-mapper.ts +31 -26
  164. package/src/data/flow-editor-contract.ts +1 -1
  165. package/src/data/flow-editor.ts +89 -100
  166. package/src/data/flow-node-options.ts +90 -0
  167. package/src/data/flow-remote-options.ts +0 -103
  168. package/src/data/footer.ts +2 -2
  169. package/src/data/form-draft-registry.ts +2 -4
  170. package/src/data/gantt.ts +14 -17
  171. package/src/data/hero.ts +2 -2
  172. package/src/data/image-viewer.ts +20 -26
  173. package/src/data/index.ts +0 -2
  174. package/src/data/item-list.ts +31 -22
  175. package/src/data/kanban.ts +43 -42
  176. package/src/data/media-grid.ts +14 -19
  177. package/src/data/menu.ts +2 -2
  178. package/src/data/mockup.ts +2 -2
  179. package/src/data/modal-dialog.ts +22 -18
  180. package/src/data/navbar.ts +7 -2
  181. package/src/data/notify-renderer.ts +235 -0
  182. package/src/data/object-form.ts +1036 -648
  183. package/src/data/pager.ts +65 -29
  184. package/src/data/permission-matrix.ts +20 -21
  185. package/src/data/permission-tree.ts +28 -26
  186. package/src/data/pricing-table.ts +9 -3
  187. package/src/data/reaction-bar.ts +77 -88
  188. package/src/data/read-rollback.ts +73 -0
  189. package/src/data/record-card.ts +3 -3
  190. package/src/data/record-picker.ts +93 -50
  191. package/src/data/redirect.ts +32 -32
  192. package/src/data/remote-options.ts +13 -6
  193. package/src/data/request-console.ts +5 -3
  194. package/src/data/resident.ts +2 -1
  195. package/src/data/result-panel.ts +4 -2
  196. package/src/data/rich-text.ts +45 -55
  197. package/src/data/row-editor.ts +285 -52
  198. package/src/data/rule-builder.ts +18 -12
  199. package/src/data/shape-util.ts +4 -0
  200. package/src/data/stat-group.ts +243 -101
  201. package/src/data/static-registry.ts +22 -11
  202. package/src/data/steps.ts +2 -2
  203. package/src/data/survey.ts +24 -29
  204. package/src/data/system-switcher.ts +2 -2
  205. package/src/data/timeline.ts +2 -2
  206. package/src/data/tour-guide.ts +22 -29
  207. package/src/data/transfer.ts +27 -23
  208. package/src/data/tree-table.ts +96 -48
  209. package/src/data/tree.ts +27 -34
  210. package/src/data/trend-line.ts +6 -24
  211. package/src/data/virtual-rows.ts +118 -76
  212. package/src/data/watermark.ts +2 -2
  213. package/src/data/wrap.ts +63 -38
  214. package/src/frames/blank-frame.ts +1 -0
  215. package/src/frames/index.ts +2 -2
  216. package/src/frames/page-bar.ts +12 -11
  217. package/src/frames/page-header.ts +14 -5
  218. package/src/frames/page-status.ts +2 -2
  219. package/src/frames/shared.ts +23 -17
  220. package/src/frames/single-frame.ts +1 -0
  221. package/src/frames/split-frame/shell.ts +5 -5
  222. package/src/frames/split-frame/wiring.ts +2 -2
  223. package/src/frames/tabs-frame/shell.ts +2 -13
  224. package/src/frames/tabs-frame/wiring.ts +4 -8
  225. package/src/frames/top-main-frame.ts +1 -0
  226. package/src/frames/types.ts +13 -2
  227. package/src/frames/workspace-frame/extras.ts +20 -4
  228. package/src/frames/workspace-frame/index.ts +1 -1
  229. package/src/frames/workspace-frame/shell.ts +1 -0
  230. package/src/frames/workspace-frame/state.ts +13 -6
  231. package/src/frames/workspace-frame/view.ts +119 -25
  232. package/src/generated/kit-grammar-runtime.ts +430 -366
  233. package/src/generated/page-origin.ts +0 -11
  234. package/src/i18n/kit-text.ts +23 -27
  235. package/src/index.ts +2 -1
  236. package/src/object-renderer/action-gate.ts +11 -147
  237. package/src/object-renderer/arrange.ts +71 -77
  238. package/src/object-renderer/collapse-wiring.ts +2 -2
  239. package/src/object-renderer/collection-expand.ts +2 -2
  240. package/src/object-renderer/collection-parts.ts +216 -100
  241. package/src/object-renderer/collection-table.ts +180 -42
  242. package/src/object-renderer/collection.ts +95 -79
  243. package/src/object-renderer/compile-data.ts +85 -100
  244. package/src/object-renderer/crud-bridge.ts +32 -0
  245. package/src/object-renderer/defaults.ts +8 -14
  246. package/src/object-renderer/display-checks.ts +3 -24
  247. package/src/object-renderer/emit-events.ts +186 -172
  248. package/src/object-renderer/emit-object.ts +15 -2
  249. package/src/object-renderer/emit-static.ts +174 -132
  250. package/src/object-renderer/field-value.ts +593 -396
  251. package/src/object-renderer/filter-reload.ts +70 -0
  252. package/src/object-renderer/form-detail.ts +112 -2
  253. package/src/object-renderer/index.ts +26 -0
  254. package/src/object-renderer/key-field.ts +12 -0
  255. package/src/object-renderer/linkage.ts +7 -270
  256. package/src/object-renderer/merge-class.ts +18 -1
  257. package/src/object-renderer/path-pick.ts +27 -0
  258. package/src/object-renderer/render-object.ts +405 -86
  259. package/src/object-renderer/request-actions.ts +230 -249
  260. package/src/object-renderer/table-actions.ts +195 -95
  261. package/src/object-renderer/table-summary.ts +2 -2
  262. package/src/object-renderer/table-tools.ts +418 -84
  263. package/src/object-renderer/types.ts +128 -122
  264. package/src/object-renderer/view-binding.ts +196 -0
  265. package/src/page-target/ai-surface.ts +37 -0
  266. package/src/page-target/compile.ts +48 -8
  267. package/src/page-target/index.ts +8 -1
  268. package/src/page-target/intent-schema.ts +154 -28
  269. package/src/page-target/target.ts +257 -50
  270. package/src/page-target/writer-policy.ts +14 -3
  271. package/src/recipes/container.ts +165 -0
  272. package/src/recipes/control.ts +219 -0
  273. package/src/recipes/index.ts +263 -0
  274. package/src/recipes/overlay.ts +182 -0
  275. package/src/recipes/state.ts +70 -0
  276. package/src/recipes/table-row.ts +51 -0
  277. package/src/recipes/typography.ts +87 -0
  278. package/src/shared/action-field-guard.ts +41 -0
  279. package/src/shared/envelope.ts +207 -0
  280. package/src/shared/escape.ts +57 -0
  281. package/src/shared/kit-error.ts +21 -0
  282. package/src/shared/paged-list-adapter.ts +240 -0
  283. package/src/shared/path-guard.ts +127 -0
  284. package/src/shared/theme-runtime-shared.ts +175 -0
  285. package/src/shared/view-info.ts +10 -0
  286. package/src/theme/index.ts +12 -0
  287. package/src/theme/kit-theme-text.ts +1 -1
  288. package/src/theme/kit-theme.css +38 -1
  289. package/src/theme/kit-theme.tpl +38 -1
  290. package/src/theme/nine-dim-structure.ts +77 -0
  291. package/src/theme/surface-layers.ts +97 -0
  292. package/src/theme/theme-tokens.ts +85 -79
  293. package/src/theme/theme-types.ts +71 -0
  294. package/src/theme/typography.ts +17 -17
  295. package/src/biz/shared/step-values.ts +0 -25
  296. package/src/biz/step-form/steps-ref.ts +0 -112
  297. package/src/data/options-bus.ts +0 -24
  298. package/src/data/prompt-dialog.ts +0 -235
  299. package/src/object-renderer/adopt-gate.ts +0 -333
  300. package/src/object-renderer/field-policy.ts +0 -89
  301. package/src/object-renderer/outcome-draft.ts +0 -61
  302. package/src/theme/nine-dim-palettes.ts +0 -1473
package/src/base/fab.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  } from './shared';
12
12
  import { kitText } from '../i18n/kit-text';
13
13
  import { kitIcon } from './icons';
14
+ import { setKitFixed } from '../recipes';
14
15
  import { menuItemsOf, wireMenu, type MenuClasses, type MenuHandle } from './menu-core';
15
16
  import { KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, popPlaceClass, type PopPlace } from './popup';
16
17
 
@@ -85,7 +86,9 @@ function makeView(): KitView {
85
86
  const scrolled = (): boolean => (typeof window === 'undefined' ? 0 : window.scrollY) >= backTopOffsetOf(api.props().back_top_offset);
86
87
  paintRoot = (): void => {
87
88
  const p = api.props();
88
- root.className = bool(p.back_top) && !backTopShown ? BACK_TOP_HIDDEN : joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
89
+ const hiddenNow = bool(p.back_top) && !backTopShown;
90
+ root.className = hiddenNow ? BACK_TOP_HIDDEN : joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
91
+ setKitFixed(root, !hiddenNow && placementOf(p.placement) !== 'inline');
89
92
  };
90
93
  const onScroll = (): void => {
91
94
  if (!bool(api.props().back_top)) return;
@@ -104,6 +107,7 @@ function makeView(): KitView {
104
107
  hiddenClass: MENU_HIDDEN,
105
108
  fitted: () => ({ pref: pref(), classFor: menuClass }),
106
109
  classes: MENU_CLASSES,
110
+ rowFace: 'raised',
107
111
  items: () => menuItemsOf(api.props().items),
108
112
  locked: () => bool(api.props().disabled) || !hasItems(),
109
113
  onPick: (item) => api.emit('select', { key: item.key }),
@@ -145,7 +149,10 @@ function makeView(): KitView {
145
149
  if (bool(p.disabled) && handle?.isOpen()) handle.close(false);
146
150
  handle?.sync();
147
151
  if (paintRoot) paintRoot();
148
- else root.className = joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
152
+ else {
153
+ root.className = joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
154
+ setKitFixed(root, placementOf(p.placement) !== 'inline');
155
+ }
149
156
  },
150
157
  };
151
158
  }
@@ -186,7 +193,7 @@ export function createFab(): SomaComponentDefinition {
186
193
  click: { payload: {}, desc: '没有动作项时点主按钮' },
187
194
  },
188
195
  },
189
- templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS.inline}"><button type="button" class="${TRIGGER_CLASS.md}"><span aria-hidden="true">+</span></button><div class="${MENU_HIDDEN}"></div></div>`,
190
- controllerFactory: (ctx) => createKitController(withTooltip(makeView(), (root) => root.firstElementChild as HTMLElement))(ctx),
196
+ templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS.inline}"><button type="button" data-kit-face="raised" class="${TRIGGER_CLASS.md}"><span aria-hidden="true">+</span></button><div class="${MENU_HIDDEN}"></div></div>`,
197
+ controllerFactory: createKitController(() => withTooltip(makeView(), (root) => root.firstElementChild as HTMLElement)),
191
198
  };
192
199
  }
package/src/base/image.ts CHANGED
@@ -172,6 +172,6 @@ export function createImage(): SomaComponentDefinition {
172
172
  },
173
173
  },
174
174
  templateHtml: `<span data-soma-id="root" class="${ROOT_BASE}"></span>`,
175
- controllerFactory: (ctx) => createKitController(makeView())(ctx),
175
+ controllerFactory: createKitController(() => makeView()),
176
176
  };
177
177
  }
package/src/base/index.ts CHANGED
@@ -54,7 +54,8 @@ import { KIT_TEXTAREA_CLASS_CANDIDATES } from './textarea';
54
54
  import { KIT_BUTTON_CLASS_CANDIDATES } from './button';
55
55
  import { KIT_LINK_CLASS_CANDIDATES } from './link';
56
56
  import { KIT_TEXT_CLASS_CANDIDATES } from './text';
57
- import { KIT_BADGE_CLASS_CANDIDATES } from './shared';
57
+ import { FIELD_INVALID_CLASS, FOCUS_RING, INVALID_PROPS, KIT_BADGE_CLASS_CANDIDATES, KIT_SPINNER_CLASS, withInvalid } from './shared';
58
+ export { FIELD_INVALID_CLASS, FOCUS_RING, INVALID_PROPS, KIT_SPINNER_CLASS, withInvalid };
58
59
  import { createPriceText, KIT_PRICE_TEXT_CLASS_CANDIDATES } from './price-text';
59
60
  import { createQrCode, KIT_QR_CODE_CLASS_CANDIDATES } from './qr-code';
60
61
  import { KIT_CONTEXT_MENU_CLASS_CANDIDATES } from './context-menu';
@@ -163,7 +164,7 @@ export const KIT_BASE_CORE_CLASS_CANDIDATES: readonly string[] = Object.freeze([
163
164
  'px-1.5', 'px-2', 'px-2.5', 'px-3', 'px-4', 'px-5', 'py-0.5', 'py-1', 'py-2', 'py-3',
164
165
  'read-only:bg-surface-sunken', 'relative', 'rounded-full', 'rounded-md', 'shadow-sm', 'shrink-0',
165
166
  'text-base', 'text-danger-fg', 'text-danger-on-soft', 'text-fg', 'text-fg-muted', 'text-fg-subtle',
166
- 'text-info-on-soft', 'text-lg', 'text-primary', 'text-primary-fg', 'text-sm', 'text-success-on-soft',
167
+ 'text-info-on-soft', 'text-lg', 'text-primary-fg', 'text-sm', 'text-success-on-soft',
167
168
  'text-warning-on-soft', 'text-xs',
168
169
  'top-0.5', 'transition-colors', 'transition-transform',
169
170
  'translate-x-0', 'translate-x-4', 'translate-x-5', 'translate-x-7', 'rtl:-translate-x-4', 'rtl:-translate-x-5', 'rtl:-translate-x-7',
@@ -186,13 +187,18 @@ export const KIT_BASE_CORE_CLASS_CANDIDATES: readonly string[] = Object.freeze([
186
187
  'enabled:hover:bg-danger-hover', 'enabled:hover:bg-fg-subtle', 'enabled:hover:bg-primary-hover', 'enabled:hover:bg-surface-sunken',
187
188
  'border-input', 'hover:border-input-hover', 'enabled:hover:border-input-hover',
188
189
  'enabled:hover:border-fg-subtle', 'focus-visible:border-primary', 'focus-within:border-primary', 'hover:border-fg-subtle',
189
- 'hover:border-primary', 'hover:bg-surface-sunken', 'hover:text-fg', 'hover:text-primary', 'active:opacity-60', 'hover:opacity-100',
190
+ 'hover:border-primary', 'hover:bg-surface-sunken', 'hover:text-fg', 'hover:text-primary-on-soft', 'active:opacity-60', 'hover:opacity-100',
190
191
  'min-h-10', 'opacity-60', 'opacity-70', 'px-2.5', 'py-1.5', 'py-2.5', 'rounded-lg', 'rounded-sm', 'underline-offset-2',
191
192
  'cursor-not-allowed', 'transition-colors', 'bg-info-fg', 'text-info-fg', 'text-success-fg', 'text-warning-fg', 'bg-surface',
192
193
  'bg-surface-sunken', 'text-fg-muted', 'text-fg-subtle', 'font-medium', 'text-xs', 'gap-1', 'rounded-full', 'items-center',
193
194
  'justify-center', 'inline-flex', 'h-5', 'w-5', 'shrink-0',
194
195
  // R1 复审追加:Upload 列表清默认样式、Select / TreeSelect 常驻 live region
195
196
  'm-0', 'list-none', 'p-0', 'sr-only', 'rounded-lg', 'border-border-subtle',
197
+ // 加载转圈动画、统一错误态与小控件热区
198
+ 'animate-spin', 'aria-invalid:border-danger', 'border-danger',
199
+ 'focus-visible:border-danger', 'focus-visible:ring-1', 'focus-visible:ring-danger',
200
+ 'focus-within:border-danger', 'focus-within:ring-danger',
201
+ 'min-h-5', 'min-w-5', 'min-h-6', 'min-w-6',
196
202
  ])].sort());
197
203
 
198
204
  /** 基础组件全量候选类 = 公共底座(上面的写死清单)+ 各组件自带类;按页裁剪见 compile/component-candidates.ts */
package/src/base/input.ts CHANGED
@@ -11,12 +11,35 @@
11
11
 
12
12
  import type { SomaComponentDefinition } from 'soma-core';
13
13
  import {
14
- CLASS_PROP, ID_PROPS, SIZE_PROP,
15
- FIELD_CLASS, applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, num, setBoolAttr, sizeOf, str,
14
+ CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
15
+ FIELD_CLASS, applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, num, setBoolAttr, sizeOf, str, withInvalid,
16
16
  type KitApi, type KitProps, type KitSize,
17
17
  } from './shared';
18
18
  import { kitText } from '../i18n/kit-text';
19
19
  import { kitIcon } from './icons';
20
+ import {
21
+ KIT_PART_ATTRIBUTE,
22
+ KIT_PART_BUTTON,
23
+ KIT_PART_CONTROL,
24
+ KIT_PART_TEXTAREA,
25
+ kitControlPartOf,
26
+ kitControlRecipe,
27
+ kitControlSizeRecipe,
28
+ kitSelectedRecipe,
29
+ setKitFace,
30
+ } from '../recipes';
31
+
32
+ export {
33
+ KIT_PART_CONTROL,
34
+ KIT_PART_BUTTON,
35
+ KIT_PART_TEXTAREA,
36
+ kitControlRecipe,
37
+ kitControlPartOf,
38
+ kitControlSizeRecipe,
39
+ kitSelectedRecipe,
40
+ };
41
+
42
+
20
43
 
21
44
  // 每档一整串字面量;禁用 / 只读态靠 disabled: / read-only: 变体,不切类串
22
45
  const INPUT_CLASS: Record<KitSize, string> = FIELD_CLASS;
@@ -41,9 +64,9 @@ const BOX_CLASS: Record<InputVariant, Record<BoxState, string>> = {
41
64
  },
42
65
  };
43
66
  const BOX_SIZE: Record<KitSize, string> = {
44
- sm: 'h-8 px-2.5 text-sm',
45
- md: 'h-9 px-3 text-sm',
46
- lg: 'h-10 px-4 text-base',
67
+ sm: kitControlSizeRecipe('sm'),
68
+ md: kitControlSizeRecipe('md'),
69
+ lg: kitControlSizeRecipe('lg'),
47
70
  };
48
71
  const BARE_CLASS: Record<KitSize, string> = {
49
72
  sm: 'min-w-0 flex-1 bg-transparent text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none disabled:cursor-not-allowed',
@@ -51,14 +74,14 @@ const BARE_CLASS: Record<KitSize, string> = {
51
74
  lg: 'min-w-0 flex-1 bg-transparent text-base text-fg placeholder:text-fg-subtle focus-visible:outline-none disabled:cursor-not-allowed',
52
75
  };
53
76
  const AFFIX_CLASS = 'shrink-0 text-fg-muted';
54
- const ICON_BTN_CLASS = 'inline-flex shrink-0 items-center justify-center rounded-sm px-1 text-sm text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed';
77
+ const ICON_BTN_CLASS = 'inline-flex min-h-6 min-w-6 shrink-0 items-center justify-center rounded-sm px-1 text-sm text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
55
78
  const COUNTER_CLASS = 'shrink-0 text-xs tabular-nums text-fg-subtle';
56
- const SUFFIX_BTN_CLASS = 'shrink-0 rounded-sm px-1 text-sm font-medium text-primary transition-colors enabled:hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-subtle';
79
+ const SUFFIX_BTN_CLASS = `inline-flex min-h-6 shrink-0 items-center justify-center rounded-sm px-1 text-sm font-medium text-primary-on-soft transition-colors enabled:hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-subtle disabled:opacity-60`;
57
80
  const HIDDEN = 'hidden';
58
81
 
59
82
  export const KIT_INPUT_CLASS_CANDIDATES: readonly string[] = classCandidates(
60
83
  WRAP_PLAIN, Object.values(BOX_CLASS).flatMap((m) => Object.values(m)), Object.values(BOX_SIZE), Object.values(BARE_CLASS),
61
- AFFIX_CLASS, ICON_BTN_CLASS, COUNTER_CLASS, SUFFIX_BTN_CLASS, HIDDEN,
84
+ AFFIX_CLASS, ICON_BTN_CLASS, COUNTER_CLASS, SUFFIX_BTN_CLASS, HIDDEN, FIELD_INVALID_CLASS,
62
85
  );
63
86
 
64
87
  // 外壳子元素的固定次序(模板与 render 共用)
@@ -169,6 +192,7 @@ export function createInput(): SomaComponentDefinition {
169
192
  disabled: { type: 'boolean', default: false },
170
193
  readonly: { type: 'boolean', default: false },
171
194
  ...ID_PROPS,
195
+ ...INVALID_PROPS,
172
196
  size: SIZE_PROP,
173
197
  class: CLASS_PROP,
174
198
  },
@@ -178,8 +202,8 @@ export function createInput(): SomaComponentDefinition {
178
202
  suffix_click: { payload: {}, desc: '点后缀动作钮(suffix.action);倒数中与 disabled 时不抛' },
179
203
  },
180
204
  },
181
- templateHtml: `<span class="${WRAP_PLAIN}"><span class="${HIDDEN}"></span><input data-soma-id="root" type="text" class="${INPUT_CLASS.md}" /><button type="button" class="${HIDDEN}"></button><button type="button" class="${HIDDEN}"></button><span class="${HIDDEN}"></span><span class="${HIDDEN}"></span><button type="button" class="${HIDDEN}"></button></span>`,
182
- controllerFactory: createKitController({
205
+ templateHtml: `<span class="${WRAP_PLAIN}"><span class="${HIDDEN}"></span><input data-soma-id="root" data-kit-part="${KIT_PART_CONTROL}" type="text" class="${INPUT_CLASS.md}" /><button type="button" class="${HIDDEN}"></button><button type="button" class="${HIDDEN}"></button><span class="${HIDDEN}"></span><span class="${HIDDEN}"></span><button type="button" class="${HIDDEN}"></button></span>`,
206
+ controllerFactory: createKitController(() => ({
183
207
  attach(root, api) {
184
208
  const el = root as HTMLInputElement;
185
209
  const s = stateOf(root);
@@ -266,6 +290,7 @@ export function createInput(): SomaComponentDefinition {
266
290
  const prefix = str(p.prefix);
267
291
  const spec = suffixOf(p.suffix, root);
268
292
  const variant: InputVariant = p.variant === 'filled' ? 'filled' : 'outline';
293
+ el.setAttribute(KIT_PART_ATTRIBUTE, kitControlPartOf({ size, variant }));
269
294
  const boxed = variant === 'filled' || bool(p.clearable) || bool(p.counter) || toggleOn || prefix !== '' || spec.text !== '' || spec.action !== '';
270
295
 
271
296
  const prefixEl = k[PREFIX] as HTMLElement;
@@ -284,16 +309,20 @@ export function createInput(): SomaComponentDefinition {
284
309
  paintAction(root, p);
285
310
  paintLive(el, p);
286
311
 
312
+ const invalid = bool(p.invalid);
313
+ // 质感标记打在「带边框的那一层」:装饰模式是外壳(里面的 input 无边无底),否则是 input 自己
314
+ setKitFace(el, boxed ? null : 'field');
315
+ setKitFace(wrap, boxed ? 'field' : null);
287
316
  if (boxed) {
288
317
  const state: BoxState = bool(p.disabled) ? 'off' : bool(p.readonly) ? 'ro' : 'on';
289
- wrap.className = joinClass(`${BOX_CLASS[variant][state]} ${BOX_SIZE[size]}`, p.class);
318
+ wrap.className = joinClass(withInvalid(`${BOX_CLASS[variant][state]} ${BOX_SIZE[size]}`, invalid), p.class);
290
319
  el.className = BARE_CLASS[size];
291
320
  } else {
292
321
  wrap.className = WRAP_PLAIN;
293
- el.className = joinClass(INPUT_CLASS[size], p.class);
322
+ el.className = joinClass(withInvalid(INPUT_CLASS[size], invalid), p.class);
294
323
  }
295
324
  },
296
- }),
325
+ })),
297
326
  };
298
327
  }
299
328
 
package/src/base/kbd.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  applyCommon, bool, classCandidates, createKitController, joinClass, sizeOf, str, withTooltip,
9
9
  type KitSize,
10
10
  } from './shared';
11
+ import { setKitFace } from '../recipes';
11
12
 
12
13
  const ROOT_CLASS = 'inline-flex items-center gap-1';
13
14
  const KEY_CLASS: Record<KitSize, string> = {
@@ -70,7 +71,7 @@ export function createKbd(): SomaComponentDefinition {
70
71
  emits: {},
71
72
  },
72
73
  templateHtml: `<span data-soma-id="root" class="${ROOT_CLASS}"></span>`,
73
- controllerFactory: createKitController(withTooltip({
74
+ controllerFactory: createKitController(() => withTooltip({
74
75
  render(root, p) {
75
76
  const keys = splitKeys(str(p.keys) !== '' ? str(p.keys) : str(p.value));
76
77
  const symbols = bool(p.symbols);
@@ -87,6 +88,7 @@ export function createKbd(): SomaComponentDefinition {
87
88
  }
88
89
  const cap = document.createElement('kbd');
89
90
  cap.className = KEY_CLASS[size];
91
+ setKitFace(cap, 'raised'); // 键帽有底 + 边框 + shadow-xs,质感经合成槽叠进去
90
92
  cap.textContent = keyLabel(key, symbols);
91
93
  if (symbols && keyLabel(key, true) !== key) cap.setAttribute('aria-label', key);
92
94
  root.appendChild(cap);
package/src/base/link.ts CHANGED
@@ -21,9 +21,9 @@ function underlineOf(raw: unknown): LinkUnderline {
21
21
  }
22
22
 
23
23
  const LINK_CLASS: Record<KitSize, string> = {
24
- sm: 'cursor-pointer rounded-sm text-sm font-medium text-primary transition-colors hover:opacity-80 active:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
25
- md: 'cursor-pointer rounded-sm text-base font-medium text-primary transition-colors hover:opacity-80 active:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
26
- lg: 'cursor-pointer rounded-sm text-base font-medium text-primary transition-colors hover:opacity-80 active:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
24
+ sm: 'cursor-pointer rounded-sm text-sm font-medium text-primary-on-soft transition-colors hover:opacity-80 active:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
25
+ md: 'cursor-pointer rounded-sm text-base font-medium text-primary-on-soft transition-colors hover:opacity-80 active:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
26
+ lg: 'cursor-pointer rounded-sm text-base font-medium text-primary-on-soft transition-colors hover:opacity-80 active:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
27
27
  };
28
28
 
29
29
  const LINK_DISABLED_CLASS: Record<KitSize, string> = {
@@ -79,7 +79,7 @@ export function createLink(): SomaComponentDefinition {
79
79
  },
80
80
  },
81
81
  templateHtml: `<a data-soma-id="root" class="${LINK_CLASS.md}"></a>`,
82
- controllerFactory: createKitController(withTooltip({
82
+ controllerFactory: createKitController(() => withTooltip({
83
83
  attach(root, api) {
84
84
  const onClick = (event: Event): void => {
85
85
  const p = api.props();
@@ -16,11 +16,12 @@ import {
16
16
  cssEscape, createListNav, onOutsidePress, optionClass, releaseDropdown, scrollIntoViewIfAny, syncDropdown,
17
17
  } from './popup';
18
18
  import {
19
- FIELD_CLASS, applyDisabled, bool, classCandidates, createKitController, joinClass, nextUid, num, optionsOf, sameValue, setAttr, setBoolAttr, sizeOf, str,
20
- type KitOption, type KitProps, type KitSize,
19
+ FIELD_CLASS, FIELD_INVALID_CLASS, applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, nextUid, num, optionsOf, sameValue, setAttr, setBoolAttr, sizeOf, str, withInvalid,
20
+ type KitApi, type KitOption, type KitProps, type KitSize, type KitView, type KitViewSetup,
21
21
  } from './shared';
22
+ import { setKitFace } from '../recipes';
22
23
  import {
23
- KIT_VIRTUAL_CLASS_CANDIDATES, KIT_VIRTUAL_OPTION_ROW_CLASS, KIT_VIRTUAL_ROW_PX, createVirtualWindow, paintVirtualRows, rowTierOf, withoutPy,
24
+ KIT_VIRTUAL_CLASS_CANDIDATES, KIT_VIRTUAL_OPTION_ROW_CLASS, virtualRowPx, createVirtualWindow, paintVirtualRows, rowTierOf, withoutPy,
24
25
  type VirtualWindow,
25
26
  } from './virtual-list';
26
27
  import { kitText } from '../i18n/kit-text';
@@ -34,7 +35,7 @@ const WRAP_CLASS = 'relative block';
34
35
  const WRAP_FULL_CLASS = 'relative block w-full';
35
36
  const STATUS_CLASS = 'sr-only';
36
37
  const ICON_CLASS = 'shrink-0';
37
- const LABEL_CLASS = 'min-w-0 flex-1 truncate';
38
+ const LABEL_CLASS = 'min-w-0 flex-1 truncate whitespace-nowrap';
38
39
  const DESC_CLASS = 'ms-auto shrink-0 text-xs opacity-70';
39
40
  const CLEAR_PAD_CLASS = 'pe-8';
40
41
  const CLEAR_PAD_SELECT_CLASS = 'pe-12';
@@ -52,7 +53,7 @@ export const BOX_OFF_CLASS: Record<KitSize, string> = {
52
53
  };
53
54
  export const BOX_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';
54
55
  export const CHIP_CLASS = 'inline-flex max-w-full 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';
55
- export const CHIP_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';
56
+ export const CHIP_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';
56
57
  export const GROUP_TITLE_CLASS = 'sticky top-0 z-10 bg-surface-raised px-4 py-1 text-xs font-medium text-fg-subtle';
57
58
  /**
58
59
  * 下拉选项的水平内边距对齐 16(MUI 16 / Element 20,原 12):选项 / 空态行 / 分组标题同为 px-4。
@@ -82,16 +83,16 @@ export const SELECT_FIELD_RO_CLASS = selFieldClasses('cursor-default bg-surface-
82
83
  const SEL_CHIPS_FIELD_CLASS = 'min-w-8 flex-1 cursor-pointer px-1 py-0.5 text-sm focus-visible:outline-none';
83
84
  const SEL_CHIPS_FIELD_OFF_CLASS = 'min-w-8 flex-1 cursor-not-allowed px-1 py-0.5 text-sm focus-visible:outline-none';
84
85
  const SEL_CHIPS_FIELD_RO_CLASS = 'min-w-8 flex-1 cursor-default px-1 py-0.5 text-sm focus-visible:outline-none';
85
- const SEL_TEXT_CLASS = 'min-w-0 flex-1 truncate';
86
- const SEL_TEXT_CLEAR_CLASS = 'min-w-0 flex-1 truncate me-5';
87
- const SEL_PLACEHOLDER_CLASS = 'min-w-0 flex-1 truncate text-fg-subtle';
88
- const SEL_PLACEHOLDER_CLEAR_CLASS = 'min-w-0 flex-1 truncate text-fg-subtle me-5';
86
+ const SEL_TEXT_CLASS = 'min-w-0 flex-1 truncate whitespace-nowrap';
87
+ const SEL_TEXT_CLEAR_CLASS = 'min-w-0 flex-1 truncate whitespace-nowrap me-5';
88
+ const SEL_PLACEHOLDER_CLASS = 'min-w-0 flex-1 truncate whitespace-nowrap text-fg-subtle';
89
+ const SEL_PLACEHOLDER_CLEAR_CLASS = 'min-w-0 flex-1 truncate whitespace-nowrap text-fg-subtle me-5';
89
90
  const SEL_CHEVRON_CLASS = 'inline-flex shrink-0 text-fg-subtle motion-safe:transition-transform';
90
91
 
91
92
  /** 两个组件共用的候选类清单 */
92
93
  export const KIT_LISTBOX_CLASS_CANDIDATES: readonly string[] = classCandidates(
93
94
  WRAP_CLASS, WRAP_FULL_CLASS, STATUS_CLASS, ICON_CLASS, LABEL_CLASS, DESC_CLASS, CLEAR_PAD_CLASS, CLEAR_PAD_SELECT_CLASS,
94
- Object.values(FIELD_CLASS), Object.values(BOX_CLASS), Object.values(BOX_OFF_CLASS),
95
+ Object.values(FIELD_CLASS), Object.values(BOX_CLASS), Object.values(BOX_OFF_CLASS), FIELD_INVALID_CLASS,
95
96
  BOX_INPUT_CLASS, CHIP_CLASS, CHIP_REMOVE_CLASS, GROUP_TITLE_CLASS, CHECK_CLASS,
96
97
  CLEAR_CLASS, CLEAR_SELECT_CLASS, CLEAR_HIDDEN_CLASS,
97
98
  Object.values(SELECT_FIELD_CLASS), Object.values(SELECT_FIELD_OFF_CLASS), Object.values(SELECT_FIELD_RO_CLASS),
@@ -209,10 +210,10 @@ interface Zone {
209
210
  off: () => void;
210
211
  }
211
212
 
212
- /** 控制器工厂:kind 决定 change 载荷、display 的含义与 search 事件 */
213
- export function createListboxController(kind: ListboxKind): SomaComponentControllerFactory {
213
+ /** 控制器视图工厂:kind 决定 change 载荷、display 的含义与 search 事件 */
214
+ export function createListboxView(kind: ListboxKind): KitViewSetup {
214
215
  const isCombo = kind === 'combobox';
215
- return (ctx) => {
216
+ return (api: KitApi): KitView => {
216
217
  let open = false;
217
218
  let query = '';
218
219
  let typing = false;
@@ -226,13 +227,24 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
226
227
  let taAt = 0;
227
228
  let zone: Zone | null = null;
228
229
  let renderFn: ((p: KitProps) => void) | null = null;
230
+ // 远程搜索防过期:记住最近一次发出的 search query 与上一批已采用的 options(options_query 与之不符的回填不采用)
231
+ let lastSearch: string | null = null;
232
+ let adopted: unknown;
233
+ let hasAdopted = false;
234
+ const rawOptions = (p: KitProps): unknown => {
235
+ const oq = p.options_query;
236
+ if (isCombo && hasAdopted && lastSearch !== null && typeof oq === 'string' && oq !== '' && oq !== lastSearch) return adopted;
237
+ adopted = p.options;
238
+ hasAdopted = true;
239
+ return adopted;
240
+ };
229
241
  const disposeVirt = (): void => {
230
242
  virt?.dispose();
231
243
  virt = null;
232
244
  scrolledTo = null;
233
245
  };
234
246
 
235
- return createKitController({
247
+ return {
236
248
  attach(root, api) {
237
249
  const listId = nextUid('kit-listbox');
238
250
  const panel = document.createElement('div');
@@ -268,19 +280,19 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
268
280
 
269
281
  // ── 取数 ─────────────────────────────────────────────
270
282
  const visible = (p: KitProps): KitOption[] => {
271
- const all = optionsOf(p.options);
283
+ const all = optionsOf(rawOptions(p));
272
284
  const list = !zone?.editable || str(p.filter, 'local') === 'none' || !typing ? all : comboFilter(all, query);
273
285
  const field = str(p.group);
274
- return field === '' ? list : groupedOrder(list, optionExtras(p.options, field), true);
286
+ return field === '' ? list : groupedOrder(list, optionExtras(rawOptions(p), field), true);
275
287
  };
276
288
  const pickedKeys = (p: KitProps): Set<string> => {
277
289
  if (isMulti(p)) return new Set(multiValuesOf(p.value).map((v) => String(v)));
278
- const hit = optionsOf(p.options).find((o) => sameValue(o.value, p.value));
290
+ const hit = optionsOf(rawOptions(p)).find((o) => sameValue(o.value, p.value));
279
291
  return new Set(hit ? [keyOf(hit)] : []);
280
292
  };
281
- const labelOfKey = (p: KitProps, key: string): string => optionsOf(p.options).find((o) => keyOf(o) === key)?.label ?? key;
293
+ const labelOfKey = (p: KitProps, key: string): string => optionsOf(rawOptions(p)).find((o) => keyOf(o) === key)?.label ?? key;
282
294
  const selectedLabel = (p: KitProps): string => {
283
- const hit = optionsOf(p.options).find((o) => sameValue(o.value, p.value));
295
+ const hit = optionsOf(rawOptions(p)).find((o) => sameValue(o.value, p.value));
284
296
  if (hit) return hit.label;
285
297
  if (isCombo && str(p.display) !== '') return str(p.display);
286
298
  if (str(p.value) === '') return '';
@@ -363,7 +375,7 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
363
375
  services: api.services,
364
376
  scroller: () => panel,
365
377
  count: list.length,
366
- rowPx: KIT_VIRTUAL_ROW_PX[tier],
378
+ rowPx: virtualRowPx(tier, panel),
367
379
  onChange: () => { if (open) paintList(api.props()); },
368
380
  });
369
381
  } else {
@@ -372,7 +384,7 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
372
384
  markMulti(p);
373
385
  status.textContent = '';
374
386
  const picked = pickedKeys(p);
375
- const extras = optionExtras(p.options, '');
387
+ const extras = optionExtras(rawOptions(p), '');
376
388
  const none = { icon: '', desc: '' };
377
389
  const cursorIndex = cursor === null ? -1 : list.findIndex((o) => keyOf(o) === cursor);
378
390
  if (cursorIndex >= 0 && scrolledTo !== cursor) {
@@ -421,7 +433,7 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
421
433
  }
422
434
  const picked = pickedKeys(p);
423
435
  const field = str(p.group);
424
- const extras = optionExtras(p.options, field);
436
+ const extras = optionExtras(rawOptions(p), field);
425
437
  const none = { icon: '', desc: '' };
426
438
  let index = 0;
427
439
  groupSegments(list, extras, field !== '').forEach((seg, segIndex) => {
@@ -494,7 +506,7 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
494
506
  if (isMulti(p)) {
495
507
  vals = multiValuesOf(p.value).map((v) => String(v));
496
508
  } else {
497
- const hit = optionsOf(p.options).find((o) => sameValue(o.value, p.value));
509
+ const hit = optionsOf(rawOptions(p)).find((o) => sameValue(o.value, p.value));
498
510
  vals = [hit ? keyOf(hit) : bool(p.allow_free) ? str(p.value) : ''];
499
511
  }
500
512
  while (hiddenEls.length > vals.length) hiddenEls.pop()!.remove();
@@ -593,7 +605,7 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
593
605
  };
594
606
  const commitOption = (key: string): void => {
595
607
  const p = api.props();
596
- const hit = optionsOf(p.options).find((o) => keyOf(o) === key);
608
+ const hit = optionsOf(rawOptions(p)).find((o) => keyOf(o) === key);
597
609
  if (!hit || hit.disabled) return;
598
610
  if (isMulti(p)) {
599
611
  if (locked()) {
@@ -772,6 +784,7 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
772
784
  const delay = Math.max(0, num(p.search_delay) ?? 0);
773
785
  const fire = (): void => {
774
786
  timer = null;
787
+ lastSearch = query;
775
788
  api.emit('search', { query });
776
789
  };
777
790
  if (delay === 0) fire();
@@ -911,14 +924,19 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
911
924
  if (disabled || readonly) open = false;
912
925
  markMulti(p);
913
926
  clear.setAttribute('aria-label', kitText('soma.kit.clear', undefined, root));
927
+ const invalid = bool(p.invalid);
914
928
  const pad = clearable ? ` ${z.editable ? CLEAR_PAD_CLASS : CLEAR_PAD_SELECT_CLASS}` : '';
929
+ // 质感标记打在带边框的那一层:多选 chips 是外壳 box(里面的 field 无边),其余是 field 自己
930
+ if (z.box) setKitFace(z.box, 'field');
931
+ else setKitFace(z.field, 'field');
915
932
  if (z.box) {
916
- z.box.className = `${disabled ? BOX_OFF_CLASS[size] : BOX_CLASS[size]}${pad}`;
933
+ z.box.className = withInvalid(`${disabled ? BOX_OFF_CLASS[size] : BOX_CLASS[size]}${pad}`, invalid);
917
934
  z.field.className = z.editable ? BOX_INPUT_CLASS : disabled ? SEL_CHIPS_FIELD_OFF_CLASS : readonly ? SEL_CHIPS_FIELD_RO_CLASS : SEL_CHIPS_FIELD_CLASS;
918
935
  } else if (z.editable) {
919
- z.field.className = `${FIELD_CLASS[size]}${pad}`;
936
+ z.field.className = withInvalid(`${FIELD_CLASS[size]}${pad}`, invalid);
920
937
  } else {
921
- z.field.className = disabled ? SELECT_FIELD_OFF_CLASS[size] : readonly ? SELECT_FIELD_RO_CLASS[size] : SELECT_FIELD_CLASS[size];
938
+ const selCls = disabled ? SELECT_FIELD_OFF_CLASS[size] : readonly ? SELECT_FIELD_RO_CLASS[size] : SELECT_FIELD_CLASS[size];
939
+ z.field.className = withInvalid(selCls, invalid);
922
940
  }
923
941
  if (z.editable) {
924
942
  applyDisabled(z.field, disabled);
@@ -930,8 +948,7 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
930
948
  if (readonly) z.field.setAttribute('aria-readonly', 'true');
931
949
  else z.field.removeAttribute('aria-readonly');
932
950
  }
933
- setAttr(z.field, 'id', str(p.id));
934
- setAttr(z.field, 'aria-label', str(p.aria_label));
951
+ applyCommon(z.field, { ...p, name: '' });
935
952
  setAttr(panel, 'aria-label', str(p.aria_label));
936
953
  root.className = joinClass(/(^|\s)(w-|min-w-|max-w-|flex-|basis-)/.test(str(p.class)) ? WRAP_CLASS : WRAP_FULL_CLASS, p.class);
937
954
  paint();
@@ -960,6 +977,9 @@ export function createListboxController(kind: ListboxKind): SomaComponentControl
960
977
  render(_root, p) {
961
978
  renderFn?.(p);
962
979
  },
963
- })(ctx);
980
+ };
964
981
  };
965
982
  }
983
+
984
+ export const createListboxController = (kind: ListboxKind): SomaComponentControllerFactory =>
985
+ createKitController(createListboxView(kind));
@@ -0,0 +1,133 @@
1
+ // 加载反馈三阈值状态机(延迟出现 delayMs / 最短可见停留 minDurationMs / 完成过渡停留 doneHoldMs)。
2
+ //
3
+ // 目的:
4
+ // 1. 快请求(在 delayMs 内完成)全程不进入 visible,避免加载指示器闪屏;
5
+ // 2. 一旦超过 delayMs 进入 visible,即使请求随即完成也至少保持 visible 满 minDurationMs,防止一闪而过;
6
+ // 3. 从 visible 结束时进入短暂 done 过渡态停留 doneHoldMs 后回到 idle。
7
+
8
+ export type KitLoadingPhase = 'idle' | 'pending-delay' | 'visible' | 'done';
9
+
10
+ export interface KitLoadingGateOptions {
11
+ /** 延迟出现阈值(毫秒),默认 150ms:在此时间内完成则不显示 loading 态 */
12
+ delayMs?: number;
13
+ /** 最短可见停留阈值(毫秒),默认 300ms:进入 visible 后至少保持此时长 */
14
+ minDurationMs?: number;
15
+ /** 完成态停留阈值(毫秒),默认 200ms:从 visible 结束时停留 done 态的时长 */
16
+ doneHoldMs?: number;
17
+ /** 状态变化回调(也可通过 createLoadingGate 第二参数传入) */
18
+ onChange?: (phase: KitLoadingPhase) => void;
19
+ }
20
+
21
+ export interface KitLoadingGate {
22
+ start(): void;
23
+ finish(): void;
24
+ cancel(): void;
25
+ phase(): KitLoadingPhase;
26
+ isVisible(): boolean;
27
+ }
28
+
29
+ export const KIT_LOADING_GATE_DEFAULTS = Object.freeze({
30
+ delayMs: 150,
31
+ minDurationMs: 300,
32
+ doneHoldMs: 200,
33
+ } as const);
34
+
35
+ function resolveMs(val: number | undefined, fallback: number): number {
36
+ return typeof val === 'number' && Number.isFinite(val) && val >= 0 ? val : fallback;
37
+ }
38
+
39
+ export function createLoadingGate(
40
+ options?: KitLoadingGateOptions | ((phase: KitLoadingPhase) => void),
41
+ onChange?: (phase: KitLoadingPhase) => void,
42
+ ): KitLoadingGate {
43
+ const opts: KitLoadingGateOptions = typeof options === 'function' ? { onChange: options } : (options ?? {});
44
+ const notify = onChange ?? opts.onChange;
45
+ const delayMs = resolveMs(opts.delayMs, KIT_LOADING_GATE_DEFAULTS.delayMs);
46
+ const minDurationMs = resolveMs(opts.minDurationMs, KIT_LOADING_GATE_DEFAULTS.minDurationMs);
47
+ const doneHoldMs = resolveMs(opts.doneHoldMs, KIT_LOADING_GATE_DEFAULTS.doneHoldMs);
48
+
49
+ let currentPhase: KitLoadingPhase = 'idle';
50
+ let visibleAt = 0;
51
+ let delayTimer: ReturnType<typeof setTimeout> | undefined;
52
+ let minWaitTimer: ReturnType<typeof setTimeout> | undefined;
53
+ let doneTimer: ReturnType<typeof setTimeout> | undefined;
54
+
55
+ const clearTimers = (): void => {
56
+ if (delayTimer !== undefined) {
57
+ clearTimeout(delayTimer);
58
+ delayTimer = undefined;
59
+ }
60
+ if (minWaitTimer !== undefined) {
61
+ clearTimeout(minWaitTimer);
62
+ minWaitTimer = undefined;
63
+ }
64
+ if (doneTimer !== undefined) {
65
+ clearTimeout(doneTimer);
66
+ doneTimer = undefined;
67
+ }
68
+ };
69
+
70
+ const setPhase = (next: KitLoadingPhase): void => {
71
+ if (currentPhase === next) return;
72
+ currentPhase = next;
73
+ notify?.(next);
74
+ };
75
+
76
+ const enterVisible = (): void => {
77
+ delayTimer = undefined;
78
+ visibleAt = Date.now();
79
+ setPhase('visible');
80
+ };
81
+
82
+ const enterDone = (): void => {
83
+ minWaitTimer = undefined;
84
+ if (doneHoldMs <= 0) {
85
+ setPhase('idle');
86
+ return;
87
+ }
88
+ setPhase('done');
89
+ doneTimer = setTimeout(() => {
90
+ doneTimer = undefined;
91
+ setPhase('idle');
92
+ }, doneHoldMs);
93
+ };
94
+
95
+ return {
96
+ start() {
97
+ clearTimers();
98
+ if (delayMs <= 0) {
99
+ enterVisible();
100
+ return;
101
+ }
102
+ setPhase('pending-delay');
103
+ delayTimer = setTimeout(enterVisible, delayMs);
104
+ },
105
+ finish() {
106
+ if (currentPhase === 'idle' || currentPhase === 'done') return;
107
+ if (currentPhase === 'pending-delay') {
108
+ clearTimers();
109
+ setPhase('idle');
110
+ return;
111
+ }
112
+ // currentPhase === 'visible'
113
+ if (minWaitTimer !== undefined) return;
114
+ const elapsed = Math.max(0, Date.now() - visibleAt);
115
+ const remainMin = Math.max(0, minDurationMs - elapsed);
116
+ if (remainMin > 0) {
117
+ minWaitTimer = setTimeout(enterDone, remainMin);
118
+ } else {
119
+ enterDone();
120
+ }
121
+ },
122
+ cancel() {
123
+ clearTimers();
124
+ setPhase('idle');
125
+ },
126
+ phase() {
127
+ return currentPhase;
128
+ },
129
+ isVisible() {
130
+ return currentPhase === 'visible';
131
+ },
132
+ };
133
+ }
@@ -119,16 +119,16 @@ export function createMentions(): SomaComponentDefinition {
119
119
  },
120
120
  templateHtml:
121
121
  `<div data-soma-id="root" class="${WRAP}">` +
122
- `<textarea data-soma-id="area" rows="3" aria-haspopup="listbox" class="${AREA.md}"></textarea>` +
122
+ `<textarea data-soma-id="area" rows="3" aria-haspopup="listbox" data-kit-face="field" class="${AREA.md}"></textarea>` +
123
123
  `<div data-soma-id="panel" role="listbox" class="${PANEL_HIDDEN_CLASS}"></div>` +
124
124
  `<div data-soma-id="status" role="status" class="${STATUS}"></div></div>`,
125
- controllerFactory: (ctx) => {
125
+ controllerFactory: createKitController((api) => {
126
126
  let hit: MentionHit | null = null;
127
127
  let cursor: string | null = null;
128
128
  let lastQuery: string | null = null;
129
129
  let paintFn: (() => void) | null = null;
130
130
 
131
- return createKitController({
131
+ return {
132
132
  attach(root, api) {
133
133
  const area = root.querySelector<HTMLTextAreaElement>('[data-soma-id="area"], [data-soma-scoped-id="area"]') as HTMLTextAreaElement;
134
134
  const panel = root.querySelector<HTMLElement>('[data-soma-id="panel"], [data-soma-scoped-id="panel"]') as HTMLElement;
@@ -317,7 +317,7 @@ export function createMentions(): SomaComponentDefinition {
317
317
  root.className = joinClass(WRAP, p.class);
318
318
  paintFn?.();
319
319
  },
320
- })(ctx);
321
- },
320
+ };
321
+ }),
322
322
  };
323
323
  }