soma-kit 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +158 -4
- package/spec/generated/kit-page.schema.json +139 -5
- package/spec/kit-grammar.json +438 -87
- package/spec/kit-grammar.schema.json +11 -3
- package/src/app/app-config.ts +83 -5
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +17 -5
- package/src/app/kit-view-context.ts +163 -14
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +3 -1
- package/src/app/server.ts +40 -3
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +57 -12
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/index.ts +27 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +23 -12
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +9 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +24 -22
- package/src/base/shared.ts +169 -23
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +63 -33
- package/src/base/text.ts +42 -13
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -10
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +2 -2
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/import-wizard/shell.ts +2 -1
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +102 -10
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +4 -1
- package/src/biz/multi-board/shell.ts +8 -5
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +18 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +139 -10
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +22 -160
- package/src/biz/standard-crud/shell.ts +16 -44
- package/src/biz/step-form/shell.ts +5 -5
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/view-writes.ts +69 -60
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +51 -7
- package/src/compile/component-candidates.ts +12 -1
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +36 -8
- package/src/compile/types.ts +13 -1
- package/src/compile/view-check.ts +149 -16
- package/src/data/amount-breakdown.ts +6 -1
- package/src/data/approval-flow.ts +1 -1
- package/src/data/assignment-picker.ts +53 -27
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +2 -2
- package/src/data/carousel.ts +8 -6
- package/src/data/chart.ts +141 -10
- package/src/data/checklist.ts +18 -5
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +2 -2
- package/src/data/confirm-dialog.ts +71 -18
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +4 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +25 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/gantt.ts +5 -2
- package/src/data/hero.ts +2 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +6 -1
- package/src/data/item-list.ts +18 -10
- package/src/data/kanban.ts +39 -10
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +45 -13
- package/src/data/mockup.ts +8 -4
- package/src/data/modal-dialog.ts +29 -9
- package/src/data/navbar.ts +5 -5
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +354 -48
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +17 -7
- package/src/data/permission-matrix.ts +33 -11
- package/src/data/permission-tree.ts +47 -22
- package/src/data/pricing-table.ts +21 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +23 -2
- package/src/data/record-picker.ts +13 -7
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +79 -26
- package/src/data/rule-builder.ts +8 -8
- package/src/data/shape-util.ts +23 -9
- package/src/data/stat-group.ts +170 -29
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +2 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +3 -3
- package/src/data/system-switcher.ts +1 -1
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +1 -1
- package/src/data/transfer.ts +36 -16
- package/src/data/tree-table.ts +62 -36
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +19 -10
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/page-bar.ts +14 -13
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +15 -10
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +2 -1
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +2 -2
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/view.ts +141 -33
- package/src/generated/kit-grammar-runtime.ts +239 -55
- package/src/i18n/kit-text.ts +63 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/arrange.ts +42 -8
- package/src/object-renderer/collection-parts.ts +241 -60
- package/src/object-renderer/collection-table.ts +109 -5
- package/src/object-renderer/collection.ts +174 -36
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +30 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-static.ts +370 -30
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/render-object.ts +54 -6
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +135 -27
- package/src/object-renderer/table-tools.ts +12 -11
- package/src/object-renderer/types.ts +78 -7
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +46 -1
- package/src/recipes/control.ts +70 -12
- package/src/recipes/index.ts +49 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +75 -17
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +34 -5
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +40 -3
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +13 -1
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +372 -12
- package/src/theme/kit-theme.tpl +372 -12
- package/src/theme/nine-dim-structure.ts +177 -7
- package/src/theme/surface-layers.ts +4 -0
- package/src/theme/theme-tokens.ts +53 -13
- package/src/theme/theme-types.ts +32 -0
- package/src/biz/shared/remove-key.ts +0 -6
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// NoticeList:说明 / 披露条列表(layer: data,写死形状,accept: list)。
|
|
2
|
+
//
|
|
3
|
+
// 用途:在面板顶部或页面角落,把「这些数据有什么需要你知道」一次列清:口径说明、延迟提示、降级提示、权限提示……
|
|
4
|
+
// 数据:条目数组 [{ id?, code?, tone?, title?, text, time?, href?, action_label?, icon? }](也容忍 { items: [...] } 形状)。
|
|
5
|
+
// 键名可经 `map` 对照。条目顺序、去重、哪几条出现都由数据决定(业务对象 / 接口),组件不排序、不去重、不按 code 或文案分支。
|
|
6
|
+
//
|
|
7
|
+
// 画法:每条 = 左侧语气竖线 + 图标 + 文字(标题 / 正文 / 时间 / 动作链接)。语气双编码:图标 + 读屏文字(sr-only 的「注意」「重要」…),
|
|
8
|
+
// 不靠颜色、不用符号字符。颜色只用令牌(彩色文字只配 on-soft);闲置态的 neutral / info 不用警示色。
|
|
9
|
+
//
|
|
10
|
+
// 折叠:fold_after = N(≥ 1)时只画前 N 条,其余由一个原生按钮展开 / 收起(aria-expanded + aria-controls,键盘 Enter / Space);
|
|
11
|
+
// 折叠态属于组件自己的视图态,重绘不丢,点按钮抛 toggle { open }。不可关闭,只能折叠。
|
|
12
|
+
//
|
|
13
|
+
// 状态:错误 > 加载 > 内容,由共用的三态面板(base/state-panel)画;读状态由编译器自动绑定(loading / error_text / retry)。
|
|
14
|
+
// 数据说了算的三态(state_kind:not_ready / upstream_broken / denied)由页面 / 展示对象给,面板只画。
|
|
15
|
+
// 空:empty_text 非空 → 画紧凑空态;空串(缺省)→ 整块不渲染(根节点 hidden、无子节点、无占位)。
|
|
16
|
+
// 本组件只管自己的根:不越界去隐藏外层面板 / 标题(外层怎么随之隐藏由所在业务组件模板处理)。
|
|
17
|
+
|
|
18
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
19
|
+
import { kitText } from '../i18n/kit-text';
|
|
20
|
+
import { KIT_ICON_CLASS_CANDIDATES, KIT_ICON_NAMES, kitIcon, type KitIconName } from '../base/icons';
|
|
21
|
+
import { safeHref } from '../base/link';
|
|
22
|
+
import { KIT_STATUS_TONE_ICON, KIT_STATUS_TONE_TEXT_KEY, statusToneOrNull } from '../base/status-tone';
|
|
23
|
+
import {
|
|
24
|
+
applyKitReadState, KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS, KIT_STATE_PANEL_CLASS_CANDIDATES,
|
|
25
|
+
kitEmptyPanel, kitExtraStateKindOf, kitStatePanel,
|
|
26
|
+
} from '../base/state-panel';
|
|
27
|
+
import { CLASS_PROP, createKitController, joinClass, nextUid, num, str } from '../base/shared';
|
|
28
|
+
import {
|
|
29
|
+
KIT_NOTICE_ACTION, KIT_NOTICE_BODY, KIT_NOTICE_BOX, KIT_NOTICE_HEADLINE, KIT_NOTICE_ICON, KIT_NOTICE_ITEM, KIT_NOTICE_LIST,
|
|
30
|
+
KIT_NOTICE_RECIPE_CLASS_CANDIDATES, KIT_NOTICE_SR_ONLY, KIT_NOTICE_TIME, KIT_NOTICE_TITLE, KIT_NOTICE_TOGGLE,
|
|
31
|
+
type KitStatusTone,
|
|
32
|
+
} from '../recipes/status';
|
|
33
|
+
import { classTokens, keyMap, mk, recOf, textOf } from './shape-util';
|
|
34
|
+
|
|
35
|
+
export const KIT_NOTICE_LIST_DEFAULT_MAP = Object.freeze({
|
|
36
|
+
id: 'id', code: 'code', tone: 'tone', title: 'title', text: 'text', time: 'time', href: 'href', action_label: 'action_label', icon: 'icon',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const KIT_NOTICE_LIST_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
40
|
+
KIT_NOTICE_RECIPE_CLASS_CANDIDATES, KIT_STATE_PANEL_CLASS_CANDIDATES, KIT_ICON_CLASS_CANDIDATES,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export interface KitNotice {
|
|
44
|
+
id: string;
|
|
45
|
+
code: string;
|
|
46
|
+
tone: KitStatusTone;
|
|
47
|
+
title: string;
|
|
48
|
+
text: string;
|
|
49
|
+
time: string;
|
|
50
|
+
href: string;
|
|
51
|
+
actionLabel: string;
|
|
52
|
+
/** kit 图标名;空 = 按语气取默认图标 */
|
|
53
|
+
icon: KitIconName | '';
|
|
54
|
+
raw: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const TONE_ICON = KIT_STATUS_TONE_ICON;
|
|
58
|
+
const TONE_TEXT_KEY = KIT_STATUS_TONE_TEXT_KEY;
|
|
59
|
+
|
|
60
|
+
/** 语气:在闭集内取,否则按 info(说明条的缺省语气) */
|
|
61
|
+
export function noticeToneOf(raw: unknown): KitStatusTone {
|
|
62
|
+
return statusToneOrNull(raw) ?? 'info';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 条目(纯函数,便于单测):只要 text 与 title 都空的丢弃;缺 id 用下标;tone 不在闭集按 info */
|
|
66
|
+
export function noticeItemsOf(rawRows: unknown, mapRaw: unknown): KitNotice[] {
|
|
67
|
+
const m = keyMap(KIT_NOTICE_LIST_DEFAULT_MAP, mapRaw);
|
|
68
|
+
const rec = recOf(rawRows);
|
|
69
|
+
const list: unknown[] = Array.isArray(rawRows) ? rawRows : Array.isArray(rec.items) ? rec.items as unknown[] : [];
|
|
70
|
+
const out: KitNotice[] = [];
|
|
71
|
+
list.forEach((row, i) => {
|
|
72
|
+
if (row === null || typeof row !== 'object' || Array.isArray(row)) return;
|
|
73
|
+
const raw = row as Record<string, unknown>;
|
|
74
|
+
const text = textOf(raw[m.text]);
|
|
75
|
+
const title = textOf(raw[m.title]);
|
|
76
|
+
if (text.trim() === '' && title.trim() === '') return;
|
|
77
|
+
const idRaw = textOf(raw[m.id]);
|
|
78
|
+
const iconRaw = textOf(raw[m.icon]);
|
|
79
|
+
out.push({
|
|
80
|
+
id: idRaw === '' ? `i${i}` : idRaw,
|
|
81
|
+
code: textOf(raw[m.code]),
|
|
82
|
+
tone: noticeToneOf(raw[m.tone]),
|
|
83
|
+
title,
|
|
84
|
+
text,
|
|
85
|
+
time: textOf(raw[m.time]),
|
|
86
|
+
href: textOf(raw[m.href]),
|
|
87
|
+
actionLabel: textOf(raw[m.action_label]),
|
|
88
|
+
icon: (KIT_ICON_NAMES as readonly string[]).includes(iconRaw) ? iconRaw as KitIconName : '',
|
|
89
|
+
raw,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 折叠阈值:≥ 1 的整数才生效,其余(0 / 负 / 非数字)= 不折叠 */
|
|
96
|
+
export function noticeFoldOf(raw: unknown): number {
|
|
97
|
+
const n = num(raw);
|
|
98
|
+
return n !== null && n >= 1 ? Math.floor(n) : 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function createNoticeList(): SomaComponentDefinition {
|
|
102
|
+
interface NoticeState { open: boolean; refocus: boolean; listId: string }
|
|
103
|
+
const states = new WeakMap<HTMLElement, NoticeState>();
|
|
104
|
+
const stateOf = (root: HTMLElement): NoticeState => {
|
|
105
|
+
let s = states.get(root);
|
|
106
|
+
if (!s) { s = { open: false, refocus: false, listId: nextUid('kit-notice') }; states.set(root, s); }
|
|
107
|
+
return s;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
contract: {
|
|
112
|
+
name: 'NoticeList',
|
|
113
|
+
layer: 'data',
|
|
114
|
+
props: {
|
|
115
|
+
data: { type: 'array', default: [], desc: '说明条目 [{ id?, code?, tone?(neutral / info / success / warning / danger,缺省 info), title?, text, time?, href?, action_label?, icon?(kit 图标名,缺省按语气) }];顺序与去重由数据决定,组件不排序' },
|
|
116
|
+
map: { type: 'object', default: {}, desc: '键名对照:id / code / tone / title / text / time / href / action_label / icon' },
|
|
117
|
+
title: { type: 'string', default: '', desc: '列表小标题(如「数据说明」);空不显示。有标题时整块带 role=group 并以它命名' },
|
|
118
|
+
fold_after: { type: 'number', default: 0, desc: '超过该条数折叠(≥ 1 生效):只画前 N 条,其余由「展开其余 N 条」按钮展开;0 = 全部展开、无按钮' },
|
|
119
|
+
empty_text: { type: 'string', default: '', desc: '没有条目时的紧凑空态文案;空 = 整块不渲染(根 hidden、无子节点)' },
|
|
120
|
+
state_kind: { type: 'string', default: '', desc: '由数据给出的三态:not_ready(未就绪)/ upstream_broken(上游断供)/ denied(无权查看);非空且在闭集内时只画对应面板,不画条目' },
|
|
121
|
+
state_text: { type: 'string', default: '', desc: 'state_kind 面板的文案;空取内置默认文案(按页面语言)' },
|
|
122
|
+
aria_label: { type: 'string', default: '', desc: '无小标题时整块的无障碍名称(写入 role=group 的 aria-label)' },
|
|
123
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
124
|
+
class: CLASS_PROP,
|
|
125
|
+
},
|
|
126
|
+
emits: {
|
|
127
|
+
toggle: { payload: { open: { type: 'boolean' } }, desc: '展开 / 收起其余条目;open 为展开后的状态' },
|
|
128
|
+
action: { payload: { id: { type: 'string' }, href: { type: 'string' }, item: { type: 'object' } }, desc: '点条目的动作链接 / 按钮(有可用 href 时照常跳转,同时抛本事件)' },
|
|
129
|
+
...KIT_READ_STATE_EMIT_DEFS,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
templateHtml: '<div data-soma-id="root"></div>',
|
|
133
|
+
controllerFactory: createKitController((api) => ({
|
|
134
|
+
attach(root) {
|
|
135
|
+
const onClick = (event: Event): void => {
|
|
136
|
+
const target = event.target as HTMLElement | null;
|
|
137
|
+
const toggle = target?.closest<HTMLElement>('[data-kit-notice-toggle]');
|
|
138
|
+
if (toggle && root.contains(toggle)) {
|
|
139
|
+
const st = stateOf(root);
|
|
140
|
+
st.open = !st.open;
|
|
141
|
+
st.refocus = document.activeElement === toggle;
|
|
142
|
+
api.refresh();
|
|
143
|
+
api.emit('toggle', { open: st.open });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const act = target?.closest<HTMLElement>('[data-kit-notice-action]');
|
|
147
|
+
if (!act || !root.contains(act)) return;
|
|
148
|
+
const id = act.closest('[data-kit-notice]')?.getAttribute('data-kit-notice');
|
|
149
|
+
if (id === null || id === undefined) return;
|
|
150
|
+
const p = api.props();
|
|
151
|
+
const item = noticeItemsOf(p.data, p.map).find((n) => n.id === id);
|
|
152
|
+
if (item) api.emit('action', { id, href: safeHref(item.href), item: item.raw });
|
|
153
|
+
};
|
|
154
|
+
root.addEventListener('click', onClick);
|
|
155
|
+
return () => {
|
|
156
|
+
root.removeEventListener('click', onClick);
|
|
157
|
+
states.delete(root);
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
render(root, p) {
|
|
161
|
+
const doc = root.ownerDocument;
|
|
162
|
+
const st = stateOf(root);
|
|
163
|
+
const items = noticeItemsOf(p.data, p.map);
|
|
164
|
+
root.textContent = '';
|
|
165
|
+
root.removeAttribute('aria-busy');
|
|
166
|
+
root.hidden = false;
|
|
167
|
+
root.className = joinClass('', p.class);
|
|
168
|
+
const onRetry = (): void => api.emit('retry', {});
|
|
169
|
+
|
|
170
|
+
// 数据说了算的三态(未就绪 / 上游断供 / 无权限):只画面板
|
|
171
|
+
const extra = kitExtraStateKindOf(p.state_kind);
|
|
172
|
+
if (extra !== null) {
|
|
173
|
+
const retryLabel = str(p.retry_text);
|
|
174
|
+
root.appendChild(kitStatePanel(doc, extra, { text: str(p.state_text), retry: retryLabel !== '' ? onRetry : null, retryLabel }));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
// 错误 > 加载 > 内容
|
|
178
|
+
if (applyKitReadState(root, p, { hasContent: items.length > 0, onRetry, repaint: () => api.refresh() })) return;
|
|
179
|
+
|
|
180
|
+
if (items.length === 0) {
|
|
181
|
+
const emptyText = str(p.empty_text);
|
|
182
|
+
if (emptyText === '') {
|
|
183
|
+
// 整块不渲染:根 hidden、无子节点(没有错误面板时 applyKitReadState 不会往根里放东西)
|
|
184
|
+
root.hidden = true;
|
|
185
|
+
root.className = '';
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
root.appendChild(kitEmptyPanel(doc, emptyText, true));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const fold = noticeFoldOf(p.fold_after);
|
|
193
|
+
const foldable = fold > 0 && items.length > fold;
|
|
194
|
+
const hidden = foldable && !st.open ? items.length - fold : 0;
|
|
195
|
+
const shown = hidden > 0 ? items.slice(0, fold) : items;
|
|
196
|
+
|
|
197
|
+
const box = mk('div', KIT_NOTICE_BOX);
|
|
198
|
+
const title = str(p.title).trim();
|
|
199
|
+
const label = str(p.aria_label).trim();
|
|
200
|
+
if (title !== '') {
|
|
201
|
+
const head = mk('p', KIT_NOTICE_TITLE, title);
|
|
202
|
+
head.id = `${st.listId}-title`;
|
|
203
|
+
box.setAttribute('role', 'group');
|
|
204
|
+
box.setAttribute('aria-labelledby', head.id);
|
|
205
|
+
box.appendChild(head);
|
|
206
|
+
} else if (label !== '') {
|
|
207
|
+
box.setAttribute('role', 'group');
|
|
208
|
+
box.setAttribute('aria-label', label);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const ul = mk('ul', KIT_NOTICE_LIST);
|
|
212
|
+
ul.id = st.listId;
|
|
213
|
+
for (const n of shown) {
|
|
214
|
+
const li = mk('li', KIT_NOTICE_ITEM[n.tone]);
|
|
215
|
+
li.setAttribute('data-kit-notice', n.id);
|
|
216
|
+
li.setAttribute('data-kit-tone', n.tone);
|
|
217
|
+
if (n.code !== '') li.setAttribute('data-kit-code', n.code);
|
|
218
|
+
li.appendChild(kitIcon(n.icon !== '' ? n.icon : TONE_ICON[n.tone], 'sm', KIT_NOTICE_ICON[n.tone]));
|
|
219
|
+
const body = mk('span', KIT_NOTICE_BODY);
|
|
220
|
+
// 语气的读屏文字(图标是装饰,aria-hidden):不靠颜色 / 图标传达
|
|
221
|
+
body.appendChild(mk('span', KIT_NOTICE_SR_ONLY, kitText(TONE_TEXT_KEY[n.tone], undefined, root)));
|
|
222
|
+
if (n.title !== '') body.appendChild(mk('span', KIT_NOTICE_HEADLINE, n.title));
|
|
223
|
+
if (n.text !== '') body.appendChild(mk('span', '', n.text));
|
|
224
|
+
if (n.time !== '') {
|
|
225
|
+
const time = mk('time', KIT_NOTICE_TIME, n.time);
|
|
226
|
+
if (/^\d{4}-\d{2}-\d{2}/.test(n.time)) time.setAttribute('datetime', n.time);
|
|
227
|
+
body.appendChild(time);
|
|
228
|
+
}
|
|
229
|
+
if (n.actionLabel !== '') {
|
|
230
|
+
const href = safeHref(n.href);
|
|
231
|
+
if (href !== '') {
|
|
232
|
+
const a = mk('a', KIT_NOTICE_ACTION, n.actionLabel);
|
|
233
|
+
a.setAttribute('href', href);
|
|
234
|
+
a.setAttribute('data-kit-notice-action', '');
|
|
235
|
+
body.appendChild(a);
|
|
236
|
+
} else {
|
|
237
|
+
const b = mk('button', KIT_NOTICE_ACTION, n.actionLabel);
|
|
238
|
+
b.type = 'button';
|
|
239
|
+
b.setAttribute('data-kit-notice-action', '');
|
|
240
|
+
body.appendChild(b);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
li.appendChild(body);
|
|
244
|
+
ul.appendChild(li);
|
|
245
|
+
}
|
|
246
|
+
box.appendChild(ul);
|
|
247
|
+
|
|
248
|
+
let toggleBtn: HTMLButtonElement | null = null;
|
|
249
|
+
if (foldable) {
|
|
250
|
+
toggleBtn = mk('button', KIT_NOTICE_TOGGLE, st.open
|
|
251
|
+
? kitText('soma.kit.notice_collapse', undefined, root)
|
|
252
|
+
: kitText('soma.kit.notice_expand', { n: items.length - fold }, root));
|
|
253
|
+
toggleBtn.type = 'button';
|
|
254
|
+
toggleBtn.setAttribute('data-kit-notice-toggle', '');
|
|
255
|
+
toggleBtn.setAttribute('aria-expanded', st.open ? 'true' : 'false');
|
|
256
|
+
toggleBtn.setAttribute('aria-controls', st.listId);
|
|
257
|
+
box.appendChild(toggleBtn);
|
|
258
|
+
}
|
|
259
|
+
root.appendChild(box);
|
|
260
|
+
// 重绘换掉了按钮:键盘 / 点击触发的展开收起,把焦点还给新按钮
|
|
261
|
+
if (st.refocus) {
|
|
262
|
+
st.refocus = false;
|
|
263
|
+
toggleBtn?.focus();
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
})),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
// 确认类(confirm / alert)用 kit 自绘的确认对话框(data/confirm-dialog,经浮层端口挂出);typed 级要键入 phrase,consent 级先展示影响说明再确认。
|
|
5
5
|
|
|
6
6
|
import type { NotifyAction, NotifyEntry, NotifyRenderer } from 'soma-core';
|
|
7
|
+
import { KIT_OVERLAY_LIMITS } from 'soma-foundation/kit-limits';
|
|
7
8
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
8
9
|
import { kitText } from '../i18n/kit-text';
|
|
10
|
+
import { beginKitLeave } from '../base/overlay-runtime';
|
|
9
11
|
import { askKitConfirm, KIT_CONFIRM_CLASS_CANDIDATES } from './confirm-dialog';
|
|
12
|
+
import { KIT_PROMPT_CLASS_CANDIDATES } from './prompt-dialog';
|
|
10
13
|
import {
|
|
11
14
|
KIT_PART_ATTRIBUTE,
|
|
12
15
|
KIT_PART_TOAST,
|
|
@@ -16,7 +19,8 @@ import {
|
|
|
16
19
|
kitToastTitleRecipe,
|
|
17
20
|
} from '../recipes';
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
// top-16:落在浮层页头(关闭钮所在行,约 56px)之下,toast 不盖对话框 / 抽屉右上角的关闭钮(U1d)
|
|
23
|
+
const CONTAINER_CLASS = 'fixed top-16 end-4 z-50 flex flex-col gap-2';
|
|
20
24
|
const ITEM_BASE = kitOverlayRecipe({ kind: 'toast', size: 'md', toned: true });
|
|
21
25
|
const LEVEL_CLASS: Readonly<Record<NotifyEntry['level'], string>> = {
|
|
22
26
|
info: 'bg-info-soft text-info-on-soft',
|
|
@@ -32,8 +36,13 @@ const ICON_CLASS = 'mt-0.5 shrink-0';
|
|
|
32
36
|
const COUNT_CLASS = 'ms-2';
|
|
33
37
|
const LEVEL_ICON: Readonly<Record<NotifyEntry['level'], KitIconName>> = { info: 'info', success: 'success', warning: 'warning', error: 'error' };
|
|
34
38
|
|
|
35
|
-
/**
|
|
36
|
-
const DEFAULT_DURATION_MS: Readonly<Record<NotifyEntry['level'], number>> = {
|
|
39
|
+
/** 各级别默认停留毫秒:普通(info / success / warning)一律取真源 kit-limits#overlay.notifyDwellMs(4 秒);error 常驻为 0,由用户手动关闭 */
|
|
40
|
+
const DEFAULT_DURATION_MS: Readonly<Record<NotifyEntry['level'], number>> = {
|
|
41
|
+
info: KIT_OVERLAY_LIMITS.notifyDwellMs,
|
|
42
|
+
success: KIT_OVERLAY_LIMITS.notifyDwellMs,
|
|
43
|
+
warning: KIT_OVERLAY_LIMITS.notifyDwellMs,
|
|
44
|
+
error: 0,
|
|
45
|
+
};
|
|
37
46
|
/** 悬停/聚焦移开后恢复计时的最小缓冲毫秒,避免移开瞬间消失 */
|
|
38
47
|
const MIN_RESUME_BUFFER_MS = 1000;
|
|
39
48
|
|
|
@@ -44,6 +53,8 @@ export const KIT_NOTIFY_CLASS_CANDIDATES: readonly string[] = [
|
|
|
44
53
|
),
|
|
45
54
|
// 确认 / 提示对话框(自绘,模态壳 + 按钮)的类并入:通知端口的 confirm / alert 每页都可能被调用
|
|
46
55
|
...KIT_CONFIRM_CLASS_CANDIDATES,
|
|
56
|
+
// 输入对话框(request.prompt / ctx.prompt)同族
|
|
57
|
+
...KIT_PROMPT_CLASS_CANDIDATES,
|
|
47
58
|
].sort();
|
|
48
59
|
|
|
49
60
|
function resolveActions(entry: NotifyEntry): NotifyAction[] {
|
|
@@ -114,13 +125,15 @@ export function createKitNotifyRenderer(): NotifyRenderer {
|
|
|
114
125
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
115
126
|
let dismissed = false;
|
|
116
127
|
const dismiss = (): void => {
|
|
128
|
+
if (dismissed) return;
|
|
117
129
|
dismissed = true;
|
|
118
130
|
if (live.get(dedupeKey)?.dismiss === dismiss) live.delete(dedupeKey);
|
|
119
131
|
if (timer !== undefined) {
|
|
120
132
|
clearTimeout(timer);
|
|
121
133
|
timer = undefined;
|
|
122
134
|
}
|
|
123
|
-
|
|
135
|
+
// 退场:标 data-kit-leaving 等主题侧的退场关键帧结束再移除(没有关键帧 / 减弱动效时立即移除);退场中的通知已出 live 表,不再并入新通知
|
|
136
|
+
if (beginKitLeave(item, () => item.remove()) === null) item.remove();
|
|
124
137
|
};
|
|
125
138
|
|
|
126
139
|
for (const act of actions) {
|
|
@@ -169,7 +182,7 @@ export function createKitNotifyRenderer(): NotifyRenderer {
|
|
|
169
182
|
const hasExplicitDuration = typeof d === 'number' && Number.isFinite(d) && d >= 0;
|
|
170
183
|
const ms = hasExplicitDuration
|
|
171
184
|
? d
|
|
172
|
-
: (level === 'error' || actions.length > 0 ? 0 : (DEFAULT_DURATION_MS[level] ??
|
|
185
|
+
: (level === 'error' || actions.length > 0 ? 0 : (DEFAULT_DURATION_MS[level] ?? KIT_OVERLAY_LIMITS.notifyDwellMs));
|
|
173
186
|
|
|
174
187
|
if (ms > 0) {
|
|
175
188
|
let remainingMs = ms;
|
|
@@ -220,7 +233,9 @@ export function createKitNotifyRenderer(): NotifyRenderer {
|
|
|
220
233
|
...(spec?.impact !== undefined && spec.impact !== '' ? { impact: spec.impact } : {}),
|
|
221
234
|
};
|
|
222
235
|
if (spec?.level === 'typed' && spec.phrase !== undefined) return askKitConfirm({ ...base, typedPhrase: spec.phrase, tone: 'danger' });
|
|
223
|
-
if (spec?.level === 'consent') return askKitConfirm({ ...base, tone: 'danger' });
|
|
236
|
+
if (spec?.level === 'consent') return askKitConfirm({ ...base, consent: true, tone: 'danger' });
|
|
237
|
+
// 语气(core 确认规格 tone):danger = 警示色确认钮 + 初始焦点落「取消」(破坏性确认);不写 = 常规
|
|
238
|
+
if (spec?.tone === 'danger') return askKitConfirm({ ...base, tone: 'danger' });
|
|
224
239
|
return askKitConfirm(base);
|
|
225
240
|
},
|
|
226
241
|
async alert(req) {
|