soma-kit 0.1.13 → 0.1.15
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/package.json +3 -3
- package/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- package/spec/generated/kit-app.schema.json +18 -2
- package/spec/generated/kit-page.schema.json +95 -0
- package/spec/kit-grammar.json +332 -75
- package/spec/kit-grammar.schema.json +1 -27
- package/src/app/app-config.ts +11 -5
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +82 -10
- package/src/app/define-kit-app.ts +6 -5
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +20 -8
- package/src/app/kit-view-context.ts +30 -4
- package/src/app/server-pages.ts +5 -1
- package/src/app/server.ts +15 -5
- package/src/app/theme-endpoint.ts +1 -1
- package/src/app/theme-runtime.ts +7 -2
- package/src/base/alert.ts +23 -20
- package/src/base/anchored-layer.ts +1 -1
- package/src/base/button.ts +34 -17
- package/src/base/cascader.ts +8 -4
- package/src/base/check-core.ts +9 -6
- package/src/base/color-picker.ts +10 -6
- package/src/base/command-palette.ts +10 -4
- package/src/base/context-menu.ts +5 -2
- package/src/base/date-range.ts +9 -6
- package/src/base/date.ts +10 -6
- package/src/base/delta.ts +4 -2
- package/src/base/divider.ts +15 -66
- package/src/base/end-edge.ts +14 -2
- package/src/base/fab.ts +11 -6
- package/src/base/gap-value.ts +25 -5
- package/src/base/hint-tips.ts +1 -1
- package/src/base/illustrations.ts +2 -1
- package/src/base/index.ts +20 -4
- package/src/base/inline-error.ts +84 -0
- package/src/base/input.ts +54 -18
- package/src/base/kbd.ts +4 -3
- package/src/base/link.ts +1 -1
- package/src/base/listbox-core.ts +70 -22
- package/src/base/mentions.ts +6 -3
- package/src/base/menu-button.ts +73 -50
- package/src/base/menu-core.ts +9 -2
- package/src/base/motion/hover-3d.ts +4 -1
- package/src/base/motion/hover-gallery.ts +4 -1
- package/src/base/otp.ts +7 -3
- package/src/base/overlay-runtime.ts +3 -2
- package/src/base/overlay-shell.ts +141 -0
- package/src/base/popover.ts +7 -6
- package/src/base/popup.ts +47 -41
- package/src/base/qty-stepper.ts +14 -9
- package/src/base/reason-tip.ts +2 -2
- package/src/{frames → base}/resize-handle.ts +1 -1
- package/src/base/segmented.ts +44 -35
- package/src/base/select.ts +1 -0
- package/src/base/shared.ts +52 -18
- package/src/base/state-panel.ts +34 -13
- package/src/base/status-tone.ts +1 -1
- package/src/base/tag-input.ts +13 -8
- package/src/base/tag.ts +56 -57
- package/src/base/text.ts +38 -14
- package/src/base/textarea.ts +1 -1
- package/src/base/time-picker.ts +9 -5
- package/src/base/tree-select.ts +12 -9
- package/src/base/upload.ts +26 -17
- package/src/biz/approval-desk/compile.ts +28 -1
- package/src/biz/approval-desk/shell.ts +10 -9
- package/src/biz/auth-panel/compile.ts +1 -1
- package/src/biz/auth-panel/shell.ts +7 -6
- package/src/biz/category-crud/compile.ts +20 -6
- package/src/biz/category-crud/shell.ts +10 -7
- package/src/biz/checkout-page/compile.ts +1 -1
- package/src/biz/checkout-page/shell.ts +15 -13
- package/src/biz/compose.ts +5 -5
- package/src/biz/data-components.ts +4 -0
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +1 -1
- package/src/biz/import-wizard/shell.ts +17 -13
- package/src/biz/index.ts +4 -3
- package/src/biz/landing-page/compile.ts +1 -1
- package/src/biz/landing-page/shell.ts +6 -5
- package/src/biz/link/shared.ts +8 -1
- package/src/biz/master-sub/compile.ts +269 -27
- package/src/biz/master-sub/detail-head.ts +62 -0
- package/src/biz/master-sub/index.ts +5 -4
- package/src/biz/master-sub/shell.ts +138 -69
- package/src/biz/multi-board/compile.ts +166 -11
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +25 -10
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +96 -24
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +9 -2
- package/src/biz/notification-center/shell.ts +15 -7
- package/src/biz/page-templates/domain-templates.ts +7 -3
- package/src/biz/page-templates/result-page/compile.ts +1 -1
- package/src/biz/page-templates/result-page/shell.ts +5 -4
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +18 -18
- package/src/biz/record-detail/compile.ts +5 -2
- package/src/biz/record-detail/shell.ts +12 -11
- package/src/biz/settings-center/compile.ts +1 -1
- package/src/biz/settings-center/shell.ts +14 -10
- package/src/biz/shared/action-host.ts +12 -5
- package/src/biz/shared/compile-helpers.ts +83 -4
- package/src/biz/shared/coordinator.ts +104 -21
- package/src/biz/shared/overlay-compile.ts +76 -4
- package/src/biz/shared/overlay-shell.ts +65 -112
- package/src/biz/single-form/compile.ts +2 -2
- package/src/biz/single-form/shell.ts +13 -7
- package/src/biz/standard-crud/compile.ts +24 -4
- package/src/biz/standard-crud/shell.ts +38 -30
- package/src/biz/standard-crud/summary.ts +42 -0
- package/src/biz/step-form/compile.ts +1 -1
- package/src/biz/step-form/hub.ts +4 -0
- package/src/biz/step-form/shell.ts +16 -12
- package/src/biz/types.ts +15 -3
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +35 -8
- package/src/cli/kit-init.ts +149 -0
- package/src/cli/layout-cli.ts +7 -7
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/compile-page.ts +36 -230
- package/src/compile/component-candidates.ts +4 -1
- package/src/compile/hints.ts +5 -58
- package/src/compile/index.ts +2 -2
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +97 -18
- package/src/compile/layout-lint/rules-form.ts +6 -7
- package/src/compile/layout-lint/rules-table.ts +98 -14
- package/src/compile/page-composition.ts +191 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/redirect.ts +1 -1
- package/src/compile/stages.ts +169 -0
- package/src/compile/styles.ts +80 -32
- package/src/compile/types.ts +5 -3
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +6 -2
- package/src/data/anchor-nav.ts +4 -1
- package/src/data/approval-flow.ts +13 -5
- package/src/data/assignment-picker.ts +35 -20
- package/src/data/async-result-panel.ts +7 -3
- package/src/data/breadcrumbs.ts +13 -9
- package/src/data/calendar.ts +10 -4
- package/src/data/carousel.ts +13 -5
- package/src/data/chart.ts +745 -48
- package/src/data/checklist.ts +9 -5
- package/src/data/code-view.ts +220 -26
- package/src/data/comment-thread.ts +9 -3
- package/src/data/confirm-dialog.ts +57 -20
- package/src/data/diff.ts +4 -1
- package/src/data/dock.ts +5 -1
- package/src/data/embed.ts +1 -1
- package/src/data/engine-ports.ts +126 -0
- package/src/data/field-mapper.ts +16 -7
- package/src/data/flow-editor.ts +106 -29
- package/src/data/footer.ts +8 -2
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +8 -2
- package/src/data/image-viewer.ts +7 -3
- package/src/data/index.ts +22 -8
- package/src/data/item-list.ts +11 -3
- package/src/data/json-view.ts +844 -0
- package/src/data/kanban.ts +13 -8
- package/src/data/markdown-view.ts +487 -0
- package/src/data/matrix.ts +400 -0
- package/src/data/media-grid.ts +5 -2
- package/src/data/mega-menu.ts +4 -3
- package/src/data/menu-dom.ts +9 -8
- package/src/data/menu.ts +35 -17
- package/src/data/mockup.ts +12 -8
- package/src/data/modal-dialog.ts +108 -57
- package/src/data/navbar.ts +13 -7
- package/src/data/notice-list.ts +53 -20
- package/src/data/notify-renderer.ts +21 -10
- package/src/data/object-form.ts +248 -151
- package/src/data/pager.ts +15 -10
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +19 -9
- package/src/data/permission-tree.ts +30 -13
- package/src/data/pricing-table.ts +10 -4
- package/src/data/reaction-bar.ts +6 -3
- package/src/data/record-card.ts +30 -14
- package/src/data/record-picker.ts +8 -4
- package/src/data/redirect.ts +1 -1
- package/src/data/request-console.ts +20 -7
- package/src/data/resident.ts +6 -10
- package/src/data/result-panel.ts +2 -2
- package/src/data/rich-text.ts +58 -96
- package/src/data/row-editor.ts +12 -7
- package/src/data/rule-builder.ts +22 -11
- package/src/data/shape-util.ts +26 -14
- package/src/data/stat-group.ts +369 -84
- package/src/data/static-lazy.ts +7 -0
- package/src/data/static-registry.ts +14 -2
- package/src/data/steps.ts +6 -2
- package/src/data/survey.ts +13 -4
- package/src/data/system-switcher.ts +17 -7
- package/src/data/text-diff.ts +663 -0
- package/src/data/timeline.ts +1 -1
- package/src/data/tour-guide.ts +8 -4
- package/src/data/transfer.ts +24 -11
- package/src/data/tree-table.ts +84 -17
- package/src/data/tree.ts +6 -3
- package/src/data/virtual-rows.ts +22 -11
- package/src/data/wrap.ts +2 -2
- package/src/data/wrapped-candidates.ts +22 -1
- package/src/frames/index.ts +4 -2
- package/src/frames/inherited-shell.ts +178 -0
- package/src/frames/list-summary.ts +123 -0
- package/src/frames/page-bar.ts +10 -16
- package/src/frames/resident-components.ts +20 -0
- package/src/frames/shared.ts +37 -17
- package/src/frames/split-frame/shell.ts +17 -11
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +17 -9
- package/src/frames/top-main-frame.ts +1 -1
- package/src/frames/types.ts +6 -3
- package/src/frames/workspace-frame/extras.ts +19 -5
- package/src/frames/workspace-frame/shell.ts +4 -3
- package/src/frames/workspace-frame/state.ts +8 -2
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +156 -91
- package/src/generated/kit-grammar-runtime.ts +227 -58
- package/src/i18n/kit-text.ts +141 -2
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +169 -0
- package/src/object-renderer/action-more.ts +160 -0
- package/src/object-renderer/arrange.ts +86 -26
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +72 -20
- package/src/object-renderer/collection-table.ts +178 -65
- package/src/object-renderer/collection.ts +129 -83
- package/src/object-renderer/compile-data.ts +1 -1
- package/src/object-renderer/defaults.ts +10 -5
- package/src/object-renderer/emit-events.ts +1 -1
- package/src/object-renderer/emit-object.ts +7 -0
- package/src/object-renderer/emit-static.ts +243 -87
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/filter-toolbar.ts +103 -0
- package/src/{compile → object-renderer}/fragment.ts +13 -2
- package/src/object-renderer/index.ts +6 -1
- package/src/object-renderer/layout-facts.ts +46 -6
- package/src/object-renderer/layout-plan.ts +136 -43
- package/src/object-renderer/layout-plan.types.ts +42 -5
- package/src/object-renderer/overlay-decide.ts +82 -0
- package/src/object-renderer/parts.ts +7 -259
- package/src/object-renderer/render-object.ts +60 -47
- package/src/object-renderer/table-actions.ts +135 -56
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +63 -25
- package/src/object-renderer/types.ts +16 -22
- package/src/recipes/app-blocks.ts +66 -0
- package/src/recipes/code-view.ts +56 -0
- package/src/recipes/compact-group.ts +31 -0
- package/src/recipes/container.ts +54 -13
- package/src/recipes/control.ts +77 -157
- package/src/recipes/desc-list.ts +14 -0
- package/src/recipes/divider.ts +53 -0
- package/src/recipes/emphasis.ts +60 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +34 -1
- package/src/recipes/inherited-shell.ts +37 -0
- package/src/recipes/json-view.ts +49 -0
- package/src/recipes/markdown.ts +86 -0
- package/src/recipes/overlay.ts +149 -18
- package/src/recipes/page-width.ts +20 -0
- package/src/recipes/placeholder.ts +21 -5
- package/src/recipes/rail-grid.ts +3 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +20 -28
- package/src/recipes/status.ts +17 -8
- package/src/recipes/strip.ts +72 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +10 -6
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +120 -11
- package/src/recipes/tabs.ts +126 -0
- package/src/recipes/text-diff.ts +90 -0
- package/src/recipes/title-row.ts +7 -5
- package/src/recipes/typography.ts +24 -43
- package/src/shared/diagnostics.ts +16 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-value-format.ts +246 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +12 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- package/src/shared/path-guard.ts +1 -1
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/theme-runtime-shared.ts +19 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +49 -14
- package/src/theme/kit-theme.tpl +49 -14
- package/src/theme/nine-dim-structure.ts +129 -37
- package/src/theme/surface-layers.ts +17 -4
- package/src/theme/theme-tokens.ts +16 -5
- package/src/theme/typography.ts +21 -17
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- /package/src/{base → shared}/class-candidates.ts +0 -0
package/src/base/listbox-core.ts
CHANGED
|
@@ -20,12 +20,15 @@ import {
|
|
|
20
20
|
type KitApi, type KitOption, type KitProps, type KitSize, type KitView, type KitViewSetup,
|
|
21
21
|
} from './shared';
|
|
22
22
|
import { setKitFace } from '../recipes';
|
|
23
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
24
|
+
import { kitFocusRingRecipe } from '../recipes/state';
|
|
25
|
+
import { mergeClass } from '../shared/merge-class';
|
|
23
26
|
import {
|
|
24
27
|
KIT_VIRTUAL_CLASS_CANDIDATES, KIT_VIRTUAL_OPTION_ROW_CLASS, virtualRowPx, createVirtualWindow, paintVirtualRows, rowTierOf, withoutPy,
|
|
25
28
|
type VirtualWindow,
|
|
26
29
|
} from './virtual-list';
|
|
27
30
|
import { kitText } from '../i18n/kit-text';
|
|
28
|
-
import { kitIcon } from '
|
|
31
|
+
import { kitIcon } from '../shared/icons';
|
|
29
32
|
|
|
30
33
|
export type ListboxKind = 'select' | 'combobox';
|
|
31
34
|
|
|
@@ -41,45 +44,69 @@ const CLEAR_PAD_CLASS = 'pe-8';
|
|
|
41
44
|
const CLEAR_PAD_SELECT_CLASS = 'pe-12';
|
|
42
45
|
|
|
43
46
|
// 多选 chips 形态:字段嵌在一个像字段的盒子里,标签与字段同排换行
|
|
47
|
+
// 自绘控件外壳的边只取控件轮廓出口(KT-B1 / §4 C6,与输入框同一条控件线);禁用 / 只读整串不出悬停色
|
|
48
|
+
const EDGE = kitControlEdgeRecipe({ wrapper: true });
|
|
49
|
+
const EDGE_STILL = kitControlEdgeRecipe({ wrapper: true, hover: false });
|
|
44
50
|
export const BOX_CLASS: Record<KitSize, string> = {
|
|
45
|
-
sm:
|
|
46
|
-
md:
|
|
47
|
-
lg:
|
|
51
|
+
sm: `flex min-h-6 w-full flex-wrap items-center gap-1 rounded-md ${EDGE} bg-surface px-2 py-0.5 text-sm text-fg transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring`,
|
|
52
|
+
md: `flex min-h-8 w-full flex-wrap items-center gap-1 rounded-md ${EDGE} bg-surface px-2 py-1 text-sm text-fg transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring`,
|
|
53
|
+
lg: `flex min-h-10 w-full flex-wrap items-center gap-2 rounded-md ${EDGE} bg-surface px-3 py-1 text-base text-fg transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring`,
|
|
48
54
|
};
|
|
49
55
|
export const BOX_OFF_CLASS: Record<KitSize, string> = {
|
|
50
|
-
sm:
|
|
51
|
-
md:
|
|
52
|
-
lg:
|
|
56
|
+
sm: `flex min-h-6 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md ${EDGE_STILL} bg-control-disabled px-2 py-0.5 text-sm text-fg-disabled`,
|
|
57
|
+
md: `flex min-h-8 w-full cursor-not-allowed flex-wrap items-center gap-1 rounded-md ${EDGE_STILL} bg-control-disabled px-2 py-1 text-sm text-fg-disabled`,
|
|
58
|
+
lg: `flex min-h-10 w-full cursor-not-allowed flex-wrap items-center gap-2 rounded-md ${EDGE_STILL} bg-control-disabled px-3 py-1 text-base text-fg-disabled`,
|
|
53
59
|
};
|
|
54
60
|
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';
|
|
55
|
-
|
|
61
|
+
// 已选标签(芯片):浅底、无描边——控件里不再套第二圈线(一处边界一种手段)
|
|
62
|
+
export const CHIP_CLASS = 'inline-flex max-w-full items-center gap-1 rounded-md bg-surface-sunken px-2 py-0.5 text-sm font-medium text-fg-muted';
|
|
56
63
|
export const CHIP_REMOVE_CLASS = 'inline-flex min-h-5 min-w-5 cursor-pointer items-center justify-center rounded-md px-0.5 text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
57
|
-
export const GROUP_TITLE_CLASS = 'sticky top-0 z-10 bg-surface-raised px-
|
|
64
|
+
export const GROUP_TITLE_CLASS = 'sticky top-0 z-10 bg-surface-raised px-3 py-1 text-xs font-medium text-fg-subtle';
|
|
58
65
|
/**
|
|
59
|
-
*
|
|
60
|
-
* popup 底座的 OPTION_CLASS 被多个列表件共用,这里只在下拉列表(Select / Combobox / Cascader 等经 listbox-core 的件)落一次,
|
|
61
|
-
* 不改菜单项(menu-core)的紧凑内边距。
|
|
66
|
+
* 下拉选项的水平内边距 = 触发器(md)的文字内缩 px-3:选项 / 空态行 / 分组标题文字与触发器文字同轴(面板与触发器同宽同左缘,边框同为 1px)。
|
|
62
67
|
*/
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const EMPTY_ROW_WIDE = widenPad(EMPTY_ROW_CLASS);
|
|
68
|
+
const optionClassWide = (selected: boolean, active: boolean, disabled: boolean): string => optionClass(selected, active, disabled);
|
|
69
|
+
const EMPTY_ROW_WIDE = EMPTY_ROW_CLASS;
|
|
66
70
|
export const CHECK_CLASS = 'w-4 shrink-0 text-center';
|
|
71
|
+
/** 单选选中项尾部对勾(KT-K-select-3):主色字随选中项(text-primary-on-soft 由选项类给出),推到行尾 */
|
|
72
|
+
export const CHECK_END_CLASS = 'ms-auto w-4 shrink-0 text-center';
|
|
67
73
|
|
|
68
74
|
const CLEAR_CLASS = 'absolute end-2 top-0 flex h-full cursor-pointer items-center px-1 text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
69
75
|
const CLEAR_SELECT_CLASS = 'absolute end-7 top-0 flex h-full cursor-pointer items-center px-1 text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
70
76
|
const CLEAR_HIDDEN_CLASS = 'hidden';
|
|
71
77
|
|
|
72
78
|
// select-only 字段(可聚焦的 div):状态整串换,不依赖原生 enabled: / read-only: 变体
|
|
73
|
-
|
|
79
|
+
// 焦点 = 输入类焦点出口(KT-K0-3 / KT-K-select-1:主色边 + 2px 外环 + 外晕,与输入框同一出口)
|
|
80
|
+
const SEL_FIELD_BASE = mergeClass('flex w-full items-center justify-between gap-2 rounded-md text-start transition-colors aria-invalid:border-danger', kitFocusRingRecipe('control'));
|
|
74
81
|
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
82
|
const selFieldClasses = (tone: string): Record<KitSize, string> => ({
|
|
76
83
|
sm: `${SEL_FIELD_BASE} ${SEL_FIELD_SIZE.sm} ${tone}`,
|
|
77
84
|
md: `${SEL_FIELD_BASE} ${SEL_FIELD_SIZE.md} ${tone}`,
|
|
78
85
|
lg: `${SEL_FIELD_BASE} ${SEL_FIELD_SIZE.lg} ${tone}`,
|
|
79
86
|
});
|
|
80
|
-
|
|
81
|
-
export const
|
|
82
|
-
|
|
87
|
+
// 触发器是自带实底的可点控件:悬停 / 按下各一级用 state-layer 叠层(KT-K0-2;控件边的悬停色与静止色同值,单靠边看不出悬停)
|
|
88
|
+
export const SELECT_FIELD_CLASS = selFieldClasses(`cursor-pointer bg-surface text-fg state-layer ${EDGE}`);
|
|
89
|
+
// 禁用 = 专用令牌(KT-K0-4 第 1 点,二-6),不整体降透明度
|
|
90
|
+
export const SELECT_FIELD_OFF_CLASS = selFieldClasses(`cursor-not-allowed bg-control-disabled text-fg-disabled ${EDGE_STILL}`);
|
|
91
|
+
export const SELECT_FIELD_RO_CLASS = selFieldClasses(`cursor-default bg-surface-sunken text-fg ${EDGE_STILL}`);
|
|
92
|
+
// filled 变体(筛选工具条与 Input variant: filled 同材质:浅底无框、悬停出边、聚焦回白面)
|
|
93
|
+
const EDGE_FILLED = kitControlEdgeRecipe({ variant: 'filled', wrapper: true });
|
|
94
|
+
const EDGE_FILLED_STILL = kitControlEdgeRecipe({ variant: 'filled', wrapper: true, hover: false });
|
|
95
|
+
const SEL_FILLED_BASE = 'flex w-full items-center justify-between gap-2 rounded-md text-start transition-colors focus-visible:outline-none focus-visible:border-primary focus-visible:bg-surface focus-visible:ring-2 focus-visible:ring-ring aria-invalid:border-danger';
|
|
96
|
+
const selFilledClasses = (tone: string): Record<KitSize, string> => ({
|
|
97
|
+
sm: `${SEL_FILLED_BASE} ${SEL_FIELD_SIZE.sm} ${tone}`,
|
|
98
|
+
md: `${SEL_FILLED_BASE} ${SEL_FIELD_SIZE.md} ${tone}`,
|
|
99
|
+
lg: `${SEL_FILLED_BASE} ${SEL_FIELD_SIZE.lg} ${tone}`,
|
|
100
|
+
});
|
|
101
|
+
export const SELECT_FIELD_FILLED_CLASS = selFilledClasses(`cursor-pointer bg-surface-well text-fg ${EDGE_FILLED}`);
|
|
102
|
+
export const SELECT_FIELD_FILLED_OFF_CLASS = selFilledClasses(`cursor-not-allowed bg-control-disabled text-fg-disabled ${EDGE_FILLED_STILL}`);
|
|
103
|
+
export const SELECT_FIELD_FILLED_RO_CLASS = selFilledClasses(`cursor-default bg-surface-well text-fg ${EDGE_FILLED_STILL}`);
|
|
104
|
+
const FIELD_FILLED_BASE = `block w-full rounded-md ${EDGE_FILLED} bg-surface-well text-fg placeholder:text-fg-subtle transition-colors focus-visible:outline-none focus-visible:border-primary focus-visible:bg-surface focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60 aria-invalid:border-danger`;
|
|
105
|
+
const FIELD_FILLED_CLASS: Record<KitSize, string> = {
|
|
106
|
+
sm: `${FIELD_FILLED_BASE} ${SEL_FIELD_SIZE.sm}`,
|
|
107
|
+
md: `${FIELD_FILLED_BASE} ${SEL_FIELD_SIZE.md}`,
|
|
108
|
+
lg: `${FIELD_FILLED_BASE} ${SEL_FIELD_SIZE.lg}`,
|
|
109
|
+
};
|
|
83
110
|
const SEL_CHIPS_FIELD_CLASS = 'min-w-8 flex-1 cursor-pointer px-1 py-0.5 text-sm focus-visible:outline-none';
|
|
84
111
|
const SEL_CHIPS_FIELD_OFF_CLASS = 'min-w-8 flex-1 cursor-not-allowed px-1 py-0.5 text-sm focus-visible:outline-none';
|
|
85
112
|
const SEL_CHIPS_FIELD_RO_CLASS = 'min-w-8 flex-1 cursor-default px-1 py-0.5 text-sm focus-visible:outline-none';
|
|
@@ -93,9 +120,11 @@ const SEL_CHEVRON_CLASS = 'inline-flex shrink-0 text-fg-subtle motion-safe:trans
|
|
|
93
120
|
export const KIT_LISTBOX_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
94
121
|
WRAP_CLASS, WRAP_FULL_CLASS, STATUS_CLASS, ICON_CLASS, LABEL_CLASS, DESC_CLASS, CLEAR_PAD_CLASS, CLEAR_PAD_SELECT_CLASS,
|
|
95
122
|
Object.values(FIELD_CLASS), Object.values(BOX_CLASS), Object.values(BOX_OFF_CLASS), FIELD_INVALID_CLASS,
|
|
96
|
-
BOX_INPUT_CLASS, CHIP_CLASS, CHIP_REMOVE_CLASS, GROUP_TITLE_CLASS, CHECK_CLASS,
|
|
123
|
+
BOX_INPUT_CLASS, CHIP_CLASS, CHIP_REMOVE_CLASS, GROUP_TITLE_CLASS, CHECK_CLASS, CHECK_END_CLASS,
|
|
97
124
|
CLEAR_CLASS, CLEAR_SELECT_CLASS, CLEAR_HIDDEN_CLASS,
|
|
98
125
|
Object.values(SELECT_FIELD_CLASS), Object.values(SELECT_FIELD_OFF_CLASS), Object.values(SELECT_FIELD_RO_CLASS),
|
|
126
|
+
Object.values(SELECT_FIELD_FILLED_CLASS), Object.values(SELECT_FIELD_FILLED_OFF_CLASS), Object.values(SELECT_FIELD_FILLED_RO_CLASS),
|
|
127
|
+
Object.values(FIELD_FILLED_CLASS),
|
|
99
128
|
SEL_CHIPS_FIELD_CLASS, SEL_CHIPS_FIELD_OFF_CLASS, SEL_CHIPS_FIELD_RO_CLASS,
|
|
100
129
|
SEL_TEXT_CLASS, SEL_TEXT_CLEAR_CLASS, SEL_PLACEHOLDER_CLASS, SEL_PLACEHOLDER_CLEAR_CLASS, SEL_CHEVRON_CLASS,
|
|
101
130
|
PANEL_HIDDEN_CLASS, PANEL_SHOWN_CLASS, EMPTY_ROW_WIDE,
|
|
@@ -359,6 +388,22 @@ export function createListboxView(kind: ListboxKind): KitViewSetup {
|
|
|
359
388
|
desc.textContent = extra.desc;
|
|
360
389
|
el.appendChild(desc);
|
|
361
390
|
}
|
|
391
|
+
// 单选也画对勾(KT-K-select-3,二-18):选中项尾部一枚对勾,状态不只靠底色(KT-K0-2 第 6 条);
|
|
392
|
+
// 放尾部而不是像多选那样占首列,选项文字仍与触发器文字同轴
|
|
393
|
+
if (!isMulti(p) && isSel) {
|
|
394
|
+
if (el.firstChild !== null && el.firstChild.nodeType === 3) {
|
|
395
|
+
const label = document.createElement('span');
|
|
396
|
+
label.className = LABEL_CLASS;
|
|
397
|
+
label.textContent = o.label;
|
|
398
|
+
el.textContent = '';
|
|
399
|
+
el.appendChild(label);
|
|
400
|
+
}
|
|
401
|
+
const check = document.createElement('span');
|
|
402
|
+
check.className = CHECK_END_CLASS;
|
|
403
|
+
check.setAttribute('aria-hidden', 'true');
|
|
404
|
+
check.appendChild(kitIcon('check', 'sm'));
|
|
405
|
+
el.appendChild(check);
|
|
406
|
+
}
|
|
362
407
|
return el;
|
|
363
408
|
};
|
|
364
409
|
|
|
@@ -929,13 +974,16 @@ export function createListboxView(kind: ListboxKind): KitViewSetup {
|
|
|
929
974
|
// 质感标记打在带边框的那一层:多选 chips 是外壳 box(里面的 field 无边),其余是 field 自己
|
|
930
975
|
if (z.box) setKitFace(z.box, 'field');
|
|
931
976
|
else setKitFace(z.field, 'field');
|
|
977
|
+
const filled = p.variant === 'filled';
|
|
932
978
|
if (z.box) {
|
|
933
979
|
z.box.className = withInvalid(`${disabled ? BOX_OFF_CLASS[size] : BOX_CLASS[size]}${pad}`, invalid);
|
|
934
980
|
z.field.className = z.editable ? BOX_INPUT_CLASS : disabled ? SEL_CHIPS_FIELD_OFF_CLASS : readonly ? SEL_CHIPS_FIELD_RO_CLASS : SEL_CHIPS_FIELD_CLASS;
|
|
935
981
|
} else if (z.editable) {
|
|
936
|
-
z.field.className = withInvalid(`${FIELD_CLASS[size]}${pad}`, invalid);
|
|
982
|
+
z.field.className = withInvalid(`${(filled ? FIELD_FILLED_CLASS : FIELD_CLASS)[size]}${pad}`, invalid);
|
|
937
983
|
} else {
|
|
938
|
-
const selCls =
|
|
984
|
+
const selCls = filled
|
|
985
|
+
? (disabled ? SELECT_FIELD_FILLED_OFF_CLASS[size] : readonly ? SELECT_FIELD_FILLED_RO_CLASS[size] : SELECT_FIELD_FILLED_CLASS[size])
|
|
986
|
+
: (disabled ? SELECT_FIELD_OFF_CLASS[size] : readonly ? SELECT_FIELD_RO_CLASS[size] : SELECT_FIELD_CLASS[size]);
|
|
939
987
|
z.field.className = withInvalid(selCls, invalid);
|
|
940
988
|
}
|
|
941
989
|
if (z.editable) {
|
package/src/base/mentions.ts
CHANGED
|
@@ -21,13 +21,16 @@ import {
|
|
|
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';
|
|
24
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
24
25
|
|
|
26
|
+
// 文本框的边 = 控件轮廓出口(KT-B1 / §4 C6)
|
|
27
|
+
const CONTROL_EDGE = kitControlEdgeRecipe();
|
|
25
28
|
const WRAP = 'relative block w-full';
|
|
26
29
|
const STATUS = 'sr-only';
|
|
27
30
|
const AREA: Record<KitSize, string> = {
|
|
28
|
-
sm: 'block w-full appearance-none autofill-clear resize-none rounded-md
|
|
29
|
-
md: 'block w-full appearance-none autofill-clear resize-none rounded-md
|
|
30
|
-
lg: 'block w-full appearance-none autofill-clear resize-none rounded-md
|
|
31
|
+
sm: 'block w-full appearance-none autofill-clear resize-none rounded-md ' + CONTROL_EDGE + ' bg-surface px-2.5 py-1.5 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
|
|
32
|
+
md: 'block w-full appearance-none autofill-clear resize-none rounded-md ' + CONTROL_EDGE + ' bg-surface px-3 py-2 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
|
|
33
|
+
lg: 'block w-full appearance-none autofill-clear resize-none rounded-md ' + CONTROL_EDGE + ' bg-surface px-4 py-2.5 text-base text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export const KIT_MENTIONS_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
package/src/base/menu-button.ts
CHANGED
|
@@ -4,18 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
6
6
|
import { kitText } from '../i18n/kit-text';
|
|
7
|
-
import { mergeClass } from '../
|
|
8
|
-
import { kitIconHtml } from '
|
|
7
|
+
import { mergeClass } from '../shared/merge-class';
|
|
8
|
+
import { kitIconHtml } from '../shared/icons';
|
|
9
9
|
import {
|
|
10
10
|
CLASS_PROP, ID_PROPS, SIZE_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES,
|
|
11
11
|
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setBoolAttr, sizeOf, str, withBadgeAnchor, withTooltip,
|
|
12
12
|
type KitSize, type KitView,
|
|
13
13
|
} from './shared';
|
|
14
|
-
import { kitTypographyRecipe, setKitFace } from '../recipes';
|
|
15
|
-
import { kitButtonNoWrapMap } from '../recipes/nowrap';
|
|
14
|
+
import { kitControlRecipe, kitTypographyRecipe, setKitFace } from '../recipes';
|
|
16
15
|
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
17
16
|
import { menuItemsOf, wireMenu, type MenuClasses, type MenuHandle } from './menu-core';
|
|
18
17
|
import { KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, popPlaceClass, type PopPlace } from './popup';
|
|
18
|
+
import { kitDividerRecipe } from '../recipes/divider';
|
|
19
|
+
import { KIT_COMPACT_GROUP_ATTR, kitCompactGroupRecipe, markKitCompactGroup } from '../recipes/compact-group';
|
|
20
|
+
import { KIT_STRIP_MENU_ITEM_CLASS } from '../recipes/strip';
|
|
21
|
+
import { FOCUS_INSET } from '../shared/focus-ring';
|
|
19
22
|
import {
|
|
20
23
|
CONTEXT_AREA, CONTEXT_AREA_OFF, CONTEXT_POINT_PANEL, CONTEXT_SHOWN, KIT_CONTEXT_MENU_CLASS_CANDIDATES, wireContextTrigger, type Corner,
|
|
21
24
|
} from './context-menu';
|
|
@@ -25,66 +28,68 @@ const ROOT_CONTEXT_CLASS = 'relative block';
|
|
|
25
28
|
export type MenuButtonVariant = 'primary' | 'neutral' | 'ghost';
|
|
26
29
|
|
|
27
30
|
const ROOT_CLASS = 'relative inline-block';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
neutral: {
|
|
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',
|
|
38
|
-
},
|
|
39
|
-
ghost: {
|
|
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',
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
// 触发钮文案单行(「更多」「操作」等不逐字折行)
|
|
31
|
+
// 菜单触发钮:控件引擎的按钮配方(四元组整档取用,恒单行不压缩由引擎给出),不再手写 3 变体 × 3 尺寸 9 串
|
|
32
|
+
const triggerClassesOf = (variant: MenuButtonVariant): Record<KitSize, string> => ({
|
|
33
|
+
sm: kitControlRecipe({ variant, size: 'sm' }),
|
|
34
|
+
md: kitControlRecipe({ variant, size: 'md' }),
|
|
35
|
+
lg: kitControlRecipe({ variant, size: 'lg' }),
|
|
36
|
+
});
|
|
46
37
|
const TRIGGER_CLASS: Record<MenuButtonVariant, Record<KitSize, string>> = {
|
|
47
|
-
primary:
|
|
48
|
-
neutral:
|
|
49
|
-
ghost:
|
|
38
|
+
primary: triggerClassesOf('primary'),
|
|
39
|
+
neutral: triggerClassesOf('neutral'),
|
|
40
|
+
ghost: triggerClassesOf('ghost'),
|
|
50
41
|
};
|
|
51
42
|
const MENU_HIDDEN = 'hidden';
|
|
52
|
-
const MENU_BASE = mergeClass('absolute z-10 flex min-w-40 flex-col p-1', kitSurfaceRecipe('raised'));
|
|
43
|
+
const MENU_BASE = mergeClass('absolute z-10 flex w-max min-w-40 min-w-full max-w-xs flex-col p-1', kitSurfaceRecipe('raised'));
|
|
53
44
|
/** 默认偏好:触发钮下方、左对齐;贴边时由 popup.ts 在闭集位置间翻转 */
|
|
54
45
|
const MENU_PREF: PopPlace = { side: 'bottom', align: 'start' };
|
|
55
|
-
const menuClass = (place: PopPlace): string => `${MENU_BASE} ${popPlaceClass(place
|
|
46
|
+
const menuClass = (place: PopPlace): string => `${MENU_BASE} ${popPlaceClass(place)}`;
|
|
56
47
|
const MENU_SHOWN = menuClass(MENU_PREF);
|
|
57
48
|
/** 菜单面板外观的唯一一份:表格行「更多」菜单、右键菜单等共用(改外观只改这里) */
|
|
49
|
+
/** 文字型触发器(无内边距的文字链接,如行内「更多」)的菜单:面板左缘外移一个文字内缩(面板边框 + 内边距 + 项内边距 ≈ 12px),菜单项文字与触发器文字同轴;右缘对齐(翻转)时不移 */
|
|
50
|
+
const TEXT_TRIGGER_SHIFT = '-ms-3';
|
|
51
|
+
const menuClassTextTrigger = (place: PopPlace): string => `${menuClass(place)}${place.align === 'start' ? ` ${TEXT_TRIGGER_SHIFT}` : ''}`;
|
|
58
52
|
export const KIT_MENU_PANEL = {
|
|
59
53
|
/** 面板整串类(按位置) */
|
|
60
54
|
classFor: menuClass,
|
|
55
|
+
/** 文字型触发器的面板整串类(见 TEXT_TRIGGER_SHIFT) */
|
|
56
|
+
classForTextTrigger: menuClassTextTrigger,
|
|
61
57
|
/** 触发钮(幽灵变体小号),行内「更多」用 */
|
|
62
58
|
ghostTrigger: (): string => TRIGGER_CLASS.ghost.sm,
|
|
63
59
|
} as const;
|
|
60
|
+
// 菜单项(KT-K-select-2 / 4):项高 = 条带阶梯的菜单项行高(sizeSpec.strip.menuItemPx,与下拉选项同一种);
|
|
61
|
+
// 键盘当前项与悬停同一层(focus-visible 叠悬停层),并画集合项焦点环(2px 内收,KT-K0-3),不只靠底色
|
|
62
|
+
const ITEM_ROW = KIT_STRIP_MENU_ITEM_CLASS;
|
|
64
63
|
export const KIT_MENU_ITEM_CLASSES: MenuClasses = {
|
|
65
|
-
idle:
|
|
66
|
-
danger:
|
|
67
|
-
disabled:
|
|
64
|
+
idle: `flex cursor-pointer ${ITEM_ROW} items-center gap-2 whitespace-nowrap rounded-md px-2 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:bg-state-layer-hover ${FOCUS_INSET}`,
|
|
65
|
+
danger: `flex cursor-pointer ${ITEM_ROW} items-center gap-2 whitespace-nowrap rounded-md px-2 text-sm text-danger-on-soft transition-colors hover:bg-danger-soft focus-visible:bg-danger-soft ${FOCUS_INSET}`,
|
|
66
|
+
disabled: `flex cursor-not-allowed ${ITEM_ROW} items-center gap-2 whitespace-nowrap rounded-md px-2 text-sm text-fg-disabled`,
|
|
67
|
+
// 带原因描述的置灰项:两行结构(标签 / 描述各占一行),标签不折行、描述在面板宽度上限内折行
|
|
68
|
+
disabledDesc: 'flex cursor-not-allowed min-h-9 flex-wrap items-center gap-x-2 rounded-md px-2 py-1.5 text-sm text-fg-disabled',
|
|
68
69
|
divider: 'my-1 h-px bg-border-subtle',
|
|
69
70
|
icon: 'inline-block shrink-0',
|
|
70
|
-
//
|
|
71
|
-
desc: mergeClass(kitTypographyRecipe('caption'), '
|
|
71
|
+
// 置灰项的原因描述:独占第二行、弱色小字、可折行
|
|
72
|
+
desc: mergeClass(kitTypographyRecipe('caption'), 'basis-full whitespace-normal'),
|
|
72
73
|
};
|
|
73
74
|
const MENU_CLASSES = KIT_MENU_ITEM_CLASSES;
|
|
74
75
|
const CARET_CLASS = 'inline-flex';
|
|
75
76
|
|
|
76
|
-
// split
|
|
77
|
+
// split(knowledge/Kit主题规则与算法.md KT-K-button-5 / KT-B7,裁决 E-4):DOM 顺序 = 视觉顺序 [主钮][箭头钮],两钮包在一个紧凑组合里——
|
|
78
|
+
// 相邻共用一条边(负外边距 = 控件轮廓宽)、内侧圆角由结构 CSS 按 data-kit-compact 清、悬停 / 聚焦项抬层;Tab 序先主钮后箭头。
|
|
79
|
+
// 非 split 时包层是 contents(不产生盒),主钮隐藏。
|
|
77
80
|
const ROOT_SPLIT_CLASS = 'relative inline-flex';
|
|
78
|
-
const
|
|
81
|
+
const PAIR_SPLIT_CLASS = kitCompactGroupRecipe('x');
|
|
82
|
+
const PAIR_PLAIN_CLASS = 'contents';
|
|
83
|
+
// 两块实心之间要有缝(笔记 §3.3 第 8 条):实心变体箭头钮起始边一道主色前景混色的控件线;幽灵变体的缝 = 分隔线出口(发丝宽、分隔灰,KT-B5);描边变体两钮的边已重叠成一条
|
|
79
84
|
const SPLIT_TRIGGER_CLASS: Record<MenuButtonVariant, string> = {
|
|
80
|
-
primary: '
|
|
81
|
-
neutral: '
|
|
82
|
-
ghost: '
|
|
85
|
+
primary: 'border-s border-primary-fg/30',
|
|
86
|
+
neutral: '',
|
|
87
|
+
ghost: kitDividerRecipe('start'),
|
|
83
88
|
};
|
|
84
89
|
|
|
85
90
|
export const KIT_MENU_BUTTON_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
86
|
-
ROOT_SPLIT_CLASS,
|
|
87
|
-
ROOT_CLASS, Object.values(TRIGGER_CLASS).flatMap((m) => Object.values(m)), MENU_HIDDEN, MENU_BASE, KIT_POPUP_PLACE_CLASS_CANDIDATES, KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES,
|
|
91
|
+
ROOT_SPLIT_CLASS, PAIR_SPLIT_CLASS, PAIR_PLAIN_CLASS, Object.values(SPLIT_TRIGGER_CLASS), KIT_BADGE_CLASS_CANDIDATES,
|
|
92
|
+
ROOT_CLASS, Object.values(TRIGGER_CLASS).flatMap((m) => Object.values(m)), MENU_HIDDEN, MENU_BASE, TEXT_TRIGGER_SHIFT, KIT_POPUP_PLACE_CLASS_CANDIDATES, KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES,
|
|
88
93
|
Object.values(MENU_CLASSES), CARET_CLASS, 'hidden', 'inline-block', ROOT_CONTEXT_CLASS, KIT_CONTEXT_MENU_CLASS_CANDIDATES,
|
|
89
94
|
);
|
|
90
95
|
|
|
@@ -97,22 +102,32 @@ function variantOf(raw: unknown): MenuButtonVariant {
|
|
|
97
102
|
return raw === 'primary' || raw === 'ghost' ? raw : 'neutral';
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
/**
|
|
105
|
+
/** 两钮的包层(根的第一个子元素):split 时是紧凑组合,否则 contents */
|
|
106
|
+
function pairOf(root: HTMLElement): HTMLElement {
|
|
107
|
+
return root.firstElementChild as HTMLElement;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 分体主钮:包层里的第一个 button(非 split 时隐藏) */
|
|
101
111
|
function mainOf(root: HTMLElement): HTMLElement | undefined {
|
|
102
|
-
return
|
|
112
|
+
return (pairOf(root)?.firstElementChild ?? undefined) as HTMLElement | undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 触发钮(展开菜单):包层里的第二个 button */
|
|
116
|
+
function triggerOf(root: HTMLElement): HTMLElement {
|
|
117
|
+
return pairOf(root).lastElementChild as HTMLElement;
|
|
103
118
|
}
|
|
104
119
|
|
|
105
120
|
/** tooltip 的目标:split 时是主钮(箭头钮另有可访问名),否则是触发钮;主钮显示与否以渲染后的类为准 */
|
|
106
121
|
function tooltipTarget(root: HTMLElement): HTMLElement {
|
|
107
122
|
const main = mainOf(root);
|
|
108
|
-
return main && !main.classList.contains(MENU_HIDDEN) ? main : (root
|
|
123
|
+
return main && !main.classList.contains(MENU_HIDDEN) ? main : triggerOf(root);
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
function makeView(): KitView {
|
|
112
127
|
let handle: MenuHandle | null = null;
|
|
113
128
|
return {
|
|
114
129
|
attach(root, api) {
|
|
115
|
-
const trigger = root
|
|
130
|
+
const trigger = triggerOf(root);
|
|
116
131
|
const menu = root.children[1] as HTMLElement;
|
|
117
132
|
let corner: Corner = 'tl';
|
|
118
133
|
let at: { x: number; y: number } | null = null;
|
|
@@ -161,8 +176,9 @@ function makeView(): KitView {
|
|
|
161
176
|
};
|
|
162
177
|
},
|
|
163
178
|
render(root, p) {
|
|
164
|
-
const btn = root
|
|
179
|
+
const btn = triggerOf(root) as HTMLElement | null;
|
|
165
180
|
const main = mainOf(root);
|
|
181
|
+
const pair = pairOf(root);
|
|
166
182
|
const size = sizeOf(p.size);
|
|
167
183
|
const ctx = contextMode(p);
|
|
168
184
|
const split = bool(p.split) && !ctx;
|
|
@@ -198,21 +214,22 @@ function makeView(): KitView {
|
|
|
198
214
|
if (off) main.setAttribute('aria-disabled', 'true');
|
|
199
215
|
else main.removeAttribute('aria-disabled');
|
|
200
216
|
applyCommon(main, { id: p.id, aria_label: p.aria_label });
|
|
201
|
-
main.className =
|
|
217
|
+
main.className = TRIGGER_CLASS[variant][size];
|
|
202
218
|
setKitFace(main, variant === 'ghost' ? null : 'raised');
|
|
203
|
-
badgeHost = main;
|
|
204
219
|
} else {
|
|
205
220
|
setKitFace(main, null);
|
|
206
221
|
main.textContent = '';
|
|
207
222
|
main.className = MENU_HIDDEN;
|
|
208
223
|
}
|
|
209
224
|
}
|
|
210
|
-
//
|
|
211
|
-
|
|
225
|
+
// 角标只落在一处:split 时挂在组外缘(根 = 组容器,ROOT_SPLIT_CLASS 自带 relative,角标在组末端上角、不压两钮接缝,
|
|
226
|
+
// 在根上而不在紧凑组合内,层叠高于组内抬层的钮;KT-K-button-5,§6.1 G-20),否则在触发钮;其余位置的角标摘掉
|
|
227
|
+
if (split) badgeHost = root;
|
|
228
|
+
for (const el of [btn, main, root]) {
|
|
212
229
|
if (!el) continue;
|
|
213
230
|
if (el === badgeHost) {
|
|
214
231
|
const has = paintBadge(el, p);
|
|
215
|
-
el.className = withBadgeAnchor(el.className, has);
|
|
232
|
+
if (el !== root) el.className = withBadgeAnchor(el.className, has);
|
|
216
233
|
} else {
|
|
217
234
|
paintBadge(el, {});
|
|
218
235
|
}
|
|
@@ -220,6 +237,12 @@ function makeView(): KitView {
|
|
|
220
237
|
if (bool(p.disabled) && handle?.isOpen()) handle.close(false);
|
|
221
238
|
handle?.sync();
|
|
222
239
|
root.className = joinClass(ctx ? ROOT_CONTEXT_CLASS : split ? ROOT_SPLIT_CLASS : ROOT_CLASS, p.class);
|
|
240
|
+
// 紧凑组合只在 split 时成立(非 split 时包层不产生盒,单个触发钮保留完整圆角)
|
|
241
|
+
if (pair) {
|
|
242
|
+
pair.className = split ? PAIR_SPLIT_CLASS : PAIR_PLAIN_CLASS;
|
|
243
|
+
if (split) markKitCompactGroup(pair, 'x');
|
|
244
|
+
else pair.removeAttribute(KIT_COMPACT_GROUP_ATTR);
|
|
245
|
+
}
|
|
223
246
|
},
|
|
224
247
|
};
|
|
225
248
|
}
|
|
@@ -250,7 +273,7 @@ export function createMenuButton(): SomaComponentDefinition {
|
|
|
250
273
|
click: { payload: {}, desc: 'split 时点主钮;disabled 时不抛' },
|
|
251
274
|
},
|
|
252
275
|
},
|
|
253
|
-
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"><button type="button" class="${TRIGGER_CLASS.neutral.md}"><span></span><span aria-hidden="true" class="${CARET_CLASS}">${kitIconHtml('chevron-down', 'sm')}</span></button><div class="${MENU_HIDDEN}"></div
|
|
276
|
+
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"><span class="${PAIR_PLAIN_CLASS}"><button type="button" class="${MENU_HIDDEN}"></button><button type="button" class="${TRIGGER_CLASS.neutral.md}"><span></span><span aria-hidden="true" class="${CARET_CLASS}">${kitIconHtml('chevron-down', 'sm')}</span></button></span><div class="${MENU_HIDDEN}"></div></div>`,
|
|
254
277
|
controllerFactory: createKitController(() => withTooltip(makeView(), tooltipTarget)),
|
|
255
278
|
};
|
|
256
279
|
}
|
package/src/base/menu-core.ts
CHANGED
|
@@ -65,6 +65,8 @@ export interface MenuClasses {
|
|
|
65
65
|
idle: string;
|
|
66
66
|
danger: string;
|
|
67
67
|
disabled: string;
|
|
68
|
+
/** 置灰且带原因描述的项:两行结构(标签一行,描述另起一行),高度随内容 */
|
|
69
|
+
disabledDesc?: string;
|
|
68
70
|
divider: string;
|
|
69
71
|
icon: string;
|
|
70
72
|
/** 置灰原因描述文字的类(项带 reason 时用;缺省不加类) */
|
|
@@ -153,8 +155,13 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
153
155
|
const elOf = (key: string): HTMLElement | undefined => itemEls().find((el) => el.dataset.key === key);
|
|
154
156
|
const itemOf = (key: string): MenuItemSpec | undefined => o.items().find((i) => i.key === key && !i.divider);
|
|
155
157
|
|
|
156
|
-
const classOf = (item: MenuItemSpec): string =>
|
|
157
|
-
item.disabled
|
|
158
|
+
const classOf = (item: MenuItemSpec): string => {
|
|
159
|
+
if (item.disabled) {
|
|
160
|
+
const hasDesc = item.reason !== undefined && item.reason.trim() !== '';
|
|
161
|
+
return hasDesc && o.classes.disabledDesc !== undefined ? o.classes.disabledDesc : o.classes.disabled;
|
|
162
|
+
}
|
|
163
|
+
return item.danger ? o.classes.danger : o.classes.idle;
|
|
164
|
+
};
|
|
158
165
|
|
|
159
166
|
const build = (): void => {
|
|
160
167
|
const items = o.items();
|
|
@@ -11,10 +11,13 @@ import {
|
|
|
11
11
|
type KitApi, type KitProps,
|
|
12
12
|
} from '../shared';
|
|
13
13
|
import { safeHref } from '../link';
|
|
14
|
+
import { kitShellRecipe } from '../../recipes/container';
|
|
14
15
|
import { HOVER_3D_GRID, MOTION_STRENGTHS, prefersReducedMotion, segmentOf, strengthOf, type MotionStrength } from './limits';
|
|
15
16
|
|
|
16
17
|
const ROOT_CLASS = 'block perspective-normal';
|
|
17
|
-
|
|
18
|
+
// 卡面外缘 = 壳配方(容器边,KT-B2)
|
|
19
|
+
const CARD_EDGE = kitShellRecipe({ tone: 'base', shadow: false });
|
|
20
|
+
const CARD_CORE = 'block overflow-hidden ' + CARD_EDGE + ' text-fg motion-safe:transition-transform focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
18
21
|
const CARD_IDLE = `${CARD_CORE} shadow-sm`;
|
|
19
22
|
const CARD_TILTED = `${CARD_CORE} shadow-md`;
|
|
20
23
|
const IMAGE_CLASS = 'block h-40 w-full object-cover';
|
|
@@ -10,10 +10,13 @@ import {
|
|
|
10
10
|
} from '../shared';
|
|
11
11
|
import { kitText } from '../../i18n/kit-text';
|
|
12
12
|
import { safeHref } from '../link';
|
|
13
|
+
import { kitShellRecipe } from '../../recipes/container';
|
|
13
14
|
import { HOVER_GALLERY_MAX_IMAGES, segmentOf } from './limits';
|
|
14
15
|
|
|
15
16
|
type HeightKey = 'sm' | 'md' | 'lg';
|
|
16
|
-
|
|
17
|
+
// 外缘 = 凹槽面的壳配方(容器边,KT-B2)
|
|
18
|
+
const ROOT_EDGE = kitShellRecipe({ tone: 'sunken', shadow: false });
|
|
19
|
+
const ROOT_BASE = 'relative block w-full overflow-hidden ' + ROOT_EDGE + ' focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
17
20
|
const HEIGHT_CLASS: Record<HeightKey, string> = { sm: 'h-40', md: 'h-56', lg: 'h-72' };
|
|
18
21
|
const STAGE_CLASS = 'block h-full w-full';
|
|
19
22
|
const IMG_ACTIVE = 'block h-full w-full object-cover motion-safe:animate-kit-fade';
|
package/src/base/otp.ts
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
7
7
|
import { kitKey, kitText } from '../i18n/kit-text';
|
|
8
8
|
import { setKitFace } from '../recipes';
|
|
9
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
10
|
+
|
|
11
|
+
// 格子的边 = 控件轮廓出口(KT-B1 / §4 C6)
|
|
12
|
+
const CONTROL_EDGE = kitControlEdgeRecipe();
|
|
9
13
|
import {
|
|
10
14
|
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
11
15
|
applyGroupA11y, bool, classCandidates, createKitController, joinClass, num, setAttr, setBoolAttr, sizeOf, str,
|
|
@@ -15,9 +19,9 @@ import {
|
|
|
15
19
|
const GROUP_CLASS = 'inline-flex items-center gap-2';
|
|
16
20
|
|
|
17
21
|
const CELL_CLASS: Record<KitSize, string> = {
|
|
18
|
-
sm: 'block h-8 w-8 appearance-none autofill-clear rounded-md
|
|
19
|
-
md: 'block h-10 w-10 appearance-none autofill-clear rounded-md
|
|
20
|
-
lg: 'block h-12 w-12 appearance-none autofill-clear rounded-md
|
|
22
|
+
sm: 'block h-8 w-8 appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface p-0 text-center text-sm text-fg transition-colors focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
|
|
23
|
+
md: 'block h-10 w-10 appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface p-0 text-center text-base text-fg transition-colors focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
|
|
24
|
+
lg: 'block h-12 w-12 appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface p-0 text-center text-lg text-fg transition-colors focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken',
|
|
21
25
|
};
|
|
22
26
|
|
|
23
27
|
export const KIT_OTP_CLASS_CANDIDATES: readonly string[] = classCandidates(GROUP_CLASS, Object.values(CELL_CLASS));
|
|
@@ -147,7 +147,8 @@ export type KitHideTransition = (element: HTMLElement, signal: AbortSignal) => P
|
|
|
147
147
|
|
|
148
148
|
/** 浮层显隐外层:锚点 id 以 _layer 结尾(overlay-shell 的 dialogIds / overlayIds),且直接子节点含遮罩 */
|
|
149
149
|
export function isKitLayerHost(el: HTMLElement): boolean {
|
|
150
|
-
|
|
150
|
+
const id = el.getAttribute('data-soma-id') ?? el.getAttribute('data-soma-scoped-id') ?? '';
|
|
151
|
+
if (!id.endsWith('_layer')) return false;
|
|
151
152
|
return Array.from(el.children).some((c) => c.hasAttribute('data-kit-scrim'));
|
|
152
153
|
}
|
|
153
154
|
|
|
@@ -221,7 +222,7 @@ export function installKitOverlayRuntime(doc: Document): void {
|
|
|
221
222
|
|| Array.from(r.addedNodes).some(relevantNode) || Array.from(r.removedNodes).some(relevantNode));
|
|
222
223
|
if (hit) onChange();
|
|
223
224
|
});
|
|
224
|
-
mo.observe(root, { childList: true, subtree: true, attributes: true, attributeFilter: ['hidden', KIT_LEAVING_ATTR] });
|
|
225
|
+
mo.observe(root, { childList: true, subtree: true, attributes: true, attributeFilter: ['hidden', 'class', KIT_LEAVING_ATTR] });
|
|
225
226
|
}
|
|
226
227
|
const onHide = (): void => { if (state.last !== 0) { state.last = 0; postOpen(win, 0); } };
|
|
227
228
|
win.addEventListener('pagehide', onHide);
|