soma-core 1.3.5 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -7
- package/app/SomaPageClient.tsx +4 -4
- package/app/components/SomaHostPage.tsx +5 -5
- package/app/components/SomaHydrationShell.tsx +4 -7
- package/app/globals.css +126 -3
- package/core/build/{v2 → blocks}/block-compile.ts +17 -17
- package/core/build/{v2/soma-file-loader.ts → blocks/block-container.ts} +28 -28
- package/core/build/{v2 → blocks}/block-loader.ts +1 -1
- package/core/build/{v2 → blocks}/html-index.ts +1 -1
- package/core/build/{v2/migrate-v1.ts → blocks/migrate-flat.ts} +27 -27
- package/core/build/compiler/host-config-sync.cjs +2 -9
- package/core/build/compiler/page-declaration-compiler.ts +2 -2
- package/core/build/compiler/soma-manifest-webpack-plugin.js +1 -1
- package/core/build/compiler/soma-precompile.js +17 -17
- package/core/build/compiler/soma-precompile.ts +2 -2
- package/core/client/component/ai-catalog.ts +4 -4
- package/core/client/component/contract-compat.ts +32 -3
- package/core/client/component/{example-v2.ts → example-blocks.ts} +19 -19
- package/core/client/engine/soma-bootstrap.ts +21 -2
- package/core/client/engine/style-binder.ts +1 -1
- package/core/client/infra/notify/DomNotifyService.ts +2 -1
- package/core/client/infra/notify/INotifyTheme.ts +1 -1
- package/core/client/parser/{v2 → blocks}/namespace.ts +1 -1
- package/core/client/parser/{v2 → blocks}/page-parser.ts +16 -16
- package/core/client/parser/{v2 → blocks}/use-parser.ts +20 -14
- package/core/client/parser/style-config-parser.ts +7 -7
- package/core/client/parser/value-lang.ts +1 -1
- package/core/client/registry/index.ts +8 -0
- package/core/client/theme/theme-engine.ts +42 -14
- package/core/client/typography/typography-base.ts +1 -1
- package/core/index.ts +25 -13
- package/core/server/host/csp-nonce-metadata.ts +1 -1
- package/core/server/host/published-page-assets.ts +3 -8
- package/core/server/host/soma-page-compile.ts +1 -1
- package/core/server/index.ts +2 -2
- package/core/shared/published-page-route.ts +61 -0
- package/core/shared/types/adaptive.types.ts +1 -1
- package/core/shared/types/data-config.types.ts +30 -2
- package/core/shared/types/scope-manifest.types.ts +11 -15
- package/core/shared/types/style-config.types.ts +4 -4
- package/dist/cli/soma.js +15 -2
- package/dist/core/index.cjs +165 -76
- package/dist/types/build/{v2 → blocks}/block-compile.d.ts +7 -7
- package/dist/types/build/{v2/soma-file-loader.d.ts → blocks/block-container.d.ts} +6 -6
- package/dist/types/build/{v2/migrate-v1.d.ts → blocks/migrate-flat.d.ts} +6 -6
- package/dist/types/client/component/contract-compat.d.ts +2 -2
- package/dist/types/client/component/example-blocks.d.ts +9 -0
- package/dist/types/client/infra/notify/DomNotifyService.d.ts +2 -1
- package/dist/types/client/infra/notify/INotifyTheme.d.ts +1 -1
- package/dist/types/client/parser/{v2 → blocks}/page-parser.d.ts +2 -2
- package/dist/types/client/parser/{v2 → blocks}/use-parser.d.ts +1 -1
- package/dist/types/client/parser/style-config-parser.d.ts +1 -1
- package/dist/types/client/registry/index.d.ts +1 -0
- package/dist/types/client/theme/theme-engine.d.ts +11 -0
- package/dist/types/index.d.ts +8 -7
- package/dist/types/server/host/published-page-assets.d.ts +3 -2
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/shared/published-page-route.d.ts +21 -0
- package/dist/types/shared/types/data-config.types.d.ts +18 -2
- package/dist/types/shared/types/scope-manifest.types.d.ts +11 -11
- package/dist/types/shared/types/style-config.types.d.ts +4 -4
- package/package.json +1 -6
- package/dist/types/client/component/example-v2.d.ts +0 -9
- package/postcss.config.js +0 -6
- package/tailwind.config.ts +0 -43
- /package/dist/types/build/{v2 → blocks}/block-loader.d.ts +0 -0
- /package/dist/types/build/{v2 → blocks}/html-index.d.ts +0 -0
- /package/dist/types/client/parser/{v2 → blocks}/namespace.d.ts +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 块解析 · page 块(REQ-005 F2)。
|
|
2
2
|
//
|
|
3
|
-
// **产出目标是
|
|
4
|
-
//
|
|
3
|
+
// **产出目标是 平铺等价的 UiConfig**——这是两级编译架构的关键:
|
|
4
|
+
// 块声明只是更好写的书写层,编译后交给既有引擎,运行时零新增、零感知。
|
|
5
5
|
//
|
|
6
6
|
// 两处形状转换:
|
|
7
7
|
// 平铺 → 嵌套:`锚点.when` / `锚点.class` 后缀键合并成一个 ExtendedShowValue;
|
|
8
|
-
// each → bind:`each: 路径 as 变量 [by 路径]` 还原成
|
|
8
|
+
// each → bind:`each: 路径 as 变量 [by 路径]` 还原成 平铺的 NestedShowMapping。
|
|
9
9
|
//
|
|
10
10
|
// 唯一的缩进理由是列表作用域——when 组与插槽内容一律平铺,
|
|
11
11
|
// 因为编译器手里有 HTML,结构不需要 YAML 再复述一遍。
|
|
@@ -18,17 +18,17 @@ import type {
|
|
|
18
18
|
UiConfig,
|
|
19
19
|
} from '../../../shared/types/ui-config.types';
|
|
20
20
|
import type { OnChangeRule } from '../../../shared/types/watcher.types';
|
|
21
|
-
import {
|
|
21
|
+
import { SomaBlockParseError } from '../../../build/blocks/block-container';
|
|
22
22
|
import { buildBlockScope, expandPath, type BlockScope } from './namespace';
|
|
23
23
|
|
|
24
24
|
const PAGE_KEYS = new Set([
|
|
25
25
|
'domain', 'locale', 'ui', 'watch', 'event', 'data', 'adaptive', 'alias',
|
|
26
|
-
// initProps
|
|
26
|
+
// initProps:引擎启动前写入的初始值(平铺 UiConfig 同名字段的直通)。
|
|
27
27
|
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
28
|
+
// 块声明是照**手写页面**设计的——那里文案住 HTML、初值住 Domain,声明里不需要它。
|
|
29
|
+
// 但块声明产的是平铺等价物,而生成链的页面把字面文案内联在 initProps 里
|
|
30
30
|
// (模型出的是组织意图,没有 Domain 可写)。少了这个键,AI 产的页面
|
|
31
|
-
//
|
|
31
|
+
// 就永远迈不过块声明的门槛——不是"用不上块声明",是"表达不了"。
|
|
32
32
|
'initProps',
|
|
33
33
|
]);
|
|
34
34
|
/** 后缀键:平铺书写的高级绑定 */
|
|
@@ -36,9 +36,9 @@ const SUFFIXES = ['when', 'model', 'class'] as const;
|
|
|
36
36
|
type Suffix = (typeof SUFFIXES)[number];
|
|
37
37
|
|
|
38
38
|
export interface PageBlockAst {
|
|
39
|
-
/**
|
|
39
|
+
/** 平铺等价 UiConfig:直接交既有编译管线 */
|
|
40
40
|
ui: UiConfig;
|
|
41
|
-
/** 事件段原文(交 pipeline-parser
|
|
41
|
+
/** 事件段原文(交 pipeline-parser,形状与平铺 _event.yaml 一致) */
|
|
42
42
|
eventRaw: Record<string, unknown>;
|
|
43
43
|
/** 数据段原文(页面级共享对象,交数据对象层) */
|
|
44
44
|
dataRaw?: Record<string, unknown>;
|
|
@@ -58,7 +58,7 @@ export interface ParsePageInput {
|
|
|
58
58
|
export function parsePageBlock(input: ParsePageInput): PageBlockAst {
|
|
59
59
|
const { body } = input;
|
|
60
60
|
const fail = (message: string): never => {
|
|
61
|
-
throw new
|
|
61
|
+
throw new SomaBlockParseError(message, 'page');
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
for (const key of Object.keys(body)) {
|
|
@@ -101,7 +101,7 @@ export function parsePageBlock(input: ParsePageInput): PageBlockAst {
|
|
|
101
101
|
if (typeof uiRaw !== 'object' || Array.isArray(uiRaw)) fail('ui 段必须是映射');
|
|
102
102
|
parseShowLevel(uiRaw, show, scope, input, 'page');
|
|
103
103
|
|
|
104
|
-
// ── watch
|
|
104
|
+
// ── watch 段:平铺 onChange 换位 ─────────────────────────────────────────
|
|
105
105
|
const bind: BindDeclaration = { obj: String(domain), var: 'page' };
|
|
106
106
|
const watch = body.watch;
|
|
107
107
|
if (watch !== undefined) {
|
|
@@ -155,7 +155,7 @@ function parseShowLevel(
|
|
|
155
155
|
where: string,
|
|
156
156
|
): void {
|
|
157
157
|
const fail = (message: string): never => {
|
|
158
|
-
throw new
|
|
158
|
+
throw new SomaBlockParseError(message, 'page');
|
|
159
159
|
};
|
|
160
160
|
|
|
161
161
|
for (const [key, value] of Object.entries(raw)) {
|
|
@@ -217,7 +217,7 @@ function isEachBlock(value: unknown): boolean {
|
|
|
217
217
|
&& typeof (value as Record<string, unknown>).each === 'string';
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
/** `each: 路径 as 变量 [by 路径] [key 字段]` →
|
|
220
|
+
/** `each: 路径 as 变量 [by 路径] [key 字段]` → 平铺 NestedShowMapping */
|
|
221
221
|
function parseEachBlock(
|
|
222
222
|
block: Record<string, unknown>,
|
|
223
223
|
scope: BlockScope,
|
|
@@ -225,7 +225,7 @@ function parseEachBlock(
|
|
|
225
225
|
anchor: string,
|
|
226
226
|
): ShowValue {
|
|
227
227
|
const fail = (message: string): never => {
|
|
228
|
-
throw new
|
|
228
|
+
throw new SomaBlockParseError(message, 'page');
|
|
229
229
|
};
|
|
230
230
|
const raw = String(block.each);
|
|
231
231
|
const match = /^(\S+)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)(?:\s+by\s+(\S+))?(?:\s+key\s+(\S+))?$/.exec(raw.trim());
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 块解析 · 组件块(REQ-005 F3)。
|
|
2
2
|
//
|
|
3
3
|
// 一个实例 = 一个块,块体是该组件的**全部**:data(三通道 + 字段字典)、
|
|
4
4
|
// ui(props / Row 体系)、event(actions 定义 + on 路由)。
|
|
5
5
|
// 不自包含就是耦合——复杂场景一来三处拼装,复杂度没有地方搬进业务组件。
|
|
6
6
|
//
|
|
7
|
-
// 产出仍是
|
|
7
|
+
// 产出仍是 平铺等价物:props 进 UiConfig.show 的 ExtendedShowValue.props,
|
|
8
8
|
// emit 路由进事件清单。soma-core 运行时对"块"一无所知,也不需要知道。
|
|
9
9
|
|
|
10
10
|
import type { ExtendedShowValue } from '../../../shared/types/ui-config.types';
|
|
11
|
-
import {
|
|
11
|
+
import { SomaBlockParseError } from '../../../build/blocks/block-container';
|
|
12
|
+
import {
|
|
13
|
+
SOMA_DATA_FIELD_TYPES,
|
|
14
|
+
SOMA_DATA_FIELD_TYPE_ALIASES,
|
|
15
|
+
} from '../../../shared/types/data-config.types';
|
|
12
16
|
import {
|
|
13
17
|
buildBlockScope,
|
|
14
18
|
expandPath,
|
|
@@ -23,11 +27,10 @@ const ACTION_KEYS = new Set([
|
|
|
23
27
|
'label', 'handler', 'change', 'confirm', 'permission', 'tone', 'when', 'disabled_reason',
|
|
24
28
|
]);
|
|
25
29
|
const FIELD_KEYS = new Set(['name', 'type', 'values', 'permission', 'rules']);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
]);
|
|
30
|
+
// 字段类型不在这里再抄一份:唯一真源是 shared/types/data-config.types.ts 的
|
|
31
|
+
// SomaDataFieldType。此前这里手写了一套 9 型,与数据对象层的 11 型已经漂开——
|
|
32
|
+
// `type: url` 在块声明里被拒收,`type: percent` 能过解析器却在 soma-ui 侧没有映射。
|
|
33
|
+
const FIELD_TYPES = new Set(SOMA_DATA_FIELD_TYPES);
|
|
31
34
|
|
|
32
35
|
export interface DataObjectDecl {
|
|
33
36
|
localName: string;
|
|
@@ -78,7 +81,7 @@ export interface UseBlockAst {
|
|
|
78
81
|
/** emit 路由:emit 名 → Pipeline 表达式 */
|
|
79
82
|
emitRoutes: Record<string, string>;
|
|
80
83
|
scope: BlockScope;
|
|
81
|
-
/**
|
|
84
|
+
/** 供既有编译管线消费的 props 形态 */
|
|
82
85
|
toShowValue(): ExtendedShowValue;
|
|
83
86
|
}
|
|
84
87
|
|
|
@@ -94,7 +97,7 @@ export interface ParseUseInput {
|
|
|
94
97
|
export function parseUseBlock(input: ParseUseInput): UseBlockAst {
|
|
95
98
|
const { blockId, body } = input;
|
|
96
99
|
const fail = (message: string): never => {
|
|
97
|
-
throw new
|
|
100
|
+
throw new SomaBlockParseError(message, blockId);
|
|
98
101
|
};
|
|
99
102
|
|
|
100
103
|
for (const key of Object.keys(body)) {
|
|
@@ -255,10 +258,13 @@ function parseField(
|
|
|
255
258
|
fail(`字段 ${objectName}.${fieldName} 不支持键 "${key}"(可用:${[...FIELD_KEYS].join('/')})`);
|
|
256
259
|
}
|
|
257
260
|
}
|
|
258
|
-
const
|
|
259
|
-
|
|
261
|
+
const declaredType = String(field.type ?? '');
|
|
262
|
+
// 别名归一(number → float):两边都有存量声明,所以两种拼写都收,
|
|
263
|
+
// 但产物里只留规范名,下游不必再判第二种写法
|
|
264
|
+
const type = SOMA_DATA_FIELD_TYPE_ALIASES[declaredType] ?? declaredType;
|
|
265
|
+
if (!FIELD_TYPES.has(declaredType)) {
|
|
260
266
|
fail(
|
|
261
|
-
`字段 ${objectName}.${fieldName} 的 type "${
|
|
267
|
+
`字段 ${objectName}.${fieldName} 的 type "${declaredType}" 非法`
|
|
262
268
|
+ `(封闭集:${[...FIELD_TYPES].join('/')})`,
|
|
263
269
|
);
|
|
264
270
|
}
|
|
@@ -356,7 +362,7 @@ function parseEventSection(
|
|
|
356
362
|
return { actions, emitRoutes };
|
|
357
363
|
}
|
|
358
364
|
|
|
359
|
-
/** funcPath 不含点 → 自动补 page
|
|
365
|
+
/** funcPath 不含点 → 自动补 page.(平铺 onChange 既有先例) */
|
|
360
366
|
function withPageDefault(funcPath: string): string {
|
|
361
367
|
return funcPath.includes('.') ? funcPath : `page.${funcPath}`;
|
|
362
368
|
}
|
|
@@ -41,8 +41,8 @@ const VALID_TRIGGERS = new Set<TransitionTrigger>([
|
|
|
41
41
|
* 解析层是页面进入运行时的**唯一必经通道**。代价是 breaking(存量违规页面报错),
|
|
42
42
|
* 这是本需求记名接受的唯一破坏点。
|
|
43
43
|
*
|
|
44
|
-
* `\b`
|
|
45
|
-
*
|
|
44
|
+
* `\b` 词边界锚定是防误伤的关键:没有它,普通业务类名可能被 utility 命名片段误判。
|
|
45
|
+
* 这里仅拦截常见的物理布局命名,不要求宿主使用任何特定 CSS 工具链。
|
|
46
46
|
*/
|
|
47
47
|
const LAYOUT_CLASS_PATTERN =
|
|
48
48
|
/\b(?:flex|grid|absolute|fixed|sticky|w-|h-|min-w-|max-w-|p[xytblre]?-|m[xytblre]?-|gap-|inset-|left-|right-|top-|bottom-|translate-|order-|col-|row-)\S*/;
|
|
@@ -120,7 +120,7 @@ function parseBase(raw: unknown, path: string): Record<string, string> {
|
|
|
120
120
|
validateSomaId(somaId, `${path}.${somaId}`);
|
|
121
121
|
if (typeof classes !== 'string') {
|
|
122
122
|
throw new SomaStyleConfigError(
|
|
123
|
-
`base 的值必须是
|
|
123
|
+
`base 的值必须是 CSS 类名字符串,当前值: ${JSON.stringify(classes)}`,
|
|
124
124
|
`${path}.${somaId}`,
|
|
125
125
|
);
|
|
126
126
|
}
|
|
@@ -167,7 +167,7 @@ function parseStateRule(raw: unknown, path: string): StyleStateRule {
|
|
|
167
167
|
// apply
|
|
168
168
|
if (!obj.apply || typeof obj.apply !== 'string') {
|
|
169
169
|
throw new SomaStyleConfigError(
|
|
170
|
-
`apply 必须是非空
|
|
170
|
+
`apply 必须是非空 CSS 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
|
|
171
171
|
path,
|
|
172
172
|
);
|
|
173
173
|
}
|
|
@@ -228,7 +228,7 @@ function parseTransition(raw: unknown, somaId: string, path: string): StyleTrans
|
|
|
228
228
|
// apply
|
|
229
229
|
if (!obj.apply || typeof obj.apply !== 'string') {
|
|
230
230
|
throw new SomaStyleConfigError(
|
|
231
|
-
`apply 必须是非空
|
|
231
|
+
`apply 必须是非空 CSS 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
|
|
232
232
|
path,
|
|
233
233
|
);
|
|
234
234
|
}
|
|
@@ -334,7 +334,7 @@ function parseTheme(raw: unknown, themeName: string, path: string): ThemeConfig
|
|
|
334
334
|
// 直铺的 somaId → 类名覆盖
|
|
335
335
|
if (typeof value !== 'string') {
|
|
336
336
|
throw new SomaStyleConfigError(
|
|
337
|
-
`主题基础覆盖的值必须是
|
|
337
|
+
`主题基础覆盖的值必须是 CSS 类名字符串,当前值: ${JSON.stringify(value)}`,
|
|
338
338
|
`${path}.${key}`,
|
|
339
339
|
);
|
|
340
340
|
}
|
|
@@ -369,7 +369,7 @@ function parseThemes(raw: unknown, path: string): Record<string, ThemeConfig> {
|
|
|
369
369
|
*
|
|
370
370
|
* 校验规则:
|
|
371
371
|
* - host 必须是非空字符串
|
|
372
|
-
* - base 的值必须是纯
|
|
372
|
+
* - base 的值必须是纯 CSS 类名字符串;core 不解析也不编译具体类名
|
|
373
373
|
* - states 的 condition 必须是纯属性路径,value 必须是基础类型
|
|
374
374
|
* - transitions 的 trigger 必须是有效枚举值
|
|
375
375
|
* - base / themes 命中布局类模式即失败;states / transitions 放行显隐对(F-06)
|
|
@@ -26,3 +26,11 @@ export {
|
|
|
26
26
|
type PublishedPageRecord,
|
|
27
27
|
type RenderPublishedPageOptions,
|
|
28
28
|
} from './remote-page';
|
|
29
|
+
export {
|
|
30
|
+
PUBLISHED_PAGE_SLUG_PATTERN,
|
|
31
|
+
RESERVED_PUBLISHED_PAGE_SLUGS,
|
|
32
|
+
isPublishedPageSlug,
|
|
33
|
+
normalizePublishedPageSlug,
|
|
34
|
+
publishedPagePath,
|
|
35
|
+
publishedPageSlugFromPath,
|
|
36
|
+
} from '../../shared/published-page-route';
|
|
@@ -54,6 +54,17 @@ export interface SomaThemeInput {
|
|
|
54
54
|
dark?: boolean;
|
|
55
55
|
/** 逐令牌精调通道:最后合并进 cssVars 与 darkCssVars,优先级最高(亮暗同时生效) */
|
|
56
56
|
overrides?: Record<string, string>;
|
|
57
|
+
/**
|
|
58
|
+
* 暗色专属精调:只并进 darkCssVars,在 `overrides` **之后**合并(同键胜出)。
|
|
59
|
+
*
|
|
60
|
+
* 为什么需要它:`overrides` 一份表同时盖亮暗两套,等于「一个令牌只能有一个值」。
|
|
61
|
+
* 后果不是理论问题——`soma-ui/src/daisy-presets.ts` 里 daisyLight / daisyDark 因此
|
|
62
|
+
* 被迫拆成两套完整独立预设,而 `ThemeScope` 的 `mode: 'system'` 只认一个预设名,
|
|
63
|
+
* 于是 35 套 daisy 主题的跟随系统亮暗**全部失效**。
|
|
64
|
+
*
|
|
65
|
+
* 缺省不给 = 行为与之前字节级一致(不影响任何既有预设)。
|
|
66
|
+
*/
|
|
67
|
+
darkOverrides?: Record<string, string>;
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
export interface SomaThemeMeta {
|
|
@@ -1007,13 +1018,22 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
1007
1018
|
};
|
|
1008
1019
|
|
|
1009
1020
|
// ⑥ 用户逐令牌精调通道:最后合并;语义色背景保留,低于 AA 的配对前景随后自动校正
|
|
1021
|
+
//
|
|
1022
|
+
// 亮暗分列:`overrides` 是两套共用的基线,`darkOverrides` 只盖暗色且排在它之后。
|
|
1023
|
+
// 不给 darkOverrides 时 darkMerged === input.overrides,行为与分列之前完全一致。
|
|
1024
|
+
const darkMerged = input.darkOverrides
|
|
1025
|
+
? { ...input.overrides, ...input.darkOverrides }
|
|
1026
|
+
: input.overrides;
|
|
1010
1027
|
if (input.overrides) {
|
|
1011
1028
|
Object.assign(cssVars, input.overrides);
|
|
1012
|
-
|
|
1029
|
+
}
|
|
1030
|
+
if (darkMerged) {
|
|
1031
|
+
Object.assign(darkCssVars, darkMerged);
|
|
1013
1032
|
}
|
|
1014
1033
|
// ⑥.1 淡底跟随实心色的覆盖(否则 daisy 那 35 套预设的徽标底与字来自两个色系)
|
|
1034
|
+
// 暗色侧要吃合并后的表,否则 darkOverrides 换掉的实心色配不上淡底
|
|
1015
1035
|
syncSoftWithOverrides(cssVars, input.overrides);
|
|
1016
|
-
syncSoftWithOverrides(darkCssVars,
|
|
1036
|
+
syncSoftWithOverrides(darkCssVars, darkMerged);
|
|
1017
1037
|
enforceContrastPairs(cssVars);
|
|
1018
1038
|
enforceContrastPairs(darkCssVars);
|
|
1019
1039
|
// ⑥.2 淡底前景:必须在 overrides 之后算,AA 保障的是**最终生效**的那套底与那套色
|
|
@@ -1022,20 +1042,28 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
1022
1042
|
|
|
1023
1043
|
// S7′ 场景颜色:与 ⑥.1/⑥.2 同一条纪律——吃最终变量表,不吃派生中途的值
|
|
1024
1044
|
/** 主色被 overrides 换过时按新主色重建色阶——光球才不会与表面分属两个色系 */
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1045
|
+
const makeRescale = (
|
|
1046
|
+
tokens: Record<string, string> | undefined,
|
|
1047
|
+
): ((primaryHex: string) => Record<string, string>) | null => (
|
|
1048
|
+
tokens?.['--soma-c-primary']
|
|
1049
|
+
? (primaryHex: string): Record<string, string> => {
|
|
1050
|
+
const p = hexToOklch(primaryHex);
|
|
1051
|
+
const rebuilt: Record<string, string> = {};
|
|
1052
|
+
STEPS.forEach((step, i) => {
|
|
1053
|
+
rebuilt[step] = oklchToHex({
|
|
1054
|
+
l: LIGHTNESS[i], c: Math.max(p.c, 0.02) * CHROMA_CURVE[i], h: p.h,
|
|
1055
|
+
});
|
|
1032
1056
|
});
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1057
|
+
return rebuilt;
|
|
1058
|
+
}
|
|
1059
|
+
: null
|
|
1060
|
+
);
|
|
1061
|
+
// 亮暗各按自己那套最终 overrides 判定要不要重建色阶:
|
|
1062
|
+
// 只在 darkOverrides 里换主色时,亮色侧不该跟着重建。
|
|
1063
|
+
const rescale = makeRescale(input.overrides);
|
|
1064
|
+
const darkRescale = makeRescale(darkMerged);
|
|
1037
1065
|
Object.assign(cssVars, sceneColorTokens(cssVars, axes, params.fieldAlphas, hexWithAlpha, scale, rescale));
|
|
1038
|
-
Object.assign(darkCssVars, sceneColorTokens(darkCssVars, axes, params.fieldAlphas, hexWithAlpha, scale,
|
|
1066
|
+
Object.assign(darkCssVars, sceneColorTokens(darkCssVars, axes, params.fieldAlphas, hexWithAlpha, scale, darkRescale));
|
|
1039
1067
|
|
|
1040
1068
|
return {
|
|
1041
1069
|
scale,
|
package/core/index.ts
CHANGED
|
@@ -58,6 +58,12 @@ export type {
|
|
|
58
58
|
SomaDataFieldPermission,
|
|
59
59
|
SomaDataDicts,
|
|
60
60
|
} from './shared/types/data-config.types';
|
|
61
|
+
// 字段类型的唯一真源(值导出):块解析器与 soma-ui 的双态映射表都消费它,
|
|
62
|
+
// 消费方不得再手抄一份清单——四份手写副本里漏改一份,就是「一处合法、一处静默按 text 渲染」。
|
|
63
|
+
export {
|
|
64
|
+
SOMA_DATA_FIELD_TYPES,
|
|
65
|
+
SOMA_DATA_FIELD_TYPE_ALIASES,
|
|
66
|
+
} from './shared/types/data-config.types';
|
|
61
67
|
export {
|
|
62
68
|
deriveTheme,
|
|
63
69
|
applyTheme,
|
|
@@ -235,6 +241,12 @@ export {
|
|
|
235
241
|
type RegisterDeclarationOptions,
|
|
236
242
|
type RenderPublishedPageOptions,
|
|
237
243
|
type SomaPageLifecycleOptions,
|
|
244
|
+
PUBLISHED_PAGE_SLUG_PATTERN,
|
|
245
|
+
RESERVED_PUBLISHED_PAGE_SLUGS,
|
|
246
|
+
isPublishedPageSlug,
|
|
247
|
+
normalizePublishedPageSlug,
|
|
248
|
+
publishedPagePath,
|
|
249
|
+
publishedPageSlugFromPath,
|
|
238
250
|
} from './client/registry/index';
|
|
239
251
|
|
|
240
252
|
// 组件包(业务拓展组件库):合成、查重、目录、自检。
|
|
@@ -252,8 +264,8 @@ export {
|
|
|
252
264
|
} from './client/component/component-pack';
|
|
253
265
|
export { verifyComponentPack, type VerifyPackOptions } from './client/component/verify-pack';
|
|
254
266
|
|
|
255
|
-
// 值语言(
|
|
256
|
-
// 规格见 doc
|
|
267
|
+
// 值语言(REQ-005 F4):算术六词元 + 管道链的唯一值规则。
|
|
268
|
+
// 规格见 soma-core/doc/soma DSL 语法全书 v2.md §7;
|
|
257
269
|
// v2 其余部件未施工前,本模块可被 v1 路径独立复用(纯函数、无依赖)。
|
|
258
270
|
export {
|
|
259
271
|
parseValueSegment,
|
|
@@ -272,35 +284,35 @@ export {
|
|
|
272
284
|
// SOMA DSL 容器与块装载(外置块发现在 soma-core/server)。
|
|
273
285
|
export {
|
|
274
286
|
loadSomaFile,
|
|
275
|
-
|
|
287
|
+
SomaBlockParseError,
|
|
276
288
|
PAGE_BLOCK_ID,
|
|
277
289
|
type RawBlock,
|
|
278
290
|
type SomaFileLoadInput,
|
|
279
|
-
} from './build/
|
|
291
|
+
} from './build/blocks/block-container';
|
|
280
292
|
export {
|
|
281
293
|
buildHtmlAnchorIndex,
|
|
282
294
|
type HtmlAnchorIndex,
|
|
283
295
|
type HtmlAnchorInfo,
|
|
284
|
-
} from './build/
|
|
285
|
-
//
|
|
296
|
+
} from './build/blocks/html-index';
|
|
297
|
+
// 资产级入口:拿着原始块声明的一方(服务端装载层/测试替身/预览器)先编译,
|
|
286
298
|
// 再把 v1 等价产物交给 mount——运行时只认 v1(两级编译、单一运行时)。
|
|
287
299
|
export { compilePageAssets } from './build/compiler/page-assets';
|
|
288
300
|
export {
|
|
289
|
-
|
|
290
|
-
type
|
|
291
|
-
type
|
|
292
|
-
} from './build/
|
|
301
|
+
compileSomaBlocks,
|
|
302
|
+
type CompiledSomaBlocks,
|
|
303
|
+
type CompileSomaBlocksInput,
|
|
304
|
+
} from './build/blocks/block-compile';
|
|
293
305
|
export {
|
|
294
306
|
parsePageBlock,
|
|
295
307
|
type PageBlockAst,
|
|
296
|
-
} from './client/parser/
|
|
308
|
+
} from './client/parser/blocks/page-parser';
|
|
297
309
|
export {
|
|
298
310
|
parseUseBlock,
|
|
299
311
|
type UseBlockAst,
|
|
300
312
|
type DataObjectDecl,
|
|
301
313
|
type FieldDecl,
|
|
302
314
|
type ActionDecl,
|
|
303
|
-
} from './client/parser/
|
|
315
|
+
} from './client/parser/blocks/use-parser';
|
|
304
316
|
export {
|
|
305
317
|
buildBlockScope,
|
|
306
318
|
resolvePath,
|
|
@@ -309,7 +321,7 @@ export {
|
|
|
309
321
|
scopeHasVar,
|
|
310
322
|
SomaScopeError,
|
|
311
323
|
type BlockScope,
|
|
312
|
-
} from './client/parser/
|
|
324
|
+
} from './client/parser/blocks/namespace';
|
|
313
325
|
export {
|
|
314
326
|
checkOverrideCompat,
|
|
315
327
|
type ContractCompatIssue,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// 阶段直接给它打 nonce,所以必须留一个客户端读得到的落点——`<meta name="csp-nonce">`。
|
|
7
7
|
//
|
|
8
8
|
// 为什么单独成模块而不是写死在 app/layout.tsx 里:
|
|
9
|
-
// 1. 官方 Host 的 layout 会 `import './globals.css'
|
|
9
|
+
// 1. 官方 Host 的 layout 会 `import './globals.css'`,把逻辑关在
|
|
10
10
|
// 里面就没法单测;
|
|
11
11
|
// 2. 自己写 layout 的宿主也需要这段能力,抄一遍就会抄漏「CSP 关时别读请求头」这条。
|
|
12
12
|
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
// 发布页路径接线:Registry canonical 声明 → 服务端内存编译 → Host 运行时资产。
|
|
2
2
|
|
|
3
3
|
import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
|
|
4
|
+
import { publishedPageSlugFromPath } from '../../shared/published-page-route';
|
|
4
5
|
import { getPageRegistryRepository } from '../registry/page-registry-repository';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** `/pages/<registry-name>` 是发布声明的稳定浏览路径;更深层路径仍归普通 Host 页面。 */
|
|
9
|
-
export function registryPageNameFromPath(pagePath: string): string | null {
|
|
10
|
-
if (!pagePath.startsWith(PUBLISHED_PAGE_PREFIX)) return null;
|
|
11
|
-
const name = pagePath.slice(PUBLISHED_PAGE_PREFIX.length);
|
|
12
|
-
return name !== '' && !name.includes('/') ? name : null;
|
|
13
|
-
}
|
|
7
|
+
/** Registry `myworkspace` 的正式地址是 `/myworkspace`;兼容读取旧 `/pages/myworkspace`。 */
|
|
8
|
+
export const registryPageNameFromPath = publishedPageSlugFromPath;
|
|
14
9
|
|
|
15
10
|
/** Registry 声明只在服务端编译,浏览器收到的仍是既有运行时资产。 */
|
|
16
11
|
export async function loadPublishedRegistryPageAssets(pagePath: string) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SOMA DSL 页面接入运行路径:源声明只在服务端编译,浏览器只消费运行时资产。
|
|
2
2
|
|
|
3
3
|
import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
|
|
4
|
-
import { loadExternalBlocks } from '../../build/
|
|
4
|
+
import { loadExternalBlocks } from '../../build/blocks/block-loader';
|
|
5
5
|
|
|
6
6
|
export interface SomaPageCompileResult {
|
|
7
7
|
ui: string;
|
package/core/server/index.ts
CHANGED
|
@@ -70,12 +70,12 @@ export {
|
|
|
70
70
|
type LoadPackFromDirOptions,
|
|
71
71
|
} from '../build/component/pack-from-dir';
|
|
72
72
|
|
|
73
|
-
//
|
|
73
|
+
// 块声明容器(REQ-005):开关探测、HTML 锚点索引、块装载、外置块发现。
|
|
74
74
|
// 用 node:fs 的只有 block-loader,其余纯函数(可在浏览器侧复用)。
|
|
75
75
|
export {
|
|
76
76
|
loadExternalBlocks,
|
|
77
77
|
blocksDirOf,
|
|
78
|
-
} from '../build/
|
|
78
|
+
} from '../build/blocks/block-loader';
|
|
79
79
|
|
|
80
80
|
export {
|
|
81
81
|
setSomaDb,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry 发布页的公开 URL 契约。
|
|
3
|
+
*
|
|
4
|
+
* 页面名就是根路径 slug:Registry `myworkspace` 对应 `/myworkspace`。
|
|
5
|
+
* `/pages/<name>` 仅保留为存量链接兼容入口,新发布结果不再生成该前缀。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const PUBLISHED_PAGE_SLUG_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
9
|
+
|
|
10
|
+
/** Next/SOMA 内部入口不能被 Registry 根路径页面占用。 */
|
|
11
|
+
export const RESERVED_PUBLISHED_PAGE_SLUGS = new Set([
|
|
12
|
+
'api',
|
|
13
|
+
'soma',
|
|
14
|
+
'pages',
|
|
15
|
+
'workbench',
|
|
16
|
+
'_next',
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export function isPublishedPageSlug(value: unknown): value is string {
|
|
20
|
+
return typeof value === 'string'
|
|
21
|
+
&& PUBLISHED_PAGE_SLUG_PATTERN.test(value)
|
|
22
|
+
&& !RESERVED_PUBLISHED_PAGE_SLUGS.has(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 归一化模型或用户给出的候选路径。只做机械变换,不擅自翻译中文;
|
|
27
|
+
* 语义翻译由生成模型负责,调用方可在 null 时提供确定性兜底。
|
|
28
|
+
*/
|
|
29
|
+
export function normalizePublishedPageSlug(value: unknown): string | null {
|
|
30
|
+
if (typeof value !== 'string') return null;
|
|
31
|
+
const normalized = value
|
|
32
|
+
.trim()
|
|
33
|
+
.toLowerCase()
|
|
34
|
+
.replace(/^\/+|\/+$/g, '')
|
|
35
|
+
.replace(/[\s_]+/g, '-')
|
|
36
|
+
.replace(/[^a-z0-9-]/g, '')
|
|
37
|
+
.replace(/-+/g, '-')
|
|
38
|
+
.replace(/^-|-$/g, '')
|
|
39
|
+
.slice(0, 64)
|
|
40
|
+
.replace(/-$/g, '');
|
|
41
|
+
return isPublishedPageSlug(normalized) ? normalized : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function publishedPagePath(slug: string): string {
|
|
45
|
+
if (!isPublishedPageSlug(slug)) {
|
|
46
|
+
throw new Error(`Invalid published page slug: ${slug}`);
|
|
47
|
+
}
|
|
48
|
+
return `/${slug}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 根路径是正式入口;旧 `/pages/<name>` 继续可读,避免已分享链接立即失效。
|
|
53
|
+
* 只接受单段路径,子路径仍交给 Host 文件页处理。
|
|
54
|
+
*/
|
|
55
|
+
export function publishedPageSlugFromPath(pagePath: string): string | null {
|
|
56
|
+
const legacy = pagePath.match(/^\/pages\/([^/]+)$/)?.[1];
|
|
57
|
+
if (legacy && isPublishedPageSlug(legacy)) return legacy;
|
|
58
|
+
|
|
59
|
+
const root = pagePath.match(/^\/([^/]+)$/)?.[1];
|
|
60
|
+
return root && isPublishedPageSlug(root) ? root : null;
|
|
61
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// core/shared/types/adaptive.types.ts — 降级阶梯声明类型与词汇注册契约(F-07 / F-09)
|
|
2
2
|
//
|
|
3
|
-
// 边界(
|
|
3
|
+
// 边界(soma-core/doc/空间体系契约与边界.md C4 C5 与禁止边 2):
|
|
4
4
|
// 语法归语言(core),级语义词汇归组件(soma-ui)。
|
|
5
5
|
// 本文件只定义"形状",不定义任何级的含义——core 不内置、也不 import 任何级语义;
|
|
6
6
|
// 词汇一律由宿主 bootstrap 注入。这是"core 对几何档位零认知"不变量在类型层的落点。
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
// 数据对象是业务抽象出的命名数据(如 order),来源是一个或多个后端接口;
|
|
4
4
|
// 组件与页面只认对象与字段,不认接口协议。
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* 字段类型枚举(决定 soma-ui 双态映射走哪个渲染组件)。
|
|
8
|
+
*
|
|
9
|
+
* **这是字段类型的唯一真源。** 块声明的 `fields.type` 与 soma-ui 的双态映射表
|
|
10
|
+
* 都必须消费它,不得各自再抄一份——此前正是抄成了三份:
|
|
11
|
+
* 数据对象层 11 型、soma-ui 11 型(逐字重复)、块声明 9 型(已漂)。
|
|
12
|
+
* 后果是 `type: url` 在块声明里被解析器拒收,而 `type: percent` 能过解析器
|
|
13
|
+
* 却在 soma-ui 侧没有映射、静默按 text 渲染出来。
|
|
14
|
+
*/
|
|
7
15
|
export type SomaDataFieldType =
|
|
8
16
|
| 'text'
|
|
9
17
|
| 'int'
|
|
@@ -15,7 +23,27 @@ export type SomaDataFieldType =
|
|
|
15
23
|
| 'datetime'
|
|
16
24
|
| 'image'
|
|
17
25
|
| 'url'
|
|
18
|
-
| 'richtext'
|
|
26
|
+
| 'richtext'
|
|
27
|
+
// 以下三型原本只在块声明侧存在,收编进唯一真源:
|
|
28
|
+
// percent 与 progress 是同一份数据的两种读法(前者出文字、后者出进度条)
|
|
29
|
+
| 'percent'
|
|
30
|
+
| 'progress';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 类型别名:块声明历史上用 `number` 表示小数,与本表的 `float` 同义。
|
|
34
|
+
* 保留为可接受拼写而不是二选一,是因为两边都有存量声明——
|
|
35
|
+
* 归一到 `float` 由解析器做,词汇表只认一个概念。
|
|
36
|
+
*/
|
|
37
|
+
export const SOMA_DATA_FIELD_TYPE_ALIASES: Readonly<Record<string, SomaDataFieldType>> = {
|
|
38
|
+
number: 'float',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** 全部合法字段类型(含别名),供解析器做封闭集校验 */
|
|
42
|
+
export const SOMA_DATA_FIELD_TYPES: readonly string[] = [
|
|
43
|
+
'text', 'int', 'float', 'money', 'bool', 'enum', 'date', 'datetime',
|
|
44
|
+
'image', 'url', 'richtext', 'percent', 'progress',
|
|
45
|
+
...Object.keys(SOMA_DATA_FIELD_TYPE_ALIASES),
|
|
46
|
+
];
|
|
19
47
|
|
|
20
48
|
/** 字段权限:r 只读 / w 可写(决定双态映射走 show 还是 edit 形态) */
|
|
21
49
|
export type SomaDataFieldPermission = 'r' | 'w';
|