soma-core 1.3.2 → 1.3.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/README.md +42 -0
- package/app/SomaPageClient.tsx +26 -2
- 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/core/build/compiler/full-manifest-builder.ts +6 -1
- package/core/build/compiler/rollup-plugin-soma.ts +6 -0
- package/core/build/compiler/soma-manifest-webpack-plugin.js +4 -0
- package/core/build/compiler/soma-precompile.js +3507 -2387
- package/core/build/compiler/soma-precompile.ts +31 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +3 -0
- package/core/build/compiler/soma-webpack-loader.js +7 -1
- package/core/build/compiler/vite-plugin-soma.ts +11 -1
- package/core/build/component/package-loader.ts +135 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +139 -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 +262 -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 +271 -0
- package/core/client/component/component-registry.ts +71 -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 +235 -16
- 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 +3 -3
- 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 +359 -4
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/host-bridge/empty-host/data/README.md +17 -0
- 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/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +159 -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/theme-engine.ts +936 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +190 -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 +10 -0
- package/core/server/index.ts +30 -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 +129 -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 +903 -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 +86 -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 +71 -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 +77 -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 +110 -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 +5341 -894
- package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +1 -0
- package/dist/types/build/compiler/soma-precompile.d.ts +9 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +3 -0
- package/dist/types/build/component/package-loader.d.ts +9 -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/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 +90 -0
- package/dist/types/client/component/component-registry.d.ts +12 -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 +49 -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 +116 -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/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +51 -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/theme-engine.d.ts +49 -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 +36 -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 +5 -0
- package/dist/types/server/index.d.ts +4 -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 +10 -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 +68 -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/global.d.ts +4 -0
- package/next.config.js +76 -1
- package/package.json +32 -11
- package/proxy.ts +62 -0
- 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/middleware.ts +0 -33
|
@@ -3,6 +3,7 @@ import type { ParsedEvent } from '../../shared/types/event.types';
|
|
|
3
3
|
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
4
4
|
import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
5
5
|
import type { StyleConfig } from '../../shared/types/style-config.types';
|
|
6
|
+
import type { SomaDataConfig } from '../../shared/types/data-config.types';
|
|
6
7
|
import { type SomaRouteEntry } from './route-builder';
|
|
7
8
|
export interface SomaPrecompiledPage {
|
|
8
9
|
path: string;
|
|
@@ -12,6 +13,8 @@ export interface SomaPrecompiledPage {
|
|
|
12
13
|
timers: ParsedTimer[];
|
|
13
14
|
styleConfig?: StyleConfig;
|
|
14
15
|
appConfig?: unknown;
|
|
16
|
+
/** 数据对象层声明(*_data.yaml 预编译物化产物,可选件) */
|
|
17
|
+
dataConfig?: SomaDataConfig;
|
|
15
18
|
}
|
|
16
19
|
export interface SomaPrecompiledManifest {
|
|
17
20
|
routes: SomaRouteEntry[];
|
|
@@ -32,6 +35,7 @@ export declare function precompileAll(inputs: {
|
|
|
32
35
|
uiYaml: string;
|
|
33
36
|
eventYaml: string;
|
|
34
37
|
styleYaml?: string;
|
|
38
|
+
dataYaml?: string;
|
|
35
39
|
appConfigYaml?: string;
|
|
36
40
|
}>;
|
|
37
41
|
}): SomaPrecompiledManifest;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SomaDataConfig } from '../../shared/types/data-config.types';
|
|
1
2
|
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
2
3
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
3
4
|
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
@@ -34,6 +35,14 @@ export declare function compileEventConfigFromRaw(raw: unknown): CompiledEventCo
|
|
|
34
35
|
* 预编译 Style YAML → StyleConfig 对象
|
|
35
36
|
*/
|
|
36
37
|
export declare function compileStyleConfig(yamlStr: string): StyleConfig | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* 预编译 Data YAML(数据对象层声明)→ SomaDataConfig 对象
|
|
40
|
+
*/
|
|
41
|
+
export declare function compileDataConfig(yamlStr: string): SomaDataConfig;
|
|
42
|
+
/**
|
|
43
|
+
* 预编译 Data YAML(数据对象层声明)→ JSON 字符串
|
|
44
|
+
*/
|
|
45
|
+
export declare function precompileDataYaml(yamlStr: string): string;
|
|
37
46
|
/**
|
|
38
47
|
* 预编译任意 YAML → JSON 字符串(locale、app.config 等纯数据配置)
|
|
39
48
|
*/
|
|
@@ -6,6 +6,8 @@ export interface SomaPluginOptions {
|
|
|
6
6
|
eventSuffix?: string;
|
|
7
7
|
/** 样式配置文件后缀,默认 _style.yaml */
|
|
8
8
|
styleSuffix?: string;
|
|
9
|
+
/** 数据对象层配置文件后缀,默认 _data.yaml */
|
|
10
|
+
dataSuffix?: string;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* SOMA Vite 预编译插件
|
|
@@ -17,6 +19,7 @@ export interface SomaPluginOptions {
|
|
|
17
19
|
* - `_ui.yaml` → UiConfig 对象(parseUiConfig 预编译)
|
|
18
20
|
* - `_event.yaml` → ParsedEvent[] 数组(parseEventConfig 预编译)
|
|
19
21
|
* - `_style.yaml` → StyleConfig 对象(parseStyleConfig 预编译)
|
|
22
|
+
* - `_data.yaml` → SomaDataConfig 对象(parseDataConfig 预编译)
|
|
20
23
|
* - `locale.yaml` → Record<string, unknown>
|
|
21
24
|
* - `*.config.yaml` → 任意配置对象
|
|
22
25
|
* - 其他 `.yaml` → 通用 YAML → JS 对象
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SomaComponentDefinition } from '../../client/component/component-definition.types';
|
|
2
|
+
export declare class SomaComponentPackageError extends Error {
|
|
3
|
+
readonly packageDir: string;
|
|
4
|
+
constructor(message: string, packageDir: string);
|
|
5
|
+
}
|
|
6
|
+
/** 装载单个组件包目录 → 运行时定义(结构校验 fail fast) */
|
|
7
|
+
export declare function loadComponentPackage(packageDir: string): SomaComponentDefinition;
|
|
8
|
+
/** 扫描根目录下的全部组件包(含 contract.yaml 的一级子目录) */
|
|
9
|
+
export declare function loadComponentPackages(rootDir: string): Record<string, SomaComponentDefinition>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EjectPlan } from './plan-eject';
|
|
2
|
+
export declare class EjectApplyError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export interface ApplyEjectOptions {
|
|
5
|
+
/** 宿主根目录 */
|
|
6
|
+
hostDir: string;
|
|
7
|
+
/** 覆盖既有文件(默认 false:撞名即整体中止) */
|
|
8
|
+
force?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface EjectApplyResult {
|
|
11
|
+
/** 实际写入的文件(相对宿主根) */
|
|
12
|
+
written: string[];
|
|
13
|
+
/** 被覆盖的既有文件(force 模式下才可能非空) */
|
|
14
|
+
overwritten: string[];
|
|
15
|
+
/** 撤销这次固化:新建的删掉、覆盖的还原、空目录清理 */
|
|
16
|
+
rollback(): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 落盘一个固化计划。返回句柄带 rollback——校验不过时调它,
|
|
20
|
+
* 宿主目录回到固化之前的样子。
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyEject(plan: EjectPlan, options: ApplyEjectOptions): EjectApplyResult;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** 页面名:小写字母/数字/连字符——它同时是文件名与 URL 片段 */
|
|
2
|
+
export declare const EJECT_NAME_PATTERN: RegExp;
|
|
3
|
+
export interface EjectDeclaration {
|
|
4
|
+
html: string;
|
|
5
|
+
uiYaml: string;
|
|
6
|
+
eventYaml?: string;
|
|
7
|
+
styleYaml?: string;
|
|
8
|
+
dataYaml?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface EjectFile {
|
|
11
|
+
/** 相对宿主根目录的路径 */
|
|
12
|
+
path: string;
|
|
13
|
+
contents: string;
|
|
14
|
+
}
|
|
15
|
+
export interface EjectPlan {
|
|
16
|
+
/** 页面名(URL 片段与文件名) */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Domain 类名,已写进 html 的 data-soma-host 与 ui 的 bind.obj */
|
|
19
|
+
domainClass: string;
|
|
20
|
+
/** 固化后可访问的 URL */
|
|
21
|
+
url: string;
|
|
22
|
+
files: EjectFile[];
|
|
23
|
+
}
|
|
24
|
+
export declare class EjectPlanError extends Error {
|
|
25
|
+
}
|
|
26
|
+
/** order-board → OrderBoardPage */
|
|
27
|
+
export declare function domainClassNameOf(name: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* 规划一次固化。不碰磁盘——产出"该写哪些文件、内容是什么",
|
|
30
|
+
* 由调用方检查冲突、一次性落盘、失败时整体回滚。
|
|
31
|
+
*/
|
|
32
|
+
export declare function planEject(name: string, declaration: EjectDeclaration): EjectPlan;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface SomaAdaptiveTask<P = unknown> {
|
|
2
|
+
/** 算相:返回本帧的 plan;返回 null 表示"本帧无意见",一字节不写 */
|
|
3
|
+
decide(): P | null;
|
|
4
|
+
/** 写相:只在 plan 与上一次不同时被调用 */
|
|
5
|
+
write(plan: P): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 把若干作用域任务并入本帧的调度批次。
|
|
9
|
+
*
|
|
10
|
+
* 同帧内重复提交同一 task 以最后一次为准(task 对象自带最新状态,Set 去重即合帧)。
|
|
11
|
+
* 无 rAF 环境(SSR)直接返回,不排队也不同步执行——页面以默认档渲染即可(F-14)。
|
|
12
|
+
*/
|
|
13
|
+
export declare function scheduleAdaptiveFlush(tasks: readonly SomaAdaptiveTask<any>[]): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 迟滞带默认宽度:档位边界的 ±8%。可覆盖,但不可为负或 ≥ 1 */
|
|
2
|
+
export declare const SOMA_DEFAULT_HYSTERESIS = 0.08;
|
|
3
|
+
/**
|
|
4
|
+
* 带迟滞的档位解算。
|
|
5
|
+
*
|
|
6
|
+
* 每个边界 b 拆成两个阈值:升档须越过 `b·(1+h)`,降档须跌破 `b·(1−h)`。
|
|
7
|
+
* 于是同一取值点上最多存在两个合法档(当前与相邻),走哪个由 `prev` 决定——
|
|
8
|
+
* 这正是"往复拖拽不抖"的来源。
|
|
9
|
+
*
|
|
10
|
+
* @param value 被判定的量(通常是容器宽度);非有限数时返回 prev(ERR-04)
|
|
11
|
+
* @param bounds 升序边界数组;空数组时返回 prev(无档可分)
|
|
12
|
+
* @param prev 上一档位(0 ~ bounds.length);越界时按无迟滞裸档返回
|
|
13
|
+
* @param h 迟滞带宽度,默认 0.08
|
|
14
|
+
* @returns 档位序号,0 ~ bounds.length
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveTierWithHysteresis(value: number, bounds: readonly number[], prev: number, h?: number): number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createAdaptiveObserverPool } from './observer-pool';
|
|
2
|
+
export type { SomaAdaptiveObserverPool, SomaAdaptiveSize, SomaAdaptiveSizeCallback, } from './observer-pool';
|
|
3
|
+
export { scheduleAdaptiveFlush } from './flush-scheduler';
|
|
4
|
+
export type { SomaAdaptiveTask } from './flush-scheduler';
|
|
5
|
+
export { resolveTierWithHysteresis, SOMA_DEFAULT_HYSTERESIS } from './hysteresis';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface SomaAdaptiveSize {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}
|
|
5
|
+
export type SomaAdaptiveSizeCallback = (size: SomaAdaptiveSize) => void;
|
|
6
|
+
export interface SomaAdaptiveObserverPool {
|
|
7
|
+
/** 订阅元素尺寸;返回退订函数(幂等,重复调用不抛错) */
|
|
8
|
+
observe(target: Element, onSize: SomaAdaptiveSizeCallback): () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 取得观察者池。
|
|
12
|
+
* 多次调用复用同一实例、同一 ResizeObserver——"create" 是使用面的措辞,
|
|
13
|
+
* 语义上是取单例;调用方不需要自己去做全局缓存。
|
|
14
|
+
*/
|
|
15
|
+
export declare function createAdaptiveObserverPool(): SomaAdaptiveObserverPool;
|
|
@@ -28,6 +28,39 @@ export declare abstract class SomaPageRootBase implements SomaPageRoot {
|
|
|
28
28
|
_config: SomaAppConfig;
|
|
29
29
|
/** 由引擎注入的运行时基础设施(router / http / notify 等) */
|
|
30
30
|
_services?: SomaRuntimeServices;
|
|
31
|
+
/**
|
|
32
|
+
* 数据对象层(*_data.yaml,可选件)解析产物挂载点。
|
|
33
|
+
* bootstrap 在数据对象解析完成后注入 { 对象名: 数据 },UI 走既有
|
|
34
|
+
* `page.data.<对象>.<字段>` 绑定通道;页面无数据声明时恒为空对象。
|
|
35
|
+
* 以非枚举属性挂载:不进入页面状态序列化/快照,存量行为零变化。
|
|
36
|
+
*/
|
|
37
|
+
data: Record<string, unknown>;
|
|
38
|
+
/** 由 bootstrap 注入的数据对象重取钩子(无 *_data.yaml 声明时保持未定义) */
|
|
39
|
+
_reloadData?: () => Promise<void>;
|
|
40
|
+
constructor();
|
|
41
|
+
/**
|
|
42
|
+
* 重新执行数据对象取数(Domain 可在业务动作后调用刷新 page.data)。
|
|
43
|
+
* 页面未声明数据对象时为空操作。
|
|
44
|
+
*/
|
|
45
|
+
reloadData(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 把此刻改过的页面状态**立刻**推到界面上,不等这次事件处理结束。
|
|
48
|
+
*
|
|
49
|
+
* 什么时候需要它:一次事件 = 一次原子提交是引擎刻意的设计——中间态不闪烁,
|
|
50
|
+
* 出错时未提交的界面变更整体回滚。代价是**长任务的中途进展播不出去**:
|
|
51
|
+
* 实测 AI 生成一次 P50 约 40 秒,期间 Domain 改多少次状态,界面一次都不动,
|
|
52
|
+
* 连"生成中"三个字都不会出现,用户分不清"在想"还是"卡死"。
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* this.statusText = '正在生成…';
|
|
56
|
+
* await this.publishUi(); // ← 这一帧现在就让用户看见
|
|
57
|
+
* const result = await longTask();
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* 代价要写明白:**已经上屏的这部分不再享有失败回滚**。所以它是自愿的——
|
|
61
|
+
* 只有业务知道"这一帧值不值得让用户看见"。不调用则行为与过去完全一致。
|
|
62
|
+
*/
|
|
63
|
+
protected publishUi(): Promise<void>;
|
|
31
64
|
/**
|
|
32
65
|
* 封装页面级异步操作:自动管理 pageLoading / pageError
|
|
33
66
|
*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import type { SomaAdaptiveConfig, SomaAdaptiveVocabulary, SomaCompiledAdaptive } from '../../shared/types/adaptive.types';
|
|
3
|
+
/** 宿主根上的画像属性名:CSS 与 ui 决策的共同入口,跨包契约,改名要两边一起改 */
|
|
4
|
+
export declare const SOMA_ADAPTIVE_PROFILE_ATTR = "data-soma-adaptive-profile";
|
|
5
|
+
export interface SomaAdaptiveCompileInput {
|
|
6
|
+
config: SomaAdaptiveConfig;
|
|
7
|
+
/** 已注册词汇表;解析期已断言过声明值在表内,此处只做取值 */
|
|
8
|
+
vocabulary?: SomaAdaptiveVocabulary;
|
|
9
|
+
container: HTMLElement;
|
|
10
|
+
adapter: IContainerAdapter;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 把 `adaptive` 声明展开为确定性编译产物。
|
|
14
|
+
*
|
|
15
|
+
* 锚点存在性在此校验(解析期看不到 DOM,归属仍是 F-08):
|
|
16
|
+
* 槽与 pin 的目标锚点不可解析时快速失败,不静默丢级——
|
|
17
|
+
* 丢一级的后果是页面在某个宽度下悄悄不降级,比报错难查得多。
|
|
18
|
+
*/
|
|
19
|
+
export declare function compileAdaptive(input: SomaAdaptiveCompileInput): SomaCompiledAdaptive;
|
|
20
|
+
/**
|
|
21
|
+
* 落地编译产物:宿主根写画像属性 + 断点型级挂作用域类。
|
|
22
|
+
*
|
|
23
|
+
* 测量型执行器配置**不在此消费**——它是交给 soma-ui 接线层的数据,
|
|
24
|
+
* core 落地它就等于把组件行为搬进了引擎。
|
|
25
|
+
*/
|
|
26
|
+
export declare function applyCompiledAdaptive(compiled: SomaCompiledAdaptive, container: HTMLElement, adapter: IContainerAdapter): void;
|
|
@@ -3,19 +3,30 @@ import type { SomaScopeResolver } from '../engine/scope-resolver';
|
|
|
3
3
|
import type { SomaRuntimeManifest } from '../../shared/types/manifest.types';
|
|
4
4
|
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
5
5
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
6
|
+
import { type SomaPipeRegistry } from '../pipes/pipe-registry';
|
|
7
|
+
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
6
8
|
export interface SomaManifestCompilerInput {
|
|
7
9
|
container: HTMLElement;
|
|
8
10
|
adapter: IContainerAdapter;
|
|
9
11
|
uiConfig: UiConfig;
|
|
10
12
|
eventConfig: ParsedEvent[];
|
|
11
13
|
resolver: SomaScopeResolver;
|
|
14
|
+
/** 格式化管道注册表(缺省为内置管道集) */
|
|
15
|
+
pipes?: SomaPipeRegistry;
|
|
16
|
+
/** 阶梯词汇表(F-09);仅当 uiConfig.adaptive 存在时才被读取 */
|
|
17
|
+
adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
12
18
|
}
|
|
13
19
|
export declare class SomaManifestCompiler {
|
|
14
|
-
/** 事件编译缓存:eventConfig 不依赖 DOM,可安全缓存 */
|
|
15
|
-
private eventCache;
|
|
16
20
|
compile(input: SomaManifestCompilerInput): SomaRuntimeManifest;
|
|
17
21
|
private walkShow;
|
|
18
22
|
private compileExtendedValue;
|
|
23
|
+
/**
|
|
24
|
+
* 解析并校验展示值上的管道链(编译期白名单,未注册名 fail fast)。
|
|
25
|
+
* 无管道时原样返回(零开销路径)。
|
|
26
|
+
*/
|
|
27
|
+
private parsePipes;
|
|
28
|
+
/** 列表/对象子作用域配置的管道预校验(行内解释执行前的编译期 fail fast) */
|
|
29
|
+
private validateScopedPipes;
|
|
19
30
|
private parseSomaKey;
|
|
20
31
|
private parseConditionalPath;
|
|
21
32
|
private resolveBindingType;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { SomaComponentContract, SomaGeometryFamily } from '../../shared/types/component-contract.types';
|
|
2
|
+
import type { SomaComponentDefinition } from './component-definition.types';
|
|
3
|
+
export interface SomaAiCatalogEntry {
|
|
4
|
+
name: string;
|
|
5
|
+
layer: string;
|
|
6
|
+
version: string;
|
|
7
|
+
description: string;
|
|
8
|
+
/** 组件主几何族;由契约字段提供,旧组件由编译期迁移推导补齐。 */
|
|
9
|
+
geometry: SomaGeometryFamily;
|
|
10
|
+
props: Array<{
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
required: boolean;
|
|
14
|
+
default?: unknown;
|
|
15
|
+
values?: (string | number)[];
|
|
16
|
+
mode: 'oneway' | 'model';
|
|
17
|
+
desc: string;
|
|
18
|
+
}>;
|
|
19
|
+
emits: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
payload: Array<{
|
|
22
|
+
name: string;
|
|
23
|
+
type: string;
|
|
24
|
+
desc: string;
|
|
25
|
+
}>;
|
|
26
|
+
desc: string;
|
|
27
|
+
}>;
|
|
28
|
+
slots: Array<{
|
|
29
|
+
name: string;
|
|
30
|
+
required: boolean;
|
|
31
|
+
desc: string;
|
|
32
|
+
}>;
|
|
33
|
+
ai?: {
|
|
34
|
+
whenToUse: string;
|
|
35
|
+
whenNotToUse?: string;
|
|
36
|
+
example: string;
|
|
37
|
+
antiPatterns?: string[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 旧组件契约的迁移归族。
|
|
42
|
+
*
|
|
43
|
+
* 这是目录编译器中的一次性兼容层,不是生成链的第二份布局真源:一旦组件契约
|
|
44
|
+
* 写入 geometry,显式值永远优先。名称表只覆盖几何语义明显的公共骨架/覆盖层/消息
|
|
45
|
+
* 组件,剩余 composite/solution 默认归 surface,保证生成链不会把未知组件裸放。
|
|
46
|
+
*/
|
|
47
|
+
export declare function inferGeometryFamily(contract: Pick<SomaComponentContract, 'name' | 'layer'>): SomaGeometryFamily;
|
|
48
|
+
export interface SomaAiCatalog {
|
|
49
|
+
generatedFrom: string[];
|
|
50
|
+
entries: SomaAiCatalogEntry[];
|
|
51
|
+
markdown: string;
|
|
52
|
+
}
|
|
53
|
+
export declare function buildCatalogEntry(contract: SomaComponentContract): SomaAiCatalogEntry;
|
|
54
|
+
export interface GenerateAiCatalogOptions {
|
|
55
|
+
/** 严格模式(默认 true):缺 ai 段的契约视为目录质量线不达标,直接抛错 */
|
|
56
|
+
strict?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 设计规范正文(Markdown 片段,可选)。
|
|
59
|
+
*
|
|
60
|
+
* 传入后会被渲染成目录开头的「版式与视觉规范」章节,排在组件清单之前——
|
|
61
|
+
* 让"怎么排版才好看"和"有哪些组件"成为同一份通用资产,任何 AI 只要读目录
|
|
62
|
+
* 就同时拿到选型知识与美观知识,无需调用方再打提示词补丁。
|
|
63
|
+
*
|
|
64
|
+
* 约定:正文内部的小标题请用 `###` 起步(`##` 由本函数产出,避免抢占章节层级)。
|
|
65
|
+
* 不传则目录产物与历史完全一致。
|
|
66
|
+
*/
|
|
67
|
+
conventions?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 生成完整 AI 目录。
|
|
71
|
+
* strict 模式(默认)下缺少 ai 段的组件视为违反目录质量线(契约规则 C1 的目录侧),抛错。
|
|
72
|
+
*/
|
|
73
|
+
export declare function generateAiCatalog(defs: SomaComponentDefinition[] | Record<string, SomaComponentDefinition>, options?: GenerateAiCatalogOptions): SomaAiCatalog;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
2
|
+
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
3
|
+
import type { SomaComponentContract } from '../../shared/types/component-contract.types';
|
|
4
|
+
/** 控制器工厂上下文:props 即实例作用域根(可读取最新值),emit 向页面上抛 */
|
|
5
|
+
export interface SomaComponentControllerContext {
|
|
6
|
+
props: Record<string, unknown>;
|
|
7
|
+
emit: (name: string, payload?: unknown) => void;
|
|
8
|
+
host: HTMLElement;
|
|
9
|
+
/**
|
|
10
|
+
* 注入服务(仅自治组件,契约规范第 10 章):
|
|
11
|
+
* 按定义的 services 白名单过滤后的页面运行时服务子集(http/auth/notify/router…),
|
|
12
|
+
* 白名单外的服务不可见——组件包可信分发的安全边界。
|
|
13
|
+
*/
|
|
14
|
+
services?: Record<string, unknown>;
|
|
15
|
+
/** 请求实例重渲(控制器异步状态变更后调用,如 onMount 拉数据完成) */
|
|
16
|
+
refresh: () => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 组件控制器:组件内部行为逻辑(边界判断、派生 getter 等)。
|
|
20
|
+
* 实例作用域根上以保留键 `ctrl` 暴露:
|
|
21
|
+
* - 内部 event.yaml 以 `ctrl.method` 调用方法;
|
|
22
|
+
* - 内部 ui.yaml 以 `ctrl.getter` 绑定派生值(契约状态机的 P0 承载形态)。
|
|
23
|
+
*
|
|
24
|
+
* 生命周期约定(自治组件):控制器可暴露 `onPropsChange(): void`——props 下行更新后
|
|
25
|
+
* 触发(浮层的焦点陷阱、滚动锁定这类副作用靠它),以及 `onMount(): void | Promise<void>`
|
|
26
|
+
* 与 `onUnmount(): void`——实例引擎就绪后调用 onMount(异步完成后自动重渲),
|
|
27
|
+
* 实例销毁时调用 onUnmount(清理订阅/定时器)。
|
|
28
|
+
*/
|
|
29
|
+
export type SomaComponentControllerFactory = (ctx: SomaComponentControllerContext) => Record<string, unknown>;
|
|
30
|
+
export interface SomaComponentDefinition {
|
|
31
|
+
contract: SomaComponentContract;
|
|
32
|
+
/**
|
|
33
|
+
* 组件内部结构模板。内部锚点写 data-soma-id(与页面 DSL 一致),
|
|
34
|
+
* 展开器统一改写为 data-soma-scoped-id 实现作用域隔离。
|
|
35
|
+
* 插槽出口:<div data-soma-slot-outlet="插槽名"></div>
|
|
36
|
+
*/
|
|
37
|
+
templateHtml: string;
|
|
38
|
+
/**
|
|
39
|
+
* 内部绑定声明。作用域根为 props(约定 bind: { obj: '__component', var: 'p' }),
|
|
40
|
+
* 路径 `p.xxx` 读 prop,`ctrl.xxx` 读控制器派生值。
|
|
41
|
+
*/
|
|
42
|
+
uiConfig?: UiConfig;
|
|
43
|
+
/** 内部事件声明(针对内部锚点;funcPath 以 ctrl. 开头调用控制器) */
|
|
44
|
+
eventConfig?: ParsedEvent[];
|
|
45
|
+
controllerFactory?: SomaComponentControllerFactory;
|
|
46
|
+
/**
|
|
47
|
+
* 自治组件的服务注入白名单(契约规范第 10 章):
|
|
48
|
+
* 声明用到的页面运行时服务名(http/auth/notify/router/storage/i18n/permission…),
|
|
49
|
+
* 未声明的服务不注入。不声明本字段 = 非自治组件,ctx.services 为 undefined。
|
|
50
|
+
*/
|
|
51
|
+
services?: string[];
|
|
52
|
+
}
|
|
53
|
+
/** 保留键:实例作用域根上暴露控制器的字段名,契约禁止同名 prop */
|
|
54
|
+
export declare const SOMA_COMPONENT_CTRL_KEY = "ctrl";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SomaComponentDefinition } from './component-definition.types';
|
|
2
|
+
export declare const SOMA_COMPONENT_ATTR = "data-soma-component";
|
|
3
|
+
/**
|
|
4
|
+
* 展开完成标记;**值为该次展开分配的 scopeId**(此前是空串)。
|
|
5
|
+
* 只用 hasAttribute / `[data-soma-component-ready]` 判定的调用方不受影响。
|
|
6
|
+
* 之所以把 scopeId 挂在这里而不是新加一个宿主属性:宿主本身还是**父**作用域的锚点,
|
|
7
|
+
* 已经带着父的 data-soma-scope,两个"作用域"含义挂在同一个属性上必然要出事。
|
|
8
|
+
*/
|
|
9
|
+
export declare const SOMA_COMPONENT_READY_ATTR = "data-soma-component-ready";
|
|
10
|
+
export declare const SOMA_SLOT_ATTR = "data-soma-slot";
|
|
11
|
+
export declare const SOMA_SLOT_OUTLET_ATTR = "data-soma-slot-outlet";
|
|
12
|
+
/** 组件模板内部的子组件局部 id;页面组件管理器忽略,由父实例运行时接管。 */
|
|
13
|
+
export declare const SOMA_CHILD_COMPONENT_ID_ATTR = "data-soma-child-id";
|
|
14
|
+
export declare class SomaComponentExpandError extends Error {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class SomaComponentExpander {
|
|
18
|
+
/** 宿主是否已展开(行内实例复用节点时避免重复展开) */
|
|
19
|
+
isExpanded(host: HTMLElement): boolean;
|
|
20
|
+
/** 已展开宿主的 scopeId(未展开返回 null) */
|
|
21
|
+
scopeIdOf(host: HTMLElement): string | null;
|
|
22
|
+
/** @returns 本次展开分配的 scopeId(宿主已展开时返回既有的那个) */
|
|
23
|
+
expand(host: HTMLElement, def: SomaComponentDefinition): string;
|
|
24
|
+
private scopeAnchors;
|
|
25
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { SomaRenderEngine } from '../engine/render-engine';
|
|
2
|
+
import { SomaEventEngine } from '../engine/event-engine';
|
|
3
|
+
import { SomaScopeResolver } from '../engine/scope-resolver';
|
|
4
|
+
import type { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
5
|
+
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
6
|
+
import type { SomaRuntimeManifest } from '../../shared/types/manifest.types';
|
|
7
|
+
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
8
|
+
import type { SomaComponentDefinition } from './component-definition.types';
|
|
9
|
+
import { SomaComponentRegistry } from './component-registry';
|
|
10
|
+
/** 页面运行时接入点(activate 入参) */
|
|
11
|
+
export interface SomaComponentPageRuntime {
|
|
12
|
+
container: HTMLElement;
|
|
13
|
+
renderEngine: SomaRenderEngine;
|
|
14
|
+
eventEngine: SomaEventEngine;
|
|
15
|
+
resolver: SomaScopeResolver;
|
|
16
|
+
manifest: SomaRuntimeManifest;
|
|
17
|
+
/** 页面运行时服务表(自治组件按白名单注入用) */
|
|
18
|
+
services?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface SomaComponentManagerOptions {
|
|
21
|
+
registry: SomaComponentRegistry;
|
|
22
|
+
scheduler?: SomaScheduler;
|
|
23
|
+
diagnostics?: SomaDiagnostics;
|
|
24
|
+
/** 格式化管道注册表(实例内部绑定同样可用管道) */
|
|
25
|
+
pipeRegistry?: import('../pipes/pipe-registry').SomaPipeRegistry;
|
|
26
|
+
}
|
|
27
|
+
export declare class SomaComponentManager {
|
|
28
|
+
private readonly registry;
|
|
29
|
+
private readonly scheduler?;
|
|
30
|
+
private readonly diagnostics?;
|
|
31
|
+
private readonly pipeRegistry?;
|
|
32
|
+
private readonly expander;
|
|
33
|
+
private staticDecls;
|
|
34
|
+
private propsIndex;
|
|
35
|
+
private readonly instances;
|
|
36
|
+
private readonly hostInstances;
|
|
37
|
+
private readonly watchDisposers;
|
|
38
|
+
private page;
|
|
39
|
+
constructor(options: SomaComponentManagerOptions);
|
|
40
|
+
/**
|
|
41
|
+
* 阶段 A(页面引擎构建前):展开容器内全部静态实例的模板。
|
|
42
|
+
* 组件嵌套(插槽内容里再放组件)通过多轮扫描收敛,超过深度上限报错。
|
|
43
|
+
*/
|
|
44
|
+
prepare(container: HTMLElement, uiConfig: UiConfig): void;
|
|
45
|
+
/**
|
|
46
|
+
* 阶段 B(页面引擎构建后):标记 emit 路由、挂载静态实例、
|
|
47
|
+
* 注册 prop 源路径 watch、装配行内组件钩子。
|
|
48
|
+
*/
|
|
49
|
+
activate(page: SomaComponentPageRuntime): void;
|
|
50
|
+
destroy(): void;
|
|
51
|
+
/**
|
|
52
|
+
* 一段渲染产物离开 DOM:销毁其中的全部组件实例(含嵌套的孙实例)。
|
|
53
|
+
*
|
|
54
|
+
* 三件事必须一起做,缺一条就还是泄漏:
|
|
55
|
+
* 出强引用实例表(`instances` 是 Set,不是 WeakMap —— 它才是内存泄漏点);
|
|
56
|
+
* 出宿主索引(否则同一元素若被复用会拿到已死实例);
|
|
57
|
+
* `instance.destroy()`(onUnmount + eventEngine.destroy + renderEngine.destroy)。
|
|
58
|
+
*
|
|
59
|
+
* 子树里的实例既可能是行内实例(applyRowComponent),也可能是它们模板里的
|
|
60
|
+
* 子实例(applyChildComponent)——两者都登记在 hostInstances 上,一次遍历全收。
|
|
61
|
+
*/
|
|
62
|
+
private releaseSubtree;
|
|
63
|
+
private releaseHost;
|
|
64
|
+
private applyRowComponent;
|
|
65
|
+
private mountInstance;
|
|
66
|
+
/**
|
|
67
|
+
* 父组件模板里的真实子组件:props 在父实例作用域求值,emit 回到父实例事件清单。
|
|
68
|
+
* 这是通用组合能力;父子双方仍各自拥有独立 controller / render / event 生命周期。
|
|
69
|
+
*/
|
|
70
|
+
private applyChildComponent;
|
|
71
|
+
/**
|
|
72
|
+
* 阶段 A'(**实例编译之前**):把宿主子树里静态嵌套的子组件**结构**先展开。
|
|
73
|
+
*
|
|
74
|
+
* 只展开、不建实例。目的只有一个:让**插槽投影先于父的编译发生**。
|
|
75
|
+
* 不这么做的话,父模板写在 `<template data-soma-slot>` 里的那段内容在父编译时
|
|
76
|
+
* 还封在 template 里——querySelectorAll 不下钻 template content,
|
|
77
|
+
* SomaDomRenderer.bindEntry 找不到锚点就直接 `return null`,绑定被**整条丢弃**,
|
|
78
|
+
* 于是投影进去的文本渲染成 "--"、列表渲染成空,且全程不报错。
|
|
79
|
+
* (页面把内容投影进组件插槽之所以是通的,正是因为 prepare() 早于页面编译。
|
|
80
|
+
* 这里补的是同一件事在组件层的对称形态。)
|
|
81
|
+
*
|
|
82
|
+
* 多轮收敛:一轮展开会把插槽内容搬进 DOM,其中可能还有孙组件宿主,下一轮接着展开。
|
|
83
|
+
* 未注册的组件名在此静默跳过(不阻塞收敛),照旧由 applyChildComponent 抛错点名。
|
|
84
|
+
*/
|
|
85
|
+
private expandNestedTemplates;
|
|
86
|
+
private createChildReader;
|
|
87
|
+
/** 自治组件服务注入:按定义白名单过滤页面服务表(白名单外不可见) */
|
|
88
|
+
private filterServices;
|
|
89
|
+
/** 页面订阅了的契约 emit → 走页面 Pipeline;未订阅静默丢弃(契约规范第 4 章) */
|
|
90
|
+
private dispatchEmit;
|
|
91
|
+
/**
|
|
92
|
+
* 把页面事件清单中"实例id.契约emit名"的条目标记为 emit 路由。
|
|
93
|
+
* 覆盖静态实例与行模板内的实例(模板内容递归扫描)。
|
|
94
|
+
*/
|
|
95
|
+
private markEmitRoutes;
|
|
96
|
+
private createPageReader;
|
|
97
|
+
/** 行作用域读取:与 dom-renderer.resolveShowValue 同语义 */
|
|
98
|
+
private createRowReader;
|
|
99
|
+
/** 静态实例的 prop 源路径 watch:源变更 → 重解析 → 实例更新 */
|
|
100
|
+
private registerPropWatches;
|
|
101
|
+
}
|
|
102
|
+
interface SomaComponentInstanceOptions {
|
|
103
|
+
host: HTMLElement;
|
|
104
|
+
instanceId: string;
|
|
105
|
+
def: SomaComponentDefinition;
|
|
106
|
+
initialProps: Record<string, unknown>;
|
|
107
|
+
scheduler?: SomaScheduler;
|
|
108
|
+
diagnostics?: SomaDiagnostics;
|
|
109
|
+
pipeRegistry?: import('../pipes/pipe-registry').SomaPipeRegistry;
|
|
110
|
+
services?: Record<string, unknown>;
|
|
111
|
+
dispatchEmit: (emitName: string, payload: unknown) => void;
|
|
112
|
+
registry: SomaComponentRegistry;
|
|
113
|
+
/** 编译前的结构展开(插槽投影必须先于编译完成,见 expandNestedTemplates) */
|
|
114
|
+
expandNested: (root: HTMLElement) => void;
|
|
115
|
+
mountChild: (parent: SomaComponentInstance, host: HTMLElement, propsDecl: Record<string, unknown>, rowData: unknown) => void;
|
|
116
|
+
/** 本实例内部列表删行时的释放通道(与 mountChild 成对,见 releaseSubtree) */
|
|
117
|
+
releaseSubtree: (removedRoot: HTMLElement) => void;
|
|
118
|
+
}
|
|
119
|
+
export declare class SomaComponentInstance {
|
|
120
|
+
readonly def: SomaComponentDefinition;
|
|
121
|
+
private readonly scopeRoot;
|
|
122
|
+
private readonly renderEngine;
|
|
123
|
+
private readonly eventEngine;
|
|
124
|
+
private readonly resolver;
|
|
125
|
+
private readonly manifest;
|
|
126
|
+
private destroyed;
|
|
127
|
+
/**
|
|
128
|
+
* 模板里静态嵌套的子组件(宿主元素 + 父 uiConfig 里那份 props 声明)。
|
|
129
|
+
*
|
|
130
|
+
* 为什么要记住:父实例的作用域根是普通对象、没有响应式代理,
|
|
131
|
+
* 走的是"整树重渲"的路子,而 `props` 声明**不生成绑定**
|
|
132
|
+
* (manifest-compiler 只为 text/model/when/class/show 生成),
|
|
133
|
+
* 所以子组件不在任何 watch 里。页面层的静态实例有 registerPropWatches
|
|
134
|
+
* 补这一课,组件层此前没有对应通道——子组件因此永远停在首帧值,
|
|
135
|
+
* 父把 expanded/loading 这类受控 props 下发给子的写法在真实页面上是坏的,
|
|
136
|
+
* 而且不报错:单测只要断言 emit 上行就全绿。
|
|
137
|
+
*/
|
|
138
|
+
private readonly staticChildren;
|
|
139
|
+
private readonly mountChild;
|
|
140
|
+
constructor(options: SomaComponentInstanceOptions);
|
|
141
|
+
/**
|
|
142
|
+
* 整树重渲 + 把新的 props 推给模板里静态嵌套的子组件。
|
|
143
|
+
*
|
|
144
|
+
* 两件事必须绑在一起做:实例这一层的每一次重渲都意味着 `p.*` / `ctrl.*`
|
|
145
|
+
* 可能算出了新值,而子组件的 props 正是由这些表达式求值来的。
|
|
146
|
+
* 分开写迟早会有人新加一处 `renderEngine.render()` 却忘了刷子组件——
|
|
147
|
+
* 那种漏法不报错、只是子组件停在旧值,是最难查的一类。
|
|
148
|
+
*/
|
|
149
|
+
private rerender;
|
|
150
|
+
/** props 下行更新:浅合并后整树重渲(ctrl 派生 getter 自然重算) */
|
|
151
|
+
setProps(next: Record<string, unknown>): void;
|
|
152
|
+
getScopeRoot(): Record<string, unknown>;
|
|
153
|
+
/** 父实例作用域读取;rowData 存在时与列表行内组件的求值语义一致。 */
|
|
154
|
+
read(path: string, rowData?: unknown): unknown;
|
|
155
|
+
hasVar(segment: string): boolean;
|
|
156
|
+
/** 子组件契约 emit → 父组件 eventConfig → 父 ctrl;未订阅时静默丢弃。 */
|
|
157
|
+
dispatchChildEmit(childId: string, childHost: HTMLElement, emitName: string, payload: unknown): void;
|
|
158
|
+
destroy(): void;
|
|
159
|
+
}
|
|
160
|
+
export {};
|