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,326 @@
|
|
|
1
|
+
// ooui 横切 · 推导链 `SomaTrace`——架构 §5「每层产物都带 trace」的落点。
|
|
2
|
+
//
|
|
3
|
+
// ── 为什么"没有 trace"是一种静默失败 ───────────────────────────────
|
|
4
|
+
// 自动推导最大的风险不是**算错**,是**算错了且不知道为什么**(架构 §5 原文)。
|
|
5
|
+
// 这句话的可执行形态是:一份没有 trace 的产物,**坏掉的时候和对的时候长得一模一样**。
|
|
6
|
+
//
|
|
7
|
+
// ① **推导错了没有现场。** 页面上标题栏显示的是订单备注。产物是对的形状:
|
|
8
|
+
// HTML 有、CSS 有、绑定有、`decisions` 里也有一条"字段 remark 落成 display"。
|
|
9
|
+
// 可是**没人答得出为什么是 remark**——那条结论出自哪条规则、依据哪句声明,
|
|
10
|
+
// 在产物里没有任何一处写着。作者只能在六层里逐层加 `console.log` 反推,
|
|
11
|
+
// 而反推出来的因果与引擎真实走过的路是否一致,没有任何东西担保。
|
|
12
|
+
//
|
|
13
|
+
// ② **局部台账互相看不见对方。** 今天各层已经各有一份"我做了什么决定":
|
|
14
|
+
// 语义层的 `SomaOriginLedger`、空间层与产物层的 `SomaSpatialDecision`、
|
|
15
|
+
// 意图层的 `rule` 字段、构件层的 `considered`。四份都是真的,
|
|
16
|
+
// **但它们之间没有边**。于是"这条 CSS 规则来自哪句对象声明"这个问题,
|
|
17
|
+
// 在任何一份台账里都答不出来——每一份都只覆盖一跳。
|
|
18
|
+
// 四份齐全、每份都绿,而跨层的那个问题依然无解:这正是"看起来已经有了"的失败。
|
|
19
|
+
//
|
|
20
|
+
// ③ **没有 trace 的推导会悄悄进主路径。** 架构 §5 写着"没有 trace 的推导
|
|
21
|
+
// 不允许进主路径",而这条纪律若只是文档里的一句话,新加的推导默认就是不带 trace 的:
|
|
22
|
+
// 不带 trace 的代码**编译通过、测试全绿、页面渲染正常**。
|
|
23
|
+
// 它必须落成闸门(§8「推导可解释:每条结论都有 trace」),
|
|
24
|
+
// 而闸门要有东西可查,就必须先有这个类型。
|
|
25
|
+
//
|
|
26
|
+
// ── 与 `decisions` / `origin` 台账的关系:接上,不另起 ────────────────
|
|
27
|
+
// 本文件**不废除**已有的局部台账,它们是 trace 的**原料**:
|
|
28
|
+
// · `SomaOriginLedger`(语义层) → `originTraces(ledger)` 转成 `layer:'semantic'` 的 trace
|
|
29
|
+
// · `SomaIntent.rule` + `src` → `intentTrace(intent, parent)`
|
|
30
|
+
// · `SomaCompositionChoice` → `compositionTrace(choice, …)`
|
|
31
|
+
// · `SomaSpatialDecision` → `spatialTraces(plan, parent)` / `decisionTrace(…)`
|
|
32
|
+
// 转换函数**住在各自的层里**(那里才认识那些类型),本层只提供类型与链条工具。
|
|
33
|
+
// 这是依赖倒置的必然结果,见下面的边界一节。
|
|
34
|
+
//
|
|
35
|
+
// ── 边界:横切不认识业务 ────────────────────────────────────────────
|
|
36
|
+
// 本文件**不得** import 任何管线层(semantic / intent / composition / spatial /
|
|
37
|
+
// artifact),`verify-ooui-dep-graph` 判 `CROSSCUT-DOWNWARD` 当场红。
|
|
38
|
+
// 因此 `SomaTrace` 里没有任何一个字段的类型来自业务层:`conclusion` / `rule` / `note`
|
|
39
|
+
// 都是字符串,`from` 是同属横切层的 `SomaSource`。
|
|
40
|
+
// 代价是**各层的语义在这里被压成人话**——这是有意的:trace 的消费方是闸门与人,
|
|
41
|
+
// 不是下一层的求解器。要结构化消费某一层的产物,读那一层自己的产物字段,
|
|
42
|
+
// 不要把业务结构塞进 trace 让它长成第二份产物。
|
|
43
|
+
//
|
|
44
|
+
// ── 序列化纪律 ──────────────────────────────────────────────────────
|
|
45
|
+
// `SomaOouiError.trace` 会被 `compile-gate.ts` 做一次 `JSON.parse(JSON.stringify(…))`,
|
|
46
|
+
// **带函数或循环引用时它会静默丢掉整条链**(它宁可丢 trace 也不让诊断本身变成新失败面)。
|
|
47
|
+
// 所以本类型是纯数据:无函数、无 Map/Set;`parent` 构成的是一条**链**不是图,
|
|
48
|
+
// 成环时 `traceChain` / `traceDefects` 当场点名(见 `TRACE_MAX_DEPTH`)。
|
|
49
|
+
|
|
50
|
+
import type { SomaSource } from './source.types';
|
|
51
|
+
import { formatSomaSource } from './source.types';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 五层管线的层名。**与 `verify-ooui-dep-graph.mjs` 的 `PIPELINE` 同序**——
|
|
55
|
+
* 下标即上下游次序,`traceDefects` 靠它判"链条有没有倒流"。
|
|
56
|
+
*
|
|
57
|
+
* 分发层 ⑥ 不在其中:它不做推导,只做版本与寻址(架构 §3.6)。
|
|
58
|
+
*/
|
|
59
|
+
export const SOMA_TRACE_LAYERS = ['semantic', 'intent', 'composition', 'spatial', 'artifact'] as const;
|
|
60
|
+
export type SomaTraceLayer = typeof SOMA_TRACE_LAYERS[number];
|
|
61
|
+
|
|
62
|
+
/** 层名 → 上下游次序。链条只许从下标大的指回下标小的(或同层) */
|
|
63
|
+
const LAYER_ORDER: Readonly<Record<string, number>> = Object.fromEntries(
|
|
64
|
+
SOMA_TRACE_LAYERS.map((layer, index) => [layer, index]),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 一条结论是怎么来的。**前三个与语义层 `SomaValueOrigin` 逐字对齐**
|
|
69
|
+
* (`declared` / `defaulted` / `inferred`,见 `semantic/origin.types.ts` 的判据),
|
|
70
|
+
* 第四个 `declined` 是"想猜但没敢猜"——它在语义层是另一个类型
|
|
71
|
+
* (`SomaOriginDecline`),到了 trace 这里两者都只是"一条结论",故并成一个轴。
|
|
72
|
+
*
|
|
73
|
+
* **为什么不 import 语义层那个联合类型**:横切不许认识业务层(见文件头)。
|
|
74
|
+
* 抄本漂移由**转换函数**挡:`originTraces()` 把 `SomaValueOrigin` 赋给本类型,
|
|
75
|
+
* 语义层哪天加了第四种来历,那一行当场编译红——
|
|
76
|
+
* 这比"两份联合类型碰巧一样"要硬,后者漂开时没有任何东西会红。
|
|
77
|
+
*/
|
|
78
|
+
export type SomaTraceOrigin = 'declared' | 'defaulted' | 'inferred' | 'declined';
|
|
79
|
+
|
|
80
|
+
/** 链条最大深度。超过即判定成环——五层管线的真实链条不会超过它 */
|
|
81
|
+
export const TRACE_MAX_DEPTH = 64;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 缺陷文案里引用别人的结论时的截断长度。
|
|
85
|
+
*
|
|
86
|
+
* 为什么要截:一条语义层结论会把对象的十几个字段名列全,而闸门失败时
|
|
87
|
+
* 每条不合格的 trace 都要引用它一次——三十条乘一百字,失败输出滚过两屏,
|
|
88
|
+
* **真正要看的那句"没有上溯到 semantic 层"被推到看不见的地方**。
|
|
89
|
+
* 报告(`renderTrace`)不截:那里是逐条看的,信息完整比短更重要。
|
|
90
|
+
*/
|
|
91
|
+
const BRIEF_LIMIT = 32;
|
|
92
|
+
|
|
93
|
+
const brief = (text: string): string => (
|
|
94
|
+
text.length <= BRIEF_LIMIT ? text : `${text.slice(0, BRIEF_LIMIT)}…`
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 一条推导记录(架构 §5)。
|
|
99
|
+
*
|
|
100
|
+
* 前五个字段是架构原文的,后四个是落地时补的,各有不可省的理由:
|
|
101
|
+
*
|
|
102
|
+
* · `path` —— 结论**落在哪**(节点路径 / 选择器 / 核心层路径)。
|
|
103
|
+
* 与 `from.path` 是两件事:`from` 指的是**依据**在哪一行,`path` 指的是
|
|
104
|
+
* **结论**作用在哪个东西上。合成一个字段的话,"按 order.yaml 第 12 行
|
|
105
|
+
* 推出了 detail.amount 的形态"这句话就只剩一半,而剩下哪一半取决于谁先写。
|
|
106
|
+
* · `origin` —— 铁律三:写的 / 补的 / 猜的 / 没敢猜,必须可区分。
|
|
107
|
+
* 诊断报告最有用的那一行(§5.1 末行)正是从它来的。
|
|
108
|
+
* · `note` —— 一句人话,报告直接印。conclusion 是"得出了什么",
|
|
109
|
+
* note 是"顺便你该知道的"(如落选候选的原因),两者混写会让报告第一行变成一段。
|
|
110
|
+
* · `caveat` —— **这条结论在什么条件下会变**。铁律四(编译期决策对运行时可变量
|
|
111
|
+
* 取保守边界)的可读形态:§5.1 那行 `⚠ 若窄于 18rem 将降级为 Select` 就是它。
|
|
112
|
+
* 没有这个字段的话,"这次成立"与"永远成立"在报告里长得一模一样。
|
|
113
|
+
*/
|
|
114
|
+
export interface SomaTrace {
|
|
115
|
+
/** 哪一层得出的 */
|
|
116
|
+
readonly layer: SomaTraceLayer;
|
|
117
|
+
/** 得出了什么 */
|
|
118
|
+
readonly conclusion: string;
|
|
119
|
+
/** 依据哪条规则。作者显式声明时写 `declared`(声明本身就是理由) */
|
|
120
|
+
readonly rule: string;
|
|
121
|
+
/** 依据哪句声明。合成来源用 `<rule:…>` / `<vocabulary:…>` 形态,**不留空** */
|
|
122
|
+
readonly from: SomaSource;
|
|
123
|
+
/** 上一层的 trace,构成完整链条 */
|
|
124
|
+
readonly parent?: SomaTrace;
|
|
125
|
+
/** 结论落在哪个路径上(节点路径 / 选择器 / 核心层路径) */
|
|
126
|
+
readonly path?: string;
|
|
127
|
+
/** 写的 / 补的 / 猜的 / 没敢猜 */
|
|
128
|
+
readonly origin?: SomaTraceOrigin;
|
|
129
|
+
/** 一句人话,诊断报告直接印 */
|
|
130
|
+
readonly note?: string;
|
|
131
|
+
/** 这条结论在什么条件下会变(运行时可变量的保守边界) */
|
|
132
|
+
readonly caveat?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** `traceLink` 的入参:与 `SomaTrace` 同形,可选字段给 `undefined` 即视为不给 */
|
|
136
|
+
export interface SomaTraceInput {
|
|
137
|
+
readonly layer: SomaTraceLayer;
|
|
138
|
+
readonly conclusion: string;
|
|
139
|
+
readonly rule: string;
|
|
140
|
+
readonly from: SomaSource;
|
|
141
|
+
readonly parent?: SomaTrace | undefined;
|
|
142
|
+
readonly path?: string | undefined;
|
|
143
|
+
readonly origin?: SomaTraceOrigin | undefined;
|
|
144
|
+
readonly note?: string | undefined;
|
|
145
|
+
readonly caveat?: string | undefined;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 造一条 trace。
|
|
150
|
+
*
|
|
151
|
+
* **可选字段为 `undefined` 时整个键都不写进对象**,而不是留一个 `key: undefined`:
|
|
152
|
+
* 产物要按内容寻址(§19.3 幂等 + §22.2 缓存键),而 `JSON.stringify` 会丢掉
|
|
153
|
+
* `undefined` 值的键——同一份输入若一次带键一次不带,序列化出来的字节相同、
|
|
154
|
+
* 对象却不 `toEqual`,于是"幂等"这件事在断言里与在缓存里得出相反的结论。
|
|
155
|
+
*
|
|
156
|
+
* 本函数**不校验**(不抛):校验是闸门的活,见 `traceDefects`。
|
|
157
|
+
* 构造点当场抛的话,一条写歪的 trace 会把整次编译变成一次崩溃——
|
|
158
|
+
* 而 trace 是解释推导的,不该自己成为新的失败面。
|
|
159
|
+
*/
|
|
160
|
+
export function traceLink(input: SomaTraceInput): SomaTrace {
|
|
161
|
+
return {
|
|
162
|
+
layer: input.layer,
|
|
163
|
+
conclusion: input.conclusion,
|
|
164
|
+
rule: input.rule,
|
|
165
|
+
from: input.from,
|
|
166
|
+
...(input.parent !== undefined ? { parent: input.parent } : {}),
|
|
167
|
+
...(input.path !== undefined ? { path: input.path } : {}),
|
|
168
|
+
...(input.origin !== undefined ? { origin: input.origin } : {}),
|
|
169
|
+
...(input.note !== undefined ? { note: input.note } : {}),
|
|
170
|
+
...(input.caveat !== undefined ? { caveat: input.caveat } : {}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 造一条 trace 并追加进收集数组,返回它本身(好接着当下一条的 `parent`)。
|
|
176
|
+
*
|
|
177
|
+
* 各层的用法就是依赖闸门在 `CROSSCUT-DOWNWARD` 那条建议里写的那一句:
|
|
178
|
+
*
|
|
179
|
+
* import { pushTrace } from '../trace/trace.types';
|
|
180
|
+
* const head = pushTrace(traces, { layer: 'spatial', conclusion: …, rule: …, from: … });
|
|
181
|
+
*/
|
|
182
|
+
export function pushTrace(into: SomaTrace[], input: SomaTraceInput): SomaTrace {
|
|
183
|
+
const link = traceLink(input);
|
|
184
|
+
into.push(link);
|
|
185
|
+
return link;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 给一条已经造好的 trace 换上 parent(**返回新对象,不改原对象**)。
|
|
190
|
+
*
|
|
191
|
+
* 为什么需要它:跨层接线发生在编排层(`ooui/index.ts`),而各层自己产 trace 时
|
|
192
|
+
* 看不见上一层的实例。层内造链、编排层挂链,是唯一不违反依赖方向的分工。
|
|
193
|
+
* `parent` 为 `undefined` 时原样返回——不制造一个"内容相同但引用不同"的副本,
|
|
194
|
+
* 那会让按引用比较的断言无谓地失手。
|
|
195
|
+
*/
|
|
196
|
+
export function linkTrace(trace: SomaTrace, parent: SomaTrace | undefined): SomaTrace {
|
|
197
|
+
if (parent === undefined) return trace;
|
|
198
|
+
return { ...trace, parent };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 整条链,**根在前**(语义层在数组第 0 位)——报告与闸门都按这个方向读。
|
|
203
|
+
*
|
|
204
|
+
* 成环时在环处停下并**只返回已走过的部分**,不抛:一条坏链不该让诊断本身崩掉。
|
|
205
|
+
* 环这件事由 `traceDefects` 点名(它是闸门的判据),不由这里。
|
|
206
|
+
*/
|
|
207
|
+
export function traceChain(trace: SomaTrace): SomaTrace[] {
|
|
208
|
+
const chain: SomaTrace[] = [];
|
|
209
|
+
const seen = new Set<SomaTrace>();
|
|
210
|
+
let cursor: SomaTrace | undefined = trace;
|
|
211
|
+
while (cursor !== undefined && chain.length < TRACE_MAX_DEPTH && !seen.has(cursor)) {
|
|
212
|
+
seen.add(cursor);
|
|
213
|
+
chain.push(cursor);
|
|
214
|
+
cursor = cursor.parent;
|
|
215
|
+
}
|
|
216
|
+
return chain.reverse();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** 链条的根(最上游的那一条)。`traceChain(trace)[0]` 的快捷式 */
|
|
220
|
+
export function traceRoot(trace: SomaTrace): SomaTrace {
|
|
221
|
+
return traceChain(trace)[0];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** 链条里属于某一层的那些条(根在前) */
|
|
225
|
+
export function traceAtLayer(trace: SomaTrace, layer: SomaTraceLayer): SomaTrace[] {
|
|
226
|
+
return traceChain(trace).filter((link) => link.layer === layer);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** 一批 trace 里落在某个路径上的那些条。`path` 精确匹配,不做前缀猜测 */
|
|
230
|
+
export function tracesForPath(traces: readonly SomaTrace[], path: string): SomaTrace[] {
|
|
231
|
+
return traces.filter((trace) => trace.path === path);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** `traceDefects` 的判据开关 */
|
|
235
|
+
export interface SomaTraceDefectOptions {
|
|
236
|
+
/**
|
|
237
|
+
* 链条必须上溯到哪一层。缺省 `'semantic'`——架构 §5 的硬要求是
|
|
238
|
+
* "能从一个 CSS 规则**一路回溯到某句对象声明**",止于中途的链条不算数。
|
|
239
|
+
* 传 `null` 关掉这一条(只在单层单测里用)。
|
|
240
|
+
*/
|
|
241
|
+
readonly requireRoot?: SomaTraceLayer | null;
|
|
242
|
+
/** 这条 trace 是干什么的,进缺陷文案好定位。缺省用 `path` 或 `conclusion` */
|
|
243
|
+
readonly label?: string;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 一条 trace(连同它的整条链)的缺陷清单。**闸门的判据就是它**,
|
|
248
|
+
* 返回空数组表示这条链可解释。
|
|
249
|
+
*
|
|
250
|
+
* 为什么是"返回清单"而不是"抛异常":§8 那道闸门要一次列全所有不可解释的结论,
|
|
251
|
+
* 抛异常只能报第一条,而作者会因此以为改完这一条就好了,跑一轮再看见第二条。
|
|
252
|
+
* 三段式错误由调用方(闸门)按这份清单拼,本函数只出判据。
|
|
253
|
+
*/
|
|
254
|
+
export function traceDefects(
|
|
255
|
+
trace: SomaTrace | undefined,
|
|
256
|
+
options: SomaTraceDefectOptions = {},
|
|
257
|
+
): string[] {
|
|
258
|
+
const label = options.label ?? '(未命名)';
|
|
259
|
+
if (trace === undefined) return [`${label}:没有 trace`];
|
|
260
|
+
|
|
261
|
+
const defects: string[] = [];
|
|
262
|
+
const seen = new Set<SomaTrace>();
|
|
263
|
+
let cursor: SomaTrace | undefined = trace;
|
|
264
|
+
let depth = 0;
|
|
265
|
+
let last: SomaTrace = trace;
|
|
266
|
+
|
|
267
|
+
while (cursor !== undefined) {
|
|
268
|
+
if (seen.has(cursor)) {
|
|
269
|
+
defects.push(`${label}:trace 链成环,在「${brief(cursor.conclusion)}」处回到了已走过的一条`);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
if (depth >= TRACE_MAX_DEPTH) {
|
|
273
|
+
defects.push(`${label}:trace 链超过 ${TRACE_MAX_DEPTH} 层,按成环处理`);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
seen.add(cursor);
|
|
277
|
+
depth += 1;
|
|
278
|
+
last = cursor;
|
|
279
|
+
|
|
280
|
+
const at = `${label} 第 ${depth} 跳(${cursor.layer})`;
|
|
281
|
+
if (LAYER_ORDER[cursor.layer] === undefined) {
|
|
282
|
+
defects.push(`${at}:layer "${cursor.layer}" 不在五层闭集内(${SOMA_TRACE_LAYERS.join(' / ')})`);
|
|
283
|
+
}
|
|
284
|
+
if (cursor.conclusion.trim() === '') defects.push(`${at}:conclusion 为空——"得出了什么"没有答案`);
|
|
285
|
+
if (cursor.rule.trim() === '') defects.push(`${at}:rule 为空——"依据哪条规则"没有答案`);
|
|
286
|
+
if (typeof cursor.from?.file !== 'string' || cursor.from.file.trim() === '') {
|
|
287
|
+
defects.push(`${at}:from.file 为空——"依据哪句声明"指不回任何地方`);
|
|
288
|
+
}
|
|
289
|
+
if (typeof cursor.from?.path !== 'string' || cursor.from.path.trim() === '') {
|
|
290
|
+
defects.push(`${at}:from.path 为空——"依据哪句声明"指不回任何地方`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const parent: SomaTrace | undefined = cursor.parent;
|
|
294
|
+
if (parent !== undefined) {
|
|
295
|
+
const here = LAYER_ORDER[cursor.layer];
|
|
296
|
+
const up = LAYER_ORDER[parent.layer];
|
|
297
|
+
if (here !== undefined && up !== undefined && up > here) {
|
|
298
|
+
defects.push(
|
|
299
|
+
`${at}:parent 是下游层 ${parent.layer},链条倒流了`
|
|
300
|
+
+ `(管线是 ${SOMA_TRACE_LAYERS.join(' → ')},parent 只能是同层或上游)`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
cursor = parent;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const requireRoot = options.requireRoot === undefined ? 'semantic' : options.requireRoot;
|
|
308
|
+
if (requireRoot !== null && last.layer !== requireRoot) {
|
|
309
|
+
defects.push(
|
|
310
|
+
`${label}:链条止于 ${last.layer} 层的「${brief(last.conclusion)}」,没有上溯到 ${requireRoot} 层`
|
|
311
|
+
+ '——回溯不到对象声明的推导等于没有 trace(架构 §5)',
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
return defects;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* 一条 trace 的单行摘要:`[层] 结论 ← 规则 @ 声明处`。
|
|
319
|
+
*
|
|
320
|
+
* 给闸门失败输出与日志用。**给人读的因果叙述是 `renderTrace`**(§5.1 的报告形态),
|
|
321
|
+
* 两者是按消费方分的两个形态,不要把其中一个改成另一个的样子。
|
|
322
|
+
*/
|
|
323
|
+
export function formatTraceLine(trace: SomaTrace): string {
|
|
324
|
+
const rule = trace.rule === 'declared' ? '' : ` ← 规则「${trace.rule}」`;
|
|
325
|
+
return `[${trace.layer}] ${trace.conclusion}${rule} @ ${formatSomaSource(trace.from)}`;
|
|
326
|
+
}
|
|
@@ -115,6 +115,7 @@ function renderIndex(packName: string, packVar: string, componentName: string):
|
|
|
115
115
|
function renderComponents(componentName: string, kebab: string): string {
|
|
116
116
|
return [
|
|
117
117
|
"import type { SomaComponentDefinition } from 'soma-core';",
|
|
118
|
+
"import { somaEmits, somaFields, somaSlots } from 'soma-core';",
|
|
118
119
|
'',
|
|
119
120
|
'/**',
|
|
120
121
|
' * 示例业务组件。solution 层的四维设计判据(深度 / 组合 / 完备 / 可操作)见',
|
|
@@ -128,20 +129,24 @@ function renderComponents(componentName: string, kebab: string): string {
|
|
|
128
129
|
" version: '0.1.0',",
|
|
129
130
|
" geometry: 'surface',",
|
|
130
131
|
" description: '示例卡片:把一类业务场景整套打包,一个声明落一个完整业务功能',",
|
|
131
|
-
'
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
'
|
|
137
|
-
'
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
'
|
|
141
|
-
'
|
|
142
|
-
'
|
|
143
|
-
|
|
144
|
-
'
|
|
132
|
+
' // 字段行写法(REQ-012):一行一个字段,缩进即嵌套,示例值就在行尾。',
|
|
133
|
+
' // 示例值不是装饰——组件橱窗、视觉矩阵与 AI 拿到的样张都由它派生,',
|
|
134
|
+
' // 缺了它这个组件在橱窗里只有一个空壳(verifyComponentPack 会点名)。',
|
|
135
|
+
' props: somaFields`',
|
|
136
|
+
" title: string, 卡片标题, 默认 \"\", 示例 本周待跟进",
|
|
137
|
+
' items: array<object>, 条目列表, 默认 []',
|
|
138
|
+
' id: string, 条目编号, 必填, 示例 T-1001',
|
|
139
|
+
' label: string, 条目文案, 必填, 示例 杭州云汀科技 · 周四回访',
|
|
140
|
+
' status: enum(todo|doing|done), 条目状态, 默认 todo, 示例 doing',
|
|
141
|
+
' loading: boolean, 加载态, 默认 false',
|
|
142
|
+
' `,',
|
|
143
|
+
' emits: somaEmits`',
|
|
144
|
+
' action: 用户触发了卡片上的动作(业务处置归页面)',
|
|
145
|
+
' key: string, 动作标识',
|
|
146
|
+
' `,',
|
|
147
|
+
' slots: somaSlots`',
|
|
148
|
+
' footer: 底部动作区,宿主接手时用它',
|
|
149
|
+
' `,',
|
|
145
150
|
' // 组件级令牌(M-1):组件自己声明的可调旋钮。',
|
|
146
151
|
' // default 必须引用语义令牌——组件令牌是语义令牌的收窄,不是新的真源。',
|
|
147
152
|
' tokens: {',
|
|
@@ -15,6 +15,36 @@ export interface SomaHttpClientConfig {
|
|
|
15
15
|
defaultHeaders?: Record<string, string> | (() => Record<string, string>);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** 错误正文带进异常消息的长度上限:够看清服务端文案,又不至于把整页 HTML 错误页塞进日志 */
|
|
19
|
+
const ERROR_BODY_MAX_LENGTH = 500;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 从错误响应正文里提炼一句可读文案。
|
|
23
|
+
*
|
|
24
|
+
* 服务端精心写的结构化错误(`{ ok: false, error: "未知组件:X" }`)才是调用方要的信息,
|
|
25
|
+
* 只留 statusText 等于把它整条丢掉。正文也可能是 HTML 错误页或空串,
|
|
26
|
+
* 因此 JSON 解析必须容错——解析失败只是"没有结构化字段",不该把请求变成另一种崩法。
|
|
27
|
+
*/
|
|
28
|
+
export function describeHttpErrorBody(body: string, statusText: string): string {
|
|
29
|
+
const text = (body ?? '').trim();
|
|
30
|
+
if (text === '') return statusText;
|
|
31
|
+
|
|
32
|
+
let message = text;
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(text);
|
|
35
|
+
if (parsed && typeof parsed === 'object') {
|
|
36
|
+
const field = (parsed as Record<string, unknown>).error ?? (parsed as Record<string, unknown>).message;
|
|
37
|
+
if (typeof field === 'string' && field.trim() !== '') message = field.trim();
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// 非 JSON(HTML 错误页、纯文本)就用正文原文
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return message.length > ERROR_BODY_MAX_LENGTH
|
|
44
|
+
? `${message.slice(0, ERROR_BODY_MAX_LENGTH)}…`
|
|
45
|
+
: message;
|
|
46
|
+
}
|
|
47
|
+
|
|
18
48
|
/**
|
|
19
49
|
* SomaHttpClient — API 请求封装
|
|
20
50
|
*
|
|
@@ -116,7 +146,10 @@ export class SomaHttpClient {
|
|
|
116
146
|
const res = await fetch(url, options);
|
|
117
147
|
|
|
118
148
|
if (!res.ok) {
|
|
119
|
-
|
|
149
|
+
const errorBody = typeof res.text === 'function'
|
|
150
|
+
? await res.text().catch(() => '')
|
|
151
|
+
: '';
|
|
152
|
+
throw new Error(`HTTP ${res.status}: ${describeHttpErrorBody(errorBody, res.statusText)}`);
|
|
120
153
|
}
|
|
121
154
|
|
|
122
155
|
return (await res.json()) as T;
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
// 纪律(D10):目录永远从契约生成,禁止手工维护第二份副本。
|
|
8
8
|
|
|
9
9
|
import { deriveBlockExample } from './example-blocks';
|
|
10
|
+
import { renderFieldLines } from '../../shared/component/field-lines';
|
|
11
|
+
import { deriveContractSample, hasRenderableSample } from '../../shared/component/derive-sample';
|
|
10
12
|
import { renderKeyboardMatrixLine } from './keyboard-matrix';
|
|
11
13
|
import {
|
|
12
14
|
componentTokenVar,
|
|
@@ -62,6 +64,24 @@ export interface SomaAiCatalogEntry {
|
|
|
62
64
|
example: string;
|
|
63
65
|
antiPatterns?: string[];
|
|
64
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* 字段行原文(REQ-012):对象 / 数组 prop 的逐字段形状与示例。
|
|
69
|
+
*
|
|
70
|
+
* 只在契约真写了嵌套形状或示例时出现——否则它与上面的 props 表逐字重复。
|
|
71
|
+
* 目录直接打印它,不另生成第二张字段表:作者写的和读者读到的是同一份东西。
|
|
72
|
+
*/
|
|
73
|
+
spec?: string;
|
|
74
|
+
/** 派生样张(REQ-012):展示页与视觉矩阵喂给组件的那份 props */
|
|
75
|
+
sample?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 契约里是否写了值得单独打印的字段形状(嵌套或示例) */
|
|
79
|
+
function hasFieldSpec(contract: SomaComponentContract): boolean {
|
|
80
|
+
const seen = (field: SomaContractProp): boolean => {
|
|
81
|
+
if (field.fields !== undefined || field.items !== undefined || field.example !== undefined) return true;
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
return Object.values(contract.props ?? {}).some(seen);
|
|
65
85
|
}
|
|
66
86
|
|
|
67
87
|
/**
|
|
@@ -154,6 +174,11 @@ export function buildCatalogEntry(contract: SomaComponentContract): SomaAiCatalo
|
|
|
154
174
|
antiPatterns: contract.ai.anti_patterns,
|
|
155
175
|
}
|
|
156
176
|
: undefined,
|
|
177
|
+
// 两个可选段(REQ-012):缺席时连键都不写,目录 JSON 的形状对存量消费者逐键不变
|
|
178
|
+
...(hasFieldSpec(contract) ? { spec: renderFieldLines(contract.props ?? {}) } : {}),
|
|
179
|
+
...(hasRenderableSample(contract)
|
|
180
|
+
? { sample: deriveContractSample(contract).props }
|
|
181
|
+
: {}),
|
|
157
182
|
};
|
|
158
183
|
}
|
|
159
184
|
|
|
@@ -278,6 +303,23 @@ function renderMarkdown(entries: SomaAiCatalogEntry[], conventions?: string): st
|
|
|
278
303
|
}
|
|
279
304
|
}
|
|
280
305
|
|
|
306
|
+
// 字段形状与样张(REQ-012):对象 / 数组 prop 的内部长什么样、真实数据是什么。
|
|
307
|
+
// 上面的 props 表只说得清标量;`{ id, name, phone? }` 那种花括号提示机器读不出来。
|
|
308
|
+
if (entry.spec) {
|
|
309
|
+
lines.push('');
|
|
310
|
+
lines.push('字段形状(名: 类型, 描述, 必填 或 默认 x, 示例 y;缩进即嵌套):');
|
|
311
|
+
lines.push('```');
|
|
312
|
+
lines.push(entry.spec);
|
|
313
|
+
lines.push('```');
|
|
314
|
+
}
|
|
315
|
+
if (entry.sample) {
|
|
316
|
+
lines.push('');
|
|
317
|
+
lines.push('样张(由示例值派生,展示页与视觉矩阵喂的就是它):');
|
|
318
|
+
lines.push('```json');
|
|
319
|
+
lines.push(JSON.stringify(entry.sample, null, 2));
|
|
320
|
+
lines.push('```');
|
|
321
|
+
}
|
|
322
|
+
|
|
281
323
|
if (entry.emits.length) {
|
|
282
324
|
lines.push('');
|
|
283
325
|
lines.push('| emit | payload | 说明 |');
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
// 换不出来的(示例本身不是标准三行式)就不产块写法行——宁可少给一份示例,
|
|
18
18
|
// 也不要给一份**看着对、抄过去装载不进去**的示例。
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
const HTML_PREFIX = 'html:';
|
|
20
|
+
/** 平铺示例里参与换算的两行前缀(html 行两种写法通用,不换算) */
|
|
22
21
|
const UI_PREFIX = 'ui:';
|
|
23
22
|
const EVENT_PREFIX = 'event:';
|
|
24
23
|
|
|
@@ -125,8 +124,3 @@ export function deriveBlockExample(componentName: string, example: string): stri
|
|
|
125
124
|
}
|
|
126
125
|
return lines.join('\n');
|
|
127
126
|
}
|
|
128
|
-
|
|
129
|
-
/** 示例里的 html 行(两种写法通用),供块写法段复用而不重复贴一遍 */
|
|
130
|
-
export function exampleHtmlLine(example: string): string | null {
|
|
131
|
-
return lineAfter(example.split('\n'), HTML_PREFIX);
|
|
132
|
-
}
|
|
@@ -10,16 +10,15 @@
|
|
|
10
10
|
import type { SomaComponentDefinition } from './component-definition.types';
|
|
11
11
|
import { COMPONENT_TOKEN_KEY_PATTERN } from '../../shared/types/component-contract.types';
|
|
12
12
|
|
|
13
|
-
export class SomaThemeComponentTokenError extends Error {
|
|
14
|
-
constructor(message: string) {
|
|
15
|
-
super(`[SomaThemeComponentTokens] ${message}`);
|
|
16
|
-
this.name = 'SomaThemeComponentTokenError';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
13
|
/**
|
|
21
|
-
* 校验主题输入的 `components` / `darkComponents`
|
|
14
|
+
* 校验主题输入的 `components` / `darkComponents` 段是否与契约对得上。返回问题清单(空 = 对得上)。
|
|
22
15
|
* Host 在调 `applyTheme` 之前调用;不给组件表时(纯预览场景)跳过。
|
|
16
|
+
*
|
|
17
|
+
* 返回清单而不是抛(与同文件 `validateContractTokens` 同一形态):主题是 app 级的一份声明,
|
|
18
|
+
* 被该 Host 的全部页面共享,而组件表是「这个 Host + 这一页」的——共享主题里写了 `SomeCard`
|
|
19
|
+
* 的令牌、某一页没注册 `SomeCard` 是正常的。曾经这里抛,被主题注入的兜底接住,
|
|
20
|
+
* 结果是**整份品牌主题一起丢掉**(全页回落默认令牌),代价与「一个组件令牌没人读」完全不成比例。
|
|
21
|
+
* 对不上的令牌写进 :root 也只是没人读,所以调用方的正确处置是「照常换装 + 点名告警」。
|
|
23
22
|
*/
|
|
24
23
|
export function validateThemeComponentTokens(
|
|
25
24
|
input: {
|
|
@@ -27,12 +26,14 @@ export function validateThemeComponentTokens(
|
|
|
27
26
|
darkComponents?: Record<string, Record<string, string>>;
|
|
28
27
|
},
|
|
29
28
|
components: Record<string, SomaComponentDefinition>,
|
|
30
|
-
):
|
|
29
|
+
): string[] {
|
|
31
30
|
const issues: string[] = [];
|
|
32
31
|
for (const segment of [input.components, input.darkComponents]) {
|
|
33
32
|
if (!segment) continue;
|
|
34
33
|
for (const [componentName, tokens] of Object.entries(segment)) {
|
|
35
|
-
|
|
34
|
+
// hasOwn:`components: { toString: … }` 不能从原型上「找到」一个组件——
|
|
35
|
+
// 挂载期对账跑在主题注入的兜底之外,这里抛出去会让整页挂载失败
|
|
36
|
+
const definition = Object.hasOwn(components, componentName) ? components[componentName] : undefined;
|
|
36
37
|
if (!definition) {
|
|
37
38
|
issues.push(`未知组件 "${componentName}"`);
|
|
38
39
|
continue;
|
|
@@ -52,11 +53,7 @@ export function validateThemeComponentTokens(
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
throw new SomaThemeComponentTokenError(
|
|
57
|
-
`主题的组件令牌段有 ${issues.length} 处问题:\n${issues.map((i) => ` · ${i}`).join('\n')}`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
56
|
+
return issues;
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
/** 契约自检:令牌键名格式 + default 必须引用语义令牌。返回问题清单 */
|