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
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
// 1) KIT-APP-004:所有登记进 baseComponents / staticObjectComponents 的 App* 组件,必须经
|
|
5
5
|
// wrapKitDataComponent、composeKitDataComponents 或 declareKitUses 显式登记依赖组件与候选类元数据;
|
|
6
6
|
// 声明的 uses 必须是真实存在的内置组件名,own 候选类必须通过 checkClasses 校验(禁方括号任意值)。
|
|
7
|
-
// 2) KIT-APP-005:严禁应用组件在 templateHtml
|
|
7
|
+
// 2) KIT-APP-005:严禁应用组件在 templateHtml、控制器或源码中私自拼写已被 soma-kit
|
|
8
8
|
// 标准组件接管的原生表单控件(原生 <select>、原生 <input type="range">、原生 <input type="date|datetime-local|time|month|week">),
|
|
9
|
-
//
|
|
10
|
-
//
|
|
9
|
+
// 严禁在 TS/HTML 中书写内联 style / 操作 .style / setAttribute('style', ...),
|
|
10
|
+
// 也严禁在非组件 TS(views/actions/api/soma.app.ts 等)中操作 .className / .classList 或手绑 addEventListener 等 DOM 事件。
|
|
11
|
+
// 下拉一律走 Select / Combobox / mountKitSelectField,滑块一律走 Range,日期时间一律走 Date / DateRange / TimePicker。
|
|
11
12
|
|
|
12
13
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
14
|
import { KIT_BASE_COMPONENTS } from '../base/index';
|
|
@@ -16,6 +17,8 @@ import { KIT_STATIC_BUILTIN_LAZY_NAMES } from '../data/static-lazy';
|
|
|
16
17
|
import { KIT_RESIDENT_COMPONENT_NAMES, wrappedCandidateSource } from '../data/wrapped-candidates';
|
|
17
18
|
import { checkClasses } from '../object-renderer/merge-class';
|
|
18
19
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
20
|
+
import { kitFail } from '../compile/kit-error';
|
|
21
|
+
import { getKitControllerSource, isKitControllerFactory } from '../base/shared';
|
|
19
22
|
|
|
20
23
|
/** declareKitUses 允许引用的内置组件全集 */
|
|
21
24
|
export const VALID_KIT_USES_NAMES: ReadonlySet<string> = new Set<string>([
|
|
@@ -44,6 +47,13 @@ interface ForbiddenRule {
|
|
|
44
47
|
readonly message: string;
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
const MSG_STYLE_PROP = '禁止在 TS 中操作 .style 修改内联样式;要么在组件模板写好标准类,要么通过 DSL 传入或使用 data-* 状态属性 / SVG 几何属性';
|
|
51
|
+
const MSG_SET_ATTR_STYLE = '禁止调用 setAttribute("style", ...) 注入内联样式;请统一使用 Tailwind 候选类与 --soma-* 设计令牌';
|
|
52
|
+
const MSG_INLINE_STYLE_HTML = '禁止在模板或 HTML 片段中使用内联 style="..." 属性;请统一使用 Tailwind 候选类与 --soma-* 设计令牌';
|
|
53
|
+
const MSG_INLINE_ON_EVENT = '禁止使用内联 on* 事件或 .on* = 赋值;业务交互请预埋到组件事件槽位并通过 DSL 绑定';
|
|
54
|
+
const MSG_NON_COMP_CLASS = '业务与展示对象 TS(非 components/)禁止直接操作 DOM 样式类(.className / .classList);样式要么在组件模板写好,要么由 *.kit.yaml DSL 传入';
|
|
55
|
+
const MSG_NON_COMP_EVENT = '业务与展示对象 TS(非 components/)禁止直接调用 addEventListener 手绑 DOM 事件;动态事件应预埋在业务组件槽位中,由 *.kit.yaml 的 behavior.actions / view.on 传入并路由至展示对象方法';
|
|
56
|
+
|
|
47
57
|
const FORBIDDEN_DOM_PATTERNS: readonly ForbiddenRule[] = [
|
|
48
58
|
{
|
|
49
59
|
id: 'raw-style-tag',
|
|
@@ -55,6 +65,31 @@ const FORBIDDEN_DOM_PATTERNS: readonly ForbiddenRule[] = [
|
|
|
55
65
|
pattern: /createElement\s*\(\s*['"`]style['"`]\s*\)/,
|
|
56
66
|
message: '禁止调用 createElement("style") 动态注入样式表;请统一使用 Tailwind 候选类与 --soma-* 设计令牌',
|
|
57
67
|
},
|
|
68
|
+
{
|
|
69
|
+
id: 'inline-style-html',
|
|
70
|
+
pattern: /<[a-zA-Z][^>]*\sstyle\s*=\s*['"]/i,
|
|
71
|
+
message: MSG_INLINE_STYLE_HTML,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'inline-on-event-html',
|
|
75
|
+
pattern: /<[a-zA-Z][^>]*\son(?:click|change|input|keydown|keyup|submit|focus|blur|mousedown|mouseup|pointerdown|pointerup)\s*=\s*['"]/i,
|
|
76
|
+
message: MSG_INLINE_ON_EVENT,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'dom-style-prop',
|
|
80
|
+
pattern: /\.\s*style\s*(?:\.\s*[a-zA-Z_$][\w$]*|\[\s*['"`][^'"`]+['"`]\s*\])/,
|
|
81
|
+
message: MSG_STYLE_PROP,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'dom-set-attribute-style',
|
|
85
|
+
pattern: /\.\s*setAttribute(?:NS)?\s*\([^)]*['"`]style['"`]/,
|
|
86
|
+
message: MSG_SET_ATTR_STYLE,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'dom-on-event-assign',
|
|
90
|
+
pattern: /\.\s*on(?:click|change|input|keydown|keyup|submit|focus|blur|mousedown|mouseup|pointerdown|pointerup)\s*=(?!=)/,
|
|
91
|
+
message: MSG_INLINE_ON_EVENT,
|
|
92
|
+
},
|
|
58
93
|
{
|
|
59
94
|
id: 'native-select-tag',
|
|
60
95
|
pattern: /<\s*select(?=[\s>/])/i,
|
|
@@ -118,53 +153,274 @@ export function findForbiddenNativeControls(text: string): Array<{ line: number;
|
|
|
118
153
|
export function assertSinglePathComponent(name: string, def: SomaComponentDefinition): void {
|
|
119
154
|
const meta = wrappedCandidateSource(def);
|
|
120
155
|
if (meta === undefined) {
|
|
121
|
-
|
|
122
|
-
`[soma-kit] [KIT-APP-004] 应用组件 ${name} 未经唯一接入路径声明:必须通过 wrapKitDataComponent / composeKitDataComponents 包装组合,或经 declareKitUses(${name}, uses, candidates) 显式登记依赖组件与候选类`,
|
|
123
|
-
);
|
|
156
|
+
kitFail('KIT-APP-004', `components.${name}`, `应用组件 ${name} 未经唯一接入路径声明:必须通过 wrapKitDataComponent / composeKitDataComponents 包装组合,或经 declareKitUses(${name}, uses, candidates) 显式登记依赖组件与候选类`, `用 wrapKitDataComponent 包装,或在定义处调用 declareKitUses(${name}, uses, candidates)`);
|
|
124
157
|
}
|
|
125
158
|
for (const used of meta.uses ?? []) {
|
|
126
159
|
if (!VALID_KIT_USES_NAMES.has(used)) {
|
|
127
|
-
|
|
128
|
-
`[soma-kit] [KIT-APP-004] 应用组件 ${name} 在 declareKitUses 中声明了未知的内置组件 "${used}"`,
|
|
129
|
-
);
|
|
160
|
+
kitFail('KIT-APP-004', `components.${name}.uses`, `应用组件 ${name} 在 declareKitUses 中声明了未知的内置组件 "${used}"`, '依赖组件名必须是内置组件闭集里的名字');
|
|
130
161
|
}
|
|
131
162
|
}
|
|
132
163
|
for (const tok of meta.own) {
|
|
133
164
|
const bad = checkClasses(tok, `${name}.candidates`);
|
|
134
165
|
if (bad.length > 0) {
|
|
135
|
-
|
|
136
|
-
`[soma-kit] [KIT-APP-004] 应用组件 ${name} 的候选类 "${tok}" 非法:${bad[0]!.message}`,
|
|
137
|
-
);
|
|
166
|
+
kitFail('KIT-APP-004', `components.${name}.candidates`, `应用组件 ${name} 的候选类 "${tok}" 非法:${bad[0]!.message}`, '候选类只能用刻度内的 Tailwind 类,不写方括号任意值');
|
|
138
167
|
}
|
|
139
168
|
}
|
|
169
|
+
if (typeof def.controllerFactory !== 'function' || !isKitControllerFactory(def.controllerFactory)) {
|
|
170
|
+
kitFail('KIT-APP-014', `components.${name}.controllerFactory`, `应用组件 ${name} 的 controllerFactory 必须由 createKitController((api) => ({ ... })) 生成(不接受纯声明式无控制器组件或手写工厂)`, '使用 createKitController((api) => ({ render(root, p, api) { ... } })) 定义控制器');
|
|
171
|
+
}
|
|
140
172
|
if (typeof def.templateHtml === 'string' && /\sstyle\s*=/i.test(def.templateHtml)) {
|
|
141
|
-
|
|
142
|
-
`[soma-kit] [KIT-APP-005] 应用组件 ${name} 的 templateHtml 含内联 style 属性;样式必须统一使用 Tailwind 候选类`,
|
|
143
|
-
);
|
|
173
|
+
kitFail('KIT-APP-005', `components.${name}.templateHtml`, `应用组件 ${name} 的 templateHtml 含内联 style 属性;样式必须统一使用 Tailwind 候选类`, '删掉 style 属性,改用 class 里的 Tailwind 候选类');
|
|
144
174
|
}
|
|
145
175
|
const tplHits = typeof def.templateHtml === 'string' ? findForbiddenNativeControls(def.templateHtml) : [];
|
|
146
176
|
if (tplHits.length > 0) {
|
|
147
|
-
|
|
177
|
+
kitFail('KIT-APP-005', `components.${name}.templateHtml`, `应用组件 ${name} 的 templateHtml 违规:${tplHits[0]!.message}`, '改用 soma-kit 标准组件(Select / Slider / DatePicker 等),不手写原生控件');
|
|
148
178
|
}
|
|
149
179
|
if (typeof def.controllerFactory === 'function') {
|
|
150
|
-
const fnHits = findForbiddenNativeControls(
|
|
180
|
+
const fnHits = findForbiddenNativeControls(getKitControllerSource(def.controllerFactory));
|
|
151
181
|
if (fnHits.length > 0) {
|
|
152
|
-
|
|
182
|
+
kitFail('KIT-APP-005', `components.${name}.controller`, `应用组件 ${name} 的控制器违规:${fnHits[0]!.message}`, '控制器里不要创建原生控件,改用 soma-kit 标准组件');
|
|
153
183
|
}
|
|
154
184
|
}
|
|
155
185
|
}
|
|
156
186
|
|
|
187
|
+
const SKIP_SCAN_DIRS = new Set([
|
|
188
|
+
'node_modules',
|
|
189
|
+
'dist',
|
|
190
|
+
'build',
|
|
191
|
+
'coverage',
|
|
192
|
+
'tests',
|
|
193
|
+
'test',
|
|
194
|
+
'scripts',
|
|
195
|
+
'.soma',
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
const DOM_INLINE_ON_EVENTS = new Set([
|
|
199
|
+
'onclick',
|
|
200
|
+
'onchange',
|
|
201
|
+
'oninput',
|
|
202
|
+
'onkeydown',
|
|
203
|
+
'onkeyup',
|
|
204
|
+
'onsubmit',
|
|
205
|
+
'onfocus',
|
|
206
|
+
'onblur',
|
|
207
|
+
'onmousedown',
|
|
208
|
+
'onmouseup',
|
|
209
|
+
'onpointerdown',
|
|
210
|
+
'onpointerup',
|
|
211
|
+
]);
|
|
212
|
+
|
|
213
|
+
const HTML_TAG_FORBIDDEN_RULES: readonly ForbiddenRule[] = [
|
|
214
|
+
{
|
|
215
|
+
id: 'raw-style-tag',
|
|
216
|
+
pattern: /<\s*style(?=[\s>/])/i,
|
|
217
|
+
message: '禁止在模板或控制器中手写 <style> 标签注入全局样式;请统一使用 Tailwind 候选类与 --soma-* 设计令牌',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: 'native-select-tag',
|
|
221
|
+
pattern: /<\s*select(?=[\s>/])/i,
|
|
222
|
+
message: '禁止手写原生 <select> 标签;请改用 soma-kit 标准组件 Select / Combobox(命令式嵌入用 mountKitSelectField)',
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: 'native-range-tag',
|
|
226
|
+
pattern: /<\s*input\b[^>]*\btype\s*=\s*['"]range['"]/i,
|
|
227
|
+
message: '禁止手写原生 <input type="range"> 滑块;请改用 soma-kit 标准组件 Range(自绘无障碍 SVG 滑块)',
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
id: 'native-date-tag',
|
|
231
|
+
pattern: /<\s*input\b[^>]*\btype\s*=\s*['"](?:date|datetime-local|time|month|week)['"]/i,
|
|
232
|
+
message: '禁止手写原生日期/时间 <input>;请改用 soma-kit 标准组件 Date / DateRange / TimePicker',
|
|
233
|
+
},
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
const HTML_INLINE_ATTR_RULES: readonly ForbiddenRule[] = [
|
|
237
|
+
{
|
|
238
|
+
id: 'inline-style-html',
|
|
239
|
+
pattern: /<[a-zA-Z][^>]*\sstyle\s*=\s*['"]/i,
|
|
240
|
+
message: MSG_INLINE_STYLE_HTML,
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: 'inline-on-event-html',
|
|
244
|
+
pattern: /<[a-zA-Z][^>]*\son(?:click|change|input|keydown|keyup|submit|focus|blur|mousedown|mouseup|pointerdown|pointerup)\s*=\s*['"]/i,
|
|
245
|
+
message: MSG_INLINE_ON_EVENT,
|
|
246
|
+
},
|
|
247
|
+
];
|
|
248
|
+
|
|
249
|
+
type TsModule = typeof import('typescript');
|
|
250
|
+
|
|
251
|
+
function scriptKindForFile(ts: TsModule, fileName: string): import('typescript').ScriptKind {
|
|
252
|
+
if (fileName.endsWith('.tsx')) return ts.ScriptKind.TSX;
|
|
253
|
+
if (fileName.endsWith('.jsx')) return ts.ScriptKind.JSX;
|
|
254
|
+
if (fileName.endsWith('.js') || fileName.endsWith('.mjs') || fileName.endsWith('.cjs')) return ts.ScriptKind.JS;
|
|
255
|
+
return ts.ScriptKind.TS;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function extractStaticHtmlText(ts: TsModule, node: import('typescript').Expression): string {
|
|
259
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node)) {
|
|
260
|
+
return extractStaticHtmlText(ts, node.expression);
|
|
261
|
+
}
|
|
262
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
263
|
+
return node.text;
|
|
264
|
+
}
|
|
265
|
+
if (ts.isTemplateExpression(node)) {
|
|
266
|
+
return [node.head.text, ...node.templateSpans.map((span) => span.literal.text)].join(' ');
|
|
267
|
+
}
|
|
268
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
269
|
+
return extractStaticHtmlText(ts, node.left) + extractStaticHtmlText(ts, node.right);
|
|
270
|
+
}
|
|
271
|
+
return '';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function propertyAccessName(ts: TsModule, node: import('typescript').Expression): string | undefined {
|
|
275
|
+
if (ts.isPropertyAccessExpression(node)) return node.name.text;
|
|
276
|
+
if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression)) {
|
|
277
|
+
return node.argumentExpression.text;
|
|
278
|
+
}
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function scanSourceWithAst(
|
|
283
|
+
ts: TsModule,
|
|
284
|
+
fullPath: string,
|
|
285
|
+
code: string,
|
|
286
|
+
inComponentsDir: boolean,
|
|
287
|
+
): Array<{ line: number; message: string }> {
|
|
288
|
+
const sourceFile = ts.createSourceFile(fullPath, code, ts.ScriptTarget.Latest, true, scriptKindForFile(ts, fullPath));
|
|
289
|
+
const hits: Array<{ line: number; message: string }> = [];
|
|
290
|
+
const seen = new Set<string>();
|
|
291
|
+
|
|
292
|
+
const pushHit = (node: import('typescript').Node, message: string): void => {
|
|
293
|
+
const line = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
294
|
+
const key = `${line}:${message}`;
|
|
295
|
+
if (seen.has(key)) return;
|
|
296
|
+
seen.add(key);
|
|
297
|
+
hits.push({ line, message });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const checkHtmlString = (node: import('typescript').Node, html: string, includeInlineAttrs: boolean): void => {
|
|
301
|
+
if (!html) return;
|
|
302
|
+
if (includeInlineAttrs) {
|
|
303
|
+
for (const rule of HTML_INLINE_ATTR_RULES) {
|
|
304
|
+
if (rule.pattern.test(html)) pushHit(node, rule.message);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
for (const rule of HTML_TAG_FORBIDDEN_RULES) {
|
|
308
|
+
if (rule.pattern.test(html)) pushHit(node, rule.message);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const visit = (node: import('typescript').Node, insideFunction: boolean): void => {
|
|
313
|
+
if (ts.isTypeNode(node) || ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// 1. AST .style / ['style'] 访问(全应用禁止)
|
|
318
|
+
if (
|
|
319
|
+
(ts.isPropertyAccessExpression(node) && node.name.text === 'style')
|
|
320
|
+
|| (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression) && node.argumentExpression.text === 'style')
|
|
321
|
+
) {
|
|
322
|
+
pushHit(node, MSG_STYLE_PROP);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// 2. AST 非组件目录禁止操作 .className / .classList
|
|
326
|
+
if (!inComponentsDir) {
|
|
327
|
+
const propName = ts.isPropertyAccessExpression(node)
|
|
328
|
+
? node.name.text
|
|
329
|
+
: (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : undefined);
|
|
330
|
+
if (propName === 'className' || propName === 'classList') {
|
|
331
|
+
pushHit(node, MSG_NON_COMP_CLASS);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 3. AST 函数调用检查
|
|
336
|
+
if (ts.isCallExpression(node)) {
|
|
337
|
+
const calleeName = ts.isIdentifier(node.expression)
|
|
338
|
+
? node.expression.text
|
|
339
|
+
: (ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : undefined);
|
|
340
|
+
|
|
341
|
+
if (calleeName === 'setAttribute' && node.arguments.length >= 1 && ts.isStringLiteralLike(node.arguments[0])) {
|
|
342
|
+
const attr = node.arguments[0].text.toLowerCase();
|
|
343
|
+
if (attr === 'style') pushHit(node, MSG_SET_ATTR_STYLE);
|
|
344
|
+
if (!inComponentsDir && attr === 'class') pushHit(node, MSG_NON_COMP_CLASS);
|
|
345
|
+
} else if (calleeName === 'setAttributeNS' && node.arguments.length >= 2 && ts.isStringLiteralLike(node.arguments[1])) {
|
|
346
|
+
const attr = node.arguments[1].text.toLowerCase();
|
|
347
|
+
if (attr === 'style') pushHit(node, MSG_SET_ATTR_STYLE);
|
|
348
|
+
if (!inComponentsDir && attr === 'class') pushHit(node, MSG_NON_COMP_CLASS);
|
|
349
|
+
} else if (calleeName === 'createElement' && node.arguments.length >= 1 && ts.isStringLiteralLike(node.arguments[0])) {
|
|
350
|
+
const tag = node.arguments[0].text.toLowerCase();
|
|
351
|
+
if (tag === 'style') {
|
|
352
|
+
pushHit(node, '禁止调用 createElement("style") 动态注入样式表;请统一使用 Tailwind 候选类与 --soma-* 设计令牌');
|
|
353
|
+
} else if (tag === 'select') {
|
|
354
|
+
pushHit(node, '禁止调用 createElement("select") 创建原生下拉框;请改用 mountKitSelectField 或 Select 组件');
|
|
355
|
+
}
|
|
356
|
+
} else if (calleeName === 'insertAdjacentHTML' && node.arguments.length >= 2) {
|
|
357
|
+
checkHtmlString(node.arguments[1]!, extractStaticHtmlText(ts, node.arguments[1]!), true);
|
|
358
|
+
} else if (!inComponentsDir && (calleeName === 'addEventListener' || calleeName === 'removeEventListener' || calleeName === 'dispatchEvent')) {
|
|
359
|
+
pushHit(node, MSG_NON_COMP_EVENT);
|
|
360
|
+
} else if (!inComponentsDir && calleeName === 'insertRule') {
|
|
361
|
+
pushHit(node, MSG_NON_COMP_CLASS);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 4. AST new CSSStyleSheet()(非组件目录禁止)
|
|
366
|
+
if (!inComponentsDir && ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'CSSStyleSheet') {
|
|
367
|
+
pushHit(node, MSG_NON_COMP_CLASS);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// 5. AST 赋值表达式检查(innerHTML / outerHTML / .on* = / .type = 'range'|'date')
|
|
371
|
+
if (ts.isBinaryExpression(node) && (node.operatorToken.kind === ts.SyntaxKind.EqualsToken || node.operatorToken.kind === ts.SyntaxKind.PlusEqualsToken)) {
|
|
372
|
+
const leftName = propertyAccessName(ts, node.left);
|
|
373
|
+
if (leftName === 'innerHTML' || leftName === 'outerHTML') {
|
|
374
|
+
checkHtmlString(node.right, extractStaticHtmlText(ts, node.right), true);
|
|
375
|
+
} else if (node.operatorToken.kind === ts.SyntaxKind.EqualsToken && leftName !== undefined) {
|
|
376
|
+
if (DOM_INLINE_ON_EVENTS.has(leftName)) {
|
|
377
|
+
pushHit(node, MSG_INLINE_ON_EVENT);
|
|
378
|
+
} else if (leftName === 'type' && ts.isStringLiteralLike(node.right)) {
|
|
379
|
+
const val = node.right.text.toLowerCase();
|
|
380
|
+
if (val === 'range') {
|
|
381
|
+
pushHit(node, '禁止设置 input.type = "range" 创建原生滑块;请改用 soma-kit 标准组件 Range');
|
|
382
|
+
} else if (/^(?:date|datetime-local|time|month|week)$/.test(val)) {
|
|
383
|
+
pushHit(node, '禁止设置原生日期/时间 input.type;请改用 soma-kit 标准组件 Date / DateRange / TimePicker');
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// 6. AST 对象字面量 templateHtml 属性检查
|
|
390
|
+
if (ts.isPropertyAssignment(node)) {
|
|
391
|
+
const propName = ts.isIdentifier(node.name) || ts.isStringLiteral(node.name) ? node.name.text : undefined;
|
|
392
|
+
if (propName === 'templateHtml') {
|
|
393
|
+
checkHtmlString(node.initializer, extractStaticHtmlText(ts, node.initializer), true);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// 7. 函数体内的字符串/模板字面量中的原生控件标签(如 renderSneaky 返回 `<select>...`),不误伤顶层纯数据字典
|
|
398
|
+
if (insideFunction && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) || ts.isTemplateExpression(node))) {
|
|
399
|
+
checkHtmlString(node, extractStaticHtmlText(ts, node), false);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const nextInsideFunction = insideFunction || ts.isFunctionLike(node);
|
|
403
|
+
ts.forEachChild(node, (child) => visit(child, nextInsideFunction));
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
visit(sourceFile, false);
|
|
407
|
+
return hits;
|
|
408
|
+
}
|
|
409
|
+
|
|
157
410
|
/**
|
|
158
|
-
* 服务端编译与 `soma kit check`
|
|
159
|
-
*
|
|
160
|
-
*
|
|
411
|
+
* 服务端编译与 `soma kit check` 全量源码 AST 门禁:
|
|
412
|
+
* 递归扫描应用根目录 `<root>` 下全部 `.ts` / `.tsx` / `.js` / `.mjs` 源码(跳过 `node_modules` / `dist` / `tests` / `.soma` 等),
|
|
413
|
+
* 1) 全应用禁止:非标原生控件、<style>、AST `.style` 访问、`setAttribute('style', ...)`、`innerHTML`/`outerHTML`/`templateHtml` 内联 `style="..."` 或 `on*`、`.onclick =` 等赋值;
|
|
414
|
+
* 2) 非 `components/` 目录(如 `views/**`、`actions/**`、`api/**`、`soma.app.ts`)额外禁止:操作 `.className` / `.classList` / `setAttribute('class', ...)` / `CSSStyleSheet` 与手绑 `addEventListener`。
|
|
161
415
|
*/
|
|
162
416
|
export async function scanAppComponentSources(root: string): Promise<KitDiagnostic[]> {
|
|
163
417
|
const fsSpec = 'node:fs/promises';
|
|
164
418
|
const pathSpec = 'node:path';
|
|
419
|
+
const tsSpec = 'typescript';
|
|
165
420
|
const fs = await import(fsSpec);
|
|
166
421
|
const path = await import(pathSpec);
|
|
167
|
-
const
|
|
422
|
+
const tsMod = await import(tsSpec);
|
|
423
|
+
const ts = (tsMod.default ?? tsMod) as TsModule;
|
|
168
424
|
const diagnostics: KitDiagnostic[] = [];
|
|
169
425
|
|
|
170
426
|
async function walk(dir: string): Promise<void> {
|
|
@@ -179,16 +435,15 @@ export async function scanAppComponentSources(root: string): Promise<KitDiagnost
|
|
|
179
435
|
for (const entry of entries) {
|
|
180
436
|
const full = path.join(dir, entry.name);
|
|
181
437
|
if (entry.isDirectory()) {
|
|
182
|
-
if (entry.name
|
|
438
|
+
if (SKIP_SCAN_DIRS.has(entry.name) || entry.name.startsWith('.')) continue;
|
|
183
439
|
await walk(full);
|
|
184
440
|
continue;
|
|
185
441
|
}
|
|
186
|
-
if (!/\.(?:ts|js|mjs)$/.test(entry.name) || entry.name.endsWith('.d.ts')) continue;
|
|
442
|
+
if (!/\.(?:ts|tsx|js|mjs)$/.test(entry.name) || entry.name.endsWith('.d.ts')) continue;
|
|
187
443
|
const code = await fs.readFile(full, 'utf8');
|
|
188
|
-
// 仅对含可执行函数或模板字面量的组件/渲染模块扫描,跳过纯 JSON 常量数据字典
|
|
189
|
-
if (!code.includes('`') && !/\bfunction\b|=>|createElement/.test(code)) continue;
|
|
190
444
|
const rel = path.relative(root, full).split(path.sep).join('/');
|
|
191
|
-
|
|
445
|
+
const inComponentsDir = rel === 'components' || rel.startsWith('components/');
|
|
446
|
+
for (const hit of scanSourceWithAst(ts, full, code, inComponentsDir)) {
|
|
192
447
|
diagnostics.push({
|
|
193
448
|
code: 'KIT-APP-005',
|
|
194
449
|
path: `${rel}:${hit.line}`,
|
|
@@ -198,6 +453,6 @@ export async function scanAppComponentSources(root: string): Promise<KitDiagnost
|
|
|
198
453
|
}
|
|
199
454
|
}
|
|
200
455
|
|
|
201
|
-
await walk(
|
|
456
|
+
await walk(root);
|
|
202
457
|
return diagnostics;
|
|
203
458
|
}
|
package/src/app/compose-apps.ts
CHANGED
|
@@ -15,9 +15,22 @@ import { kitText } from '../i18n/kit-text';
|
|
|
15
15
|
import { kitActionExtras } from '../biz/shared/runtime-hub';
|
|
16
16
|
import { kitPermissionAllows } from '../base/permission-gate';
|
|
17
17
|
import type { DefineKitAppOptions } from './define-kit-app';
|
|
18
|
+
import type { KitViewClass } from './define-kit-view';
|
|
19
|
+
import { KitDiagnosticError, kitFail } from '../compile/kit-error';
|
|
18
20
|
|
|
19
21
|
type Grant = ReturnType<NonNullable<DefineKitAppOptions['pageGrants']>>[number];
|
|
20
22
|
type ExclusiveKey = 'auth' | 'eventMiddleware' | 'login';
|
|
23
|
+
type FileLayoutKey = 'root' | 'app' | 'pagesDir' | 'extraPagesDirs' | 'services' | 'defaultTheme';
|
|
24
|
+
type ComposedOptionKey =
|
|
25
|
+
| 'appYaml' | 'devFallback' | 'dicts' | 'entities' | 'packs'
|
|
26
|
+
| 'baseComponents' | 'staticObjectComponents' | 'actions' | 'requestTimeout' | 'views'
|
|
27
|
+
| 'bizComponents' | 'frames' | 'overrides' | 'appCandidates'
|
|
28
|
+
| 'appName' | 'title' | 'locales' | 'defaultLocale' | 'auth' | 'eventMiddleware'
|
|
29
|
+
| 'renderPorts' | 'identity' | 'defaultAccess' | 'pageGrants' | 'requestHook'
|
|
30
|
+
| 'startup' | 'responseHeaders' | 'reservedRoutes' | 'login';
|
|
31
|
+
type UnhandledOptionKey = Exclude<keyof DefineKitAppOptions, FileLayoutKey | ComposedOptionKey>;
|
|
32
|
+
type AssertNever<T extends never> = T;
|
|
33
|
+
type EveryOptionHasACompositionPolicy = AssertNever<UnhandledOptionKey>;
|
|
21
34
|
|
|
22
35
|
export interface ComposeKitAppsOptions {
|
|
23
36
|
/** 基座独占、叠加不得再写的选项键;缺省 auth / eventMiddleware / login */
|
|
@@ -34,14 +47,56 @@ export function mergeKitTables<T>(label: string, ...tables: ReadonlyArray<Readon
|
|
|
34
47
|
const dup: string[] = [];
|
|
35
48
|
for (const table of tables) {
|
|
36
49
|
for (const [name, value] of Object.entries(table ?? {})) {
|
|
37
|
-
if (name
|
|
38
|
-
else out
|
|
50
|
+
if (Object.hasOwn(out, name)) dup.push(name);
|
|
51
|
+
else Object.defineProperty(out, name, { value, enumerable: true, configurable: true, writable: true });
|
|
39
52
|
}
|
|
40
53
|
}
|
|
41
|
-
if (dup.length > 0)
|
|
54
|
+
if (dup.length > 0) kitFail('KIT-APP-012', label, `${label}重名:${[...new Set(dup)].join('、')}(不提供覆盖)`, '给叠加应用里的同名项改名');
|
|
42
55
|
return out;
|
|
43
56
|
}
|
|
44
57
|
|
|
58
|
+
function normalizeViewTable(views: DefineKitAppOptions['views'], side: string): Record<string, KitViewClass> {
|
|
59
|
+
const out: Record<string, KitViewClass> = {};
|
|
60
|
+
const entries: Array<[string | undefined, KitViewClass]> = Array.isArray(views)
|
|
61
|
+
? (views as readonly KitViewClass[]).map((cls) => [undefined, cls])
|
|
62
|
+
: Object.entries(views ?? {}) as Array<[string, KitViewClass]>;
|
|
63
|
+
for (const [declaredName, cls] of entries) {
|
|
64
|
+
const name = (cls as { viewName?: unknown } | null)?.viewName;
|
|
65
|
+
if (typeof name !== 'string' || name === '') {
|
|
66
|
+
kitFail('KIT-VIEW-005', `views.${String(declaredName ?? '')}`, `${side}的展示对象缺少有效 viewName`, '用 defineKitView 定义后再登记');
|
|
67
|
+
}
|
|
68
|
+
if (declaredName !== undefined && declaredName !== name) {
|
|
69
|
+
kitFail('KIT-VIEW-005', `views.${declaredName}`, `${side}展示对象登记名 ${declaredName} 与 viewName ${name} 不一致`, '登记键必须等于 defineKitView 的 viewName');
|
|
70
|
+
}
|
|
71
|
+
if (Object.hasOwn(out, name)) {
|
|
72
|
+
kitFail('KIT-VIEW-005', `views.${name}`, `${side}重复登记展示对象 ${name}`, '同一个展示对象只登记一次');
|
|
73
|
+
}
|
|
74
|
+
Object.defineProperty(out, name, { value: cls, enumerable: true, configurable: true, writable: true });
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function mergeKitPacks(base: DefineKitAppOptions['packs'], overlay: DefineKitAppOptions['packs']): NonNullable<DefineKitAppOptions['packs']> | undefined {
|
|
80
|
+
const out: NonNullable<DefineKitAppOptions['packs']>[number][] = [];
|
|
81
|
+
const byName = new Map<string, NonNullable<DefineKitAppOptions['packs']>[number]>();
|
|
82
|
+
for (const pack of [...(base ?? []), ...(overlay ?? [])]) {
|
|
83
|
+
if (pack === null || typeof pack !== 'object' || typeof pack.name !== 'string') {
|
|
84
|
+
out.push(pack);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const previous = byName.get(pack.name);
|
|
88
|
+
if (previous !== undefined) {
|
|
89
|
+
if (previous !== pack) {
|
|
90
|
+
kitFail('KIT-PACK-003', `packs.${pack.name}`, `领域包名 ${pack.name} 对应不同的包实例`, '基座与叠加应用的领域包名称不得冲突');
|
|
91
|
+
}
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
byName.set(pack.name, pack);
|
|
95
|
+
out.push(pack);
|
|
96
|
+
}
|
|
97
|
+
return out.length === 0 ? undefined : out;
|
|
98
|
+
}
|
|
99
|
+
|
|
45
100
|
/**
|
|
46
101
|
* 合并选项(不含 root / app / pagesDir / extraPagesDirs / services / defaultTheme:那几项取决于文件布局,由应用自己的装配补)。
|
|
47
102
|
* `base` 取自基座 `soma.app.ts` 默认导出的 `.options`,原样不改。
|
|
@@ -51,13 +106,14 @@ export function composeKitApps(base: DefineKitAppOptions, overlay: DefineKitAppO
|
|
|
51
106
|
const names = opts.names ?? { base: '基座', overlay: '叠加应用' };
|
|
52
107
|
const exclusive = opts.exclusive ?? ['auth', 'eventMiddleware', 'login'];
|
|
53
108
|
const bad = exclusive.filter((k) => overlay[k] !== undefined);
|
|
54
|
-
if (bad.length > 0) throw new
|
|
109
|
+
if (bad.length > 0) throw new KitDiagnosticError({ code: 'KIT-APP-012', path: bad.join(' / '), message: `${names.overlay}不得设置 ${bad.join(' / ')}:由${names.base}持有`, hint: `从${names.overlay}的 defineKitApp 选项里删掉 ${bad.join(' / ')}` }, tag);
|
|
55
110
|
|
|
56
111
|
const table = <T>(label: string, a: Readonly<Record<string, T>> | undefined, b: Readonly<Record<string, T>> | undefined): Record<string, T> => {
|
|
57
112
|
try {
|
|
58
113
|
return mergeKitTables(label, a, b);
|
|
59
114
|
} catch (e) {
|
|
60
|
-
|
|
115
|
+
const d = (e as KitDiagnosticError).diagnostics[0]!;
|
|
116
|
+
throw new KitDiagnosticError({ ...d, message: `${d.message}(${names.base}已登记同名项)` }, tag);
|
|
61
117
|
}
|
|
62
118
|
};
|
|
63
119
|
const merged: DefineKitAppOptions = {
|
|
@@ -66,13 +122,28 @@ export function composeKitApps(base: DefineKitAppOptions, overlay: DefineKitAppO
|
|
|
66
122
|
actions: table('具名动作', base.actions, overlay.actions),
|
|
67
123
|
bizComponents: table('业务组件', base.bizComponents, overlay.bizComponents),
|
|
68
124
|
frames: table('页面框', base.frames, overlay.frames),
|
|
125
|
+
dicts: table('共享字典', base.dicts, overlay.dicts),
|
|
126
|
+
entities: table('共享实体', base.entities, overlay.entities),
|
|
69
127
|
appCandidates: [...new Set([...(base.appCandidates ?? []), ...(overlay.appCandidates ?? [])])].sort(),
|
|
70
128
|
};
|
|
71
129
|
|
|
72
|
-
|
|
73
|
-
|
|
130
|
+
const views = table('展示对象', normalizeViewTable(base.views, names.base), normalizeViewTable(overlay.views, names.overlay));
|
|
131
|
+
if (Object.keys(views).length > 0) merged.views = views;
|
|
132
|
+
const packs = mergeKitPacks(base.packs, overlay.packs);
|
|
133
|
+
if (packs !== undefined) merged.packs = packs;
|
|
134
|
+
|
|
135
|
+
// 覆盖白名单只授权覆盖 kit 内置名;基座与叠加的声明并集去重,绝不授权覆盖对方登记项。
|
|
136
|
+
const overrides = [...new Set([...(base.overrides ?? []), ...(overlay.overrides ?? [])])];
|
|
74
137
|
if (overrides.length > 0) merged.overrides = overrides;
|
|
75
138
|
|
|
139
|
+
// 页面编译错误降级开关归叠加应用优先,显式 false 可关闭基座默认值。
|
|
140
|
+
const devFallback = overlay.devFallback !== undefined ? overlay.devFallback : base.devFallback;
|
|
141
|
+
if (devFallback !== undefined) merged.devFallback = devFallback;
|
|
142
|
+
|
|
143
|
+
// HTTP 默认超时:显式 0 有意义,只有 undefined 才继承基座。
|
|
144
|
+
const requestTimeout = overlay.requestTimeout !== undefined ? overlay.requestTimeout : base.requestTimeout;
|
|
145
|
+
if (requestTimeout !== undefined) merged.requestTimeout = requestTimeout;
|
|
146
|
+
|
|
76
147
|
// 基座独占面:原样取基座的
|
|
77
148
|
for (const k of exclusive) {
|
|
78
149
|
if (base[k] !== undefined) (merged as Record<string, unknown>)[k] = base[k];
|
|
@@ -146,7 +217,7 @@ export function createKitPermissionMiddleware(): SomaMiddlewareChain<SomaEventMi
|
|
|
146
217
|
if (typeof code === 'string' && code !== '' && !kitPermissionAllows(code)) {
|
|
147
218
|
context.status = 'blocked';
|
|
148
219
|
context.message = kitText('soma.kit.perm_denied', { code });
|
|
149
|
-
kitActionExtras().notify(context.message, 'danger');
|
|
220
|
+
kitActionExtras(context.element).notify(context.message, 'danger');
|
|
150
221
|
return;
|
|
151
222
|
}
|
|
152
223
|
await next();
|