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
|
@@ -5,31 +5,39 @@
|
|
|
5
5
|
// 失败(任何诊断)即拒绝启动。
|
|
6
6
|
// 应用组件、业务组件、页面框重名必须显式点名,不静默覆盖。
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
SomaAuthOption,
|
|
10
|
-
SomaComponentDefinition,
|
|
11
|
-
SomaEventMiddlewareContext,
|
|
8
|
+
import {
|
|
9
|
+
type SomaAuthOption,
|
|
10
|
+
type SomaComponentDefinition,
|
|
11
|
+
type SomaEventMiddlewareContext,
|
|
12
12
|
SomaMiddlewareChain,
|
|
13
|
-
SomaRenderPorts,
|
|
13
|
+
type SomaRenderPorts,
|
|
14
14
|
} from 'soma-core';
|
|
15
|
-
import {
|
|
15
|
+
import { createKitRenderPorts } from './render-ports';
|
|
16
16
|
import type { SomaHostAssembly } from 'soma-core/server/host-assembly';
|
|
17
17
|
import { createKitBaseComponents, KIT_BASE_COMPONENTS } from '../base/index';
|
|
18
18
|
import { bizDataComponents, KIT_BIZ_DATA_COMPONENTS } from '../biz/data-components';
|
|
19
19
|
import { KIT_BIZ_COMPONENT_NAMES, KIT_FRAME_NAMES } from '../biz/names';
|
|
20
20
|
import type { KitBizDefinition } from '../biz/types';
|
|
21
21
|
import type { KitThemeConfig } from '../theme/theme-tokens';
|
|
22
|
-
import type { KitAppTheme } from './app-config';
|
|
23
|
-
import {
|
|
22
|
+
import type { KitAppDicts, KitAppEntities, KitAppTheme } from './app-config';
|
|
23
|
+
import { parseKitAppEnvelopeFromYaml, registerKitAppDefaultEnvelope, type KitEnvelope } from './envelope';
|
|
24
24
|
import { KitPackError, type KitPack } from './define-kit-pack';
|
|
25
|
+
import { readKitViewInfo, type KitViewClass } from './define-kit-view';
|
|
25
26
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
26
27
|
import { createKitResidentDataComponents } from '../data/resident';
|
|
27
28
|
import { addWrappedOwnCandidates } from '../data/wrapped-candidates';
|
|
28
29
|
import { assertSinglePathComponent } from './component-gate';
|
|
29
30
|
import { KIT_STATIC_BUILTIN_LAZY_NAMES as KIT_STATIC_BUILTIN_NAMES, KIT_STATIC_LAZY_LOADERS } from '../data/static-lazy';
|
|
30
31
|
import type { KitFrameDefinition } from '../frames/types';
|
|
31
|
-
import type
|
|
32
|
+
import { bindKitActionRequestTimeout, isKitDefinedAction, validateKitAppRequestTimeout, type KitNamedAction } from './define-kit-actions';
|
|
32
33
|
import type { KitServerFace } from './server';
|
|
34
|
+
import { checkNoRelativeOrSystemPath } from '../shared/path-guard';
|
|
35
|
+
import { kitFail } from '../compile/kit-error';
|
|
36
|
+
import { configureKitThemeAppId, installKitThemeRuntime, restoreKitThemeBeforeFirstPaint } from './theme-runtime';
|
|
37
|
+
import { withActiveKitActionTarget } from '../biz/shared/runtime-hub';
|
|
38
|
+
import { buildKitThemeBootDataElement, buildKitThemeFirstPaintScript, isKitThemePath, toKitRuntimeTheme } from './theme-runtime-shared';
|
|
39
|
+
|
|
40
|
+
export { checkNoRelativeOrSystemPath };
|
|
33
41
|
|
|
34
42
|
type ComponentInput = SomaComponentDefinition | (() => SomaComponentDefinition);
|
|
35
43
|
|
|
@@ -56,8 +64,14 @@ export interface DefineKitAppOptions {
|
|
|
56
64
|
* 不同目录里的页面 URL 重复报 KIT-PAGE-004。目录不存在视为空。
|
|
57
65
|
*/
|
|
58
66
|
extraPagesDirs?: string[];
|
|
67
|
+
/** dev 模式下单页编译失败时将该页降级渲染为可读的诊断错误页而不阻断其它正常页面(生产模式与 soma kit check 仍严格报错拒绝) */
|
|
68
|
+
devFallback?: boolean;
|
|
59
69
|
/** kit.app.yaml 没写 `theme` 时使用的主题(写了 `theme` 则完全以 yaml 为准,不做字段级合并) */
|
|
60
70
|
defaultTheme?: KitThemeConfig | KitAppTheme;
|
|
71
|
+
/** 应用级共享枚举字典(也可在 kit.app.yaml 的 dicts: 声明) */
|
|
72
|
+
dicts?: KitAppDicts;
|
|
73
|
+
/** 应用级共享实体定义(也可在 kit.app.yaml 的 entities: 声明) */
|
|
74
|
+
entities?: KitAppEntities;
|
|
61
75
|
/**
|
|
62
76
|
* 领域包(`defineKitPack` 的返回值,如 soma-kit/packs/commerce 的 commercePack)。
|
|
63
77
|
* 装配时把包内的数据组件、业务组件、协作数据组件与候选类并入;重名报 KIT-PACK-002。
|
|
@@ -69,6 +83,14 @@ export interface DefineKitAppOptions {
|
|
|
69
83
|
staticObjectComponents?: Record<string, KitStaticComponentInput>;
|
|
70
84
|
/** defineKitActions 的返回值 */
|
|
71
85
|
actions?: Record<string, KitNamedAction>;
|
|
86
|
+
/** defineKitActions 注入的 HTTP 默认超时毫秒数;0 禁用,或用核心写超时区间内的整数。逐次 timeoutMs 优先并保留既有范围;未设置沿用 design Host 缺省,手写 KitNamedAction 不变。 */
|
|
87
|
+
requestTimeout?: number;
|
|
88
|
+
/**
|
|
89
|
+
* 页面的展示对象(View Object,交互逻辑的承载位):可传 `[OrderView, ...]` 数组(直接从每个 `cls.viewName` 读取名字)
|
|
90
|
+
* 或 `{ 类名: defineKitView 的返回值 }`(键必须等于定义里的 name)。
|
|
91
|
+
* 页面用 `page.view: 类名` 指向它,一页至多一个、一个展示对象至多被一页引用;没写 page.view 的页面(含 AI 生成页)使用默认空展示对象。
|
|
92
|
+
*/
|
|
93
|
+
views?: Record<string, KitViewClass> | readonly KitViewClass[];
|
|
72
94
|
/** 应用扩展的业务组件 / 页面框;与内置同名必须在 overrides 点名 */
|
|
73
95
|
bizComponents?: Record<string, KitBizDefinition>;
|
|
74
96
|
frames?: Record<string, KitFrameDefinition>;
|
|
@@ -111,6 +133,9 @@ export interface KitAppRegistry {
|
|
|
111
133
|
baseComponents: Record<string, SomaComponentDefinition>;
|
|
112
134
|
staticComponents: Record<string, { definition: SomaComponentDefinition; accept?: 'single' | 'list' }>;
|
|
113
135
|
actions: Record<string, KitNamedAction>;
|
|
136
|
+
/** 展示对象类(浏览器 pageRoots 表)及其成员 / 方法清单(编译期核对) */
|
|
137
|
+
views: Record<string, KitViewClass>;
|
|
138
|
+
viewInfos: Record<string, { stateKeys: ReadonlySet<string>; methodNames: ReadonlySet<string>; shape: import('soma-foundation/view-state').ViewStateShape }>;
|
|
114
139
|
bizComponents: Record<string, KitBizDefinition>;
|
|
115
140
|
frames: Record<string, KitFrameDefinition>;
|
|
116
141
|
appCandidates: readonly string[];
|
|
@@ -118,6 +143,8 @@ export interface KitAppRegistry {
|
|
|
118
143
|
packDataComponents: Record<string, SomaComponentDefinition>;
|
|
119
144
|
/** 已登记的领域包名 */
|
|
120
145
|
packNames: readonly string[];
|
|
146
|
+
/** 本应用实例持有的应用级业务信封(kit.app.yaml#envelope):服务端装配 / 浏览器引导写入,本应用具名动作的 http 兜底读取;不是进程全局 */
|
|
147
|
+
readonly appEnvelope: { current: KitEnvelope | undefined };
|
|
121
148
|
}
|
|
122
149
|
|
|
123
150
|
export interface KitBrowserMount {
|
|
@@ -126,6 +153,8 @@ export interface KitBrowserMount {
|
|
|
126
153
|
/** 内置写死形状数据组件(Tree / Chart / Timeline 等)的按需加载工厂:core 只补载本页引用到的,打包器按动态 import 分片 */
|
|
127
154
|
lazyComponents: Record<string, () => Promise<SomaComponentDefinition>>;
|
|
128
155
|
actions: Record<string, KitNamedAction>;
|
|
156
|
+
/** 展示对象(页面根类)表:交 core 的 SomaBootstrap.pageRoots,引擎按页面 bind.obj 取类 */
|
|
157
|
+
pageRoots: Record<string, KitViewClass>;
|
|
129
158
|
}
|
|
130
159
|
|
|
131
160
|
export interface KitApp {
|
|
@@ -145,10 +174,10 @@ const ACTION_NAME = /^[a-z][a-zA-Z0-9_]*$/;
|
|
|
145
174
|
function instantiate(name: string, input: ComponentInput): SomaComponentDefinition {
|
|
146
175
|
const def = typeof input === 'function' ? input() : input;
|
|
147
176
|
if (def === null || typeof def !== 'object' || (def as { contract?: unknown }).contract === undefined) {
|
|
148
|
-
|
|
177
|
+
kitFail('KIT-APP-006', `components.${name}`, `应用组件 ${name} 不是组件定义(需 defineComponent 的返回值或返回它的函数)`, '用 defineComponent 定义组件,登记时传它的返回值或返回它的函数');
|
|
149
178
|
}
|
|
150
179
|
if (def.contract.name !== name) {
|
|
151
|
-
|
|
180
|
+
kitFail('KIT-APP-006', `components.${name}`, `应用组件登记名 "${name}" 与契约名 "${def.contract.name}" 不一致`, `把登记名或契约 name 改成同一个,如都写 ${def.contract.name}`);
|
|
152
181
|
}
|
|
153
182
|
return def;
|
|
154
183
|
}
|
|
@@ -162,50 +191,110 @@ function isSpec(v: KitStaticComponentInput): v is { define: ComponentInput; acce
|
|
|
162
191
|
|
|
163
192
|
/** 校验并规整应用登记;任何冲突当场抛(装配期失败,不拖到运行期) */
|
|
164
193
|
export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
194
|
+
validateKitAppRequestTimeout(options.requestTimeout);
|
|
195
|
+
if (options.login?.path !== undefined) {
|
|
196
|
+
const loginDiags: KitDiagnostic[] = [];
|
|
197
|
+
if (!checkNoRelativeOrSystemPath(options.login.path, 'login.path', loginDiags, 'KIT-APP-001')) {
|
|
198
|
+
kitFail('KIT-APP-001', 'login.path', loginDiags[0]!.message, '改为以 / 开头的站内路由路径(如 /login),严禁相对路径或系统绝对路径');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (options.app !== undefined) {
|
|
202
|
+
const appDiags: KitDiagnostic[] = [];
|
|
203
|
+
if (!checkNoRelativeOrSystemPath(options.app, 'app', appDiags, 'KIT-APP-001', { allowConfigSubpath: true })) {
|
|
204
|
+
kitFail('KIT-APP-001', 'app', appDiags[0]!.message, '改为相对应用根的配置名(如 kit.app.yaml),严禁 ./、../ 或宿主机系统绝对路径');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (options.pagesDir !== undefined) {
|
|
208
|
+
const pagesDiags: KitDiagnostic[] = [];
|
|
209
|
+
if (!checkNoRelativeOrSystemPath(options.pagesDir, 'pagesDir', pagesDiags, 'KIT-APP-001', { allowConfigSubpath: true })) {
|
|
210
|
+
kitFail('KIT-APP-001', 'pagesDir', pagesDiags[0]!.message, '改为相对应用根的页面子目录名(如 pages),严禁 ./、../ 或宿主机系统绝对路径');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
165
213
|
const allow = new Set(options.overrides ?? []);
|
|
166
214
|
const builtinBase = new Set<string>(Object.keys(KIT_BASE_COMPONENTS));
|
|
167
215
|
const baseComponents: KitAppRegistry['baseComponents'] = {};
|
|
168
216
|
for (const [name, input] of Object.entries(options.baseComponents ?? {})) {
|
|
169
|
-
if (!APP_NAME.test(name))
|
|
170
|
-
if (builtinBase.has(name) && !allow.has(name))
|
|
217
|
+
if (!APP_NAME.test(name)) kitFail('KIT-APP-006', `baseComponents.${name}`, `应用基础组件名必须以 App 开头(如 AppCopyCode),收到 "${name}"`, `改名为 App${name.charAt(0).toUpperCase()}${name.slice(1)}`);
|
|
218
|
+
if (builtinBase.has(name) && !allow.has(name)) kitFail('KIT-APP-007', `baseComponents.${name}`, `基础组件 "${name}" 已内置;要覆盖请在 overrides 点名`, `换一个 App 开头的新名字,或在 defineKitApp 的 overrides 里加入 "${name}"`);
|
|
171
219
|
const def = instantiate(name, input);
|
|
172
|
-
if (def.contract['layer'] !== 'basic')
|
|
220
|
+
if (def.contract['layer'] !== 'basic') kitFail('KIT-APP-006', `baseComponents.${name}`, `应用基础组件 ${name} 的契约 layer 必须是 basic`, '契约 layer 改为 basic;业务含数据的组件请登记到 staticObjectComponents');
|
|
173
221
|
assertSinglePathComponent(name, def);
|
|
174
222
|
baseComponents[name] = def;
|
|
175
223
|
}
|
|
176
224
|
|
|
177
225
|
const staticComponents: KitAppRegistry['staticComponents'] = {};
|
|
178
226
|
for (const [name, input] of Object.entries(options.staticObjectComponents ?? {})) {
|
|
179
|
-
if (!APP_NAME.test(name))
|
|
227
|
+
if (!APP_NAME.test(name)) kitFail('KIT-APP-006', `staticObjectComponents.${name}`, `应用数据组件名必须以 App 开头(如 AppLogisticsTrack),收到 "${name}"`, `改名为 App${name.charAt(0).toUpperCase()}${name.slice(1)}`);
|
|
180
228
|
if (KIT_STATIC_BUILTIN_NAMES.includes(name) && !allow.has(name)) {
|
|
181
|
-
|
|
229
|
+
kitFail('KIT-APP-007', `staticObjectComponents.${name}`, `写死形状组件 "${name}" 已内置;要覆盖请在 overrides 点名`, `换一个 App 开头的新名字,或在 defineKitApp 的 overrides 里加入 "${name}"`);
|
|
182
230
|
}
|
|
183
|
-
if (name in baseComponents)
|
|
231
|
+
if (name in baseComponents) kitFail('KIT-APP-007', `staticObjectComponents.${name}`, `"${name}" 同时登记为基础组件与数据组件`, '一个组件名只登记一处:从 baseComponents 或 staticObjectComponents 删掉其一');
|
|
184
232
|
const spec = isSpec(input);
|
|
185
233
|
const def = instantiate(name, spec ? input.define : input);
|
|
186
|
-
if (def.contract['layer'] !== 'data')
|
|
234
|
+
if (def.contract['layer'] !== 'data') kitFail('KIT-APP-006', `staticObjectComponents.${name}`, `应用数据组件 ${name} 的契约 layer 必须是 data`, '契约 layer 改为 data;纯展示小件请登记到 baseComponents');
|
|
187
235
|
assertSinglePathComponent(name, def);
|
|
188
236
|
staticComponents[name] = spec ? { definition: def, accept: input.accept } : { definition: def };
|
|
189
237
|
}
|
|
190
238
|
|
|
239
|
+
// 应用级信封持有者:属于本应用实例(服务端装配写 kit.app.yaml 的 envelope,浏览器引导写 appYaml 的 envelope),本应用的具名动作按它取缺省信封
|
|
240
|
+
const appEnvelope: { current: KitEnvelope | undefined } = { current: undefined };
|
|
191
241
|
const actions: Record<string, KitNamedAction> = {};
|
|
242
|
+
const handWrittenActions: string[] = [];
|
|
192
243
|
for (const [name, fn] of Object.entries(options.actions ?? {})) {
|
|
193
|
-
if (!ACTION_NAME.test(name))
|
|
194
|
-
if (typeof fn !== 'function')
|
|
195
|
-
actions[name] = fn;
|
|
244
|
+
if (!ACTION_NAME.test(name)) kitFail('KIT-APP-008', `actions.${name}`, `具名动作名不合法:"${name}"`, '动作名用小写字母开头的标识符(字母数字下划线),与 ACTION | 名字 同一文法');
|
|
245
|
+
if (typeof fn !== 'function') kitFail('KIT-APP-008', `actions.${name}`, `具名动作 "${name}" 不是函数(用 defineKitActions 包装)`, '用 defineKitActions({ 名字: async (ctx) => {...} }) 定义后再登记');
|
|
246
|
+
actions[name] = bindKitActionRequestTimeout(fn, options.requestTimeout, () => appEnvelope.current);
|
|
247
|
+
if (options.requestTimeout !== undefined && !isKitDefinedAction(fn)) handWrittenActions.push(name);
|
|
248
|
+
}
|
|
249
|
+
if (handWrittenActions.length > 0) {
|
|
250
|
+
console.warn(`[soma-kit] 应用配置了 requestTimeout,但这些动作不是 defineKitActions 产出,应用级 requestTimeout 对其不生效:${handWrittenActions.join('、')}`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// 展示对象:登记名 = 类名,值必须是 defineKitView 的返回值(支持 readonly KitViewClass[] 数组或 Record<string, KitViewClass>)
|
|
254
|
+
const views: Record<string, KitViewClass> = {};
|
|
255
|
+
const viewInfos: KitAppRegistry['viewInfos'] = {};
|
|
256
|
+
if (Array.isArray(options.views)) {
|
|
257
|
+
for (let i = 0; i < options.views.length; i++) {
|
|
258
|
+
const cls = options.views[i] as KitViewClass | undefined;
|
|
259
|
+
const rawViewName = typeof (cls as { viewName?: unknown } | null)?.viewName === 'string' && (cls as { viewName: string }).viewName !== ''
|
|
260
|
+
? (cls as { viewName: string }).viewName
|
|
261
|
+
: undefined;
|
|
262
|
+
const info = readKitViewInfo(cls);
|
|
263
|
+
const label = rawViewName ?? info?.name ?? `[${i}]`;
|
|
264
|
+
if (info === undefined) {
|
|
265
|
+
kitFail('KIT-VIEW-005', `views.${label}`, `展示对象 "${label}" 不是 defineKitView 的返回值`, '用 defineKitView({ name, state, methods }) 定义后再登记');
|
|
266
|
+
}
|
|
267
|
+
const name = rawViewName ?? info.name;
|
|
268
|
+
if (info.name !== name) {
|
|
269
|
+
kitFail('KIT-VIEW-005', `views.${name}`, `展示对象登记名 "${name}" 与定义的 name "${info.name}" 不一致`, '登记名必须等于 defineKitView 的 name,也就是页面 page.view 写的名字');
|
|
270
|
+
}
|
|
271
|
+
if (name in views) {
|
|
272
|
+
kitFail('KIT-VIEW-005', `views.${name}`, `展示对象 "${name}" 重复登记`, '同一个展示对象在 views 中只登记一次');
|
|
273
|
+
}
|
|
274
|
+
views[name] = cls!;
|
|
275
|
+
viewInfos[name] = { stateKeys: info.stateKeys, methodNames: info.methodNames, shape: info.shape };
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
for (const [name, cls] of Object.entries(options.views ?? {})) {
|
|
279
|
+
const info = readKitViewInfo(cls);
|
|
280
|
+
if (info === undefined) kitFail('KIT-VIEW-005', `views.${name}`, `展示对象 "${name}" 不是 defineKitView 的返回值`, '用 defineKitView({ name, state, methods }) 定义后再登记');
|
|
281
|
+
if (info.name !== name) kitFail('KIT-VIEW-005', `views.${name}`, `展示对象登记名 "${name}" 与定义的 name "${info.name}" 不一致`, '登记名必须等于 defineKitView 的 name,也就是页面 page.view 写的名字');
|
|
282
|
+
views[name] = cls;
|
|
283
|
+
viewInfos[name] = { stateKeys: info.stateKeys, methodNames: info.methodNames, shape: info.shape };
|
|
284
|
+
}
|
|
196
285
|
}
|
|
197
286
|
|
|
198
287
|
// 业务组件 / 页面框与内置同名:必须在 overrides 点名,不静默覆盖;登记名必须等于定义的 kind
|
|
199
288
|
for (const [name, def] of Object.entries(options.bizComponents ?? {})) {
|
|
200
|
-
if (def === null || typeof def !== 'object' || def.kind !== name)
|
|
289
|
+
if (def === null || typeof def !== 'object' || def.kind !== name) kitFail('KIT-APP-009', `bizComponents.${name}`, `业务组件登记名 "${name}" 与定义的 kind 不一致`, '登记名必须等于定义的 kind');
|
|
201
290
|
if (KIT_BIZ_COMPONENT_NAMES.includes(name) && !allow.has(name)) {
|
|
202
|
-
|
|
291
|
+
kitFail('KIT-APP-007', `bizComponents.${name}`, `业务组件 "${name}" 已内置;要覆盖请在 overrides 点名`, `换一个新名字,或在 defineKitApp 的 overrides 里加入 "${name}"`);
|
|
203
292
|
}
|
|
204
293
|
}
|
|
205
294
|
for (const [name, def] of Object.entries(options.frames ?? {})) {
|
|
206
|
-
if (def === null || typeof def !== 'object' || def.kind !== name)
|
|
295
|
+
if (def === null || typeof def !== 'object' || def.kind !== name) kitFail('KIT-APP-009', `frames.${name}`, `页面框登记名 "${name}" 与定义的 kind 不一致`, '登记名必须等于定义的 kind');
|
|
207
296
|
if (KIT_FRAME_NAMES.includes(name) && !allow.has(name)) {
|
|
208
|
-
|
|
297
|
+
kitFail('KIT-APP-007', `frames.${name}`, `页面框 "${name}" 已内置;要覆盖请在 overrides 点名`, `换一个新名字,或在 defineKitApp 的 overrides 里加入 "${name}"`);
|
|
209
298
|
}
|
|
210
299
|
}
|
|
211
300
|
const bizComponents: Record<string, KitBizDefinition> = { ...(options.bizComponents ?? {}) };
|
|
@@ -218,11 +307,14 @@ export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
|
218
307
|
baseComponents,
|
|
219
308
|
staticComponents,
|
|
220
309
|
actions,
|
|
310
|
+
views,
|
|
311
|
+
viewInfos,
|
|
221
312
|
bizComponents,
|
|
222
313
|
frames: { ...(options.frames ?? {}) },
|
|
223
314
|
appCandidates: options.packs !== undefined && options.packs.length > 0 ? [...candidates] : (options.appCandidates ?? []),
|
|
224
315
|
packDataComponents,
|
|
225
316
|
packNames,
|
|
317
|
+
appEnvelope,
|
|
226
318
|
};
|
|
227
319
|
}
|
|
228
320
|
|
|
@@ -319,7 +411,7 @@ export function buildBrowserMount(registry: KitAppRegistry): KitBrowserMount {
|
|
|
319
411
|
for (const [name, entry] of Object.entries(registry.staticComponents)) components[name] = entry.definition;
|
|
320
412
|
for (const [name, def] of Object.entries(registry.packDataComponents)) components[name] = def;
|
|
321
413
|
// 应用登记项同名覆盖内置时,常驻表优先(core 以 components 为准),不再按需加载内置版
|
|
322
|
-
return { components, lazyComponents: { ...KIT_STATIC_LAZY_LOADERS }, actions: { ...registry.actions } };
|
|
414
|
+
return { components, lazyComponents: { ...KIT_STATIC_LAZY_LOADERS }, actions: { ...registry.actions }, pageRoots: { ...registry.views } };
|
|
323
415
|
}
|
|
324
416
|
|
|
325
417
|
const TREE_CONTEXT = {
|
|
@@ -328,10 +420,19 @@ const TREE_CONTEXT = {
|
|
|
328
420
|
};
|
|
329
421
|
|
|
330
422
|
export function defineKitApp(options: DefineKitAppOptions = {}): KitApp {
|
|
423
|
+
const themeAppId = options.appName ?? options.title;
|
|
424
|
+
if (themeAppId !== undefined) configureKitThemeAppId(themeAppId);
|
|
425
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
426
|
+
restoreKitThemeBeforeFirstPaint(document, themeAppId);
|
|
427
|
+
}
|
|
331
428
|
const registry = buildAppRegistry(options);
|
|
332
429
|
let mount: KitBrowserMount | undefined;
|
|
333
430
|
const browserMount = (): KitBrowserMount => (mount ??= buildBrowserMount(registry));
|
|
334
431
|
let renderPorts: SomaRenderPorts | undefined;
|
|
432
|
+
/** 浏览器引导登记的应用级缺省信封的注销函数(重复引导时先注销再登记) */
|
|
433
|
+
let offAppDefaultEnvelope: (() => void) | undefined;
|
|
434
|
+
|
|
435
|
+
let resolvedBaseTheme = options.defaultTheme !== undefined ? toKitRuntimeTheme(options.defaultTheme) : undefined;
|
|
335
436
|
|
|
336
437
|
// 服务端面按变量说明符惰性 import:浏览器打包器不跟进服务端入口(它含 node:fs 与服务端样式引擎)
|
|
337
438
|
type ServerModule = typeof import('./server');
|
|
@@ -343,18 +444,52 @@ export function defineKitApp(options: DefineKitAppOptions = {}): KitApp {
|
|
|
343
444
|
serverFace ??= (preloaded !== undefined
|
|
344
445
|
? Promise.resolve(preloaded)
|
|
345
446
|
: (import(/* webpackIgnore: true */ /* @vite-ignore */ specifier) as Promise<ServerModule>)
|
|
346
|
-
)
|
|
447
|
+
)
|
|
448
|
+
.then((m) => m.assembleKitServer(options, registry))
|
|
449
|
+
.then(
|
|
450
|
+
(face) => {
|
|
451
|
+
resolvedBaseTheme = toKitRuntimeTheme(face.appContext.theme);
|
|
452
|
+
return face;
|
|
453
|
+
},
|
|
454
|
+
(err) => {
|
|
455
|
+
serverFace = undefined;
|
|
456
|
+
throw err;
|
|
457
|
+
}
|
|
458
|
+
);
|
|
347
459
|
return serverFace;
|
|
348
460
|
};
|
|
349
461
|
|
|
350
|
-
|
|
462
|
+
// documentHead:core 宿主壳按形状读取的可选文档头片段(不在 SomaHostAssembly 类型契约内,故用交叉类型声明)。
|
|
463
|
+
// 交出主题首屏防闪烁脚本与基底主题引导数据元素:在模块脚本执行前恢复本地缓存的主题令牌 CSS 与明暗档,消除首帧闪烁;CSP 开启时带上请求 nonce。
|
|
464
|
+
const host: SomaHostAssembly & {
|
|
465
|
+
readonly documentHead: (ctx: { readonly nonce?: string }) => string;
|
|
466
|
+
invalidate?: () => void;
|
|
467
|
+
} = {
|
|
351
468
|
kind: 'soma-host',
|
|
469
|
+
invalidate() {
|
|
470
|
+
serverFace = undefined;
|
|
471
|
+
},
|
|
472
|
+
documentHead: (ctx) => `${buildKitThemeBootDataElement(themeAppId, resolvedBaseTheme, ctx.nonce)}${buildKitThemeFirstPaintScript(themeAppId, ctx.nonce)}`,
|
|
352
473
|
...(options.reservedRoutes !== undefined ? { reservedRoutes: options.reservedRoutes } : {}),
|
|
353
474
|
...(options.login !== undefined ? { login: options.login } : {}),
|
|
354
475
|
bootstrap() {
|
|
355
|
-
//
|
|
356
|
-
|
|
476
|
+
// 应用级业务信封:在任何页面挂载前交本应用持有(外壳等没有动作宿主的页面也读得到);页面级编译信封由各页面宿主挂载时登记在自己名下,互不覆盖。
|
|
477
|
+
// 没写 envelope 不动已持有的值;重复引导(热更新)先注销上一份缺省登记再登记新值
|
|
478
|
+
if (options.appYaml !== undefined) {
|
|
479
|
+
const parsed = parseKitAppEnvelopeFromYaml(options.appYaml);
|
|
480
|
+
if (parsed !== undefined) {
|
|
481
|
+
registry.appEnvelope.current = parsed;
|
|
482
|
+
offAppDefaultEnvelope?.();
|
|
483
|
+
offAppDefaultEnvelope = registerKitAppDefaultEnvelope(parsed);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
357
486
|
const m = browserMount();
|
|
487
|
+
installKitThemeRuntime(themeAppId);
|
|
488
|
+
const eventMiddlewareChain = new SomaMiddlewareChain<SomaEventMiddlewareContext>();
|
|
489
|
+
eventMiddlewareChain.use((ctx, next) => withActiveKitActionTarget(ctx.element, () => next()));
|
|
490
|
+
if (options.eventMiddleware !== undefined) {
|
|
491
|
+
eventMiddlewareChain.use((ctx, next) => options.eventMiddleware!.execute(ctx, next));
|
|
492
|
+
}
|
|
358
493
|
return {
|
|
359
494
|
...(options.appName !== undefined ? { appName: options.appName } : {}),
|
|
360
495
|
...(options.title !== undefined ? { title: options.title } : {}),
|
|
@@ -363,9 +498,10 @@ export function defineKitApp(options: DefineKitAppOptions = {}): KitApp {
|
|
|
363
498
|
components: m.components,
|
|
364
499
|
lazyComponents: m.lazyComponents,
|
|
365
500
|
actions: m.actions,
|
|
501
|
+
pageRoots: m.pageRoots,
|
|
366
502
|
...(options.auth !== undefined ? { auth: options.auth } : {}),
|
|
367
|
-
|
|
368
|
-
renderPorts: (renderPorts ??= options.renderPorts
|
|
503
|
+
eventMiddleware: eventMiddlewareChain,
|
|
504
|
+
renderPorts: (renderPorts ??= createKitRenderPorts(options.renderPorts)),
|
|
369
505
|
};
|
|
370
506
|
},
|
|
371
507
|
services: options.services ?? (() => ({ kind: 'table', routes: {} })),
|
|
@@ -374,7 +510,14 @@ export function defineKitApp(options: DefineKitAppOptions = {}): KitApp {
|
|
|
374
510
|
...(options.identity !== undefined ? { identity: options.identity } : {}),
|
|
375
511
|
...(options.defaultAccess !== undefined ? { defaultAccess: options.defaultAccess } : {}),
|
|
376
512
|
...(options.pageGrants !== undefined ? { pageGrants: options.pageGrants } : {}),
|
|
377
|
-
|
|
513
|
+
// 请求钩子:先接运行期主题端点(浏览器切换主题取新令牌 CSS),其余交应用自己的钩子
|
|
514
|
+
requestHook() {
|
|
515
|
+
const own = options.requestHook?.();
|
|
516
|
+
return async (request, context) => {
|
|
517
|
+
if (isKitThemePath(request.url)) return (await server()).themeResponse(request);
|
|
518
|
+
return own?.(request, context);
|
|
519
|
+
};
|
|
520
|
+
},
|
|
378
521
|
...(options.startup !== undefined ? { startup: options.startup } : {}),
|
|
379
522
|
...(options.responseHeaders !== undefined ? { responseHeaders: options.responseHeaders } : {}),
|
|
380
523
|
async prewarm() {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// defineKitView:声明一个页面的展示对象(View Object,亦称渲染对象)——三层分工里承载交互逻辑的那一层。
|
|
2
|
+
//
|
|
3
|
+
// 业务对象 真实业务逻辑(接口 / 具名动作) 页面里不写
|
|
4
|
+
// 展示对象 交互逻辑:显隐、禁用、必填、联动、动作可否执行 本函数声明;与页面 1:1,就是 core 的 Domain 页面类
|
|
5
|
+
// 视觉页面 纯视觉翻译 + 纯路径绑定 *.kit.yaml 只写 view.<成员> 路径与方法名
|
|
6
|
+
//
|
|
7
|
+
// 本函数是 core `defineSomaView` 的薄封装,只加 kit 的类名规则(KIT-VIEW-005)。
|
|
8
|
+
// 登记:defineKitApp({ views: [RefG3View] })(或 { views: { RefG3View } });页面:`page.view: RefG3View`。约定文件放 pages/<页面名>.view.ts。
|
|
9
|
+
//
|
|
10
|
+
// 展示对象是应用对象,属于最上层:可调业务对象(ctx.action / ctx.http)、改下层对象(ctx.form(对象).set、候选项成员)、
|
|
11
|
+
// 在下层注册事件(ctx.form(对象).onChange / onField、ctx.onRequestDone、ctx.component(id).on)、托管计时(ctx.every / after / debounce);
|
|
12
|
+
// 它的成员值对页面只读(页面只写 view.<成员> 纯路径)。能力清单见 knowledge/SOMA领域建模与组件编写准则.md §1.0 与 kit 接入指南 §5.3。
|
|
13
|
+
//
|
|
14
|
+
// export const RefG3View = defineKitView({
|
|
15
|
+
// name: 'RefG3View',
|
|
16
|
+
// state: { remarkHidden: true, provinceOptions: [] as Array<{ value: string; label: string }> }, // 页面 view.<成员> 能绑定的就是这些
|
|
17
|
+
// methods: {
|
|
18
|
+
// // view 上的数组成员是只读类型(view.rows.push / view.rows[3].x = … 在 tsc 下报错,check 报 KIT-VIEW-008):数组整体替换引用
|
|
19
|
+
// onDraft(view, { values }) { view.remarkHidden = values.kind !== 'other'; }, // 页面 view.form.onDraft: onDraft
|
|
20
|
+
// },
|
|
21
|
+
// onMount(view, ctx) { // 挂载后注册下层事件 / 定时器,卸载自动撤销
|
|
22
|
+
// const form = ctx.form('target');
|
|
23
|
+
// form.onField('country', () => { form.set('province', ''); }); // 级联清空下级
|
|
24
|
+
// ctx.every(3000, () => ctx.reload(['entity'])); // 轮询
|
|
25
|
+
// },
|
|
26
|
+
// });
|
|
27
|
+
|
|
28
|
+
import { defineSomaView, SomaViewDefineError } from 'soma-core/base';
|
|
29
|
+
import { readKitViewInfo } from '../shared/view-info';
|
|
30
|
+
export { readKitViewInfo };
|
|
31
|
+
import type { SomaPageRootBase, SomaState, SomaViewContext } from 'soma-core/base';
|
|
32
|
+
import { extendKitViewContext, type KitViewContext } from './kit-view-context';
|
|
33
|
+
import { findSharedStateReferences, type ViewStateShape } from 'soma-foundation/view-state';
|
|
34
|
+
import { kitFail } from '../compile/kit-error';
|
|
35
|
+
import { isViewName } from '../object-renderer/view-binding';
|
|
36
|
+
|
|
37
|
+
/** 表单草稿钩子(`view.form.onDraft`)等展示对象方法的标准载荷类型 */
|
|
38
|
+
export interface KitDraftPayload<V extends Record<string, unknown> = Record<string, unknown>> {
|
|
39
|
+
readonly values: V;
|
|
40
|
+
readonly dirty: boolean;
|
|
41
|
+
readonly field?: string;
|
|
42
|
+
/** input = 用户输入;api = 展示对象写入;load = 草稿重建 / 详情到达;suggestion = 画布上一条 AI 建议被采纳 / 忽略(见 `suggestion`) */
|
|
43
|
+
readonly source?: 'input' | 'api' | 'load' | 'suggestion';
|
|
44
|
+
/** 画布(FlowEditor)AI 建议被处理:action = accept(建议已并入 values)/ reject(忽略);展示对象据此清掉自己持有的那条建议 */
|
|
45
|
+
readonly suggestion?: { readonly id: string; readonly action: 'accept' | 'reject' };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface KitViewDefinition<
|
|
49
|
+
S extends Record<string, unknown>,
|
|
50
|
+
// 方法载荷:草稿钩子(view.form.onDraft)是 KitDraftPayload,动作绑定(submit: view.<方法>)是 { row, … } 等事件载荷;各方法自己标注参数类型
|
|
51
|
+
P = any,
|
|
52
|
+
> {
|
|
53
|
+
/** 类名:以 View 结尾,页面 `page.view` 写同一个名字 */
|
|
54
|
+
readonly name: string;
|
|
55
|
+
/** 页面 `view.<成员>` 能绑定的成员与初值(JSON 值) */
|
|
56
|
+
readonly state: S;
|
|
57
|
+
/** 方法:`(view, payload, ctx)`;`view` 改成员即被动刷新页面,`ctx` 是能力上下文(调业务对象、改下层对象、在下层注册事件、托管计时) */
|
|
58
|
+
readonly methods?: Record<
|
|
59
|
+
string,
|
|
60
|
+
{ bivarianceHack(view: SomaPageRootBase & SomaState<S>, payload: P, ctx: KitViewContext): unknown }['bivarianceHack']
|
|
61
|
+
>;
|
|
62
|
+
/** 页面挂载后调用一次:用 ctx 注册事件订阅 / 定时器(随卸载自动撤销) */
|
|
63
|
+
readonly onMount?: (view: SomaPageRootBase & SomaState<S>, ctx: KitViewContext) => void | Promise<void>;
|
|
64
|
+
/** 页面卸载时调用(先于自动撤销) */
|
|
65
|
+
readonly onUnmount?: (view: SomaPageRootBase & SomaState<S>, ctx: KitViewContext) => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** defineKitView 的返回值:展示对象的页面根类(继承 core 的 SomaPageRootBase) */
|
|
69
|
+
export type KitViewClass = (new () => SomaPageRootBase) & { readonly viewName: string };
|
|
70
|
+
|
|
71
|
+
export function defineKitView<
|
|
72
|
+
S extends Record<string, unknown>,
|
|
73
|
+
>(definition: KitViewDefinition<S>): (new () => SomaPageRootBase & SomaState<S>) & { readonly viewName: string } {
|
|
74
|
+
if (!isViewName(definition?.name)) {
|
|
75
|
+
kitFail('KIT-VIEW-005', `defineKitView.${String(definition?.name)}`, `展示对象类名 ${JSON.stringify(definition?.name)} 不合法(大写字母开头、以 View 结尾,如 RefG3View)`, '把 name 改成 PascalCase 并以 View 结尾,和页面 page.view 写同一个名字');
|
|
76
|
+
}
|
|
77
|
+
// data 对象扫描编译:state 初值里两处引用同一对象(同一对象挂多路径,刷新会错位)
|
|
78
|
+
const shared = findSharedStateReferences(definition.state ?? {});
|
|
79
|
+
if (shared.length > 0) {
|
|
80
|
+
kitFail('KIT-VIEW-009', `defineKitView.${definition.name}`, `state 初值里 ${shared[0]!.first} 与 ${shared[0]!.second} 引用同一个对象(同一对象不能挂在两个路径下)`, '各成员写各自的字面量,或用 { ...共享值 } 浅拷贝;数组同理用 [...共享值]');
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
// 方法与生命周期钩子拿到的是 core ctx,这里统一扩成 kit ctx(多出 form / onRequestDone)
|
|
84
|
+
const wrapped: Record<string, (view: SomaPageRootBase & SomaState<S>, payload: any, ctx: SomaViewContext) => unknown> = {};
|
|
85
|
+
for (const [key, fn] of Object.entries(definition.methods ?? {})) {
|
|
86
|
+
wrapped[key] = (view, payload, ctx) => fn(view, payload, extendKitViewContext(ctx, definition.name));
|
|
87
|
+
}
|
|
88
|
+
const { onMount, onUnmount } = definition;
|
|
89
|
+
return defineSomaView({
|
|
90
|
+
name: definition.name,
|
|
91
|
+
state: definition.state,
|
|
92
|
+
methods: wrapped,
|
|
93
|
+
...(onMount !== undefined ? { onMount: (view: SomaPageRootBase & SomaState<S>, ctx: SomaViewContext) => onMount(view, extendKitViewContext(ctx, definition.name)) } : {}),
|
|
94
|
+
...(onUnmount !== undefined ? { onUnmount: (view: SomaPageRootBase & SomaState<S>, ctx: SomaViewContext) => onUnmount(view, extendKitViewContext(ctx, definition.name)) } : {}),
|
|
95
|
+
}) as unknown as (new () => SomaPageRootBase & SomaState<S>) & { readonly viewName: string };
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof SomaViewDefineError) {
|
|
98
|
+
kitFail('KIT-VIEW-005', `defineKitView.${definition.name}`, error.message, '成员 / 方法名不得与页面根成员重名(data / params / query / pageLoading …),不得以 _ 开头,初值须是 JSON 值');
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// 开发态编译降级页的标记属性:编译失败时 dev 服务回一张诊断页(根元素带本属性),页面其余内容不挂载。
|
|
2
|
+
// 单一来源:kit 的 server.ts 写它;渲染观测的守卫(scripts/lib/aesthetic-kit-driver.mjs)经 Node 类型剥离直接读本文件,不抄字符串。
|
|
3
|
+
// 只放可被类型剥离的写法(常量与 as const),不要在本文件加 import 或枚举。
|
|
4
|
+
export const KIT_DEV_DIAGNOSTIC_ATTR = 'data-kit-dev-diagnostic' as const;
|
|
5
|
+
export const KIT_DEV_DIAGNOSTIC_VALUE = 'true' as const;
|