soma-core 1.4.0 → 1.4.2

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.
Files changed (132) hide show
  1. package/README.md +1 -1
  2. package/core/build/blocks/block-compile.ts +31 -2
  3. package/core/build/blocks/block-container.ts +2 -11
  4. package/core/build/compiler/page-declaration-compiler.ts +30 -2
  5. package/core/build/compiler/soma-precompile.js +2053 -23
  6. package/core/build/component/component-graph.ts +208 -0
  7. package/core/build/component/package-loader.ts +32 -0
  8. package/core/build/eject/component-eject.ts +473 -0
  9. package/core/build/eject/component-upgrade.ts +359 -0
  10. package/core/build/layout/constraint-solver.ts +235 -0
  11. package/core/build/layout/css-emitter.ts +116 -0
  12. package/core/build/layout/page-layout.ts +85 -0
  13. package/core/build/pack/pack-init.ts +270 -0
  14. package/core/client/base/SomaHttpClient.ts +34 -1
  15. package/core/client/base/SomaPageRootBase.ts +61 -0
  16. package/core/client/component/ai-catalog.ts +121 -4
  17. package/core/client/component/component-defaults.ts +100 -0
  18. package/core/client/component/component-definition.types.ts +39 -0
  19. package/core/client/component/component-manager.ts +79 -4
  20. package/core/client/component/component-pack.ts +126 -2
  21. package/core/client/component/keyboard-matrix.ts +144 -0
  22. package/core/client/component/pack-styles.ts +59 -1
  23. package/core/client/component/style-features.ts +131 -0
  24. package/core/client/component/theme-component-tokens.ts +83 -0
  25. package/core/client/component/verify-pack.ts +120 -1
  26. package/core/client/container/SomaContainerAdapter.ts +6 -2
  27. package/core/client/data/data-object-resolver.ts +407 -4
  28. package/core/client/data/reaction-engine.ts +176 -0
  29. package/core/client/data/window-engine.ts +477 -0
  30. package/core/client/engine/event-engine.ts +98 -0
  31. package/core/client/engine/soma-bootstrap.ts +265 -5
  32. package/core/client/engine/step-runner.ts +134 -0
  33. package/core/client/infra/http/SomaHttpService.ts +2 -2
  34. package/core/client/parser/blocks/page-parser.ts +15 -1
  35. package/core/client/parser/blocks/use-parser.ts +5 -12
  36. package/core/client/parser/data-config-parser.ts +316 -8
  37. package/core/client/parser/duration.ts +16 -0
  38. package/core/client/parser/layout-parser.ts +157 -0
  39. package/core/client/parser/page-state-parser.ts +166 -0
  40. package/core/client/parser/pipeline-parser.ts +76 -1
  41. package/core/client/parser/reaction-parser.ts +459 -0
  42. package/core/client/parser/reaction-sugar.ts +47 -0
  43. package/core/client/parser/step-parser.ts +359 -0
  44. package/core/client/parser/ui-config-parser.ts +59 -0
  45. package/core/client/parser/window-parser.ts +294 -0
  46. package/core/client/theme/theme-engine.ts +102 -2
  47. package/core/index.ts +184 -0
  48. package/core/shared/block-errors.ts +11 -0
  49. package/core/shared/calc/coerce.ts +29 -0
  50. package/core/shared/calc/errors.ts +43 -0
  51. package/core/shared/calc/evaluator.ts +101 -0
  52. package/core/shared/calc/index.ts +12 -0
  53. package/core/shared/calc/lexer.ts +194 -0
  54. package/core/shared/calc/parser.ts +204 -0
  55. package/core/shared/calc/typer.ts +184 -0
  56. package/core/shared/component/derive-sample.ts +105 -0
  57. package/core/shared/component/field-lines.ts +473 -0
  58. package/core/shared/path-algebra.ts +169 -0
  59. package/core/shared/predicates/index.ts +527 -0
  60. package/core/shared/types/component-contract.types.ts +151 -9
  61. package/core/shared/types/data-config.types.ts +120 -1
  62. package/core/shared/types/domain.types.ts +13 -0
  63. package/core/shared/types/event.types.ts +22 -2
  64. package/core/shared/types/layout-constraint.types.ts +73 -0
  65. package/core/shared/types/page-state.types.ts +60 -0
  66. package/core/shared/types/reaction.types.ts +144 -0
  67. package/core/shared/types/step.types.ts +91 -0
  68. package/core/shared/types/ui-config.types.ts +18 -0
  69. package/core/shared/types/window.types.ts +177 -0
  70. package/dist/cli/soma.js +13 -1
  71. package/dist/core/index.cjs +5529 -631
  72. package/dist/types/build/blocks/block-container.d.ts +1 -6
  73. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
  74. package/dist/types/build/component/component-graph.d.ts +85 -0
  75. package/dist/types/build/eject/component-eject.d.ts +121 -0
  76. package/dist/types/build/eject/component-upgrade.d.ts +43 -0
  77. package/dist/types/build/layout/constraint-solver.d.ts +36 -0
  78. package/dist/types/build/layout/css-emitter.d.ts +18 -0
  79. package/dist/types/build/layout/page-layout.d.ts +24 -0
  80. package/dist/types/build/pack/pack-init.d.ts +8 -0
  81. package/dist/types/client/base/SomaHttpClient.d.ts +8 -0
  82. package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
  83. package/dist/types/client/component/ai-catalog.d.ts +33 -1
  84. package/dist/types/client/component/component-defaults.d.ts +15 -0
  85. package/dist/types/client/component/component-definition.types.d.ts +38 -0
  86. package/dist/types/client/component/component-manager.d.ts +36 -0
  87. package/dist/types/client/component/component-pack.d.ts +32 -2
  88. package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
  89. package/dist/types/client/component/pack-styles.d.ts +21 -0
  90. package/dist/types/client/component/style-features.d.ts +26 -0
  91. package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
  92. package/dist/types/client/component/verify-pack.d.ts +10 -0
  93. package/dist/types/client/data/data-object-resolver.d.ts +106 -1
  94. package/dist/types/client/data/reaction-engine.d.ts +21 -0
  95. package/dist/types/client/data/window-engine.d.ts +27 -0
  96. package/dist/types/client/engine/event-engine.d.ts +15 -0
  97. package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
  98. package/dist/types/client/engine/step-runner.d.ts +24 -0
  99. package/dist/types/client/parser/blocks/use-parser.d.ts +2 -2
  100. package/dist/types/client/parser/duration.d.ts +1 -0
  101. package/dist/types/client/parser/layout-parser.d.ts +9 -0
  102. package/dist/types/client/parser/page-state-parser.d.ts +32 -0
  103. package/dist/types/client/parser/reaction-parser.d.ts +16 -0
  104. package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
  105. package/dist/types/client/parser/step-parser.d.ts +23 -0
  106. package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
  107. package/dist/types/client/parser/window-parser.d.ts +25 -0
  108. package/dist/types/client/theme/theme-engine.d.ts +26 -0
  109. package/dist/types/index.d.ts +35 -2
  110. package/dist/types/shared/block-errors.d.ts +5 -0
  111. package/dist/types/shared/calc/coerce.d.ts +4 -0
  112. package/dist/types/shared/calc/errors.d.ts +14 -0
  113. package/dist/types/shared/calc/evaluator.d.ts +2 -0
  114. package/dist/types/shared/calc/index.d.ts +6 -0
  115. package/dist/types/shared/calc/lexer.d.ts +20 -0
  116. package/dist/types/shared/calc/parser.d.ts +49 -0
  117. package/dist/types/shared/calc/typer.d.ts +16 -0
  118. package/dist/types/shared/component/derive-sample.d.ts +23 -0
  119. package/dist/types/shared/component/field-lines.d.ts +19 -0
  120. package/dist/types/shared/path-algebra.d.ts +56 -0
  121. package/dist/types/shared/predicates/index.d.ts +79 -0
  122. package/dist/types/shared/types/component-contract.types.d.ts +134 -6
  123. package/dist/types/shared/types/data-config.types.d.ts +115 -1
  124. package/dist/types/shared/types/domain.types.d.ts +12 -0
  125. package/dist/types/shared/types/event.types.d.ts +8 -2
  126. package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
  127. package/dist/types/shared/types/page-state.types.d.ts +49 -0
  128. package/dist/types/shared/types/reaction.types.d.ts +115 -0
  129. package/dist/types/shared/types/step.types.d.ts +76 -0
  130. package/dist/types/shared/types/ui-config.types.d.ts +18 -0
  131. package/dist/types/shared/types/window.types.d.ts +171 -0
  132. package/package.json +3 -2
