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.
Files changed (169) hide show
  1. package/README.md +20 -7
  2. package/app/SomaPageClient.tsx +4 -4
  3. package/app/components/SomaHostPage.tsx +5 -5
  4. package/app/components/SomaHydrationShell.tsx +4 -7
  5. package/app/globals.css +126 -3
  6. package/core/build/{v2 → blocks}/block-compile.ts +47 -18
  7. package/core/build/{v2/soma-file-loader.ts → blocks/block-container.ts} +28 -37
  8. package/core/build/{v2 → blocks}/block-loader.ts +1 -1
  9. package/core/build/{v2 → blocks}/html-index.ts +1 -1
  10. package/core/build/{v2/migrate-v1.ts → blocks/migrate-flat.ts} +27 -27
  11. package/core/build/compiler/host-config-sync.cjs +2 -9
  12. package/core/build/compiler/page-declaration-compiler.ts +32 -4
  13. package/core/build/compiler/soma-manifest-webpack-plugin.js +1 -1
  14. package/core/build/compiler/soma-precompile.js +2057 -35
  15. package/core/build/compiler/soma-precompile.ts +2 -2
  16. package/core/build/component/component-graph.ts +208 -0
  17. package/core/build/eject/component-eject.ts +473 -0
  18. package/core/build/eject/component-upgrade.ts +359 -0
  19. package/core/build/layout/constraint-solver.ts +235 -0
  20. package/core/build/layout/css-emitter.ts +116 -0
  21. package/core/build/layout/page-layout.ts +85 -0
  22. package/core/build/pack/pack-init.ts +265 -0
  23. package/core/client/base/SomaPageRootBase.ts +61 -0
  24. package/core/client/component/ai-catalog.ts +83 -8
  25. package/core/client/component/component-defaults.ts +100 -0
  26. package/core/client/component/component-definition.types.ts +39 -0
  27. package/core/client/component/component-manager.ts +79 -4
  28. package/core/client/component/component-pack.ts +126 -2
  29. package/core/client/component/contract-compat.ts +32 -3
  30. package/core/client/component/{example-v2.ts → example-blocks.ts} +19 -19
  31. package/core/client/component/keyboard-matrix.ts +144 -0
  32. package/core/client/component/pack-styles.ts +59 -1
  33. package/core/client/component/style-features.ts +131 -0
  34. package/core/client/component/theme-component-tokens.ts +83 -0
  35. package/core/client/data/data-object-resolver.ts +407 -4
  36. package/core/client/data/reaction-engine.ts +176 -0
  37. package/core/client/data/window-engine.ts +477 -0
  38. package/core/client/engine/event-engine.ts +98 -0
  39. package/core/client/engine/soma-bootstrap.ts +286 -7
  40. package/core/client/engine/step-runner.ts +134 -0
  41. package/core/client/engine/style-binder.ts +1 -1
  42. package/core/client/infra/notify/DomNotifyService.ts +2 -1
  43. package/core/client/infra/notify/INotifyTheme.ts +1 -1
  44. package/core/client/parser/{v2 → blocks}/namespace.ts +1 -1
  45. package/core/client/parser/{v2 → blocks}/page-parser.ts +30 -16
  46. package/core/client/parser/{v2 → blocks}/use-parser.ts +24 -25
  47. package/core/client/parser/data-config-parser.ts +316 -8
  48. package/core/client/parser/duration.ts +16 -0
  49. package/core/client/parser/layout-parser.ts +157 -0
  50. package/core/client/parser/page-state-parser.ts +166 -0
  51. package/core/client/parser/pipeline-parser.ts +76 -1
  52. package/core/client/parser/reaction-parser.ts +459 -0
  53. package/core/client/parser/reaction-sugar.ts +47 -0
  54. package/core/client/parser/step-parser.ts +359 -0
  55. package/core/client/parser/style-config-parser.ts +7 -7
  56. package/core/client/parser/ui-config-parser.ts +59 -0
  57. package/core/client/parser/value-lang.ts +1 -1
  58. package/core/client/parser/window-parser.ts +294 -0
  59. package/core/client/registry/index.ts +8 -0
  60. package/core/client/theme/theme-engine.ts +144 -16
  61. package/core/client/typography/typography-base.ts +1 -1
  62. package/core/index.ts +188 -13
  63. package/core/server/host/csp-nonce-metadata.ts +1 -1
  64. package/core/server/host/published-page-assets.ts +3 -8
  65. package/core/server/host/soma-page-compile.ts +1 -1
  66. package/core/server/index.ts +2 -2
  67. package/core/shared/block-errors.ts +11 -0
  68. package/core/shared/calc/coerce.ts +29 -0
  69. package/core/shared/calc/errors.ts +43 -0
  70. package/core/shared/calc/evaluator.ts +101 -0
  71. package/core/shared/calc/index.ts +12 -0
  72. package/core/shared/calc/lexer.ts +194 -0
  73. package/core/shared/calc/parser.ts +204 -0
  74. package/core/shared/calc/typer.ts +184 -0
  75. package/core/shared/path-algebra.ts +169 -0
  76. package/core/shared/predicates/index.ts +527 -0
  77. package/core/shared/published-page-route.ts +61 -0
  78. package/core/shared/types/adaptive.types.ts +1 -1
  79. package/core/shared/types/component-contract.types.ts +128 -2
  80. package/core/shared/types/data-config.types.ts +149 -2
  81. package/core/shared/types/domain.types.ts +13 -0
  82. package/core/shared/types/event.types.ts +22 -2
  83. package/core/shared/types/layout-constraint.types.ts +73 -0
  84. package/core/shared/types/page-state.types.ts +60 -0
  85. package/core/shared/types/reaction.types.ts +144 -0
  86. package/core/shared/types/scope-manifest.types.ts +11 -15
  87. package/core/shared/types/step.types.ts +91 -0
  88. package/core/shared/types/style-config.types.ts +4 -4
  89. package/core/shared/types/ui-config.types.ts +18 -0
  90. package/core/shared/types/window.types.ts +177 -0
  91. package/dist/cli/soma.js +28 -3
  92. package/dist/core/index.cjs +4829 -405
  93. package/dist/types/build/{v2 → blocks}/block-compile.d.ts +7 -7
  94. package/dist/types/build/{v2/soma-file-loader.d.ts → blocks/block-container.d.ts} +6 -11
  95. package/dist/types/build/{v2/migrate-v1.d.ts → blocks/migrate-flat.d.ts} +6 -6
  96. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
  97. package/dist/types/build/component/component-graph.d.ts +85 -0
  98. package/dist/types/build/eject/component-eject.d.ts +121 -0
  99. package/dist/types/build/eject/component-upgrade.d.ts +43 -0
  100. package/dist/types/build/layout/constraint-solver.d.ts +36 -0
  101. package/dist/types/build/layout/css-emitter.d.ts +18 -0
  102. package/dist/types/build/layout/page-layout.d.ts +24 -0
  103. package/dist/types/build/pack/pack-init.d.ts +8 -0
  104. package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
  105. package/dist/types/client/component/ai-catalog.d.ts +24 -1
  106. package/dist/types/client/component/component-defaults.d.ts +15 -0
  107. package/dist/types/client/component/component-definition.types.d.ts +38 -0
  108. package/dist/types/client/component/component-manager.d.ts +36 -0
  109. package/dist/types/client/component/component-pack.d.ts +32 -2
  110. package/dist/types/client/component/contract-compat.d.ts +2 -2
  111. package/dist/types/client/component/example-blocks.d.ts +9 -0
  112. package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
  113. package/dist/types/client/component/pack-styles.d.ts +21 -0
  114. package/dist/types/client/component/style-features.d.ts +26 -0
  115. package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
  116. package/dist/types/client/data/data-object-resolver.d.ts +106 -1
  117. package/dist/types/client/data/reaction-engine.d.ts +21 -0
  118. package/dist/types/client/data/window-engine.d.ts +27 -0
  119. package/dist/types/client/engine/event-engine.d.ts +15 -0
  120. package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
  121. package/dist/types/client/engine/step-runner.d.ts +24 -0
  122. package/dist/types/client/infra/notify/DomNotifyService.d.ts +2 -1
  123. package/dist/types/client/infra/notify/INotifyTheme.d.ts +1 -1
  124. package/dist/types/client/parser/{v2 → blocks}/page-parser.d.ts +2 -2
  125. package/dist/types/client/parser/{v2 → blocks}/use-parser.d.ts +3 -3
  126. package/dist/types/client/parser/duration.d.ts +1 -0
  127. package/dist/types/client/parser/layout-parser.d.ts +9 -0
  128. package/dist/types/client/parser/page-state-parser.d.ts +32 -0
  129. package/dist/types/client/parser/reaction-parser.d.ts +16 -0
  130. package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
  131. package/dist/types/client/parser/step-parser.d.ts +23 -0
  132. package/dist/types/client/parser/style-config-parser.d.ts +1 -1
  133. package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
  134. package/dist/types/client/parser/window-parser.d.ts +25 -0
  135. package/dist/types/client/registry/index.d.ts +1 -0
  136. package/dist/types/client/theme/theme-engine.d.ts +37 -0
  137. package/dist/types/index.d.ts +40 -9
  138. package/dist/types/server/host/published-page-assets.d.ts +3 -2
  139. package/dist/types/server/index.d.ts +1 -1
  140. package/dist/types/shared/block-errors.d.ts +5 -0
  141. package/dist/types/shared/calc/coerce.d.ts +4 -0
  142. package/dist/types/shared/calc/errors.d.ts +14 -0
  143. package/dist/types/shared/calc/evaluator.d.ts +2 -0
  144. package/dist/types/shared/calc/index.d.ts +6 -0
  145. package/dist/types/shared/calc/lexer.d.ts +20 -0
  146. package/dist/types/shared/calc/parser.d.ts +49 -0
  147. package/dist/types/shared/calc/typer.d.ts +16 -0
  148. package/dist/types/shared/path-algebra.d.ts +56 -0
  149. package/dist/types/shared/predicates/index.d.ts +79 -0
  150. package/dist/types/shared/published-page-route.d.ts +21 -0
  151. package/dist/types/shared/types/component-contract.types.d.ts +112 -0
  152. package/dist/types/shared/types/data-config.types.d.ts +132 -2
  153. package/dist/types/shared/types/domain.types.d.ts +12 -0
  154. package/dist/types/shared/types/event.types.d.ts +8 -2
  155. package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
  156. package/dist/types/shared/types/page-state.types.d.ts +49 -0
  157. package/dist/types/shared/types/reaction.types.d.ts +115 -0
  158. package/dist/types/shared/types/scope-manifest.types.d.ts +11 -11
  159. package/dist/types/shared/types/step.types.d.ts +76 -0
  160. package/dist/types/shared/types/style-config.types.d.ts +4 -4
  161. package/dist/types/shared/types/ui-config.types.d.ts +18 -0
  162. package/dist/types/shared/types/window.types.d.ts +171 -0
  163. package/package.json +2 -6
  164. package/dist/types/client/component/example-v2.d.ts +0 -9
  165. package/postcss.config.js +0 -6
  166. package/tailwind.config.ts +0 -43
  167. /package/dist/types/build/{v2 → blocks}/block-loader.d.ts +0 -0
  168. /package/dist/types/build/{v2 → blocks}/html-index.d.ts +0 -0
  169. /package/dist/types/client/parser/{v2 → blocks}/namespace.d.ts +0 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Registry 发布页的公开 URL 契约。
