soma-kit 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +158 -4
- package/spec/generated/kit-page.schema.json +139 -5
- package/spec/kit-grammar.json +438 -87
- package/spec/kit-grammar.schema.json +11 -3
- package/src/app/app-config.ts +83 -5
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +17 -5
- package/src/app/kit-view-context.ts +163 -14
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +3 -1
- package/src/app/server.ts +40 -3
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +57 -12
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/index.ts +27 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +23 -12
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +9 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +24 -22
- package/src/base/shared.ts +169 -23
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +63 -33
- package/src/base/text.ts +42 -13
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -10
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +2 -2
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/import-wizard/shell.ts +2 -1
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +102 -10
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +4 -1
- package/src/biz/multi-board/shell.ts +8 -5
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +18 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +139 -10
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +22 -160
- package/src/biz/standard-crud/shell.ts +16 -44
- package/src/biz/step-form/shell.ts +5 -5
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/view-writes.ts +69 -60
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +51 -7
- package/src/compile/component-candidates.ts +12 -1
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +36 -8
- package/src/compile/types.ts +13 -1
- package/src/compile/view-check.ts +149 -16
- package/src/data/amount-breakdown.ts +6 -1
- package/src/data/approval-flow.ts +1 -1
- package/src/data/assignment-picker.ts +53 -27
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +2 -2
- package/src/data/carousel.ts +8 -6
- package/src/data/chart.ts +141 -10
- package/src/data/checklist.ts +18 -5
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +2 -2
- package/src/data/confirm-dialog.ts +71 -18
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +4 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +25 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/gantt.ts +5 -2
- package/src/data/hero.ts +2 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +6 -1
- package/src/data/item-list.ts +18 -10
- package/src/data/kanban.ts +39 -10
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +45 -13
- package/src/data/mockup.ts +8 -4
- package/src/data/modal-dialog.ts +29 -9
- package/src/data/navbar.ts +5 -5
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +354 -48
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +17 -7
- package/src/data/permission-matrix.ts +33 -11
- package/src/data/permission-tree.ts +47 -22
- package/src/data/pricing-table.ts +21 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +23 -2
- package/src/data/record-picker.ts +13 -7
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +79 -26
- package/src/data/rule-builder.ts +8 -8
- package/src/data/shape-util.ts +23 -9
- package/src/data/stat-group.ts +170 -29
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +2 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +3 -3
- package/src/data/system-switcher.ts +1 -1
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +1 -1
- package/src/data/transfer.ts +36 -16
- package/src/data/tree-table.ts +62 -36
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +19 -10
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/page-bar.ts +14 -13
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +15 -10
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +2 -1
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +2 -2
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/view.ts +141 -33
- package/src/generated/kit-grammar-runtime.ts +239 -55
- package/src/i18n/kit-text.ts +63 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/arrange.ts +42 -8
- package/src/object-renderer/collection-parts.ts +241 -60
- package/src/object-renderer/collection-table.ts +109 -5
- package/src/object-renderer/collection.ts +174 -36
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +30 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-static.ts +370 -30
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/render-object.ts +54 -6
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +135 -27
- package/src/object-renderer/table-tools.ts +12 -11
- package/src/object-renderer/types.ts +78 -7
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +46 -1
- package/src/recipes/control.ts +70 -12
- package/src/recipes/index.ts +49 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +75 -17
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +34 -5
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +40 -3
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +13 -1
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +372 -12
- package/src/theme/kit-theme.tpl +372 -12
- package/src/theme/nine-dim-structure.ts +177 -7
- package/src/theme/surface-layers.ts +4 -0
- package/src/theme/theme-tokens.ts +53 -13
- package/src/theme/theme-types.ts +32 -0
- package/src/biz/shared/remove-key.ts +0 -6
package/src/data/rule-builder.ts
CHANGED
|
@@ -237,10 +237,10 @@ export function describeCondition(cond: RuleCondition, field: RuleField | undefi
|
|
|
237
237
|
|
|
238
238
|
const VALUE_WRAP = 'flex min-w-40 flex-1 flex-wrap items-center gap-2';
|
|
239
239
|
const CONTROL = `${FIELD_CLASS.md} data-kit-invalid:border-danger`;
|
|
240
|
-
const DATE_CONTROL = 'block h-
|
|
240
|
+
const DATE_CONTROL = 'block h-8 w-full rounded-md border border-border bg-surface ps-3 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken data-kit-invalid:border-danger';
|
|
241
241
|
const RANGE_SEP = 'text-fg-subtle';
|
|
242
242
|
const PILLS = 'flex flex-wrap gap-1.5';
|
|
243
|
-
const PILL = 'inline-flex h-8 items-center rounded-full border border-border bg-surface px-3 text-xs text-fg transition-colors
|
|
243
|
+
const PILL = 'inline-flex h-8 items-center rounded-full border border-border bg-surface px-3 text-xs text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-kit-selected:border-primary data-kit-selected:bg-primary-soft data-kit-selected:text-primary-on-soft';
|
|
244
244
|
const HALF = 'min-w-28 flex-1';
|
|
245
245
|
|
|
246
246
|
export const KIT_RULE_CONDITION_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
@@ -589,11 +589,11 @@ const GROUP_CLASS = 'flex flex-col gap-2 rounded-lg border border-border-subtle
|
|
|
589
589
|
const GROUP_NESTED_CLASS = 'flex flex-col gap-2 rounded-lg border border-border-subtle bg-surface-sunken p-3';
|
|
590
590
|
const HEAD_CLASS = 'flex flex-wrap items-center gap-2';
|
|
591
591
|
const MODE_WRAP_CLASS = 'inline-flex rounded-md border border-border bg-surface p-0.5';
|
|
592
|
-
const MODE_BTN_CLASS = 'inline-flex h-7 items-center justify-center rounded-md px-3 text-xs font-medium text-fg-muted transition-colors hover:bg-
|
|
593
|
-
const NOT_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-
|
|
592
|
+
const MODE_BTN_CLASS = 'inline-flex h-7 items-center justify-center rounded-md px-3 text-xs font-medium text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-kit-selected:bg-primary data-kit-selected:text-primary-fg data-kit-selected:hover:bg-primary-hover';
|
|
593
|
+
const NOT_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-xs font-medium text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-kit-selected:border-primary data-kit-selected:bg-primary-soft data-kit-selected:text-primary-on-soft';
|
|
594
594
|
const SPACER_CLASS = 'flex-1';
|
|
595
|
-
const TOOL_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-
|
|
596
|
-
const ACT_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-xs text-fg-muted transition-colors hover:bg-
|
|
595
|
+
const TOOL_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-xs font-medium text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
596
|
+
const ACT_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
597
597
|
const DEL_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-xs text-danger-on-soft transition-colors hover:bg-danger-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
598
598
|
const ACTIONS_CLASS = 'inline-flex items-center gap-0.5';
|
|
599
599
|
const BODY_CLASS = 'flex flex-col gap-2';
|
|
@@ -605,8 +605,8 @@ const EMPTY_CLASS = 'rounded-md border border-dashed border-border-subtle px-3 p
|
|
|
605
605
|
const SUMMARY_CLASS = 'rounded-md bg-surface-sunken px-3 py-2 text-sm text-fg-muted';
|
|
606
606
|
const READONLY_CLASS = 'text-sm text-fg';
|
|
607
607
|
const FOOT_CLASS = 'flex items-center justify-end gap-2';
|
|
608
|
-
const SAVE_CLASS = 'inline-flex h-
|
|
609
|
-
const CANCEL_CLASS = 'inline-flex h-
|
|
608
|
+
const SAVE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
609
|
+
const CANCEL_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-button-edge bg-surface px-4 text-sm font-medium text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
610
610
|
|
|
611
611
|
export const KIT_RULE_BUILDER_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
612
612
|
ROOT_CLASS, GROUP_CLASS, GROUP_NESTED_CLASS, HEAD_CLASS, MODE_WRAP_CLASS, MODE_BTN_CLASS, NOT_BTN_CLASS, SPACER_CLASS, TOOL_BTN_CLASS,
|
package/src/data/shape-util.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// 颜色只用语义色名:彩色文字只配 `-on-soft`,实心底只配 `-fg`;空态与分隔用实线。
|
|
7
7
|
|
|
8
8
|
import { setKitFace } from '../recipes';
|
|
9
|
+
import { KIT_STATE_EMPTY_COMPACT, KIT_STATE_RETRY_CLASS_CANDIDATES, kitRetryRecipe, type KitRetryTone } from '../recipes/placeholder';
|
|
10
|
+
import { kitEmptyPanel } from '../base/state-panel';
|
|
9
11
|
|
|
10
12
|
export type Rec = Record<string, unknown>;
|
|
11
13
|
|
|
@@ -85,23 +87,23 @@ export const TONE_SOLID: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
|
85
87
|
/** 标签(小胶囊) */
|
|
86
88
|
export const BADGE_BASE = 'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium';
|
|
87
89
|
|
|
88
|
-
/**
|
|
89
|
-
export const EMPTY_CLASS =
|
|
90
|
+
/** 空态:虚线框(紧凑形;类串来自 recipes/placeholder,受控类只在 recipes 层) */
|
|
91
|
+
export const EMPTY_CLASS = KIT_STATE_EMPTY_COMPACT;
|
|
90
92
|
|
|
91
93
|
// ── 动作按钮 ─────────────────────────────────────────────────
|
|
92
94
|
|
|
93
95
|
export type ActionTone = 'primary' | 'danger' | 'neutral';
|
|
94
96
|
|
|
95
|
-
const BUTTON_BASE = 'inline-flex items-center justify-center rounded-md px-3 py-1.5 text-sm font-medium transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
97
|
+
const BUTTON_BASE = 'inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
96
98
|
const BUTTON_TONE: Readonly<Record<ActionTone, string>> = Object.freeze({
|
|
97
99
|
primary: 'border-0 bg-primary text-primary-fg hover:opacity-90',
|
|
98
100
|
danger: 'border-0 bg-danger text-danger-fg hover:opacity-90',
|
|
99
|
-
neutral: 'border border-
|
|
101
|
+
neutral: 'border border-button-edge bg-surface text-fg state-layer',
|
|
100
102
|
});
|
|
101
103
|
const BUTTON_DISABLED = 'opacity-50 cursor-not-allowed';
|
|
102
104
|
|
|
103
105
|
export const BUTTON_CLASS_TOKENS: readonly string[] = classTokens(
|
|
104
|
-
BUTTON_BASE, Object.values(BUTTON_TONE), BUTTON_DISABLED,
|
|
106
|
+
BUTTON_BASE, Object.values(BUTTON_TONE), BUTTON_DISABLED, KIT_STATE_RETRY_CLASS_CANDIDATES,
|
|
105
107
|
);
|
|
106
108
|
|
|
107
109
|
export function actionToneOf(raw: unknown): ActionTone {
|
|
@@ -152,6 +154,16 @@ export function actionButton(action: ShapeAction, extraClass = ''): HTMLButtonEl
|
|
|
152
154
|
return btn;
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
/** 「重试」钮(kitRetryRecipe 的中性档,全 kit 唯一一种写法):带 data-kit-action,供各组件的点击委托识别 */
|
|
158
|
+
export function retryButton(key: string, label: string, tone: KitRetryTone = 'neutral'): HTMLButtonElement {
|
|
159
|
+
const btn = document.createElement('button');
|
|
160
|
+
btn.type = 'button';
|
|
161
|
+
btn.className = kitRetryRecipe(tone);
|
|
162
|
+
btn.textContent = label;
|
|
163
|
+
btn.setAttribute('data-kit-action', key);
|
|
164
|
+
return btn;
|
|
165
|
+
}
|
|
166
|
+
|
|
155
167
|
// ── DOM ──────────────────────────────────────────────────────
|
|
156
168
|
|
|
157
169
|
/** 自绘进度条(替代原生 <progress>)用到的类;并入用到 mkProgressBar 的组件候选类 */
|
|
@@ -204,10 +216,12 @@ export function mk<K extends keyof HTMLElementTagNameMap>(
|
|
|
204
216
|
return el;
|
|
205
217
|
}
|
|
206
218
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
219
|
+
/**
|
|
220
|
+
* 数据组件的空态:与集合空态同一画法(base/state-panel.ts:插画 + 文案、role=status);
|
|
221
|
+
* compact = 只有文案(嵌在表单 / 小容器里,如子表、样机屏幕),其余沿用同一个盒的类。
|
|
222
|
+
*/
|
|
223
|
+
export function emptyNode(text: string, compact = false): HTMLElement {
|
|
224
|
+
return kitEmptyPanel(document, text, compact);
|
|
211
225
|
}
|
|
212
226
|
|
|
213
227
|
/** 值转文字:空值回空串 */
|
package/src/data/stat-group.ts
CHANGED
|
@@ -12,31 +12,51 @@ import { gridFillPlanOf, type SomaGridFillPlan } from 'soma-foundation/data/valu
|
|
|
12
12
|
import { KIT_STAT_GRID } from 'soma-foundation/kit-limits';
|
|
13
13
|
import { createKitController, formatValue, joinClass, num, str } from '../base/shared';
|
|
14
14
|
import { kitIcon } from '../base/icons';
|
|
15
|
+
import { trendTone } from '../base/trend-tone';
|
|
15
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';
|
|
16
22
|
import { KIT_TREND_LINE_CLASS_CANDIDATES, sparklineSvg, trendToneOf, trendValuesOf } from './trend-line';
|
|
17
|
-
import { KIT_PART_ATTRIBUTE,
|
|
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';
|
|
18
30
|
|
|
19
31
|
const WRAP_CLASS = '@container';
|
|
20
|
-
|
|
21
|
-
|
|
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`;
|
|
22
36
|
const LABEL_CLASS = 'text-xs font-medium text-fg-muted';
|
|
23
37
|
/** 指标主数值样式:对齐规则卡 30px 大数字 + font-bold tabular-nums */
|
|
24
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';
|
|
25
42
|
const VALUE_CLASS = STAT_VALUE_CLASS;
|
|
26
43
|
const VALUE_ROW_CLASS = 'inline-flex items-baseline gap-1';
|
|
27
44
|
const UNIT_CLASS = 'text-xs font-normal text-fg-muted';
|
|
28
45
|
|
|
29
46
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
30
47
|
export const KIT_STAT_GROUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
31
|
-
'@container', 'grid', 'grid-cols-1', '
|
|
32
|
-
'flex', 'flex-col', 'gap-1', '
|
|
48
|
+
'@container', 'grid', 'grid-cols-1', 'min-w-0', 'appearance-none', 'border-0', 'bg-primary-soft',
|
|
49
|
+
'flex', 'flex-col', 'gap-1', 'text-start',
|
|
33
50
|
'transition-colors', 'active:opacity-80', 'font-medium', 'font-normal', 'font-bold', 'tabular-nums',
|
|
34
|
-
'
|
|
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,
|
|
35
53
|
'text-sm', 'text-fg-muted', 'text-2xl', 'text-stat-value', 'font-title', 'tracking-tight', 'font-semibold', 'text-fg',
|
|
36
54
|
'items-center', 'items-baseline', 'flex-wrap', 'rounded-md', 'px-1.5', 'py-0.5', 'text-xs', 'inline-flex',
|
|
37
55
|
...Object.values(TAG_CLASS.sm).flatMap((s) => s.split(' ')),
|
|
38
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',
|
|
39
57
|
...KIT_TREND_LINE_CLASS_CANDIDATES, 'h-8', 'w-full',
|
|
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),
|
|
40
60
|
// 各档列数与末块拉伸的全部可能类(档名 x 允许列数取自真源,Tailwind 静态扫描不到运行期拼的类名,所以在此列全)
|
|
41
61
|
...Object.keys(KIT_STAT_GRID.tierCols).flatMap((tier) => [
|
|
42
62
|
...KIT_STAT_GRID.allowed.map((k) => `@${tier}:grid-cols-${k}`),
|
|
@@ -95,6 +115,26 @@ export interface KitStatItem {
|
|
|
95
115
|
spark: string;
|
|
96
116
|
/** 指标项主色高亮强调 */
|
|
97
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;
|
|
98
138
|
}
|
|
99
139
|
|
|
100
140
|
// 趋势徽标直接复用基础组件 Tag 的 sm 档类串
|
|
@@ -107,12 +147,8 @@ const FOOT_CLASS = 'flex flex-wrap items-center gap-2';
|
|
|
107
147
|
const COMPARE_CLASS = 'text-xs text-fg-muted';
|
|
108
148
|
const HINT_CLASS = 'text-xs text-fg-subtle';
|
|
109
149
|
|
|
110
|
-
/**
|
|
111
|
-
export
|
|
112
|
-
if (change === 0) return 'flat';
|
|
113
|
-
const up = change > 0;
|
|
114
|
-
return up === (upIs === 'good') ? 'good' : 'bad';
|
|
115
|
-
}
|
|
150
|
+
/** 环比徽标的语气:实现在基础层 base/trend-tone(KitDelta 共用),此处再导出保持旧引用不变 */
|
|
151
|
+
export { trendTone };
|
|
116
152
|
|
|
117
153
|
function resolveCompareValue(rec: Record<string, unknown>): string | number | undefined {
|
|
118
154
|
for (const k of ['compareValue', 'delta'] as const) {
|
|
@@ -141,9 +177,32 @@ function itemOf(key: string, label: string, rec: Record<string, unknown>): KitSt
|
|
|
141
177
|
hintKey: str(rec.hintKey),
|
|
142
178
|
spark: str(rec.spark),
|
|
143
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),
|
|
144
196
|
};
|
|
145
197
|
}
|
|
146
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
|
+
|
|
147
206
|
function recOf(raw: unknown): Record<string, unknown> {
|
|
148
207
|
return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw as Record<string, unknown> : {};
|
|
149
208
|
}
|
|
@@ -238,7 +297,7 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
238
297
|
layer: 'data',
|
|
239
298
|
props: {
|
|
240
299
|
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
|
|
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? }])' },
|
|
242
301
|
map: { type: 'object', default: {}, desc: '键名对照:items 里的 key -> 数据里的键' },
|
|
243
302
|
columns: { type: 'number', default: 0, desc: '列数:1 / 2 / 3 / 4 / 6(宽容器下的列数,窄容器 1 列);0 或其它 = 自动(每个容器宽度档按项数取不让末行落单一项的列数,档位与上限见真源 kit-limits 的 statGrid)。单个统计卡片 = 一项 items + columns: 1' },
|
|
244
303
|
locale: { type: 'string', default: '', desc: '格式化语言;空则 zh-CN' },
|
|
@@ -286,59 +345,141 @@ export function createStatGroup(): SomaComponentDefinition {
|
|
|
286
345
|
const items = statItemsOf(p.items, map, data);
|
|
287
346
|
const classes = statGridClasses(items.length, num(p.columns));
|
|
288
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)));
|
|
289
357
|
grid.textContent = '';
|
|
290
358
|
current = [];
|
|
291
359
|
for (const [index, item] of items.entries()) {
|
|
292
360
|
const source = typeof map[item.key] === 'string' && map[item.key] !== '' ? String(map[item.key]) : item.key;
|
|
293
361
|
const value = data[source];
|
|
294
362
|
current.push({ key: item.key, label: item.label, value });
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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;
|
|
301
372
|
block.setAttribute('data-kit-stat', item.key);
|
|
302
|
-
block.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_CARD);
|
|
303
373
|
if (item.highlight === true) block.setAttribute('data-kit-highlight', 'true');
|
|
304
|
-
const label = document.createElement('span');
|
|
374
|
+
const label = markKitSlot(document.createElement('span'), 'title');
|
|
305
375
|
label.className = LABEL_CLASS;
|
|
306
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
|
+
}
|
|
307
387
|
const val = document.createElement('span');
|
|
308
388
|
val.className = VALUE_CLASS;
|
|
309
389
|
val.setAttribute('data-kit-stat-value', '');
|
|
310
390
|
val.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE);
|
|
311
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
|
+
}
|
|
312
402
|
block.appendChild(label);
|
|
403
|
+
const metric = markKitSlot(document.createElement('span'), 'metric');
|
|
404
|
+
metric.className = METRIC_SLOT_CLASS;
|
|
405
|
+
block.appendChild(metric);
|
|
313
406
|
|
|
314
|
-
const unitText = resolveMappedString(item.unit, item.unitKey, map, data);
|
|
407
|
+
const unitText = gapKind !== null ? '' : resolveMappedString(item.unit, item.unitKey, map, data);
|
|
315
408
|
if (unitText !== '') {
|
|
316
409
|
const valRow = document.createElement('span');
|
|
317
410
|
valRow.className = VALUE_ROW_CLASS;
|
|
411
|
+
// 带单位时贴底对齐交给整行(VALUE_ROW_CLASS);数值自己不再带 mt-auto,否则在行内被单独下推,单位浮到右上角
|
|
412
|
+
val.className = STAT_VALUE_CLASS;
|
|
318
413
|
valRow.appendChild(val);
|
|
319
414
|
const unitEl = document.createElement('span');
|
|
320
415
|
unitEl.className = UNIT_CLASS;
|
|
321
416
|
unitEl.setAttribute('data-kit-stat-unit', '');
|
|
322
417
|
unitEl.textContent = unitText;
|
|
323
418
|
valRow.appendChild(unitEl);
|
|
324
|
-
|
|
419
|
+
metric.appendChild(valRow);
|
|
325
420
|
} else {
|
|
326
|
-
|
|
421
|
+
metric.appendChild(val);
|
|
327
422
|
}
|
|
328
423
|
|
|
329
424
|
if (item.spark !== '') {
|
|
330
425
|
const sparkSource = typeof map[item.spark] === 'string' && map[item.spark] !== '' ? String(map[item.spark]) : item.spark;
|
|
331
426
|
const values = trendValuesOf(data[sparkSource]);
|
|
332
427
|
const svg = sparklineSvg(values, { tone: trendToneOf('auto', values, item.upIs), label: item.label, className: 'h-8 w-full' });
|
|
333
|
-
if (svg)
|
|
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
|
+
}
|
|
334
477
|
}
|
|
335
478
|
|
|
336
479
|
// 变化率、对比期说明与提示:趋势数值取 trend / compareValue / delta,对比期取 compare / compareLabel / period
|
|
337
|
-
const changeBadge
|
|
338
|
-
const compareText = resolveMappedString(item.compare, item.compareKey, map, data);
|
|
339
|
-
const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
|
|
480
|
+
const { changeBadge, compareText, hintText } = foots[index]!;
|
|
340
481
|
if (changeBadge !== undefined || compareText !== '' || hintText !== '') {
|
|
341
|
-
const foot = document.createElement('span');
|
|
482
|
+
const foot = markKitSlot(document.createElement('span'), 'action');
|
|
342
483
|
foot.className = FOOT_CLASS;
|
|
343
484
|
if (changeBadge !== undefined) {
|
|
344
485
|
const { change, text: changeText } = changeBadge;
|
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
|
|
|
@@ -54,6 +54,7 @@ import { createQuestionnaire } from './survey';
|
|
|
54
54
|
import { createTourGuide } from './tour-guide';
|
|
55
55
|
import { createTrendLine } from './trend-line';
|
|
56
56
|
import { createRecordPicker } from './record-picker';
|
|
57
|
+
import { createNoticeList } from './notice-list';
|
|
57
58
|
import { kitFail } from '../compile/kit-error';
|
|
58
59
|
|
|
59
60
|
export type KitStaticAccept = 'single' | 'list';
|
|
@@ -117,6 +118,7 @@ export const KIT_STATIC_BUILTIN_SPECS: readonly KitStaticSpec[] = Object.freeze(
|
|
|
117
118
|
{ name: 'PricingTable', accept: 'single', desc: '定价表:{ cycles?, plans[], current_key? },推荐标记、功能对勾 / 叉 / 文字、按周期切换价格文案(不计算价格),抛 cycle_change { key } / select { key, cycle, item }', define: createPricingTable },
|
|
118
119
|
{ name: 'CodeView', accept: 'single', desc: '只读代码 / 文本块:{ title?, text, caption? },等宽保留换行,max_height 档滚动,copyable 出复制钮,抛 copy { ok }', define: createCodeView },
|
|
119
120
|
{ name: 'ItemList', accept: 'list', desc: '可选条目列表:[{ id, title, sub?, text?, tags?, disabled?, actions? }],selected 高亮,↑↓ Home End 移动焦点,loading / error(可重试)/ 空三态,抛 select { id, item } / action { key, id, item } / retry', define: createItemList },
|
|
121
|
+
{ name: 'NoticeList', accept: 'list', desc: '说明 / 披露条列表:[{ id?, code?, tone?, title?, text, time?, href?, action_label?, icon? }],语气竖线 + 图标 + 读屏语气文字双编码,fold_after 折叠其余(按钮 aria-expanded),空则整块不渲染(empty_text 可给紧凑空态),读状态与 state_kind(not_ready / upstream_broken / denied)走共用三态面板;顺序与去重由数据决定;抛 toggle { open } / action { id, href, item } / retry', define: createNoticeList },
|
|
120
122
|
{ name: 'SystemSwitcher', accept: 'single', desc: '系统 / 应用切换面板:{ items[{ id, title, sub?, favorite?, disabled? }], keyword?, server_search?, favorites_max? },已选常用 chip + 搜索(本地过滤或 server_search 抛 search)+ 系统列表,不乐观更新,抛 open { id, item } / favorite { id, on, item } / search { keyword }', define: createSystemSwitcher },
|
|
121
123
|
{ name: 'RowEditor', accept: 'single', desc: '行表编辑器:{ title?, hint?, rows[], error? } + columns 声明列(text / select / bool / json),行内删除、下方录入区、required / pattern 声明式校验,auto_apply 控制是否自己改行;抛 add { row, replaced } / remove { key, row, index } / change { value } / invalid { message }', define: createRowEditor },
|
|
122
124
|
{ name: 'AsyncResultPanel', accept: 'single', desc: '后台生成结果面板:{ title?, subtitle?, status: idle|busy|ready|failed, message?, result? },指令输入 + 运行 / 取消 + 待确认结果(采纳 / 忽略);抛 run { prompt } / cancel / adopt / dismiss / prompt_change { value }', define: createAsyncResultPanel },
|
package/src/data/steps.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
9
9
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
10
10
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
11
11
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
12
|
+
import { applyKitReadState, KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS } from '../base/state-panel';
|
|
12
13
|
import { classTokens, emptyNode, keyMap, mk, rowsOf, textOf, TONE_SOLID, type Rec } from './shape-util';
|
|
13
14
|
|
|
14
15
|
export const KIT_STEPS_DEFAULT_MAP = Object.freeze({ id: 'id', label: 'label', text: 'text', status: 'status', count: 'count', optional: 'optional' });
|
|
@@ -20,9 +21,9 @@ const ROOT_H = 'flex items-start overflow-x-auto text-sm text-fg';
|
|
|
20
21
|
const ROOT_V = 'flex flex-col text-sm text-fg';
|
|
21
22
|
const LI_H = 'flex flex-1';
|
|
22
23
|
const ITEM_H = 'flex min-w-20 flex-1 flex-col items-center gap-1 text-center';
|
|
23
|
-
const ITEM_H_BUTTON = 'flex min-w-20 flex-1 flex-col items-center gap-1 rounded-md py-1 text-center transition-colors hover:bg-
|
|
24
|
+
const ITEM_H_BUTTON = 'flex min-w-20 flex-1 flex-col items-center gap-1 rounded-md py-1 text-center transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
24
25
|
const ITEM_V = 'flex gap-3';
|
|
25
|
-
const ITEM_V_BUTTON = 'flex gap-3 rounded-md px-1 text-start transition-colors hover:bg-
|
|
26
|
+
const ITEM_V_BUTTON = 'flex gap-3 rounded-md px-1 text-start transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
26
27
|
const TOP_ROW = 'flex w-full items-center';
|
|
27
28
|
const LINE_H = 'h-0.5 flex-1 rounded-full bg-border-subtle';
|
|
28
29
|
const LINE_H_DONE = 'h-0.5 flex-1 rounded-full bg-success';
|
|
@@ -114,10 +115,12 @@ export function createSteps(): SomaComponentDefinition {
|
|
|
114
115
|
direction: { type: 'enum', values: ['horizontal', 'vertical'], default: 'horizontal', desc: '排列方向' },
|
|
115
116
|
clickable: { type: 'boolean', default: false, desc: '每步是按钮,点击抛 select' },
|
|
116
117
|
empty_text: { type: 'string', default: '', desc: '无数据时的文案' },
|
|
118
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
117
119
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
118
120
|
},
|
|
119
121
|
emits: {
|
|
120
122
|
select: { payload: { item: { type: 'object' } }, desc: '点某一步(clickable 时);item 是源数据里的原对象' },
|
|
123
|
+
...KIT_READ_STATE_EMIT_DEFS,
|
|
121
124
|
},
|
|
122
125
|
},
|
|
123
126
|
templateHtml: `<ol data-soma-id="root" role="list" class="${ROOT_H}"></ol>`,
|
|
@@ -133,12 +136,14 @@ export function createSteps(): SomaComponentDefinition {
|
|
|
133
136
|
root.addEventListener('click', onClick);
|
|
134
137
|
return () => root.removeEventListener('click', onClick);
|
|
135
138
|
},
|
|
136
|
-
render(root, p) {
|
|
139
|
+
render(root, p, api) {
|
|
137
140
|
const vertical = p.direction === 'vertical';
|
|
138
141
|
const clickable = bool(p.clickable);
|
|
139
142
|
root.className = joinClass(vertical ? ROOT_V : ROOT_H, p.class);
|
|
140
143
|
root.textContent = '';
|
|
141
144
|
const steps = stepEntriesOf(p.data, p.map, root);
|
|
145
|
+
// 读状态(加载中 / 读取失败 + 重试):与集合三态同一画法(base/state-panel.ts)
|
|
146
|
+
if (applyKitReadState(root, p, { hasContent: steps.length > 0, onRetry: () => api.emit('retry', {}), repaint: () => api.refresh() })) return;
|
|
142
147
|
if (steps.length === 0) {
|
|
143
148
|
root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.st_empty', undefined, root))));
|
|
144
149
|
return;
|
package/src/data/survey.ts
CHANGED
|
@@ -32,12 +32,12 @@ const PROGRESS_CLASS = 'block flex-1';
|
|
|
32
32
|
const QUESTION_CLASS = 'flex min-w-0 flex-col gap-2 border-0 p-0';
|
|
33
33
|
const LEGEND_CLASS = 'mb-1 font-medium text-fg';
|
|
34
34
|
const REQUIRED_CLASS = 'ms-1 text-danger-on-soft';
|
|
35
|
-
const OPTION_CLASS = 'w-full px-2 py-1.5 hover:bg-
|
|
36
|
-
const AREA_CLASS = 'w-full appearance-none autofill-clear resize-none rounded-md border border-border bg-surface px-3 py-2 text-sm text-fg transition-colors
|
|
35
|
+
const OPTION_CLASS = 'w-full px-2 py-1.5 hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
36
|
+
const AREA_CLASS = 'w-full appearance-none autofill-clear resize-none rounded-md border border-border bg-surface px-3 py-2 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
37
37
|
const RATING_ROW = 'flex flex-wrap gap-1';
|
|
38
38
|
const RATING_BOX = 'relative';
|
|
39
39
|
const RATING_INPUT = 'peer sr-only';
|
|
40
|
-
const RATING_LABEL = 'inline-flex h-8 min-w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-2 text-sm text-fg transition-colors
|
|
40
|
+
const RATING_LABEL = 'inline-flex h-8 min-w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-2 text-sm text-fg transition-colors state-layer peer-checked:border-primary peer-checked:bg-primary-soft peer-checked:text-primary-on-soft peer-focus-visible:ring-2 peer-focus-visible:ring-ring';
|
|
41
41
|
const ERROR_CLASS = 'text-xs text-danger-on-soft';
|
|
42
42
|
const FOOT_CLASS = 'flex items-center justify-end gap-2';
|
|
43
43
|
const RESULT_ROW = 'flex flex-col gap-1 rounded-md px-2 py-1.5';
|
|
@@ -35,7 +35,7 @@ const FAV_HEAD_CLASS = 'flex items-center justify-between gap-2 text-xs text-fg-
|
|
|
35
35
|
const CHIPS_CLASS = 'flex flex-wrap gap-2';
|
|
36
36
|
const CHIP_CLASS = 'inline-flex items-center gap-1 rounded-full border border-border-subtle bg-surface ps-3 pe-1 text-sm text-fg';
|
|
37
37
|
const CHIP_OPEN_CLASS = 'cursor-pointer rounded-sm text-sm text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
38
|
-
const CHIP_REMOVE_CLASS = 'inline-flex size-6 cursor-pointer items-center justify-center rounded-full text-fg-muted transition-colors hover:bg-
|
|
38
|
+
const CHIP_REMOVE_CLASS = 'inline-flex size-6 p-0 cursor-pointer items-center justify-center rounded-full text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
39
39
|
const SEARCH_ROW_CLASS = 'flex items-center gap-2';
|
|
40
40
|
const SEARCH_FIELD_CLASS = 'min-w-0 flex-1';
|
|
41
41
|
const LIST_CLASS = 'grid grid-cols-1 gap-2 @2xl:grid-cols-2';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// 行内 / 面板内的文字链接式动作钮:全 kit 唯一配方 kitTextActionRecipe(主色或危险语义色文字,无底无描边)。
|
|
2
|
+
// 带 data-kit-action,供各组件的点击委托识别(与 actionButton 同一约定)。
|
|
3
|
+
|
|
4
|
+
import { kitTextActionRecipe, type KitTextActionTone } from '../recipes/control';
|
|
5
|
+
import { classTokens } from './shape-util';
|
|
6
|
+
|
|
7
|
+
export function textActionButton(key: string, label: string, tone: KitTextActionTone = 'primary'): HTMLButtonElement {
|
|
8
|
+
const btn = document.createElement('button');
|
|
9
|
+
btn.type = 'button';
|
|
10
|
+
btn.className = kitTextActionRecipe(tone);
|
|
11
|
+
btn.textContent = label;
|
|
12
|
+
btn.setAttribute('data-kit-action', key);
|
|
13
|
+
return btn;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 候选类(用到 textActionButton 的组件并入) */
|
|
17
|
+
export const TEXT_ACTION_CLASS_TOKENS: readonly string[] = classTokens(kitTextActionRecipe('primary'), kitTextActionRecipe('danger'));
|