soma-core 1.3.2 → 1.3.4
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/README.md +43 -0
- package/app/SomaPageClient.tsx +22 -68
- package/app/[...path]/page.tsx +7 -6
- package/app/api/[...path]/route.ts +3 -3
- package/app/api/soma-registry/[...path]/route.ts +67 -0
- package/app/components/SomaHostPage.tsx +3 -8
- package/app/components/SomaPageClientBoundary.tsx +13 -0
- package/app/layout.tsx +6 -1
- package/app/page.tsx +3 -3
- package/app/soma/manifest/route.ts +1 -0
- package/app/soma/page-object/route.ts +1 -1
- package/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +19 -23
- package/core/build/compiler/html-include-expander.ts +56 -0
- package/core/build/compiler/page-assets.ts +26 -0
- package/core/build/compiler/page-declaration-compiler.ts +85 -0
- package/core/build/compiler/rollup-plugin-soma.ts +4 -13
- package/core/build/compiler/route-builder.ts +0 -2
- package/core/build/compiler/rspack-plugin-soma.js +1 -10
- package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
- package/core/build/compiler/soma-precompile.js +3581 -2387
- package/core/build/compiler/soma-precompile.ts +44 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
- package/core/build/compiler/soma-webpack-loader.js +6 -15
- package/core/build/compiler/vite-plugin-soma.ts +9 -21
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +281 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +133 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
- package/core/build/lsp/extra-completion.cjs +14 -8
- package/core/build/lsp/lsp-navigation.cjs +50 -43
- package/core/build/lsp/soma-declaration.cjs +85 -0
- package/core/build/lsp/ui-yaml-completion.cjs +98 -104
- package/core/build/v2/block-compile.ts +200 -0
- package/core/build/v2/block-loader.ts +33 -0
- package/core/build/v2/html-index.ts +120 -0
- package/core/build/v2/migrate-v1.ts +370 -0
- package/core/build/v2/soma-file-loader.ts +216 -0
- package/core/client/adaptive/flush-scheduler.ts +96 -0
- package/core/client/adaptive/hysteresis.ts +56 -0
- package/core/client/adaptive/index.ts +23 -0
- package/core/client/adaptive/observer-pool.ts +90 -0
- package/core/client/base/SomaPageRootBase.ts +50 -0
- package/core/client/compiler/adaptive-compile.ts +136 -0
- package/core/client/compiler/manifest-compiler.ts +155 -27
- package/core/client/component/ai-catalog.ts +277 -0
- package/core/client/component/component-definition.types.ts +65 -0
- package/core/client/component/component-expander.ts +119 -0
- package/core/client/component/component-manager.ts +933 -0
- package/core/client/component/component-pack.ts +445 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -0
- package/core/client/component/pack-styles.ts +94 -0
- package/core/client/component/scoped-adapter.ts +85 -0
- package/core/client/component/verify-pack.ts +247 -0
- package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
- package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
- package/core/client/container/SomaContainerAdapter.ts +186 -180
- package/core/client/data/data-object-resolver.ts +417 -0
- package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
- package/core/client/diagnostics/boot-timings.ts +152 -0
- package/core/client/engine/asset-resolver.ts +12 -2
- package/core/client/engine/dom-renderer.ts +249 -24
- package/core/client/engine/emit-event.ts +21 -0
- package/core/client/engine/event-engine.ts +34 -4
- package/core/client/engine/on-change-engine.ts +1 -1
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +11 -10
- package/core/client/engine/render-engine.ts +39 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +380 -7
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/observability/error-reporter.ts +173 -0
- package/core/client/parser/adaptive-parser.ts +264 -0
- package/core/client/parser/data-config-parser.ts +396 -0
- package/core/client/parser/pipeline-parser.ts +15 -3
- package/core/client/parser/style-config-parser.ts +65 -2
- package/core/client/parser/ui-config-parser.ts +52 -3
- package/core/client/parser/v2/namespace.ts +182 -0
- package/core/client/parser/v2/page-parser.ts +359 -0
- package/core/client/parser/v2/use-parser.ts +412 -0
- package/core/client/parser/value-lang.ts +340 -0
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +161 -0
- package/core/client/registry/index.ts +28 -0
- package/core/client/registry/page-lifecycle.ts +171 -0
- package/core/client/registry/remote-page.ts +139 -0
- package/core/client/runtime/SomaRuntimeServices.ts +24 -0
- package/core/client/security/attribute-presence.ts +70 -0
- package/core/client/security/html-sanitizer.ts +113 -0
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/theme/harmony.ts +307 -0
- package/core/client/theme/scene-tokens.ts +134 -0
- package/core/client/theme/theme-axes.ts +228 -0
- package/core/client/theme/theme-engine.ts +1196 -0
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +262 -2
- package/core/server/api/IService.ts +18 -6
- package/core/server/api/load-host-service.ts +3 -3
- package/core/server/host/content-security-policy.ts +190 -0
- package/core/server/host/csp-nonce-metadata.ts +75 -0
- package/core/server/host/resolve-host-request-hook.ts +5 -0
- package/core/server/host/server-page-assets.ts +34 -7
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +45 -1
- package/core/server/infra/cache/ServerFileCache.ts +1 -1
- package/core/server/mock/node/cli.mjs +2 -2
- package/core/server/registry/api-registry-store.ts +518 -0
- package/core/server/registry/conditional-object-store.ts +29 -0
- package/core/server/registry/declaration-precompiler.ts +99 -0
- package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
- package/core/server/registry/index.ts +142 -0
- package/core/server/registry/page-registry-repository.ts +373 -0
- package/core/server/registry/page-registry-store.ts +932 -0
- package/core/server/registry/registry-error.ts +17 -0
- package/core/server/registry/registry-file-lock.ts +173 -0
- package/core/server/registry/registry-response.ts +71 -0
- package/core/server/registry/registry-subjects.ts +194 -0
- package/core/server/registry/registry-write-pipeline.ts +240 -0
- package/core/server/registry/request-body-limit.ts +99 -0
- package/core/server/registry/services/apis/Get.ts +25 -0
- package/core/server/registry/services/apis/List.ts +41 -0
- package/core/server/registry/services/apis/Register.ts +39 -0
- package/core/server/registry/services/apis/Unregister.ts +24 -0
- package/core/server/registry/services/index.ts +40 -0
- package/core/server/registry/services/pages/Get.ts +96 -0
- package/core/server/registry/services/pages/List.ts +53 -0
- package/core/server/registry/services/pages/Register.ts +49 -0
- package/core/server/registry/services/pages/Rollback.ts +36 -0
- package/core/server/registry/services/pages/Unregister.ts +23 -0
- package/core/server/registry/services/service-utils.ts +21 -0
- package/core/server/registry/validation/compile-gate.ts +54 -0
- package/core/server/registry/validation/component-existence.ts +55 -0
- package/core/server/registry/validation/credential-ban.ts +86 -0
- package/core/server/registry/validation/cross-check.ts +67 -0
- package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
- package/core/shared/types/adaptive.types.ts +109 -0
- package/core/shared/types/component-contract.types.ts +120 -0
- package/core/shared/types/data-config.types.ts +105 -0
- package/core/shared/types/domain.types.ts +6 -0
- package/core/shared/types/engine.types.ts +41 -35
- package/core/shared/types/manifest.types.ts +55 -32
- package/core/shared/types/scope-manifest.types.ts +96 -0
- package/core/shared/types/style-config.types.ts +9 -0
- package/core/shared/types/ui-config.types.ts +118 -98
- package/dist/cli/soma.js +20 -5
- package/dist/core/index.cjs +7811 -1380
- package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
- package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
- package/dist/types/build/compiler/page-assets.d.ts +3 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +40 -0
- package/dist/types/build/eject/apply-eject.d.ts +22 -0
- package/dist/types/build/eject/plan-eject.d.ts +32 -0
- package/dist/types/build/v2/block-compile.d.ts +28 -0
- package/dist/types/build/v2/block-loader.d.ts +9 -0
- package/dist/types/build/v2/html-index.d.ts +37 -0
- package/dist/types/build/v2/migrate-v1.d.ts +32 -0
- package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
- package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
- package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
- package/dist/types/client/adaptive/index.d.ts +5 -0
- package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
- package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
- package/dist/types/client/component/ai-catalog.d.ts +73 -0
- package/dist/types/client/component/component-definition.types.d.ts +54 -0
- package/dist/types/client/component/component-expander.d.ts +25 -0
- package/dist/types/client/component/component-manager.d.ts +160 -0
- package/dist/types/client/component/component-pack.d.ts +110 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/contract-compat.d.ts +16 -0
- package/dist/types/client/component/example-v2.d.ts +9 -0
- package/dist/types/client/component/pack-styles.d.ts +22 -0
- package/dist/types/client/component/scoped-adapter.d.ts +18 -0
- package/dist/types/client/component/verify-pack.d.ts +14 -0
- package/dist/types/client/data/data-object-resolver.d.ts +71 -0
- package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
- package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
- package/dist/types/client/engine/asset-resolver.d.ts +7 -1
- package/dist/types/client/engine/dom-renderer.d.ts +51 -1
- package/dist/types/client/engine/emit-event.d.ts +6 -0
- package/dist/types/client/engine/event-engine.d.ts +6 -0
- package/dist/types/client/engine/render-engine.d.ts +25 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +118 -0
- package/dist/types/client/observability/error-reporter.d.ts +51 -0
- package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
- package/dist/types/client/parser/data-config-parser.d.ts +34 -0
- package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
- package/dist/types/client/parser/style-config-parser.d.ts +5 -3
- package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
- package/dist/types/client/parser/v2/namespace.d.ts +52 -0
- package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
- package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
- package/dist/types/client/parser/value-lang.d.ts +63 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +50 -0
- package/dist/types/client/registry/index.d.ts +10 -0
- package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
- package/dist/types/client/registry/remote-page.d.ts +52 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
- package/dist/types/client/security/attribute-presence.d.ts +7 -0
- package/dist/types/client/security/html-sanitizer.d.ts +37 -0
- package/dist/types/client/security/url-guard.d.ts +11 -0
- package/dist/types/client/theme/harmony.d.ts +77 -0
- package/dist/types/client/theme/scene-tokens.d.ts +25 -0
- package/dist/types/client/theme/theme-axes.d.ts +81 -0
- package/dist/types/client/theme/theme-engine.d.ts +77 -0
- package/dist/types/client/theme/tone-solver.d.ts +47 -0
- package/dist/types/client/typography/typography-base.d.ts +15 -0
- package/dist/types/client/validation/contract-validator.d.ts +2 -0
- package/dist/types/index.d.ts +47 -2
- package/dist/types/server/api/IService.d.ts +18 -6
- package/dist/types/server/host/content-security-policy.d.ts +53 -0
- package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
- package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
- package/dist/types/server/host/server-page-assets.d.ts +2 -0
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +6 -1
- package/dist/types/server/registry/api-registry-store.d.ts +141 -0
- package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
- package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
- package/dist/types/server/registry/index.d.ts +29 -0
- package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
- package/dist/types/server/registry/page-registry-store.d.ts +259 -0
- package/dist/types/server/registry/registry-error.d.ts +12 -0
- package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
- package/dist/types/server/registry/registry-response.d.ts +18 -0
- package/dist/types/server/registry/registry-subjects.d.ts +59 -0
- package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
- package/dist/types/server/registry/request-body-limit.d.ts +31 -0
- package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
- package/dist/types/server/registry/services/apis/List.d.ts +10 -0
- package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
- package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
- package/dist/types/server/registry/services/index.d.ts +3 -0
- package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
- package/dist/types/server/registry/services/pages/List.d.ts +13 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
- package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
- package/dist/types/server/registry/services/service-utils.d.ts +10 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +12 -0
- package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
- package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
- package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
- package/dist/types/shared/types/adaptive.types.d.ts +88 -0
- package/dist/types/shared/types/component-contract.types.d.ts +78 -0
- package/dist/types/shared/types/data-config.types.d.ts +81 -0
- package/dist/types/shared/types/domain.types.d.ts +6 -0
- package/dist/types/shared/types/engine.types.d.ts +6 -0
- package/dist/types/shared/types/manifest.types.d.ts +23 -0
- package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
- package/dist/types/shared/types/style-config.types.d.ts +8 -0
- package/dist/types/shared/types/ui-config.types.d.ts +20 -0
- package/editor/vscode/package.json +1 -24
- package/global.d.ts +5 -11
- package/next.config.js +85 -28
- package/package.json +33 -11
- package/proxy.ts +62 -0
- package/tailwind.config.ts +0 -1
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- package/core/client/engine/theme-variables.ts +0 -37
- package/dist/tsconfig.types.tsbuildinfo +0 -1
- package/dist/types/client/engine/theme-variables.d.ts +0 -3
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
- package/middleware.ts +0 -33
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// 声明渲染通道:拿着统一声明与服务端编译产物直接上屏(空 Domain + initProps 演示数据)。
|
|
2
|
+
//
|
|
3
|
+
// REQ-002 自 soma-ai 收编归位:「soma-ai 管生成,soma-core 管使用」——
|
|
4
|
+
// 把声明变成运行页面是引擎能力,与声明从哪来(AI 生成 / 应用构造 / 注册中心拉取)无关。
|
|
5
|
+
//
|
|
6
|
+
// - 传入声明即渲染,不经任何存储;应用攒在自己内存里的声明也能直接喂;
|
|
7
|
+
// - 预编译产物(注册中心 P-a)可选:版本闸在服务端,这里只做结构性校验;
|
|
8
|
+
// - destroy 清场:引擎 unmount 不清 DOM,本通道的销毁语义是挂载点还原为空。
|
|
9
|
+
|
|
10
|
+
import { SomaBootstrap } from '../engine/soma-bootstrap';
|
|
11
|
+
import type { SomaComponentDefinition } from '../component/component-definition.types';
|
|
12
|
+
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
13
|
+
import type { SomaErrorEvent, SomaPageIdentity } from '../observability/error-reporter';
|
|
14
|
+
import { SomaPageRootBase } from '../base/SomaPageRootBase';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 服务端编译产物。浏览器不编译 SOMA DSL 源声明,缺失或不完整时明确拒绝。
|
|
18
|
+
*/
|
|
19
|
+
export interface PrecompiledDeclarationAssets {
|
|
20
|
+
uiConfig?: unknown;
|
|
21
|
+
eventConfig?: unknown;
|
|
22
|
+
triggerConfig?: unknown;
|
|
23
|
+
timerConfig?: unknown;
|
|
24
|
+
styleConfig?: unknown;
|
|
25
|
+
dataConfig?: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GeneratedPageDeclarations {
|
|
29
|
+
html: string;
|
|
30
|
+
uiYaml: string;
|
|
31
|
+
eventYaml?: string;
|
|
32
|
+
styleYaml?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 错误采集开关(默认关闭)。
|
|
37
|
+
* 声明态页面是"注册即生效"的——出错时唯一有价值的问题是"哪个版本引入的"。
|
|
38
|
+
* 页面名与版本号只有渲染通道知道,不在这里盖戳,后面任何一层都补不回来。
|
|
39
|
+
*/
|
|
40
|
+
export interface PreviewObservabilityOptions {
|
|
41
|
+
/** 页面身份缺省值;renderPublishedPage 会用真实的 name@version 覆盖 */
|
|
42
|
+
page?: SomaPageIdentity;
|
|
43
|
+
/** 上报通道;缺省走 soma-core 的 console 单行 JSON 通道 */
|
|
44
|
+
report?: (event: SomaErrorEvent) => void;
|
|
45
|
+
/** 同签名错误去重窗口(毫秒) */
|
|
46
|
+
dedupeWindowMs?: number;
|
|
47
|
+
/** 单页上报条数上限 */
|
|
48
|
+
maxEvents?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface GeneratedPagePreviewOptions {
|
|
52
|
+
/** 给了就开启错误采集(`{ observability: {} }` 即为一行开启,用默认通道) */
|
|
53
|
+
observability?: PreviewObservabilityOptions;
|
|
54
|
+
/** 页面声明含 adaptive.ladder 时由 Host 注入的组件词汇。 */
|
|
55
|
+
adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface PreviewHandle {
|
|
59
|
+
/**
|
|
60
|
+
* 用新产物重新渲染(先卸载旧页面)。
|
|
61
|
+
* page 传入时覆盖本次渲染的页面身份——发布页拉到版本号后才知道该盖什么戳。
|
|
62
|
+
*/
|
|
63
|
+
render(
|
|
64
|
+
decl: GeneratedPageDeclarations,
|
|
65
|
+
page?: SomaPageIdentity,
|
|
66
|
+
compiled?: PrecompiledDeclarationAssets,
|
|
67
|
+
): Promise<void>;
|
|
68
|
+
destroy(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 采集未指定身份时的兜底戳:至少标明"这是即时预览产物,不是注册版本" */
|
|
72
|
+
const ANONYMOUS_PREVIEW_PAGE: SomaPageIdentity = { name: 'ai-preview', source: 'preview' };
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 预览页 Domain:无业务代码,数据全部来自产物的 initProps。
|
|
76
|
+
* 惰性建类:本模块可能被服务端脚本间接拉进 Node ESM,顶层继承会在导入那一刻
|
|
77
|
+
* 要求基类绑定就位;挪到首次使用时再建,浏览器行为一字不变。
|
|
78
|
+
*/
|
|
79
|
+
let previewPageRootCtor: (new () => SomaPageRootBase) | null = null;
|
|
80
|
+
|
|
81
|
+
function getPreviewPageRoot(): new () => SomaPageRootBase {
|
|
82
|
+
previewPageRootCtor ??= class PreviewPageRoot extends SomaPageRootBase {};
|
|
83
|
+
return previewPageRootCtor;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function createGeneratedPagePreview(
|
|
87
|
+
target: HTMLElement | string,
|
|
88
|
+
components: Record<string, SomaComponentDefinition>,
|
|
89
|
+
options: GeneratedPagePreviewOptions = {},
|
|
90
|
+
): PreviewHandle {
|
|
91
|
+
// Domain 层禁碰 DOM(架构规则),挂载点查找由本客户端助手代劳
|
|
92
|
+
const container = typeof target === 'string'
|
|
93
|
+
? document.getElementById(target)
|
|
94
|
+
: target;
|
|
95
|
+
if (!container) {
|
|
96
|
+
throw new Error(`[soma-core][声明渲染] 挂载点不存在: ${String(target)}`);
|
|
97
|
+
}
|
|
98
|
+
const observability = options.observability;
|
|
99
|
+
const adaptiveVocabulary = options.adaptiveVocabulary;
|
|
100
|
+
let bootstrap: SomaBootstrap | null = null;
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
async render(
|
|
104
|
+
decl: GeneratedPageDeclarations,
|
|
105
|
+
page?: SomaPageIdentity,
|
|
106
|
+
compiled?: PrecompiledDeclarationAssets,
|
|
107
|
+
): Promise<void> {
|
|
108
|
+
if (bootstrap) {
|
|
109
|
+
await bootstrap.unmount();
|
|
110
|
+
bootstrap = null;
|
|
111
|
+
}
|
|
112
|
+
const next = new SomaBootstrap({
|
|
113
|
+
components,
|
|
114
|
+
adaptiveVocabulary,
|
|
115
|
+
// 未开启采集时连字段都不传,引擎侧整条路径旁路(默认关闭)
|
|
116
|
+
...(observability
|
|
117
|
+
? {
|
|
118
|
+
errorReporting: {
|
|
119
|
+
...observability,
|
|
120
|
+
page: page ?? observability.page ?? ANONYMOUS_PREVIEW_PAGE,
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
: {}),
|
|
124
|
+
});
|
|
125
|
+
// 版本闸在服务端:那里同时知道"产物是哪个编译器版本产的"与"当前跑的是哪个版本",
|
|
126
|
+
// 客户端拿不到后者,在这里判等于自欺。服务端只有认定可用才会把 compiled 发下来,
|
|
127
|
+
// 这里只做最后一道结构性校验(ui/event 两段齐备,asset-resolver 的硬要求)。
|
|
128
|
+
const usable = compiled !== undefined
|
|
129
|
+
&& compiled.uiConfig !== undefined
|
|
130
|
+
&& compiled.eventConfig !== undefined;
|
|
131
|
+
if (!usable) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
'[soma-core][声明渲染] 缺少完整的服务端编译产物。'
|
|
134
|
+
+ '浏览器不解析 SOMA DSL 源声明;请由生成/注册服务返回 compiled 资产。',
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
await next.mount(container, {
|
|
138
|
+
html: decl.html,
|
|
139
|
+
uiYaml: '',
|
|
140
|
+
eventYaml: '',
|
|
141
|
+
styleYaml: '',
|
|
142
|
+
DomainClass: getPreviewPageRoot(),
|
|
143
|
+
uiConfig: compiled.uiConfig as never,
|
|
144
|
+
eventConfig: compiled.eventConfig as never,
|
|
145
|
+
triggerConfig: compiled.triggerConfig as never,
|
|
146
|
+
timerConfig: compiled.timerConfig as never,
|
|
147
|
+
...(compiled.styleConfig !== undefined ? { styleConfig: compiled.styleConfig as never } : {}),
|
|
148
|
+
...(compiled.dataConfig !== undefined ? { dataConfig: compiled.dataConfig as never } : {}),
|
|
149
|
+
});
|
|
150
|
+
bootstrap = next;
|
|
151
|
+
},
|
|
152
|
+
async destroy(): Promise<void> {
|
|
153
|
+
if (bootstrap) {
|
|
154
|
+
await bootstrap.unmount();
|
|
155
|
+
bootstrap = null;
|
|
156
|
+
}
|
|
157
|
+
// 引擎 unmount 不清 DOM(由下一次 mount 覆盖),销毁语义是清场
|
|
158
|
+
container.innerHTML = '';
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行时注册中心(客户端桶,'soma-core/registry')。
|
|
3
|
+
*
|
|
4
|
+
* REQ-002:声明 → 运行页面是引擎能力。两条消费路径:
|
|
5
|
+
* - createGeneratedPagePreview:拿着内存里的声明直接渲染(生成即渲、应用自组织的临时页);
|
|
6
|
+
* - renderPublishedPage:按名从注册中心拉取声明再渲染(注册即生效的共享页)。
|
|
7
|
+
*/
|
|
8
|
+
export {
|
|
9
|
+
createGeneratedPagePreview,
|
|
10
|
+
type GeneratedPageDeclarations,
|
|
11
|
+
type GeneratedPagePreviewOptions,
|
|
12
|
+
type PrecompiledDeclarationAssets,
|
|
13
|
+
type PreviewHandle,
|
|
14
|
+
type PreviewObservabilityOptions,
|
|
15
|
+
} from './declaration-renderer';
|
|
16
|
+
export {
|
|
17
|
+
createSomaPageLifecycle,
|
|
18
|
+
SomaPageLifecycle,
|
|
19
|
+
type MountedPageInfo,
|
|
20
|
+
type RegisterDeclarationOptions,
|
|
21
|
+
type SomaPageLifecycleOptions,
|
|
22
|
+
} from './page-lifecycle';
|
|
23
|
+
export {
|
|
24
|
+
renderPublishedPage,
|
|
25
|
+
type PublishedPageHandle,
|
|
26
|
+
type PublishedPageRecord,
|
|
27
|
+
type RenderPublishedPageOptions,
|
|
28
|
+
} from './remote-page';
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// 页面生命周期管理器:注册 → 挂载 → 卸载 → 注销的实例表。
|
|
2
|
+
//
|
|
3
|
+
// 为什么要有它:平台已经能"把声明变成页面",但**谁在管这些页面的死活**先前没人管——
|
|
4
|
+
// 每个应用自己拿着句柄、自己记哪个槽位挂了什么、自己保证切走时卸干净。
|
|
5
|
+
// ai-demo `/my-space` 就是手写这套簿记的样子:能跑,但每个应用都要重写一遍,
|
|
6
|
+
// 而写漏一次 destroy 在 2GB 机器上就是内存不还。
|
|
7
|
+
//
|
|
8
|
+
// 边界(和注册中心分得很清):
|
|
9
|
+
// - 它**不碰服务端**:声明从哪来不关它的事(应用现攒的、按名拉的都行);
|
|
10
|
+
// - 它**不碰路由**:挂到哪个 DOM 挂载点由调用方给,URL 空间归开发态页面;
|
|
11
|
+
// - 它只做一件事:把"名字 → 声明 → 若干个挂载实例"这张表管住,并保证卸载真还内存。
|
|
12
|
+
//
|
|
13
|
+
// 一个名字可以同时挂多处(多实例):同一份声明渲染在两个槽位是合法用法,
|
|
14
|
+
// unmount 按挂载点收,unregister 连声明带全部实例一起清。
|
|
15
|
+
|
|
16
|
+
import type { SomaComponentDefinition } from '../component/component-definition.types';
|
|
17
|
+
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
18
|
+
import type { SomaPageIdentity } from '../observability/error-reporter';
|
|
19
|
+
import {
|
|
20
|
+
createGeneratedPagePreview,
|
|
21
|
+
type GeneratedPageDeclarations,
|
|
22
|
+
type PrecompiledDeclarationAssets,
|
|
23
|
+
type PreviewHandle,
|
|
24
|
+
type PreviewObservabilityOptions,
|
|
25
|
+
} from './declaration-renderer';
|
|
26
|
+
|
|
27
|
+
export interface SomaPageLifecycleOptions {
|
|
28
|
+
/** 组件定义表(通常是 createSomaUiComponents() 加宿主自治组件) */
|
|
29
|
+
components: Record<string, SomaComponentDefinition>;
|
|
30
|
+
/** 页面声明含 adaptive.ladder 时由 Host 注入的组件词汇 */
|
|
31
|
+
adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
32
|
+
/** 错误采集(默认关闭);页面身份会自动盖上注册名 */
|
|
33
|
+
observability?: PreviewObservabilityOptions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface RegisterDeclarationOptions {
|
|
37
|
+
/** 预编译产物(注册中心取页时会带回来),有就省一次解析 */
|
|
38
|
+
compiled?: PrecompiledDeclarationAssets;
|
|
39
|
+
/** 页面身份戳(缺省用注册名);注册中心来的声明应带上真实版本号 */
|
|
40
|
+
page?: SomaPageIdentity;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface MountedPageInfo {
|
|
44
|
+
/** 注册名 */
|
|
45
|
+
name: string;
|
|
46
|
+
/** 挂载点 id */
|
|
47
|
+
mountId: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface RegisteredEntry {
|
|
51
|
+
declaration: GeneratedPageDeclarations;
|
|
52
|
+
compiled?: PrecompiledDeclarationAssets;
|
|
53
|
+
page?: SomaPageIdentity;
|
|
54
|
+
/** 挂载点 id → 渲染句柄 */
|
|
55
|
+
mounts: Map<string, PreviewHandle>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 实例表。**纯内存、纯客户端**:进程内活着,刷新即空——
|
|
60
|
+
* 需要跨刷新存活的声明属于注册中心那一侧的事(按名拉取)。
|
|
61
|
+
*/
|
|
62
|
+
export class SomaPageLifecycle {
|
|
63
|
+
private readonly entries = new Map<string, RegisteredEntry>();
|
|
64
|
+
|
|
65
|
+
constructor(private readonly options: SomaPageLifecycleOptions) {}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 登记一份声明(同名即替换)。替换时会先把它已有的挂载全部卸掉——
|
|
69
|
+
* 否则屏幕上留着旧内容而表里已是新声明,是最难查的那类不一致。
|
|
70
|
+
*/
|
|
71
|
+
async register(
|
|
72
|
+
name: string,
|
|
73
|
+
declaration: GeneratedPageDeclarations,
|
|
74
|
+
options: RegisterDeclarationOptions = {},
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
await this.unregister(name);
|
|
77
|
+
this.entries.set(name, {
|
|
78
|
+
declaration,
|
|
79
|
+
...(options.compiled ? { compiled: options.compiled } : {}),
|
|
80
|
+
...(options.page ? { page: options.page } : {}),
|
|
81
|
+
mounts: new Map(),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 这个名字登记过吗 */
|
|
86
|
+
has(name: string): boolean {
|
|
87
|
+
return this.entries.has(name);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 已登记的名字(按登记顺序) */
|
|
91
|
+
names(): string[] {
|
|
92
|
+
return [...this.entries.keys()];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 当前挂着的实例清单(名字 + 挂载点) */
|
|
96
|
+
mounted(): MountedPageInfo[] {
|
|
97
|
+
const list: MountedPageInfo[] = [];
|
|
98
|
+
for (const [name, entry] of this.entries) {
|
|
99
|
+
for (const mountId of entry.mounts.keys()) list.push({ name, mountId });
|
|
100
|
+
}
|
|
101
|
+
return list;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 把已登记的声明挂到某个挂载点。
|
|
106
|
+
* 同一挂载点重复 mount 会先卸掉那里的旧实例(挂载点是唯一的,不叠加)。
|
|
107
|
+
*/
|
|
108
|
+
async mount(name: string, mountId: string): Promise<void> {
|
|
109
|
+
const entry = this.entries.get(name);
|
|
110
|
+
if (!entry) {
|
|
111
|
+
throw new Error(`[soma-core][生命周期] 页面未登记:${name}(先 register 再 mount)`);
|
|
112
|
+
}
|
|
113
|
+
await this.unmount(name, mountId);
|
|
114
|
+
const handle = createGeneratedPagePreview(mountId, this.options.components, {
|
|
115
|
+
...(this.options.adaptiveVocabulary ? { adaptiveVocabulary: this.options.adaptiveVocabulary } : {}),
|
|
116
|
+
...(this.options.observability ? { observability: this.options.observability } : {}),
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
await handle.render(
|
|
120
|
+
entry.declaration,
|
|
121
|
+
entry.page ?? { name, source: 'registry' },
|
|
122
|
+
entry.compiled,
|
|
123
|
+
);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
// 渲染失败就别把半死的句柄留在表里:清场后原样抛给调用方兜底
|
|
126
|
+
await handle.destroy().catch(() => undefined);
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
entry.mounts.set(mountId, handle);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 卸载。给 mountId 只卸那一处,不给则卸这个名字的全部实例。
|
|
134
|
+
* 卸载**必须真还内存**:句柄 destroy 会 unmount 引擎并清空挂载点 DOM,
|
|
135
|
+
* 这里再把句柄从表里删掉——表还拿着引用,GC 就收不走。
|
|
136
|
+
*/
|
|
137
|
+
async unmount(name: string, mountId?: string): Promise<void> {
|
|
138
|
+
const entry = this.entries.get(name);
|
|
139
|
+
if (!entry) return;
|
|
140
|
+
if (mountId === undefined) {
|
|
141
|
+
const handles = [...entry.mounts.values()];
|
|
142
|
+
entry.mounts.clear();
|
|
143
|
+
await Promise.all(handles.map((handle) => handle.destroy()));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const handle = entry.mounts.get(mountId);
|
|
147
|
+
if (!handle) return;
|
|
148
|
+
entry.mounts.delete(mountId);
|
|
149
|
+
await handle.destroy();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** 注销:先卸全部实例,再把声明从表里丢掉 */
|
|
153
|
+
async unregister(name: string): Promise<void> {
|
|
154
|
+
if (!this.entries.has(name)) return;
|
|
155
|
+
await this.unmount(name);
|
|
156
|
+
this.entries.delete(name);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 全清:页面离开时调一次,别把整张表连同声明一起漏在内存里 */
|
|
160
|
+
async destroyAll(): Promise<void> {
|
|
161
|
+
const names = this.names();
|
|
162
|
+
for (const name of names) {
|
|
163
|
+
await this.unregister(name);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** 建一个实例表(与 createSomaUiComponents() 一起用) */
|
|
169
|
+
export function createSomaPageLifecycle(options: SomaPageLifecycleOptions): SomaPageLifecycle {
|
|
170
|
+
return new SomaPageLifecycle(options);
|
|
171
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// 注册页面的运行时渲染:按名从注册中心拉取页面声明,复用声明渲染通道挂载。
|
|
2
|
+
//
|
|
3
|
+
// 「声明即数据」的消费端:
|
|
4
|
+
// - 声明存服务端(/api/soma-registry/pages/*,带版本可回滚),注册即生效;
|
|
5
|
+
// - 拉取成功 → 走 createGeneratedPagePreview 通道渲染(空 Domain + initProps);
|
|
6
|
+
// - 拉取失败(404 / 网络异常 / 响应异常)抛出带上下文的明确错误,由调用方兜底。
|
|
7
|
+
//
|
|
8
|
+
// 注意:本文件是浏览器入口,不得引入 Node 内建或服务端模块,
|
|
9
|
+
// 因此声明记录的类型在此独立声明(与 PageRegistryStore 的 PageVersionRecord 同构)。
|
|
10
|
+
|
|
11
|
+
import type { SomaComponentDefinition } from '../component/component-definition.types';
|
|
12
|
+
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
13
|
+
import {
|
|
14
|
+
createGeneratedPagePreview,
|
|
15
|
+
type GeneratedPageDeclarations,
|
|
16
|
+
type PrecompiledDeclarationAssets,
|
|
17
|
+
type PreviewObservabilityOptions,
|
|
18
|
+
} from './declaration-renderer';
|
|
19
|
+
|
|
20
|
+
/** 服务端返回的版本记录(与注册中心 PageVersionRecord 同构) */
|
|
21
|
+
export interface PublishedPageRecord {
|
|
22
|
+
name: string;
|
|
23
|
+
version: number;
|
|
24
|
+
declaration: GeneratedPageDeclarations & { notes?: string };
|
|
25
|
+
status: 'published' | 'draft';
|
|
26
|
+
createdAt: number;
|
|
27
|
+
/**
|
|
28
|
+
* 注册期预编译产物(P-a)。服务端已做过版本闸:发下来就是能用的,
|
|
29
|
+
* 没发下来就说明版本对不上或压根没编译过——客户端照常运行时解析。
|
|
30
|
+
*/
|
|
31
|
+
compiled?: PrecompiledDeclarationAssets;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface RenderPublishedPageOptions {
|
|
35
|
+
/** 指定版本号;缺省拉最新 published 版本 */
|
|
36
|
+
version?: number;
|
|
37
|
+
/** 可注入 fetch(测试 / 自定义传输),默认 globalThis.fetch */
|
|
38
|
+
http?: typeof globalThis.fetch;
|
|
39
|
+
/** 拉取端点,默认 /api/soma-registry/pages/get */
|
|
40
|
+
endpoint?: string;
|
|
41
|
+
/**
|
|
42
|
+
* 非敏感请求头(例如 Host 的页面来源标识)。用于让服务端能力网关识别调用页面;
|
|
43
|
+
* 禁止放 Authorization、签名密钥或任何长期凭据。
|
|
44
|
+
*/
|
|
45
|
+
requestHeaders?: Readonly<Record<string, string>>;
|
|
46
|
+
/**
|
|
47
|
+
* 错误采集(默认关闭;给了就开启,`observability: {}` 即为一行开启)。
|
|
48
|
+
* 页面身份由本函数按拉取结果自动盖戳 `{ name, version, source: 'registry' }`——
|
|
49
|
+
* 声明可以随时注册新版本,只有这里知道渲染的究竟是哪一版。
|
|
50
|
+
*/
|
|
51
|
+
observability?: PreviewObservabilityOptions;
|
|
52
|
+
/** 页面声明含 adaptive.ladder 时由 Host 注入的组件词汇。 */
|
|
53
|
+
adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface PublishedPageHandle {
|
|
57
|
+
/** 实际渲染的页面名 */
|
|
58
|
+
name: string;
|
|
59
|
+
/** 实际渲染的版本号(缺省拉取时即最新 published 版本) */
|
|
60
|
+
version: number;
|
|
61
|
+
/** 卸载页面并清空挂载点 */
|
|
62
|
+
destroy(): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 拉取注册页面声明并渲染到 mountId 对应的挂载点。
|
|
67
|
+
* 任何拉取 / 解析失败都会抛出带页面名上下文的 Error(调用方 catch 后兜底展示)。
|
|
68
|
+
*/
|
|
69
|
+
export async function renderPublishedPage(
|
|
70
|
+
mountId: string,
|
|
71
|
+
name: string,
|
|
72
|
+
components: Record<string, SomaComponentDefinition>,
|
|
73
|
+
options: RenderPublishedPageOptions = {},
|
|
74
|
+
): Promise<PublishedPageHandle> {
|
|
75
|
+
const fetcher = options.http ?? globalThis.fetch;
|
|
76
|
+
if (typeof fetcher !== 'function') {
|
|
77
|
+
throw new Error('[soma-core][注册页] 当前环境没有可用的 fetch 实现');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const query = new URLSearchParams({ name });
|
|
81
|
+
if (options.version !== undefined) {
|
|
82
|
+
query.set('version', String(options.version));
|
|
83
|
+
}
|
|
84
|
+
const url = `${options.endpoint ?? '/api/soma-registry/pages/get'}?${query.toString()}`;
|
|
85
|
+
|
|
86
|
+
let response: Response;
|
|
87
|
+
try {
|
|
88
|
+
response = await fetcher(url, {
|
|
89
|
+
credentials: 'include',
|
|
90
|
+
headers: { Accept: 'application/json', ...options.requestHeaders },
|
|
91
|
+
});
|
|
92
|
+
} catch (error) {
|
|
93
|
+
throw new Error(`[soma-core][注册页] 拉取页面声明失败:${name}(网络异常)`, {
|
|
94
|
+
cause: error,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const body = (await response.json().catch(() => null)) as {
|
|
99
|
+
success?: unknown;
|
|
100
|
+
message?: unknown;
|
|
101
|
+
data?: unknown;
|
|
102
|
+
} | null;
|
|
103
|
+
if (!response.ok || !body || body.success !== true || !isPublishedPageRecord(body.data)) {
|
|
104
|
+
const reason = body && typeof body.message === 'string' && body.message
|
|
105
|
+
? body.message
|
|
106
|
+
: `HTTP ${response.status}`;
|
|
107
|
+
throw new Error(`[soma-core][注册页] 页面声明不可用:${name}(${reason})`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const record = body.data;
|
|
111
|
+
const preview = createGeneratedPagePreview(mountId, components, {
|
|
112
|
+
observability: options.observability,
|
|
113
|
+
adaptiveVocabulary: options.adaptiveVocabulary,
|
|
114
|
+
});
|
|
115
|
+
// 版本号只有拉取回来才知道,页面身份必须在这一刻盖戳,否则错误再也归不了因
|
|
116
|
+
await preview.render(
|
|
117
|
+
record.declaration,
|
|
118
|
+
{ name: record.name, version: record.version, source: 'registry' },
|
|
119
|
+
record.compiled,
|
|
120
|
+
);
|
|
121
|
+
return {
|
|
122
|
+
name: record.name,
|
|
123
|
+
version: record.version,
|
|
124
|
+
destroy: () => preview.destroy(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function isPublishedPageRecord(value: unknown): value is PublishedPageRecord {
|
|
129
|
+
if (!value || typeof value !== 'object') {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const record = value as Partial<PublishedPageRecord>;
|
|
133
|
+
return typeof record.name === 'string'
|
|
134
|
+
&& typeof record.version === 'number'
|
|
135
|
+
&& !!record.declaration
|
|
136
|
+
&& typeof record.declaration === 'object'
|
|
137
|
+
&& typeof record.declaration.html === 'string'
|
|
138
|
+
&& typeof record.declaration.uiYaml === 'string';
|
|
139
|
+
}
|
|
@@ -32,6 +32,28 @@ export interface SomaRuntimeServices {
|
|
|
32
32
|
permission: SomaPermission;
|
|
33
33
|
i18n: DefaultI18n;
|
|
34
34
|
realtime: IRealtimeService;
|
|
35
|
+
/**
|
|
36
|
+
* 界面中途提交:把此刻改过的页面状态立刻上屏,**不结束**当前事件事务。
|
|
37
|
+
*
|
|
38
|
+
* 存在的理由:一次事件 = 一次原子提交是刻意的设计(避免中间态闪烁、出错整体回滚),
|
|
39
|
+
* 代价是**长任务里的中途进展播不出去**——实测 AI 生成 P50 约 40 秒,期间 Domain
|
|
40
|
+
* 改多少次状态,界面一次都不动,连"生成中"都看不到。
|
|
41
|
+
*
|
|
42
|
+
* 它是**自愿**的:不调用,行为与过去逐字节一致;调用了,就等于声明
|
|
43
|
+
* "已上屏的这部分不再享有失败回滚"。这个取舍只能由业务自己做。
|
|
44
|
+
* 引擎未接线时(纯 Node 单测、无渲染宿主)为空操作,调用方不必判空。
|
|
45
|
+
*/
|
|
46
|
+
ui: SomaUiService;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 界面中途提交服务(见 SomaRuntimeServices.ui) */
|
|
50
|
+
export interface SomaUiService {
|
|
51
|
+
publish(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 缺省实现:引擎未接线时的空操作(纯 Node 单测、无渲染宿主) */
|
|
55
|
+
function createNoopUiService(): SomaUiService {
|
|
56
|
+
return { publish: async () => undefined };
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
export function createDefaultRuntimeServices(options?: {
|
|
@@ -100,5 +122,7 @@ export function createDefaultRuntimeServices(options?: {
|
|
|
100
122
|
wsBaseUrl: config.get<string>('realtime.wsBaseUrl'),
|
|
101
123
|
tokenProvider: () => auth.getToken(),
|
|
102
124
|
}),
|
|
125
|
+
// 渲染引擎就绪后由 bootstrap 换成真实实现;在那之前(以及无渲染宿主时)是空操作
|
|
126
|
+
ui: createNoopUiService(),
|
|
103
127
|
};
|
|
104
128
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// 属性「存在性」语义(B4)。
|
|
2
|
+
//
|
|
3
|
+
// 问题:声明绑定是静态的——`'node@aria-expanded': 'row.ariaExpanded'` 这一行写下去,
|
|
4
|
+
// 每一行数据都会写出这个属性。但有些属性的正确用法是「要么带正确值,要么根本不出现」:
|
|
5
|
+
// - ARIA 状态属性:树的叶子节点不该有 aria-expanded(有值就等于宣称"我能展开"),
|
|
6
|
+
// 空串 aria-expanded="" 是无效值,不同读屏器解读不一致;
|
|
7
|
+
// - HTML 布尔属性:readonly="" 等同 readonly=true,想表达"不只读"必须让属性消失。
|
|
8
|
+
//
|
|
9
|
+
// 规则:上述两类属性拿到空串时删除属性,而不是写入空串。
|
|
10
|
+
// 反过来,`alt=""`(装饰图)、`value=""`、`placeholder=""` 是有意义的空值,一律照写。
|
|
11
|
+
// 于是控制器里 `ariaExpanded: isLeaf ? '' : String(isOpen)` 就能表达"这行不要这个属性"。
|
|
12
|
+
|
|
13
|
+
/** HTML 布尔属性:属性一旦存在即为真,值无关紧要 */
|
|
14
|
+
const BOOLEAN_ATTRS = new Set([
|
|
15
|
+
'disabled',
|
|
16
|
+
'readonly',
|
|
17
|
+
'required',
|
|
18
|
+
'checked',
|
|
19
|
+
'selected',
|
|
20
|
+
'multiple',
|
|
21
|
+
'hidden',
|
|
22
|
+
'open',
|
|
23
|
+
'autofocus',
|
|
24
|
+
'novalidate',
|
|
25
|
+
'inert',
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ARIA 里"缺省即无此状态"的属性。
|
|
30
|
+
* 只收状态/关系类;aria-label 这类"内容型"不在此列(空 label 直接不写更合适,
|
|
31
|
+
* 但那属于内容缺失,交由 a11y 闸门管,不在写入层默默吞掉)。
|
|
32
|
+
*/
|
|
33
|
+
const ABSENT_WHEN_EMPTY_ARIA = new Set([
|
|
34
|
+
'aria-expanded',
|
|
35
|
+
'aria-selected',
|
|
36
|
+
'aria-checked',
|
|
37
|
+
'aria-pressed',
|
|
38
|
+
'aria-current',
|
|
39
|
+
'aria-disabled',
|
|
40
|
+
'aria-hidden',
|
|
41
|
+
'aria-level',
|
|
42
|
+
'aria-setsize',
|
|
43
|
+
'aria-posinset',
|
|
44
|
+
'aria-controls',
|
|
45
|
+
'aria-describedby',
|
|
46
|
+
'aria-labelledby',
|
|
47
|
+
'aria-owns',
|
|
48
|
+
'aria-activedescendant',
|
|
49
|
+
// 2026-08-17(soma-ui B10-2 DataTable 受控排序)补:aria-sort 的合法值只有
|
|
50
|
+
// ascending/descending/none/other,空串是无效值;且"这一列根本不可排序"与
|
|
51
|
+
// "这一列可排序但当前没排"是两回事——前者必须没有这个属性,后者才写 none。
|
|
52
|
+
'aria-sort',
|
|
53
|
+
// 同理:aria-invalid 空串在部分读屏器上会被当作 true("存在即为真"的老实现),
|
|
54
|
+
// 表单控件在非错误态下写空串等于凭空宣告"这个字段填错了"。
|
|
55
|
+
'aria-invalid',
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
/** 空串是否意味着「删除该属性」 */
|
|
59
|
+
export function isAbsentWhenEmpty(attrName: string): boolean {
|
|
60
|
+
const name = attrName.toLowerCase();
|
|
61
|
+
return BOOLEAN_ATTRS.has(name) || ABSENT_WHEN_EMPTY_ARIA.has(name);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 属性写入前的存在性判定。
|
|
66
|
+
* 返回 true = 应删除属性(而非写入空串)。
|
|
67
|
+
*/
|
|
68
|
+
export function shouldRemoveAttribute(attrName: string, value: string): boolean {
|
|
69
|
+
return value === '' && isAbsentWhenEmpty(attrName);
|
|
70
|
+
}
|