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.
- package/app/SomaPageClient.tsx +364 -0
- package/app/api/[...path]/route.ts +9 -85
- package/app/api/page/route.ts +57 -35
- package/app/api/soma-manifest/route.ts +39 -0
- package/app/components/SomaHydrationShell.tsx +23 -0
- package/app/favicon.ico/route.ts +13 -0
- package/app/layout.tsx +2 -2
- package/app/loading.tsx +5 -0
- package/app/page.tsx +19 -128
- package/bin/soma-lsp.cjs +195 -0
- package/bin/soma-sync.cjs +3 -0
- package/bin/soma.cjs +13 -1
- package/core/api/IService.ts +6 -10
- package/core/api/load-host-service.ts +75 -0
- package/core/api/service-path.ts +39 -0
- package/core/base/SomaEntity.ts +3 -10
- package/core/base/SomaLocaleOnlyPageRoot.ts +3 -4
- package/core/base/SomaPageRootBase.ts +20 -3
- package/core/base/decorators/Event.ts +23 -0
- package/core/base/decorators/Locale.ts +35 -0
- package/core/base/decorators/Page.ts +16 -0
- package/core/base/decorators/Show.ts +20 -0
- package/core/base/decorators/ShowList.ts +34 -0
- package/core/base/decorators/index.ts +5 -0
- package/core/base/index.ts +2 -0
- package/core/base/runAsync.ts +32 -0
- package/core/compiler/full-manifest-builder.ts +33 -7
- package/core/compiler/host-config-sync.cjs +38 -0
- package/core/compiler/manifest-compiler.ts +3 -2
- package/core/compiler/page-base-resolver.ts +26 -0
- package/core/compiler/precompiled-manifest-loader.ts +34 -0
- package/core/compiler/rollup-plugin-soma.ts +45 -0
- package/core/compiler/rspack-plugin-soma.js +33 -0
- package/core/compiler/soma-manifest-webpack-plugin.js +188 -0
- package/core/compiler/soma-precompile.js +3513 -0
- package/core/compiler/soma-precompile.ts +52 -6
- package/core/compiler/soma-rspack-yaml-loader.js +22 -0
- package/core/compiler/soma-webpack-loader.js +7 -1
- package/core/compiler/vite-plugin-soma.ts +11 -1
- package/core/container/IContainerAdapter.ts +36 -0
- package/core/container/MiniProgramContainerAdapter.ts +190 -0
- package/core/container/ReactNativeContainerAdapter.ts +189 -0
- package/core/container/SomaContainerAdapter.ts +17 -6
- package/core/diagnostics/SomaDiagnostics.ts +1 -1
- package/core/diagnostics/SomaTelemetry.ts +100 -0
- package/core/diagnostics/telemetry-context.ts +15 -0
- package/core/engine/asset-resolver.ts +39 -4
- package/core/engine/dom-renderer.ts +169 -35
- package/core/engine/event-engine.ts +110 -41
- package/core/engine/on-change-engine.ts +71 -0
- package/core/engine/property-watcher.ts +117 -0
- package/core/engine/reactive-proxy.ts +11 -5
- package/core/engine/render-engine.ts +97 -11
- package/core/engine/runtime-builder.ts +88 -11
- package/core/engine/scope-resolver.ts +65 -9
- package/core/engine/soma-bootstrap.ts +448 -244
- package/core/engine/style-binder.ts +423 -0
- package/core/engine/theme-variables.ts +37 -0
- package/core/engine/timer-engine.ts +92 -0
- package/core/engine/trigger-engine.ts +55 -0
- package/core/host/app-config.stub.ts +2 -0
- package/core/host/locale.stub.ts +2 -0
- package/core/host/resolve-host-bootstrap.ts +28 -0
- package/core/host/soma-bootstrap-host.stub.ts +4 -0
- package/core/host/source-packages.ts +112 -0
- package/core/index.ts +33 -2
- package/core/infra/auth/TokenAuthService.ts +17 -3
- package/core/infra/http/IHttpClient.ts +11 -1
- package/core/infra/http/SomaHttpService.ts +89 -31
- package/core/infra/i18n/DefaultI18n.ts +6 -18
- package/core/infra/i18n/II18n.ts +2 -3
- package/core/infra/notify/DomNotifyService.ts +98 -0
- package/core/infra/notify/INotifyTheme.ts +22 -0
- package/core/infra/realtime/IRealtimeService.ts +23 -0
- package/core/infra/realtime/IRealtimeTransport.ts +9 -0
- package/core/infra/realtime/SomaRealtimeService.ts +95 -0
- package/core/infra/realtime/SseRealtimeTransport.ts +36 -0
- package/core/infra/realtime/WebSocketRealtimeTransport.ts +102 -0
- package/core/infra/router/router-path.ts +28 -0
- package/core/infra/storage/SessionStorageService.ts +59 -0
- package/core/lsp/cross-file-diagnostics.cjs +160 -0
- package/core/lsp/event-yaml-completion.cjs +106 -0
- package/core/lsp/extra-completion.cjs +64 -0
- package/core/lsp/lsp-navigation.cjs +191 -0
- package/core/lsp/ui-yaml-completion.cjs +170 -0
- package/core/manifest/manifest-contract.ts +12 -0
- package/core/middleware/createPermissionMiddleware.ts +37 -0
- package/core/parser/annotation-extractor.ts +113 -0
- package/core/parser/pipeline-parser.ts +344 -276
- package/core/parser/style-config-parser.ts +340 -0
- package/core/parser/timer-parser.ts +70 -0
- package/core/parser/trigger-parser.ts +90 -0
- package/core/parser/ui-config-parser.ts +73 -1
- package/core/quality/SomaQualityRegistry.ts +68 -0
- package/core/runtime/SomaRuntimeServices.ts +100 -0
- package/core/runtime/SomaSnapshotStore.ts +5 -3
- package/core/types/domain.types.ts +5 -2
- package/core/types/event.types.ts +82 -57
- package/core/types/manifest.types.ts +2 -0
- package/core/types/style-config.types.ts +76 -0
- package/core/types/timer.types.ts +23 -0
- package/core/types/trigger.types.ts +14 -0
- package/core/types/ui-config.types.ts +9 -0
- package/core/types/watcher.types.ts +29 -0
- package/dist/cli/soma.js +23 -23
- package/dist/core/index.cjs +9065 -0
- package/dist/diagnostics/telemetry.cjs +105 -0
- package/dist/preview-export.cjs +3401 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/api/IService.d.ts +28 -0
- package/dist/types/api/load-host-service.d.ts +5 -0
- package/dist/types/api/service-path.d.ts +13 -0
- package/dist/types/base/SomaApi.d.ts +5 -0
- package/dist/types/base/SomaDict.d.ts +89 -0
- package/dist/types/base/SomaEntity.d.ts +15 -0
- package/dist/types/base/SomaHttpClient.d.ts +66 -0
- package/dist/types/base/SomaLocaleOnlyPageRoot.d.ts +3 -0
- package/dist/types/base/SomaPageRootBase.d.ts +49 -0
- package/dist/types/base/SomaValidator.d.ts +55 -0
- package/dist/types/base/decorators/Event.d.ts +10 -0
- package/dist/types/base/decorators/Locale.d.ts +9 -0
- package/dist/types/base/decorators/Page.d.ts +4 -0
- package/dist/types/base/decorators/Show.d.ts +7 -0
- package/dist/types/base/decorators/ShowList.d.ts +12 -0
- package/dist/types/base/decorators/index.d.ts +5 -0
- package/dist/types/base/index.d.ts +9 -0
- package/dist/types/base/runAsync.d.ts +12 -0
- package/dist/types/compiler/full-manifest-builder.d.ts +35 -0
- package/dist/types/compiler/manifest-compiler.d.ts +29 -0
- package/dist/types/compiler/page-base-resolver.d.ts +6 -0
- package/dist/types/compiler/precompiled-manifest-loader.d.ts +5 -0
- package/dist/types/compiler/rollup-plugin-soma.d.ts +14 -0
- package/dist/types/compiler/route-builder.d.ts +12 -0
- package/dist/types/compiler/soma-precompile.d.ts +40 -0
- package/dist/types/compiler/vite-plugin-soma.d.ts +34 -0
- package/dist/types/container/IContainerAdapter.d.ts +30 -0
- package/dist/types/container/MiniProgramContainerAdapter.d.ts +52 -0
- package/dist/types/container/ReactNativeContainerAdapter.d.ts +47 -0
- package/dist/types/container/SomaContainerAdapter.d.ts +30 -0
- package/dist/types/diagnostics/SomaDiagnostics.d.ts +64 -0
- package/dist/types/diagnostics/SomaTelemetry.d.ts +32 -0
- package/dist/types/diagnostics/telemetry-context.d.ts +4 -0
- package/dist/types/engine/asset-resolver.d.ts +17 -0
- package/dist/types/engine/dom-renderer.d.ts +41 -0
- package/dist/types/engine/event-engine.d.ts +64 -0
- package/dist/types/engine/lis.d.ts +10 -0
- package/dist/types/engine/on-change-engine.d.ts +16 -0
- package/dist/types/engine/property-watcher.d.ts +18 -0
- package/dist/types/engine/reactive-proxy.d.ts +58 -0
- package/dist/types/engine/render-engine.d.ts +73 -0
- package/dist/types/engine/runtime-builder.d.ts +58 -0
- package/dist/types/engine/scope-resolver.d.ts +90 -0
- package/dist/types/engine/soma-bootstrap.d.ts +112 -0
- package/dist/types/engine/style-binder.d.ts +81 -0
- package/dist/types/engine/theme-variables.d.ts +3 -0
- package/dist/types/engine/timer-engine.d.ts +19 -0
- package/dist/types/engine/trigger-engine.d.ts +16 -0
- package/dist/types/host/app-config.stub.d.ts +3 -0
- package/dist/types/host/locale.stub.d.ts +3 -0
- package/dist/types/host/resolve-host-bootstrap.d.ts +11 -0
- package/dist/types/host/soma-bootstrap-host.stub.d.ts +3 -0
- package/dist/types/host/source-packages.d.ts +8 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/infra/auth/IAuthService.d.ts +12 -0
- package/dist/types/infra/auth/TokenAuthService.d.ts +26 -0
- package/dist/types/infra/cache/ICache.d.ts +12 -0
- package/dist/types/infra/cache/MemoryCache.d.ts +14 -0
- package/dist/types/infra/cache/ServerFileCache.d.ts +37 -0
- package/dist/types/infra/config/IConfig.d.ts +9 -0
- package/dist/types/infra/config/SomaConfig.d.ts +21 -0
- package/dist/types/infra/event-bus/IEventBus.d.ts +8 -0
- package/dist/types/infra/event-bus/SomaEventBus.d.ts +9 -0
- package/dist/types/infra/http/IHttpClient.d.ts +28 -0
- package/dist/types/infra/http/SomaHttpService.d.ts +27 -0
- package/dist/types/infra/i18n/DefaultI18n.d.ts +7 -0
- package/dist/types/infra/i18n/II18n.d.ts +6 -0
- package/dist/types/infra/logger/ConsoleLogger.d.ts +14 -0
- package/dist/types/infra/logger/ILogger.d.ts +17 -0
- package/dist/types/infra/notify/DefaultNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/DomNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/INotifyService.d.ts +12 -0
- package/dist/types/infra/notify/INotifyTheme.d.ts +12 -0
- package/dist/types/infra/permission/IPermission.d.ts +10 -0
- package/dist/types/infra/permission/SomaPermission.d.ts +19 -0
- package/dist/types/infra/realtime/IRealtimeService.d.ts +13 -0
- package/dist/types/infra/realtime/IRealtimeTransport.d.ts +8 -0
- package/dist/types/infra/realtime/SomaRealtimeService.d.ts +20 -0
- package/dist/types/infra/realtime/SseRealtimeTransport.d.ts +11 -0
- package/dist/types/infra/realtime/WebSocketRealtimeTransport.d.ts +30 -0
- package/dist/types/infra/router/IRouter.d.ts +16 -0
- package/dist/types/infra/router/SomaRouter.d.ts +18 -0
- package/dist/types/infra/router/router-path.d.ts +6 -0
- package/dist/types/infra/storage/IStorageService.d.ts +7 -0
- package/dist/types/infra/storage/MemoryStorageService.d.ts +15 -0
- package/dist/types/infra/storage/SessionStorageService.d.ts +14 -0
- package/dist/types/infra/timer/ITimer.d.ts +13 -0
- package/dist/types/infra/timer/SomaTimer.d.ts +21 -0
- package/dist/types/manifest/manifest-contract.d.ts +4 -0
- package/dist/types/middleware/SomaMiddlewareChain.d.ts +6 -0
- package/dist/types/middleware/createPermissionMiddleware.d.ts +14 -0
- package/dist/types/parser/annotation-extractor.d.ts +12 -0
- package/dist/types/parser/pipeline-parser.d.ts +62 -0
- package/dist/types/parser/style-config-parser.d.ts +20 -0
- package/dist/types/parser/timer-parser.d.ts +6 -0
- package/dist/types/parser/trigger-parser.d.ts +13 -0
- package/dist/types/parser/ui-config-parser.d.ts +34 -0
- package/dist/types/parser/yaml-loader.d.ts +21 -0
- package/dist/types/quality/SomaQualityRegistry.d.ts +31 -0
- package/dist/types/runtime/SomaRuntimeServices.d.ts +35 -0
- package/dist/types/runtime/SomaSnapshotStore.d.ts +13 -0
- package/dist/types/scheduler/SomaScheduler.d.ts +25 -0
- package/dist/types/types/domain.types.d.ts +82 -0
- package/dist/types/types/engine.types.d.ts +22 -0
- package/dist/types/types/event.types.d.ts +61 -0
- package/dist/types/types/keyboard.types.d.ts +4 -0
- package/dist/types/types/manifest.types.d.ts +29 -0
- package/dist/types/types/scheduler.types.d.ts +8 -0
- package/dist/types/types/style-config.types.d.ts +62 -0
- package/dist/types/types/timer.types.d.ts +19 -0
- package/dist/types/types/trigger.types.d.ts +12 -0
- package/dist/types/types/ui-config.types.d.ts +85 -0
- package/dist/types/types/watcher.types.d.ts +24 -0
- package/dist/types/validation/contract-validator.d.ts +40 -0
- package/editor/vscode/extension.js +39 -0
- package/editor/vscode/language-configuration.json +17 -0
- package/editor/vscode/package.json +98 -0
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +30 -0
- package/editor/vscode/syntaxes/soma-ui-yaml.tmLanguage.json +42 -0
- package/global.d.ts +22 -3
- package/next.config.js +73 -4
- package/package.json +58 -17
- package/tailwind.config.ts +36 -13
- package/tsconfig.json +6 -2
- package/core/router/RouteHandler.ts +0 -93
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** CSS / 编译 Telemetry 度量 — 聚合诊断与编译指标 */
|
|
2
|
+
export interface TelemetryMetric {
|
|
3
|
+
name: string;
|
|
4
|
+
value: number;
|
|
5
|
+
unit: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TelemetryExportOptions {
|
|
10
|
+
/** 导出为 OpenTelemetry 兼容 JSON 结构 */
|
|
11
|
+
format?: 'json' | 'otlp';
|
|
12
|
+
serviceName?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class SomaTelemetry {
|
|
16
|
+
private metrics: TelemetryMetric[] = [];
|
|
17
|
+
private readonly maxEntries: number;
|
|
18
|
+
|
|
19
|
+
constructor(maxEntries = 500) {
|
|
20
|
+
this.maxEntries = maxEntries;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
record(name: string, value: number, unit = 'ms'): void {
|
|
24
|
+
this.metrics.push({ name, value, unit, timestamp: Date.now() });
|
|
25
|
+
if (this.metrics.length > this.maxEntries) {
|
|
26
|
+
this.metrics.shift();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getMetrics(name?: string): TelemetryMetric[] {
|
|
31
|
+
return name ? this.metrics.filter((m) => m.name === name) : [...this.metrics];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
aggregate(name: string): { count: number; avg: number; max: number; min: number } {
|
|
35
|
+
const items = this.getMetrics(name);
|
|
36
|
+
if (items.length === 0) return { count: 0, avg: 0, max: 0, min: 0 };
|
|
37
|
+
const values = items.map((m) => m.value);
|
|
38
|
+
return {
|
|
39
|
+
count: values.length,
|
|
40
|
+
avg: values.reduce((a, b) => a + b, 0) / values.length,
|
|
41
|
+
max: Math.max(...values),
|
|
42
|
+
min: Math.min(...values),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
snapshot(): Record<string, ReturnType<SomaTelemetry['aggregate']>> {
|
|
47
|
+
const names = [...new Set(this.metrics.map((m) => m.name))];
|
|
48
|
+
const result: Record<string, ReturnType<SomaTelemetry['aggregate']>> = {};
|
|
49
|
+
for (const n of names) result[n] = this.aggregate(n);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 导出原始指标 JSON */
|
|
54
|
+
exportJson(): string {
|
|
55
|
+
return JSON.stringify(
|
|
56
|
+
{
|
|
57
|
+
exportedAt: new Date().toISOString(),
|
|
58
|
+
metrics: this.metrics,
|
|
59
|
+
aggregates: this.snapshot(),
|
|
60
|
+
},
|
|
61
|
+
null,
|
|
62
|
+
2,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 导出 OpenTelemetry 兼容 metrics 结构(简化版) */
|
|
67
|
+
exportOpenTelemetry(options: TelemetryExportOptions = {}): string {
|
|
68
|
+
const serviceName = options.serviceName ?? 'soma-runtime';
|
|
69
|
+
const resourceMetrics = {
|
|
70
|
+
resource: { attributes: [{ key: 'service.name', value: { stringValue: serviceName } }] },
|
|
71
|
+
scopeMetrics: [{
|
|
72
|
+
scope: { name: 'soma.telemetry' },
|
|
73
|
+
metrics: Object.entries(this.snapshot()).map(([name, stats]) => ({
|
|
74
|
+
name,
|
|
75
|
+
unit: 'ms',
|
|
76
|
+
summary: {
|
|
77
|
+
count: stats.count,
|
|
78
|
+
sum: stats.avg * stats.count,
|
|
79
|
+
quantileValues: [
|
|
80
|
+
{ quantile: 0.5, value: stats.avg },
|
|
81
|
+
{ quantile: 1, value: stats.max },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
})),
|
|
85
|
+
}],
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return JSON.stringify({ resourceMetrics: [resourceMetrics] }, null, 2);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** POST 到自定义 endpoint(浏览器 / Node fetch) */
|
|
92
|
+
async report(endpoint: string, format: 'json' | 'otlp' = 'json'): Promise<void> {
|
|
93
|
+
const body = format === 'otlp' ? this.exportOpenTelemetry() : this.exportJson();
|
|
94
|
+
await fetch(endpoint, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: { 'Content-Type': 'application/json' },
|
|
97
|
+
body,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SomaTelemetry } from './SomaTelemetry';
|
|
2
|
+
|
|
3
|
+
let active: SomaTelemetry | null = null;
|
|
4
|
+
|
|
5
|
+
export function setActiveTelemetry(telemetry: SomaTelemetry | null): void {
|
|
6
|
+
active = telemetry;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getActiveTelemetry(): SomaTelemetry | null {
|
|
10
|
+
return active;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function recordMetric(name: string, value: number, unit = 'ms'): void {
|
|
14
|
+
active?.record(name, value, unit);
|
|
15
|
+
}
|
|
@@ -5,7 +5,12 @@ import yaml from 'js-yaml';
|
|
|
5
5
|
import type { ICache } from '../infra/cache/ICache';
|
|
6
6
|
import { MemoryCache } from '../infra/cache/MemoryCache';
|
|
7
7
|
import { parseEventConfig } from '../parser/pipeline-parser';
|
|
8
|
+
import { splitEventConfigRaw } from '../parser/trigger-parser';
|
|
9
|
+
import { parseStyleConfig } from '../parser/style-config-parser';
|
|
8
10
|
import { parseUiConfig } from '../parser/ui-config-parser';
|
|
11
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
12
|
+
import { extractConfigFromDomainClass } from '../parser/annotation-extractor';
|
|
13
|
+
import { hasPageMetadata } from '../base/decorators/Page';
|
|
9
14
|
import type { SomaPageAssets, ParsedRuntimeAssets } from './soma-bootstrap';
|
|
10
15
|
|
|
11
16
|
/**
|
|
@@ -28,25 +33,48 @@ export class SomaAssetResolver {
|
|
|
28
33
|
return {
|
|
29
34
|
uiConfig: assets.uiConfig,
|
|
30
35
|
eventConfig: assets.eventConfig,
|
|
36
|
+
triggers: assets.triggerConfig ?? [],
|
|
37
|
+
timers: assets.timerConfig ?? [],
|
|
38
|
+
styleConfig: assets.styleConfig ?? this.parseStyleConfig(assets.styleYaml),
|
|
31
39
|
locale: assets.locale ?? this.parseLocale(assets.localeYaml),
|
|
32
40
|
appConfig: assets.appConfig ?? this.parseAppConfig(assets.appConfigYaml),
|
|
33
41
|
};
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
// 字符串模式:运行时解析,带缓存
|
|
37
|
-
const uiYaml = assets.uiYaml
|
|
38
|
-
const eventYaml = assets.eventYaml
|
|
45
|
+
const uiYaml = assets.uiYaml ?? '';
|
|
46
|
+
const eventYaml = assets.eventYaml ?? '';
|
|
39
47
|
const localeYaml = assets.localeYaml ?? '';
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
// 注解模式:无 YAML 时从 Domain Class 装饰器提取配置
|
|
50
|
+
if (!uiYaml.trim() && assets.DomainClass && hasPageMetadata(assets.DomainClass)) {
|
|
51
|
+
const extracted = extractConfigFromDomainClass(assets.DomainClass);
|
|
52
|
+
return {
|
|
53
|
+
uiConfig: extracted.uiConfig,
|
|
54
|
+
eventConfig: extracted.eventConfig,
|
|
55
|
+
triggers: assets.triggerConfig ?? [],
|
|
56
|
+
timers: assets.timerConfig ?? [],
|
|
57
|
+
styleConfig: this.parseStyleConfig(assets.styleYaml),
|
|
58
|
+
locale: localeYaml ? (yaml.load(localeYaml) as Record<string, unknown>) || {} : {},
|
|
59
|
+
appConfig: this.parseAppConfig(assets.appConfigYaml),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const cacheKey = `${uiYaml}\0${eventYaml}\0${localeYaml}\0${assets.appConfigYaml ?? ''}\0${assets.styleYaml ?? ''}`;
|
|
42
64
|
const cached = this.cache.get(cacheKey);
|
|
43
65
|
if (cached) {
|
|
44
66
|
return cached;
|
|
45
67
|
}
|
|
46
68
|
|
|
69
|
+
const eventRaw = eventYaml.trim() ? yaml.load(eventYaml) : {};
|
|
70
|
+
const { eventsRaw, triggers, timers } = splitEventConfigRaw(eventRaw);
|
|
71
|
+
|
|
47
72
|
const result: ParsedRuntimeAssets = {
|
|
48
73
|
uiConfig: parseUiConfig(yaml.load(uiYaml)),
|
|
49
|
-
eventConfig: parseEventConfig(
|
|
74
|
+
eventConfig: parseEventConfig(eventsRaw as any),
|
|
75
|
+
triggers,
|
|
76
|
+
timers,
|
|
77
|
+
styleConfig: this.parseStyleConfig(assets.styleYaml),
|
|
50
78
|
locale: localeYaml ? (yaml.load(localeYaml) as Record<string, unknown>) || {} : {},
|
|
51
79
|
appConfig: this.parseAppConfig(assets.appConfigYaml),
|
|
52
80
|
};
|
|
@@ -64,4 +92,11 @@ export class SomaAssetResolver {
|
|
|
64
92
|
if (!appConfigYaml) return null;
|
|
65
93
|
return yaml.load(appConfigYaml);
|
|
66
94
|
}
|
|
95
|
+
|
|
96
|
+
private parseStyleConfig(styleYaml?: string): import('../types/style-config.types').StyleConfig | undefined {
|
|
97
|
+
if (!styleYaml) return undefined;
|
|
98
|
+
const raw = yaml.load(styleYaml);
|
|
99
|
+
if (!raw) return undefined;
|
|
100
|
+
return parseStyleConfig(raw);
|
|
101
|
+
}
|
|
67
102
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
2
|
import type { SomaCompiledBinding } from '../types/manifest.types';
|
|
3
3
|
import type { BindingEntry } from '../types/engine.types';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
ExtendedShowValue,
|
|
6
|
+
NestedShowMapping,
|
|
7
|
+
ShowMapping,
|
|
8
|
+
ShowValue,
|
|
9
|
+
} from '../types/ui-config.types';
|
|
5
10
|
import type { SomaScopeResolver } from './scope-resolver';
|
|
6
11
|
import { longestIncreasingSubsequence } from './lis';
|
|
7
12
|
|
|
8
13
|
export type ModelWriteBack = (path: string, value: string) => void;
|
|
9
14
|
|
|
10
15
|
export class SomaDomRenderer {
|
|
11
|
-
private adapter:
|
|
16
|
+
private adapter: IContainerAdapter | null = null;
|
|
12
17
|
private resolver: SomaScopeResolver | null = null;
|
|
13
18
|
private scopeTracker: WeakMap<HTMLElement, any> | null = null;
|
|
14
19
|
private modelWriteBack: ModelWriteBack | null = null;
|
|
@@ -16,7 +21,7 @@ export class SomaDomRenderer {
|
|
|
16
21
|
private modelAbort = new AbortController();
|
|
17
22
|
|
|
18
23
|
init(
|
|
19
|
-
adapter:
|
|
24
|
+
adapter: IContainerAdapter,
|
|
20
25
|
resolver: SomaScopeResolver,
|
|
21
26
|
scopeTracker: WeakMap<HTMLElement, any>,
|
|
22
27
|
): void {
|
|
@@ -111,14 +116,12 @@ export class SomaDomRenderer {
|
|
|
111
116
|
}
|
|
112
117
|
if (modelWriteBack && !modelListeners.has(modelEl)) {
|
|
113
118
|
modelListeners.add(modelEl);
|
|
114
|
-
|
|
115
|
-
modelEl
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
modelAbort.signal,
|
|
121
|
-
);
|
|
119
|
+
const writeModel = () => {
|
|
120
|
+
modelWriteBack(dataPath, modelAdapter.getValue(modelEl));
|
|
121
|
+
};
|
|
122
|
+
for (const eventType of ['input', 'change', 'blur']) {
|
|
123
|
+
modelAdapter.listen(modelEl, eventType, writeModel, modelAbort.signal);
|
|
124
|
+
}
|
|
122
125
|
}
|
|
123
126
|
};
|
|
124
127
|
}
|
|
@@ -316,18 +319,24 @@ export class SomaDomRenderer {
|
|
|
316
319
|
this.adapter.appendFragment(entry.element, fragment);
|
|
317
320
|
}
|
|
318
321
|
|
|
319
|
-
private applyShowConfig(
|
|
320
|
-
root: HTMLElement,
|
|
321
|
-
data: any,
|
|
322
|
-
showConfig: ShowMapping,
|
|
323
|
-
): void {
|
|
324
|
-
for (const [rawKey, config] of Object.entries(showConfig)) {
|
|
325
|
-
if (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
322
|
+
private applyShowConfig(
|
|
323
|
+
root: HTMLElement,
|
|
324
|
+
data: any,
|
|
325
|
+
showConfig: ShowMapping,
|
|
326
|
+
): void {
|
|
327
|
+
for (const [rawKey, config] of Object.entries(showConfig)) {
|
|
328
|
+
if (this.isNestedShowMapping(config)) {
|
|
329
|
+
this.applyNestedShowConfig(root, data, rawKey, config);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (this.isExtendedShowValue(config)) {
|
|
334
|
+
this.applyExtendedShowConfig(root, data, rawKey, config);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const [somaId, attrName] = rawKey.split('@');
|
|
339
|
+
const element = root.querySelector<HTMLElement>(`[data-soma-id="${somaId}"]`);
|
|
331
340
|
if (!element) {
|
|
332
341
|
continue;
|
|
333
342
|
}
|
|
@@ -345,13 +354,122 @@ export class SomaDomRenderer {
|
|
|
345
354
|
continue;
|
|
346
355
|
}
|
|
347
356
|
|
|
348
|
-
this.adapter?.setText(element, value != null ? String(value) : '--');
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
private
|
|
353
|
-
|
|
354
|
-
|
|
357
|
+
this.adapter?.setText(element, value != null ? String(value) : '--');
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
private applyNestedShowConfig(
|
|
362
|
+
root: HTMLElement,
|
|
363
|
+
data: any,
|
|
364
|
+
rawKey: string,
|
|
365
|
+
config: NestedShowMapping,
|
|
366
|
+
): void {
|
|
367
|
+
if (!this.adapter) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const [somaId] = rawKey.split('@');
|
|
372
|
+
const element = root.querySelector<HTMLElement>(`[data-soma-id="${somaId}"]`);
|
|
373
|
+
if (!element) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const nestedData = this.resolveShowValue(config.bind.obj, data);
|
|
378
|
+
const role = this.adapter.readRole(element);
|
|
379
|
+
const templateCache = this.adapter.cloneTemplate(element);
|
|
380
|
+
if (!templateCache) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
this.adapter.clearRenderedChildren(element);
|
|
385
|
+
|
|
386
|
+
if (Array.isArray(nestedData) || role === 'item') {
|
|
387
|
+
const items = Array.isArray(nestedData) ? nestedData : [];
|
|
388
|
+
for (const itemData of items) {
|
|
389
|
+
this.appendNestedTemplateItem(element, templateCache, itemData, config.show);
|
|
390
|
+
}
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (nestedData && typeof nestedData === 'object') {
|
|
395
|
+
this.appendNestedTemplateItem(element, templateCache, nestedData, config.show);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
private appendNestedTemplateItem(
|
|
400
|
+
container: HTMLElement,
|
|
401
|
+
templateCache: DocumentFragment,
|
|
402
|
+
itemData: any,
|
|
403
|
+
showConfig: ShowMapping,
|
|
404
|
+
): void {
|
|
405
|
+
if (!this.adapter) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const fragment = templateCache.cloneNode(true) as DocumentFragment;
|
|
410
|
+
const wrapper = fragment.firstElementChild as HTMLElement | null;
|
|
411
|
+
if (!wrapper) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (itemData && typeof itemData === 'object') {
|
|
416
|
+
const key = 'id' in itemData ? itemData.id : ('key' in itemData ? itemData.key : undefined);
|
|
417
|
+
if (key != null) {
|
|
418
|
+
wrapper.setAttribute('data-soma-key', String(key));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
this.scopeTracker?.set(wrapper, itemData);
|
|
423
|
+
this.applyShowConfig(wrapper, itemData, showConfig);
|
|
424
|
+
this.adapter.appendFragment(container, fragment);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private applyExtendedShowConfig(
|
|
428
|
+
root: HTMLElement,
|
|
429
|
+
data: any,
|
|
430
|
+
rawKey: string,
|
|
431
|
+
config: ExtendedShowValue,
|
|
432
|
+
): void {
|
|
433
|
+
const [somaId, attrName] = rawKey.split('@');
|
|
434
|
+
const element = root.querySelector<HTMLElement>(`[data-soma-id="${somaId}"]`);
|
|
435
|
+
|
|
436
|
+
if (element) {
|
|
437
|
+
if (config.text) {
|
|
438
|
+
const value = this.resolveShowValue(config.text, data);
|
|
439
|
+
if (attrName === 'html') {
|
|
440
|
+
this.adapter?.setHtml(element, String(value ?? ''));
|
|
441
|
+
} else if (attrName) {
|
|
442
|
+
if (value != null) {
|
|
443
|
+
this.adapter?.setAttribute(element, attrName, String(value));
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
this.adapter?.setText(element, value != null ? String(value) : '--');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (config.when) {
|
|
451
|
+
const { path, negate } = this.parseConditionalPath(config.when);
|
|
452
|
+
const value = this.resolveShowValue(path, data);
|
|
453
|
+
this.adapter?.setVisibility(element, negate ? !value : !!value);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (config.class) {
|
|
457
|
+
for (const [classes, path] of Object.entries(config.class)) {
|
|
458
|
+
const enabled = !!this.resolveShowValue(path, data);
|
|
459
|
+
this.adapter?.toggleClasses(element, classes.split(' ').filter(Boolean), enabled);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (config.show) {
|
|
465
|
+
const showRoot = element ?? root;
|
|
466
|
+
this.applyShowConfig(showRoot, data, config.show);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
private resolveShowValue(valuePath: string, itemData: any): any {
|
|
471
|
+
const segments = valuePath.split('.');
|
|
472
|
+
const firstSeg = segments[0];
|
|
355
473
|
|
|
356
474
|
if (this.resolver && this.resolver.hasVar(firstSeg)) {
|
|
357
475
|
const varPath = this.resolver.getVarPath(firstSeg);
|
|
@@ -360,7 +478,23 @@ export class SomaDomRenderer {
|
|
|
360
478
|
}
|
|
361
479
|
return segments.slice(1).reduce((obj: any, key: string) => obj?.[key], itemData);
|
|
362
480
|
}
|
|
363
|
-
|
|
364
|
-
return segments.reduce((obj: any, key: string) => obj?.[key], itemData);
|
|
365
|
-
}
|
|
366
|
-
|
|
481
|
+
|
|
482
|
+
return segments.reduce((obj: any, key: string) => obj?.[key], itemData);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
private parseConditionalPath(valuePath: string): { path: string; negate: boolean } {
|
|
486
|
+
const negate = valuePath.startsWith('!');
|
|
487
|
+
return {
|
|
488
|
+
path: negate ? valuePath.slice(1) : valuePath,
|
|
489
|
+
negate,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
private isNestedShowMapping(value: ShowValue): value is NestedShowMapping {
|
|
494
|
+
return typeof value === 'object' && value !== null && 'bind' in value && 'show' in value;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
private isExtendedShowValue(value: ShowValue): value is ExtendedShowValue {
|
|
498
|
+
return typeof value === 'object' && value !== null;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { recordMetric } from '../diagnostics/telemetry-context';
|
|
2
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
3
|
import { SOMA_KEY_MODIFIERS } from '../types/keyboard.types';
|
|
3
4
|
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
4
5
|
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
5
6
|
import { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
6
7
|
import type { SomaCompiledEvent, SomaRuntimeManifest } from '../types/manifest.types';
|
|
7
|
-
import type { InteractAction } from '../types/event.types';
|
|
8
|
+
import type { InteractAction, EventHandlerResult } from '../types/event.types';
|
|
8
9
|
import type { SomaScopeResolver } from './scope-resolver';
|
|
9
10
|
|
|
10
11
|
export interface SomaEventMiddlewareContext {
|
|
@@ -19,12 +20,18 @@ export interface SomaEventMiddlewareContext {
|
|
|
19
20
|
export interface SomaEventEngineOptions<TContext extends Record<string, unknown> = Record<string, never>> {
|
|
20
21
|
manifest: SomaRuntimeManifest;
|
|
21
22
|
container: HTMLElement;
|
|
22
|
-
adapter:
|
|
23
|
+
adapter: IContainerAdapter;
|
|
23
24
|
resolver: SomaScopeResolver;
|
|
24
25
|
scopeTracker: WeakMap<HTMLElement, any>;
|
|
25
26
|
callbacks: {
|
|
26
27
|
onRefresh: () => void | Promise<void>;
|
|
27
|
-
|
|
28
|
+
/** @deprecated 使用 onCommit */
|
|
29
|
+
onFlush?: () => void | Promise<void>;
|
|
30
|
+
onCommit?: () => void | Promise<void>;
|
|
31
|
+
onBeginTransaction?: () => void;
|
|
32
|
+
onEndTransaction?: () => void;
|
|
33
|
+
onDiscardPending?: () => void;
|
|
34
|
+
onSyncModels?: () => void;
|
|
28
35
|
};
|
|
29
36
|
diagnostics?: SomaDiagnostics;
|
|
30
37
|
scheduler?: SomaScheduler;
|
|
@@ -39,12 +46,16 @@ export interface SomaEventEngineOptions<TContext extends Record<string, unknown>
|
|
|
39
46
|
export class SomaEventEngine<TContext extends Record<string, unknown> = Record<string, never>> {
|
|
40
47
|
private readonly manifest: SomaRuntimeManifest;
|
|
41
48
|
private readonly container: HTMLElement;
|
|
42
|
-
private readonly adapter:
|
|
49
|
+
private readonly adapter: IContainerAdapter;
|
|
43
50
|
private readonly resolver: SomaScopeResolver;
|
|
44
51
|
private readonly scopeTracker: WeakMap<HTMLElement, any>;
|
|
45
52
|
private readonly callbacks: {
|
|
46
53
|
onRefresh: () => void | Promise<void>;
|
|
47
|
-
|
|
54
|
+
onCommit: () => void | Promise<void>;
|
|
55
|
+
onBeginTransaction?: () => void;
|
|
56
|
+
onEndTransaction?: () => void;
|
|
57
|
+
onDiscardPending?: () => void;
|
|
58
|
+
onSyncModels?: () => void;
|
|
48
59
|
};
|
|
49
60
|
private readonly diagnostics: SomaDiagnostics | null;
|
|
50
61
|
private readonly scheduler: SomaScheduler;
|
|
@@ -63,7 +74,17 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
63
74
|
this.adapter = options.adapter;
|
|
64
75
|
this.resolver = options.resolver;
|
|
65
76
|
this.scopeTracker = options.scopeTracker;
|
|
66
|
-
this.callbacks =
|
|
77
|
+
this.callbacks = {
|
|
78
|
+
onRefresh: options.callbacks.onRefresh,
|
|
79
|
+
onCommit:
|
|
80
|
+
options.callbacks.onCommit ??
|
|
81
|
+
options.callbacks.onFlush ??
|
|
82
|
+
(() => Promise.resolve()),
|
|
83
|
+
onBeginTransaction: options.callbacks.onBeginTransaction,
|
|
84
|
+
onEndTransaction: options.callbacks.onEndTransaction,
|
|
85
|
+
onDiscardPending: options.callbacks.onDiscardPending,
|
|
86
|
+
onSyncModels: options.callbacks.onSyncModels,
|
|
87
|
+
};
|
|
67
88
|
this.diagnostics = options.diagnostics ?? null;
|
|
68
89
|
this.scheduler = options.scheduler ?? new SomaScheduler();
|
|
69
90
|
this.middleware = options.middleware ?? null;
|
|
@@ -81,26 +102,39 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
81
102
|
this.container,
|
|
82
103
|
eventType,
|
|
83
104
|
(event) => {
|
|
84
|
-
const
|
|
85
|
-
if (!
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const somaId = this.adapter.getAnchorId(target);
|
|
90
|
-
if (!somaId) {
|
|
105
|
+
const resolved = this.resolveEventBinding(eventType, event.target);
|
|
106
|
+
if (!resolved) {
|
|
91
107
|
return;
|
|
92
108
|
}
|
|
93
|
-
|
|
94
|
-
const config = this.manifest.eventIndex.get(`${eventType}:${somaId}`);
|
|
95
|
-
if (config) {
|
|
96
|
-
void this.execute(config, target, event);
|
|
97
|
-
}
|
|
109
|
+
void this.execute(resolved.config, resolved.element, event);
|
|
98
110
|
},
|
|
99
111
|
this.abortController.signal,
|
|
100
112
|
);
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
|
|
116
|
+
/**
|
|
117
|
+
* 从内层锚点向上查找第一个已注册事件的 data-soma-id。
|
|
118
|
+
* 避免点击 product_name 等子节点时,closest 停在无事件的子 id 上。
|
|
119
|
+
*/
|
|
120
|
+
private resolveEventBinding(
|
|
121
|
+
eventType: string,
|
|
122
|
+
start: EventTarget | null,
|
|
123
|
+
): { element: HTMLElement; config: SomaCompiledEvent } | null {
|
|
124
|
+
let el: HTMLElement | null = start instanceof HTMLElement ? start : null;
|
|
125
|
+
while (el && el !== this.container) {
|
|
126
|
+
const somaId = this.adapter.getAnchorId(el);
|
|
127
|
+
if (somaId) {
|
|
128
|
+
const config = this.manifest.eventIndex.get(`${eventType}:${somaId}`);
|
|
129
|
+
if (config) {
|
|
130
|
+
return { element: el, config };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
el = el.parentElement;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
104
138
|
execute(config: SomaCompiledEvent, element: HTMLElement, originalEvent: Event): Promise<void> {
|
|
105
139
|
return this.scheduler.schedule(
|
|
106
140
|
() => this.executeNow(config, element, originalEvent),
|
|
@@ -148,27 +182,61 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
148
182
|
}
|
|
149
183
|
}
|
|
150
184
|
|
|
151
|
-
let result = true;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
runtime.status = 'error';
|
|
159
|
-
runtime.message = error instanceof Error ? error.message : String(error);
|
|
160
|
-
result = false;
|
|
161
|
-
} finally {
|
|
162
|
-
this.pendingSet.delete(config.somaId);
|
|
163
|
-
}
|
|
185
|
+
let result: EventHandlerResult = true;
|
|
186
|
+
const runsHandler = Boolean(config.funcPath && config.type !== 'NAV_STATIC');
|
|
187
|
+
let inTransaction = false;
|
|
188
|
+
|
|
189
|
+
if (runsHandler) {
|
|
190
|
+
this.callbacks.onBeginTransaction?.();
|
|
191
|
+
inTransaction = true;
|
|
164
192
|
}
|
|
165
193
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
try {
|
|
195
|
+
if (runsHandler) {
|
|
196
|
+
try {
|
|
197
|
+
this.pendingSet.add(config.somaId);
|
|
198
|
+
this.callbacks.onSyncModels?.();
|
|
199
|
+
const fn = this.resolveFunction(config.funcPath!, currentVar);
|
|
200
|
+
result = await fn(currentVar, originalEvent);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
runtime.status = 'error';
|
|
203
|
+
runtime.message = error instanceof Error ? error.message : String(error);
|
|
204
|
+
result = false;
|
|
205
|
+
} finally {
|
|
206
|
+
this.pendingSet.delete(config.somaId);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const isError = runtime.status === 'error';
|
|
211
|
+
|
|
212
|
+
// DOM 同步:handler 正常返回后始终 commit(与成功/失败返回值无关)
|
|
213
|
+
if (runsHandler && !isError) {
|
|
214
|
+
const forceRefresh =
|
|
215
|
+
result !== false &&
|
|
216
|
+
config.type === 'UI_REFRESH' &&
|
|
217
|
+
config.refreshForce === true;
|
|
218
|
+
|
|
219
|
+
if (forceRefresh) {
|
|
220
|
+
this.callbacks.onDiscardPending?.();
|
|
221
|
+
await this.callbacks.onRefresh();
|
|
222
|
+
} else {
|
|
223
|
+
await this.callbacks.onCommit();
|
|
224
|
+
}
|
|
225
|
+
} else if (isError) {
|
|
226
|
+
this.callbacks.onDiscardPending?.();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Post-action:仅成功(非 false)时继续后续流程(跳转 / 显隐)
|
|
230
|
+
if (result !== false && !isError) {
|
|
231
|
+
await this.postAction(config, element);
|
|
232
|
+
} else if (!isError && runsHandler && result === false) {
|
|
233
|
+
runtime.status = 'blocked';
|
|
234
|
+
runtime.message = runtime.message ?? 'business handler returned false';
|
|
235
|
+
}
|
|
236
|
+
} finally {
|
|
237
|
+
if (inTransaction) {
|
|
238
|
+
this.callbacks.onEndTransaction?.();
|
|
239
|
+
}
|
|
172
240
|
}
|
|
173
241
|
};
|
|
174
242
|
|
|
@@ -187,6 +255,7 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
187
255
|
durationMs: this.adapter.now() - startedAt,
|
|
188
256
|
message: context.message,
|
|
189
257
|
});
|
|
258
|
+
recordMetric(`event.${config.type}`, this.adapter.now() - startedAt);
|
|
190
259
|
}
|
|
191
260
|
|
|
192
261
|
private getContext(element: HTMLElement): any {
|
|
@@ -206,8 +275,8 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
206
275
|
return false;
|
|
207
276
|
}
|
|
208
277
|
|
|
209
|
-
if (
|
|
210
|
-
return this.adapter.confirm(
|
|
278
|
+
if (config.confirm) {
|
|
279
|
+
return this.adapter.confirm(config.confirm);
|
|
211
280
|
}
|
|
212
281
|
|
|
213
282
|
return true;
|
|
@@ -223,7 +292,7 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
223
292
|
break;
|
|
224
293
|
|
|
225
294
|
case 'UI_REFRESH':
|
|
226
|
-
|
|
295
|
+
// 非 force:commit 已在 handler 后完成;force 时 onRefresh 在 executeNow 中调用
|
|
227
296
|
break;
|
|
228
297
|
|
|
229
298
|
case 'UI_INTERACT':
|