soma-kit 0.1.12 → 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/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 +172 -4
- package/spec/generated/kit-page.schema.json +164 -5
- package/spec/kit-grammar.json +598 -96
- package/spec/kit-grammar.schema.json +12 -6
- package/src/app/app-config.ts +92 -8
- 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 +29 -5
- package/src/app/kit-view-context.ts +181 -15
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +55 -8
- 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 +62 -15
- 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 +61 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +168 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +95 -0
- package/src/base/index.ts +32 -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 +16 -18
- 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 +10 -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 +36 -24
- package/src/base/shared.ts +180 -36
- package/src/base/state-panel.ts +367 -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 +76 -41
- package/src/base/text.ts +43 -14
- 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 -9
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +15 -11
- package/src/biz/auth-panel/shell.ts +9 -7
- package/src/biz/category-crud/compile.ts +5 -4
- package/src/biz/category-crud/shell.ts +5 -3
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +10 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +13 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +207 -16
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +7 -3
- package/src/biz/master-sub/shell.ts +133 -24
- package/src/biz/multi-board/compile.ts +167 -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 +94 -23
- package/src/biz/notification-center/shell.ts +10 -7
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- package/src/biz/page-templates/sign-in-page/shell.ts +16 -16
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +13 -10
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +12 -9
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +97 -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 +281 -0
- package/src/biz/shared/overlay-shell.ts +142 -11
- 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 +9 -6
- package/src/biz/standard-crud/compile.ts +36 -161
- package/src/biz/standard-crud/shell.ts +23 -60
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +15 -13
- package/src/biz/types.ts +6 -1
- 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/access-gate-attach.ts +27 -0
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +66 -11
- package/src/compile/component-candidates.ts +14 -1
- package/src/compile/fragment.ts +11 -0
- 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 +267 -0
- package/src/compile/layout-lint/rules-form.ts +191 -0
- package/src/compile/layout-lint/rules-table.ts +278 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- 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/remove-guard.ts +10 -7
- package/src/compile/styles.ts +46 -8
- package/src/compile/types.ts +16 -2
- package/src/compile/view-check.ts +149 -16
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +9 -2
- package/src/data/approval-flow.ts +5 -2
- package/src/data/assignment-picker.ts +59 -28
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +8 -3
- package/src/data/carousel.ts +10 -6
- package/src/data/chart.ts +744 -46
- package/src/data/checklist.ts +22 -6
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +3 -2
- package/src/data/confirm-dialog.ts +72 -25
- 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 +7 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +26 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +4 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +16 -4
- package/src/data/item-list.ts +27 -12
- package/src/data/kanban.ts +41 -10
- package/src/data/matrix.ts +391 -0
- 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 +60 -16
- package/src/data/mockup.ts +5 -1
- package/src/data/modal-dialog.ts +146 -26
- package/src/data/navbar.ts +8 -6
- package/src/data/notice-list.ts +301 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +409 -87
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +19 -8
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +36 -11
- package/src/data/permission-tree.ts +52 -23
- package/src/data/pricing-table.ts +22 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +40 -7
- package/src/data/record-picker.ts +13 -7
- package/src/data/resident.ts +8 -0
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +77 -24
- package/src/data/rule-builder.ts +14 -9
- package/src/data/shape-util.ts +27 -12
- package/src/data/stat-group.ts +459 -74
- package/src/data/static-lazy.ts +5 -0
- package/src/data/static-registry.ts +8 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +7 -4
- package/src/data/system-switcher.ts +3 -2
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +3 -2
- package/src/data/transfer.ts +40 -16
- package/src/data/tree-table.ts +65 -37
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +21 -11
- package/src/data/wrapped-candidates.ts +32 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +7 -14
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +34 -13
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +9 -6
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +3 -3
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +4 -4
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +168 -44
- package/src/generated/kit-grammar-runtime.ts +390 -59
- package/src/i18n/kit-text.ts +90 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +71 -7
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +264 -62
- package/src/object-renderer/collection-table.ts +177 -5
- package/src/object-renderer/collection.ts +188 -37
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +27 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +434 -41
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +394 -0
- package/src/object-renderer/layout-plan.ts +225 -0
- package/src/object-renderer/layout-plan.types.ts +59 -0
- package/src/object-renderer/parts.ts +6 -7
- package/src/object-renderer/render-object.ts +107 -46
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +172 -32
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +62 -30
- package/src/object-renderer/types.ts +84 -13
- 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 +77 -1
- package/src/recipes/control.ts +76 -116
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +72 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +120 -17
- package/src/recipes/placeholder.ts +95 -0
- package/src/recipes/rail-grid.ts +48 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +40 -21
- package/src/recipes/status.ts +147 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +146 -3
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +30 -37
- 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 +384 -13
- package/src/theme/kit-theme.tpl +384 -13
- package/src/theme/nine-dim-structure.ts +244 -7
- package/src/theme/surface-layers.ts +10 -1
- package/src/theme/theme-tokens.ts +63 -16
- package/src/theme/theme-types.ts +32 -0
- package/src/theme/typography.ts +21 -17
- package/src/biz/shared/remove-key.ts +0 -6
|
@@ -0,0 +1,301 @@
|
|
|
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 { KIT_NOTICE_FOLD as KIT_NOTICE_FOLD_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
|
+
import { kitText } from '../i18n/kit-text';
|
|
21
|
+
import { KIT_ICON_CLASS_CANDIDATES, KIT_ICON_NAMES, kitIcon, type KitIconName } from '../base/icons';
|
|
22
|
+
import { safeHref } from '../base/link';
|
|
23
|
+
import { KIT_STATUS_TONE_ICON, KIT_STATUS_TONE_TEXT_KEY, statusToneOrNull } from '../base/status-tone';
|
|
24
|
+
import {
|
|
25
|
+
applyKitReadState, KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS, KIT_STATE_PANEL_CLASS_CANDIDATES,
|
|
26
|
+
kitEmptyPanel, kitExtraStateKindOf, kitStatePanel,
|
|
27
|
+
} from '../base/state-panel';
|
|
28
|
+
import { CLASS_PROP, createKitController, joinClass, kitCollapseBlock, nextUid, num, str } from '../base/shared';
|
|
29
|
+
import {
|
|
30
|
+
KIT_NOTICE_ACTION, KIT_NOTICE_BODY, KIT_NOTICE_BOX, KIT_NOTICE_BOX_FOOTER, KIT_NOTICE_TOGGLE_FOOTER, KIT_NOTICE_HEADLINE, KIT_NOTICE_ICON, KIT_NOTICE_ITEM, KIT_NOTICE_LIST,
|
|
31
|
+
KIT_NOTICE_RECIPE_CLASS_CANDIDATES, KIT_NOTICE_SR_ONLY, KIT_NOTICE_TIME, KIT_NOTICE_TITLE, KIT_NOTICE_TOGGLE,
|
|
32
|
+
type KitStatusTone,
|
|
33
|
+
} from '../recipes/status';
|
|
34
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
35
|
+
import { classTokens, keyMap, mk, recOf, textOf } from './shape-util';
|
|
36
|
+
|
|
37
|
+
/** 自动折叠阈值与常显条数(真源 kit-limits#noticeFold) */
|
|
38
|
+
export const KIT_NOTICE_FOLD = KIT_NOTICE_FOLD_LIMITS;
|
|
39
|
+
|
|
40
|
+
export const KIT_NOTICE_LIST_DEFAULT_MAP = Object.freeze({
|
|
41
|
+
id: 'id', code: 'code', tone: 'tone', title: 'title', text: 'text', time: 'time', href: 'href', action_label: 'action_label', icon: 'icon',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const KIT_NOTICE_LIST_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
45
|
+
KIT_NOTICE_RECIPE_CLASS_CANDIDATES, KIT_STATE_PANEL_CLASS_CANDIDATES, KIT_ICON_CLASS_CANDIDATES,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export interface KitNotice {
|
|
49
|
+
id: string;
|
|
50
|
+
code: string;
|
|
51
|
+
tone: KitStatusTone;
|
|
52
|
+
title: string;
|
|
53
|
+
text: string;
|
|
54
|
+
time: string;
|
|
55
|
+
href: string;
|
|
56
|
+
actionLabel: string;
|
|
57
|
+
/** kit 图标名;空 = 按语气取默认图标 */
|
|
58
|
+
icon: KitIconName | '';
|
|
59
|
+
raw: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const TONE_ICON = KIT_STATUS_TONE_ICON;
|
|
63
|
+
const TONE_TEXT_KEY = KIT_STATUS_TONE_TEXT_KEY;
|
|
64
|
+
|
|
65
|
+
/** 语气:在闭集内取,否则按 info(说明条的缺省语气) */
|
|
66
|
+
export function noticeToneOf(raw: unknown): KitStatusTone {
|
|
67
|
+
return statusToneOrNull(raw) ?? 'info';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 条目(纯函数,便于单测):只要 text 与 title 都空的丢弃;缺 id 用下标;tone 不在闭集按 info */
|
|
71
|
+
export function noticeItemsOf(rawRows: unknown, mapRaw: unknown): KitNotice[] {
|
|
72
|
+
const m = keyMap(KIT_NOTICE_LIST_DEFAULT_MAP, mapRaw);
|
|
73
|
+
const rec = recOf(rawRows);
|
|
74
|
+
const list: unknown[] = Array.isArray(rawRows) ? rawRows : Array.isArray(rec.items) ? rec.items as unknown[] : [];
|
|
75
|
+
const out: KitNotice[] = [];
|
|
76
|
+
list.forEach((row, i) => {
|
|
77
|
+
if (row === null || typeof row !== 'object' || Array.isArray(row)) return;
|
|
78
|
+
const raw = row as Record<string, unknown>;
|
|
79
|
+
const text = textOf(raw[m.text]);
|
|
80
|
+
const title = textOf(raw[m.title]);
|
|
81
|
+
if (text.trim() === '' && title.trim() === '') return;
|
|
82
|
+
const idRaw = textOf(raw[m.id]);
|
|
83
|
+
const iconRaw = textOf(raw[m.icon]);
|
|
84
|
+
out.push({
|
|
85
|
+
id: idRaw === '' ? `i${i}` : idRaw,
|
|
86
|
+
code: textOf(raw[m.code]),
|
|
87
|
+
tone: noticeToneOf(raw[m.tone]),
|
|
88
|
+
title,
|
|
89
|
+
text,
|
|
90
|
+
time: textOf(raw[m.time]),
|
|
91
|
+
href: textOf(raw[m.href]),
|
|
92
|
+
actionLabel: textOf(raw[m.action_label]),
|
|
93
|
+
icon: (KIT_ICON_NAMES as readonly string[]).includes(iconRaw) ? iconRaw as KitIconName : '',
|
|
94
|
+
raw,
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 条目来源:items(展示对象成员绑定的数组)非空取它,否则取 data;两处读取(渲染 / 点击)共用 */
|
|
101
|
+
function noticeSourceOf(p: Record<string, unknown>): unknown {
|
|
102
|
+
return Array.isArray(p.items) && p.items.length > 0 ? p.items : p.data;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 折叠阈值:≥ 1 的整数才生效,其余(0 / 负 / 非数字)= 不折叠 */
|
|
106
|
+
export function noticeFoldOf(raw: unknown): number {
|
|
107
|
+
const n = num(raw);
|
|
108
|
+
return n !== null && n >= 1 ? Math.floor(n) : 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function createNoticeList(): SomaComponentDefinition {
|
|
112
|
+
interface NoticeState { open: boolean; refocus: boolean; listId: string }
|
|
113
|
+
const states = new WeakMap<HTMLElement, NoticeState>();
|
|
114
|
+
const stateOf = (root: HTMLElement): NoticeState => {
|
|
115
|
+
let s = states.get(root);
|
|
116
|
+
if (!s) { s = { open: false, refocus: false, listId: nextUid('kit-notice') }; states.set(root, s); }
|
|
117
|
+
return s;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
contract: {
|
|
122
|
+
name: 'NoticeList',
|
|
123
|
+
layer: 'data',
|
|
124
|
+
props: {
|
|
125
|
+
data: { type: 'array', default: [], desc: '说明条目 [{ id?, code?, tone?(neutral / info / success / warning / danger,缺省 info), title?, text, time?, href?, action_label?, icon?(kit 图标名,缺省按语气) }];顺序与去重由数据决定,组件不排序' },
|
|
126
|
+
items: { type: 'array', default: [], desc: '条目数组(与 data 同形):页面声明 items: view.<成员> 取展示对象成员里的数组,不必再写包装组件;非空时取它,否则取 data(同一条渲染路径)' },
|
|
127
|
+
map: { type: 'object', default: {}, desc: '键名对照:id / code / tone / title / text / time / href / action_label / icon' },
|
|
128
|
+
title: { type: 'string', default: '', desc: '列表小标题(如「数据说明」);空不显示。有标题时整块带 role=group 并以它命名' },
|
|
129
|
+
fold_after: { type: 'number', default: 0, desc: '超过该条数折叠(≥ 1 生效):只画前 N 条,其余由「展开其余 N 条」按钮展开;0 = 自动(条数超过真源 kit-limits#noticeFold.autoAfter 时只画前 autoAfter 条,不超过则全部展开)' },
|
|
130
|
+
collapse: { type: 'boolean', default: false, desc: '整组折叠为一项「标题(N)」,默认收起;danger 语气条(至多 noticeFold.pinnedMax 条)常显。用于数据说明 / 降级 / 素材缺口这类不该压过正文的提示' },
|
|
131
|
+
footer: { type: 'boolean', default: false, desc: '作为宿主面板的页脚(只在 collapse 时生效):不画自己的面与边,只是面板底部一行次级色收起项。MultiObjectBoard 把「紧跟在某面板之后、无标题、collapse 的 NoticeList 面板」自动并为前一面板的页脚,页面不写这个键' },
|
|
132
|
+
empty_text: { type: 'string', default: '', desc: '没有条目时的紧凑空态文案;空 = 整块不渲染(根 hidden、无子节点)' },
|
|
133
|
+
state_kind: { type: 'string', default: '', desc: '由数据给出的三态:not_ready(未就绪)/ upstream_broken(上游断供)/ denied(无权查看);非空且在闭集内时只画对应面板,不画条目' },
|
|
134
|
+
state_text: { type: 'string', default: '', desc: 'state_kind 面板的文案;空取内置默认文案(按页面语言)' },
|
|
135
|
+
aria_label: { type: 'string', default: '', desc: '无小标题时整块的无障碍名称(写入 role=group 的 aria-label)' },
|
|
136
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
137
|
+
class: CLASS_PROP,
|
|
138
|
+
},
|
|
139
|
+
emits: {
|
|
140
|
+
toggle: { payload: { open: { type: 'boolean' } }, desc: '展开 / 收起其余条目;open 为展开后的状态' },
|
|
141
|
+
action: { payload: { id: { type: 'string' }, href: { type: 'string' }, item: { type: 'object' } }, desc: '点条目的动作链接 / 按钮(有可用 href 时照常跳转,同时抛本事件)' },
|
|
142
|
+
...KIT_READ_STATE_EMIT_DEFS,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
templateHtml: '<div data-soma-id="root"></div>',
|
|
146
|
+
controllerFactory: createKitController((api) => ({
|
|
147
|
+
attach(root) {
|
|
148
|
+
const onClick = (event: Event): void => {
|
|
149
|
+
const target = event.target as HTMLElement | null;
|
|
150
|
+
const toggle = target?.closest<HTMLElement>('[data-kit-notice-toggle]');
|
|
151
|
+
if (toggle && root.contains(toggle)) {
|
|
152
|
+
const st = stateOf(root);
|
|
153
|
+
st.open = !st.open;
|
|
154
|
+
st.refocus = document.activeElement === toggle;
|
|
155
|
+
api.refresh();
|
|
156
|
+
api.emit('toggle', { open: st.open });
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const act = target?.closest<HTMLElement>('[data-kit-notice-action]');
|
|
160
|
+
if (!act || !root.contains(act)) return;
|
|
161
|
+
const id = act.closest('[data-kit-notice]')?.getAttribute('data-kit-notice');
|
|
162
|
+
if (id === null || id === undefined) return;
|
|
163
|
+
const p = api.props();
|
|
164
|
+
const item = noticeItemsOf(noticeSourceOf(p), p.map).find((n) => n.id === id);
|
|
165
|
+
if (item) api.emit('action', { id, href: safeHref(item.href), item: item.raw });
|
|
166
|
+
};
|
|
167
|
+
root.addEventListener('click', onClick);
|
|
168
|
+
return () => {
|
|
169
|
+
root.removeEventListener('click', onClick);
|
|
170
|
+
states.delete(root);
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
render(root, p) {
|
|
174
|
+
const doc = root.ownerDocument;
|
|
175
|
+
const st = stateOf(root);
|
|
176
|
+
const items = noticeItemsOf(noticeSourceOf(p), p.map);
|
|
177
|
+
root.textContent = '';
|
|
178
|
+
root.removeAttribute('aria-busy');
|
|
179
|
+
kitCollapseBlock(root, false);
|
|
180
|
+
root.className = joinClass('', p.class);
|
|
181
|
+
const onRetry = (): void => api.emit('retry', {});
|
|
182
|
+
|
|
183
|
+
// 数据说了算的三态(未就绪 / 上游断供 / 无权限):只画面板
|
|
184
|
+
const extra = kitExtraStateKindOf(p.state_kind);
|
|
185
|
+
if (extra !== null) {
|
|
186
|
+
const retryLabel = str(p.retry_text);
|
|
187
|
+
root.appendChild(kitStatePanel(doc, extra, { text: str(p.state_text), retry: retryLabel !== '' ? onRetry : null, retryLabel }));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
// 错误 > 加载 > 内容
|
|
191
|
+
if (applyKitReadState(root, p, { hasContent: items.length > 0, onRetry, repaint: () => api.refresh() })) return;
|
|
192
|
+
|
|
193
|
+
if (items.length === 0) {
|
|
194
|
+
const emptyText = str(p.empty_text);
|
|
195
|
+
if (emptyText === '') {
|
|
196
|
+
// 整块不渲染:根 hidden、无子节点(没有错误面板时 applyKitReadState 不会往根里放东西)
|
|
197
|
+
kitCollapseBlock(root, true);
|
|
198
|
+
root.className = '';
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
root.appendChild(kitEmptyPanel(doc, emptyText));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 折叠:collapse = 整组收成「标题(N)」一项(danger 条至多 pinnedMax 条常显);否则 fold_after ≥ 1 取它,
|
|
206
|
+
// 没写(0)时条数超过 autoAfter 自动只画前 autoAfter 条
|
|
207
|
+
const collapse = p.collapse === true;
|
|
208
|
+
const title = str(p.title).trim();
|
|
209
|
+
let shown: KitNotice[];
|
|
210
|
+
let foldable: boolean;
|
|
211
|
+
let toggleLabelClosed: string;
|
|
212
|
+
if (collapse) {
|
|
213
|
+
const pinned = new Set(items.filter((n) => n.tone === 'danger').slice(0, KIT_NOTICE_FOLD.pinnedMax));
|
|
214
|
+
const restCount = items.length - pinned.size;
|
|
215
|
+
foldable = restCount > 0;
|
|
216
|
+
shown = foldable && !st.open ? items.filter((n) => pinned.has(n)) : items;
|
|
217
|
+
toggleLabelClosed = title !== '' ? `${title}(${restCount})` : kitText('soma.kit.notice_expand', { n: restCount }, root);
|
|
218
|
+
} else {
|
|
219
|
+
const explicit = noticeFoldOf(p.fold_after);
|
|
220
|
+
const fold = explicit > 0 ? explicit : items.length > KIT_NOTICE_FOLD.autoAfter ? KIT_NOTICE_FOLD.autoAfter : 0;
|
|
221
|
+
foldable = fold > 0 && items.length > fold;
|
|
222
|
+
shown = foldable && !st.open ? items.slice(0, fold) : items;
|
|
223
|
+
toggleLabelClosed = kitText('soma.kit.notice_expand', { n: items.length - fold }, root);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 页脚形态:折叠的数据说明属于它所说明的面板——无自己的面与边(面板页脚一行收起项)
|
|
227
|
+
const footer = collapse && p.footer === true;
|
|
228
|
+
const box = mk('div', footer ? KIT_NOTICE_BOX_FOOTER : KIT_NOTICE_BOX);
|
|
229
|
+
if (footer) box.setAttribute('data-kit-notice-footer', '');
|
|
230
|
+
markKitEdge(box);
|
|
231
|
+
const label = collapse && title !== '' ? title : str(p.aria_label).trim();
|
|
232
|
+
if (title !== '' && !collapse) {
|
|
233
|
+
const head = mk('p', KIT_NOTICE_TITLE, title);
|
|
234
|
+
head.id = `${st.listId}-title`;
|
|
235
|
+
box.setAttribute('role', 'group');
|
|
236
|
+
box.setAttribute('aria-labelledby', head.id);
|
|
237
|
+
box.appendChild(head);
|
|
238
|
+
} else if (label !== '') {
|
|
239
|
+
box.setAttribute('role', 'group');
|
|
240
|
+
box.setAttribute('aria-label', label);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const ul = mk('ul', KIT_NOTICE_LIST);
|
|
244
|
+
ul.id = st.listId;
|
|
245
|
+
if (shown.length === 0) ul.hidden = true;
|
|
246
|
+
for (const n of shown) {
|
|
247
|
+
const li = mk('li', KIT_NOTICE_ITEM[n.tone]);
|
|
248
|
+
li.setAttribute('data-kit-notice', n.id);
|
|
249
|
+
li.setAttribute('data-kit-tone', n.tone);
|
|
250
|
+
if (n.code !== '') li.setAttribute('data-kit-code', n.code);
|
|
251
|
+
li.appendChild(kitIcon(n.icon !== '' ? n.icon : TONE_ICON[n.tone], 'sm', KIT_NOTICE_ICON[n.tone]));
|
|
252
|
+
const body = mk('span', KIT_NOTICE_BODY);
|
|
253
|
+
// 语气的读屏文字(图标是装饰,aria-hidden):不靠颜色 / 图标传达
|
|
254
|
+
body.appendChild(mk('span', KIT_NOTICE_SR_ONLY, kitText(TONE_TEXT_KEY[n.tone], undefined, root)));
|
|
255
|
+
if (n.title !== '') body.appendChild(mk('span', KIT_NOTICE_HEADLINE, n.title));
|
|
256
|
+
if (n.text !== '') body.appendChild(mk('span', '', n.text));
|
|
257
|
+
if (n.time !== '') {
|
|
258
|
+
const time = mk('time', KIT_NOTICE_TIME, n.time);
|
|
259
|
+
if (/^\d{4}-\d{2}-\d{2}/.test(n.time)) time.setAttribute('datetime', n.time);
|
|
260
|
+
body.appendChild(time);
|
|
261
|
+
}
|
|
262
|
+
if (n.actionLabel !== '') {
|
|
263
|
+
const href = safeHref(n.href);
|
|
264
|
+
if (href !== '') {
|
|
265
|
+
const a = mk('a', KIT_NOTICE_ACTION, n.actionLabel);
|
|
266
|
+
a.setAttribute('href', href);
|
|
267
|
+
a.setAttribute('data-kit-notice-action', '');
|
|
268
|
+
body.appendChild(a);
|
|
269
|
+
} else {
|
|
270
|
+
const b = mk('button', KIT_NOTICE_ACTION, n.actionLabel);
|
|
271
|
+
b.type = 'button';
|
|
272
|
+
b.setAttribute('data-kit-notice-action', '');
|
|
273
|
+
body.appendChild(b);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
li.appendChild(body);
|
|
277
|
+
ul.appendChild(li);
|
|
278
|
+
}
|
|
279
|
+
if (shown.length > 0) box.appendChild(ul);
|
|
280
|
+
|
|
281
|
+
let toggleBtn: HTMLButtonElement | null = null;
|
|
282
|
+
if (foldable) {
|
|
283
|
+
toggleBtn = mk('button', footer ? KIT_NOTICE_TOGGLE_FOOTER : KIT_NOTICE_TOGGLE, st.open
|
|
284
|
+
? kitText('soma.kit.notice_collapse', undefined, root)
|
|
285
|
+
: toggleLabelClosed);
|
|
286
|
+
toggleBtn.type = 'button';
|
|
287
|
+
toggleBtn.setAttribute('data-kit-notice-toggle', '');
|
|
288
|
+
toggleBtn.setAttribute('aria-expanded', st.open ? 'true' : 'false');
|
|
289
|
+
toggleBtn.setAttribute('aria-controls', st.listId);
|
|
290
|
+
box.appendChild(toggleBtn);
|
|
291
|
+
}
|
|
292
|
+
root.appendChild(box);
|
|
293
|
+
// 重绘换掉了按钮:键盘 / 点击触发的展开收起,把焦点还给新按钮
|
|
294
|
+
if (st.refocus) {
|
|
295
|
+
st.refocus = false;
|
|
296
|
+
toggleBtn?.focus();
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
})),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
@@ -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) {
|