soma-core 1.3.4 → 1.4.0

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 (74) hide show
  1. package/README.md +20 -7
  2. package/app/SomaPageClient.tsx +4 -4
  3. package/app/components/SomaHostPage.tsx +5 -5
  4. package/app/components/SomaHydrationShell.tsx +4 -7
  5. package/app/globals.css +126 -3
  6. package/app/soma/page/route.ts +17 -2
  7. package/core/build/{v2 → blocks}/block-compile.ts +17 -17
  8. package/core/build/{v2/soma-file-loader.ts → blocks/block-container.ts} +28 -28
  9. package/core/build/{v2 → blocks}/block-loader.ts +1 -1
  10. package/core/build/{v2 → blocks}/html-index.ts +1 -1
  11. package/core/build/{v2/migrate-v1.ts → blocks/migrate-flat.ts} +28 -28
  12. package/core/build/compiler/host-config-sync.cjs +2 -9
  13. package/core/build/compiler/page-declaration-compiler.ts +2 -2
  14. package/core/build/compiler/soma-manifest-webpack-plugin.js +1 -1
  15. package/core/build/compiler/soma-precompile.js +17 -17
  16. package/core/build/compiler/soma-precompile.ts +2 -2
  17. package/core/client/component/ai-catalog.ts +4 -4
  18. package/core/client/component/contract-compat.ts +32 -3
  19. package/core/client/component/{example-v2.ts → example-blocks.ts} +19 -19
  20. package/core/client/engine/soma-bootstrap.ts +21 -2
  21. package/core/client/engine/style-binder.ts +1 -1
  22. package/core/client/infra/notify/DomNotifyService.ts +2 -1
  23. package/core/client/infra/notify/INotifyTheme.ts +1 -1
  24. package/core/client/parser/{v2 → blocks}/namespace.ts +1 -1
  25. package/core/client/parser/{v2 → blocks}/page-parser.ts +16 -16
  26. package/core/client/parser/{v2 → blocks}/use-parser.ts +20 -14
  27. package/core/client/parser/style-config-parser.ts +7 -7
  28. package/core/client/parser/value-lang.ts +1 -1
  29. package/core/client/registry/index.ts +8 -0
  30. package/core/client/registry/page-lifecycle.ts +1 -1
  31. package/core/client/security/attribute-presence.ts +16 -1
  32. package/core/client/theme/theme-engine.ts +42 -14
  33. package/core/client/typography/typography-base.ts +1 -1
  34. package/core/index.ts +25 -13
  35. package/core/server/host/csp-nonce-metadata.ts +1 -1
  36. package/core/server/host/published-page-assets.ts +30 -0
  37. package/core/server/host/soma-page-compile.ts +1 -1
  38. package/core/server/index.ts +2 -2
  39. package/core/server/registry/page-registry-store.ts +1 -1
  40. package/core/shared/published-page-route.ts +61 -0
  41. package/core/shared/types/adaptive.types.ts +1 -1
  42. package/core/shared/types/data-config.types.ts +30 -2
  43. package/core/shared/types/scope-manifest.types.ts +11 -15
  44. package/core/shared/types/style-config.types.ts +4 -4
  45. package/dist/cli/soma.js +15 -2
  46. package/dist/core/index.cjs +171 -77
  47. package/dist/types/build/{v2 → blocks}/block-compile.d.ts +7 -7
  48. package/dist/types/build/{v2/soma-file-loader.d.ts → blocks/block-container.d.ts} +6 -6
  49. package/dist/types/build/{v2/migrate-v1.d.ts → blocks/migrate-flat.d.ts} +6 -6
  50. package/dist/types/client/component/contract-compat.d.ts +2 -2
  51. package/dist/types/client/component/example-blocks.d.ts +9 -0
  52. package/dist/types/client/infra/notify/DomNotifyService.d.ts +2 -1
  53. package/dist/types/client/infra/notify/INotifyTheme.d.ts +1 -1
  54. package/dist/types/client/parser/{v2 → blocks}/page-parser.d.ts +2 -2
  55. package/dist/types/client/parser/{v2 → blocks}/use-parser.d.ts +1 -1
  56. package/dist/types/client/parser/style-config-parser.d.ts +1 -1
  57. package/dist/types/client/registry/index.d.ts +1 -0
  58. package/dist/types/client/theme/theme-engine.d.ts +11 -0
  59. package/dist/types/index.d.ts +8 -7
  60. package/dist/types/server/host/published-page-assets.d.ts +20 -0
  61. package/dist/types/server/index.d.ts +1 -1
  62. package/dist/types/server/registry/page-registry-store.d.ts +1 -1
  63. package/dist/types/shared/published-page-route.d.ts +21 -0
  64. package/dist/types/shared/types/data-config.types.d.ts +18 -2
  65. package/dist/types/shared/types/scope-manifest.types.d.ts +11 -11
  66. package/dist/types/shared/types/style-config.types.d.ts +4 -4
  67. package/package.json +1 -6
  68. package/tsconfig.json +20 -7
  69. package/dist/types/client/component/example-v2.d.ts +0 -9
  70. package/postcss.config.js +0 -6
  71. package/tailwind.config.ts +0 -43
  72. /package/dist/types/build/{v2 → blocks}/block-loader.d.ts +0 -0
  73. /package/dist/types/build/{v2 → blocks}/html-index.d.ts +0 -0
  74. /package/dist/types/client/parser/{v2 → blocks}/namespace.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- // v1 → v2 迁移器(REQ-005 F8.3)。
