soma-kit 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +158 -4
- package/spec/generated/kit-page.schema.json +139 -5
- package/spec/kit-grammar.json +438 -87
- package/spec/kit-grammar.schema.json +11 -3
- package/src/app/app-config.ts +83 -5
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +17 -5
- package/src/app/kit-view-context.ts +163 -14
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +3 -1
- package/src/app/server.ts +40 -3
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +57 -12
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/index.ts +27 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +23 -12
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +9 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +24 -22
- package/src/base/shared.ts +169 -23
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +63 -33
- package/src/base/text.ts +42 -13
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -10
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +2 -2
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/import-wizard/shell.ts +2 -1
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +102 -10
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +4 -1
- package/src/biz/multi-board/shell.ts +8 -5
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +18 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +139 -10
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +22 -160
- package/src/biz/standard-crud/shell.ts +16 -44
- package/src/biz/step-form/shell.ts +5 -5
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/view-writes.ts +69 -60
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +51 -7
- package/src/compile/component-candidates.ts +12 -1
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +36 -8
- package/src/compile/types.ts +13 -1
- package/src/compile/view-check.ts +149 -16
- package/src/data/amount-breakdown.ts +6 -1
- package/src/data/approval-flow.ts +1 -1
- package/src/data/assignment-picker.ts +53 -27
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +2 -2
- package/src/data/carousel.ts +8 -6
- package/src/data/chart.ts +141 -10
- package/src/data/checklist.ts +18 -5
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +2 -2
- package/src/data/confirm-dialog.ts +71 -18
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +4 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +25 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/gantt.ts +5 -2
- package/src/data/hero.ts +2 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +6 -1
- package/src/data/item-list.ts +18 -10
- package/src/data/kanban.ts +39 -10
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +45 -13
- package/src/data/mockup.ts +8 -4
- package/src/data/modal-dialog.ts +29 -9
- package/src/data/navbar.ts +5 -5
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +354 -48
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +17 -7
- package/src/data/permission-matrix.ts +33 -11
- package/src/data/permission-tree.ts +47 -22
- package/src/data/pricing-table.ts +21 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +23 -2
- package/src/data/record-picker.ts +13 -7
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +79 -26
- package/src/data/rule-builder.ts +8 -8
- package/src/data/shape-util.ts +23 -9
- package/src/data/stat-group.ts +170 -29
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +2 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +3 -3
- package/src/data/system-switcher.ts +1 -1
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +1 -1
- package/src/data/transfer.ts +36 -16
- package/src/data/tree-table.ts +62 -36
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +19 -10
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/page-bar.ts +14 -13
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +15 -10
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +2 -1
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +2 -2
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/view.ts +141 -33
- package/src/generated/kit-grammar-runtime.ts +239 -55
- package/src/i18n/kit-text.ts +63 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/arrange.ts +42 -8
- package/src/object-renderer/collection-parts.ts +241 -60
- package/src/object-renderer/collection-table.ts +109 -5
- package/src/object-renderer/collection.ts +174 -36
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +30 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-static.ts +370 -30
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/render-object.ts +54 -6
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +135 -27
- package/src/object-renderer/table-tools.ts +12 -11
- package/src/object-renderer/types.ts +78 -7
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +46 -1
- package/src/recipes/control.ts +70 -12
- package/src/recipes/index.ts +49 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +75 -17
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +34 -5
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +40 -3
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +13 -1
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +372 -12
- package/src/theme/kit-theme.tpl +372 -12
- package/src/theme/nine-dim-structure.ts +177 -7
- package/src/theme/surface-layers.ts +4 -0
- package/src/theme/theme-tokens.ts +53 -13
- package/src/theme/theme-types.ts +32 -0
- package/src/biz/shared/remove-key.ts +0 -6
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 锚定浮层的统一构件(美化方案 G):无遮罩、锚定触发点、空间不足自动翻转的小浮层——提示、菜单、表头筛选面板、选择器下拉、日期面板、气泡。
|
|
2
|
+
//
|
|
3
|
+
// 一份实现,分三处:
|
|
4
|
+
// - 定位与翻转:popup.ts 的 resolvePopPlace / resolveDropdown(纯函数,贴边翻转与对齐翻转)+ portal-core 的 createPanelPortalWith(挂浮层根、
|
|
5
|
+
// 锚盒跟随触发点、随滚动与尺寸变化重定位);
|
|
6
|
+
// - 标记(本文件):面板根标 data-kit-anchored 与 data-kit-placement="top|bottom|start|end"(落位后的实际方向,翻转 / 重定位后随之更新)。
|
|
7
|
+
// 样式只认这两个属性(nine-dim-structure 的「载体与布局构件」规则(carrierRules)):进场 120ms / 出场 80ms(motion.json 的 popover 意图令牌),从锚点方向小位移 + 缩放 + 淡入,
|
|
8
|
+
// 减弱动效只淡入淡出;表面(浮起面 + 高光边 + 双层阴影)读 --soma-surface-raised / --soma-edge-highlight / --soma-elevation-raised;
|
|
9
|
+
// - 出场(本文件的 leaveAnchored):复用 overlay-runtime 的隐藏前过渡机制(beginKitLeave:标 data-kit-leaving + inert,等退场动画结束再收尾,
|
|
10
|
+
// 带超时兜底,没有退场动画则立即收尾)。
|
|
11
|
+
// 层栈与焦点域仍各有唯一裁决者:Esc 只关栈顶由 core 浮层挂载点登记的层栈裁决,焦点隔离 / 回焦归各组件的 focus-scope;本文件不另立。
|
|
12
|
+
// 不引入浏览器内置 Popover API。
|
|
13
|
+
|
|
14
|
+
import { beginKitLeave, type KitLeaveHandle } from './overlay-runtime';
|
|
15
|
+
|
|
16
|
+
/** 锚定浮层根标记(无遮罩的锚定面板) */
|
|
17
|
+
export const KIT_ANCHORED_ATTR = 'data-kit-anchored';
|
|
18
|
+
/** 落位后的实际方向:面板在锚点的哪一侧 */
|
|
19
|
+
export const KIT_PLACEMENT_ATTR = 'data-kit-placement';
|
|
20
|
+
|
|
21
|
+
export type KitPlacement = 'top' | 'bottom' | 'start' | 'end';
|
|
22
|
+
const PLACEMENTS: readonly KitPlacement[] = ['top', 'bottom', 'start', 'end'];
|
|
23
|
+
|
|
24
|
+
/** 纯函数:任意值 -> 合法方向(非法回落 bottom) */
|
|
25
|
+
export function placementSideOf(raw: unknown): KitPlacement {
|
|
26
|
+
return PLACEMENTS.includes(raw as KitPlacement) ? (raw as KitPlacement) : 'bottom';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 给面板打锚定浮层标记(幂等;每次落位 / 翻转后重复调用即更新方向) */
|
|
30
|
+
export function markAnchored(panel: HTMLElement, place: { side: string }): void {
|
|
31
|
+
const side = placementSideOf(place.side);
|
|
32
|
+
if (!panel.hasAttribute(KIT_ANCHORED_ATTR)) panel.setAttribute(KIT_ANCHORED_ATTR, '');
|
|
33
|
+
if (panel.getAttribute(KIT_PLACEMENT_ATTR) !== side) panel.setAttribute(KIT_PLACEMENT_ATTR, side);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 摘掉标记(面板收起后不再是锚定浮层) */
|
|
37
|
+
export function unmarkAnchored(panel: HTMLElement): void {
|
|
38
|
+
panel.removeAttribute(KIT_ANCHORED_ATTR);
|
|
39
|
+
panel.removeAttribute(KIT_PLACEMENT_ATTR);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 出场:有退场动画就先播完再调 done,没有(无关键帧 / jsdom / 无窗口)立即调 done。
|
|
44
|
+
* 返回句柄:退场中被重新打开时调 cancel(撤销退场状态,不调 done);立即收尾时返回 null。
|
|
45
|
+
*/
|
|
46
|
+
export function leaveAnchored(panel: HTMLElement, done: () => void): KitLeaveHandle | null {
|
|
47
|
+
const handle = beginKitLeave(panel, done);
|
|
48
|
+
if (handle === null) done();
|
|
49
|
+
return handle;
|
|
50
|
+
}
|
package/src/base/button.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
5
5
|
import {
|
|
6
6
|
CLASS_PROP, ID_PROPS, SIZE_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES, KIT_SPINNER_CLASS,
|
|
7
|
-
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setAttr, sizeOf, str, withBadgeAnchor, withTooltip, type KitSize,
|
|
7
|
+
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setAttr, sizeOf, str, withBadgeAnchor, withTooltip, type KitSize, type KitView,
|
|
8
8
|
} from './shared';
|
|
9
9
|
import {
|
|
10
10
|
KIT_PART_ATTRIBUTE,
|
|
@@ -14,8 +14,11 @@ import {
|
|
|
14
14
|
kitControlPartOf,
|
|
15
15
|
kitControlRecipe,
|
|
16
16
|
kitSelectedRecipe,
|
|
17
|
+
kitDisabledRecipe,
|
|
17
18
|
setKitFace,
|
|
18
19
|
} from '../recipes';
|
|
20
|
+
import { KIT_REASON_TIP_CLASS_CANDIDATES, releaseReasonTip, syncReasonTip } from './reason-tip';
|
|
21
|
+
import { KIT_BUSY_SPIN_ATTR, KIT_BUSY_SPIN_CLASS_CANDIDATES } from './action-busy';
|
|
19
22
|
|
|
20
23
|
export {
|
|
21
24
|
KIT_PART_BUTTON,
|
|
@@ -57,16 +60,23 @@ export const BUTTON_CLASS: Record<ButtonVariant, Record<KitSize, string>> = {
|
|
|
57
60
|
},
|
|
58
61
|
};
|
|
59
62
|
|
|
63
|
+
const SPINNER_WRAP_CLASS = 'absolute inset-0 flex items-center justify-center';
|
|
60
64
|
const SPINNER_CLASS = KIT_SPINNER_CLASS;
|
|
61
65
|
|
|
62
66
|
// icon_only:宽度等于高度,文字藏起来只留符号(横向内边距被 border-box 的定宽吃掉,符号居中溢出)
|
|
63
67
|
const ICON_ONLY_WIDTH: Record<KitSize, string> = { sm: 'w-8', md: 'w-9', lg: 'w-10' };
|
|
64
68
|
|
|
65
69
|
export const KIT_BUTTON_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
66
|
-
Object.values(BUTTON_CLASS).flatMap((m) => Object.values(m)), Object.values(ICON_ONLY_WIDTH),
|
|
67
|
-
|
|
70
|
+
Object.values(BUTTON_CLASS).flatMap((m) => Object.values(m)), Object.values(ICON_ONLY_WIDTH), SPINNER_WRAP_CLASS, SPINNER_CLASS,
|
|
71
|
+
KIT_BUSY_SPIN_CLASS_CANDIDATES, 'hidden', 'inline-block', 'relative',
|
|
72
|
+
KIT_BADGE_CLASS_CANDIDATES, KIT_REASON_TIP_CLASS_CANDIDATES, kitDisabledRecipe('aria'),
|
|
68
73
|
);
|
|
69
74
|
|
|
75
|
+
/** 带原因的置灰:disabled 为真、不在加载中、原因非空——此时只留 aria-disabled(可聚焦),原因走气泡 */
|
|
76
|
+
function reasonOf(p: Record<string, unknown>): string {
|
|
77
|
+
return bool(p.disabled) && !bool(p.loading) ? str(p.disabled_reason).trim() : '';
|
|
78
|
+
}
|
|
79
|
+
|
|
70
80
|
function variantOf(raw: unknown): ButtonVariant {
|
|
71
81
|
return raw === 'neutral' || raw === 'danger' || raw === 'ghost' || raw === 'tonal' ? raw : 'primary';
|
|
72
82
|
}
|
|
@@ -84,6 +94,7 @@ export function createButton(): SomaComponentDefinition {
|
|
|
84
94
|
...BADGE_PROPS,
|
|
85
95
|
loading: { type: 'boolean', default: false, desc: '加载中:显示转圈,不响应点击' },
|
|
86
96
|
disabled: { type: 'boolean', default: false },
|
|
97
|
+
disabled_reason: { type: 'string', default: '', desc: '置灰原因文案:disabled 为真且非空时,按钮不用原生 disabled(只留 aria-disabled,保持可聚焦),原因经气泡在悬停 / 聚焦时显示(aria-describedby,Esc 隐藏);点击 / Enter / Space 仍不抛 click;disabled 为假或为空串时与没写一样' },
|
|
87
98
|
type: { type: 'enum', values: ['button', 'submit', 'reset'], default: 'button', desc: '原生按钮类型' },
|
|
88
99
|
tooltip: TOOLTIP_PROP,
|
|
89
100
|
permission: { type: 'string', default: '', desc: '权限码;非空且当前身份无此权限时整个按钮不渲染(点击拦截另在事件管道尾段)' },
|
|
@@ -96,8 +107,8 @@ export function createButton(): SomaComponentDefinition {
|
|
|
96
107
|
},
|
|
97
108
|
},
|
|
98
109
|
services: ['permission'],
|
|
99
|
-
templateHtml: `<button data-soma-id="root" data-kit-part="${KIT_PART_BUTTON}" type="button" class="${BUTTON_CLASS.primary.md}"><span data-soma-id="spin" aria-hidden="true" class="hidden"></span><span data-soma-id="icon" aria-hidden="true" class="hidden"></span><span data-soma-id="label"></span></button>`,
|
|
100
|
-
controllerFactory: createKitController(() => withTooltip({
|
|
110
|
+
templateHtml: `<button data-soma-id="root" data-kit-part="${KIT_PART_BUTTON}" type="button" class="${BUTTON_CLASS.primary.md}"><span data-soma-id="spin" aria-hidden="true" class="hidden"><span class="${SPINNER_CLASS}"></span></span><span data-soma-id="icon" aria-hidden="true" class="hidden"></span><span data-soma-id="label"></span></button>`,
|
|
111
|
+
controllerFactory: createKitController(() => withReasonTip(withTooltip({
|
|
101
112
|
attach(root, api) {
|
|
102
113
|
const onClick = (event: Event): void => {
|
|
103
114
|
const p = api.props();
|
|
@@ -115,8 +126,11 @@ export function createButton(): SomaComponentDefinition {
|
|
|
115
126
|
const off = bool(p.disabled) || loading;
|
|
116
127
|
const type = str(p.type, 'button');
|
|
117
128
|
root.setAttribute('type', type === 'submit' || type === 'reset' ? type : 'button');
|
|
129
|
+
const reason = reasonOf(p);
|
|
118
130
|
if (off) {
|
|
119
|
-
|
|
131
|
+
// 带原因:不用原生 disabled(原生禁用的按钮拿不到焦点,读屏 / 键盘用户读不到原因),点击由 onClick 的 disabled 判断拦下
|
|
132
|
+
if (reason === '') root.setAttribute('disabled', '');
|
|
133
|
+
else root.removeAttribute('disabled');
|
|
120
134
|
root.setAttribute('aria-disabled', 'true');
|
|
121
135
|
} else {
|
|
122
136
|
root.removeAttribute('disabled');
|
|
@@ -129,18 +143,24 @@ export function createButton(): SomaComponentDefinition {
|
|
|
129
143
|
applyCommon(root, iconOnly && str(p.aria_label) === '' ? { ...p, aria_label: str(p.label) } : p);
|
|
130
144
|
const [spin, icon, label] = Array.from(root.children) as HTMLElement[];
|
|
131
145
|
if (spin) {
|
|
132
|
-
|
|
146
|
+
if (loading) {
|
|
147
|
+
spin.setAttribute(KIT_BUSY_SPIN_ATTR, '');
|
|
148
|
+
spin.className = SPINNER_WRAP_CLASS;
|
|
149
|
+
} else {
|
|
150
|
+
spin.removeAttribute(KIT_BUSY_SPIN_ATTR);
|
|
151
|
+
spin.className = 'hidden';
|
|
152
|
+
}
|
|
133
153
|
}
|
|
134
154
|
if (icon) {
|
|
135
155
|
const glyph = str(p.icon);
|
|
136
156
|
icon.textContent = glyph;
|
|
137
|
-
icon.className = glyph !== ''
|
|
157
|
+
icon.className = glyph !== '' ? 'inline-block' : 'hidden';
|
|
138
158
|
}
|
|
139
159
|
if (label) {
|
|
140
160
|
label.textContent = str(p.label);
|
|
161
|
+
// 加载态不在这里藏文字:转圈出现时的原内容遮盖只有一个来源(kit-theme 的 kit-busy-conceal,opacity 过渡,保留无障碍名称与宽度)
|
|
141
162
|
label.className = iconOnly ? 'hidden' : '';
|
|
142
163
|
}
|
|
143
|
-
if (icon && iconOnly) icon.className = str(p.icon) !== '' && !loading ? 'inline-block' : 'hidden';
|
|
144
164
|
setAttr(root, 'title', '');
|
|
145
165
|
const hasBadge = paintBadge(root, p);
|
|
146
166
|
const size = sizeOf(p.size);
|
|
@@ -148,9 +168,34 @@ export function createButton(): SomaComponentDefinition {
|
|
|
148
168
|
root.setAttribute(KIT_PART_ATTRIBUTE, kitControlPartOf({ variant, size }));
|
|
149
169
|
// 质感标记:ghost 无底无边(没有「面」),不标;其余变体有实心 / 描边 / 浅底,标 raised
|
|
150
170
|
setKitFace(root, variant === 'ghost' ? null : 'raised');
|
|
151
|
-
const
|
|
152
|
-
|
|
171
|
+
const base = iconOnly ? `${BUTTON_CLASS[variant][size]} ${ICON_ONLY_WIDTH[size]}` : BUTTON_CLASS[variant][size];
|
|
172
|
+
// 带原因的置灰没有原生 disabled,伪类 disabled: 不生效,补静态置灰类(配方 kitDisabledRecipe('aria'))
|
|
173
|
+
const look = reason === '' ? base : `${base} ${kitDisabledRecipe('aria')}`;
|
|
174
|
+
root.className = joinClass(withBadgeAnchor(look, hasBadge || loading), p.class);
|
|
153
175
|
},
|
|
154
|
-
})),
|
|
176
|
+
}))),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 置灰原因气泡:每次渲染之后按 disabled_reason 同步(withTooltip 每次渲染会重写 aria-describedby,所以放在它外面补);
|
|
182
|
+
* 卸载时摘掉。气泡挂 role=tooltip 占位在按钮里面,显示时走浮层端口(见 reason-tip.ts)。
|
|
183
|
+
*/
|
|
184
|
+
function withReasonTip(view: KitView): KitView {
|
|
185
|
+
return {
|
|
186
|
+
attach(root, api) {
|
|
187
|
+
const off = view.attach?.(root, api);
|
|
188
|
+
return () => {
|
|
189
|
+
releaseReasonTip(root);
|
|
190
|
+
if (off) off();
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
render(root, p, api) {
|
|
194
|
+
const done = view.render(root, p, api);
|
|
195
|
+
syncReasonTip(root, reasonOf(p), true);
|
|
196
|
+
return done;
|
|
197
|
+
},
|
|
198
|
+
...(view.handle !== undefined ? { handle: view.handle } : {}),
|
|
199
|
+
...(view.busyAware !== undefined ? { busyAware: view.busyAware } : {}),
|
|
155
200
|
};
|
|
156
201
|
}
|
package/src/base/check-core.ts
CHANGED
|
@@ -21,6 +21,13 @@ export type CheckState = boolean | 'mixed';
|
|
|
21
21
|
|
|
22
22
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
23
23
|
const MARK_ATTR = 'data-kit-mark';
|
|
24
|
+
/** 方形勾选框的标记:主题结构 CSS 据此把半径限到「一个间距单位」以内(胶囊 / 大圆角档下多选框也保持方形小圆角,单选框不带) */
|
|
25
|
+
export const KIT_CHECK_BOX_ATTR = 'data-kit-check-box';
|
|
26
|
+
|
|
27
|
+
/** 给手写的方形勾选框(树 / 授权树 / 穿梭框等自绘的小方块)打上同一标记 */
|
|
28
|
+
export function markCheckBox(el: Element): void {
|
|
29
|
+
el.setAttribute(KIT_CHECK_BOX_ATTR, '');
|
|
30
|
+
}
|
|
24
31
|
|
|
25
32
|
const ROOT_ON = 'group inline-flex cursor-pointer items-center gap-2 rounded-sm transition-colors hover:text-primary-on-soft';
|
|
26
33
|
const ROOT_OFF = 'inline-flex cursor-not-allowed items-center gap-2 rounded-sm text-fg-subtle opacity-60';
|
|
@@ -102,6 +109,7 @@ export function createCheck(doc: Document, kind: CheckKind, paint: CheckPaint =
|
|
|
102
109
|
input.type = kind;
|
|
103
110
|
const box = doc.createElement('span');
|
|
104
111
|
box.setAttribute('aria-hidden', 'true');
|
|
112
|
+
if (kind === 'checkbox') markCheckBox(box);
|
|
105
113
|
slot.append(input, box);
|
|
106
114
|
if (kind === 'checkbox') {
|
|
107
115
|
slot.append(svg(doc, 'M3.5 8.5l3 3 6-7'), svg(doc, 'M4 8h8'));
|
package/src/base/checkbox.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
5
5
|
import { CHOICE_GROUP_DEFAULT_CLASS, createChoiceView } from './choice';
|
|
6
|
-
import { CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP, createKitController } from './shared';
|
|
6
|
+
import { CLASS_PROP, ID_PROPS, INVALID_PROPS, OPTIONS_PROP, SIZE_PROP, createKitController } from './shared';
|
|
7
7
|
|
|
8
8
|
export function createCheckbox(): SomaComponentDefinition {
|
|
9
9
|
return {
|
|
@@ -22,6 +22,7 @@ export function createCheckbox(): SomaComponentDefinition {
|
|
|
22
22
|
disabled: { type: 'boolean', default: false },
|
|
23
23
|
readonly: { type: 'boolean', default: false },
|
|
24
24
|
...ID_PROPS,
|
|
25
|
+
...INVALID_PROPS,
|
|
25
26
|
size: SIZE_PROP,
|
|
26
27
|
class: CLASS_PROP,
|
|
27
28
|
},
|
package/src/base/choice.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// 选项集变化才重建 DOM,其余只更新 input 属性 / 类串,保住焦点。
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
applyCommon, bool, nextUid, optionsKey, optionsOf, sameValue, setAttr, sizeOf, str, joinClass,
|
|
6
|
+
applyCommon, applyGroupA11y, bool, nextUid, optionsKey, optionsOf, sameValue, setAttr, sizeOf, str, joinClass,
|
|
7
7
|
type KitApi, type KitOption, type KitProps, type KitSize, type KitView, type KitViewSetup,
|
|
8
8
|
} from './shared';
|
|
9
9
|
import { attachMarkEvents, createCheck, markChecked, markInput, paintCheck } from './check-core';
|
|
@@ -106,7 +106,26 @@ function paint(kind: ChoiceKind, root: HTMLElement, p: KitProps): void {
|
|
|
106
106
|
if (readonly && kind === 'radio') root.setAttribute('aria-readonly', 'true');
|
|
107
107
|
else root.removeAttribute('aria-readonly');
|
|
108
108
|
// id 已给第一个控件,根上不重复写;这里只写可访问名
|
|
109
|
-
|
|
109
|
+
// 组根写可访问名 / 标签关联;必填 / 无效 / 说明关联:组(radiogroup、多选组)写在根上,单个勾选框写在它的原生 input 上
|
|
110
|
+
const firstMark = marksOf(root)[0];
|
|
111
|
+
const first = single && firstMark ? markInput(firstMark) : null;
|
|
112
|
+
if (first) {
|
|
113
|
+
applyCommon(root, { aria_label: p.aria_label, labelledby: p.labelledby, aria_labelledby: p.aria_labelledby });
|
|
114
|
+
applyCommon(first, {
|
|
115
|
+
id: str(p.id),
|
|
116
|
+
name: first.getAttribute('name') ?? '',
|
|
117
|
+
aria_label: first.getAttribute('aria-label') ?? '',
|
|
118
|
+
required: p.required,
|
|
119
|
+
invalid: p.invalid,
|
|
120
|
+
describedby: p.describedby,
|
|
121
|
+
aria_describedby: p.aria_describedby,
|
|
122
|
+
errormessage: p.errormessage,
|
|
123
|
+
aria_errormessage: p.aria_errormessage,
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
// radiogroup 根支持 aria-required / aria-invalid;多选组(role=group)则落到各原生 checkbox 上
|
|
127
|
+
applyGroupA11y(root, p, root.querySelectorAll('input'));
|
|
128
|
+
}
|
|
110
129
|
// 外部类追加在根节点类串末尾(冲突合并留给以后的编译器)
|
|
111
130
|
const vertical = orientationOf(p.orientation) === 'vertical';
|
|
112
131
|
if (vertical) root.setAttribute('aria-orientation', 'vertical');
|
package/src/base/color-picker.ts
CHANGED
|
@@ -14,9 +14,11 @@ import { createKeyboardWiring } from 'soma-core/keyboard';
|
|
|
14
14
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
15
15
|
import { part, wirePopLayer } from './popover';
|
|
16
16
|
import { KIT_DROPDOWN_CLASS_CANDIDATES } from './popup';
|
|
17
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
18
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
17
19
|
import {
|
|
18
|
-
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
19
|
-
applyCommon, bool, classCandidates, createKitController, joinClass, nextUid, setAttr, sizeOf, str,
|
|
20
|
+
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
21
|
+
applyCommon, applyCompositeField, bool, classCandidates, createKitController, joinClass, nextUid, setAttr, sizeOf, str,
|
|
20
22
|
type KitSize,
|
|
21
23
|
} from './shared';
|
|
22
24
|
|
|
@@ -63,15 +65,15 @@ export function presetsOf(raw: unknown): string[] {
|
|
|
63
65
|
|
|
64
66
|
const ROOT = 'relative block w-full';
|
|
65
67
|
const TRIGGER: Record<KitSize, string> = {
|
|
66
|
-
sm: 'inline-flex h-
|
|
67
|
-
md: 'inline-flex h-
|
|
68
|
+
sm: 'inline-flex h-6 w-full cursor-pointer items-center gap-2 rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:opacity-60',
|
|
69
|
+
md: 'inline-flex h-8 w-full cursor-pointer items-center gap-2 rounded-md border border-input bg-surface px-3 text-sm text-fg transition-colors enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:opacity-60',
|
|
68
70
|
lg: 'inline-flex h-10 w-full cursor-pointer items-center gap-2 rounded-md border border-input bg-surface px-4 text-base text-fg transition-colors enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:opacity-60',
|
|
69
71
|
};
|
|
70
72
|
const TRIGGER_TEXT = 'min-w-0 flex-1 truncate text-start';
|
|
71
73
|
const TRIGGER_TEXT_EMPTY = 'min-w-0 flex-1 truncate text-start text-fg-subtle';
|
|
72
74
|
const SWATCH_SVG = 'h-4 w-4 shrink-0';
|
|
73
75
|
const SWATCH_RECT = 'stroke-border stroke-1';
|
|
74
|
-
const PANEL = 'absolute z-10 w-64
|
|
76
|
+
const PANEL = mergeClass('absolute z-10 w-64 p-3 focus-visible:outline-none', kitSurfaceRecipe('raised'));
|
|
75
77
|
const HIDDEN = 'hidden';
|
|
76
78
|
const PRESETS = 'flex flex-wrap gap-2';
|
|
77
79
|
const CHIP_IDLE = 'inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md border border-border-subtle transition-colors hover:border-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
@@ -116,6 +118,7 @@ export function createColorPicker(): SomaComponentDefinition {
|
|
|
116
118
|
disabled: { type: 'boolean', default: false },
|
|
117
119
|
readonly: { type: 'boolean', default: false },
|
|
118
120
|
...ID_PROPS,
|
|
121
|
+
...INVALID_PROPS,
|
|
119
122
|
size: SIZE_PROP,
|
|
120
123
|
class: CLASS_PROP,
|
|
121
124
|
},
|
|
@@ -276,6 +279,8 @@ export function createColorPicker(): SomaComponentDefinition {
|
|
|
276
279
|
trigger.className = TRIGGER[sizeOf(p.size)];
|
|
277
280
|
trigger.disabled = disabled;
|
|
278
281
|
applyCommon(trigger, { id: p.id, aria_label: p.aria_label });
|
|
282
|
+
// 作表单字段:根承载字段名 / 说明 / 错误关联与无效标记(触发钮是 button,不写校验属性)
|
|
283
|
+
applyCompositeField(root, p);
|
|
279
284
|
chipHost.textContent = '';
|
|
280
285
|
chipHost.appendChild(swatch(SWATCH_SVG, value));
|
|
281
286
|
text.textContent = value ?? str(p.placeholder, kitText('soma.kit.pick_color', undefined, text));
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from './shared';
|
|
23
23
|
|
|
24
24
|
const ROOT = 'inline-block';
|
|
25
|
-
const TRIGGER = 'inline-flex h-
|
|
25
|
+
const TRIGGER = 'inline-flex h-8 cursor-pointer items-center gap-3 rounded-md border border-border bg-surface px-3 text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
26
26
|
const TRIGGER_KEYS = 'rounded-sm border border-border-subtle bg-surface-sunken px-1.5 py-0.5 text-xs text-fg-subtle';
|
|
27
27
|
const HIDDEN = 'hidden';
|
|
28
28
|
const OVERLAY = 'fixed inset-0 z-50 flex items-start justify-center bg-scrim p-4';
|
package/src/base/context-menu.ts
CHANGED
|
@@ -7,19 +7,22 @@
|
|
|
7
7
|
// 见 kit-grammar.json#cssomWrites);端口缺失时降级为按指针象限选四角偏移类的就地定位(不写 CSSOM);键盘打开落在触发区左上。
|
|
8
8
|
// 3. 触发区的外观:虚线框的「右键此处」区域。
|
|
9
9
|
|
|
10
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
10
11
|
import { classCandidates } from './shared';
|
|
11
12
|
|
|
12
13
|
export type Corner = 'tl' | 'tr' | 'bl' | 'br';
|
|
13
14
|
|
|
15
|
+
// 菜单面板的表面(圆角 / hairline 描边 / 浮起底 / 双层阴影 / 高光边)统一取 recipes/surface.ts 的浮起级
|
|
16
|
+
const MENU_PANEL_SURFACE = kitSurfaceRecipe('raised');
|
|
14
17
|
export const CONTEXT_SHOWN: Record<Corner, string> = {
|
|
15
|
-
tl:
|
|
16
|
-
tr:
|
|
17
|
-
bl:
|
|
18
|
-
br:
|
|
18
|
+
tl: `absolute left-4 top-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
19
|
+
tr: `absolute right-4 top-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
20
|
+
bl: `absolute bottom-4 left-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
21
|
+
br: `absolute bottom-4 right-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
19
22
|
};
|
|
20
|
-
/** 按点挂浮层时的面板类(fixed,几何由 portal-core 的 showAtPoint 一次写入;无 style=
|
|
21
|
-
export const CONTEXT_POINT_PANEL =
|
|
22
|
-
export const CONTEXT_AREA ='block w-full cursor-context-menu rounded-lg border border-dashed border-border bg-surface px-4 py-6 text-center text-sm text-fg-muted transition-colors
|
|
23
|
+
/** 按点挂浮层时的面板类(fixed,几何由 portal-core 的 showAtPoint 一次写入;无 style= 字面量;进场由 showAtPoint 打的 data-kit-anchored 规则统一驱动) */
|
|
24
|
+
export const CONTEXT_POINT_PANEL = `fixed z-50 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`;
|
|
25
|
+
export const CONTEXT_AREA ='block w-full cursor-context-menu rounded-lg border border-dashed border-border bg-surface px-4 py-6 text-center text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
23
26
|
export const CONTEXT_AREA_OFF = 'block w-full cursor-not-allowed rounded-lg border border-dashed border-border bg-surface-sunken px-4 py-6 text-center text-sm text-fg-subtle opacity-60';
|
|
24
27
|
const LONG_PRESS_MS = 500;
|
|
25
28
|
|
package/src/base/date-range.ts
CHANGED
|
@@ -29,21 +29,21 @@ const RANGE_CLASS: Record<KitSize, string> = {
|
|
|
29
29
|
const FIELDS_CLASS = 'relative inline-flex items-center gap-2';
|
|
30
30
|
const HIDDEN_CLASS = 'hidden';
|
|
31
31
|
const DATE_CLASS: Record<KitSize, string> = {
|
|
32
|
-
sm: 'block h-
|
|
33
|
-
md: 'block h-
|
|
32
|
+
sm: 'block h-6 w-32 rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
33
|
+
md: 'block h-8 w-36 rounded-md border border-input bg-surface px-3 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
34
34
|
lg: 'block h-10 w-40 rounded-md border border-input bg-surface px-4 text-base text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
35
35
|
};
|
|
36
36
|
const OPEN_BTN_CLASS: Record<KitSize, string> = {
|
|
37
|
-
sm: 'inline-flex size-8 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
38
|
-
md: 'inline-flex size-9 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
39
|
-
lg: 'inline-flex size-10 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
37
|
+
sm: 'inline-flex size-8 p-0 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
38
|
+
md: 'inline-flex size-9 p-0 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
39
|
+
lg: 'inline-flex size-10 p-0 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
40
40
|
};
|
|
41
41
|
const ICON_CLASS = 'size-4 pointer-events-none';
|
|
42
42
|
|
|
43
43
|
const PRESETS_CLASS = 'inline-flex flex-wrap items-center gap-1';
|
|
44
44
|
const PRESET_CLASS = {
|
|
45
|
-
idle: 'inline-flex h-
|
|
46
|
-
pressed: 'inline-flex h-
|
|
45
|
+
idle: 'inline-flex h-6 border-0 bg-transparent cursor-pointer items-center rounded-md px-2.5 text-sm text-fg-muted transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
46
|
+
pressed: 'inline-flex h-6 border-0 cursor-pointer items-center rounded-md 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 disabled:cursor-not-allowed disabled:opacity-60',
|
|
47
47
|
} as const;
|
|
48
48
|
|
|
49
49
|
export const KIT_DATE_RANGE_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
package/src/base/date.ts
CHANGED
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
} from './shared';
|
|
23
23
|
import { kitIcon } from './icons';
|
|
24
24
|
import { setKitFace } from '../recipes';
|
|
25
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
26
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
25
27
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, focusCellQuiet, handoffTab, onOutsidePress, releaseDropdown, syncDropdown, trackInputModality } from './popup';
|
|
26
28
|
|
|
27
29
|
// ── 类串(整串写死,进候选类清单)──────────────────────────────
|
|
@@ -29,20 +31,20 @@ import { KIT_DROPDOWN_CLASS_CANDIDATES, focusCellQuiet, handoffTab, onOutsidePre
|
|
|
29
31
|
const ROOT_CLASS = 'relative block w-full';
|
|
30
32
|
const HIDDEN_CLASS = 'hidden';
|
|
31
33
|
const INPUT_CLASS: Record<KitSize, string> = {
|
|
32
|
-
sm: 'block h-
|
|
33
|
-
md: 'block h-
|
|
34
|
+
sm: 'block h-6 w-full appearance-none autofill-clear rounded-md border border-input bg-surface ps-2.5 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
35
|
+
md: 'block h-8 w-full appearance-none autofill-clear rounded-md border border-input bg-surface ps-3 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
34
36
|
lg: 'block h-10 w-full appearance-none autofill-clear rounded-md border border-input bg-surface ps-4 pe-9 text-base text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
35
37
|
};
|
|
36
|
-
const OPEN_BTN_CLASS = 'absolute end-0 top-0 border-0 bg-transparent flex h-full w-8 cursor-pointer items-center justify-center rounded-md text-fg-subtle transition-colors enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
37
|
-
const CLEAR_BTN_CLASS = 'absolute end-8 top-0 border-0 bg-transparent flex h-full w-
|
|
38
|
+
const OPEN_BTN_CLASS = 'absolute end-0 top-0 border-0 bg-transparent flex h-full w-8 p-0 cursor-pointer items-center justify-center rounded-md text-fg-subtle transition-colors enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
39
|
+
const CLEAR_BTN_CLASS = 'absolute end-8 top-0 border-0 bg-transparent flex h-full w-6 p-0 cursor-pointer items-center justify-center rounded-md text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
38
40
|
const ICON_CLASS = 'size-4 pointer-events-none';
|
|
39
41
|
|
|
40
|
-
const PANEL_BASE = 'absolute z-10 flex w-max flex-col gap-2
|
|
42
|
+
const PANEL_BASE = mergeClass('absolute z-10 flex w-max flex-col gap-2 p-4', kitSurfaceRecipe('raised'));
|
|
41
43
|
const MONTHS_CLASS = 'flex gap-4';
|
|
42
44
|
const MONTH_CLASS = 'flex flex-col gap-1';
|
|
43
45
|
const MONTH_HEAD_CLASS = 'flex items-center justify-between gap-2';
|
|
44
46
|
const MONTH_TITLE_CLASS = 'flex-1 text-center text-base font-medium text-fg';
|
|
45
|
-
const NAV_CLASS = 'inline-flex size-8 border-0 bg-transparent cursor-pointer items-center justify-center rounded-md text-fg-muted transition-colors hover:bg-
|
|
47
|
+
const NAV_CLASS = 'inline-flex size-8 p-0 border-0 bg-transparent cursor-pointer items-center justify-center rounded-md 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-1 focus-visible:ring-inset focus-visible:ring-ring data-kit-quiet:focus-visible:ring-0';
|
|
46
48
|
const NAV_SPACER_CLASS = 'size-8';
|
|
47
49
|
const NAV_GLYPH_CLASS = 'inline-block rtl:rotate-180';
|
|
48
50
|
const ROW_CLASS = 'grid grid-cols-7';
|
|
@@ -52,15 +54,15 @@ const SPACER_CELL_CLASS = 'size-8';
|
|
|
52
54
|
// 日格带 data-kit-quiet,data-kit-quiet:focus-visible:ring-0 把环压掉(见 focusCell)。今天只用文字强调(primary 粗体),不画边框,避免与焦点环叠成一团
|
|
53
55
|
const DAY_FOCUS = 'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring data-kit-quiet:focus-visible:ring-0';
|
|
54
56
|
const DAY_CLASS = {
|
|
55
|
-
idle: `flex size-8 cursor-pointer items-center justify-center rounded-md text-sm text-fg transition-colors hover:bg-
|
|
56
|
-
today: `flex size-8 cursor-pointer items-center justify-center rounded-full text-sm font-semibold text-primary-on-soft transition-colors hover:bg-
|
|
57
|
+
idle: `flex size-8 cursor-pointer items-center justify-center rounded-md text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${DAY_FOCUS}`,
|
|
58
|
+
today: `flex size-8 cursor-pointer items-center justify-center rounded-full text-sm font-semibold text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${DAY_FOCUS}`,
|
|
57
59
|
between: `flex size-8 cursor-pointer items-center justify-center rounded-none bg-primary-soft text-sm text-primary-on-soft transition-colors ${DAY_FOCUS}`,
|
|
58
60
|
selected: `flex size-8 cursor-pointer items-center justify-center rounded-full bg-primary text-sm font-medium text-primary-fg ${DAY_FOCUS}`,
|
|
59
61
|
disabled: `flex size-8 cursor-not-allowed items-center justify-center rounded-md bg-surface-sunken text-sm text-fg-subtle ${DAY_FOCUS}`,
|
|
60
62
|
} as const;
|
|
61
63
|
const FOOT_CLASS = 'flex items-center justify-between gap-2';
|
|
62
64
|
// 文字钮用底色表示键盘焦点,不用环
|
|
63
|
-
const TODAY_BTN_CLASS = 'border-0 bg-transparent cursor-pointer rounded-md px-2 py-1 text-sm text-primary-on-soft transition-colors hover:bg-
|
|
65
|
+
const TODAY_BTN_CLASS = 'border-0 bg-transparent cursor-pointer rounded-md px-2 py-1 text-sm text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:bg-state-layer-hover focus-visible:outline-none';
|
|
64
66
|
// 状态文字不再可见(R7):只给读屏播报
|
|
65
67
|
const STATUS_CLASS = { sr: 'sr-only' } as const;
|
|
66
68
|
|
|
@@ -571,6 +573,7 @@ interface FieldState {
|
|
|
571
573
|
fieldClass: string;
|
|
572
574
|
invalid: boolean;
|
|
573
575
|
required: boolean;
|
|
576
|
+
labelledby: string;
|
|
574
577
|
describedby: string;
|
|
575
578
|
errormessage: string;
|
|
576
579
|
}
|
|
@@ -784,6 +787,7 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
784
787
|
name: '',
|
|
785
788
|
required: s.required,
|
|
786
789
|
invalid: s.invalid,
|
|
790
|
+
labelledby: s.labelledby,
|
|
787
791
|
describedby: s.describedby,
|
|
788
792
|
errormessage: s.errormessage,
|
|
789
793
|
});
|
|
@@ -836,6 +840,7 @@ function stateOfProps(p: KitProps): FieldState {
|
|
|
836
840
|
fieldClass: '',
|
|
837
841
|
invalid: bool(p.invalid),
|
|
838
842
|
required: bool(p.required),
|
|
843
|
+
labelledby: str(p.aria_labelledby, str(p.labelledby)),
|
|
839
844
|
describedby: str(p.aria_describedby, str(p.describedby)),
|
|
840
845
|
errormessage: str(p.aria_errormessage, str(p.errormessage)),
|
|
841
846
|
};
|
|
@@ -905,20 +910,42 @@ export interface KitDateFieldOptions {
|
|
|
905
910
|
readonly?: boolean;
|
|
906
911
|
/** 换掉文本框整串类(须自带右侧 pe-8 给日历钮留位);缺省按 size 取默认类 */
|
|
907
912
|
fieldClass?: string;
|
|
913
|
+
/** 无可见标签时的可访问名(写文本框 aria-label) */
|
|
914
|
+
ariaLabel?: string;
|
|
915
|
+
/** 可见标签元素 id(写文本框 aria-labelledby) */
|
|
916
|
+
labelledby?: string;
|
|
917
|
+
/** 说明 / 错误元素 id(写 aria-describedby / aria-errormessage) */
|
|
918
|
+
describedby?: string;
|
|
919
|
+
errormessage?: string;
|
|
920
|
+
/** 必填 / 校验无效(写 aria-required / aria-invalid 并呈现错误态边框) */
|
|
921
|
+
required?: boolean;
|
|
922
|
+
invalid?: boolean;
|
|
923
|
+
/** 文本框 id / 表单字段名 */
|
|
924
|
+
id?: string;
|
|
925
|
+
name?: string;
|
|
908
926
|
/** 选中 / 清除 / 键入合法值后调(已写进 input.value) */
|
|
909
927
|
onChange?(value: string): void;
|
|
910
928
|
onReject?(value: string): void;
|
|
911
929
|
}
|
|
912
930
|
|
|
931
|
+
/** 挂载后可随时改的无障碍 / 校验态(给了哪些键就改哪些键) */
|
|
932
|
+
export type KitDateFieldState = Pick<KitDateFieldOptions, 'disabled' | 'readonly' | 'required' | 'invalid' | 'ariaLabel' | 'labelledby' | 'describedby' | 'errormessage'>;
|
|
933
|
+
|
|
913
934
|
export interface KitDateField {
|
|
914
935
|
/** 要挂进 DOM 的外壳(relative 盒) */
|
|
915
936
|
el: HTMLElement;
|
|
916
937
|
/** 文本框:value 即日期文本;调用方在它身上写 data-* / aria-label、读 value、听 input / change */
|
|
917
938
|
input: HTMLInputElement;
|
|
918
939
|
setValue(value: string): void;
|
|
940
|
+
/** 改禁用 / 只读 / 必填 / 无效 / 标签与说明关联(只改传入的键) */
|
|
941
|
+
setState(next: KitDateFieldState): void;
|
|
919
942
|
dispose(): void;
|
|
920
943
|
}
|
|
921
944
|
|
|
945
|
+
/**
|
|
946
|
+
* 在命令式 DOM 里画一个自绘 Date(与页面里的 Date 组件同一份实现,无原生 `<input type=date>`)。
|
|
947
|
+
* 应用组件经 `soma-kit/app` 取用;须 `declareKitUses(组件, ['Date'])`,卸载 / 重画前经 `createKitEmbedBag().add(field)` 或 `dispose()` 释放。
|
|
948
|
+
*/
|
|
922
949
|
export function mountKitDateField(opts: KitDateFieldOptions = {}): KitDateField {
|
|
923
950
|
const root = document.createElement('div');
|
|
924
951
|
root.className = ROOT_CLASS;
|
|
@@ -933,14 +960,15 @@ export function mountKitDateField(opts: KitDateFieldOptions = {}): KitDateField
|
|
|
933
960
|
size: opts.size ?? 'md',
|
|
934
961
|
disabled: opts.disabled === true,
|
|
935
962
|
readonly: opts.readonly === true,
|
|
936
|
-
id: '',
|
|
937
|
-
name: '',
|
|
938
|
-
ariaLabel: '',
|
|
963
|
+
id: opts.id ?? '',
|
|
964
|
+
name: opts.name ?? '',
|
|
965
|
+
ariaLabel: opts.ariaLabel ?? '',
|
|
939
966
|
fieldClass: opts.fieldClass ?? '',
|
|
940
|
-
invalid:
|
|
941
|
-
required:
|
|
942
|
-
|
|
943
|
-
|
|
967
|
+
invalid: opts.invalid === true,
|
|
968
|
+
required: opts.required === true,
|
|
969
|
+
labelledby: opts.labelledby ?? '',
|
|
970
|
+
describedby: opts.describedby ?? '',
|
|
971
|
+
errormessage: opts.errormessage ?? '',
|
|
944
972
|
};
|
|
945
973
|
const ui = buildDateField(root, {
|
|
946
974
|
read: () => st,
|
|
@@ -962,6 +990,17 @@ export function mountKitDateField(opts: KitDateFieldOptions = {}): KitDateField
|
|
|
962
990
|
st.value = value;
|
|
963
991
|
ui.paint();
|
|
964
992
|
},
|
|
993
|
+
setState(next) {
|
|
994
|
+
if (next.disabled !== undefined) st.disabled = next.disabled;
|
|
995
|
+
if (next.readonly !== undefined) st.readonly = next.readonly;
|
|
996
|
+
if (next.required !== undefined) st.required = next.required;
|
|
997
|
+
if (next.invalid !== undefined) st.invalid = next.invalid;
|
|
998
|
+
if (next.ariaLabel !== undefined) st.ariaLabel = next.ariaLabel;
|
|
999
|
+
if (next.labelledby !== undefined) st.labelledby = next.labelledby;
|
|
1000
|
+
if (next.describedby !== undefined) st.describedby = next.describedby;
|
|
1001
|
+
if (next.errormessage !== undefined) st.errormessage = next.errormessage;
|
|
1002
|
+
ui.paint();
|
|
1003
|
+
},
|
|
965
1004
|
dispose: ui.dispose,
|
|
966
1005
|
};
|
|
967
1006
|
}
|