soma-core 1.3.5 → 1.4.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/README.md +20 -7
- package/app/SomaPageClient.tsx +4 -4
- package/app/components/SomaHostPage.tsx +5 -5
- package/app/components/SomaHydrationShell.tsx +4 -7
- package/app/globals.css +126 -3
- package/core/build/{v2 → blocks}/block-compile.ts +47 -18
- package/core/build/{v2/soma-file-loader.ts → blocks/block-container.ts} +28 -37
- package/core/build/{v2 → blocks}/block-loader.ts +1 -1
- package/core/build/{v2 → blocks}/html-index.ts +1 -1
- package/core/build/{v2/migrate-v1.ts → blocks/migrate-flat.ts} +27 -27
- package/core/build/compiler/host-config-sync.cjs +2 -9
- package/core/build/compiler/page-declaration-compiler.ts +32 -4
- package/core/build/compiler/soma-manifest-webpack-plugin.js +1 -1
- package/core/build/compiler/soma-precompile.js +2057 -35
- package/core/build/compiler/soma-precompile.ts +2 -2
- package/core/build/component/component-graph.ts +208 -0
- package/core/build/eject/component-eject.ts +473 -0
- package/core/build/eject/component-upgrade.ts +359 -0
- package/core/build/layout/constraint-solver.ts +235 -0
- package/core/build/layout/css-emitter.ts +116 -0
- package/core/build/layout/page-layout.ts +85 -0
- package/core/build/pack/pack-init.ts +265 -0
- package/core/client/base/SomaPageRootBase.ts +61 -0
- package/core/client/component/ai-catalog.ts +83 -8
- package/core/client/component/component-defaults.ts +100 -0
- package/core/client/component/component-definition.types.ts +39 -0
- package/core/client/component/component-manager.ts +79 -4
- package/core/client/component/component-pack.ts +126 -2
- package/core/client/component/contract-compat.ts +32 -3
- package/core/client/component/{example-v2.ts → example-blocks.ts} +19 -19
- package/core/client/component/keyboard-matrix.ts +144 -0
- package/core/client/component/pack-styles.ts +59 -1
- package/core/client/component/style-features.ts +131 -0
- package/core/client/component/theme-component-tokens.ts +83 -0
- package/core/client/data/data-object-resolver.ts +407 -4
- package/core/client/data/reaction-engine.ts +176 -0
- package/core/client/data/window-engine.ts +477 -0
- package/core/client/engine/event-engine.ts +98 -0
- package/core/client/engine/soma-bootstrap.ts +286 -7
- package/core/client/engine/step-runner.ts +134 -0
- package/core/client/engine/style-binder.ts +1 -1
- package/core/client/infra/notify/DomNotifyService.ts +2 -1
- package/core/client/infra/notify/INotifyTheme.ts +1 -1
- package/core/client/parser/{v2 → blocks}/namespace.ts +1 -1
- package/core/client/parser/{v2 → blocks}/page-parser.ts +30 -16
- package/core/client/parser/{v2 → blocks}/use-parser.ts +24 -25
- package/core/client/parser/data-config-parser.ts +316 -8
- package/core/client/parser/duration.ts +16 -0
- package/core/client/parser/layout-parser.ts +157 -0
- package/core/client/parser/page-state-parser.ts +166 -0
- package/core/client/parser/pipeline-parser.ts +76 -1
- package/core/client/parser/reaction-parser.ts +459 -0
- package/core/client/parser/reaction-sugar.ts +47 -0
- package/core/client/parser/step-parser.ts +359 -0
- package/core/client/parser/style-config-parser.ts +7 -7
- package/core/client/parser/ui-config-parser.ts +59 -0
- package/core/client/parser/value-lang.ts +1 -1
- package/core/client/parser/window-parser.ts +294 -0
- package/core/client/registry/index.ts +8 -0
- package/core/client/theme/theme-engine.ts +144 -16
- package/core/client/typography/typography-base.ts +1 -1
- package/core/index.ts +188 -13
- package/core/server/host/csp-nonce-metadata.ts +1 -1
- package/core/server/host/published-page-assets.ts +3 -8
- package/core/server/host/soma-page-compile.ts +1 -1
- package/core/server/index.ts +2 -2
- package/core/shared/block-errors.ts +11 -0
- package/core/shared/calc/coerce.ts +29 -0
- package/core/shared/calc/errors.ts +43 -0
- package/core/shared/calc/evaluator.ts +101 -0
- package/core/shared/calc/index.ts +12 -0
- package/core/shared/calc/lexer.ts +194 -0
- package/core/shared/calc/parser.ts +204 -0
- package/core/shared/calc/typer.ts +184 -0
- package/core/shared/path-algebra.ts +169 -0
- package/core/shared/predicates/index.ts +527 -0
- package/core/shared/published-page-route.ts +61 -0
- package/core/shared/types/adaptive.types.ts +1 -1
- package/core/shared/types/component-contract.types.ts +128 -2
- package/core/shared/types/data-config.types.ts +149 -2
- package/core/shared/types/domain.types.ts +13 -0
- package/core/shared/types/event.types.ts +22 -2
- package/core/shared/types/layout-constraint.types.ts +73 -0
- package/core/shared/types/page-state.types.ts +60 -0
- package/core/shared/types/reaction.types.ts +144 -0
- package/core/shared/types/scope-manifest.types.ts +11 -15
- package/core/shared/types/step.types.ts +91 -0
- package/core/shared/types/style-config.types.ts +4 -4
- package/core/shared/types/ui-config.types.ts +18 -0
- package/core/shared/types/window.types.ts +177 -0
- package/dist/cli/soma.js +28 -3
- package/dist/core/index.cjs +4829 -405
- package/dist/types/build/{v2 → blocks}/block-compile.d.ts +7 -7
- package/dist/types/build/{v2/soma-file-loader.d.ts → blocks/block-container.d.ts} +6 -11
- package/dist/types/build/{v2/migrate-v1.d.ts → blocks/migrate-flat.d.ts} +6 -6
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
- package/dist/types/build/component/component-graph.d.ts +85 -0
- package/dist/types/build/eject/component-eject.d.ts +121 -0
- package/dist/types/build/eject/component-upgrade.d.ts +43 -0
- package/dist/types/build/layout/constraint-solver.d.ts +36 -0
- package/dist/types/build/layout/css-emitter.d.ts +18 -0
- package/dist/types/build/layout/page-layout.d.ts +24 -0
- package/dist/types/build/pack/pack-init.d.ts +8 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
- package/dist/types/client/component/ai-catalog.d.ts +24 -1
- package/dist/types/client/component/component-defaults.d.ts +15 -0
- package/dist/types/client/component/component-definition.types.d.ts +38 -0
- package/dist/types/client/component/component-manager.d.ts +36 -0
- package/dist/types/client/component/component-pack.d.ts +32 -2
- package/dist/types/client/component/contract-compat.d.ts +2 -2
- package/dist/types/client/component/example-blocks.d.ts +9 -0
- package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
- package/dist/types/client/component/pack-styles.d.ts +21 -0
- package/dist/types/client/component/style-features.d.ts +26 -0
- package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
- package/dist/types/client/data/data-object-resolver.d.ts +106 -1
- package/dist/types/client/data/reaction-engine.d.ts +21 -0
- package/dist/types/client/data/window-engine.d.ts +27 -0
- package/dist/types/client/engine/event-engine.d.ts +15 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
- package/dist/types/client/engine/step-runner.d.ts +24 -0
- package/dist/types/client/infra/notify/DomNotifyService.d.ts +2 -1
- package/dist/types/client/infra/notify/INotifyTheme.d.ts +1 -1
- package/dist/types/client/parser/{v2 → blocks}/page-parser.d.ts +2 -2
- package/dist/types/client/parser/{v2 → blocks}/use-parser.d.ts +3 -3
- package/dist/types/client/parser/duration.d.ts +1 -0
- package/dist/types/client/parser/layout-parser.d.ts +9 -0
- package/dist/types/client/parser/page-state-parser.d.ts +32 -0
- package/dist/types/client/parser/reaction-parser.d.ts +16 -0
- package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
- package/dist/types/client/parser/step-parser.d.ts +23 -0
- package/dist/types/client/parser/style-config-parser.d.ts +1 -1
- package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
- package/dist/types/client/parser/window-parser.d.ts +25 -0
- package/dist/types/client/registry/index.d.ts +1 -0
- package/dist/types/client/theme/theme-engine.d.ts +37 -0
- package/dist/types/index.d.ts +40 -9
- package/dist/types/server/host/published-page-assets.d.ts +3 -2
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/shared/block-errors.d.ts +5 -0
- package/dist/types/shared/calc/coerce.d.ts +4 -0
- package/dist/types/shared/calc/errors.d.ts +14 -0
- package/dist/types/shared/calc/evaluator.d.ts +2 -0
- package/dist/types/shared/calc/index.d.ts +6 -0
- package/dist/types/shared/calc/lexer.d.ts +20 -0
- package/dist/types/shared/calc/parser.d.ts +49 -0
- package/dist/types/shared/calc/typer.d.ts +16 -0
- package/dist/types/shared/path-algebra.d.ts +56 -0
- package/dist/types/shared/predicates/index.d.ts +79 -0
- package/dist/types/shared/published-page-route.d.ts +21 -0
- package/dist/types/shared/types/component-contract.types.d.ts +112 -0
- package/dist/types/shared/types/data-config.types.d.ts +132 -2
- package/dist/types/shared/types/domain.types.d.ts +12 -0
- package/dist/types/shared/types/event.types.d.ts +8 -2
- package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
- package/dist/types/shared/types/page-state.types.d.ts +49 -0
- package/dist/types/shared/types/reaction.types.d.ts +115 -0
- package/dist/types/shared/types/scope-manifest.types.d.ts +11 -11
- package/dist/types/shared/types/step.types.d.ts +76 -0
- package/dist/types/shared/types/style-config.types.d.ts +4 -4
- package/dist/types/shared/types/ui-config.types.d.ts +18 -0
- package/dist/types/shared/types/window.types.d.ts +171 -0
- package/package.json +2 -6
- package/dist/types/client/component/example-v2.d.ts +0 -9
- package/postcss.config.js +0 -6
- package/tailwind.config.ts +0 -43
- /package/dist/types/build/{v2 → blocks}/block-loader.d.ts +0 -0
- /package/dist/types/build/{v2 → blocks}/html-index.d.ts +0 -0
- /package/dist/types/client/parser/{v2 → blocks}/namespace.d.ts +0 -0
|
@@ -7,7 +7,7 @@ import { parseEventConfig } from '../../client/parser/pipeline-parser';
|
|
|
7
7
|
import { splitEventConfigRaw } from '../../client/parser/trigger-parser';
|
|
8
8
|
import { parseStyleConfig } from '../../client/parser/style-config-parser';
|
|
9
9
|
import { parseDataConfig } from '../../client/parser/data-config-parser';
|
|
10
|
-
import {
|
|
10
|
+
import { parseSomaBlockContainer } from '../blocks/block-container';
|
|
11
11
|
import type { SomaDataConfig } from '../../shared/types/data-config.types';
|
|
12
12
|
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
13
13
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
@@ -50,7 +50,7 @@ export function precompileUiYaml(yamlStr: string): string {
|
|
|
50
50
|
* 旧页面形状、未闭合开关或坏 YAML 被伪装成“没有预编译产物”。
|
|
51
51
|
*/
|
|
52
52
|
export function precompileUiModule(yamlStr: string): string {
|
|
53
|
-
|
|
53
|
+
parseSomaBlockContainer(yamlStr);
|
|
54
54
|
return 'null';
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// 组件依赖图与可寻址目录(REQ-010 F-46)。
|
|
2
|
+
//
|
|
3
|
+
// ── 两个具体的坏结果 ──────────────────────────────────────────────────
|
|
4
|
+
// ① **少拉一个依赖**。TreeSelect 的面板模板用了 Tree 分片里的类,但这条依赖
|
|
5
|
+
// 只登记在 soma-ui 的一张手工表里、且曾经漏登记过——只用 TreeSelect 不用 Tree 的
|
|
6
|
+
// 页面上,展开箭头与节点文字是无样式的。它不报错,只是长得不对。
|
|
7
|
+
// ② **说不出这份副本从哪来**。shadcn 的 registry 里没有版本、没有哈希、没有依赖,
|
|
8
|
+
// 所以"我这份 Select 是从哪一版复制的、它还需要谁"这两个问题都答不出来。
|
|
9
|
+
//
|
|
10
|
+
// 把依赖写进契约(`uses`),这两件事都有了答案:拉组件时按图拉齐,
|
|
11
|
+
// 发目录时每一项带版本、哈希与依赖。
|
|
12
|
+
|
|
13
|
+
import type { SomaComponentDefinition } from '../../client/component/component-definition.types';
|
|
14
|
+
|
|
15
|
+
export interface ComponentGraphNode {
|
|
16
|
+
name: string;
|
|
17
|
+
layer: string;
|
|
18
|
+
version: string;
|
|
19
|
+
/** 直接依赖(契约 `uses`) */
|
|
20
|
+
uses: string[];
|
|
21
|
+
/** 传递闭包(不含自身) */
|
|
22
|
+
closure: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ComponentGraph {
|
|
26
|
+
nodes: Record<string, ComponentGraphNode>;
|
|
27
|
+
/** 声明了却不存在的依赖:`组件名 → 缺失的依赖名[]` */
|
|
28
|
+
missing: Record<string, string[]>;
|
|
29
|
+
/** 依赖环:每条是一个完整回路 */
|
|
30
|
+
cycles: string[][];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 建图。
|
|
35
|
+
*
|
|
36
|
+
* 缺失依赖与环**不抛**,而是收进产物:这个函数同时服务于闸门与 CLI,
|
|
37
|
+
* 闸门要拿到全部问题一次报完(抛的话作者修一条跑一次,修十条跑十次),
|
|
38
|
+
* CLI 则要在有问题时也能给出一份"能拉的先拉上"的清单。判定归调用方。
|
|
39
|
+
*/
|
|
40
|
+
export function buildComponentGraph(
|
|
41
|
+
definitions: Record<string, SomaComponentDefinition>,
|
|
42
|
+
): ComponentGraph {
|
|
43
|
+
const names = Object.keys(definitions);
|
|
44
|
+
const known = new Set(names);
|
|
45
|
+
const nodes: Record<string, ComponentGraphNode> = {};
|
|
46
|
+
const missing: Record<string, string[]> = {};
|
|
47
|
+
|
|
48
|
+
for (const name of names) {
|
|
49
|
+
const contract = definitions[name].contract;
|
|
50
|
+
const uses = [...new Set(contract.uses ?? [])];
|
|
51
|
+
const absent = uses.filter((dep) => !known.has(dep));
|
|
52
|
+
if (absent.length > 0) missing[name] = absent;
|
|
53
|
+
nodes[name] = {
|
|
54
|
+
name,
|
|
55
|
+
layer: String(contract.layer),
|
|
56
|
+
version: String(contract.version),
|
|
57
|
+
uses: uses.filter((dep) => known.has(dep)),
|
|
58
|
+
closure: [],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 传递闭包 + 检环。深度优先,回边即环——报出整条回路而不只是"成环了":
|
|
63
|
+
// 只说成环的话,作者得自己把链条走一遍才知道该断哪一条。
|
|
64
|
+
const cycles: string[][] = [];
|
|
65
|
+
const state: Record<string, 'visiting' | 'done'> = {};
|
|
66
|
+
const stack: string[] = [];
|
|
67
|
+
|
|
68
|
+
const visit = (name: string): Set<string> => {
|
|
69
|
+
if (state[name] === 'done') return new Set(nodes[name].closure);
|
|
70
|
+
if (state[name] === 'visiting') {
|
|
71
|
+
const from = stack.indexOf(name);
|
|
72
|
+
if (from !== -1) cycles.push([...stack.slice(from), name]);
|
|
73
|
+
return new Set();
|
|
74
|
+
}
|
|
75
|
+
state[name] = 'visiting';
|
|
76
|
+
stack.push(name);
|
|
77
|
+
const out = new Set<string>();
|
|
78
|
+
for (const dep of nodes[name].uses) {
|
|
79
|
+
out.add(dep);
|
|
80
|
+
for (const deeper of visit(dep)) out.add(deeper);
|
|
81
|
+
}
|
|
82
|
+
stack.pop();
|
|
83
|
+
state[name] = 'done';
|
|
84
|
+
// 自己不进自己的闭包:成环时上面会把自己加进来,这里摘掉
|
|
85
|
+
out.delete(name);
|
|
86
|
+
nodes[name].closure = [...out].sort();
|
|
87
|
+
return out;
|
|
88
|
+
};
|
|
89
|
+
for (const name of names) visit(name);
|
|
90
|
+
|
|
91
|
+
return { nodes, missing, cycles };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 按图拉齐:给一组组件名,返回它们加上全部传递依赖的名单(拓扑序)。
|
|
96
|
+
*
|
|
97
|
+
* 拓扑序而不是字母序:注册组件时被依赖的要先在册,否则合成期查注册表会落空。
|
|
98
|
+
*/
|
|
99
|
+
export function resolveWithDependencies(
|
|
100
|
+
graph: ComponentGraph,
|
|
101
|
+
wanted: readonly string[],
|
|
102
|
+
): string[] {
|
|
103
|
+
const out: string[] = [];
|
|
104
|
+
const seen = new Set<string>();
|
|
105
|
+
const visit = (name: string): void => {
|
|
106
|
+
if (seen.has(name)) return;
|
|
107
|
+
seen.add(name);
|
|
108
|
+
const node = graph.nodes[name];
|
|
109
|
+
if (!node) return; // 未知名字由调用方另行报错,这里不吞也不猜
|
|
110
|
+
for (const dep of node.uses) visit(dep);
|
|
111
|
+
out.push(name);
|
|
112
|
+
};
|
|
113
|
+
for (const name of wanted) visit(name);
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** `registry.json` 的一项 */
|
|
118
|
+
export interface ComponentRegistryEntry {
|
|
119
|
+
name: string;
|
|
120
|
+
layer: string;
|
|
121
|
+
/** 契约版本(破坏性变更升 major) */
|
|
122
|
+
version: string;
|
|
123
|
+
/** 源码内容哈希:回答"我这份是不是官方那一份" */
|
|
124
|
+
sha256: string;
|
|
125
|
+
/** 直接依赖 */
|
|
126
|
+
uses: string[];
|
|
127
|
+
/** 传递依赖(拉齐时按它一次拉全) */
|
|
128
|
+
requires: string[];
|
|
129
|
+
/** 源文件相对路径(eject / upgrade 的取源位置) */
|
|
130
|
+
source: string;
|
|
131
|
+
description: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface ComponentRegistryManifest {
|
|
135
|
+
/** 目录格式版本:读的人据此判断自己认不认得这份文件 */
|
|
136
|
+
schema: 1;
|
|
137
|
+
/** 产出这份目录的包与版本 */
|
|
138
|
+
pack: { name: string; version: string };
|
|
139
|
+
generatedFrom: string;
|
|
140
|
+
components: ComponentRegistryEntry[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 产出可寻址目录。
|
|
145
|
+
*
|
|
146
|
+
* 与 shadcn registry 的差别就是这三列:`version` / `sha256` / `requires`。
|
|
147
|
+
* 少了它们,一份被复制出去的组件就永久脱离了升级链路——
|
|
148
|
+
* 而"脱离了"这件事本身也是看不出来的。
|
|
149
|
+
*/
|
|
150
|
+
export function buildRegistryManifest(
|
|
151
|
+
definitions: Record<string, SomaComponentDefinition>,
|
|
152
|
+
options: {
|
|
153
|
+
packName: string;
|
|
154
|
+
packVersion: string;
|
|
155
|
+
/** 组件名 → 源码相对路径 */
|
|
156
|
+
sourceOf(name: string): string;
|
|
157
|
+
/** 组件名 → 源码内容哈希 */
|
|
158
|
+
hashOf(name: string): string;
|
|
159
|
+
},
|
|
160
|
+
): ComponentRegistryManifest {
|
|
161
|
+
const graph = buildComponentGraph(definitions);
|
|
162
|
+
const components = Object.keys(definitions)
|
|
163
|
+
.sort()
|
|
164
|
+
.map((name) => {
|
|
165
|
+
const contract = definitions[name].contract;
|
|
166
|
+
return {
|
|
167
|
+
name,
|
|
168
|
+
layer: String(contract.layer),
|
|
169
|
+
version: String(contract.version),
|
|
170
|
+
sha256: options.hashOf(name),
|
|
171
|
+
uses: graph.nodes[name].uses,
|
|
172
|
+
requires: graph.nodes[name].closure,
|
|
173
|
+
source: options.sourceOf(name),
|
|
174
|
+
description: String(contract.description ?? ''),
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
return {
|
|
178
|
+
schema: 1,
|
|
179
|
+
pack: { name: options.packName, version: options.packVersion },
|
|
180
|
+
generatedFrom: `${options.packName}@${options.packVersion}`,
|
|
181
|
+
components,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 契约 `uses` 与 CSS 依赖表的对账。
|
|
187
|
+
*
|
|
188
|
+
* 两张表都在描述"这个组件还需要谁",所以它们必须一致。不对账的话,
|
|
189
|
+
* 一条只写在 CSS 表里的依赖会让 eject 少拉一个文件,而一条只写在契约里的依赖
|
|
190
|
+
* 会让页面少注一段样式——两种坏法都不报错,都只是长得不对。
|
|
191
|
+
*/
|
|
192
|
+
export function reconcileCssDeps(
|
|
193
|
+
graph: ComponentGraph,
|
|
194
|
+
cssDeps: Record<string, readonly string[]>,
|
|
195
|
+
): Array<{ component: string; onlyInCss: string[]; onlyInContract: string[] }> {
|
|
196
|
+
const issues: Array<{ component: string; onlyInCss: string[]; onlyInContract: string[] }> = [];
|
|
197
|
+
const names = new Set([...Object.keys(graph.nodes), ...Object.keys(cssDeps)]);
|
|
198
|
+
for (const name of names) {
|
|
199
|
+
const fromContract = new Set(graph.nodes[name]?.uses ?? []);
|
|
200
|
+
const fromCss = new Set(cssDeps[name] ?? []);
|
|
201
|
+
const onlyInCss = [...fromCss].filter((dep) => !fromContract.has(dep) && graph.nodes[dep] !== undefined);
|
|
202
|
+
const onlyInContract = [...fromContract].filter((dep) => !fromCss.has(dep));
|
|
203
|
+
if (onlyInCss.length > 0 || onlyInContract.length > 0) {
|
|
204
|
+
issues.push({ component: name, onlyInCss, onlyInContract });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return issues;
|
|
208
|
+
}
|