soma-kit 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- package/spec/generated/kit-app.schema.json +18 -2
- package/spec/generated/kit-page.schema.json +95 -0
- package/spec/kit-grammar.json +332 -75
- package/spec/kit-grammar.schema.json +1 -27
- package/src/app/app-config.ts +11 -5
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +82 -10
- package/src/app/define-kit-app.ts +6 -5
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +20 -8
- package/src/app/kit-view-context.ts +30 -4
- package/src/app/server-pages.ts +5 -1
- package/src/app/server.ts +15 -5
- package/src/app/theme-endpoint.ts +1 -1
- package/src/app/theme-runtime.ts +7 -2
- package/src/base/alert.ts +23 -20
- package/src/base/anchored-layer.ts +1 -1
- package/src/base/button.ts +34 -17
- package/src/base/cascader.ts +8 -4
- package/src/base/check-core.ts +9 -6
- package/src/base/color-picker.ts +10 -6
- package/src/base/command-palette.ts +10 -4
- package/src/base/context-menu.ts +5 -2
- package/src/base/date-range.ts +9 -6
- package/src/base/date.ts +10 -6
- package/src/base/delta.ts +4 -2
- package/src/base/divider.ts +15 -66
- package/src/base/end-edge.ts +14 -2
- package/src/base/fab.ts +11 -6
- package/src/base/gap-value.ts +25 -5
- package/src/base/hint-tips.ts +1 -1
- package/src/base/illustrations.ts +2 -1
- package/src/base/index.ts +20 -4
- package/src/base/inline-error.ts +84 -0
- package/src/base/input.ts +54 -18
- package/src/base/kbd.ts +4 -3
- package/src/base/link.ts +1 -1
- package/src/base/listbox-core.ts +70 -22
- package/src/base/mentions.ts +6 -3
- package/src/base/menu-button.ts +73 -50
- package/src/base/menu-core.ts +9 -2
- package/src/base/motion/hover-3d.ts +4 -1
- package/src/base/motion/hover-gallery.ts +4 -1
- package/src/base/otp.ts +7 -3
- package/src/base/overlay-runtime.ts +3 -2
- package/src/base/overlay-shell.ts +141 -0
- package/src/base/popover.ts +7 -6
- package/src/base/popup.ts +47 -41
- package/src/base/qty-stepper.ts +14 -9
- package/src/base/reason-tip.ts +2 -2
- package/src/{frames → base}/resize-handle.ts +1 -1
- package/src/base/segmented.ts +44 -35
- package/src/base/select.ts +1 -0
- package/src/base/shared.ts +52 -18
- package/src/base/state-panel.ts +34 -13
- package/src/base/status-tone.ts +1 -1
- package/src/base/tag-input.ts +13 -8
- package/src/base/tag.ts +56 -57
- package/src/base/text.ts +38 -14
- package/src/base/textarea.ts +1 -1
- package/src/base/time-picker.ts +9 -5
- package/src/base/tree-select.ts +12 -9
- package/src/base/upload.ts +26 -17
- package/src/biz/approval-desk/compile.ts +28 -1
- package/src/biz/approval-desk/shell.ts +10 -9
- package/src/biz/auth-panel/compile.ts +1 -1
- package/src/biz/auth-panel/shell.ts +7 -6
- package/src/biz/category-crud/compile.ts +20 -6
- package/src/biz/category-crud/shell.ts +10 -7
- package/src/biz/checkout-page/compile.ts +1 -1
- package/src/biz/checkout-page/shell.ts +15 -13
- package/src/biz/compose.ts +5 -5
- package/src/biz/data-components.ts +4 -0
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +1 -1
- package/src/biz/import-wizard/shell.ts +17 -13
- package/src/biz/index.ts +4 -3
- package/src/biz/landing-page/compile.ts +1 -1
- package/src/biz/landing-page/shell.ts +6 -5
- package/src/biz/link/shared.ts +8 -1
- package/src/biz/master-sub/compile.ts +269 -27
- package/src/biz/master-sub/detail-head.ts +62 -0
- package/src/biz/master-sub/index.ts +5 -4
- package/src/biz/master-sub/shell.ts +138 -69
- package/src/biz/multi-board/compile.ts +166 -11
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +25 -10
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +96 -24
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +9 -2
- package/src/biz/notification-center/shell.ts +15 -7
- package/src/biz/page-templates/domain-templates.ts +7 -3
- package/src/biz/page-templates/result-page/compile.ts +1 -1
- package/src/biz/page-templates/result-page/shell.ts +5 -4
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +18 -18
- package/src/biz/record-detail/compile.ts +5 -2
- package/src/biz/record-detail/shell.ts +12 -11
- package/src/biz/settings-center/compile.ts +1 -1
- package/src/biz/settings-center/shell.ts +14 -10
- package/src/biz/shared/action-host.ts +12 -5
- package/src/biz/shared/compile-helpers.ts +83 -4
- package/src/biz/shared/coordinator.ts +104 -21
- package/src/biz/shared/overlay-compile.ts +76 -4
- package/src/biz/shared/overlay-shell.ts +65 -112
- package/src/biz/single-form/compile.ts +2 -2
- package/src/biz/single-form/shell.ts +13 -7
- package/src/biz/standard-crud/compile.ts +24 -4
- package/src/biz/standard-crud/shell.ts +38 -30
- package/src/biz/standard-crud/summary.ts +42 -0
- package/src/biz/step-form/compile.ts +1 -1
- package/src/biz/step-form/hub.ts +4 -0
- package/src/biz/step-form/shell.ts +16 -12
- package/src/biz/types.ts +15 -3
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +35 -8
- package/src/cli/kit-init.ts +149 -0
- package/src/cli/layout-cli.ts +7 -7
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/compile-page.ts +36 -230
- package/src/compile/component-candidates.ts +4 -1
- package/src/compile/hints.ts +5 -58
- package/src/compile/index.ts +2 -2
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +97 -18
- package/src/compile/layout-lint/rules-form.ts +6 -7
- package/src/compile/layout-lint/rules-table.ts +98 -14
- package/src/compile/page-composition.ts +191 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/redirect.ts +1 -1
- package/src/compile/stages.ts +169 -0
- package/src/compile/styles.ts +80 -32
- package/src/compile/types.ts +5 -3
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +6 -2
- package/src/data/anchor-nav.ts +4 -1
- package/src/data/approval-flow.ts +13 -5
- package/src/data/assignment-picker.ts +35 -20
- package/src/data/async-result-panel.ts +7 -3
- package/src/data/breadcrumbs.ts +13 -9
- package/src/data/calendar.ts +10 -4
- package/src/data/carousel.ts +13 -5
- package/src/data/chart.ts +745 -48
- package/src/data/checklist.ts +9 -5
- package/src/data/code-view.ts +220 -26
- package/src/data/comment-thread.ts +9 -3
- package/src/data/confirm-dialog.ts +57 -20
- package/src/data/diff.ts +4 -1
- package/src/data/dock.ts +5 -1
- package/src/data/embed.ts +1 -1
- package/src/data/engine-ports.ts +126 -0
- package/src/data/field-mapper.ts +16 -7
- package/src/data/flow-editor.ts +106 -29
- package/src/data/footer.ts +8 -2
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +8 -2
- package/src/data/image-viewer.ts +7 -3
- package/src/data/index.ts +22 -8
- package/src/data/item-list.ts +11 -3
- package/src/data/json-view.ts +844 -0
- package/src/data/kanban.ts +13 -8
- package/src/data/markdown-view.ts +487 -0
- package/src/data/matrix.ts +400 -0
- package/src/data/media-grid.ts +5 -2
- package/src/data/mega-menu.ts +4 -3
- package/src/data/menu-dom.ts +9 -8
- package/src/data/menu.ts +35 -17
- package/src/data/mockup.ts +12 -8
- package/src/data/modal-dialog.ts +108 -57
- package/src/data/navbar.ts +13 -7
- package/src/data/notice-list.ts +53 -20
- package/src/data/notify-renderer.ts +21 -10
- package/src/data/object-form.ts +248 -151
- package/src/data/pager.ts +15 -10
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +19 -9
- package/src/data/permission-tree.ts +30 -13
- package/src/data/pricing-table.ts +10 -4
- package/src/data/reaction-bar.ts +6 -3
- package/src/data/record-card.ts +30 -14
- package/src/data/record-picker.ts +8 -4
- package/src/data/redirect.ts +1 -1
- package/src/data/request-console.ts +20 -7
- package/src/data/resident.ts +6 -10
- package/src/data/result-panel.ts +2 -2
- package/src/data/rich-text.ts +58 -96
- package/src/data/row-editor.ts +12 -7
- package/src/data/rule-builder.ts +22 -11
- package/src/data/shape-util.ts +26 -14
- package/src/data/stat-group.ts +369 -84
- package/src/data/static-lazy.ts +7 -0
- package/src/data/static-registry.ts +14 -2
- package/src/data/steps.ts +6 -2
- package/src/data/survey.ts +13 -4
- package/src/data/system-switcher.ts +17 -7
- package/src/data/text-diff.ts +663 -0
- package/src/data/timeline.ts +1 -1
- package/src/data/tour-guide.ts +8 -4
- package/src/data/transfer.ts +24 -11
- package/src/data/tree-table.ts +84 -17
- package/src/data/tree.ts +6 -3
- package/src/data/virtual-rows.ts +22 -11
- package/src/data/wrap.ts +2 -2
- package/src/data/wrapped-candidates.ts +22 -1
- package/src/frames/index.ts +4 -2
- package/src/frames/inherited-shell.ts +178 -0
- package/src/frames/list-summary.ts +123 -0
- package/src/frames/page-bar.ts +10 -16
- package/src/frames/resident-components.ts +20 -0
- package/src/frames/shared.ts +37 -17
- package/src/frames/split-frame/shell.ts +17 -11
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +17 -9
- package/src/frames/top-main-frame.ts +1 -1
- package/src/frames/types.ts +6 -3
- package/src/frames/workspace-frame/extras.ts +19 -5
- package/src/frames/workspace-frame/shell.ts +4 -3
- package/src/frames/workspace-frame/state.ts +8 -2
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +156 -91
- package/src/generated/kit-grammar-runtime.ts +227 -58
- package/src/i18n/kit-text.ts +141 -2
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +169 -0
- package/src/object-renderer/action-more.ts +160 -0
- package/src/object-renderer/arrange.ts +86 -26
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +72 -20
- package/src/object-renderer/collection-table.ts +178 -65
- package/src/object-renderer/collection.ts +129 -83
- package/src/object-renderer/compile-data.ts +1 -1
- package/src/object-renderer/defaults.ts +10 -5
- package/src/object-renderer/emit-events.ts +1 -1
- package/src/object-renderer/emit-object.ts +7 -0
- package/src/object-renderer/emit-static.ts +243 -87
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/filter-toolbar.ts +103 -0
- package/src/{compile → object-renderer}/fragment.ts +13 -2
- package/src/object-renderer/index.ts +6 -1
- package/src/object-renderer/layout-facts.ts +46 -6
- package/src/object-renderer/layout-plan.ts +136 -43
- package/src/object-renderer/layout-plan.types.ts +42 -5
- package/src/object-renderer/overlay-decide.ts +82 -0
- package/src/object-renderer/parts.ts +7 -259
- package/src/object-renderer/render-object.ts +60 -47
- package/src/object-renderer/table-actions.ts +135 -56
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +63 -25
- package/src/object-renderer/types.ts +16 -22
- package/src/recipes/app-blocks.ts +66 -0
- package/src/recipes/code-view.ts +56 -0
- package/src/recipes/compact-group.ts +31 -0
- package/src/recipes/container.ts +54 -13
- package/src/recipes/control.ts +77 -157
- package/src/recipes/desc-list.ts +14 -0
- package/src/recipes/divider.ts +53 -0
- package/src/recipes/emphasis.ts +60 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +34 -1
- package/src/recipes/inherited-shell.ts +37 -0
- package/src/recipes/json-view.ts +49 -0
- package/src/recipes/markdown.ts +86 -0
- package/src/recipes/overlay.ts +149 -18
- package/src/recipes/page-width.ts +20 -0
- package/src/recipes/placeholder.ts +21 -5
- package/src/recipes/rail-grid.ts +3 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +20 -28
- package/src/recipes/status.ts +17 -8
- package/src/recipes/strip.ts +72 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +10 -6
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +120 -11
- package/src/recipes/tabs.ts +126 -0
- package/src/recipes/text-diff.ts +90 -0
- package/src/recipes/title-row.ts +7 -5
- package/src/recipes/typography.ts +24 -43
- package/src/shared/diagnostics.ts +16 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-value-format.ts +246 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +12 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- package/src/shared/path-guard.ts +1 -1
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/theme-runtime-shared.ts +19 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +49 -14
- package/src/theme/kit-theme.tpl +49 -14
- package/src/theme/nine-dim-structure.ts +129 -37
- package/src/theme/surface-layers.ts +17 -4
- package/src/theme/theme-tokens.ts +16 -5
- package/src/theme/typography.ts +21 -17
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- /package/src/{base → shared}/class-candidates.ts +0 -0
package/src/compile/hints.ts
CHANGED
|
@@ -6,66 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
import { KIT_GRAMMAR } from '../object-renderer/defaults';
|
|
8
8
|
import { KIT_AI_WRITER } from '../generated/kit-grammar-runtime';
|
|
9
|
-
import { classify } from '../
|
|
10
|
-
import type { KitDiagnostic } from '../
|
|
9
|
+
import { classify } from '../shared/merge-class';
|
|
10
|
+
import type { KitDiagnostic } from '../shared/diagnostics';
|
|
11
|
+
import { closestOf, editDistance, hintOf, nameSuggestion, shownList as shown } from '../shared/hints';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// ---------------------------------------------------------------- 编辑距离
|
|
15
|
-
|
|
16
|
-
/** Levenshtein 编辑距离(两行滚动数组) */
|
|
17
|
-
export function editDistance(a: string, b: string): number {
|
|
18
|
-
if (a === b) return 0;
|
|
19
|
-
if (a.length === 0) return b.length;
|
|
20
|
-
if (b.length === 0) return a.length;
|
|
21
|
-
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
22
|
-
for (let i = 1; i <= a.length; i += 1) {
|
|
23
|
-
const cur = [i];
|
|
24
|
-
for (let j = 1; j <= b.length; j += 1) {
|
|
25
|
-
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
26
|
-
cur[j] = Math.min(prev[j]! + 1, cur[j - 1]! + 1, prev[j - 1]! + cost);
|
|
27
|
-
}
|
|
28
|
-
prev = cur;
|
|
29
|
-
}
|
|
30
|
-
return prev[b.length]!;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** 候选里最接近 word 的一个;距离超过阈值(约 40% 长度,至少 2)返回 undefined */
|
|
34
|
-
export function closestOf(word: string, candidates: readonly string[]): string | undefined {
|
|
35
|
-
const w = word.toLowerCase();
|
|
36
|
-
const limit = Math.max(2, Math.ceil(w.length * 0.4));
|
|
37
|
-
let best: string | undefined;
|
|
38
|
-
let bestD = Infinity;
|
|
39
|
-
for (const c of candidates) {
|
|
40
|
-
const lc = c.toLowerCase();
|
|
41
|
-
// 包含关系(如 labelWidht ⊂ ...)按近邻处理,同分取长度更接近者
|
|
42
|
-
const d = lc === w ? 0 : Math.min(editDistance(w, lc), lc.includes(w) || w.includes(lc) ? Math.abs(lc.length - w.length) : Infinity);
|
|
43
|
-
if (d < bestD || (d === bestD && best !== undefined && Math.abs(c.length - w.length) < Math.abs(best.length - w.length))) {
|
|
44
|
-
best = c;
|
|
45
|
-
bestD = d;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return best !== undefined && bestD <= limit && bestD < w.length ? best : undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const shown = (list: readonly string[], max = 16): string => (list.length <= max ? list.join(' / ') : `${list.slice(0, max).join(' / ')} …(共 ${list.length} 个)`);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 「被引用的名字」写错时的建议:有近似项给「你可能想写的是 X」,候选不超过 shown 的上限时再列可选项;
|
|
55
|
-
* 既无近似项、候选又太多(或为空)返回 undefined。诊断点用现场候选集直接写进 hint,不靠事后正则匹配消息。
|
|
56
|
-
*/
|
|
57
|
-
export function nameSuggestion(name: string, candidates: Iterable<string>): string | undefined {
|
|
58
|
-
// 名字本身或候选可能来自页面原文(id 缺失 / 写成数字):非字符串与空串一律不参与,不让算建议抛异常
|
|
59
|
-
if (typeof name !== 'string' || name === '') return undefined;
|
|
60
|
-
const list = [...new Set(candidates)].filter((c): c is string => typeof c === 'string' && c !== '');
|
|
61
|
-
const near = closestOf(name, list);
|
|
62
|
-
const listed = list.length > 0 && list.length <= 16 ? `可选:${shown(list)}` : undefined;
|
|
63
|
-
if (near !== undefined) return listed !== undefined ? `你可能想写的是 ${near};${listed}` : `你可能想写的是 ${near}`;
|
|
64
|
-
return listed;
|
|
65
|
-
}
|
|
13
|
+
export { closestOf, editDistance, hintOf, nameSuggestion };
|
|
66
14
|
|
|
67
|
-
|
|
68
|
-
export const hintOf = (hint: string | undefined): { hint?: string } => (hint === undefined ? {} : { hint });
|
|
15
|
+
type Json = Record<string, any>;
|
|
69
16
|
|
|
70
17
|
// ---------------------------------------------------------------- 键 / 取值 / 名字
|
|
71
18
|
|
package/src/compile/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { emptyFragment, mergeFragments, fragmentFromEmit } from '
|
|
2
|
-
export type { KitFragment } from '
|
|
1
|
+
export { emptyFragment, mergeFragments, fragmentFromEmit } from '../object-renderer/fragment';
|
|
2
|
+
export type { KitFragment } from '../object-renderer/fragment';
|
|
3
3
|
export { compileKitPage, pageIdOf, stableHash, KIT_ROOT_HOST } from './compile-page';
|
|
4
4
|
export { parsePageDecl } from './parse';
|
|
5
5
|
export { checkNoRelativeOrSystemPath, isSystemAbsolutePath, isRelativePathValue } from './closed-set';
|
|
@@ -26,6 +26,8 @@ export interface KitLayoutAnalysisOptions {
|
|
|
26
26
|
readonly rules?: number;
|
|
27
27
|
/** 页面源文本(用来读行内豁免);缺省不豁免 */
|
|
28
28
|
readonly source?: string;
|
|
29
|
+
/** 页面作者写的 page.max_width(decl 已补过页面模式 / 应用默认版心时由调用方给原值;缺省取 decl 上的值) */
|
|
30
|
+
readonly declaredMaxWidth?: string | null;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/** 一个档案下的体检结果。 */
|
|
@@ -44,7 +46,8 @@ export interface KitLayoutReport {
|
|
|
44
46
|
|
|
45
47
|
/** 页面声明 → 布局报告。纯函数;任何内部异常都由调用方(compile-page 的旁路)兜住。 */
|
|
46
48
|
export function analyzeKitPageLayout(decl: KitPageDecl, options?: KitLayoutAnalysisOptions): KitLayoutReport {
|
|
47
|
-
const
|
|
49
|
+
const raw = extractKitPageFacts(decl);
|
|
50
|
+
const facts = options?.declaredMaxWidth === undefined ? raw : { ...raw, maxWidthDeclared: options.declaredMaxWidth };
|
|
48
51
|
const plan = planKitPageLayout(facts, options?.rules === undefined ? undefined : { rules: options.rules });
|
|
49
52
|
const ignore = options?.source === undefined ? undefined : extractLayoutIgnores(options.source);
|
|
50
53
|
const report = (profile: KitLintProfile): KitLayoutProfileReport => {
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// 展示型大图标卡(030)、卡片套卡片(032)、强调滥用(035)。
|
|
4
4
|
|
|
5
5
|
import { KIT_LAYOUT_SMELLS } from 'soma-foundation/kit-layout';
|
|
6
|
-
import type { KitFactObject, KitFactView } from '../../object-renderer/layout-facts';
|
|
6
|
+
import type { KitFactObject, KitFactView, KitPageFacts } from '../../object-renderer/layout-facts';
|
|
7
|
+
import { boardCompositionNodes, composeBoard } from '../../biz/multi-board/composition';
|
|
7
8
|
import { allFieldsOf, viewSites, type KitSmellFinding, type KitSmellRule } from './types';
|
|
8
9
|
|
|
9
10
|
const C = KIT_LAYOUT_SMELLS.catalog;
|
|
@@ -142,15 +143,60 @@ const r033: KitSmellRule = (input) => {
|
|
|
142
143
|
return out;
|
|
143
144
|
};
|
|
144
145
|
|
|
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) => {
|
|
146
172
|
const out: KitSmellFinding[] = [];
|
|
147
|
-
const p = C['
|
|
148
|
-
const
|
|
149
|
-
|
|
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
|
+
}
|
|
150
178
|
if (input.facts.tabsDepth > p.tabsNestMax) out.push({ path: 'frame', message: `页签嵌套 ${input.facts.tabsDepth} 层(超过 ${p.tabsNestMax})` });
|
|
151
179
|
return out;
|
|
152
180
|
};
|
|
153
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
|
+
// KIT-LAYOUT-043 页面写死版心:版心由页面模式推导(报告阅读页 ReportBoard → 阅读版心),page.max_width 降级为告警、迁移期仍生效
|
|
195
|
+
const r043: KitSmellRule = (input) => {
|
|
196
|
+
if (input.facts.maxWidthDeclared === null) return [];
|
|
197
|
+
return [{ path: 'page.max_width', message: `page.max_width: ${input.facts.maxWidthDeclared} 由页面作者选档;版心改由页面模式推导(报告类页面写 product.kind: ReportBoard),该键将删除` }];
|
|
198
|
+
};
|
|
199
|
+
|
|
154
200
|
const r035: KitSmellRule = (input) => {
|
|
155
201
|
const out: KitSmellFinding[] = [];
|
|
156
202
|
const p = C['035'].params;
|
|
@@ -167,24 +213,23 @@ const r035: KitSmellRule = (input) => {
|
|
|
167
213
|
const r036: KitSmellRule = (input) => {
|
|
168
214
|
const re = new RegExp(KIT_LAYOUT_SMELLS.classPattern);
|
|
169
215
|
const decoration = new RegExp(KIT_LAYOUT_SMELLS.decorationClassPattern);
|
|
216
|
+
// frame.class 里的纯内边距清零类(p-0 / px-0 …):由 frame.bleed 语义键替代(正则在真源 kit-layout.json#smells.framePaddingResetPattern)
|
|
217
|
+
const frameReset = new RegExp(KIT_LAYOUT_SMELLS.framePaddingResetPattern);
|
|
170
218
|
const out: KitSmellFinding[] = [];
|
|
171
|
-
const sites
|
|
172
|
-
|
|
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
|
-
}
|
|
219
|
+
const sites = classSites(input.facts);
|
|
220
|
+
const framePaths = new Set(input.facts.frameClasses.map((f) => f.path));
|
|
182
221
|
const seen = new Set<string>();
|
|
183
222
|
for (const site of sites) {
|
|
184
223
|
if (seen.has(site.path)) continue;
|
|
185
224
|
seen.add(site.path);
|
|
186
225
|
if (site.key === 'areaClass.panel' && decoration.test(site.value)) continue; // 039 专报
|
|
187
|
-
if (re.test(site.value))
|
|
226
|
+
if (re.test(site.value)) {
|
|
227
|
+
const base = `手写样式类「${site.value}」含尺寸 / 间距 / 颜色 / 栅格族`;
|
|
228
|
+
// 版心:手写 max-w-* 做内容限宽 → 语义键 page.max_width(档位 narrow / medium / wide / xwide=1440px / full,值在 kit-grammar.json#pageHeader.maxWidths)
|
|
229
|
+
const widthHint = site.key === 'class' && framePaths.has(site.path) && /(^|\s)max-w-\S+/.test(site.value)
|
|
230
|
+
? ';页面版心请写 page.max_width(narrow / medium / wide / xwide=1440px / full),不要手写 max-w-*' : '';
|
|
231
|
+
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}` });
|
|
232
|
+
}
|
|
188
233
|
}
|
|
189
234
|
return out;
|
|
190
235
|
};
|
|
@@ -203,6 +248,40 @@ const r038: KitSmellRule = (input) => {
|
|
|
203
248
|
return out;
|
|
204
249
|
};
|
|
205
250
|
|
|
251
|
+
// KIT-LAYOUT-044 页面写边界类(knowledge/Kit主题规则与算法.md §4 C13、裁决 E-5):边界只由容器与基本构件的配方画,
|
|
252
|
+
// 页面 / 应用声明的类键里写 border / ring / divide / shadow / rounded / outline 一律告警(areaClass.panel 的去卡片外观归 039 专报)
|
|
253
|
+
const r044: KitSmellRule = (input) => {
|
|
254
|
+
const boundary = new RegExp(KIT_LAYOUT_SMELLS.boundaryClassPattern);
|
|
255
|
+
const decoration = new RegExp(KIT_LAYOUT_SMELLS.decorationClassPattern);
|
|
256
|
+
const out: KitSmellFinding[] = [];
|
|
257
|
+
const seen = new Set<string>();
|
|
258
|
+
for (const site of classSites(input.facts)) {
|
|
259
|
+
if (seen.has(site.path)) continue;
|
|
260
|
+
seen.add(site.path);
|
|
261
|
+
if (site.key === 'areaClass.panel' && decoration.test(site.value)) continue;
|
|
262
|
+
const hit = site.value.split(/\s+/).filter((t) => t !== '' && boundary.test(t));
|
|
263
|
+
if (hit.length === 0) continue;
|
|
264
|
+
out.push({ path: site.path, message: `声明里写了边界类「${hit.join(' ')}」:线、框、圆角、阴影只由容器配方画——要一块面交给业务组件的区域 / 对象视图形态,表格外框写 collection.bordered,不要框的交给构成分析(plain),嵌套由层级规则去框` });
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/** 页面声明里全部类键的位置(页面框、产品、对象、视图、字段),036 / 044 共用 */
|
|
270
|
+
function classSites(facts: KitPageFacts): Array<{ key: string; value: string; path: string }> {
|
|
271
|
+
const sites: Array<{ key: string; value: string; path: string }> = [...facts.frameClasses];
|
|
272
|
+
for (const p of facts.products) {
|
|
273
|
+
sites.push(...p.classes);
|
|
274
|
+
for (const o of p.objects) {
|
|
275
|
+
sites.push(...o.classes);
|
|
276
|
+
for (const v of o.views) {
|
|
277
|
+
sites.push(...v.classes);
|
|
278
|
+
for (const f of allFieldsOf(v)) sites.push(...f.classes);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return sites;
|
|
283
|
+
}
|
|
284
|
+
|
|
206
285
|
const r039: KitSmellRule = (input) => {
|
|
207
286
|
const decoration = new RegExp(KIT_LAYOUT_SMELLS.decorationClassPattern);
|
|
208
287
|
const out: KitSmellFinding[] = [];
|
|
@@ -214,5 +293,5 @@ const r039: KitSmellRule = (input) => {
|
|
|
214
293
|
|
|
215
294
|
export const COMPOSITION_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
|
|
216
295
|
'026': r026, '027': r027, '028': r028, '029': r029, '030': r030, '031': r031, '032': r032, '033': r033,
|
|
217
|
-
'
|
|
296
|
+
'035': r035, '036': r036, '038': r038, '039': r039, '041': r041, '042': r042, '043': r043, '044': r044,
|
|
218
297
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 布局体检 · 表单 / 筛选 / 详情类气味(014–025、037)。谓词全部静态,阈值读 KIT_LAYOUT_SMELLS。
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { KIT_ARRANGE, arrangeFilter } from 'soma-foundation/arrange';
|
|
4
4
|
import { KIT_LAYOUT_SMELLS, kitRuleTableOf, kitTextWidthEm, solveKitSummary } from 'soma-foundation/kit-layout';
|
|
5
5
|
import type { KitFactField } from '../../object-renderer/layout-facts';
|
|
6
6
|
import { allFieldsOf, viewSites, type KitSmellFinding, type KitSmellRule } from './types';
|
|
@@ -111,14 +111,13 @@ const r020: KitSmellRule = (input) => {
|
|
|
111
111
|
|
|
112
112
|
const r021: KitSmellRule = (input) => {
|
|
113
113
|
const out: KitSmellFinding[] = [];
|
|
114
|
-
const factor = C['021'].params.overColsFactor;
|
|
115
|
-
const defaultCols = KIT_VIEW_DEFAULTS.filter.arrange.cols;
|
|
116
114
|
for (const s of viewSites(input.facts)) {
|
|
117
|
-
//
|
|
115
|
+
// 档位由排布引擎按字段数选定(字段数超过提交档上限即选「更多」档);只有作者显式写了 collapsible: false 才会不折叠
|
|
118
116
|
if (s.view.slot !== 'filter' || s.view.collapsible !== false) continue;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
}
|
|
122
121
|
}
|
|
123
122
|
return out;
|
|
124
123
|
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// 布局体检 · 表格与动作类气味(001–013)。谓词全部静态:页面事实 + 影子规划,阈值读 KIT_LAYOUT_SMELLS,不抄数字。
|
|
2
2
|
|
|
3
3
|
import { KIT_WIDTH_LIMITS } from 'soma-foundation/kit-limits';
|
|
4
|
-
import { KIT_LAYOUT_SMELLS, kitLabelTooLong, kitReferenceContainerRem,
|
|
4
|
+
import { KIT_LAYOUT_SMELLS, kitLabelTooLong, kitReferenceContainerRem, kitRuleTableOf } from 'soma-foundation/kit-layout';
|
|
5
|
+
import { KIT_ARRANGE, textWidthEm } from 'soma-foundation/arrange';
|
|
6
|
+
import { sparsityMetrics, sparsityVerdict, SPARSITY_THRESHOLDS } from 'soma-foundation/arrange/measure';
|
|
7
|
+
import { arrangeColumns } from 'soma-foundation/arrange/table';
|
|
8
|
+
import { KIT_TABLE_EXT, KIT_TREE_TABLE } from '../../object-renderer/defaults';
|
|
9
|
+
import { splitRowActions } from '../../object-renderer/table-actions';
|
|
5
10
|
import type { KitFactAction, KitFactObject } from '../../object-renderer/layout-facts';
|
|
6
11
|
import { allFieldsOf, viewSites, type KitLintInput, type KitSmellFinding, type KitSmellRule } from './types';
|
|
7
12
|
|
|
@@ -15,6 +20,15 @@ function rowActionsOf(object: KitFactObject, ids: readonly string[]): KitFactAct
|
|
|
15
20
|
return ids.flatMap((id) => (byId.has(id) ? [byId.get(id) as KitFactAction] : []));
|
|
16
21
|
}
|
|
17
22
|
|
|
23
|
+
/** 行动作的行内 / 「更多」切分:与发射(KitTableActions)同一个函数,体检不再另算一份。 */
|
|
24
|
+
function inlineSplitOf(actions: readonly KitFactAction[], cap: number): ReturnType<typeof splitRowActions> {
|
|
25
|
+
return splitRowActions(
|
|
26
|
+
actions.map((a) => ({ id: a.id, name: a.name, tone: a.primary ? 'primary' as const : a.danger ? 'danger' as const : 'neutral' as const, ...(a.more ? { more: true } : {}) })),
|
|
27
|
+
cap,
|
|
28
|
+
false,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
const r001: KitSmellRule = (input) => {
|
|
19
33
|
const out: KitSmellFinding[] = [];
|
|
20
34
|
for (const s of viewSites(input.facts)) {
|
|
@@ -26,8 +40,8 @@ const r001: KitSmellRule = (input) => {
|
|
|
26
40
|
const fact = allFieldsOf(s.view).find((f) => f.name === col.field);
|
|
27
41
|
if (fact === undefined || fact.width === null) continue;
|
|
28
42
|
const have = (free * fact.width) / parts;
|
|
29
|
-
if (have + 0.0005 < col.
|
|
30
|
-
out.push({ path: fact.path, message: `列「${fact.label}」写了 width: ${fact.width},在参考容器里约 ${have.toFixed(1)}rem,小于内容需求的最小宽 ${col.
|
|
43
|
+
if (have + 0.0005 < col.minRem) {
|
|
44
|
+
out.push({ path: fact.path, message: `列「${fact.label}」写了 width: ${fact.width},在参考容器里约 ${have.toFixed(1)}rem,小于内容需求的最小宽 ${col.minRem.toFixed(1)}rem,会被压窄截断` });
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
47
|
}
|
|
@@ -40,7 +54,7 @@ const r002: KitSmellRule = (input) => {
|
|
|
40
54
|
for (const s of viewSites(input.facts)) {
|
|
41
55
|
const plan = input.plan.views[s.planKey];
|
|
42
56
|
if (plan === undefined || plan.kind !== 'table' || plan.mode !== 'parts') continue;
|
|
43
|
-
const sum = plan.columns.reduce((a, c) => a + c.
|
|
57
|
+
const sum = plan.columns.reduce((a, c) => a + c.idealRem, 0);
|
|
44
58
|
if (sum < max * kitReferenceContainerRem()) out.push({ path: s.view.path, message: `每列都写了 width,而各列理想宽之和只有 ${sum.toFixed(1)}rem(不足参考宽的 ${Math.round(max * 100)}%),均分会把短值列拉稀` });
|
|
45
59
|
}
|
|
46
60
|
return out;
|
|
@@ -54,11 +68,13 @@ const r003: KitSmellRule = (input) => {
|
|
|
54
68
|
for (const s of viewSites(input.facts)) {
|
|
55
69
|
if (!isTable(s.view)) continue;
|
|
56
70
|
const actions = rowActionsOf(s.object, s.view.rowActionIds);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
71
|
+
if (actions.every((a) => a.more)) continue;
|
|
72
|
+
// 行内平铺的实际集合 = 发射用的同一个切分(引擎保留序 + 危险动作默认收进「更多」),不再各判各的
|
|
73
|
+
const split = inlineSplitOf(actions, cap);
|
|
74
|
+
const flat = split.inline;
|
|
75
|
+
const hasMore = split.folded.length > 0;
|
|
76
|
+
// 行操作是文字链接形态:估宽用文字链接的度量(字数 × 字宽 + 项间距 + 「更多」触发钮),与实际投影同一个引擎估算,不按按钮宽
|
|
77
|
+
const need = arrangeColumns({ fontRem: KIT_LAYOUT_SMELLS.reference.bodyFontRem, columns: [], actions: { labelEms: flat.map((a) => textWidthEm(a.name)), hasMore } }).actionsRem ?? 0;
|
|
62
78
|
const colParts = flat.length >= parts.actionsWideFromInline ? parts.actionsWide : parts.actions;
|
|
63
79
|
const have = (kitReferenceContainerRem() * colParts) / KIT_WIDTH_LIMITS.totalParts;
|
|
64
80
|
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} 份),放不下` });
|
|
@@ -126,12 +142,16 @@ const r008: KitSmellRule = (input) => {
|
|
|
126
142
|
const r009: KitSmellRule = (input) => {
|
|
127
143
|
const out: KitSmellFinding[] = [];
|
|
128
144
|
if (input.plan.rules >= 1) return out;
|
|
129
|
-
const min = kitRuleTableOf().rowActions.dangerInMoreMinActions;
|
|
130
145
|
for (const s of viewSites(input.facts)) {
|
|
131
146
|
if (!isTable(s.view)) continue;
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
147
|
+
const actions = rowActionsOf(s.object, s.view.rowActionIds);
|
|
148
|
+
// 按发射的实际内联集合判:危险动作内联时置末并与前一项分隔(有分隔即合规),多个危险动作默认收进「更多」;
|
|
149
|
+
// 仍违规的只剩「整组都是危险动作」(引擎不折叠)并排平铺
|
|
150
|
+
const split = inlineSplitOf(actions, C['008'].params.inlineCap);
|
|
151
|
+
const dangerInline = split.inline.filter((a) => a.tone === 'danger' && !split.separated.has(a.id));
|
|
152
|
+
const sole = split.inline.every((a) => a.tone === 'danger');
|
|
153
|
+
if (!(sole && dangerInline.length >= 2)) continue;
|
|
154
|
+
for (const a of dangerInline) out.push({ path: actions.find((x) => x.id === a.id)?.path ?? s.view.path, message: `危险动作「${a.name}」与其他危险动作并排平铺(整组都是危险动作,无处分隔),应拆出非危险动作或放进「更多」` });
|
|
135
155
|
}
|
|
136
156
|
return out;
|
|
137
157
|
};
|
|
@@ -186,9 +206,73 @@ const r013: KitSmellRule = (input) => {
|
|
|
186
206
|
return out;
|
|
187
207
|
};
|
|
188
208
|
|
|
209
|
+
/**
|
|
210
|
+
* 内容宽(rem):能从声明静态知道的列才有——枚举 / 布尔看最长选项文案 + 药丸内边距、日期类取真源日期内容宽、有长度上限的文本 / 标识取 上限 × 字宽;
|
|
211
|
+
* 数字 / 金额 / 无长度上限的文本在编译期不知道值,返回 0(不参与列宽 / 内容宽之比)。
|
|
212
|
+
*/
|
|
213
|
+
function contentRemOf(f: { readonly type: string; readonly maxLen: number | null; readonly options?: readonly string[] }): number {
|
|
214
|
+
const font = KIT_LAYOUT_SMELLS.reference.bodyFontRem;
|
|
215
|
+
const A = KIT_ARRANGE.columns;
|
|
216
|
+
if (f.type === 'enum' || f.type === 'enums' || f.type === 'bool') {
|
|
217
|
+
const em = (f.options ?? []).reduce((m, o) => Math.max(m, textWidthEm(o)), 0);
|
|
218
|
+
return em > 0 ? em * font + A.pillPadRem : 0;
|
|
219
|
+
}
|
|
220
|
+
if (KIT_TREE_TABLE.columnWeightRules.dateTypes.includes(f.type)) return (KIT_TABLE_EXT.narrowGrid.dateEms[f.type] ?? 0) * font;
|
|
221
|
+
if ((f.type === 'text' || f.type === 'longtext') && f.maxLen !== null) return f.maxLen * A.charEm * font;
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 表格稀疏 / 拥挤(IR 盒子):列轨求出的每个定宽列宽 / 内容宽之比超过 `measure.maxWidthRatio`(与渲染测量同一份 `sparsityMetrics` / `sparsityVerdict`),
|
|
227
|
+
* 说明该列比内容宽得多(列内大片空白);各列最小宽之和超过参考容器宽为拥挤(放不下,横滚)。主列吸收余量、其留白是设计,不计。
|
|
228
|
+
*/
|
|
229
|
+
const r040: KitSmellRule = (input) => {
|
|
230
|
+
const out: KitSmellFinding[] = [];
|
|
231
|
+
const font = KIT_LAYOUT_SMELLS.reference.bodyFontRem;
|
|
232
|
+
const idName = new RegExp(KIT_ARRANGE.columns.idNamePattern);
|
|
233
|
+
for (const s of viewSites(input.facts)) {
|
|
234
|
+
if (!isTable(s.view)) continue;
|
|
235
|
+
const fields = allFieldsOf(s.view);
|
|
236
|
+
if (fields.length === 0) continue;
|
|
237
|
+
const solved = arrangeColumns({
|
|
238
|
+
fontRem: font,
|
|
239
|
+
columns: fields.map((f) => {
|
|
240
|
+
const em = (f.options ?? []).reduce((m, o) => Math.max(m, textWidthEm(o)), 0);
|
|
241
|
+
return {
|
|
242
|
+
key: f.name,
|
|
243
|
+
type: f.type === 'text' && idName.test(f.name) ? 'id' : f.type,
|
|
244
|
+
labelEm: textWidthEm(f.label),
|
|
245
|
+
...(em > 0 ? { optionEm: em } : {}),
|
|
246
|
+
...(f.maxLen !== null ? { maxLen: f.maxLen } : {}),
|
|
247
|
+
};
|
|
248
|
+
}),
|
|
249
|
+
});
|
|
250
|
+
if (solved.minRem > kitReferenceContainerRem()) {
|
|
251
|
+
out.push({ path: s.view.path, message: `各列最小宽之和 ${solved.minRem.toFixed(1)}rem 超过参考容器 ${kitReferenceContainerRem().toFixed(1)}rem,表格拥挤、要横向滚动` });
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const columnWidths: number[] = [];
|
|
255
|
+
const contentWidths: number[] = [];
|
|
256
|
+
const names: string[] = [];
|
|
257
|
+
solved.columns.forEach((c, i) => {
|
|
258
|
+
const content = contentRemOf(fields[i]!);
|
|
259
|
+
if (c.grow || content <= 0) return;
|
|
260
|
+
columnWidths.push(c.ideal);
|
|
261
|
+
contentWidths.push(content);
|
|
262
|
+
names.push(fields[i]!.label);
|
|
263
|
+
});
|
|
264
|
+
const metrics = sparsityMetrics({ width: 1, height: 1, boxes: [], dividers: [], columnWidths, contentWidths });
|
|
265
|
+
if (sparsityVerdict(metrics).violations.includes('widthRatio')) {
|
|
266
|
+
const worst = columnWidths.reduce((best, w, i) => (w / contentWidths[i]! > columnWidths[best]! / contentWidths[best]! ? i : best), 0);
|
|
267
|
+
out.push({ path: s.view.path, message: `列「${names[worst]}」的列宽是内容宽的 ${metrics.widthRatioMax.toFixed(1)} 倍(上限 ${SPARSITY_THRESHOLDS.maxWidthRatio}),列内空白过大` });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return out;
|
|
271
|
+
};
|
|
272
|
+
|
|
189
273
|
export const TABLE_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
|
|
190
274
|
'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,
|
|
275
|
+
'009': r009, '010': r010, '011': r011, '012': r012, '013': r013, '040': r040,
|
|
192
276
|
};
|
|
193
277
|
|
|
194
278
|
export type { KitLintInput };
|