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
@@ -33,6 +33,10 @@ export interface KitProductDecl {
33
33
  config?: Record<string, unknown>;
34
34
  /** 产品块级主题(已过 checkBlockTheme):简写 inverse / dark / light,或 { mode?, color? } 词条对象 */
35
35
  theme?: string | Record<string, unknown>;
36
+ /** 区块级语义强调档位 */
37
+ emphasis?: "primary" | "normal" | "subtle";
38
+ /** 区块级容器表面配方 */
39
+ surface?: "card" | "flush" | "plain";
36
40
  }
37
41
 
38
42
  /** 页签槽的一项 */
@@ -44,9 +48,11 @@ export interface KitTabDecl {
44
48
 
45
49
  /** 解析后的页面声明 */
46
50
  export interface KitPageDecl {
47
- page: { url: string; title: string; subtitle?: string; eyebrow?: string; roles?: string[]; breadcrumbs?: Array<{ label: string; href?: string }>; redirect?: KitRedirectDecl; params?: Record<string, Record<string, unknown>>; query?: Record<string, Record<string, unknown>>; locale?: string; dir?: 'ltr' | 'rtl'; theme?: string | Record<string, unknown>; envelope?: import('../app/envelope').KitEnvelope; inheritLayout?: boolean } & Pick<import('../frames/types').KitPageMeta, 'actions' | 'back' | 'status' | 'statusFollow' | 'maxWidth' | 'sticky'>;
51
+ page: { url: string; title: string; subtitle?: string; eyebrow?: string; roles?: string[]; breadcrumbs?: Array<{ label: string; href?: string }>; redirect?: KitRedirectDecl; params?: Record<string, Record<string, unknown>>; query?: Record<string, Record<string, unknown>>; locale?: string; dir?: 'ltr' | 'rtl'; theme?: string | Record<string, unknown>; envelope?: import('../app/envelope').KitEnvelope; inheritLayout?: boolean; view?: string } & Pick<import('../frames/types').KitPageMeta, 'actions' | 'back' | 'status' | 'statusFollow' | 'maxWidth' | 'sticky'>;
48
52
  frame: {
49
53
  kind: string;
54
+ /** 页面是否显式声明了 frame.kind(未显式声明时可继承 kit.app.yaml#layout.frame) */
55
+ explicitKind?: boolean;
50
56
  class?: string;
51
57
  slotClass?: Record<string, string>;
52
58
  /** 页面框自己的配置(目前只有 workspace-frame 用);键与限值见真源 workspaceFrame */
@@ -63,7 +69,7 @@ export interface KitAppContext {
63
69
  /** 已登记基础组件名:内置 13 + 应用 App* */
64
70
  registeredComponents: ReadonlySet<string>;
65
71
  /** 写死形状数据组件契约:内置 Tree / StatGroup / Pager + 应用 App* */
66
- staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[] }>;
72
+ staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[]; propTypes?: Readonly<Record<string, string>> }>;
67
73
  /** 主题头 CSS(kit.app.yaml 的 style: 或内置 kit-theme.css) */
68
74
  themeCss: string;
69
75
  /** 令牌 CSS(soma-foundation 求解的 `:root` 亮色 + 暗色块),拼在主题头前面;缺省不拼(测试可不给) */
@@ -74,6 +80,8 @@ export interface KitAppContext {
74
80
  themeConfig?: import('../theme/theme-tokens').KitThemeConfig;
75
81
  /** 整站 9 维正交主题声明(规整后的 kit.app.yaml#theme) */
76
82
  theme?: import('../app/app-config').KitAppTheme;
83
+ /** 九维主题求解产生的降级清单(供 CLI 检查展示) */
84
+ themeDegradations?: readonly import('../theme/theme-tokens').NineDimDegradation[];
77
85
  /** 应用级默认页面布局继承配置(kit.app.yaml 的 layout:) */
78
86
  layout?: import('../app/app-config').KitAppLayout;
79
87
  /** 应用扩展的业务组件(与内置同名需自行保证不重名;重名以应用的为准) */
@@ -86,10 +94,18 @@ export interface KitAppContext {
86
94
  appCandidates?: readonly string[];
87
95
  /** 样式引擎;缺省 createStyleEnginePort()(Tailwind v4) */
88
96
  styleEngine?: SomaStyleEngine;
97
+ /** 已登记的展示对象(`defineKitApp({ views })`,键 = 类名):成员与方法清单,编译期核页面的 view 路径与 onDraft;缺省 = 没有登记 */
98
+ views?: Readonly<Record<string, { stateKeys: ReadonlySet<string>; methodNames: ReadonlySet<string>; shape?: import('soma-foundation/view-state').ViewStateShape }>>;
89
99
  /** 应用缺省语言(`defineKitApp({ defaultLocale })`):页面不写 `page.locale` 时取它;都没有则不写 lang,运行期按文档语言 */
100
+ /** 应用标识(供运行期主题缓存键与首屏同步恢复区分同源多应用;缺省 default) */
101
+ appName?: string;
90
102
  defaultLocale?: string;
91
103
  /** 应用词条表 `{ 语言: { 键: 文案 } }`(`locales/*.yaml` 读成后交入);`$t:键` 在编译期按页面语言展开 */
92
104
  locales?: Readonly<Record<string, Readonly<Record<string, string>>>>;
105
+ /** 应用级共享枚举字典(kit.app.yaml#dicts):供字段 options: '$dict.<name>' 在编译期静态展开 */
106
+ dicts?: import("../app/app-config").KitAppDicts;
107
+ /** 应用级共享实体定义(kit.app.yaml#entities):供对象 schema: '$entity.<name>' 或 { $ref: '$entity.<name>', pick?, omit?, override? } 在编译期静态展开 */
108
+ entities?: import("../app/app-config").KitAppEntities;
93
109
  }
94
110
 
95
111
  export interface KitPageArtifact {
@@ -0,0 +1,151 @@
1
+ // 展示对象的编译期核对(三层分工:页面只做纯路径绑定,交互逻辑在与页面 1:1 的展示对象)。
2
+ // 页面语法层(object-renderer/view-binding.ts)已核路径是不是纯 view 路径;这里对着登记表核「这些路径 / 方法在展示对象上有没有」:
3
+ // KIT-VIEW-002 页面写了展示对象绑定却没有 page.view,或 page.view 没经 defineKitApp({ views }) 登记
4
+ // KIT-VIEW-003 view 路径的成员没在展示对象 state 里声明
5
+ // KIT-VIEW-004 view.form.onDraft 的方法没在展示对象 methods 里
6
+ // KIT-VIEW-007 绑定的成员性质不对:hidden / disabled / required / 动作 disabled 要标量,绑到数组 / 对象成员报;options 要数组、nodeOptions 要对象,绑到别的形状也报(形状来自 state 初值的扫描)
7
+ // 没写 page.view 的页面(含 AI 生成页)使用默认空展示对象,不允许带任何绑定。纯函数。
8
+
9
+ import { checkBindingKind, type ViewBindingSite, type ViewStateShape } from 'soma-foundation/view-state';
10
+ import { readKitViewInfo } from '../shared/view-info';
11
+ import { normalizeRef } from '../object-renderer/arrange';
12
+ import { collectFieldState, isViewMethodName, isViewPath, viewPathMember, KIT_FIELD_STATE_KEYS } from '../object-renderer/view-binding';
13
+ import type { KitDiagnostic } from '../object-renderer/types';
14
+ import type { KitAppContext, KitPageDecl, KitProductDecl, KitTabDecl } from './types';
15
+
16
+ type Rec = Record<string, unknown>;
17
+ const isRec = (v: unknown): v is Rec => v !== null && typeof v === 'object' && !Array.isArray(v);
18
+
19
+ interface RegisteredViewEntry {
20
+ stateKeys: ReadonlySet<string>;
21
+ methodNames: ReadonlySet<string>;
22
+ shape?: ViewStateShape;
23
+ }
24
+
25
+ /** 兼容字典或数组形式的展示对象登记表(支持直接从 KitViewClass 读取 viewName 与元信息) */
26
+ function resolveRegisteredViews(raw: KitAppContext['views'] | readonly unknown[]): Record<string, RegisteredViewEntry> {
27
+ const out: Record<string, RegisteredViewEntry> = {};
28
+ if (raw === undefined || raw === null) return out;
29
+ if (Array.isArray(raw)) {
30
+ for (const item of raw) {
31
+ const info = readKitViewInfo(item);
32
+ if (info !== undefined) {
33
+ const name = typeof (item as { viewName?: unknown }).viewName === 'string' && (item as { viewName: string }).viewName !== ''
34
+ ? (item as { viewName: string }).viewName
35
+ : info.name;
36
+ out[name] = { stateKeys: info.stateKeys, methodNames: info.methodNames, shape: info.shape };
37
+ } else if (isRec(item) && typeof item.name === 'string' && item.stateKeys instanceof Set && item.methodNames instanceof Set) {
38
+ out[item.name] = item as unknown as RegisteredViewEntry;
39
+ }
40
+ }
41
+ return out;
42
+ }
43
+ for (const [key, val] of Object.entries(raw)) {
44
+ const info = readKitViewInfo(val);
45
+ if (info !== undefined) {
46
+ out[key] = { stateKeys: info.stateKeys, methodNames: info.methodNames, shape: info.shape };
47
+ } else if (isRec(val) && val.stateKeys instanceof Set && val.methodNames instanceof Set) {
48
+ out[key] = val as unknown as RegisteredViewEntry;
49
+ }
50
+ }
51
+ return out;
52
+ }
53
+
54
+ interface Usage {
55
+ /** 用到的成员(view.<成员> 的第一段)及其出处 */
56
+ members: Array<{ name: string; at: string; /** view. 之后的完整路径 */ sub: string; site: ViewBindingSite }>;
57
+ /** 用到的展示对象方法及其出处 */
58
+ methods: Array<{ name: string; at: string }>;
59
+ /** 字段状态语法/位置诊断(兜底:自定义业务组件未调 renderObject 时仍能检出 KIT-VIEW-001 / 006) */
60
+ syntaxDiags: KitDiagnostic[];
61
+ }
62
+
63
+ function usageOfObject(obj: unknown, at: string, out: Usage): void {
64
+ if (!isRec(obj)) return;
65
+ const form = isRec(obj.view) && isRec(obj.view.form) ? obj.view.form : undefined;
66
+ if (form !== undefined) {
67
+ if (typeof form.onDraft === 'string' && isViewMethodName(form.onDraft)) out.methods.push({ name: form.onDraft, at: `${at}.view.form.onDraft` });
68
+ const scan = (items: unknown, base: string): void => {
69
+ if (!Array.isArray(items)) return;
70
+ items.forEach((item, i) => {
71
+ if (item === null || (typeof item !== 'string' && typeof item !== 'object')) return;
72
+ const ref = normalizeRef(item as never) as unknown as Rec;
73
+ for (const key of KIT_FIELD_STATE_KEYS) {
74
+ if (isViewPath(ref[key])) out.members.push({ name: viewPathMember(ref[key] as string), at: `${base}[${i}].${key}`, sub: (ref[key] as string).slice('view.'.length), site: key === 'options' ? 'fieldOptions' : key === 'nodeOptions' ? 'fieldNodeOptions' : 'fieldState' });
75
+ }
76
+ });
77
+ };
78
+ if (isViewPath(form.submitDisabled)) out.members.push({ name: viewPathMember(form.submitDisabled), at: `${at}.view.form.submitDisabled`, sub: form.submitDisabled.slice('view.'.length), site: 'actionDisabled' });
79
+ collectFieldState('form', form as never, `${at}.view.form`, out.syntaxDiags, isRec(obj.schema) ? (obj.schema as never) : undefined);
80
+ scan(form.fields, `${at}.view.form.fields`);
81
+ if (Array.isArray(form.groups)) form.groups.forEach((g, gi) => scan(isRec(g) ? g.fields : undefined, `${at}.view.form.groups[${gi}].fields`));
82
+ }
83
+ const actions = isRec(obj.behavior) && Array.isArray(obj.behavior.actions) ? obj.behavior.actions : [];
84
+ actions.forEach((a, i) => {
85
+ if (!isRec(a) || (a.on !== 'toolbar' && a.on !== 'row')) return;
86
+ // toolbar 动作只支持 disabled;行动作 hidden / disabled 可写 view.<成员>(与 row.<字段> 二选一)
87
+ for (const key of ['disabled', 'hidden'] as const) {
88
+ if (a.on === 'toolbar' && key !== 'disabled') continue;
89
+ const raw = a[key];
90
+ if (isViewPath(raw)) out.members.push({ name: viewPathMember(raw), at: `${at}.behavior.actions[${i}].${key}`, sub: raw.slice('view.'.length), site: key === 'disabled' ? 'actionDisabled' : 'actionHidden' });
91
+ }
92
+ });
93
+ }
94
+
95
+ function usageOfProduct(product: KitProductDecl, at: string, out: Usage): void {
96
+ for (const [role, value] of Object.entries(product.objects ?? {})) {
97
+ if (isRec(value) && (value.schema !== undefined || value.behavior !== undefined || value.view !== undefined)) {
98
+ usageOfObject(value, `${at}.objects.${role}`, out);
99
+ } else if (isRec(value)) {
100
+ // 对象表(many 角色):名字 -> 对象
101
+ for (const [name, sub] of Object.entries(value)) usageOfObject(sub, `${at}.objects.${role}.${name}`, out);
102
+ }
103
+ }
104
+ }
105
+
106
+ /** 收集页面上全部展示对象绑定的用法 */
107
+ export function viewUsageOf(decl: KitPageDecl): Usage {
108
+ const out: Usage = { members: [], methods: [], syntaxDiags: [] };
109
+ for (const [slot, val] of Object.entries(decl.frame.slots)) {
110
+ if (Array.isArray(val)) (val as KitTabDecl[]).forEach((tab, i) => usageOfProduct(tab.product, `frame.slots.${slot}[${i}].product`, out));
111
+ else usageOfProduct(val as KitProductDecl, slot === 'main' ? 'product' : `frame.slots.${slot}`, out);
112
+ }
113
+ return out;
114
+ }
115
+
116
+ /** 核对一页的展示对象用法;返回诊断(空 = 通过) */
117
+ export function checkPageView(decl: KitPageDecl, app: KitAppContext): KitDiagnostic[] {
118
+ const usage = viewUsageOf(decl);
119
+ const diags: KitDiagnostic[] = [...usage.syntaxDiags];
120
+ const name = decl.page.view;
121
+ if (name === undefined) {
122
+ const first = usage.members[0] ?? usage.methods[0];
123
+ if (first !== undefined) {
124
+ diags.push({ code: 'KIT-VIEW-002', path: first.at, message: `页面写了展示对象绑定(${first.name}),但没有 page.view:先写 page.view 指向 defineKitApp({ views }) 登记的展示对象` });
125
+ }
126
+ return diags;
127
+ }
128
+ const registered = resolveRegisteredViews(app.views);
129
+ const info = registered[name];
130
+ if (info === undefined) {
131
+ diags.push({ code: 'KIT-VIEW-002', path: 'page.view', message: `page.view 指向的展示对象 ${name} 没有登记(已登记:${Object.keys(registered).join(' / ') || '无'})` });
132
+ return diags;
133
+ }
134
+ for (const m of usage.members) {
135
+ if (!info.stateKeys.has(m.name)) diags.push({ code: 'KIT-VIEW-003', path: m.at, message: `展示对象 ${name} 的 state 里没有成员 ${m.name}(已声明:${[...info.stateKeys].join(' / ') || '无'})` });
136
+ }
137
+ // 性质匹配:成员存在之后,核对绑定位置对成员形状的要求(形状 = state 初值扫描结果)
138
+ if (info.shape !== undefined) {
139
+ for (const m of usage.members) {
140
+ if (!info.stateKeys.has(m.name)) continue;
141
+ const problem = checkBindingKind(info.shape, m.sub, m.site);
142
+ if (problem !== undefined) {
143
+ diags.push({ code: 'KIT-VIEW-007', path: m.at, message: `展示对象 ${name} 的成员 ${problem.path} 是${problem.actual === 'array' ? '数组' : problem.actual === 'object' ? '对象' : '标量'},${problem.label} 要绑${problem.expected.includes('array') ? '数组成员(候选项 [{ value, label }])' : problem.expected.includes('object') ? '对象成员({ "<节点类型>.<字段键>": [{ value, label }] })' : '标量(' + problem.expected.join(' / ') + ');绑它的某个标量字段(view.' + problem.path + '.<字段>)或另声明一个布尔成员'}` });
144
+ }
145
+ }
146
+ }
147
+ for (const m of usage.methods) {
148
+ if (!info.methodNames.has(m.name)) diags.push({ code: 'KIT-VIEW-004', path: m.at, message: `展示对象 ${name} 的 methods 里没有方法 ${m.name}(已声明:${[...info.methodNames].join(' / ') || '无'})` });
149
+ }
150
+ return diags;
151
+ }
@@ -88,7 +88,7 @@ export function createAmountBreakdown(): SomaComponentDefinition {
88
88
  },
89
89
  },
90
90
  templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
91
- controllerFactory: createKitController({
91
+ controllerFactory: createKitController(() => ({
92
92
  attach(root, api) {
93
93
  const onClick = (event: Event): void => {
94
94
  const btn = (event.target as HTMLElement | null)?.closest<HTMLButtonElement>('[data-kit-action]');
@@ -127,6 +127,6 @@ export function createAmountBreakdown(): SomaComponentDefinition {
127
127
  root.appendChild(row);
128
128
  }
129
129
  },
130
- }),
130
+ })),
131
131
  };
132
132
  }
@@ -81,7 +81,7 @@ export function createAnchorNav(): SomaComponentDefinition {
81
81
  },
82
82
  },
83
83
  templateHtml: `<nav data-soma-id="root" class="${ROOT_CLASS}"></nav>`,
84
- controllerFactory: createKitController({
84
+ controllerFactory: createKitController(() => ({
85
85
  attach(root, api) {
86
86
  const doc = root.ownerDocument;
87
87
  const view = doc.defaultView;
@@ -220,6 +220,6 @@ export function createAnchorNav(): SomaComponentDefinition {
220
220
  render(root, p) {
221
221
  HANDLES.get(root)?.update(p);
222
222
  },
223
- }),
223
+ })),
224
224
  };
225
225
  }
@@ -150,7 +150,7 @@ export function createApprovalFlow(): SomaComponentDefinition {
150
150
  },
151
151
  },
