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
|
@@ -43,7 +43,7 @@ import { decodePageState, encodePageState, parseStateValue } from '../parser/pag
|
|
|
43
43
|
import { injectStyleOnce } from '../component/pack-styles';
|
|
44
44
|
import type { SomaComponentDefinition } from '../component/component-definition.types';
|
|
45
45
|
import { SomaComponentRegistry } from '../component/component-registry';
|
|
46
|
-
import { SomaComponentManager } from '../component/component-manager';
|
|
46
|
+
import { SomaComponentManager, warnSubscriptionsWithoutComponents } from '../component/component-manager';
|
|
47
47
|
import {
|
|
48
48
|
validateComponentDefaults,
|
|
49
49
|
type SomaComponentDefaults,
|
|
@@ -60,8 +60,11 @@ import {
|
|
|
60
60
|
} from '../observability/error-reporter';
|
|
61
61
|
|
|
62
62
|
// ─── 类型定义 ──────────────────────────────────────────
|
|
63
|
+
import { assertRuntimeArtifact } from '../../shared/component-tree-artifact';
|
|
64
|
+
import { SomaComponentTreeError } from '../../shared/component-tree-errors';
|
|
65
|
+
import type { ComponentTreeRuntimeEnvelope } from '../../shared/types/component-tree-artifact.types';
|
|
63
66
|
|
|
64
|
-
export interface SomaPageAssets {
|
|
67
|
+
export interface SomaPageAssets extends ComponentTreeRuntimeEnvelope {
|
|
65
68
|
html: string;
|
|
66
69
|
includes?: Record<string, string>;
|
|
67
70
|
DomainClass: new () => SomaPageRoot;
|
|
@@ -104,6 +107,123 @@ export interface SomaPageAssets {
|
|
|
104
107
|
components?: Record<string, SomaComponentDefinition>;
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
/** Validate before mutating the current DOM or instantiating any business Domain. */
|
|
111
|
+
export function assertPageRuntimeAssets(assets: SomaPageAssets, hostComponents: Record<string, SomaComponentDefinition>): void {
|
|
112
|
+
assertRuntimeArtifact(assets);
|
|
113
|
+
if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
|
|
114
|
+
throw new Error('[soma-core][引擎] 收到未编译的 SOMA DSL 源声明,请先在服务端编译。');
|
|
115
|
+
}
|
|
116
|
+
if (assets.sourceMarkup === 'component-tree') {
|
|
117
|
+
for (const ref of assets.artifact!.componentRefs) {
|
|
118
|
+
const definition = assets.components?.[ref.name] ?? hostComponents[ref.name];
|
|
119
|
+
if (!definition || definition.contractDigest !== ref.contractDigest || definition.structureDigest !== ref.structureDigest) {
|
|
120
|
+
throw new SomaComponentTreeError({
|
|
121
|
+
code: 'CT-ARTIFACT-CAPABILITY', phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'componentRefs',
|
|
122
|
+
fixHint: '客户端组件供货缺失或契约/结构摘要与资产不一致;请同步部署服务端与客户端供货。',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const objectConfig = assets.uiConfig !== undefined && assets.eventConfig !== undefined;
|
|
127
|
+
const yamlConfig = typeof assets.uiYaml === 'string' && assets.uiYaml.trim() !== ''
|
|
128
|
+
&& typeof assets.eventYaml === 'string';
|
|
129
|
+
if ((!objectConfig && !yamlConfig) || (assets.styleConfig && Object.keys(assets.styleConfig).length > 0)
|
|
130
|
+
|| Boolean(assets.styleYaml?.trim()) || Object.keys(assets.includes ?? {}).length > 0) {
|
|
131
|
+
throw new SomaComponentTreeError({
|
|
132
|
+
code: 'CT-ARTIFACT-INCOMPLETE', phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'config',
|
|
133
|
+
fixHint: '树页面必须携带完整编译配置;不能附带独立样式或待展开 includes。',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Browser parsing is used only for leak detection, never as the source tree parser.
|
|
138
|
+
const probe = document.createElement('template');
|
|
139
|
+
probe.innerHTML = assets.html;
|
|
140
|
+
const pending: ParentNode[] = [probe.content];
|
|
141
|
+
const treeHosts = new Map<string, Element>();
|
|
142
|
+
const treeTemplates = new Map<string, Element>();
|
|
143
|
+
const templateParents = new Map<Node, HTMLTemplateElement>();
|
|
144
|
+
const invalidPlan = (): never => {
|
|
145
|
+
throw new SomaComponentTreeError({
|
|
146
|
+
code: 'CT-ARTIFACT-INCOMPLETE', phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'html.plans',
|
|
147
|
+
fixHint: '兼容 HTML 的组件/行模板与结构计划不是同一编译批次;旧页面不会被替换。',
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
while (pending.length > 0) {
|
|
151
|
+
for (const element of pending.pop()!.querySelectorAll('*')) {
|
|
152
|
+
if (element.localName.toLowerCase().startsWith('soma-')) {
|
|
153
|
+
throw new SomaComponentTreeError({
|
|
154
|
+
code: 'CT-SYNTAX-LEAK', phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'html',
|
|
155
|
+
fixHint: '运行时 HTML 仍包含组件树源码标签;请检查完整资产出口。',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (assets.sourceMarkup === 'component-tree') {
|
|
159
|
+
if (element.hasAttribute('data-soma-component')) {
|
|
160
|
+
const symbol = element.getAttribute('data-soma-id') ?? '';
|
|
161
|
+
if (!symbol || treeHosts.has(symbol)) invalidPlan();
|
|
162
|
+
treeHosts.set(symbol, element);
|
|
163
|
+
}
|
|
164
|
+
if (element.hasAttribute('data-soma-repeat-template')) {
|
|
165
|
+
const symbol = element.getAttribute('data-soma-repeat-template') ?? '';
|
|
166
|
+
if (!symbol || !isHtmlTemplateElement(element) || treeTemplates.has(symbol)) invalidPlan();
|
|
167
|
+
treeTemplates.set(symbol, element);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (isHtmlTemplateElement(element)) {
|
|
171
|
+
templateParents.set(element.content, element);
|
|
172
|
+
pending.push(element.content);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (assets.sourceMarkup === 'component-tree') {
|
|
177
|
+
if (treeHosts.size !== assets.artifact!.structurePlan.length || treeTemplates.size !== assets.artifact!.repeatPlans.length
|
|
178
|
+
|| probe.content.children.length !== 1 || !probe.content.firstElementChild?.hasAttribute('data-soma-host')) invalidPlan();
|
|
179
|
+
for (const plan of assets.artifact!.structurePlan) {
|
|
180
|
+
const host = treeHosts.get(plan.instanceSymbol);
|
|
181
|
+
if (!host || host.getAttribute('data-soma-component') !== plan.componentName
|
|
182
|
+
|| host.localName !== plan.hostTag || host.namespaceURI !== 'http://www.w3.org/1999/xhtml') invalidPlan();
|
|
183
|
+
}
|
|
184
|
+
const repeats = assets.artifact!.repeatPlans;
|
|
185
|
+
const lexicalTemplate = (element: Element): string | undefined => {
|
|
186
|
+
let parent: Node | null = element.parentNode;
|
|
187
|
+
while (parent) {
|
|
188
|
+
const template = templateParents.get(parent);
|
|
189
|
+
if (template?.hasAttribute('data-soma-repeat-template')) return template.getAttribute('data-soma-repeat-template')!;
|
|
190
|
+
parent = template ? template.parentNode : parent.parentNode;
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
};
|
|
194
|
+
const symbolScopes = new Map<string, string>();
|
|
195
|
+
for (const plan of repeats) {
|
|
196
|
+
const template = treeTemplates.get(plan.rowTemplateId);
|
|
197
|
+
const slot = template?.parentNode ? templateParents.get(template.parentNode) : undefined;
|
|
198
|
+
const owner = treeHosts.get(plan.consumerOwner.instanceSymbol);
|
|
199
|
+
const ownerPlan = assets.artifact!.structurePlan.find(item => item.instanceSymbol === plan.consumerOwner.instanceSymbol);
|
|
200
|
+
const slotPlan = ownerPlan?.slotPlans.find(item => item.name === plan.consumerOwner.slotName);
|
|
201
|
+
if (!template || !slot || !owner || slot.parentElement !== owner
|
|
202
|
+
|| slot.getAttribute('data-soma-slot') !== plan.consumerOwner.slotName
|
|
203
|
+
|| template.getAttribute('data-soma-role') !== 'item'
|
|
204
|
+
|| slot.content.children.length !== 1 || slot.content.firstElementChild !== template
|
|
205
|
+
|| slotPlan?.kind !== 'collection' || slotPlan.layoutRootKey !== plan.consumerOwner.layoutRootKey
|
|
206
|
+
|| slotPlan.rowContainer !== plan.consumerOwner.rowContainer
|
|
207
|
+
|| ownerPlan?.componentName !== plan.consumerOwner.componentName) invalidPlan();
|
|
208
|
+
const parentPlan = plan.parentPlanId ? repeats.find(item => item.planId === plan.parentPlanId) : undefined;
|
|
209
|
+
if (lexicalTemplate(owner!) !== parentPlan?.rowTemplateId) invalidPlan();
|
|
210
|
+
for (const symbol of Object.values(plan.localSymbols)) {
|
|
211
|
+
if (symbolScopes.has(symbol) || !treeHosts.has(symbol)) invalidPlan();
|
|
212
|
+
symbolScopes.set(symbol, plan.rowTemplateId);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
for (const [symbol, host] of treeHosts) {
|
|
216
|
+
if (lexicalTemplate(host) !== symbolScopes.get(symbol)) invalidPlan();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Template contents use an inert ownerDocument; its defaultView can be null in real DOM/JSDOM. */
|
|
222
|
+
function isHtmlTemplateElement(element: Element): element is HTMLTemplateElement {
|
|
223
|
+
return element.localName === 'template' && element.namespaceURI === 'http://www.w3.org/1999/xhtml'
|
|
224
|
+
&& 'content' in element && (element as HTMLTemplateElement).content?.nodeType === 11;
|
|
225
|
+
}
|
|
226
|
+
|
|
107
227
|
/** 浏览器只用于拒绝源声明;不存在旧/新两套执行分派。 */
|
|
108
228
|
function isSomaDeclarationSource(value: string): boolean {
|
|
109
229
|
return value.split('\n').some((line) => {
|
|
@@ -395,10 +515,11 @@ export class SomaBootstrap {
|
|
|
395
515
|
this.scheduler.setDiagnostics(this.diagnostics);
|
|
396
516
|
}
|
|
397
517
|
this.container = container;
|
|
518
|
+
assertPageRuntimeAssets(assets, this.hostComponents);
|
|
398
519
|
// 源声明只允许在构建/服务端编译;浏览器 mount 只消费运行时资产。
|
|
399
520
|
if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
|
|
400
521
|
throw new Error(
|
|
401
|
-
'[
|
|
522
|
+
'[soma-core][引擎] 收到未编译的 SOMA DSL 源声明。'
|
|
402
523
|
+ '请先用 compilePageAssets(构建/测试)或 Host 页面编译入口生成运行时资产。',
|
|
403
524
|
);
|
|
404
525
|
}
|
|
@@ -432,6 +553,10 @@ export class SomaBootstrap {
|
|
|
432
553
|
this.prepareDataLayer(this.domainInstance, assets);
|
|
433
554
|
|
|
434
555
|
// 4. 包装响应式代理
|
|
556
|
+
// 第三参(数组变异守卫)这里**故意不传**:传 false 会把开发期也一起关掉,
|
|
557
|
+
// 而这条告警正是写页面时唯一能发现"就地 push 不触发更新"的提示。
|
|
558
|
+
// 该开还是该关交给 SomaReactiveProxy 的默认值按环境判定(isSomaArrayGuardEnabled)——
|
|
559
|
+
// 生产包里是关的,`npm run dev` 与 `globalThis.SOMA_DEV_GUARD = true` 时照旧报。
|
|
435
560
|
this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
|
|
436
561
|
this.domainInstance = this.proxy.wrap(this.domainInstance);
|
|
437
562
|
|
|
@@ -462,7 +587,7 @@ export class SomaBootstrap {
|
|
|
462
587
|
options?: { resetDiagnostics?: boolean; preserveState?: boolean },
|
|
463
588
|
): Promise<void> {
|
|
464
589
|
if (!this.mounted || !this.container || !this.assets || !this.domainInstance) {
|
|
465
|
-
throw new Error('[
|
|
590
|
+
throw new Error('[soma-core][引擎] Cannot hotSwap before mount');
|
|
466
591
|
}
|
|
467
592
|
|
|
468
593
|
const savedLocale =
|
|
@@ -482,6 +607,28 @@ export class SomaBootstrap {
|
|
|
482
607
|
...overrides,
|
|
483
608
|
DomainClass: overrides.DomainClass ?? this.assets.DomainClass,
|
|
484
609
|
};
|
|
610
|
+
if (this.assets.sourceMarkup === 'component-tree' || merged.sourceMarkup === 'component-tree') {
|
|
611
|
+
const compilationFields = ['html', 'uiConfig', 'eventConfig', 'triggerConfig', 'timerConfig',
|
|
612
|
+
'dataConfig', 'uiYaml', 'eventYaml', 'dataYaml', 'sourceMarkup', 'artifact'] as const;
|
|
613
|
+
const updatesCompilation = compilationFields.some((key) => Object.hasOwn(overrides, key));
|
|
614
|
+
if (updatesCompilation && (overrides.html === undefined || overrides.sourceMarkup === undefined
|
|
615
|
+
|| (merged.sourceMarkup === 'component-tree' && overrides.artifact === undefined)
|
|
616
|
+
|| !((overrides.uiConfig !== undefined && overrides.eventConfig !== undefined)
|
|
617
|
+
|| (overrides.uiYaml !== undefined && overrides.eventYaml !== undefined)))) {
|
|
618
|
+
throw new SomaComponentTreeError({
|
|
619
|
+
code: 'CT-ARTIFACT-INCOMPLETE', phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'hotSwap',
|
|
620
|
+
fixHint: '树页面热替换必须整体提供 HTML、格式、配置与 artifact,不能混用新旧编译批次。',
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
if (updatesCompilation) {
|
|
624
|
+
// Remove alternate representations from the previous compile batch.
|
|
625
|
+
for (const key of ['uiConfig', 'eventConfig', 'triggerConfig', 'timerConfig', 'dataConfig',
|
|
626
|
+
'uiYaml', 'eventYaml', 'dataYaml', 'artifact'] as const) {
|
|
627
|
+
if (!Object.hasOwn(overrides, key)) delete merged[key];
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
assertPageRuntimeAssets(merged, this.hostComponents);
|
|
485
632
|
|
|
486
633
|
if (options?.resetDiagnostics) {
|
|
487
634
|
this.diagnostics = new SomaDiagnostics();
|
|
@@ -509,6 +656,7 @@ export class SomaBootstrap {
|
|
|
509
656
|
if (overrides.DomainClass) {
|
|
510
657
|
this.proxy?.dispose();
|
|
511
658
|
const raw = this.createDomainInstance(merged.DomainClass, parsed, merged.routerPath);
|
|
659
|
+
// 与 mount 第 4 步同一口径:守卫开关交给默认值按环境判定,这里不传死
|
|
512
660
|
this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
|
|
513
661
|
this.domainInstance = this.proxy.wrap(raw);
|
|
514
662
|
} else {
|
|
@@ -548,14 +696,14 @@ export class SomaBootstrap {
|
|
|
548
696
|
|
|
549
697
|
captureSnapshot(options?: { exclude?: string[] }): number {
|
|
550
698
|
if (!this.domainInstance) {
|
|
551
|
-
throw new Error('[
|
|
699
|
+
throw new Error('[soma-core][引擎] Cannot capture snapshot before mount');
|
|
552
700
|
}
|
|
553
701
|
return this.snapshotStore.capture(this.domainInstance, options);
|
|
554
702
|
}
|
|
555
703
|
|
|
556
704
|
restoreSnapshot(snapshotId: number): void {
|
|
557
705
|
if (!this.domainInstance) {
|
|
558
|
-
throw new Error('[
|
|
706
|
+
throw new Error('[soma-core][引擎] Cannot restore snapshot before mount');
|
|
559
707
|
}
|
|
560
708
|
this.snapshotStore.restore(snapshotId, this.domainInstance);
|
|
561
709
|
this.renderEngine?.render();
|
|
@@ -563,7 +711,7 @@ export class SomaBootstrap {
|
|
|
563
711
|
|
|
564
712
|
batch(fn: () => void): void {
|
|
565
713
|
if (!this.proxy) {
|
|
566
|
-
throw new Error('[
|
|
714
|
+
throw new Error('[soma-core][引擎] Cannot batch before mount');
|
|
567
715
|
}
|
|
568
716
|
this.proxy.beginBatch();
|
|
569
717
|
try {
|
|
@@ -657,7 +805,7 @@ export class SomaBootstrap {
|
|
|
657
805
|
/** 监听属性变更(委托 RenderEngine.watch) */
|
|
658
806
|
watch(path: string, callback: WatchCallback, options?: WatcherOptions): () => void {
|
|
659
807
|
if (!this.renderEngine) {
|
|
660
|
-
throw new Error('[
|
|
808
|
+
throw new Error('[soma-core][引擎] Cannot watch before mount');
|
|
661
809
|
}
|
|
662
810
|
return this.renderEngine.watch(path, callback, options);
|
|
663
811
|
}
|
|
@@ -1170,7 +1318,7 @@ export class SomaBootstrap {
|
|
|
1170
1318
|
.map(([name, wheres]) => ` "${name}" —— 用在 ${wheres.join('、')}`)
|
|
1171
1319
|
.join('\n');
|
|
1172
1320
|
throw new Error(
|
|
1173
|
-
`[
|
|
1321
|
+
`[soma-core][引擎] 页面用到了未注册的具名动作:\n${lines}\n`
|
|
1174
1322
|
+ ` 已注册:${known}\n`
|
|
1175
1323
|
+ ' 在 configureSomaBootstrap 的 options.actions 里登记它们。'
|
|
1176
1324
|
+ '具名动作是 custom(script) 的替代:实现在 Host 代码里、有名字、可审计。',
|
|
@@ -1218,6 +1366,9 @@ export class SomaBootstrap {
|
|
|
1218
1366
|
}
|
|
1219
1367
|
const defs = { ...this.hostComponents, ...pageComponents };
|
|
1220
1368
|
if (Object.keys(defs).length === 0) {
|
|
1369
|
+
// 一个组件都没有的页面不建管理器(展开、注册表、行钩子全是用不上的开销)。
|
|
1370
|
+
// 管理器顺带做的那件事不能跟着一起没有:没走上 emit 路由的事件名告警由
|
|
1371
|
+
// buildRuntime 里的 warnSubscriptionsWithoutComponents 单独补(见那里的注释)。
|
|
1221
1372
|
return;
|
|
1222
1373
|
}
|
|
1223
1374
|
|
|
@@ -1240,6 +1391,7 @@ export class SomaBootstrap {
|
|
|
1240
1391
|
pipeRegistry: this.pipeRegistry,
|
|
1241
1392
|
componentDefaults: this.componentDefaults,
|
|
1242
1393
|
styleOptions: { nonce: this.componentStyleNonce ?? null },
|
|
1394
|
+
treeArtifact: assets.artifact,
|
|
1243
1395
|
});
|
|
1244
1396
|
this.componentManager.prepare(container, uiConfig);
|
|
1245
1397
|
}
|
|
@@ -1270,6 +1422,7 @@ export class SomaBootstrap {
|
|
|
1270
1422
|
eventMiddleware: this.eventMiddleware,
|
|
1271
1423
|
pipeRegistry: this.pipeRegistry,
|
|
1272
1424
|
adaptiveVocabulary: this.adaptiveVocabulary,
|
|
1425
|
+
repeatPlans: this.assets?.artifact?.repeatPlans,
|
|
1273
1426
|
});
|
|
1274
1427
|
|
|
1275
1428
|
this.parsedTimers = parsed.timers;
|
|
@@ -1289,14 +1442,20 @@ export class SomaBootstrap {
|
|
|
1289
1442
|
this.timerEngine = runtime.timerEngine;
|
|
1290
1443
|
|
|
1291
1444
|
// 组件实例挂载(页面引擎就绪后:emit 路由标记、props watch、行内钩子)
|
|
1292
|
-
this.componentManager
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1445
|
+
if (this.componentManager) {
|
|
1446
|
+
this.componentManager.activate({
|
|
1447
|
+
container: this.container,
|
|
1448
|
+
renderEngine: runtime.renderEngine,
|
|
1449
|
+
eventEngine: runtime.eventEngine,
|
|
1450
|
+
resolver: runtime.resolver,
|
|
1451
|
+
manifest: runtime.manifest,
|
|
1452
|
+
services: this.buildComponentServices(),
|
|
1453
|
+
});
|
|
1454
|
+
} else {
|
|
1455
|
+
// 没有注册任何组件的页面:管理器不建,但它顺带做的事件名告警要补上——
|
|
1456
|
+
// 否则 `card.reach_limit` 这种笔误在这类页面全程静默(解析期那条只认 33 个 DOM 专有名字)。
|
|
1457
|
+
warnSubscriptionsWithoutComponents(runtime.manifest, this.container);
|
|
1458
|
+
}
|
|
1300
1459
|
|
|
1301
1460
|
// 界面中途提交接线:Domain 在长任务里调 `this.publishUi()` 时,
|
|
1302
1461
|
// 把此刻积累的 patch 立刻上屏而不结束事件事务(见 SomaRuntimeServices.ui)
|
|
@@ -26,7 +26,7 @@ export class SomaAdaptiveConfigError extends Error {
|
|
|
26
26
|
|
|
27
27
|
constructor(message: string, path: string = '') {
|
|
28
28
|
const prefix = path ? ` (路径: ${path})` : '';
|
|
29
|
-
super(`[
|
|
29
|
+
super(`[soma-core][引擎] ${message}${prefix}`);
|
|
30
30
|
this.name = 'SomaAdaptiveConfigError';
|
|
31
31
|
this.path = path;
|
|
32
32
|
}
|
|
@@ -86,7 +86,7 @@ function parseAnnotatedPipeline(
|
|
|
86
86
|
): ParsedEvent {
|
|
87
87
|
const colonIdx = raw.indexOf(':');
|
|
88
88
|
if (colonIdx === -1) {
|
|
89
|
-
throw new Error(`[
|
|
89
|
+
throw new Error(`[soma-core][引擎] 无效的 @Event 格式,缺少冒号: "${raw}"`);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const selector = raw.slice(0, colonIdx).trim();
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
import type { OnChangeRule } from '../../../shared/types/watcher.types';
|
|
21
21
|
import { SomaBlockParseError } from '../../../shared/block-errors';
|
|
22
22
|
import { buildBlockScope, expandPath, type BlockScope } from './namespace';
|
|
23
|
+
import { withPageDefaultInPipeline } from './use-parser';
|
|
23
24
|
|
|
24
25
|
const PAGE_KEYS = new Set([
|
|
25
26
|
'domain', 'locale', 'ui', 'watch', 'event', 'data', 'adaptive', 'alias',
|
|
@@ -285,17 +286,24 @@ function parseEachBlock(
|
|
|
285
286
|
throw new SomaBlockParseError(message, 'page');
|
|
286
287
|
};
|
|
287
288
|
const raw = String(block.each);
|
|
288
|
-
const match = /^(\S+)\s+as\s+([A-
|
|
289
|
+
const match = /^(\S+)\s+as\s+([$A-Z_a-z][$\w]*)(?:\s+by\s+(\S+))?(?:\s+key\s+(\S+))?$/.exec(raw.trim());
|
|
289
290
|
if (!match) {
|
|
290
291
|
fail(`each 语法错误: "${raw}"(应为 each: 路径 as 变量 [by 路径] [key 字段])`);
|
|
291
292
|
}
|
|
292
|
-
const [, sourcePath, rowVar, byPath] = match!;
|
|
293
|
+
const [, sourcePath, rowVar, byPath, keyPath] = match!;
|
|
293
294
|
|
|
294
295
|
const bind: BindDeclaration = {
|
|
295
296
|
obj: expandPath(sourcePath, scope),
|
|
296
297
|
var: rowVar,
|
|
297
298
|
};
|
|
298
299
|
if (byPath) bind.role_by = byPath;
|
|
300
|
+
if (keyPath) {
|
|
301
|
+
bind.key = keyPath.includes('.') ? keyPath : `${rowVar}.${keyPath}`;
|
|
302
|
+
if (!bind.key.startsWith(`${rowVar}.`) || !/^[$A-Z_a-z][$\w]*(?:\.[$A-Z_a-z][$\w]*)+$/.test(bind.key)
|
|
303
|
+
|| bind.key.split('.').some(part => ['__proto__', 'prototype', 'constructor'].includes(part))) {
|
|
304
|
+
fail('each key 必须是当前行变量的安全字段路径');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
299
307
|
|
|
300
308
|
// 行作用域:行变量加入可见名
|
|
301
309
|
const rowScope: BlockScope = {
|
|
@@ -409,8 +417,50 @@ function normalizeEventSection(
|
|
|
409
417
|
}
|
|
410
418
|
|
|
411
419
|
// 交给既有 pipeline-parser 的形状:DOM 事件映射 + timers/triggers 原样
|
|
412
|
-
const result: Record<string, unknown> =
|
|
420
|
+
const result: Record<string, unknown> = withPageDefaultInEventTree(on) as Record<string, unknown>;
|
|
413
421
|
if (section.timers !== undefined) result.timers = section.timers;
|
|
414
422
|
if (section.triggers !== undefined) result.triggers = section.triggers;
|
|
415
423
|
return result;
|
|
416
424
|
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* page 块 `event.on` 的处理器段免写 `page.`(REQ-005 F7.3)。
|
|
428
|
+
*
|
|
429
|
+
* 组件块的 `event.on` 与 `event.actions` 早就免前缀了(use-parser),page 块没接上——
|
|
430
|
+
* 同一条 `UI_REFRESH | doSearch` 写在组件块里能跑,搬到 page 块就报"函数路径至少需要
|
|
431
|
+
* 「对象.方法」两段"。这是接线漏了一处,不是两种块有不同规矩,所以直接复用同一个函数。
|
|
432
|
+
*
|
|
433
|
+
* 三种形状分开走:
|
|
434
|
+
* - 叶子字符串:事件声明本体,整条交 withPageDefaultInPipeline;
|
|
435
|
+
* - `{ steps: [...] }`(编排事件):管道住在每一步的 `do:` 里,深走一遍只改 `do` 的字符串值
|
|
436
|
+
* (步骤键是封闭集 when/do/output/on_error/switch/parallel/for_each,`do` 恒为管道表达式);
|
|
437
|
+
* - 其余映射:列表作用域的一层缩进,原样递归。
|
|
438
|
+
* timers / triggers 不在此列:timers 的 `tick` 写的是页面级轮询、triggers 的 `target`/`event`
|
|
439
|
+
* 是锚点与事件名,都不是 funcPath 槽。
|
|
440
|
+
*/
|
|
441
|
+
function withPageDefaultInEventTree(node: unknown): unknown {
|
|
442
|
+
if (typeof node === 'string') return withPageDefaultInPipeline(node);
|
|
443
|
+
if (node === null || typeof node !== 'object' || Array.isArray(node)) return node;
|
|
444
|
+
const source = node as Record<string, unknown>;
|
|
445
|
+
if (Array.isArray(source.steps)) {
|
|
446
|
+
return { ...source, steps: withPageDefaultInSteps(source.steps) };
|
|
447
|
+
}
|
|
448
|
+
const mapped: Record<string, unknown> = {};
|
|
449
|
+
for (const [key, value] of Object.entries(source)) {
|
|
450
|
+
mapped[key] = withPageDefaultInEventTree(value);
|
|
451
|
+
}
|
|
452
|
+
return mapped;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** 步骤树里只有 `do:` 是管道表达式,其余(when / output / 分支名)原样保留 */
|
|
456
|
+
function withPageDefaultInSteps(node: unknown): unknown {
|
|
457
|
+
if (Array.isArray(node)) return node.map(withPageDefaultInSteps);
|
|
458
|
+
if (node === null || typeof node !== 'object') return node;
|
|
459
|
+
const mapped: Record<string, unknown> = {};
|
|
460
|
+
for (const [key, value] of Object.entries(node as Record<string, unknown>)) {
|
|
461
|
+
mapped[key] = key === 'do' && typeof value === 'string'
|
|
462
|
+
? withPageDefaultInPipeline(value)
|
|
463
|
+
: withPageDefaultInSteps(value);
|
|
464
|
+
}
|
|
465
|
+
return mapped;
|
|
466
|
+
}
|
|
@@ -580,20 +580,35 @@ function withPageDefault(funcPath: string): string {
|
|
|
580
580
|
return funcPath.includes('.') ? funcPath : `page.${funcPath}`;
|
|
581
581
|
}
|
|
582
582
|
|
|
583
|
-
/**
|
|
584
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Pipeline 表达式里的处理器段同样享受免前缀。
|
|
585
|
+
*
|
|
586
|
+
* 组件块 `event.on` 与 page 块 `event.on` 共用本函数(REQ-005 F7.3)——两处写的都是
|
|
587
|
+
* 同一套四动词管道,"谁能免写 page." 不该取决于声明住在哪个块里。
|
|
588
|
+
*
|
|
589
|
+
* 槽位按动词查,不按形状猜:
|
|
590
|
+
* - UI_INTERACT 第 2 槽是 DOM 目标锚点、第 3 槽才是可选处理器(裸锚点不能改成 page.<锚点>);
|
|
591
|
+
* - NAV_STATIC 只有路由目标,没有处理器槽;
|
|
592
|
+
* - ACTION 的第 1 槽是**注册表动作名**(`ACTION | refreshBoard`),解析器只认不含点的
|
|
593
|
+
* 标识符(pipeline-parser 的 ACTION 分支),补成 `page.refreshBoard` 反而当场解析失败——
|
|
594
|
+
* 此前它落进了 else 分支拿到 handlerIndex 0,于是 `ACTION` 这个动词本身被改写成
|
|
595
|
+
* `page.ACTION`,报出来的是"未知事件类型 page.ACTION",与真实病因差着十万八千里;
|
|
596
|
+
* - 其余(首段不是动词 = 动词缺省,见 pipeline-parser 的 IMPLICIT_REFRESH_FUNC_PATH)
|
|
597
|
+
* 处理器就在第 0 槽,但只认小写起头的标识符:写错的动词(`UI_REFRESHH`)保持原样,
|
|
598
|
+
* 让 pipeline-parser 报"未知事件类型 UI_REFRESHH",而不是先被改写成 `page.UI_REFRESHH`。
|
|
599
|
+
*/
|
|
600
|
+
export function withPageDefaultInPipeline(expr: string): string {
|
|
585
601
|
const parts = expr.split('|').map((part) => part.trim());
|
|
586
602
|
const verb = parts[0];
|
|
587
|
-
// UI_INTERACT 的第 2 槽是 DOM 目标,第 3 槽才是可选处理器;
|
|
588
|
-
// NAV_STATIC 只有路由目标,不存在处理器。不能把裸锚点误改成 page.<锚点>。
|
|
589
603
|
const handlerIndex = verb === 'UI_INTERACT'
|
|
590
604
|
? 2
|
|
591
|
-
: verb === 'NAV_STATIC'
|
|
605
|
+
: verb === 'NAV_STATIC' || verb === 'ACTION'
|
|
592
606
|
? -1
|
|
593
607
|
: ['UI_REFRESH', 'NAV_ACTION'].includes(verb)
|
|
594
608
|
? 1
|
|
595
609
|
: 0;
|
|
596
|
-
|
|
610
|
+
const shape = handlerIndex === 0 ? /^[a-z][A-Za-z0-9_]*$/ : /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
611
|
+
if (handlerIndex >= 0 && parts[handlerIndex] && shape.test(parts[handlerIndex])) {
|
|
597
612
|
parts[handlerIndex] = `page.${parts[handlerIndex]}`;
|
|
598
613
|
}
|
|
599
614
|
return parts.reduce(
|
|
@@ -47,7 +47,7 @@ export class SomaDataConfigError extends Error {
|
|
|
47
47
|
|
|
48
48
|
constructor(message: string, path: string = '') {
|
|
49
49
|
const prefix = path ? ` (路径: ${path})` : '';
|
|
50
|
-
super(`[
|
|
50
|
+
super(`[soma-core][数据] ${message}${prefix}`);
|
|
51
51
|
this.name = 'SomaDataConfigError';
|
|
52
52
|
this.path = path;
|
|
53
53
|
}
|