soma-core 1.3.1 → 1.3.3
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 +42 -0
- package/app/SomaPageClient.tsx +39 -2
- 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/core/build/compiler/full-manifest-builder.ts +6 -1
- package/core/build/compiler/rollup-plugin-soma.ts +6 -0
- package/core/build/compiler/soma-manifest-webpack-plugin.js +4 -0
- package/core/build/compiler/soma-precompile.js +3507 -2387
- package/core/build/compiler/soma-precompile.ts +31 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +3 -0
- package/core/build/compiler/soma-webpack-loader.js +7 -1
- package/core/build/compiler/vite-plugin-soma.ts +11 -1
- package/core/build/component/package-loader.ts +135 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +139 -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 +262 -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 +271 -0
- package/core/client/component/component-registry.ts +71 -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 +235 -16
- 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 +3 -3
- package/core/client/engine/render-engine.ts +43 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +389 -5
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/host-bridge/empty-host/data/README.md +17 -0
- package/core/client/infra/http/SomaHttpService.ts +5 -0
- 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/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +159 -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/scheduler/SomaScheduler.ts +29 -1
- 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/theme-engine.ts +936 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +190 -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 +10 -0
- package/core/server/index.ts +30 -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 +129 -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 +903 -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 +86 -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 +71 -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 +77 -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 +110 -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 +5388 -888
- package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +1 -0
- package/dist/types/build/compiler/soma-precompile.d.ts +9 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +3 -0
- package/dist/types/build/component/package-loader.d.ts +9 -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/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 +90 -0
- package/dist/types/client/component/component-registry.d.ts +12 -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 +49 -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 +26 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +122 -0
- package/dist/types/client/infra/http/SomaHttpService.d.ts +2 -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/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +51 -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/scheduler/SomaScheduler.d.ts +8 -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/theme-engine.d.ts +49 -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 +36 -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 +5 -0
- package/dist/types/server/index.d.ts +4 -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 +10 -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 +68 -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/global.d.ts +12 -0
- package/next.config.js +76 -1
- package/package.json +32 -11
- package/proxy.ts +62 -0
- 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/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,15 +51,110 @@ 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 {
|
|
@@ -54,10 +181,16 @@ export class SomaDomRenderer {
|
|
|
54
181
|
binding.type === 'list' || binding.type === 'obj'
|
|
55
182
|
? this.adapter.cloneTemplate(element) ?? undefined
|
|
56
183
|
: undefined,
|
|
184
|
+
templatesByRole:
|
|
185
|
+
binding.type === 'list'
|
|
186
|
+
? this.collectRoleTemplates(element)
|
|
187
|
+
: undefined,
|
|
57
188
|
childShowConfig: binding.childShowConfig,
|
|
189
|
+
roleBy: binding.roleBy,
|
|
58
190
|
attrName: binding.attrName,
|
|
59
191
|
negate: binding.negate,
|
|
60
192
|
classRules: binding.classRules,
|
|
193
|
+
pipes: binding.pipes,
|
|
61
194
|
};
|
|
62
195
|
|
|
63
196
|
// 编译渲染函数:消除运行时 switch + 类型判断
|
|
@@ -82,15 +215,24 @@ export class SomaDomRenderer {
|
|
|
82
215
|
const el = entry.element;
|
|
83
216
|
|
|
84
217
|
switch (entry.type) {
|
|
85
|
-
case 'text':
|
|
218
|
+
case 'text': {
|
|
219
|
+
const pipes = entry.pipes;
|
|
220
|
+
if (pipes?.length) {
|
|
221
|
+
return (v) => adapter.setText(el, this.applyPipes(v, pipes, this.rootPipeContext()));
|
|
222
|
+
}
|
|
86
223
|
return (v) => {
|
|
87
224
|
if (v != null && typeof v !== 'object') {
|
|
88
225
|
adapter.setText(el, String(v));
|
|
89
226
|
}
|
|
90
227
|
};
|
|
228
|
+
}
|
|
91
229
|
|
|
92
230
|
case 'attr': {
|
|
93
231
|
const attrName = entry.attrName!;
|
|
232
|
+
const pipes = entry.pipes;
|
|
233
|
+
if (pipes?.length) {
|
|
234
|
+
return (v) => adapter.setAttribute(el, attrName, this.applyPipes(v, pipes, this.rootPipeContext()));
|
|
235
|
+
}
|
|
94
236
|
return (v) => {
|
|
95
237
|
if (v != null && typeof v !== 'object') {
|
|
96
238
|
adapter.setAttribute(el, attrName, String(v));
|
|
@@ -189,8 +331,8 @@ export class SomaDomRenderer {
|
|
|
189
331
|
typeof dataArray[0] === 'object' && ('id' in dataArray[0] || 'key' in dataArray[0]);
|
|
190
332
|
|
|
191
333
|
if (!hasKey) {
|
|
192
|
-
// 无 key
|
|
193
|
-
this.
|
|
334
|
+
// 无 key 时保持全量更新(每行的组件实例随之释放:这是泄漏最快的路径)
|
|
335
|
+
this.clearRendered(entry.element);
|
|
194
336
|
for (const itemData of dataArray) {
|
|
195
337
|
this.appendListItem(entry, itemData);
|
|
196
338
|
}
|
|
@@ -220,7 +362,7 @@ export class SomaDomRenderer {
|
|
|
220
362
|
// ── 阶段 2:删除不再存在的旧节点 ──
|
|
221
363
|
for (const [key, { el }] of oldKeyMap) {
|
|
222
364
|
if (!newKeySet.has(key)) {
|
|
223
|
-
|
|
365
|
+
this.removeRendered(el);
|
|
224
366
|
oldKeyMap.delete(key);
|
|
225
367
|
}
|
|
226
368
|
}
|
|
@@ -233,6 +375,13 @@ export class SomaDomRenderer {
|
|
|
233
375
|
for (let i = 0; i < newKeys.length; i++) {
|
|
234
376
|
const old = oldKeyMap.get(newKeys[i]);
|
|
235
377
|
if (old) {
|
|
378
|
+
// 异构列表:行换型(variant 变化)不复用节点,整行重建
|
|
379
|
+
const { variant } = this.pickRowTemplate(entry, dataArray[i]);
|
|
380
|
+
if ((old.el.getAttribute('data-soma-variant') ?? '') !== variant) {
|
|
381
|
+
// 行换型:整行重建,旧行里的组件实例跟着释放
|
|
382
|
+
this.removeRendered(old.el);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
236
385
|
source[i] = old.index;
|
|
237
386
|
newElements[i] = old.el;
|
|
238
387
|
// 更新数据
|
|
@@ -252,12 +401,15 @@ export class SomaDomRenderer {
|
|
|
252
401
|
let nextSibling: Node | null = null;
|
|
253
402
|
for (let i = newKeys.length - 1; i >= 0; i--) {
|
|
254
403
|
if (source[i] === -1) {
|
|
255
|
-
//
|
|
256
|
-
const
|
|
404
|
+
// 新增节点:按行选模板克隆(异构列表 role_by)
|
|
405
|
+
const { template, variant } = this.pickRowTemplate(entry, dataArray[i]);
|
|
406
|
+
if (!template) continue;
|
|
407
|
+
const fragment = template.cloneNode(true) as DocumentFragment;
|
|
257
408
|
const wrapper = fragment.firstElementChild as HTMLElement | null;
|
|
258
409
|
if (!wrapper) continue;
|
|
259
410
|
|
|
260
411
|
wrapper.setAttribute('data-soma-key', newKeys[i]);
|
|
412
|
+
if (variant) wrapper.setAttribute('data-soma-variant', variant);
|
|
261
413
|
this.scopeTracker?.set(wrapper, dataArray[i]);
|
|
262
414
|
if (entry.childShowConfig) {
|
|
263
415
|
this.applyShowConfig(wrapper, dataArray[i], entry.childShowConfig);
|
|
@@ -285,12 +437,15 @@ export class SomaDomRenderer {
|
|
|
285
437
|
}
|
|
286
438
|
|
|
287
439
|
private appendListItem(entry: BindingEntry, itemData: any): void {
|
|
288
|
-
if (!this.adapter
|
|
440
|
+
if (!this.adapter) return;
|
|
441
|
+
const { template, variant } = this.pickRowTemplate(entry, itemData);
|
|
442
|
+
if (!template) return;
|
|
289
443
|
|
|
290
|
-
const fragment =
|
|
444
|
+
const fragment = template.cloneNode(true) as DocumentFragment;
|
|
291
445
|
const wrapper = fragment.firstElementChild as HTMLElement | null;
|
|
292
446
|
if (!wrapper) return;
|
|
293
447
|
|
|
448
|
+
if (variant) wrapper.setAttribute('data-soma-variant', variant);
|
|
294
449
|
this.scopeTracker?.set(wrapper, itemData);
|
|
295
450
|
if (entry.childShowConfig) {
|
|
296
451
|
this.applyShowConfig(wrapper, itemData, entry.childShowConfig);
|
|
@@ -304,7 +459,7 @@ export class SomaDomRenderer {
|
|
|
304
459
|
return;
|
|
305
460
|
}
|
|
306
461
|
|
|
307
|
-
this.
|
|
462
|
+
this.clearRendered(entry.element);
|
|
308
463
|
const fragment = entry.templateCache.cloneNode(true) as DocumentFragment;
|
|
309
464
|
const wrapper = fragment.firstElementChild as HTMLElement | null;
|
|
310
465
|
if (!wrapper) {
|
|
@@ -325,6 +480,14 @@ export class SomaDomRenderer {
|
|
|
325
480
|
showConfig: ShowMapping,
|
|
326
481
|
): void {
|
|
327
482
|
for (const [rawKey, config] of Object.entries(showConfig)) {
|
|
483
|
+
const groupMatch = rawKey.match(/^item:(.+)$/);
|
|
484
|
+
if (groupMatch) {
|
|
485
|
+
const sub = (config as ExtendedShowValue | undefined)?.show;
|
|
486
|
+
if (sub && (root.getAttribute('data-soma-variant') ?? '') === groupMatch[1]) {
|
|
487
|
+
this.applyShowConfig(root, data, sub);
|
|
488
|
+
}
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
328
491
|
if (this.isNestedShowMapping(config)) {
|
|
329
492
|
this.applyNestedShowConfig(root, data, rawKey, config);
|
|
330
493
|
continue;
|
|
@@ -336,12 +499,12 @@ export class SomaDomRenderer {
|
|
|
336
499
|
}
|
|
337
500
|
|
|
338
501
|
const [somaId, attrName] = rawKey.split('@');
|
|
339
|
-
const element =
|
|
502
|
+
const element = this.findScopedAnchor(root, somaId);
|
|
340
503
|
if (!element) {
|
|
341
504
|
continue;
|
|
342
505
|
}
|
|
343
506
|
|
|
344
|
-
const value = this.
|
|
507
|
+
const value = this.resolveRowValue(config, data);
|
|
345
508
|
if (attrName === 'html') {
|
|
346
509
|
this.adapter?.setHtml(element, String(value ?? ''));
|
|
347
510
|
continue;
|
|
@@ -369,10 +532,18 @@ export class SomaDomRenderer {
|
|
|
369
532
|
}
|
|
370
533
|
|
|
371
534
|
const [somaId] = rawKey.split('@');
|
|
372
|
-
const element =
|
|
535
|
+
const element = this.findScopedAnchor(root, somaId);
|
|
373
536
|
if (!element) {
|
|
374
537
|
return;
|
|
375
538
|
}
|
|
539
|
+
// 行内嵌套列表的整块显隐(与行内 when 走同一套解析与可见性写入)
|
|
540
|
+
if (typeof config.when === 'string') {
|
|
541
|
+
const { path, negate } = this.parseConditionalPath(config.when);
|
|
542
|
+
const raw = this.resolveShowValue(path, data);
|
|
543
|
+
const visible = negate ? !raw : Boolean(raw);
|
|
544
|
+
this.adapter.setVisibility(element, visible);
|
|
545
|
+
if (!visible) return;
|
|
546
|
+
}
|
|
376
547
|
|
|
377
548
|
const nestedData = this.resolveShowValue(config.bind.obj, data);
|
|
378
549
|
const role = this.adapter.readRole(element);
|
|
@@ -380,13 +551,19 @@ export class SomaDomRenderer {
|
|
|
380
551
|
if (!templateCache) {
|
|
381
552
|
return;
|
|
382
553
|
}
|
|
554
|
+
// 嵌套列表同样支持 role_by 异构模板(与顶层列表一致);缺省仍走单模板
|
|
555
|
+
const templatesByRole = this.collectRoleTemplates(element);
|
|
556
|
+
const roleBy = config.bind.role_by;
|
|
383
557
|
|
|
384
|
-
|
|
558
|
+
// 行内嵌套列表**每次行重渲都整体重建**,是比顶层列表更快的泄漏路径
|
|
559
|
+
this.clearRendered(element);
|
|
385
560
|
|
|
386
561
|
if (Array.isArray(nestedData) || role === 'item') {
|
|
387
562
|
const items = Array.isArray(nestedData) ? nestedData : [];
|
|
388
563
|
for (const itemData of items) {
|
|
389
|
-
this.
|
|
564
|
+
const picked = this.pickNestedTemplate(templateCache, templatesByRole, roleBy, itemData);
|
|
565
|
+
if (!picked.template) continue;
|
|
566
|
+
this.appendNestedTemplateItem(element, picked.template, itemData, config.show, picked.variant);
|
|
390
567
|
}
|
|
391
568
|
return;
|
|
392
569
|
}
|
|
@@ -396,11 +573,30 @@ export class SomaDomRenderer {
|
|
|
396
573
|
}
|
|
397
574
|
}
|
|
398
575
|
|
|
576
|
+
/** 嵌套列表的按行选模板:role_by 命中 item:<值> 变体,否则回落默认模板 */
|
|
577
|
+
private pickNestedTemplate(
|
|
578
|
+
fallback: DocumentFragment,
|
|
579
|
+
templatesByRole: Record<string, DocumentFragment> | undefined,
|
|
580
|
+
roleBy: string | undefined,
|
|
581
|
+
itemData: any,
|
|
582
|
+
): { template: DocumentFragment | undefined; variant: string } {
|
|
583
|
+
if (!roleBy || !templatesByRole) {
|
|
584
|
+
return { template: fallback, variant: '' };
|
|
585
|
+
}
|
|
586
|
+
const value = String(this.resolveShowValue(roleBy, itemData) ?? '');
|
|
587
|
+
const variantTemplate = templatesByRole[`item:${value}`];
|
|
588
|
+
if (variantTemplate) {
|
|
589
|
+
return { template: variantTemplate, variant: value };
|
|
590
|
+
}
|
|
591
|
+
return { template: templatesByRole['item'] ?? fallback, variant: '' };
|
|
592
|
+
}
|
|
593
|
+
|
|
399
594
|
private appendNestedTemplateItem(
|
|
400
595
|
container: HTMLElement,
|
|
401
596
|
templateCache: DocumentFragment,
|
|
402
597
|
itemData: any,
|
|
403
598
|
showConfig: ShowMapping,
|
|
599
|
+
variant = '',
|
|
404
600
|
): void {
|
|
405
601
|
if (!this.adapter) {
|
|
406
602
|
return;
|
|
@@ -418,6 +614,10 @@ export class SomaDomRenderer {
|
|
|
418
614
|
wrapper.setAttribute('data-soma-key', String(key));
|
|
419
615
|
}
|
|
420
616
|
}
|
|
617
|
+
// 变体名落到 DOM:applyShowConfig 的 item:<变体> 分组绑定据此生效
|
|
618
|
+
if (variant) {
|
|
619
|
+
wrapper.setAttribute('data-soma-variant', variant);
|
|
620
|
+
}
|
|
421
621
|
|
|
422
622
|
this.scopeTracker?.set(wrapper, itemData);
|
|
423
623
|
this.applyShowConfig(wrapper, itemData, showConfig);
|
|
@@ -431,11 +631,15 @@ export class SomaDomRenderer {
|
|
|
431
631
|
config: ExtendedShowValue,
|
|
432
632
|
): void {
|
|
433
633
|
const [somaId, attrName] = rawKey.split('@');
|
|
434
|
-
const element =
|
|
634
|
+
const element = this.findScopedAnchor(root, somaId);
|
|
635
|
+
|
|
636
|
+
if (element && config.props && this.componentHook) {
|
|
637
|
+
this.componentHook(element, config.props, data);
|
|
638
|
+
}
|
|
435
639
|
|
|
436
640
|
if (element) {
|
|
437
641
|
if (config.text) {
|
|
438
|
-
const value = this.
|
|
642
|
+
const value = this.resolveRowValue(config.text, data);
|
|
439
643
|
if (attrName === 'html') {
|
|
440
644
|
this.adapter?.setHtml(element, String(value ?? ''));
|
|
441
645
|
} else if (attrName) {
|
|
@@ -467,6 +671,21 @@ export class SomaDomRenderer {
|
|
|
467
671
|
}
|
|
468
672
|
}
|
|
469
673
|
|
|
674
|
+
/** 行作用域展示值:透明处理管道(`item.price | money`),无管道走原路径 */
|
|
675
|
+
private resolveRowValue(raw: string, itemData: any): any {
|
|
676
|
+
if (!hasPipes(raw)) {
|
|
677
|
+
return this.resolveShowValue(raw, itemData);
|
|
678
|
+
}
|
|
679
|
+
const resolver = this.resolver;
|
|
680
|
+
const parsed = parsePipedValue(raw, (seg) => resolver?.hasVar(seg) ?? false);
|
|
681
|
+
const base = this.resolveShowValue(parsed.basePath, itemData);
|
|
682
|
+
const ctx: SomaPipeContext = {
|
|
683
|
+
read: (path) => this.resolveShowValue(path, itemData),
|
|
684
|
+
locale: () => resolver?.readFromRoot('_locale') as Record<string, unknown> | undefined,
|
|
685
|
+
};
|
|
686
|
+
return this.pipeRegistry.apply(base, parsed.pipes, ctx);
|
|
687
|
+
}
|
|
688
|
+
|
|
470
689
|
private resolveShowValue(valuePath: string, itemData: any): any {
|
|
471
690
|
const segments = valuePath.split('.');
|
|
472
691
|
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
|
}
|
|
@@ -179,7 +179,7 @@ export class SomaReactiveProxy {
|
|
|
179
179
|
self.onChange(path, value, oldValue);
|
|
180
180
|
}
|
|
181
181
|
} catch (e) {
|
|
182
|
-
console.error('[
|
|
182
|
+
console.error('[soma-core][引擎] onChange error:', e);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
return true;
|
|
@@ -199,7 +199,7 @@ export class SomaReactiveProxy {
|
|
|
199
199
|
if (typeof prop === 'string' && ARRAY_MUTATING_METHODS.has(prop) && typeof value === 'function') {
|
|
200
200
|
return (...args: any[]) => {
|
|
201
201
|
console.warn(
|
|
202
|
-
`[
|
|
202
|
+
`[soma-core][引擎] Direct mutation "${prop}" on array at "${arrayPath}" will NOT trigger reactive updates. ` +
|
|
203
203
|
`Use reference replacement instead: this.${arrayPath} = [...this.${arrayPath}]`,
|
|
204
204
|
);
|
|
205
205
|
return value.apply(target, args);
|
|
@@ -19,10 +19,13 @@ export interface SomaRenderEngineOptions {
|
|
|
19
19
|
diagnostics?: SomaDiagnostics;
|
|
20
20
|
middleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
21
21
|
propertyWatcher?: SomaPropertyWatcher;
|
|
22
|
+
/** 格式化管道注册表(缺省内置管道集) */
|
|
23
|
+
pipeRegistry?: import('../pipes/pipe-registry').SomaPipeRegistry;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export interface SomaRenderMiddlewareContext {
|
|
25
|
-
|
|
27
|
+
/** publish = 事务中途的自愿提交(长任务播进展),其余含义见 render-engine 各方法 */
|
|
28
|
+
phase: 'full-render' | 'patch' | 'commit' | 'publish';
|
|
26
29
|
path?: string;
|
|
27
30
|
changedPaths: string[];
|
|
28
31
|
bindings: BindingEntry[];
|
|
@@ -60,7 +63,7 @@ export class SomaRenderEngine {
|
|
|
60
63
|
this.initProps = { ...(options.manifest.initProps ?? {}) };
|
|
61
64
|
|
|
62
65
|
this.renderer = new SomaDomRenderer();
|
|
63
|
-
this.renderer.init(this.adapter, this.resolver, this.scopeTracker);
|
|
66
|
+
this.renderer.init(this.adapter, this.resolver, this.scopeTracker, options.pipeRegistry);
|
|
64
67
|
this.renderer.setModelWriteBack((path, value) => this.writeToProxy(path, value));
|
|
65
68
|
|
|
66
69
|
this.bindingTable = options.manifest.bindings
|
|
@@ -79,6 +82,25 @@ export class SomaRenderEngine {
|
|
|
79
82
|
return this.scopeTracker;
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
getRegisteredSomaIds(): string[] {
|
|
86
|
+
return [...new Set(this.bindingTable.map((entry) => entry.somaId).filter(Boolean) as string[])];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 装配行内组件钩子(组件管理器调用,见 dom-renderer.SomaRowComponentHook) */
|
|
90
|
+
setComponentHook(hook: import('./dom-renderer').SomaRowComponentHook | null): void {
|
|
91
|
+
this.renderer.setComponentHook(hook);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 装配行内组件**释放**钩子:删行/清空产物前放行,组件管理器据此销毁行内实例。
|
|
96
|
+
* 与 setComponentHook 成对存在——只有挂载没有卸载,就是泄漏。
|
|
97
|
+
*/
|
|
98
|
+
setComponentReleaseHook(
|
|
99
|
+
hook: import('./dom-renderer').SomaRowComponentReleaseHook | null,
|
|
100
|
+
): void {
|
|
101
|
+
this.renderer.setComponentReleaseHook(hook);
|
|
102
|
+
}
|
|
103
|
+
|
|
82
104
|
/** 注册属性监听器(文档 §10.2 watch API) */
|
|
83
105
|
watch(
|
|
84
106
|
path: string,
|
|
@@ -129,6 +151,23 @@ export class SomaRenderEngine {
|
|
|
129
151
|
return this.flushPatches('commit');
|
|
130
152
|
}
|
|
131
153
|
|
|
154
|
+
/**
|
|
155
|
+
* 事务**中途**的自愿提交点:把此刻积累的 patch 立刻上屏,事务不结束。
|
|
156
|
+
*
|
|
157
|
+
* 为什么需要它:一次事件 = 一次原子提交,是这套事务语义刻意的设计(避免中间态闪烁、
|
|
158
|
+
* 出错时 discardPendingPatches 能整体回滚)。但它有个代价——**长任务里的中途进展
|
|
159
|
+
* 播不出去**:实测 AI 生成一次 P50 约 40 秒,期间 Domain 改了多少次 statusText,
|
|
160
|
+
* 界面一次都不会动,连"生成中"都看不到;用户分不清"在想"还是"卡死"。
|
|
161
|
+
*
|
|
162
|
+
* 这里给的是**自愿**的中途提交,而不是把事务拆掉:
|
|
163
|
+
* - 不调用它 → 行为与过去逐字节一致(原子提交 + 失败回滚),存量页面零影响;
|
|
164
|
+
* - 调用它 → 调用方明确知道:**已经上屏的这部分不再享有失败回滚**。
|
|
165
|
+
* 这个取舍必须由业务自己做——它才知道"这一帧值不值得让用户看见"。
|
|
166
|
+
*/
|
|
167
|
+
publishInTransaction(): Promise<void> {
|
|
168
|
+
return this.flushPatches('publish');
|
|
169
|
+
}
|
|
170
|
+
|
|
132
171
|
/** force 全量 render 前丢弃 pending patch(避免 commit + render 双写) */
|
|
133
172
|
discardPendingPatches(): void {
|
|
134
173
|
this.pendingPatches.clear();
|
|
@@ -252,7 +291,7 @@ export class SomaRenderEngine {
|
|
|
252
291
|
return result;
|
|
253
292
|
}
|
|
254
293
|
|
|
255
|
-
private async flushPatches(phase: 'patch' | 'commit' = 'patch'): Promise<void> {
|
|
294
|
+
private async flushPatches(phase: 'patch' | 'commit' | 'publish' = 'patch'): Promise<void> {
|
|
256
295
|
this.flushScheduled = false;
|
|
257
296
|
if (this.destroyed || this.pendingPatches.size === 0) {
|
|
258
297
|
return;
|
|
@@ -307,7 +346,7 @@ export class SomaRenderEngine {
|
|
|
307
346
|
this.renderer.renderEntry(entry, value);
|
|
308
347
|
};
|
|
309
348
|
|
|
310
|
-
if (current.phase === 'patch' || current.phase === 'commit') {
|
|
349
|
+
if (current.phase === 'patch' || current.phase === 'commit' || current.phase === 'publish') {
|
|
311
350
|
// patch/commit 阶段:各 binding 互不依赖,并发调度(同一 microtask 内完成)
|
|
312
351
|
await Promise.all(
|
|
313
352
|
current.bindings.map((entry) => Promise.resolve().then(() => renderBinding(entry))),
|