152
152
  templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
153
- controllerFactory: createKitController({
153
+ controllerFactory: createKitController(() => ({
154
154
  attach(root, api) {
155
155
  const onClick = (event: Event): void => {
156
156
  const target = event.target as HTMLElement | null;
@@ -264,6 +264,6 @@ export function createApprovalFlow(): SomaComponentDefinition {
264
264
  root.appendChild(foot);
265
265
  }
266
266
  },
267
- }),
267
+ })),
268
268
  };
269
269
  }
@@ -22,13 +22,14 @@
22
22
  // 每次勾选抛 `change { value, added, removed, reason }`;save_label 非空时底部出现保存钮,校验通过抛
23
23
  // `saved { values, object, model, mode, value, added, removed, reason }`;cancel_label 非空时出现取消钮,抛 `cancel {}` 并还原草稿。
24
24
 
25
- import type { SomaComponentControllerContext, SomaComponentDefinition } from 'soma-core';
25
+ import type { SomaComponentDefinition } from 'soma-core';
26
26
  import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
27
27
  import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
28
- import { bool, findRoot, joinClass, num, str } from '../base/shared';
28
+ import { bool, createKitController, joinClass, num, str } from '../base/shared';
29
29
  import { kitIcon } from '../base/icons';
30
30
  import { kitText, type KitTextKey } from '../i18n/kit-text';
