soma-kit 0.1.14 → 0.1.15
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/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- package/spec/generated/kit-app.schema.json +4 -2
- package/spec/generated/kit-page.schema.json +72 -2
- package/spec/kit-grammar.json +163 -57
- package/spec/kit-grammar.schema.json +0 -24
- package/src/app/app-config.ts +1 -1
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +82 -10
- package/src/app/define-kit-app.ts +6 -5
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +7 -7
- package/src/app/kit-view-context.ts +11 -2
- package/src/app/theme-endpoint.ts +1 -1
- package/src/app/theme-runtime.ts +7 -2
- package/src/base/alert.ts +23 -20
- package/src/base/anchored-layer.ts +1 -1
- package/src/base/button.ts +30 -15
- package/src/base/cascader.ts +8 -4
- package/src/base/check-core.ts +9 -6
- package/src/base/color-picker.ts +10 -6
- package/src/base/command-palette.ts +10 -4
- package/src/base/context-menu.ts +5 -2
- package/src/base/date-range.ts +9 -6
- package/src/base/date.ts +10 -6
- package/src/base/delta.ts +4 -2
- package/src/base/divider.ts +15 -66
- package/src/base/fab.ts +11 -6
- package/src/base/gap-value.ts +1 -1
- package/src/base/hint-tips.ts +1 -1
- package/src/base/index.ts +15 -4
- package/src/base/inline-error.ts +84 -0
- package/src/base/input.ts +54 -18
- package/src/base/kbd.ts +4 -3
- package/src/base/link.ts +1 -1
- package/src/base/listbox-core.ts +70 -22
- package/src/base/mentions.ts +6 -3
- package/src/base/menu-button.ts +63 -27
- package/src/base/menu-core.ts +9 -2
- package/src/base/motion/hover-3d.ts +4 -1
- package/src/base/motion/hover-gallery.ts +4 -1
- package/src/base/otp.ts +7 -3
- package/src/base/overlay-runtime.ts +3 -2
- package/src/base/overlay-shell.ts +141 -0
- package/src/base/popover.ts +2 -2
- package/src/base/popup.ts +47 -41
- package/src/base/qty-stepper.ts +14 -9
- package/src/base/reason-tip.ts +2 -2
- package/src/{frames → base}/resize-handle.ts +1 -1
- package/src/base/segmented.ts +35 -36
- package/src/base/select.ts +1 -0
- package/src/base/shared.ts +43 -7
- package/src/base/status-tone.ts +1 -1
- package/src/base/tag-input.ts +13 -8
- package/src/base/tag.ts +53 -59
- package/src/base/text.ts +37 -13
- package/src/base/textarea.ts +1 -1
- package/src/base/time-picker.ts +9 -5
- package/src/base/tree-select.ts +12 -9
- package/src/base/upload.ts +21 -13
- package/src/biz/approval-desk/compile.ts +28 -1
- package/src/biz/approval-desk/shell.ts +2 -2
- package/src/biz/auth-panel/compile.ts +1 -1
- package/src/biz/auth-panel/shell.ts +2 -2
- package/src/biz/category-crud/compile.ts +17 -4
- package/src/biz/category-crud/shell.ts +7 -5
- package/src/biz/checkout-page/compile.ts +1 -1
- package/src/biz/checkout-page/shell.ts +7 -6
- package/src/biz/compose.ts +3 -3
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +1 -1
- package/src/biz/import-wizard/shell.ts +6 -4
- package/src/biz/index.ts +4 -3
- package/src/biz/landing-page/compile.ts +1 -1
- package/src/biz/landing-page/shell.ts +5 -4
- package/src/biz/link/shared.ts +8 -1
- package/src/biz/master-sub/compile.ts +162 -19
- package/src/biz/master-sub/detail-head.ts +7 -6
- package/src/biz/master-sub/index.ts +3 -3
- package/src/biz/master-sub/shell.ts +90 -53
- package/src/biz/multi-board/compile.ts +3 -3
- package/src/biz/multi-board/index.ts +24 -9
- package/src/biz/multi-board/prose-fold.ts +2 -2
- package/src/biz/multi-board/shell.ts +17 -13
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +9 -2
- package/src/biz/notification-center/shell.ts +9 -2
- package/src/biz/page-templates/domain-templates.ts +6 -2
- package/src/biz/page-templates/result-page/compile.ts +1 -1
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +4 -4
- package/src/biz/record-detail/compile.ts +5 -2
- package/src/biz/record-detail/shell.ts +4 -4
- package/src/biz/settings-center/compile.ts +1 -1
- package/src/biz/settings-center/shell.ts +8 -5
- package/src/biz/shared/action-host.ts +12 -5
- package/src/biz/shared/compile-helpers.ts +4 -4
- package/src/biz/shared/coordinator.ts +104 -21
- package/src/biz/shared/overlay-compile.ts +48 -18
- package/src/biz/shared/overlay-shell.ts +63 -112
- package/src/biz/single-form/compile.ts +2 -2
- package/src/biz/single-form/shell.ts +8 -4
- package/src/biz/standard-crud/compile.ts +11 -4
- package/src/biz/standard-crud/shell.ts +26 -9
- package/src/biz/standard-crud/summary.ts +3 -1
- package/src/biz/step-form/compile.ts +1 -1
- package/src/biz/step-form/hub.ts +4 -0
- package/src/biz/step-form/shell.ts +6 -4
- package/src/biz/types.ts +11 -4
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +35 -8
- package/src/cli/kit-init.ts +149 -0
- package/src/compile/access-gate-attach.ts +1 -1
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/compile-page.ts +29 -234
- package/src/compile/component-candidates.ts +2 -1
- package/src/compile/hints.ts +5 -58
- package/src/compile/index.ts +2 -2
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +43 -13
- package/src/compile/page-composition.ts +33 -31
- package/src/compile/redirect.ts +1 -1
- package/src/compile/stages.ts +169 -0
- package/src/compile/styles.ts +70 -32
- package/src/compile/types.ts +2 -2
- package/src/data/amount-breakdown.ts +4 -2
- package/src/data/anchor-nav.ts +4 -1
- package/src/data/approval-flow.ts +9 -4
- package/src/data/assignment-picker.ts +28 -18
- package/src/data/async-result-panel.ts +6 -2
- package/src/data/breadcrumbs.ts +13 -9
- package/src/data/calendar.ts +4 -3
- package/src/data/carousel.ts +11 -5
- package/src/data/chart.ts +153 -23
- package/src/data/checklist.ts +5 -4
- package/src/data/code-view.ts +220 -26
- package/src/data/comment-thread.ts +7 -2
- package/src/data/confirm-dialog.ts +56 -13
- package/src/data/diff.ts +4 -1
- package/src/data/dock.ts +5 -1
- package/src/data/embed.ts +1 -1
- package/src/data/engine-ports.ts +126 -0
- package/src/data/field-mapper.ts +12 -6
- package/src/data/flow-editor.ts +105 -29
- package/src/data/footer.ts +6 -2
- package/src/data/gantt.ts +11 -8
- package/src/data/hero.ts +6 -2
- package/src/data/image-viewer.ts +7 -3
- package/src/data/index.ts +12 -5
- package/src/data/item-list.ts +6 -5
- package/src/data/json-view.ts +844 -0
- package/src/data/kanban.ts +11 -8
- package/src/data/markdown-view.ts +487 -0
- package/src/data/matrix.ts +23 -14
- package/src/data/media-grid.ts +5 -2
- package/src/data/mega-menu.ts +4 -3
- package/src/data/menu-dom.ts +9 -8
- package/src/data/menu.ts +15 -9
- package/src/data/mockup.ts +9 -5
- package/src/data/modal-dialog.ts +39 -88
- package/src/data/navbar.ts +11 -7
- package/src/data/notice-list.ts +1 -1
- package/src/data/notify-renderer.ts +21 -10
- package/src/data/object-form.ts +129 -48
- package/src/data/pager.ts +12 -8
- package/src/data/panel-head.ts +1 -1
- package/src/data/permission-matrix.ts +15 -8
- package/src/data/permission-tree.ts +24 -11
- package/src/data/pricing-table.ts +8 -3
- package/src/data/reaction-bar.ts +6 -3
- package/src/data/record-card.ts +13 -9
- package/src/data/record-picker.ts +8 -4
- package/src/data/redirect.ts +1 -1
- package/src/data/request-console.ts +20 -7
- package/src/data/resident.ts +0 -12
- package/src/data/result-panel.ts +2 -2
- package/src/data/rich-text.ts +58 -96
- package/src/data/row-editor.ts +10 -5
- package/src/data/rule-builder.ts +14 -8
- package/src/data/shape-util.ts +14 -3
- package/src/data/stat-group.ts +63 -22
- package/src/data/static-lazy.ts +3 -0
- package/src/data/static-registry.ts +8 -2
- package/src/data/steps.ts +6 -2
- package/src/data/survey.ts +9 -3
- package/src/data/system-switcher.ts +15 -6
- package/src/data/text-diff.ts +663 -0
- package/src/data/timeline.ts +1 -1
- package/src/data/tour-guide.ts +6 -3
- package/src/data/transfer.ts +19 -10
- package/src/data/tree-table.ts +77 -12
- package/src/data/tree.ts +5 -2
- package/src/data/virtual-rows.ts +17 -7
- package/src/data/wrap.ts +2 -2
- package/src/frames/index.ts +3 -2
- package/src/frames/inherited-shell.ts +178 -0
- package/src/frames/list-summary.ts +59 -36
- package/src/frames/page-bar.ts +4 -2
- package/src/frames/resident-components.ts +20 -0
- package/src/frames/shared.ts +18 -14
- package/src/frames/split-frame/shell.ts +17 -11
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +12 -6
- package/src/frames/types.ts +3 -2
- package/src/frames/workspace-frame/extras.ts +19 -5
- package/src/frames/workspace-frame/shell.ts +2 -1
- package/src/frames/workspace-frame/state.ts +8 -2
- package/src/frames/workspace-frame/view.ts +125 -76
- package/src/generated/kit-grammar-runtime.ts +61 -39
- package/src/i18n/kit-text.ts +114 -2
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +31 -1
- package/src/object-renderer/action-more.ts +28 -12
- package/src/object-renderer/arrange.ts +37 -7
- package/src/object-renderer/collection-parts.ts +38 -7
- package/src/object-renderer/collection-table.ts +68 -23
- package/src/object-renderer/collection.ts +63 -30
- package/src/object-renderer/compile-data.ts +1 -1
- package/src/object-renderer/defaults.ts +8 -0
- package/src/object-renderer/emit-events.ts +1 -1
- package/src/object-renderer/emit-object.ts +3 -0
- package/src/object-renderer/emit-static.ts +140 -37
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-toolbar.ts +103 -0
- package/src/{compile → object-renderer}/fragment.ts +2 -2
- package/src/object-renderer/index.ts +1 -1
- package/src/object-renderer/layout-facts.ts +37 -5
- package/src/object-renderer/overlay-decide.ts +82 -0
- package/src/object-renderer/render-object.ts +1 -1
- package/src/object-renderer/table-actions.ts +70 -23
- package/src/object-renderer/table-tools.ts +12 -5
- package/src/object-renderer/types.ts +9 -15
- package/src/recipes/app-blocks.ts +66 -0
- package/src/recipes/code-view.ts +56 -0
- package/src/recipes/compact-group.ts +31 -0
- package/src/recipes/container.ts +25 -15
- package/src/recipes/control.ts +21 -3
- package/src/recipes/desc-list.ts +14 -0
- package/src/recipes/divider.ts +53 -0
- package/src/recipes/emphasis.ts +12 -8
- package/src/recipes/frame-bleed.ts +3 -3
- package/src/recipes/index.ts +11 -1
- package/src/recipes/inherited-shell.ts +37 -0
- package/src/recipes/json-view.ts +49 -0
- package/src/recipes/markdown.ts +86 -0
- package/src/recipes/overlay.ts +112 -26
- package/src/recipes/page-width.ts +20 -0
- package/src/recipes/placeholder.ts +1 -1
- package/src/recipes/stat-state.ts +1 -1
- package/src/recipes/state.ts +10 -8
- package/src/recipes/status.ts +13 -12
- package/src/recipes/strip.ts +72 -0
- package/src/recipes/surface.ts +10 -6
- package/src/recipes/table-gap.ts +1 -1
- package/src/recipes/table-native-edit.ts +4 -4
- package/src/recipes/table-row.ts +11 -8
- package/src/recipes/tabs.ts +108 -31
- package/src/recipes/text-diff.ts +90 -0
- package/src/recipes/title-row.ts +4 -2
- package/src/recipes/typography.ts +2 -2
- package/src/shared/diagnostics.ts +16 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-value-format.ts +246 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +12 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- package/src/shared/path-guard.ts +1 -1
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/theme-runtime-shared.ts +19 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -14
- package/src/theme/kit-theme.tpl +38 -14
- package/src/theme/nine-dim-structure.ts +66 -41
- package/src/theme/surface-layers.ts +11 -3
- package/src/theme/theme-tokens.ts +5 -1
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- /package/src/{base → shared}/class-candidates.ts +0 -0
package/src/data/code-view.ts
CHANGED
|
@@ -1,26 +1,151 @@
|
|
|
1
1
|
// CodeView:只读代码 / 文本块(layer: data,写死形状,accept: single)。
|
|
2
2
|
//
|
|
3
3
|
// 数据:`data` 是 { title?, text, caption? };`text` 非字符串(对象、数组)时按两空格缩进的 JSON 展示。
|
|
4
|
-
// 等宽、保留换行、可滚动(有 max_height
|
|
4
|
+
// 等宽、保留换行、可滚动(有 max_height 档时);顶部标题行右侧「复制」钮(缺省显示,copyable: false 关闭):
|
|
5
5
|
// 经剪贴板接口写入,成功把按钮文字短暂换成 copied_label,抛 `copy { ok }`(不带文本,避免凭据类文本再次上行)。
|
|
6
6
|
// 数据只经 textContent 写入。无文本显示 empty_text。
|
|
7
7
|
|
|
8
8
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
9
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
10
|
-
import { kitIcon } from '../
|
|
10
|
+
import { kitIcon } from '../shared/icons';
|
|
11
11
|
import { KIT_PART_ATTRIBUTE, KIT_PART_WELL } from '../recipes';
|
|
12
|
+
import { KIT_DIVIDER_HEAD_CLASS, kitDividerRecipe } from '../recipes/divider';
|
|
13
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
12
14
|
import { kitText } from '../i18n/kit-text';
|
|
13
15
|
import { actionButton, classTokens, BUTTON_CLASS_TOKENS, mk, recOf, textOf } from './shape-util';
|
|
14
16
|
import {
|
|
15
17
|
CODE_FOLLOW_SLACK_PX, CODE_MAX_LINES_CAP, CODE_TREE_MAX_DEPTH, CODE_TREE_MAX_NODES, CODE_TREE_OPEN_DEPTH, CODE_VARIANTS_MAX,
|
|
16
18
|
} from './d9-limits';
|
|
19
|
+
import { KIT_CONTENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
|
+
import {
|
|
21
|
+
KIT_CODE_BIDI_CLASS, KIT_CODE_GUTTER_CLASS, KIT_CODE_LANG_CLASS, KIT_CODE_LINES_SCROLL_CLASS, KIT_CODE_LINES_WRAP_CLASS, KIT_CODE_LINE_CLASS,
|
|
22
|
+
KIT_CODE_LINE_MARKED_CLASS, KIT_CODE_LINE_MARKED_WRAP_CLASS, KIT_CODE_LINE_WRAP_CLASS, KIT_CODE_NOTE_CLASS, KIT_CODE_TEXT_CLASS,
|
|
23
|
+
KIT_CODE_VIEW_RECIPE_CLASS_CANDIDATES, kitCodeTokenClass,
|
|
24
|
+
} from '../recipes/code-view';
|
|
25
|
+
import { kitEnginePort, type KitCodeResult, type KitHighlightEnginePort } from './engine-ports';
|
|
26
|
+
import { textActionButton, TEXT_ACTION_CLASS_TOKENS } from './text-action-button';
|
|
27
|
+
|
|
28
|
+
const CL = KIT_CONTENT_LIMITS.codeView;
|
|
29
|
+
|
|
30
|
+
export const KIT_CODE_VIEW_DEFAULT_MAP = Object.freeze({
|
|
31
|
+
title: 'title', text: 'text', caption: 'caption', copy: 'copy',
|
|
32
|
+
language: 'language', filename: 'filename', highlight_lines: 'highlight_lines', start_line: 'start_line',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// ── 高亮形态的纯函数(内容展示批次 ③;规格 knowledge/Kit主题规则与算法.md §10.16) ──
|
|
36
|
+
|
|
37
|
+
/** 高亮行:`"1-3,7"` 或 `[1, 2, 3]`(1 起,按显示行号)→ 集合;非法片段忽略 */
|
|
38
|
+
export function parseLineRanges(raw: unknown): Set<number> {
|
|
39
|
+
const out = new Set<number>();
|
|
40
|
+
const add = (n: number): void => { if (Number.isInteger(n) && n > 0 && out.size < CL.markedLinesMax) out.add(n); };
|
|
41
|
+
if (Array.isArray(raw)) { for (const v of raw) add(Number(v)); return out; }
|
|
42
|
+
if (typeof raw !== 'string') return out;
|
|
43
|
+
for (const part of raw.split(',')) {
|
|
44
|
+
const m = /^\s*(\d+)\s*(?:-\s*(\d+))?\s*$/u.exec(part);
|
|
45
|
+
if (!m) continue;
|
|
46
|
+
const a = Number(m[1]);
|
|
47
|
+
const b = m[2] !== undefined ? Number(m[2]) : a;
|
|
48
|
+
for (let n = Math.min(a, b); n <= Math.max(a, b) && out.size < CL.markedLinesMax; n += 1) add(n);
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const BIDI = /[--]/u;
|
|
54
|
+
/** 行内含 Unicode 双向控制字符(Trojan Source 风险)→ 行首警告 */
|
|
55
|
+
export const hasBidiControl = (line: string): boolean => BIDI.test(line);
|
|
56
|
+
|
|
57
|
+
const HAN_LINE = /[㐀-鿿豈-]/u;
|
|
58
|
+
/** 换行缺省:text / markdown,或含中文的行占比 > 阈值 → 换行;否则横向滚动 */
|
|
59
|
+
export function codeWrapDefault(language: string, lines: readonly string[]): boolean {
|
|
60
|
+
if (language === 'text' || language === 'markdown') return true;
|
|
61
|
+
const nonEmpty = lines.filter((l) => l.trim() !== '');
|
|
62
|
+
if (nonEmpty.length === 0) return false;
|
|
63
|
+
return nonEmpty.filter((l) => HAN_LINE.test(l)).length / nonEmpty.length > CL.wrapCjkRatio;
|
|
64
|
+
}
|
|
17
65
|
|
|
18
|
-
export
|
|
66
|
+
export interface KitCodeLinesOptions {
|
|
67
|
+
readonly language: string;
|
|
68
|
+
readonly wrap: boolean;
|
|
69
|
+
/** null = 宿主没装配高亮端口(只画纯文本行) */
|
|
70
|
+
readonly port: KitHighlightEnginePort | null;
|
|
71
|
+
/** 组件根(取页面语言的文案) */
|
|
72
|
+
readonly root: HTMLElement;
|
|
73
|
+
readonly marked?: ReadonlySet<number>;
|
|
74
|
+
readonly start?: number;
|
|
75
|
+
/** 只画前 N 行(折叠);缺省全部 */
|
|
76
|
+
readonly shown?: number;
|
|
77
|
+
/** 异步着色回来时是否仍是当前这次绘制(后发先至时丢弃旧结果) */
|
|
78
|
+
readonly current?: () => boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 按行画代码区(CodeView 高亮形态与 JsonView「原文」共用的唯一画法):先画纯文本行(行号槽、高亮行、双向字符警告),
|
|
83
|
+
* 再经 engines.highlight 异步取记号替换各行正文;超长 / 超时补一行说明。返回行容器。
|
|
84
|
+
*/
|
|
85
|
+
export function paintCodeLines(host: HTMLElement, text: string, o: KitCodeLinesOptions): HTMLElement {
|
|
86
|
+
const allLines = text.split('\n');
|
|
87
|
+
const shownLines = o.shown !== undefined && o.shown < allLines.length ? allLines.slice(0, o.shown) : allLines;
|
|
88
|
+
const start = o.start ?? 1;
|
|
89
|
+
const marked = o.marked ?? new Set<number>();
|
|
90
|
+
const numbers = allLines.length >= CL.lineNumbersMin;
|
|
91
|
+
const root = o.root;
|
|
92
|
+
const box = mk('div', o.wrap ? KIT_CODE_LINES_WRAP_CLASS : KIT_CODE_LINES_SCROLL_CLASS);
|
|
93
|
+
box.setAttribute('data-kit-code-lines', '');
|
|
94
|
+
const rows: HTMLElement[] = shownLines.map((line, i) => {
|
|
95
|
+
const n = start + i;
|
|
96
|
+
const on = marked.has(n);
|
|
97
|
+
const row = mk('div', on ? (o.wrap ? KIT_CODE_LINE_MARKED_WRAP_CLASS : KIT_CODE_LINE_MARKED_CLASS) : (o.wrap ? KIT_CODE_LINE_WRAP_CLASS : KIT_CODE_LINE_CLASS));
|
|
98
|
+
if (numbers) {
|
|
99
|
+
const g = mk('span', KIT_CODE_GUTTER_CLASS, String(n));
|
|
100
|
+
g.setAttribute('aria-hidden', 'true');
|
|
101
|
+
row.appendChild(g);
|
|
102
|
+
}
|
|
103
|
+
if (on) row.appendChild(mk('span', 'sr-only', kitText('soma.kit.code_marked_line', { n }, root)));
|
|
104
|
+
if (hasBidiControl(line)) {
|
|
105
|
+
const w = mk('span', KIT_CODE_BIDI_CLASS);
|
|
106
|
+
w.title = kitText('soma.kit.code_bidi_warning', undefined, root);
|
|
107
|
+
w.setAttribute('aria-label', w.title);
|
|
108
|
+
w.appendChild(kitIcon('warning', 'xs'));
|
|
109
|
+
row.appendChild(w);
|
|
110
|
+
}
|
|
111
|
+
row.appendChild(mk('span', KIT_CODE_TEXT_CLASS, line === '' ? ' ' : line));
|
|
112
|
+
box.appendChild(row);
|
|
113
|
+
return row;
|
|
114
|
+
});
|
|
115
|
+
host.appendChild(box);
|
|
116
|
+
if (o.port !== null && o.language !== 'text') {
|
|
117
|
+
const current = o.current ?? ((): boolean => true);
|
|
118
|
+
void o.port.highlight(text, o.language).then((res: KitCodeResult) => {
|
|
119
|
+
if (!current() || !host.contains(box)) return;
|
|
120
|
+
rows.forEach((row, i) => {
|
|
121
|
+
const toks = res.lines[i];
|
|
122
|
+
if (toks === undefined || toks.length === 0) return;
|
|
123
|
+
const body = row.lastElementChild as HTMLElement | null;
|
|
124
|
+
if (!body) return;
|
|
125
|
+
body.textContent = '';
|
|
126
|
+
for (const tok of toks) {
|
|
127
|
+
const cls = kitCodeTokenClass(tok.kind);
|
|
128
|
+
body.appendChild(cls === '' ? document.createTextNode(tok.text) : mk('span', cls, tok.text));
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
if (res.fallback === 'too-large' || res.fallback === 'timeout') {
|
|
132
|
+
host.appendChild(mk('p', KIT_CODE_NOTE_CLASS, kitText('soma.kit.code_partly_plain', undefined, root)));
|
|
133
|
+
}
|
|
134
|
+
}, () => { /* 端口不抛;保险起见吞掉,保留纯文本 */ });
|
|
135
|
+
}
|
|
136
|
+
return box;
|
|
137
|
+
}
|
|
19
138
|
|
|
20
139
|
const ROOT_CLASS = 'flex flex-col gap-2';
|
|
21
140
|
const HEAD_CLASS = 'flex items-center justify-between gap-2';
|
|
141
|
+
const HEAD_META_CLASS = 'flex min-w-0 items-center gap-2';
|
|
142
|
+
const PLAIN_TEXT_HINTS: ReadonlySet<string> = new Set(['text', 'txt', 'plain', 'plaintext']);
|
|
143
|
+
// 页签头只画朝内的一条分隔线(分隔线出口);代码井 / 结构树 = 凹槽面的壳配方(容器边,嵌套在面板里由层级规则去框,KT-B2 / KT-L2);树的缩进导线 = 分隔线出口
|
|
144
|
+
const HEAD_TABS_CLASS = `flex items-center justify-between gap-2 ${KIT_DIVIDER_HEAD_CLASS}`;
|
|
22
145
|
const TITLE_CLASS = 'text-sm font-medium text-fg';
|
|
23
|
-
|
|
146
|
+
const WELL_EDGE = kitShellRecipe({ tone: 'sunken', shadow: false });
|
|
147
|
+
const TREE_GUIDE = kitDividerRecipe('start');
|
|
148
|
+
export const KIT_CODE_PRE_CLASS = `m-0 whitespace-pre-wrap break-all ${WELL_EDGE} p-3 font-mono text-xs text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;
|
|
24
149
|
const PRE_HEIGHT: Readonly<Record<string, string>> = Object.freeze({
|
|
25
150
|
none: '',
|
|
26
151
|
sm: 'max-h-40 overflow-y-auto',
|
|
@@ -31,10 +156,10 @@ const EMPTY_CLASS = 'text-fg-subtle';
|
|
|
31
156
|
const CAPTION_CLASS = 'text-xs text-fg-subtle';
|
|
32
157
|
|
|
33
158
|
// variants:同一块位置按页签切换多份文本(如同一服务的多个客户端配置)
|
|
34
|
-
//
|
|
35
|
-
const TABS_CLASS = 'flex min-w-0 flex-1 flex-
|
|
159
|
+
// 页签行单行不折行可横向滚动,底部分割线挂在整行 header 容器上贯通左右,右侧「复制」钮齐平不错位
|
|
160
|
+
const TABS_CLASS = '-mb-px flex min-w-0 flex-1 flex-nowrap items-center gap-1 overflow-x-auto';
|
|
36
161
|
const HEAD_END_BUTTON = 'shrink-0';
|
|
37
|
-
const TAB_CLASS = 'h-8 -
|
|
162
|
+
const TAB_CLASS = 'h-8 shrink-0 whitespace-nowrap border-b-2 border-transparent bg-transparent px-3 text-sm text-fg-muted hover:text-fg motion-safe:transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
38
163
|
const TAB_ACTIVE_CLASS = 'border-primary font-medium text-fg';
|
|
39
164
|
|
|
40
165
|
export interface KitCodeVariant {
|
|
@@ -79,9 +204,9 @@ export function codeVariantsFromProps(p: Record<string, unknown>): KitCodeVarian
|
|
|
79
204
|
}
|
|
80
205
|
|
|
81
206
|
// tree:JSON 树(自绘 disclosure:标题 button + aria-expanded / aria-controls,Enter / Space 由 button 触发点击切换)
|
|
82
|
-
const TREE_CLASS =
|
|
207
|
+
const TREE_CLASS = `m-0 ${WELL_EDGE} p-3 font-mono text-xs text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;
|
|
83
208
|
const TREE_SUMMARY_CLASS = 'block w-full cursor-pointer select-none rounded-sm bg-transparent p-0 text-start font-mono text-xs text-fg hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
84
|
-
const TREE_CHILDREN_CLASS =
|
|
209
|
+
const TREE_CHILDREN_CLASS = `ms-3 ${TREE_GUIDE} ps-3`;
|
|
85
210
|
const TREE_LEAF_CLASS = 'py-0.5 break-all';
|
|
86
211
|
const TREE_KEY_CLASS = 'text-fg-muted';
|
|
87
212
|
const TREE_VALUE_CLASS: Readonly<Record<'string' | 'number' | 'other', string>> = Object.freeze({
|
|
@@ -94,8 +219,8 @@ let treeSeq = 0;
|
|
|
94
219
|
|
|
95
220
|
export const KIT_CODE_VIEW_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
96
221
|
TREE_CLASS, TREE_SUMMARY_CLASS, TREE_CHILDREN_CLASS, TREE_LEAF_CLASS, TREE_KEY_CLASS, TREE_MARK_CLASS, TREE_HIDDEN_CLASS, Object.values(TREE_VALUE_CLASS), TREE_MORE_CLASS,
|
|
97
|
-
ROOT_CLASS, HEAD_CLASS, TITLE_CLASS, KIT_CODE_PRE_CLASS, Object.values(PRE_HEIGHT), EMPTY_CLASS, CAPTION_CLASS, BUTTON_CLASS_TOKENS,
|
|
98
|
-
TABS_CLASS, TAB_CLASS, TAB_ACTIVE_CLASS, HEAD_END_BUTTON,
|
|
222
|
+
ROOT_CLASS, HEAD_CLASS, HEAD_META_CLASS, HEAD_TABS_CLASS, TITLE_CLASS, KIT_CODE_PRE_CLASS, Object.values(PRE_HEIGHT), EMPTY_CLASS, CAPTION_CLASS, BUTTON_CLASS_TOKENS,
|
|
223
|
+
TABS_CLASS, TAB_CLASS, TAB_ACTIVE_CLASS, HEAD_END_BUTTON, KIT_CODE_VIEW_RECIPE_CLASS_CANDIDATES, TEXT_ACTION_CLASS_TOKENS, 'sr-only',
|
|
99
224
|
);
|
|
100
225
|
|
|
101
226
|
/** 展示文本(纯函数,便于单测):字符串原样,其余 JSON 缩进;不可序列化回空串 */
|
|
@@ -177,6 +302,10 @@ export function treeNode(key: string, value: unknown, depth: number, budget: { l
|
|
|
177
302
|
|
|
178
303
|
export function createCodeView(): SomaComponentDefinition {
|
|
179
304
|
const timers = new WeakMap<HTMLElement, ReturnType<typeof setTimeout>>();
|
|
305
|
+
// 长代码「展开全部」已点开的实例;内容变化时重置展开态;高亮请求的序号(后发先至,旧结果丢弃)
|
|
306
|
+
const unfolded = new WeakSet<HTMLElement>();
|
|
307
|
+
const renderedText = new WeakMap<HTMLElement, string>();
|
|
308
|
+
const hlSeq = new WeakMap<HTMLElement, number>();
|
|
180
309
|
// stream + follow:滚动区是否贴在底部(用户往上翻就不再自动跟随);键 = 组件根
|
|
181
310
|
const pinned = new WeakMap<HTMLElement, boolean>();
|
|
182
311
|
// variants:当前页签序号与外部 variant 的上次取值(外部变化才覆盖内部选择)
|
|
@@ -200,9 +329,10 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
200
329
|
name: 'CodeView',
|
|
201
330
|
layer: 'data',
|
|
202
331
|
props: {
|
|
203
|
-
data: { type: 'object', default: {}, desc: '{ title?, text, caption?, copy? };text 非字符串时按缩进 JSON 展示;copy
|
|
204
|
-
map: { type: 'object', default: {}, desc: '键名对照:title / text / caption / copy' },
|
|
205
|
-
|
|
332
|
+
data: { type: 'object', default: {}, desc: '{ title?, text, caption?, copy?, language?, filename?, highlight_lines?, start_line? };text 非字符串时按缩进 JSON 展示;copy 非空时复制钮复制它而不是展示文本;语言按 language → filename → JSON 确定性推断,经 core 端口 engines.highlight 着色(闭集外按纯文本并注明)' },
|
|
333
|
+
map: { type: 'object', default: {}, desc: '键名对照:title / text / caption / copy / language / filename / highlight_lines / start_line' },
|
|
334
|
+
wrap: { type: 'enum', values: ['auto', 'on', 'off'], default: 'auto', desc: '长行:auto = text / markdown 或含中文行占比过半时换行,否则横向滚动;on 换行;off 横向滚动' },
|
|
335
|
+
copyable: { type: 'boolean', default: true, desc: '显示「复制」钮(缺省显示,裁决 2026-11-24:缺省即最佳;写 false 关闭)' },
|
|
206
336
|
copy_label: { type: 'string', default: '', desc: '复制钮文字;缺省取内置文案(按页面语言)' },
|
|
207
337
|
copied_label: { type: 'string', default: '', desc: '复制成功后短暂显示的文字;缺省取内置文案(按页面语言)' },
|
|
208
338
|
stream: { type: 'boolean', default: false, desc: '流式日志:text 是不断追加的全文;内容区标 role=log(读屏礼貌播报新增);配合 max_lines 只保留末尾若干行' },
|
|
@@ -222,7 +352,8 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
222
352
|
variant: { payload: { key: { type: 'string' }, index: { type: 'number' } }, desc: '切换页签后抛(variants 非空时)' },
|
|
223
353
|
},
|
|
224
354
|
},
|
|
225
|
-
|
|
355
|
+
services: ['engines'],
|
|
356
|
+
templateHtml: `<section data-kit-container="card" data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
226
357
|
controllerFactory: createKitController(() => ({
|
|
227
358
|
attach(root, api) {
|
|
228
359
|
const onClick = (event: Event): void => {
|
|
@@ -246,17 +377,28 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
246
377
|
} catch { ok = false; }
|
|
247
378
|
if (ok) {
|
|
248
379
|
btn.textContent = str(p.copied_label, kitText('soma.kit.copied', undefined, root));
|
|
380
|
+
const live = root.querySelector<HTMLElement>('[data-kit-code-live]');
|
|
381
|
+
if (live) live.textContent = kitText('soma.kit.copied', undefined, root);
|
|
249
382
|
const prev = timers.get(root);
|
|
250
383
|
if (prev !== undefined) clearTimeout(prev);
|
|
251
384
|
timers.set(root, setTimeout(() => {
|
|
252
385
|
btn.textContent = str(api.props().copy_label, kitText('soma.kit.copy', undefined, root));
|
|
386
|
+
if (live) live.textContent = '';
|
|
253
387
|
timers.delete(root);
|
|
254
|
-
},
|
|
388
|
+
}, CL.copyFeedbackMs));
|
|
255
389
|
}
|
|
256
390
|
api.emit('copy', { ok });
|
|
257
391
|
})();
|
|
258
392
|
};
|
|
259
393
|
root.addEventListener('click', onClick);
|
|
394
|
+
// 长代码折叠条:展开全部(只展开不收起,与 Carbon 一致)
|
|
395
|
+
const onUnfold = (event: Event): void => {
|
|
396
|
+
const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-action="code-unfold"]');
|
|
397
|
+
if (!btn || !root.contains(btn)) return;
|
|
398
|
+
unfolded.add(root);
|
|
399
|
+
renderCode(root, api.props(), api.services);
|
|
400
|
+
};
|
|
401
|
+
root.addEventListener('click', onUnfold);
|
|
260
402
|
// 树节点折叠:button 的 Enter / Space 原生触发 click;这里切 aria-expanded、折叠体显隐与标记
|
|
261
403
|
const onToggle = (event: Event): void => {
|
|
262
404
|
const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-tree-toggle]');
|
|
@@ -279,7 +421,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
279
421
|
if (st.index === index) return;
|
|
280
422
|
st.index = index;
|
|
281
423
|
picked.set(root, st);
|
|
282
|
-
renderCode(root, p);
|
|
424
|
+
renderCode(root, p, api.services);
|
|
283
425
|
if (refocus) root.querySelector<HTMLElement>('[data-kit-variant][aria-selected="true"]')?.focus();
|
|
284
426
|
api.emit('variant', { key: list[index]!.key, index });
|
|
285
427
|
};
|
|
@@ -311,6 +453,9 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
311
453
|
root.addEventListener('scroll', onScroll, true);
|
|
312
454
|
return () => {
|
|
313
455
|
root.removeEventListener('click', onClick);
|
|
456
|
+
root.removeEventListener('click', onUnfold);
|
|
457
|
+
unfolded.delete(root);
|
|
458
|
+
renderedText.delete(root);
|
|
314
459
|
root.removeEventListener('click', onToggle);
|
|
315
460
|
root.removeEventListener('click', onTab);
|
|
316
461
|
root.removeEventListener('keydown', onTabKey as EventListener);
|
|
@@ -322,13 +467,13 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
322
467
|
timers.delete(root);
|
|
323
468
|
};
|
|
324
469
|
},
|
|
325
|
-
render(root, p) {
|
|
326
|
-
renderCode(root, p);
|
|
470
|
+
render(root, p, renderApi) {
|
|
471
|
+
renderCode(root, p, renderApi.services);
|
|
327
472
|
},
|
|
328
473
|
})),
|
|
329
474
|
};
|
|
330
475
|
|
|
331
|
-
function renderCode(root: HTMLElement, p: Record<string, unknown
|
|
476
|
+
function renderCode(root: HTMLElement, p: Record<string, unknown>, services: unknown): void {
|
|
332
477
|
const data = recOf(p.data);
|
|
333
478
|
const m = { ...KIT_CODE_VIEW_DEFAULT_MAP, ...recOf(p.map) } as Record<string, string>;
|
|
334
479
|
const variants = codeVariantsFromProps(p);
|
|
@@ -344,7 +489,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
344
489
|
const caption = limited.omitted > 0
|
|
345
490
|
? `${captionBase}${captionBase !== '' ? ' · ' : ''}${kitText(stream ? 'soma.kit.code_omitted_head' : 'soma.kit.code_omitted_tail', { n: limited.omitted }, root)}`
|
|
346
491
|
: captionBase;
|
|
347
|
-
const copyable = bool(p.copyable);
|
|
492
|
+
const copyable = p.copyable === undefined ? true : bool(p.copyable);
|
|
348
493
|
const heightKey = str(p.max_height, 'md');
|
|
349
494
|
// tree:对象 / 数组,或能解析成对象 / 数组的 JSON 字符串
|
|
350
495
|
let treeValue: unknown = null;
|
|
@@ -360,10 +505,25 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
360
505
|
const oldPre = root.querySelector<HTMLElement>('[data-kit-code]');
|
|
361
506
|
const prevTop = oldPre?.scrollTop ?? 0;
|
|
362
507
|
|
|
508
|
+
// 内容变化时重置长代码展开状态,避免切换新代码后沿用旧代码的 unfolded 标记
|
|
509
|
+
if (renderedText.get(root) !== text) {
|
|
510
|
+
unfolded.delete(root);
|
|
511
|
+
renderedText.set(root, text);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// 高亮形态(非流式、非树):语言确定性推断(长文件仍传 firstLine 以支持 shebang);头部有文件名显示文件名,否则显示语言名(显式 text 不显示且不报未知语言)
|
|
515
|
+
const port = kitEnginePort<KitHighlightEnginePort>(services, 'highlight');
|
|
516
|
+
const filename = textOf(data[m.filename ?? 'filename']);
|
|
517
|
+
const langHint = textOf(data[m.language ?? 'language']);
|
|
518
|
+
const firstLine = text.split('\n', 1)[0] ?? '';
|
|
519
|
+
const language = stream || port === null ? 'text' : port.resolveLanguage({ language: langHint, filename, firstLine, sample: text.length <= CL.sniffMaxChars ? text : '' });
|
|
520
|
+
const explicitPlain = langHint !== '' && PLAIN_TEXT_HINTS.has(langHint.trim().toLowerCase());
|
|
521
|
+
const unknownLang = langHint !== '' && language === 'text' && !explicitPlain;
|
|
522
|
+
const langLabel = filename !== '' ? filename : language !== 'text' && port !== null ? port.languageLabel(language) : unknownLang ? langHint : '';
|
|
363
523
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
364
524
|
root.textContent = '';
|
|
365
|
-
if (title !== '' || copyable || variants.length > 0) {
|
|
366
|
-
const head = mk('div', HEAD_CLASS);
|
|
525
|
+
if (title !== '' || copyable || variants.length > 0 || langLabel !== '') {
|
|
526
|
+
const head = mk('div', variants.length > 0 ? HEAD_TABS_CLASS : HEAD_CLASS);
|
|
367
527
|
if (variants.length > 0) {
|
|
368
528
|
const tabs = mk('div', TABS_CLASS);
|
|
369
529
|
tabs.setAttribute('role', 'tablist');
|
|
@@ -378,7 +538,12 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
378
538
|
tabs.appendChild(tab);
|
|
379
539
|
});
|
|
380
540
|
head.appendChild(tabs);
|
|
381
|
-
} else
|
|
541
|
+
} else if (title !== '' || langLabel !== '') {
|
|
542
|
+
const meta = mk('div', HEAD_META_CLASS);
|
|
543
|
+
if (title !== '') meta.appendChild(mk('span', TITLE_CLASS, title));
|
|
544
|
+
if (langLabel !== '') meta.appendChild(mk('span', KIT_CODE_LANG_CLASS, langLabel));
|
|
545
|
+
head.appendChild(meta);
|
|
546
|
+
}
|
|
382
547
|
if (copyable) {
|
|
383
548
|
const copyBtn = actionButton({ key: 'copy', label: str(p.copy_label, kitText('soma.kit.copy', undefined, root)), tone: 'neutral', disabled: text === '', reason: '' });
|
|
384
549
|
copyBtn.classList.add(HEAD_END_BUTTON);
|
|
@@ -388,9 +553,11 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
388
553
|
}
|
|
389
554
|
const height = PRE_HEIGHT[heightKey] ?? 'max-h-80 overflow-y-auto';
|
|
390
555
|
const asTree = treeValue !== null;
|
|
556
|
+
// 高亮形态每行一个块元素,外壳用 div(pre 里只许短语内容);流式与空态仍是 pre
|
|
557
|
+
const lineMode = !asTree && !stream && text !== '';
|
|
391
558
|
const pre = asTree
|
|
392
559
|
? mk('div', `${TREE_CLASS}${height !== '' ? ` ${height}` : ''}`)
|
|
393
|
-
: mk('pre', `${KIT_CODE_PRE_CLASS}${height !== '' ? ` ${height}` : ''}`);
|
|
560
|
+
: mk(lineMode ? 'div' : 'pre', `${KIT_CODE_PRE_CLASS}${height !== '' ? ` ${height}` : ''}`);
|
|
394
561
|
pre.tabIndex = 0;
|
|
395
562
|
pre.setAttribute('data-kit-code', '');
|
|
396
563
|
pre.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_WELL);
|
|
@@ -407,10 +574,37 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
407
574
|
} else if (text === '') {
|
|
408
575
|
pre.appendChild(mk('span', EMPTY_CLASS, str(p.empty_text, kitText('soma.kit.empty_content', undefined, root))));
|
|
409
576
|
pre.setAttribute('data-kit-empty', '');
|
|
410
|
-
} else {
|
|
577
|
+
} else if (stream) {
|
|
411
578
|
pre.textContent = text;
|
|
579
|
+
} else {
|
|
580
|
+
// 高亮形态:先画纯文本行(行号、折叠、换行、高亮行都在这一步定好),再异步取记号替换各行正文
|
|
581
|
+
pre.setAttribute('role', 'region');
|
|
582
|
+
pre.setAttribute('data-kit-container', 'plain');
|
|
583
|
+
pre.setAttribute('aria-label', label !== '' ? label : kitText('soma.kit.code_region', { name: langLabel !== '' ? langLabel : kitText('soma.kit.code_plain', undefined, root) }, root));
|
|
584
|
+
const allLines = text.split('\n');
|
|
585
|
+
const folded = allLines.length > CL.foldAbove && !unfolded.has(root);
|
|
586
|
+
const wrapMode = str(p.wrap, 'auto');
|
|
587
|
+
const wrapOn = wrapMode === 'on' || (wrapMode === 'auto' && codeWrapDefault(language, allLines));
|
|
588
|
+
const startRaw = Number(data[m.start_line ?? 'start_line']);
|
|
589
|
+
const mine = (hlSeq.get(root) ?? 0) + 1;
|
|
590
|
+
hlSeq.set(root, mine);
|
|
591
|
+
paintCodeLines(pre, text, {
|
|
592
|
+
language, wrap: wrapOn, port, root,
|
|
593
|
+
marked: parseLineRanges(data[m.highlight_lines ?? 'highlight_lines']),
|
|
594
|
+
start: Number.isInteger(startRaw) && startRaw > 0 ? startRaw : 1,
|
|
595
|
+
shown: folded ? CL.foldTo : allLines.length,
|
|
596
|
+
current: () => hlSeq.get(root) === mine,
|
|
597
|
+
});
|
|
598
|
+
if (folded) pre.appendChild(textActionButton('code-unfold', kitText('soma.kit.code_unfold', { n: allLines.length }, root), 'primary'));
|
|
599
|
+
if (unknownLang && port !== null) {
|
|
600
|
+
pre.appendChild(mk('p', KIT_CODE_NOTE_CLASS, kitText('soma.kit.code_unknown_language', undefined, root)));
|
|
601
|
+
}
|
|
412
602
|
}
|
|
413
603
|
root.appendChild(pre);
|
|
604
|
+
const live = mk('span', 'sr-only');
|
|
605
|
+
live.setAttribute('aria-live', 'polite');
|
|
606
|
+
live.setAttribute('data-kit-code-live', '');
|
|
607
|
+
root.appendChild(live);
|
|
414
608
|
// 流式:贴底(或首次)且 follow 时滚到最新;用户翻上去过就保持原位置
|
|
415
609
|
if (stream) {
|
|
416
610
|
const wasPinned = pinned.get(root) ?? true;
|
|
@@ -11,6 +11,10 @@ import { matchSubmitKey } from 'soma-core/keyboard';
|
|
|
11
11
|
import { bool, createKitController, formatValue, joinClass, num, str } from '../base/shared';
|
|
12
12
|
import { kitText } from '../i18n/kit-text';
|
|
13
13
|
import { setKitFace } from '../recipes';
|
|
14
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
15
|
+
|
|
16
|
+
/** 回复框的边 = 控件轮廓出口(KT-B1 / §4 C6) */
|
|
17
|
+
const AREA_EDGE = kitControlEdgeRecipe();
|
|
14
18
|
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
15
19
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
16
20
|
import { AVATAR_CLASS_TOKENS, avatarNode } from './d9-util';
|
|
@@ -50,7 +54,7 @@ const TEXT_CLASS = 'whitespace-pre-wrap text-fg';
|
|
|
50
54
|
const ROW_ACTIONS = 'flex items-center gap-3 text-xs';
|
|
51
55
|
const LINK_BUTTON = 'rounded-md text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
52
56
|
const COMPOSER_CLASS = 'flex flex-col gap-2';
|
|
53
|
-
const INPUT_CLASS = 'w-full appearance-none autofill-clear resize-none rounded-md
|
|
57
|
+
const INPUT_CLASS = 'w-full appearance-none autofill-clear resize-none rounded-md ' + AREA_EDGE + ' bg-surface px-3 py-2 text-sm text-fg transition-colors state-layer disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
54
58
|
const COMPOSER_FOOT = 'flex items-center justify-between gap-2';
|
|
55
59
|
const COUNTER_CLASS = 'text-xs text-fg-subtle';
|
|
56
60
|
|
|
@@ -147,7 +151,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
147
151
|
retry: { payload: { id: { type: 'string' }, item: { type: 'object' } }, desc: '点失败消息的重试(chat 变体)' },
|
|
148
152
|
},
|
|
149
153
|
},
|
|
150
|
-
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
154
|
+
templateHtml: `<section data-kit-container="card" data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
151
155
|
controllerFactory: createKitController(() => ({
|
|
152
156
|
attach(root, api) {
|
|
153
157
|
const submit = (): void => {
|
|
@@ -278,6 +282,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
278
282
|
}
|
|
279
283
|
for (const e of chat ? [] : entries) {
|
|
280
284
|
const item = mk('article', ITEM_CLASS);
|
|
285
|
+
item.setAttribute('data-kit-container', 'card');
|
|
281
286
|
item.setAttribute('data-kit-comment', e.key);
|
|
282
287
|
// 头像与 chat 变体同一个 avatarNode:地址只认 http(s) / 站内相对 / data:image,其余退回首字母徽标
|
|
283
288
|
item.appendChild(avatarNode(e.author, e.avatar, 'md'));
|
|
@@ -14,15 +14,16 @@ import { confirmKeyAccepts, confirmSatisfied } from 'soma-core/render-ports';
|
|
|
14
14
|
import { KIT_CHECK_CLASS_CANDIDATES, createCheck, markInput, setMarkLabel } from '../base/check-core';
|
|
15
15
|
import { nextUid } from '../base/shared';
|
|
16
16
|
import { kitText } from '../i18n/kit-text';
|
|
17
|
-
import { setKitFace } from '../recipes';
|
|
17
|
+
import { kitControlRecipe, setKitFace } from '../recipes';
|
|
18
18
|
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal } from './modal-dialog';
|
|
19
|
-
import { ACTION_BUTTON_TONE, BUTTON_CLASS_TOKENS, classTokens, type ActionTone } from './shape-util';
|
|
19
|
+
import { ACTION_BUTTON_CONFIRM_DANGER, ACTION_BUTTON_TONE, BUTTON_CLASS_TOKENS, classTokens, type ActionTone } from './shape-util';
|
|
20
20
|
|
|
21
21
|
const BUTTON_DISABLED = 'opacity-60 cursor-not-allowed';
|
|
22
22
|
const MESSAGE_CLASS = 'm-0 whitespace-pre-line text-sm text-fg';
|
|
23
23
|
const IMPACT_CLASS = 'm-0 whitespace-pre-line text-xs text-fg-muted';
|
|
24
24
|
const PROMPT_CLASS = 'm-0 text-xs text-fg-muted';
|
|
25
|
-
|
|
25
|
+
// 键入短语的输入框 = 标准输入(控件配方,KT-B1 控件轮廓、§4 C6、§8 G-B5)
|
|
26
|
+
const INPUT_CLASS = kitControlRecipe();
|
|
26
27
|
|
|
27
28
|
export const KIT_CONFIRM_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
28
29
|
BUTTON_DISABLED, MESSAGE_CLASS, IMPACT_CLASS, PROMPT_CLASS, INPUT_CLASS, BUTTON_CLASS_TOKENS, KIT_MODAL_CLASS_CANDIDATES,
|
|
@@ -57,7 +58,8 @@ export interface KitConfirmOptions {
|
|
|
57
58
|
function btn(doc: Document, tone: ActionTone, label: string): HTMLButtonElement {
|
|
58
59
|
const b = doc.createElement('button');
|
|
59
60
|
b.type = 'button';
|
|
60
|
-
|
|
61
|
+
// 确认弹层里的危险语气是实心危险色(全应用唯一的实心危险钮);其余语气取动作按钮的强调形体
|
|
62
|
+
b.className = tone === 'danger' ? ACTION_BUTTON_CONFIRM_DANGER : ACTION_BUTTON_TONE[tone];
|
|
61
63
|
setKitFace(b, 'raised');
|
|
62
64
|
b.textContent = label;
|
|
63
65
|
return b;
|
|
@@ -69,19 +71,60 @@ export const KIT_DIALOG_INPUT_CLASS = INPUT_CLASS;
|
|
|
69
71
|
export const KIT_DIALOG_MESSAGE_CLASS = MESSAGE_CLASS;
|
|
70
72
|
export const KIT_DIALOG_HINT_CLASS = PROMPT_CLASS;
|
|
71
73
|
|
|
74
|
+
/**
|
|
75
|
+
* 确认窗口的文案派生(工序 4:没有「确认」这个空标题;标题 = 具体问句,正文 = 后果说明,主钮 = 具体动词)。唯一出口,页面不逐个手写:
|
|
76
|
+
* - 调用方给了标题(且不是空泛的「确认」)就用它,正文 = message;
|
|
77
|
+
* - 否则 message 的第一句问句(到第一个 ?/ ?)是标题,去掉空泛前缀(确认 / 确定 / 是否…,词条 confirm_prefixes);其余是正文;没有问句时整段是标题、正文为空;
|
|
78
|
+
* - 主钮:标题开头命中具体动词(词条 confirm_verbs,长的先配)就用该动词,否则「确认」。
|
|
79
|
+
*/
|
|
80
|
+
export function kitConfirmCopy(message: string, title: string | undefined, at?: Element | null): { title: string; body: string; verb: string } {
|
|
81
|
+
const generic = kitText('soma.kit.confirm', undefined, at);
|
|
82
|
+
// 词条是「|」分隔的词表(不是类串):逐词取出,长的先配
|
|
83
|
+
const words = (s: string): string[] => [...s.matchAll(/[^|]+/g)].map((m) => m[0]).sort((a, b) => b.length - a.length);
|
|
84
|
+
const prefixes = words(kitText('soma.kit.confirm_prefixes', undefined, at));
|
|
85
|
+
const verbs = words(kitText('soma.kit.confirm_verbs', undefined, at));
|
|
86
|
+
/** 词表里第一个作为 text 开头的词(不区分大小写;lenient = 允许整句就是该词) */
|
|
87
|
+
const leading = (list: readonly string[], text: string, lenient: boolean): string | undefined => {
|
|
88
|
+
const low = text.toLowerCase();
|
|
89
|
+
for (const w of list) if (low.indexOf(w.toLowerCase()) === 0 && (lenient || text.length > w.length)) return w;
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
92
|
+
let head: string;
|
|
93
|
+
let body: string;
|
|
94
|
+
if (title !== undefined && title.trim() !== '' && title.trim() !== generic) {
|
|
95
|
+
head = title.trim();
|
|
96
|
+
body = message.trim();
|
|
97
|
+
} else {
|
|
98
|
+
const m = /^([\s\S]*?[??])\s*([\s\S]*)$/.exec(message.trim());
|
|
99
|
+
head = (m === null ? message : m[1]!).trim();
|
|
100
|
+
body = m === null ? '' : m[2]!.trim();
|
|
101
|
+
const p = leading(prefixes, head, false);
|
|
102
|
+
if (p !== undefined) head = head.slice(p.length).trimStart();
|
|
103
|
+
}
|
|
104
|
+
const verb = leading(verbs, head, true) ?? generic;
|
|
105
|
+
return { title: head, body, verb };
|
|
106
|
+
}
|
|
107
|
+
|
|
72
108
|
export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
73
109
|
if (opts.signal?.aborted === true) return Promise.resolve(false);
|
|
74
110
|
if (typeof document === 'undefined' || document.body === null) return Promise.resolve(opts.whenNoDom === true);
|
|
75
111
|
const doc = opts.at?.ownerDocument ?? document;
|
|
112
|
+
// 提示框(alertOnly)不派生动词:只有「确定」;确认框的标题 / 正文 / 主钮由 kitConfirmCopy 唯一派生
|
|
113
|
+
const copy = opts.alertOnly === true
|
|
114
|
+
? { title: opts.title ?? kitText('soma.kit.confirm', undefined, opts.at), body: opts.message, verb: kitText('soma.kit.ok', undefined, opts.at) }
|
|
115
|
+
: kitConfirmCopy(opts.message, opts.title, opts.at);
|
|
76
116
|
return new Promise<boolean>((resolve) => {
|
|
77
117
|
let settled = false;
|
|
78
118
|
const modal = mountKitModal({
|
|
79
|
-
title:
|
|
80
|
-
size: '
|
|
119
|
+
title: copy.title,
|
|
120
|
+
size: 'confirm',
|
|
81
121
|
at: opts.at ?? null,
|
|
82
122
|
showClose: false,
|
|
83
|
-
//
|
|
84
|
-
|
|
123
|
+
// C 稿确认窗口:没有头部条,语气图标块 + 「具体问句 / 后果说明」一列;危险确认与普通确认的图标块一眼可辨
|
|
124
|
+
lead: opts.tone === 'danger' && opts.alertOnly !== true ? 'danger' : 'primary',
|
|
125
|
+
// 点遮罩 = 取消(文件头契约);纯提示框没有取消语义,只认确认钮 / Esc;
|
|
126
|
+
// 危险确认不因点击遮罩关闭(knowledge/Kit主题规则与算法.md KT-K-overlay-2,2026-11-25 裁决:误触遮罩不该成为对危险动作的回答)
|
|
127
|
+
dismissOnScrim: opts.alertOnly !== true && opts.tone !== 'danger',
|
|
85
128
|
onClose: () => finish(opts.alertOnly === true),
|
|
86
129
|
}, doc);
|
|
87
130
|
// 兜底:打开期间宿主区域被卸载(层锚点脱离文档)时按取消收口,调用方的 await 不会永久挂起
|
|
@@ -100,14 +143,14 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
100
143
|
|
|
101
144
|
const msg = doc.createElement('p');
|
|
102
145
|
msg.className = MESSAGE_CLASS;
|
|
103
|
-
msg.textContent =
|
|
146
|
+
msg.textContent = copy.body;
|
|
104
147
|
msg.id = nextUid('kit-confirm-msg');
|
|
105
|
-
|
|
148
|
+
if (copy.body !== '') modal.lead.appendChild(msg);
|
|
106
149
|
// 无障碍:确认框是 alertdialog(要求用户回应),可访问名 = 标题,描述 = 正文;壳由 mountKitModal 画成 dialog,这里改角色
|
|
107
150
|
const panel = modal.body.parentElement;
|
|
108
151
|
if (panel !== null) {
|
|
109
152
|
panel.setAttribute('role', 'alertdialog');
|
|
110
|
-
panel.setAttribute('aria-describedby', msg.id);
|
|
153
|
+
if (copy.body !== '') panel.setAttribute('aria-describedby', msg.id);
|
|
111
154
|
}
|
|
112
155
|
let impactId = '';
|
|
113
156
|
if (opts.impact !== undefined && opts.impact !== '') {
|
|
@@ -120,7 +163,7 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
120
163
|
}
|
|
121
164
|
|
|
122
165
|
const tone = opts.tone ?? 'primary';
|
|
123
|
-
const okLabel = opts.confirmLabel ??
|
|
166
|
+
const okLabel = opts.confirmLabel ?? copy.verb;
|
|
124
167
|
const ok = btn(doc, opts.alertOnly === true ? 'primary' : tone, okLabel);
|
|
125
168
|
let cancel: HTMLButtonElement | null = null;
|
|
126
169
|
let input: HTMLInputElement | null = null;
|
|
@@ -139,7 +182,7 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
139
182
|
ok.disabled = !met;
|
|
140
183
|
if (met) ok.removeAttribute('aria-disabled');
|
|
141
184
|
else ok.setAttribute('aria-disabled', 'true');
|
|
142
|
-
ok.className = `${ACTION_BUTTON_TONE[tone]}${met ? '' : ` ${BUTTON_DISABLED}`}`;
|
|
185
|
+
ok.className = `${tone === 'danger' ? ACTION_BUTTON_CONFIRM_DANGER : ACTION_BUTTON_TONE[tone]}${met ? '' : ` ${BUTTON_DISABLED}`}`;
|
|
143
186
|
};
|
|
144
187
|
const onGateKey = (e: KeyboardEvent): void => {
|
|
145
188
|
if (gate !== null && confirmKeyAccepts(e, gate, gateInput())) { e.preventDefault(); finish(true); }
|
package/src/data/diff.ts
CHANGED
|
@@ -14,11 +14,14 @@ import { setKitFace } from '../recipes';
|
|
|
14
14
|
import { createKitController, joinClass, str } from '../base/shared';
|
|
15
15
|
import { classTokens, mk, recOf, textOf, type Rec } from './shape-util';
|
|
16
16
|
import { clampInt, singleOf, urlOf } from './display-util';
|
|
17
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
17
18
|
|
|
18
19
|
export const KIT_DIFF_STEP: number = KIT_STATIC_COMPONENT_LIMITS.display.Diff.positionStep;
|
|
19
20
|
export const KIT_DIFF_STEPS = 20;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
// 外缘 = 壳配方(容器边,KT-B2)
|
|
23
|
+
const ROOT_EDGE = kitShellRecipe({ tone: 'base', shadow: false });
|
|
24
|
+
const ROOT_CLASS = `relative aspect-16/9 w-full select-none overflow-hidden ${ROOT_EDGE} touch-none`;
|
|
22
25
|
const LAYER_CLASS = 'absolute inset-0';
|
|
23
26
|
const BEFORE_BOX_BASE = 'absolute inset-y-0 left-0 overflow-hidden';
|
|
24
27
|
const INNER_CLASS = 'relative h-full shrink-0';
|
package/src/data/dock.ts
CHANGED
|
@@ -11,8 +11,12 @@ import { kitText } from '../i18n/kit-text';
|
|
|
11
11
|
import { createKitController, joinClass, str } from '../base/shared';
|
|
12
12
|
import { classTokens, mk, textOf, type Rec } from './shape-util';
|
|
13
13
|
import { keyOfRow, listOf, rovingTabIndex, wireRovingRow } from './display-util';
|
|
14
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
/** 外缘 = 壳配方(容器边 + 容器阴影令牌,KT-B2) */
|
|
17
|
+
const ROOT_EDGE = kitShellRecipe({ tone: 'base' });
|
|
18
|
+
|
|
19
|
+
const ROOT_CLASS = `flex items-stretch justify-around gap-1 ${ROOT_EDGE} p-1`;
|
|
16
20
|
const ITEM_CLASS = 'relative flex min-w-14 flex-1 flex-col items-center justify-center gap-0.5 rounded-md px-2 py-1.5 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60 data-kit-selected:bg-primary-soft data-kit-selected:text-primary-on-soft';
|
|
17
21
|
const ICON_CLASS = 'text-lg';
|
|
18
22
|
const LABEL_CLASS = 'font-medium';
|
package/src/data/embed.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { createInput } from '../base/input';
|
|
|
12
12
|
import { createTextarea } from '../base/textarea';
|
|
13
13
|
import { createCheckbox } from '../base/checkbox';
|
|
14
14
|
import { hintUndeclaredKitUse } from './wrapped-candidates';
|
|
15
|
-
import { kitFail } from '../
|
|
15
|
+
import { kitFail } from '../shared/kit-error';
|
|
16
16
|
|
|
17
17
|
export type KitEmitHandlers = Record<string, (payload: any) => void>;
|
|
18
18
|
|