soma-core 1.0.1 → 1.0.3

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 (234) hide show
  1. package/app/SomaPageClient.tsx +364 -0
  2. package/app/api/[...path]/route.ts +9 -85
  3. package/app/api/page/route.ts +57 -35
  4. package/app/api/soma-manifest/route.ts +39 -0
  5. package/app/components/SomaHydrationShell.tsx +23 -0
  6. package/app/favicon.ico/route.ts +13 -0
  7. package/app/layout.tsx +2 -2
  8. package/app/loading.tsx +5 -0
  9. package/app/page.tsx +19 -128
  10. package/bin/soma-lsp.cjs +195 -0
  11. package/bin/soma-sync.cjs +3 -0
  12. package/bin/soma.cjs +13 -1
  13. package/core/api/IService.ts +6 -10
  14. package/core/api/load-host-service.ts +75 -0
  15. package/core/api/service-path.ts +39 -0
  16. package/core/base/SomaEntity.ts +3 -10
  17. package/core/base/SomaLocaleOnlyPageRoot.ts +3 -4
  18. package/core/base/SomaPageRootBase.ts +20 -3
  19. package/core/base/decorators/Event.ts +23 -0
  20. package/core/base/decorators/Locale.ts +35 -0
  21. package/core/base/decorators/Page.ts +16 -0
  22. package/core/base/decorators/Show.ts +20 -0
  23. package/core/base/decorators/ShowList.ts +34 -0
  24. package/core/base/decorators/index.ts +5 -0
  25. package/core/base/index.ts +2 -0
  26. package/core/base/runAsync.ts +32 -0
  27. package/core/compiler/full-manifest-builder.ts +33 -7
  28. package/core/compiler/host-config-sync.cjs +38 -0
  29. package/core/compiler/manifest-compiler.ts +3 -2
  30. package/core/compiler/page-base-resolver.ts +26 -0
  31. package/core/compiler/precompiled-manifest-loader.ts +34 -0
  32. package/core/compiler/rollup-plugin-soma.ts +45 -0
  33. package/core/compiler/rspack-plugin-soma.js +33 -0
  34. package/core/compiler/soma-manifest-webpack-plugin.js +188 -0
  35. package/core/compiler/soma-precompile.js +3513 -0
  36. package/core/compiler/soma-precompile.ts +52 -6
  37. package/core/compiler/soma-rspack-yaml-loader.js +22 -0
  38. package/core/compiler/soma-webpack-loader.js +7 -1
  39. package/core/compiler/vite-plugin-soma.ts +11 -1
  40. package/core/container/IContainerAdapter.ts +36 -0
  41. package/core/container/MiniProgramContainerAdapter.ts +190 -0
  42. package/core/container/ReactNativeContainerAdapter.ts +189 -0
  43. package/core/container/SomaContainerAdapter.ts +17 -6
  44. package/core/diagnostics/SomaDiagnostics.ts +1 -1
  45. package/core/diagnostics/SomaTelemetry.ts +100 -0
  46. package/core/diagnostics/telemetry-context.ts +15 -0
  47. package/core/engine/asset-resolver.ts +39 -4
  48. package/core/engine/dom-renderer.ts +169 -35
  49. package/core/engine/event-engine.ts +110 -41
  50. package/core/engine/on-change-engine.ts +71 -0
  51. package/core/engine/property-watcher.ts +117 -0
  52. package/core/engine/reactive-proxy.ts +11 -5
  53. package/core/engine/render-engine.ts +97 -11
  54. package/core/engine/runtime-builder.ts +88 -11
  55. package/core/engine/scope-resolver.ts +65 -9
  56. package/core/engine/soma-bootstrap.ts +448 -244
  57. package/core/engine/style-binder.ts +423 -0
  58. package/core/engine/theme-variables.ts +37 -0
  59. package/core/engine/timer-engine.ts +92 -0
  60. package/core/engine/trigger-engine.ts +55 -0
  61. package/core/host/app-config.stub.ts +2 -0
  62. package/core/host/locale.stub.ts +2 -0
  63. package/core/host/resolve-host-bootstrap.ts +28 -0
  64. package/core/host/soma-bootstrap-host.stub.ts +4 -0
  65. package/core/host/source-packages.ts +112 -0
  66. package/core/index.ts +33 -2
  67. package/core/infra/auth/TokenAuthService.ts +17 -3
  68. package/core/infra/http/IHttpClient.ts +11 -1
  69. package/core/infra/http/SomaHttpService.ts +89 -31
  70. package/core/infra/i18n/DefaultI18n.ts +6 -18
  71. package/core/infra/i18n/II18n.ts +2 -3
  72. package/core/infra/notify/DomNotifyService.ts +98 -0
  73. package/core/infra/notify/INotifyTheme.ts +22 -0
  74. package/core/infra/realtime/IRealtimeService.ts +23 -0
  75. package/core/infra/realtime/IRealtimeTransport.ts +9 -0
  76. package/core/infra/realtime/SomaRealtimeService.ts +95 -0
  77. package/core/infra/realtime/SseRealtimeTransport.ts +36 -0
  78. package/core/infra/realtime/WebSocketRealtimeTransport.ts +102 -0
  79. package/core/infra/router/router-path.ts +28 -0
  80. package/core/infra/storage/SessionStorageService.ts +59 -0
  81. package/core/lsp/cross-file-diagnostics.cjs +160 -0
  82. package/core/lsp/event-yaml-completion.cjs +106 -0
  83. package/core/lsp/extra-completion.cjs +64 -0
  84. package/core/lsp/lsp-navigation.cjs +191 -0
  85. package/core/lsp/ui-yaml-completion.cjs +170 -0
  86. package/core/manifest/manifest-contract.ts +12 -0
  87. package/core/middleware/createPermissionMiddleware.ts +37 -0
  88. package/core/parser/annotation-extractor.ts +113 -0
  89. package/core/parser/pipeline-parser.ts +344 -276
  90. package/core/parser/style-config-parser.ts +340 -0
  91. package/core/parser/timer-parser.ts +70 -0
  92. package/core/parser/trigger-parser.ts +90 -0
  93. package/core/parser/ui-config-parser.ts +73 -1
  94. package/core/quality/SomaQualityRegistry.ts +68 -0
  95. package/core/runtime/SomaRuntimeServices.ts +100 -0
  96. package/core/runtime/SomaSnapshotStore.ts +5 -3
  97. package/core/types/domain.types.ts +5 -2
  98. package/core/types/event.types.ts +82 -57
  99. package/core/types/manifest.types.ts +2 -0
  100. package/core/types/style-config.types.ts +76 -0
  101. package/core/types/timer.types.ts +23 -0
  102. package/core/types/trigger.types.ts +14 -0
  103. package/core/types/ui-config.types.ts +9 -0
  104. package/core/types/watcher.types.ts +29 -0
  105. package/dist/cli/soma.js +23 -23
  106. package/dist/core/index.cjs +9065 -0
  107. package/dist/diagnostics/telemetry.cjs +105 -0
  108. package/dist/preview-export.cjs +3401 -0
  109. package/dist/tsconfig.types.tsbuildinfo +1 -0
  110. package/dist/types/api/IService.d.ts +28 -0
  111. package/dist/types/api/load-host-service.d.ts +5 -0
  112. package/dist/types/api/service-path.d.ts +13 -0
  113. package/dist/types/base/SomaApi.d.ts +5 -0
  114. package/dist/types/base/SomaDict.d.ts +89 -0
  115. package/dist/types/base/SomaEntity.d.ts +15 -0
  116. package/dist/types/base/SomaHttpClient.d.ts +66 -0
  117. package/dist/types/base/SomaLocaleOnlyPageRoot.d.ts +3 -0
  118. package/dist/types/base/SomaPageRootBase.d.ts +49 -0
  119. package/dist/types/base/SomaValidator.d.ts +55 -0
  120. package/dist/types/base/decorators/Event.d.ts +10 -0
  121. package/dist/types/base/decorators/Locale.d.ts +9 -0
  122. package/dist/types/base/decorators/Page.d.ts +4 -0
  123. package/dist/types/base/decorators/Show.d.ts +7 -0
  124. package/dist/types/base/decorators/ShowList.d.ts +12 -0
  125. package/dist/types/base/decorators/index.d.ts +5 -0
  126. package/dist/types/base/index.d.ts +9 -0
  127. package/dist/types/base/runAsync.d.ts +12 -0
  128. package/dist/types/compiler/full-manifest-builder.d.ts +35 -0
  129. package/dist/types/compiler/manifest-compiler.d.ts +29 -0
  130. package/dist/types/compiler/page-base-resolver.d.ts +6 -0
  131. package/dist/types/compiler/precompiled-manifest-loader.d.ts +5 -0
  132. package/dist/types/compiler/rollup-plugin-soma.d.ts +14 -0
  133. package/dist/types/compiler/route-builder.d.ts +12 -0
  134. package/dist/types/compiler/soma-precompile.d.ts +40 -0
  135. package/dist/types/compiler/vite-plugin-soma.d.ts +34 -0
  136. package/dist/types/container/IContainerAdapter.d.ts +30 -0
  137. package/dist/types/container/MiniProgramContainerAdapter.d.ts +52 -0
  138. package/dist/types/container/ReactNativeContainerAdapter.d.ts +47 -0
  139. package/dist/types/container/SomaContainerAdapter.d.ts +30 -0
  140. package/dist/types/diagnostics/SomaDiagnostics.d.ts +64 -0
  141. package/dist/types/diagnostics/SomaTelemetry.d.ts +32 -0
  142. package/dist/types/diagnostics/telemetry-context.d.ts +4 -0
  143. package/dist/types/engine/asset-resolver.d.ts +17 -0
  144. package/dist/types/engine/dom-renderer.d.ts +41 -0
  145. package/dist/types/engine/event-engine.d.ts +64 -0
  146. package/dist/types/engine/lis.d.ts +10 -0
  147. package/dist/types/engine/on-change-engine.d.ts +16 -0
  148. package/dist/types/engine/property-watcher.d.ts +18 -0
  149. package/dist/types/engine/reactive-proxy.d.ts +58 -0
  150. package/dist/types/engine/render-engine.d.ts +73 -0
  151. package/dist/types/engine/runtime-builder.d.ts +58 -0
  152. package/dist/types/engine/scope-resolver.d.ts +90 -0
  153. package/dist/types/engine/soma-bootstrap.d.ts +112 -0
  154. package/dist/types/engine/style-binder.d.ts +81 -0
  155. package/dist/types/engine/theme-variables.d.ts +3 -0
  156. package/dist/types/engine/timer-engine.d.ts +19 -0
  157. package/dist/types/engine/trigger-engine.d.ts +16 -0
  158. package/dist/types/host/app-config.stub.d.ts +3 -0
  159. package/dist/types/host/locale.stub.d.ts +3 -0
  160. package/dist/types/host/resolve-host-bootstrap.d.ts +11 -0
  161. package/dist/types/host/soma-bootstrap-host.stub.d.ts +3 -0
  162. package/dist/types/host/source-packages.d.ts +8 -0
  163. package/dist/types/index.d.ts +35 -0
  164. package/dist/types/infra/auth/IAuthService.d.ts +12 -0
  165. package/dist/types/infra/auth/TokenAuthService.d.ts +26 -0
  166. package/dist/types/infra/cache/ICache.d.ts +12 -0
  167. package/dist/types/infra/cache/MemoryCache.d.ts +14 -0
  168. package/dist/types/infra/cache/ServerFileCache.d.ts +37 -0
  169. package/dist/types/infra/config/IConfig.d.ts +9 -0
  170. package/dist/types/infra/config/SomaConfig.d.ts +21 -0
  171. package/dist/types/infra/event-bus/IEventBus.d.ts +8 -0
  172. package/dist/types/infra/event-bus/SomaEventBus.d.ts +9 -0
  173. package/dist/types/infra/http/IHttpClient.d.ts +28 -0
  174. package/dist/types/infra/http/SomaHttpService.d.ts +27 -0
  175. package/dist/types/infra/i18n/DefaultI18n.d.ts +7 -0
  176. package/dist/types/infra/i18n/II18n.d.ts +6 -0
  177. package/dist/types/infra/logger/ConsoleLogger.d.ts +14 -0
  178. package/dist/types/infra/logger/ILogger.d.ts +17 -0
  179. package/dist/types/infra/notify/DefaultNotifyService.d.ts +16 -0
  180. package/dist/types/infra/notify/DomNotifyService.d.ts +16 -0
  181. package/dist/types/infra/notify/INotifyService.d.ts +12 -0
  182. package/dist/types/infra/notify/INotifyTheme.d.ts +12 -0
  183. package/dist/types/infra/permission/IPermission.d.ts +10 -0
  184. package/dist/types/infra/permission/SomaPermission.d.ts +19 -0
  185. package/dist/types/infra/realtime/IRealtimeService.d.ts +13 -0
  186. package/dist/types/infra/realtime/IRealtimeTransport.d.ts +8 -0
  187. package/dist/types/infra/realtime/SomaRealtimeService.d.ts +20 -0
  188. package/dist/types/infra/realtime/SseRealtimeTransport.d.ts +11 -0
  189. package/dist/types/infra/realtime/WebSocketRealtimeTransport.d.ts +30 -0
  190. package/dist/types/infra/router/IRouter.d.ts +16 -0
  191. package/dist/types/infra/router/SomaRouter.d.ts +18 -0
  192. package/dist/types/infra/router/router-path.d.ts +6 -0
  193. package/dist/types/infra/storage/IStorageService.d.ts +7 -0
  194. package/dist/types/infra/storage/MemoryStorageService.d.ts +15 -0
  195. package/dist/types/infra/storage/SessionStorageService.d.ts +14 -0
  196. package/dist/types/infra/timer/ITimer.d.ts +13 -0
  197. package/dist/types/infra/timer/SomaTimer.d.ts +21 -0
  198. package/dist/types/manifest/manifest-contract.d.ts +4 -0
  199. package/dist/types/middleware/SomaMiddlewareChain.d.ts +6 -0
  200. package/dist/types/middleware/createPermissionMiddleware.d.ts +14 -0
  201. package/dist/types/parser/annotation-extractor.d.ts +12 -0
  202. package/dist/types/parser/pipeline-parser.d.ts +62 -0
  203. package/dist/types/parser/style-config-parser.d.ts +20 -0
  204. package/dist/types/parser/timer-parser.d.ts +6 -0
  205. package/dist/types/parser/trigger-parser.d.ts +13 -0
  206. package/dist/types/parser/ui-config-parser.d.ts +34 -0
  207. package/dist/types/parser/yaml-loader.d.ts +21 -0
  208. package/dist/types/quality/SomaQualityRegistry.d.ts +31 -0
  209. package/dist/types/runtime/SomaRuntimeServices.d.ts +35 -0
  210. package/dist/types/runtime/SomaSnapshotStore.d.ts +13 -0
  211. package/dist/types/scheduler/SomaScheduler.d.ts +25 -0
  212. package/dist/types/types/domain.types.d.ts +82 -0
  213. package/dist/types/types/engine.types.d.ts +22 -0
  214. package/dist/types/types/event.types.d.ts +61 -0
  215. package/dist/types/types/keyboard.types.d.ts +4 -0
  216. package/dist/types/types/manifest.types.d.ts +29 -0
  217. package/dist/types/types/scheduler.types.d.ts +8 -0
  218. package/dist/types/types/style-config.types.d.ts +62 -0
  219. package/dist/types/types/timer.types.d.ts +19 -0
  220. package/dist/types/types/trigger.types.d.ts +12 -0
  221. package/dist/types/types/ui-config.types.d.ts +85 -0
  222. package/dist/types/types/watcher.types.d.ts +24 -0
  223. package/dist/types/validation/contract-validator.d.ts +40 -0
  224. package/editor/vscode/extension.js +39 -0
  225. package/editor/vscode/language-configuration.json +17 -0
  226. package/editor/vscode/package.json +98 -0
  227. package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +30 -0
  228. package/editor/vscode/syntaxes/soma-ui-yaml.tmLanguage.json +42 -0
  229. package/global.d.ts +22 -3
  230. package/next.config.js +73 -4
  231. package/package.json +58 -17
  232. package/tailwind.config.ts +36 -13
  233. package/tsconfig.json +6 -2
  234. package/core/router/RouteHandler.ts +0 -93
