soma-core 1.3.3 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +7 -6
  2. package/app/SomaPageClient.tsx +2 -72
  3. package/app/soma/page/route.ts +17 -2
  4. package/bin/soma-lsp.cjs +1 -4
  5. package/core/build/compiler/full-manifest-builder.ts +17 -26
  6. package/core/build/compiler/html-include-expander.ts +56 -0
  7. package/core/build/compiler/page-assets.ts +26 -0
  8. package/core/build/compiler/page-declaration-compiler.ts +85 -0
  9. package/core/build/compiler/rollup-plugin-soma.ts +4 -19
  10. package/core/build/compiler/route-builder.ts +0 -2
  11. package/core/build/compiler/rspack-plugin-soma.js +1 -10
  12. package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -13
  13. package/core/build/compiler/soma-precompile.js +74 -0
  14. package/core/build/compiler/soma-precompile.ts +13 -0
  15. package/core/build/compiler/soma-rspack-yaml-loader.js +5 -11
  16. package/core/build/compiler/soma-webpack-loader.js +6 -21
  17. package/core/build/compiler/vite-plugin-soma.ts +9 -31
  18. package/core/build/component/pack-from-dir.ts +58 -0
  19. package/core/build/component/package-loader.ts +158 -12
  20. package/core/build/eject/plan-eject.ts +15 -21
  21. package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
  22. package/core/build/lsp/extra-completion.cjs +14 -8
  23. package/core/build/lsp/lsp-navigation.cjs +50 -43
  24. package/core/build/lsp/soma-declaration.cjs +85 -0
  25. package/core/build/lsp/ui-yaml-completion.cjs +98 -104
  26. package/core/build/v2/block-compile.ts +200 -0
  27. package/core/build/v2/block-loader.ts +33 -0
  28. package/core/build/v2/html-index.ts +120 -0
  29. package/core/build/v2/migrate-v1.ts +370 -0
  30. package/core/build/v2/soma-file-loader.ts +216 -0
  31. package/core/client/component/ai-catalog.ts +15 -0
  32. package/core/client/component/component-pack.ts +205 -31
  33. package/core/client/component/contract-compat.ts +132 -0
  34. package/core/client/component/example-v2.ts +132 -0
  35. package/core/client/engine/dom-renderer.ts +14 -8
  36. package/core/client/engine/reactive-proxy.ts +8 -7
  37. package/core/client/engine/soma-bootstrap.ts +23 -5
  38. package/core/client/parser/v2/namespace.ts +182 -0
  39. package/core/client/parser/v2/page-parser.ts +359 -0
  40. package/core/client/parser/v2/use-parser.ts +412 -0
  41. package/core/client/parser/value-lang.ts +340 -0
  42. package/core/client/pipes/pipe-registry.ts +1 -1
  43. package/core/client/registry/declaration-renderer.ts +17 -15
  44. package/core/client/registry/page-lifecycle.ts +1 -1
  45. package/core/client/security/attribute-presence.ts +16 -1
  46. package/core/client/theme/harmony.ts +307 -0
  47. package/core/client/theme/scene-tokens.ts +134 -0
  48. package/core/client/theme/theme-axes.ts +228 -0
  49. package/core/client/theme/theme-engine.ts +333 -73
  50. package/core/client/theme/tone-solver.ts +118 -0
  51. package/core/index.ts +74 -2
  52. package/core/server/host/published-page-assets.ts +35 -0
  53. package/core/server/host/server-page-assets.ts +33 -16
  54. package/core/server/host/soma-page-compile.ts +33 -0
  55. package/core/server/index.ts +15 -0
  56. package/core/server/registry/declaration-precompiler.ts +24 -54
  57. package/core/server/registry/page-registry-store.ts +39 -10
  58. package/core/server/registry/services/pages/Get.ts +19 -9
  59. package/core/server/registry/validation/compile-gate.ts +14 -31
  60. package/core/server/registry/validation/cross-check.ts +7 -17
  61. package/core/server/registry/validation/declaration-safety-scan.ts +2 -2
  62. package/core/shared/types/component-contract.types.ts +10 -0
  63. package/dist/core/index.cjs +2144 -155
  64. package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -4
  65. package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
  66. package/dist/types/build/compiler/page-assets.d.ts +3 -0
  67. package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
  68. package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -3
  69. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  70. package/dist/types/build/compiler/soma-precompile.d.ts +8 -0
  71. package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -10
  72. package/dist/types/build/component/pack-from-dir.d.ts +17 -0
  73. package/dist/types/build/component/package-loader.d.ts +33 -2
  74. package/dist/types/build/v2/block-compile.d.ts +28 -0
  75. package/dist/types/build/v2/block-loader.d.ts +9 -0
  76. package/dist/types/build/v2/html-index.d.ts +37 -0
  77. package/dist/types/build/v2/migrate-v1.d.ts +32 -0
  78. package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
  79. package/dist/types/client/component/component-pack.d.ts +23 -3
  80. package/dist/types/client/component/contract-compat.d.ts +16 -0
  81. package/dist/types/client/component/example-v2.d.ts +9 -0
  82. package/dist/types/client/engine/dom-renderer.d.ts +2 -0
  83. package/dist/types/client/engine/soma-bootstrap.d.ts +3 -1
  84. package/dist/types/client/parser/v2/namespace.d.ts +52 -0
  85. package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
  86. package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
  87. package/dist/types/client/parser/value-lang.d.ts +63 -0
  88. package/dist/types/client/registry/declaration-renderer.d.ts +1 -2
  89. package/dist/types/client/theme/harmony.d.ts +77 -0
  90. package/dist/types/client/theme/scene-tokens.d.ts +25 -0
  91. package/dist/types/client/theme/theme-axes.d.ts +81 -0
  92. package/dist/types/client/theme/theme-engine.d.ts +29 -1
  93. package/dist/types/client/theme/tone-solver.d.ts +47 -0
  94. package/dist/types/index.d.ts +13 -2
  95. package/dist/types/server/host/published-page-assets.d.ts +19 -0
  96. package/dist/types/server/host/server-page-assets.d.ts +1 -4
  97. package/dist/types/server/host/soma-page-compile.d.ts +7 -0
  98. package/dist/types/server/index.d.ts +3 -1
  99. package/dist/types/server/registry/declaration-precompiler.d.ts +3 -3
  100. package/dist/types/server/registry/page-registry-store.d.ts +5 -5
  101. package/dist/types/server/registry/validation/compile-gate.d.ts +2 -0
  102. package/dist/types/server/registry/validation/cross-check.d.ts +4 -4
  103. package/dist/types/shared/types/component-contract.types.d.ts +10 -0
  104. package/editor/vscode/package.json +1 -24
  105. package/global.d.ts +1 -11
  106. package/next.config.js +32 -50
  107. package/package.json +3 -2
  108. package/tailwind.config.ts +0 -1
  109. package/tsconfig.json +20 -7
  110. package/core/build/lsp/event-yaml-completion.cjs +0 -106
  111. package/core/client/host-bridge/empty-host/data/README.md +0 -17
  112. package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
