soma-core 2.2.4 → 2.2.6

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 (259) hide show
  1. package/README.md +5 -6
  2. package/bin/soma.cjs +2 -2
  3. package/core/build/compiler/flat-page.ts +16 -0
  4. package/core/build/compiler/full-manifest-builder.ts +0 -3
  5. package/core/build/compiler/page-assets.ts +0 -1
  6. package/core/build/compiler/page-closure.ts +245 -0
  7. package/core/build/compiler/page-declaration-compiler.ts +2 -5
  8. package/core/build/compiler/soma-precompile.js +1848 -3244
  9. package/core/build/compiler/soma-precompile.ts +4 -7
  10. package/core/build/component-tree/artifact-codec.ts +4 -8
  11. package/core/build/lsp/soma-declaration.cjs +1 -1
  12. package/core/build/lsp/std-completion.generated.json +3 -3
  13. package/core/client/a11y/a11y-config.ts +2 -1
  14. package/core/client/a11y/dom-id.ts +1 -1
  15. package/core/client/base/SomaHttpClient.ts +11 -3
  16. package/core/client/base/SomaPageRootBase.ts +6 -0
  17. package/core/client/base/defineSomaView.ts +178 -0
  18. package/core/client/base/index.ts +13 -0
  19. package/core/client/base/view-context.ts +328 -0
  20. package/core/client/behavior/adapter-collection.ts +2 -2
  21. package/core/client/compiler/manifest-compiler.ts +5 -36
  22. package/core/client/component/component-definition.types.ts +2 -1
  23. package/core/client/component/component-manager.ts +110 -20
  24. package/core/client/component/structure-adapter.ts +3 -7
  25. package/core/client/container/SomaContainerAdapter.ts +9 -1
  26. package/core/client/data/data-object-resolver.ts +516 -181
  27. package/core/client/data/data-write-actions.ts +79 -15
  28. package/core/client/data/format-config.ts +3 -1
  29. package/core/client/data/region-scope-port.ts +11 -0
  30. package/core/client/engine/asset-resolver.ts +2 -5
  31. package/core/client/engine/dom-renderer.ts +7 -40
  32. package/core/client/engine/event-engine.ts +1 -105
  33. package/core/client/engine/property-watcher.ts +1 -1
  34. package/core/client/engine/reactive-proxy.ts +78 -17
  35. package/core/client/engine/runtime-builder.ts +0 -14
  36. package/core/client/engine/scope-resolver.ts +18 -0
  37. package/core/client/engine/soma-bootstrap.ts +385 -98
  38. package/core/client/engine/style-binder.ts +49 -106
  39. package/core/client/engine/timer-engine.ts +11 -1
  40. package/core/client/host-bridge/load-host-domain-class.ts +2 -1
  41. package/core/client/infra/http/SomaHttpService.ts +15 -4
  42. package/core/client/infra/i18n/pack-locales.ts +2 -2
  43. package/core/client/mount/domain-rule.ts +7 -3
  44. package/core/client/mount/mount-page.ts +38 -5
  45. package/core/client/mount/types.ts +2 -0
  46. package/core/client/parser/confirm-spec.ts +1 -1
  47. package/core/client/parser/data-config-parser.ts +27 -210
  48. package/core/client/parser/pipeline-parser.ts +14 -59
  49. package/core/client/parser/style-config-parser.ts +101 -95
  50. package/core/client/parser/timer-parser.ts +21 -0
  51. package/core/client/parser/ui-config-parser.ts +64 -12
  52. package/core/client/registry/declaration-renderer.ts +1 -1
  53. package/core/client/runtime/SomaRuntimeServices.ts +2 -1
  54. package/core/client/runtime/SomaSnapshotStore.ts +5 -0
  55. package/core/client/security/url-guard.ts +71 -11
  56. package/core/client/validation/async-check-registry.ts +2 -1
  57. package/core/client/validation/contract-validator.ts +2 -6
  58. package/core/client/validation/field-rules.ts +3 -13
  59. package/core/client/validation/object-rules.ts +2 -10
  60. package/core/index.ts +1 -35
  61. package/core/inspect/check-product.ts +5 -5
  62. package/core/inspect/runtime.ts +2 -1
  63. package/core/server/api/dispatch-service-api.ts +35 -36
  64. package/core/server/api/load-host-service.ts +5 -4
  65. package/core/server/compile-port.ts +1 -1
  66. package/core/server/host/app-config-composer.ts +2 -1
  67. package/core/server/host/host-assembly-entry.ts +1 -0
  68. package/core/server/host/host-assembly.ts +47 -3
  69. package/core/server/host/host-caller.ts +2 -1
  70. package/core/server/host/host-dir.ts +9 -0
  71. package/core/server/host/host-response-headers.ts +2 -1
  72. package/core/server/host/invoke-host-request-hook.ts +28 -4
  73. package/core/server/host/published-page-assets.ts +2 -1
  74. package/core/server/host/resolve-host-request-hook.ts +25 -7
  75. package/core/server/host/server-page-assets.ts +4 -4
  76. package/core/server/host/virtual-pages.ts +3 -2
  77. package/core/server/infra/cache/ServerFileCache.ts +79 -9
  78. package/core/server/registry/api-registry-store.ts +3 -1
  79. package/core/server/registry/declaration-precompiler.ts +0 -2
  80. package/core/server/registry/page-registry-repository.ts +2 -1
  81. package/core/server/registry/page-registry-store.ts +2 -1
  82. package/core/server/registry/registry-error.ts +6 -1
  83. package/core/server/registry/registry-file-lock.ts +296 -23
  84. package/core/server/registry/request-body-limit.ts +3 -2
  85. package/core/server/registry/validation/declaration-safety-scan.ts +151 -27
  86. package/core/server/runtime-space/access-gate.ts +21 -7
  87. package/core/server/runtime-space/bindings.ts +3 -6
  88. package/core/server/runtime-space/dynamic-pages.ts +181 -49
  89. package/core/server/runtime-space/errors.ts +3 -0
  90. package/core/server/runtime-space/inject.ts +74 -15
  91. package/core/server/runtime-space/page-grants.ts +7 -1
  92. package/core/server/runtime-space/resolve.ts +66 -19
  93. package/core/server/runtime-space/store.ts +32 -3
  94. package/core/server/runtime-space/submit-steps.ts +2 -1
  95. package/core/server/runtime-space/types.ts +3 -1
  96. package/core/shared/component-tree-errors.ts +2 -1
  97. package/core/shared/contract-a11y.ts +1 -1
  98. package/core/shared/contract-sections.ts +2 -2
  99. package/core/shared/core-diagnostic-codes.ts +8 -0
  100. package/core/shared/declaration-keys.ts +1 -1
  101. package/core/shared/engines/engine-error.ts +2 -1
  102. package/core/shared/generation-error.ts +2 -1
  103. package/core/shared/page-envelope.ts +1 -1
  104. package/core/shared/pure-binding.ts +88 -0
  105. package/core/shared/registry-generated/diagnostic-registry-index.ts +16 -19
  106. package/core/shared/registry-generated/diagnostic-registry.ts +135 -177
  107. package/core/shared/registry-generated/limits.ts +49 -13
  108. package/core/shared/registry-generated/std-grammar-completion.ts +0 -4
  109. package/core/shared/registry-generated/std-grammar-views.ts +40 -10
  110. package/core/shared/registry-generated/std-grammar.ts +42 -20
  111. package/core/shared/soma-error.ts +36 -0
  112. package/core/shared/types/compile-port.types.ts +1 -1
  113. package/core/shared/types/data-config.types.ts +17 -17
  114. package/core/shared/types/engine.types.ts +0 -3
  115. package/core/shared/types/event.types.ts +1 -11
  116. package/core/shared/types/generation-error.types.ts +5 -1
  117. package/core/shared/types/host-assembly.types.ts +7 -1
  118. package/core/shared/types/manifest.types.ts +0 -3
  119. package/core/shared/types/region-scope.types.ts +5 -1
  120. package/core/shared/types/scope-manifest.types.ts +0 -2
  121. package/core/shared/types/style-config.types.ts +21 -21
  122. package/core/shared/types/ui-config.types.ts +4 -5
  123. package/core/shared/types/watcher.types.ts +1 -1
  124. package/dist/browser/runtime-bundle.manifest.json +11 -13
  125. package/dist/browser/soma-runtime.js +2567 -2696
  126. package/dist/core/index.cjs +5446 -5486
  127. package/dist/host-native/aot-builder.cjs +46 -1
  128. package/dist/host-native/native-server.cjs +4879 -4505
  129. package/dist/lsp/component-tree.cjs +5814 -7042
  130. package/dist/types/build/compiler/full-manifest-builder.d.ts +0 -2
  131. package/dist/types/build/compiler/page-closure.d.ts +21 -0
  132. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -4
  133. package/dist/types/build/compiler/soma-precompile.d.ts +1 -3
  134. package/dist/types/build/component-tree/artifact-codec.d.ts +0 -2
  135. package/dist/types/client/a11y/a11y-config.d.ts +2 -1
  136. package/dist/types/client/base/SomaHttpClient.d.ts +1 -1
  137. package/dist/types/client/base/SomaPageRootBase.d.ts +5 -0
  138. package/dist/types/client/base/defineSomaView.d.ts +46 -0
  139. package/dist/types/client/base/index.d.ts +2 -0
  140. package/dist/types/client/base/view-context.d.ts +136 -0
  141. package/dist/types/client/behavior/adapter-collection.d.ts +1 -1
  142. package/dist/types/client/compiler/manifest-compiler.d.ts +0 -3
  143. package/dist/types/client/component/component-definition.types.d.ts +2 -1
  144. package/dist/types/client/component/component-manager.d.ts +29 -0
  145. package/dist/types/client/data/data-object-resolver.d.ts +91 -31
  146. package/dist/types/client/data/format-config.d.ts +2 -1
  147. package/dist/types/client/engine/dom-renderer.d.ts +1 -2
  148. package/dist/types/client/engine/event-engine.d.ts +0 -7
  149. package/dist/types/client/engine/reactive-proxy.d.ts +11 -4
  150. package/dist/types/client/engine/runtime-builder.d.ts +0 -4
  151. package/dist/types/client/engine/soma-bootstrap.d.ts +44 -6
  152. package/dist/types/client/engine/style-binder.d.ts +8 -4
  153. package/dist/types/client/host-bridge/load-host-domain-class.d.ts +2 -1
  154. package/dist/types/client/mount/domain-rule.d.ts +2 -0
  155. package/dist/types/client/mount/mount-page.d.ts +2 -1
  156. package/dist/types/client/mount/types.d.ts +2 -0
  157. package/dist/types/client/parser/data-config-parser.d.ts +6 -5
  158. package/dist/types/client/parser/style-config-parser.d.ts +7 -3
  159. package/dist/types/client/parser/timer-parser.d.ts +5 -0
  160. package/dist/types/client/parser/ui-config-parser.d.ts +6 -2
  161. package/dist/types/client/runtime/SomaSnapshotStore.d.ts +2 -0
  162. package/dist/types/client/security/url-guard.d.ts +14 -0
  163. package/dist/types/client/validation/async-check-registry.d.ts +2 -1
  164. package/dist/types/client/validation/object-rules.d.ts +0 -5
  165. package/dist/types/index.d.ts +2 -7
  166. package/dist/types/inspect/runtime.d.ts +2 -1
  167. package/dist/types/server/api/dispatch-service-api.d.ts +5 -0
  168. package/dist/types/server/api/load-host-service.d.ts +1 -1
  169. package/dist/types/server/compile-port.d.ts +1 -1
  170. package/dist/types/server/host/host-assembly-entry.d.ts +1 -1
  171. package/dist/types/server/host/host-assembly.d.ts +2 -0
  172. package/dist/types/server/host/host-dir.d.ts +2 -0
  173. package/dist/types/server/host/invoke-host-request-hook.d.ts +10 -3
  174. package/dist/types/server/host/published-page-assets.d.ts +2 -1
  175. package/dist/types/server/host/resolve-host-request-hook.d.ts +18 -5
  176. package/dist/types/server/host/server-page-assets.d.ts +2 -1
  177. package/dist/types/server/infra/cache/ServerFileCache.d.ts +8 -0
  178. package/dist/types/server/registry/declaration-precompiler.d.ts +0 -1
  179. package/dist/types/server/registry/registry-error.d.ts +5 -1
  180. package/dist/types/server/registry/registry-file-lock.d.ts +30 -0
  181. package/dist/types/server/registry/request-body-limit.d.ts +3 -2
  182. package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +3 -0
  183. package/dist/types/server/runtime-space/access-gate.d.ts +7 -0
  184. package/dist/types/server/runtime-space/bindings.d.ts +3 -2
  185. package/dist/types/server/runtime-space/dynamic-pages.d.ts +6 -1
  186. package/dist/types/server/runtime-space/errors.d.ts +1 -1
  187. package/dist/types/server/runtime-space/resolve.d.ts +2 -0
  188. package/dist/types/server/runtime-space/store.d.ts +8 -1
  189. package/dist/types/server/runtime-space/submit-steps.d.ts +2 -1
  190. package/dist/types/server/runtime-space/types.d.ts +3 -1
  191. package/dist/types/shared/component-tree-errors.d.ts +2 -1
  192. package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
  193. package/dist/types/shared/declaration-keys.d.ts +1 -1
  194. package/dist/types/shared/engines/engine-error.d.ts +2 -1
  195. package/dist/types/shared/generation-error.d.ts +2 -1
  196. package/dist/types/shared/pure-binding.d.ts +48 -0
  197. package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +119 -158
  198. package/dist/types/shared/registry-generated/limits.d.ts +40 -10
  199. package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +0 -30
  200. package/dist/types/shared/registry-generated/std-grammar-views.d.ts +97 -23
  201. package/dist/types/shared/registry-generated/std-grammar.d.ts +109 -241
  202. package/dist/types/shared/soma-error.d.ts +15 -0
  203. package/dist/types/shared/types/data-config.types.d.ts +14 -16
  204. package/dist/types/shared/types/engine.types.d.ts +0 -3
  205. package/dist/types/shared/types/event.types.d.ts +1 -7
  206. package/dist/types/shared/types/generation-error.types.d.ts +1 -1
  207. package/dist/types/shared/types/host-assembly.types.d.ts +2 -0
  208. package/dist/types/shared/types/manifest.types.d.ts +0 -3
  209. package/dist/types/shared/types/region-scope.types.d.ts +4 -1
  210. package/dist/types/shared/types/scope-manifest.types.d.ts +0 -2
  211. package/dist/types/shared/types/style-config.types.d.ts +17 -19
  212. package/dist/types/shared/types/ui-config.types.d.ts +4 -5
  213. package/host-native/bin/host-native.cjs +22 -1
  214. package/host-native/client/browser-entry.ts +44 -9
  215. package/host-native/src/aot-builder.ts +52 -0
  216. package/host-native/src/host-prepare.ts +39 -5
  217. package/host-native/src/manifest-http.ts +2 -3
  218. package/host-native/src/native-server.ts +812 -174
  219. package/host-native/src/page-http.ts +3 -3
  220. package/host-native/src/public-packages.cjs +0 -1
  221. package/host-native/src/registry-handler.ts +12 -5
  222. package/host-native/src/static-file.ts +203 -53
  223. package/package.json +3 -2
  224. package/core/client/engine/step-runner.ts +0 -212
  225. package/core/client/engine/trigger-engine.ts +0 -55
  226. package/core/client/format/zoned.ts +0 -10
  227. package/core/client/parser/step-parser.ts +0 -359
  228. package/core/client/parser/trigger-parser.ts +0 -90
  229. package/core/client/parser/value-lang.ts +0 -340
  230. package/core/client/time/instant.ts +0 -2
  231. package/core/shared/calc/coerce.ts +0 -2
  232. package/core/shared/calc/errors.ts +0 -40
  233. package/core/shared/calc/evaluator.ts +0 -113
  234. package/core/shared/calc/index.ts +0 -11
  235. package/core/shared/calc/lexer.ts +0 -189
  236. package/core/shared/calc/parser.ts +0 -193
  237. package/core/shared/calc/typer.ts +0 -171
  238. package/core/shared/date-parts.ts +0 -2
  239. package/core/shared/show-when.ts +0 -77
  240. package/core/shared/types/step.types.ts +0 -91
  241. package/core/shared/types/trigger.types.ts +0 -14
  242. package/dist/types/client/engine/step-runner.d.ts +0 -42
  243. package/dist/types/client/engine/trigger-engine.d.ts +0 -16
  244. package/dist/types/client/format/zoned.d.ts +0 -1
  245. package/dist/types/client/parser/step-parser.d.ts +0 -23
  246. package/dist/types/client/parser/trigger-parser.d.ts +0 -13
  247. package/dist/types/client/parser/value-lang.d.ts +0 -63
  248. package/dist/types/client/time/instant.d.ts +0 -1
  249. package/dist/types/shared/calc/coerce.d.ts +0 -1
  250. package/dist/types/shared/calc/errors.d.ts +0 -14
  251. package/dist/types/shared/calc/evaluator.d.ts +0 -2
  252. package/dist/types/shared/calc/index.d.ts +0 -6
  253. package/dist/types/shared/calc/lexer.d.ts +0 -19
  254. package/dist/types/shared/calc/parser.d.ts +0 -43
  255. package/dist/types/shared/calc/typer.d.ts +0 -11
  256. package/dist/types/shared/date-parts.d.ts +0 -1
  257. package/dist/types/shared/show-when.d.ts +0 -21
  258. package/dist/types/shared/types/step.types.d.ts +0 -76
  259. package/dist/types/shared/types/trigger.types.d.ts +0 -12
