soma-core 1.5.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/SomaPageClient.tsx +28 -9
- package/app/soma/manifest/route.ts +3 -0
- package/bin/migrate.cjs +71 -1
- package/bin/soma-lsp.cjs +8 -1
- package/core/build/blocks/block-compile.ts +23 -5
- package/core/build/compiler/full-manifest-builder.ts +15 -0
- package/core/build/compiler/page-assets.ts +17 -1
- package/core/build/compiler/page-declaration-compiler.ts +67 -11
- package/core/build/compiler/precompiled-manifest-loader.ts +7 -0
- package/core/build/compiler/soma-manifest-webpack-plugin.js +7 -0
- package/core/build/compiler/soma-precompile.js +212 -21
- package/core/build/component/package-loader.ts +35 -4
- package/core/build/component-tree/artifact-codec.ts +192 -0
- package/core/build/component-tree/binding-bridge.ts +272 -0
- package/core/build/component-tree/collection-binding-lowerer.ts +65 -0
- package/core/build/component-tree/definition-preparation.ts +320 -0
- package/core/build/component-tree/migration-files.ts +214 -0
- package/core/build/component-tree/migration.ts +170 -0
- package/core/build/component-tree/parser.ts +362 -0
- package/core/build/component-tree/registry-snapshot.ts +317 -0
- package/core/build/component-tree/source-preflight.ts +132 -0
- package/core/build/component-tree/structure-topology.ts +63 -0
- package/core/build/component-tree/validator.ts +318 -0
- package/core/build/eject/component-eject.ts +1 -0
- package/core/build/lsp/component-tree-service.ts +79 -0
- package/core/build/lsp/component-tree.cjs +42 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +15 -3
- package/core/build/lsp/extra-completion.cjs +7 -0
- package/core/client/adaptive/observer-pool.ts +122 -8
- package/core/client/compiler/manifest-compiler.ts +48 -5
- package/core/client/component/ai-catalog.ts +41 -3
- package/core/client/component/catalog-examples.ts +60 -0
- package/core/client/component/component-defaults.ts +1 -1
- package/core/client/component/component-definition.types.ts +9 -0
- package/core/client/component/component-expander.ts +22 -6
- package/core/client/component/component-manager.ts +881 -45
- package/core/client/component/component-pack.ts +1 -1
- package/core/client/component/component-registry.ts +11 -2
- package/core/client/component/scoped-adapter.ts +29 -2
- package/core/client/component/structure-adapter.ts +207 -0
- package/core/client/component/verify-pack.ts +21 -1
- package/core/client/container/SomaContainerAdapter.ts +103 -2
- package/core/client/data/data-object-resolver.ts +45 -1
- package/core/client/engine/asset-resolver.ts +1 -1
- package/core/client/engine/dom-renderer.ts +712 -26
- package/core/client/engine/event-engine.ts +328 -21
- package/core/client/engine/property-watcher.ts +164 -18
- package/core/client/engine/reactive-proxy.ts +194 -23
- package/core/client/engine/render-engine.ts +120 -11
- package/core/client/engine/row-range.ts +62 -0
- package/core/client/engine/row-scope.ts +77 -0
- package/core/client/engine/runtime-builder.ts +2 -0
- package/core/client/engine/scope-resolver.ts +3 -3
- package/core/client/engine/soma-bootstrap.ts +176 -17
- package/core/client/parser/adaptive-parser.ts +1 -1
- package/core/client/parser/annotation-extractor.ts +1 -1
- package/core/client/parser/blocks/page-parser.ts +53 -3
- package/core/client/parser/blocks/use-parser.ts +21 -6
- package/core/client/parser/data-config-parser.ts +1 -1
- package/core/client/parser/pipeline-parser.ts +252 -15
- package/core/client/parser/style-config-parser.ts +1 -1
- package/core/client/parser/timer-parser.ts +1 -1
- package/core/client/parser/trigger-parser.ts +1 -1
- package/core/client/parser/ui-config-parser.ts +39 -7
- package/core/client/pipes/pipe-registry.ts +45 -4
- package/core/client/registry/declaration-renderer.ts +32 -24
- package/core/client/registry/remote-page.ts +1 -1
- package/core/client/runtime/SomaSnapshotStore.ts +1 -1
- package/core/client/scheduler/SomaScheduler.ts +1 -1
- package/core/client/security/attribute-presence.ts +3 -0
- package/core/client/theme/harmony.ts +135 -13
- package/core/client/theme/scene-tokens.ts +17 -2
- package/core/client/theme/theme-axes.ts +43 -6
- package/core/client/theme/theme-engine.ts +921 -126
- package/core/client/validation/contract-validator.ts +2 -2
- package/core/index.ts +3 -0
- package/core/server/host/page-markup-config.ts +42 -0
- package/core/server/host/published-page-artifact-cache.ts +36 -4
- package/core/server/host/published-page-assets.ts +13 -7
- package/core/server/host/resolve-host-tree-context.ts +43 -0
- package/core/server/host/server-page-assets.ts +23 -4
- package/core/server/host/soma-page-compile.ts +10 -0
- package/core/server/mock/node/cli.mjs +3 -3
- package/core/server/page-declaration.ts +7 -0
- package/core/server/registry/declaration-precompiler.ts +35 -3
- package/core/server/registry/page-registry-repository.ts +31 -3
- package/core/server/registry/page-registry-store.ts +64 -7
- package/core/server/registry/publish-asset-pin.ts +6 -1
- package/core/server/registry/services/pages/Get.ts +11 -6
- package/core/server/registry/validation/compile-gate.ts +10 -1
- package/core/shared/component-tree-artifact.ts +237 -0
- package/core/shared/component-tree-errors.ts +52 -0
- package/core/shared/path-algebra.ts +1 -1
- package/core/shared/types/component-contract.types.ts +51 -0
- package/core/shared/types/component-tree-artifact.types.ts +121 -0
- package/core/shared/types/component-tree.types.ts +170 -0
- package/core/shared/types/engine.types.ts +5 -0
- package/core/shared/types/event.types.ts +8 -4
- package/core/shared/types/manifest.types.ts +4 -0
- package/core/shared/types/ui-config.types.ts +8 -0
- package/dist/cli/soma.js +1 -1
- package/dist/core/index.cjs +14508 -11358
- package/dist/lsp/component-tree.cjs +20997 -0
- package/dist/types/build/blocks/block-compile.d.ts +10 -1
- package/dist/types/build/compiler/full-manifest-builder.d.ts +9 -0
- package/dist/types/build/compiler/page-assets.d.ts +6 -1
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +11 -1
- package/dist/types/build/component/package-loader.d.ts +4 -1
- package/dist/types/build/component-tree/artifact-codec.d.ts +50 -0
- package/dist/types/build/component-tree/binding-bridge.d.ts +19 -0
- package/dist/types/build/component-tree/collection-binding-lowerer.d.ts +18 -0
- package/dist/types/build/component-tree/definition-preparation.d.ts +11 -0
- package/dist/types/build/component-tree/migration-files.d.ts +35 -0
- package/dist/types/build/component-tree/migration.d.ts +28 -0
- package/dist/types/build/component-tree/parser.d.ts +13 -0
- package/dist/types/build/component-tree/registry-snapshot.d.ts +15 -0
- package/dist/types/build/component-tree/source-preflight.d.ts +22 -0
- package/dist/types/build/component-tree/structure-topology.d.ts +7 -0
- package/dist/types/build/component-tree/validator.d.ts +9 -0
- package/dist/types/build/lsp/component-tree-service.d.ts +34 -0
- package/dist/types/client/adaptive/observer-pool.d.ts +9 -2
- package/dist/types/client/compiler/manifest-compiler.d.ts +11 -2
- package/dist/types/client/component/ai-catalog.d.ts +18 -1
- package/dist/types/client/component/catalog-examples.d.ts +18 -0
- package/dist/types/client/component/component-definition.types.d.ts +9 -0
- package/dist/types/client/component/component-expander.d.ts +2 -1
- package/dist/types/client/component/component-manager.d.ts +97 -0
- package/dist/types/client/component/scoped-adapter.d.ts +1 -0
- package/dist/types/client/component/structure-adapter.d.ts +17 -0
- package/dist/types/client/container/SomaContainerAdapter.d.ts +8 -0
- package/dist/types/client/data/data-object-resolver.d.ts +19 -0
- package/dist/types/client/engine/dom-renderer.d.ts +125 -2
- package/dist/types/client/engine/event-engine.d.ts +62 -3
- package/dist/types/client/engine/property-watcher.d.ts +41 -1
- package/dist/types/client/engine/reactive-proxy.d.ts +42 -2
- package/dist/types/client/engine/render-engine.d.ts +55 -3
- package/dist/types/client/engine/row-range.d.ts +13 -0
- package/dist/types/client/engine/row-scope.d.ts +20 -0
- package/dist/types/client/engine/runtime-builder.d.ts +1 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +4 -1
- package/dist/types/client/parser/blocks/use-parser.d.ts +18 -0
- package/dist/types/client/parser/pipeline-parser.d.ts +12 -4
- package/dist/types/client/parser/ui-config-parser.d.ts +2 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +39 -1
- package/dist/types/client/registry/declaration-renderer.d.ts +5 -1
- package/dist/types/client/registry/remote-page.d.ts +1 -1
- package/dist/types/client/theme/harmony.d.ts +44 -2
- package/dist/types/client/theme/scene-tokens.d.ts +11 -1
- package/dist/types/client/theme/theme-axes.d.ts +36 -6
- package/dist/types/index.d.ts +3 -1
- package/dist/types/server/host/page-markup-config.d.ts +6 -0
- package/dist/types/server/host/published-page-artifact-cache.d.ts +9 -1
- package/dist/types/server/host/published-page-assets.d.ts +5 -3
- package/dist/types/server/host/resolve-host-tree-context.d.ts +8 -0
- package/dist/types/server/host/server-page-assets.d.ts +6 -0
- package/dist/types/server/host/soma-page-compile.d.ts +10 -1
- package/dist/types/server/page-declaration.d.ts +6 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +8 -3
- package/dist/types/server/registry/page-registry-repository.d.ts +5 -0
- package/dist/types/server/registry/page-registry-store.d.ts +11 -1
- package/dist/types/server/registry/publish-asset-pin.d.ts +4 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +4 -1
- package/dist/types/shared/component-tree-artifact.d.ts +5 -0
- package/dist/types/shared/component-tree-errors.d.ts +22 -0
- package/dist/types/shared/types/component-contract.types.d.ts +42 -0
- package/dist/types/shared/types/component-tree-artifact.types.d.ts +104 -0
- package/dist/types/shared/types/component-tree.types.d.ts +149 -0
- package/dist/types/shared/types/engine.types.d.ts +5 -0
- package/dist/types/shared/types/event.types.d.ts +8 -4
- package/dist/types/shared/types/manifest.types.d.ts +4 -0
- package/dist/types/shared/types/ui-config.types.d.ts +8 -0
- package/package.json +5 -4
- package/dist/preview-export.cjs +0 -3401
|
@@ -19,7 +19,7 @@ export class SomaEventParseError extends Error {
|
|
|
19
19
|
public readonly rawExpression: string;
|
|
20
20
|
|
|
21
21
|
constructor(message: string, rawExpression: string) {
|
|
22
|
-
super(`[
|
|
22
|
+
super(`[soma-core][引擎] ${message} — 原始表达式: "${rawExpression}"`);
|
|
23
23
|
this.name = 'SomaEventParseError';
|
|
24
24
|
this.rawExpression = rawExpression;
|
|
25
25
|
}
|
|
@@ -27,8 +27,16 @@ export class SomaEventParseError extends Error {
|
|
|
27
27
|
|
|
28
28
|
// ─── 常量 ─────────────────────────────────────────────────────────────────────
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 管道表达式能写出来的事件类型。
|
|
32
|
+
*
|
|
33
|
+
* 刻意排掉 `STEPS`:编排事件只从 `{ steps: [...] }` 对象形态来,一串步骤压不进一行竖线文本
|
|
34
|
+
* (见 event.types 的注释)。分出这个别名,槽数表与 URL 槽表才能按类型穷举、漏一个当场编译报错。
|
|
35
|
+
*/
|
|
36
|
+
type PipelineEventType = Exclude<EventType, 'STEPS'>;
|
|
37
|
+
|
|
30
38
|
/** 支持的事件类型 */
|
|
31
|
-
const VALID_TYPES = new Set<
|
|
39
|
+
const VALID_TYPES = new Set<PipelineEventType>([
|
|
32
40
|
'NAV_STATIC',
|
|
33
41
|
'NAV_ACTION',
|
|
34
42
|
'UI_REFRESH',
|
|
@@ -36,10 +44,51 @@ const VALID_TYPES = new Set<EventType>([
|
|
|
36
44
|
'ACTION',
|
|
37
45
|
]);
|
|
38
46
|
|
|
39
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* 支持的 DOM 事件
|
|
49
|
+
*
|
|
50
|
+
* focus / blur 不冒泡,事件引擎改挂 focusin / focusout 委托;focusin / focusout 本身
|
|
51
|
+
* 会冒泡,直接委托。两组的分发规则相同(从 target 向上找最近一个声明者),处理器拿到的
|
|
52
|
+
* 都是 focusin / focusout 事件(`x.focus` 的 event.type 也是 focusin),区别只在查表用的键:
|
|
53
|
+
* `focus:<somaId>` 与 `focusin:<somaId>` 各查各的,同一锚点两个都声明时各执行一次。
|
|
54
|
+
* 焦点在外层声明者的子树内部移动、而内部元素自己没声明时,外层每次移动都会收到一对
|
|
55
|
+
* blur/focus,"真正离开"用 relatedTarget 判断。
|
|
56
|
+
* mouseenter / mouseleave / scroll 不冒泡,内部元素上的声明到不了委托监听。
|
|
57
|
+
*
|
|
58
|
+
* **mousedown / pointerdown 为什么不进这张表(2026-09-20 裁决,不是漏了)**
|
|
59
|
+
*
|
|
60
|
+
* 先说清现状:它们不在表里,并不等于"声明不出来"。两段式选择器按 EMIT_NAME_PATTERN 放行,
|
|
61
|
+
* 事件引擎照样按事件名挂委托监听(event-engine 的 init),`tool.mousedown` 今天就能触发。
|
|
62
|
+
* 表里表外的差别只有三项:解析期的那条告警、`isKnownDomEvent` 的分类、三段式按键修饰符的资格。
|
|
63
|
+
* 所以"按下工具栏时不让编辑区失焦"做不成,病根不在白名单。
|
|
64
|
+
*
|
|
65
|
+
* 病根在 preventDefault 的时序:委托监听只把处理器交给调度器,处理器晚于监听回调执行
|
|
66
|
+
* (见 event-engine 的 SYNC_PREVENT_DEFAULT 注释)。调度器空闲时处理器赶在派发结束前跑完,
|
|
67
|
+
* preventDefault 生效;调度器忙、同帧已有 rAF 渲染补丁排队、或事件由脚本派发时,处理器落到
|
|
68
|
+
* 派发之后,preventDefault 什么也不做。把 mousedown 放进白名单,等于给页面作者一条
|
|
69
|
+
* "多数时候保得住焦点、偶尔保不住"的写法——失败时没有任何报错,只是选区丢了、
|
|
70
|
+
* 一份过时的中间稿被上抛。这正是最不该有的那种失败:系统猜错了还装作正确。
|
|
71
|
+
*
|
|
72
|
+
* 那把 mousedown 一起塞进 SYNC_PREVENT_DEFAULT(像 submit 那样由引擎同步阻止)行不行?更糟。
|
|
73
|
+
* submit 的默认动作只有一件事(整页提交),声明 submit 的人无一例外要单页行为;
|
|
74
|
+
* mousedown 的默认动作是一组:交出焦点、起始文本选区、起始原生拖拽、中键自动滚屏。
|
|
75
|
+
* 无条件阻止会把声明者子树里的文本选中能力一并掐掉,同样是静默的坏。
|
|
76
|
+
*
|
|
77
|
+
* 还有两条只在放行之后才会显形的坏写法,且都静默:
|
|
78
|
+
* - 拿 mousedown 当 click 用——键盘激活(Enter / Space)只产生 click,不产生 mousedown,
|
|
79
|
+
* 于是控件对键盘用户是死的,页面上看不出来;
|
|
80
|
+
* - 触屏上 mousedown 是合成事件,派发在 pointerup / touchend 之后
|
|
81
|
+
* (见 soma-ui/doc 组件体系与契约 §"触摸下的外点收口"),同一条声明在鼠标与手指下
|
|
82
|
+
* 执行次序不同,而作者按鼠标的次序写。
|
|
83
|
+
*
|
|
84
|
+
* 结论:不加。要在按下那一刻同步 preventDefault 的,只能走手册给的那条路——封装成组件,
|
|
85
|
+
* 由控制器把监听直接挂到元素上、在监听里同步调用 preventDefault,再经契约 emit 上报
|
|
86
|
+
* (库内先例:soma-ui 的 shared/press.ts preventFocusOnPress、rich-text-editor 的
|
|
87
|
+
* keepSelectionOnToolPress)。这条路不是权宜之计,它是目前唯一能保证时序的写法。
|
|
88
|
+
*/
|
|
40
89
|
const VALID_DOM_EVENTS = new Set<string>([
|
|
41
90
|
'click', 'dblclick', 'input', 'change', 'blur',
|
|
42
|
-
'focus', 'mouseenter', 'mouseleave', 'submit',
|
|
91
|
+
'focus', 'focusin', 'focusout', 'mouseenter', 'mouseleave', 'submit',
|
|
43
92
|
'keydown', 'keyup', 'scroll',
|
|
44
93
|
]);
|
|
45
94
|
|
|
@@ -52,6 +101,43 @@ const VALID_ACTIONS = new Set<InteractAction>([
|
|
|
52
101
|
/** 组件契约 emit 名(两段式触发器放行;运行时由组件管理器标记路由) */
|
|
53
102
|
const EMIT_NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
54
103
|
|
|
104
|
+
const HOVER_ALTERNATIVE = '悬停样式用 Style transitions 的 hover;悬停才出现的提示或面板用 click、focusin / focusout,或 Tooltip 组件';
|
|
105
|
+
const CONTROLLER_ALTERNATIVE = '封装成组件,由控制器把监听直接挂到元素上,再经契约 emit 上报';
|
|
106
|
+
|
|
107
|
+
function hintGroup(names: readonly string[], hint: string): [string, string][] {
|
|
108
|
+
return names.map((name) => [name, hint]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 常见但不在 VALID_DOM_EVENTS 里的 DOM 事件名 → 告警里的现状说明与替代写法。
|
|
113
|
+
*
|
|
114
|
+
* 两段式选择器按 EMIT_NAME_PATTERN 放行 snake_case 名,而解析时手上既没有组件注册表、也没有
|
|
115
|
+
* 页面 HTML,分不清 somaId 是组件实例还是普通锚点,硬拦会误伤合法 emit。没匹配上契约 emit 的
|
|
116
|
+
* 订阅(普通锚点,或契约里没有这个 emit 的组件实例)不走 emit 路由,引擎按事件名原样挂委托监听:
|
|
117
|
+
* 会冒泡的照样触发,不冒泡的永远不执行,两种都在白名单约定之外。所以对这些名字只告警、不改解析结果。
|
|
118
|
+
*
|
|
119
|
+
* 只收 DOM 专有的名字。与组件 emit 同名的 DOM 事件不收——select / toggle / close / cancel /
|
|
120
|
+
* reset / search / copy / error / invalid 都是 soma-ui 契约里在用的 emit 名,收了合法订阅每次解析都告警。
|
|
121
|
+
*/
|
|
122
|
+
const UNLISTED_DOM_EVENT_HINTS: ReadonlyMap<string, string> = new Map([
|
|
123
|
+
...hintGroup(['mouseover', 'mouseout', 'pointerover', 'pointerout'],
|
|
124
|
+
`会冒泡,但指针在锚点内的子元素之间移动时会反复触发。替代写法:${HOVER_ALTERNATIVE}`),
|
|
125
|
+
...hintGroup(['pointerenter', 'pointerleave'],
|
|
126
|
+
`不冒泡,内层锚点上的声明永远不会执行。替代写法:${HOVER_ALTERNATIVE}`),
|
|
127
|
+
...hintGroup(['mousedown', 'mouseup', 'pointerdown', 'pointerup', 'touchstart', 'touchend'],
|
|
128
|
+
`会冒泡,能触发。替代写法:改用 click;确实要区分按下与抬起时${CONTROLLER_ALTERNATIVE}`),
|
|
129
|
+
...hintGroup(['mousemove', 'pointermove', 'touchmove', 'wheel'],
|
|
130
|
+
`会冒泡,每次派发都执行一遍 Pipeline。替代写法:${CONTROLLER_ALTERNATIVE}`),
|
|
131
|
+
...hintGroup(['contextmenu', 'auxclick', 'pointercancel', 'touchcancel', 'dragstart', 'dragend',
|
|
132
|
+
'dragenter', 'dragleave', 'dragover', 'animationend', 'transitionend'],
|
|
133
|
+
`会冒泡,能触发。替代写法:${CONTROLLER_ALTERNATIVE}`),
|
|
134
|
+
...hintGroup(['scrollend'],
|
|
135
|
+
`在元素上不冒泡,内层锚点上的声明永远不会执行。替代写法:${CONTROLLER_ALTERNATIVE}`),
|
|
136
|
+
...hintGroup(['keypress'], '会冒泡,能触发,但已被浏览器弃用。替代写法:改用 keydown'),
|
|
137
|
+
...hintGroup(['beforeinput', 'compositionstart', 'compositionupdate', 'compositionend'],
|
|
138
|
+
'会冒泡,能触发。替代写法:改用 input'),
|
|
139
|
+
]);
|
|
140
|
+
|
|
55
141
|
/** 是否为已知 DOM 事件(组件管理器区分 DOM 订阅与疑似 emit 订阅用) */
|
|
56
142
|
export function isKnownDomEvent(name: string): boolean {
|
|
57
143
|
return VALID_DOM_EVENTS.has(name);
|
|
@@ -96,9 +182,62 @@ const CONFIRM_PREFIX = 'confirm:';
|
|
|
96
182
|
/** Pipeline optional permission segment prefix */
|
|
97
183
|
const PERMISSION_PREFIX = 'permission:';
|
|
98
184
|
|
|
185
|
+
/** UI_INTERACT 具名动作段(REQ-005 F7.2):与位置式第 3 槽等价,两种写法不得同给 */
|
|
186
|
+
const ACTION_PREFIX = 'action:';
|
|
187
|
+
|
|
99
188
|
/** UI_REFRESH 显式全量渲染段 */
|
|
100
189
|
const FORCE_SEGMENT = 'force';
|
|
101
190
|
|
|
191
|
+
/** 具名段前缀闭集(报错时原样列出,让人知道能写哪几个) */
|
|
192
|
+
const NAMED_SEGMENT_PREFIXES = [CONFIRM_PREFIX, PERMISSION_PREFIX, ACTION_PREFIX] as const;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 疑似具名段的形状:小写标识符紧跟冒号。
|
|
196
|
+
*
|
|
197
|
+
* 这条判断存在的理由是**拼错的前缀此前会被当成位置值悄悄吃掉**:
|
|
198
|
+
* `UI_REFRESH | page.delete | confrim:确定删除?` 里第 2 段是 UI_REFRESH 根本不读的槽,
|
|
199
|
+
* 于是整条确认框无声消失——按下删除直接删,页面上看不出少了一道闸。
|
|
200
|
+
* 同一类还有段数写多(`UI_REFRESH | page.save | page.also` 的第 2 个路径)与把 `| force`
|
|
201
|
+
* 写在 UI_REFRESH 之外(事件引擎只在 UI_REFRESH 上认它,别处写了等于没写)。
|
|
202
|
+
* 现在这三种都当场报错(见 parsePipelineBody 的段数与前缀校验)。
|
|
203
|
+
*
|
|
204
|
+
* targetUrl 槽不套这条:`https://…`、`mailto:…` 都合法带冒号,那一槽的值域拦不住也不该拦。
|
|
205
|
+
*/
|
|
206
|
+
const NAMED_SEGMENT_SHAPE = /^[a-z][a-z0-9_]*:/;
|
|
207
|
+
|
|
208
|
+
/** 各动词的位置参数槽数(不含动词本身)。超出的段以前静默丢弃,现在报错 */
|
|
209
|
+
const POSITIONAL_ARITY: Readonly<Record<PipelineEventType, number>> = {
|
|
210
|
+
NAV_STATIC: 1,
|
|
211
|
+
NAV_ACTION: 2,
|
|
212
|
+
UI_REFRESH: 1,
|
|
213
|
+
ACTION: 1,
|
|
214
|
+
UI_INTERACT: 3,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** 值可以合法带冒号的槽(targetUrl):按动词记槽位,前缀校验跳过它 */
|
|
218
|
+
const URL_SLOT: ReadonlyMap<PipelineEventType, number> = new Map<PipelineEventType, number>([
|
|
219
|
+
['NAV_STATIC', 1],
|
|
220
|
+
['NAV_ACTION', 2],
|
|
221
|
+
]);
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 动词缺省(REQ-005 F7.1):首段不是动词、而是一条合法 funcPath 时按 UI_REFRESH 补齐。
|
|
225
|
+
* 实测 92% 的事件行是 UI_REFRESH,写全动词等于每行都复述一遍缺省值。
|
|
226
|
+
*
|
|
227
|
+
* **判别是算得准的,不是猜的**:五个动词是全大写封闭集,funcPath 一律小写起头、至少两段
|
|
228
|
+
* (`page.save`)——两个集合不相交。写错的动词(`UI_REFRESHH` / `ui_refresh` / `REFRESH`)
|
|
229
|
+
* 一个都不满足本式,照旧报"未知事件类型",不会被当成路径悄悄放行;
|
|
230
|
+
* 反过来 `page.save` 也绝不会被误读成动词。缺省只在两种形状都判定完之后才发生。
|
|
231
|
+
*/
|
|
232
|
+
const IMPLICIT_REFRESH_FUNC_PATH = /^[a-z][A-Za-z0-9_]*(?:\.[A-Za-z0-9_]+)+$/;
|
|
233
|
+
|
|
234
|
+
/** 未知具名段前缀的报错文案:指出写错的前缀与可用闭集 */
|
|
235
|
+
function unknownPrefixMessage(segment: string): string {
|
|
236
|
+
const name = segment.slice(0, segment.indexOf(':') + 1);
|
|
237
|
+
return `未知的具名段前缀 "${name}",可用: ${NAMED_SEGMENT_PREFIXES.join(' / ')}`
|
|
238
|
+
+ `(写错前缀的段以前被当成位置值吃掉:confirm 拼错一个字母就等于整条确认框消失)`;
|
|
239
|
+
}
|
|
240
|
+
|
|
102
241
|
import { VALID_KEY_MODIFIER_NAMES } from '../../shared/types/keyboard.types';
|
|
103
242
|
|
|
104
243
|
/** 支持的键盘修饰符(从统一定义导入) */
|
|
@@ -110,7 +249,8 @@ const VALID_KEY_MODIFIERS = VALID_KEY_MODIFIER_NAMES;
|
|
|
110
249
|
* 解析事件选择器字符串
|
|
111
250
|
*
|
|
112
251
|
* 支持两种格式:
|
|
113
|
-
* - 两段式:`btn.click`(somaId.domEvent
|
|
252
|
+
* - 两段式:`btn.click`(somaId.domEvent);事件名也可以是组件契约 emit 名,
|
|
253
|
+
* 白名单外的常见 DOM 事件名照样放行,但会 console.warn(见 UNLISTED_DOM_EVENT_HINTS)
|
|
114
254
|
* - 三段式:`input.keydown.enter`(somaId.domEvent.keyModifier)
|
|
115
255
|
*
|
|
116
256
|
* @param selector - 选择器字符串
|
|
@@ -133,7 +273,9 @@ export function parseSelector(
|
|
|
133
273
|
// 标准格式:somaId.event(如 btn_refresh.click)
|
|
134
274
|
// 组件契约 emit:somaId.emit名(如 qty.change、stepper.reach_limit)——
|
|
135
275
|
// emit 名与 DOM 事件同构,snake_case 命名放行;是否匹配真实契约由
|
|
136
|
-
// 组件管理器在运行时标记(emitRoute
|
|
276
|
+
// 组件管理器在运行时标记(emitRoute)。没匹配上的不走 emit 路由,引擎按事件名原样
|
|
277
|
+
// 挂委托监听:拼错的 emit 名等不到同名 DOM 事件,永远不触发;与 DOM 事件同名的
|
|
278
|
+
// 会被真实 DOM 事件触发,常见的那些在这里告警(UNLISTED_DOM_EVENT_HINTS)。
|
|
137
279
|
const [somaId, domEvent] = parts;
|
|
138
280
|
|
|
139
281
|
if (!somaId) {
|
|
@@ -149,6 +291,17 @@ export function parseSelector(
|
|
|
149
291
|
);
|
|
150
292
|
}
|
|
151
293
|
|
|
294
|
+
const unlistedHint = UNLISTED_DOM_EVENT_HINTS.get(domEvent);
|
|
295
|
+
if (unlistedHint) {
|
|
296
|
+
console.warn(
|
|
297
|
+
`[soma-core][引擎] 事件解析 "${selector}":${domEvent} 不在支持的 DOM 事件里,按组件契约 emit 名放行` +
|
|
298
|
+
`(解析时看不到组件注册表,分不清 ${somaId} 是不是组件实例)。` +
|
|
299
|
+
`${somaId} 是组件实例、契约声明了 emit "${domEvent}" 时忽略本提示;` +
|
|
300
|
+
`否则不走 emit 路由,引擎按原生事件名原样委托——${domEvent} ${unlistedHint}。` +
|
|
301
|
+
`支持的 DOM 事件: ${[...VALID_DOM_EVENTS].join(', ')}`,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
152
305
|
return { somaId, domEvent };
|
|
153
306
|
}
|
|
154
307
|
|
|
@@ -188,17 +341,21 @@ export function parseSelector(
|
|
|
188
341
|
// ─── Pipeline 表达式解析 ──────────────────────────────────────────────────────
|
|
189
342
|
|
|
190
343
|
/**
|
|
191
|
-
*
|
|
344
|
+
* 从管道段中提取可选具名段(confirm / permission / action)与 force 段,返回不含这些段的段列表。
|
|
345
|
+
*
|
|
346
|
+
* 具名段抽走之后剩下的就是纯位置段,段数与前缀校验(见 parsePipelineBody)因此能按槽位直接判。
|
|
192
347
|
*/
|
|
193
348
|
function splitOptionalSegments(parts: string[]): {
|
|
194
349
|
segments: string[];
|
|
195
350
|
confirm?: string;
|
|
196
351
|
refreshForce?: boolean;
|
|
197
352
|
permission?: string;
|
|
353
|
+
action?: string;
|
|
198
354
|
} {
|
|
199
355
|
let confirm: string | undefined;
|
|
200
356
|
let refreshForce = false;
|
|
201
357
|
let permission: string | undefined;
|
|
358
|
+
let action: string | undefined;
|
|
202
359
|
const segments: string[] = [];
|
|
203
360
|
|
|
204
361
|
for (let index = 0; index < parts.length; index++) {
|
|
@@ -223,26 +380,96 @@ function splitOptionalSegments(parts: string[]): {
|
|
|
223
380
|
permission = code;
|
|
224
381
|
continue;
|
|
225
382
|
}
|
|
383
|
+
if (index > 0 && part.startsWith(ACTION_PREFIX)) {
|
|
384
|
+
const name = part.slice(ACTION_PREFIX.length).trim();
|
|
385
|
+
if (!name) {
|
|
386
|
+
throw new SomaEventParseError('action segment requires an action name', parts.join(' | '));
|
|
387
|
+
}
|
|
388
|
+
if (action !== undefined) {
|
|
389
|
+
throw new SomaEventParseError(`具名段 "action:" 写了两次`, parts.join(' | '));
|
|
390
|
+
}
|
|
391
|
+
action = name;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
226
394
|
segments.push(part);
|
|
227
395
|
}
|
|
228
396
|
|
|
229
|
-
return { segments, confirm, refreshForce, permission };
|
|
397
|
+
return { segments, confirm, refreshForce, permission, action };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* 段数与具名段前缀校验。
|
|
402
|
+
*
|
|
403
|
+
* 在此之前,动词读不到的段一律被静默丢弃——丢掉的最常是写错前缀的 `confirm:`,
|
|
404
|
+
* 于是"删除前要确认"这条声明在页面上不存在,而谁都看不出来。这里把两类都收口:
|
|
405
|
+
* - 位置槽里出现疑似具名段(targetUrl 槽除外,它本就能带冒号);
|
|
406
|
+
* - 段数超过本动词的槽数(末尾多写的 `|` 不带信息,照旧放行)。
|
|
407
|
+
*/
|
|
408
|
+
function assertSegmentShape(type: PipelineEventType, parts: string[], expression: string): void {
|
|
409
|
+
const arity = POSITIONAL_ARITY[type];
|
|
410
|
+
const urlSlot = URL_SLOT.get(type);
|
|
411
|
+
|
|
412
|
+
for (let slot = 1; slot < parts.length; slot++) {
|
|
413
|
+
const value = parts[slot];
|
|
414
|
+
if (slot !== urlSlot && NAMED_SEGMENT_SHAPE.test(value)) {
|
|
415
|
+
throw new SomaEventParseError(unknownPrefixMessage(value), expression);
|
|
416
|
+
}
|
|
417
|
+
if (slot <= arity || !value) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
throw new SomaEventParseError(
|
|
421
|
+
`${type} 最多 ${arity} 个参数段,第 ${slot} 段 "${value}" 没有对应的槽`
|
|
422
|
+
+ `(多写的段以前被静默丢弃,现在当场报错)`,
|
|
423
|
+
expression,
|
|
424
|
+
);
|
|
425
|
+
}
|
|
230
426
|
}
|
|
231
427
|
|
|
232
428
|
/**
|
|
233
429
|
* 解析 Pipeline 表达式体(不含 DOM 选择器,供 timers 块使用)
|
|
430
|
+
*
|
|
431
|
+
* 动词可缺省(REQ-005 F7.1):首段是小写起头、至少两段的 funcPath 时按 UI_REFRESH 补齐,
|
|
432
|
+
* `page.save` 等价于 `UI_REFRESH | page.save`。NAV_* / UI_INTERACT / ACTION 仍须显式写动词——
|
|
433
|
+
* 它们各带副作用(跳页、开关浮层、跑注册动作),不该靠缺省值决定。
|
|
234
434
|
*/
|
|
235
435
|
export function parsePipelineBody(
|
|
236
436
|
expression: string,
|
|
237
437
|
): Omit<ParsedEvent, 'somaId' | 'domEvent'> {
|
|
238
438
|
const rawParts = expression.split('|').map((s) => s.trim());
|
|
239
|
-
const {
|
|
240
|
-
|
|
439
|
+
const {
|
|
440
|
+
segments: parts, confirm, refreshForce, permission, action: namedAction,
|
|
441
|
+
} = splitOptionalSegments(rawParts);
|
|
442
|
+
|
|
443
|
+
// 动词缺省:首段判定为 funcPath 就把 UI_REFRESH 补回段列表,后面一切照旧按槽位读。
|
|
444
|
+
// 补在这里而不是各分支里,是为了让段数校验、`| force`、confirm 全部走同一条路。
|
|
445
|
+
if (!VALID_TYPES.has(parts[0] as PipelineEventType) && IMPLICIT_REFRESH_FUNC_PATH.test(parts[0])) {
|
|
446
|
+
parts.unshift('UI_REFRESH');
|
|
447
|
+
}
|
|
448
|
+
const type = parts[0] as PipelineEventType;
|
|
241
449
|
|
|
242
450
|
if (!VALID_TYPES.has(type)) {
|
|
243
451
|
throw new SomaEventParseError(
|
|
244
452
|
`未知事件类型 "${type}",` +
|
|
245
|
-
`支持的类型: ${[...VALID_TYPES].join(', ')}
|
|
453
|
+
`支持的类型: ${[...VALID_TYPES].join(', ')};` +
|
|
454
|
+
`省略动词按 UI_REFRESH 处理,但首段须是小写起头、至少两段的 funcPath(如 page.save)`,
|
|
455
|
+
expression,
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
assertSegmentShape(type, parts, expression);
|
|
460
|
+
|
|
461
|
+
if (namedAction !== undefined && type !== 'UI_INTERACT') {
|
|
462
|
+
throw new SomaEventParseError(
|
|
463
|
+
`具名段 "action:" 只属于 UI_INTERACT,${type} 没有动作槽`,
|
|
464
|
+
expression,
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// `| force` 同理:事件引擎只在 UI_REFRESH 上读 refreshForce(见 event-engine 的 forceRefresh),
|
|
469
|
+
// 写在别的动词上是个不报错的空操作——作者以为要了全量渲染,实际什么都没发生
|
|
470
|
+
if (refreshForce && type !== 'UI_REFRESH') {
|
|
471
|
+
throw new SomaEventParseError(
|
|
472
|
+
`可选段 "force" 只属于 UI_REFRESH(全量渲染),${type} 上写了不会生效`,
|
|
246
473
|
expression,
|
|
247
474
|
);
|
|
248
475
|
}
|
|
@@ -304,7 +531,14 @@ export function parsePipelineBody(
|
|
|
304
531
|
result.targetId = parts[1] || undefined;
|
|
305
532
|
result.funcPath = parts[2] || null;
|
|
306
533
|
{
|
|
307
|
-
|
|
534
|
+
// 具名段与位置式等价,同给即报错:两处写的不一样时按谁都是猜
|
|
535
|
+
if (namedAction !== undefined && parts[3]) {
|
|
536
|
+
throw new SomaEventParseError(
|
|
537
|
+
`UI_INTERACT 的动作同时写了具名段 "action:${namedAction}" 与位置式 "${parts[3]}",只能留一种`,
|
|
538
|
+
expression,
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
const action = namedAction || parts[3] || 'toggle';
|
|
308
542
|
if (!VALID_ACTIONS.has(action as InteractAction)) {
|
|
309
543
|
throw new SomaEventParseError(
|
|
310
544
|
`不支持的交互动作 "${action}",` +
|
|
@@ -328,9 +562,12 @@ export function parsePipelineBody(
|
|
|
328
562
|
* 各类型管道签名:
|
|
329
563
|
* - NAV_STATIC | targetUrl
|
|
330
564
|
* - NAV_ACTION | funcPath | targetUrl
|
|
331
|
-
* - UI_REFRESH | funcPath [| force]
|
|
332
|
-
* - UI_INTERACT | targetId | funcPath | action
|
|
333
|
-
* -
|
|
565
|
+
* - UI_REFRESH | funcPath [| force](动词可缺省:`page.save` 即 `UI_REFRESH | page.save`)
|
|
566
|
+
* - UI_INTERACT | targetId | funcPath | action(第 3 槽也可写具名段 `action:open`)
|
|
567
|
+
* - ACTION | 动作名
|
|
568
|
+
* - 任意类型均可在末尾追加可选段 confirm:确认文案 / permission:权限点
|
|
569
|
+
*
|
|
570
|
+
* 槽数与具名段前缀都是封闭的:读不到的段与拼错的前缀当场报错,不再静默丢弃。
|
|
334
571
|
*
|
|
335
572
|
* @param selector - 事件选择器(如 "btn.click")
|
|
336
573
|
* @param expression - Pipeline 表达式(如 "NAV_STATIC | /home.html")
|
|
@@ -19,7 +19,7 @@ export class SomaStyleConfigError extends Error {
|
|
|
19
19
|
|
|
20
20
|
constructor(message: string, path: string = '', kind?: SomaStyleViolationKind) {
|
|
21
21
|
const prefix = path ? ` (路径: ${path})` : '';
|
|
22
|
-
super(`[
|
|
22
|
+
super(`[soma-core][引擎] ${message}${prefix}`);
|
|
23
23
|
this.name = 'SomaStyleConfigError';
|
|
24
24
|
this.path = path;
|
|
25
25
|
this.kind = kind;
|
|
@@ -5,7 +5,7 @@ import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
|
5
5
|
|
|
6
6
|
export class SomaTimerParseError extends Error {
|
|
7
7
|
constructor(message: string) {
|
|
8
|
-
super(`[
|
|
8
|
+
super(`[soma-core][引擎] ${message}`);
|
|
9
9
|
this.name = 'SomaTimerParseError';
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -6,7 +6,7 @@ import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
|
6
6
|
|
|
7
7
|
export class SomaTriggerParseError extends Error {
|
|
8
8
|
constructor(message: string) {
|
|
9
|
-
super(`[
|
|
9
|
+
super(`[soma-core][引擎] ${message}`);
|
|
10
10
|
this.name = 'SomaTriggerParseError';
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -43,7 +43,7 @@ export class SomaUiConfigError extends Error {
|
|
|
43
43
|
|
|
44
44
|
constructor(message: string, path: string = '') {
|
|
45
45
|
const prefix = path ? ` (路径: ${path})` : '';
|
|
46
|
-
super(`[
|
|
46
|
+
super(`[soma-core][引擎] ${message}${prefix}`);
|
|
47
47
|
this.name = 'SomaUiConfigError';
|
|
48
48
|
this.path = path;
|
|
49
49
|
}
|
|
@@ -52,6 +52,8 @@ export class SomaUiConfigError extends Error {
|
|
|
52
52
|
// ─── 解析选项 ─────────────────────────────────────────────────────────────────
|
|
53
53
|
|
|
54
54
|
export interface SomaUiConfigParseOptions {
|
|
55
|
+
/** Raw collectionSlot is trusted package source only; runtimes consume plan references. */
|
|
56
|
+
collectionBindingStage?: 'definition-source' | 'runtime';
|
|
55
57
|
/**
|
|
56
58
|
* 阶梯词汇表(F-09)。core 不内置任何级语义,词汇由宿主 bootstrap 注入;
|
|
57
59
|
* 不传而页面声明了 `adaptive.ladder` 时,按"词汇未知"快速失败。
|
|
@@ -110,6 +112,20 @@ function validateBind(bind: any, path: string): asserts bind is BindDeclaration
|
|
|
110
112
|
if ('onChange' in bind && bind.onChange !== undefined) {
|
|
111
113
|
parseOnChangeRules(bind.onChange, `${path}.onChange`);
|
|
112
114
|
}
|
|
115
|
+
if (bind.key !== undefined && (typeof bind.key !== 'string'
|
|
116
|
+
|| !bind.key.startsWith(`${bind.var}.`)
|
|
117
|
+
|| !/^[$A-Z_a-z][$\w]*(?:\.[$A-Z_a-z][$\w]*)+$/.test(bind.key)
|
|
118
|
+
|| bind.key.split('.').some((part: string) => ['__proto__', 'prototype', 'constructor'].includes(part)))) {
|
|
119
|
+
throw new SomaUiConfigError('bind.key 必须是当前行变量的安全字段路径', path);
|
|
120
|
+
}
|
|
121
|
+
if (bind.repeatPlanId !== undefined && (typeof bind.repeatPlanId !== 'string' || !bind.repeatPlanId.trim()
|
|
122
|
+
|| bind.key !== undefined || bind.collectionSlot !== undefined)) {
|
|
123
|
+
throw new SomaUiConfigError('repeatPlanId 必须是非空引用且不能与 key/collectionSlot 双写', path);
|
|
124
|
+
}
|
|
125
|
+
if (bind.collectionSlot !== undefined && (typeof bind.collectionSlot !== 'string' || !bind.collectionSlot.trim()
|
|
126
|
+
|| bind.key === undefined)) {
|
|
127
|
+
throw new SomaUiConfigError('collectionSlot 必须具名并提供唯一显式 key', path);
|
|
128
|
+
}
|
|
113
129
|
}
|
|
114
130
|
|
|
115
131
|
function parseOnChangeRules(raw: unknown, path: string): OnChangeRule[] {
|
|
@@ -172,7 +188,7 @@ function parseInitProps(raw: unknown, path: string): Record<string, unknown> {
|
|
|
172
188
|
/**
|
|
173
189
|
* 判断一个对象值是否为嵌套绑定(含 bind + show)
|
|
174
190
|
*/
|
|
175
|
-
function isNestedShowMapping(value: any): value is { bind: any; show: any; when?: unknown } {
|
|
191
|
+
function isNestedShowMapping(value: any): value is { bind: any; show: any; when?: unknown; props?: unknown } {
|
|
176
192
|
return (
|
|
177
193
|
typeof value === 'object' &&
|
|
178
194
|
value !== null &&
|
|
@@ -205,7 +221,7 @@ function isExtendedShowValue(value: any): boolean {
|
|
|
205
221
|
* @returns 类型安全的 ShowMapping
|
|
206
222
|
* @throws SomaUiConfigError 格式不合法时抛出
|
|
207
223
|
*/
|
|
208
|
-
function parseShowMapping(rawShow: any, path: string): ShowMapping {
|
|
224
|
+
function parseShowMapping(rawShow: any, path: string, options?: SomaUiConfigParseOptions): ShowMapping {
|
|
209
225
|
if (!rawShow || typeof rawShow !== 'object') {
|
|
210
226
|
throw new SomaUiConfigError(`show 必须是对象`, path);
|
|
211
227
|
}
|
|
@@ -225,23 +241,36 @@ function parseShowMapping(rawShow: any, path: string): ShowMapping {
|
|
|
225
241
|
} else if (/^item:.+/.test(key) && typeof value === 'object' && value !== null
|
|
226
242
|
&& !isNestedShowMapping(value) && !isExtendedShowValue(value)) {
|
|
227
243
|
// 异构列表分组键:item:变体 → 仅该变体行生效的子映射(DSL 扩展规范 2.1)
|
|
228
|
-
result[key] = { show: parseShowMapping(value, currentPath) };
|
|
244
|
+
result[key] = { show: parseShowMapping(value, currentPath, options) };
|
|
229
245
|
} else if (isNestedShowMapping(value)) {
|
|
230
246
|
// 嵌套绑定:含 bind + show
|
|
231
247
|
const nestedPath = `${currentPath}.bind`;
|
|
232
248
|
validateBind(value.bind, nestedPath);
|
|
249
|
+
if (value.bind.collectionSlot !== undefined && options?.collectionBindingStage !== 'definition-source') {
|
|
250
|
+
throw new SomaUiConfigError('collectionSlot 仅允许受信组件定义源;运行时必须使用准备计划', nestedPath);
|
|
251
|
+
}
|
|
233
252
|
|
|
234
253
|
const nested: NestedShowMapping = {
|
|
235
254
|
bind: {
|
|
236
255
|
obj: value.bind.obj,
|
|
237
256
|
var: value.bind.var,
|
|
238
257
|
...(typeof value.bind.role_by === 'string' ? { role_by: value.bind.role_by } : {}),
|
|
258
|
+
...(value.bind.key !== undefined ? { key: value.bind.key } : {}),
|
|
259
|
+
...(value.bind.repeatPlanId !== undefined ? { repeatPlanId: value.bind.repeatPlanId } : {}),
|
|
260
|
+
...(value.bind.collectionSlot !== undefined ? { collectionSlot: value.bind.collectionSlot } : {}),
|
|
239
261
|
},
|
|
240
|
-
show: parseShowMapping(value.show, `${currentPath}.show
|
|
262
|
+
show: parseShowMapping(value.show, `${currentPath}.show`, options),
|
|
241
263
|
// when 与 bind 同处一层:整块显隐(列表在错误/加载态整体隐藏靠它)
|
|
242
264
|
...(typeof value.when === 'string' ? { when: value.when } : {}),
|
|
243
265
|
};
|
|
244
266
|
|
|
267
|
+
if (value.props !== undefined) {
|
|
268
|
+
if (!value.props || typeof value.props !== 'object' || Array.isArray(value.props)) {
|
|
269
|
+
throw new SomaUiConfigError('props 必须是对象', currentPath);
|
|
270
|
+
}
|
|
271
|
+
nested.props = { ...value.props };
|
|
272
|
+
}
|
|
273
|
+
|
|
245
274
|
result[key] = nested;
|
|
246
275
|
} else if (typeof value === 'object' && value !== null && isExtendedShowValue(value)) {
|
|
247
276
|
// 扩展绑定:含 text / model / when / class / show
|
|
@@ -299,7 +328,7 @@ function parseShowMapping(rawShow: any, path: string): ShowMapping {
|
|
|
299
328
|
}
|
|
300
329
|
|
|
301
330
|
if ('show' in value && value.show !== undefined) {
|
|
302
|
-
extended.show = parseShowMapping(value.show, `${currentPath}.show
|
|
331
|
+
extended.show = parseShowMapping(value.show, `${currentPath}.show`, options);
|
|
303
332
|
}
|
|
304
333
|
|
|
305
334
|
if ('props' in value && value.props !== undefined) {
|
|
@@ -389,7 +418,10 @@ export function parseUiConfig(raw: any, options?: SomaUiConfigParseOptions): UiC
|
|
|
389
418
|
bind.onChange = parseOnChangeRules(raw.bind.onChange, 'bind.onChange');
|
|
390
419
|
}
|
|
391
420
|
|
|
392
|
-
|
|
421
|
+
if (raw.bind.key !== undefined || raw.bind.repeatPlanId !== undefined || raw.bind.collectionSlot !== undefined) {
|
|
422
|
+
throw new SomaUiConfigError('顶层 bind 不接受集合行字段', 'bind');
|
|
423
|
+
}
|
|
424
|
+
const show = parseShowMapping(raw.show, 'show', options);
|
|
393
425
|
|
|
394
426
|
const config: UiConfig = { bind, show };
|
|
395
427
|
|
|
@@ -22,6 +22,11 @@ export type SomaPipeFn = (
|
|
|
22
22
|
ctx: SomaPipeContext,
|
|
23
23
|
) => string;
|
|
24
24
|
|
|
25
|
+
/** SomaPipeRegistry.tryApply 的结果:成功带展示字符串;失败带出错的管道名与它抛出的原始异常 */
|
|
26
|
+
export type SomaPipeApplyResult =
|
|
27
|
+
| { ok: true; value: string }
|
|
28
|
+
| { ok: false; pipeName: string; error: unknown };
|
|
29
|
+
|
|
25
30
|
export class SomaPipeError extends Error {
|
|
26
31
|
constructor(message: string) {
|
|
27
32
|
super(`[soma-core][管道] ${message}`);
|
|
@@ -143,8 +148,45 @@ export class SomaPipeRegistry {
|
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
|
|
146
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* 链式应用(从左到右);单个管道异常时降级为原值字符串并告警,不中断渲染。
|
|
153
|
+
*
|
|
154
|
+
* **仓内零消费者,保留是因为它是对外公开 API**(`core/index.ts` 导出 `SomaPipeRegistry`,
|
|
155
|
+
* 1.6.0 已发布)。四条内部路径——页面绑定(`dom-renderer.ts:441`)、行绑定
|
|
156
|
+
* (`dom-renderer.ts:1351`)、组件 props(`component-manager.ts:1246`)、data transform
|
|
157
|
+
* (`data-object-resolver.ts:728`)——2026-09 全部改走 `tryApply`,改的理由四处写得一样:
|
|
158
|
+
* 本方法的告警**不带锚点、不带声明、不带 prop,而且每次重算都打一遍**,
|
|
159
|
+
* 而失败时上屏的又是一个"看起来像格式化过"的原值字符串。
|
|
160
|
+
* 谁在什么位置坏了,看控制台是看不出来的。
|
|
161
|
+
*
|
|
162
|
+
* 那删不删?**不删**:删它是对外 breaking change,而它的降级**是出声的**
|
|
163
|
+
* (console.warn),不属于"猜错了还装作正确"那一类,外部 Host 想要"格式化失败也别炸"
|
|
164
|
+
* 时它仍是一个诚实的选择。两者的差别取舍另见
|
|
165
|
+
* 《soma 运行时引擎详设》§5.3「管道失败」,那里逐字写明了降级值相同、告警质量不同。
|
|
166
|
+
*
|
|
167
|
+
* **但仓内代码一律用 `tryApply`。** 这条规则目前**没有机器面**:
|
|
168
|
+
* `verify-symbols` 的符号图不收类成员(`scripts/lib/symbol-graph.mjs` 文件头
|
|
169
|
+
* "类成员不进图:类活着,全部成员体里的引用都算活"),所以它既不会把本方法报成
|
|
170
|
+
* public-only、也不会拦住谁在仓内重新用起它——换句话说,重新引入这条差路是**不报错**的。
|
|
171
|
+
* 想让它变成机器判定,最便宜的落点是 `scripts/` 下加一条 grep 式检查
|
|
172
|
+
* (生产面禁止出现 `.apply(` 接 pipes 的调用),不是在这里加运行时开关。
|
|
173
|
+
*/
|
|
147
174
|
apply(value: unknown, pipes: SomaPipeCall[], ctx: SomaPipeContext): string {
|
|
175
|
+
const result = this.tryApply(value, pipes, ctx);
|
|
176
|
+
if (!result.ok) {
|
|
177
|
+
console.warn(`[soma-core][管道] 管道 "${result.pipeName}" 执行失败:`, result.error);
|
|
178
|
+
return String(value ?? '');
|
|
179
|
+
}
|
|
180
|
+
return result.value;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 与 apply 同一条链式执行,区别只在管道函数抛错时:不告警、不降级,停在出错的那一段,
|
|
185
|
+
* 把管道名与原始异常作为结果交回。失败的降级值与告警由调用方决定——
|
|
186
|
+
* 组件 props 管道出错时按 undefined 下发,并点名实例锚点与 prop 告警(component-manager 的 resolvePipedProp)。
|
|
187
|
+
* 其余与 apply 相同:未注册的管道照样在这里告警并跳过;绑定型实参读取(ctx.read)抛错不算管道失败,照样向外抛。
|
|
188
|
+
*/
|
|
189
|
+
tryApply(value: unknown, pipes: SomaPipeCall[], ctx: SomaPipeContext): SomaPipeApplyResult {
|
|
148
190
|
let current: unknown = value;
|
|
149
191
|
for (const pipe of pipes) {
|
|
150
192
|
const fn = this.fns.get(pipe.name);
|
|
@@ -159,11 +201,10 @@ export class SomaPipeRegistry {
|
|
|
159
201
|
try {
|
|
160
202
|
current = fn(current, args, ctx);
|
|
161
203
|
} catch (error) {
|
|
162
|
-
|
|
163
|
-
return String(value ?? '');
|
|
204
|
+
return { ok: false, pipeName: pipe.name, error };
|
|
164
205
|
}
|
|
165
206
|
}
|
|
166
|
-
return String(current ?? '');
|
|
207
|
+
return { ok: true, value: String(current ?? '') };
|
|
167
208
|
}
|
|
168
209
|
}
|
|
169
210
|
|