soma-core 1.4.0 → 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 +1 -1
- package/core/build/blocks/block-compile.ts +31 -2
- package/core/build/blocks/block-container.ts +2 -11
- package/core/build/compiler/page-declaration-compiler.ts +30 -2
- package/core/build/compiler/soma-precompile.js +2041 -19
- 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 +79 -4
- 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/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 +265 -5
- package/core/client/engine/step-runner.ts +134 -0
- package/core/client/parser/blocks/page-parser.ts +15 -1
- package/core/client/parser/blocks/use-parser.ts +5 -12
- 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/ui-config-parser.ts +59 -0
- package/core/client/parser/window-parser.ts +294 -0
- package/core/client/theme/theme-engine.ts +102 -2
- package/core/index.ts +163 -0
- 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/types/component-contract.types.ts +128 -2
- package/core/shared/types/data-config.types.ts +120 -1
- 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/step.types.ts +91 -0
- package/core/shared/types/ui-config.types.ts +18 -0
- package/core/shared/types/window.types.ts +177 -0
- package/dist/cli/soma.js +13 -1
- package/dist/core/index.cjs +4684 -349
- package/dist/types/build/blocks/block-container.d.ts +1 -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/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/parser/blocks/use-parser.d.ts +2 -2
- 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/ui-config-parser.d.ts +5 -0
- package/dist/types/client/parser/window-parser.d.ts +25 -0
- package/dist/types/client/theme/theme-engine.d.ts +26 -0
- package/dist/types/index.d.ts +32 -2
- 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/types/component-contract.types.d.ts +112 -0
- package/dist/types/shared/types/data-config.types.d.ts +115 -1
- 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/step.types.d.ts +76 -0
- 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 -1
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { SomaNamedPredicates } from '../predicates';
|
|
2
|
+
import type { SomaReactionGraph } from './reaction.types';
|
|
3
|
+
import type { SomaWindowConfig, SomaWindowHandle } from './window.types';
|
|
1
4
|
/**
|
|
2
5
|
* 字段类型枚举(决定 soma-ui 双态映射走哪个渲染组件)。
|
|
3
6
|
*
|
|
@@ -7,7 +10,15 @@
|
|
|
7
10
|
* 后果是 `type: url` 在块声明里被解析器拒收,而 `type: percent` 能过解析器
|
|
8
11
|
* 却在 soma-ui 侧没有映射、静默按 text 渲染出来。
|
|
9
12
|
*/
|
|
10
|
-
export type SomaDataFieldType = 'text' | 'int' | 'float' | 'money' | 'bool' | 'enum' | 'date' | 'datetime' | 'image' | 'url' | 'richtext' | 'percent' | 'progress'
|
|
13
|
+
export type SomaDataFieldType = 'text' | 'int' | 'float' | 'money' | 'bool' | 'enum' | 'date' | 'datetime' | 'image' | 'url' | 'richtext' | 'percent' | 'progress'
|
|
14
|
+
/** 多值标签(string[])→ TagInput */
|
|
15
|
+
| 'tags'
|
|
16
|
+
/** 附件(文件列表或文件地址)→ Upload */
|
|
17
|
+
| 'file'
|
|
18
|
+
/** 树形单选(options 为节点集)→ TreeSelect */
|
|
19
|
+
| 'tree'
|
|
20
|
+
/** 级联路径(string[],从根到叶)→ Cascader */
|
|
21
|
+
| 'cascade';
|
|
11
22
|
/**
|
|
12
23
|
* 类型别名:块声明历史上用 `number` 表示小数,与本表的 `float` 同义。
|
|
13
24
|
* 保留为可接受拼写而不是二选一,是因为两边都有存量声明——
|
|
@@ -57,6 +68,15 @@ export interface SomaDataFieldConfig {
|
|
|
57
68
|
rules?: SomaDataFieldRule[];
|
|
58
69
|
/** 枚举候选项 */
|
|
59
70
|
options?: SomaDataFieldOption[];
|
|
71
|
+
/**
|
|
72
|
+
* 派生列(REQ-010 S2 / F-10):`"[revenue] - [cost]"`。
|
|
73
|
+
*
|
|
74
|
+
* 这是 AG Grid `valueGetter` 的封闭降级:那边是一个任意函数,这边是受限文法
|
|
75
|
+
* (方括号引用同对象字段、四则、比较、六个函数),解析期能推出结果类型并与声明的
|
|
76
|
+
* `type` 对账。声了 `calc` 的字段**权限恒为 r**——它是算出来的,写它没有意义,
|
|
77
|
+
* 而"写了没反应"是最难查的一类。
|
|
78
|
+
*/
|
|
79
|
+
calc?: string;
|
|
60
80
|
}
|
|
61
81
|
/**
|
|
62
82
|
* 单个取数来源:一个后端接口 + 参数 + 聚合位置。
|
|
@@ -71,6 +91,44 @@ export interface SomaDataSourceConfig {
|
|
|
71
91
|
/** 结果聚合到对象子键(如 order.trace);缺省浅合并进对象根 */
|
|
72
92
|
into?: string;
|
|
73
93
|
}
|
|
94
|
+
/** 写通道的一个端点:接口 + 方法(《数据对象层》§8.2) */
|
|
95
|
+
export interface SomaDataWriteEndpoint {
|
|
96
|
+
/** 后端接口路径(后端接口是唯一数据边界) */
|
|
97
|
+
api: string;
|
|
98
|
+
/** HTTP 方法;白名单 POST / PUT / PATCH */
|
|
99
|
+
method: 'POST' | 'PUT' | 'PATCH';
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 写通道声明(REQ-009 M-5,《数据对象层》§8)。
|
|
103
|
+
*
|
|
104
|
+
* 读通道早已统一(from / transform / fields 走 SomaDataObjectResolver),
|
|
105
|
+
* 而写路径此前仍是组件直连:FormConsole 在 props 里自带 fields + submit_api + load_api,
|
|
106
|
+
* 于是字段与校验在 `_data.yaml` 和组件 props 各存一份,字典事实源分裂;
|
|
107
|
+
* 提交编排(收值 / 校验 / 调接口 / 错误呈现)每个自治组件各写一遍。
|
|
108
|
+
*
|
|
109
|
+
* 目标:**一份 `_data.yaml` 覆盖读 + 写,组件只说"我消费哪个对象"**。
|
|
110
|
+
*/
|
|
111
|
+
export interface SomaDataWriteConfig {
|
|
112
|
+
/** 新建端点(create / update 至少给一个) */
|
|
113
|
+
create?: SomaDataWriteEndpoint;
|
|
114
|
+
/** 更新端点 */
|
|
115
|
+
update?: SomaDataWriteEndpoint;
|
|
116
|
+
/** 乐观锁字段名(必须在字典里;它是唯一允许随请求体上行的 r 字段) */
|
|
117
|
+
version?: string;
|
|
118
|
+
/** 表单键 → 请求体键的平面改名(键必须在字典且非 r 字段) */
|
|
119
|
+
map?: Record<string, string>;
|
|
120
|
+
/**
|
|
121
|
+
* 请求体字段白名单(REQ-010 F-38):只发这几个字段。
|
|
122
|
+
*
|
|
123
|
+
* 与 `permission` 的分工:`permission: r` 说的是「这个字段不可编辑」,
|
|
124
|
+
* 是**字段自身的性质**;`only` 说的是「这次写只送这几个」,是**这条通道的口径**。
|
|
125
|
+
* 用 permission 去表达后者会连带把控件降级成只读文本——那是另一件事。
|
|
126
|
+
* 块声明 `save.fields` 归一到这里。
|
|
127
|
+
*/
|
|
128
|
+
only?: string[];
|
|
129
|
+
/** 提交成功后重取:'self' 只重取本对象 / 'all' 全部 / 指定对象名数组 */
|
|
130
|
+
reload?: 'self' | 'all' | string[];
|
|
131
|
+
}
|
|
74
132
|
/** 数据对象声明(*_data.yaml 中 data.<对象名> 的解析产物) */
|
|
75
133
|
export interface SomaDataObjectConfig {
|
|
76
134
|
/** 对象名(页面内唯一,即 data 下的键名) */
|
|
@@ -86,9 +144,65 @@ export interface SomaDataObjectConfig {
|
|
|
86
144
|
fields?: Record<string, SomaDataFieldConfig>;
|
|
87
145
|
/** mock 样本:SOMA_MOCK_ENABLED / 接口失败兜底 / 无接口预览 */
|
|
88
146
|
mock?: unknown;
|
|
147
|
+
/** 写通道声明(§8);不给 = 该对象只读 */
|
|
148
|
+
write?: SomaDataWriteConfig;
|
|
149
|
+
/**
|
|
150
|
+
* 具名谓词表(REQ-010 S1b):`{ 名字: 谓词 }`。
|
|
151
|
+
* 一条「是否企业客户」声明一次,反应与字段显隐处处 `{ ref: 名字 }` 复用——
|
|
152
|
+
* 复制粘贴出来的那几份,将来必然漏改一份。
|
|
153
|
+
*/
|
|
154
|
+
predicates?: SomaNamedPredicates;
|
|
155
|
+
/**
|
|
156
|
+
* 反应图(REQ-010 S1b):字段之间的联动。
|
|
157
|
+
* 解析期已建成 DAG、检过环、算好回溯表——这是 Formily / amis 靠 eval + 运行时
|
|
158
|
+
* 依赖收集换不来的东西。
|
|
159
|
+
*/
|
|
160
|
+
reactions?: SomaReactionGraph;
|
|
161
|
+
/**
|
|
162
|
+
* 数据窗口(REQ-010 S2):一屏一屏地取。
|
|
163
|
+
* 声明期已把过滤 AST、排序/分组/聚合的字段引用对着字典校验过,并算好字典哈希。
|
|
164
|
+
*/
|
|
165
|
+
window?: SomaWindowConfig;
|
|
89
166
|
/** 解析期提取:params 引用到的其他数据对象名(DAG 拓扑排序输入,不含自引用) */
|
|
90
167
|
deps: string[];
|
|
91
168
|
}
|
|
169
|
+
/** 写通道提交结果:成功带数据,失败带整体文案与字段级错误(§8.3) */
|
|
170
|
+
export type SomaDataSubmitResult = {
|
|
171
|
+
ok: true;
|
|
172
|
+
data?: unknown;
|
|
173
|
+
} | {
|
|
174
|
+
ok: false;
|
|
175
|
+
message: string;
|
|
176
|
+
fieldErrors?: Record<string, string>;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* 注入给自治组件的数据端口(services 白名单里的 `data`,§8.4)。
|
|
180
|
+
* 复杂度沉引擎:组件只做「收值 → 调 submit → 渲染返回的 fieldErrors」。
|
|
181
|
+
*/
|
|
182
|
+
export interface SomaDataPort {
|
|
183
|
+
/** 读态(回填来源) */
|
|
184
|
+
getObject(name: string): unknown;
|
|
185
|
+
/** 字段字典(控件 / 校验来源) */
|
|
186
|
+
getDict(name: string): Record<string, SomaDataFieldConfig>;
|
|
187
|
+
/**
|
|
188
|
+
* 反应图与具名谓词表(REQ-010 S1b):`_data.yaml` 的 `reactions:` / `predicates:` 段。
|
|
189
|
+
* 组件拿它跑 `runReactions`——联动声明在数据对象上,与字段字典同源同一份,
|
|
190
|
+
* 不必在页面 DSL 里再抄一遍。没声明的对象返回 null(= 无联动)。
|
|
191
|
+
*/
|
|
192
|
+
getReactions(name: string): {
|
|
193
|
+
graph: SomaReactionGraph;
|
|
194
|
+
named: SomaNamedPredicates;
|
|
195
|
+
} | null;
|
|
196
|
+
/**
|
|
197
|
+
* 数据窗口(REQ-010 S2):声了 `window:` 段的对象才有,没有返回 null。
|
|
198
|
+
* 组件拿到它就不再自持 `page / sort_key / filters`——那些裁决收在引擎里只有一份。
|
|
199
|
+
*/
|
|
200
|
+
window(name: string): SomaWindowHandle | null;
|
|
201
|
+
/** 写通道:校验 → 构体 → 调接口 → 错误逆映射 → reload */
|
|
202
|
+
submit(name: string, model: Record<string, unknown>, mode?: 'create' | 'update'): Promise<SomaDataSubmitResult>;
|
|
203
|
+
/** 手动重取(等价 Domain 的 _reloadData 细粒度版) */
|
|
204
|
+
reload(names?: string[]): Promise<void>;
|
|
205
|
+
}
|
|
92
206
|
/** *_data.yaml 整体解析产物(对象名 → 声明) */
|
|
93
207
|
export interface SomaDataConfig {
|
|
94
208
|
objects: Record<string, SomaDataObjectConfig>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* 页面聚合根接口
|
|
3
3
|
* 展示对象必须实现此接口,提供页面生命周期钩子
|
|
4
4
|
*/
|
|
5
|
+
import type { SomaPageState, SomaPageStateConfig } from './page-state.types';
|
|
5
6
|
export interface SomaPageRoot {
|
|
6
7
|
/** Content strings from locale.yaml (injected by bootstrap) */
|
|
7
8
|
_locale?: Record<string, unknown>;
|
|
@@ -15,6 +16,17 @@ export interface SomaPageRoot {
|
|
|
15
16
|
_reloadData?: () => Promise<void>;
|
|
16
17
|
/** 重新执行数据对象取数(无声明时为空操作) */
|
|
17
18
|
reloadData?(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* 页面态(REQ-010 F-37):排序 / 过滤 / 选择 / 列显隐 / 密度 / 展开。
|
|
21
|
+
* 没声明 `state:` 段时恒为 null——不是空对象:空对象会让调用方以为
|
|
22
|
+
* "有状态,只是都是缺省",于是把它序列化进分享链接,而链接打开后什么都恢复不了。
|
|
23
|
+
*/
|
|
24
|
+
_pageState?: SomaPageState | null;
|
|
25
|
+
/** `state:` 段的声明(bootstrap 注入) */
|
|
26
|
+
_pageStateConfig?: SomaPageStateConfig | null;
|
|
27
|
+
getState?(): SomaPageState | null;
|
|
28
|
+
setState?(next: SomaPageState): void;
|
|
29
|
+
onStateUpdated?(listener: (state: SomaPageState) => void): () => void;
|
|
18
30
|
/** 页面初始化(引擎在渲染完成后调用) */
|
|
19
31
|
onMount?(): void | Promise<void>;
|
|
20
32
|
/** 页面销毁前(引擎在卸载时调用) */
|
|
@@ -2,17 +2,23 @@
|
|
|
2
2
|
* 事件类型枚举
|
|
3
3
|
* 定义 Pipeline DSL 支持的四种事件处理类型
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
import type { SomaStepGraph } from './step.types';
|
|
6
|
+
export type EventType = 'NAV_STATIC' | 'NAV_ACTION' | 'UI_REFRESH' | 'UI_INTERACT' | 'ACTION' | 'STEPS';
|
|
6
7
|
/**
|
|
7
8
|
* UI 交互动作枚举
|
|
8
9
|
* 用于 UI_INTERACT 类型的动作指令
|
|
9
10
|
*/
|
|
10
|
-
export type InteractAction = 'open' | 'close' | 'toggle';
|
|
11
|
+
export type InteractAction = 'open' | 'close' | 'toggle' | 'focus' | 'scroll_to' | 'select';
|
|
11
12
|
/**
|
|
12
13
|
* 解析后的事件配置
|
|
13
14
|
* Pipeline DSL 解析器将 YAML 中的事件声明解析为此结构
|
|
14
15
|
*/
|
|
15
16
|
export interface ParsedEvent {
|
|
17
|
+
/**
|
|
18
|
+
* 动作编排图(`type === 'STEPS'` 时有)。
|
|
19
|
+
* 解析在 `step-parser`,执行在 `step-runner`;不带它的事件走原来的单管道路径。
|
|
20
|
+
*/
|
|
21
|
+
steps?: SomaStepGraph;
|
|
16
22
|
/** 目标元素的 data-soma-id 值 */
|
|
17
23
|
somaId: string;
|
|
18
24
|
/** DOM 事件类型(click, input, change, keydown 等) */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** 尺寸意图三档(Auto Layout 的对位物) */
|
|
2
|
+
export type SomaSizing = 'fixed' | 'hug' | 'fill';
|
|
3
|
+
/**
|
|
4
|
+
* 优先级四档(Auto Layout 惯例):
|
|
5
|
+
* 250 = Content Hugging("我愿意被拉大")、500 = 中庸、
|
|
6
|
+
* 750 = Compression Resistance("我不愿意被压小")、1000 = required(不可违反)。
|
|
7
|
+
*
|
|
8
|
+
* 是四档不是任意整数:优先级只在**相对次序**上有意义,开放成整数只会让人写出
|
|
9
|
+
* 748 与 752 这种自己也说不清差别的值,而它们的差别在求解结果上确实存在。
|
|
10
|
+
*/
|
|
11
|
+
export declare const SOMA_LAYOUT_PRIORITIES: readonly [250, 500, 750, 1000];
|
|
12
|
+
export type SomaPriority = typeof SOMA_LAYOUT_PRIORITIES[number];
|
|
13
|
+
/** 换行策略:不换 / 窄了就竖排 / 横向滚动成一条卷轴 */
|
|
14
|
+
export type SomaWrap = 'none' | 'below' | 'reel';
|
|
15
|
+
export declare const SOMA_LAYOUT_ALIGNS: readonly ["start", "center", "end", "baseline", "space_between", "space_evenly", "space_around"];
|
|
16
|
+
export type SomaAlign = typeof SOMA_LAYOUT_ALIGNS[number];
|
|
17
|
+
/** 一个子项的约束 */
|
|
18
|
+
export interface SomaLayoutNodeConstraint {
|
|
19
|
+
sizing: SomaSizing;
|
|
20
|
+
/** `sizing: fixed` 的目标宽;`rem` / `%` / `cqi` 三种单位 */
|
|
21
|
+
width?: string;
|
|
22
|
+
min?: string;
|
|
23
|
+
max?: string;
|
|
24
|
+
priority?: SomaPriority;
|
|
25
|
+
}
|
|
26
|
+
/** 一组(一行)的约束 */
|
|
27
|
+
export interface SomaLayoutConstraint {
|
|
28
|
+
/** 子项名 → 约束;声明序即视觉序 */
|
|
29
|
+
nodes: Record<string, SomaLayoutNodeConstraint>;
|
|
30
|
+
/** 子项之间的间隔(rem) */
|
|
31
|
+
gap?: string;
|
|
32
|
+
wrap?: SomaWrap;
|
|
33
|
+
align?: SomaAlign;
|
|
34
|
+
/** 具名容器上下文:编译成 `container-name` */
|
|
35
|
+
container_name?: string;
|
|
36
|
+
}
|
|
37
|
+
/** 单档的解 */
|
|
38
|
+
export interface SomaLayoutSolution {
|
|
39
|
+
/** 档名(`cqXs` … `cq4xl`) */
|
|
40
|
+
breakpoint: string;
|
|
41
|
+
/** 该档的容器宽度(rem) */
|
|
42
|
+
containerRem: number;
|
|
43
|
+
/** 子项名 → 解出的宽度(rem) */
|
|
44
|
+
widths: Record<string, number>;
|
|
45
|
+
/** 该档是否必须换行(解不出「两者都 ≥ min」时为真) */
|
|
46
|
+
wrapped: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** 求解产物 */
|
|
49
|
+
export interface SomaLayoutPlan {
|
|
50
|
+
constraint: SomaLayoutConstraint;
|
|
51
|
+
solutions: SomaLayoutSolution[];
|
|
52
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** 一个数据窗口的可序列化状态 */
|
|
2
|
+
export interface SomaWindowStateSlice {
|
|
3
|
+
sort?: Array<{
|
|
4
|
+
field: string;
|
|
5
|
+
order: 'asc' | 'desc';
|
|
6
|
+
}>;
|
|
7
|
+
filter?: unknown;
|
|
8
|
+
selection?: {
|
|
9
|
+
base: 'none' | 'all';
|
|
10
|
+
toggled: string[];
|
|
11
|
+
};
|
|
12
|
+
/** 分组展开路径 */
|
|
13
|
+
group_keys?: string[];
|
|
14
|
+
}
|
|
15
|
+
/** 一个表格锚点的列状态 */
|
|
16
|
+
export interface SomaColumnStateSlice {
|
|
17
|
+
visible?: string[];
|
|
18
|
+
order?: string[];
|
|
19
|
+
pinned?: Record<string, 'start' | 'end'>;
|
|
20
|
+
width?: Record<string, number>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 页面态。
|
|
24
|
+
*
|
|
25
|
+
* `version` 是必需的:恢复一份旧结构的状态会让界面进入一个谁都没设计过的样子,
|
|
26
|
+
* 而那种坏法是静默的(列还在、但顺序是乱的)。版本对不上就整份丢弃并说明原因。
|
|
27
|
+
*/
|
|
28
|
+
export interface SomaPageState {
|
|
29
|
+
version: number;
|
|
30
|
+
window?: Record<string, SomaWindowStateSlice>;
|
|
31
|
+
columns?: Record<string, SomaColumnStateSlice>;
|
|
32
|
+
density?: 'sm' | 'md' | 'lg';
|
|
33
|
+
/** 展开的行/分组 id */
|
|
34
|
+
expanded?: string[];
|
|
35
|
+
}
|
|
36
|
+
/** `_ui.yaml` 顶层 `state:` 段的声明形态 */
|
|
37
|
+
export interface SomaPageStateConfig {
|
|
38
|
+
version: number;
|
|
39
|
+
/** 允许出现在页面态里的窗口名(必须是已声明的数据对象) */
|
|
40
|
+
window?: string[];
|
|
41
|
+
/** 允许出现在页面态里的表格锚点 */
|
|
42
|
+
columns?: string[];
|
|
43
|
+
density?: boolean;
|
|
44
|
+
expanded?: boolean;
|
|
45
|
+
/** 初始状态:只读一次,之后由用户交互接管 */
|
|
46
|
+
initial_state?: SomaPageState;
|
|
47
|
+
/** 是否把状态同步进 URL(`?s=<紧凑序列化>`) */
|
|
48
|
+
url?: boolean;
|
|
49
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { SomaFieldPredicate } from '../predicates';
|
|
2
|
+
/**
|
|
3
|
+
* 触发时机——闭集十一档(对齐 Formily 的 effect hooks,但作为 DSL 枚举而非自由字符串)。
|
|
4
|
+
* 时机进类型系统之后,「什么时候触发」不再是拼写正确才生效的字符串。
|
|
5
|
+
*/
|
|
6
|
+
export declare const SOMA_REACTION_PHASES: readonly ["field_init", "field_mount", "field_unmount", "field_value_change", "field_input_change", "field_validate_start", "field_validate_end", "field_validate_failed", "field_validate_success", "form_submit_start", "form_submit_end"];
|
|
7
|
+
export type SomaReactionPhase = typeof SOMA_REACTION_PHASES[number];
|
|
8
|
+
/**
|
|
9
|
+
* 显示三态(Formily `display` 的对位物)。
|
|
10
|
+
*
|
|
11
|
+
* `hidden` 与 `none` 的差别在**提交载荷**上:前者字段还在 values 里(只是不给看),
|
|
12
|
+
* 后者连数据一起摘除。用一个布尔 `visible` 表达不了这件事,而后端收到一份
|
|
13
|
+
* 「隐藏了但仍然提交」的脏数据时,前端这边一点迹象都没有。
|
|
14
|
+
*/
|
|
15
|
+
export declare const SOMA_FIELD_DISPLAYS: readonly ["visible", "hidden", "none"];
|
|
16
|
+
export type SomaFieldDisplay = typeof SOMA_FIELD_DISPLAYS[number];
|
|
17
|
+
/** 可编辑四态(Formily `pattern` 的对位物),与显示三态**正交** */
|
|
18
|
+
export declare const SOMA_FIELD_PATTERNS: readonly ["editable", "disabled", "read_only", "read_pretty"];
|
|
19
|
+
export type SomaFieldPattern = typeof SOMA_FIELD_PATTERNS[number];
|
|
20
|
+
/** 值 patch:清空 / 复制另一个字段 / 走 calc 算 —— 三种,没有第四种(没有 `run`) */
|
|
21
|
+
export type SomaFieldValuePatch = 'clear' | {
|
|
22
|
+
from: string;
|
|
23
|
+
} | {
|
|
24
|
+
calc: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 封闭 patch 集。
|
|
28
|
+
*
|
|
29
|
+
* 这里是 Formily `fulfill.state` 的对位物,**刻意删掉了 `run`**——那是它的逃生舱,
|
|
30
|
+
* 也是它必须带 eval 的原因。八个键各自一句话说得清,且每个都能在解析期与字段类型配对。
|
|
31
|
+
*/
|
|
32
|
+
export interface SomaFieldStatePatch {
|
|
33
|
+
/** 语法糖:true → visible,false → hidden(要摘数据请显式写 display: none) */
|
|
34
|
+
visible?: boolean;
|
|
35
|
+
display?: SomaFieldDisplay;
|
|
36
|
+
pattern?: SomaFieldPattern;
|
|
37
|
+
required?: boolean;
|
|
38
|
+
value?: SomaFieldValuePatch;
|
|
39
|
+
/** 枚举源切换:'<对象>.<字段>' */
|
|
40
|
+
options?: {
|
|
41
|
+
from: string;
|
|
42
|
+
};
|
|
43
|
+
/** 覆盖该字段的提示文案 */
|
|
44
|
+
message?: string;
|
|
45
|
+
}
|
|
46
|
+
/** 表单级 patch(不挂在任何字段上) */
|
|
47
|
+
export interface SomaFormStatePatch {
|
|
48
|
+
submit?: {
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface SomaReactionConfig {
|
|
53
|
+
/** 条件;与 `depends` 至少给一个(否则这条反应永远不知道何时该跑) */
|
|
54
|
+
when?: SomaFieldPredicate;
|
|
55
|
+
/** 显式依赖:`when` 之外还要盯着的字段(`calc` 的引用会自动并入,不必重复写) */
|
|
56
|
+
depends?: string[];
|
|
57
|
+
/** 缺省 `field_value_change` */
|
|
58
|
+
on?: SomaReactionPhase;
|
|
59
|
+
/** 仅 `field_validate_*` 时有意义:盯着哪个字段的校验结果 */
|
|
60
|
+
target?: string;
|
|
61
|
+
fulfill?: Record<string, SomaFieldStatePatch | SomaFormStatePatch>;
|
|
62
|
+
otherwise?: Record<string, SomaFieldStatePatch | SomaFormStatePatch>;
|
|
63
|
+
}
|
|
64
|
+
/** 表单级 patch 在 fulfill/otherwise 里用的保留键 */
|
|
65
|
+
export declare const SOMA_REACTION_FORM_KEY = "submit";
|
|
66
|
+
/** 编译后的单条反应 */
|
|
67
|
+
export interface SomaCompiledReaction {
|
|
68
|
+
/** 拓扑序下标 */
|
|
69
|
+
index: number;
|
|
70
|
+
/** 声明序(错误信息用:作者看的是自己写的顺序,不是拓扑序) */
|
|
71
|
+
declaredAt: number;
|
|
72
|
+
/** 入边:`when` 字段 ∪ `depends` ∪ `calc` 引用(去重) */
|
|
73
|
+
reads: readonly string[];
|
|
74
|
+
/** 出边:`fulfill` / `otherwise` 的字段键(不含 submit) */
|
|
75
|
+
writes: readonly string[];
|
|
76
|
+
phase: SomaReactionPhase;
|
|
77
|
+
config: SomaReactionConfig;
|
|
78
|
+
/** 预解析的 calc AST(避免每次求值重新解析):`<字段>` → AST */
|
|
79
|
+
calcAsts: Readonly<Record<string, unknown>>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 字段回溯:这个字段的状态是谁写的、依据什么、数据从哪来。
|
|
83
|
+
*
|
|
84
|
+
* amis 的 `${x}` 只能沿运行时链向上找,给不出这张表;这是「可静态回溯」的落点。
|
|
85
|
+
*/
|
|
86
|
+
export interface SomaFieldProvenance {
|
|
87
|
+
/** 写它的反应(声明序下标) */
|
|
88
|
+
writtenBy: readonly number[];
|
|
89
|
+
/** 传递闭包内的全部上游字段 */
|
|
90
|
+
readsFrom: readonly string[];
|
|
91
|
+
/** 该字段来自读通道的哪个接口(`from[].api`);派生字段为 undefined */
|
|
92
|
+
sourceApi?: string;
|
|
93
|
+
}
|
|
94
|
+
/** 编译产物 */
|
|
95
|
+
export interface SomaReactionGraph {
|
|
96
|
+
/** 已按拓扑序排列 */
|
|
97
|
+
reactions: readonly SomaCompiledReaction[];
|
|
98
|
+
/** 字段 → 读它的反应在 `reactions` 里的下标(受影响子图的入口) */
|
|
99
|
+
byField: Readonly<Record<string, readonly number[]>>;
|
|
100
|
+
/** 字段 → 回溯信息 */
|
|
101
|
+
provenance: Readonly<Record<string, SomaFieldProvenance>>;
|
|
102
|
+
}
|
|
103
|
+
/** 一次求值的产物 */
|
|
104
|
+
export interface SomaReactionResult {
|
|
105
|
+
/** 字段 → 合并后的 patch(后写的赢,与声明序一致) */
|
|
106
|
+
patches: Readonly<Record<string, SomaFieldStatePatch>>;
|
|
107
|
+
/** 表单级 patch */
|
|
108
|
+
form: SomaFormStatePatch;
|
|
109
|
+
/** 应用 value patch 之后的值(新对象,不改入参) */
|
|
110
|
+
values: Record<string, unknown>;
|
|
111
|
+
/** 被 `display: none` 摘除的字段(写通道据此剔除请求体) */
|
|
112
|
+
detached: readonly string[];
|
|
113
|
+
/** 传播步数——图无环时必然有界,作为 RG-5 的断言面 */
|
|
114
|
+
steps: number;
|
|
115
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { SomaFieldPredicate } from '../predicates';
|
|
2
|
+
import type { ParsedEvent } from './event.types';
|
|
3
|
+
/** 出错之后怎么走:停 / 继续 / 跳到第 n 步(只许向后,见 AO-1) */
|
|
4
|
+
export type SomaStepOnError = 'stop' | 'continue' | `goto:${number}`;
|
|
5
|
+
/** 单步:一条管道 + 可选的条件、输出槽与错误去向 */
|
|
6
|
+
export interface SomaDoStep {
|
|
7
|
+
when?: SomaFieldPredicate;
|
|
8
|
+
do: string;
|
|
9
|
+
output?: string;
|
|
10
|
+
on_error?: SomaStepOnError;
|
|
11
|
+
}
|
|
12
|
+
/** 分支:取第一个成立的 `when`;`otherwise` 可选且只能有一个、且必须在末尾 */
|
|
13
|
+
export interface SomaSwitchStep {
|
|
14
|
+
when?: SomaFieldPredicate;
|
|
15
|
+
switch: Array<{
|
|
16
|
+
when?: SomaFieldPredicate;
|
|
17
|
+
otherwise?: true;
|
|
18
|
+
do: string;
|
|
19
|
+
output?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/** 并行:分支之间**不许互引输出槽**(互引就意味着有顺序,那它就不是并行) */
|
|
23
|
+
export interface SomaParallelStep {
|
|
24
|
+
parallel: SomaStep[];
|
|
25
|
+
}
|
|
26
|
+
/** 遍历:`over` 必须是有界的(数组型输出槽或事件载荷里的数组) */
|
|
27
|
+
export interface SomaForEachStep {
|
|
28
|
+
for_each: {
|
|
29
|
+
over: string;
|
|
30
|
+
as: string;
|
|
31
|
+
steps: SomaStep[];
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export type SomaStep = SomaDoStep | SomaSwitchStep | SomaParallelStep | SomaForEachStep;
|
|
35
|
+
/** 输出槽:本次事件内的具名中间结果 */
|
|
36
|
+
export interface SomaStepSlot {
|
|
37
|
+
/** 声明它的步骤序号(引用只许向后,见 AO-2) */
|
|
38
|
+
declaredAt: number;
|
|
39
|
+
/** 产出它的动作类型,用于「这个槽是不是数组」这类判断 */
|
|
40
|
+
producedBy: string;
|
|
41
|
+
/** 是否已知为数组(`for_each.over` 只认这种) */
|
|
42
|
+
bounded: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** 编译后的一步:管道已解析,条件已校验 */
|
|
45
|
+
export interface SomaCompiledStep {
|
|
46
|
+
index: number;
|
|
47
|
+
kind: 'do' | 'switch' | 'parallel' | 'for_each';
|
|
48
|
+
when?: SomaFieldPredicate;
|
|
49
|
+
/** kind='do' */
|
|
50
|
+
pipeline?: Omit<ParsedEvent, 'somaId' | 'domEvent'>;
|
|
51
|
+
output?: string;
|
|
52
|
+
onError: SomaStepOnError;
|
|
53
|
+
/** kind='switch' */
|
|
54
|
+
branches?: Array<{
|
|
55
|
+
when?: SomaFieldPredicate;
|
|
56
|
+
otherwise: boolean;
|
|
57
|
+
pipeline: Omit<ParsedEvent, 'somaId' | 'domEvent'>;
|
|
58
|
+
output?: string;
|
|
59
|
+
}>;
|
|
60
|
+
/** kind='parallel' / 'for_each' */
|
|
61
|
+
children?: SomaCompiledStep[];
|
|
62
|
+
/** kind='for_each' */
|
|
63
|
+
over?: string;
|
|
64
|
+
as?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 编译产物:纯数据,可画、可 diff、可进目录快照(AO-4)。
|
|
68
|
+
*
|
|
69
|
+
* `edges` 是顺序边与 `goto` 边的并集——它存在的唯一理由是**能被画出来**:
|
|
70
|
+
* 一张编排图如果只能靠读 YAML 想象,那它和写在代码里的 handler 没有区别。
|
|
71
|
+
*/
|
|
72
|
+
export interface SomaStepGraph {
|
|
73
|
+
steps: SomaCompiledStep[];
|
|
74
|
+
slots: Record<string, SomaStepSlot>;
|
|
75
|
+
edges: Array<[number, number]>;
|
|
76
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { OnChangeRule } from './watcher.types';
|
|
2
2
|
import type { SomaAdaptiveConfig } from './adaptive.types';
|
|
3
|
+
import type { SomaPageStateConfig } from './page-state.types';
|
|
4
|
+
import type { SomaLayoutConstraint } from './layout-constraint.types';
|
|
3
5
|
/**
|
|
4
6
|
* 作用域声明
|
|
5
7
|
* 定义数据源路径和当前作用域别名
|
|
@@ -90,6 +92,22 @@ export interface UiConfig {
|
|
|
90
92
|
* 所以此键必须保持可选,且缺席时不得在下游产生任何默认值。
|
|
91
93
|
*/
|
|
92
94
|
adaptive?: SomaAdaptiveConfig;
|
|
95
|
+
/**
|
|
96
|
+
* 页面态切片声明(REQ-010 F-37,保留键,可选)。
|
|
97
|
+
* 与 `adaptive` 同一条纪律:未声明时编译产物与迁移前字节级一致。
|
|
98
|
+
*/
|
|
99
|
+
state?: SomaPageStateConfig;
|
|
100
|
+
/**
|
|
101
|
+
* 约束布局声明(REQ-010 S3 / REQ-011 接线,保留键,可选):锚点 id → 一行的约束。
|
|
102
|
+
*
|
|
103
|
+
* 这是**声明**;它的产物是 `layoutCss`。求解只在构建期(`compilePageDeclaration`)发生,
|
|
104
|
+
* 运行时收到的是已经解好的 CSS(`layout_css`),浏览器一行 JS 都不用算。
|
|
105
|
+
* 运行时若收到的是 `layout` 而不是 `layout_css`,说明页面没走构建期编译——
|
|
106
|
+
* 引擎只告警、不求解(CL-4:求解器不进 client)。
|
|
107
|
+
*/
|
|
108
|
+
layout?: Record<string, SomaLayoutConstraint>;
|
|
109
|
+
/** 构建期求解产物:只含容器查询 + flex 的 CSS(CL-2),运行时按页注入一次 */
|
|
110
|
+
layoutCss?: string;
|
|
93
111
|
}
|
|
94
112
|
/**
|
|
95
113
|
* 解析后的 show 条目
|