3
+ *
4
+ * 页面名就是根路径 slug:Registry `myworkspace` 对应 `/myworkspace`。
5
+ * `/pages/<name>` 仅保留为存量链接兼容入口,新发布结果不再生成该前缀。
6
+ */
7
+ export declare const PUBLISHED_PAGE_SLUG_PATTERN: RegExp;
8
+ /** Next/SOMA 内部入口不能被 Registry 根路径页面占用。 */
9
+ export declare const RESERVED_PUBLISHED_PAGE_SLUGS: Set<string>;
10
+ export declare function isPublishedPageSlug(value: unknown): value is string;
11
+ /**
12
+ * 归一化模型或用户给出的候选路径。只做机械变换,不擅自翻译中文;
13
+ * 语义翻译由生成模型负责,调用方可在 null 时提供确定性兜底。
14
+ */
15
+ export declare function normalizePublishedPageSlug(value: unknown): string | null;
16
+ export declare function publishedPagePath(slug: string): string;
17
+ /**
18
+ * 根路径是正式入口;旧 `/pages/<name>` 继续可读,避免已分享链接立即失效。
19
+ * 只接受单段路径,子路径仍交给 Host 文件页处理。
20
+ */
21
+ export declare function publishedPageSlugFromPath(pagePath: string): string | null;
@@ -41,6 +41,22 @@ export interface SomaContractSlot {
41
41
  desc?: string;
42
42
  required?: boolean;
43
43
  }
