soma-core 1.5.0 → 1.6.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 +30 -6
- 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/layout/css-emitter.ts +14 -1
- 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/compiler/manifest-compiler.ts +2 -0
- package/core/client/component/ai-catalog.ts +41 -3
- package/core/client/component/catalog-examples.ts +60 -0
- package/core/client/component/component-definition.types.ts +9 -0
- package/core/client/component/component-expander.ts +39 -8
- package/core/client/component/component-manager.ts +107 -16
- package/core/client/component/component-registry.ts +10 -1
- 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 +64 -1
- package/core/client/engine/asset-resolver.ts +1 -1
- package/core/client/engine/dom-renderer.ts +283 -0
- package/core/client/engine/event-engine.ts +28 -9
- package/core/client/engine/render-engine.ts +2 -0
- 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/soma-bootstrap.ts +146 -1
- package/core/client/parser/blocks/page-parser.ts +9 -2
- package/core/client/parser/ui-config-parser.ts +38 -6
- package/core/client/registry/declaration-renderer.ts +32 -24
- package/core/client/registry/remote-page.ts +1 -1
- package/core/client/theme/theme-engine.ts +61 -1
- package/core/client/validation/contract-validator.ts +1 -1
- package/core/index.ts +9 -1
- 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/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/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/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 +1976 -692
- package/dist/lsp/component-tree.cjs +20807 -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/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 +3 -1
- package/dist/types/client/component/component-manager.d.ts +11 -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/engine/dom-renderer.d.ts +15 -0
- package/dist/types/client/engine/event-engine.d.ts +1 -0
- package/dist/types/client/engine/render-engine.d.ts +1 -0
- 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/ui-config-parser.d.ts +2 -0
- 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/index.d.ts +3 -2
- 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/manifest.types.d.ts +4 -0
- package/dist/types/shared/types/ui-config.types.d.ts +8 -0
- package/package.json +3 -1
|
@@ -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('[SomaBootstrap] 收到未编译的 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,6 +515,7 @@ 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(
|
|
@@ -482,6 +603,28 @@ export class SomaBootstrap {
|
|
|
482
603
|
...overrides,
|
|
483
604
|
DomainClass: overrides.DomainClass ?? this.assets.DomainClass,
|
|
484
605
|
};
|
|
606
|
+
if (this.assets.sourceMarkup === 'component-tree' || merged.sourceMarkup === 'component-tree') {
|
|
607
|
+
const compilationFields = ['html', 'uiConfig', 'eventConfig', 'triggerConfig', 'timerConfig',
|
|
608
|
+
'dataConfig', 'uiYaml', 'eventYaml', 'dataYaml', 'sourceMarkup', 'artifact'] as const;
|
|
609
|
+
const updatesCompilation = compilationFields.some((key) => Object.hasOwn(overrides, key));
|
|
610
|
+
if (updatesCompilation && (overrides.html === undefined || overrides.sourceMarkup === undefined
|
|
611
|
+
|| (merged.sourceMarkup === 'component-tree' && overrides.artifact === undefined)
|
|
612
|
+
|| !((overrides.uiConfig !== undefined && overrides.eventConfig !== undefined)
|
|
613
|
+
|| (overrides.uiYaml !== undefined && overrides.eventYaml !== undefined)))) {
|
|
614
|
+
throw new SomaComponentTreeError({
|
|
615
|
+
code: 'CT-ARTIFACT-INCOMPLETE', phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'hotSwap',
|
|
616
|
+
fixHint: '树页面热替换必须整体提供 HTML、格式、配置与 artifact,不能混用新旧编译批次。',
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
if (updatesCompilation) {
|
|
620
|
+
// Remove alternate representations from the previous compile batch.
|
|
621
|
+
for (const key of ['uiConfig', 'eventConfig', 'triggerConfig', 'timerConfig', 'dataConfig',
|
|
622
|
+
'uiYaml', 'eventYaml', 'dataYaml', 'artifact'] as const) {
|
|
623
|
+
if (!Object.hasOwn(overrides, key)) delete merged[key];
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
assertPageRuntimeAssets(merged, this.hostComponents);
|
|
485
628
|
|
|
486
629
|
if (options?.resetDiagnostics) {
|
|
487
630
|
this.diagnostics = new SomaDiagnostics();
|
|
@@ -1240,6 +1383,7 @@ export class SomaBootstrap {
|
|
|
1240
1383
|
pipeRegistry: this.pipeRegistry,
|
|
1241
1384
|
componentDefaults: this.componentDefaults,
|
|
1242
1385
|
styleOptions: { nonce: this.componentStyleNonce ?? null },
|
|
1386
|
+
treeArtifact: assets.artifact,
|
|
1243
1387
|
});
|
|
1244
1388
|
this.componentManager.prepare(container, uiConfig);
|
|
1245
1389
|
}
|
|
@@ -1270,6 +1414,7 @@ export class SomaBootstrap {
|
|
|
1270
1414
|
eventMiddleware: this.eventMiddleware,
|
|
1271
1415
|
pipeRegistry: this.pipeRegistry,
|
|
1272
1416
|
adaptiveVocabulary: this.adaptiveVocabulary,
|
|
1417
|
+
repeatPlans: this.assets?.artifact?.repeatPlans,
|
|
1273
1418
|
});
|
|
1274
1419
|
|
|
1275
1420
|
this.parsedTimers = parsed.timers;
|
|
@@ -285,17 +285,24 @@ function parseEachBlock(
|
|
|
285
285
|
throw new SomaBlockParseError(message, 'page');
|
|
286
286
|
};
|
|
287
287
|
const raw = String(block.each);
|
|
288
|
-
const match = /^(\S+)\s+as\s+([A-
|
|
288
|
+
const match = /^(\S+)\s+as\s+([$A-Z_a-z][$\w]*)(?:\s+by\s+(\S+))?(?:\s+key\s+(\S+))?$/.exec(raw.trim());
|
|
289
289
|
if (!match) {
|
|
290
290
|
fail(`each 语法错误: "${raw}"(应为 each: 路径 as 变量 [by 路径] [key 字段])`);
|
|
291
291
|
}
|
|
292
|
-
const [, sourcePath, rowVar, byPath] = match!;
|
|
292
|
+
const [, sourcePath, rowVar, byPath, keyPath] = match!;
|
|
293
293
|
|
|
294
294
|
const bind: BindDeclaration = {
|
|
295
295
|
obj: expandPath(sourcePath, scope),
|
|
296
296
|
var: rowVar,
|
|
297
297
|
};
|
|
298
298
|
if (byPath) bind.role_by = byPath;
|
|
299
|
+
if (keyPath) {
|
|
300
|
+
bind.key = keyPath.includes('.') ? keyPath : `${rowVar}.${keyPath}`;
|
|
301
|
+
if (!bind.key.startsWith(`${rowVar}.`) || !/^[$A-Z_a-z][$\w]*(?:\.[$A-Z_a-z][$\w]*)+$/.test(bind.key)
|
|
302
|
+
|| bind.key.split('.').some(part => ['__proto__', 'prototype', 'constructor'].includes(part))) {
|
|
303
|
+
fail('each key 必须是当前行变量的安全字段路径');
|
|
304
|
+
}
|
|
305
|
+
}
|
|
299
306
|
|
|
300
307
|
// 行作用域:行变量加入可见名
|
|
301
308
|
const rowScope: BlockScope = {
|
|
@@ -52,6 +52,8 @@ export class SomaUiConfigError extends Error {
|
|
|
52
52
|
// ─── 解析选项 ─────────────────────────────────────────────────────────────────
|
|
53
53
|
|
|
54
54
|
export interface SomaUiConfigParseOptions {
|
|
55
|
+
/** Raw collectionSlot is trusted package source only; runtimes consume plan references. */
|
|
56
|
+
collectionBindingStage?: 'definition-source' | 'runtime';
|
|
55
57
|
/**
|
|
56
58
|
* 阶梯词汇表(F-09)。core 不内置任何级语义,词汇由宿主 bootstrap 注入;
|
|
57
59
|
* 不传而页面声明了 `adaptive.ladder` 时,按"词汇未知"快速失败。
|
|
@@ -110,6 +112,20 @@ function validateBind(bind: any, path: string): asserts bind is BindDeclaration
|
|
|
110
112
|
if ('onChange' in bind && bind.onChange !== undefined) {
|
|
111
113
|
parseOnChangeRules(bind.onChange, `${path}.onChange`);
|
|
112
114
|
}
|
|
115
|
+
if (bind.key !== undefined && (typeof bind.key !== 'string'
|
|
116
|
+
|| !bind.key.startsWith(`${bind.var}.`)
|
|
117
|
+
|| !/^[$A-Z_a-z][$\w]*(?:\.[$A-Z_a-z][$\w]*)+$/.test(bind.key)
|
|
118
|
+
|| bind.key.split('.').some((part: string) => ['__proto__', 'prototype', 'constructor'].includes(part)))) {
|
|
119
|
+
throw new SomaUiConfigError('bind.key 必须是当前行变量的安全字段路径', path);
|
|
120
|
+
}
|
|
121
|
+
if (bind.repeatPlanId !== undefined && (typeof bind.repeatPlanId !== 'string' || !bind.repeatPlanId.trim()
|
|
122
|
+
|| bind.key !== undefined || bind.collectionSlot !== undefined)) {
|
|
123
|
+
throw new SomaUiConfigError('repeatPlanId 必须是非空引用且不能与 key/collectionSlot 双写', path);
|
|
124
|
+
}
|
|
125
|
+
if (bind.collectionSlot !== undefined && (typeof bind.collectionSlot !== 'string' || !bind.collectionSlot.trim()
|
|
126
|
+
|| bind.key === undefined)) {
|
|
127
|
+
throw new SomaUiConfigError('collectionSlot 必须具名并提供唯一显式 key', path);
|
|
128
|
+
}
|
|
113
129
|
}
|
|
114
130
|
|
|
115
131
|
function parseOnChangeRules(raw: unknown, path: string): OnChangeRule[] {
|
|
@@ -172,7 +188,7 @@ function parseInitProps(raw: unknown, path: string): Record<string, unknown> {
|
|
|
172
188
|
/**
|
|
173
189
|
* 判断一个对象值是否为嵌套绑定(含 bind + show)
|
|
174
190
|
*/
|
|
175
|
-
function isNestedShowMapping(value: any): value is { bind: any; show: any; when?: unknown } {
|
|
191
|
+
function isNestedShowMapping(value: any): value is { bind: any; show: any; when?: unknown; props?: unknown } {
|
|
176
192
|
return (
|
|
177
193
|
typeof value === 'object' &&
|
|
178
194
|
value !== null &&
|
|
@@ -205,7 +221,7 @@ function isExtendedShowValue(value: any): boolean {
|
|
|
205
221
|
* @returns 类型安全的 ShowMapping
|
|
206
222
|
* @throws SomaUiConfigError 格式不合法时抛出
|
|
207
223
|
*/
|
|
208
|
-
function parseShowMapping(rawShow: any, path: string): ShowMapping {
|
|
224
|
+
function parseShowMapping(rawShow: any, path: string, options?: SomaUiConfigParseOptions): ShowMapping {
|
|
209
225
|
if (!rawShow || typeof rawShow !== 'object') {
|
|
210
226
|
throw new SomaUiConfigError(`show 必须是对象`, path);
|
|
211
227
|
}
|
|
@@ -225,23 +241,36 @@ function parseShowMapping(rawShow: any, path: string): ShowMapping {
|
|
|
225
241
|
} else if (/^item:.+/.test(key) && typeof value === 'object' && value !== null
|
|
226
242
|
&& !isNestedShowMapping(value) && !isExtendedShowValue(value)) {
|
|
227
243
|
// 异构列表分组键:item:变体 → 仅该变体行生效的子映射(DSL 扩展规范 2.1)
|
|
228
|
-
result[key] = { show: parseShowMapping(value, currentPath) };
|
|
244
|
+
result[key] = { show: parseShowMapping(value, currentPath, options) };
|
|
229
245
|
} else if (isNestedShowMapping(value)) {
|
|
230
246
|
// 嵌套绑定:含 bind + show
|
|
231
247
|
const nestedPath = `${currentPath}.bind`;
|
|
232
248
|
validateBind(value.bind, nestedPath);
|
|
249
|
+
if (value.bind.collectionSlot !== undefined && options?.collectionBindingStage !== 'definition-source') {
|
|
250
|
+
throw new SomaUiConfigError('collectionSlot 仅允许受信组件定义源;运行时必须使用准备计划', nestedPath);
|
|
251
|
+
}
|
|
233
252
|
|
|
234
253
|
const nested: NestedShowMapping = {
|
|
235
254
|
bind: {
|
|
236
255
|
obj: value.bind.obj,
|
|
237
256
|
var: value.bind.var,
|
|
238
257
|
...(typeof value.bind.role_by === 'string' ? { role_by: value.bind.role_by } : {}),
|
|
258
|
+
...(value.bind.key !== undefined ? { key: value.bind.key } : {}),
|
|
259
|
+
...(value.bind.repeatPlanId !== undefined ? { repeatPlanId: value.bind.repeatPlanId } : {}),
|
|
260
|
+
...(value.bind.collectionSlot !== undefined ? { collectionSlot: value.bind.collectionSlot } : {}),
|
|
239
261
|
},
|
|
240
|
-
show: parseShowMapping(value.show, `${currentPath}.show
|
|
262
|
+
show: parseShowMapping(value.show, `${currentPath}.show`, options),
|
|
241
263
|
// when 与 bind 同处一层:整块显隐(列表在错误/加载态整体隐藏靠它)
|
|
242
264
|
...(typeof value.when === 'string' ? { when: value.when } : {}),
|
|
243
265
|
};
|
|
244
266
|
|
|
267
|
+
if (value.props !== undefined) {
|
|
268
|
+
if (!value.props || typeof value.props !== 'object' || Array.isArray(value.props)) {
|
|
269
|
+
throw new SomaUiConfigError('props 必须是对象', currentPath);
|
|
270
|
+
}
|
|
271
|
+
nested.props = { ...value.props };
|
|
272
|
+
}
|
|
273
|
+
|
|
245
274
|
result[key] = nested;
|
|
246
275
|
} else if (typeof value === 'object' && value !== null && isExtendedShowValue(value)) {
|
|
247
276
|
// 扩展绑定:含 text / model / when / class / show
|
|
@@ -299,7 +328,7 @@ function parseShowMapping(rawShow: any, path: string): ShowMapping {
|
|
|
299
328
|
}
|
|
300
329
|
|
|
301
330
|
if ('show' in value && value.show !== undefined) {
|
|
302
|
-
extended.show = parseShowMapping(value.show, `${currentPath}.show
|
|
331
|
+
extended.show = parseShowMapping(value.show, `${currentPath}.show`, options);
|
|
303
332
|
}
|
|
304
333
|
|
|
305
334
|
if ('props' in value && value.props !== undefined) {
|
|
@@ -389,7 +418,10 @@ export function parseUiConfig(raw: any, options?: SomaUiConfigParseOptions): UiC
|
|
|
389
418
|
bind.onChange = parseOnChangeRules(raw.bind.onChange, 'bind.onChange');
|
|
390
419
|
}
|
|
391
420
|
|
|
392
|
-
|
|
421
|
+
if (raw.bind.key !== undefined || raw.bind.repeatPlanId !== undefined || raw.bind.collectionSlot !== undefined) {
|
|
422
|
+
throw new SomaUiConfigError('顶层 bind 不接受集合行字段', 'bind');
|
|
423
|
+
}
|
|
424
|
+
const show = parseShowMapping(raw.show, 'show', options);
|
|
393
425
|
|
|
394
426
|
const config: UiConfig = { bind, show };
|
|
395
427
|
|
|
@@ -7,16 +7,19 @@
|
|
|
7
7
|
// - 预编译产物(注册中心 P-a)可选:版本闸在服务端,这里只做结构性校验;
|
|
8
8
|
// - destroy 清场:引擎 unmount 不清 DOM,本通道的销毁语义是挂载点还原为空。
|
|
9
9
|
|
|
10
|
-
import { SomaBootstrap } from '../engine/soma-bootstrap';
|
|
10
|
+
import { SomaBootstrap, assertPageRuntimeAssets, type SomaPageAssets } from '../engine/soma-bootstrap';
|
|
11
11
|
import type { SomaComponentDefinition } from '../component/component-definition.types';
|
|
12
12
|
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
13
13
|
import type { SomaErrorEvent, SomaPageIdentity } from '../observability/error-reporter';
|
|
14
14
|
import { SomaPageRootBase } from '../base/SomaPageRootBase';
|
|
15
|
+
import { assertRuntimeArtifact } from '../../shared/component-tree-artifact';
|
|
16
|
+
import type { ComponentTreeRuntimeEnvelope } from '../../shared/types/component-tree-artifact.types';
|
|
17
|
+
import type { SomaPageMarkup } from '../../shared/types/component-tree.types';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* 服务端编译产物。浏览器不编译 SOMA DSL 源声明,缺失或不完整时明确拒绝。
|
|
18
21
|
*/
|
|
19
|
-
export interface PrecompiledDeclarationAssets {
|
|
22
|
+
export interface PrecompiledDeclarationAssets extends ComponentTreeRuntimeEnvelope {
|
|
20
23
|
uiConfig?: unknown;
|
|
21
24
|
eventConfig?: unknown;
|
|
22
25
|
triggerConfig?: unknown;
|
|
@@ -26,6 +29,8 @@ export interface PrecompiledDeclarationAssets {
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export interface GeneratedPageDeclarations {
|
|
32
|
+
markup?: SomaPageMarkup;
|
|
33
|
+
grammarVersion?: number;
|
|
29
34
|
html: string;
|
|
30
35
|
uiYaml: string;
|
|
31
36
|
eventYaml?: string;
|
|
@@ -105,6 +110,30 @@ export function createGeneratedPagePreview(
|
|
|
105
110
|
page?: SomaPageIdentity,
|
|
106
111
|
compiled?: PrecompiledDeclarationAssets,
|
|
107
112
|
): Promise<void> {
|
|
113
|
+
if (decl.markup === 'component-tree' && compiled?.sourceMarkup !== 'component-tree') {
|
|
114
|
+
assertRuntimeArtifact({ sourceMarkup: 'component-tree' });
|
|
115
|
+
}
|
|
116
|
+
assertRuntimeArtifact(compiled ?? {});
|
|
117
|
+
const usable = compiled !== undefined
|
|
118
|
+
&& compiled.uiConfig !== undefined
|
|
119
|
+
&& compiled.eventConfig !== undefined;
|
|
120
|
+
if (!usable) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
'[soma-core][声明渲染] 缺少完整的服务端编译产物。'
|
|
123
|
+
+ '浏览器不解析 SOMA DSL 源声明;请由生成/注册服务返回 compiled 资产。',
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const assets: SomaPageAssets = {
|
|
127
|
+
html: compiled.html ?? decl.html,
|
|
128
|
+
sourceMarkup: compiled.sourceMarkup,
|
|
129
|
+
artifact: compiled.artifact,
|
|
130
|
+
uiYaml: '', eventYaml: '', styleYaml: '', DomainClass: getPreviewPageRoot(),
|
|
131
|
+
uiConfig: compiled.uiConfig as never, eventConfig: compiled.eventConfig as never,
|
|
132
|
+
triggerConfig: compiled.triggerConfig as never, timerConfig: compiled.timerConfig as never,
|
|
133
|
+
...(compiled.styleConfig !== undefined ? { styleConfig: compiled.styleConfig as never } : {}),
|
|
134
|
+
...(compiled.dataConfig !== undefined ? { dataConfig: compiled.dataConfig as never } : {}),
|
|
135
|
+
};
|
|
136
|
+
assertPageRuntimeAssets(assets, components);
|
|
108
137
|
if (bootstrap) {
|
|
109
138
|
await bootstrap.unmount();
|
|
110
139
|
bootstrap = null;
|
|
@@ -125,28 +154,7 @@ export function createGeneratedPagePreview(
|
|
|
125
154
|
// 版本闸在服务端:那里同时知道"产物是哪个编译器版本产的"与"当前跑的是哪个版本",
|
|
126
155
|
// 客户端拿不到后者,在这里判等于自欺。服务端只有认定可用才会把 compiled 发下来,
|
|
127
156
|
// 这里只做最后一道结构性校验(ui/event 两段齐备,asset-resolver 的硬要求)。
|
|
128
|
-
|
|
129
|
-
&& compiled.uiConfig !== undefined
|
|
130
|
-
&& compiled.eventConfig !== undefined;
|
|
131
|
-
if (!usable) {
|
|
132
|
-
throw new Error(
|
|
133
|
-
'[soma-core][声明渲染] 缺少完整的服务端编译产物。'
|
|
134
|
-
+ '浏览器不解析 SOMA DSL 源声明;请由生成/注册服务返回 compiled 资产。',
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
await next.mount(container, {
|
|
138
|
-
html: decl.html,
|
|
139
|
-
uiYaml: '',
|
|
140
|
-
eventYaml: '',
|
|
141
|
-
styleYaml: '',
|
|
142
|
-
DomainClass: getPreviewPageRoot(),
|
|
143
|
-
uiConfig: compiled.uiConfig as never,
|
|
144
|
-
eventConfig: compiled.eventConfig as never,
|
|
145
|
-
triggerConfig: compiled.triggerConfig as never,
|
|
146
|
-
timerConfig: compiled.timerConfig as never,
|
|
147
|
-
...(compiled.styleConfig !== undefined ? { styleConfig: compiled.styleConfig as never } : {}),
|
|
148
|
-
...(compiled.dataConfig !== undefined ? { dataConfig: compiled.dataConfig as never } : {}),
|
|
149
|
-
});
|
|
157
|
+
await next.mount(container, assets);
|
|
150
158
|
bootstrap = next;
|
|
151
159
|
},
|
|
152
160
|
async destroy(): Promise<void> {
|
|
@@ -307,6 +307,61 @@ function enforceContrastPairs(vars: Record<string, string>): void {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
// ─── 可读文字 × 中性表面:配色规格的令牌层保障 ─────────
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* 页面上**读得到的字**用的五枚文字令牌。弱化(muted)与次级(secondary)同样是要读的字——
|
|
314
|
+
* 卡片副标题、指标标签、定义列表 dt 全靠它们——AA 底线不因"弱化"降级。
|
|
315
|
+
* 禁用文字(text-disabled / control-fg-disabled)按 WCAG 1.4.3 豁免,不在此列。
|
|
316
|
+
*/
|
|
317
|
+
const READABLE_TEXT_KEYS = [
|
|
318
|
+
'--soma-text-strong',
|
|
319
|
+
'--soma-text-primary',
|
|
320
|
+
'--soma-text-secondary',
|
|
321
|
+
'--soma-text-muted',
|
|
322
|
+
'--soma-text-link',
|
|
323
|
+
] as const;
|
|
324
|
+
|
|
325
|
+
/** 文字令牌可能直接落上的五张中性表面;取最坏的那张求解(组件不必关心自己在哪张底上)。 */
|
|
326
|
+
const NEUTRAL_SURFACE_KEYS = [
|
|
327
|
+
'--soma-bg-page',
|
|
328
|
+
'--soma-bg-container',
|
|
329
|
+
'--soma-surface-card',
|
|
330
|
+
'--soma-bg-elevated',
|
|
331
|
+
'--soma-bg-hover',
|
|
332
|
+
] as const;
|
|
333
|
+
|
|
334
|
+
const READABLE_TEXT_TARGET = 4.52;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 在**最终生效**的变量表上(overrides 合并之后)逐枚校正文字令牌:
|
|
338
|
+
* 对五张中性表面取最坏对比度,不达标就沿"远离表面"的方向按 0.02 明度步进,
|
|
339
|
+
* 停在刚好可读的最浅处——层级(strong > primary > secondary > muted)因此保留。
|
|
340
|
+
* 与 enforceContrastPairs 的区别:那边是实心语气底配黑白字,二选一即可;
|
|
341
|
+
* 这里是灰阶层级,直接换成黑/白会把四档墨色压成一档。
|
|
342
|
+
*/
|
|
343
|
+
function enforceReadableText(vars: Record<string, string>): void {
|
|
344
|
+
const surfaces = NEUTRAL_SURFACE_KEYS
|
|
345
|
+
.map((key) => contrastColorToHex(vars[key] ?? ''))
|
|
346
|
+
.filter((hex): hex is string => hex !== null);
|
|
347
|
+
if (surfaces.length === 0) return;
|
|
348
|
+
const surfaceLum = Math.min(...surfaces.map((hex) => hexToOklch(hex).l));
|
|
349
|
+
for (const key of READABLE_TEXT_KEYS) {
|
|
350
|
+
let tone = contrastColorToHex(vars[key] ?? '');
|
|
351
|
+
if (!tone) continue;
|
|
352
|
+
const worst = (hex: string) => Math.min(...surfaces.map((surface) => contrastRatio(surface, hex)));
|
|
353
|
+
if (worst(tone) >= READABLE_TEXT_TARGET) continue;
|
|
354
|
+
const direction = hexToOklch(tone).l < surfaceLum ? -1 : 1;
|
|
355
|
+
for (let i = 0; i < 40 && worst(tone) < READABLE_TEXT_TARGET; i++) {
|
|
356
|
+
const cur = hexToOklch(tone);
|
|
357
|
+
const next = Math.max(0, Math.min(1, cur.l + direction * 0.02));
|
|
358
|
+
if (next === cur.l) break;
|
|
359
|
+
tone = oklchToHex({ ...cur, l: next });
|
|
360
|
+
}
|
|
361
|
+
vars[key] = tone;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
310
365
|
// ─── 淡底前景(-on-soft):AA 承诺覆盖到"淡底徽标"这一类配对 ─────────
|
|
311
366
|
|
|
312
367
|
/** 有 `-soft` 淡底的八个语气;每个都配一枚 `-on-soft` 前景 */
|
|
@@ -419,7 +474,9 @@ function deriveOnSoftTokens(vars: Record<string, string>, dark: boolean): void {
|
|
|
419
474
|
const backdropLuminance: number[] = [];
|
|
420
475
|
for (const surface of surfaces) {
|
|
421
476
|
const once = compositeOver(soft, surface);
|
|
422
|
-
|
|
477
|
+
// 素面本身也算一张底:`-on-soft` 是全库唯一的「彩色文字」令牌(配色规格 §11.2),
|
|
478
|
+
// 状态文案、选中项文字这类不带淡底的彩色字同样用它,AA 必须对素面同时成立
|
|
479
|
+
backdropLuminance.push(luminanceRgba(surface), luminanceRgba(once), luminanceRgba(compositeOver(soft, once)));
|
|
423
480
|
}
|
|
424
481
|
const worst = (hex: string) => {
|
|
425
482
|
const fgLuminance = luminanceHex(hex);
|
|
@@ -1019,6 +1076,7 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
1019
1076
|
textPrimary = oklchToHex({ ...cur, l: cur.l - 0.04 });
|
|
1020
1077
|
}
|
|
1021
1078
|
|
|
1079
|
+
|
|
1022
1080
|
// ── 材质令牌(REQ-006 G1)──────────────────────────────────────────────
|
|
1023
1081
|
// 玻璃面是**半透明白 + 背后模糊**;高光边是它立体感的来源(少了边就成了糊面)。
|
|
1024
1082
|
// 彩色投影取品牌色相:参照实现里投影是 rgba(37,99,235,.14) 而不是灰——
|
|
@@ -1280,6 +1338,8 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
1280
1338
|
syncSoftWithOverrides(darkCssVars, darkMerged);
|
|
1281
1339
|
enforceContrastPairs(cssVars);
|
|
1282
1340
|
enforceContrastPairs(darkCssVars);
|
|
1341
|
+
enforceReadableText(cssVars);
|
|
1342
|
+
enforceReadableText(darkCssVars);
|
|
1283
1343
|
// ⑥.2 淡底前景:必须在 overrides 之后算,AA 保障的是**最终生效**的那套底与那套色
|
|
1284
1344
|
deriveOnSoftTokens(cssVars, false);
|
|
1285
1345
|
deriveOnSoftTokens(darkCssVars, true);
|
|
@@ -103,7 +103,7 @@ export class SomaContractValidator {
|
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
// Also scan inside <template> elements whose content lives in a DocumentFragment
|
|
106
|
-
root.querySelectorAll<HTMLTemplateElement>('template
|
|
106
|
+
root.querySelectorAll<HTMLTemplateElement>('template').forEach((tmpl) => {
|
|
107
107
|
if (tmpl.content) {
|
|
108
108
|
scanNode(tmpl.content);
|
|
109
109
|
}
|
package/core/index.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type {
|
|
|
20
20
|
export { SomaComponentRegistry } from './client/component/component-registry';
|
|
21
21
|
export { SomaComponentManager } from './client/component/component-manager';
|
|
22
22
|
export { generateAiCatalog, buildCatalogEntry } from './client/component/ai-catalog';
|
|
23
|
+
export { selectSomaCatalogExample, formatSomaCatalogExample } from './client/component/catalog-examples';
|
|
24
|
+
export type { CatalogExampleCapabilities, CatalogExampleSource } from './client/component/catalog-examples';
|
|
23
25
|
export {
|
|
24
26
|
deriveKeyboardMatrix,
|
|
25
27
|
renderKeyboardMatrixLine,
|
|
@@ -301,6 +303,7 @@ export type {
|
|
|
301
303
|
SomaContractKeyboard,
|
|
302
304
|
SomaContractOverlay,
|
|
303
305
|
SomaContractToken,
|
|
306
|
+
SomaContractExample,
|
|
304
307
|
} from './shared/types/component-contract.types';
|
|
305
308
|
export { findNestedMutableContractDefault } from './shared/types/component-contract.types';
|
|
306
309
|
|
|
@@ -362,7 +365,12 @@ export type { SomaHtmlSanitizer, SomaHtmlSanitizeResult } from './client/securit
|
|
|
362
365
|
export type { SomaDiagnosticsSnapshot } from './client/diagnostics/SomaDiagnostics';
|
|
363
366
|
export { matchGlobPath } from './client/engine/property-watcher';
|
|
364
367
|
export { extractConfigFromDomainClass } from './client/parser/annotation-extractor';
|
|
365
|
-
|
|
368
|
+
// Rollup is a build-time integration and must not be re-exported from the
|
|
369
|
+
// browser-facing root barrel. Keeping it here makes bundlers traverse the
|
|
370
|
+
// CJS precompiler (`soma-precompile.js`) while compiling every client that
|
|
371
|
+
// imports `soma-core`, which fails in a browser because `module` is absent.
|
|
372
|
+
// Consumers that need Rollup use the explicit `soma-core/compiler/rollup`
|
|
373
|
+
// entry instead.
|
|
366
374
|
export { Page, Show, ShowList, Event } from './client/base/decorators';
|
|
367
375
|
export { runAsync } from './client/base/runAsync';
|
|
368
376
|
export type { AsyncStateHost } from './client/base/runAsync';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
import { resolvePageMarkup } from '../../build/component-tree/source-preflight';
|
|
5
|
+
import type { SomaPageMarkup } from '../../shared/types/component-tree.types';
|
|
6
|
+
|
|
7
|
+
/** Trusted Host/source-package source inventory; page declarations cannot change this file. */
|
|
8
|
+
export function loadPageMarkupConfig(configRoot: string, base: string): {
|
|
9
|
+
markup?: SomaPageMarkup;
|
|
10
|
+
grammarVersion?: number;
|
|
11
|
+
} {
|
|
12
|
+
const file = join(configRoot, 'page-markup.config.yaml');
|
|
13
|
+
if (!existsSync(file)) return {};
|
|
14
|
+
const raw: unknown = yaml.load(readFileSync(file, 'utf8'));
|
|
15
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
16
|
+
throw new Error('[soma-core][页面格式] page-markup.config.yaml 必须包含 pages 对象');
|
|
17
|
+
}
|
|
18
|
+
const pages = (raw as Record<string, unknown>).pages;
|
|
19
|
+
if (!pages || typeof pages !== 'object' || Array.isArray(pages)) {
|
|
20
|
+
throw new Error('[soma-core][页面格式] page-markup.config.yaml 的 pages 必须是对象');
|
|
21
|
+
}
|
|
22
|
+
if (!Object.hasOwn(pages, base)) return {};
|
|
23
|
+
const metadata = (pages as Record<string, unknown>)[base];
|
|
24
|
+
if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) {
|
|
25
|
+
throw new Error('[soma-core][页面格式] 页面格式项必须是 markup/grammarVersion 对象');
|
|
26
|
+
}
|
|
27
|
+
const entry = metadata as Record<string, unknown>;
|
|
28
|
+
if (Object.keys(entry).some((key) => key !== 'markup' && key !== 'grammarVersion')) {
|
|
29
|
+
throw new Error('[soma-core][页面格式] 页面格式项仅允许 markup/grammarVersion');
|
|
30
|
+
}
|
|
31
|
+
if (entry.markup !== undefined && entry.markup !== 'legacy-html' && entry.markup !== 'component-tree') {
|
|
32
|
+
throw new Error('[soma-core][页面格式] markup 不受支持');
|
|
33
|
+
}
|
|
34
|
+
if (entry.grammarVersion !== undefined && typeof entry.grammarVersion !== 'number') {
|
|
35
|
+
throw new Error('[soma-core][页面格式] grammarVersion 必须为数字');
|
|
36
|
+
}
|
|
37
|
+
const markup = resolvePageMarkup({ markup: entry.markup, grammarVersion: entry.grammarVersion });
|
|
38
|
+
return {
|
|
39
|
+
markup,
|
|
40
|
+
...(markup === 'component-tree' ? { grammarVersion: 1 } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|