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
|
@@ -16,14 +16,31 @@ import {
|
|
|
16
16
|
isKitType,
|
|
17
17
|
type KitFieldSetDefault,
|
|
18
18
|
} from './defaults';
|
|
19
|
-
import { adoptOf } from './adopt-gate';
|
|
20
19
|
import { resultSlotOf } from './action-gate';
|
|
20
|
+
import {
|
|
21
|
+
KIT_PART_CARD,
|
|
22
|
+
KIT_PART_PANEL,
|
|
23
|
+
KIT_PART_SECTION,
|
|
24
|
+
KIT_PART_STAT_VALUE,
|
|
25
|
+
KIT_PART_TITLE_DIALOG,
|
|
26
|
+
KIT_PART_TITLE_PAGE,
|
|
27
|
+
KIT_PART_TITLE_SECTION,
|
|
28
|
+
KIT_PART_WELL,
|
|
29
|
+
kitTypographyRecipe,
|
|
30
|
+
KIT_VIEW_HIGHLIGHT_CLASS,
|
|
31
|
+
resolveContainerEmphasisClass,
|
|
32
|
+
resolveSurfaceRecipeClass,
|
|
33
|
+
} from './form-detail';
|
|
21
34
|
import { checkDisplayProps } from './display-checks';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
35
|
+
import { bindFieldProps, checkNestedBindingValues, checkOnDraft, checkSubmitDisabled, classifyBindingValue, classifyEventBinding, collectFieldState, viewPathToCore } from './view-binding';
|
|
36
|
+
import { checkEnumOptionsAndEditCompatibility, checkFieldRules, checkFlowFields, checkViewFlowNodeOptions, checkViewRowColumns, collectFieldValues, fieldNamesOf } from './field-value';
|
|
37
|
+
import { validateRequestAction } from './request-actions';
|
|
38
|
+
import { hasBehaviorFrom, readStatePathsOf } from './crud-bridge';
|
|
39
|
+
import { KIT_ACTION_TONES } from './emit-events';
|
|
25
40
|
import { checkClasses, mergeClass, splitClasses } from './merge-class';
|
|
41
|
+
import { KIT_FILTER_INLINE_CLASS } from './parts';
|
|
26
42
|
import { slotModeOf } from './mode';
|
|
43
|
+
import { formNotifyProblem } from './form-notify';
|
|
27
44
|
import type {
|
|
28
45
|
KitArrangeInput,
|
|
29
46
|
KitCell,
|
|
@@ -44,10 +61,79 @@ import type {
|
|
|
44
61
|
KitViewSlot,
|
|
45
62
|
} from './types';
|
|
46
63
|
|
|
64
|
+
const ENTITY_REF_RE = /^\$entity\.([A-Za-z_][A-Za-z0-9_]*)$/;
|
|
65
|
+
const DICT_REF_RE = /^\$dict\.([A-Za-z_][A-Za-z0-9_]*)$/;
|
|
66
|
+
|
|
67
|
+
function expandRawSchemaIfNeeded(rawSchema: unknown, ctx: KitRenderContext, diags: KitDiagnostic[]): Record<string, KitFieldSchema> {
|
|
68
|
+
if (typeof rawSchema === 'string') {
|
|
69
|
+
const m = ENTITY_REF_RE.exec(rawSchema.trim());
|
|
70
|
+
if (!m) {
|
|
71
|
+
diags.push({ code: 'KIT-OBJ-001', path: 'schema', message: `schema 字符串引用必须为 $entity.<实体名>(收到 "${rawSchema}")` });
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
const entityDef = ctx.entities?.[m[1]!];
|
|
75
|
+
if (!entityDef || typeof entityDef !== 'object') {
|
|
76
|
+
diags.push({ code: 'KIT-OBJ-001', path: 'schema', message: `对象引用了未声明的实体 ${rawSchema}` });
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
const out: Record<string, KitFieldSchema> = {};
|
|
80
|
+
for (const [k, v] of Object.entries(entityDef)) {
|
|
81
|
+
if (v && typeof v === 'object') out[k] = { ...(v as KitFieldSchema) };
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
if (rawSchema !== null && typeof rawSchema === 'object' && !Array.isArray(rawSchema) && '$ref' in (rawSchema as Record<string, unknown>)) {
|
|
86
|
+
const refObj = rawSchema as { $ref?: unknown; pick?: unknown; omit?: unknown; override?: unknown };
|
|
87
|
+
const refStr = typeof refObj.$ref === 'string' ? refObj.$ref.trim() : '';
|
|
88
|
+
const m = ENTITY_REF_RE.exec(refStr);
|
|
89
|
+
if (!m) {
|
|
90
|
+
diags.push({ code: 'KIT-OBJ-001', path: 'schema.$ref', message: `schema.$ref 必须为 $entity.<实体名>(收到 "${String(refObj.$ref)}")` });
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
const entityDef = ctx.entities?.[m[1]!];
|
|
94
|
+
if (!entityDef || typeof entityDef !== 'object') {
|
|
95
|
+
diags.push({ code: 'KIT-OBJ-001', path: 'schema.$ref', message: `对象引用了未声明的实体 ${refStr}` });
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
let names = Object.keys(entityDef);
|
|
99
|
+
if (Array.isArray(refObj.pick)) {
|
|
100
|
+
const picks = refObj.pick.filter((x): x is string => typeof x === 'string');
|
|
101
|
+
for (const p of picks) {
|
|
102
|
+
if (!(p in entityDef)) diags.push({ code: 'KIT-OBJ-001', path: 'schema.pick', message: `schema.pick 引用了实体 ${refStr} 中不存在的字段 ${p}` });
|
|
103
|
+
}
|
|
104
|
+
names = picks.filter((p) => p in entityDef);
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(refObj.omit)) {
|
|
107
|
+
const omits = new Set(refObj.omit.filter((x): x is string => typeof x === 'string'));
|
|
108
|
+
names = names.filter((n) => !omits.has(n));
|
|
109
|
+
}
|
|
110
|
+
const out: Record<string, KitFieldSchema> = {};
|
|
111
|
+
for (const n of names) {
|
|
112
|
+
const base = entityDef[n];
|
|
113
|
+
if (base && typeof base === 'object') out[n] = { ...(base as KitFieldSchema) };
|
|
114
|
+
}
|
|
115
|
+
if (refObj.override && typeof refObj.override === 'object' && !Array.isArray(refObj.override)) {
|
|
116
|
+
for (const [fName, over] of Object.entries(refObj.override as Record<string, unknown>)) {
|
|
117
|
+
if (over && typeof over === 'object') {
|
|
118
|
+
out[fName] = { ...(out[fName] ?? (entityDef[fName] as KitFieldSchema) ?? ({} as KitFieldSchema)), ...(over as Partial<KitFieldSchema>) };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
return (rawSchema ?? {}) as Record<string, KitFieldSchema>;
|
|
125
|
+
}
|
|
126
|
+
|
|
47
127
|
function resolveSchema(obj: KitObject, ctx: KitRenderContext, diags: KitDiagnostic[]): KitSchema {
|
|
48
128
|
const out: KitSchema = {};
|
|
49
|
-
|
|
50
|
-
|
|
129
|
+
const rawObj = obj as unknown as Record<string, unknown>;
|
|
130
|
+
const hasWrite = (obj.behavior?.write !== undefined && obj.behavior.write !== null)
|
|
131
|
+
|| (rawObj.write !== undefined && rawObj.write !== null);
|
|
132
|
+
const primaryKey = typeof obj.primaryKey === 'string' && obj.primaryKey.trim() !== '' ? obj.primaryKey.trim() : 'id';
|
|
133
|
+
const sourceSchema = expandRawSchemaIfNeeded(obj.schema, ctx, diags);
|
|
134
|
+
|
|
135
|
+
for (const [key, raw] of Object.entries(sourceSchema)) {
|
|
136
|
+
let field: KitFieldSchema = { ...raw };
|
|
51
137
|
if (raw.ref) {
|
|
52
138
|
const shared = ctx.sharedSchema?.[raw.ref];
|
|
53
139
|
if (!shared) {
|
|
@@ -56,6 +142,53 @@ function resolveSchema(obj: KitObject, ctx: KitRenderContext, diags: KitDiagnost
|
|
|
56
142
|
field = { ...shared, ...raw };
|
|
57
143
|
}
|
|
58
144
|
}
|
|
145
|
+
if (typeof (field.options as unknown) === 'string') {
|
|
146
|
+
const optStr = String(field.options).trim();
|
|
147
|
+
const dm = DICT_REF_RE.exec(optStr);
|
|
148
|
+
if (!dm) {
|
|
149
|
+
diags.push({ code: 'KIT-FORM-003', path: `schema.${key}.options`, message: `字段 ${key} 的 options 字符串引用必须为 $dict.<字典名>(收到 "${optStr}")` });
|
|
150
|
+
} else {
|
|
151
|
+
const dictItems = ctx.dicts?.[dm[1]!];
|
|
152
|
+
if (!Array.isArray(dictItems) || dictItems.length === 0) {
|
|
153
|
+
diags.push({ code: 'KIT-FORM-003', path: `schema.${key}.options`, message: `字段 ${key} 引用了未声明的字典 ${optStr}` });
|
|
154
|
+
} else {
|
|
155
|
+
field.options = dictItems.map((it) => ({ ...it })) as KitFieldSchema['options'];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const rawAccess = field.access ?? field.permission;
|
|
160
|
+
if (rawAccess !== undefined) {
|
|
161
|
+
if (rawAccess === 'read' || rawAccess === 'r') {
|
|
162
|
+
field.permission = 'r';
|
|
163
|
+
field.access = 'read';
|
|
164
|
+
} else if (rawAccess === 'write' || rawAccess === 'w') {
|
|
165
|
+
field.permission = 'w';
|
|
166
|
+
field.access = 'write';
|
|
167
|
+
} else if (rawAccess === 'create') {
|
|
168
|
+
field.permission = 'create';
|
|
169
|
+
field.access = 'create';
|
|
170
|
+
} else {
|
|
171
|
+
const attrKey = field.access !== undefined ? 'access' : 'permission';
|
|
172
|
+
diags.push({ code: 'KIT-OBJ-006', path: `schema.${key}.${attrKey}`, message: `字段 ${key} 的 ${attrKey} "${String(rawAccess)}" 不合法(允许:read / write / create)` });
|
|
173
|
+
field.permission = 'r';
|
|
174
|
+
field.access = 'read';
|
|
175
|
+
}
|
|
176
|
+
} else if (field.readonly === true) {
|
|
177
|
+
field.permission = 'r';
|
|
178
|
+
field.access = 'read';
|
|
179
|
+
} else if (hasWrite) {
|
|
180
|
+
const isPrimaryKey = field.key === true || key === primaryKey;
|
|
181
|
+
if (isPrimaryKey) {
|
|
182
|
+
field.permission = 'r';
|
|
183
|
+
field.access = 'read';
|
|
184
|
+
} else {
|
|
185
|
+
field.permission = 'w';
|
|
186
|
+
field.access = 'write';
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
field.permission = 'r';
|
|
190
|
+
field.access = 'read';
|
|
191
|
+
}
|
|
59
192
|
if (!isKitType(field.type)) {
|
|
60
193
|
diags.push({ code: 'KIT-TYPE-001', path: `schema.${key}.type`, message: `type ${String(field.type)} 未在 types 表登记` });
|
|
61
194
|
}
|
|
@@ -89,7 +222,14 @@ function layoutCells(l: KitLayoutIR): KitCell[] {
|
|
|
89
222
|
|
|
90
223
|
function layoutClasses(l: KitLayoutIR, out: string[]): void {
|
|
91
224
|
switch (l.kind) {
|
|
92
|
-
case 'grid':
|
|
225
|
+
case 'grid':
|
|
226
|
+
out.push(l.wrapClass, l.gridClass);
|
|
227
|
+
// 筛选栏动作区并入字段栅格时才用到的类(emit-static 的 renderObjectForm 按 collapsible / overflow 决定用不用;候选类多收不碍事)
|
|
228
|
+
if (l.actionsClass !== undefined) out.push(l.actionsClass, KIT_FILTER_INLINE_CLASS.grid, KIT_FILTER_INLINE_CLASS.actionsExtra, KIT_FILTER_INLINE_CLASS.notice);
|
|
229
|
+
// 定宽流式版式(不折叠的筛选栏):根容器 / 字段宽度 / 动作区 / 提示条
|
|
230
|
+
if (l.filterFlow !== undefined) out.push(l.filterFlow.wrapClass, ...l.filterFlow.widthClasses, l.filterFlow.actionsClass, l.filterFlow.padClass, l.filterFlow.noticeClass, 'min-w-0');
|
|
231
|
+
if (l.filterPack !== undefined) out.push(l.filterPack.wrapClass, ...l.filterPack.cellClasses, l.filterPack.actionsClass, l.filterPack.padClass, l.filterPack.noticeClass, 'min-w-0');
|
|
232
|
+
break;
|
|
93
233
|
case 'rows': out.push(l.wrapClass, l.rowClass); break;
|
|
94
234
|
case 'flex': out.push(l.wrapClass); break;
|
|
95
235
|
case 'groups':
|
|
@@ -99,9 +239,10 @@ function layoutClasses(l: KitLayoutIR, out: string[]): void {
|
|
|
99
239
|
break;
|
|
100
240
|
case 'table':
|
|
101
241
|
out.push(l.wrapClass, l.innerClass, l.headClass, l.rowClass, l.selectClass, l.actionsClass, KIT_CLASS_DEFAULTS.tableActions, l.stripeClass);
|
|
242
|
+
// 普通表格斑马纹发射时改用 odd 键(行容器首子节点是 template),候选类要一并收
|
|
243
|
+
if (l.stripeClass !== '') out.push(KIT_CLASS_DEFAULTS.tableRowStripedAfterTemplate, KIT_CLASS_DEFAULTS.tableRowStripedExpandOuter, KIT_CLASS_DEFAULTS.tableRowStripedExpandInnerAfterTemplate);
|
|
102
244
|
for (const h of l.head) out.push(h.class);
|
|
103
245
|
// G2:表头里的选择 / 操作列类、合计行类(这些只经组件 props 下发,不在 HTML 里)
|
|
104
|
-
for (const w of l.rowClassWhen ?? []) out.push(w.class);
|
|
105
246
|
out.push(l.selectHeadClass ?? '', l.actionsHeadClass ?? '', l.summaryRowClass ?? '', ...(l.summaryCellClasses ?? []));
|
|
106
247
|
if (l.expand !== null) layoutClasses(l.expand.layout, out);
|
|
107
248
|
break;
|
|
@@ -123,8 +264,33 @@ const RESERVED_STATIC_PROPS: ReadonlySet<string> = new Set(['data', 'map', 'char
|
|
|
123
264
|
const STATIC_PROP_KEY = /^[a-z][A-Za-z0-9_]*$/;
|
|
124
265
|
|
|
125
266
|
/** view.props(配置类 prop 透传)与 view.value(值绑定路径)的校验;违规的键丢弃并记 KIT-STATIC-001 */
|
|
126
|
-
|
|
127
|
-
|
|
267
|
+
/** 实际值的类型名(诊断用):null / array 单列,其余取 typeof */
|
|
268
|
+
function literalTypeName(v: unknown): string {
|
|
269
|
+
if (v === null) return 'null';
|
|
270
|
+
if (Array.isArray(v)) return 'array';
|
|
271
|
+
return typeof v;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 字面量配置值是否符合契约 type:string / number / boolean / array / object / enum(只核是字符串,propTypes 不含枚举值);
|
|
276
|
+
* 未知类型 / 空串不核。null / undefined 视作「未填」不核。返回期望类型名,符合或不核返回 null。
|
|
277
|
+
*/
|
|
278
|
+
function propTypeMismatch(type: string | undefined, v: unknown): string | null {
|
|
279
|
+
if (type === undefined || type === '' || v === null || v === undefined) return null;
|
|
280
|
+
switch (type) {
|
|
281
|
+
case 'string': case 'number': case 'boolean': return typeof v === type ? null : type;
|
|
282
|
+
case 'array': return Array.isArray(v) ? null : type;
|
|
283
|
+
case 'object': return typeof v === 'object' && !Array.isArray(v) ? null : type;
|
|
284
|
+
case 'enum': return typeof v === 'string' ? null : 'string';
|
|
285
|
+
default: return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function staticProps(
|
|
290
|
+
form: KitViewForm, path: string, diags: KitDiagnostic[], contractProps?: readonly string[], propTypes?: Readonly<Record<string, string>>,
|
|
291
|
+
): { props?: Record<string, unknown>; value?: string; bound?: ReadonlySet<string> } {
|
|
292
|
+
const out: { props?: Record<string, unknown>; value?: string; bound?: ReadonlySet<string> } = {};
|
|
293
|
+
const bound = new Set<string>();
|
|
128
294
|
if (form.props !== undefined) {
|
|
129
295
|
if (form.props === null || typeof form.props !== 'object' || Array.isArray(form.props)) {
|
|
130
296
|
diags.push({ code: 'KIT-STATIC-001', path: `${path}.props`, message: 'props 必须是对象' });
|
|
@@ -135,9 +301,38 @@ function staticProps(form: KitViewForm, path: string, diags: KitDiagnostic[]): {
|
|
|
135
301
|
diags.push({ code: 'KIT-STATIC-001', path: `${path}.props.${k}`, message: `props 的键 ${k} 不合法或属保留键(data / map / chart / class / value 由编译器写)` });
|
|
136
302
|
continue;
|
|
137
303
|
}
|
|
304
|
+
// 闭集:组件契约登记了 props 时,键必须是契约里的 prop(已删除的写法 / 手误的键不静默透传给组件)
|
|
305
|
+
if (contractProps !== undefined && !contractProps.includes(k)) {
|
|
306
|
+
diags.push({ code: 'KIT-STATIC-001', path: `${path}.props.${k}`, message: `组件 ${form.staticComponent ?? ''} 没有 prop ${k}(契约 props:${contractProps.join(' / ')})` });
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
// 绑定(RV-1119):值写 view.<成员> 编成 core 页面变量路径(成员改了组件全量重画);row. 在静态视图里没有行;
|
|
310
|
+
// 原始运行期路径 / 取反 / 非纯路径记诊断。成员的存在与形状由 compile/view-check 对着登记表核(KIT-VIEW-003 / 011)
|
|
311
|
+
const binding = classifyBindingValue(v, `props 的 ${k}`);
|
|
312
|
+
if (binding.kind === 'invalid') {
|
|
313
|
+
diags.push({ code: binding.code, path: `${path}.props.${k}`, message: binding.message });
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (binding.kind === 'row') {
|
|
317
|
+
diags.push({ code: 'KIT-ROW-002', path: `${path}.props.${k}`, message: `静态视图 props 的 ${k} 不能绑 row.<字段>(没有行):row.<字段> 只用于列表视图的字段项 props;这里写 view.<成员>` });
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (binding.kind === 'view') {
|
|
321
|
+
kept[k] = viewPathToCore(binding.path);
|
|
322
|
+
bound.add(k);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
checkNestedBindingValues(v, `${path}.props.${k}`, diags);
|
|
326
|
+
// 类型:契约给了 propTypes 才核(字面量配置值;绑定值的形状由 view-check 核,KIT-VIEW-011);类型不符的键丢弃,不把错类型透传给组件
|
|
327
|
+
const expected = propTypeMismatch(propTypes?.[k], v);
|
|
328
|
+
if (expected !== null) {
|
|
329
|
+
diags.push({ code: 'KIT-STATIC-001', path: `${path}.props.${k}`, message: `组件 ${form.staticComponent ?? ''} 的 prop ${k} 期望 ${expected},实际是 ${literalTypeName(v)}` });
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
138
332
|
kept[k] = v;
|
|
139
333
|
}
|
|
140
334
|
if (Object.keys(kept).length > 0) out.props = kept;
|
|
335
|
+
if (bound.size > 0) out.bound = bound;
|
|
141
336
|
}
|
|
142
337
|
}
|
|
143
338
|
if (form.value !== undefined) {
|
|
@@ -147,10 +342,8 @@ function staticProps(form: KitViewForm, path: string, diags: KitDiagnostic[]): {
|
|
|
147
342
|
return out;
|
|
148
343
|
}
|
|
149
344
|
|
|
150
|
-
const VIEW_ON_THEN: ReadonlySet<string> = new Set(KIT_GRAMMAR.overlayEventRoles.actionForm.thenValues);
|
|
151
|
-
|
|
152
345
|
/**
|
|
153
|
-
* view.on(写死形状数据组件的事件接线)的形状与事件名校验:值是非空动作串,或 { action
|
|
346
|
+
* view.on(写死形状数据组件的事件接线)的形状与事件名校验:值是非空动作串,或 { action };
|
|
154
347
|
* 事件名必须在组件契约 emits 里(契约没给 emits 时不核)。违规的项丢弃并记 KIT-STATIC-001;动作是否登记由 emitEvents 核。
|
|
155
348
|
*/
|
|
156
349
|
function staticOn(
|
|
@@ -176,11 +369,20 @@ function staticOn(
|
|
|
176
369
|
diags.push({ code: 'KIT-STATIC-001', path: at, message: 'on 的动作不能是空串' });
|
|
177
370
|
continue;
|
|
178
371
|
}
|
|
372
|
+
// view.<方法>:事件调展示对象方法(RV-1119);view. 开头却不是单段方法名记 KIT-VIEW-001。方法是否登记由 compile/view-check 核(KIT-VIEW-004)
|
|
373
|
+
const evt = classifyEventBinding(value, `on.${event}`);
|
|
374
|
+
if (evt.kind === 'invalid') {
|
|
375
|
+
diags.push({ code: 'KIT-VIEW-001', path: at, message: evt.message });
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
179
378
|
} else if (value === null || typeof value !== 'object' || Array.isArray(value) || typeof value.action !== 'string' || value.action === '') {
|
|
180
|
-
diags.push({ code: 'KIT-STATIC-001', path: at, message: 'on 的值必须是动作名字符串,或 { action
|
|
379
|
+
diags.push({ code: 'KIT-STATIC-001', path: at, message: 'on 的值必须是动作名字符串,或 { action }' });
|
|
380
|
+
continue;
|
|
381
|
+
} else if (value.action.startsWith('view.')) {
|
|
382
|
+
diags.push({ code: 'KIT-VIEW-001', path: `${at}.action`, message: `展示对象方法直接写成 on 的值(${event}: view.<方法>),不写进 { action } 对象形` });
|
|
181
383
|
continue;
|
|
182
|
-
} else if (value.
|
|
183
|
-
diags.push({ code: 'KIT-STATIC-001', path:
|
|
384
|
+
} else if (Object.keys(value).some((k) => k !== 'action')) {
|
|
385
|
+
diags.push({ code: 'KIT-STATIC-001', path: at, message: 'on 的对象形态只许 action 键(动作之后的提示 / 重取 / 跳转写在具名动作或展示对象方法里)' });
|
|
184
386
|
continue;
|
|
185
387
|
}
|
|
186
388
|
kept[event] = value;
|
|
@@ -206,9 +408,9 @@ const GROUPS_AS = KIT_GRAMMAR.formLinkage.groupsAs as { values: string[] };
|
|
|
206
408
|
|
|
207
409
|
/**
|
|
208
410
|
* 表单 / 筛选的布局与行为参数(M 波 G3 D6 / D7):只许写在对应槽位上,枚举 / 范围 / 布尔不对记 KIT-FORM-006 并忽略该键;
|
|
209
|
-
*
|
|
411
|
+
* 返回 IR 形态(只含写了的键)。
|
|
210
412
|
*/
|
|
211
|
-
function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]
|
|
413
|
+
function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): KitFormOpts {
|
|
212
414
|
const out: KitFormOpts = {};
|
|
213
415
|
const raw = form as unknown as Record<string, unknown>;
|
|
214
416
|
const bad = (key: string, message: string): void => { diags.push({ code: 'KIT-FORM-006', path: `${path}.${key}`, message }); };
|
|
@@ -239,60 +441,50 @@ function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: K
|
|
|
239
441
|
}
|
|
240
442
|
bool('inline', ['form']);
|
|
241
443
|
const scroll = bool('scrollToError', ['form']);
|
|
242
|
-
if (scroll
|
|
243
|
-
if (raw.afterSave !== undefined) {
|
|
244
|
-
if (slot !== 'form') bad('afterSave', 'afterSave 只用于 form 视图');
|
|
245
|
-
else {
|
|
246
|
-
const then = normalizeThen(raw.afterSave, `${path}.afterSave`, diags);
|
|
247
|
-
if (then !== null) out.afterSave = then;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
// 采纳建议:只许 form 视图
|
|
251
|
-
if (raw.adopt !== undefined) {
|
|
252
|
-
if (slot !== 'form') diags.push({ code: 'KIT-FORM-009', path: `${path}.adopt`, message: 'adopt 只用于 form 视图' });
|
|
253
|
-
else {
|
|
254
|
-
const adopt = adoptOf(raw.adopt, `${path}.adopt`, schema, diags);
|
|
255
|
-
if (adopt !== null) out.adopt = adopt;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
444
|
+
if (scroll !== undefined) out.scrollToError = scroll;
|
|
258
445
|
// 底栏动作:只许 form 视图,动作 id 的字符串数组(是否存在 / 是否 request·download 在 emit 阶段核对)
|
|
259
446
|
if (raw.footerActions !== undefined) {
|
|
260
447
|
const list = raw.footerActions as unknown;
|
|
261
448
|
if (slot !== 'form') diags.push({ code: 'KIT-FORM-009', path: `${path}.footerActions`, message: 'footerActions 只用于 form 视图' });
|
|
262
449
|
else if (!Array.isArray(list) || list.length === 0 || list.some((x) => typeof x !== 'string' || x === '')) {
|
|
263
450
|
diags.push({ code: 'KIT-FORM-009', path: `${path}.footerActions`, message: 'footerActions 必须是非空的动作 id 数组' });
|
|
264
|
-
} else
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (raw.onChange !== undefined) {
|
|
268
|
-
const map = raw.onChange as unknown;
|
|
269
|
-
const at = `${path}.onChange`;
|
|
270
|
-
if (slot !== 'form') diags.push({ code: 'KIT-ACT-008', path: at, message: 'onChange 只用于 form 视图' });
|
|
271
|
-
else if (map === null || typeof map !== 'object' || Array.isArray(map) || Object.keys(map).length === 0) {
|
|
272
|
-
diags.push({ code: 'KIT-ACT-008', path: at, message: 'onChange 必须是非空对象 { 字段名: request 动作 id }' });
|
|
273
|
-
} else {
|
|
274
|
-
const kept: Record<string, string> = {};
|
|
275
|
-
for (const [field, aid] of Object.entries(map as Record<string, unknown>)) {
|
|
276
|
-
const f = schema?.[field];
|
|
277
|
-
if (typeof aid !== 'string' || aid === '') diags.push({ code: 'KIT-ACT-008', path: `${at}.${field}`, message: 'onChange 的值必须是 request 动作 id(字符串)' });
|
|
278
|
-
else if (schema !== undefined && f === undefined) diags.push({ code: 'KIT-ACT-008', path: `${at}.${field}`, message: `onChange 的字段 ${field} 不在对象 schema 里` });
|
|
279
|
-
else if (f !== undefined && (f.permission ?? 'r') === 'r') diags.push({ code: 'KIT-ACT-008', path: `${at}.${field}`, message: `onChange 的字段 ${field} 是只读字段(permission: r),用户改不了它,没有"变化"可触发` });
|
|
280
|
-
else kept[field] = aid;
|
|
281
|
-
}
|
|
282
|
-
if (Object.keys(kept).length > 0) out.onChange = kept;
|
|
283
|
-
}
|
|
451
|
+
} else if (new Set(list).size !== list.length) {
|
|
452
|
+
diags.push({ code: 'KIT-FORM-009', path: `${path}.footerActions`, message: 'footerActions 含重复的动作 id' });
|
|
453
|
+
} else out.footerActions = [...(list as string[])];
|
|
284
454
|
}
|
|
285
455
|
// 请求结果常驻槽(GA3):form 视图画在字段与按钮之间;其它视图在 renderSlot 里改写成 AsyncResultPanel
|
|
286
456
|
if (raw.result !== undefined && slot === 'form') {
|
|
287
457
|
const result = resultSlotOf(raw.result, `${path}.result`, diags);
|
|
288
458
|
if (result !== null) out.result = result;
|
|
289
459
|
}
|
|
290
|
-
// filter
|
|
460
|
+
// filter:折叠与触发(P2:筛选字段数量 > 4 且未显式设置 collapsible / defaultCollapsedCount 时,默认前 4 项常驻、第 5 项起自动折叠)
|
|
291
461
|
if (slot === 'filter') {
|
|
292
|
-
const
|
|
462
|
+
const filterFieldCount = Array.isArray(form.fields)
|
|
463
|
+
? form.fields.map(normalizeRef).filter((r) => r.divider === undefined).length
|
|
464
|
+
: 0;
|
|
465
|
+
let residentLimit = 4;
|
|
466
|
+
if (raw.defaultCollapsedCount !== undefined) {
|
|
467
|
+
if (typeof raw.defaultCollapsedCount !== 'number' || !Number.isInteger(raw.defaultCollapsedCount) || raw.defaultCollapsedCount < 1) {
|
|
468
|
+
bad('defaultCollapsedCount', 'defaultCollapsedCount 须是正整数');
|
|
469
|
+
} else {
|
|
470
|
+
residentLimit = raw.defaultCollapsedCount;
|
|
471
|
+
out.defaultCollapsedCount = residentLimit;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const autoCollapse = raw.collapsible === undefined && filterFieldCount > residentLimit;
|
|
475
|
+
const collapsible = raw.collapsible === undefined
|
|
476
|
+
? (autoCollapse ? true : undefined)
|
|
477
|
+
: typeof raw.collapsible === 'boolean'
|
|
478
|
+
? raw.collapsible
|
|
479
|
+
: (bad('collapsible', 'collapsible 必须是布尔'), undefined);
|
|
293
480
|
if (collapsible === true) {
|
|
294
481
|
out.collapsible = true;
|
|
295
|
-
|
|
482
|
+
if (autoCollapse || filterFieldCount > residentLimit) {
|
|
483
|
+
out.filterOverflow = true;
|
|
484
|
+
out.defaultCollapsedCount ??= residentLimit;
|
|
485
|
+
}
|
|
486
|
+
const defaultRows = raw.defaultCollapsedCount !== undefined ? Math.max(1, Math.min(FILTER_OPTS.collapsedRowsMax, Math.ceil(residentLimit / 4))) : FILTER_OPTS.collapsedRowsDefault;
|
|
487
|
+
const rows = raw.collapsedRows ?? defaultRows;
|
|
296
488
|
if (typeof rows !== 'number' || !Number.isInteger(rows) || rows < 1 || rows > FILTER_OPTS.collapsedRowsMax) {
|
|
297
489
|
bad('collapsedRows', `collapsedRows 须是 1~${FILTER_OPTS.collapsedRowsMax} 的整数`);
|
|
298
490
|
out.collapsedRows = FILTER_OPTS.collapsedRowsDefault;
|
|
@@ -306,6 +498,7 @@ function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: K
|
|
|
306
498
|
}
|
|
307
499
|
} else {
|
|
308
500
|
onlyOn('collapsedRows', ['filter']);
|
|
501
|
+
onlyOn('defaultCollapsedCount', ['filter']);
|
|
309
502
|
onlyOn('trigger', ['filter']);
|
|
310
503
|
}
|
|
311
504
|
// groupsAs
|
|
@@ -321,11 +514,78 @@ function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: K
|
|
|
321
514
|
}
|
|
322
515
|
|
|
323
516
|
/** list 槽上的 contextMenu 并入集合声明(集合自己写了就以集合为准);其它槽原样返回,由 renderSlot 报 KIT-MENU-001 */
|
|
324
|
-
function withViewContextMenu(c: KitCollection, form: KitViewForm, slot: KitViewSlot): KitCollection {
|
|
325
|
-
if (slot !== 'list' || form.contextMenu === undefined
|
|
517
|
+
function withViewContextMenu(c: KitCollection, form: KitViewForm, slot: KitViewSlot, diags?: KitDiagnostic[]): KitCollection {
|
|
518
|
+
if (slot !== 'list' || form.contextMenu === undefined) return c;
|
|
519
|
+
if ((c as { contextMenu?: unknown }).contextMenu !== undefined) {
|
|
520
|
+
diags?.push({ code: 'KIT-MENU-001', path: 'view.list.contextMenu', message: 'view.list.contextMenu 与 view.list.collection.contextMenu 不能同时声明' });
|
|
521
|
+
return c;
|
|
522
|
+
}
|
|
326
523
|
return { ...c, contextMenu: form.contextMenu } as KitCollection;
|
|
327
524
|
}
|
|
328
525
|
|
|
526
|
+
function resolveSlotKnobs(
|
|
527
|
+
slot: KitViewSlot,
|
|
528
|
+
form: KitViewForm,
|
|
529
|
+
obj: KitObject,
|
|
530
|
+
path: string,
|
|
531
|
+
diags: KitDiagnostic[],
|
|
532
|
+
): { emphasis?: 'primary' | 'normal' | 'subtle'; surface?: 'card' | 'flush' | 'plain'; highlight?: boolean; extraWrapClass: string } {
|
|
533
|
+
const viewRec = (obj.view ?? {}) as Record<string, unknown>;
|
|
534
|
+
const rawEmphasis = form.emphasis ?? (viewRec.emphasis as unknown) ?? obj.emphasis;
|
|
535
|
+
const rawSurface = form.surface ?? (viewRec.surface as unknown) ?? obj.surface;
|
|
536
|
+
const rawHighlight = form.highlight ?? (viewRec.highlight as unknown) ?? obj.highlight;
|
|
537
|
+
|
|
538
|
+
let emphasis: 'primary' | 'normal' | 'subtle' | undefined;
|
|
539
|
+
if (rawEmphasis !== undefined) {
|
|
540
|
+
if (rawEmphasis === 'primary' || rawEmphasis === 'normal' || rawEmphasis === 'subtle') {
|
|
541
|
+
emphasis = rawEmphasis;
|
|
542
|
+
} else {
|
|
543
|
+
diags.push({ code: 'KIT-OBJ-009', path: `${path}.emphasis`, message: `emphasis 只许 primary / normal / subtle,收到 "${String(rawEmphasis)}"` });
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
let surface: 'card' | 'flush' | 'plain' | undefined;
|
|
548
|
+
if (rawSurface !== undefined) {
|
|
549
|
+
if (rawSurface === 'card' || rawSurface === 'flush' || rawSurface === 'plain') {
|
|
550
|
+
surface = rawSurface;
|
|
551
|
+
} else {
|
|
552
|
+
diags.push({ code: 'KIT-OBJ-009', path: `${path}.surface`, message: `surface 只许 card / flush / plain,收到 "${String(rawSurface)}"` });
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
let highlight: boolean | undefined;
|
|
557
|
+
if (rawHighlight !== undefined) {
|
|
558
|
+
if (typeof rawHighlight === 'boolean') {
|
|
559
|
+
if (rawHighlight) highlight = true;
|
|
560
|
+
} else {
|
|
561
|
+
diags.push({ code: 'KIT-OBJ-009', path: `${path}.highlight`, message: 'highlight 必须是布尔值' });
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const classes: string[] = [];
|
|
566
|
+
if (surface !== undefined) classes.push(resolveSurfaceRecipeClass(surface));
|
|
567
|
+
if (emphasis !== undefined) classes.push(resolveContainerEmphasisClass(emphasis));
|
|
568
|
+
if (highlight === true) {
|
|
569
|
+
classes.push(KIT_VIEW_HIGHLIGHT_CLASS);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return {
|
|
573
|
+
...(emphasis !== undefined ? { emphasis } : {}),
|
|
574
|
+
...(surface !== undefined ? { surface } : {}),
|
|
575
|
+
...(highlight === true ? { highlight: true } : {}),
|
|
576
|
+
extraWrapClass: classes.filter(Boolean).join(' '),
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function applyWrapKnobClass(layout: KitLayoutIR, extraWrapClass: string): void {
|
|
581
|
+
if (extraWrapClass === '') return;
|
|
582
|
+
if (layout.kind === 'static') {
|
|
583
|
+
layout.class = mergeClass(extraWrapClass, layout.class);
|
|
584
|
+
} else {
|
|
585
|
+
layout.wrapClass = mergeClass(layout.wrapClass, extraWrapClass);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
329
589
|
function renderSlot(
|
|
330
590
|
slot: KitViewSlot,
|
|
331
591
|
form: KitViewForm,
|
|
@@ -355,7 +615,8 @@ function renderSlot(
|
|
|
355
615
|
}
|
|
356
616
|
}
|
|
357
617
|
const emptyEnv = summaryEmpty(slot, form, path, diags);
|
|
358
|
-
const fopts = formOptsOf(slot, form, path, diags
|
|
618
|
+
const fopts = formOptsOf(slot, form, path, diags);
|
|
619
|
+
const slotKnobs = resolveSlotKnobs(slot, form, obj, path, diags);
|
|
359
620
|
// inline: true 等价 arrange: inline;与别的 arrange 同写报错
|
|
360
621
|
if (slot === 'form' && form.inline === true) {
|
|
361
622
|
if (form.arrange !== undefined && form.arrange !== 'inline' && !(typeof form.arrange === 'object' && 'inline' in (form.arrange as object))) {
|
|
@@ -365,8 +626,6 @@ function renderSlot(
|
|
|
365
626
|
}
|
|
366
627
|
}
|
|
367
628
|
const requiredMark = form.requiredMark === 'start' ? 'start' : 'end';
|
|
368
|
-
// 字段策略表:form 视图的 policy 规整成 IR,经 env 交给每个字段格并入 showWhen / disabledWhen / requiredWhen
|
|
369
|
-
const policy = form.policy === undefined ? null : fieldPolicyOf(form.policy, slot, schema, `${path}.policy`, diags);
|
|
370
629
|
|
|
371
630
|
if (form.staticComponent) {
|
|
372
631
|
const contract = ctx.staticComponents?.[form.staticComponent];
|
|
@@ -380,25 +639,41 @@ function renderSlot(
|
|
|
380
639
|
});
|
|
381
640
|
}
|
|
382
641
|
diags.push(...checkClasses(form.class, `${path}.class`));
|
|
383
|
-
const extraProps = staticProps(form, path, diags);
|
|
384
|
-
|
|
642
|
+
const extraProps = staticProps(form, path, diags, contract?.props, contract?.propTypes);
|
|
643
|
+
// 绑定到展示对象成员的 prop 值不是字面量,不进字面量配置的展示校验
|
|
644
|
+
const boundKeys = extraProps.bound;
|
|
645
|
+
checkDisplayProps(boundKeys === undefined || form.props === undefined ? form : { ...form, props: Object.fromEntries(Object.entries(form.props).filter(([k]) => !boundKeys.has(k))) }, obj, path, diags);
|
|
385
646
|
const on = staticOn(form, contract?.emits, path, diags);
|
|
386
647
|
const dataSubmit = obj.behavior.write !== undefined
|
|
387
648
|
&& contract?.emits?.includes('submit') === true
|
|
388
649
|
&& contract?.props?.includes('object') === true;
|
|
389
650
|
const hasScopeProp = contract?.props?.includes('scope') === true;
|
|
651
|
+
// 读状态属性:契约声明了 loading / error_text 且对象有数据来源才标记(契约只给属性名,类型由组件契约自身保证)
|
|
652
|
+
const hasSource = hasBehaviorFrom(obj.behavior);
|
|
653
|
+
const hasLoadingProp = hasSource && contract?.props?.includes('loading') === true;
|
|
654
|
+
const hasErrorTextProp = hasSource && contract?.props?.includes('error_text') === true;
|
|
655
|
+
// 无 error_text 的组件(如 ItemList)用 string 型 error 属性承接读失败:契约给了 propTypes 才按类型认(没给不绑)
|
|
656
|
+
const hasErrorProp = hasSource && !hasErrorTextProp && contract?.props?.includes('error') === true && contract?.propTypes?.error === 'string';
|
|
657
|
+
// 读失败自动重试:绑了读取错误、契约有 retry 事件与 retry_text 属性(RecordPicker 只有 error_text 与自带 search 重试,无 retry 事件,不受影响)
|
|
658
|
+
const autoRetry = (hasErrorTextProp || hasErrorProp)
|
|
659
|
+
&& contract?.emits?.includes('retry') === true
|
|
660
|
+
&& contract?.props?.includes('retry_text') === true;
|
|
390
661
|
// 右键菜单:只有带行级动作的写死形状组件(ItemList / Tree / Kanban)接受;其它(Chart 等)报 KIT-MENU-001
|
|
391
662
|
let ctxActions: ReturnType<typeof resolveContextMenuItems> = [];
|
|
392
663
|
if (form.contextMenu !== undefined) {
|
|
393
664
|
if (!KIT_CONTEXT_MENU.staticComponents.includes(form.staticComponent)) {
|
|
394
|
-
diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `组件 ${form.staticComponent} 没有行级动作,不能写 contextMenu(只用于 ${KIT_CONTEXT_MENU.staticComponents.join(' / ')} 与 table / treeTable / cards / stack
|
|
665
|
+
diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `组件 ${form.staticComponent} 没有行级动作,不能写 contextMenu(只用于 ${KIT_CONTEXT_MENU.staticComponents.join(' / ')} 与 table / treeTable / cards / stack 集合)` });
|
|
395
666
|
} else {
|
|
396
667
|
ctxActions = resolveContextMenuItems(form.contextMenu, [], obj.behavior.actions ?? [], `${path}.contextMenu`, diags);
|
|
397
668
|
}
|
|
398
669
|
}
|
|
670
|
+
const staticBase = mergeClass(KIT_CLASS_DEFAULTS.staticRoot, slotKnobs.extraWrapClass);
|
|
399
671
|
return {
|
|
400
672
|
...viewTexts(slot, form, path, diags),
|
|
401
673
|
mode: 'show',
|
|
674
|
+
...(slotKnobs.emphasis !== undefined ? { emphasis: slotKnobs.emphasis } : {}),
|
|
675
|
+
...(slotKnobs.surface !== undefined ? { surface: slotKnobs.surface } : {}),
|
|
676
|
+
...(slotKnobs.highlight === true ? { highlight: true } : {}),
|
|
402
677
|
layout: {
|
|
403
678
|
kind: 'static',
|
|
404
679
|
component: form.staticComponent,
|
|
@@ -409,8 +684,12 @@ function renderSlot(
|
|
|
409
684
|
...(extraProps.value !== undefined ? { value: extraProps.value } : {}),
|
|
410
685
|
...(on !== undefined ? { on } : {}),
|
|
411
686
|
...(dataSubmit ? { dataSubmit: true, ...(hasScopeProp ? { hasScopeProp: true } : {}) } : {}),
|
|
687
|
+
...(hasLoadingProp ? { hasLoadingProp: true } : {}),
|
|
688
|
+
...(hasErrorTextProp ? { hasErrorTextProp: true } : {}),
|
|
689
|
+
...(hasErrorProp ? { hasErrorProp: true } : {}),
|
|
690
|
+
...(autoRetry ? { autoRetry: true } : {}),
|
|
412
691
|
...(ctxActions.length > 0 ? { contextMenu: ctxActions } : {}),
|
|
413
|
-
class: mergeClass(
|
|
692
|
+
class: mergeClass(staticBase, form.class, form.replaceClass),
|
|
414
693
|
},
|
|
415
694
|
};
|
|
416
695
|
}
|
|
@@ -428,9 +707,9 @@ function renderSlot(
|
|
|
428
707
|
path,
|
|
429
708
|
slot,
|
|
430
709
|
requiredMark,
|
|
431
|
-
...(policy !== null ? { policy } : {}),
|
|
432
710
|
...(ctx.locale !== undefined ? { locale: ctx.locale } : {}),
|
|
433
711
|
...(emptyEnv !== undefined ? { empty: emptyEnv } : {}),
|
|
712
|
+
staticPropKeys: (component: string) => ctx.staticComponents?.[component]?.props,
|
|
434
713
|
actions: obj.behavior.actions ?? [],
|
|
435
714
|
...(ctx.expandHosts !== undefined ? { expandHosts: ctx.expandHosts } : {}),
|
|
436
715
|
renderExpand: (viewName: string, at: string): KitExpandIR | null => {
|
|
@@ -471,19 +750,31 @@ function renderSlot(
|
|
|
471
750
|
if (grouped !== null) {
|
|
472
751
|
layout = grouped;
|
|
473
752
|
} else if (form.collection) {
|
|
474
|
-
layout = collection(withViewContextMenu(form.collection, form, slot), refs, form, env);
|
|
753
|
+
layout = collection(withViewContextMenu(form.collection, form, slot, diags), refs, form, env);
|
|
475
754
|
} else if (form.arrange) {
|
|
476
755
|
layout = arrange(form.arrange, refs, form, env);
|
|
477
756
|
} else if (dflt.collection) {
|
|
478
|
-
layout = collection(withViewContextMenu(dflt.collection, form, slot), refs, form, env);
|
|
757
|
+
layout = collection(withViewContextMenu(dflt.collection, form, slot, diags), refs, form, env);
|
|
479
758
|
} else {
|
|
480
759
|
layout = arrange(dflt.arrange!, refs, form, env);
|
|
481
760
|
}
|
|
482
761
|
// 没有行级动作的视图(summary / form / filter、排布而非集合的 list)写了 contextMenu:KIT-MENU-001
|
|
483
762
|
if (form.contextMenu !== undefined && !(slot === 'list' && (layout.kind === 'table' || layout.kind === 'cards' || layout.kind === 'stack'))) {
|
|
484
|
-
diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `${slot} 视图没有行级动作,不能写 contextMenu(只用于 table / treeTable / cards / stack 集合与 ItemList / Tree / Kanban
|
|
763
|
+
diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `${slot} 视图没有行级动作,不能写 contextMenu(只用于 table / treeTable / cards / stack 集合与 ItemList / Tree / Kanban)` });
|
|
485
764
|
}
|
|
486
765
|
|
|
766
|
+
applyWrapKnobClass(layout, slotKnobs.extraWrapClass);
|
|
767
|
+
// 字段项 props 绑展示对象 / 行字段(RV-1119):就地把格 props 里的 view.<成员> 换成 core 路径,row.<字段> 记进 cell.rowProps
|
|
768
|
+
bindFieldProps(slot, form, layoutCells(layout), path, diags, schema);
|
|
769
|
+
if (slot === 'filter' && fopts.filterOverflow === true) {
|
|
770
|
+
const limit = fopts.defaultCollapsedCount ?? 4;
|
|
771
|
+
let nonDividerIdx = 0;
|
|
772
|
+
for (const c of layoutCells(layout)) {
|
|
773
|
+
if (c.placeholder === true || c.divider === true || c.component === '') continue;
|
|
774
|
+
if (nonDividerIdx >= limit) c.overflow = true;
|
|
775
|
+
nonDividerIdx += 1;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
487
778
|
const modes = new Set(layoutCells(layout).filter((c) => !c.placeholder).map((c) => c.mode));
|
|
488
779
|
const mode = modes.size === 0 ? (slot === 'filter' ? 'edit' : slotModeOf(slot, {}, ctx.formCtx)) : modes.size === 1 ? [...modes][0] : 'mixed';
|
|
489
780
|
// view.loading: skeleton:只读的 summary / form 才有(可编辑 form 的初值来自协调组件,没有"数据未到"的瞬间)
|
|
@@ -493,11 +784,26 @@ function renderSlot(
|
|
|
493
784
|
else skeleton = true;
|
|
494
785
|
}
|
|
495
786
|
const groupTabs = layout.kind === 'groups' && layout.tabs === true;
|
|
496
|
-
|
|
787
|
+
// 展示对象的纯路径绑定:字段项 hidden / disabled / required、view.form.onDraft
|
|
788
|
+
const fieldState = collectFieldState(slot, form, path, diags, schema);
|
|
789
|
+
const onDraft = checkOnDraft(slot, form, path, diags);
|
|
790
|
+
const submitDisabled = checkSubmitDisabled(slot, form, path, diags);
|
|
791
|
+
const formOpts: KitFormOpts = {
|
|
792
|
+
...fopts,
|
|
793
|
+
...(groupTabs ? { groupTabs: true } : {}),
|
|
794
|
+
...(Object.keys(fieldState).length > 0 ? { fieldState } : {}),
|
|
795
|
+
...(onDraft !== undefined ? { onDraft } : {}),
|
|
796
|
+
...(submitDisabled !== undefined ? { submitDisabled } : {}),
|
|
797
|
+
};
|
|
798
|
+
const hasFrom = slot !== 'filter' && hasBehaviorFrom(obj.behavior);
|
|
497
799
|
return {
|
|
498
800
|
layout, mode, ...(skeleton ? { skeleton } : {}), ...viewTexts(slot, form, path, diags),
|
|
801
|
+
...(slotKnobs.emphasis !== undefined ? { emphasis: slotKnobs.emphasis } : {}),
|
|
802
|
+
...(slotKnobs.surface !== undefined ? { surface: slotKnobs.surface } : {}),
|
|
803
|
+
...(slotKnobs.highlight === true ? { highlight: true } : {}),
|
|
499
804
|
...(Object.keys(formOpts).length > 0 ? { formOpts } : {}),
|
|
500
|
-
|
|
805
|
+
...(hasFrom ? { readState: readStatePathsOf(ctx.object) } : {}),
|
|
806
|
+
} as KitViewIR;
|
|
501
807
|
}
|
|
502
808
|
|
|
503
809
|
/**
|
|
@@ -588,6 +894,7 @@ function groupsLayout(form: KitViewForm, env: KitCellEnv, fallbackArrange: KitAr
|
|
|
588
894
|
refs.push({ ...item, name: `__divider_g${i}_${dividerSeq++}` });
|
|
589
895
|
continue;
|
|
590
896
|
}
|
|
897
|
+
if (slot === 'form' && env.schema[item.name]?.hidden === true) continue;
|
|
591
898
|
if (seen.has(item.name)) {
|
|
592
899
|
env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.fields`, message: `字段 ${item.name} 在多节里重复出现` });
|
|
593
900
|
continue;
|
|
@@ -611,13 +918,28 @@ function groupsLayout(form: KitViewForm, env: KitCellEnv, fallbackArrange: KitAr
|
|
|
611
918
|
else if (typeof g.divider === 'string') divider = g.divider;
|
|
612
919
|
else if (g.divider !== false) env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.divider`, message: 'divider 必须是布尔或分隔线文字' });
|
|
613
920
|
}
|
|
921
|
+
let grpEmphasis: 'primary' | 'normal' | 'subtle' | undefined;
|
|
922
|
+
if (g.emphasis !== undefined) {
|
|
923
|
+
if (g.emphasis === 'primary' || g.emphasis === 'normal' || g.emphasis === 'subtle') grpEmphasis = g.emphasis;
|
|
924
|
+
else env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.emphasis`, message: 'groups[i].emphasis 只许 primary / normal / subtle' });
|
|
925
|
+
}
|
|
926
|
+
let grpSurface: 'card' | 'flush' | 'plain' | undefined;
|
|
927
|
+
if (g.surface !== undefined) {
|
|
928
|
+
if (g.surface === 'card' || g.surface === 'flush' || g.surface === 'plain') grpSurface = g.surface;
|
|
929
|
+
else env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.surface`, message: 'groups[i].surface 只许 card / flush / plain' });
|
|
930
|
+
}
|
|
931
|
+
const grpLayout = arrange(form.arrange ?? fallbackArrange, refs, form, { ...env, path: at });
|
|
932
|
+
const grpExtra = [grpSurface ? resolveSurfaceRecipeClass(grpSurface) : '', grpEmphasis ? resolveContainerEmphasisClass(grpEmphasis) : ''].filter(Boolean).join(' ');
|
|
933
|
+
applyWrapKnobClass(grpLayout, grpExtra);
|
|
614
934
|
out.push({
|
|
615
935
|
title: g.title,
|
|
616
|
-
layout:
|
|
936
|
+
layout: grpLayout,
|
|
617
937
|
id: `${objectName}__${slot}__g${i}`,
|
|
618
938
|
collapsible,
|
|
619
939
|
open,
|
|
620
940
|
divider,
|
|
941
|
+
...(grpEmphasis !== undefined ? { emphasis: grpEmphasis } : {}),
|
|
942
|
+
...(grpSurface !== undefined ? { surface: grpSurface } : {}),
|
|
621
943
|
});
|
|
622
944
|
});
|
|
623
945
|
if (out.length === 0) return null;
|
|
@@ -641,15 +963,34 @@ function groupsLayout(form: KitViewForm, env: KitCellEnv, fallbackArrange: KitAr
|
|
|
641
963
|
function viewTexts(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): { title?: string; submitLabel?: string } {
|
|
642
964
|
const out: { title?: string; submitLabel?: string } = {};
|
|
643
965
|
if (form.title !== undefined) {
|
|
644
|
-
if (
|
|
966
|
+
if (slot === 'filter') {
|
|
967
|
+
diags.push({ code: 'KIT-OBJ-007', path: `${path}.title`, message: 'filter 视图不支持 title' });
|
|
968
|
+
} else if (typeof form.title === 'string') {
|
|
645
969
|
if (slot === 'list' || slot === 'summary') out.title = form.title;
|
|
646
970
|
} else if (slot !== 'form') {
|
|
647
971
|
diags.push({ code: 'KIT-OBJ-007', path: `${path}.title`, message: `${slot} 视图的 title 必须是字符串({ create, edit } 只用于 form)` });
|
|
972
|
+
} else if (form.title === null || typeof form.title !== 'object' || Array.isArray(form.title)) {
|
|
973
|
+
diags.push({ code: 'KIT-OBJ-007', path: `${path}.title`, message: 'form 视图的 title 必须是字符串或 { create?, edit? }' });
|
|
974
|
+
} else {
|
|
975
|
+
const tObj = form.title as Record<string, unknown>;
|
|
976
|
+
for (const [k, v] of Object.entries(tObj)) {
|
|
977
|
+
if (k !== 'create' && k !== 'edit') {
|
|
978
|
+
diags.push({ code: 'KIT-OBJ-007', path: `${path}.title.${k}`, message: `form.title 只许 create / edit,未知键 ${k}` });
|
|
979
|
+
} else if (v !== undefined && typeof v !== 'string') {
|
|
980
|
+
diags.push({ code: 'KIT-OBJ-007', path: `${path}.title.${k}`, message: `form.title.${k} 必须是字符串` });
|
|
981
|
+
}
|
|
982
|
+
}
|
|
648
983
|
}
|
|
649
984
|
}
|
|
650
985
|
if (form.submitLabel !== undefined) {
|
|
651
986
|
if (slot !== 'form') diags.push({ code: 'KIT-OBJ-007', path: `${path}.submitLabel`, message: 'submitLabel 只用于 form 视图' });
|
|
652
|
-
else if (typeof form.submitLabel
|
|
987
|
+
else if (typeof form.submitLabel !== 'string') diags.push({ code: 'KIT-OBJ-007', path: `${path}.submitLabel`, message: 'submitLabel 必须是字符串' });
|
|
988
|
+
else out.submitLabel = form.submitLabel;
|
|
989
|
+
}
|
|
990
|
+
// view.form.notify:保存成功提示的字面量文案(业务组件发 NOTIFY 管道时取用,见 form-notify.ts);这里只判写法
|
|
991
|
+
if (form.notify !== undefined) {
|
|
992
|
+
const problem = slot !== 'form' ? 'notify 只用于 form 视图' : formNotifyProblem(form.notify);
|
|
993
|
+
if (problem !== null) diags.push({ code: 'KIT-OBJ-007', path: `${path}.notify`, message: problem });
|
|
653
994
|
}
|
|
654
995
|
return out;
|
|
655
996
|
}
|
|
@@ -658,18 +999,46 @@ export function renderObject(obj: KitObject, ctx: KitRenderContext): KitObjectIR
|
|
|
658
999
|
const diags: KitDiagnostic[] = [];
|
|
659
1000
|
const schema = resolveSchema(obj, ctx, diags);
|
|
660
1001
|
|
|
1002
|
+
for (const [name, field] of Object.entries(schema)) {
|
|
1003
|
+
checkFieldRules(name, field.rules, `schema.${name}.rules`, diags);
|
|
1004
|
+
}
|
|
1005
|
+
checkEnumOptionsAndEditCompatibility(schema as unknown as Record<string, unknown>, (obj.view ?? {}) as Record<string, unknown>, '', diags);
|
|
1006
|
+
|
|
1007
|
+
const rawBehavior = obj.behavior as unknown as Record<string, unknown>;
|
|
1008
|
+
if (rawBehavior.require_params !== undefined) {
|
|
1009
|
+
diags.push({ code: 'KIT-PAGE-001', path: 'behavior.require_params', message: '未知键 require_params(请改写为 behavior.requireParams)' });
|
|
1010
|
+
}
|
|
1011
|
+
if (rawBehavior.requireParams !== undefined) {
|
|
1012
|
+
if (!Array.isArray(rawBehavior.requireParams)) {
|
|
1013
|
+
diags.push({ code: 'KIT-FORM-004', path: 'behavior.requireParams', message: 'behavior.requireParams 必须是非空字符串数组' });
|
|
1014
|
+
} else {
|
|
1015
|
+
const knownParams = new Set<string>(Object.keys(obj.behavior.params ?? {}));
|
|
1016
|
+
for (const f of fieldNamesOf(obj.view?.filter?.fields)) knownParams.add(f);
|
|
1017
|
+
if (obj.view?.list !== undefined) {
|
|
1018
|
+
knownParams.add('page');
|
|
1019
|
+
knownParams.add('size');
|
|
1020
|
+
knownParams.add('sort');
|
|
1021
|
+
knownParams.add('order');
|
|
1022
|
+
}
|
|
1023
|
+
rawBehavior.requireParams.forEach((k, i) => {
|
|
1024
|
+
if (typeof k !== 'string' || k.trim() === '' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(k)) {
|
|
1025
|
+
diags.push({ code: 'KIT-FORM-004', path: `behavior.requireParams[${i}]`, message: `behavior.requireParams[${i}] 必须是合法的参数名标识符` });
|
|
1026
|
+
} else if (!knownParams.has(k)) {
|
|
1027
|
+
diags.push({ code: 'KIT-FORM-004', path: `behavior.requireParams[${i}]`, message: `behavior.requireParams 的参数 "${k}" 不在该对象的请求参数(params / 筛选 / 分页 / 排序)中` });
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
661
1033
|
(obj.behavior.actions ?? []).forEach((a, i) => {
|
|
662
1034
|
if (Array.isArray(a.permission)) {
|
|
663
1035
|
diags.push({ code: 'KIT-OBJ-006', path: `behavior.actions[${i}].permission`, message: `动作 ${a.id} 的 permission 是数组,kit 层只允许一个权限码` });
|
|
664
1036
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
} else {
|
|
671
|
-
predicateToCore(a.when, `behavior.actions[${i}].when`, new Set(Object.keys(schema)), diags);
|
|
672
|
-
}
|
|
1037
|
+
if (a.tone !== undefined && (typeof a.tone !== 'string' || !KIT_ACTION_TONES.includes(a.tone))) {
|
|
1038
|
+
diags.push({ code: 'KIT-ACT-010', path: `behavior.actions[${i}].tone`, message: `动作 ${a.id} 的 tone "${String(a.tone)}" 不在闭集(允许:${KIT_ACTION_TONES.join(' / ')})` });
|
|
1039
|
+
}
|
|
1040
|
+
if (a.request !== undefined || a.download !== undefined) {
|
|
1041
|
+
validateRequestAction(a, `behavior.actions[${i}]`, diags);
|
|
673
1042
|
}
|
|
674
1043
|
});
|
|
675
1044
|
|
|
@@ -681,17 +1050,15 @@ export function renderObject(obj: KitObject, ctx: KitRenderContext): KitObjectIR
|
|
|
681
1050
|
|
|
682
1051
|
const views: KitObjectIR['views'] = {};
|
|
683
1052
|
const declared = obj.view ?? {};
|
|
684
|
-
// GB2 / GB3
|
|
1053
|
+
// GB2 / GB3:字段 default / hidden 的写法在这里统一核(每个对象一次)
|
|
685
1054
|
const formDecl = declared.form;
|
|
686
1055
|
const rawGroups: unknown[] = Array.isArray(formDecl?.groups) ? (formDecl?.groups as unknown[]) : [];
|
|
687
1056
|
const groupFieldNames = rawGroups.flatMap((g) => (
|
|
688
|
-
g !== null && typeof g === 'object'
|
|
689
|
-
? ((g as { fields: unknown[] }).fields).flatMap((f) => (typeof f === 'string' ? [f] : []))
|
|
690
|
-
: []));
|
|
1057
|
+
g !== null && typeof g === 'object' ? fieldNamesOf((g as { fields?: unknown }).fields) : []));
|
|
691
1058
|
const fieldValue = collectFieldValues(schema, formDecl?.fields, groupFieldNames, diags);
|
|
692
1059
|
checkFlowFields(schema, diags);
|
|
693
|
-
checkViewRowColumns(declared as Record<string, unknown>, diags
|
|
694
|
-
checkViewFlowNodeOptions(declared as Record<string, unknown>,
|
|
1060
|
+
checkViewRowColumns(declared as Record<string, unknown>, diags);
|
|
1061
|
+
checkViewFlowNodeOptions(declared as Record<string, unknown>, diags);
|
|
695
1062
|
for (const key of Object.keys(declared)) {
|
|
696
1063
|
if (!(KIT_VIEW_SLOTS as readonly string[]).includes(key)) {
|
|
697
1064
|
diags.push({
|