@@ -1,7 +1,7 @@
1
1
  // 组件契约类型 — 组件体系(模块 7)
2
2
  // 契约是组件的唯一事实源,规范见 soma-ui/doc/soma 组件契约.md。
3
- // 本文件为 P0 可执行子集:props / emits / slots;
4
- // variants / states / tokens 随 P1 契约编译器落地时补充。
3
+ // 本文件为 P0 可执行子集:props / emits / slots / tokens;
4
+ // variants / states 随状态编译器落地时补充(tokens 已由 REQ-009 M-1 落地)。
5
5
 
6
6
  // solution:业务组件层(atom/composite 之上)——把一类业务场景整套打包,一个声明落一个完整业务功能
7
7
  export type SomaComponentLayer = 'atom' | 'composite' | 'solution' | 'template';
@@ -30,15 +30,34 @@ export type SomaContractPropType =
30
30
  | 'object'
31
31
  | 'array';
32
32
 
33
- export interface SomaContractProp {
33
+ /**
34
+ * 字段(REQ-012)。
35
+ *
36
+ * prop、对象里的字段、数组元素、事件载荷是同一种东西,所以只有这一个形状,递归到底:
37
+ * `type: object` 用 `fields` 继续描述,`type: array` 用 `items` 描述元素。
38
+ *
39
+ * 为什么要 `example` 而不是靠 `default`:规则 C4 要求可选 prop 有默认值,而默认值按
40
+ * C4a 必须是空串 / 空数组这类浅结构——拿它渲染出来的永远是空态。展示页、视觉矩阵与
41
+ * AI 需要的是「这个字段真实长什么样」,那是另一个值,必须另有一处写。
42
+ */
43
+ export interface SomaContractField {
34
44
  type: SomaContractPropType;
45
+ desc?: string;
35
46
  required?: boolean;
36
47
  /** 非 required 的 prop 必须有默认值(契约规则 C4:零 props 可渲染) */
37
48
  default?: unknown;
38
- desc?: string;
49
+ /** 示例值(REQ-012):样张与展示页的数据来源;不参与运行时,只被派生与目录消费 */
50
+ example?: unknown;
39
51
  /** type === 'enum' 时的取值集合 */
40
52
  values?: (string | number)[];
41
- /** 绑定模式:oneway(默认)| model(双向,一个组件最多一个) */
53
+ /** type === 'object' 时的子字段(REQ-012) */
54
+ fields?: Record<string, SomaContractField>;
55
+ /** type === 'array' 时的元素形状(REQ-012) */
56
+ items?: SomaContractField;
57
+ }
58
+
59
+ export interface SomaContractProp extends SomaContractField {
60
+ /** 绑定模式:oneway(默认)| model(双向,一个组件最多一个)。只在 prop 一层有意义 */
42
61
  mode?: 'oneway' | 'model';
43
62
  }
44
63
 
@@ -67,10 +86,7 @@ export function findNestedMutableContractDefault(value: unknown): string | null
67
86
  return null;
68
87
  }