44
+ /**
45
+ * 组件级令牌(三级令牌的第三级,REQ-009 M-1)。
46
+ *
47
+ * 为什么是「组件自己声明旋钮」而不是 MUI 的 `styleOverrides.<slot>`:
48
+ * 后者要求 Host 知道组件内部结构,而 `scopeAnchors()` 刻意让页面永不可寻址组件内部。
49
+ * 组件声明可调令牌 = 组件自己承诺「这几个值可以被外面改,改了不会散架」,
50
+ * 内部结构仍然封闭。
51
+ *
52
+ * `default` 必须形如 `var(--soma-…)`:组件令牌是语义令牌的**别名与收窄**,
53
+ * 不是新的真源。写裸值等于在组件里开一个绕过主题的后门。
54
+ */
55
+ export interface SomaContractToken {
56
+ /** 必须引用语义令牌:var(--soma-…),可带回退值 */
57
+ default: string;
58
+ desc: string;
59
+ }
44
60
  /**
45
61
  * AI 目录段(契约规范第 11 章):AI 生成页面前查表选组件的依据。
46
62
  * when_to_use / example 为目录质量线;when_not_to_use 用于同族组件消歧。
@@ -64,6 +80,11 @@ export interface SomaComponentContract {
64
80
  props?: Record<string, SomaContractProp>;
65
81
  emits?: Record<string, SomaContractEmit>;
66
82
  slots?: Record<string, SomaContractSlot>;
83
+ /**
84
+ * 组件级令牌:key 为 kebab-case,装配期写出 `--soma-<组件名 kebab>-<key>`。
85
+ * 主题输入的 `components.<组件名>.<key>` 覆盖它,`ThemeScope` 可按子树覆盖。
86
+ */
87
+ tokens?: Record<string, SomaContractToken>;
67
88
  ai?: SomaContractAiSection;