@@ -13,7 +13,7 @@ export interface SomaPrecompiledPage {
13
13
  timers: ParsedTimer[];
14
14
  styleConfig?: StyleConfig;
15
15
  appConfig?: unknown;
16
- /** 数据对象层声明(*_data.yaml 预编译物化产物,可选件) */
16
+ /** 从统一声明编译出的数据对象资产。 */
17
17
  dataConfig?: SomaDataConfig;
18
18
  }
19
19
  export interface SomaPrecompiledManifest {
@@ -32,10 +32,10 @@ export declare function precompileAll(inputs: {
32
32
  appConfigYaml: string;
33
33
  pages: Array<{
34
34
  path: string;
35
+ html: string;
35
36
  uiYaml: string;
36
- eventYaml: string;
37
- styleYaml?: string;
38
- dataYaml?: string;
39
37
  appConfigYaml?: string;
38
+ externalBlocks?: ReadonlyMap<string, string>;
39
+ includes?: Readonly<Record<string, string>>;
40
40
  }>;
41
41
  }): SomaPrecompiledManifest;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 构建期 HTML include 展开。
3
+ *
4
+ * 浏览器运行时会由 SomaContainerAdapter 把 data-soma-include 的片段填入占位元素。
5
+ * 单文件 DSL 在构建期校验 data-soma-id 时也必须看到同一棵 DOM;否则共享 Shell
6
+ * 里的锚点会被误报为不存在。这里仅按调用方已经收集好的 include 名称表查找,绝不
7
+ * 从声明值拼接或读取文件路径。
8
+ */
9
+ export declare class SomaHtmlIncludeError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ /**
13
+ * 返回供声明编译器做锚点校验的逻辑 HTML。
14
+ *
15
+ * include 容器本身保留,行为与运行时的 element.innerHTML = fragment 一致;目前
16
+ * Shell 的 include 占位节点均为空。嵌套 include 递归展开并检查循环,缺失片段
17
+ * 显式失败,避免运行时出现静默空壳而构建误通过。
18
+ */
19
+ export declare function expandSomaHtmlIncludes(html: string, includes: Readonly<Record<string, string>> | undefined): string;
@@ -0,0 +1,3 @@
1
+ import type { SomaPageAssets } from '../../client/engine/soma-bootstrap';
2
+ /** 把 SOMA DSL 源声明编译成客户端挂载所需的运行时资产。 */
3
+ export declare function compilePageAssets(assets: SomaPageAssets): SomaPageAssets;
@@ -0,0 +1,33 @@
1
+ import type { SomaDataConfig } from '../../shared/types/data-config.types';
2
+ import type { ParsedEvent } from '../../shared/types/event.types';
3
+ import type { PropertyTrigger } from '../../shared/types/trigger.types';
4
+ import type { StyleConfig } from '../../shared/types/style-config.types';
5
+ import type { ParsedTimer } from '../../shared/types/timer.types';
6
+ import type { UiConfig } from '../../shared/types/ui-config.types';
7
+ export interface SomaPageDeclarationInput {
8
+ html: string;
9
+ uiYaml: string;
10
+ eventYaml?: string;
11
+ styleYaml?: string;
12
+ dataYaml?: string;
13
+ externalBlocks?: ReadonlyMap<string, string>;
14
+ /** 与浏览器运行时一致的共享 HTML 片段;仅在构建锚点校验前展开。 */
15
+ includes?: Readonly<Record<string, string>>;
16
+ }
17
+ export interface SomaRuntimeDeclarationAssets {
18
+ uiYaml: string;
19
+ eventYaml: string;
20
+ styleYaml: string;
21
+ dataYaml?: string;
22
+ }
23
+ export interface CompiledPageDeclaration {
24
+ uiConfig: UiConfig;
25
+ eventConfig: ParsedEvent[];
26
+ triggers: PropertyTrigger[];
27
+ timers: ParsedTimer[];
28
+ styleConfig?: StyleConfig;
29
+ dataConfig?: SomaDataConfig;
30
+ runtimeAssets: SomaRuntimeDeclarationAssets;
31
+ }
32
+ /** 编译一整页 SOMA DSL 声明。旧页面形状与页面侧车在唯一入口直接拒绝。 */
33
+ export declare function compilePageDeclaration(input: SomaPageDeclarationInput): CompiledPageDeclaration;
@@ -1,8 +1,5 @@
1
1
  export interface SomaRollupPluginOptions {
2
2
  uiSuffix?: string;
3
- eventSuffix?: string;
4
- styleSuffix?: string;
5
- dataSuffix?: string;
6
3
  }
7
4
  export declare function somaRollupPlugin(options?: SomaRollupPluginOptions): {
8
5
  name: string;
@@ -2,7 +2,6 @@ export interface SomaRouteEntry {
2
2
  path: string;
3
3
  htmlFile: string;
4
4
  uiFile: string;
5
- eventFile: string;
6
5
  }
7
6
  /**
8
7
  * 从 HTML 文件列表生成路由表。
@@ -14,6 +14,14 @@ import type { StyleConfig } from '../../shared/types/style-config.types';
14
14
  * 预编译 UI YAML → JSON 字符串
15
15
  */
16
16
  export declare function precompileUiYaml(yamlStr: string): string;
17
+ /**
18
+ * 单文件 bundler 的 UI 模块产物。
19
+ *
20
+ * SOMA DSL 必须拿同页 HTML 做页面级编译,单文件 loader 无权猜锚点上下文;因此
21
+ * 导出 null,让宿主转入 manifest/page-assets 路径。回退前仍完整校验 v2 容器,避免
22
+ * 旧页面形状、未闭合开关或坏 YAML 被伪装成“没有预编译产物”。
23
+ */
24
+ export declare function precompileUiModule(yamlStr: string): string;
17
25
  /**
18
26
  * 预编译 Event YAML → JSON 字符串(含 events + triggers)
19
27
  */
@@ -2,12 +2,6 @@ import type { Plugin } from 'vite';
2
2
  export interface SomaPluginOptions {
3
3
  /** UI 配置文件后缀,默认 _ui.yaml */
4
4
  uiSuffix?: string;
5
- /** 事件配置文件后缀,默认 _event.yaml */
6
- eventSuffix?: string;
7
- /** 样式配置文件后缀,默认 _style.yaml */
8
- styleSuffix?: string;
9
- /** 数据对象层配置文件后缀,默认 _data.yaml */
10
- dataSuffix?: string;
11
5
  }
12
6
  /**
13
7
  * SOMA Vite 预编译插件
@@ -16,10 +10,8 @@ export interface SomaPluginOptions {
16
10
  * 移到构建时完成。运行时直接 import 得到已解析的对象。
17
11
  *
18
12
  * 覆盖范围:
19
- * - `_ui.yaml` → UiConfig 对象(parseUiConfig 预编译)
20
- * - `_event.yaml` → ParsedEvent[] 数组(parseEventConfig 预编译)
21
- * - `_style.yaml` → StyleConfig 对象(parseStyleConfig 预编译)
22
- * - `_data.yaml` → SomaDataConfig 对象(parseDataConfig 预编译)
13
+ * - `_ui.yaml` → 校验统一声明容器并导出 null(页面级 manifest 结合 HTML 编译)
14
+ * - 页面事件、样式、数据侧车 → 明确拒绝
23
15
  * - `locale.yaml` → Record<string, unknown>
24
16
  * - `*.config.yaml` → 任意配置对象
25
17
  * - 其他 `.yaml` → 通用 YAML → JS 对象
@@ -0,0 +1,17 @@
1
+ import type { SomaComponentPack } from '../../client/component/component-pack';
2
+ import { type LoadPackagesOptions } from './package-loader';
3
+ export interface LoadPackFromDirOptions extends LoadPackagesOptions {
4
+ /** 包标识:小写字母/数字/连字符 */
5
+ name: string;
6
+ version: string;
7
+ meta?: SomaComponentPack['meta'];
8
+ /** 并进组件目录的写作规范补充(可选) */
9
+ catalogConventions?: string;
10
+ }
11
+ /**
12
+ * 扫描固定目录,产出可直接参与合成的组件包。
13
+ *
14
+ * 文件态只产组件私有分片(styles.components)——共享分片与包基座需要跨组件的
15
+ * 设计决策,仍属 TS 形态组件包的能力,不在目录约定里猜。
16
+ */
17
+ export declare function loadComponentPackFromDir(rootDir: string, options: LoadPackFromDirOptions): SomaComponentPack;
@@ -3,7 +3,38 @@ export declare class SomaComponentPackageError extends Error {
3
3
  readonly packageDir: string;
4
4
  constructor(message: string, packageDir: string);
5
5
  }
6
+ /** 扫描期的软问题:不阻断装载,但必须让人看见(都是"不报错但坏掉"的前兆) */
7
+ export interface PackScanWarning {
8
+ kind: 'page-style-filename' | 'dir-name-mismatch';
9
+ packageDir: string;
10
+ message: string;
11
+ }
12
+ export interface LoadPackagesOptions {
13
+ /**
14
+ * 警告汇总回调(缺省时汇总为单块 console.warn)。
15
+ * 刻意做成"扫描结束一次性给全部"而不是逐条打印:dev 服务器的滚动输出里,
16
+ * 逐条 warn 与"没打印"的实际效果差不多。
17
+ */
18
+ onWarning?: (warnings: PackScanWarning[]) => void;
19
+ }
20
+ /** 单目录装载的完整产物(内部形态:definition 之外还带样式与警告) */
21
+ interface PackageEntry {
22
+ definition: SomaComponentDefinition;
23
+ /** style.css 内容;无文件或空文件为 null */
24
+ css: string | null;
25
+ warnings: PackScanWarning[];
26
+ packageDir: string;
27
+ }
6
28
  /** 装载单个组件包目录 → 运行时定义(结构校验 fail fast) */
7
29
  export declare function loadComponentPackage(packageDir: string): SomaComponentDefinition;
8
- /** 扫描根目录下的全部组件包(含 contract.yaml 的一级子目录) */
9
- export declare function loadComponentPackages(rootDir: string): Record<string, SomaComponentDefinition>;
30
+ /** 装载单个组件包目录 → 定义 + 样式 + 警告(供整包装载复用) */
31
+ export declare function loadComponentPackageEntry(packageDir: string): PackageEntry;
32
+ /**
33
+ * 扫描根目录下的全部组件包(含 contract.yaml 的一级子目录)。
34
+ *
35
+ * 组件名撞车抛错并点名两个目录——扫描层与合成层同一条纪律。
36
+ */
37
+ export declare function loadComponentPackages(rootDir: string, options?: LoadPackagesOptions): Record<string, SomaComponentDefinition>;
38
+ /** 扫描并返回完整条目(定义 + 样式 + 目录),整包装载与按需样式装配的共同入口 */
39
+ export declare function scanComponentPackages(rootDir: string, options?: LoadPackagesOptions): PackageEntry[];
40
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { UiConfig } from '../../shared/types/ui-config.types';
2
+ import { type HtmlAnchorIndex } from './html-index';
3
+ import { type UseBlockAst } from '../../client/parser/v2/use-parser';
4
+ export interface CompiledSomaV2 {
5
+ /** v1 等价 UiConfig:直接交既有编译管线 */
6
+ ui: UiConfig;
7
+ /** v1 等价事件声明(DOM 事件 + timers/triggers + 组件 emit 路由) */
8
+ event: Record<string, unknown>;
9
+ /** 数据对象声明(页面级 + 各块私有,已带全局身份) */
10
+ data: Record<string, unknown>;
11
+ /** 各组件块的 AST(供生成器族与诊断消费) */
12
+ blocks: ReadonlyMap<string, UseBlockAst>;
13
+ htmlIndex: HtmlAnchorIndex;
14
+ }
15
+ export interface CompileSomaV2Input {
16
+ html: string;
17
+ uiYamlRaw: string;
18
+ /** 外置块:锚点名 → 块体原文(服务端由 loadExternalBlocks 提供) */
19
+ externalBlocks?: ReadonlyMap<string, string>;
20
+ /** 词典键集合(locale 批量段校验;缺省不校验) */
21
+ localeKeys?: ReadonlySet<string>;
22
+ }
23
+ /**
24
+ * 编译一份 v2 声明。
25
+ *
26
+ * 本函数只接受 canonical 声明,不做旧页面形状回退;旧输入会在开关校验处明确报错。
27
+ */
28
+ export declare function compileSomaV2(input: CompileSomaV2Input): CompiledSomaV2;
@@ -0,0 +1,9 @@
1
+ /** 外置块目录名:与页面同 base */
2
+ export declare function blocksDirOf(uiDir: string, base: string): string;
3
+ /**
4
+ * 扫描外置块目录 → 锚点名 → 块体原文。
5
+ *
6
+ * 只收 `.yaml`;文件名即锚点名(合法性由 loadSomaFile 统一校验,
7
+ * 那里有 HTML 索引,报错能点名"现有实例有哪些")。
8
+ */
9
+ export declare function loadExternalBlocks(uiDir: string, base: string): Map<string, string>;
@@ -0,0 +1,37 @@
1
+ /** 锚点在 HTML 中的位置信息(用于报错定位与行变量可见性判定) */
2
+ export interface HtmlAnchorInfo {
3
+ somaId: string;
4
+ /** 带 data-soma-component 时的组件名;普通锚点为 undefined */
5
+ component?: string;
6
+ /** 所在行号(1 基) */
7
+ line: number;
8
+ /** 是否位于列表行模板 <template data-soma-role="item…"> 之内 */
9
+ inRowTemplate: boolean;
10
+ /** 所属行模板的角色后缀(异构列表用;同构为 'item') */
11
+ rowRole?: string;
12
+ /**
13
+ * 所属列表锚点(位于行模板内时)。
14
+ *
15
+ * 为什么必须有它:一页有多个列表时,"行内实例挂到哪个列表的子作用域"
16
+ * 只能由 HTML 位置回答。曾经按"找到的第一个列表"挂载,cart 页两个列表
17
+ * 就把 QtyStepper 挂进了优惠券列表——不报错,只是行内组件永远收不到行数据。
18
+ */
19
+ ownerList?: string;
20
+ }
21
+ export interface HtmlAnchorIndex {
22
+ /** 全部锚点(含普通锚点) */
23
+ anchors: ReadonlyMap<string, HtmlAnchorInfo>;
24
+ /** 组件实例锚点(可作为块 id) */
25
+ instances: ReadonlySet<string>;
26
+ /** 页面根的 data-soma-host 值 */
27
+ host?: string;
28
+ /** 重复锚点 id(页面内唯一是既有铁律,此处只收集,报错由调用方给措辞) */
29
+ duplicates: readonly string[];
30
+ }
31
+ /**
32
+ * 扫描 HTML 建立锚点索引。
33
+ *
34
+ * 组件判定:同一个标签内既有 data-soma-id 又有 data-soma-component。
35
+ * 按标签切分而不是按行——属性可以换行写,按行会漏。
36
+ */
37
+ export declare function buildHtmlAnchorIndex(html: string): HtmlAnchorIndex;
@@ -0,0 +1,32 @@
1
+ import type { UiConfig } from '../../shared/types/ui-config.types';
2
+ export interface V1PageFiles {
3
+ uiYaml: Record<string, unknown>;
4
+ eventYaml?: Record<string, unknown>;
5
+ styleYaml?: Record<string, unknown>;
6
+ dataYaml?: Record<string, unknown>;
7
+ }
8
+ export interface MigrationReport {
9
+ /** 逐条变换记录(可读,用于 review 迁移结果) */
10
+ changes: string[];
11
+ /** 需要人工处理的残留(迁移器不猜) */
12
+ manual: string[];
13
+ }
14
+ export interface MigrationResult {
15
+ /** v2 文本(含 `{{` 开关) */
16
+ somaText: string;
17
+ /** 结构形态(便于测试与等价比对) */
18
+ blocks: Record<string, unknown>;
19
+ report: MigrationReport;
20
+ }
21
+ /** 迁移一页 v1 声明为 v2 块结构 */
22
+ export declare function migrateV1(files: V1PageFiles): MigrationResult;
23
+ /**
24
+ * 语义等价比对:迁移前后的作用域清单树必须一致。
25
+ *
26
+ * 比对的是**结构**而非文本——文本必然不同(那正是迁移的目的),
27
+ * 但绑定关系、作用域层级、事件路由必须逐条对得上。
28
+ */
29
+ export declare function verifyEquivalence(v1Ui: UiConfig, v2Compiled: {
30
+ ui: UiConfig;
31
+ event: Record<string, unknown>;
32
+ }, v1Event?: Record<string, unknown>): string[];
@@ -0,0 +1,45 @@
1
+ import type { HtmlAnchorIndex } from './html-index';
2
+ export declare class SomaV2ParseError extends Error {
3
+ readonly blockId?: string | undefined;
4
+ readonly line?: number | undefined;
5
+ constructor(message: string, blockId?: string | undefined, line?: number | undefined);
6
+ }
7
+ /** 页面壳块的固定 id */
8
+ export declare const PAGE_BLOCK_ID = "page";
9
+ export interface RawBlock {
10
+ blockId: string;
11
+ /** 块体(YAML 装载后的值;页面壳与组件块各自的 schema 由后续 parser 校验) */
12
+ body: Record<string, unknown>;
13
+ /** 块在 `_ui.yaml` 中的起始行(1 基,含开关行偏移) */
14
+ line: number;
15
+ /** 来源:内联块或外置文件 */
16
+ source: 'inline' | 'external';
17
+ }
18
+ export interface SomaFileLoadInput {
19
+ /** `_ui.yaml` 原文(含首尾开关行) */
20
+ uiYamlRaw: string;
21
+ /** HTML 锚点索引:块 id 合法性以它为源 */
22
+ htmlIndex: HtmlAnchorIndex;
23
+ /** 外置块文件:锚点名 → 块体原文(由 block-loader 提供) */
24
+ externalBlocks?: ReadonlyMap<string, string>;
25
+ }
26
+ interface SomaV2Container {
27
+ doc: Record<string, unknown>;
28
+ inner: string;
29
+ offset: number;
30
+ }
31
+ /**
32
+ * 只校验 v2 单文件容器本身,不依赖 HTML 锚点。
33
+ *
34
+ * Bundler 的单文件 loader 拿不到同页 HTML,只能在这里确认开关成对、内层 YAML
35
+ * 可解析且顶层是块映射;块 id 与 HTML 的对账仍由页面级 compileSomaV2 完成。
36
+ */
37
+ export declare function parseSomaV2Container(uiYamlRaw: string): SomaV2Container;
38
+ /**
39
+ * 装载 v2 声明文件:开关剥离 → YAML 装载 → 块 id 校验 → 外置块合流。
40
+ *
41
+ * 每条校验都对应一种"静默失效":写了不存在的锚点、同一实例声明两遍、
42
+ * 块挂在普通锚点上——不拦的话都表现为"这段声明没生效",而不报错。
43
+ */
44
+ export declare function loadSomaFile(input: SomaFileLoadInput): RawBlock[];
45
+ export {};
@@ -31,12 +31,31 @@ export interface SomaComponentPack {
31
31
  export declare class ComponentPackError extends Error {
32
32
  constructor(message: string);
33
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
+ }
34
46
  export interface ComposePacksOptions {
35
47
  /**
36
- * 显式覆盖:组件名 → 胜出的包名。
37
- * 不在这张表里的重名一律抛错——默认拒绝,而不是让 spread 顺序决定渲染结果。
48
+ * 显式覆盖:组件名 → 胜出的包名。宿主的强裁决,优先级高于契约声明。
49
+ * 不在这张表、也没有契约声明的重名一律抛错——默认拒绝,
50
+ * 而不是让 spread 顺序决定渲染结果。
38
51
  */
39
52
  allowOverride?: Record<string, string>;
53
+ /**
54
+ * 覆盖生效时的通知(缺省打一行 console.info,带双方版本)。
55
+ * 版本必须在日志里:排障时"页面上跑的是哪个 DataTable"全靠这一行。
56
+ * 测试与静默场景传自己的回调。
57
+ */
58
+ onOverride?: (event: PackOverrideEvent) => void;
40
59
  /**
41
60
  * 按需样式装配(缺省开)。开着时返回的组件定义已经包好——首次实例化才注入 CSS。
42
61
  * 关掉只有一种正当理由:宿主自己接管样式注入。**不要因为"在 Node 里跑"而关它**——
@@ -57,10 +76,11 @@ export interface ComposedComponentPacks {
57
76
  };
58
77
  /** 参与合成的包(顺序保留;目录生成用) */
59
78
  packs: SomaComponentPack[];
60
- /** 被显式覆盖的组件名 → { 胜出包, 被盖掉的包 } */
79
+ /** 被显式覆盖的组件名 → { 胜出包, 被盖掉的包, 覆盖来源 } */
61
80
  overrides: Record<string, {
62
81
  winner: string;
63
82
  shadowed: string[];
83
+ source: 'contract' | 'allowOverride';
64
84
  }>;
65
85
  }
66
86
  /**
@@ -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;
@@ -56,6 +56,8 @@ export declare class SomaDomRenderer {
56
56
  private rootPipeContext;
57
57
  private applyPipes;
58
58
  setModelWriteBack(fn: ModelWriteBack): void;
59
+ /** 模型回写必须在绑定表创建时附着,不能依赖首帧渲染是否走到该项。 */
60
+ private ensureModelListener;
59
61
  bindEntry(binding: SomaCompiledBinding, container: HTMLElement): BindingEntry | null;
60
62
  /**
61
63
  * 为 binding 编译专用的渲染闭包。
@@ -24,12 +24,14 @@ export interface SomaPageAssets {
24
24
  includes?: Record<string, string>;
25
25
  DomainClass: new () => SomaPageRoot;
26
26
  uiYaml?: string;
27
+ /** 仅供构建/测试入口携带的外置声明块;mount 本身不读取。 */
28
+ declarationBlocks?: ReadonlyMap<string, string>;
27
29
  eventYaml?: string;
28
30
  styleYaml?: string;
29
31
  localeYaml?: string;
30
32
  appConfigYaml?: string;
31
33
  /**
32
- * 数据对象层声明(*_data.yaml,五件套可选件)。
34
+ * 从统一声明编译出的数据对象运行时资产。
33
35
  * 提供后 bootstrap 在首渲前解析声明、异步取数并注入 page.data,
34
36
  * 完成后触发一次全量渲染;解析/取数失败不阻塞页面(data 保持空对象 + console.error)。
35
37
  * 不提供时加载路径零变化。
@@ -0,0 +1,52 @@
1
+ export declare class SomaScopeError extends Error {
2
+ readonly blockId: string;
3
+ constructor(message: string, blockId: string);
4
+ }
5
+ export type AliasKind = 'api' | 'path';
6
+ export interface AliasEntry {
7
+ kind: AliasKind;
8
+ target: string;
9
+ }
10
+ export interface BlockScope {
11
+ blockId: string;
12
+ /** 本块 data 段声明或引入的对象名 */
13
+ dataNames: ReadonlySet<string>;
14
+ /** 块作用域别名 */
15
+ aliases: ReadonlyMap<string, AliasEntry>;
16
+ /** 按 HTML 位置可见的行变量(行内组件才有) */
17
+ rowVars: ReadonlySet<string>;
18
+ /** 页面变量固定名 */
19
+ pageVar: string;
20
+ }
21
+ export interface BuildScopeInput {
22
+ blockId: string;
23
+ dataNames?: Iterable<string>;
24
+ aliasRaw?: Record<string, unknown>;
25
+ rowVars?: Iterable<string>;
26
+ }
27
+ export declare function buildBlockScope(input: BuildScopeInput): BlockScope;
28
+ export type ResolvedPath = {
29
+ kind: 'data';
30
+ full: string;
31
+ } | {
32
+ kind: 'row';
33
+ full: string;
34
+ } | {
35
+ kind: 'page';
36
+ full: string;
37
+ } | {
38
+ kind: 'literal';
39
+ };
40
+ /**
41
+ * 路径归属裁决 + 全名还原。
42
+ *
43
+ * 返回 `literal` 表示"首段不在任何作用域内"——由调用方按位置决定它是字面量
44
+ * 还是错误(props 值位允许字面量,绑定位不允许)。
45
+ */
46
+ export declare function resolvePath(raw: string, scope: BlockScope): ResolvedPath;
47
+ /** API 位的别名展开;非别名原样返回(仍须过注册表白名单,那是另一道闸门) */
48
+ export declare function resolveApiRef(raw: string, scope: BlockScope): string;
49
+ /** 供 value-lang 使用的 hasVar:判定首段是否在作用域内 */
50
+ export declare function scopeHasVar(scope: BlockScope): (segment: string) => boolean;
51
+ /** 把值里的路径整体还原为全名(供绑定位写入清单) */
52
+ export declare function expandPath(raw: string, scope: BlockScope): string;
@@ -0,0 +1,21 @@
1
+ import type { UiConfig } from '../../../shared/types/ui-config.types';
2
+ import { type BlockScope } from './namespace';
3
+ export interface PageBlockAst {
4
+ /** v1 等价 UiConfig:直接交既有编译管线 */
5
+ ui: UiConfig;
6
+ /** 事件段原文(交 pipeline-parser,形状与 v1 _event.yaml 一致) */
7
+ eventRaw: Record<string, unknown>;
8
+ /** 数据段原文(页面级共享对象,交数据对象层) */
9
+ dataRaw?: Record<string, unknown>;
10
+ scope: BlockScope;
11
+ }
12
+ export interface ParsePageInput {
13
+ body: Record<string, unknown>;
14
+ /** 页面内全部锚点(校验引用完整性用) */
15
+ anchors: ReadonlySet<string>;
16
+ /** 组件实例锚点(出现在 ui 段 = 编译错误,指路组件块) */
17
+ instances: ReadonlySet<string>;
18
+ /** 词典键(locale 批量段校验用;缺省不校验) */
19
+ localeKeys?: ReadonlySet<string>;
20
+ }
21
+ export declare function parsePageBlock(input: ParsePageInput): PageBlockAst;
@@ -0,0 +1,72 @@
1
+ import type { ExtendedShowValue } from '../../../shared/types/ui-config.types';
2
+ import { type BlockScope } from './namespace';
3
+ export interface DataObjectDecl {
4
+ localName: string;
5
+ /** 全局身份:块id.名 */
6
+ fullName: string;
7
+ from?: {
8
+ api: string;
9
+ params: Record<string, string>;
10
+ };
11
+ save?: {
12
+ api: string;
13
+ method: string;
14
+ key?: string;
15
+ trigger: string;
16
+ fields?: string[];
17
+ };
18
+ refreshMs?: number;
19
+ reloadOn?: string[];
20
+ fields?: Record<string, FieldDecl>;
21
+ }
22
+ export interface FieldDecl {
23
+ name?: string;
24
+ type: string;
25
+ values?: Record<string, string>;
26
+ permission: 'r' | 'w';
27
+ rules?: Array<Record<string, unknown>>;
28
+ }
29
+ export interface ActionDecl {
30
+ id: string;
31
+ label: string;
32
+ handler?: string;
33
+ change?: string;
34
+ confirm?: string;
35
+ permission?: string;
36
+ tone?: string;
37
+ when?: string;
38
+ disabled_reason?: string;
39
+ }
40
+ export interface UseBlockAst {
41
+ blockId: string;
42
+ /** 声明的期望组件名(与 HTML 对账后的结果) */
43
+ component?: string;
44
+ /** 整块显隐 */
45
+ when?: string;
46
+ /** 数据对象(声明与引入) */
47
+ dataObjects: DataObjectDecl[];
48
+ dataImports: Array<{
49
+ localName: string;
50
+ targetPath: string;
51
+ }>;
52
+ /** ui 段原文(Row 编译在 soma-ui 词汇层,core 只做路径还原与结构校验) */
53
+ uiRaw: Record<string, unknown>;
54
+ /** 动作定义表 */
55
+ actions: Map<string, ActionDecl>;
56
+ /** emit 路由:emit 名 → Pipeline 表达式 */
57
+ emitRoutes: Record<string, string>;
58
+ scope: BlockScope;
59
+ /** 供 v1 编译管线消费的 props 形态 */
60
+ toShowValue(): ExtendedShowValue;
61
+ }
62
+ export interface ParseUseInput {
63
+ blockId: string;
64
+ body: Record<string, unknown>;
65
+ /** HTML 中该实例的组件名(对账用) */
66
+ htmlComponent?: string;
67
+ /** 该实例可见的行变量(由 HTML 位置决定) */
68
+ rowVars?: Iterable<string>;
69
+ }
70
+ export declare function parseUseBlock(input: ParseUseInput): UseBlockAst;
71
+ /** `30s` → 30000;单位封闭 ms/s/m,无单位报错(不猜) */
72
+ export declare function parseDuration(raw: string, where: string, fail: (m: string) => never): number;