@@ -0,0 +1,100 @@
1
+ import { TokenAuthService } from '../infra/auth/TokenAuthService';
2
+ import { MemoryCache } from '../infra/cache/MemoryCache';
3
+ import { SomaConfig } from '../infra/config/SomaConfig';
4
+ import { SomaEventBus } from '../infra/event-bus/SomaEventBus';
5
+ import { SomaHttpService } from '../infra/http/SomaHttpService';
6
+ import { DefaultI18n } from '../infra/i18n/DefaultI18n';
7
+ import { ConsoleLogger } from '../infra/logger/ConsoleLogger';
8
+ import { DefaultNotifyService } from '../infra/notify/DefaultNotifyService';
9
+ import { DomNotifyService } from '../infra/notify/DomNotifyService';
10
+ import { isToastTheme } from '../infra/notify/INotifyTheme';
11
+ import { SomaPermission } from '../infra/permission/SomaPermission';
12
+ import { SomaRouter } from '../infra/router/SomaRouter';
13
+ import { MemoryStorageService } from '../infra/storage/MemoryStorageService';
14
+ import { SessionStorageService } from '../infra/storage/SessionStorageService';
15
+ import type { IStorageService } from '../infra/storage/IStorageService';
16
+ import { SomaTimer } from '../infra/timer/SomaTimer';
17
+ import { SomaRealtimeService } from '../infra/realtime/SomaRealtimeService';
18
+ import type { IRealtimeService } from '../infra/realtime/IRealtimeService';
19
+
20
+ /** Runtime infrastructure injected into domain instances by bootstrap */
21
+ export interface SomaRuntimeServices {
22
+ router: SomaRouter;
23
+ notify: DefaultNotifyService | DomNotifyService;
24
+ logger: ConsoleLogger;
25
+ http: SomaHttpService;
26
+ storage: IStorageService;
27
+ timer: SomaTimer;
28
+ eventBus: SomaEventBus;
29
+ cache: MemoryCache<unknown>;
30
+ config: SomaConfig;
31
+ auth: TokenAuthService;
32
+ permission: SomaPermission;
33
+ i18n: DefaultI18n;
34
+ realtime: IRealtimeService;
35
+ }
36
+
37
+ export function createDefaultRuntimeServices(options?: {
38
+ appConfig?: unknown;
39
+ locale?: Record<string, unknown>;
40
+ initialPath?: string;
41
+ }): SomaRuntimeServices {
42
+ const config = new SomaConfig();
43
+ if (options?.appConfig && typeof options.appConfig === 'object') {
44
+ config.load(options.appConfig as Record<string, unknown>);
45
+ }
46
+
47
+ const http = new SomaHttpService({
48
+ baseURL: String(config.get('apiBaseUrl') ?? '/api'),
49
+ timeout: Number(config.get('requestTimeout') ?? 30000),
50
+ });
51
+
52
+ const storage: IStorageService =
53
+ typeof sessionStorage !== 'undefined' ? new SessionStorageService() : new MemoryStorageService();
54
+ const toastTheme = config.get('notify.toast');
55
+ const notify = typeof document !== 'undefined'
56
+ ? (isToastTheme(toastTheme)
57
+ ? new DomNotifyService(toastTheme)
58
+ : new DefaultNotifyService())
59
+ : new DefaultNotifyService();
60
+
61
+ http.setErrorHandler((status, message) => {
62
+ const configured = config.get(`http.errors.${status}`) as string | undefined;
63
+ const text = configured ?? message;
64
+ if (!text) return;
65
+ const level = status === 422 ? 'warning' : 'error';
66
+ notify.toast({ level, message: text });
67
+ });
68
+
69
+ const i18n = new DefaultI18n();
70
+ if (options?.locale) {
71
+ i18n.loadContent(options.locale as Record<string, string>);
72
+ }
73
+
74
+ const auth = new TokenAuthService(
75
+ http,
76
+ storage,
77
+ String(config.get('auth.loginApi') ?? ''),
78
+ String(config.get('auth.refreshApi') ?? ''),
79
+ );
80
+
81
+ return {
82
+ router: new SomaRouter(options?.initialPath ?? '/'),
83
+ notify,
84
+ logger: new ConsoleLogger(),
85
+ http,
86
+ storage,
87
+ timer: new SomaTimer(),
88
+ eventBus: new SomaEventBus(),
89
+ cache: new MemoryCache({ maxSize: 100 }),
90
+ config,
91
+ auth,
92
+ permission: new SomaPermission(),
93
+ i18n,
94
+ realtime: new SomaRealtimeService({
95
+ sseBasePath: config.get<string>('realtime.sseBasePath'),
96
+ wsBaseUrl: config.get<string>('realtime.wsBaseUrl'),
97
+ tokenProvider: () => auth.getToken(),
98
+ }),
99
+ };
100
+ }
@@ -12,10 +12,11 @@ export class SomaSnapshotStore {
12
12
  this.maxEntries = maxEntries;
13
13
  }
