soma-core 1.4.1 → 1.5.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/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 +443 -30
- package/core/build/component/component-graph.ts +28 -105
- package/core/build/component/package-loader.ts +50 -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 +15 -9
- 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/build/pack/pack-init.ts +19 -14
- package/core/client/base/SomaHttpClient.ts +34 -1
- package/core/client/component/ai-catalog.ts +42 -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 +120 -1
- package/core/client/container/SomaContainerAdapter.ts +6 -2
- 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 +5 -2
- 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 +280 -69
- package/core/client/theme/tone-solver.ts +9 -8
- package/core/index.ts +38 -3
- 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 +290 -0
- package/core/shared/component/field-lines.ts +563 -0
- 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 +30 -13
- 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 +2424 -1098
- 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/base/SomaHttpClient.d.ts +8 -0
- package/dist/types/client/component/ai-catalog.d.ts +9 -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/component/verify-pack.d.ts +10 -0
- 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 +6 -4
- 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 +37 -0
- package/dist/types/shared/component/field-lines.d.ts +19 -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 +29 -12
- 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 +28 -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
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
// 页面组合层 · 联动契约的编译期裁决(架构 REQ-014 §29.2)。**本层最有价值的闸门。**
|
|
2
|
+
//
|
|
3
|
+
// ── 为什么这个失败模式是静默的 ─────────────────────────────────────
|
|
4
|
+
// 这道闸门防的是一句业务上人人见过的话:**「点了左边列表,右边没反应」**。
|
|
5
|
+
// 它今天只能在运行时被人发现,而且发现它的人查不到任何线索:
|
|
6
|
+
//
|
|
7
|
+
// ① 「没有人监听这个事件」与「这个事件还没发生」在运行期是同一件事——
|
|
8
|
+
// 控制台没有警告、网络面板没有请求、DOM 上什么都不缺。
|
|
9
|
+
// ② 于是排查会从右边那个区域的取数开始查,一路查到接口、查到权限,
|
|
10
|
+
// **而错误在左边那个区域的动词上**:它根本不产生这个事件。
|
|
11
|
+
// ③ 修好之后也没有任何东西能防止它再来一次——因为从来没有一处声明
|
|
12
|
+
// 说过「这条线成不成立」是可判定的。
|
|
13
|
+
//
|
|
14
|
+
// 而它**是可判定的**:`boundTo.as` 引用的是语义事件(§16.3 的「体系的公事」),
|
|
15
|
+
// 每个动词在每个控制模型下产生哪些事件是意图层的既有事实(§35.2 的表)。
|
|
16
|
+
// 所以:
|
|
17
|
+
//
|
|
18
|
+
// detail ← list.select list 是 browse,browse(受控型)必然产生 select → 通过(带 caveat)
|
|
19
|
+
// b ← a.select a 是 inspect,inspect 两种模型下都不产生 select → 编译期红
|
|
20
|
+
//
|
|
21
|
+
// ── 三条比原型更紧的地方(原型 `compose-page.mjs` 是移植源,不是判据源)──
|
|
22
|
+
// 1. **事件表不再手抄**。原型的 `PRODUCES` 只列了四个动词,另外四个走
|
|
23
|
+
// `?? []` 兜底,被一律判成不成立——**把正例误判成反例**,而误判的表现是
|
|
24
|
+
// 「作者删掉一条本来对的联动」,没有任何东西会红。本文件全部走
|
|
25
|
+
// `../intent/verb-events` 的真源。
|
|
26
|
+
// 2. **控制模型这一半被接上了**。「browse 产生 select」只在受控型下成立;
|
|
27
|
+
// 自治型的 `QueryConsole` 一辈子 emit 不出 `select`。原型把它记成无条件通过,
|
|
28
|
+
// 于是「声明期绿 → 构件层选了自治型 → 运行期线是死的」是一条全绿路径。
|
|
29
|
+
// 本文件把它记成 `holdsFor: ['controlled']` + 一条 `caveat`,
|
|
30
|
+
// 并允许调用方在构件选定后**喂回控制模型或真实 emit 再核一遍**。
|
|
31
|
+
// 3. **成环被检出**。原型没有这一项(它只跑两区域)。三区域以上
|
|
32
|
+
// `a ← b.select`、`b ← c.pick`、`c ← a.select` 不会抛异常,
|
|
33
|
+
// 运行期表现是互相触发刷新——轻则每次交互多取几轮数,重则页面卡住,
|
|
34
|
+
// 而「页面卡住」指不回任何一句声明。检环照 `component-graph.ts` 的先例,
|
|
35
|
+
// **报出整条回路而不只是「成环了」**:只说成环的话,作者得自己把链条走一遍
|
|
36
|
+
// 才知道该断哪一条。
|
|
37
|
+
//
|
|
38
|
+
// ── 为什么返回 issues 而不是逐条抛 ─────────────────────────────────
|
|
39
|
+
// 照 `validateSemanticRequest` / `verifyTypeTable` 的先例:一页里可能同时有
|
|
40
|
+
// 三条坏联动,逐条抛只能让作者改一条跑一轮。要「编译期必须失败」这条铁律的
|
|
41
|
+
// 硬形态,用 `assertPageComposition`——它把一次列全的 issues 汇成一个错误抛出。
|
|
42
|
+
|
|
43
|
+
// 区域名会成为空间 IR 的节点 id、`ooui:` 的锚点名也就是区域名,三处必须是**同一条**文法
|
|
44
|
+
// (真源在 `shared/ooui-declaration.ts`,空间层与产物层也用它)。
|
|
45
|
+
// 此前本层借空间层那份「字母或数字开头」,产物层是「字母开头」:`1list` 在本层放行、
|
|
46
|
+
// 到产物层才红,而那条错误指着的是派生出来的 `1list-shell`,不是作者写错的那行区域名。
|
|
47
|
+
import {
|
|
48
|
+
SOMA_OOUI_ANCHOR_GRAMMAR,
|
|
49
|
+
SOMA_OOUI_ANCHOR_PATTERN,
|
|
50
|
+
SOMA_OOUI_BINDING_KEYS,
|
|
51
|
+
SOMA_OOUI_LAYOUT_KEYS,
|
|
52
|
+
SOMA_OOUI_SIZINGS,
|
|
53
|
+
findOouiBindingUnknownKey,
|
|
54
|
+
findOouiLayoutProblem,
|
|
55
|
+
isOouiMap,
|
|
56
|
+
} from '../../../shared/ooui-declaration';
|
|
57
|
+
import { describeOouiValue, foldOouiIssues, oouiIssue } from '../diagnostics';
|
|
58
|
+
import type { SomaOouiIssue } from '../diagnostics/issue.types';
|
|
59
|
+
import {
|
|
60
|
+
SOMA_CONTROL_MODELS,
|
|
61
|
+
SOMA_INTERACTION_KINDS,
|
|
62
|
+
isSomaInteractionKind,
|
|
63
|
+
type SomaControlModel,
|
|
64
|
+
type SomaInteractionKind,
|
|
65
|
+
} from '../intent/intent.types';
|
|
66
|
+
import { VERB_EVENTS_BY_MODEL, semanticEnablement } from '../intent/verb-events';
|
|
67
|
+
import { SOMA_VERBS, isSomaVerb, type SomaObject, type SomaVerb } from '../semantic/kernel.types';
|
|
68
|
+
import type {
|
|
69
|
+
SomaBindingVerdict,
|
|
70
|
+
SomaPageCheckOptions,
|
|
71
|
+
SomaPageComposition,
|
|
72
|
+
SomaPageCompositionPlan,
|
|
73
|
+
SomaPageCompositionResult,
|
|
74
|
+
SomaPageDecision,
|
|
75
|
+
SomaRegion,
|
|
76
|
+
} from './page.types';
|
|
77
|
+
|
|
78
|
+
/** 页面区域组的缺省节点 id。区域不得重名于它——见 `SomaPageBudgetOptions.rootId` */
|
|
79
|
+
export const SOMA_PAGE_ROOT_ID = 'page';
|
|
80
|
+
|
|
81
|
+
// ─────────────────────────────────────────────────────────────
|
|
82
|
+
// 事件可得性:唯一判据
|
|
83
|
+
// ─────────────────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
/** 某个控制模型下这个区域会发生哪些事:必然的与可能的 */
|
|
86
|
+
export interface SomaEventAvailability {
|
|
87
|
+
readonly required: readonly SomaInteractionKind[];
|
|
88
|
+
readonly optional: readonly SomaInteractionKind[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 一个 `{动词, 对象}` 在两种控制模型下各产生哪些语义事件。**本层唯一的判据来源。**
|
|
93
|
+
*
|
|
94
|
+
* 两个来源合并,缺一不可:
|
|
95
|
+
* · `VERB_EVENTS_BY_MODEL` —— 动词本质决定的那部分(§35.2);
|
|
96
|
+
* · `semanticEnablement` —— 对象的 `window` 段启用的那部分(§17.2)。
|
|
97
|
+
* 少了它,`monitor` 区域上声明了 `window.selection: all` 之后依然会被判成
|
|
98
|
+
* 「不产生 select」——**把正例误判成反例**,而误判的表现是作者删掉一条本来对的联动。
|
|
99
|
+
*
|
|
100
|
+
* 语义启用的事件只落在它自己的 `requiredFor` 模型上(今天恒为 `controlled`):
|
|
101
|
+
* 自治型自己排序、自己翻页,不需要把意图 emit 出来(§17.2 的能力/事件分家)。
|
|
102
|
+
* 把它同时算进自治型的话,一个自治型区域会被当成「能把排序意图交出去」,
|
|
103
|
+
* 而它交不出来——那正是 §35 修掉的那个判据缺陷换个位置重演。
|
|
104
|
+
*/
|
|
105
|
+
export function producedEvents(
|
|
106
|
+
verb: SomaVerb,
|
|
107
|
+
object: SomaObject,
|
|
108
|
+
): Readonly<Record<SomaControlModel, SomaEventAvailability>> {
|
|
109
|
+
const spec = VERB_EVENTS_BY_MODEL[verb];
|
|
110
|
+
const required: Record<SomaControlModel, Set<SomaInteractionKind>> = {
|
|
111
|
+
autonomous: new Set(spec.autonomous.required),
|
|
112
|
+
controlled: new Set(spec.controlled.required),
|
|
113
|
+
};
|
|
114
|
+
const optional: Record<SomaControlModel, Set<SomaInteractionKind>> = {
|
|
115
|
+
autonomous: new Set(spec.autonomous.optional),
|
|
116
|
+
controlled: new Set(spec.controlled.optional),
|
|
117
|
+
};
|
|
118
|
+
for (const event of semanticEnablement(verb, object).events) {
|
|
119
|
+
for (const model of event.requiredFor) {
|
|
120
|
+
required[model].add(event.kind);
|
|
121
|
+
optional[model].delete(event.kind);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// 输出序固定为封闭集序:产物要能逐字比对(§19.3 幂等)
|
|
125
|
+
const order = (set: ReadonlySet<SomaInteractionKind>): readonly SomaInteractionKind[] => (
|
|
126
|
+
SOMA_INTERACTION_KINDS.filter((kind) => set.has(kind))
|
|
127
|
+
);
|
|
128
|
+
return {
|
|
129
|
+
autonomous: { required: order(required.autonomous), optional: order(optional.autonomous) },
|
|
130
|
+
controlled: { required: order(required.controlled), optional: order(optional.controlled) },
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ─────────────────────────────────────────────────────────────
|
|
135
|
+
// 校验
|
|
136
|
+
// ─────────────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
const at = (slug: string, rest: string): string => `${slug}.${rest}`;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 校验一页的组合声明:形状 → 区域名 → 区域约束 → 动词 → 联动引用 → 成环 → 联动契约。
|
|
142
|
+
*
|
|
143
|
+
* **次序不是随意的**:区域名不合法时后面每一条联动都会指着一个不存在的区域,
|
|
144
|
+
* 一次报出十条互为因果的错误比报一条更难读。所以前置检查一旦有问题就不再往下判,
|
|
145
|
+
* 只把已经确定的那批 issues 返回——这与「一次列全」不冲突:
|
|
146
|
+
* 列全的是**同一层面**的问题,不是把下游的连带反应也列出来。
|
|
147
|
+
*/
|
|
148
|
+
export function validatePageComposition(
|
|
149
|
+
page: SomaPageComposition,
|
|
150
|
+
options: SomaPageCheckOptions = {},
|
|
151
|
+
): SomaPageCompositionResult {
|
|
152
|
+
const issues: SomaOouiIssue[] = [];
|
|
153
|
+
const decisions: SomaPageDecision[] = [];
|
|
154
|
+
|
|
155
|
+
if (page === null || typeof page !== 'object' || Array.isArray(page)) {
|
|
156
|
+
return { plan: null, issues: [shapeIssue('page', '页面组合声明不是映射。', describeOouiValue(page))] };
|
|
157
|
+
}
|
|
158
|
+
const slug = typeof page.slug === 'string' && page.slug.trim() !== '' ? page.slug : '<page>';
|
|
159
|
+
if (typeof page.slug !== 'string' || page.slug.trim() === '') {
|
|
160
|
+
issues.push(shapeIssue('page.slug', 'slug 不是非空字符串。', describeOouiValue(page.slug)));
|
|
161
|
+
}
|
|
162
|
+
if (!Array.isArray(page.regions)) {
|
|
163
|
+
issues.push(shapeIssue('page.regions', 'regions 不是数组。', describeOouiValue(page.regions)));
|
|
164
|
+
return { plan: null, issues };
|
|
165
|
+
}
|
|
166
|
+
if (page.regions.length === 0) {
|
|
167
|
+
issues.push(oouiIssue(
|
|
168
|
+
'OOUI-SEM-REGIONS-EMPTY',
|
|
169
|
+
at(slug, 'regions'),
|
|
170
|
+
'页面组合声明了 regions: [],一个区域都没有。',
|
|
171
|
+
'零区域的页面照常编译、照常上线,产物里 regions 是空数组——'
|
|
172
|
+
+ '而「这一页什么都没演绎」与「这一页的接口还没返回」在浏览器里长得一模一样,'
|
|
173
|
+
+ '既没有异常也没有日志。',
|
|
174
|
+
'至少写一个区域:\n'
|
|
175
|
+
+ " regions:\n"
|
|
176
|
+
+ ' - name: list\n'
|
|
177
|
+
+ ' request: { object: ticket, verb: browse }',
|
|
178
|
+
));
|
|
179
|
+
return { plan: null, issues };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ── ① 区域名:文法与唯一性 ───────────────────────────────────────
|
|
183
|
+
const seen = new Map<string, number>();
|
|
184
|
+
const rootId = SOMA_PAGE_ROOT_ID;
|
|
185
|
+
page.regions.forEach((region, index) => {
|
|
186
|
+
const path = at(slug, `regions[${index}]`);
|
|
187
|
+
if (region === null || typeof region !== 'object' || Array.isArray(region)) {
|
|
188
|
+
issues.push(shapeIssue(path, '区域不是映射。', describeOouiValue(region)));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const name = region.name;
|
|
192
|
+
if (typeof name !== 'string' || !SOMA_OOUI_ANCHOR_PATTERN.test(name) || name === rootId) {
|
|
193
|
+
issues.push(oouiIssue(
|
|
194
|
+
'OOUI-SEM-REGION-NAME',
|
|
195
|
+
`${path}.name`,
|
|
196
|
+
name === rootId
|
|
197
|
+
? `区域名 "${name}" 与页面区域组的节点 id 撞车。`
|
|
198
|
+
: `区域名 ${describeOouiValue(name)} 不是合法的节点标识。`,
|
|
199
|
+
'区域名会成为空间 IR 的节点 id 并**原样进 CSS 属性选择器**。'
|
|
200
|
+
+ '带引号或括号会让选择器提前闭合,而被吃掉的那部分规则**不报错**,只是不生效;'
|
|
201
|
+
+ `与根节点 id 撞车则两者共用同一条规则,后解出的覆盖先解出的,`
|
|
202
|
+
+ '表现是「其中一处的宽度莫名其妙跟另一处一样」。',
|
|
203
|
+
`区域名文法:${SOMA_OOUI_ANCHOR_GRAMMAR}(正则 ${SOMA_OOUI_ANCHOR_PATTERN.source}),`
|
|
204
|
+
+ `且不得等于页面区域组的 id "${rootId}"(要改这个 id 走 solvePageBudget 的 rootId 选项):\n`
|
|
205
|
+
+ ` - name: detail\n request: { object: ticket, verb: inspect }`,
|
|
206
|
+
region.request?.src,
|
|
207
|
+
));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const first = seen.get(name);
|
|
211
|
+
if (first !== undefined) {
|
|
212
|
+
issues.push(oouiIssue(
|
|
213
|
+
'OOUI-SEM-REGION-DUPLICATE',
|
|
214
|
+
`${path}.name`,
|
|
215
|
+
`区域名 "${name}" 出现了两次(regions[${first}] 与 regions[${index}])。`,
|
|
216
|
+
'重名的两个区域会共用同一个节点 id:布局解与产物选择器完全重合,'
|
|
217
|
+
+ '后注入的那份静默盖住先注入的,而两块都还渲染着——只是其中一块的样式来自另一块。'
|
|
218
|
+
+ '`boundTo` 指向重名区域时更坏:指到哪一个取决于遍历顺序。',
|
|
219
|
+
`给其中一个换个名字(如 "${name}2")——两个区域必须能被分别指到。`,
|
|
220
|
+
region.request?.src,
|
|
221
|
+
));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
seen.set(name, index);
|
|
225
|
+
});
|
|
226
|
+
if (issues.length > 0) return { plan: null, issues };
|
|
227
|
+
|
|
228
|
+
// ── ①½ 区域约束:键白名单 + 值的原始类型 + sizing 三档 ───────────────
|
|
229
|
+
// 约束会被摊进空间 IR 的叶子,而叶子上还有 `id` / `kind` / `anchor` / `classes` 这些结构键。
|
|
230
|
+
// 放行一个 `layout: { id: x }`,叶子就被改了名,求解结果里再也找不到这个区域——
|
|
231
|
+
// 此前那里读成 0rem,于是这个区域静默降到最窄的候选,页面照常渲染。
|
|
232
|
+
// sizing 写出闭集(`fil`)是同一族:求解器既不按 fixed 也不按 fill 处理,区域缩到下界。
|
|
233
|
+
for (const region of page.regions) {
|
|
234
|
+
const layout: unknown = region.layout;
|
|
235
|
+
if (layout === undefined) continue;
|
|
236
|
+
const path = at(slug, `${region.name}.layout`);
|
|
237
|
+
if (!isOouiMap(layout)) {
|
|
238
|
+
issues.push(layoutIssue(
|
|
239
|
+
region,
|
|
240
|
+
path,
|
|
241
|
+
`区域 "${region.name}" 的 layout 不是映射(收到 ${describeOouiValue(layout)})。`,
|
|
242
|
+
));
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const problem = findOouiLayoutProblem(layout);
|
|
246
|
+
if (problem === undefined) continue;
|
|
247
|
+
if (problem.kind === 'sizing-unknown') {
|
|
248
|
+
issues.push(sizingIssue(region, `${path}.sizing`, layout.sizing));
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
issues.push(layoutIssue(
|
|
252
|
+
region,
|
|
253
|
+
`${path}.${problem.key}`,
|
|
254
|
+
problem.kind === 'unknown-key'
|
|
255
|
+
? `区域 "${region.name}" 的 layout 里有约束键之外的 "${problem.key}"。`
|
|
256
|
+
: `区域 "${region.name}" 的 layout.${problem.key} 应当是 ${problem.expected}`
|
|
257
|
+
+ `(收到 ${describeOouiValue(layout[problem.key])})。`,
|
|
258
|
+
));
|
|
259
|
+
}
|
|
260
|
+
if (issues.length > 0) return { plan: null, issues };
|
|
261
|
+
|
|
262
|
+
const byName = new Map<string, SomaRegion>();
|
|
263
|
+
for (const region of page.regions) byName.set(region.name, region);
|
|
264
|
+
const names = page.regions.map((region) => region.name);
|
|
265
|
+
|
|
266
|
+
// ── ② 动词:闭集。不合法的话下面取事件表会取到 undefined ────────
|
|
267
|
+
for (const region of page.regions) {
|
|
268
|
+
if (!isSomaVerb(region.request?.verb)) {
|
|
269
|
+
issues.push(oouiIssue(
|
|
270
|
+
'OOUI-SEM-VERB-UNKNOWN',
|
|
271
|
+
at(slug, `${region.name}.request.verb`),
|
|
272
|
+
`区域 "${region.name}" 的动词是 ${describeOouiValue(region.request?.verb)},不在八动词封闭集里。`,
|
|
273
|
+
'动词是根形态与事件契约的唯一分派依据。取不到它时本层的联动判据会拿一个 '
|
|
274
|
+
+ 'undefined 去查事件表,查不到就退化成「这个区域不产生任何事件」——'
|
|
275
|
+
+ '于是所有指向它的联动被一次性判成不成立,报出来的十条错误全都指错了方向。',
|
|
276
|
+
`八动词:${SOMA_VERBS.join(' / ')}。`,
|
|
277
|
+
region.request?.src,
|
|
278
|
+
));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (issues.length > 0) return { plan: null, issues };
|
|
282
|
+
|
|
283
|
+
// ── ③ 联动引用:区域存在、事件名在闭集里 ─────────────────────────
|
|
284
|
+
for (const region of page.regions) {
|
|
285
|
+
const binding = region.boundTo;
|
|
286
|
+
if (binding === undefined) continue;
|
|
287
|
+
const path = at(slug, `${region.name}.boundTo`);
|
|
288
|
+
if (binding === null || typeof binding !== 'object' || Array.isArray(binding)) {
|
|
289
|
+
issues.push(shapeIssue(path, 'boundTo 不是映射(至少含 region 与 as)。', describeOouiValue(binding)));
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
// 键闭集与 `ooui:` 的 `bound_to` 同一份(`SOMA_OOUI_BINDING_KEYS`):多出来的键此前没有任何一层读,
|
|
293
|
+
// 作者以为钉住了的那一项从声明那一刻起就不存在。
|
|
294
|
+
const unknownKey = findOouiBindingUnknownKey(binding);
|
|
295
|
+
if (unknownKey !== undefined) {
|
|
296
|
+
issues.push(bindingKeyIssue(region, `${path}.${unknownKey}`, unknownKey));
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (typeof binding.region !== 'string' || !byName.has(binding.region)) {
|
|
300
|
+
issues.push(oouiIssue(
|
|
301
|
+
'OOUI-SEM-BINDING-REGION-UNKNOWN',
|
|
302
|
+
`${path}.region`,
|
|
303
|
+
`联动源 ${describeOouiValue(binding.region)} 不是本页任何一个区域。`,
|
|
304
|
+
'指不到区域的联动**不会抛异常**:它只是一条永远不会被触发的线。'
|
|
305
|
+
+ '页面照常渲染、左边照常能点,右边永远停在初始态——'
|
|
306
|
+
+ '而「没有人监听这个事件」与「这个事件还没发生」在运行期是同一件事。',
|
|
307
|
+
`本页区域:${names.join(' / ')}。写成其中之一:\n`
|
|
308
|
+
+ ` boundTo: { region: ${names[0]}, as: select }`,
|
|
309
|
+
region.request?.src,
|
|
310
|
+
));
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (binding.region === region.name) {
|
|
314
|
+
issues.push(cycleIssue(slug, [region.name, region.name], region));
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (!isSomaInteractionKind(binding.as)) {
|
|
318
|
+
issues.push(oouiIssue(
|
|
319
|
+
'OOUI-SEM-BINDING-EVENT-UNKNOWN',
|
|
320
|
+
`${path}.as`,
|
|
321
|
+
`联动事件 ${describeOouiValue(binding.as)} 不在语义事件封闭集里。`,
|
|
322
|
+
'语义事件名是**体系的公事**(§16.3),组件的 emit 名是组件库的私事。'
|
|
323
|
+
+ '把 `row_open` 写成 `rowOpen` 的表现不是报错,而是这条线接到了一个'
|
|
324
|
+
+ '没人监听的名字上——与「组件根本没 emit」在运行期完全无法区分。',
|
|
325
|
+
`语义事件闭集(受控语汇在前、自治语汇在后):\n ${SOMA_INTERACTION_KINDS.join(' / ')}`,
|
|
326
|
+
region.request?.src,
|
|
327
|
+
));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (issues.length > 0) return { plan: null, issues };
|
|
331
|
+
|
|
332
|
+
// ── ④ 成环 ───────────────────────────────────────────────────────
|
|
333
|
+
const { order, cycles } = topoOrder(names, byName);
|
|
334
|
+
for (const cycle of cycles) {
|
|
335
|
+
issues.push(cycleIssue(slug, cycle, byName.get(cycle[0])));
|
|
336
|
+
}
|
|
337
|
+
if (issues.length > 0) return { plan: null, issues };
|
|
338
|
+
|
|
339
|
+
// ── ⑤ 联动契约:源区域的动词到底产不产生这个事件 ─────────────────
|
|
340
|
+
const bindings: SomaBindingVerdict[] = [];
|
|
341
|
+
for (const region of page.regions) {
|
|
342
|
+
const binding = region.boundTo;
|
|
343
|
+
if (binding === undefined) continue;
|
|
344
|
+
const source = byName.get(binding.region)!;
|
|
345
|
+
const sourceVerb = source.request.verb;
|
|
346
|
+
const available = producedEvents(sourceVerb, source.request.object);
|
|
347
|
+
|
|
348
|
+
const requiredUnder = SOMA_CONTROL_MODELS.filter(
|
|
349
|
+
(model) => available[model].required.includes(binding.as),
|
|
350
|
+
);
|
|
351
|
+
const optionalUnder = SOMA_CONTROL_MODELS.filter(
|
|
352
|
+
(model) => available[model].optional.includes(binding.as),
|
|
353
|
+
);
|
|
354
|
+
let holdsFor = SOMA_CONTROL_MODELS.filter(
|
|
355
|
+
(model) => requiredUnder.includes(model) || optionalUnder.includes(model),
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
if (holdsFor.length === 0) {
|
|
359
|
+
issues.push(unsupportedIssue({
|
|
360
|
+
slug, region, binding, source, sourceVerb, available, names, byName,
|
|
361
|
+
}));
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 第二遍:构件选定之后收紧。**给了才收,不给不假装核过**。
|
|
366
|
+
let confirmedBy: SomaBindingVerdict['confirmedBy'];
|
|
367
|
+
const model = options.controlModels?.[source.name];
|
|
368
|
+
if (model !== undefined) {
|
|
369
|
+
holdsFor = holdsFor.filter((candidate) => candidate === model);
|
|
370
|
+
confirmedBy = 'control-model';
|
|
371
|
+
if (holdsFor.length === 0) {
|
|
372
|
+
issues.push(narrowedIssue({ slug, region, binding, source, sourceVerb, model, available }));
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const emits = options.emits?.[source.name];
|
|
377
|
+
if (emits !== undefined) {
|
|
378
|
+
confirmedBy = 'emits';
|
|
379
|
+
if (!emits.includes(binding.as)) {
|
|
380
|
+
issues.push(emitsIssue({ slug, region, binding, source, emits }));
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const caveat = caveatFor({
|
|
386
|
+
source: source.name, sourceVerb, as: binding.as, holdsFor, requiredUnder, confirmedBy,
|
|
387
|
+
});
|
|
388
|
+
bindings.push({
|
|
389
|
+
region: region.name,
|
|
390
|
+
source: source.name,
|
|
391
|
+
as: binding.as,
|
|
392
|
+
sourceVerb,
|
|
393
|
+
requiredUnder,
|
|
394
|
+
optionalUnder,
|
|
395
|
+
holdsFor,
|
|
396
|
+
...(caveat !== undefined ? { caveat } : {}),
|
|
397
|
+
...(confirmedBy !== undefined ? { confirmedBy } : {}),
|
|
398
|
+
...(region.request.src !== undefined ? { src: region.request.src } : {}),
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
if (issues.length > 0) return { plan: null, issues };
|
|
402
|
+
|
|
403
|
+
// ── ⑥ 把「哪一半没核」记进产物:不给则不核,且不假装核过了 ───────
|
|
404
|
+
const unchecked = names.filter((name) => (
|
|
405
|
+
options.controlModels?.[name] === undefined && options.emits?.[name] === undefined
|
|
406
|
+
));
|
|
407
|
+
if (bindings.length > 0 && unchecked.length > 0) {
|
|
408
|
+
decisions.push({
|
|
409
|
+
path: at(slug, 'bindings'),
|
|
410
|
+
conclusion: `${unchecked.length} 个区域只跑了声明期这一遍:`
|
|
411
|
+
+ `${unchecked.join(' / ')} 的控制模型与真实 emit 都没喂回来,`
|
|
412
|
+
+ '带 caveat 的联动尚未收紧',
|
|
413
|
+
rule: 'options.controlModels / options.emits 缺席',
|
|
414
|
+
origin: 'defaulted',
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
if (bindings.length === 0) {
|
|
418
|
+
decisions.push({
|
|
419
|
+
path: at(slug, 'bindings'),
|
|
420
|
+
conclusion: '本页没有任何区域间联动——各区域各自独立演绎',
|
|
421
|
+
rule: 'boundTo 未声明',
|
|
422
|
+
origin: 'declared',
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return {
|
|
427
|
+
plan: { slug, regions: names, bindings, order, decisions },
|
|
428
|
+
issues: [],
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* 校验,不过就抛(铁律二的硬形态)。
|
|
434
|
+
*
|
|
435
|
+
* 折叠口径(码取第一条、一次列全、单条时直接给那一条的修法)归横切层
|
|
436
|
+
* `foldOouiIssues` 一处——此前这里与编排层、表层入口各折叠一遍,措辞已经漂开。
|
|
437
|
+
*/
|
|
438
|
+
export function assertPageComposition(
|
|
439
|
+
page: SomaPageComposition,
|
|
440
|
+
options: SomaPageCheckOptions = {},
|
|
441
|
+
): SomaPageCompositionPlan {
|
|
442
|
+
const result = validatePageComposition(page, options);
|
|
443
|
+
if (result.plan !== null) return result.plan;
|
|
444
|
+
throw foldOouiIssues({
|
|
445
|
+
layer: 'semantic',
|
|
446
|
+
headline: '页面组合声明不成立',
|
|
447
|
+
issues: result.issues,
|
|
448
|
+
src: { file: `<page:${typeof page?.slug === 'string' ? page.slug : '?'}>`, path: 'regions' },
|
|
449
|
+
fallback: {
|
|
450
|
+
code: 'OOUI-SEM-PAGE-SHAPE',
|
|
451
|
+
problem: '联动不成立时产出的是一个能渲染、能点、看着正常的页面,只是点了没反应。',
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// ─────────────────────────────────────────────────────────────
|
|
457
|
+
// 内部
|
|
458
|
+
// ─────────────────────────────────────────────────────────────
|
|
459
|
+
|
|
460
|
+
/** 区域约束的形状拒收。码仍是 `OOUI-SEM-PAGE-SHAPE`(形状问题),修法专说约束的写法 */
|
|
461
|
+
function layoutIssue(region: SomaRegion, path: string, situation: string): SomaOouiIssue {
|
|
462
|
+
return oouiIssue(
|
|
463
|
+
'OOUI-SEM-PAGE-SHAPE',
|
|
464
|
+
path,
|
|
465
|
+
situation,
|
|
466
|
+
'区域约束会被摊进空间 IR 的叶子,而叶子上还有 id / kind / anchor / classes 这些结构键:'
|
|
467
|
+
+ '约束键之外的键要么被静默丢弃,要么顶掉结构键——`layout: { id: x }` 会把叶子改名,'
|
|
468
|
+
+ '求解结果里从此找不到这个区域,而页面照常渲染。',
|
|
469
|
+
`区域约束只收 ${SOMA_OOUI_LAYOUT_KEYS.join(' / ')}(长度写带单位的字符串,priority 写数字):\n`
|
|
470
|
+
+ ` { name: '${region.name}', request: …, layout: { sizing: 'fill', min: '10rem', priority: 750 } }`,
|
|
471
|
+
region.request?.src,
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* 区域约束的 sizing 不在三档里。码是 `OOUI-SPA-SIZING-UNKNOWN`——被违反的是空间层的闭集
|
|
477
|
+
* (前缀按「谁的契约」取),发现它的是本层:在声明期指着那一行报,而不是等 IR 树求解时报一个
|
|
478
|
+
* 指着 `page.<区域名>` 的路径。
|
|
479
|
+
*/
|
|
480
|
+
function sizingIssue(region: SomaRegion, path: string, got: unknown): SomaOouiIssue {
|
|
481
|
+
return oouiIssue(
|
|
482
|
+
'OOUI-SPA-SIZING-UNKNOWN',
|
|
483
|
+
path,
|
|
484
|
+
`区域 "${region.name}" 的 layout.sizing 是 ${describeOouiValue(got)},不在尺寸意图三档里。`,
|
|
485
|
+
'闭集之外的 sizing 既不是 fixed(按 width 定宽)也不是 fill(分余量),求解器只剩「从 min 起步」一条路:'
|
|
486
|
+
+ '这个区域静默缩到下界(没写 min 就是 0rem),构件选型随之降到最窄的候选——页面照常渲染。',
|
|
487
|
+
`sizing 只能是 ${SOMA_OOUI_SIZINGS.join(' / ')};省略即 fill(与其余区域等分):\n`
|
|
488
|
+
+ ` { name: '${region.name}', request: …, layout: { sizing: 'fill', min: '10rem', priority: 750 } }`,
|
|
489
|
+
region.request?.src,
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** `boundTo` 里有 `region` / `as` 之外的键 */
|
|
494
|
+
function bindingKeyIssue(region: SomaRegion, path: string, key: string): SomaOouiIssue {
|
|
495
|
+
return oouiIssue(
|
|
496
|
+
'OOUI-SEM-BINDING-KEY-UNKNOWN',
|
|
497
|
+
path,
|
|
498
|
+
`区域 "${region.name}" 的 boundTo 里有闭集之外的键 "${key}"。`,
|
|
499
|
+
'联动只认两项:源区域(region)与语义事件(as)。多出来的键没有任何一层会读——'
|
|
500
|
+
+ '作者以为钉住了的那一项(比如组件的 emit 名)从声明那一刻起就不存在,'
|
|
501
|
+
+ '而「写了没生效」与「这个能力不存在」在页面上分不开。',
|
|
502
|
+
`boundTo 只收 ${SOMA_OOUI_BINDING_KEYS.join(' / ')};as 写语义事件名,组件的 emit 名由候选表的 eventMap 接:\n`
|
|
503
|
+
+ ` { name: '${region.name}', request: …, boundTo: { region: 'list', as: 'select' } }`,
|
|
504
|
+
region.request?.src,
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function shapeIssue(path: string, situation: string, got: string): SomaOouiIssue {
|
|
509
|
+
return oouiIssue(
|
|
510
|
+
'OOUI-SEM-PAGE-SHAPE',
|
|
511
|
+
path,
|
|
512
|
+
`${situation}(收到 ${got})`,
|
|
513
|
+
'形状不对的那一段会被整条跳过——页面照常编译、照常上线,只是少了一块或少了一条联动,'
|
|
514
|
+
+ '而「少一块」与「这一块本来就没写」长得一模一样,没有任何日志。',
|
|
515
|
+
'页面组合的形状:\n'
|
|
516
|
+
+ ' { slug: \'/tickets\', regions: [\n'
|
|
517
|
+
+ ' { name: \'list\', request: { object: ticket, verb: \'browse\' } },\n'
|
|
518
|
+
+ ' { name: \'detail\', request: { object: ticket, verb: \'inspect\' },\n'
|
|
519
|
+
+ ' boundTo: { region: \'list\', as: \'select\' } },\n'
|
|
520
|
+
+ ' ] }',
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* 联动图的拓扑序 + 检环。照 `core/build/component/component-graph.ts` 的先例:
|
|
526
|
+
* **报出整条回路而不只是「成环了」**——只说成环的话,作者得自己把链条走一遍
|
|
527
|
+
* 才知道该断哪一条。
|
|
528
|
+
*
|
|
529
|
+
* 每个区域至多一个 `boundTo`(§29.1),所以这是一张函数图,一条回路只会被报一次。
|
|
530
|
+
* 仍然写成通用 DFS 而不是「顺着单链走」:`boundTo` 哪天变成数组时,
|
|
531
|
+
* 单链版本会**静默只看第一条**,而那正是本文件在防的那类失效。
|
|
532
|
+
*/
|
|
533
|
+
function topoOrder(
|
|
534
|
+
names: readonly string[],
|
|
535
|
+
byName: ReadonlyMap<string, SomaRegion>,
|
|
536
|
+
): { order: string[]; cycles: string[][] } {
|
|
537
|
+
const order: string[] = [];
|
|
538
|
+
const cycles: string[][] = [];
|
|
539
|
+
const state = new Map<string, 'visiting' | 'done'>();
|
|
540
|
+
const stack: string[] = [];
|
|
541
|
+
|
|
542
|
+
const visit = (name: string): void => {
|
|
543
|
+
const seen = state.get(name);
|
|
544
|
+
if (seen === 'done') return;
|
|
545
|
+
if (seen === 'visiting') {
|
|
546
|
+
const from = stack.indexOf(name);
|
|
547
|
+
if (from !== -1) cycles.push([...stack.slice(from), name]);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
state.set(name, 'visiting');
|
|
551
|
+
stack.push(name);
|
|
552
|
+
const source = byName.get(name)?.boundTo?.region;
|
|
553
|
+
if (source !== undefined && byName.has(source)) visit(source);
|
|
554
|
+
stack.pop();
|
|
555
|
+
state.set(name, 'done');
|
|
556
|
+
order.push(name);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
for (const name of names) visit(name);
|
|
560
|
+
return { order, cycles };
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function cycleIssue(slug: string, cycle: readonly string[], region?: SomaRegion): SomaOouiIssue {
|
|
564
|
+
const loop = cycle.join(' ← ');
|
|
565
|
+
const selfLoop = cycle.length === 2 && cycle[0] === cycle[1];
|
|
566
|
+
return oouiIssue(
|
|
567
|
+
'OOUI-SEM-BINDING-CYCLE',
|
|
568
|
+
at(slug, `${cycle[0]}.boundTo`),
|
|
569
|
+
selfLoop
|
|
570
|
+
? `区域 "${cycle[0]}" 的联动指向它自己。`
|
|
571
|
+
: `区域联动成环:${loop}。`,
|
|
572
|
+
'成环的联动图**不会抛异常**。运行期表现是这几个区域互相触发对方刷新:'
|
|
573
|
+
+ '轻则每次交互多取几轮数(用户只觉得「有点卡」),重则死循环——'
|
|
574
|
+
+ '而死循环在浏览器里表现为「页面卡住」,指不回任何一句声明。'
|
|
575
|
+
+ '指向自己的那条更隐蔽:它的输入是它自己的输出,第一次交互之后就再也不会稳定下来。',
|
|
576
|
+
selfLoop
|
|
577
|
+
? `删掉这条 boundTo,或把 region 改成**另一个**区域的名字——`
|
|
578
|
+
+ '一个区域的输入不能是它自己的输出。'
|
|
579
|
+
: `把回路上任意一条边断开。整条回路:${loop}。\n`
|
|
580
|
+
+ ` 断哪一条的判据:谁是这一页的**主区**(用户先操作的那个),主区不该有 boundTo。`,
|
|
581
|
+
region?.request.src,
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
interface UnsupportedInput {
|
|
586
|
+
slug: string;
|
|
587
|
+
region: SomaRegion;
|
|
588
|
+
binding: { region: string; as: SomaInteractionKind };
|
|
589
|
+
source: SomaRegion;
|
|
590
|
+
sourceVerb: SomaVerb;
|
|
591
|
+
available: Readonly<Record<SomaControlModel, SomaEventAvailability>>;
|
|
592
|
+
names: readonly string[];
|
|
593
|
+
byName: ReadonlyMap<string, SomaRegion>;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/** §29.2 的那条红线:源区域的动词在**两种控制模型下都**不产生这个事件 */
|
|
597
|
+
function unsupportedIssue(input: UnsupportedInput): SomaOouiIssue {
|
|
598
|
+
const { slug, region, binding, source, sourceVerb, available, names, byName } = input;
|
|
599
|
+
const produces = SOMA_CONTROL_MODELS
|
|
600
|
+
.map((model) => {
|
|
601
|
+
const list = [...available[model].required, ...available[model].optional];
|
|
602
|
+
return ` ${model}:${list.length > 0 ? list.join(' / ') : '(一个都不产生)'}`;
|
|
603
|
+
})
|
|
604
|
+
.join('\n');
|
|
605
|
+
// 「本页哪些区域产生这个事件」——不给这一行的话,作者只知道错了,不知道改成什么。
|
|
606
|
+
const alternatives = names.filter((name) => {
|
|
607
|
+
if (name === region.name) return false;
|
|
608
|
+
const other = byName.get(name)!;
|
|
609
|
+
const events = producedEvents(other.request.verb, other.request.object);
|
|
610
|
+
return SOMA_CONTROL_MODELS.some(
|
|
611
|
+
(model) => events[model].required.includes(binding.as) || events[model].optional.includes(binding.as),
|
|
612
|
+
);
|
|
613
|
+
});
|
|
614
|
+
return oouiIssue(
|
|
615
|
+
'OOUI-SEM-BINDING-UNSUPPORTED',
|
|
616
|
+
at(slug, `${region.name}.boundTo.as`),
|
|
617
|
+
`区域 "${region.name}" 监听 "${source.name}" 的 ${binding.as} 事件,`
|
|
618
|
+
+ `但 "${source.name}" 的动词是 ${sourceVerb}——它在两种控制模型下都不产生 ${binding.as}。`,
|
|
619
|
+
'这条线永远不会被触发,而**没有任何东西会报错**:页面照常编译、两个区域照常渲染、'
|
|
620
|
+
+ `点 "${source.name}" 照常有 hover,只是 "${region.name}" 永远不动。`
|
|
621
|
+
+ '「没有人监听这个事件」与「这个事件还没发生」在运行期是同一件事,'
|
|
622
|
+
+ '所以排查会从被绑区域的取数开始,一路查到接口、查到权限,而错在这一行。',
|
|
623
|
+
`三选一:\n`
|
|
624
|
+
+ ` (a) 改成 "${source.name}" 真会产生的事件:\n${produces}\n`
|
|
625
|
+
+ (alternatives.length > 0
|
|
626
|
+
? ` (b) 改成本页真会产生 ${binding.as} 的区域:${alternatives.join(' / ')}\n`
|
|
627
|
+
: ` (b) 本页没有任何区域产生 ${binding.as}——要它就得有一个动词产生它的区域。\n`)
|
|
628
|
+
+ ` (c) 换 "${source.name}" 的动词:${verbsProducing(binding.as).join(' / ') || '(八动词都不产生它,它只由对象的 window 段启用)'}`,
|
|
629
|
+
region.request.src,
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** 哪些动词(不看对象语义)会产生这个事件——建议里要报得出来,作者才知道该换成什么 */
|
|
634
|
+
function verbsProducing(kind: SomaInteractionKind): readonly SomaVerb[] {
|
|
635
|
+
return SOMA_VERBS.filter((verb) => SOMA_CONTROL_MODELS.some((model) => {
|
|
636
|
+
const spec = VERB_EVENTS_BY_MODEL[verb][model];
|
|
637
|
+
return spec.required.includes(kind) || spec.optional.includes(kind);
|
|
638
|
+
}));
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
interface NarrowedInput {
|
|
642
|
+
slug: string;
|
|
643
|
+
region: SomaRegion;
|
|
644
|
+
binding: { region: string; as: SomaInteractionKind };
|
|
645
|
+
source: SomaRegion;
|
|
646
|
+
sourceVerb: SomaVerb;
|
|
647
|
+
model: SomaControlModel;
|
|
648
|
+
available: Readonly<Record<SomaControlModel, SomaEventAvailability>>;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* 第二遍收紧后才发作的那一条:声明期通过了,构件层选了另一种控制模型的候选。
|
|
653
|
+
*
|
|
654
|
+
* **这是文件头 ② 那条全绿路径的落点**,也是本层与原型最大的差别。
|
|
655
|
+
*/
|
|
656
|
+
function narrowedIssue(input: NarrowedInput): SomaOouiIssue {
|
|
657
|
+
const { slug, region, binding, source, sourceVerb, model, available } = input;
|
|
658
|
+
const other: SomaControlModel = model === 'controlled' ? 'autonomous' : 'controlled';
|
|
659
|
+
const list = [...available[model].required, ...available[model].optional];
|
|
660
|
+
return oouiIssue(
|
|
661
|
+
'OOUI-SEM-BINDING-UNSUPPORTED',
|
|
662
|
+
at(slug, `${region.name}.boundTo.as`),
|
|
663
|
+
`区域 "${region.name}" 监听 "${source.name}" 的 ${binding.as}:`
|
|
664
|
+
+ `${sourceVerb} 只在 ${other} 型下产生它,而构件层给 "${source.name}" 选中的是 ${model} 型组件。`,
|
|
665
|
+
'声明期这条联动是通过的——「动词产生这个事件」这句话本身没错,'
|
|
666
|
+
+ '错在它**只在另一种控制模型下**成立。自治型组件自己取数、自己翻页,'
|
|
667
|
+
+ '它的语汇是过去式的完成通知(loaded / row_open / action_done),'
|
|
668
|
+
+ '永远 emit 不出进行时的意图事件。于是这条线在运行期是死的,'
|
|
669
|
+
+ '而声明、产物、单测三处全绿。',
|
|
670
|
+
`三选一:\n`
|
|
671
|
+
+ ` (a) 改成 ${model} 型下真会产生的事件:${list.length > 0 ? list.join(' / ') : '(一个都不产生)'}\n`
|
|
672
|
+
+ ` (b) 让 "${source.name}" 落到 ${other} 型组件上——`
|
|
673
|
+
+ `给该区域的请求加 form 逃生门,或在 env.availableComponents 里把 ${model} 型候选摘掉;\n`
|
|
674
|
+
+ ` (c) 这条联动确实不该有,删掉 boundTo。`,
|
|
675
|
+
region.request.src,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
interface EmitsInput {
|
|
680
|
+
slug: string;
|
|
681
|
+
region: SomaRegion;
|
|
682
|
+
binding: { region: string; as: SomaInteractionKind };
|
|
683
|
+
source: SomaRegion;
|
|
684
|
+
emits: readonly SomaInteractionKind[];
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** 最紧的一道:选中组件的 eventMap 压根没接这个语义事件 */
|
|
688
|
+
function emitsIssue(input: EmitsInput): SomaOouiIssue {
|
|
689
|
+
const { slug, region, binding, source, emits } = input;
|
|
690
|
+
return oouiIssue(
|
|
691
|
+
'OOUI-SEM-BINDING-UNSUPPORTED',
|
|
692
|
+
at(slug, `${region.name}.boundTo.as`),
|
|
693
|
+
`区域 "${region.name}" 监听 "${source.name}" 的 ${binding.as},`
|
|
694
|
+
+ `但构件层给 "${source.name}" 选中的组件只路由出 `
|
|
695
|
+
+ `${emits.length > 0 ? emits.join(' / ') : '(一个语义事件都没有)'}。`,
|
|
696
|
+
'动词层面这条联动成立,组件层面不成立:候选表的 eventMap 没有把该组件的某个 emit '
|
|
697
|
+
+ `接到 ${binding.as} 上。表现与「组件根本没 emit」完全一样——点了没反应,`
|
|
698
|
+
+ '而候选表看着完全正常(漏接的那个 emit 躺在候选的 `unmappedEmits` 里,那只是告警面)。',
|
|
699
|
+
`三选一:\n`
|
|
700
|
+
+ ` (a) 在候选表里把该组件的对应 emit 接上:eventMap: { <emit 名>: '${binding.as}' }\n`
|
|
701
|
+
+ ` (b) 改成它真会路由出的事件:${emits.join(' / ') || '(没有)'}\n`
|
|
702
|
+
+ ` (c) 换一个能产生 ${binding.as} 的组件(收窄 env.availableComponents,或给该区域写 form 逃生门)。`,
|
|
703
|
+
region.request.src,
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** 这条结论在什么条件下会变(铁律四的可读形态)。无条件成立时返回 undefined */
|
|
708
|
+
function caveatFor(input: {
|
|
709
|
+
source: string;
|
|
710
|
+
sourceVerb: SomaVerb;
|
|
711
|
+
as: SomaInteractionKind;
|
|
712
|
+
holdsFor: readonly SomaControlModel[];
|
|
713
|
+
requiredUnder: readonly SomaControlModel[];
|
|
714
|
+
confirmedBy: SomaBindingVerdict['confirmedBy'];
|
|
715
|
+
}): string | undefined {
|
|
716
|
+
const { source, sourceVerb, as, holdsFor, requiredUnder, confirmedBy } = input;
|
|
717
|
+
if (confirmedBy === 'emits') return undefined; // 已按真实 emit 核过,没有可变量了
|
|
718
|
+
const clauses: string[] = [];
|
|
719
|
+
if (confirmedBy !== 'control-model' && holdsFor.length === 1) {
|
|
720
|
+
const only = holdsFor[0];
|
|
721
|
+
const other: SomaControlModel = only === 'controlled' ? 'autonomous' : 'controlled';
|
|
722
|
+
clauses.push(
|
|
723
|
+
`只在 "${source}" 落到${only === 'controlled' ? '受控' : '自治'}型组件时成立:`
|
|
724
|
+
+ `${sourceVerb} 在${other === 'controlled' ? '受控' : '自治'}型下不产生 ${as}`,
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
const notGuaranteed = holdsFor.filter((model) => !requiredUnder.includes(model));
|
|
728
|
+
if (notGuaranteed.length > 0) {
|
|
729
|
+
clauses.push(
|
|
730
|
+
`${as} 在 ${notGuaranteed.join(' / ')} 型下只是**可选**事件:`
|
|
731
|
+
+ '成不成立取决于选中组件的 eventMap 有没有接它',
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
if (clauses.length === 0) return undefined;
|
|
735
|
+
return `${clauses.join(';')}。构件选定后把 controlModels / emits 喂回 validatePageComposition 再核一遍`;
|
|
736
|
+
}
|