soma-kit 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -46,16 +46,17 @@ import type { KitApp } from '../app/define-kit-app';
|
|
|
46
46
|
import { KitSubmitError } from '../app/submit.types';
|
|
47
47
|
import { compileKitPage } from '../compile/compile-page';
|
|
48
48
|
import { createYamlLocator } from '../compile/locate';
|
|
49
|
-
import { parsePageDecl } from '../compile/parse';
|
|
49
|
+
import { isRecord, parsePageDecl } from '../compile/parse';
|
|
50
50
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
51
|
+
import { KIT_CORE_MAPPING } from '../object-renderer/defaults';
|
|
51
52
|
import { resolveBiz, resolveFrame } from '../compile/registry';
|
|
52
53
|
import type { KitAppContext } from '../compile/types';
|
|
53
|
-
import { aiActionOn, aiTones, KitAiSurfaceError, kitAiDisplayMap, kitAiProductSummary, kitAiWriter, kitDiagnosticText, kitFieldTypes } from './ai-surface';
|
|
54
|
+
import { aiActionOn, aiTones, fieldHintKeys, KitAiSurfaceError, kitAiDisplayMap, kitAiProductSummary, kitAiWriter, kitDiagnosticText, kitFieldTypes, type ApiPurpose } from './ai-surface';
|
|
54
55
|
import { compileKitIntentBlueprint } from './compile';
|
|
55
56
|
import { kitReviseDriftIssues, splitKitReviseScope } from './drift';
|
|
56
57
|
import { checkDisplayMap, checkIntentMap, frameKindOfIntent, kitFrameIntents, kitProductIntents, productKindOfIntent, type KitIntentMapApp } from './intent-map';
|
|
57
58
|
import { blockThemeDomain } from '../theme/block-theme';
|
|
58
|
-
import { kitIntentSchema, parseKitIntentBlueprint, type KitIntentBlueprint } from './intent-schema';
|
|
59
|
+
import { checkIntentSurface, kitIntentSchema, parseKitIntentBlueprint, type KitIntentBlueprint } from './intent-schema';
|
|
59
60
|
import { checkKitWriterSurface } from './writer-policy';
|
|
60
61
|
|
|
61
62
|
/** 语法源文本在 `PageTargetSource.files` 里的路径:kit 页面声明 */
|
|
@@ -64,6 +65,22 @@ export const SOMA_KIT_TARGET_SOURCE_PATH = 'page.kit.yaml';
|
|
|
64
65
|
/** 目标需要的装配面:服务端面 + 浏览器挂载面 + 选项(`defineKitApp` 的返回值满足) */
|
|
65
66
|
export type KitPageTargetApp = Pick<KitApp, 'server' | 'browserMount' | 'options'>;
|
|
66
67
|
|
|
68
|
+
export interface KitCurrentApiAuthorizationRequest {
|
|
69
|
+
readonly url: string;
|
|
70
|
+
readonly caller: PageSubmitOptions['caller'];
|
|
71
|
+
readonly operator?: PageSubmitOptions['operator'];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Host 的当前 API 授权目录;每次提交调用,不接受页面或蓝图提供授权表。 */
|
|
75
|
+
export type KitCurrentApiAuthorizationProvider = (
|
|
76
|
+
request: KitCurrentApiAuthorizationRequest,
|
|
77
|
+
) => readonly PageTargetApi[] | Promise<readonly PageTargetApi[]>;
|
|
78
|
+
|
|
79
|
+
export interface KitPageTargetOptions {
|
|
80
|
+
/** 当前接口授权提供器;省略时含接口引用的提交一律拒绝,无接口页面仍可提交。 */
|
|
81
|
+
readonly currentAuthorizedApis?: KitCurrentApiAuthorizationProvider;
|
|
82
|
+
}
|
|
83
|
+
|
|
67
84
|
/** Host 配置问题(装配不成立 / 意图映射与应用登记对不上 / 语法投影缺失):回喂模型改不了,调用方映射为配置缺失 */
|
|
68
85
|
export class KitTargetAssemblyError extends Error {
|
|
69
86
|
readonly kind: 'failed' | 'intent-map';
|
|
@@ -105,7 +122,6 @@ const FRAME_SUMMARY: Readonly<Record<string, string>> = Object.freeze({
|
|
|
105
122
|
plain: '单栏页面',
|
|
106
123
|
blank: '无页头的空白页面',
|
|
107
124
|
'top-nav': '顶部概览 + 主体',
|
|
108
|
-
split: '左右分栏',
|
|
109
125
|
tabs: '页签页面(每个页签一个页面模式)',
|
|
110
126
|
});
|
|
111
127
|
|
|
@@ -167,7 +183,30 @@ function describeFrameIntent(intent: string, registry: KitIntentMapApp): string
|
|
|
167
183
|
return ` - ${intent}${summary}(${placement})`;
|
|
168
184
|
}
|
|
169
185
|
|
|
170
|
-
|
|
186
|
+
/** 个别对象角色的特殊规则(读真源 aiWriter.roleShape,按意图词.角色名列出) */
|
|
187
|
+
function roleShapeLines(): string[] {
|
|
188
|
+
const shapes = kitAiWriter().roleShape;
|
|
189
|
+
const lines: string[] = [];
|
|
190
|
+
for (const intent of kitProductIntents()) {
|
|
191
|
+
const kind = productKindOfIntent(intent);
|
|
192
|
+
if (kind === undefined || !Object.hasOwn(shapes, kind)) continue;
|
|
193
|
+
for (const [role, shape] of Object.entries(shapes[kind]!)) {
|
|
194
|
+
const parts: string[] = [];
|
|
195
|
+
const channel = shape.channel ?? 'any';
|
|
196
|
+
if (channel === 'read') parts.push('只读展示:api 可选,不写 write_api / delete_api,不挂动作');
|
|
197
|
+
if (channel === 'write') parts.push('只负责提交:须写 write_api,不写 api');
|
|
198
|
+
if (channel === 'free') parts.push('不要求接口(api / write_api 可写可不写)');
|
|
199
|
+
const omit = shape.omit ?? [];
|
|
200
|
+
if (omit.includes('schema')) parts.push('字段字典由模板合并别处,fields 只需随便列一个字段');
|
|
201
|
+
if (omit.includes('behavior')) parts.push('不写 api / write_api / delete_api,字段值读自主记录');
|
|
202
|
+
if (omit.includes('view')) parts.push('界面由模板写死,不写 views');
|
|
203
|
+
if (parts.length > 0) lines.push(` - ${intent}.${role}:${parts.join(';')}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return lines.length === 0 ? [] : ['7) 个别角色的特殊规则:', ...lines];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function composePrompt(registry: KitIntentMapApp, ctx: PageTargetContext, mode: PageTargetMode, locales: readonly string[] | undefined): string {
|
|
171
210
|
const products = kitProductIntents().map((k) => describeProductIntent(k, registry));
|
|
172
211
|
const frames = kitFrameIntents().map((k) => describeFrameIntent(k, registry));
|
|
173
212
|
const w = kitAiWriter();
|
|
@@ -181,16 +220,19 @@ function composePrompt(registry: KitIntentMapApp, ctx: PageTargetContext, mode:
|
|
|
181
220
|
...products,
|
|
182
221
|
'',
|
|
183
222
|
'蓝图结构契约:',
|
|
184
|
-
`1) objects: { "<对象名>": { "
|
|
185
|
-
` 字段 type 只能取:${kitFieldTypes().join(' / ')};type 为 enum 或 enums 时必须给非空 options 数组,其余类型不写 options。每个对象至少要有 api 或 write_api
|
|
223
|
+
`1) objects: { "<对象名>": { "api"?: "<读接口路径>", "write_api"?: "<写接口路径>", "fields": [{ "name": "<字段id>", "label"?: "<显示名>", ${fieldHintKeys().map((k) => `"${k}"?: "<纯文本>"`).join(', ')}, "type": "<类型>", "key"?: true, "required"?: true, "max_len"?: 正整数, "options"?: [{ "value": "...", "label": "...", "tone"?: "${aiTones().join('|')}" }] }] } }。`,
|
|
224
|
+
` 字段 type 只能取:${kitFieldTypes().join(' / ')};type 为 enum 或 enums 时必须给非空 options 数组,其余类型不写 options。每个对象至少要有 api 或 write_api(取自下方授权接口字典;个别角色例外,见第 7 条)。`,
|
|
225
|
+
` 接口按实际发射的方法逐条授权:api 的 from 恒发 GET;字符串 write_api 同时生成 create/${KIT_CORE_MAPPING.writeChannels.create!.method.toUpperCase()} 与 update/${KIT_CORE_MAPPING.writeChannels.update!.method.toUpperCase()},同一路径必须同时授权这两种方法;delete_api 生成 delete/${KIT_CORE_MAPPING.writeChannels.delete!.method.toUpperCase()}。`,
|
|
226
|
+
` 字段的 ${fieldHintKeys().join(' / ')} 是纯文本提示,只显示在 form / filter 视图里的该字段上(list / summary 不显示,字段不在 form / filter 里就不要写)。`,
|
|
186
227
|
'2) roles: 单个对象名角色写 { "<角色名>": "<对象名>" };对象名数组角色写 { "<角色名>": ["<对象名1>", ...] }。',
|
|
187
228
|
'3) views: 单个对象名角色写 { "<角色名>": { "<槽位>": ["<字段name>", ...] } };对象名数组角色写 { "<角色名>": { "<对象名>": { "<槽位>": ["<字段name>", ...] } } }。槽位名只能取该角色允许的槽位,字段名必须存在于对应对象的 fields[].name。声明了 form 槽位的对象必须同时填写 write_api。',
|
|
188
229
|
`4) actions(可选数组): [{ "id": "<英文标识>", "label": "<按钮文字>", "on": "${aiActionOn().join('|')}", "builtin": "${w.actionBuiltins.join('|')}", "tone"?: "${aiTones().join('|')}", "role"?: "<角色名>" }]。`,
|
|
189
230
|
' 硬性配对:openCreate 与 reload 的 on 必须是 "toolbar";openEdit 的 on 必须是 "row"(且该角色须有 list 与 form 视图、对象须有 write_api)。不接具名动作。',
|
|
190
|
-
' 行内删除用 remove(on 写 row,只用于 crud 页面模式):所属对象须另给 delete_api
|
|
231
|
+
' 行内删除用 remove(on 写 row,只用于 crud 页面模式):所属对象须另给 delete_api(取授权接口里方法为 DELETE 的接口;删除以 DELETE 发出,主键由系统拼进查询串);确认弹窗由系统恒加,可用 confirm_text 写一句纯文本确认语(缺省用默认文案;文案里可写 {name} 占位,运行时换成被删条目的标题字段 title / name / label,对象没有这类字段就不要写 {name}),不能关掉确认。',
|
|
191
232
|
'5) 字段可写 display 展示语义词(只对 list / summary 视图生效,须与字段类型匹配):',
|
|
192
233
|
...displayLines(),
|
|
193
234
|
`6) 块级主题 theme(可选):根上写整页内容区的主题,top / tabs[i] 上写该块的主题;只收词条:简写 ${blockThemeDomain().shorthands.join(' / ')},或对象 { mode: 昼夜光感词条, color: 主色意向词条 }(词条见 schema 枚举);外壳与整站主题不归你。`,
|
|
235
|
+
...roleShapeLines(),
|
|
194
236
|
'',
|
|
195
237
|
'授权接口字典:',
|
|
196
238
|
apiDictionaryText(ctx.authorizedApis),
|
|
@@ -204,6 +246,9 @@ function composePrompt(registry: KitIntentMapApp, ctx: PageTargetContext, mode:
|
|
|
204
246
|
} else if (mode === 'preview' || mode === 'visualize') {
|
|
205
247
|
lines.push('', '本次只用于预览:照常输出完整蓝图。');
|
|
206
248
|
}
|
|
249
|
+
if (locales !== undefined && locales.length > 0) {
|
|
250
|
+
lines.push('', `locale(可选)只能取应用支持的语言:${locales.join(' / ')}。`);
|
|
251
|
+
}
|
|
207
252
|
return lines.join('\n');
|
|
208
253
|
}
|
|
209
254
|
|
|
@@ -246,48 +291,150 @@ function aiPersistOf(persist: PageSubmitOptions['persist'], at: string): 'memory
|
|
|
246
291
|
return persist ?? 'runtime';
|
|
247
292
|
}
|
|
248
293
|
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
294
|
+
/** 用途 -> 蓝图键的口语名(诊断文案用) */
|
|
295
|
+
const PURPOSE_TEXT: Readonly<Record<ApiPurpose, string>> = { api: '读接口', write_api: '写接口', delete_api: '删除接口' };
|
|
296
|
+
|
|
297
|
+
interface ApiReference {
|
|
298
|
+
readonly path: string;
|
|
299
|
+
readonly purpose: ApiPurpose;
|
|
300
|
+
readonly at: string;
|
|
301
|
+
/** 源编译后实际发射的 HTTP 方法;写接口字符串展开为 create 与 update 两条引用。 */
|
|
302
|
+
readonly methods: readonly string[];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function sourceApiReferences(source: unknown): ApiReference[] {
|
|
306
|
+
const references: ApiReference[] = [];
|
|
307
|
+
const seen = new Set<object>();
|
|
308
|
+
const endpointRefs = (value: unknown, purpose: ApiPurpose, at: string, out: ApiReference[], methods: readonly string[]): void => {
|
|
309
|
+
if (typeof value === 'string') {
|
|
310
|
+
if (value !== '') out.push({ path: value, purpose, at, methods });
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (Array.isArray(value)) {
|
|
314
|
+
value.forEach((item, index) => endpointRefs(item, purpose, `${at}[${index}]`, out, methods));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!isRecord(value)) return;
|
|
318
|
+
const actualMethods = typeof value.method === 'string' ? [value.method.toUpperCase()] : methods;
|
|
319
|
+
let found = false;
|
|
320
|
+
for (const key of ['api', 'url', 'path'] as const) {
|
|
321
|
+
if (typeof value[key] === 'string') {
|
|
322
|
+
out.push({ path: value[key] as string, purpose, at: `${at}.${key}`, methods: actualMethods });
|
|
323
|
+
found = true;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (!found) {
|
|
327
|
+
for (const [key, item] of Object.entries(value)) endpointRefs(item, purpose, `${at}.${key}`, out, actualMethods);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
const walk = (value: unknown, at: string): void => {
|
|
331
|
+
if (value === null || typeof value !== 'object' || seen.has(value)) return;
|
|
332
|
+
seen.add(value);
|
|
333
|
+
if (Array.isArray(value)) {
|
|
334
|
+
value.forEach((item, index) => walk(item, `${at}[${index}]`));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (!isRecord(value)) return;
|
|
338
|
+
if (isRecord(value.behavior)) {
|
|
339
|
+
const behavior = value.behavior;
|
|
340
|
+
if (behavior.from !== undefined) endpointRefs(behavior.from, 'api', `${at}.behavior.from`, references, ['GET']);
|
|
341
|
+
if (behavior.write !== undefined) {
|
|
342
|
+
if (typeof behavior.write === 'string') {
|
|
343
|
+
for (const channel of ['create', 'update'] as const) {
|
|
344
|
+
const method = KIT_CORE_MAPPING.writeChannels[channel]!.method.toUpperCase();
|
|
345
|
+
endpointRefs(behavior.write, 'write_api', `${at}.behavior.write.${channel}`, references, [method]);
|
|
346
|
+
}
|
|
347
|
+
} else if (isRecord(behavior.write) && ['create', 'update', 'delete'].some((key) => Object.hasOwn(behavior.write as object, key))) {
|
|
348
|
+
for (const channel of ['create', 'update', 'delete'] as const) {
|
|
349
|
+
const endpoint = behavior.write[channel];
|
|
350
|
+
if (endpoint !== undefined) {
|
|
351
|
+
const method = KIT_CORE_MAPPING.writeChannels[channel]!.method.toUpperCase();
|
|
352
|
+
endpointRefs(endpoint, channel === 'delete' ? 'delete_api' : 'write_api', `${at}.behavior.write.${channel}`, references, [method]);
|
|
353
|
+
}
|
|
274
354
|
}
|
|
275
|
-
|
|
355
|
+
} else {
|
|
356
|
+
const create = KIT_CORE_MAPPING.writeChannels.create!.method.toUpperCase();
|
|
357
|
+
const update = KIT_CORE_MAPPING.writeChannels.update!.method.toUpperCase();
|
|
358
|
+
endpointRefs(behavior.write, 'write_api', `${at}.behavior.write`, references, [create, update]);
|
|
276
359
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
360
|
+
}
|
|
361
|
+
if (isRecord(behavior.detail) && isRecord(behavior.detail.from)) {
|
|
362
|
+
endpointRefs(behavior.detail.from, 'api', `${at}.behavior.detail.from`, references, ['GET']);
|
|
363
|
+
}
|
|
364
|
+
if (Array.isArray(behavior.actions)) {
|
|
365
|
+
behavior.actions.forEach((action, index) => {
|
|
366
|
+
if (!isRecord(action)) return;
|
|
367
|
+
if (action.request !== undefined) {
|
|
368
|
+
const method = isRecord(action.request) && typeof action.request.method === 'string' ? action.request.method.toUpperCase() : 'POST';
|
|
369
|
+
endpointRefs(action.request, 'write_api', `${at}.behavior.actions[${index}].request`, references, [method]);
|
|
370
|
+
}
|
|
371
|
+
if (action.download !== undefined) {
|
|
372
|
+
const method = isRecord(action.download) && typeof action.download.method === 'string' ? action.download.method.toUpperCase() : 'GET';
|
|
373
|
+
endpointRefs(action.download, 'api', `${at}.behavior.actions[${index}].download`, references, [method]);
|
|
374
|
+
}
|
|
284
375
|
});
|
|
285
376
|
}
|
|
286
377
|
}
|
|
378
|
+
for (const [key, item] of Object.entries(value)) walk(item, at === '$' ? key : `${at}.${key}`);
|
|
287
379
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
380
|
+
walk(source, '$');
|
|
381
|
+
return references;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** delete 目标在编译时附加主键占位查询;去掉该编译生成的尾参后按原授权路由核对。 */
|
|
385
|
+
function authorizationPathOf(reference: ApiReference): string {
|
|
386
|
+
if (reference.purpose !== 'delete_api') return reference.path;
|
|
387
|
+
const generatedKey = /[?&]([A-Za-z_][A-Za-z0-9_]*)=\{\1\}$/.exec(reference.path);
|
|
388
|
+
return generatedKey === null ? reference.path : reference.path.slice(0, generatedKey.index);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** accept 与 submit 共用同一套 path + method 判据;submit 的引用取自实际源而非 accepted.blueprint。 */
|
|
392
|
+
function unauthorizedApiReferenceIssues(references: readonly ApiReference[], authorized: readonly PageTargetApi[]): PageDiagnostic[] {
|
|
393
|
+
const methodsByPath = new Map<string, Set<string>>();
|
|
394
|
+
for (const api of authorized) {
|
|
395
|
+
if (!isRecord(api) || typeof api.path !== 'string' || !Array.isArray(api.fields)) continue;
|
|
396
|
+
const set = methodsByPath.get(api.path) ?? new Set<string>();
|
|
397
|
+
set.add(typeof api.method === 'string' && api.method !== '' ? api.method.toUpperCase() : 'GET');
|
|
398
|
+
methodsByPath.set(api.path, set);
|
|
399
|
+
}
|
|
400
|
+
const allowed = [...methodsByPath.keys()];
|
|
401
|
+
const methodsForReference = (reference: ApiReference): readonly string[] => reference.methods;
|
|
402
|
+
const pathsFor = (reference: ApiReference): string[] => {
|
|
403
|
+
const want = methodsForReference(reference);
|
|
404
|
+
return allowed.filter((path) => want.every((method) => methodsByPath.get(path)!.has(method)));
|
|
405
|
+
};
|
|
406
|
+
const out: PageDiagnostic[] = [];
|
|
407
|
+
for (const reference of references) {
|
|
408
|
+
const checkedPath = authorizationPathOf(reference);
|
|
409
|
+
const declared = methodsByPath.get(checkedPath);
|
|
410
|
+
const want = methodsForReference(reference);
|
|
411
|
+
if (declared === undefined) {
|
|
412
|
+
const paths = pathsFor(reference);
|
|
413
|
+
out.push({
|
|
414
|
+
code: CODE_UNAUTHORIZED_API,
|
|
415
|
+
severity: 'error',
|
|
416
|
+
situation: '核对对象描述引用的接口',
|
|
417
|
+
problem: `${reference.at} 引用接口 ${reference.path} 不在本次授权接口内`,
|
|
418
|
+
fix: paths.length === 0
|
|
419
|
+
? `移除该接口引用(当前授权中没有可用的 ${want.join('/')} 接口)${reference.purpose === 'delete_api' ? ',并移除依赖它的 remove 动作' : ''}`
|
|
420
|
+
: `改用授权接口:${paths.join(' / ')}`,
|
|
421
|
+
at: reference.at,
|
|
422
|
+
});
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (want.every((method) => declared.has(method))) continue;
|
|
426
|
+
const fits = pathsFor(reference);
|
|
427
|
+
out.push({
|
|
428
|
+
code: CODE_UNAUTHORIZED_API,
|
|
429
|
+
severity: 'error',
|
|
430
|
+
situation: '核对对象描述引用的接口',
|
|
431
|
+
problem: `${reference.at} 引用接口 ${reference.path} 在授权表里是 ${[...declared].join('/')} 接口,当前用途 ${PURPOSE_TEXT[reference.purpose]} 实际要求 ${want.join('/')}`,
|
|
432
|
+
fix: fits.length === 0
|
|
433
|
+
? `移除该接口引用(当前授权中没有可用的 ${want.join('/')} 接口)${reference.purpose === 'delete_api' ? ',并移除依赖它的 remove 动作' : ''}`
|
|
434
|
+
: `改用授权接口:${fits.join(' / ')}`,
|
|
435
|
+
at: reference.at,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
291
438
|
return out;
|
|
292
439
|
}
|
|
293
440
|
|
|
@@ -296,7 +443,7 @@ function unauthorizedApiIssues(blueprint: KitIntentBlueprint, authorized: readon
|
|
|
296
443
|
* 抛 `KitTargetAssemblyError`——都是 Host 配置问题,回喂模型改不了。
|
|
297
444
|
* 异步:服务端面是异步装配,`accept` 等同步成员要用它的应用上下文。
|
|
298
445
|
*/
|
|
299
|
-
export async function createKitPageTarget(app: KitPageTargetApp): Promise<PageTarget> {
|
|
446
|
+
export async function createKitPageTarget(app: KitPageTargetApp, targetOptions: KitPageTargetOptions = {}): Promise<PageTarget> {
|
|
300
447
|
let server: KitServerFace;
|
|
301
448
|
try {
|
|
302
449
|
server = await app.server();
|
|
@@ -312,7 +459,7 @@ export async function createKitPageTarget(app: KitPageTargetApp): Promise<PageTa
|
|
|
312
459
|
let mapProblems: readonly PageDiagnostic[];
|
|
313
460
|
let grammarDigest: string;
|
|
314
461
|
try {
|
|
315
|
-
mapProblems = [...checkIntentMap(registry), ...checkDisplayMap()];
|
|
462
|
+
mapProblems = [...checkIntentMap(registry), ...checkDisplayMap(), ...checkIntentSurface()];
|
|
316
463
|
grammarDigest = fnv1a64Hex(canonicalJson(grammarJson));
|
|
317
464
|
} catch (error) {
|
|
318
465
|
if (error instanceof KitAiSurfaceError) throw new KitTargetAssemblyError('failed', error.message, { cause: error });
|
|
@@ -329,8 +476,8 @@ export async function createKitPageTarget(app: KitPageTargetApp): Promise<PageTa
|
|
|
329
476
|
owner: SOMA_KIT_PAGE_OWNER,
|
|
330
477
|
grammarDigest,
|
|
331
478
|
|
|
332
|
-
schema: () => kitIntentSchema(),
|
|
333
|
-
prompt: (ctx, mode) => composePrompt(registry, ctx, mode),
|
|
479
|
+
schema: () => kitIntentSchema(appLocales),
|
|
480
|
+
prompt: (ctx, mode) => composePrompt(registry, ctx, mode, appLocales),
|
|
334
481
|
|
|
335
482
|
reviseNotes(): PageTargetReviseSpec {
|
|
336
483
|
return {
|
|
@@ -359,11 +506,26 @@ export async function createKitPageTarget(app: KitPageTargetApp): Promise<PageTa
|
|
|
359
506
|
throw new KitTargetInputError(`ctx.locale ${ctx.locale} 不在应用支持的语言内(可用:${appLocales.join(' / ')})`);
|
|
360
507
|
}
|
|
361
508
|
blueprint = { ...blueprint, locale: ctx.locale };
|
|
509
|
+
} else if (blueprint.locale !== undefined && appLocales !== undefined && !appLocales.includes(blueprint.locale)) {
|
|
510
|
+
// 模型自带的 locale 是模型产物:不在应用语言集内要在这里回喂,不能拖到提交阶段(那时已过自修复回合)
|
|
511
|
+
return {
|
|
512
|
+
ok: false,
|
|
513
|
+
stage: 'schema',
|
|
514
|
+
issues: [{
|
|
515
|
+
code: 'KIT-AIT-001',
|
|
516
|
+
severity: 'error',
|
|
517
|
+
situation: '解析 kit 意图蓝图',
|
|
518
|
+
problem: `locale ${blueprint.locale} 不在应用支持的语言内(可用:${appLocales.join(' / ')})`,
|
|
519
|
+
fix: `locale 改用 ${appLocales.join(' / ')} 之一,或删去 locale`,
|
|
520
|
+
at: 'locale',
|
|
521
|
+
}],
|
|
522
|
+
};
|
|
362
523
|
}
|
|
363
|
-
const unauthorized = unauthorizedApiIssues(blueprint, ctx.authorizedApis);
|
|
364
|
-
if (unauthorized.length > 0) return { ok: false, stage: 'policy', issues: unauthorized };
|
|
365
524
|
const compiled = compileKitIntentBlueprint(blueprint, { app: registry });
|
|
366
525
|
if (!compiled.ok) return { ok: false, stage: 'policy', issues: compiled.issues };
|
|
526
|
+
// 以确定性编译出的实际 source 引用核对方法:字符串 write 展开 create/POST 与 update/PUT,from 实际是 GET。
|
|
527
|
+
const unauthorized = unauthorizedApiReferenceIssues(sourceApiReferences(compiled.page), ctx.authorizedApis);
|
|
528
|
+
if (unauthorized.length > 0) return { ok: false, stage: 'policy', issues: unauthorized };
|
|
367
529
|
// 结构 + 闭集键检查(同步,沿 kit 既有 KIT-PAGE-* / KIT-FRAME-* 码)
|
|
368
530
|
const structure: KitDiagnostic[] = [];
|
|
369
531
|
parsePageDecl(compiled.page, structure);
|
|
@@ -408,7 +570,52 @@ export async function createKitPageTarget(app: KitPageTargetApp): Promise<PageTa
|
|
|
408
570
|
drift: kitReviseDriftIssues,
|
|
409
571
|
|
|
410
572
|
async submit(url: string, accepted: PageTargetAccepted, options: PageSubmitOptions): Promise<PageSubmitResult> {
|
|
573
|
+
let currentApis: readonly PageTargetApi[] = [];
|
|
574
|
+
let currentApiLookupFailed = targetOptions.currentAuthorizedApis === undefined;
|
|
575
|
+
if (targetOptions.currentAuthorizedApis !== undefined) {
|
|
576
|
+
try {
|
|
577
|
+
const resolved = await targetOptions.currentAuthorizedApis({
|
|
578
|
+
url,
|
|
579
|
+
caller: options.caller,
|
|
580
|
+
...(options.operator === undefined ? {} : { operator: options.operator }),
|
|
581
|
+
});
|
|
582
|
+
if (Array.isArray(resolved)) {
|
|
583
|
+
currentApis = resolved;
|
|
584
|
+
currentApiLookupFailed = false;
|
|
585
|
+
} else {
|
|
586
|
+
currentApiLookupFailed = true;
|
|
587
|
+
}
|
|
588
|
+
} catch {
|
|
589
|
+
currentApiLookupFailed = true;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
411
593
|
const text = sourceTextOf(accepted);
|
|
594
|
+
const { parseSomaDsl } = await import('soma-core/server/runtime');
|
|
595
|
+
const parsed = parseSomaDsl(text, 'ui');
|
|
596
|
+
if (!parsed.ok) {
|
|
597
|
+
throw new KitTargetInputError(`kit 目标只收自己 accept 出的结果:源文本不是合法 YAML(${parsed.diagnostics.map((d) => d.message).join(';')})`);
|
|
598
|
+
}
|
|
599
|
+
const surface = checkKitWriterSurface(parsed.value);
|
|
600
|
+
if (surface.length > 0) {
|
|
601
|
+
throw new KitSubmitError(CODE_REFUSED, '页面源违反写面策略,拒绝提交', surface);
|
|
602
|
+
}
|
|
603
|
+
const references = sourceApiReferences(parsed.value);
|
|
604
|
+
if (references.length > 0) {
|
|
605
|
+
const apiIssues = currentApiLookupFailed
|
|
606
|
+
? references.map((reference): PageDiagnostic => ({
|
|
607
|
+
code: CODE_UNAUTHORIZED_API,
|
|
608
|
+
severity: 'error',
|
|
609
|
+
situation: '核对提交时的当前接口授权',
|
|
610
|
+
problem: `页面源引用接口 ${reference.path},但 Host 未提供可用的当前授权目录`,
|
|
611
|
+
fix: '在 createKitPageTarget 的第二参数配置 currentAuthorizedApis,或移除该接口引用',
|
|
612
|
+
at: reference.at,
|
|
613
|
+
}))
|
|
614
|
+
: unauthorizedApiReferenceIssues(references, currentApis);
|
|
615
|
+
if (apiIssues.length > 0) {
|
|
616
|
+
throw new KitSubmitError(CODE_UNAUTHORIZED_API, '提交时当前接口授权不允许页面源中的接口引用', apiIssues);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
412
619
|
const persist = aiPersistOf(options.persist, url);
|
|
413
620
|
return server.pages.submit(url, { source: text }, { ...options, persist });
|
|
414
621
|
},
|
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
aiTones,
|
|
19
19
|
blockThemeAitIssues,
|
|
20
20
|
compilerKeysOf,
|
|
21
|
+
fieldHintKeys,
|
|
22
|
+
hintSlots,
|
|
21
23
|
isThemeKey,
|
|
22
24
|
KIT_REMOVE_CONFIRM_REF,
|
|
23
25
|
kitAiDisplayMap,
|
|
@@ -196,6 +198,14 @@ function isCompilerDisplayRef(ref: unknown, slot: string): boolean {
|
|
|
196
198
|
return Object.values(map.words).some((w) => w.component === ref.component && JSON.stringify(w.fixedProps) === JSON.stringify(props));
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
/** form / filter 视图里的字段引用对象只认编译器按 fieldRef 的 ai 提示键写的形状:{ name, placeholder?, help? }(至少一个提示,值为非空纯文本) */
|
|
202
|
+
function isCompilerHintRef(ref: unknown, slot: string): boolean {
|
|
203
|
+
if (!hintSlots().includes(slot) || !isRecord(ref) || typeof ref.name !== 'string') return false;
|
|
204
|
+
const hints = fieldHintKeys();
|
|
205
|
+
const keys = Object.keys(ref).filter((k) => k !== 'name');
|
|
206
|
+
return keys.length > 0 && keys.every((k) => hints.includes(k) && typeof ref[k] === 'string' && (ref[k] as string).trim() !== '');
|
|
207
|
+
}
|
|
208
|
+
|
|
199
209
|
function checkView(view: unknown, at: string, actionIds: ReadonlySet<string>, out: PageDiagnostic[]): void {
|
|
200
210
|
const w = kitAiWriter();
|
|
201
211
|
if (!isRecord(view)) return void out.push(issue(CODE_SHAPE, at, 'view 须是对象', '写成 { list: { fields: [...] } }'));
|
|
@@ -213,8 +223,8 @@ function checkView(view: unknown, at: string, actionIds: ReadonlySet<string>, ou
|
|
|
213
223
|
out.push(issue(CODE_OVERREACH, `${sat}.fields`, 'fields 只许字段 id 字符串数组(字段引用对象属人写:component / width / class …)', '写成字段 id 字符串数组'));
|
|
214
224
|
} else {
|
|
215
225
|
body.fields.forEach((f, i) => {
|
|
216
|
-
if (typeof f === 'string' || isCompilerDisplayRef(f, slot)) return;
|
|
217
|
-
out.push(issue(CODE_OVERREACH, `${sat}.fields[${i}]`, '字段引用只许字段 id 字符串(展示词映射出的 { name, component, props } 由编译器按 aiDisplayMap
|
|
226
|
+
if (typeof f === 'string' || isCompilerDisplayRef(f, slot) || isCompilerHintRef(f, slot)) return;
|
|
227
|
+
out.push(issue(CODE_OVERREACH, `${sat}.fields[${i}]`, '字段引用只许字段 id 字符串(展示词映射出的 { name, component, props } 由编译器按 aiDisplayMap 写,form / filter 的 { name, placeholder, help } 由编译器按 fieldRef 的 ai 键写;其余 component / width / class … 属人写)', '写成字段 id 字符串;要换展示,在蓝图字段上写 display;要加提示,写 placeholder / help'));
|
|
218
228
|
});
|
|
219
229
|
}
|
|
220
230
|
}
|
|
@@ -232,7 +242,8 @@ const OBJECT_TOP_KEYS = Object.keys((grammarJson as unknown as { objectKeys: Rec
|
|
|
232
242
|
function checkObject(obj: unknown, at: string, out: PageDiagnostic[]): void {
|
|
233
243
|
if (!isRecord(obj)) return void out.push(issue(CODE_SHAPE, at, '对象声明须是对象(schema / behavior / view)', '按编译器输出'));
|
|
234
244
|
checkKeys(obj, OBJECT_TOP_KEYS, at, out);
|
|
235
|
-
|
|
245
|
+
// 模板写死的角色(aiWriter.roleShape.omit 含 schema,如 StepForm 的 target)不带 schema
|
|
246
|
+
if (obj.schema !== undefined) checkSchema(obj.schema, `${at}.schema`, out);
|
|
236
247
|
const ids = obj.behavior === undefined ? new Set<string>() : checkBehavior(obj.behavior, `${at}.behavior`, out);
|
|
237
248
|
if (obj.view !== undefined) checkView(obj.view, `${at}.view`, ids, out);
|
|
238
249
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// 容器配方(container.ts):对齐九维空间令牌(rounded-card / gap-section / p-card),
|
|
2
|
+
// 提供 card / panel / section / well 四类 data-kit-part 常量与纯函数配方,
|
|
3
|
+
// 以及 slot 视图槽、容器 emphasis、highlight 高亮子配方函数,消除平行重复字面量。
|
|
4
|
+
|
|
5
|
+
import { classCandidates } from '../base/class-candidates';
|
|
6
|
+
|
|
7
|
+
export const KIT_PART_CARD = 'card' as const;
|
|
8
|
+
export const KIT_PART_PANEL = 'panel' as const;
|
|
9
|
+
export const KIT_PART_SECTION = 'section' as const;
|
|
10
|
+
export const KIT_PART_WELL = 'well' as const;
|
|
11
|
+
|
|
12
|
+
export type KitContainerPart =
|
|
13
|
+
| typeof KIT_PART_CARD
|
|
14
|
+
| typeof KIT_PART_PANEL
|
|
15
|
+
| typeof KIT_PART_SECTION
|
|
16
|
+
| typeof KIT_PART_WELL;
|
|
17
|
+
|
|
18
|
+
export type KitContainerSurface = 'card' | 'flush' | 'plain' | 'well';
|
|
19
|
+
export type KitContainerEmphasis = 'primary' | 'normal' | 'subtle';
|
|
20
|
+
export type KitContainerPadding = 'sm' | 'md' | 'lg' | 'none';
|
|
21
|
+
export type KitSlotSurface = 'card' | 'flush' | 'plain';
|
|
22
|
+
export type KitHighlightKind = 'metric' | 'view';
|
|
23
|
+
|
|
24
|
+
export interface KitContainerRecipeOptions {
|
|
25
|
+
surface?: KitContainerSurface;
|
|
26
|
+
emphasis?: KitContainerEmphasis;
|
|
27
|
+
padding?: KitContainerPadding;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SURFACE_CLASS: Readonly<Record<KitContainerSurface, string>> = Object.freeze({
|
|
31
|
+
// 标准卡片圆角(rounded-card),实底卡片高于画布
|
|
32
|
+
card: 'flex flex-col rounded-card border border-border-subtle bg-surface text-fg shadow-sm',
|
|
33
|
+
// flush 贴边面板:底部分隔线、无外圆角与外阴影
|
|
34
|
+
flush: 'flex flex-col rounded-none border-b border-border-subtle bg-surface text-fg',
|
|
35
|
+
// plain 纯结构区块容器:无背景与边框,遵循九维区块间距令牌(gap-section)
|
|
36
|
+
plain: 'flex flex-col bg-transparent text-fg gap-section',
|
|
37
|
+
// well 凹槽容器:低于画布(bg-surface-sunken),内嵌圆角
|
|
38
|
+
well: 'flex flex-col rounded-lg border border-border-subtle bg-surface-sunken text-fg',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const EMPHASIS_CLASS: Readonly<Record<KitContainerEmphasis, string>> = Object.freeze({
|
|
42
|
+
primary: 'border-primary/40 ring-1 ring-primary/20',
|
|
43
|
+
normal: '',
|
|
44
|
+
subtle: 'border-transparent bg-surface-sunken/60 shadow-none',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const PADDING_CLASS: Readonly<Record<KitContainerPadding, string>> = Object.freeze({
|
|
48
|
+
none: 'p-0',
|
|
49
|
+
sm: 'p-3 gap-3',
|
|
50
|
+
// 默认容器内边距消费九维卡片内边距令牌(p-card)
|
|
51
|
+
md: 'p-card gap-4',
|
|
52
|
+
// 大号容器内边距(p-6)+ 区块间距令牌(gap-section)
|
|
53
|
+
lg: 'p-6 gap-section',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 根据容器 surface 推导对应的 data-kit-part 标识值。
|
|
58
|
+
*/
|
|
59
|
+
export function kitContainerPartOf(surface: KitContainerSurface = 'card'): KitContainerPart {
|
|
60
|
+
if (surface === 'well') return KIT_PART_WELL;
|
|
61
|
+
if (surface === 'flush') return KIT_PART_PANEL;
|
|
62
|
+
if (surface === 'plain') return KIT_PART_SECTION;
|
|
63
|
+
return KIT_PART_CARD;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 容器配方纯函数:消费九维空间令牌(rounded-card / gap-section / p-card)。
|
|
68
|
+
*/
|
|
69
|
+
export function kitContainerRecipe(options: KitContainerRecipeOptions = {}): string {
|
|
70
|
+
const surface: KitContainerSurface = options.surface ?? 'card';
|
|
71
|
+
const emphasis: KitContainerEmphasis = options.emphasis ?? 'normal';
|
|
72
|
+
const padding: KitContainerPadding = options.padding ?? (surface === 'plain' ? 'none' : 'md');
|
|
73
|
+
|
|
74
|
+
const surfaceCls = SURFACE_CLASS[surface] ?? SURFACE_CLASS.card;
|
|
75
|
+
const emphasisCls = EMPHASIS_CLASS[emphasis] ?? '';
|
|
76
|
+
const paddingCls = PADDING_CLASS[padding] ?? PADDING_CLASS.md;
|
|
77
|
+
|
|
78
|
+
return [surfaceCls, emphasisCls, paddingCls].filter(Boolean).join(' ');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 视图/面板槽 surface 子配方函数:产出设计规范基准类串(card 槽无 flex flex-col gap-4,圆角 rounded-lg、阴影 shadow-xs、内边距 p-card)。
|
|
83
|
+
*/
|
|
84
|
+
export function kitSlotSurfaceRecipe(surface: KitSlotSurface = 'card'): string {
|
|
85
|
+
switch (surface) {
|
|
86
|
+
case 'card':
|
|
87
|
+
return 'rounded-lg border border-border-subtle bg-surface p-card shadow-xs';
|
|
88
|
+
case 'flush':
|
|
89
|
+
return 'p-0 border-0 bg-surface';
|
|
90
|
+
case 'plain':
|
|
91
|
+
return 'p-0 border-0 bg-transparent shadow-none';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 容器区块/对象级 emphasis 子配方函数:产出设计规范基准类串。
|
|
97
|
+
*/
|
|
98
|
+
export function kitContainerEmphasisRecipe(emphasis: KitContainerEmphasis = 'normal'): string {
|
|
99
|
+
switch (emphasis) {
|
|
100
|
+
case 'primary':
|
|
101
|
+
return 'rounded-lg border border-primary bg-surface-raised p-card shadow-sm';
|
|
102
|
+
case 'normal':
|
|
103
|
+
return 'rounded-lg border border-border-subtle bg-surface p-card';
|
|
104
|
+
case 'subtle':
|
|
105
|
+
return 'rounded-lg border border-border-divider bg-surface-sunken p-3 text-fg-muted';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 视图/指标高亮 highlight 子配方函数:产出设计规范基准类串。
|
|
111
|
+
*/
|
|
112
|
+
export function kitHighlightRecipe(kind: KitHighlightKind = 'view'): string {
|
|
113
|
+
return `rounded-lg border border-primary bg-primary-soft ${kind === 'metric' ? 'p-3' : 'p-card'}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 面板/视图级 surface -> 容器配方类映射(由 kitSlotSurfaceRecipe 同源生成) */
|
|
117
|
+
export const KIT_SURFACE_RECIPE_CLASSES: Readonly<Record<KitSlotSurface, string>> = Object.freeze({
|
|
118
|
+
card: kitSlotSurfaceRecipe('card'),
|
|
119
|
+
flush: kitSlotSurfaceRecipe('flush'),
|
|
120
|
+
plain: kitSlotSurfaceRecipe('plain'),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/** 区块/对象级 emphasis -> 容器语义类映射(由 kitContainerEmphasisRecipe 同源生成) */
|
|
124
|
+
export const KIT_CONTAINER_EMPHASIS_CLASSES: Readonly<Record<KitContainerEmphasis, string>> = Object.freeze({
|
|
125
|
+
primary: kitContainerEmphasisRecipe('primary'),
|
|
126
|
+
normal: kitContainerEmphasisRecipe('normal'),
|
|
127
|
+
subtle: kitContainerEmphasisRecipe('subtle'),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/** 指标项/字段格 highlight: true -> 主色强调边框与背景类(由 kitHighlightRecipe 同源生成) */
|
|
131
|
+
export const KIT_METRIC_HIGHLIGHT_CLASS = kitHighlightRecipe('metric');
|
|
132
|
+
|
|
133
|
+
/** 视图级 highlight: true -> 主色强调边框与背景类(由 kitHighlightRecipe 同源生成) */
|
|
134
|
+
export const KIT_VIEW_HIGHLIGHT_CLASS = kitHighlightRecipe('view');
|
|
135
|
+
|
|
136
|
+
const ALL_CONTAINER_SURFACES: readonly KitContainerSurface[] = Object.freeze(['card', 'flush', 'plain', 'well']);
|
|
137
|
+
const ALL_CONTAINER_EMPHASIS: readonly KitContainerEmphasis[] = Object.freeze(['primary', 'normal', 'subtle']);
|
|
138
|
+
const ALL_CONTAINER_PADDINGS: readonly KitContainerPadding[] = Object.freeze(['none', 'sm', 'md', 'lg']);
|
|
139
|
+
const ALL_SLOT_SURFACES: readonly KitSlotSurface[] = Object.freeze(['card', 'flush', 'plain']);
|
|
140
|
+
const ALL_HIGHLIGHT_KINDS: readonly KitHighlightKind[] = Object.freeze(['metric', 'view']);
|
|
141
|
+
|
|
142
|
+
function collectContainerRecipeCandidates(): string[] {
|
|
143
|
+
const classes: string[] = [];
|
|
144
|
+
for (const surface of ALL_CONTAINER_SURFACES) {
|
|
145
|
+
for (const emphasis of ALL_CONTAINER_EMPHASIS) {
|
|
146
|
+
for (const padding of ALL_CONTAINER_PADDINGS) {
|
|
147
|
+
classes.push(kitContainerRecipe({ surface, emphasis, padding }));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const slot of ALL_SLOT_SURFACES) {
|
|
152
|
+
classes.push(kitSlotSurfaceRecipe(slot));
|
|
153
|
+
}
|
|
154
|
+
for (const em of ALL_CONTAINER_EMPHASIS) {
|
|
155
|
+
classes.push(kitContainerEmphasisRecipe(em));
|
|
156
|
+
}
|
|
157
|
+
for (const hk of ALL_HIGHLIGHT_KINDS) {
|
|
158
|
+
classes.push(kitHighlightRecipe(hk));
|
|
159
|
+
}
|
|
160
|
+
return classes;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export const KIT_CONTAINER_RECIPE_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
164
|
+
collectContainerRecipeCandidates(),
|
|
165
|
+
);
|