soma-core 1.3.5 → 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.
- package/README.md +20 -7
- package/app/SomaPageClient.tsx +4 -4
- package/app/components/SomaHostPage.tsx +5 -5
- package/app/components/SomaHydrationShell.tsx +4 -7
- package/app/globals.css +126 -3
- package/core/build/{v2 → blocks}/block-compile.ts +17 -17
- package/core/build/{v2/soma-file-loader.ts → blocks/block-container.ts} +28 -28
- package/core/build/{v2 → blocks}/block-loader.ts +1 -1
- package/core/build/{v2 → blocks}/html-index.ts +1 -1
- package/core/build/{v2/migrate-v1.ts → blocks/migrate-flat.ts} +27 -27
- package/core/build/compiler/host-config-sync.cjs +2 -9
- package/core/build/compiler/page-declaration-compiler.ts +2 -2
- package/core/build/compiler/soma-manifest-webpack-plugin.js +1 -1
- package/core/build/compiler/soma-precompile.js +17 -17
- package/core/build/compiler/soma-precompile.ts +2 -2
- package/core/client/component/ai-catalog.ts +4 -4
- package/core/client/component/contract-compat.ts +32 -3
- package/core/client/component/{example-v2.ts → example-blocks.ts} +19 -19
- package/core/client/engine/soma-bootstrap.ts +21 -2
- package/core/client/engine/style-binder.ts +1 -1
- package/core/client/infra/notify/DomNotifyService.ts +2 -1
- package/core/client/infra/notify/INotifyTheme.ts +1 -1
- package/core/client/parser/{v2 → blocks}/namespace.ts +1 -1
- package/core/client/parser/{v2 → blocks}/page-parser.ts +16 -16
- package/core/client/parser/{v2 → blocks}/use-parser.ts +20 -14
- package/core/client/parser/style-config-parser.ts +7 -7
- package/core/client/parser/value-lang.ts +1 -1
- package/core/client/registry/index.ts +8 -0
- package/core/client/theme/theme-engine.ts +42 -14
- package/core/client/typography/typography-base.ts +1 -1
- package/core/index.ts +25 -13
- package/core/server/host/csp-nonce-metadata.ts +1 -1
- package/core/server/host/published-page-assets.ts +3 -8
- package/core/server/host/soma-page-compile.ts +1 -1
- package/core/server/index.ts +2 -2
- package/core/shared/published-page-route.ts +61 -0
- package/core/shared/types/adaptive.types.ts +1 -1
- package/core/shared/types/data-config.types.ts +30 -2
- package/core/shared/types/scope-manifest.types.ts +11 -15
- package/core/shared/types/style-config.types.ts +4 -4
- package/dist/cli/soma.js +15 -2
- package/dist/core/index.cjs +165 -76
- package/dist/types/build/{v2 → blocks}/block-compile.d.ts +7 -7
- package/dist/types/build/{v2/soma-file-loader.d.ts → blocks/block-container.d.ts} +6 -6
- package/dist/types/build/{v2/migrate-v1.d.ts → blocks/migrate-flat.d.ts} +6 -6
- package/dist/types/client/component/contract-compat.d.ts +2 -2
- package/dist/types/client/component/example-blocks.d.ts +9 -0
- package/dist/types/client/infra/notify/DomNotifyService.d.ts +2 -1
- package/dist/types/client/infra/notify/INotifyTheme.d.ts +1 -1
- package/dist/types/client/parser/{v2 → blocks}/page-parser.d.ts +2 -2
- package/dist/types/client/parser/{v2 → blocks}/use-parser.d.ts +1 -1
- package/dist/types/client/parser/style-config-parser.d.ts +1 -1
- package/dist/types/client/registry/index.d.ts +1 -0
- package/dist/types/client/theme/theme-engine.d.ts +11 -0
- package/dist/types/index.d.ts +8 -7
- package/dist/types/server/host/published-page-assets.d.ts +3 -2
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/shared/published-page-route.d.ts +21 -0
- package/dist/types/shared/types/data-config.types.d.ts +18 -2
- package/dist/types/shared/types/scope-manifest.types.d.ts +11 -11
- package/dist/types/shared/types/style-config.types.d.ts +4 -4
- package/package.json +1 -6
- package/dist/types/client/component/example-v2.d.ts +0 -9
- package/postcss.config.js +0 -6
- package/tailwind.config.ts +0 -43
- /package/dist/types/build/{v2 → blocks}/block-loader.d.ts +0 -0
- /package/dist/types/build/{v2 → blocks}/html-index.d.ts +0 -0
- /package/dist/types/client/parser/{v2 → blocks}/namespace.d.ts +0 -0
package/README.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
SOMA 运行时引擎:页面 = 四件套声明文件(html/_ui.yaml/_event.yaml/_style.yaml,另加可选
|
|
4
4
|
`data/<page>_data.yaml` 数据对象声明)+ 可选 Domain TS —— 声明即数据,落盘即渲染,零构建。
|
|
5
5
|
|
|
6
|
+
Registry 页面以页面名作为公开根路径:注册 `myworkspace` 后直接访问 `/myworkspace`。
|
|
7
|
+
Host 文件页优先,Registry 页面在 Host 404 时兜底;存量 `/pages/<name>` 链接仅保留兼容读取。
|
|
8
|
+
|
|
6
9
|
## 当前能力(以代码为准)
|
|
7
10
|
|
|
8
11
|
- **编译管线**:ManifestCompiler 把四件套编译为运行时 Manifest;`soma-precompile` 预编译产物
|
|
@@ -21,15 +24,25 @@ SOMA 运行时引擎:页面 = 四件套声明文件(html/_ui.yaml/_event.yaml/_s
|
|
|
21
24
|
- **宿主与 CLI**:Next Host(`app/`,含静态 public/ 托管)+ `soma` CLI
|
|
22
25
|
(`dev/build/start/db generate|push`、mock 服务器、LSP、codegen,见 `bin/`)。
|
|
23
26
|
|
|
24
|
-
## 文档索引
|
|
27
|
+
## 文档索引
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
对外接入文档在仓库 `external-docs/`,本目录是 soma-core 的**模块详设**,面向模块维护者。
|
|
30
|
+
|
|
31
|
+
主要篇目(`doc/`):
|
|
32
|
+
|
|
33
|
+
- `soma 运行时引擎详设.md` — 引擎架构拓扑、编译管线、组件运行时、作用域、emit 路由、services 白名单。模块详设旗舰篇
|
|
34
|
+
- `soma 业务领域详设.md` — 业务领域模块:三类领域对象、服务层分层、生命周期、基类与注解驱动
|
|
30
35
|
- `soma 数据对象层.md` — `*_data.yaml` 语法与解析器
|
|
31
|
-
- `soma
|
|
32
|
-
-
|
|
36
|
+
- `soma 设计令牌与主题.md` — 令牌总表、派生算法、换肤协议
|
|
37
|
+
- `soma 主题属性设计.md` / `soma 主题多维体系架构设计.md` — 主题多维体系
|
|
38
|
+
- `soma 空间地基详设.md` / `空间地基架构.md` / `空间体系契约与边界.md` — 空间地基与跨包契约
|
|
39
|
+
- `soma 增量刷新方案.md` — Dirty Commit 三通道设计与性能模型
|
|
40
|
+
- `soma CLI 与 Host 工作区.md` — CLI 与 Next Host 实施方案
|
|
41
|
+
- `soma DSL 语法全书.md` / `soma DSL 语法全书(v2).md` — 语法参考(对外的唯一真源是 `external-docs/soma-DSL语法参考.md`)
|
|
42
|
+
- `跨端Adapter.md` — IContainerAdapter 协议与一致性测试
|
|
43
|
+
- `archive/` — 已并入其他文档、不再维护的旧稿
|
|
44
|
+
|
|
45
|
+
全局架构见仓库 `doc/soma 架构白皮书.md`。
|
|
33
46
|
|
|
34
47
|
## 测试
|
|
35
48
|
|
package/app/SomaPageClient.tsx
CHANGED
|
@@ -278,9 +278,9 @@ function SomaPageRenderer({
|
|
|
278
278
|
|
|
279
279
|
if (error) {
|
|
280
280
|
return (
|
|
281
|
-
<div className="
|
|
282
|
-
<p className="
|
|
283
|
-
<p className="
|
|
281
|
+
<div className="soma-page-error">
|
|
282
|
+
<p className="soma-page-error__title">Page failed to load</p>
|
|
283
|
+
<p className="soma-page-error__message">{error}</p>
|
|
284
284
|
</div>
|
|
285
285
|
);
|
|
286
286
|
}
|
|
@@ -288,7 +288,7 @@ function SomaPageRenderer({
|
|
|
288
288
|
return (
|
|
289
289
|
<>
|
|
290
290
|
{mounting && !error ? <SomaHydrationShell /> : null}
|
|
291
|
-
<div ref={containerRef} className={mounting && !error ? 'hidden' : undefined} />
|
|
291
|
+
<div ref={containerRef} className={mounting && !error ? 'soma-hidden' : undefined} />
|
|
292
292
|
</>
|
|
293
293
|
);
|
|
294
294
|
}
|
|
@@ -108,13 +108,13 @@ export async function SomaHostPage({
|
|
|
108
108
|
const message = await readRejectedMessage(rejected);
|
|
109
109
|
return (
|
|
110
110
|
<main
|
|
111
|
-
className="
|
|
111
|
+
className="soma-request-rejected"
|
|
112
112
|
data-soma-request-rejected={rejected.status}
|
|
113
113
|
>
|
|
114
|
-
<section className="
|
|
115
|
-
<p className="
|
|
116
|
-
<h1 className="
|
|
117
|
-
<p className="
|
|
114
|
+
<section className="soma-request-rejected__panel">
|
|
115
|
+
<p className="soma-request-rejected__eyebrow">HTTP {rejected.status}</p>
|
|
116
|
+
<h1 className="soma-request-rejected__title">Request rejected</h1>
|
|
117
|
+
<p className="soma-request-rejected__message">{message}</p>
|
|
118
118
|
</section>
|
|
119
119
|
</main>
|
|
120
120
|
);
|
|
@@ -5,18 +5,15 @@
|
|
|
5
5
|
export function SomaHydrationShell() {
|
|
6
6
|
return (
|
|
7
7
|
<div
|
|
8
|
-
className="
|
|
8
|
+
className="soma-hydration-shell"
|
|
9
9
|
role="status"
|
|
10
10
|
aria-live="polite"
|
|
11
11
|
aria-busy="true"
|
|
12
12
|
data-soma-hydration="pending"
|
|
13
13
|
>
|
|
14
|
-
<div className="
|
|
15
|
-
<div
|
|
16
|
-
|
|
17
|
-
aria-hidden
|
|
18
|
-
/>
|
|
19
|
-
<p className="text-sm text-gray-600">Loading page…</p>
|
|
14
|
+
<div className="soma-hydration-shell__content">
|
|
15
|
+
<div className="soma-hydration-shell__spinner" aria-hidden />
|
|
16
|
+
<p className="soma-hydration-shell__label">Loading page…</p>
|
|
20
17
|
</div>
|
|
21
18
|
</div>
|
|
22
19
|
);
|
package/app/globals.css
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* SOMA core shell styles.
|
|
3
|
+
*
|
|
4
|
+
* This file deliberately contains no framework-specific utility compiler.
|
|
5
|
+
* Business applications may add their own stylesheet/toolchain in their
|
|
6
|
+
* owning Next host; SOMA's runtime and official components do not require it.
|
|
7
|
+
*/
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: light;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
*,
|
|
13
|
+
*::before,
|
|
14
|
+
*::after {
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
html,
|
|
19
|
+
body {
|
|
20
|
+
min-height: 100%;
|
|
21
|
+
margin: 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
body {
|
|
25
|
+
background: var(--soma-bg-page, #f8fafc);
|
|
26
|
+
color: var(--soma-text-primary, #1f2937);
|
|
27
|
+
font-family: var(--soma-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
button,
|
|
31
|
+
input,
|
|
32
|
+
textarea,
|
|
33
|
+
select {
|
|
34
|
+
font: inherit;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.soma-hidden {
|
|
38
|
+
display: none !important;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.soma-hydration-shell {
|
|
42
|
+
display: grid;
|
|
43
|
+
min-block-size: 100dvh;
|
|
44
|
+
place-items: center;
|
|
45
|
+
background: var(--soma-bg-page, #f8fafc);
|
|
46
|
+
color: var(--soma-text-primary, #374151);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.soma-hydration-shell__content {
|
|
50
|
+
text-align: center;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.soma-hydration-shell__spinner {
|
|
54
|
+
inline-size: 2rem;
|
|
55
|
+
block-size: 2rem;
|
|
56
|
+
margin: 0 auto var(--soma-space-3, 0.75rem);
|
|
57
|
+
border: 2px solid var(--soma-c-primary, #2563eb);
|
|
58
|
+
border-block-start-color: transparent;
|
|
59
|
+
border-radius: 999px;
|
|
60
|
+
animation: soma-core-spin 0.9s linear infinite;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.soma-hydration-shell__label {
|
|
64
|
+
margin: 0;
|
|
65
|
+
color: var(--soma-text-secondary, #4b5563);
|
|
66
|
+
font-size: var(--soma-font-size-sm, 0.875rem);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.soma-request-rejected {
|
|
70
|
+
min-block-size: 100dvh;
|
|
71
|
+
padding: 4rem 1.5rem;
|
|
72
|
+
background: var(--soma-bg-page, #f8fafc);
|
|
73
|
+
color: var(--soma-text-primary, #0f172a);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.soma-request-rejected__panel {
|
|
77
|
+
max-inline-size: 36rem;
|
|
78
|
+
margin-inline: auto;
|
|
79
|
+
padding: var(--soma-space-6, 1.5rem);
|
|
80
|
+
border: 1px solid var(--soma-border, #e2e8f0);
|
|
81
|
+
background: var(--soma-bg-elevated, #fff);
|
|
82
|
+
box-shadow: var(--soma-shadow-sm, 0 1px 2px rgb(15 23 42 / 0.08));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.soma-request-rejected__eyebrow {
|
|
86
|
+
margin: 0;
|
|
87
|
+
color: var(--soma-text-muted, #64748b);
|
|
88
|
+
font-size: var(--soma-font-size-xs, 0.75rem);
|
|
89
|
+
font-weight: 600;
|
|
90
|
+
letter-spacing: 0.08em;
|
|
91
|
+
text-transform: uppercase;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.soma-request-rejected__title {
|
|
95
|
+
margin: var(--soma-space-2, 0.5rem) 0 0;
|
|
96
|
+
font-size: var(--soma-font-size-xl, 1.25rem);
|
|
97
|
+
font-weight: 600;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.soma-request-rejected__message {
|
|
101
|
+
margin: var(--soma-space-3, 0.75rem) 0 0;
|
|
102
|
+
color: var(--soma-text-secondary, #475569);
|
|
103
|
+
font-size: var(--soma-font-size-sm, 0.875rem);
|
|
104
|
+
line-height: 1.5;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.soma-page-error {
|
|
108
|
+
padding: var(--soma-space-8, 2rem);
|
|
109
|
+
color: var(--soma-c-danger-fg, #b91c1c);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.soma-page-error__title {
|
|
113
|
+
margin: 0;
|
|
114
|
+
font-weight: 700;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.soma-page-error__message {
|
|
118
|
+
margin: var(--soma-space-1, 0.25rem) 0 0;
|
|
119
|
+
font-size: var(--soma-font-size-sm, 0.875rem);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@keyframes soma-core-spin {
|
|
123
|
+
to {
|
|
124
|
+
transform: rotate(360deg);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 块编译总调度(REQ-005 F6.2):块声明 → 平铺等价产物。
|
|
2
2
|
//
|
|
3
|
-
// 这是"两级编译、单一运行时"
|
|
3
|
+
// 这是"两级编译、单一运行时"的落点:块声明只是更好写的书写层,编译后交给
|
|
4
4
|
// 既有引擎——运行时零新增、对块零感知。产出的 UiConfig / 事件清单 / 数据对象
|
|
5
|
-
//
|
|
5
|
+
// 与手写平铺声明完全同形,因此注册中心的写入闸门、预编译、eject 全部原样可用。
|
|
6
6
|
//
|
|
7
7
|
// 编译期做完的事(第零条公理:性能由引擎吸收):
|
|
8
8
|
// 开关探测 → 块装载 → 命名空间与别名整体展开 → 路径全名还原 →
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
13
13
|
import { buildHtmlAnchorIndex, type HtmlAnchorIndex } from './html-index';
|
|
14
|
-
import { PAGE_BLOCK_ID,
|
|
15
|
-
import { parsePageBlock } from '../../client/parser/
|
|
16
|
-
import { parseUseBlock, type UseBlockAst } from '../../client/parser/
|
|
14
|
+
import { PAGE_BLOCK_ID, SomaBlockParseError, loadSomaFile } from './block-container';
|
|
15
|
+
import { parsePageBlock } from '../../client/parser/blocks/page-parser';
|
|
16
|
+
import { parseUseBlock, type UseBlockAst } from '../../client/parser/blocks/use-parser';
|
|
17
17
|
|
|
18
|
-
export interface
|
|
19
|
-
/**
|
|
18
|
+
export interface CompiledSomaBlocks {
|
|
19
|
+
/** 平铺等价 UiConfig:直接交既有编译管线 */
|
|
20
20
|
ui: UiConfig;
|
|
21
|
-
/**
|
|
21
|
+
/** 平铺等价事件声明(DOM 事件 + timers/triggers + 组件 emit 路由) */
|
|
22
22
|
event: Record<string, unknown>;
|
|
23
23
|
/** 数据对象声明(页面级 + 各块私有,已带全局身份) */
|
|
24
24
|
data: Record<string, unknown>;
|
|
@@ -27,7 +27,7 @@ export interface CompiledSomaV2 {
|
|
|
27
27
|
htmlIndex: HtmlAnchorIndex;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export interface
|
|
30
|
+
export interface CompileSomaBlocksInput {
|
|
31
31
|
html: string;
|
|
32
32
|
uiYamlRaw: string;
|
|
33
33
|
/** 外置块:锚点名 → 块体原文(服务端由 loadExternalBlocks 提供) */
|
|
@@ -37,15 +37,15 @@ export interface CompileSomaV2Input {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* 编译一份块声明。
|
|
41
41
|
*
|
|
42
42
|
* 本函数只接受 canonical 声明,不做旧页面形状回退;旧输入会在开关校验处明确报错。
|
|
43
43
|
*/
|
|
44
|
-
export function
|
|
44
|
+
export function compileSomaBlocks(input: CompileSomaBlocksInput): CompiledSomaBlocks {
|
|
45
45
|
const htmlIndex = buildHtmlAnchorIndex(input.html);
|
|
46
46
|
|
|
47
47
|
if (htmlIndex.duplicates.length > 0) {
|
|
48
|
-
throw new
|
|
48
|
+
throw new SomaBlockParseError(
|
|
49
49
|
`HTML 锚点重复:${htmlIndex.duplicates.join('、')}——页面内 data-soma-id 必须唯一`,
|
|
50
50
|
);
|
|
51
51
|
}
|
|
@@ -58,7 +58,7 @@ export function compileSomaV2(input: CompileSomaV2Input): CompiledSomaV2 {
|
|
|
58
58
|
|
|
59
59
|
const pageRaw = rawBlocks.find((block) => block.blockId === PAGE_BLOCK_ID);
|
|
60
60
|
if (!pageRaw) {
|
|
61
|
-
throw new
|
|
61
|
+
throw new SomaBlockParseError('缺少 page 块(页面必须声明 domain)');
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const anchors = new Set(htmlIndex.anchors.keys());
|
|
@@ -95,7 +95,7 @@ export function compileSomaV2(input: CompileSomaV2Input): CompiledSomaV2 {
|
|
|
95
95
|
// props 并入 show:行内组件挂到它所属列表的子 show 下,其余挂顶层
|
|
96
96
|
attachInstance(ui, raw.blockId, ast, htmlIndex);
|
|
97
97
|
|
|
98
|
-
// emit
|
|
98
|
+
// emit 路由并入事件清单:平铺形状是 "实例id.emit名"
|
|
99
99
|
for (const [emitName, expr] of Object.entries(ast.emitRoutes)) {
|
|
100
100
|
event[`${raw.blockId}.${emitName}`] = expr;
|
|
101
101
|
}
|
|
@@ -166,7 +166,7 @@ function attachInstance(
|
|
|
166
166
|
// 行内组件收不到行数据,页面不报错只是空白(cart 页实测踩到过)。
|
|
167
167
|
const owner = info.ownerList;
|
|
168
168
|
if (!owner) {
|
|
169
|
-
throw new
|
|
169
|
+
throw new SomaBlockParseError(
|
|
170
170
|
`实例 "${blockId}" 位于行模板内,但 HTML 里找不到它所属的列表锚点`,
|
|
171
171
|
blockId,
|
|
172
172
|
);
|
|
@@ -174,7 +174,7 @@ function attachInstance(
|
|
|
174
174
|
|
|
175
175
|
const target = findListShow(ui.show as Record<string, unknown>, owner);
|
|
176
176
|
if (!target) {
|
|
177
|
-
throw new
|
|
177
|
+
throw new SomaBlockParseError(
|
|
178
178
|
`实例 "${blockId}" 属于列表 "${owner}",但 page 块没有为该列表声明 each 作用域`,
|
|
179
179
|
blockId,
|
|
180
180
|
);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 块容器 · 开关探测与块装载(REQ-005 F1.1 / F1.2)。
|
|
2
2
|
//
|
|
3
|
-
// 容器形态(规格书 §1):`_ui.yaml` 首行 `{{`、末行 `}}` 是
|
|
3
|
+
// 容器形态(规格书 §1):`_ui.yaml` 首行 `{{`、末行 `}}` 是 **块声明开关**,
|
|
4
4
|
// 开关之内是纯 YAML 的块集合(顶层键 = 块 id)。
|
|
5
5
|
//
|
|
6
6
|
// 三条设计后果,都是刻意的:
|
|
7
|
-
// ①
|
|
7
|
+
// ① 不新增文件类型——四件套存储、注册中心的写入闸门、eject 全部零改动;
|
|
8
8
|
// ② 开关内是合法 YAML——编辑器/格式化/LSP/AI 先验零成本兑现,
|
|
9
9
|
// 所以这里用标准 YAML 装载,不写自造容器解析器;
|
|
10
10
|
// ③ 版本探测只看首个非注释行——比嗅探文件内容结构干净得多。
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import yaml from 'js-yaml';
|
|
16
16
|
import type { HtmlAnchorIndex } from './html-index';
|
|
17
17
|
|
|
18
|
-
export class
|
|
18
|
+
export class SomaBlockParseError extends Error {
|
|
19
19
|
constructor(
|
|
20
20
|
message: string,
|
|
21
21
|
readonly blockId?: string,
|
|
@@ -23,7 +23,7 @@ export class SomaV2ParseError extends Error {
|
|
|
23
23
|
) {
|
|
24
24
|
const where = blockId ? `(块: ${blockId}${line ? `,第 ${line} 行` : ''})` : '';
|
|
25
25
|
super(`[soma-core][引擎] ${message}${where}`);
|
|
26
|
-
this.name = '
|
|
26
|
+
this.name = 'SomaBlockParseError';
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -57,13 +57,13 @@ function stripSwitch(uiYamlRaw: string): { inner: string; offset: number } {
|
|
|
57
57
|
const text = lines[i].trim();
|
|
58
58
|
if (text === '' || text.startsWith('#')) continue;
|
|
59
59
|
if (text !== '{{') {
|
|
60
|
-
throw new
|
|
60
|
+
throw new SomaBlockParseError('块声明必须以 `{{` 开关行开头');
|
|
61
61
|
}
|
|
62
62
|
openIndex = i;
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
if (openIndex === -1) {
|
|
66
|
-
throw new
|
|
66
|
+
throw new SomaBlockParseError('文件为空或只有注释,找不到 `{{` 开关行');
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
let closeIndex = -1;
|
|
@@ -71,13 +71,13 @@ function stripSwitch(uiYamlRaw: string): { inner: string; offset: number } {
|
|
|
71
71
|
const text = lines[i].trim();
|
|
72
72
|
if (text === '') continue;
|
|
73
73
|
if (text !== '}}') {
|
|
74
|
-
throw new
|
|
74
|
+
throw new SomaBlockParseError('块声明必须以 `}}` 收口行结尾(开关成对,整文件一对)');
|
|
75
75
|
}
|
|
76
76
|
closeIndex = i;
|
|
77
77
|
break;
|
|
78
78
|
}
|
|
79
79
|
if (closeIndex === -1) {
|
|
80
|
-
throw new
|
|
80
|
+
throw new SomaBlockParseError('`{{` 开关未闭合——缺少 `}}` 收口行');
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
return {
|
|
@@ -86,40 +86,40 @@ function stripSwitch(uiYamlRaw: string): { inner: string; offset: number } {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
interface
|
|
89
|
+
interface SomaBlockContainer {
|
|
90
90
|
doc: Record<string, unknown>;
|
|
91
91
|
inner: string;
|
|
92
92
|
offset: number;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
* 只校验
|
|
96
|
+
* 只校验 单文件块容器本身,不依赖 HTML 锚点。
|
|
97
97
|
*
|
|
98
98
|
* Bundler 的单文件 loader 拿不到同页 HTML,只能在这里确认开关成对、内层 YAML
|
|
99
|
-
* 可解析且顶层是块映射;块 id 与 HTML 的对账仍由页面级
|
|
99
|
+
* 可解析且顶层是块映射;块 id 与 HTML 的对账仍由页面级 compileSomaBlocks 完成。
|
|
100
100
|
*/
|
|
101
|
-
export function
|
|
101
|
+
export function parseSomaBlockContainer(uiYamlRaw: string): SomaBlockContainer {
|
|
102
102
|
const { inner, offset } = stripSwitch(uiYamlRaw);
|
|
103
103
|
|
|
104
104
|
let doc: unknown;
|
|
105
105
|
try {
|
|
106
106
|
doc = yaml.load(inner);
|
|
107
107
|
} catch (error) {
|
|
108
|
-
throw new
|
|
108
|
+
throw new SomaBlockParseError(`YAML 解析失败: ${(error as Error).message}`);
|
|
109
109
|
}
|
|
110
110
|
if (doc === null || doc === undefined) {
|
|
111
111
|
return { doc: {}, inner, offset };
|
|
112
112
|
}
|
|
113
113
|
if (typeof doc !== 'object' || Array.isArray(doc)) {
|
|
114
|
-
throw new
|
|
114
|
+
throw new SomaBlockParseError('开关内必须是块映射(顶层键 = 块 id)');
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
for (const [blockId, body] of Object.entries(doc as Record<string, unknown>)) {
|
|
118
118
|
if (body === null || body === undefined) {
|
|
119
|
-
throw new
|
|
119
|
+
throw new SomaBlockParseError('块体为空——不需要声明的组件请直接删掉这个块', blockId);
|
|
120
120
|
}
|
|
121
121
|
if (typeof body !== 'object' || Array.isArray(body)) {
|
|
122
|
-
throw new
|
|
122
|
+
throw new SomaBlockParseError('块体必须是映射(ui/data/event 三段)', blockId);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -127,13 +127,13 @@ export function parseSomaV2Container(uiYamlRaw: string): SomaV2Container {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
*
|
|
130
|
+
* 装载块声明文件:开关剥离 → YAML 装载 → 块 id 校验 → 外置块合流。
|
|
131
131
|
*
|
|
132
132
|
* 每条校验都对应一种"静默失效":写了不存在的锚点、同一实例声明两遍、
|
|
133
133
|
* 块挂在普通锚点上——不拦的话都表现为"这段声明没生效",而不报错。
|
|
134
134
|
*/
|
|
135
135
|
export function loadSomaFile(input: SomaFileLoadInput): RawBlock[] {
|
|
136
|
-
const { doc, inner, offset } =
|
|
136
|
+
const { doc, inner, offset } = parseSomaBlockContainer(input.uiYamlRaw);
|
|
137
137
|
if (Object.keys(doc).length === 0) return [];
|
|
138
138
|
|
|
139
139
|
const innerLines = inner.split('\n');
|
|
@@ -149,13 +149,13 @@ export function loadSomaFile(input: SomaFileLoadInput): RawBlock[] {
|
|
|
149
149
|
const line = lineOfKey(blockId);
|
|
150
150
|
assertBlockId(blockId, input.htmlIndex, line);
|
|
151
151
|
if (seen.has(blockId)) {
|
|
152
|
-
throw new
|
|
152
|
+
throw new SomaBlockParseError(`块 "${blockId}" 重复声明`, blockId, line);
|
|
153
153
|
}
|
|
154
154
|
if (body === null || body === undefined) {
|
|
155
|
-
throw new
|
|
155
|
+
throw new SomaBlockParseError('块体为空——不需要声明的组件请直接删掉这个块', blockId, line);
|
|
156
156
|
}
|
|
157
157
|
if (typeof body !== 'object' || Array.isArray(body)) {
|
|
158
|
-
throw new
|
|
158
|
+
throw new SomaBlockParseError('块体必须是映射(ui/data/event 三段)', blockId, line);
|
|
159
159
|
}
|
|
160
160
|
seen.add(blockId);
|
|
161
161
|
blocks.push({ blockId, body: body as Record<string, unknown>, line, source: 'inline' });
|
|
@@ -165,7 +165,7 @@ export function loadSomaFile(input: SomaFileLoadInput): RawBlock[] {
|
|
|
165
165
|
for (const [blockId, raw] of input.externalBlocks ?? new Map()) {
|
|
166
166
|
assertBlockId(blockId, input.htmlIndex, 0);
|
|
167
167
|
if (seen.has(blockId)) {
|
|
168
|
-
throw new
|
|
168
|
+
throw new SomaBlockParseError(
|
|
169
169
|
`块 "${blockId}" 同时存在于 _ui.yaml 与 blocks/${blockId}.yaml——一个实例只能有一个声明处`,
|
|
170
170
|
blockId,
|
|
171
171
|
);
|
|
@@ -174,16 +174,16 @@ export function loadSomaFile(input: SomaFileLoadInput): RawBlock[] {
|
|
|
174
174
|
try {
|
|
175
175
|
body = yaml.load(raw);
|
|
176
176
|
} catch (error) {
|
|
177
|
-
throw new
|
|
177
|
+
throw new SomaBlockParseError(
|
|
178
178
|
`外置块 blocks/${blockId}.yaml 解析失败: ${(error as Error).message}`,
|
|
179
179
|
blockId,
|
|
180
180
|
);
|
|
181
181
|
}
|
|
182
182
|
if (body === null || body === undefined) {
|
|
183
|
-
throw new
|
|
183
|
+
throw new SomaBlockParseError(`外置块 blocks/${blockId}.yaml 为空`, blockId);
|
|
184
184
|
}
|
|
185
185
|
if (typeof body !== 'object' || Array.isArray(body)) {
|
|
186
|
-
throw new
|
|
186
|
+
throw new SomaBlockParseError(`外置块 blocks/${blockId}.yaml 必须是映射`, blockId);
|
|
187
187
|
}
|
|
188
188
|
seen.add(blockId);
|
|
189
189
|
blocks.push({ blockId, body: body as Record<string, unknown>, line: 1, source: 'external' });
|
|
@@ -199,7 +199,7 @@ function assertBlockId(blockId: string, htmlIndex: HtmlAnchorIndex, line: number
|
|
|
199
199
|
|
|
200
200
|
// 分两种错法给不同指引——"锚点不存在"与"锚点不是组件实例"是两个问题
|
|
201
201
|
if (htmlIndex.anchors.has(blockId)) {
|
|
202
|
-
throw new
|
|
202
|
+
throw new SomaBlockParseError(
|
|
203
203
|
`"${blockId}" 是普通锚点,不能作为组件块——`
|
|
204
204
|
+ '组件块只能挂在带 data-soma-component 的实例锚点上;'
|
|
205
205
|
+ '普通锚点的绑定写在 page 块的 ui: 段',
|
|
@@ -208,7 +208,7 @@ function assertBlockId(blockId: string, htmlIndex: HtmlAnchorIndex, line: number
|
|
|
208
208
|
);
|
|
209
209
|
}
|
|
210
210
|
const known = [...htmlIndex.instances].slice(0, 8).join('、');
|
|
211
|
-
throw new
|
|
211
|
+
throw new SomaBlockParseError(
|
|
212
212
|
`HTML 里没有实例锚点 "${blockId}"${known ? `(现有实例:${known})` : ''}`,
|
|
213
213
|
blockId,
|
|
214
214
|
line,
|