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
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// 窗口外壳(居中窗口 / 抽屉)的唯一结构:遮罩行 > 面板 > 头(56)/ 正文(滚动,内边距 24)/ 底栏(56)。
|
|
2
|
+
// 声明式页面浮层(biz/shared/overlay-shell:`kind: dialog / drawer`、新增编辑弹窗)与命令式浮层(data/modal-dialog:确认 / 提示 / 选择器 / 抽屉)
|
|
3
|
+
// 都只是这里的调用方:调用方传「决定」(哪种窗口、哪一档宽度、标题与正文是什么),结构、类串、标记属性只在本文件与 recipes/overlay.ts 出口。
|
|
4
|
+
// 流水线位置:recipes(类串)-> 本文件(结构)-> data / biz(调用方)。本文件不认识页面、业务对象与具体窗口用途;颜色、阴影、圆角在 recipes 里按面阶取,这里不碰。
|
|
5
|
+
// 定位:居中窗口顶边固定(遮罩上沿下 topPx)、底部留白(bottomGapPx),高度随内容、最大高度占满其间,正文在窗口内滚动;抽屉贴 end 侧整高。
|
|
6
|
+
|
|
7
|
+
import { esc } from '../shared/escape';
|
|
8
|
+
import { kitIconHtml } from '../shared/icons';
|
|
9
|
+
import {
|
|
10
|
+
KIT_OVERLAY_CLOSE_CLASS, KIT_OVERLAY_HEAD_ACTIONS_CLASS, KIT_OVERLAY_SCRIM_CLASS, KIT_OVERLAY_SCROLL_ATTR, KIT_PART_DIALOG, KIT_PART_DRAWER,
|
|
11
|
+
kitDialogPanelClass, kitDrawerPanelClass, kitOverlayContentRecipe, kitOverlayFooterRecipe, kitOverlayHeaderRecipe, kitOverlayTitleRecipe,
|
|
12
|
+
KIT_OVERLAY_LEAD_ICON, KIT_OVERLAY_LEAD_TEXT_CLASS, kitOverlayLeadBodyRecipe, kitOverlayLeadHeaderRecipe,
|
|
13
|
+
type KitDialogTier, type KitDrawerWidth,
|
|
14
|
+
} from '../recipes/overlay';
|
|
15
|
+
import { KIT_FIXED_ATTRIBUTE, KIT_PART_ATTRIBUTE, KIT_PART_TITLE_DIALOG } from '../recipes';
|
|
16
|
+
|
|
17
|
+
export type KitShellKind = 'dialog' | 'drawer';
|
|
18
|
+
|
|
19
|
+
/** 外壳各段类串(一次取全:编译期候选类收集、测试都读这一份) */
|
|
20
|
+
export interface KitShellClasses {
|
|
21
|
+
scrim: string;
|
|
22
|
+
panel: string;
|
|
23
|
+
header: string;
|
|
24
|
+
title: string;
|
|
25
|
+
close: string;
|
|
26
|
+
headActions: string;
|
|
27
|
+
body: string;
|
|
28
|
+
footer: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 窗口的决定:哪种窗口 + 档位(居中窗口 confirm / default / wide / xwide;抽屉 default / wide);panelExtra 是调用方已合并好的附加类 */
|
|
32
|
+
export interface KitShellDecision {
|
|
33
|
+
kind: KitShellKind;
|
|
34
|
+
dialogTier?: KitDialogTier;
|
|
35
|
+
drawerWidth?: KitDrawerWidth;
|
|
36
|
+
panelExtra?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function kitShellClasses(d: KitShellDecision): KitShellClasses {
|
|
40
|
+
const panel = d.kind === 'drawer' ? kitDrawerPanelClass(d.drawerWidth ?? 'default') : kitDialogPanelClass(d.dialogTier ?? 'default');
|
|
41
|
+
return {
|
|
42
|
+
scrim: KIT_OVERLAY_SCRIM_CLASS[d.kind],
|
|
43
|
+
panel: d.panelExtra !== undefined && d.panelExtra !== '' ? `${panel} ${d.panelExtra}` : panel,
|
|
44
|
+
header: kitOverlayHeaderRecipe(),
|
|
45
|
+
title: kitOverlayTitleRecipe(),
|
|
46
|
+
close: KIT_OVERLAY_CLOSE_CLASS,
|
|
47
|
+
headActions: KIT_OVERLAY_HEAD_ACTIONS_CLASS,
|
|
48
|
+
body: kitOverlayContentRecipe(),
|
|
49
|
+
footer: kitOverlayFooterRecipe(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 段标记属性(测试、协调组件与渲染度量按它找段):居中窗口 `data-kit-dialog-*`,抽屉 `data-kit-overlay-*` */
|
|
54
|
+
export function kitShellMarks(kind: KitShellKind): { header: string; body: string; footer: string } {
|
|
55
|
+
const family = kind === 'drawer' ? 'overlay' : 'dialog';
|
|
56
|
+
return { header: `data-kit-${family}-header`, body: `data-kit-${family}-body`, footer: `data-kit-${family}-footer` };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const classAttr = (v: string): string => (v === '' ? '' : ` class="${esc(v)}"`);
|
|
60
|
+
|
|
61
|
+
/** 关闭钮 HTML(someId 给声明式页面的事件绑定用;命令式没有) */
|
|
62
|
+
function closeHtml(label: string, c: KitShellClasses, somaId: string | undefined): string {
|
|
63
|
+
return `<button type="button"${somaId !== undefined ? ` data-soma-id="${esc(somaId)}"` : ''} aria-label="${esc(label)}"${classAttr(c.close)}>${kitIconHtml('close', 'md')}</button>`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface KitShellHtmlSpec extends KitShellDecision {
|
|
67
|
+
/** 面板类串的最终值(调用方在 kitShellClasses 的基准上按同族规则合并了应用的附加类时传;缺省取基准) */
|
|
68
|
+
panelClass?: string;
|
|
69
|
+
/** 面板 aria-labelledby 指向的标题元素 id(声明式);命令式用 aria-label */
|
|
70
|
+
titleId?: string;
|
|
71
|
+
/** 标题元素的 data-soma-id(声明式页面事件 / 显隐绑定用) */
|
|
72
|
+
titleSomaId?: string;
|
|
73
|
+
/** 标题元素内部 HTML(调用方已转义;纯文本标题传 esc(title)) */
|
|
74
|
+
titleHtml: string;
|
|
75
|
+
/** 面板的 aria-label(没有 titleId 时) */
|
|
76
|
+
ariaLabel?: string;
|
|
77
|
+
/** 头右侧、关闭钮之前的操作区 HTML(如「编辑」钮宿主) */
|
|
78
|
+
headActionsHtml?: string;
|
|
79
|
+
/** 关闭钮;null = 不画(正文自带关闭钮的命令式浮层) */
|
|
80
|
+
close: { label: string; somaId?: string } | null;
|
|
81
|
+
bodyHtml: string;
|
|
82
|
+
/** 底栏内容:null = 不画底栏;'' = 画空底栏(命令式,内容随后填入) */
|
|
83
|
+
footerHtml: string | null;
|
|
84
|
+
/** 引导头(确认类窗口):语气图标块 + 标题一列,没有头部条与关闭钮;说明文字由调用方追加到标题之后(同一列) */
|
|
85
|
+
lead?: 'danger' | 'primary';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 窗口外壳 HTML(遮罩行为根)。声明式页面在外面再包一层显隐宿主;命令式经 kitShellDom 解析本串得到 DOM,两条路径同一结构。 */
|
|
89
|
+
export function kitShellHtml(s: KitShellHtmlSpec): string {
|
|
90
|
+
const c = kitShellClasses(s);
|
|
91
|
+
if (s.panelClass !== undefined) c.panel = s.panelClass;
|
|
92
|
+
const marks = kitShellMarks(s.kind);
|
|
93
|
+
const part = s.kind === 'drawer' ? KIT_PART_DRAWER : KIT_PART_DIALOG;
|
|
94
|
+
const label = s.titleId !== undefined ? ` aria-labelledby="${esc(s.titleId)}"` : s.ariaLabel !== undefined ? ` aria-label="${esc(s.ariaLabel)}"` : '';
|
|
95
|
+
const titleAttrs = `${s.titleId !== undefined ? ` id="${esc(s.titleId)}"` : ''}${s.titleSomaId !== undefined ? ` data-soma-id="${esc(s.titleSomaId)}"` : ''}`;
|
|
96
|
+
const headRight = s.close === null ? '' : closeHtml(s.close.label, c, s.close.somaId);
|
|
97
|
+
const actions = s.headActionsHtml !== undefined && s.headActionsHtml !== ''
|
|
98
|
+
? `<div${classAttr(c.headActions)}>${s.headActionsHtml}${headRight}</div>`
|
|
99
|
+
: headRight;
|
|
100
|
+
const h2 = `<h2${titleAttrs}${classAttr(c.title)} ${KIT_PART_ATTRIBUTE}="${KIT_PART_TITLE_DIALOG}">${s.titleHtml}</h2>`;
|
|
101
|
+
const lead = s.lead === undefined ? null : KIT_OVERLAY_LEAD_ICON[s.lead];
|
|
102
|
+
const header = lead === null
|
|
103
|
+
? `<div ${marks.header}=""${classAttr(c.header)}>${h2}${actions}</div>`
|
|
104
|
+
: `<div ${marks.header}="" data-kit-dialog-lead=""${classAttr(kitOverlayLeadHeaderRecipe())}>`
|
|
105
|
+
+ `<span aria-hidden="true"${classAttr(lead.cls)}>${kitIconHtml(lead.icon, 'md')}</span>`
|
|
106
|
+
+ `<div${classAttr(KIT_OVERLAY_LEAD_TEXT_CLASS)}>${h2}</div></div>`;
|
|
107
|
+
return `<div data-kit-scrim="" ${KIT_FIXED_ATTRIBUTE}=""${classAttr(c.scrim)}>`
|
|
108
|
+
+ `<div role="dialog" aria-modal="true"${classAttr(c.panel)} ${KIT_PART_ATTRIBUTE}="${part}"${label}>`
|
|
109
|
+
+ header
|
|
110
|
+
+ `<div ${marks.body}="" ${KIT_OVERLAY_SCROLL_ATTR}=""${classAttr(lead === null ? c.body : kitOverlayLeadBodyRecipe())}>${s.bodyHtml}</div>`
|
|
111
|
+
+ (s.footerHtml !== null ? `<div ${marks.footer}=""${classAttr(c.footer)}>${s.footerHtml}</div>` : '')
|
|
112
|
+
+ '</div></div>';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 命令式外壳的各段元素 */
|
|
116
|
+
export interface KitShellDom {
|
|
117
|
+
scrim: HTMLElement;
|
|
118
|
+
panel: HTMLElement;
|
|
119
|
+
title: HTMLElement;
|
|
120
|
+
closeButton: HTMLButtonElement | null;
|
|
121
|
+
body: HTMLElement;
|
|
122
|
+
footer: HTMLElement | null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 命令式窗口外壳:同一份 HTML 结构解析成 DOM(标题文本经 esc 转义后进入模板,调用方之后只往 body / footer 里放元素) */
|
|
126
|
+
export function kitShellDom(doc: Document, s: Omit<KitShellHtmlSpec, 'titleHtml' | 'bodyHtml'> & { title: string }): KitShellDom {
|
|
127
|
+
const marks = kitShellMarks(s.kind);
|
|
128
|
+
const tpl = doc.createElement('template');
|
|
129
|
+
tpl.innerHTML = kitShellHtml({ ...s, titleHtml: esc(s.title), bodyHtml: '' });
|
|
130
|
+
const root = tpl.content.firstElementChild as HTMLElement;
|
|
131
|
+
const must = <T extends Element>(sel: string): T => root.querySelector(sel) as T;
|
|
132
|
+
const closeButton = root.querySelector<HTMLButtonElement>(`[${marks.header}] button`);
|
|
133
|
+
return {
|
|
134
|
+
scrim: root,
|
|
135
|
+
panel: must<HTMLElement>('[role="dialog"]'),
|
|
136
|
+
title: must<HTMLElement>('h2'),
|
|
137
|
+
closeButton,
|
|
138
|
+
body: must<HTMLElement>(`[${marks.body}]`),
|
|
139
|
+
footer: root.querySelector<HTMLElement>(`[${marks.footer}]`),
|
|
140
|
+
};
|
|
141
|
+
}
|
package/src/base/popover.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mergeClass } from '../
|
|
1
|
+
import { mergeClass } from '../shared/merge-class';
|
|
2
2
|
// Popover(通用气泡卡片)与 Popconfirm(气泡确认)。D8 组。
|
|
3
3
|
//
|
|
4
4
|
// 归类(2.1a 四问):触发钮 + 一小块浮出的文字 / 确认条,不带对象形状 -> 基础组件。
|
|
@@ -12,6 +12,7 @@ import { mergeClass } from '../object-renderer/merge-class';
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
14
|
import { setKitFace } from '../recipes';
|
|
15
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
15
16
|
import {
|
|
16
17
|
KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, handoffTab, onOutsidePress, popPlaceClass, releaseDropdown,
|
|
17
18
|
syncAnchored, syncDropdown, type PopPlace,
|
|
@@ -67,9 +68,9 @@ const HIDDEN = 'hidden';
|
|
|
67
68
|
|
|
68
69
|
const TRIGGER: Record<PopVariant, Record<KitSize, string>> = {
|
|
69
70
|
neutral: {
|
|
70
|
-
sm: '
|
|
71
|
-
md: '
|
|
72
|
-
lg: '
|
|
71
|
+
sm: kitEmphasisButtonRecipe('button.toolbar', { size: 'sm', pointer: true }),
|
|
72
|
+
md: kitEmphasisButtonRecipe('button.toolbar', { size: 'md', pointer: true }),
|
|
73
|
+
lg: kitEmphasisButtonRecipe('button.toolbar', { size: 'lg', pointer: true }),
|
|
73
74
|
},
|
|
74
75
|
primary: {
|
|
75
76
|
sm: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md bg-primary px-2.5 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
@@ -89,11 +90,11 @@ export function popPlaceOf(placement: PopPlacement): PopPlace {
|
|
|
89
90
|
const [side, align] = placement.split('-') as ['top' | 'bottom', 'start' | 'end'];
|
|
90
91
|
return { side, align };
|
|
91
92
|
}
|
|
92
|
-
const panelClass = (place: PopPlace): string => `${PANEL_BASE} ${popPlaceClass(place
|
|
93
|
+
const panelClass = (place: PopPlace): string => `${PANEL_BASE} ${popPlaceClass(place)}`;
|
|
93
94
|
const TITLE = 'text-sm font-semibold text-fg';
|
|
94
95
|
const BODY = 'mt-2 text-sm text-fg-muted';
|
|
95
96
|
const ACTIONS = mergeClass(kitPopoverActionsRecipe(), 'mt-2');
|
|
96
|
-
const BTN_CANCEL = '
|
|
97
|
+
const BTN_CANCEL = kitEmphasisButtonRecipe('button.toolbar', { pointer: true });
|
|
97
98
|
const BTN_OK: Record<'primary' | 'danger', string> = {
|
|
98
99
|
primary: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
99
100
|
danger: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-danger px-3 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
package/src/base/popup.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
|
9
9
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
10
10
|
import { kitDirAt } from '../i18n/kit-text';
|
|
11
11
|
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
12
|
+
import { KIT_STRIP_MENU_ITEM_CLASS } from '../recipes/strip';
|
|
12
13
|
import { leaveAnchored, markAnchored, unmarkAnchored } from './anchored-layer';
|
|
13
14
|
import type { KitLeaveHandle } from './overlay-runtime';
|
|
14
15
|
import {
|
|
@@ -16,18 +17,22 @@ import {
|
|
|
16
17
|
type PanelPortal, type PointPanel, type PointPanelOptions, type PointXY,
|
|
17
18
|
} from './portal-core';
|
|
18
19
|
|
|
19
|
-
import { KIT_DROPDOWN_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
|
+
import { KIT_DROPDOWN_LIMITS, KIT_OVERLAY_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
21
|
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
21
22
|
|
|
22
23
|
type WiringOptions = Parameters<typeof createKeyboardWiring>[0];
|
|
23
24
|
|
|
24
|
-
//
|
|
25
|
-
// (最大高 = 整数行 +
|
|
26
|
-
type DropdownRules = {
|
|
27
|
-
rowClass: string; panelMaxClass: string; panelShadowClass: string; panelBorderClass: string;
|
|
28
|
-
clamps: readonly { cls: string }[];
|
|
29
|
-
};
|
|
25
|
+
// 下拉面板高度与浮层阴影档的真源:阴影 / 描边类读 spec/kit-grammar.json#dropdown;行高 = 条带阶梯的菜单项行高 sizeSpec.strip.menuItemPx(AR42),
|
|
26
|
+
// 内边距与各档像素读 design 的 kit-limits.json#dropdown(最大高 = 内边距 + (整数行 + 半行) × 行高;行数从大到小);类按像素写成 max-h-[Npx](与行高同口径,密度无关)
|
|
27
|
+
type DropdownRules = { panelShadowClass: string; panelBorderClass: string };
|
|
30
28
|
const DD = (grammarJson as unknown as { dropdown: DropdownRules }).dropdown;
|
|
29
|
+
|
|
30
|
+
/** 空间不足时面板内部滚动的 max-h 闭集档位,从大到小;每档都是「整数行 + 半行」(真源 dropdown.clamps),空间不够也不腰斩一行 */
|
|
31
|
+
export const DROPDOWN_CLAMPS: readonly { cls: string; px: number }[] = Object.freeze(
|
|
32
|
+
KIT_DROPDOWN_LIMITS.clamps.map((c) => ({ cls: `max-h-[${c.px}px]`, px: c.px })),
|
|
33
|
+
);
|
|
34
|
+
/** 下拉面板的默认最大高(最大一档:visibleRows 行 + 半行) */
|
|
35
|
+
export const KIT_DROPDOWN_PANEL_MAX_CLASS: string = DROPDOWN_CLAMPS[0]!.cls;
|
|
31
36
|
/** 下拉 / 菜单面板的表面:浮起级(圆角 + 发丝描边 + 浮起底色 + 双层阴影 + 高光边,recipes/surface.ts 唯一拼装处) */
|
|
32
37
|
const SURFACE_RAISED = kitSurfaceRecipe('raised');
|
|
33
38
|
|
|
@@ -136,19 +141,24 @@ export function focusCellQuiet(node: HTMLElement | null | undefined): void {
|
|
|
136
141
|
node.focus({ preventScroll: true });
|
|
137
142
|
}
|
|
138
143
|
|
|
144
|
+
/** 下拉 / 菜单面板宽度上限(kit-limits#overlay.menuMaxPx = 320,宽度模数阶梯):按最长项取宽到上限,更长的项在行内省略;下限是触发器宽(min-w-full) */
|
|
145
|
+
const MENU_MAX_WIDTH_CLASS = `max-w-[${KIT_OVERLAY_LIMITS.menuMaxPx}px]`;
|
|
146
|
+
|
|
139
147
|
/** 默认的整串面板类:显隐只换整串,`hidden` 不与布局类并存 */
|
|
140
148
|
export const PANEL_HIDDEN_CLASS = 'hidden';
|
|
141
149
|
export const PANEL_SHOWN_CLASS =
|
|
142
|
-
`absolute start-0 top-full z-10 mt-1 ${
|
|
150
|
+
`absolute start-0 top-full z-10 mt-1 ${KIT_DROPDOWN_PANEL_MAX_CLASS} w-max min-w-full ${MENU_MAX_WIDTH_CLASS} overflow-auto ${SURFACE_RAISED} py-1`;
|
|
143
151
|
|
|
144
|
-
//
|
|
145
|
-
const ROW =
|
|
152
|
+
// 选项行高固定(条带阶梯的菜单项行高 strip.menuItemPx),面板最大高才能算成「整数行 + 半行」
|
|
153
|
+
const ROW = KIT_STRIP_MENU_ITEM_CLASS;
|
|
146
154
|
export const OPTION_CLASS = {
|
|
147
155
|
idle: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 px-3 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press`,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
// 键盘当前项与鼠标悬停同一层;选中项 = 主色淡底,选中项上的悬停 / 当前 = tonal 层(第三级,KT-K0-2 / KT-K-select-3)
|
|
157
|
+
active: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-state-layer-hover px-3 text-sm text-fg transition-colors`,
|
|
158
|
+
selected: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors hover:bg-state-layer-tonal-hover active:bg-state-layer-tonal-press`,
|
|
159
|
+
selectedActive: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-state-layer-tonal-hover px-3 text-sm font-medium text-primary-on-soft transition-colors`,
|
|
160
|
+
// 置灰项 = 禁用字色令牌(KT-K-select-5 / KT-K0-4),不降透明度
|
|
161
|
+
disabled: `flex ${ROW} cursor-not-allowed items-center whitespace-nowrap gap-2 px-3 text-sm text-fg-disabled`,
|
|
152
162
|
} as const;
|
|
153
163
|
|
|
154
164
|
export const EMPTY_ROW_CLASS = `flex ${ROW} items-center whitespace-nowrap px-3 text-sm text-fg-subtle`;
|
|
@@ -161,12 +171,12 @@ export function optionClass(selected: boolean, active: boolean, disabled: boolea
|
|
|
161
171
|
|
|
162
172
|
/** 本文件自带的类(供各组件并入候选类清单) */
|
|
163
173
|
export const KIT_POPUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
164
|
-
'hidden', 'absolute', 'start-0', 'top-full', 'z-10', 'mt-1',
|
|
174
|
+
'hidden', 'absolute', 'start-0', 'top-full', 'z-10', 'mt-1', KIT_DROPDOWN_PANEL_MAX_CLASS, KIT_STRIP_MENU_ITEM_CLASS, 'w-full', 'w-max', 'min-w-full', MENU_MAX_WIDTH_CLASS, 'overflow-auto',
|
|
165
175
|
'rounded-md', 'rounded-lg', 'border', 'border-border', 'border-border-subtle', 'bg-surface-raised', 'py-1', DD.panelShadowClass, 'shadow-sm',
|
|
166
176
|
...SURFACE_RAISED.split(/\s+/),
|
|
167
177
|
'flex', 'cursor-pointer', 'cursor-not-allowed', 'items-center', 'whitespace-nowrap', 'gap-2', 'px-3', 'py-2', 'text-sm',
|
|
168
178
|
'text-fg', 'text-fg-subtle', 'bg-surface-sunken', 'font-medium', 'text-primary-on-soft',
|
|
169
|
-
'transition-colors', 'hover:bg-state-layer-hover', 'active:bg-state-layer-press', 'bg-primary-soft', 'text-primary-on-soft', '
|
|
179
|
+
'transition-colors', 'hover:bg-state-layer-hover', 'active:bg-state-layer-press', 'bg-primary-soft', 'text-primary-on-soft', 'text-fg-disabled',
|
|
170
180
|
]);
|
|
171
181
|
|
|
172
182
|
/**
|
|
@@ -196,22 +206,25 @@ const POP_POS: Readonly<Record<PopSide, Readonly<Record<PopAlign, string>>>> = {
|
|
|
196
206
|
start: { start: 'end-full top-0', end: 'bottom-0 end-full' },
|
|
197
207
|
end: { start: 'start-full top-0', end: 'bottom-0 start-full' },
|
|
198
208
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
209
|
+
/** 锚定层与触发器的间距:只此一个值(真源 dropdown.gapPx),所有锚定浮层(下拉 / 菜单 / 气泡 / 筛选面板)共用,构件不自带偏移 */
|
|
210
|
+
export const ANCHORED_GAP_PX: number = KIT_DROPDOWN_LIMITS.gapPx;
|
|
211
|
+
const GAP_UNIT = ANCHORED_GAP_PX / 4;
|
|
212
|
+
const POP_GAP: Readonly<Record<PopSide, string>> = {
|
|
213
|
+
bottom: `mt-${GAP_UNIT}`,
|
|
214
|
+
top: `mb-${GAP_UNIT}`,
|
|
215
|
+
start: `me-${GAP_UNIT}`,
|
|
216
|
+
end: `ms-${GAP_UNIT}`,
|
|
204
217
|
};
|
|
205
218
|
|
|
206
|
-
/** 位置类串(不含 absolute / z /
|
|
207
|
-
export function popPlaceClass(place: PopPlace
|
|
208
|
-
return `${POP_POS[place.side][place.align]} ${POP_GAP[place.side]
|
|
219
|
+
/** 位置类串(不含 absolute / z / 外观类,由组件自己拼):左缘(start)或右缘(end)与触发器对齐 + 真源间距 */
|
|
220
|
+
export function popPlaceClass(place: PopPlace): string {
|
|
221
|
+
return `${POP_POS[place.side][place.align]} ${POP_GAP[place.side]}`;
|
|
209
222
|
}
|
|
210
223
|
|
|
211
224
|
/** 全部位置类(供类名候选清单) */
|
|
212
225
|
export const KIT_POPUP_PLACE_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
213
226
|
[...new Set((['top', 'bottom', 'start', 'end'] as const).flatMap((s) =>
|
|
214
|
-
(['start', 'end'] as const).flatMap((a) => `${POP_POS[s][a]} ${POP_GAP[s]
|
|
227
|
+
(['start', 'end'] as const).flatMap((a) => `${POP_POS[s][a]} ${POP_GAP[s]}`.split(' '))))],
|
|
215
228
|
);
|
|
216
229
|
|
|
217
230
|
const FLIP_OPPOSITE: Readonly<Record<PopSide, PopSide>> = { top: 'bottom', bottom: 'top', start: 'end', end: 'start' };
|
|
@@ -222,7 +235,7 @@ export function resolvePopPlace(
|
|
|
222
235
|
size: { width: number; height: number },
|
|
223
236
|
viewport: { width: number; height: number },
|
|
224
237
|
pref: PopPlace,
|
|
225
|
-
gapPx =
|
|
238
|
+
gapPx = ANCHORED_GAP_PX,
|
|
226
239
|
rtl = false,
|
|
227
240
|
): PopPlace {
|
|
228
241
|
const { width: w, height: h } = size;
|
|
@@ -268,7 +281,7 @@ export function showPopupFitted(
|
|
|
268
281
|
anchor: HTMLElement,
|
|
269
282
|
pref: PopPlace,
|
|
270
283
|
classFor: (place: PopPlace) => string,
|
|
271
|
-
gapPx =
|
|
284
|
+
gapPx = ANCHORED_GAP_PX,
|
|
272
285
|
): PopPlace {
|
|
273
286
|
const place = fitPopupPlace(panel, anchor, pref, classFor, gapPx);
|
|
274
287
|
// 锚定浮层统一标记(anchored-layer.ts):落位后的实际方向,重定位 / 翻转时随之更新
|
|
@@ -297,7 +310,7 @@ function fitPopupPlace(
|
|
|
297
310
|
|
|
298
311
|
/** 气泡的偏好位置:目标下方、左对齐;贴边时由 showPopupFitted 翻转 */
|
|
299
312
|
export const POPUP_TIP_PREF: PopPlace = { side: 'bottom', align: 'start' };
|
|
300
|
-
export const popupTipClass = (place: PopPlace): string => `${POPUP_TIP_BASE} ${popPlaceClass(place
|
|
313
|
+
export const popupTipClass = (place: PopPlace): string => `${POPUP_TIP_BASE} ${popPlaceClass(place)}`;
|
|
301
314
|
export const POPUP_TIP_SHOWN_CLASS = popupTipClass(POPUP_TIP_PREF);
|
|
302
315
|
|
|
303
316
|
// ── 下拉面板的贴边翻转(Select / Combobox / Cascader / TreeSelect / TimePicker / ColorPicker / Mentions / TagInput / Navbar / Menu columns 共用)──
|
|
@@ -309,12 +322,7 @@ export const POPUP_TIP_SHOWN_CLASS = popupTipClass(POPUP_TIP_PREF);
|
|
|
309
322
|
|
|
310
323
|
/** 下拉面板外观类(不含位置类):与 PANEL_SHOWN_CLASS 同一份外观 */
|
|
311
324
|
export const PANEL_BASE_CLASS =
|
|
312
|
-
`absolute z-10 ${
|
|
313
|
-
|
|
314
|
-
/** 空间不足时面板内部滚动的 max-h 闭集档位(px = 刻度 x 4),从大到小;每档都是「整数行 + 半行」(真源 dropdown.clamps),空间不够也不腰斩一行 */
|
|
315
|
-
export const DROPDOWN_CLAMPS: readonly { cls: string; px: number }[] = Object.freeze(
|
|
316
|
-
DD.clamps.map((c, i) => ({ cls: c.cls, px: KIT_DROPDOWN_LIMITS.clamps[i]!.px })),
|
|
317
|
-
);
|
|
325
|
+
`absolute z-10 ${KIT_DROPDOWN_PANEL_MAX_CLASS} w-max min-w-full ${MENU_MAX_WIDTH_CLASS} overflow-auto ${SURFACE_RAISED} py-1`;
|
|
318
326
|
|
|
319
327
|
/** 下拉翻转用到的全部类(位置类、间距类、max-h 档位、滚动) */
|
|
320
328
|
export const KIT_DROPDOWN_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
@@ -334,7 +342,7 @@ export function resolveDropdown(
|
|
|
334
342
|
size: { width: number; height: number },
|
|
335
343
|
viewport: { width: number; height: number },
|
|
336
344
|
prefAlign: PopAlign = 'start',
|
|
337
|
-
gapPx =
|
|
345
|
+
gapPx = ANCHORED_GAP_PX,
|
|
338
346
|
rtl = false,
|
|
339
347
|
): { place: PopPlace; clampPx: number | null } {
|
|
340
348
|
if (size.width === 0 && size.height === 0) return { place: { side: 'bottom', align: prefAlign }, clampPx: null };
|
|
@@ -374,9 +382,8 @@ export function showDropdownFitted(
|
|
|
374
382
|
anchor: HTMLElement,
|
|
375
383
|
base: string,
|
|
376
384
|
prefAlign: PopAlign = 'start',
|
|
377
|
-
gap: 1 | 2 = 1,
|
|
378
385
|
): PopPlace {
|
|
379
|
-
const place = fitDropdownPlace(panel, anchor, base, prefAlign
|
|
386
|
+
const place = fitDropdownPlace(panel, anchor, base, prefAlign);
|
|
380
387
|
markAnchored(panel, place);
|
|
381
388
|
return place;
|
|
382
389
|
}
|
|
@@ -386,9 +393,8 @@ function fitDropdownPlace(
|
|
|
386
393
|
anchor: HTMLElement,
|
|
387
394
|
base: string,
|
|
388
395
|
prefAlign: PopAlign,
|
|
389
|
-
gap: 1 | 2,
|
|
390
396
|
): PopPlace {
|
|
391
|
-
const classFor = (place: PopPlace): string => `${base} ${popPlaceClass(place
|
|
397
|
+
const classFor = (place: PopPlace): string => `${base} ${popPlaceClass(place)}`;
|
|
392
398
|
const pref: PopPlace = { side: 'bottom', align: prefAlign };
|
|
393
399
|
panel.className = classFor(pref);
|
|
394
400
|
if (typeof panel.getBoundingClientRect !== 'function') return pref;
|
|
@@ -397,8 +403,8 @@ function fitDropdownPlace(
|
|
|
397
403
|
if (vw === 0 || vh === 0) return pref;
|
|
398
404
|
const a = anchor.getBoundingClientRect();
|
|
399
405
|
const b = panel.getBoundingClientRect();
|
|
400
|
-
const { place, clampPx } = resolveDropdown(a, { width: b.width, height: b.height }, { width: vw, height: vh }, prefAlign,
|
|
401
|
-
const next = clampPx === null ? classFor(place) : `${clampDropdownClass(base, clampPx)} ${popPlaceClass(place
|
|
406
|
+
const { place, clampPx } = resolveDropdown(a, { width: b.width, height: b.height }, { width: vw, height: vh }, prefAlign, ANCHORED_GAP_PX, kitDirAt(anchor) === 'rtl');
|
|
407
|
+
const next = clampPx === null ? classFor(place) : `${clampDropdownClass(base, clampPx)} ${popPlaceClass(place)}`;
|
|
402
408
|
if (panel.className !== next) panel.className = next;
|
|
403
409
|
return place;
|
|
404
410
|
}
|
package/src/base/qty-stepper.ts
CHANGED
|
@@ -12,24 +12,29 @@
|
|
|
12
12
|
import { FIELD_INVALID_CLASS, classCandidates, bool, num, sizeOf, str, type KitProps, type KitSize } from './shared';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
14
|
import { setKitFace } from '../recipes';
|
|
15
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
16
|
+
import { kitDividerRecipe } from '../recipes/divider';
|
|
15
17
|
|
|
18
|
+
// 步进器是一个控件(减 / 输入 / 加 同在一圈控件线里):外圈 = 控件轮廓(kitControlEdgeRecipe,KT-B1 / §4 C6),段间 = 分隔线出口(KT-B5)
|
|
19
|
+
const EDGE = kitControlEdgeRecipe({ wrapper: true });
|
|
20
|
+
const SEP = `${kitDividerRecipe('start')} ${kitDividerRecipe('end')}`;
|
|
16
21
|
const GROUP: Record<KitSize, string> = {
|
|
17
|
-
sm:
|
|
18
|
-
md:
|
|
19
|
-
lg:
|
|
22
|
+
sm: `inline-flex h-6 items-stretch overflow-hidden rounded-md ${EDGE} bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring`,
|
|
23
|
+
md: `inline-flex h-8 items-stretch overflow-hidden rounded-md ${EDGE} bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring`,
|
|
24
|
+
lg: `inline-flex h-10 items-stretch overflow-hidden rounded-md ${EDGE} bg-surface text-base transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring`,
|
|
20
25
|
};
|
|
21
26
|
const GROUP_OFF: Record<KitSize, string> = {
|
|
22
|
-
sm:
|
|
23
|
-
md:
|
|
24
|
-
lg:
|
|
27
|
+
sm: `inline-flex h-6 items-stretch overflow-hidden rounded-md ${EDGE} bg-surface-sunken text-sm opacity-60`,
|
|
28
|
+
md: `inline-flex h-8 items-stretch overflow-hidden rounded-md ${EDGE} bg-surface-sunken text-sm opacity-60`,
|
|
29
|
+
lg: `inline-flex h-10 items-stretch overflow-hidden rounded-md ${EDGE} bg-surface-sunken text-base opacity-60`,
|
|
25
30
|
};
|
|
26
31
|
const BTN_ON = 'inline-flex w-8 shrink-0 cursor-pointer items-center justify-center 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';
|
|
27
32
|
const BTN_OFF = 'inline-flex w-8 shrink-0 cursor-not-allowed items-center justify-center text-fg-subtle opacity-60';
|
|
28
33
|
// 无 preflight:input 不继承分组的字号(浏览器默认 13px),所以按档位自己写 text-sm / text-base
|
|
29
34
|
export const STEPPER_INPUT: Record<KitSize, string> = {
|
|
30
|
-
sm:
|
|
31
|
-
md:
|
|
32
|
-
lg:
|
|
35
|
+
sm: `w-14 min-w-0 appearance-none autofill-clear ${SEP} bg-transparent px-1 text-center text-sm text-fg focus-visible:outline-none read-only:bg-surface-sunken`,
|
|
36
|
+
md: `w-14 min-w-0 appearance-none autofill-clear ${SEP} bg-transparent px-1 text-center text-sm text-fg focus-visible:outline-none read-only:bg-surface-sunken`,
|
|
37
|
+
lg: `w-14 min-w-0 appearance-none autofill-clear ${SEP} bg-transparent px-1 text-center text-base text-fg focus-visible:outline-none read-only:bg-surface-sunken`,
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
export const KIT_QTY_STEPPER_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
package/src/base/reason-tip.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// - 原因为空 / 动作未置灰:不建气泡、不改 aria-describedby,行为与没有该声明时完全相同。
|
|
10
10
|
// 文字一律 textContent;气泡外观取 popup 底座的 tooltip 类(去掉 pointer-events-none,浮层根里需要 pointer-events-auto)。
|
|
11
11
|
|
|
12
|
-
import { classCandidates } from '
|
|
12
|
+
import { classCandidates } from '../shared/class-candidates';
|
|
13
13
|
import {
|
|
14
14
|
KIT_POPUP_PLACE_CLASS_CANDIDATES, POPUP_TIP_BASE, POPUP_TIP_HIDDEN_CLASS, POPUP_TIP_PREF, popPlaceClass, releaseDropdown, syncAnchored,
|
|
15
15
|
type PopPlace,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { addIdToken, nextUid, removeIdToken } from './shared';
|
|
18
18
|
|
|
19
19
|
const REASON_TIP_BASE = POPUP_TIP_BASE.split(/\s+/).filter((t) => t !== 'pointer-events-none').join(' ');
|
|
20
|
-
const reasonTipClass = (place: PopPlace): string => `${REASON_TIP_BASE} ${popPlaceClass(place
|
|
20
|
+
const reasonTipClass = (place: PopPlace): string => `${REASON_TIP_BASE} ${popPlaceClass(place)}`;
|
|
21
21
|
|
|
22
22
|
export const KIT_REASON_TIP_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
23
23
|
POPUP_TIP_HIDDEN_CLASS, REASON_TIP_BASE, KIT_POPUP_PLACE_CLASS_CANDIDATES, 'pointer-events-auto',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// resize-handle:可拖动分隔手柄的行为(role=separator
|
|
1
|
+
// resize-handle:可拖动分隔手柄的行为(role=separator),基础层与页面框共用的小模块。
|
|
2
2
|
//
|
|
3
3
|
// 只管行为不管画面:给一个已有元素补 role=separator、tabindex、aria-orientation、aria-valuenow/min/max,
|
|
4
4
|
// 指针拖动(pointer capture)、方向键按档位移动、Home / End 到边界、Enter 与双击复位。
|
package/src/base/segmented.ts
CHANGED
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
import { createKeyboardWiring } from 'soma-core/keyboard';
|
|
12
12
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
13
|
+
import { textWidthEm } from 'soma-foundation/arrange';
|
|
14
|
+
import { arrangeSegmented } from 'soma-foundation/arrange/table';
|
|
13
15
|
import { setKitFace } from '../recipes';
|
|
16
|
+
import { kitButtonEdgeRecipe } from '../recipes/control';
|
|
17
|
+
import { kitCompactGroupRecipe, markKitCompactGroup } from '../recipes/compact-group';
|
|
18
|
+
import { kitTabRecipe } from '../recipes/tabs';
|
|
14
19
|
import {
|
|
15
20
|
applyCommon, bool, classCandidates, joinClass, num, optionsKey, optionsOf, sameValue, sizeOf,
|
|
16
21
|
type KitOption, type KitProps, type KitSize, type KitView,
|
|
@@ -18,53 +23,42 @@ import {
|
|
|
18
23
|
|
|
19
24
|
// ── 类串(整串字面量,不拼接)─────────────────────────────────
|
|
20
25
|
|
|
21
|
-
//
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
lg: {
|
|
36
|
-
idle: 'inline-flex h-10 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md px-4 text-base font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
37
|
-
on: 'inline-flex h-10 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md bg-primary-soft px-4 text-base font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
38
|
-
off: 'inline-flex h-10 min-w-0 flex-1 whitespace-nowrap cursor-not-allowed items-center justify-center rounded-md px-4 text-base font-medium text-fg-subtle opacity-60',
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const SEG_ROOT_V = 'inline-flex flex-col items-stretch gap-0.5';
|
|
43
|
-
const SEG_ROOT_BLOCK_V = 'flex w-full flex-col items-stretch gap-0.5';
|
|
44
|
-
const TOG_ROOT = 'inline-flex flex-wrap items-center gap-2';
|
|
45
|
-
const TOG_ROOT_V = 'inline-flex flex-col items-stretch gap-2';
|
|
26
|
+
// 分段切换的类串唯一出口 recipes/tabs(种类 segment):浅色底圆角槽 + 槽内浮起的亮面选中块;与工作页签 / 页内页签三种形体不同
|
|
27
|
+
const SEG = kitTabRecipe();
|
|
28
|
+
const SEG_ROOT = SEG.segRoot;
|
|
29
|
+
const SEG_ROOT_BLOCK = SEG.segRootBlock;
|
|
30
|
+
const SEG_ROOT_EQUAL = SEG.segRootEqual;
|
|
31
|
+
const SEG_ITEM: Record<KitSize, { idle: string; on: string; off: string }> = SEG.segItem;
|
|
32
|
+
const SEG_ROOT_V = SEG.segRootV;
|
|
33
|
+
const SEG_ROOT_BLOCK_V = SEG.segRootBlockV;
|
|
34
|
+
// 多选按钮组(Checkbox variant: buttons)= 紧凑组合(KT-B7):相邻钮共用一条边、首尾才有外侧圆角、悬停 / 聚焦者在上;
|
|
35
|
+
// 待命 / 禁用钮的边 = 带文字中性按钮描边(kitButtonEdgeRecipe,KT-B1),按下钮的边 = 强调指示(border-primary)
|
|
36
|
+
const TOG_ROOT = kitCompactGroupRecipe('x');
|
|
37
|
+
const TOG_ROOT_V = kitCompactGroupRecipe('y');
|
|
38
|
+
const TOG_EDGE = kitButtonEdgeRecipe();
|
|
46
39
|
const OPT_ICON = 'shrink-0';
|
|
40
|
+
const OPT_COUNT = 'ms-1.5 text-xs tabular-nums text-fg-subtle';
|
|
47
41
|
const OPT_GAP = 'gap-1.5';
|
|
48
42
|
const TOG_ITEM: Record<KitSize, { idle: string; on: string; off: string }> = {
|
|
49
43
|
sm: {
|
|
50
|
-
idle: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md
|
|
44
|
+
idle: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md bg-surface px-2.5 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
51
45
|
on: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-2.5 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
52
|
-
off: 'inline-flex h-6 cursor-not-allowed items-center justify-center rounded-md
|
|
46
|
+
off: 'inline-flex h-6 cursor-not-allowed items-center justify-center rounded-md bg-control-disabled px-2.5 text-sm text-fg-disabled',
|
|
53
47
|
},
|
|
54
48
|
md: {
|
|
55
|
-
idle: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md
|
|
49
|
+
idle: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-surface px-3 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
56
50
|
on: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
57
|
-
off: 'inline-flex h-8 cursor-not-allowed items-center justify-center rounded-md
|
|
51
|
+
off: 'inline-flex h-8 cursor-not-allowed items-center justify-center rounded-md bg-control-disabled px-3 text-sm text-fg-disabled',
|
|
58
52
|
},
|
|
59
53
|
lg: {
|
|
60
|
-
idle: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md
|
|
54
|
+
idle: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md bg-surface px-4 text-base text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
61
55
|
on: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-4 text-base font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
62
|
-
off: 'inline-flex h-10 cursor-not-allowed items-center justify-center rounded-md
|
|
56
|
+
off: 'inline-flex h-10 cursor-not-allowed items-center justify-center rounded-md bg-control-disabled px-4 text-base text-fg-disabled',
|
|
63
57
|
},
|
|
64
58
|
};
|
|
65
59
|
|
|
66
60
|
export const KIT_SEGMENTED_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
67
|
-
SEG_ROOT, SEG_ROOT_BLOCK, SEG_ROOT_V, SEG_ROOT_BLOCK_V, TOG_ROOT, TOG_ROOT_V, OPT_ICON, OPT_GAP,
|
|
61
|
+
SEG_ROOT, SEG_ROOT_BLOCK, SEG_ROOT_EQUAL, 'flex-none', SEG_ROOT_V, SEG_ROOT_BLOCK_V, TOG_ROOT, TOG_ROOT_V, OPT_ICON, OPT_GAP, OPT_COUNT,
|
|
68
62
|
Object.values(SEG_ITEM).flatMap((c) => [c.idle, c.on, c.off]),
|
|
69
63
|
Object.values(TOG_ITEM).flatMap((c) => [c.idle, c.on, c.off]),
|
|
70
64
|
);
|
|
@@ -97,6 +91,13 @@ export function fillOptionContent(host: HTMLElement, option: KitOption, named: H
|
|
|
97
91
|
text.textContent = option.label;
|
|
98
92
|
host.appendChild(text);
|
|
99
93
|
}
|
|
94
|
+
// 计数(分段筛选):尾部一个小号弱色数字,等宽数字防跳动
|
|
95
|
+
if (option.count !== undefined) {
|
|
96
|
+
const count = document.createElement('span');
|
|
97
|
+
count.className = OPT_COUNT;
|
|
98
|
+
count.textContent = String(option.count);
|
|
99
|
+
host.appendChild(count);
|
|
100
|
+
}
|
|
100
101
|
const name = iconOnlyName(option);
|
|
101
102
|
if (name !== null) named.setAttribute('aria-label', name);
|
|
102
103
|
else named.removeAttribute('aria-label');
|
|
@@ -224,7 +225,13 @@ export function createSegmentedView(): KitView {
|
|
|
224
225
|
else root.removeAttribute('aria-disabled');
|
|
225
226
|
if (readonly) root.setAttribute('aria-readonly', 'true');
|
|
226
227
|
else root.removeAttribute('aria-readonly');
|
|
227
|
-
|
|
228
|
+
// 各段宽度(排布引擎 arrangeSegmented):横排非撑满时,段数少且文案长度相近 = 等宽(grid 等分最宽一段的内容宽),否则按内容宽 + 统一内边距(段不拉伸)
|
|
229
|
+
const equal = !vertical && !bool(p.block) && arrangeSegmented(options.map((o) => textWidthEm(o.label))).mode === 'equal';
|
|
230
|
+
const rootClass = bool(p.block) ? (vertical ? SEG_ROOT_BLOCK_V : SEG_ROOT_BLOCK) : vertical ? SEG_ROOT_V : equal ? SEG_ROOT_EQUAL : SEG_ROOT;
|
|
231
|
+
root.className = joinClass(rootClass, p.class);
|
|
232
|
+
if (!vertical && !bool(p.block) && !equal) {
|
|
233
|
+
for (const b of Array.from(root.querySelectorAll<HTMLElement>('[role="radio"]'))) b.className = b.className.replace(/(^|\s)flex-1(?=\s|$)/, '$1flex-none');
|
|
234
|
+
}
|
|
228
235
|
},
|
|
229
236
|
};
|
|
230
237
|
}
|
|
@@ -277,7 +284,7 @@ export function createToggleView(): KitView {
|
|
|
277
284
|
const o = options.find((x) => String(x.value) === b.dataset.key);
|
|
278
285
|
const on = values.includes(b.dataset.key ?? '');
|
|
279
286
|
const off = disabled || o?.disabled === true;
|
|
280
|
-
b.className = joinClass(off ? TOG_ITEM[size].off : on ? TOG_ITEM[size].on : TOG_ITEM[size].idle
|
|
287
|
+
b.className = joinClass(off ? `${TOG_ITEM[size].off} ${TOG_EDGE}` : on ? TOG_ITEM[size].on : `${TOG_ITEM[size].idle} ${TOG_EDGE}`, o?.icon !== undefined && o.label !== '' ? OPT_GAP : '');
|
|
281
288
|
// 多选按钮组的每一枚在 idle / on / off 三态都带边框 + 底色(on 是 primary-soft 描边,off 是 surface-sunken),一律标 raised
|
|
282
289
|
setKitFace(b, 'raised');
|
|
283
290
|
b.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
@@ -286,7 +293,9 @@ export function createToggleView(): KitView {
|
|
|
286
293
|
}
|
|
287
294
|
root.setAttribute('role', 'group');
|
|
288
295
|
applyCommon(root, p);
|
|
289
|
-
|
|
296
|
+
const vertical = orientationOf(p.orientation) === 'vertical';
|
|
297
|
+
root.className = joinClass(vertical ? TOG_ROOT_V : TOG_ROOT, p.class);
|
|
298
|
+
markKitCompactGroup(root, vertical ? 'y' : 'x');
|
|
290
299
|
},
|
|
291
300
|
};
|
|
292
301
|
}
|
package/src/base/select.ts
CHANGED
|
@@ -32,6 +32,7 @@ export function createSelect(): SomaComponentDefinition {
|
|
|
32
32
|
value: { type: 'string', default: '', desc: '当前选中项的 value;multiple 时是 value 数组' },
|
|
33
33
|
options: OPTIONS_PROP,
|
|
34
34
|
placeholder: { type: 'string', default: '', desc: '无选中时字段里显示的提示文字' },
|
|
35
|
+
variant: { type: 'enum', values: ['outline', 'filled'], default: 'outline', desc: 'outline = 描边;filled = 浅底' },
|
|
35
36
|
searchable: { type: 'boolean', default: false, desc: '可搜索:字段换成输入框,输入过滤选项,↑↓ 走项、Enter 确认、Escape 收起' },
|
|
36
37
|
multiple: { type: 'boolean', default: false, desc: '多选:value 是数组,点选项切换选中、面板保持展开' },
|
|
37
38
|
group: { type: 'string', default: '', desc: '选项里承载分组标题的字段名(如 region);同标题归一组,组标题粘顶' },
|