31
- import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
31
+ import { setKitFace } from '../recipes';
32
+ import { kitBusyOf, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
32
33
  import { classTokens, keyMap, mk, recOf } from './shape-util';
33
34
  import { envelopeOf } from './permission-tree';
34
35
  import { attrEsc } from './d9-util';
@@ -254,8 +255,8 @@ export function createAssignmentPicker(): SomaComponentDefinition {
254
255
  keyboard: { layout: 'list', wrap: false, typeahead: false, focus_model: 'activedescendant', space: 'toggle_select' },
255
256
  },
256
257
  templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
257
- controllerFactory: (ctx: SomaComponentControllerContext) => {
258
- const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
258
+ controllerFactory: createKitController((api) => {
259
+ const P = (): Record<string, unknown> => api.props();
259
260
  const uid = `kit-assign-${++instanceCount}`;
260
261
  let root: HTMLElement | null = null;
261
262
  let items: KitAssignItem[] = [];
@@ -277,7 +278,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
277
278
  let fieldLabel: HTMLLabelElement; let area: HTMLTextAreaElement; let fieldError: HTMLElement; let errorBox: HTMLElement;
278
279
  let footBox: HTMLElement; let saveBox: HTMLElement; let cancelBox: HTMLElement; let saveBtn: HTMLButtonElement; let cancelBtn: HTMLButtonElement;
279
280
 
280
- const T = (): KitAssignmentPickerTexts => textsOf(P().texts, ctx.host);
281
+ const T = (): KitAssignmentPickerTexts => textsOf(P().texts, api.host);
281
282
  const locked = (): boolean => bool(P().disabled);
282
283
  const boxOf = (child: HTMLElement): HTMLElement => { const b = document.createElement('div'); b.appendChild(child); return b; };
283
284
  const mapOf = (): KitAssignmentPickerMap => keyMap(KIT_ASSIGNMENT_PICKER_DEFAULT_MAP, P().map) as KitAssignmentPickerMap;
@@ -294,6 +295,13 @@ export function createAssignmentPicker(): SomaComponentDefinition {
294
295
  };
295
296
 
296
297
  const pageStep = SOMA_SIZE_UNITS.collection.keyboard.pageStep;
298
+ // 方向键移动光标后,把活动项滚进可见区(测试环境无 scrollIntoView 时不抛)
299
+ const scrollCursorIntoView = (): void => {
300
+ const id = listEl?.getAttribute('aria-activedescendant');
301
+ if (id == null || id === '') return;
302
+ const node = listEl?.querySelector<HTMLElement>(`[id="${id.replace(/"/g, '\\"')}"]`);
303
+ node?.scrollIntoView?.({ block: 'nearest' });
304
+ };
297
305
  const wiring = createKeyboardWiring({
298
306
  contract: { layout: 'list', wrap: false, typeahead: false, focus_model: 'activedescendant', space: 'toggle_select' },
299
307
  host: () => listEl ?? null,
@@ -301,12 +309,12 @@ export function createAssignmentPicker(): SomaComponentDefinition {
301
309
  typeaheadDebounceMs: 0,
302
310
  paging: { listItems: pageStep.listItems, gridRows: pageStep.gridRows },
303
311
  getCursor: () => cursor,
304
- setCursor: (key) => { cursor = key; paintList(); },
312
+ setCursor: (key) => { cursor = key; paintList(); scrollCursorIntoView(); },
305
313
  onActivate: (key) => toggle(key),
306
314
  onToggle: (key) => toggle(key),
307
315
  });
308
316
 
309
- const emitChange = (): void => { ctx.emit('change', payload()); };
317
+ const emitChange = (): void => { api.emit('change', payload()); };
310
318
 
311
319
  const toggle = (id: string): void => {
312
320
  const item = byId().get(id);
@@ -420,6 +428,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
420
428
  const allOn = pickable.length > 0 && pickable.every((i) => now.has(i.id));
421
429
  const btn = mk('button', GROUP_BTN_CLASS, `${g.name}:${allOn ? t.group_none : t.group_all}`);
422
430
  btn.type = 'button';
431
+ setKitFace(btn, 'raised');
423
432
  btn.disabled = locked() || pickable.length === 0;
424
433
  btn.setAttribute('data-kit-group', g.name);
425
434
  btn.setAttribute('data-kit-group-on', allOn ? 'off' : 'on');
@@ -503,8 +512,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
503
512
  paintList();
504
513
  }
505
514
 
506
- const kb = createKitBusy(P);
507
- const busy = kb.busy;
515
+ const busy = (): boolean => kitBusyOf(P());
508
516
  const save = (): void => {
509
517
  if (locked() || error !== '' || busy()) return;
510
518
  const p = P();
@@ -515,26 +523,26 @@ export function createAssignmentPicker(): SomaComponentDefinition {
515
523
  notice = '';
516
524
  paint();
517
525
  area.focus();
518
- ctx.emit('invalid', { field: 'reason' });
526
+ api.emit('invalid', { field: 'reason' });
519
527
  return;
520
528
  }
521
529
  const min = num(p.min_selected) ?? 0;
522
530
  if (min > 0 && now.size < min) {
523
531
  notice = fill(t.min_selected, { n: min });
524
532
  paint();
525
- ctx.emit('invalid', { field: 'min_selected' });
533
+ api.emit('invalid', { field: 'min_selected' });
526
534
  return;
527
535
  }
528
536
  const out = payload();
529
537
  if (bool(p.require_change) && out.added.length + out.removed.length === 0) {
530
538
  notice = t.need_change;
531
539
  paint();
532
- ctx.emit('invalid', { field: 'change' });
540
+ api.emit('invalid', { field: 'change' });
533
541
  return;
534
542
  }
535
543
  notice = '';
536
544
  paint();
537
- ctx.emit('saved', { values: out, object: str(p.object), model: out, mode: str(p.mode, 'edit'), ...out });
545
+ api.emit('saved', { values: out, object: str(p.object), model: out, mode: str(p.mode, 'edit'), ...out });
538
546
  };
539
547
 
540
548
  const build = (host: HTMLElement): void => {
@@ -548,12 +556,15 @@ export function createAssignmentPicker(): SomaComponentDefinition {
548
556
  head.append(titleEl, summaryEl);
549
557
  changesEl = mk('p', CHANGES_CLASS);
550
558
  search = mk('input', SEARCH_CLASS);
559
+ setKitFace(search, 'field');
551
560
  search.type = 'search';
552
561
  search.setAttribute('autocomplete', 'off');
553
562
  searchBox = boxOf(search);
554
563
  searchBox.className = 'flex flex-1';
555
564
  allBtn = mk('button', TOOL_BTN_CLASS); allBtn.type = 'button';
556
565
  clearBtn = mk('button', TOOL_BTN_CLASS); clearBtn.type = 'button';
566
+ setKitFace(allBtn, 'raised');
567
+ setKitFace(clearBtn, 'raised');
557
568
  const tools = mk('div', TOOLS_CLASS);
558
569
  tools.append(searchBox, allBtn, clearBtn);
559
570
  groupBarEl = mk('div', 'hidden');
@@ -566,6 +577,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
566
577
  mainBox.appendChild(mainInner);
567
578
  fieldLabel = mk('label', FIELD_LABEL_CLASS);
568
579
  area = mk('textarea', AREA_CLASS);
580
+ setKitFace(area, 'field');
569
581
  area.rows = 4;
570
582
  const areaId = `${uid}-reason`;
571
583
  area.id = areaId;
@@ -581,6 +593,8 @@ export function createAssignmentPicker(): SomaComponentDefinition {
581
593
  grid.append(mainBox, sideBox);
582
594
  cancelBtn = mk('button', CANCEL_CLASS); cancelBtn.type = 'button';
583
595
  saveBtn = mk('button', SAVE_CLASS); saveBtn.type = 'button';
596
+ setKitFace(cancelBtn, 'raised');
597
+ setKitFace(saveBtn, 'raised');
584
598
  cancelBox = boxOf(cancelBtn);
585
599
  saveBox = boxOf(saveBtn);
586
600
  const foot = mk('div', FOOT_CLASS);
@@ -623,30 +637,27 @@ export function createAssignmentPicker(): SomaComponentDefinition {
623
637
  notice = '';
624
638
  reason = str(envelopeOf(P().data, mapOf().items)[mapOf().reason]);
625
639
  paint();
626
- ctx.emit('cancel', {});
640
+ api.emit('cancel', {});
627
641
  });
628
642
  };
629
643
 
630
644
  return {
631
- onMount(): void {
632
- root = findRoot(ctx.host);
645
+ busyAware: true,
646
+ attach(rootEl) {
647
+ root = rootEl;
633
648
  build(root);
634
- sync();
635
- paint();
636
- kb.subscribe(() => { if (root) paint(); });
649
+ return () => {
650
+ for (const fn of removers) fn();
651
+ removers = [];
652
+ root = null;
653
+ };
637
654
  },
638
- onPropsChange(): void {
639
- if (!root) return;
655
+ render(rootEl) {
656
+ root = rootEl;
640
657
  sync();
641
658
  paint();
642
659
  },
643
- onUnmount(): void {
644
- kb.dispose();
645
- for (const fn of removers) fn();
646
- removers = [];
647
- root = null;
648
- },
649
660
  };
650
- },
661
+ }),
651
662
  };
652
663
  }
@@ -10,8 +10,15 @@
10
10
 
11
11
  import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
12
12
  import { bool, createKitController, joinClass, str } from '../base/shared';
13
+ import {
14
+ createLoadingGate,
15
+ KIT_LOADING_GATE_DEFAULTS,
16
+ type KitLoadingGate,
17
+ type KitLoadingPhase,
18
+ } from '../base/loading-gate';
13
19
  import { watchKitOutcome, type KitOutcome } from './outcome-watch';
14
20
  import { kitText } from '../i18n/kit-text';
21
+ import { setKitFace } from '../recipes';
15
22
  import { KIT_BUSY_PROP_DEFS, cancelKitAction, kitBusyOf } from '../base/action-busy';
16
23
  import {
17
24
  actionButton, BADGE_BASE, BUTTON_CLASS_TOKENS, classTokens, mk, recOf, rowsOf, shapeToneOf, textOf, TONE_SOFT,
@@ -101,13 +108,44 @@ interface PanelState {
101
108
  btnSlot: HTMLElement | null;
102
109
  msg: HTMLElement | null;
103
110
  resSlot: HTMLElement | null;
111
+ /** 加载反馈三阈值状态机 */
112
+ gate: KitLoadingGate;
113
+ wasBusy: boolean;
104
114
  }
105
115
 
106
116
  export function createAsyncResultPanel(): SomaComponentDefinition {
107
117
  const states = new WeakMap<HTMLElement, PanelState>();
108
118
  const stateOf = (root: HTMLElement): PanelState => {
109
119
  let s = states.get(root);
110
- if (!s) { s = { outcomeName: '', offOutcome: null, outcome: null, area: null, top: null, mid: null, bottom: null, promptVisible: false, body: null, btnSlot: null, msg: null, resSlot: null }; states.set(root, s); }
120
+ if (!s) {
121
+ const gate = createLoadingGate(
122
+ {
123
+ delayMs: KIT_LOADING_GATE_DEFAULTS.delayMs,
124
+ minDurationMs: KIT_LOADING_GATE_DEFAULTS.minDurationMs,
125
+ doneHoldMs: KIT_LOADING_GATE_DEFAULTS.doneHoldMs,
126
+ },
127
+ (phase: KitLoadingPhase) => {
128
+ root.setAttribute('data-kit-loading-phase', phase);
129
+ },
130
+ );
131
+ s = {
132
+ outcomeName: '',
133
+ offOutcome: null,
134
+ outcome: null,
135
+ area: null,
136
+ top: null,
137
+ mid: null,
138
+ bottom: null,
139
+ promptVisible: false,
140
+ body: null,
141
+ btnSlot: null,
142
+ msg: null,
143
+ resSlot: null,
144
+ gate,
145
+ wasBusy: false,
146
+ };
147
+ states.set(root, s);
148
+ }
111
149
  return s;
112
150
  };
113
151
 
@@ -143,7 +181,7 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
143
181
  },
144
182
  services: ['data'],
145
183
  templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
146
- controllerFactory: createKitController({
184
+ controllerFactory: createKitController(() => ({
147
185
  busyAware: true,
148
186
  attach(root, api) {
149
187
  const onClick = (event: Event): void => {
@@ -153,7 +191,12 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
153
191
  if (key === 'run') api.emit('run', { prompt: stateOf(root).area?.value ?? '' });
154
192
  else if (key === 'cancel' || key === 'adopt' || key === 'dismiss') {
155
193
  // 所接 request 动作声明了 cancelable:真正中止在途请求(没声明则只发 cancel 事件,行为同前)
156
- if (key === 'cancel') cancelKitAction(str(api.props().busy_action, ''));
194
+ if (key === 'cancel') {
195
+ const st = stateOf(root);
196
+ st.wasBusy = false;
197
+ st.gate.cancel();
198
+ cancelKitAction(str(api.props().busy_action, ''));
199
+ }
157
200
  api.emit(key, {});
158
201
  }
159
202
  };
@@ -166,7 +209,9 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
166
209
  return () => {
167
210
  root.removeEventListener('click', onClick);
168
211
  root.removeEventListener('change', onChange);
169
- states.get(root)?.offOutcome?.();
212
+ const st = states.get(root);
213
+ st?.gate.cancel();
214
+ st?.offOutcome?.();
170
215
  states.delete(root);
171
216
  };
172
217
  },
@@ -193,6 +238,17 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
193
238
  if (outName !== '' && st.outcome?.status === 'cancelled') data.message = kitText('soma.kit.request_cancelled', undefined, root);
194
239
  const status = asyncStatusOf(data.status);
195
240
  const busy = status === 'busy';
241
+ const actionBusy = kitBusyOf(p);
242
+ const isBusy = busy || actionBusy;
243
+ if (isBusy && !st.wasBusy) {
244
+ st.wasBusy = true;
245
+ st.gate.start();
246
+ } else if (!isBusy && st.wasBusy) {
247
+ st.wasBusy = false;
248
+ if (status === 'idle') st.gate.cancel();
249
+ else st.gate.finish();
250
+ }
251
+ root.setAttribute('data-kit-loading-phase', st.gate.phase());
196
252
  const showPrompt = bool(p.show_prompt);
197
253
  root.className = joinClass(ROOT_CLASS, p.class);
198
254
 
@@ -224,6 +280,7 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
224
280
  const wrap = mk('label', LABEL_WRAP);
225
281
  if (str(p.prompt_label) !== '') wrap.appendChild(mk('span', LABEL_CLASS, str(p.prompt_label)));
226
282
  const area = mk('textarea', AREA_CLASS);
283
+ setKitFace(area, 'field');
227
284
  area.setAttribute('data-kit-prompt', '');
228
285
  area.value = str(p.prompt_value);
229
286
  area.setAttribute('data-kit-given', str(p.prompt_value));
@@ -259,7 +316,6 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
259
316
  bottom.appendChild(st.body);
260
317
  }
261
318
  const body = st.resSlot;
262
- const actionBusy = kitBusyOf(p);
263
319
  const buttons = mk('div', BUTTONS_CLASS);
264
320
  if (p.show_run !== false) {
265
321
  buttons.appendChild(actionButton({
@@ -303,6 +359,6 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
303
359
  body.appendChild(box);
304
360
  }
305
361
  },
306
- }),
362
+ })),
307
363
  };
308
364
  }
@@ -183,7 +183,7 @@ export function createBreadcrumbs(): SomaComponentDefinition {
183
183
  },
184
184
  },
185
185
  templateHtml: `<nav data-soma-id="root" class="${ROOT_CLASS}"></nav>`,
186
- controllerFactory: createKitController({
186
+ controllerFactory: createKitController(() => ({
187
187
  attach(root, api) {
188
188
  const handle = mountKitBreadcrumbs(root, (name, payload) => api.emit(name, payload));
189
189
  HANDLES.set(root, handle);
@@ -192,6 +192,6 @@ export function createBreadcrumbs(): SomaComponentDefinition {
192
192
  render(root, p) {
193
193
  HANDLES.get(root)?.update(p);
194
194
  },
195
- }),
195
+ })),
196
196
  };
197
197
  }