soma-core 1.6.0 → 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/core/build/compiler/soma-precompile.js +182 -15
- package/core/build/eject/component-eject.ts +1 -0
- package/core/client/adaptive/observer-pool.ts +122 -8
- package/core/client/compiler/manifest-compiler.ts +46 -5
- package/core/client/component/component-defaults.ts +1 -1
- package/core/client/component/component-expander.ts +1 -1
- package/core/client/component/component-manager.ts +784 -35
- package/core/client/component/component-pack.ts +1 -1
- package/core/client/component/component-registry.ts +1 -1
- package/core/client/container/SomaContainerAdapter.ts +103 -2
- package/core/client/data/data-object-resolver.ts +45 -1
- package/core/client/engine/dom-renderer.ts +432 -29
- package/core/client/engine/event-engine.ts +301 -13
- 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 +118 -11
- package/core/client/engine/scope-resolver.ts +3 -3
- package/core/client/engine/soma-bootstrap.ts +31 -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 +44 -1
- 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 +1 -1
- package/core/client/pipes/pipe-registry.ts +45 -4
- 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 +1 -1
- package/core/server/mock/node/cli.mjs +3 -3
- package/core/shared/path-algebra.ts +1 -1
- package/core/shared/types/event.types.ts +8 -4
- package/dist/core/index.cjs +5411 -3507
- package/dist/lsp/component-tree.cjs +701 -511
- 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/component-manager.d.ts +86 -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 +110 -2
- package/dist/types/client/engine/event-engine.d.ts +61 -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 +54 -3
- 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/pipes/pipe-registry.d.ts +39 -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/shared/types/event.types.d.ts +8 -4
- package/package.json +4 -4
- package/dist/preview-export.cjs +0 -3401
|
@@ -24,6 +24,25 @@ export interface SomaRenderEngineOptions {
|
|
|
24
24
|
pipeRegistry?: import('../pipes/pipe-registry').SomaPipeRegistry;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* 值一样就不必再写一次 DOM 的绑定类型。
|
|
29
|
+
*
|
|
30
|
+
* 判据只有一条:这一类绑定写进 DOM 的东西**完全**由 renderBinding 算出来的那个 value 决定。
|
|
31
|
+
* 名单外的四类各有各的理由,一条都不能放进来:
|
|
32
|
+
* - `class`:编译出来的渲染闭包根本不看 value,它自己去读每条规则的条件路径;
|
|
33
|
+
* - `model`:控件的当前状态会被用户改走(键入、勾选、输入法组合),引擎必须留着每帧纠正它的权利;
|
|
34
|
+
* - `list` / `obj`:拿到的是引用。页面就地改数组元素(`rows[0].name = x`)时引用一模一样,
|
|
35
|
+
* 记忆下去就是"数据变了、界面停在旧值"——这类静默停更比多写一次 DOM 坏得多。
|
|
36
|
+
* 带格式化管道的 text / attr 也不进(见 renderBinding 里的判断):管道的输出还取决于语言包与
|
|
37
|
+
* 参数路径,不是 value 一个人说了算。
|
|
38
|
+
*/
|
|
39
|
+
const VALUE_MEMO_TYPES: ReadonlySet<BindingEntry['type']> = new Set<BindingEntry['type']>([
|
|
40
|
+
'text',
|
|
41
|
+
'attr',
|
|
42
|
+
'html',
|
|
43
|
+
'when',
|
|
44
|
+
]);
|
|
45
|
+
|
|
27
46
|
export interface SomaRenderMiddlewareContext {
|
|
28
47
|
/** publish = 事务中途的自愿提交(长任务播进展),其余含义见 render-engine 各方法 */
|
|
29
48
|
phase: 'full-render' | 'patch' | 'commit' | 'publish';
|
|
@@ -42,6 +61,24 @@ export class SomaRenderEngine {
|
|
|
42
61
|
private readonly middleware: SomaMiddlewareChain<SomaRenderMiddlewareContext> | null;
|
|
43
62
|
private bindingTable: BindingEntry[] = [];
|
|
44
63
|
private bindingIndex = new Map<string, BindingEntry[]>();
|
|
64
|
+
/**
|
|
65
|
+
* 叶子绑定上一次**写出去**的值(名单见 VALUE_MEMO_TYPES)。
|
|
66
|
+
*
|
|
67
|
+
* 为什么需要它:`render()` 是"我不知道什么变了,整张表重来一遍"——它没有脏路径可用,
|
|
68
|
+
* 于是每一次都把整张绑定表逐条写进 DOM。窗口化列表把滚动接到这条路上之后,
|
|
69
|
+
* 一次 scroll 就是几百次 DOM 写入,其中绝大多数写的是与屏幕上一模一样的值。
|
|
70
|
+
* 这里不猜"哪些绑定受影响"(猜漏就是静默停在旧值),只做一件算得准的事:
|
|
71
|
+
* **算出来的值与上一次写出去的那个一模一样,就不再碰 DOM**。
|
|
72
|
+
*
|
|
73
|
+
* 代价说清楚:被绑定的锚点,它那条文本/属性从此只认绑定这一个写入方。
|
|
74
|
+
* 谁在绑定之外直接改写同一处 DOM,引擎不会再每帧把它改回来了
|
|
75
|
+
* (反过来说,过去那种"命令式写完下一帧被静默冲掉"的暗坑也随之消失)。
|
|
76
|
+
* 另外,叶子绑定的写入失败被 dom-renderer 当场吞掉并记日志,这里看不见,
|
|
77
|
+
* 因此失败的那一项也会被记进来:同一个值不再重试,日志也只响一次而不是每帧一次。
|
|
78
|
+
*
|
|
79
|
+
* WeakMap:绑定表重建或实例销毁后自行回收,不必手工清账。
|
|
80
|
+
*/
|
|
81
|
+
private readonly lastWritten = new WeakMap<BindingEntry, unknown>();
|
|
45
82
|
private scopeTracker = new WeakMap<HTMLElement, any>();
|
|
46
83
|
private pendingPatches = new Map<string, any>();
|
|
47
84
|
private flushScheduled = false;
|
|
@@ -141,11 +178,39 @@ export class SomaRenderEngine {
|
|
|
141
178
|
this.transactionDepth++;
|
|
142
179
|
}
|
|
143
180
|
|
|
144
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* 事件事务结束:**当场收口**——事务里还没上屏的 patch 就地提交掉。
|
|
183
|
+
*
|
|
184
|
+
* 常态下这里没活干——commit 已在 handler 之后提交过一次,pending 是空的;
|
|
185
|
+
* 出错那条路也被 discardPendingPatches 清过。还剩两条出口会把写入留在事务里:
|
|
186
|
+
* - 处理器明确返回 `false` 声明「没改动」,引擎据此跳过了那次 commit
|
|
187
|
+
* (见 event-engine 的 declaredNoChange),可它其实还是写了页面字段——
|
|
188
|
+
* 代理把 patch 收在事务里,自己出不去;
|
|
189
|
+
* - 处理器 await 期间它所在的那一行被删了(见 event-engine 行作用域失活的早退),
|
|
190
|
+
* 既没 commit 也没 discard 就退出了——这条出口比 declaredNoChange 更老,
|
|
191
|
+
* 过去那一笔写入要等下一次事件才顺带上屏。
|
|
192
|
+
*
|
|
193
|
+
* 为什么是当场 `commit()`,而不是排一次 flush 到下个调度片:`pendingPatches`
|
|
194
|
+
* 是**整本**账,`discardPendingPatches()` 也是整本清。排队的那次 flush 还没跑,
|
|
195
|
+
* 下一次事件随手一 discard(出错回滚 / 强制全量刷新 / 编排中止)就把上一次事务
|
|
196
|
+
* 的写入一起抹了,DOM 会永久停在旧值,直到有人再写同一条路径。commit 在同步段里
|
|
197
|
+
* 就把这本账倒空(真正写 DOM 仍在微任务里,不是同步重排),于是
|
|
198
|
+
* 「pendingPatches 不跨事务存活」这条不变式继续成立:一次事务写的东西,要么在
|
|
199
|
+
* 本次事务里 commit,要么在本次事务里 discard,一笔都不留给下一次。
|
|
200
|
+
*
|
|
201
|
+
* 嵌套事务只认最外层:depth 回到 0 才收口,内层 end 仍只是递减——原子提交与整体
|
|
202
|
+
* 回滚的单位始终是最外层那一次事务。pending 为空时一步都不走,「声明没改动、也
|
|
203
|
+
* 确实什么都没写」那条路照旧是空转,一次 DOM 都不碰。
|
|
204
|
+
*/
|
|
145
205
|
endTransaction(): void {
|
|
146
206
|
if (this.transactionDepth > 0) {
|
|
147
207
|
this.transactionDepth--;
|
|
148
208
|
}
|
|
209
|
+
if (this.transactionDepth === 0 && this.pendingPatches.size > 0) {
|
|
210
|
+
void this.commit().catch(() => {
|
|
211
|
+
// 静默忽略:unmount / 中间件抛错时这次收口没人接手,与排队 flush 的老行为一致
|
|
212
|
+
});
|
|
213
|
+
}
|
|
149
214
|
}
|
|
150
215
|
|
|
151
216
|
/** 一次性提交事务内积累的 dirty path(Phase 2 commit 点) */
|
|
@@ -170,7 +235,10 @@ export class SomaRenderEngine {
|
|
|
170
235
|
return this.flushPatches('publish');
|
|
171
236
|
}
|
|
172
237
|
|
|
173
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* force 全量 render 前丢弃 pending patch(避免 commit + render 双写),出错回滚也走这里。
|
|
240
|
+
* 整本清空——清得掉的只有本次事务的账:上一次事务收口时(endTransaction)已经倒空过。
|
|
241
|
+
*/
|
|
174
242
|
discardPendingPatches(): void {
|
|
175
243
|
this.pendingPatches.clear();
|
|
176
244
|
this.flushScheduled = false;
|
|
@@ -180,11 +248,18 @@ export class SomaRenderEngine {
|
|
|
180
248
|
return this.transactionDepth > 0;
|
|
181
249
|
}
|
|
182
250
|
|
|
183
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* 将 DOM 表单控件的当前值写回代理实例(点击提交前同步)。
|
|
253
|
+
* 按控件类型取值交给渲染器:checkbox 读 .checked(布尔)、radio 只回写选中那个的 value、
|
|
254
|
+
* 多选下拉回写选中项数组。直接用 adapter.getValue 读的是 .value——checkbox 默认是字符串 "on",
|
|
255
|
+
* 为真,会让每次带处理器的点击都把没勾的框写成勾选。
|
|
256
|
+
* 值与实例上的现值相同的那些不写也不通知(去重在渲染器的 syncModel 里,与控件事件回写同一处):
|
|
257
|
+
* 控件刚派发的事件多半已经把同一个值回写过了,再写一遍只是给每个 watch / onChange 多发一次空通知。
|
|
258
|
+
*/
|
|
184
259
|
syncModels(): void {
|
|
185
260
|
for (const entry of this.bindingTable) {
|
|
186
261
|
if (entry.type === 'model') {
|
|
187
|
-
this.
|
|
262
|
+
this.renderer.syncModel(entry.element, entry.dataPath);
|
|
188
263
|
}
|
|
189
264
|
}
|
|
190
265
|
}
|
|
@@ -339,13 +414,45 @@ export class SomaRenderEngine {
|
|
|
339
414
|
const startedAt = this.adapter.now();
|
|
340
415
|
const terminal = async (current: SomaRenderMiddlewareContext): Promise<void> => {
|
|
341
416
|
const renderBinding = (entry: BindingEntry): void => {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
417
|
+
// 取值与写 DOM 包在**同一个** try 里。compiledGetter 走的是页面自己的属性链,
|
|
418
|
+
// 页面把派生字段写成 `get total() { return this.rows.reduce(...) }` 时,它一样会抛;
|
|
419
|
+
// 过去这一段在 try 之外,dom-renderer.renderEntry 里那道叶子绑定的兜底够不到它。
|
|
420
|
+
// 后果按阶段分两种,而且都没有日志:
|
|
421
|
+
// - full-render 是同步 for 循环,排在它后面的绑定整帧停在旧值;
|
|
422
|
+
// - patch / commit / publish 那条并发路各自是独立微任务,后面的绑定照渲,但
|
|
423
|
+
// Promise.all 当场拒绝,这一帧的 recordRender 记不下来,异常再被
|
|
424
|
+
// ensureFlushScheduled 的 .catch 吞掉——页面停着,控制台干干净净。
|
|
425
|
+
// 日志与 dom-renderer 那条逐字相同:同一件事(这一项没渲成)只该有一个日志签名。
|
|
426
|
+
try {
|
|
427
|
+
const patchValue = patchValues?.get(entry);
|
|
428
|
+
const value = patchValue !== undefined
|
|
429
|
+
? patchValue
|
|
430
|
+
: entry.compiledGetter
|
|
431
|
+
? entry.compiledGetter(this.proxiedInstance)
|
|
432
|
+
: this.resolver.readFromRoot(entry.dataPath);
|
|
433
|
+
// 值没变就不写(见 lastWritten)。带管道的不记:管道输出还取决于语言包与参数路径。
|
|
434
|
+
const memoizable = VALUE_MEMO_TYPES.has(entry.type) && !entry.pipes?.length;
|
|
435
|
+
if (memoizable && this.lastWritten.has(entry) && Object.is(this.lastWritten.get(entry), value)) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
this.renderer.renderEntry(entry, value);
|
|
439
|
+
if (memoizable) {
|
|
440
|
+
this.lastWritten.set(entry, value);
|
|
441
|
+
}
|
|
442
|
+
} catch (error) {
|
|
443
|
+
// 结构绑定(list / obj)照旧抛出去:CT-* 预算、产物缺失、行内控制器失败按设计失败即停,
|
|
444
|
+
// 且自带行回滚(见 dom-renderer.renderEntry 的同一处判断)。在这里吞掉等于把它删了。
|
|
445
|
+
if (entry.type === 'list' || entry.type === 'obj') throw error;
|
|
446
|
+
const target = entry.attrName ? `${entry.somaId}@${entry.attrName}` : entry.somaId;
|
|
447
|
+
// class 绑定没有单一数据路径,报它的条件路径
|
|
448
|
+
const path = entry.type === 'class'
|
|
449
|
+
? Object.values(entry.classRules ?? {}).join(' / ')
|
|
450
|
+
: entry.dataPath;
|
|
451
|
+
console.error(
|
|
452
|
+
`[soma-core][引擎] 绑定渲染失败,已跳过这一项(同帧其余绑定照常渲染):${target}(${entry.type},路径 "${path}")`,
|
|
453
|
+
error,
|
|
454
|
+
);
|
|
455
|
+
}
|
|
349
456
|
};
|
|
350
457
|
|
|
351
458
|
if (current.phase === 'patch' || current.phase === 'commit' || current.phase === 'publish') {
|
|
@@ -185,7 +185,7 @@ export class SomaScopeResolver {
|
|
|
185
185
|
current = (this.rootInstance as any)[rootKey];
|
|
186
186
|
}
|
|
187
187
|
if (current === undefined) {
|
|
188
|
-
throw new Error(`[
|
|
188
|
+
throw new Error(`[soma-core][引擎] Cannot resolve "${rootKey}" in "${funcPath}"`);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
// 遍历剩余段,保留 owner
|
|
@@ -194,12 +194,12 @@ export class SomaScopeResolver {
|
|
|
194
194
|
owner = current;
|
|
195
195
|
current = current[segments[i]];
|
|
196
196
|
if (current === undefined) {
|
|
197
|
-
throw new Error(`[
|
|
197
|
+
throw new Error(`[soma-core][引擎] Cannot resolve "${segments[i]}" in "${funcPath}"`);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
if (typeof current !== 'function') {
|
|
202
|
-
throw new Error(`[
|
|
202
|
+
throw new Error(`[soma-core][引擎] "${funcPath}" is not a function`);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
return current.bind(owner);
|
|
@@ -43,7 +43,7 @@ import { decodePageState, encodePageState, parseStateValue } from '../parser/pag
|
|
|
43
43
|
import { injectStyleOnce } from '../component/pack-styles';
|
|
44
44
|
import type { SomaComponentDefinition } from '../component/component-definition.types';
|
|
45
45
|
import { SomaComponentRegistry } from '../component/component-registry';
|
|
46
|
-
import { SomaComponentManager } from '../component/component-manager';
|
|
46
|
+
import { SomaComponentManager, warnSubscriptionsWithoutComponents } from '../component/component-manager';
|
|
47
47
|
import {
|
|
48
48
|
validateComponentDefaults,
|
|
49
49
|
type SomaComponentDefaults,
|
|
@@ -111,7 +111,7 @@ export interface SomaPageAssets extends ComponentTreeRuntimeEnvelope {
|
|
|
111
111
|
export function assertPageRuntimeAssets(assets: SomaPageAssets, hostComponents: Record<string, SomaComponentDefinition>): void {
|
|
112
112
|
assertRuntimeArtifact(assets);
|
|
113
113
|
if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
|
|
114
|
-
throw new Error('[
|
|
114
|
+
throw new Error('[soma-core][引擎] 收到未编译的 SOMA DSL 源声明,请先在服务端编译。');
|
|
115
115
|
}
|
|
116
116
|
if (assets.sourceMarkup === 'component-tree') {
|
|
117
117
|
for (const ref of assets.artifact!.componentRefs) {
|
|
@@ -519,7 +519,7 @@ export class SomaBootstrap {
|
|
|
519
519
|
// 源声明只允许在构建/服务端编译;浏览器 mount 只消费运行时资产。
|
|
520
520
|
if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
|
|
521
521
|
throw new Error(
|
|
522
|
-
'[
|
|
522
|
+
'[soma-core][引擎] 收到未编译的 SOMA DSL 源声明。'
|
|
523
523
|
+ '请先用 compilePageAssets(构建/测试)或 Host 页面编译入口生成运行时资产。',
|
|
524
524
|
);
|
|
525
525
|
}
|
|
@@ -553,6 +553,10 @@ export class SomaBootstrap {
|
|
|
553
553
|
this.prepareDataLayer(this.domainInstance, assets);
|
|
554
554
|
|
|
555
555
|
// 4. 包装响应式代理
|
|
556
|
+
// 第三参(数组变异守卫)这里**故意不传**:传 false 会把开发期也一起关掉,
|
|
557
|
+
// 而这条告警正是写页面时唯一能发现"就地 push 不触发更新"的提示。
|
|
558
|
+
// 该开还是该关交给 SomaReactiveProxy 的默认值按环境判定(isSomaArrayGuardEnabled)——
|
|
559
|
+
// 生产包里是关的,`npm run dev` 与 `globalThis.SOMA_DEV_GUARD = true` 时照旧报。
|
|
556
560
|
this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
|
|
557
561
|
this.domainInstance = this.proxy.wrap(this.domainInstance);
|
|
558
562
|
|
|
@@ -583,7 +587,7 @@ export class SomaBootstrap {
|
|
|
583
587
|
options?: { resetDiagnostics?: boolean; preserveState?: boolean },
|
|
584
588
|
): Promise<void> {
|
|
585
589
|
if (!this.mounted || !this.container || !this.assets || !this.domainInstance) {
|
|
586
|
-
throw new Error('[
|
|
590
|
+
throw new Error('[soma-core][引擎] Cannot hotSwap before mount');
|
|
587
591
|
}
|
|
588
592
|
|
|
589
593
|
const savedLocale =
|
|
@@ -652,6 +656,7 @@ export class SomaBootstrap {
|
|
|
652
656
|
if (overrides.DomainClass) {
|
|
653
657
|
this.proxy?.dispose();
|
|
654
658
|
const raw = this.createDomainInstance(merged.DomainClass, parsed, merged.routerPath);
|
|
659
|
+
// 与 mount 第 4 步同一口径:守卫开关交给默认值按环境判定,这里不传死
|
|
655
660
|
this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
|
|
656
661
|
this.domainInstance = this.proxy.wrap(raw);
|
|
657
662
|
} else {
|
|
@@ -691,14 +696,14 @@ export class SomaBootstrap {
|
|
|
691
696
|
|
|
692
697
|
captureSnapshot(options?: { exclude?: string[] }): number {
|
|
693
698
|
if (!this.domainInstance) {
|
|
694
|
-
throw new Error('[
|
|
699
|
+
throw new Error('[soma-core][引擎] Cannot capture snapshot before mount');
|
|
695
700
|
}
|
|
696
701
|
return this.snapshotStore.capture(this.domainInstance, options);
|
|
697
702
|
}
|
|
698
703
|
|
|
699
704
|
restoreSnapshot(snapshotId: number): void {
|
|
700
705
|
if (!this.domainInstance) {
|
|
701
|
-
throw new Error('[
|
|
706
|
+
throw new Error('[soma-core][引擎] Cannot restore snapshot before mount');
|
|
702
707
|
}
|
|
703
708
|
this.snapshotStore.restore(snapshotId, this.domainInstance);
|
|
704
709
|
this.renderEngine?.render();
|
|
@@ -706,7 +711,7 @@ export class SomaBootstrap {
|
|
|
706
711
|
|
|
707
712
|
batch(fn: () => void): void {
|
|
708
713
|
if (!this.proxy) {
|
|
709
|
-
throw new Error('[
|
|
714
|
+
throw new Error('[soma-core][引擎] Cannot batch before mount');
|
|
710
715
|
}
|
|
711
716
|
this.proxy.beginBatch();
|
|
712
717
|
try {
|
|
@@ -800,7 +805,7 @@ export class SomaBootstrap {
|
|
|
800
805
|
/** 监听属性变更(委托 RenderEngine.watch) */
|
|
801
806
|
watch(path: string, callback: WatchCallback, options?: WatcherOptions): () => void {
|
|
802
807
|
if (!this.renderEngine) {
|
|
803
|
-
throw new Error('[
|
|
808
|
+
throw new Error('[soma-core][引擎] Cannot watch before mount');
|
|
804
809
|
}
|
|
805
810
|
return this.renderEngine.watch(path, callback, options);
|
|
806
811
|
}
|
|
@@ -1313,7 +1318,7 @@ export class SomaBootstrap {
|
|
|
1313
1318
|
.map(([name, wheres]) => ` "${name}" —— 用在 ${wheres.join('、')}`)
|
|
1314
1319
|
.join('\n');
|
|
1315
1320
|
throw new Error(
|
|
1316
|
-
`[
|
|
1321
|
+
`[soma-core][引擎] 页面用到了未注册的具名动作:\n${lines}\n`
|
|
1317
1322
|
+ ` 已注册:${known}\n`
|
|
1318
1323
|
+ ' 在 configureSomaBootstrap 的 options.actions 里登记它们。'
|
|
1319
1324
|
+ '具名动作是 custom(script) 的替代:实现在 Host 代码里、有名字、可审计。',
|
|
@@ -1361,6 +1366,9 @@ export class SomaBootstrap {
|
|
|
1361
1366
|
}
|
|
1362
1367
|
const defs = { ...this.hostComponents, ...pageComponents };
|
|
1363
1368
|
if (Object.keys(defs).length === 0) {
|
|
1369
|
+
// 一个组件都没有的页面不建管理器(展开、注册表、行钩子全是用不上的开销)。
|
|
1370
|
+
// 管理器顺带做的那件事不能跟着一起没有:没走上 emit 路由的事件名告警由
|
|
1371
|
+
// buildRuntime 里的 warnSubscriptionsWithoutComponents 单独补(见那里的注释)。
|
|
1364
1372
|
return;
|
|
1365
1373
|
}
|
|
1366
1374
|
|
|
@@ -1434,14 +1442,20 @@ export class SomaBootstrap {
|
|
|
1434
1442
|
this.timerEngine = runtime.timerEngine;
|
|
1435
1443
|
|
|
1436
1444
|
// 组件实例挂载(页面引擎就绪后:emit 路由标记、props watch、行内钩子)
|
|
1437
|
-
this.componentManager
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
+
if (this.componentManager) {
|
|
1446
|
+
this.componentManager.activate({
|
|
1447
|
+
container: this.container,
|
|
1448
|
+
renderEngine: runtime.renderEngine,
|
|
1449
|
+
eventEngine: runtime.eventEngine,
|
|
1450
|
+
resolver: runtime.resolver,
|
|
1451
|
+
manifest: runtime.manifest,
|
|
1452
|
+
services: this.buildComponentServices(),
|
|
1453
|
+
});
|
|
1454
|
+
} else {
|
|
1455
|
+
// 没有注册任何组件的页面:管理器不建,但它顺带做的事件名告警要补上——
|
|
1456
|
+
// 否则 `card.reach_limit` 这种笔误在这类页面全程静默(解析期那条只认 33 个 DOM 专有名字)。
|
|
1457
|
+
warnSubscriptionsWithoutComponents(runtime.manifest, this.container);
|
|
1458
|
+
}
|
|
1445
1459
|
|
|
1446
1460
|
// 界面中途提交接线:Domain 在长任务里调 `this.publishUi()` 时,
|
|
1447
1461
|
// 把此刻积累的 patch 立刻上屏而不结束事件事务(见 SomaRuntimeServices.ui)
|
|
@@ -26,7 +26,7 @@ export class SomaAdaptiveConfigError extends Error {
|
|
|
26
26
|
|
|
27
27
|
constructor(message: string, path: string = '') {
|
|
28
28
|
const prefix = path ? ` (路径: ${path})` : '';
|
|
29
|
-
super(`[
|
|
29
|
+
super(`[soma-core][引擎] ${message}${prefix}`);
|
|
30
30
|
this.name = 'SomaAdaptiveConfigError';
|
|
31
31
|
this.path = path;
|
|
32
32
|
}
|
|
@@ -86,7 +86,7 @@ function parseAnnotatedPipeline(
|
|
|
86
86
|
): ParsedEvent {
|
|
87
87
|
const colonIdx = raw.indexOf(':');
|
|
88
88
|
if (colonIdx === -1) {
|
|
89
|
-
throw new Error(`[
|
|
89
|
+
throw new Error(`[soma-core][引擎] 无效的 @Event 格式,缺少冒号: "${raw}"`);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const selector = raw.slice(0, colonIdx).trim();
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
import type { OnChangeRule } from '../../../shared/types/watcher.types';
|
|
21
21
|
import { SomaBlockParseError } from '../../../shared/block-errors';
|
|
22
22
|
import { buildBlockScope, expandPath, type BlockScope } from './namespace';
|
|
23
|
+
import { withPageDefaultInPipeline } from './use-parser';
|
|
23
24
|
|
|
24
25
|
const PAGE_KEYS = new Set([
|
|
25
26
|
'domain', 'locale', 'ui', 'watch', 'event', 'data', 'adaptive', 'alias',
|
|
@@ -416,8 +417,50 @@ function normalizeEventSection(
|
|
|
416
417
|
}
|
|
417
418
|
|
|
418
419
|
// 交给既有 pipeline-parser 的形状:DOM 事件映射 + timers/triggers 原样
|
|
419
|
-
const result: Record<string, unknown> =
|
|
420
|
+
const result: Record<string, unknown> = withPageDefaultInEventTree(on) as Record<string, unknown>;
|
|
420
421
|
if (section.timers !== undefined) result.timers = section.timers;
|
|
421
422
|
if (section.triggers !== undefined) result.triggers = section.triggers;
|
|
422
423
|
return result;
|
|
423
424
|
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* page 块 `event.on` 的处理器段免写 `page.`(REQ-005 F7.3)。
|
|
428
|
+
*
|
|
429
|
+
* 组件块的 `event.on` 与 `event.actions` 早就免前缀了(use-parser),page 块没接上——
|
|
430
|
+
* 同一条 `UI_REFRESH | doSearch` 写在组件块里能跑,搬到 page 块就报"函数路径至少需要
|
|
431
|
+
* 「对象.方法」两段"。这是接线漏了一处,不是两种块有不同规矩,所以直接复用同一个函数。
|
|
432
|
+
*
|
|
433
|
+
* 三种形状分开走:
|
|
434
|
+
* - 叶子字符串:事件声明本体,整条交 withPageDefaultInPipeline;
|
|
435
|
+
* - `{ steps: [...] }`(编排事件):管道住在每一步的 `do:` 里,深走一遍只改 `do` 的字符串值
|
|
436
|
+
* (步骤键是封闭集 when/do/output/on_error/switch/parallel/for_each,`do` 恒为管道表达式);
|
|
437
|
+
* - 其余映射:列表作用域的一层缩进,原样递归。
|
|
438
|
+
* timers / triggers 不在此列:timers 的 `tick` 写的是页面级轮询、triggers 的 `target`/`event`
|
|
439
|
+
* 是锚点与事件名,都不是 funcPath 槽。
|
|
440
|
+
*/
|
|
441
|
+
function withPageDefaultInEventTree(node: unknown): unknown {
|
|
442
|
+
if (typeof node === 'string') return withPageDefaultInPipeline(node);
|
|
443
|
+
if (node === null || typeof node !== 'object' || Array.isArray(node)) return node;
|
|
444
|
+
const source = node as Record<string, unknown>;
|
|
445
|
+
if (Array.isArray(source.steps)) {
|
|
446
|
+
return { ...source, steps: withPageDefaultInSteps(source.steps) };
|
|
447
|
+
}
|
|
448
|
+
const mapped: Record<string, unknown> = {};
|
|
449
|
+
for (const [key, value] of Object.entries(source)) {
|
|
450
|
+
mapped[key] = withPageDefaultInEventTree(value);
|
|
451
|
+
}
|
|
452
|
+
return mapped;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** 步骤树里只有 `do:` 是管道表达式,其余(when / output / 分支名)原样保留 */
|
|
456
|
+
function withPageDefaultInSteps(node: unknown): unknown {
|
|
457
|
+
if (Array.isArray(node)) return node.map(withPageDefaultInSteps);
|
|
458
|
+
if (node === null || typeof node !== 'object') return node;
|
|
459
|
+
const mapped: Record<string, unknown> = {};
|
|
460
|
+
for (const [key, value] of Object.entries(node as Record<string, unknown>)) {
|
|
461
|
+
mapped[key] = key === 'do' && typeof value === 'string'
|
|
462
|
+
? withPageDefaultInPipeline(value)
|
|
463
|
+
: withPageDefaultInSteps(value);
|
|
464
|
+
}
|
|
465
|
+
return mapped;
|
|
466
|
+
}
|
|
@@ -580,20 +580,35 @@ function withPageDefault(funcPath: string): string {
|
|
|
580
580
|
return funcPath.includes('.') ? funcPath : `page.${funcPath}`;
|
|
581
581
|
}
|
|
582
582
|
|
|
583
|
-
/**
|
|
584
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Pipeline 表达式里的处理器段同样享受免前缀。
|
|
585
|
+
*
|
|
586
|
+
* 组件块 `event.on` 与 page 块 `event.on` 共用本函数(REQ-005 F7.3)——两处写的都是
|
|
587
|
+
* 同一套四动词管道,"谁能免写 page." 不该取决于声明住在哪个块里。
|
|
588
|
+
*
|
|
589
|
+
* 槽位按动词查,不按形状猜:
|
|
590
|
+
* - UI_INTERACT 第 2 槽是 DOM 目标锚点、第 3 槽才是可选处理器(裸锚点不能改成 page.<锚点>);
|
|
591
|
+
* - NAV_STATIC 只有路由目标,没有处理器槽;
|
|
592
|
+
* - ACTION 的第 1 槽是**注册表动作名**(`ACTION | refreshBoard`),解析器只认不含点的
|
|
593
|
+
* 标识符(pipeline-parser 的 ACTION 分支),补成 `page.refreshBoard` 反而当场解析失败——
|
|
594
|
+
* 此前它落进了 else 分支拿到 handlerIndex 0,于是 `ACTION` 这个动词本身被改写成
|
|
595
|
+
* `page.ACTION`,报出来的是"未知事件类型 page.ACTION",与真实病因差着十万八千里;
|
|
596
|
+
* - 其余(首段不是动词 = 动词缺省,见 pipeline-parser 的 IMPLICIT_REFRESH_FUNC_PATH)
|
|
597
|
+
* 处理器就在第 0 槽,但只认小写起头的标识符:写错的动词(`UI_REFRESHH`)保持原样,
|
|
598
|
+
* 让 pipeline-parser 报"未知事件类型 UI_REFRESHH",而不是先被改写成 `page.UI_REFRESHH`。
|
|
599
|
+
*/
|
|
600
|
+
export function withPageDefaultInPipeline(expr: string): string {
|
|
585
601
|
const parts = expr.split('|').map((part) => part.trim());
|
|
586
602
|
const verb = parts[0];
|
|
587
|
-
// UI_INTERACT 的第 2 槽是 DOM 目标,第 3 槽才是可选处理器;
|
|
588
|
-
// NAV_STATIC 只有路由目标,不存在处理器。不能把裸锚点误改成 page.<锚点>。
|
|
589
603
|
const handlerIndex = verb === 'UI_INTERACT'
|
|
590
604
|
? 2
|
|
591
|
-
: verb === 'NAV_STATIC'
|
|
605
|
+
: verb === 'NAV_STATIC' || verb === 'ACTION'
|
|
592
606
|
? -1
|
|
593
607
|
: ['UI_REFRESH', 'NAV_ACTION'].includes(verb)
|
|
594
608
|
? 1
|
|
595
609
|
: 0;
|
|
596
|
-
|
|
610
|
+
const shape = handlerIndex === 0 ? /^[a-z][A-Za-z0-9_]*$/ : /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
611
|
+
if (handlerIndex >= 0 && parts[handlerIndex] && shape.test(parts[handlerIndex])) {
|
|
597
612
|
parts[handlerIndex] = `page.${parts[handlerIndex]}`;
|
|
598
613
|
}
|
|
599
614
|
return parts.reduce(
|
|
@@ -47,7 +47,7 @@ export class SomaDataConfigError extends Error {
|
|
|
47
47
|
|
|
48
48
|
constructor(message: string, path: string = '') {
|
|
49
49
|
const prefix = path ? ` (路径: ${path})` : '';
|
|
50
|
-
super(`[
|
|
50
|
+
super(`[soma-core][数据] ${message}${prefix}`);
|
|
51
51
|
this.name = 'SomaDataConfigError';
|
|
52
52
|
this.path = path;
|
|
53
53
|
}
|