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,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 {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { SomaComponentDefinition } from './component-definition.types';
|
|
2
|
+
import { type SomaAiCatalog } from './ai-catalog';
|
|
3
|
+
/** 包标识:小写字母/数字/连字符——冲突报错与来源登记都用它 */
|
|
4
|
+
export declare const PACK_NAME_PATTERN: RegExp;
|
|
5
|
+
export interface SomaComponentPackStyles {
|
|
6
|
+
/** 组件名 → 该组件独有的 CSS(首次实例化时按需注入) */
|
|
7
|
+
components?: Record<string, string>;
|
|
8
|
+
/** 共享分片名 → CSS(被多个组件依赖的资产;不要复制进组件分片) */
|
|
9
|
+
shared?: Record<string, string>;
|
|
10
|
+
/** 组件名 → 依赖的共享分片名列表 */
|
|
11
|
+
deps?: Record<string, string[]>;
|
|
12
|
+
/** 包级基座 CSS(恒定注入;克制使用——它是每个页面首屏都要付的钱) */
|
|
13
|
+
base?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SomaComponentPack {
|
|
16
|
+
/** 包标识(小写字母/数字/连字符) */
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
/** 组件名 → 运行时定义,与 createSomaUiComponents() 同构 */
|
|
20
|
+
components: Record<string, SomaComponentDefinition>;
|
|
21
|
+
/** 按需装配的样式资产(可选) */
|
|
22
|
+
styles?: SomaComponentPackStyles;
|
|
23
|
+
/** 并进组件目录的写作规范补充(可选) */
|
|
24
|
+
catalogConventions?: string;
|
|
25
|
+
meta?: {
|
|
26
|
+
description?: string;
|
|
27
|
+
homepage?: string;
|
|
28
|
+
license?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export declare class ComponentPackError extends Error {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
/** 一条生效的覆盖:谁替了谁、凭什么 */
|
|
35
|
+
export interface PackOverrideEvent {
|
|
36
|
+
name: string;
|
|
37
|
+
winner: string;
|
|
38
|
+
winnerVersion: string;
|
|
39
|
+
shadowed: Array<{
|
|
40
|
+
pack: string;
|
|
41
|
+
version: string;
|
|
42
|
+
}>;
|
|
43
|
+
/** contract = 契约上写的 overrides;allowOverride = 宿主 bootstrap 的强裁决 */
|
|
44
|
+
source: 'contract' | 'allowOverride';
|
|
45
|
+
}
|
|
46
|
+
export interface ComposePacksOptions {
|
|
47
|
+
/**
|
|
48
|
+
* 显式覆盖:组件名 → 胜出的包名。宿主的强裁决,优先级高于契约声明。
|
|
49
|
+
* 不在这张表、也没有契约声明的重名一律抛错——默认拒绝,
|
|
50
|
+
* 而不是让 spread 顺序决定渲染结果。
|
|
51
|
+
*/
|
|
52
|
+
allowOverride?: Record<string, string>;
|
|
53
|
+
/**
|
|
54
|
+
* 覆盖生效时的通知(缺省打一行 console.info,带双方版本)。
|
|
55
|
+
* 版本必须在日志里:排障时"页面上跑的是哪个 DataTable"全靠这一行。
|
|
56
|
+
* 测试与静默场景传自己的回调。
|
|
57
|
+
*/
|
|
58
|
+
onOverride?: (event: PackOverrideEvent) => void;
|
|
59
|
+
/**
|
|
60
|
+
* 按需样式装配(缺省开)。开着时返回的组件定义已经包好——首次实例化才注入 CSS。
|
|
61
|
+
* 关掉只有一种正当理由:宿主自己接管样式注入。**不要因为"在 Node 里跑"而关它**——
|
|
62
|
+
* 包装只在实例化那一刻碰 document,合成本身是纯数据操作。
|
|
63
|
+
*/
|
|
64
|
+
lazyStyles?: boolean;
|
|
65
|
+
/** CSP nonce,透传给注入的 <style> */
|
|
66
|
+
styleNonce?: string | null;
|
|
67
|
+
}
|
|
68
|
+
export interface ComposedComponentPacks {
|
|
69
|
+
/** 合成后的组件表,直接喂 bootstrap 的 components */
|
|
70
|
+
components: Record<string, SomaComponentDefinition>;
|
|
71
|
+
/** 组件名 → 来源包名。排障、目录展示、闸门报错都用它 */
|
|
72
|
+
provenance: Record<string, string>;
|
|
73
|
+
/** 合成后的按需装配样式(键已按包做过冲突检查) */
|
|
74
|
+
styles: Required<Omit<SomaComponentPackStyles, 'base'>> & {
|
|
75
|
+
base: string[];
|
|
76
|
+
};
|
|
77
|
+
/** 参与合成的包(顺序保留;目录生成用) */
|
|
78
|
+
packs: SomaComponentPack[];
|
|
79
|
+
/** 被显式覆盖的组件名 → { 胜出包, 被盖掉的包, 覆盖来源 } */
|
|
80
|
+
overrides: Record<string, {
|
|
81
|
+
winner: string;
|
|
82
|
+
shadowed: string[];
|
|
83
|
+
source: 'contract' | 'allowOverride';
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 合成多个组件包。
|
|
88
|
+
*
|
|
89
|
+
* 重名默认抛错并点名到两个包;要覆盖就在 allowOverride 里写清楚谁赢。
|
|
90
|
+
* 样式分片同理:两个包提供同名共享分片时也拦下——那通常意味着有人复制了别人的资产。
|
|
91
|
+
*/
|
|
92
|
+
export declare function composeComponentPacks(packs: readonly SomaComponentPack[], options?: ComposePacksOptions): ComposedComponentPacks;
|
|
93
|
+
/**
|
|
94
|
+
* 生成带来源标注的组件目录。
|
|
95
|
+
*
|
|
96
|
+
* 复用 generateAiCatalog(单一事实源:目录条目怎么长、ai 段怎么校验只有一处实现),
|
|
97
|
+
* 在它之上补两件包相关的事:
|
|
98
|
+
* - 每个条目盖 `pack` 戳,让人和排障工具知道这个组件是谁提供的;
|
|
99
|
+
* - 把各包的 catalogConventions 并进规范章节——第三方包对自己的组件有话要说时,
|
|
100
|
+
* 那些话必须跟着组件一起进模型的上下文,否则等于没写。
|
|
101
|
+
*
|
|
102
|
+
* 参数是合成结果而不是散装组件表:目录必须与运行时注册的是同一批组件,
|
|
103
|
+
* 中间隔一次手工拼装就迟早漂移。
|
|
104
|
+
*/
|
|
105
|
+
export declare function generatePackCatalog(composed: ComposedComponentPacks, options?: {
|
|
106
|
+
conventions?: string;
|
|
107
|
+
strict?: boolean;
|
|
108
|
+
}): SomaAiCatalog & {
|
|
109
|
+
packOf: Record<string, string>;
|
|
110
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SomaComponentDefinition } from './component-definition.types';
|
|
2
|
+
export declare class SomaComponentRegistryError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class SomaComponentRegistry {
|
|
6
|
+
private readonly defs;
|
|
7
|
+
register(def: SomaComponentDefinition): void;
|
|
8
|
+
registerAll(defs: Record<string, SomaComponentDefinition> | SomaComponentDefinition[]): void;
|
|
9
|
+
get(name: string): SomaComponentDefinition;
|
|
10
|
+
has(name: string): boolean;
|
|
11
|
+
names(): string[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SomaComponentContract } from '../../shared/types/component-contract.types';
|
|
2
|
+
export type ContractCompatIssueKind = 'prop-missing' | 'prop-type-changed' | 'prop-required-tightened' | 'prop-default-diverged' | 'emit-missing';
|
|
3
|
+
export interface ContractCompatIssue {
|
|
4
|
+
kind: ContractCompatIssueKind;
|
|
5
|
+
/** prop 名或 emit 名 */
|
|
6
|
+
member: string;
|
|
7
|
+
/** 点名到具体差异内容——报错信息是接入者读得最认真的文档 */
|
|
8
|
+
detail: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 检查 winner 覆盖 base 的契约兼容性,返回问题清单(空数组 = 兼容)。
|
|
12
|
+
*
|
|
13
|
+
* @param winner 覆盖者契约(业务包的组件)
|
|
14
|
+
* @param base 被覆盖者契约(通常是 soma-ui 的官方组件)
|
|
15
|
+
*/
|
|
16
|
+
export declare function checkOverrideCompat(winner: SomaComponentContract, base: SomaComponentContract): ContractCompatIssue[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 由 v1 示例派生一行 v2 写法;换算不出来时返回 null。
|
|
3
|
+
*
|
|
4
|
+
* 产出的是**块声明**片段(写进 `_ui.yaml` 的 `{{ … }}` 之内),
|
|
5
|
+
* html 那一行 v1 v2 通用,不重复。
|
|
6
|
+
*/
|
|
7
|
+
export declare function deriveV2Example(componentName: string, example: string): string | null;
|
|
8
|
+
/** 示例里的 html 行(v1 v2 通用),供 v2 段复用而不重复贴一遍 */
|
|
9
|
+
export declare function exampleHtmlLine(example: string): string | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SomaComponentDefinition } from './component-definition.types';
|
|
2
|
+
import type { ComposedComponentPacks } from './component-pack';
|
|
3
|
+
export interface PackStyleOptions {
|
|
4
|
+
/** CSP nonce;宿主启用严格 CSP 时必须给 */
|
|
5
|
+
nonce?: string | null;
|
|
6
|
+
}
|
|
7
|
+
/** 测试用:清空注入记录(jsdom 之间不共享 document,但模块级 Set 会跨用例残留) */
|
|
8
|
+
export declare function resetPackStyleInjection(): void;
|
|
9
|
+
/**
|
|
10
|
+
* 给合成结果里的每个组件接上按需样式。
|
|
11
|
+
*
|
|
12
|
+
* 注入顺序是**先共享分片、再组件分片**:组件分片经常覆盖共享分片里的默认值,
|
|
13
|
+
* 反过来注入会让覆盖失效——而这种失效只在"共享分片恰好晚注入"时出现,
|
|
14
|
+
* 也就是取决于页面先实例化了哪个组件,是最难复现的一类样式 bug。
|
|
15
|
+
*/
|
|
16
|
+
export declare function attachPackStyles(composed: ComposedComponentPacks, options?: PackStyleOptions): Record<string, SomaComponentDefinition>;
|
|
17
|
+
/**
|
|
18
|
+
* 注入包级基座 CSS(恒定注入,不等实例化)。
|
|
19
|
+
* 基座是每个页面首屏都要付的钱,所以接入指南里写着"克制使用";
|
|
20
|
+
* 这里按包分别盖戳,便于排查"这段全局样式是谁带来的"。
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensurePackBaseStyles(composed: ComposedComponentPacks, options?: PackStyleOptions): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SomaContainerAdapter } from '../container/SomaContainerAdapter';
|
|
2
|
+
import type { SomaAnchorStats } from '../container/IContainerAdapter';
|
|
3
|
+
export declare const SOMA_SCOPED_ID_ATTR = "data-soma-scoped-id";
|
|
4
|
+
/** 锚点的作用域归属标记(展开器写入,值为该次展开的 scopeId) */
|
|
5
|
+
export declare const SOMA_SCOPE_ATTR = "data-soma-scope";
|
|
6
|
+
export declare class SomaScopedContainerAdapter extends SomaContainerAdapter {
|
|
7
|
+
/** 本适配器认领的作用域;undefined = 认所有 scoped 锚点 */
|
|
8
|
+
private readonly scopeId?;
|
|
9
|
+
/** `[data-soma-scoped-id][data-soma-scope="X"]`,预拼避免每次查询字符串拼接 */
|
|
10
|
+
private readonly anyAnchorSelector;
|
|
11
|
+
constructor(scopeId?: string);
|
|
12
|
+
getScopeId(): string | undefined;
|
|
13
|
+
private anchorSelector;
|
|
14
|
+
findAnchor(root: ParentNode, somaId: string): HTMLElement | null;
|
|
15
|
+
findClosestAnchor(target: EventTarget | null): HTMLElement | null;
|
|
16
|
+
getAnchorId(element: HTMLElement): string | null;
|
|
17
|
+
collectAnchors(container: HTMLElement): SomaAnchorStats;
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SomaComponentPack } from './component-pack';
|
|
2
|
+
export interface VerifyPackOptions {
|
|
3
|
+
/**
|
|
4
|
+
* 关掉颜色/方向的样式检查(默认开)。
|
|
5
|
+
* 只有在包完全不带样式、或样式由宿主统一提供时才该关——关掉意味着
|
|
6
|
+
* 换肤与 RTL 的正确性没有任何自动保障。
|
|
7
|
+
*/
|
|
8
|
+
skipStyleChecks?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 自检一个组件包,返回中文问题清单(空数组 = 通过)。
|
|
12
|
+
* 与体系里其它闸门同款约定:命中即拒,清单点名到具体组件与字段。
|
|
13
|
+
*/
|
|
14
|
+
export declare function verifyComponentPack(pack: SomaComponentPack, options?: VerifyPackOptions): string[];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type SomaPipeRegistry } from '../pipes/pipe-registry';
|
|
2
|
+
import type { SomaDataConfig, SomaDataDicts } from '../../shared/types/data-config.types';
|
|
3
|
+
/** 数据对象依赖成环(`$<对象>.<字段>` 引用构成环路,无法拓扑排序) */
|
|
4
|
+
export declare class SomaDataCycleError extends Error {
|
|
5
|
+
/** 环上的对象名列表 */
|
|
6
|
+
readonly cycle: string[];
|
|
7
|
+
constructor(cycle: string[]);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* mock 通道开关:`SOMA_MOCK_ENABLED` 环境变量(Node/构建注入)
|
|
11
|
+
* 或全局标记 `globalThis.SOMA_MOCK_ENABLED`(浏览器控制台/宿主注入)。
|
|
12
|
+
*/
|
|
13
|
+
export declare function isSomaMockEnabled(): boolean;
|
|
14
|
+
/** 解析器需要的最小 http 能力(结构兼容 IHttpClient / SomaHttpService) */
|
|
15
|
+
export interface SomaDataHttpLike {
|
|
16
|
+
get<T = unknown>(url: string, config?: {
|
|
17
|
+
params?: Record<string, string>;
|
|
18
|
+
}): Promise<T>;
|
|
19
|
+
}
|
|
20
|
+
export interface SomaDataResolverOptions {
|
|
21
|
+
/** 依赖注入的 http 服务(后端接口是唯一数据边界) */
|
|
22
|
+
http: SomaDataHttpLike;
|
|
23
|
+
/**
|
|
24
|
+
* $query 读取器:注入的 query 表或取值函数;
|
|
25
|
+
* 缺省回退 location.search(复用 router-path 的读取逻辑)。
|
|
26
|
+
*/
|
|
27
|
+
query?: Record<string, string> | ((key: string) => string);
|
|
28
|
+
/** $page 读取器:Domain 实例(或返回实例的函数,取最新代理引用) */
|
|
29
|
+
page?: object | (() => object | null | undefined);
|
|
30
|
+
/** 格式化管道注册表(缺省为内置管道集;Host 自定义管道经 bootstrap 传入) */
|
|
31
|
+
pipes?: SomaPipeRegistry;
|
|
32
|
+
/** locale 表提供者(money 管道货币符号等本地化取值) */
|
|
33
|
+
locale?: () => Record<string, unknown> | undefined;
|
|
34
|
+
/** mock 通道开关(缺省读 SOMA_MOCK_ENABLED 环境) */
|
|
35
|
+
mockEnabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** 解析产物:数据对象 + 字段字典 */
|
|
38
|
+
export interface SomaDataResolveResult {
|
|
39
|
+
objects: Record<string, unknown>;
|
|
40
|
+
dicts: SomaDataDicts;
|
|
41
|
+
}
|
|
42
|
+
export declare class SomaDataObjectResolver {
|
|
43
|
+
private readonly config;
|
|
44
|
+
private readonly http;
|
|
45
|
+
private readonly queryOption?;
|
|
46
|
+
private readonly pageOption?;
|
|
47
|
+
private readonly pipes;
|
|
48
|
+
private readonly localeProvider?;
|
|
49
|
+
private readonly mockEnabled;
|
|
50
|
+
/** 拓扑执行过程中已解析的对象(供 `$<对象>.<字段>` 引用读取) */
|
|
51
|
+
private objects;
|
|
52
|
+
constructor(config: SomaDataConfig, options: SomaDataResolverOptions);
|
|
53
|
+
/**
|
|
54
|
+
* 执行整份声明的取数编排。
|
|
55
|
+
* 对象按依赖 DAG 拓扑分层:同层对象(互不依赖)并发解析;成环抛 SomaDataCycleError。
|
|
56
|
+
*/
|
|
57
|
+
resolve(): Promise<SomaDataResolveResult>;
|
|
58
|
+
/** Kahn 分层拓扑排序:返回逐层对象名(每层内部无依赖,可并发);残留节点即环 */
|
|
59
|
+
private buildTopologicalLayers;
|
|
60
|
+
private resolveObject;
|
|
61
|
+
private fetchSource;
|
|
62
|
+
/** 聚合来源结果:into 写入子键;缺省浅合并进根(非对象结果整体替换) */
|
|
63
|
+
private mergeSource;
|
|
64
|
+
/** 解析 params:`$` 引用替换为实际值 → 展平为 http query 参数表(空值参数省略) */
|
|
65
|
+
private resolveParams;
|
|
66
|
+
private resolveParamValue;
|
|
67
|
+
private readQuery;
|
|
68
|
+
private readPage;
|
|
69
|
+
/** 按 "字段路径 | 管道链" 补派生字段(复用 pipe-registry 链式执行) */
|
|
70
|
+
private applyTransform;
|
|
71
|
+
}
|
|
@@ -4,7 +4,8 @@ export interface SomaMutationRecord {
|
|
|
4
4
|
timestamp: number;
|
|
5
5
|
}
|
|
6
6
|
export interface SomaRenderRecord {
|
|
7
|
-
|
|
7
|
+
/** publish = 事务中途的自愿提交(长任务播进展) */
|
|
8
|
+
phase: 'full-render' | 'patch' | 'commit' | 'publish';
|
|
8
9
|
path?: string;
|
|
9
10
|
bindingCount: number;
|
|
10
11
|
affectedCount: number;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 三段的终点标记;起点由 startBootTimings 打下 */
|
|
2
|
+
export type SomaBootPhase = 'assetsReady' | 'compiled' | 'rendered';
|
|
3
|
+
export interface SomaBootTimings {
|
|
4
|
+
/** 段一 资产就绪:引导开始 → 页面资产到手(ms);未走到该段为 null */
|
|
5
|
+
assetsMs: number | null;
|
|
6
|
+
/** 段二 编译完成:资产到手 → 运行时清单编译完毕(ms);未走到该段为 null */
|
|
7
|
+
compileMs: number | null;
|
|
8
|
+
/** 段三 首次渲染完成:清单编译完毕 → 首帧 DOM 写完(ms);未走到该段为 null */
|
|
9
|
+
renderMs: number | null;
|
|
10
|
+
/** 引导开始 → 首次渲染完成的总耗时(ms);未走完为 null */
|
|
11
|
+
totalMs: number | null;
|
|
12
|
+
/** 三段是否都已走完(未走完的数字不可用于 p95 统计) */
|
|
13
|
+
complete: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** 开启打点并落下起点标记(重复调用即重新计时;供单测与手工排查直接使用) */
|
|
16
|
+
export declare function startBootTimings(): void;
|
|
17
|
+
/**
|
|
18
|
+
* 按需开启:仅当宿主显式置了 `globalThis.__SOMA_BOOT_TIMINGS__ = true` 才计时。
|
|
19
|
+
* 已在计时(含首屏已计完)时不重置——首屏只有一次,SPA 后续换页不应覆盖首屏数字;
|
|
20
|
+
* 要量后续页面请显式 resetBootTimings() + startBootTimings()。
|
|
21
|
+
*/
|
|
22
|
+
export declare function maybeStartBootTimings(): void;
|
|
23
|
+
/** 落下一段的终点。未开启、首屏已计完、同段重复打点,三种情况都直接返回 */
|
|
24
|
+
export declare function markBootPhase(phase: SomaBootPhase): void;
|
|
25
|
+
/** 读取三段耗时;从未开启过打点时返回 null(调用方据此区分「没量」和「量出来是 0」) */
|
|
26
|
+
export declare function readBootTimings(): SomaBootTimings | null;
|
|
27
|
+
/** 关闭打点并清空状态,回到零开销状态(单测隔离、以及要重新量一次时使用) */
|
|
28
|
+
export declare function resetBootTimings(): void;
|
|
29
|
+
/** 当前是否在计时(宿主可据此决定要不要上报) */
|
|
30
|
+
export declare function isBootTimingsEnabled(): boolean;
|