soma-kit 0.1.12 → 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 +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +158 -4
- package/spec/generated/kit-page.schema.json +139 -5
- package/spec/kit-grammar.json +438 -87
- package/spec/kit-grammar.schema.json +11 -3
- package/src/app/app-config.ts +83 -5
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +17 -5
- package/src/app/kit-view-context.ts +163 -14
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +3 -1
- package/src/app/server.ts +40 -3
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +57 -12
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +1 -1
- 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/index.ts +27 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +23 -12
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +9 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +24 -22
- package/src/base/shared.ts +169 -23
- 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 +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +63 -33
- package/src/base/text.ts +42 -13
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -10
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +2 -2
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/import-wizard/shell.ts +2 -1
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +102 -10
- 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 +4 -1
- package/src/biz/multi-board/shell.ts +8 -5
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +18 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- 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 +139 -10
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +22 -160
- package/src/biz/standard-crud/shell.ts +16 -44
- package/src/biz/step-form/shell.ts +5 -5
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- 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/view-writes.ts +69 -60
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +51 -7
- package/src/compile/component-candidates.ts +12 -1
- 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/remove-guard.ts +10 -7
- package/src/compile/styles.ts +36 -8
- package/src/compile/types.ts +13 -1
- package/src/compile/view-check.ts +149 -16
- package/src/data/amount-breakdown.ts +6 -1
- package/src/data/approval-flow.ts +1 -1
- package/src/data/assignment-picker.ts +53 -27
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +2 -2
- package/src/data/carousel.ts +8 -6
- package/src/data/chart.ts +141 -10
- package/src/data/checklist.ts +18 -5
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +2 -2
- package/src/data/confirm-dialog.ts +71 -18
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +4 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +25 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/gantt.ts +5 -2
- package/src/data/hero.ts +2 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +6 -1
- package/src/data/item-list.ts +18 -10
- package/src/data/kanban.ts +39 -10
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +45 -13
- package/src/data/mockup.ts +8 -4
- package/src/data/modal-dialog.ts +29 -9
- package/src/data/navbar.ts +5 -5
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +354 -48
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +17 -7
- package/src/data/permission-matrix.ts +33 -11
- package/src/data/permission-tree.ts +47 -22
- package/src/data/pricing-table.ts +21 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +23 -2
- package/src/data/record-picker.ts +13 -7
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +79 -26
- package/src/data/rule-builder.ts +8 -8
- package/src/data/shape-util.ts +23 -9
- package/src/data/stat-group.ts +170 -29
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +2 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +3 -3
- package/src/data/system-switcher.ts +1 -1
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +1 -1
- package/src/data/transfer.ts +36 -16
- package/src/data/tree-table.ts +62 -36
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +19 -10
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/page-bar.ts +14 -13
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +15 -10
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +2 -1
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +2 -2
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/view.ts +141 -33
- package/src/generated/kit-grammar-runtime.ts +239 -55
- package/src/i18n/kit-text.ts +63 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/arrange.ts +42 -8
- package/src/object-renderer/collection-parts.ts +241 -60
- package/src/object-renderer/collection-table.ts +109 -5
- package/src/object-renderer/collection.ts +174 -36
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +30 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-static.ts +370 -30
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -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/parts.ts +252 -1
- package/src/object-renderer/render-object.ts +54 -6
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +135 -27
- package/src/object-renderer/table-tools.ts +12 -11
- package/src/object-renderer/types.ts +78 -7
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +46 -1
- package/src/recipes/control.ts +70 -12
- package/src/recipes/index.ts +49 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +75 -17
- 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 +34 -5
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +40 -3
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +13 -1
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +372 -12
- package/src/theme/kit-theme.tpl +372 -12
- package/src/theme/nine-dim-structure.ts +177 -7
- package/src/theme/surface-layers.ts +4 -0
- package/src/theme/theme-tokens.ts +53 -13
- package/src/theme/theme-types.ts +32 -0
- package/src/biz/shared/remove-key.ts +0 -6
|
@@ -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,218 @@
|
|
|
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 { allFieldsOf, viewSites, type KitSmellFinding, type KitSmellRule } from './types';
|
|
8
|
+
|
|
9
|
+
const C = KIT_LAYOUT_SMELLS.catalog;
|
|
10
|
+
|
|
11
|
+
const isMetricObject = (o: KitFactObject): boolean => o.isPanel && o.panelKind === 'metric';
|
|
12
|
+
const isTableObject = (o: KitFactObject): boolean => o.views.some((v) => v.slot === 'list' && v.staticComponent === null && (v.collection === 'table' || v.collection === 'treeTable'));
|
|
13
|
+
|
|
14
|
+
/** 页面里按声明序展平的全部对象(槽序 × 产品内对象序)。 */
|
|
15
|
+
function orderedObjects(input: Parameters<KitSmellRule>[0]): KitFactObject[] {
|
|
16
|
+
return input.facts.products.flatMap((p) => p.objects);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const r026: KitSmellRule = (input) => {
|
|
20
|
+
const objects = orderedObjects(input);
|
|
21
|
+
const firstTable = objects.findIndex(isTableObject);
|
|
22
|
+
if (firstTable < 0) return []; // 页面没有表格面板:真看板,不报
|
|
23
|
+
const out: KitSmellFinding[] = [];
|
|
24
|
+
objects.forEach((o, i) => {
|
|
25
|
+
if (i >= firstTable || !isMetricObject(o)) return;
|
|
26
|
+
const items = o.views.flatMap((v) => v.staticItems ?? []);
|
|
27
|
+
const hasTrend = items.some((it) => it.hasTrend);
|
|
28
|
+
const hasAction = o.views.some((v) => v.hasOn) || o.actions.length > 0;
|
|
29
|
+
if (!hasTrend && !hasAction) out.push({ path: o.path, message: `统计卡「${o.title ?? o.name ?? ''}」压在表格上方,且统计项没有环比趋势、也没有关联动作` });
|
|
30
|
+
});
|
|
31
|
+
return out;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const r027: KitSmellRule = (input) => {
|
|
35
|
+
const out: KitSmellFinding[] = [];
|
|
36
|
+
const max = C['027'].params.itemsMax;
|
|
37
|
+
for (const o of orderedObjects(input)) {
|
|
38
|
+
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})` });
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const bigrams = (s: string): Set<string> => {
|
|
44
|
+
const chars = [...s.replace(/\s+/g, '')];
|
|
45
|
+
const out = new Set<string>();
|
|
46
|
+
for (let i = 0; i < chars.length - 1; i += 1) out.add(`${chars[i]}${chars[i + 1]}`);
|
|
47
|
+
if (chars.length === 1) out.add(chars[0] as string);
|
|
48
|
+
return out;
|
|
49
|
+
};
|
|
50
|
+
const jaccard = (a: string, b: string): number => {
|
|
51
|
+
const x = bigrams(a);
|
|
52
|
+
const y = bigrams(b);
|
|
53
|
+
if (x.size === 0 || y.size === 0) return 0;
|
|
54
|
+
let inter = 0;
|
|
55
|
+
for (const g of x) if (y.has(g)) inter += 1;
|
|
56
|
+
return inter / (x.size + y.size - inter);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const r028: KitSmellRule = (input) => {
|
|
60
|
+
const { title, subtitle } = input.facts;
|
|
61
|
+
if (subtitle === null || subtitle.trim() === '') return [];
|
|
62
|
+
const dup = subtitle.includes(title) || jaccard(title, subtitle) > C['028'].params.jaccardMin;
|
|
63
|
+
if (dup) return [{ path: 'page.subtitle', message: `副标题「${subtitle}」只是在复述标题「${title}」` }];
|
|
64
|
+
// 负责人裁决:不设长度阈值;人写页对任何副标题给一条「不要写副标题」的建议,AI 页不对非重复副标题发声
|
|
65
|
+
return input.profile === 'human' ? [{ path: 'page.subtitle', message: '页面写了副标题;标题已说清用途的页面不需要副标题', severity: 'advice' }] : [];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const r029: KitSmellRule = (input) => {
|
|
69
|
+
const title = input.facts.title.trim();
|
|
70
|
+
return orderedObjects(input).filter((o) => o.isPanel && o.title !== null && o.title.trim() === title).map((o) => ({ path: `${o.path}.title`, message: `面板标题「${o.title ?? ''}」与页面标题相同` }));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const r030: KitSmellRule = (input) => {
|
|
74
|
+
if (input.facts.frameKind === 'blank-frame') return [];
|
|
75
|
+
const showpieces: readonly string[] = KIT_LAYOUT_SMELLS.showpieceComponents;
|
|
76
|
+
const out: KitSmellFinding[] = [];
|
|
77
|
+
for (const o of orderedObjects(input)) {
|
|
78
|
+
for (const v of o.views) {
|
|
79
|
+
if (v.staticComponent !== null && showpieces.includes(v.staticComponent)) out.push({ path: `${v.path}.staticComponent`, message: `业务页(${input.facts.frameKind})里放了展示型组件 ${v.staticComponent}` });
|
|
80
|
+
for (const f of allFieldsOf(v)) if (f.component !== undefined && showpieces.includes(f.component)) out.push({ path: f.path, message: `业务页里放了展示型组件 ${f.component}` });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const r031: KitSmellRule = (input) => {
|
|
87
|
+
const symbol = new RegExp(KIT_LAYOUT_SMELLS.symbolPattern, 'u');
|
|
88
|
+
const out: KitSmellFinding[] = [];
|
|
89
|
+
const check = (text: string | null | undefined, path: string, what: string): void => {
|
|
90
|
+
if (text === null || text === undefined) return;
|
|
91
|
+
const m = symbol.exec(text);
|
|
92
|
+
if (m !== null) out.push({ path, message: `${what}「${text}」含符号前缀 ${m[0]}` });
|
|
93
|
+
};
|
|
94
|
+
check(input.facts.title, 'page.title', '页面标题');
|
|
95
|
+
const seen = new Set<string>();
|
|
96
|
+
for (const o of orderedObjects(input)) {
|
|
97
|
+
check(o.title, `${o.path}.title`, '标题');
|
|
98
|
+
for (const a of o.actions) check(a.name, a.path, '动作名');
|
|
99
|
+
for (const v of o.views) {
|
|
100
|
+
for (const f of allFieldsOf(v)) {
|
|
101
|
+
const key = `${o.path}.${f.name}`;
|
|
102
|
+
if (seen.has(key)) continue;
|
|
103
|
+
seen.add(key);
|
|
104
|
+
check(f.label, f.path, '字段名');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** 表面嵌套深度:显式 surface: card 的层数 + 面板外壳 + 表格自带外框(规则版本 ≥ 1 下面板内表格自动贴边,不计)。 */
|
|
112
|
+
function surfaceDepth(input: Parameters<KitSmellRule>[0], productSurface: string | null, o: KitFactObject, v: KitFactView): number {
|
|
113
|
+
let depth = 0;
|
|
114
|
+
if (productSurface === 'card') depth += 1;
|
|
115
|
+
if (o.isPanel && o.surface !== 'flush' && o.surface !== 'plain') depth += 1;
|
|
116
|
+
if (o.surface === 'card') depth += 1;
|
|
117
|
+
if (v.surface === 'card') depth += 1;
|
|
118
|
+
if (v.groups.some((g) => g.surface === 'card')) depth += 1;
|
|
119
|
+
const tableFrame = v.slot === 'list' && v.collection === 'table' && v.staticComponent === null && o.surface !== 'flush' && o.surface !== 'plain' && v.surface !== 'flush' && v.surface !== 'plain';
|
|
120
|
+
if (tableFrame && !(o.isPanel && input.plan.rules >= 1)) depth += 1;
|
|
121
|
+
return depth;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const r032: KitSmellRule = (input) => {
|
|
125
|
+
const out: KitSmellFinding[] = [];
|
|
126
|
+
const max = C['032'].params.nestingMax;
|
|
127
|
+
for (const s of viewSites(input.facts)) {
|
|
128
|
+
const depth = surfaceDepth(input, s.product.surface, s.object, s.view);
|
|
129
|
+
if (depth > max) out.push({ path: s.view.path, message: `表面嵌套 ${depth} 层(上限 ${max}):外层卡片里又套了卡片 / 带框的表格` });
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const r033: KitSmellRule = (input) => {
|
|
135
|
+
const out: KitSmellFinding[] = [];
|
|
136
|
+
for (const [path, plan] of Object.entries(input.plan.panels)) {
|
|
137
|
+
plan.shortRows.forEach((i) => {
|
|
138
|
+
const row = plan.rows[i] ?? [];
|
|
139
|
+
out.push({ path, message: `第 ${i + 1} 行面板的 span 之和是 ${row.reduce((a, c) => a + c.span, 0)},不是 12(${row.map((c) => `${c.id}:${c.span}`).join('、')})` });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const r034: KitSmellRule = (input) => {
|
|
146
|
+
const out: KitSmellFinding[] = [];
|
|
147
|
+
const p = C['034'].params;
|
|
148
|
+
const panels = orderedObjects(input).filter((o) => o.isPanel).length;
|
|
149
|
+
if (panels > p.panelsMax) out.push({ path: 'frame', message: `页面顶层有 ${panels} 个面板(超过 ${p.panelsMax})` });
|
|
150
|
+
if (input.facts.tabsDepth > p.tabsNestMax) out.push({ path: 'frame', message: `页签嵌套 ${input.facts.tabsDepth} 层(超过 ${p.tabsNestMax})` });
|
|
151
|
+
return out;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const r035: KitSmellRule = (input) => {
|
|
155
|
+
const out: KitSmellFinding[] = [];
|
|
156
|
+
const p = C['035'].params;
|
|
157
|
+
for (const s of viewSites(input.facts)) {
|
|
158
|
+
const fields = allFieldsOf(s.view);
|
|
159
|
+
const strong = fields.filter((f) => f.emphasis === 'strong' || f.highlight);
|
|
160
|
+
if (strong.length > p.strongMax || (strong.length >= 2 && strong.length / fields.length > p.strongShareMax)) {
|
|
161
|
+
out.push({ path: s.view.path, message: `${strong.length}/${fields.length} 个字段写了 emphasis: strong 或 highlight(${strong.map((f) => f.label).join('、')})` });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const r036: KitSmellRule = (input) => {
|
|
168
|
+
const re = new RegExp(KIT_LAYOUT_SMELLS.classPattern);
|
|
169
|
+
const decoration = new RegExp(KIT_LAYOUT_SMELLS.decorationClassPattern);
|
|
170
|
+
const out: KitSmellFinding[] = [];
|
|
171
|
+
const sites: Array<{ key: string; value: string; path: string }> = [...input.facts.frameClasses];
|
|
172
|
+
for (const p of input.facts.products) {
|
|
173
|
+
sites.push(...p.classes);
|
|
174
|
+
for (const o of p.objects) {
|
|
175
|
+
sites.push(...o.classes);
|
|
176
|
+
for (const v of o.views) {
|
|
177
|
+
sites.push(...v.classes);
|
|
178
|
+
for (const f of allFieldsOf(v)) sites.push(...f.classes);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const seen = new Set<string>();
|
|
183
|
+
for (const site of sites) {
|
|
184
|
+
if (seen.has(site.path)) continue;
|
|
185
|
+
seen.add(site.path);
|
|
186
|
+
if (site.key === 'areaClass.panel' && decoration.test(site.value)) continue; // 039 专报
|
|
187
|
+
if (re.test(site.value)) out.push({ path: site.path, message: `手写样式类「${site.value}」含尺寸 / 间距 / 颜色 / 栅格族` });
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const r038: KitSmellRule = (input) => {
|
|
193
|
+
const out: KitSmellFinding[] = [];
|
|
194
|
+
const seen = new Set<string>();
|
|
195
|
+
for (const s of viewSites(input.facts)) {
|
|
196
|
+
for (const f of allFieldsOf(s.view)) {
|
|
197
|
+
const key = `${s.object.path}.${f.name}`;
|
|
198
|
+
if (f.optionLabelsWithSymbol.length === 0 || seen.has(key)) continue;
|
|
199
|
+
seen.add(key);
|
|
200
|
+
out.push({ path: f.path, message: `「${f.label}」的选项标签带符号前缀:${f.optionLabelsWithSymbol.join('、')}` });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return out;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const r039: KitSmellRule = (input) => {
|
|
207
|
+
const decoration = new RegExp(KIT_LAYOUT_SMELLS.decorationClassPattern);
|
|
208
|
+
const out: KitSmellFinding[] = [];
|
|
209
|
+
for (const p of input.facts.products) {
|
|
210
|
+
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}」手写去掉卡片外观` });
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export const COMPOSITION_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
|
|
216
|
+
'026': r026, '027': r027, '028': r028, '029': r029, '030': r030, '031': r031, '032': r032, '033': r033,
|
|
217
|
+
'034': r034, '035': r035, '036': r036, '038': r038, '039': r039,
|
|
218
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// 布局体检 · 表单 / 筛选 / 详情类气味(014–025、037)。谓词全部静态,阈值读 KIT_LAYOUT_SMELLS。
|
|
2
|
+
|
|
3
|
+
import { KIT_VIEW_DEFAULTS } from 'soma-foundation/kit-limits';
|
|
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
|
+
const factor = C['021'].params.overColsFactor;
|
|
115
|
+
const defaultCols = KIT_VIEW_DEFAULTS.filter.arrange.cols;
|
|
116
|
+
for (const s of viewSites(input.facts)) {
|
|
117
|
+
// kit 现状:筛选字段 > 4 个且没写 collapsible 时自动折叠;只有作者显式写了 collapsible: false 才会不折叠
|
|
118
|
+
if (s.view.slot !== 'filter' || s.view.collapsible !== false) continue;
|
|
119
|
+
const cols = s.view.explicitCols ?? defaultCols;
|
|
120
|
+
const n = allFieldsOf(s.view).length;
|
|
121
|
+
if (n > factor * cols) out.push({ path: `${s.view.path}.collapsible`, message: `筛选有 ${n} 个字段(超过 ${factor} × ${cols} 栏),却关掉了折叠` });
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const r022: KitSmellRule = (input) => {
|
|
127
|
+
const out: KitSmellFinding[] = [];
|
|
128
|
+
const bad = ['Upload', 'RichTextEditor', 'Textarea', 'RowEditor', 'FlowEditor'];
|
|
129
|
+
for (const s of viewSites(input.facts)) {
|
|
130
|
+
if (s.view.slot !== 'filter') continue;
|
|
131
|
+
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})` });
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const r023: KitSmellRule = (input) => {
|
|
137
|
+
const out: KitSmellFinding[] = [];
|
|
138
|
+
for (const product of input.facts.products) {
|
|
139
|
+
for (const object of product.objects) {
|
|
140
|
+
const filter = object.views.find((v) => v.slot === 'filter');
|
|
141
|
+
const shown = object.views.filter((v) => v.slot === 'list' || v.slot === 'summary');
|
|
142
|
+
if (filter === undefined || shown.length === 0) continue;
|
|
143
|
+
const visible = new Set(shown.flatMap((v) => allFieldsOf(v).map((f) => f.name)));
|
|
144
|
+
for (const f of allFieldsOf(filter)) if (!visible.has(f.name)) out.push({ path: f.path, message: `筛选字段「${f.label}」既不在列表也不在详情里,用户看不到筛选的依据` });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const r024: KitSmellRule = (input) => {
|
|
151
|
+
const out: KitSmellFinding[] = [];
|
|
152
|
+
const max = C['024'].params.fieldsMax;
|
|
153
|
+
for (const s of viewSites(input.facts)) {
|
|
154
|
+
if (s.view.slot !== 'summary' || s.view.groups.length > 0 || s.view.staticComponent !== null) continue;
|
|
155
|
+
const n = allFieldsOf(s.view).length;
|
|
156
|
+
if (n > max) out.push({ path: s.view.path, message: `详情有 ${n} 个字段(超过 ${max})却没有分组` });
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const r025: KitSmellRule = (input) => {
|
|
162
|
+
const out: KitSmellFinding[] = [];
|
|
163
|
+
const min = C['025'].params.colsMin;
|
|
164
|
+
for (const s of viewSites(input.facts)) {
|
|
165
|
+
if (s.view.slot !== 'summary' || s.view.explicitCols === null || s.view.explicitCols < min) continue;
|
|
166
|
+
const fields = allFieldsOf(s.view);
|
|
167
|
+
if (fields.length === 0) continue;
|
|
168
|
+
try {
|
|
169
|
+
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 });
|
|
170
|
+
if (solved.cols < s.view.explicitCols) out.push({ path: `${s.view.path}.arrange`, message: `详情写了 cols: ${s.view.explicitCols},按字段需求参考宽最多放得下 ${solved.cols} 栏,每格会被挤窄` });
|
|
171
|
+
} catch {
|
|
172
|
+
// 字段事实异常(重复字段名等)由编译主体报,体检不重复
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const r037: KitSmellRule = (input) => {
|
|
179
|
+
const out: KitSmellFinding[] = [];
|
|
180
|
+
const extra = C['037'].params.colsOverFields;
|
|
181
|
+
for (const s of viewSites(input.facts)) {
|
|
182
|
+
if (s.view.slot !== 'filter' || s.view.explicitCols === null) continue;
|
|
183
|
+
const n = allFieldsOf(s.view).length;
|
|
184
|
+
if (s.view.explicitCols > n + extra) out.push({ path: `${s.view.path}.arrange`, message: `筛选只有 ${n} 个字段却写了 cols: ${s.view.explicitCols},必有空栏` });
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const FORM_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
|
|
190
|
+
'014': r014, '015': r015, '016': r016, '017': r017, '018': r018, '019': r019, '020': r020,
|
|
191
|
+
'021': r021, '022': r022, '023': r023, '024': r024, '025': r025, '037': r037,
|
|
192
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// 布局体检 · 表格与动作类气味(001–013)。谓词全部静态:页面事实 + 影子规划,阈值读 KIT_LAYOUT_SMELLS,不抄数字。
|
|
2
|
+
|
|
3
|
+
import { KIT_WIDTH_LIMITS } from 'soma-foundation/kit-limits';
|
|
4
|
+
import { KIT_LAYOUT_SMELLS, kitLabelTooLong, kitReferenceContainerRem, kitRowActionsNeedRem, kitRuleTableOf } from 'soma-foundation/kit-layout';
|
|
5
|
+
import type { KitFactAction, KitFactObject } from '../../object-renderer/layout-facts';
|
|
6
|
+
import { allFieldsOf, viewSites, type KitLintInput, type KitSmellFinding, type KitSmellRule } from './types';
|
|
7
|
+
|
|
8
|
+
const C = KIT_LAYOUT_SMELLS.catalog;
|
|
9
|
+
const isTable = (v: { slot: string; collection: string | null }): boolean => v.slot === 'list' && (v.collection === 'table' || v.collection === 'treeTable');
|
|
10
|
+
const numeric = (type: string): boolean => (kitRuleTableOf().table.numericTypes as readonly string[]).includes(type);
|
|
11
|
+
|
|
12
|
+
/** 对象上登记的行动作(按列表 rowActions 的声明序);没写 rowActions 的列表没有行动作。 */
|
|
13
|
+
function rowActionsOf(object: KitFactObject, ids: readonly string[]): KitFactAction[] {
|
|
14
|
+
const byId = new Map(object.actions.filter((a) => a.on === 'row').map((a) => [a.id, a]));
|
|
15
|
+
return ids.flatMap((id) => (byId.has(id) ? [byId.get(id) as KitFactAction] : []));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const r001: KitSmellRule = (input) => {
|
|
19
|
+
const out: KitSmellFinding[] = [];
|
|
20
|
+
for (const s of viewSites(input.facts)) {
|
|
21
|
+
const plan = input.plan.views[s.planKey];
|
|
22
|
+
if (plan === undefined || plan.kind !== 'table') continue;
|
|
23
|
+
const free = kitReferenceContainerRem() - plan.selectRem - plan.actionsRem;
|
|
24
|
+
const parts = KIT_WIDTH_LIMITS.totalParts;
|
|
25
|
+
for (const col of plan.columns) {
|
|
26
|
+
const fact = allFieldsOf(s.view).find((f) => f.name === col.field);
|
|
27
|
+
if (fact === undefined || fact.width === null) continue;
|
|
28
|
+
const have = (free * fact.width) / parts;
|
|
29
|
+
if (have + 0.0005 < col.demand.min) {
|
|
30
|
+
out.push({ path: fact.path, message: `列「${fact.label}」写了 width: ${fact.width},在参考容器里约 ${have.toFixed(1)}rem,小于内容需求的最小宽 ${col.demand.min.toFixed(1)}rem,会被压窄截断` });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const r002: KitSmellRule = (input) => {
|
|
38
|
+
const out: KitSmellFinding[] = [];
|
|
39
|
+
const max = C['002'].params.idealShareMax;
|
|
40
|
+
for (const s of viewSites(input.facts)) {
|
|
41
|
+
const plan = input.plan.views[s.planKey];
|
|
42
|
+
if (plan === undefined || plan.kind !== 'table' || plan.mode !== 'parts') continue;
|
|
43
|
+
const sum = plan.columns.reduce((a, c) => a + c.demand.ideal, 0);
|
|
44
|
+
if (sum < max * kitReferenceContainerRem()) out.push({ path: s.view.path, message: `每列都写了 width,而各列理想宽之和只有 ${sum.toFixed(1)}rem(不足参考宽的 ${Math.round(max * 100)}%),均分会把短值列拉稀` });
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const r003: KitSmellRule = (input) => {
|
|
50
|
+
const out: KitSmellFinding[] = [];
|
|
51
|
+
if (input.plan.rules >= 1) return out; // 规则版本 ≥ 1 的操作列宽由求解保证放得下
|
|
52
|
+
const cap = C['008'].params.inlineCap;
|
|
53
|
+
const parts = KIT_WIDTH_LIMITS.tableFixedParts;
|
|
54
|
+
for (const s of viewSites(input.facts)) {
|
|
55
|
+
if (!isTable(s.view)) continue;
|
|
56
|
+
const actions = rowActionsOf(s.object, s.view.rowActionIds);
|
|
57
|
+
const visible = actions.filter((a) => !a.more);
|
|
58
|
+
if (visible.length === 0) continue;
|
|
59
|
+
const flat = visible.slice(0, cap);
|
|
60
|
+
const hasMore = visible.length > flat.length || visible.length < actions.length;
|
|
61
|
+
const need = kitRowActionsNeedRem(flat.map((a) => a.name), hasMore);
|
|
62
|
+
const colParts = flat.length >= parts.actionsWideFromInline ? parts.actionsWide : parts.actions;
|
|
63
|
+
const have = (kitReferenceContainerRem() * colParts) / KIT_WIDTH_LIMITS.totalParts;
|
|
64
|
+
if (need > have + 0.0005) out.push({ path: s.view.path, message: `行动作「${flat.map((a) => a.name).join('」「')}」平铺需要约 ${need}rem,操作列只有约 ${have.toFixed(1)}rem(${colParts} 份),放不下` });
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const r004: KitSmellRule = (input) => {
|
|
70
|
+
const out: KitSmellFinding[] = [];
|
|
71
|
+
const max = C['004'].params.columnsMax;
|
|
72
|
+
for (const s of viewSites(input.facts)) {
|
|
73
|
+
if (!isTable(s.view) || s.view.hasFixedColumn || s.view.hasColumnsTool) continue;
|
|
74
|
+
const n = allFieldsOf(s.view).length;
|
|
75
|
+
if (n > max) out.push({ path: s.view.path, message: `表格有 ${n} 列(超过 ${max}),又没有固定列与列设置工具,一屏放不下` });
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const r005: KitSmellRule = (input) => {
|
|
81
|
+
const out: KitSmellFinding[] = [];
|
|
82
|
+
const p = C['005'].params;
|
|
83
|
+
for (const s of viewSites(input.facts)) {
|
|
84
|
+
if (!isTable(s.view)) continue;
|
|
85
|
+
const hits = allFieldsOf(s.view).filter((f) => f.type === 'longtext' || (f.maxLen !== null && f.maxLen > p.maxLen));
|
|
86
|
+
const escalate = input.profile === 'ai' && hits.length >= p.aiEscalateColumns;
|
|
87
|
+
for (const f of hits) out.push({ path: f.path, message: `列「${f.label}」是长文本(${f.type === 'longtext' ? 'longtext' : `max_len ${f.maxLen}`}),在单行省略的表格里读不全`, ...(escalate ? { severity: 'error' as const } : {}) });
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const r006: KitSmellRule = (input) => {
|
|
93
|
+
const out: KitSmellFinding[] = [];
|
|
94
|
+
for (const s of viewSites(input.facts)) {
|
|
95
|
+
if (!isTable(s.view)) continue;
|
|
96
|
+
const fields = allFieldsOf(s.view);
|
|
97
|
+
const first = fields[0];
|
|
98
|
+
if (first === undefined || first.roles.includes('title')) continue;
|
|
99
|
+
const identifying = first.type === 'text' || first.type === 'longtext' || first.type === 'enums';
|
|
100
|
+
if (!identifying && fields.some((f) => f.roles.includes('title'))) out.push({ path: first.path, message: `首列「${first.label}」不是标识列,而后面有标题类字段「${fields.find((f) => f.roles.includes('title'))?.label ?? ''}」` });
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const r007: KitSmellRule = (input) => {
|
|
106
|
+
const out: KitSmellFinding[] = [];
|
|
107
|
+
for (const s of viewSites(input.facts)) {
|
|
108
|
+
if (!isTable(s.view)) continue;
|
|
109
|
+
for (const f of allFieldsOf(s.view)) if (numeric(f.type) && f.align !== null && f.align !== 'end') out.push({ path: f.path, message: `数值列「${f.label}」写了 align: ${f.align},数值列应右对齐` });
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const r008: KitSmellRule = (input) => {
|
|
115
|
+
const out: KitSmellFinding[] = [];
|
|
116
|
+
if (input.plan.rules >= 1) return out;
|
|
117
|
+
const cap = C['008'].params.inlineCap;
|
|
118
|
+
for (const s of viewSites(input.facts)) {
|
|
119
|
+
if (!isTable(s.view)) continue;
|
|
120
|
+
const visible = rowActionsOf(s.object, s.view.rowActionIds).filter((a) => !a.more);
|
|
121
|
+
if (visible.length > cap) out.push({ path: s.view.path, message: `行内平铺 ${visible.length} 个动作,超过封顶 ${cap} 个` });
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const r009: KitSmellRule = (input) => {
|
|
127
|
+
const out: KitSmellFinding[] = [];
|
|
128
|
+
if (input.plan.rules >= 1) return out;
|
|
129
|
+
const min = kitRuleTableOf().rowActions.dangerInMoreMinActions;
|
|
130
|
+
for (const s of viewSites(input.facts)) {
|
|
131
|
+
if (!isTable(s.view)) continue;
|
|
132
|
+
const visible = rowActionsOf(s.object, s.view.rowActionIds).filter((a) => !a.more);
|
|
133
|
+
if (visible.length < min) continue;
|
|
134
|
+
for (const a of visible) if (a.danger && !a.primary) out.push({ path: a.path, message: `危险动作「${a.name}」与其他动作并排平铺,应放进「更多」末位` });
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const r010: KitSmellRule = (input) => {
|
|
140
|
+
const out: KitSmellFinding[] = [];
|
|
141
|
+
const p = C['010'].params;
|
|
142
|
+
for (const product of input.facts.products) {
|
|
143
|
+
for (const object of product.objects) {
|
|
144
|
+
for (const a of object.actions) {
|
|
145
|
+
const row = a.on === 'row';
|
|
146
|
+
const toolbar = a.on === 'toolbar';
|
|
147
|
+
if (!row && !toolbar) continue;
|
|
148
|
+
if (kitLabelTooLong(a.name, row ? p.rowCjk : p.toolbarCjk, p.rowLatin)) out.push({ path: a.path, message: `${row ? '行' : '工具栏'}动作名「${a.name}」过长` });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const r011: KitSmellRule = (input) => {
|
|
156
|
+
const out: KitSmellFinding[] = [];
|
|
157
|
+
const max = C['011'].params.primaryMax;
|
|
158
|
+
for (const product of input.facts.products) {
|
|
159
|
+
for (const object of product.objects) {
|
|
160
|
+
const primaries = object.actions.filter((a) => a.on === 'toolbar' && a.primary);
|
|
161
|
+
if (primaries.length > max) out.push({ path: primaries[max]?.path ?? object.path, message: `工具栏有 ${primaries.length} 个主操作(tone: primary):${primaries.map((a) => a.name).join('、')}` });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const r012: KitSmellRule = (input) => {
|
|
168
|
+
const out: KitSmellFinding[] = [];
|
|
169
|
+
for (const s of viewSites(input.facts)) {
|
|
170
|
+
if (!isTable(s.view)) continue;
|
|
171
|
+
for (const f of allFieldsOf(s.view)) {
|
|
172
|
+
if (f.type === 'enum' && f.optionTones && (f.component === undefined || f.component === 'Text')) out.push({ path: f.path, message: `状态列「${f.label}」的候选带 tone,却用纯文本展示` });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const r013: KitSmellRule = (input) => {
|
|
179
|
+
const out: KitSmellFinding[] = [];
|
|
180
|
+
const min = C['013'].params.columnsMin;
|
|
181
|
+
for (const s of viewSites(input.facts)) {
|
|
182
|
+
if (!isTable(s.view)) continue;
|
|
183
|
+
const ones = allFieldsOf(s.view).filter((f) => f.width === 1);
|
|
184
|
+
if (ones.length >= min) out.push({ path: s.view.path, message: `${ones.length} 列写了 width: 1(${ones.map((f) => f.label).join('、')}),每列只有约 8% 宽` });
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const TABLE_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
|
|
190
|
+
'001': r001, '002': r002, '003': r003, '004': r004, '005': r005, '006': r006, '007': r007, '008': r008,
|
|
191
|
+
'009': r009, '010': r010, '011': r011, '012': r012, '013': r013,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export type { KitLintInput };
|