@@ -0,0 +1,328 @@
1
+ // 展示对象的能力上下文(SomaViewContext):展示对象是应用对象,属于最上层——
2
+ // 可以调业务对象、改下层对象(表单草稿、候选项来源、数据取数)、在下层注册事件;其成员值对页面只读(页面只做纯路径读取)。
3
+ //
4
+ // 本文件是方言中性的能力面:kit / ui 的 defineXxxView 都是 defineSomaView 的薄封装,各自只在 ctx 上加自己的具名糖
5
+ // (kit 的 ctx.form(对象)、ctx.action(名字) 等)。能力全部复用 core 现有端口:
6
+ // · 具名动作 / 内置写入动作 → 引擎的 namedActions(browserMount.actions 登记)
7
+ // · 数据对象 → 数据解析器(读 / 重取 / 到达通知)
8
+ // · 组件 → 组件管理器:公开方法(ctrl.handle)与契约 emit 的旁路订阅(不要求页面声明订阅)
9
+ // · 写入结果(请求完成) → 数据端口的写入结果存储
10
+ // · 计时 → 本文件托管(随卸载自动清理,毫秒数由作者在代码里写)
11
+ // 所有订阅与计时都登记在 ctx 上,页面卸载(onUnmount)时一并撤销,作者不用手写清理。
12
+
13
+ import { SomaError } from '../../shared/soma-error';
14
+ import type { SomaWriteOutcomeView } from '../../shared/types/write-outcome-view.types';
15
+ import type { SomaDataReadState, SomaDataReadStatus } from '../../shared/types/data-config.types';
16
+
17
+ export class SomaViewContextError extends SomaError {
18
+ readonly code = 'CORE-VIEW-CTX';
19
+ constructor(message: string) {
20
+ super(`[CORE-VIEW-CTX] ${message}`);
21
+ this.name = 'SomaViewContextError';
22
+ }
23
+ }
24
+
25
+ /** 请求面(页面 http 服务的最小形状):绝对路径 `/api/...` 与 baseURL 重叠时已去重 */
26
+ export interface SomaViewHttp {
27
+ get<T = unknown>(url: string, config?: { params?: Record<string, string> }): Promise<T>;
28
+ post<T = unknown>(url: string, body?: unknown): Promise<T>;
29
+ put<T = unknown>(url: string, body?: unknown): Promise<T>;
30
+ patch<T = unknown>(url: string, body?: unknown): Promise<T>;
31
+ delete<T = unknown>(url: string): Promise<T>;
32
+ }
33
+
34
+ /**
35
+ * 引擎侧的宿主面(SomaBootstrap 在创建页面根时以非枚举属性 `_viewHost` 注入)。
36
+ * 展示对象不直接碰它,只经 {@link SomaViewContext};单测可以手工给一个替身。
37
+ */
38
+ export interface SomaViewHost {
39
+ readonly http: SomaViewHttp;
40
+ /** 调具名动作(browserMount.actions 登记的,或内置 data.submit / data.orderMove);未登记 reject */
41
+ action(name: string, payload: Record<string, unknown>): Promise<unknown>;
42
+ /** 数据对象当前值 */
43
+ readData(name: string): unknown;
44
+ /** 数据对象当前完整读状态(可选) */
45
+ readDataStatus?(name: string): SomaDataReadStatus | undefined;
46
+ /** 重取数据对象(缺省 = 全部);依赖它的下游随 DAG 一起重取 */
47
+ reloadData(names?: readonly string[]): Promise<void>;
48
+ /** 数据到达(首轮取数、重取、推送刷新、轮询)后通知 */
49
+ onData(listener: () => void): () => void;
50
+ /** 组件是否已挂载(按页面 data-soma-id 或组件内静态子组件 id) */
51
+ componentMounted(id: string): boolean;
52
+ /** 组件当前 props(页面求值后的);未挂载 undefined */
53
+ componentProps(id: string): Readonly<Record<string, unknown>> | undefined;
54
+ /** 调组件控制器公开的方法(ctrl.handle[method]);组件未挂载 → found: false;挂载了却没公开该方法 → missing */
55
+ componentCall(id: string, method: string, args: readonly unknown[]): { readonly found: boolean; readonly missing?: true; readonly result?: unknown };
56
+ /** 旁路订阅组件契约 emit(不要求页面 `_event` 声明订阅;组件重新挂载后仍有效) */
57
+ onComponentEmit(id: string, emit: string, listener: (payload: unknown) => void): () => void;
58
+ /** 写入结果(请求 / 提交的结果槽)的当前视图 */
59
+ outcome(scope: string): SomaWriteOutcomeView | undefined;
60
+ /** 写入结果变化通知(所有范围;按范围过滤由 ctx 做) */
61
+ onOutcome(listener: (scope: string) => void): () => void;
62
+ /** 向区域作用域发语义事件(与 `SCOPE | semantic` 管道同一条通道);作用域未声明空操作 */
63
+ emitSemantic(scope: string, name: string, payload: Readonly<Record<string, unknown>>): void;
64
+ }
65
+
66
+ /** 组件句柄:稳定壳,组件未挂载 / 重新挂载都不失效 */
67
+ export interface SomaViewComponentHandle {
68
+ readonly id: string;
69
+ /** 组件此刻是否挂载 */
70
+ mounted(): boolean;
71
+ /** 组件当前 props(只读快照);未挂载 undefined */
72
+ props(): Readonly<Record<string, unknown>> | undefined;
73
+ /**
74
+ * 调组件控制器公开的方法(组件在控制器上以 `handle: { 方法 }` 公开,写下层对象就走它)。
75
+ * 组件未挂载返回 undefined(不抛);挂载了但没公开该方法抛 CORE-VIEW-CTX(拼写错误不静默)。
76
+ */
77
+ call<T = unknown>(method: string, ...args: unknown[]): T | undefined;
78
+ /** 订阅组件抛出的契约事件;返回取消订阅。页面是否订阅该 emit 不影响;ctx 卸载时自动取消 */
79
+ on<P = unknown>(emit: string, listener: (payload: P) => void): () => void;
80
+ }
81
+
82
+ /** 数据对象句柄 */
83
+ export interface SomaViewDataHandle<T = unknown> {
84
+ readonly name: string;
85
+ /** 当前值(数据未到 undefined) */
86
+ get(): T | undefined;
87
+ /** 当前完整读状态(idle / loading / ready / error / forbidden / partial) */
88
+ status(): SomaDataReadStatus;
89
+ readonly readState: SomaDataReadState;
90
+ readonly loading: boolean;
91
+ readonly ready: boolean;
92
+ readonly errorMessage: string | undefined;
93
+ readonly errorStatus: number | undefined;
94
+ /** 重取这个对象(下游随 DAG 重取) */
95
+ reload(): Promise<void>;
96
+ /** 重试读取(等价于 reload) */
97
+ retry(): Promise<void>;
98
+ /** 数据到达 / 重取完成后通知(回调拿到最新值);返回取消订阅 */
99
+ onChange(listener: (value: T | undefined) => void): () => void;
100
+ }
101
+
102
+ /** 只认最新一次的异步任务:新任务开始后,旧任务的结果被丢弃(不 apply、不 fail) */
103
+ export interface SomaViewLatest {
104
+ run<T>(task: () => Promise<T>, apply: (value: T) => void, fail?: (error: unknown) => void): Promise<void>;
105
+ /** 丢弃在途任务的结果 */
106
+ cancel(): void;
107
+ }
108
+
109
+ export interface SomaViewDebounced<A extends unknown[]> {
110
+ (...args: A): void;
111
+ cancel(): void;
112
+ }
113
+
114
+ export interface SomaViewContext {
115
+ /** 页面还在(卸载后恒为 false;异步回调里可据此自查) */
116
+ readonly alive: boolean;
117
+ /** 业务对象:请求已登记接口(绝对路径 `/api/...`),返回 Promise */
118
+ readonly http: SomaViewHttp;
119
+ /** 业务对象:调具名动作(kit defineKitActions 登记的名字),返回动作结果;动作抛错 / 未登记 → reject */
120
+ action(name: string, payload?: Record<string, unknown>): Promise<unknown>;
121
+ /** 数据对象(读、重取、到达通知) */
122
+ data<T = unknown>(name: string): SomaViewDataHandle<T>;
123
+ /** 重取数据对象(缺省 = 全部) */
124
+ reload(names?: readonly string[]): Promise<void>;
125
+ /** 组件句柄(按页面 data-soma-id):调公开方法(写下层)、订阅事件(在下层注册事件) */
126
+ component(id: string): SomaViewComponentHandle;
127
+ /** 请求 / 提交结果槽的当前视图 */
128
+ outcome(scope: string): SomaWriteOutcomeView | undefined;
129
+ /** 触发下层的语义事件(页面级宿主 / 协调组件订阅的那一条通道,如触发一个声明式请求动作);作用域未声明空操作 */
130
+ emitSemantic(scope: string, name: string, payload?: Readonly<Record<string, unknown>>): void;
131
+ /**
132
+ * 请求完成回调:范围(字符串 = 精确;函数 = 自定判定,用于逐行分槽的结果)的写入结果变化时调用,
133
+ * 参数是该范围最新视图(status: pending / saved / failed / conflict / cancelled)与范围名。返回取消订阅。
134
+ */
135
+ onOutcome(scope: string | ((scope: string) => boolean), listener: (view: SomaWriteOutcomeView, scope: string) => void): () => void;
136
+ /** 托管定时器:每 ms 毫秒调一次 fn;毫秒数由作者在代码里写;返回停止函数,卸载自动清理 */
137
+ every(ms: number, fn: () => void | Promise<void>): () => void;
138
+ /** 托管一次性定时器;返回取消函数,卸载自动清理 */
139
+ after(ms: number, fn: () => void | Promise<void>): () => void;
140
+ /** 托管防抖:停 ms 毫秒后才调 fn;卸载自动取消 */
141
+ debounce<A extends unknown[]>(ms: number, fn: (...args: A) => void | Promise<void>): SomaViewDebounced<A>;
142
+ /** 新建一个「只认最新」的异步闸(丢弃旧结果) */
143
+ latest(): SomaViewLatest;
144
+ /** 登记卸载时的清理函数 */
145
+ onDispose(fn: () => void): void;
146
+ }
147
+
148
+ export interface SomaViewContextHandle {
149
+ readonly ctx: SomaViewContext;
150
+ /** 卸载:撤销全部订阅与计时(幂等) */
151
+ dispose(): void;
152
+ }
153
+
154
+ function report(where: string, error: unknown): void {
155
+ console.error(`[soma-core][展示对象] ${where} 抛错:`, error);
156
+ }
157
+
158
+ /** 造一个展示对象的 ctx;`host` 在用到时才取(引擎先造页面根、后注入宿主面) */
159
+ export function createViewContext(getHost: () => SomaViewHost | undefined): SomaViewContextHandle {
160
+ let alive = true;
161
+ const disposers = new Set<() => void>();
162
+
163
+ const host = (what: string): SomaViewHost => {
164
+ const h = getHost();
165
+ if (h === undefined) {
166
+ throw new SomaViewContextError(`${what} 需要页面宿主(页面根尚未由引擎挂载,或在纯 Node 单测里没有提供宿主面)`);
167
+ }
168
+ return h;
169
+ };
170
+ const track = (off: () => void): (() => void) => {
171
+ let done = false;
172
+ const wrapped = (): void => {
173
+ if (done) return;
174
+ done = true;
175
+ disposers.delete(wrapped);
176
+ off();
177
+ };
178
+ if (alive) disposers.add(wrapped);
179
+ else queueMicrotask(wrapped);
180
+ return wrapped;
181
+ };
182
+ const guard = (where: string, fn: () => void | Promise<void>): void => {
183
+ if (!alive) return;
184
+ try {
185
+ const r = fn();
186
+ if (r !== undefined && typeof (r as Promise<void>).then === 'function') {
187
+ (r as Promise<void>).catch((e: unknown) => report(where, e));
188
+ }
189
+ } catch (e) {
190
+ report(where, e);
191
+ }
192
+ };
193
+ const positive = (ms: number, what: string): void => {
194
+ if (typeof ms !== 'number' || !Number.isFinite(ms) || ms < 0) throw new SomaViewContextError(`${what} 的毫秒数应是非负有限数,收到 ${String(ms)}`);
195
+ };
196
+
197
+ const httpProxy: SomaViewHttp = {
198
+ get: (url, config) => host('ctx.http').http.get(url, config),
199
+ post: (url, body) => host('ctx.http').http.post(url, body),
200
+ put: (url, body) => host('ctx.http').http.put(url, body),
201
+ patch: (url, body) => host('ctx.http').http.patch(url, body),
202
+ delete: (url) => host('ctx.http').http.delete(url),
203
+ };
204
+
205
+ const ctx: SomaViewContext = {
206
+ get alive() { return alive; },
207
+ http: httpProxy,
208
+ action: (name, payload) => host('ctx.action').action(name, payload ?? {}),
209
+ data: <T>(name: string): SomaViewDataHandle<T> => {
210
+ const readStatus = (): SomaDataReadStatus => {
211
+ const h = host('ctx.data');
212
+ const direct = h.readDataStatus?.(name);
213
+ if (direct !== undefined) return direct;
214
+ const val = h.readData(name) as Record<string, unknown> | undefined;
215
+ if (val !== null && typeof val === 'object' && typeof val.readState === 'string') {
216
+ return {
217
+ readState: val.readState as SomaDataReadState,
218
+ loading: val.loading === true,
219
+ ready: val.ready === true,
220
+ ...(typeof val.errorMessage === 'string' ? { errorMessage: val.errorMessage } : {}),
221
+ ...(typeof val.errorStatus === 'number' ? { errorStatus: val.errorStatus } : {}),
222
+ retry: () => h.reloadData([name]),
223
+ };
224
+ }
225
+ const ready = val !== undefined;
226
+ return {
227
+ readState: ready ? 'ready' : 'idle',
228
+ loading: false,
229
+ ready,
230
+ retry: () => h.reloadData([name]),
231
+ };
232
+ };
233
+ return {
234
+ name,
235
+ get: () => host('ctx.data').readData(name) as T | undefined,
236
+ status: readStatus,
237
+ get readState() { return readStatus().readState; },
238
+ get loading() { return readStatus().loading; },
239
+ get ready() { return readStatus().ready; },
240
+ get errorMessage() { return readStatus().errorMessage; },
241
+ get errorStatus() { return readStatus().errorStatus; },
242
+ reload: () => host('ctx.data').reloadData([name]),
243
+ retry: () => host('ctx.data').reloadData([name]),
244
+ onChange: (listener) => track(host('ctx.data').onData(() => guard(`data(${name}).onChange`, () => listener(host('ctx.data').readData(name) as T | undefined)))),
245
+ };
246
+ },
247
+ reload: (names) => host('ctx.reload').reloadData(names),
248
+ component: (id) => ({
249
+ id,
250
+ mounted: () => host('ctx.component').componentMounted(id),
251
+ props: () => host('ctx.component').componentProps(id),
252
+ call: <T>(method: string, ...args: unknown[]): T | undefined => {
253
+ const r = host('ctx.component').componentCall(id, method, args);
254
+ if (r.missing === true) throw new SomaViewContextError(`组件 ${id} 没有公开方法 ${method}(组件在控制器上以 handle 公开可被展示对象调用的方法)`);
255
+ return r.found ? (r.result as T) : undefined;
256
+ },
257
+ on: <P>(emit: string, listener: (payload: P) => void) =>
258
+ track(host('ctx.component').onComponentEmit(id, emit, (payload) => guard(`component(${id}).on(${emit})`, () => listener(payload as P)))),
259
+ }),
260
+ outcome: (scope) => host('ctx.outcome').outcome(scope),
261
+ emitSemantic: (scope, name, payload) => host('ctx.emitSemantic').emitSemantic(scope, name, payload ?? {}),
262
+ onOutcome: (scope, listener) => {
263
+ const match = typeof scope === 'function' ? scope : (s: string): boolean => s === scope;
264
+ return track(host('ctx.onOutcome').onOutcome((changed) => {
265
+ if (!match(changed)) return;
266
+ const view = host('ctx.onOutcome').outcome(changed);
267
+ if (view !== undefined) guard('onOutcome', () => listener(view, changed));
268
+ }));
269
+ },
270
+ every: (ms, fn) => {
271
+ positive(ms, 'ctx.every');
272
+ const handle = globalThis.setInterval(() => guard('every', fn), ms);
273
+ return track(() => globalThis.clearInterval(handle));
274
+ },
275
+ after: (ms, fn) => {
276
+ positive(ms, 'ctx.after');
277
+ const handle = globalThis.setTimeout(() => guard('after', fn), ms);
278
+ return track(() => globalThis.clearTimeout(handle));
279
+ },
280
+ debounce: <A extends unknown[]>(ms: number, fn: (...args: A) => void | Promise<void>): SomaViewDebounced<A> => {
281
+ positive(ms, 'ctx.debounce');
282
+ let handle: ReturnType<typeof globalThis.setTimeout> | undefined;
283
+ const cancel = (): void => {
284
+ if (handle !== undefined) { globalThis.clearTimeout(handle); handle = undefined; }
285
+ };
286
+ track(cancel);
287
+ const debounced = ((...args: A): void => {
288
+ cancel();
289
+ if (!alive) return;
290
+ handle = globalThis.setTimeout(() => { handle = undefined; guard('debounce', () => fn(...args)); }, ms);
291
+ }) as SomaViewDebounced<A>;
292
+ debounced.cancel = cancel;
293
+ return debounced;
294
+ },
295
+ latest: (): SomaViewLatest => {
296
+ let seq = 0;
297
+ track(() => { seq += 1; });
298
+ return {
299
+ run: async (task, apply, fail) => {
300
+ seq += 1;
301
+ const mine = seq;
302
+ try {
303
+ const value = await task();
304
+ if (alive && mine === seq) guard('latest.apply', () => apply(value));
305
+ } catch (error) {
306
+ if (!alive || mine !== seq) return;
307
+ if (fail !== undefined) guard('latest.fail', () => fail(error));
308
+ else report('latest', error);
309
+ }
310
+ },
311
+ cancel: () => { seq += 1; },
312
+ };
313
+ },
314
+ onDispose: (fn) => { track(fn); },
315
+ };
316
+
317
+ return {
318
+ ctx,
319
+ dispose: () => {
320
+ if (!alive) return;
321
+ alive = false;
322
+ for (const off of [...disposers]) {
323
+ try { off(); } catch (e) { report('dispose', e); }
324
+ }
325
+ disposers.clear();
326
+ },
327
+ };
328
+ }
@@ -1,7 +1,7 @@
1
1
  // 集合工厂适配器(S11-1):取 `@zag-js/listbox` 的 `collection` / `gridCollection` 导出(不新增包)。
