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/base/tag.ts
CHANGED
|
@@ -3,36 +3,42 @@
|
|
|
3
3
|
|
|
4
4
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
5
5
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
6
|
-
import { kitIcon } from './icons';
|
|
6
|
+
import { KIT_ICON_NAMES, kitIcon, type KitIconName } from './icons';
|
|
7
7
|
import { setKitFace } from '../recipes';
|
|
8
|
+
import {
|
|
9
|
+
KIT_TAG_UNKNOWN_DOT, KIT_TAG_UNKNOWN_DOT_CORE, KIT_TAG_UNKNOWN_OUTLINE, KIT_TAG_UNKNOWN_SOFT, KIT_TAG_UNKNOWN_CLASS_CANDIDATES,
|
|
10
|
+
} from '../recipes/status';
|
|
8
11
|
import {
|
|
9
12
|
CLASS_PROP, SIZE_PROP, OPTIONS_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES,
|
|
10
13
|
bool, classCandidates, createKitController, displayOf, joinClass, optionsOf, paintBadge, sizeOf, str, toneOf, withBadgeAnchor, withTooltip,
|
|
11
|
-
type KitSize, type KitTone,
|
|
14
|
+
valueIsEmpty, type KitSize, type KitTone,
|
|
12
15
|
} from './shared';
|
|
13
16
|
|
|
17
|
+
/** 空值占位(静默灰字,无底无边无内边距) */
|
|
18
|
+
const EMPTY_PLACEHOLDER_CLASS = 'text-fg-subtle';
|
|
19
|
+
|
|
14
20
|
// 档位 × 语气,每格一整串字面量
|
|
15
21
|
export const TAG_CLASS: Record<KitSize, Record<KitTone, string>> = {
|
|
16
22
|
sm: {
|
|
17
|
-
neutral: 'inline-flex items-center rounded-
|
|
18
|
-
info: 'inline-flex items-center rounded-
|
|
19
|
-
success: 'inline-flex items-center rounded-
|
|
20
|
-
warning: 'inline-flex items-center rounded-
|
|
21
|
-
danger: 'inline-flex items-center rounded-
|
|
23
|
+
neutral: 'inline-flex items-center rounded-full bg-surface-sunken px-1.5 py-0.5 text-xs font-medium text-fg-muted',
|
|
24
|
+
info: 'inline-flex items-center rounded-full bg-info-soft px-1.5 py-0.5 text-xs font-medium text-info-on-soft',
|
|
25
|
+
success: 'inline-flex items-center rounded-full bg-success-soft px-1.5 py-0.5 text-xs font-medium text-success-on-soft',
|
|
26
|
+
warning: 'inline-flex items-center rounded-full bg-warning-soft px-1.5 py-0.5 text-xs font-medium text-warning-on-soft',
|
|
27
|
+
danger: 'inline-flex items-center rounded-full bg-danger-soft px-1.5 py-0.5 text-xs font-medium text-danger-on-soft',
|
|
22
28
|
},
|
|
23
29
|
md: {
|
|
24
|
-
neutral: 'inline-flex items-center rounded-
|
|
25
|
-
info: 'inline-flex items-center rounded-
|
|
26
|
-
success: 'inline-flex items-center rounded-
|
|
27
|
-
warning: 'inline-flex items-center rounded-
|
|
28
|
-
danger: 'inline-flex items-center rounded-
|
|
30
|
+
neutral: 'inline-flex items-center rounded-full bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted',
|
|
31
|
+
info: 'inline-flex items-center rounded-full bg-info-soft px-2 py-0.5 text-sm font-medium text-info-on-soft',
|
|
32
|
+
success: 'inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-sm font-medium text-success-on-soft',
|
|
33
|
+
warning: 'inline-flex items-center rounded-full bg-warning-soft px-2 py-0.5 text-sm font-medium text-warning-on-soft',
|
|
34
|
+
danger: 'inline-flex items-center rounded-full bg-danger-soft px-2 py-0.5 text-sm font-medium text-danger-on-soft',
|
|
29
35
|
},
|
|
30
36
|
lg: {
|
|
31
|
-
neutral: 'inline-flex items-center rounded-
|
|
32
|
-
info: 'inline-flex items-center rounded-
|
|
33
|
-
success: 'inline-flex items-center rounded-
|
|
34
|
-
warning: 'inline-flex items-center rounded-
|
|
35
|
-
danger: 'inline-flex items-center rounded-
|
|
37
|
+
neutral: 'inline-flex items-center rounded-full bg-surface-sunken px-2.5 py-1 text-base font-medium text-fg-muted',
|
|
38
|
+
info: 'inline-flex items-center rounded-full bg-info-soft px-2.5 py-1 text-base font-medium text-info-on-soft',
|
|
39
|
+
success: 'inline-flex items-center rounded-full bg-success-soft px-2.5 py-1 text-base font-medium text-success-on-soft',
|
|
40
|
+
warning: 'inline-flex items-center rounded-full bg-warning-soft px-2.5 py-1 text-base font-medium text-warning-on-soft',
|
|
41
|
+
danger: 'inline-flex items-center rounded-full bg-danger-soft px-2.5 py-1 text-base font-medium text-danger-on-soft',
|
|
36
42
|
},
|
|
37
43
|
};
|
|
38
44
|
|
|
@@ -73,9 +79,9 @@ const DOT_RING: Record<KitTone, string> = {
|
|
|
73
79
|
|
|
74
80
|
// variant: outline / solid:尺寸壳与色彩分开给(互不含对方的属性,不会同类冲突)
|
|
75
81
|
const SHAPE_CLASS: Record<KitSize, string> = {
|
|
76
|
-
sm: 'inline-flex items-center gap-1 rounded-
|
|
77
|
-
md: 'inline-flex items-center gap-1.5 rounded-
|
|
78
|
-
lg: 'inline-flex items-center gap-1.5 rounded-
|
|
82
|
+
sm: 'inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-xs font-medium',
|
|
83
|
+
md: 'inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-sm font-medium',
|
|
84
|
+
lg: 'inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-base font-medium',
|
|
79
85
|
};
|
|
80
86
|
const OUTLINE_CLASS: Record<KitTone, string> = {
|
|
81
87
|
neutral: 'border border-border bg-transparent text-fg-muted',
|
|
@@ -93,7 +99,7 @@ const SOLID_CLASS: Record<KitTone, string> = {
|
|
|
93
99
|
};
|
|
94
100
|
// 可点击:整枚标签是一个按钮(内层 span),悬停淡出、焦点环
|
|
95
101
|
const CLICK_CLASS = 'inline-flex cursor-pointer items-center gap-1.5 rounded-sm transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
96
|
-
const REMOVE_CLASS = 'inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm text-current opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
102
|
+
const REMOVE_CLASS = 'hit-area inline-flex h-4 w-4 shrink-0 p-0 items-center justify-center rounded-sm text-current opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
97
103
|
const ICON_CLASS = 'inline-block shrink-0';
|
|
98
104
|
const SOFT_GAP_CLASS = 'gap-1.5';
|
|
99
105
|
|
|
@@ -103,14 +109,19 @@ export const KIT_TAG_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
103
109
|
...Object.values(DOT_CLASS).join(' ').split(' '),
|
|
104
110
|
...[Object.values(DOT_ROOT), Object.values(DOT_WRAP), Object.values(DOT_CORE), Object.values(DOT_RING)].flat().join(' ').split(' '),
|
|
105
111
|
...classCandidates(
|
|
106
|
-
Object.values(SHAPE_CLASS), Object.values(OUTLINE_CLASS), Object.values(SOLID_CLASS), CLICK_CLASS, REMOVE_CLASS, ICON_CLASS, SOFT_GAP_CLASS,
|
|
107
|
-
KIT_BADGE_CLASS_CANDIDATES,
|
|
112
|
+
Object.values(SHAPE_CLASS), Object.values(OUTLINE_CLASS), Object.values(SOLID_CLASS), CLICK_CLASS, REMOVE_CLASS, ICON_CLASS, SOFT_GAP_CLASS, EMPTY_PLACEHOLDER_CLASS,
|
|
113
|
+
KIT_BADGE_CLASS_CANDIDATES, KIT_TAG_UNKNOWN_CLASS_CANDIDATES,
|
|
108
114
|
),
|
|
109
115
|
]),
|
|
110
116
|
]);
|
|
111
117
|
|
|
112
118
|
type TagVariant = 'soft' | 'outline' | 'solid' | 'dot';
|
|
113
119
|
|
|
120
|
+
/** 选项 icon 只认 kit 图标名(SVG);符号字符 / 未知名一律忽略,状态要双编码就写图标名 + 文字 */
|
|
121
|
+
function optionIconOf(raw: unknown): KitIconName | null {
|
|
122
|
+
return typeof raw === 'string' && (KIT_ICON_NAMES as readonly string[]).includes(raw) ? raw as KitIconName : null;
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
function variantOf(raw: unknown): TagVariant {
|
|
115
126
|
return raw === 'outline' || raw === 'solid' || raw === 'dot' ? raw : 'soft';
|
|
116
127
|
}
|
|
@@ -125,7 +136,7 @@ export function createTag(): SomaComponentDefinition {
|
|
|
125
136
|
options: OPTIONS_PROP,
|
|
126
137
|
format: { type: 'string', default: '', desc: '同 Text.format' },
|
|
127
138
|
locale: { type: 'string', default: '', desc: '格式化语言;缺省取页面语言(page.locale),都没声明为 zh-CN' },
|
|
128
|
-
tone: { type: 'enum', values: ['neutral', 'info', 'success', 'warning', 'danger'], default: 'neutral', desc: '
|
|
139
|
+
tone: { type: 'enum', values: ['neutral', 'info', 'success', 'warning', 'danger', 'unknown'], default: 'neutral', desc: '语气;unknown = 未知 / 无法判断(虚线描边、透明底、中性字色,与 neutral 区分)。选项 options[].tone 同样可写 unknown;options[].icon 写 kit 图标名(如 info / check / warning)则文字前画该图标,与文字双编码(装饰,读屏忽略)' },
|
|
129
140
|
placeholder: { type: 'string', default: '', desc: '空值时显示的文字' },
|
|
130
141
|
dot: { type: 'boolean', default: false, desc: '文字前加一个按语气着色的状态点(在线 / 离线这类状态列);值到语气的对照用 options[].tone 显式给' },
|
|
131
142
|
variant: { type: 'enum', values: ['soft', 'outline', 'solid', 'dot'], default: 'soft', desc: 'soft = 带浅底;outline = 描边;solid = 实心;dot = 只有状态点 + 文字(StatusDot 用法,点按 tone 着色)' },
|
|
@@ -144,7 +155,7 @@ export function createTag(): SomaComponentDefinition {
|
|
|
144
155
|
click: { payload: { value: { type: 'string' } }, desc: 'clickable 时点击或 Enter / Space' },
|
|
145
156
|
},
|
|
146
157
|
},
|
|
147
|
-
templateHtml: '<span data-soma-id="root" class="inline-flex items-center rounded-
|
|
158
|
+
templateHtml: '<span data-soma-id="root" class="inline-flex items-center rounded-full bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted"></span>',
|
|
148
159
|
controllerFactory: createKitController(() => withTooltip({
|
|
149
160
|
attach(root, api) {
|
|
150
161
|
const valueOf = (): unknown => api.props().value;
|
|
@@ -179,21 +190,34 @@ export function createTag(): SomaComponentDefinition {
|
|
|
179
190
|
};
|
|
180
191
|
},
|
|
181
192
|
render(root, p) {
|
|
182
|
-
const
|
|
193
|
+
const shown = displayOf(p.value, optionsOf(p.options), str(p.format), str(p.locale, kitLocaleAt(root) || 'zh-CN'), str(p.placeholder));
|
|
194
|
+
const option = shown.option;
|
|
195
|
+
// 选项只写 icon 没写 label(optionsOf 视作纯图标选项):Tag 的图标是装饰,状态靠文字,回退显示值文字,不留一枚没有可读文字的标签
|
|
196
|
+
const text = shown.text === '' && option !== null && option.icon !== undefined ? str(option.value) : shown.text;
|
|
183
197
|
const tone = option?.tone ?? toneOf(p.tone, 'neutral');
|
|
198
|
+
// unknown 语气:命中选项带 unknown,或没有命中语气的选项且 tone prop 为 unknown
|
|
199
|
+
const unknownTone = option?.unknown === true || (option?.tone === undefined && p.tone === 'unknown');
|
|
184
200
|
root.textContent = '';
|
|
201
|
+
// 空值(null / undefined / '' / [])不画标签:只是一个标准的静默占位(placeholder,空则什么也不画),
|
|
202
|
+
// 摘要 / 详情 / 表格单元格由此一致,不会出现一枚写着「-」的空标签
|
|
203
|
+
if (valueIsEmpty(p.value)) {
|
|
204
|
+
setKitFace(root, null);
|
|
205
|
+
root.className = joinClass(EMPTY_PLACEHOLDER_CLASS, p.class);
|
|
206
|
+
root.textContent = shown.text;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
185
209
|
if (p.variant === 'dot') {
|
|
186
210
|
const size = sizeOf(p.size);
|
|
187
211
|
const wrap = document.createElement('span');
|
|
188
212
|
wrap.setAttribute('aria-hidden', 'true');
|
|
189
213
|
wrap.className = DOT_WRAP[size];
|
|
190
|
-
if (bool(p.pulse)) {
|
|
214
|
+
if (bool(p.pulse) && !unknownTone) {
|
|
191
215
|
const ring = document.createElement('span');
|
|
192
216
|
ring.className = DOT_RING[tone];
|
|
193
217
|
wrap.appendChild(ring);
|
|
194
218
|
}
|
|
195
219
|
const core = document.createElement('span');
|
|
196
|
-
core.className = DOT_CORE[tone];
|
|
220
|
+
core.className = unknownTone ? KIT_TAG_UNKNOWN_DOT_CORE : DOT_CORE[tone];
|
|
197
221
|
wrap.appendChild(core);
|
|
198
222
|
root.appendChild(wrap);
|
|
199
223
|
if (text !== '') root.appendChild(document.createTextNode(text));
|
|
@@ -219,10 +243,14 @@ export function createTag(): SomaComponentDefinition {
|
|
|
219
243
|
if (bool(p.dot) && variant !== 'solid') {
|
|
220
244
|
const dot = document.createElement('span');
|
|
221
245
|
dot.setAttribute('aria-hidden', 'true');
|
|
222
|
-
dot.className = DOT_CLASS[tone];
|
|
246
|
+
dot.className = unknownTone ? KIT_TAG_UNKNOWN_DOT : DOT_CLASS[tone];
|
|
223
247
|
body.appendChild(dot);
|
|
224
248
|
}
|
|
225
|
-
|
|
249
|
+
// 选项图标(kit 图标名,SVG):与文字双编码;有它时优先于 icon prop 的符号字符
|
|
250
|
+
const optIcon = optionIconOf(option?.icon);
|
|
251
|
+
if (optIcon !== null) {
|
|
252
|
+
body.appendChild(kitIcon(optIcon, size === 'lg' ? 'sm' : 'xs'));
|
|
253
|
+
} else if (icon !== '') {
|
|
226
254
|
const ic = document.createElement('span');
|
|
227
255
|
ic.setAttribute('aria-hidden', 'true');
|
|
228
256
|
ic.className = ICON_CLASS;
|
|
@@ -242,11 +270,13 @@ export function createTag(): SomaComponentDefinition {
|
|
|
242
270
|
// 质感标记:soft(浅底)/ solid(实心)有「面」标 raised;outline 透明底、dot 无面,不标
|
|
243
271
|
setKitFace(root, variant === 'outline' ? null : 'raised');
|
|
244
272
|
const hasBadge = paintBadge(root, p);
|
|
273
|
+
const hasIcon = icon !== '' || optIcon !== null;
|
|
274
|
+
const softLook = unknownTone ? KIT_TAG_UNKNOWN_SOFT[size] : TAG_CLASS[size][tone];
|
|
245
275
|
const look = variant === 'outline'
|
|
246
|
-
? `${SHAPE_CLASS[size]} ${OUTLINE_CLASS[tone]}`
|
|
276
|
+
? `${SHAPE_CLASS[size]} ${unknownTone ? KIT_TAG_UNKNOWN_OUTLINE : OUTLINE_CLASS[tone]}`
|
|
247
277
|
: variant === 'solid'
|
|
248
|
-
? `${SHAPE_CLASS[size]} ${SOLID_CLASS[tone]}`
|
|
249
|
-
: (
|
|
278
|
+
? `${SHAPE_CLASS[size]} ${unknownTone ? KIT_TAG_UNKNOWN_OUTLINE : SOLID_CLASS[tone]}`
|
|
279
|
+
: (hasIcon || removable || clickable) ? `${softLook} ${SOFT_GAP_CLASS}` : softLook;
|
|
250
280
|
root.className = joinClass(withBadgeAnchor(look, hasBadge), p.class);
|
|
251
281
|
},
|
|
252
282
|
})),
|
package/src/base/text.ts
CHANGED
|
@@ -7,26 +7,48 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
7
7
|
import { TAG_CLASS } from './tag';
|
|
8
8
|
import { formatDateRangeValue, formatMoneyValue, formatPercentValue } from '../object-renderer/field-value';
|
|
9
9
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
10
|
+
import { KIT_TIPS_SCOPE_ATTR } from './hint-tips';
|
|
10
11
|
import {
|
|
11
12
|
CLASS_PROP, SIZE_PROP, OPTIONS_PROP,
|
|
12
|
-
bool, classCandidates, createKitController, displayOf, joinClass, optionsOf, sizeOf, str, type KitSize,
|
|
13
|
+
bool, classCandidates, createKitController, displayOf, joinClass, optionsOf, sizeOf, str, type KitSize, type KitTone,
|
|
13
14
|
} from './shared';
|
|
14
15
|
|
|
15
16
|
// 每档一整串字面量,不拼接
|
|
17
|
+
const TEXT_SIZE_CLASS: Record<KitSize, string> = {
|
|
18
|
+
sm: 'text-sm',
|
|
19
|
+
md: 'text-base',
|
|
20
|
+
lg: 'text-lg',
|
|
21
|
+
};
|
|
16
22
|
const TEXT_CLASS: Record<KitSize, string> = {
|
|
17
|
-
sm:
|
|
18
|
-
md:
|
|
19
|
-
lg:
|
|
23
|
+
sm: `${TEXT_SIZE_CLASS.sm} text-fg`,
|
|
24
|
+
md: `${TEXT_SIZE_CLASS.md} text-fg`,
|
|
25
|
+
lg: `${TEXT_SIZE_CLASS.lg} text-fg`,
|
|
26
|
+
};
|
|
27
|
+
// 语气纯文字着色(tone_as: text):只换字色,无底无描边;neutral 用次要字色,其余取 -on-soft 配对字色
|
|
28
|
+
export const TONE_AS_TEXT = 'text' as const;
|
|
29
|
+
const TONE_TEXT_COLOR: Record<KitTone, string> = {
|
|
30
|
+
neutral: 'text-fg-muted',
|
|
31
|
+
info: 'text-info-on-soft',
|
|
32
|
+
success: 'text-success-on-soft',
|
|
33
|
+
warning: 'text-warning-on-soft',
|
|
34
|
+
danger: 'text-danger-on-soft',
|
|
35
|
+
};
|
|
36
|
+
// 字阶取 TEXT_SIZE_CLASS 里已有的那一档(不另写一份字阶类,G101 typography 不增)
|
|
37
|
+
const toneTextClass = (size: KitSize, tone: KitTone): string => `${TEXT_SIZE_CLASS[size]} ${TONE_TEXT_COLOR[tone]}`;
|
|
38
|
+
const TONE_TEXT_CLASS: Record<KitSize, Record<KitTone, string>> = {
|
|
39
|
+
sm: { neutral: toneTextClass('sm', 'neutral'), info: toneTextClass('sm', 'info'), success: toneTextClass('sm', 'success'), warning: toneTextClass('sm', 'warning'), danger: toneTextClass('sm', 'danger') },
|
|
40
|
+
md: { neutral: toneTextClass('md', 'neutral'), info: toneTextClass('md', 'info'), success: toneTextClass('md', 'success'), warning: toneTextClass('md', 'warning'), danger: toneTextClass('md', 'danger') },
|
|
41
|
+
lg: { neutral: toneTextClass('lg', 'neutral'), info: toneTextClass('lg', 'info'), success: toneTextClass('lg', 'success'), warning: toneTextClass('lg', 'warning'), danger: toneTextClass('lg', 'danger') },
|
|
20
42
|
};
|
|
21
|
-
// copyable 时根元素变成一行:文字 +
|
|
43
|
+
// copyable 时根元素变成一行:文字 + 复制钮(whitespace-nowrap:值与复制钮是同一个不折行的行内组,宽松密度 / 窄格里也不会把钮挤到下一行)
|
|
22
44
|
const COPY_ROOT_CLASS: Record<KitSize, string> = {
|
|
23
|
-
sm: 'inline-flex items-center gap-2 text-sm text-fg',
|
|
24
|
-
md: 'inline-flex items-center gap-2 text-base text-fg',
|
|
25
|
-
lg: 'inline-flex items-center gap-2 text-lg text-fg',
|
|
45
|
+
sm: 'inline-flex items-center gap-2 whitespace-nowrap text-sm text-fg',
|
|
46
|
+
md: 'inline-flex items-center gap-2 whitespace-nowrap text-base text-fg',
|
|
47
|
+
lg: 'inline-flex items-center gap-2 whitespace-nowrap text-lg text-fg',
|
|
26
48
|
};
|
|
27
|
-
const COPY_BTN_CLASS = 'inline-flex shrink-0 cursor-pointer items-center rounded-sm px-1.5 py-0.5 text-xs font-medium text-primary-on-soft transition-colors hover:bg-
|
|
49
|
+
const COPY_BTN_CLASS = 'inline-flex shrink-0 cursor-pointer items-center rounded-sm px-1.5 py-0.5 text-xs font-medium text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
28
50
|
|
|
29
|
-
export const KIT_TEXT_CLASS_CANDIDATES: readonly string[] = classCandidates(Object.values(COPY_ROOT_CLASS), COPY_BTN_CLASS, ...Object.values(TAG_CLASS).flatMap((m) => Object.values(m)));
|
|
51
|
+
export const KIT_TEXT_CLASS_CANDIDATES: readonly string[] = classCandidates(Object.values(COPY_ROOT_CLASS), COPY_BTN_CLASS, ...Object.values(TONE_TEXT_CLASS).flatMap((m) => Object.values(m)), ...Object.values(TAG_CLASS).flatMap((m) => Object.values(m)));
|
|
30
52
|
|
|
31
53
|
const COPIED_MS = 1500;
|
|
32
54
|
|
|
@@ -48,6 +70,8 @@ function resolveTextDisplay(p: Record<string, unknown>, root: HTMLElement): { te
|
|
|
48
70
|
const opts = optionsOf(p.options);
|
|
49
71
|
const raw = p.value;
|
|
50
72
|
const placeholder = str(p.placeholder);
|
|
73
|
+
// 显式空串 '' = 有意留白,渲染为空白;null / undefined / 空数组按占位
|
|
74
|
+
if (raw === '') return { text: '', option: null };
|
|
51
75
|
if (raw === null || raw === undefined || raw === '' || (Array.isArray(raw) && raw.length === 0)) {
|
|
52
76
|
return { text: placeholder, option: null };
|
|
53
77
|
}
|
|
@@ -90,6 +114,7 @@ export function createText(): SomaComponentDefinition {
|
|
|
90
114
|
copyable: { type: 'boolean', default: false, desc: '文字后带「复制」钮,复制显示出来的文字' },
|
|
91
115
|
copy_label: { type: 'string', default: '', desc: '复制钮文字;缺省取内置文案(按页面语言)' },
|
|
92
116
|
copied_label: { type: 'string', default: '', desc: '复制成功后短暂显示的文字;缺省取内置文案(按页面语言)' },
|
|
117
|
+
tone_as: { type: 'string', default: 'tag', desc: '选项带 tone 时的呈现:tag = 徽标(缺省)/ text = 纯文字着色(无底无描边)' },
|
|
93
118
|
size: SIZE_PROP,
|
|
94
119
|
class: CLASS_PROP,
|
|
95
120
|
},
|
|
@@ -143,8 +168,11 @@ export function createText(): SomaComponentDefinition {
|
|
|
143
168
|
const raw = p.value;
|
|
144
169
|
const empty = raw === null || raw === undefined || raw === '' || (Array.isArray(raw) && raw.length === 0);
|
|
145
170
|
root.textContent = text;
|
|
146
|
-
|
|
147
|
-
|
|
171
|
+
// 不再给每个值写原生 title(无论是否被截断都冒气泡,且不可键盘 / 读屏):被截断的文字由 hint-tips 的委托在悬停 / 聚焦时现量、才挂 kitTooltip
|
|
172
|
+
root.removeAttribute('title');
|
|
173
|
+
// 自带 truncate 类的值自己标出提示作用范围(独立使用、不在表格 / 摘要格里时也有截断全文提示)
|
|
174
|
+
if (/(?:^|\s)(?:[a-z0-9*@-]+:)*truncate(?=\s|$)/.test(str(p.class))) root.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
175
|
+
else root.removeAttribute(KIT_TIPS_SCOPE_ATTR);
|
|
148
176
|
if (bool(p.copyable) && !empty) {
|
|
149
177
|
const s = stateOf(root);
|
|
150
178
|
const btn = document.createElement('button');
|
|
@@ -157,7 +185,8 @@ export function createText(): SomaComponentDefinition {
|
|
|
157
185
|
return;
|
|
158
186
|
}
|
|
159
187
|
if (!empty && !bool(p.copyable) && tone !== undefined) {
|
|
160
|
-
|
|
188
|
+
// tone_as: text = 纯文字着色(text-<tone>-on-soft,无底无描边);缺省 tag = 徽标
|
|
189
|
+
root.className = joinClass(str(p.tone_as) === TONE_AS_TEXT ? TONE_TEXT_CLASS[size][tone] : TAG_CLASS[size][tone], p.class);
|
|
161
190
|
return;
|
|
162
191
|
}
|
|
163
192
|
root.className = joinClass(TEXT_CLASS[size], p.class);
|
package/src/base/time-picker.ts
CHANGED
|
@@ -13,6 +13,8 @@ import type { CollectionItem } from 'soma-core/keyboard';
|
|
|
13
13
|
import { kitKey, kitText, type KitTextKey } from '../i18n/kit-text';
|
|
14
14
|
import { kitIcon } from './icons';
|
|
15
15
|
import { setKitFace } from '../recipes';
|
|
16
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
16
18
|
import {
|
|
17
19
|
CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
18
20
|
applyCommon, applyDisabled, bool, createKitController, joinClass, nextUid, num, setAttr, sizeOf, str, withInvalid,
|
|
@@ -27,24 +29,24 @@ import {
|
|
|
27
29
|
|
|
28
30
|
const ROOT_CLASS = 'relative block w-full';
|
|
29
31
|
const TRIGGER_CLASS: Record<KitSize, string> = {
|
|
30
|
-
sm: 'flex h-
|
|
31
|
-
md: 'flex h-
|
|
32
|
+
sm: 'flex h-6 w-full cursor-pointer items-center justify-between gap-2 rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors enabled:hover:border-input-hover 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',
|
|
33
|
+
md: 'flex h-8 w-full cursor-pointer items-center justify-between gap-2 rounded-md border border-input bg-surface px-3 text-sm text-fg transition-colors enabled:hover:border-input-hover 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',
|
|
32
34
|
lg: 'flex h-10 w-full cursor-pointer items-center justify-between gap-2 rounded-md border border-input bg-surface px-4 text-base text-fg transition-colors enabled:hover:border-input-hover 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',
|
|
33
35
|
};
|
|
34
36
|
const PLACEHOLDER_CLASS = 'text-fg-subtle';
|
|
35
37
|
const VALUE_CLASS = 'text-fg';
|
|
36
38
|
const CLEAR_CLASS = 'absolute end-8 top-0 border-0 bg-transparent flex h-full cursor-pointer items-center px-1 text-fg-subtle hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
37
39
|
const HIDDEN_CLASS = 'hidden';
|
|
38
|
-
const PANEL_BASE = 'absolute z-10 flex w-full flex-col gap-1
|
|
40
|
+
const PANEL_BASE = mergeClass('absolute z-10 flex w-full flex-col gap-1 p-1', kitSurfaceRecipe('raised'));
|
|
39
41
|
const COLUMNS_CLASS = 'flex gap-1';
|
|
40
42
|
const COLUMN_CLASS = 'flex max-h-68 flex-1 flex-col overflow-auto';
|
|
41
43
|
const CELL_CLASS = {
|
|
42
|
-
idle: 'flex h-9 shrink-0 cursor-pointer items-center justify-center rounded-md px-2 text-sm text-fg transition-colors hover:bg-
|
|
44
|
+
idle: 'flex h-9 shrink-0 cursor-pointer items-center justify-center rounded-md px-2 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring data-kit-quiet:focus-visible:ring-0',
|
|
43
45
|
selected: 'flex h-9 shrink-0 cursor-pointer items-center justify-center rounded-md bg-primary px-2 text-sm font-medium text-primary-fg focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring data-kit-quiet:focus-visible:ring-0',
|
|
44
46
|
disabled: 'flex h-9 shrink-0 cursor-not-allowed items-center justify-center rounded-md px-2 text-sm text-fg-subtle',
|
|
45
47
|
} as const;
|
|
46
48
|
// 文字钮用底色表示键盘焦点,不用环
|
|
47
|
-
const NOW_CLASS = 'border-0 bg-transparent cursor-pointer self-end rounded-md px-2 py-1 text-sm text-primary-on-soft hover:bg-
|
|
49
|
+
const NOW_CLASS = 'border-0 bg-transparent cursor-pointer self-end rounded-md px-2 py-1 text-sm text-primary-on-soft hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:bg-state-layer-hover focus-visible:outline-none';
|
|
48
50
|
|
|
49
51
|
/** 本组件自带的类(并入基础组件候选类清单) */
|
|
50
52
|
export const KIT_TIME_PICKER_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
package/src/base/tree-select.ts
CHANGED
|
@@ -13,6 +13,8 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
14
|
import { kitIcon } from './icons';
|
|
15
15
|
import { setKitFace } from '../recipes';
|
|
16
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
16
18
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
17
19
|
import { createCheck, markInput } from './check-core';
|
|
18
20
|
import {
|
|
@@ -29,8 +31,8 @@ import {
|
|
|
29
31
|
|
|
30
32
|
const ROOT_CLASS = 'relative block w-full';
|
|
31
33
|
const TRIGGER_CLASS: Record<KitSize, string> = {
|
|
32
|
-
sm: 'flex min-h-
|
|
33
|
-
md: 'flex min-h-
|
|
34
|
+
sm: 'flex min-h-6 w-full cursor-pointer items-center justify-between gap-2 rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors enabled:hover:border-input-hover 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',
|
|
35
|
+
md: 'flex min-h-8 w-full cursor-pointer items-center justify-between gap-2 rounded-md border border-input bg-surface px-3 text-sm text-fg transition-colors enabled:hover:border-input-hover 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',
|
|
34
36
|
lg: 'flex min-h-10 w-full cursor-pointer items-center justify-between gap-2 rounded-md border border-input bg-surface px-4 text-base text-fg transition-colors enabled:hover:border-input-hover 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',
|
|
35
37
|
};
|
|
36
38
|
const PLACEHOLDER_CLASS = 'truncate text-fg-subtle';
|
|
@@ -39,14 +41,14 @@ const CHIP_CLASS = 'inline-flex items-center rounded-md border border-border-sub
|
|
|
39
41
|
const CLEAR_CLASS = 'absolute end-8 top-0 flex h-full cursor-pointer items-center px-1 text-fg-subtle hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
40
42
|
const HIDDEN_CLASS = 'hidden';
|
|
41
43
|
const STATUS_CLASS = 'sr-only';
|
|
42
|
-
const PANEL_BASE = 'absolute z-10 flex max-h-70 w-full flex-col gap-1 overflow-auto
|
|
44
|
+
const PANEL_BASE = mergeClass('absolute z-10 flex max-h-70 w-full flex-col gap-1 overflow-auto p-1', kitSurfaceRecipe('raised'));
|
|
43
45
|
const SEARCH_CLASS = 'block h-8 w-full appearance-none autofill-clear rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring';
|
|
44
46
|
const TREE_CLASS = 'flex flex-col';
|
|
45
47
|
const TOGGLE_CLASS = 'w-4 shrink-0 text-fg-subtle';
|
|
46
48
|
const CHECK_CLASS = 'pointer-events-none';
|
|
47
49
|
const ROW_BASE = 'flex items-center gap-2 py-1 pe-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
48
50
|
const ROW_STATE = {
|
|
49
|
-
idle: 'cursor-pointer text-fg hover:bg-
|
|
51
|
+
idle: 'cursor-pointer text-fg hover:bg-state-layer-hover active:bg-state-layer-press',
|
|
50
52
|
selected: 'cursor-pointer bg-primary-soft text-primary-on-soft',
|
|
51
53
|
cursor: 'cursor-pointer bg-surface-sunken text-fg',
|
|
52
54
|
disabled: 'cursor-not-allowed text-fg-subtle',
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 涨跌语气(纯函数,基础层共用):涨跌方向 x 涨是好事还是坏事。StatGroup 环比徽标与 KitDelta 同用这一份。
|
|
2
|
+
|
|
3
|
+
export type TrendTone = 'good' | 'bad' | 'flat';
|
|
4
|
+
|
|
5
|
+
export function trendTone(change: number, upIs: 'good' | 'bad'): TrendTone {
|
|
6
|
+
if (change === 0) return 'flat';
|
|
7
|
+
const up = change > 0;
|
|
8
|
+
return up === (upIs === 'good') ? 'good' : 'bad';
|
|
9
|
+
}
|
package/src/base/upload.ts
CHANGED
|
@@ -9,14 +9,15 @@
|
|
|
9
9
|
|
|
10
10
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
11
|
import {
|
|
12
|
-
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
13
|
-
applyDisabled, bool, createKitController, formatValue, joinClass, num, setAttr, sizeOf, str,
|
|
12
|
+
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
13
|
+
applyCompositeField, applyDisabled, bool, createKitController, formatValue, joinClass, num, setAttr, sizeOf, str,
|
|
14
14
|
type KitApi, type KitProps, type KitSize,
|
|
15
15
|
} from './shared';
|
|
16
16
|
import { safeSrc } from './avatar';
|
|
17
17
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
18
18
|
import { kitIcon } from './icons';
|
|
19
|
-
import { setKitFace } from '../recipes';
|
|
19
|
+
import { kitControlRecipe, setKitFace } from '../recipes';
|
|
20
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
20
21
|
|
|
21
22
|
type FileStatus = 'pending' | 'uploading' | 'done' | 'error';
|
|
22
23
|
type RejectReason = 'type' | 'size' | 'count';
|
|
@@ -32,13 +33,14 @@ interface FileItem {
|
|
|
32
33
|
|
|
33
34
|
const ROOT_CLASS = 'flex w-full flex-col gap-2';
|
|
34
35
|
const PICK_CLASS: Record<KitSize, string> = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
// 选择文件钮 = 带文字的中性按钮:直接取按钮配方(描边走按钮描边令牌,随边界维度求解),只补「按内容收窄 + 手形光标」
|
|
37
|
+
sm: mergeClass(kitControlRecipe({ variant: 'neutral', size: 'sm' }), 'w-fit cursor-pointer'),
|
|
38
|
+
md: mergeClass(kitControlRecipe({ variant: 'neutral', size: 'md' }), 'w-fit cursor-pointer'),
|
|
39
|
+
lg: mergeClass(kitControlRecipe({ variant: 'neutral', size: 'lg' }), 'w-fit cursor-pointer'),
|
|
38
40
|
};
|
|
39
41
|
// 投放区:静止 / 拖入高亮 / 禁用,各一整串
|
|
40
42
|
const DROP_CLASS = {
|
|
41
|
-
idle: 'flex w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-border bg-surface px-4 py-6 text-sm text-fg-muted transition-colors hover:border-primary
|
|
43
|
+
idle: 'flex w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-border bg-surface px-4 py-6 text-sm text-fg-muted transition-colors hover:border-primary state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
42
44
|
over: 'flex w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-primary bg-primary-soft px-4 py-6 text-sm text-primary-on-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
43
45
|
disabled: 'flex w-full cursor-not-allowed flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-border bg-surface-sunken px-4 py-6 text-sm text-fg-subtle opacity-60',
|
|
44
46
|
} as const;
|
|
@@ -69,12 +71,12 @@ const TILE_IMG_CLASS = 'h-full w-full object-cover';
|
|
|
69
71
|
const TILE_NAME_CLASS = 'break-all px-2 text-center text-xs text-fg-muted';
|
|
70
72
|
const TILE_STATUS_CLASS = 'absolute bottom-1 start-1';
|
|
71
73
|
const TILE_REMOVE_CLASS = 'absolute end-1 top-1 cursor-pointer rounded-md bg-surface/80 px-1.5 text-sm text-fg transition-colors hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
72
|
-
const ADD_TILE_CLASS = 'flex aspect-square w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-border bg-surface text-sm text-fg-muted transition-colors hover:border-primary
|
|
74
|
+
const ADD_TILE_CLASS = 'flex aspect-square w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-border bg-surface text-sm text-fg-muted transition-colors hover:border-primary state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
73
75
|
const ADD_TILE_PLUS_CLASS = 'text-xl text-fg-subtle';
|
|
74
76
|
// 手动上传按钮:主色实心,文字 -fg
|
|
75
77
|
const START_CLASS: Record<KitSize, string> = {
|
|
76
|
-
sm: 'inline-flex h-
|
|
77
|
-
md: 'inline-flex h-
|
|
78
|
+
sm: 'inline-flex h-6 w-fit cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
79
|
+
md: 'inline-flex h-8 w-fit cursor-pointer items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
78
80
|
lg: 'inline-flex h-10 w-fit cursor-pointer items-center justify-center rounded-md bg-primary px-5 text-base font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
79
81
|
};
|
|
80
82
|
|
|
@@ -277,6 +279,8 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
|
|
|
277
279
|
if (wallAdd) trigger.className = HIDDEN_CLASS;
|
|
278
280
|
setAttr(trigger, 'id', wallAdd ? '' : str(p.id));
|
|
279
281
|
setAttr(trigger, 'aria-label', wallAdd ? '' : str(p.aria_label));
|
|
282
|
+
// 作表单字段:根承载字段名(labelledby)/ 说明 / 错误关联与无效标记
|
|
283
|
+
applyCompositeField(root, p);
|
|
280
284
|
|
|
281
285
|
const hint = str(p.hint);
|
|
282
286
|
ui.hint.textContent = hint;
|
|
@@ -445,6 +449,7 @@ export function createUpload(): SomaComponentDefinition {
|
|
|
445
449
|
disabled: { type: 'boolean', default: false },
|
|
446
450
|
readonly: { type: 'boolean', default: false },
|
|
447
451
|
...ID_PROPS,
|
|
452
|
+
...INVALID_PROPS,
|
|
448
453
|
size: SIZE_PROP,
|
|
449
454
|
class: CLASS_PROP,
|
|
450
455
|
},
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// 页面过渡入口:用 View Transitions 包住一次同步 DOM 更新(页签切换、主从切换的内容区)。
|
|
2
|
+
//
|
|
3
|
+
// 规则:
|
|
4
|
+
// · 浏览器支持 `document.startViewTransition`、用户没有要求减弱动效、且页面上有命名内容区(`[data-kit-vt]`)→ 包进过渡(只有带 view-transition-name 的内容区参与,外壳不动);
|
|
5
|
+
// · 不支持 / 减弱动效 / 无 document(SSR、测试环境)→ 直接调用 update,行为与没有这个函数时逐字节相同;
|
|
6
|
+
// · 并发:新调用到来时跳过上一次仍在进行的过渡(skipTransition,上一次的 update 仍会执行完,只是不再播动画);
|
|
7
|
+
// · 永不因过渡对象出错:update 抛出的错误原样透传(同步路径直接抛;过渡路径里抛给 startViewTransition 的回调,
|
|
8
|
+
// 过渡对象的 ready / finished / updateCallbackDone 三个 promise 的 rejection 一律吞掉)。
|
|
9
|
+
// 时长与缓动在样式里(kit-theme.tpl 的「自适应与过渡」块,读动效令牌),本文件不写任何数字。
|
|
10
|
+
|
|
11
|
+
import { prefersReducedMotion } from './motion/limits';
|
|
12
|
+
|
|
13
|
+
interface KitViewTransition {
|
|
14
|
+
readonly ready?: Promise<unknown>;
|
|
15
|
+
readonly finished?: Promise<unknown>;
|
|
16
|
+
readonly updateCallbackDone?: Promise<unknown>;
|
|
17
|
+
skipTransition?(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type StartViewTransition = (update: () => void) => KitViewTransition;
|
|
21
|
+
|
|
22
|
+
let active: KitViewTransition | null = null;
|
|
23
|
+
|
|
24
|
+
function swallow(p: Promise<unknown> | undefined): void {
|
|
25
|
+
if (p !== undefined && typeof p.then === 'function') p.then(undefined, () => {});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 当前环境能否播页面过渡(支持 API 且未偏好减弱动效) */
|
|
29
|
+
export function canKitViewTransition(): boolean {
|
|
30
|
+
if (typeof document === 'undefined') return false;
|
|
31
|
+
if (typeof (document as { startViewTransition?: unknown }).startViewTransition !== 'function') return false;
|
|
32
|
+
if (prefersReducedMotion()) return false;
|
|
33
|
+
// 页面上没有任何命名的内容区(data-kit-vt)就没有可过渡的东西,别白白冻一帧
|
|
34
|
+
return document.querySelector('[data-kit-vt]') !== null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 把 update 包进页面过渡;不可用时直接调用 update。update 的异常透传。 */
|
|
38
|
+
export function withKitViewTransition(update: () => void): void {
|
|
39
|
+
if (!canKitViewTransition()) {
|
|
40
|
+
update();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const start = (document as unknown as { startViewTransition: StartViewTransition }).startViewTransition.bind(document);
|
|
44
|
+
// 并发:先跳过上一次(其 update 已在跑或已跑完,skip 只取消动画)
|
|
45
|
+
const previous = active;
|
|
46
|
+
if (previous !== null) {
|
|
47
|
+
try { previous.skipTransition?.(); } catch { /* 跳过失败不影响本次 */ }
|
|
48
|
+
}
|
|
49
|
+
// 过渡路径里 update 由浏览器异步调用,抛错只会变成 updateCallbackDone 的 rejection(下面吞掉):
|
|
50
|
+
// 所以先把错误交给全局错误通道(reportError / console.error),再原样抛回给浏览器,不让 update 的错误被静默吃掉
|
|
51
|
+
const guarded = (): void => {
|
|
52
|
+
try {
|
|
53
|
+
update();
|
|
54
|
+
} catch (err) {
|
|
55
|
+
const report = (globalThis as { reportError?: (e: unknown) => void }).reportError;
|
|
56
|
+
if (typeof report === 'function') report(err); else console.error(err);
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
let transition: KitViewTransition;
|
|
61
|
+
try {
|
|
62
|
+
transition = start(guarded);
|
|
63
|
+
} catch {
|
|
64
|
+
// startViewTransition 同步抛(状态异常):退回直接更新
|
|
65
|
+
update();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
active = transition;
|
|
69
|
+
swallow(transition.ready);
|
|
70
|
+
swallow(transition.updateCallbackDone);
|
|
71
|
+
const finished = transition.finished;
|
|
72
|
+
if (finished !== undefined && typeof finished.then === 'function') {
|
|
73
|
+
finished.then(undefined, () => {}).then(() => { if (active === transition) active = null; });
|
|
74
|
+
} else {
|
|
75
|
+
active = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// ApprovalDesk 的 HTML 代码壳:左待办队列 + 中审批单 + 右历史 / 比对三栏。只有结构与 Tailwind 类(语义色名 + utilityScales 里有的尺度),不写原生 CSS。
|
|
2
2
|
// 三栏靠容器查询变体 `@md:`:窄容器下上下堆叠;达到 md 档左 3 / 中 5 / 右 4(共 12 份)。
|
|
3
3
|
|
|
4
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../../base/hint-tips';
|
|
4
5
|
import { mergeClass } from '../../object-renderer/merge-class';
|
|
6
|
+
import { KIT_SHELL_FLAT_MARK, kitShellRecipe } from '../../recipes/container';
|
|
5
7
|
import { cls, esc, host } from '../link/shared';
|
|
6
8
|
|
|
7
9
|
/** 壳的内部区域名(`areaClass` 的合法键) */
|
|
@@ -11,9 +13,11 @@ export type ApprovalDeskArea = (typeof APPROVAL_DESK_AREAS)[number];
|
|
|
11
13
|
export const APPROVAL_DESK_CLASS = {
|
|
12
14
|
root: '@container flex flex-col gap-4',
|
|
13
15
|
grid: 'grid grid-cols-12 gap-4',
|
|
14
|
-
queue: 'col-span-12 @md:col-span-3 flex min-w-0 flex-col gap-3
|
|
15
|
-
request: 'col-span-12 @md:col-span-5 flex min-w-0 flex-col gap-3
|
|
16
|
-
history: 'col-span-12 @md:col-span-4 flex min-w-0 flex-col gap-3
|
|
16
|
+
queue: mergeClass('col-span-12 @md:col-span-3 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
17
|
+
request: mergeClass('col-span-12 @md:col-span-5 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
18
|
+
history: mergeClass('col-span-12 @md:col-span-4 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
19
|
+
/** 没有历史栏时审批单栏吃掉右侧 4 份(9/12) */
|
|
20
|
+
requestWide: mergeClass('col-span-12 @md:col-span-9 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
17
21
|
title: 'min-w-0 truncate text-base font-semibold text-fg',
|
|
18
22
|
} as const;
|
|
19
23
|
|
|
@@ -34,14 +38,13 @@ export function approvalDeskHtml(
|
|
|
34
38
|
extra: string | undefined,
|
|
35
39
|
): string {
|
|
36
40
|
const col = (area: 'queue' | 'request' | 'history', c: DeskColumn, wide?: string): string => {
|
|
37
|
-
|
|
41
|
+
// 截断的标题悬停 / 聚焦时由 hint-tips 按需挂全文气泡(作用范围标记就在标题元素自身)
|
|
42
|
+
const title = c.title === '' ? '' : `<h3${cls(APPROVAL_DESK_CLASS.title)} ${KIT_TIPS_SCOPE_ATTR}="">${esc(c.title)}</h3>`;
|
|
38
43
|
const base = wide === undefined ? APPROVAL_DESK_CLASS[area] : wide;
|
|
39
|
-
return `<section${cls(mergeClass(base, areaClass[area]))}>${title}${c.html}</section>`;
|
|
44
|
+
return `<section${cls(mergeClass(base, areaClass[area]))}${KIT_SHELL_FLAT_MARK}>${title}${c.html}</section>`;
|
|
40
45
|
};
|
|
41
46
|
// 没有历史栏时,审批单栏吃掉右侧 4 份
|
|
42
|
-
const requestBase = parts.history === null
|
|
43
|
-
? 'col-span-12 @md:col-span-9 flex min-w-0 flex-col gap-3 rounded-lg border border-border-strong bg-surface-raised p-4 shadow-xs'
|
|
44
|
-
: undefined;
|
|
47
|
+
const requestBase = parts.history === null ? APPROVAL_DESK_CLASS.requestWide : undefined;
|
|
45
48
|
const cols = [col('queue', parts.queue), col('request', parts.request, requestBase)];
|
|
46
49
|
if (parts.history !== null) cols.push(col('history', parts.history));
|
|
47
50
|
const root = mergeClass(mergeClass(APPROVAL_DESK_CLASS.root, areaClass.root), extra);
|