soma-kit 0.1.13 → 0.1.15
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/package.json +3 -3
- package/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- package/spec/generated/kit-app.schema.json +18 -2
- package/spec/generated/kit-page.schema.json +95 -0
- package/spec/kit-grammar.json +332 -75
- package/spec/kit-grammar.schema.json +1 -27
- package/src/app/app-config.ts +11 -5
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +82 -10
- package/src/app/define-kit-app.ts +6 -5
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +20 -8
- package/src/app/kit-view-context.ts +30 -4
- package/src/app/server-pages.ts +5 -1
- package/src/app/server.ts +15 -5
- package/src/app/theme-endpoint.ts +1 -1
- package/src/app/theme-runtime.ts +7 -2
- package/src/base/alert.ts +23 -20
- package/src/base/anchored-layer.ts +1 -1
- package/src/base/button.ts +34 -17
- package/src/base/cascader.ts +8 -4
- package/src/base/check-core.ts +9 -6
- package/src/base/color-picker.ts +10 -6
- package/src/base/command-palette.ts +10 -4
- package/src/base/context-menu.ts +5 -2
- package/src/base/date-range.ts +9 -6
- package/src/base/date.ts +10 -6
- package/src/base/delta.ts +4 -2
- package/src/base/divider.ts +15 -66
- package/src/base/end-edge.ts +14 -2
- package/src/base/fab.ts +11 -6
- package/src/base/gap-value.ts +25 -5
- package/src/base/hint-tips.ts +1 -1
- package/src/base/illustrations.ts +2 -1
- package/src/base/index.ts +20 -4
- package/src/base/inline-error.ts +84 -0
- package/src/base/input.ts +54 -18
- package/src/base/kbd.ts +4 -3
- package/src/base/link.ts +1 -1
- package/src/base/listbox-core.ts +70 -22
- package/src/base/mentions.ts +6 -3
- package/src/base/menu-button.ts +73 -50
- package/src/base/menu-core.ts +9 -2
- package/src/base/motion/hover-3d.ts +4 -1
- package/src/base/motion/hover-gallery.ts +4 -1
- package/src/base/otp.ts +7 -3
- package/src/base/overlay-runtime.ts +3 -2
- package/src/base/overlay-shell.ts +141 -0
- package/src/base/popover.ts +7 -6
- package/src/base/popup.ts +47 -41
- package/src/base/qty-stepper.ts +14 -9
- package/src/base/reason-tip.ts +2 -2
- package/src/{frames → base}/resize-handle.ts +1 -1
- package/src/base/segmented.ts +44 -35
- package/src/base/select.ts +1 -0
- package/src/base/shared.ts +52 -18
- package/src/base/state-panel.ts +34 -13
- package/src/base/status-tone.ts +1 -1
- package/src/base/tag-input.ts +13 -8
- package/src/base/tag.ts +56 -57
- package/src/base/text.ts +38 -14
- package/src/base/textarea.ts +1 -1
- package/src/base/time-picker.ts +9 -5
- package/src/base/tree-select.ts +12 -9
- package/src/base/upload.ts +26 -17
- package/src/biz/approval-desk/compile.ts +28 -1
- package/src/biz/approval-desk/shell.ts +10 -9
- package/src/biz/auth-panel/compile.ts +1 -1
- package/src/biz/auth-panel/shell.ts +7 -6
- package/src/biz/category-crud/compile.ts +20 -6
- package/src/biz/category-crud/shell.ts +10 -7
- package/src/biz/checkout-page/compile.ts +1 -1
- package/src/biz/checkout-page/shell.ts +15 -13
- package/src/biz/compose.ts +5 -5
- package/src/biz/data-components.ts +4 -0
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +1 -1
- package/src/biz/import-wizard/shell.ts +17 -13
- package/src/biz/index.ts +4 -3
- package/src/biz/landing-page/compile.ts +1 -1
- package/src/biz/landing-page/shell.ts +6 -5
- package/src/biz/link/shared.ts +8 -1
- package/src/biz/master-sub/compile.ts +269 -27
- package/src/biz/master-sub/detail-head.ts +62 -0
- package/src/biz/master-sub/index.ts +5 -4
- package/src/biz/master-sub/shell.ts +138 -69
- package/src/biz/multi-board/compile.ts +166 -11
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +25 -10
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +96 -24
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +9 -2
- package/src/biz/notification-center/shell.ts +15 -7
- package/src/biz/page-templates/domain-templates.ts +7 -3
- package/src/biz/page-templates/result-page/compile.ts +1 -1
- package/src/biz/page-templates/result-page/shell.ts +5 -4
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +18 -18
- package/src/biz/record-detail/compile.ts +5 -2
- package/src/biz/record-detail/shell.ts +12 -11
- package/src/biz/settings-center/compile.ts +1 -1
- package/src/biz/settings-center/shell.ts +14 -10
- package/src/biz/shared/action-host.ts +12 -5
- package/src/biz/shared/compile-helpers.ts +83 -4
- package/src/biz/shared/coordinator.ts +104 -21
- package/src/biz/shared/overlay-compile.ts +76 -4
- package/src/biz/shared/overlay-shell.ts +65 -112
- package/src/biz/single-form/compile.ts +2 -2
- package/src/biz/single-form/shell.ts +13 -7
- package/src/biz/standard-crud/compile.ts +24 -4
- package/src/biz/standard-crud/shell.ts +38 -30
- package/src/biz/standard-crud/summary.ts +42 -0
- package/src/biz/step-form/compile.ts +1 -1
- package/src/biz/step-form/hub.ts +4 -0
- package/src/biz/step-form/shell.ts +16 -12
- package/src/biz/types.ts +15 -3
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +35 -8
- package/src/cli/kit-init.ts +149 -0
- package/src/cli/layout-cli.ts +7 -7
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/compile-page.ts +36 -230
- package/src/compile/component-candidates.ts +4 -1
- package/src/compile/hints.ts +5 -58
- package/src/compile/index.ts +2 -2
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +97 -18
- package/src/compile/layout-lint/rules-form.ts +6 -7
- package/src/compile/layout-lint/rules-table.ts +98 -14
- package/src/compile/page-composition.ts +191 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/redirect.ts +1 -1
- package/src/compile/stages.ts +169 -0
- package/src/compile/styles.ts +80 -32
- package/src/compile/types.ts +5 -3
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +6 -2
- package/src/data/anchor-nav.ts +4 -1
- package/src/data/approval-flow.ts +13 -5
- package/src/data/assignment-picker.ts +35 -20
- package/src/data/async-result-panel.ts +7 -3
- package/src/data/breadcrumbs.ts +13 -9
- package/src/data/calendar.ts +10 -4
- package/src/data/carousel.ts +13 -5
- package/src/data/chart.ts +745 -48
- package/src/data/checklist.ts +9 -5
- package/src/data/code-view.ts +220 -26
- package/src/data/comment-thread.ts +9 -3
- package/src/data/confirm-dialog.ts +57 -20
- package/src/data/diff.ts +4 -1
- package/src/data/dock.ts +5 -1
- package/src/data/embed.ts +1 -1
- package/src/data/engine-ports.ts +126 -0
- package/src/data/field-mapper.ts +16 -7
- package/src/data/flow-editor.ts +106 -29
- package/src/data/footer.ts +8 -2
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +8 -2
- package/src/data/image-viewer.ts +7 -3
- package/src/data/index.ts +22 -8
- package/src/data/item-list.ts +11 -3
- package/src/data/json-view.ts +844 -0
- package/src/data/kanban.ts +13 -8
- package/src/data/markdown-view.ts +487 -0
- package/src/data/matrix.ts +400 -0
- package/src/data/media-grid.ts +5 -2
- package/src/data/mega-menu.ts +4 -3
- package/src/data/menu-dom.ts +9 -8
- package/src/data/menu.ts +35 -17
- package/src/data/mockup.ts +12 -8
- package/src/data/modal-dialog.ts +108 -57
- package/src/data/navbar.ts +13 -7
- package/src/data/notice-list.ts +53 -20
- package/src/data/notify-renderer.ts +21 -10
- package/src/data/object-form.ts +248 -151
- package/src/data/pager.ts +15 -10
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +19 -9
- package/src/data/permission-tree.ts +30 -13
- package/src/data/pricing-table.ts +10 -4
- package/src/data/reaction-bar.ts +6 -3
- package/src/data/record-card.ts +30 -14
- package/src/data/record-picker.ts +8 -4
- package/src/data/redirect.ts +1 -1
- package/src/data/request-console.ts +20 -7
- package/src/data/resident.ts +6 -10
- package/src/data/result-panel.ts +2 -2
- package/src/data/rich-text.ts +58 -96
- package/src/data/row-editor.ts +12 -7
- package/src/data/rule-builder.ts +22 -11
- package/src/data/shape-util.ts +26 -14
- package/src/data/stat-group.ts +369 -84
- package/src/data/static-lazy.ts +7 -0
- package/src/data/static-registry.ts +14 -2
- package/src/data/steps.ts +6 -2
- package/src/data/survey.ts +13 -4
- package/src/data/system-switcher.ts +17 -7
- package/src/data/text-diff.ts +663 -0
- package/src/data/timeline.ts +1 -1
- package/src/data/tour-guide.ts +8 -4
- package/src/data/transfer.ts +24 -11
- package/src/data/tree-table.ts +84 -17
- package/src/data/tree.ts +6 -3
- package/src/data/virtual-rows.ts +22 -11
- package/src/data/wrap.ts +2 -2
- package/src/data/wrapped-candidates.ts +22 -1
- package/src/frames/index.ts +4 -2
- package/src/frames/inherited-shell.ts +178 -0
- package/src/frames/list-summary.ts +123 -0
- package/src/frames/page-bar.ts +10 -16
- package/src/frames/resident-components.ts +20 -0
- package/src/frames/shared.ts +37 -17
- package/src/frames/split-frame/shell.ts +17 -11
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +17 -9
- package/src/frames/top-main-frame.ts +1 -1
- package/src/frames/types.ts +6 -3
- package/src/frames/workspace-frame/extras.ts +19 -5
- package/src/frames/workspace-frame/shell.ts +4 -3
- package/src/frames/workspace-frame/state.ts +8 -2
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +156 -91
- package/src/generated/kit-grammar-runtime.ts +227 -58
- package/src/i18n/kit-text.ts +141 -2
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +169 -0
- package/src/object-renderer/action-more.ts +160 -0
- package/src/object-renderer/arrange.ts +86 -26
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +72 -20
- package/src/object-renderer/collection-table.ts +178 -65
- package/src/object-renderer/collection.ts +129 -83
- package/src/object-renderer/compile-data.ts +1 -1
- package/src/object-renderer/defaults.ts +10 -5
- package/src/object-renderer/emit-events.ts +1 -1
- package/src/object-renderer/emit-object.ts +7 -0
- package/src/object-renderer/emit-static.ts +243 -87
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/filter-toolbar.ts +103 -0
- package/src/{compile → object-renderer}/fragment.ts +13 -2
- package/src/object-renderer/index.ts +6 -1
- package/src/object-renderer/layout-facts.ts +46 -6
- package/src/object-renderer/layout-plan.ts +136 -43
- package/src/object-renderer/layout-plan.types.ts +42 -5
- package/src/object-renderer/overlay-decide.ts +82 -0
- package/src/object-renderer/parts.ts +7 -259
- package/src/object-renderer/render-object.ts +60 -47
- package/src/object-renderer/table-actions.ts +135 -56
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +63 -25
- package/src/object-renderer/types.ts +16 -22
- package/src/recipes/app-blocks.ts +66 -0
- package/src/recipes/code-view.ts +56 -0
- package/src/recipes/compact-group.ts +31 -0
- package/src/recipes/container.ts +54 -13
- package/src/recipes/control.ts +77 -157
- package/src/recipes/desc-list.ts +14 -0
- package/src/recipes/divider.ts +53 -0
- package/src/recipes/emphasis.ts +60 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +34 -1
- package/src/recipes/inherited-shell.ts +37 -0
- package/src/recipes/json-view.ts +49 -0
- package/src/recipes/markdown.ts +86 -0
- package/src/recipes/overlay.ts +149 -18
- package/src/recipes/page-width.ts +20 -0
- package/src/recipes/placeholder.ts +21 -5
- package/src/recipes/rail-grid.ts +3 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +20 -28
- package/src/recipes/status.ts +17 -8
- package/src/recipes/strip.ts +72 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +10 -6
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +120 -11
- package/src/recipes/tabs.ts +126 -0
- package/src/recipes/text-diff.ts +90 -0
- package/src/recipes/title-row.ts +7 -5
- package/src/recipes/typography.ts +24 -43
- package/src/shared/diagnostics.ts +16 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-value-format.ts +246 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +12 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- package/src/shared/path-guard.ts +1 -1
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/theme-runtime-shared.ts +19 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +49 -14
- package/src/theme/kit-theme.tpl +49 -14
- package/src/theme/nine-dim-structure.ts +129 -37
- package/src/theme/surface-layers.ts +17 -4
- package/src/theme/theme-tokens.ts +16 -5
- package/src/theme/typography.ts +21 -17
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- /package/src/{base → shared}/class-candidates.ts +0 -0
|
@@ -17,7 +17,7 @@ import { KIT_VIEW_FORM_KEYS, KIT_VIEW_SLOTS } from '../../object-renderer/defaul
|
|
|
17
17
|
import { emitObject } from '../../object-renderer/emit-object';
|
|
18
18
|
import { viewAnchor } from '../../object-renderer/emit-static';
|
|
19
19
|
import type { KitDiagnostic, KitFieldSchema, KitObject, KitViewForm } from '../../object-renderer/types';
|
|
20
|
-
import type { KitFragment } from '../../
|
|
20
|
+
import type { KitFragment } from '../../object-renderer/fragment';
|
|
21
21
|
import type { KitBizContext, KitBizInput } from '../types';
|
|
22
22
|
import { kitText } from '../../i18n/kit-text';
|
|
23
23
|
import {
|
package/src/biz/step-form/hub.ts
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
import type { SomaComponentDefinition, SomaDataPort, SomaRegionPort } from 'soma-core';
|
|
29
29
|
import { createKitController } from '../../base/shared';
|
|
30
30
|
import { kitText } from '../../i18n/kit-text';
|
|
31
|
+
import { clearKitInlineError, showKitInlineError } from '../../base/inline-error';
|
|
31
32
|
import { askKitConfirm } from '../../data/confirm-dialog';
|
|
32
33
|
|
|
33
34
|
/** 语义事件名(SCOPE | semantic 要求小写 snake_case) */
|
|
@@ -217,6 +218,8 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
217
218
|
};
|
|
218
219
|
const toast = (level: string, message: string): void => {
|
|
219
220
|
const svc = (api.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
|
|
221
|
+
// 错误不用轻提示(KT-K-feedback-3,§6.1 G-17):danger 进就地提示条(窗口内进窗口槽,页面级进页头下),无槽才回退轻提示
|
|
222
|
+
if (level === 'danger' && message !== '' && showKitInlineError(api.host ?? null, message, 'step-form')) return;
|
|
220
223
|
if (svc && typeof svc.toast === 'function') svc.toast({ level, message });
|
|
221
224
|
};
|
|
222
225
|
|
|
@@ -232,6 +235,7 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
232
235
|
// 提交期间用户点了「重新开始」(seq 已变):过期的结果不再写回,免得把新一轮表单置成完成态
|
|
233
236
|
if (cur.seq !== focus.seq) return;
|
|
234
237
|
if (result.ok) {
|
|
238
|
+
clearKitInlineError(api.host ?? null, 'step-form');
|
|
235
239
|
slice.set({ ...stepFocus(cur.step, cur.total, true, cur.values, cur.seq + 1) });
|
|
236
240
|
api.emit('saved', { result: result.data ?? {} });
|
|
237
241
|
return;
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
// 只有结构与 Tailwind 类(语义色名 + utilityScales 里有的尺度),不写原生 CSS。
|
|
3
3
|
// 显隐规则:面板 / 步骤条变体都是「外层只放 core 写的 hidden、内层放布局类」两层;各步表单一直挂着,只靠外层显隐切换。
|
|
4
4
|
|
|
5
|
-
import { mergeClass } from '../../
|
|
5
|
+
import { mergeClass } from '../../shared/merge-class';
|
|
6
6
|
import { kitShellRecipe } from '../../recipes/container';
|
|
7
|
+
import { KIT_DIVIDER_FOOT_CLASS } from '../../recipes/divider';
|
|
8
|
+
import { KIT_PAGE_FORM_WIDTH_CLASS } from '../../recipes/page-width';
|
|
9
|
+
import { kitTypographyRecipe } from '../../recipes/typography';
|
|
7
10
|
import { cls, esc, host } from '../link/shared';
|
|
8
|
-
import { kitIconHtml } from '../../
|
|
11
|
+
import { kitIconHtml } from '../../shared/icons';
|
|
9
12
|
|
|
10
13
|
/** 壳的内部区域名(`areaClass` 的合法键) */
|
|
11
14
|
export const STEP_FORM_AREAS = ['root', 'card', 'steps', 'panel', 'done'] as const;
|
|
@@ -13,10 +16,10 @@ export type StepFormArea = (typeof STEP_FORM_AREAS)[number];
|
|
|
13
16
|
|
|
14
17
|
export const STEP_FORM_CLASS = {
|
|
15
18
|
root: '@container flex justify-center',
|
|
16
|
-
card: mergeClass(
|
|
17
|
-
title: '
|
|
18
|
-
steps: 'flex flex-wrap items-center gap-
|
|
19
|
-
stepItem: 'flex items-center gap-
|
|
19
|
+
card: mergeClass(`flex w-full ${KIT_PAGE_FORM_WIDTH_CLASS} flex-col gap-stack p-inset-roomy`, kitShellRecipe()),
|
|
20
|
+
title: kitTypographyRecipe('sectionTitle'),
|
|
21
|
+
steps: 'flex flex-wrap items-center gap-cluster',
|
|
22
|
+
stepItem: 'flex items-center gap-cluster',
|
|
20
23
|
circle: 'flex h-6 w-6 items-center justify-center rounded-full text-sm font-medium',
|
|
21
24
|
circleAt: 'bg-primary text-primary-fg',
|
|
22
25
|
circlePast: 'bg-success text-success-fg',
|
|
@@ -24,11 +27,11 @@ export const STEP_FORM_CLASS = {
|
|
|
24
27
|
labelAt: 'text-sm font-semibold text-fg',
|
|
25
28
|
labelPast: 'text-sm text-fg',
|
|
26
29
|
labelFut: 'text-sm text-fg-muted',
|
|
27
|
-
joint:
|
|
28
|
-
panel: 'flex flex-col gap-
|
|
29
|
-
panelTitle: '
|
|
30
|
-
done: 'flex flex-col items-start gap-
|
|
31
|
-
doneTitle: '
|
|
30
|
+
joint: `w-6 ${KIT_DIVIDER_FOOT_CLASS}`,
|
|
31
|
+
panel: 'flex flex-col gap-region',
|
|
32
|
+
panelTitle: kitTypographyRecipe('sectionTitle'),
|
|
33
|
+
done: 'flex flex-col items-start gap-region',
|
|
34
|
+
doneTitle: kitTypographyRecipe('sectionTitle'),
|
|
32
35
|
} as const;
|
|
33
36
|
|
|
34
37
|
export interface StepFormIds {
|
|
@@ -90,7 +93,8 @@ export function stepFormHtml(
|
|
|
90
93
|
const done = `<div data-soma-id="${esc(ids.done)}"><div${cls(mergeClass(C.done, areaClass.done))}>`
|
|
91
94
|
+ `<h3${cls(C.doneTitle)}>${esc(parts.doneTitle)}</h3>${host('Button', ids.restart)}</div></div>`;
|
|
92
95
|
const title = parts.title === '' ? '' : `<h2${cls(C.title)}>${esc(parts.title)}</h2>`;
|
|
93
|
-
|
|
96
|
+
// 唯一主体 = 页面(C2):表单卡是 E1 主体
|
|
97
|
+
const card = `<section data-kit-emphasis="primary" data-kit-role="subject" data-kit-container="card"${cls(mergeClass(C.card, areaClass.card))}>${title}${bar}${panels.join('')}${done}</section>`;
|
|
94
98
|
const root = mergeClass(mergeClass(C.root, areaClass.root), extra);
|
|
95
99
|
return `<div data-soma-id="${esc(ids.root)}"${cls(root)}>\n${host('KitStepHub', ids.hub)}\n${card}\n</div>`;
|
|
96
100
|
}
|
package/src/biz/types.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 得到一个 KitFragment(HTML + `_ui.yaml` 片段 + `_event.yaml` 片段 + 候选类 + 诊断),再交页面框装入。
|
|
6
6
|
|
|
7
7
|
import type { KitObject } from '../object-renderer/types';
|
|
8
|
-
import type { KitFragment } from '../
|
|
8
|
+
import type { KitFragment } from '../object-renderer/fragment';
|
|
9
9
|
|
|
10
10
|
/** 附加浮层声明(StandardCrud 的 `overlays.*`):一个附加关联对象 + 浮层壳的种类与标题。 */
|
|
11
11
|
export interface KitOverlayDecl {
|
|
@@ -15,12 +15,17 @@ export interface KitOverlayDecl {
|
|
|
15
15
|
*/
|
|
16
16
|
kind: 'dialog' | 'drawer' | 'expand';
|
|
17
17
|
title?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 已退出的手写口:窗口宽度由内容推导(单列 480、两列或宽组件 640、三列或画布 800;只读抽屉 480 / 640),写了报 KIT-OVL-003。
|
|
20
|
+
* 抽屉只用于只读详情,带提交动作的浮层必须是 dialog(KIT-OVL-001),只读内容用 dialog 报 KIT-OVL-002
|
|
21
|
+
*/
|
|
22
|
+
width?: 'narrow' | 'default' | 'wide' | 'xwide';
|
|
18
23
|
/**
|
|
19
24
|
* 浮层里写死形状数据组件的事件映射(K-1):{ 组件抛出的事件名: 'saved' | 'close' | 'reload' }。
|
|
20
25
|
* 约定名 saved / cancel / close / reload 不用写,编译器自动接线;这里只补自定义事件名。
|
|
21
26
|
*/
|
|
22
27
|
events?: Record<string, string | KitOverlayEventAction>;
|
|
23
|
-
/**
|
|
28
|
+
/** 已退出的手写口:窗口外观由框架决定,写了报 KIT-OVL-003 */
|
|
24
29
|
class?: string;
|
|
25
30
|
/**
|
|
26
31
|
* 只读浮层(view 是 summary)的「编辑」去向:另一个浮层名(view 是 form,kind 可与本浮层不同,如只读抽屉切到编辑弹窗)。
|
|
@@ -65,9 +70,11 @@ export interface KitBizContext {
|
|
|
65
70
|
/** 已登记的基础组件名(内置 13 个 + App*) */
|
|
66
71
|
registeredComponents: ReadonlySet<string>;
|
|
67
72
|
/** 已登记的写死形状数据组件 */
|
|
68
|
-
staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[]; propTypes?: Readonly<Record<string, string
|
|
73
|
+
staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[]; propTypes?: Readonly<Record<string, string>>; composition?: 'summary' | 'subject' | 'control' | 'note' }>;
|
|
69
74
|
/** 页面语言(`page.locale`,缺省应用 defaultLocale;未声明为空串):业务组件写进产物的内置文案按它取(`kitText(key, params, ctx.locale)`) */
|
|
70
75
|
locale?: string;
|
|
76
|
+
/** 告警通道(不挡编译、随编译结果的 deprecations 带出):过渡期的新规则先以告警落地,应用改完再升为错误 */
|
|
77
|
+
advise?: (a: { code: string; path: string; message: string; hint: string }) => void;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
export interface KitBizRole {
|
|
@@ -93,5 +100,10 @@ export interface KitBizDefinition {
|
|
|
93
100
|
* 与 acceptConfig 不同,它不让 AI 目标把该组件排除在映射外——这些键在 aiWriter 里仍是 human-only。
|
|
94
101
|
*/
|
|
95
102
|
configKeys?: readonly string[];
|
|
103
|
+
/**
|
|
104
|
+
* 页面模式推导的版心(尺寸规格 §3:阅读型 800、单对象表单 720;值是 pageHeader.maxWidths 的档名):页面没写 page.max_width 时由编译期的尺寸决定(stages.planSize)采用,
|
|
105
|
+
* 先于应用级 app.layout 默认;列表 / 看板 / 主从等不限宽的模式不写。
|
|
106
|
+
*/
|
|
107
|
+
pageMaxWidth?: string;
|
|
96
108
|
compile(input: KitBizInput, ctx: KitBizContext): KitFragment;
|
|
97
109
|
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// 应用代码双平面与四层分层边界检查(`soma kit check` -> KIT-APP-015,对齐《代码四层分层规范》§5 R-APP-1/2/3):
|
|
2
|
+
// 1. R-APP-1 双面物理隔离:
|
|
3
|
+
// - 客户端面(web/、soma.app.*、views/、actions/、components/、lib/)严禁引用服务端面(bff/、api/、server/、config/、soma.server.*)
|
|
4
|
+
// - 服务端面(bff/、api/、server/)严禁反向引用客户端面(web/、soma.app.*、views/、actions/、components/)
|
|
5
|
+
// - 契约共享面(shared/)严禁引用 web/、bff/、api/、server/、config/、soma.server.* 或 Node.js 内置模块(node:* 等)
|
|
6
|
+
// - soma.server.* 作为服务端动态入口,允许桥接同应用的 soma.app.* 与服务端面,但不得被客户端面反向引用
|
|
7
|
+
// 2. R-APP-2 BFF 四层单向依赖:
|
|
8
|
+
// - foundation/ 严禁反向引用 domain/、application/、api/
|
|
9
|
+
// - domain/(当同级存在 application/ 或 foundation/ 四层目录时)严禁反向引用 application/、api/
|
|
10
|
+
// 3. R-APP-3 页面视图横向隔离:
|
|
11
|
+
// - views/*.view.* 严禁横向直接引用其它 views/*.view.*(跨页共享逻辑须下沉至 actions/、lib/ 或 shared/)
|
|
12
|
+
//
|
|
13
|
+
// 采用 TypeScript AST 解析所有静态 import / import type / export ... from / 动态 import() / require(),
|
|
14
|
+
// 天然忽略注释与普通字符串字面量;跳过 node_modules、tests/、test/、mock/、dist/、build/ 与隐藏目录。
|
|
15
|
+
|
|
16
|
+
import ts from 'typescript';
|
|
17
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
18
|
+
|
|
19
|
+
const SKIP_DIRS = new Set(['node_modules', 'tests', 'test', 'mock', 'mocks', 'dist', 'build', 'coverage', 'scripts', 'prisma']);
|
|
20
|
+
const SOURCE_EXTS = ['.ts', '.tsx', '.mts', '.mjs', '.js', '.jsx', '.cjs'];
|
|
21
|
+
const NODE_BUILTIN_RE =
|
|
22
|
+
/^(?:node:|(?:fs|path|http|https|http2|net|tls|dgram|dns|crypto|child_process|cluster|os|stream|zlib|worker_threads|v8|vm|readline|inspector|async_hooks|perf_hooks)(?:\/|$))/;
|
|
23
|
+
|
|
24
|
+
type Plane = 'web' | 'bff' | 'shared' | 'server-entry' | 'neutral';
|
|
25
|
+
type BffLayer = 'foundation' | 'domain' | 'application' | 'contract';
|
|
26
|
+
|
|
27
|
+
const LAYER_RANK: Readonly<Record<BffLayer, number>> = {
|
|
28
|
+
foundation: 0,
|
|
29
|
+
domain: 1,
|
|
30
|
+
application: 2,
|
|
31
|
+
contract: 3,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface SpecRef {
|
|
35
|
+
readonly spec: string;
|
|
36
|
+
readonly line: number;
|
|
37
|
+
readonly column: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface WorkspaceLayout {
|
|
41
|
+
readonly projectRoot: string;
|
|
42
|
+
readonly webRootRel: string | null;
|
|
43
|
+
readonly bffRootRel: string | null;
|
|
44
|
+
readonly hasFourLayerDomain: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const toPosix = (p: string): string => p.split('\\').join('/');
|
|
48
|
+
|
|
49
|
+
function extractModuleSpecifiers(sourceText: string, fileName: string): SpecRef[] {
|
|
50
|
+
const sf = ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.Latest, false);
|
|
51
|
+
const out: SpecRef[] = [];
|
|
52
|
+
const pushNode = (lit: ts.StringLiteralLike): void => {
|
|
53
|
+
const pos = sf.getLineAndCharacterOfPosition(lit.getStart(sf));
|
|
54
|
+
out.push({ spec: lit.text, line: pos.line + 1, column: pos.character + 1 });
|
|
55
|
+
};
|
|
56
|
+
const visit = (node: ts.Node): void => {
|
|
57
|
+
if (ts.isImportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
58
|
+
pushNode(node.moduleSpecifier);
|
|
59
|
+
} else if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
60
|
+
pushNode(node.moduleSpecifier);
|
|
61
|
+
} else if (
|
|
62
|
+
ts.isImportEqualsDeclaration(node) &&
|
|
63
|
+
ts.isExternalModuleReference(node.moduleReference) &&
|
|
64
|
+
ts.isStringLiteral(node.moduleReference.expression)
|
|
65
|
+
) {
|
|
66
|
+
pushNode(node.moduleReference.expression);
|
|
67
|
+
} else if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) {
|
|
68
|
+
pushNode(node.argument.literal);
|
|
69
|
+
} else if (ts.isCallExpression(node)) {
|
|
70
|
+
const expr = node.expression;
|
|
71
|
+
const isDynImport = expr.kind === ts.SyntaxKind.ImportKeyword;
|
|
72
|
+
const isRequire = ts.isIdentifier(expr) && expr.text === 'require';
|
|
73
|
+
if ((isDynImport || isRequire) && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0]!)) {
|
|
74
|
+
pushNode(node.arguments[0]!);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
ts.forEachChild(node, visit);
|
|
78
|
+
};
|
|
79
|
+
visit(sf);
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function resolveRelativeTarget(
|
|
84
|
+
fs: typeof import('node:fs'),
|
|
85
|
+
path: typeof import('node:path'),
|
|
86
|
+
fromFull: string,
|
|
87
|
+
spec: string,
|
|
88
|
+
): string | null {
|
|
89
|
+
const raw = path.resolve(path.dirname(fromFull), spec);
|
|
90
|
+
const candidates: string[] = [raw];
|
|
91
|
+
if (raw.endsWith('.js')) candidates.push(`${raw.slice(0, -3)}.ts`, `${raw.slice(0, -3)}.tsx`);
|
|
92
|
+
if (raw.endsWith('.mjs')) candidates.push(`${raw.slice(0, -4)}.mts`);
|
|
93
|
+
if (raw.endsWith('.cjs')) candidates.push(`${raw.slice(0, -4)}.cts`);
|
|
94
|
+
for (const ext of SOURCE_EXTS) candidates.push(`${raw}${ext}`);
|
|
95
|
+
for (const ext of SOURCE_EXTS) candidates.push(path.join(raw, `index${ext}`));
|
|
96
|
+
for (const c of candidates) {
|
|
97
|
+
try {
|
|
98
|
+
if (fs.statSync(c).isFile()) return c;
|
|
99
|
+
} catch {
|
|
100
|
+
// candidate absent
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isServerEntryFile(relPosix: string): boolean {
|
|
107
|
+
const base = relPosix.split('/').pop() ?? '';
|
|
108
|
+
return /^soma\.server\.[cm]?[jt]s$/.test(base);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function isClientEntryFile(relPosix: string): boolean {
|
|
112
|
+
const base = relPosix.split('/').pop() ?? '';
|
|
113
|
+
return /^soma\.app(?:\.standalone)?\.[cm]?[jt]s$/.test(base);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function isViewFile(relPosix: string): boolean {
|
|
117
|
+
const segs = relPosix.split('/');
|
|
118
|
+
const base = segs[segs.length - 1] ?? '';
|
|
119
|
+
return segs.includes('views') && /\.view\.[cm]?[jt]sx?$/.test(base);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function detectLayout(fs: typeof import('node:fs'), path: typeof import('node:path'), appDir: string): WorkspaceLayout {
|
|
123
|
+
const resolved = path.resolve(appDir);
|
|
124
|
+
const normRel = (root: string, sub: unknown): string | null => {
|
|
125
|
+
if (typeof sub !== 'string' || sub.trim() === '') return null;
|
|
126
|
+
const abs = path.resolve(root, sub.trim());
|
|
127
|
+
const rel = toPosix(path.relative(root, abs));
|
|
128
|
+
return rel === '' || rel.startsWith('..') ? null : rel;
|
|
129
|
+
};
|
|
130
|
+
const hasDir = (p: string): boolean => {
|
|
131
|
+
try {
|
|
132
|
+
return fs.statSync(p).isDirectory();
|
|
133
|
+
} catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
let projectRoot = resolved;
|
|
139
|
+
let webRootRel: string | null = null;
|
|
140
|
+
let bffRootRel: string | null = null;
|
|
141
|
+
|
|
142
|
+
// Walk up at most 2 levels so `soma kit check src/web` or `soma kit check src/kit` also sees projectRoot's package.json#soma
|
|
143
|
+
let probe = resolved;
|
|
144
|
+
for (let depth = 0; depth <= 2; depth++) {
|
|
145
|
+
const pkgFile = path.join(probe, 'package.json');
|
|
146
|
+
try {
|
|
147
|
+
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8')) as { soma?: { webRoot?: unknown; apiRoot?: unknown; serviceRoot?: unknown } };
|
|
148
|
+
const wr = normRel(probe, pkg.soma?.webRoot);
|
|
149
|
+
const ar = normRel(probe, pkg.soma?.apiRoot ?? pkg.soma?.serviceRoot);
|
|
150
|
+
if (wr !== null || ar !== null) {
|
|
151
|
+
if (probe === resolved || (wr !== null && path.resolve(probe, wr) === resolved)) {
|
|
152
|
+
projectRoot = probe;
|
|
153
|
+
webRootRel = wr;
|
|
154
|
+
bffRootRel = ar;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (probe === resolved) break;
|
|
159
|
+
} catch {
|
|
160
|
+
// no package.json at this level
|
|
161
|
+
}
|
|
162
|
+
const parent = path.dirname(probe);
|
|
163
|
+
if (parent === probe) break;
|
|
164
|
+
probe = parent;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (webRootRel === null && hasDir(path.join(projectRoot, 'src', 'web'))) webRootRel = 'src/web';
|
|
168
|
+
if (bffRootRel === null && hasDir(path.join(projectRoot, 'src', 'bff'))) bffRootRel = 'src/bff';
|
|
169
|
+
|
|
170
|
+
const checkFourLayerBase = bffRootRel !== null ? path.join(projectRoot, bffRootRel) : projectRoot;
|
|
171
|
+
const hasFourLayerDomain =
|
|
172
|
+
hasDir(path.join(checkFourLayerBase, 'application')) || hasDir(path.join(checkFourLayerBase, 'foundation'));
|
|
173
|
+
|
|
174
|
+
return { projectRoot, webRootRel, bffRootRel, hasFourLayerDomain };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function classifyPlane(relPosix: string, layout: WorkspaceLayout): Plane {
|
|
178
|
+
if (isServerEntryFile(relPosix)) return 'server-entry';
|
|
179
|
+
if (relPosix.startsWith('src/shared/') || relPosix.startsWith('shared/')) return 'shared';
|
|
180
|
+
|
|
181
|
+
if (layout.webRootRel !== null && (relPosix === layout.webRootRel || relPosix.startsWith(`${layout.webRootRel}/`))) {
|
|
182
|
+
return 'web';
|
|
183
|
+
}
|
|
184
|
+
if (
|
|
185
|
+
layout.bffRootRel !== null &&
|
|
186
|
+
layout.bffRootRel !== 'src' &&
|
|
187
|
+
(relPosix === layout.bffRootRel || relPosix.startsWith(`${layout.bffRootRel}/`))
|
|
188
|
+
) {
|
|
189
|
+
return 'bff';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Standard directory conventions (applicable to single-root or `apiRoot: "src"` layouts)
|
|
193
|
+
const stripped = relPosix.startsWith('src/') ? relPosix.slice(4) : relPosix;
|
|
194
|
+
if (isClientEntryFile(stripped)) return 'web';
|
|
195
|
+
if (/^(?:web|kit|views|actions|components)\//.test(stripped)) return 'web';
|
|
196
|
+
if (/^(?:bff|api|server|config|foundation|application)\//.test(stripped)) return 'bff';
|
|
197
|
+
return 'neutral';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function classifyBffLayer(relPosix: string, layout: WorkspaceLayout): BffLayer | null {
|
|
201
|
+
let sub = relPosix;
|
|
202
|
+
if (layout.bffRootRel !== null && sub.startsWith(`${layout.bffRootRel}/`)) {
|
|
203
|
+
sub = sub.slice(layout.bffRootRel.length + 1);
|
|
204
|
+
} else if (sub.startsWith('src/bff/')) {
|
|
205
|
+
sub = sub.slice('src/bff/'.length);
|
|
206
|
+
} else if (sub.startsWith('bff/')) {
|
|
207
|
+
sub = sub.slice('bff/'.length);
|
|
208
|
+
} else if (sub.startsWith('src/server/')) {
|
|
209
|
+
sub = sub.slice('src/server/'.length);
|
|
210
|
+
} else if (sub.startsWith('src/')) {
|
|
211
|
+
sub = sub.slice('src/'.length);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (sub.startsWith('api/service/') || sub.startsWith('api/')) return 'contract';
|
|
215
|
+
if (sub.startsWith('application/')) return 'application';
|
|
216
|
+
if (sub.startsWith('foundation/')) return 'foundation';
|
|
217
|
+
if (sub.startsWith('domain/') && layout.hasFourLayerDomain) return 'domain';
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 扫描应用源码目录,核对双平面隔离(web ↔ bff ↔ shared)、BFF 四层依赖方向与页面视图横向隔离;
|
|
223
|
+
* 返回 KIT-APP-015 诊断清单(按文件路径与行号稳定排序)。
|
|
224
|
+
*/
|
|
225
|
+
export async function scanKitAppLayering(appDir: string): Promise<KitDiagnostic[]> {
|
|
226
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
227
|
+
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
228
|
+
const layout = detectLayout(fs, path, appDir);
|
|
229
|
+
const root = layout.projectRoot;
|
|
230
|
+
const displayBase = path.resolve(appDir);
|
|
231
|
+
const out: KitDiagnostic[] = [];
|
|
232
|
+
|
|
233
|
+
const formatFile = (absFile: string): string => {
|
|
234
|
+
const rel = toPosix(path.relative(displayBase, absFile));
|
|
235
|
+
return rel.startsWith('..') ? toPosix(path.relative(root, absFile)) : rel;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const files: string[] = [];
|
|
239
|
+
const walk = (dir: string): void => {
|
|
240
|
+
let entries: import('node:fs').Dirent[];
|
|
241
|
+
try {
|
|
242
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
243
|
+
} catch {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
247
|
+
if (e.name.startsWith('.') || SKIP_DIRS.has(e.name)) continue;
|
|
248
|
+
const full = path.join(dir, e.name);
|
|
249
|
+
if (e.isDirectory()) {
|
|
250
|
+
walk(full);
|
|
251
|
+
} else if (
|
|
252
|
+
e.isFile() &&
|
|
253
|
+
SOURCE_EXTS.some((ext) => e.name.endsWith(ext)) &&
|
|
254
|
+
!/\.d\.[cm]?ts$/.test(e.name) &&
|
|
255
|
+
!/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(e.name)
|
|
256
|
+
) {
|
|
257
|
+
files.push(full);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
walk(root);
|
|
262
|
+
|
|
263
|
+
for (const fromFull of files) {
|
|
264
|
+
let text: string;
|
|
265
|
+
try {
|
|
266
|
+
text = fs.readFileSync(fromFull, 'utf8');
|
|
267
|
+
} catch {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const fromRel = toPosix(path.relative(root, fromFull));
|
|
271
|
+
const fromDisplay = formatFile(fromFull);
|
|
272
|
+
const fromPlane = classifyPlane(fromRel, layout);
|
|
273
|
+
const fromLayer = classifyBffLayer(fromRel, layout);
|
|
274
|
+
const fromIsView = isViewFile(fromRel);
|
|
275
|
+
const refs = extractModuleSpecifiers(text, fromRel);
|
|
276
|
+
|
|
277
|
+
for (const ref of refs) {
|
|
278
|
+
// R-APP-1c: shared/ 纯净度——禁止依赖 Node.js 内置模块
|
|
279
|
+
if (fromPlane === 'shared' && NODE_BUILTIN_RE.test(ref.spec)) {
|
|
280
|
+
out.push({
|
|
281
|
+
code: 'KIT-APP-015',
|
|
282
|
+
path: `${fromDisplay}:${ref.line}`,
|
|
283
|
+
file: fromDisplay,
|
|
284
|
+
line: ref.line,
|
|
285
|
+
column: ref.column,
|
|
286
|
+
message: `shared 共享契约模块 '${fromDisplay}' 引用了 Node 内置模块 '${ref.spec}'(R-APP-1:shared 须保持零运行时 IO 纯净)`,
|
|
287
|
+
hint: `将涉及文件 / 网络 / 进程的实现移入 bff/foundation/,shared/ 仅保留纯类型与静态枚举`,
|
|
288
|
+
});
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (!ref.spec.startsWith('.')) continue;
|
|
293
|
+
const targetFull = resolveRelativeTarget(fs, path, fromFull, ref.spec);
|
|
294
|
+
if (targetFull === null) continue;
|
|
295
|
+
const targetRel = toPosix(path.relative(root, targetFull));
|
|
296
|
+
if (targetRel.startsWith('..')) continue;
|
|
297
|
+
const targetDisplay = formatFile(targetFull);
|
|
298
|
+
const toPlane = classifyPlane(targetRel, layout);
|
|
299
|
+
|
|
300
|
+
// R-APP-1a: 客户端面禁止引用服务端面或 soma.server.*
|
|
301
|
+
if (fromPlane === 'web' && (toPlane === 'bff' || toPlane === 'server-entry')) {
|
|
302
|
+
out.push({
|
|
303
|
+
code: 'KIT-APP-015',
|
|
304
|
+
path: `${fromDisplay}:${ref.line}`,
|
|
305
|
+
file: fromDisplay,
|
|
306
|
+
line: ref.line,
|
|
307
|
+
column: ref.column,
|
|
308
|
+
message: `客户端模块 '${fromDisplay}' 越界引用了服务端模块 '${targetDisplay}'(R-APP-1:客户端面严禁静态依赖 BFF / api / config / soma.server)`,
|
|
309
|
+
hint: `两端共用的 DTO 类型与枚举请提取到 shared/;服务端逻辑请通过 /api/* HTTP 接口调用`,
|
|
310
|
+
});
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// R-APP-1b: 服务端面禁止反向引用客户端面
|
|
315
|
+
if (fromPlane === 'bff' && toPlane === 'web') {
|
|
316
|
+
out.push({
|
|
317
|
+
code: 'KIT-APP-015',
|
|
318
|
+
path: `${fromDisplay}:${ref.line}`,
|
|
319
|
+
file: fromDisplay,
|
|
320
|
+
line: ref.line,
|
|
321
|
+
column: ref.column,
|
|
322
|
+
message: `服务端模块 '${fromDisplay}' 反向引用了客户端模块 '${targetDisplay}'(R-APP-1:BFF 严禁依赖浏览器端视图 / 动作 / 组件)`,
|
|
323
|
+
hint: `将两端共用的纯类型或纯常量下沉至 shared/`,
|
|
324
|
+
});
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// R-APP-1c: shared/ 禁止引用客户端面或服务端面
|
|
329
|
+
if (fromPlane === 'shared' && (toPlane === 'web' || toPlane === 'bff' || toPlane === 'server-entry')) {
|
|
330
|
+
out.push({
|
|
331
|
+
code: 'KIT-APP-015',
|
|
332
|
+
path: `${fromDisplay}:${ref.line}`,
|
|
333
|
+
file: fromDisplay,
|
|
334
|
+
line: ref.line,
|
|
335
|
+
column: ref.column,
|
|
336
|
+
message: `共享契约模块 '${fromDisplay}' 反向引用了 '${targetDisplay}'(R-APP-1:shared 处于最底层,严禁引用 web 或 bff)`,
|
|
337
|
+
hint: `保持 shared/ 单向被 web/ 与 bff/ 消费,不要从 shared/ 反向 import 业务实现`,
|
|
338
|
+
});
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// R-APP-3: 页面视图禁止横向互引 views/a.view.ts -> views/b.view.ts
|
|
343
|
+
if (fromIsView && isViewFile(targetRel) && fromRel !== targetRel) {
|
|
344
|
+
out.push({
|
|
345
|
+
code: 'KIT-APP-015',
|
|
346
|
+
path: `${fromDisplay}:${ref.line}`,
|
|
347
|
+
file: fromDisplay,
|
|
348
|
+
line: ref.line,
|
|
349
|
+
column: ref.column,
|
|
350
|
+
message: `页面视图 '${fromDisplay}' 直接横向引用了另一页面视图 '${targetDisplay}'(R-APP-3:严禁跨页视图直连)`,
|
|
351
|
+
hint: `将跨页面复用的辅助逻辑提取到 views/ 非 .view 辅助模块、actions/、lib/ 或 shared/`,
|
|
352
|
+
});
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// R-APP-2: BFF 四层自上而下(api/service[3] -> application[2] -> domain[1] -> foundation[0])
|
|
357
|
+
if (fromLayer !== null) {
|
|
358
|
+
const toLayer = classifyBffLayer(targetRel, layout);
|
|
359
|
+
if (toLayer !== null && LAYER_RANK[toLayer] > LAYER_RANK[fromLayer]) {
|
|
360
|
+
out.push({
|
|
361
|
+
code: 'KIT-APP-015',
|
|
362
|
+
path: `${fromDisplay}:${ref.line}`,
|
|
363
|
+
file: fromDisplay,
|
|
364
|
+
line: ref.line,
|
|
365
|
+
column: ref.column,
|
|
366
|
+
message: `下层模块 '${fromDisplay}'(${fromLayer})反向引用了上层模块 '${targetDisplay}'(${toLayer})(R-APP-2:四层依赖只许自上而下)`,
|
|
367
|
+
hint: `将公共类型 / 纯函数下沉至更低层(${fromLayer} 或 shared/),或由上层通过参数注入依赖`,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return out;
|
|
375
|
+
}
|
package/src/cli/kit-cli.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { closestOf, formatKitDiagnostic, kitDiagnosticFooter } from '../compile/
|
|
|
5
5
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
6
6
|
import { formatKitThemeDegradation, type NineDimDegradation } from '../theme/theme-tokens';
|
|
7
7
|
import { scanKitCoreImports } from './core-imports';
|
|
8
|
+
import { scanKitAppLayering } from './app-layer-check';
|
|
8
9
|
import { scanKitViewWrites } from './view-writes';
|
|
9
10
|
import { packageNameOf, scaffoldKitApp } from './kit-init';
|
|
10
11
|
import { formatServiceEndpointReport, runServiceEndpointCheck, type ServiceEndpointWarning } from './service-endpoint-check';
|
|
@@ -34,9 +35,9 @@ export interface KitCliIo {
|
|
|
34
35
|
|
|
35
36
|
export const KIT_CLI_USAGE = [
|
|
36
37
|
'Usage:',
|
|
37
|
-
' soma-kit init <目录>
|
|
38
|
+
' soma-kit init <目录> [--bff] 生成最小可跑的 soma-kit 应用(--bff 生成 src/{shared,web,bff} 双平面四层标准骨架;已有同名文件则整体拒绝)',
|
|
38
39
|
' soma kit explain <诊断码> 打印诊断的完整说明、常见原因与正反示例',
|
|
39
|
-
' soma kit check <应用目录> [--json] 编译应用全部页面并扫描源码是否直接 import soma-core*(KIT-APP-013)、展示对象方法是否对数组原地变异(KIT-VIEW-008),打印带修改建议的诊断;--json 在标准输出打印机器可读 JSON',
|
|
40
|
+
' soma kit check <应用目录> [--json] 编译应用全部页面并扫描源码是否直接 import soma-core*(KIT-APP-013)、是否违反双平面与四层边界(KIT-APP-015)、展示对象方法是否对数组原地变异(KIT-VIEW-008),打印带修改建议的诊断;--json 在标准输出打印机器可读 JSON',
|
|
40
41
|
' 另核对页面里 /api/... 地址是否有对应服务文件与方法,不符只打印告警,不影响退出码',
|
|
41
42
|
' 退出码:0 全部通过;1 有诊断;2 用法错误(缺参数 / 未知选项)',
|
|
42
43
|
' soma kit check <应用目录> [--strict] [--profile ai|human] [--score]',
|
|
@@ -84,8 +85,23 @@ async function checkApp(
|
|
|
84
85
|
): Promise<{ pages: number; diagnostics: KitDiagnostic[]; degradations: readonly NineDimDegradation[]; layoutReports?: ReadonlyMap<string, KitLayoutReport>; deprecations?: readonly KitAdvisory[]; root: string }> {
|
|
85
86
|
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
86
87
|
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
let root = path.resolve(appDir);
|
|
89
|
+
let file = path.join(root, 'soma.app.ts');
|
|
90
|
+
if (!fs.existsSync(file)) {
|
|
91
|
+
try {
|
|
92
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')) as { soma?: { webRoot?: unknown } };
|
|
93
|
+
if (typeof pkg.soma?.webRoot === 'string' && pkg.soma.webRoot.trim() !== '') {
|
|
94
|
+
const candidateRoot = path.resolve(root, pkg.soma.webRoot.trim());
|
|
95
|
+
const candidateFile = path.join(candidateRoot, 'soma.app.ts');
|
|
96
|
+
if (!path.relative(root, candidateRoot).startsWith('..') && fs.existsSync(candidateFile)) {
|
|
97
|
+
root = candidateRoot;
|
|
98
|
+
file = candidateFile;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
// 无 package.json 或解析失败时保持原目录报错口径
|
|
103
|
+
}
|
|
104
|
+
}
|
|
89
105
|
if (!fs.existsSync(file)) {
|
|
90
106
|
return {
|
|
91
107
|
pages: 0,
|
|
@@ -219,13 +235,19 @@ export async function runKitCli(args: readonly string[], io: KitCliIo, load: (fi
|
|
|
219
235
|
return runKitMigrate(rest, io);
|
|
220
236
|
}
|
|
221
237
|
if (sub === 'init') {
|
|
222
|
-
const
|
|
238
|
+
const flags = rest.filter((x) => x.startsWith('--'));
|
|
239
|
+
const unknown = flags.filter((x) => x !== '--bff');
|
|
240
|
+
if (unknown.length > 0) {
|
|
241
|
+
io.err(`[soma-kit init] 未知选项 ${unknown.join(' ')}\n${KIT_CLI_USAGE}`);
|
|
242
|
+
return 2;
|
|
243
|
+
}
|
|
244
|
+
const dir = rest.find((x) => !x.startsWith('--'));
|
|
223
245
|
if (dir === undefined) {
|
|
224
246
|
io.err(`[soma-kit init] 缺目录\n${KIT_CLI_USAGE}`);
|
|
225
247
|
return 1;
|
|
226
248
|
}
|
|
227
249
|
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
228
|
-
const result = await scaffoldKitApp(dir, { name: packageNameOf(path.basename(path.resolve(dir))) });
|
|
250
|
+
const result = await scaffoldKitApp(dir, { name: packageNameOf(path.basename(path.resolve(dir))), bff: flags.includes('--bff') });
|
|
229
251
|
if (result.conflicts.length > 0) {
|
|
230
252
|
io.err(`[soma-kit init] ${result.root} 下已有同名文件,未写入任何内容:\n${result.conflicts.map((f) => ` ${f}`).join('\n')}\n`);
|
|
231
253
|
return 1;
|
|
@@ -259,8 +281,13 @@ export async function runKitCli(args: readonly string[], io: KitCliIo, load: (fi
|
|
|
259
281
|
const deprecations: readonly KitAdvisory[] = checked.deprecations ?? [];
|
|
260
282
|
const strictFailed = parsed.strict && strictFails([...advisories, ...deprecations]);
|
|
261
283
|
const deprecationText = deprecations.length === 0 ? '' : `弃用提示 ${deprecations.length} 条(仍生效但应迁移;不影响 ok,--strict 时算失败)\n${deprecations.map(formatAdvisory).join('\n')}\n`;
|
|
262
|
-
// AP-1:应用源码不直接 import soma-core*(KIT-APP-013
|
|
263
|
-
const diagnostics = [
|
|
284
|
+
// AP-1:应用源码不直接 import soma-core*(KIT-APP-013)、双平面与四层边界(KIT-APP-015)、展示对象方法写入与对象/动作引用核对,与装配结果合并输出
|
|
285
|
+
const diagnostics = [
|
|
286
|
+
...(await scanKitCoreImports(dir)),
|
|
287
|
+
...(await scanKitAppLayering(dir)),
|
|
288
|
+
...(await scanKitViewWrites(checked.root, load)),
|
|
289
|
+
...checked.diagnostics,
|
|
290
|
+
];
|
|
264
291
|
const degradations = checked.degradations;
|
|
265
292
|
// 接口落点核对:只出告警,不进诊断、不改退出码;编译通过或失败都跑
|
|
266
293
|
const endpoints = await runServiceEndpointCheck(dir);
|