69
88
 
70
- export interface SomaContractEmitPayloadField {
71
- type: SomaContractPropType;
72
- desc?: string;
73
- }
89
+ export interface SomaContractEmitPayloadField extends SomaContractField {}
74
90
 
75
91
  export interface SomaContractEmit {
76
92
  payload?: Record<string, SomaContractEmitPayloadField>;
@@ -82,6 +98,23 @@ export interface SomaContractSlot {
82
98
  required?: boolean;
83
99
  }
84
100
 
101
+ /**
102
+ * 组件级令牌(三级令牌的第三级,REQ-009 M-1)。
103
+ *
104
+ * 为什么是「组件自己声明旋钮」而不是 MUI 的 `styleOverrides.<slot>`:
105
+ * 后者要求 Host 知道组件内部结构,而 `scopeAnchors()` 刻意让页面永不可寻址组件内部。
106
+ * 组件声明可调令牌 = 组件自己承诺「这几个值可以被外面改,改了不会散架」,
107
+ * 内部结构仍然封闭。
108
+ *
109
+ * `default` 必须形如 `var(--soma-…)`:组件令牌是语义令牌的**别名与收窄**,
110
+ * 不是新的真源。写裸值等于在组件里开一个绕过主题的后门。
111
+ */
112
+ export interface SomaContractToken {
113
+ /** 必须引用语义令牌:var(--soma-…),可带回退值 */
114
+ default: string;
115
+ desc: string;
116
+ }
117
+
85
118
  /**
86
119
  * AI 目录段(契约规范第 11 章):AI 生成页面前查表选组件的依据。
87
120
  * when_to_use / example 为目录质量线;when_not_to_use 用于同族组件消歧。
@@ -106,6 +139,11 @@ export interface SomaComponentContract {
106
139
  props?: Record<string, SomaContractProp>;
107
140
  emits?: Record<string, SomaContractEmit>;
108
141
  slots?: Record<string, SomaContractSlot>;
142
+ /**
143
+ * 组件级令牌:key 为 kebab-case,装配期写出 `--soma-<组件名 kebab>-<key>`。
144
+ * 主题输入的 `components.<组件名>.<key>` 覆盖它,`ThemeScope` 可按子树覆盖。
145
+ */
146
+ tokens?: Record<string, SomaContractToken>;
109
147
  ai?: SomaContractAiSection;
110
148
  /**
111
149
  * 声明式覆盖:本组件有意替换该包里的同名组件(值为被覆盖组件的来源包名,如 'soma-ui')。
@@ -117,4 +155,108 @@ export interface SomaComponentContract {
117
155
  * 未声明的跨包撞名一律抛错——写出来的覆盖是设计决定,猜出来的覆盖是事故。
118
156
  */
119
157
  overrides?: string;
158
+ /**
159
+ * 依赖的其它组件(REQ-010 F-46):PascalCase 契约名数组。
160
+ *
161
+ * 两件事靠它:
162
+ * ① **按图拉齐**——`soma pack init` / eject 一个 TreeSelect 时能知道它还要 Tree,
163
+ * 而不是等页面渲染出一堆没样式的节点才发现(这条曾真实发生过:
164
+ * `COMPONENT_CSS_DEPS` 少写一条 `TreeSelect: ['Tree']`,页面上是无样式的折叠箭头);
165
+ * ② **可寻址目录**——`registry.json` 的每一项带版本、哈希与依赖,
166
+ * 于是"我这份是从哪一版来的、它还需要谁"两个问题都有答案。
167
+ * shadcn 的 registry 两个都没有。
168
+ *
169
+ * 只登记**契约级**依赖(模板里真的嵌了那个组件、或 CSS 分片依赖它),
170
+ * 不登记共享资产(`shared/*` 由构建图自然带上,写进来只会重复一份且会漂)。
171
+ */
172
+ uses?: string[];
173
+ /**
174
+ * 浮层行为契约(REQ-010 F-41 / F-42)。
175
+ *
176
+ * 声明而不是各组件自写:十几个浮层组件里的"点外面关不关""Esc 关不关"
177
+ * "退场动画放完再卸载"此前各有一份实现,而它们的差异只在某个具体组件上暴露
178
+ * (某个下拉点外面不关、某个抽屉 Esc 无效)。收成契约之后,
179
+ * 引擎按声明接线,组件不再碰这些代码。
180
+ */
181
+ overlay?: SomaContractOverlay;
182
+ /**
183
+ * 键盘契约(REQ-010 F-43)。
184
+ *
185
+ * 声明这是个什么布局(列表 / 网格 / 树),引擎据此挑键盘委托并接上方向键。
186
+ * 组件因此删掉自写的方向键分支——六个组件曾各写一套,最后一行按 ↓ 的行为各不相同。
187
+ * 另一个收益:**键盘矩阵能自动进目录**,AI 与业务开发者不必读源码才知道按键表。
188
+ */
189
+ keyboard?: SomaContractKeyboard;
190
+ }
191
+
192
+ /** 浮层行为的封闭词汇 */
193
+ export interface SomaContractOverlay {
194
+ /** 浮层类型:决定默认的模态性与回焦策略 */
195
+ kind: 'popup' | 'modal' | 'non_modal' | 'toast';
196
+ /**
197
+ * Esc 的行为。`defer` 表示交给外层——嵌套浮层里,内层已经处理过就不该再传。
198
+ * 显式三档而不是布尔:`false` 与 `defer` 的差别正是"吞掉"与"让出去"。
199
+ */
200
+ escape_key_behavior?: 'close' | 'none' | 'defer';
201
+ /** 点外面关不关;`ignore` 用于必须显式操作才能关的对话框 */
202
+ outside_press_behavior?: 'close' | 'ignore';
203
+ /** 退场动画放完再卸载(F-42):不挂起的话,关闭动画根本看不见 */
204
+ presence?: boolean;
205
+ /** 打开时把外部标 aria-hidden(F-44);模态默认真 */
206
+ hide_outside?: boolean;
207
+ /** 关闭后把焦点还给触发者;默认真 */
208
+ restore_focus?: boolean;
120
209
  }
