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
|
@@ -17,8 +17,277 @@ import {
|
|
|
17
17
|
type SomaPipeRegistry,
|
|
18
18
|
} from '../pipes/pipe-registry';
|
|
19
19
|
import type { SomaPipeCall } from '../../shared/types/scope-manifest.types';
|
|
20
|
+
import { SomaRowRange } from './row-range';
|
|
21
|
+
import { SomaRowScope, validateRowKeys, type SomaTypedRowKey } from './row-scope';
|
|
22
|
+
import { SomaComponentTreeError } from '../../shared/component-tree-errors';
|
|
23
|
+
import type { RepeatPlan } from '../../shared/types/component-tree-artifact.types';
|
|
24
|
+
import { resolveCollectionOutlet, publishCollectionState } from '../component/structure-adapter';
|
|
25
|
+
|
|
26
|
+
interface ExplicitListState {
|
|
27
|
+
element: HTMLElement;
|
|
28
|
+
end: Comment;
|
|
29
|
+
rows: Map<SomaTypedRowKey, SomaRowRange>;
|
|
30
|
+
generation: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Component-owned renderers and the page renderer share a physical-page budget.
|
|
34
|
+
// Weak roots/scopes never expose business identities or retain unmounted pages.
|
|
35
|
+
const pageRowBudgets = new WeakMap<HTMLElement, Map<SomaRowScope, HTMLElement>>();
|
|
36
|
+
const rowBudgetMembership = new WeakMap<SomaRowScope, Map<SomaRowScope, HTMLElement>>();
|
|
37
|
+
|
|
38
|
+
function pageRowBudget(element: HTMLElement): Map<SomaRowScope, HTMLElement> {
|
|
39
|
+
let root = element;
|
|
40
|
+
while (root.parentElement && root.parentElement !== root.ownerDocument.body
|
|
41
|
+
&& root.parentElement !== root.ownerDocument.documentElement) root = root.parentElement;
|
|
42
|
+
let budget = pageRowBudgets.get(root);
|
|
43
|
+
if (!budget) { budget = new Map(); pageRowBudgets.set(root, budget); }
|
|
44
|
+
return budget;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 模型值随控件形态而定:checkbox 为布尔,radio、file 与文本类为字符串,number / range 为数值(空为 null),select[multiple] 为字符串数组 */
|
|
48
|
+
export type ModelWriteBack = (path: string, value: unknown) => void;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* model 绑定的控件形态,决定读写哪个属性、听哪些事件:
|
|
52
|
+
* - checkbox:读写 `.checked`,模型值为布尔(按真值勾选,与 when / class 绑定同一口径);
|
|
53
|
+
* - radio:模型值是「这一组当前选中的值」——`.checked = (模型值 === 本控件的 value)`,
|
|
54
|
+
* 按字符串比较,模型值为 null / undefined 时不选;本控件被选中时回写它的 value;
|
|
55
|
+
* - multi-select(select[multiple]):模型值为选中项 value 组成的数组;
|
|
56
|
+
* - file(input[type=file]):读 `.value`(浏览器给出的 "C:\fakepath\文件名",没选文件为空串),与文本类同为字符串;
|
|
57
|
+
* 写只认清空:模型值为空(null / undefined / 空串)时清掉已选文件,非空一律不写——file 的 value 只能由用户
|
|
58
|
+
* 选文件改变,脚本写非空值会抛 InvalidStateError。要拿文件本身走 change 事件读 `event.target.files`(Upload 组件同此);
|
|
59
|
+
* - number(input[type=number|range]):模型值为数值,输入框为空时为 null(与 NumberInput / FormConsole 的数值通道同口径);
|
|
60
|
+
* - text:其余控件(文本类 input / textarea / 单选 select),经适配器 getValue / setValue 读写 `.value`。
|
|
61
|
+
* checkbox / radio / multi-select / file 只听 change:它们的状态只随勾选、选择改变。blur 时再回写没有新信息,
|
|
62
|
+
* 而数组每次读出来都是新引用,会让下游误以为数据变了。
|
|
63
|
+
* 读写时现取形态(`@type` 绑定可能在首帧之后才把 type 写上);听哪些事件在附着监听时按当时的形态定下。
|
|
64
|
+
*/
|
|
65
|
+
type ModelControlKind = 'checkbox' | 'radio' | 'multi-select' | 'file' | 'number' | 'text';
|
|
66
|
+
|
|
67
|
+
function modelControlKind(element: HTMLElement): ModelControlKind {
|
|
68
|
+
const tag = element.localName;
|
|
69
|
+
if (tag === 'input') {
|
|
70
|
+
const type = (element as HTMLInputElement).type;
|
|
71
|
+
if (type === 'checkbox' || type === 'radio' || type === 'file') return type;
|
|
72
|
+
return type === 'number' || type === 'range' ? 'number' : 'text';
|
|
73
|
+
}
|
|
74
|
+
return tag === 'select' && (element as HTMLSelectElement).multiple ? 'multi-select' : 'text';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 控件当前的模型值;未选中的 radio 不代表这一组的值,返回 `{ skip: true }`,不回写 */
|
|
78
|
+
function readModelValue(
|
|
79
|
+
adapter: IContainerAdapter,
|
|
80
|
+
element: HTMLElement,
|
|
81
|
+
): { skip: true } | { skip: false; value: unknown } {
|
|
82
|
+
switch (modelControlKind(element)) {
|
|
83
|
+
case 'checkbox':
|
|
84
|
+
return { skip: false, value: (element as HTMLInputElement).checked };
|
|
85
|
+
case 'radio': {
|
|
86
|
+
const radio = element as HTMLInputElement;
|
|
87
|
+
return radio.checked ? { skip: false, value: radio.value } : { skip: true };
|
|
88
|
+
}
|
|
89
|
+
case 'multi-select':
|
|
90
|
+
return {
|
|
91
|
+
skip: false,
|
|
92
|
+
value: Array.from((element as HTMLSelectElement).options)
|
|
93
|
+
.filter((option) => option.selected)
|
|
94
|
+
.map((option) => option.value),
|
|
95
|
+
};
|
|
96
|
+
case 'number': {
|
|
97
|
+
const raw = adapter.getValue(element);
|
|
98
|
+
const number = Number(raw);
|
|
99
|
+
return { skip: false, value: raw === '' || !Number.isFinite(number) ? null : number };
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
return { skip: false, value: adapter.getValue(element) };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 控件读出来的值与模型现值是否算同一个:多选每次读出来都是新数组(引用必不相同),按元素比。
|
|
108
|
+
* 用于回写前去重。代理的 set 只对基本类型去重(对象与数组一律算变了,见 reactive-proxy 的判据),
|
|
109
|
+
* 多选这种每次都是新数组的值到不了那一层,只能在这里按元素比;不去重的话文本控件的
|
|
110
|
+
* input / change / blur 与处理器执行前的整表同步会把同一个值连发好几遍。
|
|
111
|
+
*/
|
|
112
|
+
function sameModelValue(current: unknown, next: unknown): boolean {
|
|
113
|
+
if (Object.is(current, next)) return true;
|
|
114
|
+
if (Array.isArray(current) && Array.isArray(next)) {
|
|
115
|
+
return current.length === next.length && current.every((item, index) => Object.is(item, next[index]));
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 把模型值写到控件上;目标状态与控件现状一致时不写。
|
|
122
|
+
* 文本类经适配器 setValue 写入:控件正聚焦时保住选区(处理器把值改写后光标不跳到末尾)。
|
|
123
|
+
*/
|
|
124
|
+
function writeModelValue(adapter: IContainerAdapter, element: HTMLElement, value: unknown): void {
|
|
125
|
+
switch (modelControlKind(element)) {
|
|
126
|
+
case 'checkbox': {
|
|
127
|
+
const checkbox = element as HTMLInputElement;
|
|
128
|
+
const next = Boolean(value);
|
|
129
|
+
if (checkbox.checked !== next) checkbox.checked = next;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
case 'radio': {
|
|
133
|
+
const radio = element as HTMLInputElement;
|
|
134
|
+
const next = value != null && String(value) === radio.value;
|
|
135
|
+
if (radio.checked !== next) radio.checked = next;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
case 'multi-select': {
|
|
139
|
+
const wanted = new Set(Array.isArray(value) ? value.map((item) => String(item)) : []);
|
|
140
|
+
for (const option of Array.from((element as HTMLSelectElement).options)) {
|
|
141
|
+
const next = wanted.has(option.value);
|
|
142
|
+
if (option.selected !== next) option.selected = next;
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
case 'file': {
|
|
147
|
+
// 只清空:非空模型值(多半就是上次回写的 fakepath 串)不写,已选的文件保持不动
|
|
148
|
+
if (String(value ?? '') === '' && adapter.getValue(element) !== '') {
|
|
149
|
+
adapter.setValue(element, '');
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
case 'number': {
|
|
154
|
+
const next = value == null || (typeof value === 'number' && !Number.isFinite(value)) ? '' : String(value);
|
|
155
|
+
const current = adapter.getValue(element);
|
|
156
|
+
// 数值相等不写:键入中的 "7.0"、"1e3" 与模型值 7、1000 是同一个数,改写成规范写法会打断输入
|
|
157
|
+
if (current === next || (current !== '' && next !== '' && Number(current) === Number(next))) return;
|
|
158
|
+
adapter.setValue(element, next);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
default: {
|
|
162
|
+
const strValue = String(value ?? '');
|
|
163
|
+
if (adapter.getValue(element) !== strValue) {
|
|
164
|
+
adapter.setValue(element, strValue);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
20
169
|
|
|
21
|
-
|
|
170
|
+
/**
|
|
171
|
+
* 输入法组合闸门:组合进行中控件上的值是中间态(拼音、注音、还没选定的候选),不回写模型;
|
|
172
|
+
* 组合结束后只回写一次最终值。控件上的显示归浏览器管,闸门不碰。
|
|
173
|
+
* 页面 model 绑定(按控件挂,见 SomaDomRenderer.attachModelComposition)与组件 model prop 回写
|
|
174
|
+
* (按组件宿主挂,见 component-manager 的 installModelProps)用的是这同一份判断。
|
|
175
|
+
*
|
|
176
|
+
* 什么算组合中:compositionstart 之后、compositionend 之前,或事件自带 `isComposing === true`。
|
|
177
|
+
* 脚本在组合中改写 value 时 Chromium 静默丢掉组合、不派发 compositionend(实测),所以收到一次不在组合中的
|
|
178
|
+
* input(英文键入、粘贴、脚本派发的 input)就认定组合已经不在了,闸门不会一直关着。
|
|
179
|
+
*
|
|
180
|
+
* 最终值落定的时机各浏览器不同,compositionend 时不读值:
|
|
181
|
+
* - Chromium(147 实测):带最终值的 input(isComposing 为 true)→ compositionend,之后不再派发 input;
|
|
182
|
+
* - WebKit:先派发 compositionend,再把选定的字写进控件并派发 input(isComposing 为 false),
|
|
183
|
+
* compositionend 那一刻控件上还可能是拼音。
|
|
184
|
+
* 所以 compositionend 只排一个宏任务补写。同一轮派发里随后来了不在组合中的 input / change / blur(WebKit 的顺序,
|
|
185
|
+
* 或失焦结束组合),那次回写读到的已是最终值,调用方调 `settled()` 撤掉补写;没有来(Chromium 的顺序)就由补写回写。
|
|
186
|
+
* 两条路只走一条,最终值恰好回写一次。补写还没跑就开始了下一次组合(连续打字)时,compositionstart 先把补写做掉,
|
|
187
|
+
* 每个字提交各回写一次。
|
|
188
|
+
* 事件引擎按容器挂同一份闸门挡 input 声明(见 event-engine 的 attachInputComposition):补发处理器要知道是哪次组合,
|
|
189
|
+
* 所以两个回调带上对应的组合事件(按控件回写的调用方用不到,不接这个参数);失焦结束组合时补发要排在 change / blur 的
|
|
190
|
+
* 处理器之前,所以另有 `flush()` 立即做掉排着的补写。
|
|
191
|
+
*
|
|
192
|
+
* 「组合中」与「补写还排着」是两件事,判断也分成两个:`holds()` 管回写(补写还排着时读控件读到的已是最终值,
|
|
193
|
+
* 该回写就回写),`settling()` 管往控件写(补写还没跑完,模型上停的还是上一个字,这时写下去会把刚上屏的字冲掉,
|
|
194
|
+
* 见 SomaDomRenderer.compileRenderFn 的 model 分支)。
|
|
195
|
+
*/
|
|
196
|
+
export class SomaCompositionGate {
|
|
197
|
+
private composing = false;
|
|
198
|
+
private settleTimer: ReturnType<typeof setTimeout> | undefined;
|
|
199
|
+
private settleEnd: Event | undefined;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param listen 在控件或宿主上挂监听(随 signal 一起撤)
|
|
203
|
+
* @param onSettle 组合结束、最终值落定后的补写(参数为这次组合的 compositionend 事件)
|
|
204
|
+
* @param onStart 组合开始时调用,调用方记下组合前的状态(参数为 compositionstart 事件)
|
|
205
|
+
*/
|
|
206
|
+
constructor(
|
|
207
|
+
listen: (type: string, listener: (event: Event) => void) => void,
|
|
208
|
+
signal: AbortSignal,
|
|
209
|
+
private readonly onSettle: (end: Event) => void,
|
|
210
|
+
onStart?: (start: Event) => void,
|
|
211
|
+
) {
|
|
212
|
+
listen('compositionstart', (event) => {
|
|
213
|
+
this.flushSettle();
|
|
214
|
+
this.composing = true;
|
|
215
|
+
onStart?.(event);
|
|
216
|
+
});
|
|
217
|
+
listen('compositionend', (event) => {
|
|
218
|
+
this.composing = false;
|
|
219
|
+
this.cancelSettle();
|
|
220
|
+
this.settleEnd = event;
|
|
221
|
+
this.settleTimer = setTimeout(() => this.flushSettle(), 0);
|
|
222
|
+
});
|
|
223
|
+
listen('input', (event) => {
|
|
224
|
+
if ((event as InputEvent).isComposing !== true) this.composing = false;
|
|
225
|
+
});
|
|
226
|
+
signal.addEventListener('abort', () => this.cancelSettle(), { once: true });
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** 此刻控件上的值是否为组合中间态:组合进行中,或给出的事件自带 isComposing */
|
|
230
|
+
holds(event?: Event): boolean {
|
|
231
|
+
return this.composing || (event as InputEvent | undefined)?.isComposing === true;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 组合刚结束、最终值还没回写:compositionend 排下的补写还在队列里没执行。
|
|
236
|
+
* 这一小段里控件上已经是用户上屏的字,模型上还是上一个字——比控件旧,不能拿它去写控件。
|
|
237
|
+
* 连续打字时这一小段真的会被踩中:下一次 compositionstart 才把补写做掉,而下一帧渲染可能先到。
|
|
238
|
+
*/
|
|
239
|
+
settling(): boolean {
|
|
240
|
+
return this.settleTimer !== undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** 调用方这次回写读到的已是最终值:撤掉组合结束时排下的补写 */
|
|
244
|
+
settled(): void {
|
|
245
|
+
this.cancelSettle();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** 最终值已落定、补写不必等到下一个宏任务(组合结束后同一轮派发里来了 change / 失焦):有排着的补写就立即做掉 */
|
|
249
|
+
flush(): void {
|
|
250
|
+
this.flushSettle();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private flushSettle(): void {
|
|
254
|
+
const end = this.settleEnd;
|
|
255
|
+
if (this.settleTimer === undefined || end === undefined) return;
|
|
256
|
+
this.cancelSettle();
|
|
257
|
+
this.onSettle(end);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private cancelSettle(): void {
|
|
261
|
+
if (this.settleTimer === undefined) return;
|
|
262
|
+
clearTimeout(this.settleTimer);
|
|
263
|
+
this.settleTimer = undefined;
|
|
264
|
+
this.settleEnd = undefined;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** 文本控件上的组合状态:闸门 + 组合开始时的控件值 + 组合期间没写到控件上的模型值 */
|
|
269
|
+
interface ModelComposition {
|
|
270
|
+
gate: SomaCompositionGate;
|
|
271
|
+
startValue: string;
|
|
272
|
+
deferredView?: { value: unknown };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** 把一段管道调用还原成声明里的写法:`money`、`round(2)`、`tpl(count: page.n)`(位置式实参不带键名) */
|
|
276
|
+
function formatPipeCall(pipe: SomaPipeCall): string {
|
|
277
|
+
const args = Object.entries(pipe.args ?? {});
|
|
278
|
+
if (args.length === 0) return pipe.name;
|
|
279
|
+
const parts = args.map(([key, arg]) => (/^\d+$/.test(key) ? String(arg.value) : `${key}: ${String(arg.value)}`));
|
|
280
|
+
return `${pipe.name}(${parts.join(', ')})`;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 把编译后的绑定还原成 `_ui.yaml` 里那一行的写法,用于管道失败告警的点名与去重。
|
|
285
|
+
* 路径是**编译后的根相对路径**(`page.` 这类 var 前缀在编译期已经解析掉了,运行时拿不回原文),
|
|
286
|
+
* 配上锚点足以定位到具体那一行;行作用域的声明本来就是原文,直接用不经这里。
|
|
287
|
+
*/
|
|
288
|
+
function formatPipedDecl(basePath: string, pipes: SomaPipeCall[]): string {
|
|
289
|
+
return [basePath, ...pipes.map(formatPipeCall)].join(' | ');
|
|
290
|
+
}
|
|
22
291
|
|
|
23
292
|
|
|
24
293
|
/**
|
|
@@ -50,10 +319,23 @@ export class SomaDomRenderer {
|
|
|
50
319
|
private scopeTracker: WeakMap<HTMLElement, any> | null = null;
|
|
51
320
|
private modelWriteBack: ModelWriteBack | null = null;
|
|
52
321
|
private modelListeners = new WeakSet<HTMLElement>();
|
|
322
|
+
private modelCompositions = new WeakMap<HTMLElement, ModelComposition>();
|
|
53
323
|
private modelAbort = new AbortController();
|
|
54
324
|
private componentHook: SomaRowComponentHook | null = null;
|
|
55
325
|
private componentReleaseHook: SomaRowComponentReleaseHook | null = null;
|
|
56
326
|
private pipeRegistry: SomaPipeRegistry = defaultPipeRegistry;
|
|
327
|
+
private explicitLists = new Map<HTMLElement, ExplicitListState>();
|
|
328
|
+
private repeatPlans = new Map<string, RepeatPlan>();
|
|
329
|
+
/** 已报过管道执行失败的位置(键见 warnPipeFailure):同一锚点同一声明只报一次,随渲染器一起销毁 */
|
|
330
|
+
private readonly warnedPipeSites = new Set<string>();
|
|
331
|
+
|
|
332
|
+
setRepeatPlans(plans: readonly RepeatPlan[]): void {
|
|
333
|
+
this.repeatPlans.clear();
|
|
334
|
+
for (const plan of plans) {
|
|
335
|
+
if (this.repeatPlans.has(plan.planId)) this.repeatArtifactError('集合计划 id 重复');
|
|
336
|
+
this.repeatPlans.set(plan.planId, plan);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
57
339
|
|
|
58
340
|
setComponentHook(hook: SomaRowComponentHook | null): void {
|
|
59
341
|
this.componentHook = hook;
|
|
@@ -153,8 +435,39 @@ export class SomaDomRenderer {
|
|
|
153
435
|
};
|
|
154
436
|
}
|
|
155
437
|
|
|
156
|
-
|
|
157
|
-
|
|
438
|
+
/**
|
|
439
|
+
* 页面级 text / @属性 绑定的管道执行。
|
|
440
|
+
*
|
|
441
|
+
* 走 tryApply 而不是 apply:apply 自己吞掉异常、打一条 `管道 "x" 执行失败` 就完了——
|
|
442
|
+
* 那条告警没有锚点也没有声明,一页十几个管道绑定时看不出是哪一个;且它在**每次重算**都打,
|
|
443
|
+
* 首帧更是两条(组件页面装好行钩子后会补一次全量渲染,见 component-manager 的 activate),
|
|
444
|
+
* 一个写错的管道能把控制台刷满。这里把失败接回来,按「锚点 + 声明」点名并去重。
|
|
445
|
+
* 降级值与 apply 完全一致:原值字符串——用户看到的文本一个字不变。
|
|
446
|
+
*/
|
|
447
|
+
private applyPipes(value: unknown, pipes: SomaPipeCall[], ctx: SomaPipeContext, where: string, decl: string): string {
|
|
448
|
+
const result = this.pipeRegistry.tryApply(value, pipes, ctx);
|
|
449
|
+
if (result.ok) return result.value;
|
|
450
|
+
this.warnPipeFailure(where, decl, result.pipeName, result.error);
|
|
451
|
+
return String(value ?? '');
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* 管道执行失败的告警:点名锚点(`data-soma-id`)、绑定声明、出错的管道名与原因,
|
|
456
|
+
* 原始异常作为第二个实参(控制台可展开堆栈)。
|
|
457
|
+
* 同一锚点同一声明只报一次——重算不再重复,行级绑定按列表锚点去重(几百行只报一条)。
|
|
458
|
+
* 去重表随渲染器生存,页面卸载重挂会重新报一遍。
|
|
459
|
+
*/
|
|
460
|
+
private warnPipeFailure(where: string, decl: string, pipeName: string, error: unknown): void {
|
|
461
|
+
const key = `${where}\u0000${decl}`;
|
|
462
|
+
if (this.warnedPipeSites.has(key)) return;
|
|
463
|
+
this.warnedPipeSites.add(key);
|
|
464
|
+
// SomaPipeError 的消息自带 [soma-core][管道] 前缀,拼进本条告警前去掉,免得一行两个前缀
|
|
465
|
+
const reason = error instanceof Error ? error.message.replace(/^\[soma-core\]\[管道\]\s*/, '') : String(error);
|
|
466
|
+
console.warn(
|
|
467
|
+
`[soma-core][管道] ${where} 绑定为 ${JSON.stringify(decl)},管道 "${pipeName}" 执行失败(${reason})。`
|
|
468
|
+
+ '该绑定降级为原值字符串照常上屏;同一锚点同一声明只报这一次',
|
|
469
|
+
error,
|
|
470
|
+
);
|
|
158
471
|
}
|
|
159
472
|
|
|
160
473
|
setModelWriteBack(fn: ModelWriteBack): void {
|
|
@@ -165,12 +478,76 @@ export class SomaDomRenderer {
|
|
|
165
478
|
private ensureModelListener(element: HTMLElement, dataPath: string): void {
|
|
166
479
|
if (!this.adapter || !this.modelWriteBack || this.modelListeners.has(element)) return;
|
|
167
480
|
this.modelListeners.add(element);
|
|
168
|
-
const writeModel = () => this.
|
|
169
|
-
|
|
481
|
+
const writeModel = (event: Event) => this.syncModel(element, dataPath, event);
|
|
482
|
+
const kind = modelControlKind(element);
|
|
483
|
+
// 闸门的监听先于回写监听挂上:同一个事件到达控件时,闸门先更新组合状态,回写再按它判断
|
|
484
|
+
if (kind === 'text' && element.localName !== 'select') {
|
|
485
|
+
this.attachModelComposition(this.adapter, element, dataPath);
|
|
486
|
+
}
|
|
487
|
+
const eventTypes = kind === 'text' || kind === 'number' ? ['input', 'change', 'blur'] : ['change'];
|
|
488
|
+
for (const eventType of eventTypes) {
|
|
170
489
|
this.adapter.listen(element, eventType, writeModel, this.modelAbort.signal);
|
|
171
490
|
}
|
|
172
491
|
}
|
|
173
492
|
|
|
493
|
+
/**
|
|
494
|
+
* 文本输入控件(input / textarea)挂输入法组合闸门(见 SomaCompositionGate)。
|
|
495
|
+
* 组合结束后的补写:控件值与组合开始时不同(上屏了字)才回写;没变(取消、删光)不回写,
|
|
496
|
+
* 若组合期间(含组合结束、补写还排着那一小段)模型被外部改过、当时没写到控件上,这时补写到控件。
|
|
497
|
+
*/
|
|
498
|
+
private attachModelComposition(adapter: IContainerAdapter, element: HTMLElement, dataPath: string): void {
|
|
499
|
+
const signal = this.modelAbort.signal;
|
|
500
|
+
const composition: ModelComposition = {
|
|
501
|
+
startValue: '',
|
|
502
|
+
gate: new SomaCompositionGate(
|
|
503
|
+
(type, listener) => adapter.listen(element, type, listener, signal),
|
|
504
|
+
signal,
|
|
505
|
+
() => {
|
|
506
|
+
const deferred = composition.deferredView;
|
|
507
|
+
composition.deferredView = undefined;
|
|
508
|
+
if (adapter.getValue(element) !== composition.startValue) {
|
|
509
|
+
this.syncModel(element, dataPath);
|
|
510
|
+
} else if (deferred) {
|
|
511
|
+
writeModelValue(adapter, element, deferred.value);
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
() => {
|
|
515
|
+
composition.startValue = adapter.getValue(element);
|
|
516
|
+
composition.deferredView = undefined;
|
|
517
|
+
},
|
|
518
|
+
),
|
|
519
|
+
};
|
|
520
|
+
this.modelCompositions.set(element, composition);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* 把控件当前状态写回模型:checkbox 写布尔、选中的 radio 写它的 value、select[multiple] 写数组,
|
|
525
|
+
* number / range 写数值(空为 null),其余写适配器 getValue 读到的字符串。控件事件触发的回写走这里。
|
|
526
|
+
* 事件处理器执行前的整表同步若绕过这里直接读适配器 getValue,checkbox 会被写成它的 value(缺省 "on"),
|
|
527
|
+
* radio 组会被写成排在最后的那个 radio 的 value。
|
|
528
|
+
* 文本输入控件在输入法组合进行中不回写(event 为触发回写的控件事件,整表同步不传);
|
|
529
|
+
* 组合结束后的这次回写读到的已是最终值,撤掉闸门排下的补写,组合期间没写到控件上的模型值作废(控件值为准)。
|
|
530
|
+
*
|
|
531
|
+
* 与模型现值相同的回写直接丢:代理的 set 只对基本类型去重,多选这类数组值到不了那一层(每次读出来都是新数组)。
|
|
532
|
+
* 不去重的话同一个值会连发好几遍——文本控件的 input / change / blur 各一次,处理器执行前的整表同步再一次
|
|
533
|
+
* (页面同时声明 model 与 input 处理器时,每次按键、每次上屏都收到两次相同的通知就是这么来的)。
|
|
534
|
+
* 丢的只是"值没变"的那次写:控件读出来的值与模型现值不同就照常写,checkbox / radio / 多选 / number / file
|
|
535
|
+
* 的真实变化一次不少(多选每次读出来都是新数组,按元素比,见 sameModelValue)。
|
|
536
|
+
*/
|
|
537
|
+
syncModel(element: HTMLElement, dataPath: string, event?: Event): void {
|
|
538
|
+
if (!this.adapter || !this.modelWriteBack) return;
|
|
539
|
+
const composition = this.modelCompositions.get(element);
|
|
540
|
+
if (composition) {
|
|
541
|
+
if (composition.gate.holds(event)) return;
|
|
542
|
+
composition.gate.settled();
|
|
543
|
+
composition.deferredView = undefined;
|
|
544
|
+
}
|
|
545
|
+
const read = readModelValue(this.adapter, element);
|
|
546
|
+
if (read.skip) return;
|
|
547
|
+
if (this.resolver && sameModelValue(this.resolver.readFromRootCompiled(dataPath), read.value)) return;
|
|
548
|
+
this.modelWriteBack(dataPath, read.value);
|
|
549
|
+
}
|
|
550
|
+
|
|
174
551
|
bindEntry(binding: SomaCompiledBinding, container: HTMLElement): BindingEntry | null {
|
|
175
552
|
if (!this.adapter) {
|
|
176
553
|
return null;
|
|
@@ -197,11 +574,15 @@ export class SomaDomRenderer {
|
|
|
197
574
|
: undefined,
|
|
198
575
|
childShowConfig: binding.childShowConfig,
|
|
199
576
|
roleBy: binding.roleBy,
|
|
577
|
+
keyPath: binding.keyPath,
|
|
578
|
+
itemAlias: binding.itemAlias,
|
|
579
|
+
repeatPlanId: binding.repeatPlanId,
|
|
200
580
|
attrName: binding.attrName,
|
|
201
581
|
negate: binding.negate,
|
|
202
582
|
classRules: binding.classRules,
|
|
203
583
|
pipes: binding.pipes,
|
|
204
584
|
};
|
|
585
|
+
if (binding.repeatPlanId) this.attachRepeatPlan(entry, binding.repeatPlanId);
|
|
205
586
|
|
|
206
587
|
// 编译渲染函数:消除运行时 switch + 类型判断
|
|
207
588
|
entry.compiledRender = this.compileRenderFn(entry);
|
|
@@ -231,7 +612,10 @@ export class SomaDomRenderer {
|
|
|
231
612
|
case 'text': {
|
|
232
613
|
const pipes = entry.pipes;
|
|
233
614
|
if (pipes?.length) {
|
|
234
|
-
|
|
615
|
+
// 告警用的锚点与声明在编译期定下(每帧不再拼串)
|
|
616
|
+
const where = `锚点 "${entry.somaId}"`;
|
|
617
|
+
const decl = formatPipedDecl(entry.dataPath, pipes);
|
|
618
|
+
return (v) => adapter.setText(el, this.applyPipes(v, pipes, this.rootPipeContext(), where, decl));
|
|
235
619
|
}
|
|
236
620
|
return (v) => {
|
|
237
621
|
if (v != null && typeof v !== 'object') {
|
|
@@ -244,7 +628,9 @@ export class SomaDomRenderer {
|
|
|
244
628
|
const attrName = entry.attrName!;
|
|
245
629
|
const pipes = entry.pipes;
|
|
246
630
|
if (pipes?.length) {
|
|
247
|
-
|
|
631
|
+
const where = `锚点 "${entry.somaId}@${attrName}"`;
|
|
632
|
+
const decl = formatPipedDecl(entry.dataPath, pipes);
|
|
633
|
+
return (v) => adapter.setAttribute(el, attrName, this.applyPipes(v, pipes, this.rootPipeContext(), where, decl));
|
|
248
634
|
}
|
|
249
635
|
return (v) => {
|
|
250
636
|
if (v != null && typeof v !== 'object') {
|
|
@@ -264,9 +650,19 @@ export class SomaDomRenderer {
|
|
|
264
650
|
const dataPath = entry.dataPath;
|
|
265
651
|
const self = this;
|
|
266
652
|
return (v) => {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
653
|
+
// 控件上是用户正在输入、还没回写到模型的内容时不改写控件,这一帧的模型值留到组合结束
|
|
654
|
+
// (见 attachModelComposition)。两种情况:
|
|
655
|
+
// - 组合进行中:控件上是组合串,模型还是组合前的值,写进去会冲掉组合;
|
|
656
|
+
// - 组合刚结束、补写还排着(settling):控件上已是刚上屏的字,模型还停在上一个字。
|
|
657
|
+
// 连续打字时这一帧就落在这里——上一个字的回写排进了渲染,渲染的 rAF 又落在下一个字的
|
|
658
|
+
// compositionend 之后、补写之前,照写就把刚上屏的字冲回上一个字(丢字)。
|
|
659
|
+
// 模型被外部真的改了(处理器清空、转大写、定时器改值)不受影响:补写/回写时控件与组合开始时
|
|
660
|
+
// 相同就把这一帧的值写上去,不同则以控件为准,两种都不会停在旧值上。
|
|
661
|
+
const composition = self.modelCompositions.get(modelEl);
|
|
662
|
+
if (composition && (composition.gate.holds() || composition.gate.settling())) {
|
|
663
|
+
composition.deferredView = { value: v };
|
|
664
|
+
} else {
|
|
665
|
+
writeModelValue(modelAdapter, modelEl, v);
|
|
270
666
|
}
|
|
271
667
|
if (modelWriteBack && !modelListeners.has(modelEl)) {
|
|
272
668
|
self.ensureModelListener(modelEl, dataPath);
|
|
@@ -301,6 +697,11 @@ export class SomaDomRenderer {
|
|
|
301
697
|
|
|
302
698
|
case 'list':
|
|
303
699
|
return (v) => {
|
|
700
|
+
if (entry.keyPath) {
|
|
701
|
+
if (!this.collectionReady(entry)) return;
|
|
702
|
+
this.renderExplicitList(entry, v);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
304
705
|
if (Array.isArray(v)) this.renderList(entry, v);
|
|
305
706
|
};
|
|
306
707
|
|
|
@@ -315,16 +716,38 @@ export class SomaDomRenderer {
|
|
|
315
716
|
}
|
|
316
717
|
|
|
317
718
|
destroy(): void {
|
|
719
|
+
for (const state of [...this.explicitLists.values()]) this.disposeExplicitList(state);
|
|
318
720
|
this.modelAbort.abort();
|
|
319
721
|
this.modelAbort = new AbortController();
|
|
320
722
|
this.modelListeners = new WeakSet<HTMLElement>();
|
|
723
|
+
this.modelCompositions = new WeakMap<HTMLElement, ModelComposition>();
|
|
321
724
|
this.modelWriteBack = null;
|
|
725
|
+
// 管道告警去重表随渲染器一起清空:热换/重挂后的同一处失败值得再报一次
|
|
726
|
+
this.warnedPipeSites.clear();
|
|
322
727
|
}
|
|
323
728
|
|
|
324
729
|
renderEntry(entry: BindingEntry, value: any): void {
|
|
325
730
|
if (!this.adapter) return;
|
|
326
731
|
// 所有 entry 在 bindEntry 时已编译 compiledRender,直接调用
|
|
327
|
-
entry.
|
|
732
|
+
if (entry.type === 'list' || entry.type === 'obj') {
|
|
733
|
+
// 结构绑定的错误(CT-* 预算、产物缺失、行内控制器失败)按设计失败即停,且自带行回滚,照常抛出
|
|
734
|
+
entry.compiledRender!(value);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
try {
|
|
738
|
+
entry.compiledRender!(value);
|
|
739
|
+
} catch (error) {
|
|
740
|
+
// 叶子绑定(text / attr / html / model / when / class)互不依赖:一项写 DOM 或读条件出错,
|
|
741
|
+
// 不该让同一帧里排在它后面的绑定全部停在旧值。抛出去也没人接——全量渲染的 Promise 被 void 掉,
|
|
742
|
+
// patch 阶段被调度器的 catch 吞掉——所以在这里记下来,带上锚点与数据路径
|
|
743
|
+
const target = entry.attrName ? `${entry.somaId}@${entry.attrName}` : entry.somaId;
|
|
744
|
+
// class 绑定没有单一数据路径,报它的条件路径
|
|
745
|
+
const path = entry.type === 'class' ? Object.values(entry.classRules ?? {}).join(' / ') : entry.dataPath;
|
|
746
|
+
console.error(
|
|
747
|
+
`[soma-core][引擎] 绑定渲染失败,已跳过这一项(同帧其余绑定照常渲染):${target}(${entry.type},路径 "${path}")`,
|
|
748
|
+
error,
|
|
749
|
+
);
|
|
750
|
+
}
|
|
328
751
|
}
|
|
329
752
|
|
|
330
753
|
private renderList(entry: BindingEntry, dataArray: any[]): void {
|
|
@@ -393,7 +816,7 @@ export class SomaDomRenderer {
|
|
|
393
816
|
// 更新数据
|
|
394
817
|
this.scopeTracker?.set(old.el, dataArray[i]);
|
|
395
818
|
if (entry.childShowConfig) {
|
|
396
|
-
this.applyShowConfig(old.el, dataArray[i], entry.childShowConfig);
|
|
819
|
+
this.applyShowConfig(old.el, dataArray[i], entry.childShowConfig, entry.somaId);
|
|
397
820
|
}
|
|
398
821
|
}
|
|
399
822
|
}
|
|
@@ -418,7 +841,7 @@ export class SomaDomRenderer {
|
|
|
418
841
|
if (variant) wrapper.setAttribute('data-soma-variant', variant);
|
|
419
842
|
this.scopeTracker?.set(wrapper, dataArray[i]);
|
|
420
843
|
if (entry.childShowConfig) {
|
|
421
|
-
this.applyShowConfig(wrapper, dataArray[i], entry.childShowConfig);
|
|
844
|
+
this.applyShowConfig(wrapper, dataArray[i], entry.childShowConfig, entry.somaId);
|
|
422
845
|
}
|
|
423
846
|
|
|
424
847
|
if (nextSibling) {
|
|
@@ -442,6 +865,216 @@ export class SomaDomRenderer {
|
|
|
442
865
|
}
|
|
443
866
|
}
|
|
444
867
|
|
|
868
|
+
/** All explicit-key sources share this range reconciler; legacy guessing stays separate. */
|
|
869
|
+
private renderExplicitList(entry: BindingEntry, value: unknown, parentScope?: SomaRowScope): void {
|
|
870
|
+
const alias = entry.itemAlias!;
|
|
871
|
+
const keys = validateRowKeys(value, entry.keyPath!, alias, entry.repeatPlan?.limits);
|
|
872
|
+
const rows = value as unknown[];
|
|
873
|
+
const depth = this.rowDepth(parentScope) + 1;
|
|
874
|
+
if (depth > (entry.repeatPlan?.limits.maxDepth ?? 4)) this.repeatLimit('集合嵌套超过受信深度预算');
|
|
875
|
+
const nextSubtreeSize = this.validateNestedRows(rows, keys, alias, entry.childShowConfig, parentScope, depth, entry.repeatPlan?.limits);
|
|
876
|
+
if (!entry.templateCache) throw new SomaComponentTreeError({
|
|
877
|
+
code: 'CT-ARTIFACT-INCOMPLETE', phase: 'runtime', sourceId: 'runtime', nodePath: 'repeat',
|
|
878
|
+
fixHint: '显式键集合缺少完整行模板',
|
|
879
|
+
});
|
|
880
|
+
let state = this.explicitLists.get(entry.element);
|
|
881
|
+
const budget = pageRowBudget(entry.element);
|
|
882
|
+
const replacedRoots = [...(state?.rows.values() ?? [])].flatMap(range => [...range.roots]);
|
|
883
|
+
const replacedScopes = new Set([...(state?.rows.values() ?? [])].map(range => range.scope));
|
|
884
|
+
let replaced = 0;
|
|
885
|
+
for (const [scope, owner] of budget) {
|
|
886
|
+
if (replacedScopes.has(scope) || replacedRoots.some(root => root === owner || root.contains(owner))) replaced++;
|
|
887
|
+
}
|
|
888
|
+
if (budget.size - replaced + nextSubtreeSize > (entry.repeatPlan?.limits.maxPageRows ?? 5000)) this.repeatLimit('页面活跃行数超过受信预算');
|
|
889
|
+
const next = new Map<SomaTypedRowKey, SomaRowRange>();
|
|
890
|
+
const preparedRanges = new Set<SomaRowRange>();
|
|
891
|
+
for (let index = 0; index < rows.length; index++) {
|
|
892
|
+
const key = keys[index];
|
|
893
|
+
const picked = this.pickRowTemplate(entry, rows[index]);
|
|
894
|
+
const existing = state?.rows.get(key);
|
|
895
|
+
if (existing && existing.variant === picked.variant) {
|
|
896
|
+
next.set(key, existing);
|
|
897
|
+
} else {
|
|
898
|
+
if (!picked.template) throw new SomaComponentTreeError({
|
|
899
|
+
code: 'CT-ARTIFACT-INCOMPLETE', phase: 'runtime', sourceId: 'runtime', nodePath: 'repeat',
|
|
900
|
+
fixHint: '集合行类型没有可用模板',
|
|
901
|
+
});
|
|
902
|
+
const fragment = picked.template.cloneNode(true) as DocumentFragment;
|
|
903
|
+
if (entry.repeatPlan?.consumerOwner.rowContainer === 'list-item') {
|
|
904
|
+
const row = entry.element.ownerDocument.createElement('li');
|
|
905
|
+
row.append(...Array.from(fragment.childNodes));
|
|
906
|
+
fragment.append(row);
|
|
907
|
+
}
|
|
908
|
+
const scope = new SomaRowScope(alias, key, rows[index], parentScope);
|
|
909
|
+
const range = new SomaRowRange(fragment, scope, picked.variant);
|
|
910
|
+
next.set(key, range);
|
|
911
|
+
preparedRanges.add(range);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
if (!state) {
|
|
915
|
+
const end = entry.element.ownerDocument.createComment('/soma-repeat');
|
|
916
|
+
entry.element.appendChild(end);
|
|
917
|
+
state = { element: entry.element, end, rows: new Map(), generation: 0 };
|
|
918
|
+
this.explicitLists.set(entry.element, state);
|
|
919
|
+
}
|
|
920
|
+
// No DOM mutation happened before all keys, templates and row budgets passed.
|
|
921
|
+
let before: Node = state.end;
|
|
922
|
+
for (const range of [...next.values()].reverse()) {
|
|
923
|
+
range.moveBefore(entry.element, before);
|
|
924
|
+
before = range.start;
|
|
925
|
+
}
|
|
926
|
+
for (const [key, range] of state.rows) {
|
|
927
|
+
if (next.get(key) !== range) this.releaseExplicitRange(range);
|
|
928
|
+
}
|
|
929
|
+
state.rows = next;
|
|
930
|
+
state.generation++;
|
|
931
|
+
let applying: SomaRowRange | undefined;
|
|
932
|
+
try { rows.forEach((data, index) => {
|
|
933
|
+
const range = next.get(keys[index])!;
|
|
934
|
+
applying = range;
|
|
935
|
+
budget.set(range.scope, entry.element);
|
|
936
|
+
rowBudgetMembership.set(range.scope, budget);
|
|
937
|
+
range.scope.update(data);
|
|
938
|
+
for (const root of range.roots) {
|
|
939
|
+
this.scopeTracker?.set(root, range.scope);
|
|
940
|
+
if (range.variant) root.setAttribute('data-soma-variant', range.variant);
|
|
941
|
+
if (entry.childShowConfig) this.applyShowConfig(root, range.scope, entry.childShowConfig, entry.somaId);
|
|
942
|
+
this.activateDefaultRowComponents(root, range.scope, entry.childShowConfig);
|
|
943
|
+
}
|
|
944
|
+
}); } catch (error) {
|
|
945
|
+
// A controller may fail after DOM commit. Release every uncommitted/new
|
|
946
|
+
// row and the affected reused row through the same lifecycle hooks.
|
|
947
|
+
if (applying) preparedRanges.add(applying);
|
|
948
|
+
for (const [key, range] of next) {
|
|
949
|
+
if (!preparedRanges.has(range)) continue;
|
|
950
|
+
this.releaseExplicitRange(range);
|
|
951
|
+
next.delete(key);
|
|
952
|
+
}
|
|
953
|
+
if (entry.collectionOwner) publishCollectionState(entry.collectionOwner, entry.element, 'error', next.size, state.generation);
|
|
954
|
+
throw error;
|
|
955
|
+
}
|
|
956
|
+
if (entry.collectionOwner) publishCollectionState(entry.collectionOwner, entry.element, 'ready', next.size, state.generation);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
private attachRepeatPlan(entry: BindingEntry, planId: string): void {
|
|
960
|
+
const plan = this.repeatPlans.get(planId);
|
|
961
|
+
if (!plan) this.repeatArtifactError('集合绑定引用未知计划');
|
|
962
|
+
if (entry.itemAlias !== plan.itemAlias
|
|
963
|
+
|| this.resolver?.resolvePath(plan.sourcePath) !== this.resolver?.resolvePath(entry.dataPath)) {
|
|
964
|
+
this.repeatArtifactError('集合绑定与计划的数据源或行变量不一致');
|
|
965
|
+
}
|
|
966
|
+
const host = entry.element;
|
|
967
|
+
const symbol = host.getAttribute('data-soma-id') ?? host.getAttribute('data-soma-scoped-id');
|
|
968
|
+
if (symbol !== plan.consumerOwner.instanceSymbol) this.repeatArtifactError('集合消费宿主与计划符号不一致');
|
|
969
|
+
const outlet = resolveCollectionOutlet(host, plan);
|
|
970
|
+
const templates = [...outlet.querySelectorAll<HTMLTemplateElement>('template[data-soma-role="item"]')]
|
|
971
|
+
.filter(template => template.getAttribute('data-soma-repeat-template') === plan.rowTemplateId);
|
|
972
|
+
if (templates.length !== 1) this.repeatArtifactError('集合计划没有唯一的完整行模板');
|
|
973
|
+
entry.collectionOwner = host;
|
|
974
|
+
entry.element = outlet;
|
|
975
|
+
entry.templateCache = templates[0].content;
|
|
976
|
+
entry.templatesByRole = undefined;
|
|
977
|
+
entry.repeatPlan = plan;
|
|
978
|
+
entry.keyPath = plan.keyPath;
|
|
979
|
+
entry.type = 'list';
|
|
980
|
+
if (plan.statusPlan.kind === 'async') {
|
|
981
|
+
entry.watchPaths = [...new Set([...(entry.watchPaths ?? []), this.resolver!.resolvePath(plan.statusPlan.statePath)])];
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
private collectionReady(entry: BindingEntry, scope?: SomaRowScope): boolean {
|
|
986
|
+
const plan = entry.repeatPlan;
|
|
987
|
+
if (!plan || plan.statusPlan.kind === 'sync') return true;
|
|
988
|
+
const phase = scope ? this.resolveShowValue(plan.statusPlan.statePath, scope)
|
|
989
|
+
: this.resolver?.readFromRoot(this.resolver.resolvePath(plan.statusPlan.statePath));
|
|
990
|
+
if (!['pending', 'ready', 'error'].includes(phase)) this.repeatArtifactError('异步集合状态必须是 pending/ready/error');
|
|
991
|
+
if (phase === 'ready') return true;
|
|
992
|
+
const state = this.explicitLists.get(entry.element);
|
|
993
|
+
if (entry.collectionOwner) publishCollectionState(entry.collectionOwner, entry.element, phase, state?.rows.size ?? 0, state?.generation ?? 0);
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
private repeatArtifactError(fixHint: string): never {
|
|
998
|
+
throw new SomaComponentTreeError({ code: 'CT-ARTIFACT-INCOMPLETE', phase: 'runtime', sourceId: 'runtime', nodePath: 'repeat', fixHint });
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
private activateDefaultRowComponents(root: HTMLElement, scope: SomaRowScope, show?: ShowMapping): void {
|
|
1002
|
+
if (!this.componentHook || !this.adapter) return;
|
|
1003
|
+
const hosts = [root, ...Array.from(root.querySelectorAll<HTMLElement>('[data-soma-component]'))];
|
|
1004
|
+
for (const host of hosts) {
|
|
1005
|
+
if (!host.hasAttribute('data-soma-component')) continue;
|
|
1006
|
+
let foreignRow = false;
|
|
1007
|
+
for (let current: HTMLElement | null = host; current; current = current.parentElement) {
|
|
1008
|
+
const owner = this.scopeTracker?.get(current);
|
|
1009
|
+
if (owner instanceof SomaRowScope) { foreignRow = owner !== scope; break; }
|
|
1010
|
+
if (current === root) break;
|
|
1011
|
+
}
|
|
1012
|
+
if (foreignRow) continue;
|
|
1013
|
+
const id = this.adapter.getAnchorId(host);
|
|
1014
|
+
if (!id) continue;
|
|
1015
|
+
const config = show?.[id];
|
|
1016
|
+
if (config && typeof config === 'object' && config.props) continue;
|
|
1017
|
+
this.componentHook(host, {}, scope);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
private validateNestedRows(
|
|
1022
|
+
rows: unknown[], keys: SomaTypedRowKey[], alias: string, show: ShowMapping | undefined,
|
|
1023
|
+
parent: SomaRowScope | undefined, depth: number, limits?: RepeatPlan['limits'],
|
|
1024
|
+
): number {
|
|
1025
|
+
let count = rows.length;
|
|
1026
|
+
const visit = (mapping: ShowMapping, scope: SomaRowScope): void => {
|
|
1027
|
+
for (const config of Object.values(mapping)) {
|
|
1028
|
+
if (!config || typeof config !== 'object') continue;
|
|
1029
|
+
if (this.isNestedShowMapping(config) && (config.bind.key || config.bind.repeatPlanId)) {
|
|
1030
|
+
const plan = config.bind.repeatPlanId ? this.repeatPlans.get(config.bind.repeatPlanId) : undefined;
|
|
1031
|
+
if (config.bind.repeatPlanId && !plan) this.repeatArtifactError('嵌套集合引用未知计划');
|
|
1032
|
+
if (plan?.statusPlan.kind === 'async') {
|
|
1033
|
+
const phase = this.resolveShowValue(plan.statusPlan.statePath, scope);
|
|
1034
|
+
if (!['pending', 'ready', 'error'].includes(phase)) this.repeatArtifactError('异步集合状态无效');
|
|
1035
|
+
if (phase !== 'ready') continue;
|
|
1036
|
+
}
|
|
1037
|
+
if (depth >= (plan?.limits.maxDepth ?? limits?.maxDepth ?? 4)) this.repeatLimit('集合嵌套超过受信深度预算');
|
|
1038
|
+
const values = this.resolveShowValue(config.bind.obj, scope);
|
|
1039
|
+
const childKeys = validateRowKeys(values, plan?.keyPath ?? config.bind.key!, config.bind.var, plan?.limits);
|
|
1040
|
+
count += this.validateNestedRows(values, childKeys, config.bind.var, config.show, scope, depth + 1, plan?.limits ?? limits);
|
|
1041
|
+
} else if (!this.isNestedShowMapping(config) && config.show) visit(config.show, scope);
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
if (show) rows.forEach((row, index) => visit(show, new SomaRowScope(alias, keys[index], row, parent)));
|
|
1045
|
+
if (count > (limits?.maxPageRows ?? 5000)) this.repeatLimit('页面活跃行数超过受信预算');
|
|
1046
|
+
return count;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
private rowDepth(scope?: SomaRowScope): number {
|
|
1050
|
+
let depth = 0;
|
|
1051
|
+
for (let current = scope; current; current = current.parent) depth++;
|
|
1052
|
+
return depth;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
private repeatLimit(fixHint: string): never {
|
|
1056
|
+
throw new SomaComponentTreeError({ code: 'CT-LIMIT', phase: 'runtime', sourceId: 'runtime', nodePath: 'repeat', fixHint });
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
private releaseExplicitRange(range: SomaRowRange): void {
|
|
1060
|
+
rowBudgetMembership.get(range.scope)?.delete(range.scope);
|
|
1061
|
+
rowBudgetMembership.delete(range.scope);
|
|
1062
|
+
range.release(root => {
|
|
1063
|
+
for (const state of [...this.explicitLists.values()]) {
|
|
1064
|
+
if (root === state.element || root.contains(state.element)) this.disposeExplicitList(state);
|
|
1065
|
+
}
|
|
1066
|
+
this.componentReleaseHook?.(root);
|
|
1067
|
+
this.scopeTracker?.delete(root);
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
private disposeExplicitList(state: ExplicitListState): void {
|
|
1072
|
+
if (!this.explicitLists.delete(state.element)) return;
|
|
1073
|
+
for (const range of state.rows.values()) this.releaseExplicitRange(range);
|
|
1074
|
+
state.rows.clear();
|
|
1075
|
+
state.end.remove();
|
|
1076
|
+
}
|
|
1077
|
+
|
|
445
1078
|
private appendListItem(entry: BindingEntry, itemData: any): void {
|
|
446
1079
|
if (!this.adapter) return;
|
|
447
1080
|
const { template, variant } = this.pickRowTemplate(entry, itemData);
|
|
@@ -454,7 +1087,7 @@ export class SomaDomRenderer {
|
|
|
454
1087
|
if (variant) wrapper.setAttribute('data-soma-variant', variant);
|
|
455
1088
|
this.scopeTracker?.set(wrapper, itemData);
|
|
456
1089
|
if (entry.childShowConfig) {
|
|
457
|
-
this.applyShowConfig(wrapper, itemData, entry.childShowConfig);
|
|
1090
|
+
this.applyShowConfig(wrapper, itemData, entry.childShowConfig, entry.somaId);
|
|
458
1091
|
}
|
|
459
1092
|
|
|
460
1093
|
this.adapter.appendFragment(entry.element, fragment);
|
|
@@ -474,7 +1107,7 @@ export class SomaDomRenderer {
|
|
|
474
1107
|
|
|
475
1108
|
this.scopeTracker?.set(wrapper, data);
|
|
476
1109
|
if (entry.childShowConfig) {
|
|
477
|
-
this.applyShowConfig(wrapper, data, entry.childShowConfig);
|
|
1110
|
+
this.applyShowConfig(wrapper, data, entry.childShowConfig, entry.somaId);
|
|
478
1111
|
}
|
|
479
1112
|
|
|
480
1113
|
this.adapter.appendFragment(entry.element, fragment);
|
|
@@ -484,13 +1117,14 @@ export class SomaDomRenderer {
|
|
|
484
1117
|
root: HTMLElement,
|
|
485
1118
|
data: any,
|
|
486
1119
|
showConfig: ShowMapping,
|
|
1120
|
+
scopeAnchor: string | undefined,
|
|
487
1121
|
): void {
|
|
488
1122
|
for (const [rawKey, config] of Object.entries(showConfig)) {
|
|
489
1123
|
const groupMatch = rawKey.match(/^item:(.+)$/);
|
|
490
1124
|
if (groupMatch) {
|
|
491
1125
|
const sub = (config as ExtendedShowValue | undefined)?.show;
|
|
492
1126
|
if (sub && (root.getAttribute('data-soma-variant') ?? '') === groupMatch[1]) {
|
|
493
|
-
this.applyShowConfig(root, data, sub);
|
|
1127
|
+
this.applyShowConfig(root, data, sub, scopeAnchor);
|
|
494
1128
|
}
|
|
495
1129
|
continue;
|
|
496
1130
|
}
|
|
@@ -500,7 +1134,7 @@ export class SomaDomRenderer {
|
|
|
500
1134
|
}
|
|
501
1135
|
|
|
502
1136
|
if (this.isExtendedShowValue(config)) {
|
|
503
|
-
this.applyExtendedShowConfig(root, data, rawKey, config);
|
|
1137
|
+
this.applyExtendedShowConfig(root, data, rawKey, config, scopeAnchor);
|
|
504
1138
|
continue;
|
|
505
1139
|
}
|
|
506
1140
|
|
|
@@ -510,7 +1144,7 @@ export class SomaDomRenderer {
|
|
|
510
1144
|
continue;
|
|
511
1145
|
}
|
|
512
1146
|
|
|
513
|
-
const value = this.resolveRowValue(config, data);
|
|
1147
|
+
const value = this.resolveRowValue(config, data, scopeAnchor, rawKey);
|
|
514
1148
|
if (attrName === 'html') {
|
|
515
1149
|
this.adapter?.setHtml(element, String(value ?? ''));
|
|
516
1150
|
continue;
|
|
@@ -542,6 +1176,7 @@ export class SomaDomRenderer {
|
|
|
542
1176
|
if (!element) {
|
|
543
1177
|
return;
|
|
544
1178
|
}
|
|
1179
|
+
if (this.componentHook && element.hasAttribute('data-soma-component')) this.componentHook(element, config.props ?? {}, data);
|
|
545
1180
|
// 行内嵌套列表的整块显隐(与行内 when 走同一套解析与可见性写入)
|
|
546
1181
|
if (typeof config.when === 'string') {
|
|
547
1182
|
const { path, negate } = this.parseConditionalPath(config.when);
|
|
@@ -554,6 +1189,20 @@ export class SomaDomRenderer {
|
|
|
554
1189
|
const nestedData = this.resolveShowValue(config.bind.obj, data);
|
|
555
1190
|
const role = this.adapter.readRole(element);
|
|
556
1191
|
const templateCache = this.adapter.cloneTemplate(element);
|
|
1192
|
+
if (config.bind.repeatPlanId) {
|
|
1193
|
+
// RuntimeBuilder performs the first page render before Manager.activate
|
|
1194
|
+
// installs row hooks. Nested consumer templates become available on the
|
|
1195
|
+
// activation render; never infer their outlet from the authored source.
|
|
1196
|
+
if (!this.componentHook && !element.hasAttribute('data-soma-component-ready')) return;
|
|
1197
|
+
const entry: BindingEntry = {
|
|
1198
|
+
element, somaId, type: 'list', dataPath: config.bind.obj,
|
|
1199
|
+
itemAlias: config.bind.var, childShowConfig: config.show,
|
|
1200
|
+
};
|
|
1201
|
+
this.attachRepeatPlan(entry, config.bind.repeatPlanId);
|
|
1202
|
+
const parentScope = data instanceof SomaRowScope ? data : undefined;
|
|
1203
|
+
if (this.collectionReady(entry, parentScope)) this.renderExplicitList(entry, nestedData, parentScope);
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
557
1206
|
if (!templateCache) {
|
|
558
1207
|
return;
|
|
559
1208
|
}
|
|
@@ -561,6 +1210,15 @@ export class SomaDomRenderer {
|
|
|
561
1210
|
const templatesByRole = this.collectRoleTemplates(element);
|
|
562
1211
|
const roleBy = config.bind.role_by;
|
|
563
1212
|
|
|
1213
|
+
if (config.bind.key) {
|
|
1214
|
+
this.renderExplicitList({
|
|
1215
|
+
element, somaId, type: 'list', dataPath: config.bind.obj, templateCache,
|
|
1216
|
+
templatesByRole, roleBy, childShowConfig: config.show,
|
|
1217
|
+
keyPath: config.bind.key, itemAlias: config.bind.var,
|
|
1218
|
+
}, nestedData, data instanceof SomaRowScope ? data : undefined);
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
564
1222
|
// 行内嵌套列表**每次行重渲都整体重建**,是比顶层列表更快的泄漏路径
|
|
565
1223
|
this.clearRendered(element);
|
|
566
1224
|
|
|
@@ -569,13 +1227,13 @@ export class SomaDomRenderer {
|
|
|
569
1227
|
for (const itemData of items) {
|
|
570
1228
|
const picked = this.pickNestedTemplate(templateCache, templatesByRole, roleBy, itemData);
|
|
571
1229
|
if (!picked.template) continue;
|
|
572
|
-
this.appendNestedTemplateItem(element, picked.template, itemData, config.show, picked.variant);
|
|
1230
|
+
this.appendNestedTemplateItem(element, picked.template, itemData, config.show, somaId, picked.variant);
|
|
573
1231
|
}
|
|
574
1232
|
return;
|
|
575
1233
|
}
|
|
576
1234
|
|
|
577
1235
|
if (nestedData && typeof nestedData === 'object') {
|
|
578
|
-
this.appendNestedTemplateItem(element, templateCache, nestedData, config.show);
|
|
1236
|
+
this.appendNestedTemplateItem(element, templateCache, nestedData, config.show, somaId);
|
|
579
1237
|
}
|
|
580
1238
|
}
|
|
581
1239
|
|
|
@@ -602,6 +1260,7 @@ export class SomaDomRenderer {
|
|
|
602
1260
|
templateCache: DocumentFragment,
|
|
603
1261
|
itemData: any,
|
|
604
1262
|
showConfig: ShowMapping,
|
|
1263
|
+
scopeAnchor: string | undefined,
|
|
605
1264
|
variant = '',
|
|
606
1265
|
): void {
|
|
607
1266
|
if (!this.adapter) {
|
|
@@ -626,15 +1285,24 @@ export class SomaDomRenderer {
|
|
|
626
1285
|
}
|
|
627
1286
|
|
|
628
1287
|
this.scopeTracker?.set(wrapper, itemData);
|
|
629
|
-
this.applyShowConfig(wrapper, itemData, showConfig);
|
|
1288
|
+
this.applyShowConfig(wrapper, itemData, showConfig, scopeAnchor);
|
|
630
1289
|
this.adapter.appendFragment(container, fragment);
|
|
631
1290
|
}
|
|
632
1291
|
|
|
1292
|
+
/**
|
|
1293
|
+
* 行 / 对象作用域的扩展绑定:props、text、when、class 与嵌套 show。
|
|
1294
|
+
*
|
|
1295
|
+
* 这里没有 model 分支,是引擎的裁决而不是遗漏:行数据是数组元素、不经响应式代理,
|
|
1296
|
+
* 页面路径形态又缺同屏刷新与整表同步(syncModels 只认编译出来的绑定表)。
|
|
1297
|
+
* 写了 model 的声明进不到这一步——编译期就被拒收(manifest-compiler 的 scopedModelRefusal
|
|
1298
|
+
* 讲清了两种写法各自的原因与改法),不再是挂载期一条告警加一个失效的控件。
|
|
1299
|
+
*/
|
|
633
1300
|
private applyExtendedShowConfig(
|
|
634
1301
|
root: HTMLElement,
|
|
635
1302
|
data: any,
|
|
636
1303
|
rawKey: string,
|
|
637
1304
|
config: ExtendedShowValue,
|
|
1305
|
+
scopeAnchor: string | undefined,
|
|
638
1306
|
): void {
|
|
639
1307
|
const [somaId, attrName] = rawKey.split('@');
|
|
640
1308
|
const element = this.findScopedAnchor(root, somaId);
|
|
@@ -645,7 +1313,7 @@ export class SomaDomRenderer {
|
|
|
645
1313
|
|
|
646
1314
|
if (element) {
|
|
647
1315
|
if (config.text) {
|
|
648
|
-
const value = this.resolveRowValue(config.text, data);
|
|
1316
|
+
const value = this.resolveRowValue(config.text, data, scopeAnchor, rawKey);
|
|
649
1317
|
if (attrName === 'html') {
|
|
650
1318
|
this.adapter?.setHtml(element, String(value ?? ''));
|
|
651
1319
|
} else if (attrName) {
|
|
@@ -673,12 +1341,19 @@ export class SomaDomRenderer {
|
|
|
673
1341
|
|
|
674
1342
|
if (config.show) {
|
|
675
1343
|
const showRoot = element ?? root;
|
|
676
|
-
this.applyShowConfig(showRoot, data, config.show);
|
|
1344
|
+
this.applyShowConfig(showRoot, data, config.show, scopeAnchor);
|
|
677
1345
|
}
|
|
678
1346
|
}
|
|
679
1347
|
|
|
680
|
-
/**
|
|
681
|
-
|
|
1348
|
+
/**
|
|
1349
|
+
* 行作用域展示值:透明处理管道(`item.price | money`),无管道走原路径。
|
|
1350
|
+
*
|
|
1351
|
+
* 与页面绑定同样走 tryApply:管道抛错时点名「列表锚点 + 行内锚点 + 声明」并按这个键去重——
|
|
1352
|
+
* 一个写错的管道在五百行的表里只报一条,不是五百条(还要乘上每次重算)。
|
|
1353
|
+
* 声明这里拿得到原文(行内绑定是解释执行的,不经编译期的路径解析)。
|
|
1354
|
+
* 降级值与 apply 一致:原值字符串,上屏文本不变。
|
|
1355
|
+
*/
|
|
1356
|
+
private resolveRowValue(raw: string, itemData: any, scopeAnchor: string | undefined, anchorKey: string): any {
|
|
682
1357
|
if (!hasPipes(raw)) {
|
|
683
1358
|
return this.resolveShowValue(raw, itemData);
|
|
684
1359
|
}
|
|
@@ -689,10 +1364,21 @@ export class SomaDomRenderer {
|
|
|
689
1364
|
read: (path) => this.resolveShowValue(path, itemData),
|
|
690
1365
|
locale: () => resolver?.readFromRoot('_locale') as Record<string, unknown> | undefined,
|
|
691
1366
|
};
|
|
692
|
-
|
|
1367
|
+
const result = this.pipeRegistry.tryApply(base, parsed.pipes, ctx);
|
|
1368
|
+
if (result.ok) return result.value;
|
|
1369
|
+
this.warnPipeFailure(
|
|
1370
|
+
scopeAnchor ? `锚点 "${scopeAnchor}" 行内的 "${anchorKey}"` : `行内锚点 "${anchorKey}"`,
|
|
1371
|
+
raw,
|
|
1372
|
+
result.pipeName,
|
|
1373
|
+
result.error,
|
|
1374
|
+
);
|
|
1375
|
+
return String(base ?? '');
|
|
693
1376
|
}
|
|
694
1377
|
|
|
695
1378
|
private resolveShowValue(valuePath: string, itemData: any): any {
|
|
1379
|
+
if (itemData instanceof SomaRowScope) {
|
|
1380
|
+
return itemData.read(valuePath, path => this.resolver?.readFromRoot(this.resolver.resolvePath(path)));
|
|
1381
|
+
}
|
|
696
1382
|
const segments = valuePath.split('.');
|
|
697
1383
|
const firstSeg = segments[0];
|
|
698
1384
|
|