2
2
  // 库名字面量只出现在本文件(G4 判据),经 `loadEngineModule` 动态加载,不进静态可达图。
3
3
  // 返回的是 Zag 的 ListCollection / GridCollection 原生实例,成员面以 Zag 为准(`items`、`at`、`find`、`getNextValue` 等);
4
- // core 不再包一层,lite 自写集合(`components/basic/collection.ts`)整体换成它。
4
+ // core 不再包一层。
5
5
 
6
6
  import { loadEngineModule } from '../engines/load';
7
7
 
@@ -23,7 +23,7 @@ export interface BehaviorCollectionFactory {
23
23
  grid<T>(options: GridCollectionFactoryOptions<T>): ZagGridCollectionLike<T>;
24
24
  }
25
25
 
26
- /** Zag `ListCollection`(@zag-js/collection 1.x)在 core 眼里的最小形状:只列 lite / ui 实际要读的成员 */
26
+ /** Zag `ListCollection`(@zag-js/collection 1.x)在 core 眼里的最小形状:只列 ui 实际要读的成员 */
27
27
  export interface ZagCollectionLike<T> {
28
28
  readonly items: T[];
29
29
  readonly size: number;
@@ -1,6 +1,5 @@
1
1
  import type { IContainerAdapter } from '../container/IContainerAdapter';
2
2
  import { SOMA_ROLE_ATTR } from '../../shared/hook-attributes';
3
- import type { SomaShowWhen, SomaShowWhenTest } from '../../shared/show-when';
4
3
  import type { SomaScopeResolver } from '../engine/scope-resolver';
5
4
  import type { BindingType } from '../../shared/types/engine.types';
6
5
  import type {
@@ -142,15 +141,13 @@ export class SomaManifestCompiler {
142
141
  });
143
142
  // 嵌套绑定同样支持整块显隐:再补一条 when 绑定(同一锚点,互不干扰)
144
143
  if (showValue.when !== undefined) {
145
- const { dataPath: whenPath, negate, whenTest } = this.compileWhen(showValue.when, input.resolver);
144
+ const whenPath = input.resolver.resolvePath(showValue.when);
146
145
  bindings.push({
147
146
  id: `${rawKey}:when:${bindings.length}`,
148
147
  somaId: rawKey,
149
148
  type: 'when',
150
149
  dataPath: whenPath,
151
150
  watchPaths: [whenPath],
152
- negate,
153
- ...(whenTest ? { whenTest } : {}),
154
151
  });
155
152
  }
156
153
  continue;
@@ -218,24 +215,21 @@ export class SomaManifestCompiler {
218
215
  }
219
216
 
220
217
  if (value.when) {
221
- const { dataPath, negate, whenTest } = this.compileWhen(value.when, input.resolver);
218
+ const dataPath = input.resolver.resolvePath(value.when);
222
219
  bindings.push({
223
220
  id: `${somaId}:when:${bindings.length}`,
224
221
  somaId,
225
222
  type: 'when',
226
223
  dataPath,
227
224
  watchPaths: [dataPath],
228
- negate,
229
- ...(whenTest ? { whenTest } : {}),
230
225
  });
231
226
  }
232
227
 
233
228
  if (value.class) {
234
229
  const classRules = Object.fromEntries(
235
230
  Object.entries(value.class).map(([className, path]) => {
236
- // 前导 ! 取反(与 when 同语义):规则里保留 ! 前缀,watchPaths 用裸路径
237
- const { dataPath, negate } = this.parseConditionalPath(path, input.resolver);
238
- return [className, negate ? `!${dataPath}` : dataPath];
231
+ // 类名 → 纯路径(页面不取反,解析器已拒 `!`)
232
+ return [className, input.resolver.resolvePath(path)];
239
233
  }),
240
234
  );
241
235
  bindings.push({
@@ -243,7 +237,7 @@ export class SomaManifestCompiler {
243
237
  somaId,
244
238
  type: 'class',
245
239
  dataPath: '',
246
- watchPaths: [...new Set(Object.values(classRules).map((p) => (p.startsWith('!') ? p.slice(1) : p)))],
240
+ watchPaths: [...new Set(Object.values(classRules))],
247
241
  classRules,
248
242
  });
249
243
  }
@@ -305,31 +299,6 @@ export class SomaManifestCompiler {
305
299
  };
306
300
  }
307
301
 
308
- /** `when` 两种写法:字符串(真值 / `!` 取反)或对象谓词(路径取 field,算子与值进 whenTest) */
309
- private compileWhen(
310
- when: SomaShowWhen,
311
- resolver: SomaScopeResolver,
312
- ): { dataPath: string; negate: boolean; whenTest?: SomaShowWhenTest } {
313
- if (typeof when === 'string') return this.parseConditionalPath(when, resolver);
314
- return {
315
- dataPath: resolver.resolvePath(when.field),
316
- negate: false,
317
- whenTest: { op: when.op, ...(when.value !== undefined ? { value: when.value } : {}) },
318
- };
319
- }
320
-
321
- private parseConditionalPath(
322
- path: string,
323
- resolver: SomaScopeResolver,
324
- ): { dataPath: string; negate: boolean } {
325
- const negate = path.startsWith('!');
326
- const rawPath = negate ? path.slice(1) : path;
327
- return {
328
- dataPath: resolver.resolvePath(rawPath),
329
- negate,
330
- };
331
- }
332
-
333
302
  private resolveBindingType(
334
303
  element: HTMLElement | null,
335
304
  attrName: string | null,
@@ -85,12 +85,13 @@ export interface SomaComponentStyleFeature {
85
85
  * `validation` 是校验服务(`ctx.services.validation.asyncCheck(name)` → 应用经 `browserMount.asyncChecks` 登记的异步字段检查器,未登记为 null)。
86
86
  * `identity` 是当前身份只读端口(`get(field)` / `userId()`,字段闭集 id / team)。
87
87
  * 与 `soma-design/spec/component-contract.json` 的 `enums.serviceName` 逐值对账(顺序一致)。
88
+ * `actions` 是具名动作调用端口(`ctx.services.actions.run(名字, 载荷)` → 应用经 `browserMount.actions` 登记的具名动作的结果;`has(名字)`;与页面 `ACTION | 名字` 是同一张表)。
88
89
  * `nav` 是导航目录只读端口(`ctx.services.nav` → `SomaNavPort`:`view()` / `entries()` / `groups()` / `activeOf()`;外壳类组件读它渲染菜单与高亮,目录随取页下发、按身份裁剪、不含角色值)。
89
90
  */
90
91
  export type SomaComponentServiceName =
91
92
  | 'http' | 'auth' | 'notify' | 'router' | 'i18n' | 'permission' | 'storage'
92
93
  | 'observation' | 'data' | 'region' | 'engines' | 'format' | 'nav' | 'validation'
93
- | 'identity' | 'navHistory' | 'shortcuts';
94
+ | 'identity' | 'navHistory' | 'shortcuts' | 'actions';
94
95
 
95
96
  export interface SomaComponentDefinition {
96
97
  /** 契约:core 只读 core 段(`SomaComponentContractCore`),其余段不透明、原样透传(KI-18) */