soma-core 1.4.2 → 1.5.1
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/bin/component.cjs +240 -0
- package/bin/eject.cjs +174 -0
- package/bin/migrate.cjs +362 -0
- package/core/build/blocks/block-compile.ts +143 -17
- package/core/build/blocks/migrate-flat.ts +118 -25
- package/core/build/compiler/page-declaration-compiler.ts +149 -5
- package/core/build/compiler/route-builder.ts +0 -4
- package/core/build/compiler/soma-precompile.js +431 -26
- package/core/build/component/component-graph.ts +28 -105
- package/core/build/component/package-loader.ts +18 -4
- package/core/build/eject/component-eject.ts +8 -2
- package/core/build/layout/constraint-solver.ts +131 -16
- package/core/build/layout/css-emitter.ts +29 -10
- package/core/build/ooui/artifact/artifact.types.ts +275 -0
- package/core/build/ooui/artifact/emit-artifact.ts +269 -0
- package/core/build/ooui/artifact/emit-html.ts +204 -0
- package/core/build/ooui/artifact/index.ts +53 -0
- package/core/build/ooui/artifact/spatial-tree.ts +268 -0
- package/core/build/ooui/artifact/utility-class.ts +83 -0
- package/core/build/ooui/composition/candidate.types.ts +323 -0
- package/core/build/ooui/composition/control-model.ts +114 -0
- package/core/build/ooui/composition/registry.ts +520 -0
- package/core/build/ooui/composition/select.ts +232 -0
- package/core/build/ooui/diagnostics/codes.ts +230 -0
- package/core/build/ooui/diagnostics/error.ts +235 -0
- package/core/build/ooui/diagnostics/format.ts +106 -0
- package/core/build/ooui/diagnostics/index.ts +62 -0
- package/core/build/ooui/diagnostics/issue.types.ts +112 -0
- package/core/build/ooui/engine-slot.ts +184 -0
- package/core/build/ooui/index.ts +1427 -0
- package/core/build/ooui/intent/derive-intent.ts +450 -0
- package/core/build/ooui/intent/field-rules.ts +330 -0
- package/core/build/ooui/intent/intent.types.ts +476 -0
- package/core/build/ooui/intent/verb-events.ts +285 -0
- package/core/build/ooui/page/budget.ts +503 -0
- package/core/build/ooui/page/compose-page.ts +736 -0
- package/core/build/ooui/page/index.ts +66 -0
- package/core/build/ooui/page/page.types.ts +402 -0
- package/core/build/ooui/page/region-row.ts +241 -0
- package/core/build/ooui/semantic/expand-page-surface.ts +180 -0
- package/core/build/ooui/semantic/kernel.types.ts +187 -0
- package/core/build/ooui/semantic/normalize.ts +784 -0
- package/core/build/ooui/semantic/origin.types.ts +211 -0
- package/core/build/ooui/semantic/role-alias.ts +154 -0
- package/core/build/ooui/semantic/shorthand.ts +233 -0
- package/core/build/ooui/semantic/surface.types.ts +78 -0
- package/core/build/ooui/semantic/validate-request.ts +267 -0
- package/core/build/ooui/spatial/emit-utility.ts +480 -0
- package/core/build/ooui/spatial/ir.types.ts +443 -0
- package/core/build/ooui/spatial/registry.ts +565 -0
- package/core/build/ooui/spatial/solve.ts +769 -0
- package/core/build/ooui/spatial/utility.types.ts +242 -0
- package/core/build/ooui/trace/index.ts +40 -0
- package/core/build/ooui/trace/render.ts +190 -0
- package/core/build/ooui/trace/source.types.ts +69 -0
- package/core/build/ooui/trace/trace.types.ts +326 -0
- package/core/client/component/component-expander.ts +18 -3
- package/core/client/component/component-manager.ts +4 -0
- package/core/client/component/example-blocks.ts +1 -7
- package/core/client/component/theme-component-tokens.ts +12 -15
- package/core/client/component/verify-pack.ts +43 -0
- package/core/client/data/data-object-resolver.ts +27 -8
- package/core/client/diagnostics/telemetry-context.ts +0 -4
- package/core/client/engine/asset-resolver.ts +0 -1
- package/core/client/engine/event-engine.ts +7 -3
- package/core/client/engine/soma-bootstrap.ts +292 -34
- package/core/client/engine/style-binder.ts +0 -1
- package/core/client/infra/http/IHttpClient.ts +0 -6
- package/core/client/infra/http/SomaHttpService.ts +4 -1
- package/core/client/infra/notify/DomNotifyService.ts +1 -1
- package/core/client/infra/router/router-path.ts +0 -6
- package/core/client/parser/annotation-extractor.ts +1 -1
- package/core/client/parser/blocks/namespace.ts +30 -5
- package/core/client/parser/blocks/page-parser.ts +44 -1
- package/core/client/parser/blocks/use-parser.ts +266 -46
- package/core/client/parser/data-config-parser.ts +71 -3
- package/core/client/parser/layout-parser.ts +4 -3
- package/core/client/parser/reaction-parser.ts +0 -1
- package/core/client/parser/ui-config-parser.ts +212 -74
- package/core/client/theme/scene-tokens.ts +9 -3
- package/core/client/theme/theme-axes.ts +74 -16
- package/core/client/theme/theme-engine.ts +341 -70
- package/core/client/theme/tone-solver.ts +9 -8
- package/core/index.ts +24 -5
- package/core/server/api/load-host-service.ts +8 -2
- package/core/server/declaration-safety.ts +11 -0
- package/core/server/host/page-response-request.ts +0 -2
- package/core/server/host/published-page-artifact-cache.ts +244 -0
- package/core/server/host/published-page-assets.ts +44 -5
- package/core/server/mock/node/cli.mjs +0 -1
- package/core/server/mock/node/schema-generator.mjs +0 -1
- package/core/server/ooui.ts +34 -0
- package/core/server/page-assets.ts +8 -0
- package/core/server/page-declaration.ts +18 -0
- package/core/server/registry/asset-store.ts +327 -0
- package/core/server/registry/declaration-precompiler.ts +49 -6
- package/core/server/registry/index.ts +47 -1
- package/core/server/registry/page-registry-repository.ts +6 -2
- package/core/server/registry/page-registry-store.ts +133 -19
- package/core/server/registry/publish-asset-pin.ts +557 -0
- package/core/server/registry/services/pages/List.ts +15 -3
- package/core/server/registry/validation/compile-gate.ts +180 -8
- package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
- package/core/shared/component/derive-sample.ts +201 -16
- package/core/shared/component/field-lines.ts +98 -8
- package/core/shared/container-breakpoints.ts +46 -0
- package/core/shared/object-semantics.ts +240 -0
- package/core/shared/ooui-declaration.ts +235 -0
- package/core/shared/types/component-contract.types.ts +7 -6
- package/core/shared/types/data-config.types.ts +95 -0
- package/core/shared/types/domain.types.ts +0 -24
- package/core/shared/types/engine.types.ts +0 -5
- package/core/shared/types/layout-constraint.types.ts +16 -0
- package/core/shared/types/ui-config.types.ts +163 -13
- package/dist/cli/soma.js +24 -11
- package/dist/core/index.cjs +1829 -1028
- package/dist/types/build/blocks/block-compile.d.ts +16 -1
- package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/component/component-graph.d.ts +17 -53
- package/dist/types/build/component/package-loader.d.ts +8 -1
- package/dist/types/build/layout/constraint-solver.d.ts +46 -4
- package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
- package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
- package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
- package/dist/types/build/ooui/artifact/index.d.ts +5 -0
- package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
- package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
- package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
- package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
- package/dist/types/build/ooui/composition/registry.d.ts +66 -0
- package/dist/types/build/ooui/composition/select.d.ts +63 -0
- package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
- package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
- package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
- package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
- package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
- package/dist/types/build/ooui/engine-slot.d.ts +41 -0
- package/dist/types/build/ooui/index.d.ts +286 -0
- package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
- package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
- package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
- package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
- package/dist/types/build/ooui/page/budget.d.ts +28 -0
- package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
- package/dist/types/build/ooui/page/index.d.ts +4 -0
- package/dist/types/build/ooui/page/page.types.d.ts +264 -0
- package/dist/types/build/ooui/page/region-row.d.ts +16 -0
- package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
- package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
- package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
- package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
- package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
- package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
- package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
- package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
- package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
- package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
- package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
- package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
- package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
- package/dist/types/build/ooui/trace/index.d.ts +3 -0
- package/dist/types/build/ooui/trace/render.d.ts +42 -0
- package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
- package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
- package/dist/types/client/component/component-expander.d.ts +1 -0
- package/dist/types/client/component/example-blocks.d.ts +0 -2
- package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
- package/dist/types/client/data/data-object-resolver.d.ts +10 -2
- package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
- package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
- package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
- package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
- package/dist/types/client/infra/router/router-path.d.ts +0 -2
- package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
- package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
- package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
- package/dist/types/client/parser/data-config-parser.d.ts +13 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
- package/dist/types/client/theme/scene-tokens.d.ts +9 -3
- package/dist/types/client/theme/theme-axes.d.ts +64 -1
- package/dist/types/client/theme/theme-engine.d.ts +13 -8
- package/dist/types/client/theme/tone-solver.d.ts +9 -5
- package/dist/types/index.d.ts +4 -6
- package/dist/types/server/declaration-safety.d.ts +7 -0
- package/dist/types/server/host/page-response-request.d.ts +0 -1
- package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
- package/dist/types/server/ooui.d.ts +18 -0
- package/dist/types/server/page-assets.d.ts +7 -0
- package/dist/types/server/page-declaration.d.ts +14 -0
- package/dist/types/server/registry/asset-store.d.ts +112 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
- package/dist/types/server/registry/index.d.ts +3 -1
- package/dist/types/server/registry/page-registry-store.d.ts +57 -4
- package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
- package/dist/types/server/registry/services/pages/List.d.ts +9 -3
- package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
- package/dist/types/shared/component/derive-sample.d.ts +14 -0
- package/dist/types/shared/container-breakpoints.d.ts +42 -0
- package/dist/types/shared/object-semantics.d.ts +42 -0
- package/dist/types/shared/ooui-declaration.d.ts +135 -0
- package/dist/types/shared/types/component-contract.types.d.ts +7 -6
- package/dist/types/shared/types/data-config.types.d.ts +86 -0
- package/dist/types/shared/types/domain.types.d.ts +0 -21
- package/dist/types/shared/types/engine.types.d.ts +0 -4
- package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
- package/dist/types/shared/types/ui-config.types.d.ts +157 -12
- package/next.config.js +106 -13
- package/package.json +29 -2
- package/core/client/host-bridge/index.ts +0 -27
- package/core/client/parser/yaml-loader.ts +0 -36
- package/core/shared/manifest/manifest-contract.ts +0 -12
- package/dist/types/client/host-bridge/index.d.ts +0 -9
- package/dist/types/client/parser/yaml-loader.d.ts +0 -21
- package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
|
@@ -33,11 +33,8 @@ import type { SomaTimerEngine } from './timer-engine';
|
|
|
33
33
|
import { createDefaultRuntimeServices } from '../runtime/SomaRuntimeServices';
|
|
34
34
|
import { getBrowserUrlPath, readQueryParam } from '../infra/router/router-path';
|
|
35
35
|
import { parseDataYaml } from '../parser/data-config-parser';
|
|
36
|
-
import { SomaDataObjectResolver } from '../data/data-object-resolver';
|
|
37
|
-
import type {
|
|
38
|
-
SomaDataPort,
|
|
39
|
-
SomaDataSubmitResult,
|
|
40
|
-
} from '../../shared/types/data-config.types';
|
|
36
|
+
import { SomaDataObjectResolver, createSomaDataPort } from '../data/data-object-resolver';
|
|
37
|
+
import type { SomaDataPort } from '../../shared/types/data-config.types';
|
|
41
38
|
import type { SomaDataConfig, SomaDataDicts } from '../../shared/types/data-config.types';
|
|
42
39
|
import type { WatchCallback, WatcherOptions } from '../../shared/types/watcher.types';
|
|
43
40
|
import type { SomaStepGraph } from '../../shared/types/step.types';
|
|
@@ -54,6 +51,7 @@ import {
|
|
|
54
51
|
import { validateStyleFeatures } from '../component/style-features';
|
|
55
52
|
import { SomaPipeRegistry, type SomaPipeFn } from '../pipes/pipe-registry';
|
|
56
53
|
import { applyTheme, type SomaThemeInput } from '../theme/theme-engine';
|
|
54
|
+
import { validateThemeComponentTokens } from '../component/theme-component-tokens';
|
|
57
55
|
import {
|
|
58
56
|
installSomaErrorReporter,
|
|
59
57
|
type SomaErrorEvent,
|
|
@@ -115,6 +113,98 @@ function isSomaDeclarationSource(value: string): boolean {
|
|
|
115
113
|
});
|
|
116
114
|
}
|
|
117
115
|
|
|
116
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
117
|
+
// OOUI 演绎产物的注入面(REQ-014 最后一公里)
|
|
118
|
+
//
|
|
119
|
+
// 这三个常量与两个函数是**运行时那道结构闸门**的全部判据。它们刻意做成模块级
|
|
120
|
+
// 纯函数:闸门必须能对着"外面拿来的一份 html"单独跑,否则"引擎不产生内联事件
|
|
121
|
+
// 处理器"这句话在运行时这一侧就只是一句没人验证过的话
|
|
122
|
+
// (构建期那一侧是 `core/build/ooui/artifact/emit-html.ts` 的 `verifyArtifactHtml`)。
|
|
123
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 演绎区域已注入的标记。值是这份 html 的**内容指纹**,不是布尔。
|
|
127
|
+
*
|
|
128
|
+
* 布尔标记的坏法:同一个锚点换了一份产物会被当成"已经注入过了"而跳过,
|
|
129
|
+
* 页面继续显示上一版 DOM——渲染正常、内容是旧的、控制台一行都没有。
|
|
130
|
+
* 与产物侧 `css_key` 用内容哈希是同一条理由,只是这一侧的作用域是单个锚点。
|
|
131
|
+
*/
|
|
132
|
+
export const SOMA_OOUI_REGION_ATTR = 'data-soma-ooui';
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 产物 DOM 的标签允许集。**这就是 `emitRegionHtml` 今天产出的全集**
|
|
136
|
+
* (区域外壳恒为 `div`,根构件是组件时 `div`、是纯文本节点时 `span`)。
|
|
137
|
+
*
|
|
138
|
+
* 为什么是允许集不是禁用集:产物只有两种标签,禁用集只挡得住今天想得到的那几样,
|
|
139
|
+
* 而允许集把"想不到的那些"一并挡住。代价是发射器加新标签时这里会红——
|
|
140
|
+
* 那正是要的:红在写下的那天,而不是在某份被改过的资产送进 innerHTML 的那天。
|
|
141
|
+
*/
|
|
142
|
+
export const SOMA_OOUI_ALLOWED_TAGS: ReadonlySet<string> = new Set(['DIV', 'SPAN']);
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 产物 DOM 的属性允许集(HTML 解析器会把属性名小写化,所以只写小写)。
|
|
146
|
+
*
|
|
147
|
+
* `on*`、`src`/`href` 这类属性一个都不在里面——引擎从不产出它们
|
|
148
|
+
* (事件走 `eventConfig`,不进 DOM 属性;架构 §24.1),所以它们出现在这里
|
|
149
|
+
* 只有一个含义:这份产物不是编译器产的。
|
|
150
|
+
*/
|
|
151
|
+
export const SOMA_OOUI_ALLOWED_ATTRS: ReadonlySet<string> = new Set([
|
|
152
|
+
'class', 'data-soma-node', 'data-soma-id', 'data-soma-component',
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 结构闸门:返回 `null` 表示这份 DOM 就是产物该有的样子,否则返回违规描述。
|
|
157
|
+
*
|
|
158
|
+
* 三条判据:
|
|
159
|
+
* ① 顶层恰好一个元素(`emitRegionHtml` 恒产出单个区域外壳)。
|
|
160
|
+
* 不查这条的话,一份"外壳 + 一段裸文本"的产物会被照单全收,
|
|
161
|
+
* 而多出来的那段文本在页面上只是多了一行字。
|
|
162
|
+
* ② 每个元素的标签在允许集内;
|
|
163
|
+
* ③ 每个属性名在允许集内。
|
|
164
|
+
*/
|
|
165
|
+
export function findOouiDomOffence(fragment: DocumentFragment): string | null {
|
|
166
|
+
const roots = fragment.children;
|
|
167
|
+
if (roots.length !== 1) {
|
|
168
|
+
return `顶层元素有 ${roots.length} 个,产物恒为单个区域外壳`;
|
|
169
|
+
}
|
|
170
|
+
for (const node of Array.from(fragment.childNodes)) {
|
|
171
|
+
// 元素之外的顶层节点(裸文本、注释)一律拒收。发射器只产出一个外壳元素,
|
|
172
|
+
// 多出来的那一段在页面上只是"莫名其妙多了一行字"——没人会把它报成 bug。
|
|
173
|
+
// 纯空白放行:YAML 的块标量可能带一个尾换行,那不是内容。
|
|
174
|
+
if (node.nodeType !== 1 && (node.textContent ?? '').trim() !== '') {
|
|
175
|
+
return `顶层混有元素以外的节点(nodeType ${node.nodeType})`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (const element of Array.from(fragment.querySelectorAll('*'))) {
|
|
179
|
+
if (!SOMA_OOUI_ALLOWED_TAGS.has(element.tagName)) {
|
|
180
|
+
return `标签 <${element.tagName.toLowerCase()}>`;
|
|
181
|
+
}
|
|
182
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
183
|
+
if (!SOMA_OOUI_ALLOWED_ATTRS.has(attribute.name)) {
|
|
184
|
+
return `属性 ${attribute.name}`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 产物 html 的内容指纹(FNV-1a 32 位,8 位十六进制)。
|
|
193
|
+
*
|
|
194
|
+
* **不是安全边界**,只回答"这个锚点上挂的还是不是同一份产物"——
|
|
195
|
+
* 安全由上面那道结构闸门负责。所以这里不用 sha256:浏览器侧拿不到 node:crypto,
|
|
196
|
+
* 而 `crypto.subtle.digest` 是异步的,为一次同步的"变没变"判断引入异步
|
|
197
|
+
* 会把注入挪到组件展开之后(见 mount 的 2.4 与 2.5 的顺序)。
|
|
198
|
+
*/
|
|
199
|
+
export function oouiHtmlFingerprint(html: string): string {
|
|
200
|
+
let hash = 0x811c9dc5;
|
|
201
|
+
for (let index = 0; index < html.length; index += 1) {
|
|
202
|
+
hash ^= html.charCodeAt(index);
|
|
203
|
+
hash = Math.imul(hash, 0x01000193);
|
|
204
|
+
}
|
|
205
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
206
|
+
}
|
|
207
|
+
|
|
118
208
|
/**
|
|
119
209
|
* 错误采集接线声明(可观测性,默认关闭)。
|
|
120
210
|
*
|
|
@@ -320,6 +410,14 @@ export class SomaBootstrap {
|
|
|
320
410
|
// 2. 挂载 HTML
|
|
321
411
|
this.adapter.mount(container, this.assets.html, this.assets.includes);
|
|
322
412
|
|
|
413
|
+
// 2.4 演绎产物的 DOM 落点(REQ-014 最后一公里)。
|
|
414
|
+
// **必须在 2.5 之前**:演绎出的根构件带 `data-soma-component`,
|
|
415
|
+
// 而组件展开是一次性扫描 `container.querySelectorAll('[data-soma-component]')`。
|
|
416
|
+
// 插在它之后的话,演绎出来的组件不会被展开——DOM 在、锚点在、
|
|
417
|
+
// `data-soma-component` 属性也在,只是那个组件的模板永远不注入,
|
|
418
|
+
// 页面上就是一个空 div,没有异常也没有日志。
|
|
419
|
+
this.installOouiHtml(container, parsed.uiConfig);
|
|
420
|
+
|
|
323
421
|
// 2.5 组件展开(页面引擎构建前:模板注入、锚点作用域化、插槽投影)
|
|
324
422
|
this.setupComponentManager(container, this.assets, parsed.uiConfig);
|
|
325
423
|
|
|
@@ -403,6 +501,9 @@ export class SomaBootstrap {
|
|
|
403
501
|
this.componentManager = null;
|
|
404
502
|
|
|
405
503
|
this.adapter.mount(this.container, merged.html, merged.includes);
|
|
504
|
+
// 与 mount 同序:演绎 DOM 先落,组件展开后扫。热替换换的是整份 innerHTML,
|
|
505
|
+
// 上一版的区域连同它的已注入标记一起没了,所以这里必然是一次真注入。
|
|
506
|
+
this.installOouiHtml(this.container, parsed.uiConfig);
|
|
406
507
|
this.setupComponentManager(this.container, merged, parsed.uiConfig);
|
|
407
508
|
|
|
408
509
|
if (overrides.DomainClass) {
|
|
@@ -747,6 +848,7 @@ export class SomaBootstrap {
|
|
|
747
848
|
if (!theme?.brand) {
|
|
748
849
|
return;
|
|
749
850
|
}
|
|
851
|
+
this.reconcileThemeComponentTokens(theme);
|
|
750
852
|
try {
|
|
751
853
|
applyTheme(theme);
|
|
752
854
|
} catch (error) {
|
|
@@ -755,6 +857,40 @@ export class SomaBootstrap {
|
|
|
755
857
|
}
|
|
756
858
|
}
|
|
757
859
|
|
|
860
|
+
/**
|
|
861
|
+
* 组件令牌对账(REQ-009 M-1):`components: { Buton: { radius: … } }` 这样一个
|
|
862
|
+
* 拼写错误,不对账时的表现是**"改了没反应"**——变量确实写进了 :root,
|
|
863
|
+
* 只是没有任何组件读它。这类错误的排查成本远高于报错。
|
|
864
|
+
*
|
|
865
|
+
* 判据住在 `component/theme-component-tokens.ts`,而它此前**一个调用者都没有**
|
|
866
|
+
* (由 `verify:reachable` 查出)。这里是全仓唯一同时持有「主题输入」与
|
|
867
|
+
* 「这一页实际可用的组件表」的地方,所以对账只能发生在这一点上。
|
|
868
|
+
*
|
|
869
|
+
* 两条边界:
|
|
870
|
+
* · **只告警、不阻断换装**。主题是 app 级、全部页面共享的,组件表却是逐页的;
|
|
871
|
+
* 曾经对账与 applyTheme 同在一个 try 里,一条对不上就把整份品牌主题一起丢掉
|
|
872
|
+
* (全页回落默认令牌 + 一条"主题派生失败"),与"一个令牌没人读"的后果不成比例。
|
|
873
|
+
* · **组件表 = Host 级 + 页面级**,与 setupComponentManager 实际装配的那张表同一口径
|
|
874
|
+
* (页面同名胜出)。只看 Host 级的话,只在页面资产里注册的组件会被误报成未知组件。
|
|
875
|
+
* 拿不到组件表时(纯预览场景)按设计跳过,不猜。
|
|
876
|
+
*/
|
|
877
|
+
private reconcileThemeComponentTokens(theme: SomaThemeInput): void {
|
|
878
|
+
// 只读查找视图,不是组件包合成——重名裁决与告警在 setupComponentManager 里已经做过
|
|
879
|
+
const components = { ...this.hostComponents, ...(this.assets?.components ?? {}) };
|
|
880
|
+
if (Object.keys(components).length === 0) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
const issues = validateThemeComponentTokens(theme, components);
|
|
884
|
+
if (issues.length === 0) {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
const message = `主题的组件令牌段有 ${issues.length} 处对不上组件契约`
|
|
888
|
+
+ '(主题照常生效;这些令牌会写进 :root,但当前页没有组件读它们):'
|
|
889
|
+
+ `\n${issues.map((issue) => ` · ${issue}`).join('\n')}`;
|
|
890
|
+
console.warn(`[soma-core][主题] ${message}`);
|
|
891
|
+
this.diagnostics.recordValidation('warning', `[主题组件令牌] ${message}`);
|
|
892
|
+
}
|
|
893
|
+
|
|
758
894
|
/**
|
|
759
895
|
* 组件可见的服务表:页面运行时服务 + data 端口(M-5)。
|
|
760
896
|
*
|
|
@@ -771,17 +907,6 @@ export class SomaBootstrap {
|
|
|
771
907
|
return { ...base, data: this.createStableDataPort() };
|
|
772
908
|
}
|
|
773
909
|
|
|
774
|
-
/**
|
|
775
|
-
* 页面态装配(REQ-010 F-37)。
|
|
776
|
-
*
|
|
777
|
-
* 三个来源按优先级取:**URL > initial_state > 空**。
|
|
778
|
-
* URL 在最前是因为它是"用户此刻明确要求看到的那一屏"(分享链接、书签、回退按钮),
|
|
779
|
-
* 而 `initial_state` 只是作者写的缺省。反过来的话,分享链接打开后会被缺省覆盖,
|
|
780
|
-
* 而那正是分享链接唯一的用途。
|
|
781
|
-
*
|
|
782
|
-
* 版本对不上的 URL 状态整份丢弃并 warn 一次:恢复一份旧结构的状态会让界面进入
|
|
783
|
-
* 一个谁都没设计过的样子,而那种坏法是静默的(列还在、但顺序是乱的)。
|
|
784
|
-
*/
|
|
785
910
|
/**
|
|
786
911
|
* 约束布局产物注入(REQ-011 接线 / CL-4)。
|
|
787
912
|
*
|
|
@@ -808,6 +933,151 @@ export class SomaBootstrap {
|
|
|
808
933
|
}
|
|
809
934
|
}
|
|
810
935
|
|
|
936
|
+
/**
|
|
937
|
+
* OOUI 演绎产物的 DOM 落点(REQ-014 最后一公里)。
|
|
938
|
+
*
|
|
939
|
+
* ── 为什么"没有这一步"是一种静默失败 ─────────────────────────────
|
|
940
|
+
* 在它之前,整条演绎链止于 `deduce()` 的返回值:六层全绿、`ooui_artifact`
|
|
941
|
+
* 在资产里、样式表也注入了,**页面上什么都没有**。而"锚点空着"与
|
|
942
|
+
* "这块本来就没写内容"在浏览器里长得一模一样——没有异常、没有日志、
|
|
943
|
+
* 截图里也分不开。这是最像成功的那种失败,所以落点必须有断言守着。
|
|
944
|
+
*
|
|
945
|
+
* ── 运行时收到产物就用,收到声明就拒绝代算 ───────────────────────
|
|
946
|
+
* 与 `installLayoutCss` / `installOouiArtifact` 同一条范式:本方法**只搬运**。
|
|
947
|
+
* 它不认识形态、不认识候选表、不认识组件契约——那些词汇住在 soma-ui,
|
|
948
|
+
* 浏览器手里根本没有,代算出来的只会是一份猜的界面。
|
|
949
|
+
*
|
|
950
|
+
* ── 为什么"引擎生成的"不等于"可信的"(架构 §24.1)───────────────
|
|
951
|
+
* 这串 html 随 `_ui.yaml` 走。发布期的注入面静态扫描(`declaration-safety-scan.ts`)
|
|
952
|
+
* 如今对 YAML 面也跑 html 那四条判据(禁用标签 / on\* 处理器 / srcdoc / 伪协议),
|
|
953
|
+
* 门口已经拦得住一份被改过的 `_ui.yaml`。但门口只守 Registry 这一条写路径:
|
|
954
|
+
* 文件态 Host 的资产、预览器直接喂进来的资产都不经过它;而 innerHTML 插入的
|
|
955
|
+
* `<script>` 虽然不执行,`<img onerror=…>` 却会立刻执行。所以注入前必须再核一道——
|
|
956
|
+
* 这是纵深防御的最后一层,不因门口补齐而省掉。
|
|
957
|
+
*
|
|
958
|
+
* 核的方式是**允许集**不是禁用集:`emitRegionHtml` 今天只产出
|
|
959
|
+
* `div` / `span` 两种标签与四个 `class` / `data-soma-*` 属性,
|
|
960
|
+
* 把这个全集写死,任何多出来的东西一律拒收。禁用集在这种两标签的产物上
|
|
961
|
+
* 严格更差——它只挡得住今天想得到的那几样。发射器哪天真加了新标签,
|
|
962
|
+
* 这里会**当场红**(而不是静默放行),红在写下的那天,这正是要的。
|
|
963
|
+
*
|
|
964
|
+
* 解析走 `<template>`:template 的内容是**惰性的**——不加载图片、不跑脚本,
|
|
965
|
+
* 所以"先解析再检查"这个顺序本身不会触发任何东西。检查通过之后才搬进文档。
|
|
966
|
+
*/
|
|
967
|
+
private installOouiHtml(container: HTMLElement, uiConfig: UiConfig): void {
|
|
968
|
+
const artifact = uiConfig.oouiArtifact;
|
|
969
|
+
if (!artifact || artifact.regions.length === 0) return;
|
|
970
|
+
|
|
971
|
+
const doc = container.ownerDocument ?? (globalThis as { document?: Document }).document ?? null;
|
|
972
|
+
if (!doc || typeof doc.createElement !== 'function') {
|
|
973
|
+
// 非 DOM 容器(小程序 / RN 桥)。**说出来**:静默跳过的表现是
|
|
974
|
+
// "这个平台上演绎区域永远是空的",而那与"这页没写 ooui"分不开。
|
|
975
|
+
console.warn(
|
|
976
|
+
`[soma-core][演绎] 页面 "${uiConfig.bind.obj}" 有 ${artifact.regions.length} 个演绎区域,`
|
|
977
|
+
+ '但当前容器没有 document,演绎 DOM 无法落地——'
|
|
978
|
+
+ '演绎产物今天只支持 Web 容器(DOM 由 <template> 惰性解析后搬入)。',
|
|
979
|
+
);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
for (const region of artifact.regions) {
|
|
984
|
+
const host = this.adapter.findAnchor(container, region.anchor);
|
|
985
|
+
if (!host) {
|
|
986
|
+
// 构建期已对着锚点索引核过(`OOUI-SEM-ANCHOR-UNKNOWN`),这里还找不到,
|
|
987
|
+
// 说明 html 与 _ui.yaml 这两份资产不是同一次编译的产物。
|
|
988
|
+
console.warn(
|
|
989
|
+
`[soma-core][演绎] 演绎区域 "${region.anchor}" 在页面 HTML 里找不到锚点(data-soma-id)——`
|
|
990
|
+
+ 'html 与 _ui.yaml 不是同一次编译的产物。这一块不会有任何内容。',
|
|
991
|
+
);
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
const html = typeof region.html === 'string' ? region.html : '';
|
|
996
|
+
if (html.trim() === '') {
|
|
997
|
+
console.warn(
|
|
998
|
+
`[soma-core][演绎] 演绎区域 "${region.anchor}" 的产物里没有 html——`
|
|
999
|
+
+ '这是一份旧格式(或手写)的 ooui_artifact。重新跑一次构建期编译'
|
|
1000
|
+
+ '(compilePageDeclaration)即可,运行时不代为演绎。',
|
|
1001
|
+
);
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
// 已注入且内容没变 → 什么都不做。标记值是**内容指纹**而不是 "1":
|
|
1006
|
+
// 按布尔标记的话,同一个锚点换了一份产物会被当成"已经注入过了"而跳过,
|
|
1007
|
+
// 表现是页面继续显示上一版的 DOM——渲染正常、内容是旧的、控制台一行都没有。
|
|
1008
|
+
// 与 `css_key` 用内容哈希是同一条理由,只是这一侧的作用域是单个锚点。
|
|
1009
|
+
const fingerprint = oouiHtmlFingerprint(html);
|
|
1010
|
+
if (host.getAttribute(SOMA_OOUI_REGION_ATTR) === fingerprint) continue;
|
|
1011
|
+
|
|
1012
|
+
const template = doc.createElement('template');
|
|
1013
|
+
// template 内容惰性:解析这一步不会加载资源、不会执行任何东西。
|
|
1014
|
+
template.innerHTML = html;
|
|
1015
|
+
const offence = findOouiDomOffence(template.content);
|
|
1016
|
+
if (offence !== null) {
|
|
1017
|
+
console.error(
|
|
1018
|
+
`[soma-core][演绎] 演绎区域 "${region.anchor}" 的产物 DOM 不在允许集内(${offence}),已拒绝注入。`
|
|
1019
|
+
+ '产物随 _ui.yaml 走,而那份资产可以被手写、被改:发布期的注入面扫描虽然也扫 YAML 面,'
|
|
1020
|
+
+ '但它只守"写进声明仓库"这个入口,绕过 Registry 的构建与发布后改资产都不经过它。'
|
|
1021
|
+
+ '所以注入前这道结构闸门是最后一关——放行一次就等于把 innerHTML 交了出去。'
|
|
1022
|
+
+ '正常产物只含 div/span 与 class/data-soma-node/data-soma-id/data-soma-component。'
|
|
1023
|
+
+ '若这是发射器新加的合法形状,请同步 soma-bootstrap.ts 的 SOMA_OOUI_ALLOWED_TAGS / _ATTRS;'
|
|
1024
|
+
+ '否则请重新跑一次 compilePageDeclaration 生成产物,不要手写 ooui_artifact。',
|
|
1025
|
+
);
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// 整块换掉而不是追加:锚点是产物的落点,重复挂载不该叠出两份 DOM。
|
|
1030
|
+
while (host.firstChild) host.removeChild(host.firstChild);
|
|
1031
|
+
host.appendChild(template.content);
|
|
1032
|
+
host.setAttribute(SOMA_OOUI_REGION_ATTR, fingerprint);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* OOUI 演绎产物注入(REQ-014 接线)。
|
|
1038
|
+
*
|
|
1039
|
+
* 与 `installLayoutCss` 逐点同构:运行时只认**产物**,收到声明本身只告警。
|
|
1040
|
+
* 演绎链住在 core/build/ooui/,进 client 就等于把「运行期零演绎」这条
|
|
1041
|
+
* 结构性承诺撤回去——而且浏览器手里根本没有候选表与组件契约,
|
|
1042
|
+
* 代算出来的只会是一份猜的界面。
|
|
1043
|
+
*
|
|
1044
|
+
* 注入键用产物自带的**内容哈希**(`ooui:<sha256 前 8 位>`),不用页面名:
|
|
1045
|
+
* `injectStyleOnce` 没有内容冲突检测(同键不同内容静默保留第一份),
|
|
1046
|
+
* 按页面名命名的话,SPA 内路由切到同名不同产物的页面会继续用上一页的 CSS,
|
|
1047
|
+
* 页面看着渲染正常、间距全错、控制台一行都没有。
|
|
1048
|
+
* 位置紧接 `installLayoutCss`——都在组件实例挂载**之前**,级联顺序才稳定。
|
|
1049
|
+
*/
|
|
1050
|
+
private installOouiArtifact(uiConfig: UiConfig): void {
|
|
1051
|
+
const artifact = uiConfig.oouiArtifact;
|
|
1052
|
+
if (artifact?.css && artifact.css_key) {
|
|
1053
|
+
injectStyleOnce(
|
|
1054
|
+
artifact.css_key,
|
|
1055
|
+
artifact.css,
|
|
1056
|
+
{ nonce: this.componentStyleNonce ?? null },
|
|
1057
|
+
);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
if (artifact) return; // 有产物、只是这一版没有样式表(空间层未参与):正常,不吭声
|
|
1061
|
+
if (uiConfig.ooui && Object.keys(uiConfig.ooui).length > 0) {
|
|
1062
|
+
console.warn(
|
|
1063
|
+
`[soma-core][演绎] 页面 "${uiConfig.bind.obj}" 声明了 ooui: 段但没有构建期产物(ooui_artifact)——`
|
|
1064
|
+
+ '声明未经 compilePageDeclaration 演绎,本页不会产生任何演绎界面。'
|
|
1065
|
+
+ '演绎只在构建期发生(Registry 发布 / Host 预编译),运行时不代算。',
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* 页面态装配(REQ-010 F-37)。
|
|
1072
|
+
*
|
|
1073
|
+
* 三个来源按优先级取:**URL > initial_state > 空**。
|
|
1074
|
+
* URL 在最前是因为它是"用户此刻明确要求看到的那一屏"(分享链接、书签、回退按钮),
|
|
1075
|
+
* 而 `initial_state` 只是作者写的缺省。反过来的话,分享链接打开后会被缺省覆盖,
|
|
1076
|
+
* 而那正是分享链接唯一的用途。
|
|
1077
|
+
*
|
|
1078
|
+
* 版本对不上的 URL 状态整份丢弃并 warn 一次:恢复一份旧结构的状态会让界面进入
|
|
1079
|
+
* 一个谁都没设计过的样子,而那种坏法是静默的(列还在、但顺序是乱的)。
|
|
1080
|
+
*/
|
|
811
1081
|
private installPageState(config: SomaPageStateConfig | undefined): void {
|
|
812
1082
|
const instance = this.domainInstance;
|
|
813
1083
|
if (!instance) return;
|
|
@@ -907,25 +1177,12 @@ export class SomaBootstrap {
|
|
|
907
1177
|
);
|
|
908
1178
|
}
|
|
909
1179
|
|
|
910
|
-
/**
|
|
1180
|
+
/**
|
|
1181
|
+
* 稳定的 data 端口壳:每次调用现取当前解析器(解析器暂缺时的兜底住在 createSomaDataPort 里,
|
|
1182
|
+
* 与端口的方法面同一处——测试守的就是这里注入的那一个端口)。
|
|
1183
|
+
*/
|
|
911
1184
|
private createStableDataPort(): SomaDataPort {
|
|
912
|
-
|
|
913
|
-
ok: false,
|
|
914
|
-
message: `数据对象尚未就绪,无法${action}(本页可能没有声明 *_data.yaml)`,
|
|
915
|
-
});
|
|
916
|
-
return {
|
|
917
|
-
getObject: (name) => this.dataResolver?.getObject(name),
|
|
918
|
-
getDict: (name) => this.dataResolver?.getDict(name) ?? {},
|
|
919
|
-
getReactions: (name) => this.dataResolver?.getReactions(name) ?? null,
|
|
920
|
-
window: (name) => this.dataResolver?.window(name) ?? null,
|
|
921
|
-
submit: async (name, model, mode) =>
|
|
922
|
-
this.dataResolver
|
|
923
|
-
? this.dataResolver.submit(name, model, mode)
|
|
924
|
-
: noResolver(`提交 "${name}"`),
|
|
925
|
-
reload: async (names) => {
|
|
926
|
-
await this.dataResolver?.reload(names);
|
|
927
|
-
},
|
|
928
|
-
};
|
|
1185
|
+
return createSomaDataPort(() => this.dataResolver);
|
|
929
1186
|
}
|
|
930
1187
|
|
|
931
1188
|
/** 组件管理器装配:无 components 资产时保持 null,组件能力整体旁路 */
|
|
@@ -1024,6 +1281,7 @@ export class SomaBootstrap {
|
|
|
1024
1281
|
this.assertNamedActionsResolvable(parsed.eventConfig);
|
|
1025
1282
|
this.installPageState(parsed.uiConfig.state);
|
|
1026
1283
|
this.installLayoutCss(parsed.uiConfig);
|
|
1284
|
+
this.installOouiArtifact(parsed.uiConfig);
|
|
1027
1285
|
this.styleBinder = runtime.styleBinder;
|
|
1028
1286
|
this.propertyWatcher = runtime.propertyWatcher;
|
|
1029
1287
|
this.onChangeEngine = runtime.onChangeEngine;
|
|
@@ -14,12 +14,6 @@ export interface UploadOptions {
|
|
|
14
14
|
fields?: Record<string, string>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface HttpResponse<T = any> {
|
|
18
|
-
data: T;
|
|
19
|
-
status: number;
|
|
20
|
-
headers: Record<string, string>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
17
|
export interface IHttpClient {
|
|
24
18
|
get<T>(url: string, config?: HttpRequestConfig): Promise<T>;
|
|
25
19
|
post<T>(url: string, data?: any, config?: HttpRequestConfig): Promise<T>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// Use the package's public self-reference rather than the repository-only
|
|
2
|
+
// `@/` alias. This import is preserved in emitted declarations, so an
|
|
3
|
+
// internal alias here would leak into every Host's typecheck.
|
|
4
|
+
import { SomaHttpClient, SomaHttpClientConfig, describeHttpErrorBody } from 'soma-core/base';
|
|
2
5
|
import { IHttpClient, HttpRequestConfig, UploadOptions } from './IHttpClient';
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DefaultNotifyService } from './DefaultNotifyService';
|
|
2
|
-
import type {
|
|
2
|
+
import type { NotifyOptions } from './INotifyService';
|
|
3
3
|
import type { ToastTheme } from './INotifyTheme';
|
|
4
4
|
|
|
5
5
|
const ROOT_ID = 'soma-toast-root';
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/** Strip query/hash for router utilities */
|
|
2
|
-
export function pathOnly(url: string): string {
|
|
3
|
-
const raw = url.split('?')[0]?.split('#')[0] || '/';
|
|
4
|
-
return raw.replace(/\/$/, '') || '/';
|
|
5
|
-
}
|
|
6
|
-
|
|
7
1
|
/** Browser location pathname + search (includes ?id= etc.) */
|
|
8
2
|
export function getBrowserUrlPath(): string {
|
|
9
3
|
if (typeof globalThis === 'undefined' || !('location' in globalThis)) {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
getShowListMetadata,
|
|
5
5
|
getEventMetadata,
|
|
6
6
|
} from '../base/decorators';
|
|
7
|
-
import type { UiConfig, ShowMapping
|
|
7
|
+
import type { UiConfig, ShowMapping } from '../../shared/types/ui-config.types';
|
|
8
8
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
9
9
|
import { parsePipeline } from './pipeline-parser';
|
|
10
10
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// 块解析 · 块作用域与命名空间(REQ-005 F1.3 / F1.4)。
|
|
2
2
|
//
|
|
3
|
-
// 块即命名空间:块内 `data:`
|
|
4
|
-
//
|
|
3
|
+
// 块即命名空间:块内 `data:` 声明的对象名,全局身份自动是扁平名 `块id__名`
|
|
4
|
+
// (见 blockDataObjectName)——书写零前缀,跨块写 `page.data.块id__名`。
|
|
5
|
+
// 两个组件都叫 `orders` 因此互不相干。
|
|
5
6
|
//
|
|
6
7
|
// alias 是块作用域的短名:`queryOrders: /api/admin/orders` 或 `buyer: order.buyer`。
|
|
7
8
|
// 两类按**词法**分流(值以 `/` 开头即 API 别名),不靠猜;编译期整体展开,
|
|
@@ -28,6 +29,12 @@ export interface BlockScope {
|
|
|
28
29
|
blockId: string;
|
|
29
30
|
/** 本块 data 段声明或引入的对象名 */
|
|
30
31
|
dataNames: ReadonlySet<string>;
|
|
32
|
+
/**
|
|
33
|
+
* 本块 data 名 → 运行时绑定路径前缀。组件块由 use-parser 填:
|
|
34
|
+
* 声明 → `page.data.<块id__名>`,引入 → 引入目标路径。
|
|
35
|
+
* 缺省时回落 `块id.名`——那是 page 块沿用的既有口径,组件块不走这条。
|
|
36
|
+
*/
|
|
37
|
+
dataPaths?: ReadonlyMap<string, string>;
|
|
31
38
|
/** 块作用域别名 */
|
|
32
39
|
aliases: ReadonlyMap<string, AliasEntry>;
|
|
33
40
|
/** 按 HTML 位置可见的行变量(行内组件才有) */
|
|
@@ -40,6 +47,23 @@ export interface BlockScope {
|
|
|
40
47
|
const RESERVED = new Set(['page', 'p', 'ctrl']);
|
|
41
48
|
const NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
42
49
|
|
|
50
|
+
/**
|
|
51
|
+
* 块私有数据对象的全局身份:扁平名 `块id__名`(标识符,不带点)。
|
|
52
|
+
*
|
|
53
|
+
* 为什么不是 `块id.名`:数据对象层的对象名是标识符(data-config-parser 的
|
|
54
|
+
* IDENTIFIER_PATTERN),`$` 引用与 `relations[].to` 也按标识符切;运行时
|
|
55
|
+
* `page.data.<对象>.<字段>` 的绑定按点号逐段下钻。带点的对象名在这几处各断一次——
|
|
56
|
+
* 页面要么发布不了,要么发布了取不到值、只剩一片空白。扁平名让块私有对象与页面级对象
|
|
57
|
+
* 走同一条解析、同一条取数、同一条绑定,下游一行不改。
|
|
58
|
+
*
|
|
59
|
+
* 规则只在这里定义一次:use-parser(对象键与绑定路径)与 block-compile(撞名检查、
|
|
60
|
+
* `relations[].to`)都调它,不各拼一遍。撞名(`a` 的 `b__c` 与 `a__b` 的 `c`)
|
|
61
|
+
* 由 block-compile 在合表时拦下。
|
|
62
|
+
*/
|
|
63
|
+
export function blockDataObjectName(blockId: string, localName: string): string {
|
|
64
|
+
return `${blockId}__${localName}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
43
67
|
export interface BuildScopeInput {
|
|
44
68
|
blockId: string;
|
|
45
69
|
dataNames?: Iterable<string>;
|
|
@@ -131,7 +155,7 @@ export function resolvePath(raw: string, scope: BlockScope): ResolvedPath {
|
|
|
131
155
|
const hits = [inData, inRow, isPage].filter(Boolean).length;
|
|
132
156
|
if (hits > 1) {
|
|
133
157
|
const candidates = [
|
|
134
|
-
inData ?
|
|
158
|
+
inData ? `本块 data 名 ${head}` : '',
|
|
135
159
|
inRow ? `行变量 ${head}` : '',
|
|
136
160
|
isPage ? '页面变量 page' : '',
|
|
137
161
|
].filter(Boolean);
|
|
@@ -142,8 +166,9 @@ export function resolvePath(raw: string, scope: BlockScope): ResolvedPath {
|
|
|
142
166
|
}
|
|
143
167
|
|
|
144
168
|
if (inData) {
|
|
145
|
-
// 块内零前缀 →
|
|
146
|
-
|
|
169
|
+
// 块内零前缀 → 运行时绑定路径(组件块:声明 → page.data.块id__名,引入 → 引入目标)
|
|
170
|
+
const base = scope.dataPaths?.get(head) ?? `${scope.blockId}.${head}`;
|
|
171
|
+
return { kind: 'data', full: [base, ...segments.slice(1)].join('.') };
|
|
147
172
|
}
|
|
148
173
|
if (inRow) return { kind: 'row', full: text };
|
|
149
174
|
if (isPage) return { kind: 'page', full: text };
|
|
@@ -38,6 +38,28 @@ const PAGE_KEYS = new Set([
|
|
|
38
38
|
// 这里只直通原文;形状校验在 parseUiConfig(运行时)与 compilePageDeclaration(构建期)各做一次。
|
|
39
39
|
'state',
|
|
40
40
|
'layout',
|
|
41
|
+
// ooui(REQ-014 演绎接线):第三个平铺 UiConfig 保留键的直通。
|
|
42
|
+
//
|
|
43
|
+
// 少了这一条,块声明页写 `ooui:` 会当场收到「page 块不支持键 "ooui"」——
|
|
44
|
+
// 而**真实发布的页面只有块声明这一条路**(compilePageDeclaration 只收块声明),
|
|
45
|
+
// 于是整条演绎链只在"直接喂平铺 YAML"的测试路径上活着,生产页面一次都用不上。
|
|
46
|
+
// 这与上面 state / layout 那次踩的是同一个坑,不再重踩第三次。
|
|
47
|
+
// 这里只直通原文;形状校验在 parseUiConfig(运行时)与 compilePageDeclaration(构建期)各做一次。
|
|
48
|
+
'ooui',
|
|
49
|
+
// objects(REQ-014 表层语义,§38.5 断线 ②):**面向人书写的那一层对象声明**。
|
|
50
|
+
//
|
|
51
|
+
// `data:` 是核心层——完备、显式、机器好翻译(`{ type: text, rules: [{ required: true }] }`)。
|
|
52
|
+
// 表层是同一件事的人写形态(`no: text!`)。两层的转换点只有一个
|
|
53
|
+
// (`build/ooui/semantic/normalize.ts`),而在此之前**它一个生产调用者都没有**:
|
|
54
|
+
// 表层类型、展开器、台账三样都写完了,页面上却没有任何地方能写出表层来。
|
|
55
|
+
//
|
|
56
|
+
// 不接这一条的后果不是"少个语法糖",是**来历台账永远是空的**:
|
|
57
|
+
// 系统按默认补的值(如 `permission: r`)与作者显式写的值在产物里长得一模一样,
|
|
58
|
+
// 于是 `OOUI-SEM-EDIT-ALL-READONLY` 只能说"你写错了",说不出"我按默认补的、
|
|
59
|
+
// 你需要显式写 permission: w"——同一条错误,两种修法,指向两个人(§34.2)。
|
|
60
|
+
//
|
|
61
|
+
// 这里只直通原文;展开与校验在 compilePageDeclaration(构建期)做一次。
|
|
62
|
+
'objects',
|
|
41
63
|
]);
|
|
42
64
|
/** 后缀键:平铺书写的高级绑定 */
|
|
43
65
|
const SUFFIXES = ['when', 'model', 'class'] as const;
|
|
@@ -50,6 +72,15 @@ export interface PageBlockAst {
|
|
|
50
72
|
eventRaw: Record<string, unknown>;
|
|
51
73
|
/** 数据段原文(页面级共享对象,交数据对象层) */
|
|
52
74
|
dataRaw?: Record<string, unknown>;
|
|
75
|
+
/**
|
|
76
|
+
* 表层对象声明原文(REQ-014 §38.5 断线 ②)。
|
|
77
|
+
*
|
|
78
|
+
* 与 `dataRaw` 是**同一件事的两种书写形态**,不是两套对象:构建期由
|
|
79
|
+
* `normalizeSurfaceObject()` 展开成核心层后并进 `data` 段,之后一路走
|
|
80
|
+
* 同一个数据解析器、同一份 API 白名单校验、同一份运行时资产。
|
|
81
|
+
* 分成两个字段只到编译期为止——再往下游只有核心层(§2.3 判据 3:转换只发生一次)。
|
|
82
|
+
*/
|
|
83
|
+
surfaceRaw?: Record<string, unknown>;
|
|
53
84
|
scope: BlockScope;
|
|
54
85
|
}
|
|
55
86
|
|
|
@@ -80,9 +111,17 @@ export function parsePageBlock(input: ParsePageInput): PageBlockAst {
|
|
|
80
111
|
fail('page 块缺少 domain(页面 Domain 类名,必填)');
|
|
81
112
|
}
|
|
82
113
|
|
|
114
|
+
// 表层对象与核心层对象共用一个命名空间:它们在构建期会并成一份 `data`,
|
|
115
|
+
// 所以作用域这里就得两份都认。少认表层的那一半时,`ui:` 里绑到表层对象的路径
|
|
116
|
+
// 会被判成"未知对象"——而那条错误指向的是绑定那一行,不是漏登记这件事。
|
|
117
|
+
// 撞名不在这里判(这里只有原文、没有展开结果):由 compilePageDeclaration 当场拒收,
|
|
118
|
+
// 那里能同时说清"两处都声明了同一个名字"以及各自写在哪。
|
|
83
119
|
const scope = buildBlockScope({
|
|
84
120
|
blockId: 'page',
|
|
85
|
-
dataNames:
|
|
121
|
+
dataNames: [...new Set([
|
|
122
|
+
...Object.keys((body.data as Record<string, unknown>) ?? {}),
|
|
123
|
+
...Object.keys((body.objects as Record<string, unknown>) ?? {}),
|
|
124
|
+
])],
|
|
86
125
|
aliasRaw: body.alias as Record<string, unknown> | undefined,
|
|
87
126
|
});
|
|
88
127
|
|
|
@@ -148,6 +187,9 @@ export function parsePageBlock(input: ParsePageInput): PageBlockAst {
|
|
|
148
187
|
if (body.layout !== undefined) {
|
|
149
188
|
ui.layout = body.layout as UiConfig['layout'];
|
|
150
189
|
}
|
|
190
|
+
if (body.ooui !== undefined) {
|
|
191
|
+
ui.ooui = body.ooui as UiConfig['ooui'];
|
|
192
|
+
}
|
|
151
193
|
|
|
152
194
|
// ── event 段:面向 DOM ─────────────────────────────────────────────────
|
|
153
195
|
const eventRaw = normalizeEventSection(body.event, input, fail);
|
|
@@ -156,6 +198,7 @@ export function parsePageBlock(input: ParsePageInput): PageBlockAst {
|
|
|
156
198
|
ui,
|
|
157
199
|
eventRaw,
|
|
158
200
|
...(body.data ? { dataRaw: body.data as Record<string, unknown> } : {}),
|
|
201
|
+
...(body.objects ? { surfaceRaw: body.objects as Record<string, unknown> } : {}),
|
|
159
202
|
scope,
|
|
160
203
|
};
|
|
161
204
|
}
|