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.
- package/README.md +7 -6
- package/app/SomaPageClient.tsx +2 -72
- package/app/soma/page/route.ts +17 -2
- package/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +17 -26
- 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 -19
- 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 -13
- package/core/build/compiler/soma-precompile.js +74 -0
- package/core/build/compiler/soma-precompile.ts +13 -0
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -11
- package/core/build/compiler/soma-webpack-loader.js +6 -21
- package/core/build/compiler/vite-plugin-soma.ts +9 -31
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +158 -12
- package/core/build/eject/plan-eject.ts +15 -21
- 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/component/ai-catalog.ts +15 -0
- package/core/client/component/component-pack.ts +205 -31
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -0
- package/core/client/engine/dom-renderer.ts +14 -8
- package/core/client/engine/reactive-proxy.ts +8 -7
- package/core/client/engine/soma-bootstrap.ts +23 -5
- 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 +1 -1
- package/core/client/registry/declaration-renderer.ts +17 -15
- package/core/client/registry/page-lifecycle.ts +1 -1
- package/core/client/security/attribute-presence.ts +16 -1
- 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 +333 -73
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/index.ts +74 -2
- package/core/server/host/published-page-assets.ts +35 -0
- package/core/server/host/server-page-assets.ts +33 -16
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +15 -0
- package/core/server/registry/declaration-precompiler.ts +24 -54
- package/core/server/registry/page-registry-store.ts +39 -10
- package/core/server/registry/services/pages/Get.ts +19 -9
- package/core/server/registry/validation/compile-gate.ts +14 -31
- package/core/server/registry/validation/cross-check.ts +7 -17
- package/core/server/registry/validation/declaration-safety-scan.ts +2 -2
- package/core/shared/types/component-contract.types.ts +10 -0
- package/dist/core/index.cjs +2144 -155
- package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -4
- 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 -3
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +8 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -10
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +33 -2
- 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/component/component-pack.d.ts +23 -3
- 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/engine/dom-renderer.d.ts +2 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +3 -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/registry/declaration-renderer.d.ts +1 -2
- 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 +29 -1
- package/dist/types/client/theme/tone-solver.d.ts +47 -0
- package/dist/types/index.d.ts +13 -2
- package/dist/types/server/host/published-page-assets.d.ts +19 -0
- package/dist/types/server/host/server-page-assets.d.ts +1 -4
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +3 -1
- package/dist/types/server/registry/declaration-precompiler.d.ts +3 -3
- package/dist/types/server/registry/page-registry-store.d.ts +5 -5
- package/dist/types/server/registry/validation/compile-gate.d.ts +2 -0
- package/dist/types/server/registry/validation/cross-check.d.ts +4 -4
- package/dist/types/shared/types/component-contract.types.d.ts +10 -0
- package/editor/vscode/package.json +1 -24
- package/global.d.ts +1 -11
- package/next.config.js +32 -50
- package/package.json +3 -2
- package/tailwind.config.ts +0 -1
- package/tsconfig.json +20 -7
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- package/core/client/host-bridge/empty-host/data/README.md +0 -17
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
|
@@ -28,6 +28,7 @@ __export(soma_precompile_exports, {
|
|
|
28
28
|
precompileDataYaml: () => precompileDataYaml,
|
|
29
29
|
precompileEventYaml: () => precompileEventYaml,
|
|
30
30
|
precompileStyleYaml: () => precompileStyleYaml,
|
|
31
|
+
precompileUiModule: () => precompileUiModule,
|
|
31
32
|
precompileUiYaml: () => precompileUiYaml,
|
|
32
33
|
precompileYaml: () => precompileYaml
|
|
33
34
|
});
|
|
@@ -4563,6 +4564,74 @@ function parseDataConfig(raw) {
|
|
|
4563
4564
|
return { objects };
|
|
4564
4565
|
}
|
|
4565
4566
|
|
|
4567
|
+
// core/build/v2/soma-file-loader.ts
|
|
4568
|
+
var SomaV2ParseError = class extends Error {
|
|
4569
|
+
constructor(message, blockId, line) {
|
|
4570
|
+
const where = blockId ? `\uFF08\u5757: ${blockId}${line ? `\uFF0C\u7B2C ${line} \u884C` : ""}\uFF09` : "";
|
|
4571
|
+
super(`[soma-core][\u5F15\u64CE] ${message}${where}`);
|
|
4572
|
+
this.blockId = blockId;
|
|
4573
|
+
this.line = line;
|
|
4574
|
+
this.name = "SomaV2ParseError";
|
|
4575
|
+
}
|
|
4576
|
+
};
|
|
4577
|
+
function stripSwitch(uiYamlRaw) {
|
|
4578
|
+
const lines = uiYamlRaw.split("\n");
|
|
4579
|
+
let openIndex = -1;
|
|
4580
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
4581
|
+
const text = lines[i].trim();
|
|
4582
|
+
if (text === "" || text.startsWith("#")) continue;
|
|
4583
|
+
if (text !== "{{") {
|
|
4584
|
+
throw new SomaV2ParseError("v2 \u58F0\u660E\u5FC5\u987B\u4EE5 `{{` \u5F00\u5173\u884C\u5F00\u5934");
|
|
4585
|
+
}
|
|
4586
|
+
openIndex = i;
|
|
4587
|
+
break;
|
|
4588
|
+
}
|
|
4589
|
+
if (openIndex === -1) {
|
|
4590
|
+
throw new SomaV2ParseError("\u6587\u4EF6\u4E3A\u7A7A\u6216\u53EA\u6709\u6CE8\u91CA\uFF0C\u627E\u4E0D\u5230 `{{` \u5F00\u5173\u884C");
|
|
4591
|
+
}
|
|
4592
|
+
let closeIndex = -1;
|
|
4593
|
+
for (let i = lines.length - 1; i > openIndex; i -= 1) {
|
|
4594
|
+
const text = lines[i].trim();
|
|
4595
|
+
if (text === "") continue;
|
|
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");
|
|
4598
|
+
}
|
|
4599
|
+
closeIndex = i;
|
|
4600
|
+
break;
|
|
4601
|
+
}
|
|
4602
|
+
if (closeIndex === -1) {
|
|
4603
|
+
throw new SomaV2ParseError("`{{` \u5F00\u5173\u672A\u95ED\u5408\u2014\u2014\u7F3A\u5C11 `}}` \u6536\u53E3\u884C");
|
|
4604
|
+
}
|
|
4605
|
+
return {
|
|
4606
|
+
inner: lines.slice(openIndex + 1, closeIndex).join("\n"),
|
|
4607
|
+
offset: openIndex + 1
|
|
4608
|
+
};
|
|
4609
|
+
}
|
|
4610
|
+
function parseSomaV2Container(uiYamlRaw) {
|
|
4611
|
+
const { inner, offset } = stripSwitch(uiYamlRaw);
|
|
4612
|
+
let doc;
|
|
4613
|
+
try {
|
|
4614
|
+
doc = yaml.load(inner);
|
|
4615
|
+
} catch (error) {
|
|
4616
|
+
throw new SomaV2ParseError(`YAML \u89E3\u6790\u5931\u8D25: ${error.message}`);
|
|
4617
|
+
}
|
|
4618
|
+
if (doc === null || doc === void 0) {
|
|
4619
|
+
return { doc: {}, inner, offset };
|
|
4620
|
+
}
|
|
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");
|
|
4623
|
+
}
|
|
4624
|
+
for (const [blockId, body] of Object.entries(doc)) {
|
|
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);
|
|
4627
|
+
}
|
|
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);
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
return { doc, inner, offset };
|
|
4633
|
+
}
|
|
4634
|
+
|
|
4566
4635
|
// core/build/compiler/soma-precompile.ts
|
|
4567
4636
|
var PRECOMPILE_PARSE_OPTIONS = { adaptiveVocabularyRequired: false };
|
|
4568
4637
|
function precompileUiYaml(yamlStr) {
|
|
@@ -4570,6 +4639,10 @@ function precompileUiYaml(yamlStr) {
|
|
|
4570
4639
|
const uiConfig = parseUiConfig(raw, PRECOMPILE_PARSE_OPTIONS);
|
|
4571
4640
|
return JSON.stringify(uiConfig);
|
|
4572
4641
|
}
|
|
4642
|
+
function precompileUiModule(yamlStr) {
|
|
4643
|
+
parseSomaV2Container(yamlStr);
|
|
4644
|
+
return "null";
|
|
4645
|
+
}
|
|
4573
4646
|
function precompileEventYaml(yamlStr) {
|
|
4574
4647
|
const raw = yamlStr.trim() ? yaml.load(yamlStr) : {};
|
|
4575
4648
|
const compiled = compileEventConfigFromRaw(raw);
|
|
@@ -4628,6 +4701,7 @@ function precompileYaml(yamlStr) {
|
|
|
4628
4701
|
precompileDataYaml,
|
|
4629
4702
|
precompileEventYaml,
|
|
4630
4703
|
precompileStyleYaml,
|
|
4704
|
+
precompileUiModule,
|
|
4631
4705
|
precompileUiYaml,
|
|
4632
4706
|
precompileYaml
|
|
4633
4707
|
});
|
|
@@ -7,6 +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
11
|
import type { SomaDataConfig } from '../../shared/types/data-config.types';
|
|
11
12
|
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
12
13
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
@@ -41,6 +42,18 @@ export function precompileUiYaml(yamlStr: string): string {
|
|
|
41
42
|
return JSON.stringify(uiConfig);
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
/**
|
|
46
|
+
* 单文件 bundler 的 UI 模块产物。
|
|
47
|
+
*
|
|
48
|
+
* SOMA DSL 必须拿同页 HTML 做页面级编译,单文件 loader 无权猜锚点上下文;因此
|
|
49
|
+
* 导出 null,让宿主转入 manifest/page-assets 路径。回退前仍完整校验 v2 容器,避免
|
|
50
|
+
* 旧页面形状、未闭合开关或坏 YAML 被伪装成“没有预编译产物”。
|
|
51
|
+
*/
|
|
52
|
+
export function precompileUiModule(yamlStr: string): string {
|
|
53
|
+
parseSomaV2Container(yamlStr);
|
|
54
|
+
return 'null';
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
/**
|
|
45
58
|
* 预编译 Event YAML → JSON 字符串(含 events + triggers)
|
|
46
59
|
*/
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
const {
|
|
2
|
-
|
|
3
|
-
precompileEventYaml,
|
|
4
|
-
precompileStyleYaml,
|
|
5
|
-
precompileDataYaml,
|
|
2
|
+
precompileUiModule,
|
|
6
3
|
precompileYaml,
|
|
7
4
|
} = require('./soma-precompile');
|
|
8
5
|
|
|
9
6
|
module.exports = function somaRspackYamlLoader(source) {
|
|
10
7
|
const options = this.getOptions?.() ?? {};
|
|
11
8
|
const uiSuffix = options.uiSuffix ?? '_ui.yaml';
|
|
12
|
-
const eventSuffix = options.eventSuffix ?? '_event.yaml';
|
|
13
|
-
const styleSuffix = options.styleSuffix ?? '_style.yaml';
|
|
14
|
-
const dataSuffix = options.dataSuffix ?? '_data.yaml';
|
|
15
9
|
const resourcePath = this.resourcePath ?? '';
|
|
16
10
|
|
|
17
11
|
let compiled;
|
|
18
|
-
if (resourcePath.endsWith(uiSuffix)) compiled =
|
|
19
|
-
else if (
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
if (resourcePath.endsWith(uiSuffix)) compiled = precompileUiModule(source);
|
|
13
|
+
else if (/_((event)|(style)|(data))\.ya?ml$/.test(resourcePath)) {
|
|
14
|
+
throw new Error('页面侧车已退役;事件、样式状态与数据对象必须并入同一份 SOMA DSL 声明');
|
|
15
|
+
}
|
|
22
16
|
else compiled = precompileYaml(source);
|
|
23
17
|
|
|
24
18
|
return `export default ${compiled};`;
|
|
@@ -7,30 +7,16 @@ module.exports = function somaWebpackLoader(source) {
|
|
|
7
7
|
const resourcePath = this.resourcePath;
|
|
8
8
|
|
|
9
9
|
try {
|
|
10
|
-
const {
|
|
10
|
+
const { precompileUiModule, precompileYaml } = require('./soma-precompile');
|
|
11
11
|
|
|
12
|
-
// SOMA
|
|
12
|
+
// SOMA DSL 源声明只做容器校验,页面级编译交给 manifest/page-assets。
|
|
13
13
|
if (resourcePath.endsWith('_ui.yaml')) {
|
|
14
|
-
const compiled =
|
|
14
|
+
const compiled = precompileUiModule(source);
|
|
15
15
|
return `export default ${compiled};`;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const compiled = precompileEventYaml(source);
|
|
21
|
-
return `export default ${compiled};`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// SOMA Style 配置
|
|
25
|
-
if (resourcePath.endsWith('_style.yaml')) {
|
|
26
|
-
const compiled = precompileStyleYaml(source);
|
|
27
|
-
return `export default ${compiled};`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// SOMA Data 配置(数据对象层,可选件)
|
|
31
|
-
if (resourcePath.endsWith('_data.yaml')) {
|
|
32
|
-
const compiled = precompileDataYaml(source);
|
|
33
|
-
return `export default ${compiled};`;
|
|
18
|
+
if (/_((event)|(style)|(data))\.ya?ml$/.test(resourcePath)) {
|
|
19
|
+
throw new Error('页面侧车已退役;事件、样式状态与数据对象必须并入同一份 SOMA DSL 声明');
|
|
34
20
|
}
|
|
35
21
|
|
|
36
22
|
// 通用 YAML(locale、app.config 等)
|
|
@@ -41,7 +27,6 @@ module.exports = function somaWebpackLoader(source) {
|
|
|
41
27
|
|
|
42
28
|
return source;
|
|
43
29
|
} catch (e) {
|
|
44
|
-
|
|
45
|
-
return source;
|
|
30
|
+
throw new Error(`[soma-webpack-loader] 预编译失败 (${resourcePath}): ${e.message}`);
|
|
46
31
|
}
|
|
47
32
|
};
|
|
@@ -2,17 +2,11 @@
|
|
|
2
2
|
// Vite 预编译插件:在构建阶段将所有声明式 YAML 配置编译为 JS 模块
|
|
3
3
|
|
|
4
4
|
import type { Plugin } from 'vite';
|
|
5
|
-
import {
|
|
5
|
+
import { precompileUiModule, precompileYaml } from './soma-precompile';
|
|
6
6
|
|
|
7
7
|
export interface SomaPluginOptions {
|
|
8
8
|
/** UI 配置文件后缀,默认 _ui.yaml */
|
|
9
9
|
uiSuffix?: string;
|
|
10
|
-
/** 事件配置文件后缀,默认 _event.yaml */
|
|
11
|
-
eventSuffix?: string;
|
|
12
|
-
/** 样式配置文件后缀,默认 _style.yaml */
|
|
13
|
-
styleSuffix?: string;
|
|
14
|
-
/** 数据对象层配置文件后缀,默认 _data.yaml */
|
|
15
|
-
dataSuffix?: string;
|
|
16
10
|
}
|
|
17
11
|
|
|
18
12
|
/**
|
|
@@ -22,10 +16,8 @@ export interface SomaPluginOptions {
|
|
|
22
16
|
* 移到构建时完成。运行时直接 import 得到已解析的对象。
|
|
23
17
|
*
|
|
24
18
|
* 覆盖范围:
|
|
25
|
-
* - `_ui.yaml`
|
|
26
|
-
* -
|
|
27
|
-
* - `_style.yaml` → StyleConfig 对象(parseStyleConfig 预编译)
|
|
28
|
-
* - `_data.yaml` → SomaDataConfig 对象(parseDataConfig 预编译)
|
|
19
|
+
* - `_ui.yaml` → 校验统一声明容器并导出 null(页面级 manifest 结合 HTML 编译)
|
|
20
|
+
* - 页面事件、样式、数据侧车 → 明确拒绝
|
|
29
21
|
* - `locale.yaml` → Record<string, unknown>
|
|
30
22
|
* - `*.config.yaml` → 任意配置对象
|
|
31
23
|
* - 其他 `.yaml` → 通用 YAML → JS 对象
|
|
@@ -42,9 +34,6 @@ export interface SomaPluginOptions {
|
|
|
42
34
|
*/
|
|
43
35
|
export function somaPlugin(options: SomaPluginOptions = {}): Plugin {
|
|
44
36
|
const uiSuffix = options.uiSuffix ?? '_ui.yaml';
|
|
45
|
-
const eventSuffix = options.eventSuffix ?? '_event.yaml';
|
|
46
|
-
const styleSuffix = options.styleSuffix ?? '_style.yaml';
|
|
47
|
-
const dataSuffix = options.dataSuffix ?? '_data.yaml';
|
|
48
37
|
|
|
49
38
|
return {
|
|
50
39
|
name: 'vite-plugin-soma',
|
|
@@ -58,26 +47,15 @@ export function somaPlugin(options: SomaPluginOptions = {}): Plugin {
|
|
|
58
47
|
try {
|
|
59
48
|
// SOMA UI 配置
|
|
60
49
|
if (id.endsWith(uiSuffix)) {
|
|
61
|
-
const compiled =
|
|
50
|
+
const compiled = precompileUiModule(code);
|
|
62
51
|
return { code: `export default ${compiled};`, map: null };
|
|
63
52
|
}
|
|
64
53
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// SOMA Style 配置
|
|
72
|
-
if (id.endsWith(styleSuffix)) {
|
|
73
|
-
const compiled = precompileStyleYaml(code);
|
|
74
|
-
return { code: `export default ${compiled};`, map: null };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// SOMA Data 配置(数据对象层,可选件)
|
|
78
|
-
if (id.endsWith(dataSuffix)) {
|
|
79
|
-
const compiled = precompileDataYaml(code);
|
|
80
|
-
return { code: `export default ${compiled};`, map: null };
|
|
54
|
+
if (/_((event)|(style)|(data))\.ya?ml$/.test(id)) {
|
|
55
|
+
this.error(
|
|
56
|
+
`[vite-plugin-soma] 页面侧车已退役 (${id}):`
|
|
57
|
+
+ '事件、样式状态与数据对象必须并入同一份 SOMA DSL 声明',
|
|
58
|
+
);
|
|
81
59
|
}
|
|
82
60
|
|
|
83
61
|
// 通用 YAML(locale、app.config 等)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// 固定目录 → 完整组件包(一步到位的接入路径)。
|
|
2
|
+
//
|
|
3
|
+
// loadComponentPackages 只给 { 组件名: 定义 },样式还要宿主自己接线——
|
|
4
|
+
// 而"装了库还要手动接 CSS"正是组件包体系要消灭的老路。本模块把扫描出来的
|
|
5
|
+
// style.css 一并装进 pack.styles.components,交出的东西可以直接喂
|
|
6
|
+
// composeComponentPacks,宿主接线是一行。
|
|
7
|
+
//
|
|
8
|
+
// 顺带闭合一条质量链路:CSS 落在 pack.styles 上之后,verifyComponentPack 的
|
|
9
|
+
// 颜色纪律与逻辑属性检查自动覆盖它——文件态组件与 TS 组件受同一把尺子。
|
|
10
|
+
//
|
|
11
|
+
// 运行环境:本模块用 node:fs,只能在构建期/服务端跑。宿主 bootstrap 会被打进
|
|
12
|
+
// 客户端 bundle,不要在那里直接调用;见接入指南"自动扫描"一节的构建期产物写法。
|
|
13
|
+
|
|
14
|
+
import type { SomaComponentPack } from '../../client/component/component-pack';
|
|
15
|
+
import {
|
|
16
|
+
scanComponentPackages,
|
|
17
|
+
type LoadPackagesOptions,
|
|
18
|
+
} from './package-loader';
|
|
19
|
+
|
|
20
|
+
export interface LoadPackFromDirOptions extends LoadPackagesOptions {
|
|
21
|
+
/** 包标识:小写字母/数字/连字符 */
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
meta?: SomaComponentPack['meta'];
|
|
25
|
+
/** 并进组件目录的写作规范补充(可选) */
|
|
26
|
+
catalogConventions?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 扫描固定目录,产出可直接参与合成的组件包。
|
|
31
|
+
*
|
|
32
|
+
* 文件态只产组件私有分片(styles.components)——共享分片与包基座需要跨组件的
|
|
33
|
+
* 设计决策,仍属 TS 形态组件包的能力,不在目录约定里猜。
|
|
34
|
+
*/
|
|
35
|
+
export function loadComponentPackFromDir(
|
|
36
|
+
rootDir: string,
|
|
37
|
+
options: LoadPackFromDirOptions,
|
|
38
|
+
): SomaComponentPack {
|
|
39
|
+
const { name, version, meta, catalogConventions, ...scanOptions } = options;
|
|
40
|
+
const entries = scanComponentPackages(rootDir, scanOptions);
|
|
41
|
+
|
|
42
|
+
const components: SomaComponentPack['components'] = {};
|
|
43
|
+
const componentStyles: Record<string, string> = {};
|
|
44
|
+
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const componentName = entry.definition.contract.name;
|
|
47
|
+
components[componentName] = entry.definition;
|
|
48
|
+
if (entry.css) componentStyles[componentName] = entry.css;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const pack: SomaComponentPack = { name, version, components };
|
|
52
|
+
if (Object.keys(componentStyles).length > 0) {
|
|
53
|
+
pack.styles = { components: componentStyles };
|
|
54
|
+
}
|
|
55
|
+
if (catalogConventions) pack.catalogConventions = catalogConventions;
|
|
56
|
+
if (meta) pack.meta = meta;
|
|
57
|
+
return pack;
|
|
58
|
+
}
|
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
// template.html 必需
|
|
6
6
|
// ui.yaml 可选(内部绑定,作用域根 p/ctrl)
|
|
7
7
|
// event.yaml 可选(内部事件 Pipeline)
|
|
8
|
+
// style.css 可选(按需装配:首次实例化才注入)
|
|
8
9
|
//
|
|
9
10
|
// 装载为 SomaComponentDefinition,供 Host bootstrap 注册。声明式组件(无控制器)
|
|
10
11
|
// 可全文件态交付——这是"AI 自产组件落盘即用"生长层的文件通道;
|
|
11
12
|
// 需要控制器逻辑的组件仍用 TS 形态(controllerFactory)。
|
|
13
|
+
//
|
|
14
|
+
// 一条与合成层同源的默认值:**同一次扫描里组件名撞车直接抛错**并点名两个目录。
|
|
15
|
+
// 后者静默胜出会让"页面用的是哪个组件"只能靠 readdir 顺序猜——那正是
|
|
16
|
+
// composeComponentPacks 拒绝的东西,扫描层没有理由更宽松。
|
|
12
17
|
|
|
13
18
|
import fs from 'node:fs';
|
|
14
19
|
import path from 'node:path';
|
|
@@ -29,9 +34,42 @@ export class SomaComponentPackageError extends Error {
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
const LAYERS = new Set(['atom', 'composite', 'solution', 'template']);
|
|
37
|
+
const LAYER_LIST = 'atom|composite|solution|template';
|
|
38
|
+
/** 包名/覆盖目标包名:与合成层 PACK_NAME_PATTERN 同一把尺子(此处不 import,避免 build 层依赖 client 层导出) */
|
|
39
|
+
const PACK_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
40
|
+
|
|
41
|
+
/** 扫描期的软问题:不阻断装载,但必须让人看见(都是"不报错但坏掉"的前兆) */
|
|
42
|
+
export interface PackScanWarning {
|
|
43
|
+
kind: 'page-style-filename' | 'dir-name-mismatch';
|
|
44
|
+
packageDir: string;
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface LoadPackagesOptions {
|
|
49
|
+
/**
|
|
50
|
+
* 警告汇总回调(缺省时汇总为单块 console.warn)。
|
|
51
|
+
* 刻意做成"扫描结束一次性给全部"而不是逐条打印:dev 服务器的滚动输出里,
|
|
52
|
+
* 逐条 warn 与"没打印"的实际效果差不多。
|
|
53
|
+
*/
|
|
54
|
+
onWarning?: (warnings: PackScanWarning[]) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 单目录装载的完整产物(内部形态:definition 之外还带样式与警告) */
|
|
58
|
+
interface PackageEntry {
|
|
59
|
+
definition: SomaComponentDefinition;
|
|
60
|
+
/** style.css 内容;无文件或空文件为 null */
|
|
61
|
+
css: string | null;
|
|
62
|
+
warnings: PackScanWarning[];
|
|
63
|
+
packageDir: string;
|
|
64
|
+
}
|
|
32
65
|
|
|
33
66
|
/** 装载单个组件包目录 → 运行时定义(结构校验 fail fast) */
|
|
34
67
|
export function loadComponentPackage(packageDir: string): SomaComponentDefinition {
|
|
68
|
+
return loadComponentPackageEntry(packageDir).definition;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 装载单个组件包目录 → 定义 + 样式 + 警告(供整包装载复用) */
|
|
72
|
+
export function loadComponentPackageEntry(packageDir: string): PackageEntry {
|
|
35
73
|
const contractPath = path.join(packageDir, 'contract.yaml');
|
|
36
74
|
const templatePath = path.join(packageDir, 'template.html');
|
|
37
75
|
|
|
@@ -76,23 +114,122 @@ export function loadComponentPackage(packageDir: string): SomaComponentDefinitio
|
|
|
76
114
|
definition.services = servicesRaw.map(String);
|
|
77
115
|
}
|
|
78
116
|
|
|
79
|
-
|
|
117
|
+
const stylePath = path.join(packageDir, 'style.css');
|
|
118
|
+
let css: string | null = null;
|
|
119
|
+
if (fs.existsSync(stylePath)) {
|
|
120
|
+
const raw = fs.readFileSync(stylePath, 'utf-8').trim();
|
|
121
|
+
css = raw ? raw : null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { definition, css, warnings: collectWarnings(packageDir, contract), packageDir };
|
|
80
125
|
}
|
|
81
126
|
|
|
82
|
-
/**
|
|
83
|
-
|
|
127
|
+
/**
|
|
128
|
+
* 扫描根目录下的全部组件包(含 contract.yaml 的一级子目录)。
|
|
129
|
+
*
|
|
130
|
+
* 组件名撞车抛错并点名两个目录——扫描层与合成层同一条纪律。
|
|
131
|
+
*/
|
|
132
|
+
export function loadComponentPackages(
|
|
133
|
+
rootDir: string,
|
|
134
|
+
options: LoadPackagesOptions = {},
|
|
135
|
+
): Record<string, SomaComponentDefinition> {
|
|
136
|
+
const entries = scanComponentPackages(rootDir, options);
|
|
137
|
+
const result: Record<string, SomaComponentDefinition> = {};
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
result[entry.definition.contract.name] = entry.definition;
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 扫描并返回完整条目(定义 + 样式 + 目录),整包装载与按需样式装配的共同入口 */
|
|
145
|
+
export function scanComponentPackages(
|
|
146
|
+
rootDir: string,
|
|
147
|
+
options: LoadPackagesOptions = {},
|
|
148
|
+
): PackageEntry[] {
|
|
84
149
|
if (!fs.existsSync(rootDir)) {
|
|
85
|
-
return
|
|
150
|
+
return [];
|
|
86
151
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
152
|
+
const entries: PackageEntry[] = [];
|
|
153
|
+
const seenDirs: Record<string, string> = {};
|
|
154
|
+
const warnings: PackScanWarning[] = [];
|
|
155
|
+
|
|
156
|
+
for (const dirent of fs.readdirSync(rootDir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
157
|
+
if (!dirent.isDirectory()) continue;
|
|
158
|
+
const dir = path.join(rootDir, dirent.name);
|
|
91
159
|
if (!fs.existsSync(path.join(dir, 'contract.yaml'))) continue;
|
|
92
|
-
|
|
93
|
-
|
|
160
|
+
|
|
161
|
+
const entry = loadComponentPackageEntry(dir);
|
|
162
|
+
const name = entry.definition.contract.name;
|
|
163
|
+
const firstDir = seenDirs[name];
|
|
164
|
+
if (firstDir !== undefined) {
|
|
165
|
+
throw new SomaComponentPackageError(
|
|
166
|
+
`组件名冲突:"${name}" 同时来自 "${firstDir}" 与 "${dir}"。`
|
|
167
|
+
+ '\n 同一目录下的两个组件包不存在合理的胜者——请改掉其中一个的契约 name。'
|
|
168
|
+
+ '\n (跨包覆盖是另一回事:在契约上写 overrides: <被覆盖的包名>)',
|
|
169
|
+
dir,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
seenDirs[name] = dir;
|
|
173
|
+
warnings.push(...entry.warnings);
|
|
174
|
+
entries.push(entry);
|
|
94
175
|
}
|
|
95
|
-
|
|
176
|
+
|
|
177
|
+
reportWarnings(rootDir, entries.length, warnings, options.onWarning);
|
|
178
|
+
return entries;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** 一次性汇总输出:逐条 warn 会淹没在 dev 服务器的滚动输出里 */
|
|
182
|
+
function reportWarnings(
|
|
183
|
+
rootDir: string,
|
|
184
|
+
packageCount: number,
|
|
185
|
+
warnings: PackScanWarning[],
|
|
186
|
+
onWarning?: (warnings: PackScanWarning[]) => void,
|
|
187
|
+
): void {
|
|
188
|
+
if (onWarning) {
|
|
189
|
+
onWarning(warnings);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (warnings.length === 0) return;
|
|
193
|
+
const lines = warnings.map((warning) => ` · ${warning.message}`);
|
|
194
|
+
// 构建期/终端面向的日志,前缀按命令名走(与 core/build 下 `[soma db]` 同款约定)
|
|
195
|
+
// eslint-disable-next-line no-console
|
|
196
|
+
console.warn(
|
|
197
|
+
`[soma 组件扫描] ${rootDir}:${packageCount} 个组件,${warnings.length} 条警告\n${lines.join('\n')}`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** 目录级软问题:文件名写成页面四件套、目录名与组件名对不上 */
|
|
202
|
+
function collectWarnings(packageDir: string, contract: SomaComponentContract): PackScanWarning[] {
|
|
203
|
+
const warnings: PackScanWarning[] = [];
|
|
204
|
+
|
|
205
|
+
for (const [pageStyle, expected] of [['_ui.yaml', 'ui.yaml'], ['_event.yaml', 'event.yaml']] as const) {
|
|
206
|
+
if (fs.existsSync(path.join(packageDir, pageStyle))) {
|
|
207
|
+
warnings.push({
|
|
208
|
+
kind: 'page-style-filename',
|
|
209
|
+
packageDir,
|
|
210
|
+
message: `${packageDir} 里有 ${pageStyle}——组件内部声明的文件名是 ${expected}(不带下划线),`
|
|
211
|
+
+ '当前这份不会被装载',
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const dirName = path.basename(packageDir);
|
|
217
|
+
if (dirName && toKebabCase(contract.name) !== dirName) {
|
|
218
|
+
warnings.push({
|
|
219
|
+
kind: 'dir-name-mismatch',
|
|
220
|
+
packageDir,
|
|
221
|
+
message: `${packageDir} 的目录名与契约 name "${contract.name}" 对不上`
|
|
222
|
+
+ `(建议目录名 ${toKebabCase(contract.name)})——不一致时按名字找组件只能靠 grep`,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return warnings;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function toKebabCase(name: string): string {
|
|
229
|
+
return name
|
|
230
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
231
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
232
|
+
.toLowerCase();
|
|
96
233
|
}
|
|
97
234
|
|
|
98
235
|
function validateContract(raw: unknown, packageDir: string): SomaComponentContract {
|
|
@@ -110,7 +247,16 @@ function validateContract(raw: unknown, packageDir: string): SomaComponentContra
|
|
|
110
247
|
throw new SomaComponentPackageError(`契约 name "${contract.name}" 必须是 PascalCase`, packageDir);
|
|
111
248
|
}
|
|
112
249
|
if (!LAYERS.has(String(contract.layer))) {
|
|
113
|
-
throw new SomaComponentPackageError(`契约 layer "${contract.layer}"
|
|
250
|
+
throw new SomaComponentPackageError(`契约 layer "${contract.layer}" 非法(${LAYER_LIST})`, packageDir);
|
|
251
|
+
}
|
|
252
|
+
if (contract.overrides !== undefined) {
|
|
253
|
+
if (typeof contract.overrides !== 'string' || !PACK_NAME_PATTERN.test(contract.overrides)) {
|
|
254
|
+
throw new SomaComponentPackageError(
|
|
255
|
+
`契约 overrides "${String(contract.overrides)}" 必须是包名([a-z][a-z0-9-]*),`
|
|
256
|
+
+ '值写被覆盖组件的来源包名,如 soma-ui',
|
|
257
|
+
packageDir,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
114
260
|
}
|
|
115
261
|
|
|
116
262
|
// C1/C4:props 需 desc;可选 prop 必须有 default
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
//
|
|
12
12
|
// 命名约定(与 Next Host 的文件寻址一致,见 server-page-assets):
|
|
13
13
|
// 页面名 order-board → html/order-board.html · ui/order-board_ui.yaml
|
|
14
|
-
// ·
|
|
15
|
-
// Domain 类名 OrderBoardPage,必须与 html 的 data-soma-host 一致。
|
|
14
|
+
// · domain/ui/order-boardClass.ts。Domain 类名 OrderBoardPage 必须与 HTML 和声明一致。
|
|
16
15
|
|
|
17
16
|
/** 页面名:小写字母/数字/连字符——它同时是文件名与 URL 片段 */
|
|
18
17
|
export const EJECT_NAME_PATTERN = /^[a-z0-9-]{1,64}$/;
|
|
@@ -57,7 +56,7 @@ export function domainClassNameOf(name: string): string {
|
|
|
57
56
|
* 把声明里的宿主类名换成固化后的类名。
|
|
58
57
|
*
|
|
59
58
|
* 为什么必须换:运行态声明的 host 是通道给的占位(PreviewPageRoot / GeneratedPage),
|
|
60
|
-
* 固化后页面有了自己的 Domain 类,html 的 data-soma-host
|
|
59
|
+
* 固化后页面有了自己的 Domain 类,html 的 data-soma-host 与声明的 page.domain
|
|
61
60
|
* 必须与类名三处一致——差一处,页面加载时就是"Domain class missing"。
|
|
62
61
|
*/
|
|
63
62
|
function rewriteHost(html: string, domainClass: string): { html: string; previous: string } {
|
|
@@ -71,16 +70,17 @@ function rewriteHost(html: string, domainClass: string): { html: string; previou
|
|
|
71
70
|
};
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
/**
|
|
75
|
-
function
|
|
73
|
+
/** 把统一声明的 page.domain 换成固化后的类名。 */
|
|
74
|
+
function rewriteDomain(uiYaml: string, previousHost: string, domainClass: string): string {
|
|
76
75
|
if (previousHost === domainClass) return uiYaml;
|
|
76
|
+
if (!/^\s*\{\{/m.test(uiYaml) || !/^\s*\}\}\s*$/m.test(uiYaml)) {
|
|
77
|
+
throw new EjectPlanError('uiYaml 不是 SOMA DSL 统一声明(必须以 {{ 开头、以 }} 收口)');
|
|
78
|
+
}
|
|
77
79
|
const escaped = previousHost.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
const block = new RegExp(`(bind:[\\s\\S]*?\\n\\s*obj:\\s*)${escaped}\\b`);
|
|
81
|
-
if (block.test(uiYaml)) return uiYaml.replace(block, `$1${domainClass}`);
|
|
80
|
+
const domain = new RegExp(`(^\\s*domain:\\s*)${escaped}\\s*$`, 'm');
|
|
81
|
+
if (domain.test(uiYaml)) return uiYaml.replace(domain, `$1${domainClass}`);
|
|
82
82
|
throw new EjectPlanError(
|
|
83
|
-
`
|
|
83
|
+
`SOMA DSL 的 page.domain 不是 "${previousHost}"——HTML 与声明的宿主对不上,拒绝固化`,
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -96,7 +96,7 @@ function domainSource(name: string, domainClass: string): string {
|
|
|
96
96
|
"import { SomaPageRootBase } from 'soma-core/base';",
|
|
97
97
|
'',
|
|
98
98
|
`export default class ${domainClass} extends SomaPageRootBase {`,
|
|
99
|
-
' //
|
|
99
|
+
' // SOMA DSL 的 event 段可绑定到这里的方法;先留空,按需要添加。',
|
|
100
100
|
'}',
|
|
101
101
|
'',
|
|
102
102
|
].join('\n');
|
|
@@ -115,22 +115,16 @@ export function planEject(name: string, declaration: EjectDeclaration): EjectPla
|
|
|
115
115
|
}
|
|
116
116
|
const domainClass = domainClassNameOf(name);
|
|
117
117
|
const { html, previous } = rewriteHost(declaration.html, domainClass);
|
|
118
|
-
|
|
118
|
+
if (declaration.eventYaml?.trim() || declaration.styleYaml?.trim() || declaration.dataYaml?.trim()) {
|
|
119
|
+
throw new EjectPlanError('页面侧车已退役;固化输入只能包含 HTML 与一份 SOMA DSL 声明');
|
|
120
|
+
}
|
|
121
|
+
const uiYaml = rewriteDomain(declaration.uiYaml, previous, domainClass);
|
|
119
122
|
|
|
120
123
|
const files: EjectFile[] = [
|
|
121
124
|
{ path: `html/${name}.html`, contents: ensureTrailingNewline(html) },
|
|
122
125
|
{ path: `ui/${name}_ui.yaml`, contents: ensureTrailingNewline(uiYaml) },
|
|
123
126
|
{ path: `domain/ui/${name}Class.ts`, contents: domainSource(name, domainClass) },
|
|
124
127
|
];
|
|
125
|
-
if (declaration.eventYaml?.trim()) {
|
|
126
|
-
files.push({ path: `event/${name}_event.yaml`, contents: ensureTrailingNewline(declaration.eventYaml) });
|
|
127
|
-
}
|
|
128
|
-
if (declaration.styleYaml?.trim()) {
|
|
129
|
-
files.push({ path: `ui/${name}_style.yaml`, contents: ensureTrailingNewline(declaration.styleYaml) });
|
|
130
|
-
}
|
|
131
|
-
if (declaration.dataYaml?.trim()) {
|
|
132
|
-
files.push({ path: `data/${name}_data.yaml`, contents: ensureTrailingNewline(declaration.dataYaml) });
|
|
133
|
-
}
|
|
134
128
|
return { name, domainClass, url: `/${name}`, files };
|
|
135
129
|
}
|
|
136
130
|
|