210
+
211
+ /** 键盘导航的封闭词汇 */
212
+ export interface SomaContractKeyboard {
213
+ /** 布局形态:决定挑哪个键盘委托 */
214
+ layout: 'list' | 'grid' | 'tree' | 'none';
215
+ /** 网格列数;`layout: grid` 时必填(DOM 上看不出来,猜错就跳到无关格子) */
216
+ columns?: number;
217
+ /** 到边之后回绕还是停住 */
218
+ wrap?: boolean;
219
+ /** 首字母跳转 */
220
+ typeahead?: boolean;
221
+ /** 焦点模型:漫游 tabindex 还是 aria-activedescendant */
222
+ focus_model?: 'roving' | 'activedescendant';
223
+ /** 选中随焦点移动(单选列表的常见形态) */
224
+ selection_follows_focus?: boolean;
225
+ /**
226
+ * 主轴方向:横向时 ←/→ 走上一项/下一项(tablist、菜单栏),RTL 下自动换向;
227
+ * 缺省纵向(↑/↓);`both` 是 APG 单选组的形态——两轴都走同一条链
228
+ * (排成一行还是一列只是 CSS 的事,键盘用户不该先猜方向)。网格两轴各有语义,本项无意义。
229
+ */
230
+ orientation?: 'horizontal' | 'vertical' | 'both';
231
+ /**
232
+ * 空格的语义:`activate`(与 Enter 同义,单选列表 / 树 / 选项卡)、
233
+ * `toggle_select`(勾选当前项而不确认,多选 listbox / 穿梭框)或
234
+ * `none`(这个键不归本组件——触发器是原生 button 的下拉就属这种:
235
+ * Space 是按钮自己的"按下",抢过来会变成"选中一项的同时又把面板重新打开")。缺省 `activate`。
236
+ * 显式三档而不是从别的字段推:Space 在多选列表里按成"确认"会把用户刚勾的东西直接提交出去,
237
+ * 而在按钮触发的下拉里按成"确认"会和浏览器的按钮语义打架。
238
+ */
239
+ space?: 'activate' | 'toggle_select' | 'none';
240
+ /**
241
+ * 组件特有的按键(引擎矩阵之外):按键 → 说明。例如 Tabs 的 `Delete: 关闭当前项`、
242
+ * Tree 的 `Alt+方向键: 搬运节点`。**只进目录,不由引擎接线**——组件自己处理,
243
+ * 但键盘表必须完整:读目录的人(与 AI)不该只看到一半的按键。
244
+ */
245
+ extra?: Record<string, string>;
246
+ }
247
+
248
+
249
+ /** PascalCase 组件名 → 令牌前缀用的 kebab-case(DataTable → data-table) */
250
+ export function componentTokenPrefix(name: string): string {
251
+ return name
252
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
253
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
254
+ .toLowerCase();
255
+ }
256
+
257
+ /** 组件令牌的 CSS 变量名:Button + radius → --soma-button-radius */
258
+ export function componentTokenVar(componentName: string, tokenKey: string): string {
259
+ return `--soma-${componentTokenPrefix(componentName)}-${tokenKey}`;
260
+ }
261
+
262
+ export const COMPONENT_TOKEN_KEY_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
@@ -1,4 +1,8 @@
1
1
  // core/shared/types/data-config.types.ts — 数据对象层(*_data.yaml)类型定义
