soma-kit 0.1.17 → 0.1.19
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/package.json +1 -1
- package/spec/generated/kit-page.schema.json +11 -1
- package/spec/kit-grammar.json +174 -13
- package/spec/kit-grammar.schema.json +4 -0
- package/src/app/component-gate.ts +668 -55
- package/src/app/define-kit-app.ts +75 -6
- package/src/app/index.ts +4 -1
- package/src/app/internal-lab.ts +90 -0
- package/src/app/kit-view-context.ts +44 -2
- package/src/app/server.ts +51 -9
- package/src/biz/compose.ts +66 -0
- package/src/biz/define.ts +38 -1
- package/src/biz/index.ts +1 -0
- package/src/biz/layout-contracts.ts +119 -4
- package/src/biz/link/hub.ts +31 -0
- package/src/biz/master-sub/compile.ts +45 -3
- package/src/biz/master-sub/index.ts +3 -1
- package/src/biz/record-detail/compile.ts +120 -10
- package/src/biz/shared/coordinator.ts +245 -48
- package/src/biz/shared/index.ts +5 -1
- package/src/biz/shared/object-aliases.ts +14 -3
- package/src/biz/shared/overlay-compile.ts +56 -5
- package/src/biz/shared/overlay-shell.ts +5 -2
- package/src/biz/shared/page-form.ts +9 -5
- package/src/biz/shared/page-overlay-host.ts +126 -0
- package/src/biz/shared/page-overlay-names.ts +27 -0
- package/src/biz/shared/runtime-hub.ts +37 -2
- package/src/biz/single-form/compile.ts +60 -5
- package/src/biz/single-form/index.ts +2 -1
- package/src/biz/standard-crud/compile.ts +9 -2
- package/src/biz/types.ts +26 -0
- package/src/cli/kit-cli.ts +1 -0
- package/src/cli/view-writes.ts +130 -3
- package/src/compile/compile-page.ts +49 -4
- package/src/compile/page-pipeline.ts +4 -0
- package/src/compile/parse.ts +14 -0
- package/src/compile/stages.ts +5 -4
- package/src/compile/types.ts +1 -1
- package/src/compile/view-check.ts +49 -17
- package/src/data/comment-thread.ts +78 -18
- package/src/data/navbar.ts +4 -0
- package/src/data/object-form.ts +17 -3
- package/src/data/prompt-dialog.ts +102 -15
- package/src/frames/page-header.ts +11 -2
- package/src/frames/shared.ts +6 -0
- package/src/frames/types.ts +2 -0
- package/src/generated/kit-grammar-runtime.ts +47 -5
- package/src/i18n/kit-text.ts +1 -0
- package/src/object-renderer/request-actions.ts +145 -17
- package/src/object-renderer/types.ts +7 -0
- package/src/shared/dom-attrs-registry.ts +5 -3
- package/src/shared/dom-attrs.ts +2 -0
- package/src/spatial/declared-actions.ts +6 -3
- package/src/spatial/emit.ts +1 -1
- package/src/spatial/expand.ts +7 -2
|
@@ -17,7 +17,10 @@ import type { SomaHostAssembly } from 'soma-core/server/host-assembly';
|
|
|
17
17
|
import { createKitBaseComponents, KIT_BASE_COMPONENTS } from '../base/index';
|
|
18
18
|
import { bizDataComponents, KIT_BIZ_DATA_COMPONENTS } from '../biz/data-components';
|
|
19
19
|
import { KIT_BIZ_COMPONENT_NAMES, KIT_FRAME_NAMES } from '../biz/names';
|
|
20
|
+
import { isDefinedKitBizComponent } from '../biz/define';
|
|
20
21
|
import type { KitBizDefinition } from '../biz/types';
|
|
22
|
+
import { hasInternalLabMark } from './internal-lab';
|
|
23
|
+
import { checkClasses } from '../shared/merge-class';
|
|
21
24
|
import type { KitThemeConfig } from '../theme/theme-tokens';
|
|
22
25
|
import type { KitAppDicts, KitAppEntities, KitAppTheme } from './app-config';
|
|
23
26
|
import { parseKitAppEnvelopeFromYaml, registerKitAppDefaultEnvelope, type KitEnvelope } from '../shared/envelope';
|
|
@@ -140,6 +143,8 @@ export interface KitAppRegistry {
|
|
|
140
143
|
bizComponents: Record<string, KitBizDefinition>;
|
|
141
144
|
frames: Record<string, KitFrameDefinition>;
|
|
142
145
|
appCandidates: readonly string[];
|
|
146
|
+
/** 自定义业务组件自携的私有协作数据组件(已实例化,并入浏览器组件表;页面不可直接选用) */
|
|
147
|
+
bizDataComponents: Record<string, SomaComponentDefinition>;
|
|
143
148
|
/** 领域包的协作数据组件(已实例化,并入浏览器组件表;页面不可直接选用) */
|
|
144
149
|
packDataComponents: Record<string, SomaComponentDefinition>;
|
|
145
150
|
/** 已登记的领域包名 */
|
|
@@ -211,6 +216,16 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
211
216
|
kitFail('KIT-APP-001', 'pagesDir', pagesDiags[0]!.message, '改为相对应用根的页面子目录名(如 pages),严禁 ./、../ 或宿主机系统绝对路径');
|
|
212
217
|
}
|
|
213
218
|
}
|
|
219
|
+
const allowLab = hasInternalLabMark(options);
|
|
220
|
+
const rawBaseNames = Object.keys(options.baseComponents ?? {});
|
|
221
|
+
if (!allowLab && rawBaseNames.length > 0) {
|
|
222
|
+
kitFail(
|
|
223
|
+
'KIT-APP-016',
|
|
224
|
+
`baseComponents.${rawBaseNames[0]!}`,
|
|
225
|
+
`禁止业务应用注册非业务/非数据的野生基础组件(baseComponents:${rawBaseNames.join('、')});基础控件一律复用框架官方闭集`,
|
|
226
|
+
'外部界面扩展仅开放两档:① 业务组件 bizComponents(defineKitBizComponent,可自带私有 dataComponents);② 纯数据驱动自定义数据组件 staticObjectComponents(一份数据一个组件、数据进事件出,供业务组件 DSL 槽位按名选用)',
|
|
227
|
+
);
|
|
228
|
+
}
|
|
214
229
|
const allow = new Set(options.overrides ?? []);
|
|
215
230
|
const builtinBase = new Set<string>(Object.keys(KIT_BASE_COMPONENTS));
|
|
216
231
|
const baseComponents: KitAppRegistry['baseComponents'] = {};
|
|
@@ -219,7 +234,7 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
219
234
|
if (builtinBase.has(name) && !allow.has(name)) kitFail('KIT-APP-007', `baseComponents.${name}`, `基础组件 "${name}" 已内置;要覆盖请在 overrides 点名`, `换一个 App 开头的新名字,或在 defineKitApp 的 overrides 里加入 "${name}"`);
|
|
220
235
|
const def = instantiate(name, input);
|
|
221
236
|
if (def.contract['layer'] !== 'basic') kitFail('KIT-APP-006', `baseComponents.${name}`, `应用基础组件 ${name} 的契约 layer 必须是 basic`, '契约 layer 改为 basic;业务含数据的组件请登记到 staticObjectComponents');
|
|
222
|
-
assertSinglePathComponent(name, def);
|
|
237
|
+
assertSinglePathComponent(name, def, { strictBizOnly: !allowLab });
|
|
223
238
|
baseComponents[name] = def;
|
|
224
239
|
}
|
|
225
240
|
|
|
@@ -233,7 +248,7 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
233
248
|
const spec = isSpec(input);
|
|
234
249
|
const def = instantiate(name, spec ? input.define : input);
|
|
235
250
|
if (def.contract['layer'] !== 'data') kitFail('KIT-APP-006', `staticObjectComponents.${name}`, `应用数据组件 ${name} 的契约 layer 必须是 data`, '契约 layer 改为 data;纯展示小件请登记到 baseComponents');
|
|
236
|
-
assertSinglePathComponent(name, def);
|
|
251
|
+
assertSinglePathComponent(name, def, { strictBizOnly: !allowLab });
|
|
237
252
|
staticComponents[name] = spec ? { definition: def, accept: input.accept } : { definition: def };
|
|
238
253
|
}
|
|
239
254
|
|
|
@@ -285,12 +300,62 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
285
300
|
}
|
|
286
301
|
}
|
|
287
302
|
|
|
288
|
-
// 业务组件 / 页面框与内置同名:必须在 overrides 点名,不静默覆盖;登记名必须等于定义的 kind
|
|
303
|
+
// 业务组件 / 页面框与内置同名:必须在 overrides 点名,不静默覆盖;登记名必须等于定义的 kind,且必须经 defineKitBizComponent 构造
|
|
304
|
+
const bizDataComponentsMap: Record<string, SomaComponentDefinition> = {};
|
|
305
|
+
const bizCandidates: string[] = [];
|
|
306
|
+
const builtinBizData = new Set<string>(Object.keys(KIT_BIZ_DATA_COMPONENTS));
|
|
289
307
|
for (const [name, def] of Object.entries(options.bizComponents ?? {})) {
|
|
290
308
|
if (def === null || typeof def !== 'object' || def.kind !== name) kitFail('KIT-APP-009', `bizComponents.${name}`, `业务组件登记名 "${name}" 与定义的 kind 不一致`, '登记名必须等于定义的 kind');
|
|
309
|
+
if (!isDefinedKitBizComponent(def)) {
|
|
310
|
+
kitFail(
|
|
311
|
+
'KIT-APP-019',
|
|
312
|
+
`bizComponents.${name}`,
|
|
313
|
+
`业务组件 "${name}" 未通过 defineKitBizComponent(...) 构造,禁止以裸对象绕过业务组件契约`,
|
|
314
|
+
'使用 defineKitBizComponent({ kind, roles, areas, dataComponents?, candidates?, compile }) 定义后再登记至 bizComponents',
|
|
315
|
+
);
|
|
316
|
+
}
|
|
291
317
|
if (KIT_BIZ_COMPONENT_NAMES.includes(name) && !allow.has(name)) {
|
|
292
318
|
kitFail('KIT-APP-007', `bizComponents.${name}`, `业务组件 "${name}" 已内置;要覆盖请在 overrides 点名`, `换一个新名字,或在 defineKitApp 的 overrides 里加入 "${name}"`);
|
|
293
319
|
}
|
|
320
|
+
for (const [compName, compInput] of Object.entries(def.dataComponents ?? {})) {
|
|
321
|
+
if (
|
|
322
|
+
builtinBase.has(compName)
|
|
323
|
+
|| KIT_STATIC_BUILTIN_NAMES.includes(compName)
|
|
324
|
+
|| KIT_BIZ_COMPONENT_NAMES.includes(compName)
|
|
325
|
+
|| builtinBizData.has(compName)
|
|
326
|
+
|| compName in baseComponents
|
|
327
|
+
|| compName in staticComponents
|
|
328
|
+
|| compName in bizDataComponentsMap
|
|
329
|
+
) {
|
|
330
|
+
kitFail(
|
|
331
|
+
'KIT-APP-007',
|
|
332
|
+
`bizComponents.${name}.dataComponents.${compName}`,
|
|
333
|
+
`业务组件 ${name} 的私有协作数据组件 "${compName}" 与内置或已登记组件重名`,
|
|
334
|
+
`为 ${name} 的私有协作组件更换唯一不冲突的名称`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
const compDef = instantiate(compName, compInput);
|
|
338
|
+
if (compDef.contract['layer'] !== 'data') {
|
|
339
|
+
kitFail(
|
|
340
|
+
'KIT-APP-006',
|
|
341
|
+
`bizComponents.${name}.dataComponents.${compName}`,
|
|
342
|
+
`业务组件 ${name} 的私有协作数据组件 ${compName} 的契约 layer 必须是 data`,
|
|
343
|
+
'契约 layer 改为 data;业务组件私有交互内核须通过 data 层组件承接业务数据',
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
assertSinglePathComponent(compName, compDef, { strictBizOnly: !allowLab });
|
|
347
|
+
bizDataComponentsMap[compName] = compDef;
|
|
348
|
+
}
|
|
349
|
+
for (const rawCand of def.candidates ?? []) {
|
|
350
|
+
for (const tok of rawCand.split(/\s+/)) {
|
|
351
|
+
if (tok === '') continue;
|
|
352
|
+
const bad = checkClasses(tok, `bizComponents.${name}.candidates`);
|
|
353
|
+
if (bad.length > 0) {
|
|
354
|
+
kitFail('KIT-COMP-003', `bizComponents.${name}.candidates`, `业务组件 ${name} 的候选类 "${tok}" 非法:${bad[0]!.message}`, '候选类只能用刻度内的 Tailwind 类,不写方括号任意值');
|
|
355
|
+
}
|
|
356
|
+
bizCandidates.push(tok);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
294
359
|
}
|
|
295
360
|
for (const [name, def] of Object.entries(options.frames ?? {})) {
|
|
296
361
|
if (def === null || typeof def !== 'object' || def.kind !== name) kitFail('KIT-APP-009', `frames.${name}`, `页面框登记名 "${name}" 与定义的 kind 不一致`, '登记名必须等于定义的 kind');
|
|
@@ -300,9 +365,9 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
300
365
|
}
|
|
301
366
|
const bizComponents: Record<string, KitBizDefinition> = { ...(options.bizComponents ?? {}) };
|
|
302
367
|
const packDataComponents: Record<string, SomaComponentDefinition> = {};
|
|
303
|
-
const candidates = new Set<string>(options.appCandidates ?? []);
|
|
368
|
+
const candidates = new Set<string>([...(options.appCandidates ?? []), ...bizCandidates]);
|
|
304
369
|
const packNames: string[] = [];
|
|
305
|
-
mergePacks(options.packs ?? [], { baseComponents, staticComponents, bizComponents, packDataComponents, candidates, packNames });
|
|
370
|
+
mergePacks(options.packs ?? [], { baseComponents, staticComponents, bizComponents, bizDataComponents: bizDataComponentsMap, packDataComponents, candidates, packNames });
|
|
306
371
|
|
|
307
372
|
return {
|
|
308
373
|
baseComponents,
|
|
@@ -312,7 +377,8 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
312
377
|
viewInfos,
|
|
313
378
|
bizComponents,
|
|
314
379
|
frames: { ...(options.frames ?? {}) },
|
|
315
|
-
appCandidates: options.packs !== undefined && options.packs.length > 0 ? [...candidates] : (options.appCandidates ?? []),
|
|
380
|
+
appCandidates: (options.packs !== undefined && options.packs.length > 0) || bizCandidates.length > 0 ? [...candidates] : (options.appCandidates ?? []),
|
|
381
|
+
bizDataComponents: bizDataComponentsMap,
|
|
316
382
|
packDataComponents,
|
|
317
383
|
packNames,
|
|
318
384
|
appEnvelope,
|
|
@@ -323,6 +389,7 @@ interface PackMergeTarget {
|
|
|
323
389
|
baseComponents: KitAppRegistry['baseComponents'];
|
|
324
390
|
staticComponents: KitAppRegistry['staticComponents'];
|
|
325
391
|
bizComponents: Record<string, KitBizDefinition>;
|
|
392
|
+
bizDataComponents: Record<string, SomaComponentDefinition>;
|
|
326
393
|
packDataComponents: Record<string, SomaComponentDefinition>;
|
|
327
394
|
candidates: Set<string>;
|
|
328
395
|
packNames: string[];
|
|
@@ -344,6 +411,7 @@ function mergePacks(packs: readonly KitPack[], t: PackMergeTarget): void {
|
|
|
344
411
|
for (const n of Object.keys(t.baseComponents)) taken.set(n, '应用基础组件');
|
|
345
412
|
for (const n of Object.keys(t.staticComponents)) taken.set(n, '应用数据组件');
|
|
346
413
|
for (const n of Object.keys(t.bizComponents)) taken.set(n, '应用业务组件');
|
|
414
|
+
for (const n of Object.keys(t.bizDataComponents)) taken.set(n, '业务组件私有协作数据组件');
|
|
347
415
|
|
|
348
416
|
const claim = (name: string, path: string, who: string): boolean => {
|
|
349
417
|
const prev = taken.get(name);
|
|
@@ -410,6 +478,7 @@ export function buildBrowserMount(registry: KitAppRegistry): KitBrowserMount {
|
|
|
410
478
|
// 业务组件壳与页面框层依赖的协作常驻组件与内置数据组件同表;内置名不与应用名冲突(应用名须 App 开头)
|
|
411
479
|
const components: Record<string, SomaComponentDefinition> = { ...base, ...data, ...createKitFrameResidentComponents(), ...bizDataComponents() };
|
|
412
480
|
for (const [name, entry] of Object.entries(registry.staticComponents)) components[name] = entry.definition;
|
|
481
|
+
for (const [name, def] of Object.entries(registry.bizDataComponents)) components[name] = def;
|
|
413
482
|
for (const [name, def] of Object.entries(registry.packDataComponents)) components[name] = def;
|
|
414
483
|
// 应用登记项同名覆盖内置时,常驻表优先(core 以 components 为准),不再按需加载内置版
|
|
415
484
|
return { components, lazyComponents: { ...KIT_STATIC_LAZY_LOADERS }, actions: { ...registry.actions }, pageRoots: { ...registry.views } };
|
package/src/app/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type {
|
|
|
10
10
|
export { defineKitPack, KitPackError, packPrefix } from './define-kit-pack';
|
|
11
11
|
export { defineKitView } from './define-kit-view';
|
|
12
12
|
export type { KitViewClass, KitViewDefinition } from './define-kit-view';
|
|
13
|
-
export type { KitViewHttp, KitViewContext, KitFormHandle, KitFormHandleSlot, KitFormChange, KitRequestDone, KitViewConfirmOptions, KitViewPromptSpec } from './kit-view-context';
|
|
13
|
+
export type { KitViewHttp, KitViewContext, KitFormHandle, KitFormHandleSlot, KitFormChange, KitRequestDone, KitViewConfirmOptions, KitViewPromptSpec, KitOpenOverlayOptions } from './kit-view-context';
|
|
14
14
|
export type { KitPack, KitPackInput, KitPackStaticComponent } from './define-kit-pack';
|
|
15
15
|
/** 应用组件契约顶层 selfReport 段(编译期静态自报声明)的形状:页面线据它补登应用组件的组件部件、宿主、自管布局与取色事实 */
|
|
16
16
|
export type { KitComponentSelfDecl } from '../spatial/self-report';
|
|
@@ -50,6 +50,9 @@ export type { ComposeKitAppsOptions } from './compose-apps';
|
|
|
50
50
|
|
|
51
51
|
// 应用自定义业务组件 / 页面框所需的公开类型与函数(K1-4)
|
|
52
52
|
export { defineKitBizComponent } from '../biz/define';
|
|
53
|
+
// 应用业务组件的版式契约(defineKitBizComponent({ layoutContract: kitLayoutContract({...}) }),消除「没有版式契约」类 KIT-PAGE-GATE-006)
|
|
54
|
+
export { kitLayoutContract, kitLayoutContractProblems } from '../biz/layout-contracts';
|
|
55
|
+
export type { KitBizLayoutContract, KitLayoutContractInput, KitRoleLayout } from '../biz/layout-contracts';
|
|
53
56
|
export { wrapKitBizComponent, composeKitBizComponents } from '../biz/compose';
|
|
54
57
|
export type { WrapBizOptions, WrapBizShellContext, ComposeBizPart, ComposeBizOptions, ComposeBizShellContext } from '../biz/compose';
|
|
55
58
|
export { wrapKitDataComponent, composeKitDataComponents, mapKeys } from '../data/wrap';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// 仓内内部实验室豁免判定(内部私有模块,严禁从 soma-kit/app 或 package.json#exports 导出)。
|
|
2
|
+
//
|
|
3
|
+
// 安全闭环:
|
|
4
|
+
// 1. 仓内单测通过 withInternalLabMode(options) 将夹具对象登记进进程内私有 WeakSet,外部代码拿不到该函数;
|
|
5
|
+
// 2. 仓内视觉实验室 soma-kit-demo 需跨浏览器与服务端双面运行且不能深导入 soma-kit/src/**,
|
|
6
|
+
// 故在其 defineKitApp 选项上标注非公开符号 KIT_INTERNAL_DEMO_MARK;
|
|
7
|
+
// 3. 服务端 assembleKitServer 必须调用 verifyInternalLabRoot 对该符号做目录物理验真
|
|
8
|
+
// (package.json 的 name === 'soma-kit-demo'、private === true 且同级存在 ../soma-kit/spec/kit-grammar.json),
|
|
9
|
+
// 且非真实验室应用的源码 AST 门禁(KIT-APP-018)直接拦截 Symbol.for('soma-kit.*') 字面量,外部应用 0 绕过口。
|
|
10
|
+
//
|
|
11
|
+
// 注意:本模块会被 define-kit-app.ts 静态引入(进浏览器包),顶层严禁静态 import node:* 或 typescript。
|
|
12
|
+
|
|
13
|
+
import type { DefineKitAppOptions } from './define-kit-app';
|
|
14
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
15
|
+
|
|
16
|
+
const INTERNAL_LAB_OPTIONS = new WeakSet<object>();
|
|
17
|
+
|
|
18
|
+
/** 仓内视觉实验室(soma-kit-demo)专用内部标记;外部应用伪造将被服务端物理验真与 AST 门禁双杀(KIT-APP-018) */
|
|
19
|
+
export const KIT_INTERNAL_DEMO_MARK = Symbol.for('soma-kit.internal.monorepo-demo');
|
|
20
|
+
|
|
21
|
+
/** 仅限 soma-kit 仓内单测使用:标记测试夹具选项处于内部实验室模式(走私有 WeakSet,不泄漏公开字段) */
|
|
22
|
+
export function withInternalLabMode<T extends DefineKitAppOptions>(options: T): T {
|
|
23
|
+
INTERNAL_LAB_OPTIONS.add(options);
|
|
24
|
+
return options;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 判定选项是否通过仓内私有 WeakSet 登记为内部实验室测试夹具 */
|
|
28
|
+
export function isInternalLabOptions(options: unknown): boolean {
|
|
29
|
+
return typeof options === 'object' && options !== null && INTERNAL_LAB_OPTIONS.has(options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 判定选项对象是否携带仓内演示应用标记(浏览器期只作形态判断,服务端必须经 verifyInternalLabRoot 物理验真) */
|
|
33
|
+
export function hasInternalDemoMark(options: unknown): boolean {
|
|
34
|
+
return typeof options === 'object' && options !== null && (options as Record<symbol, unknown>)[KIT_INTERNAL_DEMO_MARK] === true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 浏览器/同步装配期快速判断(WeakSet 测试夹具或带仓内演示标记);最终可信裁决由服务端 verifyInternalLabRoot 做出 */
|
|
38
|
+
export function hasInternalLabMark(options: unknown): boolean {
|
|
39
|
+
return isInternalLabOptions(options) || hasInternalDemoMark(options);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 服务端物理验真:仅当 root 确系本仓库同级 soma-kit-demo 时返回 true */
|
|
43
|
+
export async function isMonorepoKitDemoRoot(
|
|
44
|
+
root: string,
|
|
45
|
+
fs: typeof import('node:fs/promises'),
|
|
46
|
+
path: typeof import('node:path'),
|
|
47
|
+
): Promise<boolean> {
|
|
48
|
+
try {
|
|
49
|
+
const pkgText = await fs.readFile(path.join(root, 'package.json'), 'utf8');
|
|
50
|
+
const pkg = JSON.parse(pkgText) as { name?: unknown; private?: unknown };
|
|
51
|
+
if (pkg.name !== 'soma-kit-demo' || pkg.private !== true) return false;
|
|
52
|
+
const siblingGrammar = path.resolve(root, '..', 'soma-kit', 'spec', 'kit-grammar.json');
|
|
53
|
+
await fs.access(siblingGrammar);
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 服务端实验室身份物理验真:
|
|
62
|
+
* - WeakSet 登记的仓内单测夹具直接放行;
|
|
63
|
+
* - 携带 KIT_INTERNAL_DEMO_MARK 的应用必须通过 soma-kit-demo 物理目录验真,伪造即产出 KIT-APP-018 硬诊断并取消豁免。
|
|
64
|
+
*/
|
|
65
|
+
export async function verifyInternalLabRoot(
|
|
66
|
+
root: string,
|
|
67
|
+
options: unknown,
|
|
68
|
+
fs: typeof import('node:fs/promises'),
|
|
69
|
+
path: typeof import('node:path'),
|
|
70
|
+
): Promise<{ readonly internalLab: boolean; readonly diagnostics: KitDiagnostic[] }> {
|
|
71
|
+
if (isInternalLabOptions(options)) {
|
|
72
|
+
return { internalLab: true, diagnostics: [] };
|
|
73
|
+
}
|
|
74
|
+
if (hasInternalDemoMark(options)) {
|
|
75
|
+
const ok = await isMonorepoKitDemoRoot(root, fs, path);
|
|
76
|
+
if (ok) return { internalLab: true, diagnostics: [] };
|
|
77
|
+
return {
|
|
78
|
+
internalLab: false,
|
|
79
|
+
diagnostics: [
|
|
80
|
+
{
|
|
81
|
+
code: 'KIT-APP-018',
|
|
82
|
+
path: 'soma.app.ts',
|
|
83
|
+
message: '检测到非框架内部实验室应用伪造内部实验室符号(Symbol.for("soma-kit.internal.monorepo-demo")),已拒绝豁免',
|
|
84
|
+
hint: '移除伪造的内部符号标记,并将自定义界面封装为标准业务组件(defineKitBizComponent + bizComponents)',
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return { internalLab: false, diagnostics: [] };
|
|
90
|
+
}
|
|
@@ -18,7 +18,7 @@ import { KIT_ACT_SCOPE, requestSemanticName } from '../object-renderer/request-a
|
|
|
18
18
|
import type { KitRequestSpec } from '../object-renderer/request-actions';
|
|
19
19
|
import { KIT_GRAMMAR } from '../object-renderer/defaults';
|
|
20
20
|
import { getKitAppEnvelope, unwrapEnvelope, type KitEnvelope } from '../shared/envelope';
|
|
21
|
-
import { kitActionExtras, openKitHubCreate, type KitNotifyTone } from '../biz/shared/runtime-hub';
|
|
21
|
+
import { closeKitHubOverlay, kitActionExtras, openKitHubCreate, openKitHubOverlay, type KitNotifyTone } from '../biz/shared/runtime-hub';
|
|
22
22
|
import { runtimeNoticeText } from '../object-renderer/form-notify';
|
|
23
23
|
import { askKitConfirm, type KitConfirmOptions } from '../data/confirm-dialog';
|
|
24
24
|
import { askKitPrompt, type KitPromptOptions } from '../data/prompt-dialog';
|
|
@@ -48,6 +48,11 @@ export interface KitFormHandle {
|
|
|
48
48
|
/** 草稿快照(未挂载 {}) */
|
|
49
49
|
values(): Record<string, unknown>;
|
|
50
50
|
dirty(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 放弃这张表单的未保存修改,还原到当前初值(与用户确认「放弃修改」同一条通道:不清详情、不重发请求);表单未挂载 / 筛选栏返回 false。
|
|
53
|
+
* 浮层写了 draft: keep 时,草稿保留到提交成功或显式放弃——本方法就是显式放弃之一(另一个是 ctx.closeOverlay(名, { discard: true }))
|
|
54
|
+
*/
|
|
55
|
+
discard(): boolean;
|
|
51
56
|
/** 本表单所属页面的有效业务信封(表单 prop 编译期带入;未挂载 / 未声明为 undefined) */
|
|
52
57
|
envelope(): KitEnvelope | undefined;
|
|
53
58
|
/** 写草稿字段值(与用户输入同一条通道:即时校验、draft_change、重绘);表单未挂载 / 字段不在草稿里返回 false */
|
|
@@ -82,6 +87,14 @@ export type KitViewConfirmOptions = Omit<KitConfirmOptions, 'message' | 'at' | '
|
|
|
82
87
|
/** ctx.prompt 的声明(同 askKitPrompt,去掉调用方元素 / 中止信号 / 无 DOM 结果) */
|
|
83
88
|
export type KitViewPromptSpec = Omit<KitPromptOptions, 'at' | 'signal' | 'whenNoDom'>;
|
|
84
89
|
|
|
90
|
+
/** ctx.openOverlay 的选项 */
|
|
91
|
+
export interface KitOpenOverlayOptions {
|
|
92
|
+
/** 以这一行打开(浮层表单按编辑、读接口带该行主键);不给 = 无行打开(表单按新建) */
|
|
93
|
+
readonly row?: Readonly<Record<string, unknown>>;
|
|
94
|
+
/** 无行打开时的初值(盖在组件级预填之上;给了 row 时忽略) */
|
|
95
|
+
readonly values?: Readonly<Record<string, unknown>>;
|
|
96
|
+
}
|
|
97
|
+
|
|
85
98
|
/** ctx.notify 的语气闭集 */
|
|
86
99
|
export const KIT_VIEW_NOTIFY_TONES: readonly KitNotifyTone[] = Object.freeze(['info', 'success', 'warning', 'danger']);
|
|
87
100
|
|
|
@@ -116,7 +129,7 @@ export interface KitViewContext extends SomaViewContext {
|
|
|
116
129
|
/**
|
|
117
130
|
* 某个对象的表单句柄;第二参 `slot` 选这个对象的哪个可编辑视图:缺省 `'form'`(编辑表单),`'filter'` 是筛选栏草稿(同样的 values / set / onChange / onField;
|
|
118
131
|
* 与 `ctx.view(对象, 'filter')` 同一个槽名与同一个锚点,对象既有 form 又有 filter 时靠它区分)。筛选栏的字段项写 `options: view.<成员>` 后,
|
|
119
|
-
* 展示对象在 `onField` 里取数并整体替换引用写入成员、用 `set(下级, '')` 清下级值,与 form 同一套写法。对象名契约(ctx.form / data / reload / request / openCreate / cascadeOptions / watchDraftFlag / debouncedReload 通用;ctx.onOutcome 写对象名时指这个对象表单的写入结果):
|
|
132
|
+
* 展示对象在 `onField` 里取数并整体替换引用写入成员、用 `set(下级, '')` 清下级值,与 form 同一套写法。对象名契约(ctx.form / data / reload / request / openCreate / openOverlay / closeOverlay / cascadeOptions / watchDraftFlag / debouncedReload 通用;ctx.onOutcome 写对象名时指这个对象表单的写入结果):
|
|
120
133
|
* 页面里声明的对象名(YAML 里写的键,如 `config`、`entity`;弹窗表单也用同一个名字),整页有多个同名对象(如两个页签都有 `entity`)时写限定名 `<页签 id>.<对象名>`
|
|
121
134
|
* (如 `instances.entity`);运行期名(`instances_entity`、`register_step_config`)向后兼容、原样放行。解析与 `soma kit check` 同源(biz/shared/object-aliases.ts)。
|
|
122
135
|
*/
|
|
@@ -174,6 +187,18 @@ export interface KitViewContext extends SomaViewContext {
|
|
|
174
187
|
* 触发它的按钮写 `submit: view.<方法>`(动作事件绑展示对象方法),方法里调 `ctx.openCreate(对象, 初值)`。
|
|
175
188
|
*/
|
|
176
189
|
openCreate(object: string, values?: Readonly<Record<string, unknown>>): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* 打开本页声明的浮层(product.objects.overlays.<名> 或页面级 page.overlays.<名>;只读、表单、数据组件内容都可以):
|
|
192
|
+
* 给 `row` 以该行打开(表单按编辑、读接口带该行主键),不给按无行打开(表单按新建,`values` 为初值,盖在组件级预填之上)。
|
|
193
|
+
* 与 `builtin: openOverlay` 同一条通道(焦点、层栈、草稿规则、提交后关窗都一样)。名字按对象名契约解析(声明名 / 限定名 <页签 id 或槽名>.<名>,
|
|
194
|
+
* 页面级浮层的限定名是 `kit_page.<名>` / 运行期名);名字不是本页浮层、所属协调组件没装上、或浮层正在提交返回 false(`soma kit check` 报 KIT-VIEW-013)
|
|
195
|
+
*/
|
|
196
|
+
openOverlay(name: string, options?: KitOpenOverlayOptions): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* 关闭这个浮层(它此刻打开着才有效,否则返回 false):缺省等同用户点「取消」(draft: discard 有未保存修改先问;draft: keep 不问、保留草稿);
|
|
199
|
+
* `{ discard: true }` 不问并放弃草稿(含 draft: keep 保留的)
|
|
200
|
+
*/
|
|
201
|
+
closeOverlay(name: string, options?: { readonly discard?: boolean }): boolean;
|
|
177
202
|
/**
|
|
178
203
|
* kit 自绘确认对话框(取代浏览器原生 confirm;全 kit 同一份实现,焦点陷阱 / Esc / 回焦由浮层端口管):
|
|
179
204
|
* 确认 = true,取消 / Esc / 点遮罩 = false。页面卸载时对话框随之关闭并 resolve(false)。
|
|
@@ -265,6 +290,11 @@ function formHandle(ctx: SomaViewContext, object: string, slot: KitFormHandleSlo
|
|
|
265
290
|
return raw ?? {};
|
|
266
291
|
},
|
|
267
292
|
dirty: () => comp?.call<boolean>('dirty') === true,
|
|
293
|
+
discard: () => {
|
|
294
|
+
const raw = comp?.call<boolean>('discard');
|
|
295
|
+
if (raw === undefined) warnMissing();
|
|
296
|
+
return raw === true;
|
|
297
|
+
},
|
|
268
298
|
envelope: () => comp?.call<KitEnvelope | undefined>('envelope') ?? undefined,
|
|
269
299
|
set: (field, value) => {
|
|
270
300
|
const raw = comp?.call<boolean>('set', field, value);
|
|
@@ -358,6 +388,18 @@ export function extendKitViewContext(ctx: SomaViewContext, viewName?: string): K
|
|
|
358
388
|
} },
|
|
359
389
|
openCreate: { value: (object: string, values: Readonly<Record<string, unknown>> = {}): boolean =>
|
|
360
390
|
typeof object === 'string' && object.trim() !== '' && openKitHubCreate(nameOf(object, 'openCreate'), { ...values }) },
|
|
391
|
+
openOverlay: { value: (name: string, options: KitOpenOverlayOptions = {}): boolean => {
|
|
392
|
+
if (typeof name !== 'string' || name.trim() === '') return false;
|
|
393
|
+
const ok = openKitHubOverlay(nameOf(name, 'openOverlay'), options.row !== undefined
|
|
394
|
+
? { row: { ...options.row } }
|
|
395
|
+
: { ...(options.values !== undefined ? { values: { ...options.values } } : {}) });
|
|
396
|
+
if (!ok && isDevEnv()) console.warn(`[soma-kit][view] ctx.openOverlay("${name}") 没有打开:名字不是本页声明的浮层、所属业务组件未装上,或浮层正在提交`);
|
|
397
|
+
return ok;
|
|
398
|
+
} },
|
|
399
|
+
closeOverlay: { value: (name: string, options: { readonly discard?: boolean } = {}): boolean => {
|
|
400
|
+
if (typeof name !== 'string' || name.trim() === '') return false;
|
|
401
|
+
return closeKitHubOverlay(nameOf(name, 'closeOverlay'), options.discard === true ? { discard: true } : {});
|
|
402
|
+
} },
|
|
361
403
|
data: { value: <T = unknown>(name: string): SomaViewDataHandle<T> => ctx.data<T>(nameOf(name, 'data')) },
|
|
362
404
|
reload: { value: (names?: readonly string[]): Promise<void> => ctx.reload(namesOf(names, 'reload')) },
|
|
363
405
|
confirm: { value: (message: string, options: KitViewConfirmOptions = {}): Promise<boolean> =>
|
package/src/app/server.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { kitThemeShardUsageOfPage, mergeKitThemeShardUsage, sameKitThemeShardUsa
|
|
|
28
28
|
import type { KitThemeUsage } from '../shared/theme-usage';
|
|
29
29
|
import { parseAppConfig, checkRemovedThemeKeys, migrateKitRuntimeTheme, parseKitTheme, type KitAppTheme } from './app-config';
|
|
30
30
|
import { scanAppComponentSources } from './component-gate';
|
|
31
|
+
import { verifyInternalLabRoot } from './internal-lab';
|
|
31
32
|
import { handleKitThemeRequest } from './theme-endpoint';
|
|
32
33
|
import type { DefineKitAppOptions, KitAppRegistry } from './define-kit-app';
|
|
33
34
|
import { KIT_PAGE_OWNER, KIT_TIER_FACTS_MISSING, createKitServerPages, kitRuntimePageFactsOfVersion, type KitRuntimePageFacts, type KitRuntimePagePlan } from './server-pages';
|
|
@@ -743,17 +744,48 @@ export async function assembleKitServer(options: DefineKitAppOptions, registry:
|
|
|
743
744
|
const path = await nodePath();
|
|
744
745
|
const fs = await nodeFs();
|
|
745
746
|
const root = await resolveKitAppRoot(options.root, path);
|
|
747
|
+
const labCheck = await verifyInternalLabRoot(root, options, fs, path);
|
|
748
|
+
const internalLab = labCheck.internalLab;
|
|
746
749
|
|
|
747
750
|
// 1 kit.app.yaml
|
|
748
751
|
const appFile = path.join(root, options.app ?? 'kit.app.yaml');
|
|
749
752
|
const appText = await readIfExists(appFile);
|
|
750
|
-
const diagnostics: KitDiagnostic[] = [];
|
|
753
|
+
const diagnostics: KitDiagnostic[] = [...labCheck.diagnostics];
|
|
751
754
|
const parsedAppYaml = appText === undefined ? undefined : await parseYaml(appText, 'kit.app.yaml', diagnostics);
|
|
752
755
|
const config = parseAppConfig(parsedAppYaml, diagnostics);
|
|
753
756
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
+
if (!internalLab) {
|
|
758
|
+
for (const name of Object.keys(options.baseComponents ?? {})) {
|
|
759
|
+
diagnostics.push({
|
|
760
|
+
code: 'KIT-APP-016',
|
|
761
|
+
path: `baseComponents.${name}`,
|
|
762
|
+
message: `禁止业务应用注册非业务/非数据的野生基础组件 ${name}(baseComponents);基础控件一律复用框架官方闭集`,
|
|
763
|
+
hint: '改用 bizComponents(defineKitBizComponent,可自带私有 dataComponents)或纯数据驱动自定义数据组件 staticObjectComponents',
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
for (const name of Object.keys(config.baseComponents)) {
|
|
767
|
+
diagnostics.push({
|
|
768
|
+
code: 'KIT-APP-016',
|
|
769
|
+
path: `kit.app.yaml.baseComponents.${name}`,
|
|
770
|
+
message: `禁止在 kit.app.yaml 中声明非业务/非数据的野生基础组件 ${name}(baseComponents);基础控件一律复用框架官方闭集`,
|
|
771
|
+
hint: '删除 kit.app.yaml#baseComponents,改用业务组件 bizComponents 或纯数据驱动数据组件 staticObjectComponents',
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
if (config.style !== undefined) {
|
|
775
|
+
diagnostics.push({
|
|
776
|
+
code: 'KIT-APP-017',
|
|
777
|
+
path: 'kit.app.yaml.style',
|
|
778
|
+
message: `禁止在 kit.app.yaml 中通过 style: "${config.style}" 引入野生样式表;样式必须由框架主题求解引擎统一生成`,
|
|
779
|
+
hint: '删除 kit.app.yaml#style,改用 kit.app.yaml#theme 14 维主题 DSL 声明配色、字阶、圆角与层次',
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// 2 与代码登记对账(两边都要有;非实验室应用的 baseComponents 已由 KIT-APP-016 拒收,staticObjectComponents 照常对账)
|
|
785
|
+
if (internalLab) {
|
|
786
|
+
for (const name of Object.keys(config.baseComponents)) {
|
|
787
|
+
if (!(name in registry.baseComponents)) diagnostics.push({ code: 'KIT-APP-001', path: `baseComponents.${name}`, message: `kit.app.yaml 登记了基础组件 ${name},soma.app.ts 没有提供实现` });
|
|
788
|
+
}
|
|
757
789
|
}
|
|
758
790
|
// 只在代码里登记(kit.app.yaml#baseComponents 没有条目):不报错,按代码登记即可(不往配置对象里写东西)
|
|
759
791
|
const staticContracts: Record<string, { accept: 'single' | 'list'; emits: readonly string[]; props: readonly string[]; propTypes: Readonly<Record<string, string>>; composition?: KitCompositionRole }> = {};
|
|
@@ -777,12 +809,21 @@ export async function assembleKitServer(options: DefineKitAppOptions, registry:
|
|
|
777
809
|
staticContracts[name] = { accept, emits: Object.keys(entry.definition.contract.emits ?? {}), props: Object.keys(entry.definition.contract.props ?? {}), propTypes: staticPropTypesOf(entry.definition), ...(role !== undefined ? { composition: role } : {}) };
|
|
778
810
|
}
|
|
779
811
|
}
|
|
780
|
-
const sourceGateDiagnostics = await scanAppComponentSources(root);
|
|
781
|
-
|
|
812
|
+
const sourceGateDiagnostics = await scanAppComponentSources(root, { internalLab });
|
|
813
|
+
// 告警级的源码门禁(KIT-APP-020 命令式浮层原语、KIT-APP-021 展示对象目录裸 fetch):过渡期不挡装配,进弃用提示段(--strict 才算失败)
|
|
814
|
+
const SOURCE_GATE_WARN: ReadonlySet<string> = new Set(['KIT-APP-020', 'KIT-APP-021']);
|
|
815
|
+
diagnostics.push(...sourceGateDiagnostics.filter((d) => !SOURCE_GATE_WARN.has(d.code)));
|
|
816
|
+
const sourceGateAdvisories: KitAdvisory[] = sourceGateDiagnostics
|
|
817
|
+
.filter((d) => SOURCE_GATE_WARN.has(d.code))
|
|
818
|
+
.map((d) => {
|
|
819
|
+
const [file = '', lineText] = d.path.split(':');
|
|
820
|
+
const line = lineText !== undefined ? Number(lineText) : NaN;
|
|
821
|
+
return { code: d.code, severity: 'warn' as const, path: d.path, file, ...(Number.isInteger(line) ? { line } : {}), message: d.message, hint: d.hint ?? '' };
|
|
822
|
+
});
|
|
782
823
|
|
|
783
|
-
// 3
|
|
824
|
+
// 3 主题头(不在此处提前抛错,确保后面页面的编译诊断也能一次收集报全;非实验室应用禁止 kit.app.yaml#style,已报 KIT-APP-017)
|
|
784
825
|
let themeCss = KIT_DEFAULT_THEME_CSS;
|
|
785
|
-
if (config.style !== undefined) {
|
|
826
|
+
if (internalLab && config.style !== undefined) {
|
|
786
827
|
const text = await readIfExists(path.resolve(root, config.style));
|
|
787
828
|
if (text === undefined) {
|
|
788
829
|
diagnostics.push({ code: 'KIT-APP-001', path: 'style', message: `找不到 ${config.style}` });
|
|
@@ -881,6 +922,7 @@ export async function assembleKitServer(options: DefineKitAppOptions, registry:
|
|
|
881
922
|
const componentDefinitions = {
|
|
882
923
|
...registry.baseComponents,
|
|
883
924
|
...Object.fromEntries(Object.entries(registry.staticComponents).map(([n, e]) => [n, e.definition])),
|
|
925
|
+
...registry.bizDataComponents,
|
|
884
926
|
...registry.packDataComponents,
|
|
885
927
|
};
|
|
886
928
|
// 应用组件契约上的静态自报声明 → 页面线的补登表来源(逐组件校验、坏组件隔离告警);没有任何合法声明时不写这个键
|
|
@@ -946,7 +988,7 @@ export async function assembleKitServer(options: DefineKitAppOptions, registry:
|
|
|
946
988
|
const deprecations: KitAdvisory[] = [];
|
|
947
989
|
/** 页面文件 → 界面规则来源记录(每条规则最终生效的命中;只有用到规则的页有) */
|
|
948
990
|
const lookReports = new Map<string, readonly KitLookReportRow[]>();
|
|
949
|
-
deprecations.push(...themeGateAdvisories, ...selfReportAdvisories);
|
|
991
|
+
deprecations.push(...themeGateAdvisories, ...selfReportAdvisories, ...sourceGateAdvisories);
|
|
950
992
|
/** next 下组合核对的输入:页面地址 → 版面事实(编译出的页取 pageAttrs,缓存命中的页取旁记,已登记的运行期提交页取版本号里的事实戳) */
|
|
951
993
|
const tierPages = new Map<string, KitTierCompatFrameFacts>();
|
|
952
994
|
let tierPagesMissing = 0;
|
package/src/biz/compose.ts
CHANGED
|
@@ -12,6 +12,13 @@ import { defineKitBizComponent } from './define';
|
|
|
12
12
|
import { validateBizAreaClass } from './shared/compile-helpers';
|
|
13
13
|
import type { KitBizContext, KitBizDefinition, KitBizEnvelopeTrait, KitBizInput, KitBizRole } from './types';
|
|
14
14
|
import { kitFail } from '../shared/kit-error';
|
|
15
|
+
import { KIT_BIZ_LAYOUT_CONTRACTS, kitLayoutContract, kitLayoutContractProblems, kitRebaseLayoutContract, type KitBizLayoutContract } from './layout-contracts';
|
|
16
|
+
|
|
17
|
+
/** 组件的版式契约来源:内置冻结表优先,其次组件定义上声明的 layoutContract;都没有为 undefined */
|
|
18
|
+
function contractOfDef(def: KitBizDefinition): KitBizLayoutContract | undefined {
|
|
19
|
+
if (Object.hasOwn(KIT_BIZ_LAYOUT_CONTRACTS, def.kind)) return KIT_BIZ_LAYOUT_CONTRACTS[def.kind]!;
|
|
20
|
+
return def.layoutContract ?? undefined;
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
export interface WrapBizShellContext {
|
|
17
24
|
input: KitBizInput;
|
|
@@ -31,6 +38,12 @@ export interface WrapBizOptions {
|
|
|
31
38
|
acceptConfig?: boolean;
|
|
32
39
|
/** 可选:覆写底层业务组件的声明式版心特征;缺省透传 inner.envelope */
|
|
33
40
|
envelope?: KitBizEnvelopeTrait;
|
|
41
|
+
/**
|
|
42
|
+
* 可选:版式契约(规则同 defineKitBizComponent 的 layoutContract,不合法报 KIT-COMP-007)。
|
|
43
|
+
* 缺省继承 inner 的契约(内置冻结表或 inner.layoutContract);roles 被重定义时只在新角色都在旧契约里时继承(按新角色裁剪),
|
|
44
|
+
* 裁剪后不合法(如依附目标被裁掉)则不继承;null = 不声明(取 FREE)
|
|
45
|
+
*/
|
|
46
|
+
layoutContract?: KitBizLayoutContract | null;
|
|
34
47
|
/** 包装层写死的 Tailwind 类串或类名列表(自动校验并并入产物 candidates) */
|
|
35
48
|
candidates?: readonly string[];
|
|
36
49
|
/**
|
|
@@ -61,11 +74,39 @@ export function wrapKitBizComponent(inner: KitBizDefinition, options: WrapBizOpt
|
|
|
61
74
|
}
|
|
62
75
|
|
|
63
76
|
const resolvedEnvelope = options.envelope ?? inner.envelope;
|
|
77
|
+
// 版式契约:显式给了用显式的(定义期校验、不合法抛 KIT-COMP-007);没给则继承 inner 的(角色被重定义时按新角色裁剪),继承结果不合法就不继承(与改前同为 FREE)
|
|
78
|
+
const innerContract = contractOfDef(inner);
|
|
79
|
+
const wrapRoles = options.roles ?? inner.roles;
|
|
80
|
+
let inherited: KitBizLayoutContract | undefined;
|
|
81
|
+
if (innerContract !== undefined) {
|
|
82
|
+
if (options.roles === undefined) {
|
|
83
|
+
inherited = innerContract;
|
|
84
|
+
} else if (Object.keys(wrapRoles).every((r) => Object.hasOwn(innerContract.roles, r))) {
|
|
85
|
+
const keptRoles = Object.freeze(Object.fromEntries(Object.keys(wrapRoles).map((r) => [r, innerContract.roles[r]!])));
|
|
86
|
+
if (innerContract.exclusiveGroups !== undefined) {
|
|
87
|
+
const used = new Set(Object.values(keptRoles).map((r) => r.exclusiveGroup).filter((g): g is string => g !== undefined));
|
|
88
|
+
const filteredEntries = Object.entries(innerContract.exclusiveGroups).filter(([g]) => used.has(g));
|
|
89
|
+
const remainingKinds = filteredEntries.map(([, e]) => e);
|
|
90
|
+
if (filteredEntries.length <= 1 && remainingKinds.includes(innerContract.exclusive)) {
|
|
91
|
+
const { exclusiveGroups: _drop, ...rest } = innerContract;
|
|
92
|
+
inherited = Object.freeze({ ...rest, roles: keptRoles });
|
|
93
|
+
} else {
|
|
94
|
+
inherited = Object.freeze({ ...innerContract, roles: keptRoles, exclusiveGroups: Object.freeze(Object.fromEntries(filteredEntries)) });
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
inherited = Object.freeze({ ...innerContract, roles: keptRoles });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const resolvedContract = options.layoutContract !== undefined
|
|
102
|
+
? options.layoutContract
|
|
103
|
+
: inherited !== undefined && kitLayoutContractProblems(options.kind, wrapRoles, inherited).length === 0 ? inherited : undefined;
|
|
64
104
|
return defineKitBizComponent({
|
|
65
105
|
kind: options.kind,
|
|
66
106
|
roles: options.roles ?? inner.roles,
|
|
67
107
|
areas: allAreas,
|
|
68
108
|
acceptConfig: options.acceptConfig ?? true,
|
|
109
|
+
...(resolvedContract !== undefined ? { layoutContract: resolvedContract } : {}),
|
|
69
110
|
...(resolvedEnvelope !== undefined ? { envelope: resolvedEnvelope } : {}),
|
|
70
111
|
...(resolvedEnvelope === undefined && inner.pageMaxWidth !== undefined ? { pageMaxWidth: inner.pageMaxWidth } : {}),
|
|
71
112
|
compile(input: KitBizInput, ctx: KitBizContext): KitFragment {
|
|
@@ -169,6 +210,12 @@ export interface ComposeBizOptions {
|
|
|
169
210
|
acceptConfig?: boolean;
|
|
170
211
|
/** 复合外壳写死的 Tailwind 类串或类名列表(自动校验并并入 candidates) */
|
|
171
212
|
candidates?: readonly string[];
|
|
213
|
+
/**
|
|
214
|
+
* 可选:版式契约(规则同 defineKitBizComponent 的 layoutContract,不合法报 KIT-COMP-007)。
|
|
215
|
+
* 缺省:只有一个子部件且它有契约时合成——角色按 roleMap 改名、锚点按子部件前缀改写(kitRebaseLayoutContract)、互斥组加子部件前缀、
|
|
216
|
+
* 排法 / 互斥 / 版面事实沿用该子部件;多个子部件时排法与互斥没有确定解,不合成(取 FREE),需要契约请显式给。null = 不声明
|
|
217
|
+
*/
|
|
218
|
+
layoutContract?: KitBizLayoutContract | null;
|
|
172
219
|
/** 将各子部件生成的 HTML(`partHtml[partKey]`)装入写死的复合网格/边框外壳中 */
|
|
173
220
|
renderShell: (partHtml: Record<string, string>, ctx: ComposeBizShellContext) => string;
|
|
174
221
|
}
|
|
@@ -213,6 +260,24 @@ export function composeKitBizComponents(options: ComposeBizOptions): KitBizDefin
|
|
|
213
260
|
const badRoot = checkClasses(baseRootClass, `${options.kind}.rootClass`);
|
|
214
261
|
if (badRoot.length > 0) kitFail('KIT-COMP-003', `${options.kind}.rootClass`, `${options.kind} 的 rootClass 非法:${badRoot[0]!.message}`, 'rootClass 只能用刻度内的 Tailwind 类');
|
|
215
262
|
|
|
263
|
+
// 版式契约:显式给了用显式的;没给且只有一个子部件、它有契约时合成(合成结果不合法就不合成,与改前同为 FREE)
|
|
264
|
+
let composed: KitBizLayoutContract | undefined;
|
|
265
|
+
if (options.layoutContract === undefined && partEntries.length === 1) {
|
|
266
|
+
const [key, p] = partEntries[0]!;
|
|
267
|
+
const c = contractOfDef(p.component);
|
|
268
|
+
if (c !== undefined) {
|
|
269
|
+
const rb = kitRebaseLayoutContract(c, p.roleMap, key);
|
|
270
|
+
const candidate = kitLayoutContract({
|
|
271
|
+
arrange: c.arrange, exclusive: c.exclusive, defaultSelected: c.defaultSelected, roles: rb.roles,
|
|
272
|
+
...(Object.keys(rb.exclusiveGroups).length > 0 ? { exclusiveGroups: rb.exclusiveGroups } : {}),
|
|
273
|
+
...(rb.overlayAnchor !== undefined && p.forwardOverlays === true ? { overlayAnchor: rb.overlayAnchor } : {}),
|
|
274
|
+
frameFacts: { ...c.frameFacts },
|
|
275
|
+
});
|
|
276
|
+
if (kitLayoutContractProblems(options.kind, roles, candidate).length === 0) composed = candidate;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const resolvedContract = options.layoutContract !== undefined ? options.layoutContract : composed;
|
|
280
|
+
|
|
216
281
|
const areas = [...new Set(['root', ...(options.areas ?? [])])];
|
|
217
282
|
const areaSet = new Set<string>(areas);
|
|
218
283
|
const extraTokens = splitCandidateTokens([baseRootClass, ...(options.candidates ?? [])]);
|
|
@@ -226,6 +291,7 @@ export function composeKitBizComponents(options: ComposeBizOptions): KitBizDefin
|
|
|
226
291
|
roles,
|
|
227
292
|
areas,
|
|
228
293
|
acceptConfig: options.acceptConfig ?? true,
|
|
294
|
+
...(resolvedContract !== undefined ? { layoutContract: resolvedContract } : {}),
|
|
229
295
|
compile(input: KitBizInput, ctx: KitBizContext): KitFragment {
|
|
230
296
|
const diagnostics: KitDiagnostic[] = [];
|
|
231
297
|
const areaMap = input.areaClass ?? {};
|