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
package/core/index.ts CHANGED
@@ -20,6 +20,12 @@ export type {
20
20
  export { SomaComponentRegistry } from './client/component/component-registry';
21
21
  export { SomaComponentManager } from './client/component/component-manager';
22
22
  export { generateAiCatalog, buildCatalogEntry } from './client/component/ai-catalog';
23
+ export {
24
+ deriveKeyboardMatrix,
25
+ renderKeyboardMatrixLine,
26
+ SOMA_KEYBOARD_INTENTS,
27
+ } from './client/component/keyboard-matrix';
28
+ export type { SomaKeyboardIntent, SomaKeyboardMatrixRow } from './client/component/keyboard-matrix';
23
29
  export type {
24
30
  SomaAiCatalog,
25
31
  SomaAiCatalogEntry,
@@ -57,7 +63,160 @@ export type {
57
63
  SomaDataFieldType,
58
64
  SomaDataFieldPermission,
59
65
  SomaDataDicts,
66
+ // 写通道(REQ-009 M-5):自治组件按结构消费 data 端口,这三个类型必须公开,
67
+ // 否则每个消费方只能本地重声明一份结构型——那正是「同一个概念多份抄本」的起点
68
+ SomaDataWriteConfig,
69
+ SomaDataWriteEndpoint,
70
+ SomaDataSubmitResult,
71
+ SomaDataPort,
72
+ } from './shared/types/data-config.types';
73
+ // 字段类型的唯一真源(值导出):块解析器与 soma-ui 的双态映射表都消费它,
74
+ // 消费方不得再手抄一份清单——四份手写副本里漏改一份,就是「一处合法、一处静默按 text 渲染」。
75
+ export {
76
+ SOMA_DATA_FIELD_TYPES,
77
+ SOMA_DATA_FIELD_TYPE_ALIASES,
60
78
  } from './shared/types/data-config.types';
79
+
80
+ // 字段谓词图(REQ-010 S1b):三个消费者共用的封闭布尔代数——
81
+ // RG 反应图的 when、DW 过滤 AST 的叶子、soma-ui 表单的 visible_when。
82
+ // 真源住在 core 是因为 core 不能反向依赖 ui,而三处各判一次必然判得不一样。
83
+ export {
84
+ SOMA_FIELD_PREDICATE_OPS,
85
+ evaluatePredicate,
86
+ validatePredicate,
87
+ validateNamedPredicates,
88
+ collectPredicateFields,
89
+ } from './shared/predicates';
90
+ export type {
91
+ SomaFieldPredicateOp,
92
+ SomaFieldCondition,
93
+ SomaFieldPredicateRef,
94
+ SomaFieldPredicateAllOf,
95
+ SomaFieldPredicateAnyOf,
96
+ SomaFieldPredicateNoneOf,
97
+ SomaFieldPredicate,
98
+ SomaNamedPredicates,
99
+ SomaPredicateValidateOptions,
100
+ } from './shared/predicates';
101
+
102
+ // calc 表达式层(REQ-010 S1a):派生列与反应图 `value: { calc }` 的共同语言。
103
+ // 它不是表达式语言,是一张受限算式表——函数名封闭集由 verify:no-eval 的 CALC_CHARTER 看守。
104
+ export {
105
+ parseCalc,
106
+ collectCalcRefs,
107
+ inferCalcType,
108
+ assertCalcResultType,
109
+ evaluateCalc,
110
+ SomaCalcSyntaxError,
111
+ SomaCalcTypeError,
112
+ CALC_FUNCTIONS,
113
+ } from './shared/calc';
114
+ export type { CalcAst, CalcType, CalcTypeContext, CalcSpan } from './shared/calc';
115
+
116
+ // 反应图(REQ-010 S1b):字段之间的联动。解析在 core,消费在 soma-ui 的表单族——
117
+ // 求值器只有这一套,字段上的 visible_when / disabled_when 也编译成反应走同一条路。
118
+ export { parseReactions } from './client/parser/reaction-parser';
119
+ export { compileFieldSugar } from './client/parser/reaction-sugar';
120
+ export type { SomaSugarField } from './client/parser/reaction-sugar';
121
+ export { runReactions, explainField } from './client/data/reaction-engine';
122
+
123
+ // 数据窗口(REQ-010 S2):一屏一屏地取。解析在 core,消费面是 QueryConsole / DataTable。
124
+ export { parseWindow, dictHash } from './client/parser/window-parser';
125
+ export { createWindow } from './client/data/window-engine';
126
+
127
+ // 动作编排(REQ-010 S4):一个交互按顺序做好几件事。编排图是纯数据——
128
+ // 可画、可 diff、可在编译期判定可终止性。逃生舱是具名动作注册表,不是脚本。
129
+ export { parseSteps } from './client/parser/step-parser';
130
+ export type { StepParseInput, StepParseDeps } from './client/parser/step-parser';
131
+ export { runSteps } from './client/engine/step-runner';
132
+
133
+ // 页面态切片(REQ-010 F-37):分享链接、用户偏好、审计回放共用一套结构。
134
+ export {
135
+ parsePageState,
136
+ parseStateValue,
137
+ encodePageState,
138
+ decodePageState,
139
+ } from './client/parser/page-state-parser';
140
+ // 约束布局(REQ-010 S3):声明词汇在 client(要能被页面解析器读),
141
+ // 求解与产出在 build(CL-4:运行期零求解,求解器不进 client 依赖图)。
142
+ // 列表路径代数(REQ-010 F-11):让一条反应作用在明细行的每一项上。
143
+ export {
144
+ isListPath,
145
+ parseListPath,
146
+ expandListPath,
147
+ readListPath,
148
+ validateListPath,
149
+ SomaPathError,
150
+ } from './shared/path-algebra';
151
+ export type { SomaListPath, SomaPathSelector } from './shared/path-algebra';
152
+
153
+ export { parseLayoutConstraint } from './client/parser/layout-parser';
154
+ export { SOMA_LAYOUT_PRIORITIES, SOMA_LAYOUT_ALIGNS } from './shared/types/layout-constraint.types';
155
+ export type {
156
+ SomaSizing,
157
+ SomaPriority,
158
+ SomaWrap,
159
+ SomaAlign,
160
+ SomaLayoutNodeConstraint,
161
+ SomaLayoutConstraint,
162
+ SomaLayoutSolution,
163
+ SomaLayoutPlan,
164
+ } from './shared/types/layout-constraint.types';
165
+
166
+ export type {
167
+ SomaPageState,
168
+ SomaPageStateConfig,
169
+ SomaWindowStateSlice,
170
+ SomaColumnStateSlice,
171
+ } from './shared/types/page-state.types';
172
+ export type { StepRunContext, StepRunResult } from './client/engine/step-runner';
173
+ export type {
174
+ SomaStep,
175
+ SomaDoStep,
176
+ SomaSwitchStep,
177
+ SomaParallelStep,
178
+ SomaForEachStep,
179
+ SomaStepOnError,
180
+ SomaStepSlot,
181
+ SomaCompiledStep,
182
+ SomaStepGraph,
183
+ } from './shared/types/step.types';
184
+ export type { SomaWindowHttpLike, SomaWindowDeps } from './client/data/window-engine';
185
+ export { SOMA_AGGREGATE_FNS, SOMA_SELECT_ALL_MODES } from './shared/types/window.types';
186
+ export type {
187
+ SomaFilterNode,
188
+ SomaWindowSort,
189
+ SomaAggregateFn,
190
+ SomaWindowAggregate,
191
+ SomaSelectAllMode,
192
+ SomaWindowSelection,
193
+ SomaWindowBlockConfig,
194
+ SomaWindowConfig,
195
+ SomaWindowRequest,
196
+ SomaWindowResponse,
197
+ SomaWindowRequestPatch,
198
+ SomaWindowHandle,
199
+ SomaTransaction,
200
+ } from './shared/types/window.types';
201
+ export {
202
+ SOMA_REACTION_PHASES,
203
+ SOMA_FIELD_DISPLAYS,
204
+ SOMA_FIELD_PATTERNS,
205
+ SOMA_REACTION_FORM_KEY,
206
+ } from './shared/types/reaction.types';
207
+ export type {
208
+ SomaReactionPhase,
209
+ SomaFieldDisplay,
210
+ SomaFieldPattern,
211
+ SomaFieldValuePatch,
212
+ SomaFieldStatePatch,
213
+ SomaFormStatePatch,
214
+ SomaReactionConfig,
215
+ SomaCompiledReaction,
216
+ SomaFieldProvenance,
217
+ SomaReactionGraph,
218
+ SomaReactionResult,
219
+ } from './shared/types/reaction.types';
61
220
  export {
62
221
  deriveTheme,
63
222
  applyTheme,
@@ -130,8 +289,18 @@ export type {
130
289
  SomaContractProp,
131
290
  SomaContractEmit,
132
291
  SomaContractSlot,
292
+ SomaContractKeyboard,
293
+ SomaContractOverlay,
294
+ SomaContractToken,
133
295
  } from './shared/types/component-contract.types';
134
296
  export { findNestedMutableContractDefault } from './shared/types/component-contract.types';
297
+ // 组件级令牌(REQ-009 M-1)的命名规则。宿主与闸门都要按同一条规则拼名字——
298
+ // 各自拼一遍的话,主题的 `components` 段覆盖不上任何东西,而覆盖不上是静默的。
299
+ export {
300
+ componentTokenPrefix,
301
+ componentTokenVar,
302
+ COMPONENT_TOKEN_KEY_PATTERN,
303
+ } from './shared/types/component-contract.types';
135
304
  export { createDefaultRuntimeServices } from './client/runtime/SomaRuntimeServices';
136
305
  export type { SomaRuntimeServices } from './client/runtime/SomaRuntimeServices';
137
306
  export { SomaDiagnostics } from './client/diagnostics/SomaDiagnostics';
@@ -235,6 +404,12 @@ export {
235
404
  type RegisterDeclarationOptions,
236
405
  type RenderPublishedPageOptions,
237
406
  type SomaPageLifecycleOptions,
407
+ PUBLISHED_PAGE_SLUG_PATTERN,
408
+ RESERVED_PUBLISHED_PAGE_SLUGS,
409
+ isPublishedPageSlug,
410
+ normalizePublishedPageSlug,
411
+ publishedPagePath,
412
+ publishedPageSlugFromPath,
238
413
  } from './client/registry/index';
239
414
 
240
415
  // 组件包(业务拓展组件库):合成、查重、目录、自检。
@@ -252,8 +427,8 @@ export {
252
427
  } from './client/component/component-pack';
253
428
  export { verifyComponentPack, type VerifyPackOptions } from './client/component/verify-pack';
254
429
 
255
- // 值语言(DSL v2 · REQ-005 F4):算术六词元 + 管道链的唯一值规则。
256
- // 规格见 doc/需求/REQ-005-DSL体验强化/UI业务组件DSL规格书.md §7;
430
+ // 值语言(REQ-005 F4):算术六词元 + 管道链的唯一值规则。
431
+ // 规格见 soma-core/doc/soma DSL 语法全书 v2.md §7;
257
432
  // v2 其余部件未施工前,本模块可被 v1 路径独立复用(纯函数、无依赖)。
258
433
  export {
259
434
  parseValueSegment,
@@ -272,35 +447,35 @@ export {
272
447
  // SOMA DSL 容器与块装载(外置块发现在 soma-core/server)。
273
448
  export {
274
449
  loadSomaFile,
275
- SomaV2ParseError,
450
+ SomaBlockParseError,
276
451
  PAGE_BLOCK_ID,
277
452
  type RawBlock,
278
453
  type SomaFileLoadInput,
279
- } from './build/v2/soma-file-loader';
454
+ } from './build/blocks/block-container';
280
455
  export {
281
456
  buildHtmlAnchorIndex,
282
457
  type HtmlAnchorIndex,
283
458
  type HtmlAnchorInfo,
284
- } from './build/v2/html-index';
285
- // 资产级入口:拿着原始 v2 声明的一方(服务端装载层/测试替身/预览器)先编译,
459
+ } from './build/blocks/html-index';
460
+ // 资产级入口:拿着原始块声明的一方(服务端装载层/测试替身/预览器)先编译,
286
461
  // 再把 v1 等价产物交给 mount——运行时只认 v1(两级编译、单一运行时)。
287
462
  export { compilePageAssets } from './build/compiler/page-assets';
288
463
  export {
289
- compileSomaV2,
290
- type CompiledSomaV2,
291
- type CompileSomaV2Input,
292
- } from './build/v2/block-compile';
464
+ compileSomaBlocks,
465
+ type CompiledSomaBlocks,
466
+ type CompileSomaBlocksInput,
467
+ } from './build/blocks/block-compile';
293
468
  export {
294
469
  parsePageBlock,
295
470
  type PageBlockAst,
296
- } from './client/parser/v2/page-parser';
471
+ } from './client/parser/blocks/page-parser';
297
472
  export {
298
473
  parseUseBlock,
299
474
  type UseBlockAst,
300
475
  type DataObjectDecl,
301
476
  type FieldDecl,
302
477
  type ActionDecl,
303
- } from './client/parser/v2/use-parser';
478
+ } from './client/parser/blocks/use-parser';
304
479
  export {
305
480
  buildBlockScope,
306
481
  resolvePath,
@@ -309,7 +484,7 @@ export {
309
484
  scopeHasVar,
310
485
  SomaScopeError,
311
486
  type BlockScope,
312
- } from './client/parser/v2/namespace';
487
+ } from './client/parser/blocks/namespace';
313
488
  export {
314
489
  checkOverrideCompat,
315
490
  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'`(走 tailwind/postcss),把逻辑关在
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
- const PUBLISHED_PAGE_PREFIX = '/pages/';
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/v2/block-loader';
4
+ import { loadExternalBlocks } from '../../build/blocks/block-loader';
5
5
 
6
6
  export interface SomaPageCompileResult {
7
7
  ui: string;
@@ -70,12 +70,12 @@ export {
70
70
  type LoadPackFromDirOptions,
71
71
  } from '../build/component/pack-from-dir';
72
72
 
73
- // DSL v2 容器(REQ-005):开关探测、HTML 锚点索引、块装载、外置块发现。
73
+ // 块声明容器(REQ-005):开关探测、HTML 锚点索引、块装载、外置块发现。
74
74
  // 用 node:fs 的只有 block-loader,其余纯函数(可在浏览器侧复用)。
75
75
  export {
76
76
  loadExternalBlocks,
77
77
  blocksDirOf,
78
- } from '../build/v2/block-loader';
78
+ } from '../build/blocks/block-loader';
79
79
 
80
80
  export {
81
81
  setSomaDb,
@@ -0,0 +1,11 @@
1
+ export class SomaBlockParseError extends Error {
2
+ constructor(
3
+ message: string,
4
+ readonly blockId?: string,
5
+ readonly line?: number,
6
+ ) {
7
+ const where = blockId ? `(块: ${blockId}${line ? `,第 ${line} 行` : ''})` : '';
8
+ super(`[soma-core][引擎] ${message}${where}`);
9
+ this.name = 'SomaBlockParseError';
10
+ }
11
+ }
@@ -0,0 +1,29 @@
1
+ // 值归一(REQ-010 S1a)——calc 与谓词图共用的一层。
2
+ //
3
+ // 为什么必须共用:同一个 `amount` 字段,在 `visible_when: { field: amount, op: gt, value: 1000 }`
4
+ // 里被判为「大于 1000」,在 `calc: "[amount] * 0.1"` 里必须也当成同一个数。
5
+ // 两处各写一套归一,迟早出现「谓词说大于、算式算成 NaN」这种自相矛盾。
6
+ //
7
+ // 归一规则与 `soma-ui/src/shared/field-predicates.ts` 的 `ordinal()` 逐条对齐:
8
+ // 数字原样;Date 取时间戳;纯数字串转数字;可解析的日期串转时间戳;其余为 null。
9
+
10
+ /** 数值/日期归一:能当数用就返回数,否则 null */
11
+ export function ordinalOf(value: unknown): number | null {
12
+ if (value === null || value === undefined || value === '') return null;
13
+ if (typeof value === 'number') return Number.isFinite(value) ? value : null;
14
+ if (typeof value === 'boolean') return null;
15
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value.getTime();
16
+ const text = String(value).trim();
17
+ if (text === '') return null;
18
+ if (/^[-+]?\d+(\.\d+)?$/.test(text)) {
19
+ const parsed = Number(text);
20
+ return Number.isFinite(parsed) ? parsed : null;
21
+ }
22
+ const asDate = Date.parse(text);
23
+ return Number.isNaN(asDate) ? null : asDate;
24
+ }
25
+
26
+ /** 文本化:null/undefined → 空串(CONCAT 与等值比较共用) */
27
+ export function textOf(value: unknown): string {
28
+ return value === null || value === undefined ? '' : String(value);
29
+ }
@@ -0,0 +1,43 @@
1
+ // calc 表达式层的错误类型(REQ-010 S1a)。
2
+ //
3
+ // 两类错误分开是刻意的:语法错是「这串字符不是一个表达式」,类型错是「它是个表达式,
4
+ // 但算的东西说不通」。前者作者改的是写法,后者作者改的是字段选型——错得不一样,
5
+ // 提示也不该混成一句「表达式无效」。
6
+ //
7
+ // 两者都带 `pos`(源串里的字符区间)。声明写在 YAML 里,出错时只说「calc 有问题」
8
+ // 等于让人拿肉眼在一行里找那个字母;带列号才能一眼看到。
9
+
10
+ /** 源串里的字符区间 [起, 止),用于错误定位 */
11
+ export type CalcSpan = readonly [number, number];
12
+
13
+ export class SomaCalcSyntaxError extends Error {
14
+ readonly pos: CalcSpan;
15
+ /** 出错处附近的原文片段(供报错时回显) */
16
+ readonly near: string;
17
+
18
+ constructor(message: string, source: string, pos: CalcSpan) {
19
+ super(`[soma-core][calc] ${formatWhere(source, pos)}:${message}`);
20
+ this.name = 'SomaCalcSyntaxError';
21
+ this.pos = pos;
22
+ this.near = source.slice(pos[0], pos[1]);
23
+ }
24
+ }
25
+
26
+ export class SomaCalcTypeError extends Error {
27
+ readonly pos: CalcSpan;
28
+ readonly expected: string;
29
+ readonly actual: string;
30
+
31
+ constructor(message: string, source: string, pos: CalcSpan, expected: string, actual: string) {
32
+ super(`[soma-core][calc] ${formatWhere(source, pos)}:${message}`);
33
+ this.name = 'SomaCalcTypeError';
34
+ this.pos = pos;
35
+ this.expected = expected;
36
+ this.actual = actual;
37
+ }
38
+ }
39
+
40
+ /** `calc "[amount] - [dsicount]" 第 12 列` —— 源串短,整串回显比行号有用 */
41
+ function formatWhere(source: string, pos: CalcSpan): string {
42
+ return `calc ${JSON.stringify(source)} 第 ${pos[0] + 1} 列`;
43
+ }
@@ -0,0 +1,101 @@
1
+ // calc 求值(REQ-010 S1a)——纯递归,无 eval、无 Function 构造、无副作用。
2
+ //
3
+ // 求值发生在**类型已经推过**之后,所以这里不重复做类型判断;它只处理运行期才知道的事:
4
+ // 值缺失、除零、以及「声明写的是 money,接口回来是字符串 "1280.00"」这类现实。
5
+ //
6
+ // ── 空值语义:任一操作数缺失 → 结果为 null,不抛 ────────────────────────
7
+ // 派生列的空值不是错误:数据还没到、字段本来就允许空,都会让它算不出来。
8
+ // 抛异常会让一整行渲染失败;返回 null 让那一格显示为空,其余照常。
9
+ // 这与四态资产的纪律一致——把「没有」画出来,而不是把页面炸掉。
10
+
11
+ import { ordinalOf, textOf } from './coerce';
12
+ import type { CalcAst } from './parser';
13
+
14
+ export function evaluateCalc(ast: CalcAst, values: Record<string, unknown>): unknown {
15
+ return evaluate(ast, values);
16
+ }
17
+
18
+ function evaluate(node: CalcAst, values: Record<string, unknown>): unknown {
19
+ switch (node.k) {
20
+ case 'num': return node.v;
21
+ case 'str': return node.v;
22
+ case 'bool': return node.v;
23
+ case 'date': return node.v;
24
+ case 'ref': return values[node.name] ?? null;
25
+
26
+ case 'un': {
27
+ const n = num(evaluate(node.arg, values));
28
+ return n === null ? null : -n;
29
+ }
30
+
31
+ case 'bin': {
32
+ const left = evaluate(node.left, values);
33
+ const right = evaluate(node.right, values);
34
+ switch (node.op) {
35
+ case '+': case '-': case '*': case '/': {
36
+ const a = num(left);
37
+ const b = num(right);
38
+ if (a === null || b === null) return null;
39
+ if (node.op === '+') return a + b;
40
+ if (node.op === '-') return a - b;
41
+ if (node.op === '*') return a * b;
42
+ // 除零返回 null 而不是 Infinity:Infinity 会一路流进 CONCAT 变成 "Infinity"
43
+ return b === 0 ? null : a / b;
44
+ }
45
+ case '>': case '>=': case '<': case '<=': {
46
+ const a = num(left);
47
+ const b = num(right);
48
+ if (a === null || b === null) return null;
49
+ if (node.op === '>') return a > b;
50
+ if (node.op === '>=') return a >= b;
51
+ if (node.op === '<') return a < b;
52
+ return a <= b;
53
+ }
54
+ case '==': case '!=': {
55
+ // 等值比较走字符串(与谓词图、form-rules 同一口径):
56
+ // 声明来自 YAML,enum 的 key 可能是数字也可能是字符串
57
+ const same = textOf(left) === textOf(right);
58
+ return node.op === '==' ? same : !same;
59
+ }
60
+ }
61
+ }
62
+
63
+ case 'call': {
64
+ switch (node.fn) {
65
+ case 'IF': {
66
+ const cond = evaluate(node.args[0], values);
67
+ // 条件算不出来时不猜分支——整条派生为空,比默认走 else 诚实
68
+ if (cond === null) return null;
69
+ return evaluate(node.args[cond === true ? 1 : 2], values);
70
+ }
71
+ case 'MIN': case 'MAX': {
72
+ const nums = node.args.map((arg) => num(evaluate(arg, values)));
73
+ if (nums.some((n) => n === null)) return null;
74
+ const list = nums as number[];
75
+ return node.fn === 'MIN' ? Math.min(...list) : Math.max(...list);
76
+ }
77
+ case 'ROUND': {
78
+ const value = num(evaluate(node.args[0], values));
79
+ if (value === null) return null;
80
+ const digits = node.args[1] ? Number((node.args[1] as { v: number }).v) : 0;
81
+ const factor = 10 ** digits;
82
+ // 先乘后除而不是 toFixed:toFixed 返回字符串,会让 number 型派生列悄悄变成 text
83
+ return Math.round(value * factor) / factor;
84
+ }
85
+ case 'ABS': {
86
+ const value = num(evaluate(node.args[0], values));
87
+ return value === null ? null : Math.abs(value);
88
+ }
89
+ case 'CONCAT': {
90
+ // 拼接里的 null 按空串:一段拼接不该因为其中一节没值就整体消失
91
+ return node.args.map((arg) => textOf(evaluate(arg, values))).join('');
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ /** 取数:复用与谓词图同一套数值/日期归一,保证「同一个值在两处判定一致」 */
99
+ function num(value: unknown): number | null {
100
+ return ordinalOf(value);
101
+ }
@@ -0,0 +1,12 @@
1
+ // calc 表达式层(REQ-010 S1a)——派生列与反应图 `value: { calc }` 的共同语言。
2
+ //
3
+ // 完整规格见 `prd/REQ-010-青出于蓝/模块类设计.md` L2.1(token 表 / 文法 / 类型规则 / 错误格式)。
4
+ // 一句话边界:**这不是表达式语言,是一张受限的算式表**——没有变量绑定、没有循环、
5
+ // 没有用户函数,函数名是六个的封闭集。想加第七个必须走需求文档,不许在 lexer 里顺手加。
6
+
7
+ export { SomaCalcSyntaxError, SomaCalcTypeError, type CalcSpan } from './errors';
8
+ export { tokenize, parseDateLiteral, CALC_FUNCTIONS, type CalcToken, type CalcTokenKind, type CalcFunctionName } from './lexer';
9
+ export { parseCalc, collectCalcRefs, type CalcAst, type CalcBinaryOp } from './parser';
10
+ export { inferCalcType, assertCalcResultType, type CalcType, type CalcTypeContext } from './typer';
11
+ export { evaluateCalc } from './evaluator';
12
+ export { ordinalOf, textOf } from './coerce';