soma-core 1.3.2 → 1.3.4
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/README.md +43 -0
- package/app/SomaPageClient.tsx +22 -68
- package/app/[...path]/page.tsx +7 -6
- package/app/api/[...path]/route.ts +3 -3
- package/app/api/soma-registry/[...path]/route.ts +67 -0
- package/app/components/SomaHostPage.tsx +3 -8
- package/app/components/SomaPageClientBoundary.tsx +13 -0
- package/app/layout.tsx +6 -1
- package/app/page.tsx +3 -3
- package/app/soma/manifest/route.ts +1 -0
- package/app/soma/page-object/route.ts +1 -1
- package/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +19 -23
- package/core/build/compiler/html-include-expander.ts +56 -0
- package/core/build/compiler/page-assets.ts +26 -0
- package/core/build/compiler/page-declaration-compiler.ts +85 -0
- package/core/build/compiler/rollup-plugin-soma.ts +4 -13
- package/core/build/compiler/route-builder.ts +0 -2
- package/core/build/compiler/rspack-plugin-soma.js +1 -10
- package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
- package/core/build/compiler/soma-precompile.js +3581 -2387
- package/core/build/compiler/soma-precompile.ts +44 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
- package/core/build/compiler/soma-webpack-loader.js +6 -15
- package/core/build/compiler/vite-plugin-soma.ts +9 -21
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +281 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +133 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
- package/core/build/lsp/extra-completion.cjs +14 -8
- package/core/build/lsp/lsp-navigation.cjs +50 -43
- package/core/build/lsp/soma-declaration.cjs +85 -0
- package/core/build/lsp/ui-yaml-completion.cjs +98 -104
- package/core/build/v2/block-compile.ts +200 -0
- package/core/build/v2/block-loader.ts +33 -0
- package/core/build/v2/html-index.ts +120 -0
- package/core/build/v2/migrate-v1.ts +370 -0
- package/core/build/v2/soma-file-loader.ts +216 -0
- package/core/client/adaptive/flush-scheduler.ts +96 -0
- package/core/client/adaptive/hysteresis.ts +56 -0
- package/core/client/adaptive/index.ts +23 -0
- package/core/client/adaptive/observer-pool.ts +90 -0
- package/core/client/base/SomaPageRootBase.ts +50 -0
- package/core/client/compiler/adaptive-compile.ts +136 -0
- package/core/client/compiler/manifest-compiler.ts +155 -27
- package/core/client/component/ai-catalog.ts +277 -0
- package/core/client/component/component-definition.types.ts +65 -0
- package/core/client/component/component-expander.ts +119 -0
- package/core/client/component/component-manager.ts +933 -0
- package/core/client/component/component-pack.ts +445 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -0
- package/core/client/component/pack-styles.ts +94 -0
- package/core/client/component/scoped-adapter.ts +85 -0
- package/core/client/component/verify-pack.ts +247 -0
- package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
- package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
- package/core/client/container/SomaContainerAdapter.ts +186 -180
- package/core/client/data/data-object-resolver.ts +417 -0
- package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
- package/core/client/diagnostics/boot-timings.ts +152 -0
- package/core/client/engine/asset-resolver.ts +12 -2
- package/core/client/engine/dom-renderer.ts +249 -24
- package/core/client/engine/emit-event.ts +21 -0
- package/core/client/engine/event-engine.ts +34 -4
- package/core/client/engine/on-change-engine.ts +1 -1
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +11 -10
- package/core/client/engine/render-engine.ts +39 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +380 -7
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/observability/error-reporter.ts +173 -0
- package/core/client/parser/adaptive-parser.ts +264 -0
- package/core/client/parser/data-config-parser.ts +396 -0
- package/core/client/parser/pipeline-parser.ts +15 -3
- package/core/client/parser/style-config-parser.ts +65 -2
- package/core/client/parser/ui-config-parser.ts +52 -3
- package/core/client/parser/v2/namespace.ts +182 -0
- package/core/client/parser/v2/page-parser.ts +359 -0
- package/core/client/parser/v2/use-parser.ts +412 -0
- package/core/client/parser/value-lang.ts +340 -0
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +161 -0
- package/core/client/registry/index.ts +28 -0
- package/core/client/registry/page-lifecycle.ts +171 -0
- package/core/client/registry/remote-page.ts +139 -0
- package/core/client/runtime/SomaRuntimeServices.ts +24 -0
- package/core/client/security/attribute-presence.ts +70 -0
- package/core/client/security/html-sanitizer.ts +113 -0
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/theme/harmony.ts +307 -0
- package/core/client/theme/scene-tokens.ts +134 -0
- package/core/client/theme/theme-axes.ts +228 -0
- package/core/client/theme/theme-engine.ts +1196 -0
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +262 -2
- package/core/server/api/IService.ts +18 -6
- package/core/server/api/load-host-service.ts +3 -3
- package/core/server/host/content-security-policy.ts +190 -0
- package/core/server/host/csp-nonce-metadata.ts +75 -0
- package/core/server/host/resolve-host-request-hook.ts +5 -0
- package/core/server/host/server-page-assets.ts +34 -7
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +45 -1
- package/core/server/infra/cache/ServerFileCache.ts +1 -1
- package/core/server/mock/node/cli.mjs +2 -2
- package/core/server/registry/api-registry-store.ts +518 -0
- package/core/server/registry/conditional-object-store.ts +29 -0
- package/core/server/registry/declaration-precompiler.ts +99 -0
- package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
- package/core/server/registry/index.ts +142 -0
- package/core/server/registry/page-registry-repository.ts +373 -0
- package/core/server/registry/page-registry-store.ts +932 -0
- package/core/server/registry/registry-error.ts +17 -0
- package/core/server/registry/registry-file-lock.ts +173 -0
- package/core/server/registry/registry-response.ts +71 -0
- package/core/server/registry/registry-subjects.ts +194 -0
- package/core/server/registry/registry-write-pipeline.ts +240 -0
- package/core/server/registry/request-body-limit.ts +99 -0
- package/core/server/registry/services/apis/Get.ts +25 -0
- package/core/server/registry/services/apis/List.ts +41 -0
- package/core/server/registry/services/apis/Register.ts +39 -0
- package/core/server/registry/services/apis/Unregister.ts +24 -0
- package/core/server/registry/services/index.ts +40 -0
- package/core/server/registry/services/pages/Get.ts +96 -0
- package/core/server/registry/services/pages/List.ts +53 -0
- package/core/server/registry/services/pages/Register.ts +49 -0
- package/core/server/registry/services/pages/Rollback.ts +36 -0
- package/core/server/registry/services/pages/Unregister.ts +23 -0
- package/core/server/registry/services/service-utils.ts +21 -0
- package/core/server/registry/validation/compile-gate.ts +54 -0
- package/core/server/registry/validation/component-existence.ts +55 -0
- package/core/server/registry/validation/credential-ban.ts +86 -0
- package/core/server/registry/validation/cross-check.ts +67 -0
- package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
- package/core/shared/types/adaptive.types.ts +109 -0
- package/core/shared/types/component-contract.types.ts +120 -0
- package/core/shared/types/data-config.types.ts +105 -0
- package/core/shared/types/domain.types.ts +6 -0
- package/core/shared/types/engine.types.ts +41 -35
- package/core/shared/types/manifest.types.ts +55 -32
- package/core/shared/types/scope-manifest.types.ts +96 -0
- package/core/shared/types/style-config.types.ts +9 -0
- package/core/shared/types/ui-config.types.ts +118 -98
- package/dist/cli/soma.js +20 -5
- package/dist/core/index.cjs +7811 -1380
- package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
- package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
- package/dist/types/build/compiler/page-assets.d.ts +3 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +40 -0
- package/dist/types/build/eject/apply-eject.d.ts +22 -0
- package/dist/types/build/eject/plan-eject.d.ts +32 -0
- package/dist/types/build/v2/block-compile.d.ts +28 -0
- package/dist/types/build/v2/block-loader.d.ts +9 -0
- package/dist/types/build/v2/html-index.d.ts +37 -0
- package/dist/types/build/v2/migrate-v1.d.ts +32 -0
- package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
- package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
- package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
- package/dist/types/client/adaptive/index.d.ts +5 -0
- package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
- package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
- package/dist/types/client/component/ai-catalog.d.ts +73 -0
- package/dist/types/client/component/component-definition.types.d.ts +54 -0
- package/dist/types/client/component/component-expander.d.ts +25 -0
- package/dist/types/client/component/component-manager.d.ts +160 -0
- package/dist/types/client/component/component-pack.d.ts +110 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/contract-compat.d.ts +16 -0
- package/dist/types/client/component/example-v2.d.ts +9 -0
- package/dist/types/client/component/pack-styles.d.ts +22 -0
- package/dist/types/client/component/scoped-adapter.d.ts +18 -0
- package/dist/types/client/component/verify-pack.d.ts +14 -0
- package/dist/types/client/data/data-object-resolver.d.ts +71 -0
- package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
- package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
- package/dist/types/client/engine/asset-resolver.d.ts +7 -1
- package/dist/types/client/engine/dom-renderer.d.ts +51 -1
- package/dist/types/client/engine/emit-event.d.ts +6 -0
- package/dist/types/client/engine/event-engine.d.ts +6 -0
- package/dist/types/client/engine/render-engine.d.ts +25 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +118 -0
- package/dist/types/client/observability/error-reporter.d.ts +51 -0
- package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
- package/dist/types/client/parser/data-config-parser.d.ts +34 -0
- package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
- package/dist/types/client/parser/style-config-parser.d.ts +5 -3
- package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
- package/dist/types/client/parser/v2/namespace.d.ts +52 -0
- package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
- package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
- package/dist/types/client/parser/value-lang.d.ts +63 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +50 -0
- package/dist/types/client/registry/index.d.ts +10 -0
- package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
- package/dist/types/client/registry/remote-page.d.ts +52 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
- package/dist/types/client/security/attribute-presence.d.ts +7 -0
- package/dist/types/client/security/html-sanitizer.d.ts +37 -0
- package/dist/types/client/security/url-guard.d.ts +11 -0
- package/dist/types/client/theme/harmony.d.ts +77 -0
- package/dist/types/client/theme/scene-tokens.d.ts +25 -0
- package/dist/types/client/theme/theme-axes.d.ts +81 -0
- package/dist/types/client/theme/theme-engine.d.ts +77 -0
- package/dist/types/client/theme/tone-solver.d.ts +47 -0
- package/dist/types/client/typography/typography-base.d.ts +15 -0
- package/dist/types/client/validation/contract-validator.d.ts +2 -0
- package/dist/types/index.d.ts +47 -2
- package/dist/types/server/api/IService.d.ts +18 -6
- package/dist/types/server/host/content-security-policy.d.ts +53 -0
- package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
- package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
- package/dist/types/server/host/server-page-assets.d.ts +2 -0
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +6 -1
- package/dist/types/server/registry/api-registry-store.d.ts +141 -0
- package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
- package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
- package/dist/types/server/registry/index.d.ts +29 -0
- package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
- package/dist/types/server/registry/page-registry-store.d.ts +259 -0
- package/dist/types/server/registry/registry-error.d.ts +12 -0
- package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
- package/dist/types/server/registry/registry-response.d.ts +18 -0
- package/dist/types/server/registry/registry-subjects.d.ts +59 -0
- package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
- package/dist/types/server/registry/request-body-limit.d.ts +31 -0
- package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
- package/dist/types/server/registry/services/apis/List.d.ts +10 -0
- package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
- package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
- package/dist/types/server/registry/services/index.d.ts +3 -0
- package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
- package/dist/types/server/registry/services/pages/List.d.ts +13 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
- package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
- package/dist/types/server/registry/services/service-utils.d.ts +10 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +12 -0
- package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
- package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
- package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
- package/dist/types/shared/types/adaptive.types.d.ts +88 -0
- package/dist/types/shared/types/component-contract.types.d.ts +78 -0
- package/dist/types/shared/types/data-config.types.d.ts +81 -0
- package/dist/types/shared/types/domain.types.d.ts +6 -0
- package/dist/types/shared/types/engine.types.d.ts +6 -0
- package/dist/types/shared/types/manifest.types.d.ts +23 -0
- package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
- package/dist/types/shared/types/style-config.types.d.ts +8 -0
- package/dist/types/shared/types/ui-config.types.d.ts +20 -0
- package/editor/vscode/package.json +1 -24
- package/global.d.ts +5 -11
- package/next.config.js +85 -28
- package/package.json +33 -11
- package/proxy.ts +62 -0
- package/tailwind.config.ts +0 -1
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- package/core/client/engine/theme-variables.ts +0 -37
- package/dist/tsconfig.types.tsbuildinfo +0 -1
- package/dist/types/client/engine/theme-variables.d.ts +0 -3
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
- package/middleware.ts +0 -33
|
@@ -9,9 +9,41 @@ import type {
|
|
|
9
9
|
} from '../../shared/types/ui-config.types';
|
|
10
10
|
import type { SomaScopeResolver } from './scope-resolver';
|
|
11
11
|
import { longestIncreasingSubsequence } from './lis';
|
|
12
|
+
import {
|
|
13
|
+
defaultPipeRegistry,
|
|
14
|
+
hasPipes,
|
|
15
|
+
parsePipedValue,
|
|
16
|
+
type SomaPipeContext,
|
|
17
|
+
type SomaPipeRegistry,
|
|
18
|
+
} from '../pipes/pipe-registry';
|
|
19
|
+
import type { SomaPipeCall } from '../../shared/types/scope-manifest.types';
|
|
12
20
|
|
|
13
21
|
export type ModelWriteBack = (path: string, value: string) => void;
|
|
14
22
|
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 行内组件钩子:列表/对象作用域渲染遇到带 props 的锚点时回调。
|
|
26
|
+
* 组件管理器据此在行克隆上按需展开/更新组件实例(scopeData 为行数据)。
|
|
27
|
+
*/
|
|
28
|
+
export type SomaRowComponentHook = (
|
|
29
|
+
element: HTMLElement,
|
|
30
|
+
propsDecl: Record<string, unknown>,
|
|
31
|
+
scopeData: any,
|
|
32
|
+
) => void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 行内组件释放钩子:一段**已渲染产物**即将离开 DOM 时回调(入参是被摘除的子树根)。
|
|
36
|
+
*
|
|
37
|
+
* 为什么必须有它:渲染器删行只做 DOM 层的 `remove()` / `clearRenderedChildren()`,
|
|
38
|
+
* 而行里可能住着组件实例(组件管理器的强引用 Set + 各自的事件引擎/控制器)。
|
|
39
|
+
* 没有这条通道,删掉的行会留下:onUnmount 不触发(焦点陷阱/滚动锁/定时器不回收)、
|
|
40
|
+
* 实例表随重渲线性膨胀、事件监听留在游离 DOM 上仍能派发 emit(幽灵行)。
|
|
41
|
+
* 三者都不报错——正是"静默失败"那一类。
|
|
42
|
+
*
|
|
43
|
+
* 约定:钩子在节点**还挂在树上**时调用(实现方可以再查子树),调用后渲染器才真的摘除。
|
|
44
|
+
*/
|
|
45
|
+
export type SomaRowComponentReleaseHook = (removedRoot: HTMLElement) => void;
|
|
46
|
+
|
|
15
47
|
export class SomaDomRenderer {
|
|
16
48
|
private adapter: IContainerAdapter | null = null;
|
|
17
49
|
private resolver: SomaScopeResolver | null = null;
|
|
@@ -19,21 +51,126 @@ export class SomaDomRenderer {
|
|
|
19
51
|
private modelWriteBack: ModelWriteBack | null = null;
|
|
20
52
|
private modelListeners = new WeakSet<HTMLElement>();
|
|
21
53
|
private modelAbort = new AbortController();
|
|
54
|
+
private componentHook: SomaRowComponentHook | null = null;
|
|
55
|
+
private componentReleaseHook: SomaRowComponentReleaseHook | null = null;
|
|
56
|
+
private pipeRegistry: SomaPipeRegistry = defaultPipeRegistry;
|
|
57
|
+
|
|
58
|
+
setComponentHook(hook: SomaRowComponentHook | null): void {
|
|
59
|
+
this.componentHook = hook;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setComponentReleaseHook(hook: SomaRowComponentReleaseHook | null): void {
|
|
63
|
+
this.componentReleaseHook = hook;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 摘除单个已渲染节点:先放行释放钩子,再离开 DOM(顺序不可颠倒——查子树需要它还在树上) */
|
|
67
|
+
private removeRendered(element: HTMLElement): void {
|
|
68
|
+
this.componentReleaseHook?.(element);
|
|
69
|
+
element.remove();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 清空容器内的渲染产物(保留 <template>)。
|
|
74
|
+
* 与 `adapter.clearRenderedChildren` 的唯一区别:逐个放行释放钩子。
|
|
75
|
+
* 无钩子时(非组件页面)零额外开销,直接走适配器原路径。
|
|
76
|
+
*/
|
|
77
|
+
private clearRendered(element: HTMLElement): void {
|
|
78
|
+
if (this.componentReleaseHook) {
|
|
79
|
+
for (const child of Array.from(element.children)) {
|
|
80
|
+
if (child.tagName === 'TEMPLATE') continue;
|
|
81
|
+
this.componentReleaseHook(child as HTMLElement);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this.adapter?.clearRenderedChildren(element);
|
|
85
|
+
}
|
|
22
86
|
|
|
23
87
|
init(
|
|
24
88
|
adapter: IContainerAdapter,
|
|
25
89
|
resolver: SomaScopeResolver,
|
|
26
90
|
scopeTracker: WeakMap<HTMLElement, any>,
|
|
91
|
+
pipeRegistry?: SomaPipeRegistry,
|
|
27
92
|
): void {
|
|
28
93
|
this.adapter = adapter;
|
|
29
94
|
this.resolver = resolver;
|
|
30
95
|
this.scopeTracker = scopeTracker;
|
|
96
|
+
this.pipeRegistry = pipeRegistry ?? defaultPipeRegistry;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 行/对象作用域内查找锚点(经适配器,页面 data-soma-id 与实例 data-soma-scoped-id 同构):
|
|
101
|
+
* 行模板根元素自身就是锚点时也要命中(querySelector 只搜后代,
|
|
102
|
+
* 此前根自身锚点会静默失配,如 cart_row@title)。
|
|
103
|
+
*/
|
|
104
|
+
private findScopedAnchor(root: HTMLElement, somaId: string): HTMLElement | null {
|
|
105
|
+
if (!this.adapter) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (this.adapter.getAnchorId(root) === somaId) {
|
|
109
|
+
return root;
|
|
110
|
+
}
|
|
111
|
+
return this.adapter.findAnchor(root, somaId);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 收集列表容器的变体模板:'item' 默认 + 'item:变体'(异构列表 role_by 用) */
|
|
115
|
+
private collectRoleTemplates(element: HTMLElement): Record<string, DocumentFragment> | undefined {
|
|
116
|
+
const templates: Record<string, DocumentFragment> = {};
|
|
117
|
+
for (const child of Array.from(element.children)) {
|
|
118
|
+
if (child.tagName !== 'TEMPLATE') continue;
|
|
119
|
+
const role = child.getAttribute('data-soma-role');
|
|
120
|
+
if (role === 'item' || role?.startsWith('item:')) {
|
|
121
|
+
templates[role] = (child as HTMLTemplateElement).content;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return Object.keys(templates).length > 0 ? templates : undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 异构列表:按行数据取模板与变体名;同构列表回落默认模板 */
|
|
128
|
+
private pickRowTemplate(
|
|
129
|
+
entry: BindingEntry,
|
|
130
|
+
itemData: any,
|
|
131
|
+
): { template: DocumentFragment | undefined; variant: string } {
|
|
132
|
+
if (!entry.roleBy || !entry.templatesByRole) {
|
|
133
|
+
return { template: entry.templateCache, variant: '' };
|
|
134
|
+
}
|
|
135
|
+
const value = String(this.resolveShowValue(entry.roleBy, itemData) ?? '');
|
|
136
|
+
const variantTemplate = entry.templatesByRole[`item:${value}`];
|
|
137
|
+
if (variantTemplate) {
|
|
138
|
+
return { template: variantTemplate, variant: value };
|
|
139
|
+
}
|
|
140
|
+
const fallback = entry.templatesByRole['item'] ?? entry.templateCache;
|
|
141
|
+
if (!fallback) {
|
|
142
|
+
console.warn(`[soma-core][引擎] 异构列表无匹配模板且无默认模板: role_by 值 "${value}"`);
|
|
143
|
+
}
|
|
144
|
+
return { template: fallback, variant: '' };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 页面作用域的管道上下文(编译路径 text/attr 用) */
|
|
148
|
+
private rootPipeContext(): SomaPipeContext {
|
|
149
|
+
const resolver = this.resolver!;
|
|
150
|
+
return {
|
|
151
|
+
read: (path) => resolver.readFromRootCompiled(resolver.resolvePath(path)),
|
|
152
|
+
locale: () => resolver.readFromRoot('_locale') as Record<string, unknown> | undefined,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private applyPipes(value: unknown, pipes: SomaPipeCall[], ctx: SomaPipeContext): string {
|
|
157
|
+
return this.pipeRegistry.apply(value, pipes, ctx);
|
|
31
158
|
}
|
|
32
159
|
|
|
33
160
|
setModelWriteBack(fn: ModelWriteBack): void {
|
|
34
161
|
this.modelWriteBack = fn;
|
|
35
162
|
}
|
|
36
163
|
|
|
164
|
+
/** 模型回写必须在绑定表创建时附着,不能依赖首帧渲染是否走到该项。 */
|
|
165
|
+
private ensureModelListener(element: HTMLElement, dataPath: string): void {
|
|
166
|
+
if (!this.adapter || !this.modelWriteBack || this.modelListeners.has(element)) return;
|
|
167
|
+
this.modelListeners.add(element);
|
|
168
|
+
const writeModel = () => this.modelWriteBack?.(dataPath, this.adapter!.getValue(element));
|
|
169
|
+
for (const eventType of ['input', 'change', 'blur']) {
|
|
170
|
+
this.adapter.listen(element, eventType, writeModel, this.modelAbort.signal);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
37
174
|
bindEntry(binding: SomaCompiledBinding, container: HTMLElement): BindingEntry | null {
|
|
38
175
|
if (!this.adapter) {
|
|
39
176
|
return null;
|
|
@@ -54,14 +191,23 @@ export class SomaDomRenderer {
|
|
|
54
191
|
binding.type === 'list' || binding.type === 'obj'
|
|
55
192
|
? this.adapter.cloneTemplate(element) ?? undefined
|
|
56
193
|
: undefined,
|
|
194
|
+
templatesByRole:
|
|
195
|
+
binding.type === 'list'
|
|
196
|
+
? this.collectRoleTemplates(element)
|
|
197
|
+
: undefined,
|
|
57
198
|
childShowConfig: binding.childShowConfig,
|
|
199
|
+
roleBy: binding.roleBy,
|
|
58
200
|
attrName: binding.attrName,
|
|
59
201
|
negate: binding.negate,
|
|
60
202
|
classRules: binding.classRules,
|
|
203
|
+
pipes: binding.pipes,
|
|
61
204
|
};
|
|
62
205
|
|
|
63
206
|
// 编译渲染函数:消除运行时 switch + 类型判断
|
|
64
207
|
entry.compiledRender = this.compileRenderFn(entry);
|
|
208
|
+
if (entry.type === 'model') {
|
|
209
|
+
this.ensureModelListener(entry.element, entry.dataPath);
|
|
210
|
+
}
|
|
65
211
|
|
|
66
212
|
return entry;
|
|
67
213
|
}
|
|
@@ -82,15 +228,24 @@ export class SomaDomRenderer {
|
|
|
82
228
|
const el = entry.element;
|
|
83
229
|
|
|
84
230
|
switch (entry.type) {
|
|
85
|
-
case 'text':
|
|
231
|
+
case 'text': {
|
|
232
|
+
const pipes = entry.pipes;
|
|
233
|
+
if (pipes?.length) {
|
|
234
|
+
return (v) => adapter.setText(el, this.applyPipes(v, pipes, this.rootPipeContext()));
|
|
235
|
+
}
|
|
86
236
|
return (v) => {
|
|
87
237
|
if (v != null && typeof v !== 'object') {
|
|
88
238
|
adapter.setText(el, String(v));
|
|
89
239
|
}
|
|
90
240
|
};
|
|
241
|
+
}
|
|
91
242
|
|
|
92
243
|
case 'attr': {
|
|
93
244
|
const attrName = entry.attrName!;
|
|
245
|
+
const pipes = entry.pipes;
|
|
246
|
+
if (pipes?.length) {
|
|
247
|
+
return (v) => adapter.setAttribute(el, attrName, this.applyPipes(v, pipes, this.rootPipeContext()));
|
|
248
|
+
}
|
|
94
249
|
return (v) => {
|
|
95
250
|
if (v != null && typeof v !== 'object') {
|
|
96
251
|
adapter.setAttribute(el, attrName, String(v));
|
|
@@ -106,7 +261,6 @@ export class SomaDomRenderer {
|
|
|
106
261
|
const modelAdapter = adapter;
|
|
107
262
|
const modelListeners = this.modelListeners;
|
|
108
263
|
const modelWriteBack = this.modelWriteBack;
|
|
109
|
-
const modelAbort = this.modelAbort;
|
|
110
264
|
const dataPath = entry.dataPath;
|
|
111
265
|
const self = this;
|
|
112
266
|
return (v) => {
|
|
@@ -115,13 +269,7 @@ export class SomaDomRenderer {
|
|
|
115
269
|
modelAdapter.setValue(modelEl, strValue);
|
|
116
270
|
}
|
|
117
271
|
if (modelWriteBack && !modelListeners.has(modelEl)) {
|
|
118
|
-
|
|
119
|
-
const writeModel = () => {
|
|
120
|
-
modelWriteBack(dataPath, modelAdapter.getValue(modelEl));
|
|
121
|
-
};
|
|
122
|
-
for (const eventType of ['input', 'change', 'blur']) {
|
|
123
|
-
modelAdapter.listen(modelEl, eventType, writeModel, modelAbort.signal);
|
|
124
|
-
}
|
|
272
|
+
self.ensureModelListener(modelEl, dataPath);
|
|
125
273
|
}
|
|
126
274
|
};
|
|
127
275
|
}
|
|
@@ -189,8 +337,8 @@ export class SomaDomRenderer {
|
|
|
189
337
|
typeof dataArray[0] === 'object' && ('id' in dataArray[0] || 'key' in dataArray[0]);
|
|
190
338
|
|
|
191
339
|
if (!hasKey) {
|
|
192
|
-
// 无 key
|
|
193
|
-
this.
|
|
340
|
+
// 无 key 时保持全量更新(每行的组件实例随之释放:这是泄漏最快的路径)
|
|
341
|
+
this.clearRendered(entry.element);
|
|
194
342
|
for (const itemData of dataArray) {
|
|
195
343
|
this.appendListItem(entry, itemData);
|
|
196
344
|
}
|
|
@@ -220,7 +368,7 @@ export class SomaDomRenderer {
|
|
|
220
368
|
// ── 阶段 2:删除不再存在的旧节点 ──
|
|
221
369
|
for (const [key, { el }] of oldKeyMap) {
|
|
222
370
|
if (!newKeySet.has(key)) {
|
|
223
|
-
|
|
371
|
+
this.removeRendered(el);
|
|
224
372
|
oldKeyMap.delete(key);
|
|
225
373
|
}
|
|
226
374
|
}
|
|
@@ -233,6 +381,13 @@ export class SomaDomRenderer {
|
|
|
233
381
|
for (let i = 0; i < newKeys.length; i++) {
|
|
234
382
|
const old = oldKeyMap.get(newKeys[i]);
|
|
235
383
|
if (old) {
|
|
384
|
+
// 异构列表:行换型(variant 变化)不复用节点,整行重建
|
|
385
|
+
const { variant } = this.pickRowTemplate(entry, dataArray[i]);
|
|
386
|
+
if ((old.el.getAttribute('data-soma-variant') ?? '') !== variant) {
|
|
387
|
+
// 行换型:整行重建,旧行里的组件实例跟着释放
|
|
388
|
+
this.removeRendered(old.el);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
236
391
|
source[i] = old.index;
|
|
237
392
|
newElements[i] = old.el;
|
|
238
393
|
// 更新数据
|
|
@@ -252,12 +407,15 @@ export class SomaDomRenderer {
|
|
|
252
407
|
let nextSibling: Node | null = null;
|
|
253
408
|
for (let i = newKeys.length - 1; i >= 0; i--) {
|
|
254
409
|
if (source[i] === -1) {
|
|
255
|
-
//
|
|
256
|
-
const
|
|
410
|
+
// 新增节点:按行选模板克隆(异构列表 role_by)
|
|
411
|
+
const { template, variant } = this.pickRowTemplate(entry, dataArray[i]);
|
|
412
|
+
if (!template) continue;
|
|
413
|
+
const fragment = template.cloneNode(true) as DocumentFragment;
|
|
257
414
|
const wrapper = fragment.firstElementChild as HTMLElement | null;
|
|
258
415
|
if (!wrapper) continue;
|
|
259
416
|
|
|
260
417
|
wrapper.setAttribute('data-soma-key', newKeys[i]);
|
|
418
|
+
if (variant) wrapper.setAttribute('data-soma-variant', variant);
|
|
261
419
|
this.scopeTracker?.set(wrapper, dataArray[i]);
|
|
262
420
|
if (entry.childShowConfig) {
|
|
263
421
|
this.applyShowConfig(wrapper, dataArray[i], entry.childShowConfig);
|
|
@@ -285,12 +443,15 @@ export class SomaDomRenderer {
|
|
|
285
443
|
}
|
|
286
444
|
|
|
287
445
|
private appendListItem(entry: BindingEntry, itemData: any): void {
|
|
288
|
-
if (!this.adapter
|
|
446
|
+
if (!this.adapter) return;
|
|
447
|
+
const { template, variant } = this.pickRowTemplate(entry, itemData);
|
|
448
|
+
if (!template) return;
|
|
289
449
|
|
|
290
|
-
const fragment =
|
|
450
|
+
const fragment = template.cloneNode(true) as DocumentFragment;
|
|
291
451
|
const wrapper = fragment.firstElementChild as HTMLElement | null;
|
|
292
452
|
if (!wrapper) return;
|
|
293
453
|
|
|
454
|
+
if (variant) wrapper.setAttribute('data-soma-variant', variant);
|
|
294
455
|
this.scopeTracker?.set(wrapper, itemData);
|
|
295
456
|
if (entry.childShowConfig) {
|
|
296
457
|
this.applyShowConfig(wrapper, itemData, entry.childShowConfig);
|
|
@@ -304,7 +465,7 @@ export class SomaDomRenderer {
|
|
|
304
465
|
return;
|
|
305
466
|
}
|
|
306
467
|
|
|
307
|
-
this.
|
|
468
|
+
this.clearRendered(entry.element);
|
|
308
469
|
const fragment = entry.templateCache.cloneNode(true) as DocumentFragment;
|
|
309
470
|
const wrapper = fragment.firstElementChild as HTMLElement | null;
|
|
310
471
|
if (!wrapper) {
|
|
@@ -325,6 +486,14 @@ export class SomaDomRenderer {
|
|
|
325
486
|
showConfig: ShowMapping,
|
|
326
487
|
): void {
|
|
327
488
|
for (const [rawKey, config] of Object.entries(showConfig)) {
|
|
489
|
+
const groupMatch = rawKey.match(/^item:(.+)$/);
|
|
490
|
+
if (groupMatch) {
|
|
491
|
+
const sub = (config as ExtendedShowValue | undefined)?.show;
|
|
492
|
+
if (sub && (root.getAttribute('data-soma-variant') ?? '') === groupMatch[1]) {
|
|
493
|
+
this.applyShowConfig(root, data, sub);
|
|
494
|
+
}
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
328
497
|
if (this.isNestedShowMapping(config)) {
|
|
329
498
|
this.applyNestedShowConfig(root, data, rawKey, config);
|
|
330
499
|
continue;
|
|
@@ -336,12 +505,12 @@ export class SomaDomRenderer {
|
|
|
336
505
|
}
|
|
337
506
|
|
|
338
507
|
const [somaId, attrName] = rawKey.split('@');
|
|
339
|
-
const element =
|
|
508
|
+
const element = this.findScopedAnchor(root, somaId);
|
|
340
509
|
if (!element) {
|
|
341
510
|
continue;
|
|
342
511
|
}
|
|
343
512
|
|
|
344
|
-
const value = this.
|
|
513
|
+
const value = this.resolveRowValue(config, data);
|
|
345
514
|
if (attrName === 'html') {
|
|
346
515
|
this.adapter?.setHtml(element, String(value ?? ''));
|
|
347
516
|
continue;
|
|
@@ -369,10 +538,18 @@ export class SomaDomRenderer {
|
|
|
369
538
|
}
|
|
370
539
|
|
|
371
540
|
const [somaId] = rawKey.split('@');
|
|
372
|
-
const element =
|
|
541
|
+
const element = this.findScopedAnchor(root, somaId);
|
|
373
542
|
if (!element) {
|
|
374
543
|
return;
|
|
375
544
|
}
|
|
545
|
+
// 行内嵌套列表的整块显隐(与行内 when 走同一套解析与可见性写入)
|
|
546
|
+
if (typeof config.when === 'string') {
|
|
547
|
+
const { path, negate } = this.parseConditionalPath(config.when);
|
|
548
|
+
const raw = this.resolveShowValue(path, data);
|
|
549
|
+
const visible = negate ? !raw : Boolean(raw);
|
|
550
|
+
this.adapter.setVisibility(element, visible);
|
|
551
|
+
if (!visible) return;
|
|
552
|
+
}
|
|
376
553
|
|
|
377
554
|
const nestedData = this.resolveShowValue(config.bind.obj, data);
|
|
378
555
|
const role = this.adapter.readRole(element);
|
|
@@ -380,13 +557,19 @@ export class SomaDomRenderer {
|
|
|
380
557
|
if (!templateCache) {
|
|
381
558
|
return;
|
|
382
559
|
}
|
|
560
|
+
// 嵌套列表同样支持 role_by 异构模板(与顶层列表一致);缺省仍走单模板
|
|
561
|
+
const templatesByRole = this.collectRoleTemplates(element);
|
|
562
|
+
const roleBy = config.bind.role_by;
|
|
383
563
|
|
|
384
|
-
|
|
564
|
+
// 行内嵌套列表**每次行重渲都整体重建**,是比顶层列表更快的泄漏路径
|
|
565
|
+
this.clearRendered(element);
|
|
385
566
|
|
|
386
567
|
if (Array.isArray(nestedData) || role === 'item') {
|
|
387
568
|
const items = Array.isArray(nestedData) ? nestedData : [];
|
|
388
569
|
for (const itemData of items) {
|
|
389
|
-
this.
|
|
570
|
+
const picked = this.pickNestedTemplate(templateCache, templatesByRole, roleBy, itemData);
|
|
571
|
+
if (!picked.template) continue;
|
|
572
|
+
this.appendNestedTemplateItem(element, picked.template, itemData, config.show, picked.variant);
|
|
390
573
|
}
|
|
391
574
|
return;
|
|
392
575
|
}
|
|
@@ -396,11 +579,30 @@ export class SomaDomRenderer {
|
|
|
396
579
|
}
|
|
397
580
|
}
|
|
398
581
|
|
|
582
|
+
/** 嵌套列表的按行选模板:role_by 命中 item:<值> 变体,否则回落默认模板 */
|
|
583
|
+
private pickNestedTemplate(
|
|
584
|
+
fallback: DocumentFragment,
|
|
585
|
+
templatesByRole: Record<string, DocumentFragment> | undefined,
|
|
586
|
+
roleBy: string | undefined,
|
|
587
|
+
itemData: any,
|
|
588
|
+
): { template: DocumentFragment | undefined; variant: string } {
|
|
589
|
+
if (!roleBy || !templatesByRole) {
|
|
590
|
+
return { template: fallback, variant: '' };
|
|
591
|
+
}
|
|
592
|
+
const value = String(this.resolveShowValue(roleBy, itemData) ?? '');
|
|
593
|
+
const variantTemplate = templatesByRole[`item:${value}`];
|
|
594
|
+
if (variantTemplate) {
|
|
595
|
+
return { template: variantTemplate, variant: value };
|
|
596
|
+
}
|
|
597
|
+
return { template: templatesByRole['item'] ?? fallback, variant: '' };
|
|
598
|
+
}
|
|
599
|
+
|
|
399
600
|
private appendNestedTemplateItem(
|
|
400
601
|
container: HTMLElement,
|
|
401
602
|
templateCache: DocumentFragment,
|
|
402
603
|
itemData: any,
|
|
403
604
|
showConfig: ShowMapping,
|
|
605
|
+
variant = '',
|
|
404
606
|
): void {
|
|
405
607
|
if (!this.adapter) {
|
|
406
608
|
return;
|
|
@@ -418,6 +620,10 @@ export class SomaDomRenderer {
|
|
|
418
620
|
wrapper.setAttribute('data-soma-key', String(key));
|
|
419
621
|
}
|
|
420
622
|
}
|
|
623
|
+
// 变体名落到 DOM:applyShowConfig 的 item:<变体> 分组绑定据此生效
|
|
624
|
+
if (variant) {
|
|
625
|
+
wrapper.setAttribute('data-soma-variant', variant);
|
|
626
|
+
}
|
|
421
627
|
|
|
422
628
|
this.scopeTracker?.set(wrapper, itemData);
|
|
423
629
|
this.applyShowConfig(wrapper, itemData, showConfig);
|
|
@@ -431,11 +637,15 @@ export class SomaDomRenderer {
|
|
|
431
637
|
config: ExtendedShowValue,
|
|
432
638
|
): void {
|
|
433
639
|
const [somaId, attrName] = rawKey.split('@');
|
|
434
|
-
const element =
|
|
640
|
+
const element = this.findScopedAnchor(root, somaId);
|
|
641
|
+
|
|
642
|
+
if (element && config.props && this.componentHook) {
|
|
643
|
+
this.componentHook(element, config.props, data);
|
|
644
|
+
}
|
|
435
645
|
|
|
436
646
|
if (element) {
|
|
437
647
|
if (config.text) {
|
|
438
|
-
const value = this.
|
|
648
|
+
const value = this.resolveRowValue(config.text, data);
|
|
439
649
|
if (attrName === 'html') {
|
|
440
650
|
this.adapter?.setHtml(element, String(value ?? ''));
|
|
441
651
|
} else if (attrName) {
|
|
@@ -467,6 +677,21 @@ export class SomaDomRenderer {
|
|
|
467
677
|
}
|
|
468
678
|
}
|
|
469
679
|
|
|
680
|
+
/** 行作用域展示值:透明处理管道(`item.price | money`),无管道走原路径 */
|
|
681
|
+
private resolveRowValue(raw: string, itemData: any): any {
|
|
682
|
+
if (!hasPipes(raw)) {
|
|
683
|
+
return this.resolveShowValue(raw, itemData);
|
|
684
|
+
}
|
|
685
|
+
const resolver = this.resolver;
|
|
686
|
+
const parsed = parsePipedValue(raw, (seg) => resolver?.hasVar(seg) ?? false);
|
|
687
|
+
const base = this.resolveShowValue(parsed.basePath, itemData);
|
|
688
|
+
const ctx: SomaPipeContext = {
|
|
689
|
+
read: (path) => this.resolveShowValue(path, itemData),
|
|
690
|
+
locale: () => resolver?.readFromRoot('_locale') as Record<string, unknown> | undefined,
|
|
691
|
+
};
|
|
692
|
+
return this.pipeRegistry.apply(base, parsed.pipes, ctx);
|
|
693
|
+
}
|
|
694
|
+
|
|
470
695
|
private resolveShowValue(valuePath: string, itemData: any): any {
|
|
471
696
|
const segments = valuePath.split('.');
|
|
472
697
|
const firstSeg = segments[0];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// core/client/engine/emit-event.ts
|
|
2
|
+
// 组件契约 emit 的合成事件载体。
|
|
3
|
+
//
|
|
4
|
+
// emit 不经过 DOM 事件系统(不冒泡、不由容器委托捕获),由组件管理器
|
|
5
|
+
// 直接调用事件引擎 execute 触发;事件引擎据此类型区分处理器第二实参:
|
|
6
|
+
// emit 路由传 payload,DOM 路由传 originalEvent(作用域清单树规范 1.1 R2)。
|
|
7
|
+
|
|
8
|
+
export class SomaEmitEvent extends Event {
|
|
9
|
+
readonly emitName: string;
|
|
10
|
+
readonly payload: unknown;
|
|
11
|
+
|
|
12
|
+
constructor(emitName: string, payload?: unknown) {
|
|
13
|
+
super(`soma:emit:${emitName}`, { bubbles: false, cancelable: false });
|
|
14
|
+
this.emitName = emitName;
|
|
15
|
+
this.payload = payload;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isSomaEmitEvent(event: Event): event is SomaEmitEvent {
|
|
20
|
+
return event instanceof SomaEmitEvent;
|
|
21
|
+
}
|
|
@@ -7,6 +7,7 @@ import { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
|
7
7
|
import type { SomaCompiledEvent, SomaRuntimeManifest } from '../../shared/types/manifest.types';
|
|
8
8
|
import type { InteractAction, EventHandlerResult } from '../../shared/types/event.types';
|
|
9
9
|
import type { SomaScopeResolver } from './scope-resolver';
|
|
10
|
+
import { isSomaEmitEvent } from './emit-event';
|
|
10
11
|
|
|
11
12
|
export interface SomaEventMiddlewareContext {
|
|
12
13
|
config: SomaCompiledEvent;
|
|
@@ -94,6 +95,9 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
94
95
|
init(): void {
|
|
95
96
|
const eventTypes = new Set<string>();
|
|
96
97
|
for (const event of this.manifest.events) {
|
|
98
|
+
if (event.emitRoute) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
97
101
|
eventTypes.add(event.domEvent ?? 'click');
|
|
98
102
|
}
|
|
99
103
|
|
|
@@ -102,7 +106,7 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
102
106
|
this.container,
|
|
103
107
|
eventType,
|
|
104
108
|
(event) => {
|
|
105
|
-
const resolved = this.resolveEventBinding(eventType, event.target);
|
|
109
|
+
const resolved = this.resolveEventBinding(eventType, event.target, event);
|
|
106
110
|
if (!resolved) {
|
|
107
111
|
return;
|
|
108
112
|
}
|
|
@@ -120,13 +124,17 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
120
124
|
private resolveEventBinding(
|
|
121
125
|
eventType: string,
|
|
122
126
|
start: EventTarget | null,
|
|
127
|
+
domEvent?: Event,
|
|
123
128
|
): { element: HTMLElement; config: SomaCompiledEvent } | null {
|
|
124
129
|
let el: HTMLElement | null = start instanceof HTMLElement ? start : null;
|
|
125
130
|
while (el && el !== this.container) {
|
|
126
131
|
const somaId = this.adapter.getAnchorId(el);
|
|
127
132
|
if (somaId) {
|
|
128
|
-
const
|
|
129
|
-
|
|
133
|
+
const indexed = this.manifest.eventIndex.get(`${eventType}:${somaId}`);
|
|
134
|
+
// 多按键候选:同一锚点绑了 ↑↓←→/Enter/Esc 时按 event.key 挑那一条
|
|
135
|
+
const config = this.pickKeyVariant(indexed, domEvent);
|
|
136
|
+
// emit 路由不响应冒泡 DOM 事件(如组件内部 input 冒泡的 change)
|
|
137
|
+
if (config && !config.emitRoute) {
|
|
130
138
|
return { element: el, config };
|
|
131
139
|
}
|
|
132
140
|
}
|
|
@@ -135,6 +143,26 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
135
143
|
return null;
|
|
136
144
|
}
|
|
137
145
|
|
|
146
|
+
/**
|
|
147
|
+
* 从候选里挑与本次按键匹配的那条。
|
|
148
|
+
* 没有候选列表(绝大多数绑定)时原样返回,不产生任何额外判断成本。
|
|
149
|
+
* 一条都不匹配时返回 undefined —— 按了无关按键就该什么都不发生。
|
|
150
|
+
*/
|
|
151
|
+
private pickKeyVariant(
|
|
152
|
+
config: SomaCompiledEvent | undefined,
|
|
153
|
+
domEvent?: Event,
|
|
154
|
+
): SomaCompiledEvent | undefined {
|
|
155
|
+
if (!config?.keyVariants) {
|
|
156
|
+
return config;
|
|
157
|
+
}
|
|
158
|
+
if (!(domEvent instanceof KeyboardEvent)) {
|
|
159
|
+
return config.keyVariants.find((variant) => !variant.keyModifier);
|
|
160
|
+
}
|
|
161
|
+
return config.keyVariants.find(
|
|
162
|
+
(variant) => (SOMA_KEY_MODIFIERS[variant.keyModifier ?? ''] ?? variant.keyModifier) === domEvent.key,
|
|
163
|
+
) ?? config.keyVariants.find((variant) => !variant.keyModifier);
|
|
164
|
+
}
|
|
165
|
+
|
|
138
166
|
execute(config: SomaCompiledEvent, element: HTMLElement, originalEvent: Event): Promise<void> {
|
|
139
167
|
return this.scheduler.schedule(
|
|
140
168
|
() => this.executeNow(config, element, originalEvent),
|
|
@@ -197,7 +225,9 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
197
225
|
this.pendingSet.add(config.somaId);
|
|
198
226
|
this.callbacks.onSyncModels?.();
|
|
199
227
|
const fn = this.resolveFunction(config.funcPath!, currentVar);
|
|
200
|
-
|
|
228
|
+
// emit 路由:第二实参为契约 payload;DOM 路由保持 originalEvent
|
|
229
|
+
const handlerArg = isSomaEmitEvent(originalEvent) ? originalEvent.payload : originalEvent;
|
|
230
|
+
result = await fn(currentVar, handlerArg);
|
|
201
231
|
} catch (error) {
|
|
202
232
|
runtime.status = 'error';
|
|
203
233
|
runtime.message = error instanceof Error ? error.message : String(error);
|
|
@@ -97,7 +97,7 @@ export class SomaPropertyWatcher {
|
|
|
97
97
|
try {
|
|
98
98
|
await entry.callback(newValue, oldValue, { path, root: this.root });
|
|
99
99
|
} catch (e) {
|
|
100
|
-
console.error(`[
|
|
100
|
+
console.error(`[soma-core][引擎] callback error at "${path}":`, e);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -73,7 +73,7 @@ export class SomaReactiveProxy {
|
|
|
73
73
|
try {
|
|
74
74
|
if (this.onChange) this.onChange(path, value, undefined);
|
|
75
75
|
} catch (e) {
|
|
76
|
-
console.error('[
|
|
76
|
+
console.error('[soma-core][引擎] batch onChange error:', e);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -117,10 +117,10 @@ export class SomaReactiveProxy {
|
|
|
117
117
|
const self = this;
|
|
118
118
|
return {
|
|
119
119
|
get(target: any, prop: string | symbol, receiver: any): any {
|
|
120
|
-
//
|
|
121
|
-
if (typeof prop === 'symbol') return Reflect.get(target, prop,
|
|
120
|
+
// accessor 必须以 Proxy 为 receiver:否则 setter/getter 内的派生状态会绕过响应式写入。
|
|
121
|
+
if (typeof prop === 'symbol') return Reflect.get(target, prop, receiver);
|
|
122
122
|
|
|
123
|
-
const value = Reflect.get(target, prop,
|
|
123
|
+
const value = Reflect.get(target, prop, receiver);
|
|
124
124
|
|
|
125
125
|
// 引擎注入的基础设施不代理(Storage/DOM API 经 Proxy 会 Illegal invocation)
|
|
126
126
|
if (prop === '_services' || prop === '_config') {
|
|
@@ -156,18 +156,19 @@ export class SomaReactiveProxy {
|
|
|
156
156
|
return value;
|
|
157
157
|
},
|
|
158
158
|
|
|
159
|
-
set(target: any, prop: string | symbol, value: any): boolean {
|
|
159
|
+
set(target: any, prop: string | symbol, value: any, receiver: any): boolean {
|
|
160
160
|
const key = String(prop);
|
|
161
161
|
const path = basePath ? `${basePath}.${key}` : key;
|
|
162
162
|
|
|
163
163
|
// 旧值的子 Proxy 缓存失效
|
|
164
|
-
const oldValue = target
|
|
164
|
+
const oldValue = Reflect.get(target, prop, receiver);
|
|
165
165
|
if (oldValue != null && typeof oldValue === 'object') {
|
|
166
166
|
self.childProxyCache.delete(oldValue);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
//
|
|
170
|
-
target
|
|
169
|
+
// accessor 内的 this 必须保持为 Proxy,派生赋值才能继续经过响应式层。
|
|
170
|
+
const assigned = Reflect.set(target, prop, value, receiver);
|
|
171
|
+
if (!assigned) return false;
|
|
171
172
|
|
|
172
173
|
// 通知变更(带异常防护)
|
|
173
174
|
try {
|
|
@@ -179,7 +180,7 @@ export class SomaReactiveProxy {
|
|
|
179
180
|
self.onChange(path, value, oldValue);
|
|
180
181
|
}
|
|
181
182
|
} catch (e) {
|
|
182
|
-
console.error('[
|
|
183
|
+
console.error('[soma-core][引擎] onChange error:', e);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
return true;
|
|
@@ -199,7 +200,7 @@ export class SomaReactiveProxy {
|
|
|
199
200
|
if (typeof prop === 'string' && ARRAY_MUTATING_METHODS.has(prop) && typeof value === 'function') {
|
|
200
201
|
return (...args: any[]) => {
|
|
201
202
|
console.warn(
|
|
202
|
-
`[
|
|
203
|
+
`[soma-core][引擎] Direct mutation "${prop}" on array at "${arrayPath}" will NOT trigger reactive updates. ` +
|
|
203
204
|
`Use reference replacement instead: this.${arrayPath} = [...this.${arrayPath}]`,
|
|
204
205
|
);
|
|
205
206
|
return value.apply(target, args);
|