soma-kit 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/spec/generated/kit-app.schema.json +14 -0
- package/spec/generated/kit-page.schema.json +25 -0
- package/spec/kit-grammar.json +178 -27
- package/spec/kit-grammar.schema.json +1 -3
- package/src/app/app-config.ts +10 -4
- package/src/app/index.ts +13 -1
- package/src/app/kit-view-context.ts +19 -2
- package/src/app/server-pages.ts +5 -1
- package/src/app/server.ts +15 -5
- package/src/base/button.ts +5 -3
- package/src/base/end-edge.ts +14 -2
- package/src/base/gap-value.ts +24 -4
- package/src/base/illustrations.ts +2 -1
- package/src/base/index.ts +5 -0
- package/src/base/menu-button.ts +10 -23
- package/src/base/popover.ts +5 -4
- package/src/base/segmented.ts +14 -4
- package/src/base/shared.ts +11 -13
- package/src/base/state-panel.ts +34 -13
- package/src/base/tag.ts +18 -13
- package/src/base/text.ts +1 -1
- package/src/base/upload.ts +5 -4
- package/src/biz/approval-desk/shell.ts +8 -7
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +3 -2
- package/src/biz/category-crud/shell.ts +4 -3
- package/src/biz/checkout-page/shell.ts +9 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +12 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/master-sub/compile.ts +114 -15
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +3 -2
- package/src/biz/master-sub/shell.ts +95 -63
- package/src/biz/multi-board/compile.ts +164 -9
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +1 -1
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +91 -23
- package/src/biz/notification-center/shell.ts +6 -5
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -2
- package/src/biz/page-templates/sign-in-page/shell.ts +14 -14
- package/src/biz/record-detail/shell.ts +8 -7
- package/src/biz/settings-center/shell.ts +8 -7
- package/src/biz/shared/compile-helpers.ts +82 -3
- package/src/biz/shared/overlay-compile.ts +46 -4
- package/src/biz/shared/overlay-shell.ts +8 -6
- package/src/biz/single-form/shell.ts +6 -4
- package/src/biz/standard-crud/compile.ts +14 -1
- package/src/biz/standard-crud/shell.ts +18 -27
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +11 -9
- package/src/biz/types.ts +6 -1
- package/src/cli/layout-cli.ts +7 -7
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/compile-page.ts +15 -4
- package/src/compile/component-candidates.ts +2 -0
- package/src/compile/fragment.ts +11 -0
- package/src/compile/layout-lint/rules-composition.ts +55 -6
- package/src/compile/layout-lint/rules-form.ts +6 -7
- package/src/compile/layout-lint/rules-table.ts +98 -14
- package/src/compile/page-composition.ts +189 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/styles.ts +11 -1
- package/src/compile/types.ts +3 -1
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +3 -1
- package/src/data/approval-flow.ts +4 -1
- package/src/data/assignment-picker.ts +9 -4
- package/src/data/async-result-panel.ts +1 -1
- package/src/data/calendar.ts +7 -2
- package/src/data/carousel.ts +2 -0
- package/src/data/chart.ts +609 -42
- package/src/data/checklist.ts +4 -1
- package/src/data/comment-thread.ts +2 -1
- package/src/data/confirm-dialog.ts +4 -10
- package/src/data/field-mapper.ts +4 -1
- package/src/data/flow-editor.ts +2 -1
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +187 -25
- package/src/data/hero.ts +2 -0
- package/src/data/index.ts +10 -3
- package/src/data/item-list.ts +10 -3
- package/src/data/kanban.ts +3 -1
- package/src/data/matrix.ts +391 -0
- package/src/data/menu.ts +23 -11
- package/src/data/mockup.ts +3 -3
- package/src/data/modal-dialog.ts +118 -18
- package/src/data/navbar.ts +3 -1
- package/src/data/notice-list.ts +52 -19
- package/src/data/object-form.ts +128 -112
- package/src/data/pager.ts +3 -2
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +4 -1
- package/src/data/permission-tree.ts +6 -2
- package/src/data/pricing-table.ts +2 -1
- package/src/data/record-card.ts +18 -6
- package/src/data/resident.ts +8 -0
- package/src/data/row-editor.ts +2 -2
- package/src/data/rule-builder.ts +9 -4
- package/src/data/shape-util.ts +15 -14
- package/src/data/stat-group.ts +313 -69
- package/src/data/static-lazy.ts +4 -0
- package/src/data/static-registry.ts +6 -0
- package/src/data/survey.ts +4 -1
- package/src/data/system-switcher.ts +2 -1
- package/src/data/tour-guide.ts +2 -1
- package/src/data/transfer.ts +6 -2
- package/src/data/tree-table.ts +7 -5
- package/src/data/tree.ts +1 -1
- package/src/data/virtual-rows.ts +5 -4
- package/src/data/wrapped-candidates.ts +22 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +6 -14
- package/src/frames/shared.ts +20 -4
- package/src/frames/tabs-frame/shell.ts +8 -6
- package/src/frames/top-main-frame.ts +1 -1
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +41 -25
- package/src/generated/kit-grammar-runtime.ts +175 -28
- package/src/i18n/kit-text.ts +27 -0
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +49 -19
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +34 -13
- package/src/object-renderer/collection-table.ts +133 -65
- package/src/object-renderer/collection.ts +72 -59
- package/src/object-renderer/defaults.ts +2 -5
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +116 -63
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +9 -1
- package/src/object-renderer/layout-plan.ts +136 -43
- package/src/object-renderer/layout-plan.types.ts +42 -5
- package/src/object-renderer/parts.ts +7 -259
- package/src/object-renderer/render-object.ts +59 -46
- package/src/object-renderer/table-actions.ts +72 -40
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +51 -20
- package/src/object-renderer/types.ts +7 -7
- package/src/recipes/container.ts +31 -0
- package/src/recipes/control.ts +57 -155
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +23 -0
- package/src/recipes/overlay.ts +46 -1
- package/src/recipes/placeholder.ts +20 -4
- package/src/recipes/rail-grid.ts +3 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +12 -22
- package/src/recipes/status.ts +8 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +112 -6
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +3 -3
- package/src/recipes/typography.ts +23 -42
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +13 -2
- package/src/theme/kit-theme.tpl +13 -2
- package/src/theme/nine-dim-structure.ts +77 -10
- package/src/theme/surface-layers.ts +6 -1
- package/src/theme/theme-tokens.ts +12 -5
- package/src/theme/typography.ts +21 -17
package/src/data/item-list.ts
CHANGED
|
@@ -12,8 +12,9 @@ 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, retryButton, rowsOf, shapeToneOf, textOf, TONE_SOFT,
|
|
15
|
+
actionButton, actionsOf, BADGE_BASE, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, recOf, retryButton, rowsOf, shapeToneOf, textOf, TONE_DOT, TONE_SOFT,
|
|
16
16
|
} from './shape-util';
|
|
17
|
+
import { KIT_STATUS_BADGE_CLASS, KIT_STATUS_DOT_CLASS } from '../recipes/status';
|
|
17
18
|
import { KIT_ROW_TONE_CLASS } from '../object-renderer/view-binding';
|
|
18
19
|
import { AVATAR_CLASS_TOKENS, avatarNode } from './d9-util';
|
|
19
20
|
import { provideCtxRows } from './context-menu';
|
|
@@ -53,7 +54,7 @@ const BUSY_LIST_CLASS = `${KIT_ROW_TONE_CLASS.muted} transition-opacity`;
|
|
|
53
54
|
export const KIT_ITEM_LIST_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
54
55
|
STATE_ERR_CLASS, STATE_BUSY_CLASS, BUSY_LIST_CLASS,
|
|
55
56
|
ROOT_CLASS, Object.values(ROOT_SCROLL), ITEM_CLASS, ITEM_ON_CLASS, MAIN_CLASS, MAIN_DISABLED, TITLE_CLASS, SUB_CLASS, TEXT_CLASS,
|
|
56
|
-
TAGS_CLASS, ACTIONS_CLASS, BADGE_BASE, Object.values(TONE_SOFT), BUTTON_CLASS_TOKENS,
|
|
57
|
+
TAGS_CLASS, ACTIONS_CLASS, BADGE_BASE, Object.values(TONE_SOFT), Object.values(TONE_DOT), KIT_STATUS_BADGE_CLASS, KIT_STATUS_DOT_CLASS, BUTTON_CLASS_TOKENS,
|
|
57
58
|
PREFIX_CLASS, SUFFIX_CLASS, HEAD_ROW_CLASS, BODY_COL_CLASS, AVATAR_CLASS_TOKENS, GROUP_HEAD_CLASS,
|
|
58
59
|
);
|
|
59
60
|
|
|
@@ -316,7 +317,13 @@ export function createItemList(): SomaComponentDefinition {
|
|
|
316
317
|
if (it.text !== '') body.appendChild(mk('span', TEXT_CLASS, it.text));
|
|
317
318
|
if (it.tags.length > 0) {
|
|
318
319
|
const tags = mk('span', TAGS_CLASS);
|
|
319
|
-
|
|
320
|
+
// 状态 / 分类分开:带语气(非 neutral)的项表达「状态」,画状态徽标(浅底 + 圆点 + 文字);无语气的项是「分类 / 标签」,用无圆点的中性胶囊
|
|
321
|
+
for (const t of it.tags) {
|
|
322
|
+
if (t.tone === 'neutral') { tags.appendChild(mk('span', `${BADGE_BASE} ${TONE_SOFT.neutral}`, t.label)); continue; }
|
|
323
|
+
const mark = mk('span', `${KIT_STATUS_BADGE_CLASS} ${TONE_SOFT[t.tone]}`);
|
|
324
|
+
mark.append(mk('span', `${KIT_STATUS_DOT_CLASS} ${TONE_DOT[t.tone]}`), t.label);
|
|
325
|
+
tags.appendChild(mark);
|
|
326
|
+
}
|
|
320
327
|
body.appendChild(tags);
|
|
321
328
|
}
|
|
322
329
|
li.appendChild(main);
|
package/src/data/kanban.ts
CHANGED
|
@@ -30,6 +30,8 @@ import { kitKey, kitText } from '../i18n/kit-text';
|
|
|
30
30
|
import { createKeyboardWiring } from 'soma-core/keyboard';
|
|
31
31
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
32
32
|
import { setKitFace } from '../recipes';
|
|
33
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
34
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
33
35
|
import { provideCtxRows } from './context-menu';
|
|
34
36
|
|
|
35
37
|
// ───────── 样式常量:Tailwind 类串与候选类清单 ─────────
|
|
@@ -49,7 +51,7 @@ const CARD_TITLE_CLASS = 'font-medium text-fg';
|
|
|
49
51
|
const FACT_CLASS = 'flex items-baseline justify-between gap-2 text-xs text-fg-muted';
|
|
50
52
|
const FACT_VALUE_CLASS = 'truncate text-fg';
|
|
51
53
|
const EMPTY_CLASS = 'px-2 py-3 text-center text-sm text-fg-muted';
|
|
52
|
-
const MOVE_BTN_CLASS = '
|
|
54
|
+
const MOVE_BTN_CLASS = mergeClass(kitEmphasisButtonRecipe('button.toolbar'), 'self-start');
|
|
53
55
|
const MENU_CLASS = 'flex flex-col gap-1 rounded-md border border-border bg-surface p-1';
|
|
54
56
|
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';
|
|
55
57
|
const NOTICE_CLASS = 'rounded-md border border-border-subtle bg-warning-soft px-3 py-1.5 text-xs text-warning-on-soft';
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
// Matrix:状态着色矩阵(layer: data,写死形状,accept: single)。
|
|
2
|
+
//
|
|
3
|
+
// 数据:`data` 是一个对象 `{ cols, rows, legend }`:
|
|
4
|
+
// cols [{ key, label, note?, group? }](列;group 相同的相邻列在表头上合并成列组标题)
|
|
5
|
+
// rows [{ key, label, note?, group?, summary?, cells: [{ col, text?, tone?, level?, mark?, state?, hint? }] }](行;group 变化时插一条行组标题行)
|
|
6
|
+
// legend [{ tone, label }](图例,可选)
|
|
7
|
+
// 单元格语义:tone(neutral / primary / success / warning / danger / info)= 浅底 + 同色相文字,不是大色块;level(0..4)= 单色相强度;
|
|
8
|
+
// mark(alert / diamond / check / hollow / unknown / leave)= 符号字形;text = 短文本;state:ready(缺省)/ missing(格内「—」)/ unknown(「?」,不当作 0)。
|
|
9
|
+
// 行里没给的列 = 缺失格。形状规整与状态映射是 `soma-foundation/kit-viz` 的纯函数(parseMatrixModel / matrixCellView),本文件只画。
|
|
10
|
+
//
|
|
11
|
+
// 结构:真 `<table>`(`<th scope="col">` 列头、`<th scope="row">` 行头、行组 / 列组标题 `scope="rowgroup"` / `colgroup`),表头吸顶、行头吸左(横向滚动下行头固定),
|
|
12
|
+
// 每个单元格是一个按钮(aria-label「行 列:文本 状态 提示」),键盘走 core 键盘接线(`soma-core/keyboard`,layout: grid,roving tabindex:↑↓←→ / Home / End / 翻页,Enter / Space 激活)。
|
|
13
|
+
// 事件走 core:`cell_pick { row, col, cell }`(点击 / Enter 单元格;row / col 是键,cell 是源数据里的原对象或 null)、`row_pick { row }`(点行头)。
|
|
14
|
+
// 颜色只取语义色名类(浅底 + on-soft 文字);字阶与表格内边距取 kit 配方,不手写。
|
|
15
|
+
|
|
16
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
17
|
+
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
18
|
+
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
19
|
+
import {
|
|
20
|
+
MATRIX_LEVEL_PCT, matrixCellView, parseMatrixModel,
|
|
21
|
+
type MatrixCellView, type MatrixModel, type MatrixRow, type MatrixSpec, type MatrixTone,
|
|
22
|
+
} from 'soma-foundation/kit-viz';
|
|
23
|
+
import { classCandidates } from '../base/class-candidates';
|
|
24
|
+
import { createKitController, joinClass, bool, str } from '../base/shared';
|
|
25
|
+
import {
|
|
26
|
+
KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS, KIT_STATE_PANEL_CLASS_CANDIDATES, paintKitStatePanel,
|
|
27
|
+
} from '../base/state-panel';
|
|
28
|
+
import { kitText } from '../i18n/kit-text';
|
|
29
|
+
import { kitFocusRingRecipe } from '../recipes/state';
|
|
30
|
+
import { KIT_TAG_UNKNOWN_OUTLINE } from '../recipes/status';
|
|
31
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
32
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
33
|
+
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
34
|
+
|
|
35
|
+
/** 闭集 / 占位 / 字形读语法真源 kit-grammar.json#dataLimits.matrix;数字限值(行列封顶、强度档不透明度)读 design kit-limits 经 foundation */
|
|
36
|
+
const MATRIX_SPEC: MatrixSpec = (grammarJson as unknown as { dataLimits: { matrix: MatrixSpec & { events: string[] } } }).dataLimits.matrix;
|
|
37
|
+
export const KIT_MATRIX_TONES: readonly string[] = MATRIX_SPEC.tones;
|
|
38
|
+
export const KIT_MATRIX_MARKS: readonly string[] = MATRIX_SPEC.marks;
|
|
39
|
+
|
|
40
|
+
// ───────── 类串与候选 ─────────
|
|
41
|
+
|
|
42
|
+
const ROOT_CLASS = 'relative flex w-full flex-col gap-2';
|
|
43
|
+
/** 滚动外壳:纵向最大高度档(表头吸顶要有有界的滚动容器);none = 不设上限 */
|
|
44
|
+
const SCROLL_CLASS: Readonly<Record<string, string>> = Object.freeze({ none: '', sm: 'max-h-64', md: 'max-h-96', lg: 'max-h-128' });
|
|
45
|
+
const SCROLLER_CLASS = 'relative w-full overflow-auto';
|
|
46
|
+
const TABLE_CLASS = mergeClass('w-full', kitTypographyRecipe('text'));
|
|
47
|
+
const HEAD_CELL_CLASS = mergeClass('whitespace-nowrap px-1 py-1 text-center', kitTypographyRecipe('tableHead'));
|
|
48
|
+
const GROUP_HEAD_CLASS = mergeClass('whitespace-nowrap px-1 py-1 text-center', kitTypographyRecipe('tableGroup'));
|
|
49
|
+
const NOTE_CLASS = 'block font-normal text-fg-subtle';
|
|
50
|
+
const ROW_HEAD_CLASS = mergeClass('whitespace-nowrap px-2 py-0.5 text-start', kitTypographyRecipe('text'));
|
|
51
|
+
const ROW_HEAD_BTN_CLASS = mergeClass(mergeClass('max-w-full truncate rounded-sm text-start', kitTypographyRecipe('text')), kitFocusRingRecipe('item'));
|
|
52
|
+
const ROW_GROUP_CLASS = mergeClass('px-2 pb-1 pt-3 text-start', kitTypographyRecipe('tableGroup'));
|
|
53
|
+
const SUMMARY_CLASS = mergeClass(kitTypographyRecipe('text'), 'whitespace-nowrap px-2 py-0.5 text-end tabular-nums text-fg-muted');
|
|
54
|
+
const CELL_TD_CLASS = 'p-0.5 align-middle';
|
|
55
|
+
const CELL_BTN_CLASS = mergeClass(mergeClass('flex h-8 w-full min-w-14 items-center justify-center gap-1 rounded-md px-1', kitTypographyRecipe('deltaSm')), kitFocusRingRecipe('item'));
|
|
56
|
+
const GLYPH_CLASS = 'shrink-0';
|
|
57
|
+
const STICKY_HEAD = 'sticky top-0 z-10 bg-surface';
|
|
58
|
+
const STICKY_FIRST = 'sticky start-0 z-10 bg-surface';
|
|
59
|
+
const STICKY_CORNER = 'sticky start-0 top-0 z-20 bg-surface';
|
|
60
|
+
/** 汇总列固定在右侧可见:横向滚动只发生在中间的数据列,窄宽下汇总也不被裁(与行头吸左对称;格子之间靠间隙分隔、不画线,行头列头不加框) */
|
|
61
|
+
const STICKY_LAST = 'sticky end-0 z-10 bg-surface';
|
|
62
|
+
const STICKY_HEAD_LAST = 'sticky end-0 top-0 z-20 bg-surface';
|
|
63
|
+
const FIRST_COL_MIN = 'min-w-36';
|
|
64
|
+
const LEGEND_CLASS = mergeClass('m-0 flex list-none flex-wrap items-center gap-x-4 gap-y-1 p-0', kitTypographyRecipe('caption'));
|
|
65
|
+
const LEGEND_ITEM_CLASS = 'inline-flex items-center gap-1.5';
|
|
66
|
+
const LEGEND_SWATCH_CLASS = 'size-3 shrink-0 rounded-sm';
|
|
67
|
+
const EMPTY_INNER_CLASS = mergeClass('flex w-full items-center justify-center rounded-md border border-border-subtle bg-surface-sunken px-3 py-6', kitTypographyRecipe('textMuted'));
|
|
68
|
+
|
|
69
|
+
/** 语气 -> 浅底 + 同色相文字(level 0);颜色之外必有字形 / 文本,不靠颜色单独表达 */
|
|
70
|
+
const TONE_SOFT: Readonly<Record<MatrixTone, string>> = Object.freeze({
|
|
71
|
+
// 半透明凹底:暗色下 sunken 比卡面深得多,整格实底会成一排黑洞;半透明让「无负荷 / 无事」的格退到背景里
|
|
72
|
+
neutral: 'bg-surface-sunken/60 text-fg-muted',
|
|
73
|
+
primary: 'bg-primary-soft text-primary-on-soft',
|
|
74
|
+
success: 'bg-success-soft text-success-on-soft',
|
|
75
|
+
warning: 'bg-warning-soft text-warning-on-soft',
|
|
76
|
+
danger: 'bg-danger-soft text-danger-on-soft',
|
|
77
|
+
info: 'bg-info-soft text-info-on-soft',
|
|
78
|
+
});
|
|
79
|
+
/** 单色相强度:level > 0 时底色 = 色相 / 不透明度(档表读 design),文字回到正文色;neutral 语气的强度画成 primary 色相 */
|
|
80
|
+
const HUES: readonly MatrixTone[] = Object.freeze(['primary', 'success', 'warning', 'danger', 'info']);
|
|
81
|
+
const levelClass = (tone: MatrixTone, level: number): string => {
|
|
82
|
+
const pct = MATRIX_LEVEL_PCT[level];
|
|
83
|
+
if (pct === undefined || pct <= 0) return '';
|
|
84
|
+
return `bg-${tone === 'neutral' ? 'primary' : tone}/${pct} text-fg`;
|
|
85
|
+
};
|
|
86
|
+
const LEVEL_CLASSES: readonly string[] = HUES.flatMap((h) => MATRIX_LEVEL_PCT.map((_, lv) => levelClass(h, lv)).filter((c) => c !== ''));
|
|
87
|
+
const MISSING_CLASS = 'bg-transparent text-fg-subtle';
|
|
88
|
+
|
|
89
|
+
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
90
|
+
export const KIT_MATRIX_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
91
|
+
ROOT_CLASS, Object.values(SCROLL_CLASS), SCROLLER_CLASS, TABLE_CLASS, HEAD_CELL_CLASS, GROUP_HEAD_CLASS, NOTE_CLASS, ROW_HEAD_CLASS,
|
|
92
|
+
ROW_HEAD_BTN_CLASS, ROW_GROUP_CLASS, SUMMARY_CLASS, CELL_TD_CLASS, CELL_BTN_CLASS, GLYPH_CLASS,
|
|
93
|
+
STICKY_HEAD, STICKY_FIRST, STICKY_CORNER, STICKY_LAST, STICKY_HEAD_LAST, FIRST_COL_MIN, LEGEND_CLASS, LEGEND_ITEM_CLASS, LEGEND_SWATCH_CLASS, EMPTY_INNER_CLASS,
|
|
94
|
+
Object.values(TONE_SOFT), LEVEL_CLASSES, MISSING_CLASS, KIT_TAG_UNKNOWN_OUTLINE,
|
|
95
|
+
'hidden', 'sr-only', KIT_STATE_PANEL_CLASS_CANDIDATES,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
/** 单元格视图 -> 类串(纯函数):缺失 = 无底色次要字;未知 = 虚线描边;就绪 = 语气浅底,有强度档时按档底色 */
|
|
99
|
+
export function matrixCellClass(view: MatrixCellView): string {
|
|
100
|
+
if (view.state === 'missing') return MISSING_CLASS;
|
|
101
|
+
if (view.state === 'unknown') return KIT_TAG_UNKNOWN_OUTLINE;
|
|
102
|
+
return view.level > 0 ? levelClass(view.tone, view.level) : TONE_SOFT[view.tone];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 单元格读屏名:「行 列:文本 状态 提示」(状态词只给缺失 / 未知,就绪不重复) */
|
|
106
|
+
export function matrixCellLabel(row: string, col: string, view: MatrixCellView, hint: string, at?: Element | string | null): string {
|
|
107
|
+
const base = view.state === 'missing' ? kitText('soma.kit.matrix_missing', undefined, at)
|
|
108
|
+
: view.state === 'unknown' ? kitText('soma.kit.matrix_unknown', undefined, at)
|
|
109
|
+
: (view.glyph === view.text ? [view.text] : [view.glyph, view.text]).filter((s) => s !== '').join(' ');
|
|
110
|
+
const text = kitText('soma.kit.matrix_cell', { row, col, text: base }, at);
|
|
111
|
+
return hint !== '' ? `${text},${hint}` : text;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface CellRef { ri: number; ci: number }
|
|
115
|
+
const cellKey = (ri: number, ci: number): string => `${ri}:${ci}`;
|
|
116
|
+
const parseKey = (key: string): CellRef | null => {
|
|
117
|
+
const m = /^(\d+):(\d+)$/.exec(key);
|
|
118
|
+
return m ? { ri: Number(m[1]), ci: Number(m[2]) } : null;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export function createMatrix(): SomaComponentDefinition {
|
|
122
|
+
return {
|
|
123
|
+
contract: {
|
|
124
|
+
name: 'Matrix',
|
|
125
|
+
layer: 'data',
|
|
126
|
+
props: {
|
|
127
|
+
data: { type: 'object', default: {}, desc: '{ cols: [{ key, label, note?, group? }], rows: [{ key, label, note?, group?, summary?, cells: [{ col, text?, tone?(neutral|primary|success|warning|danger|info), level?(0-4), mark?(alert|diamond|check|hollow|unknown|leave), state?(ready|missing|unknown), hint? }] }], legend?: [{ tone, label }] };行里没给的列 = 缺失格' },
|
|
128
|
+
sticky_head: { type: 'boolean', default: true, desc: '表头吸顶(在滚动外壳内)' },
|
|
129
|
+
sticky_first_col: { type: 'boolean', default: true, desc: '行头吸左:横向滚动时行头固定' },
|
|
130
|
+
scroll_height: { type: 'enum', values: ['none', 'sm', 'md', 'lg'], default: 'md', desc: '滚动外壳的纵向最大高度档位(表头吸顶要有界滚动容器);none = 不设上限' },
|
|
131
|
+
empty: { type: 'string', default: '', desc: '无数据时的空态文案;缺省取内置文案(按页面语言)' },
|
|
132
|
+
title: { type: 'string', default: '', desc: '表格标题:进可访问名(caption)' },
|
|
133
|
+
aria_label: { type: 'string', default: '', desc: '直接指定表格的可访问名' },
|
|
134
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
135
|
+
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
136
|
+
},
|
|
137
|
+
emits: {
|
|
138
|
+
...KIT_READ_STATE_EMIT_DEFS,
|
|
139
|
+
cell_pick: { payload: { row: { type: 'string' }, col: { type: 'string' }, cell: { type: 'object' } }, desc: '点击 / Enter 某个单元格;row / col 是行列键,cell 是源数据里的单元格原对象(行里没给的缺失格为 null)' },
|
|
140
|
+
row_pick: { payload: { row: { type: 'string' } }, desc: '点击行头;row 是行键' },
|
|
141
|
+
},
|
|
142
|
+
keyboard: { layout: 'grid', columns: 'runtime', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
143
|
+
},
|
|
144
|
+
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
145
|
+
controllerFactory: createKitController((api) => {
|
|
146
|
+
const P = (): Record<string, unknown> => api.props();
|
|
147
|
+
let root: HTMLElement | null = null;
|
|
148
|
+
let model: MatrixModel = { cols: [], rows: [], legend: [] };
|
|
149
|
+
let cursor: string | null = null;
|
|
150
|
+
let pendingFocus = false;
|
|
151
|
+
|
|
152
|
+
const el = <K extends keyof HTMLElementTagNameMap>(tag: K, className: string, text?: string): HTMLElementTagNameMap[K] => {
|
|
153
|
+
const node = document.createElement(tag);
|
|
154
|
+
if (className !== '') node.className = className;
|
|
155
|
+
if (text !== undefined) node.textContent = text;
|
|
156
|
+
return node;
|
|
157
|
+
};
|
|
158
|
+
const rawRows = (): Array<Record<string, unknown>> => {
|
|
159
|
+
const d = P().data;
|
|
160
|
+
const rows = d !== null && typeof d === 'object' ? (d as Record<string, unknown>).rows : undefined;
|
|
161
|
+
return Array.isArray(rows) ? rows.filter((r): r is Record<string, unknown> => r !== null && typeof r === 'object') : [];
|
|
162
|
+
};
|
|
163
|
+
const sourceCell = (rowKey: string, colKey: string): unknown => {
|
|
164
|
+
const row = rawRows().find((r) => str(r.key) === rowKey);
|
|
165
|
+
const cells = Array.isArray(row?.cells) ? row!.cells as unknown[] : [];
|
|
166
|
+
return cells.find((c) => c !== null && typeof c === 'object' && str((c as Record<string, unknown>).col) === colKey) ?? null;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const items = (): CollectionItem[] => model.rows.flatMap((r, ri) => model.cols.map((c, ci) => ({ key: cellKey(ri, ci), text: `${r.label} ${c.label}` })));
|
|
170
|
+
const cellEl = (key: string): HTMLElement | null =>
|
|
171
|
+
root?.querySelector<HTMLElement>(`[data-kit-cell="${key}"]`) ?? null;
|
|
172
|
+
const pageStep = SOMA_SIZE_UNITS.collection.keyboard.pageStep;
|
|
173
|
+
const wiring = createKeyboardWiring({
|
|
174
|
+
contract: { layout: 'grid', columns: 'runtime', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
175
|
+
host: () => root,
|
|
176
|
+
items,
|
|
177
|
+
columns: () => Math.max(1, model.cols.length),
|
|
178
|
+
typeaheadDebounceMs: 0,
|
|
179
|
+
paging: { listItems: pageStep.listItems, gridRows: pageStep.gridRows },
|
|
180
|
+
getCursor: () => cursor,
|
|
181
|
+
setCursor: (key) => {
|
|
182
|
+
cursor = key;
|
|
183
|
+
for (const b of Array.from(root?.querySelectorAll<HTMLElement>('[data-kit-cell]') ?? [])) b.tabIndex = b.getAttribute('data-kit-cell') === key ? 0 : -1;
|
|
184
|
+
cellEl(key)?.focus();
|
|
185
|
+
},
|
|
186
|
+
onActivate: (key) => pick(key),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const pick = (key: string): void => {
|
|
190
|
+
const ref = parseKey(key);
|
|
191
|
+
const row = ref ? model.rows[ref.ri] : undefined;
|
|
192
|
+
const col = ref ? model.cols[ref.ci] : undefined;
|
|
193
|
+
if (!row || !col) return;
|
|
194
|
+
api.emit('cell_pick', { row: row.key, col: col.key, cell: sourceCell(row.key, col.key) });
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const showPanel = (kind: 'empty' | 'error' | 'loading', text: string, o: { retry?: (() => void) | null; retryLabel?: string } = {}): void => {
|
|
198
|
+
if (!root) return;
|
|
199
|
+
root.textContent = '';
|
|
200
|
+
const box = el('div', EMPTY_INNER_CLASS);
|
|
201
|
+
paintKitStatePanel(box, kind, { text, ...(o.retry ? { retry: o.retry, retryLabel: o.retryLabel ?? '' } : {}) });
|
|
202
|
+
root.appendChild(box);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const buildCell = (row: MatrixRow, ri: number, ci: number, colLabel: string, first: boolean): HTMLElement => {
|
|
206
|
+
const col = model.cols[ci]!;
|
|
207
|
+
const view = matrixCellView(row.cells.get(col.key), MATRIX_SPEC);
|
|
208
|
+
const td = el('td', CELL_TD_CLASS);
|
|
209
|
+
const key = cellKey(ri, ci);
|
|
210
|
+
const btn = el('button', `${CELL_BTN_CLASS} ${matrixCellClass(view)}`);
|
|
211
|
+
btn.type = 'button';
|
|
212
|
+
btn.setAttribute('data-kit-cell', key);
|
|
213
|
+
btn.setAttribute('data-kit-state', view.state);
|
|
214
|
+
btn.tabIndex = (cursor === null ? first : cursor === key) ? 0 : -1;
|
|
215
|
+
const hint = row.cells.get(col.key)?.hint ?? '';
|
|
216
|
+
btn.setAttribute('aria-label', matrixCellLabel(row.label, colLabel, view, hint, root));
|
|
217
|
+
if (hint !== '') btn.title = hint;
|
|
218
|
+
// 字形与文本相同(如休假字形「休」+ 文本「休」)只画一份
|
|
219
|
+
if (view.glyph !== '' && view.glyph !== view.text) {
|
|
220
|
+
const g = el('span', GLYPH_CLASS, view.glyph);
|
|
221
|
+
g.setAttribute('aria-hidden', 'true');
|
|
222
|
+
btn.appendChild(g);
|
|
223
|
+
}
|
|
224
|
+
if (view.text !== '') btn.appendChild(el('span', '', view.text));
|
|
225
|
+
td.appendChild(btn);
|
|
226
|
+
return td;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const paint = (): void => {
|
|
230
|
+
if (!root) return;
|
|
231
|
+
const p = P();
|
|
232
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
233
|
+
const focused = document.activeElement instanceof HTMLElement && root.contains(document.activeElement)
|
|
234
|
+
? document.activeElement.getAttribute('data-kit-cell') : null;
|
|
235
|
+
model = parseMatrixModel(p.data, MATRIX_SPEC);
|
|
236
|
+
const errorText = str(p.error_text);
|
|
237
|
+
const loading = bool(p.loading);
|
|
238
|
+
if (model.rows.length === 0 || model.cols.length === 0) {
|
|
239
|
+
const retryLabel = str(p.retry_text);
|
|
240
|
+
if (errorText !== '') { showPanel('error', errorText, { retry: retryLabel !== '' ? (): void => { api.emit('retry', {}); } : null, retryLabel }); return; }
|
|
241
|
+
if (loading) { showPanel('loading', str(p.loading_text, kitText('soma.kit.loading', undefined, root))); return; }
|
|
242
|
+
showPanel('empty', str(p.empty, kitText('soma.kit.matrix_empty', undefined, root)));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// 游标:保持上次的格(还在表里),否则落在第一格
|
|
246
|
+
const keys = new Set(items().map((i) => i.key));
|
|
247
|
+
if (cursor === null || !keys.has(cursor)) cursor = cellKey(0, 0);
|
|
248
|
+
root.textContent = '';
|
|
249
|
+
const stickyHead = p.sticky_head !== false && p.sticky_head !== 'false';
|
|
250
|
+
const stickyFirst = p.sticky_first_col !== false && p.sticky_first_col !== 'false';
|
|
251
|
+
const heightKey = str(p.scroll_height, 'md');
|
|
252
|
+
const scroller = el('div', joinClass(SCROLLER_CLASS, SCROLL_CLASS[heightKey] ?? SCROLL_CLASS.md));
|
|
253
|
+
scroller.setAttribute('role', 'region');
|
|
254
|
+
const label = str(p.aria_label) !== '' ? str(p.aria_label) : str(p.title);
|
|
255
|
+
if (label !== '') scroller.setAttribute('aria-label', label);
|
|
256
|
+
// 滚动外壳可聚焦(键盘用户需要能滚动),单元格 roving 之外多一个停靠点是 WCAG 对可滚动区域的要求
|
|
257
|
+
scroller.tabIndex = 0;
|
|
258
|
+
const table = el('table', TABLE_CLASS);
|
|
259
|
+
if (label !== '') table.appendChild(el('caption', 'sr-only', label));
|
|
260
|
+
const thead = el('thead', '');
|
|
261
|
+
const hasColGroups = model.cols.some((c) => c.group !== '');
|
|
262
|
+
const hasSummary = model.rows.some((r) => r.summary !== '');
|
|
263
|
+
const headCls = (extra = ''): string => joinClass(stickyHead ? STICKY_HEAD : '', extra);
|
|
264
|
+
// 汇总列表头:与行头吸左对称吸右(sticky_first_col 同管两端),表头吸顶时同吸顶
|
|
265
|
+
const summaryHeadCls = (): string => joinClass(stickyFirst ? (stickyHead ? STICKY_HEAD_LAST : STICKY_LAST) : headCls(), HEAD_CELL_CLASS);
|
|
266
|
+
if (hasColGroups) {
|
|
267
|
+
const tr = el('tr', '');
|
|
268
|
+
const corner = el('th', joinClass(stickyHead && stickyFirst ? STICKY_CORNER : headCls(), stickyFirst ? FIRST_COL_MIN : ''));
|
|
269
|
+
corner.rowSpan = 2;
|
|
270
|
+
corner.setAttribute('scope', 'col');
|
|
271
|
+
tr.appendChild(corner);
|
|
272
|
+
for (let i = 0; i < model.cols.length;) {
|
|
273
|
+
const g = model.cols[i]!.group;
|
|
274
|
+
let j = i;
|
|
275
|
+
while (j < model.cols.length && model.cols[j]!.group === g) j += 1;
|
|
276
|
+
const th = el('th', joinClass(headCls(), GROUP_HEAD_CLASS), g);
|
|
277
|
+
th.colSpan = j - i;
|
|
278
|
+
th.setAttribute('scope', 'colgroup');
|
|
279
|
+
tr.appendChild(th);
|
|
280
|
+
i = j;
|
|
281
|
+
}
|
|
282
|
+
if (hasSummary) { const s = el('th', summaryHeadCls(), kitText('soma.kit.matrix_summary_col', undefined, root)); s.rowSpan = 2; s.setAttribute('scope', 'col'); tr.appendChild(s); }
|
|
283
|
+
thead.appendChild(tr);
|
|
284
|
+
}
|
|
285
|
+
const headRow = el('tr', '');
|
|
286
|
+
if (!hasColGroups) {
|
|
287
|
+
const corner = el('th', joinClass(stickyHead && stickyFirst ? STICKY_CORNER : headCls(), stickyFirst ? FIRST_COL_MIN : ''));
|
|
288
|
+
corner.setAttribute('scope', 'col');
|
|
289
|
+
headRow.appendChild(corner);
|
|
290
|
+
}
|
|
291
|
+
for (const c of model.cols) {
|
|
292
|
+
const th = el('th', headCls(HEAD_CELL_CLASS), c.label);
|
|
293
|
+
th.setAttribute('scope', 'col');
|
|
294
|
+
if (c.note !== '') th.appendChild(el('span', NOTE_CLASS, c.note));
|
|
295
|
+
headRow.appendChild(th);
|
|
296
|
+
}
|
|
297
|
+
if (hasSummary && !hasColGroups) { const s = el('th', summaryHeadCls(), kitText('soma.kit.matrix_summary_col', undefined, root)); s.setAttribute('scope', 'col'); headRow.appendChild(s); }
|
|
298
|
+
thead.appendChild(headRow);
|
|
299
|
+
table.appendChild(thead);
|
|
300
|
+
|
|
301
|
+
const tbody = el('tbody', '');
|
|
302
|
+
const span = model.cols.length + 1 + (hasSummary ? 1 : 0);
|
|
303
|
+
let lastGroup = '';
|
|
304
|
+
model.rows.forEach((row, ri) => {
|
|
305
|
+
if (row.group !== '' && row.group !== lastGroup) {
|
|
306
|
+
const gr = el('tr', '');
|
|
307
|
+
const th = el('th', ROW_GROUP_CLASS, row.group);
|
|
308
|
+
th.colSpan = span;
|
|
309
|
+
th.setAttribute('scope', 'rowgroup');
|
|
310
|
+
gr.appendChild(th);
|
|
311
|
+
tbody.appendChild(gr);
|
|
312
|
+
}
|
|
313
|
+
if (row.group !== '') lastGroup = row.group;
|
|
314
|
+
const tr = el('tr', '');
|
|
315
|
+
const head = el('th', joinClass(joinClass(ROW_HEAD_CLASS, stickyFirst ? STICKY_FIRST : ''), stickyFirst ? FIRST_COL_MIN : ''));
|
|
316
|
+
head.setAttribute('scope', 'row');
|
|
317
|
+
const btn = el('button', ROW_HEAD_BTN_CLASS, row.label);
|
|
318
|
+
btn.type = 'button';
|
|
319
|
+
btn.tabIndex = -1;
|
|
320
|
+
btn.setAttribute('data-kit-row', row.key);
|
|
321
|
+
head.appendChild(btn);
|
|
322
|
+
if (row.note !== '') head.appendChild(el('span', NOTE_CLASS, row.note));
|
|
323
|
+
tr.appendChild(head);
|
|
324
|
+
model.cols.forEach((c, ci) => tr.appendChild(buildCell(row, ri, ci, c.label, ri === 0 && ci === 0)));
|
|
325
|
+
if (hasSummary) tr.appendChild(el('td', joinClass(SUMMARY_CLASS, stickyFirst ? STICKY_LAST : ''), row.summary));
|
|
326
|
+
tbody.appendChild(tr);
|
|
327
|
+
});
|
|
328
|
+
table.appendChild(tbody);
|
|
329
|
+
scroller.appendChild(table);
|
|
330
|
+
root.appendChild(scroller);
|
|
331
|
+
|
|
332
|
+
if (model.legend.length > 0) {
|
|
333
|
+
const ul = el('ul', LEGEND_CLASS);
|
|
334
|
+
ul.setAttribute('aria-label', kitText('soma.kit.matrix_legend', undefined, root));
|
|
335
|
+
for (const l of model.legend) {
|
|
336
|
+
const li = el('li', LEGEND_ITEM_CLASS);
|
|
337
|
+
const sw = el('span', `${LEGEND_SWATCH_CLASS} ${TONE_SOFT[l.tone]}`);
|
|
338
|
+
sw.setAttribute('aria-hidden', 'true');
|
|
339
|
+
li.appendChild(sw);
|
|
340
|
+
li.appendChild(el('span', '', l.label));
|
|
341
|
+
ul.appendChild(li);
|
|
342
|
+
}
|
|
343
|
+
root.appendChild(ul);
|
|
344
|
+
}
|
|
345
|
+
if (errorText !== '') {
|
|
346
|
+
const retryLabel = str(p.retry_text);
|
|
347
|
+
const bar = el('div', EMPTY_INNER_CLASS);
|
|
348
|
+
paintKitStatePanel(bar, 'error', { text: errorText, ...(retryLabel !== '' ? { retry: (): void => { api.emit('retry', {}); }, retryLabel } : {}) });
|
|
349
|
+
root.appendChild(bar);
|
|
350
|
+
}
|
|
351
|
+
// 整块重建会丢焦点:把键盘焦点还给原来的格
|
|
352
|
+
if (focused !== null || pendingFocus) { pendingFocus = false; cellEl(focused ?? cursor ?? '')?.focus(); }
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
attach(rootEl) {
|
|
357
|
+
root = rootEl;
|
|
358
|
+
const r = rootEl;
|
|
359
|
+
const onClick = (event: Event): void => {
|
|
360
|
+
const target = event.target as HTMLElement | null;
|
|
361
|
+
const cell = target?.closest<HTMLElement>('[data-kit-cell]');
|
|
362
|
+
if (cell && r.contains(cell)) {
|
|
363
|
+
cursor = cell.getAttribute('data-kit-cell');
|
|
364
|
+
for (const b of Array.from(r.querySelectorAll<HTMLElement>('[data-kit-cell]'))) b.tabIndex = b === cell ? 0 : -1;
|
|
365
|
+
if (cursor !== null) pick(cursor);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const rowBtn = target?.closest<HTMLElement>('[data-kit-row]');
|
|
369
|
+
if (rowBtn && r.contains(rowBtn)) api.emit('row_pick', { row: rowBtn.getAttribute('data-kit-row') ?? '' });
|
|
370
|
+
};
|
|
371
|
+
const onKey = (event: KeyboardEvent): void => {
|
|
372
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
373
|
+
if (!(event.target as HTMLElement | null)?.closest('[data-kit-cell]')) return;
|
|
374
|
+
if (wiring.onKeydown(event)) event.preventDefault();
|
|
375
|
+
};
|
|
376
|
+
r.addEventListener('click', onClick);
|
|
377
|
+
r.addEventListener('keydown', onKey);
|
|
378
|
+
return () => {
|
|
379
|
+
r.removeEventListener('click', onClick);
|
|
380
|
+
r.removeEventListener('keydown', onKey);
|
|
381
|
+
root = null;
|
|
382
|
+
};
|
|
383
|
+
},
|
|
384
|
+
render(rootEl) {
|
|
385
|
+
root = rootEl;
|
|
386
|
+
paint();
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}),
|
|
390
|
+
};
|
|
391
|
+
}
|
package/src/data/menu.ts
CHANGED
|
@@ -28,15 +28,23 @@ import { mountKitMegaMenu } from './mega-menu';
|
|
|
28
28
|
const ROOT_CLASS = 'flex flex-col text-sm text-fg';
|
|
29
29
|
const LIST_CLASS = 'flex flex-col gap-1';
|
|
30
30
|
const LIST_RAIL_CLASS = 'flex flex-col items-center gap-1';
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
const
|
|
34
|
-
const
|
|
31
|
+
// 选中 / 悬停底框在所有层级都铺满导航行宽(子容器不缩进);层级只靠行内左内边距表达:
|
|
32
|
+
// 子项文字落在父文字起点右侧一档(评审 S2:子项不得比父级更靠左)。数值读真源 kit-limits#navigation.menu.indent。
|
|
33
|
+
const MENU_INDENT = KIT_STATIC_COMPONENT_LIMITS.navigation.menu.indent;
|
|
34
|
+
const GROUP_CLASS = 'flex flex-col gap-1';
|
|
35
|
+
|
|
36
|
+
/** 二级行左内边距(间距单位):行内边距 + (父有图标 ? 图标列 + 间距 : 0)+ 一档缩进步长 */
|
|
37
|
+
export function menuChildInsetUnits(parentHasIcon: boolean): number {
|
|
38
|
+
return MENU_INDENT.rowInsetUnits + (parentHasIcon ? MENU_INDENT.iconTextUnits : 0) + MENU_INDENT.stepUnits;
|
|
39
|
+
}
|
|
40
|
+
const PAD_TOP = `px-${MENU_INDENT.rowInsetUnits}`;
|
|
41
|
+
const padChild = (parentHasIcon: boolean): string => `ps-${menuChildInsetUnits(parentHasIcon)} pe-${MENU_INDENT.rowInsetUnits}`;
|
|
35
42
|
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';
|
|
36
43
|
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';
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
44
|
+
const rowClass = (pad: string): string => `flex h-9 cursor-pointer items-center gap-2 rounded-md ${pad} text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg`;
|
|
45
|
+
const rowActiveClass = (pad: string): string => `flex h-9 cursor-pointer items-center gap-2 rounded-md bg-primary-soft ${pad} text-sm font-medium text-primary-on-soft`;
|
|
46
|
+
const rowDisabledClass = (pad: string): string => `flex h-9 cursor-not-allowed items-center gap-2 rounded-md ${pad} text-sm text-fg-subtle opacity-60`;
|
|
47
|
+
const PADS: readonly string[] = [PAD_TOP, padChild(true), padChild(false)];
|
|
40
48
|
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';
|
|
41
49
|
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';
|
|
42
50
|
const HEADING_CLASS = 'px-3 pb-1 pt-3 text-xs font-semibold text-fg-subtle';
|
|
@@ -67,7 +75,8 @@ const SEP_CLASS = 'my-1 h-px w-full bg-border-subtle';
|
|
|
67
75
|
|
|
68
76
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
69
77
|
export const KIT_MENU_CLASS_CANDIDATES: readonly string[] = classSet(
|
|
70
|
-
ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS,
|
|
78
|
+
ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS, ITEM_CLASS, ITEM_RAIL_CLASS,
|
|
79
|
+
PADS.flatMap((pad) => [rowClass(pad), rowActiveClass(pad), rowDisabledClass(pad)]),
|
|
71
80
|
ROW_RAIL_CLASS, ROW_RAIL_ACTIVE_CLASS, HEADING_CLASS, ICON_CLASS, LABEL_CLASS, CARET_CLASS, BADGE_CLASS, BADGE_PRIMARY_CLASS,
|
|
72
81
|
BADGE_DANGER_CLASS, BADGE_ACTIVE_CLASS, SEP_CLASS, ICON_SVG_CLASS,
|
|
73
82
|
);
|
|
@@ -360,7 +369,8 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
360
369
|
'aria-expanded': branch && !rail ? (isOpen ? 'true' : 'false') : undefined,
|
|
361
370
|
'aria-disabled': n.disabled ? 'true' : undefined,
|
|
362
371
|
'aria-label': rail ? n.label : undefined,
|
|
363
|
-
|
|
372
|
+
// 收起态的悬停提示走 kit 气泡(hint-tips 委托,data-kit-tip),不用原生 title(原生提示延迟长、不随主题、截图 / 触屏都没有)
|
|
373
|
+
'data-kit-tip': rail ? n.label : undefined,
|
|
364
374
|
'data-kit-key': n.key,
|
|
365
375
|
tabindex: n.key === tabbable ? '0' : '-1',
|
|
366
376
|
});
|
|
@@ -372,7 +382,9 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
372
382
|
const badgeClass = active ? BADGE_ACTIVE_CLASS
|
|
373
383
|
: n.badgeTone === 'danger' ? BADGE_DANGER_CLASS
|
|
374
384
|
: n.badgeTone === 'primary' ? BADGE_PRIMARY_CLASS : BADGE_CLASS;
|
|
375
|
-
|
|
385
|
+
const parentNode = n.level > 1 && n.parent !== null ? byKey.get(n.parent) : undefined;
|
|
386
|
+
const pad = n.level > 1 ? padChild(parentNode !== undefined && parentNode.icon !== '') : PAD_TOP;
|
|
387
|
+
row = h('div', n.disabled ? rowDisabledClass(pad) : active ? rowActiveClass(pad) : rowClass(pad), {},
|
|
376
388
|
menuIconNode(n.icon),
|
|
377
389
|
h('span', LABEL_CLASS, { [KIT_TIPS_SCOPE_ATTR]: '' }, n.label),
|
|
378
390
|
n.badge !== '' ? h('span', badgeClass, { 'data-kit-badge': '' }, n.badge) : null,
|
|
@@ -380,7 +392,7 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
380
392
|
}
|
|
381
393
|
li.append(row);
|
|
382
394
|
if (isOpen) {
|
|
383
|
-
const group = h('ul',
|
|
395
|
+
const group = h('ul', GROUP_CLASS, { role: 'group' });
|
|
384
396
|
for (const child of n.children) for (const node of buildItem(child, tabbable)) group.append(node);
|
|
385
397
|
li.append(group);
|
|
386
398
|
}
|
package/src/data/mockup.ts
CHANGED
|
@@ -121,7 +121,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
121
121
|
root.setAttribute('data-kit-variant', variant);
|
|
122
122
|
if (variant === 'code') {
|
|
123
123
|
const lines = mockupLinesOf(src.lines, num(p.start) ?? 1);
|
|
124
|
-
if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))
|
|
124
|
+
if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)))); return; }
|
|
125
125
|
const frame = mk('div', CODE_CLASS);
|
|
126
126
|
const bar = mk('div', BAR_CLASS);
|
|
127
127
|
const dots = mk('div', DOTS_CLASS);
|
|
@@ -148,7 +148,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
148
148
|
const frame = mk('div', PHONE_CLASS);
|
|
149
149
|
frame.appendChild(mk('div', NOTCH_CLASS));
|
|
150
150
|
const screen = mk('div', SCREEN_CLASS);
|
|
151
|
-
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))));
|
|
152
152
|
frame.appendChild(screen);
|
|
153
153
|
root.appendChild(frame);
|
|
154
154
|
return;
|
|
@@ -171,7 +171,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
171
171
|
}
|
|
172
172
|
frame.appendChild(bar);
|
|
173
173
|
const area = mk('div', BODY_CLASS);
|
|
174
|
-
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))));
|
|
175
175
|
frame.appendChild(area);
|
|
176
176
|
root.appendChild(frame);
|
|
177
177
|
},
|