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/index.ts
CHANGED
|
@@ -25,6 +25,9 @@ import { createAlert } from './alert';
|
|
|
25
25
|
import { createKitDivider, KIT_DIVIDER_CLASS_CANDIDATES } from './divider';
|
|
26
26
|
import { KIT_MOTION_COMPONENTS, KIT_MOTION_CLASS_CANDIDATES, type KitMotionId } from './motion';
|
|
27
27
|
export { KIT_MOTION_COMPONENTS, KIT_MOTION_CLASS_CANDIDATES } from './motion';
|
|
28
|
+
// 内置图标集:应用组件经 soma-kit/base 取用(kitIcon 返回 SVGSVGElement,kitIconHtml 返回 SVG 字符串)
|
|
29
|
+
export { kitIcon, kitIconHtml, KIT_ICON_NAMES, KIT_ICON_SIZES } from './icons';
|
|
30
|
+
export type { KitIconName, KitIconSize } from './icons';
|
|
28
31
|
// K9 / D1 补齐波:Range Rating Otp Avatar AvatarGroup Kbd KitProgress(环/条) Countdown Swap Fab Image MenuButton
|
|
29
32
|
import { createRange, KIT_RANGE_CLASS_CANDIDATES } from './range';
|
|
30
33
|
import { createRating, KIT_RATING_CLASS_CANDIDATES } from './rating';
|
|
@@ -32,6 +35,7 @@ import { createOtp, KIT_OTP_CLASS_CANDIDATES } from './otp';
|
|
|
32
35
|
import { createAvatar, createAvatarGroup, KIT_AVATAR_CLASS_CANDIDATES } from './avatar';
|
|
33
36
|
import { createKbd, KIT_KBD_CLASS_CANDIDATES } from './kbd';
|
|
34
37
|
import { createKitProgress, KIT_PROGRESS_CLASS_CANDIDATES } from './progress';
|
|
38
|
+
import { createKitDelta, KIT_DELTA_CLASS_CANDIDATES } from './delta';
|
|
35
39
|
import { createCountdown, KIT_COUNTDOWN_CLASS_CANDIDATES } from './countdown';
|
|
36
40
|
import { createSwap, KIT_SWAP_CLASS_CANDIDATES } from './swap';
|
|
37
41
|
import { createFab, KIT_FAB_CLASS_CANDIDATES } from './fab';
|
|
@@ -60,6 +64,10 @@ import { createPriceText, KIT_PRICE_TEXT_CLASS_CANDIDATES } from './price-text';
|
|
|
60
64
|
import { createQrCode, KIT_QR_CODE_CLASS_CANDIDATES } from './qr-code';
|
|
61
65
|
import { KIT_CONTEXT_MENU_CLASS_CANDIDATES } from './context-menu';
|
|
62
66
|
import { createCommandPalette, KIT_COMMAND_PALETTE_CLASS_CANDIDATES } from './command-palette';
|
|
67
|
+
import { createGapValue, KIT_GAP_VALUE_CLASS_CANDIDATES } from './gap-value';
|
|
68
|
+
import { KIT_SURFACE_CLASS_CANDIDATES } from '../recipes/surface';
|
|
69
|
+
import { KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES } from '../recipes/rail-grid';
|
|
70
|
+
import { KIT_BUSY_SPIN_CLASS_CANDIDATES } from './action-busy';
|
|
63
71
|
|
|
64
72
|
/** D8 组新增基础组件自带的类(去重),并入 KIT_BASE_CLASS_CANDIDATES */
|
|
65
73
|
export const KIT_D8_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
@@ -68,7 +76,7 @@ export const KIT_D8_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
68
76
|
...KIT_MENTIONS_CLASS_CANDIDATES, ...KIT_SEGMENTED_CLASS_CANDIDATES, ...KIT_QTY_STEPPER_CLASS_CANDIDATES,
|
|
69
77
|
...KIT_POPOVER_CLASS_CANDIDATES, ...KIT_TAG_CLASS_CANDIDATES,
|
|
70
78
|
...KIT_PRICE_TEXT_CLASS_CANDIDATES, ...KIT_QR_CODE_CLASS_CANDIDATES, ...KIT_CONTEXT_MENU_CLASS_CANDIDATES,
|
|
71
|
-
...KIT_COMMAND_PALETTE_CLASS_CANDIDATES,
|
|
79
|
+
...KIT_COMMAND_PALETTE_CLASS_CANDIDATES, ...KIT_GAP_VALUE_CLASS_CANDIDATES,
|
|
72
80
|
]),
|
|
73
81
|
]);
|
|
74
82
|
|
|
@@ -85,7 +93,7 @@ export const KIT_D1_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
85
93
|
...new Set([
|
|
86
94
|
...KIT_RANGE_CLASS_CANDIDATES, ...KIT_RATING_CLASS_CANDIDATES, ...KIT_OTP_CLASS_CANDIDATES,
|
|
87
95
|
...KIT_AVATAR_CLASS_CANDIDATES, ...KIT_KBD_CLASS_CANDIDATES, ...KIT_PROGRESS_CLASS_CANDIDATES,
|
|
88
|
-
...KIT_COUNTDOWN_CLASS_CANDIDATES, ...KIT_SWAP_CLASS_CANDIDATES, ...KIT_FAB_CLASS_CANDIDATES,
|
|
96
|
+
...KIT_DELTA_CLASS_CANDIDATES, ...KIT_COUNTDOWN_CLASS_CANDIDATES, ...KIT_SWAP_CLASS_CANDIDATES, ...KIT_FAB_CLASS_CANDIDATES,
|
|
89
97
|
...KIT_IMAGE_CLASS_CANDIDATES, ...KIT_MENU_BUTTON_CLASS_CANDIDATES, ...KIT_TOOLTIP_CLASS_CANDIDATES,
|
|
90
98
|
]),
|
|
91
99
|
]);
|
|
@@ -94,8 +102,8 @@ export type KitBaseId =
|
|
|
94
102
|
| 'Text' | 'Tag' | 'Input' | 'Textarea' | 'Number' | 'Select' | 'Radio'
|
|
95
103
|
| 'Checkbox' | 'Switch' | 'Date' | 'DateRange' | 'Button' | 'Link'
|
|
96
104
|
| 'TagInput' | 'Upload' | 'TimePicker' | 'TreeSelect' | 'Alert' | 'KitDivider' | KitMotionId
|
|
97
|
-
| 'Range' | 'Rating' | 'Otp' | 'Avatar' | 'AvatarGroup' | 'Kbd' | 'KitProgress' | 'Countdown' | 'Swap' | 'Fab' | 'Image' | 'MenuButton'
|
|
98
|
-
| 'Cascader' | 'Combobox' | 'ColorPicker' | 'Mentions' | 'Popover' | 'PriceText' | 'QrCode' | 'CommandPalette';
|
|
105
|
+
| 'Range' | 'Rating' | 'Otp' | 'Avatar' | 'AvatarGroup' | 'Kbd' | 'KitProgress' | 'KitDelta' | 'Countdown' | 'Swap' | 'Fab' | 'Image' | 'MenuButton'
|
|
106
|
+
| 'Cascader' | 'Combobox' | 'ColorPicker' | 'Mentions' | 'Popover' | 'PriceText' | 'QrCode' | 'CommandPalette' | 'GapValue';
|
|
99
107
|
|
|
100
108
|
export const KIT_BASE_COMPONENTS: Record<KitBaseId, () => SomaComponentDefinition> = {
|
|
101
109
|
Text: createText,
|
|
@@ -125,6 +133,7 @@ export const KIT_BASE_COMPONENTS: Record<KitBaseId, () => SomaComponentDefinitio
|
|
|
125
133
|
AvatarGroup: createAvatarGroup,
|
|
126
134
|
Kbd: createKbd,
|
|
127
135
|
KitProgress: createKitProgress,
|
|
136
|
+
KitDelta: createKitDelta,
|
|
128
137
|
Countdown: createCountdown,
|
|
129
138
|
Swap: createSwap,
|
|
130
139
|
Fab: createFab,
|
|
@@ -138,6 +147,7 @@ export const KIT_BASE_COMPONENTS: Record<KitBaseId, () => SomaComponentDefinitio
|
|
|
138
147
|
PriceText: createPriceText,
|
|
139
148
|
QrCode: createQrCode,
|
|
140
149
|
CommandPalette: createCommandPalette,
|
|
150
|
+
GapValue: createGapValue,
|
|
141
151
|
};
|
|
142
152
|
|
|
143
153
|
/**
|
|
@@ -158,7 +168,7 @@ export const KIT_BASE_CORE_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
158
168
|
'font-medium',
|
|
159
169
|
'gap-1', 'gap-2', 'gap-3', 'gap-x-3', 'gap-x-4', 'gap-x-5', 'gap-y-1', 'gap-y-2',
|
|
160
170
|
'h-10', 'h-11', 'h-3.5', 'h-4', 'h-5', 'h-6', 'h-7', 'h-8', 'h-9',
|
|
161
|
-
'hidden', 'hover:bg-
|
|
171
|
+
'hidden', 'state-layer', 'hover:bg-state-layer-hover', 'active:bg-state-layer-press', 'focus-visible:bg-state-layer-hover', 'hover:opacity-80', 'hover:opacity-90',
|
|
162
172
|
'inline-block', 'inline-flex', 'items-center', 'justify-center', 'start-0.5',
|
|
163
173
|
'placeholder:text-fg-subtle', 'pointer-events-none',
|
|
164
174
|
'px-1.5', 'px-2', 'px-2.5', 'px-3', 'px-4', 'px-5', 'py-0.5', 'py-1', 'py-2', 'py-3',
|
|
@@ -176,18 +186,18 @@ export const KIT_BASE_CORE_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
176
186
|
'focus-within:ring-2', 'focus-within:ring-ring',
|
|
177
187
|
'h-2', 'h-8', 'h-full', 'items-start', 'justify-between', 'start-0',
|
|
178
188
|
'max-h-70', 'max-h-52', 'max-h-34', 'max-h-25', 'max-h-16', 'shadow-lg', 'shadow-xl', 'top-0.5', 'start-4.5', 'start-5.5', 'start-7.5',
|
|
179
|
-
'peer-checked:start-4.5', 'peer-checked:start-5.5', 'peer-checked:start-7.5', 'transition-all', 'min-h-11', 'min-h-8', 'min-h-9', 'min-w-0', 'min-w-24', 'me-1.5', 'mt-1',
|
|
189
|
+
'peer-checked:start-4.5', 'peer-checked:start-5.5', 'peer-checked:start-7.5', 'transition-all', 'min-h-11', 'min-h-6', 'min-w-6', 'min-h-8', 'min-h-9', 'min-w-0', 'min-w-24', 'me-1.5', 'mt-1',
|
|
180
190
|
'object-cover', 'overflow-auto', 'p-1',
|
|
181
191
|
'ps-10', 'ps-14', 'ps-18', 'ps-2', 'ps-22', 'ps-6', 'pe-2', 'px-0.5', 'px-1', 'py-4', 'py-6',
|
|
182
192
|
'end-8', 'self-end', 'text-start', 'text-primary-on-soft', 'top-0', 'top-full', 'truncate', 'w-2', 'w-8', 'w-fit', 'z-10',
|
|
183
193
|
// V1 美化追加:统一高度 / 边框 / 反馈
|
|
184
194
|
'bg-border-subtle', 'bg-primary-active', 'bg-primary-hover', 'bg-danger-active', 'bg-danger-hover',
|
|
185
195
|
'border-border-subtle', 'border-danger-on-soft/20', 'border-info-on-soft/20', 'border-success-on-soft/20', 'border-warning-on-soft/20',
|
|
186
|
-
'disabled:opacity-60', 'enabled:active:bg-
|
|
187
|
-
'enabled:hover:bg-danger-hover', 'enabled:hover:bg-fg-subtle', 'enabled:hover:bg-primary-hover', 'enabled:hover:bg-
|
|
196
|
+
'disabled:opacity-60', 'enabled:active:bg-danger-active', 'enabled:active:bg-primary-active',
|
|
197
|
+
'enabled:hover:bg-danger-hover', 'enabled:hover:bg-fg-subtle', 'enabled:hover:bg-primary-hover', 'enabled:hover:bg-state-layer-hover', 'enabled:active:bg-state-layer-press',
|
|
188
198
|
'border-input', 'hover:border-input-hover', 'enabled:hover:border-input-hover',
|
|
189
199
|
'enabled:hover:border-fg-subtle', 'focus-visible:border-primary', 'focus-within:border-primary', 'hover:border-fg-subtle',
|
|
190
|
-
'hover:border-primary', 'hover:
|
|
200
|
+
'hover:border-primary', 'hover:text-fg', 'hover:text-primary-on-soft', 'active:opacity-60', 'hover:opacity-100',
|
|
191
201
|
'min-h-10', 'opacity-60', 'opacity-70', 'px-2.5', 'py-1.5', 'py-2.5', 'rounded-lg', 'rounded-sm', 'underline-offset-2',
|
|
192
202
|
'cursor-not-allowed', 'transition-colors', 'bg-info-fg', 'text-info-fg', 'text-success-fg', 'text-warning-fg', 'bg-surface',
|
|
193
203
|
'bg-surface-sunken', 'text-fg-muted', 'text-fg-subtle', 'font-medium', 'text-xs', 'gap-1', 'rounded-full', 'items-center',
|
|
@@ -211,6 +221,14 @@ export const KIT_BASE_CLASS_CANDIDATES: readonly string[] = Object.freeze([...ne
|
|
|
211
221
|
...KIT_D1_CLASS_CANDIDATES,
|
|
212
222
|
...KIT_D8_CLASS_CANDIDATES,
|
|
213
223
|
...KIT_G1A_CLASS_CANDIDATES,
|
|
224
|
+
// 美化批次 2:三级表面配方(甲,recipes/surface.ts)与导轨拼合配方(乙,recipes/rail-grid.ts)的类;状态层悬停 / 按下类(收尾)
|
|
225
|
+
...KIT_SURFACE_CLASS_CANDIDATES,
|
|
226
|
+
...KIT_RAIL_GRID_RECIPE_CLASS_CANDIDATES,
|
|
227
|
+
// 丙:按钮忙碌态转圈(action-busy.ts);丁:门户展示档字阶工具类
|
|
228
|
+
...KIT_BUSY_SPIN_CLASS_CANDIDATES,
|
|
229
|
+
'text-display',
|
|
230
|
+
'enabled:hover:bg-state-layer-hover', 'enabled:active:bg-state-layer-press',
|
|
231
|
+
'enabled:hover:bg-state-layer-tonal-hover', 'enabled:active:bg-state-layer-tonal-press',
|
|
214
232
|
])].sort());
|
|
215
233
|
|
|
216
234
|
export function createKitBaseComponents(): Record<KitBaseId, SomaComponentDefinition> {
|
package/src/base/listbox-core.ts
CHANGED
|
@@ -42,13 +42,13 @@ const CLEAR_PAD_SELECT_CLASS = 'pe-12';
|
|
|
42
42
|
|
|
43
43
|
// 多选 chips 形态:字段嵌在一个像字段的盒子里,标签与字段同排换行
|
|
44
44
|
export const BOX_CLASS: Record<KitSize, string> = {
|
|
45
|
-
sm: 'flex min-h-
|
|
46
|
-
md: 'flex min-h-
|
|
45
|
+
sm: 'flex min-h-6 w-full flex-wrap items-center gap-1 rounded-md border border-input bg-surface px-2 py-0.5 text-sm text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
|
|
46
|
+
md: 'flex min-h-8 w-full flex-wrap items-center gap-1 rounded-md border border-input bg-surface px-2 py-1 text-sm text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
|
|
47
47
|
lg: 'flex min-h-10 w-full flex-wrap items-center gap-2 rounded-md border border-input bg-surface px-3 py-1 text-base text-fg transition-colors hover:border-input-hover focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
|
|
48
48
|
};
|
|
49
49
|
export const BOX_OFF_CLASS: Record<KitSize, string> = {
|
|
50
|
-
sm: 'flex min-h-
|
|
51
|
-
md: 'flex min-h-
|
|
50
|
+
sm: 'flex min-h-6 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md border border-input bg-surface-sunken px-2 py-0.5 text-sm text-fg-subtle opacity-60',
|
|
51
|
+
md: 'flex min-h-8 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md border border-input bg-surface-sunken px-2 py-1 text-sm text-fg-subtle opacity-60',
|
|
52
52
|
lg: 'flex min-h-10 w-full cursor-not-allowed flex-wrap items-center gap-2 rounded-md border border-input bg-surface-sunken px-3 py-1 text-base text-fg-subtle opacity-60',
|
|
53
53
|
};
|
|
54
54
|
export const BOX_INPUT_CLASS = 'min-w-24 flex-1 appearance-none autofill-clear bg-surface px-1 py-0.5 text-fg placeholder:text-fg-subtle focus-visible:outline-none disabled:cursor-not-allowed disabled:bg-surface-sunken';
|
|
@@ -71,7 +71,7 @@ const CLEAR_HIDDEN_CLASS = 'hidden';
|
|
|
71
71
|
|
|
72
72
|
// select-only 字段(可聚焦的 div):状态整串换,不依赖原生 enabled: / read-only: 变体
|
|
73
73
|
const SEL_FIELD_BASE = 'flex w-full items-center justify-between gap-2 rounded-md border border-input text-start transition-colors focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring aria-invalid:border-danger';
|
|
74
|
-
const SEL_FIELD_SIZE: Record<KitSize, string> = { sm: 'h-
|
|
74
|
+
const SEL_FIELD_SIZE: Record<KitSize, string> = { sm: 'h-6 px-2.5 text-sm', md: 'h-8 px-3 text-sm', lg: 'h-10 px-4 text-base' };
|
|
75
75
|
const selFieldClasses = (tone: string): Record<KitSize, string> => ({
|
|
76
76
|
sm: `${SEL_FIELD_BASE} ${SEL_FIELD_SIZE.sm} ${tone}`,
|
|
77
77
|
md: `${SEL_FIELD_BASE} ${SEL_FIELD_SIZE.md} ${tone}`,
|
|
@@ -950,6 +950,7 @@ export function createListboxView(kind: ListboxKind): KitViewSetup {
|
|
|
950
950
|
}
|
|
951
951
|
applyCommon(z.field, { ...p, name: '' });
|
|
952
952
|
setAttr(panel, 'aria-label', str(p.aria_label));
|
|
953
|
+
setAttr(panel, 'aria-labelledby', str(p.aria_labelledby, str(p.labelledby)));
|
|
953
954
|
root.className = joinClass(/(^|\s)(w-|min-w-|max-w-|flex-|basis-)/.test(str(p.class)) ? WRAP_CLASS : WRAP_FULL_CLASS, p.class);
|
|
954
955
|
paint();
|
|
955
956
|
};
|
package/src/base/loading-gate.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 加载反馈时序:「延迟出现 + 最短显示」纯状态机 + 计时器外壳。
|
|
2
2
|
//
|
|
3
3
|
// 目的:
|
|
4
|
-
// 1. 快请求(在 delayMs 内完成)全程不进入 visible
|
|
5
|
-
// 2.
|
|
4
|
+
// 1. 快请求(在 delayMs 内完成)全程不进入 visible,不显示任何指示器(零闪屏);
|
|
5
|
+
// 2. 一旦进入 visible,即使请求随即完成也至少保持 minVisibleMs,防止一闪而过;
|
|
6
6
|
// 3. 从 visible 结束时进入短暂 done 过渡态停留 doneHoldMs 后回到 idle。
|
|
7
|
+
//
|
|
8
|
+
// 三个时长读真源 structure.loadingFeedback(delayMs / minVisibleMs / doneHoldMs,经 foundation 投影),本文件不写字面量。
|
|
9
|
+
// 状态转移是纯函数 `stepLoadingFeedback`(入参含当前时刻,不碰计时器、不读时钟),便于假时钟测试;
|
|
10
|
+
// `createLoadingGate` 只负责把它接到 setTimeout / Date.now 与回调上。
|
|
11
|
+
|
|
12
|
+
import { KIT_NINE_DIM } from 'soma-foundation/kit-nine-dim';
|
|
7
13
|
|
|
8
14
|
export type KitLoadingPhase = 'idle' | 'pending-delay' | 'visible' | 'done';
|
|
9
15
|
|
|
10
16
|
export interface KitLoadingGateOptions {
|
|
11
|
-
/**
|
|
17
|
+
/** 延迟出现阈值(毫秒),缺省读真源 loadingFeedback.delayMs:在此时间内完成则不显示 loading 态 */
|
|
12
18
|
delayMs?: number;
|
|
13
|
-
/**
|
|
19
|
+
/** 最短可见停留阈值(毫秒),缺省读真源 loadingFeedback.minVisibleMs:进入 visible 后至少保持此时长 */
|
|
14
20
|
minDurationMs?: number;
|
|
15
|
-
/**
|
|
21
|
+
/** 完成态停留阈值(毫秒),缺省读真源 loadingFeedback.doneHoldMs:从 visible 结束时停留 done 态的时长 */
|
|
16
22
|
doneHoldMs?: number;
|
|
17
23
|
/** 状态变化回调(也可通过 createLoadingGate 第二参数传入) */
|
|
18
24
|
onChange?: (phase: KitLoadingPhase) => void;
|
|
@@ -26,12 +32,108 @@ export interface KitLoadingGate {
|
|
|
26
32
|
isVisible(): boolean;
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
const FEEDBACK = KIT_NINE_DIM.structure.loadingFeedback;
|
|
36
|
+
|
|
29
37
|
export const KIT_LOADING_GATE_DEFAULTS = Object.freeze({
|
|
30
|
-
delayMs:
|
|
31
|
-
minDurationMs:
|
|
32
|
-
doneHoldMs:
|
|
38
|
+
delayMs: FEEDBACK.delayMs,
|
|
39
|
+
minDurationMs: FEEDBACK.minVisibleMs,
|
|
40
|
+
doneHoldMs: FEEDBACK.doneHoldMs,
|
|
33
41
|
} as const);
|
|
34
42
|
|
|
43
|
+
// ---------------------------------------------------------------- 纯状态机
|
|
44
|
+
|
|
45
|
+
export interface LoadingFeedbackConfig {
|
|
46
|
+
readonly delayMs: number;
|
|
47
|
+
readonly minVisibleMs: number;
|
|
48
|
+
readonly doneHoldMs: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface LoadingFeedbackState {
|
|
52
|
+
readonly phase: KitLoadingPhase;
|
|
53
|
+
/** 进入当前阶段的时刻(毫秒时间戳) */
|
|
54
|
+
readonly since: number;
|
|
55
|
+
/** visible 期间是否已收到 finish(等最短显示期满后退出) */
|
|
56
|
+
readonly finishing: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type LoadingFeedbackEvent =
|
|
60
|
+
| { readonly type: 'start' }
|
|
61
|
+
| { readonly type: 'finish' }
|
|
62
|
+
| { readonly type: 'cancel' }
|
|
63
|
+
| { readonly type: 'tick' };
|
|
64
|
+
|
|
65
|
+
export interface LoadingFeedbackStep {
|
|
66
|
+
readonly state: LoadingFeedbackState;
|
|
67
|
+
/** 下一次需要送 tick 的时刻;null = 不需要计时 */
|
|
68
|
+
readonly wakeAt: number | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const LOADING_FEEDBACK_IDLE: LoadingFeedbackState = Object.freeze({ phase: 'idle', since: 0, finishing: false });
|
|
72
|
+
|
|
73
|
+
/** 到期的阶段推进(可连续推进多步,如 visible 期满且 doneHold 为 0 直接回 idle) */
|
|
74
|
+
function settle(state: LoadingFeedbackState, now: number, cfg: LoadingFeedbackConfig): LoadingFeedbackState {
|
|
75
|
+
let s = state;
|
|
76
|
+
for (;;) {
|
|
77
|
+
if (s.phase === 'pending-delay' && now - s.since >= cfg.delayMs) {
|
|
78
|
+
s = { phase: 'visible', since: s.since + cfg.delayMs, finishing: false };
|
|
79
|
+
} else if (s.phase === 'visible' && s.finishing && now - s.since >= cfg.minVisibleMs) {
|
|
80
|
+
const at = s.since + cfg.minVisibleMs;
|
|
81
|
+
s = cfg.doneHoldMs <= 0 ? LOADING_FEEDBACK_IDLE : { phase: 'done', since: at, finishing: false };
|
|
82
|
+
} else if (s.phase === 'done' && now - s.since >= cfg.doneHoldMs) {
|
|
83
|
+
s = LOADING_FEEDBACK_IDLE;
|
|
84
|
+
} else {
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function wakeOf(s: LoadingFeedbackState, cfg: LoadingFeedbackConfig): number | null {
|
|
91
|
+
if (s.phase === 'pending-delay') return s.since + cfg.delayMs;
|
|
92
|
+
if (s.phase === 'visible' && s.finishing) return s.since + cfg.minVisibleMs;
|
|
93
|
+
if (s.phase === 'done') return s.since + cfg.doneHoldMs;
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 纯转移:(状态, 事件, 当前时刻, 配置) → (新状态, 下次唤醒时刻)。
|
|
99
|
+
* - start:从任何阶段重新开始;delayMs 为 0 直接 visible,否则 pending-delay;
|
|
100
|
+
* - finish:pending-delay 内完成 → 直接 idle(全程不显示);visible 内完成 → 记 finishing,满 minVisibleMs 后退出;idle / done 忽略;
|
|
101
|
+
* - cancel:立即回 idle;
|
|
102
|
+
* - tick:只做到期推进。
|
|
103
|
+
* 同一时刻先把已到期的阶段推进完,再处理事件。
|
|
104
|
+
*/
|
|
105
|
+
export function stepLoadingFeedback(
|
|
106
|
+
state: LoadingFeedbackState,
|
|
107
|
+
event: LoadingFeedbackEvent,
|
|
108
|
+
now: number,
|
|
109
|
+
cfg: LoadingFeedbackConfig,
|
|
110
|
+
): LoadingFeedbackStep {
|
|
111
|
+
let s = settle(state, now, cfg);
|
|
112
|
+
switch (event.type) {
|
|
113
|
+
case 'start':
|
|
114
|
+
s = cfg.delayMs <= 0 ? { phase: 'visible', since: now, finishing: false } : { phase: 'pending-delay', since: now, finishing: false };
|
|
115
|
+
break;
|
|
116
|
+
case 'finish':
|
|
117
|
+
if (s.phase === 'pending-delay') s = LOADING_FEEDBACK_IDLE;
|
|
118
|
+
else if (s.phase === 'visible' && !s.finishing) {
|
|
119
|
+
if (now - s.since >= cfg.minVisibleMs) {
|
|
120
|
+
s = cfg.doneHoldMs <= 0 ? LOADING_FEEDBACK_IDLE : { phase: 'done', since: now, finishing: false };
|
|
121
|
+
} else {
|
|
122
|
+
s = { ...s, finishing: true };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case 'cancel':
|
|
127
|
+
s = LOADING_FEEDBACK_IDLE;
|
|
128
|
+
break;
|
|
129
|
+
case 'tick':
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
return { state: s, wakeAt: wakeOf(s, cfg) };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ---------------------------------------------------------------- 计时器外壳
|
|
136
|
+
|
|
35
137
|
function resolveMs(val: number | undefined, fallback: number): number {
|
|
36
138
|
return typeof val === 'number' && Number.isFinite(val) && val >= 0 ? val : fallback;
|
|
37
139
|
}
|
|
@@ -42,92 +144,43 @@ export function createLoadingGate(
|
|
|
42
144
|
): KitLoadingGate {
|
|
43
145
|
const opts: KitLoadingGateOptions = typeof options === 'function' ? { onChange: options } : (options ?? {});
|
|
44
146
|
const notify = onChange ?? opts.onChange;
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let currentPhase: KitLoadingPhase = 'idle';
|
|
50
|
-
let visibleAt = 0;
|
|
51
|
-
let delayTimer: ReturnType<typeof setTimeout> | undefined;
|
|
52
|
-
let minWaitTimer: ReturnType<typeof setTimeout> | undefined;
|
|
53
|
-
let doneTimer: ReturnType<typeof setTimeout> | undefined;
|
|
54
|
-
|
|
55
|
-
const clearTimers = (): void => {
|
|
56
|
-
if (delayTimer !== undefined) {
|
|
57
|
-
clearTimeout(delayTimer);
|
|
58
|
-
delayTimer = undefined;
|
|
59
|
-
}
|
|
60
|
-
if (minWaitTimer !== undefined) {
|
|
61
|
-
clearTimeout(minWaitTimer);
|
|
62
|
-
minWaitTimer = undefined;
|
|
63
|
-
}
|
|
64
|
-
if (doneTimer !== undefined) {
|
|
65
|
-
clearTimeout(doneTimer);
|
|
66
|
-
doneTimer = undefined;
|
|
67
|
-
}
|
|
147
|
+
const cfg: LoadingFeedbackConfig = {
|
|
148
|
+
delayMs: resolveMs(opts.delayMs, KIT_LOADING_GATE_DEFAULTS.delayMs),
|
|
149
|
+
minVisibleMs: resolveMs(opts.minDurationMs, KIT_LOADING_GATE_DEFAULTS.minDurationMs),
|
|
150
|
+
doneHoldMs: resolveMs(opts.doneHoldMs, KIT_LOADING_GATE_DEFAULTS.doneHoldMs),
|
|
68
151
|
};
|
|
69
152
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
currentPhase = next;
|
|
73
|
-
notify?.(next);
|
|
74
|
-
};
|
|
153
|
+
let state: LoadingFeedbackState = LOADING_FEEDBACK_IDLE;
|
|
154
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
75
155
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
156
|
+
const clearTimer = (): void => {
|
|
157
|
+
if (timer !== undefined) {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
timer = undefined;
|
|
160
|
+
}
|
|
80
161
|
};
|
|
81
162
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
163
|
+
const apply = (event: LoadingFeedbackEvent): void => {
|
|
164
|
+
const now = Date.now();
|
|
165
|
+
const before = state.phase;
|
|
166
|
+
const step = stepLoadingFeedback(state, event, now, cfg);
|
|
167
|
+
state = step.state;
|
|
168
|
+
clearTimer();
|
|
169
|
+
if (step.wakeAt !== null) {
|
|
170
|
+
timer = setTimeout(() => {
|
|
171
|
+
timer = undefined;
|
|
172
|
+
apply({ type: 'tick' });
|
|
173
|
+
}, Math.max(0, step.wakeAt - now));
|
|
87
174
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
doneTimer = undefined;
|
|
91
|
-
setPhase('idle');
|
|
92
|
-
}, doneHoldMs);
|
|
175
|
+
// 一次推进可能连跨几个阶段(如 visible → done → idle);对外只报最终阶段的变化
|
|
176
|
+
if (state.phase !== before) notify?.(state.phase);
|
|
93
177
|
};
|
|
94
178
|
|
|
95
179
|
return {
|
|
96
|
-
start() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
setPhase('pending-delay');
|
|
103
|
-
delayTimer = setTimeout(enterVisible, delayMs);
|
|
104
|
-
},
|
|
105
|
-
finish() {
|
|
106
|
-
if (currentPhase === 'idle' || currentPhase === 'done') return;
|
|
107
|
-
if (currentPhase === 'pending-delay') {
|
|
108
|
-
clearTimers();
|
|
109
|
-
setPhase('idle');
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
// currentPhase === 'visible'
|
|
113
|
-
if (minWaitTimer !== undefined) return;
|
|
114
|
-
const elapsed = Math.max(0, Date.now() - visibleAt);
|
|
115
|
-
const remainMin = Math.max(0, minDurationMs - elapsed);
|
|
116
|
-
if (remainMin > 0) {
|
|
117
|
-
minWaitTimer = setTimeout(enterDone, remainMin);
|
|
118
|
-
} else {
|
|
119
|
-
enterDone();
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
cancel() {
|
|
123
|
-
clearTimers();
|
|
124
|
-
setPhase('idle');
|
|
125
|
-
},
|
|
126
|
-
phase() {
|
|
127
|
-
return currentPhase;
|
|
128
|
-
},
|
|
129
|
-
isVisible() {
|
|
130
|
-
return currentPhase === 'visible';
|
|
131
|
-
},
|
|
180
|
+
start: () => apply({ type: 'start' }),
|
|
181
|
+
finish: () => apply({ type: 'finish' }),
|
|
182
|
+
cancel: () => apply({ type: 'cancel' }),
|
|
183
|
+
phase: () => state.phase,
|
|
184
|
+
isVisible: () => state.phase === 'visible',
|
|
132
185
|
};
|
|
133
186
|
}
|
package/src/base/mentions.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
cssEscape, createListNav, onOutsidePress, optionClass, scrollIntoViewIfAny,
|
|
18
18
|
} from './popup';
|
|
19
19
|
import {
|
|
20
|
-
CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP,
|
|
20
|
+
CLASS_PROP, ID_PROPS, INVALID_PROPS, OPTIONS_PROP, SIZE_PROP,
|
|
21
21
|
applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, nextUid, num, optionsOf, setAttr, setBoolAttr, sizeOf, str,
|
|
22
22
|
type KitOption, type KitProps, type KitSize,
|
|
23
23
|
} from './shared';
|
|
@@ -108,6 +108,7 @@ export function createMentions(): SomaComponentDefinition {
|
|
|
108
108
|
disabled: { type: 'boolean', default: false },
|
|
109
109
|
readonly: { type: 'boolean', default: false },
|
|
110
110
|
...ID_PROPS,
|
|
111
|
+
...INVALID_PROPS,
|
|
111
112
|
size: SIZE_PROP,
|
|
112
113
|
class: CLASS_PROP,
|
|
113
114
|
},
|
package/src/base/menu-button.ts
CHANGED
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
6
6
|
import { kitText } from '../i18n/kit-text';
|
|
7
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
7
8
|
import { kitIconHtml } from './icons';
|
|
8
9
|
import {
|
|
9
10
|
CLASS_PROP, ID_PROPS, SIZE_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES,
|
|
10
11
|
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setBoolAttr, sizeOf, str, withBadgeAnchor, withTooltip,
|
|
11
12
|
type KitSize, type KitView,
|
|
12
13
|
} from './shared';
|
|
13
|
-
import { setKitFace } from '../recipes';
|
|
14
|
+
import { kitTypographyRecipe, setKitFace } from '../recipes';
|
|
15
|
+
import { kitButtonNoWrapMap } from '../recipes/nowrap';
|
|
16
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
14
17
|
import { menuItemsOf, wireMenu, type MenuClasses, type MenuHandle } from './menu-core';
|
|
15
18
|
import { KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, popPlaceClass, type PopPlace } from './popup';
|
|
16
19
|
import {
|
|
@@ -22,25 +25,31 @@ const ROOT_CONTEXT_CLASS = 'relative block';
|
|
|
22
25
|
export type MenuButtonVariant = 'primary' | 'neutral' | 'ghost';
|
|
23
26
|
|
|
24
27
|
const ROOT_CLASS = 'relative inline-block';
|
|
25
|
-
const
|
|
28
|
+
const TRIGGER_CLASS_RAW: Record<MenuButtonVariant, Record<KitSize, string>> = {
|
|
26
29
|
primary: {
|
|
27
|
-
sm: 'inline-flex h-
|
|
28
|
-
md: 'inline-flex h-
|
|
30
|
+
sm: 'inline-flex h-6 items-center justify-center gap-1 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',
|
|
31
|
+
md: 'inline-flex h-8 items-center justify-center gap-2 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',
|
|
29
32
|
lg: 'inline-flex h-10 items-center justify-center gap-2 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',
|
|
30
33
|
},
|
|
31
34
|
neutral: {
|
|
32
|
-
sm: 'inline-flex h-
|
|
33
|
-
md: 'inline-flex h-
|
|
34
|
-
lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md border border-
|
|
35
|
+
sm: 'inline-flex h-6 items-center justify-center gap-1 rounded-md border border-button-edge bg-surface px-3 text-sm 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',
|
|
36
|
+
md: 'inline-flex h-8 items-center justify-center gap-2 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 disabled:cursor-not-allowed disabled:opacity-60',
|
|
37
|
+
lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md border border-button-edge bg-surface px-5 text-base 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',
|
|
35
38
|
},
|
|
36
39
|
ghost: {
|
|
37
|
-
sm: 'inline-flex h-
|
|
38
|
-
md: 'inline-flex h-
|
|
39
|
-
lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md px-5 text-base font-medium text-fg transition-colors enabled:hover:bg-
|
|
40
|
+
sm: 'inline-flex h-6 items-center justify-center gap-1 rounded-md px-3 text-sm font-medium text-fg transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
41
|
+
md: 'inline-flex h-8 items-center justify-center gap-2 rounded-md px-4 text-sm font-medium text-fg transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
42
|
+
lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md px-5 text-base font-medium text-fg transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
40
43
|
},
|
|
41
44
|
};
|
|
45
|
+
// 触发钮文案单行(「更多」「操作」等不逐字折行)
|
|
46
|
+
const TRIGGER_CLASS: Record<MenuButtonVariant, Record<KitSize, string>> = {
|
|
47
|
+
primary: kitButtonNoWrapMap(TRIGGER_CLASS_RAW.primary),
|
|
48
|
+
neutral: kitButtonNoWrapMap(TRIGGER_CLASS_RAW.neutral),
|
|
49
|
+
ghost: kitButtonNoWrapMap(TRIGGER_CLASS_RAW.ghost),
|
|
50
|
+
};
|
|
42
51
|
const MENU_HIDDEN = 'hidden';
|
|
43
|
-
const MENU_BASE = 'absolute z-10 flex min-w-40 flex-col
|
|
52
|
+
const MENU_BASE = mergeClass('absolute z-10 flex min-w-40 flex-col p-1', kitSurfaceRecipe('raised'));
|
|
44
53
|
/** 默认偏好:触发钮下方、左对齐;贴边时由 popup.ts 在闭集位置间翻转 */
|
|
45
54
|
const MENU_PREF: PopPlace = { side: 'bottom', align: 'start' };
|
|
46
55
|
const menuClass = (place: PopPlace): string => `${MENU_BASE} ${popPlaceClass(place, 1)}`;
|
|
@@ -53,11 +62,13 @@ export const KIT_MENU_PANEL = {
|
|
|
53
62
|
ghostTrigger: (): string => TRIGGER_CLASS.ghost.sm,
|
|
54
63
|
} as const;
|
|
55
64
|
export const KIT_MENU_ITEM_CLASSES: MenuClasses = {
|
|
56
|
-
idle: 'flex cursor-pointer h-9 items-center gap-2 rounded-md px-3 text-sm text-fg transition-colors hover:bg-
|
|
65
|
+
idle: 'flex cursor-pointer h-9 items-center gap-2 rounded-md px-3 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:bg-state-layer-hover focus-visible:outline-none',
|
|
57
66
|
danger: 'flex cursor-pointer h-9 items-center gap-2 rounded-md px-3 text-sm text-danger-on-soft transition-colors hover:bg-danger-soft focus-visible:bg-danger-soft focus-visible:outline-none',
|
|
58
67
|
disabled: 'flex cursor-not-allowed h-9 items-center gap-2 rounded-md px-3 text-sm text-fg-subtle opacity-60',
|
|
59
68
|
divider: 'my-1 h-px bg-border-subtle',
|
|
60
69
|
icon: 'inline-block shrink-0',
|
|
70
|
+
// 置灰项的原因描述(行内第二段文字,贴右、弱色小字)
|
|
71
|
+
desc: mergeClass(kitTypographyRecipe('caption'), 'ms-auto ps-3'),
|
|
61
72
|
};
|
|
62
73
|
const MENU_CLASSES = KIT_MENU_ITEM_CLASSES;
|
|
63
74
|
const CARET_CLASS = 'inline-flex';
|
package/src/base/menu-core.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
11
11
|
import { createListNav, createPanelPortal, onOutsidePress, showMenuAtPoint, showPopupFitted, type ListNav, type PopPlace } from './popup';
|
|
12
12
|
import type { PointPanel } from './portal-core';
|
|
13
|
+
import { KIT_ANCHORED_ATTR, leaveAnchored, unmarkAnchored } from './anchored-layer';
|
|
14
|
+
import type { KitLeaveHandle } from './overlay-runtime';
|
|
13
15
|
import { nextUid } from './shared';
|
|
14
16
|
import { setKitFace, type KitFaceKind } from '../recipes';
|
|
15
17
|
|
|
@@ -26,6 +28,8 @@ export interface MenuItemSpec {
|
|
|
26
28
|
danger: boolean;
|
|
27
29
|
/** 分隔线(此时只有 key 有意义) */
|
|
28
30
|
divider: boolean;
|
|
31
|
+
/** 置灰原因(只对 disabled 项有意义):项里多一段可见的描述文字,项带 aria-describedby 指向它;空 / 缺省不画 */
|
|
32
|
+
reason?: string;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
/** 菜单项归一:`[{ key, label, icon?, disabled?, danger?, divider? }]`;key 重复的第二项起丢弃,分隔线不要求 label */
|
|
@@ -63,6 +67,8 @@ export interface MenuClasses {
|
|
|
63
67
|
disabled: string;
|
|
64
68
|
divider: string;
|
|
65
69
|
icon: string;
|
|
70
|
+
/** 置灰原因描述文字的类(项带 reason 时用;缺省不加类) */
|
|
71
|
+
desc?: string;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
/** 面板挂载端口(实现见 data/overlay-portal 的 createPanelPortal;这里只认形状,base 不依赖 data) */
|
|
@@ -125,6 +131,18 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
125
131
|
const portal: MenuPortal = o.portal ?? createPanelPortal(trigger);
|
|
126
132
|
let open = false;
|
|
127
133
|
let pointPanel: PointPanel | null = null;
|
|
134
|
+
// 出场(隐藏前过渡,与其他锚定浮层同一机制):播完退场动画再放回原位 / 整串 hidden;没有退场动画则立即收尾
|
|
135
|
+
let leaving: KitLeaveHandle | null = null;
|
|
136
|
+
const finishHide = (): void => {
|
|
137
|
+
leaving = null;
|
|
138
|
+
portal.hide(true);
|
|
139
|
+
if (pointPanel !== null) {
|
|
140
|
+
pointPanel.hide(true);
|
|
141
|
+
pointPanel = null;
|
|
142
|
+
}
|
|
143
|
+
menu.className = o.hiddenClass;
|
|
144
|
+
unmarkAnchored(menu);
|
|
145
|
+
};
|
|
128
146
|
let cursor: string | null = null;
|
|
129
147
|
let builtKey = '';
|
|
130
148
|
const menuId = menu.id !== '' ? menu.id : nextUid('kit-menu');
|
|
@@ -166,6 +184,15 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
166
184
|
const label = document.createElement('span');
|
|
167
185
|
label.textContent = item.label;
|
|
168
186
|
row.appendChild(label);
|
|
187
|
+
const reason = item.disabled && item.reason !== undefined ? item.reason.trim() : '';
|
|
188
|
+
if (reason !== '') {
|
|
189
|
+
const desc = document.createElement('span');
|
|
190
|
+
desc.id = nextUid('kit-menu-reason');
|
|
191
|
+
if (o.classes.desc !== undefined) desc.className = o.classes.desc;
|
|
192
|
+
desc.textContent = reason;
|
|
193
|
+
row.appendChild(desc);
|
|
194
|
+
row.setAttribute('aria-describedby', desc.id);
|
|
195
|
+
}
|
|
169
196
|
menu.appendChild(row);
|
|
170
197
|
}
|
|
171
198
|
};
|
|
@@ -181,6 +208,11 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
181
208
|
if (item.disabled) el.setAttribute('aria-disabled', 'true');
|
|
182
209
|
else el.removeAttribute('aria-disabled');
|
|
183
210
|
}
|
|
211
|
+
// 退场中被重新打开:撤销退场
|
|
212
|
+
if (open && leaving !== null) {
|
|
213
|
+
leaving.cancel();
|
|
214
|
+
leaving = null;
|
|
215
|
+
}
|
|
184
216
|
const pt = open ? (o.point?.() ?? null) : null;
|
|
185
217
|
const fit = open && pt === null ? (o.fitted?.() ?? null) : null;
|
|
186
218
|
if (pt !== null) {
|
|
@@ -199,16 +231,11 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
199
231
|
} else if (fit !== null) {
|
|
200
232
|
const placed = portal.show(menu, trigger, fit.pref, fit.classFor, { ...(fit.gapPx !== undefined ? { gapPx: fit.gapPx } : {}), onEscape: () => close(true) });
|
|
201
233
|
if (placed === null) showPopupFitted(menu, trigger, fit.pref, fit.classFor, fit.gapPx);
|
|
234
|
+
} else if (!open) {
|
|
235
|
+
if (leaving === null) leaving = menu.hasAttribute(KIT_ANCHORED_ATTR) ? leaveAnchored(menu, finishHide) : (finishHide(), null);
|
|
202
236
|
} else {
|
|
203
|
-
if (!open) {
|
|
204
|
-
portal.hide(true);
|
|
205
|
-
if (pointPanel !== null) {
|
|
206
|
-
pointPanel.hide(true);
|
|
207
|
-
pointPanel = null;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
237
|
const shown = typeof o.shownClass === 'function' ? o.shownClass() : o.shownClass;
|
|
211
|
-
menu.className =
|
|
238
|
+
menu.className = shown;
|
|
212
239
|
}
|
|
213
240
|
trigger.setAttribute('aria-haspopup', 'menu');
|
|
214
241
|
trigger.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
@@ -337,6 +364,8 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
337
364
|
scope.removeEventListener('focusout', onFocusOut);
|
|
338
365
|
menu.removeEventListener('focusout', onFocusOut);
|
|
339
366
|
offOutside();
|
|
367
|
+
leaving?.cancel();
|
|
368
|
+
leaving = null;
|
|
340
369
|
portal.hide(true);
|
|
341
370
|
pointPanel?.hide(true);
|
|
342
371
|
pointPanel = null;
|
|
@@ -14,7 +14,7 @@ import { safeHref } from '../link';
|
|
|
14
14
|
import { HOVER_3D_GRID, MOTION_STRENGTHS, prefersReducedMotion, segmentOf, strengthOf, type MotionStrength } from './limits';
|
|
15
15
|
|
|
16
16
|
const ROOT_CLASS = 'block perspective-normal';
|
|
17
|
-
const CARD_CORE = 'block overflow-hidden rounded-lg border border-border-subtle bg-surface text-fg
|
|
17
|
+
const CARD_CORE = 'block overflow-hidden rounded-lg border border-border-subtle bg-surface text-fg motion-safe:transition-transform focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
18
18
|
const CARD_IDLE = `${CARD_CORE} shadow-sm`;
|
|
19
19
|
const CARD_TILTED = `${CARD_CORE} shadow-md`;
|
|
20
20
|
const IMAGE_CLASS = 'block h-40 w-full object-cover';
|
|
@@ -31,7 +31,7 @@ const TRACK_PAUSED: Record<Speed, string> = {
|
|
|
31
31
|
};
|
|
32
32
|
const GROUP_SCROLL = 'flex shrink-0 items-center gap-8 pe-8 whitespace-nowrap';
|
|
33
33
|
const GROUP_STATIC = 'flex flex-wrap items-center gap-x-6 gap-y-1';
|
|
34
|
-
const PAUSE_CLASS = 'inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-xs text-fg-muted transition-colors hover:bg-
|
|
34
|
+
const PAUSE_CLASS = 'inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md 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';
|
|
35
35
|
const HIDDEN = 'hidden';
|
|
36
36
|
|
|
37
37
|
/** 本组件自带的类 */
|