soma-kit 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +158 -4
- package/spec/generated/kit-page.schema.json +139 -5
- package/spec/kit-grammar.json +438 -87
- package/spec/kit-grammar.schema.json +11 -3
- package/src/app/app-config.ts +83 -5
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +17 -5
- package/src/app/kit-view-context.ts +163 -14
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +3 -1
- package/src/app/server.ts +40 -3
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +57 -12
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/index.ts +27 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +23 -12
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +9 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +24 -22
- package/src/base/shared.ts +169 -23
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +63 -33
- package/src/base/text.ts +42 -13
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -10
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +2 -2
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/import-wizard/shell.ts +2 -1
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +102 -10
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +4 -1
- package/src/biz/multi-board/shell.ts +8 -5
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +18 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +139 -10
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +22 -160
- package/src/biz/standard-crud/shell.ts +16 -44
- package/src/biz/step-form/shell.ts +5 -5
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/view-writes.ts +69 -60
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +51 -7
- package/src/compile/component-candidates.ts +12 -1
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +36 -8
- package/src/compile/types.ts +13 -1
- package/src/compile/view-check.ts +149 -16
- package/src/data/amount-breakdown.ts +6 -1
- package/src/data/approval-flow.ts +1 -1
- package/src/data/assignment-picker.ts +53 -27
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +2 -2
- package/src/data/carousel.ts +8 -6
- package/src/data/chart.ts +141 -10
- package/src/data/checklist.ts +18 -5
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +2 -2
- package/src/data/confirm-dialog.ts +71 -18
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +4 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +25 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/gantt.ts +5 -2
- package/src/data/hero.ts +2 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +6 -1
- package/src/data/item-list.ts +18 -10
- package/src/data/kanban.ts +39 -10
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +45 -13
- package/src/data/mockup.ts +8 -4
- package/src/data/modal-dialog.ts +29 -9
- package/src/data/navbar.ts +5 -5
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +354 -48
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +17 -7
- package/src/data/permission-matrix.ts +33 -11
- package/src/data/permission-tree.ts +47 -22
- package/src/data/pricing-table.ts +21 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +23 -2
- package/src/data/record-picker.ts +13 -7
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +79 -26
- package/src/data/rule-builder.ts +8 -8
- package/src/data/shape-util.ts +23 -9
- package/src/data/stat-group.ts +170 -29
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +2 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +3 -3
- package/src/data/system-switcher.ts +1 -1
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +1 -1
- package/src/data/transfer.ts +36 -16
- package/src/data/tree-table.ts +62 -36
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +19 -10
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/page-bar.ts +14 -13
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +15 -10
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +2 -1
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +2 -2
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/view.ts +141 -33
- package/src/generated/kit-grammar-runtime.ts +239 -55
- package/src/i18n/kit-text.ts +63 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/arrange.ts +42 -8
- package/src/object-renderer/collection-parts.ts +241 -60
- package/src/object-renderer/collection-table.ts +109 -5
- package/src/object-renderer/collection.ts +174 -36
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +30 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-static.ts +370 -30
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/render-object.ts +54 -6
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +135 -27
- package/src/object-renderer/table-tools.ts +12 -11
- package/src/object-renderer/types.ts +78 -7
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +46 -1
- package/src/recipes/control.ts +70 -12
- package/src/recipes/index.ts +49 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +75 -17
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +34 -5
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +40 -3
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +13 -1
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +372 -12
- package/src/theme/kit-theme.tpl +372 -12
- package/src/theme/nine-dim-structure.ts +177 -7
- package/src/theme/surface-layers.ts +4 -0
- package/src/theme/theme-tokens.ts +53 -13
- package/src/theme/theme-types.ts +32 -0
- package/src/biz/shared/remove-key.ts +0 -6
package/src/data/item-list.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
12
12
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
14
|
import {
|
|
15
|
-
actionButton, actionsOf, BADGE_BASE, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, recOf, rowsOf, shapeToneOf, textOf, TONE_SOFT,
|
|
15
|
+
actionButton, actionsOf, BADGE_BASE, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, recOf, retryButton, rowsOf, shapeToneOf, textOf, TONE_SOFT,
|
|
16
16
|
} from './shape-util';
|
|
17
17
|
import { KIT_ROW_TONE_CLASS } from '../object-renderer/view-binding';
|
|
18
18
|
import { AVATAR_CLASS_TOKENS, avatarNode } from './d9-util';
|
|
@@ -35,8 +35,9 @@ const ROOT_SCROLL = Object.freeze({
|
|
|
35
35
|
md: 'max-h-80 overflow-y-auto',
|
|
36
36
|
lg: 'max-h-96 overflow-y-auto',
|
|
37
37
|
} as Record<string, string>);
|
|
38
|
-
|
|
39
|
-
const
|
|
38
|
+
// 列表行(与下拉选项行同款:无描边、悬停浅底、选中主色软底),不再是带边框的输入框样子
|
|
39
|
+
const ITEM_CLASS = 'flex items-start gap-2 rounded-md transition-colors hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
40
|
+
const ITEM_ON_CLASS = 'flex items-start gap-2 rounded-md bg-primary-soft transition-colors';
|
|
40
41
|
const MAIN_CLASS = 'flex min-w-0 flex-1 flex-col gap-1 rounded-md px-3 py-2 text-start focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
41
42
|
const MAIN_DISABLED = 'cursor-not-allowed opacity-60';
|
|
42
43
|
const TITLE_CLASS = 'text-sm font-medium text-fg';
|
|
@@ -84,12 +85,17 @@ export function groupListItems(items: readonly KitListItem[]): KitListItem[] {
|
|
|
84
85
|
return order.flatMap((g) => buckets.get(g)!);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* 条目(纯函数,便于单测):data 只认数组(单个对象 / 未取到时的 `{}` 一律当空列表,不画幽灵行),空对象行丢弃;
|
|
90
|
+
* 缺 id 用下标(仅作内部键,不当标题显示),缺 title 退到显式给的 id;没有 id 也没有任何可显示内容的行丢弃。
|
|
91
|
+
*/
|
|
88
92
|
export function listItemsOf(rawRows: unknown, mapRaw: unknown): KitListItem[] {
|
|
89
93
|
const m = keyMap(KIT_ITEM_LIST_DEFAULT_MAP, mapRaw);
|
|
90
|
-
|
|
94
|
+
const rows = Array.isArray(rawRows) ? rowsOf(rawRows).filter((r) => Object.keys(r).length > 0) : [];
|
|
95
|
+
return rows.flatMap((raw, i) => {
|
|
91
96
|
const idRaw = raw[m.id];
|
|
92
|
-
const
|
|
97
|
+
const hasId = !(idRaw === undefined || idRaw === null || idRaw === '');
|
|
98
|
+
const id = hasId ? String(idRaw) : `i${i}`;
|
|
93
99
|
const title = textOf(raw[m.title]);
|
|
94
100
|
const tags = Array.isArray(raw[m.tags])
|
|
95
101
|
? (raw[m.tags] as unknown[]).flatMap((t) => {
|
|
@@ -99,9 +105,9 @@ export function listItemsOf(rawRows: unknown, mapRaw: unknown): KitListItem[] {
|
|
|
99
105
|
return label === '' ? [] : [{ label, tone: shapeToneOf(r.tone) }];
|
|
100
106
|
})
|
|
101
107
|
: [];
|
|
102
|
-
|
|
108
|
+
const item: KitListItem = {
|
|
103
109
|
id,
|
|
104
|
-
title: title === '' ? id : title,
|
|
110
|
+
title: title === '' && hasId ? id : title,
|
|
105
111
|
sub: textOf(raw[m.sub]),
|
|
106
112
|
text: textOf(raw[m.text]),
|
|
107
113
|
tags,
|
|
@@ -114,6 +120,8 @@ export function listItemsOf(rawRows: unknown, mapRaw: unknown): KitListItem[] {
|
|
|
114
120
|
group: textOf(raw[m.group]),
|
|
115
121
|
raw,
|
|
116
122
|
};
|
|
123
|
+
const shows = item.title !== '' || item.sub !== '' || item.text !== '' || tags.length > 0 || item.avatar !== '' || item.prefix !== '' || item.suffix !== '';
|
|
124
|
+
return hasId || shows ? [item] : [];
|
|
117
125
|
});
|
|
118
126
|
}
|
|
119
127
|
|
|
@@ -247,7 +255,7 @@ export function createItemList(): SomaComponentDefinition {
|
|
|
247
255
|
box.setAttribute('role', 'alert');
|
|
248
256
|
box.appendChild(mk('span', '', errorText));
|
|
249
257
|
if (str(p.retry_text) !== '') {
|
|
250
|
-
const btn =
|
|
258
|
+
const btn = retryButton('retry', str(p.retry_text), 'danger');
|
|
251
259
|
btn.setAttribute('data-kit-retry', '');
|
|
252
260
|
box.appendChild(btn);
|
|
253
261
|
}
|
|
@@ -303,7 +311,7 @@ export function createItemList(): SomaComponentDefinition {
|
|
|
303
311
|
if (it.suffix !== '') row.appendChild(mk('span', SUFFIX_CLASS, it.suffix));
|
|
304
312
|
main.appendChild(row);
|
|
305
313
|
}
|
|
306
|
-
body.appendChild(mk('span', TITLE_CLASS, it.title));
|
|
314
|
+
if (it.title !== '') body.appendChild(mk('span', TITLE_CLASS, it.title));
|
|
307
315
|
if (it.sub !== '') body.appendChild(mk('span', SUB_CLASS, it.sub));
|
|
308
316
|
if (it.text !== '') body.appendChild(mk('span', TEXT_CLASS, it.text));
|
|
309
317
|
if (it.tags.length > 0) {
|
package/src/data/kanban.ts
CHANGED
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
|
|
27
27
|
import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
|
|
28
28
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
29
|
-
import { kitText } from '../i18n/kit-text';
|
|
29
|
+
import { kitKey, kitText } from '../i18n/kit-text';
|
|
30
|
+
import { createKeyboardWiring } from 'soma-core/keyboard';
|
|
31
|
+
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
30
32
|
import { setKitFace } from '../recipes';
|
|
31
33
|
import { provideCtxRows } from './context-menu';
|
|
32
34
|
|
|
@@ -41,15 +43,15 @@ const COUNT_CLASS = 'text-fg-muted';
|
|
|
41
43
|
const COUNT_OVER_CLASS = 'font-medium text-danger-on-soft';
|
|
42
44
|
const LANE_BODY_CLASS = 'flex min-h-16 flex-col gap-2 rounded-md';
|
|
43
45
|
const DROP_CLASS = 'ring-2 ring-inset ring-ring';
|
|
44
|
-
const CARD_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface p-3 text-sm text-fg shadow-xs transition-colors
|
|
46
|
+
const CARD_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface p-3 text-sm text-fg shadow-xs transition-colors state-layer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
45
47
|
const CARD_DRAG_CLASS = 'cursor-grab active:cursor-grabbing';
|
|
46
48
|
const CARD_TITLE_CLASS = 'font-medium text-fg';
|
|
47
49
|
const FACT_CLASS = 'flex items-baseline justify-between gap-2 text-xs text-fg-muted';
|
|
48
50
|
const FACT_VALUE_CLASS = 'truncate text-fg';
|
|
49
51
|
const EMPTY_CLASS = 'px-2 py-3 text-center text-sm text-fg-muted';
|
|
50
|
-
const MOVE_BTN_CLASS = 'inline-flex h-7 items-center self-start rounded-md border border-
|
|
52
|
+
const MOVE_BTN_CLASS = 'inline-flex h-7 items-center self-start rounded-md border border-button-edge bg-surface px-4 text-xs text-fg state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
51
53
|
const MENU_CLASS = 'flex flex-col gap-1 rounded-md border border-border bg-surface p-1';
|
|
52
|
-
const MENU_ITEM_CLASS = 'flex h-7 items-center rounded-md px-2 text-start text-xs text-fg hover:bg-
|
|
54
|
+
const MENU_ITEM_CLASS = 'flex h-7 items-center rounded-md px-2 text-start text-xs text-fg hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-subtle';
|
|
53
55
|
const NOTICE_CLASS = 'rounded-md border border-border-subtle bg-warning-soft px-3 py-1.5 text-xs text-warning-on-soft';
|
|
54
56
|
const HIDDEN_CLASS = 'hidden';
|
|
55
57
|
const LIVE_CLASS = 'sr-only';
|
|
@@ -411,7 +413,8 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
411
413
|
line.appendChild(el('span', FACT_VALUE_CLASS, str(v)));
|
|
412
414
|
card.appendChild(line);
|
|
413
415
|
}
|
|
414
|
-
|
|
416
|
+
// 移动菜单始终提供(WCAG 2.5.7:拖放之外必须有单指针替代;有拖放端口时也不隐藏)
|
|
417
|
+
if (!locked()) {
|
|
415
418
|
const btn = el('button', MOVE_BTN_CLASS, str(P().move_label) || kitText('soma.kit.move_to', undefined, api.host));
|
|
416
419
|
btn.type = 'button';
|
|
417
420
|
setKitFace(btn, 'raised');
|
|
@@ -527,6 +530,22 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
527
530
|
[...board.querySelectorAll<HTMLElement>('[data-kit-key]')].find((n) => n.getAttribute('data-kit-key') === id)?.focus();
|
|
528
531
|
};
|
|
529
532
|
|
|
533
|
+
// 泳道内的纵向导航走 core 的共享键盘接线:集合 = 当前泳道的卡(按键前由 onKeydown 填),游标 = 焦点卡
|
|
534
|
+
let wireLane: string[] = [];
|
|
535
|
+
let wireCursor: string | null = null;
|
|
536
|
+
const laneWiring = createKeyboardWiring({
|
|
537
|
+
host: () => board,
|
|
538
|
+
contract: { layout: 'list', orientation: 'vertical', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
539
|
+
typeaheadDebounceMs: 0,
|
|
540
|
+
paging: {
|
|
541
|
+
listItems: SOMA_SIZE_UNITS.collection.keyboard.pageStep.listItems,
|
|
542
|
+
gridRows: SOMA_SIZE_UNITS.collection.keyboard.pageStep.gridRows,
|
|
543
|
+
},
|
|
544
|
+
items: () => wireLane.map((k) => ({ key: k, text: k })),
|
|
545
|
+
getCursor: () => wireCursor,
|
|
546
|
+
setCursor: (k) => focusCard(k),
|
|
547
|
+
});
|
|
548
|
+
|
|
530
549
|
const onKeydown = (event: Event): void => {
|
|
531
550
|
const e = event as KeyboardEvent;
|
|
532
551
|
if (e.isComposing) return;
|
|
@@ -552,13 +571,14 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
552
571
|
if (li < 0) return;
|
|
553
572
|
const ci = keys[li]!.indexOf(id);
|
|
554
573
|
const lane = cfg.lanes[li]!.value;
|
|
555
|
-
|
|
574
|
+
// 左右键按书写方向换向(RTL 下 ← 去后一条泳道);泳道内的上下 / Home / End / 翻页走共享键盘接线
|
|
575
|
+
const key = kitKey(e.key, root);
|
|
556
576
|
if (key === 'Enter' || key === ' ') {
|
|
557
577
|
e.preventDefault();
|
|
558
578
|
api.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
|
|
559
579
|
return;
|
|
560
580
|
}
|
|
561
|
-
if ((key === 'm' || key === 'M') && !e.altKey && !e.ctrlKey && !e.metaKey && !
|
|
581
|
+
if ((key === 'm' || key === 'M') && !e.altKey && !e.ctrlKey && !e.metaKey && !locked()) {
|
|
562
582
|
e.preventDefault();
|
|
563
583
|
menuFor = menuFor === id ? null : id;
|
|
564
584
|
pendingFocus = menuFor === null ? id : null;
|
|
@@ -571,9 +591,9 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
571
591
|
}
|
|
572
592
|
const horizontal = key === 'ArrowLeft' ? -1 : key === 'ArrowRight' ? 1 : 0;
|
|
573
593
|
const vertical = key === 'ArrowUp' ? -1 : key === 'ArrowDown' ? 1 : 0;
|
|
574
|
-
if (horizontal === 0 && vertical === 0) return;
|
|
575
|
-
e.preventDefault();
|
|
576
594
|
if (e.altKey) {
|
|
595
|
+
if (horizontal === 0 && vertical === 0) return;
|
|
596
|
+
e.preventDefault();
|
|
577
597
|
if (horizontal !== 0) {
|
|
578
598
|
const nl = cfg.lanes[li + horizontal];
|
|
579
599
|
if (nl) move(id, nl.value, laneRows(cfg, nl.value).length);
|
|
@@ -582,7 +602,16 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
582
602
|
}
|
|
583
603
|
return;
|
|
584
604
|
}
|
|
585
|
-
if (
|
|
605
|
+
if (horizontal === 0) {
|
|
606
|
+
// 泳道内:↑ ↓ Home End PageUp PageDown 由共享接线(list / vertical,到边不回绕)决定落点,焦点经 setCursor 落到卡
|
|
607
|
+
if (e.ctrlKey || e.metaKey) return;
|
|
608
|
+
wireLane = keys[li]!;
|
|
609
|
+
wireCursor = id;
|
|
610
|
+
const handled = laneWiring.onKeydown(e);
|
|
611
|
+
if (handled || vertical !== 0) e.preventDefault();
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
e.preventDefault();
|
|
586
615
|
let nl = li + horizontal;
|
|
587
616
|
while (nl >= 0 && nl < keys.length && keys[nl]!.length === 0) nl += horizontal;
|
|
588
617
|
const col = keys[nl];
|
package/src/data/media-grid.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// 点图片抛 `select { id, item }`;视频自带控件,不抛事件。
|
|
8
8
|
|
|
9
9
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
10
11
|
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
11
12
|
import { classTokens, emptyNode, keyMap, mk, rowsOf, textOf } from './shape-util';
|
|
12
13
|
import { rowKey, safeImgSrc } from './d9-util';
|
|
@@ -156,7 +157,11 @@ export function createMediaGrid(): SomaComponentDefinition {
|
|
|
156
157
|
media = btn;
|
|
157
158
|
}
|
|
158
159
|
box.appendChild(media);
|
|
159
|
-
if (withCaption && e.title !== '')
|
|
160
|
+
if (withCaption && e.title !== '') {
|
|
161
|
+
const caption = mk('figcaption', CAPTION_CLASS, e.title);
|
|
162
|
+
caption.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
163
|
+
box.appendChild(caption);
|
|
164
|
+
}
|
|
160
165
|
return box;
|
|
161
166
|
};
|
|
162
167
|
|
package/src/data/mega-menu.ts
CHANGED
|
@@ -13,14 +13,16 @@ import { kitKey, kitText } from '../i18n/kit-text';
|
|
|
13
13
|
import { safeHref } from '../base/link';
|
|
14
14
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, queryWithDropdowns, releaseDropdownsIn, syncDropdown } from '../base/popup';
|
|
15
15
|
import { attrEsc } from './d9-util';
|
|
16
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
16
18
|
import { classSet, FOCUS, h, isRec, onOutsidePointer, recList, textOf, type Rec } from './menu-dom';
|
|
17
19
|
|
|
18
20
|
const ROOT_CLASS = 'relative flex flex-wrap items-center gap-1 text-sm text-fg';
|
|
19
|
-
const TRIGGER_CLASS = `inline-flex h-
|
|
20
|
-
const TRIGGER_OPEN_CLASS = `inline-flex h-
|
|
21
|
+
const TRIGGER_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md px-3 text-sm font-medium text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg ${FOCUS}`;
|
|
22
|
+
const TRIGGER_OPEN_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft ${FOCUS}`;
|
|
21
23
|
const CARET_CLASS = 'inline-flex';
|
|
22
24
|
// 位置类由 popup.ts 的 syncDropdown 贴边翻转时拼上(默认 left-0 top-full mt-1)
|
|
23
|
-
const PANEL_BASE_CLASS = 'absolute z-30 flex w-max max-w-full flex-col gap-3
|
|
25
|
+
const PANEL_BASE_CLASS = mergeClass('absolute z-30 flex w-max max-w-full flex-col gap-3 p-4', kitSurfaceRecipe('raised'));
|
|
24
26
|
const PANEL_CLASS = `${PANEL_BASE_CLASS} start-0 top-full mt-1`;
|
|
25
27
|
const GRID_CLASS: Record<number, string> = {
|
|
26
28
|
1: 'grid grid-cols-1 gap-6',
|
|
@@ -30,7 +32,7 @@ const GRID_CLASS: Record<number, string> = {
|
|
|
30
32
|
};
|
|
31
33
|
const COLUMN_CLASS = 'flex min-w-40 flex-col gap-1';
|
|
32
34
|
const COLUMN_TITLE_CLASS = 'px-3 pb-1 text-xs font-semibold text-fg-subtle';
|
|
33
|
-
const ITEM_CLASS = `flex w-full cursor-pointer flex-col gap-0.5 rounded-md px-3 py-2 text-start transition-colors hover:bg-
|
|
35
|
+
const ITEM_CLASS = `flex w-full cursor-pointer flex-col gap-0.5 rounded-md px-3 py-2 text-start transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${FOCUS}`;
|
|
34
36
|
const ITEM_DISABLED_CLASS = 'flex w-full cursor-not-allowed flex-col gap-0.5 rounded-md px-3 py-2 text-start text-fg-subtle opacity-60';
|
|
35
37
|
const ITEM_HEAD_CLASS = 'flex items-center justify-between gap-2';
|
|
36
38
|
const ITEM_LABEL_CLASS = 'min-w-0 truncate text-sm font-medium text-fg';
|
package/src/data/menu-dom.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// 全部纯函数或无状态:建元素、类串拆候选、记录读取、下拉菜单(弹层 + 焦点进入 / 回焦 / Esc / 点外面关)。
|
|
3
3
|
|
|
4
4
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, dropdownOwnerOf, syncDropdown } from '../base/popup';
|
|
5
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
6
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
5
7
|
|
|
6
8
|
export type Child =Node | string | null | undefined | false;
|
|
7
9
|
|
|
@@ -76,14 +78,14 @@ export interface KitDropdownItem {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
// 外观类;位置类(默认右对齐、下方)由 popup.ts 的 syncDropdown 贴边翻转时拼上
|
|
79
|
-
const DROP_BASE = 'absolute z-30 flex min-w-40 flex-col
|
|
81
|
+
const DROP_BASE = mergeClass('absolute z-30 flex min-w-40 flex-col p-1', kitSurfaceRecipe('raised'));
|
|
80
82
|
const DROP_BOX = `${DROP_BASE} end-0 top-full mt-1.5`;
|
|
81
83
|
|
|
82
84
|
/** 下拉面板已挂进 relative 容器之后调用:贴边翻转(上 / 下、左 / 右端),空间都不够时取较大侧并内部滚动 */
|
|
83
85
|
export function fitDropdownPanel(panel: HTMLElement): void {
|
|
84
86
|
syncDropdown(panel, true, DROP_BASE, undefined, 'end');
|
|
85
87
|
}
|
|
86
|
-
const DROP_ITEM = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg transition-colors hover:bg-
|
|
88
|
+
const DROP_ITEM = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${FOCUS_INSET}`;
|
|
87
89
|
const DROP_ITEM_DISABLED = 'flex h-9 w-full cursor-not-allowed items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg-subtle opacity-60';
|
|
88
90
|
const DROP_ITEM_DANGER = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-danger-on-soft transition-colors hover:bg-danger-soft ${FOCUS_INSET}`;
|
|
89
91
|
const DROP_SEP = 'my-1 h-px w-full bg-border-subtle';
|
package/src/data/menu.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// - divider: true 的项是「分隔线」:只画一条线,不可聚焦、不可选;
|
|
6
6
|
// - 带 children 的项是可折叠分支,点击展开 / 折叠;openable: true 的分支点击时同时选中(抛 select);
|
|
7
7
|
// - open: true 的分支初始展开;
|
|
8
|
-
// - icon
|
|
8
|
+
// - icon 可写 kit 图标名(home / user / users / key / shield / file / sparkles 等 kitIcon 名,画 SVG),
|
|
9
|
+
// 或一个短字符(emoji 或符号,原样画);缺省收起态取标签首字;badge 是徽标文字或数字。
|
|
9
10
|
// `map` 改写键名(组件期望的键 -> 数据里的键)。当前项由 `selected`(id)给出,祖先分支自动展开;
|
|
10
11
|
// `collapsed` 为真时收成仅图标窄栏:只画一级项,分支点击抛 toggle { rail: true } 交宿主决定(通常是展开侧栏)。
|
|
11
12
|
// 键盘走 core 键盘接线(layout: tree):↑↓ 走可见项,→ 展开 / 进入子项,← 折叠 / 回父项,Home / End,Enter / Space 选中。
|
|
@@ -16,8 +17,9 @@ import { kitText } from '../i18n/kit-text';
|
|
|
16
17
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
17
18
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
18
19
|
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
19
21
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
20
|
-
import { kitIcon } from '../base/icons';
|
|
22
|
+
import { KIT_ICON_NAMES, kitIcon, type KitIconName } from '../base/icons';
|
|
21
23
|
import { classSet, cssEscape, firstChar, h, isRec, textOf, type Rec } from './menu-dom';
|
|
22
24
|
import { mountKitMegaMenu } from './mega-menu';
|
|
23
25
|
|
|
@@ -26,16 +28,35 @@ import { mountKitMegaMenu } from './mega-menu';
|
|
|
26
28
|
const ROOT_CLASS = 'flex flex-col text-sm text-fg';
|
|
27
29
|
const LIST_CLASS = 'flex flex-col gap-1';
|
|
28
30
|
const LIST_RAIL_CLASS = 'flex flex-col items-center gap-1';
|
|
29
|
-
|
|
31
|
+
// 子项文字相对父级文字缩进一档(评审 S2:子项不得比父级更靠左):父项有图标时,父级文字起点 = 行内边距 3 + 图标 5 + 间距 2 = 10 个间距单位,
|
|
32
|
+
// 子项行自带 3 的内边距,所以子容器 ps-11(10 + 4 - 3)让子文字落在父文字右侧 4 个单位;父项无图标时父文字起点是 3,子容器 ps-4。
|
|
33
|
+
const GROUP_CLASS = 'flex flex-col gap-1 ps-4';
|
|
34
|
+
const GROUP_ICON_CLASS = 'flex flex-col gap-1 ps-11';
|
|
30
35
|
const ITEM_CLASS = 'flex flex-col gap-1 rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
31
36
|
const ITEM_RAIL_CLASS = 'flex w-full flex-col rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
32
|
-
const ROW_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md px-3 text-sm text-fg-muted transition-colors hover:bg-
|
|
37
|
+
const ROW_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md px-3 text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg';
|
|
33
38
|
const ROW_ACTIVE_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft';
|
|
34
39
|
const ROW_DISABLED_CLASS = 'flex h-9 cursor-not-allowed items-center gap-2 rounded-md px-3 text-sm text-fg-subtle opacity-60';
|
|
35
|
-
const ROW_RAIL_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md text-sm text-fg-muted transition-colors hover:bg-
|
|
40
|
+
const ROW_RAIL_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg';
|
|
36
41
|
const ROW_RAIL_ACTIVE_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md bg-primary-soft text-sm font-medium text-primary-on-soft';
|
|
37
42
|
const HEADING_CLASS = 'px-3 pb-1 pt-3 text-xs font-semibold text-fg-subtle';
|
|
38
43
|
const ICON_CLASS = 'w-5 shrink-0 text-center';
|
|
44
|
+
/** icon 写 kit 图标名时画 SVG:容器居中,不依赖字符基线 */
|
|
45
|
+
const ICON_SVG_CLASS = 'flex w-5 shrink-0 items-center justify-center';
|
|
46
|
+
|
|
47
|
+
/** icon 是 kit 图标名(KitIconName)则返回它,否则 null(仍按短字符原样画,兼容 emoji / 符号 / ≤2 字文本) */
|
|
48
|
+
export function menuIconNameOf(icon: string): KitIconName | null {
|
|
49
|
+
return (KIT_ICON_NAMES as readonly string[]).includes(icon) ? (icon as KitIconName) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 菜单项图标节点:图标名 → SVG;其余 → 文本(空串返回 null) */
|
|
53
|
+
function menuIconNode(icon: string): HTMLElement | null {
|
|
54
|
+
if (icon === '') return null;
|
|
55
|
+
const name = menuIconNameOf(icon);
|
|
56
|
+
return name !== null
|
|
57
|
+
? h('span', ICON_SVG_CLASS, { 'aria-hidden': 'true' }, kitIcon(name, 'md'))
|
|
58
|
+
: h('span', ICON_CLASS, { 'aria-hidden': 'true' }, icon);
|
|
59
|
+
}
|
|
39
60
|
const LABEL_CLASS = 'min-w-0 flex-1 truncate';
|
|
40
61
|
const CARET_CLASS = 'w-4 shrink-0 text-center text-xs text-fg-subtle';
|
|
41
62
|
const BADGE_CLASS = 'shrink-0 rounded-full bg-surface-sunken px-2 text-xs font-medium text-fg-muted';
|
|
@@ -46,9 +67,9 @@ const SEP_CLASS = 'my-1 h-px w-full bg-border-subtle';
|
|
|
46
67
|
|
|
47
68
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
48
69
|
export const KIT_MENU_CLASS_CANDIDATES: readonly string[] = classSet(
|
|
49
|
-
ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS, ITEM_CLASS, ITEM_RAIL_CLASS, ROW_CLASS, ROW_ACTIVE_CLASS, ROW_DISABLED_CLASS,
|
|
70
|
+
ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS, GROUP_ICON_CLASS, ITEM_CLASS, ITEM_RAIL_CLASS, ROW_CLASS, ROW_ACTIVE_CLASS, ROW_DISABLED_CLASS,
|
|
50
71
|
ROW_RAIL_CLASS, ROW_RAIL_ACTIVE_CLASS, HEADING_CLASS, ICON_CLASS, LABEL_CLASS, CARET_CLASS, BADGE_CLASS, BADGE_PRIMARY_CLASS,
|
|
51
|
-
BADGE_DANGER_CLASS, BADGE_ACTIVE_CLASS, SEP_CLASS,
|
|
72
|
+
BADGE_DANGER_CLASS, BADGE_ACTIVE_CLASS, SEP_CLASS, ICON_SVG_CLASS,
|
|
52
73
|
);
|
|
53
74
|
|
|
54
75
|
// ───────── 数据规整纯函数:键名对照、节点树、祖先链、可见项 ─────────
|
|
@@ -209,6 +230,8 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
209
230
|
let cursor: string | null = null;
|
|
210
231
|
let selected = '';
|
|
211
232
|
let lastGiven: string | null = null;
|
|
233
|
+
/** 手风琴:上一次选中项所在的一级分支('' = 选中的是一级叶子或没有选中);null = 还没选过 */
|
|
234
|
+
let lastTop: string | null = null;
|
|
212
235
|
let dataSig = '';
|
|
213
236
|
let rail = false;
|
|
214
237
|
let props: Rec = {};
|
|
@@ -287,6 +310,7 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
287
310
|
sig = `cyclic:${Math.random()}`;
|
|
288
311
|
}
|
|
289
312
|
const expandAll = bool(props.expand_all);
|
|
313
|
+
const accordion = bool(props.accordion);
|
|
290
314
|
if (sig !== dataSig) {
|
|
291
315
|
dataSig = sig;
|
|
292
316
|
nodes = buildMenuNodes(props.data, map);
|
|
@@ -306,7 +330,14 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
306
330
|
if (given !== lastGiven) {
|
|
307
331
|
lastGiven = given;
|
|
308
332
|
selected = given;
|
|
309
|
-
|
|
333
|
+
const trail = menuAncestors(nodes, given);
|
|
334
|
+
// 手风琴:选中项落进另一个一级分支(或一级叶子)时,先收起其余分支;同一分支内换项、用户手动展开的分支都保留
|
|
335
|
+
if (accordion && given !== '') {
|
|
336
|
+
const top = trail[0] ?? '';
|
|
337
|
+
if (top !== lastTop) open.clear();
|
|
338
|
+
lastTop = top;
|
|
339
|
+
}
|
|
340
|
+
for (const a of trail) open.add(a);
|
|
310
341
|
}
|
|
311
342
|
rail = bool(props.collapsed);
|
|
312
343
|
};
|
|
@@ -336,20 +367,20 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
336
367
|
let row: HTMLElement;
|
|
337
368
|
if (rail) {
|
|
338
369
|
row = h('div', active ? ROW_RAIL_ACTIVE_CLASS : ROW_RAIL_CLASS, {},
|
|
339
|
-
h('span', '', { 'aria-hidden': 'true' },
|
|
370
|
+
menuIconNode(n.icon) ?? h('span', '', { 'aria-hidden': 'true' }, firstChar(n.label)));
|
|
340
371
|
} else {
|
|
341
372
|
const badgeClass = active ? BADGE_ACTIVE_CLASS
|
|
342
373
|
: n.badgeTone === 'danger' ? BADGE_DANGER_CLASS
|
|
343
374
|
: n.badgeTone === 'primary' ? BADGE_PRIMARY_CLASS : BADGE_CLASS;
|
|
344
375
|
row = h('div', n.disabled ? ROW_DISABLED_CLASS : active ? ROW_ACTIVE_CLASS : ROW_CLASS, {},
|
|
345
|
-
|
|
346
|
-
h('span', LABEL_CLASS, {}, n.label),
|
|
376
|
+
menuIconNode(n.icon),
|
|
377
|
+
h('span', LABEL_CLASS, { [KIT_TIPS_SCOPE_ATTR]: '' }, n.label),
|
|
347
378
|
n.badge !== '' ? h('span', badgeClass, { 'data-kit-badge': '' }, n.badge) : null,
|
|
348
379
|
branch ? h('span', CARET_CLASS, { 'aria-hidden': 'true', 'data-kit-toggle': '' }, kitIcon(isOpen ? 'chevron-down' : 'chevron-right', 'sm', 'rtl:-scale-x-100')) : null);
|
|
349
380
|
}
|
|
350
381
|
li.append(row);
|
|
351
382
|
if (isOpen) {
|
|
352
|
-
const group = h('ul', GROUP_CLASS, { role: 'group' });
|
|
383
|
+
const group = h('ul', n.icon !== '' ? GROUP_ICON_CLASS : GROUP_CLASS, { role: 'group' });
|
|
353
384
|
for (const child of n.children) for (const node of buildItem(child, tabbable)) group.append(node);
|
|
354
385
|
li.append(group);
|
|
355
386
|
}
|
|
@@ -413,9 +444,10 @@ export function createMenu(): SomaComponentDefinition {
|
|
|
413
444
|
layer: 'data',
|
|
414
445
|
props: {
|
|
415
446
|
layout: { type: 'enum', values: ['tree', 'columns'], default: 'tree', desc: 'tree = 多级菜单(侧栏式);columns = 多列下拉导航(data 为触发钮数组 [{ id, label, columns[{ title?, items[{ id, label, desc?, href?, badge?, disabled? }] }], footer? }])' },
|
|
416
|
-
data: { type: 'array', default: [], desc: '菜单数据 [{ id, label, icon?, badge?, badge_tone?, href?, disabled?, openable?, group?, open?, children? }];group
|
|
447
|
+
data: { type: 'array', default: [], desc: '菜单数据 [{ id, label, icon?, badge?, badge_tone?, href?, disabled?, openable?, group?, open?, children? }];group 为分组标题;icon 可写 kit 图标名(画 SVG)或短字符。layout=columns 时见 layout' },
|
|
417
448
|
map: { type: 'object', default: {}, desc: '键名对照 { id, label, children, icon, badge, href }:组件期望的键 -> 数据里的键' },
|
|
418
449
|
selected: { type: 'string', default: '', desc: '当前项 id;祖先分支自动展开' },
|
|
450
|
+
accordion: { type: 'boolean', default: false, desc: '手风琴:选中项变化时只展开其所在的一级分支(其余收起);用户手动展开的分支保留,直到选中项落进另一个一级分支。工作台侧栏默认开启(sidebar.accordion),独立 Menu 缺省关闭' },
|
|
419
451
|
collapsed: { type: 'boolean', default: false, desc: '收起成仅图标窄栏(只画一级,分支点击抛 toggle { rail: true })' },
|
|
420
452
|
expand_all: { type: 'boolean', default: false, desc: '初始全部展开' },
|
|
421
453
|
label: { type: 'string', default: '', desc: '导航区域的可访问名;缺省取内置文案(按页面语言)' },
|
package/src/data/mockup.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// 纯展示,无事件。
|
|
9
9
|
|
|
10
10
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
11
12
|
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
12
13
|
import { kitText } from '../i18n/kit-text';
|
|
13
14
|
import { classTokens, emptyNode, mk, shapeToneOf, textOf, TONE_SOFT, type Rec, type ShapeTone } from './shape-util';
|
|
@@ -120,7 +121,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
120
121
|
root.setAttribute('data-kit-variant', variant);
|
|
121
122
|
if (variant === 'code') {
|
|
122
123
|
const lines = mockupLinesOf(src.lines, num(p.start) ?? 1);
|
|
123
|
-
if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)))); return; }
|
|
124
|
+
if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true)); return; }
|
|
124
125
|
const frame = mk('div', CODE_CLASS);
|
|
125
126
|
const bar = mk('div', BAR_CLASS);
|
|
126
127
|
const dots = mk('div', DOTS_CLASS);
|
|
@@ -147,7 +148,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
147
148
|
const frame = mk('div', PHONE_CLASS);
|
|
148
149
|
frame.appendChild(mk('div', NOTCH_CLASS));
|
|
149
150
|
const screen = mk('div', SCREEN_CLASS);
|
|
150
|
-
if (body) screen.appendChild(body); else screen.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
|
|
151
|
+
if (body) screen.appendChild(body); else screen.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true));
|
|
151
152
|
frame.appendChild(screen);
|
|
152
153
|
root.appendChild(frame);
|
|
153
154
|
return;
|
|
@@ -160,14 +161,17 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
160
161
|
if (variant === 'browser') {
|
|
161
162
|
const address = mk('div', ADDRESS_CLASS, textOf(src.url));
|
|
162
163
|
address.setAttribute('data-kit-address', '');
|
|
164
|
+
address.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
163
165
|
bar.appendChild(address);
|
|
164
166
|
} else {
|
|
165
|
-
|
|
167
|
+
const barTitle = mk('div', TITLE_CLASS, textOf(src.title));
|
|
168
|
+
barTitle.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
169
|
+
bar.appendChild(barTitle);
|
|
166
170
|
bar.appendChild(mk('span', SPACER_CLASS));
|
|
167
171
|
}
|
|
168
172
|
frame.appendChild(bar);
|
|
169
173
|
const area = mk('div', BODY_CLASS);
|
|
170
|
-
if (body) area.appendChild(body); else area.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
|
|
174
|
+
if (body) area.appendChild(body); else area.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true));
|
|
171
175
|
frame.appendChild(area);
|
|
172
176
|
root.appendChild(frame);
|
|
173
177
|
},
|
package/src/data/modal-dialog.ts
CHANGED
|
@@ -14,19 +14,22 @@ import { mountKitOverlay } from './overlay-portal';
|
|
|
14
14
|
import { kitIcon } from '../base/icons';
|
|
15
15
|
import { trapTab } from '../base/popup';
|
|
16
16
|
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { KIT_DIALOG_SURFACE_CLASS, KIT_OVERLAY_WIDTH_CLASS } from '../recipes/overlay';
|
|
17
18
|
import { KIT_PART_ATTRIBUTE, KIT_PART_DIALOG, KIT_PART_TITLE_DIALOG, kitTypographyRecipe } from '../recipes';
|
|
19
|
+
import { beginKitLeave, type KitLeaveHandle } from '../base/overlay-runtime';
|
|
18
20
|
import { lockDocumentScroll } from 'soma-core/behavior';
|
|
19
21
|
import type { OverlayMount } from 'soma-core/behavior';
|
|
20
22
|
|
|
21
23
|
export type KitModalSize = 'sm' | 'md' | 'lg';
|
|
22
24
|
|
|
23
|
-
const LAYER_CLASS = 'fixed inset-0 z-50 bg-scrim';
|
|
25
|
+
const LAYER_CLASS = 'fixed inset-0 z-50 bg-scrim motion-safe:animate-kit-fade';
|
|
24
26
|
const ROW_CLASS = 'flex h-full items-center justify-center p-4';
|
|
25
|
-
const PANEL_BASE =
|
|
26
|
-
|
|
27
|
+
const PANEL_BASE = `flex max-h-full w-full flex-col gap-4 ${KIT_DIALOG_SURFACE_CLASS} p-6 focus-visible:outline-none motion-safe:animate-kit-dialog-in`;
|
|
28
|
+
// 宽度两档读 design 真源(kit-limits#overlay.dialogPx):sm = 480 默认档,md / lg = 720 长表单档(U1b)
|
|
29
|
+
const PANEL_SIZE: Readonly<Record<KitModalSize, string>> = Object.freeze({ sm: KIT_OVERLAY_WIDTH_CLASS.dialog, md: KIT_OVERLAY_WIDTH_CLASS.dialogWide, lg: KIT_OVERLAY_WIDTH_CLASS.dialogWide });
|
|
27
30
|
const HEAD_CLASS = 'flex shrink-0 items-center justify-between gap-3';
|
|
28
31
|
const TITLE_CLASS = mergeClass(kitTypographyRecipe('dialogTitle'), 'm-0');
|
|
29
|
-
const CLOSE_CLASS = 'inline-flex size-8 shrink-0 border-0 bg-transparent p-0 cursor-pointer items-center justify-center rounded-md text-fg-muted transition-colors hover:bg-
|
|
32
|
+
const CLOSE_CLASS = 'inline-flex size-8 shrink-0 border-0 bg-transparent p-0 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-2 focus-visible:ring-ring';
|
|
30
33
|
const BODY_CLASS = 'flex flex-1 min-h-0 flex-col gap-3 overflow-y-auto text-sm text-fg-muted';
|
|
31
34
|
const FOOT_CLASS = 'flex shrink-0 flex-wrap items-center justify-end gap-3';
|
|
32
35
|
|
|
@@ -126,6 +129,8 @@ export function mountKitModal(opts: KitModalOptions, doc: Document = document):
|
|
|
126
129
|
let prev: Element | null = null;
|
|
127
130
|
let mounted: OverlayMount | null = null;
|
|
128
131
|
let releaseScroll: (() => void) | null = null;
|
|
132
|
+
// 退场中的句柄:关闭后遮罩留在文档里等退场动画结束再卸载;期间再次 open() 取消退场、原地复用
|
|
133
|
+
let leaving: KitLeaveHandle | null = null;
|
|
129
134
|
const unlockScroll = (): void => {
|
|
130
135
|
const release = releaseScroll;
|
|
131
136
|
releaseScroll = null;
|
|
@@ -155,9 +160,16 @@ export function mountKitModal(opts: KitModalOptions, doc: Document = document):
|
|
|
155
160
|
prev = doc.activeElement;
|
|
156
161
|
layer.hidden = false;
|
|
157
162
|
releaseScroll = lockDocumentScroll(doc);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
if (leaving !== null) {
|
|
164
|
+
// 退场未结束又被打开:取消退场,遮罩仍挂着,原地复用(不重复挂载、不串状态)
|
|
165
|
+
leaving.cancel();
|
|
166
|
+
leaving = null;
|
|
167
|
+
} else {
|
|
168
|
+
// Esc 只在打开态响应(退场期间忽略,不替下层浮层吞键之外不改任何业务状态)
|
|
169
|
+
mounted = mountKitOverlay(scrim, { anchor: layer, onEscape: () => { if (opened) opts.onClose(); } });
|
|
170
|
+
// 没有可挂载的文档(端口不可用)时退回锚点内联,保证至少能显示
|
|
171
|
+
if (!mounted) layer.appendChild(scrim);
|
|
172
|
+
}
|
|
161
173
|
panel.focus();
|
|
162
174
|
},
|
|
163
175
|
close(): void {
|
|
@@ -165,13 +177,21 @@ export function mountKitModal(opts: KitModalOptions, doc: Document = document):
|
|
|
165
177
|
opened = false;
|
|
166
178
|
layer.hidden = true;
|
|
167
179
|
unlockScroll();
|
|
168
|
-
|
|
169
|
-
|
|
180
|
+
// 焦点归还与解滚动锁不等退场:关闭意图一发生就生效;遮罩留到退场动画结束(无动画 / 减弱动效时立即卸载)
|
|
181
|
+
const unmount = (): void => {
|
|
182
|
+
leaving = null;
|
|
183
|
+
releaseMount();
|
|
184
|
+
if (scrim.parentElement === layer) scrim.remove();
|
|
185
|
+
};
|
|
186
|
+
leaving = scrim.isConnected ? beginKitLeave(scrim, unmount) : null;
|
|
187
|
+
if (leaving === null) unmount();
|
|
170
188
|
if (opts.restoreFocus !== false && typeof HTMLElement !== 'undefined' && prev instanceof HTMLElement && prev.isConnected) prev.focus();
|
|
171
189
|
prev = null;
|
|
172
190
|
},
|
|
173
191
|
isOpen: () => opened,
|
|
174
192
|
destroy(): void {
|
|
193
|
+
leaving?.cancel();
|
|
194
|
+
leaving = null;
|
|
175
195
|
scrim.removeEventListener('keydown', onKey);
|
|
176
196
|
scrim.removeEventListener('click', onScrim);
|
|
177
197
|
closeBtn.removeEventListener('click', onCloseClick);
|
package/src/data/navbar.ts
CHANGED
|
@@ -37,14 +37,14 @@ const SLOT_END ='ms-auto flex shrink-0 items-center gap-2';
|
|
|
37
37
|
const BRAND_CLASS = `flex min-w-0 cursor-pointer items-center gap-3 rounded-md ${FOCUS}`;
|
|
38
38
|
const LOGO_CLASS = 'flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary text-sm font-semibold text-primary-fg';
|
|
39
39
|
const BRAND_TEXT_CLASS = 'min-w-0 truncate text-base font-semibold text-fg';
|
|
40
|
-
const MENU_BTN_CLASS = `inline-flex h-
|
|
41
|
-
const BTN_BASE = `inline-flex h-
|
|
40
|
+
const MENU_BTN_CLASS = `inline-flex h-8 w-8 shrink-0 p-0 items-center justify-center rounded-md bg-surface-raised text-fg shadow-xs transition-colors state-layer @4xl:hidden ${FOCUS}`;
|
|
41
|
+
const BTN_BASE = `inline-flex h-8 items-center justify-center gap-2 rounded-md px-3 text-sm font-medium transition-colors ${FOCUS}`;
|
|
42
42
|
const VARIANT_CLASS: Record<string, string> = {
|
|
43
|
-
ghost: `${BTN_BASE} text-fg-muted hover:bg-
|
|
44
|
-
outline: `${BTN_BASE} bg-surface-raised text-fg shadow-xs
|
|
43
|
+
ghost: `${BTN_BASE} text-fg-muted hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg`,
|
|
44
|
+
outline: `${BTN_BASE} bg-surface-raised text-fg shadow-xs state-layer`,
|
|
45
45
|
primary: `${BTN_BASE} bg-primary text-primary-fg hover:bg-primary-hover active:bg-primary-active`,
|
|
46
46
|
};
|
|
47
|
-
const DISABLED_CLASS = 'inline-flex h-
|
|
47
|
+
const DISABLED_CLASS = 'inline-flex h-8 cursor-not-allowed items-center justify-center gap-2 rounded-md px-3 text-sm font-medium text-fg-subtle opacity-60';
|
|
48
48
|
const TEXT_CLASS = 'inline-flex items-center px-2 text-sm text-fg-muted';
|
|
49
49
|
const BADGE_CLASS = 'rounded-full bg-primary-soft px-2 text-xs font-medium text-primary-on-soft';
|
|
50
50
|
const FROM_CLASS: Record<string, string> = { md: 'hidden @md:contents', lg: 'hidden @lg:contents', xl: 'hidden @xl:contents' };
|