2
+
3
+ import type { SomaNamedPredicates } from '../predicates';
4
+ import type { SomaReactionGraph } from './reaction.types';
5
+ import type { SomaWindowConfig, SomaWindowHandle } from './window.types';
2
6
  // 对应《soma 数据对象层》第 2/3 节:数据对象声明 + 字段字典。
3
7
  // 数据对象是业务抽象出的命名数据(如 order),来源是一个或多个后端接口;
4
8
  // 组件与页面只认对象与字段,不认接口协议。
@@ -27,7 +31,18 @@ export type SomaDataFieldType =
27
31
  // 以下三型原本只在块声明侧存在,收编进唯一真源:
28
32
  // percent 与 progress 是同一份数据的两种读法(前者出文字、后者出进度条)
29
33
  | 'percent'
30
- | 'progress';
34
+ | 'progress'
35
+ // 以下四型随 REQ-009 F-15 进表:它们此前只能写成 text,于是「多值标签、附件、
36
+ // 树形归属、级联路径」四类字段在字典里全部塌成同一个单行输入框。
37
+ // 有了自己的类型,双态映射才能把它们分别接到 TagInput / Upload / TreeSelect / Cascader。
38
+ /** 多值标签(string[])→ TagInput */
39
+ | 'tags'
40
+ /** 附件(文件列表或文件地址)→ Upload */
41
+ | 'file'
42
+ /** 树形单选(options 为节点集)→ TreeSelect */
43
+ | 'tree'
44
+ /** 级联路径(string[],从根到叶)→ Cascader */
45
+ | 'cascade';
31
46
 
32
47
  /**
33
48
  * 类型别名:块声明历史上用 `number` 表示小数,与本表的 `float` 同义。
@@ -42,6 +57,7 @@ export const SOMA_DATA_FIELD_TYPE_ALIASES: Readonly<Record<string, SomaDataField
42
57
  export const SOMA_DATA_FIELD_TYPES: readonly string[] = [
43
58
  'text', 'int', 'float', 'money', 'bool', 'enum', 'date', 'datetime',
44
59
  'image', 'url', 'richtext', 'percent', 'progress',
60
+ 'tags', 'file', 'tree', 'cascade',
45
61
  ...Object.keys(SOMA_DATA_FIELD_TYPE_ALIASES),
46
62
  ];
47
63
 
@@ -89,6 +105,15 @@ export interface SomaDataFieldConfig {
89
105
  rules?: SomaDataFieldRule[];
90
106
  /** 枚举候选项 */
91
107
  options?: SomaDataFieldOption[];
108
+ /**
109
+ * 派生列(REQ-010 S2 / F-10):`"[revenue] - [cost]"`。
110
+ *
111
+ * 这是 AG Grid `valueGetter` 的封闭降级:那边是一个任意函数,这边是受限文法
112
+ * (方括号引用同对象字段、四则、比较、六个函数),解析期能推出结果类型并与声明的
113
+ * `type` 对账。声了 `calc` 的字段**权限恒为 r**——它是算出来的,写它没有意义,
114
+ * 而"写了没反应"是最难查的一类。
115
+ */
116
+ calc?: string;
92
117
  }
93
118
 
94
119
  /**
@@ -105,6 +130,46 @@ export interface SomaDataSourceConfig {
105
130
  into?: string;
106
131
  }
107
132
 
133
+ /** 写通道的一个端点:接口 + 方法(《数据对象层》§8.2) */
134
+ export interface SomaDataWriteEndpoint {
135
+ /** 后端接口路径(后端接口是唯一数据边界) */
136
+ api: string;
137
+ /** HTTP 方法;白名单 POST / PUT / PATCH */
138
+ method: 'POST' | 'PUT' | 'PATCH';
139
+ }
140
+
141
+ /**
142
+ * 写通道声明(REQ-009 M-5,《数据对象层》§8)。
143
+ *
144
+ * 读通道早已统一(from / transform / fields 走 SomaDataObjectResolver),
145
+ * 而写路径此前仍是组件直连:FormConsole 在 props 里自带 fields + submit_api + load_api,
146
+ * 于是字段与校验在 `_data.yaml` 和组件 props 各存一份,字典事实源分裂;
147
+ * 提交编排(收值 / 校验 / 调接口 / 错误呈现)每个自治组件各写一遍。
148
+ *
149
+ * 目标:**一份 `_data.yaml` 覆盖读 + 写,组件只说"我消费哪个对象"**。
150
+ */
151
+ export interface SomaDataWriteConfig {
152
+ /** 新建端点(create / update 至少给一个) */
153
+ create?: SomaDataWriteEndpoint;
154
+ /** 更新端点 */
155
+ update?: SomaDataWriteEndpoint;
156
+ /** 乐观锁字段名(必须在字典里;它是唯一允许随请求体上行的 r 字段) */
157
+ version?: string;
158
+ /** 表单键 → 请求体键的平面改名(键必须在字典且非 r 字段) */
159
+ map?: Record<string, string>;
160
+ /**
161
+ * 请求体字段白名单(REQ-010 F-38):只发这几个字段。
162
+ *
163
+ * 与 `permission` 的分工:`permission: r` 说的是「这个字段不可编辑」,
164
+ * 是**字段自身的性质**;`only` 说的是「这次写只送这几个」,是**这条通道的口径**。
165
+ * 用 permission 去表达后者会连带把控件降级成只读文本——那是另一件事。
166
+ * 块声明 `save.fields` 归一到这里。
167
+ */
168
+ only?: string[];
169
+ /** 提交成功后重取:'self' 只重取本对象 / 'all' 全部 / 指定对象名数组 */
170
+ reload?: 'self' | 'all' | string[];
171
+ }
172
+
108
173
  /** 数据对象声明(*_data.yaml 中 data.<对象名> 的解析产物) */