68
89
  /**
69
90
  * 声明式覆盖:本组件有意替换该包里的同名组件(值为被覆盖组件的来源包名,如 'soma-ui')。
@@ -75,4 +96,95 @@ export interface SomaComponentContract {
75
96
  * 未声明的跨包撞名一律抛错——写出来的覆盖是设计决定,猜出来的覆盖是事故。
76
97
  */
77
98
  overrides?: string;
99
+ /**
100
+ * 依赖的其它组件(REQ-010 F-46):PascalCase 契约名数组。
101
+ *
102
+ * 两件事靠它:
103
+ * ① **按图拉齐**——`soma pack init` / eject 一个 TreeSelect 时能知道它还要 Tree,
104
+ * 而不是等页面渲染出一堆没样式的节点才发现(这条曾真实发生过:
105
+ * `COMPONENT_CSS_DEPS` 少写一条 `TreeSelect: ['Tree']`,页面上是无样式的折叠箭头);
106
+ * ② **可寻址目录**——`registry.json` 的每一项带版本、哈希与依赖,
107
+ * 于是"我这份是从哪一版来的、它还需要谁"两个问题都有答案。
108
+ * shadcn 的 registry 两个都没有。
109
+ *
110
+ * 只登记**契约级**依赖(模板里真的嵌了那个组件、或 CSS 分片依赖它),
111
+ * 不登记共享资产(`shared/*` 由构建图自然带上,写进来只会重复一份且会漂)。
112
+ */
113
+ uses?: string[];
114
+ /**
115
+ * 浮层行为契约(REQ-010 F-41 / F-42)。
116
+ *
117
+ * 声明而不是各组件自写:十几个浮层组件里的"点外面关不关""Esc 关不关"
118
+ * "退场动画放完再卸载"此前各有一份实现,而它们的差异只在某个具体组件上暴露
119
+ * (某个下拉点外面不关、某个抽屉 Esc 无效)。收成契约之后,
120
+ * 引擎按声明接线,组件不再碰这些代码。
121
+ */
122
+ overlay?: SomaContractOverlay;
123
+ /**
124
+ * 键盘契约(REQ-010 F-43)。
125
+ *
126
+ * 声明这是个什么布局(列表 / 网格 / 树),引擎据此挑键盘委托并接上方向键。
127
+ * 组件因此删掉自写的方向键分支——六个组件曾各写一套,最后一行按 ↓ 的行为各不相同。
128
+ * 另一个收益:**键盘矩阵能自动进目录**,AI 与业务开发者不必读源码才知道按键表。
129
+ */
130
+ keyboard?: SomaContractKeyboard;
131
+ }
132
+ /** 浮层行为的封闭词汇 */
133
+ export interface SomaContractOverlay {
134
+ /** 浮层类型:决定默认的模态性与回焦策略 */
135
+ kind: 'popup' | 'modal' | 'non_modal' | 'toast';
136
+ /**
137
+ * Esc 的行为。`defer` 表示交给外层——嵌套浮层里,内层已经处理过就不该再传。
138
+ * 显式三档而不是布尔:`false` 与 `defer` 的差别正是"吞掉"与"让出去"。
139
+ */
140
+ escape_key_behavior?: 'close' | 'none' | 'defer';
141
+ /** 点外面关不关;`ignore` 用于必须显式操作才能关的对话框 */
142
+ outside_press_behavior?: 'close' | 'ignore';
143
+ /** 退场动画放完再卸载(F-42):不挂起的话,关闭动画根本看不见 */
144
+ presence?: boolean;
145
+ /** 打开时把外部标 aria-hidden(F-44);模态默认真 */
146
+ hide_outside?: boolean;
147
+ /** 关闭后把焦点还给触发者;默认真 */
148
+ restore_focus?: boolean;
149
+ }
150
+ /** 键盘导航的封闭词汇 */
151
+ export interface SomaContractKeyboard {
152
+ /** 布局形态:决定挑哪个键盘委托 */
153
+ layout: 'list' | 'grid' | 'tree' | 'none';
154
+ /** 网格列数;`layout: grid` 时必填(DOM 上看不出来,猜错就跳到无关格子) */
155
+ columns?: number;
156
+ /** 到边之后回绕还是停住 */
157
+ wrap?: boolean;
158
+ /** 首字母跳转 */
159
+ typeahead?: boolean;
160
+ /** 焦点模型:漫游 tabindex 还是 aria-activedescendant */
161
+ focus_model?: 'roving' | 'activedescendant';
162
+ /** 选中随焦点移动(单选列表的常见形态) */
163
+ selection_follows_focus?: boolean;
164
+ /**
165
+ * 主轴方向:横向时 ←/→ 走上一项/下一项(tablist、菜单栏),RTL 下自动换向;
166
+ * 缺省纵向(↑/↓);`both` 是 APG 单选组的形态——两轴都走同一条链
167
+ * (排成一行还是一列只是 CSS 的事,键盘用户不该先猜方向)。网格两轴各有语义,本项无意义。
168
+ */
169
+ orientation?: 'horizontal' | 'vertical' | 'both';
170
+ /**
171
+ * 空格的语义:`activate`(与 Enter 同义,单选列表 / 树 / 选项卡)、
172
+ * `toggle_select`(勾选当前项而不确认,多选 listbox / 穿梭框)或
173
+ * `none`(这个键不归本组件——触发器是原生 button 的下拉就属这种:
174
+ * Space 是按钮自己的"按下",抢过来会变成"选中一项的同时又把面板重新打开")。缺省 `activate`。
175
+ * 显式三档而不是从别的字段推:Space 在多选列表里按成"确认"会把用户刚勾的东西直接提交出去,
176
+ * 而在按钮触发的下拉里按成"确认"会和浏览器的按钮语义打架。
177
+ */
178
+ space?: 'activate' | 'toggle_select' | 'none';
179
+ /**
180
+ * 组件特有的按键(引擎矩阵之外):按键 → 说明。例如 Tabs 的 `Delete: 关闭当前项`、
181
+ * Tree 的 `Alt+方向键: 搬运节点`。**只进目录,不由引擎接线**——组件自己处理,
182
+ * 但键盘表必须完整:读目录的人(与 AI)不该只看到一半的按键。
183
+ */
184
+ extra?: Record<string, string>;
78
185
  }