14
14
 
15
- capture(root: object): number {
15
+ capture(root: object, options?: { exclude?: string[] }): number {
16
+ const exclude = new Set(options?.exclude ?? []);
16
17
  const snapshot: SomaSnapshot = {
17
18
  id: this.nextId++,
18
- state: this.cloneState(root),
19
+ state: this.cloneState(root, exclude),
19
20
  };
20
21
 
21
22
  this.snapshots.push(snapshot);
@@ -35,13 +36,14 @@ export class SomaSnapshotStore {
35
36
  this.applyState(root, snapshot.state);
36
37
  }
37
38
 
38
- private cloneState(source: unknown): Record<string, unknown> {
39
+ private cloneState(source: unknown, exclude: Set<string> = new Set()): Record<string, unknown> {
39
40
  if (typeof source !== 'object' || source === null) {
40
41
  return {};
41
42
  }
42
43
 
43
44
  const result: Record<string, unknown> = {};
44
45
  for (const key of Object.keys(source)) {
46
+ if (exclude.has(key)) continue;
45
47
  const value = (source as Record<string, unknown>)[key];
46
48
  if (typeof value === 'function') {
47
49
  continue;
@@ -6,10 +6,12 @@
6
6
  * 展示对象必须实现此接口,提供页面生命周期钩子
7
7
  */
8
8
  export interface SomaPageRoot {
9
- /** 国际化文本(引擎在 mount 时注入) */
9
+ /** Content strings from locale.yaml (injected by bootstrap) */
10
10
  _locale?: Record<string, unknown>;
11
11
  /** 应用配置(引擎在 mount 时注入) */
12
12
  _config?: unknown;
13
+ /** 运行时基础设施(引擎在 mount 时注入) */
14
+ _services?: import('../runtime/SomaRuntimeServices').SomaRuntimeServices;
13
15
  /** 页面初始化(引擎在渲染完成后调用) */
14
16
  onMount?(): void | Promise<void>;
15
17
  /** 页面销毁前(引擎在卸载时调用) */
@@ -18,7 +20,8 @@ export interface SomaPageRoot {
18
20
 
19
21
  /**
20
22
  * 应用配置接口
21
- * 外部配置通过引擎注入到 Class 的 _config 属性
23
+ * 外部配置通过引擎注入到 Class 的 _config 属性。
24
+ * 业务扩展字段(auth、realtime、notify 等)通过 SomaConfig.get() 读取,不在框架层强类型约束。
22
25
  */
23
26
  export interface SomaAppConfig {
24
27
  /** API 基础地址 */
@@ -1,57 +1,82 @@
1
- // 事件配置类型定义 — 对应模块 3
2
- // 定义 SOMA 框架中 _event.yaml 配置文件的 TypeScript 类型
3
-
4
- /**
5
- * 事件类型枚举
6
- * 定义 Pipeline DSL 支持的四种事件处理类型
7
- */
8
- export type EventType =
9
- | 'NAV_STATIC' // 静态页面跳转
10
- | 'NAV_ACTION' // 逻辑驱动跳转(先执行函数,成功后跳转)
11
- | 'UI_REFRESH' // 数据刷新(执行函数后触发 UI 重新渲染)
12
- | 'UI_INTERACT'; // UI 交互操作(显隐控制)
13
-
14
- /**
15
- * UI 交互动作枚举
16
- * 用于 UI_INTERACT 类型的动作指令
17
- */
18
- export type InteractAction = 'open' | 'close' | 'toggle';
19
-
20
- /**
21
- * 解析后的事件配置
22
- * Pipeline DSL 解析器将 YAML 中的事件声明解析为此结构
23
- */
24
- export interface ParsedEvent {
25
- /** 目标元素的 data-soma-id 值 */
26
- somaId: string;
27
-
28
- /** DOM 事件类型(click, input, change, keydown 等) */
29
- domEvent: string;
30
-
31
- /** Pipeline 类型 */
32
- type: EventType;
33
-
34
- /** 业务逻辑函数路径(如 "boardCard.funcName1"),null 表示不执行逻辑 */
35
- funcPath?: string | null;
36
-
37
- /** 目标页面 URL(NAV_STATIC / NAV_ACTION 使用) */
38
- targetUrl?: string;
39
-
40
- /** 操作目标的 data-soma-id(UI_INTERACT 使用),undefined 时默认 self */
41
- targetId?: string;
42
-
43
- /** UI 动作指令(UI_INTERACT 使用),默认 toggle */
44
- action?: InteractAction;
45
-
46
- /**
47
- * 键盘事件修饰符(如 "enter", "escape", "tab")
48
- * 仅用于 keydown/keyup 事件,引擎在触发时检查 event.key 是否匹配
49
- */
50
- keyModifier?: string;
51
- }
52
-
53
- /**
54
- * 事件配置原始结构
55
- * YAML 反序列化后的嵌套对象,叶节点为 Pipeline 表达式字符串
56
- */
57
- export type EventConfigRaw = Record<string, string | Record<string, any>>;
1
+ // 事件配置类型定义 — 对应模块 3
2
+ // 定义 SOMA 框架中 _event.yaml 配置文件的 TypeScript 类型
3
+
4
+ /**
5
+ * 事件类型枚举
6
+ * 定义 Pipeline DSL 支持的四种事件处理类型
7
+ */
8
+ export type EventType =
9
+ | 'NAV_STATIC' // 静态页面跳转
10
+ | 'NAV_ACTION' // 逻辑驱动跳转(先执行函数,成功后跳转)
11
+ | 'UI_REFRESH' // 数据刷新(执行函数后触发 UI 重新渲染)
12
+ | 'UI_INTERACT'; // UI 交互操作(显隐控制)
13
+
14
+ /**
15
+ * UI 交互动作枚举
16
+ * 用于 UI_INTERACT 类型的动作指令
17
+ */
18
+ export type InteractAction = 'open' | 'close' | 'toggle';
19
+
20
+ /**
21
+ * 解析后的事件配置
22
+ * Pipeline DSL 解析器将 YAML 中的事件声明解析为此结构
23
+ */
24
+ export interface ParsedEvent {
25
+ /** 目标元素的 data-soma-id 值 */
26
+ somaId: string;
27
+
28
+ /** DOM 事件类型(click, input, change, keydown 等) */
29
+ domEvent: string;
30
+
31
+ /** Pipeline 类型 */
32
+ type: EventType;
33
+
34
+ /** 业务逻辑函数路径(如 "boardCard.funcName1"),null 表示不执行逻辑 */
35
+ funcPath?: string | null;
36
+
37
+ /** 目标页面 URL(NAV_STATIC / NAV_ACTION 使用) */
38
+ targetUrl?: string;
39
+
40
+ /** 操作目标的 data-soma-id(UI_INTERACT 使用),undefined 时默认 self */
41
+ targetId?: string;
42
+
43
+ /** UI 动作指令(UI_INTERACT 使用),默认 toggle */
44
+ action?: InteractAction;
45
+
46
+ /**
47
+ * 键盘事件修饰符(如 "enter", "escape", "tab")
48
+ * 仅用于 keydown/keyup 事件,引擎在触发时检查 event.key 是否匹配
49
+ */
50
+ keyModifier?: string;
51
+
52
+ /**
53
+ * 执行前确认对话框文案(Pipeline 可选段 `confirm:消息`)
54
+ * 用户取消则中止事件,不调用业务方法
55
+ */
56
+ confirm?: string;
57
+
58
+ /**
59
+ * UI_REFRESH 显式全量渲染(Pipeline 可选段 `| force`)
60
+ */
61
+ refreshForce?: boolean;
62
+
63
+ /**
64
+ * 执行前权限码(Pipeline 可选段 `| permission:code`)
65
+ * 需宿主挂载 createPermissionMiddleware 后生效
66
+ */
67
+ permission?: string;
68
+ }
69
+
70
+ /**
71
+ * 事件 handler 返回值:仅表示业务成功/失败(流程是否继续)。
72
+ * - `true` / `undefined`:成功,继续 post-action(跳转、显隐等)
73
+ * - `false`:失败,中断 post-action
74
+ * 与 DOM 刷新/commit 无关(改字段后引擎自动 commit)。
75
+ */
76
+ export type EventHandlerResult = boolean | undefined;
77
+
78
+ /**
79
+ * 事件配置原始结构
80
+ * YAML 反序列化后的嵌套对象,叶节点为 Pipeline 表达式字符串
81
+ */
82
+ export type EventConfigRaw = Record<string, string | Record<string, any>>;
@@ -27,4 +27,6 @@ export interface SomaRuntimeManifest {
27
27
  bindingIndex: Map<string, SomaCompiledBinding[]>;
28
28
  events: SomaCompiledEvent[];
29
29
  eventIndex: Map<string, SomaCompiledEvent>;
30
+ /** 启动时一次性初始化的属性(来自 _ui.yaml initProps) */
31
+ initProps?: Record<string, unknown>;
30
32
  }
@@ -0,0 +1,76 @@
1
+ // 样式配置类型定义 — 对应 _style.yaml
2
+ // 定义 SOMA 框架中样式配置文件的 TypeScript 类型
3
+
4
+ /**
5
+ * 状态驱动的样式规则
6
+ * 当 condition 路径的值等于 value 时,将 apply 中的类名应用到对应 DOM 节点
7
+ */
8
+ export interface StyleStateRule {
9
+ /** 数据路径(纯属性路径,禁止逻辑表达式) */
10
+ condition: string;
11
+ /** 目标值(基础类型:string | number | boolean | null) */
12
+ value: string | number | boolean | null;
13
+ /** 匹配时应用的 Tailwind 类名 */
14
+ apply: string;
15
+ }
16
+
17
+ /**
18
+ * 过渡/动画触发器类型
19
+ */
20
+ export type TransitionTrigger =
21
+ | 'hover'
22
+ | 'focus'
23
+ | 'active'
24
+ | 'enter'
25
+ | 'leave'
26
+ | 'active_state';
27
+
28
+ /**
29
+ * 过渡/动画配置
30
+ */
31
+ export interface StyleTransition {
32
+ /** 触发方式 */
33
+ trigger: TransitionTrigger;
34
+ /** 应用的 Tailwind 动画/过渡类名 */
35
+ apply: string;
36
+ /** active_state 类型时的条件路径 */
37
+ condition?: string;
38
+ /** active_state 类型时的目标值 */
39
+ value?: string | number | boolean | null;
40
+ }
41
+
42
+ /**
43
+ * 主题内的状态覆盖
44
+ */
45
+ export interface ThemeStatesOverride {
46
+ [somaId: string]: StyleStateRule[];
47
+ }
48
+
49
+ /**
50
+ * 单个主题配置
51
+ */
52
+ export interface ThemeConfig {
53
+ /** 基础类名覆盖:somaId → Tailwind 类名 */
54
+ base: Record<string, string>;
55
+ /** 状态规则覆盖 */
56
+ states: ThemeStatesOverride;
57
+ /** 运行时 CSS 变量(ThemeMaster 注入 document) */
58
+ vars?: Record<string, string>;
59
+ }
60
+
61
+ /**
62
+ * 样式配置顶层结构
63
+ * 对应 _style.yaml 文件的完整结构
64
+ */
65
+ export interface StyleConfig {
66
+ /** 所属的业务对象标识(对应 data-soma-host) */
67
+ host: string;
68
+ /** 基础静态样式映射:somaId → Tailwind 类名 */
69
+ base: Record<string, string>;
70
+ /** 状态驱动样式:somaId → 规则数组 */
71
+ states: Record<string, StyleStateRule[]>;
72
+ /** 动态交互与动画:somaId → 过渡配置 */
73
+ transitions: Record<string, StyleTransition>;
74
+ /** 多主题覆盖配置 */
75
+ themes: Record<string, ThemeConfig>;
76
+ }
@@ -0,0 +1,23 @@
1
+ // 定时器事件 — 对应 _event.yaml 的 timers 块
2
+
3
+ import type { ParsedEvent } from './event.types';
4
+
5
+ /** 解析后的定时器配置 */
6
+ export interface ParsedTimer {
7
+ /** 唯一标识(用于日志与调试) */
8
+ id: string;
9
+ /** 周期间隔(毫秒),interval 模式必填 */
10
+ intervalMs: number;
11
+ /** 首次触发延迟(毫秒),默认 0 */
12
+ delayMs: number;
13
+ /** true 时仅触发一次(setTimeout),否则 setInterval */
14
+ once: boolean;
15
+ /** Pipeline 解析结果(不含 DOM 选择器) */
16
+ pipeline: Omit<ParsedEvent, 'somaId' | 'domEvent'>;
17
+ }
18
+
19
+ export interface SomaCompiledTimer extends ParsedTimer {
20
+ somaId: string;
21
+ domEvent: 'tick';
22
+ eventKey: string;
23
+ }
@@ -0,0 +1,14 @@
1
+ // 属性变化 DOM 事件触发器 — 对应 _event.yaml 的 triggers 块
2
+
3
+ export interface PropertyTrigger {
4
+ /** 监听的数据路径(含 var 别名,如 page.isLoading) */
5
+ condition: string;
6
+ /** 触发条件:属性值等于此值时执行 */
7
+ value: string | number | boolean | null;
8
+ /** 目标元素的 data-soma-id */
9
+ target: string;
10
+ /** 分发的 DOM 事件名(如 soma:show、click) */
11
+ event: string;
12
+ /** 自定义事件 detail 载荷 */
13
+ detail?: Record<string, unknown>;
14
+ }
@@ -1,6 +1,8 @@
1
1
  // UI 配置类型定义 — 对应模块 2
2
2
  // 定义 SOMA 框架中 _ui.yaml 配置文件的 TypeScript 类型
3
3
 
4
+ import type { OnChangeRule } from './watcher.types';
5
+
4
6
  /**
5
7
  * 作用域声明
6
8
  * 定义数据源路径和当前作用域别名
@@ -10,6 +12,8 @@ export interface BindDeclaration {
10
12
  obj: string;
11
13
  /** 当前层级别名,子层级和事件配置通过此别名引用数据 */
12
14
  var: string;
15
+ /** 属性变化时触发的 Domain 方法(声明式 watch) */
16
+ onChange?: OnChangeRule[];
13
17
  }
14
18
 
15
19
  /**
@@ -73,6 +77,11 @@ export interface UiConfig {
73
77
  bind: BindDeclaration;
74
78
  /** 顶级展示映射 */
75
79
  show: ShowMapping;
80
+ /**
81
+ * 初始化属性(引擎启动、Proxy 创建前写入)
82
+ * 键为 var 别名路径(如 page.title),值为初始值
83
+ */
84
+ initProps?: Record<string, unknown>;
76
85
  }
77
86
 
78
87
  /**
@@ -0,0 +1,29 @@
1
+ // 属性监听器类型 — RenderEngine.watch / onChange / triggers 共用
2
+
3
+ export type WatchCallback = (
4
+ newValue: unknown,
5
+ oldValue: unknown,
6
+ context: { path: string; root: object },
7
+ ) => void | Promise<void>;
8
+
9
+ export interface WatcherOptions {
10
+ /** 立即执行一次(读取当前值作为 newValue,oldValue 为 undefined) */
11
+ immediate?: boolean;
12
+ /** 前缀匹配:监听 path 及其所有子路径变更 */
13
+ prefix?: boolean;
14
+ /** 通配符匹配:path 中含 `*` 时启用(如 page.*.status) */
15
+ glob?: boolean;
16
+ /** 防抖延迟(ms) */
17
+ debounce?: number;
18
+ }
19
+
20
+ export interface OnChangeRule {
21
+ /** 监听的数据路径(含 var 别名) */
22
+ condition: string;
23
+ /** Domain Class 方法名(相对 bind.var,如 onDeviceSelected → page.onDeviceSelected) */
24
+ callback: string;
25
+ /** 回调执行后是否触发 UI 全量刷新 */
26
+ refresh?: boolean;
27
+ /** 防抖延迟(ms) */
28
+ debounce?: number;
29
+ }
package/dist/cli/soma.js CHANGED
@@ -8,42 +8,42 @@ const node_child_process_1 = require("node:child_process");
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const args = process.argv.slice(2);
10
10
  const command = args[0] || 'dev';
11
- const allowed = ['dev', 'build', 'start'];
12
- if (!allowed.includes(command)) {
13
- console.error(`Usage: soma <${allowed.join('|')}> [...next-args]`);
14
- process.exit(1);
15
- }
16
- /** 编译后为 dist/cli/soma.js → 向上两级回到包根(含 core/、package.json) */
17
- const packageRoot = node_path_1.default.resolve(__dirname, '..', '..');
11
+ const delegated = ['doctor', 'sync', 'lsp', 'codegen', 'init', 'package-vscode'];
12
+ const packageRoot = node_path_1.default.resolve(__dirname, '../..');
18
13
  function resolveNextBin() {
19
- try {
20
- return require.resolve('next/dist/bin/next', { paths: [packageRoot] });
21
- }
22
- catch {
14
+ const searchPaths = [packageRoot, node_path_1.default.join(packageRoot, '..'), node_path_1.default.join(packageRoot, '../..')];
15
+ for (const base of searchPaths) {
23
16
  try {
24
- return require.resolve('next/dist/bin/next', {
25
- paths: [node_path_1.default.join(packageRoot, '..')],
26
- });
17
+ return require.resolve('next/dist/bin/next', { paths: [base] });
27
18
  }
28
19
  catch {
29
- return null;
20
+ /* try next */
30
21
  }
31
22
  }
23
+ return null;
24
+ }
25
+ if (delegated.includes(command)) {
26
+ const inline = node_path_1.default.join(__dirname, 'soma-inline.cjs');
27
+ const child = (0, node_child_process_1.spawnSync)(process.execPath, [inline, command, ...args.slice(1)], {
28
+ cwd: packageRoot,
29
+ stdio: 'inherit',
30
+ env: process.env,
31
+ });
32
+ process.exit(child.status === null ? 1 : child.status);
33
+ }
34
+ if (!['dev', 'build', 'start'].includes(command)) {
35
+ console.error(`Usage: soma <dev|build|start|${delegated.join('|')}> [...args]`);
36
+ process.exit(1);
32
37
  }
33
38
  const nextBin = resolveNextBin();
34
39
  if (!nextBin) {
35
- console.error('[soma] 找不到 next,请在 soma-core 包内安装依赖。');
40
+ console.error('[soma] next not found. Install dependencies in the soma-core package.');
36
41
  process.exit(1);
37
42
  }
38
- /** 在业务应用根执行 CLI;子进程仅注入 SOMA_HOST_DIR */
39
43
  const hostDir = node_path_1.default.resolve(process.cwd());
40
- const nextArgs = [nextBin, command, ...args.slice(1)];
41
- const child = (0, node_child_process_1.spawnSync)(process.execPath, nextArgs, {
44
+ const child = (0, node_child_process_1.spawnSync)(process.execPath, [nextBin, command, ...args.slice(1)], {
42
45
  cwd: packageRoot,
43
46
  stdio: 'inherit',
44
- env: {
45
- ...process.env,
46
- SOMA_HOST_DIR: hostDir,
47
- },
47
+ env: { ...process.env, SOMA_HOST_DIR: hostDir },
48
48
  });
49
49
  process.exit(child.status === null ? 1 : child.status);