soma-kit 0.1.13 → 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.
- package/package.json +3 -3
- package/spec/generated/kit-app.schema.json +14 -0
- package/spec/generated/kit-page.schema.json +25 -0
- package/spec/kit-grammar.json +178 -27
- package/spec/kit-grammar.schema.json +1 -3
- package/src/app/app-config.ts +10 -4
- package/src/app/index.ts +13 -1
- package/src/app/kit-view-context.ts +19 -2
- package/src/app/server-pages.ts +5 -1
- package/src/app/server.ts +15 -5
- package/src/base/button.ts +5 -3
- package/src/base/end-edge.ts +14 -2
- package/src/base/gap-value.ts +24 -4
- package/src/base/illustrations.ts +2 -1
- package/src/base/index.ts +5 -0
- package/src/base/menu-button.ts +10 -23
- package/src/base/popover.ts +5 -4
- package/src/base/segmented.ts +14 -4
- package/src/base/shared.ts +11 -13
- package/src/base/state-panel.ts +34 -13
- package/src/base/tag.ts +18 -13
- package/src/base/text.ts +1 -1
- package/src/base/upload.ts +5 -4
- package/src/biz/approval-desk/shell.ts +8 -7
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +3 -2
- package/src/biz/category-crud/shell.ts +4 -3
- package/src/biz/checkout-page/shell.ts +9 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +12 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/master-sub/compile.ts +114 -15
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +3 -2
- package/src/biz/master-sub/shell.ts +95 -63
- package/src/biz/multi-board/compile.ts +164 -9
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +1 -1
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +91 -23
- package/src/biz/notification-center/shell.ts +6 -5
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -2
- package/src/biz/page-templates/sign-in-page/shell.ts +14 -14
- package/src/biz/record-detail/shell.ts +8 -7
- package/src/biz/settings-center/shell.ts +8 -7
- package/src/biz/shared/compile-helpers.ts +82 -3
- package/src/biz/shared/overlay-compile.ts +46 -4
- package/src/biz/shared/overlay-shell.ts +8 -6
- package/src/biz/single-form/shell.ts +6 -4
- package/src/biz/standard-crud/compile.ts +14 -1
- package/src/biz/standard-crud/shell.ts +18 -27
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +11 -9
- package/src/biz/types.ts +6 -1
- package/src/cli/layout-cli.ts +7 -7
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/compile-page.ts +15 -4
- package/src/compile/component-candidates.ts +2 -0
- package/src/compile/fragment.ts +11 -0
- package/src/compile/layout-lint/rules-composition.ts +55 -6
- 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 +189 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/styles.ts +11 -1
- package/src/compile/types.ts +3 -1
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +3 -1
- package/src/data/approval-flow.ts +4 -1
- package/src/data/assignment-picker.ts +9 -4
- package/src/data/async-result-panel.ts +1 -1
- package/src/data/calendar.ts +7 -2
- package/src/data/carousel.ts +2 -0
- package/src/data/chart.ts +609 -42
- package/src/data/checklist.ts +4 -1
- package/src/data/comment-thread.ts +2 -1
- package/src/data/confirm-dialog.ts +4 -10
- package/src/data/field-mapper.ts +4 -1
- package/src/data/flow-editor.ts +2 -1
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +187 -25
- package/src/data/hero.ts +2 -0
- package/src/data/index.ts +10 -3
- package/src/data/item-list.ts +10 -3
- package/src/data/kanban.ts +3 -1
- package/src/data/matrix.ts +391 -0
- package/src/data/menu.ts +23 -11
- package/src/data/mockup.ts +3 -3
- package/src/data/modal-dialog.ts +118 -18
- package/src/data/navbar.ts +3 -1
- package/src/data/notice-list.ts +52 -19
- package/src/data/object-form.ts +128 -112
- package/src/data/pager.ts +3 -2
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +4 -1
- package/src/data/permission-tree.ts +6 -2
- package/src/data/pricing-table.ts +2 -1
- package/src/data/record-card.ts +18 -6
- package/src/data/resident.ts +8 -0
- package/src/data/row-editor.ts +2 -2
- package/src/data/rule-builder.ts +9 -4
- package/src/data/shape-util.ts +15 -14
- package/src/data/stat-group.ts +313 -69
- package/src/data/static-lazy.ts +4 -0
- package/src/data/static-registry.ts +6 -0
- package/src/data/survey.ts +4 -1
- package/src/data/system-switcher.ts +2 -1
- package/src/data/tour-guide.ts +2 -1
- package/src/data/transfer.ts +6 -2
- package/src/data/tree-table.ts +7 -5
- package/src/data/tree.ts +1 -1
- package/src/data/virtual-rows.ts +5 -4
- package/src/data/wrapped-candidates.ts +22 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +6 -14
- package/src/frames/shared.ts +20 -4
- package/src/frames/tabs-frame/shell.ts +8 -6
- package/src/frames/top-main-frame.ts +1 -1
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +41 -25
- package/src/generated/kit-grammar-runtime.ts +175 -28
- package/src/i18n/kit-text.ts +27 -0
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +49 -19
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +34 -13
- package/src/object-renderer/collection-table.ts +133 -65
- package/src/object-renderer/collection.ts +72 -59
- package/src/object-renderer/defaults.ts +2 -5
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +116 -63
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +9 -1
- package/src/object-renderer/layout-plan.ts +136 -43
- package/src/object-renderer/layout-plan.types.ts +42 -5
- package/src/object-renderer/parts.ts +7 -259
- package/src/object-renderer/render-object.ts +59 -46
- package/src/object-renderer/table-actions.ts +72 -40
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +51 -20
- package/src/object-renderer/types.ts +7 -7
- package/src/recipes/container.ts +31 -0
- package/src/recipes/control.ts +57 -155
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +23 -0
- package/src/recipes/overlay.ts +46 -1
- package/src/recipes/placeholder.ts +20 -4
- package/src/recipes/rail-grid.ts +3 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +12 -22
- package/src/recipes/status.ts +8 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +112 -6
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +3 -3
- package/src/recipes/typography.ts +23 -42
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +13 -2
- package/src/theme/kit-theme.tpl +13 -2
- package/src/theme/nine-dim-structure.ts +77 -10
- package/src/theme/surface-layers.ts +6 -1
- package/src/theme/theme-tokens.ts +12 -5
- package/src/theme/typography.ts +21 -17
package/src/data/stat-group.ts
CHANGED
|
@@ -4,34 +4,58 @@
|
|
|
4
4
|
// `map` 是「组件期望的键 -> 数据里的键」的对照(浅映射,不改源数据)。
|
|
5
5
|
// 没写 items 时:有 map 就按 map 的键序展示(label = 键名);也没有 map 就展示数据里全部数值字段。
|
|
6
6
|
// 点某块抛 `select { item: { key, label, value } }`。
|
|
7
|
+
// 单项三态(由数据给,页面不写逻辑):items[].state = ready(缺省)/ missing / error(另有 gap / unknown 旧词,走缺口胶囊,不变);
|
|
8
|
+
// reason 是 missing / error 时显示的原因文本(取自数据,单行截断、被截断时悬停出全文);三态都落在既有标题 / 指标 / 操作三槽里,
|
|
9
|
+
// missing = 指标位「—」+ 状态圆点与原因,error = 指标位状态圆点与原因(无大色块、无新增图标)。
|
|
10
|
+
// items[].action(事件名):整块可点,除 select 外再抛 `action { key, action, item }`;error 态的块不可下钻,忽略 action(missing 态保留)。
|
|
11
|
+
// items[].retry(事件名):error 态在操作槽出文字钮「重试」,点击抛 `retry { key, retry, item }`,不触发 select / action。
|
|
12
|
+
// 带重试钮的块不能是原生 <button>(按钮里不能套按钮),画成 div role=group(不可点,只有重试钮可点)。
|
|
13
|
+
// 读屏:可点块的名称 = 「标签 数值」,missing / error 的名称 = 「标签,原因」。
|
|
7
14
|
// 列数按容器宽度档(容器查询)与项数选:每档只取不让末行落单一项的列数,无解的项数让末块拉伸占满整行;
|
|
8
15
|
// 规则与各档数字只在 soma-design 真源(kit-limits.json 的 statGrid),选列数的函数是 soma-foundation/data/values 的 gridFillPlanOf,这里只把结果写成类串。
|
|
9
16
|
|
|
10
17
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
18
|
import { gridFillPlanOf, type SomaGridFillPlan } from 'soma-foundation/data/values';
|
|
12
19
|
import { KIT_STAT_GRID } from 'soma-foundation/kit-limits';
|
|
20
|
+
import { KIT_ARRANGE } from 'soma-foundation/arrange';
|
|
13
21
|
import { createKitController, formatValue, joinClass, num, str } from '../base/shared';
|
|
14
22
|
import { kitIcon } from '../base/icons';
|
|
15
23
|
import { trendTone } from '../base/trend-tone';
|
|
16
24
|
import { TAG_CLASS } from '../base/tag';
|
|
17
25
|
import { gapMarkerNode } from '../base/gap-value';
|
|
18
26
|
import { safeHref } from '../base/link';
|
|
19
|
-
import {
|
|
27
|
+
import { KIT_STATUS_TONE_TEXT_KEY, statusToneOrNull } from '../base/status-tone';
|
|
20
28
|
import { classCandidates } from '../base/class-candidates';
|
|
21
29
|
import { kitText } from '../i18n/kit-text';
|
|
30
|
+
import { KIT_READ_STATE_PROP_DEFS, KIT_STATE_PANEL_CLASS_CANDIDATES, paintKitStatePanel } from '../base/state-panel';
|
|
22
31
|
import { KIT_TREND_LINE_CLASS_CANDIDATES, sparklineSvg, trendToneOf, trendValuesOf } from './trend-line';
|
|
23
32
|
import { KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE, kitTypographyRecipe } from '../recipes';
|
|
24
33
|
import { KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES, kitRailGridRecipe, markKitRail } from '../recipes/rail-grid';
|
|
34
|
+
import { KIT_SUMMARY_EMPTY_ATTR } from '../recipes/container';
|
|
25
35
|
import { markKitSlot, markKitSlotGrid, slotCountOf } from '../recipes/slot-align';
|
|
36
|
+
import {
|
|
37
|
+
KIT_STAT_GROUP_REASON_MIN, KIT_STAT_PLACEHOLDER, KIT_STAT_WARN_DOT_CLASS, KIT_STAT_RETRY_CLASS, KIT_STAT_STATE_CLASS_CANDIDATES, KIT_STAT_STATE_REASON,
|
|
38
|
+
kitStatGroupNoteClass, kitStatStateRowClass, statStateOf, type KitStatState,
|
|
39
|
+
} from '../recipes/stat-state';
|
|
26
40
|
import {
|
|
27
41
|
KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, KIT_NOTICE_ICON, KIT_NOTICE_SR_ONLY, KIT_STAT_EXTRA_CLASS_CANDIDATES, KIT_STAT_FLAGS_ROW,
|
|
28
|
-
|
|
42
|
+
KIT_STAT_VALUES_NUM, KIT_STAT_VALUES_ROW,
|
|
29
43
|
} from '../recipes/status';
|
|
30
44
|
|
|
31
45
|
const WRAP_CLASS = '@container';
|
|
32
46
|
// 导轨拼合(recipes/rail-grid):块并进一个容器,块间只有 1px 通栏细线,块自己不描边不画卡片;
|
|
33
47
|
// 容器的列间距 / 行间距 / 内边距 / 底色都由层内规则(真源 structure.railGrid)给,这里不写 gap-* / p-* / 边框类
|
|
34
|
-
|
|
48
|
+
/** 导轨网格的轨数(排布引擎真源 kit-arrange.rail.tracks) */
|
|
49
|
+
const KIT_RAIL_TRACKS: number = KIT_ARRANGE.rail.tracks;
|
|
50
|
+
const GRID_CLASS = `${kitRailGridRecipe().container} grid-cols-${KIT_RAIL_TRACKS}`;
|
|
51
|
+
/** 一个块可能的跨轨数:整行块(允许列数)与末行块(1..最大列数-1 项等分)的并集 */
|
|
52
|
+
function railSpans(): number[] {
|
|
53
|
+
const set = new Set<number>();
|
|
54
|
+
const maxCols = Math.max(...KIT_STAT_GRID.allowed);
|
|
55
|
+
for (const k of KIT_STAT_GRID.allowed) set.add(KIT_RAIL_TRACKS / k);
|
|
56
|
+
for (let r = 1; r < maxCols; r += 1) set.add(KIT_RAIL_TRACKS / r);
|
|
57
|
+
return [...set].sort((a, b) => a - b);
|
|
58
|
+
}
|
|
35
59
|
const BLOCK_CLASS = `${kitRailGridRecipe().cell} appearance-none border-0 transition-colors state-layer active:opacity-80 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring`;
|
|
36
60
|
const LABEL_CLASS = 'text-xs font-medium text-fg-muted';
|
|
37
61
|
/** 指标主数值样式:对齐规则卡 30px 大数字 + font-bold tabular-nums */
|
|
@@ -40,51 +64,78 @@ export const STAT_VALUE_CLASS = kitTypographyRecipe('statValue');
|
|
|
40
64
|
// 跨卡片的水平对齐由 subgrid 给,不支持 subgrid 时由层内规则退化为 flex 纵向 + 指标槽贴底
|
|
41
65
|
const METRIC_SLOT_CLASS = 'flex min-w-0 flex-col gap-1';
|
|
42
66
|
const VALUE_CLASS = STAT_VALUE_CLASS;
|
|
43
|
-
|
|
67
|
+
/**
|
|
68
|
+
* 项语气 -> 数值文字色(彩色文字只配 on-soft);info / neutral 不着色。
|
|
69
|
+
* warning 不做大号文字色(R10 / 评审 §1.2「状态」:亮黄橙在白底压到 4.5:1 必然发褐):数字保持中性墨色,语义由指标名前的 6px 警告圆点 + 读屏文字承担。
|
|
70
|
+
*/
|
|
71
|
+
const STAT_TONE_VALUE: Readonly<Partial<Record<string, string>>> = Object.freeze({
|
|
72
|
+
danger: 'text-danger-on-soft', success: 'text-success-on-soft',
|
|
73
|
+
});
|
|
74
|
+
const STAT_WARN_DOT_CLASS = KIT_STAT_WARN_DOT_CLASS;
|
|
75
|
+
// 数值行:数值 + 单位 + 变化率 / 对比期 / 提示同一条基线(没有副文本的块不为它留第三行,块高只由数值行决定)
|
|
76
|
+
const VALUE_ROW_CLASS = 'flex flex-wrap items-baseline gap-x-1 gap-y-0.5';
|
|
44
77
|
const UNIT_CLASS = 'text-xs font-normal text-fg-muted';
|
|
45
78
|
|
|
46
79
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
47
80
|
export const KIT_STAT_GROUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
48
|
-
'@container', 'grid',
|
|
81
|
+
'@container', 'grid', `grid-cols-${KIT_RAIL_TRACKS}`, 'min-w-0', 'appearance-none', 'border-0', 'bg-primary-soft',
|
|
49
82
|
'flex', 'flex-col', 'gap-1', 'text-start',
|
|
50
83
|
'transition-colors', 'active:opacity-80', 'font-medium', 'font-normal', 'font-bold', 'tabular-nums',
|
|
51
84
|
'state-layer', 'focus-visible:outline-none', 'focus-visible:ring-1', 'focus-visible:ring-inset', 'focus-visible:ring-ring',
|
|
52
85
|
...KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES,
|
|
53
86
|
'text-sm', 'text-fg-muted', 'text-2xl', 'text-stat-value', 'font-title', 'tracking-tight', 'font-semibold', 'text-fg',
|
|
54
87
|
'items-center', 'items-baseline', 'flex-wrap', 'rounded-md', 'px-1.5', 'py-0.5', 'text-xs', 'inline-flex',
|
|
88
|
+
// 数值行(VALUE_ROW_CLASS)与副文本(FOOT_CLASS)
|
|
89
|
+
'gap-x-1', 'gap-y-0.5', 'ms-1',
|
|
55
90
|
...Object.values(TAG_CLASS.sm).flatMap((s) => s.split(' ')),
|
|
56
|
-
'bg-success-soft', 'text-success-on-soft', 'bg-danger-soft', 'text-danger-on-soft', 'bg-surface-sunken', 'text-fg-subtle', 'gap-2', 'border-primary', 'bg-primary-soft',
|
|
57
|
-
...KIT_TREND_LINE_CLASS_CANDIDATES, 'h-8', 'w-full',
|
|
91
|
+
'bg-success-soft', 'text-success-on-soft', 'text-warning-on-soft', 'bg-danger-soft', 'text-danger-on-soft', 'bg-surface-sunken', 'text-fg-subtle', 'gap-2', 'border-primary', 'bg-primary-soft',
|
|
92
|
+
...KIT_TREND_LINE_CLASS_CANDIDATES, 'h-8', 'w-full', ...STAT_WARN_DOT_CLASS.split(' '),
|
|
93
|
+
// 整块读取失败面板(K6)
|
|
94
|
+
...KIT_STATE_PANEL_CLASS_CANDIDATES,
|
|
58
95
|
// 项扩展(语气 / 多值 / 标记 / 缺口)自带的类:来自 recipes/status
|
|
59
96
|
...classCandidates(Object.values(KIT_NOTICE_ICON), KIT_NOTICE_SR_ONLY, KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, KIT_STAT_EXTRA_CLASS_CANDIDATES),
|
|
97
|
+
// 三态(missing / error):状态行、圆点、原因截断、重试钮、可点块指针
|
|
98
|
+
...KIT_STAT_STATE_CLASS_CANDIDATES,
|
|
60
99
|
// 各档列数与末块拉伸的全部可能类(档名 x 允许列数取自真源,Tailwind 静态扫描不到运行期拼的类名,所以在此列全)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
]),
|
|
100
|
+
// 导轨网格固定 tracks 轨;块按档跨 tracks / 列数(整行块)或 tracks / 末行项数(末行块)轨
|
|
101
|
+
`col-span-${KIT_RAIL_TRACKS}`,
|
|
102
|
+
...Object.keys(KIT_STAT_GRID.tierCols).flatMap((tier) => railSpans().map((s) => `@${tier}:col-span-${s}`)),
|
|
65
103
|
]);
|
|
66
104
|
|
|
67
105
|
/**
|
|
68
106
|
* 栅格计划 -> 类串:网格类按档升序只写列数变化处(窄屏基准 1 列);末块类只写拉伸标记变化处(拉伸 = 占满整行,退出 = 回到单列宽)。
|
|
69
107
|
* 计划由 gridFillPlanOf 给出,这里只做格式化。
|
|
70
108
|
*/
|
|
71
|
-
export function statGridClassesOf(plan: SomaGridFillPlan): { grid: string;
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
export function statGridClassesOf(plan: SomaGridFillPlan, count: number): { grid: string; cell: (index: number) => string } {
|
|
110
|
+
const tiers = Object.keys(KIT_STAT_GRID.tierCols);
|
|
111
|
+
// 每个块的跨轨数(每档):整行块跨 tracks / 列数;末行不满时末行各项等分该行,跨 tracks / 末行项数。窄屏基准 1 列 = 跨满。
|
|
112
|
+
const spanOf = (index: number, tier: string): number => {
|
|
113
|
+
const cols = plan.cols[tier] ?? 1;
|
|
114
|
+
const tail = plan.tail[tier] ?? 0;
|
|
115
|
+
return KIT_RAIL_TRACKS / (tail > 0 && index >= count - tail ? tail : cols);
|
|
116
|
+
};
|
|
117
|
+
const cache = new Map<string, string>();
|
|
118
|
+
const cell = (index: number): string => {
|
|
119
|
+
const spans = tiers.map((tier) => spanOf(index, tier));
|
|
120
|
+
const key = spans.join(',');
|
|
121
|
+
const hit = cache.get(key);
|
|
122
|
+
if (hit !== undefined) return hit;
|
|
123
|
+
const out: string[] = [];
|
|
124
|
+
let prev = KIT_RAIL_TRACKS;
|
|
125
|
+
tiers.forEach((tier, i) => {
|
|
126
|
+
const s = spans[i]!;
|
|
127
|
+
if (s !== prev) { out.push(`@${tier}:col-span-${s}`); prev = s; }
|
|
128
|
+
});
|
|
129
|
+
const cls = out.join(' ');
|
|
130
|
+
cache.set(key, cls);
|
|
131
|
+
return cls;
|
|
132
|
+
};
|
|
133
|
+
return { grid: GRID_CLASS, cell };
|
|
83
134
|
}
|
|
84
135
|
|
|
85
|
-
/** 一排统计块的类:columns
|
|
86
|
-
export function statGridClasses(count: number, columns: number | null | undefined): { grid: string;
|
|
87
|
-
return statGridClassesOf(gridFillPlanOf(KIT_STAT_GRID, count, columns ?? undefined));
|
|
136
|
+
/** 一排统计块的类:columns 是作者显式写的列数(登记过的按登记,其余正整数是上限),各档列数由排布引擎按容器宽度档与项数求解;末行不满时各项等分末行。 */
|
|
137
|
+
export function statGridClasses(count: number, columns: number | null | undefined): { grid: string; cell: (index: number) => string } {
|
|
138
|
+
return statGridClassesOf(gridFillPlanOf(KIT_STAT_GRID, count, columns ?? undefined), count);
|
|
88
139
|
}
|
|
89
140
|
|
|
90
141
|
export interface KitStatItem {
|
|
@@ -123,8 +174,15 @@ export interface KitStatItem {
|
|
|
123
174
|
href: string;
|
|
124
175
|
/** 地址取自数据里的键 */
|
|
125
176
|
hrefKey: string;
|
|
126
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* 状态(由数据给;空 = 不指定):ready(缺省)/ missing / error 三态;另有 gap / unknown(缺口胶囊,主数值位画标记而不是值)。
|
|
179
|
+
* missing / error 时指标位画状态圆点 + 原因文字(reason),error 且有 retry 时操作槽出「重试」。
|
|
180
|
+
*/
|
|
127
181
|
state: string;
|
|
182
|
+
/** 整块可点:事件名;点击除 select 外再抛 action { key, action, item };error 态忽略(不可下钻) */
|
|
183
|
+
action: string;
|
|
184
|
+
/** error 态的重试:事件名;操作槽出「重试」钮,点击抛 retry { key, retry, item },不触发 select / action */
|
|
185
|
+
retry: string;
|
|
128
186
|
/** 状态取自数据里的键 */
|
|
129
187
|
stateKey: string;
|
|
130
188
|
/** 缺口 / 未知原因(字面量);值缺失且给了原因时按缺口画 */
|
|
@@ -135,6 +193,11 @@ export interface KitStatItem {
|
|
|
135
193
|
values: Array<{ key: string; label: string; format: string; unit: string }>;
|
|
136
194
|
/** 标记(小标签)取自数据里的键:字符串数组或 [{ label, tone? }] */
|
|
137
195
|
flagsKey: string;
|
|
196
|
+
/**
|
|
197
|
+
* 自带数据的项(数组写法):项自己就是数据行(value / unit / state / reason / hint / href / tone / values / flags 都在行上),
|
|
198
|
+
* 渲染时「数据」取这一行、不再经 map 对照;扁平写法(data 对象 + 逐项 items)为 null。两种写法走同一条渲染路径。
|
|
199
|
+
*/
|
|
200
|
+
inline: Record<string, unknown> | null;
|
|
138
201
|
}
|
|
139
202
|
|
|
140
203
|
// 趋势徽标直接复用基础组件 Tag 的 sm 档类串
|
|
@@ -143,7 +206,7 @@ const TREND_UP_CLASS: Record<'good' | 'bad' | 'flat', string> = {
|
|
|
143
206
|
bad: TAG_CLASS.sm.danger,
|
|
144
207
|
flat: TAG_CLASS.sm.neutral,
|
|
145
208
|
};
|
|
146
|
-
const FOOT_CLASS = 'flex flex-wrap items-
|
|
209
|
+
const FOOT_CLASS = 'ms-1 inline-flex flex-wrap items-baseline gap-2';
|
|
147
210
|
const COMPARE_CLASS = 'text-xs text-fg-muted';
|
|
148
211
|
const HINT_CLASS = 'text-xs text-fg-subtle';
|
|
149
212
|
|
|
@@ -160,8 +223,9 @@ function resolveCompareValue(rec: Record<string, unknown>): string | number | un
|
|
|
160
223
|
return undefined;
|
|
161
224
|
}
|
|
162
225
|
|
|
163
|
-
function itemOf(key: string, label: string, rec: Record<string, unknown
|
|
226
|
+
function itemOf(key: string, label: string, rec: Record<string, unknown>, inline: boolean = false): KitStatItem {
|
|
164
227
|
return {
|
|
228
|
+
inline: inline ? rec : null,
|
|
165
229
|
key,
|
|
166
230
|
label,
|
|
167
231
|
format: str(rec.format),
|
|
@@ -183,6 +247,8 @@ function itemOf(key: string, label: string, rec: Record<string, unknown>): KitSt
|
|
|
183
247
|
hrefKey: str(rec.hrefKey),
|
|
184
248
|
state: str(rec.state),
|
|
185
249
|
stateKey: str(rec.stateKey),
|
|
250
|
+
action: str(rec.action),
|
|
251
|
+
retry: str(rec.retry),
|
|
186
252
|
reason: str(rec.reason),
|
|
187
253
|
reasonKey: str(rec.reasonKey),
|
|
188
254
|
values: Array.isArray(rec.values)
|
|
@@ -269,17 +335,27 @@ function resolveMappedString(
|
|
|
269
335
|
return literalOrKey;
|
|
270
336
|
}
|
|
271
337
|
|
|
272
|
-
/**
|
|
273
|
-
|
|
338
|
+
/** 一项的取数范围:自带数据的项取项本身(不经 map),扁平项取全局 data + map */
|
|
339
|
+
function statScopeOf(item: KitStatItem, map: Record<string, unknown>, data: Record<string, unknown>): { map: Record<string, unknown>; data: Record<string, unknown> } {
|
|
340
|
+
return item.inline !== null ? { map: {}, data: item.inline } : { map, data };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 决定展示哪几项(纯函数,便于单测)。
|
|
345
|
+
* 来源三种(同一条渲染路径):① items_from 指向数据里的数组:每个元素就是一项(自带 key / label / value 等);
|
|
346
|
+
* ② items 数组(常由展示对象成员绑定):元素带 value 即自带数据,否则按键从 data 取(扁平写法);③ 没写 items:map 键序 / data 全部数值字段。
|
|
347
|
+
*/
|
|
348
|
+
export function statItemsOf(itemsRaw: unknown, mapRaw: unknown, data: Record<string, unknown>, from: string = ''): KitStatItem[] {
|
|
274
349
|
const map = recOf(mapRaw);
|
|
275
|
-
|
|
350
|
+
const rows = from !== '' && Array.isArray(data[from]) ? (data[from] as unknown[]) : null;
|
|
351
|
+
if (rows !== null || (Array.isArray(itemsRaw) && itemsRaw.length > 0)) {
|
|
276
352
|
const out: KitStatItem[] = [];
|
|
277
|
-
for (const raw of itemsRaw) {
|
|
353
|
+
for (const [i, raw] of (rows ?? (itemsRaw as unknown[])).entries()) {
|
|
278
354
|
if (typeof raw === 'string') { out.push(itemOf(raw, raw, {})); continue; }
|
|
279
355
|
const rec = recOf(raw);
|
|
280
|
-
const key = str(rec.key);
|
|
356
|
+
const key = str(rec.key) || (rows !== null ? `i${i}` : '');
|
|
281
357
|
if (key === '') continue;
|
|
282
|
-
out.push(itemOf(key, str(rec.label) || key, rec));
|
|
358
|
+
out.push(itemOf(key, str(rec.label) || key, rec, rows !== null || Object.prototype.hasOwnProperty.call(rec, 'value')));
|
|
283
359
|
}
|
|
284
360
|
return out;
|
|
285
361
|
}
|
|
@@ -290,6 +366,29 @@ export function statItemsOf(itemsRaw: unknown, mapRaw: unknown, data: Record<str
|
|
|
290
366
|
.map((key) => itemOf(key, key, {}));
|
|
291
367
|
}
|
|
292
368
|
|
|
369
|
+
/** 非 ready 项的原因文字:数据给的原因,没给用默认词条 */
|
|
370
|
+
function statReasonText(state: Exclude<KitStatState, 'ready'>, reason: string, at: Element | null): string {
|
|
371
|
+
const given = reason.trim();
|
|
372
|
+
return given !== '' ? given : kitText(state === 'error' ? 'soma.kit.stat_error' : 'soma.kit.stat_missing', undefined, at);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* missing / error 的原因行(落在指标槽,主位「—」之下):辅助色小字,不画圆圈类标记;
|
|
377
|
+
* 原因由数据给(reason),没给用默认词条;文字单行截断,行上的 data-kit-tips 标出截断提示的作用范围(全文始终在 DOM 里)。
|
|
378
|
+
*/
|
|
379
|
+
export function statStateRowNode(state: Exclude<KitStatState, 'ready'>, reason: string, at: Element | null): HTMLElement {
|
|
380
|
+
const row = document.createElement('span');
|
|
381
|
+
row.className = kitStatStateRowClass(state);
|
|
382
|
+
row.setAttribute('data-kit-stat-state', state);
|
|
383
|
+
row.setAttribute('data-kit-tips', '');
|
|
384
|
+
const text = document.createElement('span');
|
|
385
|
+
text.className = KIT_STAT_STATE_REASON;
|
|
386
|
+
text.setAttribute('data-kit-stat-reason', '');
|
|
387
|
+
text.textContent = statReasonText(state, reason, at);
|
|
388
|
+
row.append(text);
|
|
389
|
+
return row;
|
|
390
|
+
}
|
|
391
|
+
|
|
293
392
|
export function createStatGroup(): SomaComponentDefinition {
|
|
294
393
|
return {
|
|
295
394
|
contract: {
|
|
@@ -297,14 +396,22 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
297
396
|
layer: 'data',
|
|
298
397
|
props: {
|
|
299
398
|
data: { type: 'object', default: {}, desc: '统计对象,如 { total: 12, open: 3 }' },
|
|
300
|
-
items: { type: 'array', default: [], desc: '展示项 [{ key, label, format?, unit?, unitKey?, trend?, trendFormat?, compare?, compareLabel?, period?, compareValue?, delta?, upIs?, hint?, hintKey? }];format 取 soma-foundation/values 的写法(number / percent / currency:CNY 等);unit 为数值单位;trend / compareValue / delta 为变化率,compare / compareLabel / period 为对比期说明(如「较昨日」),upIs: good | bad 决定涨是绿还是红,hint 提示字面量、hintKey 取自数据;扩展(均由数据 / 字面量给,组件不比较数值):tone / toneKey 项语气(图标 + 读屏文字)、href / hrefKey 块画成链接(safeHref)、state(gap / unknown)/ stateKey / reason / reasonKey 缺口或未知标记(值缺失且给了 reason 也按缺口画)、values [{ key, label, format?, unit? }] 附加数值(缺失画缺口)、flagsKey 标记小标签(数据里的字符串数组或 [{ label, tone? }])' },
|
|
301
|
-
|
|
399
|
+
items: { type: 'array', default: [], desc: '展示项 [{ key, label, format?, unit?, unitKey?, trend?, trendFormat?, compare?, compareLabel?, period?, compareValue?, delta?, upIs?, hint?, hintKey? }];format 取 soma-foundation/values 的写法(number / percent / currency:CNY 等);unit 为数值单位;trend / compareValue / delta 为变化率,compare / compareLabel / period 为对比期说明(如「较昨日」),upIs: good | bad 决定涨是绿还是红,hint 提示字面量、hintKey 取自数据;扩展(均由数据 / 字面量给,组件不比较数值):tone / toneKey 项语气(图标 + 读屏文字)、href / hrefKey 块画成链接(safeHref)、state(gap / unknown)/ stateKey / reason / reasonKey 缺口或未知标记(值缺失且给了 reason 也按缺口画)、values [{ key, label, format?, unit? }] 附加数值(缺失画缺口)、flagsKey 标记小标签(数据里的字符串数组或 [{ label, tone? }]);三态与交互(均由数据 / 字面量给):state(ready 缺省 / missing / error)画状态圆点 + reason 原因文字(单行截断,悬停出全文;缺原因用默认文案),action 事件名 = 整块可点(抛 action { key, action, item }),retry 事件名 = error 态操作槽「重试」钮(抛 retry { key, retry, item },不触发整块 action)' },
|
|
400
|
+
items_from: { type: 'string', default: '', desc: '数组写法:数据(data)里存放统计项数组的键,数组每个元素就是一项,自带 { key, label, value, unit?, state?, reason?, hint?, href?, tone?, compare?, compareValue?, values?, ... }(value 与各字段都在项上,不经 map、不必再写 items 映射)。items 的元素带 value 也是同一种自带数据的项(常由展示对象成员绑定数组:items: view.<成员>);与扁平写法(data 对象 + 逐项 items)同一条渲染路径,可并存于同页不同组' },
|
|
401
|
+
map: { type: 'object', default: {}, desc: '键名对照:items 里的 key -> 数据里的键(只对扁平写法的项生效;自带数据的项不经 map)' },
|
|
302
402
|
columns: { type: 'number', default: 0, desc: '列数:1 / 2 / 3 / 4 / 6(宽容器下的列数,窄容器 1 列);0 或其它 = 自动(每个容器宽度档按项数取不让末行落单一项的列数,档位与上限见真源 kit-limits 的 statGrid)。单个统计卡片 = 一项 items + columns: 1' },
|
|
303
403
|
locale: { type: 'string', default: '', desc: '格式化语言;空则 zh-CN' },
|
|
404
|
+
// 整块读取失败(K6):绑展示对象成员(props.data)的统计组没有读接口、编译器不会替它接读状态,页面把成员上的错误文案绑到 error_text、
|
|
405
|
+
// 重试文案写 retry_text,点重试抛 read_retry(展示对象的具名动作重取);数据为空时只画错误面板,已有数据时错误面板在块之上、块保留
|
|
406
|
+
error_text: KIT_READ_STATE_PROP_DEFS.error_text,
|
|
407
|
+
retry_text: KIT_READ_STATE_PROP_DEFS.retry_text,
|
|
304
408
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
305
409
|
},
|
|
306
410
|
emits: {
|
|
411
|
+
read_retry: { payload: {}, desc: '整块读取失败(error_text 非空)时点错误面板的重试钮;绑展示对象成员的统计组由页面把它接到重取动作' },
|
|
307
412
|
select: { payload: { item: { type: 'object' } }, desc: '点某个统计块;item = { key, label, value }' },
|
|
413
|
+
action: { payload: { key: { type: 'string' }, action: { type: 'string' }, item: { type: 'object' } }, desc: '点带 action 的统计块(在 select 之后抛);action = 该项声明的事件名,item = { key, label, value }' },
|
|
414
|
+
retry: { payload: { key: { type: 'string' }, retry: { type: 'string' }, item: { type: 'object' } }, desc: '点 error 态统计块的「重试」钮;retry = 该项声明的事件名;不触发 select / action' },
|
|
308
415
|
},
|
|
309
416
|
},
|
|
310
417
|
templateHtml: `<div data-soma-id="root" class="${WRAP_CLASS}"><div data-soma-id="grid" class="${GRID_CLASS}"></div></div>`,
|
|
@@ -312,6 +419,8 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
312
419
|
let root: HTMLElement | null = null;
|
|
313
420
|
let grid: HTMLElement | null = null;
|
|
314
421
|
let current: Array<{ key: string; label: string; value: unknown }> = [];
|
|
422
|
+
// 每块的事件名(action 整块可点;retry 仅 error 态有):与 select 的载荷分开存,select 载荷形状不变
|
|
423
|
+
let meta = new Map<string, { action: string; retry: string }>();
|
|
315
424
|
|
|
316
425
|
return {
|
|
317
426
|
attach(rootEl) {
|
|
@@ -320,11 +429,33 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
320
429
|
?? root.querySelector<HTMLElement>('[data-soma-id="grid"]');
|
|
321
430
|
const r = root;
|
|
322
431
|
const onClick = (event: Event): void => {
|
|
323
|
-
const
|
|
432
|
+
const target = event.target as HTMLElement | null;
|
|
433
|
+
// 组级说明行的重试入口(在块外)
|
|
434
|
+
const noteRetry = target?.closest<HTMLElement>('[data-kit-stat-note] [data-kit-stat-retry]') ?? null;
|
|
435
|
+
if (noteRetry !== null) {
|
|
436
|
+
const nk = noteRetry.getAttribute('data-kit-stat-retry');
|
|
437
|
+
const ni = current.find((c) => c.key === nk);
|
|
438
|
+
const nm = nk === null ? undefined : meta.get(nk);
|
|
439
|
+
if (ni !== undefined && nm !== undefined && nm.retry !== '') api.emit('retry', { key: ni.key, retry: nm.retry, item: ni });
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const hit = target?.closest<HTMLElement>('[data-kit-stat]');
|
|
324
443
|
if (!hit) return;
|
|
325
444
|
const key = hit.getAttribute('data-kit-stat');
|
|
326
445
|
const item = current.find((c) => c.key === key);
|
|
327
|
-
if (item)
|
|
446
|
+
if (!item) return;
|
|
447
|
+
const m = meta.get(item.key);
|
|
448
|
+
// 重试钮:只抛 retry,不触发整块的 select / action
|
|
449
|
+
const retryEl = target?.closest<HTMLElement>('[data-kit-stat-retry]') ?? null;
|
|
450
|
+
if (retryEl !== null && hit.contains(retryEl)) {
|
|
451
|
+
event.stopPropagation();
|
|
452
|
+
if (m !== undefined && m.retry !== '') api.emit('retry', { key: item.key, retry: m.retry, item });
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
// 带重试钮的 error 块是分组容器(role=group),本身不可点、不可下钻
|
|
456
|
+
if (hit.getAttribute('role') === 'group') return;
|
|
457
|
+
api.emit('select', { item });
|
|
458
|
+
if (m !== undefined && m.action !== '') api.emit('action', { key: item.key, action: m.action, item });
|
|
328
459
|
};
|
|
329
460
|
r.addEventListener('click', onClick);
|
|
330
461
|
return () => {
|
|
@@ -340,35 +471,92 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
340
471
|
if (!grid) return;
|
|
341
472
|
const data = recOf(p.data);
|
|
342
473
|
const map = recOf(p.map);
|
|
474
|
+
const flatData = data;
|
|
475
|
+
const flatMap = map;
|
|
343
476
|
const locale = str(p.locale);
|
|
344
477
|
root.className = joinClass(WRAP_CLASS, p.class);
|
|
345
|
-
|
|
478
|
+
// 整块读取失败(K6):错误面板画在块之前;数据为空时只留面板(块区收起),有数据时块保留
|
|
479
|
+
root.querySelector('[data-kit-stat-read]')?.remove();
|
|
480
|
+
const readError = str(p.error_text);
|
|
481
|
+
if (readError !== '') {
|
|
482
|
+
const panel = document.createElement('div');
|
|
483
|
+
panel.setAttribute('data-kit-stat-read', '');
|
|
484
|
+
const retryLabel = str(p.retry_text);
|
|
485
|
+
paintKitStatePanel(panel, 'error', {
|
|
486
|
+
text: readError,
|
|
487
|
+
...(retryLabel !== '' ? { retry: (): void => { api.emit('read_retry', {}); }, retryLabel } : {}),
|
|
488
|
+
});
|
|
489
|
+
root.insertBefore(panel, grid);
|
|
490
|
+
if (Object.keys(data).length === 0) { grid.className = 'hidden'; grid.textContent = ''; return; }
|
|
491
|
+
}
|
|
492
|
+
const items = statItemsOf(p.items, map, data, str(p.items_from));
|
|
493
|
+
// 没有任何指标项(数据说「这一块不适用」,如旧口径报告无摘要统计):整块不渲染(根 hidden、无子节点),不留空卡片;同 NoticeList 的空约定
|
|
494
|
+
// 概况条里的统计块没有指标可显示时自报(宿主带 data-kit-summary-empty):条内成员全空,整条概况条不渲染(结构 CSS)
|
|
495
|
+
if (items.length === 0 && readError === '') { root.hidden = true; grid.className = 'hidden'; grid.textContent = ''; api.host.setAttribute(KIT_SUMMARY_EMPTY_ATTR, ''); return; }
|
|
496
|
+
api.host.removeAttribute(KIT_SUMMARY_EMPTY_ATTR);
|
|
497
|
+
root.hidden = false;
|
|
346
498
|
const classes = statGridClasses(items.length, num(p.columns));
|
|
347
499
|
grid.className = classes.grid;
|
|
348
500
|
// 导轨拼合 + 三槽对齐(默认行为,不是页面语法):块并进一个带通栏细线的容器,标题 / 指标 / 操作三槽跨块水平对齐
|
|
349
501
|
markKitRail(grid);
|
|
502
|
+
// 三态(由数据给):非 ready 的块没有可比的数值,不画环比 / 对比期;error 且给了 retry 时操作槽出重试钮
|
|
503
|
+
const stateOfItem = (item: KitStatItem): KitStatState => {
|
|
504
|
+
const scope = statScopeOf(item, map, data);
|
|
505
|
+
return statStateOf(pickText(item.state, item.stateKey, scope.map, scope.data));
|
|
506
|
+
};
|
|
507
|
+
// 同组原因相同(达到 groupReasonMin)的非 ready 项:原因提到组级只写一次,各项只留「—」;error 组级带一个重试入口
|
|
508
|
+
root.querySelectorAll('[data-kit-stat-note]').forEach((n) => n.remove());
|
|
509
|
+
const hoistKey = (item: KitStatItem): string => {
|
|
510
|
+
const st = stateOfItem(item);
|
|
511
|
+
if (st === 'ready') return '';
|
|
512
|
+
const sc = statScopeOf(item, flatMap, flatData);
|
|
513
|
+
return `${st}\u0000${statReasonText(st, pickText(item.reason, item.reasonKey, sc.map, sc.data), rootEl)}`;
|
|
514
|
+
};
|
|
515
|
+
const keyCount = new Map<string, number>();
|
|
516
|
+
for (const item of items) {
|
|
517
|
+
const k = hoistKey(item);
|
|
518
|
+
if (k !== '') keyCount.set(k, (keyCount.get(k) ?? 0) + 1);
|
|
519
|
+
}
|
|
520
|
+
const hoisted = new Set<string>([...keyCount].filter(([, n]) => n >= KIT_STAT_GROUP_REASON_MIN).map(([k]) => k));
|
|
521
|
+
const isHoisted = (item: KitStatItem): boolean => hoisted.has(hoistKey(item));
|
|
350
522
|
const foots = items.map((item) => {
|
|
351
|
-
const
|
|
352
|
-
const
|
|
523
|
+
const { map, data } = statScopeOf(item, flatMap, flatData);
|
|
524
|
+
const itemState = stateOfItem(item);
|
|
525
|
+
const changeBadge = itemState === 'ready' ? resolveChangeBadge(item, map, data, locale) : undefined;
|
|
526
|
+
const compareText = itemState === 'ready' ? resolveMappedString(item.compare, item.compareKey, map, data) : '';
|
|
353
527
|
const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
|
|
354
|
-
|
|
528
|
+
const retry = itemState === 'error' && item.retry !== '' && !isHoisted(item);
|
|
529
|
+
return { changeBadge, compareText, hintText, retry, any: changeBadge !== undefined || compareText !== '' || hintText !== '' || retry };
|
|
355
530
|
});
|
|
356
|
-
|
|
531
|
+
// 两槽(标题 / 指标):变化率 / 对比期 / 提示并进数值行,不再有第三行
|
|
532
|
+
markKitSlotGrid(grid, slotCountOf(false));
|
|
357
533
|
grid.textContent = '';
|
|
358
534
|
current = [];
|
|
535
|
+
meta = new Map();
|
|
359
536
|
for (const [index, item] of items.entries()) {
|
|
537
|
+
// 取数范围:自带数据的项取项本身,扁平项取全局 data + map(以下 map / data 在本项内指这个范围)
|
|
538
|
+
const { map, data } = statScopeOf(item, flatMap, flatData);
|
|
360
539
|
const source = typeof map[item.key] === 'string' && map[item.key] !== '' ? String(map[item.key]) : item.key;
|
|
361
|
-
const value = data[source];
|
|
540
|
+
const value = item.inline !== null ? item.inline.value : data[source];
|
|
362
541
|
current.push({ key: item.key, label: item.label, value });
|
|
542
|
+
const itemState = stateOfItem(item);
|
|
543
|
+
const hasRetry = foots[index]!.retry;
|
|
544
|
+
// error 态的块不可下钻:忽略 action(只保留重试钮),missing 态保留 action
|
|
545
|
+
const action = itemState === 'error' ? '' : item.action;
|
|
546
|
+
meta.set(item.key, { action, retry: hasRetry ? item.retry : '' });
|
|
363
547
|
// href(字面量或取自数据,过 safeHref):块画成链接,原生跳转;被拒或没给仍是按钮。select 事件两种形态都照常抛
|
|
364
|
-
|
|
365
|
-
const
|
|
548
|
+
// 带重试钮的块(error + retry)不能是链接 / 原生按钮(里面有按钮),画成不可点的 div(role=group),只有重试钮可点
|
|
549
|
+
const hrefSafe = hasRetry ? '' : safeHref(pickText(item.href, item.hrefKey, map, data));
|
|
550
|
+
const block: HTMLElement = document.createElement(hrefSafe !== '' ? 'a' : hasRetry ? 'div' : 'button');
|
|
366
551
|
if (block instanceof HTMLButtonElement) block.type = 'button';
|
|
552
|
+
else if (hasRetry) block.setAttribute('role', 'group');
|
|
367
553
|
else block.setAttribute('href', hrefSafe);
|
|
554
|
+
if (action !== '') block.setAttribute('data-kit-stat-action', action);
|
|
555
|
+
if (itemState !== 'ready') block.setAttribute('data-kit-state', itemState);
|
|
368
556
|
// 块在导轨里不描边、不画卡片(不标 card 部件,免得命中容器边界 / 阴影规则);高亮块只换底色
|
|
369
557
|
const blockClass = item.highlight === true ? `${BLOCK_CLASS} bg-primary-soft` : BLOCK_CLASS;
|
|
370
|
-
const
|
|
371
|
-
block.className =
|
|
558
|
+
const spanClass = `col-span-${KIT_RAIL_TRACKS} ${classes.cell(index)}`.trim();
|
|
559
|
+
block.className = `${blockClass} ${spanClass}`;
|
|
372
560
|
block.setAttribute('data-kit-stat', item.key);
|
|
373
561
|
if (item.highlight === true) block.setAttribute('data-kit-highlight', 'true');
|
|
374
562
|
const label = markKitSlot(document.createElement('span'), 'title');
|
|
@@ -377,15 +565,21 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
377
565
|
// 项语气(数据给的词):指标名前加图标 + 读屏文字(双编码,不靠颜色);非闭集的词忽略
|
|
378
566
|
const itemTone = statusToneOrNull(pickText(item.tone, item.toneKey, map, data));
|
|
379
567
|
if (itemTone !== null) {
|
|
568
|
+
// 语气不加图标(统计项标签前的图标有的有有的没有,是噪声):读屏文字 + 数值语义色(danger / warning / success)双编码
|
|
380
569
|
block.setAttribute('data-kit-tone', itemTone);
|
|
381
|
-
label.className = `${LABEL_CLASS} ${KIT_STAT_TONE_LABEL}`;
|
|
382
570
|
const sr = document.createElement('span');
|
|
383
571
|
sr.className = KIT_NOTICE_SR_ONLY;
|
|
384
572
|
sr.textContent = kitText(KIT_STATUS_TONE_TEXT_KEY[itemTone], undefined, rootEl);
|
|
385
|
-
|
|
573
|
+
if (itemTone === 'warning') {
|
|
574
|
+
const dot = document.createElement('span');
|
|
575
|
+
dot.className = STAT_WARN_DOT_CLASS;
|
|
576
|
+
dot.setAttribute('aria-hidden', 'true');
|
|
577
|
+
label.replaceChildren(sr, dot, document.createTextNode(item.label));
|
|
578
|
+
} else label.replaceChildren(sr, document.createTextNode(item.label));
|
|
386
579
|
}
|
|
387
580
|
const val = document.createElement('span');
|
|
388
|
-
|
|
581
|
+
const toneText = itemTone !== null && itemState === 'ready' && STAT_TONE_VALUE[itemTone] !== undefined ? ` ${STAT_TONE_VALUE[itemTone]}` : '';
|
|
582
|
+
val.className = `${VALUE_CLASS}${toneText}`;
|
|
389
583
|
val.setAttribute('data-kit-stat-value', '');
|
|
390
584
|
val.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE);
|
|
391
585
|
val.textContent = value === undefined || value === null || value === '' ? '' : formatValue(value, item.format, locale);
|
|
@@ -393,7 +587,8 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
393
587
|
const stateRaw = pickText(item.state, item.stateKey, map, data);
|
|
394
588
|
const reasonText = pickText(item.reason, item.reasonKey, map, data);
|
|
395
589
|
const valueMissing = value === undefined || value === null || value === '';
|
|
396
|
-
const gapKind = stateRaw === 'gap' || stateRaw === 'unknown' ? stateRaw : valueMissing && reasonText.trim() !== '' ? 'gap' : null;
|
|
590
|
+
const gapKind = itemState !== 'ready' ? null : stateRaw === 'gap' || stateRaw === 'unknown' ? stateRaw : valueMissing && reasonText.trim() !== '' ? 'gap' : null;
|
|
591
|
+
if (itemState === 'missing') val.textContent = KIT_STAT_PLACEHOLDER;
|
|
397
592
|
if (gapKind !== null) {
|
|
398
593
|
val.textContent = '';
|
|
399
594
|
val.setAttribute('data-kit-gap', gapKind);
|
|
@@ -404,24 +599,32 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
404
599
|
metric.className = METRIC_SLOT_CLASS;
|
|
405
600
|
block.appendChild(metric);
|
|
406
601
|
|
|
407
|
-
const unitText = gapKind !== null ? '' : resolveMappedString(item.unit, item.unitKey, map, data);
|
|
408
|
-
|
|
409
|
-
|
|
602
|
+
const unitText = gapKind !== null || itemState !== 'ready' ? '' : resolveMappedString(item.unit, item.unitKey, map, data);
|
|
603
|
+
// 三态原因行:状态圆点 + 原因文字;error 态指标位只有这一行(没有主数值),missing 态在占位「—」之下
|
|
604
|
+
const stateRow = itemState === 'ready' || isHoisted(item) ? null : statStateRowNode(itemState, reasonText, rootEl);
|
|
605
|
+
// error 与 missing 一样主位只写「—」,原因在其下(或提到组级)
|
|
606
|
+
if (itemState === 'error') val.textContent = KIT_STAT_PLACEHOLDER;
|
|
607
|
+
let valRow: HTMLElement | null = null;
|
|
608
|
+
if (unitText !== '' || foots[index]!.any) {
|
|
609
|
+
valRow = document.createElement('span');
|
|
410
610
|
valRow.className = VALUE_ROW_CLASS;
|
|
411
|
-
//
|
|
412
|
-
val.className = STAT_VALUE_CLASS
|
|
611
|
+
// 带单位 / 副文本时贴底对齐交给整行(VALUE_ROW_CLASS);数值自己不再带 mt-auto,否则在行内被单独下推,单位浮到右上角
|
|
612
|
+
val.className = `${STAT_VALUE_CLASS}${toneText}`;
|
|
413
613
|
valRow.appendChild(val);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
614
|
+
if (unitText !== '') {
|
|
615
|
+
const unitEl = document.createElement('span');
|
|
616
|
+
unitEl.className = UNIT_CLASS;
|
|
617
|
+
unitEl.setAttribute('data-kit-stat-unit', '');
|
|
618
|
+
unitEl.textContent = unitText;
|
|
619
|
+
valRow.appendChild(unitEl);
|
|
620
|
+
}
|
|
419
621
|
metric.appendChild(valRow);
|
|
420
622
|
} else {
|
|
421
623
|
metric.appendChild(val);
|
|
422
624
|
}
|
|
625
|
+
if (stateRow !== null) metric.appendChild(stateRow);
|
|
423
626
|
|
|
424
|
-
if (item.spark !== '') {
|
|
627
|
+
if (itemState === 'ready' && item.spark !== '') {
|
|
425
628
|
const sparkSource = typeof map[item.spark] === 'string' && map[item.spark] !== '' ? String(map[item.spark]) : item.spark;
|
|
426
629
|
const values = trendValuesOf(data[sparkSource]);
|
|
427
630
|
const svg = sparklineSvg(values, { tone: trendToneOf('auto', values, item.upIs), label: item.label, className: 'h-8 w-full' });
|
|
@@ -429,7 +632,7 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
429
632
|
}
|
|
430
633
|
|
|
431
634
|
// 附加数值:主数值之下的「名 值」小字对;值缺失的画缺口标记(不画空白 / 0)
|
|
432
|
-
if (item.values.length > 0) {
|
|
635
|
+
if (itemState === 'ready' && item.values.length > 0) {
|
|
433
636
|
const row = document.createElement('span');
|
|
434
637
|
row.className = KIT_STAT_VALUES_ROW;
|
|
435
638
|
row.setAttribute('data-kit-stat-values', '');
|
|
@@ -454,7 +657,7 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
454
657
|
}
|
|
455
658
|
|
|
456
659
|
// 标记:数据给的小标签(字符串或 { label, tone? }),顺序与取舍由数据决定
|
|
457
|
-
if (item.flagsKey !== '') {
|
|
660
|
+
if (itemState === 'ready' && item.flagsKey !== '') {
|
|
458
661
|
const flagSource = typeof map[item.flagsKey] === 'string' && map[item.flagsKey] !== '' ? String(map[item.flagsKey]) : item.flagsKey;
|
|
459
662
|
const flagData = data[flagSource];
|
|
460
663
|
const flags = Array.isArray(flagData) ? flagData.flatMap((f) => {
|
|
@@ -478,9 +681,10 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
478
681
|
|
|
479
682
|
// 变化率、对比期说明与提示:趋势数值取 trend / compareValue / delta,对比期取 compare / compareLabel / period
|
|
480
683
|
const { changeBadge, compareText, hintText } = foots[index]!;
|
|
481
|
-
if (
|
|
482
|
-
const foot =
|
|
684
|
+
if (foots[index]!.any) {
|
|
685
|
+
const foot = document.createElement('span');
|
|
483
686
|
foot.className = FOOT_CLASS;
|
|
687
|
+
foot.setAttribute('data-kit-stat-foot', '');
|
|
484
688
|
if (changeBadge !== undefined) {
|
|
485
689
|
const { change, text: changeText } = changeBadge;
|
|
486
690
|
const badge = document.createElement('span');
|
|
@@ -503,10 +707,50 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
503
707
|
hint.textContent = hintText;
|
|
504
708
|
foot.appendChild(hint);
|
|
505
709
|
}
|
|
506
|
-
|
|
710
|
+
// error 态的「重试」:文字钮,点击只抛 retry(委托里先判重试钮,不触发整块 select / action)
|
|
711
|
+
if (hasRetry) {
|
|
712
|
+
const retryBtn = document.createElement('button');
|
|
713
|
+
retryBtn.type = 'button';
|
|
714
|
+
retryBtn.className = KIT_STAT_RETRY_CLASS;
|
|
715
|
+
retryBtn.setAttribute('data-kit-stat-retry', item.key);
|
|
716
|
+
retryBtn.setAttribute('aria-label', kitText('soma.kit.retry_of', { label: item.label }, rootEl));
|
|
717
|
+
retryBtn.textContent = kitText('soma.kit.stat_retry', undefined, rootEl);
|
|
718
|
+
foot.appendChild(retryBtn);
|
|
719
|
+
}
|
|
720
|
+
(valRow ?? metric).appendChild(foot);
|
|
721
|
+
}
|
|
722
|
+
// 读屏名称:可点块 =「标签 数值」,missing / error =「标签,原因」(原因缺省用默认文案);没有这两类的块沿用内容自然名称
|
|
723
|
+
if (itemState !== 'ready') {
|
|
724
|
+
const stateText = reasonText.trim() !== '' ? reasonText.trim() : kitText(itemState === 'error' ? 'soma.kit.stat_error' : 'soma.kit.stat_missing', undefined, rootEl);
|
|
725
|
+
block.setAttribute('aria-label', kitText('soma.kit.stat_state_name', { label: item.label, state: stateText }, rootEl));
|
|
726
|
+
} else if (action !== '') {
|
|
727
|
+
block.setAttribute('aria-label', `${item.label} ${val.textContent ?? ''}${unitText === '' ? '' : ` ${unitText}`}`.trim());
|
|
507
728
|
}
|
|
508
729
|
grid.appendChild(block);
|
|
509
730
|
}
|
|
731
|
+
// 组级说明行:每条被提到组级的原因一行(全文、不截断);error 组带一个重试入口(取组内第一个声明了 retry 的项)
|
|
732
|
+
for (const k of hoisted) {
|
|
733
|
+
const members = items.filter((it) => hoistKey(it) === k);
|
|
734
|
+
const state = k.slice(0, k.indexOf('\u0000')) as Exclude<KitStatState, 'ready'>;
|
|
735
|
+
const note = document.createElement('p');
|
|
736
|
+
note.className = `m-0 ${kitStatGroupNoteClass(state)}`;
|
|
737
|
+
note.setAttribute('data-kit-stat-note', state);
|
|
738
|
+
const text = document.createElement('span');
|
|
739
|
+
text.setAttribute('data-kit-stat-reason', '');
|
|
740
|
+
text.textContent = k.slice(k.indexOf('\u0000') + 1);
|
|
741
|
+
note.appendChild(text);
|
|
742
|
+
const retryItem = state === 'error' ? members.find((it) => it.retry !== '') : undefined;
|
|
743
|
+
if (retryItem !== undefined) {
|
|
744
|
+
meta.set(retryItem.key, { action: '', retry: retryItem.retry });
|
|
745
|
+
const btn = document.createElement('button');
|
|
746
|
+
btn.type = 'button';
|
|
747
|
+
btn.className = KIT_STAT_RETRY_CLASS;
|
|
748
|
+
btn.setAttribute('data-kit-stat-retry', retryItem.key);
|
|
749
|
+
btn.textContent = kitText('soma.kit.stat_retry', undefined, rootEl);
|
|
750
|
+
note.appendChild(btn);
|
|
751
|
+
}
|
|
752
|
+
root.appendChild(note);
|
|
753
|
+
}
|
|
510
754
|
},
|
|
511
755
|
};
|
|
512
756
|
}),
|