soma-kit 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- 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/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -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 +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
package/src/data/stat-group.ts
CHANGED
|
@@ -1,53 +1,110 @@
|
|
|
1
1
|
// StatGroup:统计块一排(layer: data,写死形状,accept: single)。
|
|
2
2
|
//
|
|
3
|
-
// 数据:`data` 是一个对象(如汇总接口的返回)。展示哪几项由 `items` 外部传入 [{ key, label, format? }];
|
|
3
|
+
// 数据:`data` 是一个对象(如汇总接口的返回)。展示哪几项由 `items` 外部传入 [{ key, label, format?, unit?, trend?, compare?, compareValue? }];
|
|
4
4
|
// `map` 是「组件期望的键 -> 数据里的键」的对照(浅映射,不改源数据)。
|
|
5
5
|
// 没写 items 时:有 map 就按 map 的键序展示(label = 键名);也没有 map 就展示数据里全部数值字段。
|
|
6
|
-
// 点某块抛 `select { item: { key, label, value } }
|
|
6
|
+
// 点某块抛 `select { item: { key, label, value } }`。
|
|
7
|
+
// 列数按容器宽度档(容器查询)与项数选:每档只取不让末行落单一项的列数,无解的项数让末块拉伸占满整行;
|
|
8
|
+
// 规则与各档数字只在 soma-design 真源(kit-limits.json 的 statGrid),选列数的函数是 soma-foundation/data/values 的 gridFillPlanOf,这里只把结果写成类串。
|
|
7
9
|
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
10
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
|
+
import { gridFillPlanOf, type SomaGridFillPlan } from 'soma-foundation/data/values';
|
|
12
|
+
import { KIT_STAT_GRID } from 'soma-foundation/kit-limits';
|
|
13
|
+
import { createKitController, formatValue, joinClass, num, str } from '../base/shared';
|
|
10
14
|
import { kitIcon } from '../base/icons';
|
|
15
|
+
import { trendTone } from '../base/trend-tone';
|
|
11
16
|
import { TAG_CLASS } from '../base/tag';
|
|
17
|
+
import { gapMarkerNode } from '../base/gap-value';
|
|
18
|
+
import { safeHref } from '../base/link';
|
|
19
|
+
import { KIT_STATUS_TONE_ICON, KIT_STATUS_TONE_TEXT_KEY, statusToneOrNull } from '../base/status-tone';
|
|
20
|
+
import { classCandidates } from '../base/class-candidates';
|
|
21
|
+
import { kitText } from '../i18n/kit-text';
|
|
12
22
|
import { KIT_TREND_LINE_CLASS_CANDIDATES, sparklineSvg, trendToneOf, trendValuesOf } from './trend-line';
|
|
23
|
+
import { KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE, kitTypographyRecipe } from '../recipes';
|
|
24
|
+
import { KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES, kitRailGridRecipe, markKitRail } from '../recipes/rail-grid';
|
|
25
|
+
import { markKitSlot, markKitSlotGrid, slotCountOf } from '../recipes/slot-align';
|
|
26
|
+
import {
|
|
27
|
+
KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, KIT_NOTICE_ICON, KIT_NOTICE_SR_ONLY, KIT_STAT_EXTRA_CLASS_CANDIDATES, KIT_STAT_FLAGS_ROW,
|
|
28
|
+
KIT_STAT_TONE_LABEL, KIT_STAT_VALUES_NUM, KIT_STAT_VALUES_ROW,
|
|
29
|
+
} from '../recipes/status';
|
|
13
30
|
|
|
14
31
|
const WRAP_CLASS = '@container';
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
// 导轨拼合(recipes/rail-grid):块并进一个容器,块间只有 1px 通栏细线,块自己不描边不画卡片;
|
|
33
|
+
// 容器的列间距 / 行间距 / 内边距 / 底色都由层内规则(真源 structure.railGrid)给,这里不写 gap-* / p-* / 边框类
|
|
34
|
+
const GRID_CLASS = `${kitRailGridRecipe().container} grid-cols-1`;
|
|
35
|
+
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`;
|
|
17
36
|
const LABEL_CLASS = 'text-xs font-medium text-fg-muted';
|
|
18
|
-
|
|
37
|
+
/** 指标主数值样式:对齐规则卡 30px 大数字 + font-bold tabular-nums */
|
|
38
|
+
export const STAT_VALUE_CLASS = kitTypographyRecipe('statValue');
|
|
39
|
+
// 三槽(recipes/slot-align):标题 = 指标名,指标 = 数值 + 单位 + 迷你图 + 附加数值 + 标记,操作 = 变化率 / 对比期 / 提示;
|
|
40
|
+
// 跨卡片的水平对齐由 subgrid 给,不支持 subgrid 时由层内规则退化为 flex 纵向 + 指标槽贴底
|
|
41
|
+
const METRIC_SLOT_CLASS = 'flex min-w-0 flex-col gap-1';
|
|
42
|
+
const VALUE_CLASS = STAT_VALUE_CLASS;
|
|
43
|
+
const VALUE_ROW_CLASS = 'inline-flex items-baseline gap-1';
|
|
44
|
+
const UNIT_CLASS = 'text-xs font-normal text-fg-muted';
|
|
19
45
|
|
|
20
46
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
21
47
|
export const KIT_STAT_GROUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
22
|
-
'@container', 'grid', 'grid-cols-1', '
|
|
23
|
-
'flex', 'flex-col', 'gap-1', '
|
|
24
|
-
'transition-colors', 'active:opacity-80', 'font-medium',
|
|
25
|
-
'
|
|
26
|
-
|
|
27
|
-
'
|
|
48
|
+
'@container', 'grid', 'grid-cols-1', 'min-w-0', 'appearance-none', 'border-0', 'bg-primary-soft',
|
|
49
|
+
'flex', 'flex-col', 'gap-1', 'text-start',
|
|
50
|
+
'transition-colors', 'active:opacity-80', 'font-medium', 'font-normal', 'font-bold', 'tabular-nums',
|
|
51
|
+
'state-layer', 'focus-visible:outline-none', 'focus-visible:ring-1', 'focus-visible:ring-inset', 'focus-visible:ring-ring',
|
|
52
|
+
...KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES,
|
|
53
|
+
'text-sm', 'text-fg-muted', 'text-2xl', 'text-stat-value', 'font-title', 'tracking-tight', 'font-semibold', 'text-fg',
|
|
54
|
+
'items-center', 'items-baseline', 'flex-wrap', 'rounded-md', 'px-1.5', 'py-0.5', 'text-xs', 'inline-flex',
|
|
28
55
|
...Object.values(TAG_CLASS.sm).flatMap((s) => s.split(' ')),
|
|
29
|
-
'bg-success-soft', 'text-success-on-soft', 'bg-danger-soft', 'text-danger-on-soft', 'bg-surface-sunken', 'text-fg-subtle', 'gap-2',
|
|
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',
|
|
30
57
|
...KIT_TREND_LINE_CLASS_CANDIDATES, 'h-8', 'w-full',
|
|
31
|
-
|
|
58
|
+
// 项扩展(语气 / 多值 / 标记 / 缺口)自带的类:来自 recipes/status
|
|
59
|
+
...classCandidates(Object.values(KIT_NOTICE_ICON), KIT_NOTICE_SR_ONLY, KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, KIT_STAT_EXTRA_CLASS_CANDIDATES),
|
|
60
|
+
// 各档列数与末块拉伸的全部可能类(档名 x 允许列数取自真源,Tailwind 静态扫描不到运行期拼的类名,所以在此列全)
|
|
61
|
+
...Object.keys(KIT_STAT_GRID.tierCols).flatMap((tier) => [
|
|
62
|
+
...KIT_STAT_GRID.allowed.map((k) => `@${tier}:grid-cols-${k}`),
|
|
63
|
+
`@${tier}:col-span-full`, `@${tier}:col-span-1`,
|
|
64
|
+
]),
|
|
32
65
|
]);
|
|
33
66
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
67
|
+
/**
|
|
68
|
+
* 栅格计划 -> 类串:网格类按档升序只写列数变化处(窄屏基准 1 列);末块类只写拉伸标记变化处(拉伸 = 占满整行,退出 = 回到单列宽)。
|
|
69
|
+
* 计划由 gridFillPlanOf 给出,这里只做格式化。
|
|
70
|
+
*/
|
|
71
|
+
export function statGridClassesOf(plan: SomaGridFillPlan): { grid: string; last: string } {
|
|
72
|
+
const grid = [GRID_CLASS];
|
|
73
|
+
const last: string[] = [];
|
|
74
|
+
let cols = 1;
|
|
75
|
+
let stretch = false;
|
|
76
|
+
for (const tier of Object.keys(KIT_STAT_GRID.tierCols)) {
|
|
77
|
+
const c: number = plan.cols[tier] ?? cols;
|
|
78
|
+
if (c !== cols) { grid.push(`@${tier}:grid-cols-${c}`); cols = c; }
|
|
79
|
+
const s: boolean = plan.stretch[tier] ?? stretch;
|
|
80
|
+
if (s !== stretch) { last.push(`@${tier}:col-span-${s ? 'full' : '1'}`); stretch = s; }
|
|
81
|
+
}
|
|
82
|
+
return { grid: grid.join(' '), last: last.join(' ') };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 一排统计块的类:columns 是作者显式写的列数(在真源 explicit 登记才生效),否则按项数防孤行。 */
|
|
86
|
+
export function statGridClasses(count: number, columns: number | null | undefined): { grid: string; last: string } {
|
|
87
|
+
return statGridClassesOf(gridFillPlanOf(KIT_STAT_GRID, count, columns ?? undefined));
|
|
88
|
+
}
|
|
42
89
|
|
|
43
90
|
export interface KitStatItem {
|
|
44
91
|
key: string;
|
|
45
92
|
label: string;
|
|
46
93
|
format: string;
|
|
94
|
+
/** 单位(如 '元'、'单'、'%') */
|
|
95
|
+
unit: string;
|
|
96
|
+
/** 单位取自数据里的键(给了就优先于 unit) */
|
|
97
|
+
unitKey: string;
|
|
47
98
|
/** 环比:数据里放环比数值的键(正升负降);空 = 不显示 */
|
|
48
99
|
trend: string;
|
|
49
100
|
/** 环比的显示格式(缺省 percent,数据按小数,0.12 显示 12%) */
|
|
50
101
|
trendFormat: string;
|
|
102
|
+
/** 对比期变化值(支持 '+12.5%' 或数字,或经 delta 传入) */
|
|
103
|
+
compareValue: string | number | undefined;
|
|
104
|
+
/** 对比期文案(支持 compare / compareLabel / period,如 '较昨日'、'同比上周') */
|
|
105
|
+
compare: string;
|
|
106
|
+
/** 对比期文案取自数据里的键 */
|
|
107
|
+
compareKey: string;
|
|
51
108
|
/** 上升是好事(success)还是坏事(danger);缺省 good */
|
|
52
109
|
upIs: 'good' | 'bad';
|
|
53
110
|
/** 提示文案(字面量) */
|
|
@@ -56,6 +113,28 @@ export interface KitStatItem {
|
|
|
56
113
|
hintKey: string;
|
|
57
114
|
/** 迷你趋势线:数据里放数字数组的键(经 map 对照);空 = 不画。线色按首末涨跌与 upIs 取好 / 坏色 */
|
|
58
115
|
spark: string;
|
|
116
|
+
/** 指标项主色高亮强调 */
|
|
117
|
+
highlight?: boolean;
|
|
118
|
+
/** 项语气(neutral / info / success / warning / danger):只接数据给的词或字面量,组件不比较数值;非闭集 = 无语气 */
|
|
119
|
+
tone: string;
|
|
120
|
+
/** 语气取自数据里的键(给了就优先于 tone) */
|
|
121
|
+
toneKey: string;
|
|
122
|
+
/** 点击跳转地址(走 safeHref;被拒 / 空 = 仍是按钮):块画成链接 */
|
|
123
|
+
href: string;
|
|
124
|
+
/** 地址取自数据里的键 */
|
|
125
|
+
hrefKey: string;
|
|
126
|
+
/** 缺口 / 未知状态(gap / unknown,由数据给;空 = 不指定):此时主数值位画标记而不是值 */
|
|
127
|
+
state: string;
|
|
128
|
+
/** 状态取自数据里的键 */
|
|
129
|
+
stateKey: string;
|
|
130
|
+
/** 缺口 / 未知原因(字面量);值缺失且给了原因时按缺口画 */
|
|
131
|
+
reason: string;
|
|
132
|
+
/** 原因取自数据里的键 */
|
|
133
|
+
reasonKey: string;
|
|
134
|
+
/** 附加数值 [{ key, label, format?, unit? }]:主数值之下的「名 值」小字对,值取自数据;缺失的画缺口标记 */
|
|
135
|
+
values: Array<{ key: string; label: string; format: string; unit: string }>;
|
|
136
|
+
/** 标记(小标签)取自数据里的键:字符串数组或 [{ label, tone? }] */
|
|
137
|
+
flagsKey: string;
|
|
59
138
|
}
|
|
60
139
|
|
|
61
140
|
// 趋势徽标直接复用基础组件 Tag 的 sm 档类串
|
|
@@ -65,13 +144,20 @@ const TREND_UP_CLASS: Record<'good' | 'bad' | 'flat', string> = {
|
|
|
65
144
|
flat: TAG_CLASS.sm.neutral,
|
|
66
145
|
};
|
|
67
146
|
const FOOT_CLASS = 'flex flex-wrap items-center gap-2';
|
|
147
|
+
const COMPARE_CLASS = 'text-xs text-fg-muted';
|
|
68
148
|
const HINT_CLASS = 'text-xs text-fg-subtle';
|
|
69
149
|
|
|
70
|
-
/**
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
150
|
+
/** 环比徽标的语气:实现在基础层 base/trend-tone(KitDelta 共用),此处再导出保持旧引用不变 */
|
|
151
|
+
export { trendTone };
|
|
152
|
+
|
|
153
|
+
function resolveCompareValue(rec: Record<string, unknown>): string | number | undefined {
|
|
154
|
+
for (const k of ['compareValue', 'delta'] as const) {
|
|
155
|
+
const raw = rec[k];
|
|
156
|
+
if (typeof raw === 'number' && Number.isFinite(raw)) return raw;
|
|
157
|
+
if (typeof raw === 'string' && raw.trim() !== '') return raw.trim();
|
|
158
|
+
}
|
|
159
|
+
if (typeof rec.trend === 'number' && Number.isFinite(rec.trend)) return rec.trend;
|
|
160
|
+
return undefined;
|
|
75
161
|
}
|
|
76
162
|
|
|
77
163
|
function itemOf(key: string, label: string, rec: Record<string, unknown>): KitStatItem {
|
|
@@ -79,19 +165,110 @@ function itemOf(key: string, label: string, rec: Record<string, unknown>): KitSt
|
|
|
79
165
|
key,
|
|
80
166
|
label,
|
|
81
167
|
format: str(rec.format),
|
|
82
|
-
|
|
168
|
+
unit: str(rec.unit),
|
|
169
|
+
unitKey: str(rec.unitKey),
|
|
170
|
+
trend: typeof rec.trend === 'string' ? rec.trend : '',
|
|
83
171
|
trendFormat: str(rec.trendFormat, 'percent'),
|
|
172
|
+
compareValue: resolveCompareValue(rec),
|
|
173
|
+
compare: str(rec.compare) || str(rec.compareLabel) || str(rec.period),
|
|
174
|
+
compareKey: str(rec.compareKey),
|
|
84
175
|
upIs: rec.upIs === 'bad' ? 'bad' : 'good',
|
|
85
176
|
hint: str(rec.hint),
|
|
86
177
|
hintKey: str(rec.hintKey),
|
|
87
178
|
spark: str(rec.spark),
|
|
179
|
+
...(rec.highlight === true ? { highlight: true } : {}),
|
|
180
|
+
tone: str(rec.tone),
|
|
181
|
+
toneKey: str(rec.toneKey),
|
|
182
|
+
href: str(rec.href),
|
|
183
|
+
hrefKey: str(rec.hrefKey),
|
|
184
|
+
state: str(rec.state),
|
|
185
|
+
stateKey: str(rec.stateKey),
|
|
186
|
+
reason: str(rec.reason),
|
|
187
|
+
reasonKey: str(rec.reasonKey),
|
|
188
|
+
values: Array.isArray(rec.values)
|
|
189
|
+
? rec.values.flatMap((v) => {
|
|
190
|
+
const r = recOf(v);
|
|
191
|
+
const key = str(r.key);
|
|
192
|
+
return key === '' ? [] : [{ key, label: str(r.label) || key, format: str(r.format), unit: str(r.unit) }];
|
|
193
|
+
})
|
|
194
|
+
: [],
|
|
195
|
+
flagsKey: str(rec.flagsKey),
|
|
88
196
|
};
|
|
89
197
|
}
|
|
90
198
|
|
|
199
|
+
/** 取项上的一个字符串设置:给了数据键就读数据(经 map 对照),否则用字面量 */
|
|
200
|
+
function pickText(literal: string, key: string, map: Record<string, unknown>, data: Record<string, unknown>): string {
|
|
201
|
+
if (key === '') return literal;
|
|
202
|
+
const source = typeof map[key] === 'string' && map[key] !== '' ? String(map[key]) : key;
|
|
203
|
+
return str(data[source]);
|
|
204
|
+
}
|
|
205
|
+
|
|
91
206
|
function recOf(raw: unknown): Record<string, unknown> {
|
|
92
207
|
return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw as Record<string, unknown> : {};
|
|
93
208
|
}
|
|
94
209
|
|
|
210
|
+
function parseChangeString(text: string): { change: number; text: string } {
|
|
211
|
+
const trimmed = text.trim();
|
|
212
|
+
const parsed = Number.parseFloat(trimmed.replace(/[,%\s+]/g, ''));
|
|
213
|
+
const mag = Number.isFinite(parsed) ? Math.abs(parsed) : 0;
|
|
214
|
+
const change = trimmed.startsWith('-') ? -(mag || 1) : trimmed.startsWith('+') ? (mag || 1) : (Number.isFinite(parsed) ? parsed : 0);
|
|
215
|
+
return { change, text: trimmed };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function resolveChangeBadge(
|
|
219
|
+
item: KitStatItem,
|
|
220
|
+
map: Record<string, unknown>,
|
|
221
|
+
data: Record<string, unknown>,
|
|
222
|
+
locale: string,
|
|
223
|
+
): { change: number; text: string } | undefined {
|
|
224
|
+
if (item.trend !== '') {
|
|
225
|
+
const trendSource = typeof map[item.trend] === 'string' && map[item.trend] !== '' ? String(map[item.trend]) : item.trend;
|
|
226
|
+
const trendRaw = data[trendSource];
|
|
227
|
+
const change = num(trendRaw) ?? NaN;
|
|
228
|
+
if (Number.isFinite(change)) {
|
|
229
|
+
return { change, text: formatValue(Math.abs(change), item.trendFormat, locale) };
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const cv = item.compareValue;
|
|
233
|
+
if (typeof cv === 'number' && Number.isFinite(cv)) {
|
|
234
|
+
return { change: cv, text: formatValue(Math.abs(cv), item.trendFormat, locale) };
|
|
235
|
+
}
|
|
236
|
+
if (typeof cv === 'string' && cv !== '') {
|
|
237
|
+
const mapped = typeof map[cv] === 'string' && map[cv] !== '' ? String(map[cv]) : cv;
|
|
238
|
+
if (Object.prototype.hasOwnProperty.call(data, mapped)) {
|
|
239
|
+
const raw = data[mapped];
|
|
240
|
+
const n = num(raw);
|
|
241
|
+
if (typeof n === "number" && Number.isFinite(n)) {
|
|
242
|
+
return { change: n, text: formatValue(Math.abs(n), item.trendFormat, locale) };
|
|
243
|
+
}
|
|
244
|
+
if (typeof raw === 'string' && raw.trim() !== '') {
|
|
245
|
+
return parseChangeString(raw);
|
|
246
|
+
}
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
return parseChangeString(cv);
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function resolveMappedString(
|
|
255
|
+
literalOrKey: string,
|
|
256
|
+
explicitKey: string,
|
|
257
|
+
map: Record<string, unknown>,
|
|
258
|
+
data: Record<string, unknown>,
|
|
259
|
+
): string {
|
|
260
|
+
if (explicitKey !== '') {
|
|
261
|
+
const source = typeof map[explicitKey] === 'string' && map[explicitKey] !== '' ? String(map[explicitKey]) : explicitKey;
|
|
262
|
+
return str(data[source]);
|
|
263
|
+
}
|
|
264
|
+
if (literalOrKey === '') return '';
|
|
265
|
+
const source = typeof map[literalOrKey] === 'string' && map[literalOrKey] !== '' ? String(map[literalOrKey]) : literalOrKey;
|
|
266
|
+
if (Object.prototype.hasOwnProperty.call(data, source) && typeof data[source] === 'string') {
|
|
267
|
+
return String(data[source]);
|
|
268
|
+
}
|
|
269
|
+
return literalOrKey;
|
|
270
|
+
}
|
|
271
|
+
|
|
95
272
|
/** 决定展示哪几项(纯函数,便于单测) */
|
|
96
273
|
export function statItemsOf(itemsRaw: unknown, mapRaw: unknown, data: Record<string, unknown>): KitStatItem[] {
|
|
97
274
|
const map = recOf(mapRaw);
|
|
@@ -120,9 +297,9 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
120
297
|
layer: 'data',
|
|
121
298
|
props: {
|
|
122
299
|
data: { type: 'object', default: {}, desc: '统计对象,如 { total: 12, open: 3 }' },
|
|
123
|
-
items: { type: 'array', default: [], desc: '展示项 [{ key, label, format?, trend?, trendFormat?, upIs?, hint?, hintKey? }];format 取 soma-foundation/values 的写法(number / percent / currency:CNY 等);trend
|
|
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? }])' },
|
|
124
301
|
map: { type: 'object', default: {}, desc: '键名对照:items 里的 key -> 数据里的键' },
|
|
125
|
-
columns: { type: 'number', default: 0, desc: '列数:1 / 2 / 3 / 4 / 6(宽容器下的列数,窄容器 1 列);0 或其它 =
|
|
302
|
+
columns: { type: 'number', default: 0, desc: '列数:1 / 2 / 3 / 4 / 6(宽容器下的列数,窄容器 1 列);0 或其它 = 自动(每个容器宽度档按项数取不让末行落单一项的列数,档位与上限见真源 kit-limits 的 statGrid)。单个统计卡片 = 一项 items + columns: 1' },
|
|
126
303
|
locale: { type: 'string', default: '', desc: '格式化语言;空则 zh-CN' },
|
|
127
304
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
128
305
|
},
|
|
@@ -131,77 +308,14 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
131
308
|
},
|
|
132
309
|
},
|
|
133
310
|
templateHtml: `<div data-soma-id="root" class="${WRAP_CLASS}"><div data-soma-id="grid" class="${GRID_CLASS}"></div></div>`,
|
|
134
|
-
controllerFactory: (
|
|
135
|
-
const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
|
|
311
|
+
controllerFactory: createKitController((api) => {
|
|
136
312
|
let root: HTMLElement | null = null;
|
|
137
313
|
let grid: HTMLElement | null = null;
|
|
138
|
-
let cleanup: (() => void) | undefined;
|
|
139
314
|
let current: Array<{ key: string; label: string; value: unknown }> = [];
|
|
140
315
|
|
|
141
|
-
const paint = (): void => {
|
|
142
|
-
if (!root || !grid) return;
|
|
143
|
-
const p = P();
|
|
144
|
-
const data = recOf(p.data);
|
|
145
|
-
const map = recOf(p.map);
|
|
146
|
-
const locale = str(p.locale);
|
|
147
|
-
root.className = joinClass(WRAP_CLASS, p.class);
|
|
148
|
-
grid.className = GRID_BY_COLUMNS[num(p.columns) ?? 0] ?? GRID_CLASS;
|
|
149
|
-
grid.textContent = '';
|
|
150
|
-
current = [];
|
|
151
|
-
for (const item of statItemsOf(p.items, map, data)) {
|
|
152
|
-
const source = typeof map[item.key] === 'string' && map[item.key] !== '' ? String(map[item.key]) : item.key;
|
|
153
|
-
const value = data[source];
|
|
154
|
-
current.push({ key: item.key, label: item.label, value });
|
|
155
|
-
const block = document.createElement('button');
|
|
156
|
-
block.type = 'button';
|
|
157
|
-
block.className = BLOCK_CLASS;
|
|
158
|
-
block.setAttribute('data-kit-stat', item.key);
|
|
159
|
-
const label = document.createElement('span');
|
|
160
|
-
label.className = LABEL_CLASS;
|
|
161
|
-
label.textContent = item.label;
|
|
162
|
-
const val = document.createElement('span');
|
|
163
|
-
val.className = VALUE_CLASS;
|
|
164
|
-
val.textContent = value === undefined || value === null || value === '' ? '' : formatValue(value, item.format, locale);
|
|
165
|
-
block.appendChild(label);
|
|
166
|
-
block.appendChild(val);
|
|
167
|
-
if (item.spark !== '') {
|
|
168
|
-
const sparkSource = typeof map[item.spark] === 'string' && map[item.spark] !== '' ? String(map[item.spark]) : item.spark;
|
|
169
|
-
const values = trendValuesOf(data[sparkSource]);
|
|
170
|
-
const svg = sparklineSvg(values, { tone: trendToneOf('auto', values, item.upIs), label: item.label, className: 'h-8 w-full' });
|
|
171
|
-
if (svg) block.appendChild(svg);
|
|
172
|
-
}
|
|
173
|
-
// 环比与提示:规则写死——趋势数值取 trend 键(经 map 对照),正升负降,语气由 upIs 决定
|
|
174
|
-
const trendSource = item.trend === '' ? '' : (typeof map[item.trend] === 'string' && map[item.trend] !== '' ? String(map[item.trend]) : item.trend);
|
|
175
|
-
const trendRaw = trendSource === '' ? undefined : data[trendSource];
|
|
176
|
-
// null / 空 / 非数字都不出徽标(Number(null) 是 0,不能让缺值显示成「持平 0%」)
|
|
177
|
-
const change = num(trendRaw) ?? NaN;
|
|
178
|
-
const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
|
|
179
|
-
if (Number.isFinite(change) || hintText !== '') {
|
|
180
|
-
const foot = document.createElement('span');
|
|
181
|
-
foot.className = FOOT_CLASS;
|
|
182
|
-
if (Number.isFinite(change)) {
|
|
183
|
-
const badge = document.createElement('span');
|
|
184
|
-
badge.className = TREND_UP_CLASS[trendTone(change, item.upIs)];
|
|
185
|
-
badge.setAttribute('data-kit-trend', change > 0 ? 'up' : change < 0 ? 'down' : 'flat');
|
|
186
|
-
badge.appendChild(kitIcon(change > 0 ? 'arrow-up' : change < 0 ? 'arrow-down' : 'minus', 'xs'));
|
|
187
|
-
badge.appendChild(document.createTextNode(formatValue(Math.abs(change), item.trendFormat, locale)));
|
|
188
|
-
foot.appendChild(badge);
|
|
189
|
-
}
|
|
190
|
-
if (hintText !== '') {
|
|
191
|
-
const hint = document.createElement('span');
|
|
192
|
-
hint.className = HINT_CLASS;
|
|
193
|
-
hint.textContent = hintText;
|
|
194
|
-
foot.appendChild(hint);
|
|
195
|
-
}
|
|
196
|
-
block.appendChild(foot);
|
|
197
|
-
}
|
|
198
|
-
grid.appendChild(block);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
316
|
return {
|
|
203
|
-
|
|
204
|
-
root =
|
|
317
|
+
attach(rootEl) {
|
|
318
|
+
root = rootEl;
|
|
205
319
|
grid = root.querySelector<HTMLElement>('[data-soma-scoped-id="grid"]')
|
|
206
320
|
?? root.querySelector<HTMLElement>('[data-soma-id="grid"]');
|
|
207
321
|
const r = root;
|
|
@@ -210,22 +324,191 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
210
324
|
if (!hit) return;
|
|
211
325
|
const key = hit.getAttribute('data-kit-stat');
|
|
212
326
|
const item = current.find((c) => c.key === key);
|
|
213
|
-
if (item)
|
|
327
|
+
if (item) api.emit('select', { item });
|
|
214
328
|
};
|
|
215
329
|
r.addEventListener('click', onClick);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
330
|
+
return () => {
|
|
331
|
+
r.removeEventListener('click', onClick);
|
|
332
|
+
root = null;
|
|
333
|
+
grid = null;
|
|
334
|
+
};
|
|
221
335
|
},
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
grid
|
|
336
|
+
render(rootEl, p) {
|
|
337
|
+
root = rootEl;
|
|
338
|
+
grid = root.querySelector<HTMLElement>('[data-soma-scoped-id="grid"]')
|
|
339
|
+
?? root.querySelector<HTMLElement>('[data-soma-id="grid"]');
|
|
340
|
+
if (!grid) return;
|
|
341
|
+
const data = recOf(p.data);
|
|
342
|
+
const map = recOf(p.map);
|
|
343
|
+
const locale = str(p.locale);
|
|
344
|
+
root.className = joinClass(WRAP_CLASS, p.class);
|
|
345
|
+
const items = statItemsOf(p.items, map, data);
|
|
346
|
+
const classes = statGridClasses(items.length, num(p.columns));
|
|
347
|
+
grid.className = classes.grid;
|
|
348
|
+
// 导轨拼合 + 三槽对齐(默认行为,不是页面语法):块并进一个带通栏细线的容器,标题 / 指标 / 操作三槽跨块水平对齐
|
|
349
|
+
markKitRail(grid);
|
|
350
|
+
const foots = items.map((item) => {
|
|
351
|
+
const changeBadge = resolveChangeBadge(item, map, data, locale);
|
|
352
|
+
const compareText = resolveMappedString(item.compare, item.compareKey, map, data);
|
|
353
|
+
const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
|
|
354
|
+
return { changeBadge, compareText, hintText, any: changeBadge !== undefined || compareText !== '' || hintText !== '' };
|
|
355
|
+
});
|
|
356
|
+
markKitSlotGrid(grid, slotCountOf(foots.some((f) => f.any)));
|
|
357
|
+
grid.textContent = '';
|
|
358
|
+
current = [];
|
|
359
|
+
for (const [index, item] of items.entries()) {
|
|
360
|
+
const source = typeof map[item.key] === 'string' && map[item.key] !== '' ? String(map[item.key]) : item.key;
|
|
361
|
+
const value = data[source];
|
|
362
|
+
current.push({ key: item.key, label: item.label, value });
|
|
363
|
+
// href(字面量或取自数据,过 safeHref):块画成链接,原生跳转;被拒或没给仍是按钮。select 事件两种形态都照常抛
|
|
364
|
+
const hrefSafe = safeHref(pickText(item.href, item.hrefKey, map, data));
|
|
365
|
+
const block: HTMLElement = document.createElement(hrefSafe !== '' ? 'a' : 'button');
|
|
366
|
+
if (block instanceof HTMLButtonElement) block.type = 'button';
|
|
367
|
+
else block.setAttribute('href', hrefSafe);
|
|
368
|
+
// 块在导轨里不描边、不画卡片(不标 card 部件,免得命中容器边界 / 阴影规则);高亮块只换底色
|
|
369
|
+
const blockClass = item.highlight === true ? `${BLOCK_CLASS} bg-primary-soft` : BLOCK_CLASS;
|
|
370
|
+
const edgeLast = index === items.length - 1;
|
|
371
|
+
block.className = edgeLast && classes.last !== '' ? `${blockClass} ${classes.last}` : blockClass;
|
|
372
|
+
block.setAttribute('data-kit-stat', item.key);
|
|
373
|
+
if (item.highlight === true) block.setAttribute('data-kit-highlight', 'true');
|
|
374
|
+
const label = markKitSlot(document.createElement('span'), 'title');
|
|
375
|
+
label.className = LABEL_CLASS;
|
|
376
|
+
label.textContent = item.label;
|
|
377
|
+
// 项语气(数据给的词):指标名前加图标 + 读屏文字(双编码,不靠颜色);非闭集的词忽略
|
|
378
|
+
const itemTone = statusToneOrNull(pickText(item.tone, item.toneKey, map, data));
|
|
379
|
+
if (itemTone !== null) {
|
|
380
|
+
block.setAttribute('data-kit-tone', itemTone);
|
|
381
|
+
label.className = `${LABEL_CLASS} ${KIT_STAT_TONE_LABEL}`;
|
|
382
|
+
const sr = document.createElement('span');
|
|
383
|
+
sr.className = KIT_NOTICE_SR_ONLY;
|
|
384
|
+
sr.textContent = kitText(KIT_STATUS_TONE_TEXT_KEY[itemTone], undefined, rootEl);
|
|
385
|
+
label.replaceChildren(kitIcon(KIT_STATUS_TONE_ICON[itemTone], 'xs', KIT_NOTICE_ICON[itemTone]), sr, document.createTextNode(item.label));
|
|
386
|
+
}
|
|
387
|
+
const val = document.createElement('span');
|
|
388
|
+
val.className = VALUE_CLASS;
|
|
389
|
+
val.setAttribute('data-kit-stat-value', '');
|
|
390
|
+
val.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE);
|
|
391
|
+
val.textContent = value === undefined || value === null || value === '' ? '' : formatValue(value, item.format, locale);
|
|
392
|
+
// 缺口 / 未知(由数据给):state 明示 gap / unknown,或值缺失且给了原因(缺口);此时主数值位画标记,不画空白 / 0
|
|
393
|
+
const stateRaw = pickText(item.state, item.stateKey, map, data);
|
|
394
|
+
const reasonText = pickText(item.reason, item.reasonKey, map, data);
|
|
395
|
+
const valueMissing = value === undefined || value === null || value === '';
|
|
396
|
+
const gapKind = stateRaw === 'gap' || stateRaw === 'unknown' ? stateRaw : valueMissing && reasonText.trim() !== '' ? 'gap' : null;
|
|
397
|
+
if (gapKind !== null) {
|
|
398
|
+
val.textContent = '';
|
|
399
|
+
val.setAttribute('data-kit-gap', gapKind);
|
|
400
|
+
val.appendChild(gapMarkerNode(gapKind, reasonText, rootEl));
|
|
401
|
+
}
|
|
402
|
+
block.appendChild(label);
|
|
403
|
+
const metric = markKitSlot(document.createElement('span'), 'metric');
|
|
404
|
+
metric.className = METRIC_SLOT_CLASS;
|
|
405
|
+
block.appendChild(metric);
|
|
406
|
+
|
|
407
|
+
const unitText = gapKind !== null ? '' : resolveMappedString(item.unit, item.unitKey, map, data);
|
|
408
|
+
if (unitText !== '') {
|
|
409
|
+
const valRow = document.createElement('span');
|
|
410
|
+
valRow.className = VALUE_ROW_CLASS;
|
|
411
|
+
// 带单位时贴底对齐交给整行(VALUE_ROW_CLASS);数值自己不再带 mt-auto,否则在行内被单独下推,单位浮到右上角
|
|
412
|
+
val.className = STAT_VALUE_CLASS;
|
|
413
|
+
valRow.appendChild(val);
|
|
414
|
+
const unitEl = document.createElement('span');
|
|
415
|
+
unitEl.className = UNIT_CLASS;
|
|
416
|
+
unitEl.setAttribute('data-kit-stat-unit', '');
|
|
417
|
+
unitEl.textContent = unitText;
|
|
418
|
+
valRow.appendChild(unitEl);
|
|
419
|
+
metric.appendChild(valRow);
|
|
420
|
+
} else {
|
|
421
|
+
metric.appendChild(val);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (item.spark !== '') {
|
|
425
|
+
const sparkSource = typeof map[item.spark] === 'string' && map[item.spark] !== '' ? String(map[item.spark]) : item.spark;
|
|
426
|
+
const values = trendValuesOf(data[sparkSource]);
|
|
427
|
+
const svg = sparklineSvg(values, { tone: trendToneOf('auto', values, item.upIs), label: item.label, className: 'h-8 w-full' });
|
|
428
|
+
if (svg) metric.appendChild(svg);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// 附加数值:主数值之下的「名 值」小字对;值缺失的画缺口标记(不画空白 / 0)
|
|
432
|
+
if (item.values.length > 0) {
|
|
433
|
+
const row = document.createElement('span');
|
|
434
|
+
row.className = KIT_STAT_VALUES_ROW;
|
|
435
|
+
row.setAttribute('data-kit-stat-values', '');
|
|
436
|
+
for (const sub of item.values) {
|
|
437
|
+
const subSource = typeof map[sub.key] === 'string' && map[sub.key] !== '' ? String(map[sub.key]) : sub.key;
|
|
438
|
+
const subValue = data[subSource];
|
|
439
|
+
const pair = document.createElement('span');
|
|
440
|
+
pair.setAttribute('data-kit-stat-sub', sub.key);
|
|
441
|
+
pair.appendChild(document.createTextNode(`${sub.label} `));
|
|
442
|
+
if (subValue === undefined || subValue === null || subValue === '') {
|
|
443
|
+
pair.appendChild(gapMarkerNode('gap', '', rootEl, 'sm'));
|
|
444
|
+
} else {
|
|
445
|
+
const numEl = document.createElement('span');
|
|
446
|
+
numEl.className = KIT_STAT_VALUES_NUM;
|
|
447
|
+
const shown = formatValue(subValue, sub.format, locale);
|
|
448
|
+
numEl.textContent = sub.unit === '' ? shown : `${shown} ${sub.unit}`;
|
|
449
|
+
pair.appendChild(numEl);
|
|
450
|
+
}
|
|
451
|
+
row.appendChild(pair);
|
|
452
|
+
}
|
|
453
|
+
metric.appendChild(row);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// 标记:数据给的小标签(字符串或 { label, tone? }),顺序与取舍由数据决定
|
|
457
|
+
if (item.flagsKey !== '') {
|
|
458
|
+
const flagSource = typeof map[item.flagsKey] === 'string' && map[item.flagsKey] !== '' ? String(map[item.flagsKey]) : item.flagsKey;
|
|
459
|
+
const flagData = data[flagSource];
|
|
460
|
+
const flags = Array.isArray(flagData) ? flagData.flatMap((f) => {
|
|
461
|
+
const r = recOf(f);
|
|
462
|
+
const text = typeof f === 'string' ? f : str(r.label);
|
|
463
|
+
return text === '' ? [] : [{ text, tone: statusToneOrNull(r.tone) ?? 'neutral' }];
|
|
464
|
+
}) : [];
|
|
465
|
+
if (flags.length > 0) {
|
|
466
|
+
const row = document.createElement('span');
|
|
467
|
+
row.className = KIT_STAT_FLAGS_ROW;
|
|
468
|
+
row.setAttribute('data-kit-stat-flags', '');
|
|
469
|
+
for (const f of flags) {
|
|
470
|
+
const chip = document.createElement('span');
|
|
471
|
+
chip.className = TAG_CLASS.sm[f.tone];
|
|
472
|
+
chip.textContent = f.text;
|
|
473
|
+
row.appendChild(chip);
|
|
474
|
+
}
|
|
475
|
+
metric.appendChild(row);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// 变化率、对比期说明与提示:趋势数值取 trend / compareValue / delta,对比期取 compare / compareLabel / period
|
|
480
|
+
const { changeBadge, compareText, hintText } = foots[index]!;
|
|
481
|
+
if (changeBadge !== undefined || compareText !== '' || hintText !== '') {
|
|
482
|
+
const foot = markKitSlot(document.createElement('span'), 'action');
|
|
483
|
+
foot.className = FOOT_CLASS;
|
|
484
|
+
if (changeBadge !== undefined) {
|
|
485
|
+
const { change, text: changeText } = changeBadge;
|
|
486
|
+
const badge = document.createElement('span');
|
|
487
|
+
badge.className = TREND_UP_CLASS[trendTone(change, item.upIs)];
|
|
488
|
+
badge.setAttribute('data-kit-trend', change > 0 ? 'up' : change < 0 ? 'down' : 'flat');
|
|
489
|
+
badge.appendChild(kitIcon(change > 0 ? 'arrow-up' : change < 0 ? 'arrow-down' : 'minus', 'xs'));
|
|
490
|
+
badge.appendChild(document.createTextNode(changeText));
|
|
491
|
+
foot.appendChild(badge);
|
|
492
|
+
}
|
|
493
|
+
if (compareText !== '') {
|
|
494
|
+
const cmp = document.createElement('span');
|
|
495
|
+
cmp.className = COMPARE_CLASS;
|
|
496
|
+
cmp.setAttribute('data-kit-stat-compare', '');
|
|
497
|
+
cmp.textContent = compareText;
|
|
498
|
+
foot.appendChild(cmp);
|
|
499
|
+
}
|
|
500
|
+
if (hintText !== '') {
|
|
501
|
+
const hint = document.createElement('span');
|
|
502
|
+
hint.className = HINT_CLASS;
|
|
503
|
+
hint.textContent = hintText;
|
|
504
|
+
foot.appendChild(hint);
|
|
505
|
+
}
|
|
506
|
+
block.appendChild(foot);
|
|
507
|
+
}
|
|
508
|
+
grid.appendChild(block);
|
|
509
|
+
}
|
|
227
510
|
},
|
|
228
511
|
};
|
|
229
|
-
},
|
|
512
|
+
}),
|
|
230
513
|
};
|
|
231
514
|
}
|
package/src/data/static-lazy.ts
CHANGED
|
@@ -56,6 +56,7 @@ export const KIT_STATIC_LAZY_LOADERS: Readonly<Record<string, Loader>> = Object.
|
|
|
56
56
|
TourGuide: () => import('./tour-guide').then((m) => m.createTourGuide()),
|
|
57
57
|
TrendLine: () => import('./trend-line').then((m) => m.createTrendLine()),
|
|
58
58
|
RecordPicker: () => import('./record-picker').then((m) => m.createRecordPicker()),
|
|
59
|
+
NoticeList: () => import('./notice-list').then((m) => m.createNoticeList()),
|
|
59
60
|
Chart: () => import('./chart').then((m) => m.createChart()),
|
|
60
61
|
});
|
|
61
62
|
|