186
+ /** PascalCase 组件名 → 令牌前缀用的 kebab-case(DataTable → data-table) */
187
+ export declare function componentTokenPrefix(name: string): string;
188
+ /** 组件令牌的 CSS 变量名:Button + radius → --soma-button-radius */
189
+ export declare function componentTokenVar(componentName: string, tokenKey: string): string;
190
+ export declare const COMPONENT_TOKEN_KEY_PATTERN: RegExp;
@@ -1,5 +1,32 @@
1
- /** 字段类型枚举(决定 soma-ui 双态映射走哪个渲染组件) */
2
- export type SomaDataFieldType = 'text' | 'int' | 'float' | 'money' | 'bool' | 'enum' | 'date' | 'datetime' | 'image' | 'url' | 'richtext';
1
+ import type { SomaNamedPredicates } from '../predicates';
2
+ import type { SomaReactionGraph } from './reaction.types';
3
+ import type { SomaWindowConfig, SomaWindowHandle } from './window.types';
4
+ /**
5
+ * 字段类型枚举(决定 soma-ui 双态映射走哪个渲染组件)。
6
+ *
7
+ * **这是字段类型的唯一真源。** 块声明的 `fields.type` 与 soma-ui 的双态映射表
8
+ * 都必须消费它,不得各自再抄一份——此前正是抄成了三份:
9
+ * 数据对象层 11 型、soma-ui 11 型(逐字重复)、块声明 9 型(已漂)。
10
+ * 后果是 `type: url` 在块声明里被解析器拒收,而 `type: percent` 能过解析器
11
+ * 却在 soma-ui 侧没有映射、静默按 text 渲染出来。
12
+ */
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';
22
+ /**
23
+ * 类型别名:块声明历史上用 `number` 表示小数,与本表的 `float` 同义。
24
+ * 保留为可接受拼写而不是二选一,是因为两边都有存量声明——
25
+ * 归一到 `float` 由解析器做,词汇表只认一个概念。
26
+ */
27
+ export declare const SOMA_DATA_FIELD_TYPE_ALIASES: Readonly<Record<string, SomaDataFieldType>>;
28
+ /** 全部合法字段类型(含别名),供解析器做封闭集校验 */
29
+ export declare const SOMA_DATA_FIELD_TYPES: readonly string[];
3
30
  /** 字段权限:r 只读 / w 可写(决定双态映射走 show 还是 edit 形态) */
