soma-kit 0.1.11 → 0.1.13
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 +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -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 +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- 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 +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- 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 +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- 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 +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- 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 +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- 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/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -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 +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- 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/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -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/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- 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 +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -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 +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- 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 +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- 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 +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- 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 +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -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 +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -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 +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -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/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
package/src/compile/parse.ts
CHANGED
|
@@ -1,34 +1,100 @@
|
|
|
1
1
|
// 第 0 步:页面声明解析与闭集键检查(KIT-PAGE-001 / 003 / 004)。纯函数,不查注册表。
|
|
2
|
-
// 键闭集全部读 spec/kit-grammar.json
|
|
2
|
+
// 键闭集全部读 spec/kit-grammar.json;对象声明内部各层(schema / behavior / 动作 request·download·then / view 各槽 / fields[])
|
|
3
|
+
// 的闭集在 closed-set.ts 逐层查,写了闭集之外的键(含曾经的逻辑键)一律报错拒绝编译;字段级语义(type、component)归对象渲染内核校验。
|
|
3
4
|
|
|
5
|
+
import { isViewName } from '../object-renderer/view-binding';
|
|
4
6
|
import { KIT_AI_WRITER_LIMITS, KIT_WORKSPACE_FRAME_LIMITS } from 'soma-foundation/kit-limits';
|
|
5
7
|
import grammarJson from '../../spec/kit-grammar.json';
|
|
6
8
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
7
9
|
import type { KitPageDecl, KitProductDecl, KitTabDecl } from './types';
|
|
8
10
|
import { parseRedirect } from './redirect';
|
|
11
|
+
import { checkNoRelativeOrSystemPath, checkObjectClosedSet } from './closed-set';
|
|
9
12
|
import { blockThemeKitDiagnostics, checkBlockTheme } from '../theme/block-theme';
|
|
10
13
|
import { parsePageHeader } from '../frames/page-header';
|
|
11
14
|
import { parsePageParams } from './page-params';
|
|
12
|
-
import { parseKitEnvelope } from '../
|
|
15
|
+
import { parseKitEnvelope } from '../shared/envelope';
|
|
13
16
|
|
|
14
17
|
interface GrammarKeys {
|
|
15
18
|
pageTopKeys: string[];
|
|
16
19
|
pageKeys: string[];
|
|
17
20
|
frameKeys: string[];
|
|
18
21
|
productKeys: string[];
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
objectLayer: {
|
|
23
|
+
topKeys: string[];
|
|
24
|
+
recordRoleExtraKeys: string[];
|
|
25
|
+
overlayExtraKeys: string[];
|
|
26
|
+
containerEmphasis: string[];
|
|
27
|
+
surface: string[];
|
|
28
|
+
};
|
|
29
|
+
bizComponents: {
|
|
30
|
+
MultiObjectBoard: {
|
|
31
|
+
roles?: Record<string, { required?: boolean; views?: string[]; many?: boolean; extraKeys?: string[] }>;
|
|
32
|
+
panelKeys: string[];
|
|
33
|
+
areas?: string[];
|
|
34
|
+
};
|
|
35
|
+
[kind: string]: {
|
|
36
|
+
roles?: Record<string, { required?: boolean; views?: string[]; many?: boolean; extraKeys?: string[] }>;
|
|
37
|
+
panelKeys?: string[];
|
|
38
|
+
areas?: string[];
|
|
39
|
+
} | undefined;
|
|
40
|
+
};
|
|
21
41
|
}
|
|
22
|
-
const
|
|
42
|
+
const KIT_GRAMMAR = grammarJson as unknown as GrammarKeys;
|
|
43
|
+
const G = KIT_GRAMMAR;
|
|
23
44
|
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
const CONTAINER_EMPHASIS_VALUES: readonly string[] = KIT_GRAMMAR.objectLayer.containerEmphasis;
|
|
46
|
+
const SURFACE_RECIPE_VALUES: readonly string[] = KIT_GRAMMAR.objectLayer.surface;
|
|
47
|
+
|
|
48
|
+
/** 对象一级键:schema / behavior / view;title 给从属对象(subs.*)与浮层做标题(真源 KIT_GRAMMAR.objectLayer) */
|
|
49
|
+
const OBJECT_TOP_KEYS: readonly string[] = KIT_GRAMMAR.objectLayer.topKeys;
|
|
50
|
+
/** 浮层声明键(真源 KIT_GRAMMAR.objectLayer) */
|
|
51
|
+
const OVERLAY_KEYS: readonly string[] = [...KIT_GRAMMAR.objectLayer.topKeys, ...KIT_GRAMMAR.objectLayer.overlayExtraKeys];
|
|
52
|
+
/** RecordDetail 的 record 角色多一个布局键:subsLayout(stack / tabs,E5,真源 KIT_GRAMMAR.objectLayer) */
|
|
53
|
+
const RECORD_ROLE_KEYS: readonly string[] = [...KIT_GRAMMAR.objectLayer.topKeys, ...KIT_GRAMMAR.objectLayer.recordRoleExtraKeys];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 求解指定业务组件角色允许的对象顶层键(包含标准键与角色附加键 extraKeys)。
|
|
57
|
+
* 优先取应用装配/自定义组件(appRefs.bizComponents),未命中回退语法真源内置规则。
|
|
58
|
+
*/
|
|
59
|
+
function resolveRoleAllowedKeys(
|
|
60
|
+
kind: string,
|
|
61
|
+
role: string,
|
|
62
|
+
_isMany: boolean,
|
|
63
|
+
appRefs?: KitAppRefsContext,
|
|
64
|
+
): readonly string[] {
|
|
65
|
+
const customRole = appRefs?.bizComponents?.[kind]?.roles?.[role];
|
|
66
|
+
if (customRole !== undefined) {
|
|
67
|
+
return [...new Set([...OBJECT_TOP_KEYS, ...(customRole.extraKeys ?? [])])];
|
|
68
|
+
}
|
|
69
|
+
const builtinRole = KIT_GRAMMAR.bizComponents[kind]?.roles?.[role];
|
|
70
|
+
if (builtinRole?.extraKeys !== undefined) {
|
|
71
|
+
return [...new Set([...OBJECT_TOP_KEYS, ...builtinRole.extraKeys])];
|
|
72
|
+
}
|
|
73
|
+
return OBJECT_TOP_KEYS;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function resolveRoleAllowedKeysForRawObjects(
|
|
77
|
+
role: string,
|
|
78
|
+
appRefs?: KitAppRefsContext,
|
|
79
|
+
productKind?: string,
|
|
80
|
+
): readonly string[] {
|
|
81
|
+
if (productKind) {
|
|
82
|
+
return resolveRoleAllowedKeys(productKind, role, false, appRefs);
|
|
83
|
+
}
|
|
84
|
+
const customExtra = Object.values(appRefs?.bizComponents ?? {})
|
|
85
|
+
.find((c) => c?.roles?.[role]?.extraKeys !== undefined)
|
|
86
|
+
?.roles?.[role]?.extraKeys;
|
|
87
|
+
if (customExtra !== undefined) {
|
|
88
|
+
return [...new Set([...OBJECT_TOP_KEYS, ...customExtra])];
|
|
89
|
+
}
|
|
90
|
+
const builtinExtra = Object.values(KIT_GRAMMAR.bizComponents ?? {})
|
|
91
|
+
.find((c) => (c as { roles?: Record<string, { extraKeys?: string[] }> })?.roles?.[role]?.extraKeys !== undefined)
|
|
92
|
+
?.roles?.[role]?.extraKeys;
|
|
93
|
+
if (builtinExtra !== undefined) {
|
|
94
|
+
return [...new Set([...OBJECT_TOP_KEYS, ...builtinExtra])];
|
|
95
|
+
}
|
|
96
|
+
return OBJECT_TOP_KEYS;
|
|
97
|
+
}
|
|
32
98
|
const TITLE_MAX = KIT_AI_WRITER_LIMITS.limits.titleMax;
|
|
33
99
|
const SUBTITLE_MAX = KIT_AI_WRITER_LIMITS.limits.subtitleMax;
|
|
34
100
|
/** page.breadcrumbs 项数上限(读真源 workspaceFrame.limits,缺省 8) */
|
|
@@ -75,6 +141,222 @@ function checkClassMap(v: unknown, path: string, out: KitDiagnostic[]): Record<s
|
|
|
75
141
|
return res;
|
|
76
142
|
}
|
|
77
143
|
|
|
144
|
+
export interface KitAppRefsContext {
|
|
145
|
+
dicts?: Record<string, Array<{ value: string | number | boolean; label: string; tone?: string }>>;
|
|
146
|
+
entities?: Record<string, Record<string, unknown>>;
|
|
147
|
+
bizComponents?: Readonly<Record<string, { readonly roles?: Readonly<Record<string, { readonly many?: boolean; readonly extraKeys?: readonly string[] }>> }>>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 解析期特例:只给 frame.config、不写任何槽位也合法的页面框(自带整页内容,内容全由 config 驱动)。
|
|
152
|
+
* 解析发生在应用页面框登记表可得之前(parsePage 不接触 KitAppContext),无法读页面框能力字段,故保留框名比较、集中于此。
|
|
153
|
+
*/
|
|
154
|
+
const CONFIG_ONLY_FRAME_KIND = 'workspace-frame';
|
|
155
|
+
|
|
156
|
+
const ENTITY_REF_RE = /^\$entity\.([A-Za-z_][A-Za-z0-9_]*)$/;
|
|
157
|
+
const DICT_REF_RE = /^\$dict\.([A-Za-z_][A-Za-z0-9_]*)$/;
|
|
158
|
+
const SCHEMA_REF_KEYS = ['$ref', 'pick', 'omit', 'override'] as const;
|
|
159
|
+
|
|
160
|
+
function cloneFieldMap(src: Record<string, unknown>): Record<string, Record<string, unknown>> {
|
|
161
|
+
const out: Record<string, Record<string, unknown>> = {};
|
|
162
|
+
for (const [k, v] of Object.entries(src)) {
|
|
163
|
+
if (isRecord(v)) {
|
|
164
|
+
const copy: Record<string, unknown> = { ...v };
|
|
165
|
+
if (Array.isArray(v.options)) copy.options = v.options.map((o) => (isRecord(o) ? { ...o } : o));
|
|
166
|
+
if (Array.isArray(v.rules)) copy.rules = v.rules.map((r) => (isRecord(r) ? { ...r } : r));
|
|
167
|
+
out[k] = copy;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function hasStaticComponentInView(view: unknown): boolean {
|
|
174
|
+
if (!isRecord(view)) return false;
|
|
175
|
+
if (typeof view.staticComponent === 'string' && view.staticComponent !== '') return true;
|
|
176
|
+
for (const slot of ['list', 'summary', 'filter', 'form'] as const) {
|
|
177
|
+
const s = view[slot];
|
|
178
|
+
if (isRecord(s) && typeof s.staticComponent === 'string' && s.staticComponent !== '') return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function expandFieldDictOptions(
|
|
184
|
+
schema: Record<string, unknown>,
|
|
185
|
+
path: string,
|
|
186
|
+
appRefs: KitAppRefsContext | undefined,
|
|
187
|
+
out: KitDiagnostic[],
|
|
188
|
+
): void {
|
|
189
|
+
for (const [fieldName, fieldDef] of Object.entries(schema)) {
|
|
190
|
+
if (!isRecord(fieldDef) || typeof fieldDef.options !== 'string') continue;
|
|
191
|
+
const rawOpt = fieldDef.options.trim();
|
|
192
|
+
const m = DICT_REF_RE.exec(rawOpt);
|
|
193
|
+
if (!m) {
|
|
194
|
+
out.push({
|
|
195
|
+
code: 'KIT-FORM-003',
|
|
196
|
+
path: `${path}.schema.${fieldName}.options`,
|
|
197
|
+
message: `字段 ${fieldName} 的 options 字符串引用必须为 $dict.<字典名>(收到 "${fieldDef.options}")`,
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const dictName = m[1]!;
|
|
202
|
+
const dictItems = appRefs?.dicts?.[dictName];
|
|
203
|
+
if (!Array.isArray(dictItems) || dictItems.length === 0) {
|
|
204
|
+
out.push({
|
|
205
|
+
code: 'KIT-FORM-003',
|
|
206
|
+
path: `${path}.schema.${fieldName}.options`,
|
|
207
|
+
message: `字段 ${fieldName} 引用了未在 kit.app.yaml#dicts 声明的字典 $dict.${dictName}`,
|
|
208
|
+
});
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
fieldDef.options = dictItems.map((it) => ({ ...it }));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function expandObjectEntityAndDicts(
|
|
216
|
+
obj: Record<string, unknown>,
|
|
217
|
+
path: string,
|
|
218
|
+
appRefs: KitAppRefsContext | undefined,
|
|
219
|
+
out: KitDiagnostic[],
|
|
220
|
+
): void {
|
|
221
|
+
const rawSchema = obj.schema;
|
|
222
|
+
if (typeof rawSchema === 'string') {
|
|
223
|
+
const m = ENTITY_REF_RE.exec(rawSchema.trim());
|
|
224
|
+
if (!m) {
|
|
225
|
+
out.push({
|
|
226
|
+
code: 'KIT-OBJ-001',
|
|
227
|
+
path: `${path}.schema`,
|
|
228
|
+
message: `schema 字符串引用必须为 $entity.<实体名>(收到 "${rawSchema}")`,
|
|
229
|
+
});
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const entityName = m[1]!;
|
|
233
|
+
const entityDef = appRefs?.entities?.[entityName];
|
|
234
|
+
if (!isRecord(entityDef)) {
|
|
235
|
+
out.push({
|
|
236
|
+
code: 'KIT-OBJ-001',
|
|
237
|
+
path: `${path}.schema`,
|
|
238
|
+
message: `对象引用了未在 kit.app.yaml#entities 声明的实体 $entity.${entityName}`,
|
|
239
|
+
});
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const resolved = cloneFieldMap(entityDef);
|
|
243
|
+
expandFieldDictOptions(resolved, path, appRefs, out);
|
|
244
|
+
obj.schema = resolved;
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (isRecord(rawSchema) && '$ref' in rawSchema) {
|
|
249
|
+
unknownKeys(rawSchema, SCHEMA_REF_KEYS, `${path}.schema`, out);
|
|
250
|
+
const refStr = typeof rawSchema.$ref === 'string' ? rawSchema.$ref.trim() : '';
|
|
251
|
+
const m = ENTITY_REF_RE.exec(refStr);
|
|
252
|
+
if (!m) {
|
|
253
|
+
out.push({
|
|
254
|
+
code: 'KIT-OBJ-001',
|
|
255
|
+
path: `${path}.schema.$ref`,
|
|
256
|
+
message: `schema.$ref 必须为 $entity.<实体名>(收到 "${String(rawSchema.$ref)}")`,
|
|
257
|
+
});
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const entityName = m[1]!;
|
|
261
|
+
const entityDef = appRefs?.entities?.[entityName];
|
|
262
|
+
if (!isRecord(entityDef)) {
|
|
263
|
+
out.push({
|
|
264
|
+
code: 'KIT-OBJ-001',
|
|
265
|
+
path: `${path}.schema.$ref`,
|
|
266
|
+
message: `对象引用了未在 kit.app.yaml#entities 声明的实体 $entity.${entityName}`,
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const baseFields = cloneFieldMap(entityDef);
|
|
271
|
+
let selectedNames = Object.keys(baseFields);
|
|
272
|
+
if (rawSchema.pick !== undefined) {
|
|
273
|
+
if (!Array.isArray(rawSchema.pick) || rawSchema.pick.some((x) => typeof x !== 'string' || x === '')) {
|
|
274
|
+
shape(`${path}.schema.pick`, 'schema.pick 必须是非空字段名字符串数组', out);
|
|
275
|
+
} else {
|
|
276
|
+
const pickList = rawSchema.pick as string[];
|
|
277
|
+
for (const f of pickList) {
|
|
278
|
+
if (!(f in baseFields)) {
|
|
279
|
+
out.push({
|
|
280
|
+
code: 'KIT-OBJ-001',
|
|
281
|
+
path: `${path}.schema.pick`,
|
|
282
|
+
message: `schema.pick 引用了实体 $entity.${entityName} 中不存在的字段 ${f}`,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
selectedNames = pickList.filter((f) => f in baseFields);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (rawSchema.omit !== undefined) {
|
|
290
|
+
if (!Array.isArray(rawSchema.omit) || rawSchema.omit.some((x) => typeof x !== 'string' || x === '')) {
|
|
291
|
+
shape(`${path}.schema.omit`, 'schema.omit 必须是非空字段名字符串数组', out);
|
|
292
|
+
} else {
|
|
293
|
+
const omitSet = new Set(rawSchema.omit as string[]);
|
|
294
|
+
selectedNames = selectedNames.filter((f) => !omitSet.has(f));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const resolved: Record<string, Record<string, unknown>> = {};
|
|
298
|
+
for (const f of selectedNames) {
|
|
299
|
+
if (baseFields[f] !== undefined) resolved[f] = { ...baseFields[f]! };
|
|
300
|
+
}
|
|
301
|
+
if (rawSchema.override !== undefined) {
|
|
302
|
+
if (!isRecord(rawSchema.override)) {
|
|
303
|
+
shape(`${path}.schema.override`, 'schema.override 必须是 { 字段名: 覆写属性 } 对象', out);
|
|
304
|
+
} else {
|
|
305
|
+
for (const [fName, overDef] of Object.entries(rawSchema.override)) {
|
|
306
|
+
if (!isRecord(overDef)) {
|
|
307
|
+
shape(`${path}.schema.override.${fName}`, `schema.override.${fName} 必须是对象`, out);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
resolved[fName] = { ...(resolved[fName] ?? baseFields[fName] ?? {}), ...overDef };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
expandFieldDictOptions(resolved, path, appRefs, out);
|
|
315
|
+
obj.schema = resolved;
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (isRecord(rawSchema)) {
|
|
320
|
+
expandFieldDictOptions(rawSchema, path, appRefs, out);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function expandProductObjects(
|
|
325
|
+
objects: Record<string, unknown>,
|
|
326
|
+
path: string,
|
|
327
|
+
appRefs: KitAppRefsContext | undefined,
|
|
328
|
+
out: KitDiagnostic[],
|
|
329
|
+
): void {
|
|
330
|
+
// 1) 先展开所有非浮层角色对象的 $entity / $dict
|
|
331
|
+
for (const [role, val] of Object.entries(objects)) {
|
|
332
|
+
if (role === 'overlays') continue;
|
|
333
|
+
const rp = `${path}.objects.${role}`;
|
|
334
|
+
if (isRecord(val) && !('schema' in val) && !('behavior' in val) && !('view' in val) && Object.keys(val).length > 0 && Object.values(val).every(isRecord)) {
|
|
335
|
+
for (const [subName, subObj] of Object.entries(val)) {
|
|
336
|
+
if (isRecord(subObj)) expandObjectEntityAndDicts(subObj, `${rp}.${subName}`, appRefs, out);
|
|
337
|
+
}
|
|
338
|
+
} else if (isRecord(val)) {
|
|
339
|
+
expandObjectEntityAndDicts(val, rp, appRefs, out);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// 2) 确定主对象 schema,供未显式声明 schema 的关联浮层(overlays)继承
|
|
343
|
+
const mainCandidate = objects.entity ?? objects.master ?? objects.record ?? objects.target ?? objects.item
|
|
344
|
+
?? Object.entries(objects).find(([k, v]) => k !== 'overlays' && k !== 'subs' && isRecord(v) && isRecord(v.schema))?.[1];
|
|
345
|
+
const mainSchema = isRecord(mainCandidate) && isRecord(mainCandidate.schema) ? mainCandidate.schema : undefined;
|
|
346
|
+
|
|
347
|
+
if (isRecord(objects.overlays)) {
|
|
348
|
+
for (const [ovName, ovDecl] of Object.entries(objects.overlays)) {
|
|
349
|
+
if (!isRecord(ovDecl)) continue;
|
|
350
|
+
const ovPath = `${path}.objects.overlays.${ovName}`;
|
|
351
|
+
if (ovDecl.schema !== undefined) {
|
|
352
|
+
expandObjectEntityAndDicts(ovDecl, ovPath, appRefs, out);
|
|
353
|
+
} else if (mainSchema !== undefined && !hasStaticComponentInView(ovDecl.view)) {
|
|
354
|
+
ovDecl.schema = cloneFieldMap(mainSchema);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
78
360
|
function checkObjectDecl(obj: unknown, path: string, out: KitDiagnostic[], allowTop: readonly string[]): void {
|
|
79
361
|
if (!isRecord(obj)) {
|
|
80
362
|
shape(path, `${path} 必须是对象声明(schema / behavior / view)`, out);
|
|
@@ -86,22 +368,14 @@ function checkObjectDecl(obj: unknown, path: string, out: KitDiagnostic[], allow
|
|
|
86
368
|
if (f.includes('.')) {
|
|
87
369
|
out.push({ code: 'KIT-PAGE-005', path: `${path}.schema.${f}`, message: `字段名 ${f} 含点号(会与 _event 选择器分段冲突)` });
|
|
88
370
|
}
|
|
89
|
-
if (isRecord(def))
|
|
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
|
-
});
|
|
371
|
+
if (!isRecord(def)) shape(`${path}.schema.${f}`, '字段声明必须是对象', out);
|
|
100
372
|
}
|
|
101
373
|
}
|
|
374
|
+
// 各层闭集(schema 字段 / options / rules / default、behavior 与动作的 request / download / then、view 各槽与 fields[])
|
|
375
|
+
checkObjectClosedSet(obj, path, out);
|
|
102
376
|
}
|
|
103
377
|
|
|
104
|
-
function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProductDecl | undefined {
|
|
378
|
+
function parseProduct(raw: unknown, path: string, out: KitDiagnostic[], appRefs?: KitAppRefsContext): KitProductDecl | undefined {
|
|
105
379
|
if (!isRecord(raw)) {
|
|
106
380
|
shape(path, `${path} 必须是产品声明 { kind, objects, class?, areaClass? }`, out);
|
|
107
381
|
return undefined;
|
|
@@ -116,6 +390,7 @@ function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProd
|
|
|
116
390
|
shape(`${path}.objects`, `${path}.objects 必须是对象角色表`, out);
|
|
117
391
|
return undefined;
|
|
118
392
|
}
|
|
393
|
+
expandProductObjects(objects, path, appRefs, out);
|
|
119
394
|
for (const [role, val] of Object.entries(objects)) {
|
|
120
395
|
const rp = `${path}.objects.${role}`;
|
|
121
396
|
checkObjectName(role, rp, out);
|
|
@@ -132,11 +407,10 @@ function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProd
|
|
|
132
407
|
&& Object.values(val).every(isRecord)) {
|
|
133
408
|
// 对象表(如 subs.*):每项是一个对象
|
|
134
409
|
for (const [name, sub] of Object.entries(val)) checkObjectName(name, `${rp}.${name}`, out);
|
|
135
|
-
|
|
136
|
-
const keys = role === 'panels' ? [...OBJECT_TOP_KEYS, 'span', 'class'] as const : role === 'steps' ? [...OBJECT_TOP_KEYS, 'gate'] as const : OBJECT_TOP_KEYS;
|
|
410
|
+
const keys = resolveRoleAllowedKeys(raw.kind, role, true, appRefs);
|
|
137
411
|
for (const [name, sub] of Object.entries(val)) checkObjectDecl(sub, `${rp}.${name}`, out, keys);
|
|
138
412
|
} else {
|
|
139
|
-
checkObjectDecl(val, rp, out, role
|
|
413
|
+
checkObjectDecl(val, rp, out, resolveRoleAllowedKeys(raw.kind, role, false, appRefs));
|
|
140
414
|
}
|
|
141
415
|
}
|
|
142
416
|
const decl: KitProductDecl = { kind: raw.kind, objects };
|
|
@@ -153,10 +427,18 @@ function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProd
|
|
|
153
427
|
if (!isRecord(raw.config)) shape(`${path}.config`, `${path}.config 必须是对象(业务组件专属配置)`, out);
|
|
154
428
|
else decl.config = raw.config;
|
|
155
429
|
}
|
|
430
|
+
if (raw.emphasis !== undefined) {
|
|
431
|
+
if (typeof raw.emphasis === 'string' && CONTAINER_EMPHASIS_VALUES.includes(raw.emphasis)) decl.emphasis = raw.emphasis as KitProductDecl['emphasis'];
|
|
432
|
+
else out.push({ code: 'KIT-OBJ-009', path: `${path}.emphasis`, message: `product.emphasis 只许 ${CONTAINER_EMPHASIS_VALUES.join(' / ')},收到 "${String(raw.emphasis)}"` });
|
|
433
|
+
}
|
|
434
|
+
if (raw.surface !== undefined) {
|
|
435
|
+
if (typeof raw.surface === 'string' && SURFACE_RECIPE_VALUES.includes(raw.surface)) decl.surface = raw.surface as KitProductDecl['surface'];
|
|
436
|
+
else out.push({ code: 'KIT-OBJ-009', path: `${path}.surface`, message: `product.surface 只许 ${SURFACE_RECIPE_VALUES.join(' / ')},收到 "${String(raw.surface)}"` });
|
|
437
|
+
}
|
|
156
438
|
return decl;
|
|
157
439
|
}
|
|
158
440
|
|
|
159
|
-
function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[]): KitTabDecl[] {
|
|
441
|
+
function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[], appRefs?: KitAppRefsContext): KitTabDecl[] {
|
|
160
442
|
const tabs: KitTabDecl[] = [];
|
|
161
443
|
const seen = new Set<string>();
|
|
162
444
|
raw.forEach((t, i) => {
|
|
@@ -185,7 +467,7 @@ function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[]): KitTabDe
|
|
|
185
467
|
shape(`${tp}.title`, '页签 title 必须是非空字符串', out);
|
|
186
468
|
return;
|
|
187
469
|
}
|
|
188
|
-
const product = parseProduct(t.product, `${tp}.product`, out);
|
|
470
|
+
const product = parseProduct(t.product, `${tp}.product`, out, appRefs);
|
|
189
471
|
if (product) tabs.push({ id, title: t.title, product });
|
|
190
472
|
});
|
|
191
473
|
return tabs;
|
|
@@ -195,13 +477,30 @@ function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[]): KitTabDe
|
|
|
195
477
|
* 解析并检查一份页面声明。有任何诊断就不要继续编译。
|
|
196
478
|
* 顶层键 page / frame / product;product 等价于 frame.slots.main;frame 缺省为 single-frame。
|
|
197
479
|
*/
|
|
198
|
-
|
|
480
|
+
/** 根据页面相对 pages/ 目录的文件路径推导默认路由(如 orders/detail.kit.yaml -> /orders/detail) */
|
|
481
|
+
export function inferPageUrlFromPath(relPath: string): string {
|
|
482
|
+
const normalized = relPath.replace(/\\/g, '/').replace(/^\/+/, '');
|
|
483
|
+
const stem = normalized.replace(/\.(?:kit\.ya?ml|ya?ml)$/i, '');
|
|
484
|
+
if (stem === '' || stem === 'index') return '/';
|
|
485
|
+
if (stem.endsWith('/index')) return `/${stem.slice(0, -'/index'.length)}`;
|
|
486
|
+
return `/${stem}`;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[], defaultUrl?: string, appRefs?: KitAppRefsContext): KitPageDecl | undefined {
|
|
199
490
|
const before = diagnostics.length;
|
|
200
491
|
if (!isRecord(raw)) {
|
|
201
492
|
shape('$', '页面声明必须是对象(page / frame / product)', diagnostics);
|
|
202
493
|
return undefined;
|
|
203
494
|
}
|
|
204
|
-
|
|
495
|
+
for (const k of Object.keys(raw)) {
|
|
496
|
+
if (!G.pageTopKeys.includes(k)) {
|
|
497
|
+
if (k === 'layout' && isRecord(raw.layout) && raw.layout.frame !== undefined) {
|
|
498
|
+
diagnostics.push({ code: 'KIT-PAGE-001', path: '$.layout', message: '未知键 layout(页面级请改写为 frame.kind,或将 layout.frame 写在 kit.app.yaml)' });
|
|
499
|
+
} else {
|
|
500
|
+
diagnostics.push({ code: 'KIT-PAGE-001', path: `$.${k}`, message: `未知键 ${k}($ 允许:${G.pageTopKeys.join(' / ')})` });
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
205
504
|
|
|
206
505
|
const page = raw.page;
|
|
207
506
|
let meta: KitPageDecl['page'] | undefined;
|
|
@@ -210,7 +509,12 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
210
509
|
shape('page', 'page 必须是对象 { url, title, subtitle?, roles? }', diagnostics);
|
|
211
510
|
} else {
|
|
212
511
|
unknownKeys(page, G.pageKeys, 'page', diagnostics);
|
|
213
|
-
const { url, title, subtitle, roles, eyebrow, breadcrumbs, redirect } = page;
|
|
512
|
+
const { url: rawUrl, title, subtitle, roles, eyebrow, breadcrumbs, redirect } = page;
|
|
513
|
+
if (page.path !== undefined) {
|
|
514
|
+
if (typeof page.path !== 'string') shape('page.path', 'page.path 必须是以 / 开头的路径', diagnostics);
|
|
515
|
+
else checkNoRelativeOrSystemPath(page.path, 'page.path', diagnostics, 'KIT-PAGE-004');
|
|
516
|
+
}
|
|
517
|
+
const url = rawUrl !== undefined ? rawUrl : defaultUrl;
|
|
214
518
|
// 内置页面类型:跳转页(page.redirect);不写 product / frame.slots
|
|
215
519
|
const redirectDecl = redirect === undefined ? undefined : parseRedirect(redirect, diagnostics);
|
|
216
520
|
if (redirect !== undefined && (raw.product !== undefined || (isRecord(raw.frame) && raw.frame.slots !== undefined))) {
|
|
@@ -232,6 +536,9 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
232
536
|
}
|
|
233
537
|
const keys = Object.keys(b).filter((k) => k !== 'label' && k !== 'href');
|
|
234
538
|
if (keys.length > 0) shape(`page.breadcrumbs[${i}]`, `page.breadcrumbs 的项只许 label / href,多余:${keys.join(' / ')}`, diagnostics);
|
|
539
|
+
if (typeof b.href === 'string') {
|
|
540
|
+
checkNoRelativeOrSystemPath(b.href, `page.breadcrumbs[${i}].href`, diagnostics, 'KIT-PAGE-004', { allowExternalHref: true });
|
|
541
|
+
}
|
|
235
542
|
crumbs!.push(typeof b.href === 'string' ? { label: b.label, href: b.href } : { label: b.label });
|
|
236
543
|
});
|
|
237
544
|
}
|
|
@@ -242,7 +549,11 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
242
549
|
diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.eyebrow', message: `page.eyebrow 不得超过 ${TITLE_MAX} 字` });
|
|
243
550
|
}
|
|
244
551
|
}
|
|
245
|
-
if (typeof url !== 'string' ||
|
|
552
|
+
if (typeof url !== 'string' || url.trim() === '') {
|
|
553
|
+
shape('page.url', 'page.url 必须是以 / 开头的路径', diagnostics);
|
|
554
|
+
} else {
|
|
555
|
+
checkNoRelativeOrSystemPath(url, 'page.url', diagnostics, 'KIT-PAGE-004');
|
|
556
|
+
}
|
|
246
557
|
if (typeof title !== 'string' || title.trim() === '') {
|
|
247
558
|
diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.title', message: 'page.title 必填' });
|
|
248
559
|
} else if ([...title].length > TITLE_MAX) {
|
|
@@ -267,6 +578,9 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
267
578
|
if (page.inherit_layout !== undefined && typeof page.inherit_layout !== 'boolean') {
|
|
268
579
|
shape('page.inherit_layout', 'page.inherit_layout 必须是布尔值', diagnostics);
|
|
269
580
|
}
|
|
581
|
+
if (page.view !== undefined && !isViewName(page.view)) {
|
|
582
|
+
diagnostics.push({ code: 'KIT-VIEW-001', path: 'page.view', message: `page.view 须是展示对象类名(大写字母开头、以 View 结尾,如 RefG3View),收到 ${JSON.stringify(page.view)}` });
|
|
583
|
+
}
|
|
270
584
|
if (raw.locales !== undefined) {
|
|
271
585
|
const lc = raw.locales;
|
|
272
586
|
const ok = isRecord(lc) && Object.values(lc).every((t) => isRecord(t) && Object.values(t).every((s) => typeof s === 'string'));
|
|
@@ -281,6 +595,7 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
281
595
|
if (Array.isArray(roles)) meta.roles = roles.filter((r): r is string => typeof r === 'string');
|
|
282
596
|
if (crumbs !== undefined && crumbs.length > 0) meta.breadcrumbs = crumbs;
|
|
283
597
|
if (typeof page.inherit_layout === 'boolean') meta.inheritLayout = page.inherit_layout;
|
|
598
|
+
if (isViewName(page.view)) meta.view = page.view;
|
|
284
599
|
if (redirectDecl !== undefined) meta.redirect = redirectDecl;
|
|
285
600
|
Object.assign(meta, header);
|
|
286
601
|
Object.assign(meta, parsePageParams(page, url, diagnostics));
|
|
@@ -298,6 +613,7 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
298
613
|
|
|
299
614
|
// frame
|
|
300
615
|
let frameKind = 'single-frame';
|
|
616
|
+
let explicitKind = false;
|
|
301
617
|
let frameClass: string | undefined;
|
|
302
618
|
let slotClass: Record<string, string> | undefined;
|
|
303
619
|
let frameConfig: Record<string, unknown> | undefined;
|
|
@@ -309,8 +625,10 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
309
625
|
const f = raw.frame;
|
|
310
626
|
unknownKeys(f, G.frameKeys, 'frame', diagnostics);
|
|
311
627
|
if (f.kind !== undefined) {
|
|
312
|
-
if (typeof f.kind === 'string' && f.kind !== '')
|
|
313
|
-
|
|
628
|
+
if (typeof f.kind === 'string' && f.kind !== '') {
|
|
629
|
+
frameKind = f.kind;
|
|
630
|
+
explicitKind = true;
|
|
631
|
+
} else shape('frame.kind', 'frame.kind 必须是页面框名', diagnostics);
|
|
314
632
|
}
|
|
315
633
|
if (typeof f.class === 'string') frameClass = f.class;
|
|
316
634
|
else if (f.class !== undefined) shape('frame.class', 'frame.class 必须是类串', diagnostics);
|
|
@@ -327,9 +645,9 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
327
645
|
diagnostics.push({ code: 'KIT-PAGE-005', path: `frame.slots.${slot}`, message: `槽名 ${slot} 只能是字母开头的字母数字下划线` });
|
|
328
646
|
continue;
|
|
329
647
|
}
|
|
330
|
-
if (Array.isArray(val)) slots[slot] = parseTabs(val, `frame.slots.${slot}`, diagnostics);
|
|
648
|
+
if (Array.isArray(val)) slots[slot] = parseTabs(val, `frame.slots.${slot}`, diagnostics, appRefs);
|
|
331
649
|
else {
|
|
332
|
-
const p = parseProduct(val, `frame.slots.${slot}`, diagnostics);
|
|
650
|
+
const p = parseProduct(val, `frame.slots.${slot}`, diagnostics, appRefs);
|
|
333
651
|
if (p) slots[slot] = p;
|
|
334
652
|
}
|
|
335
653
|
}
|
|
@@ -340,18 +658,29 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
|
|
|
340
658
|
|
|
341
659
|
// product -> main 槽
|
|
342
660
|
if (raw.product !== undefined) {
|
|
343
|
-
const p = parseProduct(raw.product, 'product', diagnostics);
|
|
661
|
+
const p = parseProduct(raw.product, 'product', diagnostics, appRefs);
|
|
344
662
|
if (p) {
|
|
345
663
|
if ('main' in slots) shape('product', 'product 与 frame.slots.main 不能同时写', diagnostics);
|
|
346
664
|
else slots.main = p;
|
|
347
665
|
}
|
|
348
666
|
}
|
|
349
|
-
if (
|
|
667
|
+
if (isRecord(raw.objects)) {
|
|
668
|
+
const rawProductKind = isRecord(raw.product) && typeof raw.product.kind === 'string'
|
|
669
|
+
? raw.product.kind
|
|
670
|
+
: (isRecord(raw.page) && typeof raw.page.kind === 'string' ? raw.page.kind : undefined);
|
|
671
|
+
for (const [role, val] of Object.entries(raw.objects)) {
|
|
672
|
+
const rp = `objects.${role}`;
|
|
673
|
+
checkObjectName(role, rp, diagnostics);
|
|
674
|
+
if (isRecord(val)) expandObjectEntityAndDicts(val, rp, appRefs, diagnostics);
|
|
675
|
+
checkObjectDecl(val, rp, diagnostics, resolveRoleAllowedKeysForRawObjects(role, appRefs, rawProductKind));
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (Object.keys(slots).length === 0 && diagnostics.length === before && !isRedirect && !(frameConfig !== undefined && frameKind === CONFIG_ONLY_FRAME_KIND)) {
|
|
350
679
|
shape('product', '页面至少要有一个产品(product 或 frame.slots.*)', diagnostics);
|
|
351
680
|
}
|
|
352
681
|
|
|
353
682
|
if (diagnostics.length > before || meta === undefined) return undefined;
|
|
354
|
-
const frame: KitPageDecl['frame'] = { kind: frameKind, slots };
|
|
683
|
+
const frame: KitPageDecl['frame'] = { kind: frameKind, explicitKind, slots };
|
|
355
684
|
if (frameClass !== undefined) frame.class = frameClass;
|
|
356
685
|
if (slotClass !== undefined) frame.slotClass = slotClass;
|
|
357
686
|
if (frameConfig !== undefined) frame.config = frameConfig;
|
package/src/compile/redirect.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { KIT_REDIRECT } from '../object-renderer/defaults';
|
|
12
12
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
13
13
|
import { safeRedirectTarget } from '../data/redirect';
|
|
14
|
+
import { checkNoRelativeOrSystemPath } from '../shared/path-guard';
|
|
14
15
|
import type { KitFragment } from './fragment';
|
|
15
16
|
|
|
16
17
|
export interface KitRedirectDecl {
|
|
@@ -40,8 +41,11 @@ export function parseRedirect(raw: unknown, diagnostics: KitDiagnostic[]): KitRe
|
|
|
40
41
|
diagnostics.push({ code: 'KIT-PAGE-001', path: `${path}.${k}`, message: `未知键 ${k}(${path} 允许:${KIT_REDIRECT.keys.join(' / ')})` });
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
const
|
|
44
|
-
|
|
44
|
+
const validPath = typeof raw.to === 'string' && raw.to.trim() !== '' && checkNoRelativeOrSystemPath(raw.to, `${path}.to`, diagnostics, 'KIT-PAGE-004');
|
|
45
|
+
const to = validPath && typeof raw.to === 'string' ? safeRedirectTarget(raw.to) : '';
|
|
46
|
+
if (to === '' && !diagnostics.some((d) => d.path === `${path}.to`)) {
|
|
47
|
+
shape(`${path}.to`, 'redirect.to 必须是站内绝对路径(单个 / 开头,不是 //,不含反斜杠)');
|
|
48
|
+
}
|
|
45
49
|
let replace = KIT_REDIRECT.defaults.replace;
|
|
46
50
|
if (raw.replace !== undefined) {
|
|
47
51
|
if (typeof raw.replace === 'boolean') replace = raw.replace;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// 确认尾段 `confirm:` 由事件编译(pipeTails / actionPipeline)按动作的 confirm 写出,这里只保证 remove 一定带着非空 confirm 进去。
|
|
8
8
|
// 只改动作,不改入参:有改动时返回新的输入(对象与动作数组浅拷贝),没有改动返回原引用。
|
|
9
9
|
import type { KitBizInput } from '../biz/types';
|
|
10
|
+
import { listConfirmPlaceholders } from 'soma-core';
|
|
10
11
|
import { interpolate } from 'soma-core/i18n';
|
|
11
12
|
import { kitText } from '../i18n/kit-text';
|
|
12
13
|
import { KIT_GRAMMAR } from '../object-renderer/defaults';
|
|
@@ -27,10 +28,9 @@ export function removeTitleFieldOf(obj: KitObject): string | undefined {
|
|
|
27
28
|
return TITLE_FIELDS.find((f) => isRec(obj.schema) && f in obj.schema);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
/** 确认文案里的行占位 `{字段}
|
|
31
|
-
export function removeConfirmPlaceholders(confirm:
|
|
32
|
-
|
|
33
|
-
return [...new Set([...confirm.matchAll(/\{([^{}]+)\}/g)].map((m) => m[1]!))];
|
|
31
|
+
/** 确认文案里的行占位 `{字段}`(按出现顺序去重;文法与转义以 core 的 listConfirmPlaceholders 为准);没有返回空数组 */
|
|
32
|
+
export function removeConfirmPlaceholders(confirm: unknown): string[] {
|
|
33
|
+
return typeof confirm === 'string' ? listConfirmPlaceholders(confirm) : [];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function guardObject(obj: KitObject, at: string, locale: string, out: KitDiagnostic[]): KitObject {
|
|
@@ -47,11 +47,14 @@ function guardObject(obj: KitObject, at: string, locale: string, out: KitDiagnos
|
|
|
47
47
|
out.push({ code: 'KIT-ACT-001', path: `${aat}.confirm`, message: `动作 ${a.id} 是删除(remove),confirm 不能是空串:删除必须二次确认` });
|
|
48
48
|
}
|
|
49
49
|
const plain = kitText('soma.kit.confirm_remove', undefined, locale);
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// 带名字的缺省确认只给行动作(占位 {字段} 取被删行;没有行的删除没有可代入的字段,confirm 也不许写占位——shared/confirm-decl)
|
|
51
|
+
const title = a.on === 'row' ? removeTitleFieldOf(obj) : undefined;
|
|
52
|
+
// 删除动作的 confirm 只收字符串(对象形在 closed-set 已报 KIT-ACT-010,这里按没写处理)
|
|
53
|
+
const given = typeof a.confirm === 'string' ? a.confirm : undefined;
|
|
54
|
+
let confirm = given === undefined || given === plain
|
|
52
55
|
// 缺省确认:有标题字段取带名字的文案,没有退回不带名字的
|
|
53
56
|
? (title !== undefined ? interpolate(kitText('soma.kit.confirm_remove_named', undefined, locale), { name: `{${title}}` }) : plain)
|
|
54
|
-
:
|
|
57
|
+
: given;
|
|
55
58
|
// {name} 指对象的 name 字段;对象没有 name 字段时指标题字段(没有标题字段则无处可取)
|
|
56
59
|
let nameReported = false;
|
|
57
60
|
if (confirm.includes('{name}') && !('name' in obj.schema)) {
|