soma-kit 0.0.0-stage → 0.1.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/README.md +539 -2
- package/bin/soma-kit.mjs +27 -0
- package/package.json +66 -4
- package/packs/ai/agent-run-card.ts +64 -0
- package/packs/ai/evaluation-card.ts +51 -0
- package/packs/ai/guardrail-policy-card.ts +48 -0
- package/packs/ai/index.ts +31 -0
- package/packs/ai/model-card.ts +55 -0
- package/packs/ai/model-routing-card.ts +49 -0
- package/packs/ai/prompt-template-card.ts +49 -0
- package/packs/ai/texts.ts +19 -0
- package/packs/commerce/address-card.ts +58 -0
- package/packs/commerce/coupon-card.ts +64 -0
- package/packs/commerce/index.ts +25 -0
- package/packs/commerce/order-card.ts +60 -0
- package/packs/commerce/purchase-order-card.ts +74 -0
- package/packs/commerce/texts.ts +14 -0
- package/packs/finance/index.ts +30 -0
- package/packs/finance/invoice-summary-card.ts +48 -0
- package/packs/finance/reconcile-board.ts +450 -0
- package/packs/finance/reconcile-case-card.ts +70 -0
- package/packs/finance/reconcile-desk/compile.ts +208 -0
- package/packs/finance/reconcile-desk/index.ts +20 -0
- package/packs/finance/reconcile-desk/shell.ts +27 -0
- package/packs/finance/texts.ts +21 -0
- package/packs/ops/change-window-card.ts +54 -0
- package/packs/ops/dependency-status-card.ts +50 -0
- package/packs/ops/error-budget-card.ts +60 -0
- package/packs/ops/execution-task-runner.ts +61 -0
- package/packs/ops/index.ts +36 -0
- package/packs/ops/integration-status-card.ts +45 -0
- package/packs/ops/release-readiness-card.ts +63 -0
- package/packs/ops/runbook-execution-card.ts +81 -0
- package/packs/ops/texts.ts +21 -0
- package/packs/security/control-evidence-card.ts +54 -0
- package/packs/security/finding-card.ts +96 -0
- package/packs/security/index.ts +29 -0
- package/packs/security/texts.ts +31 -0
- package/packs/shared/card-util.ts +60 -0
- package/packs/shared/wrap.ts +13 -0
- package/spec/generated/kit-app.schema.json +84 -0
- package/spec/generated/kit-page.schema.json +2766 -0
- package/spec/kit-grammar.json +1358 -0
- package/spec/kit-grammar.schema.json +716 -0
- package/src/app/app-config.ts +108 -0
- package/src/app/compose-apps.ts +139 -0
- package/src/app/define-kit-actions.ts +89 -0
- package/src/app/define-kit-app.ts +362 -0
- package/src/app/define-kit-pack.ts +114 -0
- package/src/app/envelope.ts +117 -0
- package/src/app/index.ts +50 -0
- package/src/app/notify-renderer.ts +114 -0
- package/src/app/paged-list-adapter.ts +246 -0
- package/src/app/server-pages.ts +303 -0
- package/src/app/server.ts +244 -0
- package/src/app/submit.types.ts +87 -0
- package/src/base/action-busy.ts +159 -0
- package/src/base/action-gate.ts +267 -0
- package/src/base/action-status.ts +31 -0
- package/src/base/alert.ts +136 -0
- package/src/base/avatar.ts +271 -0
- package/src/base/button.ts +139 -0
- package/src/base/cascader.ts +523 -0
- package/src/base/check-core.ts +214 -0
- package/src/base/checkbox.ts +35 -0
- package/src/base/choice.ts +183 -0
- package/src/base/color-picker.ts +316 -0
- package/src/base/combobox.ts +61 -0
- package/src/base/command-palette.ts +371 -0
- package/src/base/context-menu.ts +103 -0
- package/src/base/countdown.ts +168 -0
- package/src/base/date-range.ts +444 -0
- package/src/base/date.ts +899 -0
- package/src/base/divider.ts +156 -0
- package/src/base/fab.ts +192 -0
- package/src/base/icons.ts +106 -0
- package/src/base/image.ts +177 -0
- package/src/base/index.ts +214 -0
- package/src/base/input.ts +316 -0
- package/src/base/kbd.ts +99 -0
- package/src/base/link.ts +167 -0
- package/src/base/listbox-core.ts +965 -0
- package/src/base/mentions.ts +323 -0
- package/src/base/menu-button.ts +240 -0
- package/src/base/menu-core.ts +341 -0
- package/src/base/month-grid.ts +171 -0
- package/src/base/motion/aura.ts +94 -0
- package/src/base/motion/hover-3d.ts +154 -0
- package/src/base/motion/hover-gallery.ts +185 -0
- package/src/base/motion/index.ts +27 -0
- package/src/base/motion/limits.ts +75 -0
- package/src/base/motion/marquee.ts +157 -0
- package/src/base/motion/text-rotate.ts +195 -0
- package/src/base/number.ts +121 -0
- package/src/base/otp.ts +259 -0
- package/src/base/permission-gate.ts +99 -0
- package/src/base/popover.ts +352 -0
- package/src/base/popup.ts +542 -0
- package/src/base/portal-core.ts +297 -0
- package/src/base/price-text.ts +126 -0
- package/src/base/progress.ts +216 -0
- package/src/base/qr-code.ts +446 -0
- package/src/base/qty-stepper.ts +241 -0
- package/src/base/radio.ts +33 -0
- package/src/base/range.ts +444 -0
- package/src/base/rating.ts +249 -0
- package/src/base/segmented.ts +286 -0
- package/src/base/select.ts +57 -0
- package/src/base/shared.ts +708 -0
- package/src/base/swap.ts +86 -0
- package/src/base/switch.ts +111 -0
- package/src/base/tag-input.ts +464 -0
- package/src/base/tag.ts +250 -0
- package/src/base/text.ts +126 -0
- package/src/base/textarea.ts +129 -0
- package/src/base/time-picker.ts +606 -0
- package/src/base/tree-select.ts +629 -0
- package/src/base/upload.ts +548 -0
- package/src/base/virtual-list.ts +286 -0
- package/src/biz/approval-desk/compile.ts +179 -0
- package/src/biz/approval-desk/index.ts +21 -0
- package/src/biz/approval-desk/shell.ts +50 -0
- package/src/biz/auth-panel/compile.ts +196 -0
- package/src/biz/auth-panel/index.ts +24 -0
- package/src/biz/auth-panel/shell.ts +46 -0
- package/src/biz/category-crud/compile.ts +173 -0
- package/src/biz/category-crud/index.ts +19 -0
- package/src/biz/category-crud/shell.ts +29 -0
- package/src/biz/checkout-page/compile.ts +111 -0
- package/src/biz/checkout-page/index.ts +20 -0
- package/src/biz/checkout-page/shell.ts +50 -0
- package/src/biz/compose.ts +313 -0
- package/src/biz/data-components.ts +26 -0
- package/src/biz/define.ts +23 -0
- package/src/biz/import-wizard/compile.ts +204 -0
- package/src/biz/import-wizard/hub.ts +540 -0
- package/src/biz/import-wizard/index.ts +24 -0
- package/src/biz/import-wizard/shell.ts +161 -0
- package/src/biz/index.ts +80 -0
- package/src/biz/landing-page/compile.ts +67 -0
- package/src/biz/landing-page/index.ts +20 -0
- package/src/biz/landing-page/shell.ts +48 -0
- package/src/biz/link/hub.ts +255 -0
- package/src/biz/link/shared.ts +493 -0
- package/src/biz/master-sub/compile.ts +232 -0
- package/src/biz/master-sub/index.ts +20 -0
- package/src/biz/master-sub/shell.ts +56 -0
- package/src/biz/multi-board/compile.ts +234 -0
- package/src/biz/multi-board/index.ts +19 -0
- package/src/biz/multi-board/shell.ts +70 -0
- package/src/biz/names.ts +30 -0
- package/src/biz/notification-center/compile.ts +138 -0
- package/src/biz/notification-center/index.ts +29 -0
- package/src/biz/notification-center/shell.ts +42 -0
- package/src/biz/page-templates/result-page/compile.ts +46 -0
- package/src/biz/page-templates/result-page/index.ts +19 -0
- package/src/biz/page-templates/result-page/shell.ts +31 -0
- package/src/biz/page-templates/shared.ts +121 -0
- package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
- package/src/biz/page-templates/sign-in-page/index.ts +18 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
- package/src/biz/record-detail/compile.ts +290 -0
- package/src/biz/record-detail/index.ts +22 -0
- package/src/biz/record-detail/shell.ts +64 -0
- package/src/biz/settings-center/compile.ts +100 -0
- package/src/biz/settings-center/index.ts +18 -0
- package/src/biz/settings-center/shell.ts +51 -0
- package/src/biz/shared/action-host.ts +469 -0
- package/src/biz/shared/coordinator.ts +516 -0
- package/src/biz/shared/index.ts +9 -0
- package/src/biz/shared/pipes.ts +58 -0
- package/src/biz/shared/runtime-hub.ts +112 -0
- package/src/biz/shared/step-values.ts +25 -0
- package/src/biz/single-form/compile.ts +146 -0
- package/src/biz/single-form/index.ts +18 -0
- package/src/biz/single-form/shell.ts +38 -0
- package/src/biz/standard-crud/bridge.ts +11 -0
- package/src/biz/standard-crud/compile.ts +546 -0
- package/src/biz/standard-crud/index.ts +18 -0
- package/src/biz/standard-crud/shell.ts +157 -0
- package/src/biz/step-form/compile.ts +400 -0
- package/src/biz/step-form/hub.ts +412 -0
- package/src/biz/step-form/index.ts +23 -0
- package/src/biz/step-form/shell.ts +96 -0
- package/src/biz/step-form/steps-ref.ts +112 -0
- package/src/biz/types.ts +96 -0
- package/src/cli/kit-cli.ts +102 -0
- package/src/compile/action-host-attach.ts +76 -0
- package/src/compile/compile-page.ts +472 -0
- package/src/compile/component-candidates.ts +147 -0
- package/src/compile/fragment.ts +104 -0
- package/src/compile/hints.ts +255 -0
- package/src/compile/index.ts +16 -0
- package/src/compile/locate.ts +166 -0
- package/src/compile/page-params.ts +80 -0
- package/src/compile/parse.ts +355 -0
- package/src/compile/redirect.ts +90 -0
- package/src/compile/registry.ts +30 -0
- package/src/compile/remove-guard.ts +99 -0
- package/src/compile/styles.ts +244 -0
- package/src/compile/types.ts +106 -0
- package/src/data/amount-breakdown.ts +132 -0
- package/src/data/anchor-nav.ts +225 -0
- package/src/data/approval-flow.ts +269 -0
- package/src/data/assignment-picker.ts +652 -0
- package/src/data/async-result-panel.ts +308 -0
- package/src/data/breadcrumbs.ts +197 -0
- package/src/data/calendar.ts +363 -0
- package/src/data/carousel.ts +408 -0
- package/src/data/chart.ts +726 -0
- package/src/data/checklist.ts +215 -0
- package/src/data/code-view.ts +415 -0
- package/src/data/comment-thread.ts +342 -0
- package/src/data/confirm-dialog.ts +144 -0
- package/src/data/context-menu.ts +216 -0
- package/src/data/d9-limits.ts +42 -0
- package/src/data/d9-util.ts +81 -0
- package/src/data/diff.ts +239 -0
- package/src/data/display-util.ts +135 -0
- package/src/data/dock.ts +152 -0
- package/src/data/embed.ts +200 -0
- package/src/data/field-mapper.ts +544 -0
- package/src/data/flow-editor-contract.ts +41 -0
- package/src/data/flow-editor.ts +2622 -0
- package/src/data/flow-remote-options.ts +257 -0
- package/src/data/footer.ts +157 -0
- package/src/data/form-draft-registry.ts +76 -0
- package/src/data/gantt.ts +430 -0
- package/src/data/hero.ts +149 -0
- package/src/data/image-viewer.ts +333 -0
- package/src/data/index.ts +268 -0
- package/src/data/item-list.ts +335 -0
- package/src/data/kanban.ts +667 -0
- package/src/data/media-grid.ts +246 -0
- package/src/data/mega-menu.ts +257 -0
- package/src/data/menu-dom.ts +169 -0
- package/src/data/menu.ts +464 -0
- package/src/data/mockup.ts +176 -0
- package/src/data/modal-dialog.ts +182 -0
- package/src/data/navbar.ts +292 -0
- package/src/data/object-form.ts +1981 -0
- package/src/data/options-bus.ts +24 -0
- package/src/data/outcome-watch.ts +40 -0
- package/src/data/overlay-portal.ts +6 -0
- package/src/data/pager.ts +473 -0
- package/src/data/permission-matrix.ts +432 -0
- package/src/data/permission-tree.ts +916 -0
- package/src/data/pricing-table.ts +269 -0
- package/src/data/prompt-dialog.ts +235 -0
- package/src/data/reaction-bar.ts +236 -0
- package/src/data/record-card.ts +413 -0
- package/src/data/record-picker.ts +489 -0
- package/src/data/redirect.ts +109 -0
- package/src/data/remote-options.ts +54 -0
- package/src/data/request-console.ts +399 -0
- package/src/data/resident.ts +58 -0
- package/src/data/result-panel.ts +160 -0
- package/src/data/rich-text.ts +626 -0
- package/src/data/row-editor.ts +1066 -0
- package/src/data/rule-builder.ts +1137 -0
- package/src/data/shape-util.ts +221 -0
- package/src/data/staged-rows.ts +69 -0
- package/src/data/stat-group.ts +231 -0
- package/src/data/static-lazy.ts +63 -0
- package/src/data/static-registry.ts +227 -0
- package/src/data/steps.ts +195 -0
- package/src/data/survey.ts +455 -0
- package/src/data/system-switcher.ts +243 -0
- package/src/data/timeline.ts +204 -0
- package/src/data/tour-guide.ts +392 -0
- package/src/data/transfer.ts +597 -0
- package/src/data/tree-check.ts +30 -0
- package/src/data/tree-table.ts +674 -0
- package/src/data/tree.ts +656 -0
- package/src/data/trend-line.ts +147 -0
- package/src/data/virtual-rows.ts +556 -0
- package/src/data/watermark.ts +140 -0
- package/src/data/wrap.ts +267 -0
- package/src/data/wrapped-candidates.ts +96 -0
- package/src/frames/blank-frame.ts +19 -0
- package/src/frames/index.ts +44 -0
- package/src/frames/page-bar.ts +185 -0
- package/src/frames/page-header.ts +185 -0
- package/src/frames/page-status.ts +54 -0
- package/src/frames/resize-handle.ts +147 -0
- package/src/frames/shared.ts +242 -0
- package/src/frames/single-frame.ts +16 -0
- package/src/frames/split-frame/index.ts +4 -0
- package/src/frames/split-frame/shell.ts +219 -0
- package/src/frames/split-frame/span.ts +64 -0
- package/src/frames/split-frame/wiring.ts +164 -0
- package/src/frames/tabs-frame/index.ts +3 -0
- package/src/frames/tabs-frame/shell.ts +112 -0
- package/src/frames/tabs-frame/wiring.ts +69 -0
- package/src/frames/top-main-frame.ts +20 -0
- package/src/frames/types.ts +72 -0
- package/src/frames/workspace-frame/extras.ts +197 -0
- package/src/frames/workspace-frame/index.ts +13 -0
- package/src/frames/workspace-frame/shell.ts +282 -0
- package/src/frames/workspace-frame/state.ts +152 -0
- package/src/frames/workspace-frame/view.ts +1013 -0
- package/src/generated/kit-grammar-runtime.ts +2822 -0
- package/src/generated/page-origin.ts +57 -0
- package/src/i18n/index.ts +22 -0
- package/src/i18n/kit-text.ts +692 -0
- package/src/i18n/resolve-text-refs.ts +128 -0
- package/src/index.ts +6 -0
- package/src/object-renderer/action-gate.ts +216 -0
- package/src/object-renderer/adopt-gate.ts +333 -0
- package/src/object-renderer/arrange.ts +411 -0
- package/src/object-renderer/candidates.ts +68 -0
- package/src/object-renderer/collapse-wiring.ts +99 -0
- package/src/object-renderer/collection-expand.ts +185 -0
- package/src/object-renderer/collection-parts.ts +653 -0
- package/src/object-renderer/collection-table.ts +503 -0
- package/src/object-renderer/collection.ts +628 -0
- package/src/object-renderer/compile-data.ts +549 -0
- package/src/object-renderer/defaults.ts +252 -0
- package/src/object-renderer/display-checks.ts +153 -0
- package/src/object-renderer/emit-events.ts +498 -0
- package/src/object-renderer/emit-object.ts +98 -0
- package/src/object-renderer/emit-static.ts +1036 -0
- package/src/object-renderer/field-policy.ts +89 -0
- package/src/object-renderer/field-value.ts +581 -0
- package/src/object-renderer/form-detail.ts +116 -0
- package/src/object-renderer/index.ts +13 -0
- package/src/object-renderer/linkage.ts +371 -0
- package/src/object-renderer/merge-class.ts +126 -0
- package/src/object-renderer/mode.ts +25 -0
- package/src/object-renderer/outcome-draft.ts +61 -0
- package/src/object-renderer/parts.ts +136 -0
- package/src/object-renderer/pick-component.ts +36 -0
- package/src/object-renderer/render-object.ts +724 -0
- package/src/object-renderer/request-actions.ts +581 -0
- package/src/object-renderer/skeleton.ts +101 -0
- package/src/object-renderer/table-actions.ts +438 -0
- package/src/object-renderer/table-summary.ts +105 -0
- package/src/object-renderer/table-tools.ts +1072 -0
- package/src/object-renderer/types.ts +936 -0
- package/src/page-target/ai-surface.ts +154 -0
- package/src/page-target/compile.ts +354 -0
- package/src/page-target/drift.ts +186 -0
- package/src/page-target/index.ts +25 -0
- package/src/page-target/intent-map.ts +137 -0
- package/src/page-target/intent-schema.ts +711 -0
- package/src/page-target/origin.ts +17 -0
- package/src/page-target/target.ts +450 -0
- package/src/page-target/writer-policy.ts +315 -0
- package/src/theme/block-theme.ts +202 -0
- package/src/theme/kit-theme-text.ts +2 -0
- package/src/theme/kit-theme.css +275 -0
- package/src/theme/kit-theme.tpl +275 -0
- package/src/theme/theme-tokens.ts +135 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
// 第 0 步:页面声明解析与闭集键检查(KIT-PAGE-001 / 003 / 004)。纯函数,不查注册表。
|
|
2
|
+
// 键闭集全部读 spec/kit-grammar.json;对象内部的字段级语义(type、component、view 槽位名)归对象渲染内核校验,这里只拦未知键。
|
|
3
|
+
|
|
4
|
+
import { KIT_AI_WRITER_LIMITS, KIT_WORKSPACE_FRAME_LIMITS } from 'soma-foundation/kit-limits';
|
|
5
|
+
import grammarJson from '../../spec/kit-grammar.json';
|
|
6
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
7
|
+
import type { KitPageDecl, KitProductDecl, KitTabDecl } from './types';
|
|
8
|
+
import { parseRedirect } from './redirect';
|
|
9
|
+
import { blockThemeKitDiagnostics, checkBlockTheme } from '../theme/block-theme';
|
|
10
|
+
import { parsePageHeader } from '../frames/page-header';
|
|
11
|
+
import { parsePageParams } from './page-params';
|
|
12
|
+
import { parseKitEnvelope } from '../app/envelope';
|
|
13
|
+
|
|
14
|
+
interface GrammarKeys {
|
|
15
|
+
pageTopKeys: string[];
|
|
16
|
+
pageKeys: string[];
|
|
17
|
+
frameKeys: string[];
|
|
18
|
+
productKeys: string[];
|
|
19
|
+
actionKeys: string[];
|
|
20
|
+
objectKeys: { schema: string[]; behavior: string[]; view: string[] };
|
|
21
|
+
}
|
|
22
|
+
const G = grammarJson as unknown as GrammarKeys;
|
|
23
|
+
|
|
24
|
+
/** 对象一级键:schema / behavior / view;title 给从属对象(subs.*)与浮层做标题 */
|
|
25
|
+
const OBJECT_TOP_KEYS = ['schema', 'behavior', 'view', 'title'] as const;
|
|
26
|
+
/** behavior 里编译器认、真源 objectKeys 没列全的键(types.ts 的 KitBehavior 有,规格 8.3 用到) */
|
|
27
|
+
const BEHAVIOR_EXTRA_KEYS = ['params', 'list'] as const;
|
|
28
|
+
/** 浮层声明键 */
|
|
29
|
+
const OVERLAY_KEYS = ['kind', 'title', 'class', 'behavior', 'view', 'schema', 'events', 'editOverlay', 'rowClick'] as const;
|
|
30
|
+
/** RecordDetail 的 record 角色多一个布局键:subsLayout(stack / tabs,E5) */
|
|
31
|
+
const RECORD_ROLE_KEYS = [...OBJECT_TOP_KEYS, 'subsLayout'] as const;
|
|
32
|
+
const TITLE_MAX = KIT_AI_WRITER_LIMITS.limits.titleMax;
|
|
33
|
+
const SUBTITLE_MAX = KIT_AI_WRITER_LIMITS.limits.subtitleMax;
|
|
34
|
+
/** page.breadcrumbs 项数上限(读真源 workspaceFrame.limits,缺省 8) */
|
|
35
|
+
const BREADCRUMBS_MAX: number = KIT_WORKSPACE_FRAME_LIMITS.limits.breadcrumbs;
|
|
36
|
+
const ID_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
37
|
+
/** 对象名保留字:core 页面变量名与 kit 锚点前缀 */
|
|
38
|
+
const RESERVED_OBJECT_NAMES: readonly string[] = ['frame', 'tabs', 'page', 'p', 'ctrl'];
|
|
39
|
+
|
|
40
|
+
function checkObjectName(name: string, path: string, out: KitDiagnostic[]): void {
|
|
41
|
+
if (RESERVED_OBJECT_NAMES.includes(name)) {
|
|
42
|
+
out.push({ code: 'KIT-PAGE-005', path, message: `对象名 ${name} 是保留名(${RESERVED_OBJECT_NAMES.join(' / ')})` });
|
|
43
|
+
} else if (!ID_RE.test(name)) {
|
|
44
|
+
out.push({ code: 'KIT-PAGE-005', path, message: `对象名 ${name} 只能是字母开头的字母数字下划线` });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function isRecord(v: unknown): v is Record<string, unknown> {
|
|
49
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function unknownKeys(obj: Record<string, unknown>, allowed: readonly string[], path: string, out: KitDiagnostic[]): void {
|
|
53
|
+
for (const k of Object.keys(obj)) {
|
|
54
|
+
if (!allowed.includes(k)) {
|
|
55
|
+
out.push({ code: 'KIT-PAGE-001', path: `${path}.${k}`, message: `未知键 ${k}(${path} 允许:${allowed.join(' / ')})` });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function shape(path: string, message: string, out: KitDiagnostic[]): void {
|
|
61
|
+
out.push({ code: 'KIT-PAGE-004', path, message });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function checkClassMap(v: unknown, path: string, out: KitDiagnostic[]): Record<string, string> | undefined {
|
|
65
|
+
if (v === undefined) return undefined;
|
|
66
|
+
if (!isRecord(v)) {
|
|
67
|
+
shape(path, `${path} 必须是 { 名字: Tailwind 类串 }`, out);
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const res: Record<string, string> = {};
|
|
71
|
+
for (const [k, val] of Object.entries(v)) {
|
|
72
|
+
if (typeof val !== 'string') shape(`${path}.${k}`, `${path}.${k} 必须是类串`, out);
|
|
73
|
+
else res[k] = val;
|
|
74
|
+
}
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function checkObjectDecl(obj: unknown, path: string, out: KitDiagnostic[], allowTop: readonly string[]): void {
|
|
79
|
+
if (!isRecord(obj)) {
|
|
80
|
+
shape(path, `${path} 必须是对象声明(schema / behavior / view)`, out);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
unknownKeys(obj, allowTop, path, out);
|
|
84
|
+
if (isRecord(obj.schema)) {
|
|
85
|
+
for (const [f, def] of Object.entries(obj.schema)) {
|
|
86
|
+
if (f.includes('.')) {
|
|
87
|
+
out.push({ code: 'KIT-PAGE-005', path: `${path}.schema.${f}`, message: `字段名 ${f} 含点号(会与 _event 选择器分段冲突)` });
|
|
88
|
+
}
|
|
89
|
+
if (isRecord(def)) unknownKeys(def, G.objectKeys.schema, `${path}.schema.${f}`, out);
|
|
90
|
+
else shape(`${path}.schema.${f}`, '字段声明必须是对象', out);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (isRecord(obj.behavior)) {
|
|
94
|
+
unknownKeys(obj.behavior, [...G.objectKeys.behavior, ...BEHAVIOR_EXTRA_KEYS], `${path}.behavior`, out);
|
|
95
|
+
const actions = obj.behavior.actions;
|
|
96
|
+
if (Array.isArray(actions)) {
|
|
97
|
+
actions.forEach((a, i) => {
|
|
98
|
+
if (isRecord(a)) unknownKeys(a, G.actionKeys, `${path}.behavior.actions[${i}]`, out);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProductDecl | undefined {
|
|
105
|
+
if (!isRecord(raw)) {
|
|
106
|
+
shape(path, `${path} 必须是产品声明 { kind, objects, class?, areaClass? }`, out);
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
unknownKeys(raw, G.productKeys, path, out);
|
|
110
|
+
if (typeof raw.kind !== 'string' || raw.kind === '') {
|
|
111
|
+
shape(`${path}.kind`, `${path}.kind 必须是业务组件名`, out);
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
const objects = raw.objects;
|
|
115
|
+
if (!isRecord(objects)) {
|
|
116
|
+
shape(`${path}.objects`, `${path}.objects 必须是对象角色表`, out);
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
for (const [role, val] of Object.entries(objects)) {
|
|
120
|
+
const rp = `${path}.objects.${role}`;
|
|
121
|
+
checkObjectName(role, rp, out);
|
|
122
|
+
if (role === 'overlays') {
|
|
123
|
+
if (!isRecord(val)) {
|
|
124
|
+
shape(rp, 'overlays 必须是 { 浮层名: 声明 }', out);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
for (const [name, decl] of Object.entries(val)) {
|
|
128
|
+
checkObjectName(name, `${rp}.${name}`, out);
|
|
129
|
+
checkObjectDecl(decl, `${rp}.${name}`, out, OVERLAY_KEYS);
|
|
130
|
+
}
|
|
131
|
+
} else if (isRecord(val) && !('schema' in val) && !('behavior' in val) && !('view' in val) && Object.keys(val).length > 0
|
|
132
|
+
&& Object.values(val).every(isRecord)) {
|
|
133
|
+
// 对象表(如 subs.*):每项是一个对象
|
|
134
|
+
for (const [name, sub] of Object.entries(val)) checkObjectName(name, `${rp}.${name}`, out);
|
|
135
|
+
// MultiObjectBoard 的 panels.*:面板宽度 span(1~12)与面板外框 class 由业务组件解释
|
|
136
|
+
const keys = role === 'panels' ? [...OBJECT_TOP_KEYS, 'span', 'class'] as const : role === 'steps' ? [...OBJECT_TOP_KEYS, 'gate'] as const : OBJECT_TOP_KEYS;
|
|
137
|
+
for (const [name, sub] of Object.entries(val)) checkObjectDecl(sub, `${rp}.${name}`, out, keys);
|
|
138
|
+
} else {
|
|
139
|
+
checkObjectDecl(val, rp, out, role === 'record' ? RECORD_ROLE_KEYS : OBJECT_TOP_KEYS);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const decl: KitProductDecl = { kind: raw.kind, objects };
|
|
143
|
+
if (raw.theme !== undefined) {
|
|
144
|
+
const themeIssues = checkBlockTheme(raw.theme, `${path}.theme`);
|
|
145
|
+
if (themeIssues.length > 0) out.push(...blockThemeKitDiagnostics(themeIssues));
|
|
146
|
+
else decl.theme = raw.theme as KitProductDecl['theme'];
|
|
147
|
+
}
|
|
148
|
+
if (typeof raw.class === 'string') decl.class = raw.class;
|
|
149
|
+
else if (raw.class !== undefined) shape(`${path}.class`, `${path}.class 必须是类串`, out);
|
|
150
|
+
const areaClass = checkClassMap(raw.areaClass, `${path}.areaClass`, out);
|
|
151
|
+
if (areaClass) decl.areaClass = areaClass;
|
|
152
|
+
if (raw.config !== undefined) {
|
|
153
|
+
if (!isRecord(raw.config)) shape(`${path}.config`, `${path}.config 必须是对象(业务组件专属配置)`, out);
|
|
154
|
+
else decl.config = raw.config;
|
|
155
|
+
}
|
|
156
|
+
return decl;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[]): KitTabDecl[] {
|
|
160
|
+
const tabs: KitTabDecl[] = [];
|
|
161
|
+
const seen = new Set<string>();
|
|
162
|
+
raw.forEach((t, i) => {
|
|
163
|
+
const tp = `${path}[${i}]`;
|
|
164
|
+
if (!isRecord(t)) {
|
|
165
|
+
shape(tp, '页签必须是 { id, title, product }', out);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
unknownKeys(t, ['id', 'title', 'product'], tp, out);
|
|
169
|
+
const id = t.id;
|
|
170
|
+
if (typeof id !== 'string' || !ID_RE.test(id)) {
|
|
171
|
+
shape(`${tp}.id`, '页签 id 必须是字母数字下划线', out);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (seen.has(id)) {
|
|
175
|
+
shape(`${tp}.id`, `页签 id ${id} 重复`, out);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
// 页签 id 是锚点前缀,也是按 id 取槽的键:保留名(尤其 tabs,会覆盖页签数组槽)一律拒收
|
|
179
|
+
if (RESERVED_OBJECT_NAMES.includes(id)) {
|
|
180
|
+
out.push({ code: 'KIT-PAGE-005', path: `${tp}.id`, message: `页签 id ${id} 是保留名(${RESERVED_OBJECT_NAMES.join(' / ')})` });
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
seen.add(id);
|
|
184
|
+
if (typeof t.title !== 'string' || t.title === '') {
|
|
185
|
+
shape(`${tp}.title`, '页签 title 必须是非空字符串', out);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const product = parseProduct(t.product, `${tp}.product`, out);
|
|
189
|
+
if (product) tabs.push({ id, title: t.title, product });
|
|
190
|
+
});
|
|
191
|
+
return tabs;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 解析并检查一份页面声明。有任何诊断就不要继续编译。
|
|
196
|
+
* 顶层键 page / frame / product;product 等价于 frame.slots.main;frame 缺省为 single-frame。
|
|
197
|
+
*/
|
|
198
|
+
export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPageDecl | undefined {
|
|
199
|
+
const before = diagnostics.length;
|
|
200
|
+
if (!isRecord(raw)) {
|
|
201
|
+
shape('$', '页面声明必须是对象(page / frame / product)', diagnostics);
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
unknownKeys(raw, G.pageTopKeys, '$', diagnostics);
|
|
205
|
+
|
|
206
|
+
const page = raw.page;
|
|
207
|
+
let meta: KitPageDecl['page'] | undefined;
|
|
208
|
+
let isRedirect = false;
|
|
209
|
+
if (!isRecord(page)) {
|
|
210
|
+
shape('page', 'page 必须是对象 { url, title, subtitle?, roles? }', diagnostics);
|
|
211
|
+
} else {
|
|
212
|
+
unknownKeys(page, G.pageKeys, 'page', diagnostics);
|
|
213
|
+
const { url, title, subtitle, roles, eyebrow, breadcrumbs, redirect } = page;
|
|
214
|
+
// 内置页面类型:跳转页(page.redirect);不写 product / frame.slots
|
|
215
|
+
const redirectDecl = redirect === undefined ? undefined : parseRedirect(redirect, diagnostics);
|
|
216
|
+
if (redirect !== undefined && (raw.product !== undefined || (isRecord(raw.frame) && raw.frame.slots !== undefined))) {
|
|
217
|
+
shape('page.redirect', '跳转页(page.redirect)不写 product / frame.slots', diagnostics);
|
|
218
|
+
}
|
|
219
|
+
isRedirect = redirect !== undefined;
|
|
220
|
+
// 页头扩展(F1):actions / back / status / max_width / sticky,解析在 frames/page-header.ts
|
|
221
|
+
const header = parsePageHeader(page, diagnostics);
|
|
222
|
+
let crumbs: Array<{ label: string; href?: string }> | undefined;
|
|
223
|
+
if (breadcrumbs !== undefined) {
|
|
224
|
+
if (!Array.isArray(breadcrumbs) || breadcrumbs.length === 0 || breadcrumbs.length > BREADCRUMBS_MAX) {
|
|
225
|
+
shape('page.breadcrumbs', `page.breadcrumbs 必须是 1..${BREADCRUMBS_MAX} 项的 [{ label, href? }]`, diagnostics);
|
|
226
|
+
} else {
|
|
227
|
+
crumbs = [];
|
|
228
|
+
breadcrumbs.forEach((b, i) => {
|
|
229
|
+
if (!isRecord(b) || typeof b.label !== 'string' || b.label.trim() === '' || (b.href !== undefined && typeof b.href !== 'string')) {
|
|
230
|
+
shape(`page.breadcrumbs[${i}]`, 'page.breadcrumbs 的每一项必须是 { label: 字符串, href?: 字符串 }', diagnostics);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const keys = Object.keys(b).filter((k) => k !== 'label' && k !== 'href');
|
|
234
|
+
if (keys.length > 0) shape(`page.breadcrumbs[${i}]`, `page.breadcrumbs 的项只许 label / href,多余:${keys.join(' / ')}`, diagnostics);
|
|
235
|
+
crumbs!.push(typeof b.href === 'string' ? { label: b.label, href: b.href } : { label: b.label });
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (eyebrow !== undefined) {
|
|
240
|
+
if (typeof eyebrow !== 'string') shape('page.eyebrow', 'page.eyebrow 必须是字符串', diagnostics);
|
|
241
|
+
else if ([...eyebrow].length > TITLE_MAX) {
|
|
242
|
+
diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.eyebrow', message: `page.eyebrow 不得超过 ${TITLE_MAX} 字` });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (typeof url !== 'string' || !url.startsWith('/')) shape('page.url', 'page.url 必须是以 / 开头的路径', diagnostics);
|
|
246
|
+
if (typeof title !== 'string' || title.trim() === '') {
|
|
247
|
+
diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.title', message: 'page.title 必填' });
|
|
248
|
+
} else if ([...title].length > TITLE_MAX) {
|
|
249
|
+
diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.title', message: `page.title 不得超过 ${TITLE_MAX} 字` });
|
|
250
|
+
}
|
|
251
|
+
if (subtitle !== undefined) {
|
|
252
|
+
if (typeof subtitle !== 'string') shape('page.subtitle', 'page.subtitle 必须是字符串', diagnostics);
|
|
253
|
+
else if ([...subtitle].length > SUBTITLE_MAX) {
|
|
254
|
+
diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.subtitle', message: `page.subtitle 不得超过 ${SUBTITLE_MAX} 字` });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (roles !== undefined && !(Array.isArray(roles) && roles.every((r) => typeof r === 'string'))) {
|
|
258
|
+
shape('page.roles', 'page.roles 必须是字符串数组', diagnostics);
|
|
259
|
+
}
|
|
260
|
+
// 页面语言与书写方向(N5):locale 写进页面根 lang,dir 缺省按语言推导
|
|
261
|
+
const rawLocale = page.locale;
|
|
262
|
+
const rawDir = page.dir;
|
|
263
|
+
if (rawLocale !== undefined && (typeof rawLocale !== 'string' || !/^[A-Za-z]{2,3}([-_][A-Za-z0-9]{2,8})*$/.test(rawLocale))) {
|
|
264
|
+
shape('page.locale', 'page.locale 必须是语言标签(如 zh-CN / en / ar)', diagnostics);
|
|
265
|
+
}
|
|
266
|
+
if (rawDir !== undefined && rawDir !== 'ltr' && rawDir !== 'rtl') shape('page.dir', 'page.dir 只许 ltr / rtl', diagnostics);
|
|
267
|
+
if (raw.locales !== undefined) {
|
|
268
|
+
const lc = raw.locales;
|
|
269
|
+
const ok = isRecord(lc) && Object.values(lc).every((t) => isRecord(t) && Object.values(t).every((s) => typeof s === 'string'));
|
|
270
|
+
if (!ok) shape('locales', 'locales 必须是 { 语言: { 词条键: 文案字符串 } }', diagnostics);
|
|
271
|
+
}
|
|
272
|
+
if (typeof url === 'string' && typeof title === 'string') {
|
|
273
|
+
meta = { url, title };
|
|
274
|
+
if (typeof rawLocale === 'string') meta.locale = rawLocale;
|
|
275
|
+
if (rawDir === 'ltr' || rawDir === 'rtl') meta.dir = rawDir;
|
|
276
|
+
if (typeof subtitle === 'string') meta.subtitle = subtitle;
|
|
277
|
+
if (typeof eyebrow === 'string' && eyebrow !== '') meta.eyebrow = eyebrow;
|
|
278
|
+
if (Array.isArray(roles)) meta.roles = roles.filter((r): r is string => typeof r === 'string');
|
|
279
|
+
if (crumbs !== undefined && crumbs.length > 0) meta.breadcrumbs = crumbs;
|
|
280
|
+
if (redirectDecl !== undefined) meta.redirect = redirectDecl;
|
|
281
|
+
Object.assign(meta, header);
|
|
282
|
+
Object.assign(meta, parsePageParams(page, url, diagnostics));
|
|
283
|
+
if (page.envelope !== undefined) {
|
|
284
|
+
const env = parseKitEnvelope(page.envelope, 'page.envelope', 'KIT-PAGE-004', diagnostics);
|
|
285
|
+
if (env !== undefined) meta.envelope = env;
|
|
286
|
+
}
|
|
287
|
+
if (page.theme !== undefined) {
|
|
288
|
+
const themeIssues = checkBlockTheme(page.theme, 'page.theme');
|
|
289
|
+
if (themeIssues.length > 0) diagnostics.push(...blockThemeKitDiagnostics(themeIssues));
|
|
290
|
+
else meta.theme = page.theme as NonNullable<KitPageDecl['page']['theme']>;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// frame
|
|
296
|
+
let frameKind = 'single-frame';
|
|
297
|
+
let frameClass: string | undefined;
|
|
298
|
+
let slotClass: Record<string, string> | undefined;
|
|
299
|
+
let frameConfig: Record<string, unknown> | undefined;
|
|
300
|
+
const slots: Record<string, KitProductDecl | KitTabDecl[]> = {};
|
|
301
|
+
if (raw.frame !== undefined) {
|
|
302
|
+
if (!isRecord(raw.frame)) {
|
|
303
|
+
shape('frame', 'frame 必须是对象 { kind, class?, slotClass?, slots? }', diagnostics);
|
|
304
|
+
} else {
|
|
305
|
+
const f = raw.frame;
|
|
306
|
+
unknownKeys(f, G.frameKeys, 'frame', diagnostics);
|
|
307
|
+
if (f.kind !== undefined) {
|
|
308
|
+
if (typeof f.kind === 'string' && f.kind !== '') frameKind = f.kind;
|
|
309
|
+
else shape('frame.kind', 'frame.kind 必须是页面框名', diagnostics);
|
|
310
|
+
}
|
|
311
|
+
if (typeof f.class === 'string') frameClass = f.class;
|
|
312
|
+
else if (f.class !== undefined) shape('frame.class', 'frame.class 必须是类串', diagnostics);
|
|
313
|
+
slotClass = checkClassMap(f.slotClass, 'frame.slotClass', diagnostics);
|
|
314
|
+
if (f.config !== undefined) {
|
|
315
|
+
if (!isRecord(f.config)) shape('frame.config', 'frame.config 必须是对象(页面框配置)', diagnostics);
|
|
316
|
+
else frameConfig = f.config;
|
|
317
|
+
}
|
|
318
|
+
if (f.slots !== undefined) {
|
|
319
|
+
if (!isRecord(f.slots)) shape('frame.slots', 'frame.slots 必须是 { 槽名: 产品 | 页签数组 }', diagnostics);
|
|
320
|
+
else {
|
|
321
|
+
for (const [slot, val] of Object.entries(f.slots)) {
|
|
322
|
+
if (!ID_RE.test(slot)) {
|
|
323
|
+
diagnostics.push({ code: 'KIT-PAGE-005', path: `frame.slots.${slot}`, message: `槽名 ${slot} 只能是字母开头的字母数字下划线` });
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (Array.isArray(val)) slots[slot] = parseTabs(val, `frame.slots.${slot}`, diagnostics);
|
|
327
|
+
else {
|
|
328
|
+
const p = parseProduct(val, `frame.slots.${slot}`, diagnostics);
|
|
329
|
+
if (p) slots[slot] = p;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// product -> main 槽
|
|
338
|
+
if (raw.product !== undefined) {
|
|
339
|
+
const p = parseProduct(raw.product, 'product', diagnostics);
|
|
340
|
+
if (p) {
|
|
341
|
+
if ('main' in slots) shape('product', 'product 与 frame.slots.main 不能同时写', diagnostics);
|
|
342
|
+
else slots.main = p;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (Object.keys(slots).length === 0 && diagnostics.length === before && !isRedirect && !(frameConfig !== undefined && frameKind === 'workspace-frame')) {
|
|
346
|
+
shape('product', '页面至少要有一个产品(product 或 frame.slots.*)', diagnostics);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (diagnostics.length > before || meta === undefined) return undefined;
|
|
350
|
+
const frame: KitPageDecl['frame'] = { kind: frameKind, slots };
|
|
351
|
+
if (frameClass !== undefined) frame.class = frameClass;
|
|
352
|
+
if (slotClass !== undefined) frame.slotClass = slotClass;
|
|
353
|
+
if (frameConfig !== undefined) frame.config = frameConfig;
|
|
354
|
+
return { page: meta, frame };
|
|
355
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// 内置页面类型:跳转页(page.redirect)。
|
|
2
|
+
//
|
|
3
|
+
// 页面 DSL:
|
|
4
|
+
// page:
|
|
5
|
+
// url: /auth-manage/route
|
|
6
|
+
// title: 菜单管理
|
|
7
|
+
// redirect: { to: /auth-manage/menu, replace: true, query: true, message: 路由列表已并入菜单管理,正在跳转。 }
|
|
8
|
+
// 不写 product / frame.slots;页面外壳(页头)照常由 frame 编出,页面体是一个 KitRedirect 实例 + 一条 <noscript> 兜底链接。
|
|
9
|
+
// 目标只收站内绝对路径(safeRedirectTarget,防开放重定向);规则与限值读真源 kit-grammar.json#redirectPage。
|
|
10
|
+
|
|
11
|
+
import { KIT_REDIRECT } from '../object-renderer/defaults';
|
|
12
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
13
|
+
import { safeRedirectTarget } from '../data/redirect';
|
|
14
|
+
import type { KitFragment } from './fragment';
|
|
15
|
+
|
|
16
|
+
export interface KitRedirectDecl {
|
|
17
|
+
to: string;
|
|
18
|
+
replace: boolean;
|
|
19
|
+
/** true = 透传全部 search + hash;字符串数组 = 只透传这些 search 键;false = 不透传 */
|
|
20
|
+
query: boolean | string[];
|
|
21
|
+
message: string;
|
|
22
|
+
linkLabel: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isRec(v: unknown): v is Record<string, unknown> {
|
|
26
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 解析并检查 page.redirect;有问题记 KIT-PAGE-004 / KIT-PAGE-001 并返回 undefined */
|
|
30
|
+
export function parseRedirect(raw: unknown, diagnostics: KitDiagnostic[]): KitRedirectDecl | undefined {
|
|
31
|
+
const path = 'page.redirect';
|
|
32
|
+
const before = diagnostics.length;
|
|
33
|
+
const shape = (p: string, message: string): void => { diagnostics.push({ code: 'KIT-PAGE-004', path: p, message }); };
|
|
34
|
+
if (!isRec(raw)) {
|
|
35
|
+
shape(path, 'page.redirect 必须是 { to, replace?, query?, message?, linkLabel? }');
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
for (const k of Object.keys(raw)) {
|
|
39
|
+
if (!KIT_REDIRECT.keys.includes(k)) {
|
|
40
|
+
diagnostics.push({ code: 'KIT-PAGE-001', path: `${path}.${k}`, message: `未知键 ${k}(${path} 允许:${KIT_REDIRECT.keys.join(' / ')})` });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const to = typeof raw.to === 'string' ? safeRedirectTarget(raw.to) : '';
|
|
44
|
+
if (to === '') shape(`${path}.to`, 'redirect.to 必须是站内绝对路径(单个 / 开头,不是 //,不含反斜杠)');
|
|
45
|
+
let replace = KIT_REDIRECT.defaults.replace;
|
|
46
|
+
if (raw.replace !== undefined) {
|
|
47
|
+
if (typeof raw.replace === 'boolean') replace = raw.replace;
|
|
48
|
+
else shape(`${path}.replace`, 'redirect.replace 必须是布尔');
|
|
49
|
+
}
|
|
50
|
+
let query: boolean | string[] = KIT_REDIRECT.defaults.query;
|
|
51
|
+
if (raw.query !== undefined) {
|
|
52
|
+
if (typeof raw.query === 'boolean') query = raw.query;
|
|
53
|
+
else if (Array.isArray(raw.query) && raw.query.every((k) => typeof k === 'string' && k !== '')) query = raw.query as string[];
|
|
54
|
+
else shape(`${path}.query`, 'redirect.query 必须是布尔或非空字符串数组');
|
|
55
|
+
}
|
|
56
|
+
const text = (key: 'message' | 'linkLabel'): string => {
|
|
57
|
+
const v = raw[key];
|
|
58
|
+
if (v === undefined) return KIT_REDIRECT.defaults[key];
|
|
59
|
+
if (typeof v === 'string') return v;
|
|
60
|
+
shape(`${path}.${key}`, `redirect.${key} 必须是字符串`);
|
|
61
|
+
return KIT_REDIRECT.defaults[key];
|
|
62
|
+
};
|
|
63
|
+
const message = text('message');
|
|
64
|
+
const linkLabel = text('linkLabel');
|
|
65
|
+
if (diagnostics.length > before) return undefined;
|
|
66
|
+
return { to, replace, query, message, linkLabel };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const esc = (s: string): string => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
70
|
+
|
|
71
|
+
/** 跳转页的页面体片段:KitRedirect 实例 + <noscript> 兜底链接 */
|
|
72
|
+
export function redirectFragment(decl: KitRedirectDecl): KitFragment {
|
|
73
|
+
const id = 'redirect';
|
|
74
|
+
const props: Record<string, unknown> = {
|
|
75
|
+
to: decl.to,
|
|
76
|
+
replace: decl.replace,
|
|
77
|
+
message: decl.message,
|
|
78
|
+
linkLabel: decl.linkLabel,
|
|
79
|
+
...(decl.query === true ? { pass_all: true } : Array.isArray(decl.query) ? { pass_keys: decl.query } : {}),
|
|
80
|
+
};
|
|
81
|
+
const fallback = `<noscript><p><a href="${esc(decl.to)}">${esc(decl.linkLabel)}</a></p></noscript>`;
|
|
82
|
+
return {
|
|
83
|
+
html: `<div data-soma-component="KitRedirect" data-soma-id="${id}"></div>${fallback}`,
|
|
84
|
+
ui: { show: { [id]: { props } } },
|
|
85
|
+
events: {},
|
|
86
|
+
components: ['KitRedirect'],
|
|
87
|
+
candidates: [],
|
|
88
|
+
diagnostics: [],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// 页面框与业务组件的注册表查询:内置闭集 + 应用扩展(应用的同名项优先,但应用装配期已核对不静默覆盖)。
|
|
2
|
+
|
|
3
|
+
import { KIT_BIZ_COMPONENTS } from '../biz';
|
|
4
|
+
import type { KitBizDefinition } from '../biz/types';
|
|
5
|
+
import { KIT_FRAMES } from '../frames';
|
|
6
|
+
import type { KitFrameDefinition } from '../frames/types';
|
|
7
|
+
import type { KitAppContext } from './types';
|
|
8
|
+
|
|
9
|
+
export function resolveFrame(kind: string, app: KitAppContext): KitFrameDefinition | undefined {
|
|
10
|
+
const own = app.frames !== undefined && Object.prototype.hasOwnProperty.call(app.frames, kind) ? app.frames[kind] : undefined;
|
|
11
|
+
if (own !== undefined) return own;
|
|
12
|
+
return Object.prototype.hasOwnProperty.call(KIT_FRAMES, kind) ? KIT_FRAMES[kind] : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function resolveBiz(kind: string, app: KitAppContext): KitBizDefinition | undefined {
|
|
16
|
+
const own = app.bizComponents !== undefined && Object.prototype.hasOwnProperty.call(app.bizComponents, kind) ? app.bizComponents[kind] : undefined;
|
|
17
|
+
if (own !== undefined) return own;
|
|
18
|
+
return Object.prototype.hasOwnProperty.call(KIT_BIZ_COMPONENTS, kind) ? KIT_BIZ_COMPONENTS[kind] : undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 业务组件壳依赖的协作数据组件(KitCrudBridge 等):实现在 biz/data-components(浏览器面直接取那里),这里再导出 */
|
|
22
|
+
export { bizDataComponents } from '../biz/data-components';
|
|
23
|
+
|
|
24
|
+
export function frameKinds(app: KitAppContext): string[] {
|
|
25
|
+
return [...new Set([...Object.keys(KIT_FRAMES), ...Object.keys(app.frames ?? {})])].sort();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function bizKinds(app: KitAppContext): string[] {
|
|
29
|
+
return [...new Set([...Object.keys(KIT_BIZ_COMPONENTS), ...Object.keys(app.bizComponents ?? {})])].sort();
|
|
30
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// 删除动作(builtin: remove)的二次确认守卫(Q 波 G2,KIT-ACT-001;人写页与 AI 页共用)。
|
|
2
|
+
//
|
|
3
|
+
// 规则:对象里每个 `builtin: remove` 的动作——
|
|
4
|
+
// · 所属对象必须声明 behavior.write.delete(删除通道),否则 KIT-ACT-001;
|
|
5
|
+
// · confirm 写成空串(想关掉确认)KIT-ACT-001;没写 confirm 时编译器补默认确认词条 soma.kit.confirm_remove(按页面语言);
|
|
6
|
+
// · tone 缺省补 danger(写了别的色调尊重人写)。
|
|
7
|
+
// 确认尾段 `confirm:` 由事件编译(pipeTails / actionPipeline)按动作的 confirm 写出,这里只保证 remove 一定带着非空 confirm 进去。
|
|
8
|
+
// 只改动作,不改入参:有改动时返回新的输入(对象与动作数组浅拷贝),没有改动返回原引用。
|
|
9
|
+
import type { KitBizInput } from '../biz/types';
|
|
10
|
+
import { interpolate } from 'soma-core/i18n';
|
|
11
|
+
import { kitText } from '../i18n/kit-text';
|
|
12
|
+
import { KIT_GRAMMAR } from '../object-renderer/defaults';
|
|
13
|
+
import type { KitAction, KitDiagnostic, KitObject } from '../object-renderer/types';
|
|
14
|
+
|
|
15
|
+
const isRec = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
16
|
+
const isObjectDecl = (v: unknown): v is KitObject => isRec(v) && (isRec(v.schema) || isRec(v.behavior) || isRec(v.view));
|
|
17
|
+
|
|
18
|
+
function hasDeleteChannel(obj: KitObject): boolean {
|
|
19
|
+
const write: unknown = obj.behavior?.write;
|
|
20
|
+
return isRec(write) && typeof write.delete === 'string' && write.delete !== '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const TITLE_FIELDS = (KIT_GRAMMAR.actionBuiltins as unknown as { removeTitleFields: readonly string[] }).removeTitleFields;
|
|
24
|
+
|
|
25
|
+
/** 对象的标题字段:schema 里按 removeTitleFields 的顺序取第一个存在的字段;没有返回 undefined */
|
|
26
|
+
export function removeTitleFieldOf(obj: KitObject): string | undefined {
|
|
27
|
+
return TITLE_FIELDS.find((f) => isRec(obj.schema) && f in obj.schema);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 确认文案里的行占位 `{字段}`(按出现顺序去重);没有返回空数组 */
|
|
31
|
+
export function removeConfirmPlaceholders(confirm: string | undefined): string[] {
|
|
32
|
+
if (confirm === undefined) return [];
|
|
33
|
+
return [...new Set([...confirm.matchAll(/\{([^{}]+)\}/g)].map((m) => m[1]!))];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function guardObject(obj: KitObject, at: string, locale: string, out: KitDiagnostic[]): KitObject {
|
|
37
|
+
const actions = obj.behavior?.actions;
|
|
38
|
+
if (!Array.isArray(actions) || !actions.some((a) => a?.builtin === 'remove')) return obj;
|
|
39
|
+
const deletable = hasDeleteChannel(obj);
|
|
40
|
+
const next: KitAction[] = actions.map((a, i) => {
|
|
41
|
+
if (a?.builtin !== 'remove') return a;
|
|
42
|
+
const aat = `${at}.behavior.actions[${i}]`;
|
|
43
|
+
if (!deletable) {
|
|
44
|
+
out.push({ code: 'KIT-ACT-001', path: aat, message: `动作 ${a.id} 是删除(remove),但对象没有声明 behavior.write.delete:删除没有写通道` });
|
|
45
|
+
}
|
|
46
|
+
if (typeof a.confirm === 'string' && a.confirm.trim() === '') {
|
|
47
|
+
out.push({ code: 'KIT-ACT-001', path: `${aat}.confirm`, message: `动作 ${a.id} 是删除(remove),confirm 不能是空串:删除必须二次确认` });
|
|
48
|
+
}
|
|
49
|
+
const plain = kitText('soma.kit.confirm_remove', undefined, locale);
|
|
50
|
+
const title = removeTitleFieldOf(obj);
|
|
51
|
+
let confirm = a.confirm === undefined || a.confirm === plain
|
|
52
|
+
// 缺省确认:有标题字段取带名字的文案,没有退回不带名字的
|
|
53
|
+
? (title !== undefined ? interpolate(kitText('soma.kit.confirm_remove_named', undefined, locale), { name: `{${title}}` }) : plain)
|
|
54
|
+
: a.confirm;
|
|
55
|
+
// {name} 指对象的 name 字段;对象没有 name 字段时指标题字段(没有标题字段则无处可取)
|
|
56
|
+
let nameReported = false;
|
|
57
|
+
if (confirm.includes('{name}') && !('name' in obj.schema)) {
|
|
58
|
+
if (title === undefined) {
|
|
59
|
+
nameReported = true;
|
|
60
|
+
out.push({ code: 'KIT-ACT-001', path: `${aat}.confirm`, message: `动作 ${a.id} 的 confirm 用了 {name},但对象没有标题字段(schema 里要有 ${TITLE_FIELDS.join(' / ')} 之一):去掉 {name},或改写成对象已有的字段占位` });
|
|
61
|
+
} else {
|
|
62
|
+
confirm = confirm.split('{name}').join(`{${title}}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const field of removeConfirmPlaceholders(confirm)) {
|
|
66
|
+
if (nameReported && field === 'name') continue;
|
|
67
|
+
if (!(field in obj.schema)) {
|
|
68
|
+
out.push({ code: 'KIT-ACT-001', path: `${aat}.confirm`, message: `动作 ${a.id} 的 confirm 里的占位 {${field}} 不是对象 schema 里的字段` });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { ...a, confirm, tone: a.tone ?? 'danger' };
|
|
72
|
+
});
|
|
73
|
+
return { ...obj, behavior: { ...obj.behavior, actions: next } };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 守卫一个业务组件输入里的全部对象(角色槽的单对象与对象表);浮层里的对象没有行动作,不处理 */
|
|
77
|
+
export function guardRemoveActions(input: KitBizInput, path: string, locale: string, out: KitDiagnostic[]): KitBizInput {
|
|
78
|
+
let changed = false;
|
|
79
|
+
const objects: KitBizInput['objects'] = {};
|
|
80
|
+
for (const [role, val] of Object.entries(input.objects)) {
|
|
81
|
+
const rp = `${path}.objects.${role}`;
|
|
82
|
+
if (isObjectDecl(val)) {
|
|
83
|
+
const g = guardObject(val, rp, locale, out);
|
|
84
|
+
if (g !== val) changed = true;
|
|
85
|
+
objects[role] = g;
|
|
86
|
+
} else if (isRec(val)) {
|
|
87
|
+
const table: Record<string, KitObject> = {};
|
|
88
|
+
for (const [name, obj] of Object.entries(val as Record<string, KitObject>)) {
|
|
89
|
+
const g = isObjectDecl(obj) ? guardObject(obj, `${rp}.${name}`, locale, out) : obj;
|
|
90
|
+
if (g !== obj) changed = true;
|
|
91
|
+
table[name] = g;
|
|
92
|
+
}
|
|
93
|
+
objects[role] = table;
|
|
94
|
+
} else {
|
|
95
|
+
objects[role] = val;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return changed ? { ...input, objects } : input;
|
|
99
|
+
}
|