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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { recordMetric } from '../diagnostics/telemetry-context';
|
|
2
2
|
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
3
|
+
import { SomaRowScope, readRowPath } from './row-scope';
|
|
3
4
|
import { SOMA_KEY_MODIFIERS } from '../../shared/types/keyboard.types';
|
|
4
5
|
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
5
6
|
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
@@ -9,6 +10,7 @@ import type { InteractAction, EventHandlerResult } from '../../shared/types/even
|
|
|
9
10
|
import type { SomaScopeResolver } from './scope-resolver';
|
|
10
11
|
import { isSomaEmitEvent } from './emit-event';
|
|
11
12
|
import { runSteps } from './step-runner';
|
|
13
|
+
import { SomaCompositionGate } from './dom-renderer';
|
|
12
14
|
|
|
13
15
|
/** 原生可聚焦标签:`UI_INTERACT | … | focus` 对它们不必补 tabindex */
|
|
14
16
|
const NATIVELY_FOCUSABLE = new Set(['A', 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'DETAILS', 'SUMMARY']);
|
|
@@ -17,6 +19,111 @@ function isNativelyFocusable(element: HTMLElement): boolean {
|
|
|
17
19
|
return NATIVELY_FOCUSABLE.has(element.tagName);
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
/**
|
|
23
|
+
* 声明事件 → 容器上实际挂的监听类型。只有 focus / blur 需要换,其余原样。
|
|
24
|
+
*
|
|
25
|
+
* 委托监听挂在容器(页面挂载根 / 组件宿主)的冒泡阶段,而 focus / blur 不冒泡:
|
|
26
|
+
* 容器只在**自己**获得/失去焦点时收得到,内部元素上声明的 focus / blur 处理器
|
|
27
|
+
* 永远不触发——Combobox 聚焦不展开、NumberInput / RichTextEditor 失焦不提交。
|
|
28
|
+
* 浏览器每次焦点变化都紧随 focus / blur 派发恰好一个会冒泡的 focusin / focusout,
|
|
29
|
+
* 挂它们就是在冒泡阶段收到同一次焦点变化:容器只收一次,查表仍用声明名
|
|
30
|
+
* (`focus:<somaId>`),"从 target 向上找最近一个声明者"的规则与 click 相同。
|
|
31
|
+
*
|
|
32
|
+
* 不走捕获阶段:捕获监听先于目标元素自己的监听执行(模型回写、控制器自挂的监听),
|
|
33
|
+
* 时序与其他委托事件正好相反;且适配器 listen 没有捕获参数,要动三个容器适配器的契约。
|
|
34
|
+
*
|
|
35
|
+
* 处理器第二实参因此是 type 为 focusin / focusout 的 FocusEvent(relatedTarget 照常可用)。
|
|
36
|
+
* 手工派发合成的 `new Event('focus', { bubbles: true })` 不再命中——浏览器从不派发
|
|
37
|
+
* 冒泡的 focus,要模拟聚焦请调用元素的 focus() / blur()。
|
|
38
|
+
*
|
|
39
|
+
* mouseenter / mouseleave / scroll 同样不冒泡、也没有语义等价的冒泡事件,
|
|
40
|
+
* 仍然到不了容器(悬停走 Style transition 或控制器直挂宿主)。
|
|
41
|
+
*/
|
|
42
|
+
const DELEGATED_LISTEN_TYPE: ReadonlyMap<string, string> = new Map([
|
|
43
|
+
['focus', 'focusin'],
|
|
44
|
+
['blur', 'focusout'],
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 找到声明者后由引擎**同步**调用 preventDefault() 的声明事件。只有 submit。
|
|
49
|
+
*
|
|
50
|
+
* 委托监听只把处理器交给调度器,处理器本身晚于监听回调执行。真实浏览器里,用户输入派发的事件
|
|
51
|
+
* 在每个监听回调返回后跑一次微任务检查点,调度器空闲时处理器赶在派发结束前执行,里面的
|
|
52
|
+
* preventDefault() 生效;以下情况处理器在派发结束后才执行,preventDefault() 不起作用:
|
|
53
|
+
* - 调度器忙:上一个处理器还在 await(提交等接口期间再按一次回车);
|
|
54
|
+
* - 同一帧已有渲染补丁经 rAF 排队,immediate 任务跟着等到那一帧;
|
|
55
|
+
* - 脚本发起:form.requestSubmit()、submitButton.click()、dispatchEvent(派发期间 JS 栈不空,没有检查点)。
|
|
56
|
+
* 对 submit 这意味着浏览器照常提交——导航或整页刷新,页面状态全部丢失。
|
|
57
|
+
*
|
|
58
|
+
* 声明了 submit 的处理器都要单页行为(组件库 FormPanel / FilterBar / Questionnaire 的处理器第一句
|
|
59
|
+
* 就是 preventDefault),所以不交给处理器:监听回调里找到声明者就阻止,与调度状态无关;
|
|
60
|
+
* 处理器被 confirm 取消、被 pre-check 拦下时也不会落回默认提交。处理器里再调 preventDefault() 无害。
|
|
61
|
+
* 确实需要原生提交(表单 POST 下载、跳外部支付页)时不声明 submit,或在处理器里调用
|
|
62
|
+
* form.submit()——它不派发 submit 事件。
|
|
63
|
+
*
|
|
64
|
+
* keydown / click 不在此列:输入字符、空格滚动、链接跳转该不该阻止取决于按键和状态,
|
|
65
|
+
* 监听回调里无从判断,仍由处理器调用 preventDefault(),受上面同样的时序限制。
|
|
66
|
+
* emit 路由不经过委托监听,不受影响。
|
|
67
|
+
*/
|
|
68
|
+
const SYNC_PREVENT_DEFAULT: ReadonlySet<string> = new Set(['submit']);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 输入法组合中一律不分发的按键事件。
|
|
72
|
+
*
|
|
73
|
+
* 组合进行中的按键是按给输入法的:字母在拼音串上、空格与数字在选词、↑↓ 翻候选、回车确认、Esc 取消。
|
|
74
|
+
* 分发下去就是"组合 nihao 时按回车,把拼音当消息发出去"——ChatComposer / SearchBar / TextInput 的
|
|
75
|
+
* `keydown.enter` 收到的 value 正是那串拼音(Chromium 147 实测)。
|
|
76
|
+
* 不带修饰符的绑定同样跳过:DataTable 的 `filter_input.keydown`、DatePicker 的 `dp_input.keydown`
|
|
77
|
+
* 在组合中执行同样是拿中间态当输入。
|
|
78
|
+
*
|
|
79
|
+
* 跳过 = 这一发在这个容器上什么都不做:引擎不调用 preventDefault(该不该阻止默认行为由输入法决定),
|
|
80
|
+
* 也不动"从 target 向上找最近一个声明者"的规则——这里根本没开始找,外层容器的引擎各自按同一条判断
|
|
81
|
+
* 跳过自己的那次分发,"内层不吞外层"的语义不变。
|
|
82
|
+
*/
|
|
83
|
+
const IME_HELD_KEY_EVENTS: ReadonlySet<string> = new Set(['keydown', 'keyup']);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 宿主是不是 WebKit(Safari,以及 iOS 上的所有浏览器)。只给按键判断的第 ④ 条用。
|
|
87
|
+
*
|
|
88
|
+
* 认引擎而不认能力:第 ④ 条修的就是 WebKit 特有的事件顺序(compositionend 先于确认选词那一发 keydown,
|
|
89
|
+
* WebKit bug 165004),没有任何特性检测问得出"这个引擎会不会把 compositionend 提前发";
|
|
90
|
+
* ProseMirror 的 inOrNearComposition 同样只在 Safari 上开这道豁免。
|
|
91
|
+
* 开给别的引擎是有代价的:Chromium 里确认键的 keydown 在 compositionend 之前,豁免只会误伤"上屏后立刻按回车"
|
|
92
|
+
* ——不限引擎时 40 轮实测吞掉 8 次(CDP 把上屏与回车挤进同一批任务时)。
|
|
93
|
+
* 排除 jsdom:它的 UA 里带 AppleWebKit,但事件顺序由测试自己安排(SomaScheduler 也这么排除它)。
|
|
94
|
+
*/
|
|
95
|
+
let webkitHost: boolean | undefined;
|
|
96
|
+
function isWebKitHost(): boolean {
|
|
97
|
+
if (webkitHost === undefined) {
|
|
98
|
+
const ua = typeof navigator === 'undefined' ? '' : navigator.userAgent ?? '';
|
|
99
|
+
webkitHost = /AppleWebKit/.test(ua) && !/Chrome|Chromium|Edg\/|jsdom/i.test(ua);
|
|
100
|
+
}
|
|
101
|
+
return webkitHost;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 组合开始 / 结束时比对用的控件文本:文本控件读 value,contenteditable 读 textContent(适配器 getValue 对它恒为空串) */
|
|
105
|
+
function composedText(adapter: IContainerAdapter, element: Element): string {
|
|
106
|
+
return typeof (element as HTMLInputElement).value === 'string'
|
|
107
|
+
? adapter.getValue(element as HTMLElement)
|
|
108
|
+
: element.textContent ?? '';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 容器上的输入法组合状态:闸门 + 这次组合的目标、开始时与结束时的控件文本 + 刚结束的标记(见 SomaEventEngine.attachInputComposition) */
|
|
112
|
+
interface InputComposition {
|
|
113
|
+
gate: SomaCompositionGate;
|
|
114
|
+
target: EventTarget | null;
|
|
115
|
+
startText: string;
|
|
116
|
+
/** compositionend 当场读到的控件文本:补发要拿它与 startText 比(见 attachInputComposition) */
|
|
117
|
+
endText: string;
|
|
118
|
+
/** compositionend 刚发生、还没跨过一个宏任务(见 heldByComposition ④) */
|
|
119
|
+
justEnded: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 按键修饰符 → 它要求的 KeyboardEvent.key(enter → 'Enter');映射表外的原样当作 key 值比对 */
|
|
123
|
+
function expectedKey(keyModifier: string): string {
|
|
124
|
+
return SOMA_KEY_MODIFIERS[keyModifier] ?? keyModifier;
|
|
125
|
+
}
|
|
126
|
+
|
|
20
127
|
export interface SomaEventMiddlewareContext {
|
|
21
128
|
config: SomaCompiledEvent;
|
|
22
129
|
element: HTMLElement;
|
|
@@ -75,7 +182,10 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
75
182
|
originalEvent: Event,
|
|
76
183
|
) => TContext;
|
|
77
184
|
private readonly pendingSet = new Set<string>();
|
|
185
|
+
private pendingRows = new WeakSet<HTMLElement>();
|
|
78
186
|
private readonly abortController = new AbortController();
|
|
187
|
+
/** 声明了 input / keydown / keyup 时才有(见 attachInputComposition) */
|
|
188
|
+
private composition: InputComposition | null = null;
|
|
79
189
|
|
|
80
190
|
constructor(options: SomaEventEngineOptions<TContext>) {
|
|
81
191
|
this.manifest = options.manifest;
|
|
@@ -109,15 +219,43 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
109
219
|
eventTypes.add(event.domEvent ?? 'click');
|
|
110
220
|
}
|
|
111
221
|
|
|
222
|
+
// 闸门的监听先于委托监听挂上:同一个事件到达容器时,闸门先更新组合状态,分发再按它判断。
|
|
223
|
+
// input 靠它挡住组合中间态并在组合结束后补发一次;keydown / keyup 靠它认出"这一发是输入法在用"。
|
|
224
|
+
if (eventTypes.has('input') || eventTypes.has('keydown') || eventTypes.has('keyup')) {
|
|
225
|
+
this.attachInputComposition();
|
|
226
|
+
}
|
|
227
|
+
|
|
112
228
|
for (const eventType of eventTypes) {
|
|
113
229
|
this.adapter.listen(
|
|
114
230
|
this.container,
|
|
115
|
-
|
|
231
|
+
// Map 而非对象字面量:snake_case 的疑似 emit 名(如 constructor)不能撞上原型键
|
|
232
|
+
DELEGATED_LISTEN_TYPE.get(eventType) ?? eventType,
|
|
116
233
|
(event) => {
|
|
234
|
+
// 输入法组合中的按键整发不分发,选词与确认用的键全部交给输入法(见 IME_HELD_KEY_EVENTS / heldByComposition)
|
|
235
|
+
if (IME_HELD_KEY_EVENTS.has(eventType) && this.heldByComposition(event)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// 查表用声明名:focusin 送来的焦点变化按 `focus:<somaId>` 找处理器。
|
|
239
|
+
// 同时声明了 x.focus 与 x.focusin 时是两个 focusin 监听各查各的键,各触发一次。
|
|
117
240
|
const resolved = this.resolveEventBinding(eventType, event.target, event);
|
|
118
241
|
if (!resolved) {
|
|
119
242
|
return;
|
|
120
243
|
}
|
|
244
|
+
// 必须在交给调度器之前:处理器执行时派发可能早已结束(见 SYNC_PREVENT_DEFAULT)
|
|
245
|
+
if (SYNC_PREVENT_DEFAULT.has(eventType)) {
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
}
|
|
248
|
+
const composition = eventType === 'input' ? this.composition : null;
|
|
249
|
+
if (composition) {
|
|
250
|
+
// 组合中的 input 不执行,最终值由组合结束后补发(见 attachInputComposition)
|
|
251
|
+
if (composition.gate.holds(event)) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
// 组合结束后带最终值的 input(WebKit 的顺序):照常执行这一次,撤掉补发
|
|
255
|
+
if (event.target === composition.target) {
|
|
256
|
+
composition.gate.settled();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
121
259
|
void this.execute(resolved.config, resolved.element, event);
|
|
122
260
|
},
|
|
123
261
|
this.abortController.signal,
|
|
@@ -125,6 +263,119 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
125
263
|
}
|
|
126
264
|
}
|
|
127
265
|
|
|
266
|
+
/**
|
|
267
|
+
* 容器上的输入法组合闸门:判断复用 SomaCompositionGate(组合中的认定、各浏览器最终值落定的时机见它的注释),
|
|
268
|
+
* 按容器挂一份,容器内同一时刻只有获得焦点的那个控件在组合。挡两件事——input 声明的中间态(下面)与
|
|
269
|
+
* keydown / keyup 的整发分发(见 heldByComposition):判断只此一处,组件不必各判一次。
|
|
270
|
+
*
|
|
271
|
+
* 组合进行中控件上是拼音、注音这类中间态,浏览器照样逐键派发 input;Chromium 组合结束后不再派发 input。
|
|
272
|
+
* 不挡的话,处理器在组合期间照常执行(页面 model 此时不回写,处理器读到的页面字段还是组合前的值),
|
|
273
|
+
* 组合结束却收不到带最终值的那一次;处理器在组合期间改写控件的值还会打断组合。
|
|
274
|
+
*
|
|
275
|
+
* 所以组合中的 input 不执行处理器,组合结束后执行一次:
|
|
276
|
+
* - WebKit 顺序:compositionend 之后来了带最终值、不在组合中的 input,照常分发,撤掉闸门排下的补发;
|
|
277
|
+
* - Chromium 顺序:没有后续 input,由闸门的补写补发一次;compositionend 当场的控件文本与组合开始时相同(取消、删光)不补发。
|
|
278
|
+
* 连续打字时下一次 compositionstart 先把补发做掉,每个字上屏各执行一次。
|
|
279
|
+
*
|
|
280
|
+
* 补发时处理器第二实参是这次组合的 compositionend 事件:target 就是控件,此时 target.value 已是最终值,
|
|
281
|
+
* `event.data` 是上屏的字;`event.type` 为 'compositionend',没有 inputType / isComposing。
|
|
282
|
+
* 不另造 input 事件:新建的事件没派发过,target 为 null,读 event.target.value 的处理器拿不到值;
|
|
283
|
+
* 也不把组合中最后一个 input 留下来传:它的 isComposing 为 true,按它跳过组合中间态的处理器会连最终值一起跳过。
|
|
284
|
+
* 组件库里声明 input 的处理器都从控件或 event.target 读值,不看事件类型。
|
|
285
|
+
*
|
|
286
|
+
* 与 model 的先后:页面 model 的补写排在补发之前(控件上的闸门先于容器收到 compositionend),
|
|
287
|
+
* 补发走的仍是 execute,处理器执行前照常整表同步 model,处理器读到的页面字段已是最终值——与英文键入的一次 input 相同。
|
|
288
|
+
*
|
|
289
|
+
* 失焦结束组合(点别处、Tab、脚本 blur())时 Chromium 在同一轮派发里接着发 change、blur / focusout,点别处还有随后的 click;
|
|
290
|
+
* 闸门的补写要等下一个宏任务,而浏览器先处理排队的输入事件,补发会落到这些处理器全部执行之后。
|
|
291
|
+
* 所以容器上收到 change / focusout 时先把排着的补发做掉(此刻控件上已是最终值,见 SomaCompositionGate),
|
|
292
|
+
* 执行顺序与英文键入后失焦相同:input → change → blur → click。这两个监听同样先于委托监听挂上。
|
|
293
|
+
* 不在组合中的输入(英文键入、粘贴、脚本派发的 input)分发不变;没有声明 input / keydown / keyup 的容器不挂闸门。
|
|
294
|
+
*/
|
|
295
|
+
private attachInputComposition(): void {
|
|
296
|
+
const signal = this.abortController.signal;
|
|
297
|
+
const composition: InputComposition = {
|
|
298
|
+
target: null,
|
|
299
|
+
startText: '',
|
|
300
|
+
endText: '',
|
|
301
|
+
justEnded: false,
|
|
302
|
+
gate: new SomaCompositionGate(
|
|
303
|
+
(type, listener) => this.adapter.listen(this.container, type, listener, signal),
|
|
304
|
+
signal,
|
|
305
|
+
(end) => {
|
|
306
|
+
const target = end.target;
|
|
307
|
+
if (!(target instanceof Element)) return;
|
|
308
|
+
// "文本没变就不补发"比的是 compositionend 当场的文本,不是补发时的文本:
|
|
309
|
+
// 组合期间被推迟的 model 值在补发之前就写进了控件(控件上的闸门先于容器收到 compositionend,
|
|
310
|
+
// 补写排在容器补发之前,见 dom-renderer 的 deferredView),补发时再读控件,文本已经与组合开始时不同,
|
|
311
|
+
// 于是取消组合也照样补发一次、处理器读到的 `data` 是空串——这正是那条判断拦不住的缺口。
|
|
312
|
+
// 换成 compositionend 当场的快照:取消、删光时控件已经回到组合开始的样子,不补发;
|
|
313
|
+
// 上屏、以及"选中一段文本后组合再取消"(那段真的被删掉了)文本都变了,照常补发。
|
|
314
|
+
if (target === composition.target && composition.endText === composition.startText) return;
|
|
315
|
+
const resolved = this.resolveEventBinding('input', target, end);
|
|
316
|
+
if (resolved) {
|
|
317
|
+
void this.execute(resolved.config, resolved.element, end);
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
(start) => {
|
|
321
|
+
composition.target = start.target;
|
|
322
|
+
composition.startText = start.target instanceof Element ? composedText(this.adapter, start.target) : '';
|
|
323
|
+
composition.endText = composition.startText;
|
|
324
|
+
},
|
|
325
|
+
),
|
|
326
|
+
};
|
|
327
|
+
for (const type of ['change', 'focusout']) {
|
|
328
|
+
this.adapter.listen(this.container, type, () => composition.gate.flush(), signal);
|
|
329
|
+
}
|
|
330
|
+
// 闸门自己的 compositionend 监听先挂、这个后挂(都在容器的冒泡相位,补发还要等下一个宏任务,先后无妨):
|
|
331
|
+
// 这里当场记下控件文本给补发判断用,另记一个"刚结束"给按键判断的第 ④ 条用
|
|
332
|
+
this.adapter.listen(
|
|
333
|
+
this.container,
|
|
334
|
+
'compositionend',
|
|
335
|
+
(end) => {
|
|
336
|
+
composition.endText = end.target instanceof Element ? composedText(this.adapter, end.target) : '';
|
|
337
|
+
composition.justEnded = true;
|
|
338
|
+
// 跨一个宏任务就撤:Chromium 里确认键的 keydown 早在 compositionend 之前就过去了,
|
|
339
|
+
// 之后按的回车是新的一次按下("上屏后再按回车发送"),不能被这道豁免吞掉。
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
composition.justEnded = false;
|
|
342
|
+
}, 0);
|
|
343
|
+
},
|
|
344
|
+
signal,
|
|
345
|
+
);
|
|
346
|
+
this.composition = composition;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 这一发 keydown / keyup 是不是输入法在用。四条判断,前两条是社区通行写法
|
|
351
|
+
* (`event.isComposing || event.keyCode === 229`),后两条补上它们各自漏掉的那一发:
|
|
352
|
+
*
|
|
353
|
+
* ① `isComposing === true`:规范给的判断。Chromium / Firefox 上组合中的每一发按键都带它
|
|
354
|
+
* (Chromium 147 实测:组合 nihao 时按回车,keydown 的 isComposing 为 true)。
|
|
355
|
+
* ② `keyCode === 229`:输入法在处理这一发按键时键码恒为 229。WebKit 确认选词时先发 compositionend
|
|
356
|
+
* 再发那一发 keydown,isComposing 已经是 false,只剩 229 认得出来(WebKit bug 165004;Quill 的
|
|
357
|
+
* keyboard 模块、React Aria 的 usePress 都这么判,本仓库 soma-ui/src/shared/press.ts 同样)。
|
|
358
|
+
* keyCode 虽已废弃但各浏览器都还在发,且只有输入法路径取 229,正常按键取不到这个值。
|
|
359
|
+
* ③ 容器自己看到的组合状态:事件不带 isComposing(手工派发的 KeyboardEvent、非浏览器宿主)时兜底。
|
|
360
|
+
* 组合期间脚本改写控件值、Chromium 静默丢掉组合不发 compositionend 时,闸门收到一次不在组合中的
|
|
361
|
+
* input 就复位(见 SomaCompositionGate),闸不会一直关着。
|
|
362
|
+
* ④ 只在 WebKit 上:compositionend 之后、还没跨过一个宏任务的第一发 keydown。确认选词那一发落在这里,
|
|
363
|
+
* 是 ② 失手(不是每个输入法都把 keyCode 交成 229)时的第二道,社区通行的兜底写法——留一个
|
|
364
|
+
* "组合刚结束"的短命标志,下一个宏任务即撤。只豁免一发,所以"上屏后再按一次回车"照常执行。
|
|
365
|
+
* 不开给别的引擎的理由见 isWebKitHost:Chromium 的顺序反过来,开了只会误伤真实按下的回车。
|
|
366
|
+
*/
|
|
367
|
+
private heldByComposition(event: Event): boolean {
|
|
368
|
+
const key = event as KeyboardEvent;
|
|
369
|
+
if (key.isComposing === true) return true;
|
|
370
|
+
if (key.keyCode === 229) return true;
|
|
371
|
+
const composition = this.composition;
|
|
372
|
+
if (!composition) return false;
|
|
373
|
+
if (composition.gate.holds()) return true;
|
|
374
|
+
if (!composition.justEnded) return false;
|
|
375
|
+
composition.justEnded = false;
|
|
376
|
+
return event.type === 'keydown' && isWebKitHost();
|
|
377
|
+
}
|
|
378
|
+
|
|
128
379
|
/**
|
|
129
380
|
* 从内层锚点向上查找第一个已注册事件的 data-soma-id。
|
|
130
381
|
* 避免点击 product_name 等子节点时,closest 停在无事件的子 id 上。
|
|
@@ -139,39 +390,50 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
139
390
|
// 沿 parentElement 向上找锚点对任何 Element 都成立;交给下游仍按 HTMLElement 类型传,
|
|
140
391
|
// 下游只用 getAttribute / parentElement / tagName / focus / dataset,SVGElement 同样具备。
|
|
141
392
|
let el: Element | null = start instanceof Element ? start : null;
|
|
142
|
-
while (el
|
|
393
|
+
while (el) {
|
|
143
394
|
const somaId = this.adapter.getAnchorId(el as HTMLElement);
|
|
144
395
|
if (somaId) {
|
|
145
396
|
const indexed = this.manifest.eventIndex.get(`${eventType}:${somaId}`);
|
|
146
|
-
//
|
|
397
|
+
// 带按键修饰符的绑定在这里就比对 event.key:不匹配的锚点不算命中,继续向上找
|
|
147
398
|
const config = this.pickKeyVariant(indexed, domEvent);
|
|
148
399
|
// emit 路由不响应冒泡 DOM 事件(如组件内部 input 冒泡的 change)
|
|
149
400
|
if (config && !config.emitRoute) {
|
|
150
401
|
return { element: el as HTMLElement, config };
|
|
151
402
|
}
|
|
152
403
|
}
|
|
404
|
+
if (el === this.container) break;
|
|
153
405
|
el = el.parentElement;
|
|
154
406
|
}
|
|
155
407
|
return null;
|
|
156
408
|
}
|
|
157
409
|
|
|
158
410
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
411
|
+
* 从锚点的绑定里挑与本次按键匹配的那条。返回 undefined 表示这个锚点不算命中,
|
|
412
|
+
* 由 resolveEventBinding 继续向上找——内层 `search_input.keydown.enter` 不截下 Escape,
|
|
413
|
+
* 外层 `dialog.keydown.escape` 才收得到。
|
|
414
|
+
*
|
|
415
|
+
* - 单条、不带修饰符(绝大多数绑定):原样返回,最近的声明者就命中,与按键无关。
|
|
416
|
+
* - 单条、带修饰符:按键匹配才返回。
|
|
417
|
+
* - 多条候选(同一锚点绑了 ↑↓←→/Enter/Esc):先挑修饰符与按键匹配的,
|
|
418
|
+
* 没有就退回不带修饰符的那条(同锚点的普通 keydown 兜底其余按键),两者都没有才不命中。
|
|
419
|
+
* - 不是 KeyboardEvent(手工派发的 `new Event('keydown')` 等)无键可比:
|
|
420
|
+
* 单条原样返回,多条只取不带修饰符的那条。
|
|
162
421
|
*/
|
|
163
422
|
private pickKeyVariant(
|
|
164
423
|
config: SomaCompiledEvent | undefined,
|
|
165
424
|
domEvent?: Event,
|
|
166
425
|
): SomaCompiledEvent | undefined {
|
|
167
426
|
if (!config?.keyVariants) {
|
|
427
|
+
if (config?.keyModifier && domEvent instanceof KeyboardEvent && domEvent.key !== expectedKey(config.keyModifier)) {
|
|
428
|
+
return undefined;
|
|
429
|
+
}
|
|
168
430
|
return config;
|
|
169
431
|
}
|
|
170
432
|
if (!(domEvent instanceof KeyboardEvent)) {
|
|
171
433
|
return config.keyVariants.find((variant) => !variant.keyModifier);
|
|
172
434
|
}
|
|
173
435
|
return config.keyVariants.find(
|
|
174
|
-
(variant) =>
|
|
436
|
+
(variant) => variant.keyModifier !== undefined && expectedKey(variant.keyModifier) === domEvent.key,
|
|
175
437
|
) ?? config.keyVariants.find((variant) => !variant.keyModifier);
|
|
176
438
|
}
|
|
177
439
|
|
|
@@ -188,6 +450,7 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
188
450
|
destroy(): void {
|
|
189
451
|
this.abortController.abort();
|
|
190
452
|
this.pendingSet.clear();
|
|
453
|
+
this.pendingRows = new WeakSet();
|
|
191
454
|
}
|
|
192
455
|
|
|
193
456
|
private async executeNow(
|
|
@@ -196,7 +459,9 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
196
459
|
originalEvent: Event,
|
|
197
460
|
): Promise<void> {
|
|
198
461
|
const startedAt = this.adapter.now();
|
|
199
|
-
const
|
|
462
|
+
const rowContext = this.getContext(element);
|
|
463
|
+
if (rowContext instanceof SomaRowScope && !rowContext.active) return;
|
|
464
|
+
const currentVar = rowContext instanceof SomaRowScope ? rowContext.data : rowContext;
|
|
200
465
|
const context = {
|
|
201
466
|
config,
|
|
202
467
|
element,
|
|
@@ -208,14 +473,15 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
208
473
|
};
|
|
209
474
|
|
|
210
475
|
const terminal = async (runtime: SomaEventMiddlewareContext & TContext): Promise<void> => {
|
|
211
|
-
if (!this.preCheck(config, config.somaId)) {
|
|
476
|
+
if (!this.preCheck(config, config.somaId, element)) {
|
|
212
477
|
runtime.status = 'blocked';
|
|
213
478
|
runtime.message = 'pre-check rejected';
|
|
214
479
|
return;
|
|
215
480
|
}
|
|
216
481
|
|
|
482
|
+
// 委托监听送来的按键已在 pickKeyVariant 比对过;这里拦的是直接调用 execute() 传入的按键事件
|
|
217
483
|
if (config.keyModifier && originalEvent instanceof KeyboardEvent) {
|
|
218
|
-
if (originalEvent.key !== (
|
|
484
|
+
if (originalEvent.key !== expectedKey(config.keyModifier)) {
|
|
219
485
|
runtime.status = 'blocked';
|
|
220
486
|
runtime.message = `key modifier mismatch: expected ${config.keyModifier}`;
|
|
221
487
|
return;
|
|
@@ -262,36 +528,67 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
262
528
|
try {
|
|
263
529
|
if (runsHandler) {
|
|
264
530
|
try {
|
|
265
|
-
this.
|
|
531
|
+
if (rowContext instanceof SomaRowScope) this.pendingRows.add(element);
|
|
532
|
+
else this.pendingSet.add(config.somaId);
|
|
266
533
|
this.callbacks.onSyncModels?.();
|
|
267
|
-
const fn = this.resolveFunction(config.funcPath!,
|
|
534
|
+
const fn = this.resolveFunction(config.funcPath!, rowContext);
|
|
268
535
|
// emit 路由:第二实参为契约 payload;DOM 路由保持 originalEvent
|
|
269
536
|
const handlerArg = isSomaEmitEvent(originalEvent) ? originalEvent.payload : originalEvent;
|
|
270
537
|
result = await fn(currentVar, handlerArg);
|
|
538
|
+
// await 期间这一行被删了:后面的 commit / postAction 都是对着不存在的行做的,直接退。
|
|
539
|
+
// 这条出口既不 commit 也不 discard,处理器写下的页面级字段交给 finally 里的
|
|
540
|
+
// onEndTransaction 当场收口上屏(见 render-engine 的 endTransaction);
|
|
541
|
+
// 过去 endTransaction 只是递减计数,这一笔要等下一次事件才顺带上屏。
|
|
542
|
+
if (rowContext instanceof SomaRowScope && !rowContext.active) return;
|
|
271
543
|
} catch (error) {
|
|
272
544
|
runtime.status = 'error';
|
|
273
545
|
runtime.message = error instanceof Error ? error.message : String(error);
|
|
274
546
|
result = false;
|
|
275
547
|
} finally {
|
|
276
|
-
this.
|
|
548
|
+
if (rowContext instanceof SomaRowScope) this.pendingRows.delete(element);
|
|
549
|
+
else this.pendingSet.delete(config.somaId);
|
|
277
550
|
}
|
|
278
551
|
}
|
|
279
552
|
|
|
280
553
|
const isError = runtime.status === 'error';
|
|
281
554
|
|
|
282
|
-
//
|
|
555
|
+
// 处理器明确声明「这次什么都没改」——**只有字面的 `false` 算数**。
|
|
556
|
+
//
|
|
557
|
+
// 为什么要认这一句:commit 在页面级是按脏路径提交的,没写过东西就是空转;
|
|
558
|
+
// 但在组件实例级它等于**整树重渲**(实例作用域根是普通对象,没有代理,
|
|
559
|
+
// 见 component-manager 的 onCommit)。行内嵌套列表每次重渲整体重建,
|
|
560
|
+
// 于是「按一下与本组件无关的键(裸 Shift、字母、F2)」就能把正被聚焦的
|
|
561
|
+
// 那个 <button> 换掉,焦点掉回 <body>。日历三件套和查询控制台各自接一手
|
|
562
|
+
// 焦点是治标,真正的病在这里:处理器说了不管,引擎还是照提交。
|
|
563
|
+
//
|
|
564
|
+
// 向后兼容的边界划在「写没写返回值」上:`undefined` 是存量处理器的绝大多数
|
|
565
|
+
// 形态(改完字段直接收尾),一律当作「改了」照常提交,行为逐值不变;
|
|
566
|
+
// 异步处理器同理——上面已经 `await` 过,兑现值是 `false` 才算声明,
|
|
567
|
+
// 兑现 `undefined` 或 Promise 本身都照常提交。
|
|
568
|
+
const declaredNoChange = result === false;
|
|
569
|
+
|
|
570
|
+
// DOM 同步:handler 正常返回且没声明「没改动」时提交
|
|
283
571
|
if (runsHandler && !isError) {
|
|
284
572
|
const forceRefresh =
|
|
285
|
-
|
|
573
|
+
!declaredNoChange &&
|
|
286
574
|
config.type === 'UI_REFRESH' &&
|
|
287
575
|
config.refreshForce === true;
|
|
288
576
|
|
|
289
577
|
if (forceRefresh) {
|
|
290
578
|
this.callbacks.onDiscardPending?.();
|
|
291
579
|
await this.callbacks.onRefresh();
|
|
292
|
-
} else {
|
|
580
|
+
} else if (!declaredNoChange) {
|
|
293
581
|
await this.callbacks.onCommit();
|
|
294
582
|
}
|
|
583
|
+
// declaredNoChange:不提交这次重渲。
|
|
584
|
+
// 处理器要是说了假话——嘴上没改、手上改了页面字段——数据也丢不了:
|
|
585
|
+
// 页面级的写入都进了代理的 pending patch,下面 finally 里的 onEndTransaction
|
|
586
|
+
// 当场把这本账收口提交(见 render-engine 的 endTransaction),不留到下一次事件,
|
|
587
|
+
// 也就不会被下一次事件的 discardPendingPatches 连坐抹掉。
|
|
588
|
+
// 什么都没写的那一次仍是空转:pending 是空的,收口一步都不走,DOM 一次都不碰
|
|
589
|
+
// ——「说了不管就别重渲」这条承诺没有被收口换掉。
|
|
590
|
+
// 组件实例级没有这本脏账,声明就按字面采信;实例内部状态改了要上屏,
|
|
591
|
+
// 控制器手上一直有 `refresh()`(soma-ui 里已是通行写法)。
|
|
295
592
|
} else if (isError) {
|
|
296
593
|
this.callbacks.onDiscardPending?.();
|
|
297
594
|
}
|
|
@@ -341,8 +638,10 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
341
638
|
let value: unknown;
|
|
342
639
|
if (pipeline.funcPath && pipeline.type !== 'NAV_STATIC') {
|
|
343
640
|
const currentVar = this.getContext(element);
|
|
641
|
+
if (currentVar instanceof SomaRowScope && !currentVar.active) return undefined;
|
|
344
642
|
const fn = this.resolveFunction(pipeline.funcPath, currentVar);
|
|
345
|
-
value = await fn(currentVar, undefined);
|
|
643
|
+
value = await fn(currentVar instanceof SomaRowScope ? currentVar.data : currentVar, undefined);
|
|
644
|
+
if (currentVar instanceof SomaRowScope && !currentVar.active) return undefined;
|
|
346
645
|
// 一步之内就 commit:后面的步骤(和它们的 when)要看得见这一步的效果
|
|
347
646
|
await this.callbacks.onCommit();
|
|
348
647
|
}
|
|
@@ -371,8 +670,8 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
371
670
|
return undefined;
|
|
372
671
|
}
|
|
373
672
|
|
|
374
|
-
private preCheck(config: SomaCompiledEvent, somaId: string): boolean {
|
|
375
|
-
if (this.pendingSet.has(somaId)) {
|
|
673
|
+
private preCheck(config: SomaCompiledEvent, somaId: string, element: HTMLElement): boolean {
|
|
674
|
+
if (this.getContext(element) instanceof SomaRowScope ? this.pendingRows.has(element) : this.pendingSet.has(somaId)) {
|
|
376
675
|
return false;
|
|
377
676
|
}
|
|
378
677
|
|
|
@@ -461,6 +760,14 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
461
760
|
private resolveFunction(funcPath: string, currentVar: any): Function {
|
|
462
761
|
const segments = funcPath.split('.');
|
|
463
762
|
const rootToken = segments[0];
|
|
763
|
+
if (currentVar instanceof SomaRowScope) {
|
|
764
|
+
if (!currentVar.has(rootToken)) return this.resolver.resolveFunction(funcPath);
|
|
765
|
+
const ownerPath = segments.slice(0, -1).join('.');
|
|
766
|
+
const owner = currentVar.read(ownerPath, () => undefined);
|
|
767
|
+
const fn = readRowPath(owner, segments.slice(-1));
|
|
768
|
+
if (typeof fn !== 'function') throw new Error('[soma-core][引擎] Row handler is not a function');
|
|
769
|
+
return fn.bind(owner);
|
|
770
|
+
}
|
|
464
771
|
|
|
465
772
|
// When the root token refers to a list-item var alias and we have a
|
|
466
773
|
// concrete item context, resolve the function directly on that item rather
|
|
@@ -472,12 +779,12 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
472
779
|
owner = current;
|
|
473
780
|
current = current?.[segments[index]];
|
|
474
781
|
if (current === undefined) {
|
|
475
|
-
throw new Error(`[
|
|
782
|
+
throw new Error(`[soma-core][引擎] Cannot resolve "${segments[index]}" in "${funcPath}"`);
|
|
476
783
|
}
|
|
477
784
|
}
|
|
478
785
|
|
|
479
786
|
if (typeof current !== 'function') {
|
|
480
|
-
throw new Error(`[
|
|
787
|
+
throw new Error(`[soma-core][引擎] "${funcPath}" is not a function`);
|
|
481
788
|
}
|
|
482
789
|
|
|
483
790
|
return current.bind(owner);
|