1
+ // 平铺声明 → 块声明 迁移器(REQ-005 F8.3)。
2
2
  //
3
3
  // 迁移必须是**机械的**:逐条封闭变换规则,不含判断、不猜意图。
4
4
  // 因为迁移器要跑在存量页面上,一次"聪明的推断"就是一次静默改语义。
@@ -12,7 +12,7 @@
12
12
 
13
13
  import type { BindDeclaration, UiConfig } from '../../shared/types/ui-config.types';
14
14
 
15
- export interface V1PageFiles {
15
+ export interface FlatPageFiles {
16
16
  uiYaml: Record<string, unknown>;
17
17
  eventYaml?: Record<string, unknown>;
18
18
  styleYaml?: Record<string, unknown>;
@@ -27,20 +27,20 @@ export interface MigrationReport {
27
27
  }
28
28
 
29
29
  export interface MigrationResult {
30
- /** v2 文本(含 `{{` 开关) */
30
+ /** 块声明文本(含 `{{` 开关) */
31
31
  somaText: string;
32
32
  /** 结构形态(便于测试与等价比对) */
33
33
  blocks: Record<string, unknown>;
34
34
  report: MigrationReport;
35
35
  }
36
36
 
37
- /** 迁移一页 v1 声明为 v2 块结构 */
38
- export function migrateV1(files: V1PageFiles): MigrationResult {
37
+ /** 把一页平铺声明迁移为块结构 */
38
+ export function migrateFlatToBlocks(files: FlatPageFiles): MigrationResult {
39
39
  const report: MigrationReport = { changes: [], manual: [] };
40
40
  const ui = files.uiYaml as unknown as UiConfig;
41
41
 
42
42
  if (!ui?.bind?.obj) {
43
- throw new Error('[soma-core][引擎] v1 _ui.yaml 缺少 bind.obj,无法迁移');
43
+ throw new Error('[soma-core][引擎] 平铺 _ui.yaml 缺少 bind.obj,无法迁移');
44
44
  }
45
45
 
46
46
  const pageBlock: Record<string, unknown> = { domain: ui.bind.obj };
@@ -51,12 +51,12 @@ export function migrateV1(files: V1PageFiles): MigrationResult {
51
51
  }
52
52
  if (ui.bind.var && ui.bind.var !== 'page') {
53
53
  report.manual.push(
54
- `顶层变量名是 "${ui.bind.var}" 而非 page——v2 固定为 page,`
54
+ `顶层变量名是 "${ui.bind.var}" 而非 page——块声明固定为 page,`
55
55
  + '请全局替换该页所有引用后再迁移',
56
56
  );
57
57
  }
58
58
 
59
- // watch:v1 onChange → v2 watch 段
59
+ // watch:平铺 onChange → 块 watch 段
60
60
  if (ui.bind.onChange?.length) {
61
61
  pageBlock.watch = ui.bind.onChange.map((rule) => ({
62
62
  path: rule.condition,
@@ -105,7 +105,7 @@ export function migrateV1(files: V1PageFiles): MigrationResult {
105
105
  return { somaText: renderSoma(blocks), blocks, report };
106
106
  }
107
107
 
108
- /** show 树 → 平铺 page.ui + 组件块(实例分离是 v2 的核心形状变化) */
108
+ /** show 树 → 平铺 page.ui + 组件块(实例分离是块声明的核心形状变化) */
109
109
  function flattenShow(
110
110
  show: Record<string, unknown>,
111
111
  pageUi: Record<string, unknown>,
@@ -175,9 +175,9 @@ function migrateEvents(
175
175
  const extra: Record<string, unknown> = {};
176
176
 
177
177
  /**
178
- * 列表作用域在 v1 事件里是**嵌套**的(外层键 = 列表锚点)。
179
- * v2 保持同形——曾经把它拍平成 `列表.锚点.事件` 三段,
180
- * 解析器直接拒收(DOM 事件白名单只认两段),app-demo 实迁时当场炸出来。
178
+ * 列表作用域在平铺事件里是**嵌套**的(外层键 = 列表锚点)。
179
+ * 块声明保持同形——曾经把它拍平成 `列表.锚点.事件` 三段,
180
+ * 解析器直接拒收(DOM 事件白名单只认两段),既有 Host 实迁时当场暴露。
181
181
  * 嵌套照搬,只把其中的 emit 抽走。
182
182
  */
183
183
  const walk = (node: Record<string, unknown>, target: Record<string, unknown>): void => {
@@ -234,7 +234,7 @@ function reportStyleMigration(styleYaml: Record<string, unknown>, report: Migrat
234
234
  if (transitions && Object.keys(transitions).length > 0) {
235
235
  report.manual.push(
236
236
  `_style.yaml transitions(${Object.keys(transitions).length} 项):`
237
- + '改写为 HTML class 的 Tailwind 变体(hover: / focus:)',
237
+ + '改写为 HTML class 的 CSS 变体(hover: / focus:;具体实现由宿主样式系统提供)',
238
238
  );
239
239
  }
240
240
  if (states && Object.keys(states).length > 0) {
@@ -244,7 +244,7 @@ function reportStyleMigration(styleYaml: Record<string, unknown>, report: Migrat
244
244
  }
245
245
  }
246
246
 
247
- /** 块结构 → v2 文本(YAML 风格,两空格缩进) */
247
+ /** 块结构 → 块声明文本(YAML 风格,两空格缩进) */
248
248
  function renderSoma(blocks: Record<string, unknown>): string {
249
249
  const lines: string[] = ['{{'];
250
250
  for (const [blockId, body] of Object.entries(blocks)) {
@@ -301,29 +301,29 @@ function formatScalar(value: unknown): string {
301
301
  * 但绑定关系、作用域层级、事件路由必须逐条对得上。
302
302
  */
303
303
  export function verifyEquivalence(
304
- v1Ui: UiConfig,
305
- v2Compiled: { ui: UiConfig; event: Record<string, unknown> },
306
- v1Event: Record<string, unknown> = {},
304
+ flatUi: UiConfig,
305
+ blockCompiled: { ui: UiConfig; event: Record<string, unknown> },
306
+ flatEvent: Record<string, unknown> = {},
307
307
  ): string[] {
308
308
  const issues: string[] = [];
309
309
 
310
- if (v1Ui.bind.obj !== v2Compiled.ui.bind.obj) {
311
- issues.push(`domain 不一致: ${v1Ui.bind.obj} → ${v2Compiled.ui.bind.obj}`);
310
+ if (flatUi.bind.obj !== blockCompiled.ui.bind.obj) {
311
+ issues.push(`domain 不一致: ${flatUi.bind.obj} → ${blockCompiled.ui.bind.obj}`);
312
312
  }
313
313
 
314
- const v1Paths = collectBindings(v1Ui.show ?? {}, '');
315
- const v2Paths = collectBindings(v2Compiled.ui.show ?? {}, '');
316
- for (const [anchor, expr] of v1Paths) {
317
- const after = v2Paths.get(anchor);
314
+ const flatPaths = collectBindings(flatUi.show ?? {}, '');
315
+ const blockPaths = collectBindings(blockCompiled.ui.show ?? {}, '');
316
+ for (const [anchor, expr] of flatPaths) {
317
+ const after = blockPaths.get(anchor);
318
318
  if (after === undefined) issues.push(`绑定丢失: ${anchor}`);
319
319
  else if (after !== expr) issues.push(`绑定变化: ${anchor} "${expr}" → "${after}"`);
320
320
  }
321
321
 
322
- // 两侧必须同法拍平:v2 保留列表作用域嵌套,直接比顶层键会把嵌套项误判成丢失
323
- const v1EventKeys = collectEventKeys(v1Event, '');
324
- const v2EventKeys = new Set(collectEventKeys(v2Compiled.event, ''));
325
- for (const key of v1EventKeys) {
326
- if (!v2EventKeys.has(key)) issues.push(`事件丢失: ${key}`);
322
+ // 两侧必须同法拍平:块声明保留列表作用域嵌套,直接比顶层键会把嵌套项误判成丢失
323
+ const flatEventKeys = collectEventKeys(flatEvent, '');
324
+ const blockEventKeys = new Set(collectEventKeys(blockCompiled.event, ''));
325
+ for (const key of flatEventKeys) {
326
+ if (!blockEventKeys.has(key)) issues.push(`事件丢失: ${key}`);
327
327
  }
328
328
 
329
329
  return issues;
@@ -6,7 +6,6 @@ const { resolveHostConfigRoot } = require('../../server/host/host-config-paths.c
6
6
  const SYNC_FILES = [
7
7
  'locale.yaml',
8
8
  'app.config.yaml',
9
- 'tailwind.config.js',
10
9
  ];
11
10
 
12
11
  function listEnvAppConfigFiles(configRoot) {
@@ -28,14 +27,8 @@ function syncHostConfig(hostDir, outputDir) {
28
27
  if (!fs.existsSync(target)) fs.mkdirSync(target, { recursive: true });
29
28
 
30
29
  for (const rel of SYNC_FILES) {
31
- const resolvedSrc =
32
- rel === 'tailwind.config.js'
33
- ? path.join(hostDir, rel)
34
- : path.join(configRoot, rel);
35
- const dest =
36
- rel === 'tailwind.config.js'
37
- ? path.join(target, rel)
38
- : path.join(target, 'config', rel);
30
+ const resolvedSrc = path.join(configRoot, rel);
31
+ const dest = path.join(target, 'config', rel);
39
32
  if (!fs.existsSync(resolvedSrc)) {
40
33
  skipped.push(rel);
41
34
  continue;
@@ -1,5 +1,5 @@
1
1
  import yaml from 'js-yaml';
2
- import { compileSomaV2 } from '../v2/block-compile';
2
+ import { compileSomaBlocks } from '../blocks/block-compile';
3
3
  import { expandSomaHtmlIncludes } from './html-include-expander';
4
4
  import type { SomaDataConfig } from '../../shared/types/data-config.types';
5
5
  import type { ParsedEvent } from '../../shared/types/event.types';
@@ -61,7 +61,7 @@ export function compilePageDeclaration(input: SomaPageDeclarationInput): Compile
61
61
  );
62
62
  }
63
63
 
64
- const compiled = compileSomaV2({
64
+ const compiled = compileSomaBlocks({
65
65
  html: expandSomaHtmlIncludes(input.html, input.includes),
66
66
  uiYamlRaw: input.uiYaml,
67
67
  ...(input.externalBlocks ? { externalBlocks: input.externalBlocks } : {}),
@@ -214,7 +214,7 @@ class SomaManifestWebpackPlugin {
214
214
 
215
215
  try {
216
216
  const { precompileAll } = this.jiti('./full-manifest-builder.ts');
217
- const { loadExternalBlocks } = this.jiti('../v2/block-loader.ts');
217
+ const { loadExternalBlocks } = this.jiti('../blocks/block-loader.ts');
218
218
  const sources = getSomaAssetSources(hostDir);
219
219
  const pageEntries = collectPageEntries(sources);
220
220
  const includes = collectIncludes(sources);
@@ -3871,7 +3871,7 @@ function parseBase(raw, path) {
3871
3871
  validateSomaId(somaId, `${path}.${somaId}`);
3872
3872
  if (typeof classes !== "string") {
3873
3873
  throw new SomaStyleConfigError(
3874
- `base \u7684\u503C\u5FC5\u987B\u662F Tailwind \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(classes)}`,
3874
+ `base \u7684\u503C\u5FC5\u987B\u662F CSS \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(classes)}`,
3875
3875
  `${path}.${somaId}`
3876
3876
  );
3877
3877
  }
@@ -3908,7 +3908,7 @@ function parseStateRule(raw, path) {
3908
3908
  }
3909
3909
  if (!obj.apply || typeof obj.apply !== "string") {
3910
3910
  throw new SomaStyleConfigError(
3911
- `apply \u5FC5\u987B\u662F\u975E\u7A7A Tailwind \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(obj.apply)}`,
3911
+ `apply \u5FC5\u987B\u662F\u975E\u7A7A CSS \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(obj.apply)}`,
3912
3912
  path
3913
3913
  );
3914
3914
  }
@@ -3958,7 +3958,7 @@ function parseTransition(raw, somaId, path) {
3958
3958
  }
3959
3959
  if (!obj.apply || typeof obj.apply !== "string") {
3960
3960
  throw new SomaStyleConfigError(
3961
- `apply \u5FC5\u987B\u662F\u975E\u7A7A Tailwind \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(obj.apply)}`,
3961
+ `apply \u5FC5\u987B\u662F\u975E\u7A7A CSS \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(obj.apply)}`,
3962
3962
  path
3963
3963
  );
3964
3964
  }
@@ -4051,7 +4051,7 @@ function parseTheme(raw, themeName, path) {
4051
4051
  } else {
4052
4052
  if (typeof value !== "string") {
4053
4053
  throw new SomaStyleConfigError(
4054
- `\u4E3B\u9898\u57FA\u7840\u8986\u76D6\u7684\u503C\u5FC5\u987B\u662F Tailwind \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(value)}`,
4054
+ `\u4E3B\u9898\u57FA\u7840\u8986\u76D6\u7684\u503C\u5FC5\u987B\u662F CSS \u7C7B\u540D\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C: ${JSON.stringify(value)}`,
4055
4055
  `${path}.${key}`
4056
4056
  );
4057
4057
  }
@@ -4564,14 +4564,14 @@ function parseDataConfig(raw) {
4564
4564
  return { objects };
4565
4565
  }
4566
4566
 
4567
- // core/build/v2/soma-file-loader.ts
4568
- var SomaV2ParseError = class extends Error {
4567
+ // core/build/blocks/block-container.ts
4568
+ var SomaBlockParseError = class extends Error {
4569
4569
  constructor(message, blockId, line) {
4570
4570
  const where = blockId ? `\uFF08\u5757: ${blockId}${line ? `\uFF0C\u7B2C ${line} \u884C` : ""}\uFF09` : "";
4571
4571
  super(`[soma-core][\u5F15\u64CE] ${message}${where}`);
4572
4572
  this.blockId = blockId;
4573
4573
  this.line = line;
4574
- this.name = "SomaV2ParseError";
4574
+ this.name = "SomaBlockParseError";
4575
4575
  }
4576
4576
  };
4577
4577
  function stripSwitch(uiYamlRaw) {
@@ -4581,52 +4581,52 @@ function stripSwitch(uiYamlRaw) {
4581
4581
  const text = lines[i].trim();
4582
4582
  if (text === "" || text.startsWith("#")) continue;
4583
4583
  if (text !== "{{") {
4584
- throw new SomaV2ParseError("v2 \u58F0\u660E\u5FC5\u987B\u4EE5 `{{` \u5F00\u5173\u884C\u5F00\u5934");
4584
+ throw new SomaBlockParseError("\u5757\u58F0\u660E\u5FC5\u987B\u4EE5 `{{` \u5F00\u5173\u884C\u5F00\u5934");
4585
4585
  }
4586
4586
  openIndex = i;
4587
4587
  break;
4588
4588
  }
4589
4589
  if (openIndex === -1) {
4590
- throw new SomaV2ParseError("\u6587\u4EF6\u4E3A\u7A7A\u6216\u53EA\u6709\u6CE8\u91CA\uFF0C\u627E\u4E0D\u5230 `{{` \u5F00\u5173\u884C");
4590
+ throw new SomaBlockParseError("\u6587\u4EF6\u4E3A\u7A7A\u6216\u53EA\u6709\u6CE8\u91CA\uFF0C\u627E\u4E0D\u5230 `{{` \u5F00\u5173\u884C");
4591
4591
  }
4592
4592
  let closeIndex = -1;
4593
4593
  for (let i = lines.length - 1; i > openIndex; i -= 1) {
4594
4594
  const text = lines[i].trim();
4595
4595
  if (text === "") continue;
4596
4596
  if (text !== "}}") {
4597
- throw new SomaV2ParseError("v2 \u58F0\u660E\u5FC5\u987B\u4EE5 `}}` \u6536\u53E3\u884C\u7ED3\u5C3E\uFF08\u5F00\u5173\u6210\u5BF9\uFF0C\u6574\u6587\u4EF6\u4E00\u5BF9\uFF09");
4597
+ throw new SomaBlockParseError("\u5757\u58F0\u660E\u5FC5\u987B\u4EE5 `}}` \u6536\u53E3\u884C\u7ED3\u5C3E\uFF08\u5F00\u5173\u6210\u5BF9\uFF0C\u6574\u6587\u4EF6\u4E00\u5BF9\uFF09");
4598
4598
  }
4599
4599
  closeIndex = i;
4600
4600
  break;
4601
4601
  }
4602
4602
  if (closeIndex === -1) {
4603
- throw new SomaV2ParseError("`{{` \u5F00\u5173\u672A\u95ED\u5408\u2014\u2014\u7F3A\u5C11 `}}` \u6536\u53E3\u884C");
4603
+ throw new SomaBlockParseError("`{{` \u5F00\u5173\u672A\u95ED\u5408\u2014\u2014\u7F3A\u5C11 `}}` \u6536\u53E3\u884C");
4604
4604
  }
4605
4605
  return {
4606
4606
  inner: lines.slice(openIndex + 1, closeIndex).join("\n"),
4607
4607
  offset: openIndex + 1
4608
4608
  };
4609
4609
  }
4610
- function parseSomaV2Container(uiYamlRaw) {
4610
+ function parseSomaBlockContainer(uiYamlRaw) {
4611
4611
  const { inner, offset } = stripSwitch(uiYamlRaw);
4612
4612
  let doc;
4613
4613
  try {
4614
4614
  doc = yaml.load(inner);
4615
4615
  } catch (error) {
4616
- throw new SomaV2ParseError(`YAML \u89E3\u6790\u5931\u8D25: ${error.message}`);
4616
+ throw new SomaBlockParseError(`YAML \u89E3\u6790\u5931\u8D25: ${error.message}`);
4617
4617
  }
4618
4618
  if (doc === null || doc === void 0) {
4619
4619
  return { doc: {}, inner, offset };
4620
4620
  }
4621
4621
  if (typeof doc !== "object" || Array.isArray(doc)) {
4622
- throw new SomaV2ParseError("\u5F00\u5173\u5185\u5FC5\u987B\u662F\u5757\u6620\u5C04\uFF08\u9876\u5C42\u952E = \u5757 id\uFF09");
4622
+ throw new SomaBlockParseError("\u5F00\u5173\u5185\u5FC5\u987B\u662F\u5757\u6620\u5C04\uFF08\u9876\u5C42\u952E = \u5757 id\uFF09");
4623
4623
  }
4624
4624
  for (const [blockId, body] of Object.entries(doc)) {
4625
4625
  if (body === null || body === void 0) {
4626
- throw new SomaV2ParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId);
4626
+ throw new SomaBlockParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId);
4627
4627
  }
4628
4628
  if (typeof body !== "object" || Array.isArray(body)) {
4629
- throw new SomaV2ParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId);
4629
+ throw new SomaBlockParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId);
4630
4630
  }
4631
4631
  }
4632
4632
  return { doc, inner, offset };
@@ -4640,7 +4640,7 @@ function precompileUiYaml(yamlStr) {
4640
4640
  return JSON.stringify(uiConfig);
4641
4641
  }
4642
4642
  function precompileUiModule(yamlStr) {
4643
- parseSomaV2Container(yamlStr);
4643
+ parseSomaBlockContainer(yamlStr);
4644
4644
  return "null";
4645
4645
  }
4646
4646
  function precompileEventYaml(yamlStr) {
@@ -7,7 +7,7 @@ import { parseEventConfig } from '../../client/parser/pipeline-parser';
7
7
  import { splitEventConfigRaw } from '../../client/parser/trigger-parser';
8
8
  import { parseStyleConfig } from '../../client/parser/style-config-parser';
9
9
  import { parseDataConfig } from '../../client/parser/data-config-parser';
10
- import { parseSomaV2Container } from '../v2/soma-file-loader';
10
+ import { parseSomaBlockContainer } from '../blocks/block-container';
11
11
  import type { SomaDataConfig } from '../../shared/types/data-config.types';
12
12
  import type { UiConfig } from '../../shared/types/ui-config.types';
13
13
  import type { ParsedEvent } from '../../shared/types/event.types';
@@ -50,7 +50,7 @@ export function precompileUiYaml(yamlStr: string): string {
50
50
  * 旧页面形状、未闭合开关或坏 YAML 被伪装成“没有预编译产物”。
51
51
  */
52
52
  export function precompileUiModule(yamlStr: string): string {
53
- parseSomaV2Container(yamlStr);
53
+ parseSomaBlockContainer(yamlStr);
54
54
  return 'null';
55
55
  }
56
56
 
@@ -6,7 +6,7 @@
6
6
  //
7
7
  // 纪律(D10):目录永远从契约生成,禁止手工维护第二份副本。
8
8
 
9
- import { deriveV2Example } from './example-v2';
9
+ import { deriveBlockExample } from './example-blocks';
10
10
  import type {
11
11
  SomaComponentContract,
12
12
  SomaGeometryFamily,
@@ -247,15 +247,15 @@ function renderMarkdown(entries: SomaAiCatalogEntry[], conventions?: string): st
247
247
  lines.push(entry.ai.example.trimEnd());
248
248
  lines.push('```');
249
249
 
250
- // DSL v2 写法(由 v1 示例机械派生,见 example-v2.ts)。
250
+ // 块写法(由平铺示例机械派生,见 example-blocks.ts)。
251
251
  // 派生而不是在 315 份契约里各写一份:契约仍是单一真源,
252
252
  // 两份示例不可能不一致——因为后者是前者的函数
253
- const v2 = deriveV2Example(entry.name, entry.ai.example);
253
+ const v2 = deriveBlockExample(entry.name, entry.ai.example);
254
254
  if (v2) {
255
255
  lines.push('');
256
256
  // 目录会被压成裸文本喂给模型(围栏与多余空行都剥掉),
257
257
  // 所以这行标注必须自带上下文:不能靠代码块的视觉分隔来区分两种写法
258
- lines.push('v2(html 同上,_ui.yaml 改块声明):');
258
+ lines.push('块写法(html 同上,_ui.yaml 改为块声明):');
259
259
  lines.push('```');
260
260
  lines.push(v2);
261
261
  lines.push('```');
@@ -13,7 +13,9 @@
13
13
  // props 缺失/类型变 → 页面照常传值,组件读不到,白屏或空块;
14
14
  // 可选变必填 → 存量页面没传那个 prop,覆盖后变成缺必填;
15
15
  // default 变化 → 最阴的一种:结构完全兼容,但存量页面没传该 prop 的地方
16
- // 行为静默改变(分页大小从 20 变 50 这种),任何结构检查都抓不到。
16
+ // 行为静默改变(分页大小从 20 变 50 这种),任何结构检查都抓不到;
17
+ // 插槽缺失/收紧 → 唯一会把问题推迟成**页面级崩溃**的一类:
18
+ // 投影内容在挂载时被判为未知槽名,直接抛 SomaComponentExpandError。
17
19
 
18
20
  import type {
19
21
  SomaComponentContract,
@@ -25,11 +27,13 @@ export type ContractCompatIssueKind =
25
27
  | 'prop-type-changed'
26
28
  | 'prop-required-tightened'
27
29
  | 'prop-default-diverged'
28
- | 'emit-missing';
30
+ | 'emit-missing'
31
+ | 'slot-missing'
32
+ | 'slot-required-tightened';
29
33
 
30
34
  export interface ContractCompatIssue {
31
35
  kind: ContractCompatIssueKind;
32
- /** prop 名或 emit 名 */
36
+ /** prop / emit / slot 名 */
33
37
  member: string;
34
38
  /** 点名到具体差异内容——报错信息是接入者读得最认真的文档 */
35
39
  detail: string;
@@ -99,6 +103,31 @@ export function checkOverrideCompat(
99
103
  }
100
104
  }
101
105
 
106
+ // 插槽(REQ-008 D-5 补洞):此前闸门只查 props + emits,插槽整个漏在管辖外。
107
+ // 漏掉的代价比另两类更重——页面投影进插槽的内容不会消失,它会在**运行时**
108
+ // 被 component-expander 判为「声明了组件不认识的槽名」而抛 SomaComponentExpandError,
109
+ // 整页崩。也就是说:本该在合成期挡下的问题,被推迟成了页面级崩溃。
110
+ const winnerSlots = winner.slots ?? {};
111
+ for (const [name, baseSlot] of Object.entries(base.slots ?? {})) {
112
+ const winnerSlot = winnerSlots[name];
113
+ if (!winnerSlot) {
114
+ issues.push({
115
+ kind: 'slot-missing',
116
+ member: name,
117
+ detail: `缺少插槽 "${name}"——存量页面仍在往这个槽投影内容,`
118
+ + '覆盖后不是少一块内容,而是挂载时直接抛 SomaComponentExpandError(整页崩)',
119
+ });
120
+ continue;
121
+ }
122
+ if (winnerSlot.required === true && baseSlot.required !== true) {
123
+ issues.push({
124
+ kind: 'slot-required-tightened',
125
+ member: name,
126
+ detail: `插槽 "${name}" 从可选收紧为必填——存量页面没给这个槽的地方会在挂载时抛错`,
127
+ });
128
+ }
129
+ }
130
+
102
131
  return issues;
103
132
  }
104
133
 
@@ -1,23 +1,23 @@
1
- // 契约示例的 v2 派生(REQ-005 F8.4 生态再生)。
1
+ // 契约示例的块写法派生(REQ-005 F8.4 生态再生)。
2
2
  //
3
- // 315 份契约的 `ai.example` 是 v1 三行式(html / ui / event)。DSL v2 落地后
4
- // AI 需要看到 v2 写法,否则它学到的永远是旧格式——而"生成质量的知识沉在
3
+ // 315 份契约的 `ai.example` 是平铺三行式(html / ui / event)。块声明落地后
4
+ // AI 需要看到块写法,否则它学到的永远是旧格式——而"生成质量的知识沉在
5
5
  // 通用资产里"这条工程铁律,说的就是这种地方。
6
6
  //
7
7
  // ── 为什么是派生而不是改 315 个源文件 ──────────────────────────────────
8
- // 改源文件要动 315 处,且从此 v1/v2 两份示例并存、各自演化、必然漂移。
9
- // 派生只有一处实现:契约仍是单一真源,v2 示例由 v1 示例机械换算而来,
8
+ // 改源文件要动 315 处,且从此两份示例并存、各自演化、必然漂移。
9
+ // 派生只有一处实现:契约仍是单一真源,块写法示例由平铺示例机械换算而来,
10
10
  // 两者不可能不一致——因为后者是前者的函数。
11
11
  //
12
- // ── 换算规则(v2 的两处结构差异)─────────────────────────────────────
13
- // 1. 组件实例**自成顶层块**(v2 第一公理:"组件是声明的第一公民"):
14
- // v1 的 `锚点: { props: {…} }` → v2 的 `锚点:` 块 + `component:` + `ui:`;
12
+ // ── 换算规则(块写法的两处结构差异)─────────────────────────────────────
13
+ // 1. 组件实例**自成顶层块**(块声明第一公理:"组件是声明的第一公民"):
14
+ // 平铺的 `锚点: { props: {…} }` → 块写法的 `锚点:` 块 + `component:` + `ui:`;
15
15
  // 2. 实例的 emit 路由并进块内的 `event.on`,不再写在页面级事件文件里。
16
16
  //
17
- // 换不出来的(示例本身不是标准三行式)就不产 v2 行——宁可少给一份示例,
17
+ // 换不出来的(示例本身不是标准三行式)就不产块写法行——宁可少给一份示例,
18
18
  // 也不要给一份**看着对、抄过去装载不进去**的示例。
19
19
 
20
- /** v1 示例的三行前缀 */
20
+ /** 平铺示例的三行前缀 */
21
21
  const HTML_PREFIX = 'html:';
22
22
  const UI_PREFIX = 'ui:';
23
23
  const EVENT_PREFIX = 'event:';
@@ -56,14 +56,14 @@ function lineAfter(lines: readonly string[], prefix: string): string | null {
56
56
  }
57
57
 
58
58
  /**
59
- * 解析 v1 示例的 ui / event 两行。
59
+ * 解析平铺示例的 ui / event 两行。
60
60
  *
61
61
  * 只认最规整的那一种形状:`锚点: { props: { … } }`。
62
62
  * 示例写得更花的(多锚点、嵌套 show、列表作用域)一律返回 null——
63
- * 那些形状换算成 v2 需要真的理解作用域,不是字符串搬运;
63
+ * 那些形状换算成块写法需要真的理解作用域,不是字符串搬运;
64
64
  * 猜错了产出的是能骗过肉眼、装载器却拒收的示例。
65
65
  */
66
- function parseV1Example(example: string): ParsedExample | null {
66
+ function parseFlatExample(example: string): ParsedExample | null {
67
67
  const lines = example.split('\n');
68
68
  const ui = lineAfter(lines, UI_PREFIX);
69
69
  if (!ui) return null;
@@ -99,16 +99,16 @@ function parseV1Example(example: string): ParsedExample | null {
99
99
  }
100
100
 
101
101
  /**
102
- * 由 v1 示例派生一行 v2 写法;换算不出来时返回 null。
102
+ * 由平铺示例派生一行块写法;换算不出来时返回 null。
103
103
  *
104
104
  * 产出的是**块声明**片段(写进 `_ui.yaml` 的 `{{ … }}` 之内),
105
- * html 那一行 v1 v2 通用,不重复。
105
+ * html 那一行两种写法通用,不重复。
106
106
  */
107
- export function deriveV2Example(componentName: string, example: string): string | null {
108
- const parsed = parseV1Example(example);
107
+ export function deriveBlockExample(componentName: string, example: string): string | null {
108
+ const parsed = parseFlatExample(example);
109
109
  if (!parsed) return null;
110
110
 
111
- // props 逐字与 v1 的 ui 行相同——**不重复贴一遍**,写成"同上"。
111
+ // props 逐字与平铺的 ui 行相同——**不重复贴一遍**,写成"同上"。
112
112
  //
113
113
  // 目录是喂给模型的,字节即成本(体积预算闸门盯着最大单分片)。
114
114
  // 重贴一份 props 对 AI 没有增量信息:它要学的是**结构差异**
@@ -126,7 +126,7 @@ export function deriveV2Example(componentName: string, example: string): string
126
126
  return lines.join('\n');
127
127
  }
128
128
 
129
- /** 示例里的 html 行(v1 v2 通用),供 v2 段复用而不重复贴一遍 */
129
+ /** 示例里的 html 行(两种写法通用),供块写法段复用而不重复贴一遍 */
130
130
  export function exampleHtmlLine(example: string): string | null {
131
131
  return lineAfter(example.split('\n'), HTML_PREFIX);
132
132
  }
@@ -696,8 +696,27 @@ export class SomaBootstrap {
696
696
  this.componentManager?.destroy();
697
697
  this.componentManager = null;
698
698
 
699
- // Host 级注册(构造选项)+ 页面级资产,页面同名覆盖
700
- const defs = { ...this.hostComponents, ...(assets.components ?? {}) };
699
+ // Host 级注册(构造选项)+ 页面级资产。
700
+ //
701
+ // 页面同名仍然胜出(既有行为,不改),但**不再静默**:组件包体系为重名建了三道闸门
702
+ // (`composeComponentPacks` 重名默认拒收、provenance 追溯、覆盖前过契约兼容检查),
703
+ // 而这里曾经是一句 `{ ...host, ...page }` ——对象 spread 把三道闸门全绕过去了,
704
+ // 「页面上用的到底是哪个组件」只能靠 spread 顺序猜。这正是 CLAUDE.md §4 点名禁止的写法。
705
+ //
706
+ // 这一层拿不到包元数据(defs 是已合成的定义表),做不了契约兼容判定;
707
+ // 能做也必须做的是:**让覆盖可见**。撞名走 validation 轨记名,排查时有据可查。
708
+ const pageComponents = assets.components ?? {};
709
+ const shadowed = Object.keys(pageComponents)
710
+ .filter((name) => Object.hasOwn(this.hostComponents, name));
711
+ if (shadowed.length > 0) {
712
+ this.diagnostics.recordValidation(
713
+ 'warning',
714
+ `[组件覆盖] 页面级资产覆盖了 Host 级同名组件:${shadowed.join('、')}。`
715
+ + '页面级胜出是既定行为,但覆盖不应是意外——'
716
+ + '若非本意,请改名或在组件包侧用 overrides / allowOverride 显式表达裁决。',
717
+ );
718
+ }
719
+ const defs = { ...this.hostComponents, ...pageComponents };
701
720
  if (Object.keys(defs).length === 0) {
702
721
  return;
703
722
  }
@@ -36,7 +36,7 @@ const BUILTIN_THEME_VARS: Record<string, Record<string, string>> = {
36
36
  },
37
37
  };
38
38
 
39
- /** _style.yaml 主题切换时注入 CSS 变量(样式类仍由 Tailwind 提供) */
39
+ /** _style.yaml 主题切换时注入 CSS 变量(样式类由宿主样式系统提供) */
40
40
  function applyThemeVariables(
41
41
  themeName: string | null,
42
42
  themeConfig?: ThemeConfig,
@@ -5,7 +5,8 @@ import type { ToastTheme } from './INotifyTheme';
5
5
  const ROOT_ID = 'soma-toast-root';
6
6
 
7
7
  /**
8
- * 浏览器端通知:样式类名由宿主 app.config.yaml → notify.toast 注入(Tailwind)。
8
+ * 浏览器端通知:样式类名由宿主 app.config.yaml → notify.toast 注入;
9
+ * core 不关心这些类名由哪一种 CSS 工具链或业务样式表提供。
9
10
  */
10
11
  export class DomNotifyService extends DefaultNotifyService {
11
12
  private root: HTMLElement | null = null;
@@ -1,6 +1,6 @@
1
1
  import type { NotifyLevel } from './INotifyService';
2
2
 
3
- /** 宿主在 app.config.yaml 中声明的 Toast Tailwind 类名 */
3
+ /** 宿主在 app.config.yaml 中声明的 Toast CSS 类名 */
4
4
  export interface ToastTheme {
5
5
  root: string;
6
6
  item: string;
@@ -1,4 +1,4 @@
1
- // v2 解析 · 块作用域与命名空间(REQ-005 F1.3 / F1.4)。
1
+ // 块解析 · 块作用域与命名空间(REQ-005 F1.3 / F1.4)。
2
2
  //
3
3
  // 块即命名空间:块内 `data:` 声明的对象名,全局身份自动是 `块id.名`——
4
4
  // 书写零前缀,跨块显式全名。两个组件都叫 `orders` 因此互不相干。