soma-kit 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +172 -4
- package/spec/generated/kit-page.schema.json +164 -5
- package/spec/kit-grammar.json +598 -96
- package/spec/kit-grammar.schema.json +12 -6
- package/src/app/app-config.ts +92 -8
- 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 +29 -5
- package/src/app/kit-view-context.ts +181 -15
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +55 -8
- 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 +62 -15
- 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 +61 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +168 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +95 -0
- package/src/base/index.ts +32 -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 +16 -18
- 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 +10 -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 +36 -24
- package/src/base/shared.ts +180 -36
- package/src/base/state-panel.ts +367 -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 +76 -41
- package/src/base/text.ts +43 -14
- 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 -9
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +15 -11
- package/src/biz/auth-panel/shell.ts +9 -7
- package/src/biz/category-crud/compile.ts +5 -4
- package/src/biz/category-crud/shell.ts +5 -3
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +10 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +13 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +207 -16
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +7 -3
- package/src/biz/master-sub/shell.ts +133 -24
- package/src/biz/multi-board/compile.ts +167 -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 +94 -23
- package/src/biz/notification-center/shell.ts +10 -7
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- package/src/biz/page-templates/sign-in-page/shell.ts +16 -16
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +13 -10
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +12 -9
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +97 -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 +281 -0
- package/src/biz/shared/overlay-shell.ts +142 -11
- 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 +9 -6
- package/src/biz/standard-crud/compile.ts +36 -161
- package/src/biz/standard-crud/shell.ts +23 -60
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +15 -13
- package/src/biz/types.ts +6 -1
- 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/access-gate-attach.ts +27 -0
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +66 -11
- package/src/compile/component-candidates.ts +14 -1
- package/src/compile/fragment.ts +11 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +267 -0
- package/src/compile/layout-lint/rules-form.ts +191 -0
- package/src/compile/layout-lint/rules-table.ts +278 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- 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/remove-guard.ts +10 -7
- package/src/compile/styles.ts +46 -8
- package/src/compile/types.ts +16 -2
- package/src/compile/view-check.ts +149 -16
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +9 -2
- package/src/data/approval-flow.ts +5 -2
- package/src/data/assignment-picker.ts +59 -28
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +8 -3
- package/src/data/carousel.ts +10 -6
- package/src/data/chart.ts +744 -46
- package/src/data/checklist.ts +22 -6
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +3 -2
- package/src/data/confirm-dialog.ts +72 -25
- 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 +7 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +26 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +4 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +16 -4
- package/src/data/item-list.ts +27 -12
- package/src/data/kanban.ts +41 -10
- package/src/data/matrix.ts +391 -0
- 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 +60 -16
- package/src/data/mockup.ts +5 -1
- package/src/data/modal-dialog.ts +146 -26
- package/src/data/navbar.ts +8 -6
- package/src/data/notice-list.ts +301 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +409 -87
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +19 -8
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +36 -11
- package/src/data/permission-tree.ts +52 -23
- package/src/data/pricing-table.ts +22 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +40 -7
- package/src/data/record-picker.ts +13 -7
- package/src/data/resident.ts +8 -0
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +77 -24
- package/src/data/rule-builder.ts +14 -9
- package/src/data/shape-util.ts +27 -12
- package/src/data/stat-group.ts +459 -74
- package/src/data/static-lazy.ts +5 -0
- package/src/data/static-registry.ts +8 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +7 -4
- package/src/data/system-switcher.ts +3 -2
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +3 -2
- package/src/data/transfer.ts +40 -16
- package/src/data/tree-table.ts +65 -37
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +21 -11
- package/src/data/wrapped-candidates.ts +32 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +7 -14
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +34 -13
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +9 -6
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +3 -3
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +4 -4
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +168 -44
- package/src/generated/kit-grammar-runtime.ts +390 -59
- package/src/i18n/kit-text.ts +90 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +71 -7
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +264 -62
- package/src/object-renderer/collection-table.ts +177 -5
- package/src/object-renderer/collection.ts +188 -37
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +27 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +434 -41
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +394 -0
- package/src/object-renderer/layout-plan.ts +225 -0
- package/src/object-renderer/layout-plan.types.ts +59 -0
- package/src/object-renderer/parts.ts +6 -7
- package/src/object-renderer/render-object.ts +107 -46
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +172 -32
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +62 -30
- package/src/object-renderer/types.ts +84 -13
- 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 +77 -1
- package/src/recipes/control.ts +76 -116
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +72 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +120 -17
- package/src/recipes/placeholder.ts +95 -0
- package/src/recipes/rail-grid.ts +48 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +40 -21
- package/src/recipes/status.ts +147 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +146 -3
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +30 -37
- 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 +384 -13
- package/src/theme/kit-theme.tpl +384 -13
- package/src/theme/nine-dim-structure.ts +244 -7
- package/src/theme/surface-layers.ts +10 -1
- package/src/theme/theme-tokens.ts +63 -16
- package/src/theme/theme-types.ts +32 -0
- package/src/theme/typography.ts +21 -17
- package/src/biz/shared/remove-key.ts +0 -6
package/src/data/stat-group.ts
CHANGED
|
@@ -4,67 +4,138 @@
|
|
|
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';
|
|
23
|
+
import { trendTone } from '../base/trend-tone';
|
|
15
24
|
import { TAG_CLASS } from '../base/tag';
|
|
25
|
+
import { gapMarkerNode } from '../base/gap-value';
|
|
26
|
+
import { safeHref } from '../base/link';
|
|
27
|
+
import { KIT_STATUS_TONE_TEXT_KEY, statusToneOrNull } from '../base/status-tone';
|
|
28
|
+
import { classCandidates } from '../base/class-candidates';
|
|
29
|
+
import { kitText } from '../i18n/kit-text';
|
|
30
|
+
import { KIT_READ_STATE_PROP_DEFS, KIT_STATE_PANEL_CLASS_CANDIDATES, paintKitStatePanel } from '../base/state-panel';
|
|
16
31
|
import { KIT_TREND_LINE_CLASS_CANDIDATES, sparklineSvg, trendToneOf, trendValuesOf } from './trend-line';
|
|
17
|
-
import { KIT_PART_ATTRIBUTE,
|
|
32
|
+
import { KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE, kitTypographyRecipe } from '../recipes';
|
|
33
|
+
import { KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES, kitRailGridRecipe, markKitRail } from '../recipes/rail-grid';
|
|
34
|
+
import { KIT_SUMMARY_EMPTY_ATTR } from '../recipes/container';
|
|
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';
|
|
40
|
+
import {
|
|
41
|
+
KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, KIT_NOTICE_ICON, KIT_NOTICE_SR_ONLY, KIT_STAT_EXTRA_CLASS_CANDIDATES, KIT_STAT_FLAGS_ROW,
|
|
42
|
+
KIT_STAT_VALUES_NUM, KIT_STAT_VALUES_ROW,
|
|
43
|
+
} from '../recipes/status';
|
|
18
44
|
|
|
19
45
|
const WRAP_CLASS = '@container';
|
|
20
|
-
|
|
21
|
-
|
|
46
|
+
// 导轨拼合(recipes/rail-grid):块并进一个容器,块间只有 1px 通栏细线,块自己不描边不画卡片;
|
|
47
|
+
// 容器的列间距 / 行间距 / 内边距 / 底色都由层内规则(真源 structure.railGrid)给,这里不写 gap-* / p-* / 边框类
|
|
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
|
+
}
|
|
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`;
|
|
22
60
|
const LABEL_CLASS = 'text-xs font-medium text-fg-muted';
|
|
23
61
|
/** 指标主数值样式:对齐规则卡 30px 大数字 + font-bold tabular-nums */
|
|
24
62
|
export const STAT_VALUE_CLASS = kitTypographyRecipe('statValue');
|
|
63
|
+
// 三槽(recipes/slot-align):标题 = 指标名,指标 = 数值 + 单位 + 迷你图 + 附加数值 + 标记,操作 = 变化率 / 对比期 / 提示;
|
|
64
|
+
// 跨卡片的水平对齐由 subgrid 给,不支持 subgrid 时由层内规则退化为 flex 纵向 + 指标槽贴底
|
|
65
|
+
const METRIC_SLOT_CLASS = 'flex min-w-0 flex-col gap-1';
|
|
25
66
|
const VALUE_CLASS = STAT_VALUE_CLASS;
|
|
26
|
-
|
|
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';
|
|
27
77
|
const UNIT_CLASS = 'text-xs font-normal text-fg-muted';
|
|
28
78
|
|
|
29
79
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
30
80
|
export const KIT_STAT_GROUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
31
|
-
'@container', 'grid',
|
|
32
|
-
'flex', 'flex-col', 'gap-1', '
|
|
81
|
+
'@container', 'grid', `grid-cols-${KIT_RAIL_TRACKS}`, 'min-w-0', 'appearance-none', 'border-0', 'bg-primary-soft',
|
|
82
|
+
'flex', 'flex-col', 'gap-1', 'text-start',
|
|
33
83
|
'transition-colors', 'active:opacity-80', 'font-medium', 'font-normal', 'font-bold', 'tabular-nums',
|
|
34
|
-
'
|
|
84
|
+
'state-layer', 'focus-visible:outline-none', 'focus-visible:ring-1', 'focus-visible:ring-inset', 'focus-visible:ring-ring',
|
|
85
|
+
...KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES,
|
|
35
86
|
'text-sm', 'text-fg-muted', 'text-2xl', 'text-stat-value', 'font-title', 'tracking-tight', 'font-semibold', 'text-fg',
|
|
36
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',
|
|
37
90
|
...Object.values(TAG_CLASS.sm).flatMap((s) => s.split(' ')),
|
|
38
|
-
'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',
|
|
39
|
-
...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,
|
|
95
|
+
// 项扩展(语气 / 多值 / 标记 / 缺口)自带的类:来自 recipes/status
|
|
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,
|
|
40
99
|
// 各档列数与末块拉伸的全部可能类(档名 x 允许列数取自真源,Tailwind 静态扫描不到运行期拼的类名,所以在此列全)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
]),
|
|
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}`)),
|
|
45
103
|
]);
|
|
46
104
|
|
|
47
105
|
/**
|
|
48
106
|
* 栅格计划 -> 类串:网格类按档升序只写列数变化处(窄屏基准 1 列);末块类只写拉伸标记变化处(拉伸 = 占满整行,退出 = 回到单列宽)。
|
|
49
107
|
* 计划由 gridFillPlanOf 给出,这里只做格式化。
|
|
50
108
|
*/
|
|
51
|
-
export function statGridClassesOf(plan: SomaGridFillPlan): { grid: string;
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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 };
|
|
63
134
|
}
|
|
64
135
|
|
|
65
|
-
/** 一排统计块的类:columns
|
|
66
|
-
export function statGridClasses(count: number, columns: number | null | undefined): { grid: string;
|
|
67
|
-
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);
|
|
68
139
|
}
|
|
69
140
|
|
|
70
141
|
export interface KitStatItem {
|
|
@@ -95,6 +166,38 @@ export interface KitStatItem {
|
|
|
95
166
|
spark: string;
|
|
96
167
|
/** 指标项主色高亮强调 */
|
|
97
168
|
highlight?: boolean;
|
|
169
|
+
/** 项语气(neutral / info / success / warning / danger):只接数据给的词或字面量,组件不比较数值;非闭集 = 无语气 */
|
|
170
|
+
tone: string;
|
|
171
|
+
/** 语气取自数据里的键(给了就优先于 tone) */
|
|
172
|
+
toneKey: string;
|
|
173
|
+
/** 点击跳转地址(走 safeHref;被拒 / 空 = 仍是按钮):块画成链接 */
|
|
174
|
+
href: string;
|
|
175
|
+
/** 地址取自数据里的键 */
|
|
176
|
+
hrefKey: string;
|
|
177
|
+
/**
|
|
178
|
+
* 状态(由数据给;空 = 不指定):ready(缺省)/ missing / error 三态;另有 gap / unknown(缺口胶囊,主数值位画标记而不是值)。
|
|
179
|
+
* missing / error 时指标位画状态圆点 + 原因文字(reason),error 且有 retry 时操作槽出「重试」。
|
|
180
|
+
*/
|
|
181
|
+
state: string;
|
|
182
|
+
/** 整块可点:事件名;点击除 select 外再抛 action { key, action, item };error 态忽略(不可下钻) */
|
|
183
|
+
action: string;
|
|
184
|
+
/** error 态的重试:事件名;操作槽出「重试」钮,点击抛 retry { key, retry, item },不触发 select / action */
|
|
185
|
+
retry: string;
|
|
186
|
+
/** 状态取自数据里的键 */
|
|
187
|
+
stateKey: string;
|
|
188
|
+
/** 缺口 / 未知原因(字面量);值缺失且给了原因时按缺口画 */
|
|
189
|
+
reason: string;
|
|
190
|
+
/** 原因取自数据里的键 */
|
|
191
|
+
reasonKey: string;
|
|
192
|
+
/** 附加数值 [{ key, label, format?, unit? }]:主数值之下的「名 值」小字对,值取自数据;缺失的画缺口标记 */
|
|
193
|
+
values: Array<{ key: string; label: string; format: string; unit: string }>;
|
|
194
|
+
/** 标记(小标签)取自数据里的键:字符串数组或 [{ label, tone? }] */
|
|
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;
|
|
98
201
|
}
|
|
99
202
|
|
|
100
203
|
// 趋势徽标直接复用基础组件 Tag 的 sm 档类串
|
|
@@ -103,16 +206,12 @@ const TREND_UP_CLASS: Record<'good' | 'bad' | 'flat', string> = {
|
|
|
103
206
|
bad: TAG_CLASS.sm.danger,
|
|
104
207
|
flat: TAG_CLASS.sm.neutral,
|
|
105
208
|
};
|
|
106
|
-
const FOOT_CLASS = 'flex flex-wrap items-
|
|
209
|
+
const FOOT_CLASS = 'ms-1 inline-flex flex-wrap items-baseline gap-2';
|
|
107
210
|
const COMPARE_CLASS = 'text-xs text-fg-muted';
|
|
108
211
|
const HINT_CLASS = 'text-xs text-fg-subtle';
|
|
109
212
|
|
|
110
|
-
/**
|
|
111
|
-
export
|
|
112
|
-
if (change === 0) return 'flat';
|
|
113
|
-
const up = change > 0;
|
|
114
|
-
return up === (upIs === 'good') ? 'good' : 'bad';
|
|
115
|
-
}
|
|
213
|
+
/** 环比徽标的语气:实现在基础层 base/trend-tone(KitDelta 共用),此处再导出保持旧引用不变 */
|
|
214
|
+
export { trendTone };
|
|
116
215
|
|
|
117
216
|
function resolveCompareValue(rec: Record<string, unknown>): string | number | undefined {
|
|
118
217
|
for (const k of ['compareValue', 'delta'] as const) {
|
|
@@ -124,8 +223,9 @@ function resolveCompareValue(rec: Record<string, unknown>): string | number | un
|
|
|
124
223
|
return undefined;
|
|
125
224
|
}
|
|
126
225
|
|
|
127
|
-
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 {
|
|
128
227
|
return {
|
|
228
|
+
inline: inline ? rec : null,
|
|
129
229
|
key,
|
|
130
230
|
label,
|
|
131
231
|
format: str(rec.format),
|
|
@@ -141,9 +241,34 @@ function itemOf(key: string, label: string, rec: Record<string, unknown>): KitSt
|
|
|
141
241
|
hintKey: str(rec.hintKey),
|
|
142
242
|
spark: str(rec.spark),
|
|
143
243
|
...(rec.highlight === true ? { highlight: true } : {}),
|
|
244
|
+
tone: str(rec.tone),
|
|
245
|
+
toneKey: str(rec.toneKey),
|
|
246
|
+
href: str(rec.href),
|
|
247
|
+
hrefKey: str(rec.hrefKey),
|
|
248
|
+
state: str(rec.state),
|
|
249
|
+
stateKey: str(rec.stateKey),
|
|
250
|
+
action: str(rec.action),
|
|
251
|
+
retry: str(rec.retry),
|
|
252
|
+
reason: str(rec.reason),
|
|
253
|
+
reasonKey: str(rec.reasonKey),
|
|
254
|
+
values: Array.isArray(rec.values)
|
|
255
|
+
? rec.values.flatMap((v) => {
|
|
256
|
+
const r = recOf(v);
|
|
257
|
+
const key = str(r.key);
|
|
258
|
+
return key === '' ? [] : [{ key, label: str(r.label) || key, format: str(r.format), unit: str(r.unit) }];
|
|
259
|
+
})
|
|
260
|
+
: [],
|
|
261
|
+
flagsKey: str(rec.flagsKey),
|
|
144
262
|
};
|
|
145
263
|
}
|
|
146
264
|
|
|
265
|
+
/** 取项上的一个字符串设置:给了数据键就读数据(经 map 对照),否则用字面量 */
|
|
266
|
+
function pickText(literal: string, key: string, map: Record<string, unknown>, data: Record<string, unknown>): string {
|
|
267
|
+
if (key === '') return literal;
|
|
268
|
+
const source = typeof map[key] === 'string' && map[key] !== '' ? String(map[key]) : key;
|
|
269
|
+
return str(data[source]);
|
|
270
|
+
}
|
|
271
|
+
|
|
147
272
|
function recOf(raw: unknown): Record<string, unknown> {
|
|
148
273
|
return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw as Record<string, unknown> : {};
|
|
149
274
|
}
|
|
@@ -210,17 +335,27 @@ function resolveMappedString(
|
|
|
210
335
|
return literalOrKey;
|
|
211
336
|
}
|
|
212
337
|
|
|
213
|
-
/**
|
|
214
|
-
|
|
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[] {
|
|
215
349
|
const map = recOf(mapRaw);
|
|
216
|
-
|
|
350
|
+
const rows = from !== '' && Array.isArray(data[from]) ? (data[from] as unknown[]) : null;
|
|
351
|
+
if (rows !== null || (Array.isArray(itemsRaw) && itemsRaw.length > 0)) {
|
|
217
352
|
const out: KitStatItem[] = [];
|
|
218
|
-
for (const raw of itemsRaw) {
|
|
353
|
+
for (const [i, raw] of (rows ?? (itemsRaw as unknown[])).entries()) {
|
|
219
354
|
if (typeof raw === 'string') { out.push(itemOf(raw, raw, {})); continue; }
|
|
220
355
|
const rec = recOf(raw);
|
|
221
|
-
const key = str(rec.key);
|
|
356
|
+
const key = str(rec.key) || (rows !== null ? `i${i}` : '');
|
|
222
357
|
if (key === '') continue;
|
|
223
|
-
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')));
|
|
224
359
|
}
|
|
225
360
|
return out;
|
|
226
361
|
}
|
|
@@ -231,6 +366,29 @@ export function statItemsOf(itemsRaw: unknown, mapRaw: unknown, data: Record<str
|
|
|
231
366
|
.map((key) => itemOf(key, key, {}));
|
|
232
367
|
}
|
|
233
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
|
+
|
|
234
392
|
export function createStatGroup(): SomaComponentDefinition {
|
|
235
393
|
return {
|
|
236
394
|
contract: {
|
|
@@ -238,14 +396,22 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
238
396
|
layer: 'data',
|
|
239
397
|
props: {
|
|
240
398
|
data: { type: 'object', default: {}, desc: '统计对象,如 { total: 12, open: 3 }' },
|
|
241
|
-
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
|
|
242
|
-
|
|
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)' },
|
|
243
402
|
columns: { type: 'number', default: 0, desc: '列数:1 / 2 / 3 / 4 / 6(宽容器下的列数,窄容器 1 列);0 或其它 = 自动(每个容器宽度档按项数取不让末行落单一项的列数,档位与上限见真源 kit-limits 的 statGrid)。单个统计卡片 = 一项 items + columns: 1' },
|
|
244
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,
|
|
245
408
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
246
409
|
},
|
|
247
410
|
emits: {
|
|
411
|
+
read_retry: { payload: {}, desc: '整块读取失败(error_text 非空)时点错误面板的重试钮;绑展示对象成员的统计组由页面把它接到重取动作' },
|
|
248
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' },
|
|
249
415
|
},
|
|
250
416
|
},
|
|
251
417
|
templateHtml: `<div data-soma-id="root" class="${WRAP_CLASS}"><div data-soma-id="grid" class="${GRID_CLASS}"></div></div>`,
|
|
@@ -253,6 +419,8 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
253
419
|
let root: HTMLElement | null = null;
|
|
254
420
|
let grid: HTMLElement | null = null;
|
|
255
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 }>();
|
|
256
424
|
|
|
257
425
|
return {
|
|
258
426
|
attach(rootEl) {
|
|
@@ -261,11 +429,33 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
261
429
|
?? root.querySelector<HTMLElement>('[data-soma-id="grid"]');
|
|
262
430
|
const r = root;
|
|
263
431
|
const onClick = (event: Event): void => {
|
|
264
|
-
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]');
|
|
265
443
|
if (!hit) return;
|
|
266
444
|
const key = hit.getAttribute('data-kit-stat');
|
|
267
445
|
const item = current.find((c) => c.key === key);
|
|
268
|
-
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 });
|
|
269
459
|
};
|
|
270
460
|
r.addEventListener('click', onClick);
|
|
271
461
|
return () => {
|
|
@@ -281,65 +471,220 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
281
471
|
if (!grid) return;
|
|
282
472
|
const data = recOf(p.data);
|
|
283
473
|
const map = recOf(p.map);
|
|
474
|
+
const flatData = data;
|
|
475
|
+
const flatMap = map;
|
|
284
476
|
const locale = str(p.locale);
|
|
285
477
|
root.className = joinClass(WRAP_CLASS, p.class);
|
|
286
|
-
|
|
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;
|
|
287
498
|
const classes = statGridClasses(items.length, num(p.columns));
|
|
288
499
|
grid.className = classes.grid;
|
|
500
|
+
// 导轨拼合 + 三槽对齐(默认行为,不是页面语法):块并进一个带通栏细线的容器,标题 / 指标 / 操作三槽跨块水平对齐
|
|
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));
|
|
522
|
+
const foots = items.map((item) => {
|
|
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) : '';
|
|
527
|
+
const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
|
|
528
|
+
const retry = itemState === 'error' && item.retry !== '' && !isHoisted(item);
|
|
529
|
+
return { changeBadge, compareText, hintText, retry, any: changeBadge !== undefined || compareText !== '' || hintText !== '' || retry };
|
|
530
|
+
});
|
|
531
|
+
// 两槽(标题 / 指标):变化率 / 对比期 / 提示并进数值行,不再有第三行
|
|
532
|
+
markKitSlotGrid(grid, slotCountOf(false));
|
|
289
533
|
grid.textContent = '';
|
|
290
534
|
current = [];
|
|
535
|
+
meta = new Map();
|
|
291
536
|
for (const [index, item] of items.entries()) {
|
|
537
|
+
// 取数范围:自带数据的项取项本身,扁平项取全局 data + map(以下 map / data 在本项内指这个范围)
|
|
538
|
+
const { map, data } = statScopeOf(item, flatMap, flatData);
|
|
292
539
|
const source = typeof map[item.key] === 'string' && map[item.key] !== '' ? String(map[item.key]) : item.key;
|
|
293
|
-
const value = data[source];
|
|
540
|
+
const value = item.inline !== null ? item.inline.value : data[source];
|
|
294
541
|
current.push({ key: item.key, label: item.label, value });
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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 : '' });
|
|
547
|
+
// href(字面量或取自数据,过 safeHref):块画成链接,原生跳转;被拒或没给仍是按钮。select 事件两种形态都照常抛
|
|
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');
|
|
551
|
+
if (block instanceof HTMLButtonElement) block.type = 'button';
|
|
552
|
+
else if (hasRetry) block.setAttribute('role', 'group');
|
|
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);
|
|
556
|
+
// 块在导轨里不描边、不画卡片(不标 card 部件,免得命中容器边界 / 阴影规则);高亮块只换底色
|
|
557
|
+
const blockClass = item.highlight === true ? `${BLOCK_CLASS} bg-primary-soft` : BLOCK_CLASS;
|
|
558
|
+
const spanClass = `col-span-${KIT_RAIL_TRACKS} ${classes.cell(index)}`.trim();
|
|
559
|
+
block.className = `${blockClass} ${spanClass}`;
|
|
301
560
|
block.setAttribute('data-kit-stat', item.key);
|
|
302
|
-
block.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_CARD);
|
|
303
561
|
if (item.highlight === true) block.setAttribute('data-kit-highlight', 'true');
|
|
304
|
-
const label = document.createElement('span');
|
|
562
|
+
const label = markKitSlot(document.createElement('span'), 'title');
|
|
305
563
|
label.className = LABEL_CLASS;
|
|
306
564
|
label.textContent = item.label;
|
|
565
|
+
// 项语气(数据给的词):指标名前加图标 + 读屏文字(双编码,不靠颜色);非闭集的词忽略
|
|
566
|
+
const itemTone = statusToneOrNull(pickText(item.tone, item.toneKey, map, data));
|
|
567
|
+
if (itemTone !== null) {
|
|
568
|
+
// 语气不加图标(统计项标签前的图标有的有有的没有,是噪声):读屏文字 + 数值语义色(danger / warning / success)双编码
|
|
569
|
+
block.setAttribute('data-kit-tone', itemTone);
|
|
570
|
+
const sr = document.createElement('span');
|
|
571
|
+
sr.className = KIT_NOTICE_SR_ONLY;
|
|
572
|
+
sr.textContent = kitText(KIT_STATUS_TONE_TEXT_KEY[itemTone], undefined, rootEl);
|
|
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));
|
|
579
|
+
}
|
|
307
580
|
const val = document.createElement('span');
|
|
308
|
-
|
|
581
|
+
const toneText = itemTone !== null && itemState === 'ready' && STAT_TONE_VALUE[itemTone] !== undefined ? ` ${STAT_TONE_VALUE[itemTone]}` : '';
|
|
582
|
+
val.className = `${VALUE_CLASS}${toneText}`;
|
|
309
583
|
val.setAttribute('data-kit-stat-value', '');
|
|
310
584
|
val.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE);
|
|
311
585
|
val.textContent = value === undefined || value === null || value === '' ? '' : formatValue(value, item.format, locale);
|
|
586
|
+
// 缺口 / 未知(由数据给):state 明示 gap / unknown,或值缺失且给了原因(缺口);此时主数值位画标记,不画空白 / 0
|
|
587
|
+
const stateRaw = pickText(item.state, item.stateKey, map, data);
|
|
588
|
+
const reasonText = pickText(item.reason, item.reasonKey, map, data);
|
|
589
|
+
const valueMissing = value === undefined || value === null || value === '';
|
|
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;
|
|
592
|
+
if (gapKind !== null) {
|
|
593
|
+
val.textContent = '';
|
|
594
|
+
val.setAttribute('data-kit-gap', gapKind);
|
|
595
|
+
val.appendChild(gapMarkerNode(gapKind, reasonText, rootEl));
|
|
596
|
+
}
|
|
312
597
|
block.appendChild(label);
|
|
598
|
+
const metric = markKitSlot(document.createElement('span'), 'metric');
|
|
599
|
+
metric.className = METRIC_SLOT_CLASS;
|
|
600
|
+
block.appendChild(metric);
|
|
313
601
|
|
|
314
|
-
const unitText = resolveMappedString(item.unit, item.unitKey, map, data);
|
|
315
|
-
|
|
316
|
-
|
|
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');
|
|
317
610
|
valRow.className = VALUE_ROW_CLASS;
|
|
611
|
+
// 带单位 / 副文本时贴底对齐交给整行(VALUE_ROW_CLASS);数值自己不再带 mt-auto,否则在行内被单独下推,单位浮到右上角
|
|
612
|
+
val.className = `${STAT_VALUE_CLASS}${toneText}`;
|
|
318
613
|
valRow.appendChild(val);
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
+
}
|
|
621
|
+
metric.appendChild(valRow);
|
|
325
622
|
} else {
|
|
326
|
-
|
|
623
|
+
metric.appendChild(val);
|
|
327
624
|
}
|
|
625
|
+
if (stateRow !== null) metric.appendChild(stateRow);
|
|
328
626
|
|
|
329
|
-
if (item.spark !== '') {
|
|
627
|
+
if (itemState === 'ready' && item.spark !== '') {
|
|
330
628
|
const sparkSource = typeof map[item.spark] === 'string' && map[item.spark] !== '' ? String(map[item.spark]) : item.spark;
|
|
331
629
|
const values = trendValuesOf(data[sparkSource]);
|
|
332
630
|
const svg = sparklineSvg(values, { tone: trendToneOf('auto', values, item.upIs), label: item.label, className: 'h-8 w-full' });
|
|
333
|
-
if (svg)
|
|
631
|
+
if (svg) metric.appendChild(svg);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// 附加数值:主数值之下的「名 值」小字对;值缺失的画缺口标记(不画空白 / 0)
|
|
635
|
+
if (itemState === 'ready' && item.values.length > 0) {
|
|
636
|
+
const row = document.createElement('span');
|
|
637
|
+
row.className = KIT_STAT_VALUES_ROW;
|
|
638
|
+
row.setAttribute('data-kit-stat-values', '');
|
|
639
|
+
for (const sub of item.values) {
|
|
640
|
+
const subSource = typeof map[sub.key] === 'string' && map[sub.key] !== '' ? String(map[sub.key]) : sub.key;
|
|
641
|
+
const subValue = data[subSource];
|
|
642
|
+
const pair = document.createElement('span');
|
|
643
|
+
pair.setAttribute('data-kit-stat-sub', sub.key);
|
|
644
|
+
pair.appendChild(document.createTextNode(`${sub.label} `));
|
|
645
|
+
if (subValue === undefined || subValue === null || subValue === '') {
|
|
646
|
+
pair.appendChild(gapMarkerNode('gap', '', rootEl, 'sm'));
|
|
647
|
+
} else {
|
|
648
|
+
const numEl = document.createElement('span');
|
|
649
|
+
numEl.className = KIT_STAT_VALUES_NUM;
|
|
650
|
+
const shown = formatValue(subValue, sub.format, locale);
|
|
651
|
+
numEl.textContent = sub.unit === '' ? shown : `${shown} ${sub.unit}`;
|
|
652
|
+
pair.appendChild(numEl);
|
|
653
|
+
}
|
|
654
|
+
row.appendChild(pair);
|
|
655
|
+
}
|
|
656
|
+
metric.appendChild(row);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// 标记:数据给的小标签(字符串或 { label, tone? }),顺序与取舍由数据决定
|
|
660
|
+
if (itemState === 'ready' && item.flagsKey !== '') {
|
|
661
|
+
const flagSource = typeof map[item.flagsKey] === 'string' && map[item.flagsKey] !== '' ? String(map[item.flagsKey]) : item.flagsKey;
|
|
662
|
+
const flagData = data[flagSource];
|
|
663
|
+
const flags = Array.isArray(flagData) ? flagData.flatMap((f) => {
|
|
664
|
+
const r = recOf(f);
|
|
665
|
+
const text = typeof f === 'string' ? f : str(r.label);
|
|
666
|
+
return text === '' ? [] : [{ text, tone: statusToneOrNull(r.tone) ?? 'neutral' }];
|
|
667
|
+
}) : [];
|
|
668
|
+
if (flags.length > 0) {
|
|
669
|
+
const row = document.createElement('span');
|
|
670
|
+
row.className = KIT_STAT_FLAGS_ROW;
|
|
671
|
+
row.setAttribute('data-kit-stat-flags', '');
|
|
672
|
+
for (const f of flags) {
|
|
673
|
+
const chip = document.createElement('span');
|
|
674
|
+
chip.className = TAG_CLASS.sm[f.tone];
|
|
675
|
+
chip.textContent = f.text;
|
|
676
|
+
row.appendChild(chip);
|
|
677
|
+
}
|
|
678
|
+
metric.appendChild(row);
|
|
679
|
+
}
|
|
334
680
|
}
|
|
335
681
|
|
|
336
682
|
// 变化率、对比期说明与提示:趋势数值取 trend / compareValue / delta,对比期取 compare / compareLabel / period
|
|
337
|
-
const changeBadge
|
|
338
|
-
|
|
339
|
-
const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
|
|
340
|
-
if (changeBadge !== undefined || compareText !== '' || hintText !== '') {
|
|
683
|
+
const { changeBadge, compareText, hintText } = foots[index]!;
|
|
684
|
+
if (foots[index]!.any) {
|
|
341
685
|
const foot = document.createElement('span');
|
|
342
686
|
foot.className = FOOT_CLASS;
|
|
687
|
+
foot.setAttribute('data-kit-stat-foot', '');
|
|
343
688
|
if (changeBadge !== undefined) {
|
|
344
689
|
const { change, text: changeText } = changeBadge;
|
|
345
690
|
const badge = document.createElement('span');
|
|
@@ -362,10 +707,50 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
362
707
|
hint.textContent = hintText;
|
|
363
708
|
foot.appendChild(hint);
|
|
364
709
|
}
|
|
365
|
-
|
|
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());
|
|
366
728
|
}
|
|
367
729
|
grid.appendChild(block);
|
|
368
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
|
+
}
|
|
369
754
|
},
|
|
370
755
|
};
|
|
371
756
|
}),
|