4
31
  export type SomaDataFieldPermission = 'r' | 'w';
5
32
  /** 枚举字段候选项(type: enum 专用) */
@@ -41,6 +68,15 @@ export interface SomaDataFieldConfig {
41
68
  rules?: SomaDataFieldRule[];
42
69
  /** 枚举候选项 */
43
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;
44
80
  }
45
81
  /**
46
82
  * 单个取数来源:一个后端接口 + 参数 + 聚合位置。
@@ -55,6 +91,44 @@ export interface SomaDataSourceConfig {
55
91
  /** 结果聚合到对象子键(如 order.trace);缺省浅合并进对象根 */
56
92
  into?: string;
57
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
+ }
58
132
  /** 数据对象声明(*_data.yaml 中 data.<对象名> 的解析产物) */
59
133
  export interface SomaDataObjectConfig {
60
134
  /** 对象名(页面内唯一,即 data 下的键名) */
@@ -70,9 +144,65 @@ export interface SomaDataObjectConfig {
70
144
  fields?: Record<string, SomaDataFieldConfig>;
71
145
  /** mock 样本:SOMA_MOCK_ENABLED / 接口失败兜底 / 无接口预览 */
72
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;
73
166
  /** 解析期提取:params 引用到的其他数据对象名(DAG 拓扑排序输入,不含自引用) */
74
167
  deps: string[];
75
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
+ }
76
206
  /** *_data.yaml 整体解析产物(对象名 → 声明) */
77
207
  export interface SomaDataConfig {
78
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
- export type EventType = 'NAV_STATIC' | 'NAV_ACTION' | 'UI_REFRESH' | 'UI_INTERACT';
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
+ }
@@ -1,13 +1,15 @@
1
- import type { SomaCompiledBinding, SomaCompiledEvent, SomaRuntimeManifest } from './manifest.types';
1
+ import type { SomaCompiledBinding, SomaCompiledEvent } from './manifest.types';
2
2
  /**
3
- * v2 作用域清单树(组件体系 P0)。
3
+ * 作用域清单树(组件体系 P0)。
4
4
  *
5
- * 设计规范:soma-core/doc/soma 作用域清单树.md
6
- * 兼容承诺:v1 清单(SomaRuntimeManifest)长期保留;无组件页面继续走 v1 原路径,
7
- * 本文件只做类型新增,不修改任何既有类型。
5
+ * 设计规范:soma-core/doc/archive/soma 作用域清单树.md(事实已并入《运行时引擎详设》)。
6
+ *
7
+ * **状态:目标模型,尚未物化。** 当前运行时以「实例级迷你运行时」承载同一语义
8
+ * (见《soma 运行时引擎详设》§4);本文件先把节点形状定下来,随契约编译器落地。
9
+ * 除下面的管道类型外,其余类型暂无消费者——改动它们不会影响运行行为。
8
10
  *
9
11
  * 节点结构保持可 JSON 序列化(仅数组/普通对象,无 Map)——构建期产物与
10
- * 运行期客户端编译产物必须深度相等(规范 7.4),索引一律在运行时装配。
12
+ * 运行期客户端编译产物必须深度相等,索引一律在运行时装配。
11
13
  */
12
14
  export type SomaScopeKind = 'page' | 'list' | 'component';
13
15
  export type SomaPropMode = 'oneway' | 'model';
@@ -68,15 +70,13 @@ export interface SomaScopeNode {
68
70
  listVar?: string;
69
71
  /** 异构列表模板选择器的绑定路径(DSL 扩展规范 2.1,行模板后缀 = 该路径取值) */
70
72
  roleBy?: string;
71
- /** 本作用域直属锚点的绑定(结构与 v1 逐字段同构) */
73
+ /** 本作用域直属锚点的绑定(结构与扁平清单逐字段同构) */
72
74
  bindings: SomaCompiledBinding[];
73
75
  events: SomaCompiledEvent[];
74
76
  children: SomaScopeNode[];
75
77
  }
76
- export interface SomaRuntimeManifestV2 {
77
- version: 2;
78
+ /** 作用域树形态的运行清单(目标模型,尚无产出者与消费者) */
79
+ export interface SomaScopeManifest {
78
80
  root: SomaScopeNode;
79
81
  initProps?: Record<string, unknown>;
80
82
  }
81
- export type SomaAnyRuntimeManifest = SomaRuntimeManifest | SomaRuntimeManifestV2;
82
- export declare function isManifestV2(manifest: SomaAnyRuntimeManifest): manifest is SomaRuntimeManifestV2;