109
174
  export interface SomaDataObjectConfig {
110
175
  /** 对象名(页面内唯一,即 data 下的键名) */
@@ -120,10 +185,64 @@ export interface SomaDataObjectConfig {
120
185
  fields?: Record<string, SomaDataFieldConfig>;
121
186
  /** mock 样本:SOMA_MOCK_ENABLED / 接口失败兜底 / 无接口预览 */
122
187
  mock?: unknown;
188
+ /** 写通道声明(§8);不给 = 该对象只读 */
189
+ write?: SomaDataWriteConfig;
190
+ /**
191
+ * 具名谓词表(REQ-010 S1b):`{ 名字: 谓词 }`。
192
+ * 一条「是否企业客户」声明一次,反应与字段显隐处处 `{ ref: 名字 }` 复用——
193
+ * 复制粘贴出来的那几份,将来必然漏改一份。
194
+ */
195
+ predicates?: SomaNamedPredicates;
196
+ /**
197
+ * 反应图(REQ-010 S1b):字段之间的联动。
198
+ * 解析期已建成 DAG、检过环、算好回溯表——这是 Formily / amis 靠 eval + 运行时
199
+ * 依赖收集换不来的东西。
200
+ */
201
+ reactions?: SomaReactionGraph;
202
+ /**
203
+ * 数据窗口(REQ-010 S2):一屏一屏地取。
204
+ * 声明期已把过滤 AST、排序/分组/聚合的字段引用对着字典校验过,并算好字典哈希。
205
+ */
206
+ window?: SomaWindowConfig;
123
207
  /** 解析期提取:params 引用到的其他数据对象名(DAG 拓扑排序输入,不含自引用) */
124
208
  deps: string[];
125
209
  }
126
210
 
211
+ /** 写通道提交结果:成功带数据,失败带整体文案与字段级错误(§8.3) */
212
+ export type SomaDataSubmitResult =
213
+ | { ok: true; data?: unknown }
214
+ | { ok: false; message: string; fieldErrors?: Record<string, string> };
215
+
216
+ /**
217
+ * 注入给自治组件的数据端口(services 白名单里的 `data`,§8.4)。
218
+ * 复杂度沉引擎:组件只做「收值 → 调 submit → 渲染返回的 fieldErrors」。
219
+ */
220
+ export interface SomaDataPort {
221
+ /** 读态(回填来源) */
222
+ getObject(name: string): unknown;
223
+ /** 字段字典(控件 / 校验来源) */
224
+ getDict(name: string): Record<string, SomaDataFieldConfig>;
225
+ /**
226
+ * 反应图与具名谓词表(REQ-010 S1b):`_data.yaml` 的 `reactions:` / `predicates:` 段。
227
+ * 组件拿它跑 `runReactions`——联动声明在数据对象上,与字段字典同源同一份,
228
+ * 不必在页面 DSL 里再抄一遍。没声明的对象返回 null(= 无联动)。
229
+ */
230
+ getReactions(name: string): { graph: SomaReactionGraph; named: SomaNamedPredicates } | null;
231
+ /**
232
+ * 数据窗口(REQ-010 S2):声了 `window:` 段的对象才有,没有返回 null。
233
+ * 组件拿到它就不再自持 `page / sort_key / filters`——那些裁决收在引擎里只有一份。
234
+ */
235
+ window(name: string): SomaWindowHandle | null;
236
+ /** 写通道:校验 → 构体 → 调接口 → 错误逆映射 → reload */
237
+ submit(
238
+ name: string,
239
+ model: Record<string, unknown>,
240
+ mode?: 'create' | 'update',
241
+ ): Promise<SomaDataSubmitResult>;
242
+ /** 手动重取(等价 Domain 的 _reloadData 细粒度版) */
243
+ reload(names?: string[]): Promise<void>;
244
+ }
245
+
127
246
  /** *_data.yaml 整体解析产物(对象名 → 声明) */
128
247
  export interface SomaDataConfig {
129
248
  objects: Record<string, SomaDataObjectConfig>;
@@ -5,6 +5,8 @@
5
5
  * 页面聚合根接口
6
6
  * 展示对象必须实现此接口,提供页面生命周期钩子
7
7
  */
8
+ import type { SomaPageState, SomaPageStateConfig } from './page-state.types';
9
+
8
10
  export interface SomaPageRoot {
9
11
  /** Content strings from locale.yaml (injected by bootstrap) */
10
12
  _locale?: Record<string, unknown>;
@@ -18,6 +20,17 @@ export interface SomaPageRoot {
18
20
  _reloadData?: () => Promise<void>;
19
21
  /** 重新执行数据对象取数(无声明时为空操作) */
20
22
  reloadData?(): Promise<void>;
23
+ /**
24
+ * 页面态(REQ-010 F-37):排序 / 过滤 / 选择 / 列显隐 / 密度 / 展开。
25
+ * 没声明 `state:` 段时恒为 null——不是空对象:空对象会让调用方以为
26
+ * "有状态,只是都是缺省",于是把它序列化进分享链接,而链接打开后什么都恢复不了。
27
+ */
28
+ _pageState?: SomaPageState | null;
29
+ /** `state:` 段的声明(bootstrap 注入) */
30
+ _pageStateConfig?: SomaPageStateConfig | null;
31
+ getState?(): SomaPageState | null;
32
+ setState?(next: SomaPageState): void;
33
+ onStateUpdated?(listener: (state: SomaPageState) => void): () => void;
21
34
  /** 页面初始化(引擎在渲染完成后调用) */
22
35
  onMount?(): void | Promise<void>;
23
36
  /** 页面销毁前(引擎在卸载时调用) */
@@ -5,23 +5,43 @@
5
5
  * 事件类型枚举
6
6
  * 定义 Pipeline DSL 支持的四种事件处理类型
7
7
  */
8
+ import type { SomaStepGraph } from './step.types';
9
+
8
10
  export type EventType =
9
11
  | 'NAV_STATIC' // 静态页面跳转
10
12
  | 'NAV_ACTION' // 逻辑驱动跳转(先执行函数,成功后跳转)
11
13
  | 'UI_REFRESH' // 数据刷新(执行函数后触发 UI 重新渲染)
12
- | 'UI_INTERACT'; // UI 交互操作(显隐控制)
14
+ | 'UI_INTERACT' // UI 交互操作(显隐、聚焦、滚动、选中)
15
+ // 具名动作(REQ-010 F-20):`ACTION | <名字>`,实现在 bootstrap 的 options.actions 里。
16
+ // 它是 amis `custom(script)` 的替代——同样能接任意 Host 逻辑,但**有名字、要注册、
17
+ // 未注册即抛**,声明层因此仍然零脚本。
18
+ | 'ACTION'
19
+ // 编排事件(REQ-010 F-13):值不是一条管道字符串,而是 `{ steps: [...] }`。
20
+ // 它不能写成管道串——一串步骤没法压进一行竖线分隔的文本,硬压只会得到
21
+ // 一门新的微型语法。所以它只从对象形态来,`parsePipelineBody` 不认它。
22
+ | 'STEPS';
13
23
 
14
24
  /**
15
25
  * UI 交互动作枚举
16
26
  * 用于 UI_INTERACT 类型的动作指令
17
27
  */
18
- export type InteractAction = 'open' | 'close' | 'toggle';
28
+ export type InteractAction =
29
+ | 'open' | 'close' | 'toggle'
30
+ // REQ-010 §4.4 扩容:编排里最常见的三件"看得见的副作用"。
31
+ // 没有它们,「提交完把焦点放回列表」这类事只能回到 Host 代码里写 DOM 操作。
32
+ | 'focus' | 'scroll_to' | 'select';
19
33
 
20
34
  /**
21
35
  * 解析后的事件配置
22
36
  * Pipeline DSL 解析器将 YAML 中的事件声明解析为此结构
23
37
  */
24
38
  export interface ParsedEvent {
39
+ /**
40
+ * 动作编排图(`type === 'STEPS'` 时有)。
41
+ * 解析在 `step-parser`,执行在 `step-runner`;不带它的事件走原来的单管道路径。
42
+ */
43
+ steps?: SomaStepGraph;
44
+
25
45
  /** 目标元素的 data-soma-id 值 */
26
46
  somaId: string;
27
47
 
@@ -0,0 +1,73 @@
1
+ // 约束布局类型(REQ-010 S3)——「这一行里谁让谁」的声明式表达。
2
+ //
3
+ // ── 为什么需要它 ──────────────────────────────────────────────────────
4
+ // 今天写一个「侧栏固定 20rem、正文占满、窄了侧栏先缩到 16rem、再窄就换行」的布局,
5
+ // 要手写四段容器查询并在每一档里各写一遍 flex 值。四段之间的一致性靠人维护,
6
+ // 而它们坏起来是"某一档下侧栏比 min 还窄"——只有把窗口拖到那一档才看得见。
7
+ //
8
+ // Figma 的 Auto Layout 用约束求解表达同一件事(hug / fill / 优先级),
9
+ // 但它在**运行时**求解,因为画布可交互。页面不需要:容器宽度是八档封闭集,
10
+ // 每档一个解就是全部解。所以 SOMA 在**构建期**求解,运行期只剩 CSS。
11
+ // 这是本段的结构性差异——运行期零求解 = 零 JS 成本 + 零布局抖动 + 产物可审计。
12
+
13
+ /** 尺寸意图三档(Auto Layout 的对位物) */
14
+ export type SomaSizing = 'fixed' | 'hug' | 'fill';
15
+
16
+ /**
17
+ * 优先级四档(Auto Layout 惯例):
18
+ * 250 = Content Hugging("我愿意被拉大")、500 = 中庸、
19
+ * 750 = Compression Resistance("我不愿意被压小")、1000 = required(不可违反)。
20
+ *
21
+ * 是四档不是任意整数:优先级只在**相对次序**上有意义,开放成整数只会让人写出
22
+ * 748 与 752 这种自己也说不清差别的值,而它们的差别在求解结果上确实存在。
23
+ */
24
+ export const SOMA_LAYOUT_PRIORITIES = [250, 500, 750, 1000] as const;
25
+ export type SomaPriority = typeof SOMA_LAYOUT_PRIORITIES[number];
26
+
27
+ /** 换行策略:不换 / 窄了就竖排 / 横向滚动成一条卷轴 */
28
+ export type SomaWrap = 'none' | 'below' | 'reel';
29
+
30
+ export const SOMA_LAYOUT_ALIGNS = [
31
+ 'start', 'center', 'end', 'baseline', 'space_between', 'space_evenly', 'space_around',
32
+ ] as const;
33
+ export type SomaAlign = typeof SOMA_LAYOUT_ALIGNS[number];
34
+
35
+ /** 一个子项的约束 */
36
+ export interface SomaLayoutNodeConstraint {
37
+ sizing: SomaSizing;
38
+ /** `sizing: fixed` 的目标宽;`rem` / `%` / `cqi` 三种单位 */
39
+ width?: string;
40
+ min?: string;
41
+ max?: string;
42
+ priority?: SomaPriority;
43
+ }
44
+
45
+ /** 一组(一行)的约束 */
46
+ export interface SomaLayoutConstraint {
47
+ /** 子项名 → 约束;声明序即视觉序 */
48
+ nodes: Record<string, SomaLayoutNodeConstraint>;
49
+ /** 子项之间的间隔(rem) */
50
+ gap?: string;
51
+ wrap?: SomaWrap;
52
+ align?: SomaAlign;
53
+ /** 具名容器上下文:编译成 `container-name` */
54
+ container_name?: string;
55
+ }
56
+
57
+ /** 单档的解 */
58
+ export interface SomaLayoutSolution {
59
+ /** 档名(`cqXs` … `cq4xl`) */
60
+ breakpoint: string;
61
+ /** 该档的容器宽度(rem) */
62
+ containerRem: number;
63
+ /** 子项名 → 解出的宽度(rem) */
64
+ widths: Record<string, number>;
65
+ /** 该档是否必须换行(解不出「两者都 ≥ min」时为真) */
66
+ wrapped: boolean;
67
+ }
68
+
69
+ /** 求解产物 */
70
+ export interface SomaLayoutPlan {
71
+ constraint: SomaLayoutConstraint;
72
+ solutions: SomaLayoutSolution[];
73
+ }
@@ -0,0 +1,60 @@
1
+ // 页面态切片(REQ-010 F-37)——「这一屏此刻长什么样」的可序列化表达。
2
+ //
3
+ // ── 要解决的问题 ──────────────────────────────────────────────────────
4
+ // 排序、过滤、选了哪些行、哪几列可见、列宽列序、密度、展开了哪些分组——
5
+ // 这些状态今天散在各个组件的私有变量里。后果是三件事都做不了:
6
+ // ① 分享链接(把当前视图发给同事);
7
+ // ② 用户偏好(下次打开还是这个样子);
8
+ // ③ 审计回放(他当时到底看到的是哪一屏)。
9
+ //
10
+ // AG Grid 的 `GridState` 解决了它,但那是一个网格的状态。SOMA 的落点更靠上:
11
+ // 页面态是**具名切片的并集**,每个切片对应一个已声明的东西(一个数据窗口、
12
+ // 一个表格锚点),所以它能被静态校验——切片名指向一个不存在的窗口时当场报错,
13
+ // 而不是在恢复状态时静默丢掉一半。
14
+
15
+ /** 一个数据窗口的可序列化状态 */
16
+ export interface SomaWindowStateSlice {
17
+ sort?: Array<{ field: string; order: 'asc' | 'desc' }>;
18
+ filter?: unknown;
19
+ selection?: { base: 'none' | 'all'; toggled: string[] };
20
+ /** 分组展开路径 */
21
+ group_keys?: string[];
22
+ }
23
+
24
+ /** 一个表格锚点的列状态 */
25
+ export interface SomaColumnStateSlice {
26
+ visible?: string[];
27
+ order?: string[];
28
+ pinned?: Record<string, 'start' | 'end'>;
29
+ width?: Record<string, number>;
30
+ }
31
+
32
+ /**
33
+ * 页面态。
34
+ *
35
+ * `version` 是必需的:恢复一份旧结构的状态会让界面进入一个谁都没设计过的样子,
36
+ * 而那种坏法是静默的(列还在、但顺序是乱的)。版本对不上就整份丢弃并说明原因。
37
+ */
38
+ export interface SomaPageState {
39
+ version: number;
40
+ window?: Record<string, SomaWindowStateSlice>;
41
+ columns?: Record<string, SomaColumnStateSlice>;
42
+ density?: 'sm' | 'md' | 'lg';
43
+ /** 展开的行/分组 id */
44
+ expanded?: string[];
45
+ }
46
+
47
+ /** `_ui.yaml` 顶层 `state:` 段的声明形态 */
48
+ export interface SomaPageStateConfig {
49
+ version: number;
50
+ /** 允许出现在页面态里的窗口名(必须是已声明的数据对象) */
51
+ window?: string[];
52
+ /** 允许出现在页面态里的表格锚点 */
53
+ columns?: string[];
54
+ density?: boolean;
55
+ expanded?: boolean;
56
+ /** 初始状态:只读一次,之后由用户交互接管 */
57
+ initial_state?: SomaPageState;
58
+ /** 是否把状态同步进 URL(`?s=<紧凑序列化>`) */
59
+ url?: boolean;
60
+ }