soma-kit 0.1.12 → 0.1.14

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.
Files changed (300) hide show
  1. package/README.md +5 -4
  2. package/bin/soma-kit.mjs +31 -1
  3. package/bin/soma.mjs +0 -0
  4. package/package.json +5 -4
  5. package/spec/generated/kit-app.schema.json +172 -4
  6. package/spec/generated/kit-page.schema.json +164 -5
  7. package/spec/kit-grammar.json +598 -96
  8. package/spec/kit-grammar.schema.json +12 -6
  9. package/src/app/app-config.ts +92 -8
  10. package/src/app/component-gate.ts +271 -13
  11. package/src/app/define-kit-app.ts +2 -2
  12. package/src/app/define-kit-view.ts +9 -5
  13. package/src/app/dev-diagnostic.ts +5 -0
  14. package/src/app/index.ts +29 -5
  15. package/src/app/kit-view-context.ts +181 -15
  16. package/src/app/render-ports.ts +18 -0
  17. package/src/app/server-pages.ts +8 -2
  18. package/src/app/server.ts +55 -8
  19. package/src/app/theme-runtime.ts +4 -0
  20. package/src/base/action-busy.ts +101 -4
  21. package/src/base/action-slots.ts +13 -2
  22. package/src/base/anchored-layer.ts +50 -0
  23. package/src/base/button.ts +62 -15
  24. package/src/base/check-core.ts +8 -0
  25. package/src/base/checkbox.ts +2 -1
  26. package/src/base/choice.ts +21 -2
  27. package/src/base/color-picker.ts +10 -5
  28. package/src/base/command-palette.ts +1 -1
  29. package/src/base/context-menu.ts +10 -7
  30. package/src/base/date-range.ts +7 -7
  31. package/src/base/date.ts +55 -16
  32. package/src/base/delta.ts +72 -0
  33. package/src/base/end-edge.ts +61 -0
  34. package/src/base/fab.ts +1 -1
  35. package/src/base/gap-value.ts +168 -0
  36. package/src/base/hint-tips.ts +170 -0
  37. package/src/base/icons.ts +8 -0
  38. package/src/base/illustrations.ts +95 -0
  39. package/src/base/index.ts +32 -9
  40. package/src/base/listbox-core.ts +6 -5
  41. package/src/base/loading-gate.ts +140 -87
  42. package/src/base/mentions.ts +2 -1
  43. package/src/base/menu-button.ts +16 -18
  44. package/src/base/menu-core.ts +37 -8
  45. package/src/base/motion/hover-3d.ts +1 -1
  46. package/src/base/motion/marquee.ts +1 -1
  47. package/src/base/otp.ts +5 -4
  48. package/src/base/overlay-runtime.ts +235 -0
  49. package/src/base/popover.ts +10 -9
  50. package/src/base/popup.ts +67 -8
  51. package/src/base/portal-core.ts +4 -0
  52. package/src/base/qty-stepper.ts +5 -5
  53. package/src/base/radio.ts +2 -1
  54. package/src/base/range.ts +19 -2
  55. package/src/base/rating.ts +11 -6
  56. package/src/base/reason-tip.ts +150 -0
  57. package/src/base/segmented.ts +36 -24
  58. package/src/base/shared.ts +180 -36
  59. package/src/base/state-panel.ts +367 -0
  60. package/src/base/status-tone.ts +27 -0
  61. package/src/base/sticky-edge.ts +116 -0
  62. package/src/base/swap.ts +6 -6
  63. package/src/base/switch.ts +10 -5
  64. package/src/base/tag-input.ts +6 -6
  65. package/src/base/tag.ts +76 -41
  66. package/src/base/text.ts +43 -14
  67. package/src/base/time-picker.ts +7 -5
  68. package/src/base/tree-select.ts +6 -4
  69. package/src/base/trend-tone.ts +9 -0
  70. package/src/base/upload.ts +15 -9
  71. package/src/base/view-transition.ts +77 -0
  72. package/src/biz/approval-desk/shell.ts +15 -11
  73. package/src/biz/auth-panel/shell.ts +9 -7
  74. package/src/biz/category-crud/compile.ts +5 -4
  75. package/src/biz/category-crud/shell.ts +5 -3
  76. package/src/biz/checkout-page/compile.ts +2 -1
  77. package/src/biz/checkout-page/shell.ts +10 -8
  78. package/src/biz/compose.ts +2 -2
  79. package/src/biz/data-components.ts +4 -0
  80. package/src/biz/import-wizard/shell.ts +13 -10
  81. package/src/biz/landing-page/shell.ts +2 -2
  82. package/src/biz/link/hub.ts +23 -5
  83. package/src/biz/link/shared.ts +23 -12
  84. package/src/biz/master-sub/compile.ts +207 -16
  85. package/src/biz/master-sub/detail-head.ts +61 -0
  86. package/src/biz/master-sub/index.ts +7 -3
  87. package/src/biz/master-sub/shell.ts +133 -24
  88. package/src/biz/multi-board/compile.ts +167 -9
  89. package/src/biz/multi-board/composition.ts +58 -0
  90. package/src/biz/multi-board/index.ts +1 -1
  91. package/src/biz/multi-board/prose-fold.ts +143 -0
  92. package/src/biz/multi-board/shell.ts +94 -23
  93. package/src/biz/notification-center/shell.ts +10 -7
  94. package/src/biz/page-templates/domain-templates.ts +2 -2
  95. package/src/biz/page-templates/result-page/shell.ts +4 -3
  96. package/src/biz/page-templates/sign-in-page/shell.ts +16 -16
  97. package/src/biz/record-detail/compile.ts +2 -2
  98. package/src/biz/record-detail/shell.ts +13 -10
  99. package/src/biz/settings-center/compile.ts +2 -1
  100. package/src/biz/settings-center/shell.ts +12 -9
  101. package/src/biz/shared/action-host.ts +6 -0
  102. package/src/biz/shared/compile-helpers.ts +97 -0
  103. package/src/biz/shared/coordinator.ts +7 -30
  104. package/src/biz/shared/index.ts +5 -0
  105. package/src/biz/shared/object-aliases.ts +154 -0
  106. package/src/biz/shared/overlay-compile.ts +281 -0
  107. package/src/biz/shared/overlay-shell.ts +142 -11
  108. package/src/biz/shared/pipes.ts +11 -5
  109. package/src/biz/shared/remove-wire.ts +4 -19
  110. package/src/biz/shared/runtime-hub.ts +10 -0
  111. package/src/biz/single-form/compile.ts +3 -2
  112. package/src/biz/single-form/shell.ts +9 -6
  113. package/src/biz/standard-crud/compile.ts +36 -161
  114. package/src/biz/standard-crud/shell.ts +23 -60
  115. package/src/biz/standard-crud/summary.ts +40 -0
  116. package/src/biz/step-form/shell.ts +15 -13
  117. package/src/biz/types.ts +6 -1
  118. package/src/cli/kit-cli.ts +138 -13
  119. package/src/cli/kit-init.ts +6 -1
  120. package/src/cli/layout-cli.ts +167 -0
  121. package/src/cli/migrate/index.ts +10 -0
  122. package/src/cli/migrate/migrate.ts +248 -0
  123. package/src/cli/migrate/text-utils.ts +306 -0
  124. package/src/cli/migrate/theme-map.ts +104 -0
  125. package/src/cli/migrate/ts-rules.ts +235 -0
  126. package/src/cli/migrate/types.ts +95 -0
  127. package/src/cli/migrate/view-skeleton.ts +159 -0
  128. package/src/cli/migrate/yaml-report.ts +376 -0
  129. package/src/cli/migrate/yaml-rules.ts +465 -0
  130. package/src/cli/view-writes.ts +69 -60
  131. package/src/compile/access-gate-attach.ts +27 -0
  132. package/src/compile/closed-set.ts +65 -4
  133. package/src/compile/compile-page.ts +66 -11
  134. package/src/compile/component-candidates.ts +14 -1
  135. package/src/compile/fragment.ts +11 -0
  136. package/src/compile/layout-lint/engine.ts +82 -0
  137. package/src/compile/layout-lint/index.ts +55 -0
  138. package/src/compile/layout-lint/rules-composition.ts +267 -0
  139. package/src/compile/layout-lint/rules-form.ts +191 -0
  140. package/src/compile/layout-lint/rules-table.ts +278 -0
  141. package/src/compile/layout-lint/score.ts +52 -0
  142. package/src/compile/layout-lint/types.ts +51 -0
  143. package/src/compile/page-composition.ts +189 -0
  144. package/src/compile/parse.ts +4 -0
  145. package/src/compile/producer-fingerprint.ts +56 -0
  146. package/src/compile/remove-guard.ts +10 -7
  147. package/src/compile/styles.ts +46 -8
  148. package/src/compile/types.ts +16 -2
  149. package/src/compile/view-check.ts +149 -16
  150. package/src/data/access-gate.ts +112 -0
  151. package/src/data/amount-breakdown.ts +9 -2
  152. package/src/data/approval-flow.ts +5 -2
  153. package/src/data/assignment-picker.ts +59 -28
  154. package/src/data/async-result-panel.ts +49 -3
  155. package/src/data/breadcrumbs.ts +3 -2
  156. package/src/data/calendar.ts +8 -3
  157. package/src/data/carousel.ts +10 -6
  158. package/src/data/chart.ts +744 -46
  159. package/src/data/checklist.ts +22 -6
  160. package/src/data/code-view.ts +8 -4
  161. package/src/data/comment-thread.ts +3 -2
  162. package/src/data/confirm-dialog.ts +72 -25
  163. package/src/data/context-menu.ts +3 -3
  164. package/src/data/dock.ts +1 -1
  165. package/src/data/embed.ts +231 -29
  166. package/src/data/field-mapper.ts +7 -4
  167. package/src/data/flow-editor-contract.ts +7 -0
  168. package/src/data/flow-editor.ts +26 -9
  169. package/src/data/flow-node-options.ts +33 -3
  170. package/src/data/footer.ts +2 -0
  171. package/src/data/gantt.ts +192 -27
  172. package/src/data/hero.ts +4 -1
  173. package/src/data/image-viewer.ts +7 -4
  174. package/src/data/index.ts +16 -4
  175. package/src/data/item-list.ts +27 -12
  176. package/src/data/kanban.ts +41 -10
  177. package/src/data/matrix.ts +391 -0
  178. package/src/data/media-grid.ts +6 -1
  179. package/src/data/mega-menu.ts +6 -4
  180. package/src/data/menu-dom.ts +4 -2
  181. package/src/data/menu.ts +60 -16
  182. package/src/data/mockup.ts +5 -1
  183. package/src/data/modal-dialog.ts +146 -26
  184. package/src/data/navbar.ts +8 -6
  185. package/src/data/notice-list.ts +301 -0
  186. package/src/data/notify-renderer.ts +21 -6
  187. package/src/data/object-form.ts +409 -87
  188. package/src/data/outcome-watch.ts +61 -2
  189. package/src/data/pager.ts +19 -8
  190. package/src/data/panel-head.ts +406 -0
  191. package/src/data/permission-matrix.ts +36 -11
  192. package/src/data/permission-tree.ts +52 -23
  193. package/src/data/pricing-table.ts +22 -11
  194. package/src/data/prompt-dialog.ts +165 -0
  195. package/src/data/reaction-bar.ts +6 -4
  196. package/src/data/record-card.ts +40 -7
  197. package/src/data/record-picker.ts +13 -7
  198. package/src/data/resident.ts +8 -0
  199. package/src/data/result-panel.ts +4 -2
  200. package/src/data/rich-text.ts +17 -1
  201. package/src/data/row-editor.ts +77 -24
  202. package/src/data/rule-builder.ts +14 -9
  203. package/src/data/shape-util.ts +27 -12
  204. package/src/data/stat-group.ts +459 -74
  205. package/src/data/static-lazy.ts +5 -0
  206. package/src/data/static-registry.ts +8 -0
  207. package/src/data/steps.ts +8 -3
  208. package/src/data/survey.ts +7 -4
  209. package/src/data/system-switcher.ts +3 -2
  210. package/src/data/text-action-button.ts +17 -0
  211. package/src/data/timeline.ts +17 -6
  212. package/src/data/tour-guide.ts +3 -2
  213. package/src/data/transfer.ts +40 -16
  214. package/src/data/tree-table.ts +65 -37
  215. package/src/data/tree.ts +22 -2
  216. package/src/data/virtual-rows.ts +21 -11
  217. package/src/data/wrapped-candidates.ts +32 -1
  218. package/src/frames/index.ts +1 -0
  219. package/src/frames/list-summary.ts +100 -0
  220. package/src/frames/page-bar.ts +7 -14
  221. package/src/frames/page-status.ts +7 -5
  222. package/src/frames/shared.ts +34 -13
  223. package/src/frames/split-frame/shell.ts +1 -1
  224. package/src/frames/tabs-frame/shell.ts +9 -6
  225. package/src/frames/tabs-frame/wiring.ts +1 -0
  226. package/src/frames/top-main-frame.ts +3 -3
  227. package/src/frames/types.ts +3 -1
  228. package/src/frames/workspace-frame/extras.ts +1 -1
  229. package/src/frames/workspace-frame/shell.ts +4 -4
  230. package/src/frames/workspace-frame/tab-scroll.ts +28 -0
  231. package/src/frames/workspace-frame/view.ts +168 -44
  232. package/src/generated/kit-grammar-runtime.ts +390 -59
  233. package/src/i18n/kit-text.ts +90 -4
  234. package/src/i18n/resolve-text-refs.ts +22 -6
  235. package/src/object-renderer/action-group.ts +139 -0
  236. package/src/object-renderer/action-more.ts +144 -0
  237. package/src/object-renderer/arrange.ts +71 -7
  238. package/src/object-renderer/candidates.ts +4 -0
  239. package/src/object-renderer/collection-parts.ts +264 -62
  240. package/src/object-renderer/collection-table.ts +177 -5
  241. package/src/object-renderer/collection.ts +188 -37
  242. package/src/object-renderer/compile-data.ts +28 -3
  243. package/src/object-renderer/defaults.ts +27 -2
  244. package/src/object-renderer/display-checks.ts +1 -1
  245. package/src/object-renderer/emit-events.ts +43 -9
  246. package/src/object-renderer/emit-object.ts +4 -0
  247. package/src/object-renderer/emit-static.ts +434 -41
  248. package/src/object-renderer/filter-plan.ts +84 -0
  249. package/src/object-renderer/form-detail.ts +1 -2
  250. package/src/object-renderer/form-notify.ts +45 -0
  251. package/src/object-renderer/index.ts +5 -0
  252. package/src/object-renderer/layout-facts.ts +394 -0
  253. package/src/object-renderer/layout-plan.ts +225 -0
  254. package/src/object-renderer/layout-plan.types.ts +59 -0
  255. package/src/object-renderer/parts.ts +6 -7
  256. package/src/object-renderer/render-object.ts +107 -46
  257. package/src/object-renderer/request-actions.ts +4 -2
  258. package/src/object-renderer/skeleton.ts +58 -19
  259. package/src/object-renderer/table-actions.ts +172 -32
  260. package/src/object-renderer/table-gap.ts +37 -0
  261. package/src/object-renderer/table-tools.ts +62 -30
  262. package/src/object-renderer/types.ts +84 -13
  263. package/src/object-renderer/view-binding.ts +205 -8
  264. package/src/page-target/intent-schema.ts +11 -0
  265. package/src/page-target/target.ts +5 -1
  266. package/src/recipes/container.ts +77 -1
  267. package/src/recipes/control.ts +76 -116
  268. package/src/recipes/emphasis.ts +56 -0
  269. package/src/recipes/frame-bleed.ts +33 -0
  270. package/src/recipes/index.ts +72 -0
  271. package/src/recipes/nowrap.ts +16 -0
  272. package/src/recipes/overlay.ts +120 -17
  273. package/src/recipes/placeholder.ts +95 -0
  274. package/src/recipes/rail-grid.ts +48 -0
  275. package/src/recipes/slot-align.ts +56 -0
  276. package/src/recipes/stat-state.ts +65 -0
  277. package/src/recipes/state.ts +40 -21
  278. package/src/recipes/status.ts +147 -0
  279. package/src/recipes/surface-edge.ts +16 -0
  280. package/src/recipes/surface.ts +40 -0
  281. package/src/recipes/table-gap.ts +80 -0
  282. package/src/recipes/table-native-edit.ts +242 -0
  283. package/src/recipes/table-row.ts +146 -3
  284. package/src/recipes/tabs.ts +49 -0
  285. package/src/recipes/title-row.ts +37 -0
  286. package/src/recipes/typography.ts +30 -37
  287. package/src/shared/confirm-decl.ts +118 -0
  288. package/src/shared/envelope.ts +2 -2
  289. package/src/shared/paged-list-adapter.ts +15 -240
  290. package/src/shared/theme-runtime-shared.ts +6 -1
  291. package/src/theme/index.ts +1 -0
  292. package/src/theme/kit-theme-text.ts +1 -1
  293. package/src/theme/kit-theme.css +384 -13
  294. package/src/theme/kit-theme.tpl +384 -13
  295. package/src/theme/nine-dim-structure.ts +244 -7
  296. package/src/theme/surface-layers.ts +10 -1
  297. package/src/theme/theme-tokens.ts +63 -16
  298. package/src/theme/theme-types.ts +32 -0
  299. package/src/theme/typography.ts +21 -17
  300. package/src/biz/shared/remove-key.ts +0 -6
@@ -0,0 +1,82 @@
1
+ // 布局体检引擎(RV-1117 T05):39 条气味规则 → advisories 通道。
2
+ // 严重级与建议文案读真源 kit-layout.json#smells.catalog(human / ai 两档,off = 该档案下不适用);规则只给「位置 + 问题」,三段式的「建议」取 catalog.fix。
3
+ // 与 diagnostics 并行:engine 不产 diagnostics,`ok` 契约由调用方保持不变。纯函数、确定(同输入同输出、按 码 → 路径 排序)。
4
+
5
+ import { KIT_LAYOUT_SMELLS } from 'soma-foundation/kit-layout';
6
+ import type { KitAdvisory, KitAdvisorySeverity } from '../../object-renderer/types';
7
+ import type { KitPageFacts } from '../../object-renderer/layout-facts';
8
+ import type { KitLayoutPlan } from '../../object-renderer/layout-plan.types';
9
+ import { COMPOSITION_SMELL_RULES } from './rules-composition';
10
+ import { FORM_SMELL_RULES } from './rules-form';
11
+ import { TABLE_SMELL_RULES } from './rules-table';
12
+ import type { KitLintInput, KitLintProfile, KitSmellRule } from './types';
13
+
14
+ type CatalogEntry = { readonly id: string; readonly name: string; readonly severity: { readonly human: string; readonly ai: string }; readonly fix: string };
15
+ const CATALOG = KIT_LAYOUT_SMELLS.catalog as unknown as Readonly<Record<string, CatalogEntry>>;
16
+
17
+ /** 编号 → 规则;与 catalog 一一对应(测试对账:缺规则或缺目录条目都红)。 */
18
+ export const KIT_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = { ...TABLE_SMELL_RULES, ...FORM_SMELL_RULES, ...COMPOSITION_SMELL_RULES };
19
+
20
+ /** 全部气味编号(升序)。 */
21
+ export const KIT_SMELL_CODES: readonly string[] = Object.keys(CATALOG).sort();
22
+
23
+ export interface KitLintOptions {
24
+ readonly profile?: KitLintProfile;
25
+ /** 行内豁免(页面源里的 `# kit-layout-ignore KIT-LAYOUT-0xx: 原因`):被豁免的码不产出,并记入 ignored(棘轮只减不增) */
26
+ readonly ignore?: ReadonlyMap<string, string>;
27
+ }
28
+
29
+ export interface KitLintResult {
30
+ readonly advisories: KitAdvisory[];
31
+ /** 被豁免的码 → 原因 */
32
+ readonly ignored: ReadonlyArray<{ readonly code: string; readonly reason: string }>;
33
+ }
34
+
35
+ const SEVERITIES: readonly string[] = ['error', 'warn', 'advice'];
36
+
37
+ /** 该档案下某条气味的严重级;off(不适用)返回 undefined。 */
38
+ export function smellSeverityOf(code: string, profile: KitLintProfile): KitAdvisorySeverity | undefined {
39
+ const entry = CATALOG[code];
40
+ if (entry === undefined) return undefined;
41
+ const level = entry.severity[profile];
42
+ return SEVERITIES.includes(level) ? (level as KitAdvisorySeverity) : undefined;
43
+ }
44
+
45
+ /** 跑全部规则:facts + plan → advisories。 */
46
+ export function lintKitPageLayout(facts: KitPageFacts, plan: KitLayoutPlan, options?: KitLintOptions): KitLintResult {
47
+ const profile = options?.profile ?? 'human';
48
+ const input: KitLintInput = { facts, plan, profile };
49
+ const advisories: KitAdvisory[] = [];
50
+ const ignored: Array<{ code: string; reason: string }> = [];
51
+ for (const code of KIT_SMELL_CODES) {
52
+ const base = smellSeverityOf(code, profile);
53
+ if (base === undefined) continue;
54
+ const entry = CATALOG[code] as CatalogEntry;
55
+ if (options?.ignore?.has(entry.id) === true) {
56
+ ignored.push({ code: entry.id, reason: options.ignore.get(entry.id) as string });
57
+ continue;
58
+ }
59
+ const rule = KIT_SMELL_RULES[code];
60
+ if (rule === undefined) continue;
61
+ let findings;
62
+ try {
63
+ findings = rule(input);
64
+ } catch {
65
+ continue; // 体检是旁路:一条规则读到异常形状的事实时跳过,不让页面编译失败
66
+ }
67
+ for (const f of findings) advisories.push({ code: entry.id, severity: f.severity ?? base, path: f.path, message: f.message, hint: entry.fix });
68
+ }
69
+ advisories.sort((a, b) => (a.code < b.code ? -1 : a.code > b.code ? 1 : a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
70
+ return { advisories, ignored };
71
+ }
72
+
73
+ /** 页面源里的行内豁免:`# kit-layout-ignore KIT-LAYOUT-0xx: 原因`(按码在整页生效;原因必填)。 */
74
+ export function extractLayoutIgnores(source: string): Map<string, string> {
75
+ const out = new Map<string, string>();
76
+ const re = /#\s*kit-layout-ignore\s+(KIT-LAYOUT-\d{3})[ \t]*:[ \t]*(\S.*)$/gm;
77
+ for (const m of source.matchAll(re)) out.set(m[1] as string, (m[2] as string).trim());
78
+ return out;
79
+ }
80
+
81
+ /** 严重级排序权重(error > warn > advice),供 CLI 汇总。 */
82
+ export const ADVISORY_SEVERITY_ORDER: Readonly<Record<KitAdvisorySeverity, number>> = { error: 0, warn: 1, advice: 2 };
@@ -0,0 +1,55 @@
1
+ // 布局体检(RV-1117 T05):对页面声明 + 影子规划判 KIT-LAYOUT-001…039,产出 advisories(与 diagnostics 并行的新通道)。
2
+ // 入口:`analyzeKitPageLayout(decl, options)` = 事实适配 → 规划 → 体检 → 质量分;规则表 / 严重级 / 建议文案 / 分数权重读真源 kit-layout.json
3
+ // (KIT_LAYOUT_SMELLS,soma-foundation/kit-layout 生成投影),代码里不抄数字。
4
+
5
+ import { KIT_LAYOUT_SMELLS } from 'soma-foundation/kit-layout';
6
+ import type { KitPageDecl } from '../types';
7
+ import { extractKitPageFacts } from '../../object-renderer/layout-facts';
8
+ import { planKitPageLayout } from '../../object-renderer/layout-plan';
9
+ import type { KitLayoutPlan } from '../../object-renderer/layout-plan.types';
10
+ import type { KitAdvisory } from '../../object-renderer/types';
11
+ import { extractLayoutIgnores, lintKitPageLayout, type KitLintResult } from './engine';
12
+ import { scoreKitPage, type KitQualityScoreResult } from './score';
13
+ import type { KitLintProfile } from './types';
14
+
15
+ export { ADVISORY_SEVERITY_ORDER, KIT_SMELL_CODES, KIT_SMELL_RULES, extractLayoutIgnores, lintKitPageLayout, smellSeverityOf } from './engine';
16
+ export type { KitLintOptions, KitLintResult } from './engine';
17
+ export { meetsAiAcceptLine, scoreKitPage } from './score';
18
+ export type { KitQualityScoreResult } from './score';
19
+ export type { KitLintProfile } from './types';
20
+
21
+ /** 真源里的气味目录(编号 → 目录条目)。 */
22
+ export const KIT_SMELL_CATALOG = KIT_LAYOUT_SMELLS.catalog;
23
+
24
+ export interface KitLayoutAnalysisOptions {
25
+ /** 应用钉的规则版本(缺省 0) */
26
+ readonly rules?: number;
27
+ /** 页面源文本(用来读行内豁免);缺省不豁免 */
28
+ readonly source?: string;
29
+ }
30
+
31
+ /** 一个档案下的体检结果。 */
32
+ export interface KitLayoutProfileReport {
33
+ readonly advisories: KitAdvisory[];
34
+ readonly ignored: KitLintResult['ignored'];
35
+ readonly score: KitQualityScoreResult;
36
+ }
37
+
38
+ /** 一页的布局报告:影子规划 + 两个档案(human / ai)各一份体检与质量分。 */
39
+ export interface KitLayoutReport {
40
+ readonly plan: KitLayoutPlan;
41
+ readonly human: KitLayoutProfileReport;
42
+ readonly ai: KitLayoutProfileReport;
43
+ }
44
+
45
+ /** 页面声明 → 布局报告。纯函数;任何内部异常都由调用方(compile-page 的旁路)兜住。 */
46
+ export function analyzeKitPageLayout(decl: KitPageDecl, options?: KitLayoutAnalysisOptions): KitLayoutReport {
47
+ const facts = extractKitPageFacts(decl);
48
+ const plan = planKitPageLayout(facts, options?.rules === undefined ? undefined : { rules: options.rules });
49
+ const ignore = options?.source === undefined ? undefined : extractLayoutIgnores(options.source);
50
+ const report = (profile: KitLintProfile): KitLayoutProfileReport => {
51
+ const linted = lintKitPageLayout(facts, plan, { profile, ...(ignore !== undefined ? { ignore } : {}) });
52
+ return { advisories: linted.advisories, ignored: linted.ignored, score: scoreKitPage(linted.advisories) };
53
+ };
54
+ return { plan, human: report('human'), ai: report('ai') };
55
+ }
@@ -0,0 +1,267 @@
1
+ // 布局体检 · 页面组合与「AI 式装饰」类气味(026–036、038、039)。谓词全部静态,阈值与词表读 KIT_LAYOUT_SMELLS。
2
+ // AI 式装饰:统计卡压在表格上方(026 / 027)、标题加副标题的信息块(028 / 029)、符号前缀标签(031 / 038)、
3
+ // 展示型大图标卡(030)、卡片套卡片(032)、强调滥用(035)。
4
+
5
+ import { KIT_LAYOUT_SMELLS } from 'soma-foundation/kit-layout';
6
+ import type { KitFactObject, KitFactView } from '../../object-renderer/layout-facts';
7
+ import { boardCompositionNodes, composeBoard } from '../../biz/multi-board/composition';
8
+ import { allFieldsOf, viewSites, type KitSmellFinding, type KitSmellRule } from './types';
9
+
10
+ const C = KIT_LAYOUT_SMELLS.catalog;
11
+
12
+ const isMetricObject = (o: KitFactObject): boolean => o.isPanel && o.panelKind === 'metric';
13
+ const isTableObject = (o: KitFactObject): boolean => o.views.some((v) => v.slot === 'list' && v.staticComponent === null && (v.collection === 'table' || v.collection === 'treeTable'));
14
+
15
+ /** 页面里按声明序展平的全部对象(槽序 × 产品内对象序)。 */
16
+ function orderedObjects(input: Parameters<KitSmellRule>[0]): KitFactObject[] {
17
+ return input.facts.products.flatMap((p) => p.objects);
18
+ }
19
+
20
+ const r026: KitSmellRule = (input) => {
21
+ const objects = orderedObjects(input);
22
+ const firstTable = objects.findIndex(isTableObject);
23
+ if (firstTable < 0) return []; // 页面没有表格面板:真看板,不报
24
+ const out: KitSmellFinding[] = [];
25
+ objects.forEach((o, i) => {
26
+ if (i >= firstTable || !isMetricObject(o)) return;
27
+ const items = o.views.flatMap((v) => v.staticItems ?? []);
28
+ const hasTrend = items.some((it) => it.hasTrend);
29
+ const hasAction = o.views.some((v) => v.hasOn) || o.actions.length > 0;
30
+ if (!hasTrend && !hasAction) out.push({ path: o.path, message: `统计卡「${o.title ?? o.name ?? ''}」压在表格上方,且统计项没有环比趋势、也没有关联动作` });
31
+ });
32
+ return out;
33
+ };
34
+
35
+ const r027: KitSmellRule = (input) => {
36
+ const out: KitSmellFinding[] = [];
37
+ const max = C['027'].params.itemsMax;
38
+ for (const o of orderedObjects(input)) {
39
+ for (const v of o.views) if (v.staticItems !== null && v.staticItems.length > max) out.push({ path: `${v.path}.props.items`, message: `统计组有 ${v.staticItems.length} 项(超过 ${max})` });
40
+ }
41
+ return out;
42
+ };
43
+
44
+ const bigrams = (s: string): Set<string> => {
45
+ const chars = [...s.replace(/\s+/g, '')];
46
+ const out = new Set<string>();
47
+ for (let i = 0; i < chars.length - 1; i += 1) out.add(`${chars[i]}${chars[i + 1]}`);
48
+ if (chars.length === 1) out.add(chars[0] as string);
49
+ return out;
50
+ };
51
+ const jaccard = (a: string, b: string): number => {
52
+ const x = bigrams(a);
53
+ const y = bigrams(b);
54
+ if (x.size === 0 || y.size === 0) return 0;
55
+ let inter = 0;
56
+ for (const g of x) if (y.has(g)) inter += 1;
57
+ return inter / (x.size + y.size - inter);
58
+ };
59
+
60
+ const r028: KitSmellRule = (input) => {
61
+ const { title, subtitle } = input.facts;
62
+ if (subtitle === null || subtitle.trim() === '') return [];
63
+ const dup = subtitle.includes(title) || jaccard(title, subtitle) > C['028'].params.jaccardMin;
64
+ if (dup) return [{ path: 'page.subtitle', message: `副标题「${subtitle}」只是在复述标题「${title}」` }];
65
+ // 负责人裁决:不设长度阈值;人写页对任何副标题给一条「不要写副标题」的建议,AI 页不对非重复副标题发声
66
+ return input.profile === 'human' ? [{ path: 'page.subtitle', message: '页面写了副标题;标题已说清用途的页面不需要副标题', severity: 'advice' }] : [];
67
+ };
68
+
69
+ const r029: KitSmellRule = (input) => {
70
+ const title = input.facts.title.trim();
71
+ return orderedObjects(input).filter((o) => o.isPanel && o.title !== null && o.title.trim() === title).map((o) => ({ path: `${o.path}.title`, message: `面板标题「${o.title ?? ''}」与页面标题相同` }));
72
+ };
73
+
74
+ const r030: KitSmellRule = (input) => {
75
+ if (input.facts.frameKind === 'blank-frame') return [];
76
+ const showpieces: readonly string[] = KIT_LAYOUT_SMELLS.showpieceComponents;
77
+ const out: KitSmellFinding[] = [];
78
+ for (const o of orderedObjects(input)) {
79
+ for (const v of o.views) {
80
+ if (v.staticComponent !== null && showpieces.includes(v.staticComponent)) out.push({ path: `${v.path}.staticComponent`, message: `业务页(${input.facts.frameKind})里放了展示型组件 ${v.staticComponent}` });
81
+ for (const f of allFieldsOf(v)) if (f.component !== undefined && showpieces.includes(f.component)) out.push({ path: f.path, message: `业务页里放了展示型组件 ${f.component}` });
82
+ }
83
+ }
84
+ return out;
85
+ };
86
+
87
+ const r031: KitSmellRule = (input) => {
88
+ const symbol = new RegExp(KIT_LAYOUT_SMELLS.symbolPattern, 'u');
89
+ const out: KitSmellFinding[] = [];
90
+ const check = (text: string | null | undefined, path: string, what: string): void => {
91
+ if (text === null || text === undefined) return;
92
+ const m = symbol.exec(text);
93
+ if (m !== null) out.push({ path, message: `${what}「${text}」含符号前缀 ${m[0]}` });
94
+ };
95
+ check(input.facts.title, 'page.title', '页面标题');
96
+ const seen = new Set<string>();
97
+ for (const o of orderedObjects(input)) {
98
+ check(o.title, `${o.path}.title`, '标题');
99
+ for (const a of o.actions) check(a.name, a.path, '动作名');
100
+ for (const v of o.views) {
101
+ for (const f of allFieldsOf(v)) {
102
+ const key = `${o.path}.${f.name}`;
103
+ if (seen.has(key)) continue;
104
+ seen.add(key);
105
+ check(f.label, f.path, '字段名');
106
+ }
107
+ }
108
+ }
109
+ return out;
110
+ };
111
+
112
+ /** 表面嵌套深度:显式 surface: card 的层数 + 面板外壳 + 表格自带外框(规则版本 ≥ 1 下面板内表格自动贴边,不计)。 */
113
+ function surfaceDepth(input: Parameters<KitSmellRule>[0], productSurface: string | null, o: KitFactObject, v: KitFactView): number {
114
+ let depth = 0;
115
+ if (productSurface === 'card') depth += 1;
116
+ if (o.isPanel && o.surface !== 'flush' && o.surface !== 'plain') depth += 1;
117
+ if (o.surface === 'card') depth += 1;
118
+ if (v.surface === 'card') depth += 1;
119
+ if (v.groups.some((g) => g.surface === 'card')) depth += 1;
120
+ const tableFrame = v.slot === 'list' && v.collection === 'table' && v.staticComponent === null && o.surface !== 'flush' && o.surface !== 'plain' && v.surface !== 'flush' && v.surface !== 'plain';
121
+ if (tableFrame && !(o.isPanel && input.plan.rules >= 1)) depth += 1;
122
+ return depth;
123
+ }
124
+
125
+ const r032: KitSmellRule = (input) => {
126
+ const out: KitSmellFinding[] = [];
127
+ const max = C['032'].params.nestingMax;
128
+ for (const s of viewSites(input.facts)) {
129
+ const depth = surfaceDepth(input, s.product.surface, s.object, s.view);
130
+ if (depth > max) out.push({ path: s.view.path, message: `表面嵌套 ${depth} 层(上限 ${max}):外层卡片里又套了卡片 / 带框的表格` });
131
+ }
132
+ return out;
133
+ };
134
+
135
+ const r033: KitSmellRule = (input) => {
136
+ const out: KitSmellFinding[] = [];
137
+ for (const [path, plan] of Object.entries(input.plan.panels)) {
138
+ plan.shortRows.forEach((i) => {
139
+ const row = plan.rows[i] ?? [];
140
+ out.push({ path, message: `第 ${i + 1} 行面板的 span 之和是 ${row.reduce((a, c) => a + c.span, 0)},不是 12(${row.map((c) => `${c.id}:${c.span}`).join('、')})` });
141
+ });
142
+ }
143
+ return out;
144
+ };
145
+
146
+ /** 面板事实 → 构件名(写死形状组件名优先;否则按面板形态:统计 = StatGroup、图 = Chart、其余 = 集合);应用组件角色体检期取缺省 subject */
147
+ const kindOfFact = (o: KitFactObject): string => {
148
+ const sc = o.views.find((v) => v.staticComponent !== null && v.staticComponent !== undefined)?.staticComponent;
149
+ if (typeof sc === 'string' && sc !== '') return sc;
150
+ return o.panelKind === 'metric' ? 'StatGroup' : o.panelKind === 'chart' ? 'Chart' : 'collection';
151
+ };
152
+
153
+ /** 每个多面板产品的构成分析(与编译同一函数 solveComposition);没有面板的产品跳过 */
154
+ const compositionOf = (input: Parameters<KitSmellRule>[0]): Array<{ path: string; plan: ReturnType<typeof composeBoard>; names: Map<string, KitFactObject> }> => {
155
+ const out: Array<{ path: string; plan: ReturnType<typeof composeBoard>; names: Map<string, KitFactObject> }> = [];
156
+ for (const pr of input.facts.products) {
157
+ const panels = pr.objects.filter((o) => o.isPanel);
158
+ if (panels.length === 0) continue;
159
+ const names = new Map<string, KitFactObject>();
160
+ const nodes = boardCompositionNodes(panels.map((o, i) => {
161
+ const name = o.name ?? `panel${i}`;
162
+ names.set(name, o);
163
+ return { name, kind: kindOfFact(o), group: o.panelGroup ?? '', head: o.panelHead ?? '', span: o.panelSpan ?? undefined };
164
+ }));
165
+ out.push({ path: pr.path, plan: composeBoard(nodes), names });
166
+ }
167
+ return out;
168
+ };
169
+
170
+ // KIT-LAYOUT-041 顶层主体过多须分组:按构成分析的「主体」数(概况 / 控件 / 说明与被附着者不计),分区(未分组区、每个 group 页签)各自超过上限就报(取代旧 034 的数面板)
171
+ const r041: KitSmellRule = (input) => {
172
+ const out: KitSmellFinding[] = [];
173
+ const p = C['041'].params;
174
+ for (const c of compositionOf(input)) {
175
+ const n = c.plan.needsGroup;
176
+ if (n !== undefined && n !== null) out.push({ path: 'frame', message: `页面顶层有 ${n.subjects} 个主体(超过 ${p.subjectsMax});按主题写 group 把主体收进页内页签,首屏只留结论与主体` });
177
+ }
178
+ if (input.facts.tabsDepth > p.tabsNestMax) out.push({ path: 'frame', message: `页签嵌套 ${input.facts.tabsDepth} 层(超过 ${p.tabsNestMax})` });
179
+ return out;
180
+ };
181
+
182
+ // KIT-LAYOUT-042 控件或说明找不到宿主:它们不独立成块,同一分区里没有主体可附着时被迫落在页头一行
183
+ const r042: KitSmellRule = (input) => {
184
+ const out: KitSmellFinding[] = [];
185
+ for (const c of compositionOf(input)) {
186
+ for (const d of c.plan.diagnostics) {
187
+ if (d.code !== 'control-orphan') continue;
188
+ for (const id of d.ids) out.push({ path: c.names.get(id)?.path ?? c.path, message: `控件 / 说明「${id}」找不到宿主主体(同一页签里没有它控制或说明的面板)` });
189
+ }
190
+ }
191
+ return out;
192
+ };
193
+
194
+ const r035: KitSmellRule = (input) => {
195
+ const out: KitSmellFinding[] = [];
196
+ const p = C['035'].params;
197
+ for (const s of viewSites(input.facts)) {
198
+ const fields = allFieldsOf(s.view);
199
+ const strong = fields.filter((f) => f.emphasis === 'strong' || f.highlight);
200
+ if (strong.length > p.strongMax || (strong.length >= 2 && strong.length / fields.length > p.strongShareMax)) {
201
+ out.push({ path: s.view.path, message: `${strong.length}/${fields.length} 个字段写了 emphasis: strong 或 highlight(${strong.map((f) => f.label).join('、')})` });
202
+ }
203
+ }
204
+ return out;
205
+ };
206
+
207
+ const r036: KitSmellRule = (input) => {
208
+ const re = new RegExp(KIT_LAYOUT_SMELLS.classPattern);
209
+ const decoration = new RegExp(KIT_LAYOUT_SMELLS.decorationClassPattern);
210
+ // frame.class 里的纯内边距清零类(p-0 / px-0 …):由 frame.bleed 语义键替代(正则在真源 kit-layout.json#smells.framePaddingResetPattern)
211
+ const frameReset = new RegExp(KIT_LAYOUT_SMELLS.framePaddingResetPattern);
212
+ const out: KitSmellFinding[] = [];
213
+ const sites: Array<{ key: string; value: string; path: string }> = [...input.facts.frameClasses];
214
+ const framePaths = new Set(input.facts.frameClasses.map((f) => f.path));
215
+ for (const p of input.facts.products) {
216
+ sites.push(...p.classes);
217
+ for (const o of p.objects) {
218
+ sites.push(...o.classes);
219
+ for (const v of o.views) {
220
+ sites.push(...v.classes);
221
+ for (const f of allFieldsOf(v)) sites.push(...f.classes);
222
+ }
223
+ }
224
+ }
225
+ const seen = new Set<string>();
226
+ for (const site of sites) {
227
+ if (seen.has(site.path)) continue;
228
+ seen.add(site.path);
229
+ if (site.key === 'areaClass.panel' && decoration.test(site.value)) continue; // 039 专报
230
+ if (re.test(site.value)) {
231
+ const base = `手写样式类「${site.value}」含尺寸 / 间距 / 颜色 / 栅格族`;
232
+ // 版心:手写 max-w-* 做内容限宽 → 语义键 page.max_width(档位 narrow / medium / wide / xwide=1440px / full,值在 kit-grammar.json#pageHeader.maxWidths)
233
+ const widthHint = site.key === 'class' && framePaths.has(site.path) && /(^|\s)max-w-\S+/.test(site.value)
234
+ ? ';页面版心请写 page.max_width(narrow / medium / wide / xwide=1440px / full),不要手写 max-w-*' : '';
235
+ out.push({ path: site.path, message: site.key === 'class' && framePaths.has(site.path) && frameReset.test(site.value) ? `${base};内容要顶满内容区请写 frame.bleed: true,不要用 frame.class 清零内边距` : `${base}${widthHint}` });
236
+ }
237
+ }
238
+ return out;
239
+ };
240
+
241
+ const r038: KitSmellRule = (input) => {
242
+ const out: KitSmellFinding[] = [];
243
+ const seen = new Set<string>();
244
+ for (const s of viewSites(input.facts)) {
245
+ for (const f of allFieldsOf(s.view)) {
246
+ const key = `${s.object.path}.${f.name}`;
247
+ if (f.optionLabelsWithSymbol.length === 0 || seen.has(key)) continue;
248
+ seen.add(key);
249
+ out.push({ path: f.path, message: `「${f.label}」的选项标签带符号前缀:${f.optionLabelsWithSymbol.join('、')}` });
250
+ }
251
+ }
252
+ return out;
253
+ };
254
+
255
+ const r039: KitSmellRule = (input) => {
256
+ const decoration = new RegExp(KIT_LAYOUT_SMELLS.decorationClassPattern);
257
+ const out: KitSmellFinding[] = [];
258
+ for (const p of input.facts.products) {
259
+ for (const c of p.classes) if (c.key === 'areaClass.panel' && decoration.test(c.value)) out.push({ path: c.path, message: `areaClass.panel「${c.value}」手写去掉卡片外观` });
260
+ }
261
+ return out;
262
+ };
263
+
264
+ export const COMPOSITION_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
265
+ '026': r026, '027': r027, '028': r028, '029': r029, '030': r030, '031': r031, '032': r032, '033': r033,
266
+ '035': r035, '036': r036, '038': r038, '039': r039, '041': r041, '042': r042,
267
+ };
@@ -0,0 +1,191 @@
1
+ // 布局体检 · 表单 / 筛选 / 详情类气味(014–025、037)。谓词全部静态,阈值读 KIT_LAYOUT_SMELLS。
2
+
3
+ import { KIT_ARRANGE, arrangeFilter } from 'soma-foundation/arrange';
4
+ import { KIT_LAYOUT_SMELLS, kitRuleTableOf, kitTextWidthEm, solveKitSummary } from 'soma-foundation/kit-layout';
5
+ import type { KitFactField } from '../../object-renderer/layout-facts';
6
+ import { allFieldsOf, viewSites, type KitSmellFinding, type KitSmellRule } from './types';
7
+
8
+ const C = KIT_LAYOUT_SMELLS.catalog;
9
+ /** 表单在弹层里的业务组件(form 视图走对话框 / 抽屉);其余(SingleObjectForm / StepForm …)是页内表单。 */
10
+ const DIALOG_KINDS: readonly string[] = ['StandardCrud', 'MasterSubWorkstation', 'CategoryCrud', 'ApprovalDesk'];
11
+ const STEP_KINDS: readonly string[] = ['StepForm', 'ImportWizard', 'CheckoutPage'];
12
+
13
+ const fullRowLike = (f: KitFactField): boolean => {
14
+ const form = kitRuleTableOf().form;
15
+ return (form.fullRowTypes as readonly string[]).includes(f.type) || (f.component !== undefined && (form.fullRowComponents as readonly string[]).includes(f.component));
16
+ };
17
+
18
+ const r014: KitSmellRule = (input) => {
19
+ const out: KitSmellFinding[] = [];
20
+ const max = C['014'].params.fieldsMax;
21
+ for (const s of viewSites(input.facts)) {
22
+ if (s.view.slot !== 'form' || STEP_KINDS.includes(s.product.kind) || s.view.groups.length > 0) continue;
23
+ const n = allFieldsOf(s.view).length;
24
+ if (n > max) out.push({ path: s.view.path, message: `表单有 ${n} 个字段(超过 ${max})却没有分组` });
25
+ }
26
+ return out;
27
+ };
28
+
29
+ const r015: KitSmellRule = (input) => {
30
+ const out: KitSmellFinding[] = [];
31
+ const p = C['015'].params;
32
+ for (const s of viewSites(input.facts)) {
33
+ if (s.view.slot !== 'form' || s.view.explicitCols === null) continue;
34
+ const cols = s.view.explicitCols;
35
+ const n = allFieldsOf(s.view).length;
36
+ if (DIALOG_KINDS.includes(s.product.kind) && cols > p.dialogColsMax) out.push({ path: `${s.view.path}.arrange`, message: `弹层里的表单写了 cols: ${cols}(弹层内最多 ${p.dialogColsMax} 栏)` });
37
+ else if (cols >= 2 && n <= p.fewFields) out.push({ path: `${s.view.path}.arrange`, message: `表单只有 ${n} 个字段却写了 cols: ${cols}` });
38
+ }
39
+ return out;
40
+ };
41
+
42
+ const r016: KitSmellRule = (input) => {
43
+ const out: KitSmellFinding[] = [];
44
+ for (const s of viewSites(input.facts)) {
45
+ if (s.view.slot !== 'form' || s.view.explicitCols === null || s.view.explicitCols < 2) continue;
46
+ for (const f of allFieldsOf(s.view)) {
47
+ if (fullRowLike(f) && f.span !== null && f.span < s.view.explicitCols) out.push({ path: f.path, message: `「${f.label}」是大控件,多栏(${s.view.explicitCols})下写了 span: ${f.span},没有占满整行` });
48
+ }
49
+ }
50
+ return out;
51
+ };
52
+
53
+ const r017: KitSmellRule = (input) => {
54
+ const out: KitSmellFinding[] = [];
55
+ if (input.facts.maxWidth !== 'full') return out;
56
+ const min = C['017'].params.shortShareMin;
57
+ for (const s of viewSites(input.facts)) {
58
+ if (s.view.slot !== 'form') continue;
59
+ const plan = input.plan.views[s.planKey];
60
+ if (plan === undefined || plan.kind !== 'form' || plan.cols !== 1 || plan.cells.length === 0) continue;
61
+ const short = plan.cells.filter((c) => c.widthStep === 'xs' || c.widthStep === 'sm' || c.widthStep === 'md').length;
62
+ if (short / plan.cells.length > min) out.push({ path: 'page.max_width', message: `单栏表单里 ${short}/${plan.cells.length} 个字段是短类型,页面版心 max_width: full 会把它们横向拉满` });
63
+ }
64
+ return out;
65
+ };
66
+
67
+ const r018: KitSmellRule = (input) => {
68
+ const out: KitSmellFinding[] = [];
69
+ const p = C['018'].params;
70
+ const limit: Readonly<Record<string, number>> = { Radio: p.radio, Checkbox: p.checkbox, Segmented: p.segmented };
71
+ const seen = new Set<string>();
72
+ for (const s of viewSites(input.facts)) {
73
+ for (const f of allFieldsOf(s.view)) {
74
+ const cap = f.component === undefined ? undefined : limit[f.component];
75
+ const key = `${s.object.path}.${f.name}`;
76
+ if (cap !== undefined && f.options !== undefined && f.options.length > cap && !seen.has(key)) {
77
+ seen.add(key);
78
+ out.push({ path: f.path, message: `「${f.label}」用 ${f.component} 平铺 ${f.options.length} 个选项(上限 ${cap})` });
79
+ }
80
+ }
81
+ }
82
+ return out;
83
+ };
84
+
85
+ const r019: KitSmellRule = (input) => {
86
+ const out: KitSmellFinding[] = [];
87
+ const max = C['019'].params.selectMaxOptions;
88
+ const seen = new Set<string>();
89
+ for (const s of viewSites(input.facts)) {
90
+ for (const f of allFieldsOf(s.view)) {
91
+ const key = `${s.object.path}.${f.name}`;
92
+ if (f.type === 'enum' && f.options !== undefined && f.options.length > max && (f.component === undefined || f.component === 'Select') && !seen.has(key)) {
93
+ seen.add(key);
94
+ out.push({ path: f.path, message: `「${f.label}」下拉有 ${f.options.length} 个选项(超过 ${max}),却不是可搜索下拉` });
95
+ }
96
+ }
97
+ }
98
+ return out;
99
+ };
100
+
101
+ const r020: KitSmellRule = (input) => {
102
+ const out: KitSmellFinding[] = [];
103
+ const step = C['020'].params.labelStepEm;
104
+ for (const s of viewSites(input.facts)) {
105
+ if (s.view.slot !== 'form' || s.view.labelWidth === null || (s.view.labelPosition !== 'left' && s.view.labelPosition !== 'right')) continue;
106
+ const longest = Math.max(0, ...allFieldsOf(s.view).map((f) => kitTextWidthEm(f.label)));
107
+ if (longest > s.view.labelWidth * step) out.push({ path: `${s.view.path}.labelWidth`, message: `labelWidth: ${s.view.labelWidth} 约 ${s.view.labelWidth * step}em,放不下最长的标签(约 ${longest.toFixed(1)}em)` });
108
+ }
109
+ return out;
110
+ };
111
+
112
+ const r021: KitSmellRule = (input) => {
113
+ const out: KitSmellFinding[] = [];
114
+ for (const s of viewSites(input.facts)) {
115
+ // 档位由排布引擎按字段数选定(字段数超过提交档上限即选「更多」档);只有作者显式写了 collapsible: false 才会不折叠
116
+ if (s.view.slot !== 'filter' || s.view.collapsible !== false) continue;
117
+ const fields = allFieldsOf(s.view);
118
+ if (arrangeFilter({ fields: fields.map((f) => ({ type: f.type })) }).mode === 'more') {
119
+ out.push({ path: `${s.view.path}.collapsible`, message: `筛选有 ${fields.length} 个字段(超过提交档上限 ${KIT_ARRANGE.filter.tiers.submitMax},引擎本应钉住前 ${KIT_ARRANGE.filter.tiers.pinned} 个并把其余收进「更多筛选」),却关掉了折叠` });
120
+ }
121
+ }
122
+ return out;
123
+ };
124
+
125
+ const r022: KitSmellRule = (input) => {
126
+ const out: KitSmellFinding[] = [];
127
+ const bad = ['Upload', 'RichTextEditor', 'Textarea', 'RowEditor', 'FlowEditor'];
128
+ for (const s of viewSites(input.facts)) {
129
+ if (s.view.slot !== 'filter') continue;
130
+ for (const f of allFieldsOf(s.view)) if (f.type === 'longtext' || (f.component !== undefined && bad.includes(f.component))) out.push({ path: f.path, message: `筛选里放了不宜筛选的字段「${f.label}」(${f.type === 'longtext' ? 'longtext' : f.component})` });
131
+ }
132
+ return out;
133
+ };
134
+
135
+ const r023: KitSmellRule = (input) => {
136
+ const out: KitSmellFinding[] = [];
137
+ for (const product of input.facts.products) {
138
+ for (const object of product.objects) {
139
+ const filter = object.views.find((v) => v.slot === 'filter');
140
+ const shown = object.views.filter((v) => v.slot === 'list' || v.slot === 'summary');
141
+ if (filter === undefined || shown.length === 0) continue;
142
+ const visible = new Set(shown.flatMap((v) => allFieldsOf(v).map((f) => f.name)));
143
+ for (const f of allFieldsOf(filter)) if (!visible.has(f.name)) out.push({ path: f.path, message: `筛选字段「${f.label}」既不在列表也不在详情里,用户看不到筛选的依据` });
144
+ }
145
+ }
146
+ return out;
147
+ };
148
+
149
+ const r024: KitSmellRule = (input) => {
150
+ const out: KitSmellFinding[] = [];
151
+ const max = C['024'].params.fieldsMax;
152
+ for (const s of viewSites(input.facts)) {
153
+ if (s.view.slot !== 'summary' || s.view.groups.length > 0 || s.view.staticComponent !== null) continue;
154
+ const n = allFieldsOf(s.view).length;
155
+ if (n > max) out.push({ path: s.view.path, message: `详情有 ${n} 个字段(超过 ${max})却没有分组` });
156
+ }
157
+ return out;
158
+ };
159
+
160
+ const r025: KitSmellRule = (input) => {
161
+ const out: KitSmellFinding[] = [];
162
+ const min = C['025'].params.colsMin;
163
+ for (const s of viewSites(input.facts)) {
164
+ if (s.view.slot !== 'summary' || s.view.explicitCols === null || s.view.explicitCols < min) continue;
165
+ const fields = allFieldsOf(s.view);
166
+ if (fields.length === 0) continue;
167
+ try {
168
+ const solved = solveKitSummary({ fields: fields.map((f) => ({ key: f.name, type: f.type, label: f.label, ...(f.maxLen !== null ? { maxLen: f.maxLen } : {}), roles: f.roles })), explicitCols: null });
169
+ if (solved.cols < s.view.explicitCols) out.push({ path: `${s.view.path}.arrange`, message: `详情写了 cols: ${s.view.explicitCols},按字段需求参考宽最多放得下 ${solved.cols} 栏,每格会被挤窄` });
170
+ } catch {
171
+ // 字段事实异常(重复字段名等)由编译主体报,体检不重复
172
+ }
173
+ }
174
+ return out;
175
+ };
176
+
177
+ const r037: KitSmellRule = (input) => {
178
+ const out: KitSmellFinding[] = [];
179
+ const extra = C['037'].params.colsOverFields;
180
+ for (const s of viewSites(input.facts)) {
181
+ if (s.view.slot !== 'filter' || s.view.explicitCols === null) continue;
182
+ const n = allFieldsOf(s.view).length;
183
+ if (s.view.explicitCols > n + extra) out.push({ path: `${s.view.path}.arrange`, message: `筛选只有 ${n} 个字段却写了 cols: ${s.view.explicitCols},必有空栏` });
184
+ }
185
+ return out;
186
+ };
187
+
188
+ export const FORM_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
189
+ '014': r014, '015': r015, '016': r016, '017': r017, '018': r018, '019': r019, '020': r020,
190
+ '021': r021, '022': r022, '023': r023, '024': r024, '025': r025, '037': r037,
191
+ };